Added docs.
authorTeodor Zlatanov <tzz@lifelogs.com>
Wed, 9 Apr 2008 20:16:17 +0000 (20:16 +0000)
committerTeodor Zlatanov <tzz@lifelogs.com>
Wed, 9 Apr 2008 20:16:17 +0000 (20:16 +0000)
(auth-sources): Modified format to support server.
(auth-source-pick, auth-source-user-or-password)
(auth-source-user-or-password-imap)
(auth-source-user-or-password-pop3, auth-source-user-or-password-ssh)
(auth-source-user-or-password-sftp)
(auth-source-user-or-password-smtp): Add server parameter.

lisp/ChangeLog
lisp/auth-source.el

index 4dc27a6..dbb787e 100644 (file)
@@ -1,3 +1,13 @@
+2008-04-09  Teodor Zlatanov  <tzz@lifelogs.com>
+
+       * auth-source.el: Added docs.
+       (auth-sources): Modified format to support server.
+       (auth-source-pick, auth-source-user-or-password)
+       (auth-source-user-or-password-imap)
+       (auth-source-user-or-password-pop3, auth-source-user-or-password-ssh)
+       (auth-source-user-or-password-sftp)
+       (auth-source-user-or-password-smtp): Add server parameter.
+
 2008-04-08  Teodor Zlatanov  <tzz@lifelogs.com>
 
        * gnus-registry.el: Initialize the registry when gnus-registry-install
index f37e036..9883eb6 100644 (file)
 ;; authenticate in a single place.  Simplicity is the goal.  Instead
 ;; of providing 5000 options, we'll stick to simple, easy to
 ;; understand options.
+
+;; Easy setup:
+;; (require 'auth-source)
+;; (customize-variable 'auth-sources) ;; optional
+
+;; now, whatever sources you've defined for password have to be available
+
+;; if you want encrypted sources, which is strongly recommended, do
+;; (require 'epa-file)
+;; (epa-file-mode)
+
+;; before you put some data in ~/.authinfo.gpg (the default place)
+
 ;;; Code:
 
 (eval-when-compile (require 'cl))
@@ -73,10 +86,15 @@ Each entry is the authentication type with optional properties."
                 (list :tag "Source definition"
                       (const :format "" :value :source)
                       (string :tag "Authentication Source")
+                      (const :format "" :value :server)
+                      (choice :tag "Server (logical name) choice"
+                              (const :tag "Any" t)
+                              (regexp :tag "Server regular expression (TODO)")
+                              (const :tag "Fallback" nil))
                       (const :format "" :value :host)
-                      (choice :tag "Host choice"
+                      (choice :tag "Host (machine) choice"
                               (const :tag "Any" t)
-                              (regexp :tag "Host regular expression (TODO)")
+                              (regexp :tag "Host (machine) regular expression (TODO)")
                               (const :tag "Fallback" nil))
                       (const :format "" :value :protocol)
                       (choice :tag "Protocol"
@@ -100,16 +118,20 @@ Each entry is the authentication type with optional properties."
 ;; (auth-source-user-or-password-imap "password" "imap.myhost.com")
 ;; (auth-source-protocol-defaults 'imap)
 
-(defun auth-source-pick (host protocol &optional fallback)
-  "Parse `auth-sources' for HOST and PROTOCOL matches.
+(defun auth-source-pick (server host protocol &optional fallback)
+  "Parse `auth-sources' for SERVER, HOST, and PROTOCOL matches.
 
-Returns fallback choices (where PROTOCOL or HOST are nil) with FALLBACK t."
+Returns fallback choices (where SERVER. PROTOCOL or HOST are nil) with FALLBACK t."
   (interactive "sHost: \nsProtocol: \n") ;for testing
   (let (choices)
     (dolist (choice auth-sources)
-      (let ((h (plist-get choice :host))
+      (let ((s (plist-get choice :server))
+           (h (plist-get choice :host))
            (p (plist-get choice :protocol)))
        (when (and
+              (or (equal t s)
+                  (and (stringp s) (string-match s server))
+                  (and fallback (equal s nil)))
               (or (equal t h)
                   (and (stringp h) (string-match h host))
                   (and fallback (equal h nil)))
@@ -120,12 +142,12 @@ Returns fallback choices (where PROTOCOL or HOST are nil) with FALLBACK t."
     (if choices
        choices
       (unless fallback
-       (auth-source-pick host protocol t)))))
+       (auth-source-pick server host protocol t)))))
 
-(defun auth-source-user-or-password (mode host protocol)
-  "Find user or password (from the string MODE) matching HOST and PROTOCOL."
+(defun auth-source-user-or-password (mode server host protocol)
+  "Find user or password (from the string MODE) matching SERVER, HOST, and PROTOCOL."
   (let (found)
-    (dolist (choice (auth-source-pick host protocol))
+    (dolist (choice (auth-source-pick server host protocol))
       (setq found (netrc-machine-user-or-password 
                   mode
                   (plist-get choice :source)
@@ -139,20 +161,20 @@ Returns fallback choices (where PROTOCOL or HOST are nil) with FALLBACK t."
   "Return a list of default ports and names for PROTOCOL."
   (cdr-safe (assoc protocol auth-source-protocols)))
 
-(defun auth-source-user-or-password-imap (mode host)
-  (auth-source-user-or-password mode host 'imap))
+(defun auth-source-user-or-password-imap (mode server host)
+  (auth-source-user-or-password mode server host 'imap))
 
-(defun auth-source-user-or-password-pop3 (mode host)
-  (auth-source-user-or-password mode host 'pop3))
+(defun auth-source-user-or-password-pop3 (mode server host)
+  (auth-source-user-or-password mode server host 'pop3))
 
-(defun auth-source-user-or-password-ssh (mode host)
-  (auth-source-user-or-password mode host 'ssh))
+(defun auth-source-user-or-password-ssh (mode server host)
+  (auth-source-user-or-password mode server host 'ssh))
 
-(defun auth-source-user-or-password-sftp (mode host)
-  (auth-source-user-or-password mode host 'sftp))
+(defun auth-source-user-or-password-sftp (mode server host)
+  (auth-source-user-or-password mode server host 'sftp))
 
-(defun auth-source-user-or-password-smtp (mode host)
-  (auth-source-user-or-password mode host 'smtp))
+(defun auth-source-user-or-password-smtp (mode server host)
+  (auth-source-user-or-password mode server host 'smtp))
 
 (provide 'auth-source)