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.

232 lines
5.2 KiB

  1. /*++
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. rpcserv.c
  5. Abstract:
  6. This module contains the RPC server startup
  7. and shutdown code.
  8. Author:
  9. abhisheV 30-September-1999
  10. Environment:
  11. User Level: Win32
  12. Revision History:
  13. --*/
  14. #include "precomp.h"
  15. DWORD
  16. SPDStartRPCServer(
  17. )
  18. {
  19. DWORD dwStatus = 0;
  20. WCHAR * pszPrincipalName = NULL;
  21. RPC_BINDING_VECTOR * pBindingVector = NULL;
  22. //
  23. // Register dynamic end-point (Used to be static np in prior versions)
  24. dwStatus = RpcServerUseProtseq(
  25. L"ncacn_np",
  26. 10,
  27. NULL
  28. );
  29. if (dwStatus) {
  30. return (dwStatus);
  31. }
  32. dwStatus = RpcServerUseProtseq(
  33. L"ncalrpc",
  34. 10,
  35. NULL
  36. );
  37. if (dwStatus) {
  38. return (dwStatus);
  39. }
  40. dwStatus = RpcServerInqBindings(&pBindingVector);
  41. if (dwStatus) {
  42. return (dwStatus);
  43. }
  44. dwStatus = RpcEpRegister(
  45. winipsec_ServerIfHandle,
  46. pBindingVector,
  47. NULL,
  48. L"IPSec Policy agent endpoint"
  49. );
  50. if (dwStatus) {
  51. RpcBindingVectorFree(&pBindingVector);
  52. return (dwStatus);
  53. }
  54. RpcBindingVectorFree(&pBindingVector);
  55. dwStatus = RpcServerRegisterIf(
  56. winipsec_ServerIfHandle,
  57. 0,
  58. 0
  59. );
  60. if (dwStatus) {
  61. return (dwStatus);
  62. }
  63. dwStatus = RpcServerRegisterAuthInfo(
  64. 0,
  65. RPC_C_AUTHN_WINNT,
  66. 0,
  67. 0
  68. );
  69. if (dwStatus) {
  70. (VOID) RpcServerUnregisterIfEx(
  71. winipsec_ServerIfHandle,
  72. 0,
  73. 0
  74. );
  75. return (dwStatus);
  76. }
  77. dwStatus = RpcServerInqDefaultPrincNameW(
  78. RPC_C_AUTHN_GSS_KERBEROS,
  79. &pszPrincipalName
  80. );
  81. if (dwStatus == RPC_S_INVALID_AUTH_IDENTITY) {
  82. dwStatus = ERROR_SUCCESS;
  83. pszPrincipalName = NULL;
  84. }
  85. if (dwStatus) {
  86. (VOID) RpcServerUnregisterIfEx(
  87. winipsec_ServerIfHandle,
  88. 0,
  89. 0
  90. );
  91. return (dwStatus);
  92. }
  93. dwStatus = RpcServerRegisterAuthInfo(
  94. pszPrincipalName,
  95. RPC_C_AUTHN_GSS_KERBEROS,
  96. 0,
  97. 0
  98. );
  99. if (dwStatus) {
  100. (VOID) RpcServerUnregisterIfEx(
  101. winipsec_ServerIfHandle,
  102. 0,
  103. 0
  104. );
  105. RpcStringFree(&pszPrincipalName);
  106. return (dwStatus);
  107. }
  108. dwStatus = RpcServerRegisterAuthInfo(
  109. pszPrincipalName,
  110. RPC_C_AUTHN_GSS_NEGOTIATE,
  111. 0,
  112. 0
  113. );
  114. if (dwStatus) {
  115. (VOID) RpcServerUnregisterIfEx(
  116. winipsec_ServerIfHandle,
  117. 0,
  118. 0
  119. );
  120. RpcStringFree(&pszPrincipalName);
  121. return (dwStatus);
  122. }
  123. RpcStringFree(&pszPrincipalName);
  124. #if !defined(__IN_LSASS__)
  125. EnterCriticalSection(&gcServerListenSection);
  126. gdwServersListening++;
  127. if (gdwServersListening == 1) {
  128. dwStatus = RpcServerListen(
  129. 3,
  130. RPC_C_LISTEN_MAX_CALLS_DEFAULT,
  131. TRUE
  132. );
  133. if (dwStatus) {
  134. LeaveCriticalSection(&gcServerListenSection);
  135. (VOID) RpcServerUnregisterIfEx(
  136. winipsec_ServerIfHandle,
  137. 0,
  138. 0
  139. );
  140. return (dwStatus);
  141. }
  142. }
  143. LeaveCriticalSection(&gcServerListenSection);
  144. #endif
  145. gbSPDRPCServerUp = TRUE;
  146. return (dwStatus);
  147. }
  148. DWORD
  149. SPDStopRPCServer(
  150. )
  151. {
  152. DWORD dwStatus = 0;
  153. RPC_BINDING_VECTOR * pBindingVector = NULL;
  154. dwStatus = RpcServerInqBindings(&pBindingVector);
  155. if (!dwStatus) {
  156. dwStatus = RpcEpUnregister(
  157. winipsec_ServerIfHandle,
  158. pBindingVector,
  159. NULL
  160. );
  161. RpcBindingVectorFree(&pBindingVector);
  162. }
  163. dwStatus = RpcServerUnregisterIfEx(
  164. winipsec_ServerIfHandle,
  165. 0,
  166. 0
  167. );
  168. #if !defined(__IN_LSASS__)
  169. EnterCriticalSection(&gcServerListenSection);
  170. gdwServersListening--;
  171. if (gdwServersListening == 0) {
  172. RpcMgmtStopServerListening(0);
  173. }
  174. LeaveCriticalSection(&gcServerListenSection);
  175. #endif
  176. return (dwStatus);
  177. }