]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldbm/config.c
3c8475024e5621e81739513579404b4ef4e2c1ca
[openldap] / servers / slapd / back-ldbm / config.c
1 /* config.c - ldbm backend configuration file routine */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-2002 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
12 #include <ac/socket.h>
13 #include <ac/string.h>
14
15 #include "slap.h"
16 #include "back-ldbm.h"
17
18 int
19 ldbm_back_db_config(
20     Backend     *be,
21     const char  *fname,
22     int         lineno,
23     int         argc,
24     char        **argv
25 )
26 {
27         int rc;
28         struct ldbminfo *li = (struct ldbminfo *) be->be_private;
29
30         if ( li == NULL ) {
31                 fprintf( stderr, "%s: line %d: ldbm database info is null!\n",
32                     fname, lineno );
33                 return( 1 );
34         }
35
36         /* directory where database files live */
37         if ( strcasecmp( argv[0], "directory" ) == 0 ) {
38                 if ( argc < 2 ) {
39                         fprintf( stderr,
40                 "%s: line %d: missing dir in \"directory <dir>\" line\n",
41                             fname, lineno );
42                         return( 1 );
43                 }
44                 if ( li->li_directory )
45                         free( li->li_directory );
46                 li->li_directory = ch_strdup( argv[1] );
47
48         /* mode with which to create new database files */
49         } else if ( strcasecmp( argv[0], "mode" ) == 0 ) {
50                 if ( argc < 2 ) {
51                         fprintf( stderr,
52                         "%s: line %d: missing mode in \"mode <mode>\" line\n",
53                             fname, lineno );
54                         return( 1 );
55                 }
56                 li->li_mode = strtol( argv[1], NULL, 0 );
57
58         /* attribute to index */
59         } else if ( strcasecmp( argv[0], "index" ) == 0 ) {
60                 if ( argc < 2 ) {
61                         fprintf( stderr,
62 "%s: line %d: missing attr in \"index <attr> [pres,eq,approx,sub]\" line\n",
63                             fname, lineno );
64                         return( 1 );
65                 } else if ( argc > 3 ) {
66                         fprintf( stderr,
67 "%s: line %d: extra junk after \"index <attr> [pres,eq,approx,sub]\" line (ignored)\n",
68                             fname, lineno );
69                 }
70                 rc = attr_index_config( li, fname, lineno, argc - 1, &argv[1] );
71
72                 if( rc != LDAP_SUCCESS ) return 1;
73
74         /* size of the cache in entries */
75         } else if ( strcasecmp( argv[0], "cachesize" ) == 0 ) {
76                 if ( argc < 2 ) {
77                         fprintf( stderr,
78                 "%s: line %d: missing size in \"cachesize <size>\" line\n",
79                             fname, lineno );
80                         return( 1 );
81                 }
82                 li->li_cache.c_maxsize = atoi( argv[1] );
83
84         /* size of each dbcache in bytes */
85         } else if ( strcasecmp( argv[0], "dbcachesize" ) == 0 ) {
86                 if ( argc < 2 ) {
87                         fprintf( stderr,
88                 "%s: line %d: missing size in \"dbcachesize <size>\" line\n",
89                             fname, lineno );
90                         return( 1 );
91                 }
92                 li->li_dbcachesize = atoi( argv[1] );
93
94         /* no locking (not safe) */
95         } else if ( strcasecmp( argv[0], "dbnolocking" ) == 0 ) {
96                 li->li_dblocking = 0;
97
98         /* no write sync (not safe) */
99         } else if ( ( strcasecmp( argv[0], "dbnosync" ) == 0 )
100                 || ( strcasecmp( argv[0], "dbcachenowsync" ) == 0 ) )
101         {
102                 li->li_dbwritesync = 0;
103
104         /* run sync thread */
105         } else if ( strcasecmp( argv[0], "dbsync" ) == 0 ) {
106 #ifndef NO_THREADS
107                 int i;
108                 if ( argc < 2 ) {
109 #ifdef NEW_LOGGING
110                         LDAP_LOG (( "config", LDAP_LEVEL_ERR, "ldbm_back_db_config: %s: "
111                                 "line %d: missing frequency value in \"dbsync <frequency> "
112                                 "[<wait-times> [wait-interval]]\" line\n", fname, lineno ));
113 #else   
114                         Debug( LDAP_DEBUG_ANY,
115     "%s: line %d: missing frquency value in \"dbsync <frequency> [<wait-times> [wait-interval]]\" line\n",
116                             fname, lineno, 0 );
117 #endif
118                         return 1;
119                 }
120
121                 i = atoi( argv[1] );
122
123                 if( i < 0 ) {
124 #ifdef NEW_LOGGING
125                         LDAP_LOG (( "config", LDAP_LEVEL_ERR, "ldbm_back_db_config: %s: "
126                                 "line %d: frequency value (%d) invalid \"dbsync "
127                                 "<frequency> [<wait-times> [wait-interval]]\" line\n", 
128                                 fname, lineno, i ));
129 #else   
130                         Debug( LDAP_DEBUG_ANY,
131     "%s: line %d: frquency value (%d) invalid \"dbsync <frequency> [<wait-times> [wait-interval]]\" line\n",
132                             fname, lineno, i );
133 #endif
134                         return 1;
135                 }
136
137                 li->li_dbsyncfreq = i;
138
139                 if ( argc > 2 ) {
140                         i = atoi( argv[2] );
141                         if ( i < 0 ) {
142 #ifdef NEW_LOGGING
143                                 LDAP_LOG (( "config",LDAP_LEVEL_ERR, "ldbm_back_db_config: %s: "
144                                         "line %d: frequency value (%d) invalid \"dbsync "
145                                         "<frequency> [<wait-times> [wait-interval]]\" line\n", 
146                                         fname, lineno, i ));
147 #else   
148                                 Debug( LDAP_DEBUG_ANY,
149             "%s: line %d: frquency value (%d) invalid \"dbsync <frequency> [<wait-times> [wait-interval]]\" line\n",
150                                     fname, lineno, i );
151 #endif
152                                 return 1;
153                         }
154                         li ->li_dbsyncwaitn = i;
155                 }
156
157                 if ( argc > 3 ) {
158                         i = atoi( argv[3] );
159                         if ( i <= 0 ) {
160 #ifdef NEW_LOGGING
161                                 LDAP_LOG (( "config",LDAP_LEVEL_ERR, "ldbm_back_db_config: %s: "
162                                         "line %d: frequency value (%d) invalid \"dbsync "
163                                         "<frequency> [<wait-times> [wait-interval]]\" line\n", 
164                                         fname, lineno, i ));
165 #else   
166                                 Debug( LDAP_DEBUG_ANY,
167             "%s: line %d: frquency value (%d) invalid \"dbsync <frequency> [<wait-times> [wait-interval]]\" line\n",
168                                     fname, lineno, i );
169 #endif
170                                 return 1;
171                         }
172                         li ->li_dbsyncwaitinterval = i;
173                 }
174
175                 /* turn off writesync when sync policy is in place */
176                 li->li_dbwritesync = 0;
177
178 #else
179 #ifdef NEW_LOGGING
180                 LDAP_LOG (( "config",LDAP_LEVEL_ERR, "ldbm_back_db_config: "\"dbsync\""
181                         " policies not supported in non-threaded environments\n" ));
182 #else   
183                 Debug( LDAP_DEBUG_ANY,
184     "\"dbsync\" policies not supported in non-threaded environments\n", 0, 0, 0);
185 #endif
186                 return 1;
187 #endif
188
189
190         /* anything else */
191         } else {
192                 fprintf( stderr,
193 "%s: line %d: unknown directive \"%s\" in ldbm database definition (ignored)\n",
194                     fname, lineno, argv[0] );
195         }
196
197         return 0;
198 }