X-Git-Url: http://git.hcoop.net/bpt/emacs.git/blobdiff_plain/565c0ca57e89ab1a1b4c378c615a998eb8fc0f99..06d8ace51597cd41e110560a56a1abeb6cce23d6:/lisp/net/netrc.el diff --git a/lisp/net/netrc.el b/lisp/net/netrc.el index 2644659e20..1b0d4df53c 100644 --- a/lisp/net/netrc.el +++ b/lisp/net/netrc.el @@ -1,6 +1,6 @@ ;;; netrc.el --- .netrc parsing functionality ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, -;; 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. +;; 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc. ;; Author: Lars Magne Ingebrigtsen ;; Keywords: news @@ -34,18 +34,6 @@ ;;; .netrc and .authinfo rc parsing ;;; -(defalias 'netrc-point-at-eol - (if (fboundp 'point-at-eol) - 'point-at-eol - 'line-end-position)) -(eval-when-compile - ;; This is unnecessary in the compiled version as it is a macro. - (if (fboundp 'bound-and-true-p) - (defalias 'netrc-bound-and-true-p 'bound-and-true-p) - (defmacro netrc-bound-and-true-p (var) - "Return the value of symbol VAR if it is bound, else nil." - `(and (boundp (quote ,var)) ,var)))) - (defgroup netrc nil "Netrc configuration." :group 'comm) @@ -58,12 +46,15 @@ (defvar netrc-services-file "/etc/services" "The name of the services file.") +(defvar netrc-cache nil) + (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) + ;; We got already parsed contents; just return it. file (when (file-exists-p file) (with-temp-buffer @@ -71,7 +62,16 @@ "password" "account" "macdef" "force" "port")) alist elem result pair) - (insert-file-contents file) + (if (and netrc-cache + (equal (car netrc-cache) (nth 5 (file-attributes file)))) + ;; Store the contents of the file heavily encrypted in memory. + (insert (base64-decode-string (rot13-string (cdr netrc-cache)))) + (insert-file-contents file) + (when (string-match "\\.gpg\\'" file) + (setq netrc-cache (cons (nth 5 (file-attributes file)) + (rot13-string + (base64-encode-string + (buffer-string))))))) (goto-char (point-min)) ;; Go through the file, line by line. (while (not (eobp)) @@ -131,19 +131,23 @@ Entries without port tokens default to DEFAULTPORT." ;; No machine name matches, so we look for default entries. (while rest (when (assoc "default" (car rest)) - (push (car rest) result)) + (let ((elem (car rest))) + (setq elem (delete (assoc "default" elem) elem)) + (push elem result))) (pop rest))) (when result (setq result (nreverse result)) - (while (and result - (not (netrc-port-equal - (or port defaultport "nntp") - ;; when port is not given in the netrc file, - ;; it should mean "any port" - (or (netrc-get (car result) "port") - defaultport port)))) - (pop result)) - (car result)))) + (if (not port) + (car result) + (while (and result + (not (netrc-port-equal + (or port defaultport "nntp") + ;; when port is not given in the netrc file, + ;; it should mean "any port" + (or (netrc-get (car result) "port") + defaultport port)))) + (pop result)) + (car result))))) (defun netrc-machine-user-or-password (mode authinfo-file-or-list machines ports defaults) "Get the user name or password according to MODE from AUTHINFO-FILE-OR-LIST. @@ -220,6 +224,17 @@ MODE can be \"login\" or \"password\", suitable for passing to (eq type (car (cddr service))))))) (cadr service))) +(defun netrc-store-data (file host port user password) + (with-temp-buffer + (when (file-exists-p file) + (insert-file-contents file)) + (goto-char (point-max)) + (unless (bolp) + (insert "\n")) + (insert (format "machine %s login %s password %s port %s\n" + host user password port)) + (write-region (point-min) (point-max) file nil 'silent))) + ;;;###autoload (defun netrc-credentials (machine &rest ports) "Return a user name/password pair. @@ -227,9 +242,11 @@ 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)))) + (if (not ports) + (setq found (netrc-machine list machine)) + (while (and ports + (not found)) + (setq found (netrc-machine list machine (pop ports))))) (when found (list (cdr (assoc "login" found)) (cdr (assoc "password" found))))))