]> git.sur5r.net Git - openldap/blob - servers/slapd/config.c
Never let ldif_parse_line() return a NULL value with success.
[openldap] / servers / slapd / config.c
1 /* config.c - configuration file handling routines */
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/string.h>
13 #include <ac/ctype.h>
14 #include <ac/signal.h>
15 #include <ac/socket.h>
16 #include <ac/errno.h>
17
18 #include "lutil.h"
19 #include "ldap_pvt.h"
20 #include "slap.h"
21
22 #define ARGS_STEP       512
23
24 /*
25  * defaults for various global variables
26  */
27 struct slap_limits_set deflimit = {
28         SLAPD_DEFAULT_TIMELIMIT,        /* backward compatible limits */
29         0,
30
31         SLAPD_DEFAULT_SIZELIMIT,        /* backward compatible limits */
32         0,
33         -1,                             /* no limit on unchecked size */
34         0,                              /* page limit */
35         0                               /* hide number of entries left */
36 };
37
38 AccessControl   *global_acl = NULL;
39 slap_access_t           global_default_access = ACL_READ;
40 slap_mask_t             global_restrictops = 0;
41 slap_mask_t             global_allows = 0;
42 slap_mask_t             global_disallows = 0;
43 slap_mask_t             global_requires = 0;
44 slap_ssf_set_t  global_ssf_set;
45 char            *replogfile;
46 int             global_gentlehup = 0;
47 int             global_idletimeout = 0;
48 char    *global_host = NULL;
49 char    *global_realm = NULL;
50 char            *ldap_srvtab = "";
51 char            *default_passwd_hash = NULL;
52 int             cargc = 0, cargv_size = 0;
53 char    **cargv;
54 struct berval default_search_base = { 0, NULL };
55 struct berval default_search_nbase = { 0, NULL };
56 unsigned                num_subordinates = 0;
57 struct berval global_schemadn = { 0, NULL };
58 struct berval global_schemandn = { 0, NULL };
59
60 ber_len_t sockbuf_max_incoming = SLAP_SB_MAX_INCOMING_DEFAULT;
61 ber_len_t sockbuf_max_incoming_auth= SLAP_SB_MAX_INCOMING_AUTH;
62
63 char   *slapd_pid_file  = NULL;
64 char   *slapd_args_file = NULL;
65
66 char   *strtok_quote_ptr;
67
68 #ifdef SLAPD_RLOOKUPS
69 int use_reverse_lookup = 1;
70 #else /* !SLAPD_RLOOKUPS */
71 int use_reverse_lookup = 0;
72 #endif /* !SLAPD_RLOOKUPS */
73
74 static char     *fp_getline(FILE *fp, int *lineno);
75 static void     fp_getline_init(int *lineno);
76 static int      fp_parse_line(int lineno, char *line);
77
78 static char     *strtok_quote(char *line, char *sep);
79 static int      load_ucdata(char *path);
80
81 int
82 read_config( const char *fname, int depth )
83 {
84         FILE    *fp;
85         char    *line, *savefname, *saveline;
86         int savelineno;
87         int     lineno, i;
88         int rc;
89         struct berval vals[2];
90
91         static int lastmod = 1;
92         static BackendInfo *bi = NULL;
93         static BackendDB        *be = NULL;
94
95         vals[1].bv_val = NULL;
96
97         if ( depth == 0 ) {
98                 cargv = ch_calloc( ARGS_STEP + 1, sizeof(*cargv) );
99                 cargv_size = ARGS_STEP + 1;
100         }
101
102         if ( (fp = fopen( fname, "r" )) == NULL ) {
103                 ldap_syslog = 1;
104 #ifdef NEW_LOGGING
105                 LDAP_LOG( CONFIG, ENTRY, 
106                         "read_config: " "could not open config file \"%s\": %s (%d)\n",
107                     fname, strerror(errno), errno );
108 #else
109                 Debug( LDAP_DEBUG_ANY,
110                     "could not open config file \"%s\": %s (%d)\n",
111                     fname, strerror(errno), errno );
112 #endif
113                 return 1;
114         }
115
116 #ifdef NEW_LOGGING
117         LDAP_LOG( CONFIG, ENTRY, 
118                 "read_config: reading config file %s\n", fname, 0, 0 );
119 #else
120         Debug( LDAP_DEBUG_CONFIG, "reading config file %s\n", fname, 0, 0 );
121 #endif
122
123
124         fp_getline_init( &lineno );
125
126         while ( (line = fp_getline( fp, &lineno )) != NULL ) {
127                 /* skip comments and blank lines */
128                 if ( line[0] == '#' || line[0] == '\0' ) {
129                         continue;
130                 }
131
132                 /* fp_parse_line is destructive, we save a copy */
133                 saveline = ch_strdup( line );
134
135                 if ( fp_parse_line( lineno, line ) != 0 ) {
136                         return( 1 );
137                 }
138
139                 if ( cargc < 1 ) {
140 #ifdef NEW_LOGGING
141                         LDAP_LOG( CONFIG, INFO, 
142                                 "%s: line %d: bad config line (ignored)\n", fname, lineno, 0 );
143 #else
144                         Debug( LDAP_DEBUG_ANY,
145                             "%s: line %d: bad config line (ignored)\n",
146                             fname, lineno, 0 );
147 #endif
148
149                         continue;
150                 }
151
152                 if ( strcasecmp( cargv[0], "backend" ) == 0 ) {
153                         if ( cargc < 2 ) {
154 #ifdef NEW_LOGGING
155                                 LDAP_LOG( CONFIG, CRIT, 
156                                            "%s : line %d: missing type in \"backend\" line.\n",
157                                            fname, lineno, 0 );
158 #else
159                                 Debug( LDAP_DEBUG_ANY,
160                 "%s: line %d: missing type in \"backend <type>\" line\n",
161                                     fname, lineno, 0 );
162 #endif
163
164                                 return( 1 );
165                         }
166
167                         if( be != NULL ) {
168 #ifdef NEW_LOGGING
169                                 LDAP_LOG( CONFIG, CRIT, 
170                                            "%s: line %d: backend line must appear before any "
171                                            "database definition.\n", fname, lineno , 0 );
172 #else
173                                 Debug( LDAP_DEBUG_ANY,
174 "%s: line %d: backend line must appear before any database definition\n",
175                                     fname, lineno, 0 );
176 #endif
177
178                                 return( 1 );
179                         }
180
181                         bi = backend_info( cargv[1] );
182
183                         if( bi == NULL ) {
184 #ifdef NEW_LOGGING
185                                 LDAP_LOG( CONFIG, CRIT, 
186                                            "read_config: backend %s initialization failed.\n",
187                                            cargv[1], 0, 0 );
188 #else
189                                 Debug( LDAP_DEBUG_ANY,
190                                         "backend %s initialization failed.\n",
191                                     cargv[1], 0, 0 );
192 #endif
193
194                                 return( 1 );
195                         }
196                 } else if ( strcasecmp( cargv[0], "database" ) == 0 ) {
197                         if ( cargc < 2 ) {
198 #ifdef NEW_LOGGING
199                                 LDAP_LOG( CONFIG, CRIT, 
200                                         "%s: line %d: missing type in \"database <type>\" line\n",
201                                         fname, lineno, 0 );
202 #else
203                                 Debug( LDAP_DEBUG_ANY,
204                 "%s: line %d: missing type in \"database <type>\" line\n",
205                                     fname, lineno, 0 );
206 #endif
207
208                                 return( 1 );
209                         }
210
211                         bi = NULL;
212                         be = backend_db_init( cargv[1] );
213
214                         if( be == NULL ) {
215 #ifdef NEW_LOGGING
216                                 LDAP_LOG( CONFIG, CRIT, 
217                                         "database %s initialization failed.\n", cargv[1], 0, 0 );
218 #else
219                                 Debug( LDAP_DEBUG_ANY,
220                                         "database %s initialization failed.\n",
221                                     cargv[1], 0, 0 );
222 #endif
223
224                                 return( 1 );
225                         }
226
227                 /* set thread concurrency */
228                 } else if ( strcasecmp( cargv[0], "concurrency" ) == 0 ) {
229                         int c;
230                         if ( cargc < 2 ) {
231 #ifdef NEW_LOGGING
232                                 LDAP_LOG( CONFIG, CRIT, 
233                                         "%s: line %d: missing level in \"concurrency <level\" "
234                                         " line\n", fname, lineno, 0 );
235 #else
236                                 Debug( LDAP_DEBUG_ANY,
237             "%s: line %d: missing level in \"concurrency <level>\" line\n",
238                                     fname, lineno, 0 );
239 #endif
240
241                                 return( 1 );
242                         }
243
244                         c = atoi( cargv[1] );
245
246                         if( c < 1 ) {
247 #ifdef NEW_LOGGING
248                                 LDAP_LOG( CONFIG, CRIT, 
249                                         "%s: line %d: invalid level (%d) in "
250                                         "\"concurrency <level>\" line.\n", fname, lineno, c );
251 #else
252                                 Debug( LDAP_DEBUG_ANY,
253             "%s: line %d: invalid level (%d) in \"concurrency <level>\" line\n",
254                                     fname, lineno, c );
255 #endif
256
257                                 return( 1 );
258                         }
259
260                         ldap_pvt_thread_set_concurrency( c );
261
262                 /* set sockbuf max */
263                 } else if ( strcasecmp( cargv[0], "sockbuf_max_incoming" ) == 0 ) {
264                         long max;
265                         if ( cargc < 2 ) {
266 #ifdef NEW_LOGGING
267                                 LDAP_LOG( CONFIG, CRIT, 
268                                    "%s: line %d: missing max in \"sockbuf_max_incoming "
269                                    "<bytes>\" line\n", fname, lineno, 0 );
270 #else
271                                 Debug( LDAP_DEBUG_ANY,
272                                            "%s: line %d: missing max in \"sockbuf_max_incoming <bytes>\" line\n",
273                                     fname, lineno, 0 );
274 #endif
275
276                                 return( 1 );
277                         }
278
279                         max = atol( cargv[1] );
280
281                         if( max < 0 ) {
282 #ifdef NEW_LOGGING
283                                 LDAP_LOG( CONFIG, CRIT, 
284                                            "%s: line %d: invalid max value (%ld) in "
285                                            "\"sockbuf_max_incoming <bytes>\" line.\n",
286                                            fname, lineno, max );
287 #else
288                                 Debug( LDAP_DEBUG_ANY,
289                                         "%s: line %d: invalid max value (%ld) in "
290                                         "\"sockbuf_max_incoming <bytes>\" line.\n",
291                                     fname, lineno, max );
292 #endif
293
294                                 return( 1 );
295                         }
296
297                         sockbuf_max_incoming = max;
298
299                 /* set sockbuf max authenticated */
300                 } else if ( strcasecmp( cargv[0], "sockbuf_max_incoming_auth" ) == 0 ) {
301                         long max;
302                         if ( cargc < 2 ) {
303 #ifdef NEW_LOGGING
304                                 LDAP_LOG( CONFIG, CRIT, 
305                                    "%s: line %d: missing max in \"sockbuf_max_incoming_auth "
306                                    "<bytes>\" line\n", fname, lineno, 0 );
307 #else
308                                 Debug( LDAP_DEBUG_ANY,
309                                            "%s: line %d: missing max in \"sockbuf_max_incoming_auth <bytes>\" line\n",
310                                     fname, lineno, 0 );
311 #endif
312
313                                 return( 1 );
314                         }
315
316                         max = atol( cargv[1] );
317
318                         if( max < 0 ) {
319 #ifdef NEW_LOGGING
320                                 LDAP_LOG( CONFIG, CRIT, 
321                                            "%s: line %d: invalid max value (%ld) in "
322                                            "\"sockbuf_max_incoming_auth <bytes>\" line.\n",
323                                            fname, lineno, max );
324 #else
325                                 Debug( LDAP_DEBUG_ANY,
326                                         "%s: line %d: invalid max value (%ld) in "
327                                         "\"sockbuf_max_incoming_auth <bytes>\" line.\n",
328                                     fname, lineno, max );
329 #endif
330
331                                 return( 1 );
332                         }
333
334                         sockbuf_max_incoming_auth = max;
335
336                 /* default search base */
337                 } else if ( strcasecmp( cargv[0], "defaultSearchBase" ) == 0 ) {
338                         if ( cargc < 2 ) {
339 #ifdef NEW_LOGGING
340                                 LDAP_LOG( CONFIG, CRIT, 
341                                         "%s: line %d: missing dn in \"defaultSearchBase <dn\" "
342                                         "line\n", fname, lineno, 0 );
343 #else
344                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
345                                         "missing dn in \"defaultSearchBase <dn>\" line\n",
346                                         fname, lineno, 0 );
347 #endif
348
349                                 return 1;
350
351                         } else if ( cargc > 2 ) {
352 #ifdef NEW_LOGGING
353                                 LDAP_LOG( CONFIG, INFO, 
354                                         "%s: line %d: extra cruft after <dn> in "
355                                         "\"defaultSearchBase %s\" line (ignored)\n",
356                                         fname, lineno, cargv[1] );
357 #else
358                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
359                                         "extra cruft after <dn> in \"defaultSearchBase %s\", "
360                                         "line (ignored)\n",
361                                         fname, lineno, cargv[1] );
362 #endif
363                         }
364
365                         if ( bi != NULL || be != NULL ) {
366 #ifdef NEW_LOGGING
367                                 LDAP_LOG( CONFIG, CRIT, 
368                                         "%s: line %d: defaultSearchBase line must appear "
369                                         "prior to any backend or database definitions\n",
370                                         fname, lineno, 0 );
371 #else
372                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
373                                         "defaultSearchBaase line must appear prior to "
374                                         "any backend or database definition\n",
375                                     fname, lineno, 0 );
376 #endif
377
378                                 return 1;
379                         }
380
381                         if ( default_search_nbase.bv_len ) {
382 #ifdef NEW_LOGGING
383                                 LDAP_LOG( CONFIG, INFO, "%s: line %d: "
384                                         "default search base \"%s\" already defined "
385                                         "(discarding old)\n", fname, lineno,
386                                         default_search_base.bv_val );
387 #else
388                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
389                                         "default search base \"%s\" already defined "
390                                         "(discarding old)\n",
391                                         fname, lineno, default_search_base.bv_val );
392 #endif
393
394                                 free( default_search_base.bv_val );
395                                 free( default_search_nbase.bv_val );
396                         }
397
398                         if ( load_ucdata( NULL ) < 0 ) return 1;
399
400                         {
401                                 struct berval dn;
402
403                                 dn.bv_val = cargv[1];
404                                 dn.bv_len = strlen( dn.bv_val );
405
406                                 rc = dnPrettyNormal( NULL, &dn,
407                                         &default_search_base,
408                                         &default_search_nbase );
409
410                                 if( rc != LDAP_SUCCESS ) {
411 #ifdef NEW_LOGGING
412                                         LDAP_LOG( CONFIG, CRIT, 
413                                                 "%s: line %d: defaultSearchBase DN is invalid.\n",
414                                                 fname, lineno, 0 );
415 #else
416                                         Debug( LDAP_DEBUG_ANY,
417                                                 "%s: line %d: defaultSearchBase DN is invalid\n",
418                                            fname, lineno, 0 );
419 #endif
420                                         return( 1 );
421                                 }
422                         }
423
424                 /* set maximum threads in thread pool */
425                 } else if ( strcasecmp( cargv[0], "threads" ) == 0 ) {
426                         int c;
427                         if ( cargc < 2 ) {
428 #ifdef NEW_LOGGING
429                                 LDAP_LOG( CONFIG, CRIT, 
430                                         "%s: line %d: missing count in \"threads <count>\" line\n",
431                                         fname, lineno, 0 );
432 #else
433                                 Debug( LDAP_DEBUG_ANY,
434             "%s: line %d: missing count in \"threads <count>\" line\n",
435                                     fname, lineno, 0 );
436 #endif
437
438                                 return( 1 );
439                         }
440
441                         c = atoi( cargv[1] );
442
443                         if( c < 0 ) {
444 #ifdef NEW_LOGGING
445                                 LDAP_LOG( CONFIG, CRIT, 
446                                            "%s: line %d: invalid level (%d) in \"threads <count>\""
447                                            "line\n", fname, lineno, c );
448 #else
449                                 Debug( LDAP_DEBUG_ANY,
450             "%s: line %d: invalid level (%d) in \"threads <count>\" line\n",
451                                     fname, lineno, c );
452 #endif
453
454                                 return( 1 );
455                         }
456
457                         ldap_pvt_thread_pool_maxthreads( &connection_pool, c );
458
459                         /* save for later use */
460                         connection_pool_max = c;
461
462                 /* get pid file name */
463                 } else if ( strcasecmp( cargv[0], "pidfile" ) == 0 ) {
464                         if ( cargc < 2 ) {
465 #ifdef NEW_LOGGING
466                                 LDAP_LOG( CONFIG, CRIT, 
467                                         "%s: line %d missing file name in \"pidfile <file>\" "
468                                         "line.\n", fname, lineno, 0 );
469 #else
470                                 Debug( LDAP_DEBUG_ANY,
471             "%s: line %d: missing file name in \"pidfile <file>\" line\n",
472                                     fname, lineno, 0 );
473 #endif
474
475                                 return( 1 );
476                         }
477
478                         slapd_pid_file = ch_strdup( cargv[1] );
479
480                 /* get args file name */
481                 } else if ( strcasecmp( cargv[0], "argsfile" ) == 0 ) {
482                         if ( cargc < 2 ) {
483 #ifdef NEW_LOGGING
484                                 LDAP_LOG( CONFIG, CRIT, 
485                                            "%s: %d: missing file name in "
486                                            "\"argsfile <file>\" line.\n",
487                                            fname, lineno, 0 );
488 #else
489                                 Debug( LDAP_DEBUG_ANY,
490             "%s: line %d: missing file name in \"argsfile <file>\" line\n",
491                                     fname, lineno, 0 );
492 #endif
493
494                                 return( 1 );
495                         }
496
497                         slapd_args_file = ch_strdup( cargv[1] );
498
499                 /* default password hash */
500                 } else if ( strcasecmp( cargv[0], "password-hash" ) == 0 ) {
501                         if ( cargc < 2 ) {
502 #ifdef NEW_LOGGING
503                                 LDAP_LOG( CONFIG, CRIT, 
504                                            "%s: line %d: missing hash in "
505                                            "\"password-hash <hash>\" line.\n",
506                                            fname, lineno, 0 );
507 #else
508                                 Debug( LDAP_DEBUG_ANY,
509             "%s: line %d: missing hash in \"password-hash <hash>\" line\n",
510                                     fname, lineno, 0 );
511 #endif
512
513                                 return( 1 );
514                         }
515                         if ( default_passwd_hash != NULL ) {
516 #ifdef NEW_LOGGING
517                                 LDAP_LOG( CONFIG, CRIT, 
518                                            "%s: line %d: already set default password_hash!\n",
519                                            fname, lineno, 0 );
520 #else
521                                 Debug( LDAP_DEBUG_ANY,
522                                         "%s: line %d: already set default password_hash!\n",
523                                         fname, lineno, 0 );
524 #endif
525
526                                 return 1;
527
528                         }
529
530                         if ( lutil_passwd_scheme( cargv[1] ) == 0 ) {
531 #ifdef NEW_LOGGING
532                                 LDAP_LOG( CONFIG, CRIT, 
533                                            "%s: line %d: password scheme \"%s\" not available\n",
534                                            fname, lineno, cargv[1] );
535 #else
536                                 Debug( LDAP_DEBUG_ANY,
537                                         "%s: line %d: password scheme \"%s\" not available\n",
538                                         fname, lineno, cargv[1] );
539 #endif
540                                 return 1;
541                         }
542
543                         default_passwd_hash = ch_strdup( cargv[1] );
544
545                 } else if ( strcasecmp( cargv[0], "password-crypt-salt-format" ) == 0 ) 
546                 {
547                         if ( cargc < 2 ) {
548 #ifdef NEW_LOGGING
549                                 LDAP_LOG( CONFIG, CRIT, 
550                                         "%s: line %d: missing format in "
551                                         "\"password-crypt-salt-format <format>\" line\n",
552                                         fname, lineno, 0 );
553 #else
554                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: missing format in "
555                                         "\"password-crypt-salt-format <format>\" line\n",
556                                     fname, lineno, 0 );
557 #endif
558
559                                 return 1;
560                         }
561
562                         lutil_salt_format( cargv[1] );
563
564 #ifdef HAVE_CYRUS_SASL
565                 /* SASL config options */
566                 } else if ( strncasecmp( cargv[0], "sasl", 4 ) == 0 ) {
567                         if ( slap_sasl_config( cargc, cargv, line, fname, lineno ) )
568                                 return 1;
569 #endif /* HAVE_CYRUS_SASL */
570
571                 } else if ( strcasecmp( cargv[0], "schemadn" ) == 0 ) {
572                         struct berval dn;
573                         if ( cargc < 2 ) {
574 #ifdef NEW_LOGGING
575                                 LDAP_LOG( CONFIG, CRIT, 
576                                            "%s: line %d: missing dn in "
577                                            "\"schemadn <dn>\" line.\n", fname, lineno, 0  );
578 #else
579                                 Debug( LDAP_DEBUG_ANY,
580             "%s: line %d: missing dn in \"schemadn <dn>\" line\n",
581                                     fname, lineno, 0 );
582 #endif
583                                 return 1 ;
584                         }
585                         ber_str2bv( cargv[1], 0, 0, &dn );
586                         if ( be ) {
587                                 rc = dnPrettyNormal( NULL, &dn, &be->be_schemadn,
588                                         &be->be_schemandn );
589                         } else {
590                                 rc = dnPrettyNormal( NULL, &dn, &global_schemadn,
591                                         &global_schemandn );
592                         }
593                         if ( rc != LDAP_SUCCESS ) {
594 #ifdef NEW_LOGGING
595                                 LDAP_LOG( CONFIG, CRIT, 
596                                         "%s: line %d: schemadn DN is invalid.\n",
597                                         fname, lineno , 0 );
598 #else
599                                 Debug( LDAP_DEBUG_ANY,
600                                         "%s: line %d: schemadn DN is invalid\n",
601                                         fname, lineno, 0 );
602 #endif
603                                 return 1;
604                         }
605
606                 /* set UCDATA path */
607                 } else if ( strcasecmp( cargv[0], "ucdata-path" ) == 0 ) {
608                         int err;
609                         if ( cargc < 2 ) {
610 #ifdef NEW_LOGGING
611                                 LDAP_LOG( CONFIG, CRIT, 
612                                            "%s: line %d: missing path in "
613                                            "\"ucdata-path <path>\" line.\n", fname, lineno, 0  );
614 #else
615                                 Debug( LDAP_DEBUG_ANY,
616             "%s: line %d: missing path in \"ucdata-path <path>\" line\n",
617                                     fname, lineno, 0 );
618 #endif
619
620                                 return( 1 );
621                         }
622
623                         err = load_ucdata( cargv[1] );
624                         if ( err <= 0 ) {
625                                 if ( err == 0 ) {
626 #ifdef NEW_LOGGING
627                                         LDAP_LOG( CONFIG, CRIT, 
628                                                    "%s: line %d: ucdata already loaded, ucdata-path "
629                                                    "must be set earlier in the file and/or be "
630                                                    "specified only once!\n", fname, lineno, 0 );
631 #else
632                                         Debug( LDAP_DEBUG_ANY,
633                                                "%s: line %d: ucdata already loaded, ucdata-path must be set earlier in the file and/or be specified only once!\n",
634                                                fname, lineno, 0 );
635 #endif
636
637                                 }
638                                 return( 1 );
639                         }
640
641                 /* set size limit */
642                 } else if ( strcasecmp( cargv[0], "sizelimit" ) == 0 ) {
643                         int rc = 0, i;
644                         struct slap_limits_set *lim;
645                         
646                         if ( cargc < 2 ) {
647 #ifdef NEW_LOGGING
648                                 LDAP_LOG( CONFIG, CRIT, 
649                                    "%s: line %d: missing limit in \"sizelimit <limit>\" "
650                                    "line.\n", fname, lineno, 0 );
651 #else
652                                 Debug( LDAP_DEBUG_ANY,
653             "%s: line %d: missing limit in \"sizelimit <limit>\" line\n",
654                                     fname, lineno, 0 );
655 #endif
656
657                                 return( 1 );
658                         }
659
660                         if ( be == NULL ) {
661                                 lim = &deflimit;
662                         } else {
663                                 lim = &be->be_def_limit;
664                         }
665
666                         for ( i = 1; i < cargc; i++ ) {
667                                 if ( strncasecmp( cargv[i], "size", 4 ) == 0 ) {
668                                         rc = parse_limit( cargv[i], lim );
669                                         if ( rc ) {
670 #ifdef NEW_LOGGING
671                                                 LDAP_LOG( CONFIG, CRIT, 
672                                                         "%s: line %d: unable "
673                                                            "to parse value \"%s\" in \"sizelimit "
674                                                            "<limit>\" line.\n", fname, lineno, cargv[i] );
675 #else
676                                                 Debug( LDAP_DEBUG_ANY,
677                                                         "%s: line %d: unable "
678                                                         "to parse value \"%s\" "
679                                                         "in \"sizelimit "
680                                                         "<limit>\" line\n",
681                                                         fname, lineno, cargv[i] );
682 #endif
683                                                 return( 1 );
684                                         }
685
686                                 } else {
687                                         if ( strcasecmp( cargv[i], "unlimited" ) == 0 ) {
688                                                 lim->lms_s_soft = -1;
689                                         } else {
690                                                 char *next;
691
692                                                 lim->lms_s_soft = strtol( cargv[i] , &next, 0 );
693                                                 if ( next == cargv[i] ) {
694 #ifdef NEW_LOGGING
695                                                         LDAP_LOG( CONFIG, CRIT, 
696                                                            "%s: line %d: unable to parse limit \"%s\" in \"sizelimit <limit>\" "
697                                                            "line.\n", fname, lineno, cargv[i] );
698 #else
699                                                         Debug( LDAP_DEBUG_ANY,
700                                                             "%s: line %d: unable to parse limit \"%s\" in \"sizelimit <limit>\" line\n",
701                                                             fname, lineno, cargv[i] );
702 #endif
703                                                         return( 1 );
704
705                                                 } else if ( next[0] != '\0' ) {
706 #ifdef NEW_LOGGING
707                                                         LDAP_LOG( CONFIG, CRIT, 
708                                                            "%s: line %d: trailing chars \"%s\" in \"sizelimit <limit>\" "
709                                                            "line ignored.\n", fname, lineno, next );
710 #else
711                                                         Debug( LDAP_DEBUG_ANY,
712                                                             "%s: line %d: trailing chars \"%s\" in \"sizelimit <limit>\" line ignored\n",
713                                                             fname, lineno, next );
714 #endif
715                                                 }
716                                         }
717                                         lim->lms_s_hard = 0;
718                                 }
719                         }
720
721                 /* set time limit */
722                 } else if ( strcasecmp( cargv[0], "timelimit" ) == 0 ) {
723                         int rc = 0, i;
724                         struct slap_limits_set *lim;
725                         
726                         if ( cargc < 2 ) {
727 #ifdef NEW_LOGGING
728                                 LDAP_LOG( CONFIG, CRIT, 
729                                         "%s: line %d missing limit in \"timelimit <limit>\" "
730                                         "line.\n", fname, lineno, 0 );
731 #else
732                                 Debug( LDAP_DEBUG_ANY,
733             "%s: line %d: missing limit in \"timelimit <limit>\" line\n",
734                                     fname, lineno, 0 );
735 #endif
736
737                                 return( 1 );
738                         }
739                         
740                         if ( be == NULL ) {
741                                 lim = &deflimit;
742                         } else {
743                                 lim = &be->be_def_limit;
744                         }
745
746                         for ( i = 1; i < cargc; i++ ) {
747                                 if ( strncasecmp( cargv[i], "time", 4 ) == 0 ) {
748                                         rc = parse_limit( cargv[i], lim );
749                                         if ( rc ) {
750 #ifdef NEW_LOGGING
751                                                 LDAP_LOG( CONFIG, CRIT, 
752                                                             "%s: line %d: unable to parse value \"%s\" "
753                                                            "in \"timelimit <limit>\" line.\n",
754                                                            fname, lineno, cargv[i] );
755 #else
756                                                 Debug( LDAP_DEBUG_ANY,
757                                                         "%s: line %d: unable "
758                                                         "to parse value \"%s\" "
759                                                         "in \"timelimit "
760                                                         "<limit>\" line\n",
761                                                         fname, lineno, cargv[i] );
762 #endif
763                                                 return( 1 );
764                                         }
765
766                                 } else {
767                                         if ( strcasecmp( cargv[i], "unlimited" ) == 0 ) {
768                                                 lim->lms_t_soft = -1;
769                                         } else {
770                                                 char *next;
771
772                                                 lim->lms_t_soft = strtol( cargv[i] , &next, 0 );
773                                                 if ( next == cargv[i] ) {
774 #ifdef NEW_LOGGING
775                                                         LDAP_LOG( CONFIG, CRIT, 
776                                                            "%s: line %d: unable to parse limit \"%s\" in \"timelimit <limit>\" "
777                                                            "line.\n", fname, lineno, cargv[i] );
778 #else
779                                                         Debug( LDAP_DEBUG_ANY,
780                                                             "%s: line %d: unable to parse limit \"%s\" in \"timelimit <limit>\" line\n",
781                                                             fname, lineno, cargv[i] );
782 #endif
783                                                         return( 1 );
784
785                                                 } else if ( next[0] != '\0' ) {
786 #ifdef NEW_LOGGING
787                                                         LDAP_LOG( CONFIG, CRIT, 
788                                                            "%s: line %d: trailing chars \"%s\" in \"timelimit <limit>\" "
789                                                            "line ignored.\n", fname, lineno, next );
790 #else
791                                                         Debug( LDAP_DEBUG_ANY,
792                                                             "%s: line %d: trailing chars \"%s\" in \"timelimit <limit>\" line ignored\n",
793                                                             fname, lineno, next );
794 #endif
795                                                 }
796                                         }
797                                         lim->lms_t_hard = 0;
798                                 }
799                         }
800
801                 /* set regex-based limits */
802                 } else if ( strcasecmp( cargv[0], "limits" ) == 0 ) {
803                         if ( be == NULL ) {
804 #ifdef NEW_LOGGING
805                                 LDAP_LOG( CONFIG, WARNING, 
806                                            "%s: line %d \"limits\" allowed only in database "
807                                            "environment.\n", fname, lineno, 0 );
808 #else
809                                 Debug( LDAP_DEBUG_ANY,
810         "%s: line %d \"limits\" allowed only in database environment.\n%s",
811                                         fname, lineno, "" );
812 #endif
813                                 return( 1 );
814                         }
815
816                         if ( parse_limits( be, fname, lineno, cargc, cargv ) ) {
817                                 return( 1 );
818                         }
819
820                 /* mark this as a subordinate database */
821                 } else if ( strcasecmp( cargv[0], "subordinate" ) == 0 ) {
822                         if ( be == NULL ) {
823 #ifdef NEW_LOGGING
824                                 LDAP_LOG( CONFIG, INFO, "%s: line %d: "
825                                         "subordinate keyword must appear inside a database "
826                                         "definition.\n", fname, lineno, 0 );
827 #else
828                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: suffix line "
829                                         "must appear inside a database definition.\n",
830                                     fname, lineno, 0 );
831 #endif
832                                 return 1;
833
834                         } else {
835                                 be->be_flags |= SLAP_BFLAG_GLUE_SUBORDINATE;
836                                 num_subordinates++;
837                         }
838
839                 /* set database suffix */
840                 } else if ( strcasecmp( cargv[0], "suffix" ) == 0 ) {
841                         Backend *tmp_be;
842                         struct berval dn, pdn, ndn;
843
844                         if ( cargc < 2 ) {
845 #ifdef NEW_LOGGING
846                                 LDAP_LOG( CONFIG, CRIT, 
847                                         "%s: line %d: missing dn in \"suffix <dn>\" line.\n",
848                                         fname, lineno, 0 );
849 #else
850                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
851                                         "missing dn in \"suffix <dn>\" line\n",
852                                     fname, lineno, 0 );
853 #endif
854
855                                 return( 1 );
856
857                         } else if ( cargc > 2 ) {
858 #ifdef NEW_LOGGING
859                                 LDAP_LOG( CONFIG, INFO, 
860                                         "%s: line %d: extra cruft after <dn> in \"suffix %s\""
861                                         " line (ignored).\n", fname, lineno, cargv[1] );
862 #else
863                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: extra cruft "
864                                         "after <dn> in \"suffix %s\" line (ignored)\n",
865                                     fname, lineno, cargv[1] );
866 #endif
867                         }
868
869                         if ( be == NULL ) {
870 #ifdef NEW_LOGGING
871                                 LDAP_LOG( CONFIG, INFO, 
872                                         "%s: line %d: suffix line must appear inside a database "
873                                         "definition.\n", fname, lineno, 0 );
874 #else
875                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: suffix line "
876                                         "must appear inside a database definition\n",
877                                     fname, lineno, 0 );
878 #endif
879                                 return( 1 );
880
881 #if defined(SLAPD_MONITOR_DN)
882                         /* "cn=Monitor" is reserved for monitoring slap */
883                         } else if ( strcasecmp( cargv[1], SLAPD_MONITOR_DN ) == 0 ) {
884 #ifdef NEW_LOGGING
885                                 LDAP_LOG( CONFIG, CRIT, "%s: line %d: \""
886                                         SLAPD_MONITOR_DN "\" is reserved for monitoring slapd\n", 
887                                         fname, lineno, 0 );
888 #else
889                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: \""
890                                         SLAPD_MONITOR_DN "\" is reserved for monitoring slapd\n", 
891                                         fname, lineno, 0 );
892 #endif
893                                 return( 1 );
894 #endif /* SLAPD_MONITOR_DN */
895                         }
896
897                         if ( load_ucdata( NULL ) < 0 ) return 1;
898
899                         dn.bv_val = cargv[1];
900                         dn.bv_len = strlen( cargv[1] );
901
902                         rc = dnPrettyNormal( NULL, &dn, &pdn, &ndn );
903                         if( rc != LDAP_SUCCESS ) {
904 #ifdef NEW_LOGGING
905                                 LDAP_LOG( CONFIG, CRIT, 
906                                         "%s: line %d: suffix DN is invalid.\n",
907                                         fname, lineno, 0 );
908 #else
909                                 Debug( LDAP_DEBUG_ANY,
910                                         "%s: line %d: suffix DN is invalid\n",
911                                    fname, lineno, 0 );
912 #endif
913                                 return( 1 );
914                         }
915
916                         tmp_be = select_backend( &ndn, 0, 0 );
917                         if ( tmp_be == be ) {
918 #ifdef NEW_LOGGING
919                                 LDAP_LOG( CONFIG, INFO, 
920                                         "%s: line %d: suffix already served by this backend "
921                                         "(ignored)\n", fname, lineno, 0 );
922 #else
923                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: suffix "
924                                         "already served by this backend (ignored)\n",
925                                     fname, lineno, 0 );
926 #endif
927                                 free( pdn.bv_val );
928                                 free( ndn.bv_val );
929
930                         } else if ( tmp_be  != NULL ) {
931 #ifdef NEW_LOGGING
932                                 LDAP_LOG( CONFIG, INFO, 
933                                         "%s: line %d: suffix already served by a preceding "
934                                         "backend \"%s\"\n", fname, lineno,
935                                         tmp_be->be_suffix[0].bv_val );
936 #else
937                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: suffix "
938                                         "already served by a preceeding backend \"%s\"\n",
939                                     fname, lineno, tmp_be->be_suffix[0].bv_val );
940 #endif
941                                 free( pdn.bv_val );
942                                 free( ndn.bv_val );
943                                 return( 1 );
944
945                         } else if( pdn.bv_len == 0 && default_search_nbase.bv_len ) {
946 #ifdef NEW_LOGGING
947                                         LDAP_LOG( CONFIG, INFO, 
948                                                 "%s: line %d: suffix DN empty and default search "
949                                                 "base provided \"%s\" (assuming okay).\n",
950                                                 fname, lineno, default_search_base.bv_val );
951 #else
952                                         Debug( LDAP_DEBUG_ANY, "%s: line %d: "
953                                                 "suffix DN empty and default "
954                                                 "search base provided \"%s\" (assuming okay)\n",
955                                         fname, lineno, default_search_base.bv_val );
956 #endif
957                         }
958
959                         ber_bvarray_add( &be->be_suffix, &pdn );
960                         ber_bvarray_add( &be->be_nsuffix, &ndn );
961
962                 /* set database suffixAlias */
963                 } else if ( strcasecmp( cargv[0], "suffixAlias" ) == 0 ) {
964                         Backend *tmp_be;
965                         struct berval alias, palias, nalias;
966                         struct berval aliased, paliased, naliased;
967
968                         if ( cargc < 2 ) {
969 #ifdef NEW_LOGGING
970                                 LDAP_LOG( CONFIG, CRIT, 
971                                         "%s: line %d: missing alias and aliased_dn in "
972                                         "\"suffixAlias <alias> <aliased_dn>\" line.\n",
973                                         fname, lineno, 0 );
974 #else
975                                 Debug( LDAP_DEBUG_ANY,
976                                         "%s: line %d: missing alias and aliased_dn in "
977                                         "\"suffixAlias <alias> <aliased_dn>\" line.\n",
978                                         fname, lineno, 0 );
979 #endif
980
981                                 return( 1 );
982                         } else if ( cargc < 3 ) {
983 #ifdef NEW_LOGGING
984                                 LDAP_LOG( CONFIG, CRIT, 
985                                         "%s: line %d: missing aliased_dn in "
986                                         "\"suffixAlias <alias> <aliased_dn>\" line\n",
987                                         fname, lineno, 0 );
988 #else
989                                 Debug( LDAP_DEBUG_ANY,
990                                         "%s: line %d: missing aliased_dn in "
991                                         "\"suffixAlias <alias> <aliased_dn>\" line\n",
992                                         fname, lineno, 0 );
993 #endif
994                                 return( 1 );
995
996                         } else if ( cargc > 3 ) {
997 #ifdef NEW_LOGGING
998                                 LDAP_LOG( CONFIG, CRIT, 
999                                         "%s: line %d: extra cruft in suffixAlias line (ignored)\n",
1000                                         fname, lineno, 0 );
1001 #else
1002                                 Debug( LDAP_DEBUG_ANY,
1003                                         "%s: line %d: extra cruft in suffixAlias line (ignored)\n",
1004                                         fname, lineno, 0 );
1005 #endif
1006                         }
1007
1008                         if ( be == NULL ) {
1009 #ifdef NEW_LOGGING
1010                                 LDAP_LOG( CONFIG, INFO, 
1011                                         "%s: line %d: suffix line must appear inside a database "
1012                                         "definition.\n", fname, lineno, 0 );
1013 #else
1014                                 Debug( LDAP_DEBUG_ANY,
1015                                         "%s: line %d: suffixAlias line"
1016                                         " must appear inside a database definition.\n",
1017                                         fname, lineno, 0 );
1018 #endif
1019                                 return 1;
1020                         }
1021
1022                         if ( load_ucdata( NULL ) < 0 ) return 1;
1023                         
1024                         alias.bv_val = cargv[1];
1025                         alias.bv_len = strlen( cargv[1] );
1026
1027                         rc = dnPrettyNormal( NULL, &alias, &palias, &nalias );
1028                         if( rc != LDAP_SUCCESS ) {
1029 #ifdef NEW_LOGGING
1030                                 LDAP_LOG( CONFIG, CRIT, 
1031                                         "%s: line %d: alias DN is invalid.\n", fname, lineno, 0 );
1032 #else
1033                                 Debug( LDAP_DEBUG_ANY,
1034                                         "%s: line %d: alias DN is invalid\n",
1035                                    fname, lineno, 0 );
1036 #endif
1037                                 return( 1 );
1038                         }
1039
1040                         tmp_be = select_backend( &nalias, 0, 0 );
1041                         free( nalias.bv_val );
1042                         if ( tmp_be && tmp_be != be ) {
1043 #ifdef NEW_LOGGING
1044                                 LDAP_LOG( CONFIG, INFO, 
1045                                         "%s: line %d: suffixAlias served by a preceeding "
1046                                         "backend \"%s\"\n", fname, lineno, 
1047                                         tmp_be->be_suffix[0].bv_val );
1048 #else
1049                                 Debug( LDAP_DEBUG_ANY,
1050                                         "%s: line %d: suffixAlias served by"
1051                                         "  a preceeding backend \"%s\"\n",
1052                                         fname, lineno, tmp_be->be_suffix[0].bv_val );
1053 #endif
1054                                 free( palias.bv_val );
1055                                 return -1;
1056                         }
1057
1058                         aliased.bv_val = cargv[2];
1059                         aliased.bv_len = strlen( cargv[2] );
1060
1061                         rc = dnPrettyNormal( NULL, &aliased, &paliased, &naliased );
1062                         if( rc != LDAP_SUCCESS ) {
1063 #ifdef NEW_LOGGING
1064                                 LDAP_LOG( CONFIG, CRIT, 
1065                                         "%s: line %d: aliased DN is invalid.\n", fname, lineno,0 );
1066 #else
1067                                 Debug( LDAP_DEBUG_ANY,
1068                                         "%s: line %d: aliased DN is invalid\n",
1069                                    fname, lineno, 0 );
1070 #endif
1071                                 free( palias.bv_val );
1072                                 return( 1 );
1073                         }
1074
1075                         tmp_be = select_backend( &naliased, 0, 0 );
1076                         free( naliased.bv_val );
1077                         if ( tmp_be && tmp_be != be ) {
1078 #ifdef NEW_LOGGING
1079                                 LDAP_LOG( CONFIG, INFO, 
1080                                         "%s: line %d: suffixAlias derefs to a different backend "
1081                                         "a preceeding backend \"%s\"\n",
1082                                         fname, lineno, tmp_be->be_suffix[0].bv_val );
1083 #else
1084                                 Debug( LDAP_DEBUG_ANY,
1085                                         "%s: line %d: suffixAlias derefs to differnet backend"
1086                                         "  a preceeding backend \"%s\"\n",
1087                                         fname, lineno, tmp_be->be_suffix[0].bv_val );
1088 #endif
1089                                 free( palias.bv_val );
1090                                 free( paliased.bv_val );
1091                                 return -1;
1092                         }
1093
1094                         ber_bvarray_add( &be->be_suffixAlias, &palias ); 
1095                         ber_bvarray_add( &be->be_suffixAlias, &paliased );
1096
1097                /* set max deref depth */
1098                } else if ( strcasecmp( cargv[0], "maxDerefDepth" ) == 0 ) {
1099                                         int i;
1100                        if ( cargc < 2 ) {
1101 #ifdef NEW_LOGGING
1102                                LDAP_LOG( CONFIG, CRIT, 
1103                                           "%s: line %d: missing depth in \"maxDerefDepth <depth>\""
1104                                           " line\n", fname, lineno, 0 );
1105 #else
1106                                Debug( LDAP_DEBUG_ANY,
1107                    "%s: line %d: missing depth in \"maxDerefDepth <depth>\" line\n",
1108                                    fname, lineno, 0 );
1109 #endif
1110
1111                                return( 1 );
1112                        }
1113                        if ( be == NULL ) {
1114 #ifdef NEW_LOGGING
1115                                LDAP_LOG( CONFIG, INFO, 
1116                                           "%s: line %d: depth line must appear inside a database "
1117                                           "definition.\n", fname, lineno ,0 );
1118 #else
1119                                Debug( LDAP_DEBUG_ANY,
1120 "%s: line %d: depth line must appear inside a database definition.\n",
1121                                    fname, lineno, 0 );
1122 #endif
1123                                                         return 1;
1124
1125                        } else if ((i = atoi(cargv[1])) < 0) {
1126 #ifdef NEW_LOGGING
1127                                LDAP_LOG( CONFIG, INFO, 
1128                                           "%s: line %d: depth must be positive.\n",
1129                                           fname, lineno ,0 );
1130 #else
1131                                Debug( LDAP_DEBUG_ANY,
1132 "%s: line %d: depth must be positive.\n",
1133                                    fname, lineno, 0 );
1134 #endif
1135                                                         return 1;
1136
1137
1138                        } else {
1139                            be->be_max_deref_depth = i;
1140                                            }
1141
1142
1143                 /* set magic "root" dn for this database */
1144                 } else if ( strcasecmp( cargv[0], "rootdn" ) == 0 ) {
1145                         if ( cargc < 2 ) {
1146 #ifdef NEW_LOGGING
1147                                 LDAP_LOG( CONFIG, INFO, 
1148                                            "%s: line %d: missing dn in \"rootdn <dn>\" line.\n",
1149                                            fname, lineno ,0 );
1150 #else
1151                                 Debug( LDAP_DEBUG_ANY,
1152                     "%s: line %d: missing dn in \"rootdn <dn>\" line\n",
1153                                     fname, lineno, 0 );
1154 #endif
1155
1156                                 return( 1 );
1157                         }
1158
1159                         if ( be == NULL ) {
1160 #ifdef NEW_LOGGING
1161                                 LDAP_LOG( CONFIG, INFO, 
1162                                            "%s: line %d: rootdn line must appear inside a database "
1163                                            "definition.\n", fname, lineno ,0 );
1164 #else
1165                                 Debug( LDAP_DEBUG_ANY,
1166 "%s: line %d: rootdn line must appear inside a database definition.\n",
1167                                     fname, lineno, 0 );
1168 #endif
1169                                 return 1;
1170
1171                         } else {
1172                                 struct berval dn;
1173                                 
1174                                 if ( load_ucdata( NULL ) < 0 ) return 1;
1175
1176                                 dn.bv_val = cargv[1];
1177                                 dn.bv_len = strlen( cargv[1] );
1178
1179                                 rc = dnPrettyNormal( NULL, &dn,
1180                                         &be->be_rootdn,
1181                                         &be->be_rootndn );
1182
1183                                 if( rc != LDAP_SUCCESS ) {
1184 #ifdef NEW_LOGGING
1185                                         LDAP_LOG( CONFIG, CRIT, 
1186                                                 "%s: line %d: rootdn DN is invalid.\n", 
1187                                                 fname, lineno ,0 );
1188 #else
1189                                         Debug( LDAP_DEBUG_ANY,
1190                                                 "%s: line %d: rootdn DN is invalid\n",
1191                                            fname, lineno, 0 );
1192 #endif
1193                                         return( 1 );
1194                                 }
1195                         }
1196
1197                 /* set super-secret magic database password */
1198                 } else if ( strcasecmp( cargv[0], "rootpw" ) == 0 ) {
1199                         if ( cargc < 2 ) {
1200 #ifdef NEW_LOGGING
1201                                 LDAP_LOG( CONFIG, CRIT, 
1202                                         "%s: line %d: missing passwd in \"rootpw <passwd>\""
1203                                         " line\n", fname, lineno ,0 );
1204 #else
1205                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1206                                         "missing passwd in \"rootpw <passwd>\" line\n",
1207                                     fname, lineno, 0 );
1208 #endif
1209
1210                                 return( 1 );
1211                         }
1212
1213                         if ( be == NULL ) {
1214 #ifdef NEW_LOGGING
1215                                 LDAP_LOG( CONFIG, INFO, "%s: line %d: "
1216                                         "rootpw line must appear inside a database "
1217                                         "definition.\n", fname, lineno ,0 );
1218 #else
1219                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1220                                         "rootpw line must appear inside a database "
1221                                         "definition.\n",
1222                                     fname, lineno, 0 );
1223 #endif
1224                                 return 1;
1225
1226                         } else {
1227                                 Backend *tmp_be = select_backend( &be->be_rootndn, 0, 0 );
1228
1229                                 if( tmp_be != be ) {
1230 #ifdef NEW_LOGGING
1231                                         LDAP_LOG( CONFIG, INFO,
1232                                                 "%s: line %d: "
1233                                                 "rootpw can only be set when rootdn is under suffix\n",
1234                                                 fname, lineno, "" );
1235 #else
1236                                         Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1237                                                 "rootpw can only be set when rootdn is under suffix\n",
1238                                         fname, lineno, 0 );
1239 #endif
1240                                         return 1;
1241                                 }
1242
1243                                 be->be_rootpw.bv_val = ch_strdup( cargv[1] );
1244                                 be->be_rootpw.bv_len = strlen( be->be_rootpw.bv_val );
1245                         }
1246
1247                 /* make this database read-only */
1248                 } else if ( strcasecmp( cargv[0], "readonly" ) == 0 ) {
1249                         if ( cargc < 2 ) {
1250 #ifdef NEW_LOGGING
1251                                 LDAP_LOG( CONFIG, CRIT, 
1252                                         "%s: line %d: missing on|off in \"readonly <on|off>\" "
1253                                         "line.\n", fname, lineno ,0 );
1254 #else
1255                                 Debug( LDAP_DEBUG_ANY,
1256             "%s: line %d: missing on|off in \"readonly <on|off>\" line\n",
1257                                     fname, lineno, 0 );
1258 #endif
1259
1260                                 return( 1 );
1261                         }
1262                         if ( be == NULL ) {
1263                                 if ( strcasecmp( cargv[1], "on" ) == 0 ) {
1264                                         global_restrictops |= SLAP_RESTRICT_OP_WRITES;
1265                                 } else {
1266                                         global_restrictops &= ~SLAP_RESTRICT_OP_WRITES;
1267                                 }
1268                         } else {
1269                                 if ( strcasecmp( cargv[1], "on" ) == 0 ) {
1270                                         be->be_restrictops |= SLAP_RESTRICT_OP_WRITES;
1271                                 } else {
1272                                         be->be_restrictops &= ~SLAP_RESTRICT_OP_WRITES;
1273                                 }
1274                         }
1275
1276
1277                 /* allow these features */
1278                 } else if ( strcasecmp( cargv[0], "allows" ) == 0 ||
1279                         strcasecmp( cargv[0], "allow" ) == 0 )
1280                 {
1281                         slap_mask_t     allows;
1282
1283                         if ( be != NULL ) {
1284 #ifdef NEW_LOGGING
1285                                 LDAP_LOG( CONFIG, INFO, 
1286                                            "%s: line %d: allow line must appear prior to "
1287                                            "database definitions.\n", fname, lineno ,0 );
1288 #else
1289                                 Debug( LDAP_DEBUG_ANY,
1290 "%s: line %d: allow line must appear prior to database definitions\n",
1291                                     fname, lineno, 0 );
1292 #endif
1293
1294                         }
1295
1296                         if ( cargc < 2 ) {
1297 #ifdef NEW_LOGGING
1298                                 LDAP_LOG( CONFIG, CRIT, 
1299                                            "%s: line %d: missing feature(s) in \"allow <features>\""
1300                                            " line\n", fname, lineno ,0 );
1301 #else
1302                                 Debug( LDAP_DEBUG_ANY,
1303             "%s: line %d: missing feature(s) in \"allow <features>\" line\n",
1304                                     fname, lineno, 0 );
1305 #endif
1306
1307                                 return( 1 );
1308                         }
1309
1310                         allows = 0;
1311
1312                         for( i=1; i < cargc; i++ ) {
1313                                 if( strcasecmp( cargv[i], "bind_v2" ) == 0 ) {
1314                                         allows |= SLAP_ALLOW_BIND_V2;
1315
1316                                 } else if( strcasecmp( cargv[i], "bind_anon_cred" ) == 0 ) {
1317                                         allows |= SLAP_ALLOW_BIND_ANON_CRED;
1318
1319                                 } else if( strcasecmp( cargv[i], "bind_anon_dn" ) == 0 ) {
1320                                         allows |= SLAP_ALLOW_BIND_ANON_DN;
1321
1322                                 } else if( strcasecmp( cargv[i], "update_anon" ) == 0 ) {
1323                                         allows |= SLAP_ALLOW_UPDATE_ANON;
1324
1325                                 } else if( strcasecmp( cargv[i], "none" ) != 0 ) {
1326 #ifdef NEW_LOGGING
1327                                         LDAP_LOG( CONFIG, CRIT, "%s: line %d: "
1328                                                 "unknown feature %s in \"allow <features>\" line.\n",
1329                                                 fname, lineno, cargv[1] );
1330 #else
1331                                         Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1332                                                 "unknown feature %s in \"allow <features>\" line\n",
1333                                                 fname, lineno, cargv[i] );
1334 #endif
1335
1336                                         return( 1 );
1337                                 }
1338                         }
1339
1340                         global_allows = allows;
1341
1342                 /* disallow these features */
1343                 } else if ( strcasecmp( cargv[0], "disallows" ) == 0 ||
1344                         strcasecmp( cargv[0], "disallow" ) == 0 )
1345                 {
1346                         slap_mask_t     disallows;
1347
1348                         if ( be != NULL ) {
1349 #ifdef NEW_LOGGING
1350                                 LDAP_LOG( CONFIG, INFO, 
1351                                            "%s: line %d: disallow line must appear prior to "
1352                                            "database definitions.\n", fname, lineno ,0 );
1353 #else
1354                                 Debug( LDAP_DEBUG_ANY,
1355 "%s: line %d: disallow line must appear prior to database definitions\n",
1356                                     fname, lineno, 0 );
1357 #endif
1358
1359                         }
1360
1361                         if ( cargc < 2 ) {
1362 #ifdef NEW_LOGGING
1363                                 LDAP_LOG( CONFIG, CRIT, 
1364                                         "%s: line %d: missing feature(s) in \"disallow <features>\""
1365                                         " line.\n", fname, lineno ,0 );
1366 #else
1367                                 Debug( LDAP_DEBUG_ANY,
1368             "%s: line %d: missing feature(s) in \"disallow <features>\" line\n",
1369                                     fname, lineno, 0 );
1370 #endif
1371
1372                                 return( 1 );
1373                         }
1374
1375                         disallows = 0;
1376
1377                         for( i=1; i < cargc; i++ ) {
1378                                 if( strcasecmp( cargv[i], "bind_anon" ) == 0 ) {
1379                                         disallows |= SLAP_DISALLOW_BIND_ANON;
1380
1381                                 } else if( strcasecmp( cargv[i], "bind_simple" ) == 0 ) {
1382                                         disallows |= SLAP_DISALLOW_BIND_SIMPLE;
1383
1384                                 } else if( strcasecmp( cargv[i], "bind_krbv4" ) == 0 ) {
1385                                         disallows |= SLAP_DISALLOW_BIND_KRBV4;
1386
1387                                 } else if( strcasecmp( cargv[i], "tls_2_anon" ) == 0 ) {
1388                                         disallows |= SLAP_DISALLOW_TLS_2_ANON;
1389
1390                                 } else if( strcasecmp( cargv[i], "tls_authc" ) == 0 ) {
1391                                         disallows |= SLAP_DISALLOW_TLS_AUTHC;
1392
1393                                 } else if( strcasecmp( cargv[i], "none" ) != 0 ) {
1394 #ifdef NEW_LOGGING
1395                                         LDAP_LOG( CONFIG, CRIT, 
1396                                                 "%s: line %d: unknown feature %s in "
1397                                                 "\"disallow <features>\" line.\n",
1398                                                 fname, lineno, cargv[i] );
1399 #else
1400                                         Debug( LDAP_DEBUG_ANY,
1401                     "%s: line %d: unknown feature %s in \"disallow <features>\" line\n",
1402                                             fname, lineno, cargv[i] );
1403 #endif
1404
1405                                         return( 1 );
1406                                 }
1407                         }
1408
1409                         global_disallows = disallows;
1410
1411                 /* require these features */
1412                 } else if ( strcasecmp( cargv[0], "requires" ) == 0 ||
1413                         strcasecmp( cargv[0], "require" ) == 0 )
1414                 {
1415                         slap_mask_t     requires;
1416
1417                         if ( cargc < 2 ) {
1418 #ifdef NEW_LOGGING
1419                                 LDAP_LOG( CONFIG, CRIT, 
1420                                            "%s: line %d: missing feature(s) in "
1421                                            "\"require <features>\" line.\n", fname, lineno ,0 );
1422 #else
1423                                 Debug( LDAP_DEBUG_ANY,
1424             "%s: line %d: missing feature(s) in \"require <features>\" line\n",
1425                                     fname, lineno, 0 );
1426 #endif
1427
1428                                 return( 1 );
1429                         }
1430
1431                         requires = 0;
1432
1433                         for( i=1; i < cargc; i++ ) {
1434                                 if( strcasecmp( cargv[i], "bind" ) == 0 ) {
1435                                         requires |= SLAP_REQUIRE_BIND;
1436
1437                                 } else if( strcasecmp( cargv[i], "LDAPv3" ) == 0 ) {
1438                                         requires |= SLAP_REQUIRE_LDAP_V3;
1439
1440                                 } else if( strcasecmp( cargv[i], "authc" ) == 0 ) {
1441                                         requires |= SLAP_REQUIRE_AUTHC;
1442
1443                                 } else if( strcasecmp( cargv[i], "SASL" ) == 0 ) {
1444                                         requires |= SLAP_REQUIRE_SASL;
1445
1446                                 } else if( strcasecmp( cargv[i], "strong" ) == 0 ) {
1447                                         requires |= SLAP_REQUIRE_STRONG;
1448
1449                                 } else if( strcasecmp( cargv[i], "none" ) != 0 ) {
1450 #ifdef NEW_LOGGING
1451                                         LDAP_LOG( CONFIG, CRIT, 
1452                                                    "%s: line %d: unknown feature %s in "
1453                                                    "\"require <features>\" line.\n", 
1454                                                    fname, lineno , cargv[i] );
1455 #else
1456                                         Debug( LDAP_DEBUG_ANY,
1457                     "%s: line %d: unknown feature %s in \"require <features>\" line\n",
1458                                             fname, lineno, cargv[i] );
1459 #endif
1460
1461                                         return( 1 );
1462                                 }
1463                         }
1464
1465                         if ( be == NULL ) {
1466                                 global_requires = requires;
1467                         } else {
1468                                 be->be_requires = requires;
1469                         }
1470
1471                 /* required security factors */
1472                 } else if ( strcasecmp( cargv[0], "security" ) == 0 ) {
1473                         slap_ssf_set_t *set;
1474
1475                         if ( cargc < 2 ) {
1476 #ifdef NEW_LOGGING
1477                                 LDAP_LOG( CONFIG, CRIT, 
1478                                         "%s: line %d: missing factor(s) in \"security <factors>\""
1479                                         " line.\n", fname, lineno ,0 );
1480 #else
1481                                 Debug( LDAP_DEBUG_ANY,
1482             "%s: line %d: missing factor(s) in \"security <factors>\" line\n",
1483                                     fname, lineno, 0 );
1484 #endif
1485
1486                                 return( 1 );
1487                         }
1488
1489                         if ( be == NULL ) {
1490                                 set = &global_ssf_set;
1491                         } else {
1492                                 set = &be->be_ssf_set;
1493                         }
1494
1495                         for( i=1; i < cargc; i++ ) {
1496                                 if( strncasecmp( cargv[i], "ssf=",
1497                                         sizeof("ssf") ) == 0 )
1498                                 {
1499                                         set->sss_ssf =
1500                                                 atoi( &cargv[i][sizeof("ssf")] );
1501
1502                                 } else if( strncasecmp( cargv[i], "transport=",
1503                                         sizeof("transport") ) == 0 )
1504                                 {
1505                                         set->sss_transport =
1506                                                 atoi( &cargv[i][sizeof("transport")] );
1507
1508                                 } else if( strncasecmp( cargv[i], "tls=",
1509                                         sizeof("tls") ) == 0 )
1510                                 {
1511                                         set->sss_tls =
1512                                                 atoi( &cargv[i][sizeof("tls")] );
1513
1514                                 } else if( strncasecmp( cargv[i], "sasl=",
1515                                         sizeof("sasl") ) == 0 )
1516                                 {
1517                                         set->sss_sasl =
1518                                                 atoi( &cargv[i][sizeof("sasl")] );
1519
1520                                 } else if( strncasecmp( cargv[i], "update_ssf=",
1521                                         sizeof("update_ssf") ) == 0 )
1522                                 {
1523                                         set->sss_update_ssf =
1524                                                 atoi( &cargv[i][sizeof("update_ssf")] );
1525
1526                                 } else if( strncasecmp( cargv[i], "update_transport=",
1527                                         sizeof("update_transport") ) == 0 )
1528                                 {
1529                                         set->sss_update_transport =
1530                                                 atoi( &cargv[i][sizeof("update_transport")] );
1531
1532                                 } else if( strncasecmp( cargv[i], "update_tls=",
1533                                         sizeof("update_tls") ) == 0 )
1534                                 {
1535                                         set->sss_update_tls =
1536                                                 atoi( &cargv[i][sizeof("update_tls")] );
1537
1538                                 } else if( strncasecmp( cargv[i], "update_sasl=",
1539                                         sizeof("update_sasl") ) == 0 )
1540                                 {
1541                                         set->sss_update_sasl =
1542                                                 atoi( &cargv[i][sizeof("update_sasl")] );
1543
1544                                 } else if( strncasecmp( cargv[i], "simple_bind=",
1545                                         sizeof("simple_bind") ) == 0 )
1546                                 {
1547                                         set->sss_simple_bind =
1548                                                 atoi( &cargv[i][sizeof("simple_bind")] );
1549
1550                                 } else {
1551 #ifdef NEW_LOGGING
1552                                         LDAP_LOG( CONFIG, CRIT, 
1553                                                    "%s: line %d: unknown factor %S in "
1554                                                    "\"security <factors>\" line.\n",
1555                                                    fname, lineno, cargv[1] );
1556 #else
1557                                         Debug( LDAP_DEBUG_ANY,
1558                     "%s: line %d: unknown factor %s in \"security <factors>\" line\n",
1559                                             fname, lineno, cargv[i] );
1560 #endif
1561
1562                                         return( 1 );
1563                                 }
1564                         }
1565                 /* where to send clients when we don't hold it */
1566                 } else if ( strcasecmp( cargv[0], "referral" ) == 0 ) {
1567                         if ( cargc < 2 ) {
1568 #ifdef NEW_LOGGING
1569                                 LDAP_LOG( CONFIG, CRIT, 
1570                                         "%s: line %d: missing URL in \"referral <URL>\""
1571                                         " line.\n", fname, lineno , 0 );
1572 #else
1573                                 Debug( LDAP_DEBUG_ANY,
1574                     "%s: line %d: missing URL in \"referral <URL>\" line\n",
1575                                     fname, lineno, 0 );
1576 #endif
1577
1578                                 return( 1 );
1579                         }
1580
1581                         if( validate_global_referral( cargv[1] ) ) {
1582 #ifdef NEW_LOGGING
1583                                 LDAP_LOG( CONFIG, CRIT, 
1584                                         "%s: line %d: invalid URL (%s) in \"referral\" line.\n",
1585                                         fname, lineno, cargv[1]  );
1586 #else
1587                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1588                                         "invalid URL (%s) in \"referral\" line.\n",
1589                                     fname, lineno, cargv[1] );
1590 #endif
1591                                 return 1;
1592                         }
1593
1594                         vals[0].bv_val = cargv[1];
1595                         vals[0].bv_len = strlen( vals[0].bv_val );
1596                         if( value_add( &default_referral, vals ) )
1597                                 return LDAP_OTHER;
1598
1599 #ifdef NEW_LOGGING
1600                 } else if ( strcasecmp( cargv[0], "logfile" ) == 0 ) {
1601                         FILE *logfile;
1602                         if ( cargc < 2 ) {
1603 #ifdef NEW_LOGGING
1604                                 LDAP_LOG( CONFIG, CRIT, 
1605                                         "%s: line %d: Error in logfile directive, "
1606                                         "\"logfile <filename>\"\n", fname, lineno , 0 );
1607 #else
1608                                 Debug( LDAP_DEBUG_ANY,
1609                                        "%s: line %d: Error in logfile directive, \"logfile filename\"\n",
1610                                        fname, lineno, 0 );
1611 #endif
1612
1613                                 return( 1 );
1614                         }
1615                         logfile = fopen( cargv[1], "w" );
1616                         if ( logfile != NULL ) lutil_debug_file( logfile  );
1617
1618 #endif
1619                 /* start of a new database definition */
1620                 } else if ( strcasecmp( cargv[0], "debug" ) == 0 ) {
1621                         int level;
1622                         if ( cargc < 3 ) {
1623 #ifdef NEW_LOGGING
1624                                 LDAP_LOG( CONFIG, CRIT, 
1625                                            "%s: line %d: Error in debug directive, "
1626                                            "\"debug <subsys> <level>\"\n", fname, lineno , 0 );
1627 #else
1628                                 Debug( LDAP_DEBUG_ANY,
1629                                         "%s: line %d: Error in debug directive, \"debug subsys level\"\n",
1630                                         fname, lineno, 0 );
1631 #endif
1632
1633                                 return( 1 );
1634                         }
1635                         level = atoi( cargv[2] );
1636                         if ( level <= 0 ) level = lutil_mnem2level( cargv[2] );
1637                         lutil_set_debug_level( cargv[1], level );
1638                 /* specify an Object Identifier macro */
1639                 } else if ( strcasecmp( cargv[0], "objectidentifier" ) == 0 ) {
1640                         rc = parse_oidm( fname, lineno, cargc, cargv );
1641                         if( rc ) return rc;
1642
1643                 /* specify an objectclass */
1644                 } else if ( strcasecmp( cargv[0], "objectclass" ) == 0 ) {
1645                         if ( *cargv[1] == '('  /*')'*/) {
1646                                 char * p;
1647                                 p = strchr(saveline,'(' /*')'*/);
1648                                 rc = parse_oc( fname, lineno, p, cargv );
1649                                 if( rc ) return rc;
1650
1651                         } else {
1652 #ifdef NEW_LOGGING
1653                                 LDAP_LOG( CONFIG, INFO, 
1654                                         "%s: line %d: old objectclass format not supported\n",
1655                                         fname, lineno , 0 );
1656 #else
1657                                 Debug( LDAP_DEBUG_ANY,
1658                                        "%s: line %d: old objectclass format not supported.\n",
1659                                        fname, lineno, 0 );
1660 #endif
1661                         }
1662
1663 #ifdef SLAP_EXTENDED_SCHEMA
1664                 } else if ( strcasecmp( cargv[0], "ditcontentrule" ) == 0 ) {
1665                         char * p;
1666                         p = strchr(saveline,'(' /*')'*/);
1667                         rc = parse_cr( fname, lineno, p, cargv );
1668                         if( rc ) return rc;
1669 #endif
1670
1671                 /* specify an attribute type */
1672                 } else if (( strcasecmp( cargv[0], "attributetype" ) == 0 )
1673                         || ( strcasecmp( cargv[0], "attribute" ) == 0 ))
1674                 {
1675                         if ( *cargv[1] == '(' /*')'*/) {
1676                                 char * p;
1677                                 p = strchr(saveline,'(' /*')'*/);
1678                                 rc = parse_at( fname, lineno, p, cargv );
1679                                 if( rc ) return rc;
1680
1681                         } else {
1682 #ifdef NEW_LOGGING
1683                                 LDAP_LOG( CONFIG, INFO, 
1684                                         "%s: line %d: old attribute type format not supported.\n",
1685                                         fname, lineno , 0 );
1686 #else
1687                                 Debug( LDAP_DEBUG_ANY,
1688     "%s: line %d: old attribute type format not supported.\n",
1689                                     fname, lineno, 0 );
1690 #endif
1691
1692                         }
1693
1694                 /* turn on/off schema checking */
1695                 } else if ( strcasecmp( cargv[0], "schemacheck" ) == 0 ) {
1696                         if ( cargc < 2 ) {
1697 #ifdef NEW_LOGGING
1698                                 LDAP_LOG( CONFIG, CRIT, 
1699                                         "%s: line %d: missing on|off in \"schemacheck <on|off>\""
1700                                         " line.\n", fname, lineno , 0 );
1701 #else
1702                                 Debug( LDAP_DEBUG_ANY,
1703     "%s: line %d: missing on|off in \"schemacheck <on|off>\" line\n",
1704                                     fname, lineno, 0 );
1705 #endif
1706
1707                                 return( 1 );
1708                         }
1709                         if ( strcasecmp( cargv[1], "off" ) == 0 ) {
1710 #ifdef NEW_LOGGING
1711                                 LDAP_LOG( CONFIG, CRIT, 
1712                                         "%s: line %d: schema checking disabled! your mileage may "
1713                                         "vary!\n", fname, lineno , 0 );
1714 #else
1715                                 Debug( LDAP_DEBUG_ANY,
1716                                         "%s: line %d: schema checking disabled! your mileage may vary!\n",
1717                                     fname, lineno, 0 );
1718 #endif
1719                                 global_schemacheck = 0;
1720                         } else {
1721                                 global_schemacheck = 1;
1722                         }
1723
1724                 /* specify access control info */
1725                 } else if ( strcasecmp( cargv[0], "access" ) == 0 ) {
1726                         parse_acl( be, fname, lineno, cargc, cargv );
1727
1728                 /* debug level to log things to syslog */
1729                 } else if ( strcasecmp( cargv[0], "loglevel" ) == 0 ) {
1730                         if ( cargc < 2 ) {
1731 #ifdef NEW_LOGGING
1732                                 LDAP_LOG( CONFIG, CRIT, 
1733                                         "%s: line %d: missing level in \"loglevel <level>\""
1734                                         " line.\n", fname, lineno , 0 );
1735 #else
1736                                 Debug( LDAP_DEBUG_ANY,
1737                     "%s: line %d: missing level in \"loglevel <level>\" line\n",
1738                                     fname, lineno, 0 );
1739 #endif
1740
1741                                 return( 1 );
1742                         }
1743
1744                         ldap_syslog = 0;
1745
1746                         for( i=1; i < cargc; i++ ) {
1747                                 ldap_syslog += atoi( cargv[1] );
1748                         }
1749
1750                 /* list of replicas of the data in this backend (master only) */
1751                 } else if ( strcasecmp( cargv[0], "replica" ) == 0 ) {
1752                         if ( cargc < 2 ) {
1753 #ifdef NEW_LOGGING
1754                                 LDAP_LOG( CONFIG, CRIT, 
1755                                         "%s: line %d: missing host in \"replica "
1756                                         " <host[:port]\" line\n", fname, lineno , 0 );
1757 #else
1758                                 Debug( LDAP_DEBUG_ANY,
1759             "%s: line %d: missing host in \"replica <host[:port]>\" line\n",
1760                                     fname, lineno, 0 );
1761 #endif
1762
1763                                 return( 1 );
1764                         }
1765                         if ( be == NULL ) {
1766 #ifdef NEW_LOGGING
1767                                 LDAP_LOG( CONFIG, INFO, 
1768                                             "%s: line %d: replica line must appear inside "
1769                                             "a database definition.\n", fname, lineno, 0);
1770 #else
1771                                 Debug( LDAP_DEBUG_ANY,
1772 "%s: line %d: replica line must appear inside a database definition\n",
1773                                     fname, lineno, 0 );
1774 #endif
1775                                 return 1;
1776
1777                         } else {
1778                                 int nr = -1;
1779
1780                                 for ( i = 1; i < cargc; i++ ) {
1781                                         if ( strncasecmp( cargv[i], "host=", 5 )
1782                                             == 0 ) {
1783                                                 nr = add_replica_info( be, 
1784                                                         cargv[i] + 5 );
1785                                                 break;
1786                                         }
1787                                 }
1788                                 if ( i == cargc ) {
1789 #ifdef NEW_LOGGING
1790                                         LDAP_LOG( CONFIG, INFO, 
1791                                                 "%s: line %d: missing host in \"replica\" line\n", 
1792                                                 fname, lineno , 0 );
1793 #else
1794                                         Debug( LDAP_DEBUG_ANY,
1795                     "%s: line %d: missing host in \"replica\" line\n",
1796                                             fname, lineno, 0 );
1797 #endif
1798                                         return 1;
1799
1800                                 } else if ( nr == -1 ) {
1801 #ifdef NEW_LOGGING
1802                                         LDAP_LOG( CONFIG, INFO, 
1803                                                    "%s: line %d: unable to add"
1804                                                    " replica \"%s\"\n",
1805                                                    fname, lineno, 
1806                                                    cargv[i] + 5 );
1807 #else
1808                                         Debug( LDAP_DEBUG_ANY,
1809                 "%s: line %d: unable to add replica \"%s\"\n",
1810                                                 fname, lineno, cargv[i] + 5 );
1811 #endif
1812                                         return 1;
1813                                 } else {
1814                                         for ( i = 1; i < cargc; i++ ) {
1815                                                 if ( strncasecmp( cargv[i], "suffix=", 7 ) == 0 ) {
1816
1817                                                         switch ( add_replica_suffix( be, nr, cargv[i] + 7 ) ) {
1818                                                         case 1:
1819 #ifdef NEW_LOGGING
1820                                                                 LDAP_LOG( CONFIG, INFO, 
1821                                                                         "%s: line %d: suffix \"%s\" in \"replica\""
1822                                                                         " line is not valid for backend(ignored)\n",
1823                                                                         fname, lineno, cargv[i] + 7 );
1824 #else
1825                                                                 Debug( LDAP_DEBUG_ANY,
1826                                                                                 "%s: line %d: suffix \"%s\" in \"replica\" line is not valid for backend (ignored)\n",
1827                                                                                 fname, lineno, cargv[i] + 7 );
1828 #endif
1829                                                                 break;
1830
1831                                                         case 2:
1832 #ifdef NEW_LOGGING
1833                                                                 LDAP_LOG( CONFIG, INFO, 
1834                                                                         "%s: line %d: unable to normalize suffix"
1835                                                                         " in \"replica\" line (ignored)\n",
1836                                                                         fname, lineno , 0 );
1837 #else
1838                                                                 Debug( LDAP_DEBUG_ANY,
1839                                                                                  "%s: line %d: unable to normalize suffix in \"replica\" line (ignored)\n",
1840                                                                                  fname, lineno, 0 );
1841 #endif
1842                                                                 break;
1843                                                         }
1844
1845                                                 } else if ( strncasecmp( cargv[i], "attr", 4 ) == 0 ) {
1846                                                         int exclude = 0;
1847                                                         char *arg = cargv[i] + 4;
1848
1849                                                         if ( arg[0] == '!' ) {
1850                                                                 arg++;
1851                                                                 exclude = 1;
1852                                                         }
1853
1854                                                         if ( arg[0] != '=' ) {
1855                                                                 continue;
1856                                                         }
1857
1858                                                         if ( add_replica_attrs( be, nr, arg + 1, exclude ) ) {
1859 #ifdef NEW_LOGGING
1860                                                                 LDAP_LOG( CONFIG, INFO, 
1861                                                                         "%s: line %d: attribute \"%s\" in "
1862                                                                         "\"replica\" line is unknown\n",
1863                                                                         fname, lineno, arg + 1 ); 
1864 #else
1865                                                                 Debug( LDAP_DEBUG_ANY,
1866                                                                                 "%s: line %d: attribute \"%s\" in \"replica\" line is unknown\n",
1867                                                                                 fname, lineno, arg + 1 );
1868 #endif
1869                                                                 return( 1 );
1870                                                         }
1871                                                 }
1872                                         }
1873                                 }
1874                         }
1875
1876                 /* dn of master entity allowed to write to replica */
1877                 } else if ( strcasecmp( cargv[0], "updatedn" ) == 0 ) {
1878                         if ( cargc < 2 ) {
1879 #ifdef NEW_LOGGING
1880                                 LDAP_LOG( CONFIG, CRIT, 
1881                                         "%s: line %d: missing dn in \"updatedn <dn>\""
1882                                         " line.\n", fname, lineno , 0 );
1883 #else
1884                                 Debug( LDAP_DEBUG_ANY,
1885                     "%s: line %d: missing dn in \"updatedn <dn>\" line\n",
1886                                     fname, lineno, 0 );
1887 #endif
1888
1889                                 return( 1 );
1890                         }
1891                         if ( be == NULL ) {
1892 #ifdef NEW_LOGGING
1893                                 LDAP_LOG( CONFIG, INFO, 
1894                                         "%s: line %d: updatedn line must appear inside "
1895                                         "a database definition\n", 
1896                                         fname, lineno , 0 );
1897 #else
1898                                 Debug( LDAP_DEBUG_ANY,
1899 "%s: line %d: updatedn line must appear inside a database definition\n",
1900                                     fname, lineno, 0 );
1901 #endif
1902                                 return 1;
1903
1904                         } else {
1905                                 struct berval dn;
1906
1907                                 if ( load_ucdata( NULL ) < 0 ) return 1;
1908
1909                                 dn.bv_val = cargv[1];
1910                                 dn.bv_len = strlen( cargv[1] );
1911
1912                                 rc = dnNormalize2( NULL, &dn, &be->be_update_ndn );
1913                                 if( rc != LDAP_SUCCESS ) {
1914 #ifdef NEW_LOGGING
1915                                         LDAP_LOG( CONFIG, CRIT, 
1916                                                 "%s: line %d: updatedn DN is invalid.\n",
1917                                                 fname, lineno , 0 );
1918 #else
1919                                         Debug( LDAP_DEBUG_ANY,
1920                                                 "%s: line %d: updatedn DN is invalid\n",
1921                                             fname, lineno, 0 );
1922 #endif
1923                                         return 1;
1924                                 }
1925                         }
1926
1927                 } else if ( strcasecmp( cargv[0], "updateref" ) == 0 ) {
1928                         if ( cargc < 2 ) {
1929 #ifdef NEW_LOGGING
1930                                 LDAP_LOG( CONFIG, CRIT, "%s: line %d: "
1931                                         "missing url in \"updateref <ldapurl>\" line.\n",
1932                                         fname, lineno , 0 );
1933 #else
1934                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1935                                         "missing url in \"updateref <ldapurl>\" line\n",
1936                                     fname, lineno, 0 );
1937 #endif
1938
1939                                 return( 1 );
1940                         }
1941                         if ( be == NULL ) {
1942 #ifdef NEW_LOGGING
1943                                 LDAP_LOG( CONFIG, INFO, "%s: line %d: updateref"
1944                                         " line must appear inside a database definition\n",
1945                                         fname, lineno , 0 );
1946 #else
1947                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: updateref"
1948                                         " line must appear inside a database definition\n",
1949                                         fname, lineno, 0 );
1950 #endif
1951                                 return 1;
1952
1953                         } else if ( !be->be_update_ndn.bv_len ) {
1954 #ifdef NEW_LOGGING
1955                                 LDAP_LOG( CONFIG, INFO, "%s: line %d: "
1956                                         "updateref line must come after updatedn.\n",
1957                                         fname, lineno , 0 );
1958 #else
1959                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1960                                         "updateref line must after updatedn.\n",
1961                                     fname, lineno, 0 );
1962 #endif
1963                                 return 1;
1964                         }
1965
1966                         if( validate_global_referral( cargv[1] ) ) {
1967 #ifdef NEW_LOGGING
1968                                 LDAP_LOG( CONFIG, CRIT, "%s: line %d: "
1969                                         "invalid URL (%s) in \"updateref\" line.\n",
1970                                         fname, lineno, cargv[1] );
1971 #else
1972                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1973                                         "invalid URL (%s) in \"updateref\" line.\n",
1974                                     fname, lineno, cargv[1] );
1975 #endif
1976                                 return 1;
1977                         }
1978
1979                         vals[0].bv_val = cargv[1];
1980                         vals[0].bv_len = strlen( vals[0].bv_val );
1981                         if( value_add( &be->be_update_refs, vals ) )
1982                                 return LDAP_OTHER;
1983
1984                 /* replication log file to which changes are appended */
1985                 } else if ( strcasecmp( cargv[0], "replogfile" ) == 0 ) {
1986                         if ( cargc < 2 ) {
1987 #ifdef NEW_LOGGING
1988                                 LDAP_LOG( CONFIG, CRIT, 
1989                                         "%s: line %d: missing filename in \"replogfile <filename>\""
1990                                         " line.\n", fname, lineno , 0 );
1991 #else
1992                                 Debug( LDAP_DEBUG_ANY,
1993             "%s: line %d: missing filename in \"replogfile <filename>\" line\n",
1994                                     fname, lineno, 0 );
1995 #endif
1996
1997                                 return( 1 );
1998                         }
1999                         if ( be ) {
2000                                 be->be_replogfile = ch_strdup( cargv[1] );
2001                         } else {
2002                                 replogfile = ch_strdup( cargv[1] );
2003                         }
2004
2005                 /* file from which to read additional rootdse attrs */
2006                 } else if ( strcasecmp( cargv[0], "rootDSE" ) == 0) {
2007                         if ( cargc < 2 ) {
2008 #ifdef NEW_LOGGING
2009                                 LDAP_LOG( CONFIG, CRIT, "%s: line %d: "
2010                                         "missing filename in \"rootDSE <filename>\" line.\n",
2011                                         fname, lineno , 0 );
2012 #else
2013                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
2014                                         "missing filename in \"rootDSE <filename>\" line.\n",
2015                                     fname, lineno, 0 );
2016 #endif
2017                                 return 1;
2018                         }
2019
2020                         if( read_root_dse_file( cargv[1] ) ) {
2021 #ifdef NEW_LOGGING
2022                                 LDAP_LOG( CONFIG, CRIT, "%s: line %d: "
2023                                         "could not read \"rootDSE <filename>\" line.\n",
2024                                         fname, lineno , 0 );
2025 #else
2026                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
2027                                         "could not read \"rootDSE <filename>\" line\n",
2028                                     fname, lineno, 0 );
2029 #endif
2030                                 return 1;
2031                         }
2032
2033                 /* maintain lastmodified{by,time} attributes */
2034                 } else if ( strcasecmp( cargv[0], "lastmod" ) == 0 ) {
2035                         if ( cargc < 2 ) {
2036 #ifdef NEW_LOGGING
2037                                 LDAP_LOG( CONFIG, CRIT, 
2038                                            "%s: line %d: missing on|off in \"lastmod <on|off>\""
2039                                            " line.\n", fname, lineno , 0 );
2040 #else
2041                                 Debug( LDAP_DEBUG_ANY,
2042             "%s: line %d: missing on|off in \"lastmod <on|off>\" line\n",
2043                                     fname, lineno, 0 );
2044 #endif
2045
2046                                 return( 1 );
2047                         }
2048                         if ( strcasecmp( cargv[1], "on" ) == 0 ) {
2049                                 if ( be ) {
2050                                         be->be_flags &= ~SLAP_BFLAG_NOLASTMOD;
2051                                 } else {
2052                                         lastmod = 1;
2053                                 }
2054                         } else {
2055                                 if ( be ) {
2056                                         be->be_flags |= SLAP_BFLAG_NOLASTMOD;
2057                                 } else {
2058                                         lastmod = 0;
2059                                 }
2060                         }
2061
2062 #ifdef SIGHUP
2063                 /* turn on/off gentle SIGHUP handling */
2064                 } else if ( strcasecmp( cargv[0], "gentlehup" ) == 0 ) {
2065                         if ( cargc < 2 ) {
2066                                 Debug( LDAP_DEBUG_ANY,
2067     "%s: line %d: missing on|off in \"gentlehup <on|off>\" line\n",
2068                                     fname, lineno, 0 );
2069                                 return( 1 );
2070                         }
2071                         if ( strcasecmp( cargv[1], "off" ) == 0 ) {
2072                                 global_gentlehup = 0;
2073                         } else {
2074                                 global_gentlehup = 1;
2075                         }
2076 #endif
2077
2078                 /* set idle timeout value */
2079                 } else if ( strcasecmp( cargv[0], "idletimeout" ) == 0 ) {
2080                         int i;
2081                         if ( cargc < 2 ) {
2082 #ifdef NEW_LOGGING
2083                                 LDAP_LOG( CONFIG, CRIT, 
2084                                         "%s: line %d: missing timeout value in "
2085                                         "\"idletimeout <seconds>\" line.\n", fname, lineno , 0 );
2086 #else
2087                                 Debug( LDAP_DEBUG_ANY,
2088             "%s: line %d: missing timeout value in \"idletimeout <seconds>\" line\n",
2089                                     fname, lineno, 0 );
2090 #endif
2091
2092                                 return( 1 );
2093                         }
2094
2095                         i = atoi( cargv[1] );
2096
2097                         if( i < 0 ) {
2098 #ifdef NEW_LOGGING
2099                                 LDAP_LOG( CONFIG, CRIT, 
2100                                         "%s: line %d: timeout value (%d) invalid "
2101                                         "\"idletimeout <seconds>\" line.\n", fname, lineno, i );
2102 #else
2103                                 Debug( LDAP_DEBUG_ANY,
2104             "%s: line %d: timeout value (%d) invalid \"idletimeout <seconds>\" line\n",
2105                                     fname, lineno, i );
2106 #endif
2107
2108                                 return( 1 );
2109                         }
2110
2111                         global_idletimeout = i;
2112
2113                 /* include another config file */
2114                 } else if ( strcasecmp( cargv[0], "include" ) == 0 ) {
2115                         if ( cargc < 2 ) {
2116 #ifdef NEW_LOGGING
2117                                 LDAP_LOG( CONFIG, CRIT, 
2118                                         "%s: line %d: missing filename in \"include "
2119                                         "<filename>\" line.\n", fname, lineno , 0 );
2120 #else
2121                                 Debug( LDAP_DEBUG_ANY,
2122     "%s: line %d: missing filename in \"include <filename>\" line\n",
2123                                     fname, lineno, 0 );
2124 #endif
2125
2126                                 return( 1 );
2127                         }
2128                         savefname = ch_strdup( cargv[1] );
2129                         savelineno = lineno;
2130
2131                         if ( read_config( savefname, depth+1 ) != 0 ) {
2132                                 return( 1 );
2133                         }
2134
2135                         free( savefname );
2136                         lineno = savelineno - 1;
2137
2138                 /* location of kerberos srvtab file */
2139                 } else if ( strcasecmp( cargv[0], "srvtab" ) == 0 ) {
2140                         if ( cargc < 2 ) {
2141 #ifdef NEW_LOGGING
2142                                 LDAP_LOG( CONFIG, CRIT, 
2143                                         "%s: line %d: missing filename in \"srvtab "
2144                                         "<filename>\" line.\n", fname, lineno , 0 );
2145 #else
2146                                 Debug( LDAP_DEBUG_ANY,
2147             "%s: line %d: missing filename in \"srvtab <filename>\" line\n",
2148                                     fname, lineno, 0 );
2149 #endif
2150
2151                                 return( 1 );
2152                         }
2153                         ldap_srvtab = ch_strdup( cargv[1] );
2154
2155 #ifdef SLAPD_MODULES
2156                 } else if (strcasecmp( cargv[0], "moduleload") == 0 ) {
2157                    if ( cargc < 2 ) {
2158 #ifdef NEW_LOGGING
2159                            LDAP_LOG( CONFIG, INFO, 
2160                                    "%s: line %d: missing filename in \"moduleload "
2161                                    "<filename>\" line.\n", fname, lineno , 0 );
2162 #else
2163                       Debug( LDAP_DEBUG_ANY,
2164                              "%s: line %d: missing filename in \"moduleload <filename>\" line\n",
2165                              fname, lineno, 0 );
2166 #endif
2167
2168                       exit( EXIT_FAILURE );
2169                    }
2170                    if (module_load(cargv[1], cargc - 2, (cargc > 2) ? cargv + 2 : NULL)) {
2171 #ifdef NEW_LOGGING
2172                            LDAP_LOG( CONFIG, CRIT, 
2173                                    "%s: line %d: failed to load or initialize module %s\n",
2174                                    fname, lineno, cargv[1] );
2175 #else
2176                       Debug( LDAP_DEBUG_ANY,
2177                              "%s: line %d: failed to load or initialize module %s\n",
2178                              fname, lineno, cargv[1]);
2179 #endif
2180
2181                       exit( EXIT_FAILURE );
2182                    }
2183                 } else if (strcasecmp( cargv[0], "modulepath") == 0 ) {
2184                    if ( cargc != 2 ) {
2185 #ifdef NEW_LOGGING
2186                            LDAP_LOG( CONFIG, INFO, 
2187                                   "%s: line %d: missing path in \"modulepath <path>\""
2188                                   " line\n", fname, lineno , 0 );
2189 #else
2190                       Debug( LDAP_DEBUG_ANY,
2191                              "%s: line %d: missing path in \"modulepath <path>\" line\n",
2192                              fname, lineno, 0 );
2193 #endif
2194
2195                       exit( EXIT_FAILURE );
2196                    }
2197                    if (module_path( cargv[1] )) {
2198 #ifdef NEW_LOGGING
2199                            LDAP_LOG( CONFIG, CRIT, 
2200                                   "%s: line %d: failed to set module search path to %s.\n",
2201                                   fname, lineno, cargv[1] );
2202 #else
2203                            Debug( LDAP_DEBUG_ANY,
2204                                   "%s: line %d: failed to set module search path to %s\n",
2205                                   fname, lineno, cargv[1]);
2206 #endif
2207
2208                       exit( EXIT_FAILURE );
2209                    }
2210                    
2211 #endif /*SLAPD_MODULES*/
2212
2213 #ifdef HAVE_TLS
2214                 } else if ( !strcasecmp( cargv[0], "TLSRandFile" ) ) {
2215                         rc = ldap_pvt_tls_set_option( NULL,
2216                                                       LDAP_OPT_X_TLS_RANDOM_FILE,
2217                                                       cargv[1] );
2218                         if ( rc )
2219                                 return rc;
2220
2221                 } else if ( !strcasecmp( cargv[0], "TLSCipherSuite" ) ) {
2222                         rc = ldap_pvt_tls_set_option( NULL,
2223                                                       LDAP_OPT_X_TLS_CIPHER_SUITE,
2224                                                       cargv[1] );
2225                         if ( rc )
2226                                 return rc;
2227
2228                 } else if ( !strcasecmp( cargv[0], "TLSCertificateFile" ) ) {
2229                         rc = ldap_pvt_tls_set_option( NULL,
2230                                                       LDAP_OPT_X_TLS_CERTFILE,
2231                                                       cargv[1] );
2232                         if ( rc )
2233                                 return rc;
2234
2235                 } else if ( !strcasecmp( cargv[0], "TLSCertificateKeyFile" ) ) {
2236                         rc = ldap_pvt_tls_set_option( NULL,
2237                                                       LDAP_OPT_X_TLS_KEYFILE,
2238                                                       cargv[1] );
2239                         if ( rc )
2240                                 return rc;
2241
2242                 } else if ( !strcasecmp( cargv[0], "TLSCACertificatePath" ) ) {
2243                         rc = ldap_pvt_tls_set_option( NULL,
2244                                                       LDAP_OPT_X_TLS_CACERTDIR,
2245                                                       cargv[1] );
2246                         if ( rc )
2247                                 return rc;
2248
2249                 } else if ( !strcasecmp( cargv[0], "TLSCACertificateFile" ) ) {
2250                         rc = ldap_pvt_tls_set_option( NULL,
2251                                                       LDAP_OPT_X_TLS_CACERTFILE,
2252                                                       cargv[1] );
2253                         if ( rc )
2254                                 return rc;
2255                 } else if ( !strcasecmp( cargv[0], "TLSVerifyClient" ) ) {
2256                         if ( isdigit( (unsigned char) cargv[1][0] ) ) {
2257                                 i = atoi(cargv[1]);
2258                                 rc = ldap_pvt_tls_set_option( NULL,
2259                                                       LDAP_OPT_X_TLS_REQUIRE_CERT,
2260                                                       &i );
2261                         } else {
2262                                 rc = ldap_int_tls_config( NULL,
2263                                                       LDAP_OPT_X_TLS_REQUIRE_CERT,
2264                                                       cargv[1] );
2265                         }
2266
2267                         if ( rc )
2268                                 return rc;
2269
2270 #endif
2271
2272                 } else if ( !strcasecmp( cargv[0], "reverse-lookup" ) ) {
2273 #ifdef SLAPD_RLOOKUPS
2274                         if ( cargc < 2 ) {
2275 #ifdef NEW_LOGGING
2276                                 LDAP_LOG( CONFIG, INFO, 
2277                                         "%s: line %d: reverse-lookup: missing \"on\" or \"off\"\n",
2278                                         fname, lineno , 0 );
2279 #else
2280                                 Debug( LDAP_DEBUG_ANY,
2281 "%s: line %d: reverse-lookup: missing \"on\" or \"off\"\n",
2282                                         fname, lineno, 0 );
2283 #endif
2284                                 return( 1 );
2285                         }
2286
2287                         if ( !strcasecmp( cargv[1], "on" ) ) {
2288                                 use_reverse_lookup = 1;
2289                         } else if ( !strcasecmp( cargv[1], "off" ) ) {
2290                                 use_reverse_lookup = 0;
2291                         } else {
2292 #ifdef NEW_LOGGING
2293                                 LDAP_LOG( CONFIG, INFO, 
2294                                         "%s: line %d: reverse-lookup: "
2295                                         "must be \"on\" (default) or \"off\"\n", fname, lineno, 0 );
2296 #else
2297                                 Debug( LDAP_DEBUG_ANY,
2298 "%s: line %d: reverse-lookup: must be \"on\" (default) or \"off\"\n",
2299                                         fname, lineno, 0 );
2300 #endif
2301                                 return( 1 );
2302                         }
2303
2304 #else /* !SLAPD_RLOOKUPS */
2305 #ifdef NEW_LOGGING
2306                         LDAP_LOG( CONFIG, INFO, 
2307                                 "%s: line %d: reverse lookups "
2308                                 "are not configured (ignored).\n", fname, lineno , 0 );
2309 #else
2310                         Debug( LDAP_DEBUG_ANY,
2311 "%s: line %d: reverse lookups are not configured (ignored).\n",
2312                                 fname, lineno, 0 );
2313 #endif
2314 #endif /* !SLAPD_RLOOKUPS */
2315
2316                 /* pass anything else to the current backend info/db config routine */
2317                 } else {
2318                         if ( bi != NULL ) {
2319                                 if ( bi->bi_config == 0 ) {
2320 #ifdef NEW_LOGGING
2321                                         LDAP_LOG( CONFIG, INFO, 
2322                                                 "%s: line %d: unknown directive \"%s\" inside "
2323                                                 "backend info definition (ignored).\n",
2324                                                 fname, lineno, cargv[0] );
2325 #else
2326                                         Debug( LDAP_DEBUG_ANY,
2327 "%s: line %d: unknown directive \"%s\" inside backend info definition (ignored)\n",
2328                                                 fname, lineno, cargv[0] );
2329 #endif
2330
2331                                 } else {
2332                                         if ( (*bi->bi_config)( bi, fname, lineno, cargc, cargv )
2333                                                 != 0 )
2334                                         {
2335                                                 return( 1 );
2336                                         }
2337                                 }
2338                         } else if ( be != NULL ) {
2339                                 if ( be->be_config == 0 ) {
2340 #ifdef NEW_LOGGING
2341                                         LDAP_LOG( CONFIG, INFO, 
2342                                                 "%s: line %d: uknown directive \"%s\" inside "
2343                                                 "backend database definition (ignored).\n",
2344                                                 fname, lineno, cargv[0] );
2345 #else
2346                                         Debug( LDAP_DEBUG_ANY,
2347 "%s: line %d: unknown directive \"%s\" inside backend database definition (ignored)\n",
2348                                         fname, lineno, cargv[0] );
2349 #endif
2350
2351                                 } else {
2352                                         if ( (*be->be_config)( be, fname, lineno, cargc, cargv )
2353                                                 != 0 )
2354                                         {
2355                                                 return( 1 );
2356                                         }
2357                                 }
2358                         } else {
2359 #ifdef NEW_LOGGING
2360                                 LDAP_LOG( CONFIG, INFO, 
2361                                         "%s: line %d: unknown directive \"%s\" outside backend "
2362                                         "info and database definitions (ignored).\n",
2363                                         fname, lineno, cargv[0] );
2364 #else
2365                                 Debug( LDAP_DEBUG_ANY,
2366 "%s: line %d: unknown directive \"%s\" outside backend info and database definitions (ignored)\n",
2367                                     fname, lineno, cargv[0] );
2368 #endif
2369
2370                         }
2371                 }
2372                 free( saveline );
2373         }
2374         fclose( fp );
2375
2376         if ( depth == 0 ) ch_free( cargv );
2377
2378         if ( !global_schemadn.bv_val ) {
2379                 ber_str2bv( SLAPD_SCHEMA_DN, sizeof(SLAPD_SCHEMA_DN)-1, 1,
2380                         &global_schemadn );
2381                 dnNormalize2( NULL, &global_schemadn, &global_schemandn );
2382         }
2383
2384         if ( load_ucdata( NULL ) < 0 ) return 1;
2385         return( 0 );
2386 }
2387
2388 static int
2389 fp_parse_line(
2390     int         lineno,
2391     char        *line
2392 )
2393 {
2394         char *  token;
2395         char *  logline;
2396         char    logbuf[sizeof("pseudorootpw ***")];
2397
2398         cargc = 0;
2399         token = strtok_quote( line, " \t" );
2400
2401         logline = line;
2402
2403         if ( token && ( strcasecmp( token, "rootpw" ) == 0 ||
2404                 strcasecmp( token, "replica" ) == 0 ||          /* contains "credentials" */
2405                 strcasecmp( token, "bindpw" ) == 0 ||           /* used in back-ldap */
2406                 strcasecmp( token, "pseudorootpw" ) == 0 ||     /* used in back-meta */
2407                 strcasecmp( token, "dbpasswd" ) == 0 ) )        /* used in back-sql */
2408         {
2409                 snprintf( logline = logbuf, sizeof logbuf, "%s ***", token );
2410         }
2411
2412         if ( strtok_quote_ptr ) {
2413                 *strtok_quote_ptr = ' ';
2414         }
2415
2416 #ifdef NEW_LOGGING
2417         LDAP_LOG( CONFIG, DETAIL1, "line %d (%s)\n", lineno, logline , 0 );
2418 #else
2419         Debug( LDAP_DEBUG_CONFIG, "line %d (%s)\n", lineno, logline, 0 );
2420 #endif
2421
2422         if ( strtok_quote_ptr ) {
2423                 *strtok_quote_ptr = '\0';
2424         }
2425
2426         for ( ; token != NULL; token = strtok_quote( NULL, " \t" ) ) {
2427                 if ( cargc == cargv_size - 1 ) {
2428                         char **tmp;
2429                         tmp = ch_realloc( cargv, (cargv_size + ARGS_STEP) *
2430                                             sizeof(*cargv) );
2431                         if ( tmp == NULL ) {
2432 #ifdef NEW_LOGGING
2433                                 LDAP_LOG( CONFIG, ERR, "line %d: out of memory\n", lineno, 0,0 );
2434 #else
2435                                 Debug( LDAP_DEBUG_ANY, 
2436                                                 "line %d: out of memory\n", 
2437                                                 lineno, 0, 0 );
2438 #endif
2439                                 return -1;
2440                         }
2441                         cargv = tmp;
2442                         cargv_size += ARGS_STEP;
2443                 }
2444                 cargv[cargc++] = token;
2445         }
2446         cargv[cargc] = NULL;
2447         return 0;
2448 }
2449
2450 static char *
2451 strtok_quote( char *line, char *sep )
2452 {
2453         int             inquote;
2454         char            *tmp;
2455         static char     *next;
2456
2457         strtok_quote_ptr = NULL;
2458         if ( line != NULL ) {
2459                 next = line;
2460         }
2461         while ( *next && strchr( sep, *next ) ) {
2462                 next++;
2463         }
2464
2465         if ( *next == '\0' ) {
2466                 next = NULL;
2467                 return( NULL );
2468         }
2469         tmp = next;
2470
2471         for ( inquote = 0; *next; ) {
2472                 switch ( *next ) {
2473                 case '"':
2474                         if ( inquote ) {
2475                                 inquote = 0;
2476                         } else {
2477                                 inquote = 1;
2478                         }
2479                         AC_MEMCPY( next, next + 1, strlen( next + 1 ) + 1 );
2480                         break;
2481
2482                 case '\\':
2483                         if ( next[1] )
2484                                 AC_MEMCPY( next,
2485                                             next + 1, strlen( next + 1 ) + 1 );
2486                         next++;         /* dont parse the escaped character */
2487                         break;
2488
2489                 default:
2490                         if ( ! inquote ) {
2491                                 if ( strchr( sep, *next ) != NULL ) {
2492                                         strtok_quote_ptr = next;
2493                                         *next++ = '\0';
2494                                         return( tmp );
2495                                 }
2496                         }
2497                         next++;
2498                         break;
2499                 }
2500         }
2501
2502         return( tmp );
2503 }
2504
2505 static char     buf[BUFSIZ];
2506 static char     *line;
2507 static size_t lmax, lcur;
2508
2509 #define CATLINE( buf ) \
2510         do { \
2511                 size_t len = strlen( buf ); \
2512                 while ( lcur + len + 1 > lmax ) { \
2513                         lmax += BUFSIZ; \
2514                         line = (char *) ch_realloc( line, lmax ); \
2515                 } \
2516                 strcpy( line + lcur, buf ); \
2517                 lcur += len; \
2518         } while( 0 )
2519
2520 static char *
2521 fp_getline( FILE *fp, int *lineno )
2522 {
2523         char            *p;
2524
2525         lcur = 0;
2526         CATLINE( buf );
2527         (*lineno)++;
2528
2529         /* hack attack - keeps us from having to keep a stack of bufs... */
2530         if ( strncasecmp( line, "include", 7 ) == 0 ) {
2531                 buf[0] = '\0';
2532                 return( line );
2533         }
2534
2535         while ( fgets( buf, sizeof(buf), fp ) != NULL ) {
2536                 /* trim off \r\n or \n */
2537                 if ( (p = strchr( buf, '\n' )) != NULL ) {
2538                         if( p > buf && p[-1] == '\r' ) --p;
2539                         *p = '\0';
2540                 }
2541                 
2542                 /* trim off trailing \ and append the next line */
2543                 if ( line[ 0 ] != '\0' 
2544                                 && (p = line + strlen( line ) - 1)[ 0 ] == '\\'
2545                                 && p[ -1 ] != '\\' ) {
2546                         p[ 0 ] = '\0';
2547                         lcur--;
2548
2549                 } else {
2550                         if ( ! isspace( (unsigned char) buf[0] ) ) {
2551                                 return( line );
2552                         }
2553
2554                         /* change leading whitespace to a space */
2555                         buf[0] = ' ';
2556                 }
2557
2558                 CATLINE( buf );
2559                 (*lineno)++;
2560         }
2561         buf[0] = '\0';
2562
2563         return( line[0] ? line : NULL );
2564 }
2565
2566 static void
2567 fp_getline_init( int *lineno )
2568 {
2569         *lineno = -1;
2570         buf[0] = '\0';
2571 }
2572
2573 /* Loads ucdata, returns 1 if loading, 0 if already loaded, -1 on error */
2574 static int
2575 load_ucdata( char *path )
2576 {
2577         static int loaded = 0;
2578         int err;
2579         
2580         if ( loaded ) {
2581                 return( 0 );
2582         }
2583         err = ucdata_load( path ? path : SLAPD_DEFAULT_UCDATA, UCDATA_ALL );
2584         if ( err ) {
2585 #ifdef NEW_LOGGING
2586                 LDAP_LOG( CONFIG, CRIT, 
2587                         "load_ucdata: Error %d loading ucdata.\n", err, 0,0 );
2588 #else
2589                 Debug( LDAP_DEBUG_ANY, "error loading ucdata (error %d)\n",
2590                        err, 0, 0 );
2591 #endif
2592
2593                 return( -1 );
2594         }
2595         loaded = 1;
2596         return( 1 );
2597 }
2598
2599 void
2600 config_destroy( )
2601 {
2602         ucdata_unload( UCDATA_ALL );
2603         free( global_schemandn.bv_val );
2604         free( global_schemadn.bv_val );
2605         free( line );
2606         if ( slapd_args_file )
2607                 free ( slapd_args_file );
2608         if ( slapd_pid_file )
2609                 free ( slapd_pid_file );
2610         acl_destroy( global_acl, NULL );
2611 }