Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

289 lines
5.1 KiB

  1. /*++
  2. Copyright (c) 1996-1997 Microsoft Corporation
  3. Module Name:
  4. intrface.c
  5. Abstract:
  6. Server side support for Cluster APIs dealing with network interfaces
  7. Author:
  8. John Vert (jvert) 7-Mar-1996
  9. Revision History:
  10. --*/
  11. #include "apip.h"
  12. HNETINTERFACE_RPC
  13. s_ApiOpenNetInterface(
  14. IN handle_t IDL_handle,
  15. IN LPCWSTR lpszNetInterfaceName,
  16. OUT error_status_t *Status
  17. )
  18. /*++
  19. Routine Description:
  20. Opens a handle to an existing network interface object.
  21. Arguments:
  22. IDL_handle - RPC binding handle, not used.
  23. lpszNetInterfaceName - Supplies the name of the netinterface to open.
  24. Status - Returns any error that may occur.
  25. Return Value:
  26. A context handle to a network interface object if successful
  27. NULL otherwise.
  28. --*/
  29. {
  30. PAPI_HANDLE Handle;
  31. HNETINTERFACE_RPC NetInterface;
  32. if (ApiState != ApiStateOnline) {
  33. *Status = ERROR_SHARING_PAUSED;
  34. return(NULL);
  35. }
  36. Handle = LocalAlloc(LMEM_FIXED, sizeof(API_HANDLE));
  37. if (Handle == NULL) {
  38. *Status = ERROR_NOT_ENOUGH_MEMORY;
  39. return(NULL);
  40. }
  41. NetInterface = OmReferenceObjectByName(ObjectTypeNetInterface,
  42. lpszNetInterfaceName);
  43. if (NetInterface == NULL) {
  44. LocalFree(Handle);
  45. *Status = ERROR_CLUSTER_NETINTERFACE_NOT_FOUND;
  46. return(NULL);
  47. }
  48. Handle->Type = API_NETINTERFACE_HANDLE;
  49. Handle->Flags = 0;
  50. Handle->NetInterface = NetInterface;
  51. InitializeListHead(&Handle->NotifyList);
  52. *Status = ERROR_SUCCESS;
  53. return(Handle);
  54. }
  55. error_status_t
  56. s_ApiCloseNetInterface(
  57. IN OUT HNETINTERFACE_RPC *phNetInterface
  58. )
  59. /*++
  60. Routine Description:
  61. Closes an open network interface context handle.
  62. Arguments:
  63. NetInterface - Supplies a pointer to the HNETINTERFACE_RPC to be closed.
  64. Returns NULL
  65. Return Value:
  66. None.
  67. --*/
  68. {
  69. PNM_INTERFACE NetInterface;
  70. PAPI_HANDLE Handle;
  71. API_ASSERT_INIT();
  72. VALIDATE_NETINTERFACE(NetInterface, *phNetInterface);
  73. Handle = (PAPI_HANDLE)*phNetInterface;
  74. ApipRundownNotify(Handle);
  75. OmDereferenceObject(NetInterface);
  76. LocalFree(Handle);
  77. *phNetInterface = NULL;
  78. return(ERROR_SUCCESS);
  79. }
  80. VOID
  81. HNETINTERFACE_RPC_rundown(
  82. IN HNETINTERFACE_RPC NetInterface
  83. )
  84. /*++
  85. Routine Description:
  86. RPC rundown procedure for a HNETINTERFACE_RPC. Just closes the handle.
  87. Arguments:
  88. NetInterface - Supplies the HNETINTERFACE_RPC that is to be rundown.
  89. Return Value:
  90. None.
  91. --*/
  92. {
  93. API_ASSERT_INIT();
  94. s_ApiCloseNetInterface(&NetInterface);
  95. }
  96. error_status_t
  97. s_ApiGetNetInterfaceState(
  98. IN HNETINTERFACE_RPC hNetInterface,
  99. OUT DWORD *lpState
  100. )
  101. /*++
  102. Routine Description:
  103. Returns the current state of the specified network interface.
  104. Arguments:
  105. hNetInterface - Supplies the network interface whose state is to be returned
  106. lpState - Returns the current state of the network interface
  107. Return Value:
  108. ERROR_SUCCESS if successful
  109. Win32 error code otherwise
  110. --*/
  111. {
  112. PNM_INTERFACE NetInterface;
  113. API_ASSERT_INIT();
  114. VALIDATE_NETINTERFACE_EXISTS(NetInterface, hNetInterface);
  115. *lpState = NmGetInterfaceState( NetInterface );
  116. return( ERROR_SUCCESS );
  117. }
  118. error_status_t
  119. s_ApiGetNetInterface(
  120. IN handle_t IDL_handle,
  121. IN LPCWSTR lpszNodeName,
  122. IN LPCWSTR lpszNetworkName,
  123. OUT LPWSTR *lppszInterfaceName
  124. )
  125. /*++
  126. Routine Description:
  127. Gets the network interface for the given node and network.
  128. Arguments:
  129. IDL_handle - RPC binding handle, not used.
  130. lpszNodeName - Supplies the node name
  131. lpszNetworkName - Supplies the network name
  132. lppszInterfaceName - Returns the interface name
  133. Return Value:
  134. ERROR_SUCCESS if successful
  135. Win32 error code otherwise
  136. --*/
  137. {
  138. API_ASSERT_INIT();
  139. return(NmGetInterfaceForNodeAndNetwork(
  140. lpszNodeName,
  141. lpszNetworkName,
  142. lppszInterfaceName
  143. ));
  144. }
  145. error_status_t
  146. s_ApiGetNetInterfaceId(
  147. IN HNETINTERFACE_RPC hNetInterface,
  148. OUT LPWSTR *pGuid
  149. )
  150. /*++
  151. Routine Description:
  152. Returns the unique identifier (GUID) for a network interface.
  153. Arguments:
  154. hNetInterface - Supplies the network interface whose identifer is to be
  155. returned
  156. pGuid - Returns the unique identifier. This memory must be freed on the
  157. client side.
  158. Return Value:
  159. ERROR_SUCCESS if successful
  160. Win32 error code otherwise.
  161. --*/
  162. {
  163. PNM_INTERFACE NetInterface;
  164. DWORD NameLen;
  165. LPCWSTR Name;
  166. VALIDATE_NETINTERFACE_EXISTS(NetInterface, hNetInterface);
  167. Name = OmObjectId(NetInterface);
  168. NameLen = (lstrlenW(Name)+1)*sizeof(WCHAR);
  169. *pGuid = MIDL_user_allocate(NameLen);
  170. if (*pGuid == NULL) {
  171. return(ERROR_NOT_ENOUGH_MEMORY);
  172. }
  173. CopyMemory(*pGuid, Name, NameLen);
  174. return(ERROR_SUCCESS);
  175. }