]> git.sur5r.net Git - openldap/blob - servers/slapd/config.c
Add support for separate max incoming for anonymous and authenticated
[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                 /* set SASL host */
507                 } else if ( strcasecmp( cargv[0], "sasl-host" ) == 0 ) {
508                         if ( cargc < 2 ) {
509 #ifdef NEW_LOGGING
510                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
511                                            "%s: line %d: missing host in \"sasl-host <host>\" line\n",
512                                            fname, lineno ));
513 #else
514                                 Debug( LDAP_DEBUG_ANY,
515             "%s: line %d: missing host in \"sasl-host <host>\" line\n",
516                                     fname, lineno, 0 );
517 #endif
518
519                                 return( 1 );
520                         }
521
522                         if ( global_host != NULL ) {
523 #ifdef NEW_LOGGING
524                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
525                                            "%s: line %d: already set sasl-host!\n",
526                                            fname, lineno ));
527 #else
528                                 Debug( LDAP_DEBUG_ANY,
529                                         "%s: line %d: already set sasl-host!\n",
530                                         fname, lineno, 0 );
531 #endif
532
533                                 return 1;
534
535                         } else {
536                                 global_host = ch_strdup( cargv[1] );
537                         }
538
539                 /* set SASL realm */
540                 } else if ( strcasecmp( cargv[0], "sasl-realm" ) == 0 ) {
541                         if ( cargc < 2 ) {
542 #ifdef NEW_LOGGING
543                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
544                                            "%s: line %d: missing realm in \"sasl-realm <realm>\" line.\n",
545                                            fname, lineno ));
546 #else
547                                 Debug( LDAP_DEBUG_ANY,
548             "%s: line %d: missing realm in \"sasl-realm <realm>\" line\n",
549                                     fname, lineno, 0 );
550 #endif
551
552                                 return( 1 );
553                         }
554
555                         if ( global_realm != NULL ) {
556 #ifdef NEW_LOGGING
557                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
558                                            "%s: line %d: already set sasl-realm!\n",
559                                            fname, lineno ));
560 #else
561                                 Debug( LDAP_DEBUG_ANY,
562                                         "%s: line %d: already set sasl-realm!\n",
563                                         fname, lineno, 0 );
564 #endif
565
566                                 return 1;
567
568                         } else {
569                                 global_realm = ch_strdup( cargv[1] );
570                         }
571
572                 } else if ( !strcasecmp( cargv[0], "sasl-regexp" ) 
573                         || !strcasecmp( cargv[0], "saslregexp" ) )
574                 {
575                         int rc;
576                         if ( cargc != 3 ) {
577 #ifdef NEW_LOGGING
578                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
579                                            "%s: line %d: need 2 args in "
580                                            "\"saslregexp <match> <replace>\"\n",
581                                            fname, lineno ));
582 #else
583                                 Debug( LDAP_DEBUG_ANY, 
584                                 "%s: line %d: need 2 args in \"saslregexp <match> <replace>\"\n",
585                                     fname, lineno, 0 );
586 #endif
587
588                                 return( 1 );
589                         }
590                         rc = slap_sasl_regexp_config( cargv[1], cargv[2] );
591                         if ( rc ) {
592                                 return rc;
593                         }
594
595                 /* SASL security properties */
596                 } else if ( strcasecmp( cargv[0], "sasl-secprops" ) == 0 ) {
597                         char *txt;
598
599                         if ( cargc < 2 ) {
600 #ifdef NEW_LOGGING
601                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
602                                            "%s: line %d: missing flags in "
603                                            "\"sasl-secprops <properties>\" line\n",
604                                            fname, lineno ));
605 #else
606                                 Debug( LDAP_DEBUG_ANY,
607             "%s: line %d: missing flags in \"sasl-secprops <properties>\" line\n",
608                                     fname, lineno, 0 );
609 #endif
610
611                                 return 1;
612                         }
613
614                         txt = slap_sasl_secprops( cargv[1] );
615                         if ( txt != NULL ) {
616 #ifdef NEW_LOGGING
617                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
618                                            "%s: line %d sas-secprops: %s\n",
619                                            fname, lineno, txt ));
620 #else
621                                 Debug( LDAP_DEBUG_ANY,
622             "%s: line %d: sasl-secprops: %s\n",
623                                     fname, lineno, txt );
624 #endif
625
626                                 return 1;
627                         }
628
629                 } else if ( strcasecmp( cargv[0], "sasl-external-x509dn-convert" ) == 0 ) {
630                         sasl_external_x509dn_convert++;
631
632                 /* set UCDATA path */
633                 } else if ( strcasecmp( cargv[0], "ucdata-path" ) == 0 ) {
634                         int err;
635                         if ( cargc < 2 ) {
636 #ifdef NEW_LOGGING
637                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
638                                            "%s: line %d: missing path in "
639                                            "\"ucdata-path <path>\" line.\n",
640                                            fname, lineno ));
641 #else
642                                 Debug( LDAP_DEBUG_ANY,
643             "%s: line %d: missing path in \"ucdata-path <path>\" line\n",
644                                     fname, lineno, 0 );
645 #endif
646
647                                 return( 1 );
648                         }
649
650                         err = load_ucdata( cargv[1] );
651                         if ( err <= 0 ) {
652                                 if ( err == 0 ) {
653 #ifdef NEW_LOGGING
654                                         LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
655                                                    "%s: line %d: ucdata already loaded, ucdata-path "
656                                                    "must be set earlier in the file and/or be "
657                                                    "specified only once!\n",
658                                                    fname, lineno ));
659 #else
660                                         Debug( LDAP_DEBUG_ANY,
661                                                "%s: line %d: ucdata already loaded, ucdata-path must be set earlier in the file and/or be specified only once!\n",
662                                                fname, lineno, 0 );
663 #endif
664
665                                 }
666                                 return( 1 );
667                         }
668
669                 /* set time limit */
670                 } else if ( strcasecmp( cargv[0], "sizelimit" ) == 0 ) {
671                         if ( cargc < 2 ) {
672 #ifdef NEW_LOGGING
673                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
674                                            "%s: line %d: missing limit in \"sizelimit <limit>\" line.\n",
675                                            fname, lineno ));
676 #else
677                                 Debug( LDAP_DEBUG_ANY,
678             "%s: line %d: missing limit in \"sizelimit <limit>\" line\n",
679                                     fname, lineno, 0 );
680 #endif
681
682                                 return( 1 );
683                         }
684                         if ( be == NULL ) {
685                                 defsize = atoi( cargv[1] );
686                         } else {
687                                 be->be_sizelimit = atoi( cargv[1] );
688                         }
689
690                 /* set time limit */
691                 } else if ( strcasecmp( cargv[0], "timelimit" ) == 0 ) {
692                         if ( cargc < 2 ) {
693 #ifdef NEW_LOGGING
694                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
695                                            "%s: line %d missing limit in \"timelimit <limit>\" line.\n",
696                                            fname, lineno ));
697 #else
698                                 Debug( LDAP_DEBUG_ANY,
699             "%s: line %d: missing limit in \"timelimit <limit>\" line\n",
700                                     fname, lineno, 0 );
701 #endif
702
703                                 return( 1 );
704                         }
705                         if ( be == NULL ) {
706                                 deftime = atoi( cargv[1] );
707                         } else {
708                                 be->be_timelimit = atoi( cargv[1] );
709                         }
710
711                 /* set database suffix */
712                 } else if ( strcasecmp( cargv[0], "suffix" ) == 0 ) {
713                         Backend *tmp_be;
714                         if ( cargc < 2 ) {
715 #ifdef NEW_LOGGING
716                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
717                                            "%s: line %d: missing dn in \"suffix <dn>\" line.\n",
718                                            fname, lineno ));
719 #else
720                                 Debug( LDAP_DEBUG_ANY,
721                     "%s: line %d: missing dn in \"suffix <dn>\" line\n",
722                                     fname, lineno, 0 );
723 #endif
724
725                                 return( 1 );
726                         } else if ( cargc > 2 ) {
727 #ifdef NEW_LOGGING
728                                 LDAP_LOG(( "config", LDAP_LEVEL_INFO,
729                                            "%s: line %d: extra cruft after <dn> in \"suffix %s\""
730                                            " line (ignored).\n", fname, lineno, cargv[1] ));
731 #else
732                                 Debug( LDAP_DEBUG_ANY,
733     "%s: line %d: extra cruft after <dn> in \"suffix %s\" line (ignored)\n",
734                                     fname, lineno, cargv[1] );
735 #endif
736
737                         }
738                         if ( be == NULL ) {
739 #ifdef NEW_LOGGING
740                                 LDAP_LOG(( "config", LDAP_LEVEL_INFO,
741                                            "%s: line %d: suffix line must appear inside a database "
742                                            "definition (ignored).\n", fname, lineno ));
743 #else
744                                 Debug( LDAP_DEBUG_ANY,
745 "%s: line %d: suffix line must appear inside a database definition (ignored)\n",
746                                     fname, lineno, 0 );
747 #endif
748
749                         } else if ( ( tmp_be = select_backend( cargv[1], 0 ) ) == be ) {
750 #ifdef NEW_LOGGING
751                                 LDAP_LOG(( "config", LDAP_LEVEL_INFO,
752                                            "%s: line %d: suffix already served by this backend "
753                                            "(ignored)\n", fname, lineno ));
754 #else
755                                 Debug( LDAP_DEBUG_ANY,
756 "%s: line %d: suffix already served by this backend (ignored)\n",
757                                     fname, lineno, 0 );
758 #endif
759
760                         } else if ( tmp_be  != NULL ) {
761 #ifdef NEW_LOGGING
762                                 LDAP_LOG(( "config", LDAP_LEVEL_INFO,
763                                            "%s: line %d: suffix already served by a preceding "
764                                            "backend \"%s\" (ignored)\n", fname, lineno,
765                                            tmp_be->be_suffix[0] ));
766 #else
767                                 Debug( LDAP_DEBUG_ANY,
768 "%s: line %d: suffix already served by a preceeding backend \"%s\" (ignored)\n",
769                                     fname, lineno, tmp_be->be_suffix[0] );
770 #endif
771
772                         } else {
773                                 char *dn = ch_strdup( cargv[1] );
774                                 if ( load_ucdata( NULL ) < 0 ) {
775                                         return( 1 );
776                                 }
777                                 if( dn_validate( dn ) == NULL ) {
778 #ifdef NEW_LOGGING
779                                         LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
780                                                    "%s: line %d: suffix DN invalid\"%s\"\n",
781                                                    fname, lineno, cargv[1] ));
782 #else
783                                         Debug( LDAP_DEBUG_ANY, "%s: line %d: "
784                                                 "suffix DN invalid \"%s\"\n",
785                                         fname, lineno, cargv[1] );
786 #endif
787
788                                         return 1;
789
790                                 } else if( *dn == '\0' && default_search_nbase != NULL ) {
791 #ifdef NEW_LOGGING
792                                         LDAP_LOG(( "config", LDAP_LEVEL_INFO,
793                                                    "%s: line %d: suffix DN empty and default search "
794                                                    "base provided \"%s\" (assuming okay).\n",
795                                                    fname, lineno, default_search_base ));
796 #else
797                                         Debug( LDAP_DEBUG_ANY, "%s: line %d: "
798                                                 "suffix DN empty and default "
799                                                 "search base provided \"%s\" (assuming okay)\n",
800                                         fname, lineno, default_search_base );
801 #endif
802
803                                 }
804                                 charray_add( &be->be_suffix, dn );
805                                 (void) ldap_pvt_str2upper( dn );
806                                 charray_add( &be->be_nsuffix, dn );
807                                 free( dn );
808                         }
809
810                 /* set database suffixAlias */
811                 } else if ( strcasecmp( cargv[0], "suffixAlias" ) == 0 ) {
812                         Backend *tmp_be;
813                         if ( cargc < 2 ) {
814 #ifdef NEW_LOGGING
815                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
816                                            "%s: line %d: missing alias and aliased_dn in "
817                                            "\"suffixAlias <alias> <aliased_dn>\" line.\n",
818                                            fname, lineno ));
819 #else
820                                 Debug( LDAP_DEBUG_ANY,
821 "%s: line %d: missing alias and aliased_dn in \"suffixAlias <alias> <aliased_dn>\" line\n",
822                                         fname, lineno, 0 );
823 #endif
824
825                                 return( 1 );
826                         } else if ( cargc < 3 ) {
827 #ifdef NEW_LOGGING
828                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
829                                            "%s: line %d: missing aliased_dn in "
830                                            "\"suffixAlias <alias> <aliased_dn>\" line\n",
831                                            fname, lineno ));
832 #else
833                                 Debug( LDAP_DEBUG_ANY,
834 "%s: line %d: missing aliased_dn in \"suffixAlias <alias> <aliased_dn>\" line\n",
835                                 fname, lineno, 0 );
836 #endif
837
838                                 return( 1 );
839                         } else if ( cargc > 3 ) {
840 #ifdef NEW_LOGGING
841                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
842                                            "%s: line %d: extra cruft in suffixAlias line (ignored)\n",
843                                            fname, lineno ));
844 #else
845                                 Debug( LDAP_DEBUG_ANY,
846                                         "%s: line %d: extra cruft in suffixAlias line (ignored)\n",
847                                 fname, lineno, 0 );
848 #endif
849
850                         }
851
852                         if ( be == NULL ) {
853 #ifdef NEW_LOGGING
854                                 LDAP_LOG(( "config", LDAP_LEVEL_INFO,
855                                            "%s: line %d: suffixAlias line must appear inside a "
856                                            "database definition (ignored).\n", fname, lineno ));
857 #else
858                                 Debug( LDAP_DEBUG_ANY,
859                                         "%s: line %d: suffixAlias line"
860                                         " must appear inside a database definition (ignored)\n",
861                                         fname, lineno, 0 );
862 #endif
863
864                         } else if ( (tmp_be = select_backend( cargv[1], 0 )) != NULL ) {
865 #ifdef NEW_LOGGING
866                                 LDAP_LOG(( "config", LDAP_LEVEL_INFO,
867                                            "%s: line %d: suffixAlias served by a preceeding "
868                                            "backend \"%s\" (ignored).\n", fname, lineno,
869                                            tmp_be->be_suffix[0] ));
870 #else
871                                 Debug( LDAP_DEBUG_ANY,
872                                         "%s: line %d: suffixAlias served by"
873                                         "  a preceeding backend \"%s\" (ignored)\n",
874                                         fname, lineno, tmp_be->be_suffix[0] );
875 #endif
876
877
878                         } else if ( (tmp_be = select_backend( cargv[2], 0 )) != NULL ) {
879 #ifdef NEW_LOGGING
880                                 LDAP_LOG(( "config", LDAP_LEVEL_INFO,
881                                            "%s: line %d: suffixAlias derefs to a different backend "
882                                            "a preceeding backend \"%s\" (ignored)\n",
883                                            fname, lineno, tmp_be->be_suffix[0] ));
884 #else
885                                 Debug( LDAP_DEBUG_ANY,
886                                         "%s: line %d: suffixAlias derefs to differnet backend"
887                                         "  a preceeding backend \"%s\" (ignored)\n",
888                                         fname, lineno, tmp_be->be_suffix[0] );
889 #endif
890
891
892                         } else {
893                                 char *alias, *aliased_dn;
894
895                                 alias = ch_strdup( cargv[1] );
896                                 if ( load_ucdata( NULL ) < 0 ) {
897                                         return( 1 );
898                                 }
899                                 (void) dn_normalize( alias );
900
901                                 aliased_dn = ch_strdup( cargv[2] );
902                                 (void) dn_normalize( aliased_dn );
903
904                                 charray_add( &be->be_suffixAlias, alias );
905                                 charray_add( &be->be_suffixAlias, aliased_dn );
906
907                                 free(alias);
908                                 free(aliased_dn);
909                         }
910
911                /* set max deref depth */
912                } else if ( strcasecmp( cargv[0], "maxDerefDepth" ) == 0 ) {
913                                         int i;
914                        if ( cargc < 2 ) {
915 #ifdef NEW_LOGGING
916                                LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
917                                           "%s: line %d: missing depth in \"maxDerefDepth <depth>\""
918                                           " line\n", fname, lineno ));
919 #else
920                                Debug( LDAP_DEBUG_ANY,
921                    "%s: line %d: missing depth in \"maxDerefDepth <depth>\" line\n",
922                                    fname, lineno, 0 );
923 #endif
924
925                                return( 1 );
926                        }
927                        if ( be == NULL ) {
928 #ifdef NEW_LOGGING
929                                LDAP_LOG(( "config", LDAP_LEVEL_INFO,
930                                           "%s: line %d: depth line must appear inside a database "
931                                           "definition (ignored)\n", fname, lineno ));
932 #else
933                                Debug( LDAP_DEBUG_ANY,
934 "%s: line %d: depth line must appear inside a database definition (ignored)\n",
935                                    fname, lineno, 0 );
936 #endif
937
938                        } else if ((i = atoi(cargv[1])) < 0) {
939 #ifdef NEW_LOGGING
940                                LDAP_LOG(( "config", LDAP_LEVEL_INFO,
941                                           "%s: line %d: depth must be positive (ignored).\n",
942                                           fname, lineno ));
943 #else
944                                Debug( LDAP_DEBUG_ANY,
945 "%s: line %d: depth must be positive (ignored)\n",
946                                    fname, lineno, 0 );
947 #endif
948
949
950                        } else {
951                            be->be_max_deref_depth = i;
952                                            }
953
954
955                 /* set magic "root" dn for this database */
956                 } else if ( strcasecmp( cargv[0], "rootdn" ) == 0 ) {
957                         if ( cargc < 2 ) {
958 #ifdef NEW_LOGGING
959                                 LDAP_LOG(( "config", LDAP_LEVEL_INFO,
960                                            "%s: line %d: missing dn in \"rootdn <dn>\" line.\n",
961                                            fname, lineno ));
962 #else
963                                 Debug( LDAP_DEBUG_ANY,
964                     "%s: line %d: missing dn in \"rootdn <dn>\" line\n",
965                                     fname, lineno, 0 );
966 #endif
967
968                                 return( 1 );
969                         }
970                         if ( be == NULL ) {
971 #ifdef NEW_LOGGING
972                                 LDAP_LOG(( "config", LDAP_LEVEL_INFO,
973                                            "%s: line %d: rootdn line must appear inside a database "
974                                            "definition (ignored).\n", fname, lineno ));
975 #else
976                                 Debug( LDAP_DEBUG_ANY,
977 "%s: line %d: rootdn line must appear inside a database definition (ignored)\n",
978                                     fname, lineno, 0 );
979 #endif
980
981                         } else {
982                                 be->be_root_dn = ch_strdup( cargv[1] );
983                                 be->be_root_ndn = ch_strdup( cargv[1] );
984
985                                 if ( load_ucdata( NULL ) < 0 ) {
986                                         return( 1 );
987                                 }
988                                 if( dn_normalize( be->be_root_ndn ) == NULL ) {
989                                         free( be->be_root_dn );
990                                         free( be->be_root_ndn );
991 #ifdef NEW_LOGGING
992                                         LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
993                                                    "%s: line %d: rootdn DN is invalid.\n",
994                                                    fname, lineno ));
995 #else
996                                         Debug( LDAP_DEBUG_ANY,
997 "%s: line %d: rootdn DN is invalid\n",
998                                            fname, lineno, 0 );
999 #endif
1000
1001                                         return( 1 );
1002                                 }
1003                         }
1004
1005                 /* set super-secret magic database password */
1006                 } else if ( strcasecmp( cargv[0], "rootpw" ) == 0 ) {
1007                         if ( cargc < 2 ) {
1008 #ifdef NEW_LOGGING
1009                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
1010                                            "%s: line %d: missing passwd in \"rootpw <passwd>\""
1011                                            " line\n", fname, lineno ));
1012 #else
1013                                 Debug( LDAP_DEBUG_ANY,
1014             "%s: line %d: missing passwd in \"rootpw <passwd>\" line\n",
1015                                     fname, lineno, 0 );
1016 #endif
1017
1018                                 return( 1 );
1019                         }
1020                         if ( be == NULL ) {
1021 #ifdef NEW_LOGGING
1022                                 LDAP_LOG(( "config", LDAP_LEVEL_INFO,
1023                                            "%s: line %d: rootpw line must appear inside a database "
1024                                            "definition (ignored)\n", fname, lineno ));
1025 #else
1026                                 Debug( LDAP_DEBUG_ANY,
1027 "%s: line %d: rootpw line must appear inside a database definition (ignored)\n",
1028                                     fname, lineno, 0 );
1029 #endif
1030
1031                         } else {
1032                                 be->be_root_pw.bv_val = ch_strdup( cargv[1] );
1033                                 be->be_root_pw.bv_len = strlen( be->be_root_pw.bv_val );
1034                         }
1035
1036                 /* make this database read-only */
1037                 } else if ( strcasecmp( cargv[0], "readonly" ) == 0 ) {
1038                         if ( cargc < 2 ) {
1039 #ifdef NEW_LOGGING
1040                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
1041                                            "%s: line %d: missing on|off in \"readonly <on|off>\" line.\n",
1042                                            fname, lineno ));
1043 #else
1044                                 Debug( LDAP_DEBUG_ANY,
1045             "%s: line %d: missing on|off in \"readonly <on|off>\" line\n",
1046                                     fname, lineno, 0 );
1047 #endif
1048
1049                                 return( 1 );
1050                         }
1051                         if ( be == NULL ) {
1052                                 if ( strcasecmp( cargv[1], "on" ) == 0 ) {
1053                                         global_restrictops |= SLAP_RESTRICT_OP_WRITES;
1054                                 } else {
1055                                         global_restrictops &= ~SLAP_RESTRICT_OP_WRITES;
1056                                 }
1057                         } else {
1058                                 if ( strcasecmp( cargv[1], "on" ) == 0 ) {
1059                                         be->be_restrictops |= SLAP_RESTRICT_OP_WRITES;
1060                                 } else {
1061                                         be->be_restrictops &= ~SLAP_RESTRICT_OP_WRITES;
1062                                 }
1063                         }
1064
1065
1066                 /* allow these features */
1067                 } else if ( strcasecmp( cargv[0], "allows" ) == 0 ||
1068                         strcasecmp( cargv[0], "allow" ) == 0 )
1069                 {
1070                         slap_mask_t     allows;
1071
1072                         if ( be != NULL ) {
1073 #ifdef NEW_LOGGING
1074                                 LDAP_LOG(( "config", LDAP_LEVEL_INFO,
1075                                            "%s: line %d: allow line must appear prior to "
1076                                            "database definitions.\n", fname, lineno ));
1077 #else
1078                                 Debug( LDAP_DEBUG_ANY,
1079 "%s: line %d: allow line must appear prior to database definitions\n",
1080                                     fname, lineno, 0 );
1081 #endif
1082
1083                         }
1084
1085                         if ( cargc < 2 ) {
1086 #ifdef NEW_LOGGING
1087                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
1088                                            "%s: line %d: missing feature(s) in \"allow <features>\""
1089                                            " line\n", fname, lineno ));
1090 #else
1091                                 Debug( LDAP_DEBUG_ANY,
1092             "%s: line %d: missing feature(s) in \"allow <features>\" line\n",
1093                                     fname, lineno, 0 );
1094 #endif
1095
1096                                 return( 1 );
1097                         }
1098
1099                         allows = 0;
1100
1101                         for( i=1; i < cargc; i++ ) {
1102                                 if( strcasecmp( cargv[i], "tls_2_anon" ) == 0 ) {
1103                                         allows |= SLAP_ALLOW_TLS_2_ANON;
1104
1105                                 } else if( strcasecmp( cargv[i], "none" ) != 0 ) {
1106 #ifdef NEW_LOGGING
1107                                         LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
1108                                                    "%s: line %d: unknown feature %s in "
1109                                                    "\"allow <features>\" line.\n",
1110                                                    fname, lineno, cargv[1] ));
1111 #else
1112                                         Debug( LDAP_DEBUG_ANY,
1113                     "%s: line %d: unknown feature %s in \"allow <features>\" line\n",
1114                                             fname, lineno, cargv[i] );
1115 #endif
1116
1117                                         return( 1 );
1118                                 }
1119                         }
1120
1121                         global_allows = allows;
1122
1123                 /* disallow these features */
1124                 } else if ( strcasecmp( cargv[0], "disallows" ) == 0 ||
1125                         strcasecmp( cargv[0], "disallow" ) == 0 )
1126                 {
1127                         slap_mask_t     disallows;
1128
1129                         if ( be != NULL ) {
1130 #ifdef NEW_LOGGING
1131                                 LDAP_LOG(( "config", LDAP_LEVEL_INFO,
1132                                            "%s: line %d: disallow line must appear prior to "
1133                                            "database definitions.\n", fname, lineno ));
1134 #else
1135                                 Debug( LDAP_DEBUG_ANY,
1136 "%s: line %d: disallow line must appear prior to database definitions\n",
1137                                     fname, lineno, 0 );
1138 #endif
1139
1140                         }
1141
1142                         if ( cargc < 2 ) {
1143 #ifdef NEW_LOGGING
1144                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
1145                                            "%s: line %d: missing feature(s) in \"disallow <features>\""
1146                                            " line.\n", fname, lineno ));
1147 #else
1148                                 Debug( LDAP_DEBUG_ANY,
1149             "%s: line %d: missing feature(s) in \"disallow <features>\" line\n",
1150                                     fname, lineno, 0 );
1151 #endif
1152
1153                                 return( 1 );
1154                         }
1155
1156                         disallows = 0;
1157
1158                         for( i=1; i < cargc; i++ ) {
1159                                 if( strcasecmp( cargv[i], "bind_v2" ) == 0 ) {
1160                                         disallows |= SLAP_DISALLOW_BIND_V2;
1161
1162                                 } else if( strcasecmp( cargv[i], "bind_anon" ) == 0 ) {
1163                                         disallows |= SLAP_DISALLOW_BIND_ANON;
1164
1165                                 } else if( strcasecmp( cargv[i], "bind_anon_cred" ) == 0 ) {
1166                                         disallows |= SLAP_DISALLOW_BIND_ANON_CRED;
1167
1168                                 } else if( strcasecmp( cargv[i], "bind_anon_dn" ) == 0 ) {
1169                                         disallows |= SLAP_DISALLOW_BIND_ANON_DN;
1170
1171                                 } else if( strcasecmp( cargv[i], "bind_simple" ) == 0 ) {
1172                                         disallows |= SLAP_DISALLOW_BIND_SIMPLE;
1173
1174                                 } else if( strcasecmp( cargv[i], "bind_krbv4" ) == 0 ) {
1175                                         disallows |= SLAP_DISALLOW_BIND_KRBV4;
1176
1177                                 } else if( strcasecmp( cargv[i], "tls_authc" ) == 0 ) {
1178                                         disallows |= SLAP_DISALLOW_TLS_AUTHC;
1179
1180                                 } else if( strcasecmp( cargv[i], "none" ) != 0 ) {
1181 #ifdef NEW_LOGGING
1182                                         LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
1183                                                    "%s: line %d: unknownfeature %s in "
1184                                                    "\"disallow <features>\" line.\n",
1185                                                    fname, lineno ));
1186 #else
1187                                         Debug( LDAP_DEBUG_ANY,
1188                     "%s: line %d: unknown feature %s in \"disallow <features>\" line\n",
1189                                             fname, lineno, cargv[i] );
1190 #endif
1191
1192                                         return( 1 );
1193                                 }
1194                         }
1195
1196                         global_disallows = disallows;
1197
1198                 /* require these features */
1199                 } else if ( strcasecmp( cargv[0], "requires" ) == 0 ||
1200                         strcasecmp( cargv[0], "require" ) == 0 )
1201                 {
1202                         slap_mask_t     requires;
1203
1204                         if ( cargc < 2 ) {
1205 #ifdef NEW_LOGGING
1206                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
1207                                            "%s: line %d: missing feature(s) in "
1208                                            "\"require <features>\" line.\n", fname, lineno ));
1209 #else
1210                                 Debug( LDAP_DEBUG_ANY,
1211             "%s: line %d: missing feature(s) in \"require <features>\" line\n",
1212                                     fname, lineno, 0 );
1213 #endif
1214
1215                                 return( 1 );
1216                         }
1217
1218                         requires = 0;
1219
1220                         for( i=1; i < cargc; i++ ) {
1221                                 if( strcasecmp( cargv[i], "bind" ) == 0 ) {
1222                                         requires |= SLAP_REQUIRE_BIND;
1223
1224                                 } else if( strcasecmp( cargv[i], "LDAPv3" ) == 0 ) {
1225                                         requires |= SLAP_REQUIRE_LDAP_V3;
1226
1227                                 } else if( strcasecmp( cargv[i], "authc" ) == 0 ) {
1228                                         requires |= SLAP_REQUIRE_AUTHC;
1229
1230                                 } else if( strcasecmp( cargv[i], "SASL" ) == 0 ) {
1231                                         requires |= SLAP_REQUIRE_SASL;
1232
1233                                 } else if( strcasecmp( cargv[i], "strong" ) == 0 ) {
1234                                         requires |= SLAP_REQUIRE_STRONG;
1235
1236                                 } else if( strcasecmp( cargv[i], "none" ) != 0 ) {
1237 #ifdef NEW_LOGGING
1238                                         LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
1239                                                    "%s: line %d: unknown feature %s in "
1240                                                    "\"require <features>\" line.\n",
1241                                                    fname, lineno ));
1242 #else
1243                                         Debug( LDAP_DEBUG_ANY,
1244                     "%s: line %d: unknown feature %s in \"require <features>\" line\n",
1245                                             fname, lineno, cargv[i] );
1246 #endif
1247
1248                                         return( 1 );
1249                                 }
1250                         }
1251
1252                         if ( be == NULL ) {
1253                                 global_requires = requires;
1254                         } else {
1255                                 be->be_requires = requires;
1256                         }
1257
1258                 /* required security factors */
1259                 } else if ( strcasecmp( cargv[0], "security" ) == 0 ) {
1260                         slap_ssf_set_t *set;
1261
1262                         if ( cargc < 2 ) {
1263 #ifdef NEW_LOGGING
1264                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
1265                                            "%s: line %d: missing factor(s) in \"security <factors>\""
1266                                            " line.\n", fname, lineno ));
1267 #else
1268                                 Debug( LDAP_DEBUG_ANY,
1269             "%s: line %d: missing factor(s) in \"security <factors>\" line\n",
1270                                     fname, lineno, 0 );
1271 #endif
1272
1273                                 return( 1 );
1274                         }
1275
1276                         if ( be == NULL ) {
1277                                 set = &global_ssf_set;
1278                         } else {
1279                                 set = &be->be_ssf_set;
1280                         }
1281
1282                         for( i=1; i < cargc; i++ ) {
1283                                 if( strncasecmp( cargv[i], "ssf=",
1284                                         sizeof("ssf") ) == 0 )
1285                                 {
1286                                         set->sss_ssf =
1287                                                 atoi( &cargv[i][sizeof("ssf")] );
1288
1289                                 } else if( strncasecmp( cargv[i], "transport=",
1290                                         sizeof("transport") ) == 0 )
1291                                 {
1292                                         set->sss_transport =
1293                                                 atoi( &cargv[i][sizeof("transport")] );
1294
1295                                 } else if( strncasecmp( cargv[i], "tls=",
1296                                         sizeof("tls") ) == 0 )
1297                                 {
1298                                         set->sss_tls =
1299                                                 atoi( &cargv[i][sizeof("tls")] );
1300
1301                                 } else if( strncasecmp( cargv[i], "sasl=",
1302                                         sizeof("sasl") ) == 0 )
1303                                 {
1304                                         set->sss_sasl =
1305                                                 atoi( &cargv[i][sizeof("sasl")] );
1306
1307                                 } else if( strncasecmp( cargv[i], "update_ssf=",
1308                                         sizeof("update_ssf") ) == 0 )
1309                                 {
1310                                         set->sss_update_ssf =
1311                                                 atoi( &cargv[i][sizeof("update_ssf")] );
1312
1313                                 } else if( strncasecmp( cargv[i], "update_transport=",
1314                                         sizeof("update_transport") ) == 0 )
1315                                 {
1316                                         set->sss_update_transport =
1317                                                 atoi( &cargv[i][sizeof("update_transport")] );
1318
1319                                 } else if( strncasecmp( cargv[i], "update_tls=",
1320                                         sizeof("update_tls") ) == 0 )
1321                                 {
1322                                         set->sss_update_tls =
1323                                                 atoi( &cargv[i][sizeof("update_tls")] );
1324
1325                                 } else if( strncasecmp( cargv[i], "update_sasl=",
1326                                         sizeof("update_sasl") ) == 0 )
1327                                 {
1328                                         set->sss_update_sasl =
1329                                                 atoi( &cargv[i][sizeof("update_sasl")] );
1330
1331                                 } else {
1332 #ifdef NEW_LOGGING
1333                                         LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
1334                                                    "%s: line %d: unknown factor %S in "
1335                                                    "\"security <factors>\" line.\n",
1336                                                    fname, lineno, cargv[1] ));
1337 #else
1338                                         Debug( LDAP_DEBUG_ANY,
1339                     "%s: line %d: unknown factor %s in \"security <factors>\" line\n",
1340                                             fname, lineno, cargv[i] );
1341 #endif
1342
1343                                         return( 1 );
1344                                 }
1345                         }
1346                 /* where to send clients when we don't hold it */
1347                 } else if ( strcasecmp( cargv[0], "referral" ) == 0 ) {
1348                         if ( cargc < 2 ) {
1349 #ifdef NEW_LOGGING
1350                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
1351                                            "%s: line %d: missing URL in \"referral <URL>\""
1352                                            " line.\n", fname, lineno ));
1353 #else
1354                                 Debug( LDAP_DEBUG_ANY,
1355                     "%s: line %d: missing URL in \"referral <URL>\" line\n",
1356                                     fname, lineno, 0 );
1357 #endif
1358
1359                                 return( 1 );
1360                         }
1361
1362                         vals[0]->bv_val = cargv[1];
1363                         vals[0]->bv_len = strlen( vals[0]->bv_val );
1364                         value_add( &default_referral, vals );
1365
1366 #ifdef NEW_LOGGING
1367                 } else if ( strcasecmp( cargv[0], "logfile" ) == 0 ) {
1368                         FILE *logfile;
1369                         if ( cargc < 2 ) {
1370 #ifdef NEW_LOGGING
1371                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
1372                                            "%s: line %d: Error in logfile directive, "
1373                                            "\"logfile <filename>\"\n", fname, lineno ));
1374 #else
1375                                 Debug( LDAP_DEBUG_ANY,
1376                                        "%s: line %d: Error in logfile directive, \"logfile filename\"\n",
1377                                        fname, lineno, 0 );
1378 #endif
1379
1380                                 return( 1 );
1381                         }
1382                         logfile = fopen( cargv[1], "w" );
1383                         if ( logfile != NULL ) lutil_debug_file( logfile );
1384
1385 #endif
1386                 /* start of a new database definition */
1387                 } else if ( strcasecmp( cargv[0], "debug" ) == 0 ) {
1388                         int level;
1389                         if ( cargc < 3 ) {
1390 #ifdef NEW_LOGGING
1391                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
1392                                            "%s: line %d: Error in debug directive, "
1393                                            "\"debug <subsys> <level>\"\n", fname, lineno ));
1394 #else
1395                                 Debug( LDAP_DEBUG_ANY,
1396                                         "%s: line %d: Error in debug directive, \"debug subsys level\"\n",
1397                                         fname, lineno, 0 );
1398 #endif
1399
1400                                 return( 1 );
1401                         }
1402                         level = atoi( cargv[2] );
1403                         if ( level <= 0 ) level = lutil_mnem2level( cargv[2] );
1404                         lutil_set_debug_level( cargv[1], level );
1405                 /* specify an Object Identifier macro */
1406                 } else if ( strcasecmp( cargv[0], "objectidentifier" ) == 0 ) {
1407                         rc = parse_oidm( fname, lineno, cargc, cargv );
1408                         if( rc ) return rc;
1409
1410                 /* specify an objectclass */
1411                 } else if ( strcasecmp( cargv[0], "objectclass" ) == 0 ) {
1412                         if ( *cargv[1] == '(' ) {
1413                                 char * p;
1414                                 p = strchr(saveline,'(');
1415                                 rc = parse_oc( fname, lineno, p, cargv );
1416                                 if( rc ) return rc;
1417
1418                         } else {
1419 #ifdef NEW_LOGGING
1420                                 LDAP_LOG(( "config", LDAP_LEVEL_INFO,
1421                                            "%s: line %d: old objectclass format not supported\n",
1422                                            fname, lineno ));
1423 #else
1424                                 Debug( LDAP_DEBUG_ANY,
1425                                        "%s: line %d: old objectclass format not supported.\n",
1426                                        fname, lineno, 0 );
1427 #endif
1428
1429                         }
1430
1431                 /* specify an attribute type */
1432                 } else if (( strcasecmp( cargv[0], "attributetype" ) == 0 )
1433                         || ( strcasecmp( cargv[0], "attribute" ) == 0 ))
1434                 {
1435                         if ( *cargv[1] == '(' ) {
1436                                 char * p;
1437                                 p = strchr(saveline,'(');
1438                                 rc = parse_at( fname, lineno, p, cargv );
1439                                 if( rc ) return rc;
1440
1441                         } else {
1442 #ifdef NEW_LOGGING
1443                                 LDAP_LOG(( "config", LDAP_LEVEL_INFO,
1444                                            "%s: line %d: old attribute type format not supported.\n",
1445                                            fname, lineno ));
1446 #else
1447                                 Debug( LDAP_DEBUG_ANY,
1448     "%s: line %d: old attribute type format not supported.\n",
1449                                     fname, lineno, 0 );
1450 #endif
1451
1452                         }
1453
1454                 /* turn on/off schema checking */
1455                 } else if ( strcasecmp( cargv[0], "schemacheck" ) == 0 ) {
1456                         if ( cargc < 2 ) {
1457 #ifdef NEW_LOGGING
1458                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
1459                                            "%s: line %d: missing on|off in "
1460                                            "\"schemacheck <on|off>\" line.\n",
1461                                            fname, lineno ));
1462 #else
1463                                 Debug( LDAP_DEBUG_ANY,
1464     "%s: line %d: missing on|off in \"schemacheck <on|off>\" line\n",
1465                                     fname, lineno, 0 );
1466 #endif
1467
1468                                 return( 1 );
1469                         }
1470                         if ( strcasecmp( cargv[1], "off" ) == 0 ) {
1471                                 global_schemacheck = 0;
1472                         } else {
1473                                 global_schemacheck = 1;
1474                         }
1475
1476                 /* specify access control info */
1477                 } else if ( strcasecmp( cargv[0], "access" ) == 0 ) {
1478                         parse_acl( be, fname, lineno, cargc, cargv );
1479
1480                 /* debug level to log things to syslog */
1481                 } else if ( strcasecmp( cargv[0], "loglevel" ) == 0 ) {
1482                         if ( cargc < 2 ) {
1483 #ifdef NEW_LOGGING
1484                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
1485                                            "%s: line %d: missing level in \"loglevel <level>\""
1486                                            " line.\n", fname, lineno ));
1487 #else
1488                                 Debug( LDAP_DEBUG_ANY,
1489                     "%s: line %d: missing level in \"loglevel <level>\" line\n",
1490                                     fname, lineno, 0 );
1491 #endif
1492
1493                                 return( 1 );
1494                         }
1495
1496                         ldap_syslog = 0;
1497
1498                         for( i=1; i < cargc; i++ ) {
1499                                 ldap_syslog += atoi( cargv[1] );
1500                         }
1501
1502                 /* list of replicas of the data in this backend (master only) */
1503                 } else if ( strcasecmp( cargv[0], "replica" ) == 0 ) {
1504                         if ( cargc < 2 ) {
1505 #ifdef NEW_LOGGING
1506                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
1507                                            "%s: line %d: missing host in \"replica "
1508                                            " <host[:port]\" line\n", fname, lineno ));
1509 #else
1510                                 Debug( LDAP_DEBUG_ANY,
1511             "%s: line %d: missing host in \"replica <host[:port]>\" line\n",
1512                                     fname, lineno, 0 );
1513 #endif
1514
1515                                 return( 1 );
1516                         }
1517                         if ( be == NULL ) {
1518 #ifdef NEW_LOGGING
1519                                 LDAP_LOG(( "config", LDAP_LEVEL_INFO,
1520                                            "%s: line %d: replica line must appear inside "
1521                                            "a database definition (ignored).\n", fname, lineno ));
1522 #else
1523                                 Debug( LDAP_DEBUG_ANY,
1524 "%s: line %d: replica line must appear inside a database definition (ignored)\n",
1525                                     fname, lineno, 0 );
1526 #endif
1527
1528                         } else {
1529                                 for ( i = 1; i < cargc; i++ ) {
1530                                         if ( strncasecmp( cargv[i], "host=", 5 )
1531                                             == 0 ) {
1532                                                 charray_add( &be->be_replica,
1533                                                              cargv[i] + 5 );
1534                                                 break;
1535                                         }
1536                                 }
1537                                 if ( i == cargc ) {
1538 #ifdef NEW_LOGGING
1539                                         LDAP_LOG(( "config", LDAP_LEVEL_INFO,
1540                                                    "%s: line %d: missing host in \"replica\" "
1541                                                    "line (ignored)\n", fname, lineno ));
1542 #else
1543                                         Debug( LDAP_DEBUG_ANY,
1544                     "%s: line %d: missing host in \"replica\" line (ignored)\n",
1545                                             fname, lineno, 0 );
1546 #endif
1547
1548                                 }
1549                         }
1550
1551                 /* dn of master entity allowed to write to replica */
1552                 } else if ( strcasecmp( cargv[0], "updatedn" ) == 0 ) {
1553                         if ( cargc < 2 ) {
1554 #ifdef NEW_LOGGING
1555                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
1556                                            "%s: line %d: missing dn in \"updatedn <dn>\""
1557                                            " line.\n", fname, lineno ));
1558 #else
1559                                 Debug( LDAP_DEBUG_ANY,
1560                     "%s: line %d: missing dn in \"updatedn <dn>\" line\n",
1561                                     fname, lineno, 0 );
1562 #endif
1563
1564                                 return( 1 );
1565                         }
1566                         if ( be == NULL ) {
1567 #ifdef NEW_LOGGING
1568                                 LDAP_LOG(( "config", LDAP_LEVEL_INFO,
1569                                            "%s: line %d: updatedn line must appear inside "
1570                                            "a database definition (ignored)\n",
1571                                            fname, lineno ));
1572 #else
1573                                 Debug( LDAP_DEBUG_ANY,
1574 "%s: line %d: updatedn line must appear inside a database definition (ignored)\n",
1575                                     fname, lineno, 0 );
1576 #endif
1577
1578                         } else {
1579                                 be->be_update_ndn = ch_strdup( cargv[1] );
1580                                 if ( load_ucdata( NULL ) < 0 ) {
1581                                         return( 1 );
1582                                 }
1583                                 if( dn_normalize( be->be_update_ndn ) == NULL ) {
1584 #ifdef NEW_LOGGING
1585                                         LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
1586                                                    "%s: line %d: updatedn DN is invalid.\n",
1587                                                    fname, lineno ));
1588 #else
1589                                         Debug( LDAP_DEBUG_ANY,
1590 "%s: line %d: updatedn DN is invalid\n",
1591                                             fname, lineno, 0 );
1592 #endif
1593
1594                                         return 1;
1595                                 }
1596                         }
1597
1598                 } else if ( strcasecmp( cargv[0], "updateref" ) == 0 ) {
1599                         if ( cargc < 2 ) {
1600 #ifdef NEW_LOGGING
1601                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
1602                                            "%s: line %d: missing dn in \"updateref <ldapurl>\" "
1603                                            "line.\n", fname, lineno ));
1604 #else
1605                                 Debug( LDAP_DEBUG_ANY,
1606                     "%s: line %d: missing dn in \"updateref <ldapurl>\" line\n",
1607                                     fname, lineno, 0 );
1608 #endif
1609
1610                                 return( 1 );
1611                         }
1612                         if ( be == NULL ) {
1613 #ifdef NEW_LOGGING
1614                                 LDAP_LOG(( "config", LDAP_LEVEL_INFO,
1615                                            "%s: line %d: updateref line must appear inside "
1616                                            "a database definition (ignored)\n", fname, lineno ));
1617 #else
1618                                 Debug( LDAP_DEBUG_ANY,
1619 "%s: line %d: updateref line must appear inside a database definition (ignored)\n",
1620                                     fname, lineno, 0 );
1621 #endif
1622
1623                         } else if ( be->be_update_ndn == NULL ) {
1624 #ifdef NEW_LOGGING
1625                                 LDAP_LOG(( "config", LDAP_LEVEL_INFO,
1626                                            "%s: line %d: updateref line must come after updatedn "
1627                                            "(ignored).\n", fname, lineno ));
1628 #else
1629                                 Debug( LDAP_DEBUG_ANY,
1630 "%s: line %d: updateref line must after updatedn (ignored)\n",
1631                                     fname, lineno, 0 );
1632 #endif
1633
1634                         } else {
1635                                 vals[0]->bv_val = cargv[1];
1636                                 vals[0]->bv_len = strlen( vals[0]->bv_val );
1637                                 value_add( &be->be_update_refs, vals );
1638                         }
1639
1640                 /* replication log file to which changes are appended */
1641                 } else if ( strcasecmp( cargv[0], "replogfile" ) == 0 ) {
1642                         if ( cargc < 2 ) {
1643 #ifdef NEW_LOGGING
1644                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
1645                                            "%s: line %d: missing filename in \"replogfile <filename>\""
1646                                            " line.\n", fname, lineno ));
1647 #else
1648                                 Debug( LDAP_DEBUG_ANY,
1649             "%s: line %d: missing dn in \"replogfile <filename>\" line\n",
1650                                     fname, lineno, 0 );
1651 #endif
1652
1653                                 return( 1 );
1654                         }
1655                         if ( be ) {
1656                                 be->be_replogfile = ch_strdup( cargv[1] );
1657                         } else {
1658                                 replogfile = ch_strdup( cargv[1] );
1659                         }
1660
1661                 /* maintain lastmodified{by,time} attributes */
1662                 } else if ( strcasecmp( cargv[0], "lastmod" ) == 0 ) {
1663                         if ( cargc < 2 ) {
1664 #ifdef NEW_LOGGING
1665                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
1666                                            "%s: line %d: missing on|off in \"lastmod <on|off>\""
1667                                            " line.\n", fname, lineno ));
1668 #else
1669                                 Debug( LDAP_DEBUG_ANY,
1670             "%s: line %d: missing on|off in \"lastmod <on|off>\" line\n",
1671                                     fname, lineno, 0 );
1672 #endif
1673
1674                                 return( 1 );
1675                         }
1676                         if ( strcasecmp( cargv[1], "on" ) == 0 ) {
1677                                 if ( be )
1678                                         be->be_lastmod = ON;
1679                                 else
1680                                         global_lastmod = ON;
1681                         } else {
1682                                 if ( be )
1683                                         be->be_lastmod = OFF;
1684                                 else
1685                                         global_lastmod = OFF;
1686                         }
1687
1688                 /* set idle timeout value */
1689                 } else if ( strcasecmp( cargv[0], "idletimeout" ) == 0 ) {
1690                         int i;
1691                         if ( cargc < 2 ) {
1692 #ifdef NEW_LOGGING
1693                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
1694                                            "%s: line %d: missing timeout value in "
1695                                            "\"idletimeout <seconds>\" line.\n", fname, lineno ));
1696 #else
1697                                 Debug( LDAP_DEBUG_ANY,
1698             "%s: line %d: missing timeout value in \"idletimeout <seconds>\" line\n",
1699                                     fname, lineno, 0 );
1700 #endif
1701
1702                                 return( 1 );
1703                         }
1704
1705                         i = atoi( cargv[1] );
1706
1707                         if( i < 0 ) {
1708 #ifdef NEW_LOGGING
1709                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
1710                                            "%s: line %d: timeout value (%d) invalid "
1711                                            "\"idletimeout <seconds>\" line.\n",
1712                                            fname, lineno, i ));
1713 #else
1714                                 Debug( LDAP_DEBUG_ANY,
1715             "%s: line %d: timeout value (%d) invalid \"idletimeout <seconds>\" line\n",
1716                                     fname, lineno, i );
1717 #endif
1718
1719                                 return( 1 );
1720                         }
1721
1722                         global_idletimeout = i;
1723
1724                 /* include another config file */
1725                 } else if ( strcasecmp( cargv[0], "include" ) == 0 ) {
1726                         if ( cargc < 2 ) {
1727 #ifdef NEW_LOGGING
1728                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
1729                                            "%s: line %d: missing filename in \"include "
1730                                            "<filename>\" line.\n", fname, lineno ));
1731 #else
1732                                 Debug( LDAP_DEBUG_ANY,
1733     "%s: line %d: missing filename in \"include <filename>\" line\n",
1734                                     fname, lineno, 0 );
1735 #endif
1736
1737                                 return( 1 );
1738                         }
1739                         savefname = ch_strdup( cargv[1] );
1740                         savelineno = lineno;
1741
1742                         if ( read_config( savefname ) != 0 ) {
1743                                 return( 1 );
1744                         }
1745
1746                         free( savefname );
1747                         lineno = savelineno - 1;
1748
1749                 /* location of kerberos srvtab file */
1750                 } else if ( strcasecmp( cargv[0], "srvtab" ) == 0 ) {
1751                         if ( cargc < 2 ) {
1752 #ifdef NEW_LOGGING
1753                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
1754                                            "%s: line %d: missing filename in \"srvtab "
1755                                            "<filename>\" line.\n", fname, lineno ));
1756 #else
1757                                 Debug( LDAP_DEBUG_ANY,
1758             "%s: line %d: missing filename in \"srvtab <filename>\" line\n",
1759                                     fname, lineno, 0 );
1760 #endif
1761
1762                                 return( 1 );
1763                         }
1764                         ldap_srvtab = ch_strdup( cargv[1] );
1765
1766 #ifdef SLAPD_MODULES
1767                 } else if (strcasecmp( cargv[0], "moduleload") == 0 ) {
1768                    if ( cargc < 2 ) {
1769 #ifdef NEW_LOGGING
1770                            LDAP_LOG(( "config", LDAP_LEVEL_INFO,
1771                                       "%s: line %d: missing filename in \"moduleload "
1772                                       "<filename>\" line.\n", fname, lineno ));
1773 #else
1774                       Debug( LDAP_DEBUG_ANY,
1775                              "%s: line %d: missing filename in \"moduleload <filename>\" line\n",
1776                              fname, lineno, 0 );
1777 #endif
1778
1779                       exit( EXIT_FAILURE );
1780                    }
1781                    if (module_load(cargv[1], cargc - 2, (cargc > 2) ? cargv + 2 : NULL)) {
1782 #ifdef NEW_LOGGING
1783                            LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
1784                                       "%s: line %d: failed to load or initialize module %s\n"<
1785                                       fname, lineno, cargv[1] ));
1786 #else
1787                       Debug( LDAP_DEBUG_ANY,
1788                              "%s: line %d: failed to load or initialize module %s\n",
1789                              fname, lineno, cargv[1]);
1790 #endif
1791
1792                       exit( EXIT_FAILURE );
1793                    }
1794                 } else if (strcasecmp( cargv[0], "modulepath") == 0 ) {
1795                    if ( cargc != 2 ) {
1796 #ifdef NEW_LOGGING
1797                            LDAP_LOG(( "config", LDAP_LEVEL_INFO,
1798                                       "%s: line %d: missing path in \"modulepath <path>\""
1799                                       " line\n", fname, lineno ));
1800 #else
1801                       Debug( LDAP_DEBUG_ANY,
1802                              "%s: line %d: missing path in \"modulepath <path>\" line\n",
1803                              fname, lineno, 0 );
1804 #endif
1805
1806                       exit( EXIT_FAILURE );
1807                    }
1808                    if (module_path( cargv[1] )) {
1809 #ifdef NEW_LOGGING
1810                            LDAP_LOG(( "cofig", LDAP_LEVEL_CRIT,
1811                                       "%s: line %d: failed to set module search path to %s.\n",
1812                                       fname, lineno, cargv[1] ));
1813 #else
1814                            Debug( LDAP_DEBUG_ANY,
1815                                   "%s: line %d: failed to set module search path to %s\n",
1816                                   fname, lineno, cargv[1]);
1817 #endif
1818
1819                       exit( EXIT_FAILURE );
1820                    }
1821                    
1822 #endif /*SLAPD_MODULES*/
1823
1824 #ifdef HAVE_TLS
1825                 } else if ( !strcasecmp( cargv[0], "TLSProtocol" ) ) {
1826                         rc = ldap_pvt_tls_set_option( NULL,
1827                                                       LDAP_OPT_X_TLS_PROTOCOL,
1828                                                       cargv[1] );
1829                         if ( rc )
1830                                 return rc;
1831
1832                 } else if ( !strcasecmp( cargv[0], "TLSRandFile" ) ) {
1833                         rc = ldap_pvt_tls_set_option( NULL,
1834                                                       LDAP_OPT_X_TLS_RANDOM_FILE,
1835                                                       cargv[1] );
1836                         if ( rc )
1837                                 return rc;
1838
1839                 } else if ( !strcasecmp( cargv[0], "TLSCipherSuite" ) ) {
1840                         rc = ldap_pvt_tls_set_option( NULL,
1841                                                       LDAP_OPT_X_TLS_CIPHER_SUITE,
1842                                                       cargv[1] );
1843                         if ( rc )
1844                                 return rc;
1845
1846                 } else if ( !strcasecmp( cargv[0], "TLSCertificateFile" ) ) {
1847                         rc = ldap_pvt_tls_set_option( NULL,
1848                                                       LDAP_OPT_X_TLS_CERTFILE,
1849                                                       cargv[1] );
1850                         if ( rc )
1851                                 return rc;
1852
1853                 } else if ( !strcasecmp( cargv[0], "TLSCertificateKeyFile" ) ) {
1854                         rc = ldap_pvt_tls_set_option( NULL,
1855                                                       LDAP_OPT_X_TLS_KEYFILE,
1856                                                       cargv[1] );
1857                         if ( rc )
1858                                 return rc;
1859
1860                 } else if ( !strcasecmp( cargv[0], "TLSCACertificatePath" ) ) {
1861                         rc = ldap_pvt_tls_set_option( NULL,
1862                                                       LDAP_OPT_X_TLS_CACERTDIR,
1863                                                       cargv[1] );
1864                         if ( rc )
1865                                 return rc;
1866
1867                 } else if ( !strcasecmp( cargv[0], "TLSCACertificateFile" ) ) {
1868                         rc = ldap_pvt_tls_set_option( NULL,
1869                                                       LDAP_OPT_X_TLS_CACERTFILE,
1870                                                       cargv[1] );
1871                         if ( rc )
1872                                 return rc;
1873                 } else if ( !strcasecmp( cargv[0], "TLSVerifyClient" ) ) {
1874                         i = atoi(cargv[1]);
1875                         rc = ldap_pvt_tls_set_option( NULL,
1876                                                       LDAP_OPT_X_TLS_REQUIRE_CERT,
1877                                                       &i );
1878                         if ( rc )
1879                                 return rc;
1880
1881 #endif
1882
1883                 /* pass anything else to the current backend info/db config routine */
1884                 } else {
1885                         if ( bi != NULL ) {
1886                                 if ( bi->bi_config == 0 ) {
1887 #ifdef NEW_LOGGING
1888                                         LDAP_LOG(( "config", LDAP_LEVEL_INFO,
1889                                                    "%s: line %d: unknown directive \"%s\" inside "
1890                                                    "backend info definition (ignored).\n",
1891                                                    fname, lineno, cargv[0] ));
1892 #else
1893                                         Debug( LDAP_DEBUG_ANY,
1894 "%s: line %d: unknown directive \"%s\" inside backend info definition (ignored)\n",
1895                                                 fname, lineno, cargv[0] );
1896 #endif
1897
1898                                 } else {
1899                                         if ( (*bi->bi_config)( bi, fname, lineno, cargc, cargv )
1900                                                 != 0 )
1901                                         {
1902                                                 return( 1 );
1903                                         }
1904                                 }
1905                         } else if ( be != NULL ) {
1906                                 if ( be->be_config == 0 ) {
1907 #ifdef NEW_LOGGING
1908                                         LDAP_LOG(( "config", LDAP_LEVEL_INFO,
1909                                                    "%s: line %d: uknown directive \"%s\" inside "
1910                                                    "backend database definition (ignored).\n",
1911                                                    fname, lineno, cargv[0] ));
1912 #else
1913                                         Debug( LDAP_DEBUG_ANY,
1914 "%s: line %d: unknown directive \"%s\" inside backend database definition (ignored)\n",
1915                                         fname, lineno, cargv[0] );
1916 #endif
1917
1918                                 } else {
1919                                         if ( (*be->be_config)( be, fname, lineno, cargc, cargv )
1920                                                 != 0 )
1921                                         {
1922                                                 return( 1 );
1923                                         }
1924                                 }
1925                         } else {
1926 #ifdef NEW_LOGGING
1927                                 LDAP_LOG(( "config", LDAP_LEVEL_INFO,
1928                                            "%s: line %d: unknown directive \"%s\" outside backend "
1929                                            "info and database definitions (ignored).\n",
1930                                            fname, lineno, cargv[0] ));
1931 #else
1932                                 Debug( LDAP_DEBUG_ANY,
1933 "%s: line %d: unknown directive \"%s\" outside backend info and database definitions (ignored)\n",
1934                                     fname, lineno, cargv[0] );
1935 #endif
1936
1937                         }
1938                 }
1939                 free( saveline );
1940         }
1941         fclose( fp );
1942         if ( load_ucdata( NULL ) < 0 ) {
1943                 return( 1 );
1944         }
1945         return( 0 );
1946 }
1947
1948 static int
1949 fp_parse_line(
1950     char        *line,
1951     int         *argcp,
1952     char        **argv
1953 )
1954 {
1955         char *  token;
1956
1957         *argcp = 0;
1958         for ( token = strtok_quote( line, " \t" ); token != NULL;
1959             token = strtok_quote( NULL, " \t" ) ) {
1960                 if ( *argcp == MAXARGS ) {
1961 #ifdef NEW_LOGGING
1962                         LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
1963                                    "fp_parse_line: too many tokens (%d max).\n",
1964                                    MAXARGS ));
1965 #else
1966                         Debug( LDAP_DEBUG_ANY, "Too many tokens (max %d)\n",
1967                             MAXARGS, 0, 0 );
1968 #endif
1969
1970                         return( 1 );
1971                 }
1972                 argv[(*argcp)++] = token;
1973         }
1974         argv[*argcp] = NULL;
1975         return 0;
1976 }
1977
1978 static char *
1979 strtok_quote( char *line, char *sep )
1980 {
1981         int             inquote;
1982         char            *tmp;
1983         static char     *next;
1984
1985         if ( line != NULL ) {
1986                 next = line;
1987         }
1988         while ( *next && strchr( sep, *next ) ) {
1989                 next++;
1990         }
1991
1992         if ( *next == '\0' ) {
1993                 next = NULL;
1994                 return( NULL );
1995         }
1996         tmp = next;
1997
1998         for ( inquote = 0; *next; ) {
1999                 switch ( *next ) {
2000                 case '"':
2001                         if ( inquote ) {
2002                                 inquote = 0;
2003                         } else {
2004                                 inquote = 1;
2005                         }
2006                         AC_MEMCPY( next, next + 1, strlen( next + 1 ) + 1 );
2007                         break;
2008
2009                 case '\\':
2010                         if ( next[1] )
2011                                 AC_MEMCPY( next,
2012                                             next + 1, strlen( next + 1 ) + 1 );
2013                         next++;         /* dont parse the escaped character */
2014                         break;
2015
2016                 default:
2017                         if ( ! inquote ) {
2018                                 if ( strchr( sep, *next ) != NULL ) {
2019                                         *next++ = '\0';
2020                                         return( tmp );
2021                                 }
2022                         }
2023                         next++;
2024                         break;
2025                 }
2026         }
2027
2028         return( tmp );
2029 }
2030
2031 static char     buf[BUFSIZ];
2032 static char     *line;
2033 static int      lmax, lcur;
2034
2035 #define CATLINE( buf )  { \
2036         int     len; \
2037         len = strlen( buf ); \
2038         while ( lcur + len + 1 > lmax ) { \
2039                 lmax += BUFSIZ; \
2040                 line = (char *) ch_realloc( line, lmax ); \
2041         } \
2042         strcpy( line + lcur, buf ); \
2043         lcur += len; \
2044 }
2045
2046 static char *
2047 fp_getline( FILE *fp, int *lineno )
2048 {
2049         char            *p;
2050
2051         lcur = 0;
2052         CATLINE( buf );
2053         (*lineno)++;
2054
2055         /* hack attack - keeps us from having to keep a stack of bufs... */
2056         if ( strncasecmp( line, "include", 7 ) == 0 ) {
2057                 buf[0] = '\0';
2058                 return( line );
2059         }
2060
2061         while ( fgets( buf, sizeof(buf), fp ) != NULL ) {
2062                 if ( (p = strchr( buf, '\n' )) != NULL ) {
2063                         *p = '\0';
2064                 }
2065                 if ( ! isspace( (unsigned char) buf[0] ) ) {
2066                         return( line );
2067                 }
2068
2069                 /* change leading whitespace to a space */
2070                 buf[0] = ' ';
2071
2072                 CATLINE( buf );
2073                 (*lineno)++;
2074         }
2075         buf[0] = '\0';
2076
2077         return( line[0] ? line : NULL );
2078 }
2079
2080 static void
2081 fp_getline_init( int *lineno )
2082 {
2083         *lineno = -1;
2084         buf[0] = '\0';
2085 }
2086
2087 /* Loads ucdata, returns 1 if loading, 0 if already loaded, -1 on error */
2088 static int
2089 load_ucdata( char *path )
2090 {
2091         static int loaded = 0;
2092         int err;
2093         
2094         if ( loaded ) {
2095                 return( 0 );
2096         }
2097         err = ucdata_load( path ? path : SLAPD_DEFAULT_UCDATA, UCDATA_ALL );
2098         if ( err ) {
2099 #ifdef NEW_LOGGING
2100                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
2101                            "load_ucdata: Error %d loading ucdata.\n", err ));
2102 #else
2103                 Debug( LDAP_DEBUG_ANY, "error loading ucdata (error %d)\n",
2104                        err, 0, 0 );
2105 #endif
2106
2107                 return( -1 );
2108         }
2109         loaded = 1;
2110         return( 1 );
2111 }