Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions Source/User.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
////////////////////////////////////////////////////////////////////////////////
// -------------------------------------------------------------------------- //
// //
// (C) 2010-2016 Robot Developers //
// (C) 2016 Chris Gregory [email protected] //
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line should be deleted and the one above should be (C) 2016-2017.

// See LICENSE for licensing info //
// //
// -------------------------------------------------------------------------- //
////////////////////////////////////////////////////////////////////////////////

//----------------------------------------------------------------------------//
// Prefaces //
//----------------------------------------------------------------------------//

#include "User.h"

#if defined (ROBOT_OS_MAC) || \
defined (ROBOT_OS_LINUX)
#include <unistd.h>
#include <sys/types.h>
#endif

#if defined (ROBOT_OS_WIN)
#include <Winbase.h>
#endif

ROBOT_NS_BEGIN

bool User::IsAdmin(void)
{
#if defined (ROBOT_OS_MAC) || \
defined (ROBOT_OS_LINUX)
return getuid() == 0;
#endif
#ifdef ROBOT_OS_WIN
BOOL b;
SID_IDENTIFIER_AUTHORITY NtAuthority = SECURITY_NT_AUTHORITY;
PSID AdministratorsGroup;
b = AllocateAndInitializeSid(
&NtAuthority,
2,
SECURITY_BUILTIN_DOMAIN_RID,
DOMAIN_ALIAS_RID_ADMINS,
0, 0, 0, 0, 0, 0,
&AdministratorsGroup);
if(b)
{
if (!CheckTokenMembership (NULL, AdministratorsGroup, &b))
{
b = FALSE;
}
FreeSid(AdministratorsGroup);
}

return b == TRUE;
#endif
}

ROBOT_NS_END
36 changes: 36 additions & 0 deletions Source/User.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
////////////////////////////////////////////////////////////////////////////////
// -------------------------------------------------------------------------- //
// //
// (C) 2010-2016 Robot Developers //
// (C) 2016 Chris Gregory [email protected] //
// See LICENSE for licensing info //
// //
// -------------------------------------------------------------------------- //
////////////////////////////////////////////////////////////////////////////////

//----------------------------------------------------------------------------//
// Prefaces //
//----------------------------------------------------------------------------//

#pragma once

#include "Types.h"
ROBOT_NS_BEGIN



//----------------------------------------------------------------------------//
// Classes //
//----------------------------------------------------------------------------//

////////////////////////////////////////////////////////////////////////////////

class ROBOT_EXPORT User
{
public:
////////////////////////////////////////////////////////////////////////////////

static bool IsAdmin(void);
};

ROBOT_NS_END