]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb2/config.c
Add OpenLDAP RCSid to *.[ch] in clients, libraries, and servers.
[openldap] / servers / slapd / back-bdb2 / config.c
1 /* config.c - bdb2 backend configuration file routine */
2 /* $OpenLDAP$ */
3
4 #include "portable.h"
5
6 #include <stdio.h>
7
8 #include <ac/socket.h>
9 #include <ac/string.h>
10
11 #include "slap.h"
12 #include "back-bdb2.h"
13
14 static int
15 bdb2i_back_config_internal(
16     BackendInfo *bi,
17     const char          *fname,
18     int                 lineno,
19     int                 argc,
20     char                **argv
21 )
22 {
23         struct ldbtype  *lty = (struct ldbtype *) bi->bi_private;
24
25         if ( lty == NULL ) {
26                 fprintf( stderr, "%s: line %d: ldbm backend type info is null!\n",
27                     fname, lineno );
28                 return( 1 );
29         }
30
31         /* directory where DB control files live */
32         if ( strcasecmp( argv[0], "home" ) == 0 ) {
33                 if ( argc < 2 ) {
34                         fprintf( stderr,
35                 "%s: line %d: missing dir in \"home <dir>\" line\n",
36                             fname, lineno );
37                         return( 1 );
38                 }
39                 lty->lty_dbhome = ch_strdup( argv[1] );
40
41         /* size of the DB memory pool */
42         } else if ( strcasecmp( argv[0], "mpoolsize" ) == 0 ) {
43                 if ( argc < 2 ) {
44                         fprintf( stderr,
45                         "%s: line %d: missing size in \"mpoolsize <size>\" line\n",
46                             fname, lineno );
47                         return( 1 );
48                 }
49                 lty->lty_mpsize = (size_t) atoi( argv[1] );
50                 /*  we should at least have the suggested 128k  */
51                 if ( lty->lty_mpsize < DEFAULT_DBCACHE_SIZE )
52                         lty->lty_mpsize = DEFAULT_DBCACHE_SIZE;
53
54         /* anything else */
55         } else {
56                 fprintf( stderr,
57 "%s: line %d: unknown directive \"%s\" in ldbm backend definition (ignored)\n",
58                     fname, lineno, argv[0] );
59         }
60
61         return 0;
62 }
63
64
65 int
66 bdb2_back_config(
67     BackendInfo *bi,
68     const char  *fname,
69     int         lineno,
70     int         argc,
71     char        **argv
72 )
73 {
74         struct timeval  time1;
75         int             ret;
76
77         bdb2i_start_timing( bi, &time1 );
78
79         ret = bdb2i_back_config_internal( bi, fname, lineno, argc, argv );
80         bdb2i_stop_timing( bi, time1, "BE-CONFIG", NULL, NULL );
81
82         return( ret );
83 }
84
85
86 static int
87 bdb2i_back_db_config_internal(
88     BackendDB   *be,
89     const char  *fname,
90     int         lineno,
91     int         argc,
92     char        **argv
93 )
94 {
95         struct ldbminfo *li = (struct ldbminfo *) be->be_private;
96
97         if ( li == NULL ) {
98                 fprintf( stderr, "%s: line %d: ldbm database info is null!\n",
99                     fname, lineno );
100                 return( 1 );
101         }
102
103         /* directory where database files live */
104         if ( strcasecmp( argv[0], "directory" ) == 0 ) {
105                 if ( argc < 2 ) {
106                         fprintf( stderr,
107                 "%s: line %d: missing dir in \"directory <dir>\" line\n",
108                             fname, lineno );
109                         return( 1 );
110                 }
111                 li->li_directory = ch_strdup( argv[1] );
112
113                 li->li_nextid_file =
114                         ch_malloc( strlen(li->li_directory) + sizeof("/NEXTID") + 1 );
115
116                 strcpy(li->li_nextid_file, li->li_directory);
117                 strcat(li->li_nextid_file, "/NEXTID");
118
119         /* mode with which to create new database files */
120         } else if ( strcasecmp( argv[0], "mode" ) == 0 ) {
121                 if ( argc < 2 ) {
122                         fprintf( stderr,
123                         "%s: line %d: missing mode in \"mode <mode>\" line\n",
124                             fname, lineno );
125                         return( 1 );
126                 }
127                 li->li_mode = strtol( argv[1], NULL, 0 );
128
129         /* attribute to index */
130         } else if ( strcasecmp( argv[0], "index" ) == 0 ) {
131                 if ( argc < 2 ) {
132                         fprintf( stderr,
133 "%s: line %d: missing attr in \"index <attr> [pres,eq,approx,sub]\" line\n",
134                             fname, lineno );
135                         return( 1 );
136                 } else if ( argc > 3 ) {
137                         fprintf( stderr,
138 "%s: line %d: extra junk after \"index <attr> [pres,eq,approx,sub]\" line (ignored)\n",
139                             fname, lineno );
140                 }
141                 bdb2i_attr_index_config( li, fname, lineno, argc - 1, &argv[1], 0 );
142
143         /* size of the cache in entries */
144         } else if ( strcasecmp( argv[0], "cachesize" ) == 0 ) {
145                 if ( argc < 2 ) {
146                         fprintf( stderr,
147                 "%s: line %d: missing size in \"cachesize <size>\" line\n",
148                             fname, lineno );
149                         return( 1 );
150                 }
151                 li->li_cache.c_maxsize = atoi( argv[1] );
152
153         /* size of each dbcache in bytes */
154         } else if ( strcasecmp( argv[0], "dbcachesize" ) == 0 ) {
155                 if ( argc < 2 ) {
156                         fprintf( stderr,
157                 "%s: line %d: missing size in \"dbcachesize <size>\" line\n",
158                             fname, lineno );
159                         return( 1 );
160                 }
161                 li->li_dbcachesize = atoi( argv[1] );
162                 /*  we should at least have the suggested 128k  */
163                 if ( li->li_dbcachesize < DEFAULT_DBCACHE_SIZE )
164                         li->li_dbcachesize = DEFAULT_DBCACHE_SIZE;
165
166         /* no write sync */
167         } else if ( strcasecmp( argv[0], "dbcachenowsync" ) == 0 ) {
168                 li->li_dbcachewsync = 0;
169
170         /* anything else */
171         } else {
172                 fprintf( stderr,
173 "%s: line %d: unknown directive \"%s\" in ldbm database definition (ignored)\n",
174                     fname, lineno, argv[0] );
175         }
176
177         return 0;
178 }
179
180
181 int
182 bdb2_back_db_config(
183     BackendDB   *be,
184     const char  *fname,
185     int         lineno,
186     int         argc,
187     char        **argv
188 )
189 {
190         struct timeval  time1;
191         int             ret;
192
193         bdb2i_start_timing( be->bd_info, &time1 );
194
195         ret = bdb2i_back_db_config_internal( be, fname, lineno, argc, argv );
196
197         bdb2i_stop_timing( be->bd_info, time1, "DB-CONFIG", NULL, NULL );
198
199         return( ret );
200 }
201
202