components/gzip/patches/chmod_chown.patch
author Norm Jacobs <Norm.Jacobs@Oracle.COM>
Thu, 11 Jun 2015 20:52:26 -0700
changeset 4479 68cd14867fa2
parent 1543 46dbc9af0fe5
permissions -rw-r--r--
19969975 gcc 4.8.2 regression to old GNU linkonce
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1543
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
     1
http://debbugs.gnu.org/cgi/bugreport.cgi?bug=15672
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
     2
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
     3
The patch was changed so that it applies cleanly to our soruce tree.
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
     4
---
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
     5
Thanks for the suggestion.  Does the following patch work for you?
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
     6
I've pushed this to the savannah master for gzip.
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
     7
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
     8
From 0f167be4f843ac5fcd8f0bc120202782d09a453f Mon Sep 17 00:00:00 2001
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
     9
From: Paul Eggert <[email protected]>
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    10
Date: Thu, 24 Oct 2013 00:19:56 -0700
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    11
Subject: [PATCH] gzip: fix permissions issue on Solaris-like systems
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    12
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    13
I.e., on systems that let users give files away.
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    14
* gzip.c (do_chown): New function.
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    15
(copy_stat): Use it, to change the group, then the permissions,
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    16
then the owner.  Idea suggested by Vladimir Marek in
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    17
<http://bugs.gnu.org/15672#11>
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    18
---
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    19
 gzip.c | 33 ++++++++++++++++++++++++---------
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    20
 1 file changed, 24 insertions(+), 9 deletions(-)
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    21
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    22
diff --git a/gzip.c b/gzip.c
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    23
index 93cc738..f40cd21 100644
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    24
--- a/gzip.c
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    25
+++ b/gzip.c
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    26
@@ -1684,6 +1684,21 @@ local int check_ofname()
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    27
     return OK;
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    28
 }
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    29
 
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    30
+/* Change the owner and group of a file.  FD is a file descriptor for
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    31
+   the file and NAME its name.  Change it to user UID and to group GID.
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    32
+   If UID or GID is -1, though, do not change the corresponding user
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    33
+   or group.  */
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    34
+static void
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    35
+do_chown (int fd, char const *name, uid_t uid, gid_t gid)
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    36
+{
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    37
+#ifndef NO_CHOWN
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    38
+# if HAVE_FCHOWN
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    39
+  ignore_value (fchown (fd, uid, gid));
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    40
+# else
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    41
+  ignore_value (chown (name, uid, gid));
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    42
+# endif
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    43
+#endif
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    44
+}
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    45
 
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    46
 /* ========================================================================
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    47
  * Copy modes, times, ownership from input file to output file.
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    48
@@ -1722,16 +1727,14 @@ local void copy_stat(ifstat)
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    49
       }
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    50
 #endif
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    51
 
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    52
-#ifndef NO_CHOWN
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    53
-    /* Copy ownership */
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    54
-# if HAVE_FCHOWN
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    55
-    ignore_value (fchown (ofd, ifstat->st_uid, ifstat->st_gid));
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    56
-# elif HAVE_CHOWN
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    57
-    ignore_value (chown (ofname, ifstat->st_uid, ifstat->st_gid));
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    58
-# endif
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    59
-#endif
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    60
+    /* Change the group first, then the permissions, then the owner.
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    61
+       That way, the permissions will be correct on systems that allow
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    62
+       users to give away files, without introducing a security hole.
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    63
+       Security depends on permissions not containing the setuid or
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    64
+       setgid bits.  */
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    65
+
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    66
+    do_chown (ofd, ofname, -1, ifstat->st_gid);
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    67
 
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    68
-    /* Copy the protection modes */
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    69
 #if HAVE_FCHMOD
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    70
     r = fchmod (ofd, mode);
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    71
 #else
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    72
@@ -1745,6 +1758,8 @@ local void copy_stat(ifstat)
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    73
             perror(ofname);
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    74
         }
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    75
     }
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    76
+
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    77
+    do_chown (ofd, ofname, ifstat->st_uid, -1);
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    78
 }
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    79
 
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    80
 #if ! NO_DIR
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    81
-- 
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    82
1.8.3.1
46dbc9af0fe5 17601119 gzip is unable to set permissions under file_chown_self privilege
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    83