aboutsummaryrefslogtreecommitdiffstats
path: root/src/fileio.c
diff options
context:
space:
mode:
authorPaul Eggert2011-07-18 23:10:15 -0700
committerPaul Eggert2011-07-18 23:10:15 -0700
commit7403ff044d82d390bdc4cdd3954448daedcd4571 (patch)
tree2f5ce508e4b20d5641ebd6c86ca61bc8dab401cc /src/fileio.c
parentd3411f89d34bd1009cae738f917abf477be09882 (diff)
parent15e3a074a6ebdcefd828a1ba14a5a12ff9921034 (diff)
downloademacs-7403ff044d82d390bdc4cdd3954448daedcd4571.tar.gz
emacs-7403ff044d82d390bdc4cdd3954448daedcd4571.zip
Merge from trunk.
Diffstat (limited to 'src/fileio.c')
-rw-r--r--src/fileio.c35
1 files changed, 27 insertions, 8 deletions
diff --git a/src/fileio.c b/src/fileio.c
index af11e927059..60ee35bb399 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"
@@ -1939,10 +1937,19 @@ on the system, we copy the SELinux context of FILE to NEWNAME. */)
1939 | (NILP (ok_if_already_exists) ? O_EXCL : 0), 1937 | (NILP (ok_if_already_exists) ? O_EXCL : 0),
1940 S_IREAD | S_IWRITE); 1938 S_IREAD | S_IWRITE);
1941#else /* not MSDOS */ 1939#else /* not MSDOS */
1942 ofd = emacs_open (SSDATA (encoded_newname), 1940 {
1943 O_WRONLY | O_TRUNC | O_CREAT 1941 int new_mask = 0666;
1944 | (NILP (ok_if_already_exists) ? O_EXCL : 0), 1942 if (input_file_statable_p)
1945 0666); 1943 {
1944 if (!NILP (preserve_uid_gid))
1945 new_mask = 0600;
1946 new_mask &= st.st_mode;
1947 }
1948 ofd = emacs_open (SSDATA (encoded_newname),
1949 (O_WRONLY | O_TRUNC | O_CREAT
1950 | (NILP (ok_if_already_exists) ? O_EXCL : 0)),
1951 new_mask);
1952 }
1946#endif /* not MSDOS */ 1953#endif /* not MSDOS */
1947 if (ofd < 0) 1954 if (ofd < 0)
1948 report_file_error ("Opening output file", Fcons (newname, Qnil)); 1955 report_file_error ("Opening output file", Fcons (newname, Qnil));
@@ -1961,9 +1968,21 @@ on the system, we copy the SELinux context of FILE to NEWNAME. */)
1961 owner and group. */ 1968 owner and group. */
1962 if (input_file_statable_p) 1969 if (input_file_statable_p)
1963 { 1970 {
1971 int mode_mask = 07777;
1964 if (!NILP (preserve_uid_gid)) 1972 if (!NILP (preserve_uid_gid))
1965 ignore_value (fchown (ofd, st.st_uid, st.st_gid)); 1973 {
1966 if (fchmod (ofd, st.st_mode & 07777) != 0) 1974 /* Attempt to change owner and group. If that doesn't work
1975 attempt to change just the group, as that is sometimes allowed.
1976 Adjust the mode mask to eliminate setuid or setgid bits
1977 that are inappropriate if the owner and group are wrong. */
1978 if (fchown (ofd, st.st_uid, st.st_gid) != 0)
1979 {
1980 mode_mask &= ~06000;
1981 if (fchown (ofd, -1, st.st_gid) == 0)
1982 mode_mask |= 02000;
1983 }
1984 }
1985 if (fchmod (ofd, st.st_mode & mode_mask) != 0)
1967 report_file_error ("Doing chmod", Fcons (newname, Qnil)); 1986 report_file_error ("Doing chmod", Fcons (newname, Qnil));
1968 } 1987 }
1969#endif /* not MSDOS */ 1988#endif /* not MSDOS */