IopSetDeviceSecurityDescriptor

NTSTATUS __stdcall IopSetDeviceSecurityDescriptor(
        _DEVICE_OBJECT *DeviceObject,
        UINT64 *SecurityInformation,
        PVOID SecurityDescriptor,
        POOL_TYPE PoolType,
        _GENERIC_MAPPING *GenericMapping){
  _ETHREAD *CurrentThread; 
  _GENERIC_MAPPING *v9; 
  volatile signed __int64 *v11; 
  int v12; 
  INT64 v13; 
  UINT64 v14; 
  void *OutputSecurityDescriptor[2]; 
  PSECURITY_DESCRIPTOR ObjectsSecurityDescriptor; 

  ObjectsSecurityDescriptor = 0i64;
  OutputSecurityDescriptor[0] = 0i64;
  CurrentThread = (_ETHREAD *)KeGetCurrentThread();
  v9 = GenericMapping;
  while( 1 )
  {
    --CurrentThread->Tcb.KernelApcDisable;
    ExAcquireResourceSharedLite((UINT64)&stru_140C452E0 + 1408, 1);
    v11 = (volatile signed __int64 *)DeviceObject->SecurityDescriptor;
    if( v11 && _InterlockedExchangeAdd64(v11 - 3, 1ui64) <= 0 )
      __fastfail(0xEu);
    ExReleaseResourceLite((PERESOURCE)((char *)&stru_140C452E0 + 1408));
    KeLeaveCriticalRegionThread(&CurrentThread->Tcb);
    ObjectsSecurityDescriptor = (PSECURITY_DESCRIPTOR)v11;
    v12 = SeSetSecurityDescriptorInfo(
            0i64,
            SecurityInformation,
            SecurityDescriptor,
            &ObjectsSecurityDescriptor,
            PoolType,
            v9,
            (INT64)OutputSecurityDescriptor[0],
            OutputSecurityDescriptor[1]);
    if( v12 < 0 )
      break;
    v12 = ObLogSecurityDescriptor(ObjectsSecurityDescriptor, OutputSecurityDescriptor, 1ui64);
    ExFreePoolWithTag(ObjectsSecurityDescriptor, 0);
    if( v12 < 0 )
      goto LABEL_13;
    --CurrentThread->Tcb.KernelApcDisable;
    ExAcquireResourceExclusiveLite((UINT64)&stru_140C452E0 + 1408, 1, v13);
    if( DeviceObject->SecurityDescriptor == v11 )
    {
      DeviceObject->SecurityDescriptor = OutputSecurityDescriptor[0];
      DeviceObject->DeviceObjectExtension->ExtensionFlags &= ~0x800u;
      ExReleaseResourceLite((PERESOURCE)((char *)&stru_140C452E0 + 1408));
      KeLeaveCriticalRegionThread(&CurrentThread->Tcb);
      v14 = 2i64;
LABEL_9:
      ObDereferenceSecurityDescriptor((VOID *)v11, v14);
      return v12;
    }
    ExReleaseResourceLite((PERESOURCE)((char *)&stru_140C452E0 + 1408));
    KeLeaveCriticalRegionThread(&CurrentThread->Tcb);
    ObDereferenceSecurityDescriptor((VOID *)v11, 1ui64);
    ObDereferenceSecurityDescriptor(OutputSecurityDescriptor[0], 1ui64);
  }
  if( v11 )
  {
LABEL_13:
    v14 = 1i64;
    goto LABEL_9;
  }
  return v12;
}

Referenced by:

IopGetSetSecurityObject
IopSetDeviceSecurityDescriptors