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.2 $
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."
44 :type '(choice (string :tag "Host name")
45 (const :tag "Use library default" nil))
48 (defcustom ldap-default-port nil
49 "*Default TCP port for LDAP connections.
50 Initialized from the LDAP library at build time. Default value is 389."
51 :type '(choice (const :tag "Use library default" nil)
52 (integer :tag "Port number"))
55 (defcustom ldap-default-base nil
56 "*Default base for LDAP searches.
57 This is a string using the syntax of RFC 1779.
58 For instance, \"o=ACME, c=US\" limits the search to the
59 Acme organization in the United States."
60 :type '(choice (const :tag "Use library default" nil)
61 (string :tag "Search base"))
65 (defcustom ldap-host-parameters-alist nil
66 "*Alist of host-specific options for LDAP transactions.
67 The format of each list element is:
68 \(HOST PROP1 VAL1 PROP2 VAL2 ...)
69 HOST is the name of an LDAP server. PROPn and VALn are property/value
70 pairs describing parameters for the server. Valid properties include:
71 `binddn' is the distinguished name of the user to bind as
73 `passwd' is the password to use for simple authentication.
74 `auth' is the authentication method to use.
75 Possible values are: `simple', `krbv41' and `krbv42'.
76 `base' is the base for the search as described in RFC 1779.
77 `scope' is one of the three symbols `subtree', `base' or `onelevel'.
78 `deref' is one of the symbols `never', `always', `search' or `find'.
79 `timelimit' is the timeout limit for the connection in seconds.
80 `sizelimit' is the maximum number of matches to return."
81 :type '(repeat :menu-tag "Host parameters"
82 :tag "Host parameters"
83 (list :menu-tag "Host parameters"
84 :tag "Host parameters"
86 (string :tag "Host name")
92 (const :tag "Binding DN" binddn)
97 (const :tag "Password" passwd)
100 :tag "Authentication Method"
102 (const :tag "Authentication Method" auth)
104 (const :menu-tag "None" :tag "None" nil)
105 (const :menu-tag "Simple" :tag "Simple" simple)
106 (const :menu-tag "Kerberos 4.1" :tag "Kerberos 4.1" krbv41)
107 (const :menu-tag "Kerberos 4.2" :tag "Kerberos 4.2" krbv42)))
111 (const :tag "Search Base" base)
116 (const :tag "Search Scope" scope)
118 (const :menu-tag "Default" :tag "Default" nil)
119 (const :menu-tag "Subtree" :tag "Subtree" subtree)
120 (const :menu-tag "Base" :tag "Base" base)
121 (const :menu-tag "One Level" :tag "One Level" onelevel)))
125 (const :tag "Dereferencing" deref)
127 (const :menu-tag "Default" :tag "Default" nil)
128 (const :menu-tag "Never" :tag "Never" never)
129 (const :menu-tag "Always" :tag "Always" always)
130 (const :menu-tag "When searching" :tag "When searching" search)
131 (const :menu-tag "When locating base" :tag "When locating base" find)))
135 (const :tag "Time Limit" timelimit)
136 (integer :tag "(in seconds)"))
140 (const :tag "Size Limit" sizelimit)
141 (integer :tag "(number of records)")))))
145 (defun ldap-search (filter &optional host attributes attrsonly)
146 "Perform an LDAP search.
147 FILTER is the search filter in RFC1558 syntax, i.e. something that
148 looks like \"(cn=John Smith)\".
149 HOST is the LDAP host on which to perform the search.
150 ATTRIBUTES is a list of attributes to retrieve; nil means retrieve all.
151 If ATTRSONLY is non nil, the attributes will be retrieved without
152 the associated values.
153 Additional search parameters can be specified through
154 `ldap-host-parameters-alist' which see."
155 (interactive "sFilter:")
157 (setq host ldap-default-host))
159 (error "No LDAP host specified"))
160 (let ((host-plist (cdr (assoc host ldap-host-parameters-alist)))
162 (message "Opening LDAP connection to %s..." host)
163 (setq ldap (ldap-open host host-plist))
164 (message "Searching with LDAP on %s..." host)
165 (prog1 (ldap-search-internal ldap filter
166 (plist-get host-plist 'base)
167 (plist-get host-plist 'scope)
168 attributes attrsonly)
173 ;;; ldap.el ends here