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