]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/bconfig.c
ITS#6967 normalize schema RDN
[openldap] / servers / slapd / bconfig.c
index 72b36631a72b1314d75c84b5c3c705accf919713..3be11658901039b9f28adf8837dc25d6085894fc 100644 (file)
@@ -319,6 +319,7 @@ static ConfigTable config_back_cf_table[] = {
                &config_generic, "( OLcfgGlAt:4 NAME 'olcAttributeTypes' "
                        "DESC 'OpenLDAP attributeTypes' "
                        "EQUALITY caseIgnoreMatch "
+                       "SUBSTR caseIgnoreSubstringsMatch "
                        "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
                                NULL, NULL },
        { "authid-rewrite", NULL, 2, 0, STRLENOF( "authid-rewrite" ),
@@ -368,6 +369,7 @@ static ConfigTable config_back_cf_table[] = {
                &config_generic, "( OLcfgGlAt:16 NAME 'olcDitContentRules' "
                        "DESC 'OpenLDAP DIT content rules' "
                        "EQUALITY caseIgnoreMatch "
+                       "SUBSTR caseIgnoreSubstringsMatch "
                        "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
                        NULL, NULL },
        { "extra_attrs", "attrlist", 2, 2, 0, ARG_DB|ARG_MAGIC,
@@ -414,6 +416,7 @@ static ConfigTable config_back_cf_table[] = {
                &config_generic, "( OLcfgGlAt:85 NAME 'olcLdapSyntaxes' "
                        "DESC 'OpenLDAP ldapSyntax' "
                        "EQUALITY caseIgnoreMatch "
+                       "SUBSTR caseIgnoreSubstringsMatch "
                        "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
                                NULL, NULL },
        { "limits", "limits", 2, 0, 0, ARG_DB|ARG_MAGIC|CFG_LIMITS,
@@ -469,11 +472,13 @@ static ConfigTable config_back_cf_table[] = {
                &config_generic, "( OLcfgGlAt:32 NAME 'olcObjectClasses' "
                "DESC 'OpenLDAP object classes' "
                "EQUALITY caseIgnoreMatch "
+               "SUBSTR caseIgnoreSubstringsMatch "
                "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
                        NULL, NULL },
        { "objectidentifier", "name> <oid",     3, 3, 0, ARG_MAGIC|CFG_OID,
                &config_generic, "( OLcfgGlAt:33 NAME 'olcObjectIdentifier' "
                        "EQUALITY caseIgnoreMatch "
+                       "SUBSTR caseIgnoreSubstringsMatch "
                        "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
        { "overlay", "overlay", 2, 2, 0, ARG_MAGIC,
                &config_overlay, "( OLcfgGlAt:34 NAME 'olcOverlay' "
@@ -1761,7 +1766,8 @@ config_generic(ConfigArgs *c) {
                                        int i;
                                        for (i=0, oc = cfn->c_oc_head; i<c->valx; i++) {
                                                prev = oc;
-                                               oc_next( &oc );
+                                               if ( !oc_next( &oc ))
+                                                       break;
                                        }
                                } else
                                /* If adding the first, and head exists, find its prev */
@@ -1793,7 +1799,8 @@ config_generic(ConfigArgs *c) {
                                        int i;
                                        for (i=0, at = cfn->c_at_head; i<c->valx; i++) {
                                                prev = at;
-                                               at_next( &at );
+                                               if ( !at_next( &at ))
+                                                       break;
                                        }
                                } else
                                /* If adding the first, and head exists, find its prev */
@@ -1825,7 +1832,8 @@ config_generic(ConfigArgs *c) {
                                        int i;
                                        for ( i = 0, syn = cfn->c_syn_head; i < c->valx; i++ ) {
                                                prev = syn;
-                                               syn_next( &syn );
+                                               if ( !syn_next( &syn ))
+                                                       break;
                                        }
                                } else
                                /* If adding the first, and head exists, find its prev */
@@ -4749,12 +4757,19 @@ check_name_index( CfEntryInfo *parent, ConfigType ce_type, Entry *e,
        return rc;
 }
 
+/* Insert all superior classes of the given class */
 static int
 count_oc( ObjectClass *oc, ConfigOCs ***copp, int *nocs )
 {
        ConfigOCs       co, *cop;
        ObjectClass     **sups;
 
+       for ( sups = oc->soc_sups; sups && *sups; sups++ ) {
+               if ( count_oc( *sups, copp, nocs ) ) {
+                       return -1;
+               }
+       }
+
        co.co_name = &oc->soc_cname;
        cop = avl_find( CfOcTree, &co, CfOc_cmp );
        if ( cop ) {
@@ -4778,27 +4793,23 @@ count_oc( ObjectClass *oc, ConfigOCs ***copp, int *nocs )
                }
        }
 
-       for ( sups = oc->soc_sups; sups && *sups; sups++ ) {
-               if ( count_oc( *sups, copp, nocs ) ) {
-                       return -1;
-               }
-       }
-
        return 0;
 }
 
+/* Find all superior classes of the given objectclasses,
+ * return list in order of most-subordinate first.
+ *
+ * Special / auxiliary / Cft_Misc classes always take precedence.
+ */
 static ConfigOCs **
 count_ocs( Attribute *oc_at, int *nocs )
 {
-       int             i;
+       int             i, j, misc = -1;
        ConfigOCs       **colst = NULL;
 
        *nocs = 0;
 
-       for ( i = 0; !BER_BVISNULL( &oc_at->a_nvals[i] ); i++ )
-               /* count attrs */ ;
-
-       for ( ; i--; ) {
+       for ( i = oc_at->a_numvals; i--; ) {
                ObjectClass     *oc = oc_bvfind( &oc_at->a_nvals[i] );
 
                assert( oc != NULL );
@@ -4808,6 +4819,25 @@ count_ocs( Attribute *oc_at, int *nocs )
                }
        }
 
+       /* invert order */
+       i = 0;
+       j = *nocs - 1;
+       while ( i < j ) {
+               ConfigOCs *tmp = colst[i];
+               colst[i] = colst[j];
+               colst[j] = tmp;
+               if (tmp->co_type == Cft_Misc)
+                       misc = j;
+               i++; j--;
+       }
+       /* Move misc class to front of list */
+       if (misc > 0) {
+               ConfigOCs *tmp = colst[misc];
+               for (i=misc; i>0; i--)
+                       colst[i] = colst[i-1];
+               colst[0] = tmp;
+       }
+
        return colst;
 }
 
@@ -5546,6 +5576,11 @@ config_modify_internal( CfEntryInfo *ce, Operation *op, SlapReply *rs,
        oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
        if ( !oc_at ) return LDAP_OBJECT_CLASS_VIOLATION;
 
+       for (ml = op->orm_modlist; ml; ml=ml->sml_next) {
+               if (ml->sml_desc == slap_schema.si_ad_objectClass)
+                       return rc;
+       }
+
        colst = count_ocs( oc_at, &nocs );
 
        /* make sure add/del flags are clear; should always be true */
@@ -6162,31 +6197,65 @@ config_back_delete( Operation *op, SlapReply *rs )
                        rs->sr_matched = last->ce_entry->e_name.bv_val;
                rs->sr_err = LDAP_NO_SUCH_OBJECT;
        } else if ( ce->ce_kids ) {
-               rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
+               rs->sr_err = LDAP_NOT_ALLOWED_ON_NONLEAF;
        } else if ( op->o_abandon ) {
                rs->sr_err = SLAPD_ABANDON;
-       } else if ( ce->ce_type == Cft_Overlay || ce->ce_type == Cft_Database ){
+       } else if ( ce->ce_type == Cft_Overlay ||
+                       ce->ce_type == Cft_Database ||
+                       ce->ce_type == Cft_Misc ){
                char *iptr;
                int count, ixold;
 
                ldap_pvt_thread_pool_pause( &connection_pool );
 
                if ( ce->ce_type == Cft_Overlay ){
-                       if ( SLAP_ISGLOBALOVERLAY(ce->ce_be ) ) {
-                               rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
-                               rs->sr_text = "Cannot delete global overlays";
+                       overlay_remove( ce->ce_be, (slap_overinst *)ce->ce_bi, op );
+               } else if ( ce->ce_type == Cft_Misc ) {
+                       /*
+                        * only Cft_Misc objects that have a co_lddel handler set in
+                        * the ConfigOCs struct can be deleted. This code also
+                        * assumes that the entry can be only have one objectclass
+                        * with co_type == Cft_Misc
+                        */
+                       ConfigOCs co, *coptr;
+                       Attribute *oc_at;
+                       int i;
+
+                       oc_at = attr_find( ce->ce_entry->e_attrs,
+                                       slap_schema.si_ad_objectClass );
+                       if ( !oc_at ) {
+                               rs->sr_err = LDAP_OTHER;
+                               rs->sr_text = "objectclass not found";
                                ldap_pvt_thread_pool_resume( &connection_pool );
                                goto out;
-                       } else {
-                               overlay_remove( ce->ce_be, (slap_overinst *)ce->ce_bi, op );
                        }
-               } else { /* Cft_Database*/
+                       for ( i=0; !BER_BVISNULL(&oc_at->a_nvals[i]); i++ ) {
+                               co.co_name = &oc_at->a_nvals[i];
+                               coptr = avl_find( CfOcTree, &co, CfOc_cmp );
+                               if ( coptr == NULL || coptr->co_type != Cft_Misc ) {
+                                       continue;
+                               }
+                               if ( ! coptr->co_lddel || coptr->co_lddel( ce, op ) ){
+                                       rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
+                                       if ( ! coptr->co_lddel ) {
+                                               rs->sr_text = "No delete handler found";
+                                       } else {
+                                               rs->sr_err = LDAP_OTHER;
+                                               /* FIXME: We should return a helpful error message
+                                                * here */
+                                       }
+                                       ldap_pvt_thread_pool_resume( &connection_pool );
+                                       goto out;
+                               }
+                               break;
+                       }
+               } else if (ce->ce_type == Cft_Database ) {
                        if ( ce->ce_be == frontendDB || ce->ce_be == op->o_bd ){
                                rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
                                rs->sr_text = "Cannot delete config or frontend database";
                                ldap_pvt_thread_pool_resume( &connection_pool );
                                goto out;
-                       } 
+                       }
                        if ( ce->ce_be->bd_info->bi_db_close ) {
                                ce->ce_be->bd_info->bi_db_close( ce->ce_be, NULL );
                        }
@@ -6250,10 +6319,10 @@ config_back_delete( Operation *op, SlapReply *rs )
        } else {
                rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
        }
+out:
 #else
        rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
 #endif /* SLAP_CONFIG_DELETE */
-out:
        send_ldap_result( op, rs );
        return rs->sr_err;
 }
@@ -6556,11 +6625,12 @@ config_build_schema_inc( ConfigArgs *c, CfEntryInfo *ceparent,
                        bv.bv_len );
                c->value_dn.bv_len += bv.bv_len;
                c->value_dn.bv_val[c->value_dn.bv_len] ='\0';
-               rdn = c->value_dn;
+               rdnNormalize( 0, NULL, NULL, &c->value_dn, &rdn, NULL );
 
                c->ca_private = cf;
                e = config_build_entry( op, rs, ceparent, c, &rdn,
                        &CFOC_SCHEMA, NULL );
+               ch_free( rdn.bv_val );
                if ( !e ) {
                        return -1;
                } else if ( e && cf->c_kids ) {
@@ -7128,6 +7198,7 @@ config_tool_entry_put( BackendDB *be, Entry *e, struct berval *text )
        Operation *op = NULL;
        void *thrctx;
        int isFrontend = 0;
+       int isFrontendChild = 0;
 
        /* Create entry for frontend database if it does not exist already */
        if ( !entry_put_got_frontend ) {
@@ -7181,8 +7252,34 @@ config_tool_entry_put( BackendDB *be, Entry *e, struct berval *text )
                        }
                }
        }
+
+       /* Child entries of the frontend database, e.g. slapo-chain's back-ldap
+        * instances, may appear before the config database entry in the ldif, skip
+        * auto-creation of olcDatabase={0}config in such a case */
+       if ( !entry_put_got_config &&
+                       !strncmp( e->e_nname.bv_val, "olcDatabase", STRLENOF( "olcDatabase" ))) {
+               struct berval pdn;
+               dnParent( &e->e_nname, &pdn );
+               while ( pdn.bv_len ) {
+                       if ( !strncmp( pdn.bv_val, "olcDatabase",
+                                       STRLENOF( "olcDatabase" ))) {
+                               if ( !strncmp( pdn.bv_val +
+                                               STRLENOF( "olcDatabase" ), "={-1}frontend",
+                                               STRLENOF( "={-1}frontend" )) ||
+                                               !strncmp( pdn.bv_val +
+                                               STRLENOF( "olcDatabase" ), "=frontend",
+                                               STRLENOF( "=frontend" ))) {
+
+                                       isFrontendChild = 1;
+                                       break;
+                               }
+                       }
+                       dnParent( &pdn, &pdn );
+               }
+       }
+
        /* Create entry for config database if it does not exist already */
-       if ( !entry_put_got_config && !isFrontend ) {
+       if ( !entry_put_got_config && !isFrontend && !isFrontendChild ) {
                if ( !strncmp( e->e_nname.bv_val, "olcDatabase",
                                STRLENOF( "olcDatabase" ))) {
                        if ( strncmp( e->e_nname.bv_val +