diff options
author | Ron Yorston <rmy@pobox.com> | 2024-08-05 11:08:10 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2024-08-05 11:08:10 +0100 |
commit | 2a09008c8eab35b5cc0422fab333ca657877256c (patch) | |
tree | 4a6702b4ed5e4b12df5bd37bd371e39e363b85c3 | |
parent | 5eb14d55da843927f792e35dbf54079579f0d701 (diff) | |
download | busybox-w32-2a09008c8eab35b5cc0422fab333ca657877256c.tar.gz busybox-w32-2a09008c8eab35b5cc0422fab333ca657877256c.tar.bz2 busybox-w32-2a09008c8eab35b5cc0422fab333ca657877256c.zip |
drop: allow an alternative shell to be selected
Add the '-s' option to allow an alternative shell to be given.
No PATH search is performed for the shell, so an absolute or
relative path to a suitable executable must be provided.
Adds 80-96 bytes.
(GitHub issue #438)
-rw-r--r-- | miscutils/drop.c | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/miscutils/drop.c b/miscutils/drop.c index 629460564..a1344ab65 100644 --- a/miscutils/drop.c +++ b/miscutils/drop.c | |||
@@ -36,10 +36,10 @@ | |||
36 | //kbuild:lib-$(CONFIG_PDROP) += drop.o | 36 | //kbuild:lib-$(CONFIG_PDROP) += drop.o |
37 | 37 | ||
38 | //usage:#define drop_trivial_usage | 38 | //usage:#define drop_trivial_usage |
39 | //usage: "[COMMAND [ARG...] | -c CMD_STRING [ARG...]]" | 39 | //usage: "[COMMAND [ARG...] | [-s SHELL] -c CMD_STRING [ARG...]]" |
40 | //usage:#define drop_full_usage "\n\n" | 40 | //usage:#define drop_full_usage "\n\n" |
41 | //usage: "Drop elevated privileges and run a command. If no command\n" | 41 | //usage: "Drop elevated privileges and run a command. If no command\n" |
42 | //usage: "is provided run the BusyBox shell.\n" | 42 | //usage: "is provided run a shell (by default, the BusyBox shell).\n" |
43 | 43 | ||
44 | //usage:#define cdrop_trivial_usage | 44 | //usage:#define cdrop_trivial_usage |
45 | //usage: "[COMMAND [ARG...] | -c CMD_STRING [ARG...]]" | 45 | //usage: "[COMMAND [ARG...] | -c CMD_STRING [ARG...]]" |
@@ -71,7 +71,7 @@ static void setenv_name(const char *key) | |||
71 | } | 71 | } |
72 | 72 | ||
73 | int drop_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 73 | int drop_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
74 | int drop_main(int argc, char **argv) | 74 | int drop_main(int argc UNUSED_PARAM, char **argv) |
75 | { | 75 | { |
76 | SAFER_LEVEL_HANDLE safer; | 76 | SAFER_LEVEL_HANDLE safer; |
77 | HANDLE token; | 77 | HANDLE token; |
@@ -109,15 +109,19 @@ int drop_main(int argc, char **argv) | |||
109 | if (SetTokenInformation(token, TokenIntegrityLevel, &TIL, | 109 | if (SetTokenInformation(token, TokenIntegrityLevel, &TIL, |
110 | sizeof(TOKEN_MANDATORY_LABEL))) { | 110 | sizeof(TOKEN_MANDATORY_LABEL))) { |
111 | char *opt_command = NULL; | 111 | char *opt_command = NULL; |
112 | char *opt_shell = NULL; | ||
112 | char **a; | 113 | char **a; |
113 | const char *opt, *arg; | 114 | const char *opt, *arg; |
114 | char *exe, *cmd, *q; | 115 | char *exe, *cmd, *q; |
115 | 116 | ||
116 | getopt32(argv, "c:", &opt_command); | 117 | if (*applet_name == 'd') |
118 | getopt32(argv, "c:s:", &opt_command, &opt_shell); | ||
119 | else | ||
120 | getopt32(argv, "c:", &opt_command); | ||
117 | a = argv + optind; | 121 | a = argv + optind; |
118 | opt = "-c"; | 122 | opt = "-c"; |
119 | 123 | ||
120 | if (argc == 1 || opt_command) { | 124 | if (*a == NULL || opt_command) { |
121 | switch (*applet_name) { | 125 | switch (*applet_name) { |
122 | #if ENABLE_PDROP | 126 | #if ENABLE_PDROP |
123 | case 'p': | 127 | case 'p': |
@@ -134,8 +138,13 @@ int drop_main(int argc, char **argv) | |||
134 | #endif | 138 | #endif |
135 | #if ENABLE_DROP | 139 | #if ENABLE_DROP |
136 | case 'd': | 140 | case 'd': |
137 | arg = "sh"; | 141 | if (opt_shell) { |
138 | exe = xstrdup(bb_busybox_exec_path); | 142 | arg = bb_basename(opt_shell); |
143 | exe = file_is_win32_exe(opt_shell); | ||
144 | } else { | ||
145 | arg = "sh"; | ||
146 | exe = xstrdup(bb_busybox_exec_path); | ||
147 | } | ||
139 | break; | 148 | break; |
140 | #endif | 149 | #endif |
141 | default: | 150 | default: |