comparison src/eldap.c @ 404:2f8bb876ab1d r21-2-32

Import from CVS: tag r21-2-32
author cvs
date Mon, 13 Aug 2007 11:16:07 +0200
parents a86b2b5e0111
children 697ef44129c6
comparison
equal deleted inserted replaced
403:9f011ab08d48 404:2f8bb876ab1d
415 /* Vars for query */ 415 /* Vars for query */
416 LDAP *ld; 416 LDAP *ld;
417 LDAPMessage *e; 417 LDAPMessage *e;
418 BerElement *ptr; 418 BerElement *ptr;
419 char *a, *dn; 419 char *a, *dn;
420 int i, rc, rc2; 420 int i, rc;
421 int matches; 421 int matches;
422 struct ldap_unwind_struct unwind; 422 struct ldap_unwind_struct unwind;
423 423
424 int ldap_scope = LDAP_SCOPE_SUBTREE; 424 int ldap_scope = LDAP_SCOPE_SUBTREE;
425 char **ldap_attributes = NULL; 425 char **ldap_attributes = NULL;
426 426
427 int speccount = specpdl_depth (); 427 int speccount = specpdl_depth ();
428 428
429 Lisp_Object list, entry, result; 429 Lisp_Object list = Qnil;
430 Lisp_Object entry = Qnil;
431 Lisp_Object result = Qnil;
430 struct gcpro gcpro1, gcpro2, gcpro3; 432 struct gcpro gcpro1, gcpro2, gcpro3;
431 433
432 list = entry = result = Qnil;
433 GCPRO3 (list, entry, result); 434 GCPRO3 (list, entry, result);
434 435
435 unwind.res = NULL; 436 unwind.res = NULL;
436 unwind.vals = NULL; 437 unwind.vals = NULL;
437 438
487 /* Attributes only ? */ 488 /* Attributes only ? */
488 CHECK_SYMBOL (attrsonly); 489 CHECK_SYMBOL (attrsonly);
489 490
490 /* Perform the search */ 491 /* Perform the search */
491 if (ldap_search (ld, 492 if (ldap_search (ld,
492 NILP (base) ? "" : (char *) XSTRING_DATA (base), 493 NILP (base) ? (char *) "" : (char *) XSTRING_DATA (base),
493 ldap_scope, 494 ldap_scope,
494 NILP (filter) ? "" : (char *) XSTRING_DATA (filter), 495 NILP (filter) ? (char *) "" : (char *) XSTRING_DATA (filter),
495 ldap_attributes, 496 ldap_attributes,
496 NILP (attrsonly) ? 0 : 1) 497 NILP (attrsonly) ? 0 : 1)
497 == -1) 498 == -1)
498 { 499 {
499 signal_ldap_error (ld, NULL, 0); 500 signal_ldap_error (ld, NULL, 0);
536 unwind.vals = ldap_get_values_len (ld, e, a); 537 unwind.vals = ldap_get_values_len (ld, e, a);
537 if (unwind.vals != NULL) 538 if (unwind.vals != NULL)
538 { 539 {
539 for (i = 0; unwind.vals[i] != NULL; i++) 540 for (i = 0; unwind.vals[i] != NULL; i++)
540 { 541 {
541 list = Fcons (make_ext_string (unwind.vals[i]->bv_val, 542 list = Fcons (make_ext_string ((Extbyte *) unwind.vals[i]->bv_val,
542 unwind.vals[i]->bv_len, 543 unwind.vals[i]->bv_len,
543 Qnative), 544 Qnative),
544 list); 545 list);
545 } 546 }
546 } 547 }
556 557
557 rc = ldap_result (ld, LDAP_RES_ANY, 0, NULL, &(unwind.res)); 558 rc = ldap_result (ld, LDAP_RES_ANY, 0, NULL, &(unwind.res));
558 } 559 }
559 560
560 #if defined HAVE_LDAP_PARSE_RESULT 561 #if defined HAVE_LDAP_PARSE_RESULT
561 rc2 = ldap_parse_result (ld, unwind.res, 562 {
562 &rc, 563 int rc2 = ldap_parse_result (ld, unwind.res,
563 NULL, NULL, NULL, NULL, 0); 564 &rc,
564 if (rc2 != LDAP_SUCCESS) 565 NULL, NULL, NULL, NULL, 0);
565 rc = rc2; 566 if (rc2 != LDAP_SUCCESS)
567 rc = rc2;
568 }
566 #else 569 #else
567 if (rc == 0) 570 if (rc == 0)
568 signal_ldap_error (ld, NULL, LDAP_TIMELIMIT_EXCEEDED); 571 signal_ldap_error (ld, NULL, LDAP_TIMELIMIT_EXCEEDED);
569 572
570 if (rc == -1) 573 if (rc == -1)
602 LDAP *ld; 605 LDAP *ld;
603 LDAPMod *ldap_mods, **ldap_mods_ptrs; 606 LDAPMod *ldap_mods, **ldap_mods_ptrs;
604 struct berval *bervals; 607 struct berval *bervals;
605 int rc; 608 int rc;
606 int i, j; 609 int i, j;
607 610 size_t len;
608 Lisp_Object current, values; 611
612 Lisp_Object current = Qnil;
613 Lisp_Object values = Qnil;
609 struct gcpro gcpro1, gcpro2; 614 struct gcpro gcpro1, gcpro2;
615
610 GCPRO2 (current, values); 616 GCPRO2 (current, values);
611 617
612 /* Do all the parameter checking */ 618 /* Do all the parameter checking */
613 CHECK_LIVE_LDAP (ldap); 619 CHECK_LIVE_LDAP (ldap);
614 ld = XLDAP (ldap)->ld; 620 ld = XLDAP (ldap)->ld;
620 CHECK_CONS (entry); 626 CHECK_CONS (entry);
621 if (NILP (entry)) 627 if (NILP (entry))
622 signal_simple_error ("Cannot add void entry", entry); 628 signal_simple_error ("Cannot add void entry", entry);
623 629
624 /* Build the ldap_mods array */ 630 /* Build the ldap_mods array */
625 ldap_mods = alloca_array (LDAPMod, XINT (Flength (entry))); 631 len = XINT (Flength (entry));
626 ldap_mods_ptrs = alloca_array (LDAPMod *, 1 + XINT (Flength (entry))); 632 ldap_mods = alloca_array (LDAPMod, len);
633 ldap_mods_ptrs = alloca_array (LDAPMod *, 1 + len);
627 i = 0; 634 i = 0;
628 EXTERNAL_LIST_LOOP (entry, entry) 635 EXTERNAL_LIST_LOOP (entry, entry)
629 { 636 {
630 current = XCAR (entry); 637 current = XCAR (entry);
631 CHECK_CONS (current); 638 CHECK_CONS (current);
636 Qnative); 643 Qnative);
637 ldap_mods[i].mod_op = LDAP_MOD_ADD | LDAP_MOD_BVALUES; 644 ldap_mods[i].mod_op = LDAP_MOD_ADD | LDAP_MOD_BVALUES;
638 values = XCDR (current); 645 values = XCDR (current);
639 if (CONSP (values)) 646 if (CONSP (values))
640 { 647 {
641 bervals = 648 len = XINT (Flength (values));
642 alloca_array (struct berval, XINT (Flength (values))); 649 bervals = alloca_array (struct berval, len);
643 ldap_mods[i].mod_vals.modv_bvals = 650 ldap_mods[i].mod_vals.modv_bvals =
644 alloca_array (struct berval *, 1 + XINT (Flength (values))); 651 alloca_array (struct berval *, 1 + len);
645 j = 0; 652 j = 0;
646 EXTERNAL_LIST_LOOP (values, values) 653 EXTERNAL_LIST_LOOP (values, values)
647 { 654 {
648 current = XCAR (values); 655 current = XCAR (values);
649 CHECK_STRING (current); 656 CHECK_STRING (current);
674 rc = ldap_add_s (ld, (char *) XSTRING_DATA (dn), ldap_mods_ptrs); 681 rc = ldap_add_s (ld, (char *) XSTRING_DATA (dn), ldap_mods_ptrs);
675 if (rc != LDAP_SUCCESS) 682 if (rc != LDAP_SUCCESS)
676 signal_ldap_error (ld, NULL, rc); 683 signal_ldap_error (ld, NULL, rc);
677 684
678 UNGCPRO; 685 UNGCPRO;
686 return Qnil;
679 } 687 }
680 688
681 DEFUN ("ldap-modify", Fldap_modify, 3, 3, 0, /* 689 DEFUN ("ldap-modify", Fldap_modify, 3, 3, 0, /*
682 Add an entry to an LDAP directory. 690 Add an entry to an LDAP directory.
683 LDAP is an LDAP connection object created with `ldap-open'. 691 LDAP is an LDAP connection object created with `ldap-open'.
684 DN is the distinguished name of the entry to modify. 692 DN is the distinguished name of the entry to modify.
685 MODS is a list of modifications to apply. 693 MODS is a list of modifications to apply.
686 A modification is a list of the form (MOD-OP ATTR VALUE1 VALUE2 ...) 694 A modification is a list of the form (MOD-OP ATTR VALUE1 VALUE2 ...)
687 MOD-OP and ATTR are mandatory, VALUEs are optional depending on MOD-OP. 695 MOD-OP and ATTR are mandatory, VALUEs are optional depending on MOD-OP.
688 MOD-OP is the type of modification, one of the symbols `add', `delete' 696 MOD-OP is the type of modification, one of the symbols `add', `delete'
689 or `replace'. ATTR is the LDAP attribute type to modify 697 or `replace'. ATTR is the LDAP attribute type to modify.
690 */ 698 */
691 (ldap, dn, mods)) 699 (ldap, dn, mods))
692 { 700 {
693 LDAP *ld; 701 LDAP *ld;
694 LDAPMod *ldap_mods, **ldap_mods_ptrs; 702 LDAPMod *ldap_mods, **ldap_mods_ptrs;
695 struct berval *bervals; 703 struct berval *bervals;
696 int i, j, rc; 704 int i, j, rc;
697 705 Lisp_Object mod_op;
698 Lisp_Object current, mod_op, values; 706 size_t len;
707
708 Lisp_Object current = Qnil;
709 Lisp_Object values = Qnil;
699 struct gcpro gcpro1, gcpro2; 710 struct gcpro gcpro1, gcpro2;
700 711
701 GCPRO2 (current, values); 712 GCPRO2 (current, values);
702 713
703 /* Do all the parameter checking */ 714 /* Do all the parameter checking */
711 CHECK_CONS (mods); 722 CHECK_CONS (mods);
712 if (NILP (mods)) 723 if (NILP (mods))
713 return Qnil; 724 return Qnil;
714 725
715 /* Build the ldap_mods array */ 726 /* Build the ldap_mods array */
716 ldap_mods = alloca_array (LDAPMod, XINT (Flength (mods))); 727 len = XINT (Flength (mods));
717 ldap_mods_ptrs = alloca_array (LDAPMod *, 1 + XINT (Flength (mods))); 728 ldap_mods = alloca_array (LDAPMod, len);
729 ldap_mods_ptrs = alloca_array (LDAPMod *, 1 + len);
718 i = 0; 730 i = 0;
719 EXTERNAL_LIST_LOOP (mods, mods) 731 EXTERNAL_LIST_LOOP (mods, mods)
720 { 732 {
721 current = XCAR (mods); 733 current = XCAR (mods);
722 CHECK_CONS (current); 734 CHECK_CONS (current);
736 CHECK_STRING (XCAR (current)); 748 CHECK_STRING (XCAR (current));
737 TO_EXTERNAL_FORMAT (LISP_STRING, XCAR (current), 749 TO_EXTERNAL_FORMAT (LISP_STRING, XCAR (current),
738 C_STRING_ALLOCA, ldap_mods[i].mod_type, 750 C_STRING_ALLOCA, ldap_mods[i].mod_type,
739 Qnative); 751 Qnative);
740 values = XCDR (current); 752 values = XCDR (current);
741 bervals = alloca_array (struct berval, XINT (Flength (values))); 753 len = XINT (Flength (values));
754 bervals = alloca_array (struct berval, len);
742 ldap_mods[i].mod_vals.modv_bvals = 755 ldap_mods[i].mod_vals.modv_bvals =
743 alloca_array (struct berval *, 1 + XINT (Flength (values))); 756 alloca_array (struct berval *, 1 + len);
744 j = 0; 757 j = 0;
745 EXTERNAL_LIST_LOOP (values, values) 758 EXTERNAL_LIST_LOOP (values, values)
746 { 759 {
747 current = XCAR (values); 760 current = XCAR (values);
748 CHECK_STRING (current); 761 CHECK_STRING (current);
760 rc = ldap_modify_s (ld, (char *) XSTRING_DATA (dn), ldap_mods_ptrs); 773 rc = ldap_modify_s (ld, (char *) XSTRING_DATA (dn), ldap_mods_ptrs);
761 if (rc != LDAP_SUCCESS) 774 if (rc != LDAP_SUCCESS)
762 signal_ldap_error (ld, NULL, rc); 775 signal_ldap_error (ld, NULL, rc);
763 776
764 UNGCPRO; 777 UNGCPRO;
778 return Qnil;
765 } 779 }
766 780
767 781
768 DEFUN ("ldap-delete", Fldap_delete, 2, 2, 0, /* 782 DEFUN ("ldap-delete", Fldap_delete, 2, 2, 0, /*
769 Delete an entry to an LDAP directory. 783 Delete an entry to an LDAP directory.
781 CHECK_STRING (dn); 795 CHECK_STRING (dn);
782 796
783 rc = ldap_delete_s (ld, (char *) XSTRING_DATA (dn)); 797 rc = ldap_delete_s (ld, (char *) XSTRING_DATA (dn));
784 if (rc != LDAP_SUCCESS) 798 if (rc != LDAP_SUCCESS)
785 signal_ldap_error (ld, NULL, rc); 799 signal_ldap_error (ld, NULL, rc);
800
801 return Qnil;
786 } 802 }
787 803
788 void 804 void
789 syms_of_eldap (void) 805 syms_of_eldap (void)
790 { 806 {