return -EIO;
}
-int get_process_uid(pid_t pid, uid_t *ret) {
+int pid_get_uid(pid_t pid, uid_t *ret) {
+ assert(ret);
if (pid == 0 || pid == getpid_cached()) {
*ret = getuid();
return get_process_id(pid, "Uid:", ret);
}
+int pidref_get_uid(const PidRef *pid, uid_t *ret) {
+ uid_t uid;
+ int r;
+
+ if (!pidref_is_set(pid))
+ return -ESRCH;
+
+ r = pid_get_uid(pid->pid, &uid);
+ if (r < 0)
+ return r;
+
+ r = pidref_verify(pid);
+ if (r < 0)
+ return r;
+
+ if (ret)
+ *ret = uid;
+ return 0;
+}
+
int get_process_gid(pid_t pid, gid_t *ret) {
if (pid == 0 || pid == getpid_cached()) {
int pid_get_cmdline_strv(pid_t pid, ProcessCmdlineFlags flags, char ***ret);
int pidref_get_cmdline_strv(const PidRef *pid, ProcessCmdlineFlags flags, char ***ret);
int get_process_exe(pid_t pid, char **ret);
-int get_process_uid(pid_t pid, uid_t *ret);
+int pid_get_uid(pid_t pid, uid_t *ret);
+int pidref_get_uid(const PidRef *pid, uid_t *ret);
int get_process_gid(pid_t pid, gid_t *ret);
int get_process_capeff(pid_t pid, char **ret);
int get_process_cwd(pid_t pid, char **ret);
/* Let's validate security: if the sender is root, then all is OK. If the sender is any other unit,
* then the process' UID and the target unit's UID have to match the sender's UID */
if (sender_uid != 0 && sender_uid != getuid()) {
- r = get_process_uid(pidref->pid, &process_uid);
+ r = pidref_get_uid(pidref, &process_uid);
if (r < 0)
return sd_bus_error_set_errnof(error, r, "Failed to retrieve process UID: %m");
if (ucred && uid_is_valid(ucred->uid))
c->uid = ucred->uid;
else
- (void) get_process_uid(c->pid, &c->uid);
+ (void) pid_get_uid(c->pid, &c->uid);
if (ucred && gid_is_valid(ucred->gid))
c->gid = ucred->gid;
if (is_survivor_cgroup(pid))
return true;
- r = get_process_uid(pid, &uid);
+ r = pid_get_uid(pid, &uid);
if (r < 0)
return true; /* not really, but better safe than sorry */
assert_se(r >= 0 || r == -EACCES);
log_info("PID"PID_FMT" exe: '%s'", pid, strna(f));
- assert_se(get_process_uid(pid, &u) == 0);
+ assert_se(pid_get_uid(pid, &u) == 0);
log_info("PID"PID_FMT" UID: "UID_FMT, pid, u);
assert_se(get_process_gid(pid, &g) == 0);