diff options
author | Lennart Poettering <lennart@poettering.net> | 2019-04-29 13:21:40 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2019-04-30 09:18:23 +0200 |
commit | 8b364a38238bf828ae6df93fdbca7897bd8f042c (patch) | |
tree | a0adc9b6eeb87c6ceeae28691aa4cfe3d8a90b1f /src/tmpfiles | |
parent | 908665f4e93126bdd8f9ba08935394de26e7966f (diff) | |
download | systemd-8b364a38238bf828ae6df93fdbca7897bd8f042c.tar.gz systemd-8b364a38238bf828ae6df93fdbca7897bd8f042c.tar.bz2 systemd-8b364a38238bf828ae6df93fdbca7897bd8f042c.zip |
tmpfiles: split out ~ mode handling into a helper function
No change of behaviour, just some minor refactoring.
Diffstat (limited to 'src/tmpfiles')
-rw-r--r-- | src/tmpfiles/tmpfiles.c | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c index d9d1cc1c1a..e157714662 100644 --- a/src/tmpfiles/tmpfiles.c +++ b/src/tmpfiles/tmpfiles.c @@ -776,6 +776,20 @@ static bool hardlink_vulnerable(const struct stat *st) { return !S_ISDIR(st->st_mode) && st->st_nlink > 1 && dangerous_hardlinks(); } +static mode_t process_mask_perms(mode_t mode, mode_t current) { + + if ((current & 0111) == 0) + mode &= ~0111; + if ((current & 0222) == 0) + mode &= ~0222; + if ((current & 0444) == 0) + mode &= ~0444; + if (!S_ISDIR(current)) + mode &= ~07000; /* remove sticky/sgid/suid bit, unless directory */ + + return mode; +} + static int fd_set_perms(Item *i, int fd, const char *path, const struct stat *st) { struct stat stbuf; @@ -797,22 +811,16 @@ static int fd_set_perms(Item *i, int fd, const char *path, const struct stat *st "Refusing to set permissions on hardlinked file %s while the fs.protected_hardlinks sysctl is turned off.", path); + + if (i->mode_set) { if (S_ISLNK(st->st_mode)) log_debug("Skipping mode fix for symlink %s.", path); else { mode_t m = i->mode; - if (i->mask_perms) { - if (!(st->st_mode & 0111)) - m &= ~0111; - if (!(st->st_mode & 0222)) - m &= ~0222; - if (!(st->st_mode & 0444)) - m &= ~0444; - if (!S_ISDIR(st->st_mode)) - m &= ~07000; /* remove sticky/sgid/suid bit, unless directory */ - } + if (i->mask_perms) + m = process_mask_perms(m, st->st_mode); if (m == (st->st_mode & 07777)) log_debug("\"%s\" has correct mode %o already.", path, st->st_mode); |