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