E-MailRelay
Public Member Functions | Static Public Member Functions | List of all members
G::Identity Class Reference

A combination of user-id and group-id, with a very low-level interface to the get/set/e/uid/gid functions. More...

#include <gidentity.h>

Public Member Functions

 Identity (const std::string &username, const std::string &group_name_override=std::string())
 Constructor for the named identity. More...
 
bool isRoot () const noexcept
 Returns true if the userid is zero. More...
 
std::string str () const
 Returns a string representation. More...
 
uid_t userid () const noexcept
 Returns the user part. More...
 
gid_t groupid () const noexcept
 Returns the group part. More...
 
bool operator== (const Identity &) const noexcept
 Comparison operator. More...
 
bool operator!= (const Identity &) const noexcept
 Comparison operator. More...
 

Static Public Member Functions

static Identity effective () noexcept
 Returns the current effective identity. More...
 
static Identity real (bool with_cache=true) noexcept
 Returns the calling process's real identity. More...
 
static Identity root () noexcept
 Returns the superuser identity. More...
 
static Identity invalid () noexcept
 Returns an invalid identity. More...
 
static Identity invalid (SignalSafe) noexcept
 Returns an invalid identity, with a signal-safe guarantee. More...
 
static std::pair< uid_t, gid_t > lookupUser (const std::string &user)
 Does a username lookup. Throws on error. More...
 
static gid_t lookupGroup (const std::string &group)
 Does a groupname lookup. Throws on error. More...
 

Detailed Description

A combination of user-id and group-id, with a very low-level interface to the get/set/e/uid/gid functions.

Uses getpwnam() to do username lookups.

See also
G::Process, G::Root

Definition at line 42 of file gidentity.h.

Constructor & Destructor Documentation

◆ Identity()

G::Identity::Identity ( const std::string &  username,
const std::string &  group_name_override = std::string() 
)
explicit

Constructor for the named identity.

Throws NoSuchUser on error.

Definition at line 55 of file gidentity_unix.cpp.

Member Function Documentation

◆ effective()

G::Identity G::Identity::effective ( )
staticnoexcept

Returns the current effective identity.

Definition at line 133 of file gidentity_unix.cpp.

◆ groupid()

gid_t G::Identity::groupid ( ) const
noexcept

Returns the group part.

Definition at line 189 of file gidentity_unix.cpp.

◆ invalid() [1/2]

G::Identity G::Identity::invalid ( )
staticnoexcept

Returns an invalid identity.

Definition at line 159 of file gidentity_unix.cpp.

◆ invalid() [2/2]

G::Identity G::Identity::invalid ( SignalSafe  safe)
staticnoexcept

Returns an invalid identity, with a signal-safe guarantee.

Definition at line 164 of file gidentity_unix.cpp.

◆ isRoot()

bool G::Identity::isRoot ( ) const
noexcept

Returns true if the userid is zero.

Definition at line 194 of file gidentity_unix.cpp.

◆ lookupGroup()

gid_t G::Identity::lookupGroup ( const std::string &  group)
static

Does a groupname lookup. Throws on error.

Definition at line 106 of file gidentity_unix.cpp.

◆ lookupUser()

std::pair< uid_t, gid_t > G::Identity::lookupUser ( const std::string &  user)
static

Does a username lookup. Throws on error.

Definition at line 67 of file gidentity_unix.cpp.

◆ operator!=()

bool G::Identity::operator!= ( const Identity other) const
noexcept

Comparison operator.

Definition at line 204 of file gidentity_unix.cpp.

◆ operator==()

bool G::Identity::operator== ( const Identity other) const
noexcept

Comparison operator.

Definition at line 199 of file gidentity_unix.cpp.

◆ real()

G::Identity G::Identity::real ( bool  with_cache = true)
staticnoexcept

Returns the calling process's real identity.

Definition at line 142 of file gidentity_unix.cpp.

◆ root()

G::Identity G::Identity::root ( )
staticnoexcept

Returns the superuser identity.

Definition at line 169 of file gidentity_unix.cpp.

◆ str()

std::string G::Identity::str ( ) const

Returns a string representation.

Definition at line 177 of file gidentity_unix.cpp.

◆ userid()

uid_t G::Identity::userid ( ) const
noexcept

Returns the user part.

Definition at line 184 of file gidentity_unix.cpp.


The documentation for this class was generated from the following files: