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