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