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.

262 lines
5.8 KiB

  1. /*++
  2. Copyright (c) 1990 Microsoft Corporation
  3. Module Name:
  4. scbind.c
  5. Abstract:
  6. Contains the RPC bind and un-bind routines for the Service Controller.
  7. Author:
  8. Dan Lafferty (danl) 19-Mar-1991
  9. Environment:
  10. User Mode -Win32
  11. Revision History:
  12. 19-Mar-1991 danl
  13. created
  14. --*/
  15. //
  16. // INCLUDES
  17. //
  18. extern "C"
  19. {
  20. #include <nt.h> // DbgPrint prototype
  21. }
  22. #include <rpc.h> // DataTypes and runtime APIs
  23. #include <svcctl.h> // generated by the MIDL compiler
  24. #include <ntrpcp.h> // RpcUtils for binding
  25. #include <sclib.h> // ansi to unicode conversion functions.
  26. #include <scdebug.h> // SCC_LOG
  27. #include <sclib.h> // ScConvertToUnicode
  28. //
  29. // GLOBALS - This handle maintains a static binding for status
  30. // messages between the service process and the service
  31. // controller.
  32. //
  33. static handle_t StatusBindHandle;
  34. RPC_STATUS
  35. InitializeStatusBinding( VOID)
  36. /*++
  37. Routine Description:
  38. This routine initializes the global StatusBindHandle that is used for
  39. the status connection to the service controller. This routine is called
  40. by the Service Process (NetServiceStartCtrlDispatcher) when it starts up.
  41. Arguments:
  42. none
  43. Return Value:
  44. NERR_Success - (or 0) if the operation was successful.
  45. Otherwise, it returns any RPC failure status that can be returned
  46. from RpcBindToInterface.
  47. --*/
  48. {
  49. RPC_STATUS status;
  50. status = RpcpBindRpc (
  51. NULL,
  52. L"svcctl",
  53. 0,
  54. &StatusBindHandle);
  55. SCC_LOG(TRACE,"InitializeStatusBinding:RpcpBindRpc status=%d\n", status);
  56. SCC_LOG(TRACE,"InitializeStatusBinding: handle=%d\n",StatusBindHandle);
  57. return(status);
  58. }
  59. /****************************************************************************/
  60. handle_t
  61. SVCCTL_HANDLEW_bind (
  62. SVCCTL_HANDLEW ServerName
  63. )
  64. /*++
  65. Routine Description:
  66. This routine calls a common bind routine that is shared by all services.
  67. This routine is called from the service controller client stubs when
  68. it is necessary to bind to a server.
  69. Arguments:
  70. ServerName - A pointer to a string containing the name of the server
  71. to bind with.
  72. Return Value:
  73. The binding handle is returned to the stub routine. If the
  74. binding is unsuccessful, a NULL will be returned.
  75. --*/
  76. {
  77. handle_t bindingHandle;
  78. RPC_STATUS status;
  79. status = RpcpBindRpc (
  80. ServerName,
  81. L"svcctl",
  82. L"Security=Impersonation Dynamic False",
  83. &bindingHandle);
  84. SCC_LOG(TRACE,"SVCCTL_HANDLEW_bind:RpcpBindRpc status=%d\n",status);
  85. SCC_LOG(TRACE,"SVCCTL_HANDLEW_bind: handle=%d\n",bindingHandle);
  86. return( bindingHandle);
  87. }
  88. /****************************************************************************/
  89. void
  90. SVCCTL_HANDLEW_unbind (
  91. SVCCTL_HANDLEW ServerName,
  92. handle_t BindingHandle
  93. )
  94. /*++
  95. Routine Description:
  96. This routine calls a common unbind routine that is shared by
  97. all services.
  98. This routine is called from the Service Controller client stubs when
  99. it is necessary to unbind to a server.
  100. Arguments:
  101. ServerName - This is the name of the server from which to unbind.
  102. BindingHandle - This is the binding handle that is to be closed.
  103. Return Value:
  104. none.
  105. --*/
  106. {
  107. UNREFERENCED_PARAMETER(ServerName); // This parameter is not used
  108. SCC_LOG(TRACE,"SVCCTL_HANDLEW_unbind: handle=%d\n",BindingHandle);
  109. RpcpUnbindRpc ( BindingHandle);
  110. return;
  111. }
  112. /****************************************************************************/
  113. handle_t
  114. SVCCTL_HANDLEA_bind (
  115. SVCCTL_HANDLEA ServerName
  116. )
  117. /*++
  118. Routine Description:
  119. This routine calls a common bind routine that is shared by all services.
  120. This routine is called from the service controller client stubs when
  121. it is necessary to bind to a server.
  122. Arguments:
  123. ServerName - A pointer to a string containing the name of the server
  124. to bind with.
  125. Return Value:
  126. The binding handle is returned to the stub routine. If the
  127. binding is unsuccessful, a NULL will be returned.
  128. --*/
  129. {
  130. handle_t bindingHandle;
  131. RPC_STATUS status;
  132. LPWSTR pServerNameW = NULL;
  133. if (ServerName != NULL) {
  134. if (!ScConvertToUnicode(&pServerNameW, ServerName)) {
  135. SCC_LOG(ERROR,"SVCCTL_HANDLEA_bind:ScConvertToUnicode failed\n",0);
  136. return(NULL);
  137. }
  138. }
  139. status = RpcpBindRpc (
  140. pServerNameW,
  141. L"svcctl",
  142. L"Security=Impersonation Dynamic False",
  143. &bindingHandle);
  144. (void) LocalFree(pServerNameW);
  145. SCC_LOG(TRACE,"SVCCTL_HANDLEA_bind:RpcpBindRpc status=%d\n",status);
  146. SCC_LOG(TRACE,"SVCCTL_HANDLEA_bind: handle=%d\n",bindingHandle);
  147. return( bindingHandle);
  148. }
  149. /****************************************************************************/
  150. void
  151. SVCCTL_HANDLEA_unbind (
  152. SVCCTL_HANDLEA ServerName,
  153. handle_t BindingHandle
  154. )
  155. /*++
  156. Routine Description:
  157. This routine calls a common unbind routine that is shared by
  158. all services.
  159. This routine is called from the Service Controller client stubs when
  160. it is necessary to unbind to a server.
  161. Arguments:
  162. ServerName - This is the name of the server from which to unbind.
  163. BindingHandle - This is the binding handle that is to be closed.
  164. Return Value:
  165. none.
  166. --*/
  167. {
  168. UNREFERENCED_PARAMETER(ServerName); // This parameter is not used
  169. SCC_LOG(TRACE,"SVCCTL_HANDLEA_unbind: handle=%d\n",BindingHandle);
  170. RpcpUnbindRpc ( BindingHandle);
  171. return;
  172. }
  173.