comparison src/eldap.c @ 280:7df0dd720c89 r21-0b38

Import from CVS: tag r21-0b38
author cvs
date Mon, 13 Aug 2007 10:32:22 +0200
parents 90d73dddcdc4
children c42ec1d1cded
comparison
equal deleted inserted replaced
279:c20b2fb5bb0a 280:7df0dd720c89
45 #else 45 #else
46 #undef HAVE_LDAP_SET_OPTION 46 #undef HAVE_LDAP_SET_OPTION
47 #undef HAVE_LDAP_GET_ERRNO 47 #undef HAVE_LDAP_GET_ERRNO
48 #endif 48 #endif
49 49
50
51
52 static int ldap_default_port; 50 static int ldap_default_port;
53 static Lisp_Object Vldap_default_base; 51 static Lisp_Object Vldap_default_base;
54 52
55 /* ldap-open plist keywords */ 53 /* ldap-open plist keywords */
56 static Lisp_Object Qport, Qauth, Qbinddn, Qpasswd, Qderef, Qtimelimit, 54 extern Lisp_Object Qport, Qauth, Qbinddn, Qpasswd, Qderef, Qtimelimit,
57 Qsizelimit; 55 Qsizelimit;
58 /* Search scope limits */ 56 /* Search scope limits */
59 static Lisp_Object Qbase, Qonelevel, Qsubtree; 57 extern Lisp_Object Qbase, Qonelevel, Qsubtree;
60 /* Authentication methods */ 58 /* Authentication methods */
61 #ifdef LDAP_AUTH_KRBV41 59 #ifdef LDAP_AUTH_KRBV41
62 static Lisp_Object Qkrbv41; 60 extern Lisp_Object Qkrbv41;
63 #endif 61 #endif
64 #ifdef LDAP_AUTH_KRBV42 62 #ifdef LDAP_AUTH_KRBV42
65 static Lisp_Object Qkrbv42; 63 extern Lisp_Object Qkrbv42;
66 #endif 64 #endif
67 /* Deref policy */ 65 /* Deref policy */
68 static Lisp_Object Qnever, Qalways, Qfind; 66 extern Lisp_Object Qnever, Qalways, Qfind;
67 /* Connection status */
68 extern Lisp_Object Qopen, Qclosed;
69 69
70 static Lisp_Object Qldapp; 70 static Lisp_Object Qldapp;
71 71
72 72
73 /************************************************************************/ 73 /************************************************************************/
148 ldap->host = Qnil; 148 ldap->host = Qnil;
149 ldap->status_symbol = Qnil; 149 ldap->status_symbol = Qnil;
150 return ldap; 150 return ldap;
151 } 151 }
152 152
153 static void
154 finalize_ldap (void *header, int for_disksave)
155 {
156 struct Lisp_LDAP *ldap = (struct Lisp_LDAP *) header;
157
158 if (for_disksave)
159 {
160 Lisp_Object obj;
161 XSETLDAP (obj, ldap);
162 signal_simple_error
163 ("Can't dump an emacs containing LDAP objects", obj);
164 }
165 if (EQ (ldap->status_symbol, Qopen))
166 ldap_unbind (ldap->ld);
167 }
168
153 DEFINE_LRECORD_IMPLEMENTATION ("ldap", ldap, 169 DEFINE_LRECORD_IMPLEMENTATION ("ldap", ldap,
154 mark_ldap, print_ldap, NULL, 170 mark_ldap, print_ldap, finalize_ldap,
155 NULL, NULL, struct Lisp_LDAP); 171 NULL, NULL, struct Lisp_LDAP);
156 172
157 173
158 174
159 175
318 signal_simple_error_2 ("Failed connecting to host", 334 signal_simple_error_2 ("Failed connecting to host",
319 host, 335 host,
320 lisp_strerror (errno)); 336 lisp_strerror (errno));
321 337
322 338
323 #if HAVE_LDAP_SET_OPTION 339 #ifdef HAVE_LDAP_SET_OPTION
324 if (ldap_set_option (ld, LDAP_OPT_DEREF, (void *)&ldap_deref) != LDAP_SUCCESS) 340 if (ldap_set_option (ld, LDAP_OPT_DEREF, (void *)&ldap_deref) != LDAP_SUCCESS)
325 signal_ldap_error (ld); 341 signal_ldap_error (ld);
326 if (ldap_set_option (ld, LDAP_OPT_TIMELIMIT, 342 if (ldap_set_option (ld, LDAP_OPT_TIMELIMIT,
327 (void *)&ldap_timelimit) != LDAP_SUCCESS) 343 (void *)&ldap_timelimit) != LDAP_SUCCESS)
328 signal_ldap_error (ld); 344 signal_ldap_error (ld);
329 if (ldap_set_option (ld, LDAP_OPT_SIZELIMIT, 345 if (ldap_set_option (ld, LDAP_OPT_SIZELIMIT,
330 (void *)&ldap_sizelimit) != LDAP_SUCCESS) 346 (void *)&ldap_sizelimit) != LDAP_SUCCESS)
331 signal_ldap_error (ld); 347 signal_ldap_error (ld);
332 if (ldap_set_option (ld, LDAP_OPT_REFERRALS, LDAP_OPT_ON) != LDAP_SUCCESS) 348 if (ldap_set_option (ld, LDAP_OPT_REFERRALS, LDAP_OPT_ON) != LDAP_SUCCESS)
333 signal_ldap_error (ld); 349 signal_ldap_error (ld);
334 #else /* HAVE_LDAP_SET_OPTION */ 350 #else /* not HAVE_LDAP_SET_OPTION */
335 ld->ld_deref = ldap_deref; 351 ld->ld_deref = ldap_deref;
336 ld->ld_timelimit = ldap_timelimit; 352 ld->ld_timelimit = ldap_timelimit;
337 ld->ld_sizelimit = ldap_sizelimit; 353 ld->ld_sizelimit = ldap_sizelimit;
338 #ifdef LDAP_REFERRALS 354 #ifdef LDAP_REFERRALS
339 ld->ld_options = LDAP_OPT_REFERRALS; 355 ld->ld_options = LDAP_OPT_REFERRALS;
340 #else /* LDAP_REFERRALS */ 356 #else /* not LDAP_REFERRALS */
341 ld->ld_options = 0; 357 ld->ld_options = 0;
342 #endif /* LDAP_REFERRALS */ 358 #endif /* not LDAP_REFERRALS */
343 #endif /* HAVE_LDAP_SET_OPTION */ 359 #endif /* not HAVE_LDAP_SET_OPTION */
344 360
345 /* ldap_bind_s calls select and may be wedged by spurious signals */ 361 /* ldap_bind_s calls select and may be wedged by spurious signals */
346 slow_down_interrupts (); 362 slow_down_interrupts ();
347 err = ldap_bind_s (ld, ldap_binddn, ldap_passwd, ldap_auth); 363 err = ldap_bind_s (ld, ldap_binddn, ldap_passwd, ldap_auth);
348 speed_up_interrupts (); 364 speed_up_interrupts ();
362 378
363 379
364 380
365 DEFUN ("ldap-close", Fldap_close, 1, 1, 0, /* 381 DEFUN ("ldap-close", Fldap_close, 1, 1, 0, /*
366 Close an LDAP connection. 382 Close an LDAP connection.
367 Return t if the connection was actually closed or nil if
368 it was already closed before the call
369 */ 383 */
370 (ldap)) 384 (ldap))
371 { 385 {
372 CHECK_LDAP (ldap); 386 struct Lisp_LDAP *lldap;
373 if ( EQ ((XLDAP (ldap))->status_symbol, Qopen) ) 387 CHECK_LIVE_LDAP (ldap);
374 { 388 lldap = XLDAP (ldap);
375 ldap_unbind ((XLDAP (ldap))->ld); 389 ldap_unbind (lldap->ld);
376 (XLDAP (ldap))->status_symbol = Qclosed; 390 lldap->status_symbol = Qclosed;
377 return Qt;
378 }
379 return Qnil; 391 return Qnil;
380 } 392 }
381 393
382 394
383 395
560 572
561 if (rc == -1) 573 if (rc == -1)
562 { 574 {
563 signal_ldap_error (ld); 575 signal_ldap_error (ld);
564 } 576 }
565 577 rc = ldap_result2error (ld, unwind.res, 0);
566 if ((rc = ldap_result2error (ld, unwind.res, 0)) != LDAP_SUCCESS) 578 if ((rc != LDAP_SUCCESS) &&
579 (rc != LDAP_SIZELIMIT_EXCEEDED))
567 { 580 {
568 signal_ldap_error (ld); 581 signal_ldap_error (ld);
569 } 582 }
570 583
571 ldap_msgfree (unwind.res); 584 ldap_msgfree (unwind.res);