libmoost
|
Process ownership information and manipulation. More...
#include <ownership.hpp>
Public Types | |
typedef detail::ownership::uid_type | uid_type |
typedef detail::ownership::gid_type | gid_type |
Public Member Functions | |
bool | is_superuser () const |
Check for superuser privileges. | |
bool | lookup_user (std::string &name, const uid_type &uid) const |
Lookup user name by user id. | |
bool | lookup_uid (uid_type &uid, const std::string &name) const |
Lookup user id by user name. | |
bool | lookup_uid (uid_type &uid, gid_type &gid, const std::string &name) const |
Lookup user id and group id by user name. | |
void | set_uid (uid_type uid) |
Set new user id. | |
void | set_effective_uid (uid_type uid) |
Set new effective user id. | |
uid_type | get_uid () const |
Get current user id. | |
uid_type | get_effective_uid () const |
Get current effective user id. | |
bool | lookup_group (std::string &name, const gid_type &gid) const |
Lookup group name by group id. | |
bool | lookup_gid (gid_type &gid, const std::string &name) const |
Lookup group id by group name. | |
void | set_gid (gid_type gid) |
Set new group id. | |
void | set_effective_gid (gid_type gid) |
Set new effective group id. | |
gid_type | get_gid () const |
Get current group id. | |
gid_type | get_effective_gid () const |
Get current effective group id. | |
bool | set_user (const std::string &name) |
Set new user id by user name. | |
bool | set_effective_user (const std::string &name) |
Set new effective user id by user name. | |
bool | set_group (const std::string &name) |
Set new group id by group name. | |
bool | set_effective_group (const std::string &name) |
Set new effective group id by group name. | |
std::string | get_user () const |
Get current user name. | |
std::string | get_effective_user () const |
Get current effective user name. | |
std::string | get_group () const |
Get current group name. | |
std::string | get_effective_group () const |
Get current effective group name. | |
void | drop_privileges (const std::string &user, const std::string &group="") |
Drop process ownership privileges. | |
Private Attributes | |
detail::ownership | m_impl |
Process ownership information and manipulation.
This class allows a process to retrieve information about or manipulate its ownership. For example, it allows a daemon process to drop privileges when being run by the superuser.
Platform specific abstractions are provided for Win32 and POSIX systems, although the Win32 abstraction is just a dummy at the moment.
Definition at line 45 of file ownership.hpp.
Definition at line 49 of file ownership.hpp.
Definition at line 48 of file ownership.hpp.
void moost::process::ownership::drop_privileges | ( | const std::string & | user, |
const std::string & | group = "" |
||
) | [inline] |
Drop process ownership privileges.
user | User name to continue to run this process as. |
group | Optional group name to run this process as. Defaults to the primary group of the user. |
Throws | an instance of boost::system::system_error on failure or a std::runtime_error when either user or group could not be found. |
Definition at line 419 of file ownership.hpp.
gid_type moost::process::ownership::get_effective_gid | ( | ) | const [inline] |
Get current effective group id.
Throws | an instance of boost::system::system_error on failure. |
Definition at line 235 of file ownership.hpp.
std::string moost::process::ownership::get_effective_group | ( | ) | const [inline] |
Get current effective group name.
Throws | an instance of boost::system::system_error on failure or a std::runtime_error when the group could not be found. |
Definition at line 396 of file ownership.hpp.
uid_type moost::process::ownership::get_effective_uid | ( | ) | const [inline] |
Get current effective user id.
Throws | an instance of boost::system::system_error on failure. |
Definition at line 155 of file ownership.hpp.
std::string moost::process::ownership::get_effective_user | ( | ) | const [inline] |
Get current effective user name.
Throws | an instance of boost::system::system_error on failure or a std::runtime_error when the user could not be found. |
Definition at line 356 of file ownership.hpp.
gid_type moost::process::ownership::get_gid | ( | ) | const [inline] |
Get current group id.
Throws | an instance of boost::system::system_error on failure. |
Definition at line 223 of file ownership.hpp.
std::string moost::process::ownership::get_group | ( | ) | const [inline] |
Get current group name.
Throws | an instance of boost::system::system_error on failure or a std::runtime_error when the group could not be found. |
Definition at line 376 of file ownership.hpp.
uid_type moost::process::ownership::get_uid | ( | ) | const [inline] |
Get current user id.
Throws | an instance of boost::system::system_error on failure. |
Definition at line 143 of file ownership.hpp.
std::string moost::process::ownership::get_user | ( | ) | const [inline] |
Get current user name.
Throws | an instance of boost::system::system_error on failure or a std::runtime_error when the user could not be found. |
Definition at line 336 of file ownership.hpp.
bool moost::process::ownership::is_superuser | ( | ) | const [inline] |
Check for superuser privileges.
Definition at line 57 of file ownership.hpp.
bool moost::process::ownership::lookup_gid | ( | gid_type & | gid, |
const std::string & | name | ||
) | const [inline] |
Lookup group id by group name.
gid | Reference to native type to store the group id in. |
name | Group name. |
Throws | an instance of boost::system::system_error on failure. |
Definition at line 187 of file ownership.hpp.
bool moost::process::ownership::lookup_group | ( | std::string & | name, |
const gid_type & | gid | ||
) | const [inline] |
Lookup group name by group id.
name | Reference to a string to store the group name in. |
gid | Group id in the platform's native format. |
Throws | an instance of boost::system::system_error on failure. |
Definition at line 171 of file ownership.hpp.
bool moost::process::ownership::lookup_uid | ( | uid_type & | uid, |
const std::string & | name | ||
) | const [inline] |
Lookup user id by user name.
uid | Reference to native type to store the user id in. |
name | User name. |
Throws | an instance of boost::system::system_error on failure. |
Definition at line 89 of file ownership.hpp.
bool moost::process::ownership::lookup_uid | ( | uid_type & | uid, |
gid_type & | gid, | ||
const std::string & | name | ||
) | const [inline] |
Lookup user id and group id by user name.
uid | Reference to native type to store the user id in. |
uid | Reference to native type to store the group id in. |
name | User name. |
Throws | an instance of boost::system::system_error on failure. |
Definition at line 107 of file ownership.hpp.
bool moost::process::ownership::lookup_user | ( | std::string & | name, |
const uid_type & | uid | ||
) | const [inline] |
Lookup user name by user id.
name | Reference to a string to store the user name in. |
uid | User id in the platform's native format. |
Throws | an instance of boost::system::system_error on failure. |
Definition at line 73 of file ownership.hpp.
void moost::process::ownership::set_effective_gid | ( | gid_type | gid | ) | [inline] |
Set new effective group id.
uid | Group id in the platform's native format. |
Throws | an instance of boost::system::system_error on failure. |
Definition at line 211 of file ownership.hpp.
bool moost::process::ownership::set_effective_group | ( | const std::string & | name | ) | [inline] |
Set new effective group id by group name.
name | String holding the group name. |
Throws | an instance of boost::system::system_error on failure or a std::runtime_error when the group could not be found. |
Definition at line 314 of file ownership.hpp.
void moost::process::ownership::set_effective_uid | ( | uid_type | uid | ) | [inline] |
Set new effective user id.
uid | User id in the platform's native format. |
Throws | an instance of boost::system::system_error on failure. |
Definition at line 131 of file ownership.hpp.
bool moost::process::ownership::set_effective_user | ( | const std::string & | name | ) | [inline] |
Set new effective user id by user name.
name | String holding the user name. |
Throws | an instance of boost::system::system_error on failure or a std::runtime_error when the user could not be found. |
Definition at line 270 of file ownership.hpp.
void moost::process::ownership::set_gid | ( | gid_type | gid | ) | [inline] |
Set new group id.
uid | Group id in the platform's native format. |
Throws | an instance of boost::system::system_error on failure. |
Definition at line 199 of file ownership.hpp.
bool moost::process::ownership::set_group | ( | const std::string & | name | ) | [inline] |
Set new group id by group name.
name | String holding the group name. |
Throws | an instance of boost::system::system_error on failure or a std::runtime_error when the group could not be found. |
Definition at line 292 of file ownership.hpp.
void moost::process::ownership::set_uid | ( | uid_type | uid | ) | [inline] |
Set new user id.
uid | User id in the platform's native format. |
Throws | an instance of boost::system::system_error on failure. |
Definition at line 119 of file ownership.hpp.
bool moost::process::ownership::set_user | ( | const std::string & | name | ) | [inline] |
Set new user id by user name.
name | String holding the user name. |
Throws | an instance of boost::system::system_error on failure or a std::runtime_error when the user could not be found. |
Definition at line 248 of file ownership.hpp.
Definition at line 449 of file ownership.hpp.