Subject: bug#67937: 30.0.50; auth-source-pass relies on epa-file being enabled

From: Michael Albinus <[email-masked]>
Date: Fri, 29 Dec 2023 10:38:27 +0100

Arsen Arsenović <[email-masked]> writes:

> Hi Michael,

Hi Arsen,

> So I did.  With the diff below, I ran into an issue: the error emitted
> in it is caught.

Could you pls just print a backtrace when epa-fle-handler isn't found?
Something like

--8<---------------cut here---------------start------------->8---
(message "%s" (with-output-to-string (backtrace)))
--8<---------------cut here---------------end--------------->8---

This would give us a backtrace to analyze.

> I believe that the check utilized below is correct for the
> check-and-error solution.
>
> diff --git a/lisp/auth-source-pass.el b/lisp/auth-source-pass.el
> index 0f51755a250..4da15a65259 100644
> --- a/lisp/auth-source-pass.el
> +++ b/lisp/auth-source-pass.el
> @@ -195,10 +195,13 @@ auth-source-pass--get-attr
>  (defun auth-source-pass--read-entry (entry)
>    "Return a string with the file content of ENTRY."
>    (with-temp-buffer
> -    (insert-file-contents (expand-file-name
> -                           (format "%s.gpg" entry)
> -                           auth-source-pass-filename))
> -    (buffer-substring-no-properties (point-min) (point-max))))
> +    (let ((fname (format "%s.gpg" entry)))
> +      (if (not (find-file-name-handler fname 'insert-file-contents))
> +          (error "auth-source-pass requires a handler for .gpg files"))
> +      (insert-file-contents (expand-file-name
> +                             fname
> +                             auth-source-pass-filename))
> +      (buffer-substring-no-properties (point-min) (point-max)))))
>
>  (defun auth-source-pass-parse-entry (entry)
>    "Return an alist of the data associated with ENTRY.

Nope. find-file-name-handler shows the next file name handler to be
applied. It could be epa-file-handler, but if it is removed from
file-name-handler-alist, another file name handler could be returned,
like tramp-file-name-handler. So if you want to use
find-file-name-handler, you must check something like

--8<---------------cut here---------------start------------->8---
(eq (find-file-name-handler fname 'insert-file-contents) 'epa-file-handler)
--8<---------------cut here---------------end--------------->8---

> Arsen Arsenović

Best regards, Michael.