diff options
-rw-r--r-- | INSTALL | 4 | ||||
-rw-r--r-- | doc/index.html | 6 | ||||
-rw-r--r-- | doc/upgrade.html | 8 | ||||
-rw-r--r-- | package/info | 2 | ||||
-rw-r--r-- | src/daemontools-extras/s6-envuidgid.c | 89 |
5 files changed, 79 insertions, 30 deletions
@@ -6,8 +6,8 @@ Build Instructions - A POSIX-compliant C development environment - GNU make version 4.0 or later - - skalibs version 2.3.1.0 or later: http://skarnet.org/software/skalibs/ - - execline version 2.1.0.0 or later: http://skarnet.org/software/execline/ + - skalibs version 2.3.2.0 or later: http://skarnet.org/software/skalibs/ + - execline version 2.1.1.0 or later: http://skarnet.org/software/execline/ This software will run on any operating system that implements POSIX.1-2008, available at: diff --git a/doc/index.html b/doc/index.html index f4f4add..ed62e41 100644 --- a/doc/index.html +++ b/doc/index.html @@ -82,11 +82,11 @@ with s6</a> </li> <li> GNU make, version 4.0 or later. Please be aware that s6 will not build with an earlier version. </li> <li> <a href="http://skarnet.org/software/skalibs/">skalibs</a> version -2.3.1.0 or later. It's a build-time requirement. It's also a run-time +2.3.2.0 or later. It's a build-time requirement. It's also a run-time requirement if you link against the shared version of the skalibs library. </li> <li> <a href="http://skarnet.org/software/execline/">execline</a> version -2.1.0.0 or later. It's a build-time and run-time requirement. </li> +2.1.1.0 or later. It's a build-time and run-time requirement. </li> </ul> <h3> Licensing </h3> @@ -99,7 +99,7 @@ library. </li> <h3> Download </h3> <ul> - <li> The current released version of s6 is <a href="s6-2.1.2.0.tar.gz">2.1.2.0</a>. </li> + <li> The current released version of s6 is <a href="s6-2.1.3.0.tar.gz">2.1.3.0</a>. </li> <li> Alternatively, you can checkout a copy of the s6 git repository: <pre> git clone git://git.skarnet.org/s6 </pre> </li> </ul> diff --git a/doc/upgrade.html b/doc/upgrade.html index 0777b51..e2477a3 100644 --- a/doc/upgrade.html +++ b/doc/upgrade.html @@ -17,6 +17,14 @@ <h1> What has changed in s6 </h1> +<h2> in 2.1.3.0 </h2> + +<ul> + <li> skalibs dependency bumped to 2.3.2.0. </li> + <li> execline dependency bumped to 2.1.1.0. </li> + <li> New options to <a href="s6-envuidgid.html">s6-envuidgid</a>. </li> +</ul> + <h2> in 2.1.2.0 </h2> <ul> diff --git a/package/info b/package/info index 3993f04..97e35d3 100644 --- a/package/info +++ b/package/info @@ -1,4 +1,4 @@ package=s6 -version=2.1.2.0 +version=2.1.3.0 category=admin package_macro_name=S6 diff --git a/src/daemontools-extras/s6-envuidgid.c b/src/daemontools-extras/s6-envuidgid.c index 64521b0..3a58c3c 100644 --- a/src/daemontools-extras/s6-envuidgid.c +++ b/src/daemontools-extras/s6-envuidgid.c @@ -3,42 +3,83 @@ #include <sys/types.h> #include <pwd.h> #include <limits.h> +#include <skalibs/uint64.h> #include <skalibs/gidstuff.h> -#include <skalibs/env.h> +#include <skalibs/bytestr.h> +#include <skalibs/sgetopt.h> #include <skalibs/strerr2.h> +#include <skalibs/env.h> #include <skalibs/fmtscan.h> #include <skalibs/djbunix.h> -#define USAGE "s6-envuidgid username prog..." +#define USAGE "s6-envuidgid [ -i | -D defaultuid:defaultgid ] username prog..." +#define dieusage() strerr_dieusage(100, USAGE) int main (int argc, char const *const *argv, char const *const *envp) { + struct passwd *pw ; + uint64 uid ; + gid_t gid ; + gid_t tab[NGROUPS_MAX] ; + int n = 0 ; + int insist = 1 ; PROG = "s6-envuidgid" ; - if (argc < 3) strerr_dieusage(100, USAGE) ; { - char fmt[UINT64_FMT] ; - struct passwd *pw = getpwnam(argv[1]) ; - if (!pw) strerr_dief2x(1, "unknown user: ", argv[1]) ; - fmt[gid_fmt(fmt, pw->pw_gid)] = 0 ; - if (!pathexec_env("GID", fmt)) - strerr_diefu1sys(111, "update environment") ; - fmt[uint64_fmt(fmt, pw->pw_uid)] = 0 ; - if (!pathexec_env("UID", fmt)) - strerr_diefu1sys(111, "update environment") ; + subgetopt_t l = SUBGETOPT_ZERO ; + for (;;) + { + register int opt = subgetopt_r(argc, argv, "iD:", &l) ; + if (opt == -1) break ; + switch (opt) + { + case 'i' : insist = 1 ; break ; + case 'D' : + { + unsigned int pos = uint64_scan(l.arg, &uid) ; + if (!pos) + { + if (l.arg[pos] != ':') dieusage() ; + uid = 0 ; + } + if (!l.arg[pos]) gid = 0 ; + else + { + if (l.arg[pos++] != ':') dieusage() ; + if (!l.arg[pos]) gid = 0 ; + else if (!gid0_scan(l.arg + pos, &gid)) dieusage() ; + } + insist = 0 ; + break ; + } + default : dieusage() ; + } + } + argc -= l.ind ; argv += l.ind ; } - + if (argc < 2) dieusage() ; + + pw = getpwnam(argv[0]) ; + if (pw) { - gid_t tab[NGROUPS_MAX] ; - int n = prot_readgroups(argv[1], tab, NGROUPS_MAX) ; + uid = pw->pw_uid ; + gid = pw->pw_gid ; + n = prot_readgroups(argv[0], tab, NGROUPS_MAX) ; if (n < 0) - strerr_diefu2sys(111, "get supplementary groups for ", argv[1]) ; - { - char fmt[GID_FMT * n] ; - fmt[gid_fmtlist(fmt, tab, n)] = 0 ; - if (!pathexec_env("GIDLIST", fmt)) - strerr_diefu1sys(111, "update environment") ; - } + strerr_diefu2sys(111, "get supplementary groups for ", argv[0]) ; + } + else if (insist) strerr_dief2x(1, "unknown user: ", argv[1]) ; + + { + unsigned int pos = 0 ; + char fmt[19 + UINT64_FMT + (n+1) * GID_FMT] ; + byte_copy(fmt + pos, 4, "UID=") ; pos += 4 ; + pos += uint64_fmt(fmt + pos, uid) ; + byte_copy(fmt + pos, 5, "\0GID=") ; pos += 5 ; + pos += gid_fmt(fmt + pos, gid) ; + byte_copy(fmt + pos, 9, "\0GIDLIST=") ; pos += 9 ; + pos += gid_fmtlist(fmt + pos, tab, n) ; + fmt[pos++] = 0 ; + pathexec_r(argv+1, envp, env_len(envp), fmt, pos) ; } - pathexec_fromenv(argv+2, envp, env_len(envp)) ; - strerr_dieexec(111, argv[2]) ; + strerr_dieexec(111, argv[1]) ; } |