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