diff options
author | Jeremie Koenig <jk@jk.fr.eu.org> | 2010-08-23 11:02:13 +0000 |
---|---|---|
committer | Jeremie Koenig <jk@jk.fr.eu.org> | 2010-08-30 14:29:53 +0200 |
commit | fa82e6672499e2fb5a4191c567c6a418d1f88405 (patch) | |
tree | 07b09d02571162c0788885b8bb97d0dd1cb17e62 | |
parent | 687c9658628eb044be75df8074c5983e865b6394 (diff) |
Fix the handling of processes without an owner
* main.c (argp_parser): New option --anonymous-owner.
* main.h: Publish it.
* process.c (process_lookup_pid): Use it to set the file owner
uid of non-owned processes.
-rw-r--r-- | main.c | 22 | ||||
-rw-r--r-- | main.h | 1 | ||||
-rw-r--r-- | process.c | 4 |
3 files changed, 26 insertions, 1 deletions
@@ -16,10 +16,12 @@ int opt_clk_tck; mode_t opt_stat_mode; pid_t opt_fake_self; pid_t opt_kernel_pid; +uid_t opt_anon_owner; static error_t argp_parser (int key, char *arg, struct argp_state *state) { + struct passwd *pw; char *endp; switch (key) @@ -58,6 +60,20 @@ argp_parser (int key, char *arg, struct argp_state *state) opt_stat_mode = 0444; opt_fake_self = 1; break; + + case 'a': + pw = getpwnam (arg); + if (pw) + { + opt_anon_owner = pw->pw_uid; + break; + } + + opt_anon_owner = strtol (arg, &endp, 0); + if (*endp || ! *arg || (signed) opt_anon_owner < 0) + error(1, 0, "--anonymous-owner: USER should be the a user name " + "or a numeric UID."); + break; } return 0; @@ -84,6 +100,11 @@ struct argp argp = { { "compatible", 'c', NULL, 0, "Try to be compatible with the Linux procps utilities. " "Currently equivalent to -h 100 -s 0444 -S 1." }, + { "anonymous-owner", 'a', "USER", 0, + "Make USER the owner of files related to processes without one. " + "Be aware that USER will be granted access to the environment and " + "other sensitive information about the processes in question. " + "(default: use uid 0)" }, {} }, .parser = argp_parser, @@ -138,6 +159,7 @@ int main (int argc, char **argv) opt_stat_mode = 0400; opt_fake_self = -1; opt_kernel_pid = 2; + opt_anon_owner = 0; err = argp_parse (&argp, argc, argv, 0, 0, 0); if (err) error (1, err, "Could not parse command line"); @@ -3,3 +3,4 @@ extern int opt_clk_tck; extern mode_t opt_stat_mode; extern pid_t opt_fake_self; extern pid_t opt_kernel_pid; +extern uid_t opt_anon_owner; @@ -314,6 +314,7 @@ error_t process_lookup_pid (struct ps_context *pc, pid_t pid, struct node **np) { struct proc_stat *ps; + int owner; error_t err; err = _proc_stat_create (pid, pc, &ps); @@ -334,6 +335,7 @@ process_lookup_pid (struct ps_context *pc, pid_t pid, struct node **np) if (! *np) return ENOMEM; - procfs_node_chown (*np, proc_stat_owner_uid (ps)); + owner = proc_stat_owner_uid (ps); + procfs_node_chown (*np, owner >= 0 ? owner : opt_anon_owner); return 0; } |