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