Skip to content

Commit 03765ef

Browse files
committed
tmpfiles: fix f/F to apply ownership when writing content
When f or F types write content to a file, the mode and ownership specified in the config should be applied. Previously, ownership was only applied when create() was used (i.e., when no argument was specified). Now we explicitly apply mode and ownership after writing content to the file. Signed-off-by: Aaron Andersen <[email protected]>
1 parent 1266d85 commit 03765ef

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/tmpfiles.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,8 +617,20 @@ static void tmpfiles(char *line)
617617
}
618618

619619
if (fp) {
620+
int uid, gid;
621+
620622
write_arg(fp, arg);
621623
rc = fclose(fp);
624+
625+
/* Apply mode and ownership */
626+
if (mode)
627+
chmod(path, mode);
628+
uid = parse_uid(user);
629+
gid = parse_gid(group);
630+
if (gid < 0)
631+
gid = 0;
632+
if (uid >= 0 && chown(path, uid, gid))
633+
warn("Failed chown(%s, %d, %d)", path, uid, gid);
622634
}
623635
break;
624636
case 'l': /* Finit extension, like 'L' but only if target exists */

0 commit comments

Comments
 (0)