diff options
author | Ron Yorston <rmy@pobox.com> | 2019-03-10 09:58:13 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2019-03-10 13:04:55 +0000 |
commit | b04bbc0109046ee69806a472fd7e44313c646687 (patch) | |
tree | 6e7a1985aecdbee605ae58ce7cc342c5d4e23027 /win32 | |
parent | 399b1dd641c16113c3340933a9b1ab1793a13d8a (diff) | |
download | busybox-w32-b04bbc0109046ee69806a472fd7e44313c646687.tar.gz busybox-w32-b04bbc0109046ee69806a472fd7e44313c646687.tar.bz2 busybox-w32-b04bbc0109046ee69806a472fd7e44313c646687.zip |
win32: changes to user ids
Formalise the use of 0 as the uid of a process running with elevated
privileges:
- Rewrite getuid(2) to return DEFAULT_UID by default and 0 if the
process has elevated privileges.
- geteuid(2) and the corresponding functions for groups are aliases
for getuid(2).
- Change root's home directory to be whatever GetSystemDirectory()
returns, probably C:/Windows/System32 in most cases.
- Remove the special handling of geteuid(2) in the line editing code.
With these changes the shell started by 'su' is a lot more like a
*nix root shell.
Diffstat (limited to 'win32')
-rw-r--r-- | win32/mingw.c | 50 |
1 files changed, 30 insertions, 20 deletions
diff --git a/win32/mingw.c b/win32/mingw.c index b50c1ecee..84b059506 100644 --- a/win32/mingw.c +++ b/win32/mingw.c | |||
@@ -872,6 +872,25 @@ static char *get_user_name(void) | |||
872 | return user_name; | 872 | return user_name; |
873 | } | 873 | } |
874 | 874 | ||
875 | int getuid(void) | ||
876 | { | ||
877 | int ret = DEFAULT_UID; | ||
878 | HANDLE h; | ||
879 | |||
880 | if (OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &h)) { | ||
881 | TOKEN_ELEVATION elevation; | ||
882 | DWORD size = sizeof(TOKEN_ELEVATION); | ||
883 | |||
884 | if (GetTokenInformation(h, TokenElevation, &elevation, | ||
885 | sizeof(elevation), &size)) { | ||
886 | if (elevation.TokenIsElevated) | ||
887 | ret = 0; | ||
888 | } | ||
889 | CloseHandle(h); | ||
890 | } | ||
891 | return ret; | ||
892 | } | ||
893 | |||
875 | struct passwd *getpwnam(const char *name) | 894 | struct passwd *getpwnam(const char *name) |
876 | { | 895 | { |
877 | const char *myname; | 896 | const char *myname; |
@@ -892,8 +911,17 @@ struct passwd *getpwuid(uid_t uid) | |||
892 | static struct passwd p; | 911 | static struct passwd p; |
893 | 912 | ||
894 | if (uid == 0) { | 913 | if (uid == 0) { |
914 | static char *buf = NULL; | ||
915 | char dir[PATH_MAX]; | ||
916 | |||
917 | if (!buf) { | ||
918 | buf = xzalloc(PATH_MAX); | ||
919 | GetSystemDirectory(dir, PATH_MAX); | ||
920 | realpath(dir, buf); | ||
921 | } | ||
922 | |||
895 | p.pw_name = (char *)"root"; | 923 | p.pw_name = (char *)"root"; |
896 | p.pw_dir = (char *)"/"; | 924 | p.pw_dir = buf; |
897 | } | 925 | } |
898 | else if (uid == DEFAULT_UID && (p.pw_name=get_user_name()) != NULL) { | 926 | else if (uid == DEFAULT_UID && (p.pw_name=get_user_name()) != NULL) { |
899 | p.pw_dir = gethomedir(); | 927 | p.pw_dir = gethomedir(); |
@@ -949,7 +977,7 @@ int getgroups(int n, gid_t *groups) | |||
949 | return 1; | 977 | return 1; |
950 | } | 978 | } |
951 | 979 | ||
952 | groups[0] = DEFAULT_GID; | 980 | groups[0] = getgid(); |
953 | return 1; | 981 | return 1; |
954 | } | 982 | } |
955 | 983 | ||
@@ -1576,21 +1604,3 @@ void hide_console(void) | |||
1576 | } | 1604 | } |
1577 | } | 1605 | } |
1578 | #endif | 1606 | #endif |
1579 | |||
1580 | int is_admin(void) | ||
1581 | { | ||
1582 | int ret = FALSE; | ||
1583 | HANDLE h; | ||
1584 | |||
1585 | if (OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &h)) { | ||
1586 | TOKEN_ELEVATION elevation; | ||
1587 | DWORD size = sizeof(TOKEN_ELEVATION); | ||
1588 | |||
1589 | if (GetTokenInformation(h, TokenElevation, &elevation, | ||
1590 | sizeof(elevation), &size)) { | ||
1591 | ret = elevation.TokenIsElevated; | ||
1592 | } | ||
1593 | CloseHandle(h); | ||
1594 | } | ||
1595 | return ret; | ||
1596 | } | ||