user: better check for uids/gids existence
authorRobert Swiecki <robert@swiecki.net>
Sat, 27 May 2017 23:16:48 +0000 (01:16 +0200)
committerRobert Swiecki <robert@swiecki.net>
Sat, 27 May 2017 23:16:48 +0000 (01:16 +0200)
user.c

diff --git a/user.c b/user.c
index 1fe8dd682d03abe326f7dc07262f07edb4487a64..d4d707434b5cbdf2e555fb4641a2f1968eed380a 100644 (file)
--- a/user.c
+++ b/user.c
@@ -131,6 +131,7 @@ static bool userGidMapExternal(struct nsjconf_t *nsjconf, pid_t pid UNUSED)
        idx++;
 
        struct idmap_t *p;
+       bool use = false;
        TAILQ_FOREACH(p, &nsjconf->gids, pointers) {
                if (p->is_newidmap == false) {
                        continue;
@@ -139,6 +140,7 @@ static bool userGidMapExternal(struct nsjconf_t *nsjconf, pid_t pid UNUSED)
                        LOG_W("Number of arguments to '/usr/bin/newgidmap' too big");
                        return false;
                }
+               use = true;
 
                snprintf(parms[idx], sizeof(parms[idx]), "%u", (unsigned)p->inside_id);
                argv[idx] = parms[idx];
@@ -155,7 +157,7 @@ static bool userGidMapExternal(struct nsjconf_t *nsjconf, pid_t pid UNUSED)
 
        argv[idx] = NULL;
 
-       if (idx < 4) {
+       if (!use) {
                return true;
        }
 
@@ -181,6 +183,7 @@ static bool userUidMapExternal(struct nsjconf_t *nsjconf, pid_t pid UNUSED)
        argv[idx] = parms[idx];
        idx++;
 
+       bool use = false;
        struct idmap_t *p;
        TAILQ_FOREACH(p, &nsjconf->uids, pointers) {
                if (p->is_newidmap == false) {
@@ -190,6 +193,7 @@ static bool userUidMapExternal(struct nsjconf_t *nsjconf, pid_t pid UNUSED)
                        LOG_W("Number of arguments to '/usr/bin/newuidmap' too big");
                        return false;
                }
+               use = true;
 
                snprintf(parms[idx], sizeof(parms[idx]), "%u", (unsigned)p->inside_id);
                argv[idx] = parms[idx];
@@ -206,7 +210,7 @@ static bool userUidMapExternal(struct nsjconf_t *nsjconf, pid_t pid UNUSED)
 
        argv[idx] = NULL;
 
-       if (idx < 4) {
+       if (!use) {
                return true;
        }