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