X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=extras%2Fvolume_id%2Fvol_id.c;h=0427d70da199e312e518c5e48792350de9cc4e26;hp=7bdfda17e7ab5b967ac923935cbee08c7351e140;hb=e18e6d79996edeeb07e122f3582a688c3ef4f6b9;hpb=708cb3594139f28f7d99b4ea1cf91b4ccd032273 diff --git a/extras/volume_id/vol_id.c b/extras/volume_id/vol_id.c index 7bdfda17e..0427d70da 100644 --- a/extras/volume_id/vol_id.c +++ b/extras/volume_id/vol_id.c @@ -27,6 +27,8 @@ #include #include #include +#include +#include #include #include @@ -114,6 +116,7 @@ int main(int argc, char *argv[]) " -t filesystem type\n" " -l filesystem label\n" " -u filesystem uuid\n" + " -L raw label\n" " --skip-raid don't probe for raid\n" " --probe-all find possibly conflicting signatures\n" " --help\n" @@ -123,6 +126,7 @@ int main(int argc, char *argv[]) PRINT_TYPE, PRINT_LABEL, PRINT_UUID, + PRINT_RAW_LABEL, } print = PRINT_EXPORT; struct volume_id *vid = NULL; static char name[VOLUME_ID_LABEL_SIZE]; @@ -131,8 +135,7 @@ int main(int argc, char *argv[]) int skip_raid = 0; int probe_all = 0; const char *node = NULL; - uid_t nobody_uid; - gid_t nobody_gid; + struct passwd *pw; int retval; int rc = 0; @@ -152,6 +155,8 @@ int main(int argc, char *argv[]) print = PRINT_LABEL; } else if (strcmp(arg, "-u") == 0) { print = PRINT_UUID; + } else if (strcmp(arg, "-L") == 0) { + print = PRINT_RAW_LABEL; } else if (strcmp(arg, "--skip-raid") == 0) { skip_raid = 1; } else if (strcmp(arg, "--probe-all") == 0) { @@ -178,15 +183,17 @@ int main(int argc, char *argv[]) if (ioctl(vid->fd, BLKGETSIZE64, &size) != 0) size = 0; - dbg("BLKGETSIZE64=%llu", size); + dbg("BLKGETSIZE64=%llu", (unsigned long long)size); - /* drop all privileges */ - nobody_uid = lookup_user("nobody"); - nobody_gid = lookup_group("nogroup"); - if (nobody_uid > 0 && nobody_gid > 0) { + /* 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(nobody_gid) != 0 || - setuid(nobody_uid) != 0) { + setgid(pw->pw_gid) != 0 || + setuid(pw->pw_uid) != 0) { + fprintf(stderr, "error dropping privileges: %s\n", strerror(errno)); rc = 3; goto exit; } @@ -304,6 +311,13 @@ int main(int argc, char *argv[]) } printf("%s\n", vid->uuid); break; + case PRINT_RAW_LABEL: + if (vid->label[0] == '\0' || vid->usage_id == VOLUME_ID_RAID) { + rc = 3; + goto exit; + } + printf("%s\n", vid->label); + break; } exit: