mirror of
https://github.com/troglobit/finit.git
synced 2026-11-23 20:11:44 +00:00
tmpfiles: skip any entry with an unknown user
What an unknown user in an entry did depended on the type. A d entry
was skipped, but this one made a file owned by root:
f /run/frr/state 0640 frr frr
The user was looked up in each type on its own, and only d checked
the result.
Look it up once for the entry, and skip the entry when the user is
not known. An unknown group leaves the group of the path as it is,
for a new path that is the group of root, as before. Both are only
reported with --debug, Finit's own files have entries for services
that may not be installed.
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
4 files changed
+36
-27
No files matched your search
+22
-24
@@ -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);
|
||||
|
||||
|
||||
Reference in new issue
Block a user