mirror of
https://github.com/troglobit/finit.git
synced 2026-10-07 08:04:22 +07:00
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.
This commit is contained in:
+12
-4
@@ -601,10 +601,6 @@ static void tmpfiles(char *line)
|
||||
mkparent(path, 0755);
|
||||
if (type[1] == '+' || type[0] == 'F') {
|
||||
/* f+/F will create or truncate the file */
|
||||
if (!arg) {
|
||||
rc = create(path, mode ?: 0644, user, group);
|
||||
break;
|
||||
}
|
||||
fp = fopen(path, "w+");
|
||||
} else {
|
||||
/* f will create the file if it doesn't exist */
|
||||
@@ -613,8 +609,20 @@ static void tmpfiles(char *line)
|
||||
}
|
||||
|
||||
if (fp) {
|
||||
int uid, gid;
|
||||
|
||||
write_arg(fp, arg);
|
||||
rc = fclose(fp);
|
||||
|
||||
/* Apply mode and ownership */
|
||||
if (mode)
|
||||
chmod(path, mode);
|
||||
uid = parse_uid(user);
|
||||
gid = parse_gid(group);
|
||||
if (gid < 0)
|
||||
gid = 0;
|
||||
if (uid >= 0 && chown(path, uid, gid))
|
||||
warn("Failed chown(%s, %d, %d)", path, uid, gid);
|
||||
}
|
||||
break;
|
||||
case 'l': /* Finit extension, like 'L' but only if target exists */
|
||||
|
||||
Reference in New Issue
Block a user