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 /libpwdgrp | |
parent | 01c27fc5ac89b07821a5430880d771e3c993c1c1 (diff) | |
download | busybox-de59c0f58fa5dc75b753f94da61be92bfa0935ec.tar.gz |
httpd: add -u user[:grp] support
Diffstat (limited to 'libpwdgrp')
-rw-r--r-- | libpwdgrp/Kbuild | 2 | ||||
-rw-r--r-- | libpwdgrp/uidgid_get.c | 49 |
2 files changed, 50 insertions, 1 deletions
diff --git a/libpwdgrp/Kbuild b/libpwdgrp/Kbuild index 36a6ce393..9e60ef1e5 100644 --- a/libpwdgrp/Kbuild +++ b/libpwdgrp/Kbuild @@ -4,4 +4,4 @@ # # Licensed under the GPL v2, see the file LICENSE in this tarball. -lib-y:=pwd_grp.o +lib-y:=pwd_grp.o uidgid_get.o diff --git a/libpwdgrp/uidgid_get.c b/libpwdgrp/uidgid_get.c new file mode 100644 index 000000000..a2d02a84f --- /dev/null +++ b/libpwdgrp/uidgid_get.c @@ -0,0 +1,49 @@ +#include "busybox.h" + +unsigned uidgid_get(struct bb_uidgid_t *u, const char *ug /*, unsigned dogrp */) +{ + struct passwd *pwd; + struct group *gr; + const char *g; + + /* g = 0; if (dogrp) g = strchr(ug, ':'); */ + g = strchr(ug, ':'); + if (g) { + int sz = (++g) - ug; + char buf[sz]; + safe_strncpy(buf, ug, sz); + pwd = getpwnam(buf); + } else + pwd = getpwnam(ug); + if (!pwd) + return 0; + u->uid = pwd->pw_uid; + u->gid = pwd->pw_gid; + if (g) { + gr = getgrnam(g); + if (!gr) return 0; + u->gid = gr->gr_gid; + } + return 1; +} + +#if 0 +#include <stdio.h> +int main() +{ + unsigned u; + struct bb_uidgid_t ug; + u = uidgid_get(&ug, "apache"); + printf("%u = %u:%u\n", u, ug.uid, ug.gid); + ug.uid = ug.gid = 1111; + u = uidgid_get(&ug, "apache"); + printf("%u = %u:%u\n", u, ug.uid, ug.gid); + ug.uid = ug.gid = 1111; + u = uidgid_get(&ug, "apache:users"); + printf("%u = %u:%u\n", u, ug.uid, ug.gid); + ug.uid = ug.gid = 1111; + u = uidgid_get(&ug, "apache:users"); + printf("%u = %u:%u\n", u, ug.uid, ug.gid); + return 0; +} +#endif |