1 /* config.c - bdb backend configuration file routine */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2000-2014 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;
58 static ConfigTable bdbcfg[] = {
59 { "directory", "dir", 2, 2, 0, ARG_STRING|ARG_MAGIC|BDB_DIRECTORY,
60 bdb_cf_gen, "( OLcfgDbAt:0.1 NAME 'olcDbDirectory' "
61 "DESC 'Directory for database content' "
62 "EQUALITY caseIgnoreMatch "
63 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
64 { "cachefree", "size", 2, 2, 0, ARG_ULONG|ARG_OFFSET,
65 (void *)offsetof(struct bdb_info, bi_cache.c_minfree),
66 "( OLcfgDbAt:1.11 NAME 'olcDbCacheFree' "
67 "DESC 'Number of extra entries to free when max is reached' "
68 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
69 { "cachesize", "size", 2, 2, 0, ARG_ULONG|ARG_OFFSET,
70 (void *)offsetof(struct bdb_info, bi_cache.c_maxsize),
71 "( OLcfgDbAt:1.1 NAME 'olcDbCacheSize' "
72 "DESC 'Entry cache size in entries' "
73 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
74 { "checkpoint", "kbyte> <min", 3, 3, 0, ARG_MAGIC|BDB_CHKPT,
75 bdb_cf_gen, "( OLcfgDbAt:1.2 NAME 'olcDbCheckpoint' "
76 "DESC 'Database checkpoint interval in kbytes and minutes' "
77 "SYNTAX OMsDirectoryString SINGLE-VALUE )",NULL, NULL },
78 { "checksum", NULL, 1, 2, 0, ARG_ON_OFF|ARG_MAGIC|BDB_CHECKSUM,
79 bdb_cf_gen, "( OLcfgDbAt:1.16 NAME 'olcDbChecksum' "
80 "DESC 'Enable database checksum validation' "
81 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
82 { "cryptfile", "file", 2, 2, 0, ARG_STRING|ARG_MAGIC|BDB_CRYPTFILE,
83 bdb_cf_gen, "( OLcfgDbAt:1.13 NAME 'olcDbCryptFile' "
84 "DESC 'Pathname of file containing the DB encryption key' "
85 "SYNTAX OMsDirectoryString SINGLE-VALUE )",NULL, NULL },
86 { "cryptkey", "key", 2, 2, 0, ARG_BERVAL|ARG_MAGIC|BDB_CRYPTKEY,
87 bdb_cf_gen, "( OLcfgDbAt:1.14 NAME 'olcDbCryptKey' "
88 "DESC 'DB encryption key' "
89 "SYNTAX OMsOctetString SINGLE-VALUE )",NULL, NULL },
90 { "dbconfig", "DB_CONFIG setting", 1, 0, 0, ARG_MAGIC|BDB_CONFIG,
91 bdb_cf_gen, "( OLcfgDbAt:1.3 NAME 'olcDbConfig' "
92 "DESC 'BerkeleyDB DB_CONFIG configuration directives' "
93 "SYNTAX OMsIA5String X-ORDERED 'VALUES' )", NULL, NULL },
94 { "dbnosync", NULL, 1, 2, 0, ARG_ON_OFF|ARG_MAGIC|BDB_NOSYNC,
95 bdb_cf_gen, "( OLcfgDbAt:1.4 NAME 'olcDbNoSync' "
96 "DESC 'Disable synchronous database writes' "
97 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
98 { "dbpagesize", "db> <size", 3, 3, 0, ARG_MAGIC|BDB_PGSIZE,
99 bdb_cf_gen, "( OLcfgDbAt:1.15 NAME 'olcDbPageSize' "
100 "DESC 'Page size of specified DB, in Kbytes' "
101 "EQUALITY caseExactMatch "
102 "SYNTAX OMsDirectoryString )", NULL, NULL },
103 { "dirtyread", NULL, 1, 2, 0,
104 #ifdef SLAP_BDB_ALLOW_DIRTY_READ
105 ARG_ON_OFF|ARG_MAGIC|BDB_DIRTYR, bdb_cf_gen,
109 "( OLcfgDbAt:1.5 NAME 'olcDbDirtyRead' "
110 "DESC 'Allow reads of uncommitted data' "
111 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
112 { "dncachesize", "size", 2, 2, 0, ARG_ULONG|ARG_OFFSET,
113 (void *)offsetof(struct bdb_info, bi_cache.c_eimax),
114 "( OLcfgDbAt:1.12 NAME 'olcDbDNcacheSize' "
115 "DESC 'DN cache size' "
116 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
117 { "idlcachesize", "size", 2, 2, 0, ARG_ULONG|ARG_OFFSET,
118 (void *)offsetof(struct bdb_info, bi_idl_cache_max_size),
119 "( OLcfgDbAt:1.6 NAME 'olcDbIDLcacheSize' "
120 "DESC 'IDL cache size in IDLs' "
121 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
122 { "index", "attr> <[pres,eq,approx,sub]", 2, 3, 0, ARG_MAGIC|BDB_INDEX,
123 bdb_cf_gen, "( OLcfgDbAt:0.2 NAME 'olcDbIndex' "
124 "DESC 'Attribute index parameters' "
125 "EQUALITY caseIgnoreMatch "
126 "SYNTAX OMsDirectoryString )", NULL, NULL },
127 { "linearindex", NULL, 1, 2, 0, ARG_ON_OFF|ARG_OFFSET,
128 (void *)offsetof(struct bdb_info, bi_linear_index),
129 "( OLcfgDbAt:1.7 NAME 'olcDbLinearIndex' "
130 "DESC 'Index attributes one at a time' "
131 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
132 { "lockdetect", "policy", 2, 2, 0, ARG_MAGIC|BDB_LOCKD,
133 bdb_cf_gen, "( OLcfgDbAt:1.8 NAME 'olcDbLockDetect' "
134 "DESC 'Deadlock detection algorithm' "
135 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
136 { "mode", "mode", 2, 2, 0, ARG_MAGIC|BDB_MODE,
137 bdb_cf_gen, "( OLcfgDbAt:0.3 NAME 'olcDbMode' "
138 "DESC 'Unix permissions of database files' "
139 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
140 { "searchstack", "depth", 2, 2, 0, ARG_INT|ARG_MAGIC|BDB_SSTACK,
141 bdb_cf_gen, "( OLcfgDbAt:1.9 NAME 'olcDbSearchStack' "
142 "DESC 'Depth of search stack in IDLs' "
143 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
144 { "shm_key", "key", 2, 2, 0, ARG_LONG|ARG_OFFSET,
145 (void *)offsetof(struct bdb_info, bi_shm_key),
146 "( OLcfgDbAt:1.10 NAME 'olcDbShmKey' "
147 "DESC 'Key for shared memory region' "
148 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
149 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
150 NULL, NULL, NULL, NULL }
153 static ConfigOCs bdbocs[] = {
157 "NAME 'olcHdbConfig' "
158 "DESC 'HDB backend configuration' "
161 "NAME 'olcBdbConfig' "
162 "DESC 'BDB backend configuration' "
164 "SUP olcDatabaseConfig "
165 "MUST olcDbDirectory "
166 "MAY ( olcDbCacheSize $ olcDbCheckpoint $ olcDbConfig $ "
167 "olcDbCryptFile $ olcDbCryptKey $ "
168 "olcDbNoSync $ olcDbDirtyRead $ olcDbIDLcacheSize $ "
169 "olcDbIndex $ olcDbLinearIndex $ olcDbLockDetect $ "
170 "olcDbMode $ olcDbSearchStack $ olcDbShmKey $ "
171 "olcDbCacheFree $ olcDbDNcacheSize $ olcDbPageSize ) )",
172 Cft_Database, bdbcfg },
176 static slap_verbmasks bdb_lockd[] = {
177 { BER_BVC("default"), DB_LOCK_DEFAULT },
178 { BER_BVC("oldest"), DB_LOCK_OLDEST },
179 { BER_BVC("random"), DB_LOCK_RANDOM },
180 { BER_BVC("youngest"), DB_LOCK_YOUNGEST },
181 { BER_BVC("fewest"), DB_LOCK_MINLOCKS },
185 /* perform periodic checkpoints */
187 bdb_checkpoint( void *ctx, void *arg )
189 struct re_s *rtask = arg;
190 struct bdb_info *bdb = rtask->arg;
192 TXN_CHECKPOINT( bdb->bi_dbenv, bdb->bi_txn_cp_kbyte,
193 bdb->bi_txn_cp_min, 0 );
194 ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
195 ldap_pvt_runqueue_stoptask( &slapd_rq, rtask );
196 ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
200 /* reindex entries on the fly */
202 bdb_online_index( void *ctx, void *arg )
204 struct re_s *rtask = arg;
205 BackendDB *be = rtask->arg;
206 struct bdb_info *bdb = be->be_private;
208 Connection conn = {0};
209 OperationBuffer opbuf;
221 connection_fake_init( &conn, &opbuf, ctx );
231 key.size = key.ulen = sizeof(ID);
232 key.flags = DB_DBT_USERMEM;
234 data.flags = DB_DBT_USERMEM | DB_DBT_PARTIAL;
235 data.dlen = data.ulen = 0;
238 if ( slapd_shutdown )
241 rc = TXN_BEGIN( bdb->bi_dbenv, NULL, &txn, bdb->bi_db_opflags );
244 Debug( LDAP_DEBUG_TRACE, LDAP_XSTRING(bdb_online_index) ": txn id: %x\n",
245 txn->id(txn), 0, 0 );
248 BDB_ID2DISK( id, &nid );
249 rc = bdb->bi_id2entry->bdi_db->cursor(
250 bdb->bi_id2entry->bdi_db, txn, &curs, bdb->bi_db_opflags );
255 rc = curs->c_get( curs, &key, &data, DB_SET_RANGE );
256 curs->c_close( curs );
259 if ( rc == DB_NOTFOUND )
261 if ( rc == DB_LOCK_DEADLOCK ) {
262 ldap_pvt_thread_yield();
267 BDB_DISK2ID( &nid, &id );
271 rc = bdb_cache_find_id( op, txn, id, &ei, 0, &lock );
274 if ( rc == DB_LOCK_DEADLOCK ) {
275 ldap_pvt_thread_yield();
278 if ( rc == DB_NOTFOUND ) {
286 rc = bdb_index_entry( op, txn, BDB_INDEX_UPDATE_OP, ei->bei_e );
289 if ( rc == DB_LOCK_DEADLOCK ) {
290 ldap_pvt_thread_yield();
295 rc = TXN_COMMIT( txn, 0 );
302 for ( i = 0; i < bdb->bi_nattrs; i++ ) {
303 if ( bdb->bi_attrs[ i ]->ai_indexmask & BDB_INDEX_DELETING
304 || bdb->bi_attrs[ i ]->ai_newmask == 0 )
308 bdb->bi_attrs[ i ]->ai_indexmask = bdb->bi_attrs[ i ]->ai_newmask;
309 bdb->bi_attrs[ i ]->ai_newmask = 0;
312 ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
313 ldap_pvt_runqueue_stoptask( &slapd_rq, rtask );
314 bdb->bi_index_task = NULL;
315 ldap_pvt_runqueue_remove( &slapd_rq, rtask );
316 ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
321 /* Cleanup loose ends after Modify completes */
323 bdb_cf_cleanup( ConfigArgs *c )
325 struct bdb_info *bdb = c->be->be_private;
329 if ( bdb->bi_flags & BDB_DEL_INDEX ) {
330 bdb_attr_flush( bdb );
331 bdb->bi_flags ^= BDB_DEL_INDEX;
334 if ( bdb->bi_flags & BDB_RE_OPEN ) {
335 bdb->bi_flags ^= BDB_RE_OPEN;
336 bva = bdb->bi_db_config;
337 bdb->bi_db_config = NULL;
338 rc = c->be->bd_info->bi_db_close( c->be, &c->reply );
340 if ( bdb->bi_flags & BDB_UPD_CONFIG ) {
343 FILE *f = fopen( bdb->bi_db_config_path, "w" );
345 bdb->bi_db_config = bva;
347 for (i=0; bdb->bi_db_config[i].bv_val; i++)
348 fprintf( f, "%s\n", bdb->bi_db_config[i].bv_val );
351 ber_bvarray_free( bva );
354 unlink( bdb->bi_db_config_path );
356 bdb->bi_flags ^= BDB_UPD_CONFIG;
358 rc = c->be->bd_info->bi_db_open( c->be, &c->reply );
360 /* If this fails, we need to restart */
363 snprintf( c->cr_msg, sizeof( c->cr_msg ),
364 "failed to reopen database, rc=%d", rc );
365 Debug( LDAP_DEBUG_ANY, LDAP_XSTRING(bdb_cf_cleanup)
366 ": %s\n", c->cr_msg, 0, 0 );
374 bdb_cf_gen( ConfigArgs *c )
376 struct bdb_info *bdb = c->be->be_private;
379 if ( c->op == SLAP_CONFIG_EMIT ) {
385 bv.bv_len = snprintf( buf, sizeof(buf), "0%o", bdb->bi_dbenv_mode );
386 if ( bv.bv_len > 0 && bv.bv_len < sizeof(buf) ) {
388 value_add_one( &c->rvalue_vals, &bv );
395 if ( bdb->bi_txn_cp ) {
398 bv.bv_len = snprintf( buf, sizeof(buf), "%ld %ld",
399 (long) bdb->bi_txn_cp_kbyte, (long) bdb->bi_txn_cp_min );
400 if ( bv.bv_len > 0 && bv.bv_len < sizeof(buf) ) {
402 value_add_one( &c->rvalue_vals, &bv );
412 if ( bdb->bi_db_crypt_file ) {
413 c->value_string = ch_strdup( bdb->bi_db_crypt_file );
419 /* If a crypt file has been set, its contents are copied here.
420 * But we don't want the key to be incorporated here.
423 if ( !bdb->bi_db_crypt_file && !BER_BVISNULL( &bdb->bi_db_crypt_key )) {
424 value_add_one( &c->rvalue_vals, &bdb->bi_db_crypt_key );
431 if ( bdb->bi_dbenv_home ) {
432 c->value_string = ch_strdup( bdb->bi_dbenv_home );
439 if ( !( bdb->bi_flags & BDB_IS_OPEN )
440 && !bdb->bi_db_config )
442 char buf[SLAP_TEXT_BUFLEN];
443 FILE *f = fopen( bdb->bi_db_config_path, "r" );
447 bdb->bi_flags |= BDB_HAS_CONFIG;
448 while ( fgets( buf, sizeof(buf), f )) {
449 ber_str2bv( buf, 0, 1, &bv );
450 if ( bv.bv_len > 0 && bv.bv_val[bv.bv_len-1] == '\n' ) {
452 bv.bv_val[bv.bv_len] = '\0';
454 /* shouldn't need this, but ... */
455 if ( bv.bv_len > 0 && bv.bv_val[bv.bv_len-1] == '\r' ) {
457 bv.bv_val[bv.bv_len] = '\0';
459 ber_bvarray_add( &bdb->bi_db_config, &bv );
464 if ( bdb->bi_db_config ) {
469 for (i=0; !BER_BVISNULL(&bdb->bi_db_config[i]); i++) {
470 bv.bv_len = sprintf( bv.bv_val, "{%d}%s", i,
471 bdb->bi_db_config[i].bv_val );
472 value_add_one( &c->rvalue_vals, &bv );
475 if ( !c->rvalue_vals ) rc = 1;
479 if ( bdb->bi_dbenv_xflags & DB_TXN_NOSYNC )
484 if ( bdb->bi_flags & BDB_CHKSUM )
489 bdb_attr_index_unparse( bdb, &c->rvalue_vals );
490 if ( !c->rvalue_vals ) rc = 1;
495 if ( bdb->bi_lock_detect != DB_LOCK_DEFAULT ) {
497 for (i=0; !BER_BVISNULL(&bdb_lockd[i].word); i++) {
498 if ( bdb->bi_lock_detect == (u_int32_t)bdb_lockd[i].mask ) {
499 value_add_one( &c->rvalue_vals, &bdb_lockd[i].word );
508 c->value_int = bdb->bi_search_stack_depth;
512 struct bdb_db_pgsize *ps;
513 char buf[SLAP_TEXT_BUFLEN];
518 for ( ps = bdb->bi_pagesizes; ps; ps = ps->bdp_next ) {
519 bv.bv_len = sprintf( buf, "%s %d", ps->bdp_name.bv_val,
520 ps->bdp_size / 1024 );
521 value_add_one( &c->rvalue_vals, &bv );
529 } else if ( c->op == LDAP_MOD_DELETE ) {
534 /* FIXME: does it make any sense to change the mode,
535 * if we don't exec a chmod()? */
536 bdb->bi_dbenv_mode = SLAPD_DEFAULT_DB_MODE;
540 /* single-valued no-ops */
546 if ( bdb->bi_txn_cp_task ) {
547 struct re_s *re = bdb->bi_txn_cp_task;
548 bdb->bi_txn_cp_task = NULL;
549 ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
550 if ( ldap_pvt_runqueue_isrunning( &slapd_rq, re ) )
551 ldap_pvt_runqueue_stoptask( &slapd_rq, re );
552 ldap_pvt_runqueue_remove( &slapd_rq, re );
553 ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
559 ber_bvarray_free( bdb->bi_db_config );
560 bdb->bi_db_config = NULL;
563 ch_free( bdb->bi_db_config[i].bv_val );
564 for (; bdb->bi_db_config[i].bv_val; i++)
565 bdb->bi_db_config[i] = bdb->bi_db_config[i+1];
567 bdb->bi_flags |= BDB_UPD_CONFIG|BDB_RE_OPEN;
568 c->cleanup = bdb_cf_cleanup;
570 /* Doesn't really make sense to change these on the fly;
571 * the entire DB must be dumped and reloaded
574 if ( bdb->bi_db_crypt_file ) {
575 ch_free( bdb->bi_db_crypt_file );
576 bdb->bi_db_crypt_file = NULL;
580 if ( !BER_BVISNULL( &bdb->bi_db_crypt_key )) {
581 ch_free( bdb->bi_db_crypt_key.bv_val );
582 BER_BVZERO( &bdb->bi_db_crypt_key );
586 bdb->bi_flags |= BDB_RE_OPEN;
587 bdb->bi_flags ^= BDB_HAS_CONFIG;
588 ch_free( bdb->bi_dbenv_home );
589 bdb->bi_dbenv_home = NULL;
590 ch_free( bdb->bi_db_config_path );
591 bdb->bi_db_config_path = NULL;
592 c->cleanup = bdb_cf_cleanup;
593 ldap_pvt_thread_pool_purgekey( bdb->bi_dbenv );
596 bdb->bi_dbenv->set_flags( bdb->bi_dbenv, DB_TXN_NOSYNC, 0 );
599 bdb->bi_flags &= ~BDB_CHKSUM;
602 if ( c->valx == -1 ) {
605 /* delete all (FIXME) */
606 for ( i = 0; i < bdb->bi_nattrs; i++ ) {
607 bdb->bi_attrs[i]->ai_indexmask |= BDB_INDEX_DELETING;
609 bdb->bi_flags |= BDB_DEL_INDEX;
610 c->cleanup = bdb_cf_cleanup;
613 struct berval bv, def = BER_BVC("default");
616 for (ptr = c->line; !isspace( (unsigned char) *ptr ); ptr++);
619 bv.bv_len = ptr - bv.bv_val;
620 if ( bvmatch( &bv, &def )) {
621 bdb->bi_defaultmask = 0;
628 sep = bv.bv_val[ bv.bv_len ];
629 bv.bv_val[ bv.bv_len ] = '\0';
630 attrs = ldap_str2charray( bv.bv_val, "," );
632 for ( i = 0; attrs[ i ]; i++ ) {
633 AttributeDescription *ad = NULL;
637 slap_str2ad( attrs[ i ], &ad, &text );
638 /* if we got here... */
639 assert( ad != NULL );
641 ai = bdb_attr_mask( bdb, ad );
642 /* if we got here... */
643 assert( ai != NULL );
645 ai->ai_indexmask |= BDB_INDEX_DELETING;
646 bdb->bi_flags |= BDB_DEL_INDEX;
647 c->cleanup = bdb_cf_cleanup;
650 bv.bv_val[ bv.bv_len ] = sep;
651 ldap_charray_free( attrs );
655 /* doesn't make sense on the fly; the DB file must be
659 struct bdb_db_pgsize *ps, **prev;
662 for ( i = 0, prev = &bdb->bi_pagesizes, ps = *prev; ps;
663 prev = &ps->bdp_next, ps = ps->bdp_next, i++ ) {
664 if ( c->valx == -1 || i == c->valx ) {
665 *prev = ps->bdp_next;
668 if ( i == c->valx ) break;
679 if ( ASCII_DIGIT( c->argv[1][0] ) ) {
683 mode = strtol( c->argv[1], &next, 0 );
684 if ( errno != 0 || next == c->argv[1] || next[0] != '\0' ) {
685 fprintf( stderr, "%s: "
686 "unable to parse mode=\"%s\".\n",
687 c->log, c->argv[1] );
690 bdb->bi_dbenv_mode = mode;
693 char *m = c->argv[1];
694 int who, what, mode = 0;
696 if ( strlen( m ) != STRLENOF("-rwxrwxrwx") ) {
705 for ( who = 0; who < 3; who++ ) {
706 for ( what = 0; what < 3; what++, m++ ) {
709 } else if ( m[0] != "rwx"[what] ) {
712 mode += ((1 << (2 - what)) << 3*(2 - who));
715 bdb->bi_dbenv_mode = mode;
721 if ( lutil_atolx( &l, c->argv[1], 0 ) != 0 ) {
722 fprintf( stderr, "%s: "
723 "invalid kbyte \"%s\" in \"checkpoint\".\n",
724 c->log, c->argv[1] );
727 bdb->bi_txn_cp_kbyte = l;
728 if ( lutil_atolx( &l, c->argv[2], 0 ) != 0 ) {
729 fprintf( stderr, "%s: "
730 "invalid minutes \"%s\" in \"checkpoint\".\n",
731 c->log, c->argv[2] );
734 bdb->bi_txn_cp_min = l;
735 /* If we're in server mode and time-based checkpointing is enabled,
736 * submit a task to perform periodic checkpoints.
738 if ((slapMode & SLAP_SERVER_MODE) && bdb->bi_txn_cp_min ) {
739 struct re_s *re = bdb->bi_txn_cp_task;
741 re->interval.tv_sec = bdb->bi_txn_cp_min * 60;
743 if ( c->be->be_suffix == NULL || BER_BVISNULL( &c->be->be_suffix[0] ) ) {
744 fprintf( stderr, "%s: "
745 "\"checkpoint\" must occur after \"suffix\".\n",
749 ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
750 bdb->bi_txn_cp_task = ldap_pvt_runqueue_insert( &slapd_rq,
751 bdb->bi_txn_cp_min * 60, bdb_checkpoint, bdb,
752 LDAP_XSTRING(bdb_checkpoint), c->be->be_suffix[0].bv_val );
753 ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
762 if ( c->op == SLAP_CONFIG_ADD ) {
763 ptr += STRLENOF("dbconfig");
764 while (!isspace((unsigned char)*ptr)) ptr++;
765 while (isspace((unsigned char)*ptr)) ptr++;
768 if ( bdb->bi_flags & BDB_IS_OPEN ) {
769 bdb->bi_flags |= BDB_UPD_CONFIG|BDB_RE_OPEN;
770 c->cleanup = bdb_cf_cleanup;
772 /* If we're just starting up...
775 /* If a DB_CONFIG file exists, or we don't know the path
776 * to the DB_CONFIG file, ignore these directives
778 if (( bdb->bi_flags & BDB_HAS_CONFIG ) || !bdb->bi_db_config_path )
780 f = fopen( bdb->bi_db_config_path, "a" );
782 /* FIXME: EBCDIC probably needs special handling */
783 fprintf( f, "%s\n", ptr );
787 ber_str2bv( ptr, 0, 1, &bv );
788 ber_bvarray_add( &bdb->bi_db_config, &bv );
793 rc = lutil_get_filed_password( c->value_string, &bdb->bi_db_crypt_key );
795 bdb->bi_db_crypt_file = c->value_string;
799 /* Cannot set key if file was already set */
801 if ( bdb->bi_db_crypt_file ) {
804 bdb->bi_db_crypt_key = c->value_bv;
808 case BDB_DIRECTORY: {
810 char *ptr, *testpath;
813 len = strlen( c->value_string );
814 testpath = ch_malloc( len + STRLENOF(LDAP_DIRSEP) + STRLENOF("DUMMY") + 1 );
815 ptr = lutil_strcopy( testpath, c->value_string );
816 *ptr++ = LDAP_DIRSEP[0];
817 strcpy( ptr, "DUMMY" );
818 f = fopen( testpath, "w" );
825 snprintf( c->cr_msg, sizeof( c->cr_msg ), "%s: invalid path: %s",
826 c->log, strerror( errno ));
827 Debug( LDAP_DEBUG_ANY, "%s\n", c->cr_msg, 0, 0 );
831 if ( bdb->bi_dbenv_home )
832 ch_free( bdb->bi_dbenv_home );
833 bdb->bi_dbenv_home = c->value_string;
835 /* See if a DB_CONFIG file already exists here */
836 if ( bdb->bi_db_config_path )
837 ch_free( bdb->bi_db_config_path );
838 bdb->bi_db_config_path = ch_malloc( len +
839 STRLENOF(LDAP_DIRSEP) + STRLENOF("DB_CONFIG") + 1 );
840 ptr = lutil_strcopy( bdb->bi_db_config_path, bdb->bi_dbenv_home );
841 *ptr++ = LDAP_DIRSEP[0];
842 strcpy( ptr, "DB_CONFIG" );
844 f = fopen( bdb->bi_db_config_path, "r" );
846 bdb->bi_flags |= BDB_HAS_CONFIG;
854 bdb->bi_dbenv_xflags |= DB_TXN_NOSYNC;
856 bdb->bi_dbenv_xflags &= ~DB_TXN_NOSYNC;
857 if ( bdb->bi_flags & BDB_IS_OPEN ) {
858 bdb->bi_dbenv->set_flags( bdb->bi_dbenv, DB_TXN_NOSYNC,
865 bdb->bi_flags |= BDB_CHKSUM;
867 bdb->bi_flags &= ~BDB_CHKSUM;
871 rc = bdb_attr_index_config( bdb, c->fname, c->lineno,
872 c->argc - 1, &c->argv[1], &c->reply);
874 if( rc != LDAP_SUCCESS ) return 1;
875 if (( bdb->bi_flags & BDB_IS_OPEN ) && !bdb->bi_index_task ) {
876 /* Start the task as soon as we finish here. Set a long
877 * interval (10 hours) so that it only gets scheduled once.
879 if ( c->be->be_suffix == NULL || BER_BVISNULL( &c->be->be_suffix[0] ) ) {
880 fprintf( stderr, "%s: "
881 "\"index\" must occur after \"suffix\".\n",
885 ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
886 bdb->bi_index_task = ldap_pvt_runqueue_insert( &slapd_rq, 36000,
887 bdb_online_index, c->be,
888 LDAP_XSTRING(bdb_online_index), c->be->be_suffix[0].bv_val );
889 ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
894 rc = verb_to_mask( c->argv[1], bdb_lockd );
895 if ( BER_BVISNULL(&bdb_lockd[rc].word) ) {
896 fprintf( stderr, "%s: "
897 "bad policy (%s) in \"lockDetect <policy>\" line\n",
898 c->log, c->argv[1] );
901 bdb->bi_lock_detect = (u_int32_t)rc;
905 if ( c->value_int < MINIMUM_SEARCH_STACK_DEPTH ) {
907 "%s: depth %d too small, using %d\n",
908 c->log, c->value_int, MINIMUM_SEARCH_STACK_DEPTH );
909 c->value_int = MINIMUM_SEARCH_STACK_DEPTH;
911 bdb->bi_search_stack_depth = c->value_int;
915 struct bdb_db_pgsize *ps, **prev;
918 s = atoi(c->argv[2]);
919 if ( s < 1 || s > 64 ) {
920 snprintf( c->cr_msg, sizeof( c->cr_msg ),
921 "%s: size must be > 0 and <= 64: %d",
923 Debug( LDAP_DEBUG_ANY, "%s\n", c->cr_msg, 0, 0 );
926 i = strlen(c->argv[1]);
927 ps = ch_malloc( sizeof(struct bdb_db_pgsize) + i + 1 );
929 ps->bdp_name.bv_len = i;
930 ps->bdp_name.bv_val = (char *)(ps+1);
931 strcpy( ps->bdp_name.bv_val, c->argv[1] );
932 ps->bdp_size = s * 1024;
933 for ( prev = &bdb->bi_pagesizes; *prev; prev = &(*prev)->bdp_next )
942 int bdb_back_init_cf( BackendInfo *bi )
945 bi->bi_cf_ocs = bdbocs;
947 rc = config_register_schema( bdbcfg, bdbocs );