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