Bump to version 1.22.1
[platform/upstream/busybox.git] / runit / chpst.c
index 1857060..71af29f 100644 (file)
@@ -91,6 +91,7 @@ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 //usage:     "\n                       a SIGXCPU after N seconds"
 
 #include "libbb.h"
+#include <sys/resource.h> /* getrlimit */
 
 /*
 Five applets here: chpst, envdir, envuidgid, setuidgid, softlimit.
@@ -235,7 +236,6 @@ int chpst_main(int argc UNUSED_PARAM, char **argv)
 {
        struct bb_uidgid_t ugid;
        char *set_user = set_user; /* for compiler */
-       char *env_user = env_user;
        char *env_dir = env_dir;
        char *root;
        char *nicestr;
@@ -263,7 +263,7 @@ int chpst_main(int argc UNUSED_PARAM, char **argv)
                        IF_CHPST("/:n:vP012"),
                        &limita, &limitc, &limitd, &limitf, &limitl,
                        &limitm, &limito, &limitp, &limitr, &limits, &limitt,
-                       &set_user, &env_user, &env_dir
+                       &set_user, &set_user, &env_dir
                        IF_CHPST(, &root, &nicestr));
                argv += optind;
                if (opt & OPT_m) { // -m means -asld
@@ -291,7 +291,7 @@ int chpst_main(int argc UNUSED_PARAM, char **argv)
 
        // envuidgid?
        if (ENABLE_ENVUIDGID && applet_name[0] == 'e' && applet_name[3] == 'u') {
-               env_user = *argv++;
+               set_user = *argv++;
                opt |= OPT_U;
        }
 
@@ -405,22 +405,19 @@ int chpst_main(int argc UNUSED_PARAM, char **argv)
        if (opt & OPT_e)
                edir(env_dir);
 
-       // FIXME: chrooted jail must have /etc/passwd if we move this after chroot!
-       // OTOH chroot fails for non-roots!
-       // SOLUTION: cache uid/gid before chroot, apply uid/gid after
+       if (opt & (OPT_u|OPT_U))
+               xget_uidgid(&ugid, set_user);
+
+       // chrooted jail must have /etc/passwd if we move this after chroot.
+       // OTOH chroot fails for non-roots.
+       // Solution: cache uid/gid before chroot, apply uid/gid after.
        if (opt & OPT_U) {
-               xget_uidgid(&ugid, env_user);
                xsetenv("GID", utoa(ugid.gid));
                xsetenv("UID", utoa(ugid.uid));
        }
 
-       if (opt & OPT_u) {
-               xget_uidgid(&ugid, set_user);
-       }
-
        if (opt & OPT_root) {
-               xchdir(root);
-               xchroot(".");
+               xchroot(root);
        }
 
        if (opt & OPT_u) {