include/llfio/v2.0/detail/impl/windows/import.hpp
// Detect if we are running under SUID or SGID
Detect if we are running under SUID or SGID
Detect if we are running under SUID or SGID
inline bool running_under_suid_gid()
{
  HANDLE processtoken;
  if(OpenProcessToken(GetCurrentProcess(), TOKEN_ALL_ACCESS, &processtoken) == 0)
  {
    abort();
  }
  auto unprocesstoken = make_scope_exit([&processtoken]() noexcept { CloseHandle(processtoken); });
  (void) unprocesstoken;
  DWORD written;
  char buffer1[1024], buffer2[1024];
  if(GetTokenInformation(processtoken, TokenUser, buffer1, sizeof(buffer1), &written) == 0)
  {
    abort();
  }
  if(GetTokenInformation(processtoken, TokenOwner, buffer2, sizeof(buffer2), &written) == 0)
  {
    abort();
  }
  auto *tu = reinterpret_cast<TOKEN_USER *>(buffer1);
  auto *to = reinterpret_cast<TOKEN_OWNER *>(buffer2);
  return EqualSid(tu->User.Sid, to->Owner) == 0;
}
inline bool running_under_suid_gid ( ) { HANDLE processtoken ; if ( OpenProcessToken ( GetCurrentProcess ( ) , TOKEN_ALL_ACCESS , & processtoken ) == 0 ) { abort ( ) ; } auto unprocesstoken = make_scope_exit ( [ & processtoken ] ( ) noexcept { CloseHandle ( processtoken ) ; } ) ; ( void ) unprocesstoken ; DWORD written ; char buffer1 [ 1024 ] , buffer2 [ 1024 ] ; if ( GetTokenInformation ( processtoken , TokenUser , buffer1 , sizeof ( buffer1 ) , & written ) == 0 ) { abort ( ) ; } if ( GetTokenInformation ( processtoken , TokenOwner , buffer2 , sizeof ( buffer2 ) , & written ) == 0 ) { abort ( ) ; } auto * tu = reinterpret_cast < TOKEN_USER * > ( buffer1 ) ; auto * to = reinterpret_cast < TOKEN_OWNER * > ( buffer2 ) ; return EqualSid ( tu -> User . Sid , to -> Owner ) == 0 ; }
Detect if we are running under SUID or SGID
Detect if we are running under SUID or SGID