]> git.sur5r.net Git - openldap/blob - servers/slapd/config.c
9cf80a8575fd22d0c8b68e61bcc6033ee3324a43
[openldap] / servers / slapd / config.c
1 /* config.c - configuration file handling routines */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-2003 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/signal.h>
15 #include <ac/socket.h>
16 #include <ac/errno.h>
17
18 #include "ldap_pvt.h"
19 #include "slap.h"
20 #ifdef LDAP_SLAPI
21 #include "slapi.h"
22 #endif
23 #include "lutil.h"
24
25 #define ARGS_STEP       512
26
27 /*
28  * defaults for various global variables
29  */
30 struct slap_limits_set deflimit = {
31         SLAPD_DEFAULT_TIMELIMIT,        /* backward compatible limits */
32         0,
33
34         SLAPD_DEFAULT_SIZELIMIT,        /* backward compatible limits */
35         0,
36         -1,                             /* no limit on unchecked size */
37         0,                              /* page limit */
38         0                               /* hide number of entries left */
39 };
40
41 AccessControl   *global_acl = NULL;
42 slap_access_t           global_default_access = ACL_READ;
43 slap_mask_t             global_restrictops = 0;
44 slap_mask_t             global_allows = 0;
45 slap_mask_t             global_disallows = 0;
46 slap_mask_t             global_requires = 0;
47 slap_ssf_set_t  global_ssf_set;
48 char            *replogfile;
49 int             global_gentlehup = 0;
50 int             global_idletimeout = 0;
51 char    *global_host = NULL;
52 char    *global_realm = NULL;
53 char            *ldap_srvtab = "";
54 char            *default_passwd_hash = NULL;
55 int             cargc = 0, cargv_size = 0;
56 char    **cargv;
57 struct berval default_search_base = { 0, NULL };
58 struct berval default_search_nbase = { 0, NULL };
59 unsigned                num_subordinates = 0;
60 struct berval global_schemadn = { 0, NULL };
61 struct berval global_schemandn = { 0, NULL };
62
63 ber_len_t sockbuf_max_incoming = SLAP_SB_MAX_INCOMING_DEFAULT;
64 ber_len_t sockbuf_max_incoming_auth= SLAP_SB_MAX_INCOMING_AUTH;
65
66 int     slap_conn_max_pending = SLAP_CONN_MAX_PENDING_DEFAULT;
67 int     slap_conn_max_pending_auth = SLAP_CONN_MAX_PENDING_AUTH;
68
69 char   *slapd_pid_file  = NULL;
70 char   *slapd_args_file = NULL;
71
72 char   *strtok_quote_ptr;
73
74 int use_reverse_lookup = 0;
75
76 static char     *fp_getline(FILE *fp, int *lineno);
77 static void     fp_getline_init(int *lineno);
78 static int      fp_parse_line(int lineno, char *line);
79
80 static char     *strtok_quote(char *line, char *sep);
81 static int      load_ucdata(char *path);
82
83 #ifdef LDAP_SYNCREPL
84 static void     add_syncrepl LDAP_P(( Backend *, char **, int ));
85 static int      parse_syncrepl_line LDAP_P(( char **, int, syncinfo_t *));
86 #endif
87
88 int
89 read_config( const char *fname, int depth )
90 {
91         FILE    *fp;
92         char    *line, *savefname, *saveline;
93         int savelineno;
94         int     lineno, i;
95         int rc;
96         struct berval vals[2];
97
98         static int lastmod = 1;
99         static BackendInfo *bi = NULL;
100         static BackendDB        *be = NULL;
101
102         vals[1].bv_val = NULL;
103
104         if ( depth == 0 ) {
105                 cargv = ch_calloc( ARGS_STEP + 1, sizeof(*cargv) );
106                 cargv_size = ARGS_STEP + 1;
107         }
108
109         if ( (fp = fopen( fname, "r" )) == NULL ) {
110                 ldap_syslog = 1;
111 #ifdef NEW_LOGGING
112                 LDAP_LOG( CONFIG, ENTRY, 
113                         "read_config: " "could not open config file \"%s\": %s (%d)\n",
114                     fname, strerror(errno), errno );
115 #else
116                 Debug( LDAP_DEBUG_ANY,
117                     "could not open config file \"%s\": %s (%d)\n",
118                     fname, strerror(errno), errno );
119 #endif
120                 return 1;
121         }
122
123 #ifdef NEW_LOGGING
124         LDAP_LOG( CONFIG, ENTRY, 
125                 "read_config: reading config file %s\n", fname, 0, 0 );
126 #else
127         Debug( LDAP_DEBUG_CONFIG, "reading config file %s\n", fname, 0, 0 );
128 #endif
129
130
131         fp_getline_init( &lineno );
132
133         while ( (line = fp_getline( fp, &lineno )) != NULL ) {
134                 /* skip comments and blank lines */
135                 if ( line[0] == '#' || line[0] == '\0' ) {
136                         continue;
137                 }
138
139                 /* fp_parse_line is destructive, we save a copy */
140                 saveline = ch_strdup( line );
141
142                 if ( fp_parse_line( lineno, line ) != 0 ) {
143                         return( 1 );
144                 }
145
146                 if ( cargc < 1 ) {
147 #ifdef NEW_LOGGING
148                         LDAP_LOG( CONFIG, INFO, 
149                                 "%s: line %d: bad config line (ignored)\n", fname, lineno, 0 );
150 #else
151                         Debug( LDAP_DEBUG_ANY,
152                             "%s: line %d: bad config line (ignored)\n",
153                             fname, lineno, 0 );
154 #endif
155
156                         continue;
157                 }
158
159                 if ( strcasecmp( cargv[0], "backend" ) == 0 ) {
160                         if ( cargc < 2 ) {
161 #ifdef NEW_LOGGING
162                                 LDAP_LOG( CONFIG, CRIT, 
163                                            "%s : line %d: missing type in \"backend\" line.\n",
164                                            fname, lineno, 0 );
165 #else
166                                 Debug( LDAP_DEBUG_ANY,
167                 "%s: line %d: missing type in \"backend <type>\" line\n",
168                                     fname, lineno, 0 );
169 #endif
170
171                                 return( 1 );
172                         }
173
174                         if( be != NULL ) {
175 #ifdef NEW_LOGGING
176                                 LDAP_LOG( CONFIG, CRIT, 
177                                            "%s: line %d: backend line must appear before any "
178                                            "database definition.\n", fname, lineno , 0 );
179 #else
180                                 Debug( LDAP_DEBUG_ANY,
181 "%s: line %d: backend line must appear before any database definition\n",
182                                     fname, lineno, 0 );
183 #endif
184
185                                 return( 1 );
186                         }
187
188                         bi = backend_info( cargv[1] );
189
190                         if( bi == NULL ) {
191 #ifdef NEW_LOGGING
192                                 LDAP_LOG( CONFIG, CRIT, 
193                                            "read_config: backend %s initialization failed.\n",
194                                            cargv[1], 0, 0 );
195 #else
196                                 Debug( LDAP_DEBUG_ANY,
197                                         "backend %s initialization failed.\n",
198                                     cargv[1], 0, 0 );
199 #endif
200
201                                 return( 1 );
202                         }
203                 } else if ( strcasecmp( cargv[0], "database" ) == 0 ) {
204                         if ( cargc < 2 ) {
205 #ifdef NEW_LOGGING
206                                 LDAP_LOG( CONFIG, CRIT, 
207                                         "%s: line %d: missing type in \"database <type>\" line\n",
208                                         fname, lineno, 0 );
209 #else
210                                 Debug( LDAP_DEBUG_ANY,
211                 "%s: line %d: missing type in \"database <type>\" line\n",
212                                     fname, lineno, 0 );
213 #endif
214
215                                 return( 1 );
216                         }
217
218                         bi = NULL;
219                         be = backend_db_init( cargv[1] );
220
221                         if( be == NULL ) {
222 #ifdef NEW_LOGGING
223                                 LDAP_LOG( CONFIG, CRIT, 
224                                         "database %s initialization failed.\n", cargv[1], 0, 0 );
225 #else
226                                 Debug( LDAP_DEBUG_ANY,
227                                         "database %s initialization failed.\n",
228                                     cargv[1], 0, 0 );
229 #endif
230
231                                 return( 1 );
232                         }
233
234                 /* set thread concurrency */
235                 } else if ( strcasecmp( cargv[0], "concurrency" ) == 0 ) {
236                         int c;
237                         if ( cargc < 2 ) {
238 #ifdef NEW_LOGGING
239                                 LDAP_LOG( CONFIG, CRIT, 
240                                         "%s: line %d: missing level in \"concurrency <level\" "
241                                         " line\n", fname, lineno, 0 );
242 #else
243                                 Debug( LDAP_DEBUG_ANY,
244             "%s: line %d: missing level in \"concurrency <level>\" line\n",
245                                     fname, lineno, 0 );
246 #endif
247
248                                 return( 1 );
249                         }
250
251                         c = atoi( cargv[1] );
252
253                         if( c < 1 ) {
254 #ifdef NEW_LOGGING
255                                 LDAP_LOG( CONFIG, CRIT, 
256                                         "%s: line %d: invalid level (%d) in "
257                                         "\"concurrency <level>\" line.\n", fname, lineno, c );
258 #else
259                                 Debug( LDAP_DEBUG_ANY,
260             "%s: line %d: invalid level (%d) in \"concurrency <level>\" line\n",
261                                     fname, lineno, c );
262 #endif
263
264                                 return( 1 );
265                         }
266
267                         ldap_pvt_thread_set_concurrency( c );
268
269                 /* set sockbuf max */
270                 } else if ( strcasecmp( cargv[0], "sockbuf_max_incoming" ) == 0 ) {
271                         long max;
272                         if ( cargc < 2 ) {
273 #ifdef NEW_LOGGING
274                                 LDAP_LOG( CONFIG, CRIT, 
275                                    "%s: line %d: missing max in \"sockbuf_max_incoming "
276                                    "<bytes>\" line\n", fname, lineno, 0 );
277 #else
278                                 Debug( LDAP_DEBUG_ANY,
279                                            "%s: line %d: missing max in \"sockbuf_max_incoming <bytes>\" line\n",
280                                     fname, lineno, 0 );
281 #endif
282
283                                 return( 1 );
284                         }
285
286                         max = atol( cargv[1] );
287
288                         if( max < 0 ) {
289 #ifdef NEW_LOGGING
290                                 LDAP_LOG( CONFIG, CRIT, 
291                                            "%s: line %d: invalid max value (%ld) in "
292                                            "\"sockbuf_max_incoming <bytes>\" line.\n",
293                                            fname, lineno, max );
294 #else
295                                 Debug( LDAP_DEBUG_ANY,
296                                         "%s: line %d: invalid max value (%ld) in "
297                                         "\"sockbuf_max_incoming <bytes>\" line.\n",
298                                     fname, lineno, max );
299 #endif
300
301                                 return( 1 );
302                         }
303
304                         sockbuf_max_incoming = max;
305
306                 /* set sockbuf max authenticated */
307                 } else if ( strcasecmp( cargv[0], "sockbuf_max_incoming_auth" ) == 0 ) {
308                         long max;
309                         if ( cargc < 2 ) {
310 #ifdef NEW_LOGGING
311                                 LDAP_LOG( CONFIG, CRIT, 
312                                    "%s: line %d: missing max in \"sockbuf_max_incoming_auth "
313                                    "<bytes>\" line\n", fname, lineno, 0 );
314 #else
315                                 Debug( LDAP_DEBUG_ANY,
316                                            "%s: line %d: missing max in \"sockbuf_max_incoming_auth <bytes>\" line\n",
317                                     fname, lineno, 0 );
318 #endif
319
320                                 return( 1 );
321                         }
322
323                         max = atol( cargv[1] );
324
325                         if( max < 0 ) {
326 #ifdef NEW_LOGGING
327                                 LDAP_LOG( CONFIG, CRIT, 
328                                            "%s: line %d: invalid max value (%ld) in "
329                                            "\"sockbuf_max_incoming_auth <bytes>\" line.\n",
330                                            fname, lineno, max );
331 #else
332                                 Debug( LDAP_DEBUG_ANY,
333                                         "%s: line %d: invalid max value (%ld) in "
334                                         "\"sockbuf_max_incoming_auth <bytes>\" line.\n",
335                                     fname, lineno, max );
336 #endif
337
338                                 return( 1 );
339                         }
340
341                         sockbuf_max_incoming_auth = max;
342
343                 /* set conn pending max */
344                 } else if ( strcasecmp( cargv[0], "conn_max_pending" ) == 0 ) {
345                         long max;
346                         if ( cargc < 2 ) {
347 #ifdef NEW_LOGGING
348                                 LDAP_LOG( CONFIG, CRIT, 
349                                    "%s: line %d: missing max in \"conn_max_pending "
350                                    "<requests>\" line\n", fname, lineno, 0 );
351 #else
352                                 Debug( LDAP_DEBUG_ANY,
353                                            "%s: line %d: missing max in \"conn_max_pending <requests>\" line\n",
354                                     fname, lineno, 0 );
355 #endif
356
357                                 return( 1 );
358                         }
359
360                         max = atol( cargv[1] );
361
362                         if( max < 0 ) {
363 #ifdef NEW_LOGGING
364                                 LDAP_LOG( CONFIG, CRIT, 
365                                            "%s: line %d: invalid max value (%ld) in "
366                                            "\"conn_max_pending <requests>\" line.\n",
367                                            fname, lineno, max );
368 #else
369                                 Debug( LDAP_DEBUG_ANY,
370                                         "%s: line %d: invalid max value (%ld) in "
371                                         "\"conn_max_pending <requests>\" line.\n",
372                                     fname, lineno, max );
373 #endif
374
375                                 return( 1 );
376                         }
377
378                         slap_conn_max_pending = max;
379
380                 /* set conn pending max authenticated */
381                 } else if ( strcasecmp( cargv[0], "conn_max_pending_auth" ) == 0 ) {
382                         long max;
383                         if ( cargc < 2 ) {
384 #ifdef NEW_LOGGING
385                                 LDAP_LOG( CONFIG, CRIT, 
386                                    "%s: line %d: missing max in \"conn_max_pending_auth "
387                                    "<requests>\" line\n", fname, lineno, 0 );
388 #else
389                                 Debug( LDAP_DEBUG_ANY,
390                                            "%s: line %d: missing max in \"conn_max_pending_auth <requests>\" line\n",
391                                     fname, lineno, 0 );
392 #endif
393
394                                 return( 1 );
395                         }
396
397                         max = atol( cargv[1] );
398
399                         if( max < 0 ) {
400 #ifdef NEW_LOGGING
401                                 LDAP_LOG( CONFIG, CRIT, 
402                                            "%s: line %d: invalid max value (%ld) in "
403                                            "\"conn_max_pending_auth <requests>\" line.\n",
404                                            fname, lineno, max );
405 #else
406                                 Debug( LDAP_DEBUG_ANY,
407                                         "%s: line %d: invalid max value (%ld) in "
408                                         "\"conn_max_pending_auth <requests>\" line.\n",
409                                     fname, lineno, max );
410 #endif
411
412                                 return( 1 );
413                         }
414
415                         slap_conn_max_pending_auth = max;
416
417                 /* default search base */
418                 } else if ( strcasecmp( cargv[0], "defaultSearchBase" ) == 0 ) {
419                         if ( cargc < 2 ) {
420 #ifdef NEW_LOGGING
421                                 LDAP_LOG( CONFIG, CRIT, 
422                                         "%s: line %d: missing dn in \"defaultSearchBase <dn\" "
423                                         "line\n", fname, lineno, 0 );
424 #else
425                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
426                                         "missing dn in \"defaultSearchBase <dn>\" line\n",
427                                         fname, lineno, 0 );
428 #endif
429
430                                 return 1;
431
432                         } else if ( cargc > 2 ) {
433 #ifdef NEW_LOGGING
434                                 LDAP_LOG( CONFIG, INFO, 
435                                         "%s: line %d: extra cruft after <dn> in "
436                                         "\"defaultSearchBase %s\" line (ignored)\n",
437                                         fname, lineno, cargv[1] );
438 #else
439                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
440                                         "extra cruft after <dn> in \"defaultSearchBase %s\", "
441                                         "line (ignored)\n",
442                                         fname, lineno, cargv[1] );
443 #endif
444                         }
445
446                         if ( bi != NULL || be != NULL ) {
447 #ifdef NEW_LOGGING
448                                 LDAP_LOG( CONFIG, CRIT, 
449                                         "%s: line %d: defaultSearchBase line must appear "
450                                         "prior to any backend or database definitions\n",
451                                         fname, lineno, 0 );
452 #else
453                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
454                                         "defaultSearchBaase line must appear prior to "
455                                         "any backend or database definition\n",
456                                     fname, lineno, 0 );
457 #endif
458
459                                 return 1;
460                         }
461
462                         if ( default_search_nbase.bv_len ) {
463 #ifdef NEW_LOGGING
464                                 LDAP_LOG( CONFIG, INFO, "%s: line %d: "
465                                         "default search base \"%s\" already defined "
466                                         "(discarding old)\n", fname, lineno,
467                                         default_search_base.bv_val );
468 #else
469                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
470                                         "default search base \"%s\" already defined "
471                                         "(discarding old)\n",
472                                         fname, lineno, default_search_base.bv_val );
473 #endif
474
475                                 free( default_search_base.bv_val );
476                                 free( default_search_nbase.bv_val );
477                         }
478
479                         if ( load_ucdata( NULL ) < 0 ) return 1;
480
481                         {
482                                 struct berval dn;
483
484                                 dn.bv_val = cargv[1];
485                                 dn.bv_len = strlen( dn.bv_val );
486
487                                 rc = dnPrettyNormal( NULL, &dn,
488                                         &default_search_base,
489                                         &default_search_nbase, NULL );
490
491                                 if( rc != LDAP_SUCCESS ) {
492 #ifdef NEW_LOGGING
493                                         LDAP_LOG( CONFIG, CRIT, 
494                                                 "%s: line %d: defaultSearchBase DN is invalid.\n",
495                                                 fname, lineno, 0 );
496 #else
497                                         Debug( LDAP_DEBUG_ANY,
498                                                 "%s: line %d: defaultSearchBase DN is invalid\n",
499                                            fname, lineno, 0 );
500 #endif
501                                         return( 1 );
502                                 }
503                         }
504
505                 /* set maximum threads in thread pool */
506                 } else if ( strcasecmp( cargv[0], "threads" ) == 0 ) {
507                         int c;
508                         if ( cargc < 2 ) {
509 #ifdef NEW_LOGGING
510                                 LDAP_LOG( CONFIG, CRIT, 
511                                         "%s: line %d: missing count in \"threads <count>\" line\n",
512                                         fname, lineno, 0 );
513 #else
514                                 Debug( LDAP_DEBUG_ANY,
515             "%s: line %d: missing count in \"threads <count>\" line\n",
516                                     fname, lineno, 0 );
517 #endif
518
519                                 return( 1 );
520                         }
521
522                         c = atoi( cargv[1] );
523
524                         if( c < 0 ) {
525 #ifdef NEW_LOGGING
526                                 LDAP_LOG( CONFIG, CRIT, 
527                                            "%s: line %d: invalid level (%d) in \"threads <count>\""
528                                            "line\n", fname, lineno, c );
529 #else
530                                 Debug( LDAP_DEBUG_ANY,
531             "%s: line %d: invalid level (%d) in \"threads <count>\" line\n",
532                                     fname, lineno, c );
533 #endif
534
535                                 return( 1 );
536                         }
537
538                         ldap_pvt_thread_pool_maxthreads( &connection_pool, c );
539
540                         /* save for later use */
541                         connection_pool_max = c;
542
543                 /* get pid file name */
544                 } else if ( strcasecmp( cargv[0], "pidfile" ) == 0 ) {
545                         if ( cargc < 2 ) {
546 #ifdef NEW_LOGGING
547                                 LDAP_LOG( CONFIG, CRIT, 
548                                         "%s: line %d missing file name in \"pidfile <file>\" "
549                                         "line.\n", fname, lineno, 0 );
550 #else
551                                 Debug( LDAP_DEBUG_ANY,
552             "%s: line %d: missing file name in \"pidfile <file>\" line\n",
553                                     fname, lineno, 0 );
554 #endif
555
556                                 return( 1 );
557                         }
558
559                         slapd_pid_file = ch_strdup( cargv[1] );
560
561                 /* get args file name */
562                 } else if ( strcasecmp( cargv[0], "argsfile" ) == 0 ) {
563                         if ( cargc < 2 ) {
564 #ifdef NEW_LOGGING
565                                 LDAP_LOG( CONFIG, CRIT, 
566                                            "%s: %d: missing file name in "
567                                            "\"argsfile <file>\" line.\n",
568                                            fname, lineno, 0 );
569 #else
570                                 Debug( LDAP_DEBUG_ANY,
571             "%s: line %d: missing file name in \"argsfile <file>\" line\n",
572                                     fname, lineno, 0 );
573 #endif
574
575                                 return( 1 );
576                         }
577
578                         slapd_args_file = ch_strdup( cargv[1] );
579
580                 } else if ( strcasecmp( cargv[0], "replica-pidfile" ) == 0 ) {
581                         /* ignore */ ;
582
583                 } else if ( strcasecmp( cargv[0], "replica-argsfile" ) == 0 ) {
584                         /* ignore */ ;
585
586                 /* default password hash */
587                 } else if ( strcasecmp( cargv[0], "password-hash" ) == 0 ) {
588                         if ( cargc < 2 ) {
589 #ifdef NEW_LOGGING
590                                 LDAP_LOG( CONFIG, CRIT, 
591                                            "%s: line %d: missing hash in "
592                                            "\"password-hash <hash>\" line.\n",
593                                            fname, lineno, 0 );
594 #else
595                                 Debug( LDAP_DEBUG_ANY,
596             "%s: line %d: missing hash in \"password-hash <hash>\" line\n",
597                                     fname, lineno, 0 );
598 #endif
599
600                                 return( 1 );
601                         }
602                         if ( default_passwd_hash != NULL ) {
603 #ifdef NEW_LOGGING
604                                 LDAP_LOG( CONFIG, CRIT, 
605                                            "%s: line %d: already set default password_hash!\n",
606                                            fname, lineno, 0 );
607 #else
608                                 Debug( LDAP_DEBUG_ANY,
609                                         "%s: line %d: already set default password_hash!\n",
610                                         fname, lineno, 0 );
611 #endif
612
613                                 return 1;
614
615                         }
616
617                         if ( lutil_passwd_scheme( cargv[1] ) == 0 ) {
618 #ifdef NEW_LOGGING
619                                 LDAP_LOG( CONFIG, CRIT, 
620                                            "%s: line %d: password scheme \"%s\" not available\n",
621                                            fname, lineno, cargv[1] );
622 #else
623                                 Debug( LDAP_DEBUG_ANY,
624                                         "%s: line %d: password scheme \"%s\" not available\n",
625                                         fname, lineno, cargv[1] );
626 #endif
627                                 return 1;
628                         }
629
630                         default_passwd_hash = ch_strdup( cargv[1] );
631
632                 } else if ( strcasecmp( cargv[0], "password-crypt-salt-format" ) == 0 ) 
633                 {
634                         if ( cargc < 2 ) {
635 #ifdef NEW_LOGGING
636                                 LDAP_LOG( CONFIG, CRIT, 
637                                         "%s: line %d: missing format in "
638                                         "\"password-crypt-salt-format <format>\" line\n",
639                                         fname, lineno, 0 );
640 #else
641                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: missing format in "
642                                         "\"password-crypt-salt-format <format>\" line\n",
643                                     fname, lineno, 0 );
644 #endif
645
646                                 return 1;
647                         }
648
649                         lutil_salt_format( cargv[1] );
650
651                 /* SASL config options */
652                 } else if ( strncasecmp( cargv[0], "sasl", 4 ) == 0 ) {
653                         if ( slap_sasl_config( cargc, cargv, line, fname, lineno ) )
654                                 return 1;
655
656                 } else if ( strcasecmp( cargv[0], "schemadn" ) == 0 ) {
657                         struct berval dn;
658                         if ( cargc < 2 ) {
659 #ifdef NEW_LOGGING
660                                 LDAP_LOG( CONFIG, CRIT, 
661                                            "%s: line %d: missing dn in "
662                                            "\"schemadn <dn>\" line.\n", fname, lineno, 0  );
663 #else
664                                 Debug( LDAP_DEBUG_ANY,
665             "%s: line %d: missing dn in \"schemadn <dn>\" line\n",
666                                     fname, lineno, 0 );
667 #endif
668                                 return 1 ;
669                         }
670                         ber_str2bv( cargv[1], 0, 0, &dn );
671                         if ( be ) {
672                                 rc = dnPrettyNormal( NULL, &dn, &be->be_schemadn,
673                                         &be->be_schemandn, NULL );
674                         } else {
675                                 rc = dnPrettyNormal( NULL, &dn, &global_schemadn,
676                                         &global_schemandn, NULL );
677                         }
678                         if ( rc != LDAP_SUCCESS ) {
679 #ifdef NEW_LOGGING
680                                 LDAP_LOG( CONFIG, CRIT, 
681                                         "%s: line %d: schemadn DN is invalid.\n",
682                                         fname, lineno , 0 );
683 #else
684                                 Debug( LDAP_DEBUG_ANY,
685                                         "%s: line %d: schemadn DN is invalid\n",
686                                         fname, lineno, 0 );
687 #endif
688                                 return 1;
689                         }
690
691                 /* set UCDATA path */
692                 } else if ( strcasecmp( cargv[0], "ucdata-path" ) == 0 ) {
693                         int err;
694                         if ( cargc < 2 ) {
695 #ifdef NEW_LOGGING
696                                 LDAP_LOG( CONFIG, CRIT, 
697                                            "%s: line %d: missing path in "
698                                            "\"ucdata-path <path>\" line.\n", fname, lineno, 0  );
699 #else
700                                 Debug( LDAP_DEBUG_ANY,
701             "%s: line %d: missing path in \"ucdata-path <path>\" line\n",
702                                     fname, lineno, 0 );
703 #endif
704
705                                 return( 1 );
706                         }
707
708                         err = load_ucdata( cargv[1] );
709                         if ( err <= 0 ) {
710                                 if ( err == 0 ) {
711 #ifdef NEW_LOGGING
712                                         LDAP_LOG( CONFIG, CRIT, 
713                                                    "%s: line %d: ucdata already loaded, ucdata-path "
714                                                    "must be set earlier in the file and/or be "
715                                                    "specified only once!\n", fname, lineno, 0 );
716 #else
717                                         Debug( LDAP_DEBUG_ANY,
718                                                "%s: line %d: ucdata already loaded, ucdata-path must be set earlier in the file and/or be specified only once!\n",
719                                                fname, lineno, 0 );
720 #endif
721
722                                 }
723                                 return( 1 );
724                         }
725
726                 /* set size limit */
727                 } else if ( strcasecmp( cargv[0], "sizelimit" ) == 0 ) {
728                         int rc = 0, i;
729                         struct slap_limits_set *lim;
730                         
731                         if ( cargc < 2 ) {
732 #ifdef NEW_LOGGING
733                                 LDAP_LOG( CONFIG, CRIT, 
734                                    "%s: line %d: missing limit in \"sizelimit <limit>\" "
735                                    "line.\n", fname, lineno, 0 );
736 #else
737                                 Debug( LDAP_DEBUG_ANY,
738             "%s: line %d: missing limit in \"sizelimit <limit>\" line\n",
739                                     fname, lineno, 0 );
740 #endif
741
742                                 return( 1 );
743                         }
744
745                         if ( be == NULL ) {
746                                 lim = &deflimit;
747                         } else {
748                                 lim = &be->be_def_limit;
749                         }
750
751                         for ( i = 1; i < cargc; i++ ) {
752                                 if ( strncasecmp( cargv[i], "size", 4 ) == 0 ) {
753                                         rc = parse_limit( cargv[i], lim );
754                                         if ( rc ) {
755 #ifdef NEW_LOGGING
756                                                 LDAP_LOG( CONFIG, CRIT, 
757                                                         "%s: line %d: unable "
758                                                            "to parse value \"%s\" in \"sizelimit "
759                                                            "<limit>\" line.\n", fname, lineno, cargv[i] );
760 #else
761                                                 Debug( LDAP_DEBUG_ANY,
762                                                         "%s: line %d: unable "
763                                                         "to parse value \"%s\" "
764                                                         "in \"sizelimit "
765                                                         "<limit>\" line\n",
766                                                         fname, lineno, cargv[i] );
767 #endif
768                                                 return( 1 );
769                                         }
770
771                                 } else {
772                                         if ( strcasecmp( cargv[i], "unlimited" ) == 0 ) {
773                                                 lim->lms_s_soft = -1;
774                                         } else {
775                                                 char *next;
776
777                                                 lim->lms_s_soft = strtol( cargv[i] , &next, 0 );
778                                                 if ( next == cargv[i] ) {
779 #ifdef NEW_LOGGING
780                                                         LDAP_LOG( CONFIG, CRIT, 
781                                                            "%s: line %d: unable to parse limit \"%s\" in \"sizelimit <limit>\" "
782                                                            "line.\n", fname, lineno, cargv[i] );
783 #else
784                                                         Debug( LDAP_DEBUG_ANY,
785                                                             "%s: line %d: unable to parse limit \"%s\" in \"sizelimit <limit>\" line\n",
786                                                             fname, lineno, cargv[i] );
787 #endif
788                                                         return( 1 );
789
790                                                 } else if ( next[0] != '\0' ) {
791 #ifdef NEW_LOGGING
792                                                         LDAP_LOG( CONFIG, CRIT, 
793                                                            "%s: line %d: trailing chars \"%s\" in \"sizelimit <limit>\" "
794                                                            "line ignored.\n", fname, lineno, next );
795 #else
796                                                         Debug( LDAP_DEBUG_ANY,
797                                                             "%s: line %d: trailing chars \"%s\" in \"sizelimit <limit>\" line ignored\n",
798                                                             fname, lineno, next );
799 #endif
800                                                 }
801                                         }
802                                         lim->lms_s_hard = 0;
803                                 }
804                         }
805
806                 /* set time limit */
807                 } else if ( strcasecmp( cargv[0], "timelimit" ) == 0 ) {
808                         int rc = 0, i;
809                         struct slap_limits_set *lim;
810                         
811                         if ( cargc < 2 ) {
812 #ifdef NEW_LOGGING
813                                 LDAP_LOG( CONFIG, CRIT, 
814                                         "%s: line %d missing limit in \"timelimit <limit>\" "
815                                         "line.\n", fname, lineno, 0 );
816 #else
817                                 Debug( LDAP_DEBUG_ANY,
818             "%s: line %d: missing limit in \"timelimit <limit>\" line\n",
819                                     fname, lineno, 0 );
820 #endif
821
822                                 return( 1 );
823                         }
824                         
825                         if ( be == NULL ) {
826                                 lim = &deflimit;
827                         } else {
828                                 lim = &be->be_def_limit;
829                         }
830
831                         for ( i = 1; i < cargc; i++ ) {
832                                 if ( strncasecmp( cargv[i], "time", 4 ) == 0 ) {
833                                         rc = parse_limit( cargv[i], lim );
834                                         if ( rc ) {
835 #ifdef NEW_LOGGING
836                                                 LDAP_LOG( CONFIG, CRIT, 
837                                                             "%s: line %d: unable to parse value \"%s\" "
838                                                            "in \"timelimit <limit>\" line.\n",
839                                                            fname, lineno, cargv[i] );
840 #else
841                                                 Debug( LDAP_DEBUG_ANY,
842                                                         "%s: line %d: unable "
843                                                         "to parse value \"%s\" "
844                                                         "in \"timelimit "
845                                                         "<limit>\" line\n",
846                                                         fname, lineno, cargv[i] );
847 #endif
848                                                 return( 1 );
849                                         }
850
851                                 } else {
852                                         if ( strcasecmp( cargv[i], "unlimited" ) == 0 ) {
853                                                 lim->lms_t_soft = -1;
854                                         } else {
855                                                 char *next;
856
857                                                 lim->lms_t_soft = strtol( cargv[i] , &next, 0 );
858                                                 if ( next == cargv[i] ) {
859 #ifdef NEW_LOGGING
860                                                         LDAP_LOG( CONFIG, CRIT, 
861                                                            "%s: line %d: unable to parse limit \"%s\" in \"timelimit <limit>\" "
862                                                            "line.\n", fname, lineno, cargv[i] );
863 #else
864                                                         Debug( LDAP_DEBUG_ANY,
865                                                             "%s: line %d: unable to parse limit \"%s\" in \"timelimit <limit>\" line\n",
866                                                             fname, lineno, cargv[i] );
867 #endif
868                                                         return( 1 );
869
870                                                 } else if ( next[0] != '\0' ) {
871 #ifdef NEW_LOGGING
872                                                         LDAP_LOG( CONFIG, CRIT, 
873                                                            "%s: line %d: trailing chars \"%s\" in \"timelimit <limit>\" "
874                                                            "line ignored.\n", fname, lineno, next );
875 #else
876                                                         Debug( LDAP_DEBUG_ANY,
877                                                             "%s: line %d: trailing chars \"%s\" in \"timelimit <limit>\" line ignored\n",
878                                                             fname, lineno, next );
879 #endif
880                                                 }
881                                         }
882                                         lim->lms_t_hard = 0;
883                                 }
884                         }
885
886                 /* set regex-based limits */
887                 } else if ( strcasecmp( cargv[0], "limits" ) == 0 ) {
888                         if ( be == NULL ) {
889 #ifdef NEW_LOGGING
890                                 LDAP_LOG( CONFIG, WARNING, 
891                                            "%s: line %d \"limits\" allowed only in database "
892                                            "environment.\n", fname, lineno, 0 );
893 #else
894                                 Debug( LDAP_DEBUG_ANY,
895         "%s: line %d \"limits\" allowed only in database environment.\n%s",
896                                         fname, lineno, "" );
897 #endif
898                                 return( 1 );
899                         }
900
901                         if ( parse_limits( be, fname, lineno, cargc, cargv ) ) {
902                                 return( 1 );
903                         }
904
905                 /* mark this as a subordinate database */
906                 } else if ( strcasecmp( cargv[0], "subordinate" ) == 0 ) {
907                         if ( be == NULL ) {
908 #ifdef NEW_LOGGING
909                                 LDAP_LOG( CONFIG, INFO, "%s: line %d: "
910                                         "subordinate keyword must appear inside a database "
911                                         "definition.\n", fname, lineno, 0 );
912 #else
913                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: subordinate keyword "
914                                         "must appear inside a database definition.\n",
915                                     fname, lineno, 0 );
916 #endif
917                                 return 1;
918
919                         } else {
920                                 be->be_flags |= SLAP_BFLAG_GLUE_SUBORDINATE;
921                                 num_subordinates++;
922                         }
923
924                 /* add an overlay to this backend */
925                 } else if ( strcasecmp( cargv[0], "overlay" ) == 0 ) {
926                         if ( be == NULL ) {
927 #ifdef NEW_LOGGING
928                                 LDAP_LOG( CONFIG, INFO, "%s: line %d: "
929                                         "overlay keyword must appear inside a database "
930                                         "definition.\n", fname, lineno, 0 );
931 #else
932                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: overlay keyword "
933                                         "must appear inside a database definition.\n",
934                                     fname, lineno, 0 );
935 #endif
936                                 return 1;
937
938                         } else {
939                                 return overlay_config( be, cargv[1] );
940                         }
941
942                 /* set database suffix */
943                 } else if ( strcasecmp( cargv[0], "suffix" ) == 0 ) {
944                         Backend *tmp_be;
945                         struct berval dn, pdn, ndn;
946
947                         if ( cargc < 2 ) {
948 #ifdef NEW_LOGGING
949                                 LDAP_LOG( CONFIG, CRIT, 
950                                         "%s: line %d: missing dn in \"suffix <dn>\" line.\n",
951                                         fname, lineno, 0 );
952 #else
953                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
954                                         "missing dn in \"suffix <dn>\" line\n",
955                                     fname, lineno, 0 );
956 #endif
957
958                                 return( 1 );
959
960                         } else if ( cargc > 2 ) {
961 #ifdef NEW_LOGGING
962                                 LDAP_LOG( CONFIG, INFO, 
963                                         "%s: line %d: extra cruft after <dn> in \"suffix %s\""
964                                         " line (ignored).\n", fname, lineno, cargv[1] );
965 #else
966                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: extra cruft "
967                                         "after <dn> in \"suffix %s\" line (ignored)\n",
968                                     fname, lineno, cargv[1] );
969 #endif
970                         }
971
972                         if ( be == NULL ) {
973 #ifdef NEW_LOGGING
974                                 LDAP_LOG( CONFIG, INFO, 
975                                         "%s: line %d: suffix line must appear inside a database "
976                                         "definition.\n", fname, lineno, 0 );
977 #else
978                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: suffix line "
979                                         "must appear inside a database definition\n",
980                                     fname, lineno, 0 );
981 #endif
982                                 return( 1 );
983
984 #if defined(SLAPD_MONITOR_DN)
985                         /* "cn=Monitor" is reserved for monitoring slap */
986                         } else if ( strcasecmp( cargv[1], SLAPD_MONITOR_DN ) == 0 ) {
987 #ifdef NEW_LOGGING
988                                 LDAP_LOG( CONFIG, CRIT, "%s: line %d: \""
989                                         "%s\" is reserved for monitoring slapd\n", 
990                                         fname, lineno, SLAPD_MONITOR_DN );
991 #else
992                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: \""
993                                         "%s\" is reserved for monitoring slapd\n", 
994                                         fname, lineno, SLAPD_MONITOR_DN );
995 #endif
996                                 return( 1 );
997 #endif /* SLAPD_MONITOR_DN */
998                         }
999
1000                         if ( load_ucdata( NULL ) < 0 ) return 1;
1001
1002                         dn.bv_val = cargv[1];
1003                         dn.bv_len = strlen( cargv[1] );
1004
1005                         rc = dnPrettyNormal( NULL, &dn, &pdn, &ndn, NULL );
1006                         if( rc != LDAP_SUCCESS ) {
1007 #ifdef NEW_LOGGING
1008                                 LDAP_LOG( CONFIG, CRIT, 
1009                                         "%s: line %d: suffix DN is invalid.\n",
1010                                         fname, lineno, 0 );
1011 #else
1012                                 Debug( LDAP_DEBUG_ANY,
1013                                         "%s: line %d: suffix DN is invalid\n",
1014                                    fname, lineno, 0 );
1015 #endif
1016                                 return( 1 );
1017                         }
1018
1019                         tmp_be = select_backend( &ndn, 0, 0 );
1020                         if ( tmp_be == be ) {
1021 #ifdef NEW_LOGGING
1022                                 LDAP_LOG( CONFIG, INFO, 
1023                                         "%s: line %d: suffix already served by this backend "
1024                                         "(ignored)\n", fname, lineno, 0 );
1025 #else
1026                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: suffix "
1027                                         "already served by this backend (ignored)\n",
1028                                     fname, lineno, 0 );
1029 #endif
1030                                 free( pdn.bv_val );
1031                                 free( ndn.bv_val );
1032
1033                         } else if ( tmp_be  != NULL ) {
1034 #ifdef NEW_LOGGING
1035                                 LDAP_LOG( CONFIG, INFO, 
1036                                         "%s: line %d: suffix already served by a preceding "
1037                                         "backend \"%s\"\n", fname, lineno,
1038                                         tmp_be->be_suffix[0].bv_val );
1039 #else
1040                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: suffix "
1041                                         "already served by a preceeding backend \"%s\"\n",
1042                                     fname, lineno, tmp_be->be_suffix[0].bv_val );
1043 #endif
1044                                 free( pdn.bv_val );
1045                                 free( ndn.bv_val );
1046                                 return( 1 );
1047
1048                         } else if( pdn.bv_len == 0 && default_search_nbase.bv_len ) {
1049 #ifdef NEW_LOGGING
1050                                         LDAP_LOG( CONFIG, INFO, 
1051                                                 "%s: line %d: suffix DN empty and default search "
1052                                                 "base provided \"%s\" (assuming okay).\n",
1053                                                 fname, lineno, default_search_base.bv_val );
1054 #else
1055                                         Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1056                                                 "suffix DN empty and default "
1057                                                 "search base provided \"%s\" (assuming okay)\n",
1058                                         fname, lineno, default_search_base.bv_val );
1059 #endif
1060                         }
1061
1062                         ber_bvarray_add( &be->be_suffix, &pdn );
1063                         ber_bvarray_add( &be->be_nsuffix, &ndn );
1064
1065                /* set max deref depth */
1066                } else if ( strcasecmp( cargv[0], "maxDerefDepth" ) == 0 ) {
1067                                         int i;
1068                        if ( cargc < 2 ) {
1069 #ifdef NEW_LOGGING
1070                                LDAP_LOG( CONFIG, CRIT, 
1071                                           "%s: line %d: missing depth in \"maxDerefDepth <depth>\""
1072                                           " line\n", fname, lineno, 0 );
1073 #else
1074                                Debug( LDAP_DEBUG_ANY,
1075                    "%s: line %d: missing depth in \"maxDerefDepth <depth>\" line\n",
1076                                    fname, lineno, 0 );
1077 #endif
1078
1079                                return( 1 );
1080                        }
1081                        if ( be == NULL ) {
1082 #ifdef NEW_LOGGING
1083                                LDAP_LOG( CONFIG, INFO, 
1084                                           "%s: line %d: depth line must appear inside a database "
1085                                           "definition.\n", fname, lineno ,0 );
1086 #else
1087                                Debug( LDAP_DEBUG_ANY,
1088 "%s: line %d: depth line must appear inside a database definition.\n",
1089                                    fname, lineno, 0 );
1090 #endif
1091                                                         return 1;
1092
1093                        } else if ((i = atoi(cargv[1])) < 0) {
1094 #ifdef NEW_LOGGING
1095                                LDAP_LOG( CONFIG, INFO, 
1096                                           "%s: line %d: depth must be positive.\n",
1097                                           fname, lineno ,0 );
1098 #else
1099                                Debug( LDAP_DEBUG_ANY,
1100 "%s: line %d: depth must be positive.\n",
1101                                    fname, lineno, 0 );
1102 #endif
1103                                                         return 1;
1104
1105
1106                        } else {
1107                            be->be_max_deref_depth = i;
1108                                            }
1109
1110
1111                 /* set magic "root" dn for this database */
1112                 } else if ( strcasecmp( cargv[0], "rootdn" ) == 0 ) {
1113                         if ( cargc < 2 ) {
1114 #ifdef NEW_LOGGING
1115                                 LDAP_LOG( CONFIG, INFO, 
1116                                            "%s: line %d: missing dn in \"rootdn <dn>\" line.\n",
1117                                            fname, lineno ,0 );
1118 #else
1119                                 Debug( LDAP_DEBUG_ANY,
1120                     "%s: line %d: missing dn in \"rootdn <dn>\" line\n",
1121                                     fname, lineno, 0 );
1122 #endif
1123
1124                                 return( 1 );
1125                         }
1126
1127                         if ( be == NULL ) {
1128 #ifdef NEW_LOGGING
1129                                 LDAP_LOG( CONFIG, INFO, 
1130                                            "%s: line %d: rootdn line must appear inside a database "
1131                                            "definition.\n", fname, lineno ,0 );
1132 #else
1133                                 Debug( LDAP_DEBUG_ANY,
1134 "%s: line %d: rootdn line must appear inside a database definition.\n",
1135                                     fname, lineno, 0 );
1136 #endif
1137                                 return 1;
1138
1139                         } else {
1140                                 struct berval dn;
1141                                 
1142                                 if ( load_ucdata( NULL ) < 0 ) return 1;
1143
1144                                 dn.bv_val = cargv[1];
1145                                 dn.bv_len = strlen( cargv[1] );
1146
1147                                 rc = dnPrettyNormal( NULL, &dn,
1148                                         &be->be_rootdn,
1149                                         &be->be_rootndn, NULL );
1150
1151                                 if( rc != LDAP_SUCCESS ) {
1152 #ifdef NEW_LOGGING
1153                                         LDAP_LOG( CONFIG, CRIT, 
1154                                                 "%s: line %d: rootdn DN is invalid.\n", 
1155                                                 fname, lineno ,0 );
1156 #else
1157                                         Debug( LDAP_DEBUG_ANY,
1158                                                 "%s: line %d: rootdn DN is invalid\n",
1159                                            fname, lineno, 0 );
1160 #endif
1161                                         return( 1 );
1162                                 }
1163                         }
1164
1165                 /* set super-secret magic database password */
1166                 } else if ( strcasecmp( cargv[0], "rootpw" ) == 0 ) {
1167                         if ( cargc < 2 ) {
1168 #ifdef NEW_LOGGING
1169                                 LDAP_LOG( CONFIG, CRIT, 
1170                                         "%s: line %d: missing passwd in \"rootpw <passwd>\""
1171                                         " line\n", fname, lineno ,0 );
1172 #else
1173                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1174                                         "missing passwd in \"rootpw <passwd>\" line\n",
1175                                     fname, lineno, 0 );
1176 #endif
1177
1178                                 return( 1 );
1179                         }
1180
1181                         if ( be == NULL ) {
1182 #ifdef NEW_LOGGING
1183                                 LDAP_LOG( CONFIG, INFO, "%s: line %d: "
1184                                         "rootpw line must appear inside a database "
1185                                         "definition.\n", fname, lineno ,0 );
1186 #else
1187                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1188                                         "rootpw line must appear inside a database "
1189                                         "definition.\n",
1190                                     fname, lineno, 0 );
1191 #endif
1192                                 return 1;
1193
1194                         } else {
1195                                 Backend *tmp_be = select_backend( &be->be_rootndn, 0, 0 );
1196
1197                                 if( tmp_be != be ) {
1198 #ifdef NEW_LOGGING
1199                                         LDAP_LOG( CONFIG, INFO,
1200                                                 "%s: line %d: "
1201                                                 "rootpw can only be set when rootdn is under suffix\n",
1202                                                 fname, lineno, "" );
1203 #else
1204                                         Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1205                                                 "rootpw can only be set when rootdn is under suffix\n",
1206                                         fname, lineno, 0 );
1207 #endif
1208                                         return 1;
1209                                 }
1210
1211                                 be->be_rootpw.bv_val = ch_strdup( cargv[1] );
1212                                 be->be_rootpw.bv_len = strlen( be->be_rootpw.bv_val );
1213                         }
1214
1215                 /* make this database read-only */
1216                 } else if ( strcasecmp( cargv[0], "readonly" ) == 0 ) {
1217                         if ( cargc < 2 ) {
1218 #ifdef NEW_LOGGING
1219                                 LDAP_LOG( CONFIG, CRIT, 
1220                                         "%s: line %d: missing on|off in \"readonly <on|off>\" "
1221                                         "line.\n", fname, lineno ,0 );
1222 #else
1223                                 Debug( LDAP_DEBUG_ANY,
1224             "%s: line %d: missing on|off in \"readonly <on|off>\" line\n",
1225                                     fname, lineno, 0 );
1226 #endif
1227
1228                                 return( 1 );
1229                         }
1230                         if ( be == NULL ) {
1231                                 if ( strcasecmp( cargv[1], "on" ) == 0 ) {
1232                                         global_restrictops |= SLAP_RESTRICT_OP_WRITES;
1233                                 } else {
1234                                         global_restrictops &= ~SLAP_RESTRICT_OP_WRITES;
1235                                 }
1236                         } else {
1237                                 if ( strcasecmp( cargv[1], "on" ) == 0 ) {
1238                                         be->be_restrictops |= SLAP_RESTRICT_OP_WRITES;
1239                                 } else {
1240                                         be->be_restrictops &= ~SLAP_RESTRICT_OP_WRITES;
1241                                 }
1242                         }
1243
1244
1245                 /* allow these features */
1246                 } else if ( strcasecmp( cargv[0], "allows" ) == 0 ||
1247                         strcasecmp( cargv[0], "allow" ) == 0 )
1248                 {
1249                         slap_mask_t     allows;
1250
1251                         if ( be != NULL ) {
1252 #ifdef NEW_LOGGING
1253                                 LDAP_LOG( CONFIG, INFO, 
1254                                            "%s: line %d: allow line must appear prior to "
1255                                            "database definitions.\n", fname, lineno ,0 );
1256 #else
1257                                 Debug( LDAP_DEBUG_ANY,
1258 "%s: line %d: allow line must appear prior to database definitions\n",
1259                                     fname, lineno, 0 );
1260 #endif
1261
1262                         }
1263
1264                         if ( cargc < 2 ) {
1265 #ifdef NEW_LOGGING
1266                                 LDAP_LOG( CONFIG, CRIT, 
1267                                            "%s: line %d: missing feature(s) in \"allow <features>\""
1268                                            " line\n", fname, lineno ,0 );
1269 #else
1270                                 Debug( LDAP_DEBUG_ANY,
1271             "%s: line %d: missing feature(s) in \"allow <features>\" line\n",
1272                                     fname, lineno, 0 );
1273 #endif
1274
1275                                 return( 1 );
1276                         }
1277
1278                         allows = 0;
1279
1280                         for( i=1; i < cargc; i++ ) {
1281                                 if( strcasecmp( cargv[i], "bind_v2" ) == 0 ) {
1282                                         allows |= SLAP_ALLOW_BIND_V2;
1283
1284                                 } else if( strcasecmp( cargv[i], "bind_anon_cred" ) == 0 ) {
1285                                         allows |= SLAP_ALLOW_BIND_ANON_CRED;
1286
1287                                 } else if( strcasecmp( cargv[i], "bind_anon_dn" ) == 0 ) {
1288                                         allows |= SLAP_ALLOW_BIND_ANON_DN;
1289
1290                                 } else if( strcasecmp( cargv[i], "update_anon" ) == 0 ) {
1291                                         allows |= SLAP_ALLOW_UPDATE_ANON;
1292
1293                                 } else if( strcasecmp( cargv[i], "none" ) != 0 ) {
1294 #ifdef NEW_LOGGING
1295                                         LDAP_LOG( CONFIG, CRIT, "%s: line %d: "
1296                                                 "unknown feature %s in \"allow <features>\" line.\n",
1297                                                 fname, lineno, cargv[1] );
1298 #else
1299                                         Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1300                                                 "unknown feature %s in \"allow <features>\" line\n",
1301                                                 fname, lineno, cargv[i] );
1302 #endif
1303
1304                                         return( 1 );
1305                                 }
1306                         }
1307
1308                         global_allows = allows;
1309
1310                 /* disallow these features */
1311                 } else if ( strcasecmp( cargv[0], "disallows" ) == 0 ||
1312                         strcasecmp( cargv[0], "disallow" ) == 0 )
1313                 {
1314                         slap_mask_t     disallows;
1315
1316                         if ( be != NULL ) {
1317 #ifdef NEW_LOGGING
1318                                 LDAP_LOG( CONFIG, INFO, 
1319                                            "%s: line %d: disallow line must appear prior to "
1320                                            "database definitions.\n", fname, lineno ,0 );
1321 #else
1322                                 Debug( LDAP_DEBUG_ANY,
1323 "%s: line %d: disallow line must appear prior to database definitions\n",
1324                                     fname, lineno, 0 );
1325 #endif
1326
1327                         }
1328
1329                         if ( cargc < 2 ) {
1330 #ifdef NEW_LOGGING
1331                                 LDAP_LOG( CONFIG, CRIT, 
1332                                         "%s: line %d: missing feature(s) in \"disallow <features>\""
1333                                         " line.\n", fname, lineno ,0 );
1334 #else
1335                                 Debug( LDAP_DEBUG_ANY,
1336             "%s: line %d: missing feature(s) in \"disallow <features>\" line\n",
1337                                     fname, lineno, 0 );
1338 #endif
1339
1340                                 return( 1 );
1341                         }
1342
1343                         disallows = 0;
1344
1345                         for( i=1; i < cargc; i++ ) {
1346                                 if( strcasecmp( cargv[i], "bind_anon" ) == 0 ) {
1347                                         disallows |= SLAP_DISALLOW_BIND_ANON;
1348
1349                                 } else if( strcasecmp( cargv[i], "bind_simple" ) == 0 ) {
1350                                         disallows |= SLAP_DISALLOW_BIND_SIMPLE;
1351
1352                                 } else if( strcasecmp( cargv[i], "bind_krbv4" ) == 0 ) {
1353                                         disallows |= SLAP_DISALLOW_BIND_KRBV4;
1354
1355                                 } else if( strcasecmp( cargv[i], "tls_2_anon" ) == 0 ) {
1356                                         disallows |= SLAP_DISALLOW_TLS_2_ANON;
1357
1358                                 } else if( strcasecmp( cargv[i], "tls_authc" ) == 0 ) {
1359                                         disallows |= SLAP_DISALLOW_TLS_AUTHC;
1360
1361                                 } else if( strcasecmp( cargv[i], "none" ) != 0 ) {
1362 #ifdef NEW_LOGGING
1363                                         LDAP_LOG( CONFIG, CRIT, 
1364                                                 "%s: line %d: unknown feature %s in "
1365                                                 "\"disallow <features>\" line.\n",
1366                                                 fname, lineno, cargv[i] );
1367 #else
1368                                         Debug( LDAP_DEBUG_ANY,
1369                     "%s: line %d: unknown feature %s in \"disallow <features>\" line\n",
1370                                             fname, lineno, cargv[i] );
1371 #endif
1372
1373                                         return( 1 );
1374                                 }
1375                         }
1376
1377                         global_disallows = disallows;
1378
1379                 /* require these features */
1380                 } else if ( strcasecmp( cargv[0], "requires" ) == 0 ||
1381                         strcasecmp( cargv[0], "require" ) == 0 )
1382                 {
1383                         slap_mask_t     requires;
1384
1385                         if ( cargc < 2 ) {
1386 #ifdef NEW_LOGGING
1387                                 LDAP_LOG( CONFIG, CRIT, 
1388                                            "%s: line %d: missing feature(s) in "
1389                                            "\"require <features>\" line.\n", fname, lineno ,0 );
1390 #else
1391                                 Debug( LDAP_DEBUG_ANY,
1392             "%s: line %d: missing feature(s) in \"require <features>\" line\n",
1393                                     fname, lineno, 0 );
1394 #endif
1395
1396                                 return( 1 );
1397                         }
1398
1399                         requires = 0;
1400
1401                         for( i=1; i < cargc; i++ ) {
1402                                 if( strcasecmp( cargv[i], "bind" ) == 0 ) {
1403                                         requires |= SLAP_REQUIRE_BIND;
1404
1405                                 } else if( strcasecmp( cargv[i], "LDAPv3" ) == 0 ) {
1406                                         requires |= SLAP_REQUIRE_LDAP_V3;
1407
1408                                 } else if( strcasecmp( cargv[i], "authc" ) == 0 ) {
1409                                         requires |= SLAP_REQUIRE_AUTHC;
1410
1411                                 } else if( strcasecmp( cargv[i], "SASL" ) == 0 ) {
1412                                         requires |= SLAP_REQUIRE_SASL;
1413
1414                                 } else if( strcasecmp( cargv[i], "strong" ) == 0 ) {
1415                                         requires |= SLAP_REQUIRE_STRONG;
1416
1417                                 } else if( strcasecmp( cargv[i], "none" ) != 0 ) {
1418 #ifdef NEW_LOGGING
1419                                         LDAP_LOG( CONFIG, CRIT, 
1420                                                    "%s: line %d: unknown feature %s in "
1421                                                    "\"require <features>\" line.\n", 
1422                                                    fname, lineno , cargv[i] );
1423 #else
1424                                         Debug( LDAP_DEBUG_ANY,
1425                     "%s: line %d: unknown feature %s in \"require <features>\" line\n",
1426                                             fname, lineno, cargv[i] );
1427 #endif
1428
1429                                         return( 1 );
1430                                 }
1431                         }
1432
1433                         if ( be == NULL ) {
1434                                 global_requires = requires;
1435                         } else {
1436                                 be->be_requires = requires;
1437                         }
1438
1439                 /* required security factors */
1440                 } else if ( strcasecmp( cargv[0], "security" ) == 0 ) {
1441                         slap_ssf_set_t *set;
1442
1443                         if ( cargc < 2 ) {
1444 #ifdef NEW_LOGGING
1445                                 LDAP_LOG( CONFIG, CRIT, 
1446                                         "%s: line %d: missing factor(s) in \"security <factors>\""
1447                                         " line.\n", fname, lineno ,0 );
1448 #else
1449                                 Debug( LDAP_DEBUG_ANY,
1450             "%s: line %d: missing factor(s) in \"security <factors>\" line\n",
1451                                     fname, lineno, 0 );
1452 #endif
1453
1454                                 return( 1 );
1455                         }
1456
1457                         if ( be == NULL ) {
1458                                 set = &global_ssf_set;
1459                         } else {
1460                                 set = &be->be_ssf_set;
1461                         }
1462
1463                         for( i=1; i < cargc; i++ ) {
1464                                 if( strncasecmp( cargv[i], "ssf=",
1465                                         sizeof("ssf") ) == 0 )
1466                                 {
1467                                         set->sss_ssf =
1468                                                 atoi( &cargv[i][sizeof("ssf")] );
1469
1470                                 } else if( strncasecmp( cargv[i], "transport=",
1471                                         sizeof("transport") ) == 0 )
1472                                 {
1473                                         set->sss_transport =
1474                                                 atoi( &cargv[i][sizeof("transport")] );
1475
1476                                 } else if( strncasecmp( cargv[i], "tls=",
1477                                         sizeof("tls") ) == 0 )
1478                                 {
1479                                         set->sss_tls =
1480                                                 atoi( &cargv[i][sizeof("tls")] );
1481
1482                                 } else if( strncasecmp( cargv[i], "sasl=",
1483                                         sizeof("sasl") ) == 0 )
1484                                 {
1485                                         set->sss_sasl =
1486                                                 atoi( &cargv[i][sizeof("sasl")] );
1487
1488                                 } else if( strncasecmp( cargv[i], "update_ssf=",
1489                                         sizeof("update_ssf") ) == 0 )
1490                                 {
1491                                         set->sss_update_ssf =
1492                                                 atoi( &cargv[i][sizeof("update_ssf")] );
1493
1494                                 } else if( strncasecmp( cargv[i], "update_transport=",
1495                                         sizeof("update_transport") ) == 0 )
1496                                 {
1497                                         set->sss_update_transport =
1498                                                 atoi( &cargv[i][sizeof("update_transport")] );
1499
1500                                 } else if( strncasecmp( cargv[i], "update_tls=",
1501                                         sizeof("update_tls") ) == 0 )
1502                                 {
1503                                         set->sss_update_tls =
1504                                                 atoi( &cargv[i][sizeof("update_tls")] );
1505
1506                                 } else if( strncasecmp( cargv[i], "update_sasl=",
1507                                         sizeof("update_sasl") ) == 0 )
1508                                 {
1509                                         set->sss_update_sasl =
1510                                                 atoi( &cargv[i][sizeof("update_sasl")] );
1511
1512                                 } else if( strncasecmp( cargv[i], "simple_bind=",
1513                                         sizeof("simple_bind") ) == 0 )
1514                                 {
1515                                         set->sss_simple_bind =
1516                                                 atoi( &cargv[i][sizeof("simple_bind")] );
1517
1518                                 } else {
1519 #ifdef NEW_LOGGING
1520                                         LDAP_LOG( CONFIG, CRIT, 
1521                                                    "%s: line %d: unknown factor %S in "
1522                                                    "\"security <factors>\" line.\n",
1523                                                    fname, lineno, cargv[1] );
1524 #else
1525                                         Debug( LDAP_DEBUG_ANY,
1526                     "%s: line %d: unknown factor %s in \"security <factors>\" line\n",
1527                                             fname, lineno, cargv[i] );
1528 #endif
1529
1530                                         return( 1 );
1531                                 }
1532                         }
1533                 /* where to send clients when we don't hold it */
1534                 } else if ( strcasecmp( cargv[0], "referral" ) == 0 ) {
1535                         if ( cargc < 2 ) {
1536 #ifdef NEW_LOGGING
1537                                 LDAP_LOG( CONFIG, CRIT, 
1538                                         "%s: line %d: missing URL in \"referral <URL>\""
1539                                         " line.\n", fname, lineno , 0 );
1540 #else
1541                                 Debug( LDAP_DEBUG_ANY,
1542                     "%s: line %d: missing URL in \"referral <URL>\" line\n",
1543                                     fname, lineno, 0 );
1544 #endif
1545
1546                                 return( 1 );
1547                         }
1548
1549                         if( validate_global_referral( cargv[1] ) ) {
1550 #ifdef NEW_LOGGING
1551                                 LDAP_LOG( CONFIG, CRIT, 
1552                                         "%s: line %d: invalid URL (%s) in \"referral\" line.\n",
1553                                         fname, lineno, cargv[1]  );
1554 #else
1555                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1556                                         "invalid URL (%s) in \"referral\" line.\n",
1557                                     fname, lineno, cargv[1] );
1558 #endif
1559                                 return 1;
1560                         }
1561
1562                         vals[0].bv_val = cargv[1];
1563                         vals[0].bv_len = strlen( vals[0].bv_val );
1564                         if( value_add( &default_referral, vals ) )
1565                                 return LDAP_OTHER;
1566
1567 #ifdef NEW_LOGGING
1568                 } else if ( strcasecmp( cargv[0], "logfile" ) == 0 ) {
1569                         FILE *logfile;
1570                         if ( cargc < 2 ) {
1571 #ifdef NEW_LOGGING
1572                                 LDAP_LOG( CONFIG, CRIT, 
1573                                         "%s: line %d: Error in logfile directive, "
1574                                         "\"logfile <filename>\"\n", fname, lineno , 0 );
1575 #else
1576                                 Debug( LDAP_DEBUG_ANY,
1577                                        "%s: line %d: Error in logfile directive, \"logfile filename\"\n",
1578                                        fname, lineno, 0 );
1579 #endif
1580
1581                                 return( 1 );
1582                         }
1583                         logfile = fopen( cargv[1], "w" );
1584                         if ( logfile != NULL ) lutil_debug_file( logfile  );
1585
1586 #endif
1587                 /* start of a new database definition */
1588                 } else if ( strcasecmp( cargv[0], "debug" ) == 0 ) {
1589                         int level;
1590                         if ( cargc < 3 ) {
1591 #ifdef NEW_LOGGING
1592                                 LDAP_LOG( CONFIG, CRIT, 
1593                                            "%s: line %d: Error in debug directive, "
1594                                            "\"debug <subsys> <level>\"\n", fname, lineno , 0 );
1595 #else
1596                                 Debug( LDAP_DEBUG_ANY,
1597                                         "%s: line %d: Error in debug directive, \"debug subsys level\"\n",
1598                                         fname, lineno, 0 );
1599 #endif
1600
1601                                 return( 1 );
1602                         }
1603                         level = atoi( cargv[2] );
1604                         if ( level <= 0 ) level = lutil_mnem2level( cargv[2] );
1605                         lutil_set_debug_level( cargv[1], level );
1606                 /* specify an Object Identifier macro */
1607                 } else if ( strcasecmp( cargv[0], "objectidentifier" ) == 0 ) {
1608                         rc = parse_oidm( fname, lineno, cargc, cargv );
1609                         if( rc ) return rc;
1610
1611                 /* specify an objectclass */
1612                 } else if ( strcasecmp( cargv[0], "objectclass" ) == 0 ) {
1613                         if ( cargc < 2 ) {
1614 #ifdef NEW_LOGGING
1615                                 LDAP_LOG( CONFIG, INFO, 
1616                                         "%s: line %d: illegal objectclass format.\n",
1617                                         fname, lineno , 0 );
1618 #else
1619                                 Debug( LDAP_DEBUG_ANY,
1620                                        "%s: line %d: illegal objectclass format.\n",
1621                                        fname, lineno, 0 );
1622 #endif
1623                                 return( 1 );
1624
1625                         } else if ( *cargv[1] == '('  /*')'*/) {
1626                                 char * p;
1627                                 p = strchr(saveline,'(' /*')'*/);
1628                                 rc = parse_oc( fname, lineno, p, cargv );
1629                                 if( rc ) return rc;
1630
1631                         } else {
1632 #ifdef NEW_LOGGING
1633                                 LDAP_LOG( CONFIG, INFO, 
1634                                         "%s: line %d: old objectclass format not supported\n",
1635                                         fname, lineno , 0 );
1636 #else
1637                                 Debug( LDAP_DEBUG_ANY,
1638                                        "%s: line %d: old objectclass format not supported.\n",
1639                                        fname, lineno, 0 );
1640 #endif
1641                         }
1642
1643 #ifdef SLAP_EXTENDED_SCHEMA
1644                 } else if ( strcasecmp( cargv[0], "ditcontentrule" ) == 0 ) {
1645                         char * p;
1646                         p = strchr(saveline,'(' /*')'*/);
1647                         rc = parse_cr( fname, lineno, p, cargv );
1648                         if( rc ) return rc;
1649 #endif
1650
1651                 /* specify an attribute type */
1652                 } else if (( strcasecmp( cargv[0], "attributetype" ) == 0 )
1653                         || ( strcasecmp( cargv[0], "attribute" ) == 0 ))
1654                 {
1655                         if ( cargc < 2 ) {
1656 #ifdef NEW_LOGGING
1657                                 LDAP_LOG( CONFIG, INFO, "%s: line %d: "
1658                                         "illegal attribute type format.\n",
1659                                         fname, lineno , 0 );
1660 #else
1661                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1662                                         "illegal attribute type format.\n",
1663                                         fname, lineno, 0 );
1664 #endif
1665                                 return( 1 );
1666
1667                         } else if ( *cargv[1] == '(' /*')'*/) {
1668                                 char * p;
1669                                 p = strchr(saveline,'(' /*')'*/);
1670                                 rc = parse_at( fname, lineno, p, cargv );
1671                                 if( rc ) return rc;
1672
1673                         } else {
1674 #ifdef NEW_LOGGING
1675                                 LDAP_LOG( CONFIG, INFO, 
1676                                         "%s: line %d: old attribute type format not supported.\n",
1677                                         fname, lineno , 0 );
1678 #else
1679                                 Debug( LDAP_DEBUG_ANY,
1680     "%s: line %d: old attribute type format not supported.\n",
1681                                     fname, lineno, 0 );
1682 #endif
1683
1684                         }
1685
1686                 /* define attribute option(s) */
1687                 } else if ( strcasecmp( cargv[0], "attributeoptions" ) == 0 ) {
1688                         ad_define_option( NULL, NULL, 0 );
1689                         for ( i = 1; i < cargc; i++ )
1690                                 if ( ad_define_option( cargv[i], fname, lineno ) != 0 )
1691                                         return 1;
1692
1693                 /* turn on/off schema checking */
1694                 } else if ( strcasecmp( cargv[0], "schemacheck" ) == 0 ) {
1695                         if ( cargc < 2 ) {
1696 #ifdef NEW_LOGGING
1697                                 LDAP_LOG( CONFIG, CRIT, 
1698                                         "%s: line %d: missing on|off in \"schemacheck <on|off>\""
1699                                         " line.\n", fname, lineno , 0 );
1700 #else
1701                                 Debug( LDAP_DEBUG_ANY,
1702     "%s: line %d: missing on|off in \"schemacheck <on|off>\" line\n",
1703                                     fname, lineno, 0 );
1704 #endif
1705
1706                                 return( 1 );
1707                         }
1708                         if ( strcasecmp( cargv[1], "off" ) == 0 ) {
1709 #ifdef NEW_LOGGING
1710                                 LDAP_LOG( CONFIG, CRIT, 
1711                                         "%s: line %d: schema checking disabled! your mileage may "
1712                                         "vary!\n", fname, lineno , 0 );
1713 #else
1714                                 Debug( LDAP_DEBUG_ANY,
1715                                         "%s: line %d: schema checking disabled! your mileage may vary!\n",
1716                                     fname, lineno, 0 );
1717 #endif
1718                                 global_schemacheck = 0;
1719                         } else {
1720                                 global_schemacheck = 1;
1721                         }
1722
1723                 /* specify access control info */
1724                 } else if ( strcasecmp( cargv[0], "access" ) == 0 ) {
1725                         parse_acl( be, fname, lineno, cargc, cargv );
1726
1727                 /* debug level to log things to syslog */
1728                 } else if ( strcasecmp( cargv[0], "loglevel" ) == 0 ) {
1729                         if ( cargc < 2 ) {
1730 #ifdef NEW_LOGGING
1731                                 LDAP_LOG( CONFIG, CRIT, 
1732                                         "%s: line %d: missing level in \"loglevel <level>\""
1733                                         " line.\n", fname, lineno , 0 );
1734 #else
1735                                 Debug( LDAP_DEBUG_ANY,
1736                     "%s: line %d: missing level in \"loglevel <level>\" line\n",
1737                                     fname, lineno, 0 );
1738 #endif
1739
1740                                 return( 1 );
1741                         }
1742
1743                         ldap_syslog = 0;
1744
1745                         for( i=1; i < cargc; i++ ) {
1746                                 ldap_syslog += atoi( cargv[1] );
1747                         }
1748
1749 #ifdef LDAP_SYNCREPL
1750                 /* list of sync replication information in this backend (slave only) */
1751                 } else if ( strcasecmp( cargv[0], "syncrepl" ) == 0 ) {
1752
1753                         add_syncrepl( be, cargv, cargc );
1754 #endif
1755
1756                 /* list of replicas of the data in this backend (master only) */
1757                 } else if ( strcasecmp( cargv[0], "replica" ) == 0 ) {
1758                         if ( cargc < 2 ) {
1759 #ifdef NEW_LOGGING
1760                                 LDAP_LOG( CONFIG, CRIT, 
1761                                         "%s: line %d: missing host in \"replica "
1762                                         " <host[:port]\" line\n", fname, lineno , 0 );
1763 #else
1764                                 Debug( LDAP_DEBUG_ANY,
1765             "%s: line %d: missing host in \"replica <host[:port]>\" line\n",
1766                                     fname, lineno, 0 );
1767 #endif
1768
1769                                 return( 1 );
1770                         }
1771                         if ( be == NULL ) {
1772 #ifdef NEW_LOGGING
1773                                 LDAP_LOG( CONFIG, INFO, 
1774                                             "%s: line %d: replica line must appear inside "
1775                                             "a database definition.\n", fname, lineno, 0);
1776 #else
1777                                 Debug( LDAP_DEBUG_ANY,
1778 "%s: line %d: replica line must appear inside a database definition\n",
1779                                     fname, lineno, 0 );
1780 #endif
1781                                 return 1;
1782
1783                         } else {
1784                                 int nr = -1;
1785
1786                                 for ( i = 1; i < cargc; i++ ) {
1787                                         if ( strncasecmp( cargv[i], "host=", 5 )
1788                                             == 0 ) {
1789                                                 nr = add_replica_info( be, 
1790                                                         cargv[i] + 5 );
1791                                                 break;
1792                                         }
1793                                 }
1794                                 if ( i == cargc ) {
1795 #ifdef NEW_LOGGING
1796                                         LDAP_LOG( CONFIG, INFO, 
1797                                                 "%s: line %d: missing host in \"replica\" line\n", 
1798                                                 fname, lineno , 0 );
1799 #else
1800                                         Debug( LDAP_DEBUG_ANY,
1801                     "%s: line %d: missing host in \"replica\" line\n",
1802                                             fname, lineno, 0 );
1803 #endif
1804                                         return 1;
1805
1806                                 } else if ( nr == -1 ) {
1807 #ifdef NEW_LOGGING
1808                                         LDAP_LOG( CONFIG, INFO, 
1809                                                    "%s: line %d: unable to add"
1810                                                    " replica \"%s\"\n",
1811                                                    fname, lineno, 
1812                                                    cargv[i] + 5 );
1813 #else
1814                                         Debug( LDAP_DEBUG_ANY,
1815                 "%s: line %d: unable to add replica \"%s\"\n",
1816                                                 fname, lineno, cargv[i] + 5 );
1817 #endif
1818                                         return 1;
1819                                 } else {
1820                                         for ( i = 1; i < cargc; i++ ) {
1821                                                 if ( strncasecmp( cargv[i], "suffix=", 7 ) == 0 ) {
1822
1823                                                         switch ( add_replica_suffix( be, nr, cargv[i] + 7 ) ) {
1824                                                         case 1:
1825 #ifdef NEW_LOGGING
1826                                                                 LDAP_LOG( CONFIG, INFO, 
1827                                                                         "%s: line %d: suffix \"%s\" in \"replica\""
1828                                                                         " line is not valid for backend(ignored)\n",
1829                                                                         fname, lineno, cargv[i] + 7 );
1830 #else
1831                                                                 Debug( LDAP_DEBUG_ANY,
1832                                                                                 "%s: line %d: suffix \"%s\" in \"replica\" line is not valid for backend (ignored)\n",
1833                                                                                 fname, lineno, cargv[i] + 7 );
1834 #endif
1835                                                                 break;
1836
1837                                                         case 2:
1838 #ifdef NEW_LOGGING
1839                                                                 LDAP_LOG( CONFIG, INFO, 
1840                                                                         "%s: line %d: unable to normalize suffix"
1841                                                                         " in \"replica\" line (ignored)\n",
1842                                                                         fname, lineno , 0 );
1843 #else
1844                                                                 Debug( LDAP_DEBUG_ANY,
1845                                                                                  "%s: line %d: unable to normalize suffix in \"replica\" line (ignored)\n",
1846                                                                                  fname, lineno, 0 );
1847 #endif
1848                                                                 break;
1849                                                         }
1850
1851                                                 } else if ( strncasecmp( cargv[i], "attr", 4 ) == 0 ) {
1852                                                         int exclude = 0;
1853                                                         char *arg = cargv[i] + 4;
1854
1855                                                         if ( arg[0] == '!' ) {
1856                                                                 arg++;
1857                                                                 exclude = 1;
1858                                                         }
1859
1860                                                         if ( arg[0] != '=' ) {
1861                                                                 continue;
1862                                                         }
1863
1864                                                         if ( add_replica_attrs( be, nr, arg + 1, exclude ) ) {
1865 #ifdef NEW_LOGGING
1866                                                                 LDAP_LOG( CONFIG, INFO, 
1867                                                                         "%s: line %d: attribute \"%s\" in "
1868                                                                         "\"replica\" line is unknown\n",
1869                                                                         fname, lineno, arg + 1 ); 
1870 #else
1871                                                                 Debug( LDAP_DEBUG_ANY,
1872                                                                                 "%s: line %d: attribute \"%s\" in \"replica\" line is unknown\n",
1873                                                                                 fname, lineno, arg + 1 );
1874 #endif
1875                                                                 return( 1 );
1876                                                         }
1877                                                 }
1878                                         }
1879                                 }
1880                         }
1881
1882                 /* dn of master entity allowed to write to replica */
1883                 } else if ( strcasecmp( cargv[0], "updatedn" ) == 0 ) {
1884                         if ( cargc < 2 ) {
1885 #ifdef NEW_LOGGING
1886                                 LDAP_LOG( CONFIG, CRIT, 
1887                                         "%s: line %d: missing dn in \"updatedn <dn>\""
1888                                         " line.\n", fname, lineno , 0 );
1889 #else
1890                                 Debug( LDAP_DEBUG_ANY,
1891                     "%s: line %d: missing dn in \"updatedn <dn>\" line\n",
1892                                     fname, lineno, 0 );
1893 #endif
1894
1895                                 return( 1 );
1896                         }
1897                         if ( be == NULL ) {
1898 #ifdef NEW_LOGGING
1899                                 LDAP_LOG( CONFIG, INFO, 
1900                                         "%s: line %d: updatedn line must appear inside "
1901                                         "a database definition\n", 
1902                                         fname, lineno , 0 );
1903 #else
1904                                 Debug( LDAP_DEBUG_ANY,
1905 "%s: line %d: updatedn line must appear inside a database definition\n",
1906                                     fname, lineno, 0 );
1907 #endif
1908                                 return 1;
1909
1910                         } else {
1911                                 struct berval dn;
1912
1913                                 if ( load_ucdata( NULL ) < 0 ) return 1;
1914
1915                                 dn.bv_val = cargv[1];
1916                                 dn.bv_len = strlen( cargv[1] );
1917
1918                                 rc = dnNormalize( 0, NULL, NULL, &dn, &be->be_update_ndn, NULL );
1919                                 if( rc != LDAP_SUCCESS ) {
1920 #ifdef NEW_LOGGING
1921                                         LDAP_LOG( CONFIG, CRIT, 
1922                                                 "%s: line %d: updatedn DN is invalid.\n",
1923                                                 fname, lineno , 0 );
1924 #else
1925                                         Debug( LDAP_DEBUG_ANY,
1926                                                 "%s: line %d: updatedn DN is invalid\n",
1927                                             fname, lineno, 0 );
1928 #endif
1929                                         return 1;
1930                                 }
1931                         }
1932
1933                 } else if ( strcasecmp( cargv[0], "updateref" ) == 0 ) {
1934                         if ( cargc < 2 ) {
1935 #ifdef NEW_LOGGING
1936                                 LDAP_LOG( CONFIG, CRIT, "%s: line %d: "
1937                                         "missing url in \"updateref <ldapurl>\" line.\n",
1938                                         fname, lineno , 0 );
1939 #else
1940                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1941                                         "missing url in \"updateref <ldapurl>\" line\n",
1942                                     fname, lineno, 0 );
1943 #endif
1944
1945                                 return( 1 );
1946                         }
1947                         if ( be == NULL ) {
1948 #ifdef NEW_LOGGING
1949                                 LDAP_LOG( CONFIG, INFO, "%s: line %d: updateref"
1950                                         " line must appear inside a database definition\n",
1951                                         fname, lineno , 0 );
1952 #else
1953                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: updateref"
1954                                         " line must appear inside a database definition\n",
1955                                         fname, lineno, 0 );
1956 #endif
1957                                 return 1;
1958
1959                         } else if ( !be->be_update_ndn.bv_len ) {
1960 #ifdef NEW_LOGGING
1961                                 LDAP_LOG( CONFIG, INFO, "%s: line %d: "
1962                                         "updateref line must come after updatedn.\n",
1963                                         fname, lineno , 0 );
1964 #else
1965                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1966                                         "updateref line must after updatedn.\n",
1967                                     fname, lineno, 0 );
1968 #endif
1969                                 return 1;
1970                         }
1971
1972                         if( validate_global_referral( cargv[1] ) ) {
1973 #ifdef NEW_LOGGING
1974                                 LDAP_LOG( CONFIG, CRIT, "%s: line %d: "
1975                                         "invalid URL (%s) in \"updateref\" line.\n",
1976                                         fname, lineno, cargv[1] );
1977 #else
1978                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1979                                         "invalid URL (%s) in \"updateref\" line.\n",
1980                                     fname, lineno, cargv[1] );
1981 #endif
1982                                 return 1;
1983                         }
1984
1985                         vals[0].bv_val = cargv[1];
1986                         vals[0].bv_len = strlen( vals[0].bv_val );
1987                         if( value_add( &be->be_update_refs, vals ) )
1988                                 return LDAP_OTHER;
1989
1990                 /* replication log file to which changes are appended */
1991                 } else if ( strcasecmp( cargv[0], "replogfile" ) == 0 ) {
1992                         if ( cargc < 2 ) {
1993 #ifdef NEW_LOGGING
1994                                 LDAP_LOG( CONFIG, CRIT, 
1995                                         "%s: line %d: missing filename in \"replogfile <filename>\""
1996                                         " line.\n", fname, lineno , 0 );
1997 #else
1998                                 Debug( LDAP_DEBUG_ANY,
1999             "%s: line %d: missing filename in \"replogfile <filename>\" line\n",
2000                                     fname, lineno, 0 );
2001 #endif
2002
2003                                 return( 1 );
2004                         }
2005                         if ( be ) {
2006                                 be->be_replogfile = ch_strdup( cargv[1] );
2007                         } else {
2008                                 replogfile = ch_strdup( cargv[1] );
2009                         }
2010
2011                 /* file from which to read additional rootdse attrs */
2012                 } else if ( strcasecmp( cargv[0], "rootDSE" ) == 0) {
2013                         if ( cargc < 2 ) {
2014 #ifdef NEW_LOGGING
2015                                 LDAP_LOG( CONFIG, CRIT, "%s: line %d: "
2016                                         "missing filename in \"rootDSE <filename>\" line.\n",
2017                                         fname, lineno , 0 );
2018 #else
2019                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
2020                                         "missing filename in \"rootDSE <filename>\" line.\n",
2021                                     fname, lineno, 0 );
2022 #endif
2023                                 return 1;
2024                         }
2025
2026                         if( read_root_dse_file( cargv[1] ) ) {
2027 #ifdef NEW_LOGGING
2028                                 LDAP_LOG( CONFIG, CRIT, "%s: line %d: "
2029                                         "could not read \"rootDSE <filename>\" line.\n",
2030                                         fname, lineno , 0 );
2031 #else
2032                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
2033                                         "could not read \"rootDSE <filename>\" line\n",
2034                                     fname, lineno, 0 );
2035 #endif
2036                                 return 1;
2037                         }
2038
2039                 /* maintain lastmodified{by,time} attributes */
2040                 } else if ( strcasecmp( cargv[0], "lastmod" ) == 0 ) {
2041                         if ( cargc < 2 ) {
2042 #ifdef NEW_LOGGING
2043                                 LDAP_LOG( CONFIG, CRIT, 
2044                                            "%s: line %d: missing on|off in \"lastmod <on|off>\""
2045                                            " line.\n", fname, lineno , 0 );
2046 #else
2047                                 Debug( LDAP_DEBUG_ANY,
2048             "%s: line %d: missing on|off in \"lastmod <on|off>\" line\n",
2049                                     fname, lineno, 0 );
2050 #endif
2051
2052                                 return( 1 );
2053                         }
2054                         if ( strcasecmp( cargv[1], "on" ) == 0 ) {
2055                                 if ( be ) {
2056                                         be->be_flags &= ~SLAP_BFLAG_NOLASTMOD;
2057                                 } else {
2058                                         lastmod = 1;
2059                                 }
2060                         } else {
2061                                 if ( be ) {
2062                                         be->be_flags |= SLAP_BFLAG_NOLASTMOD;
2063                                 } else {
2064                                         lastmod = 0;
2065                                 }
2066                         }
2067
2068 #ifdef SIGHUP
2069                 /* turn on/off gentle SIGHUP handling */
2070                 } else if ( strcasecmp( cargv[0], "gentlehup" ) == 0 ) {
2071                         if ( cargc < 2 ) {
2072                                 Debug( LDAP_DEBUG_ANY,
2073     "%s: line %d: missing on|off in \"gentlehup <on|off>\" line\n",
2074                                     fname, lineno, 0 );
2075                                 return( 1 );
2076                         }
2077                         if ( strcasecmp( cargv[1], "off" ) == 0 ) {
2078                                 global_gentlehup = 0;
2079                         } else {
2080                                 global_gentlehup = 1;
2081                         }
2082 #endif
2083
2084                 /* set idle timeout value */
2085                 } else if ( strcasecmp( cargv[0], "idletimeout" ) == 0 ) {
2086                         int i;
2087                         if ( cargc < 2 ) {
2088 #ifdef NEW_LOGGING
2089                                 LDAP_LOG( CONFIG, CRIT, 
2090                                         "%s: line %d: missing timeout value in "
2091                                         "\"idletimeout <seconds>\" line.\n", fname, lineno , 0 );
2092 #else
2093                                 Debug( LDAP_DEBUG_ANY,
2094             "%s: line %d: missing timeout value in \"idletimeout <seconds>\" line\n",
2095                                     fname, lineno, 0 );
2096 #endif
2097
2098                                 return( 1 );
2099                         }
2100
2101                         i = atoi( cargv[1] );
2102
2103                         if( i < 0 ) {
2104 #ifdef NEW_LOGGING
2105                                 LDAP_LOG( CONFIG, CRIT, 
2106                                         "%s: line %d: timeout value (%d) invalid "
2107                                         "\"idletimeout <seconds>\" line.\n", fname, lineno, i );
2108 #else
2109                                 Debug( LDAP_DEBUG_ANY,
2110             "%s: line %d: timeout value (%d) invalid \"idletimeout <seconds>\" line\n",
2111                                     fname, lineno, i );
2112 #endif
2113
2114                                 return( 1 );
2115                         }
2116
2117                         global_idletimeout = i;
2118
2119                 /* include another config file */
2120                 } else if ( strcasecmp( cargv[0], "include" ) == 0 ) {
2121                         if ( cargc < 2 ) {
2122 #ifdef NEW_LOGGING
2123                                 LDAP_LOG( CONFIG, CRIT, 
2124                                         "%s: line %d: missing filename in \"include "
2125                                         "<filename>\" line.\n", fname, lineno , 0 );
2126 #else
2127                                 Debug( LDAP_DEBUG_ANY,
2128     "%s: line %d: missing filename in \"include <filename>\" line\n",
2129                                     fname, lineno, 0 );
2130 #endif
2131
2132                                 return( 1 );
2133                         }
2134                         savefname = ch_strdup( cargv[1] );
2135                         savelineno = lineno;
2136
2137                         if ( read_config( savefname, depth+1 ) != 0 ) {
2138                                 return( 1 );
2139                         }
2140
2141                         free( savefname );
2142                         lineno = savelineno - 1;
2143
2144                 /* location of kerberos srvtab file */
2145                 } else if ( strcasecmp( cargv[0], "srvtab" ) == 0 ) {
2146                         if ( cargc < 2 ) {
2147 #ifdef NEW_LOGGING
2148                                 LDAP_LOG( CONFIG, CRIT, 
2149                                         "%s: line %d: missing filename in \"srvtab "
2150                                         "<filename>\" line.\n", fname, lineno , 0 );
2151 #else
2152                                 Debug( LDAP_DEBUG_ANY,
2153             "%s: line %d: missing filename in \"srvtab <filename>\" line\n",
2154                                     fname, lineno, 0 );
2155 #endif
2156
2157                                 return( 1 );
2158                         }
2159                         ldap_srvtab = ch_strdup( cargv[1] );
2160
2161 #ifdef SLAPD_MODULES
2162                 } else if (strcasecmp( cargv[0], "moduleload") == 0 ) {
2163                    if ( cargc < 2 ) {
2164 #ifdef NEW_LOGGING
2165                            LDAP_LOG( CONFIG, INFO, 
2166                                    "%s: line %d: missing filename in \"moduleload "
2167                                    "<filename>\" line.\n", fname, lineno , 0 );
2168 #else
2169                       Debug( LDAP_DEBUG_ANY,
2170                              "%s: line %d: missing filename in \"moduleload <filename>\" line\n",
2171                              fname, lineno, 0 );
2172 #endif
2173
2174                       exit( EXIT_FAILURE );
2175                    }
2176                    if (module_load(cargv[1], cargc - 2, (cargc > 2) ? cargv + 2 : NULL)) {
2177 #ifdef NEW_LOGGING
2178                            LDAP_LOG( CONFIG, CRIT, 
2179                                    "%s: line %d: failed to load or initialize module %s\n",
2180                                    fname, lineno, cargv[1] );
2181 #else
2182                       Debug( LDAP_DEBUG_ANY,
2183                              "%s: line %d: failed to load or initialize module %s\n",
2184                              fname, lineno, cargv[1]);
2185 #endif
2186
2187                       exit( EXIT_FAILURE );
2188                    }
2189                 } else if (strcasecmp( cargv[0], "modulepath") == 0 ) {
2190                    if ( cargc != 2 ) {
2191 #ifdef NEW_LOGGING
2192                            LDAP_LOG( CONFIG, INFO, 
2193                                   "%s: line %d: missing path in \"modulepath <path>\""
2194                                   " line\n", fname, lineno , 0 );
2195 #else
2196                       Debug( LDAP_DEBUG_ANY,
2197                              "%s: line %d: missing path in \"modulepath <path>\" line\n",
2198                              fname, lineno, 0 );
2199 #endif
2200
2201                       exit( EXIT_FAILURE );
2202                    }
2203                    if (module_path( cargv[1] )) {
2204 #ifdef NEW_LOGGING
2205                            LDAP_LOG( CONFIG, CRIT, 
2206                                   "%s: line %d: failed to set module search path to %s.\n",
2207                                   fname, lineno, cargv[1] );
2208 #else
2209                            Debug( LDAP_DEBUG_ANY,
2210                                   "%s: line %d: failed to set module search path to %s\n",
2211                                   fname, lineno, cargv[1]);
2212 #endif
2213
2214                       exit( EXIT_FAILURE );
2215                    }
2216                    
2217 #endif /*SLAPD_MODULES*/
2218
2219 #ifdef HAVE_TLS
2220                 } else if ( !strcasecmp( cargv[0], "TLSRandFile" ) ) {
2221                         rc = ldap_pvt_tls_set_option( NULL,
2222                                                       LDAP_OPT_X_TLS_RANDOM_FILE,
2223                                                       cargv[1] );
2224                         if ( rc )
2225                                 return rc;
2226
2227                 } else if ( !strcasecmp( cargv[0], "TLSCipherSuite" ) ) {
2228                         rc = ldap_pvt_tls_set_option( NULL,
2229                                                       LDAP_OPT_X_TLS_CIPHER_SUITE,
2230                                                       cargv[1] );
2231                         if ( rc )
2232                                 return rc;
2233
2234                 } else if ( !strcasecmp( cargv[0], "TLSCertificateFile" ) ) {
2235                         rc = ldap_pvt_tls_set_option( NULL,
2236                                                       LDAP_OPT_X_TLS_CERTFILE,
2237                                                       cargv[1] );
2238                         if ( rc )
2239                                 return rc;
2240
2241                 } else if ( !strcasecmp( cargv[0], "TLSCertificateKeyFile" ) ) {
2242                         rc = ldap_pvt_tls_set_option( NULL,
2243                                                       LDAP_OPT_X_TLS_KEYFILE,
2244                                                       cargv[1] );
2245                         if ( rc )
2246                                 return rc;
2247
2248                 } else if ( !strcasecmp( cargv[0], "TLSCACertificatePath" ) ) {
2249                         rc = ldap_pvt_tls_set_option( NULL,
2250                                                       LDAP_OPT_X_TLS_CACERTDIR,
2251                                                       cargv[1] );
2252                         if ( rc )
2253                                 return rc;
2254
2255                 } else if ( !strcasecmp( cargv[0], "TLSCACertificateFile" ) ) {
2256                         rc = ldap_pvt_tls_set_option( NULL,
2257                                                       LDAP_OPT_X_TLS_CACERTFILE,
2258                                                       cargv[1] );
2259                         if ( rc )
2260                                 return rc;
2261                 } else if ( !strcasecmp( cargv[0], "TLSVerifyClient" ) ) {
2262                         if ( isdigit( (unsigned char) cargv[1][0] ) ) {
2263                                 i = atoi(cargv[1]);
2264                                 rc = ldap_pvt_tls_set_option( NULL,
2265                                                       LDAP_OPT_X_TLS_REQUIRE_CERT,
2266                                                       &i );
2267                         } else {
2268                                 rc = ldap_int_tls_config( NULL,
2269                                                       LDAP_OPT_X_TLS_REQUIRE_CERT,
2270                                                       cargv[1] );
2271                         }
2272
2273                         if ( rc )
2274                                 return rc;
2275
2276 #endif
2277
2278                 } else if ( !strcasecmp( cargv[0], "reverse-lookup" ) ) {
2279 #ifdef SLAPD_RLOOKUPS
2280                         if ( cargc < 2 ) {
2281 #ifdef NEW_LOGGING
2282                                 LDAP_LOG( CONFIG, INFO, 
2283                                         "%s: line %d: reverse-lookup: missing \"on\" or \"off\"\n",
2284                                         fname, lineno , 0 );
2285 #else
2286                                 Debug( LDAP_DEBUG_ANY,
2287 "%s: line %d: reverse-lookup: missing \"on\" or \"off\"\n",
2288                                         fname, lineno, 0 );
2289 #endif
2290                                 return( 1 );
2291                         }
2292
2293                         if ( !strcasecmp( cargv[1], "on" ) ) {
2294                                 use_reverse_lookup = 1;
2295                         } else if ( !strcasecmp( cargv[1], "off" ) ) {
2296                                 use_reverse_lookup = 0;
2297                         } else {
2298 #ifdef NEW_LOGGING
2299                                 LDAP_LOG( CONFIG, INFO, 
2300                                         "%s: line %d: reverse-lookup: "
2301                                         "must be \"on\" (default) or \"off\"\n", fname, lineno, 0 );
2302 #else
2303                                 Debug( LDAP_DEBUG_ANY,
2304 "%s: line %d: reverse-lookup: must be \"on\" (default) or \"off\"\n",
2305                                         fname, lineno, 0 );
2306 #endif
2307                                 return( 1 );
2308                         }
2309
2310 #else /* !SLAPD_RLOOKUPS */
2311 #ifdef NEW_LOGGING
2312                         LDAP_LOG( CONFIG, INFO, 
2313                                 "%s: line %d: reverse lookups "
2314                                 "are not configured (ignored).\n", fname, lineno , 0 );
2315 #else
2316                         Debug( LDAP_DEBUG_ANY,
2317 "%s: line %d: reverse lookups are not configured (ignored).\n",
2318                                 fname, lineno, 0 );
2319 #endif
2320 #endif /* !SLAPD_RLOOKUPS */
2321
2322                 /* Netscape plugins */
2323                 } else if ( strcasecmp( cargv[0], "plugin" ) == 0 ) {
2324 #if defined( LDAP_SLAPI )
2325
2326 #ifdef notdef /* allow global plugins, too */
2327                         /*
2328                          * a "plugin" line must be inside a database
2329                          * definition, since we implement pre-,post- 
2330                          * and extended operation plugins
2331                          */
2332                         if ( be == NULL ) {
2333 #ifdef NEW_LOGGING
2334                                 LDAP_LOG( CONFIG, INFO, 
2335                                         "%s: line %d: plugin line must appear "
2336                                         "inside a database definition.\n",
2337                                         fname, lineno, 0 );
2338 #else
2339                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: plugin "
2340                                     "line must appear inside a database "
2341                                     "definition\n", fname, lineno, 0 );
2342 #endif
2343                                 return( 1 );
2344                         }
2345 #endif /* notdef */
2346
2347                         if ( netscape_plugin( be, fname, lineno, cargc, cargv ) 
2348                                         != LDAP_SUCCESS ) {
2349                                 return( 1 );
2350                         }
2351
2352 #else /* !defined( LDAP_SLAPI ) */
2353 #ifdef NEW_LOGGING
2354                         LDAP_LOG( CONFIG, INFO, 
2355                                 "%s: line %d: SLAPI not supported.\n",
2356                                 fname, lineno, 0 );
2357 #else
2358                         Debug( LDAP_DEBUG_ANY, "%s: line %d: SLAPI "
2359                             "not supported.\n", fname, lineno, 0 );
2360 #endif
2361                         return( 1 );
2362                         
2363 #endif /* !defined( LDAP_SLAPI ) */
2364
2365                 /* Netscape plugins */
2366                 } else if ( strcasecmp( cargv[0], "pluginlog" ) == 0 ) {
2367 #if defined( LDAP_SLAPI )
2368                         if ( cargc < 2 ) {
2369 #ifdef NEW_LOGGING
2370                                 LDAP_LOG( CONFIG, INFO, 
2371                                         "%s: line %d: missing file name "
2372                                         "in pluginlog <filename> line.\n",
2373                                         fname, lineno, 0 );
2374 #else
2375                                 Debug( LDAP_DEBUG_ANY, 
2376                                         "%s: line %d: missing file name "
2377                                         "in pluginlog <filename> line.\n",
2378                                         fname, lineno, 0 );
2379 #endif
2380                                 return( 1 );
2381                         }
2382
2383                         if ( slapi_log_file != NULL ) {
2384                                 ch_free( slapi_log_file );
2385                         }
2386
2387                         slapi_log_file = ch_strdup( cargv[1] );
2388 #endif /* !defined( LDAP_SLAPI ) */
2389
2390                 /* pass anything else to the current backend info/db config routine */
2391                 } else {
2392                         if ( bi != NULL ) {
2393                                 if ( bi->bi_config == 0 ) {
2394 #ifdef NEW_LOGGING
2395                                         LDAP_LOG( CONFIG, INFO, 
2396                                                 "%s: line %d: unknown directive \"%s\" inside "
2397                                                 "backend info definition (ignored).\n",
2398                                                 fname, lineno, cargv[0] );
2399 #else
2400                                         Debug( LDAP_DEBUG_ANY,
2401 "%s: line %d: unknown directive \"%s\" inside backend info definition (ignored)\n",
2402                                                 fname, lineno, cargv[0] );
2403 #endif
2404
2405                                 } else {
2406                                         if ( (*bi->bi_config)( bi, fname, lineno, cargc, cargv )
2407                                                 != 0 )
2408                                         {
2409                                                 return( 1 );
2410                                         }
2411                                 }
2412                         } else if ( be != NULL ) {
2413                                 if ( be->be_config == 0 ) {
2414 #ifdef NEW_LOGGING
2415                                         LDAP_LOG( CONFIG, INFO, 
2416                                                 "%s: line %d: uknown directive \"%s\" inside "
2417                                                 "backend database definition (ignored).\n",
2418                                                 fname, lineno, cargv[0] );
2419 #else
2420                                         Debug( LDAP_DEBUG_ANY,
2421 "%s: line %d: unknown directive \"%s\" inside backend database definition (ignored)\n",
2422                                         fname, lineno, cargv[0] );
2423 #endif
2424
2425                                 } else {
2426                                         if ( (*be->be_config)( be, fname, lineno, cargc, cargv )
2427                                                 != 0 )
2428                                         {
2429                                                 return( 1 );
2430                                         }
2431                                 }
2432                         } else {
2433 #ifdef NEW_LOGGING
2434                                 LDAP_LOG( CONFIG, INFO, 
2435                                         "%s: line %d: unknown directive \"%s\" outside backend "
2436                                         "info and database definitions (ignored).\n",
2437                                         fname, lineno, cargv[0] );
2438 #else
2439                                 Debug( LDAP_DEBUG_ANY,
2440 "%s: line %d: unknown directive \"%s\" outside backend info and database definitions (ignored)\n",
2441                                     fname, lineno, cargv[0] );
2442 #endif
2443
2444                         }
2445                 }
2446                 free( saveline );
2447         }
2448         fclose( fp );
2449
2450         if ( depth == 0 ) ch_free( cargv );
2451
2452         if ( !global_schemadn.bv_val ) {
2453                 ber_str2bv( SLAPD_SCHEMA_DN, sizeof(SLAPD_SCHEMA_DN)-1, 1,
2454                         &global_schemadn );
2455                 dnNormalize( 0, NULL, NULL, &global_schemadn, &global_schemandn, NULL );
2456         }
2457
2458         if ( load_ucdata( NULL ) < 0 ) return 1;
2459         return( 0 );
2460 }
2461
2462 static int
2463 fp_parse_line(
2464     int         lineno,
2465     char        *line
2466 )
2467 {
2468         char *  token;
2469         char *  logline;
2470         char    logbuf[sizeof("pseudorootpw ***")];
2471
2472         cargc = 0;
2473         token = strtok_quote( line, " \t" );
2474
2475         logline = line;
2476
2477         if ( token && ( strcasecmp( token, "rootpw" ) == 0 ||
2478                 strcasecmp( token, "replica" ) == 0 ||          /* contains "credentials" */
2479                 strcasecmp( token, "bindpw" ) == 0 ||           /* used in back-ldap */
2480                 strcasecmp( token, "pseudorootpw" ) == 0 ||     /* used in back-meta */
2481                 strcasecmp( token, "dbpasswd" ) == 0 ) )        /* used in back-sql */
2482         {
2483                 snprintf( logline = logbuf, sizeof logbuf, "%s ***", token );
2484         }
2485
2486         if ( strtok_quote_ptr ) {
2487                 *strtok_quote_ptr = ' ';
2488         }
2489
2490 #ifdef NEW_LOGGING
2491         LDAP_LOG( CONFIG, DETAIL1, "line %d (%s)\n", lineno, logline , 0 );
2492 #else
2493         Debug( LDAP_DEBUG_CONFIG, "line %d (%s)\n", lineno, logline, 0 );
2494 #endif
2495
2496         if ( strtok_quote_ptr ) {
2497                 *strtok_quote_ptr = '\0';
2498         }
2499
2500         for ( ; token != NULL; token = strtok_quote( NULL, " \t" ) ) {
2501                 if ( cargc == cargv_size - 1 ) {
2502                         char **tmp;
2503                         tmp = ch_realloc( cargv, (cargv_size + ARGS_STEP) *
2504                                             sizeof(*cargv) );
2505                         if ( tmp == NULL ) {
2506 #ifdef NEW_LOGGING
2507                                 LDAP_LOG( CONFIG, ERR, "line %d: out of memory\n", lineno, 0,0 );
2508 #else
2509                                 Debug( LDAP_DEBUG_ANY, 
2510                                                 "line %d: out of memory\n", 
2511                                                 lineno, 0, 0 );
2512 #endif
2513                                 return -1;
2514                         }
2515                         cargv = tmp;
2516                         cargv_size += ARGS_STEP;
2517                 }
2518                 cargv[cargc++] = token;
2519         }
2520         cargv[cargc] = NULL;
2521         return 0;
2522 }
2523
2524 static char *
2525 strtok_quote( char *line, char *sep )
2526 {
2527         int             inquote;
2528         char            *tmp;
2529         static char     *next;
2530
2531         strtok_quote_ptr = NULL;
2532         if ( line != NULL ) {
2533                 next = line;
2534         }
2535         while ( *next && strchr( sep, *next ) ) {
2536                 next++;
2537         }
2538
2539         if ( *next == '\0' ) {
2540                 next = NULL;
2541                 return( NULL );
2542         }
2543         tmp = next;
2544
2545         for ( inquote = 0; *next; ) {
2546                 switch ( *next ) {
2547                 case '"':
2548                         if ( inquote ) {
2549                                 inquote = 0;
2550                         } else {
2551                                 inquote = 1;
2552                         }
2553                         AC_MEMCPY( next, next + 1, strlen( next + 1 ) + 1 );
2554                         break;
2555
2556                 case '\\':
2557                         if ( next[1] )
2558                                 AC_MEMCPY( next,
2559                                             next + 1, strlen( next + 1 ) + 1 );
2560                         next++;         /* dont parse the escaped character */
2561                         break;
2562
2563                 default:
2564                         if ( ! inquote ) {
2565                                 if ( strchr( sep, *next ) != NULL ) {
2566                                         strtok_quote_ptr = next;
2567                                         *next++ = '\0';
2568                                         return( tmp );
2569                                 }
2570                         }
2571                         next++;
2572                         break;
2573                 }
2574         }
2575
2576         return( tmp );
2577 }
2578
2579 static char     buf[BUFSIZ];
2580 static char     *line;
2581 static size_t lmax, lcur;
2582
2583 #define CATLINE( buf ) \
2584         do { \
2585                 size_t len = strlen( buf ); \
2586                 while ( lcur + len + 1 > lmax ) { \
2587                         lmax += BUFSIZ; \
2588                         line = (char *) ch_realloc( line, lmax ); \
2589                 } \
2590                 strcpy( line + lcur, buf ); \
2591                 lcur += len; \
2592         } while( 0 )
2593
2594 static char *
2595 fp_getline( FILE *fp, int *lineno )
2596 {
2597         char            *p;
2598
2599         lcur = 0;
2600         CATLINE( buf );
2601         (*lineno)++;
2602
2603         /* hack attack - keeps us from having to keep a stack of bufs... */
2604         if ( strncasecmp( line, "include", 7 ) == 0 ) {
2605                 buf[0] = '\0';
2606                 return( line );
2607         }
2608
2609         while ( fgets( buf, sizeof(buf), fp ) != NULL ) {
2610                 /* trim off \r\n or \n */
2611                 if ( (p = strchr( buf, '\n' )) != NULL ) {
2612                         if( p > buf && p[-1] == '\r' ) --p;
2613                         *p = '\0';
2614                 }
2615                 
2616                 /* trim off trailing \ and append the next line */
2617                 if ( line[ 0 ] != '\0' 
2618                                 && (p = line + strlen( line ) - 1)[ 0 ] == '\\'
2619                                 && p[ -1 ] != '\\' ) {
2620                         p[ 0 ] = '\0';
2621                         lcur--;
2622
2623                 } else {
2624                         if ( ! isspace( (unsigned char) buf[0] ) ) {
2625                                 return( line );
2626                         }
2627
2628                         /* change leading whitespace to a space */
2629                         buf[0] = ' ';
2630                 }
2631
2632                 CATLINE( buf );
2633                 (*lineno)++;
2634         }
2635         buf[0] = '\0';
2636
2637         return( line[0] ? line : NULL );
2638 }
2639
2640 static void
2641 fp_getline_init( int *lineno )
2642 {
2643         *lineno = -1;
2644         buf[0] = '\0';
2645 }
2646
2647 /* Loads ucdata, returns 1 if loading, 0 if already loaded, -1 on error */
2648 static int
2649 load_ucdata( char *path )
2650 {
2651         static int loaded = 0;
2652         int err;
2653         
2654         if ( loaded ) {
2655                 return( 0 );
2656         }
2657         err = ucdata_load( path ? path : SLAPD_DEFAULT_UCDATA, UCDATA_ALL );
2658         if ( err ) {
2659 #ifdef NEW_LOGGING
2660                 LDAP_LOG( CONFIG, CRIT, 
2661                         "load_ucdata: Error %d loading ucdata.\n", err, 0,0 );
2662 #else
2663                 Debug( LDAP_DEBUG_ANY, "error loading ucdata (error %d)\n",
2664                        err, 0, 0 );
2665 #endif
2666
2667                 return( -1 );
2668         }
2669         loaded = 1;
2670         return( 1 );
2671 }
2672
2673 void
2674 config_destroy( )
2675 {
2676         ucdata_unload( UCDATA_ALL );
2677         free( global_schemandn.bv_val );
2678         free( global_schemadn.bv_val );
2679         free( line );
2680         if ( slapd_args_file )
2681                 free ( slapd_args_file );
2682         if ( slapd_pid_file )
2683                 free ( slapd_pid_file );
2684         if ( default_passwd_hash )
2685                 free( default_passwd_hash );
2686         acl_destroy( global_acl, NULL );
2687 }
2688
2689 #ifdef LDAP_SYNCREPL
2690 static void
2691 add_syncrepl(
2692         Backend *be,
2693         char    **cargv,
2694         int     cargc
2695 )
2696 {
2697         syncinfo_t *si;
2698
2699         si = be->syncinfo = (syncinfo_t *) ch_calloc( 1, sizeof( syncinfo_t ) );
2700
2701         if ( si == NULL ) {
2702 #ifdef NEW_LOGGING
2703                 LDAP_LOG( CONFIG, ERR, "out of memory in add_syncrepl\n", 0, 0,0 );
2704 #else
2705                 Debug( LDAP_DEBUG_ANY, "out of memory in add_syncrepl\n", 0, 0, 0 );
2706 #endif
2707                 exit( EXIT_FAILURE );
2708         }
2709
2710         if ( parse_syncrepl_line( cargv, cargc, si ) < 0 ) {
2711                 /* Something bad happened - back out */
2712 #ifdef NEW_LOGGING
2713                 LDAP_LOG( CONFIG, ERR, "failed to add syncinfo\n", 0, 0,0 );
2714 #else
2715                 Debug( LDAP_DEBUG_ANY, "failed to add syncinfo\n", 0, 0, 0 );
2716 #endif
2717                 free( si );
2718                 be->syncinfo = NULL;
2719         } else {
2720 #ifdef NEW_LOGGING
2721                 LDAP_LOG ( CONFIG, RESULTS,
2722                         "add_syncrepl: Config: ** successfully added syncrepl \"%s%d\"\n",
2723                         si->mastername == NULL ? "(null)" : si->mastername,
2724                         si->masterport, 0 );
2725 #else
2726                 Debug( LDAP_DEBUG_CONFIG,
2727                         "Config: ** successfully added syncrepl \"%s:%d\"\n",
2728                         si->mastername == NULL ? "(null)" : si->mastername,
2729                         si->masterport, 0 );
2730 #endif
2731                 si->be = be;
2732         }
2733 }
2734
2735 #define IDSTR           "id"
2736 #define PROVIDERSTR     "provider"
2737 #define SUFFIXSTR       "suffix"
2738 #define UPDATEDNSTR             "updatedn"
2739 #define BINDDNSTR       "binddn"
2740 #define BINDMETHSTR     "bindmethod"
2741 #define SIMPLESTR       "simple"
2742 #define SASLSTR         "sasl"
2743 #define CREDSTR         "credentials"
2744 #define OLDAUTHCSTR     "bindprincipal"
2745 #define AUTHCSTR        "authcID"
2746 #define AUTHZSTR        "authzID"
2747 #define SRVTABSTR       "srvtab"
2748 #define SASLMECHSTR     "saslmech"
2749 #define REALMSTR        "realm"
2750 #define SECPROPSSTR     "secprops"
2751 #define STARTTLSSTR     "starttls"
2752 #define CRITICALSTR     "critical"
2753
2754 #define FILTERSTR       "filter"
2755 #define SEARCHBASESTR   "searchbase"
2756 #define SCOPESTR        "scope"
2757 #define ATTRSSTR        "attrs"
2758 #define ATTRSONLYSTR    "attrsonly"
2759 #define TYPESTR         "type"
2760 #define INTERVALSTR     "interval"
2761 #define COOKIESTR       "cookie"
2762 #define LASTMODSTR      "lastmod"
2763 #define LMREQSTR        "req"
2764 #define LMGENSTR        "gen"
2765 #define LMNOSTR         "no"
2766
2767 #define GOT_ID                  0x0001
2768 #define GOT_HOST                0x0002
2769 #define GOT_DN                  0x0004
2770 #define GOT_METHOD              0x0008
2771 #define GOT_MECH                0x0010
2772 #define GOT_FILTER              0x0020
2773 #define GOT_SEARCHBASE  0x0040
2774 #define GOT_SCOPE               0x0080
2775 #define GOT_ATTRS               0x0100
2776 #define GOT_TYPE                0x0200
2777 #define GOT_INTERVAL    0x0400
2778 #define GOT_LASTMOD             0x0800
2779 #define GOT_UPDATEDN    0x1000
2780
2781 #define GOT_ALL                 0x1FFF
2782
2783 static int
2784 parse_syncrepl_line(
2785         char            **cargv,
2786         int             cargc,
2787         syncinfo_t      *si
2788 )
2789 {
2790         int     gots = 0;
2791         int     i, j;
2792         char    *hp, *val;
2793         int     nr_attr = 0;
2794
2795         for ( i = 1; i < cargc; i++ ) {
2796                 if ( !strncasecmp( cargv[ i ], IDSTR, sizeof( IDSTR ) - 1 )) {
2797                         /* '\0' string terminator accounts for '=' */
2798                         val = cargv[ i ] + sizeof( IDSTR );
2799                         si->id = atoi( val );
2800                         gots |= GOT_ID;
2801                 } else if ( !strncasecmp( cargv[ i ], PROVIDERSTR,
2802                                         sizeof( PROVIDERSTR ) - 1 )) {
2803                         val = cargv[ i ] + sizeof( PROVIDERSTR );
2804                         si->masteruri = ch_strdup( val );
2805                         if (( hp = strchr( val, ':' )) != NULL ) {
2806                                 if ( *( hp + 1 ) == '/' ) {
2807                                         if ( *( hp + 2 ) == '/' ) {
2808                                                 val = hp + 3;
2809                                         }
2810                                         if (( hp = strchr( hp+1, ':' )) != NULL ) {
2811                                                 *hp = '\0';
2812                                                 hp++;
2813                                                 si->masterport = atoi( hp );
2814                                         }
2815                                 } else {
2816                                         *hp = '\0';
2817                                         hp++;
2818                                         si->masterport = atoi( hp );
2819                                 }
2820                         }
2821                         if ( si->masterport <= 0 ) {
2822                                 si->masterport = 0;
2823                         }
2824                         si->mastername = ch_strdup( val );
2825                         si->master_bv = (BerVarray) ch_calloc( 2, sizeof (struct berval ));
2826                         ber_str2bv( si->masteruri, strlen(si->masteruri), 0,
2827                                                         &si->master_bv[0] );
2828                         si->master_bv[1].bv_len = 0;
2829                         si->master_bv[1].bv_val = NULL;
2830                         gots |= GOT_HOST;
2831                 } else if ( !strncasecmp( cargv[ i ], STARTTLSSTR,
2832                         sizeof(STARTTLSSTR) - 1 ) )
2833                 {
2834                         val = cargv[ i ] + sizeof( STARTTLSSTR );
2835                         if( !strcasecmp( val, CRITICALSTR ) ) {
2836                                 si->tls = TLS_CRITICAL;
2837                         } else {
2838                                 si->tls = TLS_ON;
2839                         }
2840                 } else if ( !strncasecmp( cargv[ i ],
2841                                 UPDATEDNSTR, sizeof( UPDATEDNSTR ) - 1 ) ) {
2842                         char *str;
2843                         struct berval updatedn = {0, NULL};
2844                         val = cargv[ i ] + sizeof( UPDATEDNSTR );
2845                         str = ch_strdup( val );
2846                         ber_str2bv( str, strlen(str), 1, &updatedn );
2847                         dnNormalize( 0, NULL, NULL, &updatedn, &si->updatedn, NULL );
2848                         ch_free( str );
2849                         ch_free( updatedn.bv_val );
2850                         gots |= GOT_UPDATEDN;
2851                 } else if ( !strncasecmp( cargv[ i ],
2852                                 BINDDNSTR, sizeof( BINDDNSTR ) - 1 ) ) {
2853                         val = cargv[ i ] + sizeof( BINDDNSTR );
2854                         si->binddn = ch_strdup( val );
2855                         gots |= GOT_DN;
2856                 } else if ( !strncasecmp( cargv[ i ], BINDMETHSTR,
2857                                 sizeof( BINDMETHSTR ) - 1 ) ) {
2858                         val = cargv[ i ] + sizeof( BINDMETHSTR );
2859                         if ( !strcasecmp( val, SIMPLESTR )) {
2860                                 si->bindmethod = LDAP_AUTH_SIMPLE;
2861                                 gots |= GOT_METHOD;
2862                         } else if ( !strcasecmp( val, SASLSTR )) {
2863                                 si->bindmethod = LDAP_AUTH_SASL;
2864                                 gots |= GOT_METHOD;
2865                         } else {
2866                                 si->bindmethod = -1;
2867                         }
2868                 } else if ( !strncasecmp( cargv[ i ], LASTMODSTR,
2869                                 sizeof( LASTMODSTR ) - 1 ) ) {
2870                         val = cargv[ i ] + sizeof( LASTMODSTR );
2871                         if ( !strcasecmp( val, LMREQSTR )) {
2872                                 si->lastmod = LASTMOD_REQ;
2873                                 gots |= GOT_LASTMOD;
2874                         } else if ( !strcasecmp( val, LMGENSTR )) {
2875                                 si->lastmod = LASTMOD_GEN;
2876                                 gots |= GOT_LASTMOD;
2877                         } else if ( !strcasecmp( val, LMNOSTR )) {
2878                                 si->lastmod = LASTMOD_NO;
2879                                 gots |= GOT_LASTMOD;
2880                         } else {
2881                                 si->lastmod = -1;
2882                         }
2883                 } else if ( !strncasecmp( cargv[ i ],
2884                                 SASLMECHSTR, sizeof( SASLMECHSTR ) - 1 ) ) {
2885                         val = cargv[ i ] + sizeof( SASLMECHSTR );
2886                         gots |= GOT_MECH;
2887                         si->saslmech = ch_strdup( val );
2888                 } else if ( !strncasecmp( cargv[ i ],
2889                                 CREDSTR, sizeof( CREDSTR ) - 1 ) ) {
2890                         val = cargv[ i ] + sizeof( CREDSTR );
2891                         si->passwd = ch_strdup( val );
2892                 } else if ( !strncasecmp( cargv[ i ],
2893                                 SECPROPSSTR, sizeof( SECPROPSSTR ) - 1 ) ) {
2894                         val = cargv[ i ] + sizeof( SECPROPSSTR );
2895                         si->secprops = ch_strdup( val );
2896                 } else if ( !strncasecmp( cargv[ i ],
2897                                 REALMSTR, sizeof( REALMSTR ) - 1 ) ) {
2898                         val = cargv[ i ] + sizeof( REALMSTR );
2899                         si->realm = ch_strdup( val );
2900                 } else if ( !strncasecmp( cargv[ i ],
2901                                 AUTHCSTR, sizeof( AUTHCSTR ) - 1 ) ) {
2902                         val = cargv[ i ] + sizeof( AUTHCSTR );
2903                         si->authcId = ch_strdup( val );
2904                 } else if ( !strncasecmp( cargv[ i ],
2905                                 OLDAUTHCSTR, sizeof( OLDAUTHCSTR ) - 1 ) ) {
2906                         /* Old authcID is provided for some backwards compatibility */
2907                         val = cargv[ i ] + sizeof( OLDAUTHCSTR );
2908                         si->authcId = ch_strdup( val );
2909                 } else if ( !strncasecmp( cargv[ i ],
2910                                 AUTHZSTR, sizeof( AUTHZSTR ) - 1 ) ) {
2911                         val = cargv[ i ] + sizeof( AUTHZSTR );
2912                         si->authzId = ch_strdup( val );
2913                 } else if ( !strncasecmp( cargv[ i ],
2914                                 SRVTABSTR, sizeof( SRVTABSTR ) - 1 ) ) {
2915                         val = cargv[ i ] + sizeof( SRVTABSTR );
2916                         if ( si->srvtab != NULL ) {
2917                                 free( si->srvtab );
2918                         }
2919                         si->srvtab = ch_strdup( val );
2920                 } else if ( !strncasecmp( cargv[ i ],
2921                                 FILTERSTR, sizeof( FILTERSTR ) - 1 ) ) {
2922                         val = cargv[ i ] + sizeof( FILTERSTR );
2923                         gots |= GOT_FILTER;
2924                         si->filterstr = ch_strdup( val );
2925                 } else if ( !strncasecmp( cargv[ i ],
2926                                 SEARCHBASESTR, sizeof( SEARCHBASESTR ) - 1 ) ) {
2927                         val = cargv[ i ] + sizeof( SEARCHBASESTR );
2928                         gots |= GOT_SEARCHBASE;
2929                         si->base = ch_strdup( val );
2930                 } else if ( !strncasecmp( cargv[ i ],
2931                                 SCOPESTR, sizeof( SCOPESTR ) - 1 ) ) {
2932                         val = cargv[ i ] + sizeof( SCOPESTR );
2933                         gots |= GOT_SCOPE;
2934                         if ( !strncasecmp( val, "base", sizeof( "base" ) - 1 )) {
2935                                 si->scope = LDAP_SCOPE_BASE;
2936                         } else if ( !strncasecmp( val, "one", sizeof( "one" ) - 1 )) {
2937                                 si->scope = LDAP_SCOPE_ONELEVEL;
2938                         } else if ( !strncasecmp( val, "sub", sizeof( "sub" ) - 1 )) {
2939                                 si->scope = LDAP_SCOPE_SUBTREE;
2940                         } else {
2941                                 fprintf( stderr, "Error: parse_syncrepl_line: "
2942                                                                  "unknown scope \"%s\"\n", val);
2943                                 return 1;
2944                         }
2945                 } else if ( !strncasecmp( cargv[ i ],
2946                                 ATTRSONLYSTR, sizeof( ATTRSONLYSTR ) - 1 ) ) {
2947                         si->attrsonly = 1;
2948                 } else if ( !strncasecmp( cargv[ i ],
2949                                 ATTRSSTR, sizeof( ATTRSSTR ) - 1 ) ) {
2950                         val = cargv[ i ] + sizeof( ATTRSSTR );
2951                         si->attrs = NULL;
2952                         si->attrs = str2clist( si->attrs, val, "," );
2953                         gots |= GOT_ATTRS;
2954                 } else if ( !strncasecmp( cargv[ i ],
2955                                 TYPESTR, sizeof( TYPESTR ) - 1 ) ) {
2956                         val = cargv[ i ] + sizeof( TYPESTR );
2957                         gots |= GOT_TYPE;
2958                         if ( !strncasecmp( val, "refreshOnly", sizeof( "refreshOnly" ) - 1 )) {
2959                                 si->type = LDAP_SYNC_REFRESH_ONLY;
2960                         } else if ( !strncasecmp( val, "refreshAndPersist", sizeof( "refreshAndPersist" ) - 1 )) {
2961                                 gots |= GOT_INTERVAL;
2962                                 si->type = LDAP_SYNC_REFRESH_AND_PERSIST;
2963                                 si->interval = 0;
2964                         } else {
2965                                 fprintf( stderr, "Error: parse_syncrepl_line: "
2966                                                                  "unknown sync type \"%s\"\n", val);
2967                                 return 1;
2968                         }
2969                 } else if ( !strncasecmp( cargv[ i ],
2970                                 INTERVALSTR, sizeof( INTERVALSTR ) - 1 ) ) {
2971                         val = cargv[ i ] + sizeof( INTERVALSTR );
2972                         gots |= GOT_INTERVAL;
2973                         if ( gots & GOT_TYPE && si->type == LDAP_SYNC_REFRESH_AND_PERSIST )
2974                                 si->interval = 0;
2975                         else
2976                                 si->interval = atoi( val );
2977                         if ( si->interval < 0 ) {
2978                                 fprintf( stderr, "Error: parse_syncrepl_line: "
2979                                                                  "invalid interval \"%ld\"\n",
2980                                                                  (long) si->interval);
2981                                 return 1;
2982                         }
2983                 } else if ( !strncasecmp( cargv[ i ],
2984                                 COOKIESTR, sizeof( COOKIESTR ) - 1 ) ) {
2985                         val = cargv[ i ] + sizeof( COOKIESTR );
2986                         si->syncCookie = ber_str2bv( val, strlen( val ), 1, NULL );
2987                 } else {
2988                         fprintf( stderr, "Error: parse_syncrepl_line: "
2989                                                          "unknown keyword \"%s\"\n", cargv[ i ] );
2990                 }
2991         }
2992
2993         if ( si->bindmethod == LDAP_AUTH_SASL) {
2994                 if ((gots & GOT_MECH) == 0) {
2995                         fprintf( stderr, "Error: \"syncrepl\" line needs SASLmech flag " 
2996                                          "in slapd config file\n" );
2997                         return -1;
2998                 }
2999         }
3000
3001         gots |= GOT_MECH;
3002
3003         if ( gots != GOT_ALL ) {
3004                 fprintf( stderr, "Error: Malformed \"syncrepl\" line in slapd config file"
3005  );
3006                 return -1;
3007         }
3008
3009         return 0;
3010 }
3011 #endif /* LDAP_SYNCREPL */