From 1dff8c04af815103becfa64506e2fc84a3b0bf15 Mon Sep 17 00:00:00 2001 From: Czipperz Date: Tue, 5 Jul 2016 02:20:37 -0500 Subject: [PATCH] IsAdmin defined in User.{cc,h} --- Source/User.cc | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++ Source/User.h | 36 ++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 Source/User.cc create mode 100644 Source/User.h diff --git a/Source/User.cc b/Source/User.cc new file mode 100644 index 0000000..2ab790e --- /dev/null +++ b/Source/User.cc @@ -0,0 +1,59 @@ +//////////////////////////////////////////////////////////////////////////////// +// -------------------------------------------------------------------------- // +// // +// (C) 2010-2016 Robot Developers // +// (C) 2016 Chris Gregory czipperz@gmail.com // +// See LICENSE for licensing info // +// // +// -------------------------------------------------------------------------- // +//////////////////////////////////////////////////////////////////////////////// + +//----------------------------------------------------------------------------// +// Prefaces // +//----------------------------------------------------------------------------// + +#include "User.h" + +#if defined (ROBOT_OS_MAC) || \ + defined (ROBOT_OS_LINUX) +#include +#include +#endif + +#if defined (ROBOT_OS_WIN) +#include +#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 diff --git a/Source/User.h b/Source/User.h new file mode 100644 index 0000000..e9d0a05 --- /dev/null +++ b/Source/User.h @@ -0,0 +1,36 @@ +//////////////////////////////////////////////////////////////////////////////// +// -------------------------------------------------------------------------- // +// // +// (C) 2010-2016 Robot Developers // +// (C) 2016 Chris Gregory czipperz@gmail.com // +// 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