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