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