Diff for /servers/slapd/overlays/refint.c between versions 1.7 and 1.7.2.8

version 1.7, 2004/11/25 20:16:56 version 1.7.2.8, 2005/11/26 23:54:52
Line 1 Line 1
 /* refint.c - referential integrity module */  /* refint.c - referential integrity module */
 /* $OpenLDAP: pkg/ldap/servers/slapd/overlays/refint.c,v 1.6 2004/09/11 00:02:09 jongchoi Exp $ */  /* $OpenLDAP: pkg/ldap/servers/slapd/overlays/refint.c,v 1.7.2.7 2005/11/03 18:03:02 kurt Exp $ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.  /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *   *
  * Copyright 2004 The OpenLDAP Foundation.   * Copyright 2004-2005 The OpenLDAP Foundation.
  * Portions Copyright 2004 Symas Corporation.   * Portions Copyright 2004 Symas Corporation.
  * All rights reserved.   * All rights reserved.
  *   *
Line 80  refint_db_init( Line 80  refint_db_init(
 {  {
         slap_overinst *on = (slap_overinst *)be->bd_info;          slap_overinst *on = (slap_overinst *)be->bd_info;
         refint_data *id = ch_malloc(sizeof(refint_data));          refint_data *id = ch_malloc(sizeof(refint_data));
         refint_attrs *ip;  
         id->message = "_init";          id->message = "_init";
         id->attrs = NULL;          id->attrs = NULL;
         id->newdn.bv_val = NULL;          id->newdn.bv_val = NULL;
Line 242  refint_delete_cb( Line 242  refint_delete_cb(
 {  {
         Attribute *a;          Attribute *a;
         BerVarray b = NULL;          BerVarray b = NULL;
         refint_data *id, *dd = op->o_callback->sc_private;          refint_data *dd = op->o_callback->sc_private;
         refint_attrs *ia, *da = dd->attrs;          refint_attrs *ia, *da = dd->attrs;
         dependent_data *ip, *dp = NULL;          dependent_data *ip;
         Modifications *mp, *ma;          Modifications *mp, *ma;
         int i;          int i;
   
Line 291  refint_delete_cb( Line 291  refint_delete_cb(
                                 mp->sml_values[1].bv_val = mp->sml_nvalues[1].bv_val = NULL;                                  mp->sml_values[1].bv_val = mp->sml_nvalues[1].bv_val = NULL;
   
                                 mp->sml_op = LDAP_MOD_ADD;                                  mp->sml_op = LDAP_MOD_ADD;
                                   mp->sml_flags = 0;
                                 ber_dupbv(&mp->sml_values[0],  &dd->nothing);                                  ber_dupbv(&mp->sml_values[0],  &dd->nothing);
                                 ber_dupbv(&mp->sml_nvalues[0], &dd->nnothing);                                  ber_dupbv(&mp->sml_nvalues[0], &dd->nnothing);
                                 mp->sml_next = ma;                                  mp->sml_next = ma;
Line 305  refint_delete_cb( Line 306  refint_delete_cb(
                         mp->sml_values[1].bv_len = mp->sml_nvalues[1].bv_len = 0;                          mp->sml_values[1].bv_len = mp->sml_nvalues[1].bv_len = 0;
                         mp->sml_values[1].bv_val = mp->sml_nvalues[1].bv_val = NULL;                          mp->sml_values[1].bv_val = mp->sml_nvalues[1].bv_val = NULL;
                         mp->sml_op = LDAP_MOD_DELETE;                          mp->sml_op = LDAP_MOD_DELETE;
                           mp->sml_flags = 0;
                         ber_dupbv(&mp->sml_values[0], &dd->dn);                          ber_dupbv(&mp->sml_values[0], &dd->dn);
                         ber_dupbv(&mp->sml_nvalues[0], &mp->sml_values[0]);                          ber_dupbv(&mp->sml_nvalues[0], &mp->sml_values[0]);
                         mp->sml_next = ma;                          mp->sml_next = ma;
Line 349  refint_modrdn_cb( Line 351  refint_modrdn_cb(
 {  {
         Attribute *a;          Attribute *a;
         BerVarray b = NULL;          BerVarray b = NULL;
         refint_data *id, *dd = op->o_callback->sc_private;          refint_data *dd = op->o_callback->sc_private;
         refint_attrs *ia, *da = dd->attrs;          refint_attrs *ia, *da = dd->attrs;
         dependent_data *ip = NULL, *dp = NULL;          dependent_data *ip = NULL;
         Modifications *mp;          Modifications *mp;
         int i, j, fix;          int i, fix;
   
         Debug(LDAP_DEBUG_TRACE, "refint_modrdn_cb <%s>\n",          Debug(LDAP_DEBUG_TRACE, "refint_modrdn_cb <%s>\n",
                 rs->sr_entry ? rs->sr_entry->e_name.bv_val : "NOTHING", 0, 0);                  rs->sr_entry ? rs->sr_entry->e_name.bv_val : "NOTHING", 0, 0);
Line 389  refint_modrdn_cb( Line 391  refint_modrdn_cb(
                         }                          }
                         mp = ch_malloc(sizeof(Modifications));                          mp = ch_malloc(sizeof(Modifications));
                         mp->sml_op = LDAP_MOD_ADD;                          mp->sml_op = LDAP_MOD_ADD;
                           mp->sml_flags = 0;
                         mp->sml_desc = ia->attr;                /* XXX */                          mp->sml_desc = ia->attr;                /* XXX */
                         mp->sml_type = ia->attr->ad_cname;                          mp->sml_type = ia->attr->ad_cname;
                         mp->sml_values  = ch_malloc(2 * sizeof(BerValue));                          mp->sml_values  = ch_malloc(2 * sizeof(BerValue));
Line 401  refint_modrdn_cb( Line 404  refint_modrdn_cb(
                         ip->mm = mp;                          ip->mm = mp;
                         mp = ch_malloc(sizeof(Modifications));                          mp = ch_malloc(sizeof(Modifications));
                         mp->sml_op = LDAP_MOD_DELETE;                          mp->sml_op = LDAP_MOD_DELETE;
                           mp->sml_flags = 0;
                         mp->sml_desc = ia->attr;                /* XXX */                          mp->sml_desc = ia->attr;                /* XXX */
                         mp->sml_type = ia->attr->ad_cname;                          mp->sml_type = ia->attr->ad_cname;
                         mp->sml_values  = ch_malloc(2 * sizeof(BerValue));                          mp->sml_values  = ch_malloc(2 * sizeof(BerValue));
Line 446  refint_response( Line 450  refint_response(
         refint_data dd = *id;          refint_data dd = *id;
         refint_attrs *ip;          refint_attrs *ip;
         dependent_data *dp;          dependent_data *dp;
         char *fstr, *key, *kp, **dnpp, **ndnpp, *cp;          BerValue pdn;
         BerValue ndn, moddn, pdn;          int rc, ac;
         BerVarray b = NULL;          Filter ftop, *fptr;
         int rc, ac, i, j, ksize;  
   
         id->message = "_refint_response";          id->message = "_refint_response";
   
Line 519  refint_response( Line 522  refint_response(
         }          }
   
         /*          /*
         ** calculate the search key size and allocate it;  
         ** build a search filter for all configured attributes;          ** build a search filter for all configured attributes;
         ** populate our Operation;          ** populate our Operation;
         ** pass our data (attr list, dn) to backend via sc_private;          ** pass our data (attr list, dn) to backend via sc_private;
Line 529  refint_response( Line 531  refint_response(
         **          **
         */          */
   
         for(ksize = 16, ip = id->attrs; ip; ip = ip->next)          ftop.f_choice = LDAP_FILTER_OR;
                 ksize += ip->attr->ad_cname.bv_len + op->o_req_dn.bv_len + 3;          ftop.f_next = NULL;
         kp = key = ch_malloc(ksize);          ftop.f_or = NULL;
         if(--ac) kp += sprintf(key, "(|");          nop.ors_filter = &ftop;
         for(ip = id->attrs; ip; ip = ip->next)          for(ip = id->attrs; ip; ip = ip->next) {
                 kp += sprintf(kp, "(%s=%s)",                  fptr = ch_malloc( sizeof(Filter) + sizeof(AttributeAssertion) );
                         ip->attr->ad_cname.bv_val, op->o_req_dn.bv_val);                  fptr->f_choice = LDAP_FILTER_EQUALITY;
         if(ac) *kp++ = ')';                  fptr->f_ava = (AttributeAssertion *)(fptr+1);
         *kp = 0;                  fptr->f_ava->aa_desc = ip->attr;
                   fptr->f_ava->aa_value = op->o_req_ndn;
         nop.ors_filter = str2filter_x(&nop, key);                  fptr->f_next = ftop.f_or;
         ber_str2bv(key, 0, 0, &nop.ors_filterstr);                  ftop.f_or = fptr;
           }
           filter2bv( nop.ors_filter, &nop.ors_filterstr );
   
         /* callback gets the searched dn instead */          /* callback gets the searched dn instead */
         dd.dn = op->o_req_ndn;          dd.dn = op->o_req_ndn;
Line 551  refint_response( Line 555  refint_response(
         nop.o_tag       = LDAP_REQ_SEARCH;          nop.o_tag       = LDAP_REQ_SEARCH;
         nop.ors_scope   = LDAP_SCOPE_SUBTREE;          nop.ors_scope   = LDAP_SCOPE_SUBTREE;
         nop.ors_deref   = LDAP_DEREF_NEVER;          nop.ors_deref   = LDAP_DEREF_NEVER;
           nop.ors_limit   = NULL;
         nop.ors_slimit  = SLAP_NO_LIMIT;          nop.ors_slimit  = SLAP_NO_LIMIT;
         nop.ors_tlimit  = SLAP_NO_LIMIT;          nop.ors_tlimit  = SLAP_NO_LIMIT;
   
Line 564  refint_response( Line 569  refint_response(
         /* search */          /* search */
         rc = nop.o_bd->be_search(&nop, &nrs);          rc = nop.o_bd->be_search(&nop, &nrs);
   
         filter_free_x(&nop, nop.ors_filter);          ch_free( nop.ors_filterstr.bv_val );
         ch_free(key);          while ( (fptr = ftop.f_or) != NULL ) {
                   ftop.f_or = fptr->f_next;
                   ch_free( fptr );
           }
         ch_free(dd.nnewdn.bv_val);          ch_free(dd.nnewdn.bv_val);
         ch_free(dd.newdn.bv_val);          ch_free(dd.newdn.bv_val);
         dd.newdn.bv_val = NULL;          dd.newdn.bv_val = NULL;
Line 613  refint_response( Line 621  refint_response(
         */          */
   
         for(dp = dd.mods; dp; dp = dp->next) {          for(dp = dd.mods; dp; dp = dp->next) {
                 Modifications **tail, *m;  
   
                 for(m = dp->mm; m && m->sml_next; m = m->sml_next);  
                 tail = &m->sml_next;  
                 nop.o_req_dn    = dp->dn;                  nop.o_req_dn    = dp->dn;
                 nop.o_req_ndn   = dp->dn;                  nop.o_req_ndn   = dp->dn;
                 nop.o_bd = select_backend(&dp->dn, 0, 1);                  nop.o_bd = select_backend(&dp->dn, 0, 1);
Line 629  refint_response( Line 633  refint_response(
                 nop.orm_modlist = dp->mm;       /* callback did all the work */                  nop.orm_modlist = dp->mm;       /* callback did all the work */
                 nop.o_dn = refint_dn;                  nop.o_dn = refint_dn;
                 nop.o_ndn = refint_dn;                  nop.o_ndn = refint_dn;
                 rs->sr_err = slap_mods_opattrs( &nop, nop.orm_modlist,  
                         tail, &rs->sr_text, NULL, 0, 1 );  
                 nop.o_dn = nop.o_bd->be_rootdn;                  nop.o_dn = nop.o_bd->be_rootdn;
                 nop.o_ndn = nop.o_bd->be_rootndn;                  nop.o_ndn = nop.o_bd->be_rootndn;
                 if(rs->sr_err != LDAP_SUCCESS) goto done;                  if(rs->sr_err != LDAP_SUCCESS) goto done;
Line 645  done: Line 647  done:
         for(dp = dd.mods; dp; dp = dd.mods) {          for(dp = dd.mods; dp; dp = dd.mods) {
                 dd.mods = dp->next;                  dd.mods = dp->next;
                 ch_free(dp->dn.bv_val);                  ch_free(dp->dn.bv_val);
                 slap_mods_free(dp->mm);                  slap_mods_free(dp->mm, 1);
         }          }
         dd.mods = NULL;          dd.mods = NULL;
   
Line 657  done: Line 659  done:
 ** it expects to be called automagically during dynamic module initialization  ** it expects to be called automagically during dynamic module initialization
 */  */
   
 int refint_init() {  int refint_initialize() {
   
         /* statically declared just after the #includes at top */          /* statically declared just after the #includes at top */
         refint.on_bi.bi_type = "refint";          refint.on_bi.bi_type = "refint";
Line 672  int refint_init() { Line 674  int refint_init() {
   
 #if SLAPD_OVER_REFINT == SLAPD_MOD_DYNAMIC && defined(PIC)  #if SLAPD_OVER_REFINT == SLAPD_MOD_DYNAMIC && defined(PIC)
 int init_module(int argc, char *argv[]) {  int init_module(int argc, char *argv[]) {
         return refint_init();          return refint_initialize();
 }  }
 #endif  #endif
   

Removed from v.1.7  
changed lines
  Added in v.1.7.2.8


______________
© Copyright 1998-2020, OpenLDAP Foundation, info@OpenLDAP.org