diff options
author | Ron Yorston <rmy@pobox.com> | 2019-03-08 11:38:10 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2019-03-08 11:38:10 +0000 |
commit | 5627c61f0b382593fa74757036dcd1ffbd9d9ad3 (patch) | |
tree | c41ecc5a74f986daa95b60e3936ff5e6a45567b7 /shell | |
parent | 0533794afd81b37684669ee0c5afc7a5e1ff159d (diff) | |
download | busybox-w32-5627c61f0b382593fa74757036dcd1ffbd9d9ad3.tar.gz busybox-w32-5627c61f0b382593fa74757036dcd1ffbd9d9ad3.tar.bz2 busybox-w32-5627c61f0b382593fa74757036dcd1ffbd9d9ad3.zip |
ash, su: add -d flag to set directory in ash, use it in su
When busybox-w32 is installed in C:/Windows/System32 su doesn't
run in the same directory as its parent as intended.
Work around this by adding a flag to the shell to set the working
directory.
Diffstat (limited to 'shell')
-rw-r--r-- | shell/ash.c | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/shell/ash.c b/shell/ash.c index b276544a6..b7fb29452 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -480,6 +480,9 @@ struct globals_misc { | |||
480 | int errlinno; | 480 | int errlinno; |
481 | 481 | ||
482 | char *minusc; /* argument to -c option */ | 482 | char *minusc; /* argument to -c option */ |
483 | #if ENABLE_PLATFORM_MINGW32 | ||
484 | char *dirarg; /* argument to -d option */ | ||
485 | #endif | ||
483 | 486 | ||
484 | char *curdir; // = nullstr; /* current working directory */ | 487 | char *curdir; // = nullstr; /* current working directory */ |
485 | char *physdir; // = nullstr; /* physical working directory */ | 488 | char *physdir; // = nullstr; /* physical working directory */ |
@@ -573,6 +576,9 @@ extern struct globals_misc *BB_GLOBAL_CONST ash_ptr_to_globals_misc; | |||
573 | #define loopnest (G_misc.loopnest ) | 576 | #define loopnest (G_misc.loopnest ) |
574 | #endif | 577 | #endif |
575 | #define minusc (G_misc.minusc ) | 578 | #define minusc (G_misc.minusc ) |
579 | #if ENABLE_PLATFORM_MINGW32 | ||
580 | #define dirarg (G_misc.dirarg ) | ||
581 | #endif | ||
576 | #define curdir (G_misc.curdir ) | 582 | #define curdir (G_misc.curdir ) |
577 | #define physdir (G_misc.physdir ) | 583 | #define physdir (G_misc.physdir ) |
578 | #define arg0 (G_misc.arg0 ) | 584 | #define arg0 (G_misc.arg0 ) |
@@ -11672,8 +11678,12 @@ options(int cmdline, int *login_sh) | |||
11672 | int val; | 11678 | int val; |
11673 | int c; | 11679 | int c; |
11674 | 11680 | ||
11675 | if (cmdline) | 11681 | if (cmdline) { |
11676 | minusc = NULL; | 11682 | minusc = NULL; |
11683 | #if ENABLE_PLATFORM_MINGW32 | ||
11684 | dirarg = NULL; | ||
11685 | #endif | ||
11686 | } | ||
11677 | while ((p = *argptr) != NULL) { | 11687 | while ((p = *argptr) != NULL) { |
11678 | c = *p++; | 11688 | c = *p++; |
11679 | if (c != '-' && c != '+') | 11689 | if (c != '-' && c != '+') |
@@ -11699,6 +11709,14 @@ options(int cmdline, int *login_sh) | |||
11699 | /* bash 3.2 indeed handles -c CMD and +c CMD the same */ | 11709 | /* bash 3.2 indeed handles -c CMD and +c CMD the same */ |
11700 | if (c == 'c' && cmdline) { | 11710 | if (c == 'c' && cmdline) { |
11701 | minusc = p; /* command is after shell args */ | 11711 | minusc = p; /* command is after shell args */ |
11712 | #if ENABLE_PLATFORM_MINGW32 | ||
11713 | /* Undocumented -d option to force current directory. | ||
11714 | * Must appear before -s or -c. */ | ||
11715 | } else if (c == 'd' && cmdline && val == 1) { | ||
11716 | if (*argptr == NULL) | ||
11717 | ash_msg_and_raise_error(bb_msg_requires_arg, "-d"); | ||
11718 | dirarg = *argptr++; | ||
11719 | #endif | ||
11702 | } else if (c == 'o') { | 11720 | } else if (c == 'o') { |
11703 | if (plus_minus_o(*argptr, val)) { | 11721 | if (plus_minus_o(*argptr, val)) { |
11704 | /* it already printed err message */ | 11722 | /* it already printed err message */ |
@@ -14956,12 +14974,21 @@ int ash_main(int argc UNUSED_PARAM, char **argv) | |||
14956 | hide_console(); | 14974 | hide_console(); |
14957 | #endif | 14975 | #endif |
14958 | 14976 | ||
14977 | #if ENABLE_PLATFORM_MINGW32 | ||
14978 | if (dirarg) { | ||
14979 | chdir(dirarg); | ||
14980 | setpwd(NULL, 0); | ||
14981 | } | ||
14982 | #endif | ||
14983 | |||
14959 | if (login_sh) { | 14984 | if (login_sh) { |
14960 | const char *hp; | 14985 | const char *hp; |
14961 | 14986 | ||
14962 | #if ENABLE_PLATFORM_MINGW32 | 14987 | #if ENABLE_PLATFORM_MINGW32 |
14963 | chdir(xgetpwuid(getuid())->pw_dir); | 14988 | if (!dirarg) { |
14964 | setpwd(NULL, 0); | 14989 | chdir(xgetpwuid(getuid())->pw_dir); |
14990 | setpwd(NULL, 0); | ||
14991 | } | ||
14965 | #endif | 14992 | #endif |
14966 | 14993 | ||
14967 | state = 1; | 14994 | state = 1; |