RtlpInheritAcl2

__int64 __fastcall RtlpInheritAcl2(
        unsigned __int8 *a1,
        unsigned __int8 *a2,
        __int16 a3,
        char a4,
        char a5,
        char a6,
        __int64 a7,
        __int64 a8,
        __int64 a9,
        __int64 a10,
        PGENERIC_MAPPING a11,
        int a12,
        __int64 a13,
        int a14,
        __int64 a15,
        PACL Acl,
        __int64 a17,
        __int64 a18){
  char v18; 
  int v19; 
  int v20; 
  int v21; 
  unsigned __int8 *v23; 
  int v24; 
  int v25; 
  _BYTE *v26; 
  int v27; 
  char v28; 
  char v29; 
  __int64 result; 
  char v31; 
  int v32; 
  int v33; 
  unsigned __int8 v34; 
  __int64 v35; 
  unsigned int v36; 
  int v37; 
  UINT64 v38; 
  __int64 v39; 
  unsigned int v40; 
  _DWORD v41[3]; 
  PACE Ace; 
  char v45; 
  v18 = 0;
  v19 = 0;
  memset(v41, 0, sizeof(v41));
  v20 = 2;
  v21 = *(_DWORD *)a15;
  Ace = 0i64;
  v23 = a2;
  v24 = 0;
  v39 = 256i64;
  v25 = 0;
  v45 = 0;
  v40 = 2;
  if( (unsigned int)(v21 - 8) <= 0xFFF4 )
  {
    memset((INT64)Acl, 0i64);
    v24 = HIDWORD(v39);
    v23 = a2;
    Acl->AclSize = v21 & 0xFFFC;
    v18 = 0;
    *(_WORD *)&Acl->AclRevision = 2;
    *(_DWORD *)&Acl->AceCount = 0;
  }
  v26 = (_BYTE *)a17;
  v27 = a5 != 0 ? 0x400 : 0;
  *(_BYTE *)a17 = 0;
  *(_DWORD *)a18 = v27;
  if( (a3 & 8) != 0 )
    goto LABEL_40;
  if( (a3 & 0x1000) != 0 )
  {
    v18 = 1;
    v45 = 1;
    *(_DWORD *)a18 = v27 | 0x1000;
  }
  if( (a3 & 0x1004) == 0 )
  {
LABEL_40:
    v31 = 0;
    goto LABEL_21;
  }
  if( v23 )
  {
    if( *v23 >= 2u )
      v40 = *v23;
    BYTE1(v39) = 0;
    if( a5 )
    {
      if( (a3 & 0x1000) != 0 )
      {
        v28 = 16;
      }
      else
      {
        v20 = 1;
        v28 = 0;
      }
      v29 = 1;
    }
    else
    {
      v28 = 0;
      v29 = 0;
    }
    result = RtlpCopyAces(
               (__int64)v23,
               a11,
               v20,
               v28,
               v29,
               a7,
               a8,
               a9,
               a10,
               a4,
               0,
               a12,
               (unsigned int *)&v39 + 1,
               (__int64)Acl);
    v24 = HIDWORD(v39);
    v19 = HIDWORD(v39);
    if( (_DWORD)result == -1073741789 )
    {
      v31 = 1;
    }
    else
    {
      if( (int)result < 0 )
        return result;
      v31 = 0;
    }
    if( a6 && HIDWORD(v39) )
    {
      WORD1(v39) = Acl->AceCount;
      if( !RtlFirstFreeAce(Acl, (VOID **)&Ace) )
        return 3221225597i64;
      v24 = HIDWORD(v39);
    }
    v23 = a2;
    v26 = (_BYTE *)a17;
    v18 = v45;
  }
  else
  {
    if( a5 )
    {
      v32 = a12;
      if( a12 == 1 )
      {
        if( (a3 & 0x1004) == 4 )
          return 3221225591i64;
        v31 = 0;
        goto LABEL_46;
      }
      v31 = 0;
      goto LABEL_20;
    }
    v31 = 0;
  }
  v32 = a12;
  if( a12 == 1 )
    goto LABEL_46;
LABEL_20:
  if( v32 != 2 )
    goto LABEL_21;
  if( v24 || v18 )
  {
LABEL_46:
    *v26 = 1;
    goto LABEL_21;
  }
  if( v23 && !*((_WORD *)v23 + 2) )
    *v26 = 1;
LABEL_21:
  if( (a5 || (a3 & 4) != 0) && (a3 & 8) == 0 && (!a5 || v18) || !a1 )
  {
    v33 = HIDWORD(v39);
    v34 = v40;
LABEL_27:
    v35 = (unsigned int)(v25 + v19);
    if( !(_DWORD)v35 )
    {
      if( !*(_BYTE *)a17 )
      {
        *(_DWORD *)a15 = 0;
        return 2147483659i64;
      }
      if( BYTE1(v39) )
      {
        *(_DWORD *)a15 = 0;
        return 0i64;
      }
    }
    if( (unsigned __int64)(v35 + 8) <= 0xFFFF )
    {
      *(_DWORD *)a15 = v25 + v33 + 8;
      if( v31 )
        return 3221225507i64;
      Acl->AclRevision = v34;
      Acl->AclSize = v25 + v19 + 8;
      return 0i64;
    }
    return 3221225597i64;
  }
  v36 = *a1;
  if( (unsigned __int8)(v36 - 2) > 2u )
    return 3221225560i64;
  v34 = v40;
  if( v40 <= v36 )
  {
    v40 = *a1;
    v34 = v36;
  }
  LODWORD(v38) = a14;
  result = RtlpGenerateInheritAcl(
             (__int64)a1,
             a4,
             a5,
             a7,
             a8,
             a9,
             a10,
             a11,
             a13,
             v38,
             a12,
             v31,
             (__int64)v41,
             (__int64)Acl,
             (__int64)&v39);
  if( (_DWORD)result == -1073741789 )
  {
    v31 = 1;
LABEL_38:
    v33 = HIDWORD(v39);
    if( a6 && HIDWORD(v39) && (_BYTE)v39 && !v31 )
    {
      if( !RtlFirstFreeAce(Acl, (VOID **)&v41[1]) )
        return 3221225597i64;
      v37 = v41[1];
      if( !*(_QWORD *)&v41[1] )
        v37 = (_DWORD)Acl + Acl->AclSize;
      memmove((UINT8 *)&Acl[1], (UINT8 *)Ace, (unsigned int)(v37 - (_DWORD)Ace));
      Acl->AceCount -= WORD1(v39);
      v19 = 0;
    }
    v25 = v41[0];
    goto LABEL_27;
  }
  if( (int)result >= 0 )
    goto LABEL_38;
  return result;
}

Referenced by:

RtlpNewSecurityObject