]> git.sur5r.net Git - openldap/blob - servers/slapd/overlays/translucent.c
allow trying local bind when remote fails (ITS#5656)
[openldap] / servers / slapd / overlays / translucent.c
1 /* translucent.c - translucent proxy module */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 2004-2008 The OpenLDAP Foundation.
6  * Portions Copyright 2005 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 #ifdef SLAPD_OVER_TRANSLUCENT
25
26 #include <stdio.h>
27
28 #include <ac/string.h>
29 #include <ac/socket.h>
30
31 #include "slap.h"
32 #include "lutil.h"
33
34 #include "config.h"
35
36 /* config block */
37 typedef struct translucent_info {
38         BackendDB db;                   /* captive backend */
39         AttributeName *local;   /* valid attrs for local filters */
40         AttributeName *remote;  /* valid attrs for remote filters */
41         int strict;
42         int no_glue;
43         int defer_db_open;
44         int bind_local;
45 } translucent_info;
46
47 static ConfigLDAPadd translucent_ldadd;
48 static ConfigCfAdd translucent_cfadd;
49
50 static ConfigDriver translucent_cf_gen;
51
52 enum {
53         TRANS_LOCAL = 1,
54         TRANS_REMOTE
55 };
56
57 static ConfigTable translucentcfg[] = {
58         { "translucent_strict", "on|off", 1, 2, 0,
59           ARG_ON_OFF|ARG_OFFSET,
60           (void *)offsetof(translucent_info, strict),
61           "( OLcfgOvAt:14.1 NAME 'olcTranslucentStrict' "
62           "DESC 'Reveal attribute deletion constraint violations' "
63           "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
64         { "translucent_no_glue", "on|off", 1, 2, 0,
65           ARG_ON_OFF|ARG_OFFSET,
66           (void *)offsetof(translucent_info, no_glue),
67           "( OLcfgOvAt:14.2 NAME 'olcTranslucentNoGlue' "
68           "DESC 'Disable automatic glue records for ADD and MODRDN' "
69           "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
70         { "translucent_local", "attr[,attr...]", 1, 2, 0,
71           ARG_MAGIC|TRANS_LOCAL,
72           translucent_cf_gen,
73           "( OLcfgOvAt:14.3 NAME 'olcTranslucentLocal' "
74           "DESC 'Attributes to use in local search filter' "
75           "SYNTAX OMsDirectoryString )", NULL, NULL },
76         { "translucent_remote", "attr[,attr...]", 1, 2, 0,
77           ARG_MAGIC|TRANS_REMOTE,
78           translucent_cf_gen,
79           "( OLcfgOvAt:14.4 NAME 'olcTranslucentRemote' "
80           "DESC 'Attributes to use in remote search filter' "
81           "SYNTAX OMsDirectoryString )", NULL, NULL },
82         { "translucent_bind_local", "on|off", 1, 2, 0,
83           ARG_ON_OFF|ARG_OFFSET,
84           (void *)offsetof(translucent_info, bind_local),
85           "( OLcfgOvAt:14.5 NAME 'olcTranslucentBindLocal' "
86           "DESC 'Enable local bind' "
87           "SYNTAX OMsBoolean SINGLE-VALUE)", NULL, NULL },
88         { NULL, NULL, 0, 0, 0, ARG_IGNORED }
89 };
90
91 static ConfigTable transdummy[] = {
92         { "", "", 0, 0, 0, ARG_IGNORED,
93                 NULL, "( OLcfgGlAt:13 NAME 'olcDatabase' "
94                         "DESC 'The backend type for a database instance' "
95                         "SUP olcBackend SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
96         { NULL, NULL, 0, 0, 0, ARG_IGNORED }
97 };
98
99 static ConfigOCs translucentocs[] = {
100         { "( OLcfgOvOc:14.1 "
101           "NAME 'olcTranslucentConfig' "
102           "DESC 'Translucent configuration' "
103           "SUP olcOverlayConfig "
104           "MAY ( olcTranslucentStrict $ olcTranslucentNoGlue $"
105           " olcTranslucentLocal $ olcTranslucentRemote $"
106           " olcTranslucentBindLocal ) )",
107           Cft_Overlay, translucentcfg, NULL, translucent_cfadd },
108         { "( OLcfgOvOc:14.2 "
109           "NAME 'olcTranslucentDatabase' "
110           "DESC 'Translucent target database configuration' "
111           "AUXILIARY )", Cft_Misc, transdummy, translucent_ldadd },
112         { NULL, 0, NULL }
113 };
114 /* for translucent_init() */
115
116 static int
117 translucent_ldadd_cleanup( ConfigArgs *ca )
118 {
119         slap_overinst *on = ca->ca_private;
120         translucent_info *ov = on->on_bi.bi_private;
121
122         ov->defer_db_open = 0;
123         return backend_startup_one( ca->be, &ca->reply );
124 }
125
126 static int
127 translucent_ldadd( CfEntryInfo *cei, Entry *e, ConfigArgs *ca )
128 {
129         slap_overinst *on;
130         translucent_info *ov;
131
132         Debug(LDAP_DEBUG_TRACE, "==> translucent_ldadd\n", 0, 0, 0);
133
134         if ( cei->ce_type != Cft_Overlay || !cei->ce_bi ||
135              cei->ce_bi->bi_cf_ocs != translucentocs )
136                 return LDAP_CONSTRAINT_VIOLATION;
137
138         on = (slap_overinst *)cei->ce_bi;
139         ov = on->on_bi.bi_private;
140         ca->be = &ov->db;
141         ca->ca_private = on;
142         if ( CONFIG_ONLINE_ADD( ca ))
143                 ca->cleanup = translucent_ldadd_cleanup;
144         else
145                 ov->defer_db_open = 0;
146
147         return LDAP_SUCCESS;
148 }
149
150 static int
151 translucent_cfadd( Operation *op, SlapReply *rs, Entry *e, ConfigArgs *ca )
152 {
153         CfEntryInfo *cei = e->e_private;
154         slap_overinst *on = (slap_overinst *)cei->ce_bi;
155         translucent_info *ov = on->on_bi.bi_private;
156         struct berval bv;
157
158         Debug(LDAP_DEBUG_TRACE, "==> translucent_cfadd\n", 0, 0, 0);
159
160         /* FIXME: should not hardcode "olcDatabase" here */
161         bv.bv_len = snprintf( ca->cr_msg, sizeof( ca->cr_msg ),
162                 "olcDatabase=%s", ov->db.bd_info->bi_type );
163         if ( bv.bv_len < 0 || bv.bv_len >= sizeof( ca->cr_msg ) ) {
164                 return -1;
165         }
166         bv.bv_val = ca->cr_msg;
167         ca->be = &ov->db;
168         ov->defer_db_open = 0;
169
170         /* We can only create this entry if the database is table-driven
171          */
172         if ( ov->db.bd_info->bi_cf_ocs )
173                 config_build_entry( op, rs, cei, ca, &bv,
174                                     ov->db.bd_info->bi_cf_ocs,
175                                     &translucentocs[1] );
176
177         return 0;
178 }
179
180 static int
181 translucent_cf_gen( ConfigArgs *c )
182 {
183         slap_overinst   *on = (slap_overinst *)c->bi;
184         translucent_info *ov = on->on_bi.bi_private;
185         AttributeName **an, *a2;
186         int i;
187
188         if ( c->type == TRANS_LOCAL )
189                 an = &ov->local;
190         else
191                 an = &ov->remote;
192
193         if ( c->op == SLAP_CONFIG_EMIT ) {
194                 if ( !*an )
195                         return 1;
196                 for ( i = 0; !BER_BVISNULL(&(*an)[i].an_name); i++ ) {
197                         value_add_one( &c->rvalue_vals, &(*an)[i].an_name );
198                 }
199                 return ( i < 1 );
200         } else if ( c->op == LDAP_MOD_DELETE ) {
201                 if ( c->valx < 0 ) {
202                         anlist_free( *an, 1, NULL );
203                         *an = NULL;
204                 } else {
205                         i = c->valx;
206                         ch_free( (*an)[i].an_name.bv_val );
207                         do {
208                                 (*an)[i] = (*an)[i+1];
209                         } while ( !BER_BVISNULL( &(*an)[i].an_name ));
210                 }
211                 return 0;
212         }
213         a2 = str2anlist( *an, c->argv[1], "," );
214         if ( !a2 ) {
215                 snprintf( c->cr_msg, sizeof( c->cr_msg ), "%s unable to parse attribute %s",
216                         c->argv[0], c->argv[1] );
217                 Debug( LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE,
218                         "%s: %s\n", c->log, c->cr_msg, 0 );
219                 return ARG_BAD_CONF;
220         }
221         *an = a2;
222         return 0;
223 }
224
225 static slap_overinst translucent;
226
227 /*
228 ** glue_parent()
229 **      call syncrepl_add_glue() with the parent suffix;
230 **
231 */
232
233 static struct berval glue[] = { BER_BVC("top"), BER_BVC("glue"), BER_BVNULL };
234
235 void glue_parent(Operation *op) {
236         Operation nop = *op;
237         slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
238         struct berval ndn = BER_BVNULL;
239         Attribute *a;
240         Entry *e;
241         struct berval   pdn;
242
243         dnParent( &op->o_req_ndn, &pdn );
244         ber_dupbv_x( &ndn, &pdn, op->o_tmpmemctx );
245
246         Debug(LDAP_DEBUG_TRACE, "=> glue_parent: fabricating glue for <%s>\n", ndn.bv_val, 0, 0);
247
248         e = entry_alloc();
249         e->e_id = NOID;
250         ber_dupbv(&e->e_name, &ndn);
251         ber_dupbv(&e->e_nname, &ndn);
252
253         a = attr_alloc( slap_schema.si_ad_objectClass );
254         a->a_numvals = 2;
255         a->a_vals = ch_malloc(sizeof(struct berval) * 3);
256         ber_dupbv(&a->a_vals[0], &glue[0]);
257         ber_dupbv(&a->a_vals[1], &glue[1]);
258         ber_dupbv(&a->a_vals[2], &glue[2]);
259         a->a_nvals = a->a_vals;
260         a->a_next = e->e_attrs;
261         e->e_attrs = a;
262
263         a = attr_alloc( slap_schema.si_ad_structuralObjectClass );
264         a->a_numvals = 1;
265         a->a_vals = ch_malloc(sizeof(struct berval) * 2);
266         ber_dupbv(&a->a_vals[0], &glue[1]);
267         ber_dupbv(&a->a_vals[1], &glue[2]);
268         a->a_nvals = a->a_vals;
269         a->a_next = e->e_attrs;
270         e->e_attrs = a;
271
272         nop.o_req_dn = ndn;
273         nop.o_req_ndn = ndn;
274         nop.ora_e = e;
275
276         nop.o_bd->bd_info = (BackendInfo *) on->on_info->oi_orig;
277         syncrepl_add_glue(&nop, e);
278         nop.o_bd->bd_info = (BackendInfo *) on;
279
280         op->o_tmpfree( ndn.bv_val, op->o_tmpmemctx );
281
282         return;
283 }
284
285 /*
286 ** dup_bervarray()
287 **      copy a BerVarray;
288 */
289
290 BerVarray dup_bervarray(BerVarray b) {
291         int i, len;
292         BerVarray nb;
293         for(len = 0; b[len].bv_val; len++);
294         nb = ch_malloc((len+1) * sizeof(BerValue));
295         for(i = 0; i < len; i++) ber_dupbv(&nb[i], &b[i]);
296         nb[len].bv_val = NULL;
297         nb[len].bv_len = 0;
298         return(nb);
299 }
300
301 /*
302 ** free_attr_chain()
303 **      free only the Attribute*, not the contents;
304 **
305 */
306 void free_attr_chain(Attribute *b) {
307         Attribute *a;
308         for(a=b; a; a=a->a_next) {
309                 a->a_vals = NULL;
310                 a->a_nvals = NULL;
311         }
312         attrs_free( b );
313         return;
314 }
315
316 /*
317 ** translucent_add()
318 **      if not bound as root, send ACCESS error;
319 **      if glue, glue_parent();
320 **      return CONTINUE;
321 **
322 */
323
324 static int translucent_add(Operation *op, SlapReply *rs) {
325         slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
326         translucent_info *ov = on->on_bi.bi_private;
327         Debug(LDAP_DEBUG_TRACE, "==> translucent_add: %s\n",
328                 op->o_req_dn.bv_val, 0, 0);
329         if(!be_isroot(op)) {
330                 op->o_bd->bd_info = (BackendInfo *) on->on_info;
331                 send_ldap_error(op, rs, LDAP_INSUFFICIENT_ACCESS,
332                         "user modification of overlay database not permitted");
333                 op->o_bd->bd_info = (BackendInfo *) on;
334                 return(rs->sr_err);
335         }
336         if(!ov->no_glue) glue_parent(op);
337         return(SLAP_CB_CONTINUE);
338 }
339
340 /*
341 ** translucent_modrdn()
342 **      if not bound as root, send ACCESS error;
343 **      if !glue, glue_parent();
344 **      else return CONTINUE;
345 **
346 */
347
348 static int translucent_modrdn(Operation *op, SlapReply *rs) {
349         slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
350         translucent_info *ov = on->on_bi.bi_private;
351         Debug(LDAP_DEBUG_TRACE, "==> translucent_modrdn: %s -> %s\n",
352                 op->o_req_dn.bv_val, op->orr_newrdn.bv_val, 0);
353         if(!be_isroot(op)) {
354                 op->o_bd->bd_info = (BackendInfo *) on->on_info;
355                 send_ldap_error(op, rs, LDAP_INSUFFICIENT_ACCESS,
356                         "user modification of overlay database not permitted");
357                 op->o_bd->bd_info = (BackendInfo *) on;
358                 return(rs->sr_err);
359         }
360         if(!ov->no_glue) {
361                 op->o_tag = LDAP_REQ_ADD;
362                 glue_parent(op);
363                 op->o_tag = LDAP_REQ_MODRDN;
364         }
365         return(SLAP_CB_CONTINUE);
366 }
367
368 /*
369 ** translucent_delete()
370 **      if not bound as root, send ACCESS error;
371 **      else return CONTINUE;
372 **
373 */
374
375 static int translucent_delete(Operation *op, SlapReply *rs) {
376         slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
377         Debug(LDAP_DEBUG_TRACE, "==> translucent_delete: %s\n",
378                 op->o_req_dn.bv_val, 0, 0);
379         if(!be_isroot(op)) {
380                 op->o_bd->bd_info = (BackendInfo *) on->on_info;
381                 send_ldap_error(op, rs, LDAP_INSUFFICIENT_ACCESS,
382                         "user modification of overlay database not permitted");
383                 op->o_bd->bd_info = (BackendInfo *) on;
384                 return(rs->sr_err);
385         }
386         return(SLAP_CB_CONTINUE);
387 }
388
389 static int
390 translucent_tag_cb( Operation *op, SlapReply *rs )
391 {
392         op->o_tag = LDAP_REQ_MODIFY;
393         op->orm_modlist = op->o_callback->sc_private;
394         rs->sr_tag = slap_req2res( op->o_tag );
395
396         return SLAP_CB_CONTINUE;
397 }
398
399 /*
400 ** translucent_modify()
401 **      modify in local backend if exists in both;
402 **      otherwise, add to local backend;
403 **      fail if not defined in captive backend;
404 **
405 */
406
407 static int translucent_modify(Operation *op, SlapReply *rs) {
408         SlapReply nrs = { REP_RESULT };
409
410         slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
411         translucent_info *ov = on->on_bi.bi_private;
412         Entry *e = NULL, *re = NULL;
413         Attribute *a, *ax;
414         Modifications *m, **mm;
415         BackendDB *db;
416         int del, rc, erc = 0;
417         slap_callback cb = { 0 };
418
419         Debug(LDAP_DEBUG_TRACE, "==> translucent_modify: %s\n",
420                 op->o_req_dn.bv_val, 0, 0);
421
422         if(ov->defer_db_open) {
423                 send_ldap_error(op, rs, LDAP_UNAVAILABLE,
424                         "remote DB not available");
425                 return(rs->sr_err);
426         }
427 /*
428 ** fetch entry from the captive backend;
429 ** if it did not exist, fail;
430 ** release it, if captive backend supports this;
431 **
432 */
433
434         db = op->o_bd;
435         op->o_bd = &ov->db;
436         rc = ov->db.bd_info->bi_entry_get_rw(op, &op->o_req_ndn, NULL, NULL, 0, &re);
437         if(rc != LDAP_SUCCESS || re == NULL ) {
438                 send_ldap_error((op), rs, LDAP_NO_SUCH_OBJECT,
439                         "attempt to modify nonexistent local record");
440                 return(rs->sr_err);
441         }
442         op->o_bd = db;
443 /*
444 ** fetch entry from local backend;
445 ** if it exists:
446 **      foreach Modification:
447 **          if attr not present in local:
448 **              if Mod == LDAP_MOD_DELETE:
449 **                  if remote attr not present, return NO_SUCH;
450 **                  if remote attr present, drop this Mod;
451 **              else force this Mod to LDAP_MOD_ADD;
452 **      return CONTINUE;
453 **
454 */
455
456         op->o_bd->bd_info = (BackendInfo *) on->on_info;
457         rc = be_entry_get_rw(op, &op->o_req_ndn, NULL, NULL, 0, &e);
458         op->o_bd->bd_info = (BackendInfo *) on;
459
460         if(e && rc == LDAP_SUCCESS) {
461                 Debug(LDAP_DEBUG_TRACE, "=> translucent_modify: found local entry\n", 0, 0, 0);
462                 for(mm = &op->orm_modlist; *mm; ) {
463                         m = *mm;
464                         for(a = e->e_attrs; a; a = a->a_next)
465                                 if(a->a_desc == m->sml_desc) break;
466                         if(a) {
467                                 mm = &m->sml_next;
468                                 continue;               /* found local attr */
469                         }
470                         if(m->sml_op == LDAP_MOD_DELETE) {
471                                 for(a = re->e_attrs; a; a = a->a_next)
472                                         if(a->a_desc == m->sml_desc) break;
473                                 /* not found remote attr */
474                                 if(!a) {
475                                         erc = LDAP_NO_SUCH_ATTRIBUTE;
476                                         goto release;
477                                 }
478                                 if(ov->strict) {
479                                         erc = LDAP_CONSTRAINT_VIOLATION;
480                                         goto release;
481                                 }
482                                 Debug(LDAP_DEBUG_TRACE,
483                                         "=> translucent_modify: silently dropping delete: %s\n",
484                                         m->sml_desc->ad_cname.bv_val, 0, 0);
485                                 *mm = m->sml_next;
486                                 m->sml_next = NULL;
487                                 slap_mods_free(m, 1);
488                                 continue;
489                         }
490                         m->sml_op = LDAP_MOD_ADD;
491                         mm = &m->sml_next;
492                 }
493                 erc = SLAP_CB_CONTINUE;
494 release:
495                 if(re) {
496                         if(ov->db.bd_info->bi_entry_release_rw) {
497                                 op->o_bd = &ov->db;
498                                 ov->db.bd_info->bi_entry_release_rw(op, re, 0);
499                                 op->o_bd = db;
500                         } else
501                                 entry_free(re);
502                 }
503                 op->o_bd->bd_info = (BackendInfo *) on->on_info;
504                 be_entry_release_r(op, e);
505                 op->o_bd->bd_info = (BackendInfo *) on;
506                 if(erc == SLAP_CB_CONTINUE) {
507                         return(erc);
508                 } else if(erc) {
509                         send_ldap_error(op, rs, erc,
510                                 "attempt to delete nonexistent attribute");
511                         return(erc);
512                 }
513         }
514
515         /* don't leak remote entry copy */
516         if(re) {
517                 if(ov->db.bd_info->bi_entry_release_rw) {
518                         op->o_bd = &ov->db;
519                         ov->db.bd_info->bi_entry_release_rw(op, re, 0);
520                         op->o_bd = db;
521                 } else
522                         entry_free(re);
523         }
524 /*
525 ** foreach Modification:
526 **      if MOD_ADD or MOD_REPLACE, add Attribute;
527 ** if no Modifications were suitable:
528 **      if strict, throw CONSTRAINT_VIOLATION;
529 **      else, return early SUCCESS;
530 ** fabricate Entry with new Attribute chain;
531 ** glue_parent() for this Entry;
532 ** call bi_op_add() in local backend;
533 **
534 */
535
536         Debug(LDAP_DEBUG_TRACE, "=> translucent_modify: fabricating local add\n", 0, 0, 0);
537         a = NULL;
538         for(del = 0, ax = NULL, m = op->orm_modlist; m; m = m->sml_next) {
539                 Attribute atmp;
540                 if(((m->sml_op & LDAP_MOD_OP) != LDAP_MOD_ADD) &&
541                    ((m->sml_op & LDAP_MOD_OP) != LDAP_MOD_REPLACE)) {
542                         Debug(LDAP_DEBUG_ANY,
543                                 "=> translucent_modify: silently dropped modification(%d): %s\n",
544                                 m->sml_op, m->sml_desc->ad_cname.bv_val, 0);
545                         if((m->sml_op & LDAP_MOD_OP) == LDAP_MOD_DELETE) del++;
546                         continue;
547                 }
548                 atmp.a_desc = m->sml_desc;
549                 atmp.a_vals = m->sml_values;
550                 atmp.a_nvals = m->sml_nvalues ? m->sml_nvalues : atmp.a_vals;
551                 atmp.a_numvals = m->sml_numvals;
552                 atmp.a_flags = 0;
553                 a = attr_dup( &atmp );
554                 a->a_next  = ax;
555                 ax = a;
556         }
557
558         if(del && ov->strict) {
559                 attrs_free( a );
560                 send_ldap_error(op, rs, LDAP_CONSTRAINT_VIOLATION,
561                         "attempt to delete attributes from local database");
562                 return(rs->sr_err);
563         }
564
565         if(!ax) {
566                 if(ov->strict) {
567                         send_ldap_error(op, rs, LDAP_CONSTRAINT_VIOLATION,
568                                 "modification contained other than ADD or REPLACE");
569                         return(rs->sr_err);
570                 }
571                 /* rs->sr_text = "no valid modification found"; */
572                 rs->sr_err = LDAP_SUCCESS;
573                 send_ldap_result(op, rs);
574                 return(rs->sr_err);
575         }
576
577         e = entry_alloc();
578         ber_dupbv( &e->e_name, &op->o_req_dn );
579         ber_dupbv( &e->e_nname, &op->o_req_ndn );
580         e->e_attrs = a;
581
582         op->o_tag       = LDAP_REQ_ADD;
583         cb.sc_response = translucent_tag_cb;
584         cb.sc_private = op->orm_modlist;
585         op->oq_add.rs_e = e;
586
587         glue_parent(op);
588
589         cb.sc_next = op->o_callback;
590         op->o_callback = &cb;
591         rc = on->on_info->oi_orig->bi_op_add(op, &nrs);
592         if ( op->ora_e == e )
593                 entry_free( e );
594         op->o_callback = cb.sc_next;
595
596         return(rc);
597 }
598
599 static int translucent_compare(Operation *op, SlapReply *rs) {
600         slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
601         translucent_info *ov = on->on_bi.bi_private;
602         AttributeAssertion *ava = op->orc_ava;
603         Entry *e;
604         BackendDB *db;
605         int rc;
606
607         Debug(LDAP_DEBUG_TRACE, "==> translucent_compare: <%s> %s:%s\n",
608                 op->o_req_dn.bv_val, ava->aa_desc->ad_cname.bv_val, ava->aa_value.bv_val);
609
610 /*
611 ** if the local backend has an entry for this attribute:
612 **      CONTINUE and let it do the compare;
613 **
614 */
615         rc = overlay_entry_get_ov(op, &op->o_req_ndn, NULL, ava->aa_desc, 0, &e, on);
616         if(rc == LDAP_SUCCESS && e) {
617                 overlay_entry_release_ov(op, e, 0, on);
618                 return(SLAP_CB_CONTINUE);
619         }
620
621         if(ov->defer_db_open) {
622                 send_ldap_error(op, rs, LDAP_UNAVAILABLE,
623                         "remote DB not available");
624                 return(rs->sr_err);
625         }
626 /*
627 ** call compare() in the captive backend;
628 ** return the result;
629 **
630 */
631         db = op->o_bd;
632         op->o_bd = &ov->db;
633         rc = ov->db.bd_info->bi_op_compare(op, rs);
634         op->o_bd = db;
635
636         return(rc);
637 }
638
639 /*
640 ** translucent_search_cb()
641 **      merge local data with remote data
642 **
643 ** Four cases:
644 ** 1: remote search, no local filter
645 **      merge data and send immediately
646 ** 2: remote search, with local filter
647 **      merge data and save
648 ** 3: local search, no remote filter
649 **      merge data and send immediately
650 ** 4: local search, with remote filter
651 **      check list, merge, send, delete
652 */
653
654 #define RMT_SIDE        0
655 #define LCL_SIDE        1
656 #define USE_LIST        2
657
658 typedef struct trans_ctx {
659         BackendDB *db;
660         slap_overinst *on;
661         Filter *orig;
662         Avlnode *list;
663         int step;
664 } trans_ctx;
665
666 static int translucent_search_cb(Operation *op, SlapReply *rs) {
667         trans_ctx *tc;
668         BackendDB *db;
669         slap_overinst *on;
670         translucent_info *ov;
671         Entry *le, *re;
672         Attribute *a, *ax, *an, *as = NULL;
673         int rc;
674         int test_f = 0;
675
676         tc = op->o_callback->sc_private;
677
678         /* Don't let the op complete while we're gathering data */
679         if ( rs->sr_type == REP_RESULT && ( tc->step & USE_LIST ))
680                 return 0;
681
682         if(!op || !rs || rs->sr_type != REP_SEARCH || !rs->sr_entry)
683                 return(SLAP_CB_CONTINUE);
684
685         Debug(LDAP_DEBUG_TRACE, "==> translucent_search_cb: %s\n",
686                 rs->sr_entry->e_name.bv_val, 0, 0);
687
688         on = tc->on;
689         ov = on->on_bi.bi_private;
690
691         db = op->o_bd;
692         re = NULL;
693
694         /* If we have local, get remote */
695         if ( tc->step & LCL_SIDE ) {
696                 le = rs->sr_entry;
697                 /* If entry is already on list, use it */
698                 if ( tc->step & USE_LIST ) {
699                         re = tavl_delete( &tc->list, le, entry_dn_cmp );
700                         if ( re ) {
701                                 if ( rs->sr_flags & REP_ENTRY_MUSTRELEASE ) {
702                                         rs->sr_flags ^= REP_ENTRY_MUSTRELEASE;
703                                         be_entry_release_r( op, rs->sr_entry );
704                                 }
705                                 if ( rs->sr_flags & REP_ENTRY_MUSTBEFREED ) {
706                                         rs->sr_flags ^= REP_ENTRY_MUSTBEFREED;
707                                         entry_free( rs->sr_entry );
708                                 }
709                                 rc = test_filter( op, re, tc->orig );
710                                 if ( rc == LDAP_COMPARE_TRUE ) {
711                                         rs->sr_flags |= REP_ENTRY_MUSTBEFREED;
712                                         rs->sr_entry = re;
713                                         return SLAP_CB_CONTINUE;
714                                 } else {
715                                         entry_free( re );
716                                         rs->sr_entry = NULL;
717                                         return 0;
718                                 }
719                         }
720                 }
721                 op->o_bd = &ov->db;
722                 rc = be_entry_get_rw( op, &rs->sr_entry->e_nname, NULL, NULL, 0, &re );
723                 if ( rc == LDAP_SUCCESS && re ) {
724                         Entry *tmp = entry_dup( re );
725                         be_entry_release_r( op, re );
726                         re = tmp;
727                         test_f = 1;
728                 }
729         } else {
730         /* Else we have remote, get local */
731                 op->o_bd = tc->db;
732                 rc = overlay_entry_get_ov(op, &rs->sr_entry->e_nname, NULL, NULL, 0, &le, on);
733                 if ( rc == LDAP_SUCCESS && le ) {
734                         re = entry_dup( rs->sr_entry );
735                         if ( rs->sr_flags & REP_ENTRY_MUSTRELEASE ) {
736                                 rs->sr_flags ^= REP_ENTRY_MUSTRELEASE;
737                                 be_entry_release_r( op, rs->sr_entry );
738                         }
739                         if ( rs->sr_flags & REP_ENTRY_MUSTBEFREED ) {
740                                 rs->sr_flags ^= REP_ENTRY_MUSTBEFREED;
741                                 entry_free( rs->sr_entry );
742                         }
743                 } else {
744                         le = NULL;
745                 }
746         }
747
748 /*
749 ** if we got remote and local entry:
750 **      foreach local attr:
751 **              foreach remote attr:
752 **                      if match, remote attr with local attr;
753 **                      if new local, add to list;
754 **      append new local attrs to remote;
755 **
756 */
757
758         if ( re && le ) {
759                 for(ax = le->e_attrs; ax; ax = ax->a_next) {
760                         for(a = re->e_attrs; a; a = a->a_next) {
761                                 if(a->a_desc == ax->a_desc) {
762                                         if(a->a_vals != a->a_nvals)
763                                                 ber_bvarray_free(a->a_nvals);
764                                         ber_bvarray_free(a->a_vals);
765                                         a->a_vals = dup_bervarray(ax->a_vals);
766                                         a->a_nvals = (ax->a_vals == ax->a_nvals) ?
767                                                 a->a_vals : dup_bervarray(ax->a_nvals);
768                                         break;
769                                 }
770                         }
771                         if(a) continue;
772                         an = attr_dup(ax);
773                         an->a_next = as;
774                         as = an;
775                 }
776                 /* Dispose of local entry */
777                 if ( tc->step & LCL_SIDE ) {
778                         if ( rs->sr_flags & REP_ENTRY_MUSTRELEASE ) {
779                                 rs->sr_flags ^= REP_ENTRY_MUSTRELEASE;
780                                 be_entry_release_r( op, rs->sr_entry );
781                         }
782                         if ( rs->sr_flags & REP_ENTRY_MUSTBEFREED ) {
783                                 rs->sr_flags ^= REP_ENTRY_MUSTBEFREED;
784                                 entry_free( rs->sr_entry );
785                         }
786                 } else {
787                         overlay_entry_release_ov(op, le, 0, on);
788                 }
789
790                 /* literally append, so locals are always last */
791                 if(as) {
792                         if(re->e_attrs) {
793                                 for(ax = re->e_attrs; ax->a_next; ax = ax->a_next);
794                                 ax->a_next = as;
795                         } else {
796                                 re->e_attrs = as;
797                         }
798                 }
799                 /* If both filters, save entry for later */
800                 if ( tc->step == (USE_LIST|RMT_SIDE) ) {
801                         tavl_insert( &tc->list, re, entry_dn_cmp, avl_dup_error );
802                         rs->sr_entry = NULL;
803                         rc = 0;
804                 } else {
805                 /* send it now */
806                         rs->sr_entry = re;
807                         rs->sr_flags |= REP_ENTRY_MUSTBEFREED;
808                         if ( test_f ) {
809                                 rc = test_filter( op, rs->sr_entry, tc->orig );
810                                 if ( rc == LDAP_COMPARE_TRUE ) {
811                                         rc = SLAP_CB_CONTINUE;
812                                 } else {
813                                         rc = 0;
814                                 }
815                         } else {
816                                 rc = SLAP_CB_CONTINUE;
817                         }
818                 }
819         } else if ( le ) {
820         /* Only a local entry: remote was deleted
821          * Ought to delete the local too...
822          */
823                 rc = 0;
824         } else if ( tc->step & USE_LIST ) {
825         /* Only a remote entry, but both filters:
826          * Test the complete filter
827          */
828                 rc = test_filter( op, rs->sr_entry, tc->orig );
829                 if ( rc == LDAP_COMPARE_TRUE ) {
830                         rc = SLAP_CB_CONTINUE;
831                 } else {
832                         rc = 0;
833                 }
834         } else {
835         /* Only a remote entry, only remote filter:
836          * just pass thru
837          */
838                 rc = SLAP_CB_CONTINUE;
839         }
840
841         op->o_bd = db;
842         return rc;
843 }
844
845 /* Dup the filter, excluding invalid elements */
846 static Filter *
847 trans_filter_dup(Operation *op, Filter *f, AttributeName *an)
848 {
849         Filter *n = NULL;
850
851         if ( !f )
852                 return NULL;
853
854         switch( f->f_choice & SLAPD_FILTER_MASK ) {
855         case SLAPD_FILTER_COMPUTED:
856                 n = op->o_tmpalloc( sizeof(Filter), op->o_tmpmemctx );
857                 n->f_choice = f->f_choice;
858                 n->f_result = f->f_result;
859                 n->f_next = NULL;
860                 break;
861
862         case LDAP_FILTER_PRESENT:
863                 if ( ad_inlist( f->f_desc, an )) {
864                         n = op->o_tmpalloc( sizeof(Filter), op->o_tmpmemctx );
865                         n->f_choice = f->f_choice;
866                         n->f_desc = f->f_desc;
867                         n->f_next = NULL;
868                 }
869                 break;
870
871         case LDAP_FILTER_EQUALITY:
872         case LDAP_FILTER_GE:
873         case LDAP_FILTER_LE:
874         case LDAP_FILTER_APPROX:
875         case LDAP_FILTER_SUBSTRINGS:
876         case LDAP_FILTER_EXT:
877                 if ( !f->f_av_desc || ad_inlist( f->f_av_desc, an )) {
878                         n = op->o_tmpalloc( sizeof(Filter), op->o_tmpmemctx );
879                         n->f_choice = f->f_choice;
880                         n->f_ava = f->f_ava;
881                         n->f_next = NULL;
882                 }
883                 break;
884
885         case LDAP_FILTER_AND:
886         case LDAP_FILTER_OR:
887         case LDAP_FILTER_NOT: {
888                 Filter **p;
889
890                 n = op->o_tmpalloc( sizeof(Filter), op->o_tmpmemctx );
891                 n->f_choice = f->f_choice;
892                 n->f_next = NULL;
893
894                 for ( p = &n->f_list, f = f->f_list; f; f = f->f_next ) {
895                         *p = trans_filter_dup( op, f, an );
896                         if ( !*p )
897                                 continue;
898                         p = &(*p)->f_next;
899                 }
900                 /* nothing valid in this list */
901                 if ( !n->f_list ) {
902                         op->o_tmpfree( n, op->o_tmpmemctx );
903                         return NULL;
904                 }
905                 /* Only 1 element in this list */
906                 if ((n->f_choice & SLAPD_FILTER_MASK) != LDAP_FILTER_NOT &&
907                         !n->f_list->f_next ) {
908                         f = n->f_list;
909                         *n = *f;
910                         op->o_tmpfree( f, op->o_tmpmemctx );
911                 }
912                 break;
913         }
914         }
915         return n;
916 }
917
918 static void
919 trans_filter_free( Operation *op, Filter *f )
920 {
921         Filter *n, *p, *next;
922
923         f->f_choice &= SLAPD_FILTER_MASK;
924
925         switch( f->f_choice ) {
926         case LDAP_FILTER_AND:
927         case LDAP_FILTER_OR:
928         case LDAP_FILTER_NOT:
929                 /* Free in reverse order */
930                 n = NULL;
931                 for ( p = f->f_list; p; p = next ) {
932                         next = p->f_next;
933                         p->f_next = n;
934                         n = p;
935                 }
936                 for ( p = n; p; p = next ) {
937                         next = p->f_next;
938                         trans_filter_free( op, p );
939                 }
940                 break;
941         default:
942                 break;
943         }
944         op->o_tmpfree( f, op->o_tmpmemctx );
945 }
946
947 /*
948 ** translucent_search()
949 **      search via captive backend;
950 **      override results with any local data;
951 **
952 */
953
954 static int translucent_search(Operation *op, SlapReply *rs) {
955         slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
956         translucent_info *ov = on->on_bi.bi_private;
957         slap_callback cb = { NULL, NULL, NULL, NULL };
958         trans_ctx tc;
959         Filter *fl, *fr;
960         struct berval fbv;
961         int rc = 0;
962
963         Debug(LDAP_DEBUG_TRACE, "==> translucent_search: <%s> %s\n",
964                 op->o_req_dn.bv_val, op->ors_filterstr.bv_val, 0);
965
966         if(ov->defer_db_open) {
967                 send_ldap_error(op, rs, LDAP_UNAVAILABLE,
968                         "remote DB not available");
969                 return(rs->sr_err);
970         }
971
972         fr = ov->remote ? trans_filter_dup( op, op->ors_filter, ov->remote ) : NULL;
973         fl = ov->local ? trans_filter_dup( op, op->ors_filter, ov->local ) : NULL;
974         cb.sc_response = (slap_response *) translucent_search_cb;
975         cb.sc_private = &tc;
976         cb.sc_next = op->o_callback;
977
978         tc.db = op->o_bd;
979         tc.on = on;
980         tc.orig = op->ors_filter;
981         tc.list = NULL;
982         tc.step = 0;
983         fbv = op->ors_filterstr;
984
985         op->o_callback = &cb;
986
987         if ( fr || !fl ) {
988                 op->o_bd = &ov->db;
989                 tc.step |= RMT_SIDE;
990                 if ( fl ) {
991                         tc.step |= USE_LIST;
992                         op->ors_filter = fr;
993                         filter2bv_x( op, fr, &op->ors_filterstr );
994                 }
995                 rc = ov->db.bd_info->bi_op_search(op, rs);
996                 op->o_bd = tc.db;
997                 if ( fl ) {
998                         op->o_tmpfree( op->ors_filterstr.bv_val, op->o_tmpmemctx );
999                 }
1000         }
1001         if ( fl && !rc ) {
1002                 tc.step |= LCL_SIDE;
1003                 op->ors_filter = fl;
1004                 filter2bv_x( op, fl, &op->ors_filterstr );
1005                 rc = overlay_op_walk( op, rs, op_search, on->on_info, on->on_next );
1006                 op->o_tmpfree( op->ors_filterstr.bv_val, op->o_tmpmemctx );
1007         }
1008         op->ors_filterstr = fbv;
1009         op->ors_filter = tc.orig;
1010         op->o_callback = cb.sc_next;
1011         /* Send out anything remaining on the list and finish */
1012         if ( tc.step & USE_LIST ) {
1013                 if ( tc.list ) {
1014                         Avlnode *av;
1015
1016                         av = tavl_end( tc.list, TAVL_DIR_LEFT );
1017                         while ( av ) {
1018                                 rs->sr_entry = av->avl_data;
1019                                 rc = test_filter( op, rs->sr_entry, op->ors_filter );
1020                                 if ( rc == LDAP_COMPARE_TRUE ) {
1021                                         rs->sr_flags = REP_ENTRY_MUSTBEFREED;
1022                                         rc = send_search_entry( op, rs );
1023                                         if ( rc ) break;
1024                                 } else {
1025                                         entry_free( rs->sr_entry );
1026                                 }
1027                                 av = tavl_next( av, TAVL_DIR_RIGHT );
1028                         }
1029                         tavl_free( tc.list, NULL );
1030                         rs->sr_entry = NULL;
1031                 }
1032                 send_ldap_result( op, rs );
1033         }
1034
1035         /* Free in reverse order */
1036         if ( fl )
1037                 trans_filter_free( op, fl );
1038         if ( fr )
1039                 trans_filter_free( op, fr );
1040
1041         return rc;
1042 }
1043
1044
1045 /*
1046 ** translucent_bind()
1047 **      pass bind request to captive backend;
1048 **
1049 */
1050
1051 static int translucent_bind(Operation *op, SlapReply *rs) {
1052         slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
1053         translucent_info *ov = on->on_bi.bi_private;
1054         BackendDB *db;
1055         slap_callback sc = { 0 }, *save_cb;
1056         int rc;
1057
1058         Debug(LDAP_DEBUG_TRACE, "translucent_bind: <%s> method %d\n",
1059                 op->o_req_dn.bv_val, op->orb_method, 0);
1060
1061         if(ov->defer_db_open) {
1062                 send_ldap_error(op, rs, LDAP_UNAVAILABLE,
1063                         "remote DB not available");
1064                 return(rs->sr_err);
1065         }
1066
1067         if (ov->bind_local) {
1068                 sc.sc_response = slap_null_cb;
1069                 save_cb = op->o_callback;
1070                 op->o_callback = &sc;
1071         }
1072
1073         db = op->o_bd;
1074         op->o_bd = &ov->db;
1075         rc = ov->db.bd_info->bi_op_bind(op, rs);
1076         op->o_bd = db;
1077
1078         if (ov->bind_local) {
1079                 op->o_callback = save_cb;
1080                 if (rc != LDAP_SUCCESS) {
1081                         rc = SLAP_CB_CONTINUE;
1082                 }
1083         }
1084
1085         return rc;
1086 }
1087
1088 /*
1089 ** translucent_connection_destroy()
1090 **      pass disconnect notification to captive backend;
1091 **
1092 */
1093
1094 static int translucent_connection_destroy(BackendDB *be, Connection *conn) {
1095         slap_overinst *on = (slap_overinst *) be->bd_info;
1096         translucent_info *ov = on->on_bi.bi_private;
1097         int rc = 0;
1098
1099         Debug(LDAP_DEBUG_TRACE, "translucent_connection_destroy\n", 0, 0, 0);
1100
1101         rc = ov->db.bd_info->bi_connection_destroy(&ov->db, conn);
1102
1103         return(rc);
1104 }
1105
1106 /*
1107 ** translucent_db_config()
1108 **      pass config directives to captive backend;
1109 **      parse unrecognized directives ourselves;
1110 **
1111 */
1112
1113 static int translucent_db_config(
1114         BackendDB       *be,
1115         const char      *fname,
1116         int             lineno,
1117         int             argc,
1118         char            **argv
1119 )
1120 {
1121         slap_overinst *on = (slap_overinst *) be->bd_info;
1122         translucent_info *ov = on->on_bi.bi_private;
1123
1124         Debug(LDAP_DEBUG_TRACE, "==> translucent_db_config: %s\n",
1125               argc ? argv[0] : "", 0, 0);
1126
1127         /* Something for the captive database? */
1128         if ( ov->db.bd_info && ov->db.bd_info->bi_db_config )
1129                 return ov->db.bd_info->bi_db_config( &ov->db, fname, lineno,
1130                         argc, argv );
1131         return SLAP_CONF_UNKNOWN;
1132 }
1133
1134 /*
1135 ** translucent_db_init()
1136 **      initialize the captive backend;
1137 **
1138 */
1139
1140 static int translucent_db_init(BackendDB *be, ConfigReply *cr) {
1141         slap_overinst *on = (slap_overinst *) be->bd_info;
1142         translucent_info *ov;
1143
1144         Debug(LDAP_DEBUG_TRACE, "==> translucent_db_init\n", 0, 0, 0);
1145
1146         ov = ch_calloc(1, sizeof(translucent_info));
1147         on->on_bi.bi_private = ov;
1148         ov->db = *be;
1149         ov->db.be_private = NULL;
1150         ov->db.be_pcl_mutexp = &ov->db.be_pcl_mutex;
1151         ov->defer_db_open = 1;
1152
1153         if ( !backend_db_init( "ldap", &ov->db, -1, NULL )) {
1154                 Debug( LDAP_DEBUG_CONFIG, "translucent: unable to open captive back-ldap\n", 0, 0, 0);
1155                 return 1;
1156         }
1157         SLAP_DBFLAGS(be) |= SLAP_DBFLAG_NO_SCHEMA_CHECK;
1158         SLAP_DBFLAGS(be) |= SLAP_DBFLAG_NOLASTMOD;
1159
1160         return 0;
1161 }
1162
1163 /*
1164 ** translucent_db_open()
1165 **      if the captive backend has an open() method, call it;
1166 **
1167 */
1168
1169 static int translucent_db_open(BackendDB *be, ConfigReply *cr) {
1170         slap_overinst *on = (slap_overinst *) be->bd_info;
1171         translucent_info *ov = on->on_bi.bi_private;
1172         int rc;
1173
1174         Debug(LDAP_DEBUG_TRACE, "==> translucent_db_open\n", 0, 0, 0);
1175
1176         /* need to inherit something from the original database... */
1177         ov->db.be_def_limit = be->be_def_limit;
1178         ov->db.be_limits = be->be_limits;
1179         ov->db.be_acl = be->be_acl;
1180         ov->db.be_dfltaccess = be->be_dfltaccess;
1181
1182         if ( ov->defer_db_open )
1183                 return 0;
1184
1185         rc = backend_startup_one( &ov->db, cr );
1186
1187         if(rc) Debug(LDAP_DEBUG_TRACE,
1188                 "translucent: bi_db_open() returned error %d\n", rc, 0, 0);
1189
1190         return(rc);
1191 }
1192
1193 /*
1194 ** translucent_db_close()
1195 **      if the captive backend has a close() method, call it
1196 **
1197 */
1198
1199 static int
1200 translucent_db_close( BackendDB *be, ConfigReply *cr )
1201 {
1202         slap_overinst *on = (slap_overinst *) be->bd_info;
1203         translucent_info *ov = on->on_bi.bi_private;
1204         int rc = 0;
1205
1206         Debug(LDAP_DEBUG_TRACE, "==> translucent_db_close\n", 0, 0, 0);
1207
1208         if ( ov && ov->db.bd_info && ov->db.bd_info->bi_db_close ) {
1209                 rc = ov->db.bd_info->bi_db_close(&ov->db, NULL);
1210         }
1211
1212         return(rc);
1213 }
1214
1215 /*
1216 ** translucent_db_destroy()
1217 **      if the captive backend has a db_destroy() method, call it;
1218 **      free any config data
1219 **
1220 */
1221
1222 static int
1223 translucent_db_destroy( BackendDB *be, ConfigReply *cr )
1224 {
1225         slap_overinst *on = (slap_overinst *) be->bd_info;
1226         translucent_info *ov = on->on_bi.bi_private;
1227         int rc = 0;
1228
1229         Debug(LDAP_DEBUG_TRACE, "==> translucent_db_destroy\n", 0, 0, 0);
1230
1231         if ( ov ) {
1232                 if ( ov->remote )
1233                         anlist_free( ov->remote, 1, NULL );
1234                 if ( ov->local )
1235                         anlist_free( ov->local, 1, NULL );
1236                 if ( ov->db.be_private != NULL ) {
1237                         backend_stopdown_one( &ov->db );
1238                 }
1239
1240                 ch_free(ov);
1241                 on->on_bi.bi_private = NULL;
1242         }
1243
1244         return(rc);
1245 }
1246
1247 /*
1248 ** translucent_initialize()
1249 **      initialize the slap_overinst with our entry points;
1250 **
1251 */
1252
1253 int translucent_initialize() {
1254
1255         int rc;
1256
1257         Debug(LDAP_DEBUG_TRACE, "==> translucent_initialize\n", 0, 0, 0);
1258
1259         translucent.on_bi.bi_type       = "translucent";
1260         translucent.on_bi.bi_db_init    = translucent_db_init;
1261         translucent.on_bi.bi_db_config  = translucent_db_config;
1262         translucent.on_bi.bi_db_open    = translucent_db_open;
1263         translucent.on_bi.bi_db_close   = translucent_db_close;
1264         translucent.on_bi.bi_db_destroy = translucent_db_destroy;
1265         translucent.on_bi.bi_op_bind    = translucent_bind;
1266         translucent.on_bi.bi_op_add     = translucent_add;
1267         translucent.on_bi.bi_op_modify  = translucent_modify;
1268         translucent.on_bi.bi_op_modrdn  = translucent_modrdn;
1269         translucent.on_bi.bi_op_delete  = translucent_delete;
1270         translucent.on_bi.bi_op_search  = translucent_search;
1271         translucent.on_bi.bi_op_compare = translucent_compare;
1272         translucent.on_bi.bi_connection_destroy = translucent_connection_destroy;
1273
1274         translucent.on_bi.bi_cf_ocs = translucentocs;
1275         rc = config_register_schema ( translucentcfg, translucentocs );
1276         if ( rc ) return rc;
1277
1278         return(overlay_register(&translucent));
1279 }
1280
1281 #if SLAPD_OVER_TRANSLUCENT == SLAPD_MOD_DYNAMIC && defined(PIC)
1282 int init_module(int argc, char *argv[]) {
1283         return translucent_initialize();
1284 }
1285 #endif
1286
1287 #endif /* SLAPD_OVER_TRANSLUCENT */