From unknown Wed Sep 10 10:11:26 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#26699 <26699@debbugs.gnu.org> To: bug#26699 <26699@debbugs.gnu.org> Subject: Status: 26.0.50; Allow non-string keys in password-cache Reply-To: bug#26699 <26699@debbugs.gnu.org> Date: Wed, 10 Sep 2025 17:11:26 +0000 retitle 26699 26.0.50; Allow non-string keys in password-cache reassign 26699 emacs submitter 26699 Stefan Monnier severity 26699 minor tag 26699 patch thanks From debbugs-submit-bounces@debbugs.gnu.org Fri Apr 28 12:42:59 2017 Received: (at submit) by debbugs.gnu.org; 28 Apr 2017 16:42:59 +0000 Received: from localhost ([127.0.0.1]:44945 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d48yx-0003qT-2S for submit@debbugs.gnu.org; Fri, 28 Apr 2017 12:42:59 -0400 Received: from eggs.gnu.org ([208.118.235.92]:36613) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d48yv-0003qH-EY for submit@debbugs.gnu.org; Fri, 28 Apr 2017 12:42:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d48ym-0000Dp-8M for submit@debbugs.gnu.org; Fri, 28 Apr 2017 12:42:52 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50 autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:38559) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d48ym-0000Dk-4W for submit@debbugs.gnu.org; Fri, 28 Apr 2017 12:42:48 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55811) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d48yk-0008V0-K7 for bug-gnu-emacs@gnu.org; Fri, 28 Apr 2017 12:42:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d48yh-0000BQ-Et for bug-gnu-emacs@gnu.org; Fri, 28 Apr 2017 12:42:46 -0400 Received: from ironport2-out.teksavvy.com ([206.248.154.181]:53982) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d48yh-0000Af-86 for bug-gnu-emacs@gnu.org; Fri, 28 Apr 2017 12:42:43 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0CNAgCcbwNZ/93gSC1ehAWFB4tZkQUBRoF0iguIfIIPHIYCBIQ5QBgBAgEBAQEBAQFrKIVyXw8EIQEcDYpWnxmSMos7iD2CZoFwAYJ+coF/gxgFkA+GLocUlRCIaTOBH4UhlCkfOIEKLiAILoRlAQtDDRCBfySFZII9AQEB X-IPAS-Result: A0CNAgCcbwNZ/93gSC1ehAWFB4tZkQUBRoF0iguIfIIPHIYCBIQ5QBgBAgEBAQEBAQFrKIVyXw8EIQEcDYpWnxmSMos7iD2CZoFwAYJ+coF/gxgFkA+GLocUlRCIaTOBH4UhlCkfOIEKLiAILoRlAQtDDRCBfySFZII9AQEB X-IronPort-AV: E=Sophos;i="5.37,388,1488862800"; d="scan'208";a="309597912" Received: from 45-72-224-221.cpe.teksavvy.com (HELO ceviche.home) ([45.72.224.221]) by smtp.teksavvy.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 28 Apr 2017 12:42:41 -0400 Received: by ceviche.home (Postfix, from userid 20848) id D3891662CE; Fri, 28 Apr 2017 12:42:40 -0400 (EDT) From: Stefan Monnier To: bug-gnu-emacs@gnu.org Subject: 26.0.50; Allow non-string keys in password-cache Date: Fri, 28 Apr 2017 12:42:40 -0400 Message-ID: MIME-Version: 1.0 Content-Type: text/plain X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -4.0 (----) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -4.0 (----) Package: Emacs Version: 26.0.50 I suggest the patch below to make password-cache use a hash-table rather than an obarray and at the same occasion allow non-string keys, which simplifies auth-source's code. Any objection? Should I add a `password-map` function while I'm at it (alias to `maphash`) so as to avoid auth-source depending on those internals of password-cache? Stefan diff --git a/lisp/auth-source.el b/lisp/auth-source.el index 01d12c2614..798011e6ff 100644 --- a/lisp/auth-source.el +++ b/lisp/auth-source.el @@ -200,8 +200,6 @@ auth-source-netrc-use-gpg-tokens (const :tag "Save GPG-encrypted password tokens" gpg) (const :tag "Don't encrypt tokens" never)))))) -(defvar auth-source-magic "auth-source-magic ") - (defcustom auth-source-do-cache t "Whether auth-source should cache information with `password-cache'." :group 'auth-source @@ -782,16 +780,16 @@ auth-source-netrc-cache (defun auth-source-forget-all-cached () "Forget all cached auth-source data." (interactive) - (cl-do-symbols (sym password-data) - ;; when the symbol name starts with auth-source-magic - (when (string-match (concat "^" auth-source-magic) (symbol-name sym)) - ;; remove that key - (password-cache-remove (symbol-name sym)))) + (maphash (lambda (key password) + (when (eq 'auth-source (car-safe key)) + ;; remove that key + (password-cache-remove key))) + password-data) (setq auth-source-netrc-cache nil)) (defun auth-source-format-cache-entry (spec) "Format SPEC entry to put it in the password cache." - (concat auth-source-magic (format "%S" spec))) + `(auth-source . ,spec)) (defun auth-source-remember (spec found) "Remember FOUND search results for SPEC." @@ -824,16 +822,15 @@ auth-source-forget+ while \(:host t) would find all host entries." (let ((count 0) sname) - (cl-do-symbols (sym password-data) - ;; when the symbol name matches with auth-source-magic - (when (and (setq sname (symbol-name sym)) - (string-match (concat "^" auth-source-magic "\\(.+\\)") - sname) - ;; and the spec matches what was stored in the cache - (auth-source-specmatchp spec (read (match-string 1 sname)))) - ;; remove that key - (password-cache-remove sname) - (cl-incf count))) + (maphash + (lambda (key password) + (when (and (eq 'auth-source (car-safe key)) + ;; and the spec matches what was stored in the cache + (auth-source-specmatchp spec (cdr key))) + ;; remove that key + (password-cache-remove key) + (cl-incf count))) + password-data) count)) (defun auth-source-specmatchp (spec stored) diff --git a/lisp/password-cache.el b/lisp/password-cache.el index 7be3c6fdb6..cbc248b9ec 100644 --- a/lisp/password-cache.el +++ b/lisp/password-cache.el @@ -66,7 +66,7 @@ password-cache-expiry :type '(choice (const :tag "Never" nil) (integer :tag "Seconds"))) -(defvar password-data (make-vector 7 0)) +(defvar password-data (make-hash-table :test #'equal)) (defun password-read-from-cache (key) "Obtain passphrase for KEY from time-limited passphrase cache. @@ -74,20 +74,20 @@ password-read-from-cache regulate cache behavior." (and password-cache key - (symbol-value (intern-soft key password-data)))) + (gethash key password-data))) ;;;###autoload (defun password-in-cache-p (key) "Check if KEY is in the cache." (and password-cache key - (intern-soft key password-data))) + (gethash key password-data))) (defun password-read (prompt &optional key) "Read password, for use with KEY, from user, or from cache if wanted. KEY indicate the purpose of the password, so the cache can -separate passwords. The cache is not used if KEY is nil. It is -typically a string. +separate passwords. The cache is not used if KEY is nil. +KEY is typically a string but can be anything (compared via `equal'). The variable `password-cache' control whether the cache is used." (or (password-read-from-cache key) (read-passwd prompt))) @@ -115,29 +115,27 @@ password-cache-remove from the cache. This may be useful when it has been detected that a password is invalid, so that `password-read' query the user again." - (let ((sym (intern-soft key password-data))) - (when sym - (let ((password (symbol-value sym))) - (when (stringp password) - (if (fboundp 'clear-string) - (clear-string password) - (fillarray password ?_))) - (unintern key password-data))))) + (let ((password (gethash key password-data))) + (when (stringp password) + (if (fboundp 'clear-string) + (clear-string password) + (fillarray password ?_))) + (remhash key password-data))) (defun password-cache-add (key password) "Add password to cache. The password is removed by a timer after `password-cache-expiry' seconds." - (when (and password-cache-expiry (null (intern-soft key password-data))) + (when (and password-cache-expiry (null (gethash key password-data))) (run-at-time password-cache-expiry nil #'password-cache-remove key)) - (set (intern key password-data) password) + (puthash key password password-data) nil) (defun password-reset () "Clear the password cache." (interactive) - (fillarray password-data 0)) + (clrhash password-data)) (provide 'password-cache) From debbugs-submit-bounces@debbugs.gnu.org Fri Jul 28 12:27:48 2017 Received: (at 26699-done) by debbugs.gnu.org; 28 Jul 2017 16:27:48 +0000 Received: from localhost ([127.0.0.1]:60219 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1db87A-00018L-J4 for submit@debbugs.gnu.org; Fri, 28 Jul 2017 12:27:48 -0400 Received: from pruche.dit.umontreal.ca ([132.204.246.22]:38532) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1db878-00018D-En for 26699-done@debbugs.gnu.org; Fri, 28 Jul 2017 12:27:47 -0400 Received: from ceviche.home (lechon.iro.umontreal.ca [132.204.27.242]) by pruche.dit.umontreal.ca (8.14.7/8.14.1) with ESMTP id v6SGRiLh023637; Fri, 28 Jul 2017 12:27:45 -0400 Received: by ceviche.home (Postfix, from userid 20848) id 8EDF3660F6; Fri, 28 Jul 2017 12:27:44 -0400 (EDT) From: Stefan Monnier To: 26699-done@debbugs.gnu.org Subject: Re: bug#26699: 26.0.50; Allow non-string keys in password-cache Message-ID: References: Date: Fri, 28 Jul 2017 12:27:44 -0400 In-Reply-To: (Stefan Monnier's message of "Fri, 28 Apr 2017 12:42:40 -0400") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-NAI-Spam-Flag: NO X-NAI-Spam-Level: X-NAI-Spam-Threshold: 5 X-NAI-Spam-Score: 0.1 X-NAI-Spam-Rules: 3 Rules triggered GEN_SPAM_FEATRE=0.1, EDT_SA_DN_PASS=0, RV6082=0 X-NAI-Spam-Version: 2.3.0.9418 : core <6082> : inlines <5998> : streams <1756155> : uri <2471612> X-Spam-Score: -1.3 (-) X-Debbugs-Envelope-To: 26699-done X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.3 (-) Installed into trunk, Stefan From unknown Wed Sep 10 10:11:26 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Sat, 26 Aug 2017 11:24:04 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator