]> git.sur5r.net Git - openldap/commitdiff
do not expose control until sssvlv overlay is actually instantiated at least once...
authorPierangelo Masarati <ando@openldap.org>
Wed, 6 Oct 2010 08:24:45 +0000 (08:24 +0000)
committerPierangelo Masarati <ando@openldap.org>
Wed, 6 Oct 2010 08:24:45 +0000 (08:24 +0000)
servers/slapd/overlays/sssvlv.c

index e3ca1a17f31820259caf26c8647dccff773a959d..de51f9fae141a2b72507ef4f8e5f073a30ba8293 100644 (file)
@@ -1158,6 +1158,38 @@ static int sssvlv_db_init(
 {
        slap_overinst   *on = (slap_overinst *)be->bd_info;
        sssvlv_info *si;
+
+       if ( ov_count == 0 ) {
+               int rc;
+
+               rc = register_supported_control2( LDAP_CONTROL_SORTREQUEST,
+                       SLAP_CTRL_SEARCH,
+                       NULL,
+                       sss_parseCtrl,
+                       1 /* replace */,
+                       &sss_cid );
+               if ( rc != LDAP_SUCCESS ) {
+                       Debug( LDAP_DEBUG_ANY, "Failed to register Sort Request control '%s' (%d)\n",
+                               LDAP_CONTROL_SORTREQUEST, rc, 0 );
+                       return rc;
+               }
+
+               rc = register_supported_control2( LDAP_CONTROL_VLVREQUEST,
+                       SLAP_CTRL_SEARCH,
+                       NULL,
+                       vlv_parseCtrl,
+                       1 /* replace */,
+                       &vlv_cid );
+               if ( rc != LDAP_SUCCESS ) {
+                       Debug( LDAP_DEBUG_ANY, "Failed to register VLV Request control '%s' (%d)\n",
+                               LDAP_CONTROL_VLVREQUEST, rc, 0 );
+#ifdef SLAP_CONFIG_DELETE
+                       overlay_unregister_control( be, LDAP_CONTROL_SORTREQUEST );
+#endif /* SLAP_CONFIG_DELETE */
+                       unregister_supported_control( LDAP_CONTROL_SORTREQUEST );
+                       return rc;
+               }
+       }
        
        si = (sssvlv_info *)ch_malloc(sizeof(sssvlv_info));
        on->on_bi.bi_private = si;
@@ -1195,6 +1227,9 @@ static int sssvlv_db_destroy(
        overlay_unregister_control( be, LDAP_CONTROL_SORTREQUEST );
        overlay_unregister_control( be, LDAP_CONTROL_VLVREQUEST );
 #endif /* SLAP_CONFIG_DELETE */
+       if ( ov_count == 0 ) {
+               unregister_supported_control( LDAP_CONTROL_SORTREQUEST );
+       }
 
        if ( si ) {
                ch_free( si );
@@ -1222,30 +1257,9 @@ int sssvlv_initialize()
        if ( rc )
                return rc;
 
-       rc = register_supported_control2( LDAP_CONTROL_SORTREQUEST,
-                       SLAP_CTRL_SEARCH,
-                       NULL,
-                       sss_parseCtrl,
-                       1 /* replace */,
-                       &sss_cid );
-
-       if ( rc == LDAP_SUCCESS ) {
-               rc = register_supported_control2( LDAP_CONTROL_VLVREQUEST,
-                       SLAP_CTRL_SEARCH,
-                       NULL,
-                       vlv_parseCtrl,
-                       1 /* replace */,
-                       &vlv_cid );
-       }
-
-       if ( rc == LDAP_SUCCESS ) {
-               rc = overlay_register( &sssvlv );
-               if ( rc != LDAP_SUCCESS ) {
-                       Debug( LDAP_DEBUG_ANY, "Failed to register server side sort overlay\n", 0, 0, 0 );
-               }
-       }
-       else {
-               Debug( LDAP_DEBUG_ANY, "Failed to register control %d\n", rc, 0, 0 );
+       rc = overlay_register( &sssvlv );
+       if ( rc != LDAP_SUCCESS ) {
+               Debug( LDAP_DEBUG_ANY, "Failed to register server side sort overlay\n", 0, 0, 0 );
        }
 
        return rc;