From: Pierangelo Masarati Date: Tue, 25 Jan 2005 19:39:56 +0000 (+0000) Subject: fix dynamically registered controls check; NOTE: controls registered by global overla... X-Git-Tag: OPENLDAP_REL_ENG_2_3_BP~255 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=5b193c218fcc45a909169a18500e49185fb71d52;p=openldap fix dynamically registered controls check; NOTE: controls registered by global overlays don't work yet; better leave Kurt's kludge in place right now --- diff --git a/servers/slapd/back-ldap/chain.c b/servers/slapd/back-ldap/chain.c index 0a7935a401..b56715467c 100644 --- a/servers/slapd/back-ldap/chain.c +++ b/servers/slapd/back-ldap/chain.c @@ -541,6 +541,16 @@ ldap_chain_db_init( return rc; } +#ifdef LDAP_CONTROL_X_CHAINING_BEHAVIOR +static int +ldap_chain_db_open( + BackendDB *be +) +{ + return overlay_register_control( be, LDAP_CONTROL_X_CHAINING_BEHAVIOR ); +} +#endif /* LDAP_CONTROL_X_CHAINING_BEHAVIOR */ + static int ldap_chain_db_destroy( BackendDB *be @@ -694,7 +704,7 @@ chain_init( void ) int rc; rc = register_supported_control( LDAP_CONTROL_X_CHAINING_BEHAVIOR, - SLAP_CTRL_ACCESS|SLAP_CTRL_HIDE, NULL, + SLAP_CTRL_FRONTEND|SLAP_CTRL_ACCESS|SLAP_CTRL_HIDE, NULL, ldap_chain_parse_ctrl, &sc_chainingBehavior ); if ( rc != LDAP_SUCCESS ) { fprintf( stderr, "Failed to register chaining behavior control: %d\n", rc ); @@ -704,6 +714,9 @@ chain_init( void ) ldapchain.on_bi.bi_type = "chain"; ldapchain.on_bi.bi_db_init = ldap_chain_db_init; +#ifdef LDAP_CONTROL_X_CHAINING_BEHAVIOR + ldapchain.on_bi.bi_db_open = ldap_chain_db_open; +#endif /* LDAP_CONTROL_X_CHAINING_BEHAVIOR */ ldapchain.on_bi.bi_db_config = ldap_chain_db_config; ldapchain.on_bi.bi_db_destroy = ldap_chain_db_destroy; diff --git a/servers/slapd/backend.c b/servers/slapd/backend.c index f7ffd28ae5..032a816567 100644 --- a/servers/slapd/backend.c +++ b/servers/slapd/backend.c @@ -410,6 +410,9 @@ int backend_destroy(void) free( bd->be_rootpw.bv_val ); } acl_destroy( bd->be_acl, frontendDB->be_acl ); + if ( bd->be_controls ) { + ldap_charray_free( bd->be_controls ); + } } free( backendDB ); @@ -500,6 +503,11 @@ backend_db_init( be = &backends[nbackends++]; be->bd_info = bi; + + if ( bi->bi_controls ) { + be->be_controls = ldap_charray_dup( bi->bi_controls ); + } + be->be_def_limit = frontendDB->be_def_limit; be->be_dfltaccess = frontendDB->be_dfltaccess; diff --git a/servers/slapd/backover.c b/servers/slapd/backover.c index 6e396a5904..ee3ecafe6e 100644 --- a/servers/slapd/backover.c +++ b/servers/slapd/backover.c @@ -467,6 +467,66 @@ overlay_is_inst( BackendDB *be, const char *over_type ) return 0; } +#if 0 +int +overlay_is_global( BackendDB *be ) +{ + BackendInfo *frontendBI; + + if ( !overlay_is_over( be ) ) { + return 0; + } + + frontendBI = frontendDB->bd_info; + if ( overlay_is_over( frontendDB ) ) { + frontendBI = ((slap_overinfo *)frontendBI->bi_private)->oi_orig; + } + + return ((slap_overinfo *)be->bd_info->bi_private)->oi_orig == frontendBI; +} +#endif + +int +overlay_register_control( BackendDB *be, const char *oid ) +{ + int rc = 0; + int gotit = 0; + +#if 0 + if ( overlay_is_global( be ) ) { + int i; + + /* add to all backends... */ + for ( i = 0; i < nBackendDB; i++ ) { + BackendDB *bd = &backendDB[i]; + + if ( be == bd ) { + gotit = 1; + } + + if ( bd->be_controls == NULL || + !ldap_charray_inlist( bd->be_controls, oid ) ) + { + rc = ldap_charray_add( &be->be_controls, oid ); + if ( rc ) { + break; + } + } + } + + } +#endif + + if ( rc == 0 && !gotit && !ldap_charray_inlist( be->be_controls, oid ) ) { + rc = ldap_charray_add( &be->be_controls, oid ); + if ( rc ) { + return rc; + } + } + + return rc; +} + /* add an overlay to a particular backend. */ int overlay_config( BackendDB *be, const char *ov ) diff --git a/servers/slapd/frontend.c b/servers/slapd/frontend.c index e1fca24d32..bf9635b875 100644 --- a/servers/slapd/frontend.c +++ b/servers/slapd/frontend.c @@ -42,8 +42,8 @@ #include "slapi/slapi.h" #endif -BackendInfo slap_frontendInfo; -BackendDB slap_frontendDB; +static BackendInfo slap_frontendInfo; +static BackendDB slap_frontendDB; BackendDB *frontendDB; int @@ -87,6 +87,7 @@ frontend_init( void ) /* known controls */ frontendDB->bd_info->bi_controls = slap_known_controls; + frontendDB->be_controls = ldap_charray_dup( slap_known_controls ); /* calls */ frontendDB->bd_info->bi_op_abandon = fe_op_abandon; diff --git a/servers/slapd/overlays/ppolicy.c b/servers/slapd/overlays/ppolicy.c index f586e9f8f3..f572875fef 100644 --- a/servers/slapd/overlays/ppolicy.c +++ b/servers/slapd/overlays/ppolicy.c @@ -1706,6 +1706,14 @@ ppolicy_db_init( return 0; } +static int +ppolicy_db_open( + BackendDB *be +) +{ + return overlay_register_control( be, LDAP_CONTROL_PASSWORDPOLICYREQUEST ); +} + static int ppolicy_close( BackendDB *be @@ -1813,6 +1821,7 @@ int ppolicy_init() ppolicy.on_bi.bi_type = "ppolicy"; ppolicy.on_bi.bi_db_init = ppolicy_db_init; + ppolicy.on_bi.bi_db_open = ppolicy_db_open; ppolicy.on_bi.bi_db_config = ppolicy_config; ppolicy.on_bi.bi_db_close = ppolicy_close; diff --git a/servers/slapd/overlays/syncprov.c b/servers/slapd/overlays/syncprov.c index 8b5ca2077b..aa51bcd07e 100644 --- a/servers/slapd/overlays/syncprov.c +++ b/servers/slapd/overlays/syncprov.c @@ -2012,6 +2012,11 @@ syncprov_db_open( Attribute *a; int rc; + rc = overlay_register_control( be, LDAP_CONTROL_SYNC ); + if ( rc ) { + return rc; + } + connection_fake_init( &conn, op, thrctx ); op->o_bd = be; op->o_dn = be->be_rootdn; diff --git a/servers/slapd/proto-slap.h b/servers/slapd/proto-slap.h index bacc1b3772..3629dfdd70 100644 --- a/servers/slapd/proto-slap.h +++ b/servers/slapd/proto-slap.h @@ -315,6 +315,9 @@ LDAP_SLAPD_F (slap_overinst *) overlay_next LDAP_P(( slap_overinst *on )); LDAP_SLAPD_F (slap_overinst *) overlay_find LDAP_P(( const char *name )); LDAP_SLAPD_F (int) overlay_is_over LDAP_P(( BackendDB *be )); LDAP_SLAPD_F (int) overlay_is_inst LDAP_P(( BackendDB *be, const char *name )); +LDAP_SLAPD_F (int) overlay_register_control LDAP_P(( + BackendDB *be, + const char *oid )); /* * ch_malloc.c diff --git a/servers/slapd/slap.h b/servers/slapd/slap.h index 79d3a38c13..e2e739308f 100644 --- a/servers/slapd/slap.h +++ b/servers/slapd/slap.h @@ -1564,7 +1564,11 @@ struct slap_backend_db { */ #define be_has_subordinates bd_info->bi_has_subordinates -#define be_controls bd_info->bi_controls + /* supported controls */ + /* NOTE: this stores a duplicate of the control OIDs as listed + * in bd_info->bi_controls at database startup; later on, + * controls may be added run-time, e.g. by overlays */ + char **be_controls; #define be_connection_init bd_info->bi_connection_init #define be_connection_destroy bd_info->bi_connection_destroy