aboutsummaryrefslogtreecommitdiff
path: root/loginutils
diff options
context:
space:
mode:
Diffstat (limited to 'loginutils')
-rw-r--r--loginutils/su.c1
-rw-r--r--loginutils/suw32.c67
2 files changed, 68 insertions, 0 deletions
diff --git a/loginutils/su.c b/loginutils/su.c
index 41291ea8f..2e1b309b0 100644
--- a/loginutils/su.c
+++ b/loginutils/su.c
@@ -8,6 +8,7 @@
8//config: bool "su (19 kb)" 8//config: bool "su (19 kb)"
9//config: default y 9//config: default y
10//config: select FEATURE_SYSLOG 10//config: select FEATURE_SYSLOG
11//config: depends on PLATFORM_POSIX
11//config: help 12//config: help
12//config: su is used to become another user during a login session. 13//config: su is used to become another user during a login session.
13//config: Invoked without a username, su defaults to becoming the super user. 14//config: Invoked without a username, su defaults to becoming the super user.
diff --git a/loginutils/suw32.c b/loginutils/suw32.c
new file mode 100644
index 000000000..de29f423a
--- /dev/null
+++ b/loginutils/suw32.c
@@ -0,0 +1,67 @@
1/* vi: set sw=4 ts=4: */
2/*
3 * Mini su implementation for busybox-w32
4 *
5 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
6 */
7//config:config SUW32
8//config: bool "su for Microsoft Windows"
9//config: default y
10//config: depends on PLATFORM_MINGW32 && ASH
11//config: help
12//config: su runs a shell with elevated privileges.
13
14//applet:IF_SUW32(APPLET_ODDNAME(su, suw32, BB_DIR_BIN, BB_SUID_DROP, suw32))
15
16//kbuild:lib-$(CONFIG_SUW32) += suw32.o
17
18//usage:#define suw32_trivial_usage
19//usage: "[-c \"CMD\"]"
20//usage:#define suw32_full_usage "\n\n"
21//usage: "Run shell with elevated privileges\n"
22//usage: "\n -c CMD Command to pass to 'sh -c'"
23
24#include "libbb.h"
25
26int suw32_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
27int suw32_main(int argc UNUSED_PARAM, char **argv)
28{
29 char *opt_command = NULL;
30 SHELLEXECUTEINFO info;
31 char *bb_path, *cwd;
32
33 getopt32(argv, "c:", &opt_command);
34 if (argv[optind])
35 bb_show_usage();
36
37 /* ShellExecuteEx() needs backslash as separator in UNC paths. */
38 bb_path = xstrdup(bb_busybox_exec_path);
39 slash_to_bs(bb_path);
40
41 memset(&info, 0, sizeof(SHELLEXECUTEINFO));
42 info.cbSize = sizeof(SHELLEXECUTEINFO);
43 /* info.fMask = SEE_MASK_DEFAULT; */
44 /* info.hwnd = NULL; */
45 info.lpVerb = "runas";
46 info.lpFile = bb_path;
47 /*
48 * It seems that when ShellExecuteEx() runs binaries residing in
49 * certain 'system' directories it sets the current directory of
50 * the process to %SYSTEMROOT%\System32. Override this by passing
51 * the directory we want to the shell.
52 *
53 * Canonicalise the directory now: if it's in a drive mapped to
54 * a network share it may not be available once we have elevated
55 * privileges.
56 */
57 cwd = xmalloc_realpath(getcwd(NULL, 0));
58 info.lpParameters =
59 xasprintf("--busybox ash -d \"%s\" -t \"BusyBox ash (Admin)\" ", cwd);
60 if (opt_command)
61 info.lpParameters =
62 xasprintf("%s -s -c \"%s\"", info.lpParameters, opt_command);
63 /* info.lpDirectory = NULL; */
64 info.nShow = SW_SHOWNORMAL;
65
66 return !ShellExecuteEx(&info);
67}