]> git.sur5r.net Git - openldap/blob - servers/slapd/config.c
bb73194aef33bb17ee3b0d5898c23590a14f0659
[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;
923
924                                 if ( load_ucdata( NULL ) < 0 ) {
925                                         return( 1 );
926                                 }
927                                 dn = ch_strdup( cargv[1] );
928                                 if( dn_validate( dn ) == NULL ) {
929 #ifdef NEW_LOGGING
930                                         LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
931                                                    "%s: line %d: suffix DN invalid\"%s\"\n",
932                                                    fname, lineno, cargv[1] ));
933 #else
934                                         Debug( LDAP_DEBUG_ANY, "%s: line %d: "
935                                                 "suffix DN invalid \"%s\"\n",
936                                         fname, lineno, cargv[1] );
937 #endif
938                                         free( dn );
939                                         return 1;
940
941                                 } else if( *dn == '\0' && default_search_nbase != NULL ) {
942 #ifdef NEW_LOGGING
943                                         LDAP_LOG(( "config", LDAP_LEVEL_INFO,
944                                                    "%s: line %d: suffix DN empty and default search "
945                                                    "base provided \"%s\" (assuming okay).\n",
946                                                    fname, lineno, default_search_base ));
947 #else
948                                         Debug( LDAP_DEBUG_ANY, "%s: line %d: "
949                                                 "suffix DN empty and default "
950                                                 "search base provided \"%s\" (assuming okay)\n",
951                                         fname, lineno, default_search_base );
952 #endif
953
954                                 }
955                                 charray_add( &be->be_suffix, dn );
956 #ifndef USE_LDAP_DN_PARSING
957                                 (void) ldap_pvt_str2upper( dn );
958 #else /* USE_LDAP_DN_PARSING */
959                                 if ( dn_normalize( dn ) == NULL ) {
960 #ifdef NEW_LOGGING
961                                         LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
962                                                 "%s: line %d: "
963                                                 "unable to normalize suffix "
964                                                 "\"%s\"\n", fname, lineno, dn ));
965 #else
966                                         Debug( LDAP_DEBUG_ANY, "%s: line %d: "
967                                                 "unable to normalize suffix "
968                                                 "\"%s\"\n", fname, lineno, dn );
969 #endif
970                                         free( dn );
971                                         return 1;
972                                 }
973 #endif /* USE_LDAP_DN_PARSING */
974                                 ber_bvecadd( &be->be_nsuffix, ber_bvstr( dn ) );
975                         }
976
977                 /* set database suffixAlias */
978                 } else if ( strcasecmp( cargv[0], "suffixAlias" ) == 0 ) {
979                         Backend *tmp_be;
980                         if ( cargc < 2 ) {
981 #ifdef NEW_LOGGING
982                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
983                                            "%s: line %d: missing alias and aliased_dn in "
984                                            "\"suffixAlias <alias> <aliased_dn>\" line.\n",
985                                            fname, lineno ));
986 #else
987                                 Debug( LDAP_DEBUG_ANY,
988 "%s: line %d: missing alias and aliased_dn in \"suffixAlias <alias> <aliased_dn>\" line\n",
989                                         fname, lineno, 0 );
990 #endif
991
992                                 return( 1 );
993                         } else if ( cargc < 3 ) {
994 #ifdef NEW_LOGGING
995                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
996                                            "%s: line %d: missing aliased_dn in "
997                                            "\"suffixAlias <alias> <aliased_dn>\" line\n",
998                                            fname, lineno ));
999 #else
1000                                 Debug( LDAP_DEBUG_ANY,
1001 "%s: line %d: missing aliased_dn in \"suffixAlias <alias> <aliased_dn>\" line\n",
1002                                 fname, lineno, 0 );
1003 #endif
1004
1005                                 return( 1 );
1006                         } else if ( cargc > 3 ) {
1007 #ifdef NEW_LOGGING
1008                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
1009                                            "%s: line %d: extra cruft in suffixAlias line (ignored)\n",
1010                                            fname, lineno ));
1011 #else
1012                                 Debug( LDAP_DEBUG_ANY,
1013                                         "%s: line %d: extra cruft in suffixAlias line (ignored)\n",
1014                                 fname, lineno, 0 );
1015 #endif
1016
1017                         }
1018
1019                         if ( be == NULL ) {
1020 #ifdef NEW_LOGGING
1021                                 LDAP_LOG(( "config", LDAP_LEVEL_INFO,
1022                                            "%s: line %d: suffixAlias line must appear inside a "
1023                                            "database definition (ignored).\n", fname, lineno ));
1024 #else
1025                                 Debug( LDAP_DEBUG_ANY,
1026                                         "%s: line %d: suffixAlias line"
1027                                         " must appear inside a database definition (ignored)\n",
1028                                         fname, lineno, 0 );
1029 #endif
1030
1031                         } else if ( (tmp_be = select_backend( cargv[1], 0, 0 )) != NULL ) {
1032 #ifdef NEW_LOGGING
1033                                 LDAP_LOG(( "config", LDAP_LEVEL_INFO,
1034                                            "%s: line %d: suffixAlias served by a preceeding "
1035                                            "backend \"%s\" (ignored).\n", fname, lineno,
1036                                            tmp_be->be_suffix[0] ));
1037 #else
1038                                 Debug( LDAP_DEBUG_ANY,
1039                                         "%s: line %d: suffixAlias served by"
1040                                         "  a preceeding backend \"%s\" (ignored)\n",
1041                                         fname, lineno, tmp_be->be_suffix[0] );
1042 #endif
1043
1044
1045                         } else if ( (tmp_be = select_backend( cargv[2], 0, 0 )) != NULL ) {
1046 #ifdef NEW_LOGGING
1047                                 LDAP_LOG(( "config", LDAP_LEVEL_INFO,
1048                                            "%s: line %d: suffixAlias derefs to a different backend "
1049                                            "a preceeding backend \"%s\" (ignored)\n",
1050                                            fname, lineno, tmp_be->be_suffix[0] ));
1051 #else
1052                                 Debug( LDAP_DEBUG_ANY,
1053                                         "%s: line %d: suffixAlias derefs to differnet backend"
1054                                         "  a preceeding backend \"%s\" (ignored)\n",
1055                                         fname, lineno, tmp_be->be_suffix[0] );
1056 #endif
1057
1058
1059                         } else {
1060                                 char *alias, *aliased_dn;
1061
1062                                 if ( load_ucdata( NULL ) < 0 ) {
1063                                         return( 1 );
1064                                 }
1065
1066                                 alias = ch_strdup( cargv[1] );
1067                                 (void) dn_normalize( alias );
1068
1069                                 aliased_dn = ch_strdup( cargv[2] );
1070                                 (void) dn_normalize( aliased_dn );
1071
1072                                 ber_bvecadd( &be->be_suffixAlias, 
1073                                         ber_bvstr( alias ) );
1074                                 ber_bvecadd( &be->be_suffixAlias,
1075                                         ber_bvstr( aliased_dn ) );
1076                         }
1077
1078                /* set max deref depth */
1079                } else if ( strcasecmp( cargv[0], "maxDerefDepth" ) == 0 ) {
1080                                         int i;
1081                        if ( cargc < 2 ) {
1082 #ifdef NEW_LOGGING
1083                                LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
1084                                           "%s: line %d: missing depth in \"maxDerefDepth <depth>\""
1085                                           " line\n", fname, lineno ));
1086 #else
1087                                Debug( LDAP_DEBUG_ANY,
1088                    "%s: line %d: missing depth in \"maxDerefDepth <depth>\" line\n",
1089                                    fname, lineno, 0 );
1090 #endif
1091
1092                                return( 1 );
1093                        }
1094                        if ( be == NULL ) {
1095 #ifdef NEW_LOGGING
1096                                LDAP_LOG(( "config", LDAP_LEVEL_INFO,
1097                                           "%s: line %d: depth line must appear inside a database "
1098                                           "definition (ignored)\n", fname, lineno ));
1099 #else
1100                                Debug( LDAP_DEBUG_ANY,
1101 "%s: line %d: depth line must appear inside a database definition (ignored)\n",
1102                                    fname, lineno, 0 );
1103 #endif
1104
1105                        } else if ((i = atoi(cargv[1])) < 0) {
1106 #ifdef NEW_LOGGING
1107                                LDAP_LOG(( "config", LDAP_LEVEL_INFO,
1108                                           "%s: line %d: depth must be positive (ignored).\n",
1109                                           fname, lineno ));
1110 #else
1111                                Debug( LDAP_DEBUG_ANY,
1112 "%s: line %d: depth must be positive (ignored)\n",
1113                                    fname, lineno, 0 );
1114 #endif
1115
1116
1117                        } else {
1118                            be->be_max_deref_depth = i;
1119                                            }
1120
1121
1122                 /* set magic "root" dn for this database */
1123                 } else if ( strcasecmp( cargv[0], "rootdn" ) == 0 ) {
1124                         if ( cargc < 2 ) {
1125 #ifdef NEW_LOGGING
1126                                 LDAP_LOG(( "config", LDAP_LEVEL_INFO,
1127                                            "%s: line %d: missing dn in \"rootdn <dn>\" line.\n",
1128                                            fname, lineno ));
1129 #else
1130                                 Debug( LDAP_DEBUG_ANY,
1131                     "%s: line %d: missing dn in \"rootdn <dn>\" line\n",
1132                                     fname, lineno, 0 );
1133 #endif
1134
1135                                 return( 1 );
1136                         }
1137                         if ( be == NULL ) {
1138 #ifdef NEW_LOGGING
1139                                 LDAP_LOG(( "config", LDAP_LEVEL_INFO,
1140                                            "%s: line %d: rootdn line must appear inside a database "
1141                                            "definition (ignored).\n", fname, lineno ));
1142 #else
1143                                 Debug( LDAP_DEBUG_ANY,
1144 "%s: line %d: rootdn line must appear inside a database definition (ignored)\n",
1145                                     fname, lineno, 0 );
1146 #endif
1147
1148                         } else {
1149                                 be->be_root_dn = ch_strdup( cargv[1] );
1150                                 be->be_root_ndn = ch_strdup( cargv[1] );
1151
1152                                 if ( load_ucdata( NULL ) < 0 ) {
1153                                         return( 1 );
1154                                 }
1155                                 if( dn_normalize( be->be_root_ndn ) == NULL ) {
1156                                         free( be->be_root_dn );
1157                                         free( be->be_root_ndn );
1158 #ifdef NEW_LOGGING
1159                                         LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
1160                                                    "%s: line %d: rootdn DN is invalid.\n",
1161                                                    fname, lineno ));
1162 #else
1163                                         Debug( LDAP_DEBUG_ANY,
1164 "%s: line %d: rootdn DN is invalid\n",
1165                                            fname, lineno, 0 );
1166 #endif
1167
1168                                         return( 1 );
1169                                 }
1170                         }
1171
1172                 /* set super-secret magic database password */
1173                 } else if ( strcasecmp( cargv[0], "rootpw" ) == 0 ) {
1174                         if ( cargc < 2 ) {
1175 #ifdef NEW_LOGGING
1176                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
1177                                            "%s: line %d: missing passwd in \"rootpw <passwd>\""
1178                                            " line\n", fname, lineno ));
1179 #else
1180                                 Debug( LDAP_DEBUG_ANY,
1181             "%s: line %d: missing passwd in \"rootpw <passwd>\" line\n",
1182                                     fname, lineno, 0 );
1183 #endif
1184
1185                                 return( 1 );
1186                         }
1187                         if ( be == NULL ) {
1188 #ifdef NEW_LOGGING
1189                                 LDAP_LOG(( "config", LDAP_LEVEL_INFO,
1190                                            "%s: line %d: rootpw line must appear inside a database "
1191                                            "definition (ignored)\n", fname, lineno ));
1192 #else
1193                                 Debug( LDAP_DEBUG_ANY,
1194 "%s: line %d: rootpw line must appear inside a database definition (ignored)\n",
1195                                     fname, lineno, 0 );
1196 #endif
1197
1198                         } else {
1199                                 be->be_root_pw.bv_val = ch_strdup( cargv[1] );
1200                                 be->be_root_pw.bv_len = strlen( be->be_root_pw.bv_val );
1201                         }
1202
1203                 /* make this database read-only */
1204                 } else if ( strcasecmp( cargv[0], "readonly" ) == 0 ) {
1205                         if ( cargc < 2 ) {
1206 #ifdef NEW_LOGGING
1207                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
1208                                            "%s: line %d: missing on|off in \"readonly <on|off>\" line.\n",
1209                                            fname, lineno ));
1210 #else
1211                                 Debug( LDAP_DEBUG_ANY,
1212             "%s: line %d: missing on|off in \"readonly <on|off>\" line\n",
1213                                     fname, lineno, 0 );
1214 #endif
1215
1216                                 return( 1 );
1217                         }
1218                         if ( be == NULL ) {
1219                                 if ( strcasecmp( cargv[1], "on" ) == 0 ) {
1220                                         global_restrictops |= SLAP_RESTRICT_OP_WRITES;
1221                                 } else {
1222                                         global_restrictops &= ~SLAP_RESTRICT_OP_WRITES;
1223                                 }
1224                         } else {
1225                                 if ( strcasecmp( cargv[1], "on" ) == 0 ) {
1226                                         be->be_restrictops |= SLAP_RESTRICT_OP_WRITES;
1227                                 } else {
1228                                         be->be_restrictops &= ~SLAP_RESTRICT_OP_WRITES;
1229                                 }
1230                         }
1231
1232
1233                 /* allow these features */
1234                 } else if ( strcasecmp( cargv[0], "allows" ) == 0 ||
1235                         strcasecmp( cargv[0], "allow" ) == 0 )
1236                 {
1237                         slap_mask_t     allows;
1238
1239                         if ( be != NULL ) {
1240 #ifdef NEW_LOGGING
1241                                 LDAP_LOG(( "config", LDAP_LEVEL_INFO,
1242                                            "%s: line %d: allow line must appear prior to "
1243                                            "database definitions.\n", fname, lineno ));
1244 #else
1245                                 Debug( LDAP_DEBUG_ANY,
1246 "%s: line %d: allow line must appear prior to database definitions\n",
1247                                     fname, lineno, 0 );
1248 #endif
1249
1250                         }
1251
1252                         if ( cargc < 2 ) {
1253 #ifdef NEW_LOGGING
1254                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
1255                                            "%s: line %d: missing feature(s) in \"allow <features>\""
1256                                            " line\n", fname, lineno ));
1257 #else
1258                                 Debug( LDAP_DEBUG_ANY,
1259             "%s: line %d: missing feature(s) in \"allow <features>\" line\n",
1260                                     fname, lineno, 0 );
1261 #endif
1262
1263                                 return( 1 );
1264                         }
1265
1266                         allows = 0;
1267
1268                         for( i=1; i < cargc; i++ ) {
1269                                 if( strcasecmp( cargv[i], "bind_v2" ) == 0 ) {
1270                                         allows |= SLAP_ALLOW_BIND_V2;
1271
1272                                 } else if( strcasecmp( cargv[i], "bind_anon_cred" ) == 0 ) {
1273                                         allows |= SLAP_ALLOW_BIND_ANON_CRED;
1274
1275                                 } else if( strcasecmp( cargv[i], "bind_anon_dn" ) == 0 ) {
1276                                         allows |= SLAP_ALLOW_BIND_ANON_DN;
1277
1278                                 } else if( strcasecmp( cargv[i], "none" ) != 0 ) {
1279 #ifdef NEW_LOGGING
1280                                         LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
1281                                                    "%s: line %d: unknown feature %s in "
1282                                                    "\"allow <features>\" line.\n",
1283                                                    fname, lineno, cargv[1] ));
1284 #else
1285                                         Debug( LDAP_DEBUG_ANY,
1286                     "%s: line %d: unknown feature %s in \"allow <features>\" line\n",
1287                                             fname, lineno, cargv[i] );
1288 #endif
1289
1290                                         return( 1 );
1291                                 }
1292                         }
1293
1294                         global_allows = allows;
1295
1296                 /* disallow these features */
1297                 } else if ( strcasecmp( cargv[0], "disallows" ) == 0 ||
1298                         strcasecmp( cargv[0], "disallow" ) == 0 )
1299                 {
1300                         slap_mask_t     disallows;
1301
1302                         if ( be != NULL ) {
1303 #ifdef NEW_LOGGING
1304                                 LDAP_LOG(( "config", LDAP_LEVEL_INFO,
1305                                            "%s: line %d: disallow line must appear prior to "
1306                                            "database definitions.\n", fname, lineno ));
1307 #else
1308                                 Debug( LDAP_DEBUG_ANY,
1309 "%s: line %d: disallow line must appear prior to database definitions\n",
1310                                     fname, lineno, 0 );
1311 #endif
1312
1313                         }
1314
1315                         if ( cargc < 2 ) {
1316 #ifdef NEW_LOGGING
1317                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
1318                                            "%s: line %d: missing feature(s) in \"disallow <features>\""
1319                                            " line.\n", fname, lineno ));
1320 #else
1321                                 Debug( LDAP_DEBUG_ANY,
1322             "%s: line %d: missing feature(s) in \"disallow <features>\" line\n",
1323                                     fname, lineno, 0 );
1324 #endif
1325
1326                                 return( 1 );
1327                         }
1328
1329                         disallows = 0;
1330
1331                         for( i=1; i < cargc; i++ ) {
1332                                 if( strcasecmp( cargv[i], "bind_anon" ) == 0 ) {
1333                                         disallows |= SLAP_DISALLOW_BIND_ANON;
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_2_anon" ) == 0 ) {
1342                                         disallows |= SLAP_DISALLOW_TLS_2_ANON;
1343
1344                                 } else if( strcasecmp( cargv[i], "tls_authc" ) == 0 ) {
1345                                         disallows |= SLAP_DISALLOW_TLS_AUTHC;
1346
1347                                 } else if( strcasecmp( cargv[i], "none" ) != 0 ) {
1348 #ifdef NEW_LOGGING
1349                                         LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
1350                                                 "%s: line %d: unknown feature %s in "
1351                                                 "\"disallow <features>\" line.\n",
1352                                                 fname, lineno, cargv[i] ));
1353 #else
1354                                         Debug( LDAP_DEBUG_ANY,
1355                     "%s: line %d: unknown feature %s in \"disallow <features>\" line\n",
1356                                             fname, lineno, cargv[i] );
1357 #endif
1358
1359                                         return( 1 );
1360                                 }
1361                         }
1362
1363                         global_disallows = disallows;
1364
1365                 /* require these features */
1366                 } else if ( strcasecmp( cargv[0], "requires" ) == 0 ||
1367                         strcasecmp( cargv[0], "require" ) == 0 )
1368                 {
1369                         slap_mask_t     requires;
1370
1371                         if ( cargc < 2 ) {
1372 #ifdef NEW_LOGGING
1373                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
1374                                            "%s: line %d: missing feature(s) in "
1375                                            "\"require <features>\" line.\n", fname, lineno ));
1376 #else
1377                                 Debug( LDAP_DEBUG_ANY,
1378             "%s: line %d: missing feature(s) in \"require <features>\" line\n",
1379                                     fname, lineno, 0 );
1380 #endif
1381
1382                                 return( 1 );
1383                         }
1384
1385                         requires = 0;
1386
1387                         for( i=1; i < cargc; i++ ) {
1388                                 if( strcasecmp( cargv[i], "bind" ) == 0 ) {
1389                                         requires |= SLAP_REQUIRE_BIND;
1390
1391                                 } else if( strcasecmp( cargv[i], "LDAPv3" ) == 0 ) {
1392                                         requires |= SLAP_REQUIRE_LDAP_V3;
1393
1394                                 } else if( strcasecmp( cargv[i], "authc" ) == 0 ) {
1395                                         requires |= SLAP_REQUIRE_AUTHC;
1396
1397                                 } else if( strcasecmp( cargv[i], "SASL" ) == 0 ) {
1398                                         requires |= SLAP_REQUIRE_SASL;
1399
1400                                 } else if( strcasecmp( cargv[i], "strong" ) == 0 ) {
1401                                         requires |= SLAP_REQUIRE_STRONG;
1402
1403                                 } else if( strcasecmp( cargv[i], "none" ) != 0 ) {
1404 #ifdef NEW_LOGGING
1405                                         LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
1406                                                    "%s: line %d: unknown feature %s in "
1407                                                    "\"require <features>\" line.\n",
1408                                                    fname, lineno ));
1409 #else
1410                                         Debug( LDAP_DEBUG_ANY,
1411                     "%s: line %d: unknown feature %s in \"require <features>\" line\n",
1412                                             fname, lineno, cargv[i] );
1413 #endif
1414
1415                                         return( 1 );
1416                                 }
1417                         }
1418
1419                         if ( be == NULL ) {
1420                                 global_requires = requires;
1421                         } else {
1422                                 be->be_requires = requires;
1423                         }
1424
1425                 /* required security factors */
1426                 } else if ( strcasecmp( cargv[0], "security" ) == 0 ) {
1427                         slap_ssf_set_t *set;
1428
1429                         if ( cargc < 2 ) {
1430 #ifdef NEW_LOGGING
1431                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
1432                                            "%s: line %d: missing factor(s) in \"security <factors>\""
1433                                            " line.\n", fname, lineno ));
1434 #else
1435                                 Debug( LDAP_DEBUG_ANY,
1436             "%s: line %d: missing factor(s) in \"security <factors>\" line\n",
1437                                     fname, lineno, 0 );
1438 #endif
1439
1440                                 return( 1 );
1441                         }
1442
1443                         if ( be == NULL ) {
1444                                 set = &global_ssf_set;
1445                         } else {
1446                                 set = &be->be_ssf_set;
1447                         }
1448
1449                         for( i=1; i < cargc; i++ ) {
1450                                 if( strncasecmp( cargv[i], "ssf=",
1451                                         sizeof("ssf") ) == 0 )
1452                                 {
1453                                         set->sss_ssf =
1454                                                 atoi( &cargv[i][sizeof("ssf")] );
1455
1456                                 } else if( strncasecmp( cargv[i], "transport=",
1457                                         sizeof("transport") ) == 0 )
1458                                 {
1459                                         set->sss_transport =
1460                                                 atoi( &cargv[i][sizeof("transport")] );
1461
1462                                 } else if( strncasecmp( cargv[i], "tls=",
1463                                         sizeof("tls") ) == 0 )
1464                                 {
1465                                         set->sss_tls =
1466                                                 atoi( &cargv[i][sizeof("tls")] );
1467
1468                                 } else if( strncasecmp( cargv[i], "sasl=",
1469                                         sizeof("sasl") ) == 0 )
1470                                 {
1471                                         set->sss_sasl =
1472                                                 atoi( &cargv[i][sizeof("sasl")] );
1473
1474                                 } else if( strncasecmp( cargv[i], "update_ssf=",
1475                                         sizeof("update_ssf") ) == 0 )
1476                                 {
1477                                         set->sss_update_ssf =
1478                                                 atoi( &cargv[i][sizeof("update_ssf")] );
1479
1480                                 } else if( strncasecmp( cargv[i], "update_transport=",
1481                                         sizeof("update_transport") ) == 0 )
1482                                 {
1483                                         set->sss_update_transport =
1484                                                 atoi( &cargv[i][sizeof("update_transport")] );
1485
1486                                 } else if( strncasecmp( cargv[i], "update_tls=",
1487                                         sizeof("update_tls") ) == 0 )
1488                                 {
1489                                         set->sss_update_tls =
1490                                                 atoi( &cargv[i][sizeof("update_tls")] );
1491
1492                                 } else if( strncasecmp( cargv[i], "update_sasl=",
1493                                         sizeof("update_sasl") ) == 0 )
1494                                 {
1495                                         set->sss_update_sasl =
1496                                                 atoi( &cargv[i][sizeof("update_sasl")] );
1497
1498                                 } else {
1499 #ifdef NEW_LOGGING
1500                                         LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
1501                                                    "%s: line %d: unknown factor %S in "
1502                                                    "\"security <factors>\" line.\n",
1503                                                    fname, lineno, cargv[1] ));
1504 #else
1505                                         Debug( LDAP_DEBUG_ANY,
1506                     "%s: line %d: unknown factor %s in \"security <factors>\" line\n",
1507                                             fname, lineno, cargv[i] );
1508 #endif
1509
1510                                         return( 1 );
1511                                 }
1512                         }
1513                 /* where to send clients when we don't hold it */
1514                 } else if ( strcasecmp( cargv[0], "referral" ) == 0 ) {
1515                         if ( cargc < 2 ) {
1516 #ifdef NEW_LOGGING
1517                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
1518                                            "%s: line %d: missing URL in \"referral <URL>\""
1519                                            " line.\n", fname, lineno ));
1520 #else
1521                                 Debug( LDAP_DEBUG_ANY,
1522                     "%s: line %d: missing URL in \"referral <URL>\" line\n",
1523                                     fname, lineno, 0 );
1524 #endif
1525
1526                                 return( 1 );
1527                         }
1528
1529                         if( validate_global_referral( cargv[1] ) ) {
1530 #ifdef NEW_LOGGING
1531                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT, "%s: line %d: "
1532                                         "invalid URL (%s) in \"referral\" line.\n",
1533                                         fname, lineno, cargv[1] ));
1534 #else
1535                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1536                                         "invalid URL (%s) in \"referral\" line.\n",
1537                                     fname, lineno, cargv[1] );
1538 #endif
1539                                 return 1;
1540                         }
1541
1542                         vals[0]->bv_val = cargv[1];
1543                         vals[0]->bv_len = strlen( vals[0]->bv_val );
1544                         value_add( &default_referral, vals );
1545
1546 #ifdef NEW_LOGGING
1547                 } else if ( strcasecmp( cargv[0], "logfile" ) == 0 ) {
1548                         FILE *logfile;
1549                         if ( cargc < 2 ) {
1550 #ifdef NEW_LOGGING
1551                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
1552                                            "%s: line %d: Error in logfile directive, "
1553                                            "\"logfile <filename>\"\n", fname, lineno ));
1554 #else
1555                                 Debug( LDAP_DEBUG_ANY,
1556                                        "%s: line %d: Error in logfile directive, \"logfile filename\"\n",
1557                                        fname, lineno, 0 );
1558 #endif
1559
1560                                 return( 1 );
1561                         }
1562                         logfile = fopen( cargv[1], "w" );
1563                         if ( logfile != NULL ) lutil_debug_file( logfile );
1564
1565 #endif
1566                 /* start of a new database definition */
1567                 } else if ( strcasecmp( cargv[0], "debug" ) == 0 ) {
1568                         int level;
1569                         if ( cargc < 3 ) {
1570 #ifdef NEW_LOGGING
1571                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
1572                                            "%s: line %d: Error in debug directive, "
1573                                            "\"debug <subsys> <level>\"\n", fname, lineno ));
1574 #else
1575                                 Debug( LDAP_DEBUG_ANY,
1576                                         "%s: line %d: Error in debug directive, \"debug subsys level\"\n",
1577                                         fname, lineno, 0 );
1578 #endif
1579
1580                                 return( 1 );
1581                         }
1582                         level = atoi( cargv[2] );
1583                         if ( level <= 0 ) level = lutil_mnem2level( cargv[2] );
1584                         lutil_set_debug_level( cargv[1], level );
1585                 /* specify an Object Identifier macro */
1586                 } else if ( strcasecmp( cargv[0], "objectidentifier" ) == 0 ) {
1587                         rc = parse_oidm( fname, lineno, cargc, cargv );
1588                         if( rc ) return rc;
1589
1590                 /* specify an objectclass */
1591                 } else if ( strcasecmp( cargv[0], "objectclass" ) == 0 ) {
1592                         if ( *cargv[1] == '(' ) {
1593                                 char * p;
1594                                 p = strchr(saveline,'(');
1595                                 rc = parse_oc( fname, lineno, p, cargv );
1596                                 if( rc ) return rc;
1597
1598                         } else {
1599 #ifdef NEW_LOGGING
1600                                 LDAP_LOG(( "config", LDAP_LEVEL_INFO,
1601                                            "%s: line %d: old objectclass format not supported\n",
1602                                            fname, lineno ));
1603 #else
1604                                 Debug( LDAP_DEBUG_ANY,
1605                                        "%s: line %d: old objectclass format not supported.\n",
1606                                        fname, lineno, 0 );
1607 #endif
1608
1609                         }
1610
1611                 /* specify an attribute type */
1612                 } else if (( strcasecmp( cargv[0], "attributetype" ) == 0 )
1613                         || ( strcasecmp( cargv[0], "attribute" ) == 0 ))
1614                 {
1615                         if ( *cargv[1] == '(' ) {
1616                                 char * p;
1617                                 p = strchr(saveline,'(');
1618                                 rc = parse_at( fname, lineno, p, cargv );
1619                                 if( rc ) return rc;
1620
1621                         } else {
1622 #ifdef NEW_LOGGING
1623                                 LDAP_LOG(( "config", LDAP_LEVEL_INFO,
1624                                            "%s: line %d: old attribute type format not supported.\n",
1625                                            fname, lineno ));
1626 #else
1627                                 Debug( LDAP_DEBUG_ANY,
1628     "%s: line %d: old attribute type format not supported.\n",
1629                                     fname, lineno, 0 );
1630 #endif
1631
1632                         }
1633
1634                 /* turn on/off schema checking */
1635                 } else if ( strcasecmp( cargv[0], "schemacheck" ) == 0 ) {
1636                         if ( cargc < 2 ) {
1637 #ifdef NEW_LOGGING
1638                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
1639                                            "%s: line %d: missing on|off in "
1640                                            "\"schemacheck <on|off>\" line.\n",
1641                                            fname, lineno ));
1642 #else
1643                                 Debug( LDAP_DEBUG_ANY,
1644     "%s: line %d: missing on|off in \"schemacheck <on|off>\" line\n",
1645                                     fname, lineno, 0 );
1646 #endif
1647
1648                                 return( 1 );
1649                         }
1650                         if ( strcasecmp( cargv[1], "off" ) == 0 ) {
1651                                 global_schemacheck = 0;
1652                         } else {
1653                                 global_schemacheck = 1;
1654                         }
1655
1656                 /* specify access control info */
1657                 } else if ( strcasecmp( cargv[0], "access" ) == 0 ) {
1658                         parse_acl( be, fname, lineno, cargc, cargv );
1659
1660                 /* debug level to log things to syslog */
1661                 } else if ( strcasecmp( cargv[0], "loglevel" ) == 0 ) {
1662                         if ( cargc < 2 ) {
1663 #ifdef NEW_LOGGING
1664                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
1665                                            "%s: line %d: missing level in \"loglevel <level>\""
1666                                            " line.\n", fname, lineno ));
1667 #else
1668                                 Debug( LDAP_DEBUG_ANY,
1669                     "%s: line %d: missing level in \"loglevel <level>\" line\n",
1670                                     fname, lineno, 0 );
1671 #endif
1672
1673                                 return( 1 );
1674                         }
1675
1676                         ldap_syslog = 0;
1677
1678                         for( i=1; i < cargc; i++ ) {
1679                                 ldap_syslog += atoi( cargv[1] );
1680                         }
1681
1682                 /* list of replicas of the data in this backend (master only) */
1683                 } else if ( strcasecmp( cargv[0], "replica" ) == 0 ) {
1684                         if ( cargc < 2 ) {
1685 #ifdef NEW_LOGGING
1686                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
1687                                            "%s: line %d: missing host in \"replica "
1688                                            " <host[:port]\" line\n", fname, lineno ));
1689 #else
1690                                 Debug( LDAP_DEBUG_ANY,
1691             "%s: line %d: missing host in \"replica <host[:port]>\" line\n",
1692                                     fname, lineno, 0 );
1693 #endif
1694
1695                                 return( 1 );
1696                         }
1697                         if ( be == NULL ) {
1698 #ifdef NEW_LOGGING
1699                                 LDAP_LOG(( "config", LDAP_LEVEL_INFO,
1700                                            "%s: line %d: replica line must appear inside "
1701                                            "a database definition (ignored).\n", fname, lineno ));
1702 #else
1703                                 Debug( LDAP_DEBUG_ANY,
1704 "%s: line %d: replica line must appear inside a database definition (ignored)\n",
1705                                     fname, lineno, 0 );
1706 #endif
1707
1708                         } else {
1709                                 int nr = -1;
1710
1711                                 for ( i = 1; i < cargc; i++ ) {
1712                                         if ( strncasecmp( cargv[i], "host=", 5 )
1713                                             == 0 ) {
1714                                                 nr = add_replica_info( be, 
1715                                                         cargv[i] + 5 );
1716                                                 break;
1717                                         }
1718                                 }
1719                                 if ( i == cargc ) {
1720 #ifdef NEW_LOGGING
1721                                         LDAP_LOG(( "config", LDAP_LEVEL_INFO,
1722                                                    "%s: line %d: missing host in \"replica\" "
1723                                                    "line (ignored)\n", fname, lineno ));
1724 #else
1725                                         Debug( LDAP_DEBUG_ANY,
1726                     "%s: line %d: missing host in \"replica\" line (ignored)\n",
1727                                             fname, lineno, 0 );
1728 #endif
1729
1730                                 } else if ( nr == -1 ) {
1731 #ifdef NEW_LOGGING
1732                                         LDAP_LOG(( "config", LDAP_LEVEL_INFO,
1733                                                    "%s: line %d: unable to add"
1734                                                    " replica \"%s\""
1735                                                    " (ignored)\n",
1736                                                    fname, lineno, 
1737                                                    cargv[i] + 5 ));
1738 #else
1739                                         Debug( LDAP_DEBUG_ANY,
1740                 "%s: line %d: unable to add replica \"%s\" (ignored)\n",
1741                                                 fname, lineno, cargv[i] + 5 );
1742 #endif
1743                                 } else {
1744                                         for ( i = 1; i < cargc; i++ ) {
1745                                                 if ( strncasecmp( cargv[i], "suffix=", 7 ) == 0 ) {
1746
1747                                                         switch ( add_replica_suffix( be, nr, cargv[i] + 7 ) ) {
1748                                                         case 1:
1749 #ifdef NEW_LOGGING
1750                                                                 LDAP_LOG(( "config", LDAP_LEVEL_INFO,
1751                                                                                 "%s: line %d: suffix \"%s\" in \"replica\" line is not valid for backend (ignored)\n",
1752                                                                                 fname, lineno, cargv[i] + 7 ));
1753 #else
1754                                                                 Debug( LDAP_DEBUG_ANY,
1755                                                                                 "%s: line %d: suffix \"%s\" in \"replica\" line is not valid for backend (ignored)\n",
1756                                                                                 fname, lineno, cargv[i] + 7 );
1757 #endif
1758                                                                 break;
1759
1760                                                         case 2:
1761 #ifdef NEW_LOGGING
1762                                                                 LDAP_LOG(( "config", LDAP_LEVEL_INFO,
1763                                                                                         "%s: line %d: unable to normalize suffix in \"replica\" line (ignored)\n",
1764                                                                                         fname, lineno ));
1765 #else
1766                                                                 Debug( LDAP_DEBUG_ANY,
1767                                                                                  "%s: line %d: unable to normalize suffix in \"replica\" line (ignored)\n",
1768                                                                                  fname, lineno, 0 );
1769 #endif
1770                                                                 break;
1771                                                         }
1772                                                 }
1773                                         }
1774                                 }
1775                         }
1776
1777                 /* dn of master entity allowed to write to replica */
1778                 } else if ( strcasecmp( cargv[0], "updatedn" ) == 0 ) {
1779                         if ( cargc < 2 ) {
1780 #ifdef NEW_LOGGING
1781                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
1782                                            "%s: line %d: missing dn in \"updatedn <dn>\""
1783                                            " line.\n", fname, lineno ));
1784 #else
1785                                 Debug( LDAP_DEBUG_ANY,
1786                     "%s: line %d: missing dn in \"updatedn <dn>\" line\n",
1787                                     fname, lineno, 0 );
1788 #endif
1789
1790                                 return( 1 );
1791                         }
1792                         if ( be == NULL ) {
1793 #ifdef NEW_LOGGING
1794                                 LDAP_LOG(( "config", LDAP_LEVEL_INFO,
1795                                            "%s: line %d: updatedn line must appear inside "
1796                                            "a database definition (ignored)\n",
1797                                            fname, lineno ));
1798 #else
1799                                 Debug( LDAP_DEBUG_ANY,
1800 "%s: line %d: updatedn line must appear inside a database definition (ignored)\n",
1801                                     fname, lineno, 0 );
1802 #endif
1803
1804                         } else {
1805                                 be->be_update_ndn = ch_strdup( cargv[1] );
1806                                 if ( load_ucdata( NULL ) < 0 ) {
1807                                         return( 1 );
1808                                 }
1809                                 if( dn_normalize( be->be_update_ndn ) == NULL ) {
1810 #ifdef NEW_LOGGING
1811                                         LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
1812                                                    "%s: line %d: updatedn DN is invalid.\n",
1813                                                    fname, lineno ));
1814 #else
1815                                         Debug( LDAP_DEBUG_ANY,
1816 "%s: line %d: updatedn DN is invalid\n",
1817                                             fname, lineno, 0 );
1818 #endif
1819
1820                                         return 1;
1821                                 }
1822                         }
1823
1824                 } else if ( strcasecmp( cargv[0], "updateref" ) == 0 ) {
1825                         if ( cargc < 2 ) {
1826 #ifdef NEW_LOGGING
1827                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT, "%s: line %d: "
1828                                         "missing url in \"updateref <ldapurl>\" line.\n",
1829                                         fname, lineno ));
1830 #else
1831                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1832                                         "missing url in \"updateref <ldapurl>\" line\n",
1833                                     fname, lineno, 0 );
1834 #endif
1835
1836                                 return( 1 );
1837                         }
1838                         if ( be == NULL ) {
1839 #ifdef NEW_LOGGING
1840                                 LDAP_LOG(( "config", LDAP_LEVEL_INFO, "%s: line %d: "
1841                                         "updateref line must appear inside a database definition "
1842                                         "(ignored)\n", fname, lineno ));
1843 #else
1844                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1845                                         "updateref line must appear inside a database definition "
1846                                         "(ignored)\n", fname, lineno, 0 );
1847 #endif
1848                                 return 1;
1849
1850                         } else if ( be->be_update_ndn == NULL ) {
1851 #ifdef NEW_LOGGING
1852                                 LDAP_LOG(( "config", LDAP_LEVEL_INFO, "%s: line %d: "
1853                                         "updateref line must come after updatedn (ignored).\n",
1854                                         fname, lineno ));
1855 #else
1856                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1857                                         "updateref line must after updatedn (ignored)\n",
1858                                     fname, lineno, 0 );
1859 #endif
1860                                 return 1;
1861                         }
1862
1863                         if( validate_global_referral( cargv[1] ) ) {
1864 #ifdef NEW_LOGGING
1865                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT, "%s: line %d: "
1866                                         "invalid URL (%s) in \"updateref\" line.\n",
1867                                         fname, lineno, cargv[1] ));
1868 #else
1869                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1870                                         "invalid URL (%s) in \"updateref\" line.\n",
1871                                     fname, lineno, cargv[1] );
1872 #endif
1873                                 return 1;
1874                         }
1875
1876                         vals[0]->bv_val = cargv[1];
1877                         vals[0]->bv_len = strlen( vals[0]->bv_val );
1878                         value_add( &be->be_update_refs, vals );
1879
1880                 /* replication log file to which changes are appended */
1881                 } else if ( strcasecmp( cargv[0], "replogfile" ) == 0 ) {
1882                         if ( cargc < 2 ) {
1883 #ifdef NEW_LOGGING
1884                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
1885                                            "%s: line %d: missing filename in \"replogfile <filename>\""
1886                                            " line.\n", fname, lineno ));
1887 #else
1888                                 Debug( LDAP_DEBUG_ANY,
1889             "%s: line %d: missing filename in \"replogfile <filename>\" line\n",
1890                                     fname, lineno, 0 );
1891 #endif
1892
1893                                 return( 1 );
1894                         }
1895                         if ( be ) {
1896                                 be->be_replogfile = ch_strdup( cargv[1] );
1897                         } else {
1898                                 replogfile = ch_strdup( cargv[1] );
1899                         }
1900
1901                 /* file from which to read additional rootdse attrs */
1902                 } else if ( strcasecmp( cargv[0], "rootdse" ) == 0) {
1903                         if ( cargc < 2 ) {
1904 #ifdef NEW_LOGGING
1905                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT, "%s: line %d: "
1906                                         "missing filename in \"rootDSEfile <filename>\" line.\n",
1907                                         fname, lineno ));
1908 #else
1909                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1910                                         "missing filename in \"rootDSEfile <filename>\" line.\n",
1911                                     fname, lineno, 0 );
1912 #endif
1913                                 return 1;
1914                         }
1915
1916                         if( read_root_dse_file( cargv[1] ) ) {
1917 #ifdef NEW_LOGGING
1918                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT, "%s: line %d: "
1919                                         "could not read \"rootDSEfile <filename>\" line.\n",
1920                                         fname, lineno ));
1921 #else
1922                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1923                                         "could not read \"rootDSEfile <filename>\" line\n",
1924                                     fname, lineno, 0 );
1925 #endif
1926                                 return 1;
1927                         }
1928
1929                 /* maintain lastmodified{by,time} attributes */
1930                 } else if ( strcasecmp( cargv[0], "lastmod" ) == 0 ) {
1931                         if ( cargc < 2 ) {
1932 #ifdef NEW_LOGGING
1933                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
1934                                            "%s: line %d: missing on|off in \"lastmod <on|off>\""
1935                                            " line.\n", fname, lineno ));
1936 #else
1937                                 Debug( LDAP_DEBUG_ANY,
1938             "%s: line %d: missing on|off in \"lastmod <on|off>\" line\n",
1939                                     fname, lineno, 0 );
1940 #endif
1941
1942                                 return( 1 );
1943                         }
1944                         if ( strcasecmp( cargv[1], "on" ) == 0 ) {
1945                                 if ( be )
1946                                         be->be_lastmod = ON;
1947                                 else
1948                                         global_lastmod = ON;
1949                         } else {
1950                                 if ( be )
1951                                         be->be_lastmod = OFF;
1952                                 else
1953                                         global_lastmod = OFF;
1954                         }
1955
1956                 /* set idle timeout value */
1957                 } else if ( strcasecmp( cargv[0], "idletimeout" ) == 0 ) {
1958                         int i;
1959                         if ( cargc < 2 ) {
1960 #ifdef NEW_LOGGING
1961                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
1962                                            "%s: line %d: missing timeout value in "
1963                                            "\"idletimeout <seconds>\" line.\n", fname, lineno ));
1964 #else
1965                                 Debug( LDAP_DEBUG_ANY,
1966             "%s: line %d: missing timeout value in \"idletimeout <seconds>\" line\n",
1967                                     fname, lineno, 0 );
1968 #endif
1969
1970                                 return( 1 );
1971                         }
1972
1973                         i = atoi( cargv[1] );
1974
1975                         if( i < 0 ) {
1976 #ifdef NEW_LOGGING
1977                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
1978                                            "%s: line %d: timeout value (%d) invalid "
1979                                            "\"idletimeout <seconds>\" line.\n",
1980                                            fname, lineno, i ));
1981 #else
1982                                 Debug( LDAP_DEBUG_ANY,
1983             "%s: line %d: timeout value (%d) invalid \"idletimeout <seconds>\" line\n",
1984                                     fname, lineno, i );
1985 #endif
1986
1987                                 return( 1 );
1988                         }
1989
1990                         global_idletimeout = i;
1991
1992                 /* include another config file */
1993                 } else if ( strcasecmp( cargv[0], "include" ) == 0 ) {
1994                         if ( cargc < 2 ) {
1995 #ifdef NEW_LOGGING
1996                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
1997                                            "%s: line %d: missing filename in \"include "
1998                                            "<filename>\" line.\n", fname, lineno ));
1999 #else
2000                                 Debug( LDAP_DEBUG_ANY,
2001     "%s: line %d: missing filename in \"include <filename>\" line\n",
2002                                     fname, lineno, 0 );
2003 #endif
2004
2005                                 return( 1 );
2006                         }
2007                         savefname = ch_strdup( cargv[1] );
2008                         savelineno = lineno;
2009
2010                         if ( read_config( savefname ) != 0 ) {
2011                                 return( 1 );
2012                         }
2013
2014                         free( savefname );
2015                         lineno = savelineno - 1;
2016
2017                 /* location of kerberos srvtab file */
2018                 } else if ( strcasecmp( cargv[0], "srvtab" ) == 0 ) {
2019                         if ( cargc < 2 ) {
2020 #ifdef NEW_LOGGING
2021                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
2022                                            "%s: line %d: missing filename in \"srvtab "
2023                                            "<filename>\" line.\n", fname, lineno ));
2024 #else
2025                                 Debug( LDAP_DEBUG_ANY,
2026             "%s: line %d: missing filename in \"srvtab <filename>\" line\n",
2027                                     fname, lineno, 0 );
2028 #endif
2029
2030                                 return( 1 );
2031                         }
2032                         ldap_srvtab = ch_strdup( cargv[1] );
2033
2034 #ifdef SLAPD_MODULES
2035                 } else if (strcasecmp( cargv[0], "moduleload") == 0 ) {
2036                    if ( cargc < 2 ) {
2037 #ifdef NEW_LOGGING
2038                            LDAP_LOG(( "config", LDAP_LEVEL_INFO,
2039                                       "%s: line %d: missing filename in \"moduleload "
2040                                       "<filename>\" line.\n", fname, lineno ));
2041 #else
2042                       Debug( LDAP_DEBUG_ANY,
2043                              "%s: line %d: missing filename in \"moduleload <filename>\" line\n",
2044                              fname, lineno, 0 );
2045 #endif
2046
2047                       exit( EXIT_FAILURE );
2048                    }
2049                    if (module_load(cargv[1], cargc - 2, (cargc > 2) ? cargv + 2 : NULL)) {
2050 #ifdef NEW_LOGGING
2051                            LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
2052                                       "%s: line %d: failed to load or initialize module %s\n"<
2053                                       fname, lineno, cargv[1] ));
2054 #else
2055                       Debug( LDAP_DEBUG_ANY,
2056                              "%s: line %d: failed to load or initialize module %s\n",
2057                              fname, lineno, cargv[1]);
2058 #endif
2059
2060                       exit( EXIT_FAILURE );
2061                    }
2062                 } else if (strcasecmp( cargv[0], "modulepath") == 0 ) {
2063                    if ( cargc != 2 ) {
2064 #ifdef NEW_LOGGING
2065                            LDAP_LOG(( "config", LDAP_LEVEL_INFO,
2066                                       "%s: line %d: missing path in \"modulepath <path>\""
2067                                       " line\n", fname, lineno ));
2068 #else
2069                       Debug( LDAP_DEBUG_ANY,
2070                              "%s: line %d: missing path in \"modulepath <path>\" line\n",
2071                              fname, lineno, 0 );
2072 #endif
2073
2074                       exit( EXIT_FAILURE );
2075                    }
2076                    if (module_path( cargv[1] )) {
2077 #ifdef NEW_LOGGING
2078                            LDAP_LOG(( "cofig", LDAP_LEVEL_CRIT,
2079                                       "%s: line %d: failed to set module search path to %s.\n",
2080                                       fname, lineno, cargv[1] ));
2081 #else
2082                            Debug( LDAP_DEBUG_ANY,
2083                                   "%s: line %d: failed to set module search path to %s\n",
2084                                   fname, lineno, cargv[1]);
2085 #endif
2086
2087                       exit( EXIT_FAILURE );
2088                    }
2089                    
2090 #endif /*SLAPD_MODULES*/
2091
2092 #ifdef HAVE_TLS
2093                 } else if ( !strcasecmp( cargv[0], "TLSRandFile" ) ) {
2094                         rc = ldap_pvt_tls_set_option( NULL,
2095                                                       LDAP_OPT_X_TLS_RANDOM_FILE,
2096                                                       cargv[1] );
2097                         if ( rc )
2098                                 return rc;
2099
2100                 } else if ( !strcasecmp( cargv[0], "TLSCipherSuite" ) ) {
2101                         rc = ldap_pvt_tls_set_option( NULL,
2102                                                       LDAP_OPT_X_TLS_CIPHER_SUITE,
2103                                                       cargv[1] );
2104                         if ( rc )
2105                                 return rc;
2106
2107                 } else if ( !strcasecmp( cargv[0], "TLSCertificateFile" ) ) {
2108                         rc = ldap_pvt_tls_set_option( NULL,
2109                                                       LDAP_OPT_X_TLS_CERTFILE,
2110                                                       cargv[1] );
2111                         if ( rc )
2112                                 return rc;
2113
2114                 } else if ( !strcasecmp( cargv[0], "TLSCertificateKeyFile" ) ) {
2115                         rc = ldap_pvt_tls_set_option( NULL,
2116                                                       LDAP_OPT_X_TLS_KEYFILE,
2117                                                       cargv[1] );
2118                         if ( rc )
2119                                 return rc;
2120
2121                 } else if ( !strcasecmp( cargv[0], "TLSCACertificatePath" ) ) {
2122                         rc = ldap_pvt_tls_set_option( NULL,
2123                                                       LDAP_OPT_X_TLS_CACERTDIR,
2124                                                       cargv[1] );
2125                         if ( rc )
2126                                 return rc;
2127
2128                 } else if ( !strcasecmp( cargv[0], "TLSCACertificateFile" ) ) {
2129                         rc = ldap_pvt_tls_set_option( NULL,
2130                                                       LDAP_OPT_X_TLS_CACERTFILE,
2131                                                       cargv[1] );
2132                         if ( rc )
2133                                 return rc;
2134                 } else if ( !strcasecmp( cargv[0], "TLSVerifyClient" ) ) {
2135                         i = atoi(cargv[1]);
2136                         rc = ldap_pvt_tls_set_option( NULL,
2137                                                       LDAP_OPT_X_TLS_REQUIRE_CERT,
2138                                                       &i );
2139                         if ( rc )
2140                                 return rc;
2141
2142 #endif
2143
2144                 /* pass anything else to the current backend info/db config routine */
2145                 } else {
2146                         if ( bi != NULL ) {
2147                                 if ( bi->bi_config == 0 ) {
2148 #ifdef NEW_LOGGING
2149                                         LDAP_LOG(( "config", LDAP_LEVEL_INFO,
2150                                                    "%s: line %d: unknown directive \"%s\" inside "
2151                                                    "backend info definition (ignored).\n",
2152                                                    fname, lineno, cargv[0] ));
2153 #else
2154                                         Debug( LDAP_DEBUG_ANY,
2155 "%s: line %d: unknown directive \"%s\" inside backend info definition (ignored)\n",
2156                                                 fname, lineno, cargv[0] );
2157 #endif
2158
2159                                 } else {
2160                                         if ( (*bi->bi_config)( bi, fname, lineno, cargc, cargv )
2161                                                 != 0 )
2162                                         {
2163                                                 return( 1 );
2164                                         }
2165                                 }
2166                         } else if ( be != NULL ) {
2167                                 if ( be->be_config == 0 ) {
2168 #ifdef NEW_LOGGING
2169                                         LDAP_LOG(( "config", LDAP_LEVEL_INFO,
2170                                                    "%s: line %d: uknown directive \"%s\" inside "
2171                                                    "backend database definition (ignored).\n",
2172                                                    fname, lineno, cargv[0] ));
2173 #else
2174                                         Debug( LDAP_DEBUG_ANY,
2175 "%s: line %d: unknown directive \"%s\" inside backend database definition (ignored)\n",
2176                                         fname, lineno, cargv[0] );
2177 #endif
2178
2179                                 } else {
2180                                         if ( (*be->be_config)( be, fname, lineno, cargc, cargv )
2181                                                 != 0 )
2182                                         {
2183                                                 return( 1 );
2184                                         }
2185                                 }
2186                         } else {
2187 #ifdef NEW_LOGGING
2188                                 LDAP_LOG(( "config", LDAP_LEVEL_INFO,
2189                                            "%s: line %d: unknown directive \"%s\" outside backend "
2190                                            "info and database definitions (ignored).\n",
2191                                            fname, lineno, cargv[0] ));
2192 #else
2193                                 Debug( LDAP_DEBUG_ANY,
2194 "%s: line %d: unknown directive \"%s\" outside backend info and database definitions (ignored)\n",
2195                                     fname, lineno, cargv[0] );
2196 #endif
2197
2198                         }
2199                 }
2200                 free( saveline );
2201         }
2202         fclose( fp );
2203         if ( load_ucdata( NULL ) < 0 ) {
2204                 return( 1 );
2205         }
2206         return( 0 );
2207 }
2208
2209 static int
2210 fp_parse_line(
2211     char        *line,
2212     int         *argcp,
2213     char        **argv
2214 )
2215 {
2216         char *  token;
2217
2218         *argcp = 0;
2219         for ( token = strtok_quote( line, " \t" ); token != NULL;
2220             token = strtok_quote( NULL, " \t" ) ) {
2221                 if ( *argcp == MAXARGS ) {
2222 #ifdef NEW_LOGGING
2223                         LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
2224                                    "fp_parse_line: too many tokens (%d max).\n",
2225                                    MAXARGS ));
2226 #else
2227                         Debug( LDAP_DEBUG_ANY, "Too many tokens (max %d)\n",
2228                             MAXARGS, 0, 0 );
2229 #endif
2230
2231                         return( 1 );
2232                 }
2233                 argv[(*argcp)++] = token;
2234         }
2235         argv[*argcp] = NULL;
2236         return 0;
2237 }
2238
2239 static char *
2240 strtok_quote( char *line, char *sep )
2241 {
2242         int             inquote;
2243         char            *tmp;
2244         static char     *next;
2245
2246         if ( line != NULL ) {
2247                 next = line;
2248         }
2249         while ( *next && strchr( sep, *next ) ) {
2250                 next++;
2251         }
2252
2253         if ( *next == '\0' ) {
2254                 next = NULL;
2255                 return( NULL );
2256         }
2257         tmp = next;
2258
2259         for ( inquote = 0; *next; ) {
2260                 switch ( *next ) {
2261                 case '"':
2262                         if ( inquote ) {
2263                                 inquote = 0;
2264                         } else {
2265                                 inquote = 1;
2266                         }
2267                         AC_MEMCPY( next, next + 1, strlen( next + 1 ) + 1 );
2268                         break;
2269
2270                 case '\\':
2271                         if ( next[1] )
2272                                 AC_MEMCPY( next,
2273                                             next + 1, strlen( next + 1 ) + 1 );
2274                         next++;         /* dont parse the escaped character */
2275                         break;
2276
2277                 default:
2278                         if ( ! inquote ) {
2279                                 if ( strchr( sep, *next ) != NULL ) {
2280                                         *next++ = '\0';
2281                                         return( tmp );
2282                                 }
2283                         }
2284                         next++;
2285                         break;
2286                 }
2287         }
2288
2289         return( tmp );
2290 }
2291
2292 static char     buf[BUFSIZ];
2293 static char     *line;
2294 static int      lmax, lcur;
2295
2296 #define CATLINE( buf )  { \
2297         int     len; \
2298         len = strlen( buf ); \
2299         while ( lcur + len + 1 > lmax ) { \
2300                 lmax += BUFSIZ; \
2301                 line = (char *) ch_realloc( line, lmax ); \
2302         } \
2303         strcpy( line + lcur, buf ); \
2304         lcur += len; \
2305 }
2306
2307 static char *
2308 fp_getline( FILE *fp, int *lineno )
2309 {
2310         char            *p;
2311
2312         lcur = 0;
2313         CATLINE( buf );
2314         (*lineno)++;
2315
2316         /* hack attack - keeps us from having to keep a stack of bufs... */
2317         if ( strncasecmp( line, "include", 7 ) == 0 ) {
2318                 buf[0] = '\0';
2319                 return( line );
2320         }
2321
2322         while ( fgets( buf, sizeof(buf), fp ) != NULL ) {
2323                 /* trim off \r\n or \n */
2324                 if ( (p = strchr( buf, '\n' )) != NULL ) {
2325                         if( p > buf && p[-1] == '\r' ) --p;
2326                         *p = '\0';
2327                 }
2328                 if ( ! isspace( (unsigned char) buf[0] ) ) {
2329                         return( line );
2330                 }
2331
2332                 /* change leading whitespace to a space */
2333                 buf[0] = ' ';
2334
2335                 CATLINE( buf );
2336                 (*lineno)++;
2337         }
2338         buf[0] = '\0';
2339
2340         return( line[0] ? line : NULL );
2341 }
2342
2343 static void
2344 fp_getline_init( int *lineno )
2345 {
2346         *lineno = -1;
2347         buf[0] = '\0';
2348 }
2349
2350 /* Loads ucdata, returns 1 if loading, 0 if already loaded, -1 on error */
2351 static int
2352 load_ucdata( char *path )
2353 {
2354         static int loaded = 0;
2355         int err;
2356         
2357         if ( loaded ) {
2358                 return( 0 );
2359         }
2360         err = ucdata_load( path ? path : SLAPD_DEFAULT_UCDATA, UCDATA_ALL );
2361         if ( err ) {
2362 #ifdef NEW_LOGGING
2363                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
2364                            "load_ucdata: Error %d loading ucdata.\n", err ));
2365 #else
2366                 Debug( LDAP_DEBUG_ANY, "error loading ucdata (error %d)\n",
2367                        err, 0, 0 );
2368 #endif
2369
2370                 return( -1 );
2371         }
2372         loaded = 1;
2373         return( 1 );
2374 }
2375
2376 void
2377 config_destroy( )
2378 {
2379         ucdata_unload( UCDATA_ALL );
2380         free( line );
2381         if ( slapd_args_file )
2382                 free ( slapd_args_file );
2383         if ( slapd_pid_file )
2384                 free ( slapd_pid_file );
2385         acl_destroy( global_acl, NULL );
2386 }