]> git.sur5r.net Git - openldap/blob - servers/slapd/overlays/refint.c
zero out sml_managing any time a Modifications is built (use calloc?)
[openldap] / servers / slapd / overlays / refint.c
1 /* refint.c - referential integrity module */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 2004-2005 The OpenLDAP Foundation.
6  * Portions Copyright 2004 Symas Corporation.
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted only as authorized by the OpenLDAP
11  * Public License.
12  *
13  * A copy of this license is available in the file LICENSE in the
14  * top-level directory of the distribution or, alternatively, at
15  * <http://www.OpenLDAP.org/license.html>.
16  */
17 /* ACKNOWLEDGEMENTS:
18  * This work was initially developed by Symas Corp. for inclusion in
19  * OpenLDAP Software.  This work was sponsored by Hewlett-Packard.
20  */
21
22 #include "portable.h"
23
24 /* This module maintains referential integrity for a set of
25  * DN-valued attributes by searching for all references to a given
26  * DN whenever the DN is changed or its entry is deleted, and making
27  * the appropriate update.
28  *
29  * Updates are performed using the database rootdn, but the ModifiersName
30  * is always set to refint_dn.
31  */
32
33 #ifdef SLAPD_OVER_REFINT
34
35 #include <stdio.h>
36
37 #include <ac/string.h>
38 #include <ac/socket.h>
39
40 #include "slap.h"
41
42 static slap_overinst refint;
43
44 /* The DN to use in the ModifiersName for all refint updates */
45 static BerValue refint_dn = BER_BVC("cn=Referential Integrity Overlay");
46
47 typedef struct refint_attrs_s {
48         struct refint_attrs_s *next;
49         AttributeDescription *attr;
50 } refint_attrs;
51
52 typedef struct dependents_s {
53         struct dependents_s *next;
54         BerValue dn;                            /* target dn */
55         Modifications *mm;
56 } dependent_data;
57
58 typedef struct refint_data_s {
59         const char *message;                    /* breadcrumbs */
60         struct refint_attrs_s *attrs;   /* list of known attrs */
61         struct dependents_s *mods;              /* modifications returned from callback */
62         BerValue dn;                            /* basedn in parent, searchdn in call */
63         BerValue newdn;                         /* replacement value for modrdn callback */
64         BerValue nnewdn;                        /* normalized replacement value */
65         BerValue nothing;                       /* the nothing value, if needed */
66         BerValue nnothing;                      /* normalized nothingness */
67 } refint_data;
68
69 /*
70 ** allocate new refint_data;
71 ** initialize, copy basedn;
72 ** store in on_bi.bi_private;
73 **
74 */
75
76 static int
77 refint_db_init(
78         BackendDB       *be
79 )
80 {
81         slap_overinst *on = (slap_overinst *)be->bd_info;
82         refint_data *id = ch_malloc(sizeof(refint_data));
83
84         id->message = "_init";
85         id->attrs = NULL;
86         id->newdn.bv_val = NULL;
87         id->nothing.bv_val = NULL;
88         id->nnothing.bv_val = NULL;
89         ber_dupbv( &id->dn, &be->be_nsuffix[0] );
90         on->on_bi.bi_private = id;
91         return(0);
92 }
93
94
95 /*
96 ** if command = attributes:
97 **      foreach argument:
98 **              convert to attribute;
99 **              add to configured attribute list;
100 ** elseif command = basedn:
101 **      set our basedn to argument;
102 **
103 */
104
105 static int
106 refint_config(
107         BackendDB       *be,
108         const char      *fname,
109         int             lineno,
110         int             argc,
111         char            **argv
112 )
113 {
114         slap_overinst *on       = (slap_overinst *) be->bd_info;
115         refint_data *id = on->on_bi.bi_private;
116         refint_attrs *ip;
117         const char *text;
118         AttributeDescription *ad;
119         BerValue dn;
120         int i;
121
122         if(!strcasecmp(*argv, "refint_attributes")) {
123                 for(i = 1; i < argc; i++) {
124                         for(ip = id->attrs; ip; ip = ip->next)
125                             if(!strcmp(argv[i], ip->attr->ad_cname.bv_val)) {
126                                 Debug(LDAP_DEBUG_ANY,
127                                         "%s: line %d: duplicate attribute <s>, ignored\n",
128                                         fname, lineno, argv[i]);
129                                 continue;
130                         }
131                         ad = NULL;
132                         if(slap_str2ad(argv[i], &ad, &text) != LDAP_SUCCESS) {
133                                 Debug(LDAP_DEBUG_ANY,
134                                         "%s: line %d: bad attribute <%s>, ignored\n",
135                                         fname, lineno, text);
136                                 continue;               /* XXX */
137                         } else if(ad->ad_next) {
138                                 Debug(LDAP_DEBUG_ANY,
139                                         "%s: line %d: multiple attributes match <%s>, ignored\n",
140                                         fname, lineno, argv[i]);
141                                 continue;
142                         }
143                         ip = ch_malloc(sizeof(refint_attrs));
144                         ip->attr = ad;
145                         ip->next = id->attrs;
146                         id->attrs = ip;
147                         Debug(LDAP_DEBUG_ANY, "%s: line %d: new attribute <%s>\n",
148                                 fname, lineno, argv[i]);
149                 }
150         } else if(!strcasecmp(*argv, "refint_base")) {
151                 /* XXX only one basedn (yet) - need validate argument! */
152                 if(id->dn.bv_val) ch_free(id->dn.bv_val);
153                 ber_str2bv( argv[1], 0, 0, &dn );
154                 Debug(LDAP_DEBUG_ANY, "%s: line %d: new baseDN <%s>\n",
155                         fname, lineno, argv[1]);
156                 if(dnNormalize(0, NULL, NULL, &dn, &id->dn, NULL)) {
157                         Debug(LDAP_DEBUG_ANY, "%s: line %d: bad baseDN!\n", fname, lineno, 0);
158                         return(1);
159                 }
160         } else if(!strcasecmp(*argv, "refint_nothing")) {
161                 if(id->nothing.bv_val) ch_free(id->nothing.bv_val);
162                 if(id->nnothing.bv_val) ch_free(id->nnothing.bv_val);
163                 ber_str2bv( argv[1], 0, 1, &id->nothing );
164                 if(dnNormalize(0, NULL, NULL, &id->nothing, &id->nnothing, NULL)) {
165                         Debug(LDAP_DEBUG_ANY, "%s: line %d: bad nothingDN!\n", fname, lineno, 0);
166                         return(1);
167                 }
168                 Debug(LDAP_DEBUG_ANY, "%s: line %d: new nothingDN<%s>\n",
169                         fname, lineno, argv[1]);
170         } else {
171                 return(SLAP_CONF_UNKNOWN);
172         }
173
174         id->message = "_config";
175         return(0);
176 }
177
178
179 /*
180 ** nothing really happens here;
181 **
182 */
183
184 static int
185 refint_open(
186         BackendDB *be
187 )
188 {
189         slap_overinst *on       = (slap_overinst *)be->bd_info;
190         refint_data *id = on->on_bi.bi_private;
191         id->message             = "_open";
192         return(0);
193 }
194
195
196 /*
197 ** foreach configured attribute:
198 **      free it;
199 ** free our basedn;
200 ** (do not) free id->message;
201 ** reset on_bi.bi_private;
202 ** free our config data;
203 **
204 */
205
206 static int
207 refint_close(
208         BackendDB *be
209 )
210 {
211         slap_overinst *on       = (slap_overinst *) be->bd_info;
212         refint_data *id = on->on_bi.bi_private;
213         refint_attrs *ii, *ij;
214         id->message             = "_close";
215
216         for(ii = id->attrs; ii; ii = ij) {
217                 ij = ii->next;
218                 ch_free(ii);
219         }
220
221         ch_free(id->dn.bv_val);
222         ch_free(id->nothing.bv_val);
223         ch_free(id->nnothing.bv_val);
224
225         on->on_bi.bi_private = NULL;    /* XXX */
226
227         ch_free(id);
228
229         return(0);
230 }
231
232 /*
233 ** delete callback
234 ** generates a list of Modification* from search results
235 */
236
237 static int
238 refint_delete_cb(
239         Operation *op,
240         SlapReply *rs
241 )
242 {
243         Attribute *a;
244         BerVarray b = NULL;
245         refint_data *dd = op->o_callback->sc_private;
246         refint_attrs *ia, *da = dd->attrs;
247         dependent_data *ip;
248         Modifications *mp, *ma;
249         int i;
250
251         Debug(LDAP_DEBUG_TRACE, "refint_delete_cb <%s>\n",
252                 rs->sr_entry ? rs->sr_entry->e_name.bv_val : "NOTHING", 0, 0);
253
254         if (rs->sr_type != REP_SEARCH || !rs->sr_entry) return(0);
255         dd->message = "_delete_cb";
256
257         /*
258         ** foreach configured attribute type:
259         **      if this attr exists in the search result,
260         **      and it has a value matching the target:
261         **              allocate a Modification;
262         **              allocate its array of 2 BerValues;
263         **              if only one value, and we have a configured Nothing:
264         **                      allocate additional Modification
265         **                      type = MOD_ADD
266         **                      BerValues[] = { Nothing, NULL };
267         **                      add to list
268         **              type = MOD_DELETE
269         **              BerValues[] = { our target dn, NULL };
270         **      add this mod to the list of mods;
271         **
272         */
273
274         ip = ch_malloc(sizeof(dependent_data));
275         ip->dn.bv_val = NULL;
276         ip->next = NULL;
277         ip->mm = NULL;
278         ma = NULL;
279         for(ia = da; ia; ia = ia->next) {
280             if ( (a = attr_find(rs->sr_entry->e_attrs, ia->attr) ) )
281                 for(i = 0, b = a->a_nvals; b[i].bv_val; i++)
282                     if(bvmatch(&dd->dn, &b[i])) {
283                         if(!ip->dn.bv_val) ber_dupbv(&ip->dn, &rs->sr_entry->e_nname);
284                         if(!b[1].bv_val && dd->nothing.bv_val) {
285                                 mp = ch_malloc(sizeof(Modifications));
286                                 mp->sml_desc = ia->attr;                /* XXX */
287                                 mp->sml_type = a->a_desc->ad_cname;
288                                 mp->sml_values  = ch_malloc(2 * sizeof(BerValue));
289                                 mp->sml_nvalues = ch_malloc(2 * sizeof(BerValue));
290                                 mp->sml_values[1].bv_len = mp->sml_nvalues[1].bv_len = 0;
291                                 mp->sml_values[1].bv_val = mp->sml_nvalues[1].bv_val = NULL;
292
293                                 mp->sml_op = LDAP_MOD_ADD;
294                                 mp->sml_flags = 0;
295                                 ber_dupbv(&mp->sml_values[0],  &dd->nothing);
296                                 ber_dupbv(&mp->sml_nvalues[0], &dd->nnothing);
297                                 mp->sml_managing = 0;
298                                 mp->sml_next = ma;
299                                 ma = mp;
300                         }
301                         /* this might violate the object class */
302                         mp = ch_malloc(sizeof(Modifications));
303                         mp->sml_desc = ia->attr;                /* XXX */
304                         mp->sml_type = a->a_desc->ad_cname;
305                         mp->sml_values  = ch_malloc(2 * sizeof(BerValue));
306                         mp->sml_nvalues = ch_malloc(2 * sizeof(BerValue));
307                         mp->sml_values[1].bv_len = mp->sml_nvalues[1].bv_len = 0;
308                         mp->sml_values[1].bv_val = mp->sml_nvalues[1].bv_val = NULL;
309                         mp->sml_op = LDAP_MOD_DELETE;
310                         mp->sml_flags = 0;
311                         ber_dupbv(&mp->sml_values[0], &dd->dn);
312                         ber_dupbv(&mp->sml_nvalues[0], &mp->sml_values[0]);
313                         mp->sml_managing = 0;
314                         mp->sml_next = ma;
315                         ma = mp;
316                         Debug(LDAP_DEBUG_TRACE, "refint_delete_cb: %s: %s\n",
317                                 a->a_desc->ad_cname.bv_val, dd->dn.bv_val, 0);
318                         break;
319             }
320         }
321         ip->mm = ma;
322         ip->next = dd->mods;
323         dd->mods = ip;
324
325         return(0);
326 }
327
328 /*
329 ** null callback
330 ** does nothing
331 */
332
333 static int
334 refint_null_cb(
335         Operation *op,
336         SlapReply *rs
337 )
338 {
339         ((refint_data *)op->o_callback->sc_private)->message = "_null_cb";
340         return(LDAP_SUCCESS);
341 }
342
343 /*
344 ** modrdn callback
345 ** generates a list of Modification* from search results
346 */
347
348 static int
349 refint_modrdn_cb(
350         Operation *op,
351         SlapReply *rs
352 )
353 {
354         Attribute *a;
355         BerVarray b = NULL;
356         refint_data *dd = op->o_callback->sc_private;
357         refint_attrs *ia, *da = dd->attrs;
358         dependent_data *ip = NULL;
359         Modifications *mp;
360         int i, fix;
361
362         Debug(LDAP_DEBUG_TRACE, "refint_modrdn_cb <%s>\n",
363                 rs->sr_entry ? rs->sr_entry->e_name.bv_val : "NOTHING", 0, 0);
364
365         if (rs->sr_type != REP_SEARCH || !rs->sr_entry) return(0);
366         dd->message = "_modrdn_cb";
367
368         /*
369         ** foreach configured attribute type:
370         **   if this attr exists in the search result,
371         **   and it has a value matching the target:
372         **      allocate a pair of Modifications;
373         **      make it MOD_ADD the new value and MOD_DELETE the old;
374         **      allocate its array of BerValues;
375         **      foreach value in the search result:
376         **         if it matches our target value, replace it;
377         **         otherwise, copy from the search result;
378         **      terminate the array of BerValues;
379         **   add these mods to the list of mods;
380         **
381         */
382
383         for(ia = da; ia; ia = ia->next) {
384             if((a = attr_find(rs->sr_entry->e_attrs, ia->attr))) {
385                     for(fix = 0, i = 0, b = a->a_nvals; b[i].bv_val; i++)
386                         if(bvmatch(&dd->dn, &b[i])) { fix++; break; }
387                     if(fix) {
388                         if (!ip) {
389                             ip = ch_malloc(sizeof(dependent_data));
390                             ip->next = NULL;
391                             ip->mm = NULL;
392                             ber_dupbv(&ip->dn, &rs->sr_entry->e_nname);
393                         }
394                         mp = ch_malloc(sizeof(Modifications));
395                         mp->sml_op = LDAP_MOD_ADD;
396                         mp->sml_flags = 0;
397                         mp->sml_desc = ia->attr;                /* XXX */
398                         mp->sml_type = ia->attr->ad_cname;
399                         mp->sml_values  = ch_malloc(2 * sizeof(BerValue));
400                         mp->sml_nvalues = ch_malloc(2 * sizeof(BerValue));
401                         ber_dupbv(&mp->sml_values[0], &dd->newdn);
402                         ber_dupbv(&mp->sml_nvalues[0], &dd->nnewdn);
403                         mp->sml_values[1].bv_len = mp->sml_nvalues[1].bv_len = 0;
404                         mp->sml_values[1].bv_val = mp->sml_nvalues[1].bv_val = NULL;
405                         mp->sml_managing = 0;
406                         mp->sml_next = ip->mm;
407                         ip->mm = mp;
408                         mp = ch_malloc(sizeof(Modifications));
409                         mp->sml_op = LDAP_MOD_DELETE;
410                         mp->sml_flags = 0;
411                         mp->sml_desc = ia->attr;                /* XXX */
412                         mp->sml_type = ia->attr->ad_cname;
413                         mp->sml_values  = ch_malloc(2 * sizeof(BerValue));
414                         mp->sml_nvalues = ch_malloc(2 * sizeof(BerValue));
415                         ber_dupbv(&mp->sml_values[0], &dd->dn);
416                         ber_dupbv(&mp->sml_nvalues[0], &dd->dn);
417                         mp->sml_values[1].bv_len = mp->sml_nvalues[1].bv_len = 0;
418                         mp->sml_values[1].bv_val = mp->sml_nvalues[1].bv_val = NULL;
419                         mp->sml_managing = 0;
420                         mp->sml_next = ip->mm;
421                         ip->mm = mp;
422                         Debug(LDAP_DEBUG_TRACE, "refint_modrdn_cb: %s: %s\n",
423                                 a->a_desc->ad_cname.bv_val, dd->dn.bv_val, 0);
424                 }
425             }
426         }
427         if (ip) {
428                 ip->next = dd->mods;
429                 dd->mods = ip;
430         }
431
432         return(0);
433 }
434
435
436 /*
437 ** refint_response
438 ** search for matching records and modify them
439 */
440
441 static int
442 refint_response(
443         Operation *op,
444         SlapReply *rs
445 )
446 {
447         Operation nop = *op;
448         SlapReply nrs = { REP_RESULT };
449         slap_callback cb = { NULL, NULL, NULL, NULL };
450         slap_callback cb2 = { NULL, slap_replog_cb, NULL, NULL };
451         slap_callback *cbo, *cbp;
452         slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
453         refint_data *id = on->on_bi.bi_private;
454         refint_data dd = *id;
455         refint_attrs *ip;
456         dependent_data *dp;
457         BerValue pdn;
458         int rc, ac;
459         Filter ftop, *fptr;
460
461         id->message = "_refint_response";
462
463         /* If the main op failed or is not a Delete or ModRdn, ignore it */
464         if (( op->o_tag != LDAP_REQ_DELETE && op->o_tag != LDAP_REQ_MODRDN ) ||
465                 rs->sr_err != LDAP_SUCCESS )
466                 return SLAP_CB_CONTINUE;
467
468         /*
469         ** validate (and count) the list of attrs;
470         **
471         */
472
473         for(ip = id->attrs, ac = 0; ip; ip = ip->next, ac++);
474         if(!ac) {
475                 rs->sr_err = LDAP_OTHER;
476                 rs->sr_text = "refint_response called without any attributes";
477                 return SLAP_CB_CONTINUE;
478         }
479
480         /*
481         ** find the backend that matches our configured basedn;
482         ** make sure it exists and has search and modify methods;
483         **
484         */
485
486         nop.o_bd = select_backend(&id->dn, 0, 1);
487
488         if(nop.o_bd) {
489                 if (!nop.o_bd->be_search || !nop.o_bd->be_modify) {
490                         rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
491                         rs->sr_text = "backend missing search and/or modify";
492                         return SLAP_CB_CONTINUE;
493                 }
494         } else {
495                 rs->sr_err = LDAP_OTHER;
496                 rs->sr_text = "no known backend? this shouldn't be happening!";
497                 return SLAP_CB_CONTINUE;
498         }
499
500         cb2.sc_next = &cb;
501
502         /*
503         ** if delete: set delete callback;
504         ** else modrdn: create a newdn, set modify callback;
505         **
506         */
507
508         if(op->o_tag == LDAP_REQ_DELETE) {
509                 cb.sc_response = &refint_delete_cb;
510                 dd.newdn.bv_val = NULL;
511                 dd.nnewdn.bv_val = NULL;
512         } else {
513                 cb.sc_response = &refint_modrdn_cb;
514                 if ( op->oq_modrdn.rs_newSup ) {
515                         pdn = *op->oq_modrdn.rs_newSup;
516                 } else {
517                         dnParent( &op->o_req_dn, &pdn );
518                 }
519                 build_new_dn( &dd.newdn, &pdn, &op->orr_newrdn, NULL );
520                 if ( op->oq_modrdn.rs_nnewSup ) {
521                         pdn = *op->oq_modrdn.rs_nnewSup;
522                 } else {
523                         dnParent( &op->o_req_ndn, &pdn );
524                 }
525                 build_new_dn( &dd.nnewdn, &pdn, &op->orr_nnewrdn, NULL );
526         }
527
528         /*
529         ** build a search filter for all configured attributes;
530         ** populate our Operation;
531         ** pass our data (attr list, dn) to backend via sc_private;
532         ** call the backend search function;
533         ** nb: (|(one=thing)) is valid, but do smart formatting anyway;
534         ** nb: 16 is arbitrarily a dozen or so extra bytes;
535         **
536         */
537
538         ftop.f_choice = LDAP_FILTER_OR;
539         ftop.f_next = NULL;
540         ftop.f_or = NULL;
541         nop.ors_filter = &ftop;
542         for(ip = id->attrs; ip; ip = ip->next) {
543                 fptr = ch_malloc( sizeof(Filter) + sizeof(AttributeAssertion) );
544                 fptr->f_choice = LDAP_FILTER_EQUALITY;
545                 fptr->f_ava = (AttributeAssertion *)(fptr+1);
546                 fptr->f_ava->aa_desc = ip->attr;
547                 fptr->f_ava->aa_value = op->o_req_ndn;
548                 fptr->f_next = ftop.f_or;
549                 ftop.f_or = fptr;
550         }
551         filter2bv( nop.ors_filter, &nop.ors_filterstr );
552
553         /* callback gets the searched dn instead */
554         dd.dn = op->o_req_ndn;
555         dd.message      = "_dependent_search";
556         dd.mods         = NULL;
557         cb.sc_private   = &dd;
558         nop.o_callback  = &cb;
559         nop.o_tag       = LDAP_REQ_SEARCH;
560         nop.ors_scope   = LDAP_SCOPE_SUBTREE;
561         nop.ors_deref   = LDAP_DEREF_NEVER;
562         nop.ors_limit   = NULL;
563         nop.ors_slimit  = SLAP_NO_LIMIT;
564         nop.ors_tlimit  = SLAP_NO_LIMIT;
565
566         /* no attrs! */
567         nop.ors_attrs = slap_anlist_no_attrs;
568         nop.ors_attrsonly = 1;
569
570         nop.o_req_ndn = id->dn;
571         nop.o_req_dn = id->dn;
572
573         /* search */
574         rc = nop.o_bd->be_search(&nop, &nrs);
575
576         ch_free( nop.ors_filterstr.bv_val );
577         while ( (fptr = ftop.f_or) != NULL ) {
578                 ftop.f_or = fptr->f_next;
579                 ch_free( fptr );
580         }
581         ch_free(dd.nnewdn.bv_val);
582         ch_free(dd.newdn.bv_val);
583         dd.newdn.bv_val = NULL;
584         dd.nnewdn.bv_val = NULL;
585
586         if(rc != LDAP_SUCCESS) {
587                 rs->sr_err = nrs.sr_err;
588                 rs->sr_text = "refint_response search failed";
589                 goto done;
590         }
591
592         /* safety? paranoid just in case */
593         if(!cb.sc_private) {
594                 rs->sr_err = LDAP_OTHER;
595                 rs->sr_text = "whoa! refint_response callback wiped out sc_private?!";
596                 goto done;
597         }
598
599         /* presto! now it's a modify request with null callback */
600         cb.sc_response  = &refint_null_cb;
601         nop.o_tag       = LDAP_REQ_MODIFY;
602         dd.message      = "_dependent_modify";
603
604         /* See if the parent operation is going into the replog */
605         for (cbo=op->o_callback, cbp = cbo->sc_next; cbp; cbo=cbp,cbp=cbp->sc_next) {
606                 if (cbp->sc_response == slap_replog_cb) {
607                         /* Invoke replog now, arrange for our
608                          * dependent mods to also be logged
609                          */
610                         cbo->sc_next = cbp->sc_next;
611                         replog( op );
612                         nop.o_callback = &cb2;
613                         break;
614                 }
615         }
616
617         /*
618         ** [our search callback builds a list of mods]
619         ** foreach mod:
620         **      make sure its dn has a backend;
621         **      connect Modification* chain to our op;
622         **      call the backend modify function;
623         **      pass any errors upstream;
624         **
625         */
626
627         for(dp = dd.mods; dp; dp = dp->next) {
628                 Modifications **tail, *m;
629
630                 for(m = dp->mm; m && m->sml_next; m = m->sml_next);
631                 tail = &m->sml_next;
632                 nop.o_req_dn    = dp->dn;
633                 nop.o_req_ndn   = dp->dn;
634                 nop.o_bd = select_backend(&dp->dn, 0, 1);
635                 if(!nop.o_bd) {
636                         rs->sr_err = LDAP_OTHER;
637                         rs->sr_text = "this should never happen either!";
638                         goto done;
639                 }
640                 nrs.sr_type     = REP_RESULT;
641                 nop.orm_modlist = dp->mm;       /* callback did all the work */
642                 nop.o_dn = refint_dn;
643                 nop.o_ndn = refint_dn;
644                 rs->sr_err = slap_mods_opattrs( &nop, nop.orm_modlist,
645                         tail, &rs->sr_text, NULL, 0, 1 );
646                 nop.o_dn = nop.o_bd->be_rootdn;
647                 nop.o_ndn = nop.o_bd->be_rootndn;
648                 if(rs->sr_err != LDAP_SUCCESS) goto done;
649                 if((rc = nop.o_bd->be_modify(&nop, &nrs)) != LDAP_SUCCESS) {
650                         rs->sr_err = nrs.sr_err;
651                         rs->sr_text = "dependent modify failed";
652                         goto done;
653                 }
654         }
655
656 done:
657         for(dp = dd.mods; dp; dp = dd.mods) {
658                 dd.mods = dp->next;
659                 ch_free(dp->dn.bv_val);
660                 slap_mods_free(dp->mm, 1);
661         }
662         dd.mods = NULL;
663
664         return(SLAP_CB_CONTINUE);
665 }
666
667 /*
668 ** init_module is last so the symbols resolve "for free" --
669 ** it expects to be called automagically during dynamic module initialization
670 */
671
672 int refint_init() {
673
674         /* statically declared just after the #includes at top */
675         refint.on_bi.bi_type = "refint";
676         refint.on_bi.bi_db_init = refint_db_init;
677         refint.on_bi.bi_db_config = refint_config;
678         refint.on_bi.bi_db_open = refint_open;
679         refint.on_bi.bi_db_close = refint_close;
680         refint.on_response = refint_response;
681
682         return(overlay_register(&refint));
683 }
684
685 #if SLAPD_OVER_REFINT == SLAPD_MOD_DYNAMIC && defined(PIC)
686 int init_module(int argc, char *argv[]) {
687         return refint_init();
688 }
689 #endif
690
691 #endif /* SLAPD_OVER_REFINT */