1 /* config.c - bdb backend configuration file routine */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2000-2008 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
21 #include <ac/string.h>
32 # define SLAP_BDB_ALLOW_DIRTY_READ
35 #define bdb_cf_gen BDB_SYMBOL(cf_gen)
36 #define bdb_cf_cleanup BDB_SYMBOL(cf_cleanup)
37 #define bdb_checkpoint BDB_SYMBOL(checkpoint)
38 #define bdb_online_index BDB_SYMBOL(online_index)
40 static ConfigDriver bdb_cf_gen;
57 static ConfigTable bdbcfg[] = {
58 { "directory", "dir", 2, 2, 0, ARG_STRING|ARG_MAGIC|BDB_DIRECTORY,
59 bdb_cf_gen, "( OLcfgDbAt:0.1 NAME 'olcDbDirectory' "
60 "DESC 'Directory for database content' "
61 "EQUALITY caseIgnoreMatch "
62 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
63 { "cachefree", "size", 2, 2, 0, ARG_UINT|ARG_OFFSET,
64 (void *)offsetof(struct bdb_info, bi_cache.c_minfree),
65 "( OLcfgDbAt:1.11 NAME 'olcDbCacheFree' "
66 "DESC 'Number of extra entries to free when max is reached' "
67 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
68 { "cachesize", "size", 2, 2, 0, ARG_UINT|ARG_OFFSET,
69 (void *)offsetof(struct bdb_info, bi_cache.c_maxsize),
70 "( OLcfgDbAt:1.1 NAME 'olcDbCacheSize' "
71 "DESC 'Entry cache size in entries' "
72 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
73 { "checkpoint", "kbyte> <min", 3, 3, 0, ARG_MAGIC|BDB_CHKPT,
74 bdb_cf_gen, "( OLcfgDbAt:1.2 NAME 'olcDbCheckpoint' "
75 "DESC 'Database checkpoint interval in kbytes and minutes' "
76 "SYNTAX OMsDirectoryString SINGLE-VALUE )",NULL, NULL },
77 { "cryptfile", "file", 2, 2, 0, ARG_STRING|ARG_MAGIC|BDB_CRYPTFILE,
78 bdb_cf_gen, "( OLcfgDbAt:1.13 NAME 'olcDbCryptFile' "
79 "DESC 'Pathname of file containing the DB encryption key' "
80 "SYNTAX OMsDirectoryString SINGLE-VALUE )",NULL, NULL },
81 { "cryptkey", "key", 2, 2, 0, ARG_BERVAL|ARG_MAGIC|BDB_CRYPTKEY,
82 bdb_cf_gen, "( OLcfgDbAt:1.14 NAME 'olcDbCryptKey' "
83 "DESC 'DB encryption key' "
84 "SYNTAX OMsOctetString SINGLE-VALUE )",NULL, NULL },
85 { "dbconfig", "DB_CONFIG setting", 1, 0, 0, ARG_MAGIC|BDB_CONFIG,
86 bdb_cf_gen, "( OLcfgDbAt:1.3 NAME 'olcDbConfig' "
87 "DESC 'BerkeleyDB DB_CONFIG configuration directives' "
88 "SYNTAX OMsIA5String X-ORDERED 'VALUES' )", NULL, NULL },
89 { "dbnosync", NULL, 1, 2, 0, ARG_ON_OFF|ARG_MAGIC|BDB_NOSYNC,
90 bdb_cf_gen, "( OLcfgDbAt:1.4 NAME 'olcDbNoSync' "
91 "DESC 'Disable synchronous database writes' "
92 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
93 { "dbpagesize", "db> <size", 3, 3, 0, ARG_MAGIC|BDB_PGSIZE,
94 bdb_cf_gen, "( OLcfgDbAt:1.15 NAME 'olcDbPageSize' "
95 "DESC 'Page size of specified DB, in Kbytes' "
96 "EQUALITY caseExactMatch "
97 "SYNTAX OMsDirectoryString )", NULL, NULL },
98 { "dirtyread", NULL, 1, 2, 0,
99 #ifdef SLAP_BDB_ALLOW_DIRTY_READ
100 ARG_ON_OFF|ARG_MAGIC|BDB_DIRTYR, bdb_cf_gen,
104 "( OLcfgDbAt:1.5 NAME 'olcDbDirtyRead' "
105 "DESC 'Allow reads of uncommitted data' "
106 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
107 { "dncachesize", "size", 2, 2, 0, ARG_UINT|ARG_OFFSET,
108 (void *)offsetof(struct bdb_info, bi_cache.c_eimax),
109 "( OLcfgDbAt:1.12 NAME 'olcDbDNcacheSize' "
110 "DESC 'DN cache size' "
111 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
112 { "idlcachesize", "size", 2, 2, 0, ARG_UINT|ARG_OFFSET,
113 (void *)offsetof(struct bdb_info, bi_idl_cache_max_size),
114 "( OLcfgDbAt:1.6 NAME 'olcDbIDLcacheSize' "
115 "DESC 'IDL cache size in IDLs' "
116 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
117 { "index", "attr> <[pres,eq,approx,sub]", 2, 3, 0, ARG_MAGIC|BDB_INDEX,
118 bdb_cf_gen, "( OLcfgDbAt:0.2 NAME 'olcDbIndex' "
119 "DESC 'Attribute index parameters' "
120 "EQUALITY caseIgnoreMatch "
121 "SYNTAX OMsDirectoryString )", NULL, NULL },
122 { "linearindex", NULL, 1, 2, 0, ARG_ON_OFF|ARG_OFFSET,
123 (void *)offsetof(struct bdb_info, bi_linear_index),
124 "( OLcfgDbAt:1.7 NAME 'olcDbLinearIndex' "
125 "DESC 'Index attributes one at a time' "
126 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
127 { "lockdetect", "policy", 2, 2, 0, ARG_MAGIC|BDB_LOCKD,
128 bdb_cf_gen, "( OLcfgDbAt:1.8 NAME 'olcDbLockDetect' "
129 "DESC 'Deadlock detection algorithm' "
130 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
131 { "mode", "mode", 2, 2, 0, ARG_MAGIC|BDB_MODE,
132 bdb_cf_gen, "( OLcfgDbAt:0.3 NAME 'olcDbMode' "
133 "DESC 'Unix permissions of database files' "
134 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
135 { "searchstack", "depth", 2, 2, 0, ARG_INT|ARG_MAGIC|BDB_SSTACK,
136 bdb_cf_gen, "( OLcfgDbAt:1.9 NAME 'olcDbSearchStack' "
137 "DESC 'Depth of search stack in IDLs' "
138 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
139 { "shm_key", "key", 2, 2, 0, ARG_LONG|ARG_OFFSET,
140 (void *)offsetof(struct bdb_info, bi_shm_key),
141 "( OLcfgDbAt:1.10 NAME 'olcDbShmKey' "
142 "DESC 'Key for shared memory region' "
143 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
144 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
145 NULL, NULL, NULL, NULL }
148 static ConfigOCs bdbocs[] = {
152 "NAME 'olcHdbConfig' "
153 "DESC 'HDB backend configuration' "
156 "NAME 'olcBdbConfig' "
157 "DESC 'BDB backend configuration' "
159 "SUP olcDatabaseConfig "
160 "MUST olcDbDirectory "
161 "MAY ( olcDbCacheSize $ olcDbCheckpoint $ olcDbConfig $ "
162 "olcDbCryptFile $ olcDbCryptKey $ "
163 "olcDbNoSync $ olcDbDirtyRead $ olcDbIDLcacheSize $ "
164 "olcDbIndex $ olcDbLinearIndex $ olcDbLockDetect $ "
165 "olcDbMode $ olcDbSearchStack $ olcDbShmKey $ "
166 "olcDbCacheFree $ olcDbDNcacheSize $ olcDbPageSize ) )",
167 Cft_Database, bdbcfg },
171 static slap_verbmasks bdb_lockd[] = {
172 { BER_BVC("default"), DB_LOCK_DEFAULT },
173 { BER_BVC("oldest"), DB_LOCK_OLDEST },
174 { BER_BVC("random"), DB_LOCK_RANDOM },
175 { BER_BVC("youngest"), DB_LOCK_YOUNGEST },
176 { BER_BVC("fewest"), DB_LOCK_MINLOCKS },
180 /* perform periodic checkpoints */
182 bdb_checkpoint( void *ctx, void *arg )
184 struct re_s *rtask = arg;
185 struct bdb_info *bdb = rtask->arg;
187 TXN_CHECKPOINT( bdb->bi_dbenv, bdb->bi_txn_cp_kbyte,
188 bdb->bi_txn_cp_min, 0 );
189 ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
190 ldap_pvt_runqueue_stoptask( &slapd_rq, rtask );
191 ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
195 /* reindex entries on the fly */
197 bdb_online_index( void *ctx, void *arg )
199 struct re_s *rtask = arg;
200 BackendDB *be = rtask->arg;
201 struct bdb_info *bdb = be->be_private;
203 Connection conn = {0};
204 OperationBuffer opbuf;
216 connection_fake_init( &conn, &opbuf, ctx );
226 key.size = key.ulen = sizeof(ID);
227 key.flags = DB_DBT_USERMEM;
229 data.flags = DB_DBT_USERMEM | DB_DBT_PARTIAL;
230 data.dlen = data.ulen = 0;
233 if ( slapd_shutdown )
236 rc = TXN_BEGIN( bdb->bi_dbenv, NULL, &txn, bdb->bi_db_opflags );
241 BDB_ID2DISK( id, &nid );
242 rc = bdb->bi_id2entry->bdi_db->cursor(
243 bdb->bi_id2entry->bdi_db, txn, &curs, bdb->bi_db_opflags );
248 rc = curs->c_get( curs, &key, &data, DB_SET_RANGE );
249 curs->c_close( curs );
252 if ( rc == DB_NOTFOUND )
254 if ( rc == DB_LOCK_DEADLOCK ) {
255 ldap_pvt_thread_yield();
260 BDB_DISK2ID( &nid, &id );
264 rc = bdb_cache_find_id( op, txn, id, &ei, 0, &lock );
267 if ( rc == DB_LOCK_DEADLOCK ) {
268 ldap_pvt_thread_yield();
271 if ( rc == DB_NOTFOUND ) {
279 rc = bdb_index_entry( op, txn, BDB_INDEX_UPDATE_OP, ei->bei_e );
280 if ( rc == DB_LOCK_DEADLOCK ) {
282 ldap_pvt_thread_yield();
286 rc = TXN_COMMIT( txn, 0 );
296 for ( i = 0; i < bdb->bi_nattrs; i++ ) {
297 if ( bdb->bi_attrs[ i ]->ai_indexmask & BDB_INDEX_DELETING
298 || bdb->bi_attrs[ i ]->ai_newmask == 0 )
302 bdb->bi_attrs[ i ]->ai_indexmask = bdb->bi_attrs[ i ]->ai_newmask;
303 bdb->bi_attrs[ i ]->ai_newmask = 0;
306 ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
307 ldap_pvt_runqueue_stoptask( &slapd_rq, rtask );
308 bdb->bi_index_task = NULL;
309 ldap_pvt_runqueue_remove( &slapd_rq, rtask );
310 ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
315 /* Cleanup loose ends after Modify completes */
317 bdb_cf_cleanup( ConfigArgs *c )
319 struct bdb_info *bdb = c->be->be_private;
322 if ( bdb->bi_flags & BDB_UPD_CONFIG ) {
323 if ( bdb->bi_db_config ) {
325 FILE *f = fopen( bdb->bi_db_config_path, "w" );
327 for (i=0; bdb->bi_db_config[i].bv_val; i++)
328 fprintf( f, "%s\n", bdb->bi_db_config[i].bv_val );
332 unlink( bdb->bi_db_config_path );
334 bdb->bi_flags ^= BDB_UPD_CONFIG;
337 if ( bdb->bi_flags & BDB_DEL_INDEX ) {
338 bdb_attr_flush( bdb );
339 bdb->bi_flags ^= BDB_DEL_INDEX;
342 if ( bdb->bi_flags & BDB_RE_OPEN ) {
343 bdb->bi_flags ^= BDB_RE_OPEN;
344 rc = c->be->bd_info->bi_db_close( c->be, &c->reply );
346 rc = c->be->bd_info->bi_db_open( c->be, &c->reply );
347 /* If this fails, we need to restart */
350 snprintf( c->cr_msg, sizeof( c->cr_msg ),
351 "failed to reopen database, rc=%d", rc );
352 Debug( LDAP_DEBUG_ANY, LDAP_XSTRING(bdb_cf_cleanup)
353 ": %s\n", c->cr_msg, 0, 0 );
361 bdb_cf_gen( ConfigArgs *c )
363 struct bdb_info *bdb = c->be->be_private;
366 if ( c->op == SLAP_CONFIG_EMIT ) {
372 bv.bv_len = snprintf( buf, sizeof(buf), "0%o", bdb->bi_dbenv_mode );
373 if ( bv.bv_len > 0 && bv.bv_len < sizeof(buf) ) {
375 value_add_one( &c->rvalue_vals, &bv );
382 if ( bdb->bi_txn_cp ) {
385 bv.bv_len = snprintf( buf, sizeof(buf), "%d %d", bdb->bi_txn_cp_kbyte,
386 bdb->bi_txn_cp_min );
387 if ( bv.bv_len > 0 && bv.bv_len < sizeof(buf) ) {
389 value_add_one( &c->rvalue_vals, &bv );
399 if ( bdb->bi_db_crypt_file ) {
400 c->value_string = ch_strdup( bdb->bi_db_crypt_file );
406 /* If a crypt file has been set, its contents are copied here.
407 * But we don't want the key to be incorporated here.
410 if ( !bdb->bi_db_crypt_file && !BER_BVISNULL( &bdb->bi_db_crypt_key )) {
411 value_add_one( &c->rvalue_vals, &bdb->bi_db_crypt_key );
418 if ( bdb->bi_dbenv_home ) {
419 c->value_string = ch_strdup( bdb->bi_dbenv_home );
426 if ( !( bdb->bi_flags & BDB_IS_OPEN )
427 && !bdb->bi_db_config )
429 char buf[SLAP_TEXT_BUFLEN];
430 FILE *f = fopen( bdb->bi_db_config_path, "r" );
434 bdb->bi_flags |= BDB_HAS_CONFIG;
435 while ( fgets( buf, sizeof(buf), f )) {
436 ber_str2bv( buf, 0, 1, &bv );
437 if ( bv.bv_len > 0 && bv.bv_val[bv.bv_len-1] == '\n' ) {
439 bv.bv_val[bv.bv_len] = '\0';
441 /* shouldn't need this, but ... */
442 if ( bv.bv_len > 0 && bv.bv_val[bv.bv_len-1] == '\r' ) {
444 bv.bv_val[bv.bv_len] = '\0';
446 ber_bvarray_add( &bdb->bi_db_config, &bv );
451 if ( bdb->bi_db_config ) {
456 for (i=0; !BER_BVISNULL(&bdb->bi_db_config[i]); i++) {
457 bv.bv_len = sprintf( bv.bv_val, "{%d}%s", i,
458 bdb->bi_db_config[i].bv_val );
459 value_add_one( &c->rvalue_vals, &bv );
462 if ( !c->rvalue_vals ) rc = 1;
466 if ( bdb->bi_dbenv_xflags & DB_TXN_NOSYNC )
471 bdb_attr_index_unparse( bdb, &c->rvalue_vals );
472 if ( !c->rvalue_vals ) rc = 1;
477 if ( bdb->bi_lock_detect != DB_LOCK_DEFAULT ) {
479 for (i=0; !BER_BVISNULL(&bdb_lockd[i].word); i++) {
480 if ( bdb->bi_lock_detect == bdb_lockd[i].mask ) {
481 value_add_one( &c->rvalue_vals, &bdb_lockd[i].word );
490 c->value_int = bdb->bi_search_stack_depth;
494 struct bdb_db_pgsize *ps;
495 char buf[SLAP_TEXT_BUFLEN];
500 for ( ps = bdb->bi_pagesizes; ps; ps = ps->bdp_next ) {
501 bv.bv_len = sprintf( buf, "%s %d", ps->bdp_name.bv_val,
502 ps->bdp_size / 1024 );
503 value_add_one( &c->rvalue_vals, &bv );
511 } else if ( c->op == LDAP_MOD_DELETE ) {
516 /* FIXME: does it make any sense to change the mode,
517 * if we don't exec a chmod()? */
518 bdb->bi_dbenv_mode = SLAPD_DEFAULT_DB_MODE;
522 /* single-valued no-ops */
528 if ( bdb->bi_txn_cp_task ) {
529 struct re_s *re = bdb->bi_txn_cp_task;
530 bdb->bi_txn_cp_task = NULL;
531 ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
532 if ( ldap_pvt_runqueue_isrunning( &slapd_rq, re ) )
533 ldap_pvt_runqueue_stoptask( &slapd_rq, re );
534 ldap_pvt_runqueue_remove( &slapd_rq, re );
535 ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
541 ber_bvarray_free( bdb->bi_db_config );
542 bdb->bi_db_config = NULL;
545 ch_free( bdb->bi_db_config[i].bv_val );
546 for (; bdb->bi_db_config[i].bv_val; i++)
547 bdb->bi_db_config[i] = bdb->bi_db_config[i+1];
549 bdb->bi_flags |= BDB_UPD_CONFIG;
550 c->cleanup = bdb_cf_cleanup;
552 /* Doesn't really make sense to change these on the fly;
553 * the entire DB must be dumped and reloaded
556 if ( bdb->bi_db_crypt_file ) {
557 ch_free( bdb->bi_db_crypt_file );
558 bdb->bi_db_crypt_file = NULL;
562 if ( !BER_BVISNULL( &bdb->bi_db_crypt_key )) {
563 ch_free( bdb->bi_db_crypt_key.bv_val );
564 BER_BVZERO( &bdb->bi_db_crypt_key );
568 bdb->bi_flags |= BDB_RE_OPEN;
569 bdb->bi_flags ^= BDB_HAS_CONFIG;
570 ch_free( bdb->bi_dbenv_home );
571 bdb->bi_dbenv_home = NULL;
572 ch_free( bdb->bi_db_config_path );
573 bdb->bi_db_config_path = NULL;
574 c->cleanup = bdb_cf_cleanup;
575 ldap_pvt_thread_pool_purgekey( bdb->bi_dbenv );
578 bdb->bi_dbenv->set_flags( bdb->bi_dbenv, DB_TXN_NOSYNC, 0 );
581 if ( c->valx == -1 ) {
584 /* delete all (FIXME) */
585 for ( i = 0; i < bdb->bi_nattrs; i++ ) {
586 bdb->bi_attrs[i]->ai_indexmask |= BDB_INDEX_DELETING;
588 bdb->bi_flags |= BDB_DEL_INDEX;
589 c->cleanup = bdb_cf_cleanup;
592 struct berval bv, def = BER_BVC("default");
595 for (ptr = c->line; !isspace( (unsigned char) *ptr ); ptr++);
598 bv.bv_len = ptr - bv.bv_val;
599 if ( bvmatch( &bv, &def )) {
600 bdb->bi_defaultmask = 0;
607 sep = bv.bv_val[ bv.bv_len ];
608 bv.bv_val[ bv.bv_len ] = '\0';
609 attrs = ldap_str2charray( bv.bv_val, "," );
611 for ( i = 0; attrs[ i ]; i++ ) {
612 AttributeDescription *ad = NULL;
616 slap_str2ad( attrs[ i ], &ad, &text );
617 /* if we got here... */
618 assert( ad != NULL );
620 ai = bdb_attr_mask( bdb, ad );
621 /* if we got here... */
622 assert( ai != NULL );
624 ai->ai_indexmask |= BDB_INDEX_DELETING;
625 bdb->bi_flags |= BDB_DEL_INDEX;
626 c->cleanup = bdb_cf_cleanup;
629 bv.bv_val[ bv.bv_len ] = sep;
630 ldap_charray_free( attrs );
634 /* doesn't make sense on the fly; the DB file must be
638 struct bdb_db_pgsize *ps, **prev;
641 for ( i = 0, prev = &bdb->bi_pagesizes, ps = *prev; ps;
642 prev = &ps->bdp_next, ps = ps->bdp_next, i++ ) {
643 if ( c->valx == -1 || i == c->valx ) {
644 *prev = ps->bdp_next;
647 if ( i == c->valx ) break;
658 if ( ASCII_DIGIT( c->argv[1][0] ) ) {
662 mode = strtol( c->argv[1], &next, 0 );
663 if ( errno != 0 || next == c->argv[1] || next[0] != '\0' ) {
664 fprintf( stderr, "%s: "
665 "unable to parse mode=\"%s\".\n",
666 c->log, c->argv[1] );
669 bdb->bi_dbenv_mode = mode;
672 char *m = c->argv[1];
673 int who, what, mode = 0;
675 if ( strlen( m ) != STRLENOF("-rwxrwxrwx") ) {
684 for ( who = 0; who < 3; who++ ) {
685 for ( what = 0; what < 3; what++, m++ ) {
688 } else if ( m[0] != "rwx"[what] ) {
691 mode += ((1 << (2 - what)) << 3*(2 - who));
694 bdb->bi_dbenv_mode = mode;
700 if ( lutil_atolx( &l, c->argv[1], 0 ) != 0 ) {
701 fprintf( stderr, "%s: "
702 "invalid kbyte \"%s\" in \"checkpoint\".\n",
703 c->log, c->argv[1] );
706 bdb->bi_txn_cp_kbyte = l;
707 if ( lutil_atolx( &l, c->argv[2], 0 ) != 0 ) {
708 fprintf( stderr, "%s: "
709 "invalid minutes \"%s\" in \"checkpoint\".\n",
710 c->log, c->argv[2] );
713 bdb->bi_txn_cp_min = l;
714 /* If we're in server mode and time-based checkpointing is enabled,
715 * submit a task to perform periodic checkpoints.
717 if ((slapMode & SLAP_SERVER_MODE) && bdb->bi_txn_cp_min ) {
718 struct re_s *re = bdb->bi_txn_cp_task;
720 re->interval.tv_sec = bdb->bi_txn_cp_min * 60;
722 if ( c->be->be_suffix == NULL || BER_BVISNULL( &c->be->be_suffix[0] ) ) {
723 fprintf( stderr, "%s: "
724 "\"checkpoint\" must occur after \"suffix\".\n",
728 ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
729 bdb->bi_txn_cp_task = ldap_pvt_runqueue_insert( &slapd_rq,
730 bdb->bi_txn_cp_min * 60, bdb_checkpoint, bdb,
731 LDAP_XSTRING(bdb_checkpoint), c->be->be_suffix[0].bv_val );
732 ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
741 if ( c->op == SLAP_CONFIG_ADD ) {
742 ptr += STRLENOF("dbconfig");
743 while (!isspace((unsigned char)*ptr)) ptr++;
744 while (isspace((unsigned char)*ptr)) ptr++;
747 if ( bdb->bi_flags & BDB_IS_OPEN ) {
748 bdb->bi_flags |= BDB_UPD_CONFIG;
749 c->cleanup = bdb_cf_cleanup;
751 /* If we're just starting up...
754 /* If a DB_CONFIG file exists, or we don't know the path
755 * to the DB_CONFIG file, ignore these directives
757 if (( bdb->bi_flags & BDB_HAS_CONFIG ) || !bdb->bi_db_config_path )
759 f = fopen( bdb->bi_db_config_path, "a" );
761 /* FIXME: EBCDIC probably needs special handling */
762 fprintf( f, "%s\n", ptr );
766 ber_str2bv( ptr, 0, 1, &bv );
767 ber_bvarray_add( &bdb->bi_db_config, &bv );
772 rc = lutil_get_filed_password( c->value_string, &bdb->bi_db_crypt_key );
774 bdb->bi_db_crypt_file = c->value_string;
778 /* Cannot set key if file was already set */
780 if ( bdb->bi_db_crypt_file ) {
783 bdb->bi_db_crypt_key = c->value_bv;
787 case BDB_DIRECTORY: {
789 char *ptr, *testpath;
792 len = strlen( c->value_string );
793 testpath = ch_malloc( len + STRLENOF(LDAP_DIRSEP) + STRLENOF("DUMMY") + 1 );
794 ptr = lutil_strcopy( testpath, c->value_string );
795 *ptr++ = LDAP_DIRSEP[0];
796 strcpy( ptr, "DUMMY" );
797 f = fopen( testpath, "w" );
804 snprintf( c->cr_msg, sizeof( c->cr_msg ), "%s: invalid path: %s",
805 c->log, strerror( errno ));
806 Debug( LDAP_DEBUG_ANY, "%s\n", c->cr_msg, 0, 0 );
810 if ( bdb->bi_dbenv_home )
811 ch_free( bdb->bi_dbenv_home );
812 bdb->bi_dbenv_home = c->value_string;
814 /* See if a DB_CONFIG file already exists here */
815 if ( bdb->bi_db_config_path )
816 ch_free( bdb->bi_db_config_path );
817 bdb->bi_db_config_path = ch_malloc( len +
818 STRLENOF(LDAP_DIRSEP) + STRLENOF("DB_CONFIG") + 1 );
819 ptr = lutil_strcopy( bdb->bi_db_config_path, bdb->bi_dbenv_home );
820 *ptr++ = LDAP_DIRSEP[0];
821 strcpy( ptr, "DB_CONFIG" );
823 f = fopen( bdb->bi_db_config_path, "r" );
825 bdb->bi_flags |= BDB_HAS_CONFIG;
833 bdb->bi_dbenv_xflags |= DB_TXN_NOSYNC;
835 bdb->bi_dbenv_xflags &= ~DB_TXN_NOSYNC;
836 if ( bdb->bi_flags & BDB_IS_OPEN ) {
837 bdb->bi_dbenv->set_flags( bdb->bi_dbenv, DB_TXN_NOSYNC,
843 rc = bdb_attr_index_config( bdb, c->fname, c->lineno,
844 c->argc - 1, &c->argv[1], &c->reply);
846 if( rc != LDAP_SUCCESS ) return 1;
847 if (( bdb->bi_flags & BDB_IS_OPEN ) && !bdb->bi_index_task ) {
848 /* Start the task as soon as we finish here. Set a long
849 * interval (10 hours) so that it only gets scheduled once.
851 if ( c->be->be_suffix == NULL || BER_BVISNULL( &c->be->be_suffix[0] ) ) {
852 fprintf( stderr, "%s: "
853 "\"index\" must occur after \"suffix\".\n",
857 ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
858 bdb->bi_index_task = ldap_pvt_runqueue_insert( &slapd_rq, 36000,
859 bdb_online_index, c->be,
860 LDAP_XSTRING(bdb_online_index), c->be->be_suffix[0].bv_val );
861 ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
866 rc = verb_to_mask( c->argv[1], bdb_lockd );
867 if ( BER_BVISNULL(&bdb_lockd[rc].word) ) {
868 fprintf( stderr, "%s: "
869 "bad policy (%s) in \"lockDetect <policy>\" line\n",
870 c->log, c->argv[1] );
873 bdb->bi_lock_detect = rc;
877 if ( c->value_int < MINIMUM_SEARCH_STACK_DEPTH ) {
879 "%s: depth %d too small, using %d\n",
880 c->log, c->value_int, MINIMUM_SEARCH_STACK_DEPTH );
881 c->value_int = MINIMUM_SEARCH_STACK_DEPTH;
883 bdb->bi_search_stack_depth = c->value_int;
887 struct bdb_db_pgsize *ps, **prev;
890 s = atoi(c->argv[2]);
891 if ( s < 1 || s > 64 ) {
892 snprintf( c->cr_msg, sizeof( c->cr_msg ),
893 "%s: size must be > 0 and <= 64: %d",
895 Debug( LDAP_DEBUG_ANY, "%s\n", c->cr_msg, 0, 0 );
898 i = strlen(c->argv[1]);
899 ps = ch_malloc( sizeof(struct bdb_db_pgsize) + i + 1 );
901 ps->bdp_name.bv_len = i;
902 ps->bdp_name.bv_val = (char *)(ps+1);
903 strcpy( ps->bdp_name.bv_val, c->argv[1] );
904 ps->bdp_size = s * 1024;
905 for ( prev = &bdb->bi_pagesizes; *prev; prev = &(*prev)->bdp_next )
914 int bdb_back_init_cf( BackendInfo *bi )
917 bi->bi_cf_ocs = bdbocs;
919 rc = config_register_schema( bdbcfg, bdbocs );