]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb/config.c
First rounded of changes in prep for 2.2.beta3
[openldap] / servers / slapd / back-bdb / config.c
1 /* config.c - bdb backend configuration file routine */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-2003 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 #include "external.h"
15
16 #ifdef DB_DIRTY_READ
17 #       define  SLAP_BDB_ALLOW_DIRTY_READ
18 #endif
19
20 int
21 bdb_db_config(
22         BackendDB       *be,
23         const char      *fname,
24         int             lineno,
25         int             argc,
26         char    **argv )
27 {
28         struct bdb_info *bdb = (struct bdb_info *) be->be_private;
29
30         if ( bdb == NULL ) {
31                 fprintf( stderr, "%s: line %d: "
32                         "bdb database info is null!\n",
33                         fname, lineno );
34                 return 1;
35         }
36
37         /* directory is the DB_HOME */
38         if ( strcasecmp( argv[0], "directory" ) == 0 ) {
39                 if ( argc < 2 ) {
40                         fprintf( stderr, "%s: line %d: "
41                                 "missing dir in \"directory <dir>\" line\n",
42                                 fname, lineno );
43                         return 1;
44                 }
45                 if ( bdb->bi_dbenv_home ) {
46                         free( bdb->bi_dbenv_home );
47                 }
48                 bdb->bi_dbenv_home = ch_strdup( argv[1] );
49
50 #ifdef SLAP_BDB_ALLOW_DIRTY_READ
51         } else if ( strcasecmp( argv[0], "dirtyread" ) == 0 ) {
52                 bdb->bi_db_opflags |= DB_DIRTY_READ;
53 #endif
54         /* transaction logging configuration */
55         } else if ( strcasecmp( argv[0], "dbnosync" ) == 0 ) {
56                 bdb->bi_dbenv_xflags |= DB_TXN_NOSYNC;
57
58         /* transaction checkpoint configuration */
59         } else if ( strcasecmp( argv[0], "checkpoint" ) == 0 ) {
60                 if ( argc < 3 ) {
61                         fprintf( stderr, "%s: line %d: "
62                                 "missing parameters in \"checkpoint <kbyte> <min>\" line\n",
63                                 fname, lineno );
64                         return 1;
65                 }
66                 bdb->bi_txn_cp = 1;
67                 bdb->bi_txn_cp_kbyte = strtol( argv[1], NULL, 0 );
68                 bdb->bi_txn_cp_min = strtol( argv[2], NULL, 0 );
69
70         /* lock detect configuration */
71         } else if ( strcasecmp( argv[0], "lockdetect" ) == 0 ) {
72                 if ( argc < 2 ) {
73                         fprintf( stderr, "%s: line %d: "
74                                 "missing parameters in \"lockDetect <policy>\" line\n",
75                                 fname, lineno );
76                         return 1;
77                 }
78
79                 if( strcasecmp( argv[1], "default" ) == 0 ) {
80                         bdb->bi_lock_detect = DB_LOCK_DEFAULT;
81
82                 } else if( strcasecmp( argv[1], "oldest" ) == 0 ) {
83                         bdb->bi_lock_detect = DB_LOCK_OLDEST;
84
85                 } else if( strcasecmp( argv[1], "random" ) == 0 ) {
86                         bdb->bi_lock_detect = DB_LOCK_RANDOM;
87
88                 } else if( strcasecmp( argv[1], "youngest" ) == 0 ) {
89                         bdb->bi_lock_detect = DB_LOCK_YOUNGEST;
90
91                 } else if( strcasecmp( argv[1], "fewest" ) == 0 ) {
92                         bdb->bi_lock_detect = DB_LOCK_MINLOCKS;
93
94                 } else {
95                         fprintf( stderr, "%s: line %d: "
96                                 "bad policy (%s) in \"lockDetect <policy>\" line\n",
97                                 fname, lineno, argv[1] );
98                         return 1;
99                 }
100
101         /* mode with which to create new database files */
102         } else if ( strcasecmp( argv[0], "mode" ) == 0 ) {
103                 if ( argc < 2 ) {
104                         fprintf( stderr, "%s: line %d: "
105                                 "missing mode in \"mode <mode>\" line\n",
106                                 fname, lineno );
107                         return 1;
108                 }
109                 bdb->bi_dbenv_mode = strtol( argv[1], NULL, 0 );
110
111         /* attribute to index */
112         } else if ( strcasecmp( argv[0], "index" ) == 0 ) {
113                 int rc;
114                 if ( argc < 2 ) {
115                         fprintf( stderr, "%s: line %d: "
116                                 "missing attr in \"index <attr> [pres,eq,approx,sub]\" line\n",
117                                 fname, lineno );
118                         return 1;
119                 } else if ( argc > 3 ) {
120                         fprintf( stderr, "%s: line %d: "
121                                 "extra junk after \"index <attr> [pres,eq,approx,sub]\" "
122                                 "line (ignored)\n",
123                                 fname, lineno );
124                 }
125                 rc = bdb_attr_index_config( bdb, fname, lineno, argc - 1, &argv[1] );
126
127                 if( rc != LDAP_SUCCESS ) return 1;
128
129         /* unique key for shared memory regions */
130         } else if ( strcasecmp( argv[0], "shm_key" ) == 0 ) {
131                 if ( argc < 2 ) {
132                         fprintf( stderr,
133                                 "%s: line %d: missing key in \"shm_key <key>\" line\n",
134                                 fname, lineno );
135                         return( 1 );
136                 }
137                 bdb->bi_shm_key = atoi( argv[1] );
138
139         /* size of the cache in entries */
140         } else if ( strcasecmp( argv[0], "cachesize" ) == 0 ) {
141                 if ( argc < 2 ) {
142                         fprintf( stderr,
143                                 "%s: line %d: missing size in \"cachesize <size>\" line\n",
144                                 fname, lineno );
145                         return( 1 );
146                 }
147                 bdb->bi_cache.c_maxsize = atoi( argv[1] );
148
149         /* depth of search stack cache in units of (IDL)s */
150         } else if ( strcasecmp( argv[0], "searchstack" ) == 0 ) {
151                 if ( argc < 2 ) {
152                         fprintf( stderr,
153                                 "%s: line %d: missing depth in \"searchstack <depth>\" line\n",
154                                 fname, lineno );
155                         return( 1 );
156                 }
157                 bdb->bi_search_stack_depth = atoi( argv[1] );
158                 if ( bdb->bi_search_stack_depth < MINIMUM_SEARCH_STACK_DEPTH ) {
159                         fprintf( stderr,
160                 "%s: line %d: depth %d too small, using %d\n",
161                         fname, lineno, bdb->bi_search_stack_depth,
162                         MINIMUM_SEARCH_STACK_DEPTH );
163                         bdb->bi_search_stack_depth = MINIMUM_SEARCH_STACK_DEPTH;
164                 }
165
166 #ifdef SLAP_IDL_CACHE
167         /* size of the IDL cache in entries */
168         } else if ( strcasecmp( argv[0], "idlcachesize" ) == 0 ) {
169                 if ( argc < 2 ) {
170                         fprintf( stderr,
171                                 "%s: line %d: missing size in \"idlcachesize <size>\" line\n",
172                                 fname, lineno );
173                         return( 1 );
174                 }
175                 if ( !( slapMode & SLAP_TOOL_MODE ) )
176                         bdb->bi_idl_cache_max_size = atoi( argv[1] );
177 #endif
178
179         } else if ( strcasecmp( argv[0], "sessionlog" ) == 0 ) {
180                 int se_id = 0, se_size = 0;
181                 struct slap_session_entry *sent;
182                 if ( argc < 3 ) {
183 #ifdef NEW_LOGGING
184                         LDAP_LOG( CONFIG, CRIT,
185                                 "%s: line %d: missing arguments in \"sessionlog <id> <size>\""
186                                 " line.\n", fname, lineno , 0 );
187 #else
188                         Debug( LDAP_DEBUG_ANY,
189                                 "%s: line %d: missing arguments in \"sessionlog <id> <size>\""
190                                 " line\n", fname, lineno, 0 );
191 #endif
192                         return( 1 );
193                 }
194
195                 se_id = atoi( argv[1] );
196                 se_size = atoi( argv[2] );
197
198                 if ( se_id < 0 || se_id > 999 ) {
199 #ifdef NEW_LOGGING
200                         LDAP_LOG( CONFIG, CRIT,
201                                 "%s: line %d: session log id %d is out of range [0..999]\n",
202                                 fname, lineno , se_id );
203 #else
204                         Debug( LDAP_DEBUG_ANY,
205                                 "%s: line %d: session log id %d is out of range [0..999]\n",
206                                 fname, lineno , se_id );
207 #endif
208                         return( 1 );
209                 }
210
211                 if ( se_size < 0 || se_size > 999 ) {
212 #ifdef NEW_LOGGING
213                         LDAP_LOG( CONFIG, CRIT,
214                                 "%s: line %d: session log size %d is negative\n",
215                                 fname, lineno , se_size );
216 #else
217                         Debug( LDAP_DEBUG_ANY,
218                                 "%s: line %d: session log size %d is negative\n",
219                                 fname, lineno , se_size );
220 #endif
221                         return( 1 );
222                 }
223
224                 LDAP_LIST_FOREACH( sent, &bdb->bi_session_list, se_link ) {
225                         if ( sent->se_id == se_id ) {
226 #ifdef NEW_LOGGING
227                                 LDAP_LOG( CONFIG, CRIT,
228                                         "%s: line %d: session %d already exists\n",
229                                         fname, lineno , se_id );
230 #else
231                                 Debug( LDAP_DEBUG_ANY,
232                                         "%s: line %d: session %d already exists\n",
233                                         fname, lineno , se_id );
234 #endif
235                                 return( 1 );
236                         }
237                 }
238                 sent = (struct slap_session_entry *) ch_calloc( 1,
239                                                 sizeof( struct slap_session_entry ));
240                 sent->se_id = se_id;
241                 sent->se_size = se_size;
242                 LDAP_LIST_INSERT_HEAD( &bdb->bi_session_list, sent, se_link );
243
244         /* anything else */
245         } else {
246                 fprintf( stderr, "%s: line %d: "
247                         "unknown directive \"%s\" in bdb database definition (ignored)\n",
248                         fname, lineno, argv[0] );
249         }
250
251         return 0;
252 }