]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
copy: move sync_rights() to copy.c and rename copy_rights()
authorLennart Poettering <lennart@poettering.net>
Thu, 4 Mar 2021 17:52:10 +0000 (18:52 +0100)
committerLuca Boccassi <luca.boccassi@gmail.com>
Thu, 4 Mar 2021 22:35:52 +0000 (22:35 +0000)
It's so similar to copy_access(), hence let's move it over and rename it
in similar style to the rest of the functions.

No change in behaviour, just moving things over.

src/basic/copy.c
src/basic/copy.h
src/basic/fileio.c
src/basic/fileio.h
src/firstboot/firstboot.c
src/sysusers/sysusers.c

index b77a1769c6f1d4cde9c56a048d8bbe507b2ff055..109f44c32d8e2bb74bc409891f1d31d763cb0422 100644 (file)
@@ -1232,6 +1232,8 @@ int copy_access(int fdf, int fdt) {
         assert(fdf >= 0);
         assert(fdt >= 0);
 
+        /* Copies just the access mode (and not the ownership) from fdf to fdt */
+
         if (fstat(fdf, &st) < 0)
                 return -errno;
 
@@ -1241,6 +1243,20 @@ int copy_access(int fdf, int fdt) {
         return 0;
 }
 
+int copy_rights(int fdf, int fdt) {
+        struct stat st;
+
+        assert(fdf >= 0);
+        assert(fdt >= 0);
+
+        /* Copies both access mode and ownership from fdf to fdt */
+
+        if (fstat(fdf, &st) < 0)
+                return -errno;
+
+        return fchmod_and_chown(fdt, st.st_mode & 07777, st.st_uid, st.st_gid);
+}
+
 int copy_xattr(int fdf, int fdt) {
         _cleanup_free_ char *names = NULL;
         int ret = 0, r;
index b583dff2c09e966a1ce78956668f927247cc8707..da3ba07ad27868c27221756321cdad44a17d846d 100644 (file)
@@ -64,4 +64,5 @@ static inline int copy_bytes(int fdf, int fdt, uint64_t max_bytes, CopyFlags cop
 
 int copy_times(int fdf, int fdt, CopyFlags flags);
 int copy_access(int fdf, int fdt);
+int copy_rights(int fdf, int fdt);
 int copy_xattr(int fdf, int fdt);
index 596946ccf4982d6a6fc87e23413bdea34b48e2e5..8560982aab209b0f2624e7a4c2bc90018be1e303 100644 (file)
@@ -1327,15 +1327,6 @@ int warn_file_is_world_accessible(const char *filename, struct stat *st, const c
         return 0;
 }
 
-int sync_rights(int from, int to) {
-        struct stat st;
-
-        if (fstat(from, &st) < 0)
-                return -errno;
-
-        return fchmod_and_chown(to, st.st_mode & 07777, st.st_uid, st.st_gid);
-}
-
 int rename_and_apply_smack_floor_label(const char *from, const char *to) {
         int r = 0;
         if (rename(from, to) < 0)
index 498e88035483cfa5716dcb8f521613bafb4a2f88..64a30ab7bb12df0236c776366a733c5670c7da71 100644 (file)
@@ -118,6 +118,4 @@ int safe_fgetc(FILE *f, char *ret);
 
 int warn_file_is_world_accessible(const char *filename, struct stat *st, const char *unit, unsigned line);
 
-int sync_rights(int from, int to);
-
 int rename_and_apply_smack_floor_label(const char *temp_path, const char *dest_path);
index c0e88e7915d5d96b72636d2291769b3e2477470f..8cd5e28532884e1c0b49c6421324e26a753844f8 100644 (file)
@@ -675,7 +675,7 @@ static int write_root_passwd(const char *passwd_path, const char *password, cons
         if (original) {
                 struct passwd *i;
 
-                r = sync_rights(fileno(original), fileno(passwd));
+                r = copy_rights(fileno(original), fileno(passwd));
                 if (r < 0)
                         return r;
 
@@ -743,7 +743,7 @@ static int write_root_shadow(const char *shadow_path, const char *hashed_passwor
         if (original) {
                 struct spwd *i;
 
-                r = sync_rights(fileno(original), fileno(shadow));
+                r = copy_rights(fileno(original), fileno(shadow));
                 if (r < 0)
                         return r;
 
index 4e231be856ebd63f9f37f9660588f36b2aa78715..88e365c6626080b4277bfd327e78460df9bf5a6e 100644 (file)
@@ -393,7 +393,7 @@ static int write_temporary_passwd(const char *passwd_path, FILE **tmpfile, char
         original = fopen(passwd_path, "re");
         if (original) {
 
-                r = sync_rights(fileno(original), fileno(passwd));
+                r = copy_rights(fileno(original), fileno(passwd));
                 if (r < 0)
                         return r;
 
@@ -494,7 +494,7 @@ static int write_temporary_shadow(const char *shadow_path, FILE **tmpfile, char
         original = fopen(shadow_path, "re");
         if (original) {
 
-                r = sync_rights(fileno(original), fileno(shadow));
+                r = copy_rights(fileno(original), fileno(shadow));
                 if (r < 0)
                         return r;
 
@@ -590,7 +590,7 @@ static int write_temporary_group(const char *group_path, FILE **tmpfile, char **
         original = fopen(group_path, "re");
         if (original) {
 
-                r = sync_rights(fileno(original), fileno(group));
+                r = copy_rights(fileno(original), fileno(group));
                 if (r < 0)
                         return r;
 
@@ -688,7 +688,7 @@ static int write_temporary_gshadow(const char * gshadow_path, FILE **tmpfile, ch
         if (original) {
                 struct sgrp *sg;
 
-                r = sync_rights(fileno(original), fileno(gshadow));
+                r = copy_rights(fileno(original), fileno(gshadow));
                 if (r < 0)
                         return r;