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.
42 "Lightweight Directory Access Protocol"
45 (defcustom ldap-default-host nil
46 "*Default LDAP server."
47 :type '(choice (string :tag "Host name")
48 (const :tag "Use library default" nil))
51 (defcustom ldap-default-port nil
52 "*Default TCP port for LDAP connections.
53 Initialized from the LDAP library at build time. Default value is 389."
54 :type '(choice (const :tag "Use library default" nil)
55 (integer :tag "Port number"))
58 (defcustom ldap-default-base nil
59 "*Default base for LDAP searches.
60 This is a string using the syntax of RFC 1779.
61 For instance, \"o=ACME, c=US\" limits the search to the
62 Acme organization in the United States."
63 :type '(choice (const :tag "Use library default" nil)
64 (string :tag "Search base"))
68 (defcustom ldap-host-parameters-alist nil
69 "*Alist of host-specific options for LDAP transactions.
70 The format of each list element is:
71 \(HOST PROP1 VAL1 PROP2 VAL2 ...)
72 HOST is the name of an LDAP server. PROPn and VALn are property/value
73 pairs describing parameters for the server. Valid properties include:
74 `binddn' is the distinguished name of the user to bind as
76 `passwd' is the password to use for simple authentication.
77 `auth' is the authentication method to use.
78 Possible values are: `simple', `krbv41' and `krbv42'.
79 `base' is the base for the search as described in RFC 1779.
80 `scope' is one of the three symbols `subtree', `base' or `onelevel'.
81 `deref' is one of the symbols `never', `always', `search' or `find'.
82 `timelimit' is the timeout limit for the connection in seconds.
83 `sizelimit' is the maximum number of matches to return."
84 :type '(repeat :menu-tag "Host parameters"
85 :tag "Host parameters"
86 (list :menu-tag "Host parameters"
87 :tag "Host parameters"
89 (string :tag "Host name")
95 (const :tag "Binding DN" binddn)
100 (const :tag "Password" passwd)
103 :tag "Authentication Method"
105 (const :tag "Authentication Method" auth)
107 (const :menu-tag "None" :tag "None" nil)
108 (const :menu-tag "Simple" :tag "Simple" simple)
109 (const :menu-tag "Kerberos 4.1" :tag "Kerberos 4.1" krbv41)
110 (const :menu-tag "Kerberos 4.2" :tag "Kerberos 4.2" krbv42)))
114 (const :tag "Search Base" base)
119 (const :tag "Search Scope" scope)
121 (const :menu-tag "Default" :tag "Default" nil)
122 (const :menu-tag "Subtree" :tag "Subtree" subtree)
123 (const :menu-tag "Base" :tag "Base" base)
124 (const :menu-tag "One Level" :tag "One Level" onelevel)))
128 (const :tag "Dereferencing" deref)
130 (const :menu-tag "Default" :tag "Default" nil)
131 (const :menu-tag "Never" :tag "Never" never)
132 (const :menu-tag "Always" :tag "Always" always)
133 (const :menu-tag "When searching" :tag "When searching" search)
134 (const :menu-tag "When locating base" :tag "When locating base" find)))
138 (const :tag "Time Limit" timelimit)
139 (integer :tag "(in seconds)"))
143 (const :tag "Size Limit" sizelimit)
144 (integer :tag "(number of records)")))))
148 (defun ldap-search (filter &optional host attributes attrsonly)
149 "Perform an LDAP search.
150 FILTER is the search filter in RFC1558 syntax, i.e. something that
151 looks like \"(cn=John Smith)\".
152 HOST is the LDAP host on which to perform the search.
153 ATTRIBUTES is a list of attributes to retrieve; nil means retrieve all.
154 If ATTRSONLY is non nil, the attributes will be retrieved without
155 the associated values.
156 Additional search parameters can be specified through
157 `ldap-host-parameters-alist' which see."
158 (interactive "sFilter:")
160 (setq host ldap-default-host))
162 (error "No LDAP host specified"))
163 (let ((host-plist (cdr (assoc host ldap-host-parameters-alist)))
165 (message "Opening LDAP connection to %s..." host)
166 (setq ldap (ldap-open host host-plist))
167 (message "Searching with LDAP on %s..." host)
168 (prog1 (ldap-search-internal ldap filter
169 (plist-get host-plist 'base)
170 (plist-get host-plist 'scope)
171 attributes attrsonly)
174 ;;; ldap.el ends here