Source code of Windows XP (NT5)
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.

207 lines
5.4 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. clussprt.c
  5. Abstract:
  6. Public interfaces for managing clusters.
  7. Author:
  8. Sunita Shrivastava (sunitas) 15-Jan-1997
  9. Revision History:
  10. --*/
  11. #include "clusprtp.h"
  12. //
  13. // General Cluster Support Routines for base components
  14. //
  15. /****
  16. @doc EXTERNAL INTERFACES CLUSSVC CLUSSPRT EVTLOG
  17. ****/
  18. /****
  19. @func HANDLE WINAPI | BindToClusterSvc| This returns a handle via which
  20. you can talk to the cluster service.
  21. @parm IN LPWSTR | lpszClusterName | A pointer to the cluster name. If NULL,
  22. this connects to the local cluster service.
  23. @rdesc Returns a handle to the binding if successful, else returns NULL.
  24. Error can be obtained by calling GetLastError().
  25. @comm The handle obtained from this must be passed on to other apis exported
  26. by this module. It must be freed eventually by calling UnbindFromClusterSvc().
  27. @xref <f UnbindFromClusterSvc>
  28. ****/
  29. HANDLE
  30. WINAPI
  31. BindToClusterSvc(IN LPWSTR lpszClusterName)
  32. {
  33. WCHAR *pBinding = NULL;
  34. PCLUSTER_SPRT pCluster;
  35. DWORD Status = ERROR_SUCCESS;
  36. pCluster = LocalAlloc(LMEM_ZEROINIT, sizeof(CLUSTER_SPRT));
  37. if (pCluster == NULL) {
  38. Status = ERROR_NOT_ENOUGH_MEMORY;
  39. SetLastError( Status );
  40. return NULL;
  41. }
  42. pCluster->dwSignature = CLUSTER_SPRT_SIGNATURE;
  43. if ((lpszClusterName == NULL) ||
  44. (lpszClusterName[0] == '\0'))
  45. {
  46. Status = RpcStringBindingComposeW(L"b97db8b2-4c63-11cf-bff6-08002be23f2f",
  47. L"ncalrpc",
  48. NULL,
  49. L"clusapi",
  50. NULL,
  51. &pBinding);
  52. if (Status != RPC_S_OK)
  53. {
  54. goto FnExit;
  55. }
  56. }
  57. else
  58. {
  59. //
  60. // Try to connect directly to the cluster.
  61. //
  62. Status = RpcStringBindingComposeW(L"b97db8b2-4c63-11cf-bff6-08002be23f2f",
  63. L"ncacn_np",
  64. (LPWSTR)lpszClusterName,
  65. L"\\pipe\\clusapi",
  66. NULL,
  67. &pBinding);
  68. if (Status != RPC_S_OK) {
  69. goto FnExit;
  70. }
  71. }
  72. //bind to the cluster svc and save the binding handle
  73. Status = RpcBindingFromStringBindingW(pBinding, &pCluster->RpcBinding);
  74. RpcStringFreeW(&pBinding);
  75. if (Status != RPC_S_OK) {
  76. goto FnExit;
  77. }
  78. Status = RpcBindingSetAuthInfoW(pCluster->RpcBinding,
  79. L"CLUSAPI",
  80. RPC_C_AUTHN_LEVEL_CONNECT,
  81. RPC_C_AUTHN_WINNT,
  82. NULL,
  83. RPC_C_AUTHZ_NAME);
  84. FnExit:
  85. if (Status != ERROR_SUCCESS)
  86. {
  87. SetLastError(Status);
  88. if (pCluster->RpcBinding)
  89. RpcBindingFree(&(pCluster->RpcBinding));
  90. LocalFree(pCluster);
  91. pCluster=NULL;
  92. }
  93. return((HANDLE)pCluster);
  94. }
  95. /****
  96. @func DWORD | UnbindFromClusterSvc| This initializes the cluster
  97. wide eventlog replicating services.
  98. @parm IN HANDLE | hCluster | A handle to the binding context obtained
  99. via BindToClusterSvc().
  100. @rdesc Returns a result code. ERROR_SUCCESS on success.
  101. @comm Frees the context related with this binding.
  102. @xref <f UnbindFromClusterSvc>
  103. ****/
  104. DWORD
  105. WINAPI
  106. UnbindFromClusterSvc(IN HANDLE hCluster)
  107. {
  108. DWORD Status = ERROR_SUCCESS;
  109. PCLUSTER_SPRT pCluster = (PCLUSTER_SPRT)hCluster;
  110. if (!pCluster || (pCluster->dwSignature != CLUSTER_SPRT_SIGNATURE) || !(pCluster->RpcBinding))
  111. {
  112. Status = ERROR_INVALID_PARAMETER;
  113. goto FnExit;
  114. }
  115. RpcBindingFree(&(pCluster->RpcBinding));
  116. LocalFree(pCluster);
  117. FnExit:
  118. return(Status);
  119. }
  120. /****
  121. @func DWORD | PropagateEvents| This eventlog service calls the
  122. local cluster service via this api to propagate events
  123. within a cluster.
  124. @parm IN HANDLE | hCluster | handle to a cluster binding context
  125. returned by BindToClusterSvc().
  126. @parm IN DWORD | dwEventInfoSize | Size of the event info structure
  127. that contains the events to be propagated.
  128. @parm IN PPACKEDEVENTINFO| pPackedEventInfo | A pointer to the packed
  129. event information structure.
  130. @rdesc Returns a result code. ERROR_SUCCESS on success.
  131. @comm This calls ApiEvPropEvents() in the cluster via lrpc.
  132. @xref <f BindToClusterSvc>
  133. ****/
  134. DWORD
  135. WINAPI
  136. PropagateEvents(
  137. IN HANDLE hCluster,
  138. IN DWORD dwEventInfoSize,
  139. IN PPACKEDEVENTINFO pPackedEventInfo)
  140. {
  141. DWORD Status=ERROR_SUCCESS;
  142. PCLUSTER_SPRT pCluster=(PCLUSTER_SPRT)hCluster;
  143. if (!pCluster || (pCluster->dwSignature != CLUSTER_SPRT_SIGNATURE) || !(pCluster->RpcBinding))
  144. {
  145. Status = ERROR_INVALID_PARAMETER;
  146. goto FnExit;
  147. }
  148. RpcTryExcept {
  149. //call the cluster service
  150. ApiEvPropEvents(pCluster->RpcBinding,
  151. dwEventInfoSize, (UCHAR *)pPackedEventInfo);
  152. }
  153. RpcExcept (I_RpcExceptionFilter(RpcExceptionCode())) {
  154. //SS: dont do anything -
  155. }
  156. RpcEndExcept
  157. FnExit:
  158. return(Status);
  159. }