chiark / gitweb /
Prep v239: fs-util: Mask new chase_symlinks_and_*() functions.
[elogind.git] / src / basic / fs-util.c
index 942f43ae938f4d56005ce86bff35dae2e8b70974..a82d3a14eb22cde90b6711acf8f142d883f76722 100644 (file)
@@ -234,6 +234,22 @@ int chmod_and_chown(const char *path, mode_t mode, uid_t uid, gid_t gid) {
         return 0;
 }
 
+int fchmod_and_chown(int fd, mode_t mode, uid_t uid, gid_t gid) {
+        /* Under the assumption that we are running privileged we
+         * first change the access mode and only then hand out
+         * ownership to avoid a window where access is too open. */
+
+        if (mode != MODE_INVALID)
+                if (fchmod(fd, mode) < 0)
+                        return -errno;
+
+        if (uid != UID_INVALID || gid != GID_INVALID)
+                if (fchown(fd, uid, gid) < 0)
+                        return -errno;
+
+        return 0;
+}
+
 int fchmod_umask(int fd, mode_t m) {
         mode_t u;
         int r;
@@ -942,6 +958,7 @@ chased_one:
         return 0;
 }
 
+#if 0 /// UNNEEDED by elogind
 int chase_symlinks_and_open(
                 const char *path,
                 const char *root,
@@ -1061,6 +1078,7 @@ int chase_symlinks_and_stat(
 
         return 1;
 }
+#endif // 0
 
 int access_fd(int fd, int mode) {
         char p[STRLEN("/proc/self/fd/") + DECIMAL_STR_MAX(fd) + 1];