commit 522acbf49c349710ef0c69df873472e62f816cdb (HEAD, refs/remotes/origin/master) Author: Stefan Monnier Date: Sun Dec 16 23:39:51 2018 -0500 * lisp/emacs-lisp/macroexp.el: Don't hide backtrace (macroexp--compiler-macro): Use condition-case-unless-debug. diff --git a/lisp/emacs-lisp/macroexp.el b/lisp/emacs-lisp/macroexp.el index 2418264bdb..4bef5893ae 100644 --- a/lisp/emacs-lisp/macroexp.el +++ b/lisp/emacs-lisp/macroexp.el @@ -94,7 +94,7 @@ each clause." clause))) (defun macroexp--compiler-macro (handler form) - (condition-case err + (condition-case-unless-debug err (apply handler form (cdr form)) (error (message "Compiler-macro error for %S: %S" (car form) err) commit 2f65525774b6e7edf119db678c9eb78cbb84de6a Author: João Távora Date: Sun Dec 16 16:55:09 2018 +0000 Jsonrpc error handlers can now safely call jsonrpc-shutdown Previously, if an error handler called jsonrpc-shutdown, and if that error handler was being called from the process sentinel, jsonrpc-shutdown would infloop waiting for jsonrpc-sentinel-done to be set. Rename the process property jsonrpc-sentinel-done to jsonrpc-sentinel-cleanup-started, arrange for it to be set earlier in the sentinel, and also check for it earlier in jsonrpc-shutdown. * lisp/jsonrpc.el (Version): Bump to 1.0.7. (jsonrpc--process-sentinel): Set jsonrpc-sentinel-cleanup-started a bit earlier than previous jsonrpc-sentinel-done. (jsonrpc-shutdown): Query jsonrpc-sentinel-cleanup-started diff --git a/lisp/jsonrpc.el b/lisp/jsonrpc.el index 020d7f56cc..af69aa4dfd 100644 --- a/lisp/jsonrpc.el +++ b/lisp/jsonrpc.el @@ -6,7 +6,7 @@ ;; Maintainer: João Távora ;; Keywords: processes, languages, extensions ;; Package-Requires: ((emacs "25.2")) -;; Version: 1.0.6 +;; Version: 1.0.7 ;; This is an Elpa :core package. Don't use functionality that is not ;; compatible with Emacs 25.2. @@ -421,13 +421,13 @@ connection object, called when the process dies .") With optional CLEANUP, kill any associated buffers. " (unwind-protect (cl-loop - with proc = (jsonrpc--process conn) + with proc = (jsonrpc--process conn) for i from 0 + while (not (process-get proc 'jsonrpc-sentinel-cleanup-started)) + unless (zerop i) do + (jsonrpc--warn "Sentinel for %s still hasn't run, deleting it!" proc) do (delete-process proc) - (accept-process-output nil 0.1) - while (not (process-get proc 'jsonrpc-sentinel-done)) - do (jsonrpc--warn - "Sentinel for %s still hasn't run, deleting it!" proc)) + (accept-process-output nil 0.1)) (when cleanup (kill-buffer (process-buffer (jsonrpc--process conn))) (kill-buffer (jsonrpc-stderr-buffer conn))))) @@ -486,6 +486,7 @@ With optional CLEANUP, kill any associated buffers. " (pcase-let ((`(,_success ,_error ,timeout) triplet)) (when timeout (cancel-timer timeout)))) (jsonrpc--request-continuations connection)) + (process-put proc 'jsonrpc-sentinel-cleanup-started t) (unwind-protect ;; Call all outstanding error handlers (maphash (lambda (_id triplet) @@ -493,7 +494,6 @@ With optional CLEANUP, kill any associated buffers. " (funcall error '(:code -1 :message "Server died")))) (jsonrpc--request-continuations connection)) (jsonrpc--message "Server exited with status %s" (process-exit-status proc)) - (process-put proc 'jsonrpc-sentinel-done t) (delete-process proc) (funcall (jsonrpc--on-shutdown connection) connection))))) commit f74595aace4b1240402562b0073b06c170969327 Author: Paul Eggert Date: Sun Dec 16 08:11:35 2018 -0800 Update from Gnulib This incorporates: 2018-12-16 regex: propagate fix for glibc bug 18040 2018-12-16 obstack, libc-config: Support HP-UX cc in C99 mode 2018-12-15 regex: work around a bug in glibc-2.27 and prior 2018-12-13 localtime-buffer: Avoid endless recursion * build-aux/config.guess, build-aux/config.sub, lib/cdefs.h: * lib/gettext.h, lib/localtime-buffer.c, lib/regexec.c, m4/regex.m4: Copy from Gnulib. diff --git a/build-aux/config.guess b/build-aux/config.guess index 47d7bed50c..94c4ac154a 100755 --- a/build-aux/config.guess +++ b/build-aux/config.guess @@ -2,7 +2,7 @@ # Attempt to guess a canonical system name. # Copyright 1992-2018 Free Software Foundation, Inc. -timestamp='2018-11-28' +timestamp='2018-12-07' # This file is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by @@ -96,8 +96,7 @@ fi tmp= # shellcheck disable=SC2172 -trap 'test -z "$tmp" || rm -fr "$tmp"' 1 2 13 15 -trap 'exitcode=$?; test -z "$tmp" || rm -fr "$tmp"; exit $exitcode' 0 +trap 'test -z "$tmp" || rm -fr "$tmp"' 0 1 2 13 15 set_cc_for_build() { : "${TMPDIR=/tmp}" diff --git a/build-aux/config.sub b/build-aux/config.sub index 46708056af..a5081b8e0d 100755 --- a/build-aux/config.sub +++ b/build-aux/config.sub @@ -2,7 +2,7 @@ # Configuration validation subroutine script. # Copyright 1992-2018 Free Software Foundation, Inc. -timestamp='2018-11-28' +timestamp='2018-12-16' # This file is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by @@ -111,7 +111,7 @@ case $# in esac # Split fields of configuration type -IFS="-" read -r field1 field2 field3 field4 <= 199901L +#if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L && !defined __HP_cc # define __flexarr [] # define __glibc_c99_flexarr_available 1 #elif __GNUC_PREREQ (2,97) diff --git a/lib/gettext.h b/lib/gettext.h index f2d7458f4a..8eef008e7c 100644 --- a/lib/gettext.h +++ b/lib/gettext.h @@ -185,7 +185,7 @@ npgettext_aux (const char *domain, #include #if (((__GNUC__ >= 3 || __GNUG__ >= 2) && !defined __STRICT_ANSI__) \ - /* || __STDC_VERSION__ == 199901L + /* || (__STDC_VERSION__ == 199901L && !defined __HP_cc) || (__STDC_VERSION__ >= 201112L && !defined __STDC_NO_VLA__) */ ) # define _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS 1 #else diff --git a/lib/localtime-buffer.c b/lib/localtime-buffer.c index df11f4321d..910c8bcfed 100644 --- a/lib/localtime-buffer.c +++ b/lib/localtime-buffer.c @@ -34,6 +34,7 @@ struct tm *localtime_buffer_addr = &tm_zero_buffer; struct tm * rpl_localtime (time_t const *timep) +#undef localtime { struct tm *tm = localtime (timep); @@ -46,6 +47,7 @@ rpl_localtime (time_t const *timep) /* Same as above, since gmtime and localtime use the same buffer. */ struct tm * rpl_gmtime (time_t const *timep) +#undef gmtime { struct tm *tm = gmtime (timep); diff --git a/lib/regexec.c b/lib/regexec.c index 8b82ea50d4..c7d099c38e 100644 --- a/lib/regexec.c +++ b/lib/regexec.c @@ -2783,8 +2783,11 @@ get_subexp (re_match_context_t *mctx, Idx bkref_node, Idx bkref_str_idx) return REG_ESPACE; err = get_subexp_sub (mctx, sub_top, sub_last, bkref_node, bkref_str_idx); + buf = (const char *) re_string_get_buffer (&mctx->input); if (err == REG_NOMATCH) continue; + if (__glibc_unlikely (err != REG_NOERROR)) + return err; } } return REG_NOERROR; diff --git a/m4/regex.m4 b/m4/regex.m4 index 055d71b5aa..3a39b1a204 100644 --- a/m4/regex.m4 +++ b/m4/regex.m4 @@ -1,4 +1,4 @@ -# serial 67 +# serial 68 # Copyright (C) 1996-2001, 2003-2018 Free Software Foundation, Inc. # @@ -213,6 +213,17 @@ AC_DEFUN([gl_REGEX], if (! REG_STARTEND) result |= 64; + /* Matching with the compiled form of this regexp would provoke + an assertion failure prior to glibc-2.28: + regexec.c:1375: pop_fail_stack: Assertion 'num >= 0' failed + With glibc-2.28, compilation fails and reports the invalid + back reference. */ + re_set_syntax (RE_SYNTAX_POSIX_EGREP); + memset (®ex, 0, sizeof regex); + s = re_compile_pattern ("0|()0|\\1|0", 10, ®ex); + if (!s || strcmp (s, "Invalid back reference")) + result |= 64; + #if 0 /* It would be nice to reject hosts whose regoff_t values are too narrow (including glibc on hosts with 64-bit ptrdiff_t and commit 07d8827946f9364180f18d6842acc80f0997ed75 Author: Stefan Monnier Date: Sun Dec 16 10:32:53 2018 -0500 * lisp/net/tramp: Rework mutual dependencies Functionally split tramp-loaddefs.el into two parts: one part run while loading it at the very beginning of loading tramp.el (holding plain autoloads and declarations), and another run at the very end of loading tramp.el (holding setup code). This should reduce infinite-recursion problems while loading. * lisp/net/tramp.el: Require tramp-loaddefs at beginning. Run (new and internal) tramp--startup-hook at the end. Remove all tramp-autoloads. Prefer tramp--with-startup over eval-after-load. (tramp--with-startup): New macro. (tramp-set-syntax): Show the new value rather than the old value in the error message. (tramp-syntax-values): Explicitly return 'values'. (tramp-prefix-format, tramp-prefix-regexp, tramp-method-regexp) (tramp-postfix-method-format, tramp-postfix-method-regexp) (tramp-prefix-ipv6-format, tramp-prefix-ipv6-regexp) (tramp-postfix-ipv6-format, tramp-postfix-ipv6-regexp) (tramp-postfix-host-format, tramp-postfix-host-regexp) (tramp-remote-file-name-spec-regexp, tramp-file-name-structure) (tramp-completion-file-name-regexp): Don't initialize in the declaration, since it's recomputed at the end anyway. (tramp-time-dont-know, tramp-time-doesnt-exist): Move before first use. * lisp/net/tramp-compat.el: Don't require tramp-loaddefs any more. (tramp-compat-tramp-syntax): Declare tramp-syntax. * lisp/net/tramp-smb.el: * lisp/net/tramp-rclone.el: * lisp/net/tramp-gvfs.el: * lisp/net/tramp-ftp.el: * lisp/net/tramp-adb.el: Wrap all autoloaded setup operations within tramp--with-startup. * lisp/net/tramp-sh.el: Wrap all autoloaded setup operations within tramp--with-startup. (tramp-display-escape-sequence-regexp) (tramp-device-escape-sequence-regexp): Don't tramp-autoload any more. (tramp-stat-marker): Use eval-and-compile rather than tramp-autoload. * lisp/net/tramp-sudoedit.el: Wrap all autoloaded setup operations within tramp--with-startup. Require tramp-sh at compile-time to precompute some regexps based on tramp-stat-marker. diff --git a/lisp/net/tramp-adb.el b/lisp/net/tramp-adb.el index 7bf709b79a..4b839f5e2b 100644 --- a/lisp/net/tramp-adb.el +++ b/lisp/net/tramp-adb.el @@ -78,18 +78,16 @@ It is used for TCP/IP devices." "Regexp for ls output.") ;;;###tramp-autoload -(add-to-list 'tramp-methods - `(,tramp-adb-method - (tramp-tmpdir "/data/local/tmp") - (tramp-default-port 5555))) +(tramp--with-startup + (add-to-list 'tramp-methods + `(,tramp-adb-method + (tramp-tmpdir "/data/local/tmp") + (tramp-default-port 5555))) -;;;###tramp-autoload -(add-to-list 'tramp-default-host-alist `(,tramp-adb-method nil "")) + (add-to-list 'tramp-default-host-alist `(,tramp-adb-method nil "")) -;;;###tramp-autoload -(eval-after-load 'tramp - '(tramp-set-completion-function - tramp-adb-method '((tramp-adb-parse-device-names "")))) + (tramp-set-completion-function + tramp-adb-method '((tramp-adb-parse-device-names "")))) ;;;###tramp-autoload (defconst tramp-adb-file-name-handler-alist @@ -188,8 +186,9 @@ pass to the OPERATION." (tramp-run-real-handler operation args)))) ;;;###tramp-autoload -(tramp-register-foreign-file-name-handler - 'tramp-adb-file-name-p 'tramp-adb-file-name-handler) +(tramp--with-startup + (tramp-register-foreign-file-name-handler + #'tramp-adb-file-name-p #'tramp-adb-file-name-handler)) ;;;###tramp-autoload (defun tramp-adb-parse-device-names (_ignore) diff --git a/lisp/net/tramp-cache.el b/lisp/net/tramp-cache.el index d13e6ee9f5..575d188c05 100644 --- a/lisp/net/tramp-cache.el +++ b/lisp/net/tramp-cache.el @@ -246,17 +246,17 @@ This is suppressed for temporary buffers." (with-parsed-tramp-file-name bfn nil (tramp-flush-file-properties v localname))))))) -(add-hook 'before-revert-hook 'tramp-flush-file-function) -(add-hook 'eshell-pre-command-hook 'tramp-flush-file-function) -(add-hook 'kill-buffer-hook 'tramp-flush-file-function) +(add-hook 'before-revert-hook #'tramp-flush-file-function) +(add-hook 'eshell-pre-command-hook #'tramp-flush-file-function) +(add-hook 'kill-buffer-hook #'tramp-flush-file-function) (add-hook 'tramp-cache-unload-hook (lambda () (remove-hook 'before-revert-hook - 'tramp-flush-file-function) + #'tramp-flush-file-function) (remove-hook 'eshell-pre-command-hook - 'tramp-flush-file-function) + #'tramp-flush-file-function) (remove-hook 'kill-buffer-hook - 'tramp-flush-file-function))) + #'tramp-flush-file-function))) ;;; -- Properties -- @@ -452,11 +452,11 @@ used to cache connection properties of the local machine." (pp (read (format "(%s)" (tramp-cache-print cache))))))))))) (unless noninteractive - (add-hook 'kill-emacs-hook 'tramp-dump-connection-properties)) + (add-hook 'kill-emacs-hook #'tramp-dump-connection-properties)) (add-hook 'tramp-cache-unload-hook (lambda () (remove-hook 'kill-emacs-hook - 'tramp-dump-connection-properties))) + #'tramp-dump-connection-properties))) ;;;###tramp-autoload (defun tramp-parse-connection-properties (method) diff --git a/lisp/net/tramp-compat.el b/lisp/net/tramp-compat.el index 046966e019..df0e0887b4 100644 --- a/lisp/net/tramp-compat.el +++ b/lisp/net/tramp-compat.el @@ -45,8 +45,6 @@ (require 'timer) (require 'ucs-normalize) -(require 'tramp-loaddefs) - ;; For not existing functions, obsolete functions, or functions with a ;; changed argument list, there are compiler warnings. We want to ;; avoid them in cases we know what we do. @@ -230,6 +228,7 @@ If NAME is a remote file name, the local part of NAME is unquoted." ;; support old settings. (defsubst tramp-compat-tramp-syntax () "Return proper value of `tramp-syntax'." + (defvar tramp-syntax) (cond ((eq tramp-syntax 'ftp) 'default) ((eq tramp-syntax 'sep) 'separate) (t tramp-syntax))) diff --git a/lisp/net/tramp-ftp.el b/lisp/net/tramp-ftp.el index 5d8b56e218..8526b4e217 100644 --- a/lisp/net/tramp-ftp.el +++ b/lisp/net/tramp-ftp.el @@ -95,22 +95,19 @@ present for backward compatibility." ;; ... and add it to the method list. ;;;###tramp-autoload -(add-to-list 'tramp-methods (cons tramp-ftp-method nil)) +(tramp--with-startup + (add-to-list 'tramp-methods (cons tramp-ftp-method nil)) -;; Add some defaults for `tramp-default-method-alist'. -;;;###tramp-autoload -(add-to-list 'tramp-default-method-alist - (list "\\`ftp\\." nil tramp-ftp-method)) -;;;###tramp-autoload -(add-to-list 'tramp-default-method-alist - (list nil "\\`\\(anonymous\\|ftp\\)\\'" tramp-ftp-method)) + ;; Add some defaults for `tramp-default-method-alist'. + (add-to-list 'tramp-default-method-alist + (list "\\`ftp\\." nil tramp-ftp-method)) + (add-to-list 'tramp-default-method-alist + (list nil "\\`\\(anonymous\\|ftp\\)\\'" tramp-ftp-method)) -;; Add completion function for FTP method. -;;;###tramp-autoload -(eval-after-load 'tramp - '(tramp-set-completion-function - tramp-ftp-method - '((tramp-parse-netrc "~/.netrc")))) + ;; Add completion function for FTP method. + (tramp-set-completion-function + tramp-ftp-method + '((tramp-parse-netrc "~/.netrc")))) ;;;###tramp-autoload (defun tramp-ftp-file-name-handler (operation &rest args) @@ -188,8 +185,9 @@ pass to the OPERATION." tramp-ftp-method))) ;;;###tramp-autoload -(add-to-list 'tramp-foreign-file-name-handler-alist - (cons 'tramp-ftp-file-name-p 'tramp-ftp-file-name-handler)) +(tramp--with-startup + (add-to-list 'tramp-foreign-file-name-handler-alist + (cons #'tramp-ftp-file-name-p #'tramp-ftp-file-name-handler))) (add-hook 'tramp-unload-hook (lambda () diff --git a/lisp/net/tramp-gvfs.el b/lisp/net/tramp-gvfs.el index 295b288d06..047f4109d7 100644 --- a/lisp/net/tramp-gvfs.el +++ b/lisp/net/tramp-gvfs.el @@ -147,12 +147,13 @@ ;; Add defaults for `tramp-default-user-alist' and `tramp-default-host-alist'. ;;;###tramp-autoload -(when (string-match "\\(.+\\)@\\(\\(?:gmail\\|googlemail\\)\\.com\\)" - user-mail-address) - (add-to-list 'tramp-default-user-alist - `("\\`gdrive\\'" nil ,(match-string 1 user-mail-address))) - (add-to-list 'tramp-default-host-alist - '("\\`gdrive\\'" nil ,(match-string 2 user-mail-address)))) +(tramp--with-startup + (when (string-match "\\(.+\\)@\\(\\(?:gmail\\|googlemail\\)\\.com\\)" + user-mail-address) + (add-to-list 'tramp-default-user-alist + `("\\`gdrive\\'" nil ,(match-string 1 user-mail-address))) + (add-to-list 'tramp-default-host-alist + '("\\`gdrive\\'" nil ,(match-string 2 user-mail-address))))) ;;;###tramp-autoload (defcustom tramp-gvfs-zeroconf-domain "local" @@ -165,9 +166,10 @@ ;; completion. ;;;###tramp-autoload (when (featurep 'dbusbind) - (dolist (elt tramp-gvfs-methods) - (unless (assoc elt tramp-methods) - (add-to-list 'tramp-methods (cons elt nil))))) + (tramp--with-startup + (dolist (elt tramp-gvfs-methods) + (unless (assoc elt tramp-methods) + (add-to-list 'tramp-methods (cons elt nil)))))) (defconst tramp-gvfs-path-tramp (concat dbus-path-emacs "/Tramp") "The preceding object path for own objects.") @@ -621,8 +623,9 @@ pass to the OPERATION." ;;;###tramp-autoload (when (featurep 'dbusbind) - (tramp-register-foreign-file-name-handler - 'tramp-gvfs-file-name-p 'tramp-gvfs-file-name-handler)) + (tramp--with-startup + (tramp-register-foreign-file-name-handler + #'tramp-gvfs-file-name-p #'tramp-gvfs-file-name-handler))) ;; D-Bus helper function. diff --git a/lisp/net/tramp-rclone.el b/lisp/net/tramp-rclone.el index 18cb971bd1..4b94ab6bdc 100644 --- a/lisp/net/tramp-rclone.el +++ b/lisp/net/tramp-rclone.el @@ -50,13 +50,14 @@ :type 'string) ;;;###tramp-autoload -(add-to-list - 'tramp-methods - `(,tramp-rclone-method - (tramp-mount-args nil) - (tramp-copyto-args nil) - (tramp-moveto-args nil) - (tramp-about-args ("--full")))) +(tramp--with-startup + (add-to-list + 'tramp-methods + `(,tramp-rclone-method + (tramp-mount-args nil) + (tramp-copyto-args nil) + (tramp-moveto-args nil) + (tramp-about-args ("--full"))))) ;;;###tramp-autoload (eval-after-load 'tramp @@ -162,8 +163,9 @@ pass to the OPERATION." (tramp-run-real-handler operation args)))) ;;;###tramp-autoload -(tramp-register-foreign-file-name-handler - 'tramp-rclone-file-name-p 'tramp-rclone-file-name-handler) +(tramp--with-startup + (tramp-register-foreign-file-name-handler + #'tramp-rclone-file-name-p #'tramp-rclone-file-name-handler)) ;;;###tramp-autoload (defun tramp-rclone-parse-device-names (_ignore) diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el index a3038780e6..1aecebb37f 100644 --- a/lisp/net/tramp-sh.el +++ b/lisp/net/tramp-sh.el @@ -41,6 +41,7 @@ (defvar vc-git-program) (defvar vc-hg-program) +;; FIXME: Why autoload all those defcustoms? ;;;###tramp-autoload (defcustom tramp-inline-compress-start-size 4096 "The minimum size of compressing where inline transfer. @@ -84,11 +85,9 @@ the default storage location, e.g. \"$HOME/.sh_history\"." (const :tag "Unset HISTFILE" t) (string :tag "Redirect to a file"))) -;;;###tramp-autoload (defconst tramp-display-escape-sequence-regexp "\e[[;0-9]+m" "Terminal control escape sequences for display attributes.") -;;;###tramp-autoload (defconst tramp-device-escape-sequence-regexp "\e[[0-9]+n" "Terminal control escape sequences for device status.") @@ -134,285 +133,262 @@ The string is used in `tramp-methods'.") ;; Initialize `tramp-methods' with the supported methods. ;;;###tramp-autoload -(add-to-list 'tramp-methods - '("rcp" - (tramp-login-program "rsh") - (tramp-login-args (("%h") ("-l" "%u"))) - (tramp-remote-shell "/bin/sh") - (tramp-remote-shell-login ("-l")) - (tramp-remote-shell-args ("-c")) - (tramp-copy-program "rcp") - (tramp-copy-args (("-p" "%k") ("-r"))) - (tramp-copy-keep-date t) - (tramp-copy-recursive t))) -;;;###tramp-autoload -(add-to-list 'tramp-methods - '("remcp" - (tramp-login-program "remsh") - (tramp-login-args (("%h") ("-l" "%u"))) - (tramp-remote-shell "/bin/sh") - (tramp-remote-shell-login ("-l")) - (tramp-remote-shell-args ("-c")) - (tramp-copy-program "rcp") - (tramp-copy-args (("-p" "%k"))) - (tramp-copy-keep-date t))) -;;;###tramp-autoload -(add-to-list 'tramp-methods - '("scp" - (tramp-login-program "ssh") - (tramp-login-args (("-l" "%u") ("-p" "%p") ("%c") - ("-e" "none") ("%h"))) - (tramp-async-args (("-q"))) - (tramp-remote-shell "/bin/sh") - (tramp-remote-shell-login ("-l")) - (tramp-remote-shell-args ("-c")) - (tramp-copy-program "scp") - (tramp-copy-args (("-P" "%p") ("-p" "%k") ("-q") ("-r") ("%c"))) - (tramp-copy-keep-date t) - (tramp-copy-recursive t))) -;;;###tramp-autoload -(add-to-list 'tramp-methods - '("scpx" - (tramp-login-program "ssh") - (tramp-login-args (("-l" "%u") ("-p" "%p") ("%c") - ("-e" "none") ("-t" "-t") ("%h") ("/bin/sh"))) - (tramp-async-args (("-q"))) - (tramp-remote-shell "/bin/sh") - (tramp-remote-shell-login ("-l")) - (tramp-remote-shell-args ("-c")) - (tramp-copy-program "scp") - (tramp-copy-args (("-P" "%p") ("-p" "%k") - ("-q") ("-r") ("%c"))) - (tramp-copy-keep-date t) - (tramp-copy-recursive t))) -;;;###tramp-autoload -(add-to-list 'tramp-methods - '("rsync" - (tramp-login-program "ssh") - (tramp-login-args (("-l" "%u") ("-p" "%p") ("%c") - ("-e" "none") ("%h"))) - (tramp-async-args (("-q"))) - (tramp-remote-shell "/bin/sh") - (tramp-remote-shell-login ("-l")) - (tramp-remote-shell-args ("-c")) - (tramp-copy-program "rsync") - (tramp-copy-args (("-t" "%k") ("-p") ("-r") ("-s") ("-c"))) - (tramp-copy-env (("RSYNC_RSH") ("ssh" "%c"))) - (tramp-copy-keep-date t) - (tramp-copy-keep-tmpfile t) - (tramp-copy-recursive t))) -;;;###tramp-autoload -(add-to-list 'tramp-methods - '("rsh" - (tramp-login-program "rsh") - (tramp-login-args (("%h") ("-l" "%u"))) - (tramp-remote-shell "/bin/sh") - (tramp-remote-shell-login ("-l")) - (tramp-remote-shell-args ("-c")))) -;;;###tramp-autoload -(add-to-list 'tramp-methods - '("remsh" - (tramp-login-program "remsh") - (tramp-login-args (("%h") ("-l" "%u"))) - (tramp-remote-shell "/bin/sh") - (tramp-remote-shell-login ("-l")) - (tramp-remote-shell-args ("-c")))) -;;;###tramp-autoload -(add-to-list 'tramp-methods - '("ssh" - (tramp-login-program "ssh") - (tramp-login-args (("-l" "%u") ("-p" "%p") ("%c") - ("-e" "none") ("%h"))) - (tramp-async-args (("-q"))) - (tramp-remote-shell "/bin/sh") - (tramp-remote-shell-login ("-l")) - (tramp-remote-shell-args ("-c")))) -;;;###tramp-autoload -(add-to-list 'tramp-methods - '("sshx" - (tramp-login-program "ssh") - (tramp-login-args (("-l" "%u") ("-p" "%p") ("%c") - ("-e" "none") ("-t" "-t") ("%h") ("/bin/sh"))) - (tramp-async-args (("-q"))) - (tramp-remote-shell "/bin/sh") - (tramp-remote-shell-login ("-l")) - (tramp-remote-shell-args ("-c")))) -;;;###tramp-autoload -(add-to-list 'tramp-methods - '("telnet" - (tramp-login-program "telnet") - (tramp-login-args (("%h") ("%p") ("2>/dev/null"))) - (tramp-remote-shell "/bin/sh") - (tramp-remote-shell-login ("-l")) - (tramp-remote-shell-args ("-c")))) -;;;###tramp-autoload -(add-to-list 'tramp-methods - '("nc" - (tramp-login-program "telnet") - (tramp-login-args (("%h") ("%p") ("2>/dev/null"))) - (tramp-remote-shell "/bin/sh") - (tramp-remote-shell-login ("-l")) - (tramp-remote-shell-args ("-c")) - (tramp-copy-program "nc") - ;; We use "-v" for better error tracking. - (tramp-copy-args (("-w" "1") ("-v") ("%h") ("%r"))) - (tramp-remote-copy-program "nc") - ;; We use "-p" as required for newer busyboxes. For older - ;; busybox/nc versions, the value must be (("-l") ("%r")). This - ;; can be achieved by tweaking `tramp-connection-properties'. - (tramp-remote-copy-args (("-l") ("-p" "%r") ("2>/dev/null"))))) -;;;###tramp-autoload -(add-to-list 'tramp-methods - '("su" - (tramp-login-program "su") - (tramp-login-args (("-") ("%u"))) - (tramp-remote-shell "/bin/sh") - (tramp-remote-shell-login ("-l")) - (tramp-remote-shell-args ("-c")) - (tramp-connection-timeout 10))) -;;;###tramp-autoload -(add-to-list 'tramp-methods - '("sg" - (tramp-login-program "sg") - (tramp-login-args (("-") ("%u"))) - (tramp-remote-shell "/bin/sh") - (tramp-remote-shell-args ("-c")) - (tramp-connection-timeout 10))) -;;;###tramp-autoload -(add-to-list 'tramp-methods - '("sudo" - (tramp-login-program "sudo") - ;; The password template must be masked. Otherwise, it could be - ;; interpreted as password prompt if the remote host echoes the command. - (tramp-login-args (("-u" "%u") ("-s") ("-H") - ("-p" "P\"\"a\"\"s\"\"s\"\"w\"\"o\"\"r\"\"d\"\":"))) - ;; Local $SHELL could be a nasty one, like zsh or fish. Let's override it. - (tramp-login-env (("SHELL") ("/bin/sh"))) - (tramp-remote-shell "/bin/sh") - (tramp-remote-shell-login ("-l")) - (tramp-remote-shell-args ("-c")) - (tramp-connection-timeout 10) - (tramp-session-timeout 300))) -;;;###tramp-autoload -(add-to-list 'tramp-methods - '("doas" - (tramp-login-program "doas") - (tramp-login-args (("-u" "%u") ("-s"))) - (tramp-remote-shell "/bin/sh") - (tramp-remote-shell-args ("-c")) - (tramp-connection-timeout 10) - (tramp-session-timeout 300))) -;;;###tramp-autoload -(add-to-list 'tramp-methods - '("ksu" - (tramp-login-program "ksu") - (tramp-login-args (("%u") ("-q"))) - (tramp-remote-shell "/bin/sh") - (tramp-remote-shell-login ("-l")) - (tramp-remote-shell-args ("-c")) - (tramp-connection-timeout 10))) -;;;###tramp-autoload -(add-to-list 'tramp-methods - '("krlogin" - (tramp-login-program "krlogin") - (tramp-login-args (("%h") ("-l" "%u") ("-x"))) - (tramp-remote-shell "/bin/sh") - (tramp-remote-shell-login ("-l")) - (tramp-remote-shell-args ("-c")))) -;;;###tramp-autoload -(add-to-list 'tramp-methods - `("plink" - (tramp-login-program "plink") - (tramp-login-args (("-l" "%u") ("-P" "%p") ("-ssh") ("-t") - ("%h") ("\"") - (,(format - "env 'TERM=%s' 'PROMPT_COMMAND=' 'PS1=%s'" - tramp-terminal-type - tramp-initial-end-of-output)) - ("/bin/sh") ("\""))) - (tramp-remote-shell "/bin/sh") - (tramp-remote-shell-login ("-l")) - (tramp-remote-shell-args ("-c")))) -;;;###tramp-autoload -(add-to-list 'tramp-methods - `("plinkx" - (tramp-login-program "plink") - (tramp-login-args (("-load") ("%h") ("-t") ("\"") - (,(format - "env 'TERM=%s' 'PROMPT_COMMAND=' 'PS1=%s'" - tramp-terminal-type - tramp-initial-end-of-output)) - ("/bin/sh") ("\""))) - (tramp-remote-shell "/bin/sh") - (tramp-remote-shell-login ("-l")) - (tramp-remote-shell-args ("-c")))) -;;;###tramp-autoload -(add-to-list 'tramp-methods - `("pscp" - (tramp-login-program "plink") - (tramp-login-args (("-l" "%u") ("-P" "%p") ("-ssh") ("-t") - ("%h") ("\"") - (,(format - "env 'TERM=%s' 'PROMPT_COMMAND=' 'PS1=%s'" - tramp-terminal-type - tramp-initial-end-of-output)) - ("/bin/sh") ("\""))) - (tramp-remote-shell "/bin/sh") - (tramp-remote-shell-login ("-l")) - (tramp-remote-shell-args ("-c")) - (tramp-copy-program "pscp") - (tramp-copy-args (("-l" "%u") ("-P" "%p") ("-scp") ("-p" "%k") - ("-q") ("-r"))) - (tramp-copy-keep-date t) - (tramp-copy-recursive t))) -;;;###tramp-autoload -(add-to-list 'tramp-methods - `("psftp" - (tramp-login-program "plink") - (tramp-login-args (("-l" "%u") ("-P" "%p") ("-ssh") ("-t") - ("%h") ("\"") - (,(format - "env 'TERM=%s' 'PROMPT_COMMAND=' 'PS1=%s'" - tramp-terminal-type - tramp-initial-end-of-output)) - ("/bin/sh") ("\""))) - (tramp-remote-shell "/bin/sh") - (tramp-remote-shell-login ("-l")) - (tramp-remote-shell-args ("-c")) - (tramp-copy-program "pscp") - (tramp-copy-args (("-l" "%u") ("-P" "%p") ("-sftp") ("-p" "%k") - ("-q"))) - (tramp-copy-keep-date t))) -;;;###tramp-autoload -(add-to-list 'tramp-methods - '("fcp" - (tramp-login-program "fsh") - (tramp-login-args (("%h") ("-l" "%u") ("sh" "-i"))) - (tramp-remote-shell "/bin/sh") - (tramp-remote-shell-login ("-l")) - (tramp-remote-shell-args ("-i") ("-c")) - (tramp-copy-program "fcp") - (tramp-copy-args (("-p" "%k"))) - (tramp-copy-keep-date t))) - -;;;###tramp-autoload -(add-to-list 'tramp-default-method-alist - `(,tramp-local-host-regexp "\\`root\\'" "su")) - -;;;###tramp-autoload -(add-to-list 'tramp-default-user-alist - `(,(concat "\\`" (regexp-opt '("su" "sudo" "doas" "ksu")) "\\'") - nil "root")) -;; Do not add "ssh" based methods, otherwise ~/.ssh/config would be ignored. -;; Do not add "plink" based methods, they ask interactively for the user. -;;;###tramp-autoload -(add-to-list 'tramp-default-user-alist - `(,(concat - "\\`" - (regexp-opt - '("rcp" "remcp" "rsh" "telnet" "nc" "krlogin" "fcp")) - "\\'") - nil ,(user-login-name))) +(tramp--with-startup + (add-to-list 'tramp-methods + '("rcp" + (tramp-login-program "rsh") + (tramp-login-args (("%h") ("-l" "%u"))) + (tramp-remote-shell "/bin/sh") + (tramp-remote-shell-login ("-l")) + (tramp-remote-shell-args ("-c")) + (tramp-copy-program "rcp") + (tramp-copy-args (("-p" "%k") ("-r"))) + (tramp-copy-keep-date t) + (tramp-copy-recursive t))) + (add-to-list 'tramp-methods + '("remcp" + (tramp-login-program "remsh") + (tramp-login-args (("%h") ("-l" "%u"))) + (tramp-remote-shell "/bin/sh") + (tramp-remote-shell-login ("-l")) + (tramp-remote-shell-args ("-c")) + (tramp-copy-program "rcp") + (tramp-copy-args (("-p" "%k"))) + (tramp-copy-keep-date t))) + (add-to-list 'tramp-methods + '("scp" + (tramp-login-program "ssh") + (tramp-login-args (("-l" "%u") ("-p" "%p") ("%c") + ("-e" "none") ("%h"))) + (tramp-async-args (("-q"))) + (tramp-remote-shell "/bin/sh") + (tramp-remote-shell-login ("-l")) + (tramp-remote-shell-args ("-c")) + (tramp-copy-program "scp") + (tramp-copy-args (("-P" "%p") ("-p" "%k") ("-q") ("-r") ("%c"))) + (tramp-copy-keep-date t) + (tramp-copy-recursive t))) + (add-to-list 'tramp-methods + '("scpx" + (tramp-login-program "ssh") + (tramp-login-args (("-l" "%u") ("-p" "%p") ("%c") + ("-e" "none") ("-t" "-t") ("%h") ("/bin/sh"))) + (tramp-async-args (("-q"))) + (tramp-remote-shell "/bin/sh") + (tramp-remote-shell-login ("-l")) + (tramp-remote-shell-args ("-c")) + (tramp-copy-program "scp") + (tramp-copy-args (("-P" "%p") ("-p" "%k") + ("-q") ("-r") ("%c"))) + (tramp-copy-keep-date t) + (tramp-copy-recursive t))) + (add-to-list 'tramp-methods + '("rsync" + (tramp-login-program "ssh") + (tramp-login-args (("-l" "%u") ("-p" "%p") ("%c") + ("-e" "none") ("%h"))) + (tramp-async-args (("-q"))) + (tramp-remote-shell "/bin/sh") + (tramp-remote-shell-login ("-l")) + (tramp-remote-shell-args ("-c")) + (tramp-copy-program "rsync") + (tramp-copy-args (("-t" "%k") ("-p") ("-r") ("-s") ("-c"))) + (tramp-copy-env (("RSYNC_RSH") ("ssh" "%c"))) + (tramp-copy-keep-date t) + (tramp-copy-keep-tmpfile t) + (tramp-copy-recursive t))) + (add-to-list 'tramp-methods + '("rsh" + (tramp-login-program "rsh") + (tramp-login-args (("%h") ("-l" "%u"))) + (tramp-remote-shell "/bin/sh") + (tramp-remote-shell-login ("-l")) + (tramp-remote-shell-args ("-c")))) + (add-to-list 'tramp-methods + '("remsh" + (tramp-login-program "remsh") + (tramp-login-args (("%h") ("-l" "%u"))) + (tramp-remote-shell "/bin/sh") + (tramp-remote-shell-login ("-l")) + (tramp-remote-shell-args ("-c")))) + (add-to-list 'tramp-methods + '("ssh" + (tramp-login-program "ssh") + (tramp-login-args (("-l" "%u") ("-p" "%p") ("%c") + ("-e" "none") ("%h"))) + (tramp-async-args (("-q"))) + (tramp-remote-shell "/bin/sh") + (tramp-remote-shell-login ("-l")) + (tramp-remote-shell-args ("-c")))) + (add-to-list 'tramp-methods + '("sshx" + (tramp-login-program "ssh") + (tramp-login-args (("-l" "%u") ("-p" "%p") ("%c") + ("-e" "none") ("-t" "-t") ("%h") ("/bin/sh"))) + (tramp-async-args (("-q"))) + (tramp-remote-shell "/bin/sh") + (tramp-remote-shell-login ("-l")) + (tramp-remote-shell-args ("-c")))) + (add-to-list 'tramp-methods + '("telnet" + (tramp-login-program "telnet") + (tramp-login-args (("%h") ("%p") ("2>/dev/null"))) + (tramp-remote-shell "/bin/sh") + (tramp-remote-shell-login ("-l")) + (tramp-remote-shell-args ("-c")))) + (add-to-list 'tramp-methods + '("nc" + (tramp-login-program "telnet") + (tramp-login-args (("%h") ("%p") ("2>/dev/null"))) + (tramp-remote-shell "/bin/sh") + (tramp-remote-shell-login ("-l")) + (tramp-remote-shell-args ("-c")) + (tramp-copy-program "nc") + ;; We use "-v" for better error tracking. + (tramp-copy-args (("-w" "1") ("-v") ("%h") ("%r"))) + (tramp-remote-copy-program "nc") + ;; We use "-p" as required for newer busyboxes. For older + ;; busybox/nc versions, the value must be (("-l") ("%r")). This + ;; can be achieved by tweaking `tramp-connection-properties'. + (tramp-remote-copy-args (("-l") ("-p" "%r") ("2>/dev/null"))))) + (add-to-list 'tramp-methods + '("su" + (tramp-login-program "su") + (tramp-login-args (("-") ("%u"))) + (tramp-remote-shell "/bin/sh") + (tramp-remote-shell-login ("-l")) + (tramp-remote-shell-args ("-c")) + (tramp-connection-timeout 10))) + (add-to-list 'tramp-methods + '("sg" + (tramp-login-program "sg") + (tramp-login-args (("-") ("%u"))) + (tramp-remote-shell "/bin/sh") + (tramp-remote-shell-args ("-c")) + (tramp-connection-timeout 10))) + (add-to-list 'tramp-methods + '("sudo" + (tramp-login-program "sudo") + ;; The password template must be masked. Otherwise, it could be + ;; interpreted as password prompt if the remote host echoes the command. + (tramp-login-args (("-u" "%u") ("-s") ("-H") + ("-p" "P\"\"a\"\"s\"\"s\"\"w\"\"o\"\"r\"\"d\"\":"))) + ;; Local $SHELL could be a nasty one, like zsh or fish. Let's override it. + (tramp-login-env (("SHELL") ("/bin/sh"))) + (tramp-remote-shell "/bin/sh") + (tramp-remote-shell-login ("-l")) + (tramp-remote-shell-args ("-c")) + (tramp-connection-timeout 10) + (tramp-session-timeout 300))) + (add-to-list 'tramp-methods + '("doas" + (tramp-login-program "doas") + (tramp-login-args (("-u" "%u") ("-s"))) + (tramp-remote-shell "/bin/sh") + (tramp-remote-shell-args ("-c")) + (tramp-connection-timeout 10) + (tramp-session-timeout 300))) + (add-to-list 'tramp-methods + '("ksu" + (tramp-login-program "ksu") + (tramp-login-args (("%u") ("-q"))) + (tramp-remote-shell "/bin/sh") + (tramp-remote-shell-login ("-l")) + (tramp-remote-shell-args ("-c")) + (tramp-connection-timeout 10))) + (add-to-list 'tramp-methods + '("krlogin" + (tramp-login-program "krlogin") + (tramp-login-args (("%h") ("-l" "%u") ("-x"))) + (tramp-remote-shell "/bin/sh") + (tramp-remote-shell-login ("-l")) + (tramp-remote-shell-args ("-c")))) + (add-to-list 'tramp-methods + `("plink" + (tramp-login-program "plink") + (tramp-login-args (("-l" "%u") ("-P" "%p") ("-ssh") ("-t") + ("%h") ("\"") + (,(format + "env 'TERM=%s' 'PROMPT_COMMAND=' 'PS1=%s'" + tramp-terminal-type + tramp-initial-end-of-output)) + ("/bin/sh") ("\""))) + (tramp-remote-shell "/bin/sh") + (tramp-remote-shell-login ("-l")) + (tramp-remote-shell-args ("-c")))) + (add-to-list 'tramp-methods + `("plinkx" + (tramp-login-program "plink") + (tramp-login-args (("-load") ("%h") ("-t") ("\"") + (,(format + "env 'TERM=%s' 'PROMPT_COMMAND=' 'PS1=%s'" + tramp-terminal-type + tramp-initial-end-of-output)) + ("/bin/sh") ("\""))) + (tramp-remote-shell "/bin/sh") + (tramp-remote-shell-login ("-l")) + (tramp-remote-shell-args ("-c")))) + (add-to-list 'tramp-methods + `("pscp" + (tramp-login-program "plink") + (tramp-login-args (("-l" "%u") ("-P" "%p") ("-ssh") ("-t") + ("%h") ("\"") + (,(format + "env 'TERM=%s' 'PROMPT_COMMAND=' 'PS1=%s'" + tramp-terminal-type + tramp-initial-end-of-output)) + ("/bin/sh") ("\""))) + (tramp-remote-shell "/bin/sh") + (tramp-remote-shell-login ("-l")) + (tramp-remote-shell-args ("-c")) + (tramp-copy-program "pscp") + (tramp-copy-args (("-l" "%u") ("-P" "%p") ("-scp") ("-p" "%k") + ("-q") ("-r"))) + (tramp-copy-keep-date t) + (tramp-copy-recursive t))) + (add-to-list 'tramp-methods + `("psftp" + (tramp-login-program "plink") + (tramp-login-args (("-l" "%u") ("-P" "%p") ("-ssh") ("-t") + ("%h") ("\"") + (,(format + "env 'TERM=%s' 'PROMPT_COMMAND=' 'PS1=%s'" + tramp-terminal-type + tramp-initial-end-of-output)) + ("/bin/sh") ("\""))) + (tramp-remote-shell "/bin/sh") + (tramp-remote-shell-login ("-l")) + (tramp-remote-shell-args ("-c")) + (tramp-copy-program "pscp") + (tramp-copy-args (("-l" "%u") ("-P" "%p") ("-sftp") ("-p" "%k") + ("-q"))) + (tramp-copy-keep-date t))) + (add-to-list 'tramp-methods + '("fcp" + (tramp-login-program "fsh") + (tramp-login-args (("%h") ("-l" "%u") ("sh" "-i"))) + (tramp-remote-shell "/bin/sh") + (tramp-remote-shell-login ("-l")) + (tramp-remote-shell-args ("-i") ("-c")) + (tramp-copy-program "fcp") + (tramp-copy-args (("-p" "%k"))) + (tramp-copy-keep-date t))) + + (add-to-list 'tramp-default-method-alist + `(,tramp-local-host-regexp "\\`root\\'" "su")) + + (add-to-list 'tramp-default-user-alist + `(,(concat "\\`" (regexp-opt '("su" "sudo" "doas" "ksu")) "\\'") + nil "root")) + ;; Do not add "ssh" based methods, otherwise ~/.ssh/config would be ignored. + ;; Do not add "plink" based methods, they ask interactively for the user. + (add-to-list 'tramp-default-user-alist + `(,(concat + "\\`" + (regexp-opt + '("rcp" "remcp" "rsh" "telnet" "nc" "krlogin" "fcp")) + "\\'") + nil ,(user-login-name)))) ;;;###tramp-autoload (defconst tramp-completion-function-alist-rsh @@ -460,33 +436,32 @@ The string is used in `tramp-methods'.") "Default list of (FUNCTION REGISTRY) pairs to be examined for putty sessions.") ;;;###tramp-autoload -(eval-after-load 'tramp - '(progn - (tramp-set-completion-function "rcp" tramp-completion-function-alist-rsh) - (tramp-set-completion-function "remcp" tramp-completion-function-alist-rsh) - (tramp-set-completion-function "scp" tramp-completion-function-alist-ssh) - (tramp-set-completion-function "scpx" tramp-completion-function-alist-ssh) - (tramp-set-completion-function "rsync" tramp-completion-function-alist-ssh) - (tramp-set-completion-function "rsh" tramp-completion-function-alist-rsh) - (tramp-set-completion-function "remsh" tramp-completion-function-alist-rsh) - (tramp-set-completion-function "ssh" tramp-completion-function-alist-ssh) - (tramp-set-completion-function "sshx" tramp-completion-function-alist-ssh) - (tramp-set-completion-function - "telnet" tramp-completion-function-alist-telnet) - (tramp-set-completion-function "nc" tramp-completion-function-alist-telnet) - (tramp-set-completion-function "su" tramp-completion-function-alist-su) - (tramp-set-completion-function "sudo" tramp-completion-function-alist-su) - (tramp-set-completion-function "doas" tramp-completion-function-alist-su) - (tramp-set-completion-function "ksu" tramp-completion-function-alist-su) - (tramp-set-completion-function "sg" tramp-completion-function-alist-sg) - (tramp-set-completion-function - "krlogin" tramp-completion-function-alist-rsh) - (tramp-set-completion-function "plink" tramp-completion-function-alist-ssh) - (tramp-set-completion-function - "plinkx" tramp-completion-function-alist-putty) - (tramp-set-completion-function "pscp" tramp-completion-function-alist-ssh) - (tramp-set-completion-function "psftp" tramp-completion-function-alist-ssh) - (tramp-set-completion-function "fcp" tramp-completion-function-alist-ssh))) +(tramp--with-startup + (tramp-set-completion-function "rcp" tramp-completion-function-alist-rsh) + (tramp-set-completion-function "remcp" tramp-completion-function-alist-rsh) + (tramp-set-completion-function "scp" tramp-completion-function-alist-ssh) + (tramp-set-completion-function "scpx" tramp-completion-function-alist-ssh) + (tramp-set-completion-function "rsync" tramp-completion-function-alist-ssh) + (tramp-set-completion-function "rsh" tramp-completion-function-alist-rsh) + (tramp-set-completion-function "remsh" tramp-completion-function-alist-rsh) + (tramp-set-completion-function "ssh" tramp-completion-function-alist-ssh) + (tramp-set-completion-function "sshx" tramp-completion-function-alist-ssh) + (tramp-set-completion-function + "telnet" tramp-completion-function-alist-telnet) + (tramp-set-completion-function "nc" tramp-completion-function-alist-telnet) + (tramp-set-completion-function "su" tramp-completion-function-alist-su) + (tramp-set-completion-function "sudo" tramp-completion-function-alist-su) + (tramp-set-completion-function "doas" tramp-completion-function-alist-su) + (tramp-set-completion-function "ksu" tramp-completion-function-alist-su) + (tramp-set-completion-function "sg" tramp-completion-function-alist-sg) + (tramp-set-completion-function + "krlogin" tramp-completion-function-alist-rsh) + (tramp-set-completion-function "plink" tramp-completion-function-alist-ssh) + (tramp-set-completion-function + "plinkx" tramp-completion-function-alist-putty) + (tramp-set-completion-function "pscp" tramp-completion-function-alist-ssh) + (tramp-set-completion-function "psftp" tramp-completion-function-alist-ssh) + (tramp-set-completion-function "fcp" tramp-completion-function-alist-ssh)) ;; "getconf PATH" yields: ;; HP-UX: /usr/bin:/usr/ccs/bin:/opt/ansic/bin:/opt/langtools/bin:/opt/fortran/bin @@ -945,9 +920,9 @@ od -v -t x1 -A n Date: Sun Dec 16 15:49:07 2018 +0100 Add Tramp sudoedit method * doc/misc/tramp.texi (Quick Start Guide): New section "Using sudoedit". (External methods) : Describe. * lisp/net/tramp-adb.el (tramp-adb-file-name-handler-alist): * lisp/net/tramp-gvfs.el (tramp-gvfs-file-name-handler-alist): * lisp/net/tramp-rclone.el (tramp-rclone-file-name-handler-alist): * lisp/net/tramp-sh.el (tramp-sh-file-name-handler-alist) * lisp/net/tramp-smb.el (tramp-smb-file-name-handler-alist): Add handler. * lisp/net/tramp-sh.el (tramp-sh-handle-set-file-uid-gid): Rename from `tramp-sh-handle-set-file-uid-gid'. Handle only remote file names. * lisp/net/tramp-sudoedit.el: New file. * lisp/net/tramp.el (tramp-file-name-for-operation): Handle also `tramp-set-file-uid-gid'. (tramp-set-file-uid-gid): New defun. (tramp-get-local-uid, tramp-get-local-gid): Cache result. * test/lisp/net/tramp-tests.el (tramp--test-sudoedit-p): New defun. (tramp-test20-file-modes, tramp-test22-file-times) (tramp--test-sudoedit-p): Use it. diff --git a/doc/misc/tramp.texi b/doc/misc/tramp.texi index a4946f0b8d..c9f1e75d8e 100644 --- a/doc/misc/tramp.texi +++ b/doc/misc/tramp.texi @@ -468,6 +468,19 @@ The method @option{sg} stands for ``switch group''; the changed group must be used here as user name. The default host name is the same. +@anchor{Quick Start Guide: @option{sudoedit} method} +@section Using @command{sudoedit} +@cindex method @option{sudoedit} +@cindex @option{sudoedit} method + +The @option{sudoedit} method is similar to the @option{sudo} method. +However, it is a different implementation: it does not keep an open +session running in the background. This is for security reasons; on +the backside this method is less performant than the @option{sudo} +method, it is restricted to the @samp{localhost} only, and it does not +support external processes. + + @anchor{Quick Start Guide: @option{smb} method} @section Using @command{smbclient} @cindex method @option{smb} @@ -919,6 +932,30 @@ NAS hosts. These dumb devices have severely restricted local shells, such as the @command{busybox} and do not host any other encode or decode programs. +@item @option{sudoedit} +@cindex method @option{sudoedit} +@cindex @option{sudoedit} method + +The @option{sudoedit} method allows to edit a file as a different user +on the local host. You could regard this as @value{tramp}'s +implementation of the @command{sudoedit}. Contrary to the +@option{sudo} method, all magic file name functions are implemented by +single @command{sudo @dots{}} commands. The purpose is to make +editing such a file as secure as possible; there must be no session +running in the Emacs background which could be attacked from inside +Emacs. + +Consequently, external processes are not implemented. + +The host name of such remote file names must represent the local host. +Since the default value is already proper, it is recommended not to +use any host name in the remote file name, like +@file{@trampfn{sudoedit,,/path/to/file}} or +@file{@trampfn{sudoedit,user@@,/path/to/file}}. + +Like the @option{sudo} method, a @option{sudoedit} password expires +after a predefined timeout. + @item @option{ftp} @cindex method @option{ftp} @cindex @option{ftp} method diff --git a/etc/NEWS b/etc/NEWS index 0624c5690b..c88f6ef5ca 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -864,6 +864,12 @@ or NextCloud hosted files and directories. *** New connection method "rclone", which allows to access system storages via the 'rclone' program. This feature is experimental. ++++ +*** New connection method "sudoedit", which allows to edit local files +with different user credentials. Contrary to the "sudo" method, no +session is run permanently in the background. This is for security +reasons. + +++ *** Connection methods "obex" and "synce" are removed, because they are obsoleted in GVFS. diff --git a/lisp/net/tramp-adb.el b/lisp/net/tramp-adb.el index 7906ec9f7c..7bf709b79a 100644 --- a/lisp/net/tramp-adb.el +++ b/lisp/net/tramp-adb.el @@ -161,6 +161,7 @@ It is used for TCP/IP devices." (start-file-process . tramp-adb-handle-start-file-process) (substitute-in-file-name . tramp-handle-substitute-in-file-name) (temporary-file-directory . tramp-handle-temporary-file-directory) + (tramp-set-file-uid-gid . ignore) (unhandled-file-name-directory . ignore) (vc-registered . ignore) (verify-visited-file-modtime . tramp-handle-verify-visited-file-modtime) diff --git a/lisp/net/tramp-archive.el b/lisp/net/tramp-archive.el index cb072ac720..02580359f7 100644 --- a/lisp/net/tramp-archive.el +++ b/lisp/net/tramp-archive.el @@ -273,6 +273,7 @@ It must be supported by libarchive(3).") (start-file-process . tramp-archive-handle-not-implemented) ;; `substitute-in-file-name' performed by default handler. (temporary-file-directory . tramp-archive-handle-temporary-file-directory) + ;; `tramp-set-file-uid-gid' performed by default handler. (unhandled-file-name-directory . ignore) (vc-registered . ignore) (verify-visited-file-modtime . tramp-handle-verify-visited-file-modtime) diff --git a/lisp/net/tramp-cache.el b/lisp/net/tramp-cache.el index 0a799d721d..d13e6ee9f5 100644 --- a/lisp/net/tramp-cache.el +++ b/lisp/net/tramp-cache.el @@ -50,10 +50,11 @@ ;; definitions already sent to the remote shell, "last-cmd-time" is ;; the time stamp a command has been sent to the remote process. ;; -;; - The key is `nil'. This are temporary properties related to the +;; - The key is nil. This are temporary properties related to the ;; local machine. Examples: "parse-passwd" and "parse-group" keep -;; the results of parsing "/etc/passwd" and "/etc/group", "locale" -;; is the used shell locale. +;; the results of parsing "/etc/passwd" and "/etc/group", +;; "{uid,gid}-{integer,string}" are the local uid and gid, and +;; "locale" is the used shell locale. ;; Some properties are handled special: ;; diff --git a/lisp/net/tramp-gvfs.el b/lisp/net/tramp-gvfs.el index e034f7bba5..295b288d06 100644 --- a/lisp/net/tramp-gvfs.el +++ b/lisp/net/tramp-gvfs.el @@ -589,6 +589,7 @@ It has been changed in GVFS 1.14.") (start-file-process . ignore) (substitute-in-file-name . tramp-handle-substitute-in-file-name) (temporary-file-directory . tramp-handle-temporary-file-directory) + (tramp-set-file-uid-gid . ignore) (unhandled-file-name-directory . ignore) (vc-registered . ignore) (verify-visited-file-modtime . tramp-handle-verify-visited-file-modtime) @@ -1843,7 +1844,7 @@ connection if a previous connection has died for some reason." (tramp-get-connection-process vec) "connected" t)))) ;; In `tramp-check-cached-permissions', the connection properties - ;; {uig,gid}-{integer,string} are used. We set them to proper values. + ;; "{uid,gid}-{integer,string}" are used. We set them to proper values. (unless tramp-gvfs-get-remote-uid-gid-in-progress (let ((tramp-gvfs-get-remote-uid-gid-in-progress t)) (tramp-gvfs-get-remote-uid vec 'integer) diff --git a/lisp/net/tramp-rclone.el b/lisp/net/tramp-rclone.el index 5ea42c07bf..18cb971bd1 100644 --- a/lisp/net/tramp-rclone.el +++ b/lisp/net/tramp-rclone.el @@ -134,6 +134,7 @@ (start-file-process . ignore) (substitute-in-file-name . tramp-handle-substitute-in-file-name) (temporary-file-directory . tramp-handle-temporary-file-directory) + (tramp-set-file-uid-gid . ignore) (unhandled-file-name-directory . ignore) (vc-registered . ignore) (verify-visited-file-modtime . tramp-handle-verify-visited-file-modtime) @@ -575,7 +576,7 @@ connection if a previous connection has died for some reason." (tramp-cleanup-connection vec 'keep-debug 'keep-password))))) ;; In `tramp-check-cached-permissions', the connection properties - ;; {uig,gid}-{integer,string} are used. We set them to proper values. + ;; "{uid,gid}-{integer,string}" are used. We set them to proper values. (with-tramp-connection-property vec "uid-integer" (tramp-get-local-uid 'integer)) (with-tramp-connection-property diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el index a6e9d299a8..a3038780e6 100644 --- a/lisp/net/tramp-sh.el +++ b/lisp/net/tramp-sh.el @@ -1044,6 +1044,7 @@ of command line.") (start-file-process . tramp-sh-handle-start-file-process) (substitute-in-file-name . tramp-handle-substitute-in-file-name) (temporary-file-directory . tramp-handle-temporary-file-directory) + (tramp-set-file-uid-gid . tramp-sh-handle-set-file-uid-gid) (unhandled-file-name-directory . ignore) (vc-registered . tramp-sh-handle-vc-registered) (verify-visited-file-modtime . tramp-sh-handle-verify-visited-file-modtime) @@ -1516,39 +1517,26 @@ of." "") (tramp-shell-quote-argument localname))))))) -(defun tramp-set-file-uid-gid (filename &optional uid gid) - "Set the ownership for FILENAME. -If UID and GID are provided, these values are used; otherwise uid -and gid of the corresponding user is taken. Both parameters must -be non-negative integers." +(defun tramp-sh-handle-set-file-uid-gid (filename &optional uid gid) + "Like `tramp-set-file-uid-gid' for Tramp files." ;; Modern Unices allow chown only for root. So we might need ;; another implementation, see `dired-do-chown'. OTOH, it is mostly ;; working with su(do)? when it is needed, so it shall succeed in ;; the majority of cases. ;; Don't modify `last-coding-system-used' by accident. (let ((last-coding-system-used last-coding-system-used)) - (if (tramp-tramp-file-p filename) - (with-parsed-tramp-file-name filename nil - (if (and (zerop (user-uid)) (tramp-local-host-p v)) - ;; If we are root on the local host, we can do it directly. - (tramp-set-file-uid-gid localname uid gid) - (let ((uid (or (and (natnump uid) uid) - (tramp-get-remote-uid v 'integer))) - (gid (or (and (natnump gid) gid) - (tramp-get-remote-gid v 'integer)))) - (tramp-send-command - v (format - "chown %d:%d %s" uid gid - (tramp-shell-quote-argument localname)))))) - - ;; We handle also the local part, because there doesn't exist - ;; `set-file-uid-gid'. On W32 "chown" does not work. - (unless (memq system-type '(ms-dos windows-nt)) - (let ((uid (or (and (natnump uid) uid) (tramp-get-local-uid 'integer))) - (gid (or (and (natnump gid) gid) (tramp-get-local-gid 'integer)))) - (tramp-call-process - nil "chown" nil nil nil - (format "%d:%d" uid gid) (shell-quote-argument filename))))))) + (with-parsed-tramp-file-name filename nil + (if (and (zerop (user-uid)) (tramp-local-host-p v)) + ;; If we are root on the local host, we can do it directly. + (tramp-set-file-uid-gid localname uid gid) + (let ((uid (or (and (natnump uid) uid) + (tramp-get-remote-uid v 'integer))) + (gid (or (and (natnump gid) gid) + (tramp-get-remote-gid v 'integer)))) + (tramp-send-command + v (format + "chown %d:%d %s" uid gid + (tramp-shell-quote-argument localname)))))))) (defun tramp-remote-selinux-p (vec) "Check, whether SELINUX is enabled on the remote host." @@ -2114,6 +2102,7 @@ file names." ;; Handle `preserve-extended-attributes'. We ignore possible ;; errors, because ACL strings could be incompatible. + ;; `set-file-extended-attributes' exists since Emacs 24.4. (when attributes (ignore-errors (apply 'set-file-extended-attributes (list newname attributes)))) diff --git a/lisp/net/tramp-smb.el b/lisp/net/tramp-smb.el index 5b7998ac97..fcc6f6c6ef 100644 --- a/lisp/net/tramp-smb.el +++ b/lisp/net/tramp-smb.el @@ -282,6 +282,7 @@ See `tramp-actions-before-shell' for more info.") (start-file-process . tramp-smb-handle-start-file-process) (substitute-in-file-name . tramp-smb-handle-substitute-in-file-name) (temporary-file-directory . tramp-handle-temporary-file-directory) + (tramp-set-file-uid-gid . ignore) (unhandled-file-name-directory . ignore) (vc-registered . ignore) (verify-visited-file-modtime . tramp-handle-verify-visited-file-modtime) diff --git a/lisp/net/tramp-sudoedit.el b/lisp/net/tramp-sudoedit.el new file mode 100644 index 0000000000..640fa570ff --- /dev/null +++ b/lisp/net/tramp-sudoedit.el @@ -0,0 +1,880 @@ +;;; tramp-sudoedit.el --- Functions for accessing under root permissions -*- lexical-binding:t -*- + +;; Copyright (C) 2018 Free Software Foundation, Inc. + +;; Author: Michael Albinus +;; Keywords: comm, processes +;; Package: tramp + +;; This file is part of GNU Emacs. + +;; GNU Emacs is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; GNU Emacs is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs. If not, see . + +;;; Commentary: + +;; The "sudoedit" Tramp method allows to edit a file as a different +;; user on the local host. Contrary to the "sudo" method, all magic +;; file name functions are implemented by single "sudo ..." commands. +;; The purpose is to make editing such a file as secure as possible; +;; there must be no session running in the Emacs background which +;; could be attacked from inside Emacs. + +;; Consequently, external processes are not implemented. + +;;; Code: + +(require 'tramp) +(require 'server) + +;;;###tramp-autoload +(defconst tramp-sudoedit-method "sudoedit" + "When this method name is used, call sudoedit for editing a file.") + +;;;###tramp-autoload +(add-to-list 'tramp-methods + `(,tramp-sudoedit-method + (tramp-sudo-login (("sudo") ("-u" "%u") ("-S") ("-H") + ("-p" "Password:") ("--"))))) + +;;;###tramp-autoload +(add-to-list 'tramp-default-user-alist '("\\`sudoedit\\'" nil "root")) + +;;;###tramp-autoload +(eval-after-load 'tramp + '(tramp-set-completion-function + tramp-sudoedit-method tramp-completion-function-alist-su)) + +(defconst tramp-sudoedit-sudo-actions + '((tramp-password-prompt-regexp tramp-action-password) + (tramp-wrong-passwd-regexp tramp-action-permission-denied) + (tramp-process-alive-regexp tramp-sudoedit-action-sudo)) + "List of pattern/action pairs. +This list is used for sudo calls. + +See `tramp-actions-before-shell' for more info.") + +;;;###tramp-autoload +(defconst tramp-sudoedit-file-name-handler-alist + '((access-file . ignore) + (add-name-to-file . tramp-sudoedit-handle-add-name-to-file) + (byte-compiler-base-file-name . ignore) + ;; `copy-directory' performed by default handler. + (copy-file . tramp-sudoedit-handle-copy-file) + (delete-directory . tramp-sudoedit-handle-delete-directory) + (delete-file . tramp-sudoedit-handle-delete-file) + (diff-latest-backup-file . ignore) + ;; `directory-file-name' performed by default handler. + (directory-files . tramp-handle-directory-files) + (directory-files-and-attributes + . tramp-handle-directory-files-and-attributes) + (dired-compress-file . ignore) + (dired-uncache . tramp-handle-dired-uncache) + (exec-path . ignore) + (expand-file-name . tramp-sudoedit-handle-expand-file-name) + (file-accessible-directory-p . tramp-handle-file-accessible-directory-p) + (file-acl . tramp-sudoedit-handle-file-acl) + (file-attributes . tramp-sudoedit-handle-file-attributes) + (file-directory-p . tramp-handle-file-directory-p) + (file-equal-p . tramp-handle-file-equal-p) + (file-executable-p . tramp-sudoedit-handle-file-executable-p) + (file-exists-p . tramp-sudoedit-handle-file-exists-p) + (file-in-directory-p . tramp-handle-file-in-directory-p) + (file-local-copy . tramp-handle-file-local-copy) + (file-modes . tramp-handle-file-modes) + (file-name-all-completions + . tramp-sudoedit-handle-file-name-all-completions) + (file-name-as-directory . tramp-handle-file-name-as-directory) + (file-name-case-insensitive-p . tramp-handle-file-name-case-insensitive-p) + (file-name-completion . tramp-handle-file-name-completion) + (file-name-directory . tramp-handle-file-name-directory) + (file-name-nondirectory . tramp-handle-file-name-nondirectory) + ;; `file-name-sans-versions' performed by default handler. + (file-newer-than-file-p . tramp-handle-file-newer-than-file-p) + (file-notify-add-watch . ignore) + (file-notify-rm-watch . ignore) + (file-notify-valid-p . ignore) + (file-ownership-preserved-p . ignore) + (file-readable-p . tramp-sudoedit-handle-file-readable-p) + (file-regular-p . tramp-handle-file-regular-p) + (file-remote-p . tramp-handle-file-remote-p) + (file-selinux-context . tramp-sudoedit-handle-file-selinux-context) + (file-symlink-p . tramp-handle-file-symlink-p) + (file-system-info . tramp-sudoedit-handle-file-system-info) + (file-truename . tramp-sudoedit-handle-file-truename) + (file-writable-p . tramp-sudoedit-handle-file-writable-p) + (find-backup-file-name . tramp-handle-find-backup-file-name) + ;; `get-file-buffer' performed by default handler. + (insert-directory . tramp-handle-insert-directory) + (insert-file-contents . tramp-handle-insert-file-contents) + (load . tramp-handle-load) + (make-auto-save-file-name . tramp-handle-make-auto-save-file-name) + (make-directory . tramp-sudoedit-handle-make-directory) + (make-directory-internal . ignore) + (make-nearby-temp-file . tramp-handle-make-nearby-temp-file) + (make-symbolic-link . tramp-sudoedit-handle-make-symbolic-link) + (process-file . ignore) + (rename-file . tramp-sudoedit-handle-rename-file) + (set-file-acl . tramp-sudoedit-handle-set-file-acl) + (set-file-modes . tramp-sudoedit-handle-set-file-modes) + (set-file-selinux-context . tramp-sudoedit-handle-set-file-selinux-context) + (set-file-times . tramp-sudoedit-handle-set-file-times) + (set-visited-file-modtime . tramp-handle-set-visited-file-modtime) + (shell-command . ignore) + (start-file-process . ignore) + (substitute-in-file-name . tramp-handle-substitute-in-file-name) + (temporary-file-directory . tramp-handle-temporary-file-directory) + (tramp-set-file-uid-gid . tramp-sudoedit-handle-set-file-uid-gid) + (unhandled-file-name-directory . ignore) + (vc-registered . ignore) + (verify-visited-file-modtime . tramp-handle-verify-visited-file-modtime) + (write-region . tramp-sudoedit-handle-write-region)) + "Alist of handler functions for Tramp SUDOEDIT method.") + +;; It must be a `defsubst' in order to push the whole code into +;; tramp-loaddefs.el. Otherwise, there would be recursive autoloading. +;;;###tramp-autoload +(defsubst tramp-sudoedit-file-name-p (filename) + "Check if it's a filename for SUDOEDIT." + (and (tramp-tramp-file-p filename) + (string= (tramp-file-name-method (tramp-dissect-file-name filename)) + tramp-sudoedit-method))) + +;;;###tramp-autoload +(defun tramp-sudoedit-file-name-handler (operation &rest args) + "Invoke the SUDOEDIT handler for OPERATION. +First arg specifies the OPERATION, second arg is a list of arguments to +pass to the OPERATION." + (let ((fn (assoc operation tramp-sudoedit-file-name-handler-alist))) + (if fn + (save-match-data (apply (cdr fn) args)) + (tramp-run-real-handler operation args)))) + +;;;###tramp-autoload +(tramp-register-foreign-file-name-handler + 'tramp-sudoedit-file-name-p 'tramp-sudoedit-file-name-handler) + + +;; File name primitives. + +(defun tramp-sudoedit-handle-add-name-to-file + (filename newname &optional ok-if-already-exists) + "Like `add-name-to-file' for Tramp files." + (unless (tramp-equal-remote filename newname) + (with-parsed-tramp-file-name + (if (tramp-tramp-file-p filename) filename newname) nil + (tramp-error + v 'file-error + "add-name-to-file: %s" + "only implemented for same method, same user, same host"))) + (with-parsed-tramp-file-name filename v1 + (with-parsed-tramp-file-name newname v2 + ;; Do the 'confirm if exists' thing. + (when (file-exists-p newname) + ;; What to do? + (if (or (null ok-if-already-exists) ; not allowed to exist + (and (numberp ok-if-already-exists) + (not (yes-or-no-p + (format + "File %s already exists; make it a link anyway? " + v2-localname))))) + (tramp-error v2 'file-already-exists newname) + (delete-file newname))) + (tramp-flush-file-properties v2 (file-name-directory v2-localname)) + (tramp-flush-file-properties v2 v2-localname) + (unless + (tramp-sudoedit-send-command + v1 "ln" + (tramp-compat-file-name-unquote v1-localname) + (tramp-compat-file-name-unquote v2-localname)) + (tramp-error + v1 'file-error + "error with add-name-to-file, see buffer `%s' for details" + (buffer-name)))))) + +(defun tramp-sudoedit-do-copy-or-rename-file + (op filename newname &optional ok-if-already-exists keep-date + preserve-uid-gid preserve-extended-attributes) + "Copy or rename a remote file. +OP must be `copy' or `rename' and indicates the operation to perform. +FILENAME specifies the file to copy or rename, NEWNAME is the name of +the new file (for copy) or the new name of the file (for rename). +OK-IF-ALREADY-EXISTS means don't barf if NEWNAME exists already. +KEEP-DATE means to make sure that NEWNAME has the same timestamp +as FILENAME. PRESERVE-UID-GID, when non-nil, instructs to keep +the uid and gid if both files are on the same host. +PRESERVE-EXTENDED-ATTRIBUTES activates selinux and acl commands. + +This function is invoked by `tramp-sudoedit-handle-copy-file' and +`tramp-sudoedit-handle-rename-file'. It is an error if OP is +neither of `copy' and `rename'. FILENAME and NEWNAME must be +absolute file names." + (unless (memq op '(copy rename)) + (error "Unknown operation `%s', must be `copy' or `rename'" op)) + + (setq filename (file-truename filename)) + (if (file-directory-p filename) + (progn + (copy-directory filename newname keep-date t) + (when (eq op 'rename) (delete-directory filename 'recursive))) + + (let ((t1 (tramp-sudoedit-file-name-p filename)) + (t2 (tramp-sudoedit-file-name-p newname)) + (file-times (tramp-compat-file-attribute-modification-time + (file-attributes filename))) + (file-modes (tramp-default-file-modes filename)) + ;; `file-extended-attributes' exists since Emacs 24.4. + (attributes (and preserve-extended-attributes + (apply 'file-extended-attributes (list filename)))) + (sudoedit-operation + (cond + ((and (eq op 'copy) preserve-uid-gid) '("cp" "-f" "-p")) + ((eq op 'copy) '("cp" "-f")) + ((eq op 'rename) '("mv" "-f")))) + (msg-operation (if (eq op 'copy) "Copying" "Renaming"))) + + (with-parsed-tramp-file-name (if t1 filename newname) nil + (when (and (not ok-if-already-exists) (file-exists-p newname)) + (tramp-error v 'file-already-exists newname)) + + (if (or (and (file-remote-p filename) (not t1)) + (and (file-remote-p newname) (not t2))) + ;; We cannot copy or rename directly. + (let ((tmpfile (tramp-compat-make-temp-file filename))) + (if (eq op 'copy) + (copy-file filename tmpfile t) + (rename-file filename tmpfile t)) + (rename-file tmpfile newname ok-if-already-exists)) + + ;; Direct action. + (with-tramp-progress-reporter + v 0 (format "%s %s to %s" msg-operation filename newname) + (unless (tramp-sudoedit-send-command + v sudoedit-operation + (tramp-compat-file-name-unquote + (tramp-compat-file-local-name filename)) + (tramp-compat-file-name-unquote + (tramp-compat-file-local-name newname))) + (tramp-error + v 'file-error + "Error %s `%s' `%s'" msg-operation filename newname)))) + + ;; When `newname' is local, we must change the ownership to + ;; the local user. + (unless (file-remote-p newname) + (tramp-set-file-uid-gid + (concat (file-remote-p filename) newname) + (tramp-get-local-uid 'integer) + (tramp-get-local-gid 'integer))) + + ;; Set the time and mode. Mask possible errors. + (when keep-date + (ignore-errors + (set-file-times newname file-times) + (set-file-modes newname file-modes))) + + ;; Handle `preserve-extended-attributes'. We ignore possible + ;; errors, because ACL strings could be incompatible. + ;; `set-file-extended-attributes' exists since Emacs 24.4. + (when attributes + (ignore-errors + (apply 'set-file-extended-attributes (list newname attributes)))) + + (when (and t1 (eq op 'rename)) + (with-parsed-tramp-file-name filename v1 + (tramp-flush-file-properties + v1 (file-name-directory v1-localname)) + (tramp-flush-file-properties v1 v1-localname))) + + (when t2 + (with-parsed-tramp-file-name newname v2 + (tramp-flush-file-properties + v2 (file-name-directory v2-localname)) + (tramp-flush-file-properties v2 v2-localname) + (when (tramp-rclone-file-name-p newname)))))))) + +(defun tramp-sudoedit-handle-copy-file + (filename newname &optional ok-if-already-exists keep-date + preserve-uid-gid preserve-extended-attributes) + "Like `copy-file' for Tramp files." + (setq filename (expand-file-name filename)) + (setq newname (expand-file-name newname)) + ;; At least one file a Tramp file? + (if (or (tramp-tramp-file-p filename) + (tramp-tramp-file-p newname)) + (tramp-sudoedit-do-copy-or-rename-file + 'copy filename newname ok-if-already-exists keep-date + preserve-uid-gid preserve-extended-attributes) + (tramp-run-real-handler + 'copy-file + (list filename newname ok-if-already-exists keep-date + preserve-uid-gid preserve-extended-attributes)))) + +(defun tramp-sudoedit-handle-delete-directory + (directory &optional recursive trash) + "Like `delete-directory' for Tramp files." + (setq directory (expand-file-name directory)) + (with-parsed-tramp-file-name directory nil + (tramp-flush-file-properties v (file-name-directory localname)) + (tramp-flush-directory-properties v localname) + (unless + (tramp-sudoedit-send-command + v (or (and trash "trash") + (if recursive '("rm" "-rf") "rmdir")) + (tramp-compat-file-name-unquote localname)) + (tramp-error v 'file-error "Couldn't delete %s" directory)))) + +(defun tramp-sudoedit-handle-delete-file (filename &optional trash) + "Like `delete-file' for Tramp files." + (with-parsed-tramp-file-name filename nil + (tramp-flush-file-properties v (file-name-directory localname)) + (tramp-flush-file-properties v localname) + (unless + (tramp-sudoedit-send-command + v (if (and trash delete-by-moving-to-trash) "trash" "rm") + (tramp-compat-file-name-unquote localname)) + ;; Propagate the error. + (with-current-buffer (tramp-get-connection-buffer v) + (goto-char (point-min)) + (tramp-error-with-buffer + nil v 'file-error "Couldn't delete %s" filename))))) + +(defun tramp-sudoedit-handle-expand-file-name (name &optional dir) + "Like `expand-file-name' for Tramp files. +If the localname part of the given file name starts with \"/../\" then +the result will be a local, non-Tramp, file name." + ;; If DIR is not given, use `default-directory' or "/". + (setq dir (or dir default-directory "/")) + ;; Unless NAME is absolute, concat DIR and NAME. + (unless (file-name-absolute-p name) + (setq name (concat (file-name-as-directory dir) name))) + (with-parsed-tramp-file-name name nil + ;; Tilde expansion if necessary. We cannot accept "~/", because + ;; under sudo "~/" is expanded to the local user home directory + ;; but to the root home directory. + (when (zerop (length localname)) + (setq localname "~")) + (unless (file-name-absolute-p localname) + (setq localname (format "~%s/%s" user localname))) + (when (string-match "\\`\\(~[^/]*\\)\\(.*\\)\\'" localname) + (let ((uname (match-string 1 localname)) + (fname (match-string 2 localname))) + (when (string-equal uname "~") + (setq uname (concat uname user))) + (setq localname (concat uname fname)))) + ;; Do normal `expand-file-name' (this does "~user/", "/./" and "/../"). + (tramp-make-tramp-file-name v (expand-file-name localname)))) + +(defun tramp-sudoedit-remote-acl-p (vec) + "Check, whether ACL is enabled on the remote host." + (with-tramp-connection-property (tramp-get-connection-process vec) "acl-p" + (zerop (tramp-call-process vec "getfacl" nil nil nil "/")))) + +(defun tramp-sudoedit-handle-file-acl (filename) + "Like `file-acl' for Tramp files." + (with-parsed-tramp-file-name filename nil + (with-tramp-file-property v localname "file-acl" + (let ((result (and (tramp-sudoedit-remote-acl-p v) + (tramp-sudoedit-send-command-string + v "getfacl" "-acp" + (tramp-compat-file-name-unquote localname))))) + ;; The acl string must have a trailing \n, which is not + ;; provided by `tramp-sudoedit-send-command-string'. Add it. + (and (stringp result) (concat result "\n")))))) + +(defun tramp-sudoedit-handle-file-attributes (filename &optional id-format) + "Like `file-attributes' for Tramp files." + (unless id-format (setq id-format 'integer)) + (with-parsed-tramp-file-name (expand-file-name filename) nil + (with-tramp-file-property + v localname (format "file-attributes-%s" id-format) + (tramp-message v 5 "file attributes: %s" localname) + (ignore-errors + (tramp-convert-file-attributes + v + (tramp-sudoedit-send-command-and-read + v "env" "QUOTING_STYLE=locale" "stat" "-c" + (format + ;; Apostrophes in the stat output are masked as + ;; `tramp-stat-marker', in order to make a proper shell + ;; escape of them in file names. + "((%s%%N%s) %%h %s %s %%X %%Y %%Z %%s %s%%A%s t %%i -1)" + tramp-stat-marker tramp-stat-marker + (if (eq id-format 'integer) + "%u" + (eval-when-compile + (concat tramp-stat-marker "%U" tramp-stat-marker))) + (if (eq id-format 'integer) + "%g" + (eval-when-compile + (concat tramp-stat-marker "%G" tramp-stat-marker))) + tramp-stat-marker tramp-stat-marker) + (tramp-compat-file-name-unquote localname))))))) + +(defun tramp-sudoedit-handle-file-executable-p (filename) + "Like `file-executable-p' for Tramp files." + (with-parsed-tramp-file-name filename nil + (with-tramp-file-property v localname "file-executable-p" + (tramp-sudoedit-send-command + v "test" "-x" (tramp-compat-file-name-unquote localname))))) + +(defun tramp-sudoedit-handle-file-exists-p (filename) + "Like `file-exists-p' for Tramp files." + (with-parsed-tramp-file-name filename nil + (with-tramp-file-property v localname "file-exists-p" + (tramp-sudoedit-send-command + v "test" "-e" (tramp-compat-file-name-unquote localname))))) + +(defun tramp-sudoedit-handle-file-name-all-completions (filename directory) + "Like `file-name-all-completions' for Tramp files." + (all-completions + filename + (with-parsed-tramp-file-name (expand-file-name directory) nil + (with-tramp-file-property v localname "file-name-all-completions" + (tramp-sudoedit-send-command + v "ls" "-a1" "--quoting-style=literal" "--show-control-chars" + (if (zerop (length localname)) + "" (tramp-compat-file-name-unquote localname))) + (mapcar + (lambda (f) + (if (file-directory-p (expand-file-name f directory)) + (file-name-as-directory f) + f)) + (with-current-buffer (tramp-get-connection-buffer v) + (delq + nil + (mapcar + (lambda (l) (and (not (string-match-p "^[[:space:]]*$" l)) l)) + (split-string (buffer-string) "\n" 'omit))))))))) + +(defun tramp-sudoedit-handle-file-readable-p (filename) + "Like `file-readable-p' for Tramp files." + (with-parsed-tramp-file-name filename nil + (with-tramp-file-property v localname "file-readable-p" + (tramp-sudoedit-send-command + v "test" "-r" (tramp-compat-file-name-unquote localname))))) + +(defun tramp-sudoedit-handle-set-file-modes (filename mode) + "Like `set-file-modes' for Tramp files." + (with-parsed-tramp-file-name filename nil + (tramp-flush-file-properties v (file-name-directory localname)) + (tramp-flush-file-properties v localname) + (unless (tramp-sudoedit-send-command + v "chmod" (format "%o" mode) + (tramp-compat-file-name-unquote localname)) + (tramp-error + v 'file-error "Error while changing file's mode %s" filename)))) + +(defun tramp-sudoedit-remote-selinux-p (vec) + "Check, whether SELINUX is enabled on the remote host." + (with-tramp-connection-property (tramp-get-connection-process vec) "selinux-p" + (zerop (tramp-call-process vec "selinuxenabled")))) + +(defun tramp-sudoedit-handle-file-selinux-context (filename) + "Like `file-selinux-context' for Tramp files." + (with-parsed-tramp-file-name filename nil + (with-tramp-file-property v localname "file-selinux-context" + (let ((context '(nil nil nil nil)) + (regexp (eval-when-compile + (concat "\\([a-z0-9_]+\\):" "\\([a-z0-9_]+\\):" + "\\([a-z0-9_]+\\):" "\\([a-z0-9_]+\\)")))) + (when (and (tramp-sudoedit-remote-selinux-p v) + (tramp-sudoedit-send-command + v "ls" "-d" "-Z" + (tramp-compat-file-name-unquote localname))) + (with-current-buffer (tramp-get-connection-buffer v) + (goto-char (point-min)) + (when (re-search-forward regexp (point-at-eol) t) + (setq context (list (match-string 1) (match-string 2) + (match-string 3) (match-string 4)))))) + ;; Return the context. + context)))) + +(defun tramp-sudoedit-handle-file-system-info (filename) + "Like `file-system-info' for Tramp files." + (ignore-errors + (with-parsed-tramp-file-name (expand-file-name filename) nil + (tramp-message v 5 "file system info: %s" localname) + (when (tramp-sudoedit-send-command + v "df" "--block-size=1" "--output=size,used,avail" + (tramp-compat-file-name-unquote localname))) + (with-current-buffer (tramp-get-connection-buffer v) + (goto-char (point-min)) + (forward-line) + (when (looking-at + (eval-when-compile + (concat "[[:space:]]*\\([[:digit:]]+\\)" + "[[:space:]]+\\([[:digit:]]+\\)" + "[[:space:]]+\\([[:digit:]]+\\)"))) + (list (string-to-number (match-string 1)) + ;; The second value is the used size. We need the + ;; free size. + (- (string-to-number (match-string 1)) + (string-to-number (match-string 2))) + (string-to-number (match-string 3)))))))) + +(defun tramp-sudoedit-handle-set-file-times (filename &optional time) + "Like `set-file-times' for Tramp files." + (with-parsed-tramp-file-name filename nil + (tramp-flush-file-properties v (file-name-directory localname)) + (tramp-flush-file-properties v localname) + (let ((time + (if (or (null time) + (tramp-compat-time-equal-p time tramp-time-doesnt-exist) + (tramp-compat-time-equal-p time tramp-time-dont-know)) + (current-time) + time))) + (tramp-sudoedit-send-command + v "env" "TZ=UTC" "touch" "-t" + (format-time-string "%Y%m%d%H%M.%S" time t) + (tramp-compat-file-name-unquote localname))))) + +(defun tramp-sudoedit-handle-file-truename (filename) + "Like `file-truename' for Tramp files." + ;; Preserve trailing "/". + (funcall + (if (string-equal (file-name-nondirectory filename) "") + 'file-name-as-directory 'identity) + (with-parsed-tramp-file-name (expand-file-name filename) nil + (tramp-make-tramp-file-name + v + (with-tramp-file-property v localname "file-truename" + (let ((quoted (tramp-compat-file-name-quoted-p localname)) + (localname (tramp-compat-file-name-unquote localname)) + result) + (tramp-message v 4 "Finding true name for `%s'" filename) + (setq result (tramp-sudoedit-send-command-string + v "readlink" "--canonicalize-missing" localname)) + ;; Detect cycle. + (when (and (file-symlink-p filename) + (string-equal result localname)) + (tramp-error + v 'file-error + "Apparent cycle of symbolic links for %s" filename)) + ;; If the resulting localname looks remote, we must quote it + ;; for security reasons. + (when (or quoted (file-remote-p result)) + (let (file-name-handler-alist) + (setq result (tramp-compat-file-name-quote result)))) + (tramp-message v 4 "True name of `%s' is `%s'" localname result) + result)) + 'nohop)))) + +(defun tramp-sudoedit-handle-file-writable-p (filename) + "Like `file-writable-p' for Tramp files." + (with-parsed-tramp-file-name filename nil + (with-tramp-file-property v localname "file-writable-p" + (if (file-exists-p filename) + (tramp-sudoedit-send-command + v "test" "-w" (tramp-compat-file-name-unquote localname)) + (let ((dir (file-name-directory filename))) + (and (file-exists-p dir) + (file-writable-p dir))))))) + +(defun tramp-sudoedit-handle-make-directory (dir &optional parents) + "Like `make-directory' for Tramp files." + (setq dir (expand-file-name dir)) + (with-parsed-tramp-file-name dir nil + ;; When PARENTS is non-nil, DIR could be a chain of non-existent + ;; directories a/b/c/... Instead of checking, we simply flush the + ;; whole cache. + (tramp-flush-directory-properties + v (if parents "/" (file-name-directory localname))) + (unless (tramp-sudoedit-send-command + v (if parents '("mkdir" "-p") "mkdir") + (tramp-compat-file-name-unquote localname)) + (tramp-error v 'file-error "Couldn't make directory %s" dir)))) + +(defun tramp-sudoedit-handle-make-symbolic-link + (target linkname &optional ok-if-already-exists) + "Like `make-symbolic-link' for Tramp files. +If TARGET is a non-Tramp file, it is used verbatim as the target +of the symlink. If TARGET is a Tramp file, only the localname +component is used as the target of the symlink." + (if (not (tramp-tramp-file-p (expand-file-name linkname))) + (tramp-run-real-handler + 'make-symbolic-link (list target linkname ok-if-already-exists)) + + (with-parsed-tramp-file-name linkname nil + ;; If TARGET is a Tramp name, use just the localname component. + (when (and (tramp-tramp-file-p target) + (tramp-file-name-equal-p v (tramp-dissect-file-name target))) + (setq target + (tramp-file-name-localname + (tramp-dissect-file-name (expand-file-name target))))) + + ;; If TARGET is still remote, quote it. + (if (tramp-tramp-file-p target) + (make-symbolic-link + (let (file-name-handler-alist) (tramp-compat-file-name-quote target)) + linkname ok-if-already-exists) + + ;; Do the 'confirm if exists' thing. + (when (file-exists-p linkname) + ;; What to do? + (if (or (null ok-if-already-exists) ; not allowed to exist + (and (numberp ok-if-already-exists) + (not + (yes-or-no-p + (format + "File %s already exists; make it a link anyway? " + localname))))) + (tramp-error v 'file-already-exists localname) + (delete-file linkname))) + + (tramp-flush-file-properties v (file-name-directory localname)) + (tramp-flush-file-properties v localname) + (tramp-sudoedit-send-command + v "ln" "-sf" + (tramp-compat-file-name-unquote target) + (tramp-compat-file-name-unquote localname)))))) + +(defun tramp-sudoedit-handle-rename-file + (filename newname &optional ok-if-already-exists) + "Like `rename-file' for Tramp files." + (setq filename (expand-file-name filename)) + (setq newname (expand-file-name newname)) + ;; At least one file a Tramp file? + (if (or (tramp-tramp-file-p filename) + (tramp-tramp-file-p newname)) + (tramp-sudoedit-do-copy-or-rename-file + 'rename filename newname ok-if-already-exists + 'keep-date 'preserve-uid-gid) + (tramp-run-real-handler + 'rename-file (list filename newname ok-if-already-exists)))) + +(defun tramp-sudoedit-handle-set-file-acl (filename acl-string) + "Like `set-file-acl' for Tramp files." + (with-parsed-tramp-file-name (expand-file-name filename) nil + (when (and (stringp acl-string) (tramp-sudoedit-remote-acl-p v)) + ;; Massage `acl-string'. + (setq acl-string + (mapconcat 'identity (split-string acl-string "\n" 'omit) ",")) + (prog1 + (tramp-sudoedit-send-command + v "setfacl" "-m" + acl-string (tramp-compat-file-name-unquote localname)) + (tramp-flush-file-property v localname "file-acl"))))) + +(defun tramp-sudoedit-handle-set-file-selinux-context (filename context) + "Like `set-file-selinux-context' for Tramp files." + (with-parsed-tramp-file-name filename nil + (when (and (consp context) + (tramp-sudoedit-remote-selinux-p v)) + (let ((user (and (stringp (nth 0 context)) (nth 0 context))) + (role (and (stringp (nth 1 context)) (nth 1 context))) + (type (and (stringp (nth 2 context)) (nth 2 context))) + (range (and (stringp (nth 3 context)) (nth 3 context)))) + (when (tramp-sudoedit-send-command + v "chcon" + (when user (format "--user=%s" user)) + (when role (format "--role=%s" role)) + (when type (format "--type=%s" type)) + (when range (format "--range=%s" range)) + (tramp-compat-file-name-unquote localname)) + (if (and user role type range) + (tramp-set-file-property + v localname "file-selinux-context" context) + (tramp-flush-file-property v localname "file-selinux-context")) + t))))) + +(defun tramp-sudoedit-get-remote-uid (vec id-format) + "The uid of the remote connection VEC, in ID-FORMAT. +ID-FORMAT valid values are `string' and `integer'." + (with-tramp-connection-property vec (format "uid-%s" id-format) + (if (equal id-format 'integer) + (tramp-sudoedit-send-command-and-read vec "id" "-u") + (tramp-sudoedit-send-command-string vec "id" "-un")))) + +(defun tramp-sudoedit-get-remote-gid (vec id-format) + "The gid of the remote connection VEC, in ID-FORMAT. +ID-FORMAT valid values are `string' and `integer'." + (with-tramp-connection-property vec (format "gid-%s" id-format) + (if (equal id-format 'integer) + (tramp-sudoedit-send-command-and-read vec "id" "-g") + (tramp-sudoedit-send-command-string vec "id" "-gn")))) + +(defun tramp-sudoedit-handle-set-file-uid-gid (filename &optional uid gid) + "Like `tramp-set-file-uid-gid' for Tramp files." + (with-parsed-tramp-file-name filename nil + (tramp-sudoedit-send-command + v "chown" + (format "%d:%d" + (or uid (tramp-sudoedit-get-remote-uid v 'integer)) + (or gid (tramp-sudoedit-get-remote-gid v 'integer))) + (tramp-compat-file-name-unquote + (tramp-compat-file-local-name filename))))) + +(defun tramp-sudoedit-handle-write-region + (start end filename &optional append visit lockname mustbenew) + "Like `write-region' for Tramp files." + (with-parsed-tramp-file-name filename nil + (let ((uid (or (tramp-compat-file-attribute-user-id + (file-attributes filename 'integer)) + (tramp-sudoedit-get-remote-uid v 'integer))) + (gid (or (tramp-compat-file-attribute-group-id + (file-attributes filename 'integer)) + (tramp-sudoedit-get-remote-gid v 'integer))) + (modes (tramp-default-file-modes filename))) + (prog1 + (tramp-handle-write-region + start end filename append visit lockname mustbenew) + + ;; Set the ownership and modes. This is not performed in + ;; `tramp-handle-write-region'. + (unless (and (= (tramp-compat-file-attribute-user-id + (file-attributes filename 'integer)) + uid) + (= (tramp-compat-file-attribute-group-id + (file-attributes filename 'integer)) + gid)) + (tramp-set-file-uid-gid filename uid gid)) + (set-file-modes filename modes))))) + + +;; Internal functions. + +;; Used in `tramp-sudoedit-sudo-actions'. +(defun tramp-sudoedit-action-sudo (proc vec) + "Check, whether a sudo process copy has finished." + ;; There might be pending output for the exit status. + (tramp-accept-process-output proc 0.1) + (when (not (process-live-p proc)) + ;; Delete narrowed region, it would be in the way reading a Lisp form. + (goto-char (point-min)) + (widen) + (delete-region (point-min) (point)) + ;; Delete empty lines. + (goto-char (point-min)) + (while (and (not (eobp)) (= (point) (point-at-eol))) + (forward-line)) + (delete-region (point-min) (point)) + (tramp-message vec 3 "Process has finished.") + (throw 'tramp-action 'ok))) + +(defun tramp-sudoedit-maybe-open-connection (vec) + "Maybe open a connection VEC. +Does not do anything if a connection is already open, but re-opens the +connection if a previous connection has died for some reason." + ;; We need a process bound to the connection buffer. Therefore, we + ;; create a dummy process. Maybe there is a better solution? + (unless (tramp-get-connection-process vec) + (let ((p (make-network-process + :name (tramp-buffer-name vec) + :buffer (tramp-get-connection-buffer vec) + :server t :host 'local :service t :noquery t))) + (process-put p 'vector vec) + (set-process-query-on-exit-flag p nil) + + ;; Set connection-local variables. + (tramp-set-connection-local-variables vec)) + + ;; In `tramp-check-cached-permissions', the connection properties + ;; "{uid,gid}-{integer,string}" are used. We set them to proper values. + (tramp-sudoedit-get-remote-uid vec 'integer) + (tramp-sudoedit-get-remote-gid vec 'integer) + (tramp-sudoedit-get-remote-uid vec 'string) + (tramp-sudoedit-get-remote-gid vec 'string))) + +(defun tramp-sudoedit-send-command (vec &rest args) + "Send commands ARGS to connection VEC. +If an element of ARGS is a list, it will be flattened. If an +element of ARGS is nil, it will be deleted. +Erases temporary buffer before sending the command. Returns nil +in case of error, t otherwise." + (tramp-sudoedit-maybe-open-connection vec) + (with-current-buffer (tramp-get-connection-buffer vec) + (erase-buffer) + (let* ((login (tramp-get-method-parameter vec 'tramp-sudo-login)) + (host (or (tramp-file-name-host vec) "")) + (user (or (tramp-file-name-user vec) "")) + (spec (format-spec-make ?h host ?u user)) + (args (append + (tramp-compat-flatten-list + (mapcar + (lambda (x) + (setq x (mapcar (lambda (y) (format-spec y spec)) x)) + (unless (member "" x) x)) + login)) + (tramp-compat-flatten-list (delq nil args)))) + (delete-exited-processes t) + (process-connection-type tramp-process-connection-type) + (p (apply 'start-process + (tramp-get-connection-name vec) (current-buffer) args)) + ;; We suppress the messages `Waiting for prompts from remote shell'. + (tramp-verbose (if (= tramp-verbose 3) 2 tramp-verbose)) + ;; We do not want to save the password. + auth-source-save-behavior) + (tramp-message vec 6 "%s" (mapconcat 'identity (process-command p) " ")) + ;; Avoid process status message in output buffer. + (set-process-sentinel p 'ignore) + (process-put p 'vector vec) + (process-put p 'adjust-window-size-function 'ignore) + (set-process-query-on-exit-flag p nil) + (tramp-process-actions p vec nil tramp-sudoedit-sudo-actions) + (tramp-message vec 6 "%s\n%s" (process-exit-status p) (buffer-string)) + (prog1 + (zerop (process-exit-status p)) + (delete-process p))))) + +(defun tramp-sudoedit-send-command-and-read (vec &rest args) + "Run command ARGS and return the output, which must be a Lisp expression. +In case there is no valid Lisp expression, it raises an error." + (when (apply 'tramp-sudoedit-send-command vec args) + (with-current-buffer (tramp-get-connection-buffer vec) + ;; Replace stat marker. + (goto-char (point-min)) + (when (search-forward tramp-stat-marker nil t) + (goto-char (point-min)) + (while (search-forward "\"" nil t) + (replace-match "\\\"" nil 'literal)) + (goto-char (point-min)) + (while (search-forward tramp-stat-marker nil t) + (replace-match "\""))) + ;; Read the expression. + (tramp-message vec 6 "\n%s" (buffer-string)) + (goto-char (point-min)) + (condition-case nil + (prog1 (read (current-buffer)) + ;; Error handling. + (when (re-search-forward "\\S-" (point-at-eol) t) + (error nil))) + (error (tramp-error + vec 'file-error + "`%s' does not return a valid Lisp expression: `%s'" + (car args) (buffer-string))))))) + +(defun tramp-sudoedit-send-command-string (vec &rest args) + "Run command ARGS and return the output as astring." + (when (apply 'tramp-sudoedit-send-command vec args) + (with-current-buffer (tramp-get-connection-buffer vec) + (tramp-message vec 6 "\n%s" (buffer-string)) + (goto-char (point-max)) + ;(delete-blank-lines) + (while (looking-back "[ \t\n]+" nil 'greedy) + (delete-region (match-beginning 0) (point))) + (when (> (point-max) (point-min)) + (substring-no-properties (buffer-string)))))) + +(add-hook 'tramp-unload-hook + (lambda () + (unload-feature 'tramp-sudoedit 'force))) + +(provide 'tramp-sudoedit) + +;;; TODO: + +;; * Fix *-selinux functions. Likely, this is due to wrong file +;; ownership after `write-region' and/or `copy-file'. + +;;; tramp-sudoedit.el ends here diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el index a44abfdcbb..a1514f85a3 100644 --- a/lisp/net/tramp.el +++ b/lisp/net/tramp.el @@ -2234,7 +2234,9 @@ ARGS are the arguments OPERATION has been called with." ;; Emacs 26+ only. file-name-case-insensitive-p ;; Emacs 27+ only. - file-system-info)) + file-system-info + ;; Tramp internal magic file name function. + tramp-set-file-uid-gid)) (if (file-name-absolute-p (nth 0 args)) (nth 0 args) default-directory)) @@ -4329,24 +4331,49 @@ This is used internally by `tramp-file-mode-from-int'." (and suid (upcase suid-text)) ; suid, !execute (and x "x") "-")))) ; !suid +;; This is a Tramp internal function. A general `set-file-uid-gid' +;; outside Tramp is not needed, I believe. +(defun tramp-set-file-uid-gid (filename &optional uid gid) + "Set the ownership for FILENAME. +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. +If FILENAME is remote, a file name handler is called." + (let ((handler (find-file-name-handler filename 'tramp-set-file-uid-gid))) + (if handler + (funcall handler 'tramp-set-file-uid-gid filename uid gid) + ;; On W32 "chown" does not work. + (unless (memq system-type '(ms-dos windows-nt)) + (let ((uid (or (and (natnump uid) uid) (tramp-get-local-uid 'integer))) + (gid (or (and (natnump gid) gid) (tramp-get-local-gid 'integer)))) + (tramp-call-process + nil "chown" nil nil nil + (format "%d:%d" uid gid) (shell-quote-argument filename))))))) + ;;;###tramp-autoload (defun tramp-get-local-uid (id-format) "The uid of the local user, in ID-FORMAT. ID-FORMAT valid values are `string' and `integer'." - (if (equal id-format 'integer) (user-uid) (user-login-name))) + ;; We use key nil for local connection properties. + (with-tramp-connection-property nil (format "uid-%s" id-format) + (if (equal id-format 'integer) (user-uid) (user-login-name)))) ;;;###tramp-autoload (defun tramp-get-local-gid (id-format) "The gid of the local user, in ID-FORMAT. ID-FORMAT valid values are `string' and `integer'." - (cond - ;; `group-gid' has been introduced with Emacs 24.4. - ((and (fboundp 'group-gid) (equal id-format 'integer)) - (tramp-compat-funcall 'group-gid)) - ;; `group-name' has been introduced with Emacs 27.1. - ((and (fboundp 'group-name) (equal id-format 'string)) - (tramp-compat-funcall 'group-name (tramp-compat-funcall 'group-gid))) - ((tramp-compat-file-attribute-group-id (file-attributes "~/" id-format))))) + ;; We use key nil for local connection properties. + (with-tramp-connection-property nil (format "gid-%s" id-format) + (cond + ;; `group-gid' has been introduced with Emacs 24.4. + ((and (fboundp 'group-gid) (equal id-format 'integer)) + (tramp-compat-funcall 'group-gid)) + ;; `group-name' has been introduced with Emacs 27.1. + ((and (fboundp 'group-name) (equal id-format 'string)) + (tramp-compat-funcall 'group-name (tramp-compat-funcall 'group-gid))) + ((tramp-compat-file-attribute-group-id + (file-attributes "~/" id-format)))))) (defun tramp-get-local-locale (&optional vec) "Determine locale, supporting UTF8 if possible. diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el index d68804a1c4..056b6ce836 100644 --- a/test/lisp/net/tramp-tests.el +++ b/test/lisp/net/tramp-tests.el @@ -3009,7 +3009,7 @@ This tests also `file-readable-p', `file-regular-p' and "Check `file-modes'. This tests also `file-executable-p', `file-writable-p' and `set-file-modes'." (skip-unless (tramp--test-enabled)) - (skip-unless (tramp--test-sh-p)) + (skip-unless (or (tramp--test-sh-p) (tramp--test-sudoedit-p))) (dolist (quoted (if (tramp--test-expensive-test) '(nil t) '(nil))) (let ((tmp-name (tramp--test-make-temp-name nil quoted))) @@ -3309,7 +3309,8 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'." (ert-deftest tramp-test22-file-times () "Check `set-file-times' and `file-newer-than-file-p'." (skip-unless (tramp--test-enabled)) - (skip-unless (or (tramp--test-adb-p) (tramp--test-sh-p))) + (skip-unless + (or (tramp--test-adb-p) (tramp--test-sh-p) (tramp--test-sudoedit-p))) (dolist (quoted (if (tramp--test-expensive-test) '(nil t) '(nil))) (let ((tmp-name1 (tramp--test-make-temp-name nil quoted)) @@ -4567,6 +4568,10 @@ This does not support special file names." (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory) 'tramp-sh-file-name-handler)) +(defun tramp--test-sudoedit-p () + "Check, whether the sudoedit method is used." + (tramp-sudoedit-file-name-p tramp-test-temporary-file-directory)) + (defun tramp--test-windows-nt () "Check, whether the locale host runs MS Windows." (eq system-type 'windows-nt)) @@ -4761,6 +4766,7 @@ This requires restrictions of file name syntax." (list (if (or (tramp--test-gvfs-p) (tramp--test-rclone-p) + (tramp--test-sudoedit-p) (tramp--test-windows-nt-or-smb-p)) "foo bar baz" (if (or (tramp--test-adb-p) commit 4f230e8dd551d711433e2a8095a19c2ce00c9b4c Author: João Távora Date: Sun Dec 16 11:45:27 2018 +0000 Rephrase a confusing sentence in the jsonrpc.el manual * doc/lispref/text.texi (JSONRPC Overview): Rephrase first sentence on building JSONRPC applications. diff --git a/doc/lispref/text.texi b/doc/lispref/text.texi index 6d93264758..d0185eb08e 100644 --- a/doc/lispref/text.texi +++ b/doc/lispref/text.texi @@ -5179,11 +5179,11 @@ class: @item A user interface for building JSONRPC applications -In this scenario, the JSONRPC application instantiates -@code{jsonrpc-connection} objects of one of its concrete subclasses -using @code{make-instance}. To initiate a contact to the remote -endpoint, the JSONRPC application passes this object to the functions -@code{jsonrpc-notify'}, @code{jsonrpc-request} and +In this scenario, the JSONRPC application selects a concrete subclass +of @code{jsonrpc-connection}, and proceeds to create objects of that +subclass using @code{make-instance}. To initiate a contact to the +remote endpoint, the JSONRPC application passes this object to the +functions @code{jsonrpc-notify'}, @code{jsonrpc-request} and @code{jsonrpc-async-request}. For handling remotely initiated contacts, which generally come in asynchronously, the instantiation should include @code{:request-dispatcher} and