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