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