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.

206 lines
4.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. dwStatus = RpcServerUseProtseqEp(
  22. L"ncacn_np",
  23. 10,
  24. L"\\pipe\\ipsec",
  25. NULL
  26. );
  27. if (dwStatus) {
  28. if (dwStatus != RPC_S_DUPLICATE_ENDPOINT) {
  29. return (dwStatus);
  30. }
  31. }
  32. dwStatus = RpcServerUseProtseqEp(
  33. L"ncalrpc",
  34. 10,
  35. L"ipsec",
  36. NULL
  37. );
  38. if (dwStatus) {
  39. if (dwStatus != RPC_S_DUPLICATE_ENDPOINT) {
  40. return (dwStatus);
  41. }
  42. }
  43. dwStatus = RpcServerRegisterIf(
  44. winipsec_ServerIfHandle,
  45. 0,
  46. 0
  47. );
  48. if (dwStatus) {
  49. return (dwStatus);
  50. }
  51. dwStatus = RpcServerRegisterAuthInfo(
  52. 0,
  53. RPC_C_AUTHN_WINNT,
  54. 0,
  55. 0
  56. );
  57. if (dwStatus) {
  58. (VOID) RpcServerUnregisterIfEx(
  59. winipsec_ServerIfHandle,
  60. 0,
  61. 0
  62. );
  63. return (dwStatus);
  64. }
  65. dwStatus = RpcServerInqDefaultPrincNameW(
  66. RPC_C_AUTHN_GSS_KERBEROS,
  67. &pszPrincipalName
  68. );
  69. if (dwStatus == RPC_S_INVALID_AUTH_IDENTITY) {
  70. dwStatus = ERROR_SUCCESS;
  71. pszPrincipalName = NULL;
  72. }
  73. if (dwStatus) {
  74. (VOID) RpcServerUnregisterIfEx(
  75. winipsec_ServerIfHandle,
  76. 0,
  77. 0
  78. );
  79. return (dwStatus);
  80. }
  81. dwStatus = RpcServerRegisterAuthInfo(
  82. pszPrincipalName,
  83. RPC_C_AUTHN_GSS_KERBEROS,
  84. 0,
  85. 0
  86. );
  87. if (dwStatus) {
  88. (VOID) RpcServerUnregisterIfEx(
  89. winipsec_ServerIfHandle,
  90. 0,
  91. 0
  92. );
  93. RpcStringFree(&pszPrincipalName);
  94. return (dwStatus);
  95. }
  96. dwStatus = RpcServerRegisterAuthInfo(
  97. pszPrincipalName,
  98. RPC_C_AUTHN_GSS_NEGOTIATE,
  99. 0,
  100. 0
  101. );
  102. if (dwStatus) {
  103. (VOID) RpcServerUnregisterIfEx(
  104. winipsec_ServerIfHandle,
  105. 0,
  106. 0
  107. );
  108. RpcStringFree(&pszPrincipalName);
  109. return (dwStatus);
  110. }
  111. RpcStringFree(&pszPrincipalName);
  112. #if !defined(__IN_LSASS__)
  113. EnterCriticalSection(&gcServerListenSection);
  114. gdwServersListening++;
  115. if (gdwServersListening == 1) {
  116. dwStatus = RpcServerListen(
  117. 3,
  118. RPC_C_LISTEN_MAX_CALLS_DEFAULT,
  119. TRUE
  120. );
  121. if (dwStatus) {
  122. LeaveCriticalSection(&gcServerListenSection);
  123. (VOID) RpcServerUnregisterIfEx(
  124. winipsec_ServerIfHandle,
  125. 0,
  126. 0
  127. );
  128. return (dwStatus);
  129. }
  130. }
  131. LeaveCriticalSection(&gcServerListenSection);
  132. #endif
  133. gbSPDRPCServerUp = TRUE;
  134. return (dwStatus);
  135. }
  136. DWORD
  137. SPDStopRPCServer(
  138. )
  139. {
  140. DWORD dwStatus = 0;
  141. dwStatus = RpcServerUnregisterIfEx(
  142. winipsec_ServerIfHandle,
  143. 0,
  144. 0
  145. );
  146. #if !defined(__IN_LSASS__)
  147. EnterCriticalSection(&gcServerListenSection);
  148. gdwServersListening--;
  149. if (gdwServersListening == 0) {
  150. RpcMgmtStopServerListening(0);
  151. }
  152. LeaveCriticalSection(&gcServerListenSection);
  153. #endif
  154. return (dwStatus);
  155. }