]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb/config.c
1c01c2296fceb30b32c5b70b9fa2acc6a0611277
[openldap] / servers / slapd / back-bdb / config.c
1 /* config.c - bdb backend configuration file routine */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 2000-2005 The OpenLDAP Foundation.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted only as authorized by the OpenLDAP
10  * Public License.
11  *
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>.
15  */
16
17 #include "portable.h"
18
19 #include <stdio.h>
20 #include <ac/ctype.h>
21 #include <ac/string.h>
22
23 #include "back-bdb.h"
24
25 #include "config.h"
26
27 #include "lutil.h"
28 #include "ldap_rq.h"
29
30 #ifdef DB_DIRTY_READ
31 #       define  SLAP_BDB_ALLOW_DIRTY_READ
32 #endif
33
34 #define bdb_cf_gen                      BDB_SYMBOL(cf_gen)
35 #define bdb_cf_cleanup          BDB_SYMBOL(cf_cleanup)
36 #define bdb_checkpoint          BDB_SYMBOL(checkpoint)
37 #define bdb_online_index        BDB_SYMBOL(online_index)
38
39 static ConfigDriver bdb_cf_gen;
40
41 enum {
42         BDB_CHKPT = 1,
43         BDB_CONFIG,
44         BDB_DIRECTORY,
45         BDB_NOSYNC,
46         BDB_DIRTYR,
47         BDB_INDEX,
48         BDB_LOCKD,
49         BDB_SSTACK
50 };
51
52 static ConfigTable bdbcfg[] = {
53         { "directory", "dir", 2, 2, 0, ARG_STRING|ARG_MAGIC|BDB_DIRECTORY,
54                 bdb_cf_gen, "( OLcfgDbAt:0.1 NAME 'olcDbDirectory' "
55                         "DESC 'Directory for database content' "
56                         "EQUALITY caseIgnoreMatch "
57                         "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
58         { "cachesize", "size", 2, 2, 0, ARG_INT|ARG_OFFSET,
59                 (void *)offsetof(struct bdb_info, bi_cache.c_maxsize),
60                 "( OLcfgDbAt:1.1 NAME 'olcDbCacheSize' "
61                         "DESC 'Entry cache size in entries' "
62                         "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
63         { "checkpoint", "kbyte> <min", 3, 3, 0, ARG_MAGIC|BDB_CHKPT,
64                 bdb_cf_gen, "( OLcfgDbAt:1.2 NAME 'olcDbCheckpoint' "
65                         "DESC 'Database checkpoint interval in kbytes and minutes' "
66                         "SYNTAX OMsDirectoryString SINGLE-VALUE )",NULL, NULL },
67         { "dbconfig", "DB_CONFIG setting", 1, 0, 0, ARG_MAGIC|BDB_CONFIG,
68                 bdb_cf_gen, "( OLcfgDbAt:1.3 NAME 'olcDbConfig' "
69                         "DESC 'BerkeleyDB DB_CONFIG configuration directives' "
70                         "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",NULL, NULL },
71         { "dbnosync", NULL, 1, 2, 0, ARG_ON_OFF|ARG_MAGIC|BDB_NOSYNC,
72                 bdb_cf_gen, "( OLcfgDbAt:1.4 NAME 'olcDbNoSync' "
73                         "DESC 'Disable synchronous database writes' "
74                         "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
75         { "dirtyread", NULL, 1, 2, 0,
76 #ifdef SLAP_BDB_ALLOW_DIRTY_READ
77                 ARG_ON_OFF|ARG_MAGIC|BDB_DIRTYR, bdb_cf_gen,
78 #else
79                 ARG_IGNORED, NULL,
80 #endif
81                 "( OLcfgDbAt:1.5 NAME 'olcDbDirtyRead' "
82                 "DESC 'Allow reads of uncommitted data' "
83                 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
84         { "idlcachesize", "size", 2, 2, 0, ARG_INT|ARG_OFFSET,
85                 (void *)offsetof(struct bdb_info,bi_idl_cache_max_size),
86                 "( OLcfgDbAt:1.6 NAME 'olcDbIDLcacheSize' "
87                 "DESC 'IDL cache size in IDLs' "
88                 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
89         { "index", "attr> <[pres,eq,approx,sub]", 2, 3, 0, ARG_MAGIC|BDB_INDEX,
90                 bdb_cf_gen, "( OLcfgDbAt:0.2 NAME 'olcDbIndex' "
91                 "DESC 'Attribute index parameters' "
92                 "EQUALITY caseIgnoreMatch "
93                 "SYNTAX OMsDirectoryString )", NULL, NULL },
94         { "linearindex", NULL, 1, 2, 0, ARG_ON_OFF|ARG_OFFSET,
95                 (void *)offsetof(struct bdb_info, bi_linear_index), 
96                 "( OLcfgDbAt:1.7 NAME 'olcDbLinearIndex' "
97                 "DESC 'Index attributes one at a time' "
98                 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
99         { "lockdetect", "policy", 2, 2, 0, ARG_MAGIC|BDB_LOCKD,
100                 bdb_cf_gen, "( OLcfgDbAt:1.8 NAME 'olcDbLockDetect' "
101                 "DESC 'Deadlock detection algorithm' "
102                 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
103         { "mode", "mode", 2, 2, 0, ARG_INT|ARG_OFFSET,
104                 (void *)offsetof(struct bdb_info, bi_dbenv_mode),
105                 "( OLcfgDbAt:0.3 NAME 'olcDbMode' "
106                 "DESC 'Unix permissions of database files' "
107                 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
108         { "searchstack", "depth", 2, 2, 0, ARG_INT|ARG_MAGIC|BDB_SSTACK,
109                 bdb_cf_gen, "( OLcfgDbAt:1.9 NAME 'olcDbSearchStack' "
110                 "DESC 'Depth of search stack in IDLs' "
111                 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
112         { "shm_key", "key", 2, 2, 0, ARG_INT|ARG_OFFSET,
113                 (void *)offsetof(struct bdb_info, bi_shm_key), 
114                 "( OLcfgDbAt:1.10 NAME 'olcDbShmKey' "
115                 "DESC 'Key for shared memory region' "
116                 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
117         { NULL, NULL, 0, 0, 0, ARG_IGNORED,
118                 NULL, NULL, NULL, NULL }
119 };
120
121 static ConfigOCs bdbocs[] = {
122         {
123 #ifdef BDB_HIER
124                 "( OLcfgDbOc:1.2 "
125                 "NAME 'olcHdbConfig' "
126                 "DESC 'HDB backend configuration' "
127 #else
128                 "( OLcfgDbOc:1.1 "
129                 "NAME 'olcBdbConfig' "
130                 "DESC 'BDB backend configuration' "
131 #endif
132                 "SUP olcDatabaseConfig "
133                 "MUST olcDbDirectory "
134                 "MAY ( olcDbCacheSize $ olcDbCheckpoint $ olcDbConfig $ "
135                 "olcDbNoSync $ olcDbDirtyRead $ olcDbIDLcacheSize $ "
136                 "olcDbIndex $ olcDbLinearIndex $ olcDbLockDetect $ "
137                 "olcDbMode $ olcDbSearchStack $ olcDbShmKey ) )",
138                         Cft_Database, bdbcfg },
139         { NULL, 0, NULL }
140 };
141
142 static slap_verbmasks bdb_lockd[] = {
143         { BER_BVC("default"), DB_LOCK_DEFAULT },
144         { BER_BVC("oldest"), DB_LOCK_OLDEST },
145         { BER_BVC("random"), DB_LOCK_RANDOM },
146         { BER_BVC("youngest"), DB_LOCK_YOUNGEST },
147         { BER_BVC("fewest"), DB_LOCK_MINLOCKS },
148         { BER_BVNULL, 0 }
149 };
150
151 /* perform periodic checkpoints */
152 static void *
153 bdb_checkpoint( void *ctx, void *arg )
154 {
155         struct re_s *rtask = arg;
156         struct bdb_info *bdb = rtask->arg;
157         
158         TXN_CHECKPOINT( bdb->bi_dbenv, bdb->bi_txn_cp_kbyte,
159                 bdb->bi_txn_cp_min, 0 );
160         ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
161         ldap_pvt_runqueue_stoptask( &slapd_rq, rtask );
162         ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
163         return NULL;
164 }
165
166 /* reindex entries on the fly */
167 static void *
168 bdb_online_index( void *ctx, void *arg )
169 {
170         struct re_s *rtask = arg;
171         BackendDB *be = rtask->arg;
172         struct bdb_info *bdb = be->be_private;
173
174         Connection conn = {0};
175         char opbuf[OPERATION_BUFFER_SIZE];
176         Operation *op = (Operation *)opbuf;
177
178         DBC *curs;
179         DBT key, data;
180         DB_TXN *txn;
181         DB_LOCK lock;
182         u_int32_t locker;
183         ID id, nid;
184         EntryInfo *ei;
185         int rc, getnext = 1;
186
187         connection_fake_init( &conn, op, ctx );
188
189         op->o_bd = be;
190
191         DBTzero( &key );
192         DBTzero( &data );
193         
194         id = 1;
195         key.data = &nid;
196         key.size = key.ulen = sizeof(ID);
197         key.flags = DB_DBT_USERMEM;
198
199         data.flags = DB_DBT_USERMEM | DB_DBT_PARTIAL;
200         data.dlen = data.ulen = 0;
201
202         while ( 1 ) {
203                 if ( slapd_shutdown )
204                         break;
205
206                 rc = TXN_BEGIN( bdb->bi_dbenv, NULL, &txn, bdb->bi_db_opflags );
207                 if ( rc ) 
208                         break;
209                 locker = TXN_ID( txn );
210                 if ( getnext ) {
211                         getnext = 0;
212                         BDB_ID2DISK( id, &nid );
213                         rc = bdb->bi_id2entry->bdi_db->cursor(
214                                 bdb->bi_id2entry->bdi_db, txn, &curs, bdb->bi_db_opflags );
215                         if ( rc ) {
216                                 TXN_ABORT( txn );
217                                 break;
218                         }
219                         rc = curs->c_get( curs, &key, &data, DB_SET_RANGE );
220                         curs->c_close( curs );
221                         if ( rc ) {
222                                 TXN_ABORT( txn );
223                                 if ( rc == DB_NOTFOUND )
224                                         rc = 0;
225                                 if ( rc == DB_LOCK_DEADLOCK ) {
226                                         ldap_pvt_thread_yield();
227                                         continue;
228                                 }
229                                 break;
230                         }
231                         BDB_DISK2ID( &nid, &id );
232                 }
233
234                 ei = NULL;
235                 rc = bdb_cache_find_id( op, txn, id, &ei, 0, locker, &lock );
236                 if ( rc ) {
237                         TXN_ABORT( txn );
238                         if ( rc == DB_LOCK_DEADLOCK ) {
239                                 ldap_pvt_thread_yield();
240                                 continue;
241                         }
242                         if ( rc == DB_NOTFOUND ) {
243                                 id++;
244                                 getnext = 1;
245                                 continue;
246                         }
247                         break;
248                 }
249                 if ( ei->bei_e ) {
250                         rc = bdb_index_entry( op, txn, BDB_INDEX_UPDATE_OP, ei->bei_e );
251                         if ( rc == DB_LOCK_DEADLOCK ) {
252                                 TXN_ABORT( txn );
253                                 ldap_pvt_thread_yield();
254                                 continue;
255                         }
256                         if ( rc == 0 ) {
257                                 rc = TXN_COMMIT( txn, 0 );
258                                 txn = NULL;
259                         }
260                         if ( rc )
261                                 break;
262                 }
263                 id++;
264                 getnext = 1;
265         }
266 out:
267         ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
268         ldap_pvt_runqueue_stoptask( &slapd_rq, rtask );
269         bdb->bi_index_task = NULL;
270         ldap_pvt_runqueue_remove( &slapd_rq, rtask );
271         ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
272
273         return NULL;
274 }
275
276 /* Cleanup loose ends after Modify completes */
277 static int
278 bdb_cf_cleanup( ConfigArgs *c )
279 {
280         struct bdb_info *bdb = c->be->be_private;
281         int rc = 0;
282
283         if ( bdb->bi_flags & BDB_UPD_CONFIG ) {
284                 if ( bdb->bi_db_config ) {
285                         int i;
286                         FILE *f = fopen( bdb->bi_db_config_path, "w" );
287                         if ( f ) {
288                                 for (i=0; bdb->bi_db_config[i].bv_val; i++)
289                                         fprintf( f, "%s\n", bdb->bi_db_config[i].bv_val );
290                                 fclose( f );
291                         }
292                 } else {
293                         unlink( bdb->bi_db_config_path );
294                 }
295                 bdb->bi_flags ^= BDB_UPD_CONFIG;
296         }
297
298         if ( bdb->bi_flags & BDB_DEL_INDEX ) {
299                 bdb_attr_flush( bdb );
300                 bdb->bi_flags ^= BDB_DEL_INDEX;
301         }
302         
303         if ( bdb->bi_flags & BDB_RE_OPEN ) {
304                 bdb->bi_flags ^= BDB_RE_OPEN;
305                 rc = c->be->bd_info->bi_db_close( c->be );
306                 if ( rc == 0 )
307                         rc = c->be->bd_info->bi_db_open( c->be );
308                 /* If this fails, we need to restart */
309                 if ( rc ) {
310                         slapd_shutdown = 2;
311                         Debug( LDAP_DEBUG_ANY, LDAP_XSTRING(bdb_cf_cleanup)
312                                 ": failed to reopen database, rc=%d", rc, 0, 0 );
313                 }
314         }
315         return rc;
316 }
317
318 static int
319 bdb_cf_gen(ConfigArgs *c)
320 {
321         struct bdb_info *bdb = c->be->be_private;
322         int rc;
323
324         if ( c->op == SLAP_CONFIG_EMIT ) {
325                 rc = 0;
326                 switch( c->type ) {
327                 case BDB_CHKPT:
328                         if (bdb->bi_txn_cp ) {
329                                 char buf[64];
330                                 struct berval bv;
331                                 bv.bv_len = sprintf( buf, "%d %d", bdb->bi_txn_cp_kbyte,
332                                         bdb->bi_txn_cp_min );
333                                 bv.bv_val = buf;
334                                 value_add_one( &c->rvalue_vals, &bv );
335                         } else{
336                                 rc = 1;
337                         }
338                         break;
339
340                 case BDB_DIRECTORY:
341                         if ( bdb->bi_dbenv_home ) {
342                                 c->value_string = ch_strdup( bdb->bi_dbenv_home );
343                         } else {
344                                 rc = 1;
345                         }
346                         break;
347
348                 case BDB_CONFIG:
349                         if (( slapMode&SLAP_SERVER_MODE ) && !( bdb->bi_flags&BDB_IS_OPEN )
350                                 && !bdb->bi_db_config ) {
351                                 char    buf[SLAP_TEXT_BUFLEN];
352                                 FILE *f = fopen( bdb->bi_db_config_path, "r" );
353                                 struct berval bv;
354
355                                 if ( f ) {
356                                         bdb->bi_flags |= BDB_HAS_CONFIG;
357                                         while ( fgets( buf, sizeof(buf), f )) {
358                                                 ber_str2bv( buf, 0, 1, &bv );
359                                                 if ( bv.bv_val[bv.bv_len-1] == '\n' ) {
360                                                         bv.bv_len--;
361                                                         bv.bv_val[bv.bv_len] = '\0';
362                                                 }
363                                                 /* shouldn't need this, but ... */
364                                                 if ( bv.bv_val[bv.bv_len-1] == '\r' ) {
365                                                         bv.bv_len--;
366                                                         bv.bv_val[bv.bv_len] = '\0';
367                                                 }
368                                                 ber_bvarray_add( &bdb->bi_db_config, &bv );
369                                         }
370                                         fclose( f );
371                                 }
372                         }
373                         if ( bdb->bi_db_config ) {
374                                 int i;
375                                 struct berval bv;
376
377                                 bv.bv_val = c->log;
378                                 for (i=0; !BER_BVISNULL(&bdb->bi_db_config[i]); i++) {
379                                         bv.bv_len = sprintf( bv.bv_val, "{%d}%s", i,
380                                                 bdb->bi_db_config[i].bv_val );
381                                         value_add_one( &c->rvalue_vals, &bv );
382                                 }
383                         }
384                         if ( !c->rvalue_vals ) rc = 1;
385                         break;
386
387                 case BDB_NOSYNC:
388                         if ( bdb->bi_dbenv_xflags & DB_TXN_NOSYNC )
389                                 c->value_int = 1;
390                         break;
391                         
392                 case BDB_INDEX:
393                         bdb_attr_index_unparse( bdb, &c->rvalue_vals );
394                         if ( !c->rvalue_vals ) rc = 1;
395                         break;
396
397                 case BDB_LOCKD:
398                         rc = 1;
399                         if ( bdb->bi_lock_detect != DB_LOCK_DEFAULT ) {
400                                 int i;
401                                 for (i=0; !BER_BVISNULL(&bdb_lockd[i].word); i++) {
402                                         if ( bdb->bi_lock_detect == bdb_lockd[i].mask ) {
403                                                 value_add_one( &c->rvalue_vals, &bdb_lockd[i].word );
404                                                 rc = 0;
405                                                 break;
406                                         }
407                                 }
408                         }
409                         break;
410
411                 case BDB_SSTACK:
412                         c->value_int = bdb->bi_search_stack_depth;
413                         break;
414                 }
415                 return rc;
416         } else if ( c->op == LDAP_MOD_DELETE ) {
417                 rc = 0;
418                 switch( c->type ) {
419                 /* single-valued no-ops */
420                 case BDB_LOCKD:
421                 case BDB_SSTACK:
422                         break;
423
424                 case BDB_CHKPT:
425                         if ( bdb->bi_txn_cp_task ) {
426                                 struct re_s *re = bdb->bi_txn_cp_task;
427                                 bdb->bi_txn_cp_task = NULL;
428                                 if ( ldap_pvt_runqueue_isrunning( &slapd_rq, re ))
429                                         ldap_pvt_runqueue_stoptask( &slapd_rq, re );
430                                 ldap_pvt_runqueue_remove( &slapd_rq, re );
431                         }
432                         bdb->bi_txn_cp = 0;
433                         break;
434                 case BDB_CONFIG:
435                         if ( c->valx < 0 ) {
436                                 ber_bvarray_free( bdb->bi_db_config );
437                                 bdb->bi_db_config = NULL;
438                         } else {
439                                 int i = c->valx;
440                                 ch_free( bdb->bi_db_config[i].bv_val );
441                                 for (; bdb->bi_db_config[i].bv_val; i++)
442                                         bdb->bi_db_config[i] = bdb->bi_db_config[i+1];
443                         }
444                         bdb->bi_flags |= BDB_UPD_CONFIG;
445                         c->cleanup = bdb_cf_cleanup;
446                         break;
447                 case BDB_DIRECTORY:
448                         bdb->bi_flags |= BDB_RE_OPEN;
449                         bdb->bi_flags ^= BDB_HAS_CONFIG;
450                         ch_free( bdb->bi_dbenv_home );
451                         bdb->bi_dbenv_home = NULL;
452                         ch_free( bdb->bi_db_config_path );
453                         bdb->bi_db_config_path = NULL;
454                         c->cleanup = bdb_cf_cleanup;
455                         ldap_pvt_thread_pool_purgekey( bdb->bi_dbenv );
456                         ldap_pvt_thread_pool_purgekey( ((char *)bdb->bi_dbenv) + 1 );
457                         break;
458                 case BDB_NOSYNC:
459                         bdb->bi_dbenv->set_flags( bdb->bi_dbenv, DB_TXN_NOSYNC, 0 );
460                         break;
461                 case BDB_INDEX: {
462                         AttributeDescription *ad = NULL;
463                         struct berval bv, def = BER_BVC("default");
464                         char *ptr;
465                         const char *text;
466                         for (ptr = c->line; !isspace( *ptr ); ptr++);
467                         bv.bv_val = c->line;
468                         bv.bv_len = ptr - bv.bv_val;
469                         if ( bvmatch( &bv, &def )) {
470                                 bdb->bi_defaultmask = 0;
471                         } else {
472                                 slap_bv2ad( &bv, &ad, &text );
473                                 if ( ad ) {
474                                         AttrInfo *ai = bdb_attr_mask( bdb, ad );
475                                         ai->ai_indexmask |= BDB_INDEX_DELETING;
476                                         bdb->bi_flags |= BDB_DEL_INDEX;
477                                         c->cleanup = bdb_cf_cleanup;
478                                 }
479                         }
480                         }
481                         break;
482                 }
483                 return rc;
484         }
485
486         switch( c->type ) {
487         case BDB_CHKPT:
488                 bdb->bi_txn_cp = 1;
489                 bdb->bi_txn_cp_kbyte = strtol( c->argv[1], NULL, 0 );
490                 bdb->bi_txn_cp_min = strtol( c->argv[2], NULL, 0 );
491                 /* If we're in server mode and time-based checkpointing is enabled,
492                  * submit a task to perform periodic checkpoints.
493                  */
494                 if ((slapMode & SLAP_SERVER_MODE) && bdb->bi_txn_cp_min ) {
495                         struct re_s *re = bdb->bi_txn_cp_task;
496                         if ( re ) {
497                                 re->interval.tv_sec = bdb->bi_txn_cp_min * 60;
498                         } else {
499                                 if ( c->be->be_suffix == NULL || BER_BVISNULL( &c->be->be_suffix[0] ) ) {
500                                         fprintf( stderr, "%s: "
501                                                 "\"checkpoint\" must occur after \"suffix\".\n",
502                                                 c->log );
503                                         return 1;
504                                 }
505                                 bdb->bi_txn_cp_task = ldap_pvt_runqueue_insert( &slapd_rq,
506                                         bdb->bi_txn_cp_min * 60, bdb_checkpoint, bdb,
507                                         LDAP_XSTRING(bdb_checkpoint), c->be->be_suffix[0].bv_val );
508                         }
509                 }
510                 break;
511
512         case BDB_CONFIG: {
513                 char *ptr = c->line;
514                 struct berval bv;
515
516                 if ( c->op == SLAP_CONFIG_ADD ) {
517                         ptr += STRLENOF("dbconfig");
518                         while (!isspace(*ptr)) ptr++;
519                         while (isspace(*ptr)) ptr++;
520                 }
521
522                 if ( bdb->bi_flags & BDB_IS_OPEN ) {
523                         bdb->bi_flags |= BDB_UPD_CONFIG;
524                         c->cleanup = bdb_cf_cleanup;
525                 } else {
526                 /* If we're just starting up...
527                  */
528                         FILE *f;
529                         /* If a DB_CONFIG file exists, or we don't know the path
530                          * to the DB_CONFIG file, ignore these directives
531                          */
532                         if (( bdb->bi_flags & BDB_HAS_CONFIG ) || !bdb->bi_db_config_path )
533                                 break;
534                         f = fopen( bdb->bi_db_config_path, "a" );
535                         if ( f ) {
536                                 /* FIXME: EBCDIC probably needs special handling */
537                                 fprintf( f, "%s\n", ptr );
538                                 fclose( f );
539                         }
540                 }
541                 ber_str2bv( ptr, 0, 1, &bv );
542                 ber_bvarray_add( &bdb->bi_db_config, &bv );
543                 }
544                 break;
545
546         case BDB_DIRECTORY: {
547                 FILE *f;
548                 char *ptr;
549
550                 if ( bdb->bi_dbenv_home )
551                         ch_free( bdb->bi_dbenv_home );
552                 bdb->bi_dbenv_home = c->value_string;
553
554                 /* See if a DB_CONFIG file already exists here */
555                 if ( bdb->bi_db_config_path )
556                         ch_free( bdb->bi_db_config_path );
557                 bdb->bi_db_config_path = ch_malloc( strlen( bdb->bi_dbenv_home ) +
558                         STRLENOF(LDAP_DIRSEP) + STRLENOF("DB_CONFIG") + 1 );
559                 ptr = lutil_strcopy( bdb->bi_db_config_path, bdb->bi_dbenv_home );
560                 *ptr++ = LDAP_DIRSEP[0];
561                 strcpy( ptr, "DB_CONFIG" );
562
563                 f = fopen( bdb->bi_db_config_path, "r" );
564                 if ( f ) {
565                         bdb->bi_flags |= BDB_HAS_CONFIG;
566                         fclose(f);
567                 }
568                 }
569                 break;
570
571         case BDB_NOSYNC:
572                 if ( c->value_int )
573                         bdb->bi_dbenv_xflags |= DB_TXN_NOSYNC;
574                 else
575                         bdb->bi_dbenv_xflags &= ~DB_TXN_NOSYNC;
576                 if ( bdb->bi_flags & BDB_IS_OPEN ) {
577                         bdb->bi_dbenv->set_flags( bdb->bi_dbenv, DB_TXN_NOSYNC,
578                                 c->value_int );
579                 }
580                 break;
581
582         case BDB_INDEX:
583                 rc = bdb_attr_index_config( bdb, c->fname, c->lineno,
584                         c->argc - 1, &c->argv[1] );
585
586                 if( rc != LDAP_SUCCESS ) return 1;
587                 if (( bdb->bi_flags & BDB_IS_OPEN ) && !bdb->bi_index_task ) {
588                         /* Start the task as soon as we finish here. Set a long
589                          * interval (10 hours) so that it only gets scheduled once.
590                          */
591                         if ( c->be->be_suffix == NULL || BER_BVISNULL( &c->be->be_suffix[0] ) ) {
592                                 fprintf( stderr, "%s: "
593                                         "\"index\" must occur after \"suffix\".\n",
594                                         c->log );
595                                 return 1;
596                         }
597                         bdb->bi_index_task = ldap_pvt_runqueue_insert( &slapd_rq, 36000,
598                                 bdb_online_index, c->be,
599                                 LDAP_XSTRING(bdb_online_index), c->be->be_suffix[0].bv_val );
600                 }
601                 break;
602
603         case BDB_LOCKD:
604                 rc = verb_to_mask( c->argv[1], bdb_lockd );
605                 if ( BER_BVISNULL(&bdb_lockd[rc].word) ) {
606                         fprintf( stderr, "%s: "
607                                 "bad policy (%s) in \"lockDetect <policy>\" line\n",
608                                 c->log, c->argv[1] );
609                         return 1;
610                 }
611                 bdb->bi_lock_detect = rc;
612                 break;
613
614         case BDB_SSTACK:
615                 if ( c->value_int < MINIMUM_SEARCH_STACK_DEPTH ) {
616                         fprintf( stderr,
617                 "%s: depth %d too small, using %d\n",
618                         c->log, c->value_int, MINIMUM_SEARCH_STACK_DEPTH );
619                         c->value_int = MINIMUM_SEARCH_STACK_DEPTH;
620                 }
621                 bdb->bi_search_stack_depth = c->value_int;
622                 break;
623         }
624         return 0;
625 }
626
627 int bdb_back_init_cf( BackendInfo *bi )
628 {
629         int rc;
630         bi->bi_cf_ocs = bdbocs;
631
632         rc = config_register_schema( bdbcfg, bdbocs );
633         if ( rc ) return rc;
634         return 0;
635 }