qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH 7/8] os-posix: Provide new -runasid option


From: Ross Lagerwall
Subject: Re: [Qemu-devel] [PATCH 7/8] os-posix: Provide new -runasid option
Date: Fri, 6 Oct 2017 13:47:31 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0

On 10/04/2017 05:18 PM, Ian Jackson wrote:
This allows the caller to specify a uid and gid to use, even if there
is no corresponding password entry.  This will be useful in certain
Xen configurations.

Signed-off-by: Ian Jackson <address@hidden>
snip
@@ -166,17 +187,19 @@ void os_parse_cmd_args(int index, const char *optarg)
static void change_process_uid(void)
  {
-    if (user_pwd) {
-        if (setgid(user_pwd->pw_gid) < 0) {
+    if (user_pwd || user_uid != (uid_t)-1) {
+        if (setgid(user_pwd ? user_pwd->pw_gid : user_gid) < 0) {
              fprintf(stderr, "Failed to setgid(%d)\n", user_pwd->pw_gid);
              exit(1);
          }
-        if (initgroups(user_pwd->pw_name, user_pwd->pw_gid) < 0) {
+        if ((user_pwd
+             ? initgroups(user_pwd->pw_name, user_pwd->pw_gid)
+             : setgroups(1, &user_gid)) < 0) {
              fprintf(stderr, "Failed to initgroups(\"%s\", %d)\n",
                      user_pwd->pw_name, user_pwd->pw_gid);
              exit(1);
          }
-        if (setuid(user_pwd->pw_uid) < 0) {
+        if (setuid(user_pwd ? user_pwd->pw_uid : user_gid) < 0) {
              fprintf(stderr, "Failed to setuid(%d)\n", user_pwd->pw_uid);
              exit(1);
          }

This last one should be user_uid, not user_gid.

--
Ross Lagerwall



reply via email to

[Prev in Thread] Current Thread [Next in Thread]