From 788a65862ed9b9bc0437a016cae7e3ba1282a1a7 Mon Sep 17 00:00:00 2001 From: Michael Albinus Date: Sun, 19 Sep 2021 19:59:05 +0200 Subject: 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. --- lisp/auth-source.el | 52 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 21 deletions(-) (limited to 'lisp/auth-source.el') 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))) -- cgit v1.2.3