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