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