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.

254 lines
9.4 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. apip.h
  5. Abstract:
  6. Private data structures and procedure prototypes for
  7. the Cluster API subcomponent of the NT Cluster
  8. Service
  9. Author:
  10. John Vert (jvert) 7-Feb-1996
  11. Revision History:
  12. --*/
  13. #include "service.h"
  14. #include "clusapi.h"
  15. #include "api_rpc.h"
  16. #define LOG_CURRENT_MODULE LOG_MODULE_API
  17. //
  18. // Event processing routine
  19. //
  20. DWORD
  21. WINAPI
  22. ApipEventHandler(
  23. IN CLUSTER_EVENT Event,
  24. IN PVOID Context
  25. );
  26. //
  27. // Data definitions global to the API module.
  28. //
  29. typedef enum _API_INIT_STATE {
  30. ApiStateUninitialized,
  31. ApiStateOffline,
  32. ApiStateReadOnly,
  33. ApiStateOnline
  34. } API_INIT_STATE;
  35. extern API_INIT_STATE ApiState;
  36. extern LIST_ENTRY NotifyListHead;
  37. extern CRITICAL_SECTION NotifyListLock;
  38. #define API_CHECK_INIT() \
  39. if (ApiState != ApiStateOnline) return(ERROR_SHARING_PAUSED)
  40. #define API_ASSERT_INIT() CL_ASSERT(ApiState == ApiStateOnline)
  41. //
  42. // Notification port
  43. //
  44. typedef struct _NOTIFY_PORT {
  45. LIST_ENTRY ListEntry;
  46. CRITICAL_SECTION Lock;
  47. CL_QUEUE Queue;
  48. DWORD Filter;
  49. LIST_ENTRY InterestList;
  50. LIST_ENTRY RegistryList;
  51. } NOTIFY_PORT, *PNOTIFY_PORT;
  52. //
  53. // Common API handle structure. Every RPC context handle points to one of these.
  54. // This allows us to do our own type checking since RPC does not do this for us.
  55. //
  56. #define API_NOTIFY_HANDLE 1
  57. #define API_NODE_HANDLE 2
  58. #define API_GROUP_HANDLE 3
  59. #define API_RESOURCE_HANDLE 4
  60. #define API_KEY_HANDLE 5
  61. #define API_CLUSTER_HANDLE 6
  62. #define API_NETWORK_HANDLE 7
  63. #define API_NETINTERFACE_HANDLE 8
  64. #define HANDLE_DELETED 1
  65. typedef struct _API_HANDLE {
  66. USHORT Type;
  67. USHORT Flags;
  68. LIST_ENTRY NotifyList;
  69. union {
  70. PNOTIFY_PORT Notify;
  71. PNM_NODE Node;
  72. PFM_GROUP Group;
  73. PFM_RESOURCE Resource;
  74. HDMKEY Key;
  75. PVOID Cluster;
  76. PNM_NETWORK Network;
  77. PNM_INTERFACE NetInterface;
  78. };
  79. } API_HANDLE, *PAPI_HANDLE;
  80. #define DELETE_HANDLE(_handle_) (((PAPI_HANDLE)(_handle_))->Flags |= HANDLE_DELETED)
  81. #define IS_HANDLE_DELETED(_handle_) (((PAPI_HANDLE)(_handle_))->Flags & HANDLE_DELETED)
  82. #define VALIDATE_NOTIFY(_notify_, _handle_) \
  83. if (((_handle_) == NULL) || \
  84. (((PAPI_HANDLE)(_handle_))->Type != API_NOTIFY_HANDLE) || \
  85. IS_HANDLE_DELETED(_handle_)) { \
  86. return(ERROR_INVALID_HANDLE); \
  87. } else { \
  88. (_notify_) = ((PAPI_HANDLE)(_handle_))->Notify; \
  89. }
  90. #define VALIDATE_NODE(_node_, _handle_) \
  91. if ((_handle_ == NULL) || \
  92. (((PAPI_HANDLE)(_handle_))->Type != API_NODE_HANDLE)) { \
  93. return(ERROR_INVALID_HANDLE); \
  94. } else { \
  95. (_node_) = ((PAPI_HANDLE)(_handle_))->Node; \
  96. }
  97. #define VALIDATE_NODE_EXISTS(_node_, _handle_) \
  98. if ((_handle_ == NULL) || \
  99. (((PAPI_HANDLE)(_handle_))->Type != API_NODE_HANDLE)) { \
  100. return(ERROR_INVALID_HANDLE); \
  101. } else { \
  102. (_node_) = ((PAPI_HANDLE)(_handle_))->Node; \
  103. if (!OmObjectInserted((_node_))) { \
  104. return(ERROR_NODE_NOT_AVAILABLE); \
  105. } \
  106. }
  107. #define VALIDATE_GROUP(_group_, _handle_) \
  108. if ((_handle_ == NULL) || \
  109. (((PAPI_HANDLE)(_handle_))->Type != API_GROUP_HANDLE)) { \
  110. return(ERROR_INVALID_HANDLE); \
  111. } else { \
  112. (_group_) = ((PAPI_HANDLE)(_handle_))->Group; \
  113. }
  114. #define VALIDATE_GROUP_EXISTS(_group_, _handle_) \
  115. if ((_handle_ == NULL) || \
  116. (((PAPI_HANDLE)(_handle_))->Type != API_GROUP_HANDLE)) { \
  117. return(ERROR_INVALID_HANDLE); \
  118. } else { \
  119. (_group_) = ((PAPI_HANDLE)(_handle_))->Group; \
  120. if (!OmObjectInserted((_group_))) { \
  121. return(ERROR_GROUP_NOT_AVAILABLE); \
  122. } \
  123. }
  124. #define VALIDATE_RESOURCE(_resource_, _handle_) \
  125. if ((_handle_ == NULL) || \
  126. (((PAPI_HANDLE)(_handle_))->Type != API_RESOURCE_HANDLE)) { \
  127. return(ERROR_INVALID_HANDLE); \
  128. } else { \
  129. (_resource_) = ((PAPI_HANDLE)(_handle_))->Resource; \
  130. }
  131. #define VALIDATE_RESOURCE_EXISTS(_resource_, _handle_) \
  132. if ((_handle_ == NULL) || \
  133. (((PAPI_HANDLE)(_handle_))->Type != API_RESOURCE_HANDLE)) { \
  134. return(ERROR_INVALID_HANDLE); \
  135. } else { \
  136. (_resource_) = ((PAPI_HANDLE)(_handle_))->Resource; \
  137. if (!OmObjectInserted((_resource_))) { \
  138. return(ERROR_RESOURCE_NOT_AVAILABLE); \
  139. } \
  140. }
  141. #define VALIDATE_KEY(_key_, _handle_) \
  142. if ((_handle_ == NULL) || \
  143. (((PAPI_HANDLE)(_handle_))->Type != API_KEY_HANDLE)) { \
  144. return(ERROR_INVALID_HANDLE); \
  145. } else { \
  146. (_key_) = ((PAPI_HANDLE)(_handle_))->Key; \
  147. }
  148. #define VALIDATE_NETWORK(_network_, _handle_) \
  149. if ((_handle_ == NULL) || \
  150. (((PAPI_HANDLE)(_handle_))->Type != API_NETWORK_HANDLE)) { \
  151. return(ERROR_INVALID_HANDLE); \
  152. } else { \
  153. (_network_) = ((PAPI_HANDLE)(_handle_))->Network; \
  154. }
  155. #define VALIDATE_NETWORK_EXISTS(_network_, _handle_) \
  156. if ((_handle_ == NULL) || \
  157. (((PAPI_HANDLE)(_handle_))->Type != API_NETWORK_HANDLE)) { \
  158. return(ERROR_INVALID_HANDLE); \
  159. } else { \
  160. (_network_) = ((PAPI_HANDLE)(_handle_))->Network; \
  161. if (!OmObjectInserted((_network_))) { \
  162. return(ERROR_NETWORK_NOT_AVAILABLE); \
  163. } \
  164. }
  165. #define VALIDATE_NETINTERFACE(_netinterface_, _handle_) \
  166. if ((_handle_ == NULL) || \
  167. (((PAPI_HANDLE)(_handle_))->Type != API_NETINTERFACE_HANDLE)) { \
  168. return(ERROR_INVALID_HANDLE); \
  169. } else { \
  170. (_netinterface_) = ((PAPI_HANDLE)(_handle_))->NetInterface; \
  171. }
  172. #define VALIDATE_NETINTERFACE_EXISTS(_netinterface_, _handle_) \
  173. if ((_handle_ == NULL) || \
  174. (((PAPI_HANDLE)(_handle_))->Type != API_NETINTERFACE_HANDLE)) { \
  175. return(ERROR_INVALID_HANDLE); \
  176. } else { \
  177. (_netinterface_) = ((PAPI_HANDLE)(_handle_))->NetInterface; \
  178. if (!OmObjectInserted((_netinterface_))) { \
  179. return(ERROR_NETWORK_NOT_AVAILABLE); \
  180. } \
  181. }
  182. //
  183. // Common routines
  184. //
  185. #define INITIAL_ENUM_LIST_ALLOCATION 8
  186. #define ENUM_SIZE(Entries) ((Entries-1) * sizeof(ENUM_ENTRY) + sizeof(ENUM_LIST))
  187. VOID
  188. ApipAddToEnum(
  189. IN PENUM_LIST *pEnum,
  190. IN DWORD *pAllocated,
  191. IN LPCWSTR Name,
  192. IN DWORD Type
  193. );
  194. LPWSTR
  195. ApipGetObjectName(
  196. IN PVOID Object
  197. );
  198. VOID
  199. ApipRundownNotify(
  200. IN PAPI_HANDLE Handle
  201. );
  202. RPC_STATUS
  203. ApipConnectCallback(
  204. IN RPC_IF_ID * Interface,
  205. IN void * Context
  206. );
  207. DWORD
  208. ApipUnblockGetNotifyCall(
  209. PNOTIFY_PORT pPort
  210. );