Add hooks for gcc handling
[gnus] / lisp / auth-source.el
index a8e6750..3ddbb56 100644 (file)
@@ -1,6 +1,6 @@
 ;;; auth-source.el --- authentication sources for Gnus and Emacs
 
-;; Copyright (C) 2008-2011 Free Software Foundation, Inc.
+;; Copyright (C) 2008-2012 Free Software Foundation, Inc.
 
 ;; Author: Ted Zlatanov <tzz@lifelogs.com>
 ;; Keywords: news
@@ -94,6 +94,7 @@
   "How many seconds passwords are cached, or nil to disable
 expiring.  Overrides `password-cache-expiry' through a
 let-binding."
+  :version "24.1"
   :group 'auth-source
   :type '(choice (const :tag "Never" nil)
                  (const :tag "All Day" 86400)
@@ -1201,7 +1202,7 @@ See `auth-source-search' for details on SPEC."
              (default (cond
                        ((and (not given-default) (eq r 'user))
                         (user-login-name))
-                       (t (eval given-default))))
+                       (t given-default)))
              (printable-defaults (list
                                   (cons 'user
                                         (or
@@ -1235,50 +1236,46 @@ See `auth-source-search' for details on SPEC."
                         (?p ,(aget printable-defaults 'port))))))
 
         ;; Store the data, prompting for the password if needed.
-        (setq data
-              (cond
-               ((and (null data) (eq r 'secret))
-                (if default
-                    default
-                  ;; Special case prompt for passwords.
-                  ;; TODO: make the default (setq auth-source-netrc-use-gpg-tokens `((,(if (boundp 'epa-file-auto-mode-alist-entry) (car (symbol-value 'epa-file-auto-mode-alist-entry)) "\\.gpg\\'") nil) (t gpg)))
-                  ;; TODO: or maybe leave as (setq auth-source-netrc-use-gpg-tokens 'never)
-                  (let* ((ep (format "Use GPG password tokens in %s?" file))
-                         (gpg-encrypt
-                          (cond
-                           ((eq auth-source-netrc-use-gpg-tokens 'never)
-                          'never)
-                           ((listp auth-source-netrc-use-gpg-tokens)
-                            (let ((check (copy-sequence
-                                        auth-source-netrc-use-gpg-tokens))
-                                  item ret)
-                              (while check
-                              (setq item (pop check))
-                              (when (or (eq (car item) t)
-                                        (string-match (car item) file))
-                                (setq ret (cdr item))
-                                (setq check nil)))))
-                           (t 'never)))
-                         (plain (read-passwd prompt)))
-                    ;; ask if we don't know what to do (in which case
-                    ;; auth-source-netrc-use-gpg-tokens must be a list)
-                    (unless gpg-encrypt
-                      (setq gpg-encrypt (if (y-or-n-p ep) 'gpg 'never))
-                      ;; TODO: save the defcustom now? or ask?
-                      (setq auth-source-netrc-use-gpg-tokens
-                            (cons `(,file ,gpg-encrypt)
-                                  auth-source-netrc-use-gpg-tokens)))
-                    (if (eq gpg-encrypt 'gpg)
-                        (auth-source-epa-make-gpg-token plain file)
-                      plain))))
-               ((null data)
-                (when default
-                  (read-string (if (string-match ": *\\'" prompt)
-                                   (concat (substring prompt 0 (match-beginning 0))
-                                           " (default " default "): ")
-                                 (concat prompt "(default " default ") "))
-                               nil nil default)))
-               (t (or data default))))
+        (setq data (or data
+                       (if (eq r 'secret)
+                           ;; Special case prompt for passwords.
+                           ;; TODO: make the default (setq auth-source-netrc-use-gpg-tokens `((,(if (boundp 'epa-file-auto-mode-alist-entry) (car (symbol-value 'epa-file-auto-mode-alist-entry)) "\\.gpg\\'") nil) (t gpg)))
+                           ;; TODO: or maybe leave as (setq auth-source-netrc-use-gpg-tokens 'never)
+                           (let* ((ep (format "Use GPG password tokens in %s?" file))
+                                  (gpg-encrypt
+                                   (cond
+                                    ((eq auth-source-netrc-use-gpg-tokens 'never)
+                                     'never)
+                                    ((listp auth-source-netrc-use-gpg-tokens)
+                                     (let ((check (copy-sequence
+                                                   auth-source-netrc-use-gpg-tokens))
+                                           item ret)
+                                       (while check
+                                         (setq item (pop check))
+                                         (when (or (eq (car item) t)
+                                                   (string-match (car item) file))
+                                           (setq ret (cdr item))
+                                           (setq check nil)))))
+                                    (t 'never)))
+                                  (plain (or (eval default) (read-passwd prompt))))
+                             ;; ask if we don't know what to do (in which case
+                             ;; auth-source-netrc-use-gpg-tokens must be a list)
+                             (unless gpg-encrypt
+                               (setq gpg-encrypt (if (y-or-n-p ep) 'gpg 'never))
+                               ;; TODO: save the defcustom now? or ask?
+                               (setq auth-source-netrc-use-gpg-tokens
+                                     (cons `(,file ,gpg-encrypt)
+                                           auth-source-netrc-use-gpg-tokens)))
+                             (if (eq gpg-encrypt 'gpg)
+                                 (auth-source-epa-make-gpg-token plain file)
+                               plain))
+                         (if (stringp default)
+                             (read-string (if (string-match ": *\\'" prompt)
+                                              (concat (substring prompt 0 (match-beginning 0))
+                                                      " (default " default "): ")
+                                            (concat prompt "(default " default ") "))
+                                          nil nil default)
+                           (eval default)))))
 
         (when data
           (setq artificial (plist-put artificial
@@ -1648,7 +1645,7 @@ authentication tokens:
              (default (cond
                        ((and (not given-default) (eq r 'user))
                         (user-login-name))
-                       (t (eval given-default))))
+                       (t given-default)))
              (printable-defaults (list
                                   (cons 'user
                                         (or
@@ -1682,21 +1679,16 @@ authentication tokens:
                         (?p ,(aget printable-defaults 'port))))))
 
         ;; Store the data, prompting for the password if needed.
-        (setq data
-              (cond
-               ((and (null data) (eq r 'secret))
-                ;; Special case prompt for passwords.
-                (if default
-                    default
-                  (read-passwd prompt)))
-               ((null data)
-                (when default
-                  (read-string (if (string-match ": *\\'" prompt)
-                                   (concat (substring prompt 0 (match-beginning 0))
-                                           " (default " default "): ")
-                                 (concat prompt "(default " default ") "))
-                               nil nil default)))
-               (t (or data default))))
+        (setq data (or data
+                       (if (eq r 'secret)
+                           (or (eval default) (read-passwd prompt))
+                         (if (stringp default)
+                             (read-string (if (string-match ": *\\'" prompt)
+                                              (concat (substring prompt 0 (match-beginning 0))
+                                                      " (default " default "): ")
+                                            (concat prompt "(default " default ") "))
+                                          nil nil default)
+                           (eval default)))))
 
         (when data
           (if (member r base-secret)
@@ -1800,6 +1792,26 @@ MODE can be \"login\" or \"password\"."
 
     found))
 
+(defun auth-source-user-and-password (host &optional user)
+  (let* ((auth-info (car
+                     (if user
+                         (auth-source-search
+                          :host host
+                          :user "yourusername"
+                          :max 1
+                          :require '(:user :secret)
+                          :create nil)
+                       (auth-source-search
+                        :host host
+                        :max 1
+                        :require '(:user :secret)
+                        :create nil))))
+         (user (plist-get auth-info :user))
+         (password (plist-get auth-info :secret)))
+    (when (functionp password)
+      (setq password (funcall password)))
+    (list user password auth-info)))
+
 (provide 'auth-source)
 
 ;;; auth-source.el ends here