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