all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* auth-source-search doesn't work with auth-source-pass properly (IMO)
@ 2022-11-02 18:42 Akib Azmain Turja
  2022-11-06  0:08 ` F. Jason Park
  0 siblings, 1 reply; 2+ messages in thread
From: Akib Azmain Turja @ 2022-11-02 18:42 UTC (permalink / raw)
  To: Emacs Developer List

[-- Attachment #1: Type: text/plain, Size: 3648 bytes --]


I have a pass entry "akib@disroot.org", containing the password of this
mail address.  I can find it with the following:

(auth-source-search :host "disroot.org" :user "akib")
=> (#<secret>)

When I don't specify the :user, there's no result:

(auth-source-search :host "disroot.org")
=> nil

After hunting for the root, I found that the bug originates from
the let-binding lines of "suffixes" and "matching-entries" in the
"auth-source-pass--find-match-unambiguous" function.

I think the idea of searching with suffixes is entirely flawed.  IMHO,
every entry should be matched with "hostname", "user", "port"
individually.

I have fixed it by the putting the following in the init file (actually,
I added the advices with Leaf).  This works for me, and the second
example find the entry with this, and it also seems to respect
auth-source-pass-port-separator.

--8<---------------cut here---------------start------------->8---
(defun *auth-source-pass--generate-entry-suffixes--advice
    (hostname user port)
  "Return ((HOSTNAME USER PORT))."
  `((,hostname ,user ,(if (consp port) port (list port)))))

(defun *auth-source-pass--entries-matching-suffix--advice
    (query entries)
  "Return elements of ENTRIES matching QUERY."
  (let* ((hostname (pop query))
         (user (pop query))
         (port (pop query))
         (match (lambda (u h p)
                  (and h (or (equal h hostname)
                             (string-match-p
                              (format "\\.%s$" (regexp-quote h))
                              hostname))
                       (or (not u)
                           (not user)
                           (equal u user))
                       (or (not p)
                           (not port)
                           (member p port))))))
    (cl-remove-if-not
     (lambda (entry)
       (or
        ;; HOST:PORT/USER
        (pcase-let
            (((rx
               (or string-start ?/)
               (and (let h (zero-or-more (not (any ?: ?/))))
                    (zero-or-one
                     (literal auth-source-pass-port-separator)
                     (let p (one-or-more
                             (any (?0 . ?9)))))
                    ?/ (let u (one-or-more
                               (not (any ?@ ?/)))))
               string-end)
              entry))
          (funcall match u h p))
        ;; USER@HOST:PORT
        (pcase-let
            (((rx
               (or string-start ?/)
               (and (zero-or-one (let u (one-or-more
                                         (not (any ?@ ?/))))
                                 ?@)
                    (let h (zero-or-more (not (any ?: ?/))))
                    (zero-or-one
                     (literal auth-source-pass-port-separator)
                     (let p (one-or-more
                             (any (?0 . ?9))))))
               string-end)
              entry))
          (funcall match u h p))))
     (or entries (auth-source-pass-entries)))))

(advice-add #'auth-source-pass--generate-entry-suffixes :override
            #'*auth-source-pass--generate-entry-suffixes--advice)
(advice-add #'auth-source-pass--entries-matching-suffix :override
            #'*auth-source-pass--entries-matching-suffix--advice)
--8<---------------cut here---------------end--------------->8---

-- 
Akib Azmain Turja

Find me on Mastodon at @akib@hostux.social, and on Codeberg (user
"akib").

This message is signed by me with my GnuPG key.  Its fingerprint is:

    7001 8CE5 819F 17A3 BBA6  66AF E74F 0EFA 922A E7F5

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: auth-source-search doesn't work with auth-source-pass properly (IMO)
  2022-11-02 18:42 auth-source-search doesn't work with auth-source-pass properly (IMO) Akib Azmain Turja
@ 2022-11-06  0:08 ` F. Jason Park
  0 siblings, 0 replies; 2+ messages in thread
From: F. Jason Park @ 2022-11-06  0:08 UTC (permalink / raw)
  To: Akib Azmain Turja; +Cc: emacs-devel

Hi Akib,

Not sure if you've seen

  https://debbugs.gnu.org/cgi/bugreport.cgi?bug=58985

If it's of any interest to you, please volunteer to adopt it. Seems you
already have a solution going. Might as well take it all the way.

Thanks,
J.P.



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-11-06  0:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-02 18:42 auth-source-search doesn't work with auth-source-pass properly (IMO) Akib Azmain Turja
2022-11-06  0:08 ` F. Jason Park

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.