annotate lisp/ldap.el @ 361:7347b34c275b r21-1-10

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