SepReferenceTokenUsingPseudoHandle

NTSTATUS __stdcall SepReferenceTokenUsingPseudoHandle(
        PVOID TokenHandle,
        PVOID *Token,
        _BYTE *UseNewTrust,
        PVOID *TrustLevelSid){
  _ETHREAD *CurrentThread; 
  _ADAPTER_OBJECT *v8; 
  VOID *v9; 
  VOID *v10; 
  void *v11; 
  _SECURITY_IMPERSONATION_LEVEL ImpersonationLevel; 
  _TOKEN_TYPE TokenType[13]; 
  _PS_PROTECTION Protection; 
  UINT8 EffectiveOnly; 
  UINT8 pbDominate; 
  UINT8 CopyOnOpen; 

  EffectiveOnly = 0;
  *Token = 0i64;
  *UseNewTrust = 0;
  *TrustLevelSid = 0i64;
  CurrentThread = (_ETHREAD *)KeGetCurrentThread();
  ImpersonationLevel = SecurityAnonymous;
  TokenType[0] = 0;
  Protection.Level = 0;
  if( TokenHandle == (PVOID)-4i64 )
  {
    *Token = PsReferencePrimaryToken(CurrentThread->Tcb.ApcState.Process);
    return 0;
  }
  if( TokenHandle == (PVOID)-5i64 )
  {
    v8 = (_ADAPTER_OBJECT *)PsReferenceImpersonationTokenEx(
                              CurrentThread,
                              0i64,
                              &CopyOnOpen,
                              &EffectiveOnly,
                              &ImpersonationLevel,
                              &Protection);
    if( !v8 )
      return -1073741700;
  }
  else
  {
    v8 = (_ADAPTER_OBJECT *)PsReferenceEffectiveToken(
                              CurrentThread,
                              TokenType,
                              &EffectiveOnly,
                              &ImpersonationLevel,
                              &Protection);
    if( TokenType[0] != TokenImpersonation )
      goto LABEL_7;
  }
  if( ImpersonationLevel == SecurityAnonymous )
  {
    HalPutDmaAdapter(v8);
    return -1073741658;
  }
LABEL_7:
  *UseNewTrust = 0;
  *TrustLevelSid = 0i64;
  pbDominate = 0;
  v9 = SepSidFromProcessProtection(&Protection);
  RtlSidDominatesForTrust(v9, v10, &pbDominate);
  if( !pbDominate )
  {
    *UseNewTrust = 1;
    *TrustLevelSid = v9;
  }
  *Token = v11;
  return 0;
}

Referenced by:

SepReferenceTokenByHandle