start_stop_daemon: set complementary group ids too. Closes 3253
authorDenys Vlasenko <vda.linux@googlemail.com>
Thu, 15 Sep 2011 16:27:05 +0000 (18:27 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Thu, 15 Sep 2011 16:27:05 +0000 (18:27 +0200)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
debianutils/start_stop_daemon.c
networking/inetd.c

index bc61959d28c736de8737647c006826360c662886..02609c04fe8c30a52615547e2fcbff8b2d4aaf93 100644 (file)
@@ -502,8 +502,16 @@ int start_stop_daemon_main(int argc UNUSED_PARAM, char **argv)
        if (opt & OPT_c) {
                struct bb_uidgid_t ugid = { -1, -1 };
                parse_chown_usergroup_or_die(&ugid, chuid);
-               if (ugid.gid != (gid_t) -1) xsetgid(ugid.gid);
-               if (ugid.uid != (uid_t) -1) xsetuid(ugid.uid);
+               if (ugid.uid != (uid_t) -1) {
+                       struct passwd *pw = xgetpwuid(ugid.uid);
+                       if (ugid.gid != (gid_t) -1)
+                               pw->pw_gid = ugid.gid;
+                       /* initgroups, setgid, setuid: */
+                       change_identity(pw);
+               } else if (ugid.gid != (gid_t) -1) {
+                       xsetgid(ugid.gid);
+                       setgroups(1, &ugid.gid);
+               }
        }
 #if ENABLE_FEATURE_START_STOP_DAEMON_FANCY
        if (opt & OPT_NICELEVEL) {
index fc6847bb5dc3613690027df543cbd33c780a8e12..26b66992d47e1b6cc803ed5d2a95d037c502b17f 100644 (file)
@@ -1414,7 +1414,7 @@ int inetd_main(int argc UNUSED_PARAM, char **argv)
                                bb_error_msg("non-root must run services as himself");
                                goto do_exit1;
                        }
-                       if (pwd->pw_uid) {
+                       if (pwd->pw_uid != 0) {
                                if (sep->se_group)
                                        pwd->pw_gid = grp->gr_gid;
                                /* initgroups, setgid, setuid: */