aboutsummaryrefslogtreecommitdiff
path: root/util-linux/setpriv.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2017-07-02 15:42:51 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2017-07-04 17:15:32 +0200
commit6a3bcf340aa9d7defc86f21d75fd9412c5b9f427 (patch)
treeef070f39c9d47dd7abae691b74d6da25b3de97c8 /util-linux/setpriv.c
parentd253b557a338c5fe27e8f5e55540db07e7842fc4 (diff)
downloadbusybox-6a3bcf340aa9d7defc86f21d75fd9412c5b9f427.tar.gz
setpriv: prepare option parsing logic for additional opts
The current option parsing logic of setpriv only supports the case where we want to execute a sub-program and have at most one argument. Refactor handling of options to solve these shortcomings to make it easy to support 'setpriv --dump', which does not accept any additional arguments, as well as the case where additional options are passed to setpriv. This is done by handling 'argc' ourselves, throwing an error when no program is specified, as well as introducing an enum for the different option bitmasks. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'util-linux/setpriv.c')
-rw-r--r--util-linux/setpriv.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/util-linux/setpriv.c b/util-linux/setpriv.c
index 686ad45d5..d15e0d84e 100644
--- a/util-linux/setpriv.c
+++ b/util-linux/setpriv.c
@@ -51,6 +51,12 @@
#define PR_SET_NO_NEW_PRIVS 38
#endif
+enum {
+ OPTBIT_NNP,
+
+ OPT_NNP = (1 << OPTBIT_NNP),
+};
+
int setpriv_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int setpriv_main(int argc UNUSED_PARAM, char **argv)
{
@@ -60,15 +66,17 @@ int setpriv_main(int argc UNUSED_PARAM, char **argv)
;
int opts;
- opt_complementary = "-1";
applet_long_options = setpriv_longopts;
opts = getopt32(argv, "+");
- if (opts) {
+ argv += optind;
+
+ if (opts & OPT_NNP) {
if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0))
bb_simple_perror_msg_and_die("prctl: NO_NEW_PRIVS");
}
- argv += optind;
+ if (!argv[0])
+ bb_show_usage();
BB_EXECVP_or_die(argv);
}