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