summaryrefslogtreecommitdiff
path: root/src/daemontools-extras/s6-applyuidgid.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/daemontools-extras/s6-applyuidgid.c')
-rw-r--r--src/daemontools-extras/s6-applyuidgid.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/daemontools-extras/s6-applyuidgid.c b/src/daemontools-extras/s6-applyuidgid.c
index 31dc198..b80564f 100644
--- a/src/daemontools-extras/s6-applyuidgid.c
+++ b/src/daemontools-extras/s6-applyuidgid.c
@@ -5,7 +5,7 @@
#include <unistd.h>
#include <grp.h>
#include <limits.h>
-#include <skalibs/uint.h>
+#include <skalibs/uint64.h>
#include <skalibs/gidstuff.h>
#include <skalibs/setgroups.h>
#include <skalibs/strerr2.h>
@@ -18,7 +18,8 @@
int main (int argc, char const *const *argv, char const *const *envp)
{
- unsigned int uid = 0, gid = 0 ;
+ uint64 uid = 0 ;
+ gid_t gid = 0 ;
gid_t gids[NGROUPS_MAX] ;
unsigned int gidn = (unsigned int)-1 ;
int unexport = 0 ;
@@ -32,17 +33,17 @@ int main (int argc, char const *const *argv, char const *const *envp)
switch (opt)
{
case 'z' : unexport = 1 ; break ;
- case 'u' : if (!uint0_scan(l.arg, &uid)) dieusage() ; break ;
- case 'g' : if (!uint0_scan(l.arg, &gid)) dieusage() ; break ;
+ case 'u' : if (!uint640_scan(l.arg, &uid)) dieusage() ; break ;
+ case 'g' : if (!gid0_scan(l.arg, &gid)) dieusage() ; break ;
case 'G' : if (!gid_scanlist(gids, NGROUPS_MAX, l.arg, &gidn) && *l.arg) dieusage() ; break ;
case 'U' :
{
char const *x = env_get2(envp, "UID") ;
if (!x) strerr_dienotset(100, "UID") ;
- if (!uint0_scan(x, &uid)) strerr_dieinvalid(100, "UID") ;
+ if (!uint640_scan(x, &uid)) strerr_dieinvalid(100, "UID") ;
x = env_get2(envp, "GID") ;
if (!x) strerr_dienotset(100, "GID") ;
- if (!uint0_scan(x, &gid)) strerr_dieinvalid(100, "GID") ;
+ if (!gid0_scan(x, &gid)) strerr_dieinvalid(100, "GID") ;
x = env_get2(envp, "GIDLIST") ;
if (!x) strerr_dienotset(100, "GIDLIST") ;
if (!gid_scanlist(gids, NGROUPS_MAX, x, &gidn) && *x)
@@ -56,11 +57,12 @@ int main (int argc, char const *const *argv, char const *const *envp)
}
if (!argc) dieusage() ;
+ if (uid > (uint64)(uid_t)-1) strerr_dief1x(100, "uid value too big") ;
if (gidn != (unsigned int)-1 && setgroups(gidn, gids) < 0)
strerr_diefu1sys(111, "set supplementary group list") ;
if (gid && setgid(gid) < 0)
strerr_diefu1sys(111, "setgid") ;
- if (uid && setuid(uid) < 0)
+ if (uid && setuid((uid_t)uid) < 0)
strerr_diefu1sys(111, "setuid") ;
if (unexport) pathexec_r(argv, envp, env_len(envp), "UID\0GID\0GIDLIST", 16) ;