259
|
1 /* LDAP client interface for XEmacs.
|
265
|
2 Copyright (C) 1998 Free Software Foundation, Inc.
|
259
|
3
|
|
4 This file is part of XEmacs.
|
|
5
|
|
6 XEmacs is free software; you can redistribute it and/or modify it
|
|
7 under the terms of the GNU General Public License as published by the
|
|
8 Free Software Foundation; either version 2, or (at your option) any
|
|
9 later version.
|
|
10
|
|
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 for more details.
|
|
15
|
|
16 You should have received a copy of the GNU General Public License
|
|
17 along with XEmacs; see the file COPYING. If not, write to
|
|
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
19 Boston, MA 02111-1307, USA. */
|
|
20
|
|
21 /* Synched up with: Not in FSF. */
|
|
22
|
282
|
23 /* Author: Oscar Figueiredo with lots of support from Hrvoje Niksic */
|
259
|
24
|
|
25 /* This file provides lisp primitives for access to an LDAP library
|
|
26 conforming to the API defined in RFC 1823.
|
|
27 It has been tested with:
|
|
28 - UMich LDAP 3.3 (http://www.umich.edu/~dirsvcs/ldap/)
|
|
29 - Netscape's LDAP SDK 1.0 (http://developer.netscape.com) */
|
|
30
|
|
31
|
|
32 #include <config.h>
|
|
33 #include "lisp.h"
|
278
|
34 #include "opaque.h"
|
259
|
35
|
265
|
36 #include <errno.h>
|
259
|
37 #include <lber.h>
|
|
38 #include <ldap.h>
|
|
39
|
276
|
40 #include "eldap.h"
|
|
41
|
259
|
42 #ifdef HAVE_NS_LDAP
|
282
|
43 # define HAVE_LDAP_SET_OPTION 1
|
|
44 # define HAVE_LDAP_GET_ERRNO 1
|
259
|
45 #else
|
282
|
46 # undef HAVE_LDAP_SET_OPTION
|
|
47 # undef HAVE_LDAP_GET_ERRNO
|
259
|
48 #endif
|
|
49
|
276
|
50 static int ldap_default_port;
|
|
51 static Lisp_Object Vldap_default_base;
|
|
52
|
282
|
53 /* Needed by the lrecord definition */
|
|
54 Lisp_Object Qldapp;
|
|
55
|
276
|
56 /* ldap-open plist keywords */
|
280
|
57 extern Lisp_Object Qport, Qauth, Qbinddn, Qpasswd, Qderef, Qtimelimit,
|
276
|
58 Qsizelimit;
|
259
|
59 /* Search scope limits */
|
280
|
60 extern Lisp_Object Qbase, Qonelevel, Qsubtree;
|
259
|
61 /* Authentication methods */
|
282
|
62 extern Lisp_Object Qkrbv41, Qkrbv42;
|
259
|
63 /* Deref policy */
|
280
|
64 extern Lisp_Object Qnever, Qalways, Qfind;
|
276
|
65
|
|
66 /************************************************************************/
|
|
67 /* Utility Functions */
|
|
68 /************************************************************************/
|
|
69
|
|
70 static void
|
|
71 signal_ldap_error (LDAP *ld)
|
|
72 {
|
282
|
73 #ifdef HAVE_LDAP_GET_ERRNO
|
276
|
74 signal_simple_error
|
|
75 ("LDAP error",
|
|
76 build_string (ldap_err2string (ldap_get_lderrno (ld, NULL, NULL))));
|
|
77 #else
|
|
78 signal_simple_error ("LDAP error",
|
|
79 build_string (ldap_err2string (ld->ld_errno)));
|
|
80 #endif
|
|
81 }
|
|
82
|
|
83
|
|
84 /************************************************************************/
|
|
85 /* The ldap Lisp object */
|
|
86 /************************************************************************/
|
|
87
|
|
88 /*
|
|
89 * Structure records pertinent information about an open LDAP connection.
|
|
90 */
|
|
91
|
|
92 struct Lisp_LDAP
|
|
93 {
|
|
94 /* lcrecord header */
|
|
95 struct lcrecord_header header;
|
|
96 /* The LDAP connection handle used by the LDAP API */
|
|
97 LDAP *ld;
|
|
98 /* Name of the host we connected to */
|
|
99 Lisp_Object host;
|
282
|
100 /* Status of the LDAP connection. */
|
|
101 int livep;
|
276
|
102 };
|
|
103
|
|
104
|
282
|
105 static Lisp_Object
|
|
106 make_ldap (struct Lisp_LDAP *ldap)
|
|
107 {
|
|
108 Lisp_Object lisp_ldap;
|
|
109 XSETLDAP (lisp_ldap, ldap);
|
|
110 return lisp_ldap;
|
|
111 }
|
276
|
112
|
|
113 static Lisp_Object
|
|
114 mark_ldap (Lisp_Object obj, void (*markobj) (Lisp_Object))
|
|
115 {
|
282
|
116 return XLDAP (obj)->host;
|
276
|
117 }
|
|
118
|
|
119 static void
|
|
120 print_ldap (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
|
|
121 {
|
282
|
122 char buf[32];
|
276
|
123
|
|
124 struct Lisp_LDAP *ldap = XLDAP (obj);
|
|
125
|
|
126 if (print_readably)
|
|
127 error ("printing unreadable object #<ldap %s>",
|
|
128 XSTRING_DATA (ldap->host));
|
|
129
|
278
|
130 write_c_string ("#<ldap ", printcharfun);
|
|
131 print_internal (ldap->host, printcharfun, 1);
|
282
|
132 if (!ldap->livep)
|
|
133 write_c_string ("(dead) ",printcharfun);
|
278
|
134 sprintf (buf, " 0x%x>", ldap);
|
|
135 write_c_string (buf, printcharfun);
|
276
|
136 }
|
|
137
|
|
138 static struct Lisp_LDAP *
|
|
139 allocate_ldap (void)
|
|
140 {
|
|
141 struct Lisp_LDAP *ldap =
|
|
142 alloc_lcrecord_type (struct Lisp_LDAP, lrecord_ldap);
|
|
143
|
282
|
144 ldap->ld = NULL;
|
276
|
145 ldap->host = Qnil;
|
282
|
146 ldap->livep = 0;
|
276
|
147 return ldap;
|
|
148 }
|
|
149
|
280
|
150 static void
|
|
151 finalize_ldap (void *header, int for_disksave)
|
|
152 {
|
|
153 struct Lisp_LDAP *ldap = (struct Lisp_LDAP *) header;
|
|
154
|
|
155 if (for_disksave)
|
282
|
156 signal_simple_error ("Can't dump an emacs containing LDAP objects",
|
|
157 make_ldap (ldap));
|
|
158
|
|
159 if (ldap->livep)
|
280
|
160 ldap_unbind (ldap->ld);
|
|
161 }
|
|
162
|
276
|
163 DEFINE_LRECORD_IMPLEMENTATION ("ldap", ldap,
|
280
|
164 mark_ldap, print_ldap, finalize_ldap,
|
276
|
165 NULL, NULL, struct Lisp_LDAP);
|
|
166
|
|
167
|
|
168
|
|
169
|
|
170 /************************************************************************/
|
|
171 /* Basic ldap accessors */
|
|
172 /************************************************************************/
|
|
173
|
|
174 DEFUN ("ldapp", Fldapp, 1, 1, 0, /*
|
|
175 Return t if OBJECT is a LDAP connection.
|
|
176 */
|
|
177 (object))
|
|
178 {
|
|
179 return LDAPP (object) ? Qt : Qnil;
|
|
180 }
|
|
181
|
|
182 DEFUN ("ldap-host", Fldap_host, 1, 1, 0, /*
|
|
183 Return the server host of the connection LDAP, as a string.
|
|
184 */
|
|
185 (ldap))
|
|
186 {
|
|
187 CHECK_LDAP (ldap);
|
|
188 return (XLDAP (ldap))->host;
|
|
189 }
|
|
190
|
282
|
191 DEFUN ("ldap-live-p", Fldap_status, 1, 1, 0, /*
|
|
192 Return t if LDAP is an active LDAP connection.
|
276
|
193 */
|
|
194 (ldap))
|
|
195 {
|
|
196 CHECK_LDAP (ldap);
|
282
|
197 return (XLDAP (ldap))->livep ? Qt : Qnil;
|
276
|
198 }
|
|
199
|
|
200 /************************************************************************/
|
|
201 /* Opening/Closing a LDAP connection */
|
|
202 /************************************************************************/
|
|
203
|
|
204
|
|
205 DEFUN ("ldap-open", Fldap_open, 1, 2, 0, /*
|
|
206 Open a LDAP connection to HOST.
|
|
207 PLIST is a plist containing additional parameters for the connection.
|
259
|
208 Valid keys in that list are:
|
276
|
209 `port' the TCP port to use for the connection if different from
|
|
210 `ldap-default-port'.
|
259
|
211 `auth' is the authentication method to use, possible values depend on
|
|
212 the LDAP library XEmacs was compiled with: `simple', `krbv41' and `krbv42'.
|
|
213 `binddn' is the distinguished name of the user to bind as (in RFC 1779 syntax).
|
|
214 `passwd' is the password to use for simple authentication.
|
|
215 `deref' is one of the symbols `never', `always', `search' or `find'.
|
|
216 `timelimit' is the timeout limit for the connection in seconds.
|
|
217 `sizelimit' is the maximum number of matches to return.
|
|
218 */
|
276
|
219 (host, plist))
|
259
|
220 {
|
282
|
221 /* This function can GC */
|
|
222 struct Lisp_LDAP *ldap;
|
259
|
223 LDAP *ld;
|
278
|
224 int ldap_port = 0;
|
259
|
225 int ldap_auth = LDAP_AUTH_SIMPLE;
|
|
226 char *ldap_binddn = NULL;
|
|
227 char *ldap_passwd = NULL;
|
|
228 int ldap_deref = LDAP_DEREF_NEVER;
|
|
229 int ldap_timelimit = 0;
|
|
230 int ldap_sizelimit = 0;
|
278
|
231 int err;
|
259
|
232
|
282
|
233 Lisp_Object list, keyword, value;
|
259
|
234
|
276
|
235 CHECK_STRING (host);
|
|
236
|
282
|
237 EXTERNAL_PROPERTY_LIST_LOOP (list, keyword, value, plist)
|
276
|
238 {
|
|
239 /* TCP Port */
|
|
240 if (EQ (keyword, Qport))
|
259
|
241 {
|
276
|
242 CHECK_INT (value);
|
|
243 ldap_port = XINT (value);
|
259
|
244 }
|
|
245 /* Authentication method */
|
276
|
246 if (EQ (keyword, Qauth))
|
259
|
247 {
|
|
248 if (EQ (value, Qsimple))
|
|
249 ldap_auth = LDAP_AUTH_SIMPLE;
|
|
250 #ifdef LDAP_AUTH_KRBV41
|
|
251 else if (EQ (value, Qkrbv41))
|
|
252 ldap_auth = LDAP_AUTH_KRBV41;
|
|
253 #endif
|
|
254 #ifdef LDAP_AUTH_KRBV42
|
|
255 else if (EQ (value, Qkrbv42))
|
|
256 ldap_auth = LDAP_AUTH_KRBV42;
|
|
257 #endif
|
|
258 else
|
|
259 signal_simple_error ("Invalid authentication method", value);
|
|
260 }
|
|
261 /* Bind DN */
|
|
262 else if (EQ (keyword, Qbinddn))
|
|
263 {
|
276
|
264 CHECK_STRING (value);
|
|
265 ldap_binddn = alloca (XSTRING_LENGTH (value) + 1);
|
|
266 strcpy (ldap_binddn, (char *)XSTRING_DATA (value));
|
259
|
267 }
|
|
268 /* Password */
|
|
269 else if (EQ (keyword, Qpasswd))
|
|
270 {
|
276
|
271 CHECK_STRING (value);
|
|
272 ldap_passwd = alloca (XSTRING_LENGTH (value) + 1);
|
|
273 strcpy (ldap_passwd, (char *)XSTRING_DATA (value));
|
259
|
274 }
|
|
275 /* Deref */
|
|
276 else if (EQ (keyword, Qderef))
|
|
277 {
|
|
278 if (EQ (value, Qnever))
|
|
279 ldap_deref = LDAP_DEREF_NEVER;
|
|
280 else if (EQ (value, Qsearch))
|
|
281 ldap_deref = LDAP_DEREF_SEARCHING;
|
|
282 else if (EQ (value, Qfind))
|
|
283 ldap_deref = LDAP_DEREF_FINDING;
|
|
284 else if (EQ (value, Qalways))
|
|
285 ldap_deref = LDAP_DEREF_ALWAYS;
|
|
286 else
|
|
287 signal_simple_error ("Invalid deref value", value);
|
|
288 }
|
|
289 /* Timelimit */
|
|
290 else if (EQ (keyword, Qtimelimit))
|
|
291 {
|
276
|
292 CHECK_INT (value);
|
|
293 ldap_timelimit = XINT (value);
|
259
|
294 }
|
|
295 /* Sizelimit */
|
|
296 else if (EQ (keyword, Qsizelimit))
|
|
297 {
|
276
|
298 CHECK_INT (value);
|
|
299 ldap_sizelimit = XINT (value);
|
259
|
300 }
|
|
301 }
|
|
302
|
276
|
303 if (ldap_port == 0)
|
259
|
304 {
|
276
|
305 ldap_port = ldap_default_port;
|
259
|
306 }
|
|
307
|
276
|
308 /* Connect to the server and bind */
|
|
309 ld = ldap_open ((char *)XSTRING_DATA (host), ldap_port);
|
|
310 if (ld == NULL )
|
|
311 signal_simple_error_2 ("Failed connecting to host",
|
|
312 host,
|
|
313 lisp_strerror (errno));
|
259
|
314
|
|
315
|
280
|
316 #ifdef HAVE_LDAP_SET_OPTION
|
259
|
317 if (ldap_set_option (ld, LDAP_OPT_DEREF, (void *)&ldap_deref) != LDAP_SUCCESS)
|
276
|
318 signal_ldap_error (ld);
|
|
319 if (ldap_set_option (ld, LDAP_OPT_TIMELIMIT,
|
|
320 (void *)&ldap_timelimit) != LDAP_SUCCESS)
|
|
321 signal_ldap_error (ld);
|
|
322 if (ldap_set_option (ld, LDAP_OPT_SIZELIMIT,
|
|
323 (void *)&ldap_sizelimit) != LDAP_SUCCESS)
|
|
324 signal_ldap_error (ld);
|
259
|
325 if (ldap_set_option (ld, LDAP_OPT_REFERRALS, LDAP_OPT_ON) != LDAP_SUCCESS)
|
276
|
326 signal_ldap_error (ld);
|
280
|
327 #else /* not HAVE_LDAP_SET_OPTION */
|
259
|
328 ld->ld_deref = ldap_deref;
|
|
329 ld->ld_timelimit = ldap_timelimit;
|
|
330 ld->ld_sizelimit = ldap_sizelimit;
|
|
331 #ifdef LDAP_REFERRALS
|
|
332 ld->ld_options = LDAP_OPT_REFERRALS;
|
280
|
333 #else /* not LDAP_REFERRALS */
|
259
|
334 ld->ld_options = 0;
|
280
|
335 #endif /* not LDAP_REFERRALS */
|
|
336 #endif /* not HAVE_LDAP_SET_OPTION */
|
259
|
337
|
282
|
338 /* ldap_bind_s calls select and may be wedged by SIGIO. */
|
276
|
339 slow_down_interrupts ();
|
|
340 err = ldap_bind_s (ld, ldap_binddn, ldap_passwd, ldap_auth);
|
|
341 speed_up_interrupts ();
|
|
342 if (err != LDAP_SUCCESS)
|
259
|
343 signal_simple_error ("Failed binding to the server",
|
|
344 build_string (ldap_err2string (err)));
|
|
345
|
282
|
346 ldap = allocate_ldap ();
|
|
347 ldap->ld = ld;
|
|
348 ldap->host = host;
|
|
349 ldap->livep = 1;
|
276
|
350
|
282
|
351 return make_ldap (ldap);
|
276
|
352 }
|
|
353
|
|
354
|
|
355
|
|
356 DEFUN ("ldap-close", Fldap_close, 1, 1, 0, /*
|
|
357 Close an LDAP connection.
|
|
358 */
|
|
359 (ldap))
|
|
360 {
|
280
|
361 struct Lisp_LDAP *lldap;
|
|
362 CHECK_LIVE_LDAP (ldap);
|
|
363 lldap = XLDAP (ldap);
|
|
364 ldap_unbind (lldap->ld);
|
282
|
365 lldap->livep = 0;
|
276
|
366 return Qnil;
|
|
367 }
|
|
368
|
|
369
|
|
370
|
|
371 /************************************************************************/
|
|
372 /* Working on a LDAP connection */
|
|
373 /************************************************************************/
|
278
|
374 struct ldap_unwind_struct
|
|
375 {
|
|
376 LDAPMessage *res;
|
|
377 char **vals;
|
|
378 };
|
|
379
|
|
380
|
|
381 static Lisp_Object
|
|
382 ldap_search_unwind (Lisp_Object unwind_obj)
|
|
383 {
|
|
384 struct ldap_unwind_struct *unwind =
|
|
385 (struct ldap_unwind_struct *) get_opaque_ptr (unwind_obj);
|
282
|
386 if (unwind->res)
|
278
|
387 ldap_msgfree (unwind->res);
|
282
|
388 if (unwind->vals)
|
278
|
389 ldap_value_free (unwind->vals);
|
|
390 }
|
276
|
391
|
|
392 DEFUN ("ldap-search-internal", Fldap_search_internal, 2, 6, 0, /*
|
|
393 Perform a search on an open LDAP connection.
|
|
394 LDAP is an LDAP connection object created with `ldap-open'.
|
|
395 FILTER is a filter string for the search as described in RFC 1558
|
|
396 BASE is the distinguished name at which to start the search
|
|
397 SCOPE is an integer or a symbol indicating the scope of the search
|
|
398 Possible values are `ldap-scope-base', `ldap-scope-onelevel' or
|
|
399 `ldap-scope-subtree'
|
|
400 ATTRS is a list of strings indicating which attributes to retrieve
|
|
401 for each matching entry. If nil return all available attributes.
|
|
402 If ATTRSONLY is non-nil then only the attributes are retrieved, not
|
|
403 the associated values
|
|
404 The function returns a list of matching entries. Each entry is itself
|
|
405 an alist of attribute/values.
|
|
406 */
|
|
407 (ldap, filter, base, scope, attrs, attrsonly))
|
|
408 {
|
282
|
409 /* This function can GC */
|
276
|
410
|
|
411 /* Vars for query */
|
|
412 LDAP *ld;
|
278
|
413 LDAPMessage *e;
|
276
|
414 BerElement *ptr;
|
|
415 char *a;
|
|
416 int i, rc, err;
|
|
417 int matches;
|
278
|
418 struct ldap_unwind_struct unwind;
|
276
|
419
|
|
420 int ldap_scope = LDAP_SCOPE_SUBTREE;
|
|
421 char **ldap_attributes = NULL;
|
|
422
|
278
|
423 int speccount = specpdl_depth ();
|
|
424
|
276
|
425 Lisp_Object list, entry, result;
|
|
426 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
427
|
|
428 list = entry = result = Qnil;
|
282
|
429 GCPRO3 (list, entry, result);
|
276
|
430
|
282
|
431 unwind.res = NULL;
|
|
432 unwind.vals = NULL;
|
278
|
433
|
276
|
434 /* Do all the parameter checking */
|
|
435 CHECK_LIVE_LDAP (ldap);
|
282
|
436 ld = XLDAP (ldap)->ld;
|
276
|
437
|
|
438 /* Filter */
|
|
439 CHECK_STRING (filter);
|
|
440
|
|
441 /* Search base */
|
|
442 if (NILP (base))
|
|
443 {
|
|
444 base = Vldap_default_base;
|
|
445 }
|
|
446 if (!NILP (base))
|
|
447 {
|
|
448 CHECK_STRING (Vldap_default_base);
|
|
449 }
|
|
450
|
|
451 /* Search scope */
|
|
452 if (!NILP (scope))
|
|
453 {
|
|
454 if (EQ (scope, Qbase))
|
|
455 ldap_scope = LDAP_SCOPE_BASE;
|
|
456 else if (EQ (scope, Qonelevel))
|
|
457 ldap_scope = LDAP_SCOPE_ONELEVEL;
|
|
458 else if (EQ (scope, Qsubtree))
|
|
459 ldap_scope = LDAP_SCOPE_SUBTREE;
|
|
460 else
|
|
461 signal_simple_error ("Invalid scope", scope);
|
|
462 }
|
|
463
|
|
464 /* Attributes to search */
|
|
465 if (!NILP (attrs))
|
|
466 {
|
|
467 CHECK_CONS (attrs);
|
278
|
468 ldap_attributes = alloca_array (char *, 1 + XINT (Flength (attrs)));
|
276
|
469
|
278
|
470 i = 0;
|
|
471 EXTERNAL_LIST_LOOP (attrs, attrs)
|
|
472 {
|
|
473 Lisp_Object current = XCAR (attrs);
|
|
474 CHECK_STRING (current);
|
|
475 ldap_attributes[i] =
|
|
476 alloca_array (char, 1 + XSTRING_LENGTH (current));
|
|
477 memcpy (ldap_attributes[i],
|
|
478 XSTRING_DATA (current), XSTRING_LENGTH (current));
|
|
479 ++i;
|
|
480 }
|
276
|
481 ldap_attributes[i] = NULL;
|
|
482 }
|
|
483
|
|
484 /* Attributes only ? */
|
|
485 CHECK_SYMBOL (attrsonly);
|
|
486
|
|
487 /* Perform the search */
|
|
488 if (ldap_search (ld,
|
|
489 NILP (base) ? "" : (char *) XSTRING_DATA (base),
|
|
490 ldap_scope,
|
|
491 NILP (filter) ? "" : (char *) XSTRING_DATA (filter),
|
|
492 ldap_attributes,
|
|
493 NILP (attrsonly) ? 0 : 1)
|
|
494 == -1)
|
|
495 {
|
|
496 signal_ldap_error (ld);
|
259
|
497 }
|
|
498
|
278
|
499 /* Ensure we don't exit without cleaning up */
|
|
500 record_unwind_protect (ldap_search_unwind,
|
|
501 make_opaque_ptr (&unwind));
|
|
502
|
259
|
503 /* Build the results list */
|
|
504 matches = 0;
|
|
505
|
276
|
506 /* ldap_result calls select() and can get wedged by EINTR signals */
|
|
507 slow_down_interrupts ();
|
282
|
508 rc = ldap_result (ld, LDAP_RES_ANY, 0, NULL, &unwind.res);
|
276
|
509 speed_up_interrupts ();
|
282
|
510 while (rc == LDAP_RES_SEARCH_ENTRY)
|
259
|
511 {
|
278
|
512 QUIT;
|
259
|
513 matches ++;
|
278
|
514 e = ldap_first_entry (ld, unwind.res);
|
282
|
515 /* #### This call to message() is pretty fascist, because it
|
|
516 destroys the current echo area contents, even when invoked
|
|
517 from Lisp. It should use echo_area_message() instead, and
|
|
518 restore the old echo area contents later. */
|
|
519 message ("Parsing ldap results... %d", matches);
|
259
|
520 entry = Qnil;
|
|
521 for (a= ldap_first_attribute (ld, e, &ptr);
|
|
522 a != NULL;
|
|
523 a= ldap_next_attribute (ld, e, ptr) )
|
|
524 {
|
|
525 list = Fcons (build_string (a), Qnil);
|
278
|
526 unwind.vals = ldap_get_values (ld, e, a);
|
|
527 if (unwind.vals != NULL)
|
259
|
528 {
|
282
|
529 for (i = 0; unwind.vals[i] != NULL; i++)
|
259
|
530 {
|
278
|
531 list = Fcons (build_string (unwind.vals[i]),
|
259
|
532 list);
|
|
533 }
|
|
534 }
|
|
535 entry = Fcons (Fnreverse (list),
|
|
536 entry);
|
278
|
537 ldap_value_free (unwind.vals);
|
282
|
538 unwind.vals = NULL;
|
259
|
539 }
|
|
540 result = Fcons (Fnreverse (entry),
|
|
541 result);
|
278
|
542 ldap_msgfree (unwind.res);
|
282
|
543 unwind.res = NULL;
|
276
|
544
|
|
545 slow_down_interrupts ();
|
278
|
546 rc = ldap_result (ld, LDAP_RES_ANY, 0, NULL, &(unwind.res));
|
276
|
547 speed_up_interrupts ();
|
259
|
548 }
|
|
549
|
|
550 if (rc == -1)
|
|
551 {
|
276
|
552 signal_ldap_error (ld);
|
259
|
553 }
|
280
|
554 rc = ldap_result2error (ld, unwind.res, 0);
|
|
555 if ((rc != LDAP_SUCCESS) &&
|
|
556 (rc != LDAP_SIZELIMIT_EXCEEDED))
|
259
|
557 {
|
276
|
558 signal_ldap_error (ld);
|
259
|
559 }
|
|
560
|
278
|
561 ldap_msgfree (unwind.res);
|
|
562 unwind.res = (LDAPMessage *)NULL;
|
282
|
563 /* #### See above for calling message(). */
|
|
564 message ("Parsing ldap results... done");
|
259
|
565
|
278
|
566 unbind_to (speccount, Qnil);
|
259
|
567 UNGCPRO;
|
282
|
568 return Fnreverse (result);
|
259
|
569 }
|
|
570
|
|
571
|
|
572 void
|
|
573 syms_of_eldap (void)
|
|
574 {
|
276
|
575 defsymbol (&Qldapp, "ldapp");
|
|
576 DEFSUBR (Fldapp);
|
|
577 DEFSUBR (Fldap_host);
|
|
578 DEFSUBR (Fldap_status);
|
|
579 DEFSUBR (Fldap_open);
|
|
580 DEFSUBR (Fldap_close);
|
|
581 DEFSUBR (Fldap_search_internal);
|
259
|
582 }
|
|
583
|
|
584 void
|
|
585 vars_of_eldap (void)
|
|
586 {
|
276
|
587 Fprovide (intern ("ldap"));
|
259
|
588
|
276
|
589 ldap_default_port = LDAP_PORT;
|
|
590 Vldap_default_base = Qnil;
|
|
591
|
|
592 DEFVAR_INT ("ldap-default-port", &ldap_default_port /*
|
|
593 Default TCP port for LDAP connections.
|
|
594 Initialized from the LDAP library. Default value is 389.
|
259
|
595 */ );
|
|
596
|
|
597 DEFVAR_LISP ("ldap-default-base", &Vldap_default_base /*
|
|
598 Default base for LDAP searches.
|
|
599 This is a string using the syntax of RFC 1779.
|
|
600 For instance, "o=ACME, c=US" limits the search to the
|
|
601 Acme organization in the United States.
|
|
602 */ );
|
|
603
|
|
604 }
|
276
|
605
|
|
606
|