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