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 /* Clear impersonation info for the idle thread */
113 PsGetCurrentThread()->ImpersonationInfo
= NULL
;
114 PspClearCrossThreadFlag(PsGetCurrentThread(),
115 CT_ACTIVE_IMPERSONATION_INFO_BIT
);
117 /* Initialize the boot token */
118 ObInitializeFastReference(&PsGetCurrentProcess()->Token
, NULL
);
119 ObInitializeFastReference(&PsGetCurrentProcess()->Token
,
120 SepCreateSystemProcessToken());
127 SepInitializationPhase1(VOID
)
129 OBJECT_ATTRIBUTES ObjectAttributes
;
131 HANDLE SecurityHandle
;
137 /* Insert the system token into the tree */
138 Status
= ObInsertObject((PVOID
)(PsGetCurrentProcess()->Token
.Value
&
145 ASSERT(NT_SUCCESS(Status
));
147 /* TODO: Create a security desscriptor for the directory */
149 /* Create '\Security' directory */
150 RtlInitUnicodeString(&Name
, L
"\\Security");
151 InitializeObjectAttributes(&ObjectAttributes
,
153 OBJ_PERMANENT
| OBJ_CASE_INSENSITIVE
,
157 Status
= ZwCreateDirectoryObject(&SecurityHandle
,
158 DIRECTORY_ALL_ACCESS
,
160 ASSERT(NT_SUCCESS(Status
));
162 /* Create 'LSA_AUTHENTICATION_INITIALIZED' event */
163 RtlInitUnicodeString(&Name
, L
"LSA_AUTHENTICATION_INITIALIZED");
164 InitializeObjectAttributes(&ObjectAttributes
,
166 OBJ_PERMANENT
| OBJ_CASE_INSENSITIVE
,
170 Status
= ZwCreateEvent(&EventHandle
,
175 ASSERT(NT_SUCCESS(Status
));
177 Status
= ZwClose(EventHandle
);
178 ASSERT(NT_SUCCESS(Status
));
180 Status
= ZwClose(SecurityHandle
);
181 ASSERT(NT_SUCCESS(Status
));
191 /* Check the initialization phase */
192 switch (ExpInitializationPhase
)
197 return SepInitializationPhase0();
202 return SepInitializationPhase1();
206 /* Don't know any other phase! Bugcheck! */
207 KeBugCheckEx(UNEXPECTED_INITIALIZATION_CALL
,
209 ExpInitializationPhase
,
218 SeDefaultObjectMethod(IN PVOID Object
,
219 IN SECURITY_OPERATION_CODE OperationType
,
220 IN PSECURITY_INFORMATION SecurityInformation
,
221 IN OUT PSECURITY_DESCRIPTOR SecurityDescriptor
,
222 IN OUT PULONG ReturnLength OPTIONAL
,
223 IN OUT PSECURITY_DESCRIPTOR
*OldSecurityDescriptor
,
224 IN POOL_TYPE PoolType
,
225 IN PGENERIC_MAPPING GenericMapping
)
229 /* Select the operation type */
230 switch (OperationType
)
232 /* Setting a new descriptor */
233 case SetSecurityDescriptor
:
236 ASSERT((PoolType
== PagedPool
) || (PoolType
== NonPagedPool
));
238 /* Set the information */
239 return ObSetSecurityDescriptorInfo(Object
,
242 OldSecurityDescriptor
,
246 case QuerySecurityDescriptor
:
248 /* Query the information */
249 return ObQuerySecurityDescriptorInfo(Object
,
253 OldSecurityDescriptor
);
255 case DeleteSecurityDescriptor
:
258 return ObDeassignSecurity(OldSecurityDescriptor
);
260 case AssignSecurityDescriptor
:
263 ObAssignObjectSecurityDescriptor(Object
, SecurityDescriptor
, PoolType
);
264 return STATUS_SUCCESS
;
269 KeBugCheckEx(SECURITY_SYSTEM
, 0, STATUS_INVALID_PARAMETER
, 0, 0);
272 /* Should never reach here */
274 return STATUS_SUCCESS
;
279 SeQuerySecurityAccessMask(IN SECURITY_INFORMATION SecurityInformation
,
280 OUT PACCESS_MASK DesiredAccess
)
284 if (SecurityInformation
& (OWNER_SECURITY_INFORMATION
|
285 GROUP_SECURITY_INFORMATION
| DACL_SECURITY_INFORMATION
))
287 *DesiredAccess
|= READ_CONTROL
;
290 if (SecurityInformation
& SACL_SECURITY_INFORMATION
)
292 *DesiredAccess
|= ACCESS_SYSTEM_SECURITY
;
298 SeSetSecurityAccessMask(IN SECURITY_INFORMATION SecurityInformation
,
299 OUT PACCESS_MASK DesiredAccess
)
303 if (SecurityInformation
& (OWNER_SECURITY_INFORMATION
| GROUP_SECURITY_INFORMATION
))
305 *DesiredAccess
|= WRITE_OWNER
;
308 if (SecurityInformation
& DACL_SECURITY_INFORMATION
)
310 *DesiredAccess
|= WRITE_DAC
;
313 if (SecurityInformation
& SACL_SECURITY_INFORMATION
)
315 *DesiredAccess
|= ACCESS_SYSTEM_SECURITY
;
321 SeReportSecurityEvent(
323 _In_ PUNICODE_STRING SourceName
,
324 _In_opt_ PSID UserSid
,
325 _In_ PSE_ADT_PARAMETER_ARRAY AuditParameters
)
327 SECURITY_SUBJECT_CONTEXT SubjectContext
;
328 PTOKEN EffectiveToken
;
332 /* Validate parameters */
334 (SourceName
== NULL
) ||
335 (SourceName
->Buffer
== NULL
) ||
336 (SourceName
->Length
== 0) ||
337 (AuditParameters
== NULL
) ||
338 (AuditParameters
->ParameterCount
> SE_MAX_AUDIT_PARAMETERS
- 4))
340 return STATUS_INVALID_PARAMETER
;
343 /* Validate the source name */
344 Status
= RtlValidateUnicodeString(0, SourceName
);
345 if (!NT_SUCCESS(Status
))
350 /* Check if we have a user SID */
354 if (!RtlValidSid(UserSid
))
356 return STATUS_INVALID_PARAMETER
;
359 /* Use the user SID */
364 /* No user SID, capture the security subject context */
365 SeCaptureSubjectContext(&SubjectContext
);
367 /* Extract the effective token */
368 EffectiveToken
= SubjectContext
.ClientToken
?
369 SubjectContext
.ClientToken
: SubjectContext
.PrimaryToken
;
371 /* Use the user-and-groups SID */
372 Sid
= EffectiveToken
->UserAndGroups
->Sid
;
377 /* Check if we captured the subject context */
381 SeReleaseSubjectContext(&SubjectContext
);
385 return STATUS_SUCCESS
;
392 _Inout_ PSE_ADT_PARAMETER_ARRAY AuditParameters
,
393 _In_ SE_ADT_PARAMETER_TYPE Type
,
394 _In_range_(<, SE_MAX_AUDIT_PARAMETERS
) ULONG Index
,
395 _In_reads_(_Inexpressible_("depends on SE_ADT_PARAMETER_TYPE")) PVOID Data
)
398 return STATUS_SUCCESS
;