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