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