diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 7 | ||||
| -rw-r--r-- | src/fileio.c | 18 |
2 files changed, 21 insertions, 4 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index a2891fa9c91..5de5fefd6aa 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,10 @@ | |||
| 1 | 2011-07-18 Paul Eggert <eggert@cs.ucla.edu> | ||
| 2 | |||
| 3 | * fileio.c (Fcopy_file): Adjust mode if fchown fails. (Bug#9002) | ||
| 4 | If fchown fails to set both uid and gid, try to set just gid, | ||
| 5 | as that is sometimes allowed. Adjust the file's mode to eliminate | ||
| 6 | setuid or setgid bits that are inappropriate if fchown fails. | ||
| 7 | |||
| 1 | 2011-07-18 Stefan Monnier <monnier@iro.umontreal.ca> | 8 | 2011-07-18 Stefan Monnier <monnier@iro.umontreal.ca> |
| 2 | 9 | ||
| 3 | * xdisp.c (next_element_from_string, next_element_from_buffer): Use EQ | 10 | * xdisp.c (next_element_from_string, next_element_from_buffer): Use EQ |
diff --git a/src/fileio.c b/src/fileio.c index a52e834c2b2..fb2c081ae5c 100644 --- a/src/fileio.c +++ b/src/fileio.c | |||
| @@ -38,8 +38,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 38 | #include <selinux/context.h> | 38 | #include <selinux/context.h> |
| 39 | #endif | 39 | #endif |
| 40 | 40 | ||
| 41 | #include <ignore-value.h> | ||
| 42 | |||
| 43 | #include "lisp.h" | 41 | #include "lisp.h" |
| 44 | #include "intervals.h" | 42 | #include "intervals.h" |
| 45 | #include "buffer.h" | 43 | #include "buffer.h" |
| @@ -1961,9 +1959,21 @@ on the system, we copy the SELinux context of FILE to NEWNAME. */) | |||
| 1961 | owner and group. */ | 1959 | owner and group. */ |
| 1962 | if (input_file_statable_p) | 1960 | if (input_file_statable_p) |
| 1963 | { | 1961 | { |
| 1962 | int mode_mask = 07777; | ||
| 1964 | if (!NILP (preserve_uid_gid)) | 1963 | if (!NILP (preserve_uid_gid)) |
| 1965 | ignore_value (fchown (ofd, st.st_uid, st.st_gid)); | 1964 | { |
| 1966 | if (fchmod (ofd, st.st_mode & 07777) != 0) | 1965 | /* Attempt to change owner and group. If that doesn't work |
| 1966 | attempt to change just the group, as that is sometimes allowed. | ||
| 1967 | Adjust the mode mask to eliminate setuid or setgid bits | ||
| 1968 | that are inappropriate if the owner and group are wrong. */ | ||
| 1969 | if (fchown (ofd, st.st_uid, st.st_gid) != 0) | ||
| 1970 | { | ||
| 1971 | mode_mask &= ~06000; | ||
| 1972 | if (fchown (ofd, -1, st.st_gid) == 0) | ||
| 1973 | mode_mask |= 02000; | ||
| 1974 | } | ||
| 1975 | } | ||
| 1976 | if (fchmod (ofd, st.st_mode & mode_mask) != 0) | ||
| 1967 | report_file_error ("Doing chmod", Fcons (newname, Qnil)); | 1977 | report_file_error ("Doing chmod", Fcons (newname, Qnil)); |
| 1968 | } | 1978 | } |
| 1969 | #endif /* not MSDOS */ | 1979 | #endif /* not MSDOS */ |