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