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.

385 lines
8.5 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. seinit.c
  5. Abstract:
  6. Executive security components Initialization.
  7. Author:
  8. Jim Kelly (JimK) 10-May-1990
  9. Revision History:
  10. --*/
  11. #include "pch.h"
  12. #pragma hdrstop
  13. #include "adt.h"
  14. #include <string.h>
  15. //
  16. // Security Database Constants
  17. //
  18. #define SEP_INITIAL_KEY_COUNT 15
  19. #define SEP_INITIAL_LEVEL_COUNT 6L
  20. #ifdef ALLOC_PRAGMA
  21. #pragma alloc_text(INIT,SeInitSystem)
  22. #pragma alloc_text(INIT,SepInitializationPhase0)
  23. #pragma alloc_text(INIT,SepInitializationPhase1)
  24. #endif
  25. BOOLEAN
  26. SeInitSystem( VOID )
  27. /*++
  28. Routine Description:
  29. Perform security related system initialization functions.
  30. Arguments:
  31. None.
  32. Return Value:
  33. TRUE - Initialization succeeded.
  34. FALSE - Initialization failed.
  35. --*/
  36. {
  37. PAGED_CODE();
  38. switch ( InitializationPhase ) {
  39. case 0 :
  40. return SepInitializationPhase0();
  41. case 1 :
  42. return SepInitializationPhase1();
  43. default:
  44. KeBugCheckEx(UNEXPECTED_INITIALIZATION_CALL, 0, InitializationPhase, 0, 0);
  45. }
  46. }
  47. VOID
  48. SepInitProcessAuditSd( VOID );
  49. BOOLEAN
  50. SepInitializationPhase0( VOID )
  51. /*++
  52. Routine Description:
  53. Perform phase 0 security initialization.
  54. This includes:
  55. - Initialize LUID allocation
  56. - Initialize security global variables
  57. - initialize the token object.
  58. - Initialize the necessary security components of the boot thread/process
  59. Arguments:
  60. None.
  61. Return Value:
  62. TRUE - Initialization was successful.
  63. FALSE - Initialization Failed.
  64. --*/
  65. {
  66. PAGED_CODE();
  67. //
  68. // LUID allocation services are needed by security prior to phase 0
  69. // Executive initialization. So, LUID initialization is performed
  70. // here
  71. //
  72. if (ExLuidInitialization() == FALSE) {
  73. KdPrint(("Security: Locally Unique ID initialization failed.\n"));
  74. return FALSE;
  75. }
  76. //
  77. // Initialize security global variables
  78. //
  79. if (!SepVariableInitialization()) {
  80. KdPrint(("Security: Global variable initialization failed.\n"));
  81. return FALSE;
  82. }
  83. //
  84. // Perform Phase 0 Reference Monitor Initialization.
  85. //
  86. if (!SepRmInitPhase0()) {
  87. KdPrint(("Security: Ref Mon state initialization failed.\n"));
  88. return FALSE;
  89. }
  90. //
  91. // Initialize the token object type.
  92. //
  93. if (!SepTokenInitialization()) {
  94. KdPrint(("Security: Token object initialization failed.\n"));
  95. return FALSE;
  96. }
  97. // //
  98. // // Initialize auditing structures
  99. // //
  100. //
  101. // if (!SepAdtInitializePhase0()) {
  102. // KdPrint(("Security: Auditing initialization failed.\n"));
  103. // return FALSE;
  104. // }
  105. //
  106. //
  107. // Initialize SpinLock and list for the LSA worker thread
  108. //
  109. //
  110. // Initialize the work queue spinlock, list head, and semaphore
  111. // for each of the work queues.
  112. //
  113. if (!SepInitializeWorkList()) {
  114. KdPrint(("Security: Unable to initialize work queue\n"));
  115. return FALSE;
  116. }
  117. //
  118. // Initialize the security fields of the boot thread.
  119. //
  120. PsGetCurrentThread()->ImpersonationInfo = NULL;
  121. PS_CLEAR_BITS (&PsGetCurrentThread()->CrossThreadFlags, PS_CROSS_THREAD_FLAGS_IMPERSONATING);
  122. ObInitializeFastReference (&PsGetCurrentProcess()->Token, NULL);
  123. ObInitializeFastReference (&PsGetCurrentProcess()->Token, SeMakeSystemToken());
  124. return ( !ExFastRefObjectNull (PsGetCurrentProcess()->Token) );
  125. }
  126. BOOLEAN
  127. SepInitializationPhase1( VOID )
  128. /*++
  129. Routine Description:
  130. Perform phase 1 security initialization.
  131. This includes:
  132. - Create an object directory for security related objects.
  133. (\Security).
  134. - Create an event to be signalled after the LSA has initialized.
  135. (\Security\LSA_Initialized)
  136. Arguments:
  137. None.
  138. Return Value:
  139. TRUE - Initialization was successful.
  140. FALSE - Initialization Failed.
  141. --*/
  142. {
  143. NTSTATUS Status;
  144. STRING Name;
  145. UNICODE_STRING UnicodeName;
  146. OBJECT_ATTRIBUTES ObjectAttributes;
  147. HANDLE SecurityRoot, TemporaryHandle;
  148. PSECURITY_DESCRIPTOR SD ;
  149. UCHAR SDBuffer[ SECURITY_DESCRIPTOR_MIN_LENGTH ];
  150. PACL Dacl ;
  151. PAGED_CODE();
  152. //
  153. // Insert the system token
  154. //
  155. Status = ObInsertObject( ExFastRefGetObject (PsGetCurrentProcess()->Token),
  156. NULL,
  157. 0,
  158. 0,
  159. NULL,
  160. NULL );
  161. ASSERT( NT_SUCCESS(Status) );
  162. SeAnonymousLogonToken = SeMakeAnonymousLogonToken();
  163. ASSERT(SeAnonymousLogonToken != NULL);
  164. SeAnonymousLogonTokenNoEveryone = SeMakeAnonymousLogonTokenNoEveryone();
  165. ASSERT(SeAnonymousLogonTokenNoEveryone != NULL);
  166. //
  167. // Create the security object directory.
  168. //
  169. RtlInitString( &Name, "\\Security" );
  170. Status = RtlAnsiStringToUnicodeString(
  171. &UnicodeName,
  172. &Name,
  173. TRUE );
  174. ASSERT( NT_SUCCESS(Status) );
  175. //
  176. // Build up the security descriptor
  177. //
  178. SD = (PSECURITY_DESCRIPTOR) SDBuffer ;
  179. RtlCreateSecurityDescriptor( SD,
  180. SECURITY_DESCRIPTOR_REVISION );
  181. Dacl = ExAllocatePool(
  182. NonPagedPool,
  183. 256 );
  184. if ( !Dacl )
  185. {
  186. return FALSE ;
  187. }
  188. Status = RtlCreateAcl( Dacl, 256, ACL_REVISION );
  189. ASSERT( NT_SUCCESS(Status) );
  190. Status = RtlAddAccessAllowedAce( Dacl,
  191. ACL_REVISION,
  192. DIRECTORY_ALL_ACCESS,
  193. SeLocalSystemSid );
  194. ASSERT( NT_SUCCESS(Status) );
  195. Status = RtlAddAccessAllowedAce( Dacl,
  196. ACL_REVISION,
  197. DIRECTORY_QUERY | DIRECTORY_TRAVERSE |
  198. READ_CONTROL,
  199. SeAliasAdminsSid );
  200. ASSERT( NT_SUCCESS(Status) );
  201. Status = RtlAddAccessAllowedAce( Dacl,
  202. ACL_REVISION,
  203. DIRECTORY_TRAVERSE,
  204. SeWorldSid );
  205. ASSERT( NT_SUCCESS(Status) );
  206. Status = RtlSetDaclSecurityDescriptor(
  207. SD,
  208. TRUE,
  209. Dacl,
  210. FALSE );
  211. ASSERT( NT_SUCCESS(Status) );
  212. InitializeObjectAttributes(
  213. &ObjectAttributes,
  214. &UnicodeName,
  215. (OBJ_PERMANENT | OBJ_CASE_INSENSITIVE),
  216. NULL,
  217. SD
  218. );
  219. Status = NtCreateDirectoryObject(
  220. &SecurityRoot,
  221. DIRECTORY_ALL_ACCESS,
  222. &ObjectAttributes
  223. );
  224. RtlFreeUnicodeString( &UnicodeName );
  225. ASSERTMSG("Security root object directory creation failed.",NT_SUCCESS(Status));
  226. ExFreePool( Dacl );
  227. //
  228. // Create an event in the security directory
  229. //
  230. RtlInitString( &Name, "LSA_AUTHENTICATION_INITIALIZED" );
  231. Status = RtlAnsiStringToUnicodeString(
  232. &UnicodeName,
  233. &Name,
  234. TRUE );
  235. ASSERT( NT_SUCCESS(Status) );
  236. InitializeObjectAttributes(
  237. &ObjectAttributes,
  238. &UnicodeName,
  239. (OBJ_PERMANENT | OBJ_CASE_INSENSITIVE),
  240. SecurityRoot,
  241. SePublicDefaultSd
  242. );
  243. Status = NtCreateEvent(
  244. &TemporaryHandle,
  245. GENERIC_WRITE,
  246. &ObjectAttributes,
  247. NotificationEvent,
  248. FALSE
  249. );
  250. RtlFreeUnicodeString( &UnicodeName );
  251. ASSERTMSG("LSA Initialization Event Creation Failed.",NT_SUCCESS(Status));
  252. Status = NtClose( SecurityRoot );
  253. ASSERTMSG("Security object directory handle closure Failed.",NT_SUCCESS(Status));
  254. Status = NtClose( TemporaryHandle );
  255. ASSERTMSG("LSA Initialization Event handle closure Failed.",NT_SUCCESS(Status));
  256. //
  257. // Initialize the default SACL to use for auditing
  258. // accesses to system processes. This initializes SepProcessSacl
  259. //
  260. SepInitProcessAuditSd();
  261. #ifndef SETEST
  262. return TRUE;
  263. #else
  264. return SepDevelopmentTest();
  265. #endif //SETEST
  266. }