aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2023-04-25 09:17:36 +0100
committerRon Yorston <rmy@pobox.com>2023-04-25 09:17:36 +0100
commit0521050e78cfa153ad281abc0d6cfe9d2fc2e293 (patch)
tree0c8394710136e9d4daba31457018c147badb7560
parent0575aaaa0779812752427badbc0f80a09aac02a4 (diff)
downloadbusybox-w32-su_cmd3.tar.gz
busybox-w32-su_cmd3.tar.bz2
busybox-w32-su_cmd3.zip
su: allow command file and argumentssu_cmd3
The real su allows a command file to be run, with arguments given on the command line. Similarly it allows the script run with '-c' to take arguments. Permit the same in the Windows implementation. For compatibility this requires a user name to be specified, even though we only support elevation. The user name must be 'root'. Adds 128-144 bytes. (GitHub PR #317)
-rw-r--r--loginutils/suw32.c37
1 files changed, 28 insertions, 9 deletions
diff --git a/loginutils/suw32.c b/loginutils/suw32.c
index 3500c08db..9a81c9a06 100644
--- a/loginutils/suw32.c
+++ b/loginutils/suw32.c
@@ -16,7 +16,7 @@
16//kbuild:lib-$(CONFIG_SUW32) += suw32.o 16//kbuild:lib-$(CONFIG_SUW32) += suw32.o
17 17
18//usage:#define suw32_trivial_usage 18//usage:#define suw32_trivial_usage
19//usage: "[-c \"CMD\"]" 19//usage: "[-c 'CMD'] [root [FILE ARGS | ARG0 ARGS]"
20//usage:#define suw32_full_usage "\n\n" 20//usage:#define suw32_full_usage "\n\n"
21//usage: "Run shell with elevated privileges\n" 21//usage: "Run shell with elevated privileges\n"
22//usage: "\n -c CMD Command to pass to 'sh -c'" 22//usage: "\n -c CMD Command to pass to 'sh -c'"
@@ -29,12 +29,17 @@ int suw32_main(int argc UNUSED_PARAM, char **argv)
29{ 29{
30 char *opt_command = NULL; 30 char *opt_command = NULL;
31 SHELLEXECUTEINFO info; 31 SHELLEXECUTEINFO info;
32 char *bb_path, *cwd; 32 char *bb_path, *cwd, *q, *args;
33 DECLARE_PROC_ADDR(BOOL, ShellExecuteExA, SHELLEXECUTEINFOA *); 33 DECLARE_PROC_ADDR(BOOL, ShellExecuteExA, SHELLEXECUTEINFOA *);
34 34
35 getopt32(argv, "c:", &opt_command); 35 getopt32(argv, "c:", &opt_command);
36 if (argv[optind]) 36 argv += optind;
37 bb_show_usage(); 37 if (argv[0]) {
38 if (strcmp(argv[0], "root") != 0) {
39 bb_error_msg_and_die("unknown user '%s'", argv[0]);
40 }
41 ++argv;
42 }
38 43
39 /* ShellExecuteEx() needs backslash as separator in UNC paths. */ 44 /* ShellExecuteEx() needs backslash as separator in UNC paths. */
40 bb_path = xstrdup(bb_busybox_exec_path); 45 bb_path = xstrdup(bb_busybox_exec_path);
@@ -57,11 +62,25 @@ int suw32_main(int argc UNUSED_PARAM, char **argv)
57 * privileges. 62 * privileges.
58 */ 63 */
59 cwd = xmalloc_realpath(getcwd(NULL, 0)); 64 cwd = xmalloc_realpath(getcwd(NULL, 0));
60 info.lpParameters = 65 q = quote_arg(cwd);
61 xasprintf("--busybox ash -d \"%s\" -t \"BusyBox ash (Admin)\" ", cwd); 66 args = xasprintf("--busybox ash -d %s -t \"BusyBox ash (Admin)\"", q);
62 if (opt_command) 67 free(q);
63 info.lpParameters = 68 free(cwd);
64 xasprintf("%s -s -c \"%s\"", info.lpParameters, opt_command); 69
70 if (opt_command) {
71 args = xappendword(args, "-s -c");
72 q = quote_arg(opt_command);
73 args = xappendword(args, q);
74 free(q);
75 }
76
77 while (*argv) {
78 q = quote_arg(*argv++);
79 args = xappendword(args, q);
80 free(q);
81 }
82
83 info.lpParameters = args;
65 /* info.lpDirectory = NULL; */ 84 /* info.lpDirectory = NULL; */
66 info.nShow = SW_SHOWNORMAL; 85 info.nShow = SW_SHOWNORMAL;
67 86