diff --git a/doc/ChangeLog.md b/doc/ChangeLog.md index 8b8f40c5..48fb72e4 100644 --- a/doc/ChangeLog.md +++ b/doc/ChangeLog.md @@ -263,6 +263,9 @@ All relevant changes are documented in this file. file or in the files after it. Such an entry is now skipped with a warning - Fix `tmpfiles --clean` cleaning other file systems mounted below the directory of an entry, it now stays on the file system of the directory +- Fix tmpfiles entries with an unknown user: `d` skipped the entry, but `f` + created the file owned by root and `e` set the group anyway. All of them + now skip the entry. An unknown group still only leaves the group as it is - Fix age `0` in a tmpfiles entry, it was read as no age. As in tmpfiles.d(5), `tmpfiles --clean` now empties the directory of such an entry diff --git a/doc/tmpfiles-todo.md b/doc/tmpfiles-todo.md index 8a089ef0..1d5112ea 100644 --- a/doc/tmpfiles-todo.md +++ b/doc/tmpfiles-todo.md @@ -29,9 +29,6 @@ user to call it from cron. mode * User and group `:name`, only when creating: looked up as the name `:name`, which fails. For `d` the directory is then not created -* An unknown group becomes root, an unknown user makes `d` skip the - entry while `e` and `f` go on. Warn and leave the owner alone in - all of them 3. Mode and owner not applied diff --git a/src/tmpfiles.c b/src/tmpfiles.c index 0dda8818..a4efdde0 100644 --- a/src/tmpfiles.c +++ b/src/tmpfiles.c @@ -331,8 +331,7 @@ static int parse_uid(const char *user) /** * Parse group string - supports both names and numeric GIDs. - * Returns GID on success, 0 for an unknown group, and -1 when no - * group is given. + * Returns GID on success, -1 on failure or when no group is given. */ static int parse_gid(const char *group) { @@ -347,9 +346,7 @@ static int parse_gid(const char *group) return val; /* Not numeric, look up by name */ - val = getgroup(group); - - return val < 0 ? 0 : val; + return getgroup(group); } /* What the x and X entries keep from being cleaned */ @@ -769,6 +766,7 @@ static void tmpfiles(char *line) int major, minor; int strc, rc = 0; int plus = 0, boot = 0; + int uid, gid; mode_t mode = 0; FILE *fp = NULL; char buf[1024]; @@ -818,6 +816,20 @@ static void tmpfiles(char *line) if (group && !strcmp(group, "-")) group = NULL; + /* + * Quiet about it, Finit's own files have entries for users of + * services that may not be installed, and for the utmp group + */ + uid = parse_uid(user); + if (user && uid < 0) { + if (debug) + warnx("Unknown user %s, skipping %s", user, path); + return; + } + gid = parse_gid(group); + if (group && gid < 0 && debug) + warnx("Unknown group %s, not setting the group of %s", group, path); + age = strtok(NULL, "\t "); arg = strtok(NULL, "\n"); if (arg) { @@ -948,31 +960,20 @@ static void tmpfiles(char *line) break; case 'd': case 'D': { - int uid, gid; mode_t omask; mkparent(path, 0755); omask = umask(0); - uid = parse_uid(user); - if (!user || uid >= 0) { - gid = parse_gid(group); - - rc = makedir(path, mode ?: 0755); - if (!rc && dirperm(path, mode, uid, gid)) - warn("Failed setting mode/owner on %s", path); - } + rc = makedir(path, mode ?: 0755); + if (!rc && dirperm(path, mode, uid, gid)) + warn("Failed setting mode/owner on %s", path); umask(omask); break; } - case 'e': { - int uid, gid; - + case 'e': if (glob(path, GLOB_NOESCAPE, NULL, &gl)) break; - uid = parse_uid(user); - gid = parse_gid(group); - for (size_t i = 0; i < gl.gl_pathc; i++) { char *p = gl.gl_pathv[i]; @@ -982,11 +983,10 @@ static void tmpfiles(char *line) } globfree(&gl); break; - } case 'f': case 'F': { int flags = O_WRONLY | O_CREAT | O_NOFOLLOW | O_CLOEXEC; - int fd, uid, gid; + int fd; if (plus || type[0] == 'F') { flags |= O_TRUNC; /* create or truncate */ @@ -1012,8 +1012,6 @@ static void tmpfiles(char *line) write_arg(fp, arg); - uid = parse_uid(user); - gid = parse_gid(group); if (fdperm(fd, mode, uid, gid)) warn("Failed setting mode/owner on %s", path); diff --git a/test/tmpfiles-perm.sh b/test/tmpfiles-perm.sh index d6c5ff57..48bc2796 100755 --- a/test/tmpfiles-perm.sh +++ b/test/tmpfiles-perm.sh @@ -39,3 +39,14 @@ assert_perm "d $DIR - bin" 750 bin:daemon assert_perm "d $DIR - - sys" 750 bin:sys assert_perm "e $DIR" 750 bin:sys assert_perm "d $DIR 1777 root root" 1777 root:root + +sep +say 'An unknown user skips the entry, an unknown group only the group' +run "cat > $CONF" <