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