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.

407 lines
9.6 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. rpcinit.c
  5. Abstract:
  6. LSA - RPC Server Initialization
  7. Author:
  8. Scott Birrell (ScottBi) April 29, 1991
  9. Environment:
  10. Revision History:
  11. --*/
  12. #include <lsapch2.h>
  13. #include <efsrpc.h>
  14. #include "adtgenp.h"
  15. PVOID LsapRegisterTcpIpTask = NULL;
  16. NTSTATUS
  17. LsapRegisterTcpIp(
  18. PVOID pVoid
  19. )
  20. /*++
  21. Routine Description:
  22. This routine registers the LSA interface over any protocols that have
  23. been registered so far. This routine is designed to be called on a
  24. domain controller after the DS has started since it already waits
  25. for the conditions necessary to register its RPC interface over TCP/IP.
  26. N.B. Should the DS ever not register of TCP/IP this mechanism will
  27. need to be updated.
  28. N.B. This routine is called from the thread pool call back mechanism.
  29. Arguments:
  30. pVoid -- ignored.
  31. Return Value:
  32. STATUS_SUCCESS
  33. --*/
  34. {
  35. ULONG RpcStatus = 0;
  36. NTSTATUS Status = STATUS_SUCCESS;
  37. RPC_BINDING_VECTOR *BindingVector;
  38. //
  39. // Register LSA's interface over the new interfaces
  40. //
  41. RpcStatus = RpcServerInqBindings(&BindingVector);
  42. if (RpcStatus == 0) {
  43. RpcStatus = RpcEpRegister(
  44. lsarpc_ServerIfHandle,
  45. BindingVector,
  46. NULL, // no uuid vector
  47. L"" // no annotation
  48. );
  49. RpcBindingVectorFree(&BindingVector);
  50. }
  51. if (RpcStatus != 0) {
  52. SpmpReportEvent( TRUE,
  53. EVENTLOG_WARNING_TYPE,
  54. LSAEVENT_LOOKUP_TCPIP_NOT_INSTALLED,
  55. 0,
  56. sizeof( ULONG ),
  57. &RpcStatus,
  58. 0);
  59. }
  60. //
  61. // Deregister ourselves
  62. //
  63. ASSERT(NULL != LsapRegisterTcpIpTask);
  64. Status = LsaICancelNotification(LsapRegisterTcpIpTask);
  65. ASSERT(NT_SUCCESS(Status));
  66. LsapRegisterTcpIpTask = NULL;
  67. //
  68. // Close the handle
  69. //
  70. ASSERT(pVoid != NULL);
  71. CloseHandle((HANDLE)pVoid);
  72. return STATUS_SUCCESS;
  73. }
  74. NTSTATUS
  75. LsapRPCInit(
  76. )
  77. /*++
  78. Routine Description:
  79. This function performs the initialization of the RPC server in the LSA
  80. subsystem. Clients such as the Local Security Manager on this or some
  81. other machine will then be able to call the LSA API that use RPC .
  82. Arguments:
  83. None
  84. Return Value:
  85. NTSTATUS - Standard Nt Result Code.
  86. All Result Code returned are from called routines.
  87. Environment:
  88. User Mode
  89. --*/
  90. {
  91. NTSTATUS NtStatus;
  92. NTSTATUS TmpStatus;
  93. LPWSTR ServiceName;
  94. //
  95. // Publish the Lsa server interface package...
  96. //
  97. //
  98. // NOTE: Now all RPC servers in lsass.exe (now winlogon) share the same
  99. // pipe name. However, in order to support communication with
  100. // version 1.0 of WinNt, it is necessary for the Client Pipe name
  101. // to remain the same as it was in version 1.0. Mapping to the new
  102. // name is performed in the Named Pipe File System code.
  103. //
  104. //
  105. ServiceName = L"lsass";
  106. NtStatus = RpcpAddInterface( ServiceName, lsarpc_ServerIfHandle);
  107. if (!NT_SUCCESS(NtStatus)) {
  108. LsapLogError(
  109. "LSASS: Could Not Start RPC Server.\n"
  110. " Failing to initialize LSA Server.\n",
  111. NtStatus
  112. );
  113. }
  114. TmpStatus = RpcpAddInterface( ServiceName, efsrpc_ServerIfHandle);
  115. if (!NT_SUCCESS(TmpStatus)) {
  116. LsapLogError(
  117. "LSASS: Could Not Start RPC Server.\n"
  118. " Failing to initialize LSA Server.\n",
  119. TmpStatus
  120. );
  121. }
  122. //
  123. // Register for authenticated RPC for name and sid lookups
  124. //
  125. #ifndef RPC_C_AUTHN_NETLOGON
  126. #define RPC_C_AUTHN_NETLOGON 0x44
  127. #endif // RPC_C_AUTHN_NETLOGON
  128. TmpStatus = I_RpcMapWin32Status(RpcServerRegisterAuthInfo(
  129. NULL, // no principal name
  130. RPC_C_AUTHN_NETLOGON,
  131. NULL, // no get key fn
  132. NULL // no get key argument
  133. ));
  134. if (!NT_SUCCESS(TmpStatus))
  135. {
  136. DebugLog((DEB_ERROR,"Failed to register NETLOGON auth info: 0x%x\n",TmpStatus));
  137. }
  138. //
  139. // If we are a DC, register our interface over TCP/IP for fast
  140. // lookups. Note that this routine is called so early on in startup
  141. // the the TCP/IP interface is not ready yet. We must wait until
  142. // it is ready. The DS currently waits on the necessary conditions, so
  143. // simply wait until the DS is ready to register our interface over
  144. // TCP/IP.
  145. //
  146. {
  147. NT_PRODUCT_TYPE Product;
  148. if ( RtlGetNtProductType( &Product )
  149. && (Product == NtProductLanManNt) ) {
  150. HANDLE hDsStartup;
  151. hDsStartup = CreateEvent(NULL,
  152. TRUE,
  153. FALSE,
  154. NTDS_DELAYED_STARTUP_COMPLETED_EVENT);
  155. if (hDsStartup) {
  156. LsapRegisterTcpIpTask = LsaIRegisterNotification(
  157. LsapRegisterTcpIp,
  158. (PVOID) hDsStartup,
  159. NOTIFIER_TYPE_HANDLE_WAIT,
  160. 0, // no class,
  161. 0,
  162. 0,
  163. hDsStartup);
  164. }
  165. }
  166. }
  167. {
  168. RPC_STATUS RpcStatus;
  169. //
  170. // enable lsa rpc server to listen on LRPC transport on endpoint 'audit'
  171. // this endpoint is used by auditing clients
  172. //
  173. RpcStatus = RpcServerUseProtseqEp(
  174. L"ncalrpc",
  175. RPC_C_PROTSEQ_MAX_REQS_DEFAULT , // max concurrent calls
  176. L"audit", // end point
  177. NULL // security descriptor
  178. );
  179. if ( RpcStatus != RPC_S_OK )
  180. {
  181. DebugLog((DEB_ERROR, "RpcServerUseProtseqEp failed for ncalrpc: %d\n",
  182. RpcStatus));
  183. NtStatus = I_RpcMapWin32Status( RpcStatus );
  184. }
  185. }
  186. {
  187. RPC_STATUS RpcStatus;
  188. //
  189. // Enable lsa rpc server to listen on LRPC transport on endpoint 'securityevent'.
  190. // This endpoint is used by auditing clients.
  191. //
  192. RpcStatus = RpcServerUseProtseqEp(
  193. L"ncalrpc",
  194. RPC_C_PROTSEQ_MAX_REQS_DEFAULT, // max concurrent calls
  195. L"securityevent", // end point
  196. NULL // security descriptor
  197. );
  198. if ( RpcStatus != RPC_S_OK )
  199. {
  200. DebugLog((DEB_ERROR, "RpcServerUseProtseqEp failed for ncalrpc: %d\n",
  201. RpcStatus));
  202. NtStatus = I_RpcMapWin32Status( RpcStatus );
  203. }
  204. }
  205. return(NtStatus);
  206. }
  207. VOID LSAPR_HANDLE_rundown(
  208. LSAPR_HANDLE LsaHandle
  209. )
  210. /*++
  211. Routine Description:
  212. This routine is called by the server RPC runtime to run down a
  213. Context Handle.
  214. Arguments:
  215. None.
  216. Return Value:
  217. --*/
  218. {
  219. NTSTATUS Status;
  220. //
  221. // Close and free the handle. Since the container handle reference
  222. // count includes one reference for every reference made to the
  223. // target handle, the container's reference count will be decremented
  224. // by n where n is the reference count in the target handle.
  225. //
  226. Status = LsapDbCloseObject(
  227. &LsaHandle,
  228. LSAP_DB_DEREFERENCE_CONTR |
  229. LSAP_DB_VALIDATE_HANDLE |
  230. LSAP_DB_ADMIT_DELETED_OBJECT_HANDLES,
  231. STATUS_SUCCESS
  232. );
  233. }
  234. VOID PLSA_ENUMERATION_HANDLE_rundown(
  235. PLSA_ENUMERATION_HANDLE LsaHandle
  236. )
  237. /*++
  238. Routine Description:
  239. This routine is called by the server RPC runtime to run down a
  240. Context Handle.
  241. Arguments:
  242. None.
  243. Return Value:
  244. --*/
  245. {
  246. DBG_UNREFERENCED_PARAMETER(LsaHandle);
  247. return;
  248. }
  249. VOID AUDIT_HANDLE_rundown(
  250. AUDIT_HANDLE hAudit
  251. )
  252. /*++
  253. Routine Description:
  254. This routine is called by the server RPC runtime to run down a
  255. Context Handle.
  256. Arguments:
  257. None.
  258. Return Value:
  259. --*/
  260. {
  261. NTSTATUS Status = STATUS_SUCCESS;
  262. Status = LsapUnregisterAuditEvent( &hAudit );
  263. if (!NT_SUCCESS(Status))
  264. {
  265. DebugLog((DEB_ERROR,"AUDIT_HANDLE_rundown: LsapUnregisterAuditEvent: 0x%x\n", Status));
  266. }
  267. }
  268. VOID SECURITY_SOURCE_HANDLE_rundown(
  269. SECURITY_SOURCE_HANDLE hSecuritySource
  270. )
  271. /*++
  272. Routine Description:
  273. This routine is called by the server RPC runtime to run down a
  274. Context Handle.
  275. Arguments:
  276. None.
  277. Return Value:
  278. --*/
  279. {
  280. NTSTATUS Status = STATUS_SUCCESS;
  281. #if DEBUG_AUTHZ
  282. DbgPrint("Rundown Source 0x%x\n", hSecuritySource);
  283. #endif
  284. Status = LsapAdtRundownSecurityEventSource( 0, 0, &hSecuritySource );
  285. if (!NT_SUCCESS(Status))
  286. {
  287. DebugLog((DEB_ERROR,"SECURITY_SOURCE_HANDLE_rundown: LsapUnregisterSecurityEventSource: 0x%x\n", Status));
  288. }
  289. }