Mercurial > emacs
annotate lisp/net/ldap.el @ 62778:75fa29e46766
(display-time-string-forms, display-time-update):
Use mode-line-highlight as mouse-face.
author | Luc Teirlinck <teirllm@auburn.edu> |
---|---|
date | Thu, 26 May 2005 20:43:39 +0000 |
parents | df55e63482c4 |
children | 18a818a2ee7c f042e7c0fe20 |
rev | line source |
---|---|
38422
7a94f1c588c4
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
33930
diff
changeset
|
1 ;;; ldap.el --- client interface to LDAP for Emacs |
27313 | 2 |
62437
df55e63482c4
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
59941
diff
changeset
|
3 ;; Copyright (C) 1998, 1999, 2000, 2002, 2005 Free Software Foundation, Inc. |
27313 | 4 |
42607
033986c328d5
New maintainer. New e-mail address of the author.
Pavel Janík <Pavel@Janik.cz>
parents:
42579
diff
changeset
|
5 ;; Author: Oscar Figueiredo <oscar@cpe.fr> |
59941 | 6 ;; Maintainer: FSF |
27313 | 7 ;; Created: April 1998 |
8 ;; Keywords: comm | |
9 | |
10 ;; This file is part of GNU Emacs. | |
11 | |
12 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
13 ;; it under the terms of the GNU General Public License as published by | |
14 ;; the Free Software Foundation; either version 2, or (at your option) | |
15 ;; any later version. | |
16 | |
17 ;; GNU Emacs is distributed in the hope that it will be useful, | |
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 ;; GNU General Public License for more details. | |
21 | |
22 ;; You should have received a copy of the GNU General Public License | |
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
25 ;; Boston, MA 02111-1307, USA. | |
26 | |
27 ;;; Commentary: | |
28 | |
29 ;; This package provides basic functionality to perform searches on LDAP | |
42517
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
30 ;; servers. It requires a command line utility generally named |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
31 ;; `ldapsearch' to actually perform the searches. That program can be |
27313 | 32 ;; found in all LDAP developer kits such as: |
33 ;; - UM-LDAP 3.3 (http://www.umich.edu/~dirsvcs/ldap/) | |
34 ;; - OpenLDAP (http://www.openldap.org/) | |
35 | |
36 ;;; Code: | |
37 | |
38 (require 'custom) | |
54805
37581abcf761
(ldap-search): Use list*.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54359
diff
changeset
|
39 (eval-when-compile (require 'cl)) |
27313 | 40 |
41 (defgroup ldap nil | |
42 "Lightweight Directory Access Protocol." | |
33930 | 43 :version "21.1" |
27313 | 44 :group 'comm) |
45 | |
46 (defcustom ldap-default-host nil | |
47 "*Default LDAP server. | |
42517
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
48 A TCP port number can be appended to that name using a colon as |
27313 | 49 a separator." |
50 :type '(choice (string :tag "Host name") | |
51 (const :tag "Use library default" nil)) | |
52 :group 'ldap) | |
53 | |
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 (HOST PROP1 VAL1 PROP2 VAL2 ...). | |
42573 | 74 HOST is the hostname of an LDAP server (with an optional TCP port number |
42517
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
75 appended to it using a colon as a separator). |
27313 | 76 PROPn and VALn are property/value pairs describing parameters for the server. |
42517
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
77 Valid properties include: |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
78 `binddn' is the distinguished name of the user to bind as |
27313 | 79 (in RFC 1779 syntax). |
80 `passwd' is the password to use for simple authentication. | |
42517
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
81 `auth' is the authentication method to use. |
27313 | 82 Possible values are: `simple', `krbv41' and `krbv42'. |
83 `base' is the base for the search as described in RFC 1779. | |
84 `scope' is one of the three symbols `subtree', `base' or `onelevel'. | |
85 `deref' is one of the symbols `never', `always', `search' or `find'. | |
86 `timelimit' is the timeout limit for the connection in seconds. | |
87 `sizelimit' is the maximum number of matches to return." | |
88 :type '(repeat :menu-tag "Host parameters" | |
89 :tag "Host parameters" | |
90 (list :menu-tag "Host parameters" | |
91 :tag "Host parameters" | |
92 :value nil | |
93 (string :tag "Host name") | |
94 (checklist :inline t | |
95 :greedy t | |
96 (list | |
42517
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
97 :tag "Search Base" |
27313 | 98 :inline t |
99 (const :tag "Search Base" base) | |
100 string) | |
101 (list | |
102 :tag "Binding DN" | |
103 :inline t | |
104 (const :tag "Binding DN" binddn) | |
105 string) | |
106 (list | |
107 :tag "Password" | |
108 :inline t | |
109 (const :tag "Password" passwd) | |
110 string) | |
111 (list | |
112 :tag "Authentication Method" | |
113 :inline t | |
114 (const :tag "Authentication Method" auth) | |
115 (choice | |
116 (const :menu-tag "None" :tag "None" nil) | |
117 (const :menu-tag "Simple" :tag "Simple" simple) | |
118 (const :menu-tag "Kerberos 4.1" :tag "Kerberos 4.1" krbv41) | |
119 (const :menu-tag "Kerberos 4.2" :tag "Kerberos 4.2" krbv42))) | |
120 (list | |
42517
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
121 :tag "Search Scope" |
27313 | 122 :inline t |
123 (const :tag "Search Scope" scope) | |
124 (choice | |
125 (const :menu-tag "Default" :tag "Default" nil) | |
126 (const :menu-tag "Subtree" :tag "Subtree" subtree) | |
127 (const :menu-tag "Base" :tag "Base" base) | |
128 (const :menu-tag "One Level" :tag "One Level" onelevel))) | |
129 (list | |
130 :tag "Dereferencing" | |
131 :inline t | |
132 (const :tag "Dereferencing" deref) | |
133 (choice | |
134 (const :menu-tag "Default" :tag "Default" nil) | |
135 (const :menu-tag "Never" :tag "Never" never) | |
136 (const :menu-tag "Always" :tag "Always" always) | |
137 (const :menu-tag "When searching" :tag "When searching" search) | |
138 (const :menu-tag "When locating base" :tag "When locating base" find))) | |
139 (list | |
140 :tag "Time Limit" | |
141 :inline t | |
142 (const :tag "Time Limit" timelimit) | |
143 (integer :tag "(in seconds)")) | |
144 (list | |
145 :tag "Size Limit" | |
146 :inline t | |
147 (const :tag "Size Limit" sizelimit) | |
148 (integer :tag "(number of records)"))))) | |
149 :group 'ldap) | |
150 | |
151 (defcustom ldap-ldapsearch-prog "ldapsearch" | |
152 "*The name of the ldapsearch command line program." | |
153 :type '(string :tag "`ldapsearch' Program") | |
154 :group 'ldap) | |
155 | |
42783
c1bb3d3c9621
(ldap-ldapsearch-prog): Default to OpenLDAP version 2 ldapsearch.
Pavel Janík <Pavel@Janik.cz>
parents:
42607
diff
changeset
|
156 (defcustom ldap-ldapsearch-args '("-LL" "-tt" "-x") |
c1bb3d3c9621
(ldap-ldapsearch-prog): Default to OpenLDAP version 2 ldapsearch.
Pavel Janík <Pavel@Janik.cz>
parents:
42607
diff
changeset
|
157 "*A list of additional arguments to pass to `ldapsearch'." |
27313 | 158 :type '(repeat :tag "`ldapsearch' Arguments" |
159 (string :tag "Argument")) | |
160 :group 'ldap) | |
161 | |
42517
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
162 (defcustom ldap-ignore-attribute-codings nil |
27313 | 163 "*If non-nil, do not encode/decode LDAP attribute values." |
164 :type 'boolean | |
165 :group 'ldap) | |
166 | |
167 (defcustom ldap-default-attribute-decoder nil | |
168 "*Decoder function to use for attributes whose syntax is unknown." | |
169 :type 'symbol | |
170 :group 'ldap) | |
171 | |
42517
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
172 (defcustom ldap-coding-system 'utf-8 |
27313 | 173 "*Coding system of LDAP string values. |
42517
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
174 LDAP v3 specifies the coding system of strings to be UTF-8." |
27313 | 175 :type 'symbol |
176 :group 'ldap) | |
177 | |
178 (defvar ldap-attribute-syntax-encoders | |
42517
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
179 [nil ; 1 ACI Item N |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
180 nil ; 2 Access Point Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
181 nil ; 3 Attribute Type Description Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
182 nil ; 4 Audio N |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
183 nil ; 5 Binary N |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
184 nil ; 6 Bit String Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
185 ldap-encode-boolean ; 7 Boolean Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
186 nil ; 8 Certificate N |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
187 nil ; 9 Certificate List N |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
188 nil ; 10 Certificate Pair N |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
189 ldap-encode-country-string ; 11 Country String Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
190 ldap-encode-string ; 12 DN Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
191 nil ; 13 Data Quality Syntax Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
192 nil ; 14 Delivery Method Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
193 ldap-encode-string ; 15 Directory String Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
194 nil ; 16 DIT Content Rule Description Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
195 nil ; 17 DIT Structure Rule Description Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
196 nil ; 18 DL Submit Permission Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
197 nil ; 19 DSA Quality Syntax Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
198 nil ; 20 DSE Type Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
199 nil ; 21 Enhanced Guide Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
200 nil ; 22 Facsimile Telephone Number Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
201 nil ; 23 Fax N |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
202 nil ; 24 Generalized Time Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
203 nil ; 25 Guide Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
204 nil ; 26 IA5 String Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
205 number-to-string ; 27 INTEGER Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
206 nil ; 28 JPEG N |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
207 nil ; 29 Master And Shadow Access Points Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
208 nil ; 30 Matching Rule Description Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
209 nil ; 31 Matching Rule Use Description Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
210 nil ; 32 Mail Preference Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
211 nil ; 33 MHS OR Address Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
212 nil ; 34 Name And Optional UID Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
213 nil ; 35 Name Form Description Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
214 nil ; 36 Numeric String Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
215 nil ; 37 Object Class Description Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
216 nil ; 38 OID Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
217 nil ; 39 Other Mailbox Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
218 nil ; 40 Octet String Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
219 ldap-encode-address ; 41 Postal Address Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
220 nil ; 42 Protocol Information Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
221 nil ; 43 Presentation Address Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
222 ldap-encode-string ; 44 Printable String Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
223 nil ; 45 Subtree Specification Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
224 nil ; 46 Supplier Information Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
225 nil ; 47 Supplier Or Consumer Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
226 nil ; 48 Supplier And Consumer Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
227 nil ; 49 Supported Algorithm N |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
228 nil ; 50 Telephone Number Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
229 nil ; 51 Teletex Terminal Identifier Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
230 nil ; 52 Telex Number Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
231 nil ; 53 UTC Time Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
232 nil ; 54 LDAP Syntax Description Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
233 nil ; 55 Modify Rights Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
234 nil ; 56 LDAP Schema Definition Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
235 nil ; 57 LDAP Schema Description Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
236 nil ; 58 Substring Assertion Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
237 ] |
27313 | 238 "A vector of functions used to encode LDAP attribute values. |
239 The sequence of functions corresponds to the sequence of LDAP attribute syntax | |
42517
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
240 object identifiers of the form 1.3.6.1.4.1.1466.1115.121.1.* as defined in |
27313 | 241 RFC2252 section 4.3.2") |
242 | |
243 (defvar ldap-attribute-syntax-decoders | |
42517
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
244 [nil ; 1 ACI Item N |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
245 nil ; 2 Access Point Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
246 nil ; 3 Attribute Type Description Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
247 nil ; 4 Audio N |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
248 nil ; 5 Binary N |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
249 nil ; 6 Bit String Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
250 ldap-decode-boolean ; 7 Boolean Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
251 nil ; 8 Certificate N |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
252 nil ; 9 Certificate List N |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
253 nil ; 10 Certificate Pair N |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
254 ldap-decode-string ; 11 Country String Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
255 ldap-decode-string ; 12 DN Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
256 nil ; 13 Data Quality Syntax Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
257 nil ; 14 Delivery Method Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
258 ldap-decode-string ; 15 Directory String Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
259 nil ; 16 DIT Content Rule Description Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
260 nil ; 17 DIT Structure Rule Description Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
261 nil ; 18 DL Submit Permission Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
262 nil ; 19 DSA Quality Syntax Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
263 nil ; 20 DSE Type Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
264 nil ; 21 Enhanced Guide Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
265 nil ; 22 Facsimile Telephone Number Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
266 nil ; 23 Fax N |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
267 nil ; 24 Generalized Time Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
268 nil ; 25 Guide Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
269 nil ; 26 IA5 String Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
270 string-to-number ; 27 INTEGER Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
271 nil ; 28 JPEG N |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
272 nil ; 29 Master And Shadow Access Points Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
273 nil ; 30 Matching Rule Description Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
274 nil ; 31 Matching Rule Use Description Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
275 nil ; 32 Mail Preference Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
276 nil ; 33 MHS OR Address Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
277 nil ; 34 Name And Optional UID Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
278 nil ; 35 Name Form Description Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
279 nil ; 36 Numeric String Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
280 nil ; 37 Object Class Description Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
281 nil ; 38 OID Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
282 nil ; 39 Other Mailbox Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
283 nil ; 40 Octet String Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
284 ldap-decode-address ; 41 Postal Address Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
285 nil ; 42 Protocol Information Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
286 nil ; 43 Presentation Address Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
287 ldap-decode-string ; 44 Printable String Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
288 nil ; 45 Subtree Specification Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
289 nil ; 46 Supplier Information Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
290 nil ; 47 Supplier Or Consumer Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
291 nil ; 48 Supplier And Consumer Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
292 nil ; 49 Supported Algorithm N |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
293 nil ; 50 Telephone Number Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
294 nil ; 51 Teletex Terminal Identifier Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
295 nil ; 52 Telex Number Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
296 nil ; 53 UTC Time Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
297 nil ; 54 LDAP Syntax Description Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
298 nil ; 55 Modify Rights Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
299 nil ; 56 LDAP Schema Definition Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
300 nil ; 57 LDAP Schema Description Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
301 nil ; 58 Substring Assertion Y |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
302 ] |
27313 | 303 "A vector of functions used to decode LDAP attribute values. |
304 The sequence of functions corresponds to the sequence of LDAP attribute syntax | |
42517
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
305 object identifiers of the form 1.3.6.1.4.1.1466.1115.121.1.* as defined in |
27313 | 306 RFC2252 section 4.3.2") |
307 | |
308 | |
309 (defvar ldap-attribute-syntaxes-alist | |
310 '((createtimestamp . 24) | |
311 (modifytimestamp . 24) | |
312 (creatorsname . 12) | |
313 (modifiersname . 12) | |
314 (subschemasubentry . 12) | |
315 (attributetypes . 3) | |
316 (objectclasses . 37) | |
317 (matchingrules . 30) | |
318 (matchingruleuse . 31) | |
319 (namingcontexts . 12) | |
320 (altserver . 26) | |
321 (supportedextension . 38) | |
322 (supportedcontrol . 38) | |
323 (supportedsaslmechanisms . 15) | |
324 (supportedldapversion . 27) | |
325 (ldapsyntaxes . 16) | |
326 (ditstructurerules . 17) | |
327 (nameforms . 35) | |
328 (ditcontentrules . 16) | |
329 (objectclass . 38) | |
330 (aliasedobjectname . 12) | |
331 (cn . 15) | |
332 (sn . 15) | |
333 (serialnumber . 44) | |
334 (c . 15) | |
335 (l . 15) | |
336 (st . 15) | |
337 (street . 15) | |
338 (o . 15) | |
339 (ou . 15) | |
340 (title . 15) | |
341 (description . 15) | |
342 (searchguide . 25) | |
343 (businesscategory . 15) | |
344 (postaladdress . 41) | |
345 (postalcode . 15) | |
346 (postofficebox . 15) | |
347 (physicaldeliveryofficename . 15) | |
348 (telephonenumber . 50) | |
349 (telexnumber . 52) | |
350 (telexterminalidentifier . 51) | |
351 (facsimiletelephonenumber . 22) | |
352 (x121address . 36) | |
353 (internationalisdnnumber . 36) | |
354 (registeredaddress . 41) | |
355 (destinationindicator . 44) | |
356 (preferreddeliverymethod . 14) | |
357 (presentationaddress . 43) | |
358 (supportedapplicationcontext . 38) | |
359 (member . 12) | |
360 (owner . 12) | |
361 (roleoccupant . 12) | |
362 (seealso . 12) | |
363 (userpassword . 40) | |
364 (usercertificate . 8) | |
365 (cacertificate . 8) | |
366 (authorityrevocationlist . 9) | |
367 (certificaterevocationlist . 9) | |
368 (crosscertificatepair . 10) | |
369 (name . 15) | |
370 (givenname . 15) | |
371 (initials . 15) | |
372 (generationqualifier . 15) | |
373 (x500uniqueidentifier . 6) | |
374 (dnqualifier . 44) | |
375 (enhancedsearchguide . 21) | |
376 (protocolinformation . 42) | |
377 (distinguishedname . 12) | |
378 (uniquemember . 34) | |
379 (houseidentifier . 15) | |
380 (supportedalgorithms . 49) | |
381 (deltarevocationlist . 9) | |
382 (dmdname . 15)) | |
383 "A map of LDAP attribute names to their type object id minor number. | |
384 This table is built from RFC2252 Section 5 and RFC2256 Section 5") | |
385 | |
386 | |
387 ;; Coding/decoding functions | |
388 | |
389 (defun ldap-encode-boolean (bool) | |
390 (if bool | |
391 "TRUE" | |
392 "FALSE")) | |
393 | |
394 (defun ldap-decode-boolean (str) | |
395 (cond | |
396 ((string-equal str "TRUE") | |
397 t) | |
398 ((string-equal str "FALSE") | |
399 nil) | |
400 (t | |
401 (error "Wrong LDAP boolean string: %s" str)))) | |
42517
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
402 |
27313 | 403 (defun ldap-encode-country-string (str) |
404 ;; We should do something useful here... | |
405 (if (not (= 2 (length str))) | |
406 (error "Invalid country string: %s" str))) | |
407 | |
408 (defun ldap-decode-string (str) | |
409 (decode-coding-string str ldap-coding-system)) | |
410 | |
411 (defun ldap-encode-string (str) | |
412 (encode-coding-string str ldap-coding-system)) | |
413 | |
414 (defun ldap-decode-address (str) | |
415 (mapconcat 'ldap-decode-string | |
416 (split-string str "\\$") | |
417 "\n")) | |
418 | |
419 (defun ldap-encode-address (str) | |
420 (mapconcat 'ldap-encode-string | |
421 (split-string str "\n") | |
422 "$")) | |
423 | |
424 | |
425 ;; LDAP protocol functions | |
42517
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
426 |
27313 | 427 (defun ldap-get-host-parameter (host parameter) |
428 "Get the value of PARAMETER for HOST in `ldap-host-parameters-alist'." | |
429 (plist-get (cdr (assoc host ldap-host-parameters-alist)) | |
430 parameter)) | |
42517
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
431 |
27313 | 432 (defun ldap-decode-attribute (attr) |
433 "Decode the attribute/value pair ATTR according to LDAP rules. | |
42517
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
434 The attribute name is looked up in `ldap-attribute-syntaxes-alist' |
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
435 and the corresponding decoder is then retrieved from |
27313 | 436 `ldap-attribute-syntax-decoders' and applied on the value(s)." |
437 (let* ((name (car attr)) | |
438 (values (cdr attr)) | |
439 (syntax-id (cdr (assq (intern (downcase name)) | |
440 ldap-attribute-syntaxes-alist))) | |
441 decoder) | |
442 (if syntax-id | |
443 (setq decoder (aref ldap-attribute-syntax-decoders | |
444 (1- syntax-id))) | |
445 (setq decoder ldap-default-attribute-decoder)) | |
446 (if decoder | |
447 (cons name (mapcar decoder values)) | |
448 attr))) | |
449 | |
450 (defun ldap-search (filter &optional host attributes attrsonly withdn) | |
451 "Perform an LDAP search. | |
452 FILTER is the search filter in RFC1558 syntax. | |
453 HOST is the LDAP host on which to perform the search. | |
42517
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
454 ATTRIBUTES are the specific attributes to retrieve, nil means |
27313 | 455 retrieve all. |
42517
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
456 ATTRSONLY, if non-nil, retrieves the attributes only, without |
27313 | 457 the associated values. |
458 If WITHDN is non-nil, each entry in the result will be prepended with | |
459 its distinguished name WITHDN. | |
42517
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
460 Additional search parameters can be specified through |
27313 | 461 `ldap-host-parameters-alist', which see." |
462 (interactive "sFilter:") | |
463 (or host | |
464 (setq host ldap-default-host) | |
465 (error "No LDAP host specified")) | |
466 (let ((host-plist (cdr (assoc host ldap-host-parameters-alist))) | |
467 result) | |
54805
37581abcf761
(ldap-search): Use list*.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54359
diff
changeset
|
468 (setq result (ldap-search-internal (list* 'host host |
37581abcf761
(ldap-search): Use list*.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54359
diff
changeset
|
469 'filter filter |
37581abcf761
(ldap-search): Use list*.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54359
diff
changeset
|
470 'attributes attributes |
37581abcf761
(ldap-search): Use list*.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54359
diff
changeset
|
471 'attrsonly attrsonly |
37581abcf761
(ldap-search): Use list*.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54359
diff
changeset
|
472 'withdn withdn |
37581abcf761
(ldap-search): Use list*.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54359
diff
changeset
|
473 host-plist))) |
27313 | 474 (if ldap-ignore-attribute-codings |
475 result | |
54805
37581abcf761
(ldap-search): Use list*.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54359
diff
changeset
|
476 (mapcar (lambda (record) |
37581abcf761
(ldap-search): Use list*.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54359
diff
changeset
|
477 (mapcar 'ldap-decode-attribute record)) |
27313 | 478 result)))) |
479 | |
480 | |
481 (defun ldap-search-internal (search-plist) | |
482 "Perform a search on a LDAP server. | |
483 SEARCH-PLIST is a property list describing the search request. | |
484 Valid keys in that list are: | |
485 `host' is a string naming one or more (blank-separated) LDAP servers to | |
486 to try to connect to. Each host name may optionally be of the form HOST:PORT. | |
487 `filter' is a filter string for the search as described in RFC 1558. | |
488 `attributes' is a list of strings indicating which attributes to retrieve | |
489 for each matching entry. If nil, return all available attributes. | |
490 `attrsonly', if non-nil, indicates that only attributes are retrieved, | |
491 not their associated values. | |
492 `base' is the base for the search as described in RFC 1779. | |
493 `scope' is one of the three symbols `sub', `base' or `one'. | |
494 `binddn' is the distinguished name of the user to bind as (in RFC 1779 syntax). | |
495 `passwd' is the password to use for simple authentication. | |
496 `deref' is one of the symbols `never', `always', `search' or `find'. | |
497 `timelimit' is the timeout limit for the connection in seconds. | |
498 `sizelimit' is the maximum number of matches to return. | |
499 `withdn' if non-nil each entry in the result will be prepended with | |
500 its distinguished name DN. | |
501 The function returns a list of matching entries. Each entry is itself | |
502 an alist of attribute/value pairs." | |
503 (let ((buf (get-buffer-create " *ldap-search*")) | |
504 (bufval (get-buffer-create " *ldap-value*")) | |
505 (host (or (plist-get search-plist 'host) | |
506 ldap-default-host)) | |
507 (filter (plist-get search-plist 'filter)) | |
508 (attributes (plist-get search-plist 'attributes)) | |
509 (attrsonly (plist-get search-plist 'attrsonly)) | |
510 (base (or (plist-get search-plist 'base) | |
511 ldap-default-base)) | |
512 (scope (plist-get search-plist 'scope)) | |
513 (binddn (plist-get search-plist 'binddn)) | |
514 (passwd (plist-get search-plist 'passwd)) | |
515 (deref (plist-get search-plist 'deref)) | |
516 (timelimit (plist-get search-plist 'timelimit)) | |
517 (sizelimit (plist-get search-plist 'sizelimit)) | |
518 (withdn (plist-get search-plist 'withdn)) | |
519 (numres 0) | |
520 arglist dn name value record result) | |
521 (if (or (null filter) | |
522 (equal "" filter)) | |
523 (error "No search filter")) | |
524 (setq filter (cons filter attributes)) | |
525 (save-excursion | |
526 (set-buffer buf) | |
527 (erase-buffer) | |
528 (if (and host | |
529 (not (equal "" host))) | |
530 (setq arglist (nconc arglist (list (format "-h%s" host))))) | |
531 (if (and attrsonly | |
532 (not (equal "" attrsonly))) | |
533 (setq arglist (nconc arglist (list "-A")))) | |
534 (if (and base | |
535 (not (equal "" base))) | |
536 (setq arglist (nconc arglist (list (format "-b%s" base))))) | |
537 (if (and scope | |
538 (not (equal "" scope))) | |
539 (setq arglist (nconc arglist (list (format "-s%s" scope))))) | |
540 (if (and binddn | |
541 (not (equal "" binddn))) | |
542 (setq arglist (nconc arglist (list (format "-D%s" binddn))))) | |
543 (if (and passwd | |
544 (not (equal "" passwd))) | |
545 (setq arglist (nconc arglist (list (format "-w%s" passwd))))) | |
546 (if (and deref | |
547 (not (equal "" deref))) | |
548 (setq arglist (nconc arglist (list (format "-a%s" deref))))) | |
549 (if (and timelimit | |
550 (not (equal "" timelimit))) | |
551 (setq arglist (nconc arglist (list (format "-l%s" timelimit))))) | |
552 (if (and sizelimit | |
553 (not (equal "" sizelimit))) | |
554 (setq arglist (nconc arglist (list (format "-z%s" sizelimit))))) | |
555 (eval `(call-process ldap-ldapsearch-prog | |
556 nil | |
55698
dae0dc3dfbad
Avoid mixing standard error output messages into the search result.
Pavel Janík <Pavel@Janik.cz>
parents:
54805
diff
changeset
|
557 `(,buf nil) |
42517
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
558 nil |
27313 | 559 ,@arglist |
560 ,@ldap-ldapsearch-args | |
561 ,@filter)) | |
562 (insert "\n") | |
563 (goto-char (point-min)) | |
42517
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
564 |
45247
6baa96917e56
(ldap-search-internal): Unfold folded lines before parsing.
Pavel Janík <Pavel@Janik.cz>
parents:
42783
diff
changeset
|
565 (while (re-search-forward "[\t\n\f]+ " nil t) |
6baa96917e56
(ldap-search-internal): Unfold folded lines before parsing.
Pavel Janík <Pavel@Janik.cz>
parents:
42783
diff
changeset
|
566 (replace-match "" nil nil)) |
6baa96917e56
(ldap-search-internal): Unfold folded lines before parsing.
Pavel Janík <Pavel@Janik.cz>
parents:
42783
diff
changeset
|
567 (goto-char (point-min)) |
6baa96917e56
(ldap-search-internal): Unfold folded lines before parsing.
Pavel Janík <Pavel@Janik.cz>
parents:
42783
diff
changeset
|
568 |
27313 | 569 (if (looking-at "usage") |
570 (error "Incorrect ldapsearch invocation") | |
571 (message "Parsing results... ") | |
42579
c914fba3811b
(ldap-search-internal): Skip error message from ldapsearch. Allow listing
Pavel Janík <Pavel@Janik.cz>
parents:
42573
diff
changeset
|
572 ;; Skip error message when retrieving attribute list |
c914fba3811b
(ldap-search-internal): Skip error message from ldapsearch. Allow listing
Pavel Janík <Pavel@Janik.cz>
parents:
42573
diff
changeset
|
573 (if (looking-at "Size limit exceeded") |
c914fba3811b
(ldap-search-internal): Skip error message from ldapsearch. Allow listing
Pavel Janík <Pavel@Janik.cz>
parents:
42573
diff
changeset
|
574 (forward-line 1)) |
42517
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
575 (while (progn |
27313 | 576 (skip-chars-forward " \t\n") |
577 (not (eobp))) | |
42517
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
578 (setq dn (buffer-substring (point) (save-excursion |
27313 | 579 (end-of-line) |
580 (point)))) | |
581 (forward-line 1) | |
59935
ccb26cb917af
(ldap-search-internal): Support attributes with
Eli Zaretskii <eliz@gnu.org>
parents:
55698
diff
changeset
|
582 (while (looking-at "^\\(\\w*\\)\\(;\\w*\\)?[=:\t ]+\\(<[\t ]*file://\\)?\\(.*\\)$") |
27313 | 583 (setq name (match-string 1) |
59935
ccb26cb917af
(ldap-search-internal): Support attributes with
Eli Zaretskii <eliz@gnu.org>
parents:
55698
diff
changeset
|
584 value (match-string 4)) |
54359
e63d620f8988
(ldap-search-internal): Handle file URLs with drive
Jason Rumney <jasonr@gnu.org>
parents:
52401
diff
changeset
|
585 ;; Need to handle file:///D:/... as generated by OpenLDAP |
e63d620f8988
(ldap-search-internal): Handle file URLs with drive
Jason Rumney <jasonr@gnu.org>
parents:
52401
diff
changeset
|
586 ;; on DOS/Windows as local files. |
e63d620f8988
(ldap-search-internal): Handle file URLs with drive
Jason Rumney <jasonr@gnu.org>
parents:
52401
diff
changeset
|
587 (if (and (memq system-type '(windows-nt ms-dos)) |
e63d620f8988
(ldap-search-internal): Handle file URLs with drive
Jason Rumney <jasonr@gnu.org>
parents:
52401
diff
changeset
|
588 (eq (string-match "/\\(.:.*\\)$" value) 0)) |
e63d620f8988
(ldap-search-internal): Handle file URLs with drive
Jason Rumney <jasonr@gnu.org>
parents:
52401
diff
changeset
|
589 (setq value (match-string 1 value))) |
42579
c914fba3811b
(ldap-search-internal): Skip error message from ldapsearch. Allow listing
Pavel Janík <Pavel@Janik.cz>
parents:
42573
diff
changeset
|
590 ;; Do not try to open non-existent files |
c914fba3811b
(ldap-search-internal): Skip error message from ldapsearch. Allow listing
Pavel Janík <Pavel@Janik.cz>
parents:
42573
diff
changeset
|
591 (if (equal value "") |
c914fba3811b
(ldap-search-internal): Skip error message from ldapsearch. Allow listing
Pavel Janík <Pavel@Janik.cz>
parents:
42573
diff
changeset
|
592 (setq value " ") |
c914fba3811b
(ldap-search-internal): Skip error message from ldapsearch. Allow listing
Pavel Janík <Pavel@Janik.cz>
parents:
42573
diff
changeset
|
593 (save-excursion |
c914fba3811b
(ldap-search-internal): Skip error message from ldapsearch. Allow listing
Pavel Janík <Pavel@Janik.cz>
parents:
42573
diff
changeset
|
594 (set-buffer bufval) |
c914fba3811b
(ldap-search-internal): Skip error message from ldapsearch. Allow listing
Pavel Janík <Pavel@Janik.cz>
parents:
42573
diff
changeset
|
595 (erase-buffer) |
c914fba3811b
(ldap-search-internal): Skip error message from ldapsearch. Allow listing
Pavel Janík <Pavel@Janik.cz>
parents:
42573
diff
changeset
|
596 (set-buffer-multibyte nil) |
c914fba3811b
(ldap-search-internal): Skip error message from ldapsearch. Allow listing
Pavel Janík <Pavel@Janik.cz>
parents:
42573
diff
changeset
|
597 (insert-file-contents-literally value) |
c914fba3811b
(ldap-search-internal): Skip error message from ldapsearch. Allow listing
Pavel Janík <Pavel@Janik.cz>
parents:
42573
diff
changeset
|
598 (delete-file value) |
c914fba3811b
(ldap-search-internal): Skip error message from ldapsearch. Allow listing
Pavel Janík <Pavel@Janik.cz>
parents:
42573
diff
changeset
|
599 (setq value (buffer-string)))) |
27313 | 600 (setq record (cons (list name value) |
601 record)) | |
602 (forward-line 1)) | |
42517
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
603 (setq result (cons (if withdn |
27313 | 604 (cons dn (nreverse record)) |
605 (nreverse record)) result)) | |
606 (setq record nil) | |
42517
400e6bda5a0d
(ldap-host-parameters-alist): Remove duplicated entry.
Pavel Janík <Pavel@Janik.cz>
parents:
42368
diff
changeset
|
607 (skip-chars-forward " \t\n") |
27313 | 608 (message "Parsing results... %d" numres) |
609 (1+ numres)) | |
610 (message "Parsing results... done") | |
611 (nreverse result))))) | |
612 | |
613 (provide 'ldap) | |
614 | |
52401 | 615 ;;; arch-tag: 47913a76-6155-42e6-ac58-6d28b5d50eb0 |
27313 | 616 ;;; ldap.el ends here |