From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Akib Azmain Turja Newsgroups: gmane.emacs.devel Subject: auth-source-search doesn't work with auth-source-pass properly (IMO) Date: Thu, 03 Nov 2022 00:42:10 +0600 Message-ID: <878rkturjx.fsf@disroot.org> Mime-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="6224"; mail-complaints-to="usenet@ciao.gmane.io" To: Emacs Developer List Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed Nov 02 19:47:52 2022 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oqImF-0001Lk-Fu for ged-emacs-devel@m.gmane-mx.org; Wed, 02 Nov 2022 19:47:51 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oqIld-0007Q1-DS; Wed, 02 Nov 2022 14:47:13 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oqIlc-0007Pe-8S for emacs-devel@gnu.org; Wed, 02 Nov 2022 14:47:12 -0400 Original-Received: from knopi.disroot.org ([178.21.23.139]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oqIlW-00053b-9c for emacs-devel@gnu.org; Wed, 02 Nov 2022 14:47:11 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by disroot.org (Postfix) with ESMTP id 219DB411E6 for ; Wed, 2 Nov 2022 19:47:05 +0100 (CET) X-Virus-Scanned: SPAM Filter at disroot.org Original-Received: from knopi.disroot.org ([127.0.0.1]) by localhost (disroot.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id DkZgbZW9fIdK for ; Wed, 2 Nov 2022 19:47:03 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1667414823; bh=13mkRGXIgkuTE/0XWXZLxRLamNWLJQbETTVpc3TD+RQ=; h=From:To:Subject:Date; b=UBJsdu8r7kWQoatOW3qVm9BvGVOMH5SlDakhknlr3RbEcLnXrazSLURYVC4nupJp5 dzeUGVJBbWfl46cXVHgM/GY7hrtU/IHhrXVMI1Zbqm51K+BHtCI6xpvf8l0PyI4KBT l1N5/t0aRtrL7UCVr9cXKkGif1YWrYfMML5YG34Z6s07yymuKzSk+V/8sIFiL7lk7A 0kFNyW1xmzIlCWdLXihH/mbemfsVXcM3ckv+C1nkaDV8fyy7gXLx9pvjlt8JADELe6 V5deTIJt5oBxJm+kAqgF4Zadu6eKjmJJEo+hFXfDD7PhDxt070u20LCc+YNwFzaJhu pfkZpfWwIjc/w== Received-SPF: pass client-ip=178.21.23.139; envelope-from=akib@disroot.org; helo=knopi.disroot.org X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: "Emacs-devel" Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:299034 Archived-At: --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable 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") =3D> (#) When I don't specify the :user, there's no result: (auth-source-search :host "disroot.org") =3D> 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. =2D-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) =2D-8<---------------cut here---------------end--------------->8--- =2D-=20 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 --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEyVTKmrtL6kNBe3FRVTX89U2IYWsFAmNiugIACgkQVTX89U2I YWsuDA//Z1QyPhfI2Qp2nFL9kbiEwEoaPiREEIhgcIMZuoZxrWwqdsjbPgISGD48 /yThnBXRzt+tel0K1tLROMNdq3xL3JaBfyXGa6W8QOh07O/DEMQQGj/kuxzeR15k h2ycSXfTTqqz9D4SO2ykC5ITrVpuLCD76CGHCjjDOzeLv9t6eA3SCd6fPBxkSeKn aMulUvptW9P49guv0Yhx7KIxQW2s8qe6KUVyUMpxUQ7kXbK8wTXGo3ltUAQyV3yM WqGUptZXvsAuq2ZjwVFtm3WffgHDjG4l6iYhMu5H+61hKQncNKX/G/qXaRdFtRKQ HaOR7YxXwtDxbjpSSlzURZB6VQakZ0RffgyqF5lqARQwW8FstL1vclgezTe8G5ki amjcX/SVDGlTedqG3GRDYuaqGz2XRHBC73dH/0sQuTfaRekGlIxVQSPxeGuL/Y8y baaDT/GMiggjr3TSCN0OeourOADa4KvzncN8P/gr1koS0WRAFihE5irEbAmDtAO7 8Kcqh0CG7v+EJIGjOg6xzPIxik38uiLwPMEC/Vod0Ey4N/n6C2yaxIaqZPV24rmg BD8aHvE5/7Gia2aF07svwrt4n/fcY5kbVjT3gBWIHsrzvJcFK4SWKFSLAbwjCfkB 4x0rf/6rVsyedk5pfeyM5qDRRrZUWqJ8ZzNKzgzsl1qsEyilRU8= =l7Sa -----END PGP SIGNATURE----- --=-=-=--