2010-09-26 Lars Magne Ingebrigtsen <larsi@gnus.org>
+ * auth-source.el (auth-source-create): Query the user for whether to
+ store the credentials.
+
+ * netrc.el (netrc-store-data): New function.
+
* auth-source.el (auth-source-user-or-password): Use the existing auth
sources, if any, for creation.
(setq result
(mapcar
(lambda (m)
- (cond
- ((equal "password" m)
- (let ((passwd (read-passwd
- (format "Password for %s on %s: " prot host))))
- (cond
- ;; Secret Service API.
- ((consp source)
- (apply
- 'secrets-create-item
- (auth-get-source entry) name passwd spec))
- (t)) ;; netrc not implemented yes.
- passwd))
- ((equal "login" m)
- (or user
- (read-string (format "User name for %s on %s: " prot host))))
- (t
- "unknownuser")))
+ (cons
+ m
+ (cond
+ ((equal "password" m)
+ (let ((passwd (read-passwd
+ (format "Password for %s on %s: " prot host))))
+ (cond
+ ;; Secret Service API.
+ ((consp source)
+ (apply
+ 'secrets-create-item
+ (auth-get-source entry) name passwd spec))
+ (t)) ;; netrc not implemented yes.
+ passwd))
+ ((equal "login" m)
+ (or user
+ (read-string (format "User name for %s on %s: " prot host))))
+ (t
+ "unknownuser"))))
(if (consp mode) mode (list mode))))
- (if (consp mode) result (car result))))
+ ;; Allow the source to save the data.
+ (cond
+ ((consp source)
+ ;; Secret Service API -- not implemented.
+ )
+ (t
+ ;; netrc interface.
+ (when (y-or-n-p (format "Do you want to save this password in %s? "
+ source))
+ (netrc-store-data source host prot
+ (or user (cdr (assoc "login" result)))
+ (cdr (assoc "password" result))))))
+ (if (consp mode)
+ (mapcar #'cdr result)
+ (cdar result))))
(defun auth-source-delete (entry &rest spec)
"Delete credentials according to SPEC in ENTRY."
(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.