2006-10-21 01:10:44 +05:30
|
|
|
/*
|
|
|
|
Copyright (c) 2001-2006, Gerrit Pape
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions are met:
|
|
|
|
|
|
|
|
1. Redistributions of source code must retain the above copyright notice,
|
|
|
|
this list of conditions and the following disclaimer.
|
|
|
|
2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer in the
|
|
|
|
documentation and/or other materials provided with the distribution.
|
|
|
|
3. The name of the author may not be used to endorse or promote products
|
|
|
|
derived from this software without specific prior written permission.
|
|
|
|
|
2017-08-02 17:56:33 +05:30
|
|
|
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR IMPLIED
|
2006-10-21 01:10:44 +05:30
|
|
|
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
|
|
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
|
|
|
EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
|
|
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
|
|
|
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
|
|
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
|
|
|
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
|
|
|
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2008-03-02 18:23:15 +05:30
|
|
|
/* Busyboxed by Denys Vlasenko <vda.linux@googlemail.com> */
|
2015-10-19 04:11:28 +05:30
|
|
|
|
|
|
|
//config:config CHPST
|
2017-07-19 01:31:24 +05:30
|
|
|
//config: bool "chpst (8.7 kb)"
|
2015-10-19 04:11:28 +05:30
|
|
|
//config: default y
|
|
|
|
//config: help
|
2017-07-21 13:20:55 +05:30
|
|
|
//config: chpst changes the process state according to the given options, and
|
|
|
|
//config: execs specified program.
|
2015-10-19 04:11:28 +05:30
|
|
|
//config:
|
|
|
|
//config:config SETUIDGID
|
2017-07-19 01:31:24 +05:30
|
|
|
//config: bool "setuidgid (4.2 kb)"
|
2015-10-19 04:11:28 +05:30
|
|
|
//config: default y
|
|
|
|
//config: help
|
2017-07-21 13:20:55 +05:30
|
|
|
//config: Sets soft resource limits as specified by options
|
2015-10-19 04:11:28 +05:30
|
|
|
//config:
|
|
|
|
//config:config ENVUIDGID
|
2017-07-19 01:31:24 +05:30
|
|
|
//config: bool "envuidgid (3.6 kb)"
|
2015-10-19 04:11:28 +05:30
|
|
|
//config: default y
|
|
|
|
//config: help
|
2017-07-21 13:20:55 +05:30
|
|
|
//config: Sets $UID to account's uid and $GID to account's gid
|
2015-10-19 04:11:28 +05:30
|
|
|
//config:
|
|
|
|
//config:config ENVDIR
|
2017-07-19 01:31:24 +05:30
|
|
|
//config: bool "envdir (2.5 kb)"
|
2015-10-19 04:11:28 +05:30
|
|
|
//config: default y
|
|
|
|
//config: help
|
2017-07-21 13:20:55 +05:30
|
|
|
//config: Sets various environment variables as specified by files
|
|
|
|
//config: in the given directory
|
2015-10-19 04:11:28 +05:30
|
|
|
//config:
|
|
|
|
//config:config SOFTLIMIT
|
2017-07-19 01:31:24 +05:30
|
|
|
//config: bool "softlimit (4.3 kb)"
|
2015-10-19 04:11:28 +05:30
|
|
|
//config: default y
|
|
|
|
//config: help
|
2017-07-21 13:20:55 +05:30
|
|
|
//config: Sets soft resource limits as specified by options
|
2015-10-19 04:11:28 +05:30
|
|
|
|
|
|
|
//applet:IF_CHPST(APPLET(chpst, BB_DIR_USR_BIN, BB_SUID_DROP))
|
2017-01-29 19:27:33 +05:30
|
|
|
// APPLET_ODDNAME:name main location suid_type help
|
|
|
|
//applet:IF_ENVDIR( APPLET_ODDNAME(envdir, chpst, BB_DIR_USR_BIN, BB_SUID_DROP, envdir))
|
2015-10-19 04:11:28 +05:30
|
|
|
//applet:IF_ENVUIDGID(APPLET_ODDNAME(envuidgid, chpst, BB_DIR_USR_BIN, BB_SUID_DROP, envuidgid))
|
|
|
|
//applet:IF_SETUIDGID(APPLET_ODDNAME(setuidgid, chpst, BB_DIR_USR_BIN, BB_SUID_DROP, setuidgid))
|
|
|
|
//applet:IF_SOFTLIMIT(APPLET_ODDNAME(softlimit, chpst, BB_DIR_USR_BIN, BB_SUID_DROP, softlimit))
|
|
|
|
|
|
|
|
//kbuild:lib-$(CONFIG_CHPST) += chpst.o
|
|
|
|
//kbuild:lib-$(CONFIG_ENVDIR) += chpst.o
|
|
|
|
//kbuild:lib-$(CONFIG_ENVUIDGID) += chpst.o
|
|
|
|
//kbuild:lib-$(CONFIG_SETUIDGID) += chpst.o
|
|
|
|
//kbuild:lib-$(CONFIG_SOFTLIMIT) += chpst.o
|
2006-10-21 01:10:44 +05:30
|
|
|
|
2011-04-11 06:59:49 +05:30
|
|
|
//usage:#define chpst_trivial_usage
|
|
|
|
//usage: "[-vP012] [-u USER[:GRP]] [-U USER[:GRP]] [-e DIR]\n"
|
|
|
|
//usage: " [-/ DIR] [-n NICE] [-m BYTES] [-d BYTES] [-o N]\n"
|
|
|
|
//usage: " [-p N] [-f BYTES] [-c BYTES] PROG ARGS"
|
|
|
|
//usage:#define chpst_full_usage "\n\n"
|
|
|
|
//usage: "Change the process state, run PROG\n"
|
|
|
|
//usage: "\n -u USER[:GRP] Set uid and gid"
|
|
|
|
//usage: "\n -U USER[:GRP] Set $UID and $GID in environment"
|
|
|
|
//usage: "\n -e DIR Set environment variables as specified by files"
|
|
|
|
//usage: "\n in DIR: file=1st_line_of_file"
|
|
|
|
//usage: "\n -/ DIR Chroot to DIR"
|
|
|
|
//usage: "\n -n NICE Add NICE to nice value"
|
|
|
|
//usage: "\n -m BYTES Same as -d BYTES -s BYTES -l BYTES"
|
|
|
|
//usage: "\n -d BYTES Limit data segment"
|
|
|
|
//usage: "\n -o N Limit number of open files per process"
|
|
|
|
//usage: "\n -p N Limit number of processes per uid"
|
|
|
|
//usage: "\n -f BYTES Limit output file sizes"
|
|
|
|
//usage: "\n -c BYTES Limit core file size"
|
|
|
|
//usage: "\n -v Verbose"
|
|
|
|
//usage: "\n -P Create new process group"
|
|
|
|
//usage: "\n -0 Close stdin"
|
|
|
|
//usage: "\n -1 Close stdout"
|
|
|
|
//usage: "\n -2 Close stderr"
|
|
|
|
//usage:
|
|
|
|
//usage:#define envdir_trivial_usage
|
|
|
|
//usage: "DIR PROG ARGS"
|
|
|
|
//usage:#define envdir_full_usage "\n\n"
|
|
|
|
//usage: "Set various environment variables as specified by files\n"
|
|
|
|
//usage: "in the directory DIR, run PROG"
|
|
|
|
//usage:
|
|
|
|
//usage:#define envuidgid_trivial_usage
|
|
|
|
//usage: "USER PROG ARGS"
|
|
|
|
//usage:#define envuidgid_full_usage "\n\n"
|
|
|
|
//usage: "Set $UID to USER's uid and $GID to USER's gid, run PROG"
|
|
|
|
//usage:
|
|
|
|
//usage:#define setuidgid_trivial_usage
|
|
|
|
//usage: "USER PROG ARGS"
|
|
|
|
//usage:#define setuidgid_full_usage "\n\n"
|
|
|
|
//usage: "Set uid and gid to USER's uid and gid, drop supplementary group ids,\n"
|
|
|
|
//usage: "run PROG"
|
|
|
|
//usage:
|
|
|
|
//usage:#define softlimit_trivial_usage
|
|
|
|
//usage: "[-a BYTES] [-m BYTES] [-d BYTES] [-s BYTES] [-l BYTES]\n"
|
|
|
|
//usage: " [-f BYTES] [-c BYTES] [-r BYTES] [-o N] [-p N] [-t N]\n"
|
|
|
|
//usage: " PROG ARGS"
|
|
|
|
//usage:#define softlimit_full_usage "\n\n"
|
|
|
|
//usage: "Set soft resource limits, then run PROG\n"
|
|
|
|
//usage: "\n -a BYTES Limit total size of all segments"
|
|
|
|
//usage: "\n -m BYTES Same as -d BYTES -s BYTES -l BYTES -a BYTES"
|
|
|
|
//usage: "\n -d BYTES Limit data segment"
|
|
|
|
//usage: "\n -s BYTES Limit stack segment"
|
|
|
|
//usage: "\n -l BYTES Limit locked memory size"
|
|
|
|
//usage: "\n -o N Limit number of open files per process"
|
|
|
|
//usage: "\n -p N Limit number of processes per uid"
|
|
|
|
//usage: "\nOptions controlling file sizes:"
|
|
|
|
//usage: "\n -f BYTES Limit output file sizes"
|
|
|
|
//usage: "\n -c BYTES Limit core file size"
|
|
|
|
//usage: "\nEfficiency opts:"
|
|
|
|
//usage: "\n -r BYTES Limit resident set size"
|
|
|
|
//usage: "\n -t N Limit CPU time, process receives"
|
|
|
|
//usage: "\n a SIGXCPU after N seconds"
|
|
|
|
|
2007-05-27 00:30:18 +05:30
|
|
|
#include "libbb.h"
|
2012-07-06 08:49:09 +05:30
|
|
|
#include <sys/resource.h> /* getrlimit */
|
2006-10-03 23:22:24 +05:30
|
|
|
|
2008-07-31 02:53:26 +05:30
|
|
|
/*
|
|
|
|
Five applets here: chpst, envdir, envuidgid, setuidgid, softlimit.
|
2006-10-03 23:22:24 +05:30
|
|
|
|
2008-07-31 02:53:26 +05:30
|
|
|
Only softlimit and chpst are taking options:
|
2006-10-03 23:22:24 +05:30
|
|
|
|
2008-07-31 02:53:26 +05:30
|
|
|
# common
|
|
|
|
-o N Limit number of open files per process
|
|
|
|
-p N Limit number of processes per uid
|
|
|
|
-m BYTES Same as -d BYTES -s BYTES -l BYTES [-a BYTES]
|
|
|
|
-d BYTES Limit data segment
|
|
|
|
-f BYTES Limit output file sizes
|
|
|
|
-c BYTES Limit core file size
|
|
|
|
# softlimit
|
|
|
|
-a BYTES Limit total size of all segments
|
|
|
|
-s BYTES Limit stack segment
|
|
|
|
-l BYTES Limit locked memory size
|
|
|
|
-r BYTES Limit resident set size
|
|
|
|
-t N Limit CPU time
|
|
|
|
# chpst
|
|
|
|
-u USER[:GRP] Set uid and gid
|
|
|
|
-U USER[:GRP] Set $UID and $GID in environment
|
|
|
|
-e DIR Set environment variables as specified by files in DIR
|
|
|
|
-/ DIR Chroot to DIR
|
|
|
|
-n NICE Add NICE to nice value
|
|
|
|
-v Verbose
|
|
|
|
-P Create new process group
|
|
|
|
-0 -1 -2 Close fd 0,1,2
|
2006-10-03 23:22:24 +05:30
|
|
|
|
2008-07-31 02:53:26 +05:30
|
|
|
Even though we accept all these options for both softlimit and chpst,
|
|
|
|
they are not to be advertised on their help texts.
|
|
|
|
We have enough problems with feature creep in other people's
|
|
|
|
software, don't want to add our own.
|
2006-10-03 23:22:24 +05:30
|
|
|
|
2008-07-31 02:53:26 +05:30
|
|
|
envdir, envuidgid, setuidgid take no options, but they reuse code which
|
|
|
|
handles -e, -U and -u.
|
|
|
|
*/
|
|
|
|
|
|
|
|
enum {
|
|
|
|
OPT_a = (1 << 0) * ENABLE_SOFTLIMIT,
|
|
|
|
OPT_c = (1 << 1) * (ENABLE_SOFTLIMIT || ENABLE_CHPST),
|
|
|
|
OPT_d = (1 << 2) * (ENABLE_SOFTLIMIT || ENABLE_CHPST),
|
|
|
|
OPT_f = (1 << 3) * (ENABLE_SOFTLIMIT || ENABLE_CHPST),
|
|
|
|
OPT_l = (1 << 4) * ENABLE_SOFTLIMIT,
|
|
|
|
OPT_m = (1 << 5) * (ENABLE_SOFTLIMIT || ENABLE_CHPST),
|
|
|
|
OPT_o = (1 << 6) * (ENABLE_SOFTLIMIT || ENABLE_CHPST),
|
|
|
|
OPT_p = (1 << 7) * (ENABLE_SOFTLIMIT || ENABLE_CHPST),
|
|
|
|
OPT_r = (1 << 8) * ENABLE_SOFTLIMIT,
|
|
|
|
OPT_s = (1 << 9) * ENABLE_SOFTLIMIT,
|
|
|
|
OPT_t = (1 << 10) * ENABLE_SOFTLIMIT,
|
|
|
|
OPT_u = (1 << 11) * (ENABLE_CHPST || ENABLE_SETUIDGID),
|
|
|
|
OPT_U = (1 << 12) * (ENABLE_CHPST || ENABLE_ENVUIDGID),
|
|
|
|
OPT_e = (1 << 13) * (ENABLE_CHPST || ENABLE_ENVDIR),
|
|
|
|
OPT_root = (1 << 14) * ENABLE_CHPST,
|
|
|
|
OPT_n = (1 << 15) * ENABLE_CHPST,
|
|
|
|
OPT_v = (1 << 16) * ENABLE_CHPST,
|
|
|
|
OPT_P = (1 << 17) * ENABLE_CHPST,
|
|
|
|
OPT_0 = (1 << 18) * ENABLE_CHPST,
|
|
|
|
OPT_1 = (1 << 19) * ENABLE_CHPST,
|
|
|
|
OPT_2 = (1 << 20) * ENABLE_CHPST,
|
|
|
|
};
|
2006-10-03 23:22:24 +05:30
|
|
|
|
2009-10-27 03:57:07 +05:30
|
|
|
/* TODO: use recursive_action? */
|
2009-10-08 18:05:37 +05:30
|
|
|
static NOINLINE void edir(const char *directory_name)
|
2006-10-03 23:22:24 +05:30
|
|
|
{
|
|
|
|
int wdir;
|
|
|
|
DIR *dir;
|
|
|
|
struct dirent *d;
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
wdir = xopen(".", O_RDONLY | O_NDELAY);
|
|
|
|
xchdir(directory_name);
|
2009-10-27 03:57:07 +05:30
|
|
|
dir = xopendir(".");
|
2006-10-03 23:22:24 +05:30
|
|
|
for (;;) {
|
2010-01-06 22:46:39 +05:30
|
|
|
char buf[256];
|
2008-04-01 21:43:14 +05:30
|
|
|
char *tail;
|
|
|
|
int size;
|
|
|
|
|
2006-10-03 23:22:24 +05:30
|
|
|
errno = 0;
|
|
|
|
d = readdir(dir);
|
|
|
|
if (!d) {
|
2006-11-16 07:57:24 +05:30
|
|
|
if (errno)
|
|
|
|
bb_perror_msg_and_die("readdir %s",
|
|
|
|
directory_name);
|
2006-10-03 23:22:24 +05:30
|
|
|
break;
|
|
|
|
}
|
2007-10-06 02:53:49 +05:30
|
|
|
if (d->d_name[0] == '.')
|
|
|
|
continue;
|
2006-10-03 23:22:24 +05:30
|
|
|
fd = open(d->d_name, O_RDONLY | O_NDELAY);
|
|
|
|
if (fd < 0) {
|
2008-07-31 02:53:26 +05:30
|
|
|
if ((errno == EISDIR) && directory_name) {
|
|
|
|
if (option_mask32 & OPT_v)
|
2006-11-16 07:57:24 +05:30
|
|
|
bb_perror_msg("warning: %s/%s is a directory",
|
2010-10-28 22:27:19 +05:30
|
|
|
directory_name, d->d_name);
|
2006-10-03 23:22:24 +05:30
|
|
|
continue;
|
2010-10-28 22:27:19 +05:30
|
|
|
}
|
|
|
|
bb_perror_msg_and_die("open %s/%s",
|
2006-11-16 07:57:24 +05:30
|
|
|
directory_name, d->d_name);
|
2006-10-03 23:22:24 +05:30
|
|
|
}
|
2008-04-01 21:43:14 +05:30
|
|
|
size = full_read(fd, buf, sizeof(buf)-1);
|
|
|
|
close(fd);
|
|
|
|
if (size < 0)
|
|
|
|
bb_perror_msg_and_die("read %s/%s",
|
|
|
|
directory_name, d->d_name);
|
|
|
|
if (size == 0) {
|
|
|
|
unsetenv(d->d_name);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
buf[size] = '\n';
|
|
|
|
tail = strchr(buf, '\n');
|
|
|
|
/* skip trailing whitespace */
|
|
|
|
while (1) {
|
|
|
|
*tail = '\0';
|
|
|
|
tail--;
|
|
|
|
if (tail < buf || !isspace(*tail))
|
|
|
|
break;
|
2006-10-03 23:22:24 +05:30
|
|
|
}
|
2008-04-01 21:43:14 +05:30
|
|
|
xsetenv(d->d_name, buf);
|
2006-10-03 23:22:24 +05:30
|
|
|
}
|
|
|
|
closedir(dir);
|
2016-04-02 01:42:44 +05:30
|
|
|
xfchdir(wdir);
|
2006-10-03 23:22:24 +05:30
|
|
|
close(wdir);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void limit(int what, long l)
|
|
|
|
{
|
|
|
|
struct rlimit r;
|
|
|
|
|
2008-03-13 03:44:34 +05:30
|
|
|
/* Never fails under Linux (except if you pass it bad arguments) */
|
|
|
|
getrlimit(what, &r);
|
2006-10-03 23:22:24 +05:30
|
|
|
if ((l < 0) || (l > r.rlim_max))
|
|
|
|
r.rlim_cur = r.rlim_max;
|
|
|
|
else
|
|
|
|
r.rlim_cur = l;
|
2007-10-06 02:53:49 +05:30
|
|
|
if (setrlimit(what, &r) == -1)
|
|
|
|
bb_perror_msg_and_die("setrlimit");
|
2006-10-03 23:22:24 +05:30
|
|
|
}
|
|
|
|
|
2008-07-31 02:53:26 +05:30
|
|
|
int chpst_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
|
|
|
int chpst_main(int argc UNUSED_PARAM, char **argv)
|
2006-10-03 23:22:24 +05:30
|
|
|
{
|
2008-07-31 02:53:26 +05:30
|
|
|
struct bb_uidgid_t ugid;
|
2008-08-05 23:13:29 +05:30
|
|
|
char *set_user = set_user; /* for compiler */
|
|
|
|
char *env_dir = env_dir;
|
2008-07-31 02:53:26 +05:30
|
|
|
char *root;
|
|
|
|
char *nicestr;
|
|
|
|
unsigned limita;
|
|
|
|
unsigned limitc;
|
|
|
|
unsigned limitd;
|
|
|
|
unsigned limitf;
|
|
|
|
unsigned limitl;
|
|
|
|
unsigned limitm;
|
|
|
|
unsigned limito;
|
|
|
|
unsigned limitp;
|
|
|
|
unsigned limitr;
|
|
|
|
unsigned limits;
|
|
|
|
unsigned limitt;
|
|
|
|
unsigned opt;
|
|
|
|
|
|
|
|
if ((ENABLE_CHPST && applet_name[0] == 'c')
|
|
|
|
|| (ENABLE_SOFTLIMIT && applet_name[1] == 'o')
|
|
|
|
) {
|
|
|
|
// FIXME: can we live with int-sized limits?
|
|
|
|
// can we live with 40000 days?
|
|
|
|
// if yes -> getopt converts strings to numbers for us
|
2016-07-07 01:28:02 +05:30
|
|
|
opt_complementary = "-1";
|
|
|
|
opt = getopt32(argv, "+a:+c:+d:+f:+l:+m:+o:+p:+r:+s:+t:+u:U:e:"
|
2009-04-21 16:39:40 +05:30
|
|
|
IF_CHPST("/:n:vP012"),
|
2008-07-31 02:53:26 +05:30
|
|
|
&limita, &limitc, &limitd, &limitf, &limitl,
|
|
|
|
&limitm, &limito, &limitp, &limitr, &limits, &limitt,
|
2013-11-29 21:09:28 +05:30
|
|
|
&set_user, &set_user, &env_dir
|
2009-04-21 16:39:40 +05:30
|
|
|
IF_CHPST(, &root, &nicestr));
|
2008-07-31 02:53:26 +05:30
|
|
|
argv += optind;
|
|
|
|
if (opt & OPT_m) { // -m means -asld
|
|
|
|
limita = limits = limitl = limitd = limitm;
|
|
|
|
opt |= (OPT_s | OPT_l | OPT_a | OPT_d);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
option_mask32 = opt = 0;
|
|
|
|
argv++;
|
2008-08-21 03:49:27 +05:30
|
|
|
if (!*argv)
|
|
|
|
bb_show_usage();
|
2008-07-31 02:53:26 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
// envdir?
|
|
|
|
if (ENABLE_ENVDIR && applet_name[3] == 'd') {
|
|
|
|
env_dir = *argv++;
|
|
|
|
opt |= OPT_e;
|
|
|
|
}
|
|
|
|
|
|
|
|
// setuidgid?
|
2008-08-21 03:49:27 +05:30
|
|
|
if (ENABLE_SETUIDGID && applet_name[1] == 'e') {
|
2008-07-31 02:53:26 +05:30
|
|
|
set_user = *argv++;
|
|
|
|
opt |= OPT_u;
|
|
|
|
}
|
|
|
|
|
|
|
|
// envuidgid?
|
2008-08-16 02:33:17 +05:30
|
|
|
if (ENABLE_ENVUIDGID && applet_name[0] == 'e' && applet_name[3] == 'u') {
|
2013-11-29 21:09:28 +05:30
|
|
|
set_user = *argv++;
|
2008-07-31 02:53:26 +05:30
|
|
|
opt |= OPT_U;
|
|
|
|
}
|
|
|
|
|
|
|
|
// we must have PROG [ARGS]
|
|
|
|
if (!*argv)
|
|
|
|
bb_show_usage();
|
|
|
|
|
|
|
|
// set limits
|
|
|
|
if (opt & OPT_d) {
|
2006-10-03 23:22:24 +05:30
|
|
|
#ifdef RLIMIT_DATA
|
|
|
|
limit(RLIMIT_DATA, limitd);
|
|
|
|
#else
|
2008-07-31 02:53:26 +05:30
|
|
|
if (opt & OPT_v)
|
2007-10-06 02:53:49 +05:30
|
|
|
bb_error_msg("system does not support RLIMIT_%s",
|
|
|
|
"DATA");
|
2006-10-03 23:22:24 +05:30
|
|
|
#endif
|
|
|
|
}
|
2008-07-31 02:53:26 +05:30
|
|
|
if (opt & OPT_s) {
|
2006-10-03 23:22:24 +05:30
|
|
|
#ifdef RLIMIT_STACK
|
|
|
|
limit(RLIMIT_STACK, limits);
|
|
|
|
#else
|
2008-07-31 02:53:26 +05:30
|
|
|
if (opt & OPT_v)
|
2007-10-06 02:53:49 +05:30
|
|
|
bb_error_msg("system does not support RLIMIT_%s",
|
|
|
|
"STACK");
|
2006-10-03 23:22:24 +05:30
|
|
|
#endif
|
|
|
|
}
|
2008-07-31 02:53:26 +05:30
|
|
|
if (opt & OPT_l) {
|
2006-10-03 23:22:24 +05:30
|
|
|
#ifdef RLIMIT_MEMLOCK
|
|
|
|
limit(RLIMIT_MEMLOCK, limitl);
|
|
|
|
#else
|
2008-07-31 02:53:26 +05:30
|
|
|
if (opt & OPT_v)
|
2007-10-06 02:53:49 +05:30
|
|
|
bb_error_msg("system does not support RLIMIT_%s",
|
|
|
|
"MEMLOCK");
|
2006-10-03 23:22:24 +05:30
|
|
|
#endif
|
|
|
|
}
|
2008-07-31 02:53:26 +05:30
|
|
|
if (opt & OPT_a) {
|
2006-10-03 23:22:24 +05:30
|
|
|
#ifdef RLIMIT_VMEM
|
|
|
|
limit(RLIMIT_VMEM, limita);
|
|
|
|
#else
|
|
|
|
#ifdef RLIMIT_AS
|
|
|
|
limit(RLIMIT_AS, limita);
|
|
|
|
#else
|
2008-07-31 02:53:26 +05:30
|
|
|
if (opt & OPT_v)
|
2007-10-06 02:53:49 +05:30
|
|
|
bb_error_msg("system does not support RLIMIT_%s",
|
|
|
|
"VMEM");
|
2006-10-03 23:22:24 +05:30
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
2008-07-31 02:53:26 +05:30
|
|
|
if (opt & OPT_o) {
|
2006-10-03 23:22:24 +05:30
|
|
|
#ifdef RLIMIT_NOFILE
|
|
|
|
limit(RLIMIT_NOFILE, limito);
|
|
|
|
#else
|
|
|
|
#ifdef RLIMIT_OFILE
|
|
|
|
limit(RLIMIT_OFILE, limito);
|
|
|
|
#else
|
2008-07-31 02:53:26 +05:30
|
|
|
if (opt & OPT_v)
|
2007-10-06 02:53:49 +05:30
|
|
|
bb_error_msg("system does not support RLIMIT_%s",
|
|
|
|
"NOFILE");
|
2006-10-03 23:22:24 +05:30
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
2008-07-31 02:53:26 +05:30
|
|
|
if (opt & OPT_p) {
|
2006-10-03 23:22:24 +05:30
|
|
|
#ifdef RLIMIT_NPROC
|
|
|
|
limit(RLIMIT_NPROC, limitp);
|
|
|
|
#else
|
2008-07-31 02:53:26 +05:30
|
|
|
if (opt & OPT_v)
|
2007-10-06 02:53:49 +05:30
|
|
|
bb_error_msg("system does not support RLIMIT_%s",
|
|
|
|
"NPROC");
|
2006-10-03 23:22:24 +05:30
|
|
|
#endif
|
|
|
|
}
|
2008-07-31 02:53:26 +05:30
|
|
|
if (opt & OPT_f) {
|
2006-10-03 23:22:24 +05:30
|
|
|
#ifdef RLIMIT_FSIZE
|
|
|
|
limit(RLIMIT_FSIZE, limitf);
|
|
|
|
#else
|
2008-07-31 02:53:26 +05:30
|
|
|
if (opt & OPT_v)
|
2007-10-06 02:53:49 +05:30
|
|
|
bb_error_msg("system does not support RLIMIT_%s",
|
|
|
|
"FSIZE");
|
2006-10-03 23:22:24 +05:30
|
|
|
#endif
|
|
|
|
}
|
2008-07-31 02:53:26 +05:30
|
|
|
if (opt & OPT_c) {
|
2006-10-03 23:22:24 +05:30
|
|
|
#ifdef RLIMIT_CORE
|
|
|
|
limit(RLIMIT_CORE, limitc);
|
|
|
|
#else
|
2008-07-31 02:53:26 +05:30
|
|
|
if (opt & OPT_v)
|
2007-10-06 02:53:49 +05:30
|
|
|
bb_error_msg("system does not support RLIMIT_%s",
|
|
|
|
"CORE");
|
2006-10-03 23:22:24 +05:30
|
|
|
#endif
|
|
|
|
}
|
2008-07-31 02:53:26 +05:30
|
|
|
if (opt & OPT_r) {
|
2006-10-03 23:22:24 +05:30
|
|
|
#ifdef RLIMIT_RSS
|
|
|
|
limit(RLIMIT_RSS, limitr);
|
|
|
|
#else
|
2008-07-31 02:53:26 +05:30
|
|
|
if (opt & OPT_v)
|
2007-10-06 02:53:49 +05:30
|
|
|
bb_error_msg("system does not support RLIMIT_%s",
|
|
|
|
"RSS");
|
2006-10-03 23:22:24 +05:30
|
|
|
#endif
|
|
|
|
}
|
2008-07-31 02:53:26 +05:30
|
|
|
if (opt & OPT_t) {
|
2006-10-03 23:22:24 +05:30
|
|
|
#ifdef RLIMIT_CPU
|
|
|
|
limit(RLIMIT_CPU, limitt);
|
|
|
|
#else
|
2008-07-31 02:53:26 +05:30
|
|
|
if (opt & OPT_v)
|
2007-10-06 02:53:49 +05:30
|
|
|
bb_error_msg("system does not support RLIMIT_%s",
|
|
|
|
"CPU");
|
2006-10-03 23:22:24 +05:30
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2008-07-31 02:53:26 +05:30
|
|
|
if (opt & OPT_P)
|
|
|
|
setsid();
|
2006-10-03 23:22:24 +05:30
|
|
|
|
2008-07-31 02:53:26 +05:30
|
|
|
if (opt & OPT_e)
|
|
|
|
edir(env_dir);
|
|
|
|
|
2011-09-16 15:24:13 +05:30
|
|
|
if (opt & (OPT_u|OPT_U))
|
2011-09-16 15:22:43 +05:30
|
|
|
xget_uidgid(&ugid, set_user);
|
|
|
|
|
2011-09-16 15:24:13 +05:30
|
|
|
// 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.
|
2008-07-31 02:53:26 +05:30
|
|
|
if (opt & OPT_U) {
|
|
|
|
xsetenv("GID", utoa(ugid.gid));
|
|
|
|
xsetenv("UID", utoa(ugid.uid));
|
2006-10-03 23:22:24 +05:30
|
|
|
}
|
2007-01-11 22:50:00 +05:30
|
|
|
|
2008-07-31 02:53:26 +05:30
|
|
|
if (opt & OPT_root) {
|
2012-03-08 04:58:24 +05:30
|
|
|
xchroot(root);
|
2006-10-03 23:22:24 +05:30
|
|
|
}
|
2008-07-31 02:53:26 +05:30
|
|
|
|
2017-03-14 03:02:05 +05:30
|
|
|
/* nice should be done before xsetuid */
|
|
|
|
if (opt & OPT_n) {
|
|
|
|
errno = 0;
|
|
|
|
if (nice(xatoi(nicestr)) == -1)
|
|
|
|
bb_perror_msg_and_die("nice");
|
|
|
|
}
|
|
|
|
|
2008-07-31 02:53:26 +05:30
|
|
|
if (opt & OPT_u) {
|
|
|
|
if (setgroups(1, &ugid.gid) == -1)
|
|
|
|
bb_perror_msg_and_die("setgroups");
|
|
|
|
xsetgid(ugid.gid);
|
|
|
|
xsetuid(ugid.uid);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (opt & OPT_0)
|
|
|
|
close(STDIN_FILENO);
|
|
|
|
if (opt & OPT_1)
|
|
|
|
close(STDOUT_FILENO);
|
|
|
|
if (opt & OPT_2)
|
|
|
|
close(STDERR_FILENO);
|
2006-10-03 23:22:24 +05:30
|
|
|
|
2010-07-04 04:27:03 +05:30
|
|
|
BB_EXECVP_or_die(argv);
|
2006-10-03 23:22:24 +05:30
|
|
|
}
|