annotate lisp/efs/efs-netrc.el @ 40:7e54bd776075 r19-15b103

Import from CVS: tag r19-15b103
author cvs
date Mon, 13 Aug 2007 08:54:25 +0200
parents 8fc7fe29b841
children 8b8b7f3559a2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1 ;; -*-Emacs-Lisp-*-
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3 ;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4 ;; File: efs-netrc.el
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5 ;; Release: $efs release: 1.15 $
40
7e54bd776075 Import from CVS: tag r19-15b103
cvs
parents: 22
diff changeset
6 ;; Version: $Revision: 1.2 $
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
7 ;; RCS:
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
8 ;; Description: Parses ~/.netrc file, and does completion in /.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
9 ;; Author: Sandy Rutherford <sandy@ibm550.sissa.it>
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
10 ;; Created: Fri Jan 28 19:32:47 1994 by sandy on ibm550
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
11 ;; Language: Emacs-Lisp
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
12 ;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
13 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
14
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
15 ;;; This file is part of efs. See efs.el for copyright
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
16 ;;; (it's copylefted) and warrranty (there isn't one) information.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
17
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
18 ;;;; ------------------------------------------------------------
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
19 ;;;; Provisions and requirements.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
20 ;;;; ------------------------------------------------------------
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
21
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
22 (provide 'efs-netrc)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
23 (require 'efs-cu)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
24 (require 'efs-ovwrt)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
25 (require 'passwd)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
26 (require 'efs-fnh)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
27
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
28 ;;;; ------------------------------------------------------------
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
29 ;;;; Internal Variables
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
30 ;;;; ------------------------------------------------------------
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
31
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
32 (defconst efs-netrc-version
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
33 (concat (substring "$efs release: 1.15 $" 14 -2)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
34 "/"
40
7e54bd776075 Import from CVS: tag r19-15b103
cvs
parents: 22
diff changeset
35 (substring "$Revision: 1.2 $" 11 -2)))
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
36
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
37 ;; Make the byte compiler happy.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
38 (defvar dired-directory)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
39
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
40 ;;;; ------------------------------------------------------------
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
41 ;;;; Use configuration variables.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
42 ;;;; ------------------------------------------------------------
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
43
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
44 (defvar efs-netrc-filename "~/.netrc"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
45 "*File in .netrc format to search for passwords.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
46 If you encrypt this file, name it something other than ~/.netrc. Otherwise,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
47 ordinary FTP will bomb.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
48
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
49 If you have any cryption package running off of find-file-hooks
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
50 (such as crypt.el or crypt++.el), efs will use it to decrypt this file.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
51 Encrypting this file is a good idea!")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
52
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
53 (defvar efs-disable-netrc-security-check nil
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
54 "*If non-nil avoid checking permissions for `efs-netrc-filename'.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
55
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
56 ;;;; ------------------------------------------------------------
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
57 ;;;; Host / User / Account mapping support.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
58 ;;;; ------------------------------------------------------------
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
59
40
7e54bd776075 Import from CVS: tag r19-15b103
cvs
parents: 22
diff changeset
60 ;;;###autoload
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
61 (defun efs-set-passwd (host user passwd)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
62 "For a given HOST and USER, set or change the associated PASSWORD."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
63 (interactive (list (read-string "Host: ")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
64 (read-string "User: ")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
65 (read-passwd "Password: ")))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
66 (efs-set-host-user-property host user 'passwd
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
67 (and passwd (efs-code-string passwd))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
68
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
69 (defun efs-set-account (host user minidisk account)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
70 "Given HOST, USER, and MINIDISK, set or change the ACCOUNT password.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
71 The minidisk is only relevant for CMS. If minidisk is irrelevant,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
72 give the null string for it. In lisp programs, give the minidisk as nil."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
73 (interactive (efs-save-match-data
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
74 (let* ((path (or buffer-file-name
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
75 (and (eq major-mode 'dired-mode)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
76 dired-directory)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
77 (parsed (and path (efs-ftp-path path)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
78 (default-host (car parsed))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
79 (default-user (nth 1 parsed))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
80 (default-minidisk
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
81 (and parsed
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
82 (eq (efs-host-type default-host) 'cms)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
83 (string-match "^/[^/]+/" (nth 2 parsed))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
84 (substring (nth 2 parsed) 1
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
85 (1- (match-end 0)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
86 (host (read-string "Host: " default-host))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
87 (user (read-string "User: " default-user))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
88 (minidisk
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
89 (read-string
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
90 "Minidisk (enter null string if inapplicable): "
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
91 default-minidisk))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
92 (account (read-passwd "Account password: ")))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
93 (if (string-match "^ *$" minidisk)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
94 (setq minidisk nil))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
95 (list host user minidisk account))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
96 (and account (setq account (efs-code-string account)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
97 (if minidisk
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
98 (efs-put-hash-entry (concat (downcase host) "/" user "/" minidisk)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
99 account efs-minidisk-hashtable)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
100 (efs-set-host-user-property host user 'account account)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
101
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
102 ;;;; ------------------------------------------------------------
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
103 ;;;; Parsing the ~/.netrc.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
104 ;;;; ------------------------------------------------------------
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
105
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
106 (defconst efs-netrc-modtime nil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
107 ;; Last modified time of the netrc file from file-attributes.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
108
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
109 (defun efs-netrc-next-token ()
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
110 ;; Gets the next token plus it's value.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
111 ;; Returns \(token value-1 value-2 ...\)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
112 (skip-chars-forward " \t\n")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
113 (while (char-equal (following-char) ?#)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
114 (forward-line 1)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
115 (skip-chars-forward " \t\n"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
116 (let ((tok (and (not (eobp))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
117 (downcase (buffer-substring
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
118 (point)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
119 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
120 (skip-chars-forward "^ \n\t")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
121 (point)))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
122 (cond
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
123 ((null tok) nil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
124 ((string-equal tok "default")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
125 (list tok))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
126 ((member tok (list "machine" "login" "password" "account"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
127 (list tok (efs-netrc-read-token-value)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
128 ((string-equal tok "minidisk")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
129 (list tok (efs-netrc-read-token-value)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
130 (efs-netrc-read-token-value)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
131 ((string-equal tok "include")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
132 (let ((start (- (point) 7))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
133 (path (expand-file-name (efs-netrc-read-token-value))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
134 (delete-region start (point))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
135 (save-excursion (insert (efs-netrc-get-include path))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
136 (efs-netrc-next-token))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
137 ;; Deal with tokens that we skip
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
138 ((string-equal tok "macdef")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
139 (efs-save-match-data
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
140 (search-forward "\n\n" nil 'move))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
141 (if (eobp)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
142 nil
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
143 (efs-netrc-next-token)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
144 (t (error "efs netrc file error: Invalid token %s." tok)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
145
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
146 (defun efs-netrc-read-token-value ()
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
147 ;; Read the following word as a token value.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
148 (skip-chars-forward " \t\n")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
149 (while (char-equal (following-char) ?#)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
150 (forward-line 1)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
151 (skip-chars-forward " \t\n"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
152 (if (eq (following-char) ?\") ;quoted token value
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
153 (prog2
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
154 (forward-char 1)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
155 (buffer-substring (point)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
156 (progn (skip-chars-forward "^\"") (point)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
157 (forward-char 1))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
158 (buffer-substring (point)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
159 (progn (skip-chars-forward "^ \n\t") (point)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
160
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
161 (defun efs-netrc-get-include (path)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
162 ;; Returns the text of an include file.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
163 (let ((buff (create-file-buffer path)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
164 (unwind-protect
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
165 (save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
166 (set-buffer buff)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
167 (setq buffer-file-name path
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
168 default-directory (file-name-directory path))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
169 (insert-file-contents path)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
170 (normal-mode t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
171 (mapcar 'funcall find-file-hooks)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
172 (setq buffer-file-name nil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
173 (buffer-string))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
174 (condition-case nil
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
175 ;; go through this rigamoroll, because who knows
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
176 ;; where an interrupt in find-file-hooks leaves us.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
177 (save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
178 (set-buffer buff)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
179 (set-buffer-modified-p nil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
180 (passwd-kill-buffer buff))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
181 (error nil)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
182
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
183 (defun efs-parse-netrc-group (&optional machine)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
184 ;; Extract the values for the tokens "machine", "login", "password",
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
185 ;; "account" and "minidisk" in the current buffer. If successful,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
186 ;; record the information found.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
187 (let (data login)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
188 ;; Get a machine token.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
189 (if (or machine (setq data (efs-netrc-next-token)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
190 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
191 (cond
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
192 (machine) ; noop
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
193 ((string-equal (car data) "machine")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
194 (setq machine (nth 1 data)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
195 ((string-equal (car data) "default")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
196 (setq machine 'default))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
197 (error
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
198 "efs netrc file error: %s"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
199 "Token group must start with machine or default."))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
200 ;; Next look for a login token.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
201 (setq data (efs-netrc-next-token))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
202 (cond
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
203 ((null data)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
204 ;; This just interns in the hashtable for completion to
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
205 ;; work. The username gets set later by efs-get-user.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
206 (if (stringp machine) (efs-set-user machine nil))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
207 nil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
208 ((string-equal (car data) "machine")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
209 (if (stringp machine) (efs-set-user machine nil))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
210 (nth 1 data))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
211 ((string-equal (car data) "default")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
212 'default)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
213 ((not (string-equal (car data) "login"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
214 (error "efs netrc file error: Expected login token for %s."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
215 (if (eq machine 'default)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
216 "default"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
217 (format "machine %s" machine))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
218 (t
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
219 (setq login (nth 1 data))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
220 (if (eq machine 'default)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
221 (setq efs-default-user login)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
222 (efs-set-user machine login)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
223 ;; Since an explicit login entry is given, intern an entry
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
224 ;; in the efs-host-user-hashtable for completion purposes.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
225 (efs-set-host-user-property machine login nil nil))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
226 (while (and (setq data (efs-netrc-next-token))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
227 (not (or (string-equal (car data) "machine")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
228 (string-equal (car data) "default"))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
229 (cond
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
230 ((string-equal (car data) "password")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
231 (if (eq machine 'default)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
232 (setq efs-default-password (nth 1 data))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
233 (efs-set-passwd machine login (nth 1 data))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
234 ((string-equal (car data) "account")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
235 (if (eq machine 'default)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
236 (setq efs-default-account (nth 1 data))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
237 (efs-set-account machine login nil (nth 1 data))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
238 ((string-equal (car data) "minidisk")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
239 (if (eq machine 'default)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
240 (error "efs netrc file error: %s."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
241 "Minidisk token is not allowed for default entry.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
242 (apply 'efs-set-account machine login (cdr data))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
243 ((string-equal (car data) "login")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
244 (error "efs netrc file error: Second login token for %s."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
245 (if (eq machine 'default)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
246 "default"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
247 (format "machine %s" machine))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
248 (and data (if (string-equal (car data) "machine")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
249 (nth 1 data)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
250 'default))))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
251
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
252 (defun efs-parse-netrc ()
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
253 "Parse the users ~/.netrc file, or file specified `by efs-netrc-filename'.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
254 If the file exists and has the correct permissions then extract the
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
255 \`machine\', \`login\', \`password\', \`account\', and \`minidisk\'
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
256 information from within."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
257 (interactive)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
258 (and efs-netrc-filename
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
259 (let* ((file (expand-file-name efs-netrc-filename))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
260 ;; Set to nil to avoid an infinite recursion if the
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
261 ;; .netrc file is remote.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
262 (efs-netrc-filename nil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
263 (file (efs-chase-symlinks file))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
264 (attr (file-attributes file))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
265 netrc-buffer next)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
266 (if (or (interactive-p) ; If interactive, really do something.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
267 (and attr ; file exists.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
268 ;; file changed
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
269 (not (equal (nth 5 attr) efs-netrc-modtime))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
270 (efs-save-match-data
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
271 (or efs-disable-netrc-security-check
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
272 (and (eq (nth 2 attr) (user-uid)) ; Same uids.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
273 (string-match ".r..------" (nth 8 attr)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
274 (efs-netrc-scream-and-yell file attr))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
275 (unwind-protect
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
276 (save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
277 ;; we are cheating a bit here. I'm trying to do the
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
278 ;; equivalent of find-file on the .netrc file, but
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
279 ;; then nuke it afterwards.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
280 ;; with the bit of logic below we should be able to have
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
281 ;; encrypted .netrc files.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
282 (set-buffer (setq netrc-buffer
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
283 (generate-new-buffer "*ftp-.netrc*")))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
284 (insert-file-contents file)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
285 (setq buffer-file-name file)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
286 (setq default-directory (file-name-directory file))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
287 (normal-mode t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
288 (mapcar 'funcall find-file-hooks)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
289 (setq buffer-file-name nil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
290 (goto-char (point-min))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
291 (while (and (not (eobp))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
292 (setq next (efs-parse-netrc-group next)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
293 (condition-case nil
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
294 ;; go through this rigamoroll, because we knows
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
295 ;; where an interrupt in find-file-hooks leaves us.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
296 (save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
297 (set-buffer netrc-buffer)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
298 (set-buffer-modified-p nil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
299 (passwd-kill-buffer netrc-buffer))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
300 (error nil)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
301 (setq efs-netrc-modtime (nth 5 attr)))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
302
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
303 (defun efs-netrc-scream-and-yell (file attr)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
304 ;; Complain about badly protected netrc files.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
305 (let* ((bad-own (/= (nth 2 attr) (user-uid)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
306 (modes (nth 8 attr))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
307 (bad-protect (not (string-match ".r..------" modes))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
308 (if (or bad-own bad-protect)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
309 (save-window-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
310 (with-output-to-temp-buffer "*Help*"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
311 (if bad-own
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
312 (princ
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
313 (format
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
314 "Beware that your .netrc file %s is not owned by you.\n"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
315 file)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
316 (if bad-protect
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
317 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
318 (if bad-own
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
319 (princ "\nAlso,")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
320 (princ "Beware that"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
321 (princ
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
322 " your .netrc file ")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
323 (or bad-own (princ (concat file " ")))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
324 (princ
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
325 (format
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
326 "has permissions\n %s.\n" modes))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
327 (princ
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
328 "\nIf this is intentional, then setting \
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
329 efs-disable-netrc-security-check
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
330 to t will inhibit this warning in the future.\n"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
331 (select-window (get-buffer-window "*Help*"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
332 (enlarge-window (- (count-lines (point-min) (point-max))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
333 (window-height) -1))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
334 (if (and bad-protect
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
335 (y-or-n-p (format "Set permissions on %s to 600? " file)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
336 (set-file-modes file 384))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
337
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
338 ;;;; ----------------------------------------------------------------
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
339 ;;;; Completion in the root directory.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
340 ;;;; ----------------------------------------------------------------
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
341
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
342 (defun efs-generate-root-prefixes ()
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
343 "Return a list of prefixes of the form \"user@host:\".
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
344 Used when completion is done in the root directory."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
345 (efs-parse-netrc)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
346 (efs-save-match-data
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
347 (let (res)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
348 (efs-map-hashtable
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
349 (function
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
350 (lambda (key value)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
351 (if (string-match "^[^/]+\\(/\\).+$" key)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
352 ;; efs-passwd-hashtable may have entries of the type
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
353 ;; "machine/" to indicate a password assigned to the default
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
354 ;; user for "machine". Don't use these entries for completion.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
355 (let ((host (substring key 0 (match-beginning 1)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
356 (user (substring key (match-end 1))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
357 (setq res (cons (list (format
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
358 efs-path-user-at-host-format
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
359 user host))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
360 res))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
361 efs-host-user-hashtable)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
362 (efs-map-hashtable
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
363 (function (lambda (host user)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
364 (setq res (cons (list (format efs-path-host-format
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
365 host))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
366 res))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
367 efs-host-hashtable)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
368 (if (and (null res)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
369 (string-match "^1[0-8]\\.\\|^[0-9]\\." emacs-version))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
370 (list nil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
371 res))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
372
40
7e54bd776075 Import from CVS: tag r19-15b103
cvs
parents: 22
diff changeset
373 ;;;###autoload
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
374 (defun efs-root-file-name-all-completions (file dir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
375 ;; Generates all completions in the root directory.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
376 (let ((file-name-handler-alist (efs-file-name-handler-alist-sans-fn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
377 'efs-root-handler-function)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
378 (nconc (all-completions file (efs-generate-root-prefixes))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
379 (file-name-all-completions file dir))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
380
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
381
40
7e54bd776075 Import from CVS: tag r19-15b103
cvs
parents: 22
diff changeset
382 ;;;###autoload
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
383 (defun efs-root-file-name-completion (file dir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
384 ;; Calculates completions in the root directory to include remote hosts.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
385 (let ((file-name-handler-alist (efs-file-name-handler-alist-sans-fn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
386 'efs-root-handler-function)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
387 (try-completion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
388 file
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
389 (nconc (efs-generate-root-prefixes)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
390 (mapcar 'list (file-name-all-completions file "/"))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
391
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
392
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
393 ;;; end of efs-netrc.el