]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/bconfig.c
fix typo
[openldap] / servers / slapd / bconfig.c
index 882be198c825b9c528af4e32b1abccd69fb73426..60dd39362dccd71156d3950dd7a0d7b8463afa0a 100644 (file)
@@ -254,6 +254,7 @@ static OidRec OidMacros[] = {
  * OLcfgOv{Oc|At}:17                   -> dyngroup
  * OLcfgOv{Oc|At}:18                   -> memberof
  * OLcfgOv{Oc|At}:19                   -> collect
+ * OLcfgOv{Oc|At}:20                   -> retcode
  */
 
 /* alphabetical ordering */
@@ -501,6 +502,7 @@ static ConfigTable config_back_cf_table[] = {
                        "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
        { "rootdn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
                &config_rootdn, "( OLcfgDbAt:0.8 NAME 'olcRootDN' "
+                       "EQUALITY distinguishedNameMatch "
                        "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
        { "rootDSE", "file", 2, 2, 0, ARG_MAGIC|CFG_ROOTDSE,
                &config_generic, "( OLcfgGlAt:51 NAME 'olcRootDSE' "
@@ -541,6 +543,7 @@ static ConfigTable config_back_cf_table[] = {
                &config_generic, NULL, NULL, NULL },
        { "schemadn", "dn", 2, 2, 0, ARG_MAY_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
                &config_schema_dn, "( OLcfgGlAt:58 NAME 'olcSchemaDN' "
+                       "EQUALITY distinguishedNameMatch "
                        "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
        { "security", "factors", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
                &config_security, "( OLcfgGlAt:59 NAME 'olcSecurity' "
@@ -1676,7 +1679,7 @@ sortval_reject:
                                                Listener **l = slapd_get_listeners();
                                                int i;
 
-                                               for ( i=0; l[i]; i++ ) {
+                                               for ( i=0; l && l[i]; i++ ) {
                                                        LDAPURLDesc *lu2;
                                                        int isMe = 0;
                                                        ldap_url_parse( l[i]->sl_url.bv_val, &lu2 );
@@ -3879,7 +3882,7 @@ check_name_index( CfEntryInfo *parent, ConfigType ce_type, Entry *e,
                if ( isconfig && index == -1 ) {
                        index = 0;
                }
-               if ( !isfrontend && index == -1 ) {
+               if (( !isfrontend && index == -1 ) || ( index > nsibs ) ){
                        index = nsibs;
                }
 
@@ -3990,6 +3993,11 @@ cfAddDatabase( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
        if ( p->ce_type != Cft_Global ) {
                return LDAP_CONSTRAINT_VIOLATION;
        }
+       /* config must be {0}, nothing else allowed */
+       if ( !strncmp( e->e_nname.bv_val, "olcDatabase={0}", STRLENOF("olcDatabase={0}")) &&
+               strncmp( e->e_nname.bv_val + STRLENOF("olcDatabase={0}"), "config,", STRLENOF("config,") )) {
+               return LDAP_CONSTRAINT_VIOLATION;
+       }
        ca->be = frontendDB;    /* just to get past check_vals */
        return LDAP_SUCCESS;
 }
@@ -5225,7 +5233,102 @@ out:
 static int
 config_back_delete( Operation *op, SlapReply *rs )
 {
-       send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM, NULL );
+#ifdef SLAP_CONFIG_DELETE
+       CfBackInfo *cfb;
+       CfEntryInfo *ce, *last, *ce2;
+
+       cfb = (CfBackInfo *)op->o_bd->be_private;
+
+       ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
+       if ( !ce ) {
+               if ( last )
+                       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;
+       } else if ( ce->ce_type == Cft_Overlay || ce->ce_type == Cft_Database ){
+               char *iptr;
+               int count, ixold;
+
+               ldap_pvt_thread_pool_pause( &connection_pool );
+
+               if ( ce->ce_type == Cft_Overlay ){
+                       overlay_remove( ce->ce_be, (slap_overinst *)ce->ce_bi );
+               } else { /* 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 );
+                       }
+                       backend_destroy_one( ce->ce_be, 1);
+               }
+
+               /* remove CfEntryInfo from the siblings list */
+               if ( ce->ce_parent->ce_kids == ce ) {
+                       ce->ce_parent->ce_kids = ce->ce_sibs;
+               } else {
+                       for ( ce2 = ce->ce_parent->ce_kids ; ce2; ce2 = ce2->ce_sibs ) {
+                               if ( ce2->ce_sibs == ce ) {
+                                       ce2->ce_sibs = ce->ce_sibs;
+                                       break;
+                               }
+                       }
+               }
+
+               /* remove from underlying database */
+               if ( cfb->cb_use_ldif ) {
+                       BackendDB *be = op->o_bd;
+                       slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
+                       struct berval dn, ndn, req_dn, req_ndn;
+
+                       op->o_bd = &cfb->cb_db;
+
+                       dn = op->o_dn;
+                       ndn = op->o_ndn;
+                       req_dn = op->o_req_dn;
+                       req_ndn = op->o_req_ndn;
+
+                       op->o_dn = op->o_bd->be_rootdn;
+                       op->o_ndn = op->o_bd->be_rootndn;
+                       op->o_req_dn = ce->ce_entry->e_name;
+                       op->o_req_ndn = ce->ce_entry->e_nname;
+
+                       scp = op->o_callback;
+                       op->o_callback = ≻
+                       op->o_bd->be_delete( op, rs );
+                       op->o_bd = be;
+                       op->o_callback = scp;
+                       op->o_dn = dn;
+                       op->o_ndn = ndn;
+                       op->o_req_dn = req_dn;
+                       op->o_req_ndn = req_ndn;
+               }
+
+               /* renumber siblings */
+               iptr = ber_bvchr( &op->o_req_ndn, '{' ) + 1;
+               ixold = strtol( iptr, NULL, 0 );
+               for (ce2 = ce->ce_sibs, count=0; ce2; ce2=ce2->ce_sibs) {
+                       config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
+                               count+ixold, 0, cfb->cb_use_ldif );
+                       count++;
+               }
+
+               ce->ce_entry->e_private=NULL;
+               entry_free(ce->ce_entry);
+               ch_free(ce);
+               ldap_pvt_thread_pool_resume( &connection_pool );
+       } else {
+               rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
+       }
+#else
+       rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
+#endif /* SLAP_CONFIG_DELETE */
+out:
+       send_ldap_result( op, rs );
        return rs->sr_err;
 }
 
@@ -5372,7 +5475,7 @@ config_build_entry( Operation *op, SlapReply *rs, CfEntryInfo *parent,
        ce->ce_parent = parent;
        if ( parent ) {
                pdn = parent->ce_entry->e_nname;
-               if ( parent->ce_kids )
+               if ( parent->ce_kids && parent->ce_kids->ce_type <= ce->ce_type )
                        for ( ceprev = parent->ce_kids; ceprev->ce_sibs &&
                                ceprev->ce_type <= ce->ce_type;
                                ceprev = ceprev->ce_sibs );
@@ -5424,6 +5527,12 @@ config_build_entry( Operation *op, SlapReply *rs, CfEntryInfo *parent,
        oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
        rc = structural_class(oc_at->a_vals, &oc, NULL, &text, c->cr_msg,
                sizeof(c->cr_msg), op ? op->o_tmpmemctx : NULL );
+       if ( rc != LDAP_SUCCESS ) {
+               Debug( LDAP_DEBUG_ANY,
+                       "config_build_entry: build \"%s\" failed: \"%s\"\n",
+                       rdn->bv_val, text, 0);
+               return NULL;
+       }
        attr_merge_normalize_one(e, slap_schema.si_ad_structuralObjectClass, &oc->soc_cname, NULL );
        if ( op ) {
                op->ora_e = e;