]> code.delx.au - gnu-emacs/blobdiff - lisp/url/url-auth.el
* vc-dav.el: Move here from url/vc-dav.el.
[gnu-emacs] / lisp / url / url-auth.el
index ed1a79260ee3771111d179c9e97117b9045a7d3f..ebd5c54ce14df278dd97f4ca2c9bb73a8b6caed2 100644 (file)
@@ -1,16 +1,16 @@
 ;;; url-auth.el --- Uniform Resource Locator authorization modules
 
-;; Copyright (C) 1996, 1997, 1998, 1999, 2004,
-;;   2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+;; Copyright (C) 1996, 1997, 1998, 1999, 2004, 2005, 2006, 2007,
+;;   200 Free Software Foundation, Inc.
 
 ;; Keywords: comm, data, processes, hypermedia
 
 ;; This file is part of GNU Emacs.
 
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; GNU Emacs is free software: you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 3, or (at your option)
-;; any later version.
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
 ;; GNU General Public License for more details.
 
 ;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-;; Boston, MA 02110-1301, USA.
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
 
 ;;; Code:
 
 (require 'url-vars)
 (require 'url-parse)
 (autoload 'url-warn "url")
+(autoload 'auth-source-user-or-password "auth-source")
 
 (defsubst url-auth-user-prompt (url realm)
   "String to usefully prompt for a username."
@@ -66,6 +65,7 @@ instead of the filename inheritance method."
                   (url-generic-parse-url url)
                 url))
         (server (url-host href))
+        (type (url-type href))
         (port (url-port href))
         (file (url-filename href))
         (user (url-user href))
@@ -81,9 +81,13 @@ instead of the filename inheritance method."
                                  (symbol-value url-basic-auth-storage))))
     (cond
      ((and prompt (not byserv))
-      (setq user (read-string (url-auth-user-prompt url realm)
-                             (or user (user-real-login-name)))
-           pass (read-passwd "Password: " nil (or pass "")))
+      (setq user (or
+                 (auth-source-user-or-password "login" server type)
+                 (read-string (url-auth-user-prompt url realm)
+                              (or user (user-real-login-name))))
+           pass (or
+                 (auth-source-user-or-password "password" server type)
+                 (read-passwd "Password: " nil (or pass ""))))
       (set url-basic-auth-storage
           (cons (list server
                       (cons file
@@ -105,9 +109,13 @@ instead of the filename inheritance method."
            (setq byserv (cdr byserv))))
       (if (or (and (not retval) prompt) overwrite)
          (progn
-           (setq user (read-string (url-auth-user-prompt url realm)
-                                   (user-real-login-name))
-                 pass (read-passwd "Password: ")
+           (setq user (or
+                       (auth-source-user-or-password "login" server type)
+                       (read-string (url-auth-user-prompt url realm)
+                                    (user-real-login-name)))
+                 pass (or
+                       (auth-source-user-or-password "password" server type)
+                       (read-passwd "Password: "))
                  retval (base64-encode-string (format "%s:%s" user pass))
                  byserv (assoc server (symbol-value url-basic-auth-storage)))
            (setcdr byserv
@@ -152,6 +160,7 @@ instead of hostname:portnum."
                       (url-generic-parse-url url)
                     url))
             (server (url-host href))
+            (type (url-type href))
             (port (url-port href))
             (file (url-filename href))
             user pass byserv retval data)
@@ -163,9 +172,13 @@ instead of hostname:portnum."
              byserv (cdr-safe (assoc server url-digest-auth-storage)))
        (cond
         ((and prompt (not byserv))
-         (setq user (read-string (url-auth-user-prompt url realm)
-                                 (user-real-login-name))
-               pass (read-passwd "Password: ")
+         (setq user (or
+                     (auth-source-user-or-password "login" server type)
+                     (read-string (url-auth-user-prompt url realm)
+                                  (user-real-login-name)))
+               pass (or
+                     (auth-source-user-or-password "password" server type)
+                     (read-passwd "Password: "))
                url-digest-auth-storage
                (cons (list server
                            (cons file
@@ -190,9 +203,13 @@ instead of hostname:portnum."
                (setq byserv (cdr byserv))))
          (if overwrite
              (if (and (not retval) prompt)
-                 (setq user (read-string (url-auth-user-prompt url realm)
-                                         (user-real-login-name))
-                       pass (read-passwd "Password: ")
+                 (setq user (or
+                             (auth-source-user-or-password "login" server type)
+                             (read-string (url-auth-user-prompt url realm)
+                                          (user-real-login-name)))
+                       pass (or
+                             (auth-source-user-or-password "password" server type)
+                             (read-passwd "Password: "))
                        retval (setq retval
                                     (cons user
                                           (url-digest-auth-create-key