]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
utils: make lxc_switch_uid_gid() return bool 2596/head
authorChristian Brauner <christian.brauner@ubuntu.com>
Sun, 9 Sep 2018 14:34:50 +0000 (16:34 +0200)
committerChristian Brauner <christian.brauner@ubuntu.com>
Tue, 11 Sep 2018 08:55:07 +0000 (10:55 +0200)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/attach.c
src/lxc/cmd/lxc_usernsexec.c
src/lxc/start.c
src/lxc/storage/rsync.c
src/lxc/utils.c
src/lxc/utils.h

index 951d3bb936b54631786201072cc8f465e8181b56..425f257e4239f1c0b7f7fe8ffc4843626e26100c 100644 (file)
@@ -854,8 +854,7 @@ static int attach_child_main(struct attach_clone_payload *payload)
                if (ns_root_uid == LXC_INVALID_UID)
                        goto on_error;
 
-               ret = lxc_switch_uid_gid(ns_root_uid, ns_root_gid);
-               if (ret < 0)
+               if (!lxc_switch_uid_gid(ns_root_uid, ns_root_gid))
                        goto on_error;
        }
 
@@ -969,8 +968,7 @@ static int attach_child_main(struct attach_clone_payload *payload)
        if (new_gid == ns_root_gid)
                new_gid = LXC_INVALID_GID;
 
-       ret = lxc_switch_uid_gid(new_uid, new_gid);
-       if (ret < 0)
+       if (!lxc_switch_uid_gid(new_uid, new_gid))
                goto on_error;
 
        /* We're done, so we can now do whatever the user intended us to do. */
index 0b698f86d13820468ad89a9056e66211ddcac122..e5b5d1f0196b564145bba4e26ee4a25ffa98b1b6 100644 (file)
@@ -104,8 +104,7 @@ static int do_child(void *vargv)
        char **argv = (char **)vargv;
 
        /* Assume we want to become root */
-       ret = lxc_switch_uid_gid(0, 0);
-       if (ret < 0)
+       if (!lxc_switch_uid_gid(0, 0))
                return -1;
 
        if (!lxc_setgroups(0, NULL))
index 8d0e2a1e6fe900d8850388b52c8b814ccc2ffcae..8d3a7ced5951891a19faf1166e11332a0652648d 100644 (file)
@@ -1124,8 +1124,7 @@ static int do_start(void *data)
                if (!handler->conf->root_nsgid_map)
                        nsgid = handler->conf->init_gid;
 
-               ret = lxc_switch_uid_gid(nsuid, nsgid);
-               if (ret < 0)
+               if (!lxc_switch_uid_gid(nsuid, nsgid))
                        goto out_warn_father;
 
                /* Drop groups only after we switched to a valid gid in the new
@@ -1362,8 +1361,7 @@ static int do_start(void *data)
        if (new_gid == nsgid)
                new_gid = LXC_INVALID_GID;
 
-       ret = lxc_switch_uid_gid(new_uid, new_gid);
-       if (ret < 0)
+       if (!lxc_switch_uid_gid(new_uid, new_gid))
                goto out_warn_father;
 
        /* If we are in a new user namespace we already dropped all groups when
index e53a538dba1c2105477b0d09103f83faffd78a4f..ca2da186ebaed42eec28645282e2358b626883ab 100644 (file)
@@ -50,8 +50,7 @@ int lxc_rsync_exec_wrapper(void *data)
        int ret;
        struct rsync_data_char *args = data;
 
-       ret = lxc_switch_uid_gid(0, 0);
-       if (ret < 0)
+       if (!lxc_switch_uid_gid(0, 0))
                return -1;
 
        if (!lxc_setgroups(0, NULL))
@@ -116,8 +115,7 @@ int lxc_rsync(struct rsync_data *data)
                return -1;
        }
 
-       ret = lxc_switch_uid_gid(0, 0);
-       if (ret < 0)
+       if (!lxc_switch_uid_gid(0, 0))
                return -1;
 
        if (!lxc_setgroups(0, NULL))
index 9c30dc2eac41c0d8c8b5bf4e4cf59f311309284c..9b6f0a617a3d50d04af7159e05f9cb5a7f3b1509 100644 (file)
@@ -1351,7 +1351,7 @@ int lxc_preserve_ns(const int pid, const char *ns)
        return open(path, O_RDONLY | O_CLOEXEC);
 }
 
-int lxc_switch_uid_gid(uid_t uid, gid_t gid)
+bool lxc_switch_uid_gid(uid_t uid, gid_t gid)
 {
        int ret = 0;
 
@@ -1359,7 +1359,7 @@ int lxc_switch_uid_gid(uid_t uid, gid_t gid)
                ret = setgid(gid);
                if (ret < 0) {
                        SYSERROR("Failed to switch to gid %d", gid);
-                       return -1;
+                       return false;
                }
                NOTICE("Switched to gid %d", gid);
        }
@@ -1368,12 +1368,12 @@ int lxc_switch_uid_gid(uid_t uid, gid_t gid)
                ret = setuid(uid);
                if (ret < 0) {
                        SYSERROR("Failed to switch to uid %d", uid);
-                       return -1;
+                       return false;
                }
                NOTICE("Switched to uid %d", uid);
        }
 
-       return ret;
+       return true;
 }
 
 /* Simple covenience function which enables uniform logging. */
index e6a82978f2d4da6158c4c418a4b096059aaf8137..0f121e673282e2553d9bdf37e757525e59f39dfb 100644 (file)
@@ -361,7 +361,7 @@ extern bool task_blocks_signal(pid_t pid, int signal);
 /* Switch to a new uid and gid.
  * If LXC_INVALID_{G,U}ID is passed then the set{g,u}id() will not be called.
  */
-extern int lxc_switch_uid_gid(uid_t uid, gid_t gid);
+extern bool lxc_switch_uid_gid(uid_t uid, gid_t gid);
 extern bool lxc_setgroups(int size, gid_t list[]);
 
 /* Find an unused loop device and associate it with source. */