From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Filipp Gunbin Newsgroups: gmane.emacs.bugs Subject: bug#64089: 30.0.50; `ldap-search' errors out with `wrong-type-argument listp' when called WITHDN == t Date: Sat, 17 Jun 2023 01:13:33 +0300 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="39886"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: Eli Zaretskii , 64089@debbugs.gnu.org, Stefan Monnier To: Jens Schmidt Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Jun 17 00:14:23 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1qAHi1-000A91-9s for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 17 Jun 2023 00:14:23 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qAHhj-0006IK-S3; Fri, 16 Jun 2023 18:14:03 -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 1qAHhi-0006I2-Mh for bug-gnu-emacs@gnu.org; Fri, 16 Jun 2023 18:14:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qAHhi-0004vW-E3 for bug-gnu-emacs@gnu.org; Fri, 16 Jun 2023 18:14:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qAHhh-0006S0-TQ for bug-gnu-emacs@gnu.org; Fri, 16 Jun 2023 18:14:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Filipp Gunbin Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 16 Jun 2023 22:14:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 64089 X-GNU-PR-Package: emacs Original-Received: via spool by 64089-submit@debbugs.gnu.org id=B64089.168695362824771 (code B ref 64089); Fri, 16 Jun 2023 22:14:01 +0000 Original-Received: (at 64089) by debbugs.gnu.org; 16 Jun 2023 22:13:48 +0000 Original-Received: from localhost ([127.0.0.1]:50496 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qAHhT-0006RP-RG for submit@debbugs.gnu.org; Fri, 16 Jun 2023 18:13:48 -0400 Original-Received: from wout4-smtp.messagingengine.com ([64.147.123.20]:33519) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qAHhQ-0006RC-TH for 64089@debbugs.gnu.org; Fri, 16 Jun 2023 18:13:45 -0400 Original-Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.west.internal (Postfix) with ESMTP id E91E932005C1; Fri, 16 Jun 2023 18:13:38 -0400 (EDT) Original-Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Fri, 16 Jun 2023 18:13:39 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastmail.fm; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm2; t=1686953618; x=1687040018; bh=Ur TjtOo97iExPnii+1Zkpy1aiGy7SoHfx+LvNzlTYEs=; b=XMOJYYHqb1+Or1ivxy /rIT1iLUIiCpMsgGXyob86TYG4BfJbddSbHfbghXZvGNOFdazS4plLLfqWJJ2yTQ aoUshpO5jpEQqWJcwaGR0kp8KbSwWmCe7sgCmTOlX/3cv/mqZQ1RnLyNKk4/Z4bm U8ipDhrZVzGQm0+re70D3oH2T9E26ORI6QvQpCqE5IZlfRHGinTIfz+mjH/K8eyo cJjLRfU9cUqtugIxv0cWGoOAiQsj3X599MIjT0DWxhHZ6WSd71lZU5Y54cMoelH4 KkWkPUz24FK4PW/7BdBYCPGapxBJQHW3cYZhJoWafL2UDLmrMamaF6yoRK9HpNbS h92g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; t=1686953618; x=1687040018; bh=UrTjtOo97iExP nii+1Zkpy1aiGy7SoHfx+LvNzlTYEs=; b=RSshebqtklnobcLeNvii2i+oesW0b dTwRAGf2gj15M9aV3296ApiHUkhLL0RQoknIj43Yy9wCE3awjHMIOMExuOwwKtYy 7AzCDAma7lw+iLe7MNIDoCGCjVRmD8E1USrkS1NSKllFwPQ+0vNGaEAwswz+Getb SXQvGL5Mzblfcbw0hlAJJIy+x5xICj/I4LGyHTGHBW+BmN+HdfTqaZUkcl1E8Smk wJbFcQOFhhEeeFZN1mCO2dCVzb8xdKnZQ2GaiNyAXigokfbC+9isMq467YqOnvBJ 7ryRPwLv6ZoTxNILLXpqx8169Z52A6uRr1CgDeVwlxNXAfYeMDhRj+ZKA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrgedvhedgtdekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefujghffgffkfggtgesthdtredttdertdenucfhrhhomhephfhilhhi phhpucfiuhhnsghinhcuoehfghhunhgsihhnsehfrghsthhmrghilhdrfhhmqeenucggtf frrghtthgvrhhnpeffhfejveeiieeiudetgfehffelieevfeeffedtkeelheeludefueeu udehveeiffenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhroh hmpehfghhunhgsihhnsehfrghsthhmrghilhdrfhhm X-ME-Proxy: Feedback-ID: id48c41f1:Fastmail Original-Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 16 Jun 2023 18:13:36 -0400 (EDT) In-Reply-To: (Jens Schmidt's message of "Fri, 16 Jun 2023 00:11:15 +0200") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:263489 Archived-At: Hi Jens, thanks for reporting this. On 16/06/2023 00:11 +0200, Jens Schmidt wrote: > With the following patch things work as expected: > > (ldap-search "(uid=)" > "ldap://" > '("mail") > nil > t) > => ((("dn" "cn=,L=,DC=,DC=COM") ("mail" > "@.com"))) > > I tried to make the patch as conservative as possible and > intentionally do not check syntax of the dn line if its parsing is not > required. I think I have better patch here. This is what it addresses: 1) The bug you reported. My patch tries to keep the API intact (we don't want breakage, however I think not much people actually use withdn arg): return dn as a string, prepended to attribute alist. 2) dn is now parsed just like the other attributes, with the same regexp. 3) (unrelated, just noticed and fixed) Match data clobbering in this piece: - ;; Need to handle file:///D:/... as generated by OpenLDAP - ;; on DOS/Windows as local files. - (if (and (memq system-type '(windows-nt ms-dos)) - (eq (string-match "/\\(.:.*\\)$" value) 0)) - (setq value (match-string 1 value))) 4) This code: + (when dn + (cond (withdn + (push (cons dn (nreverse record)) + result)) intentionally doesn't check whether record is non-nil: potentially we could request "no attributes" (there's an option for that in ldapsearch, however I don't think this is currently possible in ldap.el), and it's ok to return just dn. Please give it a try, if it's OK and others have no objections, I'll install it on Monday (on master, I guess). Thanks. Filipp diff --git a/lisp/net/ldap.el b/lisp/net/ldap.el index 78405414a28..3048b7e7a2f 100644 --- a/lisp/net/ldap.el +++ b/lisp/net/ldap.el @@ -487,7 +487,9 @@ ldap-search (if ldap-ignore-attribute-codings result (mapcar (lambda (record) - (mapcar #'ldap-decode-attribute record)) + (append (and withdn (list (car record))) + (mapcar #'ldap-decode-attribute + (if withdn (cdr record) record)))) result)))) (defun ldap-password-read (host) @@ -703,35 +705,42 @@ ldap-search-internal (while (progn (skip-chars-forward " \t\n") (not (eobp))) - (setq dn (buffer-substring (point) (line-end-position))) - (forward-line 1) (while (looking-at "^\\([A-Za-z][-A-Za-z0-9]*\ \\|[0-9]+\\(?:\\.[0-9]+\\)*\\)\\(;[-A-Za-z0-9]+\\)*[=:\t ]+\ \\(<[\t ]*file://\\)?\\(.*\\)$") (setq name (match-string 1) value (match-string 4)) - ;; Need to handle file:///D:/... as generated by OpenLDAP - ;; on DOS/Windows as local files. - (if (and (memq system-type '(windows-nt ms-dos)) - (eq (string-match "/\\(.:.*\\)$" value) 0)) - (setq value (match-string 1 value))) - ;; Do not try to open non-existent files - (if (match-string 3) - (with-current-buffer bufval - (erase-buffer) - (set-buffer-multibyte nil) - (insert-file-contents-literally value) - (delete-file value) - (setq value (buffer-string))) - (setq value " ")) - (setq record (cons (list name value) - record)) + (when (memq system-type '(windows-nt ms-dos)) + ;; Need to handle file:///D:/... as generated by + ;; OpenLDAP on DOS/Windows as local files. + (save-match-data + (when (eq (string-match "/\\(.:.*\\)$" value) 0) + (setq value (match-string 1 value))))) + (cond ((match-string 3) ;normal value written to a file + (with-current-buffer bufval + (erase-buffer) + (set-buffer-multibyte nil) + (insert-file-contents-literally value) + (delete-file value) + (setq value (buffer-string)))) + (;; dn is output inline + (string-equal-ignore-case name "dn") + (setq dn value + name nil + value nil)) + (t (setq value " "))) + (and name value + (setq record (cons (list name value) + record))) (forward-line 1)) - (cond (withdn - (push (cons dn (nreverse record)) result)) - (record - (push (nreverse record) result))) - (setq record nil) + (when dn + (cond (withdn + (push (cons dn (nreverse record)) + result)) + (record + (push (nreverse record) result)))) + (setq record nil + dn nil) (message "Parsing results... %d" numres) (setq numres (1+ numres))) (message "Parsing results... done")