]> git.sur5r.net Git - openldap/blob - servers/slapd/config.c
a8b343a9eccb902fffd96804609828ac9c426eaa
[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 int     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                         if ( be == NULL ) {
1752 #ifdef NEW_LOGGING
1753                                 LDAP_LOG( CONFIG, INFO, 
1754                                             "%s: line %d: syncrepl line must appear inside "
1755                                             "a database definition.\n", fname, lineno, 0);
1756 #else
1757                                 Debug( LDAP_DEBUG_ANY,
1758                                             "%s: line %d: syncrepl line must appear inside "
1759                                             "a database definition.\n", fname, lineno, 0);
1760 #endif
1761                                 return 1;
1762                         } else {
1763                                 if ( add_syncrepl( be, cargv, cargc )) {
1764                                         return 1;
1765                                 }
1766                         }
1767
1768                 /* list of replicas of the data in this backend (master only) */
1769                 } else if ( strcasecmp( cargv[0], "replica" ) == 0 ) {
1770                         if ( cargc < 2 ) {
1771 #ifdef NEW_LOGGING
1772                                 LDAP_LOG( CONFIG, CRIT, 
1773                                         "%s: line %d: missing host or uri in \"replica "
1774                                         " <host[:port]\" line\n", fname, lineno , 0 );
1775 #else
1776                                 Debug( LDAP_DEBUG_ANY,
1777             "%s: line %d: missing host or uri in \"replica <host[:port]>\" line\n",
1778                                     fname, lineno, 0 );
1779 #endif
1780
1781                                 return( 1 );
1782                         }
1783                         if ( be == NULL ) {
1784 #ifdef NEW_LOGGING
1785                                 LDAP_LOG( CONFIG, INFO, 
1786                                             "%s: line %d: replica line must appear inside "
1787                                             "a database definition.\n", fname, lineno, 0);
1788 #else
1789                                 Debug( LDAP_DEBUG_ANY,
1790 "%s: line %d: replica line must appear inside a database definition\n",
1791                                     fname, lineno, 0 );
1792 #endif
1793                                 return 1;
1794
1795                         } else {
1796                                 int nr = -1;
1797
1798                                 for ( i = 1; i < cargc; i++ ) {
1799                                         if ( strncasecmp( cargv[i], "host=", 5 )
1800                                             == 0 ) {
1801                                                 nr = add_replica_info( be, 
1802                                                         cargv[i] + 5 );
1803                                                 break;
1804                                         } else if (strncasecmp( cargv[i], "uri=", 4 )
1805                                             == 0 ) {
1806                                             if ( ldap_url_parse( cargv[ i ] + 4, &ludp )
1807                                                 != LDAP_SUCCESS ) {
1808 #ifdef NEW_LOGGING
1809                                                         LDAP_LOG( CONFIG, INFO, 
1810                                                         "%s: line %d: replica line contains invalid "
1811                                                         "uri definition.\n", fname, lineno, 0);
1812 #else
1813                                                         Debug( LDAP_DEBUG_ANY,
1814                                                         "%s: line %d: replica line contains invalid "
1815                                                         "uri definition.\n", fname, lineno, 0);
1816 #endif
1817                                                         return 1;
1818                                                 }
1819                                                 if (ludp->lud_host == NULL ) {
1820 #ifdef NEW_LOGGING
1821                                                         LDAP_LOG( CONFIG, INFO, 
1822                                                         "%s: line %d: replica line contains invalid "
1823                                                         "uri definition - missing hostname.\n", 
1824                                                         fname, lineno, 0);
1825 #else
1826                                                         Debug( LDAP_DEBUG_ANY,
1827                                                         "%s: line %d: replica line contains invalid "
1828                                                         "uri definition - missing hostname.\n", fname, lineno, 0);
1829 #endif
1830                                                         return 1;
1831                                                 }
1832                                         replicahost = ch_malloc( strlen( cargv[ i ] ) );
1833                                                 if ( replicahost == NULL ) {
1834 #ifdef NEW_LOGGING
1835                                                         LDAP_LOG( CONFIG, ERR, 
1836                                                         "out of memory in read_config\n", 0, 0,0 );
1837 #else
1838                                                         Debug( LDAP_DEBUG_ANY, 
1839                                                         "out of memory in read_config\n", 0, 0, 0 );
1840 #endif
1841                                                         ldap_free_urldesc( ludp );                              
1842                                                         exit( EXIT_FAILURE );
1843                                                 }
1844                                                 sprintf(replicahost, "%s:%d", 
1845                                                         ludp->lud_host, ludp->lud_port);
1846                                                 nr = add_replica_info( be, replicahost );
1847                                                 ldap_free_urldesc( ludp );                              
1848                                                 ch_free(replicahost);
1849                                                 break;
1850                                         }
1851                                 }
1852                                 if ( i == cargc ) {
1853 #ifdef NEW_LOGGING
1854                                         LDAP_LOG( CONFIG, INFO, 
1855                                                 "%s: line %d: missing host or uri in \"replica\" line\n", 
1856                                                 fname, lineno , 0 );
1857 #else
1858                                         Debug( LDAP_DEBUG_ANY,
1859                     "%s: line %d: missing host or uri in \"replica\" line\n",
1860                                             fname, lineno, 0 );
1861 #endif
1862                                         return 1;
1863
1864                                 } else if ( nr == -1 ) {
1865 #ifdef NEW_LOGGING
1866                                         LDAP_LOG( CONFIG, INFO, 
1867                                                    "%s: line %d: unable to add"
1868                                                    " replica \"%s\"\n",
1869                                                    fname, lineno, 
1870                                                    cargv[i] + 5 );
1871 #else
1872                                         Debug( LDAP_DEBUG_ANY,
1873                 "%s: line %d: unable to add replica \"%s\"\n",
1874                                                 fname, lineno, cargv[i] + 5 );
1875 #endif
1876                                         return 1;
1877                                 } else {
1878                                         for ( i = 1; i < cargc; i++ ) {
1879                                                 if ( strncasecmp( cargv[i], "suffix=", 7 ) == 0 ) {
1880
1881                                                         switch ( add_replica_suffix( be, nr, cargv[i] + 7 ) ) {
1882                                                         case 1:
1883 #ifdef NEW_LOGGING
1884                                                                 LDAP_LOG( CONFIG, INFO, 
1885                                                                         "%s: line %d: suffix \"%s\" in \"replica\""
1886                                                                         " line is not valid for backend(ignored)\n",
1887                                                                         fname, lineno, cargv[i] + 7 );
1888 #else
1889                                                                 Debug( LDAP_DEBUG_ANY,
1890                                                                                 "%s: line %d: suffix \"%s\" in \"replica\" line is not valid for backend (ignored)\n",
1891                                                                                 fname, lineno, cargv[i] + 7 );
1892 #endif
1893                                                                 break;
1894
1895                                                         case 2:
1896 #ifdef NEW_LOGGING
1897                                                                 LDAP_LOG( CONFIG, INFO, 
1898                                                                         "%s: line %d: unable to normalize suffix"
1899                                                                         " in \"replica\" line (ignored)\n",
1900                                                                         fname, lineno , 0 );
1901 #else
1902                                                                 Debug( LDAP_DEBUG_ANY,
1903                                                                                  "%s: line %d: unable to normalize suffix in \"replica\" line (ignored)\n",
1904                                                                                  fname, lineno, 0 );
1905 #endif
1906                                                                 break;
1907                                                         }
1908
1909                                                 } else if ( strncasecmp( cargv[i], "attr", 4 ) == 0 ) {
1910                                                         int exclude = 0;
1911                                                         char *arg = cargv[i] + 4;
1912
1913                                                         if ( arg[0] == '!' ) {
1914                                                                 arg++;
1915                                                                 exclude = 1;
1916                                                         }
1917
1918                                                         if ( arg[0] != '=' ) {
1919                                                                 continue;
1920                                                         }
1921
1922                                                         if ( add_replica_attrs( be, nr, arg + 1, exclude ) ) {
1923 #ifdef NEW_LOGGING
1924                                                                 LDAP_LOG( CONFIG, INFO, 
1925                                                                         "%s: line %d: attribute \"%s\" in "
1926                                                                         "\"replica\" line is unknown\n",
1927                                                                         fname, lineno, arg + 1 ); 
1928 #else
1929                                                                 Debug( LDAP_DEBUG_ANY,
1930                                                                                 "%s: line %d: attribute \"%s\" in \"replica\" line is unknown\n",
1931                                                                                 fname, lineno, arg + 1 );
1932 #endif
1933                                                                 return( 1 );
1934                                                         }
1935                                                 }
1936                                         }
1937                                 }
1938                         }
1939
1940                 /* dn of master entity allowed to write to replica */
1941                 } else if ( strcasecmp( cargv[0], "updatedn" ) == 0 ) {
1942                         if ( cargc < 2 ) {
1943 #ifdef NEW_LOGGING
1944                                 LDAP_LOG( CONFIG, CRIT, 
1945                                         "%s: line %d: missing dn in \"updatedn <dn>\""
1946                                         " line.\n", fname, lineno , 0 );
1947 #else
1948                                 Debug( LDAP_DEBUG_ANY,
1949                     "%s: line %d: missing dn in \"updatedn <dn>\" line\n",
1950                                     fname, lineno, 0 );
1951 #endif
1952
1953                                 return( 1 );
1954                         }
1955                         if ( be == NULL ) {
1956 #ifdef NEW_LOGGING
1957                                 LDAP_LOG( CONFIG, INFO, 
1958                                         "%s: line %d: updatedn line must appear inside "
1959                                         "a database definition\n", 
1960                                         fname, lineno , 0 );
1961 #else
1962                                 Debug( LDAP_DEBUG_ANY,
1963 "%s: line %d: updatedn line must appear inside a database definition\n",
1964                                     fname, lineno, 0 );
1965 #endif
1966                                 return 1;
1967
1968                         } else {
1969                                 struct berval dn;
1970
1971                                 if ( load_ucdata( NULL ) < 0 ) return 1;
1972
1973                                 dn.bv_val = cargv[1];
1974                                 dn.bv_len = strlen( cargv[1] );
1975
1976                                 rc = dnNormalize( 0, NULL, NULL, &dn, &be->be_update_ndn, NULL );
1977                                 if( rc != LDAP_SUCCESS ) {
1978 #ifdef NEW_LOGGING
1979                                         LDAP_LOG( CONFIG, CRIT, 
1980                                                 "%s: line %d: updatedn DN is invalid.\n",
1981                                                 fname, lineno , 0 );
1982 #else
1983                                         Debug( LDAP_DEBUG_ANY,
1984                                                 "%s: line %d: updatedn DN is invalid\n",
1985                                             fname, lineno, 0 );
1986 #endif
1987                                         return 1;
1988                                 }
1989                         }
1990
1991                 } else if ( strcasecmp( cargv[0], "updateref" ) == 0 ) {
1992                         if ( cargc < 2 ) {
1993 #ifdef NEW_LOGGING
1994                                 LDAP_LOG( CONFIG, CRIT, "%s: line %d: "
1995                                         "missing url in \"updateref <ldapurl>\" line.\n",
1996                                         fname, lineno , 0 );
1997 #else
1998                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1999                                         "missing url in \"updateref <ldapurl>\" line\n",
2000                                     fname, lineno, 0 );
2001 #endif
2002
2003                                 return( 1 );
2004                         }
2005                         if ( be == NULL ) {
2006 #ifdef NEW_LOGGING
2007                                 LDAP_LOG( CONFIG, INFO, "%s: line %d: updateref"
2008                                         " line must appear inside a database definition\n",
2009                                         fname, lineno , 0 );
2010 #else
2011                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: updateref"
2012                                         " line must appear inside a database definition\n",
2013                                         fname, lineno, 0 );
2014 #endif
2015                                 return 1;
2016
2017                         } else if ( !be->be_update_ndn.bv_len ) {
2018 #ifdef NEW_LOGGING
2019                                 LDAP_LOG( CONFIG, INFO, "%s: line %d: "
2020                                         "updateref line must come after updatedn.\n",
2021                                         fname, lineno , 0 );
2022 #else
2023                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
2024                                         "updateref line must after updatedn.\n",
2025                                     fname, lineno, 0 );
2026 #endif
2027                                 return 1;
2028                         }
2029
2030                         if( validate_global_referral( cargv[1] ) ) {
2031 #ifdef NEW_LOGGING
2032                                 LDAP_LOG( CONFIG, CRIT, "%s: line %d: "
2033                                         "invalid URL (%s) in \"updateref\" line.\n",
2034                                         fname, lineno, cargv[1] );
2035 #else
2036                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
2037                                         "invalid URL (%s) in \"updateref\" line.\n",
2038                                     fname, lineno, cargv[1] );
2039 #endif
2040                                 return 1;
2041                         }
2042
2043                         vals[0].bv_val = cargv[1];
2044                         vals[0].bv_len = strlen( vals[0].bv_val );
2045                         if( value_add( &be->be_update_refs, vals ) )
2046                                 return LDAP_OTHER;
2047
2048                 /* replication log file to which changes are appended */
2049                 } else if ( strcasecmp( cargv[0], "replogfile" ) == 0 ) {
2050                         if ( cargc < 2 ) {
2051 #ifdef NEW_LOGGING
2052                                 LDAP_LOG( CONFIG, CRIT, 
2053                                         "%s: line %d: missing filename in \"replogfile <filename>\""
2054                                         " line.\n", fname, lineno , 0 );
2055 #else
2056                                 Debug( LDAP_DEBUG_ANY,
2057             "%s: line %d: missing filename in \"replogfile <filename>\" line\n",
2058                                     fname, lineno, 0 );
2059 #endif
2060
2061                                 return( 1 );
2062                         }
2063                         if ( be ) {
2064                                 be->be_replogfile = ch_strdup( cargv[1] );
2065                         } else {
2066                                 replogfile = ch_strdup( cargv[1] );
2067                         }
2068
2069                 /* file from which to read additional rootdse attrs */
2070                 } else if ( strcasecmp( cargv[0], "rootDSE" ) == 0) {
2071                         if ( cargc < 2 ) {
2072 #ifdef NEW_LOGGING
2073                                 LDAP_LOG( CONFIG, CRIT, "%s: line %d: "
2074                                         "missing filename in \"rootDSE <filename>\" line.\n",
2075                                         fname, lineno , 0 );
2076 #else
2077                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
2078                                         "missing filename in \"rootDSE <filename>\" line.\n",
2079                                     fname, lineno, 0 );
2080 #endif
2081                                 return 1;
2082                         }
2083
2084                         if( read_root_dse_file( cargv[1] ) ) {
2085 #ifdef NEW_LOGGING
2086                                 LDAP_LOG( CONFIG, CRIT, "%s: line %d: "
2087                                         "could not read \"rootDSE <filename>\" line.\n",
2088                                         fname, lineno , 0 );
2089 #else
2090                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
2091                                         "could not read \"rootDSE <filename>\" line\n",
2092                                     fname, lineno, 0 );
2093 #endif
2094                                 return 1;
2095                         }
2096
2097                 /* maintain lastmodified{by,time} attributes */
2098                 } else if ( strcasecmp( cargv[0], "lastmod" ) == 0 ) {
2099                         if ( cargc < 2 ) {
2100 #ifdef NEW_LOGGING
2101                                 LDAP_LOG( CONFIG, CRIT, 
2102                                            "%s: line %d: missing on|off in \"lastmod <on|off>\""
2103                                            " line.\n", fname, lineno , 0 );
2104 #else
2105                                 Debug( LDAP_DEBUG_ANY,
2106             "%s: line %d: missing on|off in \"lastmod <on|off>\" line\n",
2107                                     fname, lineno, 0 );
2108 #endif
2109
2110                                 return( 1 );
2111                         }
2112                         if ( strcasecmp( cargv[1], "on" ) == 0 ) {
2113                                 if ( be ) {
2114                                         be->be_flags &= ~SLAP_BFLAG_NOLASTMOD;
2115                                 } else {
2116                                         lastmod = 1;
2117                                 }
2118                         } else {
2119                                 if ( be ) {
2120                                         be->be_flags |= SLAP_BFLAG_NOLASTMOD;
2121                                 } else {
2122                                         lastmod = 0;
2123                                 }
2124                         }
2125
2126 #ifdef SIGHUP
2127                 /* turn on/off gentle SIGHUP handling */
2128                 } else if ( strcasecmp( cargv[0], "gentlehup" ) == 0 ) {
2129                         if ( cargc < 2 ) {
2130                                 Debug( LDAP_DEBUG_ANY,
2131     "%s: line %d: missing on|off in \"gentlehup <on|off>\" line\n",
2132                                     fname, lineno, 0 );
2133                                 return( 1 );
2134                         }
2135                         if ( strcasecmp( cargv[1], "off" ) == 0 ) {
2136                                 global_gentlehup = 0;
2137                         } else {
2138                                 global_gentlehup = 1;
2139                         }
2140 #endif
2141
2142                 /* set idle timeout value */
2143                 } else if ( strcasecmp( cargv[0], "idletimeout" ) == 0 ) {
2144                         int i;
2145                         if ( cargc < 2 ) {
2146 #ifdef NEW_LOGGING
2147                                 LDAP_LOG( CONFIG, CRIT, 
2148                                         "%s: line %d: missing timeout value in "
2149                                         "\"idletimeout <seconds>\" line.\n", fname, lineno , 0 );
2150 #else
2151                                 Debug( LDAP_DEBUG_ANY,
2152             "%s: line %d: missing timeout value in \"idletimeout <seconds>\" line\n",
2153                                     fname, lineno, 0 );
2154 #endif
2155
2156                                 return( 1 );
2157                         }
2158
2159                         i = atoi( cargv[1] );
2160
2161                         if( i < 0 ) {
2162 #ifdef NEW_LOGGING
2163                                 LDAP_LOG( CONFIG, CRIT, 
2164                                         "%s: line %d: timeout value (%d) invalid "
2165                                         "\"idletimeout <seconds>\" line.\n", fname, lineno, i );
2166 #else
2167                                 Debug( LDAP_DEBUG_ANY,
2168             "%s: line %d: timeout value (%d) invalid \"idletimeout <seconds>\" line\n",
2169                                     fname, lineno, i );
2170 #endif
2171
2172                                 return( 1 );
2173                         }
2174
2175                         global_idletimeout = i;
2176
2177                 /* include another config file */
2178                 } else if ( strcasecmp( cargv[0], "include" ) == 0 ) {
2179                         if ( cargc < 2 ) {
2180 #ifdef NEW_LOGGING
2181                                 LDAP_LOG( CONFIG, CRIT, 
2182                                         "%s: line %d: missing filename in \"include "
2183                                         "<filename>\" line.\n", fname, lineno , 0 );
2184 #else
2185                                 Debug( LDAP_DEBUG_ANY,
2186     "%s: line %d: missing filename in \"include <filename>\" line\n",
2187                                     fname, lineno, 0 );
2188 #endif
2189
2190                                 return( 1 );
2191                         }
2192                         savefname = ch_strdup( cargv[1] );
2193                         savelineno = lineno;
2194
2195                         if ( read_config( savefname, depth+1 ) != 0 ) {
2196                                 return( 1 );
2197                         }
2198
2199                         free( savefname );
2200                         lineno = savelineno - 1;
2201
2202                 /* location of kerberos srvtab file */
2203                 } else if ( strcasecmp( cargv[0], "srvtab" ) == 0 ) {
2204                         if ( cargc < 2 ) {
2205 #ifdef NEW_LOGGING
2206                                 LDAP_LOG( CONFIG, CRIT, 
2207                                         "%s: line %d: missing filename in \"srvtab "
2208                                         "<filename>\" line.\n", fname, lineno , 0 );
2209 #else
2210                                 Debug( LDAP_DEBUG_ANY,
2211             "%s: line %d: missing filename in \"srvtab <filename>\" line\n",
2212                                     fname, lineno, 0 );
2213 #endif
2214
2215                                 return( 1 );
2216                         }
2217                         ldap_srvtab = ch_strdup( cargv[1] );
2218
2219 #ifdef SLAPD_MODULES
2220                 } else if (strcasecmp( cargv[0], "moduleload") == 0 ) {
2221                    if ( cargc < 2 ) {
2222 #ifdef NEW_LOGGING
2223                            LDAP_LOG( CONFIG, INFO, 
2224                                    "%s: line %d: missing filename in \"moduleload "
2225                                    "<filename>\" line.\n", fname, lineno , 0 );
2226 #else
2227                       Debug( LDAP_DEBUG_ANY,
2228                              "%s: line %d: missing filename in \"moduleload <filename>\" line\n",
2229                              fname, lineno, 0 );
2230 #endif
2231
2232                       exit( EXIT_FAILURE );
2233                    }
2234                    if (module_load(cargv[1], cargc - 2, (cargc > 2) ? cargv + 2 : NULL)) {
2235 #ifdef NEW_LOGGING
2236                            LDAP_LOG( CONFIG, CRIT, 
2237                                    "%s: line %d: failed to load or initialize module %s\n",
2238                                    fname, lineno, cargv[1] );
2239 #else
2240                       Debug( LDAP_DEBUG_ANY,
2241                              "%s: line %d: failed to load or initialize module %s\n",
2242                              fname, lineno, cargv[1]);
2243 #endif
2244
2245                       exit( EXIT_FAILURE );
2246                    }
2247                 } else if (strcasecmp( cargv[0], "modulepath") == 0 ) {
2248                    if ( cargc != 2 ) {
2249 #ifdef NEW_LOGGING
2250                            LDAP_LOG( CONFIG, INFO, 
2251                                   "%s: line %d: missing path in \"modulepath <path>\""
2252                                   " line\n", fname, lineno , 0 );
2253 #else
2254                       Debug( LDAP_DEBUG_ANY,
2255                              "%s: line %d: missing path in \"modulepath <path>\" line\n",
2256                              fname, lineno, 0 );
2257 #endif
2258
2259                       exit( EXIT_FAILURE );
2260                    }
2261                    if (module_path( cargv[1] )) {
2262 #ifdef NEW_LOGGING
2263                            LDAP_LOG( CONFIG, CRIT, 
2264                                   "%s: line %d: failed to set module search path to %s.\n",
2265                                   fname, lineno, cargv[1] );
2266 #else
2267                            Debug( LDAP_DEBUG_ANY,
2268                                   "%s: line %d: failed to set module search path to %s\n",
2269                                   fname, lineno, cargv[1]);
2270 #endif
2271
2272                       exit( EXIT_FAILURE );
2273                    }
2274                    
2275 #endif /*SLAPD_MODULES*/
2276
2277 #ifdef HAVE_TLS
2278                 } else if ( !strcasecmp( cargv[0], "TLSRandFile" ) ) {
2279                         rc = ldap_pvt_tls_set_option( NULL,
2280                                                       LDAP_OPT_X_TLS_RANDOM_FILE,
2281                                                       cargv[1] );
2282                         if ( rc )
2283                                 return rc;
2284
2285                 } else if ( !strcasecmp( cargv[0], "TLSCipherSuite" ) ) {
2286                         rc = ldap_pvt_tls_set_option( NULL,
2287                                                       LDAP_OPT_X_TLS_CIPHER_SUITE,
2288                                                       cargv[1] );
2289                         if ( rc )
2290                                 return rc;
2291
2292                 } else if ( !strcasecmp( cargv[0], "TLSCertificateFile" ) ) {
2293                         rc = ldap_pvt_tls_set_option( NULL,
2294                                                       LDAP_OPT_X_TLS_CERTFILE,
2295                                                       cargv[1] );
2296                         if ( rc )
2297                                 return rc;
2298
2299                 } else if ( !strcasecmp( cargv[0], "TLSCertificateKeyFile" ) ) {
2300                         rc = ldap_pvt_tls_set_option( NULL,
2301                                                       LDAP_OPT_X_TLS_KEYFILE,
2302                                                       cargv[1] );
2303                         if ( rc )
2304                                 return rc;
2305
2306                 } else if ( !strcasecmp( cargv[0], "TLSCACertificatePath" ) ) {
2307                         rc = ldap_pvt_tls_set_option( NULL,
2308                                                       LDAP_OPT_X_TLS_CACERTDIR,
2309                                                       cargv[1] );
2310                         if ( rc )
2311                                 return rc;
2312
2313                 } else if ( !strcasecmp( cargv[0], "TLSCACertificateFile" ) ) {
2314                         rc = ldap_pvt_tls_set_option( NULL,
2315                                                       LDAP_OPT_X_TLS_CACERTFILE,
2316                                                       cargv[1] );
2317                         if ( rc )
2318                                 return rc;
2319                 } else if ( !strcasecmp( cargv[0], "TLSVerifyClient" ) ) {
2320                         if ( isdigit( (unsigned char) cargv[1][0] ) ) {
2321                                 i = atoi(cargv[1]);
2322                                 rc = ldap_pvt_tls_set_option( NULL,
2323                                                       LDAP_OPT_X_TLS_REQUIRE_CERT,
2324                                                       &i );
2325                         } else {
2326                                 rc = ldap_int_tls_config( NULL,
2327                                                       LDAP_OPT_X_TLS_REQUIRE_CERT,
2328                                                       cargv[1] );
2329                         }
2330
2331                         if ( rc )
2332                                 return rc;
2333
2334 #endif
2335
2336                 } else if ( !strcasecmp( cargv[0], "reverse-lookup" ) ) {
2337 #ifdef SLAPD_RLOOKUPS
2338                         if ( cargc < 2 ) {
2339 #ifdef NEW_LOGGING
2340                                 LDAP_LOG( CONFIG, INFO, 
2341                                         "%s: line %d: reverse-lookup: missing \"on\" or \"off\"\n",
2342                                         fname, lineno , 0 );
2343 #else
2344                                 Debug( LDAP_DEBUG_ANY,
2345 "%s: line %d: reverse-lookup: missing \"on\" or \"off\"\n",
2346                                         fname, lineno, 0 );
2347 #endif
2348                                 return( 1 );
2349                         }
2350
2351                         if ( !strcasecmp( cargv[1], "on" ) ) {
2352                                 use_reverse_lookup = 1;
2353                         } else if ( !strcasecmp( cargv[1], "off" ) ) {
2354                                 use_reverse_lookup = 0;
2355                         } else {
2356 #ifdef NEW_LOGGING
2357                                 LDAP_LOG( CONFIG, INFO, 
2358                                         "%s: line %d: reverse-lookup: "
2359                                         "must be \"on\" (default) or \"off\"\n", fname, lineno, 0 );
2360 #else
2361                                 Debug( LDAP_DEBUG_ANY,
2362 "%s: line %d: reverse-lookup: must be \"on\" (default) or \"off\"\n",
2363                                         fname, lineno, 0 );
2364 #endif
2365                                 return( 1 );
2366                         }
2367
2368 #else /* !SLAPD_RLOOKUPS */
2369 #ifdef NEW_LOGGING
2370                         LDAP_LOG( CONFIG, INFO, 
2371                                 "%s: line %d: reverse lookups "
2372                                 "are not configured (ignored).\n", fname, lineno , 0 );
2373 #else
2374                         Debug( LDAP_DEBUG_ANY,
2375 "%s: line %d: reverse lookups are not configured (ignored).\n",
2376                                 fname, lineno, 0 );
2377 #endif
2378 #endif /* !SLAPD_RLOOKUPS */
2379
2380                 /* Netscape plugins */
2381                 } else if ( strcasecmp( cargv[0], "plugin" ) == 0 ) {
2382 #if defined( LDAP_SLAPI )
2383
2384 #ifdef notdef /* allow global plugins, too */
2385                         /*
2386                          * a "plugin" line must be inside a database
2387                          * definition, since we implement pre-,post- 
2388                          * and extended operation plugins
2389                          */
2390                         if ( be == NULL ) {
2391 #ifdef NEW_LOGGING
2392                                 LDAP_LOG( CONFIG, INFO, 
2393                                         "%s: line %d: plugin line must appear "
2394                                         "insid a database definition.\n",
2395                                         fname, lineno, 0 );
2396 #else
2397                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: plugin "
2398                                     "line must appear inside a database "
2399                                     "definition\n", fname, lineno, 0 );
2400 #endif
2401                                 return( 1 );
2402                         }
2403 #endif /* notdef */
2404
2405                         if ( netscape_plugin( be, fname, lineno, cargc, cargv ) 
2406                                         != LDAP_SUCCESS ) {
2407                                 return( 1 );
2408                         }
2409
2410 #else /* !defined( LDAP_SLAPI ) */
2411 #ifdef NEW_LOGGING
2412                         LDAP_LOG( CONFIG, INFO, 
2413                                 "%s: line %d: SLAPI not supported.\n",
2414                                 fname, lineno, 0 );
2415 #else
2416                         Debug( LDAP_DEBUG_ANY, "%s: line %d: SLAPI "
2417                             "not supported.\n", fname, lineno, 0 );
2418 #endif
2419                         return( 1 );
2420                         
2421 #endif /* !defined( LDAP_SLAPI ) */
2422
2423                 /* Netscape plugins */
2424                 } else if ( strcasecmp( cargv[0], "pluginlog" ) == 0 ) {
2425 #if defined( LDAP_SLAPI )
2426                         if ( cargc < 2 ) {
2427 #ifdef NEW_LOGGING
2428                                 LDAP_LOG( CONFIG, INFO, 
2429                                         "%s: line %d: missing file name "
2430                                         "in pluginlog <filename> line.\n",
2431                                         fname, lineno, 0 );
2432 #else
2433                                 Debug( LDAP_DEBUG_ANY, 
2434                                         "%s: line %d: missing file name "
2435                                         "in pluginlog <filename> line.\n",
2436                                         fname, lineno, 0 );
2437 #endif
2438                                 return( 1 );
2439                         }
2440
2441                         if ( slapi_log_file != NULL ) {
2442                                 ch_free( slapi_log_file );
2443                         }
2444
2445                         slapi_log_file = ch_strdup( cargv[1] );
2446 #endif /* !defined( LDAP_SLAPI ) */
2447
2448                 /* pass anything else to the current backend info/db config routine */
2449                 } else {
2450                         if ( bi != NULL ) {
2451                                 if ( bi->bi_config == 0 ) {
2452 #ifdef NEW_LOGGING
2453                                         LDAP_LOG( CONFIG, INFO, 
2454                                                 "%s: line %d: unknown directive \"%s\" inside "
2455                                                 "backend info definition (ignored).\n",
2456                                                 fname, lineno, cargv[0] );
2457 #else
2458                                         Debug( LDAP_DEBUG_ANY,
2459 "%s: line %d: unknown directive \"%s\" inside backend info definition (ignored)\n",
2460                                                 fname, lineno, cargv[0] );
2461 #endif
2462
2463                                 } else {
2464                                         if ( (*bi->bi_config)( bi, fname, lineno, cargc, cargv )
2465                                                 != 0 )
2466                                         {
2467                                                 return( 1 );
2468                                         }
2469                                 }
2470                         } else if ( be != NULL ) {
2471                                 if ( be->be_config == 0 ) {
2472 #ifdef NEW_LOGGING
2473                                         LDAP_LOG( CONFIG, INFO, 
2474                                                 "%s: line %d: uknown directive \"%s\" inside "
2475                                                 "backend database definition (ignored).\n",
2476                                                 fname, lineno, cargv[0] );
2477 #else
2478                                         Debug( LDAP_DEBUG_ANY,
2479 "%s: line %d: unknown directive \"%s\" inside backend database definition (ignored)\n",
2480                                         fname, lineno, cargv[0] );
2481 #endif
2482
2483                                 } else {
2484                                         if ( (*be->be_config)( be, fname, lineno, cargc, cargv )
2485                                                 != 0 )
2486                                         {
2487                                                 return( 1 );
2488                                         }
2489                                 }
2490                         } else {
2491 #ifdef NEW_LOGGING
2492                                 LDAP_LOG( CONFIG, INFO, 
2493                                         "%s: line %d: unknown directive \"%s\" outside backend "
2494                                         "info and database definitions (ignored).\n",
2495                                         fname, lineno, cargv[0] );
2496 #else
2497                                 Debug( LDAP_DEBUG_ANY,
2498 "%s: line %d: unknown directive \"%s\" outside backend info and database definitions (ignored)\n",
2499                                     fname, lineno, cargv[0] );
2500 #endif
2501
2502                         }
2503                 }
2504                 free( saveline );
2505         }
2506         fclose( fp );
2507
2508         if ( depth == 0 ) ch_free( cargv );
2509
2510         if ( !global_schemadn.bv_val ) {
2511                 ber_str2bv( SLAPD_SCHEMA_DN, sizeof(SLAPD_SCHEMA_DN)-1, 1,
2512                         &global_schemadn );
2513                 dnNormalize( 0, NULL, NULL, &global_schemadn, &global_schemandn, NULL );
2514         }
2515
2516         if ( load_ucdata( NULL ) < 0 ) return 1;
2517         return( 0 );
2518 }
2519
2520 static int
2521 fp_parse_line(
2522     int         lineno,
2523     char        *line
2524 )
2525 {
2526         char *  token;
2527         char *  logline;
2528         char    logbuf[sizeof("pseudorootpw ***")];
2529
2530         cargc = 0;
2531         token = strtok_quote( line, " \t" );
2532
2533         logline = line;
2534
2535         if ( token && ( strcasecmp( token, "rootpw" ) == 0 ||
2536                 strcasecmp( token, "replica" ) == 0 ||          /* contains "credentials" */
2537                 strcasecmp( token, "bindpw" ) == 0 ||           /* used in back-ldap */
2538                 strcasecmp( token, "pseudorootpw" ) == 0 ||     /* used in back-meta */
2539                 strcasecmp( token, "dbpasswd" ) == 0 ) )        /* used in back-sql */
2540         {
2541                 snprintf( logline = logbuf, sizeof logbuf, "%s ***", token );
2542         }
2543
2544         if ( strtok_quote_ptr ) {
2545                 *strtok_quote_ptr = ' ';
2546         }
2547
2548 #ifdef NEW_LOGGING
2549         LDAP_LOG( CONFIG, DETAIL1, "line %d (%s)\n", lineno, logline , 0 );
2550 #else
2551         Debug( LDAP_DEBUG_CONFIG, "line %d (%s)\n", lineno, logline, 0 );
2552 #endif
2553
2554         if ( strtok_quote_ptr ) {
2555                 *strtok_quote_ptr = '\0';
2556         }
2557
2558         for ( ; token != NULL; token = strtok_quote( NULL, " \t" ) ) {
2559                 if ( cargc == cargv_size - 1 ) {
2560                         char **tmp;
2561                         tmp = ch_realloc( cargv, (cargv_size + ARGS_STEP) *
2562                                             sizeof(*cargv) );
2563                         if ( tmp == NULL ) {
2564 #ifdef NEW_LOGGING
2565                                 LDAP_LOG( CONFIG, ERR, "line %d: out of memory\n", lineno, 0,0 );
2566 #else
2567                                 Debug( LDAP_DEBUG_ANY, 
2568                                                 "line %d: out of memory\n", 
2569                                                 lineno, 0, 0 );
2570 #endif
2571                                 return -1;
2572                         }
2573                         cargv = tmp;
2574                         cargv_size += ARGS_STEP;
2575                 }
2576                 cargv[cargc++] = token;
2577         }
2578         cargv[cargc] = NULL;
2579         return 0;
2580 }
2581
2582 static char *
2583 strtok_quote( char *line, char *sep )
2584 {
2585         int             inquote;
2586         char            *tmp;
2587         static char     *next;
2588
2589         strtok_quote_ptr = NULL;
2590         if ( line != NULL ) {
2591                 next = line;
2592         }
2593         while ( *next && strchr( sep, *next ) ) {
2594                 next++;
2595         }
2596
2597         if ( *next == '\0' ) {
2598                 next = NULL;
2599                 return( NULL );
2600         }
2601         tmp = next;
2602
2603         for ( inquote = 0; *next; ) {
2604                 switch ( *next ) {
2605                 case '"':
2606                         if ( inquote ) {
2607                                 inquote = 0;
2608                         } else {
2609                                 inquote = 1;
2610                         }
2611                         AC_MEMCPY( next, next + 1, strlen( next + 1 ) + 1 );
2612                         break;
2613
2614                 case '\\':
2615                         if ( next[1] )
2616                                 AC_MEMCPY( next,
2617                                             next + 1, strlen( next + 1 ) + 1 );
2618                         next++;         /* dont parse the escaped character */
2619                         break;
2620
2621                 default:
2622                         if ( ! inquote ) {
2623                                 if ( strchr( sep, *next ) != NULL ) {
2624                                         strtok_quote_ptr = next;
2625                                         *next++ = '\0';
2626                                         return( tmp );
2627                                 }
2628                         }
2629                         next++;
2630                         break;
2631                 }
2632         }
2633
2634         return( tmp );
2635 }
2636
2637 static char     buf[BUFSIZ];
2638 static char     *line;
2639 static size_t lmax, lcur;
2640
2641 #define CATLINE( buf ) \
2642         do { \
2643                 size_t len = strlen( buf ); \
2644                 while ( lcur + len + 1 > lmax ) { \
2645                         lmax += BUFSIZ; \
2646                         line = (char *) ch_realloc( line, lmax ); \
2647                 } \
2648                 strcpy( line + lcur, buf ); \
2649                 lcur += len; \
2650         } while( 0 )
2651
2652 static char *
2653 fp_getline( FILE *fp, int *lineno )
2654 {
2655         char            *p;
2656
2657         lcur = 0;
2658         CATLINE( buf );
2659         (*lineno)++;
2660
2661         /* hack attack - keeps us from having to keep a stack of bufs... */
2662         if ( strncasecmp( line, "include", 7 ) == 0 ) {
2663                 buf[0] = '\0';
2664                 return( line );
2665         }
2666
2667         while ( fgets( buf, sizeof(buf), fp ) != NULL ) {
2668                 /* trim off \r\n or \n */
2669                 if ( (p = strchr( buf, '\n' )) != NULL ) {
2670                         if( p > buf && p[-1] == '\r' ) --p;
2671                         *p = '\0';
2672                 }
2673                 
2674                 /* trim off trailing \ and append the next line */
2675                 if ( line[ 0 ] != '\0' 
2676                                 && (p = line + strlen( line ) - 1)[ 0 ] == '\\'
2677                                 && p[ -1 ] != '\\' ) {
2678                         p[ 0 ] = '\0';
2679                         lcur--;
2680
2681                 } else {
2682                         if ( ! isspace( (unsigned char) buf[0] ) ) {
2683                                 return( line );
2684                         }
2685
2686                         /* change leading whitespace to a space */
2687                         buf[0] = ' ';
2688                 }
2689
2690                 CATLINE( buf );
2691                 (*lineno)++;
2692         }
2693         buf[0] = '\0';
2694
2695         return( line[0] ? line : NULL );
2696 }
2697
2698 static void
2699 fp_getline_init( int *lineno )
2700 {
2701         *lineno = -1;
2702         buf[0] = '\0';
2703 }
2704
2705 /* Loads ucdata, returns 1 if loading, 0 if already loaded, -1 on error */
2706 static int
2707 load_ucdata( char *path )
2708 {
2709         static int loaded = 0;
2710         int err;
2711         
2712         if ( loaded ) {
2713                 return( 0 );
2714         }
2715         err = ucdata_load( path ? path : SLAPD_DEFAULT_UCDATA, UCDATA_ALL );
2716         if ( err ) {
2717 #ifdef NEW_LOGGING
2718                 LDAP_LOG( CONFIG, CRIT, 
2719                         "load_ucdata: Error %d loading ucdata.\n", err, 0,0 );
2720 #else
2721                 Debug( LDAP_DEBUG_ANY, "error loading ucdata (error %d)\n",
2722                        err, 0, 0 );
2723 #endif
2724
2725                 return( -1 );
2726         }
2727         loaded = 1;
2728         return( 1 );
2729 }
2730
2731 void
2732 config_destroy( )
2733 {
2734         ucdata_unload( UCDATA_ALL );
2735         free( global_schemandn.bv_val );
2736         free( global_schemadn.bv_val );
2737         free( line );
2738         if ( slapd_args_file )
2739                 free ( slapd_args_file );
2740         if ( slapd_pid_file )
2741                 free ( slapd_pid_file );
2742         if ( default_passwd_hash )
2743                 free( default_passwd_hash );
2744         acl_destroy( global_acl, NULL );
2745 }
2746
2747 static int
2748 add_syncrepl(
2749         Backend *be,
2750         char    **cargv,
2751         int     cargc
2752 )
2753 {
2754         syncinfo_t *si;
2755
2756         if ( be->be_syncinfo ) {
2757 #ifdef NEW_LOGGING
2758                 LDAP_LOG( CONFIG, INFO, 
2759                             "add_syncrepl: multiple syncrepl lines in a database "
2760                                 "definition are yet to be supported.\n", 0, 0, 0 );
2761 #else
2762                 Debug( LDAP_DEBUG_ANY,
2763                             "add_syncrepl: multiple syncrepl lines in a database "
2764                                 "definition are yet to be supported.\n", 0, 0, 0 );
2765 #endif
2766                 return 1;
2767         }
2768
2769         si = be->be_syncinfo = (syncinfo_t *) ch_calloc( 1, sizeof( syncinfo_t ) );
2770
2771         if ( si == NULL ) {
2772 #ifdef NEW_LOGGING
2773                 LDAP_LOG( CONFIG, ERR, "out of memory in add_syncrepl\n", 0, 0,0 );
2774 #else
2775                 Debug( LDAP_DEBUG_ANY, "out of memory in add_syncrepl\n", 0, 0, 0 );
2776 #endif
2777                 return 1;
2778         }
2779
2780         si->si_tls = SYNCINFO_TLS_OFF;
2781         if ( be->be_rootndn.bv_val ) {
2782                 ber_dupbv( &si->si_updatedn, &be->be_rootndn );
2783         }
2784         si->si_bindmethod = LDAP_AUTH_SIMPLE;
2785         si->si_schemachecking = 0;
2786         ber_str2bv( "(objectclass=*)", sizeof("(objectclass=*)")-1, 0,
2787                 &si->si_filterstr );
2788         if ( be->be_suffix && be->be_suffix[0].bv_val ) {
2789                 ber_dupbv( &si->si_base, &be->be_nsuffix[0] );
2790         }
2791         si->si_scope = LDAP_SCOPE_SUBTREE;
2792         si->si_attrsonly = 0;
2793         si->si_attrs = (char **) ch_calloc( 1, sizeof( char * ));
2794         si->si_attrs[0] = NULL;
2795         si->si_type = LDAP_SYNC_REFRESH_ONLY;
2796         si->si_interval = 86400;
2797         si->si_syncCookie = NULL;
2798         si->si_manageDSAit = 0;
2799         si->si_tlimit = -1;
2800         si->si_slimit = -1;
2801         si->si_syncUUID = NULL;
2802         si->si_syncUUID_ndn = NULL;
2803         si->si_sync_mode = LDAP_SYNC_STATE_MODE;
2804
2805         si->si_presentlist = NULL;
2806         LDAP_LIST_INIT( &si->si_nonpresentlist );
2807
2808         if ( parse_syncrepl_line( cargv, cargc, si ) < 0 ) {
2809                 /* Something bad happened - back out */
2810 #ifdef NEW_LOGGING
2811                 LDAP_LOG( CONFIG, ERR, "failed to add syncinfo\n", 0, 0,0 );
2812 #else
2813                 Debug( LDAP_DEBUG_ANY, "failed to add syncinfo\n", 0, 0, 0 );
2814 #endif
2815                 free( si );
2816                 be->be_syncinfo = NULL;
2817                 return 1;
2818         } else {
2819 #ifdef NEW_LOGGING
2820                 LDAP_LOG ( CONFIG, RESULTS,
2821                         "add_syncrepl: Config: ** successfully added syncrepl \"%s\"\n",
2822                         si->si_provideruri == NULL ? "(null)" : si->si_provideruri, 0, 0 );
2823 #else
2824                 Debug( LDAP_DEBUG_CONFIG,
2825                         "Config: ** successfully added syncrepl \"%s\"\n",
2826                         si->si_provideruri == NULL ? "(null)" : si->si_provideruri, 0, 0 );
2827 #endif
2828                 if ( !si->si_schemachecking ) {
2829                         be->be_flags |= SLAP_BFLAG_NO_SCHEMA_CHECK;
2830                 }
2831                 si->si_be = be;
2832                 return 0;
2833         }
2834 }
2835
2836 #define IDSTR                   "id"
2837 #define PROVIDERSTR             "provider"
2838 #define SUFFIXSTR               "suffix"
2839 #define UPDATEDNSTR             "updatedn"
2840 #define BINDMETHSTR             "bindmethod"
2841 #define SIMPLESTR               "simple"
2842 #define SASLSTR                 "sasl"
2843 #define BINDDNSTR               "binddn"
2844 #define CREDSTR                 "credentials"
2845 #define OLDAUTHCSTR             "bindprincipal"
2846 #define AUTHCSTR                "authcID"
2847 #define AUTHZSTR                "authzID"
2848 #define SRVTABSTR               "srvtab"
2849 #define SASLMECHSTR             "saslmech"
2850 #define REALMSTR                "realm"
2851 #define SECPROPSSTR             "secprops"
2852 #define STARTTLSSTR             "starttls"
2853 #define CRITICALSTR             "critical"
2854
2855 #define SCHEMASTR               "schemachecking"
2856 #define FILTERSTR               "filter"
2857 #define SEARCHBASESTR   "searchbase"
2858 #define SCOPESTR                "scope"
2859 #define ATTRSSTR                "attrs"
2860 #define ATTRSONLYSTR    "attrsonly"
2861 #define TYPESTR                 "type"
2862 #define INTERVALSTR             "interval"
2863 #define COOKIESTR               "cookie"
2864 #define LASTMODSTR              "lastmod"
2865 #define LMREQSTR                "req"
2866 #define LMGENSTR                "gen"
2867 #define LMNOSTR                 "no"
2868 #define MANAGEDSAITSTR  "manageDSAit"
2869 #define SLIMITSTR               "sizelimit"
2870 #define TLIMITSTR               "timelimit"
2871
2872 #define GOT_ID                  0x0001
2873 #define GOT_PROVIDER    0x0002
2874 #define GOT_METHOD              0x0004
2875 #define GOT_ALL                 0x0007
2876
2877 static int
2878 parse_syncrepl_line(
2879         char            **cargv,
2880         int             cargc,
2881         syncinfo_t      *si
2882 )
2883 {
2884         int     gots = 0;
2885         int     i, j;
2886         char    *hp, *val;
2887         int     nr_attr = 0;
2888
2889         for ( i = 1; i < cargc; i++ ) {
2890                 if ( !strncasecmp( cargv[ i ], IDSTR, sizeof( IDSTR ) - 1 )) {
2891                         int tmp;
2892                         /* '\0' string terminator accounts for '=' */
2893                         val = cargv[ i ] + sizeof( IDSTR );
2894                         tmp= atoi( val );
2895                         if ( tmp >= 1000 || tmp < 0 ) {
2896                                 fprintf( stderr, "Error: parse_syncrepl_line: "
2897                                          "syncrepl id %d is out of range [0..999]\n", tmp );
2898                                 return -1;
2899                         }
2900                         si->si_id = tmp;
2901                         gots |= GOT_ID;
2902                 } else if ( !strncasecmp( cargv[ i ], PROVIDERSTR,
2903                                         sizeof( PROVIDERSTR ) - 1 )) {
2904                         val = cargv[ i ] + sizeof( PROVIDERSTR );
2905                         si->si_provideruri = ch_strdup( val );
2906                         si->si_provideruri_bv = (BerVarray)
2907                                 ch_calloc( 2, sizeof( struct berval ));
2908                         ber_str2bv( si->si_provideruri, strlen( si->si_provideruri ),
2909                                 0, &si->si_provideruri_bv[0] );
2910                         si->si_provideruri_bv[1].bv_len = 0;
2911                         si->si_provideruri_bv[1].bv_val = NULL;
2912                         gots |= GOT_PROVIDER;
2913                 } else if ( !strncasecmp( cargv[ i ], STARTTLSSTR,
2914                         sizeof(STARTTLSSTR) - 1 ) )
2915                 {
2916                         val = cargv[ i ] + sizeof( STARTTLSSTR );
2917                         if( !strcasecmp( val, CRITICALSTR ) ) {
2918                                 si->si_tls = SYNCINFO_TLS_CRITICAL;
2919                         } else {
2920                                 si->si_tls = SYNCINFO_TLS_ON;
2921                         }
2922                 } else if ( !strncasecmp( cargv[ i ],
2923                         UPDATEDNSTR, sizeof( UPDATEDNSTR ) - 1 ) )
2924                 {
2925                         struct berval updatedn = {0, NULL};
2926                         val = cargv[ i ] + sizeof( UPDATEDNSTR );
2927                         ber_str2bv( val, 0, 0, &updatedn );
2928                         ch_free( si->si_updatedn.bv_val );
2929                         dnNormalize( 0, NULL, NULL, &updatedn, &si->si_updatedn, NULL );
2930                 } else if ( !strncasecmp( cargv[ i ], BINDMETHSTR,
2931                                 sizeof( BINDMETHSTR ) - 1 ) )
2932                 {
2933                         val = cargv[ i ] + sizeof( BINDMETHSTR );
2934                         if ( !strcasecmp( val, SIMPLESTR )) {
2935                                 si->si_bindmethod = LDAP_AUTH_SIMPLE;
2936                                 gots |= GOT_METHOD;
2937                         } else if ( !strcasecmp( val, SASLSTR )) {
2938 #ifdef HAVE_CYRUS_SASL
2939                                 si->si_bindmethod = LDAP_AUTH_SASL;
2940                                 gots |= GOT_METHOD;
2941 #else /* HAVE_CYRUS_SASL */
2942                                 fprintf( stderr, "Error: parse_syncrepl_line: "
2943                                         "not compiled with SASL support\n" );
2944                                 return 1;
2945 #endif /* HAVE_CYRUS_SASL */
2946                         } else {
2947                                 si->si_bindmethod = -1;
2948                         }
2949                 } else if ( !strncasecmp( cargv[ i ],
2950                                 BINDDNSTR, sizeof( BINDDNSTR ) - 1 ) ) {
2951                         val = cargv[ i ] + sizeof( BINDDNSTR );
2952                         si->si_binddn = ch_strdup( val );
2953                 } else if ( !strncasecmp( cargv[ i ],
2954                                 CREDSTR, sizeof( CREDSTR ) - 1 ) ) {
2955                         val = cargv[ i ] + sizeof( CREDSTR );
2956                         si->si_passwd = ch_strdup( val );
2957                 } else if ( !strncasecmp( cargv[ i ],
2958                                 SASLMECHSTR, sizeof( SASLMECHSTR ) - 1 ) ) {
2959                         val = cargv[ i ] + sizeof( SASLMECHSTR );
2960                         si->si_saslmech = ch_strdup( val );
2961                 } else if ( !strncasecmp( cargv[ i ],
2962                                 SECPROPSSTR, sizeof( SECPROPSSTR ) - 1 ) ) {
2963                         val = cargv[ i ] + sizeof( SECPROPSSTR );
2964                         si->si_secprops = ch_strdup( val );
2965                 } else if ( !strncasecmp( cargv[ i ],
2966                                 REALMSTR, sizeof( REALMSTR ) - 1 ) ) {
2967                         val = cargv[ i ] + sizeof( REALMSTR );
2968                         si->si_realm = ch_strdup( val );
2969                 } else if ( !strncasecmp( cargv[ i ],
2970                                 AUTHCSTR, sizeof( AUTHCSTR ) - 1 ) ) {
2971                         val = cargv[ i ] + sizeof( AUTHCSTR );
2972                         si->si_authcId = ch_strdup( val );
2973                 } else if ( !strncasecmp( cargv[ i ],
2974                                 OLDAUTHCSTR, sizeof( OLDAUTHCSTR ) - 1 ) ) {
2975                         /* Old authcID is provided for some backwards compatibility */
2976                         val = cargv[ i ] + sizeof( OLDAUTHCSTR );
2977                         si->si_authcId = ch_strdup( val );
2978                 } else if ( !strncasecmp( cargv[ i ],
2979                                 AUTHZSTR, sizeof( AUTHZSTR ) - 1 ) ) {
2980                         val = cargv[ i ] + sizeof( AUTHZSTR );
2981                         si->si_authzId = ch_strdup( val );
2982                 } else if ( !strncasecmp( cargv[ i ],
2983                                 SCHEMASTR, sizeof( SCHEMASTR ) - 1 ) )
2984                 {
2985                         val = cargv[ i ] + sizeof( SCHEMASTR );
2986                         if ( !strncasecmp( val, "on", sizeof( "on" ) - 1 )) {
2987                                 si->si_schemachecking = 1;
2988                         } else if ( !strncasecmp( val, "off", sizeof( "off" ) - 1 ) ) {
2989                                 si->si_schemachecking = 0;
2990                         } else {
2991                                 si->si_schemachecking = 1;
2992                         }
2993                 } else if ( !strncasecmp( cargv[ i ],
2994                         FILTERSTR, sizeof( FILTERSTR ) - 1 ) )
2995                 {
2996                         val = cargv[ i ] + sizeof( FILTERSTR );
2997                         ber_str2bv( val, 0, 1, &si->si_filterstr );
2998                 } else if ( !strncasecmp( cargv[ i ],
2999                         SEARCHBASESTR, sizeof( SEARCHBASESTR ) - 1 ) )
3000                 {
3001                         struct berval bv;
3002                         val = cargv[ i ] + sizeof( SEARCHBASESTR );
3003                         ch_free( si->si_base.bv_val );
3004                         ber_str2bv( val, 0, 0, &bv );
3005                         if ( dnNormalize( 0, NULL, NULL, &bv, &si->si_base, NULL )) {
3006                                 fprintf( stderr, "Invalid base DN \"%s\"\n", val );
3007                                 return 1;
3008                         }
3009                 } else if ( !strncasecmp( cargv[ i ],
3010                         SCOPESTR, sizeof( SCOPESTR ) - 1 ) )
3011                 {
3012                         val = cargv[ i ] + sizeof( SCOPESTR );
3013                         if ( !strncasecmp( val, "base", sizeof( "base" ) - 1 )) {
3014                                 si->si_scope = LDAP_SCOPE_BASE;
3015                         } else if ( !strncasecmp( val, "one", sizeof( "one" ) - 1 )) {
3016                                 si->si_scope = LDAP_SCOPE_ONELEVEL;
3017                         } else if ( !strncasecmp( val, "sub", sizeof( "sub" ) - 1 )) {
3018                                 si->si_scope = LDAP_SCOPE_SUBTREE;
3019                         } else {
3020                                 fprintf( stderr, "Error: parse_syncrepl_line: "
3021                                         "unknown scope \"%s\"\n", val);
3022                                 return 1;
3023                         }
3024                 } else if ( !strncasecmp( cargv[ i ],
3025                         ATTRSONLYSTR, sizeof( ATTRSONLYSTR ) - 1 ) )
3026                 {
3027                         si->si_attrsonly = 1;
3028                 } else if ( !strncasecmp( cargv[ i ],
3029                         ATTRSSTR, sizeof( ATTRSSTR ) - 1 ) )
3030                 {
3031                         val = cargv[ i ] + sizeof( ATTRSSTR );
3032                         str2clist( &si->si_attrs, val, "," );
3033                 } else if ( !strncasecmp( cargv[ i ],
3034                         TYPESTR, sizeof( TYPESTR ) - 1 ) )
3035                 {
3036                         val = cargv[ i ] + sizeof( TYPESTR );
3037                         if ( !strncasecmp( val, "refreshOnly", sizeof("refreshOnly")-1 )) {
3038                                 si->si_type = LDAP_SYNC_REFRESH_ONLY;
3039                         } else if ( !strncasecmp( val, "refreshAndPersist",
3040                                 sizeof("refreshAndPersist")-1 ))
3041                         {
3042                                 si->si_type = LDAP_SYNC_REFRESH_AND_PERSIST;
3043                                 si->si_interval = 60;
3044                         } else {
3045                                 fprintf( stderr, "Error: parse_syncrepl_line: "
3046                                         "unknown sync type \"%s\"\n", val);
3047                                 return 1;
3048                         }
3049                 } else if ( !strncasecmp( cargv[ i ],
3050                         INTERVALSTR, sizeof( INTERVALSTR ) - 1 ) )
3051                 {
3052                         char *hstr;
3053                         char *mstr;
3054                         char *dstr;
3055                         val = cargv[ i ] + sizeof( INTERVALSTR );
3056                         dstr = val;
3057                         hstr = strchr( dstr, ':' );
3058                         if ( hstr == NULL ) {
3059                                 fprintf( stderr, "Error: parse_syncrepl_line: "
3060                                         "invalid interval \"%s\"\n", val );
3061                                 return 1;
3062                         }
3063                         *hstr++ = '\0';
3064                         mstr = strchr( hstr, ':' );
3065                         if ( mstr == NULL ) {
3066                                 fprintf( stderr, "Error: parse_syncrepl_line: "
3067                                         "invalid interval \"%s\"\n", val );
3068                                 return 1;
3069                         }
3070                         *mstr++ = '\0';
3071                         si->si_interval = (( atoi( dstr ) * 24 + atoi( hstr )) * 60
3072                                 + atoi( mstr )) * 60;
3073
3074                         if ( si->si_interval < 0 ) {
3075                                 fprintf( stderr, "Error: parse_syncrepl_line: "
3076                                         "invalid interval \"%ld\"\n",
3077                                         (long) si->si_interval);
3078                                 return 1;
3079                         }
3080                 } else if ( !strncasecmp( cargv[ i ],
3081                         COOKIESTR, sizeof( COOKIESTR ) - 1 ) )
3082                 {
3083                         val = cargv[ i ] + sizeof( COOKIESTR );
3084                         si->si_syncCookie = ber_str2bv( val, strlen( val ), 1, NULL );
3085                 } else if ( !strncasecmp( cargv[ i ],
3086                         MANAGEDSAITSTR, sizeof( MANAGEDSAITSTR ) - 1 ) )
3087                 {
3088                         val = cargv[ i ] + sizeof( COOKIESTR );
3089                         si->si_manageDSAit = atoi( val );
3090                 } else if ( !strncasecmp( cargv[ i ],
3091                         SLIMITSTR, sizeof( SLIMITSTR ) - 1 ) )
3092                 {
3093                         val = cargv[ i ] + sizeof( SLIMITSTR );
3094                         si->si_slimit = atoi( val );
3095                 } else if ( !strncasecmp( cargv[ i ],
3096                         TLIMITSTR, sizeof( TLIMITSTR ) - 1 ) )
3097                 {
3098                         val = cargv[ i ] + sizeof( TLIMITSTR );
3099                         si->si_tlimit = atoi( val );
3100                 } else {
3101                         fprintf( stderr, "Error: parse_syncrepl_line: "
3102                                 "unknown keyword \"%s\"\n", cargv[ i ] );
3103                 }
3104         }
3105
3106         if ( gots != GOT_ALL ) {
3107                 fprintf( stderr,
3108                         "Error: Malformed \"syncrepl\" line in slapd config file" );
3109                 return -1;
3110         }
3111
3112         return 0;
3113 }
3114
3115 char **
3116 str2clist( char ***out, char *in, const char *brkstr )
3117 {
3118         char    *str;
3119         char    *s;
3120         char    *lasts;
3121         int     i, j;
3122         const char *text;
3123         char    **new;
3124
3125         /* find last element in list */
3126         for (i = 0; *out && *out[i]; i++);
3127
3128         /* protect the input string from strtok */
3129         str = ch_strdup( in );
3130
3131         if ( *str == '\0' ) {
3132                 free( str );
3133                 return( *out );
3134         }
3135
3136         /* Count words in string */
3137         j=1;
3138         for ( s = str; *s; s++ ) {
3139                 if ( strchr( brkstr, *s ) != NULL ) {
3140                         j++;
3141                 }
3142         }
3143
3144         *out = ch_realloc( *out, ( i + j + 1 ) * sizeof( char * ) );
3145         new = *out + i;
3146         for ( s = ldap_pvt_strtok( str, brkstr, &lasts );
3147                 s != NULL;
3148                 s = ldap_pvt_strtok( NULL, brkstr, &lasts ) )
3149         {
3150                 *new = ch_strdup( s );
3151                 new++;
3152         }
3153
3154         *new = NULL;
3155         free( str );
3156         return( *out );
3157 }