2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: ntoskrnl/se/semgr.c
5 * PURPOSE: Security manager
7 * PROGRAMMERS: No programmer listed.
10 /* INCLUDES *******************************************************************/
16 /* GLOBALS ********************************************************************/
18 PSE_EXPORTS SeExports
= NULL
;
19 SE_EXPORTS SepExports
;
20 ULONG SidInTokenCalls
= 0;
22 extern ULONG ExpInitializationPhase
;
23 extern ERESOURCE SepSubjectContextLock
;
25 /* PRIVATE FUNCTIONS **********************************************************/
31 SepExports
.SeCreateTokenPrivilege
= SeCreateTokenPrivilege
;
32 SepExports
.SeAssignPrimaryTokenPrivilege
= SeAssignPrimaryTokenPrivilege
;
33 SepExports
.SeLockMemoryPrivilege
= SeLockMemoryPrivilege
;
34 SepExports
.SeIncreaseQuotaPrivilege
= SeIncreaseQuotaPrivilege
;
35 SepExports
.SeUnsolicitedInputPrivilege
= SeUnsolicitedInputPrivilege
;
36 SepExports
.SeTcbPrivilege
= SeTcbPrivilege
;
37 SepExports
.SeSecurityPrivilege
= SeSecurityPrivilege
;
38 SepExports
.SeTakeOwnershipPrivilege
= SeTakeOwnershipPrivilege
;
39 SepExports
.SeLoadDriverPrivilege
= SeLoadDriverPrivilege
;
40 SepExports
.SeCreatePagefilePrivilege
= SeCreatePagefilePrivilege
;
41 SepExports
.SeIncreaseBasePriorityPrivilege
= SeIncreaseBasePriorityPrivilege
;
42 SepExports
.SeSystemProfilePrivilege
= SeSystemProfilePrivilege
;
43 SepExports
.SeSystemtimePrivilege
= SeSystemtimePrivilege
;
44 SepExports
.SeProfileSingleProcessPrivilege
= SeProfileSingleProcessPrivilege
;
45 SepExports
.SeCreatePermanentPrivilege
= SeCreatePermanentPrivilege
;
46 SepExports
.SeBackupPrivilege
= SeBackupPrivilege
;
47 SepExports
.SeRestorePrivilege
= SeRestorePrivilege
;
48 SepExports
.SeShutdownPrivilege
= SeShutdownPrivilege
;
49 SepExports
.SeDebugPrivilege
= SeDebugPrivilege
;
50 SepExports
.SeAuditPrivilege
= SeAuditPrivilege
;
51 SepExports
.SeSystemEnvironmentPrivilege
= SeSystemEnvironmentPrivilege
;
52 SepExports
.SeChangeNotifyPrivilege
= SeChangeNotifyPrivilege
;
53 SepExports
.SeRemoteShutdownPrivilege
= SeRemoteShutdownPrivilege
;
55 SepExports
.SeNullSid
= SeNullSid
;
56 SepExports
.SeWorldSid
= SeWorldSid
;
57 SepExports
.SeLocalSid
= SeLocalSid
;
58 SepExports
.SeCreatorOwnerSid
= SeCreatorOwnerSid
;
59 SepExports
.SeCreatorGroupSid
= SeCreatorGroupSid
;
60 SepExports
.SeNtAuthoritySid
= SeNtAuthoritySid
;
61 SepExports
.SeDialupSid
= SeDialupSid
;
62 SepExports
.SeNetworkSid
= SeNetworkSid
;
63 SepExports
.SeBatchSid
= SeBatchSid
;
64 SepExports
.SeInteractiveSid
= SeInteractiveSid
;
65 SepExports
.SeLocalSystemSid
= SeLocalSystemSid
;
66 SepExports
.SeAliasAdminsSid
= SeAliasAdminsSid
;
67 SepExports
.SeAliasUsersSid
= SeAliasUsersSid
;
68 SepExports
.SeAliasGuestsSid
= SeAliasGuestsSid
;
69 SepExports
.SeAliasPowerUsersSid
= SeAliasPowerUsersSid
;
70 SepExports
.SeAliasAccountOpsSid
= SeAliasAccountOpsSid
;
71 SepExports
.SeAliasSystemOpsSid
= SeAliasSystemOpsSid
;
72 SepExports
.SeAliasPrintOpsSid
= SeAliasPrintOpsSid
;
73 SepExports
.SeAliasBackupOpsSid
= SeAliasBackupOpsSid
;
74 SepExports
.SeAuthenticatedUsersSid
= SeAuthenticatedUsersSid
;
75 SepExports
.SeRestrictedSid
= SeRestrictedSid
;
76 SepExports
.SeAnonymousLogonSid
= SeAnonymousLogonSid
;
77 SepExports
.SeLocalServiceSid
= SeLocalServiceSid
;
78 SepExports
.SeNetworkServiceSid
= SeNetworkServiceSid
;
80 SepExports
.SeUndockPrivilege
= SeUndockPrivilege
;
81 SepExports
.SeSyncAgentPrivilege
= SeSyncAgentPrivilege
;
82 SepExports
.SeEnableDelegationPrivilege
= SeEnableDelegationPrivilege
;
83 SepExports
.SeManageVolumePrivilege
= SeManageVolumePrivilege
;
84 SepExports
.SeImpersonatePrivilege
= SeImpersonatePrivilege
;
85 SepExports
.SeCreateGlobalPrivilege
= SeCreateGlobalPrivilege
;
87 SeExports
= &SepExports
;
95 SepInitializationPhase0(VOID
)
100 if (!SepInitSecurityIDs()) return FALSE
;
101 if (!SepInitDACLs()) return FALSE
;
102 if (!SepInitSDs()) return FALSE
;
104 if (!SepInitExports()) return FALSE
;
106 /* Initialize the subject context lock */
107 ExInitializeResource(&SepSubjectContextLock
);
109 /* Initialize token objects */
110 SepInitializeTokenImplementation();
112 /* Initialize logon sessions */
113 if (!SeRmInitPhase0()) return FALSE
;
115 /* Clear impersonation info for the idle thread */
116 PsGetCurrentThread()->ImpersonationInfo
= NULL
;
117 PspClearCrossThreadFlag(PsGetCurrentThread(),
118 CT_ACTIVE_IMPERSONATION_INFO_BIT
);
120 /* Initialize the boot token */
121 ObInitializeFastReference(&PsGetCurrentProcess()->Token
, NULL
);
122 ObInitializeFastReference(&PsGetCurrentProcess()->Token
,
123 SepCreateSystemProcessToken());
130 SepInitializationPhase1(VOID
)
132 OBJECT_ATTRIBUTES ObjectAttributes
;
134 HANDLE SecurityHandle
;
140 /* Insert the system token into the tree */
141 Status
= ObInsertObject((PVOID
)(PsGetCurrentProcess()->Token
.Value
&
148 ASSERT(NT_SUCCESS(Status
));
150 /* TODO: Create a security desscriptor for the directory */
152 /* Create '\Security' directory */
153 RtlInitUnicodeString(&Name
, L
"\\Security");
154 InitializeObjectAttributes(&ObjectAttributes
,
156 OBJ_PERMANENT
| OBJ_CASE_INSENSITIVE
,
160 Status
= ZwCreateDirectoryObject(&SecurityHandle
,
161 DIRECTORY_ALL_ACCESS
,
163 ASSERT(NT_SUCCESS(Status
));
165 /* Create 'LSA_AUTHENTICATION_INITIALIZED' event */
166 RtlInitUnicodeString(&Name
, L
"LSA_AUTHENTICATION_INITIALIZED");
167 InitializeObjectAttributes(&ObjectAttributes
,
169 OBJ_PERMANENT
| OBJ_CASE_INSENSITIVE
,
173 Status
= ZwCreateEvent(&EventHandle
,
178 ASSERT(NT_SUCCESS(Status
));
180 Status
= ZwClose(EventHandle
);
181 ASSERT(NT_SUCCESS(Status
));
183 Status
= ZwClose(SecurityHandle
);
184 ASSERT(NT_SUCCESS(Status
));
194 /* Check the initialization phase */
195 switch (ExpInitializationPhase
)
200 return SepInitializationPhase0();
205 return SepInitializationPhase1();
209 /* Don't know any other phase! Bugcheck! */
210 KeBugCheckEx(UNEXPECTED_INITIALIZATION_CALL
,
212 ExpInitializationPhase
,
221 SeDefaultObjectMethod(IN PVOID Object
,
222 IN SECURITY_OPERATION_CODE OperationType
,
223 IN PSECURITY_INFORMATION SecurityInformation
,
224 IN OUT PSECURITY_DESCRIPTOR SecurityDescriptor
,
225 IN OUT PULONG ReturnLength OPTIONAL
,
226 IN OUT PSECURITY_DESCRIPTOR
*OldSecurityDescriptor
,
227 IN POOL_TYPE PoolType
,
228 IN PGENERIC_MAPPING GenericMapping
)
232 /* Select the operation type */
233 switch (OperationType
)
235 /* Setting a new descriptor */
236 case SetSecurityDescriptor
:
239 ASSERT((PoolType
== PagedPool
) || (PoolType
== NonPagedPool
));
241 /* Set the information */
242 return ObSetSecurityDescriptorInfo(Object
,
245 OldSecurityDescriptor
,
249 case QuerySecurityDescriptor
:
251 /* Query the information */
252 return ObQuerySecurityDescriptorInfo(Object
,
256 OldSecurityDescriptor
);
258 case DeleteSecurityDescriptor
:
261 return ObDeassignSecurity(OldSecurityDescriptor
);
263 case AssignSecurityDescriptor
:
266 ObAssignObjectSecurityDescriptor(Object
, SecurityDescriptor
, PoolType
);
267 return STATUS_SUCCESS
;
272 KeBugCheckEx(SECURITY_SYSTEM
, 0, STATUS_INVALID_PARAMETER
, 0, 0);
275 /* Should never reach here */
277 return STATUS_SUCCESS
;
282 SeQuerySecurityAccessMask(IN SECURITY_INFORMATION SecurityInformation
,
283 OUT PACCESS_MASK DesiredAccess
)
287 if (SecurityInformation
& (OWNER_SECURITY_INFORMATION
|
288 GROUP_SECURITY_INFORMATION
| DACL_SECURITY_INFORMATION
))
290 *DesiredAccess
|= READ_CONTROL
;
293 if (SecurityInformation
& SACL_SECURITY_INFORMATION
)
295 *DesiredAccess
|= ACCESS_SYSTEM_SECURITY
;
301 SeSetSecurityAccessMask(IN SECURITY_INFORMATION SecurityInformation
,
302 OUT PACCESS_MASK DesiredAccess
)
306 if (SecurityInformation
& (OWNER_SECURITY_INFORMATION
| GROUP_SECURITY_INFORMATION
))
308 *DesiredAccess
|= WRITE_OWNER
;
311 if (SecurityInformation
& DACL_SECURITY_INFORMATION
)
313 *DesiredAccess
|= WRITE_DAC
;
316 if (SecurityInformation
& SACL_SECURITY_INFORMATION
)
318 *DesiredAccess
|= ACCESS_SYSTEM_SECURITY
;
324 SeReportSecurityEvent(
326 _In_ PUNICODE_STRING SourceName
,
327 _In_opt_ PSID UserSid
,
328 _In_ PSE_ADT_PARAMETER_ARRAY AuditParameters
)
330 SECURITY_SUBJECT_CONTEXT SubjectContext
;
331 PTOKEN EffectiveToken
;
335 /* Validate parameters */
337 (SourceName
== NULL
) ||
338 (SourceName
->Buffer
== NULL
) ||
339 (SourceName
->Length
== 0) ||
340 (AuditParameters
== NULL
) ||
341 (AuditParameters
->ParameterCount
> SE_MAX_AUDIT_PARAMETERS
- 4))
343 return STATUS_INVALID_PARAMETER
;
346 /* Validate the source name */
347 Status
= RtlValidateUnicodeString(0, SourceName
);
348 if (!NT_SUCCESS(Status
))
353 /* Check if we have a user SID */
357 if (!RtlValidSid(UserSid
))
359 return STATUS_INVALID_PARAMETER
;
362 /* Use the user SID */
367 /* No user SID, capture the security subject context */
368 SeCaptureSubjectContext(&SubjectContext
);
370 /* Extract the effective token */
371 EffectiveToken
= SubjectContext
.ClientToken
?
372 SubjectContext
.ClientToken
: SubjectContext
.PrimaryToken
;
374 /* Use the user-and-groups SID */
375 Sid
= EffectiveToken
->UserAndGroups
->Sid
;
380 /* Check if we captured the subject context */
384 SeReleaseSubjectContext(&SubjectContext
);
388 return STATUS_SUCCESS
;
395 _Inout_ PSE_ADT_PARAMETER_ARRAY AuditParameters
,
396 _In_ SE_ADT_PARAMETER_TYPE Type
,
397 _In_range_(<, SE_MAX_AUDIT_PARAMETERS
) ULONG Index
,
398 _In_reads_(_Inexpressible_("depends on SE_ADT_PARAMETER_TYPE")) PVOID Data
)
401 return STATUS_SUCCESS
;