From c580081578edf8663e80cd86a1b4de377be58dc1 Mon Sep 17 00:00:00 2001 From: Michael Albinus Date: Tue, 22 Jan 2019 10:38:49 +0100 Subject: [PATCH] Respect setgid bit of the upper directory in Tramp * doc/misc/trampver.texi: * lisp/net/trampver.el: Change version to "2.4.2-pre". * lisp/net/tramp.el: Bump version to 2.4.2-pre. (tramp-set-file-uid-gid): Respect setgid bit of the upper directory. (tramp-default-file-modes, tramp-handle-insert-file-contents) (tramp-mode-string-to-int, tramp-make-tramp-temp-file): * lisp/net/tramp-adb.el (tramp-adb-handle-file-local-copy) (tramp-adb-handle-write-region): * lisp/net/tramp-sh.el (tramp-do-copy-or-rename-file-directly) (tramp-sh-handle-write-region): Use octal constants. --- doc/misc/trampver.texi | 2 +- lisp/net/tramp-adb.el | 8 ++------ lisp/net/tramp-sh.el | 12 ++++-------- lisp/net/tramp.el | 42 +++++++++++++++++++++++------------------- lisp/net/trampver.el | 4 ++-- 5 files changed, 32 insertions(+), 36 deletions(-) diff --git a/doc/misc/trampver.texi b/doc/misc/trampver.texi index f5cc2bae179..5b1408a4974 100644 --- a/doc/misc/trampver.texi +++ b/doc/misc/trampver.texi @@ -7,7 +7,7 @@ @c In the Tramp GIT, the version number is auto-frobbed from tramp.el, @c and the bug report address is auto-frobbed from configure.ac. -@set trampver 2.4.1 +@set trampver 2.4.2-pre @set tramp-bug-report-address tramp-devel@@gnu.org @c Other flags from configuration. diff --git a/lisp/net/tramp-adb.el b/lisp/net/tramp-adb.el index 73774dbc444..c900d3c9a21 100644 --- a/lisp/net/tramp-adb.el +++ b/lisp/net/tramp-adb.el @@ -609,9 +609,7 @@ Emacs dired can't find files." (ignore-errors (delete-file tmpfile)) (tramp-error v 'file-error "Cannot make local copy of file `%s'" filename)) - (set-file-modes - tmpfile - (logior (or (file-modes filename) 0) (string-to-number "0400" 8)))) + (set-file-modes tmpfile (logior (or (file-modes filename) 0) #o0400))) tmpfile))) (defun tramp-adb-handle-file-writable-p (filename) @@ -657,9 +655,7 @@ But handle the case, if the \"test\" command is not available." (tmpfile (tramp-compat-make-temp-file filename))) (when (and append (file-exists-p filename)) (copy-file filename tmpfile 'ok) - (set-file-modes - tmpfile - (logior (or (file-modes tmpfile) 0) (string-to-number "0600" 8)))) + (set-file-modes tmpfile (logior (or (file-modes tmpfile) 0) #o0600))) (tramp-run-real-handler 'write-region (list start end tmpfile append 'no-message lockname)) (with-tramp-progress-reporter diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el index dfb4b84517f..d0e7357f8f5 100644 --- a/lisp/net/tramp-sh.el +++ b/lisp/net/tramp-sh.el @@ -2184,8 +2184,7 @@ the uid and gid from FILENAME." (or (eq op 'copy) (zerop (logand - (file-modes (file-name-directory localname1)) - (string-to-number "1000" 8)))) + (file-modes (file-name-directory localname1)) #o1000))) (file-writable-p (file-name-directory localname2)) (or (file-directory-p localname2) (file-writable-p localname2)))) @@ -2229,8 +2228,7 @@ the uid and gid from FILENAME." ;; We must change the ownership as remote user. ;; Since this does not work reliable, we also ;; give read permissions. - (set-file-modes - (concat prefix tmpfile) (string-to-number "0777" 8)) + (set-file-modes (concat prefix tmpfile) #o0777) (tramp-set-file-uid-gid (concat prefix tmpfile) (tramp-get-local-uid 'integer) @@ -2244,7 +2242,7 @@ the uid and gid from FILENAME." ;; We must change the ownership as local user. ;; Since this does not work reliable, we also ;; give read permissions. - (set-file-modes tmpfile (string-to-number "0777" 8)) + (set-file-modes tmpfile #o0777) (tramp-set-file-uid-gid tmpfile (tramp-get-remote-uid v 'integer) @@ -3267,9 +3265,7 @@ the result will be a local, non-Tramp, file name." ;; handles permissions. ;; Ensure that it is still readable. (when modes - (set-file-modes - tmpfile - (logior (or modes 0) (string-to-number "0400" 8)))) + (set-file-modes tmpfile (logior (or modes 0) #o0400))) ;; This is a bit lengthy due to the different methods ;; possible for file transfer. First, we check whether the diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el index a65094f811f..6428e18331b 100644 --- a/lisp/net/tramp.el +++ b/lisp/net/tramp.el @@ -7,7 +7,7 @@ ;; Maintainer: Michael Albinus ;; Keywords: comm, processes ;; Package: tramp -;; Version: 2.4.1 +;; Version: 2.4.2-pre ;; Package-Requires: ((emacs "24.1")) ;; This file is part of GNU Emacs. @@ -2148,7 +2148,7 @@ been set up by `rfn-eshadow-setup-minibuffer'." If the file modes of FILENAME cannot be determined, return the value of `default-file-modes', without execute permissions." (or (file-modes filename) - (logand (default-file-modes) (string-to-number "0666" 8)))) + (logand (default-file-modes) #o0666))) (defun tramp-replace-environment-variables (filename) "Replace environment variables in FILENAME. @@ -3539,7 +3539,7 @@ User is always nil." ;; When the file is not readable for the owner, it ;; cannot be inserted, even if it is readable for the ;; group or for everybody. - (set-file-modes local-copy (string-to-number "0600" 8)) + (set-file-modes local-copy #o0600) (when (and (null remote-copy) (tramp-get-method-parameter @@ -4254,47 +4254,47 @@ would yield t. On the other hand, the following check results in nil: (other-execute-or-sticky (aref mode-chars 9))) (logior (cond - ((char-equal owner-read ?r) (string-to-number "00400" 8)) + ((char-equal owner-read ?r) #o0400) ((char-equal owner-read ?-) 0) (t (error "Second char `%c' must be one of `r-'" owner-read))) (cond - ((char-equal owner-write ?w) (string-to-number "00200" 8)) + ((char-equal owner-write ?w) #o0200) ((char-equal owner-write ?-) 0) (t (error "Third char `%c' must be one of `w-'" owner-write))) (cond - ((char-equal owner-execute-or-setid ?x) (string-to-number "00100" 8)) - ((char-equal owner-execute-or-setid ?S) (string-to-number "04000" 8)) - ((char-equal owner-execute-or-setid ?s) (string-to-number "04100" 8)) + ((char-equal owner-execute-or-setid ?x) #o0100) + ((char-equal owner-execute-or-setid ?S) #o4000) + ((char-equal owner-execute-or-setid ?s) #o4100) ((char-equal owner-execute-or-setid ?-) 0) (t (error "Fourth char `%c' must be one of `xsS-'" owner-execute-or-setid))) (cond - ((char-equal group-read ?r) (string-to-number "00040" 8)) + ((char-equal group-read ?r) #o0040) ((char-equal group-read ?-) 0) (t (error "Fifth char `%c' must be one of `r-'" group-read))) (cond - ((char-equal group-write ?w) (string-to-number "00020" 8)) + ((char-equal group-write ?w) #o0020) ((char-equal group-write ?-) 0) (t (error "Sixth char `%c' must be one of `w-'" group-write))) (cond - ((char-equal group-execute-or-setid ?x) (string-to-number "00010" 8)) - ((char-equal group-execute-or-setid ?S) (string-to-number "02000" 8)) - ((char-equal group-execute-or-setid ?s) (string-to-number "02010" 8)) + ((char-equal group-execute-or-setid ?x) #o0010) + ((char-equal group-execute-or-setid ?S) #o2000) + ((char-equal group-execute-or-setid ?s) #o2010) ((char-equal group-execute-or-setid ?-) 0) (t (error "Seventh char `%c' must be one of `xsS-'" group-execute-or-setid))) (cond - ((char-equal other-read ?r) (string-to-number "00004" 8)) + ((char-equal other-read ?r) #o0004) ((char-equal other-read ?-) 0) (t (error "Eighth char `%c' must be one of `r-'" other-read))) (cond - ((char-equal other-write ?w) (string-to-number "00002" 8)) + ((char-equal other-write ?w) #o0002) ((char-equal other-write ?-) 0) (t (error "Ninth char `%c' must be one of `w-'" other-write))) (cond - ((char-equal other-execute-or-sticky ?x) (string-to-number "00001" 8)) - ((char-equal other-execute-or-sticky ?T) (string-to-number "01000" 8)) - ((char-equal other-execute-or-sticky ?t) (string-to-number "01001" 8)) + ((char-equal other-execute-or-sticky ?x) #o0001) + ((char-equal other-execute-or-sticky ?T) #o1000) + ((char-equal other-execute-or-sticky ?t) #o1001) ((char-equal other-execute-or-sticky ?-) 0) (t (error "Tenth char `%c' must be one of `xtT-'" other-execute-or-sticky)))))) @@ -4353,7 +4353,11 @@ If UID and GID are provided, these values are used; otherwise uid and gid of the corresponding remote or local user is taken, depending whether FILENAME is remote or local. Both parameters must be non-negative integers. +The setgid bit of the upper directory is respected. If FILENAME is remote, a file name handler is called." + (unless (zerop (logand #o2000 (file-modes (file-name-directory filename)))) + (setq gid (tramp-compat-file-attribute-group-id + (file-attributes (file-name-directory filename) 'integer)))) (let ((handler (find-file-name-handler filename 'tramp-set-file-uid-gid))) (if handler (funcall handler 'tramp-set-file-uid-gid filename uid gid) @@ -4521,7 +4525,7 @@ Return the local name of the temporary file." (setq result nil) ;; This creates the file by side effect. (set-file-times result) - (set-file-modes result (string-to-number "0700" 8)))) + (set-file-modes result #o0700))) ;; Return the local part. (with-parsed-tramp-file-name result nil localname))) diff --git a/lisp/net/trampver.el b/lisp/net/trampver.el index ccc7de12cb4..83d34c02220 100644 --- a/lisp/net/trampver.el +++ b/lisp/net/trampver.el @@ -31,7 +31,7 @@ ;; aclocal.m4; should be changed only there. ;;;###tramp-autoload -(defconst tramp-version "2.4.1" +(defconst tramp-version "2.4.2-pre" "This version of Tramp.") ;;;###tramp-autoload @@ -65,7 +65,7 @@ ;; Check for Emacs version. (let ((x (if (not (string-lessp emacs-version "24.1")) "ok" - (format "Tramp 2.4.1 is not fit for %s" + (format "Tramp 2.4.2-pre is not fit for %s" (replace-regexp-in-string "\n" "" (emacs-version)))))) (unless (string-equal "ok" x) (error "%s" x))) -- 2.39.2