aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2023-04-23 13:12:27 +0100
committerRon Yorston <rmy@pobox.com>2023-04-23 15:14:55 +0100
commita6b004d72931ab656293e9ab3a3cfb810b2764de (patch)
treebe96aa1af1bc6b6ebcfaaab864957840bcc8888b
parent3354901c71c3b035be7edc6fd17e0a9b20c7adc0 (diff)
downloadbusybox-w32-su_cmd2.tar.gz
busybox-w32-su_cmd2.tar.bz2
busybox-w32-su_cmd2.zip
sush: new appletsu_cmd2
Introduce the new applet sush. It's like su but it permits additional arguments on the command line which are passed to the elevated shell. Adds 144-168 bytes. (O bytes if it's not enabled.)
-rw-r--r--loginutils/suw32.c30
1 files changed, 29 insertions, 1 deletions
diff --git a/loginutils/suw32.c b/loginutils/suw32.c
index 79637dd77..f8440b93e 100644
--- a/loginutils/suw32.c
+++ b/loginutils/suw32.c
@@ -11,9 +11,18 @@
11//config: help 11//config: help
12//config: su runs a shell with elevated privileges. 12//config: su runs a shell with elevated privileges.
13 13
14//config:config SUSH
15//config: bool "sush"
16//config: default y
17//config: depends on PLATFORM_MINGW32 && ASH
18//config: help
19//config: Run a shell with elevated privileges
20
14//applet:IF_SUW32(APPLET_ODDNAME(su, suw32, BB_DIR_BIN, BB_SUID_DROP, suw32)) 21//applet:IF_SUW32(APPLET_ODDNAME(su, suw32, BB_DIR_BIN, BB_SUID_DROP, suw32))
22//applet:IF_SUSH(APPLET_ODDNAME(sush, suw32, BB_DIR_USR_BIN, BB_SUID_DROP, sush))
15 23
16//kbuild:lib-$(CONFIG_SUW32) += suw32.o 24//kbuild:lib-$(CONFIG_SUW32) += suw32.o
25//kbuild:lib-$(CONFIG_SUSH) += suw32.o
17 26
18//usage:#define suw32_trivial_usage 27//usage:#define suw32_trivial_usage
19//usage: "[-c \"CMD\"]" 28//usage: "[-c \"CMD\"]"
@@ -21,6 +30,13 @@
21//usage: "Run shell with elevated privileges\n" 30//usage: "Run shell with elevated privileges\n"
22//usage: "\n -c CMD Command to pass to 'sh -c'" 31//usage: "\n -c CMD Command to pass to 'sh -c'"
23 32
33//usage:#define sush_trivial_usage
34//usage: "[-c \"CMD\" [ARG...] | FILE [ARG...]]"
35//usage:#define sush_full_usage "\n\n"
36//usage: "Run shell with elevated privileges\n"
37//usage: "\n -c CMD [ARG...] Script [args] to pass to 'sh -c'"
38//usage: "\n FILE [ARG...] Command file [args] to pass to 'sh'"
39
24#include "libbb.h" 40#include "libbb.h"
25#include "lazyload.h" 41#include "lazyload.h"
26 42
@@ -31,12 +47,17 @@ int suw32_main(int argc UNUSED_PARAM, char **argv)
31 unsigned opts, c_opt; 47 unsigned opts, c_opt;
32 char *command, *bb_path, *cwd; 48 char *command, *bb_path, *cwd;
33 DECLARE_PROC_ADDR(BOOL, ShellExecuteExA, SHELLEXECUTEINFOA *); 49 DECLARE_PROC_ADDR(BOOL, ShellExecuteExA, SHELLEXECUTEINFOA *);
50#if ENABLE_SUSH
51 int is_sush = applet_name[2];
52#else
53 const int is_sush = 0;
54#endif
34 55
35 opts = getopt32(argv, "c"); 56 opts = getopt32(argv, "c");
36 c_opt = opts & 1; 57 c_opt = opts & 1;
37 argv += optind; 58 argv += optind;
38 command = c_opt ? *argv++ : NULL; 59 command = c_opt ? *argv++ : NULL;
39 if ((c_opt && !command) || (!c_opt && command) || *argv) { 60 if ((c_opt && !command) || (!c_opt && command) || (!is_sush && *argv)) {
40 // -c without CMD, operand without -c , or surplus arguments 61 // -c without CMD, operand without -c , or surplus arguments
41 bb_show_usage(); 62 bb_show_usage();
42 } 63 }
@@ -69,6 +90,13 @@ int suw32_main(int argc UNUSED_PARAM, char **argv)
69 info.lpParameters = xappendword(info.lpParameters, "-s -c --"); 90 info.lpParameters = xappendword(info.lpParameters, "-s -c --");
70 info.lpParameters = xappendword(info.lpParameters, quote_arg(command)); 91 info.lpParameters = xappendword(info.lpParameters, quote_arg(command));
71 } 92 }
93#if ENABLE_SUSH
94 while (*argv) {
95 char *a = quote_arg(*argv++);
96 info.lpParameters = xappendword(info.lpParameters, a);
97 free(a);
98 }
99#endif
72 /* info.lpDirectory = NULL; */ 100 /* info.lpDirectory = NULL; */
73 info.nShow = SW_SHOWNORMAL; 101 info.nShow = SW_SHOWNORMAL;
74 102