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