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