From 7206f745a2ecb23719598862a6a5c2f0b8fefe3c Mon Sep 17 00:00:00 2001 From: Aaron Andersen Date: Fri, 16 Jan 2026 16:50:08 -0500 Subject: [PATCH] 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. --- src/tmpfiles.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/tmpfiles.c b/src/tmpfiles.c index 6d7a01ae..12ee845f 100644 --- a/src/tmpfiles.c +++ b/src/tmpfiles.c @@ -577,8 +577,24 @@ static void tmpfiles(char *line) if (glob(path, GLOB_NOESCAPE, NULL, &gl)) break; - for (size_t i = 0; i < gl.gl_pathc; i++) - rc += mksubsys(gl.gl_pathv[i], mode ?: 0755, user, group); + for (size_t i = 0; i < gl.gl_pathc; i++) { + char *p = gl.gl_pathv[i]; + int uid, gid; + + /* e only adjusts existing directories */ + if (!fisdir(p)) + continue; + + uid = parse_uid(user); + gid = parse_gid(group); + if (gid < 0) + gid = 0; + + if (mode) + chmod(p, mode); + if (uid >= 0 && chown(p, uid, gid)) + warn("Failed chown(%s, %d, %d)", p, uid, gid); + } break; case 'f': case 'F':