-int chpst_main(int argc, char **argv)
-{
- if (applet_name[3] == 'd') envdir(argc, argv);
- if (applet_name[1] == 'o') softlimit(argc, argv);
- if (applet_name[0] == 's') setuidgid(argc, argv);
- if (applet_name[0] == 'e') envuidgid(argc, argv);
- // otherwise we are.......... chpst
-
- {
- char *m,*d,*o,*p,*f,*c,*r,*t,*n;
- getopt32(argc, argv, "+u:U:e:m:d:o:p:f:c:r:t:/:n:vP012",
- &set_user,&env_user,&env_dir,
- &m,&d,&o,&p,&f,&c,&r,&t,&root,&n);
- // if (option_mask32 & 0x1) // -u
- // if (option_mask32 & 0x2) // -U
- // if (option_mask32 & 0x4) // -e
- if (option_mask32 & 0x8) limits = limitl = limita = limitd = xatoul(m); // -m
- if (option_mask32 & 0x10) limitd = xatoul(d); // -d
- if (option_mask32 & 0x20) limito = xatoul(o); // -o
- if (option_mask32 & 0x40) limitp = xatoul(p); // -p
- if (option_mask32 & 0x80) limitf = xatoul(f); // -f
- if (option_mask32 & 0x100) limitc = xatoul(c); // -c
- if (option_mask32 & 0x200) limitr = xatoul(r); // -r
- if (option_mask32 & 0x400) limitt = xatoul(t); // -t
- // if (option_mask32 & 0x800) // -/
- if (option_mask32 & 0x1000) nicelvl = xatoi(n); // -n
- // The below consts should match #defines at top!
- //if (option_mask32 & 0x2000) OPT_verbose = 1; // -v
- //if (option_mask32 & 0x4000) OPT_pgrp = 1; // -P
- //if (option_mask32 & 0x8000) OPT_nostdin = 1; // -0
- //if (option_mask32 & 0x10000) OPT_nostdout = 1; // -1
- //if (option_mask32 & 0x20000) OPT_nostderr = 1; // -2
+ 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) {
+ xget_uidgid(&ugid, env_user);
+ xsetenv("GID", utoa(ugid.gid));
+ xsetenv("UID", utoa(ugid.uid));