1 /* config.c - bdb backend configuration file routine */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2000-2012 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: %u\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 );
287 if ( rc == DB_LOCK_DEADLOCK ) {
289 ldap_pvt_thread_yield();
293 rc = TXN_COMMIT( txn, 0 );
303 for ( i = 0; i < bdb->bi_nattrs; i++ ) {
304 if ( bdb->bi_attrs[ i ]->ai_indexmask & BDB_INDEX_DELETING
305 || bdb->bi_attrs[ i ]->ai_newmask == 0 )
309 bdb->bi_attrs[ i ]->ai_indexmask = bdb->bi_attrs[ i ]->ai_newmask;
310 bdb->bi_attrs[ i ]->ai_newmask = 0;
313 ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
314 ldap_pvt_runqueue_stoptask( &slapd_rq, rtask );
315 bdb->bi_index_task = NULL;
316 ldap_pvt_runqueue_remove( &slapd_rq, rtask );
317 ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
322 /* Cleanup loose ends after Modify completes */
324 bdb_cf_cleanup( ConfigArgs *c )
326 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 rc = c->be->bd_info->bi_db_close( c->be, &c->reply );
338 if ( bdb->bi_flags & BDB_UPD_CONFIG ) {
339 if ( bdb->bi_db_config ) {
341 FILE *f = fopen( bdb->bi_db_config_path, "w" );
343 for (i=0; bdb->bi_db_config[i].bv_val; i++)
344 fprintf( f, "%s\n", bdb->bi_db_config[i].bv_val );
348 unlink( bdb->bi_db_config_path );
350 bdb->bi_flags ^= BDB_UPD_CONFIG;
352 rc = c->be->bd_info->bi_db_open( c->be, &c->reply );
354 /* If this fails, we need to restart */
357 snprintf( c->cr_msg, sizeof( c->cr_msg ),
358 "failed to reopen database, rc=%d", rc );
359 Debug( LDAP_DEBUG_ANY, LDAP_XSTRING(bdb_cf_cleanup)
360 ": %s\n", c->cr_msg, 0, 0 );
368 bdb_cf_gen( ConfigArgs *c )
370 struct bdb_info *bdb = c->be->be_private;
373 if ( c->op == SLAP_CONFIG_EMIT ) {
379 bv.bv_len = snprintf( buf, sizeof(buf), "0%o", bdb->bi_dbenv_mode );
380 if ( bv.bv_len > 0 && bv.bv_len < sizeof(buf) ) {
382 value_add_one( &c->rvalue_vals, &bv );
389 if ( bdb->bi_txn_cp ) {
392 bv.bv_len = snprintf( buf, sizeof(buf), "%ld %ld",
393 (long) bdb->bi_txn_cp_kbyte, (long) bdb->bi_txn_cp_min );
394 if ( bv.bv_len > 0 && bv.bv_len < sizeof(buf) ) {
396 value_add_one( &c->rvalue_vals, &bv );
406 if ( bdb->bi_db_crypt_file ) {
407 c->value_string = ch_strdup( bdb->bi_db_crypt_file );
413 /* If a crypt file has been set, its contents are copied here.
414 * But we don't want the key to be incorporated here.
417 if ( !bdb->bi_db_crypt_file && !BER_BVISNULL( &bdb->bi_db_crypt_key )) {
418 value_add_one( &c->rvalue_vals, &bdb->bi_db_crypt_key );
425 if ( bdb->bi_dbenv_home ) {
426 c->value_string = ch_strdup( bdb->bi_dbenv_home );
433 if ( !( bdb->bi_flags & BDB_IS_OPEN )
434 && !bdb->bi_db_config )
436 char buf[SLAP_TEXT_BUFLEN];
437 FILE *f = fopen( bdb->bi_db_config_path, "r" );
441 bdb->bi_flags |= BDB_HAS_CONFIG;
442 while ( fgets( buf, sizeof(buf), f )) {
443 ber_str2bv( buf, 0, 1, &bv );
444 if ( bv.bv_len > 0 && bv.bv_val[bv.bv_len-1] == '\n' ) {
446 bv.bv_val[bv.bv_len] = '\0';
448 /* shouldn't need this, but ... */
449 if ( bv.bv_len > 0 && bv.bv_val[bv.bv_len-1] == '\r' ) {
451 bv.bv_val[bv.bv_len] = '\0';
453 ber_bvarray_add( &bdb->bi_db_config, &bv );
458 if ( bdb->bi_db_config ) {
463 for (i=0; !BER_BVISNULL(&bdb->bi_db_config[i]); i++) {
464 bv.bv_len = sprintf( bv.bv_val, "{%d}%s", i,
465 bdb->bi_db_config[i].bv_val );
466 value_add_one( &c->rvalue_vals, &bv );
469 if ( !c->rvalue_vals ) rc = 1;
473 if ( bdb->bi_dbenv_xflags & DB_TXN_NOSYNC )
478 if ( bdb->bi_flags & BDB_CHKSUM )
483 bdb_attr_index_unparse( bdb, &c->rvalue_vals );
484 if ( !c->rvalue_vals ) rc = 1;
489 if ( bdb->bi_lock_detect != DB_LOCK_DEFAULT ) {
491 for (i=0; !BER_BVISNULL(&bdb_lockd[i].word); i++) {
492 if ( bdb->bi_lock_detect == (u_int32_t)bdb_lockd[i].mask ) {
493 value_add_one( &c->rvalue_vals, &bdb_lockd[i].word );
502 c->value_int = bdb->bi_search_stack_depth;
506 struct bdb_db_pgsize *ps;
507 char buf[SLAP_TEXT_BUFLEN];
512 for ( ps = bdb->bi_pagesizes; ps; ps = ps->bdp_next ) {
513 bv.bv_len = sprintf( buf, "%s %d", ps->bdp_name.bv_val,
514 ps->bdp_size / 1024 );
515 value_add_one( &c->rvalue_vals, &bv );
523 } else if ( c->op == LDAP_MOD_DELETE ) {
528 /* FIXME: does it make any sense to change the mode,
529 * if we don't exec a chmod()? */
530 bdb->bi_dbenv_mode = SLAPD_DEFAULT_DB_MODE;
534 /* single-valued no-ops */
540 if ( bdb->bi_txn_cp_task ) {
541 struct re_s *re = bdb->bi_txn_cp_task;
542 bdb->bi_txn_cp_task = NULL;
543 ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
544 if ( ldap_pvt_runqueue_isrunning( &slapd_rq, re ) )
545 ldap_pvt_runqueue_stoptask( &slapd_rq, re );
546 ldap_pvt_runqueue_remove( &slapd_rq, re );
547 ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
553 ber_bvarray_free( bdb->bi_db_config );
554 bdb->bi_db_config = NULL;
557 ch_free( bdb->bi_db_config[i].bv_val );
558 for (; bdb->bi_db_config[i].bv_val; i++)
559 bdb->bi_db_config[i] = bdb->bi_db_config[i+1];
561 bdb->bi_flags |= BDB_UPD_CONFIG|BDB_RE_OPEN;
562 c->cleanup = bdb_cf_cleanup;
564 /* Doesn't really make sense to change these on the fly;
565 * the entire DB must be dumped and reloaded
568 if ( bdb->bi_db_crypt_file ) {
569 ch_free( bdb->bi_db_crypt_file );
570 bdb->bi_db_crypt_file = NULL;
574 if ( !BER_BVISNULL( &bdb->bi_db_crypt_key )) {
575 ch_free( bdb->bi_db_crypt_key.bv_val );
576 BER_BVZERO( &bdb->bi_db_crypt_key );
580 bdb->bi_flags |= BDB_RE_OPEN;
581 bdb->bi_flags ^= BDB_HAS_CONFIG;
582 ch_free( bdb->bi_dbenv_home );
583 bdb->bi_dbenv_home = NULL;
584 ch_free( bdb->bi_db_config_path );
585 bdb->bi_db_config_path = NULL;
586 c->cleanup = bdb_cf_cleanup;
587 ldap_pvt_thread_pool_purgekey( bdb->bi_dbenv );
590 bdb->bi_dbenv->set_flags( bdb->bi_dbenv, DB_TXN_NOSYNC, 0 );
593 bdb->bi_flags &= ~BDB_CHKSUM;
596 if ( c->valx == -1 ) {
599 /* delete all (FIXME) */
600 for ( i = 0; i < bdb->bi_nattrs; i++ ) {
601 bdb->bi_attrs[i]->ai_indexmask |= BDB_INDEX_DELETING;
603 bdb->bi_flags |= BDB_DEL_INDEX;
604 c->cleanup = bdb_cf_cleanup;
607 struct berval bv, def = BER_BVC("default");
610 for (ptr = c->line; !isspace( (unsigned char) *ptr ); ptr++);
613 bv.bv_len = ptr - bv.bv_val;
614 if ( bvmatch( &bv, &def )) {
615 bdb->bi_defaultmask = 0;
622 sep = bv.bv_val[ bv.bv_len ];
623 bv.bv_val[ bv.bv_len ] = '\0';
624 attrs = ldap_str2charray( bv.bv_val, "," );
626 for ( i = 0; attrs[ i ]; i++ ) {
627 AttributeDescription *ad = NULL;
631 slap_str2ad( attrs[ i ], &ad, &text );
632 /* if we got here... */
633 assert( ad != NULL );
635 ai = bdb_attr_mask( bdb, ad );
636 /* if we got here... */
637 assert( ai != NULL );
639 ai->ai_indexmask |= BDB_INDEX_DELETING;
640 bdb->bi_flags |= BDB_DEL_INDEX;
641 c->cleanup = bdb_cf_cleanup;
644 bv.bv_val[ bv.bv_len ] = sep;
645 ldap_charray_free( attrs );
649 /* doesn't make sense on the fly; the DB file must be
653 struct bdb_db_pgsize *ps, **prev;
656 for ( i = 0, prev = &bdb->bi_pagesizes, ps = *prev; ps;
657 prev = &ps->bdp_next, ps = ps->bdp_next, i++ ) {
658 if ( c->valx == -1 || i == c->valx ) {
659 *prev = ps->bdp_next;
662 if ( i == c->valx ) break;
673 if ( ASCII_DIGIT( c->argv[1][0] ) ) {
677 mode = strtol( c->argv[1], &next, 0 );
678 if ( errno != 0 || next == c->argv[1] || next[0] != '\0' ) {
679 fprintf( stderr, "%s: "
680 "unable to parse mode=\"%s\".\n",
681 c->log, c->argv[1] );
684 bdb->bi_dbenv_mode = mode;
687 char *m = c->argv[1];
688 int who, what, mode = 0;
690 if ( strlen( m ) != STRLENOF("-rwxrwxrwx") ) {
699 for ( who = 0; who < 3; who++ ) {
700 for ( what = 0; what < 3; what++, m++ ) {
703 } else if ( m[0] != "rwx"[what] ) {
706 mode += ((1 << (2 - what)) << 3*(2 - who));
709 bdb->bi_dbenv_mode = mode;
715 if ( lutil_atolx( &l, c->argv[1], 0 ) != 0 ) {
716 fprintf( stderr, "%s: "
717 "invalid kbyte \"%s\" in \"checkpoint\".\n",
718 c->log, c->argv[1] );
721 bdb->bi_txn_cp_kbyte = l;
722 if ( lutil_atolx( &l, c->argv[2], 0 ) != 0 ) {
723 fprintf( stderr, "%s: "
724 "invalid minutes \"%s\" in \"checkpoint\".\n",
725 c->log, c->argv[2] );
728 bdb->bi_txn_cp_min = l;
729 /* If we're in server mode and time-based checkpointing is enabled,
730 * submit a task to perform periodic checkpoints.
732 if ((slapMode & SLAP_SERVER_MODE) && bdb->bi_txn_cp_min ) {
733 struct re_s *re = bdb->bi_txn_cp_task;
735 re->interval.tv_sec = bdb->bi_txn_cp_min * 60;
737 if ( c->be->be_suffix == NULL || BER_BVISNULL( &c->be->be_suffix[0] ) ) {
738 fprintf( stderr, "%s: "
739 "\"checkpoint\" must occur after \"suffix\".\n",
743 ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
744 bdb->bi_txn_cp_task = ldap_pvt_runqueue_insert( &slapd_rq,
745 bdb->bi_txn_cp_min * 60, bdb_checkpoint, bdb,
746 LDAP_XSTRING(bdb_checkpoint), c->be->be_suffix[0].bv_val );
747 ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
756 if ( c->op == SLAP_CONFIG_ADD ) {
757 ptr += STRLENOF("dbconfig");
758 while (!isspace((unsigned char)*ptr)) ptr++;
759 while (isspace((unsigned char)*ptr)) ptr++;
762 if ( bdb->bi_flags & BDB_IS_OPEN ) {
763 bdb->bi_flags |= BDB_UPD_CONFIG|BDB_RE_OPEN;
764 c->cleanup = bdb_cf_cleanup;
766 /* If we're just starting up...
769 /* If a DB_CONFIG file exists, or we don't know the path
770 * to the DB_CONFIG file, ignore these directives
772 if (( bdb->bi_flags & BDB_HAS_CONFIG ) || !bdb->bi_db_config_path )
774 f = fopen( bdb->bi_db_config_path, "a" );
776 /* FIXME: EBCDIC probably needs special handling */
777 fprintf( f, "%s\n", ptr );
781 ber_str2bv( ptr, 0, 1, &bv );
782 ber_bvarray_add( &bdb->bi_db_config, &bv );
787 rc = lutil_get_filed_password( c->value_string, &bdb->bi_db_crypt_key );
789 bdb->bi_db_crypt_file = c->value_string;
793 /* Cannot set key if file was already set */
795 if ( bdb->bi_db_crypt_file ) {
798 bdb->bi_db_crypt_key = c->value_bv;
802 case BDB_DIRECTORY: {
804 char *ptr, *testpath;
807 len = strlen( c->value_string );
808 testpath = ch_malloc( len + STRLENOF(LDAP_DIRSEP) + STRLENOF("DUMMY") + 1 );
809 ptr = lutil_strcopy( testpath, c->value_string );
810 *ptr++ = LDAP_DIRSEP[0];
811 strcpy( ptr, "DUMMY" );
812 f = fopen( testpath, "w" );
819 snprintf( c->cr_msg, sizeof( c->cr_msg ), "%s: invalid path: %s",
820 c->log, strerror( errno ));
821 Debug( LDAP_DEBUG_ANY, "%s\n", c->cr_msg, 0, 0 );
825 if ( bdb->bi_dbenv_home )
826 ch_free( bdb->bi_dbenv_home );
827 bdb->bi_dbenv_home = c->value_string;
829 /* See if a DB_CONFIG file already exists here */
830 if ( bdb->bi_db_config_path )
831 ch_free( bdb->bi_db_config_path );
832 bdb->bi_db_config_path = ch_malloc( len +
833 STRLENOF(LDAP_DIRSEP) + STRLENOF("DB_CONFIG") + 1 );
834 ptr = lutil_strcopy( bdb->bi_db_config_path, bdb->bi_dbenv_home );
835 *ptr++ = LDAP_DIRSEP[0];
836 strcpy( ptr, "DB_CONFIG" );
838 f = fopen( bdb->bi_db_config_path, "r" );
840 bdb->bi_flags |= BDB_HAS_CONFIG;
848 bdb->bi_dbenv_xflags |= DB_TXN_NOSYNC;
850 bdb->bi_dbenv_xflags &= ~DB_TXN_NOSYNC;
851 if ( bdb->bi_flags & BDB_IS_OPEN ) {
852 bdb->bi_dbenv->set_flags( bdb->bi_dbenv, DB_TXN_NOSYNC,
859 bdb->bi_flags |= BDB_CHKSUM;
861 bdb->bi_flags &= ~BDB_CHKSUM;
865 rc = bdb_attr_index_config( bdb, c->fname, c->lineno,
866 c->argc - 1, &c->argv[1], &c->reply);
868 if( rc != LDAP_SUCCESS ) return 1;
869 if (( bdb->bi_flags & BDB_IS_OPEN ) && !bdb->bi_index_task ) {
870 /* Start the task as soon as we finish here. Set a long
871 * interval (10 hours) so that it only gets scheduled once.
873 if ( c->be->be_suffix == NULL || BER_BVISNULL( &c->be->be_suffix[0] ) ) {
874 fprintf( stderr, "%s: "
875 "\"index\" must occur after \"suffix\".\n",
879 ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
880 bdb->bi_index_task = ldap_pvt_runqueue_insert( &slapd_rq, 36000,
881 bdb_online_index, c->be,
882 LDAP_XSTRING(bdb_online_index), c->be->be_suffix[0].bv_val );
883 ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
888 rc = verb_to_mask( c->argv[1], bdb_lockd );
889 if ( BER_BVISNULL(&bdb_lockd[rc].word) ) {
890 fprintf( stderr, "%s: "
891 "bad policy (%s) in \"lockDetect <policy>\" line\n",
892 c->log, c->argv[1] );
895 bdb->bi_lock_detect = (u_int32_t)rc;
899 if ( c->value_int < MINIMUM_SEARCH_STACK_DEPTH ) {
901 "%s: depth %d too small, using %d\n",
902 c->log, c->value_int, MINIMUM_SEARCH_STACK_DEPTH );
903 c->value_int = MINIMUM_SEARCH_STACK_DEPTH;
905 bdb->bi_search_stack_depth = c->value_int;
909 struct bdb_db_pgsize *ps, **prev;
912 s = atoi(c->argv[2]);
913 if ( s < 1 || s > 64 ) {
914 snprintf( c->cr_msg, sizeof( c->cr_msg ),
915 "%s: size must be > 0 and <= 64: %d",
917 Debug( LDAP_DEBUG_ANY, "%s\n", c->cr_msg, 0, 0 );
920 i = strlen(c->argv[1]);
921 ps = ch_malloc( sizeof(struct bdb_db_pgsize) + i + 1 );
923 ps->bdp_name.bv_len = i;
924 ps->bdp_name.bv_val = (char *)(ps+1);
925 strcpy( ps->bdp_name.bv_val, c->argv[1] );
926 ps->bdp_size = s * 1024;
927 for ( prev = &bdb->bi_pagesizes; *prev; prev = &(*prev)->bdp_next )
936 int bdb_back_init_cf( BackendInfo *bi )
939 bi->bi_cf_ocs = bdbocs;
941 rc = config_register_schema( bdbcfg, bdbocs );