]> git.sur5r.net Git - openldap/commitdiff
fix dynamically registered controls check; NOTE: controls registered by global overla...
authorPierangelo Masarati <ando@openldap.org>
Tue, 25 Jan 2005 19:39:56 +0000 (19:39 +0000)
committerPierangelo Masarati <ando@openldap.org>
Tue, 25 Jan 2005 19:39:56 +0000 (19:39 +0000)
servers/slapd/back-ldap/chain.c
servers/slapd/backend.c
servers/slapd/backover.c
servers/slapd/frontend.c
servers/slapd/overlays/ppolicy.c
servers/slapd/overlays/syncprov.c
servers/slapd/proto-slap.h
servers/slapd/slap.h

index 0a7935a4014805cdaf2e0e4baa6bdc462af9bf06..b56715467c805c768c90efb518bb3ddd1ec38b78 100644 (file)
@@ -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;
        
index f7ffd28ae5a777dffc61f4271ee42a5fb601ea55..032a816567cb55f22291311203b3576058edbefc 100644 (file)
@@ -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;
 
index 6e396a59043930ec36ed447179b5784aab22851e..ee3ecafe6eea9daf57cd6d1e0fc2dc807aced0ad 100644 (file)
@@ -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 )
index e1fca24d32d4eb01ffc1aea3dca32948316b20ce..bf9635b8755a659ef468f279e7d15a0f71b24d08 100644 (file)
@@ -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;
index f586e9f8f3822ca9eea72e0d4b6748d8e4ad57b8..f572875fef781615c35a269607984e3babb6149f 100644 (file)
@@ -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;
 
index 8b5ca2077b01eb9d74fef2787dbddc13a2db0d38..aa51bcd07ec7b094db044e0d1023dba82b368cb3 100644 (file)
@@ -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;
index bacc1b3772468e7a63dd0e8cd1a3068d617eef70..3629dfdd709ccb2a51e7f8f4967f493cf776cb88 100644 (file)
@@ -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
index 79d3a38c1302db62b3bfab3b279f4643aac095b4..e2e739308f19a12b28943332cf44b01efa278c79 100644 (file)
@@ -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