]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-bdb/config.c
return structuralObjectClass errors
[openldap] / servers / slapd / back-bdb / config.c
index ad242744c711080189e22380e6e8e55a11408350..34530f38f2f08043856ecfb80ea8001b2ca5761e 100644 (file)
@@ -2,7 +2,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 2000-2005 The OpenLDAP Foundation.
+ * Copyright 2000-2006 The OpenLDAP Foundation.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -17,6 +17,7 @@
 #include "portable.h"
 
 #include <stdio.h>
+#include <ac/ctype.h>
 #include <ac/string.h>
 
 #include "back-bdb.h"
 #      define  SLAP_BDB_ALLOW_DIRTY_READ
 #endif
 
-#define bdb_cf_oc                      BDB_SYMBOL(cf_oc)
 #define bdb_cf_gen                     BDB_SYMBOL(cf_gen)
 #define        bdb_cf_cleanup          BDB_SYMBOL(cf_cleanup)
 #define bdb_checkpoint         BDB_SYMBOL(checkpoint)
 #define bdb_online_index       BDB_SYMBOL(online_index)
 
-static ObjectClass *bdb_oc;
-
-static ConfigDriver bdb_cf_oc, bdb_cf_gen;
+static ConfigDriver bdb_cf_gen;
 
 enum {
        BDB_CHKPT = 1,
@@ -52,13 +50,16 @@ enum {
 };
 
 static ConfigTable bdbcfg[] = {
-       { "", "", 0, 0, 0, ARG_MAGIC,
-               bdb_cf_oc, NULL, NULL, NULL },
        { "directory", "dir", 2, 2, 0, ARG_STRING|ARG_MAGIC|BDB_DIRECTORY,
                bdb_cf_gen, "( OLcfgDbAt:0.1 NAME 'olcDbDirectory' "
                        "DESC 'Directory for database content' "
                        "EQUALITY caseIgnoreMatch "
                        "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
+       { "cachefree", "size", 2, 2, 0, ARG_INT|ARG_OFFSET,
+               (void *)offsetof(struct bdb_info, bi_cache.c_minfree),
+               "( OLcfgDbAt:1.11 NAME 'olcDbCacheFree' "
+                       "DESC 'Number of extra entries to free when max is reached' "
+                       "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
        { "cachesize", "size", 2, 2, 0, ARG_INT|ARG_OFFSET,
                (void *)offsetof(struct bdb_info, bi_cache.c_maxsize),
                "( OLcfgDbAt:1.1 NAME 'olcDbCacheSize' "
@@ -68,10 +69,10 @@ static ConfigTable bdbcfg[] = {
                bdb_cf_gen, "( OLcfgDbAt:1.2 NAME 'olcDbCheckpoint' "
                        "DESC 'Database checkpoint interval in kbytes and minutes' "
                        "SYNTAX OMsDirectoryString SINGLE-VALUE )",NULL, NULL },
-       { "dbconfig", "DB_CONFIG setting", 3, 0, 0, ARG_MAGIC|BDB_CONFIG,
+       { "dbconfig", "DB_CONFIG setting", 1, 0, 0, ARG_MAGIC|BDB_CONFIG,
                bdb_cf_gen, "( OLcfgDbAt:1.3 NAME 'olcDbConfig' "
                        "DESC 'BerkeleyDB DB_CONFIG configuration directives' "
-                       "SYNTAX OMsDirectoryString )",NULL, NULL },
+                       "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
        { "dbnosync", NULL, 1, 2, 0, ARG_ON_OFF|ARG_MAGIC|BDB_NOSYNC,
                bdb_cf_gen, "( OLcfgDbAt:1.4 NAME 'olcDbNoSync' "
                        "DESC 'Disable synchronous database writes' "
@@ -123,29 +124,27 @@ static ConfigTable bdbcfg[] = {
 };
 
 static ConfigOCs bdbocs[] = {
-       { "( OLcfgDbOc:1.1 "
+       {
+#ifdef BDB_HIER
+               "( OLcfgDbOc:1.2 "
+               "NAME 'olcHdbConfig' "
+               "DESC 'HDB backend configuration' "
+#else
+               "( OLcfgDbOc:1.1 "
                "NAME 'olcBdbConfig' "
                "DESC 'BDB backend configuration' "
+#endif
                "SUP olcDatabaseConfig "
                "MUST olcDbDirectory "
                "MAY ( olcDbCacheSize $ olcDbCheckpoint $ olcDbConfig $ "
                "olcDbNoSync $ olcDbDirtyRead $ olcDbIDLcacheSize $ "
                "olcDbIndex $ olcDbLinearIndex $ olcDbLockDetect $ "
-               "olcDbMode $ olcDbSearchStack $ olcDbShmKey ) )",
-                       Cft_Database, &bdb_oc },
+               "olcDbMode $ olcDbSearchStack $ olcDbShmKey $ "
+               " olcDbCacheFree ) )",
+                       Cft_Database, bdbcfg },
        { NULL, 0, NULL }
 };
 
-static int
-bdb_cf_oc(ConfigArgs *c)
-{
-       if ( c->op == SLAP_CONFIG_EMIT ) {
-               value_add_one( &c->rvalue_vals, &bdb_oc->soc_cname );
-               return 0;
-       }
-       return 1;
-}
-
 static slap_verbmasks bdb_lockd[] = {
        { BER_BVC("default"), DB_LOCK_DEFAULT },
        { BER_BVC("oldest"), DB_LOCK_OLDEST },
@@ -179,8 +178,8 @@ bdb_online_index( void *ctx, void *arg )
        struct bdb_info *bdb = be->be_private;
 
        Connection conn = {0};
-       char opbuf[OPERATION_BUFFER_SIZE];
-       Operation *op = (Operation *)opbuf;
+       OperationBuffer opbuf;
+       Operation *op = (Operation *) &opbuf;
 
        DBC *curs;
        DBT key, data;
@@ -190,6 +189,7 @@ bdb_online_index( void *ctx, void *arg )
        ID id, nid;
        EntryInfo *ei;
        int rc, getnext = 1;
+       int i;
 
        connection_fake_init( &conn, op, ctx );
 
@@ -270,7 +270,17 @@ bdb_online_index( void *ctx, void *arg )
                id++;
                getnext = 1;
        }
-out:
+
+       for ( i = 0; i < bdb->bi_nattrs; i++ ) {
+               if ( bdb->bi_attrs[ i ]->ai_indexmask & BDB_INDEX_DELETING
+                       || bdb->bi_attrs[ i ]->ai_newmask == 0 )
+               {
+                       continue;
+               }
+               bdb->bi_attrs[ i ]->ai_indexmask = bdb->bi_attrs[ i ]->ai_newmask;
+               bdb->bi_attrs[ i ]->ai_newmask = 0;
+       }
+
        ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
        ldap_pvt_runqueue_stoptask( &slapd_rq, rtask );
        bdb->bi_index_task = NULL;
@@ -363,12 +373,12 @@ bdb_cf_gen(ConfigArgs *c)
                                        bdb->bi_flags |= BDB_HAS_CONFIG;
                                        while ( fgets( buf, sizeof(buf), f )) {
                                                ber_str2bv( buf, 0, 1, &bv );
-                                               if ( bv.bv_val[bv.bv_len-1] == '\n' ) {
+                                               if ( bv.bv_len > 0 && bv.bv_val[bv.bv_len-1] == '\n' ) {
                                                        bv.bv_len--;
                                                        bv.bv_val[bv.bv_len] = '\0';
                                                }
                                                /* shouldn't need this, but ... */
-                                               if ( bv.bv_val[bv.bv_len-1] == '\r' ) {
+                                               if ( bv.bv_len > 0 && bv.bv_val[bv.bv_len-1] == '\r' ) {
                                                        bv.bv_len--;
                                                        bv.bv_val[bv.bv_len] = '\0';
                                                }
@@ -465,56 +475,113 @@ bdb_cf_gen(ConfigArgs *c)
                case BDB_NOSYNC:
                        bdb->bi_dbenv->set_flags( bdb->bi_dbenv, DB_TXN_NOSYNC, 0 );
                        break;
-               case BDB_INDEX: {
-                       AttributeDescription *ad = NULL;
-                       struct berval bv, def = BER_BVC("default");
-                       char *ptr;
-                       const char *text;
-                       for (ptr = c->line; !isspace( *ptr ); ptr++);
-                       bv.bv_val = c->line;
-                       bv.bv_len = ptr - bv.bv_val;
-                       if ( bvmatch( &bv, &def )) {
-                               bdb->bi_defaultmask = 0;
+               case BDB_INDEX:
+                       if ( c->valx == -1 ) {
+                               int i;
+
+                               /* delete all (FIXME) */
+                               for ( i = 0; i < bdb->bi_nattrs; i++ ) {
+                                       bdb->bi_attrs[i]->ai_indexmask |= BDB_INDEX_DELETING;
+                               }
+                               bdb->bi_flags |= BDB_DEL_INDEX;
+                               c->cleanup = bdb_cf_cleanup;
+
                        } else {
-                               slap_bv2ad( &bv, &ad, &text );
-                               if ( ad ) {
-                                       AttrInfo *ai = bdb_attr_mask( bdb, ad );
-                                       ai->ai_indexmask |= BDB_INDEX_DELETING;
-                                       bdb->bi_flags |= BDB_DEL_INDEX;
-                                       c->cleanup = bdb_cf_cleanup;
+                               struct berval bv, def = BER_BVC("default");
+                               char *ptr;
+
+                               for (ptr = c->line; !isspace( (unsigned char) *ptr ); ptr++);
+
+                               bv.bv_val = c->line;
+                               bv.bv_len = ptr - bv.bv_val;
+                               if ( bvmatch( &bv, &def )) {
+                                       bdb->bi_defaultmask = 0;
+
+                               } else {
+                                       int i;
+                                       char **attrs;
+                                       char sep;
+
+                                       sep = bv.bv_val[ bv.bv_len ];
+                                       bv.bv_val[ bv.bv_len ] = '\0';
+                                       attrs = ldap_str2charray( bv.bv_val, "," );
+
+                                       for ( i = 0; attrs[ i ]; i++ ) {
+                                               AttributeDescription *ad = NULL;
+                                               const char *text;
+                                               AttrInfo *ai;
+
+                                               slap_str2ad( attrs[ i ], &ad, &text );
+                                               /* if we got here... */
+                                               assert( ad != NULL );
+
+                                               ai = bdb_attr_mask( bdb, ad );
+                                               /* if we got here... */
+                                               assert( ai != NULL );
+
+                                               ai->ai_indexmask |= BDB_INDEX_DELETING;
+                                               bdb->bi_flags |= BDB_DEL_INDEX;
+                                               c->cleanup = bdb_cf_cleanup;
+                                       }
+
+                                       bv.bv_val[ bv.bv_len ] = sep;
+                                       ldap_charray_free( attrs );
                                }
                        }
-                       }
                        break;
                }
                return rc;
        }
 
        switch( c->type ) {
-       case BDB_CHKPT:
+       case BDB_CHKPT: {
+               long    l;
                bdb->bi_txn_cp = 1;
-               bdb->bi_txn_cp_kbyte = strtol( c->argv[1], NULL, 0 );
-               bdb->bi_txn_cp_min = strtol( c->argv[2], NULL, 0 );
+               if ( lutil_atolx( &l, c->argv[1], 0 ) != 0 ) {
+                       fprintf( stderr, "%s: "
+                               "invalid kbyte \"%s\" in \"checkpoint\".\n",
+                               c->log, c->argv[1] );
+                       return 1;
+               }
+               bdb->bi_txn_cp_kbyte = l;
+               if ( lutil_atolx( &l, c->argv[2], 0 ) != 0 ) {
+                       fprintf( stderr, "%s: "
+                               "invalid minutes \"%s\" in \"checkpoint\".\n",
+                               c->log, c->argv[2] );
+                       return 1;
+               }
+               bdb->bi_txn_cp_min = l;
                /* If we're in server mode and time-based checkpointing is enabled,
                 * submit a task to perform periodic checkpoints.
                 */
                if ((slapMode & SLAP_SERVER_MODE) && bdb->bi_txn_cp_min ) {
                        struct re_s *re = bdb->bi_txn_cp_task;
-                       if ( re )
+                       if ( re ) {
                                re->interval.tv_sec = bdb->bi_txn_cp_min * 60;
-                       else
+                       } else {
+                               if ( c->be->be_suffix == NULL || BER_BVISNULL( &c->be->be_suffix[0] ) ) {
+                                       fprintf( stderr, "%s: "
+                                               "\"checkpoint\" must occur after \"suffix\".\n",
+                                               c->log );
+                                       return 1;
+                               }
                                bdb->bi_txn_cp_task = ldap_pvt_runqueue_insert( &slapd_rq,
                                        bdb->bi_txn_cp_min * 60, bdb_checkpoint, bdb,
                                        LDAP_XSTRING(bdb_checkpoint), c->be->be_suffix[0].bv_val );
+                       }
                }
-               break;
+               break;
 
        case BDB_CONFIG: {
-               char *ptr = c->line + STRLENOF("dbconfig");
+               char *ptr = c->line;
                struct berval bv;
-               while (!isspace(*ptr)) ptr++;
-               while (isspace(*ptr)) ptr++;
-               
+
+               if ( c->op == SLAP_CONFIG_ADD ) {
+                       ptr += STRLENOF("dbconfig");
+                       while (!isspace((unsigned char)*ptr)) ptr++;
+                       while (isspace((unsigned char)*ptr)) ptr++;
+               }
+
                if ( bdb->bi_flags & BDB_IS_OPEN ) {
                        bdb->bi_flags |= BDB_UPD_CONFIG;
                        c->cleanup = bdb_cf_cleanup;
@@ -584,6 +651,12 @@ bdb_cf_gen(ConfigArgs *c)
                        /* Start the task as soon as we finish here. Set a long
                         * interval (10 hours) so that it only gets scheduled once.
                         */
+                       if ( c->be->be_suffix == NULL || BER_BVISNULL( &c->be->be_suffix[0] ) ) {
+                               fprintf( stderr, "%s: "
+                                       "\"index\" must occur after \"suffix\".\n",
+                                       c->log );
+                               return 1;
+                       }
                        bdb->bi_index_task = ldap_pvt_runqueue_insert( &slapd_rq, 36000,
                                bdb_online_index, c->be,
                                LDAP_XSTRING(bdb_online_index), c->be->be_suffix[0].bv_val );
@@ -617,10 +690,9 @@ bdb_cf_gen(ConfigArgs *c)
 int bdb_back_init_cf( BackendInfo *bi )
 {
        int rc;
-       bi->bi_cf_table = bdbcfg;
+       bi->bi_cf_ocs = bdbocs;
 
        rc = config_register_schema( bdbcfg, bdbocs );
        if ( rc ) return rc;
-       bdbcfg[0].ad = slap_schema.si_ad_objectClass;
        return 0;
 }