am 62d0970c: Merge "allow dumpstate to work for non-root users." into gingerbread
Merge commit '62d0970c82f9a2c17aea67379c207a3f17556c46' into gingerbread-plus-aosp
* commit '62d0970c82f9a2c17aea67379c207a3f17556c46':
allow dumpstate to work for non-root users.
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 @@
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];