1 ;;; ldap.el --- LDAP support for Emacs
3 ;; Copyright (C) 1997 Free Software Foundation, Inc.
5 ;; Author: Oscar Figueiredo <Oscar.Figueiredo@di.epfl.ch>
6 ;; Maintainer: Oscar Figueiredo <Oscar.Figueiredo@di.epfl.ch>
8 ;; Version: $Revision: 1.7.2.3 $
11 ;; This file is part of XEmacs
13 ;; XEmacs is free software; you can redistribute it and/or modify it
14 ;; under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation; either version 2, or (at your option)
18 ;; XEmacs is distributed in the hope that it will be useful, but
19 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 ;; General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with XEmacs; see the file COPYING. If not, write to
25 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
26 ;; Boston, MA 02111-1307, USA.
29 ;; This file provides mid-level and user-level functions to access directory
30 ;; servers using the LDAP protocol (RFC 1777).
33 ;; LDAP support must have been built into XEmacs.
39 "Lightweight Directory Access Protocol"
42 (defcustom ldap-default-host nil
43 "*Default LDAP server hostname.
44 A TCP port number can be appended to that name using a colon as
46 :type '(choice (string :tag "Host name")
47 (const :tag "Use library default" nil))
50 (defcustom ldap-default-port nil
51 "*Default TCP port for LDAP connections.
52 Initialized from the LDAP library at build time. Default value is 389."
53 :type '(choice (const :tag "Use library default" nil)
54 (integer :tag "Port number"))
57 (defcustom ldap-default-base nil
58 "*Default base for LDAP searches.
59 This is a string using the syntax of RFC 1779.
60 For instance, \"o=ACME, c=US\" limits the search to the
61 Acme organization in the United States."
62 :type '(choice (const :tag "Use library default" nil)
63 (string :tag "Search base"))
67 (defcustom ldap-host-parameters-alist nil
68 "*Alist of host-specific options for LDAP transactions.
69 The format of each list element is:
70 \(HOST PROP1 VAL1 PROP2 VAL2 ...)
71 HOST is the hostname of an LDAP server (with an optional TCP port number
72 appended to it using a colon as a separator).
73 PROPn and VALn are property/value pairs describing parameters for the server.
74 Valid properties include:
75 `binddn' is the distinguished name of the user to bind as
77 `passwd' is the password to use for simple authentication.
78 `auth' is the authentication method to use.
79 Possible values are: `simple', `krbv41' and `krbv42'.
80 `base' is the base for the search as described in RFC 1779.
81 `scope' is one of the three symbols `subtree', `base' or `onelevel'.
82 `deref' is one of the symbols `never', `always', `search' or `find'.
83 `timelimit' is the timeout limit for the connection in seconds.
84 `sizelimit' is the maximum number of matches to return."
85 :type '(repeat :menu-tag "Host parameters"
86 :tag "Host parameters"
87 (list :menu-tag "Host parameters"
88 :tag "Host parameters"
90 (string :tag "Host name")
96 (const :tag "Search Base" base)
101 (const :tag "Binding DN" binddn)
106 (const :tag "Password" passwd)
109 :tag "Authentication Method"
111 (const :tag "Authentication Method" auth)
113 (const :menu-tag "None" :tag "None" nil)
114 (const :menu-tag "Simple" :tag "Simple" simple)
115 (const :menu-tag "Kerberos 4.1" :tag "Kerberos 4.1" krbv41)
116 (const :menu-tag "Kerberos 4.2" :tag "Kerberos 4.2" krbv42)))
120 (const :tag "Search Scope" scope)
122 (const :menu-tag "Default" :tag "Default" nil)
123 (const :menu-tag "Subtree" :tag "Subtree" subtree)
124 (const :menu-tag "Base" :tag "Base" base)
125 (const :menu-tag "One Level" :tag "One Level" onelevel)))
129 (const :tag "Dereferencing" deref)
131 (const :menu-tag "Default" :tag "Default" nil)
132 (const :menu-tag "Never" :tag "Never" never)
133 (const :menu-tag "Always" :tag "Always" always)
134 (const :menu-tag "When searching" :tag "When searching" search)
135 (const :menu-tag "When locating base" :tag "When locating base" find)))
139 (const :tag "Time Limit" timelimit)
140 (integer :tag "(in seconds)"))
144 (const :tag "Size Limit" sizelimit)
145 (integer :tag "(number of records)")))))
148 (defun ldap-get-host-parameter (host parameter)
149 "Get the value of PARAMETER for HOST in `ldap-host-parameters-alist'."
150 (plist-get (cdr (assoc host ldap-host-parameters-alist))
153 (defun ldap-search (filter &optional host attributes attrsonly withdn)
154 "Perform an LDAP search.
155 FILTER is the search filter in RFC1558 syntax, i.e. something that
156 looks like \"(cn=John Smith)\".
157 HOST is the LDAP host on which to perform the search.
158 ATTRIBUTES is a list of attributes to retrieve; nil means retrieve all.
159 If ATTRSONLY is non nil, the attributes will be retrieved without
160 the associated values.
161 If WITHDN is non-nil each entry in the result will be prepennded with
162 its distinguished name DN.
163 Additional search parameters can be specified through
164 `ldap-host-parameters-alist' which see.
165 The function returns a list of matching entries. Each entry is itself
166 an alist of attribute/value pairs optionally preceded by the DN of the
167 entry according to the value of WITHDN."
168 (interactive "sFilter:")
170 (setq host ldap-default-host))
172 (error "No LDAP host specified"))
173 (let ((host-plist (cdr (assoc host ldap-host-parameters-alist)))
175 (message "Opening LDAP connection to %s..." host)
176 (setq ldap (ldap-open host host-plist))
177 (message "Searching with LDAP on %s..." host)
178 (prog1 (ldap-search-internal ldap filter
179 (plist-get host-plist 'base)
180 (plist-get host-plist 'scope)
181 attributes attrsonly withdn)
186 ;;; ldap.el ends here