|
Tor 0.5.0-alpha-dev
|
Access the POSIX user database. More...
#include "lib/fs/userdb.h"#include "lib/malloc/malloc.h"#include "lib/log/log.h"#include "lib/log/util_bug.h"#include <pwd.h>#include <stddef.h>#include <string.h>Go to the source code of this file.
Macros | |
| #define | tor_passwd_free(pw) FREE_AND_NULL(struct passwd, tor_passwd_free_, (pw)) |
Functions | |
| static struct passwd * | tor_passwd_dup (const struct passwd *pw) |
| static void | tor_passwd_free_ (struct passwd *pw) |
| const struct passwd * | tor_getpwnam (const char *username) |
| const struct passwd * | tor_getpwuid (uid_t uid) |
| char * | get_user_homedir (const char *username) |
Variables | |
| static struct passwd * | passwd_cached = NULL |
Access the POSIX user database.
Definition in file userdb.c.
| #define tor_passwd_free | ( | pw | ) | FREE_AND_NULL(struct passwd, tor_passwd_free_, (pw)) |
| char * get_user_homedir | ( | const char * | username | ) |
Allocate and return a string containing the home directory for the user username. Only works on posix-like systems.
Definition at line 127 of file userdb.c.
Referenced by expand_filename().
| const struct passwd * tor_getpwnam | ( | const char * | username | ) |
Wrapper around getpwnam() that caches result. Used so that we don't need to give the sandbox access to /etc/passwd.
The following fields alone will definitely be copied in the output: pw_uid, pw_gid, pw_name, pw_dir. Other fields are not present in cached values.
When called with a NULL argument, this function clears storage associated with static variables it uses.
Definition at line 70 of file userdb.c.
Referenced by check_private_dir(), connection_listener_new(), get_user_homedir(), switch_id(), and tor_free_all().
| const struct passwd * tor_getpwuid | ( | uid_t | uid | ) |
Wrapper around getpwnam() that can use cached result from tor_getpwnam(). Used so that we don't need to give the sandbox access to /etc/passwd.
The following fields alone will definitely be copied in the output: pw_uid, pw_gid, pw_name, pw_dir. Other fields are not present in cached values.
Definition at line 106 of file userdb.c.
Referenced by check_private_dir(), and getinfo_helper_misc().
|
static |
Helper: copy a struct passwd object.
We only copy the fields pw_uid, pw_gid, pw_name, pw_dir. Tor doesn't use any others, and I don't want to run into incompatibilities.
Definition at line 32 of file userdb.c.
Referenced by tor_getpwnam().
|
static |
|
static |
Cached struct from the last getpwname() call we did successfully.
Definition at line 24 of file userdb.c.
Referenced by tor_getpwnam(), and tor_getpwuid().