[prev in list] [next in list] [prev in thread] [next in thread]
List: busybox
Subject: [PATCH 2/9] setpriv: prepare option parsing logic for additional opts
From: Patrick Steinhardt <ps () pks ! im>
Date: 2017-06-29 17:34:29
Message-ID: 892dad26489324c2a374e2072b568d2c81873160.1498757023.git.ps () pks ! im
[Download RAW message or body]
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.
---
util-linux/setpriv.c | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/util-linux/setpriv.c b/util-linux/setpriv.c
index 686ad45d5..24e577131 100644
--- a/util-linux/setpriv.c
+++ b/util-linux/setpriv.c
@@ -51,6 +51,10 @@
#define PR_SET_NO_NEW_PRIVS 38
#endif
+enum {
+ OPT_NNP = (1 << 0),
+};
+
int setpriv_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int setpriv_main(int argc UNUSED_PARAM, char **argv)
{
@@ -60,15 +64,20 @@ int setpriv_main(int argc UNUSED_PARAM, char **argv)
;
int opts;
- opt_complementary = "-1";
+ opt_complementary = "";
applet_long_options = setpriv_longopts;
opts = getopt32(argv, "+");
- if (opts) {
+ argc -= optind;
+ argv += optind;
+
+ if (!argc)
+ bb_error_msg_and_die("no program specified");
+
+ 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;
BB_EXECVP_or_die(argv);
}
--
2.13.2
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic