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.

288 lines
4.7 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. network.c
  5. Abstract:
  6. Server side support for Cluster APIs dealing with networks
  7. Author:
  8. John Vert (jvert) 7-Mar-1996
  9. Revision History:
  10. --*/
  11. #include "apip.h"
  12. HNETWORK_RPC
  13. s_ApiOpenNetwork(
  14. IN handle_t IDL_handle,
  15. IN LPCWSTR lpszNetworkName,
  16. OUT error_status_t *Status
  17. )
  18. /*++
  19. Routine Description:
  20. Opens a handle to an existing network object.
  21. Arguments:
  22. IDL_handle - RPC binding handle, not used.
  23. lpszNetworkName - Supplies the name of the network to open.
  24. Status - Returns any error that may occur.
  25. Return Value:
  26. A context handle to a network object if successful
  27. NULL otherwise.
  28. --*/
  29. {
  30. PAPI_HANDLE Handle;
  31. HNETWORK_RPC Network;
  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. Network = OmReferenceObjectByName(ObjectTypeNetwork, lpszNetworkName);
  42. if (Network == NULL) {
  43. LocalFree(Handle);
  44. *Status = ERROR_CLUSTER_NETWORK_NOT_FOUND;
  45. return(NULL);
  46. }
  47. Handle->Type = API_NETWORK_HANDLE;
  48. Handle->Flags = 0;
  49. Handle->Network = Network;
  50. InitializeListHead(&Handle->NotifyList);
  51. *Status = ERROR_SUCCESS;
  52. return(Handle);
  53. }
  54. error_status_t
  55. s_ApiCloseNetwork(
  56. IN OUT HNETWORK_RPC *phNetwork
  57. )
  58. /*++
  59. Routine Description:
  60. Closes an open network context handle.
  61. Arguments:
  62. Network - Supplies a pointer to the HNETWORK_RPC to be closed.
  63. Returns NULL
  64. Return Value:
  65. None.
  66. --*/
  67. {
  68. PNM_NETWORK Network;
  69. PAPI_HANDLE Handle;
  70. API_ASSERT_INIT();
  71. VALIDATE_NETWORK(Network, *phNetwork);
  72. Handle = (PAPI_HANDLE)*phNetwork;
  73. ApipRundownNotify(Handle);
  74. OmDereferenceObject(Network);
  75. LocalFree(Handle);
  76. *phNetwork = NULL;
  77. return(ERROR_SUCCESS);
  78. }
  79. VOID
  80. HNETWORK_RPC_rundown(
  81. IN HNETWORK_RPC Network
  82. )
  83. /*++
  84. Routine Description:
  85. RPC rundown procedure for a HNETWORK_RPC. Just closes the handle.
  86. Arguments:
  87. Network - Supplies the HNETWORK_RPC that is to be rundown.
  88. Return Value:
  89. None.
  90. --*/
  91. {
  92. API_ASSERT_INIT();
  93. s_ApiCloseNetwork(&Network);
  94. }
  95. error_status_t
  96. s_ApiGetNetworkState(
  97. IN HNETWORK_RPC hNetwork,
  98. OUT DWORD *lpState
  99. )
  100. /*++
  101. Routine Description:
  102. Returns the current state of the specified network.
  103. Arguments:
  104. hNetwork - Supplies the network whose state is to be returned.
  105. lpState - Returns the current state of the network
  106. Return Value:
  107. ERROR_SUCCESS if successful
  108. Win32 error code otherwise
  109. --*/
  110. {
  111. PNM_NETWORK Network;
  112. API_ASSERT_INIT();
  113. VALIDATE_NETWORK_EXISTS(Network, hNetwork);
  114. *lpState = NmGetNetworkState( Network );
  115. return( ERROR_SUCCESS );
  116. }
  117. error_status_t
  118. s_ApiSetNetworkName(
  119. IN HNETWORK_RPC hNetwork,
  120. IN LPCWSTR lpszNetworkName
  121. )
  122. /*++
  123. Routine Description:
  124. Sets the new friendly name of a network.
  125. Arguments:
  126. hNetwork - Supplies the network whose name is to be set.
  127. lpszNetworkName - Supplies the new name of hNetwork
  128. Return Value:
  129. ERROR_SUCCESS if successful
  130. Win32 error code otherwise
  131. --*/
  132. {
  133. PNM_NETWORK Network;
  134. HDMKEY NetworkKey;
  135. DWORD Status = ERROR_INVALID_FUNCTION;
  136. API_ASSERT_INIT();
  137. VALIDATE_NETWORK_EXISTS(Network, hNetwork);
  138. Status = NmSetNetworkName(
  139. Network,
  140. lpszNetworkName
  141. );
  142. return(Status);
  143. }
  144. error_status_t
  145. s_ApiGetNetworkId(
  146. IN HNETWORK_RPC hNetwork,
  147. OUT LPWSTR *pGuid
  148. )
  149. /*++
  150. Routine Description:
  151. Returns the unique identifier (GUID) for a network.
  152. Arguments:
  153. hNetwork - Supplies the network whose identifer is to be returned
  154. pGuid - Returns the unique identifier. This memory must be freed on the
  155. client side.
  156. Return Value:
  157. ERROR_SUCCESS if successful
  158. Win32 error code otherwise.
  159. --*/
  160. {
  161. PNM_NETWORK Network;
  162. DWORD NameLen;
  163. LPCWSTR Name;
  164. VALIDATE_NETWORK_EXISTS(Network, hNetwork);
  165. Name = OmObjectId(Network);
  166. NameLen = (lstrlenW(Name)+1)*sizeof(WCHAR);
  167. *pGuid = MIDL_user_allocate(NameLen);
  168. if (*pGuid == NULL) {
  169. return(ERROR_NOT_ENOUGH_MEMORY);
  170. }
  171. CopyMemory(*pGuid, Name, NameLen);
  172. return(ERROR_SUCCESS);
  173. }