]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb/config.c
75d41a4dc4d1f42c1b0e1109d76a09344915726c
[openldap] / servers / slapd / back-bdb / config.c
1 /* config.c - bdb backend configuration file routine */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
5  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
6  */
7
8 #include "portable.h"
9
10 #include <stdio.h>
11 #include <ac/string.h>
12
13 #include "back-bdb.h"
14
15 #define SLAP_BDB_ALLOW_DBNOTXN
16 #define SLAP_BDB_ALLOW_DIRTY_READ
17
18 int
19 bdb_db_config(
20         BackendDB       *be,
21         const char      *fname,
22         int             lineno,
23         int             argc,
24         char    **argv )
25 {
26         struct bdb_info *bdb = (struct bdb_info *) be->be_private;
27
28         if ( bdb == NULL ) {
29                 fprintf( stderr, "%s: line %d: "
30                         "bdb database info is null!\n",
31                         fname, lineno );
32                 return 1;
33         }
34
35         /* directory is the DB_HOME */
36         if ( strcasecmp( argv[0], "directory" ) == 0 ) {
37                 if ( argc < 2 ) {
38                         fprintf( stderr, "%s: line %d: "
39                                 "missing dir in \"directory <dir>\" line\n",
40                                 fname, lineno );
41                         return 1;
42                 }
43                 if ( bdb->bi_dbenv_home ) {
44                         free( bdb->bi_dbenv_home );
45                 }
46                 bdb->bi_dbenv_home = ch_strdup( argv[1] );
47
48 #ifdef SLAP_BDB_ALLOW_DBNOTXN
49         /* turn off transactions, use CDB mode instead */
50         } else if ( strcasecmp( argv[0], "dbnotxn" ) == 0 ) {
51                 bdb->bi_txn = 0;
52 #endif
53 #ifdef SLAP_BDB_ALLOW_DIRTY_READ
54         } else if ( strcasecmp( argv[0], "dirtyread" ) == 0 ) {
55                 bdb->bi_db_opflags |= DB_DIRTY_READ;
56 #endif
57         /* transaction checkpoint configuration */
58         } else if ( strcasecmp( argv[0], "dbnosync" ) == 0 ) {
59                 bdb->bi_dbenv_xflags |= DB_TXN_NOSYNC;
60
61         /* transaction checkpoint configuration */
62         } else if ( strcasecmp( argv[0], "checkpoint" ) == 0 ) {
63                 if ( argc < 3 ) {
64                         fprintf( stderr, "%s: line %d: "
65                                 "missing parameters in \"checkpoint <kbyte> <min>\" line\n",
66                                 fname, lineno );
67                         return 1;
68                 }
69                 bdb->bi_txn_cp = 1;
70                 bdb->bi_txn_cp_kbyte = strtol( argv[1], NULL, 0 );
71                 bdb->bi_txn_cp_min = strtol( argv[2], NULL, 0 );
72
73         /* lock detect configuration */
74         } else if ( strcasecmp( argv[0], "lockdetect" ) == 0 ) {
75 #ifndef NO_THREADS
76                 if ( argc < 3 ) {
77                         fprintf( stderr, "%s: line %d: "
78                                 "missing parameters in \"lockDetect <policy> <seconds>\" line\n",
79                                 fname, lineno );
80                         return 1;
81                 }
82
83                 if( strcasecmp( argv[1], "default" ) == 0 ) {
84                         bdb->bi_lock_detect = DB_LOCK_DEFAULT;
85
86                 } else if( strcasecmp( argv[1], "oldest" ) == 0 ) {
87                         bdb->bi_lock_detect = DB_LOCK_OLDEST;
88
89                 } else if( strcasecmp( argv[1], "random" ) == 0 ) {
90                         bdb->bi_lock_detect = DB_LOCK_RANDOM;
91
92                 } else if( strcasecmp( argv[1], "youngest" ) == 0 ) {
93                         bdb->bi_lock_detect = DB_LOCK_YOUNGEST;
94
95                 } else {
96                         fprintf( stderr, "%s: line %d: "
97                                 "bad policy (%s) in \"lockDetect <policy> <seconds>\" line\n",
98                                 fname, lineno, argv[1] );
99                         return 1;
100                 }
101
102                 bdb->bi_lock_detect_seconds = strtol( argv[2], NULL, 0 );
103                 if( bdb->bi_lock_detect_seconds < 1 ) {
104                         fprintf( stderr, "%s: line %d: "
105                                 "bad seconds (%s) in \"lockDetect <policy> <seconds>\" line\n",
106                                 fname, lineno, argv[2] );
107                         return 1;
108                 }
109 #else
110                 fprintf( stderr, "%s: line %d: "
111                         "NO THREADS: lockDetect line ignored\n",
112                         fname, lineno );
113 #endif
114
115         /* mode with which to create new database files */
116         } else if ( strcasecmp( argv[0], "mode" ) == 0 ) {
117                 if ( argc < 2 ) {
118                         fprintf( stderr, "%s: line %d: "
119                                 "missing mode in \"mode <mode>\" line\n",
120                                 fname, lineno );
121                         return 1;
122                 }
123                 bdb->bi_dbenv_mode = strtol( argv[1], NULL, 0 );
124
125 #if BDB_FILTER_INDICES
126         /* attribute to index */
127         } else if ( strcasecmp( argv[0], "index" ) == 0 ) {
128                 int rc;
129                 if ( argc < 2 ) {
130                         fprintf( stderr, "%s: line %d: "
131                                 "missing attr in \"index <attr> [pres,eq,approx,sub]\" line\n",
132                                 fname, lineno );
133                         return 1;
134                 } else if ( argc > 3 ) {
135                         fprintf( stderr, "%s: line %d: "
136                                 "extra junk after \"index <attr> [pres,eq,approx,sub]\" "
137                                 "line (ignored)\n",
138                                 fname, lineno );
139                 }
140                 rc = bdb_attr_index_config( bdb, fname, lineno, argc - 1, &argv[1] );
141
142                 if( rc != LDAP_SUCCESS ) return 1;
143 #endif
144
145         /* anything else */
146         } else {
147                 fprintf( stderr, "%s: line %d: "
148                         "unknown directive \"%s\" in bdb database definition (ignored)\n",
149                         fname, lineno, argv[0] );
150         }
151
152         return 0;
153 }