unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Filipp Gunbin <fgunbin@fastmail.fm>
To: Jens Schmidt <jschmidt4gnu@vodafonemail.de>
Cc: Eli Zaretskii <eliz@gnu.org>,
	64089@debbugs.gnu.org, Stefan Monnier <monnier@iro.umontreal.ca>
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	[thread overview]
Message-ID: <m2352rawdu.fsf_-_@fastmail.fm> (raw)
In-Reply-To: <a71487a0-3803-3fcf-5f9f-329cd4a13009@vodafonemail.de> (Jens Schmidt's message of "Fri, 16 Jun 2023 00:11:15 +0200")

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=<uid>)"
>               "ldap://<host>"
>               '("mail")
>               nil
>               t)
> => ((("dn" "cn=<NAME>,L=<REGION>,DC=<DOMAIN>,DC=COM") ("mail"
> "<name>@<domain>.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")





  parent reply	other threads:[~2023-06-16 22:13 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-15 21:28 bug#64089: 30.0.50; `ldap-search' errors out with `wrong-type-argument listp' when called WITHDN == t Jens Schmidt via Bug reports for GNU Emacs, the Swiss army knife of text editors
     [not found] ` <handler.64089.B.168686453832024.ack@debbugs.gnu.org>
2023-06-15 22:11   ` bug#64089: Acknowledgement (30.0.50; `ldap-search' errors out with `wrong-type-argument listp' when called WITHDN == t) Jens Schmidt via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-06-16  6:01     ` bug#64089: 30.0.50; " Eli Zaretskii
2023-06-16 15:12       ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-06-16 18:37         ` Jens Schmidt via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-06-17  8:40           ` Eli Zaretskii
2023-06-16 22:13     ` Filipp Gunbin [this message]
2023-06-17  6:03       ` bug#64089: 30.0.50; `ldap-search' errors out with `wrong-type-argument listp' when called WITHDN == t Eli Zaretskii
2023-06-17  8:41         ` Eli Zaretskii
2023-06-17  9:07           ` Eli Zaretskii
2023-06-17 23:14             ` Filipp Gunbin
2023-06-18  5:22               ` Eli Zaretskii
2023-06-19 14:27                 ` Filipp Gunbin
2023-06-19 17:24                   ` Eli Zaretskii
2023-06-19 18:38                     ` Filipp Gunbin
2023-06-19 19:09                       ` Eli Zaretskii
2023-06-19 19:27                         ` Filipp Gunbin
2023-06-19 20:15                           ` Jens Schmidt via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-06-19 20:35                             ` Filipp Gunbin
2023-06-19 21:37                               ` Jens Schmidt via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-06-20 14:23                                 ` Filipp Gunbin
2023-06-20 20:42                                   ` Jens Schmidt via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-06-20 11:01                           ` Eli Zaretskii
2023-06-20 17:52                             ` Filipp Gunbin
2023-06-18  7:43               ` Jens Schmidt via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-06-18  8:51                 ` Jens Schmidt via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-06-18  8:56                   ` Eli Zaretskii
2023-06-18 11:04                     ` Jens Schmidt via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-06-18 22:14                 ` bug#64160: " Jens Schmidt via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-06-19 14:11                   ` Filipp Gunbin
2023-06-19 15:13                     ` bug#64160: master; Implement various enhancements in ldap.el and EUDC Filipp Gunbin
2023-06-19 21:16                       ` Jens Schmidt via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-06-20 14:11                         ` Filipp Gunbin
2023-06-20 22:23                           ` Jens Schmidt via Bug reports for GNU Emacs, the Swiss army knife of text editors

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m2352rawdu.fsf_-_@fastmail.fm \
    --to=fgunbin@fastmail.fm \
    --cc=64089@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=jschmidt4gnu@vodafonemail.de \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).