]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/copydir.c: Cosmetic
authorAlejandro Colomar <alx@kernel.org>
Sat, 2 Sep 2023 12:58:55 +0000 (14:58 +0200)
committerIker Pedrosa <ikerpedrosam@gmail.com>
Mon, 4 Dec 2023 10:45:09 +0000 (11:45 +0100)
I was investigating a warning in this function, but the code was
inscrutable.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/copydir.c

index a5ea7efba21cab67e42909c8e86fc8084216ea13..c485088baa4613d3f9a91ef869dc1c564aafdeff 100644 (file)
@@ -673,6 +673,7 @@ static int copy_hardlink (const struct path_info *dst,
        return 0;
 }
 
+
 /*
  * copy_special - copy a special file
  *
@@ -683,29 +684,33 @@ static int copy_hardlink (const struct path_info *dst,
  *
  *     Return 0 on success, -1 on error.
  */
-static int copy_special (const struct path_info *src, const struct path_info *dst,
-                         bool reset_selinux,
-                         const struct stat *statp, const struct timespec mt[],
-                         uid_t old_uid, uid_t new_uid,
-                         gid_t old_gid, gid_t new_gid)
+static int
+copy_special(const struct path_info *src, const struct path_info *dst,
+             bool reset_selinux,
+             const struct stat *statp, const struct timespec mt[],
+             uid_t old_uid, uid_t new_uid,
+             gid_t old_gid, gid_t new_gid)
 {
-       int err = 0;
+#if defined(WITH_SELINUX)
+       if (set_selinux_file_context(dst->full_path, statp->st_mode & S_IFMT) != 0)
+               return -1;
+#endif
 
-#ifdef WITH_SELINUX
-       if (set_selinux_file_context (dst->full_path, statp->st_mode & S_IFMT) != 0) {
+       if (mknodat(dst->dirfd, dst->name, statp->st_mode & ~07777U, statp->st_rdev) == -1)
                return -1;
-       }
-#endif                         /* WITH_SELINUX */
 
-       if (   (mknodat (dst->dirfd, dst->name, statp->st_mode & ~07777U, statp->st_rdev) != 0)
-           || (chownat_if_needed (dst, statp,
-                                old_uid, new_uid, old_gid, new_gid) != 0)
-           || (fchmodat (dst->dirfd, dst->name, statp->st_mode & 07777, AT_SYMLINK_NOFOLLOW) != 0)
-#ifdef WITH_ACL
-           || (   (perm_copy_path (src, dst, &ctx) != 0)
-               && (errno != 0))
-#endif                         /* WITH_ACL */
-#ifdef WITH_ATTR
+       if (chownat_if_needed(dst, statp, old_uid, new_uid, old_gid, new_gid) == -1)
+               return -1;
+
+       if (fchmodat(dst->dirfd, dst->name, statp->st_mode & 07777, AT_SYMLINK_NOFOLLOW) == -1)
+               return -1;
+
+#if defined(WITH_ACL)
+       if (perm_copy_path(src, dst, &ctx) == -1 && errno != 0)
+               return -1;
+#endif
+
+#if defined(WITH_ATTR)
        /*
         * If the third parameter is NULL, all extended attributes
         * except those that define Access Control Lists are copied.
@@ -713,15 +718,16 @@ static int copy_special (const struct path_info *src, const struct path_info *ds
         * file systems with and without ACL support needs some
         * additional logic so that no unexpected permissions result.
         */
-           || (   !reset_selinux
-               && (attr_copy_path (src, dst, NULL, &ctx) != 0)
-               && (errno != 0))
-#endif                         /* WITH_ATTR */
-               || (utimensat (dst->dirfd, dst->name, mt, AT_SYMLINK_NOFOLLOW) != 0)) {
-               err = -1;
+       if (!reset_selinux) {
+               if (attr_copy_path(src, dst, NULL, &ctx) == -1 && errno != 0)
+                       return -1;
        }
+#endif
 
-       return err;
+       if (utimensat(dst->dirfd, dst->name, mt, AT_SYMLINK_NOFOLLOW) == -1)
+               return -1;
+
+       return 0;
 }
 
 /*