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