aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Albinus2007-10-06 12:00:42 +0000
committerMichael Albinus2007-10-06 12:00:42 +0000
commita6e9632782dec4435e8b85a7a262443d62d6e2cc (patch)
treeed386f69c94b0e885ab8dec791e66b0af60ffa17
parentea3fc256d40808e58100459220a19fc26709c207 (diff)
downloademacs-a6e9632782dec4435e8b85a7a262443d62d6e2cc.tar.gz
emacs-a6e9632782dec4435e8b85a7a262443d62d6e2cc.zip
* net/tramp.el (top): Move loading of tramp-util.el and
tramp-vc.el to tramp-compat.el. (tramp-make-tramp-temp-file): Complete rewrite. Create remote temporary file if possible, in order to avoid a security hole. (tramp-do-copy-or-rename-file-out-of-band) (tramp-maybe-open-connection): Call `tramp-make-tramp-temp-file' with DONT-CREATE, because the connection is not setup yet. (tramp-handle-process-file): Rewrite temporary file handling. (tramp-completion-mode): New defvar. (tramp-completion-mode-p): Use it. * net/tramp-compat.el (top): Load tramp-util.el and tramp-vc.el. * net/tramp-fish.el (tramp-fish-handle-process-file): Rewrite temporary file handling.
-rw-r--r--lisp/ChangeLog18
-rw-r--r--lisp/net/tramp-compat.el26
-rw-r--r--lisp/net/tramp-fish.el37
-rw-r--r--lisp/net/tramp.el122
4 files changed, 129 insertions, 74 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 9a6b052042f..21df22350de 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,21 @@
12007-10-06 Michael Albinus <michael.albinus@gmx.de>
2
3 * net/tramp.el (top): Move loading of tramp-util.el and
4 tramp-vc.el to tramp-compat.el.
5 (tramp-make-tramp-temp-file): Complete rewrite. Create remote
6 temporary file if possible, in order to avoid a security hole.
7 (tramp-do-copy-or-rename-file-out-of-band)
8 (tramp-maybe-open-connection): Call `tramp-make-tramp-temp-file'
9 with DONT-CREATE, because the connection is not setup yet.
10 (tramp-handle-process-file): Rewrite temporary file handling.
11 (tramp-completion-mode): New defvar.
12 (tramp-completion-mode-p): Use it.
13
14 * net/tramp-compat.el (top): Load tramp-util.el and tramp-vc.el.
15
16 * net/tramp-fish.el (tramp-fish-handle-process-file): Rewrite
17 temporary file handling.
18
12007-10-06 Eric S. Raymond <esr@snark.thyrsus.com> 192007-10-06 Eric S. Raymond <esr@snark.thyrsus.com>
2 20
3 * vc.el: workfile version -> focus version change. Port various 21 * vc.el: workfile version -> focus version change. Port various
diff --git a/lisp/net/tramp-compat.el b/lisp/net/tramp-compat.el
index 9808888399f..19d25f43515 100644
--- a/lisp/net/tramp-compat.el
+++ b/lisp/net/tramp-compat.el
@@ -40,6 +40,32 @@
40 (require 'timer-funcs) 40 (require 'timer-funcs)
41 (require 'timer)) 41 (require 'timer))
42 42
43 ;; tramp-util offers integration into other (X)Emacs packages like
44 ;; compile.el, gud.el etc. Not necessary in Emacs 23.
45 (eval-after-load "tramp"
46 ;; We check whether `start-file-process' is an alias.
47 '(when (or (not (fboundp 'start-file-process))
48 (symbolp (symbol-function 'start-file-process)))
49 (require 'tramp-util)
50 (add-hook 'tramp-unload-hook
51 '(lambda ()
52 (when (featurep 'tramp-util)
53 (unload-feature 'tramp-util 'force))))))
54
55 ;; Make sure that we get integration with the VC package. When it
56 ;; is loaded, we need to pull in the integration module. Not
57 ;; necessary in Emacs 23.
58 (eval-after-load "vc"
59 (eval-after-load "tramp"
60 ;; We check whether `start-file-process' is an alias.
61 '(when (or (not (fboundp 'start-file-process))
62 (symbolp (symbol-function 'start-file-process)))
63 (require 'tramp-vc)
64 (add-hook 'tramp-unload-hook
65 '(lambda ()
66 (when (featurep 'tramp-vc)
67 (unload-feature 'tramp-vc 'force)))))))
68
43 ;; Avoid byte-compiler warnings if the byte-compiler supports this. 69 ;; Avoid byte-compiler warnings if the byte-compiler supports this.
44 ;; Currently, XEmacs supports this. 70 ;; Currently, XEmacs supports this.
45 (when (featurep 'xemacs) 71 (when (featurep 'xemacs)
diff --git a/lisp/net/tramp-fish.el b/lisp/net/tramp-fish.el
index 055d6c9f5e2..7116d144061 100644
--- a/lisp/net/tramp-fish.el
+++ b/lisp/net/tramp-fish.el
@@ -734,8 +734,8 @@ target of the symlink differ."
734 (error "Implementation does not handle immediate return")) 734 (error "Implementation does not handle immediate return"))
735 735
736 (with-parsed-tramp-file-name default-directory nil 736 (with-parsed-tramp-file-name default-directory nil
737 (let ((temp-name-prefix (tramp-make-tramp-temp-file v)) 737 (let (command input tmpinput output tmpoutput stderr tmpstderr
738 command input output stderr outbuf tmpfile ret) 738 outbuf tmpfile ret)
739 ;; Compute command. 739 ;; Compute command.
740 (setq command (mapconcat 'tramp-shell-quote-argument 740 (setq command (mapconcat 'tramp-shell-quote-argument
741 (cons program args) " ")) 741 (cons program args) " "))
@@ -747,15 +747,14 @@ target of the symlink differ."
747 ;; INFILE is on the same remote host. 747 ;; INFILE is on the same remote host.
748 (setq input (with-parsed-tramp-file-name infile nil localname)) 748 (setq input (with-parsed-tramp-file-name infile nil localname))
749 ;; INFILE must be copied to remote host. 749 ;; INFILE must be copied to remote host.
750 (setq input (concat temp-name-prefix ".in")) 750 (setq input (tramp-make-tramp-temp-file v)
751 (copy-file 751 tmpinput (tramp-make-tramp-file-name method user host input))
752 infile 752 (copy-file infile tmpinput t)))
753 (tramp-make-tramp-file-name method user host input)
754 t)))
755 (when input (setq command (format "%s <%s" command input))) 753 (when input (setq command (format "%s <%s" command input)))
756 754
757 ;; Determine output. 755 ;; Determine output.
758 (setq output (concat temp-name-prefix ".out")) 756 (setq output (tramp-make-tramp-temp-file v)
757 tmpoutput (tramp-make-tramp-file-name method user host output))
759 (cond 758 (cond
760 ;; Just a buffer 759 ;; Just a buffer
761 ((bufferp destination) 760 ((bufferp destination)
@@ -781,7 +780,9 @@ target of the symlink differ."
781 (cadr destination) nil localname)) 780 (cadr destination) nil localname))
782 ;; stderr must be copied to remote host. The temporary 781 ;; stderr must be copied to remote host. The temporary
783 ;; file must be deleted after execution. 782 ;; file must be deleted after execution.
784 (setq stderr (concat temp-name-prefix ".err")))) 783 (setq stderr (tramp-make-tramp-temp-file v)
784 tmpstderr (tramp-make-tramp-file-name
785 method user host stderr))))
785 ;; stderr to be discarded 786 ;; stderr to be discarded
786 ((null (cadr destination)) 787 ((null (cadr destination))
787 (setq stderr "/dev/null")))) 788 (setq stderr "/dev/null"))))
@@ -790,9 +791,6 @@ target of the symlink differ."
790 (setq outbuf (current-buffer)))) 791 (setq outbuf (current-buffer))))
791 (when stderr (setq command (format "%s 2>%s" command stderr))) 792 (when stderr (setq command (format "%s 2>%s" command stderr)))
792 793
793 ;; If we have a temporary file, it must be removed after operation.
794 (when (and input (string-match temp-name-prefix input))
795 (setq command (format "%s; rm %s" command input)))
796 ;; Goto working directory. 794 ;; Goto working directory.
797 (unless 795 (unless
798 (tramp-fish-send-command-and-check 796 (tramp-fish-send-command-and-check
@@ -821,16 +819,15 @@ target of the symlink differ."
821 ;; We should show the output anyway. 819 ;; We should show the output anyway.
822 (when outbuf 820 (when outbuf
823 (with-current-buffer outbuf (insert-file-contents tmpfile)) 821 (with-current-buffer outbuf (insert-file-contents tmpfile))
824 (when display (display-buffer outbuf))) 822 (when display (display-buffer outbuf))))
825 ;; Remove output file.
826 (delete-file (tramp-make-tramp-file-name method user host output)))
827 ;; When the user did interrupt, we should do it also. 823 ;; When the user did interrupt, we should do it also.
828 (error (setq ret 1))) 824 (error (setq ret 1)))
829 (unless ret 825
830 ;; Provide error file. 826 ;; Provide error file.
831 (when (and stderr (string-match temp-name-prefix stderr)) 827 (when tmpstderr (rename-file tmpstderr (cadr destination) t))
832 (rename-file (tramp-make-tramp-file-name method user host stderr) 828 ;; Cleanup.
833 (cadr destination) t))) 829 (when tmpinput (delete-file tmpinput))
830 (when tmpoutput (delete-file tmpoutput))
834 ;; Return exit status. 831 ;; Return exit status.
835 ret))) 832 ret)))
836 833
diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el
index b9689eba201..9a20e9a81c6 100644
--- a/lisp/net/tramp.el
+++ b/lisp/net/tramp.el
@@ -149,16 +149,7 @@
149 (add-hook 'tramp-unload-hook 149 (add-hook 'tramp-unload-hook
150 '(lambda () 150 '(lambda ()
151 (when (featurep 'tramp-gw) 151 (when (featurep 'tramp-gw)
152 (unload-feature 'tramp-gw 'force))))) 152 (unload-feature 'tramp-gw 'force)))))))
153
154 ;; tramp-util offers integration into other (X)Emacs packages like
155 ;; compile.el, gud.el etc. Not necessary in Emacs 23.
156 (unless (functionp 'start-file-process)
157 (require 'tramp-util)
158 (add-hook 'tramp-unload-hook
159 '(lambda ()
160 (when (featurep 'tramp-util)
161 (unload-feature 'tramp-util 'force)))))))
162 153
163;;; User Customizable Internal Variables: 154;;; User Customizable Internal Variables:
164 155
@@ -1974,13 +1965,42 @@ The intent is to protect against `obsolete variable' warnings."
1974(put 'tramp-let-maybe 'lisp-indent-function 2) 1965(put 'tramp-let-maybe 'lisp-indent-function 2)
1975(put 'tramp-let-maybe 'edebug-form-spec t) 1966(put 'tramp-let-maybe 'edebug-form-spec t)
1976 1967
1977(defsubst tramp-make-tramp-temp-file (vec) 1968(defsubst tramp-make-tramp-temp-file (vec &optional dont-create)
1978 (format 1969 "Create a temporary file on the remote host identified by VEC.
1979 "/tmp/%s%s" 1970Return the local name of the temporary file.
1980 tramp-temp-name-prefix 1971If DONT-CREATE is non-nil, just the file name is returned without
1981 (if (get-buffer-process (tramp-get-connection-buffer vec)) 1972creation of the temporary file. This is not the preferred way to run,
1982 (process-id (get-buffer-process (tramp-get-connection-buffer vec))) 1973but it is necessary during connection setup, because we cannot create
1983 (emacs-pid)))) 1974a remote file at this time. This parameter shall NOT be set to
1975non-nil else."
1976 (if dont-create
1977 ;; It sounds a little bit stupid to create a LOCAL file name.
1978 ;; But we intend to use the remote directory "/tmp", and we have
1979 ;; no chance to check whether a temporary file exists already
1980 ;; remotely, because we have no working connection yet.
1981 (make-temp-name (expand-file-name tramp-temp-name-prefix "/tmp"))
1982
1983 (let ((prefix
1984 (tramp-make-tramp-file-name
1985 (tramp-file-name-method vec)
1986 (tramp-file-name-user vec)
1987 (tramp-file-name-host vec)
1988 (expand-file-name tramp-temp-name-prefix "/tmp")))
1989 result)
1990 (while (not result)
1991 ;; `make-temp-file' would be the first choice for
1992 ;; implementation. But it calls `write-region' internally,
1993 ;; which also needs a temporary file - we would end in an
1994 ;; infinite loop.
1995 (setq result (make-temp-name prefix))
1996 (if (file-exists-p result)
1997 (setq result nil)
1998 ;; This creates the file by side effect.
1999 (set-file-times result)
2000 (set-file-modes result (tramp-octal-to-decimal "0700"))))
2001
2002 ;; Return the local part.
2003 (with-parsed-tramp-file-name result nil localname))))
1984 2004
1985 2005
1986;;; Config Manipulation Functions: 2006;;; Config Manipulation Functions:
@@ -3188,7 +3208,7 @@ be a local filename. The method used must be an out-of-band method."
3188 3208
3189 ;; Compose copy command. 3209 ;; Compose copy command.
3190 (setq spec `((?h . ,host) (?u . ,user) (?p . ,port) 3210 (setq spec `((?h . ,host) (?u . ,user) (?p . ,port)
3191 (?t . ,(tramp-make-tramp-temp-file v)) 3211 (?t . ,(tramp-make-tramp-temp-file v 'dont-create))
3192 (?k . ,(if keep-date " " ""))) 3212 (?k . ,(if keep-date " " "")))
3193 copy-program (tramp-get-method-parameter 3213 copy-program (tramp-get-method-parameter
3194 method 'tramp-copy-program) 3214 method 'tramp-copy-program)
@@ -3639,8 +3659,7 @@ beginning of local filename are not substituted."
3639 (error "Implementation does not handle immediate return")) 3659 (error "Implementation does not handle immediate return"))
3640 3660
3641 (with-parsed-tramp-file-name default-directory nil 3661 (with-parsed-tramp-file-name default-directory nil
3642 (let ((temp-name-prefix (tramp-make-tramp-temp-file v)) 3662 (let (command input tmpinput stderr tmpstderr outbuf ret)
3643 command input stderr outbuf ret)
3644 ;; Compute command. 3663 ;; Compute command.
3645 (setq command (mapconcat 'tramp-shell-quote-argument 3664 (setq command (mapconcat 'tramp-shell-quote-argument
3646 (cons program args) " ")) 3665 (cons program args) " "))
@@ -3652,11 +3671,9 @@ beginning of local filename are not substituted."
3652 ;; INFILE is on the same remote host. 3671 ;; INFILE is on the same remote host.
3653 (setq input (with-parsed-tramp-file-name infile nil localname)) 3672 (setq input (with-parsed-tramp-file-name infile nil localname))
3654 ;; INFILE must be copied to remote host. 3673 ;; INFILE must be copied to remote host.
3655 (setq input (concat temp-name-prefix ".in")) 3674 (setq input (tramp-make-tramp-temp-file v)
3656 (copy-file 3675 tmpinput (tramp-make-tramp-file-name method user host input))
3657 infile 3676 (copy-file infile tmpinput t)))
3658 (tramp-make-tramp-file-name method user host input)
3659 t)))
3660 (when input (setq command (format "%s <%s" command input))) 3677 (when input (setq command (format "%s <%s" command input)))
3661 3678
3662 ;; Determine output. 3679 ;; Determine output.
@@ -3685,7 +3702,9 @@ beginning of local filename are not substituted."
3685 (cadr destination) nil localname)) 3702 (cadr destination) nil localname))
3686 ;; stderr must be copied to remote host. The temporary 3703 ;; stderr must be copied to remote host. The temporary
3687 ;; file must be deleted after execution. 3704 ;; file must be deleted after execution.
3688 (setq stderr (concat temp-name-prefix ".err")))) 3705 (setq stderr (tramp-make-tramp-temp-file v)
3706 tmpstderr (tramp-make-tramp-file-name
3707 method user host stderr))))
3689 ;; stderr to be discarded 3708 ;; stderr to be discarded
3690 ((null (cadr destination)) 3709 ((null (cadr destination))
3691 (setq stderr "/dev/null")))) 3710 (setq stderr "/dev/null"))))
@@ -3694,9 +3713,6 @@ beginning of local filename are not substituted."
3694 (setq outbuf (current-buffer)))) 3713 (setq outbuf (current-buffer))))
3695 (when stderr (setq command (format "%s 2>%s" command stderr))) 3714 (when stderr (setq command (format "%s 2>%s" command stderr)))
3696 3715
3697 ;; If we have a temporary file, it must be removed after operation.
3698 (when (and input (string-match temp-name-prefix input))
3699 (setq command (format "%s; rm %s" command input)))
3700 ;; Goto working directory. 3716 ;; Goto working directory.
3701 (tramp-send-command 3717 (tramp-send-command
3702 v (format "cd %s" (tramp-shell-quote-argument localname))) 3718 v (format "cd %s" (tramp-shell-quote-argument localname)))
@@ -3716,13 +3732,13 @@ beginning of local filename are not substituted."
3716 (error 3732 (error
3717 (kill-buffer (tramp-get-connection-buffer v)) 3733 (kill-buffer (tramp-get-connection-buffer v))
3718 (setq ret 1))) 3734 (setq ret 1)))
3719 (unless ret 3735
3720 ;; Check return code. 3736 ;; Check return code.
3721 (setq ret (tramp-send-command-and-check v nil)) 3737 (unless ret (setq ret (tramp-send-command-and-check v nil)))
3722 ;; Provide error file. 3738 ;; Provide error file.
3723 (when (and stderr (string-match temp-name-prefix stderr)) 3739 (when tmpstderr (rename-file tmpstderr (cadr destination) t))
3724 (rename-file (tramp-make-tramp-file-name method user host stderr) 3740 ;; Cleanup.
3725 (cadr destination) t))) 3741 (when tmpinput (delete-file tmpinput))
3726 ;; Return exit status. 3742 ;; Return exit status.
3727 ret))) 3743 ret)))
3728 3744
@@ -4555,7 +4571,15 @@ Falls back to normal file name handler if no tramp file name handler exists."
4555 (add-hook 'tramp-unload-hook 4571 (add-hook 'tramp-unload-hook
4556 '(lambda () (ad-unadvise 'PC-expand-many-files))))) 4572 '(lambda () (ad-unadvise 'PC-expand-many-files)))))
4557 4573
4558;;; File name handler functions for completion mode 4574;;; File name handler functions for completion mode.
4575
4576(defvar tramp-completion-mode nil
4577 "If non-nil, external packages signal that they are in file name completion.
4578
4579This is necessary, because Tramp uses a heuristic depending on last
4580input event. This fails when external packages use other characters
4581but <TAB>, <SPACE> or ?\\? for file name completion. This variable
4582should never be set globally, the intention is to let-bind it.")
4559 4583
4560;; Necessary because `tramp-file-name-regexp-unified' and 4584;; Necessary because `tramp-file-name-regexp-unified' and
4561;; `tramp-completion-file-name-regexp-unified' aren't different. If 4585;; `tramp-completion-file-name-regexp-unified' aren't different. If
@@ -4571,23 +4595,25 @@ Falls back to normal file name handler if no tramp file name handler exists."
4571(defun tramp-completion-mode-p () 4595(defun tramp-completion-mode-p ()
4572 "Checks whether method / user name / host name completion is active." 4596 "Checks whether method / user name / host name completion is active."
4573 (or 4597 (or
4574 ;; Emacs 4598 ;; Signal from outside.
4599 tramp-completion-mode
4600 ;; Emacs.
4575 (equal last-input-event 'tab) 4601 (equal last-input-event 'tab)
4576 (and (natnump last-input-event) 4602 (and (natnump last-input-event)
4577 (or 4603 (or
4578 ;; ?\t has event-modifier 'control 4604 ;; ?\t has event-modifier 'control.
4579 (char-equal last-input-event ?\t) 4605 (char-equal last-input-event ?\t)
4580 (and (not (event-modifiers last-input-event)) 4606 (and (not (event-modifiers last-input-event))
4581 (or (char-equal last-input-event ?\?) 4607 (or (char-equal last-input-event ?\?)
4582 (char-equal last-input-event ?\ ))))) 4608 (char-equal last-input-event ?\ )))))
4583 ;; XEmacs 4609 ;; XEmacs.
4584 (and (featurep 'xemacs) 4610 (and (featurep 'xemacs)
4585 ;; `last-input-event' might be nil. 4611 ;; `last-input-event' might be nil.
4586 (not (null last-input-event)) 4612 (not (null last-input-event))
4587 ;; `last-input-event' may have no character approximation. 4613 ;; `last-input-event' may have no character approximation.
4588 (funcall (symbol-function 'event-to-character) last-input-event) 4614 (funcall (symbol-function 'event-to-character) last-input-event)
4589 (or 4615 (or
4590 ;; ?\t has event-modifier 'control 4616 ;; ?\t has event-modifier 'control.
4591 (char-equal 4617 (char-equal
4592 (funcall (symbol-function 'event-to-character) 4618 (funcall (symbol-function 'event-to-character)
4593 last-input-event) ?\t) 4619 last-input-event) ?\t)
@@ -6151,7 +6177,7 @@ connection if a previous connection has died for some reason."
6151 l-user (or l-user "") 6177 l-user (or l-user "")
6152 l-port (or l-port "") 6178 l-port (or l-port "")
6153 spec `((?h . ,l-host) (?u . ,l-user) (?p . ,l-port) 6179 spec `((?h . ,l-host) (?u . ,l-user) (?p . ,l-port)
6154 (?t . ,(tramp-make-tramp-temp-file vec))) 6180 (?t . ,(tramp-make-tramp-temp-file vec 'dont-create)))
6155 command 6181 command
6156 (concat 6182 (concat
6157 command " " 6183 command " "
@@ -7468,18 +7494,6 @@ please ensure that the buffers are attached to your email.\n\n")
7468 7494
7469(provide 'tramp) 7495(provide 'tramp)
7470 7496
7471;; Make sure that we get integration with the VC package.
7472;; When it is loaded, we need to pull in the integration module.
7473;; This must come after (provide 'tramp) because tramp-vc.el
7474;; requires tramp. Not necessary in Emacs 23.
7475(eval-after-load "vc"
7476 '(unless (functionp 'start-file-process)
7477 (require 'tramp-vc)
7478 (add-hook 'tramp-unload-hook
7479 '(lambda ()
7480 (when (featurep 'tramp-vc)
7481 (unload-feature 'tramp-vc 'force))))))
7482
7483;;; TODO: 7497;;; TODO:
7484 7498
7485;; * Allow putting passwords in the filename. 7499;; * Allow putting passwords in the filename.