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
;
78 SepExports
.SeUndockPrivilege
= SeUndockPrivilege
;
79 SepExports
.SeSyncAgentPrivilege
= SeSyncAgentPrivilege
;
80 SepExports
.SeEnableDelegationPrivilege
= SeEnableDelegationPrivilege
;
82 SeExports
= &SepExports
;
90 SepInitializationPhase0(VOID
)
95 if (!SepInitSecurityIDs()) return FALSE
;
96 if (!SepInitDACLs()) return FALSE
;
97 if (!SepInitSDs()) return FALSE
;
99 if (!SepInitExports()) return FALSE
;
101 /* Initialize the subject context lock */
102 ExInitializeResource(&SepSubjectContextLock
);
104 /* Initialize token objects */
105 SepInitializeTokenImplementation();
107 /* Clear impersonation info for the idle thread */
108 PsGetCurrentThread()->ImpersonationInfo
= NULL
;
109 PspClearCrossThreadFlag(PsGetCurrentThread(),
110 CT_ACTIVE_IMPERSONATION_INFO_BIT
);
112 /* Initialize the boot token */
113 ObInitializeFastReference(&PsGetCurrentProcess()->Token
, NULL
);
114 ObInitializeFastReference(&PsGetCurrentProcess()->Token
,
115 SepCreateSystemProcessToken());
122 SepInitializationPhase1(VOID
)
124 OBJECT_ATTRIBUTES ObjectAttributes
;
126 HANDLE SecurityHandle
;
132 /* Insert the system token into the tree */
133 Status
= ObInsertObject((PVOID
)(PsGetCurrentProcess()->Token
.Value
&
140 ASSERT(NT_SUCCESS(Status
));
142 /* TODO: Create a security desscriptor for the directory */
144 /* Create '\Security' directory */
145 RtlInitUnicodeString(&Name
, L
"\\Security");
146 InitializeObjectAttributes(&ObjectAttributes
,
148 OBJ_PERMANENT
| OBJ_CASE_INSENSITIVE
,
152 Status
= ZwCreateDirectoryObject(&SecurityHandle
,
153 DIRECTORY_ALL_ACCESS
,
155 ASSERT(NT_SUCCESS(Status
));
157 /* Create 'LSA_AUTHENTICATION_INITIALIZED' event */
158 RtlInitUnicodeString(&Name
, L
"LSA_AUTHENTICATION_INITIALIZED");
159 InitializeObjectAttributes(&ObjectAttributes
,
161 OBJ_PERMANENT
| OBJ_CASE_INSENSITIVE
,
165 Status
= ZwCreateEvent(&EventHandle
,
170 ASSERT(NT_SUCCESS(Status
));
172 Status
= ZwClose(EventHandle
);
173 ASSERT(NT_SUCCESS(Status
));
175 Status
= ZwClose(SecurityHandle
);
176 ASSERT(NT_SUCCESS(Status
));
186 /* Check the initialization phase */
187 switch (ExpInitializationPhase
)
192 return SepInitializationPhase0();
197 return SepInitializationPhase1();
201 /* Don't know any other phase! Bugcheck! */
202 KeBugCheckEx(UNEXPECTED_INITIALIZATION_CALL
,
204 ExpInitializationPhase
,
213 SeDefaultObjectMethod(IN PVOID Object
,
214 IN SECURITY_OPERATION_CODE OperationType
,
215 IN PSECURITY_INFORMATION SecurityInformation
,
216 IN OUT PSECURITY_DESCRIPTOR SecurityDescriptor
,
217 IN OUT PULONG ReturnLength OPTIONAL
,
218 IN OUT PSECURITY_DESCRIPTOR
*OldSecurityDescriptor
,
219 IN POOL_TYPE PoolType
,
220 IN PGENERIC_MAPPING GenericMapping
)
224 /* Select the operation type */
225 switch (OperationType
)
227 /* Setting a new descriptor */
228 case SetSecurityDescriptor
:
231 ASSERT((PoolType
== PagedPool
) || (PoolType
== NonPagedPool
));
233 /* Set the information */
234 return ObSetSecurityDescriptorInfo(Object
,
237 OldSecurityDescriptor
,
241 case QuerySecurityDescriptor
:
243 /* Query the information */
244 return ObQuerySecurityDescriptorInfo(Object
,
248 OldSecurityDescriptor
);
250 case DeleteSecurityDescriptor
:
253 return ObDeassignSecurity(OldSecurityDescriptor
);
255 case AssignSecurityDescriptor
:
258 ObAssignObjectSecurityDescriptor(Object
, SecurityDescriptor
, PoolType
);
259 return STATUS_SUCCESS
;
264 KeBugCheckEx(SECURITY_SYSTEM
, 0, STATUS_INVALID_PARAMETER
, 0, 0);
267 /* Should never reach here */
269 return STATUS_SUCCESS
;
274 SeQuerySecurityAccessMask(IN SECURITY_INFORMATION SecurityInformation
,
275 OUT PACCESS_MASK DesiredAccess
)
279 if (SecurityInformation
& (OWNER_SECURITY_INFORMATION
|
280 GROUP_SECURITY_INFORMATION
| DACL_SECURITY_INFORMATION
))
282 *DesiredAccess
|= READ_CONTROL
;
285 if (SecurityInformation
& SACL_SECURITY_INFORMATION
)
287 *DesiredAccess
|= ACCESS_SYSTEM_SECURITY
;
293 SeSetSecurityAccessMask(IN SECURITY_INFORMATION SecurityInformation
,
294 OUT PACCESS_MASK DesiredAccess
)
298 if (SecurityInformation
& (OWNER_SECURITY_INFORMATION
| GROUP_SECURITY_INFORMATION
))
300 *DesiredAccess
|= WRITE_OWNER
;
303 if (SecurityInformation
& DACL_SECURITY_INFORMATION
)
305 *DesiredAccess
|= WRITE_DAC
;
308 if (SecurityInformation
& SACL_SECURITY_INFORMATION
)
310 *DesiredAccess
|= ACCESS_SYSTEM_SECURITY
;
316 SeReportSecurityEvent(
318 _In_ PUNICODE_STRING SourceName
,
319 _In_opt_ PSID UserSid
,
320 _In_ PSE_ADT_PARAMETER_ARRAY AuditParameters
)
322 SECURITY_SUBJECT_CONTEXT SubjectContext
;
323 PTOKEN EffectiveToken
;
327 /* Validate parameters */
329 (SourceName
== NULL
) ||
330 (SourceName
->Buffer
== NULL
) ||
331 (SourceName
->Length
== 0) ||
332 (AuditParameters
== NULL
) ||
333 (AuditParameters
->ParameterCount
> SE_MAX_AUDIT_PARAMETERS
- 4))
335 return STATUS_INVALID_PARAMETER
;
338 /* Validate the source name */
339 Status
= RtlValidateUnicodeString(0, SourceName
);
340 if (!NT_SUCCESS(Status
))
345 /* Check if we have a user SID */
349 if (!RtlValidSid(UserSid
))
351 return STATUS_INVALID_PARAMETER
;
354 /* Use the user SID */
359 /* No user SID, capture the security subject context */
360 SeCaptureSubjectContext(&SubjectContext
);
362 /* Extract the effective token */
363 EffectiveToken
= SubjectContext
.ClientToken
?
364 SubjectContext
.ClientToken
: SubjectContext
.PrimaryToken
;
366 /* Use the user-and-groups SID */
367 Sid
= EffectiveToken
->UserAndGroups
->Sid
;
372 /* Check if we captured the subject context */
376 SeReleaseSubjectContext(&SubjectContext
);
380 return STATUS_SUCCESS
;
387 _Inout_ PSE_ADT_PARAMETER_ARRAY AuditParameters
,
388 _In_ SE_ADT_PARAMETER_TYPE Type
,
389 _In_range_(<, SE_MAX_AUDIT_PARAMETERS
) ULONG Index
,
390 _In_reads_(_Inexpressible_("depends on SE_ADT_PARAMETER_TYPE")) PVOID Data
)
393 return STATUS_SUCCESS
;