]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb/config.c
Added overlay objects
[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 #ifdef DB_DIRTY_READ
25 #       define  SLAP_BDB_ALLOW_DIRTY_READ
26 #endif
27
28 int
29 bdb_db_config(
30         BackendDB       *be,
31         const char      *fname,
32         int             lineno,
33         int             argc,
34         char    **argv )
35 {
36         struct bdb_info *bdb = (struct bdb_info *) be->be_private;
37
38         if ( bdb == NULL ) {
39                 fprintf( stderr, "%s: line %d: "
40                         "bdb database info is null!\n",
41                         fname, lineno );
42                 return 1;
43         }
44
45         /* directory is the DB_HOME */
46         if ( strcasecmp( argv[0], "directory" ) == 0 ) {
47                 if ( argc < 2 ) {
48                         fprintf( stderr, "%s: line %d: "
49                                 "missing dir in \"directory <dir>\" line\n",
50                                 fname, lineno );
51                         return 1;
52                 }
53                 if ( bdb->bi_dbenv_home ) {
54                         free( bdb->bi_dbenv_home );
55                 }
56                 bdb->bi_dbenv_home = ch_strdup( argv[1] );
57
58 #ifdef SLAP_BDB_ALLOW_DIRTY_READ
59         } else if ( strcasecmp( argv[0], "dirtyread" ) == 0 ) {
60                 bdb->bi_db_opflags |= DB_DIRTY_READ;
61 #endif
62         /* transaction logging configuration */
63         } else if ( strcasecmp( argv[0], "dbnosync" ) == 0 ) {
64                 bdb->bi_dbenv_xflags |= DB_TXN_NOSYNC;
65
66         /* slapindex algorithm tuning */
67         } else if ( strcasecmp( argv[0], "linearindex" ) == 0 ) {
68                 bdb->bi_linear_index = 1;
69
70         /* transaction checkpoint configuration */
71         } else if ( strcasecmp( argv[0], "checkpoint" ) == 0 ) {
72                 if ( argc < 3 ) {
73                         fprintf( stderr, "%s: line %d: "
74                                 "missing parameters in \"checkpoint <kbyte> <min>\" line\n",
75                                 fname, lineno );
76                         return 1;
77                 }
78                 bdb->bi_txn_cp = 1;
79                 bdb->bi_txn_cp_kbyte = strtol( argv[1], NULL, 0 );
80                 bdb->bi_txn_cp_min = strtol( argv[2], NULL, 0 );
81
82         /* lock detect configuration */
83         } else if ( strcasecmp( argv[0], "lockdetect" ) == 0 ) {
84                 if ( argc < 2 ) {
85                         fprintf( stderr, "%s: line %d: "
86                                 "missing parameters in \"lockDetect <policy>\" line\n",
87                                 fname, lineno );
88                         return 1;
89                 }
90
91                 if( strcasecmp( argv[1], "default" ) == 0 ) {
92                         bdb->bi_lock_detect = DB_LOCK_DEFAULT;
93
94                 } else if( strcasecmp( argv[1], "oldest" ) == 0 ) {
95                         bdb->bi_lock_detect = DB_LOCK_OLDEST;
96
97                 } else if( strcasecmp( argv[1], "random" ) == 0 ) {
98                         bdb->bi_lock_detect = DB_LOCK_RANDOM;
99
100                 } else if( strcasecmp( argv[1], "youngest" ) == 0 ) {
101                         bdb->bi_lock_detect = DB_LOCK_YOUNGEST;
102
103                 } else if( strcasecmp( argv[1], "fewest" ) == 0 ) {
104                         bdb->bi_lock_detect = DB_LOCK_MINLOCKS;
105
106                 } else {
107                         fprintf( stderr, "%s: line %d: "
108                                 "bad policy (%s) in \"lockDetect <policy>\" line\n",
109                                 fname, lineno, argv[1] );
110                         return 1;
111                 }
112
113         /* mode with which to create new database files */
114         } else if ( strcasecmp( argv[0], "mode" ) == 0 ) {
115                 if ( argc < 2 ) {
116                         fprintf( stderr, "%s: line %d: "
117                                 "missing mode in \"mode <mode>\" line\n",
118                                 fname, lineno );
119                         return 1;
120                 }
121                 bdb->bi_dbenv_mode = strtol( argv[1], NULL, 0 );
122
123         /* attribute to index */
124         } else if ( strcasecmp( argv[0], "index" ) == 0 ) {
125                 int rc;
126                 if ( argc < 2 ) {
127                         fprintf( stderr, "%s: line %d: "
128                                 "missing attr in \"index <attr> [pres,eq,approx,sub]\" line\n",
129                                 fname, lineno );
130                         return 1;
131                 } else if ( argc > 3 ) {
132                         fprintf( stderr, "%s: line %d: "
133                                 "extra junk after \"index <attr> [pres,eq,approx,sub]\" "
134                                 "line (ignored)\n",
135                                 fname, lineno );
136                 }
137                 rc = bdb_attr_index_config( bdb, fname, lineno, argc - 1, &argv[1] );
138
139                 if( rc != LDAP_SUCCESS ) return 1;
140
141         /* unique key for shared memory regions */
142         } else if ( strcasecmp( argv[0], "shm_key" ) == 0 ) {
143                 if ( argc < 2 ) {
144                         fprintf( stderr,
145                                 "%s: line %d: missing key in \"shm_key <key>\" line\n",
146                                 fname, lineno );
147                         return( 1 );
148                 }
149                 bdb->bi_shm_key = atoi( argv[1] );
150
151         /* size of the cache in entries */
152         } else if ( strcasecmp( argv[0], "cachesize" ) == 0 ) {
153                 if ( argc < 2 ) {
154                         fprintf( stderr,
155                                 "%s: line %d: missing size in \"cachesize <size>\" line\n",
156                                 fname, lineno );
157                         return( 1 );
158                 }
159                 bdb->bi_cache.c_maxsize = atoi( argv[1] );
160
161         /* depth of search stack cache in units of (IDL)s */
162         } else if ( strcasecmp( argv[0], "searchstack" ) == 0 ) {
163                 if ( argc < 2 ) {
164                         fprintf( stderr,
165                                 "%s: line %d: missing depth in \"searchstack <depth>\" line\n",
166                                 fname, lineno );
167                         return( 1 );
168                 }
169                 bdb->bi_search_stack_depth = atoi( argv[1] );
170                 if ( bdb->bi_search_stack_depth < MINIMUM_SEARCH_STACK_DEPTH ) {
171                         fprintf( stderr,
172                 "%s: line %d: depth %d too small, using %d\n",
173                         fname, lineno, bdb->bi_search_stack_depth,
174                         MINIMUM_SEARCH_STACK_DEPTH );
175                         bdb->bi_search_stack_depth = MINIMUM_SEARCH_STACK_DEPTH;
176                 }
177
178         /* size of the IDL cache in entries */
179         } else if ( strcasecmp( argv[0], "idlcachesize" ) == 0 ) {
180                 if ( argc < 2 ) {
181                         fprintf( stderr,
182                                 "%s: line %d: missing size in \"idlcachesize <size>\" line\n",
183                                 fname, lineno );
184                         return( 1 );
185                 }
186                 if ( !( slapMode & SLAP_TOOL_MODE ) )
187                         bdb->bi_idl_cache_max_size = atoi( argv[1] );
188
189         /* anything else */
190         } else {
191                 return SLAP_CONF_UNKNOWN;
192         }
193
194         return 0;
195 }