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={})
 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 (Unix). More...
 
gid_t groupid () const noexcept
 Returns the group part (Unix). More...
 
std::string sid () const
 Returns the sid (Windows). More...
 
bool operator== (const Identity &) const noexcept
 Comparison operator. More...
 
bool operator!= (const Identity &) const noexcept
 Comparison operator. More...
 
bool match (std::pair< int, int > uid_range) const
 Returns true if the user-id is in the given range or if not implemented. More...
 

Static Public Member Functions

static Identity effective () noexcept
 Returns the current effective identity. More...
 
static Identity real () 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< Identity, std::string > lookup (std::string_view user)
 Does a username lookup returning the identity and the canonical name. More...
 
static std::pair< Identity, std::string > lookup (std::string_view user, std::nothrow_t)
 Does a username lookup returning the identity and the canonical name. More...
 
static gid_t lookupGroup (const std::string &group)
 Does a groupname lookup. 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 44 of file gidentity.h.

Constructor & Destructor Documentation

◆ Identity()

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

Constructor for the named identity.

Throws NoSuchUser on error.

Definition at line 59 of file gidentity_unix.cpp.

Member Function Documentation

◆ effective()

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

Returns the current effective identity.

Definition at line 70 of file gidentity_unix.cpp.

◆ groupid()

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

Returns the group part (Unix).

Definition at line 111 of file gidentity_unix.cpp.

◆ invalid() [1/2]

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

Returns an invalid identity.

Definition at line 80 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 86 of file gidentity_unix.cpp.

◆ isRoot()

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

Returns true if the userid is zero.

Definition at line 116 of file gidentity_unix.cpp.

◆ lookup() [1/2]

std::pair< G::Identity, std::string > G::Identity::lookup ( std::string_view  user)
static

Does a username lookup returning the identity and the canonical name.

Throws if no such user or on error.

Definition at line 132 of file gidentity_unix.cpp.

◆ lookup() [2/2]

std::pair< G::Identity, std::string > G::Identity::lookup ( std::string_view  user,
std::nothrow_t   
)
static

Does a username lookup returning the identity and the canonical name.

Returns with Identitiy::invalid() if no such user. Throws on error.

Definition at line 142 of file gidentity_unix.cpp.

◆ lookupGroup()

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

Does a groupname lookup.

Returns -1 if no such group. Throws on error.

Definition at line 150 of file gidentity_unix.cpp.

◆ match()

bool G::Identity::match ( std::pair< int, int >  uid_range) const

Returns true if the user-id is in the given range or if not implemented.

Definition at line 157 of file gidentity_unix.cpp.

◆ operator!=()

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

Comparison operator.

Definition at line 126 of file gidentity_unix.cpp.

◆ operator==()

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

Comparison operator.

Definition at line 121 of file gidentity_unix.cpp.

◆ real()

G::Identity G::Identity::real ( )
staticnoexcept

Returns the calling process's real identity.

Definition at line 75 of file gidentity_unix.cpp.

◆ root()

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

Returns the superuser identity.

Definition at line 92 of file gidentity_unix.cpp.

◆ sid()

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

Returns the sid (Windows).

Definition at line 127 of file gidentity_win32.cpp.

◆ str()

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

Returns a string representation.

Definition at line 98 of file gidentity_unix.cpp.

◆ userid()

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

Returns the user part (Unix).

Definition at line 106 of file gidentity_unix.cpp.


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