259
|
1 ;;; ldap.el --- LDAP support for Emacs
|
|
2
|
|
3 ;; Copyright (C) 1997 Free Software Foundation, Inc.
|
|
4
|
|
5 ;; Author: Oscar Figueiredo <Oscar.Figueiredo@di.epfl.ch>
|
|
6 ;; Maintainer: Oscar Figueiredo <Oscar.Figueiredo@di.epfl.ch>
|
|
7 ;; Created: Jan 1998
|
361
|
8 ;; Version: $Revision: 1.9 $
|
259
|
9 ;; Keywords: help comm
|
|
10
|
|
11 ;; This file is part of XEmacs
|
|
12
|
|
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)
|
|
16 ;; any later version.
|
|
17
|
|
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.
|
|
22
|
|
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.
|
|
27
|
|
28 ;;; Commentary:
|
|
29 ;; This file provides mid-level and user-level functions to access directory
|
|
30 ;; servers using the LDAP protocol (RFC 1777).
|
|
31
|
|
32 ;;; Installation:
|
|
33 ;; LDAP support must have been built into XEmacs.
|
|
34
|
|
35
|
|
36 ;;; Code:
|
|
37
|
361
|
38 (eval-when '(load)
|
|
39 (if (not (fboundp 'ldap-open))
|
|
40 (error "No LDAP support compiled in this XEmacs")))
|
|
41
|
|
42 (defgroup ldap nil
|
|
43 "Lightweight Directory Access Protocol"
|
|
44 :group 'comm)
|
276
|
45
|
361
|
46 (defcustom ldap-default-host nil
|
|
47 "*Default LDAP server hostname.
|
|
48 A TCP port number can be appended to that name using a colon as
|
|
49 a separator."
|
|
50 :type '(choice (string :tag "Host name")
|
|
51 (const :tag "Use library default" nil))
|
|
52 :group 'ldap)
|
259
|
53
|
361
|
54 (defcustom ldap-default-port nil
|
|
55 "*Default TCP port for LDAP connections.
|
|
56 Initialized from the LDAP library at build time. Default value is 389."
|
|
57 :type '(choice (const :tag "Use library default" nil)
|
|
58 (integer :tag "Port number"))
|
|
59 :group 'ldap)
|
|
60
|
|
61 (defcustom ldap-default-base nil
|
|
62 "*Default base for LDAP searches.
|
|
63 This is a string using the syntax of RFC 1779.
|
|
64 For instance, \"o=ACME, c=US\" limits the search to the
|
|
65 Acme organization in the United States."
|
|
66 :type '(choice (const :tag "Use library default" nil)
|
|
67 (string :tag "Search base"))
|
|
68 :group 'ldap)
|
|
69
|
|
70
|
|
71 (defcustom ldap-host-parameters-alist nil
|
|
72 "*Alist of host-specific options for LDAP transactions.
|
|
73 The format of each list element is:
|
|
74 \(HOST PROP1 VAL1 PROP2 VAL2 ...)
|
|
75 HOST is the hostname of an LDAP server (with an optional TCP port number
|
|
76 appended to it using a colon as a separator).
|
|
77 PROPn and VALn are property/value pairs describing parameters for the server.
|
|
78 Valid properties include:
|
282
|
79 `binddn' is the distinguished name of the user to bind as
|
|
80 (in RFC 1779 syntax).
|
|
81 `passwd' is the password to use for simple authentication.
|
|
82 `auth' is the authentication method to use.
|
|
83 Possible values are: `simple', `krbv41' and `krbv42'.
|
|
84 `base' is the base for the search as described in RFC 1779.
|
|
85 `scope' is one of the three symbols `subtree', `base' or `onelevel'.
|
|
86 `deref' is one of the symbols `never', `always', `search' or `find'.
|
|
87 `timelimit' is the timeout limit for the connection in seconds.
|
361
|
88 `sizelimit' is the maximum number of matches to return."
|
|
89 :type '(repeat :menu-tag "Host parameters"
|
|
90 :tag "Host parameters"
|
|
91 (list :menu-tag "Host parameters"
|
|
92 :tag "Host parameters"
|
|
93 :value nil
|
|
94 (string :tag "Host name")
|
|
95 (checklist :inline t
|
|
96 :greedy t
|
|
97 (list
|
|
98 :tag "Search Base"
|
|
99 :inline t
|
|
100 (const :tag "Search Base" base)
|
|
101 string)
|
|
102 (list
|
|
103 :tag "Binding DN"
|
|
104 :inline t
|
|
105 (const :tag "Binding DN" binddn)
|
|
106 string)
|
|
107 (list
|
|
108 :tag "Password"
|
|
109 :inline t
|
|
110 (const :tag "Password" passwd)
|
|
111 string)
|
|
112 (list
|
|
113 :tag "Authentication Method"
|
|
114 :inline t
|
|
115 (const :tag "Authentication Method" auth)
|
|
116 (choice
|
|
117 (const :menu-tag "None" :tag "None" nil)
|
|
118 (const :menu-tag "Simple" :tag "Simple" simple)
|
|
119 (const :menu-tag "Kerberos 4.1" :tag "Kerberos 4.1" krbv41)
|
|
120 (const :menu-tag "Kerberos 4.2" :tag "Kerberos 4.2" krbv42)))
|
|
121 (list
|
|
122 :tag "Search Scope"
|
|
123 :inline t
|
|
124 (const :tag "Search Scope" scope)
|
|
125 (choice
|
|
126 (const :menu-tag "Default" :tag "Default" nil)
|
|
127 (const :menu-tag "Subtree" :tag "Subtree" subtree)
|
|
128 (const :menu-tag "Base" :tag "Base" base)
|
|
129 (const :menu-tag "One Level" :tag "One Level" onelevel)))
|
|
130 (list
|
|
131 :tag "Dereferencing"
|
|
132 :inline t
|
|
133 (const :tag "Dereferencing" deref)
|
|
134 (choice
|
|
135 (const :menu-tag "Default" :tag "Default" nil)
|
|
136 (const :menu-tag "Never" :tag "Never" never)
|
|
137 (const :menu-tag "Always" :tag "Always" always)
|
|
138 (const :menu-tag "When searching" :tag "When searching" search)
|
|
139 (const :menu-tag "When locating base" :tag "When locating base" find)))
|
|
140 (list
|
|
141 :tag "Time Limit"
|
|
142 :inline t
|
|
143 (const :tag "Time Limit" timelimit)
|
|
144 (integer :tag "(in seconds)"))
|
|
145 (list
|
|
146 :tag "Size Limit"
|
|
147 :inline t
|
|
148 (const :tag "Size Limit" sizelimit)
|
|
149 (integer :tag "(number of records)")))))
|
|
150 :group 'ldap)
|
259
|
151
|
|
152 (defun ldap-search (filter &optional host attributes attrsonly)
|
|
153 "Perform an LDAP search.
|
361
|
154 FILTER is the search filter in RFC1558 syntax, i.e., something that
|
|
155 looks like \"(cn=John Smith)\".
|
|
156 HOST is the LDAP host on which to perform the search.
|
|
157 ATTRIBUTES is a list of attributes to retrieve; nil means retrieve all.
|
|
158 If ATTRSONLY is non nil, the attributes will be retrieved without
|
259
|
159 the associated values.
|
|
160 Additional search parameters can be specified through
|
298
|
161 `ldap-host-parameters-alist' which see."
|
259
|
162 (interactive "sFilter:")
|
361
|
163 (or host
|
|
164 (setq host ldap-default-host)
|
|
165 (error "No LDAP host specified"))
|
|
166 (let ((host-plist (cdr (assoc host ldap-host-parameters-alist)))
|
|
167 ldap
|
|
168 res)
|
276
|
169 (message "Opening LDAP connection to %s..." host)
|
282
|
170 (setq ldap (ldap-open host host-plist))
|
276
|
171 (message "Searching with LDAP on %s..." host)
|
|
172 (setq res (ldap-search-internal ldap filter
|
282
|
173 (plist-get host-plist 'base)
|
|
174 (plist-get host-plist 'scope)
|
276
|
175 attributes attrsonly))
|
|
176 (ldap-close ldap)
|
|
177 res))
|
259
|
178
|
|
179
|
|
180 (provide 'ldap)
|
|
181
|
|
182 ;;; ldap.el ends here
|