mirror of
git://git.sv.gnu.org/emacs.git
synced 2025-12-06 06:20:55 -08:00
Ignore non-existing or empty files in auth-sources
* doc/misc/auth.texi: Replace @code{"..."} by @t{"..."}.
(Help for users): Describe property lists format. Explain, that
empty files in auth-sources are ignored when
auth-source-ignore-empty-file is non-nil.
(Help for developers): Add auth-source-creation-defaults to vindex.
* etc/NEWS: Introduce auth-source-ignore-empty-file.
Presentational fixes and improvements.
* lisp/auth-source.el (auth-source-ignore-empty-file): New defcustom.
(auth-source-backends-parser-file): Use it. (Bug#9113)
* test/lisp/auth-source-tests.el (auth-source-validate-backend):
Let-bind `auth-source-ignore-empty-file'.
(auth-source-test-searches): Set file suffix.
(auth-source-test-netrc-create-secret): Adapt test.
This commit is contained in:
parent
a2d4034242
commit
d1221a427f
4 changed files with 136 additions and 75 deletions
|
|
@ -370,6 +370,16 @@ soon as a function returns non-nil.")
|
|||
:type 'ignore)))
|
||||
(auth-source-backend-parse-parameters entry backend)))
|
||||
|
||||
(defcustom auth-source-ignore-empty-file t
|
||||
"If set non-nil, file-based backends with no data are ignored.
|
||||
A backend is ignored, when the underlying file does not exist, or it is
|
||||
empty. Consequently, no newly created entry is saved in an empty
|
||||
backend when this user option is non-nil.
|
||||
|
||||
Supported backend types are `netrc', `plstore' and `json'."
|
||||
:version "31.1"
|
||||
:type 'boolean)
|
||||
|
||||
(defun auth-source-backends-parser-file (entry)
|
||||
;; take just a file name use it as a netrc/plist file
|
||||
;; matching any user, host, and protocol
|
||||
|
|
@ -384,26 +394,41 @@ soon as a function returns non-nil.")
|
|||
(extension (or (and (stringp source-without-gpg)
|
||||
(file-name-extension source-without-gpg))
|
||||
"")))
|
||||
(when (stringp source)
|
||||
(cond
|
||||
((equal extension "plist")
|
||||
(auth-source-backend
|
||||
:source source
|
||||
:type 'plstore
|
||||
:search-function #'auth-source-plstore-search
|
||||
:create-function #'auth-source-plstore-create
|
||||
:data (plstore-open source)))
|
||||
((member-ignore-case extension '("json"))
|
||||
(auth-source-backend
|
||||
:source source
|
||||
:type 'json
|
||||
:search-function #'auth-source-json-search))
|
||||
(t
|
||||
(auth-source-backend
|
||||
:source source
|
||||
:type 'netrc
|
||||
:search-function #'auth-source-netrc-search
|
||||
:create-function #'auth-source-netrc-create))))))
|
||||
(if (and (stringp source)
|
||||
(or (not auth-source-ignore-empty-file)
|
||||
(and-let*
|
||||
(;; File exists.
|
||||
(attr (file-attributes source))
|
||||
;; File isn't empty.
|
||||
((not (zerop (file-attribute-size attr))))))))
|
||||
(cond
|
||||
((equal extension "plist")
|
||||
(auth-source-backend
|
||||
:source source
|
||||
:type 'plstore
|
||||
:search-function #'auth-source-plstore-search
|
||||
:create-function #'auth-source-plstore-create
|
||||
:data (plstore-open source)))
|
||||
((member-ignore-case extension '("json"))
|
||||
(auth-source-backend
|
||||
:source source
|
||||
:type 'json
|
||||
:search-function #'auth-source-json-search))
|
||||
(t
|
||||
(auth-source-backend
|
||||
:source source
|
||||
:type 'netrc
|
||||
:search-function #'auth-source-netrc-search
|
||||
:create-function #'auth-source-netrc-create)))
|
||||
|
||||
(when auth-source-debug
|
||||
(auth-source-do-warn
|
||||
(concat "auth-source-backend-parse: "
|
||||
"not existing or empty file, ignoring spec: %S")
|
||||
entry))
|
||||
(auth-source-backend
|
||||
:source ""
|
||||
:type 'ignore))))
|
||||
|
||||
;; Note this function should be last in the parser functions, so we add it first
|
||||
(add-hook 'auth-source-backend-parser-functions #'auth-source-backends-parser-file)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue