(change_file_owner): Restore special file permission
authorJim Meyering <jim@meyering.net>
Sat, 9 Dec 2000 10:15:17 +0000 (10:15 +0000)
committerJim Meyering <jim@meyering.net>
Sat, 9 Dec 2000 10:15:17 +0000 (10:15 +0000)
bits, since calling chown resets them on some systems.
Reported by Matt Perry.

src/chown.c

index c6d1f3fdba6dd6ecd40669e1ad2578ecd579f71d..f155f335ae70d2530e5fd5c03f05f9927f183acf 100644 (file)
@@ -236,6 +236,25 @@ change_file_owner (int cmdline_arg, const char *file, uid_t user, gid_t group,
                       quote (file));
              errors = 1;
            }
+         else
+           {
+             /* The change succeeded.  On some systems, the chown function
+                resets the `special' permission bits.  When run by a
+                `privileged' user, this program must ensure that at least
+                the set-uid and set-group ones are still set.  */
+             if (file_stats.st_mode & ~S_IRWXUGO
+                 /* If this is a symlink and we changed *it*, then skip it.  */
+                 && ! (S_ISLNK (file_stats.st_mode) && change_symlinks))
+               {
+                 if (chmod (file, file_stats.st_mode))
+                   {
+                     error (0, saved_errno,
+                            _("unable to restore permissions of %s"),
+                            quote (file));
+                     fail = 1;
+                   }
+               }
+           }
        }
       else if (verbosity == V_high)
        {