summaryrefslogtreecommitdiff
path: root/lisp/net/tramp.el
diff options
context:
space:
mode:
authorMichael Albinus <michael.albinus@gmx.de>2021-07-14 18:36:14 +0200
committerMichael Albinus <michael.albinus@gmx.de>2021-07-14 18:36:14 +0200
commit525d5cab36fe7e719ecc49b88a1ac68abbe7924c (patch)
treed5735304483b2bb668946aa0ee4ed2d860716c3b /lisp/net/tramp.el
parentf45710e1ddf0f3a1470f6bc3a1116afd841de41a (diff)
downloademacs-525d5cab36fe7e719ecc49b88a1ac68abbe7924c.tar.gz
emacs-525d5cab36fe7e719ecc49b88a1ac68abbe7924c.tar.bz2
emacs-525d5cab36fe7e719ecc49b88a1ac68abbe7924c.zip
Preserve backward compatibility in Tramp
* lisp/net/tramp-crypt.el (tramp-crypt-handle-lock-file) (tramp-crypt-handle-unlock-file): Preserve backward compatibility. * lisp/net/tramp-sh.el (tramp-sh-handle-write-region): Do not create lock file twice. * lisp/net/tramp.el (tramp-handle-make-lock-file-name): Move lock file security check ... (tramp-handle-lock-file): ... here. (tramp-handle-unlock-file): Preserve backward compatibility. * test/lisp/net/tramp-tests.el (lock-file-name-transforms) (remote-file-name-inhibit-locks): Declare. (tramp-allow-unsafe-temporary-files): Set to t. (tramp-test37-make-auto-save-file-name) (tramp-test38-find-backup-file-name): Move binding of `tramp-allow-unsafe-temporary-files' up. (tramp-test39-lock-file): Bind `tramp-allow-unsafe-temporary-files'. Preserve backward compatibility. Extend test.
Diffstat (limited to 'lisp/net/tramp.el')
-rw-r--r--lisp/net/tramp.el49
1 files changed, 25 insertions, 24 deletions
diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el
index 3f586c62170..736c7efd242 100644
--- a/lisp/net/tramp.el
+++ b/lisp/net/tramp.el
@@ -3873,43 +3873,44 @@ Return nil when there is no lockfile."
(format
"%s@%s.%s" (user-login-name) (system-name)
(tramp-get-lock-pid file))))
+
+ ;; Protect against security hole.
+ (with-parsed-tramp-file-name file nil
+ (when (and (not tramp-allow-unsafe-temporary-files)
+ (file-in-directory-p lockname temporary-file-directory)
+ (zerop (or (tramp-compat-file-attribute-user-id
+ (file-attributes file 'integer))
+ tramp-unknown-id-integer))
+ (not (with-tramp-connection-property
+ (tramp-get-process v) "unsafe-temporary-file"
+ (yes-or-no-p
+ (concat
+ "Lock file on local temporary directory, "
+ "do you want to continue? ")))))
+ (tramp-error v 'file-error "Unsafe lock file name")))
+
+ ;; Do the lock.
(let (create-lockfiles signal-hook-function)
(condition-case nil
(make-symbolic-link info lockname 'ok-if-already-exists)
(error
- (write-region info nil lockname)
- (set-file-modes lockname #o0644))))))))
+ (with-file-modes #o0644
+ (write-region info nil lockname)))))))))
(defun tramp-handle-make-lock-file-name (file)
"Like `make-lock-file-name' for Tramp files."
- (when (and create-lockfiles
- ;; This variable has been introduced with Emacs 28.1.
- (not (bound-and-true-p remote-file-name-inhibit-locks)))
- (with-parsed-tramp-file-name file nil
- (let ((result
- ;; Run plain `make-lock-file-name'.
- (tramp-run-real-handler #'make-lock-file-name (list file))))
- ;; Protect against security hole.
- (when (and (not tramp-allow-unsafe-temporary-files)
- (file-in-directory-p result temporary-file-directory)
- (zerop (or (tramp-compat-file-attribute-user-id
- (file-attributes file 'integer))
- tramp-unknown-id-integer))
- (not (with-tramp-connection-property
- (tramp-get-process v) "unsafe-temporary-file"
- (yes-or-no-p
- (concat
- "Lock file on local temporary directory, "
- "do you want to continue? ")))))
- (tramp-error v 'file-error "Unsafe lock file name"))
- result))))
+ (and create-lockfiles
+ ;; This variable has been introduced with Emacs 28.1.
+ (not (bound-and-true-p remote-file-name-inhibit-locks))
+ (tramp-run-real-handler 'make-lock-file-name (list file))))
(defun tramp-handle-unlock-file (file)
"Like `unlock-file' for Tramp files."
(when-let ((lockname (tramp-compat-make-lock-file-name file)))
(condition-case err
(delete-file lockname)
- (error (userlock--handle-unlock-error err)))))
+ ;; `userlock--handle-unlock-error' exists since Emacs 28.1.
+ (error (tramp-compat-funcall 'userlock--handle-unlock-error err)))))
(defun tramp-handle-load (file &optional noerror nomessage nosuffix must-suffix)
"Like `load' for Tramp files."