summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Zeuthen <david@fubar.dk>2007-06-07 00:56:20 +0200
committerKay Sievers <kay.sievers@vrfy.org>2007-06-07 00:56:20 +0200
commit1fdce2f39dd5be0a722d34866e8823c4760738f2 (patch)
tree38be3788f76e3b06f5e52ed9ae147a10da177f91
parente883be3e1387328c5042bc76c18e7beb157bbddc (diff)
vol_id: do not fail if unable to drop privileges
-rw-r--r--extras/volume_id/vol_id.c20
1 files changed, 9 insertions, 11 deletions
diff --git a/extras/volume_id/vol_id.c b/extras/volume_id/vol_id.c
index e17e7abb0c..38950ee85f 100644
--- a/extras/volume_id/vol_id.c
+++ b/extras/volume_id/vol_id.c
@@ -154,7 +154,6 @@ int main(int argc, char *argv[])
int skip_raid = 0;
int probe_all = 0;
const char *node;
- struct passwd *pw;
int fd;
const char *label, *uuid, *type, *type_version, *usage;
int retval;
@@ -237,16 +236,15 @@ int main(int argc, char *argv[])
dbg("BLKGETSIZE64=%llu", (unsigned long long)size);
/* try to drop all privileges before reading disk content */
- pw = getpwnam ("nobody");
- if (pw != NULL && pw->pw_uid > 0 && pw->pw_gid > 0) {
- dbg("dropping privileges to %u:%u",
- (unsigned int)pw->pw_uid, (unsigned int)pw->pw_gid);
- if (setgroups(0, NULL) != 0 ||
- setgid(pw->pw_gid) != 0 ||
- setuid(pw->pw_uid) != 0) {
- fprintf(stderr, "error dropping privileges: %s\n", strerror(errno));
- rc = 3;
- goto exit;
+ if (getuid() == 0) {
+ struct passwd *pw;
+
+ pw = getpwnam("nobody");
+ if (pw != NULL && pw->pw_uid > 0 && pw->pw_gid > 0) {
+ if (setgroups(0, NULL) != 0 ||
+ setgid(pw->pw_gid) != 0 ||
+ setuid(pw->pw_uid) != 0)
+ info("unable to drop privileges: %s\n", strerror(errno));
}
}