X-Git-Url: http://cgit.sxemacs.org/?p=gnus;a=blobdiff_plain;f=lisp%2Fsmime-ldap.el;h=66ae9c5de4dc2ca3ff2a976f1474b75aa3620228;hp=01dec0e57e19700a9fa7f8c37c9083b29356dcfc;hb=94f288135f95ca48fb50f5aa43bc09f9669c5c23;hpb=58ecb7a74c5112d729b0aee2a5ac0add737b7caf diff --git a/lisp/smime-ldap.el b/lisp/smime-ldap.el index 01dec0e57..66ae9c5de 100644 --- a/lisp/smime-ldap.el +++ b/lisp/smime-ldap.el @@ -11,7 +11,7 @@ ;; GNU Emacs is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by -;; the Free Software Foundation; either version 2, or (at your option) +;; the Free Software Foundation; either version 3, or (at your option) ;; any later version. ;; GNU Emacs is distributed in the hope that it will be useful, @@ -20,9 +20,7 @@ ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License -;; along with GNU Emacs; see the file COPYING. If not, write to the -;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, -;; Boston, MA 02111-1307, USA. +;; along with GNU Emacs. If not, see . ;;; Commentary: @@ -31,71 +29,50 @@ ;; made to achieve compatibility with OpenLDAP v2 and to make it ;; possible to retrieve LDAP attributes that are tagged ie ";binary". -;; When Gnus drops support for Emacs 21.x this file can be removed and -;; smime.el changed to - -;; - (require 'smime-ldap) => (require 'ldap) -;; - (smime-ldap-search ...) => (ldap-search ...) - -;; If we are running in Emacs 22 or newer it just uses the build-in -;; version of ldap-search. +;; The file also adds a compatibility layer for Emacs and XEmacs. ;;; Code: -(load-library "net/ldap") +(require 'ldap) (defun smime-ldap-search (filter &optional host attributes attrsonly withdn) "Perform an LDAP search. FILTER is the search filter in RFC1558 syntax. HOST is the LDAP host on which to perform the search. -ATTRIBUTES are the specific attributes to retrieve, nil means +ATTRIBUTES are the specific attributes to retrieve, nil means retrieve all. -ATTRSONLY, if non-nil, retrieves the attributes only, without +ATTRSONLY, if non-nil, retrieves the attributes only, without the associated values. If WITHDN is non-nil, each entry in the result will be prepended with its distinguished name WITHDN. -Additional search parameters can be specified through +Additional search parameters can be specified through `ldap-host-parameters-alist', which see." (interactive "sFilter:") - (if (>= emacs-major-version 22) - (ldap-search filter host attributes attrsonly) - (or host - (setq host ldap-default-host) - (error "No LDAP host specified")) - (let ((host-plist (cdr (assoc host ldap-host-parameters-alist))) - result) - (setq result (smime-ldap-search-internal (append host-plist - (list 'host host - 'filter filter - 'attributes attributes - 'attrsonly attrsonly - 'withdn withdn)))) - (if ldap-ignore-attribute-codings - result - (mapcar (function - (lambda (record) - (mapcar 'ldap-decode-attribute record))) - result))))) + ;; for XEmacs + (if (fboundp 'ldap-search-entries) + (ldap-search-entries filter host attributes attrsonly) + ;; for Emacs + (cdr (ldap-search filter host attributes attrsonly)))) (defun smime-ldap-search-internal (search-plist) "Perform a search on a LDAP server. SEARCH-PLIST is a property list describing the search request. Valid keys in that list are: - `host' is a string naming one or more (blank-separated) LDAP servers to +`host' is a string naming one or more (blank-separated) LDAP servers to to try to connect to. Each host name may optionally be of the form HOST:PORT. - `filter' is a filter string for the search as described in RFC 1558. - `attributes' is a list of strings indicating which attributes to retrieve +`filter' is a filter string for the search as described in RFC 1558. +`attributes' is a list of strings indicating which attributes to retrieve for each matching entry. If nil, return all available attributes. - `attrsonly', if non-nil, indicates that only attributes are retrieved, +`attrsonly', if non-nil, indicates that only attributes are retrieved, not their associated values. - `base' is the base for the search as described in RFC 1779. - `scope' is one of the three symbols `sub', `base' or `one'. - `binddn' is the distinguished name of the user to bind as (in RFC 1779 syntax). - `passwd' is the password to use for simple authentication. - `deref' is one of the symbols `never', `always', `search' or `find'. - `timelimit' is the timeout limit for the connection in seconds. - `sizelimit' is the maximum number of matches to return. - `withdn' if non-nil each entry in the result will be prepended with +`base' is the base for the search as described in RFC 1779. +`scope' is one of the three symbols `sub', `base' or `one'. +`binddn' is the distinguished name of the user to bind as (in RFC 1779 syntax). +`passwd' is the password to use for simple authentication. +`deref' is one of the symbols `never', `always', `search' or `find'. +`timelimit' is the timeout limit for the connection in seconds. +`sizelimit' is the maximum number of matches to return. +`withdn' if non-nil each entry in the result will be prepended with its distinguished name DN. The function returns a list of matching entries. Each entry is itself an alist of attribute/value pairs." @@ -121,8 +98,7 @@ an alist of attribute/value pairs." (equal "" filter)) (error "No search filter")) (setq filter (cons filter attributes)) - (save-excursion - (set-buffer buf) + (with-current-buffer buf (erase-buffer) (if (and host (not (equal "" host))) @@ -178,11 +154,11 @@ an alist of attribute/value pairs." (end-of-line) (point)))) (forward-line 1) - (while (looking-at "^\\(\\w*\\)\\(;\\w*\\)?[=:\t ]+\\(<[\t ]*file://\\)?\\(.*\\)$") + (while (looking-at (concat "^\\(\\w*\\)\\(;\\w*\\)?[=:\t ]+" + "\\(<[\t ]*file://\\)?\\(.*\\)$")) (setq name (match-string 1) value (match-string 4)) - (save-excursion - (set-buffer bufval) + (with-current-buffer bufval (erase-buffer) (insert-file-contents-literally value) (delete-file value)