diff options
author | Jim Meyering <jim@meyering.net> | 2000-12-09 10:15:17 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 2000-12-09 10:15:17 +0000 |
commit | 73f1bc31d793217021c51bdf2a3c43f3571ae9f7 (patch) | |
tree | 4376d913a234abf099c39f27dccdc64faf89311b /src/chown.c | |
parent | 497d1d9e97062434722be36d12a481918c5bc13f (diff) | |
download | coreutils-73f1bc31d793217021c51bdf2a3c43f3571ae9f7.tar.xz |
(change_file_owner): Restore special file permission
bits, since calling chown resets them on some systems.
Reported by Matt Perry.
Diffstat (limited to 'src/chown.c')
-rw-r--r-- | src/chown.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/chown.c b/src/chown.c index c6d1f3fdb..f155f335a 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) { |