X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fcommon%2Frunas.c;h=930c973ff956ec2c13aeed57d2d2d69b8995775f;hb=48a4000561343808724f7cb5fa8c131877489ccd;hp=ab43423b1a3fd86ff798d45fb825a4b6e2392dba;hpb=37ccf8ecee70257a97ab6939e5dcb0112826f409;p=lttng-tools.git diff --git a/src/common/runas.c b/src/common/runas.c index ab43423b1..930c973ff 100644 --- a/src/common/runas.c +++ b/src/common/runas.c @@ -8,7 +8,6 @@ */ #define _LGPL_SOURCE -#include #include #include #include @@ -907,14 +906,15 @@ static int get_user_infos_from_uid( { int ret; char *buf = NULL; - size_t buf_size; + long raw_get_pw_buf_size; + size_t get_pw_buf_size; struct passwd pwd; struct passwd *result = NULL; /* Fetch the max size for the temporary buffer. */ errno = 0; - buf_size = sysconf(_SC_GETPW_R_SIZE_MAX); - if (buf_size < 0) { + raw_get_pw_buf_size = sysconf(_SC_GETPW_R_SIZE_MAX); + if (raw_get_pw_buf_size < 0) { if (errno != 0) { PERROR("Failed to query _SC_GETPW_R_SIZE_MAX"); goto error; @@ -923,16 +923,18 @@ static int get_user_infos_from_uid( /* Limit is indeterminate. */ WARN("Failed to query _SC_GETPW_R_SIZE_MAX as it is " "indeterminate; falling back to default buffer size"); - buf_size = GETPW_BUFFER_FALLBACK_SIZE; + raw_get_pw_buf_size = GETPW_BUFFER_FALLBACK_SIZE; } - buf = zmalloc(buf_size); + get_pw_buf_size = (size_t) raw_get_pw_buf_size; + + buf = zmalloc(get_pw_buf_size); if (buf == NULL) { PERROR("Failed to allocate buffer to get password file entries"); goto error; } - ret = getpwuid_r(uid, &pwd, buf, buf_size, &result); + ret = getpwuid_r(uid, &pwd, buf, get_pw_buf_size, &result); if (ret < 0) { PERROR("Failed to get user information for user: uid = %d", (int) uid); @@ -1101,8 +1103,8 @@ int handle_one_cmd(struct run_as_worker *worker) ssize_t readlen, writelen; struct run_as_ret sendret = {}; run_as_fct cmd; - uid_t prev_ruid; - gid_t prev_rgid; + const uid_t prev_ruid = getuid(); + const gid_t prev_rgid = getgid(); /* * Stage 1: Receive run_as_data struct from the master. @@ -1140,9 +1142,6 @@ int handle_one_cmd(struct run_as_worker *worker) goto end; } - prev_ruid = getuid(); - prev_rgid = getgid(); - ret = demote_creds(prev_ruid, prev_rgid, data.uid, data.gid); if (ret < 0) { goto write_return; @@ -1448,7 +1447,7 @@ int run_as_create_worker_no_lock(const char *procname, struct run_as_ret recvret; struct run_as_worker *worker; - assert(!global_worker); + LTTNG_ASSERT(!global_worker); if (!use_clone()) { /* * Don't initialize a worker, all run_as tasks will be performed @@ -1642,7 +1641,7 @@ int run_as(enum run_as_cmd cmd, struct run_as_data *data, if (use_clone()) { DBG("Using run_as worker"); - assert(global_worker); + LTTNG_ASSERT(global_worker); ret = run_as_cmd(global_worker, cmd, data, ret_value, uid, gid); saved_errno = ret_value->_errno; @@ -1669,13 +1668,11 @@ err: return ret; } -LTTNG_HIDDEN int run_as_mkdir_recursive(const char *path, mode_t mode, uid_t uid, gid_t gid) { return run_as_mkdirat_recursive(AT_FDCWD, path, mode, uid, gid); } -LTTNG_HIDDEN int run_as_mkdirat_recursive(int dirfd, const char *path, mode_t mode, uid_t uid, gid_t gid) { @@ -1703,13 +1700,11 @@ error: return ret; } -LTTNG_HIDDEN int run_as_mkdir(const char *path, mode_t mode, uid_t uid, gid_t gid) { return run_as_mkdirat(AT_FDCWD, path, mode, uid, gid); } -LTTNG_HIDDEN int run_as_mkdirat(int dirfd, const char *path, mode_t mode, uid_t uid, gid_t gid) { @@ -1737,14 +1732,12 @@ error: return ret; } -LTTNG_HIDDEN int run_as_open(const char *path, int flags, mode_t mode, uid_t uid, gid_t gid) { return run_as_openat(AT_FDCWD, path, flags, mode, uid, gid); } -LTTNG_HIDDEN int run_as_openat(int dirfd, const char *path, int flags, mode_t mode, uid_t uid, gid_t gid) { @@ -1772,13 +1765,11 @@ error: return ret; } -LTTNG_HIDDEN int run_as_unlink(const char *path, uid_t uid, gid_t gid) { return run_as_unlinkat(AT_FDCWD, path, uid, gid); } -LTTNG_HIDDEN int run_as_unlinkat(int dirfd, const char *path, uid_t uid, gid_t gid) { int ret; @@ -1802,13 +1793,11 @@ error: return ret; } -LTTNG_HIDDEN int run_as_rmdir(const char *path, uid_t uid, gid_t gid) { return run_as_rmdirat(AT_FDCWD, path, uid, gid); } -LTTNG_HIDDEN int run_as_rmdirat(int dirfd, const char *path, uid_t uid, gid_t gid) { int ret; @@ -1832,13 +1821,11 @@ error: return ret; } -LTTNG_HIDDEN int run_as_rmdir_recursive(const char *path, uid_t uid, gid_t gid, int flags) { return run_as_rmdirat_recursive(AT_FDCWD, path, uid, gid, flags); } -LTTNG_HIDDEN int run_as_rmdirat_recursive(int dirfd, const char *path, uid_t uid, gid_t gid, int flags) { int ret; @@ -1863,13 +1850,11 @@ error: return ret; } -LTTNG_HIDDEN int run_as_rename(const char *old, const char *new, uid_t uid, gid_t gid) { return run_as_renameat(AT_FDCWD, old, AT_FDCWD, new, uid, gid); } -LTTNG_HIDDEN int run_as_renameat(int old_dirfd, const char *old_name, int new_dirfd, const char *new_name, uid_t uid, gid_t gid) { @@ -1904,7 +1889,6 @@ error: return ret; } -LTTNG_HIDDEN int run_as_extract_elf_symbol_offset(int fd, const char* function, uid_t uid, gid_t gid, uint64_t *offset) { @@ -1939,7 +1923,6 @@ error: return ret; } -LTTNG_HIDDEN int run_as_extract_sdt_probe_offsets(int fd, const char* provider_name, const char* probe_name, uid_t uid, gid_t gid, uint64_t **offsets, uint32_t *num_offset) @@ -1986,7 +1969,6 @@ error: return ret; } -LTTNG_HIDDEN int run_as_generate_filter_bytecode(const char *filter_expression, const struct lttng_credentials *creds, struct lttng_bytecode **bytecode) @@ -2030,7 +2012,6 @@ error: return ret; } -LTTNG_HIDDEN int run_as_create_worker(const char *procname, post_fork_cleanup_cb clean_up_func, void *clean_up_user_data) @@ -2044,7 +2025,6 @@ int run_as_create_worker(const char *procname, return ret; } -LTTNG_HIDDEN void run_as_destroy_worker(void) { pthread_mutex_lock(&worker_lock);