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.

252 lines
7.3 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1993.
  5. //
  6. // File: rpc.cxx
  7. //
  8. // Contents: RPC related routines.
  9. //
  10. // Classes: None.
  11. //
  12. // Functions: StartRpcServer
  13. // StopRpcServer
  14. //
  15. // RPC:
  16. //
  17. // History: 25-Oct-95 MarkBl Created.
  18. //
  19. //----------------------------------------------------------------------------
  20. #include "..\pch\headers.hxx"
  21. #pragma hdrstop
  22. #include "debug.hxx"
  23. #include "atsvc.h"
  24. #include "SASecRPC.h"
  25. RPC_BINDING_VECTOR * gpBindingVector = NULL;
  26. //
  27. // We have to register protocol sequences and known end points only once
  28. // per process.
  29. //
  30. BOOL gRegisteredProtocolSequences = FALSE;
  31. WCHAR * grgpwszProtocolSequences[] = {
  32. L"ncalrpc", // Local RPC
  33. L"ncacn_ip_tcp", // Connection-oriented TCP/IP
  34. L"ncacn_spx", // Connection-oriented SPX
  35. NULL
  36. };
  37. //+---------------------------------------------------------------------------
  38. //
  39. // Function: StartRpcServer
  40. //
  41. // Synopsis:
  42. //
  43. // Arguments: None.
  44. //
  45. // Returns: HRESULT
  46. //
  47. // Notes:
  48. //
  49. //----------------------------------------------------------------------------
  50. HRESULT
  51. StartRpcServer(void)
  52. {
  53. RPC_STATUS RpcStatus;
  54. HRESULT hr = S_OK;
  55. //
  56. // Register protocol sequences and known end points onlt if we have not
  57. // already done so in this process.
  58. //
  59. if (!gRegisteredProtocolSequences) {
  60. //
  61. // Support all available protocols.
  62. //
  63. // NB : Named pipe support is handled specifically below.
  64. //
  65. for (int i = 0; grgpwszProtocolSequences[i] != NULL; i++)
  66. {
  67. RpcStatus = RpcServerUseProtseq(grgpwszProtocolSequences[i],
  68. RPC_C_PROTSEQ_MAX_REQS_DEFAULT,
  69. NULL);
  70. if (RpcStatus != RPC_S_OK && RpcStatus != RPC_S_PROTSEQ_NOT_SUPPORTED)
  71. {
  72. //
  73. // Bail on error other than protseq not supported; may be out
  74. // of memory.
  75. //
  76. CHECK_HRESULT(HRESULT_FROM_WIN32(RpcStatus));
  77. goto RpcError;
  78. }
  79. }
  80. //
  81. // Now, explicitly handle named pipe support. Register a specific
  82. // endpoint for named pipes.
  83. //
  84. RpcStatus = RpcServerUseProtseqEp(L"ncacn_np",
  85. RPC_C_PROTSEQ_MAX_REQS_DEFAULT,
  86. L"\\PIPE\\atsvc",
  87. NULL);
  88. if (RpcStatus)
  89. {
  90. CHECK_HRESULT(HRESULT_FROM_WIN32(RpcStatus));
  91. goto RpcError;
  92. }
  93. gRegisteredProtocolSequences = TRUE;
  94. }
  95. //
  96. // Register the protocol handles with the endpoint-mapping service.
  97. //
  98. if (RpcStatus = RpcServerInqBindings(&gpBindingVector))
  99. {
  100. CHECK_HRESULT(HRESULT_FROM_WIN32(RpcStatus));
  101. return(HRESULT_FROM_WIN32(RpcStatus));
  102. }
  103. // AT service interface.
  104. //
  105. RpcStatus = RpcEpRegister(atsvc_ServerIfHandle,
  106. gpBindingVector,
  107. NULL,
  108. NULL);
  109. if (RpcStatus)
  110. {
  111. CHECK_HRESULT(HRESULT_FROM_WIN32(RpcStatus));
  112. goto RpcError;
  113. }
  114. // Scheduling Agent security interface.
  115. //
  116. RpcStatus = RpcEpRegister(sasec_ServerIfHandle,
  117. gpBindingVector,
  118. NULL,
  119. NULL);
  120. if (RpcStatus)
  121. {
  122. CHECK_HRESULT(HRESULT_FROM_WIN32(RpcStatus));
  123. goto RpcError;
  124. }
  125. //
  126. // Set up secure RPC. Note, if the RPC client doesn't explicitly state
  127. // they wish the RPC connection to be secured, the connection defaults
  128. // to non-secure.
  129. //
  130. if (RpcStatus = RpcServerRegisterAuthInfo(NULL,
  131. RPC_C_AUTHN_WINNT,
  132. NULL,
  133. NULL))
  134. {
  135. if (RpcStatus == RPC_S_UNKNOWN_AUTHN_SERVICE)
  136. {
  137. //
  138. // This happens when NTLMSSP -- which is used for authentication
  139. // on the named pipes transport -- is not installed. Typically
  140. // happens when "Client for Microsoft Networks" is not installed.
  141. // However, local users can still be authenticated by LRPC.
  142. //
  143. // Note, if "Client for Microsoft Networks" is subsequently
  144. // installed, remote callers will get RPC_S_UNKNOWN_AUTHN_SERVICE
  145. // until the service is restarted. BUGBUG Fix this by noticing
  146. // the PNP event that indicates the net has arrived, and then
  147. // calling RpcServerRegisterAuthInfo again.
  148. //
  149. schDebugOut((DEB_ERROR, "**** No authentication provider is "
  150. "installed. Remote clients will get error "
  151. "RPC_S_UNKNOWN_AUTHN_SERVICE.\n"));
  152. }
  153. else
  154. {
  155. CHECK_HRESULT(HRESULT_FROM_WIN32(RpcStatus));
  156. goto RpcError;
  157. }
  158. }
  159. //
  160. // Finally, register the interface(s) and listen on them.
  161. //
  162. if (RpcStatus = RpcServerRegisterIfEx(atsvc_ServerIfHandle,
  163. NULL,
  164. NULL,
  165. RPC_IF_AUTOLISTEN,
  166. RPC_C_LISTEN_MAX_CALLS_DEFAULT,
  167. NULL))
  168. {
  169. CHECK_HRESULT(HRESULT_FROM_WIN32(RpcStatus));
  170. goto RpcError;
  171. }
  172. if (RpcStatus = RpcServerRegisterIfEx(sasec_ServerIfHandle,
  173. NULL,
  174. NULL,
  175. RPC_IF_AUTOLISTEN,
  176. RPC_C_LISTEN_MAX_CALLS_DEFAULT,
  177. NULL))
  178. {
  179. CHECK_HRESULT(HRESULT_FROM_WIN32(RpcStatus));
  180. goto RpcError;
  181. }
  182. return(S_OK);
  183. RpcError:
  184. if (gpBindingVector != NULL)
  185. {
  186. RpcBindingVectorFree(&gpBindingVector);
  187. gpBindingVector = NULL;
  188. }
  189. return(HRESULT_FROM_WIN32(RpcStatus));
  190. }
  191. //+---------------------------------------------------------------------------
  192. //
  193. // Function: StopRpcServer
  194. //
  195. // Synopsis: Stop the RPC server.
  196. //
  197. // Arguments: None.
  198. //
  199. // Returns: HRESULT
  200. //
  201. // Notes: None.
  202. //
  203. //----------------------------------------------------------------------------
  204. void
  205. StopRpcServer(void)
  206. {
  207. RpcServerUnregisterIf(atsvc_ServerIfHandle, NULL, 0);
  208. RpcServerUnregisterIf(sasec_ServerIfHandle, NULL, 0);
  209. if (gpBindingVector != NULL)
  210. {
  211. RpcEpUnregister(atsvc_ServerIfHandle, gpBindingVector, NULL);
  212. RpcEpUnregister(sasec_ServerIfHandle, gpBindingVector, NULL);
  213. RpcBindingVectorFree(&gpBindingVector);
  214. gpBindingVector = NULL;
  215. }
  216. }