diff options
author | Ron Yorston <rmy@pobox.com> | 2019-03-09 11:02:31 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2019-03-09 11:02:31 +0000 |
commit | 8fcbe777412b301e5dddd4931b2e1016802141b8 (patch) | |
tree | bdad2a8f74c37d0af45fcf32db6acf4ee5624990 | |
parent | 0f9bc90f097e2d3d4162757cd42941afb9358552 (diff) | |
download | busybox-w32-8fcbe777412b301e5dddd4931b2e1016802141b8.tar.gz busybox-w32-8fcbe777412b301e5dddd4931b2e1016802141b8.tar.bz2 busybox-w32-8fcbe777412b301e5dddd4931b2e1016802141b8.zip |
win32: add a function to detect running with elevated privileges
Add is_admin() and use it to alter the command prompt in the line
editor when running with admin privileges.
-rw-r--r-- | include/mingw.h | 1 | ||||
-rw-r--r-- | libbb/lineedit.c | 3 | ||||
-rw-r--r-- | win32/mingw.c | 18 |
3 files changed, 22 insertions, 0 deletions
diff --git a/include/mingw.h b/include/mingw.h index 9bc5eb018..52759b7b1 100644 --- a/include/mingw.h +++ b/include/mingw.h | |||
@@ -520,3 +520,4 @@ ULONGLONG CompatGetTickCount64(void); | |||
520 | ssize_t get_random_bytes(void *buf, ssize_t count); | 520 | ssize_t get_random_bytes(void *buf, ssize_t count); |
521 | int enumerate_links(const char *file, char *name); | 521 | int enumerate_links(const char *file, char *name); |
522 | void hide_console(void); | 522 | void hide_console(void); |
523 | int is_admin(void); | ||
diff --git a/libbb/lineedit.c b/libbb/lineedit.c index 95f92aa75..9e24d410d 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c | |||
@@ -45,6 +45,9 @@ | |||
45 | # define _POSIX_VDISABLE '\0' | 45 | # define _POSIX_VDISABLE '\0' |
46 | #endif | 46 | #endif |
47 | 47 | ||
48 | #if ENABLE_PLATFORM_MINGW32 | ||
49 | # define geteuid() (is_admin() ? 0 : DEFAULT_UID) | ||
50 | #endif | ||
48 | 51 | ||
49 | #ifdef TEST | 52 | #ifdef TEST |
50 | # define ENABLE_FEATURE_EDITING 0 | 53 | # define ENABLE_FEATURE_EDITING 0 |
diff --git a/win32/mingw.c b/win32/mingw.c index 44356d6b0..b50c1ecee 100644 --- a/win32/mingw.c +++ b/win32/mingw.c | |||
@@ -1576,3 +1576,21 @@ void hide_console(void) | |||
1576 | } | 1576 | } |
1577 | } | 1577 | } |
1578 | #endif | 1578 | #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 | } | ||