28 G::Root * G::Root::m_this = nullptr ;
29 bool G::Root::m_initialised = false ;
30 bool G::Root::m_default_change_group = true ;
35 m_change_group(m_default_change_group)
38 G_WARNING(
"G::Root::ctor: root control object exists at outer scope" ) ;
40 if( m_this ==
nullptr && m_initialised )
42 Process::beSpecial( m_special , m_change_group ) ;
48 m_change_group(change_group)
51 G_WARNING(
"G::Root::ctor: root control object exists at outer scope" ) ;
53 if( m_this ==
nullptr && m_initialised )
55 Process::beSpecial( m_special , m_change_group ) ;
64 if( m_this ==
this && m_initialised )
67 Process::beOrdinary( m_ordinary , m_change_group ) ;
70 catch( std::exception & e )
72 G_ERROR(
"G::Root: cannot release root privileges: " << e.what() ) ;
76 G_ERROR(
"G::Root: cannot release root privileges" ) ;
83 return Process::beSpecial( safe , m_special , m_default_change_group ) ;
89 Process::beOrdinary( safe , identity , m_default_change_group ) ;
92 void G::Root::init(
const std::string & non_root ,
bool default_change_group )
94 G_ASSERT( !non_root.empty() ) ;
95 Process::revokeExtraGroups() ;
97 m_special = Process::beOrdinary(
SignalSafe() , m_ordinary , default_change_group ) ;
98 m_initialised = true ;
99 m_default_change_group = default_change_group ;
An empty structure that is used to indicate a signal-safe, reentrant implementation.
static Identity nobody()
Returns the 'nobody' identity corresponding to the init() user name.
static Identity invalid()
Returns an invalid identity.
A combination of user-id and group-id, with a very low-level interface to the get/set/e/uid/gid funct...
A class which acquires the process's special privileges on construction and releases them on destruct...
static Identity start(SignalSafe)
A signal-safe alternative to construction.
static void init(const std::string &non_root, bool default_change_group=true)
Initialises this class on process start-up by releasing root (or suid) privileges.
static void stop(SignalSafe, Identity)
A signal-safe alternative to destruction.
Root()
Default constructor.
static bool enabled()
Returns true if test features are enabled.