]> git.sur5r.net Git - openldap/blob - servers/slapd/overlays/rwm.c
first step towards removing back-*/external.h
[openldap] / servers / slapd / overlays / rwm.c
1 /* rwm.c - rewrite/remap operations */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 2003-2004 The OpenLDAP Foundation.
6  * Portions Copyright 2003 Pierangelo Masarati.
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
18 #include "portable.h"
19
20 #ifdef SLAPD_OVER_RWM
21
22 #include <stdio.h>
23
24 #include <ac/string.h>
25
26 #include "slap.h"
27 #include "rwm.h"
28
29 static int
30 rwm_op_dn_massage( Operation *op, SlapReply *rs, void *cookie )
31 {
32         slap_overinst           *on = (slap_overinst *) op->o_bd->bd_info;
33         struct ldaprwmap        *rwmap = 
34                         (struct ldaprwmap *)on->on_bi.bi_private;
35
36         struct berval           dn = BER_BVNULL,
37                                 *dnp = NULL,
38                                 ndn = BER_BVNULL;
39         int                     rc = 0;
40         dncookie                dc;
41
42         /*
43          * Rewrite the dn if needed
44          */
45         dc.rwmap = rwmap;
46 #ifdef ENABLE_REWRITE
47         dc.conn = op->o_conn;
48         dc.rs = rs;
49         dc.ctx = (char *)cookie;
50 #else /* ! ENABLE_REWRITE */
51         dc.tofrom = ((int *)cookie)[0];
52         dc.normalized = 0;
53 #endif /* ! ENABLE_REWRITE */
54
55         /* NOTE: in those cases where only the ndn is available,
56          * and the caller sets op->o_req_dn = op->o_req_ndn,
57          * only rewrite the op->o_req_ndn and use it as 
58          * op->o_req_dn as well */
59         if ( op->o_req_dn.bv_val != op->o_req_ndn.bv_val ) {
60                 dnp = &dn;
61         }
62
63         rc = rwm_dn_massage( &dc, &op->o_req_dn, dnp, &ndn );
64         if ( rc != LDAP_SUCCESS ) {
65                 return rc;
66         }
67
68         if ( ( dnp && dn.bv_val == op->o_req_dn.bv_val ) ||
69                 ( !dnp && ndn.bv_val == op->o_req_ndn.bv_val ) ) {
70                 return LDAP_SUCCESS;
71         }
72
73         op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );
74         if ( dnp ) {
75                 op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx );
76                 op->o_req_dn = dn;
77         } else {
78                 op->o_req_dn = ndn;
79         }
80         op->o_req_ndn = ndn;
81
82         return LDAP_SUCCESS;
83 }
84
85 static int
86 rwm_add( Operation *op, SlapReply *rs )
87 {
88         slap_overinst           *on = (slap_overinst *) op->o_bd->bd_info;
89         struct ldaprwmap        *rwmap = 
90                         (struct ldaprwmap *)on->on_bi.bi_private;
91
92         int                     rc,
93                                 i;
94         Attribute               **ap = NULL;
95         char                    *olddn = op->o_req_dn.bv_val;
96
97 #ifdef ENABLE_REWRITE
98         rc = rwm_op_dn_massage( op, rs, "addDN" );
99 #else /* ! ENABLE_REWRITE */
100         rc = 1;
101         rc = rwm_op_dn_massage( op, rs, &rc );
102 #endif /* ! ENABLE_REWRITE */
103         if ( rc != LDAP_SUCCESS ) {
104                 op->o_bd->bd_info = (BackendInfo *)on->on_info;
105                 send_ldap_error( op, rs, rc, "addDN massage error" );
106                 return -1;
107         }
108
109         if ( olddn != op->o_req_dn.bv_val ) {
110                 ch_free( op->ora_e->e_name.bv_val );
111                 ch_free( op->ora_e->e_nname.bv_val );
112
113                 ber_dupbv( &op->ora_e->e_name, &op->o_req_dn );
114                 ber_dupbv( &op->ora_e->e_nname, &op->o_req_ndn );
115         }
116
117         /* Count number of attributes in entry */ 
118         for ( i = 0, ap = &op->oq_add.rs_e->e_attrs; *ap; ) {
119                 struct berval   mapped;
120                 Attribute       *a;
121
122                 if ( (*ap)->a_desc->ad_type->sat_no_user_mod ) {
123                         goto next_attr;
124                 }
125
126                 rwm_map( &rwmap->rwm_at, &(*ap)->a_desc->ad_cname,
127                                 &mapped, RWM_MAP );
128                 if ( BER_BVISNULL( &mapped ) || BER_BVISEMPTY( &mapped ) ) {
129                         goto cleanup_attr;
130                 }
131
132                 if ( (*ap)->a_desc->ad_type->sat_syntax
133                                 == slap_schema.si_syn_distinguishedName )
134                 {
135                         /*
136                          * FIXME: rewrite could fail; in this case
137                          * the operation should give up, right?
138                          */
139 #ifdef ENABLE_REWRITE
140                         rc = rwm_dnattr_rewrite( op, rs, "addAttrDN",
141                                         (*ap)->a_vals,
142                                         (*ap)->a_nvals ? &(*ap)->a_nvals : NULL );
143 #else /* ! ENABLE_REWRITE */
144                         rc = 1;
145                         rc = rwm_dnattr_rewrite( op, rs, &rc, (*ap)->a_vals,
146                                         (*ap)->a_nvals ? &(*ap)->a_nvals : NULL );
147 #endif /* ! ENABLE_REWRITE */
148                         if ( rc ) {
149                                 goto cleanup_attr;
150                         }
151
152                 } else if ( (*ap)->a_desc == slap_schema.si_ad_ref ) {
153 #ifdef ENABLE_REWRITE
154                         rc = rwm_referral_rewrite( op, rs, "referralAttrDN",
155                                         (*ap)->a_vals,
156                                         (*ap)->a_nvals ? &(*ap)->a_nvals : NULL );
157 #else /* ! ENABLE_REWRITE */
158                         rc = 1;
159                         rc = rwm_referral_rewrite( op, rs, &rc, (*ap)->a_vals,
160                                         (*ap)->a_nvals ? &(*ap)->a_nvals : NULL );
161 #endif /* ! ENABLE_REWRITE */
162                         if ( rc != LDAP_SUCCESS ) {
163                                 goto cleanup_attr;
164                         }
165                 }
166
167
168 next_attr:;
169                 ap = &(*ap)->a_next;
170                 continue;
171
172 cleanup_attr:;
173                 /* FIXME: leaking attribute/values? */
174                 a = *ap;
175
176                 *ap = (*ap)->a_next;
177                 attr_free( a );
178         }
179
180         /* TODO: map attribute types, values of DN-valued attributes ... */
181         return SLAP_CB_CONTINUE;
182 }
183
184 static int
185 rwm_bind( Operation *op, SlapReply *rs )
186 {
187         slap_overinst           *on = (slap_overinst *) op->o_bd->bd_info;
188         struct ldaprwmap        *rwmap = 
189                         (struct ldaprwmap *)on->on_bi.bi_private;
190         int                     rc;
191
192 #ifdef ENABLE_REWRITE
193         ( void )rewrite_session_delete( rwmap->rwm_rw, op->o_conn );
194         ( void )rewrite_session_init( rwmap->rwm_rw, op->o_conn );
195
196         rc = rwm_op_dn_massage( op, rs, "bindDN" );
197 #else /* ! ENABLE_REWRITE */
198         rc = 1;
199         rc = rwm_op_dn_massage( op, rs, &rc );
200 #endif /* ! ENABLE_REWRITE */
201         if ( rc != LDAP_SUCCESS ) {
202                 op->o_bd->bd_info = (BackendInfo *)on->on_info;
203                 send_ldap_error( op, rs, rc, "bindDN massage error" );
204                 return -1;
205         }
206
207         return SLAP_CB_CONTINUE;
208 }
209
210 static int
211 rwm_unbind( Operation *op, SlapReply *rs )
212 {
213         slap_overinst           *on = (slap_overinst *) op->o_bd->bd_info;
214         struct ldaprwmap        *rwmap = 
215                         (struct ldaprwmap *)on->on_bi.bi_private;
216
217 #ifdef ENABLE_REWRITE
218         rewrite_session_delete( rwmap->rwm_rw, op->o_conn );
219 #endif /* ENABLE_REWRITE */
220
221         return SLAP_CB_CONTINUE;
222 }
223
224 static int
225 rwm_compare( Operation *op, SlapReply *rs )
226 {
227         slap_overinst           *on = (slap_overinst *) op->o_bd->bd_info;
228         struct ldaprwmap        *rwmap = 
229                         (struct ldaprwmap *)on->on_bi.bi_private;
230
231         int                     rc;
232         struct berval           mapped_at = BER_BVNULL,
233                                 mapped_vals[2] = { BER_BVNULL, BER_BVNULL };
234
235 #ifdef ENABLE_REWRITE
236         rc = rwm_op_dn_massage( op, rs, "compareDN" );
237 #else /* ! ENABLE_REWRITE */
238         rc = 1;
239         rc = rwm_op_dn_massage( op, rs, &rc );
240 #endif /* ! ENABLE_REWRITE */
241         if ( rc != LDAP_SUCCESS ) {
242                 op->o_bd->bd_info = (BackendInfo *)on->on_info;
243                 send_ldap_error( op, rs, rc, "compareDN massage error" );
244                 return -1;
245         }
246
247         /* if the attribute is an objectClass, try to remap its value */
248         if ( op->orc_ava->aa_desc == slap_schema.si_ad_objectClass
249                         || op->orc_ava->aa_desc == slap_schema.si_ad_structuralObjectClass )
250         {
251                 rwm_map( &rwmap->rwm_oc, &op->orc_ava->aa_value,
252                                 &mapped_vals[0], RWM_MAP );
253                 if ( BER_BVISNULL( &mapped_vals[0] ) || BER_BVISEMPTY( &mapped_vals[0] ) )
254                 {
255                         op->o_bd->bd_info = (BackendInfo *)on->on_info;
256                         send_ldap_error( op, rs, LDAP_OTHER, "compare objectClass map error" );
257                         return -1;
258
259                 } else if ( mapped_vals[0].bv_val != op->orc_ava->aa_value.bv_val ) {
260                         free( op->orc_ava->aa_value.bv_val );
261                         op->orc_ava->aa_value = mapped_vals[0];
262                 }
263                 mapped_at = op->orc_ava->aa_desc->ad_cname;
264
265         } else {
266                 rwm_map( &rwmap->rwm_at, &op->orc_ava->aa_desc->ad_cname,
267                                 &mapped_at, RWM_MAP );
268                 if ( BER_BVISNULL( &mapped_at ) || BER_BVISEMPTY( &mapped_at ) )
269                 {
270                         op->o_bd->bd_info = (BackendInfo *)on->on_info;
271                         send_ldap_error( op, rs, LDAP_OTHER, "compare attributeType map error" );
272                         return -1;
273                 }
274                 if ( op->orc_ava->aa_desc->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName )
275                 {
276                         struct berval   *mapped_valsp[2];
277                         
278                         mapped_valsp[0] = &mapped_vals[0];
279                         mapped_valsp[1] = &mapped_vals[1];
280
281                         mapped_vals[0] = op->orc_ava->aa_value;
282
283 #ifdef ENABLE_REWRITE
284                         rc = rwm_dnattr_rewrite( op, rs, "compareAttrDN", NULL, mapped_valsp );
285 #else /* ! ENABLE_REWRITE */
286                         rc = 1;
287                         rc = rwm_dnattr_rewrite( op, rs, &rc, NULL, mapped_valsp );
288 #endif /* ! ENABLE_REWRITE */
289
290                         if ( rc != LDAP_SUCCESS ) {
291                                 op->o_bd->bd_info = (BackendInfo *)on->on_info;
292                                 send_ldap_error( op, rs, rc, "compareAttrDN massage error" );
293                                 return -1;
294                         }
295
296                         op->orc_ava->aa_value = mapped_vals[0];
297                 }
298         }
299
300         return SLAP_CB_CONTINUE;
301 }
302
303 static int
304 rwm_delete( Operation *op, SlapReply *rs )
305 {
306         slap_overinst           *on = (slap_overinst *) op->o_bd->bd_info;
307         int                     rc;
308
309 #ifdef ENABLE_REWRITE
310         rc = rwm_op_dn_massage( op, rs, "deleteDN" );
311 #else /* ! ENABLE_REWRITE */
312         rc = 1;
313         rc = rwm_op_dn_massage( op, rs, &rc );
314 #endif /* ! ENABLE_REWRITE */
315         if ( rc != LDAP_SUCCESS ) {
316                 op->o_bd->bd_info = (BackendInfo *)on->on_info;
317                 send_ldap_error( op, rs, rc, "deleteDN massage error" );
318                 return -1;
319         }
320
321         return SLAP_CB_CONTINUE;
322 }
323
324 static int
325 rwm_modify( Operation *op, SlapReply *rs )
326 {
327         slap_overinst           *on = (slap_overinst *) op->o_bd->bd_info;
328         struct ldaprwmap        *rwmap = 
329                         (struct ldaprwmap *)on->on_bi.bi_private;
330
331         Modifications           **mlp;
332         int                     rc;
333
334 #ifdef ENABLE_REWRITE
335         rc = rwm_op_dn_massage( op, rs, "modifyDN" );
336 #else /* ! ENABLE_REWRITE */
337         rc = 1;
338         rc = rwm_op_dn_massage( op, rs, &rc );
339 #endif /* ! ENABLE_REWRITE */
340         if ( rc != LDAP_SUCCESS ) {
341                 op->o_bd->bd_info = (BackendInfo *)on->on_info;
342                 send_ldap_error( op, rs, rc, "modifyDN massage error" );
343                 return -1;
344         }
345
346         for ( mlp = &op->oq_modify.rs_modlist; *mlp; ) {
347                 int             is_oc = 0;
348                 Modifications   *ml;
349
350                 if ( (*mlp)->sml_desc->ad_type->sat_no_user_mod  ) {
351                         goto next_mod;
352                 }
353
354                 if ( (*mlp)->sml_desc == slap_schema.si_ad_objectClass 
355                                 || (*mlp)->sml_desc == slap_schema.si_ad_structuralObjectClass ) {
356                         is_oc = 1;
357
358                 } else {
359                         struct ldapmapping      *m;
360                         int                     drop_missing;
361
362                         drop_missing = rwm_mapping( &rwmap->rwm_at, &(*mlp)->sml_desc->ad_cname, &m, RWM_MAP );
363                         if ( drop_missing || ( m != NULL && BER_BVISNULL( &m->m_dst ) ) )
364                         {
365                                 goto cleanup_mod;
366                         }
367
368                         if ( m ) {
369                                 /* use new attribute description */
370                                 assert( m->m_dst_ad );
371                                 (*mlp)->sml_desc = m->m_dst_ad;
372                         }
373                 }
374
375                 if ( (*mlp)->sml_values != NULL ) {
376                         if ( is_oc ) {
377                                 int     last, j;
378
379                                 for ( last = 0; !BER_BVISNULL( &(*mlp)->sml_values[last] ); last++ )
380                                         /* count values */ ;
381                                 last--;
382
383                                 for ( j = 0; !BER_BVISNULL( &(*mlp)->sml_values[j] ); j++ ) {
384                                         struct berval   mapped = BER_BVNULL;
385
386                                         rwm_map( &rwmap->rwm_oc,
387                                                         &(*mlp)->sml_values[j],
388                                                         &mapped, RWM_MAP );
389                                         if ( BER_BVISNULL( &mapped ) || BER_BVISEMPTY( &mapped ) ) {
390                                                 /* FIXME: we allow to remove objectClasses as well;
391                                                  * if the resulting entry is inconsistent, that's
392                                                  * the relayed database's business...
393                                                  */
394 #if 0
395                                                 goto cleanup_mod;
396 #endif
397                                                 if ( last > j ) {
398                                                         (*mlp)->sml_values[j] = (*mlp)->sml_values[last];
399                                                         BER_BVZERO( &(*mlp)->sml_values[last] );
400                                                 }
401                                                 last--;
402
403                                         } else {
404                                                 ch_free( (*mlp)->sml_values[j].bv_val );
405                                                 ber_dupbv( &(*mlp)->sml_values[j], &mapped );
406                                         }
407                                 }
408
409                         } else {
410                                 if ( (*mlp)->sml_desc->ad_type->sat_syntax ==
411                                                 slap_schema.si_syn_distinguishedName )
412                                 {
413 #ifdef ENABLE_REWRITE
414                                         rc = rwm_dnattr_rewrite( op, rs, "modifyAttrDN",
415                                                         (*mlp)->sml_values,
416                                                         (*mlp)->sml_nvalues ? &(*mlp)->sml_nvalues : NULL );
417 #else /* ! ENABLE_REWRITE */
418                                         rc = 1;
419                                         rc = rwm_dnattr_rewrite( op, rs, &rc, 
420                                                         (*mlp)->sml_values,
421                                                         (*mlp)->sml_nvalues ? &(*mlp)->sml_nvalues : NULL );
422 #endif /* ! ENABLE_REWRITE */
423
424                                 } else if ( (*mlp)->sml_desc == slap_schema.si_ad_ref ) {
425 #ifdef ENABLE_REWRITE
426                                         rc = rwm_referral_rewrite( op, rs,
427                                                         "referralAttrDN",
428                                                         (*mlp)->sml_values,
429                                                         (*mlp)->sml_nvalues ? &(*mlp)->sml_nvalues : NULL );
430 #else /* ! ENABLE_REWRITE */
431                                         rc = 1;
432                                         rc = rwm_referral_rewrite( op, rs, &rc,
433                                                         (*mlp)->sml_values,
434                                                         (*mlp)->sml_nvalues ? &(*mlp)->sml_nvalues : NULL );
435 #endif /* ! ENABLE_REWRITE */
436                                         if ( rc != LDAP_SUCCESS ) {
437                                                 goto cleanup_mod;
438                                         }
439                                 }
440
441                                 if ( rc != LDAP_SUCCESS ) {
442                                         goto cleanup_mod;
443                                 }
444                         }
445                 }
446
447 next_mod:;
448                 mlp = &(*mlp)->sml_next;
449                 continue;
450
451 cleanup_mod:;
452                 ml = *mlp;
453                 *mlp = (*mlp)->sml_next;
454                 slap_mod_free( &ml->sml_mod, 0 );
455                 free( ml );
456         }
457
458         /* TODO: rewrite attribute types, values of DN-valued attributes ... */
459         return SLAP_CB_CONTINUE;
460 }
461
462 static int
463 rwm_modrdn( Operation *op, SlapReply *rs )
464 {
465         slap_overinst           *on = (slap_overinst *) op->o_bd->bd_info;
466         struct ldaprwmap        *rwmap = 
467                         (struct ldaprwmap *)on->on_bi.bi_private;
468         
469         int                     rc;
470
471         if ( op->orr_newSup ) {
472                 dncookie        dc;
473                 struct berval   nnewSup = BER_BVNULL;
474                 struct berval   newSup = BER_BVNULL;
475
476                 /*
477                  * Rewrite the new superior, if defined and required
478                  */
479                 dc.rwmap = rwmap;
480 #ifdef ENABLE_REWRITE
481                 dc.conn = op->o_conn;
482                 dc.rs = rs;
483                 dc.ctx = "newSuperiorDN";
484 #else /* ! ENABLE_REWRITE */
485                 dc.tofrom = 0;
486                 dc.normalized = 0;
487 #endif /* ! ENABLE_REWRITE */
488                 rc = rwm_dn_massage( &dc, op->orr_newSup, &newSup, &nnewSup );
489                 if ( rc != LDAP_SUCCESS ) {
490                         op->o_bd->bd_info = (BackendInfo *)on->on_info;
491                         send_ldap_error( op, rs, rc, "newSuperiorDN massage error" );
492                         return -1;
493                 }
494
495                 if ( op->orr_newSup->bv_val != newSup.bv_val ) {
496                         op->o_tmpfree( op->orr_newSup->bv_val, op->o_tmpmemctx );
497                         op->o_tmpfree( op->orr_nnewSup->bv_val, op->o_tmpmemctx );
498                         *op->orr_newSup = newSup;
499                         *op->orr_nnewSup = nnewSup;
500                 }
501         }
502
503         /*
504          * Rewrite the dn, if needed
505          */
506 #ifdef ENABLE_REWRITE
507         rc = rwm_op_dn_massage( op, rs, "renameDN" );
508 #else /* ! ENABLE_REWRITE */
509         rc = 1;
510         rc = rwm_op_dn_massage( op, rs, &rc );
511 #endif /* ! ENABLE_REWRITE */
512         if ( rc != LDAP_SUCCESS ) {
513                 op->o_bd->bd_info = (BackendInfo *)on->on_info;
514                 send_ldap_error( op, rs, rc, "renameDN massage error" );
515                 return -1;
516         }
517
518         /* TODO: rewrite attribute types, values of DN-valued attributes ... */
519         return SLAP_CB_CONTINUE;
520 }
521
522 static int
523 rwm_swap_attrs( Operation *op, SlapReply *rs )
524 {
525         slap_callback   *cb = op->o_callback;
526         AttributeName   *an = (AttributeName *)cb->sc_private;
527
528         rs->sr_attrs = an;
529         
530         return SLAP_CB_CONTINUE;
531 }
532
533 static int rwm_freeself( Operation *op, SlapReply *rs )
534 {
535         if ( op->o_tag == LDAP_REQ_SEARCH && rs->sr_type == REP_RESULT ) {
536                 assert( op->o_callback );
537
538                 op->o_tmpfree( op->o_callback, op->o_tmpmemctx );
539                 op->o_callback = NULL;
540         }
541
542         return SLAP_CB_CONTINUE;
543 }
544
545 static int
546 rwm_search( Operation *op, SlapReply *rs )
547 {
548         slap_overinst           *on = (slap_overinst *) op->o_bd->bd_info;
549         struct ldaprwmap        *rwmap = 
550                         (struct ldaprwmap *)on->on_bi.bi_private;
551
552         int                     rc;
553         dncookie                dc;
554
555         struct berval           fstr = BER_BVNULL;
556         Filter                  *f = NULL;
557
558         slap_callback           *cb;
559         AttributeName           *an = NULL;
560
561         char                    *text = NULL;
562
563 #ifdef ENABLE_REWRITE
564         rc = rwm_op_dn_massage( op, rs, "searchDN" );
565 #else /* ! ENABLE_REWRITE */
566         rc = 1;
567         rc = rwm_op_dn_massage( op, rs, &rc );
568 #endif /* ! ENABLE_REWRITE */
569         if ( rc != LDAP_SUCCESS ) {
570                 text = "searchDN massage error";
571                 goto error_return;
572         }
573
574         /*
575          * Rewrite the dn if needed
576          */
577         dc.rwmap = rwmap;
578 #ifdef ENABLE_REWRITE
579         dc.conn = op->o_conn;
580         dc.rs = rs;
581         dc.ctx = "searchFilterAttrDN";
582 #else /* ! ENABLE_REWRITE */
583         dc.tofrom = 0;
584         dc.normalized = 0;
585 #endif /* ! ENABLE_REWRITE */
586
587         rc = rwm_filter_map_rewrite( &dc, op->ors_filter, &fstr );
588         if ( rc != LDAP_SUCCESS ) {
589                 text = "searchFilter/searchFilterAttrDN massage error";
590                 goto error_return;
591         }
592
593         f = str2filter_x( op, fstr.bv_val );
594
595         if ( f == NULL ) {
596                 text = "massaged filter parse error";
597                 goto error_return;
598         }
599
600         if ( !BER_BVISNULL( &op->ors_filterstr ) ) {
601                 ch_free( op->ors_filterstr.bv_val );
602         }
603
604         if( op->ors_filter ) {
605                 filter_free_x( op, op->ors_filter );
606         }
607
608         op->ors_filter = f;
609         op->ors_filterstr = fstr;
610
611         rc = rwm_map_attrnames( &rwmap->rwm_at, &rwmap->rwm_oc,
612                         op->ors_attrs, &an, RWM_MAP );
613         if ( rc != LDAP_SUCCESS ) {
614                 text = "attribute list mapping error";
615                 goto error_return;
616         }
617
618         cb = (slap_callback *) op->o_tmpcalloc( sizeof( slap_callback ),
619                         1, op->o_tmpmemctx );
620         if ( cb == NULL ) {
621                 rc = LDAP_NO_MEMORY;
622                 goto error_return;
623         }
624
625         cb->sc_response = rwm_swap_attrs;
626         cb->sc_cleanup = rwm_freeself;
627         cb->sc_private = (void *)op->ors_attrs;
628         cb->sc_next = op->o_callback;
629
630         op->o_callback = cb;
631         op->ors_attrs = an;
632
633         return SLAP_CB_CONTINUE;
634
635 error_return:;
636         if ( an != NULL ) {
637                 ch_free( an );
638         }
639
640         if ( f != NULL ) {
641                 filter_free_x( op, f );
642         }
643
644         if ( !BER_BVISNULL( &fstr ) ) {
645                 ch_free( fstr.bv_val );
646         }
647
648         op->o_bd->bd_info = (BackendInfo *)on->on_info;
649         send_ldap_error( op, rs, rc, text );
650
651         return -1;
652
653 }
654
655 static int
656 rwm_extended( Operation *op, SlapReply *rs )
657 {
658         slap_overinst           *on = (slap_overinst *) op->o_bd->bd_info;
659         int                     rc;
660
661 #ifdef ENABLE_REWRITE
662         rc = rwm_op_dn_massage( op, rs, "extendedDN" );
663 #else /* ! ENABLE_REWRITE */
664         rc = 1;
665         rc = rwm_op_dn_massage( op, rs, &rc );
666 #endif /* ! ENABLE_REWRITE */
667         if ( rc != LDAP_SUCCESS ) {
668                 op->o_bd->bd_info = (BackendInfo *)on->on_info;
669                 send_ldap_error( op, rs, rc, "extendedDN massage error" );
670                 return -1;
671         }
672
673         /* TODO: rewrite/map extended data ? ... */
674         return SLAP_CB_CONTINUE;
675 }
676
677 static int
678 rwm_matched( Operation *op, SlapReply *rs )
679 {
680         slap_overinst           *on = (slap_overinst *) op->o_bd->bd_info;
681         struct ldaprwmap        *rwmap = 
682                         (struct ldaprwmap *)on->on_bi.bi_private;
683
684         struct berval           dn, mdn;
685         dncookie                dc;
686         int                     rc;
687
688         if ( rs->sr_matched == NULL ) {
689                 return SLAP_CB_CONTINUE;
690         }
691
692         dc.rwmap = rwmap;
693 #ifdef ENABLE_REWRITE
694         dc.conn = op->o_conn;
695         dc.rs = rs;
696         dc.ctx = "matchedDN";
697 #else /* ! ENABLE_REWRITE */
698         dc.tofrom = 0;
699         dc.normalized = 0;
700 #endif /* ! ENABLE_REWRITE */
701         ber_str2bv( rs->sr_matched, 0, 0, &dn );
702         rc = rwm_dn_massage( &dc, &dn, &mdn, NULL );
703         if ( rc != LDAP_SUCCESS ) {
704                 rs->sr_err = rc;
705                 rs->sr_text = "Rewrite error";
706                 return 1;
707         }
708
709         if ( mdn.bv_val != dn.bv_val ) {
710                 if ( rs->sr_flags & REP_MATCHED_MUSTBEFREED ) {
711                         ch_free( (void *)rs->sr_matched );
712
713                 } else {
714                         rs->sr_flags |= REP_MATCHED_MUSTBEFREED;
715                 }
716                 rs->sr_matched = mdn.bv_val;
717         }
718         
719         return SLAP_CB_CONTINUE;
720 }
721
722 static int
723 rwm_attrs( Operation *op, SlapReply *rs, Attribute** a_first )
724 {
725         slap_overinst           *on = (slap_overinst *) op->o_bd->bd_info;
726         struct ldaprwmap        *rwmap = 
727                         (struct ldaprwmap *)on->on_bi.bi_private;
728
729         dncookie                dc;
730         int                     rc;
731         Attribute               **ap;
732
733         /*
734          * Rewrite the dn attrs, if needed
735          */
736         dc.rwmap = rwmap;
737 #ifdef ENABLE_REWRITE
738         dc.conn = op->o_conn;
739         dc.rs = NULL; 
740 #else /* ! ENABLE_REWRITE */
741         dc.tofrom = 0;
742         dc.normalized = 0;
743 #endif /* ! ENABLE_REWRITE */
744
745         /* FIXME: the entries are in the remote mapping form;
746          * so we need to select those attributes we are willing
747          * to return, and remap them accordingly */
748
749         /* FIXME: in principle, one could map an attribute
750          * on top of another, which already exists.
751          * As such, in the end there might exist more than
752          * one instance of an attribute.
753          * We should at least check if this occurs, and issue
754          * an error (because multiple instances of attrs in 
755          * response are not valid), or merge the values (what
756          * about duplicate values?) */
757         for ( ap = a_first; *ap; ) {
758                 struct ldapmapping      *m;
759                 int                     drop_missing;
760                 int                     last;
761                 Attribute               *a;
762
763                 if ( SLAP_OPATTRS( rs->sr_attr_flags ) && is_at_operational( (*ap)->a_desc->ad_type ) )
764                 {
765                         /* go on */ ;
766                         
767                 } else if ( op->ors_attrs != NULL && 
768                                 !SLAP_USERATTRS( rs->sr_attr_flags ) && 
769                                 !ad_inlist( (*ap)->a_desc, op->ors_attrs ) )
770                 {
771                         goto cleanup_attr;
772                 }
773
774                 if ( (*ap)->a_desc->ad_type->sat_no_user_mod ) {
775                         goto next_attr;
776                 }
777
778                 drop_missing = rwm_mapping( &rwmap->rwm_at,
779                                 &(*ap)->a_desc->ad_cname, &m, RWM_REMAP );
780                 if ( drop_missing || ( m != NULL && BER_BVISEMPTY( &m->m_dst ) ) ) {
781                         goto cleanup_attr;
782                 }
783
784                 for ( last = 0; !BER_BVISNULL( &(*ap)->a_vals[last] ); last++ )
785                         /* just count */ ;
786
787                 if ( last == 0 ) {
788                         /* empty? for now, we leave it in place */
789                         goto next_attr;
790                 }
791                 last--;
792
793                 if ( (*ap)->a_desc == slap_schema.si_ad_objectClass
794                                 || (*ap)->a_desc == slap_schema.si_ad_structuralObjectClass )
795                 {
796                         struct berval   *bv;
797                         
798                         for ( bv = (*ap)->a_vals; !BER_BVISNULL( bv ); bv++ ) {
799                                 struct berval   mapped;
800
801                                 rwm_map( &rwmap->rwm_oc, &bv[0], &mapped, RWM_REMAP );
802                                 if ( BER_BVISNULL( &mapped ) || BER_BVISEMPTY( &mapped ) ) {
803                                         ch_free( bv[0].bv_val );
804                                         BER_BVZERO( &bv[0] );
805                                         if ( &(*ap)->a_vals[last] > &bv[0] ) {
806                                                 bv[0] = (*ap)->a_vals[last];
807                                                 BER_BVZERO( &(*ap)->a_vals[last] );
808                                         }
809                                         last--;
810                                         bv--;
811
812                                 } else if ( mapped.bv_val != bv[0].bv_val ) {
813                                         /*
814                                          * FIXME: after LBER_FREEing
815                                          * the value is replaced by
816                                          * ch_alloc'ed memory
817                                          */
818                                         ch_free( bv[0].bv_val );
819                                         ber_dupbv( &bv[0], &mapped );
820                                 }
821                         }
822
823                 /*
824                  * It is necessary to try to rewrite attributes with
825                  * dn syntax because they might be used in ACLs as
826                  * members of groups; since ACLs are applied to the
827                  * rewritten stuff, no dn-based subject clause could
828                  * be used at the ldap backend side (see
829                  * http://www.OpenLDAP.org/faq/data/cache/452.html)
830                  * The problem can be overcome by moving the dn-based
831                  * ACLs to the target directory server, and letting
832                  * everything pass thru the ldap backend. */
833                 /* FIXME: handle distinguishedName-like syntaxes, like
834                  * nameAndOptionalUID */
835                 } else if ( (*ap)->a_desc->ad_type->sat_syntax ==
836                                 slap_schema.si_syn_distinguishedName )
837                 {
838 #ifdef ENABLE_REWRITE
839                         dc.ctx = "searchAttrDN";
840 #endif /* ENABLE_REWRITE */
841                         rc = rwm_dnattr_result_rewrite( &dc, (*ap)->a_vals );
842                         if ( rc != LDAP_SUCCESS ) {
843                                 goto cleanup_attr;
844                         }
845
846                 } else if ( (*ap)->a_desc == slap_schema.si_ad_ref ) {
847 #ifdef ENABLE_REWRITE
848                         dc.ctx = "searchAttrDN";
849 #endif /* ENABLE_REWRITE */
850                         rc = rwm_referral_result_rewrite( &dc, (*ap)->a_vals );
851                         if ( rc != LDAP_SUCCESS ) {
852                                 goto cleanup_attr;
853                         }
854                 }
855
856                 if ( m != NULL ) {
857                         /* rewrite the attribute description */
858                         assert( m->m_dst_ad );
859                         (*ap)->a_desc = m->m_dst_ad;
860                 }
861
862 next_attr:;
863                 ap = &(*ap)->a_next;
864                 continue;
865
866 cleanup_attr:;
867                 a = *ap;
868                 *ap = (*ap)->a_next;
869
870                 attr_free( a );
871         }
872
873         return 0;
874 }
875
876 static int
877 rwm_send_entry( Operation *op, SlapReply *rs )
878 {
879         slap_overinst           *on = (slap_overinst *) op->o_bd->bd_info;
880         struct ldaprwmap        *rwmap = 
881                         (struct ldaprwmap *)on->on_bi.bi_private;
882
883         Entry                   *e = NULL;
884         int                     flags;
885         struct berval           dn = BER_BVNULL,
886                                 ndn = BER_BVNULL;
887         dncookie                dc;
888         int                     rc;
889
890         assert( rs->sr_entry );
891
892         /*
893          * Rewrite the dn of the result, if needed
894          */
895         dc.rwmap = rwmap;
896 #ifdef ENABLE_REWRITE
897         dc.conn = op->o_conn;
898         dc.rs = NULL; 
899         dc.ctx = "searchEntryDN";
900 #else /* ! ENABLE_REWRITE */
901         dc.tofrom = 0;
902         dc.normalized = 0;
903 #endif /* ! ENABLE_REWRITE */
904
905         e = rs->sr_entry;
906         flags = rs->sr_flags;
907         if ( !( rs->sr_flags & REP_ENTRY_MODIFIABLE ) ) {
908                 /* FIXME: all we need to duplicate are:
909                  * - dn
910                  * - ndn
911                  * - attributes that are requested
912                  * - no values if attrsonly is set
913                  */
914
915                 e = entry_dup( e );
916                 if ( e == NULL ) {
917                         rc = LDAP_NO_MEMORY;
918                         goto fail;
919                 }
920
921                 flags |= ( REP_ENTRY_MODIFIABLE | REP_ENTRY_MUSTBEFREED );
922         }
923
924         /*
925          * Note: this may fail if the target host(s) schema differs
926          * from the one known to the meta, and a DN with unknown
927          * attributes is returned.
928          */
929         rc = rwm_dn_massage( &dc, &e->e_name, &dn, &ndn );
930         if ( rc != LDAP_SUCCESS ) {
931                 rc = 1;
932                 goto fail;
933         }
934
935         if ( e->e_name.bv_val != dn.bv_val ) {
936                 ch_free( e->e_name.bv_val );
937                 ch_free( e->e_nname.bv_val );
938
939                 e->e_name = dn;
940                 e->e_nname = ndn;
941         }
942
943         /* TODO: map entry attribute types, objectclasses 
944          * and dn-valued attribute values */
945
946         /* FIXME: the entries are in the remote mapping form;
947          * so we need to select those attributes we are willing
948          * to return, and remap them accordingly */
949         (void)rwm_attrs( op, rs, &e->e_attrs );
950
951         rs->sr_entry = e;
952         rs->sr_flags = flags;
953
954         return SLAP_CB_CONTINUE;
955
956 fail:;
957         if ( !BER_BVISNULL( &dn ) ) {
958                 ch_free( dn.bv_val );
959         }
960
961         if ( !BER_BVISNULL( &ndn ) ) {
962                 ch_free( ndn.bv_val );
963         }
964
965         if ( e != NULL && e != rs->sr_entry ) {
966                 entry_free( e );
967         }
968
969         return rc;
970 }
971
972 static int
973 rwm_operational( Operation *op, SlapReply *rs )
974 {
975         /* FIXME: the entries are in the remote mapping form;
976          * so we need to select those attributes we are willing
977          * to return, and remap them accordingly */
978         if ( rs->sr_operational_attrs ) {
979                 rwm_attrs( op, rs, &rs->sr_operational_attrs );
980         }
981
982         return SLAP_CB_CONTINUE;
983 }
984
985 static int
986 rwm_rw_config(
987     BackendDB   *be,
988     const char  *fname,
989     int         lineno,
990     int         argc,
991     char        **argv
992 )
993 {
994 #ifdef ENABLE_REWRITE
995         slap_overinst           *on = (slap_overinst *) be->bd_info;
996         struct ldaprwmap        *rwmap = 
997                         (struct ldaprwmap *)on->on_bi.bi_private;
998
999         return rewrite_parse( rwmap->rwm_rw,
1000                                 fname, lineno, argc, argv );
1001
1002 #else /* !ENABLE_REWRITE */
1003         fprintf( stderr, "%s: line %d: rewrite capabilities "
1004                         "are not enabled\n", fname, lineno );
1005 #endif /* !ENABLE_REWRITE */
1006                 
1007         return 0;
1008 }
1009
1010 static int
1011 rwm_suffixmassage_config(
1012     BackendDB   *be,
1013     const char  *fname,
1014     int         lineno,
1015     int         argc,
1016     char        **argv
1017 )
1018 {
1019         slap_overinst           *on = (slap_overinst *) be->bd_info;
1020         struct ldaprwmap        *rwmap = 
1021                         (struct ldaprwmap *)on->on_bi.bi_private;
1022
1023         struct berval           bvnc, nvnc, pvnc, brnc, nrnc, prnc;
1024         int                     massaged;
1025 #ifdef ENABLE_REWRITE
1026         int                     rc;
1027 #endif /* ENABLE_REWRITE */
1028                 
1029         /*
1030          * syntax:
1031          * 
1032          *      suffixmassage [<suffix>] <massaged suffix>
1033          *
1034          * the [<suffix>] field must be defined as a valid suffix
1035          * for the current database;
1036          * the <massaged suffix> shouldn't have already been
1037          * defined as a valid suffix for the current server
1038          */
1039         if ( argc == 2 ) {
1040                 if ( be->be_suffix == NULL ) {
1041                         fprintf( stderr, "%s: line %d: "
1042                                        " \"suffixMassage [<suffix>]"
1043                                        " <massaged suffix>\" without "
1044                                        "<suffix> part requires database "
1045                                        "suffix be defined first.\n",
1046                                 fname, lineno );
1047                         return 1;
1048                 }
1049                 bvnc = be->be_suffix[ 0 ];
1050                 massaged = 1;
1051
1052         } else if ( argc == 3 ) {
1053                 ber_str2bv( argv[ 1 ], 0, 0, &bvnc );
1054                 massaged = 2;
1055
1056         } else  {
1057                 fprintf( stderr, "%s: line %d: syntax is"
1058                                " \"suffixMassage [<suffix>]"
1059                                " <massaged suffix>\"\n",
1060                         fname, lineno );
1061                 return 1;
1062         }
1063
1064         if ( dnPrettyNormal( NULL, &bvnc, &pvnc, &nvnc, NULL ) != LDAP_SUCCESS ) {
1065                 fprintf( stderr, "%s: line %d: suffix DN %s is invalid\n",
1066                         fname, lineno, bvnc.bv_val );
1067                 return 1;
1068         }
1069
1070         ber_str2bv( argv[ massaged ], 0, 0, &brnc );
1071         if ( dnPrettyNormal( NULL, &brnc, &prnc, &nrnc, NULL ) != LDAP_SUCCESS ) {
1072                 fprintf( stderr, "%s: line %d: suffix DN %s is invalid\n",
1073                                 fname, lineno, brnc.bv_val );
1074                 free( nvnc.bv_val );
1075                 free( pvnc.bv_val );
1076                 return 1;
1077         }
1078
1079 #ifdef ENABLE_REWRITE
1080         /*
1081          * The suffix massaging is emulated 
1082          * by means of the rewrite capabilities
1083          */
1084         rc = rwm_suffix_massage_config( rwmap->rwm_rw,
1085                         &pvnc, &nvnc, &prnc, &nrnc );
1086         free( nvnc.bv_val );
1087         free( pvnc.bv_val );
1088         free( nrnc.bv_val );
1089         free( prnc.bv_val );
1090
1091         return( rc );
1092
1093 #else /* !ENABLE_REWRITE */
1094         ber_bvarray_add( &rwmap->rwm_suffix_massage, &pvnc );
1095         ber_bvarray_add( &rwmap->rwm_suffix_massage, &nvnc );
1096                 
1097         ber_bvarray_add( &rwmap->rwm_suffix_massage, &prnc );
1098         ber_bvarray_add( &rwmap->rwm_suffix_massage, &nrnc );
1099 #endif /* !ENABLE_REWRITE */
1100
1101         return 0;
1102 }
1103
1104 static int
1105 rwm_m_config(
1106     BackendDB   *be,
1107     const char  *fname,
1108     int         lineno,
1109     int         argc,
1110     char        **argv
1111 )
1112 {
1113         slap_overinst           *on = (slap_overinst *) be->bd_info;
1114         struct ldaprwmap        *rwmap = 
1115                         (struct ldaprwmap *)on->on_bi.bi_private;
1116
1117         /* objectclass/attribute mapping */
1118         return rwm_map_config( &rwmap->rwm_oc,
1119                         &rwmap->rwm_at,
1120                         fname, lineno, argc, argv );
1121 }
1122
1123 static int
1124 rwm_response( Operation *op, SlapReply *rs )
1125 {
1126         slap_overinst           *on = (slap_overinst *)op->o_bd->bd_info;
1127         struct ldaprwmap        *rwmap = 
1128                         (struct ldaprwmap *)on->on_bi.bi_private;
1129
1130         int             rc;
1131
1132         if ( op->o_tag == LDAP_REQ_SEARCH && rs->sr_type == REP_SEARCH ) {
1133                 return rwm_send_entry( op, rs );
1134         }
1135
1136         switch( op->o_tag ) {
1137         case LDAP_REQ_SEARCH:
1138                 /* Note: the operation attrs are remapped */
1139                 if ( op->ors_attrs != NULL && op->ors_attrs != rs->sr_attrs )
1140                 {
1141                         ch_free( op->ors_attrs );
1142                         op->ors_attrs = rs->sr_attrs;
1143                 }
1144                 /* fall thru */
1145
1146         case LDAP_REQ_BIND:
1147         case LDAP_REQ_ADD:
1148         case LDAP_REQ_DELETE:
1149         case LDAP_REQ_MODRDN:
1150         case LDAP_REQ_MODIFY:
1151         case LDAP_REQ_COMPARE:
1152         case LDAP_REQ_EXTENDED:
1153                 if ( rs->sr_ref ) {
1154                         dncookie                dc;
1155
1156                         /*
1157                          * Rewrite the dn of the referrals, if needed
1158                          */
1159                         dc.rwmap = rwmap;
1160 #ifdef ENABLE_REWRITE
1161                         dc.conn = op->o_conn;
1162                         dc.rs = NULL; 
1163                         dc.ctx = "referralDN";
1164 #else /* ! ENABLE_REWRITE */
1165                         dc.tofrom = 0;
1166                         dc.normalized = 0;
1167 #endif /* ! ENABLE_REWRITE */
1168                         rc = rwm_referral_result_rewrite( &dc, rs->sr_ref );
1169                         if ( rc != LDAP_SUCCESS ) {
1170                                 rc = 1;
1171                                 break;
1172                         }
1173                 }
1174                 rc = rwm_matched( op, rs );
1175                 break;
1176
1177         default:
1178                 rc = SLAP_CB_CONTINUE;
1179                 break;
1180         }
1181
1182         return rc;
1183 }
1184
1185 static int
1186 rwm_db_config(
1187     BackendDB   *be,
1188     const char  *fname,
1189     int         lineno,
1190     int         argc,
1191     char        **argv
1192 )
1193 {
1194         int             rc = 0;
1195         char            *argv0 = NULL;
1196
1197         if ( strncasecmp( argv[ 0 ], "rwm-", STRLENOF( "rwm-" ) ) == 0 ) {
1198                 argv0 = argv[ 0 ];
1199                 argv[ 0 ] = &argv0[ STRLENOF( "rwm-" ) ];
1200         }
1201
1202         if ( strncasecmp( argv[0], "rewrite", STRLENOF("rewrite") ) == 0 ) {
1203                 rc = rwm_rw_config( be, fname, lineno, argc, argv );
1204
1205         } else if ( strcasecmp( argv[0], "map" ) == 0 ) {
1206                 rc = rwm_m_config( be, fname, lineno, argc, argv );
1207
1208         } else if ( strcasecmp( argv[0], "suffixmassage" ) == 0 ) {
1209                 rc = rwm_suffixmassage_config( be, fname, lineno, argc, argv );
1210
1211         } else {
1212                 rc = SLAP_CONF_UNKNOWN;
1213         }
1214
1215         if ( argv0 ) {
1216                 argv[ 0 ] = argv0;
1217         }
1218
1219         return rc;
1220 }
1221
1222 static int
1223 rwm_db_init(
1224         BackendDB *be
1225 )
1226 {
1227         slap_overinst           *on = (slap_overinst *) be->bd_info;
1228         struct ldapmapping      *mapping = NULL;
1229         struct ldaprwmap        *rwmap;
1230
1231         rwmap = (struct ldaprwmap *)ch_malloc(sizeof(struct ldaprwmap));
1232         memset(rwmap, 0, sizeof(struct ldaprwmap));
1233
1234 #ifdef ENABLE_REWRITE
1235         rwmap->rwm_rw = rewrite_info_init( REWRITE_MODE_USE_DEFAULT );
1236         if ( rwmap->rwm_rw == NULL ) {
1237                 ch_free( rwmap );
1238                 return -1;
1239         }
1240
1241         {
1242                 char    *rargv[3];
1243
1244                 /* this rewriteContext by default must be null;
1245                  * rules can be added if required */
1246                 rargv[ 0 ] = "rewriteContext";
1247                 rargv[ 1 ] = "searchFilter";
1248                 rargv[ 2 ] = NULL;
1249                 rewrite_parse( rwmap->rwm_rw, "<suffix massage>", 1, 2, rargv );
1250
1251                 rargv[ 0 ] = "rewriteContext";
1252                 rargv[ 1 ] = "default";
1253                 rargv[ 2 ] = NULL;
1254                 rewrite_parse( rwmap->rwm_rw, "<suffix massage>", 2, 2, rargv );
1255         }
1256         
1257 #endif /* ENABLE_REWRITE */
1258
1259         if ( rwm_map_init( &rwmap->rwm_oc, &mapping ) != LDAP_SUCCESS ||
1260                         rwm_map_init( &rwmap->rwm_at, &mapping ) != LDAP_SUCCESS )
1261         {
1262                 return 1;
1263         }
1264
1265         on->on_bi.bi_private = (void *)rwmap;
1266
1267         return 0;
1268 }
1269
1270 static int
1271 rwm_db_destroy(
1272         BackendDB *be
1273 )
1274 {
1275         slap_overinst   *on = (slap_overinst *) be->bd_info;
1276         int             rc = 0;
1277
1278         if ( on->on_bi.bi_private ) {
1279                 struct ldaprwmap        *rwmap = 
1280                         (struct ldaprwmap *)on->on_bi.bi_private;
1281
1282 #ifdef ENABLE_REWRITE
1283                 if (rwmap->rwm_rw) {
1284                         rewrite_info_delete( &rwmap->rwm_rw );
1285                 }
1286 #else /* !ENABLE_REWRITE */
1287                 if ( rwmap->rwm_suffix_massage ) {
1288                         ber_bvarray_free( rwmap->rwm_suffix_massage );
1289                 }
1290 #endif /* !ENABLE_REWRITE */
1291
1292                 avl_free( rwmap->rwm_oc.remap, NULL );
1293                 avl_free( rwmap->rwm_oc.map, rwm_mapping_free );
1294                 avl_free( rwmap->rwm_at.remap, NULL );
1295                 avl_free( rwmap->rwm_at.map, rwm_mapping_free );
1296         }
1297
1298         return rc;
1299 }
1300
1301 static slap_overinst rwm = { { NULL } };
1302
1303 int
1304 rwm_init(void)
1305 {
1306         memset( &rwm, 0, sizeof( slap_overinst ) );
1307
1308         rwm.on_bi.bi_type = "rwm";
1309
1310         rwm.on_bi.bi_db_init = rwm_db_init;
1311         rwm.on_bi.bi_db_config = rwm_db_config;
1312         rwm.on_bi.bi_db_destroy = rwm_db_destroy;
1313
1314         rwm.on_bi.bi_op_bind = rwm_bind;
1315         rwm.on_bi.bi_op_search = rwm_search;
1316         rwm.on_bi.bi_op_compare = rwm_compare;
1317         rwm.on_bi.bi_op_modify = rwm_modify;
1318         rwm.on_bi.bi_op_modrdn = rwm_modrdn;
1319         rwm.on_bi.bi_op_add = rwm_add;
1320         rwm.on_bi.bi_op_delete = rwm_delete;
1321         rwm.on_bi.bi_op_unbind = rwm_unbind;
1322         rwm.on_bi.bi_extended = rwm_extended;
1323         rwm.on_bi.bi_operational = rwm_operational;
1324
1325         rwm.on_response = rwm_response;
1326
1327         return overlay_register( &rwm );
1328 }
1329
1330 #if SLAPD_OVER_RWM == SLAPD_MOD_DYNAMIC
1331 int
1332 init_module( int argc, char *argv[] )
1333 {
1334         return rwm_init();
1335 }
1336 #endif /* SLAPD_OVER_RWM == SLAPD_MOD_DYNAMIC */
1337
1338 #endif /* SLAPD_OVER_RWM */