From: Jim Meyering Date: Sat, 9 Dec 2000 10:15:17 +0000 (+0000) Subject: (change_file_owner): Restore special file permission X-Git-Tag: TEXTUTILS-2_0_10~32 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=73f1bc31d793217021c51bdf2a3c43f3571ae9f7;p=thirdparty%2Fcoreutils.git (change_file_owner): Restore special file permission bits, since calling chown resets them on some systems. Reported by Matt Perry. --- diff --git a/src/chown.c b/src/chown.c index c6d1f3fdba..f155f335ae 100644 --- a/src/chown.c +++ b/src/chown.c @@ -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) {