X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Ftmpfiles.c;h=61711401858efea68068adf95ec9d92718140464;hb=66ccd0387e528567dff92239e85c962d2f140ef1;hp=a1b2f8b1d27ef3cc9236f8ea1c224cf556b6c318;hpb=ddd88763921a1534081ed28e36f6712a85449005;p=elogind.git diff --git a/src/tmpfiles.c b/src/tmpfiles.c index a1b2f8b1d..617114018 100644 --- a/src/tmpfiles.c +++ b/src/tmpfiles.c @@ -50,7 +50,7 @@ * properly owned directories beneath /tmp, /var/tmp, /run, which are * volatile and hence need to be recreated on bootup. */ -enum { +typedef enum ItemType { /* These ones take file names */ CREATE_FILE = 'f', TRUNCATE_FILE = 'F', @@ -62,10 +62,10 @@ enum { IGNORE_PATH = 'x', REMOVE_PATH = 'r', RECURSIVE_REMOVE_PATH = 'R' -}; +} ItemType; typedef struct Item { - char type; + ItemType type; char *path; uid_t uid; @@ -90,7 +90,7 @@ static const char *arg_prefix = NULL; #define MAX_DEPTH 256 -static bool needs_glob(int t) { +static bool needs_glob(ItemType t) { return t == IGNORE_PATH || t == REMOVE_PATH || t == RECURSIVE_REMOVE_PATH; } @@ -157,6 +157,7 @@ static void load_unix_sockets(void) { } } + fclose(f); return; fail: @@ -586,7 +587,7 @@ static int remove_item(Item *i, const char *instance) { case TRUNCATE_DIRECTORY: case RECURSIVE_REMOVE_PATH: - if ((r = rm_rf(instance, false, i->type == RECURSIVE_REMOVE_PATH)) < 0 && + if ((r = rm_rf(instance, false, i->type == RECURSIVE_REMOVE_PATH, false)) < 0 && r != -ENOENT) { log_error("rm_rf(%s): %s", instance, strerror(-r)); return r; @@ -700,6 +701,7 @@ static bool item_equal(Item *a, Item *b) { static int parse_line(const char *fname, unsigned line, const char *buffer) { Item *i, *existing; char *mode = NULL, *user = NULL, *group = NULL, *age = NULL; + char type; Hashmap *h; int r; @@ -719,7 +721,7 @@ static int parse_line(const char *fname, unsigned line, const char *buffer) { "%ms " "%ms " "%ms", - &i->type, + &type, &i->path, &mode, &user, @@ -729,6 +731,7 @@ static int parse_line(const char *fname, unsigned line, const char *buffer) { r = -EIO; goto finish; } + i->type = type; if (i->type != CREATE_FILE && i->type != TRUNCATE_FILE && @@ -757,18 +760,11 @@ static int parse_line(const char *fname, unsigned line, const char *buffer) { } if (user && !streq(user, "-")) { - uid_t uid; - struct passwd *p; - - if (streq(user, "root") || streq(user, "0")) - i->uid = 0; - else if (parse_uid(user, &uid) >= 0) - i->uid = uid; - else if ((p = getpwnam(user))) - i->uid = p->pw_uid; - else { + const char *u = user; + + r = get_user_creds(&u, &i->uid, NULL, NULL); + if (r < 0) { log_error("[%s:%u] Unknown user '%s'.", fname, line, user); - r = -ENOENT; goto finish; } @@ -776,18 +772,11 @@ static int parse_line(const char *fname, unsigned line, const char *buffer) { } if (group && !streq(group, "-")) { - gid_t gid; - struct group *g; - - if (streq(group, "root") || streq(group, "0")) - i->gid = 0; - else if (parse_gid(group, &gid) >= 0) - i->gid = gid; - else if ((g = getgrnam(group))) - i->gid = g->gr_gid; - else { + const char *g = group; + + r = get_group_creds(&g, &i->gid); + if (r < 0) { log_error("[%s:%u] Unknown group '%s'.", fname, line, group); - r = -ENOENT; goto finish; } @@ -986,6 +975,8 @@ int main(int argc, char *argv[]) { log_parse_environment(); log_open(); + umask(0022); + label_init(); items = hashmap_new(string_hash_func, string_compare_func);