]> git.sur5r.net Git - openldap/blob - servers/slapd/config.c
allow optional overlays
[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_X_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_X_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                                         lim->lms_s_hard = 0;
847                                 }
848                         }
849
850                 /* set time limit */
851                 } else if ( strcasecmp( cargv[0], "timelimit" ) == 0 ) {
852                         int rc = 0, i;
853                         struct slap_limits_set *lim;
854                         
855                         if ( cargc < 2 ) {
856 #ifdef NEW_LOGGING
857                                 LDAP_LOG( CONFIG, CRIT, 
858                                         "%s: line %d missing limit in \"timelimit <limit>\" "
859                                         "line.\n", fname, lineno, 0 );
860 #else
861                                 Debug( LDAP_DEBUG_ANY,
862             "%s: line %d: missing limit in \"timelimit <limit>\" line\n",
863                                     fname, lineno, 0 );
864 #endif
865
866                                 return( 1 );
867                         }
868                         
869                         if ( be == NULL ) {
870                                 lim = &deflimit;
871                         } else {
872                                 lim = &be->be_def_limit;
873                         }
874
875                         for ( i = 1; i < cargc; i++ ) {
876                                 if ( strncasecmp( cargv[i], "time", 4 ) == 0 ) {
877                                         rc = limits_parse_one( cargv[i], lim );
878                                         if ( rc ) {
879 #ifdef NEW_LOGGING
880                                                 LDAP_LOG( CONFIG, CRIT, 
881                                                             "%s: line %d: unable to parse value \"%s\" "
882                                                            "in \"timelimit <limit>\" line.\n",
883                                                            fname, lineno, cargv[i] );
884 #else
885                                                 Debug( LDAP_DEBUG_ANY,
886                                                         "%s: line %d: unable "
887                                                         "to parse value \"%s\" "
888                                                         "in \"timelimit "
889                                                         "<limit>\" line\n",
890                                                         fname, lineno, cargv[i] );
891 #endif
892                                                 return( 1 );
893                                         }
894
895                                 } else {
896                                         if ( strcasecmp( cargv[i], "unlimited" ) == 0 ) {
897                                                 lim->lms_t_soft = -1;
898                                         } else {
899                                                 char *next;
900
901                                                 lim->lms_t_soft = strtol( cargv[i] , &next, 0 );
902                                                 if ( next == cargv[i] ) {
903 #ifdef NEW_LOGGING
904                                                         LDAP_LOG( CONFIG, CRIT, 
905                                                            "%s: line %d: unable to parse limit \"%s\" in \"timelimit <limit>\" "
906                                                            "line.\n", fname, lineno, cargv[i] );
907 #else
908                                                         Debug( LDAP_DEBUG_ANY,
909                                                             "%s: line %d: unable to parse limit \"%s\" in \"timelimit <limit>\" line\n",
910                                                             fname, lineno, cargv[i] );
911 #endif
912                                                         return( 1 );
913
914                                                 } else if ( next[0] != '\0' ) {
915 #ifdef NEW_LOGGING
916                                                         LDAP_LOG( CONFIG, CRIT, 
917                                                            "%s: line %d: trailing chars \"%s\" in \"timelimit <limit>\" "
918                                                            "line ignored.\n", fname, lineno, next );
919 #else
920                                                         Debug( LDAP_DEBUG_ANY,
921                                                             "%s: line %d: trailing chars \"%s\" in \"timelimit <limit>\" line ignored\n",
922                                                             fname, lineno, next );
923 #endif
924                                                 }
925                                         }
926                                         lim->lms_t_hard = 0;
927                                 }
928                         }
929
930                 /* set regex-based limits */
931                 } else if ( strcasecmp( cargv[0], "limits" ) == 0 ) {
932                         if ( be == NULL ) {
933 #ifdef NEW_LOGGING
934                                 LDAP_LOG( CONFIG, WARNING, 
935                                            "%s: line %d \"limits\" allowed only in database "
936                                            "environment.\n", fname, lineno, 0 );
937 #else
938                                 Debug( LDAP_DEBUG_ANY,
939         "%s: line %d \"limits\" allowed only in database environment.\n%s",
940                                         fname, lineno, "" );
941 #endif
942                                 return( 1 );
943                         }
944
945                         if ( limits_parse( be, fname, lineno, cargc, cargv ) ) {
946                                 return( 1 );
947                         }
948
949                 /* mark this as a subordinate database */
950                 } else if ( strcasecmp( cargv[0], "subordinate" ) == 0 ) {
951                         if ( be == NULL ) {
952 #ifdef NEW_LOGGING
953                                 LDAP_LOG( CONFIG, INFO, "%s: line %d: "
954                                         "subordinate keyword must appear inside a database "
955                                         "definition.\n", fname, lineno, 0 );
956 #else
957                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: subordinate keyword "
958                                         "must appear inside a database definition.\n",
959                                     fname, lineno, 0 );
960 #endif
961                                 return 1;
962
963                         } else {
964                                 SLAP_DBFLAGS(be) |= SLAP_DBFLAG_GLUE_SUBORDINATE;
965                                 num_subordinates++;
966                         }
967
968                 /* add an overlay to this backend */
969                 } else if ( strcasecmp( cargv[0], "overlay" ) == 0 ) {
970                         if ( be == NULL ) {
971 #ifdef NEW_LOGGING
972                                 LDAP_LOG( CONFIG, INFO, "%s: line %d: "
973                                         "overlay keyword must appear inside a database "
974                                         "definition.\n", fname, lineno, 0 );
975 #else
976                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: overlay keyword "
977                                         "must appear inside a database definition.\n",
978                                     fname, lineno, 0 );
979 #endif
980                                 return 1;
981
982                         } else {
983                                 if ( cargv[1][0] == '-' && overlay_config( be, &cargv[1][1] ) ) {
984                                         /* log error */
985 #ifdef NEW_LOGGING
986                                         LDAP_LOG( CONFIG, INFO, "%s: line %d: "
987                                                 "(optional) overlay \"%s\" configuration "
988                                                 "failed (ignored)\n", fname, lineno, &cargv[1][1] );
989 #else
990                                         Debug( LDAP_DEBUG_ANY, "%s: line %d: "
991                                                 "(optional) overlay \"%s\" configuration "
992                                                 "failed (ignored)\n", fname, lineno, &cargv[1][1] );
993 #endif
994                                 } else if ( overlay_config( be, cargv[1] ) ) {
995                                         return 1;
996                                 }
997                         }
998
999                 /* set database suffix */
1000                 } else if ( strcasecmp( cargv[0], "suffix" ) == 0 ) {
1001                         Backend *tmp_be;
1002                         struct berval dn, pdn, ndn;
1003
1004                         if ( cargc < 2 ) {
1005 #ifdef NEW_LOGGING
1006                                 LDAP_LOG( CONFIG, CRIT, 
1007                                         "%s: line %d: missing dn in \"suffix <dn>\" line.\n",
1008                                         fname, lineno, 0 );
1009 #else
1010                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1011                                         "missing dn in \"suffix <dn>\" line\n",
1012                                     fname, lineno, 0 );
1013 #endif
1014
1015                                 return( 1 );
1016
1017                         } else if ( cargc > 2 ) {
1018 #ifdef NEW_LOGGING
1019                                 LDAP_LOG( CONFIG, INFO, 
1020                                         "%s: line %d: extra cruft after <dn> in \"suffix %s\""
1021                                         " line (ignored).\n", fname, lineno, cargv[1] );
1022 #else
1023                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: extra cruft "
1024                                         "after <dn> in \"suffix %s\" line (ignored)\n",
1025                                     fname, lineno, cargv[1] );
1026 #endif
1027                         }
1028
1029                         if ( be == NULL ) {
1030 #ifdef NEW_LOGGING
1031                                 LDAP_LOG( CONFIG, INFO, 
1032                                         "%s: line %d: suffix line must appear inside a database "
1033                                         "definition.\n", fname, lineno, 0 );
1034 #else
1035                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: suffix line "
1036                                         "must appear inside a database definition\n",
1037                                     fname, lineno, 0 );
1038 #endif
1039                                 return( 1 );
1040
1041 #if defined(SLAPD_MONITOR_DN)
1042                         /* "cn=Monitor" is reserved for monitoring slap */
1043                         } else if ( strcasecmp( cargv[1], SLAPD_MONITOR_DN ) == 0 ) {
1044 #ifdef NEW_LOGGING
1045                                 LDAP_LOG( CONFIG, CRIT, "%s: line %d: \""
1046                                         "%s\" is reserved for monitoring slapd\n", 
1047                                         fname, lineno, SLAPD_MONITOR_DN );
1048 #else
1049                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: \""
1050                                         "%s\" is reserved for monitoring slapd\n", 
1051                                         fname, lineno, SLAPD_MONITOR_DN );
1052 #endif
1053                                 return( 1 );
1054 #endif /* SLAPD_MONITOR_DN */
1055                         }
1056
1057                         if ( load_ucdata( NULL ) < 0 ) return 1;
1058
1059                         dn.bv_val = cargv[1];
1060                         dn.bv_len = strlen( cargv[1] );
1061
1062                         rc = dnPrettyNormal( NULL, &dn, &pdn, &ndn, NULL );
1063                         if( rc != LDAP_SUCCESS ) {
1064 #ifdef NEW_LOGGING
1065                                 LDAP_LOG( CONFIG, CRIT, 
1066                                         "%s: line %d: suffix DN is invalid.\n",
1067                                         fname, lineno, 0 );
1068 #else
1069                                 Debug( LDAP_DEBUG_ANY,
1070                                         "%s: line %d: suffix DN is invalid\n",
1071                                    fname, lineno, 0 );
1072 #endif
1073                                 return( 1 );
1074                         }
1075
1076                         tmp_be = select_backend( &ndn, 0, 0 );
1077                         if ( tmp_be == be ) {
1078 #ifdef NEW_LOGGING
1079                                 LDAP_LOG( CONFIG, INFO, 
1080                                         "%s: line %d: suffix already served by this backend "
1081                                         "(ignored)\n", fname, lineno, 0 );
1082 #else
1083                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: suffix "
1084                                         "already served by this backend (ignored)\n",
1085                                     fname, lineno, 0 );
1086 #endif
1087                                 free( pdn.bv_val );
1088                                 free( ndn.bv_val );
1089
1090                         } else if ( tmp_be  != NULL ) {
1091 #ifdef NEW_LOGGING
1092                                 LDAP_LOG( CONFIG, INFO, 
1093                                         "%s: line %d: suffix already served by a preceding "
1094                                         "backend \"%s\"\n", fname, lineno,
1095                                         tmp_be->be_suffix[0].bv_val );
1096 #else
1097                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: suffix "
1098                                         "already served by a preceeding backend \"%s\"\n",
1099                                     fname, lineno, tmp_be->be_suffix[0].bv_val );
1100 #endif
1101                                 free( pdn.bv_val );
1102                                 free( ndn.bv_val );
1103                                 return( 1 );
1104
1105                         } else if( pdn.bv_len == 0 && default_search_nbase.bv_len ) {
1106 #ifdef NEW_LOGGING
1107                                         LDAP_LOG( CONFIG, INFO, 
1108                                                 "%s: line %d: suffix DN empty and default search "
1109                                                 "base provided \"%s\" (assuming okay).\n",
1110                                                 fname, lineno, default_search_base.bv_val );
1111 #else
1112                                         Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1113                                                 "suffix DN empty and default "
1114                                                 "search base provided \"%s\" (assuming okay)\n",
1115                                         fname, lineno, default_search_base.bv_val );
1116 #endif
1117                         }
1118
1119                         ber_bvarray_add( &be->be_suffix, &pdn );
1120                         ber_bvarray_add( &be->be_nsuffix, &ndn );
1121
1122                /* set max deref depth */
1123                } else if ( strcasecmp( cargv[0], "maxDerefDepth" ) == 0 ) {
1124                                         int i;
1125                        if ( cargc < 2 ) {
1126 #ifdef NEW_LOGGING
1127                                LDAP_LOG( CONFIG, CRIT, 
1128                                           "%s: line %d: missing depth in \"maxDerefDepth <depth>\""
1129                                           " line\n", fname, lineno, 0 );
1130 #else
1131                                Debug( LDAP_DEBUG_ANY,
1132                    "%s: line %d: missing depth in \"maxDerefDepth <depth>\" line\n",
1133                                    fname, lineno, 0 );
1134 #endif
1135
1136                                return( 1 );
1137                        }
1138                        if ( be == NULL ) {
1139 #ifdef NEW_LOGGING
1140                                LDAP_LOG( CONFIG, INFO, 
1141                                           "%s: line %d: depth line must appear inside a database "
1142                                           "definition.\n", fname, lineno ,0 );
1143 #else
1144                                Debug( LDAP_DEBUG_ANY,
1145 "%s: line %d: depth line must appear inside a database definition.\n",
1146                                    fname, lineno, 0 );
1147 #endif
1148                                                         return 1;
1149
1150                        } else if ((i = atoi(cargv[1])) < 0) {
1151 #ifdef NEW_LOGGING
1152                                LDAP_LOG( CONFIG, INFO, 
1153                                           "%s: line %d: depth must be positive.\n",
1154                                           fname, lineno ,0 );
1155 #else
1156                                Debug( LDAP_DEBUG_ANY,
1157 "%s: line %d: depth must be positive.\n",
1158                                    fname, lineno, 0 );
1159 #endif
1160                                                         return 1;
1161
1162
1163                        } else {
1164                            be->be_max_deref_depth = i;
1165                                            }
1166
1167
1168                 /* set magic "root" dn for this database */
1169                 } else if ( strcasecmp( cargv[0], "rootdn" ) == 0 ) {
1170                         if ( cargc < 2 ) {
1171 #ifdef NEW_LOGGING
1172                                 LDAP_LOG( CONFIG, INFO, 
1173                                            "%s: line %d: missing dn in \"rootdn <dn>\" line.\n",
1174                                            fname, lineno ,0 );
1175 #else
1176                                 Debug( LDAP_DEBUG_ANY,
1177                     "%s: line %d: missing dn in \"rootdn <dn>\" line\n",
1178                                     fname, lineno, 0 );
1179 #endif
1180
1181                                 return( 1 );
1182                         }
1183
1184                         if ( be == NULL ) {
1185 #ifdef NEW_LOGGING
1186                                 LDAP_LOG( CONFIG, INFO, 
1187                                            "%s: line %d: rootdn line must appear inside a database "
1188                                            "definition.\n", fname, lineno ,0 );
1189 #else
1190                                 Debug( LDAP_DEBUG_ANY,
1191 "%s: line %d: rootdn line must appear inside a database definition.\n",
1192                                     fname, lineno, 0 );
1193 #endif
1194                                 return 1;
1195
1196                         } else {
1197                                 struct berval dn;
1198                                 
1199                                 if ( load_ucdata( NULL ) < 0 ) return 1;
1200
1201                                 dn.bv_val = cargv[1];
1202                                 dn.bv_len = strlen( cargv[1] );
1203
1204                                 rc = dnPrettyNormal( NULL, &dn,
1205                                         &be->be_rootdn,
1206                                         &be->be_rootndn, NULL );
1207
1208                                 if( rc != LDAP_SUCCESS ) {
1209 #ifdef NEW_LOGGING
1210                                         LDAP_LOG( CONFIG, CRIT, 
1211                                                 "%s: line %d: rootdn DN is invalid.\n", 
1212                                                 fname, lineno ,0 );
1213 #else
1214                                         Debug( LDAP_DEBUG_ANY,
1215                                                 "%s: line %d: rootdn DN is invalid\n",
1216                                            fname, lineno, 0 );
1217 #endif
1218                                         return( 1 );
1219                                 }
1220                         }
1221
1222                 /* set super-secret magic database password */
1223                 } else if ( strcasecmp( cargv[0], "rootpw" ) == 0 ) {
1224                         if ( cargc < 2 ) {
1225 #ifdef NEW_LOGGING
1226                                 LDAP_LOG( CONFIG, CRIT, 
1227                                         "%s: line %d: missing passwd in \"rootpw <passwd>\""
1228                                         " line\n", fname, lineno ,0 );
1229 #else
1230                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1231                                         "missing passwd in \"rootpw <passwd>\" line\n",
1232                                     fname, lineno, 0 );
1233 #endif
1234
1235                                 return( 1 );
1236                         }
1237
1238                         if ( be == NULL ) {
1239 #ifdef NEW_LOGGING
1240                                 LDAP_LOG( CONFIG, INFO, "%s: line %d: "
1241                                         "rootpw line must appear inside a database "
1242                                         "definition.\n", fname, lineno ,0 );
1243 #else
1244                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1245                                         "rootpw line must appear inside a database "
1246                                         "definition.\n",
1247                                     fname, lineno, 0 );
1248 #endif
1249                                 return 1;
1250
1251                         } else {
1252                                 Backend *tmp_be = select_backend( &be->be_rootndn, 0, 0 );
1253
1254                                 if( tmp_be != be ) {
1255 #ifdef NEW_LOGGING
1256                                         LDAP_LOG( CONFIG, INFO,
1257                                                 "%s: line %d: "
1258                                                 "rootpw can only be set when rootdn is under suffix\n",
1259                                                 fname, lineno, "" );
1260 #else
1261                                         Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1262                                                 "rootpw can only be set when rootdn is under suffix\n",
1263                                         fname, lineno, 0 );
1264 #endif
1265                                         return 1;
1266                                 }
1267
1268                                 be->be_rootpw.bv_val = ch_strdup( cargv[1] );
1269                                 be->be_rootpw.bv_len = strlen( be->be_rootpw.bv_val );
1270                         }
1271
1272                 /* make this database read-only */
1273                 } else if ( strcasecmp( cargv[0], "readonly" ) == 0 ) {
1274                         if ( cargc < 2 ) {
1275 #ifdef NEW_LOGGING
1276                                 LDAP_LOG( CONFIG, CRIT, 
1277                                         "%s: line %d: missing on|off in \"readonly <on|off>\" "
1278                                         "line.\n", fname, lineno ,0 );
1279 #else
1280                                 Debug( LDAP_DEBUG_ANY,
1281             "%s: line %d: missing on|off in \"readonly <on|off>\" line\n",
1282                                     fname, lineno, 0 );
1283 #endif
1284
1285                                 return( 1 );
1286                         }
1287                         if ( be == NULL ) {
1288                                 if ( strcasecmp( cargv[1], "on" ) == 0 ) {
1289                                         global_restrictops |= SLAP_RESTRICT_OP_WRITES;
1290                                 } else {
1291                                         global_restrictops &= ~SLAP_RESTRICT_OP_WRITES;
1292                                 }
1293                         } else {
1294                                 if ( strcasecmp( cargv[1], "on" ) == 0 ) {
1295                                         be->be_restrictops |= SLAP_RESTRICT_OP_WRITES;
1296                                 } else {
1297                                         be->be_restrictops &= ~SLAP_RESTRICT_OP_WRITES;
1298                                 }
1299                         }
1300
1301
1302                 /* allow these features */
1303                 } else if ( strcasecmp( cargv[0], "allows" ) == 0 ||
1304                         strcasecmp( cargv[0], "allow" ) == 0 )
1305                 {
1306                         slap_mask_t     allows;
1307
1308                         if ( be != NULL ) {
1309 #ifdef NEW_LOGGING
1310                                 LDAP_LOG( CONFIG, INFO, 
1311                                            "%s: line %d: allow line must appear prior to "
1312                                            "database definitions.\n", fname, lineno ,0 );
1313 #else
1314                                 Debug( LDAP_DEBUG_ANY,
1315 "%s: line %d: allow line must appear prior to database definitions\n",
1316                                     fname, lineno, 0 );
1317 #endif
1318
1319                         }
1320
1321                         if ( cargc < 2 ) {
1322 #ifdef NEW_LOGGING
1323                                 LDAP_LOG( CONFIG, CRIT, 
1324                                            "%s: line %d: missing feature(s) in \"allow <features>\""
1325                                            " line\n", fname, lineno ,0 );
1326 #else
1327                                 Debug( LDAP_DEBUG_ANY,
1328             "%s: line %d: missing feature(s) in \"allow <features>\" line\n",
1329                                     fname, lineno, 0 );
1330 #endif
1331
1332                                 return( 1 );
1333                         }
1334
1335                         allows = 0;
1336
1337                         for( i=1; i < cargc; i++ ) {
1338                                 if( strcasecmp( cargv[i], "bind_v2" ) == 0 ) {
1339                                         allows |= SLAP_ALLOW_BIND_V2;
1340
1341                                 } else if( strcasecmp( cargv[i], "bind_anon_cred" ) == 0 ) {
1342                                         allows |= SLAP_ALLOW_BIND_ANON_CRED;
1343
1344                                 } else if( strcasecmp( cargv[i], "bind_anon_dn" ) == 0 ) {
1345                                         allows |= SLAP_ALLOW_BIND_ANON_DN;
1346
1347                                 } else if( strcasecmp( cargv[i], "update_anon" ) == 0 ) {
1348                                         allows |= SLAP_ALLOW_UPDATE_ANON;
1349
1350                                 } else if( strcasecmp( cargv[i], "none" ) != 0 ) {
1351 #ifdef NEW_LOGGING
1352                                         LDAP_LOG( CONFIG, CRIT, "%s: line %d: "
1353                                                 "unknown feature %s in \"allow <features>\" line.\n",
1354                                                 fname, lineno, cargv[1] );
1355 #else
1356                                         Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1357                                                 "unknown feature %s in \"allow <features>\" line\n",
1358                                                 fname, lineno, cargv[i] );
1359 #endif
1360
1361                                         return( 1 );
1362                                 }
1363                         }
1364
1365                         global_allows = allows;
1366
1367                 /* disallow these features */
1368                 } else if ( strcasecmp( cargv[0], "disallows" ) == 0 ||
1369                         strcasecmp( cargv[0], "disallow" ) == 0 )
1370                 {
1371                         slap_mask_t     disallows;
1372
1373                         if ( be != NULL ) {
1374 #ifdef NEW_LOGGING
1375                                 LDAP_LOG( CONFIG, INFO, 
1376                                            "%s: line %d: disallow line must appear prior to "
1377                                            "database definitions.\n", fname, lineno ,0 );
1378 #else
1379                                 Debug( LDAP_DEBUG_ANY,
1380 "%s: line %d: disallow line must appear prior to database definitions\n",
1381                                     fname, lineno, 0 );
1382 #endif
1383
1384                         }
1385
1386                         if ( cargc < 2 ) {
1387 #ifdef NEW_LOGGING
1388                                 LDAP_LOG( CONFIG, CRIT, 
1389                                         "%s: line %d: missing feature(s) in \"disallow <features>\""
1390                                         " line.\n", fname, lineno ,0 );
1391 #else
1392                                 Debug( LDAP_DEBUG_ANY,
1393             "%s: line %d: missing feature(s) in \"disallow <features>\" line\n",
1394                                     fname, lineno, 0 );
1395 #endif
1396
1397                                 return( 1 );
1398                         }
1399
1400                         disallows = 0;
1401
1402                         for( i=1; i < cargc; i++ ) {
1403                                 if( strcasecmp( cargv[i], "bind_anon" ) == 0 ) {
1404                                         disallows |= SLAP_DISALLOW_BIND_ANON;
1405
1406                                 } else if( strcasecmp( cargv[i], "bind_simple" ) == 0 ) {
1407                                         disallows |= SLAP_DISALLOW_BIND_SIMPLE;
1408
1409                                 } else if( strcasecmp( cargv[i], "bind_krbv4" ) == 0 ) {
1410                                         disallows |= SLAP_DISALLOW_BIND_KRBV4;
1411
1412                                 } else if( strcasecmp( cargv[i], "tls_2_anon" ) == 0 ) {
1413                                         disallows |= SLAP_DISALLOW_TLS_2_ANON;
1414
1415                                 } else if( strcasecmp( cargv[i], "tls_authc" ) == 0 ) {
1416                                         disallows |= SLAP_DISALLOW_TLS_AUTHC;
1417
1418                                 } else if( strcasecmp( cargv[i], "none" ) != 0 ) {
1419 #ifdef NEW_LOGGING
1420                                         LDAP_LOG( CONFIG, CRIT, 
1421                                                 "%s: line %d: unknown feature %s in "
1422                                                 "\"disallow <features>\" line.\n",
1423                                                 fname, lineno, cargv[i] );
1424 #else
1425                                         Debug( LDAP_DEBUG_ANY,
1426                     "%s: line %d: unknown feature %s in \"disallow <features>\" line\n",
1427                                             fname, lineno, cargv[i] );
1428 #endif
1429
1430                                         return( 1 );
1431                                 }
1432                         }
1433
1434                         global_disallows = disallows;
1435
1436                 /* require these features */
1437                 } else if ( strcasecmp( cargv[0], "requires" ) == 0 ||
1438                         strcasecmp( cargv[0], "require" ) == 0 )
1439                 {
1440                         slap_mask_t     requires;
1441
1442                         if ( cargc < 2 ) {
1443 #ifdef NEW_LOGGING
1444                                 LDAP_LOG( CONFIG, CRIT, 
1445                                            "%s: line %d: missing feature(s) in "
1446                                            "\"require <features>\" line.\n", fname, lineno ,0 );
1447 #else
1448                                 Debug( LDAP_DEBUG_ANY,
1449             "%s: line %d: missing feature(s) in \"require <features>\" line\n",
1450                                     fname, lineno, 0 );
1451 #endif
1452
1453                                 return( 1 );
1454                         }
1455
1456                         requires = 0;
1457
1458                         for( i=1; i < cargc; i++ ) {
1459                                 if( strcasecmp( cargv[i], "bind" ) == 0 ) {
1460                                         requires |= SLAP_REQUIRE_BIND;
1461
1462                                 } else if( strcasecmp( cargv[i], "LDAPv3" ) == 0 ) {
1463                                         requires |= SLAP_REQUIRE_LDAP_V3;
1464
1465                                 } else if( strcasecmp( cargv[i], "authc" ) == 0 ) {
1466                                         requires |= SLAP_REQUIRE_AUTHC;
1467
1468                                 } else if( strcasecmp( cargv[i], "SASL" ) == 0 ) {
1469                                         requires |= SLAP_REQUIRE_SASL;
1470
1471                                 } else if( strcasecmp( cargv[i], "strong" ) == 0 ) {
1472                                         requires |= SLAP_REQUIRE_STRONG;
1473
1474                                 } else if( strcasecmp( cargv[i], "none" ) != 0 ) {
1475 #ifdef NEW_LOGGING
1476                                         LDAP_LOG( CONFIG, CRIT, 
1477                                                    "%s: line %d: unknown feature %s in "
1478                                                    "\"require <features>\" line.\n", 
1479                                                    fname, lineno , cargv[i] );
1480 #else
1481                                         Debug( LDAP_DEBUG_ANY,
1482                     "%s: line %d: unknown feature %s in \"require <features>\" line\n",
1483                                             fname, lineno, cargv[i] );
1484 #endif
1485
1486                                         return( 1 );
1487                                 }
1488                         }
1489
1490                         if ( be == NULL ) {
1491                                 global_requires = requires;
1492                         } else {
1493                                 be->be_requires = requires;
1494                         }
1495
1496                 /* required security factors */
1497                 } else if ( strcasecmp( cargv[0], "security" ) == 0 ) {
1498                         slap_ssf_set_t *set;
1499
1500                         if ( cargc < 2 ) {
1501 #ifdef NEW_LOGGING
1502                                 LDAP_LOG( CONFIG, CRIT, 
1503                                         "%s: line %d: missing factor(s) in \"security <factors>\""
1504                                         " line.\n", fname, lineno ,0 );
1505 #else
1506                                 Debug( LDAP_DEBUG_ANY,
1507             "%s: line %d: missing factor(s) in \"security <factors>\" line\n",
1508                                     fname, lineno, 0 );
1509 #endif
1510
1511                                 return( 1 );
1512                         }
1513
1514                         if ( be == NULL ) {
1515                                 set = &global_ssf_set;
1516                         } else {
1517                                 set = &be->be_ssf_set;
1518                         }
1519
1520                         for( i=1; i < cargc; i++ ) {
1521                                 if( strncasecmp( cargv[i], "ssf=",
1522                                         sizeof("ssf") ) == 0 )
1523                                 {
1524                                         set->sss_ssf =
1525                                                 atoi( &cargv[i][sizeof("ssf")] );
1526
1527                                 } else if( strncasecmp( cargv[i], "transport=",
1528                                         sizeof("transport") ) == 0 )
1529                                 {
1530                                         set->sss_transport =
1531                                                 atoi( &cargv[i][sizeof("transport")] );
1532
1533                                 } else if( strncasecmp( cargv[i], "tls=",
1534                                         sizeof("tls") ) == 0 )
1535                                 {
1536                                         set->sss_tls =
1537                                                 atoi( &cargv[i][sizeof("tls")] );
1538
1539                                 } else if( strncasecmp( cargv[i], "sasl=",
1540                                         sizeof("sasl") ) == 0 )
1541                                 {
1542                                         set->sss_sasl =
1543                                                 atoi( &cargv[i][sizeof("sasl")] );
1544
1545                                 } else if( strncasecmp( cargv[i], "update_ssf=",
1546                                         sizeof("update_ssf") ) == 0 )
1547                                 {
1548                                         set->sss_update_ssf =
1549                                                 atoi( &cargv[i][sizeof("update_ssf")] );
1550
1551                                 } else if( strncasecmp( cargv[i], "update_transport=",
1552                                         sizeof("update_transport") ) == 0 )
1553                                 {
1554                                         set->sss_update_transport =
1555                                                 atoi( &cargv[i][sizeof("update_transport")] );
1556
1557                                 } else if( strncasecmp( cargv[i], "update_tls=",
1558                                         sizeof("update_tls") ) == 0 )
1559                                 {
1560                                         set->sss_update_tls =
1561                                                 atoi( &cargv[i][sizeof("update_tls")] );
1562
1563                                 } else if( strncasecmp( cargv[i], "update_sasl=",
1564                                         sizeof("update_sasl") ) == 0 )
1565                                 {
1566                                         set->sss_update_sasl =
1567                                                 atoi( &cargv[i][sizeof("update_sasl")] );
1568
1569                                 } else if( strncasecmp( cargv[i], "simple_bind=",
1570                                         sizeof("simple_bind") ) == 0 )
1571                                 {
1572                                         set->sss_simple_bind =
1573                                                 atoi( &cargv[i][sizeof("simple_bind")] );
1574
1575                                 } else {
1576 #ifdef NEW_LOGGING
1577                                         LDAP_LOG( CONFIG, CRIT, 
1578                                                    "%s: line %d: unknown factor %S in "
1579                                                    "\"security <factors>\" line.\n",
1580                                                    fname, lineno, cargv[1] );
1581 #else
1582                                         Debug( LDAP_DEBUG_ANY,
1583                     "%s: line %d: unknown factor %s in \"security <factors>\" line\n",
1584                                             fname, lineno, cargv[i] );
1585 #endif
1586
1587                                         return( 1 );
1588                                 }
1589                         }
1590                 /* where to send clients when we don't hold it */
1591                 } else if ( strcasecmp( cargv[0], "referral" ) == 0 ) {
1592                         if ( cargc < 2 ) {
1593 #ifdef NEW_LOGGING
1594                                 LDAP_LOG( CONFIG, CRIT, 
1595                                         "%s: line %d: missing URL in \"referral <URL>\""
1596                                         " line.\n", fname, lineno , 0 );
1597 #else
1598                                 Debug( LDAP_DEBUG_ANY,
1599                     "%s: line %d: missing URL in \"referral <URL>\" line\n",
1600                                     fname, lineno, 0 );
1601 #endif
1602
1603                                 return( 1 );
1604                         }
1605
1606                         if( validate_global_referral( cargv[1] ) ) {
1607 #ifdef NEW_LOGGING
1608                                 LDAP_LOG( CONFIG, CRIT, 
1609                                         "%s: line %d: invalid URL (%s) in \"referral\" line.\n",
1610                                         fname, lineno, cargv[1]  );
1611 #else
1612                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1613                                         "invalid URL (%s) in \"referral\" line.\n",
1614                                     fname, lineno, cargv[1] );
1615 #endif
1616                                 return 1;
1617                         }
1618
1619                         vals[0].bv_val = cargv[1];
1620                         vals[0].bv_len = strlen( vals[0].bv_val );
1621                         if( value_add( &default_referral, vals ) )
1622                                 return LDAP_OTHER;
1623
1624 #ifdef NEW_LOGGING
1625                 } else if ( strcasecmp( cargv[0], "logfile" ) == 0 ) {
1626                         FILE *logfile;
1627                         if ( cargc < 2 ) {
1628 #ifdef NEW_LOGGING
1629                                 LDAP_LOG( CONFIG, CRIT, 
1630                                         "%s: line %d: Error in logfile directive, "
1631                                         "\"logfile <filename>\"\n", fname, lineno , 0 );
1632 #else
1633                                 Debug( LDAP_DEBUG_ANY,
1634                                        "%s: line %d: Error in logfile directive, \"logfile filename\"\n",
1635                                        fname, lineno, 0 );
1636 #endif
1637
1638                                 return( 1 );
1639                         }
1640                         logfile = fopen( cargv[1], "w" );
1641                         if ( logfile != NULL ) lutil_debug_file( logfile  );
1642
1643 #endif
1644                 /* start of a new database definition */
1645                 } else if ( strcasecmp( cargv[0], "debug" ) == 0 ) {
1646                         int level;
1647                         if ( cargc < 3 ) {
1648 #ifdef NEW_LOGGING
1649                                 LDAP_LOG( CONFIG, CRIT, 
1650                                            "%s: line %d: Error in debug directive, "
1651                                            "\"debug <subsys> <level>\"\n", fname, lineno , 0 );
1652 #else
1653                                 Debug( LDAP_DEBUG_ANY,
1654                                         "%s: line %d: Error in debug directive, \"debug subsys level\"\n",
1655                                         fname, lineno, 0 );
1656 #endif
1657
1658                                 return( 1 );
1659                         }
1660                         level = atoi( cargv[2] );
1661                         if ( level <= 0 ) level = lutil_mnem2level( cargv[2] );
1662                         lutil_set_debug_level( cargv[1], level );
1663                 /* specify an Object Identifier macro */
1664                 } else if ( strcasecmp( cargv[0], "objectidentifier" ) == 0 ) {
1665                         rc = parse_oidm( fname, lineno, cargc, cargv );
1666                         if( rc ) return rc;
1667
1668                 /* specify an objectclass */
1669                 } else if ( strcasecmp( cargv[0], "objectclass" ) == 0 ) {
1670                         if ( cargc < 2 ) {
1671 #ifdef NEW_LOGGING
1672                                 LDAP_LOG( CONFIG, INFO, 
1673                                         "%s: line %d: illegal objectclass format.\n",
1674                                         fname, lineno , 0 );
1675 #else
1676                                 Debug( LDAP_DEBUG_ANY,
1677                                        "%s: line %d: illegal objectclass format.\n",
1678                                        fname, lineno, 0 );
1679 #endif
1680                                 return( 1 );
1681
1682                         } else if ( *cargv[1] == '('  /*')'*/) {
1683                                 char * p;
1684                                 p = strchr(saveline,'(' /*')'*/);
1685                                 rc = parse_oc( fname, lineno, p, cargv );
1686                                 if( rc ) return rc;
1687
1688                         } else {
1689 #ifdef NEW_LOGGING
1690                                 LDAP_LOG( CONFIG, INFO, 
1691                                         "%s: line %d: old objectclass format not supported\n",
1692                                         fname, lineno , 0 );
1693 #else
1694                                 Debug( LDAP_DEBUG_ANY,
1695                                        "%s: line %d: old objectclass format not supported.\n",
1696                                        fname, lineno, 0 );
1697 #endif
1698                         }
1699
1700                 } else if ( strcasecmp( cargv[0], "ditcontentrule" ) == 0 ) {
1701                         char * p;
1702                         p = strchr(saveline,'(' /*')'*/);
1703                         rc = parse_cr( fname, lineno, p, cargv );
1704                         if( rc ) return rc;
1705
1706                 /* specify an attribute type */
1707                 } else if (( strcasecmp( cargv[0], "attributetype" ) == 0 )
1708                         || ( strcasecmp( cargv[0], "attribute" ) == 0 ))
1709                 {
1710                         if ( cargc < 2 ) {
1711 #ifdef NEW_LOGGING
1712                                 LDAP_LOG( CONFIG, INFO, "%s: line %d: "
1713                                         "illegal attribute type format.\n",
1714                                         fname, lineno , 0 );
1715 #else
1716                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1717                                         "illegal attribute type format.\n",
1718                                         fname, lineno, 0 );
1719 #endif
1720                                 return( 1 );
1721
1722                         } else if ( *cargv[1] == '(' /*')'*/) {
1723                                 char * p;
1724                                 p = strchr(saveline,'(' /*')'*/);
1725                                 rc = parse_at( fname, lineno, p, cargv );
1726                                 if( rc ) return rc;
1727
1728                         } else {
1729 #ifdef NEW_LOGGING
1730                                 LDAP_LOG( CONFIG, INFO, 
1731                                         "%s: line %d: old attribute type format not supported.\n",
1732                                         fname, lineno , 0 );
1733 #else
1734                                 Debug( LDAP_DEBUG_ANY,
1735     "%s: line %d: old attribute type format not supported.\n",
1736                                     fname, lineno, 0 );
1737 #endif
1738
1739                         }
1740
1741                 /* define attribute option(s) */
1742                 } else if ( strcasecmp( cargv[0], "attributeoptions" ) == 0 ) {
1743                         ad_define_option( NULL, NULL, 0 );
1744                         for ( i = 1; i < cargc; i++ )
1745                                 if ( ad_define_option( cargv[i], fname, lineno ) != 0 )
1746                                         return 1;
1747
1748                 /* turn on/off schema checking */
1749                 } else if ( strcasecmp( cargv[0], "schemacheck" ) == 0 ) {
1750                         if ( cargc < 2 ) {
1751 #ifdef NEW_LOGGING
1752                                 LDAP_LOG( CONFIG, CRIT, 
1753                                         "%s: line %d: missing on|off in \"schemacheck <on|off>\""
1754                                         " line.\n", fname, lineno , 0 );
1755 #else
1756                                 Debug( LDAP_DEBUG_ANY,
1757     "%s: line %d: missing on|off in \"schemacheck <on|off>\" line\n",
1758                                     fname, lineno, 0 );
1759 #endif
1760
1761                                 return( 1 );
1762                         }
1763                         if ( strcasecmp( cargv[1], "off" ) == 0 ) {
1764 #ifdef NEW_LOGGING
1765                                 LDAP_LOG( CONFIG, CRIT, 
1766                                         "%s: line %d: schema checking disabled! your mileage may "
1767                                         "vary!\n", fname, lineno , 0 );
1768 #else
1769                                 Debug( LDAP_DEBUG_ANY,
1770                                         "%s: line %d: schema checking disabled! your mileage may vary!\n",
1771                                     fname, lineno, 0 );
1772 #endif
1773                                 global_schemacheck = 0;
1774                         } else {
1775                                 global_schemacheck = 1;
1776                         }
1777
1778                 /* specify access control info */
1779                 } else if ( strcasecmp( cargv[0], "access" ) == 0 ) {
1780                         parse_acl( be, fname, lineno, cargc, cargv );
1781
1782                 /* debug level to log things to syslog */
1783                 } else if ( strcasecmp( cargv[0], "loglevel" ) == 0 ) {
1784                         if ( cargc < 2 ) {
1785 #ifdef NEW_LOGGING
1786                                 LDAP_LOG( CONFIG, CRIT, 
1787                                         "%s: line %d: missing level in \"loglevel <level>\""
1788                                         " line.\n", fname, lineno , 0 );
1789 #else
1790                                 Debug( LDAP_DEBUG_ANY,
1791                     "%s: line %d: missing level in \"loglevel <level>\" line\n",
1792                                     fname, lineno, 0 );
1793 #endif
1794
1795                                 return( 1 );
1796                         }
1797
1798                         ldap_syslog = 0;
1799
1800                         for( i=1; i < cargc; i++ ) {
1801                                 ldap_syslog += atoi( cargv[1] );
1802                         }
1803
1804                 /* list of sync replication information in this backend (slave only) */
1805                 } else if ( strcasecmp( cargv[0], "syncrepl" ) == 0 ) {
1806
1807                         if ( be == NULL ) {
1808 #ifdef NEW_LOGGING
1809                                 LDAP_LOG( CONFIG, INFO, 
1810                                             "%s: line %d: syncrepl line must appear inside "
1811                                             "a database definition.\n", fname, lineno, 0);
1812 #else
1813                                 Debug( LDAP_DEBUG_ANY,
1814                                             "%s: line %d: syncrepl line must appear inside "
1815                                             "a database definition.\n", fname, lineno, 0);
1816 #endif
1817                                 return 1;
1818
1819                         } else if ( SLAP_SHADOW( be )) {
1820 #ifdef NEW_LOGGING
1821                                 LDAP_LOG( CONFIG, INFO, 
1822                                         "%s: line %d: syncrepl: database already shadowed.\n",
1823                                         fname, lineno, 0);
1824 #else
1825                                 Debug( LDAP_DEBUG_ANY,
1826                                         "%s: line %d: syncrepl: database already shadowed.\n",
1827                                         fname, lineno, 0);
1828 #endif
1829                                 return 1;
1830
1831                         } else if ( add_syncrepl( be, cargv, cargc )) {
1832                                 return 1;
1833                         }
1834
1835                         SLAP_DBFLAGS(be) |= ( SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SYNC_SHADOW );
1836
1837                 /* list of replicas of the data in this backend (master only) */
1838                 } else if ( strcasecmp( cargv[0], "replica" ) == 0 ) {
1839                         if ( cargc < 2 ) {
1840 #ifdef NEW_LOGGING
1841                                 LDAP_LOG( CONFIG, CRIT, 
1842                                         "%s: line %d: missing host or uri in \"replica "
1843                                         " <host[:port]\" line\n", fname, lineno , 0 );
1844 #else
1845                                 Debug( LDAP_DEBUG_ANY,
1846             "%s: line %d: missing host or uri in \"replica <host[:port]>\" line\n",
1847                                     fname, lineno, 0 );
1848 #endif
1849
1850                                 return( 1 );
1851                         }
1852                         if ( be == NULL ) {
1853 #ifdef NEW_LOGGING
1854                                 LDAP_LOG( CONFIG, INFO, 
1855                                             "%s: line %d: replica line must appear inside "
1856                                             "a database definition.\n", fname, lineno, 0);
1857 #else
1858                                 Debug( LDAP_DEBUG_ANY,
1859 "%s: line %d: replica line must appear inside a database definition\n",
1860                                     fname, lineno, 0 );
1861 #endif
1862                                 return 1;
1863
1864                         } else {
1865                                 int nr = -1;
1866
1867                                 for ( i = 1; i < cargc; i++ ) {
1868                                         if ( strncasecmp( cargv[i], "host=", 5 )
1869                                             == 0 ) {
1870                                                 nr = add_replica_info( be, 
1871                                                         cargv[i] + 5 );
1872                                                 break;
1873                                         } else if (strncasecmp( cargv[i], "uri=", 4 )
1874                                             == 0 ) {
1875                                             if ( ldap_url_parse( cargv[ i ] + 4, &ludp )
1876                                                 != LDAP_SUCCESS ) {
1877 #ifdef NEW_LOGGING
1878                                                         LDAP_LOG( CONFIG, INFO, 
1879                                                         "%s: line %d: replica line contains invalid "
1880                                                         "uri definition.\n", fname, lineno, 0);
1881 #else
1882                                                         Debug( LDAP_DEBUG_ANY,
1883                                                         "%s: line %d: replica line contains invalid "
1884                                                         "uri definition.\n", fname, lineno, 0);
1885 #endif
1886                                                         return 1;
1887                                                 }
1888                                                 if (ludp->lud_host == NULL ) {
1889 #ifdef NEW_LOGGING
1890                                                         LDAP_LOG( CONFIG, INFO, 
1891                                                         "%s: line %d: replica line contains invalid "
1892                                                         "uri definition - missing hostname.\n", 
1893                                                         fname, lineno, 0);
1894 #else
1895                                                         Debug( LDAP_DEBUG_ANY,
1896                                                         "%s: line %d: replica line contains invalid "
1897                                                         "uri definition - missing hostname.\n", fname, lineno, 0);
1898 #endif
1899                                                         return 1;
1900                                                 }
1901                                         replicahost = ch_malloc( strlen( cargv[ i ] ) );
1902                                                 if ( replicahost == NULL ) {
1903 #ifdef NEW_LOGGING
1904                                                         LDAP_LOG( CONFIG, ERR, 
1905                                                         "out of memory in read_config\n", 0, 0,0 );
1906 #else
1907                                                         Debug( LDAP_DEBUG_ANY, 
1908                                                         "out of memory in read_config\n", 0, 0, 0 );
1909 #endif
1910                                                         ldap_free_urldesc( ludp );                              
1911                                                         exit( EXIT_FAILURE );
1912                                                 }
1913                                                 sprintf(replicahost, "%s:%d", 
1914                                                         ludp->lud_host, ludp->lud_port);
1915                                                 nr = add_replica_info( be, replicahost );
1916                                                 ldap_free_urldesc( ludp );                              
1917                                                 ch_free(replicahost);
1918                                                 break;
1919                                         }
1920                                 }
1921                                 if ( i == cargc ) {
1922 #ifdef NEW_LOGGING
1923                                         LDAP_LOG( CONFIG, INFO, 
1924                                                 "%s: line %d: missing host or uri in \"replica\" line\n", 
1925                                                 fname, lineno , 0 );
1926 #else
1927                                         Debug( LDAP_DEBUG_ANY,
1928                     "%s: line %d: missing host or uri in \"replica\" line\n",
1929                                             fname, lineno, 0 );
1930 #endif
1931                                         return 1;
1932
1933                                 } else if ( nr == -1 ) {
1934 #ifdef NEW_LOGGING
1935                                         LDAP_LOG( CONFIG, INFO, 
1936                                                    "%s: line %d: unable to add"
1937                                                    " replica \"%s\"\n",
1938                                                    fname, lineno, 
1939                                                    cargv[i] + 5 );
1940 #else
1941                                         Debug( LDAP_DEBUG_ANY,
1942                 "%s: line %d: unable to add replica \"%s\"\n",
1943                                                 fname, lineno, cargv[i] + 5 );
1944 #endif
1945                                         return 1;
1946                                 } else {
1947                                         for ( i = 1; i < cargc; i++ ) {
1948                                                 if ( strncasecmp( cargv[i], "suffix=", 7 ) == 0 ) {
1949
1950                                                         switch ( add_replica_suffix( be, nr, cargv[i] + 7 ) ) {
1951                                                         case 1:
1952 #ifdef NEW_LOGGING
1953                                                                 LDAP_LOG( CONFIG, INFO, 
1954                                                                         "%s: line %d: suffix \"%s\" in \"replica\""
1955                                                                         " line is not valid for backend(ignored)\n",
1956                                                                         fname, lineno, cargv[i] + 7 );
1957 #else
1958                                                                 Debug( LDAP_DEBUG_ANY,
1959                                                                                 "%s: line %d: suffix \"%s\" in \"replica\" line is not valid for backend (ignored)\n",
1960                                                                                 fname, lineno, cargv[i] + 7 );
1961 #endif
1962                                                                 break;
1963
1964                                                         case 2:
1965 #ifdef NEW_LOGGING
1966                                                                 LDAP_LOG( CONFIG, INFO, 
1967                                                                         "%s: line %d: unable to normalize suffix"
1968                                                                         " in \"replica\" line (ignored)\n",
1969                                                                         fname, lineno , 0 );
1970 #else
1971                                                                 Debug( LDAP_DEBUG_ANY,
1972                                                                                  "%s: line %d: unable to normalize suffix in \"replica\" line (ignored)\n",
1973                                                                                  fname, lineno, 0 );
1974 #endif
1975                                                                 break;
1976                                                         }
1977
1978                                                 } else if ( strncasecmp( cargv[i], "attr", 4 ) == 0 ) {
1979                                                         int exclude = 0;
1980                                                         char *arg = cargv[i] + 4;
1981
1982                                                         if ( arg[0] == '!' ) {
1983                                                                 arg++;
1984                                                                 exclude = 1;
1985                                                         }
1986
1987                                                         if ( arg[0] != '=' ) {
1988                                                                 continue;
1989                                                         }
1990
1991                                                         if ( add_replica_attrs( be, nr, arg + 1, exclude ) ) {
1992 #ifdef NEW_LOGGING
1993                                                                 LDAP_LOG( CONFIG, INFO, 
1994                                                                         "%s: line %d: attribute \"%s\" in "
1995                                                                         "\"replica\" line is unknown\n",
1996                                                                         fname, lineno, arg + 1 ); 
1997 #else
1998                                                                 Debug( LDAP_DEBUG_ANY,
1999                                                                                 "%s: line %d: attribute \"%s\" in \"replica\" line is unknown\n",
2000                                                                                 fname, lineno, arg + 1 );
2001 #endif
2002                                                                 return( 1 );
2003                                                         }
2004                                                 }
2005                                         }
2006                                 }
2007                         }
2008
2009                 } else if ( strcasecmp( cargv[0], "replicationInterval" ) == 0 ) {
2010                         /* ignore */
2011
2012                 /* dn of slave entity allowed to write to replica */
2013                 } else if ( strcasecmp( cargv[0], "updatedn" ) == 0 ) {
2014                         if ( cargc < 2 ) {
2015 #ifdef NEW_LOGGING
2016                                 LDAP_LOG( CONFIG, CRIT, 
2017                                         "%s: line %d: missing dn in \"updatedn <dn>\""
2018                                         " line.\n", fname, lineno , 0 );
2019 #else
2020                                 Debug( LDAP_DEBUG_ANY,
2021                     "%s: line %d: missing dn in \"updatedn <dn>\" line\n",
2022                                     fname, lineno, 0 );
2023 #endif
2024
2025                                 return( 1 );
2026                         }
2027                         if ( be == NULL ) {
2028 #ifdef NEW_LOGGING
2029                                 LDAP_LOG( CONFIG, INFO, 
2030                                         "%s: line %d: updatedn line must appear inside "
2031                                         "a database definition\n", 
2032                                         fname, lineno , 0 );
2033 #else
2034                                 Debug( LDAP_DEBUG_ANY,
2035 "%s: line %d: updatedn line must appear inside a database definition\n",
2036                                     fname, lineno, 0 );
2037 #endif
2038                                 return 1;
2039
2040                         } else if ( SLAP_SHADOW(be) ) {
2041 #ifdef NEW_LOGGING
2042                                 LDAP_LOG( CONFIG, INFO, 
2043                                         "%s: line %d: updatedn: database already shadowed.\n",
2044                                         fname, lineno, 0);
2045 #else
2046                                 Debug( LDAP_DEBUG_ANY,
2047                                         "%s: line %d: updatedn: database already shadowed.\n",
2048                                         fname, lineno, 0);
2049 #endif
2050                                 return 1;
2051
2052                         } else {
2053                                 struct berval dn;
2054
2055                                 if ( load_ucdata( NULL ) < 0 ) return 1;
2056
2057                                 dn.bv_val = cargv[1];
2058                                 dn.bv_len = strlen( cargv[1] );
2059
2060                                 rc = dnNormalize( 0, NULL, NULL, &dn, &be->be_update_ndn, NULL );
2061                                 if( rc != LDAP_SUCCESS ) {
2062 #ifdef NEW_LOGGING
2063                                         LDAP_LOG( CONFIG, CRIT, 
2064                                                 "%s: line %d: updatedn DN is invalid.\n",
2065                                                 fname, lineno , 0 );
2066 #else
2067                                         Debug( LDAP_DEBUG_ANY,
2068                                                 "%s: line %d: updatedn DN is invalid\n",
2069                                             fname, lineno, 0 );
2070 #endif
2071                                         return 1;
2072                                 }
2073
2074                         }
2075                         SLAP_DBFLAGS(be) |= ( SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SLURP_SHADOW );
2076
2077                 } else if ( strcasecmp( cargv[0], "updateref" ) == 0 ) {
2078                         if ( cargc < 2 ) {
2079 #ifdef NEW_LOGGING
2080                                 LDAP_LOG( CONFIG, CRIT, "%s: line %d: "
2081                                         "missing url in \"updateref <ldapurl>\" line.\n",
2082                                         fname, lineno , 0 );
2083 #else
2084                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
2085                                         "missing url in \"updateref <ldapurl>\" line\n",
2086                                     fname, lineno, 0 );
2087 #endif
2088
2089                                 return( 1 );
2090                         }
2091                         if ( be == NULL ) {
2092 #ifdef NEW_LOGGING
2093                                 LDAP_LOG( CONFIG, INFO, "%s: line %d: updateref"
2094                                         " line must appear inside a database definition\n",
2095                                         fname, lineno , 0 );
2096 #else
2097                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: updateref"
2098                                         " line must appear inside a database definition\n",
2099                                         fname, lineno, 0 );
2100 #endif
2101                                 return 1;
2102
2103                         } else if ( !SLAP_SHADOW(be) ) {
2104 #ifdef NEW_LOGGING
2105                                 LDAP_LOG( CONFIG, INFO, "%s: line %d: "
2106                                         "updateref line must come after syncrepl or updatedn.\n",
2107                                         fname, lineno , 0 );
2108 #else
2109                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
2110                                         "updateref line must after syncrepl or updatedn.\n",
2111                                     fname, lineno, 0 );
2112 #endif
2113                                 return 1;
2114                         }
2115
2116                         if( validate_global_referral( cargv[1] ) ) {
2117 #ifdef NEW_LOGGING
2118                                 LDAP_LOG( CONFIG, CRIT, "%s: line %d: "
2119                                         "invalid URL (%s) in \"updateref\" line.\n",
2120                                         fname, lineno, cargv[1] );
2121 #else
2122                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
2123                                         "invalid URL (%s) in \"updateref\" line.\n",
2124                                     fname, lineno, cargv[1] );
2125 #endif
2126                                 return 1;
2127                         }
2128
2129                         vals[0].bv_val = cargv[1];
2130                         vals[0].bv_len = strlen( vals[0].bv_val );
2131                         if( value_add( &be->be_update_refs, vals ) ) {
2132                                 return LDAP_OTHER;
2133                         }
2134
2135                 /* replication log file to which changes are appended */
2136                 } else if ( strcasecmp( cargv[0], "replogfile" ) == 0 ) {
2137                         if ( cargc < 2 ) {
2138 #ifdef NEW_LOGGING
2139                                 LDAP_LOG( CONFIG, CRIT, 
2140                                         "%s: line %d: missing filename in \"replogfile <filename>\""
2141                                         " line.\n", fname, lineno , 0 );
2142 #else
2143                                 Debug( LDAP_DEBUG_ANY,
2144             "%s: line %d: missing filename in \"replogfile <filename>\" line\n",
2145                                     fname, lineno, 0 );
2146 #endif
2147
2148                                 return( 1 );
2149                         }
2150                         if ( be ) {
2151                                 be->be_replogfile = ch_strdup( cargv[1] );
2152                         } else {
2153                                 replogfile = ch_strdup( cargv[1] );
2154                         }
2155
2156                 /* file from which to read additional rootdse attrs */
2157                 } else if ( strcasecmp( cargv[0], "rootDSE" ) == 0) {
2158                         if ( cargc < 2 ) {
2159 #ifdef NEW_LOGGING
2160                                 LDAP_LOG( CONFIG, CRIT, "%s: line %d: "
2161                                         "missing filename in \"rootDSE <filename>\" line.\n",
2162                                         fname, lineno , 0 );
2163 #else
2164                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
2165                                         "missing filename in \"rootDSE <filename>\" line.\n",
2166                                     fname, lineno, 0 );
2167 #endif
2168                                 return 1;
2169                         }
2170
2171                         if( read_root_dse_file( cargv[1] ) ) {
2172 #ifdef NEW_LOGGING
2173                                 LDAP_LOG( CONFIG, CRIT, "%s: line %d: "
2174                                         "could not read \"rootDSE <filename>\" line.\n",
2175                                         fname, lineno , 0 );
2176 #else
2177                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
2178                                         "could not read \"rootDSE <filename>\" line\n",
2179                                     fname, lineno, 0 );
2180 #endif
2181                                 return 1;
2182                         }
2183
2184                 /* maintain lastmodified{by,time} attributes */
2185                 } else if ( strcasecmp( cargv[0], "lastmod" ) == 0 ) {
2186                         if ( cargc < 2 ) {
2187 #ifdef NEW_LOGGING
2188                                 LDAP_LOG( CONFIG, CRIT, 
2189                                            "%s: line %d: missing on|off in \"lastmod <on|off>\""
2190                                            " line.\n", fname, lineno , 0 );
2191 #else
2192                                 Debug( LDAP_DEBUG_ANY,
2193             "%s: line %d: missing on|off in \"lastmod <on|off>\" line\n",
2194                                     fname, lineno, 0 );
2195 #endif
2196
2197                                 return( 1 );
2198                         }
2199                         if ( strcasecmp( cargv[1], "on" ) == 0 ) {
2200                                 if ( be ) {
2201                                         SLAP_DBFLAGS(be) &= ~SLAP_DBFLAG_NOLASTMOD;
2202                                 } else {
2203                                         lastmod = 1;
2204                                 }
2205                         } else {
2206                                 if ( be ) {
2207                                         SLAP_DBFLAGS(be) |= SLAP_DBFLAG_NOLASTMOD;
2208                                 } else {
2209                                         lastmod = 0;
2210                                 }
2211                         }
2212
2213 #ifdef SIGHUP
2214                 /* turn on/off gentle SIGHUP handling */
2215                 } else if ( strcasecmp( cargv[0], "gentlehup" ) == 0 ) {
2216                         if ( cargc < 2 ) {
2217                                 Debug( LDAP_DEBUG_ANY,
2218     "%s: line %d: missing on|off in \"gentlehup <on|off>\" line\n",
2219                                     fname, lineno, 0 );
2220                                 return( 1 );
2221                         }
2222                         if ( strcasecmp( cargv[1], "off" ) == 0 ) {
2223                                 global_gentlehup = 0;
2224                         } else {
2225                                 global_gentlehup = 1;
2226                         }
2227 #endif
2228
2229                 /* set idle timeout value */
2230                 } else if ( strcasecmp( cargv[0], "idletimeout" ) == 0 ) {
2231                         int i;
2232                         if ( cargc < 2 ) {
2233 #ifdef NEW_LOGGING
2234                                 LDAP_LOG( CONFIG, CRIT, 
2235                                         "%s: line %d: missing timeout value in "
2236                                         "\"idletimeout <seconds>\" line.\n", fname, lineno , 0 );
2237 #else
2238                                 Debug( LDAP_DEBUG_ANY,
2239             "%s: line %d: missing timeout value in \"idletimeout <seconds>\" line\n",
2240                                     fname, lineno, 0 );
2241 #endif
2242
2243                                 return( 1 );
2244                         }
2245
2246                         i = atoi( cargv[1] );
2247
2248                         if( i < 0 ) {
2249 #ifdef NEW_LOGGING
2250                                 LDAP_LOG( CONFIG, CRIT, 
2251                                         "%s: line %d: timeout value (%d) invalid "
2252                                         "\"idletimeout <seconds>\" line.\n", fname, lineno, i );
2253 #else
2254                                 Debug( LDAP_DEBUG_ANY,
2255             "%s: line %d: timeout value (%d) invalid \"idletimeout <seconds>\" line\n",
2256                                     fname, lineno, i );
2257 #endif
2258
2259                                 return( 1 );
2260                         }
2261
2262                         global_idletimeout = i;
2263
2264                 /* include another config file */
2265                 } else if ( strcasecmp( cargv[0], "include" ) == 0 ) {
2266                         if ( cargc < 2 ) {
2267 #ifdef NEW_LOGGING
2268                                 LDAP_LOG( CONFIG, CRIT, 
2269                                         "%s: line %d: missing filename in \"include "
2270                                         "<filename>\" line.\n", fname, lineno , 0 );
2271 #else
2272                                 Debug( LDAP_DEBUG_ANY,
2273     "%s: line %d: missing filename in \"include <filename>\" line\n",
2274                                     fname, lineno, 0 );
2275 #endif
2276
2277                                 return( 1 );
2278                         }
2279                         savefname = ch_strdup( cargv[1] );
2280                         savelineno = lineno;
2281
2282                         if ( read_config( savefname, depth+1 ) != 0 ) {
2283                                 return( 1 );
2284                         }
2285
2286                         free( savefname );
2287                         lineno = savelineno - 1;
2288
2289                 /* location of kerberos srvtab file */
2290                 } else if ( strcasecmp( cargv[0], "srvtab" ) == 0 ) {
2291                         if ( cargc < 2 ) {
2292 #ifdef NEW_LOGGING
2293                                 LDAP_LOG( CONFIG, CRIT, 
2294                                         "%s: line %d: missing filename in \"srvtab "
2295                                         "<filename>\" line.\n", fname, lineno , 0 );
2296 #else
2297                                 Debug( LDAP_DEBUG_ANY,
2298             "%s: line %d: missing filename in \"srvtab <filename>\" line\n",
2299                                     fname, lineno, 0 );
2300 #endif
2301
2302                                 return( 1 );
2303                         }
2304                         ldap_srvtab = ch_strdup( cargv[1] );
2305
2306 #ifdef SLAPD_MODULES
2307                 } else if (strcasecmp( cargv[0], "moduleload") == 0 ) {
2308                    if ( cargc < 2 ) {
2309 #ifdef NEW_LOGGING
2310                            LDAP_LOG( CONFIG, INFO, 
2311                                    "%s: line %d: missing filename in \"moduleload "
2312                                    "<filename>\" line.\n", fname, lineno , 0 );
2313 #else
2314                       Debug( LDAP_DEBUG_ANY,
2315                              "%s: line %d: missing filename in \"moduleload <filename>\" line\n",
2316                              fname, lineno, 0 );
2317 #endif
2318
2319                       exit( EXIT_FAILURE );
2320                    }
2321                    if (module_load(cargv[1], cargc - 2, (cargc > 2) ? cargv + 2 : NULL)) {
2322 #ifdef NEW_LOGGING
2323                            LDAP_LOG( CONFIG, CRIT, 
2324                                    "%s: line %d: failed to load or initialize module %s\n",
2325                                    fname, lineno, cargv[1] );
2326 #else
2327                       Debug( LDAP_DEBUG_ANY,
2328                              "%s: line %d: failed to load or initialize module %s\n",
2329                              fname, lineno, cargv[1]);
2330 #endif
2331
2332                       exit( EXIT_FAILURE );
2333                    }
2334                 } else if (strcasecmp( cargv[0], "modulepath") == 0 ) {
2335                    if ( cargc != 2 ) {
2336 #ifdef NEW_LOGGING
2337                            LDAP_LOG( CONFIG, INFO, 
2338                                   "%s: line %d: missing path in \"modulepath <path>\""
2339                                   " line\n", fname, lineno , 0 );
2340 #else
2341                       Debug( LDAP_DEBUG_ANY,
2342                              "%s: line %d: missing path in \"modulepath <path>\" line\n",
2343                              fname, lineno, 0 );
2344 #endif
2345
2346                       exit( EXIT_FAILURE );
2347                    }
2348                    if (module_path( cargv[1] )) {
2349 #ifdef NEW_LOGGING
2350                            LDAP_LOG( CONFIG, CRIT, 
2351                                   "%s: line %d: failed to set module search path to %s.\n",
2352                                   fname, lineno, cargv[1] );
2353 #else
2354                            Debug( LDAP_DEBUG_ANY,
2355                                   "%s: line %d: failed to set module search path to %s\n",
2356                                   fname, lineno, cargv[1]);
2357 #endif
2358
2359                       exit( EXIT_FAILURE );
2360                    }
2361                    
2362 #endif /*SLAPD_MODULES*/
2363
2364 #ifdef HAVE_TLS
2365                 } else if ( !strcasecmp( cargv[0], "TLSRandFile" ) ) {
2366                         rc = ldap_pvt_tls_set_option( NULL,
2367                                                       LDAP_OPT_X_TLS_RANDOM_FILE,
2368                                                       cargv[1] );
2369                         if ( rc )
2370                                 return rc;
2371
2372                 } else if ( !strcasecmp( cargv[0], "TLSCipherSuite" ) ) {
2373                         rc = ldap_pvt_tls_set_option( NULL,
2374                                                       LDAP_OPT_X_TLS_CIPHER_SUITE,
2375                                                       cargv[1] );
2376                         if ( rc )
2377                                 return rc;
2378
2379                 } else if ( !strcasecmp( cargv[0], "TLSCertificateFile" ) ) {
2380                         rc = ldap_pvt_tls_set_option( NULL,
2381                                                       LDAP_OPT_X_TLS_CERTFILE,
2382                                                       cargv[1] );
2383                         if ( rc )
2384                                 return rc;
2385
2386                 } else if ( !strcasecmp( cargv[0], "TLSCertificateKeyFile" ) ) {
2387                         rc = ldap_pvt_tls_set_option( NULL,
2388                                                       LDAP_OPT_X_TLS_KEYFILE,
2389                                                       cargv[1] );
2390                         if ( rc )
2391                                 return rc;
2392
2393                 } else if ( !strcasecmp( cargv[0], "TLSCACertificatePath" ) ) {
2394                         rc = ldap_pvt_tls_set_option( NULL,
2395                                                       LDAP_OPT_X_TLS_CACERTDIR,
2396                                                       cargv[1] );
2397                         if ( rc )
2398                                 return rc;
2399
2400                 } else if ( !strcasecmp( cargv[0], "TLSCACertificateFile" ) ) {
2401                         rc = ldap_pvt_tls_set_option( NULL,
2402                                                       LDAP_OPT_X_TLS_CACERTFILE,
2403                                                       cargv[1] );
2404                         if ( rc )
2405                                 return rc;
2406                 } else if ( !strcasecmp( cargv[0], "TLSVerifyClient" ) ) {
2407                         if ( isdigit( (unsigned char) cargv[1][0] ) ) {
2408                                 i = atoi(cargv[1]);
2409                                 rc = ldap_pvt_tls_set_option( NULL,
2410                                                       LDAP_OPT_X_TLS_REQUIRE_CERT,
2411                                                       &i );
2412                         } else {
2413                                 rc = ldap_int_tls_config( NULL,
2414                                                       LDAP_OPT_X_TLS_REQUIRE_CERT,
2415                                                       cargv[1] );
2416                         }
2417
2418                         if ( rc )
2419                                 return rc;
2420
2421 #endif
2422
2423                 } else if ( !strcasecmp( cargv[0], "reverse-lookup" ) ) {
2424 #ifdef SLAPD_RLOOKUPS
2425                         if ( cargc < 2 ) {
2426 #ifdef NEW_LOGGING
2427                                 LDAP_LOG( CONFIG, INFO, 
2428                                         "%s: line %d: reverse-lookup: missing \"on\" or \"off\"\n",
2429                                         fname, lineno , 0 );
2430 #else
2431                                 Debug( LDAP_DEBUG_ANY,
2432 "%s: line %d: reverse-lookup: missing \"on\" or \"off\"\n",
2433                                         fname, lineno, 0 );
2434 #endif
2435                                 return( 1 );
2436                         }
2437
2438                         if ( !strcasecmp( cargv[1], "on" ) ) {
2439                                 use_reverse_lookup = 1;
2440                         } else if ( !strcasecmp( cargv[1], "off" ) ) {
2441                                 use_reverse_lookup = 0;
2442                         } else {
2443 #ifdef NEW_LOGGING
2444                                 LDAP_LOG( CONFIG, INFO, 
2445                                         "%s: line %d: reverse-lookup: "
2446                                         "must be \"on\" (default) or \"off\"\n", fname, lineno, 0 );
2447 #else
2448                                 Debug( LDAP_DEBUG_ANY,
2449 "%s: line %d: reverse-lookup: must be \"on\" (default) or \"off\"\n",
2450                                         fname, lineno, 0 );
2451 #endif
2452                                 return( 1 );
2453                         }
2454
2455 #else /* !SLAPD_RLOOKUPS */
2456 #ifdef NEW_LOGGING
2457                         LDAP_LOG( CONFIG, INFO, 
2458                                 "%s: line %d: reverse lookups "
2459                                 "are not configured (ignored).\n", fname, lineno , 0 );
2460 #else
2461                         Debug( LDAP_DEBUG_ANY,
2462 "%s: line %d: reverse lookups are not configured (ignored).\n",
2463                                 fname, lineno, 0 );
2464 #endif
2465 #endif /* !SLAPD_RLOOKUPS */
2466
2467                 /* Netscape plugins */
2468                 } else if ( strcasecmp( cargv[0], "plugin" ) == 0 ) {
2469 #if defined( LDAP_SLAPI )
2470
2471 #ifdef notdef /* allow global plugins, too */
2472                         /*
2473                          * a "plugin" line must be inside a database
2474                          * definition, since we implement pre-,post- 
2475                          * and extended operation plugins
2476                          */
2477                         if ( be == NULL ) {
2478 #ifdef NEW_LOGGING
2479                                 LDAP_LOG( CONFIG, INFO, 
2480                                         "%s: line %d: plugin line must appear "
2481                                         "insid a database definition.\n",
2482                                         fname, lineno, 0 );
2483 #else
2484                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: plugin "
2485                                     "line must appear inside a database "
2486                                     "definition\n", fname, lineno, 0 );
2487 #endif
2488                                 return( 1 );
2489                         }
2490 #endif /* notdef */
2491
2492                         if ( slapi_int_read_config( be, fname, lineno, cargc, cargv ) 
2493                                         != LDAP_SUCCESS ) {
2494                                 return( 1 );
2495                         }
2496                         slapi_plugins_used++;
2497
2498 #else /* !defined( LDAP_SLAPI ) */
2499 #ifdef NEW_LOGGING
2500                         LDAP_LOG( CONFIG, INFO, 
2501                                 "%s: line %d: SLAPI not supported.\n",
2502                                 fname, lineno, 0 );
2503 #else
2504                         Debug( LDAP_DEBUG_ANY, "%s: line %d: SLAPI "
2505                             "not supported.\n", fname, lineno, 0 );
2506 #endif
2507                         return( 1 );
2508                         
2509 #endif /* !defined( LDAP_SLAPI ) */
2510
2511                 /* Netscape plugins */
2512                 } else if ( strcasecmp( cargv[0], "pluginlog" ) == 0 ) {
2513 #if defined( LDAP_SLAPI )
2514                         if ( cargc < 2 ) {
2515 #ifdef NEW_LOGGING
2516                                 LDAP_LOG( CONFIG, INFO, 
2517                                         "%s: line %d: missing file name "
2518                                         "in pluginlog <filename> line.\n",
2519                                         fname, lineno, 0 );
2520 #else
2521                                 Debug( LDAP_DEBUG_ANY, 
2522                                         "%s: line %d: missing file name "
2523                                         "in pluginlog <filename> line.\n",
2524                                         fname, lineno, 0 );
2525 #endif
2526                                 return( 1 );
2527                         }
2528
2529                         if ( slapi_log_file != NULL ) {
2530                                 ch_free( slapi_log_file );
2531                         }
2532
2533                         slapi_log_file = ch_strdup( cargv[1] );
2534 #endif /* !defined( LDAP_SLAPI ) */
2535
2536                 /* pass anything else to the current backend info/db config routine */
2537                 } else {
2538                         if ( bi != NULL ) {
2539                                 if ( bi->bi_config ) {
2540                                         rc = (*bi->bi_config)( bi, fname, lineno, cargc, cargv );
2541
2542                                         switch ( rc ) {
2543                                         case 0:
2544                                                 break;
2545
2546                                         case SLAP_CONF_UNKNOWN:
2547 #ifdef NEW_LOGGING
2548                                                 LDAP_LOG( CONFIG, INFO, 
2549                                                         "%s: line %d: unknown directive \"%s\" inside "
2550                                                         "backend info definition (ignored).\n",
2551                                                         fname, lineno, cargv[0] );
2552 #else
2553                                                 Debug( LDAP_DEBUG_ANY,
2554 "%s: line %d: unknown directive \"%s\" inside backend info definition (ignored)\n",
2555                                                         fname, lineno, cargv[0] );
2556 #endif
2557                                                 break;
2558
2559                                         default:
2560                                                 return 1;
2561                                         }
2562                                 }
2563
2564                         } else if ( be != NULL ) {
2565                                 if ( be->be_config ) {
2566                                         rc = (*be->be_config)( be, fname, lineno, cargc, cargv );
2567
2568                                         switch ( rc ) {
2569                                         case 0:
2570                                                 break;
2571
2572                                         case SLAP_CONF_UNKNOWN:
2573 #ifdef NEW_LOGGING
2574                                                 LDAP_LOG( CONFIG, INFO, 
2575                                                         "%s: line %d: unknown directive \"%s\" inside "
2576                                                         "backend database definition (ignored).\n",
2577                                                         fname, lineno, cargv[0] );
2578 #else
2579                                                 Debug( LDAP_DEBUG_ANY,
2580 "%s: line %d: unknown directive \"%s\" inside backend database definition (ignored)\n",
2581                                                         fname, lineno, cargv[0] );
2582 #endif
2583                                                 break;
2584
2585                                         default:
2586                                                 return 1;
2587                                         }
2588                                 }
2589
2590                         } else {
2591 #ifdef NEW_LOGGING
2592                                 LDAP_LOG( CONFIG, INFO, 
2593                                         "%s: line %d: unknown directive \"%s\" outside backend "
2594                                         "info and database definitions (ignored).\n",
2595                                         fname, lineno, cargv[0] );
2596 #else
2597                                 Debug( LDAP_DEBUG_ANY,
2598 "%s: line %d: unknown directive \"%s\" outside backend info and database definitions (ignored)\n",
2599                                     fname, lineno, cargv[0] );
2600 #endif
2601
2602                         }
2603                 }
2604                 free( saveline );
2605         }
2606         fclose( fp );
2607
2608         if ( depth == 0 ) ch_free( cargv );
2609
2610         if ( !global_schemadn.bv_val ) {
2611                 ber_str2bv( SLAPD_SCHEMA_DN, sizeof(SLAPD_SCHEMA_DN)-1, 1,
2612                         &global_schemadn );
2613                 dnNormalize( 0, NULL, NULL, &global_schemadn, &global_schemandn, NULL );
2614         }
2615
2616         if ( load_ucdata( NULL ) < 0 ) return 1;
2617         return( 0 );
2618 }
2619
2620 static int
2621 fp_parse_line(
2622     int         lineno,
2623     char        *line
2624 )
2625 {
2626         char *  token;
2627         char *  logline;
2628         char    logbuf[sizeof("pseudorootpw ***")];
2629
2630         cargc = 0;
2631         token = strtok_quote( line, " \t" );
2632
2633         logline = line;
2634
2635         if ( token && ( strcasecmp( token, "rootpw" ) == 0 ||
2636                 strcasecmp( token, "replica" ) == 0 ||          /* contains "credentials" */
2637                 strcasecmp( token, "bindpw" ) == 0 ||           /* used in back-ldap */
2638                 strcasecmp( token, "pseudorootpw" ) == 0 ||     /* used in back-meta */
2639                 strcasecmp( token, "dbpasswd" ) == 0 ) )        /* used in back-sql */
2640         {
2641                 snprintf( logline = logbuf, sizeof logbuf, "%s ***", token );
2642         }
2643
2644         if ( strtok_quote_ptr ) {
2645                 *strtok_quote_ptr = ' ';
2646         }
2647
2648 #ifdef NEW_LOGGING
2649         LDAP_LOG( CONFIG, DETAIL1, "line %d (%s)\n", lineno, logline , 0 );
2650 #else
2651         Debug( LDAP_DEBUG_CONFIG, "line %d (%s)\n", lineno, logline, 0 );
2652 #endif
2653
2654         if ( strtok_quote_ptr ) {
2655                 *strtok_quote_ptr = '\0';
2656         }
2657
2658         for ( ; token != NULL; token = strtok_quote( NULL, " \t" ) ) {
2659                 if ( cargc == cargv_size - 1 ) {
2660                         char **tmp;
2661                         tmp = ch_realloc( cargv, (cargv_size + ARGS_STEP) *
2662                                             sizeof(*cargv) );
2663                         if ( tmp == NULL ) {
2664 #ifdef NEW_LOGGING
2665                                 LDAP_LOG( CONFIG, ERR, "line %d: out of memory\n", lineno, 0,0 );
2666 #else
2667                                 Debug( LDAP_DEBUG_ANY, 
2668                                                 "line %d: out of memory\n", 
2669                                                 lineno, 0, 0 );
2670 #endif
2671                                 return -1;
2672                         }
2673                         cargv = tmp;
2674                         cargv_size += ARGS_STEP;
2675                 }
2676                 cargv[cargc++] = token;
2677         }
2678         cargv[cargc] = NULL;
2679         return 0;
2680 }
2681
2682 static char *
2683 strtok_quote( char *line, char *sep )
2684 {
2685         int             inquote;
2686         char            *tmp;
2687         static char     *next;
2688
2689         strtok_quote_ptr = NULL;
2690         if ( line != NULL ) {
2691                 next = line;
2692         }
2693         while ( *next && strchr( sep, *next ) ) {
2694                 next++;
2695         }
2696
2697         if ( *next == '\0' ) {
2698                 next = NULL;
2699                 return( NULL );
2700         }
2701         tmp = next;
2702
2703         for ( inquote = 0; *next; ) {
2704                 switch ( *next ) {
2705                 case '"':
2706                         if ( inquote ) {
2707                                 inquote = 0;
2708                         } else {
2709                                 inquote = 1;
2710                         }
2711                         AC_MEMCPY( next, next + 1, strlen( next + 1 ) + 1 );
2712                         break;
2713
2714                 case '\\':
2715                         if ( next[1] )
2716                                 AC_MEMCPY( next,
2717                                             next + 1, strlen( next + 1 ) + 1 );
2718                         next++;         /* dont parse the escaped character */
2719                         break;
2720
2721                 default:
2722                         if ( ! inquote ) {
2723                                 if ( strchr( sep, *next ) != NULL ) {
2724                                         strtok_quote_ptr = next;
2725                                         *next++ = '\0';
2726                                         return( tmp );
2727                                 }
2728                         }
2729                         next++;
2730                         break;
2731                 }
2732         }
2733
2734         return( tmp );
2735 }
2736
2737 static char     buf[BUFSIZ];
2738 static char     *line;
2739 static size_t lmax, lcur;
2740
2741 #define CATLINE( buf ) \
2742         do { \
2743                 size_t len = strlen( buf ); \
2744                 while ( lcur + len + 1 > lmax ) { \
2745                         lmax += BUFSIZ; \
2746                         line = (char *) ch_realloc( line, lmax ); \
2747                 } \
2748                 strcpy( line + lcur, buf ); \
2749                 lcur += len; \
2750         } while( 0 )
2751
2752 static char *
2753 fp_getline( FILE *fp, int *lineno )
2754 {
2755         char            *p;
2756
2757         lcur = 0;
2758         CATLINE( buf );
2759         (*lineno)++;
2760
2761         /* hack attack - keeps us from having to keep a stack of bufs... */
2762         if ( strncasecmp( line, "include", 7 ) == 0 ) {
2763                 buf[0] = '\0';
2764                 return( line );
2765         }
2766
2767         while ( fgets( buf, sizeof(buf), fp ) != NULL ) {
2768                 /* trim off \r\n or \n */
2769                 if ( (p = strchr( buf, '\n' )) != NULL ) {
2770                         if( p > buf && p[-1] == '\r' ) --p;
2771                         *p = '\0';
2772                 }
2773                 
2774                 /* trim off trailing \ and append the next line */
2775                 if ( line[ 0 ] != '\0' 
2776                                 && (p = line + strlen( line ) - 1)[ 0 ] == '\\'
2777                                 && p[ -1 ] != '\\' ) {
2778                         p[ 0 ] = '\0';
2779                         lcur--;
2780
2781                 } else {
2782                         if ( ! isspace( (unsigned char) buf[0] ) ) {
2783                                 return( line );
2784                         }
2785
2786                         /* change leading whitespace to a space */
2787                         buf[0] = ' ';
2788                 }
2789
2790                 CATLINE( buf );
2791                 (*lineno)++;
2792         }
2793         buf[0] = '\0';
2794
2795         return( line[0] ? line : NULL );
2796 }
2797
2798 static void
2799 fp_getline_init( int *lineno )
2800 {
2801         *lineno = -1;
2802         buf[0] = '\0';
2803 }
2804
2805 /* Loads ucdata, returns 1 if loading, 0 if already loaded, -1 on error */
2806 static int
2807 load_ucdata( char *path )
2808 {
2809         static int loaded = 0;
2810         int err;
2811         
2812         if ( loaded ) {
2813                 return( 0 );
2814         }
2815         err = ucdata_load( path ? path : SLAPD_DEFAULT_UCDATA, UCDATA_ALL );
2816         if ( err ) {
2817 #ifdef NEW_LOGGING
2818                 LDAP_LOG( CONFIG, CRIT, 
2819                         "load_ucdata: Error %d loading ucdata.\n", err, 0,0 );
2820 #else
2821                 Debug( LDAP_DEBUG_ANY, "error loading ucdata (error %d)\n",
2822                        err, 0, 0 );
2823 #endif
2824
2825                 return( -1 );
2826         }
2827         loaded = 1;
2828         return( 1 );
2829 }
2830
2831 void
2832 config_destroy( )
2833 {
2834         ucdata_unload( UCDATA_ALL );
2835         free( global_schemandn.bv_val );
2836         free( global_schemadn.bv_val );
2837         free( line );
2838         if ( slapd_args_file )
2839                 free ( slapd_args_file );
2840         if ( slapd_pid_file )
2841                 free ( slapd_pid_file );
2842         if ( default_passwd_hash )
2843                 ldap_charray_free( default_passwd_hash );
2844         acl_destroy( global_acl, NULL );
2845 }
2846
2847 static int
2848 add_syncrepl(
2849         Backend *be,
2850         char    **cargv,
2851         int     cargc
2852 )
2853 {
2854         syncinfo_t *si;
2855         syncinfo_t *si_entry;
2856         int     rc = 0;
2857         int duplicated_replica_id = 0;
2858
2859         si = (syncinfo_t *) ch_calloc( 1, sizeof( syncinfo_t ) );
2860
2861         if ( si == NULL ) {
2862 #ifdef NEW_LOGGING
2863                 LDAP_LOG( CONFIG, ERR, "out of memory in add_syncrepl\n", 0, 0,0 );
2864 #else
2865                 Debug( LDAP_DEBUG_ANY, "out of memory in add_syncrepl\n", 0, 0, 0 );
2866 #endif
2867                 return 1;
2868         }
2869
2870         si->si_tls = SYNCINFO_TLS_OFF;
2871         if ( be->be_rootndn.bv_val ) {
2872                 ber_dupbv( &si->si_updatedn, &be->be_rootndn );
2873         }
2874         si->si_bindmethod = LDAP_AUTH_SIMPLE;
2875         si->si_schemachecking = 0;
2876         ber_str2bv( "(objectclass=*)", sizeof("(objectclass=*)")-1, 0,
2877                 &si->si_filterstr );
2878         si->si_base.bv_val = NULL;
2879         si->si_scope = LDAP_SCOPE_SUBTREE;
2880         si->si_attrsonly = 0;
2881         si->si_attrs = (char **) ch_calloc( 1, sizeof( char * ));
2882         si->si_attrs[0] = NULL;
2883         si->si_type = LDAP_SYNC_REFRESH_ONLY;
2884         si->si_interval = 86400;
2885         si->si_syncCookie.ctxcsn = NULL;
2886         si->si_syncCookie.octet_str = NULL;
2887         si->si_syncCookie.sid = -1;
2888         si->si_manageDSAit = 0;
2889         si->si_tlimit = -1;
2890         si->si_slimit = -1;
2891         si->si_syncUUID_ndn.bv_val = NULL;
2892         si->si_syncUUID_ndn.bv_len = 0;
2893
2894         si->si_presentlist = NULL;
2895         LDAP_LIST_INIT( &si->si_nonpresentlist );
2896
2897         rc = parse_syncrepl_line( cargv, cargc, si );
2898
2899         LDAP_STAILQ_FOREACH( si_entry, &be->be_syncinfo, si_next ) {
2900                 if ( si->si_rid == si_entry->si_rid ) {
2901 #ifdef NEW_LOGGING
2902                         LDAP_LOG( CONFIG, ERR,
2903                                 "add_syncrepl: duplicated replica id\n", 0, 0,0 );
2904 #else
2905                         Debug( LDAP_DEBUG_ANY,
2906                                 "add_syncrepl: duplicated replica id\n",0, 0, 0 );
2907 #endif
2908                         duplicated_replica_id = 1;
2909                         break;
2910                 }
2911         }
2912
2913         if ( rc < 0 || duplicated_replica_id ) {
2914                 syncinfo_t *si_entry;
2915                 /* Something bad happened - back out */
2916 #ifdef NEW_LOGGING
2917                 LDAP_LOG( CONFIG, ERR, "failed to add syncinfo\n", 0, 0,0 );
2918 #else
2919                 Debug( LDAP_DEBUG_ANY, "failed to add syncinfo\n", 0, 0, 0 );
2920 #endif
2921
2922                 /* If error, remove all syncinfo */
2923                 LDAP_STAILQ_FOREACH( si_entry, &be->be_syncinfo, si_next ) {
2924                         if ( si_entry->si_updatedn.bv_val ) {
2925                                 ch_free( si->si_updatedn.bv_val );
2926                         }
2927                         if ( si_entry->si_filterstr.bv_val ) {
2928                                 ch_free( si->si_filterstr.bv_val );
2929                         }
2930                         if ( si_entry->si_attrs ) {
2931                                 int i = 0;
2932                                 while ( si_entry->si_attrs[i] != NULL ) {
2933                                         ch_free( si_entry->si_attrs[i] );
2934                                         i++;
2935                                 }
2936                                 ch_free( si_entry->si_attrs );
2937                         }
2938                 }
2939
2940                 while ( !LDAP_STAILQ_EMPTY( &be->be_syncinfo )) {
2941                         si_entry = LDAP_STAILQ_FIRST( &be->be_syncinfo );
2942                         LDAP_STAILQ_REMOVE_HEAD( &be->be_syncinfo, si_next );
2943                         ch_free( si_entry );
2944                 }
2945                 LDAP_STAILQ_INIT( &be->be_syncinfo );
2946                 return 1;
2947         } else {
2948 #ifdef NEW_LOGGING
2949                 LDAP_LOG ( CONFIG, RESULTS,
2950                         "add_syncrepl: Config: ** successfully added syncrepl \"%s\"\n",
2951                         si->si_provideruri == NULL ? "(null)" : si->si_provideruri, 0, 0 );
2952 #else
2953                 Debug( LDAP_DEBUG_CONFIG,
2954                         "Config: ** successfully added syncrepl \"%s\"\n",
2955                         si->si_provideruri == NULL ? "(null)" : si->si_provideruri, 0, 0 );
2956 #endif
2957                 if ( !si->si_schemachecking ) {
2958                         SLAP_DBFLAGS(be) |= SLAP_DBFLAG_NO_SCHEMA_CHECK;
2959                 }
2960                 si->si_be = be;
2961                 LDAP_STAILQ_INSERT_TAIL( &be->be_syncinfo, si, si_next );
2962                 return 0;
2963         }
2964 }
2965
2966 #define IDSTR                   "rid"
2967 #define PROVIDERSTR             "provider"
2968 #define SUFFIXSTR               "suffix"
2969 #define UPDATEDNSTR             "updatedn"
2970 #define BINDMETHSTR             "bindmethod"
2971 #define SIMPLESTR               "simple"
2972 #define SASLSTR                 "sasl"
2973 #define BINDDNSTR               "binddn"
2974 #define CREDSTR                 "credentials"
2975 #define OLDAUTHCSTR             "bindprincipal"
2976 #define AUTHCSTR                "authcID"
2977 #define AUTHZSTR                "authzID"
2978 #define SRVTABSTR               "srvtab"
2979 #define SASLMECHSTR             "saslmech"
2980 #define REALMSTR                "realm"
2981 #define SECPROPSSTR             "secprops"
2982 #define STARTTLSSTR             "starttls"
2983 #define CRITICALSTR             "critical"
2984
2985 #define SCHEMASTR               "schemachecking"
2986 #define FILTERSTR               "filter"
2987 #define SEARCHBASESTR   "searchbase"
2988 #define SCOPESTR                "scope"
2989 #define ATTRSSTR                "attrs"
2990 #define ATTRSONLYSTR    "attrsonly"
2991 #define TYPESTR                 "type"
2992 #define INTERVALSTR             "interval"
2993 #define LASTMODSTR              "lastmod"
2994 #define LMREQSTR                "req"
2995 #define LMGENSTR                "gen"
2996 #define LMNOSTR                 "no"
2997 #define MANAGEDSAITSTR  "manageDSAit"
2998 #define SLIMITSTR               "sizelimit"
2999 #define TLIMITSTR               "timelimit"
3000
3001 #define GOT_ID                  0x0001
3002 #define GOT_PROVIDER    0x0002
3003 #define GOT_METHOD              0x0004
3004 #define GOT_ALL                 0x0007
3005
3006 static int
3007 parse_syncrepl_line(
3008         char            **cargv,
3009         int             cargc,
3010         syncinfo_t      *si
3011 )
3012 {
3013         int     gots = 0;
3014         int     i, j;
3015         char    *hp, *val;
3016         int     nr_attr = 0;
3017
3018         for ( i = 1; i < cargc; i++ ) {
3019                 if ( !strncasecmp( cargv[ i ], IDSTR, sizeof( IDSTR ) - 1 )) {
3020                         int tmp;
3021                         /* '\0' string terminator accounts for '=' */
3022                         val = cargv[ i ] + sizeof( IDSTR );
3023                         tmp= atoi( val );
3024                         if ( tmp >= 1000 || tmp < 0 ) {
3025                                 fprintf( stderr, "Error: parse_syncrepl_line: "
3026                                          "syncrepl id %d is out of range [0..999]\n", tmp );
3027                                 return -1;
3028                         }
3029                         si->si_rid = tmp;
3030                         gots |= GOT_ID;
3031                 } else if ( !strncasecmp( cargv[ i ], PROVIDERSTR,
3032                                         sizeof( PROVIDERSTR ) - 1 )) {
3033                         val = cargv[ i ] + sizeof( PROVIDERSTR );
3034                         si->si_provideruri = ch_strdup( val );
3035                         si->si_provideruri_bv = (BerVarray)
3036                                 ch_calloc( 2, sizeof( struct berval ));
3037                         ber_str2bv( si->si_provideruri, strlen( si->si_provideruri ),
3038                                 0, &si->si_provideruri_bv[0] );
3039                         si->si_provideruri_bv[1].bv_len = 0;
3040                         si->si_provideruri_bv[1].bv_val = NULL;
3041                         gots |= GOT_PROVIDER;
3042                 } else if ( !strncasecmp( cargv[ i ], STARTTLSSTR,
3043                         sizeof(STARTTLSSTR) - 1 ) )
3044                 {
3045                         val = cargv[ i ] + sizeof( STARTTLSSTR );
3046                         if( !strcasecmp( val, CRITICALSTR ) ) {
3047                                 si->si_tls = SYNCINFO_TLS_CRITICAL;
3048                         } else {
3049                                 si->si_tls = SYNCINFO_TLS_ON;
3050                         }
3051                 } else if ( !strncasecmp( cargv[ i ],
3052                         UPDATEDNSTR, sizeof( UPDATEDNSTR ) - 1 ) )
3053                 {
3054                         struct berval updatedn = {0, NULL};
3055                         val = cargv[ i ] + sizeof( UPDATEDNSTR );
3056                         ber_str2bv( val, 0, 0, &updatedn );
3057                         ch_free( si->si_updatedn.bv_val );
3058                         dnNormalize( 0, NULL, NULL, &updatedn, &si->si_updatedn, NULL );
3059                 } else if ( !strncasecmp( cargv[ i ], BINDMETHSTR,
3060                                 sizeof( BINDMETHSTR ) - 1 ) )
3061                 {
3062                         val = cargv[ i ] + sizeof( BINDMETHSTR );
3063                         if ( !strcasecmp( val, SIMPLESTR )) {
3064                                 si->si_bindmethod = LDAP_AUTH_SIMPLE;
3065                                 gots |= GOT_METHOD;
3066                         } else if ( !strcasecmp( val, SASLSTR )) {
3067 #ifdef HAVE_CYRUS_SASL
3068                                 si->si_bindmethod = LDAP_AUTH_SASL;
3069                                 gots |= GOT_METHOD;
3070 #else /* HAVE_CYRUS_SASL */
3071                                 fprintf( stderr, "Error: parse_syncrepl_line: "
3072                                         "not compiled with SASL support\n" );
3073                                 return 1;
3074 #endif /* HAVE_CYRUS_SASL */
3075                         } else {
3076                                 si->si_bindmethod = -1;
3077                         }
3078                 } else if ( !strncasecmp( cargv[ i ],
3079                                 BINDDNSTR, sizeof( BINDDNSTR ) - 1 ) ) {
3080                         val = cargv[ i ] + sizeof( BINDDNSTR );
3081                         si->si_binddn = ch_strdup( val );
3082                 } else if ( !strncasecmp( cargv[ i ],
3083                                 CREDSTR, sizeof( CREDSTR ) - 1 ) ) {
3084                         val = cargv[ i ] + sizeof( CREDSTR );
3085                         si->si_passwd = ch_strdup( val );
3086                 } else if ( !strncasecmp( cargv[ i ],
3087                                 SASLMECHSTR, sizeof( SASLMECHSTR ) - 1 ) ) {
3088                         val = cargv[ i ] + sizeof( SASLMECHSTR );
3089                         si->si_saslmech = ch_strdup( val );
3090                 } else if ( !strncasecmp( cargv[ i ],
3091                                 SECPROPSSTR, sizeof( SECPROPSSTR ) - 1 ) ) {
3092                         val = cargv[ i ] + sizeof( SECPROPSSTR );
3093                         si->si_secprops = ch_strdup( val );
3094                 } else if ( !strncasecmp( cargv[ i ],
3095                                 REALMSTR, sizeof( REALMSTR ) - 1 ) ) {
3096                         val = cargv[ i ] + sizeof( REALMSTR );
3097                         si->si_realm = ch_strdup( val );
3098                 } else if ( !strncasecmp( cargv[ i ],
3099                                 AUTHCSTR, sizeof( AUTHCSTR ) - 1 ) ) {
3100                         val = cargv[ i ] + sizeof( AUTHCSTR );
3101                         si->si_authcId = ch_strdup( val );
3102                 } else if ( !strncasecmp( cargv[ i ],
3103                                 OLDAUTHCSTR, sizeof( OLDAUTHCSTR ) - 1 ) ) {
3104                         /* Old authcID is provided for some backwards compatibility */
3105                         val = cargv[ i ] + sizeof( OLDAUTHCSTR );
3106                         si->si_authcId = ch_strdup( val );
3107                 } else if ( !strncasecmp( cargv[ i ],
3108                                 AUTHZSTR, sizeof( AUTHZSTR ) - 1 ) ) {
3109                         val = cargv[ i ] + sizeof( AUTHZSTR );
3110                         si->si_authzId = ch_strdup( val );
3111                 } else if ( !strncasecmp( cargv[ i ],
3112                                 SCHEMASTR, sizeof( SCHEMASTR ) - 1 ) )
3113                 {
3114                         val = cargv[ i ] + sizeof( SCHEMASTR );
3115                         if ( !strncasecmp( val, "on", sizeof( "on" ) - 1 )) {
3116                                 si->si_schemachecking = 1;
3117                         } else if ( !strncasecmp( val, "off", sizeof( "off" ) - 1 ) ) {
3118                                 si->si_schemachecking = 0;
3119                         } else {
3120                                 si->si_schemachecking = 1;
3121                         }
3122                 } else if ( !strncasecmp( cargv[ i ],
3123                         FILTERSTR, sizeof( FILTERSTR ) - 1 ) )
3124                 {
3125                         val = cargv[ i ] + sizeof( FILTERSTR );
3126                         ber_str2bv( val, 0, 1, &si->si_filterstr );
3127                 } else if ( !strncasecmp( cargv[ i ],
3128                         SEARCHBASESTR, sizeof( SEARCHBASESTR ) - 1 ) )
3129                 {
3130                         struct berval bv;
3131                         val = cargv[ i ] + sizeof( SEARCHBASESTR );
3132                         if ( si->si_base.bv_val ) {
3133                                 ch_free( si->si_base.bv_val );
3134                         }
3135                         ber_str2bv( val, 0, 0, &bv );
3136                         if ( dnNormalize( 0, NULL, NULL, &bv, &si->si_base, NULL )) {
3137                                 fprintf( stderr, "Invalid base DN \"%s\"\n", val );
3138                                 return 1;
3139                         }
3140                 } else if ( !strncasecmp( cargv[ i ],
3141                         SCOPESTR, sizeof( SCOPESTR ) - 1 ) )
3142                 {
3143                         val = cargv[ i ] + sizeof( SCOPESTR );
3144                         if ( !strncasecmp( val, "base", sizeof( "base" ) - 1 )) {
3145                                 si->si_scope = LDAP_SCOPE_BASE;
3146                         } else if ( !strncasecmp( val, "one", sizeof( "one" ) - 1 )) {
3147                                 si->si_scope = LDAP_SCOPE_ONELEVEL;
3148 #ifdef LDAP_SCOPE_SUBORDINATE
3149                         } else if ( !strcasecmp( val, "subordinate" ) ||
3150                                 !strcasecmp( val, "children" ))
3151                         {
3152                                 si->si_scope = LDAP_SCOPE_SUBORDINATE;
3153 #endif
3154                         } else if ( !strncasecmp( val, "sub", sizeof( "sub" ) - 1 )) {
3155                                 si->si_scope = LDAP_SCOPE_SUBTREE;
3156                         } else {
3157                                 fprintf( stderr, "Error: parse_syncrepl_line: "
3158                                         "unknown scope \"%s\"\n", val);
3159                                 return 1;
3160                         }
3161                 } else if ( !strncasecmp( cargv[ i ],
3162                         ATTRSONLYSTR, sizeof( ATTRSONLYSTR ) - 1 ) )
3163                 {
3164                         si->si_attrsonly = 1;
3165                 } else if ( !strncasecmp( cargv[ i ],
3166                         ATTRSSTR, sizeof( ATTRSSTR ) - 1 ) )
3167                 {
3168                         val = cargv[ i ] + sizeof( ATTRSSTR );
3169                         str2clist( &si->si_attrs, val, "," );
3170                 } else if ( !strncasecmp( cargv[ i ],
3171                         TYPESTR, sizeof( TYPESTR ) - 1 ) )
3172                 {
3173                         val = cargv[ i ] + sizeof( TYPESTR );
3174                         if ( !strncasecmp( val, "refreshOnly", sizeof("refreshOnly")-1 )) {
3175                                 si->si_type = LDAP_SYNC_REFRESH_ONLY;
3176                         } else if ( !strncasecmp( val, "refreshAndPersist",
3177                                 sizeof("refreshAndPersist")-1 ))
3178                         {
3179                                 si->si_type = LDAP_SYNC_REFRESH_AND_PERSIST;
3180                                 si->si_interval = 60;
3181                         } else {
3182                                 fprintf( stderr, "Error: parse_syncrepl_line: "
3183                                         "unknown sync type \"%s\"\n", val);
3184                                 return 1;
3185                         }
3186                 } else if ( !strncasecmp( cargv[ i ],
3187                         INTERVALSTR, sizeof( INTERVALSTR ) - 1 ) )
3188                 {
3189                         val = cargv[ i ] + sizeof( INTERVALSTR );
3190                         if ( si->si_type == LDAP_SYNC_REFRESH_AND_PERSIST ) {
3191                                 si->si_interval = 0;
3192                         } else {
3193                                 char *hstr;
3194                                 char *mstr;
3195                                 char *dstr;
3196                                 char *sstr;
3197                                 int dd, hh, mm, ss;
3198                                 dstr = val;
3199                                 hstr = strchr( dstr, ':' );
3200                                 if ( hstr == NULL ) {
3201                                         fprintf( stderr, "Error: parse_syncrepl_line: "
3202                                                 "invalid interval \"%s\"\n", val );
3203                                         return 1;
3204                                 }
3205                                 *hstr++ = '\0';
3206                                 mstr = strchr( hstr, ':' );
3207                                 if ( mstr == NULL ) {
3208                                         fprintf( stderr, "Error: parse_syncrepl_line: "
3209                                                 "invalid interval \"%s\"\n", val );
3210                                         return 1;
3211                                 }
3212                                 *mstr++ = '\0';
3213                                 sstr = strchr( mstr, ':' );
3214                                 if ( sstr == NULL ) {
3215                                         fprintf( stderr, "Error: parse_syncrepl_line: "
3216                                                 "invalid interval \"%s\"\n", val );
3217                                         return 1;
3218                                 }
3219                                 *sstr++ = '\0';
3220
3221                                 dd = atoi( dstr );
3222                                 hh = atoi( hstr );
3223                                 mm = atoi( mstr );
3224                                 ss = atoi( sstr );
3225                                 if (( hh > 24 ) || ( hh < 0 ) ||
3226                                         ( mm > 60 ) || ( mm < 0 ) ||
3227                                         ( ss > 60 ) || ( ss < 0 ) || ( dd < 0 )) {
3228                                         fprintf( stderr, "Error: parse_syncrepl_line: "
3229                                                 "invalid interval \"%s\"\n", val );
3230                                         return 1;
3231                                 }
3232                                 si->si_interval = (( dd * 24 + hh ) * 60 + mm ) * 60 + ss;
3233                         }
3234                         if ( si->si_interval < 0 ) {
3235                                 fprintf( stderr, "Error: parse_syncrepl_line: "
3236                                         "invalid interval \"%ld\"\n",
3237                                         (long) si->si_interval);
3238                                 return 1;
3239                         }
3240                 } else if ( !strncasecmp( cargv[ i ],
3241                         MANAGEDSAITSTR, sizeof( MANAGEDSAITSTR ) - 1 ) )
3242                 {
3243                         val = cargv[ i ] + sizeof( MANAGEDSAITSTR );
3244                         si->si_manageDSAit = atoi( val );
3245                 } else if ( !strncasecmp( cargv[ i ],
3246                         SLIMITSTR, sizeof( SLIMITSTR ) - 1 ) )
3247                 {
3248                         val = cargv[ i ] + sizeof( SLIMITSTR );
3249                         si->si_slimit = atoi( val );
3250                 } else if ( !strncasecmp( cargv[ i ],
3251                         TLIMITSTR, sizeof( TLIMITSTR ) - 1 ) )
3252                 {
3253                         val = cargv[ i ] + sizeof( TLIMITSTR );
3254                         si->si_tlimit = atoi( val );
3255                 } else {
3256                         fprintf( stderr, "Error: parse_syncrepl_line: "
3257                                 "unknown keyword \"%s\"\n", cargv[ i ] );
3258                 }
3259         }
3260
3261         if ( gots != GOT_ALL ) {
3262                 fprintf( stderr,
3263                         "Error: Malformed \"syncrepl\" line in slapd config file" );
3264                 return -1;
3265         }
3266
3267         return 0;
3268 }
3269
3270 char **
3271 str2clist( char ***out, char *in, const char *brkstr )
3272 {
3273         char    *str;
3274         char    *s;
3275         char    *lasts;
3276         int     i, j;
3277         const char *text;
3278         char    **new;
3279
3280         /* find last element in list */
3281         for (i = 0; *out && *out[i]; i++);
3282
3283         /* protect the input string from strtok */
3284         str = ch_strdup( in );
3285
3286         if ( *str == '\0' ) {
3287                 free( str );
3288                 return( *out );
3289         }
3290
3291         /* Count words in string */
3292         j=1;
3293         for ( s = str; *s; s++ ) {
3294                 if ( strchr( brkstr, *s ) != NULL ) {
3295                         j++;
3296                 }
3297         }
3298
3299         *out = ch_realloc( *out, ( i + j + 1 ) * sizeof( char * ) );
3300         new = *out + i;
3301         for ( s = ldap_pvt_strtok( str, brkstr, &lasts );
3302                 s != NULL;
3303                 s = ldap_pvt_strtok( NULL, brkstr, &lasts ) )
3304         {
3305                 *new = ch_strdup( s );
3306                 new++;
3307         }
3308
3309         *new = NULL;
3310         free( str );
3311         return( *out );
3312 }