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.

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