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