CmpSetKeySecurity
NTSTATUS __stdcall CmpSetKeySecurity(
CM_KEY_BODY *KeyBody,
UINT64 *SecurityInformation,
PVOID SecurityDescriptor,
POOL_TYPE PoolType,
GENERIC_MAPPING *GenericMapping){
char v6;
CHAR v7;
char v8;
CM_KCB_UOW *v9;
_CM_KEY_CONTROL_BLOCK *KeyControlBlock;
NTSTATUS started;
CM_TRANS *v12;
INT64 p_KCBLock;
CHAR v14;
char v15;
BOOL v16;
_CM_KCB_UOW *UnitOfWork;
INT64 v19;
__int64 v20;
INT64 v21;
INT64 KeyNodeForKcb;
UINT64 v23;
BOOL v24;
char v25;
char v26[20];
__int128 v27;
int v28;
VOID **v29;
INT64 v30;
CM_TRANS *CmTrans;
LIST_ENTRY DeferredPostAsync;
_GENERIC_MAPPING *v33;
int v34[2];
int v35[2];
int v36[2];
_SECURITY_SUBJECT_CONTEXT SubjectContext;
_KAPC_STATE ApcState;
_GENERIC_MAPPING *v39;
v33 = v39;
v30 = 0xFFFFFFFFi64;
*(_OWORD *)&v26[4] = 0i64;
*(_WORD *)&v26[6] = -1;
*(_QWORD *)v34 = *(_QWORD *)&PoolType;
*(_QWORD *)v35 = SecurityDescriptor;
DeferredPostAsync.Blink = &DeferredPostAsync;
v6 = 0;
*(_QWORD *)v36 = SecurityInformation;
DeferredPostAsync.Flink = &DeferredPostAsync;
v7 = 0;
*(_DWORD *)v26 = 0;
v8 = 0;
v29 = 0i64;
v9 = 0i64;
memset(&SubjectContext, 0, sizeof(SubjectContext));
CmTrans = 0i64;
v25 = 0;
memset(&ApcState, 0, sizeof(ApcState));
v28 = 0;
v27 = 0i64;
SeCaptureSubjectContext((INT64)&SubjectContext);
CmpAttachToRegistryProcess(&ApcState);
while( 1 )
{
v24 = CmpAcquireShutdownRundown();
if( !v24 )
break;
if( v6 )
CmpLockRegistryExclusive();
else
CmpLockRegistry();
KeyControlBlock = KeyBody->KeyControlBlock;
if( (KeyControlBlock->KeyHash.KeyHive->HiveFlags & 0x100000) != 0 )
{
LABEL_66:
started = -1073741790;
goto LABEL_33;
}
started = CmpStartKcbStackForTopLayerKcb((INT64)&v26[4], (INT64)KeyControlBlock);
if( started < 0 )
goto LABEL_33;
if( !v6 )
{
CmpLockKcbStackTopExclusiveRestShared((INT64)&v26[4]);
v8 = 1;
}
started = CmpPerformKeyBodyDeletionCheck(KeyBody, 0i64);
if( started < 0 )
goto LABEL_33;
if( *(_QWORD *)&KeyBody->Trans.0 || KeyBody->KtmUow )
{
started = CmpTransSearchAddTransFromKeyBody(KeyBody, &CmTrans);
if( started < 0 )
goto LABEL_33;
started = CmpPerformKeyBodyDeletionCheck(KeyBody, CmTrans);
if( started < 0 )
goto LABEL_33;
}
if( KeGetCurrentThread()->PreviousMode
&& (KeyControlBlock->KeyHash.KeyHive[2].Storage[1].FreeDisplay[6].RealVectorSize & 0x20) != 0 )
{
goto LABEL_66;
}
if( KeyControlBlock->LayerHeight )
{
if( (unsigned int)CmpGetEffectiveKcbSemantics((INT64)KeyControlBlock) || v6 )
{
if( !(unsigned int)CmpGetEffectiveKcbSemantics(v19) )
{
started = CmpPromoteKey((__int64)&v26[4], 1, 0);
if( started < 0 )
goto LABEL_33;
started = CmpPartialPromoteSubkeys((__int64)&v26[4]);
if( started < 0 )
goto LABEL_33;
}
goto LABEL_15;
}
v6 = 1;
v25 = 1;
CmpUnlockKcbStack((INT64)&v26[4]);
v8 = 0;
CmpCleanupKcbStack((INT64)&v26[4]);
*(_OWORD *)&v26[4] = 0i64;
*(_WORD *)&v26[6] = -1;
v27 = 0i64;
CmpUnlockRegistry();
CmpReleaseShutdownRundown();
}
else
{
LABEL_15:
v12 = CmTrans;
if( CmTrans )
{
if( (KeyControlBlock->KeyHash.KeyHive->HiveFlags & 2) != 0 )
{
started = -1072103423;
}
else
{
UnitOfWork = CmpAllocateUnitOfWork();
v9 = UnitOfWork;
if( UnitOfWork )
{
CmpTransEnlistUowInKcb((_CM_KCB_UOW *__ptr32)UnitOfWork, (_CM_KEY_CONTROL_BLOCK *__ptr32)KeyControlBlock);
started = CmpTransEnlistUowInCmTrans(v9, v12);
if( started >= 0 )
{
if( CmpLockIXLockExclusive((INT64)&KeyControlBlock->KCBLock, (INT64)v9, 0i64)
&& CmpLockIXLockExclusive((INT64)&KeyControlBlock->KeyLock, (INT64)v9, 1i64) )
{
LABEL_18:
if( !v25 )
{
HvLockHiveFlusherShared((INT64)KeyControlBlock->KeyHash.KeyHive);
v7 = 1;
CmLockHiveSecurityExclusive((_EX_PUSH_LOCK *)KeyControlBlock->KeyHash.KeyHive);
}
LODWORD(v23) = (_DWORD)GenericMapping;
started = CmpSetSecurityDescriptorInfo(
(__int64)KeyControlBlock,
*(int **)v36,
*(void **)v35,
*(__int64 *)v34,
v23,
v33,
(__int64)v12,
(__int64)v9,
&SubjectContext);
v14 = v7;
if( started >= 0 )
{
started = 0;
v9 = 0i64;
if( v7 )
{
CmUnlockHiveSecurity((int)KeyControlBlock->KeyHash.KeyHive);
v14 = 0;
}
if( KeyControlBlock->LayerHeight
&& !(unsigned int)CmpGetEffectiveKcbSemantics((INT64)KeyControlBlock) )
{
KeyNodeForKcb = CmpGetKeyNodeForKcb(v21, (INT64)&v30, v7);
*(_BYTE *)(KeyNodeForKcb + 13) = *(_BYTE *)(KeyNodeForKcb + 13) & 0xFC | 2;
CmpReleaseKeyNodeForKcb((__int64)KeyControlBlock);
KeyControlBlock->LayerSemantics = 2;
}
if( v7 )
{
HvUnlockHiveFlusherShared((INT64)KeyControlBlock->KeyHash.KeyHive);
v7 = 0;
}
CmpReportNotifyForKcbStack((INT64)&v26[4], (INT64)v12, 10i64, &DeferredPostAsync);
}
if( v14 )
CmUnlockHiveSecurity((int)KeyControlBlock->KeyHash.KeyHive);
if( v7 )
HvUnlockHiveFlusherShared((INT64)KeyControlBlock->KeyHash.KeyHive);
}
else
{
started = -1072103423;
}
}
if( v9 )
{
CmpRundownUnitOfWork(v9);
CmpFreeUnitOfWork(v9);
}
}
else
{
started = -1073741670;
}
}
LABEL_33:
v15 = 1;
goto LABEL_34;
}
p_KCBLock = (INT64)&KeyControlBlock->KCBLock;
if( !KeyControlBlock->KCBLock.OwnerCount )
{
p_KCBLock = (INT64)&KeyControlBlock->KeyLock;
if( !KeyControlBlock->KeyLock.OwnerCount )
goto LABEL_18;
}
v16 = 0;
started = CmpSnapshotTxOwnerArray(p_KCBLock, (UINT64 *)v26, &v29);
if( started < 0 )
goto LABEL_33;
if( v8 )
CmpUnlockKcbStack((INT64)&v26[4]);
v8 = 0;
CmpCleanupKcbStack((INT64)&v26[4]);
*(_OWORD *)&v26[4] = 0i64;
*(_WORD *)&v26[6] = -1;
v27 = 0i64;
CmpUnlockRegistry();
v15 = 0;
CmpReleaseShutdownRundown();
started = CmpRollbackTransactionArray(*(unsigned int *)v26, (PADAPTER_OBJECT *)v29, v20, &v28);
if( started < 0 )
goto LABEL_35;
v6 = v25;
}
}
started = -1073741431;
v15 = 0;
LABEL_34:
v16 = v24;
LABEL_35:
if( v8 )
CmpUnlockKcbStack((INT64)&v26[4]);
CmpCleanupKcbStack((INT64)&v26[4]);
if( v15 )
CmpUnlockRegistry();
if( DeferredPostAsync.Flink != &DeferredPostAsync )
CmpSignalDeferredPosts(&DeferredPostAsync);
if( v16 )
CmpReleaseShutdownRundown();
CmpDetachFromRegistryProcess(&ApcState);
SeReleaseSubjectContext(&SubjectContext);
return started;
}Referenced by:
CmpSecurityMethod