]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
* src/copy.c (copy_internal): Don't pass mkdir a mode greater than
authorPaul Eggert <eggert@cs.ucla.edu>
Wed, 18 Oct 2006 20:56:38 +0000 (20:56 +0000)
committerPaul Eggert <eggert@cs.ucla.edu>
Wed, 18 Oct 2006 20:56:38 +0000 (20:56 +0000)
7777.  This matches historical 'cp' behavior and avoids some
(though not all) implementation-defined behavior of mkdir.
* src/cp.c (make_dir_parents_private): Likewise.
* src/copy.c (copy_internal): Don't pass 'open' a mode greater
than 777.  This is required by POSIX.  It doesn't make any difference
in actual behavior on any host that I know of.

ChangeLog
src/copy.c
src/cp.c

index 2ddf574b431779dee78b34da086a2f69e51cfc7e..1ecc61ca44f95ee6d294df625edc029eab569d67 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2006-10-18  Paul Eggert  <eggert@cs.ucla.edu>
+
+       * src/copy.c (copy_internal): Don't pass mkdir a mode greater than
+       7777.  This matches historical 'cp' behavior and avoids some
+       (though not all) implementation-defined behavior of mkdir.
+       * src/cp.c (make_dir_parents_private): Likewise.
+       * src/copy.c (copy_internal): Don't pass 'open' a mode greater
+       than 777.  This is required by POSIX.  It doesn't make any difference
+       in actual behavior on any host that I know of.
+
 2006-10-17  Jim Meyering  <jim@meyering.net>
 
        * src/dd.c (usage): Use two spaces (not one) to separate the
index 2f03599e5f062f5298c182e343e118d5b863a1ec..d1c005300a6942d7ab7c1b60419f78595beee2da 100644 (file)
@@ -1505,7 +1505,11 @@ copy_internal (char const *src_name, char const *dst_name,
 
       if (new_dst || !S_ISDIR (dst_sb.st_mode))
        {
-         if (mkdir (dst_name, src_mode) != 0)
+         /* POSIX says mkdir's behavior is implementation-defined when
+            (src_mode & ~S_IRWXUGO) != 0.  However, common practice is
+            to ask mkdir to copy all the CHMOD_MODE_BITS, letting mkdir
+            decide what to do with S_ISUID | S_ISGID | S_ISVTX.  */
+         if (mkdir (dst_name, src_mode & CHMOD_MODE_BITS) != 0)
            {
              error (0, errno, _("cannot create directory %s"),
                     quote (dst_name));
@@ -1628,9 +1632,11 @@ copy_internal (char const *src_name, char const *dst_name,
     {
       copied_as_regular = true;
       /* POSIX says the permission bits of the source file must be
-        used as the 3rd argument in the open call, but that's not consistent
-        with historical practice.  */
-      if (! copy_reg (src_name, dst_name, x, src_mode, &new_dst, &src_sb))
+        used as the 3rd argument in the open call.  Historical
+        practice passed all the source mode bits to 'open', but the extra
+        bits were ignored, so it should be the same either way.  */
+      if (! copy_reg (src_name, dst_name, x, src_mode & S_IRWXUGO,
+                     &new_dst, &src_sb))
        goto un_backup;
     }
   else if (S_ISFIFO (src_type))
index 679ef0fe77e24dd643a14f63c56221c9d35b45be..9ba334255297042836709ceb3b2ff9ef704ace3f 100644 (file)
--- a/src/cp.c
+++ b/src/cp.c
@@ -428,7 +428,11 @@ make_dir_parents_private (char const *const_dir, size_t src_offset,
                }
              src_mode = stats.st_mode;
 
-             if (mkdir (dir, src_mode))
+             /* POSIX says mkdir's behavior is implementation-defined when
+                (src_mode & ~S_IRWXUGO) != 0.  However, common practice is
+                to ask mkdir to copy all the CHMOD_MODE_BITS, letting mkdir
+                decide what to do with S_ISUID | S_ISGID | S_ISVTX.  */
+             if (mkdir (dir, src_mode & CHMOD_MODE_BITS) != 0)
                {
                  error (0, errno, _("cannot make directory %s"),
                         quote (dir));