X-Git-Url: http://cgit.sxemacs.org/?p=gnus;a=blobdiff_plain;f=lisp%2Fnetrc.el;h=2644659e20dbd4cdf67cfe1178ab1c133cb44b23;hp=5252134367e8696a334883ace8bb4da89df8e2bb;hb=e6c27587ccdd3716cf586c4b318d9246fac6323b;hpb=c9a393eeb329a99695566342a9f03b8a30000898 diff --git a/lisp/netrc.el b/lisp/netrc.el index 525213436..2644659e2 100644 --- a/lisp/netrc.el +++ b/lisp/netrc.el @@ -34,14 +34,10 @@ ;;; .netrc and .authinfo rc parsing ;;; -;; use encrypt if loaded (encrypt-file-alist has to be set as well) -(autoload 'encrypt-find-model "encrypt") -(autoload 'encrypt-insert-file-contents "encrypt") (defalias 'netrc-point-at-eol (if (fboundp 'point-at-eol) 'point-at-eol 'line-end-position)) -(defvar encrypt-file-alist) (eval-when-compile ;; This is unnecessary in the compiled version as it is a macro. (if (fboundp 'bound-and-true-p) @@ -54,12 +50,19 @@ "Netrc configuration." :group 'comm) +(defcustom netrc-file "~/.authinfo" + "File where user credentials are stored." + :type 'file + :group 'netrc) + (defvar netrc-services-file "/etc/services" "The name of the services file.") -(defun netrc-parse (file) +(defun netrc-parse (&optional file) (interactive "fFile to Parse: ") "Parse FILE and return a list of all entries in the file." + (unless file + (setq file netrc-file)) (if (listp file) file (when (file-exists-p file) @@ -67,12 +70,8 @@ (let ((tokens '("machine" "default" "login" "password" "account" "macdef" "force" "port")) - (encryption-model (when (netrc-bound-and-true-p encrypt-file-alist) - (encrypt-find-model file))) alist elem result pair) - (if encryption-model - (encrypt-insert-file-contents file encryption-model) - (insert-file-contents file)) + (insert-file-contents file) (goto-char (point-min)) ;; Go through the file, line by line. (while (not (eobp)) @@ -160,9 +159,9 @@ MODE can be \"login\" or \"password\", suitable for passing to (defaults (or defaults '(nil))) info) (if (listp mode) - (setq info - (mapcar - (lambda (mode-element) + (setq info + (mapcar + (lambda (mode-element) (netrc-machine-user-or-password mode-element authinfo-list @@ -221,6 +220,20 @@ MODE can be \"login\" or \"password\", suitable for passing to (eq type (car (cddr service))))))) (cadr service))) +;;;###autoload +(defun netrc-credentials (machine &rest ports) + "Return a user name/password pair. +Port specifications will be prioritised in the order they are +listed in the PORTS list." + (let ((list (netrc-parse)) + found) + (while (and ports + (not found)) + (setq found (netrc-machine list machine (pop ports)))) + (when found + (list (cdr (assoc "login" found)) + (cdr (assoc "password" found)))))) + (provide 'netrc) ;;; netrc.el ends here