Subject: bug#58985: 29.0.50; Have auth-source-pass behave more like other back ends

From: Björn Bidar <[email-masked]>
Date: Thu, 10 Nov 2022 15:40:45 +0200

"J.P." <[email-masked]> writes:

> I know this is asking a lot, but if you get a chance, please apply the
> v2 patches and try them out. (Actually, you can omit the second one in
> the set, which only affects ERC.)

I want to add I'm not an ERC user but circe user, I've got interested in
the patch as I use the backend with circe, gnus, magit, elfeed and so
on.

>> will this mean the backend will act less like Passwordstore.org
>> describes or more?
>
> That's a good question. My main goal thus far has been to make its query
> behavior as close as possible to that of the other auth-source back
> ends. Glancing at that web page, it seems auth-source-pass has taken
> some liberties WRT to query features, like drilling down into the tail
> of a file's contents and ascribing semantics to parts of a file name.

A lot of programs don't implement the full path traversal and just end
up having a static or a bogus path (e.g. those that implement
Freedesktop SecretService with pass).
So I favor a correct implementation, any progress is welcome.

>> I think the backend should follow the users organization of the
>> passwordstore folder if possible.
>
> From this I'll infer that the current implementation of auth-source-pass
> does that sufficiently. If that's so and the changes I'm proposing
> threaten to interfere with that, what's your opinion on the default
> value of a knob to toggle the new behavior?

Hm it depends if there are any backends that workaround that old behavior.
>From what I see the only difference really is that you can specify
require and max.

My personal bindings for circe to auth-source currently only exist of
small functions:
;; Adopted from Ghub.el, refactored for use with Circe IRC
(defun circe--ident (username network)
  (format "%s^%s" username network))
(defun circe--auth-source-get (keys &rest spec)
  (declare (indent 1))
  (let ((plist (car (apply #'auth-source-search
                           (append spec (list :max 1))))))
    (mapcar (lambda (k)
              (plist-get plist k))
            keys)))
(defun circe-pass-get (host user &optional network)
  "\fn(fn host user &optional network)"
  (auth-source-forget (list :host host :user user :max 1))
  (when network
    (setq user (circe--ident user network)))
  (let ((match (car (circe--auth-source-get (list :secret)
                      :host host :user user))))
    (cond ((null match)
           (error "Auth source empty for %s %s %s" host user network))
          ((functionp match)
           (funcall match)) (t match))))

Which makes me wonder why ERC needs the different behavior but then I'm
not really a good lisp programmer more a novice.

Br,

Björn