aboutsummaryrefslogtreecommitdiff
path: root/networking/httpd.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2006-10-05 22:50:22 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2006-10-05 22:50:22 +0000
commitde59c0f58fa5dc75b753f94da61be92bfa0935ec (patch)
treefea308471e3d73fb6770ff6e4cda23da53b65bec /networking/httpd.c
parent01c27fc5ac89b07821a5430880d771e3c993c1c1 (diff)
downloadbusybox-w32-de59c0f58fa5dc75b753f94da61be92bfa0935ec.tar.gz
busybox-w32-de59c0f58fa5dc75b753f94da61be92bfa0935ec.tar.bz2
busybox-w32-de59c0f58fa5dc75b753f94da61be92bfa0935ec.zip
httpd: add -u user[:grp] support
Diffstat (limited to 'networking/httpd.c')
-rw-r--r--networking/httpd.c30
1 files changed, 22 insertions, 8 deletions
diff --git a/networking/httpd.c b/networking/httpd.c
index ac9eac6bf..8f985774e 100644
--- a/networking/httpd.c
+++ b/networking/httpd.c
@@ -1916,8 +1916,8 @@ int httpd_main(int argc, char *argv[])
1916 USE_FEATURE_HTTPD_WITHOUT_INETD(const char *s_port;) 1916 USE_FEATURE_HTTPD_WITHOUT_INETD(const char *s_port;)
1917 USE_FEATURE_HTTPD_WITHOUT_INETD(int server;) 1917 USE_FEATURE_HTTPD_WITHOUT_INETD(int server;)
1918 1918
1919 USE_FEATURE_HTTPD_SETUID(const char *s_uid;) 1919 USE_FEATURE_HTTPD_SETUID(const char *s_ugid = NULL;)
1920 USE_FEATURE_HTTPD_SETUID(long uid = -1;) 1920 USE_FEATURE_HTTPD_SETUID(struct bb_uidgid_t ugid;)
1921 1921
1922 USE_FEATURE_HTTPD_AUTH_MD5(const char *pass;) 1922 USE_FEATURE_HTTPD_AUTH_MD5(const char *pass;)
1923 1923
@@ -1937,7 +1937,7 @@ int httpd_main(int argc, char *argv[])
1937 USE_FEATURE_HTTPD_ENCODE_URL_STR(, &url_for_encode) 1937 USE_FEATURE_HTTPD_ENCODE_URL_STR(, &url_for_encode)
1938 USE_FEATURE_HTTPD_BASIC_AUTH(, &(config->realm)) 1938 USE_FEATURE_HTTPD_BASIC_AUTH(, &(config->realm))
1939 USE_FEATURE_HTTPD_AUTH_MD5(, &pass) 1939 USE_FEATURE_HTTPD_AUTH_MD5(, &pass)
1940 USE_FEATURE_HTTPD_SETUID(, &s_uid) 1940 USE_FEATURE_HTTPD_SETUID(, &s_ugid)
1941 USE_FEATURE_HTTPD_WITHOUT_INETD(, &s_port) 1941 USE_FEATURE_HTTPD_WITHOUT_INETD(, &s_port)
1942 ); 1942 );
1943 1943
@@ -1963,11 +1963,18 @@ int httpd_main(int argc, char *argv[])
1963#if ENABLE_FEATURE_HTTPD_SETUID 1963#if ENABLE_FEATURE_HTTPD_SETUID
1964 if (opt & OPT_SETUID) { 1964 if (opt & OPT_SETUID) {
1965 char *e; 1965 char *e;
1966 1966 // FIXME: what the default group should be?
1967 uid = strtol(s_uid, &e, 0); 1967 ugid.gid = -1;
1968 ugid.uid = strtoul(s_ugid, &e, 0);
1969 if (*e == ':') {
1970 e++;
1971 ugid.gid = strtoul(e, &e, 0);
1972 }
1968 if (*e != '\0') { 1973 if (*e != '\0') {
1969 /* not integer */ 1974 /* not integer */
1970 uid = bb_xgetpwnam(s_uid); 1975 if (!uidgid_get(&ugid, s_ugid))
1976 bb_error_msg_and_die("unrecognized user[:group] "
1977 "name '%s'", s_ugid);
1971 } 1978 }
1972 } 1979 }
1973#endif 1980#endif
@@ -1978,8 +1985,15 @@ int httpd_main(int argc, char *argv[])
1978 server = openServer(); 1985 server = openServer();
1979# ifdef CONFIG_FEATURE_HTTPD_SETUID 1986# ifdef CONFIG_FEATURE_HTTPD_SETUID
1980 /* drop privileges */ 1987 /* drop privileges */
1981 if (uid > 0) 1988 if (opt & OPT_SETUID) {
1982 xsetuid(uid); 1989 if (ugid.gid != (gid_t)-1) {
1990 // FIXME: needed?
1991 //if (setgroups(1, &ugid.gid) == -1)
1992 // bb_perror_msg_and_die("setgroups");
1993 xsetgid(ugid.gid);
1994 }
1995 xsetuid(ugid.uid);
1996 }
1983# endif 1997# endif
1984#endif 1998#endif
1985 1999