diff options
| author | Michael Albinus | 2018-11-21 13:23:01 +0100 |
|---|---|---|
| committer | Michael Albinus | 2018-11-21 13:23:01 +0100 |
| commit | fb200f3e5775fa2811ba270c2a7b0295b42539a0 (patch) | |
| tree | dc9975797d2d784d82d7fc1c05632fd9d9eba559 | |
| parent | 166f6274b4118344612e60fba831e223728f3e89 (diff) | |
| download | emacs-fb200f3e5775fa2811ba270c2a7b0295b42539a0.tar.gz emacs-fb200f3e5775fa2811ba270c2a7b0295b42539a0.zip | |
Let Tramp sudo sessions expire after a timeout
* doc/misc/tramp.texi (Inline methods) <sudo, doas>: Both methods expire
the underlying session per default.
(Predefined connection information): Explain "session-timeout".
* etc/NEWS: Mention Tramp session expiration.
* lisp/net/tramp-sh.el (tramp-methods) <sudo, doas>:
Add `tramp-session-timeout'.
(tramp-timeout-session): New defun.
(tramp-maybe-open-connection): Handle session timeout.
* lisp/net/tramp.el (tramp-methods): Adapt docstring.
(tramp-equal-remote): Extend.
| -rw-r--r-- | doc/misc/tramp.texi | 26 | ||||
| -rw-r--r-- | etc/NEWS | 5 | ||||
| -rw-r--r-- | lisp/net/tramp-sh.el | 54 | ||||
| -rw-r--r-- | lisp/net/tramp.el | 18 |
4 files changed, 84 insertions, 19 deletions
diff --git a/doc/misc/tramp.texi b/doc/misc/tramp.texi index 8cd0a72fc8c..79185285623 100644 --- a/doc/misc/tramp.texi +++ b/doc/misc/tramp.texi | |||
| @@ -721,11 +721,17 @@ the host returned by the function @command{(system-name)}. See | |||
| 721 | Similar to @option{su} method, @option{sudo} uses @command{sudo}. | 721 | Similar to @option{su} method, @option{sudo} uses @command{sudo}. |
| 722 | @command{sudo} must have sufficient rights to start a shell. | 722 | @command{sudo} must have sufficient rights to start a shell. |
| 723 | 723 | ||
| 724 | Due to security reasons, a @option{sudo} connection is disabled after | ||
| 725 | a predefined timeout (5 minutes per default). This can be changed, | ||
| 726 | see @ref{Predefined connection information}. | ||
| 727 | |||
| 724 | @item @option{doas} | 728 | @item @option{doas} |
| 725 | @cindex method @option{doas} | 729 | @cindex method @option{doas} |
| 726 | @cindex @option{doas} method | 730 | @cindex @option{doas} method |
| 727 | 731 | ||
| 728 | This method is used on OpenBSD like the @command{sudo} command. | 732 | This method is used on OpenBSD like the @command{sudo} command. Like |
| 733 | the @option{sudo} method, a @option{sudo} connection is disabled after | ||
| 734 | a predefined timeout. | ||
| 729 | 735 | ||
| 730 | @item @option{sg} | 736 | @item @option{sg} |
| 731 | @cindex method @option{sg} | 737 | @cindex method @option{sg} |
| @@ -1826,6 +1832,24 @@ The parameters @code{tramp-remote-shell} and | |||
| 1826 | @code{tramp-remote-shell-login} in @code{tramp-methods} now have new | 1832 | @code{tramp-remote-shell-login} in @code{tramp-methods} now have new |
| 1827 | values for the remote host. | 1833 | values for the remote host. |
| 1828 | 1834 | ||
| 1835 | A common use case is to override the session timeout of a connection, | ||
| 1836 | that is the time (in seconds) after a connection is disabled, and must | ||
| 1837 | be reestablished. This can be set for any connection; for the | ||
| 1838 | @option{sudo} and @option{doas} methods there exist predefined values. | ||
| 1839 | A value of @code{nil} disables this feature. For example: | ||
| 1840 | |||
| 1841 | @lisp | ||
| 1842 | @group | ||
| 1843 | (add-to-list 'tramp-connection-properties | ||
| 1844 | (list (regexp-quote "@trampfn{sudo,root@@system-name,}") | ||
| 1845 | "session-timeout" 30)) | ||
| 1846 | @end group | ||
| 1847 | @end lisp | ||
| 1848 | |||
| 1849 | @noindent | ||
| 1850 | @samp{system-name} stands here for the host returned by the function | ||
| 1851 | @command{(system-name)}. | ||
| 1852 | |||
| 1829 | @var{property} could also be any property found in | 1853 | @var{property} could also be any property found in |
| 1830 | @code{tramp-persistency-file-name}. | 1854 | @code{tramp-persistency-file-name}. |
| 1831 | 1855 | ||
| @@ -832,6 +832,11 @@ Tramp for some look-alike remote file names. | |||
| 832 | *** For some connection methods, like "su" or "sudo", the host name in | 832 | *** For some connection methods, like "su" or "sudo", the host name in |
| 833 | ad-hoc multi-hop file names must match the previous hop. | 833 | ad-hoc multi-hop file names must match the previous hop. |
| 834 | 834 | ||
| 835 | +++ | ||
| 836 | *** For the connection methods "sudo" and "doas" there exists a | ||
| 837 | timeout, after which the underlying session is disabled. This is for | ||
| 838 | security reasons. | ||
| 839 | |||
| 835 | ** Rcirc | 840 | ** Rcirc |
| 836 | 841 | ||
| 837 | --- | 842 | --- |
diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el index 4fb011b3423..4965f835b0c 100644 --- a/lisp/net/tramp-sh.el +++ b/lisp/net/tramp-sh.el | |||
| @@ -271,14 +271,13 @@ The string is used in `tramp-methods'.") | |||
| 271 | (tramp-remote-shell-args ("-c")) | 271 | (tramp-remote-shell-args ("-c")) |
| 272 | (tramp-connection-timeout 10))) | 272 | (tramp-connection-timeout 10))) |
| 273 | ;;;###tramp-autoload | 273 | ;;;###tramp-autoload |
| 274 | (add-to-list | 274 | (add-to-list 'tramp-methods |
| 275 | 'tramp-methods | 275 | '("sg" |
| 276 | '("sg" | 276 | (tramp-login-program "sg") |
| 277 | (tramp-login-program "sg") | 277 | (tramp-login-args (("-") ("%u"))) |
| 278 | (tramp-login-args (("-") ("%u"))) | 278 | (tramp-remote-shell "/bin/sh") |
| 279 | (tramp-remote-shell "/bin/sh") | 279 | (tramp-remote-shell-args ("-c")) |
| 280 | (tramp-remote-shell-args ("-c")) | 280 | (tramp-connection-timeout 10))) |
| 281 | (tramp-connection-timeout 10))) | ||
| 282 | ;;;###tramp-autoload | 281 | ;;;###tramp-autoload |
| 283 | (add-to-list 'tramp-methods | 282 | (add-to-list 'tramp-methods |
| 284 | '("sudo" | 283 | '("sudo" |
| @@ -292,7 +291,8 @@ The string is used in `tramp-methods'.") | |||
| 292 | (tramp-remote-shell "/bin/sh") | 291 | (tramp-remote-shell "/bin/sh") |
| 293 | (tramp-remote-shell-login ("-l")) | 292 | (tramp-remote-shell-login ("-l")) |
| 294 | (tramp-remote-shell-args ("-c")) | 293 | (tramp-remote-shell-args ("-c")) |
| 295 | (tramp-connection-timeout 10))) | 294 | (tramp-connection-timeout 10) |
| 295 | (tramp-session-timeout 300))) | ||
| 296 | ;;;###tramp-autoload | 296 | ;;;###tramp-autoload |
| 297 | (add-to-list 'tramp-methods | 297 | (add-to-list 'tramp-methods |
| 298 | '("doas" | 298 | '("doas" |
| @@ -300,7 +300,8 @@ The string is used in `tramp-methods'.") | |||
| 300 | (tramp-login-args (("-u" "%u") ("-s"))) | 300 | (tramp-login-args (("-u" "%u") ("-s"))) |
| 301 | (tramp-remote-shell "/bin/sh") | 301 | (tramp-remote-shell "/bin/sh") |
| 302 | (tramp-remote-shell-args ("-c")) | 302 | (tramp-remote-shell-args ("-c")) |
| 303 | (tramp-connection-timeout 10))) | 303 | (tramp-connection-timeout 10) |
| 304 | (tramp-session-timeout 300))) | ||
| 304 | ;;;###tramp-autoload | 305 | ;;;###tramp-autoload |
| 305 | (add-to-list 'tramp-methods | 306 | (add-to-list 'tramp-methods |
| 306 | '("ksu" | 307 | '("ksu" |
| @@ -4371,16 +4372,14 @@ Goes through the list `tramp-local-coding-commands' and | |||
| 4371 | vec 5 "Checking local encoding function `%s'" loc-enc) | 4372 | vec 5 "Checking local encoding function `%s'" loc-enc) |
| 4372 | (tramp-message | 4373 | (tramp-message |
| 4373 | vec 5 "Checking local encoding command `%s' for sanity" loc-enc) | 4374 | vec 5 "Checking local encoding command `%s' for sanity" loc-enc) |
| 4374 | (unless (zerop (tramp-call-local-coding-command | 4375 | (unless (zerop (tramp-call-local-coding-command loc-enc nil nil)) |
| 4375 | loc-enc nil nil)) | ||
| 4376 | (throw 'wont-work-local nil))) | 4376 | (throw 'wont-work-local nil))) |
| 4377 | (if (not (stringp loc-dec)) | 4377 | (if (not (stringp loc-dec)) |
| 4378 | (tramp-message | 4378 | (tramp-message |
| 4379 | vec 5 "Checking local decoding function `%s'" loc-dec) | 4379 | vec 5 "Checking local decoding function `%s'" loc-dec) |
| 4380 | (tramp-message | 4380 | (tramp-message |
| 4381 | vec 5 "Checking local decoding command `%s' for sanity" loc-dec) | 4381 | vec 5 "Checking local decoding command `%s' for sanity" loc-dec) |
| 4382 | (unless (zerop (tramp-call-local-coding-command | 4382 | (unless (zerop (tramp-call-local-coding-command loc-dec nil nil)) |
| 4383 | loc-dec nil nil)) | ||
| 4384 | (throw 'wont-work-local nil))) | 4383 | (throw 'wont-work-local nil))) |
| 4385 | ;; Search for remote coding commands with the same format | 4384 | ;; Search for remote coding commands with the same format |
| 4386 | (while (and remote-commands (not found)) | 4385 | (while (and remote-commands (not found)) |
| @@ -4702,6 +4701,19 @@ Goes through the list `tramp-inline-compress-commands'." | |||
| 4702 | " -o ControlPersist=no"))))))))) | 4701 | " -o ControlPersist=no"))))))))) |
| 4703 | tramp-ssh-controlmaster-options))) | 4702 | tramp-ssh-controlmaster-options))) |
| 4704 | 4703 | ||
| 4704 | (defun tramp-timeout-session (vec) | ||
| 4705 | "Close the connection VEC after a session timeout. | ||
| 4706 | If there is just some editing, retry it after 5 seconds." | ||
| 4707 | (if (and tramp-locked tramp-locker | ||
| 4708 | (tramp-equal-remote vec tramp-current-connection)) | ||
| 4709 | (progn | ||
| 4710 | (tramp-message | ||
| 4711 | vec 5 "Cannot timeout session, trying it again in %s seconds." 5) | ||
| 4712 | (run-at-time 5 nil 'tramp-timeout-session vec)) | ||
| 4713 | (tramp-message | ||
| 4714 | vec 3 "Timeout session %s" (tramp-make-tramp-file-name vec 'localname)) | ||
| 4715 | (tramp-cleanup-connection vec 'keep-debug))) | ||
| 4716 | |||
| 4705 | (defun tramp-maybe-open-connection (vec) | 4717 | (defun tramp-maybe-open-connection (vec) |
| 4706 | "Maybe open a connection VEC. | 4718 | "Maybe open a connection VEC. |
| 4707 | Does not do anything if a connection is already open, but re-opens the | 4719 | Does not do anything if a connection is already open, but re-opens the |
| @@ -4878,6 +4890,14 @@ connection if a previous connection has died for some reason." | |||
| 4878 | :method l-method :user l-user :domain l-domain | 4890 | :method l-method :user l-user :domain l-domain |
| 4879 | :host l-host :port l-port)) | 4891 | :host l-host :port l-port)) |
| 4880 | 4892 | ||
| 4893 | ;; Set session timeout. | ||
| 4894 | (when (tramp-get-method-parameter | ||
| 4895 | hop 'tramp-session-timeout) | ||
| 4896 | (tramp-set-connection-property | ||
| 4897 | p "session-timeout" | ||
| 4898 | (tramp-get-method-parameter | ||
| 4899 | hop 'tramp-session-timeout))) | ||
| 4900 | |||
| 4881 | ;; Add login environment. | 4901 | ;; Add login environment. |
| 4882 | (when login-env | 4902 | (when login-env |
| 4883 | (setq | 4903 | (setq |
| @@ -4941,6 +4961,12 @@ connection if a previous connection has died for some reason." | |||
| 4941 | ;; Set connection-local variables. | 4961 | ;; Set connection-local variables. |
| 4942 | (tramp-set-connection-local-variables vec) | 4962 | (tramp-set-connection-local-variables vec) |
| 4943 | 4963 | ||
| 4964 | ;; Activate session timeout. | ||
| 4965 | (when (tramp-get-connection-property p "session-timeout" nil) | ||
| 4966 | (run-at-time | ||
| 4967 | (tramp-get-connection-property p "session-timeout" nil) nil | ||
| 4968 | 'tramp-timeout-session vec)) | ||
| 4969 | |||
| 4944 | ;; Make initial shell settings. | 4970 | ;; Make initial shell settings. |
| 4945 | (tramp-open-connection-setup-interactive-shell p vec) | 4971 | (tramp-open-connection-setup-interactive-shell p vec) |
| 4946 | 4972 | ||
diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el index f16bb67efb5..8362d787525 100644 --- a/lisp/net/tramp.el +++ b/lisp/net/tramp.el | |||
| @@ -248,6 +248,10 @@ pair of the form (KEY VALUE). The following KEYs are defined: | |||
| 248 | In general, the global default value shall be used, but for | 248 | In general, the global default value shall be used, but for |
| 249 | some methods, like \"su\" or \"sudo\", a shorter timeout | 249 | some methods, like \"su\" or \"sudo\", a shorter timeout |
| 250 | might be desirable. | 250 | might be desirable. |
| 251 | * `tramp-session-timeout' | ||
| 252 | How long a Tramp connection keeps open before being disconnected. | ||
| 253 | This is useful for methods like \"su\" or \"sudo\", which | ||
| 254 | shouldn't run an open connection in the background forever. | ||
| 251 | * `tramp-case-insensitive' | 255 | * `tramp-case-insensitive' |
| 252 | Whether the remote file system handles file names case insensitive. | 256 | Whether the remote file system handles file names case insensitive. |
| 253 | Only a non-nil value counts, the default value nil means to | 257 | Only a non-nil value counts, the default value nil means to |
| @@ -4074,10 +4078,16 @@ Example: | |||
| 4074 | 4078 | ||
| 4075 | would yield t. On the other hand, the following check results in nil: | 4079 | would yield t. On the other hand, the following check results in nil: |
| 4076 | 4080 | ||
| 4077 | (tramp-equal-remote \"/sudo::/etc\" \"/su::/etc\")" | 4081 | (tramp-equal-remote \"/sudo::/etc\" \"/su::/etc\") |
| 4078 | (and (tramp-tramp-file-p file1) | 4082 | |
| 4079 | (tramp-tramp-file-p file2) | 4083 | FILE1 and FILE2 could also be Tramp vectors." |
| 4080 | (string-equal (file-remote-p file1) (file-remote-p file2)))) | 4084 | (or (and (tramp-tramp-file-p file1) |
| 4085 | (tramp-tramp-file-p file2) | ||
| 4086 | (string-equal (file-remote-p file1) (file-remote-p file2))) | ||
| 4087 | (and (tramp-file-name-p file1) | ||
| 4088 | (tramp-file-name-p file2) | ||
| 4089 | (string-equal (tramp-make-tramp-file-name file1 'localname) | ||
| 4090 | (tramp-make-tramp-file-name file2 'localname))))) | ||
| 4081 | 4091 | ||
| 4082 | ;;;###tramp-autoload | 4092 | ;;;###tramp-autoload |
| 4083 | (defun tramp-mode-string-to-int (mode-string) | 4093 | (defun tramp-mode-string-to-int (mode-string) |