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 | |
| 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')
| -rw-r--r-- | runit/Kbuild | 2 | ||||
| -rw-r--r-- | runit/chpst.c | 46 | ||||
| -rw-r--r-- | runit/uidgid.c | 63 | ||||
| -rw-r--r-- | runit/uidgid.h | 14 |
4 files changed, 17 insertions, 108 deletions
diff --git a/runit/Kbuild b/runit/Kbuild index 9fee84224..39a9b0229 100644 --- a/runit/Kbuild +++ b/runit/Kbuild | |||
| @@ -5,4 +5,4 @@ | |||
| 5 | # Licensed under the GPL v2, see the file LICENSE in this tarball. | 5 | # Licensed under the GPL v2, see the file LICENSE in this tarball. |
| 6 | 6 | ||
| 7 | lib-y:= | 7 | lib-y:= |
| 8 | lib-$(CONFIG_CHPST) += chpst.o uidgid.o | 8 | lib-$(CONFIG_CHPST) += chpst.o |
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 | } |
diff --git a/runit/uidgid.c b/runit/uidgid.c deleted file mode 100644 index a8fec409d..000000000 --- a/runit/uidgid.c +++ /dev/null | |||
| @@ -1,63 +0,0 @@ | |||
| 1 | #include <sys/types.h> | ||
| 2 | #include <pwd.h> | ||
| 3 | #include <grp.h> | ||
| 4 | #include "uidgid.h" | ||
| 5 | |||
| 6 | static unsigned str_chr(const char *s, int c) | ||
| 7 | { | ||
| 8 | const char *t = s; | ||
| 9 | while (t[0] && t[0] != (char)c) | ||
| 10 | t++; | ||
| 11 | return t - s; | ||
| 12 | } | ||
| 13 | |||
| 14 | |||
| 15 | unsigned uidgid_get(struct uidgid *u, char *ug, unsigned dogrp) { | ||
| 16 | char *g = 0; | ||
| 17 | struct passwd *pwd = 0; | ||
| 18 | struct group *gr = 0; | ||
| 19 | int i, d = 0; | ||
| 20 | |||
| 21 | if (dogrp) | ||
| 22 | d = str_chr(ug, ':'); | ||
| 23 | if (ug[d] == ':') { | ||
| 24 | ug[d] = 0; | ||
| 25 | g = ug + d + 1; | ||
| 26 | } | ||
| 27 | pwd = getpwnam(ug); | ||
| 28 | if (!pwd) { | ||
| 29 | if (g) ug[d] = ':'; | ||
| 30 | return 0; | ||
| 31 | } | ||
| 32 | if (g) { | ||
| 33 | ug[d] = ':'; | ||
| 34 | for (i = 0; i < 60; ++i) { | ||
| 35 | d = str_chr(g, ':'); | ||
| 36 | if (g[d] == ':') { | ||
| 37 | g[d] = 0; | ||
| 38 | gr = getgrnam(g); | ||
| 39 | if (!gr) { | ||
| 40 | g[d] = ':'; | ||
| 41 | return 0; | ||
| 42 | } | ||
| 43 | g[d] = ':'; | ||
| 44 | u->gid[i] = gr->gr_gid; | ||
| 45 | g += d+1; | ||
| 46 | } | ||
| 47 | else { | ||
| 48 | gr = getgrnam(g); | ||
| 49 | if (!gr) return 0; | ||
| 50 | u->gid[i++] = gr->gr_gid; | ||
| 51 | break; | ||
| 52 | } | ||
| 53 | } | ||
| 54 | u->gid[i] = 0; | ||
| 55 | u->gids = i; | ||
| 56 | } | ||
| 57 | if (!g) { | ||
| 58 | u->gid[0] = pwd->pw_gid; | ||
| 59 | u->gids = 1; | ||
| 60 | } | ||
| 61 | u->uid = pwd->pw_uid; | ||
| 62 | return 1; | ||
| 63 | } | ||
diff --git a/runit/uidgid.h b/runit/uidgid.h deleted file mode 100644 index 1d47fe620..000000000 --- a/runit/uidgid.h +++ /dev/null | |||
| @@ -1,14 +0,0 @@ | |||
| 1 | #ifndef UIDGID_H | ||
| 2 | #define UIDGID_H | ||
| 3 | |||
| 4 | #include <sys/types.h> | ||
| 5 | |||
| 6 | struct uidgid { | ||
| 7 | uid_t uid; | ||
| 8 | gid_t gid[61]; | ||
| 9 | int gids; | ||
| 10 | }; | ||
| 11 | |||
| 12 | extern unsigned uidgid_get(struct uidgid *, char *, unsigned); | ||
| 13 | |||
| 14 | #endif | ||
