diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2006-10-05 22:50:22 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2006-10-05 22:50:22 +0000 |
commit | de59c0f58fa5dc75b753f94da61be92bfa0935ec (patch) | |
tree | fea308471e3d73fb6770ff6e4cda23da53b65bec /runit/chpst.c | |
parent | 01c27fc5ac89b07821a5430880d771e3c993c1c1 (diff) | |
download | busybox-w32-de59c0f58fa5dc75b753f94da61be92bfa0935ec.tar.gz busybox-w32-de59c0f58fa5dc75b753f94da61be92bfa0935ec.tar.bz2 busybox-w32-de59c0f58fa5dc75b753f94da61be92bfa0935ec.zip |
httpd: add -u user[:grp] support
Diffstat (limited to 'runit/chpst.c')
-rw-r--r-- | runit/chpst.c | 46 |
1 files changed, 16 insertions, 30 deletions
diff --git a/runit/chpst.c b/runit/chpst.c index 1ee9b8d0f..da2f270e2 100644 --- a/runit/chpst.c +++ b/runit/chpst.c | |||
@@ -1,16 +1,9 @@ | |||
1 | #include "busybox.h" | 1 | #include "busybox.h" |
2 | 2 | ||
3 | #include <sys/types.h> | ||
4 | #include <sys/resource.h> | ||
5 | #include <grp.h> | ||
6 | |||
7 | #include "uidgid.h" | ||
8 | |||
9 | #include <sys/types.h> | ||
10 | #include <dirent.h> | 3 | #include <dirent.h> |
11 | 4 | ||
12 | static unsigned option_mask; | 5 | static unsigned option_mask; |
13 | // Must meatch constants in chpst_main! | 6 | // Must match constants in chpst_main! |
14 | #define OPT_verbose (option_mask & 0x2000) | 7 | #define OPT_verbose (option_mask & 0x2000) |
15 | #define OPT_pgrp (option_mask & 0x4000) | 8 | #define OPT_pgrp (option_mask & 0x4000) |
16 | #define OPT_nostdin (option_mask & 0x8000) | 9 | #define OPT_nostdin (option_mask & 0x8000) |
@@ -33,34 +26,27 @@ static long limitt = -2; | |||
33 | static long nicelvl; | 26 | static long nicelvl; |
34 | static const char *root; | 27 | static const char *root; |
35 | 28 | ||
36 | static void suidgid(char *user, unsigned dogrp) | 29 | static void suidgid(char *user) |
37 | { | 30 | { |
38 | struct uidgid ugid; | 31 | struct bb_uidgid_t ugid; |
39 | 32 | ||
40 | if (!uidgid_get(&ugid, user, dogrp)) { | 33 | if (!uidgid_get(&ugid, user)) { |
41 | if (dogrp) | 34 | bb_error_msg_and_die("unknown user/group: %s", user); |
42 | bb_error_msg_and_die("unknown user/group: %s", user); | ||
43 | else | ||
44 | bb_error_msg_and_die("unknown account: %s", user); | ||
45 | } | 35 | } |
46 | if (setgroups(ugid.gids, ugid.gid) == -1) | 36 | if (setgroups(1, &ugid.gid) == -1) |
47 | bb_perror_msg_and_die("setgroups"); | 37 | bb_perror_msg_and_die("setgroups"); |
48 | xsetgid(*ugid.gid); | 38 | xsetgid(ugid.gid); |
49 | xsetuid(ugid.uid); | 39 | xsetuid(ugid.uid); |
50 | } | 40 | } |
51 | 41 | ||
52 | static void euidgid(char *user, unsigned dogrp) | 42 | static void euidgid(char *user) |
53 | { | 43 | { |
54 | struct uidgid ugid; | 44 | struct bb_uidgid_t ugid; |
55 | 45 | ||
56 | if (!uidgid_get(&ugid, user, dogrp)) { | 46 | if (!uidgid_get(&ugid, user)) { |
57 | if (dogrp) | 47 | bb_error_msg_and_die("unknown user/group: %s", user); |
58 | bb_error_msg_and_die("unknown user/group: %s", user); | ||
59 | else | ||
60 | bb_error_msg_and_die("unknown account: %s", user); | ||
61 | } | 48 | } |
62 | //FIXME: ultoa needed here! | 49 | xsetenv("GID", utoa(ugid.gid)); |
63 | xsetenv("GID", utoa(*ugid.gid)); | ||
64 | xsetenv("UID", utoa(ugid.uid)); | 50 | xsetenv("UID", utoa(ugid.uid)); |
65 | } | 51 | } |
66 | 52 | ||
@@ -276,8 +262,8 @@ int chpst_main(int argc, char **argv) | |||
276 | if (nice(nicelvl) == -1) | 262 | if (nice(nicelvl) == -1) |
277 | bb_perror_msg_and_die("nice"); | 263 | bb_perror_msg_and_die("nice"); |
278 | } | 264 | } |
279 | if (env_user) euidgid(env_user, 1); | 265 | if (env_user) euidgid(env_user); |
280 | if (set_user) suidgid(set_user, 1); | 266 | if (set_user) suidgid(set_user); |
281 | if (OPT_nostdin) close(0); | 267 | if (OPT_nostdin) close(0); |
282 | if (OPT_nostdout) close(1); | 268 | if (OPT_nostdout) close(1); |
283 | if (OPT_nostderr) close(2); | 269 | if (OPT_nostderr) close(2); |
@@ -292,7 +278,7 @@ static void setuidgid(int argc, char **argv) | |||
292 | account = *++argv; | 278 | account = *++argv; |
293 | if (!account) bb_show_usage(); | 279 | if (!account) bb_show_usage(); |
294 | if (!*++argv) bb_show_usage(); | 280 | if (!*++argv) bb_show_usage(); |
295 | suidgid((char*)account, 0); | 281 | suidgid((char*)account); |
296 | execvp(argv[0], argv); | 282 | execvp(argv[0], argv); |
297 | bb_perror_msg_and_die("exec %s", argv[0]); | 283 | bb_perror_msg_and_die("exec %s", argv[0]); |
298 | } | 284 | } |
@@ -304,7 +290,7 @@ static void envuidgid(int argc, char **argv) | |||
304 | account = *++argv; | 290 | account = *++argv; |
305 | if (!account) bb_show_usage(); | 291 | if (!account) bb_show_usage(); |
306 | if (!*++argv) bb_show_usage(); | 292 | if (!*++argv) bb_show_usage(); |
307 | euidgid((char*)account, 0); | 293 | euidgid((char*)account); |
308 | execvp(argv[0], argv); | 294 | execvp(argv[0], argv); |
309 | bb_perror_msg_and_die("exec %s", argv[0]); | 295 | bb_perror_msg_and_die("exec %s", argv[0]); |
310 | } | 296 | } |