summaryrefslogtreecommitdiff
path: root/lisp/auth-source.el
diff options
context:
space:
mode:
authorMichael Albinus <michael.albinus@gmx.de>2021-09-19 19:59:05 +0200
committerMichael Albinus <michael.albinus@gmx.de>2021-09-19 19:59:05 +0200
commit788a65862ed9b9bc0437a016cae7e3ba1282a1a7 (patch)
tree06b7dbc2ab39634cf58ce8dfb54acff1e49a414e /lisp/auth-source.el
parent7abbf3779cf88c59a9c20526464974213db63fdb (diff)
downloademacs-788a65862ed9b9bc0437a016cae7e3ba1282a1a7.tar.gz
emacs-788a65862ed9b9bc0437a016cae7e3ba1282a1a7.tar.bz2
emacs-788a65862ed9b9bc0437a016cae7e3ba1282a1a7.zip
Do not save empty passwords in auth-source-search
* lisp/auth-source.el (auth-source-netrc-create) (auth-source-secrets-create): Set :save-function only for non empty passwords. * lisp/net/tramp.el (tramp-read-passwd): Don't save empty passwords. * test/lisp/auth-source-tests.el (auth-source-test-secrets-create-secret): Adapt test. (auth-source-test-netrc-create-secret): New test.
Diffstat (limited to 'lisp/auth-source.el')
-rw-r--r--lisp/auth-source.el52
1 files changed, 31 insertions, 21 deletions
diff --git a/lisp/auth-source.el b/lisp/auth-source.el
index 8d6ebd39dcb..d938522c803 100644
--- a/lisp/auth-source.el
+++ b/lisp/auth-source.el
@@ -1282,6 +1282,8 @@ See `auth-source-search' for details on SPEC."
(required (append base-required create-extra))
(file (oref backend source))
(add "")
+ ;; Whether to set save-function.
+ save-function
;; `valist' is an alist
valist
;; `artificial' will be returned if no creation is needed
@@ -1411,6 +1413,8 @@ See `auth-source-search' for details on SPEC."
;; When r is not an empty string...
(when (and (stringp data)
(< 0 (length data)))
+ (when (eq r 'secret)
+ (setq save-function t))
;; this function is not strictly necessary but I think it
;; makes the code clearer -tzz
(let ((printer (lambda ()
@@ -1431,12 +1435,13 @@ See `auth-source-search' for details on SPEC."
data)))))
(setq add (concat add (funcall printer)))))))
- (plist-put
- artificial
- :save-function
- (let ((file file)
- (add add))
- (lambda () (auth-source-netrc-saver file add))))
+ (when save-function
+ (plist-put
+ artificial
+ :save-function
+ (let ((file file)
+ (add add))
+ (lambda () (auth-source-netrc-saver file add)))))
(list artificial)))
@@ -1664,6 +1669,8 @@ authentication tokens:
:port port)))
(required (append base-required create-extra))
(collection (oref backend source))
+ ;; Whether to set save-function.
+ save-function
;; `args' are the arguments for `secrets-create-item'.
args
;; `valist' is an alist
@@ -1778,21 +1785,24 @@ authentication tokens:
;; When r is not an empty string...
(when (and (stringp data)
- (< 0 (length data))
- (not (member r '(secret label))))
- ;; append the key (the symbol name of r)
- ;; and the value in r
- (setq args (append args (list (auth-source--symbol-keyword r) data))))))
-
- (plist-put
- artificial
- :save-function
- (let* ((collection collection)
- (item (plist-get artificial :label))
- (secret (plist-get artificial :secret))
- (secret (if (functionp secret) (funcall secret) secret)))
- (lambda ()
- (auth-source-secrets-saver collection item secret args))))
+ (< 0 (length data)))
+ (if (eq r 'secret)
+ (setq save-function t)
+ (if (not (eq r 'label))
+ ;; append the key (the symbol name of r)
+ ;; and the value in r
+ (setq args (append args (list (auth-source--symbol-keyword r) data))))))))
+
+ (when save-function
+ (plist-put
+ artificial
+ :save-function
+ (let* ((collection collection)
+ (item (plist-get artificial :label))
+ (secret (plist-get artificial :secret))
+ (secret (if (functionp secret) (funcall secret) secret)))
+ (lambda ()
+ (auth-source-secrets-saver collection item secret args)))))
(list artificial)))