Skip to content

Commit 1266d85

Browse files
committed
tmpfiles: fix 'e' type to only adjust existing directories
According to tmpfiles.d(5), the 'e' type adjusts the mode and ownership of existing paths but should not create them. Previously, mksubsys() was used which could create directories. Now we explicitly check if the path is an existing directory before adjusting its permissions. Signed-off-by: Aaron Andersen <[email protected]>
1 parent 172ae51 commit 1266d85

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/tmpfiles.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -581,8 +581,24 @@ static void tmpfiles(char *line)
581581
if (glob(path, GLOB_NOESCAPE, NULL, &gl))
582582
break;
583583

584-
for (size_t i = 0; i < gl.gl_pathc; i++)
585-
rc += mksubsys(gl.gl_pathv[i], mode ?: 0755, user, group);
584+
for (size_t i = 0; i < gl.gl_pathc; i++) {
585+
char *p = gl.gl_pathv[i];
586+
int uid, gid;
587+
588+
/* e only adjusts existing directories */
589+
if (!fisdir(p))
590+
continue;
591+
592+
uid = parse_uid(user);
593+
gid = parse_gid(group);
594+
if (gid < 0)
595+
gid = 0;
596+
597+
if (mode)
598+
chmod(p, mode);
599+
if (uid >= 0 && chown(p, uid, gid))
600+
warn("Failed chown(%s, %d, %d)", p, uid, gid);
601+
}
586602
break;
587603
case 'f':
588604
case 'F':

0 commit comments

Comments
 (0)