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