00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
#include <nt.h>
00022
#include "sep.h"
00023
#include "tokenp.h"
00024
#include "adt.h"
00025
#include <string.h>
00026
00027
00028
00029
00030
00031 #define SEP_INITIAL_KEY_COUNT 15
00032 #define SEP_INITIAL_LEVEL_COUNT 6L
00033
00034
#ifdef ALLOC_PRAGMA
00035
#pragma alloc_text(INIT,SeInitSystem)
00036
#pragma alloc_text(INIT,SepInitializationPhase0)
00037
#pragma alloc_text(INIT,SepInitializationPhase1)
00038
#endif
00039
00040 BOOLEAN
00041 SeInitSystem( VOID )
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061 {
00062
PAGED_CODE();
00063
00064
switch (
InitializationPhase ) {
00065
00066
case 0 :
00067
return SepInitializationPhase0();
00068
case 1 :
00069
return SepInitializationPhase1();
00070
default:
00071
KeBugCheck(UNEXPECTED_INITIALIZATION_CALL);
00072 }
00073
return 0;
00074 }
00075
00076
00077 BOOLEAN
00078 SepInitializationPhase0( VOID )
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106 {
00107
00108
PAGED_CODE();
00109
00110
00111
00112
00113
00114
00115
00116
if (
ExLuidInitialization() ==
FALSE) {
00117 KdPrint((
"Security: Locally Unique ID initialization failed.\n"));
00118
return FALSE;
00119 }
00120
00121
00122
00123
00124
00125
if (!
SepVariableInitialization()) {
00126 KdPrint((
"Security: Global variable initialization failed.\n"));
00127
return FALSE;
00128 }
00129
00130
00131
00132
00133
00134
if (!
SepRmInitPhase0()) {
00135 KdPrint((
"Security: Ref Mon state initialization failed.\n"));
00136
return FALSE;
00137 }
00138
00139
00140
00141
00142
00143
if (!
SepTokenInitialization()) {
00144 KdPrint((
"Security: Token object initialization failed.\n"));
00145
return FALSE;
00146 }
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
if (!
SepInitializeWorkList()) {
00167 KdPrint((
"Security: Unable to initialize work queue\n"));
00168
return FALSE;
00169 }
00170
00171
00172
00173
00174
00175
PsGetCurrentProcess()->Token =
SeMakeSystemToken();
00176
PsGetCurrentThread()->ImpersonationInfo =
NULL;
00177
PsGetCurrentThread()->ActiveImpersonationInfo =
FALSE;
00178
00179
return (
PsGetCurrentProcess()->Token !=
NULL );
00180 }
00181
00182
00183 BOOLEAN
00184 SepInitializationPhase1( VOID )
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215 {
00216
00217
NTSTATUS Status;
00218 STRING
Name;
00219 UNICODE_STRING UnicodeName;
00220 OBJECT_ATTRIBUTES
ObjectAttributes;
00221 HANDLE SecurityRoot, TemporaryHandle;
00222 PSECURITY_DESCRIPTOR SD ;
00223 UCHAR SDBuffer[ SECURITY_DESCRIPTOR_MIN_LENGTH ];
00224 PACL
Dacl ;
00225
00226
PAGED_CODE();
00227
00228
SeAnonymousLogonToken =
SeMakeAnonymousLogonToken();
00229
ASSERT(
SeAnonymousLogonToken !=
NULL);
00230
00231
00232
00233
00234
00235
RtlInitString( &
Name,
"\\Security" );
00236
Status =
RtlAnsiStringToUnicodeString(
00237 &UnicodeName,
00238 &
Name,
00239
TRUE );
ASSERT(
NT_SUCCESS(
Status) );
00240
00241
00242
00243
00244
00245 SD = (PSECURITY_DESCRIPTOR) SDBuffer ;
00246
00247
RtlCreateSecurityDescriptor( SD,
00248 SECURITY_DESCRIPTOR_REVISION );
00249
00250
Dacl =
ExAllocatePool(
00251
NonPagedPool,
00252 256 );
00253
00254
if ( !
Dacl )
00255 {
00256
return FALSE ;
00257 }
00258
00259
RtlCreateAcl(
Dacl, 256, ACL_REVISION );
00260
00261
RtlAddAccessAllowedAce(
Dacl,
00262 ACL_REVISION,
00263 DIRECTORY_ALL_ACCESS,
00264
SeLocalSystemSid );
00265
00266
RtlAddAccessAllowedAce(
Dacl,
00267 ACL_REVISION,
00268 DIRECTORY_QUERY | DIRECTORY_TRAVERSE |
00269 READ_CONTROL,
00270
SeAliasAdminsSid );
00271
00272
RtlAddAccessAllowedAce(
Dacl,
00273 ACL_REVISION,
00274 DIRECTORY_TRAVERSE,
00275
SeWorldSid );
00276
00277
RtlSetDaclSecurityDescriptor(
00278 SD,
00279
TRUE,
00280
Dacl,
00281
FALSE );
00282
00283 InitializeObjectAttributes(
00284 &
ObjectAttributes,
00285 &UnicodeName,
00286 (OBJ_PERMANENT | OBJ_CASE_INSENSITIVE),
00287
NULL,
00288 SD
00289 );
00290
00291
Status =
NtCreateDirectoryObject(
00292 &SecurityRoot,
00293 DIRECTORY_ALL_ACCESS,
00294 &
ObjectAttributes
00295 );
00296
RtlFreeUnicodeString( &UnicodeName );
00297
ASSERTMSG(
"Security root object directory creation failed.",
NT_SUCCESS(
Status));
00298
00299
ExFreePool(
Dacl );
00300
00301
00302
00303
00304
00305
RtlInitString( &
Name,
"LSA_AUTHENTICATION_INITIALIZED" );
00306
Status =
RtlAnsiStringToUnicodeString(
00307 &UnicodeName,
00308 &
Name,
00309
TRUE );
ASSERT(
NT_SUCCESS(
Status) );
00310 InitializeObjectAttributes(
00311 &
ObjectAttributes,
00312 &UnicodeName,
00313 (OBJ_PERMANENT | OBJ_CASE_INSENSITIVE),
00314 SecurityRoot,
00315
SePublicDefaultSd
00316 );
00317
00318
Status =
NtCreateEvent(
00319 &TemporaryHandle,
00320 GENERIC_WRITE,
00321 &
ObjectAttributes,
00322 NotificationEvent,
00323
FALSE
00324 );
00325
RtlFreeUnicodeString( &UnicodeName );
00326
ASSERTMSG(
"LSA Initialization Event Creation Failed.",
NT_SUCCESS(
Status));
00327
00328
Status =
NtClose( SecurityRoot );
00329
ASSERTMSG(
"Security object directory handle closure Failed.",
NT_SUCCESS(
Status));
00330
Status =
NtClose( TemporaryHandle );
00331
ASSERTMSG(
"LSA Initialization Event handle closure Failed.",
NT_SUCCESS(
Status));
00332
00333
00334
00335
00336
00337
if (!
SepAdtInitializePhase1()) {
00338 KdPrint((
"Security: Auditing initialization failed.\n"));
00339
return FALSE;
00340 }
00341
00342
00343
#ifndef SETEST
00344
00345
return TRUE;
00346
00347
#else
00348
00349
return SepDevelopmentTest();
00350
00351
#endif //SETEST
00352
00353 }