Subject: 30.0.50; EUDC: stop adding a wildcard to LDAP searches

From: Fabrice Bauzac-Stehly <[email-masked]>
Date: Sat, 08 Apr 2023 09:20:36 +0200

Hello,

I use EUDC to search entries from LDAP.  I routinely search for a
username to retrieve the email address.  The LDAP server contains lots
of entries, and a username is often a prefix of lots of other usernames.
For example, when I search for the "js" username, I don't want to have
dozens of results of usernames that just start with "js" like "jsmith"
or "jscott".

However, that's what eudcb-ldap does: for reasons I don't understand,
the eudc-ldap-format-query-as-rfc1558 defun automatically appends the
wildcard character "*" to the last field.  This is annoying as I get
dozens of results.  I want to have the choice of adding a wildcard or
not to my searches, I don't want that imposed on me.

I propose the attached patch to fix this behaviour.  The result is a
simplification of the existing code.  Could you please review it?

>From 128e243175763606c73cb23beea0b0b25739ce2d Mon Sep 17 00:00:00 2001
From: Fabrice Bauzac <[email-masked]>
Date: Fri, 13 Jan 2023 15:44:35 +0100
Subject: [PATCH] Don't add a wildcard to LDAP query items

lisp/net/eudcb-ldap.el (eudc-ldap-format-query-as-rfc1558): don't add
an arbitrary wildcard to the last query item.
---
 lisp/net/eudcb-ldap.el | 22 +++++++---------------
 1 file changed, 7 insertions(+), 15 deletions(-)

diff --git a/lisp/net/eudcb-ldap.el b/lisp/net/eudcb-ldap.el
index b1733e99f5c..f39df13c391 100644
--- a/lisp/net/eudcb-ldap.el
+++ b/lisp/net/eudcb-ldap.el
@@ -174,21 +174,13 @@ eudc-ldap-escape-query-special-chars
 
 (defun eudc-ldap-format-query-as-rfc1558 (query)
   "Format the EUDC QUERY list as a RFC1558 LDAP search filter."
-  (let ((formatter
-         (lambda (item &optional wildcard)
-	   (format "(%s=%s)"
-		   (car item)
-		   (concat
-		    (eudc-ldap-escape-query-special-chars
-		     (cdr item))
-                    (if (and wildcard
-                             (not (memq (car item)
-                                        eudc-ldap-no-wildcard-attributes)))
-                        "*" ""))))))
-    (format "(&%s)"
-	    (concat
-	     (mapconcat formatter (butlast query) "")
-	     (funcall formatter (car (last query)) t)))))
+  (let ((formatter (lambda (item)
+		     (format "(%s=%s)"
+			     (car item)
+			     (concat
+			      (eudc-ldap-escape-query-special-chars
+			       (cdr item)))))))
+    (format "(&%s)" (mapconcat formatter query ""))))
 
 ;;}}}
 
-- 
2.25.1

In GNU Emacs 30.0.50 (build 1, x86_64-pc-linux-gnu, cairo version
 1.16.0) of 2023-03-07 built on ncelrnd2571
Repository revision: 4e8b50ec57bc0d70bdb1279756eec679eb4eab0d
Repository branch: HEAD
Windowing system distributor 'The X.Org Foundation', version 11.0.12013000
System Description: Ubuntu 20.04.6 LTS

Configured using:
 'configure -C --with-x-toolkit=no'

Configured features:
ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GPM GSETTINGS HARFBUZZ JPEG
LCMS2 LIBOTF LIBSELINUX LIBSYSTEMD LIBXML2 M17N_FLT MODULES NOTIFY
INOTIFY OLDXMENU PDUMPER PNG RSVG SECCOMP SOUND THREADS TIFF X11 XDBE
XIM XINPUT2 XPM ZLIB

Important settings:
  value of $LC_MONETARY: fr_FR.UTF-8
  value of $LC_NUMERIC: fr_FR.UTF-8
  value of $LC_TIME: C.UTF-8
  value of $LANG: en_US.UTF-8
  value of $XMODIFIERS: @im=ibus
  locale-coding-system: utf-8-unix

Major mode: Outline

Minor modes in effect:
  bug-reference-mode: t
  global-git-commit-mode: t
  magit-auto-revert-mode: t
  auto-revert-mode: t
  shell-dirtrack-mode: t
  electric-pair-mode: t
  server-mode: t
  tooltip-mode: t
  global-eldoc-mode: t
  show-paren-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  line-number-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t

Load-path shadows:
/home/fbauzac/.emacs.d/shared/el/1a-snipit hides /home/fbauzac/.emacs.d/elpa/1a-snipit-1.0/1a-snipit
/home/fbauzac/.emacs.d/elpa/transient-0.3.7/transient hides /home/fbauzac/git/emacs-master-2023-03-07/lisp/transient

Features:
(shadow sort mail-extr emacsbug magit-patch magit-subtree magit-extras
magit-gitignore magit-ediff ediff ediff-merg ediff-mult ediff-wind
ediff-diff ediff-help ediff-init ediff-util dcl-mode tempo conf-mode
genpass vc-hg vc-bzr vc-src vc-sccs vc-svn vc-cvs vc-rcs log-view vc
bug-reference face-remap cal-iso cal-move tabify man goto-addr
network-stream url-cache 1a-snipit dired-aux pcmpl-unix my-present
webjump godjira whitespace org-element org-persist org-id org-refile
avl-tree generator oc-basic ol-eww eww xdg url-queue mm-url ol-rmail
ol-mhe ol-irc ol-info ol-gnus nnselect gnus-art mm-uu mml2015 mm-view
mml-smime smime gnutls dig gnus-sum shr pixel-fill kinsoku url-file svg
dom gnus-group gnus-undo gnus-start gnus-dbus gnus-cloud nnimap nnmail
mail-source utf7 nnoo parse-time gnus-spec gnus-int gnus-range gnus-win
ol-docview doc-view image-mode exif ol-bibtex bibtex iso8601 ol-bbdb
ol-w3m ol-doi org-link-doi org ob ob-tangle ob-ref ob-lob ob-table
ob-exp org-macro org-src ob-comint org-pcomplete org-list org-footnote
org-faces org-entities ob-emacs-lisp ob-core ob-eval org-cycle org-table
ol org-fold org-fold-core org-keys oc org-loaddefs org-version
org-compat org-macs my-shell epa-file url-http url-auth url-gw nsm
secrets dbus xml kinit jka-compr my-timeline ert ewoc calc-arith dabbrev
apropos files-x anyconnect shortdoc copyright char-fold misearch
multi-isearch help-fns radix-tree cl-print debug backtrace find-func
cus-start my-host-resolve fb-jira-menu aproach bms mule-util cal-china
lunar solar cal-dst cal-islam holidays holiday-loaddefs vc-git
vc-dispatcher appt diary-lib diary-loaddefs cal-menu calendar
cal-loaddefs find-lisp filecache my-magit magit-submodule magit-obsolete
magit-blame magit-stash magit-reflog magit-bisect magit-push magit-pull
magit-fetch magit-clone magit-remote magit-commit magit-sequence
magit-notes magit-worktree magit-tag magit-merge magit-branch
magit-reset magit-files magit-refs magit-status magit magit-repos
magit-apply magit-wip magit-log which-func imenu magit-diff smerge-mode
diff diff-mode easy-mmode git-commit log-edit message sendmail
yank-media puny dired dired-loaddefs rfc822 mml mml-sec epa epg rfc6068
epg-config mm-decode mm-bodies mm-encode mail-parse rfc2231 rfc2047
rfc2045 ietf-drums mailabbrev gmm-utils mailheader pcvs-util add-log
magit-core magit-autorevert autorevert filenotify magit-margin
magit-transient magit-process with-editor shell pcomplete magit-mode
transient cl-extra edmacro kmacro help-mode format-spec magit-git
magit-section magit-utils crm dash my-bazel my-skeletons skeleton
sh-script smie executable cc-mode cc-fonts cc-guess cc-menus cc-cmds
cc-styles cc-align cc-engine cc-vars cc-defs python rx project pcase
treesit comint ansi-osc ring ansi-color ibuf-macs ibuffer
ibuffer-loaddefs calc-prog calc-ext calc calc-loaddefs rect calc-macs
gnus nnheader gnus-util text-property-search time-date mail-utils range
mm-util mail-prsvr elec-pair delsel eudcb-ldap ldap eudc
eudc-options-file eudc-vars auth-source-pass server jira-markup-mode
derived thingatpt noutline outline cus-edit pp cus-load icons wid-edit
info package browse-url url url-proxy url-privacy url-expand url-methods
url-history url-cookie generate-lisp-file url-domsuf url-util mailcap
url-handlers url-parse auth-source cl-seq eieio eieio-core cl-macs
password-cache json subr-x map byte-opt gv bytecomp byte-compile
url-vars cl-loaddefs cl-lib rmc iso-transl tooltip cconv eldoc paren
electric uniquify ediff-hook vc-hooks lisp-float-type elisp-mode mwheel
term/x-win x-win term/common-win x-dnd tool-bar dnd fontset image
regexp-opt fringe tabulated-list replace newcomment text-mode lisp-mode
prog-mode register page tab-bar menu-bar rfn-eshadow isearch easymenu
timer select scroll-bar mouse jit-lock font-lock syntax font-core
term/tty-colors frame minibuffer nadvice seq simple cl-generic
indonesian philippine cham georgian utf-8-lang misc-lang vietnamese
tibetan thai tai-viet lao korean japanese eucjp-ms cp51932 hebrew greek
romanian slovak czech european ethiopic indian cyrillic chinese
composite emoji-zwj charscript charprop case-table epa-hook
jka-cmpr-hook help abbrev obarray oclosure cl-preloaded button loaddefs
theme-loaddefs faces cus-face macroexp files window text-properties
overlay sha1 md5 base64 format env code-pages mule custom widget keymap
hashtable-print-readable backquote threads dbusbind inotify lcms2
dynamic-setting system-font-setting font-render-setting cairo xinput2 x
multi-tty make-network-process emacs)

Memory information:
((conses 16 690616 125578)
 (symbols 48 38019 3)
 (strings 32 161896 18152)
 (string-bytes 1 5147041)
 (vectors 16 85900)
 (vector-slots 8 1803819 116939)
 (floats 8 919 748)
 (intervals 56 42691 2868)
 (buffers 976 77))

-- 
Fabrice Bauzac-Stehly
PGP 01EEACF8244E9C14B551C5256ADA5F189BD322B6