summaryrefslogtreecommitdiffstats
path: root/cmds
diff options
context:
space:
mode:
authorNick Kralevich <nnk@google.com>2010-10-21 09:14:14 -0700
committerNick Kralevich <nnk@google.com>2010-10-21 09:14:14 -0700
commit77d87aa7ff352a4867d8a6e2a73fadeb3152c7eb (patch)
tree809de938ab5423ad572376b636b923b65d302f69 /cmds
parent74b1ed3231b8cafcf4e5cb3f03d794acd5080004 (diff)
downloadframeworks_base-77d87aa7ff352a4867d8a6e2a73fadeb3152c7eb.zip
frameworks_base-77d87aa7ff352a4867d8a6e2a73fadeb3152c7eb.tar.gz
frameworks_base-77d87aa7ff352a4867d8a6e2a73fadeb3152c7eb.tar.bz2
allow dumpstate to work for non-root users.
Change-Id: Iaad4a097f5e09914842955dafbc0a09cc7a1db48
Diffstat (limited to 'cmds')
-rw-r--r--cmds/dumpstate/dumpstate.c28
1 files changed, 15 insertions, 13 deletions
diff --git a/cmds/dumpstate/dumpstate.c b/cmds/dumpstate/dumpstate.c
index 822f62d..0723f67 100644
--- a/cmds/dumpstate/dumpstate.c
+++ b/cmds/dumpstate/dumpstate.c
@@ -216,19 +216,21 @@ int main(int argc, char *argv[]) {
fclose(cmdline);
}
- /* switch to non-root user and group */
- gid_t groups[] = { AID_LOG, AID_SDCARD_RW, AID_MOUNT };
- if (setgroups(sizeof(groups)/sizeof(groups[0]), groups) != 0) {
- LOGE("Unable to setgroups, aborting: %s\n", strerror(errno));
- return -1;
- }
- if (setgid(AID_SHELL) != 0) {
- LOGE("Unable to setgid, aborting: %s\n", strerror(errno));
- return -1;
- }
- if (setuid(AID_SHELL) != 0) {
- LOGE("Unable to setuid, aborting: %s\n", strerror(errno));
- return -1;
+ if (getuid() == 0) {
+ /* switch to non-root user and group */
+ gid_t groups[] = { AID_LOG, AID_SDCARD_RW, AID_MOUNT };
+ if (setgroups(sizeof(groups)/sizeof(groups[0]), groups) != 0) {
+ LOGE("Unable to setgroups, aborting: %s\n", strerror(errno));
+ return -1;
+ }
+ if (setgid(AID_SHELL) != 0) {
+ LOGE("Unable to setgid, aborting: %s\n", strerror(errno));
+ return -1;
+ }
+ if (setuid(AID_SHELL) != 0) {
+ LOGE("Unable to setuid, aborting: %s\n", strerror(errno));
+ return -1;
+ }
}
char path[PATH_MAX], tmp_path[PATH_MAX];