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