1
0
mirror of https://github.com/systemd/systemd.git synced 2024-12-23 21:35:11 +03:00

Merge pull request #8801 from fbuihuu/tmpfiles-fixes

Tmpfiles fixes
This commit is contained in:
Lennart Poettering 2018-04-24 17:29:10 +02:00 committed by GitHub
commit 9ea41a9bda
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 12 deletions

View File

@ -241,6 +241,21 @@ int fchmod_umask(int fd, mode_t m) {
return r;
}
int fchmod_opath(int fd, mode_t m) {
char procfs_path[strlen("/proc/self/fd/") + DECIMAL_STR_MAX(int)];
/* This function operates also on fd that might have been opened with
* O_PATH. Indeed fchmodat() doesn't have the AT_EMPTY_PATH flag like
* fchownat() does. */
xsprintf(procfs_path, "/proc/self/fd/%i", fd);
if (chmod(procfs_path, m) < 0)
return -errno;
return 0;
}
int fd_warn_permissions(const char *path, int fd) {
struct stat st;

View File

@ -33,6 +33,7 @@ int readlink_and_make_absolute(const char *p, char **r);
int chmod_and_chown(const char *path, mode_t mode, uid_t uid, gid_t gid);
int fchmod_umask(int fd, mode_t mode);
int fchmod_opath(int fd, mode_t m);
int fd_warn_permissions(const char *path, int fd);

View File

@ -808,15 +808,9 @@ static int fd_set_perms(Item *i, int fd, const struct stat *st) {
if (m == (st->st_mode & 07777))
log_debug("\"%s\" has correct mode %o already.", path, st->st_mode);
else {
char procfs_path[STRLEN("/proc/self/fd/") + DECIMAL_STR_MAX(int)];
log_debug("Changing \"%s\" to mode %o.", path, m);
/* fchmodat() still doesn't have AT_EMPTY_PATH flag. */
xsprintf(procfs_path, "/proc/self/fd/%i", fd);
if (chmod(procfs_path, m) < 0)
return log_error_errno(errno, "chmod() of %s via %s failed: %m", path, procfs_path);
if (fchmod_opath(fd, m) < 0)
return log_error_errno(errno, "fchmod() of %s failed: %m", path);
}
}
}
@ -865,6 +859,9 @@ static int path_set_perms(Item *i, const char *path) {
if (fstat(fd, &st) < 0)
return log_error_errno(errno, "Failed to fstat() file %s: %m", path);
if (i->type == EMPTY_DIRECTORY && !S_ISDIR(st.st_mode))
return log_error_errno(EEXIST, "'%s' already exists and is not a directory. ", path);
return fd_set_perms(i, fd, &st);
}
@ -1451,8 +1448,7 @@ static int create_item(Item *i) {
return r;
break;
case COPY_FILES: {
case COPY_FILES:
RUN_WITH_UMASK(0000)
(void) mkdir_parents_label(i->path, 0755);
@ -1574,7 +1570,7 @@ static int create_item(Item *i) {
_fallthrough_;
case EMPTY_DIRECTORY:
r = path_set_perms(i, i->path);
r = glob_item(i, path_set_perms);
if (q < 0)
return q;
if (r < 0)
@ -1625,7 +1621,6 @@ static int create_item(Item *i) {
return r;
break;
}
case CREATE_SYMLINK: {
RUN_WITH_UMASK(0000)