Mercurial > emacs
comparison lisp/net/tramp.el @ 95025:bdaea36b81dd
* net/tramp.el: Load auth-source library.
(tramp-read-passwd): Use it for password, not login.
(tramp-file-name-for-operation): Add `make-temp-name'.
author | Michael Albinus <michael.albinus@gmx.de> |
---|---|
date | Thu, 15 May 2008 21:06:00 +0000 |
parents | 5bb8f7b3f835 |
children | adc57176d5f1 |
comparison
equal
deleted
inserted
replaced
95024:7573004f2849 | 95025:bdaea36b81dd |
---|---|
84 (or (require 'password-cache nil 'noerror) | 84 (or (require 'password-cache nil 'noerror) |
85 (require 'password nil 'noerror))) ; from No Gnus, also in tar ball | 85 (require 'password nil 'noerror))) ; from No Gnus, also in tar ball |
86 | 86 |
87 (require 'shell) | 87 (require 'shell) |
88 (require 'advice) | 88 (require 'advice) |
89 | |
90 (if (featurep 'xemacs) | |
91 (load "auth-source" 'noerror) | |
92 (require 'auth-source nil 'noerror)) | |
89 | 93 |
90 ;; Requiring 'tramp-cache results in an endless loop. | 94 ;; Requiring 'tramp-cache results in an endless loop. |
91 (autoload 'tramp-get-file-property "tramp-cache") | 95 (autoload 'tramp-get-file-property "tramp-cache") |
92 (autoload 'tramp-set-file-property "tramp-cache") | 96 (autoload 'tramp-set-file-property "tramp-cache") |
93 (autoload 'tramp-flush-file-property "tramp-cache") | 97 (autoload 'tramp-flush-file-property "tramp-cache") |
4423 ; XEmacs only | 4427 ; XEmacs only |
4424 'abbreviate-file-name 'create-file-buffer | 4428 'abbreviate-file-name 'create-file-buffer |
4425 'dired-file-modtime 'dired-make-compressed-filename | 4429 'dired-file-modtime 'dired-make-compressed-filename |
4426 'dired-recursive-delete-directory 'dired-set-file-modtime | 4430 'dired-recursive-delete-directory 'dired-set-file-modtime |
4427 'dired-shell-unhandle-file-name 'dired-uucode-file | 4431 'dired-shell-unhandle-file-name 'dired-uucode-file |
4428 'insert-file-contents-literally 'recover-file | 4432 'insert-file-contents-literally 'make-temp-name 'recover-file |
4429 'vm-imap-check-mail 'vm-pop-check-mail 'vm-spool-check-mail)) | 4433 'vm-imap-check-mail 'vm-pop-check-mail 'vm-spool-check-mail)) |
4430 (if (file-name-absolute-p (nth 0 args)) | 4434 (if (file-name-absolute-p (nth 0 args)) |
4431 (nth 0 args) | 4435 (nth 0 args) |
4432 (expand-file-name (nth 0 args)))) | 4436 (expand-file-name (nth 0 args)))) |
4433 ; FILE DIRECTORY resp FILE1 FILE2 | 4437 ; FILE DIRECTORY resp FILE1 FILE2 |
7198 ;; -- Compatibility functions section -- | 7202 ;; -- Compatibility functions section -- |
7199 ;; ------------------------------------------------------------ | 7203 ;; ------------------------------------------------------------ |
7200 | 7204 |
7201 (defun tramp-read-passwd (proc &optional prompt) | 7205 (defun tramp-read-passwd (proc &optional prompt) |
7202 "Read a password from user (compat function). | 7206 "Read a password from user (compat function). |
7207 Consults the auth-source package. | |
7203 Invokes `password-read' if available, `read-passwd' else." | 7208 Invokes `password-read' if available, `read-passwd' else." |
7204 (let* ((key (tramp-make-tramp-file-name | 7209 (let* ((key (tramp-make-tramp-file-name |
7205 tramp-current-method tramp-current-user | 7210 tramp-current-method tramp-current-user |
7206 tramp-current-host "")) | 7211 tramp-current-host "")) |
7207 (pw-prompt | 7212 (pw-prompt |
7208 (or prompt | 7213 (or prompt |
7209 (with-current-buffer (process-buffer proc) | 7214 (with-current-buffer (process-buffer proc) |
7210 (tramp-check-for-regexp proc tramp-password-prompt-regexp) | 7215 (tramp-check-for-regexp proc tramp-password-prompt-regexp) |
7211 (format "%s for %s " (capitalize (match-string 1)) key))))) | 7216 (format "%s for %s " (capitalize (match-string 1)) key))))) |
7212 (if (functionp 'password-read) | 7217 |
7213 (let ((password (funcall (symbol-function 'password-read) | 7218 (or |
7214 pw-prompt key))) | 7219 ;; see if auth-sources contains something useful, if it's bound |
7215 (funcall (symbol-function 'password-cache-add) key password) | 7220 (when (boundp 'auth-sources) |
7216 password) | 7221 (or |
7217 (read-passwd pw-prompt)))) | 7222 ;; 1. try with Tramp's current method |
7223 (auth-source-user-or-password | |
7224 "password" tramp-current-host tramp-current-method) | |
7225 ;; 2. hard-code the method to be "tramp" | |
7226 (auth-source-user-or-password | |
7227 "password" tramp-current-host "tramp"))) | |
7228 ;; 3. else, get the password interactively | |
7229 (if (functionp 'password-read) | |
7230 (let ((password (funcall (symbol-function 'password-read) | |
7231 pw-prompt key))) | |
7232 (funcall (symbol-function 'password-cache-add) key password) | |
7233 password) | |
7234 (read-passwd pw-prompt))))) | |
7218 | 7235 |
7219 (defun tramp-clear-passwd (vec) | 7236 (defun tramp-clear-passwd (vec) |
7220 "Clear password cache for connection related to VEC." | 7237 "Clear password cache for connection related to VEC." |
7221 (when (functionp 'password-cache-remove) | 7238 (when (functionp 'password-cache-remove) |
7222 (funcall | 7239 (funcall |