summaryrefslogtreecommitdiff
path: root/src/basic
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2017-10-10 10:05:43 +0200
committerGitHub <noreply@github.com>2017-10-10 10:05:43 +0200
commitb74023db06a0fae917c2e646a3c6ef307dbe1e57 (patch)
tree9ae6e31aed2ab9c0e731565dae23b7014977deef /src/basic
parente2c2d70ba7cc7497b03c4a377bfb529035540aa7 (diff)
parent4240cb02fda90ba11dfc0114201e42691132c6a9 (diff)
downloadsystemd-b74023db06a0fae917c2e646a3c6ef307dbe1e57.tar.gz
Merge pull request #7003 from yuwata/enable-dynamic-user
timesyncd, journal-upload: Enable DynamicUser=
Diffstat (limited to 'src/basic')
-rw-r--r--src/basic/mkdir-label.c4
-rw-r--r--src/basic/mkdir.c20
-rw-r--r--src/basic/mkdir.h6
3 files changed, 22 insertions, 8 deletions
diff --git a/src/basic/mkdir-label.c b/src/basic/mkdir-label.c
index aa6878cdf0..731269c81c 100644
--- a/src/basic/mkdir-label.c
+++ b/src/basic/mkdir-label.c
@@ -25,8 +25,8 @@
#include "label.h"
#include "mkdir.h"
-int mkdir_safe_label(const char *path, mode_t mode, uid_t uid, gid_t gid) {
- return mkdir_safe_internal(path, mode, uid, gid, mkdir_label);
+int mkdir_safe_label(const char *path, mode_t mode, uid_t uid, gid_t gid, bool follow_symlink) {
+ return mkdir_safe_internal(path, mode, uid, gid, follow_symlink, mkdir_label);
}
int mkdir_parents_label(const char *path, mode_t mode) {
diff --git a/src/basic/mkdir.c b/src/basic/mkdir.c
index 7db09fc6a1..fb3a9430ba 100644
--- a/src/basic/mkdir.c
+++ b/src/basic/mkdir.c
@@ -22,6 +22,7 @@
#include <string.h>
#include <sys/stat.h>
+#include "alloc-util.h"
#include "fs-util.h"
#include "macro.h"
#include "mkdir.h"
@@ -29,7 +30,7 @@
#include "stat-util.h"
#include "user-util.h"
-int mkdir_safe_internal(const char *path, mode_t mode, uid_t uid, gid_t gid, mkdir_func_t _mkdir) {
+int mkdir_safe_internal(const char *path, mode_t mode, uid_t uid, gid_t gid, bool follow_symlink, mkdir_func_t _mkdir) {
struct stat st;
int r;
@@ -42,6 +43,19 @@ int mkdir_safe_internal(const char *path, mode_t mode, uid_t uid, gid_t gid, mkd
if (lstat(path, &st) < 0)
return -errno;
+ if (follow_symlink && S_ISLNK(st.st_mode)) {
+ _cleanup_free_ char *p = NULL;
+
+ r = chase_symlinks(path, NULL, CHASE_NONEXISTENT, &p);
+ if (r < 0)
+ return r;
+ if (r == 0)
+ return mkdir_safe_internal(p, mode, uid, gid, false, _mkdir);
+
+ if (lstat(p, &st) < 0)
+ return -errno;
+ }
+
if ((st.st_mode & 0007) > (mode & 0007) ||
(st.st_mode & 0070) > (mode & 0070) ||
(st.st_mode & 0700) > (mode & 0700) ||
@@ -53,8 +67,8 @@ int mkdir_safe_internal(const char *path, mode_t mode, uid_t uid, gid_t gid, mkd
return 0;
}
-int mkdir_safe(const char *path, mode_t mode, uid_t uid, gid_t gid) {
- return mkdir_safe_internal(path, mode, uid, gid, mkdir);
+int mkdir_safe(const char *path, mode_t mode, uid_t uid, gid_t gid, bool follow_symlink) {
+ return mkdir_safe_internal(path, mode, uid, gid, follow_symlink, mkdir);
}
int mkdir_parents_internal(const char *prefix, const char *path, mode_t mode, mkdir_func_t _mkdir) {
diff --git a/src/basic/mkdir.h b/src/basic/mkdir.h
index d564a3547f..4e12b5e165 100644
--- a/src/basic/mkdir.h
+++ b/src/basic/mkdir.h
@@ -22,17 +22,17 @@
#include <sys/types.h>
-int mkdir_safe(const char *path, mode_t mode, uid_t uid, gid_t gid);
+int mkdir_safe(const char *path, mode_t mode, uid_t uid, gid_t gid, bool follow_symlink);
int mkdir_parents(const char *path, mode_t mode);
int mkdir_p(const char *path, mode_t mode);
/* mandatory access control(MAC) versions */
-int mkdir_safe_label(const char *path, mode_t mode, uid_t uid, gid_t gid);
+int mkdir_safe_label(const char *path, mode_t mode, uid_t uid, gid_t gid, bool follow_symlink);
int mkdir_parents_label(const char *path, mode_t mode);
int mkdir_p_label(const char *path, mode_t mode);
/* internally used */
typedef int (*mkdir_func_t)(const char *pathname, mode_t mode);
-int mkdir_safe_internal(const char *path, mode_t mode, uid_t uid, gid_t gid, mkdir_func_t _mkdir);
+int mkdir_safe_internal(const char *path, mode_t mode, uid_t uid, gid_t gid, bool follow_symlink, mkdir_func_t _mkdir);
int mkdir_parents_internal(const char *prefix, const char *path, mode_t mode, mkdir_func_t _mkdir);
int mkdir_p_internal(const char *prefix, const char *path, mode_t mode, mkdir_func_t _mkdir);