]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb/config.c
Happy new year
[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 #ifdef SLAP_IDL_CACHE
176         /* size of the IDL cache in entries */
177         } else if ( strcasecmp( argv[0], "idlcachesize" ) == 0 ) {
178                 if ( argc < 2 ) {
179                         fprintf( stderr,
180                                 "%s: line %d: missing size in \"idlcachesize <size>\" line\n",
181                                 fname, lineno );
182                         return( 1 );
183                 }
184                 if ( !( slapMode & SLAP_TOOL_MODE ) )
185                         bdb->bi_idl_cache_max_size = atoi( argv[1] );
186 #endif
187
188         } else if ( strcasecmp( argv[0], "sessionlog" ) == 0 ) {
189                 int se_id = 0, se_size = 0;
190                 struct slap_session_entry *sent;
191                 if ( argc < 3 ) {
192 #ifdef NEW_LOGGING
193                         LDAP_LOG( CONFIG, CRIT,
194                                 "%s: line %d: missing arguments in \"sessionlog <id> <size>\""
195                                 " line.\n", fname, lineno , 0 );
196 #else
197                         Debug( LDAP_DEBUG_ANY,
198                                 "%s: line %d: missing arguments in \"sessionlog <id> <size>\""
199                                 " line\n", fname, lineno, 0 );
200 #endif
201                         return( 1 );
202                 }
203
204                 se_id = atoi( argv[1] );
205                 se_size = atoi( argv[2] );
206
207                 if ( se_id < 0 || se_id > 999 ) {
208 #ifdef NEW_LOGGING
209                         LDAP_LOG( CONFIG, CRIT,
210                                 "%s: line %d: session log id %d is out of range [0..999]\n",
211                                 fname, lineno , se_id );
212 #else
213                         Debug( LDAP_DEBUG_ANY,
214                                 "%s: line %d: session log id %d is out of range [0..999]\n",
215                                 fname, lineno , se_id );
216 #endif
217                         return( 1 );
218                 }
219
220                 if ( se_size < 0 || se_size > 999 ) {
221 #ifdef NEW_LOGGING
222                         LDAP_LOG( CONFIG, CRIT,
223                                 "%s: line %d: session log size %d is negative\n",
224                                 fname, lineno , se_size );
225 #else
226                         Debug( LDAP_DEBUG_ANY,
227                                 "%s: line %d: session log size %d is negative\n",
228                                 fname, lineno , se_size );
229 #endif
230                         return( 1 );
231                 }
232
233                 LDAP_LIST_FOREACH( sent, &bdb->bi_session_list, se_link ) {
234                         if ( sent->se_id == se_id ) {
235 #ifdef NEW_LOGGING
236                                 LDAP_LOG( CONFIG, CRIT,
237                                         "%s: line %d: session %d already exists\n",
238                                         fname, lineno , se_id );
239 #else
240                                 Debug( LDAP_DEBUG_ANY,
241                                         "%s: line %d: session %d already exists\n",
242                                         fname, lineno , se_id );
243 #endif
244                                 return( 1 );
245                         }
246                 }
247                 sent = (struct slap_session_entry *) ch_calloc( 1,
248                                                 sizeof( struct slap_session_entry ));
249                 sent->se_id = se_id;
250                 sent->se_size = se_size;
251                 LDAP_LIST_INSERT_HEAD( &bdb->bi_session_list, sent, se_link );
252
253         /* anything else */
254         } else {
255                 return SLAP_CONF_UNKNOWN;
256         }
257
258         return 0;
259 }