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.

551 lines
13 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. lsasrvp.h
  5. Abstract:
  6. LSA Subsystem - Private Includes for Server Side
  7. This file contains includes that are global to the Lsa Server Side
  8. Author:
  9. Scott Birrell (ScottBi) January 22, 1992
  10. Environment:
  11. Revision History:
  12. --*/
  13. #ifndef _LSASRVP_
  14. #define _LSASRVP_
  15. //
  16. // The LSA Server Is UNICODE Based. Define UNICODE before global includes
  17. // so that it is defined before the TEXT macro.
  18. //
  19. #ifndef UNICODE
  20. #define UNICODE
  21. #endif // UNICODE
  22. //
  23. // Set the EXTERN macro so only one file allocates all the globals.
  24. //
  25. #ifdef ALLOC_EXTERN
  26. #define EXTERN
  27. #else
  28. #define EXTERN extern
  29. #endif // ALLOC_EXTERN
  30. #include <lsacomp.h>
  31. #include <wincred.h>
  32. #include <alloca.h>
  33. #include <malloc.h>
  34. //
  35. // The following come from \nt\private\inc
  36. #include <align.h>
  37. #include <samrpc.h>
  38. #include <samsrv.h>
  39. #include <samisrv.h>
  40. #include <lsarpc.h>
  41. #include <lsaisrv.h>
  42. #include <nlrepl.h>
  43. #include <seposix.h>
  44. //
  45. // The following all come from \nt\private\lsa\server
  46. //
  47. #include "lsasrvmm.h"
  48. #include "au.h"
  49. #include "db.h"
  50. #include "adt.h"
  51. #include "dblookup.h"
  52. #include "lsads.h"
  53. #include "lsads.h"
  54. #include "lsastr.h"
  55. #include "lsawow.h"
  56. //////////////////////////////////////////////////////////////////////
  57. // //
  58. // The following define controls the diagnostic capabilities that //
  59. // are built into LSA. //
  60. // //
  61. //////////////////////////////////////////////////////////////////////
  62. #if DBG
  63. #define LSAP_DIAGNOSTICS 1
  64. #endif // DBG
  65. //
  66. // These definitions are useful diagnostics aids
  67. //
  68. #if LSAP_DIAGNOSTICS
  69. //
  70. // Diagnostics included in build
  71. //
  72. //
  73. // Test for diagnostics enabled
  74. //
  75. #define IF_LSAP_GLOBAL( FlagName ) \
  76. if (LsapGlobalFlag & (LSAP_DIAG_##FlagName))
  77. //
  78. // Diagnostics print statement
  79. //
  80. #define LsapDiagPrint( FlagName, _Text_ ) \
  81. IF_LSAP_GLOBAL( FlagName ) \
  82. DbgPrint _Text_
  83. //
  84. // Make sure no thread leaves with any open state
  85. //
  86. #define LSAP_TRACK_DBLOCK
  87. #ifdef LSAP_TRACK_DBLOCK
  88. #define LsarpReturnCheckSetup() \
  89. ULONG __lsarpthreadusecountstart; \
  90. {\
  91. PLSADS_PER_THREAD_INFO __lsarpCurrentThreadInfo = (PLSADS_PER_THREAD_INFO) LsapQueryThreadInfo() ;\
  92. if (__lsarpCurrentThreadInfo!=NULL)\
  93. __lsarpthreadusecountstart = __lsarpCurrentThreadInfo->UseCount;\
  94. else \
  95. __lsarpthreadusecountstart =0;\
  96. }
  97. #define LsarpReturnPrologue() \
  98. {\
  99. PLSADS_PER_THREAD_INFO __lsarpCurrentThreadInfoEnd = (PLSADS_PER_THREAD_INFO)LsapQueryThreadInfo() ;\
  100. ULONG __lsarpthreadusecountend ; \
  101. if (__lsarpCurrentThreadInfoEnd!=NULL)\
  102. __lsarpthreadusecountend = __lsarpCurrentThreadInfoEnd->UseCount;\
  103. else\
  104. __lsarpthreadusecountend = 0;\
  105. ASSERT (__lsarpthreadusecountstart==__lsarpthreadusecountend);\
  106. }
  107. #else
  108. #define LsarpReturnPrologue()
  109. #define LsarpReturnCheckSetup()
  110. #endif
  111. #else
  112. //
  113. // No diagnostics included in build
  114. //
  115. //
  116. // Test for diagnostics enabled
  117. //
  118. #define IF_LSAP_GLOBAL( FlagName ) if (FALSE)
  119. //
  120. // Diagnostics print statement (nothing)
  121. //
  122. #define LsapDiagPrint( FlagName, Text ) ;
  123. #define LsarpReturnPrologue()
  124. #define LsarpReturnCheckSetup()
  125. #endif // LSAP_DIAGNOSTICS
  126. //
  127. // The following flags enable or disable various diagnostic
  128. // capabilities within LSA. These flags are set in
  129. // LsapGlobalFlag
  130. //
  131. // DB_LOOKUP_WORK_LIST - Display activities related to sid/name lookups.
  132. //
  133. // AU_TRACK_THREADS - Display dynamic AU thread creation / deletion
  134. // information.
  135. //
  136. // AU_MESSAGES - Display information related to the processing of
  137. // Authentication messages.
  138. //
  139. // AU_LOGON_SESSIONS - Display information about the creation/deletion
  140. // of logon sessions within LSA.
  141. //
  142. // DB_INIT - Display information about the initialization of LSA.
  143. //
  144. #define LSAP_DIAG_DB_LOOKUP_WORK_LIST ((ULONG) 0x00000001L)
  145. #define LSAP_DIAG_AU_TRACK_THREADS ((ULONG) 0x00000002L)
  146. #define LSAP_DIAG_AU_MESSAGES ((ULONG) 0x00000004L)
  147. #define LSAP_DIAG_AU_LOGON_SESSIONS ((ULONG) 0x00000008L)
  148. #define LSAP_DIAG_DB_INIT ((ULONG) 0x00000010L)
  149. //////////////////////////////////////////////////////////////////////
  150. // //
  151. // Other defines //
  152. // //
  153. //////////////////////////////////////////////////////////////////////
  154. //
  155. // Heap available for general use throughout LSA
  156. //
  157. EXTERN PVOID LsapHeap;
  158. //
  159. // LSA Private Global State Data Structure
  160. //
  161. typedef struct _LSAP_STATE {
  162. HANDLE LsaCommandPortHandle;
  163. HANDLE RmCommandPortHandle;
  164. HANDLE AuditLogFileHandle;
  165. HANDLE AuditLogSectionHandle;
  166. PVOID AuditLogBaseAddress;
  167. ULONG AuditLogViewSize;
  168. LARGE_INTEGER AuditLogInitSize;
  169. LARGE_INTEGER AuditLogMaximumSizeOfSection;
  170. OBJECT_ATTRIBUTES AuditLogObjectAttributes;
  171. STRING AuditLogNameString;
  172. GENERIC_MAPPING GenericMapping;
  173. UNICODE_STRING SubsystemName;
  174. PRIVILEGE_SET Privileges;
  175. BOOLEAN GenerateOnClose;
  176. BOOLEAN SystemShutdownPending;
  177. } LSAP_STATE, *PLSAP_STATE;
  178. extern LSAP_STATE LsapState;
  179. extern BOOLEAN LsapInitialized;
  180. //
  181. // Global handle to LSA's policy object.
  182. // This handle is opened for trusted client.
  183. //
  184. extern LSAPR_HANDLE LsapPolicyHandle;
  185. //
  186. // LSA Server Command Dispatch Table Entry
  187. //
  188. typedef NTSTATUS (*PLSA_COMMAND_WORKER)(PLSA_COMMAND_MESSAGE, PLSA_REPLY_MESSAGE);
  189. //
  190. // LSA Client Control Block
  191. //
  192. // This structure contains context information relevant to a successful
  193. // LsaOpenLsa call.
  194. //
  195. typedef struct _LSAP_CLIENT_CONTROL_BLOCK {
  196. HANDLE KeyHandle; // Configuration Registry Key
  197. ACCESS_MASK GrantedAccess; // Accesses granted to LSA Database Object
  198. } LSAP_CLIENT_CONTROL_BLOCK, *PLSAP_CLIENT_CONTROL_BLOCK;
  199. //
  200. // LSA Privilege Pseudo-Object Types and Flags
  201. //
  202. // *********************** IMPORTANT NOTE ************************
  203. //
  204. // Privilege objects (privileges containing a list of users who have that
  205. // privilge) are pseudo-objects that use the account objects as a backing
  206. // stored. There are currently no public interfaces to open a privilege
  207. // object, so there need not be public access flags.
  208. //
  209. #define PRIVILEGE_VIEW 0x00000001L
  210. #define PRIVILEGE_ADJUST 0x00000002L
  211. #define PRIVILEGE_ALL (STANDARD_RIGHTS_REQUIRED | \
  212. PRIVILEGE_VIEW | \
  213. PRIVILEGE_ADJUST)
  214. //
  215. // LSA API Error Handling Cleanup Flags
  216. //
  217. // These flags specify cleanup operations to be performed after an LSA
  218. // API call has hit a fatal error. They are passed in the ErrorCleanupFlags
  219. // variable of the API or worker's error handling routine.
  220. //
  221. #define LSAP_CLEANUP_REVERT_TO_SELF (0x00000001L)
  222. #define LSAP_CLEANUP_CLOSE_LSA_HANDLE (0x00000002L)
  223. #define LSAP_CLEANUP_FREE_USTRING (0x00000004L)
  224. #define LSAP_CLEANUP_CLOSE_REG_KEY (0x00000008L)
  225. #define LSAP_CLEANUP_DELETE_REG_KEY (0x00000010L)
  226. #define LSAP_CLEANUP_DB_UNLOCK (0x00000020L)
  227. BOOLEAN
  228. LsapRmInitializeServer(
  229. );
  230. VOID
  231. LsapRmServerThread(
  232. );
  233. NTSTATUS
  234. LsapRPCInit(
  235. );
  236. BOOLEAN
  237. LsapAuInit( // Authentication initialization
  238. );
  239. NTSTATUS
  240. LsapDbInitializeRights(
  241. );
  242. VOID
  243. LsapDbCleanupRights(
  244. );
  245. NTSTATUS
  246. LsapCallRm(
  247. IN RM_COMMAND_NUMBER CommandNumber,
  248. IN OPTIONAL PVOID CommandParams,
  249. IN ULONG CommandParamsLength,
  250. OUT OPTIONAL PVOID ReplyBuffer,
  251. IN ULONG ReplyBufferLength
  252. );
  253. NTSTATUS
  254. LsapLogonSessionDeletedWrkr(
  255. IN PLSA_COMMAND_MESSAGE CommandMessage,
  256. OUT PLSA_REPLY_MESSAGE ReplyMessage
  257. );
  258. NTSTATUS
  259. LsapComponentTestWrkr(
  260. IN PLSA_COMMAND_MESSAGE CommandMessage,
  261. OUT PLSA_REPLY_MESSAGE ReplyMessage
  262. );
  263. //
  264. // Prototypes of RPC free routines used by LsaIFree.c
  265. //
  266. void _fgs__STRING (STRING * _source);
  267. void _fgs__LSAPR_SID_INFORMATION (LSAPR_SID_INFORMATION * _source);
  268. void _fgs__LSAPR_SID_ENUM_BUFFER (LSAPR_SID_ENUM_BUFFER * _source);
  269. void _fgs__LSAPR_ACCOUNT_INFORMATION (LSAPR_ACCOUNT_INFORMATION * _source);
  270. void _fgs__LSAPR_ACCOUNT_ENUM_BUFFER (LSAPR_ACCOUNT_ENUM_BUFFER * _source);
  271. void _fgs__LSAPR_UNICODE_STRING (LSAPR_UNICODE_STRING * _source);
  272. void _fgs__LSAPR_SECURITY_DESCRIPTOR (LSAPR_SECURITY_DESCRIPTOR * _source);
  273. void _fgs__LSAPR_SR_SECURITY_DESCRIPTOR (LSAPR_SR_SECURITY_DESCRIPTOR * _source);
  274. void _fgs__LSAPR_POLICY_PRIVILEGE_DEF (LSAPR_POLICY_PRIVILEGE_DEF * _source);
  275. void _fgs__LSAPR_PRIVILEGE_ENUM_BUFFER (LSAPR_PRIVILEGE_ENUM_BUFFER * _source);
  276. void _fgs__LSAPR_OBJECT_ATTRIBUTES (LSAPR_OBJECT_ATTRIBUTES * _source);
  277. void _fgs__LSAPR_CR_CIPHER_VALUE (LSAPR_CR_CIPHER_VALUE * _source);
  278. void _fgs__LSAPR_TRUST_INFORMATION (LSAPR_TRUST_INFORMATION * _source);
  279. void _fgs__LSAPR_TRUSTED_ENUM_BUFFER (LSAPR_TRUSTED_ENUM_BUFFER * _source);
  280. void _fgs__LSAPR_TRUSTED_ENUM_BUFFER_EX (LSAPR_TRUSTED_ENUM_BUFFER_EX * _source);
  281. void _fgs__LSAPR_REFERENCED_DOMAIN_LIST (LSAPR_REFERENCED_DOMAIN_LIST * _source);
  282. void _fgs__LSAPR_TRANSLATED_SIDS (LSAPR_TRANSLATED_SIDS * _source);
  283. void _fgs__LSAPR_TRANSLATED_NAME (LSAPR_TRANSLATED_NAME * _source);
  284. void _fgs__LSAPR_TRANSLATED_NAMES (LSAPR_TRANSLATED_NAMES * _source);
  285. void _fgs__LSAPR_POLICY_ACCOUNT_DOM_INFO (LSAPR_POLICY_ACCOUNT_DOM_INFO * _source);
  286. void _fgs__LSAPR_POLICY_PRIMARY_DOM_INFO (LSAPR_POLICY_PRIMARY_DOM_INFO * _source);
  287. void _fgs__LSAPR_POLICY_PD_ACCOUNT_INFO (LSAPR_POLICY_PD_ACCOUNT_INFO * _source);
  288. void _fgs__LSAPR_POLICY_REPLICA_SRCE_INFO (LSAPR_POLICY_REPLICA_SRCE_INFO * _source);
  289. void _fgs__LSAPR_POLICY_AUDIT_EVENTS_INFO (LSAPR_POLICY_AUDIT_EVENTS_INFO * _source);
  290. void _fgs__LSAPR_TRUSTED_DOMAIN_NAME_INFO (LSAPR_TRUSTED_DOMAIN_NAME_INFO * _source);
  291. void _fgs__LSAPR_TRUSTED_CONTROLLERS_INFO (LSAPR_TRUSTED_CONTROLLERS_INFO * _source);
  292. void _fgu__LSAPR_POLICY_INFORMATION (LSAPR_POLICY_INFORMATION * _source, POLICY_INFORMATION_CLASS _branch);
  293. void _fgu__LSAPR_POLICY_DOMAIN_INFORMATION (LSAPR_POLICY_DOMAIN_INFORMATION * _source,
  294. POLICY_DOMAIN_INFORMATION_CLASS _branch);
  295. void _fgu__LSAPR_TRUSTED_DOMAIN_INFO (LSAPR_TRUSTED_DOMAIN_INFO * _source, TRUSTED_INFORMATION_CLASS _branch);
  296. //
  297. // Old worker prototypes - These are temporary
  298. //
  299. #define LsapComponentTestCommandWrkr LsapComponentTestWrkr
  300. #define LsapWriteAuditMessageCommandWrkr LsapAdtWriteLogWrkr
  301. NTSTATUS
  302. ServiceInit (
  303. );
  304. NTSTATUS
  305. LsapInitLsa(
  306. );
  307. BOOLEAN
  308. LsapSeSetWellKnownValues(
  309. );
  310. VOID
  311. RtlConvertSidToText(
  312. IN PSID Sid,
  313. OUT PUCHAR Buffer
  314. );
  315. ULONG
  316. RtlSizeANSISid(
  317. IN PSID Sid
  318. );
  319. NTSTATUS
  320. LsapGetMessageStrings(
  321. LPVOID Resource,
  322. DWORD Index1,
  323. PUNICODE_STRING String1,
  324. DWORD Index2,
  325. PUNICODE_STRING String2 OPTIONAL
  326. );
  327. VOID
  328. LsapLogError(
  329. IN OPTIONAL PUCHAR Message,
  330. IN NTSTATUS Status
  331. );
  332. NTSTATUS
  333. LsapWinerrorToNtStatus(
  334. IN DWORD WinError
  335. );
  336. NTSTATUS
  337. LsapNtStatusFromLastWinError( VOID );
  338. NTSTATUS
  339. LsapGetPrivilegesAndQuotas(
  340. IN SECURITY_LOGON_TYPE LogonType,
  341. IN ULONG IdCount,
  342. IN PSID_AND_ATTRIBUTES Ids,
  343. OUT PULONG PrivilegeCount,
  344. OUT PLUID_AND_ATTRIBUTES *Privileges,
  345. OUT PQUOTA_LIMITS QuotaLimits
  346. );
  347. NTSTATUS
  348. LsapQueryClientInfo(
  349. PTOKEN_USER *UserSid,
  350. PLUID AuthenticationId
  351. );
  352. NTSTATUS
  353. LsapGetAccountDomainInfo(
  354. PPOLICY_ACCOUNT_DOMAIN_INFO *PolicyAccountDomainInfo
  355. );
  356. NTSTATUS
  357. LsapOpenSam( VOID );
  358. NTSTATUS
  359. LsapOpenSamEx(
  360. BOOLEAN DuringStartup
  361. );
  362. NTSTATUS
  363. LsapNotifyProcessNotificationEvent(
  364. IN POLICY_NOTIFICATION_INFORMATION_CLASS InformationClass,
  365. IN HANDLE EventHandle,
  366. IN ULONG OwnerProcess,
  367. IN HANDLE OwnerEventHandle,
  368. IN BOOLEAN Register
  369. );
  370. /////////////////////////////////////////////////////////////////////////
  371. // //
  372. // Shared Global Variables //
  373. // //
  374. /////////////////////////////////////////////////////////////////////////
  375. //
  376. // Handles used to talk to SAM directly.
  377. // Also, a flag to indicate whether or not the handles are valid.
  378. //
  379. extern BOOLEAN LsapSamOpened;
  380. extern SAMPR_HANDLE LsapAccountDomainHandle;
  381. extern SAMPR_HANDLE LsapBuiltinDomainHandle;
  382. //
  383. // These variables are used to control the number of
  384. // threads used for processing Logon Process calls.
  385. // See auloop.c for a description of these variables.
  386. //
  387. extern RTL_RESOURCE LsapAuThreadCountLock;
  388. extern LONG LsapAuActiveThreads;
  389. extern LONG LsapAuFreeThreads;
  390. extern LONG LsapAuFreeThreadsGoal;
  391. extern LONG LsapAuMinimumThreads;
  392. extern LONG LsapAuMaximumThreads;
  393. extern LONG LsapAuCallsToProcess;
  394. #if DBG
  395. //
  396. // Used to extend the resource timeout for lsass.exe to
  397. // prevent it from hitting deadlock warnings in stress tests.
  398. //
  399. extern IMAGE_LOAD_CONFIG_DIRECTORY _load_config_used;
  400. #endif \\DBG
  401. #if LSAP_DIAGNOSTICS
  402. //
  403. // Used as a global diagnostics control flag within lsass.exe
  404. //
  405. extern ULONG LsapGlobalFlag;
  406. #endif // LSAP_DIAGNOSTICS
  407. //
  408. // Fast version of NtQuerySystemTime
  409. //
  410. #define LsapQuerySystemTime( _Time ) GetSystemTimeAsFileTime( (LPFILETIME)(_Time) )
  411. #endif // _LSASRVP_