1
/* init.c - initialize relay backend */
2
/* $OpenLDAP: pkg/ldap/servers/slapd/back-relay/init.c,v 1.19.2.4 2008/02/12 01:03:16 quanah Exp $ */
3
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5
* Copyright 2004-2008 The OpenLDAP Foundation.
6
* Portions Copyright 2004 Pierangelo Masarati.
9
* Redistribution and use in source and binary forms, with or without
10
* modification, are permitted only as authorized by the OpenLDAP
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>.
18
* This work was initially developed by Pierangelo Masarati for inclusion
19
* in OpenLDAP Software.
25
#include <ac/string.h>
29
#include "back-relay.h"
31
static ConfigDriver relay_back_cf;
33
static ConfigTable relaycfg[] = {
34
{ "relay", "relay", 2, 2, 0,
36
relay_back_cf, "( OLcfgDbAt:5.1 "
45
static ConfigOCs relayocs[] = {
47
"NAME 'olcRelayConfig' "
48
"DESC 'Relay backend configuration' "
49
"SUP olcDatabaseConfig "
52
Cft_Database, relaycfg},
57
relay_back_cf( ConfigArgs *c )
59
relay_back_info *ri = ( relay_back_info * )c->be->be_private;
62
if ( c->op == SLAP_CONFIG_EMIT ) {
63
if ( ri != NULL && !BER_BVISNULL( &ri->ri_realsuffix ) ) {
64
value_add_one( &c->rvalue_vals, &ri->ri_realsuffix );
69
} else if ( c->op == LDAP_MOD_DELETE ) {
70
if ( !BER_BVISNULL( &ri->ri_realsuffix ) ) {
71
ch_free( ri->ri_realsuffix.bv_val );
72
BER_BVZERO( &ri->ri_realsuffix );
82
assert( BER_BVISNULL( &ri->ri_realsuffix ) );
84
if ( c->be->be_nsuffix == NULL ) {
85
snprintf( c->cr_msg, sizeof( c->cr_msg),
86
"\"relay\" directive "
87
"must appear after \"suffix\"" );
88
Log2( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR,
89
"%s: %s.\n", c->log, c->cr_msg );
94
if ( !BER_BVISNULL( &c->be->be_nsuffix[ 1 ] ) ) {
95
snprintf( c->cr_msg, sizeof( c->cr_msg),
96
"relaying of multiple suffix "
97
"database not supported" );
98
Log2( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR,
99
"%s: %s.\n", c->log, c->cr_msg );
104
bd = select_backend( &c->value_ndn, 1 );
106
snprintf( c->cr_msg, sizeof( c->cr_msg),
107
"cannot find database "
108
"of relay dn \"%s\" "
109
"in \"olcRelay <dn>\"\n",
110
c->value_dn.bv_val );
111
Log2( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR,
112
"%s: %s.\n", c->log, c->cr_msg );
116
} else if ( bd->be_private == c->be->be_private ) {
117
snprintf( c->cr_msg, sizeof( c->cr_msg),
118
"relay dn \"%s\" would call self "
119
"in \"relay <dn>\" line\n",
120
c->value_dn.bv_val );
121
Log2( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR,
122
"%s: %s.\n", c->log, c->cr_msg );
127
ri->ri_realsuffix = c->value_ndn;
128
BER_BVZERO( &c->value_ndn );
131
ch_free( c->value_dn.bv_val );
132
ch_free( c->value_ndn.bv_val );
139
relay_back_initialize( BackendInfo *bi )
147
bi->bi_db_init = relay_back_db_init;
148
bi->bi_db_config = config_generic_wrapper;
149
bi->bi_db_open = relay_back_db_open;
151
bi->bi_db_close = relay_back_db_close;
153
bi->bi_db_destroy = relay_back_db_destroy;
155
bi->bi_op_bind = relay_back_op_bind;
156
bi->bi_op_unbind = relay_back_op_unbind;
157
bi->bi_op_search = relay_back_op_search;
158
bi->bi_op_compare = relay_back_op_compare;
159
bi->bi_op_modify = relay_back_op_modify;
160
bi->bi_op_modrdn = relay_back_op_modrdn;
161
bi->bi_op_add = relay_back_op_add;
162
bi->bi_op_delete = relay_back_op_delete;
163
bi->bi_op_abandon = relay_back_op_abandon;
164
bi->bi_op_cancel = relay_back_op_cancel;
165
bi->bi_extended = relay_back_op_extended;
166
bi->bi_entry_release_rw = relay_back_entry_release_rw;
167
bi->bi_entry_get_rw = relay_back_entry_get_rw;
168
#if 0 /* see comment in op.c */
169
bi->bi_chk_referrals = relay_back_chk_referrals;
171
bi->bi_operational = relay_back_operational;
172
bi->bi_has_subordinates = relay_back_has_subordinates;
174
bi->bi_connection_init = relay_back_connection_init;
175
bi->bi_connection_destroy = relay_back_connection_destroy;
177
bi->bi_cf_ocs = relayocs;
179
return config_register_schema( relaycfg, relayocs );
183
relay_back_db_init( Backend *be, ConfigReply *cr)
187
be->be_private = NULL;
189
ri = (relay_back_info *)ch_calloc( 1, sizeof( relay_back_info ) );
195
BER_BVZERO( &ri->ri_realsuffix );
198
be->be_cf_ocs = be->bd_info->bi_cf_ocs;
200
be->be_private = (void *)ri;
206
relay_back_db_open( Backend *be, ConfigReply *cr )
208
relay_back_info *ri = (relay_back_info *)be->be_private;
210
assert( ri != NULL );
212
if ( !BER_BVISNULL( &ri->ri_realsuffix ) ) {
213
ri->ri_bd = select_backend( &ri->ri_realsuffix, 1 );
215
/* must be there: it was during config! */
216
assert( ri->ri_bd != NULL );
218
/* inherit controls */
219
AC_MEMCPY( be->be_ctrls, ri->ri_bd->be_ctrls, sizeof( be->be_ctrls ) );
223
AC_MEMCPY( be->be_ctrls, frontendDB->be_ctrls, sizeof( be->be_ctrls ) );
230
relay_back_db_close( Backend *be, ConfigReply *cr )
236
relay_back_db_destroy( Backend *be, ConfigReply *cr)
238
relay_back_info *ri = (relay_back_info *)be->be_private;
241
if ( !BER_BVISNULL( &ri->ri_realsuffix ) ) {
242
ch_free( ri->ri_realsuffix.bv_val );
250
#if SLAPD_RELAY == SLAPD_MOD_DYNAMIC
252
/* conditionally define the init_module() function */
253
SLAP_BACKEND_INIT_MODULE( relay )
255
#endif /* SLAPD_RELAY == SLAPD_MOD_DYNAMIC */