Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

sep.h File Reference

#include "ntos.h"
#include <ntrmlsa.h>
#include "seopaque.h"

Go to the source code of this file.

Classes

struct  _SEP_LSA_WORK_ITEM
struct  _SEP_WORK_ITEM

Defines

#define IF_SE_GLOBAL(FlagName)   if (FALSE)
#define SeDiagPrint(FlagName, _Text_)   ;
#define SE_DIAG_SD_TRACKING   ((ULONG) 0x00000001L)
#define SepAreFlagsSet(Mask, Bits)
#define SepSetFlags(Mask, Bits)
#define SepClearFlags(Mask, Bits)
#define SepPrivilegeSetSize(PrivilegeSet)
#define EffectiveToken(SubjectSecurityContext)
#define SepTokenUserSid(Token)   ((PTOKEN)(Token))->UserAndGroups->Sid
#define SepTokenAuthenticationId(Token)   (((PTOKEN)(Token))->AuthenticationId)
#define SepBadImpersonationLevel(IL, SIR)
#define IsValidElementCount(Count, STRUCTURE)
#define SEP_MAX_GROUP_COUNT   4096
#define SEP_MAX_PRIVILEGE_COUNT   4096
#define SepLockLsaQueue()
#define SepUnlockLsaQueue()
#define SepWorkListHead()   ((PSEP_LSA_WORK_ITEM)(&SepLsaQueue)->Flink)
#define ExAllocatePool(a, b)   ExAllocatePoolWithTag(a,b,' eS')
#define ExAllocatePoolWithQuota(a, b)   ExAllocatePoolWithQuotaTag(a,b,' eS')

Typedefs

typedef VOID(* PSEP_LSA_WORKER_CLEANUP_ROUTINE )(IN PVOID Parameter)
typedef enum _SEP_LSA_WORK_ITEM_TAG SEP_LSA_WORK_ITEM_TAG
typedef enum _SEP_LSA_WORK_ITEM_TAGPSEP_LSA_WORK_ITEM_TAG
typedef _SEP_LSA_WORK_ITEM SEP_LSA_WORK_ITEM
typedef _SEP_LSA_WORK_ITEMPSEP_LSA_WORK_ITEM
typedef _SEP_WORK_ITEM SEP_WORK_ITEM
typedef _SEP_WORK_ITEMPSEP_WORK_ITEM

Enumerations

enum  _SEP_LSA_WORK_ITEM_TAG { SepDeleteLogon, SepAuditRecord }

Functions

BOOLEAN SepDevelopmentTest (VOID)
BOOLEAN SepInitializationPhase0 (VOID)
BOOLEAN SepInitializationPhase1 (VOID)
BOOLEAN SepVariableInitialization (VOID)
NTSTATUS SepCreateToken (OUT PHANDLE TokenHandle, IN KPROCESSOR_MODE RequestorMode, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, IN TOKEN_TYPE TokenType, IN SECURITY_IMPERSONATION_LEVEL ImpersonationLevel OPTIONAL, IN PLUID AuthenticationId, IN PLARGE_INTEGER ExpirationTime, IN PSID_AND_ATTRIBUTES User, IN ULONG GroupCount, IN PSID_AND_ATTRIBUTES Groups, IN ULONG GroupsLength, IN ULONG PrivilegeCount, IN PLUID_AND_ATTRIBUTES Privileges, IN ULONG PrivilegesLength, IN PSID Owner OPTIONAL, IN PSID PrimaryGroup, IN PACL DefaultDacl OPTIONAL, IN PTOKEN_SOURCE TokenSource, IN BOOLEAN SystemToken, IN PSECURITY_TOKEN_PROXY_DATA ProxyData OPTIONAL, IN PSECURITY_TOKEN_AUDIT_DATA AuditData OPTIONAL)
NTSTATUS SepReferenceLogonSession (IN PLUID LogonId)
VOID SepDeReferenceLogonSession (IN PLUID LogonId)
VOID SepLockSubjectContext (IN PSECURITY_SUBJECT_CONTEXT SubjectContext)
VOID SepFreeSubjectContext (IN PSECURITY_SUBJECT_CONTEXT SubjectContext)
VOID SepGetDefaultsSubjectContext (IN PSECURITY_SUBJECT_CONTEXT SubjectContext, OUT PSID *Owner, OUT PSID *Group, OUT PSID *ServerOwner, OUT PSID *ServerGroup, OUT PACL *Dacl)
BOOLEAN SepValidOwnerSubjectContext (IN PSECURITY_SUBJECT_CONTEXT SubjectContext, IN PSID Owner, IN BOOLEAN ServerObject)
BOOLEAN SepIdAssignableAsGroup (IN PACCESS_TOKEN Token, IN PSID Group)
BOOLEAN SepCheckAcl (IN PACL Acl, IN ULONG Length)
BOOLEAN SepAuditAlarm (IN PUNICODE_STRING SubsystemName, IN PVOID HandleId, IN PUNICODE_STRING ObjectTypeName, IN PUNICODE_STRING ObjectName, IN PSECURITY_DESCRIPTOR SecurityDescriptor, IN ACCESS_MASK DesiredAccess, IN BOOLEAN ObjectCreation, IN ACCESS_MASK GrantedAccess, OUT PBOOLEAN GenerateOnClose)
BOOLEAN SepSinglePrivilegeCheck (LUID DesiredPrivilege, IN PACCESS_TOKEN EffectiveToken, IN KPROCESSOR_MODE PreviousMode)
NTSTATUS SepRmCallLsa (PSEP_WORK_ITEM SepWorkItem)
BOOLEAN SepInitializeWorkList (VOID)
BOOLEAN SepRmInitPhase0 ()
VOID SepConcatenatePrivileges (IN PPRIVILEGE_SET TargetPrivilegeSet, IN ULONG TargetBufferSize, IN PPRIVILEGE_SET SourcePrivilegeSet)
BOOLEAN SepTokenIsOwner (IN PACCESS_TOKEN Token, IN PSECURITY_DESCRIPTOR SecurityDescriptor, IN BOOLEAN TokenLocked)
VOID SepPrintAcl (IN PACL Acl)
VOID SepPrintSid (IN PSID Sid)
VOID SepDumpSecurityDescriptor (IN PSECURITY_DESCRIPTOR SecurityDescriptor, IN PSZ TitleString)
BOOLEAN SepSidTranslation (PSID Sid, PSTRING AccountName)
VOID SepDumpTokenInfo (IN PACCESS_TOKEN Token)
VOID SepDumpString (IN PUNICODE_STRING String)
BOOLEAN SepSidInToken (IN PACCESS_TOKEN Token, IN PSID PrincipalSelfSid, IN PSID Sid, IN BOOLEAN DenyAce)
VOID SepExamineSacl (IN PACL Sacl, IN PACCESS_TOKEN Token, IN ACCESS_MASK DesiredAccess, IN BOOLEAN AccessGranted, OUT PBOOLEAN GenerateAudit, OUT PBOOLEAN GenerateAlarm)
VOID SepCopyString (IN PUNICODE_STRING SourceString, OUT PUNICODE_STRING *DestString)
VOID SepAssemblePrivileges (IN ULONG PrivilegeCount, IN BOOLEAN SystemSecurity, IN BOOLEAN WriteOwner, OUT PPRIVILEGE_SET *Privileges)
PUNICODE_STRING SepQueryTypeString (IN PVOID Object)
POBJECT_NAME_INFORMATION SepQueryNameString (IN PVOID Object)
 *++

BOOLEAN SepFilterPrivilegeAudits (IN PPRIVILEGE_SET PrivilegeSet)
BOOLEAN SepQueueWorkItem (IN PSEP_LSA_WORK_ITEM LsaWorkItem, IN BOOLEAN ForceQueue)
VOID SepAdtGenerateDiscardAudit (VOID)
BOOLEAN SepAdtValidateAuditBounds (ULONG Upper, ULONG Lower)
NTSTATUS SepAdtInitializeCrashOnFail (VOID)
BOOLEAN SepAdtInitializePrivilegeAuditing (VOID)
NTSTATUS SepCopyProxyData (OUT PSECURITY_TOKEN_PROXY_DATA *DestProxyData, IN PSECURITY_TOKEN_PROXY_DATA SourceProxyData)
VOID SepFreeProxyData (IN PSECURITY_TOKEN_PROXY_DATA ProxyData)
NTSTATUS SepProbeAndCaptureQosData (IN PSECURITY_ADVANCED_QUALITY_OF_SERVICE CapturedSecurityQos)
PACCESS_TOKEN SeMakeAnonymousToken ()

Variables

HANDLE SepLsaHandle
BOOLEAN SepAuditShutdownEvents
ERESOURCE SepLsaQueueLock
ULONG SepLsaQueueLength
LIST_ENTRY SepLsaQueue
SEP_WORK_ITEM SepExWorkItem
PSEP_LSA_WORK_ITEM SepDequeueWorkItem (VOID)


Define Documentation

#define EffectiveToken SubjectSecurityContext   ) 
 

Value:

( \ (SubjectSecurityContext)->ClientToken ? \ (SubjectSecurityContext)->ClientToken : \ (SubjectSecurityContext)->PrimaryToken \ ) \

Definition at line 165 of file sep.h.

Referenced by NtCloseObjectAuditAlarm(), NtDeleteObjectAuditAlarm(), SeAccessCheck(), SeAuditHandleDuplication(), SeAuditingFileOrGlobalEvents(), SeCloseObjectAuditAlarm(), SeCreateAccessState(), SeCreateObjectAuditAlarm(), SeDeleteObjectAuditAlarm(), SeObjectReferenceAuditAlarm(), SeOpenObjectAuditAlarm(), SeOpenObjectForDeleteAuditAlarm(), SepAccessCheckAndAuditAlarm(), SepGetDefaultsSubjectContext(), SePrivilegeCheck(), SePrivilegedServiceAuditAlarm(), SePrivilegePolicyCheck(), SepTokenIsOwner(), SepValidOwnerSubjectContext(), SeQueryAuthenticationIdSubjectContext(), and SeTraverseAuditAlarm().

#define ExAllocatePool a,
 )     ExAllocatePoolWithTag(a,b,' eS')
 

Definition at line 296 of file sep.h.

#define ExAllocatePoolWithQuota a,
 )     ExAllocatePoolWithQuotaTag(a,b,' eS')
 

Definition at line 299 of file sep.h.

#define IF_SE_GLOBAL FlagName   )     if (FALSE)
 

Definition at line 79 of file sep.h.

#define IsValidElementCount Count,
STRUCTURE   ) 
 

Value:

( Count < ( (ULONG_PTR) ( (PUCHAR) ( (PUCHAR) (LONG_PTR)(LONG)0xFFFFFFFF - (PUCHAR) MM_SYSTEM_RANGE_START ) + 1 ) \ / sizeof( STRUCTURE ) ) )

Definition at line 242 of file sep.h.

Referenced by NtOpenObjectAuditAlarm(), NtPrivilegeCheck(), NtPrivilegedServiceAuditAlarm(), NtPrivilegeObjectAuditAlarm(), SeAccessCheckByType(), SeCaptureObjectTypeList(), and SepAccessCheckAndAuditAlarm().

#define SE_DIAG_SD_TRACKING   ((ULONG) 0x00000001L)
 

Definition at line 102 of file sep.h.

#define SeDiagPrint FlagName,
_Text_   )     ;
 

Definition at line 85 of file sep.h.

#define SEP_MAX_GROUP_COUNT   4096
 

Definition at line 254 of file sep.h.

Referenced by SeCaptureSidAndAttributesArray().

#define SEP_MAX_PRIVILEGE_COUNT   4096
 

Definition at line 255 of file sep.h.

Referenced by SeCaptureLuidAndAttributesArray().

#define SepAreFlagsSet Mask,
Bits   ) 
 

Value:

( \ ((Mask) & ( Bits )) == ( Bits ) \ )

Definition at line 117 of file sep.h.

#define SepBadImpersonationLevel IL,
SIR   ) 
 

Value:

(( \ ((IL) == SecurityAnonymous) || ((IL) == SecurityIdentification) || \ ( (SIR) && ((IL) != SecurityDelegation) ) \ ) ? TRUE : FALSE )

Definition at line 225 of file sep.h.

Referenced by SepCreateClientSecurity().

#define SepClearFlags Mask,
Bits   ) 
 

Value:

( \ ( Mask ) &= ~( Bits ) \ )

Definition at line 135 of file sep.h.

 
#define SepLockLsaQueue  ) 
 

Value:

Definition at line 287 of file sep.h.

Referenced by SepDequeueWorkItem(), and SepQueueWorkItem().

#define SepPrivilegeSetSize PrivilegeSet   ) 
 

Value:

( ( PrivilegeSet ) == NULL ? 0 : \ ((( PrivilegeSet )->PrivilegeCount > 0) \ ? \ ((ULONG)sizeof(PRIVILEGE_SET) + \ ( \ (( PrivilegeSet )->PrivilegeCount - ANYSIZE_ARRAY) * \ (ULONG)sizeof(LUID_AND_ATTRIBUTES) \ ) \ ) \ : ((ULONG)sizeof(PRIVILEGE_SET) - (ULONG)sizeof(LUID_AND_ATTRIBUTES)) \ ))

Definition at line 147 of file sep.h.

Referenced by SeAccessCheckByType(), SeAppendPrivileges(), and SepConcatenatePrivileges().

#define SepSetFlags Mask,
Bits   ) 
 

Value:

( \ ( Mask ) |= ( Bits ) \ )

Definition at line 126 of file sep.h.

#define SepTokenAuthenticationId Token   )     (((PTOKEN)(Token))->AuthenticationId)
 

Definition at line 183 of file sep.h.

Referenced by NtCloseObjectAuditAlarm(), NtDeleteObjectAuditAlarm(), SeAuditProcessCreation(), SeAuditProcessExit(), SeCloseObjectAuditAlarm(), SeCreateObjectAuditAlarm(), SeDeleteObjectAuditAlarm(), SepAdtObjectReferenceAuditAlarm(), SepAdtOpenObjectAuditAlarm(), SepAdtOpenObjectForDeleteAuditAlarm(), SepAdtPrivilegedServiceAuditAlarm(), SepAdtPrivilegeObjectAuditAlarm(), and SeTraverseAuditAlarm().

#define SepTokenUserSid Token   )     ((PTOKEN)(Token))->UserAndGroups->Sid
 

Definition at line 176 of file sep.h.

Referenced by NtCloseObjectAuditAlarm(), NtDeleteObjectAuditAlarm(), SeAuditHandleDuplication(), SeAuditProcessCreation(), SeAuditProcessExit(), SeCloseObjectAuditAlarm(), SeCreateObjectAuditAlarm(), SeDeleteObjectAuditAlarm(), SepAdtObjectReferenceAuditAlarm(), SepAdtOpenObjectAuditAlarm(), SepAdtOpenObjectForDeleteAuditAlarm(), SepAdtPrivilegedServiceAuditAlarm(), SepAdtPrivilegeObjectAuditAlarm(), SePrivilegedServiceAuditAlarm(), and SeTraverseAuditAlarm().

 
#define SepUnlockLsaQueue  ) 
 

Value:

Definition at line 290 of file sep.h.

Referenced by SepDequeueWorkItem(), and SepQueueWorkItem().

 
#define SepWorkListHead  )     ((PSEP_LSA_WORK_ITEM)(&SepLsaQueue)->Flink)
 

Definition at line 293 of file sep.h.

Referenced by SepRmCallLsa().


Typedef Documentation

typedef struct _SEP_LSA_WORK_ITEM * PSEP_LSA_WORK_ITEM
 

Referenced by SepInformLsaOfDeletedLogon().

typedef enum _SEP_LSA_WORK_ITEM_TAG * PSEP_LSA_WORK_ITEM_TAG
 

typedef VOID(* PSEP_LSA_WORKER_CLEANUP_ROUTINE)(IN PVOID Parameter)
 

Definition at line 304 of file sep.h.

typedef struct _SEP_WORK_ITEM * PSEP_WORK_ITEM
 

Referenced by SepRmCallLsa().

typedef struct _SEP_LSA_WORK_ITEM SEP_LSA_WORK_ITEM
 

Referenced by SepAdtLogAuditRecord(), and SepInformLsaOfDeletedLogon().

typedef enum _SEP_LSA_WORK_ITEM_TAG SEP_LSA_WORK_ITEM_TAG
 

typedef struct _SEP_WORK_ITEM SEP_WORK_ITEM
 


Enumeration Type Documentation

enum _SEP_LSA_WORK_ITEM_TAG
 

Enumeration values:
SepDeleteLogon 
SepAuditRecord 

Definition at line 309 of file sep.h.


Function Documentation

PACCESS_TOKEN SeMakeAnonymousToken  ) 
 

VOID SepAdtGenerateDiscardAudit VOID   ) 
 

Definition at line 2717 of file sepaudit.c.

References ASSERT, PAGED_CODE, SeLocalSystemSid, SepAdtCountEventsDiscarded, SepAdtLogAuditRecord(), SepSetParmTypeSid, SepSetParmTypeString, SepSetParmTypeUlong, and SeSubsystemName.

Referenced by SepQueueWorkItem().

02723 : 02724 02725 Generates an 'audits discarded' audit. 02726 02727 Arguments: 02728 02729 none 02730 02731 Return Value: 02732 02733 None. 02734 02735 --*/ 02736 02737 { 02738 02739 SE_ADT_PARAMETER_ARRAY AuditParameters; 02740 PSID UserSid; 02741 02742 PAGED_CODE(); 02743 02744 UserSid = SeLocalSystemSid; 02745 02746 RtlZeroMemory ( 02747 (PVOID) &AuditParameters, 02748 sizeof( AuditParameters ) 02749 ); 02750 02751 02752 ASSERT( SeAdtParmTypeNone == 0 ); 02753 02754 AuditParameters.CategoryId = SE_CATEGID_SYSTEM; 02755 AuditParameters.AuditId = SE_AUDITID_AUDITS_DISCARDED; 02756 AuditParameters.ParameterCount = 0; 02757 AuditParameters.Type = EVENTLOG_AUDIT_SUCCESS; 02758 02759 SepSetParmTypeSid( AuditParameters, AuditParameters.ParameterCount, UserSid ); 02760 AuditParameters.ParameterCount++; 02761 02762 SepSetParmTypeString( AuditParameters, AuditParameters.ParameterCount, &SeSubsystemName ); 02763 AuditParameters.ParameterCount++; 02764 02765 SepSetParmTypeUlong( AuditParameters, AuditParameters.ParameterCount, SepAdtCountEventsDiscarded ); 02766 AuditParameters.ParameterCount++; 02767 02768 SepAdtLogAuditRecord( &AuditParameters ); 02769 } }

NTSTATUS SepAdtInitializeCrashOnFail VOID   ) 
 

Definition at line 242 of file adtinit.c.

References ASSERT, CHAR, FALSE, KeyName, L, NT_SUCCESS, NtClose(), NtOpenKey(), NtQueryValueKey(), NTSTATUS(), NULL, RtlInitUnicodeString(), SepCrashOnAuditFail, Status, TRUE, and ValueName.

Referenced by SeRmInitPhase1().

00248 : 00249 00250 Reads the registry to see if the user has told us to crash if an audit fails. 00251 00252 Arguments: 00253 00254 None. 00255 00256 Return Value: 00257 00258 STATUS_SUCCESS 00259 00260 --*/ 00261 00262 { 00263 HANDLE KeyHandle; 00264 NTSTATUS Status; 00265 NTSTATUS TmpStatus; 00266 OBJECT_ATTRIBUTES Obja; 00267 ULONG ResultLength; 00268 UNICODE_STRING KeyName; 00269 UNICODE_STRING ValueName; 00270 CHAR KeyInfo[sizeof(KEY_VALUE_PARTIAL_INFORMATION) + sizeof(BOOLEAN)]; 00271 PKEY_VALUE_PARTIAL_INFORMATION pKeyInfo; 00272 00273 SepCrashOnAuditFail = FALSE; 00274 00275 // 00276 // Check the value of the CrashOnAudit flag in the registry. 00277 // 00278 00279 RtlInitUnicodeString( &KeyName, L"\\Registry\\Machine\\System\\CurrentControlSet\\Control\\Lsa"); 00280 00281 InitializeObjectAttributes( &Obja, 00282 &KeyName, 00283 OBJ_CASE_INSENSITIVE, 00284 NULL, 00285 NULL 00286 ); 00287 00288 Status = NtOpenKey( 00289 &KeyHandle, 00290 KEY_QUERY_VALUE | KEY_SET_VALUE, 00291 &Obja 00292 ); 00293 00294 if (Status == STATUS_OBJECT_NAME_NOT_FOUND) { 00295 return( STATUS_SUCCESS ); 00296 } 00297 00298 RtlInitUnicodeString( &ValueName, CRASH_ON_AUDIT_FAIL_VALUE ); 00299 00300 Status = NtQueryValueKey( 00301 KeyHandle, 00302 &ValueName, 00303 KeyValuePartialInformation, 00304 KeyInfo, 00305 sizeof(KeyInfo), 00306 &ResultLength 00307 ); 00308 00309 TmpStatus = NtClose(KeyHandle); 00310 ASSERT(NT_SUCCESS(TmpStatus)); 00311 00312 // 00313 // If the key isn't there, don't turn on CrashOnFail. 00314 // 00315 00316 if (NT_SUCCESS( Status )) { 00317 00318 pKeyInfo = (PKEY_VALUE_PARTIAL_INFORMATION)KeyInfo; 00319 if ((UCHAR) *(pKeyInfo->Data) == LSAP_CRASH_ON_AUDIT_FAIL) { 00320 SepCrashOnAuditFail = TRUE; 00321 } 00322 } 00323 00324 return( STATUS_SUCCESS ); 00325 }

BOOLEAN SepAdtInitializePrivilegeAuditing VOID   ) 
 

Definition at line 329 of file adtinit.c.

References ASSERT, CHAR, FALSE, FULL_PRIVILEGE_AUDITING, KeyName, L, NT_SUCCESS, NtClose(), NtOpenKey(), NtQueryValueKey(), NTSTATUS(), NULL, PAGED_CODE, RtlInitUnicodeString(), SepInitializePrivilegeFilter(), Status, and ValueName.

Referenced by SeRmInitPhase1().

00335 : 00336 00337 Checks to see if there is an entry in the registry telling us to do full privilege auditing 00338 (which currently means audit everything we normall audit, plus backup and restore privileges). 00339 00340 Arguments: 00341 00342 None 00343 00344 Return Value: 00345 00346 BOOLEAN - TRUE if Auditing has been initialized correctly, else FALSE. 00347 00348 --*/ 00349 00350 { 00351 HANDLE KeyHandle; 00352 NTSTATUS Status; 00353 NTSTATUS TmpStatus; 00354 OBJECT_ATTRIBUTES Obja; 00355 ULONG ResultLength; 00356 UNICODE_STRING KeyName; 00357 UNICODE_STRING ValueName; 00358 CHAR KeyInfo[sizeof(KEY_VALUE_PARTIAL_INFORMATION) + sizeof(BOOLEAN)]; 00359 PKEY_VALUE_PARTIAL_INFORMATION pKeyInfo; 00360 BOOLEAN Verbose; 00361 00362 PAGED_CODE(); 00363 00364 // 00365 // Query the registry to set up the privilege auditing filter. 00366 // 00367 00368 RtlInitUnicodeString( &KeyName, L"\\Registry\\Machine\\System\\CurrentControlSet\\Control\\Lsa"); 00369 00370 InitializeObjectAttributes( &Obja, 00371 &KeyName, 00372 OBJ_CASE_INSENSITIVE, 00373 NULL, 00374 NULL 00375 ); 00376 00377 Status = NtOpenKey( 00378 &KeyHandle, 00379 KEY_QUERY_VALUE | KEY_SET_VALUE, 00380 &Obja 00381 ); 00382 00383 00384 if (!NT_SUCCESS( Status )) { 00385 00386 if (Status == STATUS_OBJECT_NAME_NOT_FOUND) { 00387 00388 return ( SepInitializePrivilegeFilter( FALSE )); 00389 00390 } else { 00391 00392 return( FALSE ); 00393 } 00394 } 00395 00396 RtlInitUnicodeString( &ValueName, FULL_PRIVILEGE_AUDITING ); 00397 00398 Status = NtQueryValueKey( 00399 KeyHandle, 00400 &ValueName, 00401 KeyValuePartialInformation, 00402 KeyInfo, 00403 sizeof(KeyInfo), 00404 &ResultLength 00405 ); 00406 00407 TmpStatus = NtClose(KeyHandle); 00408 ASSERT(NT_SUCCESS(TmpStatus)); 00409 00410 if (!NT_SUCCESS( Status )) { 00411 00412 Verbose = FALSE; 00413 00414 } else { 00415 00416 pKeyInfo = (PKEY_VALUE_PARTIAL_INFORMATION)KeyInfo; 00417 Verbose = (BOOLEAN) *(pKeyInfo->Data); 00418 } 00419 00420 return ( SepInitializePrivilegeFilter( Verbose )); 00421 }

BOOLEAN SepAdtValidateAuditBounds ULONG  Upper,
ULONG  Lower
 

Definition at line 39 of file adtinit.c.

References FALSE, PAGED_CODE, and TRUE.

Referenced by SepAdtInitializeBounds().

00046 : 00047 00048 Examines the audit queue high and low water mark values and performs 00049 a general sanity check on them. 00050 00051 Arguments: 00052 00053 Upper - High water mark. 00054 00055 Lower - Low water mark. 00056 00057 Return Value: 00058 00059 TRUE - values are acceptable. 00060 00061 FALSE - values are unacceptable. 00062 00063 00064 --*/ 00065 00066 { 00067 PAGED_CODE(); 00068 00069 if ( Lower >= Upper ) { 00070 return( FALSE ); 00071 } 00072 00073 if ( Lower < 16 ) { 00074 return( FALSE ); 00075 } 00076 00077 if ( (Upper - Lower) < 16 ) { 00078 return( FALSE ); 00079 } 00080 00081 return( TRUE ); 00082 }

VOID SepAssemblePrivileges IN ULONG  PrivilegeCount,
IN BOOLEAN  SystemSecurity,
IN BOOLEAN  WriteOwner,
OUT PPRIVILEGE_SET *  Privileges
 

Definition at line 1071 of file seglobal.c.

References ASSERT, DoublePrivilegeSetSize, ExAllocatePoolWithTag, NULL, PAGED_CODE, PagedPool, POOL_RAISE_IF_ALLOCATION_FAILURE, SepDoublePrivilegeSet, SepSystemSecurityPrivilegeSet, SepTakeOwnershipPrivilegeSet, and SinglePrivilegeSetSize.

Referenced by SepAccessCheck().

01079 : 01080 01081 This routine takes the results of the various privilege checks 01082 in SeAccessCheck and returns an appropriate privilege set. 01083 01084 Arguments: 01085 01086 PrivilegeCount - The number of privileges granted. 01087 01088 SystemSecurity - Provides a boolean indicating whether to put 01089 SeSecurityPrivilege into the output privilege set. 01090 01091 WriteOwner - Provides a boolean indicating whether to put 01092 SeTakeOwnershipPrivilege into the output privilege set. 01093 01094 Privileges - Supplies a pointer that will return the privilege 01095 set. Should be freed with ExFreePool when no longer needed. 01096 01097 Return Value: 01098 01099 None. 01100 01101 --*/ 01102 { 01103 PPRIVILEGE_SET PrivilegeSet; 01104 ULONG SizeRequired; 01105 01106 PAGED_CODE(); 01107 01108 ASSERT( (PrivilegeCount != 0) && (PrivilegeCount <= 2) ); 01109 01110 if ( !ARGUMENT_PRESENT( Privileges ) ) { 01111 return; 01112 } 01113 01114 if ( PrivilegeCount == 1 ) { 01115 01116 SizeRequired = SinglePrivilegeSetSize; 01117 01118 if ( SystemSecurity ) { 01119 01120 PrivilegeSet = SepSystemSecurityPrivilegeSet; 01121 01122 } else { 01123 01124 ASSERT( WriteOwner ); 01125 01126 PrivilegeSet = SepTakeOwnershipPrivilegeSet; 01127 } 01128 01129 } else { 01130 01131 SizeRequired = DoublePrivilegeSetSize; 01132 PrivilegeSet = SepDoublePrivilegeSet; 01133 } 01134 01135 *Privileges = ExAllocatePoolWithTag( PagedPool | POOL_RAISE_IF_ALLOCATION_FAILURE, SizeRequired, 'rPeS' ); 01136 01137 if ( *Privileges != NULL ) { 01138 01139 RtlCopyMemory ( 01140 *Privileges, 01141 PrivilegeSet, 01142 SizeRequired 01143 ); 01144 } 01145 }

BOOLEAN SepAuditAlarm IN PUNICODE_STRING  SubsystemName,
IN PVOID  HandleId,
IN PUNICODE_STRING  ObjectTypeName,
IN PUNICODE_STRING  ObjectName,
IN PSECURITY_DESCRIPTOR  SecurityDescriptor,
IN ACCESS_MASK  DesiredAccess,
IN BOOLEAN  ObjectCreation,
IN ACCESS_MASK  GrantedAccess,
OUT PBOOLEAN  GenerateOnClose
 

BOOLEAN SepCheckAcl IN PACL  Acl,
IN ULONG  Length
 

Definition at line 36 of file sep.c.

References FALSE, and RtlValidAcl().

Referenced by SeCaptureAcl(), and SeCaptureSecurityDescriptor().

00043 : 00044 00045 This is a private routine that checks that an acl is well formed. 00046 00047 Arguments: 00048 00049 Acl - Supplies the acl to check 00050 00051 Length - Supplies the real size of the acl. The internal acl size 00052 must agree. 00053 00054 Return Value: 00055 00056 BOOLEAN - TRUE if the acl is well formed and FALSE otherwise 00057 00058 --*/ 00059 { 00060 if ((Length < sizeof(ACL)) || (Length != Acl->AclSize)) { 00061 return FALSE; 00062 } 00063 return RtlValidAcl( Acl ); 00064 } }

VOID SepConcatenatePrivileges IN PPRIVILEGE_SET  TargetPrivilegeSet,
IN ULONG  TargetBufferSize,
IN PPRIVILEGE_SET  SourcePrivilegeSet
 

Definition at line 543 of file seastate.c.

References ASSERT, PAGED_CODE, SEP_PRIVILEGE_SET_HEADER_SIZE, and SepPrivilegeSetSize.

Referenced by SeAppendPrivileges().

00551 : 00552 00553 Takes two privilege sets and appends the second to the end of the 00554 first. 00555 00556 There must be enough space left at the end of the first privilege 00557 set to contain the second. 00558 00559 Arguments: 00560 00561 TargetPrivilegeSet - Supplies a buffer containing a privilege set. 00562 The buffer must be large enough to contain the second privilege 00563 set. 00564 00565 TargetBufferSize - Supplies the size of the target buffer. 00566 00567 SourcePrivilegeSet - Supplies the privilege set to be copied 00568 into the target buffer. 00569 00570 Return Value: 00571 00572 None 00573 00574 --*/ 00575 00576 { 00577 PVOID Base; 00578 PVOID Source; 00579 ULONG Length; 00580 00581 PAGED_CODE(); 00582 00583 ASSERT( ((ULONG)SepPrivilegeSetSize( TargetPrivilegeSet ) + 00584 (ULONG)SepPrivilegeSetSize( SourcePrivilegeSet ) - 00585 SEP_PRIVILEGE_SET_HEADER_SIZE ) <= 00586 TargetBufferSize 00587 ); 00588 00589 Base = (PVOID)((ULONG_PTR)TargetPrivilegeSet + SepPrivilegeSetSize( TargetPrivilegeSet )); 00590 00591 Source = (PVOID) ((ULONG_PTR)SourcePrivilegeSet + SEP_PRIVILEGE_SET_HEADER_SIZE); 00592 00593 Length = SourcePrivilegeSet->PrivilegeCount * sizeof(LUID_AND_ATTRIBUTES); 00594 00595 RtlMoveMemory( 00596 Base, 00597 Source, 00598 Length 00599 ); 00600 00601 TargetPrivilegeSet->PrivilegeCount += SourcePrivilegeSet->PrivilegeCount; 00602 00603 } }

NTSTATUS SepCopyProxyData OUT PSECURITY_TOKEN_PROXY_DATA *  DestProxyData,
IN PSECURITY_TOKEN_PROXY_DATA  SourceProxyData
 

Definition at line 681 of file se/capture.c.

References ExAllocatePoolWithTag, ExFreePool(), NULL, PAGED_CODE, PagedPool, and RtlCopyUnicodeString().

Referenced by SepCreateToken(), SepDuplicateToken(), SepFilterToken(), and SepProbeAndCaptureQosData().

00688 : 00689 00690 This routine copies a token proxy data structure from one token to another. 00691 00692 Arguments: 00693 00694 DestProxyData - Receives a pointer to a new proxy data structure. 00695 00696 SourceProxyData - Supplies a pointer to an already existing proxy data structure. 00697 00698 Return Value: 00699 00700 STATUS_INSUFFICIENT_RESOURCES on failure. 00701 00702 --*/ 00703 00704 { 00705 00706 PAGED_CODE(); 00707 00708 *DestProxyData = ExAllocatePoolWithTag( PagedPool, sizeof( SECURITY_TOKEN_PROXY_DATA ), 'dPoT' ); 00709 00710 if (*DestProxyData == NULL) { 00711 return( STATUS_INSUFFICIENT_RESOURCES ); 00712 } 00713 00714 00715 00716 (*DestProxyData)->PathInfo.Buffer = ExAllocatePoolWithTag( PagedPool, SourceProxyData->PathInfo.Length, 'dPoT' ); 00717 00718 if ((*DestProxyData)->PathInfo.Buffer == NULL) { 00719 ExFreePool( *DestProxyData ); 00720 *DestProxyData = NULL; 00721 return( STATUS_INSUFFICIENT_RESOURCES ); 00722 } 00723 00724 (*DestProxyData)->Length = SourceProxyData->Length; 00725 (*DestProxyData)->ProxyClass = SourceProxyData->ProxyClass; 00726 (*DestProxyData)->PathInfo.MaximumLength = 00727 (*DestProxyData)->PathInfo.Length = SourceProxyData->PathInfo.Length; 00728 (*DestProxyData)->ContainerMask = SourceProxyData->ContainerMask; 00729 (*DestProxyData)->ObjectMask = SourceProxyData->ObjectMask; 00730 00731 RtlCopyUnicodeString( &(*DestProxyData)->PathInfo, &SourceProxyData->PathInfo ); 00732 00733 return( STATUS_SUCCESS ); 00734 }

VOID SepCopyString IN PUNICODE_STRING  SourceString,
OUT PUNICODE_STRING *  DestString
 

NTSTATUS SepCreateToken OUT PHANDLE  TokenHandle,
IN KPROCESSOR_MODE  RequestorMode,
IN ACCESS_MASK  DesiredAccess,
IN POBJECT_ATTRIBUTES ObjectAttributes  OPTIONAL,
IN TOKEN_TYPE  TokenType,
IN SECURITY_IMPERSONATION_LEVEL ImpersonationLevel  OPTIONAL,
IN PLUID  AuthenticationId,
IN PLARGE_INTEGER  ExpirationTime,
IN PSID_AND_ATTRIBUTES  User,
IN ULONG  GroupCount,
IN PSID_AND_ATTRIBUTES  Groups,
IN ULONG  GroupsLength,
IN ULONG  PrivilegeCount,
IN PLUID_AND_ATTRIBUTES  Privileges,
IN ULONG  PrivilegesLength,
IN PSID Owner  OPTIONAL,
IN PSID  PrimaryGroup,
IN PACL DefaultDacl  OPTIONAL,
IN PTOKEN_SOURCE  TokenSource,
IN BOOLEAN  SystemToken,
IN PSECURITY_TOKEN_PROXY_DATA ProxyData  OPTIONAL,
IN PSECURITY_TOKEN_AUDIT_DATA AuditData  OPTIONAL
 

Definition at line 2213 of file token.c.

References ALIGN_UP, ASSERT, ExAllocateLocallyUniqueId, ExAllocatePool, ExAllocatePoolWithTag, FALSE, _OBJECT_TYPE_INITIALIZER::GenericMapping, NT_SUCCESS, NTSTATUS(), NULL, ObCreateObject(), ObDeleteCapturedInsertInfo(), ObDereferenceObject, ObInsertObject(), ObjectAttributes, Owner, PAGED_CODE, PagedPool, PTOKEN, RtlCopySid(), RtlCopySidAndAttributesArray(), RtlEqualLuid(), RtlEqualSid(), RtlLengthRequiredSid(), SeAliasAdminsSid, SeChangeNotifyPrivilege, SeCreateAccessState(), SeCreateTokenPrivilege, SeDeleteAccessState(), SepArrayGroupAttributes, SepCopyProxyData(), SepDeReferenceLogonSession(), SepReferenceLogonSession(), SepTokenObjectType, SeSinglePrivilegeCheck(), Status, Token, TOKEN_DEFAULT_DYNAMIC_CHARGE, TOKEN_HAS_ADMIN_GROUP, TOKEN_HAS_TRAVERSE_PRIVILEGE, TRUE, _OBJECT_TYPE::TypeInfo, and UserMode.

Referenced by NtCreateToken(), SeMakeAnonymousLogonToken(), and SeMakeSystemToken().

02240 : 02241 02242 Create a token object and return a handle opened for access to 02243 that token. This API implements the bulk of the work needed 02244 for NtCreateToken. 02245 02246 All parameters except DesiredAccess and ObjectAttributes are assumed 02247 to have been probed and captured. 02248 02249 The output parameter (TokenHandle) is expected to be returned to a 02250 safe address, rather than to a user mode address that may cause an 02251 exception. 02252 02253 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 02254 NOTE: This routine is also used to create the initial system token. 02255 In that case, the SystemToken parameter is TRUE and no handle 02256 is established to the token. Instead, a pointer to the token 02257 is returned via the TokenHandle parameter. 02258 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 02259 02260 02261 Arguments: 02262 02263 TokenHandle - Receives the handle of the newly created token. If the 02264 SystemToken parameter is specified is true, then this parameter 02265 receives a pointer to the token instead of a handle to the token. 02266 02267 RequestorMode - The mode of the caller on whose behalf the token 02268 is being created. 02269 02270 DesiredAccess - Is an access mask indicating which access types 02271 the handle is to provide to the new object. 02272 02273 ObjectAttributes - Points to the standard object attributes data 02274 structure. Refer to the NT Object Management 02275 Specification for a description of this data structure. 02276 02277 TokenType - Type of token to be created. Privilege is required 02278 to create any type of token. 02279 02280 ImpersonationLevel - If the token type is TokenImpersonation, then 02281 this parameter is used to specify the impersonation level of 02282 the token. 02283 02284 AuthenticationId - Points to a LUID (or LUID) providing a unique 02285 identifier associated with the authentication. This is used 02286 within security only, for audit purposes. 02287 02288 ExpirationTime - Time at which the token becomes invalid. If this 02289 value is specified as zero, then the token has no expiration 02290 time. 02291 02292 User - Is the user SID to place in the token. 02293 02294 GroupCount - Indicates the number of groups in the 'Groups' parameter. 02295 This value may be zero, in which case the 'Groups' parameter is 02296 ignored. 02297 02298 Groups - Are the group SIDs, and their corresponding attributes, 02299 to place in the token. 02300 02301 GroupsLength - Indicates the length, in bytes, of the array of groups 02302 to place in the token. 02303 02304 PrivilegeCount - Indicates the number of privileges in the 'Privileges' 02305 parameter. This value may be zero, in which case the 'Privileges' 02306 parameter is ignored. 02307 02308 Privileges - Are the privilege LUIDs, and their corresponding attributes, 02309 to place in the token. 02310 02311 PrivilegesLength - Indicates the length, in bytes, of the array of 02312 privileges to place in the token. 02313 02314 Owner - (Optionally) identifies an identifier that is to be used 02315 as the default owner for the token. If not provided, the 02316 user ID is made the default owner. 02317 02318 PrimaryGroup - Identifies which of the group IDs is to be the 02319 primary group of the token. 02320 02321 DefaultDacl - (optionally) establishes an ACL to be used as the 02322 default discretionary access protection for the token. 02323 02324 TokenSource - Identifies the token source name string and 02325 identifier to be assigned to the token. 02326 02327 Return Value: 02328 02329 STATUS_SUCCESS - Indicates the operation was successful. 02330 02331 STATUS_INVALID_OWNER - Indicates the ID provided to be assigned 02332 as the default owner of the token does not have an attribute 02333 indicating it may be assigned as an owner. 02334 02335 STATUS_INVALID_PRIMARY_GROUP - Indicates the group ID provided 02336 via the PrimaryGroup parameter was not among those assigned 02337 to the token in the Groups parameter. 02338 02339 STATUS_INVALID_PARAMETER - Indicates that a required parameter, 02340 such as User or PrimaryGroup, was not provided with a legitimate 02341 value. 02342 02343 --*/ 02344 02345 { 02346 02347 PTOKEN Token; 02348 NTSTATUS Status; 02349 02350 ULONG PagedPoolSize; 02351 02352 ULONG PrimaryGroupLength; 02353 02354 ULONG TokenBodyLength; 02355 ULONG VariableLength; 02356 02357 ULONG DefaultOwnerIndex; 02358 PUCHAR Where ; 02359 ULONG ComputedPrivLength ; 02360 02361 //ULONG_PTR NextFree; 02362 PSID NextSidFree; 02363 02364 ULONG DynamicLength = TOKEN_DEFAULT_DYNAMIC_CHARGE; 02365 ULONG DynamicLengthUsed; 02366 02367 ULONG SubAuthorityCount; 02368 ULONG GroupIndex; 02369 ULONG PrivilegeIndex; 02370 BOOLEAN OwnerFound; 02371 02372 UCHAR TokenFlags = 0; 02373 02374 ACCESS_STATE AccessState; 02375 AUX_ACCESS_DATA AuxData; 02376 LUID NewModifiedId; 02377 02378 PAGED_CODE(); 02379 02380 ASSERT( sizeof(SECURITY_IMPERSONATION_LEVEL) <= sizeof(ULONG) ); 02381 02382 // 02383 // Make sure the Enabled and Enabled-by-default bits are set on every 02384 // mandatory group. 02385 // 02386 // Also, check to see if the local administrators alias is present. 02387 // if so, turn on the flag so that we can do restrictions later 02388 // 02389 02390 for (GroupIndex=0; GroupIndex < GroupCount; GroupIndex++) { 02391 if (Groups[GroupIndex].Attributes & SE_GROUP_MANDATORY) { 02392 Groups[GroupIndex].Attributes |= (SE_GROUP_ENABLED | SE_GROUP_ENABLED_BY_DEFAULT); 02393 } 02394 if ( RtlEqualSid( SeAliasAdminsSid, Groups[GroupIndex].Sid ) ) 02395 { 02396 TokenFlags |= TOKEN_HAS_ADMIN_GROUP ; 02397 } 02398 } 02399 02400 // 02401 // Check to see if the token being created is going to be granted 02402 // SeChangeNotifyPrivilege. If so, set a flag in the TokenFlags field 02403 // so we can find this out quickly. 02404 // 02405 02406 for (PrivilegeIndex = 0; PrivilegeIndex < PrivilegeCount; PrivilegeIndex++) { 02407 02408 if (((RtlEqualLuid(&Privileges[PrivilegeIndex].Luid,&SeChangeNotifyPrivilege)) 02409 && 02410 (Privileges[PrivilegeIndex].Attributes & SE_PRIVILEGE_ENABLED))) { 02411 02412 TokenFlags |= TOKEN_HAS_TRAVERSE_PRIVILEGE; 02413 break; 02414 } 02415 } 02416 02417 02418 // 02419 // Get a ModifiedId to use 02420 // 02421 02422 ExAllocateLocallyUniqueId( &NewModifiedId ); 02423 02424 // 02425 // Validate the owner ID, if provided and establish the default 02426 // owner index. 02427 // 02428 02429 if (!ARGUMENT_PRESENT(Owner)) { 02430 02431 DefaultOwnerIndex = 0; 02432 02433 } else { 02434 02435 02436 if ( RtlEqualSid( Owner, User->Sid ) ) { 02437 02438 DefaultOwnerIndex = 0; 02439 02440 } else { 02441 02442 GroupIndex = 0; 02443 OwnerFound = FALSE; 02444 02445 while ((GroupIndex < GroupCount) && (!OwnerFound)) { 02446 02447 if ( RtlEqualSid( Owner, (Groups[GroupIndex].Sid) ) ) { 02448 02449 // 02450 // Found a match - make sure it is assignable as owner. 02451 // 02452 02453 if ( SepArrayGroupAttributes( Groups, GroupIndex ) & 02454 SE_GROUP_OWNER ) { 02455 02456 DefaultOwnerIndex = GroupIndex + 1; 02457 OwnerFound = TRUE; 02458 02459 } else { 02460 02461 return STATUS_INVALID_OWNER; 02462 02463 } // endif Owner attribute set 02464 02465 } // endif owner = group 02466 02467 GroupIndex += 1; 02468 02469 } // endwhile 02470 02471 if (!OwnerFound) { 02472 02473 return STATUS_INVALID_OWNER; 02474 02475 } // endif !OwnerFound 02476 } // endif owner = user 02477 } // endif owner specified 02478 02479 02480 02481 // 02482 // Increment the reference count for this logon session 02483 // (fail if there is no corresponding logon session.) 02484 // 02485 02486 Status = SepReferenceLogonSession( AuthenticationId ); 02487 if ( !NT_SUCCESS(Status) ) { 02488 return Status; 02489 } 02490 02491 02492 02493 02494 // 02495 // Calculate the length needed for the variable portion of the token 02496 // This includes the User ID, Group IDs, and Privileges 02497 // 02498 // 02499 // Align the privilege chunk by pointer alignment so that the SIDs will 02500 // be correctly aligned. Align the Groups Length so that the SID_AND_ATTR 02501 // array (which is 02502 // 02503 02504 ComputedPrivLength = PrivilegeCount * sizeof( LUID_AND_ATTRIBUTES ) ; 02505 02506 ComputedPrivLength = ALIGN_UP( ComputedPrivLength, PVOID ); 02507 02508 GroupsLength = ALIGN_UP( GroupsLength, PVOID ); 02509 02510 02511 VariableLength = GroupsLength + ComputedPrivLength + 02512 ALIGN_UP( (GroupCount * sizeof( SID_AND_ATTRIBUTES )), PVOID ) ; 02513 02514 SubAuthorityCount = ((SID *)(User->Sid))->SubAuthorityCount; 02515 VariableLength += sizeof(SID_AND_ATTRIBUTES) + 02516 (ULONG)LongAlignSize(RtlLengthRequiredSid( SubAuthorityCount )); 02517 02518 02519 02520 // 02521 // Calculate the length needed for the dynamic portion of the token 02522 // This includes the default Dacl and the primary group. 02523 // 02524 02525 SubAuthorityCount = ((SID *)PrimaryGroup)->SubAuthorityCount; 02526 DynamicLengthUsed = (ULONG)LongAlignSize(RtlLengthRequiredSid( SubAuthorityCount )); 02527 02528 if (ARGUMENT_PRESENT(DefaultDacl)) { 02529 DynamicLengthUsed += (ULONG)LongAlignSize(DefaultDacl->AclSize); 02530 } 02531 02532 if (DynamicLengthUsed > DynamicLength) { 02533 DynamicLength = DynamicLengthUsed; 02534 } 02535 02536 // 02537 // Now create the token body 02538 // 02539 02540 TokenBodyLength = sizeof(TOKEN) + VariableLength; 02541 PagedPoolSize = TokenBodyLength + DynamicLength; 02542 02543 02544 Status = ObCreateObject( 02545 RequestorMode, // ProbeMode 02546 SepTokenObjectType, // ObjectType 02547 ObjectAttributes, // ObjectAttributes 02548 UserMode, // OwnershipMode 02549 NULL, // ParseContext 02550 TokenBodyLength, // ObjectBodySize 02551 PagedPoolSize, // PagedPoolCharge 02552 0, // NonPagedPoolCharge 02553 (PVOID *)&Token // Return pointer to object 02554 ); 02555 02556 if (!NT_SUCCESS(Status)) { 02557 SepDeReferenceLogonSession( AuthenticationId ); 02558 return Status; 02559 } 02560 02561 // 02562 // After this point, we rely on token deletion to clean up the referenced 02563 // logon session if the creation fails. 02564 // 02565 02566 02567 // 02568 // Main Body initialization 02569 // 02570 02571 02572 ExAllocateLocallyUniqueId( &(Token->TokenId) ); 02573 Token->ParentTokenId = RtlConvertLongToLuid(0); 02574 Token->AuthenticationId = (*AuthenticationId); 02575 Token->TokenInUse = FALSE; 02576 Token->ModifiedId = NewModifiedId; 02577 Token->ExpirationTime = (*ExpirationTime); 02578 Token->TokenType = TokenType; 02579 Token->ImpersonationLevel = ImpersonationLevel; 02580 Token->TokenSource = (*TokenSource); 02581 02582 Token->TokenFlags = TokenFlags; 02583 Token->SessionId = 0; 02584 02585 Token->DynamicCharged = DynamicLength; 02586 Token->DynamicAvailable = DynamicLength - DynamicLengthUsed; 02587 02588 Token->DefaultOwnerIndex = DefaultOwnerIndex; 02589 Token->DefaultDacl = NULL; 02590 02591 Token->VariableLength = VariableLength; 02592 02593 // Ensure SepTokenDeleteMethod knows the buffers aren't allocated yet. 02594 Token->ProxyData = NULL; 02595 Token->AuditData = NULL; 02596 Token->DynamicPart = NULL; 02597 02598 if (ARGUMENT_PRESENT( ProxyData )) { 02599 02600 Status = SepCopyProxyData( 02601 &Token->ProxyData, 02602 ProxyData 02603 ); 02604 02605 if (!NT_SUCCESS(Status)) { 02606 ObDereferenceObject( Token ); 02607 return( STATUS_NO_MEMORY ); 02608 } 02609 02610 } else { 02611 02612 Token->ProxyData = NULL; 02613 } 02614 02615 if (ARGUMENT_PRESENT( AuditData )) { 02616 02617 Token->AuditData = ExAllocatePool( PagedPool, sizeof( SECURITY_TOKEN_AUDIT_DATA )); 02618 02619 if (Token->AuditData == NULL) { 02620 ObDereferenceObject( Token ); 02621 return( STATUS_NO_MEMORY ); 02622 } 02623 02624 *(Token->AuditData) = *AuditData; 02625 02626 } else { 02627 02628 Token->AuditData = NULL; 02629 } 02630 02631 02632 // 02633 // Variable part initialization 02634 // Data is in the following order: 02635 // 02636 // Privileges array 02637 // User (SID_AND_ATTRIBUTES) 02638 // Groups (SID_AND_ATTRIBUTES) 02639 // Restricted Sids (SID_AND_ATTRIBUTES) 02640 // SIDs 02641 // 02642 02643 Where = (PUCHAR) & Token->VariablePart ; 02644 02645 Token->Privileges = (PLUID_AND_ATTRIBUTES) Where ; 02646 Token->PrivilegeCount = PrivilegeCount ; 02647 02648 RtlCopyMemory( 02649 Where, 02650 Privileges, 02651 PrivilegeCount * sizeof(LUID_AND_ATTRIBUTES) ); 02652 02653 ASSERT( ComputedPrivLength >= PrivilegeCount * sizeof( LUID_AND_ATTRIBUTES ) ); 02654 02655 Where += ComputedPrivLength ; 02656 VariableLength -= ComputedPrivLength ; 02657 02658 ASSERT( (((ULONG_PTR) Where ) & (sizeof(PVOID) - 1)) == 0 ); 02659 02660 // 02661 // Now, copy the sid and attributes arrays. 02662 // 02663 02664 NextSidFree = (PSID) (Where + (sizeof( SID_AND_ATTRIBUTES ) * 02665 (GroupCount + 1) ) ); 02666 02667 Token->UserAndGroups = (PSID_AND_ATTRIBUTES) Where ; 02668 Token->UserAndGroupCount = GroupCount + 1 ; 02669 02670 02671 ASSERT(VariableLength >= ((GroupCount + 1) * (ULONG)sizeof(SID_AND_ATTRIBUTES))); 02672 02673 VariableLength -= ((GroupCount + 1) * (ULONG)sizeof(SID_AND_ATTRIBUTES)); 02674 Status = RtlCopySidAndAttributesArray( 02675 1, 02676 User, 02677 VariableLength, 02678 (PSID_AND_ATTRIBUTES)Where, 02679 NextSidFree, 02680 &NextSidFree, 02681 &VariableLength 02682 ); 02683 02684 Where += sizeof( SID_AND_ATTRIBUTES ); 02685 02686 ASSERT( (((ULONG_PTR) Where ) & (sizeof(PVOID) - 1)) == 0 ); 02687 02688 Status = RtlCopySidAndAttributesArray( 02689 GroupCount, 02690 Groups, 02691 VariableLength, 02692 (PSID_AND_ATTRIBUTES)Where, 02693 NextSidFree, 02694 &NextSidFree, 02695 &VariableLength 02696 ); 02697 02698 02699 ASSERT(NT_SUCCESS(Status)); 02700 02701 02702 Token->RestrictedSids = NULL; 02703 Token->RestrictedSidCount = 0; 02704 02705 02706 // 02707 // Dynamic part initialization 02708 // Data is in the following order: 02709 // 02710 // PrimaryGroup (SID) 02711 // Default Discreationary Acl (ACL) 02712 // 02713 02714 Token->DynamicPart = (PULONG)ExAllocatePoolWithTag( PagedPool, DynamicLength, 'dTeS' ); 02715 02716 // 02717 // The attempt to allocate the DynamicPart of the token may have 02718 // failed. Dereference the created object and exit with an error. 02719 // 02720 02721 if (Token->DynamicPart == NULL) { 02722 ObDereferenceObject( Token ); 02723 return( STATUS_NO_MEMORY ); 02724 } 02725 02726 02727 Where = (PUCHAR) Token->DynamicPart; 02728 02729 Token->PrimaryGroup = (PSID) Where; 02730 PrimaryGroupLength = RtlLengthRequiredSid( ((SID *)PrimaryGroup)->SubAuthorityCount ); 02731 RtlCopySid( PrimaryGroupLength, (PSID)Where, PrimaryGroup ); 02732 Where += (ULONG)LongAlignSize(PrimaryGroupLength); 02733 02734 if (ARGUMENT_PRESENT(DefaultDacl)) { 02735 Token->DefaultDacl = (PACL)Where; 02736 02737 RtlCopyMemory( (PVOID)Where, 02738 (PVOID)DefaultDacl, 02739 DefaultDacl->AclSize 02740 ); 02741 } 02742 02743 #ifdef TOKEN_DEBUG 02744 02745 // 02746 // Debug 02747 SepDumpToken( Token ); 02748 // Debug 02749 // 02751 #endif //TOKEN_DEBUG 02752 02753 02754 // 02755 // Insert the token unless it is a system token. 02756 // 02757 02758 if (!SystemToken) { 02759 02760 Status = SeCreateAccessState( 02761 &AccessState, 02762 &AuxData, 02763 DesiredAccess, 02764 &SepTokenObjectType->TypeInfo.GenericMapping 02765 ); 02766 02767 if ( NT_SUCCESS(Status) ) { 02768 BOOLEAN PrivilegeHeld; 02769 02770 PrivilegeHeld = SeSinglePrivilegeCheck( 02771 SeCreateTokenPrivilege, 02772 KeGetPreviousMode() 02773 ); 02774 02775 if (PrivilegeHeld) { 02776 02777 Status = ObInsertObject( Token, 02778 &AccessState, 02779 0, 02780 0, 02781 (PVOID *)NULL, 02782 TokenHandle 02783 ); 02784 02785 } else { 02786 02787 Status = STATUS_PRIVILEGE_NOT_HELD; 02788 ObDereferenceObject( Token ); 02789 } 02790 02791 SeDeleteAccessState( &AccessState ); 02792 02793 } else { 02794 02795 ObDereferenceObject( Token ); 02796 } 02797 } else { 02798 02799 ASSERT( NT_SUCCESS( Status ) ); 02800 ObDeleteCapturedInsertInfo(Token); 02801 // 02802 // Return pointer instead of handle. 02803 // 02804 02805 (*TokenHandle) = (HANDLE)Token; 02806 } 02807 02808 return Status; 02809 02810 }

VOID SepDeReferenceLogonSession IN PLUID  LogonId  ) 
 

Definition at line 384 of file rmlogon.c.

References DbgPrint, ExFreePool(), _SEP_LOGON_SESSION_REFERENCES::Flags, KeBugCheck(), _SEP_LOGON_SESSION_REFERENCES::LogonId, _SEP_LOGON_SESSION_REFERENCES::Next, NULL, PAGED_CODE, PsGetCurrentThread, _SEP_LOGON_SESSION_REFERENCES::ReferenceCount, RtlEqualLuid(), SEP_TERMINATION_NOTIFY, SepInformFileSystemsOfDeletedLogon(), SepInformLsaOfDeletedLogon(), SepLogonSessionIndex, SepLogonSessions, SepRmAcquireDbWriteLock, and SepRmReleaseDbWriteLock.

Referenced by SepCreateToken(), SepDuplicateToken(), SepFilterToken(), and SepTokenDeleteMethod().

00390 : 00391 00392 This routine decrements the reference count of a logon session 00393 tracking record. 00394 00395 If the reference count is decremented to zero, then there is no 00396 possibility for any more tokens to exist for the logon session. 00397 In this case, the LSA is notified that a logon session has 00398 terminated. 00399 00400 00401 00402 Arguments: 00403 00404 LogonId - Pointer to the logon session ID whose logon track is 00405 to be decremented. 00406 00407 Return Value: 00408 00409 None. 00410 00411 --*/ 00412 00413 { 00414 00415 ULONG SessionArrayIndex; 00416 PSEP_LOGON_SESSION_REFERENCES Previous, Current; 00417 00418 #ifdef SEP_TRACK_LOGON_SESSION_REFS 00419 ULONG Refs; 00420 #endif //SEP_TRACK_LOGON_SESSION_REFS 00421 00422 PAGED_CODE(); 00423 00424 SessionArrayIndex = SepLogonSessionIndex( LogonId ); 00425 00426 // 00427 // Protect modification of reference monitor database 00428 // 00429 00430 SepRmAcquireDbWriteLock(); 00431 00432 00433 // 00434 // Now walk the list for our logon session array hash index. 00435 // 00436 00437 Previous = (PSEP_LOGON_SESSION_REFERENCES) 00438 ((PVOID)&SepLogonSessions[ SessionArrayIndex ]); 00439 Current = Previous->Next; 00440 00441 while (Current != NULL) { 00442 00443 // 00444 // If we found it, decrement the reference count and return 00445 // 00446 00447 if (RtlEqualLuid( LogonId, &Current->LogonId) ) { 00448 Current->ReferenceCount -= 1; 00449 if (Current->ReferenceCount == 0) { 00450 00451 // 00452 // Pull it from the list 00453 // 00454 00455 Previous->Next = Current->Next; 00456 00457 00458 // 00459 // No longer need to protect our pointer to this 00460 // record. 00461 // 00462 00463 SepRmReleaseDbWriteLock(); 00464 00465 // 00466 // Asynchronoously inform file systems that this logon session 00467 // is going away, if atleast one FS expressed interest in this 00468 // logon session. 00469 // 00470 00471 if (Current->Flags & SEP_TERMINATION_NOTIFY) { 00472 SepInformFileSystemsOfDeletedLogon( LogonId ); 00473 } 00474 00475 // 00476 // Deallocate the logon session track record. 00477 // 00478 00479 ExFreePool( (PVOID)Current ); 00480 00481 00482 #ifdef SEP_TRACK_LOGON_SESSION_REFS 00483 DbgPrint("SE (rm): -- ** logon session: (%d, %d) to ZERO by (%d, %d)\n", 00484 LogonId->HighPart, LogonId->LowPart, 00485 PsGetCurrentThread()->Cid.UniqueProcess, 00486 PsGetCurrentThread()->Cid.UniqueThread); 00487 00488 #endif //SEP_TRACK_LOGON_SESSION_REFS 00489 00490 // 00491 // Inform the LSA about the deletion of this logon session. 00492 // 00493 00494 SepInformLsaOfDeletedLogon( LogonId ); 00495 00496 00497 00498 return; 00499 00500 } 00501 00502 // 00503 // reference count was incremented, but not to zero. 00504 // 00505 00506 #ifdef SEP_TRACK_LOGON_SESSION_REFS 00507 Refs = Current->ReferenceCount; 00508 #endif //SEP_TRACK_LOGON_SESSION_REFS 00509 00510 SepRmReleaseDbWriteLock(); 00511 00512 #ifdef SEP_TRACK_LOGON_SESSION_REFS 00513 DbgPrint("SE (rm): -- logon session: (%d, %d) to %d by (%d, %d)\n", 00514 LogonId->HighPart, LogonId->LowPart, Refs, 00515 PsGetCurrentThread()->Cid.UniqueProcess, 00516 PsGetCurrentThread()->Cid.UniqueThread); 00517 #endif //SEP_TRACK_LOGON_SESSION_REFS 00518 00519 return; 00520 } 00521 00522 Previous = Current; 00523 Current = Current->Next; 00524 } 00525 00526 SepRmReleaseDbWriteLock(); 00527 00528 // 00529 // Bad news, someone asked us to decrement the reference count of 00530 // a logon session we didn't know existed. 00531 // 00532 00533 KeBugCheck( DEREF_UNKNOWN_LOGON_SESSION ); 00534 00535 return; 00536 00537 }

BOOLEAN SepDevelopmentTest VOID   ) 
 

Referenced by SepInitializationPhase1().

VOID SepDumpSecurityDescriptor IN PSECURITY_DESCRIPTOR  SecurityDescriptor,
IN PSZ  TitleString
 

Definition at line 650 of file seassign.c.

References Dacl, DbgPrint, Group, Owner, PAGED_CODE, SepPrintAcl(), and SepPrintSid().

Referenced by SeAccessCheck(), SeAssignSecurity(), SeAssignSecurityEx(), and SepAccessCheck().

00657 : 00658 00659 Private routine to dump a security descriptor to the debug 00660 screen. 00661 00662 Arguments: 00663 00664 SecurityDescriptor - Supplies the security descriptor to be dumped. 00665 00666 TitleString - A null terminated string to print before dumping 00667 the security descriptor. 00668 00669 00670 Return Value: 00671 00672 None. 00673 00674 00675 --*/ 00676 { 00677 #if DBG 00678 PISECURITY_DESCRIPTOR ISecurityDescriptor; 00679 UCHAR Revision; 00680 SECURITY_DESCRIPTOR_CONTROL Control; 00681 PSID Owner; 00682 PSID Group; 00683 PACL Sacl; 00684 PACL Dacl; 00685 00686 PAGED_CODE(); 00687 00688 00689 if (!SepDumpSD) { 00690 return; 00691 } 00692 00693 if (!ARGUMENT_PRESENT( SecurityDescriptor )) { 00694 return; 00695 } 00696 00697 DbgPrint(TitleString); 00698 00699 ISecurityDescriptor = ( PISECURITY_DESCRIPTOR )SecurityDescriptor; 00700 00701 Revision = ISecurityDescriptor->Revision; 00702 Control = ISecurityDescriptor->Control; 00703 00704 Owner = RtlpOwnerAddrSecurityDescriptor( ISecurityDescriptor ); 00705 Group = RtlpGroupAddrSecurityDescriptor( ISecurityDescriptor ); 00706 Sacl = RtlpSaclAddrSecurityDescriptor( ISecurityDescriptor ); 00707 Dacl = RtlpDaclAddrSecurityDescriptor( ISecurityDescriptor ); 00708 00709 DbgPrint("\nSECURITY DESCRIPTOR\n"); 00710 00711 DbgPrint("Revision = %d\n",Revision); 00712 00713 // 00714 // Print control info 00715 // 00716 00717 if (Control & SE_OWNER_DEFAULTED) { 00718 DbgPrint("Owner defaulted\n"); 00719 } 00720 if (Control & SE_GROUP_DEFAULTED) { 00721 DbgPrint("Group defaulted\n"); 00722 } 00723 if (Control & SE_DACL_PRESENT) { 00724 DbgPrint("Dacl present\n"); 00725 } 00726 if (Control & SE_DACL_DEFAULTED) { 00727 DbgPrint("Dacl defaulted\n"); 00728 } 00729 if (Control & SE_SACL_PRESENT) { 00730 DbgPrint("Sacl present\n"); 00731 } 00732 if (Control & SE_SACL_DEFAULTED) { 00733 DbgPrint("Sacl defaulted\n"); 00734 } 00735 if (Control & SE_SELF_RELATIVE) { 00736 DbgPrint("Self relative\n"); 00737 } 00738 if (Control & SE_DACL_UNTRUSTED) { 00739 DbgPrint("Dacl untrusted\n"); 00740 } 00741 if (Control & SE_SERVER_SECURITY) { 00742 DbgPrint("Server security\n"); 00743 } 00744 00745 DbgPrint("Owner "); 00746 SepPrintSid( Owner ); 00747 00748 DbgPrint("Group "); 00749 SepPrintSid( Group ); 00750 00751 DbgPrint("Sacl"); 00752 SepPrintAcl( Sacl ); 00753 00754 DbgPrint("Dacl"); 00755 SepPrintAcl( Dacl ); 00756 #endif 00757 }

VOID SepDumpString IN PUNICODE_STRING  String  ) 
 

Definition at line 36 of file adtutil.c.

References NULL, PAGED_CODE, and String.

00040 { 00041 PAGED_CODE(); 00042 00043 if ( String == NULL) { 00044 KdPrint(("<NULL>")); 00045 return; 00046 } 00047 00048 KdPrint(("%Z",String->Buffer)); 00049 00050 }

VOID SepDumpTokenInfo IN PACCESS_TOKEN  Token  ) 
 

Definition at line 995 of file seassign.c.

References DbgPrint, PAGED_CODE, PTOKEN, SepPrintSid(), and Token.

Referenced by SeAccessCheck(), SepAccessCheck(), SepSidInToken(), and SepSidInTokenEx().

01001 : 01002 01003 Prints interesting information in a token. 01004 01005 Arguments: 01006 01007 Token - Provides the token to be examined. 01008 01009 01010 Return Value: 01011 01012 None. 01013 01014 --*/ 01015 01016 { 01017 #if DBG 01018 ULONG UserAndGroupCount; 01019 PSID_AND_ATTRIBUTES TokenSid; 01020 ULONG i; 01021 PTOKEN IToken; 01022 01023 PAGED_CODE(); 01024 01025 if (!SepDumpToken) { 01026 return; 01027 } 01028 01029 IToken = (TOKEN *)Token; 01030 01031 UserAndGroupCount = IToken->UserAndGroupCount; 01032 01033 DbgPrint("\n\nToken Address=%lx\n",IToken); 01034 DbgPrint("Token User and Groups Array:\n\n"); 01035 01036 for ( i = 0 , TokenSid = IToken->UserAndGroups; 01037 i < UserAndGroupCount ; 01038 i++, TokenSid++ 01039 ) { 01040 01041 SepPrintSid( TokenSid->Sid ); 01042 01043 } 01044 01045 if ( IToken->RestrictedSids ) { 01046 UserAndGroupCount = IToken->RestrictedSidCount; 01047 01048 DbgPrint("Restricted Sids Array:\n\n"); 01049 01050 for ( i = 0 , TokenSid = IToken->RestrictedSids; 01051 i < UserAndGroupCount ; 01052 i++, TokenSid++ 01053 ) { 01054 01055 SepPrintSid( TokenSid->Sid ); 01056 01057 } 01058 } 01059 #endif 01060 }

VOID SepExamineSacl IN PACL  Sacl,
IN PACCESS_TOKEN  Token,
IN ACCESS_MASK  DesiredAccess,
IN BOOLEAN  AccessGranted,
OUT PBOOLEAN  GenerateAudit,
OUT PBOOLEAN  GenerateAlarm
 

Definition at line 3952 of file seaudit.c.

References FALSE, FirstAce, NextAce, NULL, PAGED_CODE, SepSidInToken(), Token, and TRUE.

Referenced by NtOpenObjectAuditAlarm(), SeCreateObjectAuditAlarm(), SeObjectReferenceAuditAlarm(), SeOpenObjectAuditAlarm(), SeOpenObjectForDeleteAuditAlarm(), and SeTraverseAuditAlarm().

03963 : 03964 03965 This routine will examine the passed Sacl and determine what 03966 if any action is required based its contents. 03967 03968 Note that this routine is not aware of any system state, ie, 03969 whether or not auditing is currently enabled for either the 03970 system or this particular object type. 03971 03972 Arguments: 03973 03974 Sacl - Supplies a pointer to the Sacl to be examined. 03975 03976 Token - Supplies the effective token of the caller 03977 03978 AccessGranted - Supplies whether or not the access attempt 03979 was successful. 03980 03981 GenerateAudit - Returns a boolean indicating whether or not 03982 we should generate an audit. 03983 03984 GenerateAlarm - Returns a boolean indiciating whether or not 03985 we should generate an alarm. 03986 03987 Return Value: 03988 03989 STATUS_SUCCESS - The operation completed successfully. 03990 03991 --*/ 03992 03993 { 03994 03995 ULONG i; 03996 PVOID Ace; 03997 ULONG AceCount; 03998 ACCESS_MASK AccessMask; 03999 UCHAR AceFlags; 04000 BOOLEAN FailedMaximumAllowed; 04001 04002 PAGED_CODE(); 04003 04004 *GenerateAudit = FALSE; 04005 *GenerateAlarm = FALSE; 04006 04007 // 04008 // If we failed an attempt to open an object for ONLY maximumum allowed, 04009 // then we generate an audit if ANY ACCESS_DENIED audit matching this 04010 // user's list of sids is found 04011 // 04012 04013 FailedMaximumAllowed = FALSE; 04014 if (!AccessGranted && (DesiredAccess & MAXIMUM_ALLOWED)) { 04015 FailedMaximumAllowed = TRUE; 04016 } 04017 04018 // 04019 // If the Sacl is null, do nothing and return 04020 // 04021 04022 if (Sacl == NULL) { 04023 04024 return; 04025 } 04026 04027 AceCount = Sacl->AceCount; 04028 04029 if (AceCount == 0) { 04030 return; 04031 } 04032 04033 // 04034 // Iterate through the ACEs on the Sacl until either we reach 04035 // the end or discover that we have to take all possible actions, 04036 // in which case it doesn't pay to look any further 04037 // 04038 04039 for ( i = 0, Ace = FirstAce( Sacl ) ; 04040 (i < AceCount) && !(*GenerateAudit && *GenerateAlarm); 04041 i++, Ace = NextAce( Ace ) ) { 04042 04043 if ( !(((PACE_HEADER)Ace)->AceFlags & INHERIT_ONLY_ACE)) { 04044 04045 if ( (((PACE_HEADER)Ace)->AceType == SYSTEM_AUDIT_ACE_TYPE) ) { 04046 04047 if ( SepSidInToken( (PACCESS_TOKEN)Token, NULL, &((PSYSTEM_AUDIT_ACE)Ace)->SidStart, FALSE ) ) { 04048 04049 AccessMask = ((PSYSTEM_AUDIT_ACE)Ace)->Mask; 04050 AceFlags = ((PACE_HEADER)Ace)->AceFlags; 04051 04052 if ( AccessMask & DesiredAccess ) { 04053 04054 if (((AceFlags & SUCCESSFUL_ACCESS_ACE_FLAG) && AccessGranted) || 04055 ((AceFlags & FAILED_ACCESS_ACE_FLAG) && !AccessGranted)) { 04056 04057 *GenerateAudit = TRUE; 04058 } 04059 } else if ( FailedMaximumAllowed && (AceFlags & FAILED_ACCESS_ACE_FLAG) ) { 04060 *GenerateAudit = TRUE; 04061 } 04062 } 04063 04064 continue; 04065 } 04066 04067 if ( (((PACE_HEADER)Ace)->AceType == SYSTEM_ALARM_ACE_TYPE) ) { 04068 04069 if ( SepSidInToken( (PACCESS_TOKEN)Token, NULL, &((PSYSTEM_ALARM_ACE)Ace)->SidStart, FALSE ) ) { 04070 04071 AccessMask = ((PSYSTEM_ALARM_ACE)Ace)->Mask; 04072 04073 if ( AccessMask & DesiredAccess ) { 04074 04075 AceFlags = ((PACE_HEADER)Ace)->AceFlags; 04076 04077 if (((AceFlags & SUCCESSFUL_ACCESS_ACE_FLAG) && AccessGranted) || 04078 ((AceFlags & FAILED_ACCESS_ACE_FLAG) && !AccessGranted)) { 04079 04080 *GenerateAlarm = TRUE; 04081 } 04082 } 04083 } 04084 } 04085 } 04086 } 04087 04088 return; 04089 }

BOOLEAN SepFilterPrivilegeAudits IN PPRIVILEGE_SET  PrivilegeSet  ) 
 

Definition at line 4587 of file seaudit.c.

References FALSE, NULL, PAGED_CODE, RtlEqualLuid(), SepFilterPrivileges, and TRUE.

Referenced by SeOpenObjectAuditAlarm(), SeOpenObjectForDeleteAuditAlarm(), SepAdtPrivilegeObjectAuditAlarm(), and SePrivilegedServiceAuditAlarm().

04593 : 04594 04595 This routine will filter out a list of privileges as listed in the 04596 SepFilterPrivileges array. 04597 04598 Arguments: 04599 04600 Privileges - The privilege set to be audited 04601 04602 Return Value: 04603 04604 FALSE means that this use of privilege is not to be audited. 04605 TRUE means that the audit should continue normally. 04606 04607 --*/ 04608 04609 { 04610 PLUID *Privilege; 04611 ULONG Match = 0; 04612 ULONG i; 04613 04614 PAGED_CODE(); 04615 04616 if ( !ARGUMENT_PRESENT(PrivilegeSet) || 04617 (PrivilegeSet->PrivilegeCount == 0) ) { 04618 return( FALSE ); 04619 } 04620 04621 for (i=0; i<PrivilegeSet->PrivilegeCount; i++) { 04622 04623 Privilege = SepFilterPrivileges; 04624 04625 do { 04626 04627 if ( RtlEqualLuid( &PrivilegeSet->Privilege[i].Luid, *Privilege )) { 04628 04629 Match++; 04630 break; 04631 } 04632 04633 } while ( *++Privilege != NULL ); 04634 } 04635 04636 if ( Match == PrivilegeSet->PrivilegeCount ) { 04637 04638 return( FALSE ); 04639 04640 } else { 04641 04642 return( TRUE ); 04643 } 04644 }

VOID SepFreeProxyData IN PSECURITY_TOKEN_PROXY_DATA  ProxyData  ) 
 

Definition at line 737 of file se/capture.c.

References ExFreePool(), NULL, and PAGED_CODE.

Referenced by SeCaptureSecurityQos(), SeFreeCapturedSecurityQos(), SepDuplicateToken(), SepFilterToken(), SepProbeAndCaptureQosData(), and SepTokenDeleteMethod().

00743 : 00744 00745 This routine frees a SECURITY_TOKEN_PROXY_DATA structure and all sub structures. 00746 00747 Arguments: 00748 00749 ProxyData - Supplies a pointer to an existing proxy data structure. 00750 00751 Return Value: 00752 00753 None. 00754 00755 --*/ 00756 { 00757 PAGED_CODE(); 00758 00759 if (ProxyData != NULL) { 00760 00761 if (ProxyData->PathInfo.Buffer != NULL) { 00762 ExFreePool( ProxyData->PathInfo.Buffer ); 00763 } 00764 00765 ExFreePool( ProxyData ); 00766 } 00767 }

VOID SepFreeSubjectContext IN PSECURITY_SUBJECT_CONTEXT  SubjectContext  ) 
 

VOID SepGetDefaultsSubjectContext IN PSECURITY_SUBJECT_CONTEXT  SubjectContext,
OUT PSID *  Owner,
OUT PSID *  Group,
OUT PSID *  ServerOwner,
OUT PSID *  ServerGroup,
OUT PACL *  Dacl
 

Definition at line 234 of file subject.c.

References EffectiveToken, PAGED_CODE, PrimaryToken, and PTOKEN.

Referenced by RtlpNewSecurityObject(), and RtlpSetSecurityObject().

00244 : 00245 00246 This routine retrieves pointers to the default owner, primary group, 00247 and, if present, discretionary ACL of the provided subject security 00248 context. 00249 00250 Arguments: 00251 00252 SubjectContext - Points to the subject security context whose default 00253 values are to be retrieved. 00254 00255 Owner - Receives a pointer to the subject's default owner SID. This 00256 value will always be returned as a non-zero pointer. That is, 00257 a subject's security context must contain a owner SID. 00258 00259 Group - Receives a pointer to the subject's default primary group SID. 00260 This value will always be returned as a non-zero pointer. That is, 00261 a subject's security context must contain a primary group. 00262 00263 Dacl - Receives a pointer to the subject's default discretionary ACL, 00264 if one is define for the subject. Note that a subject security context 00265 does not have to include a default discretionary ACL. In this case, 00266 this value will be returned as NULL. 00267 00268 00269 00270 00271 Return Value: 00272 00273 none. 00274 00275 --*/ 00276 00277 { 00278 PTOKEN EffectiveToken; 00279 PTOKEN PrimaryToken; 00280 00281 PAGED_CODE(); 00282 00283 if (ARGUMENT_PRESENT(SubjectContext->ClientToken)) { 00284 EffectiveToken = (PTOKEN)SubjectContext->ClientToken; 00285 } else { 00286 EffectiveToken = (PTOKEN)SubjectContext->PrimaryToken; 00287 } 00288 00289 (*Owner) = EffectiveToken->UserAndGroups[EffectiveToken->DefaultOwnerIndex].Sid; 00290 00291 (*Group) = EffectiveToken->PrimaryGroup; 00292 00293 (*Dacl) = EffectiveToken->DefaultDacl; 00294 00295 PrimaryToken = (PTOKEN)SubjectContext->PrimaryToken; 00296 00297 *ServerOwner = PrimaryToken->UserAndGroups[PrimaryToken->DefaultOwnerIndex].Sid; 00298 00299 *ServerGroup = PrimaryToken->PrimaryGroup; 00300 00301 return; 00302 }

BOOLEAN SepIdAssignableAsGroup IN PACCESS_TOKEN  Token,
IN PSID  Group
 

Definition at line 306 of file subject.c.

References FALSE, Group, Index, NULL, PAGED_CODE, PTOKEN, RtlEqualSid(), SepAcquireTokenReadLock, SepReleaseTokenReadLock, and Token.

Referenced by NtSetInformationToken().

00312 : 00313 00314 This routine checks to see whether the provided SID is one that 00315 may be assigned to be the default primary group in a token. 00316 00317 The current criteria is that the passed SID be a group in the 00318 token, with no other restrictions. 00319 00320 Arguments: 00321 00322 Token - Points to the token to be examined. 00323 00324 Group - Points to the SID to be checked. 00325 00326 Return Value: 00327 00328 TRUE - SID passed by be assigned as the default primary group in a token. 00329 00330 FALSE - Passed SID may not be so assigned. 00331 00332 --*/ 00333 00334 { 00335 ULONG Index; 00336 BOOLEAN Found = FALSE; 00337 PTOKEN Token; 00338 00339 PAGED_CODE(); 00340 00341 Token = (PTOKEN)AToken; 00342 00343 // 00344 // Let's make it invalid to assign a NULL primary group, 00345 // but we may need to revisit this. 00346 // 00347 00348 if (Group == NULL) { 00349 return( FALSE ); 00350 } 00351 00352 SepAcquireTokenReadLock( Token ); 00353 00354 // 00355 // Walk through the list of user and group IDs looking 00356 // for a match to the specified SID. 00357 // 00358 00359 Index = 0; 00360 while (Index < Token->UserAndGroupCount) { 00361 00362 Found = RtlEqualSid( 00363 Group, 00364 Token->UserAndGroups[Index].Sid 00365 ); 00366 00367 if ( Found ) { 00368 break; 00369 } 00370 00371 Index += 1; 00372 } 00373 00374 SepReleaseTokenReadLock( Token ); 00375 00376 return Found; 00377 }

BOOLEAN SepInitializationPhase0 VOID   ) 
 

Definition at line 78 of file seinit.c.

References ExLuidInitialization(), FALSE, NULL, PAGED_CODE, PsGetCurrentProcess, PsGetCurrentThread, SeMakeSystemToken(), SepInitializeWorkList(), SepRmInitPhase0(), SepTokenInitialization(), and SepVariableInitialization().

Referenced by SeInitSystem().

00082 : 00083 00084 Perform phase 0 security initialization. 00085 00086 This includes: 00087 00088 - Initialize LUID allocation 00089 - Initialize security global variables 00090 - initialize the token object. 00091 - Initialize the necessary security components of the boot thread/process 00092 00093 00094 Arguments: 00095 00096 None. 00097 00098 Return Value: 00099 00100 TRUE - Initialization was successful. 00101 00102 FALSE - Initialization Failed. 00103 00104 --*/ 00105 00106 { 00107 00108 PAGED_CODE(); 00109 00110 // 00111 // LUID allocation services are needed by security prior to phase 0 00112 // Executive initialization. So, LUID initialization is performed 00113 // here 00114 // 00115 00116 if (ExLuidInitialization() == FALSE) { 00117 KdPrint(("Security: Locally Unique ID initialization failed.\n")); 00118 return FALSE; 00119 } 00120 00121 // 00122 // Initialize security global variables 00123 // 00124 00125 if (!SepVariableInitialization()) { 00126 KdPrint(("Security: Global variable initialization failed.\n")); 00127 return FALSE; 00128 } 00129 00130 // 00131 // Perform Phase 0 Reference Monitor Initialization. 00132 // 00133 00134 if (!SepRmInitPhase0()) { 00135 KdPrint(("Security: Ref Mon state initialization failed.\n")); 00136 return FALSE; 00137 } 00138 00139 // 00140 // Initialize the token object type. 00141 // 00142 00143 if (!SepTokenInitialization()) { 00144 KdPrint(("Security: Token object initialization failed.\n")); 00145 return FALSE; 00146 } 00147 00148 // // 00149 // // Initialize auditing structures 00150 // // 00151 // 00152 // if (!SepAdtInitializePhase0()) { 00153 // KdPrint(("Security: Auditing initialization failed.\n")); 00154 // return FALSE; 00155 // } 00156 // 00157 // 00158 // Initialize SpinLock and list for the LSA worker thread 00159 // 00160 00161 // 00162 // Initialize the work queue spinlock, list head, and semaphore 00163 // for each of the work queues. 00164 // 00165 00166 if (!SepInitializeWorkList()) { 00167 KdPrint(("Security: Unable to initialize work queue\n")); 00168 return FALSE; 00169 } 00170 00171 // 00172 // Initialize the security fields of the boot thread. 00173 // 00174 00175 PsGetCurrentProcess()->Token = SeMakeSystemToken(); 00176 PsGetCurrentThread()->ImpersonationInfo = NULL; 00177 PsGetCurrentThread()->ActiveImpersonationInfo = FALSE; 00178 00179 return ( PsGetCurrentProcess()->Token != NULL ); 00180 }

BOOLEAN SepInitializationPhase1 VOID   ) 
 

Definition at line 184 of file seinit.c.

References ASSERT, ASSERTMSG, Dacl, ExAllocatePool, ExFreePool(), FALSE, Name, NonPagedPool, NT_SUCCESS, NtClose(), NtCreateDirectoryObject(), NtCreateEvent(), NTSTATUS(), NULL, ObjectAttributes, PAGED_CODE, RtlAddAccessAllowedAce(), RtlAnsiStringToUnicodeString(), RtlCreateAcl(), RtlCreateSecurityDescriptor(), RtlFreeUnicodeString(), RtlInitString(), RtlSetDaclSecurityDescriptor(), SeAliasAdminsSid, SeAnonymousLogonToken, SeLocalSystemSid, SeMakeAnonymousLogonToken(), SepAdtInitializePhase1(), SepDevelopmentTest(), SePublicDefaultSd, SeWorldSid, Status, and TRUE.

Referenced by SeInitSystem().

00188 : 00189 00190 Perform phase 1 security initialization. 00191 00192 This includes: 00193 00194 - Create an object directory for security related objects. 00195 (\Security). 00196 00197 - Create an event to be signalled after the LSA has initialized. 00198 (\Security\LSA_Initialized) 00199 00200 00201 00202 00203 Arguments: 00204 00205 None. 00206 00207 Return Value: 00208 00209 TRUE - Initialization was successful. 00210 00211 FALSE - Initialization Failed. 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 // Create the security object directory. 00233 // 00234 00235 RtlInitString( &Name, "\\Security" ); 00236 Status = RtlAnsiStringToUnicodeString( 00237 &UnicodeName, 00238 &Name, 00239 TRUE ); ASSERT( NT_SUCCESS(Status) ); 00240 00241 // 00242 // Build up the security descriptor 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 // Create an event in the security directory 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 // Initialize auditing structures 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 } }

BOOLEAN SepInitializeWorkList VOID   ) 
 

Definition at line 1152 of file seglobal.c.

References ExInitializeResource, PAGED_CODE, SepLsaQueue, SepLsaQueueLock, and TRUE.

Referenced by SepInitializationPhase0().

01158 : 01159 01160 Initializes the mutex and list head used to queue work from the 01161 Executive to LSA. This mechanism operates on top of the normal ExWorkerThread 01162 mechanism by capturing the first thread to perform LSA work and keeping it 01163 until all the current work is done. 01164 01165 The reduces the number of worker threads that are blocked on I/O to LSA. 01166 01167 Arguments: 01168 01169 None. 01170 01171 01172 Return Value: 01173 01174 TRUE if successful, FALSE otherwise. 01175 01176 --*/ 01177 01178 { 01179 PAGED_CODE(); 01180 01181 ExInitializeResource(&SepLsaQueueLock); 01182 InitializeListHead(&SepLsaQueue); 01183 return( TRUE ); 01184 } }

VOID SepLockSubjectContext IN PSECURITY_SUBJECT_CONTEXT  SubjectContext  ) 
 

VOID SepPrintAcl IN PACL  Acl  ) 
 

Definition at line 762 of file seassign.c.

References DbgPrint, FALSE, FirstAce, NextAce, NULL, PAGED_CODE, SepPrintSid(), and TRUE.

Referenced by SepDumpSecurityDescriptor().

00768 : 00769 00770 This routine dumps via (DbgPrint) an Acl for debug purposes. It is 00771 specialized to dump standard aces. 00772 00773 Arguments: 00774 00775 Acl - Supplies the Acl to dump 00776 00777 Return Value: 00778 00779 None 00780 00781 --*/ 00782 00783 00784 { 00785 #if DBG 00786 ULONG i; 00787 PKNOWN_ACE Ace; 00788 BOOLEAN KnownType; 00789 00790 PAGED_CODE(); 00791 00792 DbgPrint("@ %8lx\n", Acl); 00793 00794 // 00795 // Check if the Acl is null 00796 // 00797 00798 if (Acl == NULL) { 00799 00800 return; 00801 00802 } 00803 00804 // 00805 // Dump the Acl header 00806 // 00807 00808 DbgPrint(" Revision: %02x", Acl->AclRevision); 00809 DbgPrint(" Size: %04x", Acl->AclSize); 00810 DbgPrint(" AceCount: %04x\n", Acl->AceCount); 00811 00812 // 00813 // Now for each Ace we want do dump it 00814 // 00815 00816 for (i = 0, Ace = FirstAce(Acl); 00817 i < Acl->AceCount; 00818 i++, Ace = NextAce(Ace) ) { 00819 00820 // 00821 // print out the ace header 00822 // 00823 00824 DbgPrint("\n AceHeader: %08lx ", *(PULONG)Ace); 00825 00826 // 00827 // special case on the standard ace types 00828 // 00829 00830 if ((Ace->Header.AceType == ACCESS_ALLOWED_ACE_TYPE) || 00831 (Ace->Header.AceType == ACCESS_DENIED_ACE_TYPE) || 00832 (Ace->Header.AceType == SYSTEM_AUDIT_ACE_TYPE) || 00833 (Ace->Header.AceType == SYSTEM_ALARM_ACE_TYPE) || 00834 (Ace->Header.AceType == ACCESS_ALLOWED_COMPOUND_ACE_TYPE)) { 00835 00836 // 00837 // The following array is indexed by ace types and must 00838 // follow the allowed, denied, audit, alarm seqeuence 00839 // 00840 00841 PCHAR AceTypes[] = { "Access Allowed", 00842 "Access Denied ", 00843 "System Audit ", 00844 "System Alarm ", 00845 "Compound Grant", 00846 }; 00847 00848 DbgPrint(AceTypes[Ace->Header.AceType]); 00849 DbgPrint("\n Access Mask: %08lx ", Ace->Mask); 00850 KnownType = TRUE; 00851 00852 } else { 00853 00854 DbgPrint(" Unknown Ace Type\n"); 00855 KnownType = FALSE; 00856 } 00857 00858 DbgPrint("\n"); 00859 00860 DbgPrint(" AceSize = %d\n",Ace->Header.AceSize); 00861 00862 DbgPrint(" Ace Flags = "); 00863 if (Ace->Header.AceFlags & OBJECT_INHERIT_ACE) { 00864 DbgPrint("OBJECT_INHERIT_ACE\n"); 00865 DbgPrint(" "); 00866 } 00867 00868 if (Ace->Header.AceFlags & CONTAINER_INHERIT_ACE) { 00869 DbgPrint("CONTAINER_INHERIT_ACE\n"); 00870 DbgPrint(" "); 00871 } 00872 00873 if (Ace->Header.AceFlags & NO_PROPAGATE_INHERIT_ACE) { 00874 DbgPrint("NO_PROPAGATE_INHERIT_ACE\n"); 00875 DbgPrint(" "); 00876 } 00877 00878 if (Ace->Header.AceFlags & INHERIT_ONLY_ACE) { 00879 DbgPrint("INHERIT_ONLY_ACE\n"); 00880 DbgPrint(" "); 00881 } 00882 00883 00884 if (Ace->Header.AceFlags & SUCCESSFUL_ACCESS_ACE_FLAG) { 00885 DbgPrint("SUCCESSFUL_ACCESS_ACE_FLAG\n"); 00886 DbgPrint(" "); 00887 } 00888 00889 if (Ace->Header.AceFlags & FAILED_ACCESS_ACE_FLAG) { 00890 DbgPrint("FAILED_ACCESS_ACE_FLAG\n"); 00891 DbgPrint(" "); 00892 } 00893 00894 DbgPrint("\n"); 00895 00896 if (KnownType != TRUE) { 00897 continue; 00898 } 00899 00900 if (Ace->Header.AceType != ACCESS_ALLOWED_COMPOUND_ACE_TYPE) { 00901 DbgPrint(" Sid = "); 00902 SepPrintSid(&Ace->SidStart); 00903 } else { 00904 DbgPrint(" Server Sid = "); 00905 SepPrintSid(RtlCompoundAceServerSid(Ace)); 00906 DbgPrint("\n Client Sid = "); 00907 SepPrintSid(RtlCompoundAceClientSid( Ace )); 00908 } 00909 } 00910 #endif 00911 }

VOID SepPrintSid IN PSID  Sid  ) 
 

Definition at line 916 of file seassign.c.

References Buffer, DbgPrint, NULL, PAGED_CODE, SepSidTranslation(), and USHORT.

Referenced by SepDumpSecurityDescriptor(), SepDumpTokenInfo(), and SepPrintAcl().

00922 : 00923 00924 Prints a formatted Sid 00925 00926 Arguments: 00927 00928 Sid - Provides a pointer to the sid to be printed. 00929 00930 00931 Return Value: 00932 00933 None. 00934 00935 --*/ 00936 00937 { 00938 #if DBG 00939 UCHAR i; 00940 ULONG Tmp; 00941 PISID ISid; 00942 STRING AccountName; 00943 UCHAR Buffer[128]; 00944 00945 PAGED_CODE(); 00946 00947 if (Sid == NULL) { 00948 DbgPrint("Sid is NULL\n"); 00949 return; 00950 } 00951 00952 Buffer[0] = 0; 00953 00954 AccountName.MaximumLength = 127; 00955 AccountName.Length = 0; 00956 AccountName.Buffer = (PVOID)&Buffer[0]; 00957 00958 if (SepSidTranslation( Sid, &AccountName )) { 00959 00960 DbgPrint("%s ", AccountName.Buffer ); 00961 } 00962 00963 ISid = (PISID)Sid; 00964 00965 DbgPrint("S-%lu-", (USHORT)ISid->Revision ); 00966 if ( (ISid->IdentifierAuthority.Value[0] != 0) || 00967 (ISid->IdentifierAuthority.Value[1] != 0) ){ 00968 DbgPrint("0x%02hx%02hx%02hx%02hx%02hx%02hx", 00969 (USHORT)ISid->IdentifierAuthority.Value[0], 00970 (USHORT)ISid->IdentifierAuthority.Value[1], 00971 (USHORT)ISid->IdentifierAuthority.Value[2], 00972 (USHORT)ISid->IdentifierAuthority.Value[3], 00973 (USHORT)ISid->IdentifierAuthority.Value[4], 00974 (USHORT)ISid->IdentifierAuthority.Value[5] ); 00975 } else { 00976 Tmp = (ULONG)ISid->IdentifierAuthority.Value[5] + 00977 (ULONG)(ISid->IdentifierAuthority.Value[4] << 8) + 00978 (ULONG)(ISid->IdentifierAuthority.Value[3] << 16) + 00979 (ULONG)(ISid->IdentifierAuthority.Value[2] << 24); 00980 DbgPrint("%lu", Tmp); 00981 } 00982 00983 00984 for (i=0;i<ISid->SubAuthorityCount ;i++ ) { 00985 DbgPrint("-%lu", ISid->SubAuthority[i]); 00986 } 00987 DbgPrint("\n"); 00988 #endif 00989 }

NTSTATUS SepProbeAndCaptureQosData IN PSECURITY_ADVANCED_QUALITY_OF_SERVICE  CapturedSecurityQos  ) 
 

Definition at line 773 of file se/capture.c.

References ExAllocatePool, ExFreePool(), NT_SUCCESS, NTSTATUS(), NULL, PAGED_CODE, PagedPool, ProbeForRead, SepCopyProxyData(), SepFreeProxyData(), and Status.

Referenced by SeCaptureSecurityQos().

00779 : 00780 00781 This routine probes and captures the imbedded structures in a 00782 Security Quality of Service structure. 00783 00784 This routine assumes that it is being called under an existing 00785 try-except clause. 00786 00787 Arguments: 00788 00789 CapturedSecurityQos - Points to the captured body of a QOS 00790 structure. The pointers in this structure are presumed 00791 not to be probed or captured at this point. 00792 00793 Return Value: 00794 00795 STATUS_SUCCESS indicates no exceptions were encountered. 00796 00797 Any access violations encountered will be returned. 00798 00799 --*/ 00800 { 00801 NTSTATUS Status; 00802 PSECURITY_TOKEN_PROXY_DATA CapturedProxyData; 00803 PSECURITY_TOKEN_AUDIT_DATA CapturedAuditData; 00804 SECURITY_TOKEN_PROXY_DATA StackProxyData; 00805 PAGED_CODE(); 00806 00807 CapturedProxyData = CapturedSecurityQos->ProxyData; 00808 CapturedSecurityQos->ProxyData = NULL; 00809 CapturedAuditData = CapturedSecurityQos->AuditData; 00810 CapturedSecurityQos->AuditData = NULL; 00811 00812 if (ARGUMENT_PRESENT( CapturedProxyData )) { 00813 00814 // 00815 // Make sure the body of the proxy data is ok to read. 00816 // 00817 00818 ProbeForRead( 00819 CapturedProxyData, 00820 sizeof(SECURITY_TOKEN_PROXY_DATA), 00821 sizeof(ULONG) 00822 ); 00823 00824 StackProxyData = *CapturedProxyData; 00825 00826 if (StackProxyData.Length != sizeof( SECURITY_TOKEN_PROXY_DATA )) { 00827 return( STATUS_INVALID_PARAMETER ); 00828 } 00829 00830 00831 // 00832 // Probe the passed pathinfo buffer 00833 // 00834 00835 ProbeForRead( 00836 StackProxyData.PathInfo.Buffer, 00837 StackProxyData.PathInfo.Length, 00838 sizeof( UCHAR ) 00839 ); 00840 00841 Status = SepCopyProxyData( &CapturedSecurityQos->ProxyData, &StackProxyData ); 00842 00843 if (!NT_SUCCESS(Status)) { 00844 00845 if (CapturedSecurityQos->ProxyData != NULL) { 00846 SepFreeProxyData( CapturedSecurityQos->ProxyData ); 00847 CapturedSecurityQos->ProxyData = NULL; 00848 } 00849 00850 return( Status ); 00851 } 00852 00853 } 00854 00855 if (ARGUMENT_PRESENT( CapturedAuditData )) { 00856 00857 PSECURITY_TOKEN_AUDIT_DATA LocalAuditData; 00858 00859 // 00860 // Probe the audit data structure and make sure it looks ok 00861 // 00862 00863 ProbeForRead( 00864 CapturedAuditData, 00865 sizeof( SECURITY_TOKEN_AUDIT_DATA ), 00866 sizeof( ULONG ) 00867 ); 00868 00869 00870 LocalAuditData = ExAllocatePool( PagedPool, sizeof( SECURITY_TOKEN_AUDIT_DATA )); 00871 00872 if (LocalAuditData == NULL) { 00873 00874 // 00875 // Cleanup any proxy data we may have allocated. 00876 // 00877 00878 SepFreeProxyData( CapturedSecurityQos->ProxyData ); 00879 CapturedSecurityQos->ProxyData = NULL; 00880 00881 return( STATUS_INSUFFICIENT_RESOURCES ); 00882 00883 } 00884 00885 // 00886 // Copy the data to the local buffer. Note: we do this in this 00887 // order so that if the final assignment fails the caller will 00888 // still be able to free the allocated pool. 00889 // 00890 00891 CapturedSecurityQos->AuditData = LocalAuditData; 00892 00893 *CapturedSecurityQos->AuditData = *CapturedAuditData; 00894 00895 if ( LocalAuditData->Length != sizeof( SECURITY_TOKEN_AUDIT_DATA ) ) { 00896 SepFreeProxyData( CapturedSecurityQos->ProxyData ); 00897 CapturedSecurityQos->ProxyData = NULL; 00898 ExFreePool(CapturedSecurityQos->AuditData); 00899 CapturedSecurityQos->AuditData = NULL; 00900 return( STATUS_INVALID_PARAMETER ); 00901 } 00902 } 00903 00904 return( STATUS_SUCCESS ); 00905 00906 }

POBJECT_NAME_INFORMATION SepQueryNameString IN PVOID  Object  ) 
 

*++

Definition at line 2324 of file sepaudit.c.

References ExAllocatePoolWithTag, ExFreePool(), NT_SUCCESS, NTSTATUS(), NULL, ObQueryNameString(), PAGED_CODE, PagedPool, and Status.

Referenced by SeCreateObjectAuditAlarm(), SeOpenObjectAuditAlarm(), SeOpenObjectForDeleteAuditAlarm(), and SepAdtObjectReferenceAuditAlarm().

02330 : 02331 02332 Takes a pointer to an object and returns the name of the object. 02333 02334 Arguments: 02335 02336 Object - a pointer to an object. 02337 02338 02339 Return Value: 02340 02341 A pointer to a buffer containing a POBJECT_NAME_INFORMATION 02342 structure containing the name of the object. The string is 02343 allocated out of paged pool and should be freed by the caller. 02344 02345 NULL may also be returned. 02346 02347 02348 --*/ 02349 02350 { 02351 NTSTATUS Status; 02352 ULONG ReturnLength = 0; 02353 POBJECT_NAME_INFORMATION ObjectNameInfo = NULL; 02354 PUNICODE_STRING ObjectName = NULL; 02355 02356 PAGED_CODE(); 02357 02358 Status = ObQueryNameString( 02359 Object, 02360 ObjectNameInfo, 02361 0, 02362 &ReturnLength 02363 ); 02364 02365 if ( Status == STATUS_INFO_LENGTH_MISMATCH ) { 02366 02367 ObjectNameInfo = ExAllocatePoolWithTag( PagedPool, ReturnLength, 'nOeS' ); 02368 02369 if ( ObjectNameInfo != NULL ) { 02370 02371 Status = ObQueryNameString( 02372 Object, 02373 ObjectNameInfo, 02374 ReturnLength, 02375 &ReturnLength 02376 ); 02377 02378 if ( NT_SUCCESS( Status )) { 02379 02380 if (ObjectNameInfo->Name.Length != 0) { 02381 02382 return( ObjectNameInfo ); 02383 02384 } else { 02385 02386 ExFreePool( ObjectNameInfo ); 02387 return( NULL ); 02388 } 02389 } 02390 } 02391 } 02392 02393 return( NULL ); 02394 }

PUNICODE_STRING SepQueryTypeString IN PVOID  Object  ) 
 

Definition at line 2400 of file sepaudit.c.

References ExAllocatePoolWithTag, NT_SUCCESS, NTSTATUS(), NULL, ObQueryTypeName(), PAGED_CODE, PagedPool, and Status.

Referenced by SeOpenObjectAuditAlarm(), SeOpenObjectForDeleteAuditAlarm(), and SepAdtObjectReferenceAuditAlarm().

02405 : 02406 02407 Takes a pointer to an object and returns the type of the object. 02408 02409 Arguments: 02410 02411 Object - a pointer to an object. 02412 02413 02414 Return Value: 02415 02416 A pointer to a UNICODE_STRING that contains the name of the object 02417 type. The string is allocated out of paged pool and should be freed 02418 by the caller. 02419 02420 NULL may also be returned. 02421 02422 02423 --*/ 02424 02425 { 02426 02427 NTSTATUS Status; 02428 PUNICODE_STRING TypeName = NULL; 02429 ULONG ReturnLength; 02430 02431 PAGED_CODE(); 02432 02433 Status = ObQueryTypeName( 02434 Object, 02435 TypeName, 02436 0, 02437 &ReturnLength 02438 ); 02439 02440 if ( Status == STATUS_INFO_LENGTH_MISMATCH ) { 02441 02442 TypeName = ExAllocatePoolWithTag( PagedPool, ReturnLength, 'nTeS' ); 02443 02444 if ( TypeName != NULL ) { 02445 02446 Status = ObQueryTypeName( 02447 Object, 02448 TypeName, 02449 ReturnLength, 02450 &ReturnLength 02451 ); 02452 02453 if ( NT_SUCCESS( Status )) { 02454 02455 return( TypeName ); 02456 } 02457 } 02458 } 02459 02460 return( NULL ); 02461 }

BOOLEAN SepQueueWorkItem IN PSEP_LSA_WORK_ITEM  LsaWorkItem,
IN BOOLEAN  ForceQueue
 

Definition at line 600 of file adtlog.c.

References DbgPrint, DelayedWorkQueue, ExInitializeWorkItem, ExQueueWorkItem(), FALSE, PAGED_CODE, PWORKER_THREAD_ROUTINE, SepAdtCountEventsDiscarded, SepAdtCurrentListLength, SepAdtDiscardingAudits, SepAdtGenerateDiscardAudit(), SepAdtMaxListLength, SepAdtMinListLength, SepExWorkItem, SepLockLsaQueue, SepLsaQueue, SepRmCallLsa(), SepUnlockLsaQueue, TRUE, and _SEP_WORK_ITEM::WorkItem.

Referenced by SepAdtLogAuditRecord(), and SepInformLsaOfDeletedLogon().

00607 : 00608 00609 Puts the passed work item on the queue to be passed to LSA, 00610 and returns the state of the queue upon arrival. 00611 00612 Arguments: 00613 00614 LsaWorkItem - Pointer to the work item to be queued. 00615 00616 ForceQueue - Indicate that this item is not to be discarded 00617 due because of a full queue. 00618 00619 Return Value: 00620 00621 TRUE - The item was successfully queued. 00622 00623 FALSE - The item was not queued and must be discarded. 00624 00625 --*/ 00626 00627 { 00628 BOOLEAN rc = TRUE; 00629 BOOLEAN StartExThread = FALSE ; 00630 00631 PAGED_CODE(); 00632 00633 #if 0 00634 00635 DbgPrint("Queueing an audit\n"); 00636 00637 #endif 00638 00639 SepLockLsaQueue(); 00640 00641 if (SepAdtDiscardingAudits && !ForceQueue) { 00642 00643 if (SepAdtCurrentListLength < SepAdtMinListLength) { 00644 00645 // 00646 // We need to generate an audit saying how many audits we've 00647 // discarded. 00648 // 00649 // Since we have the mutex protecting the Audit queue, we don't 00650 // have to worry about anyone coming along and logging an 00651 // audit. But *we* can, since a mutex may be acquired recursively. 00652 // 00653 // Since we are so protected, turn off the SepAdtDiscardingAudits 00654 // flag here so that we don't come through this path again. 00655 // 00656 00657 SepAdtDiscardingAudits = FALSE; 00658 00659 SepAdtGenerateDiscardAudit(); 00660 #if 0 00661 DbgPrint("Auditing resumed\n"); 00662 #endif 00663 00664 // 00665 // We must assume that that worked, so clear the discard count. 00666 // 00667 00668 SepAdtCountEventsDiscarded = 0; 00669 00670 // 00671 // Our 'audits discarded' audit is now on the queue, 00672 // continue logging the one we started with. 00673 // 00674 00675 } else { 00676 00677 // 00678 // We are not yet below our low water mark. Toss 00679 // this audit and increment the discard count. 00680 // 00681 00682 SepAdtCountEventsDiscarded++; 00683 rc = FALSE; 00684 goto Exit; 00685 } 00686 } 00687 00688 if (SepAdtCurrentListLength < SepAdtMaxListLength || ForceQueue) { 00689 00690 InsertTailList(&SepLsaQueue, &LsaWorkItem->List); 00691 00692 if (++SepAdtCurrentListLength == 1) { 00693 00694 #if 0 00695 DbgPrint("Queueing a work item\n"); 00696 #endif 00697 00698 StartExThread = TRUE ; 00699 } 00700 00701 } else { 00702 00703 // 00704 // There is no room for this audit on the queue, 00705 // so change our state to 'discarding' and tell 00706 // the caller to toss this audit. 00707 // 00708 00709 SepAdtDiscardingAudits = TRUE; 00710 00711 #if 0 00712 DbgPrint("Starting to discard audits\n"); 00713 #endif 00714 00715 rc = FALSE; 00716 } 00717 00718 Exit: 00719 00720 SepUnlockLsaQueue(); 00721 00722 if ( StartExThread ) 00723 { 00724 ExInitializeWorkItem( &SepExWorkItem.WorkItem, 00725 (PWORKER_THREAD_ROUTINE) SepRmCallLsa, 00726 &SepExWorkItem 00727 ); 00728 00729 ExQueueWorkItem( &SepExWorkItem.WorkItem, DelayedWorkQueue ); 00730 } 00731 00732 return( rc ); 00733 }

NTSTATUS SepReferenceLogonSession IN PLUID  LogonId  ) 
 

Definition at line 278 of file rmlogon.c.

References DbgPrint, _SEP_LOGON_SESSION_REFERENCES::LogonId, _SEP_LOGON_SESSION_REFERENCES::Next, NULL, PAGED_CODE, PSEP_LOGON_SESSION_REFERENCES, PsGetCurrentThread, _SEP_LOGON_SESSION_REFERENCES::ReferenceCount, RtlEqualLuid(), SepLogonSessionIndex, SepLogonSessions, SepRmAcquireDbWriteLock, and SepRmReleaseDbWriteLock.

Referenced by SepCreateToken(), SepDuplicateToken(), and SepFilterToken().

00284 : 00285 00286 This routine increments the reference count of a logon session 00287 tracking record. 00288 00289 00290 00291 Arguments: 00292 00293 LogonId - Pointer to the logon session ID whose logon track is 00294 to be incremented. 00295 00296 Return Value: 00297 00298 STATUS_SUCCESS - The reference count was successfully incremented. 00299 00300 STATUS_NO_SUCH_LOGON_SESSION - The specified logon session doesn't 00301 exist in the reference monitor's database. 00302 00303 --*/ 00304 00305 { 00306 00307 ULONG SessionArrayIndex; 00308 PSEP_LOGON_SESSION_REFERENCES Previous, Current; 00309 00310 #ifdef SEP_TRACK_LOGON_SESSION_REFS 00311 ULONG Refs; 00312 #endif //SEP_TRACK_LOGON_SESSION_REFS 00313 00314 PAGED_CODE(); 00315 00316 SessionArrayIndex = SepLogonSessionIndex( LogonId ); 00317 00318 // 00319 // Protect modification of reference monitor database 00320 // 00321 00322 SepRmAcquireDbWriteLock(); 00323 00324 00325 // 00326 // Now walk the list for our logon session array hash index. 00327 // 00328 00329 Previous = (PSEP_LOGON_SESSION_REFERENCES) 00330 ((PVOID)&SepLogonSessions[ SessionArrayIndex ]); 00331 Current = Previous->Next; 00332 00333 while (Current != NULL) { 00334 00335 // 00336 // If we found it, increment the reference count and return 00337 // 00338 00339 if (RtlEqualLuid( LogonId, &Current->LogonId) ) { 00340 #ifdef SEP_TRACK_LOGON_SESSION_REFS 00341 ULONG Refs; 00342 #endif //SEP_TRACK_LOGON_SESSION_REFS 00343 00344 Current->ReferenceCount += 1; 00345 00346 #ifdef SEP_TRACK_LOGON_SESSION_REFS 00347 Refs = Current->ReferenceCount; 00348 #endif //SEP_TRACK_LOGON_SESSION_REFS 00349 00350 SepRmReleaseDbWriteLock(); 00351 00352 #ifdef SEP_TRACK_LOGON_SESSION_REFS 00353 DbgPrint("SE (rm): ++ logon session: (%d, %d) to %d by (%d, %d)\n", 00354 LogonId->HighPart, LogonId->LowPart, Refs, 00355 PsGetCurrentThread()->Cid.UniqueProcess, 00356 PsGetCurrentThread()->Cid.UniqueThread); 00357 00358 #endif //SEP_TRACK_LOGON_SESSION_REFS 00359 return STATUS_SUCCESS; 00360 } 00361 00362 Previous = Current; 00363 Current = Current->Next; 00364 } 00365 00366 SepRmReleaseDbWriteLock(); 00367 00368 // 00369 // Bad news, someone asked us to increment the reference count of 00370 // a logon session we didn't know existed. This might be a new 00371 // token being created, so return an error status and let the caller 00372 // decide if it warrants a bug check or not. 00373 // 00374 00375 00376 return STATUS_NO_SUCH_LOGON_SESSION; 00377 00378 00379 00380 }

NTSTATUS SepRmCallLsa PSEP_WORK_ITEM  SepWorkItem  ) 
 

Definition at line 907 of file rmmain.c.

References ASSERT, _SEP_LSA_WORK_ITEM::CleanupFunction, _SEP_LSA_WORK_ITEM::CleanupParameter, _SEP_LSA_WORK_ITEM::CommandNumber, _SEP_LSA_WORK_ITEM::CommandParams, _SEP_LSA_WORK_ITEM::CommandParamsLength, _SEP_LSA_WORK_ITEM::CommandParamsMemoryType, DbgPrint, ExFreePool(), KeAttachProcess(), KeDetachProcess(), _SEP_RM_STATE::LsaCommandPortHandle, _SEP_RM_STATE::LsaViewPortMemory, NT_SUCCESS, NTSTATUS(), NULL, PAGED_CODE, _EPROCESS::Pcb, PSEP_WORK_ITEM, _SEP_LSA_WORK_ITEM::ReplyBuffer, _SEP_LSA_WORK_ITEM::ReplyBufferLength, ReplyMessage(), _SEP_RM_STATE::RmViewPortMemory, SEP_RM_LSA_SHARED_MEMORY_SIZE, SepAdtCopyToLsaSharedMemory(), SepDequeueWorkItem(), SepLsaHandle, SepLsaQueueLength, SepRmLsaCallProcess, SepRmState, SepWorkListHead, and Status.

Referenced by SepQueueWorkItem().

00912 : 00913 00914 This function sends a command to the LSA via the LSA Reference Monitor 00915 Server Command LPC Port. If the command has parameters, they will be 00916 copied directly into a message structure and sent via LPC, therefore, 00917 the supplied parameters may not contain any absolute pointers. A caller 00918 must remove pointers by "marshalling" them into the buffer CommandParams. 00919 00920 This function will create a queue of requests. This is in order to allow 00921 greater throughput for the majority if its callers. If a thread enters 00922 this routine and finds the queue empty, it is the responsibility of that 00923 thread to service all requests that come in while it is working until the 00924 queue is empty again. Other threads that enter will simply hook their work 00925 item onto the queue and exit. 00926 00927 00928 To implement a new LSA command, do the following: 00929 ================================================ 00930 00931 (1) If the command takes no parameters, just call this routine directly 00932 and provide an LSA worker routine called Lsap<command>Wrkr. See 00933 file lsa\server\lsarm.c for examples 00934 00935 (2) If the command takes parameters, provide a routine called 00936 SepRmSend<command>Command that takes the parameters in unmarshalled 00937 form and calls SepRmCallLsa() with the command id, marshalled 00938 parameters, length of marshalled parameters and pointer to 00939 optional reply message. The marshalled parameters are free format: 00940 the only restriction is that there must be no absolute address 00941 pointers. These parameters are all placed in the passed LsaWorkItem 00942 structure. 00943 00944 (3) In file private\inc\ntrmlsa.h, append a command name to the 00945 enumerated type LSA_COMMAND_NUMBER defined in file 00946 private\inc\ntrmlsa.h. Change the #define for LsapMaximumCommand 00947 to reference the new command. 00948 00949 (4) Add the Lsap<command>Wrkr to the command dispatch table structure 00950 LsapCommandDispatch[] in file lsarm.c. 00951 00952 (5) Add function prototypes to lsap.h and sep.h. 00953 00954 00955 Arguments: 00956 00957 LsaWorkItem - Supplies a pointer to an SE_LSA_WORK_ITEM containing the 00958 information to be passed to LSA. This structure will be freed 00959 asynchronously by some invocation of this routine, not necessarily 00960 in the current context. 00961 00962 !THIS PARAMETER MUST BE ALLOCATED OUT OF NONPAGED POOL! 00963 00964 Return Value: 00965 00966 NTSTATUS - Result Code. This is either a result code returned from 00967 trying to send the command/receive the reply, or a status code 00968 from the command itself. 00969 00970 --*/ 00971 00972 { 00973 NTSTATUS Status = STATUS_SUCCESS; 00974 LSA_COMMAND_MESSAGE CommandMessage; 00975 LSA_REPLY_MESSAGE ReplyMessage; 00976 PSEP_LSA_WORK_ITEM WorkQueueItem; 00977 ULONG LocalListLength = 0; 00978 SIZE_T RegionSize; 00979 PVOID CopiedCommandParams = NULL; 00980 PVOID LsaViewCopiedCommandParams = NULL; 00981 00982 PAGED_CODE(); 00983 00984 #if 0 00985 DbgPrint("Entering SepRmCallLsa\n"); 00986 #endif 00987 00988 WorkQueueItem = SepWorkListHead(); 00989 00990 KeAttachProcess( &SepRmLsaCallProcess->Pcb ); 00991 00992 while ( WorkQueueItem ) { 00993 00994 #if 0 00995 DbgPrint("Got a work item from head of queue, processing\n"); 00996 #endif 00997 00998 // 00999 // Construct a message for LPC. First, fill in the message header 01000 // fields for LPC, specifying the message type and data sizes for 01001 // the outgoing CommandMessage and the incoming ReplyMessage. 01002 // 01003 01004 CommandMessage.MessageHeader.u2.ZeroInit = 0; 01005 CommandMessage.MessageHeader.u1.s1.TotalLength = 01006 ((CSHORT) RM_COMMAND_MESSAGE_HEADER_SIZE + 01007 (CSHORT) WorkQueueItem->CommandParamsLength); 01008 CommandMessage.MessageHeader.u1.s1.DataLength = 01009 CommandMessage.MessageHeader.u1.s1.TotalLength - 01010 (CSHORT) sizeof(PORT_MESSAGE); 01011 01012 ReplyMessage.MessageHeader.u2.ZeroInit = 0; 01013 ReplyMessage.MessageHeader.u1.s1.DataLength = (CSHORT) WorkQueueItem->ReplyBufferLength; 01014 ReplyMessage.MessageHeader.u1.s1.TotalLength = 01015 ReplyMessage.MessageHeader.u1.s1.DataLength + 01016 (CSHORT) sizeof(PORT_MESSAGE); 01017 01018 // 01019 // Next, fill in the header info needed by the LSA. 01020 // 01021 01022 CommandMessage.CommandNumber = WorkQueueItem->CommandNumber; 01023 ReplyMessage.ReturnedStatus = STATUS_SUCCESS; 01024 01025 // 01026 // Set up the Command Parameters either in the LPC Command Message 01027 // itself, in the preallocated Lsa shared memory block, or in a 01028 // specially allocated block. The parameters are either 01029 // immediate (i.e. in the WorkQueueItem itself, or are in a buffer 01030 // pointed to by the address in the WorkQueueItem. 01031 // 01032 01033 switch (WorkQueueItem->CommandParamsMemoryType) { 01034 01035 case SepRmImmediateMemory: 01036 01037 // 01038 // The Command Parameters are in the CommandParams buffer 01039 // in the Work Queue Item. Just copy them to the corresponding 01040 // buffer in the CommandMessage buffer. 01041 // 01042 01043 CommandMessage.CommandParamsMemoryType = SepRmImmediateMemory; 01044 01045 RtlCopyMemory( 01046 CommandMessage.CommandParams, 01047 &WorkQueueItem->CommandParams, 01048 WorkQueueItem->CommandParamsLength 01049 ); 01050 01051 break; 01052 01053 case SepRmPagedPoolMemory: 01054 case SepRmUnspecifiedMemory: 01055 01056 // 01057 // The Command Parameters are contained in paged pool memory. 01058 // Since this memory is is not accessible by the LSA, we must 01059 // copy of them either to the LPC Command Message Block, or 01060 // into LSA shared memory. 01061 // 01062 01063 if (WorkQueueItem->CommandParamsLength <= LSA_MAXIMUM_COMMAND_PARAM_SIZE) { 01064 01065 // 01066 // Parameters will fit into the LPC Command Message block. 01067 // 01068 01069 CopiedCommandParams = CommandMessage.CommandParams; 01070 01071 RtlCopyMemory( 01072 CopiedCommandParams, 01073 WorkQueueItem->CommandParams.BaseAddress, 01074 WorkQueueItem->CommandParamsLength 01075 ); 01076 01077 CommandMessage.CommandParamsMemoryType = SepRmImmediateMemory; 01078 01079 } else { 01080 01081 // 01082 // Parameters too large for LPC Command Message block. 01083 // If possible, copy them to the preallocated Lsa Shared 01084 // Memory block. If they are too large to fit, copy them 01085 // to an individually allocated chunk of Shared Virtual 01086 // Memory. 01087 // 01088 01089 if (WorkQueueItem->CommandParamsLength <= SEP_RM_LSA_SHARED_MEMORY_SIZE) { 01090 01091 RtlCopyMemory( 01092 SepRmState.RmViewPortMemory, 01093 WorkQueueItem->CommandParams.BaseAddress, 01094 WorkQueueItem->CommandParamsLength 01095 ); 01096 01097 LsaViewCopiedCommandParams = SepRmState.LsaViewPortMemory; 01098 CommandMessage.CommandParamsMemoryType = SepRmLsaCommandPortSharedMemory; 01099 01100 } else { 01101 01102 Status = SepAdtCopyToLsaSharedMemory( 01103 SepLsaHandle, 01104 WorkQueueItem->CommandParams.BaseAddress, 01105 WorkQueueItem->CommandParamsLength, 01106 &LsaViewCopiedCommandParams 01107 ); 01108 01109 if (!NT_SUCCESS(Status)) { 01110 01111 // 01112 // An error occurred, most likely in allocating 01113 // shared virtual memory. For now, just ignore 01114 // the error and discard the Audit Record. Later, 01115 // we may consider generating a warning record 01116 // indicating some records lost. 01117 // 01118 01119 break; 01120 01121 } 01122 01123 CommandMessage.CommandParamsMemoryType = SepRmLsaCustomSharedMemory; 01124 } 01125 01126 // 01127 // Buffer has been successfully copied to a shared Lsa 01128 // memory buffer. Place the address of the buffer valid in 01129 // the LSA's process context in the Command Message. 01130 // 01131 01132 *((PVOID *) CommandMessage.CommandParams) = 01133 LsaViewCopiedCommandParams; 01134 01135 CommandMessage.MessageHeader.u1.s1.TotalLength = 01136 ((CSHORT) RM_COMMAND_MESSAGE_HEADER_SIZE + 01137 (CSHORT) sizeof( LsaViewCopiedCommandParams )); 01138 CommandMessage.MessageHeader.u1.s1.DataLength = 01139 CommandMessage.MessageHeader.u1.s1.TotalLength - 01140 (CSHORT) sizeof(PORT_MESSAGE); 01141 } 01142 01143 // 01144 // Free input command params buffer if Paged Pool. 01145 // 01146 01147 if (WorkQueueItem->CommandParamsMemoryType == SepRmPagedPoolMemory) { 01148 01149 ExFreePool( WorkQueueItem->CommandParams.BaseAddress ); 01150 } 01151 01152 break; 01153 01154 default: 01155 01156 Status = STATUS_INVALID_PARAMETER; 01157 break; 01158 } 01159 01160 if (NT_SUCCESS(Status)) { 01161 01162 // 01163 // Send Message to the LSA via the LSA Server Command LPC Port. 01164 // This must be done in the process in which the handle was created. 01165 // 01166 01167 Status = ZwRequestWaitReplyPort( 01168 SepRmState.LsaCommandPortHandle, 01169 (PPORT_MESSAGE) &CommandMessage, 01170 (PPORT_MESSAGE) &ReplyMessage 01171 ); 01172 01173 // 01174 // If the command was successful, copy the data back to the output 01175 // buffer. 01176 // 01177 01178 if (NT_SUCCESS(Status)) { 01179 01180 // 01181 // Move output from command (if any) to buffer. Note that this 01182 // is done even if the command returns status, because some status 01183 // values are not errors. 01184 // 01185 01186 if (ARGUMENT_PRESENT(WorkQueueItem->ReplyBuffer)) { 01187 01188 RtlCopyMemory( 01189 WorkQueueItem->ReplyBuffer, 01190 ReplyMessage.ReplyBuffer, 01191 WorkQueueItem->ReplyBufferLength 01192 ); 01193 } 01194 01195 // 01196 // Return status from command. 01197 // 01198 01199 Status = ReplyMessage.ReturnedStatus; 01200 01201 if (!NT_SUCCESS(Status)) { 01202 KdPrint(("Security: Command sent from RM to LSA returned 0x%lx\n", 01203 Status)); 01204 } 01205 01206 } else { 01207 01208 KdPrint(("Security: Sending Command RM to LSA failed 0x%lx\n", Status)); 01209 } 01210 01211 // 01212 // On return from the LPC call to the LSA, we expect the called 01213 // LSA worker routine to have copied the Command Parameters 01214 // buffer (if any). If a custom shared memory boffer was allocated, 01215 // free it now. 01216 // 01217 01218 if (CommandMessage.CommandParamsMemoryType == SepRmLsaCustomSharedMemory) { 01219 01220 RegionSize = 0; 01221 01222 Status = ZwFreeVirtualMemory( 01223 SepLsaHandle, 01224 (PVOID *) &CommandMessage.CommandParams, 01225 &RegionSize, 01226 MEM_RELEASE 01227 ); 01228 01229 ASSERT(NT_SUCCESS(Status)); 01230 } 01231 01232 } 01233 01234 01235 // 01236 // Clean up. We must call the cleanup functions on its parameter 01237 // and then free the used WorkQueueItem itself. 01238 // 01239 01240 if ( ARGUMENT_PRESENT( WorkQueueItem->CleanupFunction)) { 01241 01242 (WorkQueueItem->CleanupFunction)(WorkQueueItem->CleanupParameter); 01243 } 01244 01245 // 01246 // Determine if there is more work to do on this list 01247 // 01248 01249 WorkQueueItem = SepDequeueWorkItem(); 01250 #if 0 01251 if ( WorkQueueItem ) { 01252 DbgPrint("Got another item from list, going back\n"); 01253 } else { 01254 DbgPrint("List is empty, leaving\n"); 01255 } 01256 #endif 01257 01258 01259 } 01260 01261 KeDetachProcess(); 01262 01263 if ( LocalListLength > SepLsaQueueLength ) { 01264 SepLsaQueueLength = LocalListLength; 01265 } 01266 01267 return Status; 01268 }

BOOLEAN SepRmInitPhase0  ) 
 

Definition at line 1275 of file rmmain.c.

References PAGED_CODE, and SepRmDbInitialization().

Referenced by SepInitializationPhase0().

01280 : 01281 01282 This function performs Reference Monitor Phase 0 initialization. 01283 This includes initializing the reference monitor database to a state 01284 which allows access validation routines to operate (always granting 01285 access) prior to the main init of the Reference Monitor in Phase 1 01286 initialization, without having to check if the RM is initialized. 01287 01288 01289 Arguments: 01290 01291 None. 01292 01293 Return Value: 01294 01295 BOOLEAN - TRUE if successful, else FALSE 01296 01297 --*/ 01298 01299 { 01300 01301 BOOLEAN CompletionStatus; 01302 01303 PAGED_CODE(); 01304 01305 CompletionStatus = SepRmDbInitialization(); 01306 01307 return CompletionStatus; 01308 } }

BOOLEAN SepSidInToken IN PACCESS_TOKEN  Token,
IN PSID  PrincipalSelfSid,
IN PSID  Sid,
IN BOOLEAN  DenyAce
 

Definition at line 733 of file accessck.c.

References FALSE, NULL, PAGED_CODE, PTOKEN, RtlEqualSid(), SepDumpTokenInfo(), SePrincipalSelfSid, Token, and TRUE.

Referenced by SepAccessCheck(), SepExamineSacl(), SepExamineSaclEx(), and SepTokenIsOwner().

00742 : 00743 00744 Checks to see if a given SID is in the given token. 00745 00746 N.B. The code to compute the length of a SID and test for equality 00747 is duplicated from the security runtime since this is such a 00748 frequently used routine. 00749 00750 Arguments: 00751 00752 Token - Pointer to the token to be examined 00753 00754 PrincipalSelfSid - If the object being access checked is an object which 00755 represents a principal (e.g., a user object), this parameter should 00756 be the SID of the object. Any ACE containing the constant 00757 PRINCIPAL_SELF_SID is replaced by this SID. 00758 00759 The parameter should be NULL if the object does not represent a principal. 00760 00761 00762 Sid - Pointer to the SID of interest 00763 00764 Return Value: 00765 00766 A value of TRUE indicates that the SID is in the token, FALSE 00767 otherwise. 00768 00769 --*/ 00770 00771 { 00772 00773 ULONG i; 00774 PISID MatchSid; 00775 ULONG SidLength; 00776 PTOKEN Token; 00777 PSID_AND_ATTRIBUTES TokenSid; 00778 ULONG UserAndGroupCount; 00779 00780 PAGED_CODE(); 00781 00782 #if DBG 00783 00784 SepDumpTokenInfo(AToken); 00785 00786 #endif 00787 00788 // 00789 // If Sid is the constant PrincipalSelfSid, 00790 // replace it with the passed in PrincipalSelfSid. 00791 // 00792 00793 if ( PrincipalSelfSid != NULL && 00794 RtlEqualSid( SePrincipalSelfSid, Sid ) ) { 00795 Sid = PrincipalSelfSid; 00796 } 00797 00798 // 00799 // Get the length of the source SID since this only needs to be computed 00800 // once. 00801 // 00802 00803 SidLength = 8 + (4 * ((PISID)Sid)->SubAuthorityCount); 00804 00805 // 00806 // Get address of user/group array and number of user/groups. 00807 // 00808 00809 Token = (PTOKEN)AToken; 00810 TokenSid = Token->UserAndGroups; 00811 UserAndGroupCount = Token->UserAndGroupCount; 00812 00813 // 00814 // Scan through the user/groups and attempt to find a match with the 00815 // specified SID. 00816 // 00817 00818 for (i = 0 ; i < UserAndGroupCount ; i += 1) { 00819 MatchSid = (PISID)TokenSid->Sid; 00820 00821 // 00822 // If the SID revision and length matches, then compare the SIDs 00823 // for equality. 00824 // 00825 00826 if ((((PISID)Sid)->Revision == MatchSid->Revision) && 00827 (SidLength == (8 + (4 * (ULONG)MatchSid->SubAuthorityCount)))) { 00828 if (RtlEqualMemory(Sid, MatchSid, SidLength)) { 00829 00830 // 00831 // If this is the first one in the list, then it is the User, 00832 // and return success immediately. 00833 // 00834 // If this is not the first one, then it represents a group, 00835 // and we must make sure the group is currently enabled before 00836 // we can say that the group is "in" the token. 00837 // 00838 00839 if ((i == 0) || (TokenSid->Attributes & SE_GROUP_ENABLED) || 00840 (DenyAce && (TokenSid->Attributes & SE_GROUP_USE_FOR_DENY_ONLY))) { 00841 return TRUE; 00842 00843 } else { 00844 return FALSE; 00845 } 00846 } 00847 } 00848 00849 TokenSid += 1; 00850 } 00851 00852 return FALSE; 00853 }

BOOLEAN SepSidTranslation PSID  Sid,
PSTRING  AccountName
 

Definition at line 1065 of file seassign.c.

References FALSE, PAGED_CODE, RtlEqualSid(), RtlInitString(), SeBatchSid, SeCreatorGroupServerSid, SeCreatorGroupSid, SeCreatorOwnerServerSid, SeCreatorOwnerSid, SeInteractiveSid, SeLocalSid, SeLocalSystemSid, SeNetworkSid, SeWorldSid, and TRUE.

Referenced by SepPrintSid().

01072 : 01073 01074 This routine translates well-known SIDs into English names. 01075 01076 Arguments: 01077 01078 Sid - Provides the sid to be examined. 01079 01080 AccountName - Provides a string buffer in which to place the 01081 translated name. 01082 01083 Return Value: 01084 01085 None 01086 01087 --*/ 01088 01089 // AccountName is expected to have a large maximum length 01090 01091 { 01092 PAGED_CODE(); 01093 01094 if (RtlEqualSid(Sid, SeWorldSid)) { 01095 RtlInitString( AccountName, "WORLD "); 01096 return(TRUE); 01097 } 01098 01099 if (RtlEqualSid(Sid, SeLocalSid)) { 01100 RtlInitString( AccountName, "LOCAL "); 01101 return(TRUE); 01102 } 01103 01104 if (RtlEqualSid(Sid, SeNetworkSid)) { 01105 RtlInitString( AccountName, "NETWORK "); 01106 return(TRUE); 01107 } 01108 01109 if (RtlEqualSid(Sid, SeBatchSid)) { 01110 RtlInitString( AccountName, "BATCH "); 01111 return(TRUE); 01112 } 01113 01114 if (RtlEqualSid(Sid, SeInteractiveSid)) { 01115 RtlInitString( AccountName, "INTERACTIVE "); 01116 return(TRUE); 01117 } 01118 01119 if (RtlEqualSid(Sid, SeLocalSystemSid)) { 01120 RtlInitString( AccountName, "SYSTEM "); 01121 return(TRUE); 01122 } 01123 01124 if (RtlEqualSid(Sid, SeCreatorOwnerSid)) { 01125 RtlInitString( AccountName, "CREATOR_OWNER "); 01126 return(TRUE); 01127 } 01128 01129 if (RtlEqualSid(Sid, SeCreatorGroupSid)) { 01130 RtlInitString( AccountName, "CREATOR_GROUP "); 01131 return(TRUE); 01132 } 01133 01134 if (RtlEqualSid(Sid, SeCreatorOwnerServerSid)) { 01135 RtlInitString( AccountName, "CREATOR_OWNER_SERVER "); 01136 return(TRUE); 01137 } 01138 01139 if (RtlEqualSid(Sid, SeCreatorGroupServerSid)) { 01140 RtlInitString( AccountName, "CREATOR_GROUP_SERVER "); 01141 return(TRUE); 01142 } 01143 01144 return(FALSE); 01145 }

BOOLEAN SepSinglePrivilegeCheck LUID  DesiredPrivilege,
IN PACCESS_TOKEN  EffectiveToken,
IN KPROCESSOR_MODE  PreviousMode
 

Definition at line 143 of file seaudit.c.

References ASSERT, PAGED_CODE, SepPrivilegeCheck(), SeTcbPrivilege, and Token.

Referenced by SepAccessCheck(), and SePrivilegePolicyCheck().

00151 : 00152 00153 Determines if the passed token has the passed privilege. 00154 00155 Arguments: 00156 00157 DesiredPrivilege - The privilege to be tested for. 00158 00159 Token - The token being examined. 00160 00161 PreviousMode - The previous processor mode. 00162 00163 Return Value: 00164 00165 Returns TRUE of the subject has the passed privilege, FALSE otherwise. 00166 00167 --*/ 00168 00169 { 00170 00171 LUID_AND_ATTRIBUTES Privilege; 00172 BOOLEAN Result; 00173 00174 PAGED_CODE(); 00175 00176 // 00177 // Don't let anyone call this to test for SeTcbPrivilege 00178 // 00179 00180 ASSERT(!((DesiredPrivilege.LowPart == SeTcbPrivilege.LowPart) && 00181 (DesiredPrivilege.HighPart == SeTcbPrivilege.HighPart))); 00182 00183 Privilege.Luid = DesiredPrivilege; 00184 Privilege.Attributes = 0; 00185 00186 Result = SepPrivilegeCheck( 00187 Token, 00188 &Privilege, 00189 1, 00190 PRIVILEGE_SET_ALL_NECESSARY, 00191 PreviousMode 00192 ); 00193 00194 return(Result); 00195 }

BOOLEAN SepTokenIsOwner IN PACCESS_TOKEN  Token,
IN PSECURITY_DESCRIPTOR  SecurityDescriptor,
IN BOOLEAN  TokenLocked
 

Definition at line 3796 of file accessck.c.

References ASSERT, EffectiveToken, FALSE, NULL, Owner, PAGED_CODE, PTOKEN, SepAcquireTokenReadLock, SepReleaseTokenReadLock, SepSidInToken(), SepSidInTokenEx(), Token, TOKEN_IS_RESTRICTED, and TRUE.

Referenced by SeAccessCheck(), SeAccessCheckByType(), and SepAccessCheckAndAuditAlarm().

03804 : 03805 03806 This routine will determine of the Owner of the passed security descriptor 03807 is in the passed token. If the token is restricted it cannot be the 03808 owner. 03809 03810 03811 Arguments: 03812 03813 Token - The token representing the current user. 03814 03815 SecurityDescriptor - The security descriptor for the object being 03816 accessed. 03817 03818 TokenLocked - A boolean describing whether the caller has taken 03819 a read lock for the token. 03820 03821 03822 Return Value: 03823 03824 TRUE - The user of the token is the owner of the object. 03825 03826 FALSE - The user of the token is not the owner of the object. 03827 03828 --*/ 03829 03830 { 03831 PSID Owner; 03832 BOOLEAN rc; 03833 03834 PISECURITY_DESCRIPTOR ISecurityDescriptor; 03835 PTOKEN Token; 03836 03837 PAGED_CODE(); 03838 03839 ISecurityDescriptor = (PISECURITY_DESCRIPTOR)SecurityDescriptor; 03840 Token = (PTOKEN)EffectiveToken; 03841 03842 if (!TokenLocked) { 03843 SepAcquireTokenReadLock( Token ); 03844 } 03845 03846 Owner = RtlpOwnerAddrSecurityDescriptor( ISecurityDescriptor ); 03847 ASSERT( Owner != NULL ); 03848 03849 rc = SepSidInToken( Token, NULL, Owner, FALSE ); 03850 03851 // 03852 // For restricted tokens, check the restricted sids too. 03853 // 03854 03855 if (rc && (Token->TokenFlags & TOKEN_IS_RESTRICTED) != 0) { 03856 rc = SepSidInTokenEx( Token, NULL, Owner, FALSE, TRUE ); 03857 03858 } 03859 03860 if (!TokenLocked) { 03861 SepReleaseTokenReadLock( Token ); 03862 } 03863 03864 return( rc ); 03865 }

BOOLEAN SepValidOwnerSubjectContext IN PSECURITY_SUBJECT_CONTEXT  SubjectContext,
IN PSID  Owner,
IN BOOLEAN  ServerObject
 

Definition at line 381 of file subject.c.

References EffectiveToken, exit, FALSE, Index, NULL, Owner, PAGED_CODE, PTOKEN, RtlEqualSid(), SepAcquireTokenReadLock, SepIdAssignableAsOwner(), SepReleaseTokenReadLock, SeRestorePrivilege, SeSinglePrivilegeCheck(), TRUE, and UserMode.

Referenced by RtlpNewSecurityObject(), and RtlpSetSecurityObject().

00388 : 00389 00390 This routine checks to see whether the provided SID is one the subject 00391 is authorized to assign as the owner of objects. It will also check to 00392 see if the caller has SeRestorePrivilege, if so, the request is granted. 00393 00394 Arguments: 00395 00396 SubjectContext - Points to the subject's security context. 00397 00398 Owner - Points to the SID to be checked. 00399 00400 00401 00402 Return Value: 00403 00404 none. 00405 00406 --*/ 00407 00408 { 00409 00410 ULONG Index; 00411 BOOLEAN Found; 00412 PTOKEN EffectiveToken; 00413 BOOLEAN Rc = FALSE; 00414 00415 PAGED_CODE(); 00416 00417 // 00418 // It is invalid to assign a NULL owner, regardless of 00419 // whether you have SeRestorePrivilege or not. 00420 // 00421 00422 if (Owner == NULL) { 00423 return( FALSE ); 00424 } 00425 00426 // 00427 // Allowable owners come from the primary if it's a server object. 00428 // 00429 00430 if (!ServerObject && ARGUMENT_PRESENT(SubjectContext->ClientToken)) { 00431 EffectiveToken = (PTOKEN)SubjectContext->ClientToken; 00432 } else { 00433 EffectiveToken = (PTOKEN)SubjectContext->PrimaryToken; 00434 } 00435 00436 00437 // 00438 // If we're impersonating, make sure we're at TokenImpersonation 00439 // or above. This prevents someone from setting the owner of an 00440 // object when impersonating at less Identify or Anonymous. 00441 // 00442 00443 if (EffectiveToken->TokenType == TokenImpersonation) { 00444 00445 if (EffectiveToken->ImpersonationLevel < SecurityImpersonation) { 00446 00447 return( FALSE ); 00448 00449 } 00450 } 00451 00452 SepAcquireTokenReadLock( EffectiveToken ); 00453 00454 // 00455 // Walk through the list of user and group IDs looking 00456 // for a match to the specified SID. If one is found, 00457 // make sure it may be assigned as an owner. 00458 // 00459 // This code is similar to that performed to set the default 00460 // owner of a token (NtSetInformationToken). 00461 // 00462 00463 Index = 0; 00464 while (Index < EffectiveToken->UserAndGroupCount) { 00465 00466 00467 Found = RtlEqualSid( 00468 Owner, 00469 EffectiveToken->UserAndGroups[Index].Sid 00470 ); 00471 00472 if ( Found ) { 00473 00474 // 00475 // We may return success if the Sid is one that may be assigned 00476 // as an owner, or if the caller has SeRestorePrivilege 00477 // 00478 00479 if ( SepIdAssignableAsOwner(EffectiveToken,Index) ) { 00480 00481 SepReleaseTokenReadLock( EffectiveToken ); 00482 Rc = TRUE; 00483 goto exit; 00484 00485 } else { 00486 00487 // 00488 // Rc is already set to FALSE, just exit. 00489 // 00490 00491 SepReleaseTokenReadLock( EffectiveToken ); 00492 goto exit; 00493 00494 } //endif assignable 00495 00496 00497 } //endif Found 00498 00499 00500 Index += 1; 00501 00502 } //endwhile 00503 00504 00505 SepReleaseTokenReadLock( EffectiveToken ); 00506 00507 exit: 00508 00509 // 00510 // If we are going to fail this call, check for Restore privilege, 00511 // and succeed if he has it. 00512 // 00513 00514 // 00515 // We should really have gotten PreviousMode from the caller, but we 00516 // didn't, so hard wire it to be user-mode here. 00517 // 00518 00519 if ( Rc == FALSE ) { 00520 Rc = SeSinglePrivilegeCheck( SeRestorePrivilege, UserMode ); 00521 } 00522 00523 return Rc; 00524 }

BOOLEAN SepVariableInitialization VOID   ) 
 


Variable Documentation

BOOLEAN SepAuditShutdownEvents
 

Definition at line 267 of file sep.h.

PSEP_LSA_WORK_ITEM SepDequeueWorkItem(VOID)
 

SEP_WORK_ITEM SepExWorkItem
 

Definition at line 376 of file sep.h.

Referenced by SepQueueWorkItem().

HANDLE SepLsaHandle
 

Definition at line 265 of file sep.h.

Referenced by SepRmCallLsa(), and SepRmCommandServerThreadInit().

LIST_ENTRY SepLsaQueue
 

Definition at line 281 of file sep.h.

Referenced by SepDequeueWorkItem(), SepInitializeWorkList(), and SepQueueWorkItem().

ULONG SepLsaQueueLength
 

Definition at line 275 of file sep.h.

Referenced by SepRmCallLsa().

ERESOURCE SepLsaQueueLock
 

Definition at line 273 of file sep.h.

Referenced by SepInitializeWorkList().


Generated on Sat May 15 19:45:35 2004 for test by doxygen 1.3.7