]> git.sur5r.net Git - openldap/blob - servers/slapd/config.c
cleanup
[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 = 0;
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                         for( i=1; i < cargc; i++ ) {
1471                                 if( strcasecmp( cargv[i], "bind_v2" ) == 0 ) {
1472                                         allows |= SLAP_ALLOW_BIND_V2;
1473
1474                                 } else if( strcasecmp( cargv[i], "bind_anon_cred" ) == 0 ) {
1475                                         allows |= SLAP_ALLOW_BIND_ANON_CRED;
1476
1477                                 } else if( strcasecmp( cargv[i], "bind_anon_dn" ) == 0 ) {
1478                                         allows |= SLAP_ALLOW_BIND_ANON_DN;
1479
1480                                 } else if( strcasecmp( cargv[i], "update_anon" ) == 0 ) {
1481                                         allows |= SLAP_ALLOW_UPDATE_ANON;
1482
1483                                 } else if( strcasecmp( cargv[i], "none" ) != 0 ) {
1484 #ifdef NEW_LOGGING
1485                                         LDAP_LOG( CONFIG, CRIT, "%s: line %d: "
1486                                                 "unknown feature %s in \"allow <features>\" line.\n",
1487                                                 fname, lineno, cargv[i] );
1488 #else
1489                                         Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1490                                                 "unknown feature %s in \"allow <features>\" line\n",
1491                                                 fname, lineno, cargv[i] );
1492 #endif
1493
1494                                         return( 1 );
1495                                 }
1496                         }
1497
1498                         global_allows = allows;
1499
1500                 /* disallow these features */
1501                 } else if ( strcasecmp( cargv[0], "disallows" ) == 0 ||
1502                         strcasecmp( cargv[0], "disallow" ) == 0 )
1503                 {
1504                         slap_mask_t     disallows;
1505
1506                         if ( be != NULL ) {
1507 #ifdef NEW_LOGGING
1508                                 LDAP_LOG( CONFIG, INFO, 
1509                                            "%s: line %d: disallow line must appear prior to "
1510                                            "database definitions.\n", fname, lineno ,0 );
1511 #else
1512                                 Debug( LDAP_DEBUG_ANY,
1513 "%s: line %d: disallow line must appear prior to database definitions\n",
1514                                     fname, lineno, 0 );
1515 #endif
1516
1517                         }
1518
1519                         if ( cargc < 2 ) {
1520 #ifdef NEW_LOGGING
1521                                 LDAP_LOG( CONFIG, CRIT, 
1522                                         "%s: line %d: missing feature(s) in \"disallow <features>\""
1523                                         " line.\n", fname, lineno ,0 );
1524 #else
1525                                 Debug( LDAP_DEBUG_ANY,
1526             "%s: line %d: missing feature(s) in \"disallow <features>\" line\n",
1527                                     fname, lineno, 0 );
1528 #endif
1529
1530                                 return( 1 );
1531                         }
1532
1533                         disallows = 0;
1534
1535                         for( i=1; i < cargc; i++ ) {
1536                                 if( strcasecmp( cargv[i], "bind_anon" ) == 0 ) {
1537                                         disallows |= SLAP_DISALLOW_BIND_ANON;
1538
1539                                 } else if( strcasecmp( cargv[i], "bind_simple" ) == 0 ) {
1540                                         disallows |= SLAP_DISALLOW_BIND_SIMPLE;
1541
1542                                 } else if( strcasecmp( cargv[i], "bind_krbv4" ) == 0 ) {
1543                                         disallows |= SLAP_DISALLOW_BIND_KRBV4;
1544
1545                                 } else if( strcasecmp( cargv[i], "tls_2_anon" ) == 0 ) {
1546                                         disallows |= SLAP_DISALLOW_TLS_2_ANON;
1547
1548                                 } else if( strcasecmp( cargv[i], "tls_authc" ) == 0 ) {
1549                                         disallows |= SLAP_DISALLOW_TLS_AUTHC;
1550
1551                                 } else if( strcasecmp( cargv[i], "none" ) != 0 ) {
1552 #ifdef NEW_LOGGING
1553                                         LDAP_LOG( CONFIG, CRIT, 
1554                                                 "%s: line %d: unknown feature %s in "
1555                                                 "\"disallow <features>\" line.\n",
1556                                                 fname, lineno, cargv[i] );
1557 #else
1558                                         Debug( LDAP_DEBUG_ANY,
1559                     "%s: line %d: unknown feature %s in \"disallow <features>\" line\n",
1560                                             fname, lineno, cargv[i] );
1561 #endif
1562
1563                                         return( 1 );
1564                                 }
1565                         }
1566
1567                         global_disallows = disallows;
1568
1569                 /* require these features */
1570                 } else if ( strcasecmp( cargv[0], "requires" ) == 0 ||
1571                         strcasecmp( cargv[0], "require" ) == 0 )
1572                 {
1573                         slap_mask_t     requires;
1574
1575                         if ( cargc < 2 ) {
1576 #ifdef NEW_LOGGING
1577                                 LDAP_LOG( CONFIG, CRIT, 
1578                                            "%s: line %d: missing feature(s) in "
1579                                            "\"require <features>\" line.\n", fname, lineno ,0 );
1580 #else
1581                                 Debug( LDAP_DEBUG_ANY,
1582             "%s: line %d: missing feature(s) in \"require <features>\" line\n",
1583                                     fname, lineno, 0 );
1584 #endif
1585
1586                                 return( 1 );
1587                         }
1588
1589                         requires = 0;
1590
1591                         for( i=1; i < cargc; i++ ) {
1592                                 if( strcasecmp( cargv[i], "bind" ) == 0 ) {
1593                                         requires |= SLAP_REQUIRE_BIND;
1594
1595                                 } else if( strcasecmp( cargv[i], "LDAPv3" ) == 0 ) {
1596                                         requires |= SLAP_REQUIRE_LDAP_V3;
1597
1598                                 } else if( strcasecmp( cargv[i], "authc" ) == 0 ) {
1599                                         requires |= SLAP_REQUIRE_AUTHC;
1600
1601                                 } else if( strcasecmp( cargv[i], "SASL" ) == 0 ) {
1602                                         requires |= SLAP_REQUIRE_SASL;
1603
1604                                 } else if( strcasecmp( cargv[i], "strong" ) == 0 ) {
1605                                         requires |= SLAP_REQUIRE_STRONG;
1606
1607                                 } else if( strcasecmp( cargv[i], "none" ) != 0 ) {
1608 #ifdef NEW_LOGGING
1609                                         LDAP_LOG( CONFIG, CRIT, 
1610                                                    "%s: line %d: unknown feature %s in "
1611                                                    "\"require <features>\" line.\n", 
1612                                                    fname, lineno , cargv[i] );
1613 #else
1614                                         Debug( LDAP_DEBUG_ANY,
1615                     "%s: line %d: unknown feature %s in \"require <features>\" line\n",
1616                                             fname, lineno, cargv[i] );
1617 #endif
1618
1619                                         return( 1 );
1620                                 }
1621                         }
1622
1623                         if ( be == NULL ) {
1624                                 frontendDB->be_requires = requires;
1625                         } else {
1626                                 be->be_requires = requires;
1627                         }
1628
1629                 /* required security factors */
1630                 } else if ( strcasecmp( cargv[0], "security" ) == 0 ) {
1631                         slap_ssf_set_t *set;
1632
1633                         if ( cargc < 2 ) {
1634 #ifdef NEW_LOGGING
1635                                 LDAP_LOG( CONFIG, CRIT, 
1636                                         "%s: line %d: missing factor(s) in \"security <factors>\""
1637                                         " line.\n", fname, lineno ,0 );
1638 #else
1639                                 Debug( LDAP_DEBUG_ANY,
1640             "%s: line %d: missing factor(s) in \"security <factors>\" line\n",
1641                                     fname, lineno, 0 );
1642 #endif
1643
1644                                 return( 1 );
1645                         }
1646
1647                         if ( be == NULL ) {
1648                                 set = &frontendDB->be_ssf_set;
1649                         } else {
1650                                 set = &be->be_ssf_set;
1651                         }
1652
1653                         for( i=1; i < cargc; i++ ) {
1654                                 slap_ssf_t      *tgt;
1655                                 char            *src;
1656
1657                                 if ( strncasecmp( cargv[i], "ssf=",
1658                                                 STRLENOF("ssf=") ) == 0 )
1659                                 {
1660                                         tgt = &set->sss_ssf;
1661                                         src = &cargv[i][STRLENOF("ssf=")];
1662
1663                                 } else if ( strncasecmp( cargv[i], "transport=",
1664                                                 STRLENOF("transport=") ) == 0 )
1665                                 {
1666                                         tgt = &set->sss_transport;
1667                                         src = &cargv[i][STRLENOF("transport=")];
1668
1669                                 } else if ( strncasecmp( cargv[i], "tls=",
1670                                                 STRLENOF("tls=") ) == 0 )
1671                                 {
1672                                         tgt = &set->sss_tls;
1673                                         src = &cargv[i][STRLENOF("tls=")];
1674
1675                                 } else if ( strncasecmp( cargv[i], "sasl=",
1676                                                 STRLENOF("sasl=") ) == 0 )
1677                                 {
1678                                         tgt = &set->sss_sasl;
1679                                         src = &cargv[i][STRLENOF("sasl=")];
1680
1681                                 } else if ( strncasecmp( cargv[i], "update_ssf=",
1682                                                 STRLENOF("update_ssf=") ) == 0 )
1683                                 {
1684                                         tgt = &set->sss_update_ssf;
1685                                         src = &cargv[i][STRLENOF("update_ssf=")];
1686
1687                                 } else if ( strncasecmp( cargv[i], "update_transport=",
1688                                                 STRLENOF("update_transport=") ) == 0 )
1689                                 {
1690                                         tgt = &set->sss_update_transport;
1691                                         src = &cargv[i][STRLENOF("update_transport=")];
1692
1693                                 } else if ( strncasecmp( cargv[i], "update_tls=",
1694                                                 STRLENOF("update_tls=") ) == 0 )
1695                                 {
1696                                         tgt = &set->sss_update_tls;
1697                                         src = &cargv[i][STRLENOF("update_tls=")];
1698
1699                                 } else if ( strncasecmp( cargv[i], "update_sasl=",
1700                                                 STRLENOF("update_sasl=") ) == 0 )
1701                                 {
1702                                         tgt = &set->sss_update_sasl;
1703                                         src = &cargv[i][STRLENOF("update_sasl=")];
1704
1705                                 } else if ( strncasecmp( cargv[i], "simple_bind=",
1706                                                 STRLENOF("simple_bind=") ) == 0 )
1707                                 {
1708                                         tgt = &set->sss_simple_bind;
1709                                         src = &cargv[i][STRLENOF("simple_bind=")];
1710
1711                                 } else {
1712 #ifdef NEW_LOGGING
1713                                         LDAP_LOG( CONFIG, CRIT, 
1714                                                    "%s: line %d: unknown factor %s in "
1715                                                    "\"security <factors>\" line.\n",
1716                                                    fname, lineno, cargv[1] );
1717 #else
1718                                         Debug( LDAP_DEBUG_ANY,
1719                     "%s: line %d: unknown factor %s in \"security <factors>\" line\n",
1720                                             fname, lineno, cargv[i] );
1721 #endif
1722
1723                                         return( 1 );
1724                                 }
1725
1726                                 *tgt = strtol( src, &next, 10 );
1727                                 if ( next == NULL || next[0] != '\0' ) {
1728 #ifdef NEW_LOGGING
1729                                         LDAP_LOG( CONFIG, CRIT, 
1730                                                    "%s: line %d: unable to parse factor \"%s\" in "
1731                                                    "\"security <factors>\" line.\n",
1732                                                    fname, lineno, cargv[1] );
1733 #else
1734                                         Debug( LDAP_DEBUG_ANY,
1735                     "%s: line %d: unable to parse factor \"%s\" in \"security <factors>\" line\n",
1736                                             fname, lineno, cargv[i] );
1737 #endif
1738
1739                                         return( 1 );
1740                                 }
1741                         }
1742
1743                 /* where to send clients when we don't hold it */
1744                 } else if ( strcasecmp( cargv[0], "referral" ) == 0 ) {
1745                         if ( cargc < 2 ) {
1746 #ifdef NEW_LOGGING
1747                                 LDAP_LOG( CONFIG, CRIT, 
1748                                         "%s: line %d: missing URL in \"referral <URL>\""
1749                                         " line.\n", fname, lineno , 0 );
1750 #else
1751                                 Debug( LDAP_DEBUG_ANY,
1752                     "%s: line %d: missing URL in \"referral <URL>\" line\n",
1753                                     fname, lineno, 0 );
1754 #endif
1755
1756                                 return( 1 );
1757                         }
1758
1759                         if( validate_global_referral( cargv[1] ) ) {
1760 #ifdef NEW_LOGGING
1761                                 LDAP_LOG( CONFIG, CRIT, 
1762                                         "%s: line %d: invalid URL (%s) in \"referral\" line.\n",
1763                                         fname, lineno, cargv[1]  );
1764 #else
1765                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1766                                         "invalid URL (%s) in \"referral\" line.\n",
1767                                     fname, lineno, cargv[1] );
1768 #endif
1769                                 return 1;
1770                         }
1771
1772                         vals[0].bv_val = cargv[1];
1773                         vals[0].bv_len = strlen( vals[0].bv_val );
1774                         if( value_add( &default_referral, vals ) )
1775                                 return LDAP_OTHER;
1776
1777 #ifdef NEW_LOGGING
1778                 } else if ( strcasecmp( cargv[0], "logfile" ) == 0 ) {
1779                         FILE *logfile;
1780                         if ( cargc < 2 ) {
1781 #ifdef NEW_LOGGING
1782                                 LDAP_LOG( CONFIG, CRIT, 
1783                                         "%s: line %d: Error in logfile directive, "
1784                                         "\"logfile <filename>\"\n", fname, lineno , 0 );
1785 #else
1786                                 Debug( LDAP_DEBUG_ANY,
1787                                        "%s: line %d: Error in logfile directive, \"logfile filename\"\n",
1788                                        fname, lineno, 0 );
1789 #endif
1790
1791                                 return( 1 );
1792                         }
1793                         logfile = fopen( cargv[1], "w" );
1794                         if ( logfile != NULL ) lutil_debug_file( logfile  );
1795
1796 #endif
1797                 /* start of a new database definition */
1798                 } else if ( strcasecmp( cargv[0], "debug" ) == 0 ) {
1799                         int level;
1800                         if ( cargc < 3 ) {
1801 #ifdef NEW_LOGGING
1802                                 LDAP_LOG( CONFIG, CRIT, 
1803                                            "%s: line %d: Error in debug directive, "
1804                                            "\"debug <subsys> <level>\"\n", fname, lineno , 0 );
1805 #else
1806                                 Debug( LDAP_DEBUG_ANY,
1807                                         "%s: line %d: Error in debug directive, \"debug subsys level\"\n",
1808                                         fname, lineno, 0 );
1809 #endif
1810                                 return( 1 );
1811                         }
1812                         level = strtol( cargv[2], &next, 10 );
1813                         if ( next == NULL || next[0] != '\0' ){
1814 #ifdef NEW_LOGGING
1815                                 LDAP_LOG( CONFIG, CRIT, 
1816                                            "%s: line %d: unable to parse level \"%s\" in debug directive, "
1817                                            "\"debug <subsys> <level>\"\n", fname, lineno , cargv[2] );
1818 #else
1819                                 Debug( LDAP_DEBUG_ANY,
1820                                            "%s: line %d: unable to parse level \"%s\" in debug directive, "
1821                                            "\"debug <subsys> <level>\"\n", fname, lineno , cargv[2] );
1822 #endif
1823                                 return( 1 );
1824                         }
1825
1826                         if ( level <= 0 ) level = lutil_mnem2level( cargv[2] );
1827                         lutil_set_debug_level( cargv[1], level );
1828                 /* specify an Object Identifier macro */
1829                 } else if ( strcasecmp( cargv[0], "objectidentifier" ) == 0 ) {
1830                         rc = parse_oidm( fname, lineno, cargc, cargv );
1831                         if( rc ) return rc;
1832
1833                 /* specify an objectclass */
1834                 } else if ( strcasecmp( cargv[0], "objectclass" ) == 0 ) {
1835                         if ( cargc < 2 ) {
1836 #ifdef NEW_LOGGING
1837                                 LDAP_LOG( CONFIG, INFO, 
1838                                         "%s: line %d: illegal objectclass format.\n",
1839                                         fname, lineno , 0 );
1840 #else
1841                                 Debug( LDAP_DEBUG_ANY,
1842                                        "%s: line %d: illegal objectclass format.\n",
1843                                        fname, lineno, 0 );
1844 #endif
1845                                 return( 1 );
1846
1847                         } else if ( *cargv[1] == '('  /*')'*/) {
1848                                 char * p;
1849                                 p = strchr(saveline,'(' /*')'*/);
1850                                 rc = parse_oc( fname, lineno, p, cargv );
1851                                 if( rc ) return rc;
1852
1853                         } else {
1854 #ifdef NEW_LOGGING
1855                                 LDAP_LOG( CONFIG, INFO, 
1856                                         "%s: line %d: old objectclass format not supported\n",
1857                                         fname, lineno , 0 );
1858 #else
1859                                 Debug( LDAP_DEBUG_ANY,
1860                                        "%s: line %d: old objectclass format not supported.\n",
1861                                        fname, lineno, 0 );
1862 #endif
1863                         }
1864
1865                 } else if ( strcasecmp( cargv[0], "ditcontentrule" ) == 0 ) {
1866                         char * p;
1867                         p = strchr(saveline,'(' /*')'*/);
1868                         rc = parse_cr( fname, lineno, p, cargv );
1869                         if( rc ) return rc;
1870
1871                 /* specify an attribute type */
1872                 } else if (( strcasecmp( cargv[0], "attributetype" ) == 0 )
1873                         || ( strcasecmp( cargv[0], "attribute" ) == 0 ))
1874                 {
1875                         if ( cargc < 2 ) {
1876 #ifdef NEW_LOGGING
1877                                 LDAP_LOG( CONFIG, INFO, "%s: line %d: "
1878                                         "illegal attribute type format.\n",
1879                                         fname, lineno , 0 );
1880 #else
1881                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1882                                         "illegal attribute type format.\n",
1883                                         fname, lineno, 0 );
1884 #endif
1885                                 return( 1 );
1886
1887                         } else if ( *cargv[1] == '(' /*')'*/) {
1888                                 char * p;
1889                                 p = strchr(saveline,'(' /*')'*/);
1890                                 rc = parse_at( fname, lineno, p, cargv );
1891                                 if( rc ) return rc;
1892
1893                         } else {
1894 #ifdef NEW_LOGGING
1895                                 LDAP_LOG( CONFIG, INFO, 
1896                                         "%s: line %d: old attribute type format not supported.\n",
1897                                         fname, lineno , 0 );
1898 #else
1899                                 Debug( LDAP_DEBUG_ANY,
1900     "%s: line %d: old attribute type format not supported.\n",
1901                                     fname, lineno, 0 );
1902 #endif
1903
1904                         }
1905
1906                 /* define attribute option(s) */
1907                 } else if ( strcasecmp( cargv[0], "attributeoptions" ) == 0 ) {
1908                         ad_define_option( NULL, NULL, 0 );
1909                         for ( i = 1; i < cargc; i++ )
1910                                 if ( ad_define_option( cargv[i], fname, lineno ) != 0 )
1911                                         return 1;
1912
1913                 /* turn on/off schema checking */
1914                 } else if ( strcasecmp( cargv[0], "schemacheck" ) == 0 ) {
1915                         if ( cargc < 2 ) {
1916 #ifdef NEW_LOGGING
1917                                 LDAP_LOG( CONFIG, CRIT, 
1918                                         "%s: line %d: missing on|off in \"schemacheck <on|off>\""
1919                                         " line.\n", fname, lineno , 0 );
1920 #else
1921                                 Debug( LDAP_DEBUG_ANY,
1922     "%s: line %d: missing on|off in \"schemacheck <on|off>\" line\n",
1923                                     fname, lineno, 0 );
1924 #endif
1925
1926                                 return( 1 );
1927                         }
1928                         if ( strcasecmp( cargv[1], "off" ) == 0 ) {
1929 #ifdef NEW_LOGGING
1930                                 LDAP_LOG( CONFIG, CRIT, 
1931                                         "%s: line %d: schema checking disabled! your mileage may "
1932                                         "vary!\n", fname, lineno , 0 );
1933 #else
1934                                 Debug( LDAP_DEBUG_ANY,
1935                                         "%s: line %d: schema checking disabled! your mileage may vary!\n",
1936                                     fname, lineno, 0 );
1937 #endif
1938                                 global_schemacheck = 0;
1939                         } else {
1940                                 global_schemacheck = 1;
1941                         }
1942
1943                 /* specify access control info */
1944                 } else if ( strcasecmp( cargv[0], "access" ) == 0 ) {
1945                         parse_acl( be, fname, lineno, cargc, cargv );
1946
1947                 /* debug level to log things to syslog */
1948                 } else if ( strcasecmp( cargv[0], "loglevel" ) == 0 ) {
1949                         if ( cargc < 2 ) {
1950 #ifdef NEW_LOGGING
1951                                 LDAP_LOG( CONFIG, CRIT, 
1952                                         "%s: line %d: missing level(s) in \"loglevel <level> [...]\""
1953                                         " line.\n", fname, lineno , 0 );
1954 #else
1955                                 Debug( LDAP_DEBUG_ANY,
1956                     "%s: line %d: missing level(s) in \"loglevel <level> [...]\" line\n",
1957                                     fname, lineno, 0 );
1958 #endif
1959
1960                                 return( 1 );
1961                         }
1962
1963                         ldap_syslog = 0;
1964
1965                         for( i=1; i < cargc; i++ ) {
1966                                 int     level;
1967
1968                                 if ( isdigit( cargv[i][0] ) ) {
1969                                         level = strtol( cargv[i], &next, 10 );
1970                                         if ( next == NULL || next[0] != '\0' ) {
1971 #ifdef NEW_LOGGING
1972                                                 LDAP_LOG( CONFIG, CRIT, 
1973                                                         "%s: line %d: unable to parse level \"%s\" "
1974                                                         "in \"loglevel <level> [...]\" line.\n",
1975                                                         fname, lineno , cargv[i] );
1976 #else
1977                                                 Debug( LDAP_DEBUG_ANY,
1978                                                         "%s: line %d: unable to parse level \"%s\" "
1979                                                         "in \"loglevel <level> [...]\" line.\n",
1980                                                         fname, lineno , cargv[i] );
1981 #endif
1982                                                 return( 1 );
1983                                         }
1984                                         
1985                                 } else {
1986                                         static struct {
1987                                                 int     i;
1988                                                 char    *s;
1989                                         } int_2_level[] = {
1990                                                 { LDAP_DEBUG_TRACE,     "Trace"         },
1991                                                 { LDAP_DEBUG_PACKETS,   "Packets"       },
1992                                                 { LDAP_DEBUG_ARGS,      "Args"          },
1993                                                 { LDAP_DEBUG_CONNS,     "Conns"         },
1994                                                 { LDAP_DEBUG_BER,       "BER"           },
1995                                                 { LDAP_DEBUG_FILTER,    "Filter"        },
1996                                                 { LDAP_DEBUG_CONFIG,    "Config"        },
1997                                                 { LDAP_DEBUG_ACL,       "ACL"           },
1998                                                 { LDAP_DEBUG_STATS,     "Stats"         },
1999                                                 { LDAP_DEBUG_STATS2,    "Stats2"        },
2000                                                 { LDAP_DEBUG_SHELL,     "Shell"         },
2001                                                 { LDAP_DEBUG_PARSE,     "Parse"         },
2002                                                 { LDAP_DEBUG_CACHE,     "Cache"         },
2003                                                 { LDAP_DEBUG_INDEX,     "Index"         },
2004                                                 { -1,                   "Any"           },
2005                                                 { 0,                    NULL            }
2006                                         };
2007                                         int     j;
2008
2009                                         for ( j = 0; int_2_level[j].s; j++ ) {
2010                                                 if ( strcasecmp( cargv[i], int_2_level[j].s ) == 0 ) {
2011                                                         level = int_2_level[j].i;
2012                                                         break;
2013                                                 }
2014                                         }
2015
2016                                         if ( int_2_level[j].s == NULL ) {
2017 #ifdef NEW_LOGGING
2018                                                 LDAP_LOG( CONFIG, CRIT, 
2019                                                         "%s: line %d: unknown level \"%s\" "
2020                                                         "in \"loglevel <level> [...]\" line.\n",
2021                                                         fname, lineno , cargv[i] );
2022 #else
2023                                                 Debug( LDAP_DEBUG_ANY,
2024                                                         "%s: line %d: unknown level \"%s\" "
2025                                                         "in \"loglevel <level> [...]\" line.\n",
2026                                                         fname, lineno , cargv[i] );
2027 #endif
2028                                                 return( 1 );
2029                                         }
2030                                 }
2031
2032                                 ldap_syslog |= level;
2033                         }
2034
2035                 /* list of sync replication information in this backend (slave only) */
2036                 } else if ( strcasecmp( cargv[0], "syncrepl" ) == 0 ) {
2037
2038                         if ( be == NULL ) {
2039 #ifdef NEW_LOGGING
2040                                 LDAP_LOG( CONFIG, INFO, 
2041                                             "%s: line %d: syncrepl line must appear inside "
2042                                             "a database definition.\n", fname, lineno, 0);
2043 #else
2044                                 Debug( LDAP_DEBUG_ANY,
2045                                             "%s: line %d: syncrepl line must appear inside "
2046                                             "a database definition.\n", fname, lineno, 0);
2047 #endif
2048                                 return 1;
2049
2050                         } else if ( SLAP_SHADOW( be )) {
2051 #ifdef NEW_LOGGING
2052                                 LDAP_LOG( CONFIG, INFO, 
2053                                         "%s: line %d: syncrepl: database already shadowed.\n",
2054                                         fname, lineno, 0);
2055 #else
2056                                 Debug( LDAP_DEBUG_ANY,
2057                                         "%s: line %d: syncrepl: database already shadowed.\n",
2058                                         fname, lineno, 0);
2059 #endif
2060                                 return 1;
2061
2062                         } else if ( add_syncrepl( be, cargv, cargc )) {
2063                                 return 1;
2064                         }
2065
2066                         SLAP_DBFLAGS(be) |= ( SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SYNC_SHADOW );
2067
2068                 /* list of replicas of the data in this backend (master only) */
2069                 } else if ( strcasecmp( cargv[0], "replica" ) == 0 ) {
2070                         if ( cargc < 2 ) {
2071 #ifdef NEW_LOGGING
2072                                 LDAP_LOG( CONFIG, CRIT, 
2073                                         "%s: line %d: missing host or uri in \"replica "
2074                                         " <host[:port]\" line\n", fname, lineno , 0 );
2075 #else
2076                                 Debug( LDAP_DEBUG_ANY,
2077             "%s: line %d: missing host or uri in \"replica <host[:port]>\" line\n",
2078                                     fname, lineno, 0 );
2079 #endif
2080
2081                                 return( 1 );
2082                         }
2083                         if ( be == NULL ) {
2084 #ifdef NEW_LOGGING
2085                                 LDAP_LOG( CONFIG, INFO, 
2086                                             "%s: line %d: replica line must appear inside "
2087                                             "a database definition.\n", fname, lineno, 0);
2088 #else
2089                                 Debug( LDAP_DEBUG_ANY,
2090 "%s: line %d: replica line must appear inside a database definition\n",
2091                                     fname, lineno, 0 );
2092 #endif
2093                                 return 1;
2094
2095                         } else {
2096                                 int nr = -1;
2097
2098                                 for ( i = 1; i < cargc; i++ ) {
2099                                         if ( strncasecmp( cargv[i], "host=", 5 )
2100                                             == 0 ) {
2101                                                 nr = add_replica_info( be, 
2102                                                         cargv[i] + 5 );
2103                                                 break;
2104                                         } else if (strncasecmp( cargv[i], "uri=", 4 )
2105                                             == 0 ) {
2106                                             if ( ldap_url_parse( cargv[ i ] + 4, &ludp )
2107                                                 != LDAP_SUCCESS ) {
2108 #ifdef NEW_LOGGING
2109                                                         LDAP_LOG( CONFIG, INFO, 
2110                                                         "%s: line %d: replica line contains invalid "
2111                                                         "uri definition.\n", fname, lineno, 0);
2112 #else
2113                                                         Debug( LDAP_DEBUG_ANY,
2114                                                         "%s: line %d: replica line contains invalid "
2115                                                         "uri definition.\n", fname, lineno, 0);
2116 #endif
2117                                                         return 1;
2118                                                 }
2119                                                 if (ludp->lud_host == NULL ) {
2120 #ifdef NEW_LOGGING
2121                                                         LDAP_LOG( CONFIG, INFO, 
2122                                                         "%s: line %d: replica line contains invalid "
2123                                                         "uri definition - missing hostname.\n", 
2124                                                         fname, lineno, 0);
2125 #else
2126                                                         Debug( LDAP_DEBUG_ANY,
2127                                                         "%s: line %d: replica line contains invalid "
2128                                                         "uri definition - missing hostname.\n", fname, lineno, 0);
2129 #endif
2130                                                         return 1;
2131                                                 }
2132                                         replicahost = ch_malloc( strlen( cargv[ i ] ) );
2133                                                 if ( replicahost == NULL ) {
2134 #ifdef NEW_LOGGING
2135                                                         LDAP_LOG( CONFIG, ERR, 
2136                                                         "out of memory in read_config\n", 0, 0,0 );
2137 #else
2138                                                         Debug( LDAP_DEBUG_ANY, 
2139                                                         "out of memory in read_config\n", 0, 0, 0 );
2140 #endif
2141                                                         ldap_free_urldesc( ludp );                              
2142                                                         exit( EXIT_FAILURE );
2143                                                 }
2144                                                 sprintf(replicahost, "%s:%d", 
2145                                                         ludp->lud_host, ludp->lud_port);
2146                                                 nr = add_replica_info( be, replicahost );
2147                                                 ldap_free_urldesc( ludp );                              
2148                                                 ch_free(replicahost);
2149                                                 break;
2150                                         }
2151                                 }
2152                                 if ( i == cargc ) {
2153 #ifdef NEW_LOGGING
2154                                         LDAP_LOG( CONFIG, INFO, 
2155                                                 "%s: line %d: missing host or uri in \"replica\" line\n", 
2156                                                 fname, lineno , 0 );
2157 #else
2158                                         Debug( LDAP_DEBUG_ANY,
2159                     "%s: line %d: missing host or uri in \"replica\" line\n",
2160                                             fname, lineno, 0 );
2161 #endif
2162                                         return 1;
2163
2164                                 } else if ( nr == -1 ) {
2165 #ifdef NEW_LOGGING
2166                                         LDAP_LOG( CONFIG, INFO, 
2167                                                    "%s: line %d: unable to add"
2168                                                    " replica \"%s\"\n",
2169                                                    fname, lineno, 
2170                                                    cargv[i] + 5 );
2171 #else
2172                                         Debug( LDAP_DEBUG_ANY,
2173                 "%s: line %d: unable to add replica \"%s\"\n",
2174                                                 fname, lineno, cargv[i] + 5 );
2175 #endif
2176                                         return 1;
2177                                 } else {
2178                                         for ( i = 1; i < cargc; i++ ) {
2179                                                 if ( strncasecmp( cargv[i], "suffix=", 7 ) == 0 ) {
2180
2181                                                         switch ( add_replica_suffix( be, nr, cargv[i] + 7 ) ) {
2182                                                         case 1:
2183 #ifdef NEW_LOGGING
2184                                                                 LDAP_LOG( CONFIG, INFO, 
2185                                                                         "%s: line %d: suffix \"%s\" in \"replica\""
2186                                                                         " line is not valid for backend(ignored)\n",
2187                                                                         fname, lineno, cargv[i] + 7 );
2188 #else
2189                                                                 Debug( LDAP_DEBUG_ANY,
2190                                                                                 "%s: line %d: suffix \"%s\" in \"replica\" line is not valid for backend (ignored)\n",
2191                                                                                 fname, lineno, cargv[i] + 7 );
2192 #endif
2193                                                                 break;
2194
2195                                                         case 2:
2196 #ifdef NEW_LOGGING
2197                                                                 LDAP_LOG( CONFIG, INFO, 
2198                                                                         "%s: line %d: unable to normalize suffix"
2199                                                                         " in \"replica\" line (ignored)\n",
2200                                                                         fname, lineno , 0 );
2201 #else
2202                                                                 Debug( LDAP_DEBUG_ANY,
2203                                                                                  "%s: line %d: unable to normalize suffix in \"replica\" line (ignored)\n",
2204                                                                                  fname, lineno, 0 );
2205 #endif
2206                                                                 break;
2207                                                         }
2208
2209                                                 } else if ( strncasecmp( cargv[i], "attr", 4 ) == 0 ) {
2210                                                         int exclude = 0;
2211                                                         char *arg = cargv[i] + 4;
2212
2213                                                         if ( arg[0] == '!' ) {
2214                                                                 arg++;
2215                                                                 exclude = 1;
2216                                                         }
2217
2218                                                         if ( arg[0] != '=' ) {
2219                                                                 continue;
2220                                                         }
2221
2222                                                         if ( add_replica_attrs( be, nr, arg + 1, exclude ) ) {
2223 #ifdef NEW_LOGGING
2224                                                                 LDAP_LOG( CONFIG, INFO, 
2225                                                                         "%s: line %d: attribute \"%s\" in "
2226                                                                         "\"replica\" line is unknown\n",
2227                                                                         fname, lineno, arg + 1 ); 
2228 #else
2229                                                                 Debug( LDAP_DEBUG_ANY,
2230                                                                                 "%s: line %d: attribute \"%s\" in \"replica\" line is unknown\n",
2231                                                                                 fname, lineno, arg + 1 );
2232 #endif
2233                                                                 return( 1 );
2234                                                         }
2235                                                 }
2236                                         }
2237                                 }
2238                         }
2239
2240                 } else if ( strcasecmp( cargv[0], "replicationInterval" ) == 0 ) {
2241                         /* ignore */
2242
2243                 /* dn of slave entity allowed to write to replica */
2244                 } else if ( strcasecmp( cargv[0], "updatedn" ) == 0 ) {
2245                         if ( cargc < 2 ) {
2246 #ifdef NEW_LOGGING
2247                                 LDAP_LOG( CONFIG, CRIT, 
2248                                         "%s: line %d: missing dn in \"updatedn <dn>\""
2249                                         " line.\n", fname, lineno , 0 );
2250 #else
2251                                 Debug( LDAP_DEBUG_ANY,
2252                     "%s: line %d: missing dn in \"updatedn <dn>\" line\n",
2253                                     fname, lineno, 0 );
2254 #endif
2255
2256                                 return( 1 );
2257                         }
2258                         if ( be == NULL ) {
2259 #ifdef NEW_LOGGING
2260                                 LDAP_LOG( CONFIG, INFO, 
2261                                         "%s: line %d: updatedn line must appear inside "
2262                                         "a database definition\n", 
2263                                         fname, lineno , 0 );
2264 #else
2265                                 Debug( LDAP_DEBUG_ANY,
2266 "%s: line %d: updatedn line must appear inside a database definition\n",
2267                                     fname, lineno, 0 );
2268 #endif
2269                                 return 1;
2270
2271                         } else if ( SLAP_SHADOW(be) ) {
2272 #ifdef NEW_LOGGING
2273                                 LDAP_LOG( CONFIG, INFO, 
2274                                         "%s: line %d: updatedn: database already shadowed.\n",
2275                                         fname, lineno, 0);
2276 #else
2277                                 Debug( LDAP_DEBUG_ANY,
2278                                         "%s: line %d: updatedn: database already shadowed.\n",
2279                                         fname, lineno, 0);
2280 #endif
2281                                 return 1;
2282
2283                         } else {
2284                                 struct berval dn;
2285
2286                                 if ( load_ucdata( NULL ) < 0 ) return 1;
2287
2288                                 dn.bv_val = cargv[1];
2289                                 dn.bv_len = strlen( cargv[1] );
2290
2291                                 rc = dnNormalize( 0, NULL, NULL, &dn, &be->be_update_ndn, NULL );
2292                                 if( rc != LDAP_SUCCESS ) {
2293 #ifdef NEW_LOGGING
2294                                         LDAP_LOG( CONFIG, CRIT, 
2295                                                 "%s: line %d: updatedn DN is invalid.\n",
2296                                                 fname, lineno , 0 );
2297 #else
2298                                         Debug( LDAP_DEBUG_ANY,
2299                                                 "%s: line %d: updatedn DN is invalid\n",
2300                                             fname, lineno, 0 );
2301 #endif
2302                                         return 1;
2303                                 }
2304
2305                         }
2306                         SLAP_DBFLAGS(be) |= ( SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SLURP_SHADOW );
2307
2308                 } else if ( strcasecmp( cargv[0], "updateref" ) == 0 ) {
2309                         if ( cargc < 2 ) {
2310 #ifdef NEW_LOGGING
2311                                 LDAP_LOG( CONFIG, CRIT, "%s: line %d: "
2312                                         "missing url in \"updateref <ldapurl>\" line.\n",
2313                                         fname, lineno , 0 );
2314 #else
2315                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
2316                                         "missing url in \"updateref <ldapurl>\" line\n",
2317                                     fname, lineno, 0 );
2318 #endif
2319
2320                                 return( 1 );
2321                         }
2322                         if ( be == NULL ) {
2323 #ifdef NEW_LOGGING
2324                                 LDAP_LOG( CONFIG, INFO, "%s: line %d: updateref"
2325                                         " line must appear inside a database definition\n",
2326                                         fname, lineno , 0 );
2327 #else
2328                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: updateref"
2329                                         " line must appear inside a database definition\n",
2330                                         fname, lineno, 0 );
2331 #endif
2332                                 return 1;
2333
2334                         } else if ( !SLAP_SHADOW(be) ) {
2335 #ifdef NEW_LOGGING
2336                                 LDAP_LOG( CONFIG, INFO, "%s: line %d: "
2337                                         "updateref line must come after syncrepl or updatedn.\n",
2338                                         fname, lineno , 0 );
2339 #else
2340                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
2341                                         "updateref line must after syncrepl or updatedn.\n",
2342                                     fname, lineno, 0 );
2343 #endif
2344                                 return 1;
2345                         }
2346
2347                         if( validate_global_referral( cargv[1] ) ) {
2348 #ifdef NEW_LOGGING
2349                                 LDAP_LOG( CONFIG, CRIT, "%s: line %d: "
2350                                         "invalid URL (%s) in \"updateref\" line.\n",
2351                                         fname, lineno, cargv[1] );
2352 #else
2353                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
2354                                         "invalid URL (%s) in \"updateref\" line.\n",
2355                                     fname, lineno, cargv[1] );
2356 #endif
2357                                 return 1;
2358                         }
2359
2360                         vals[0].bv_val = cargv[1];
2361                         vals[0].bv_len = strlen( vals[0].bv_val );
2362                         if( value_add( &be->be_update_refs, vals ) ) {
2363                                 return LDAP_OTHER;
2364                         }
2365
2366                 /* replication log file to which changes are appended */
2367                 } else if ( strcasecmp( cargv[0], "replogfile" ) == 0 ) {
2368                         if ( cargc < 2 ) {
2369 #ifdef NEW_LOGGING
2370                                 LDAP_LOG( CONFIG, CRIT, 
2371                                         "%s: line %d: missing filename in \"replogfile <filename>\""
2372                                         " line.\n", fname, lineno , 0 );
2373 #else
2374                                 Debug( LDAP_DEBUG_ANY,
2375             "%s: line %d: missing filename in \"replogfile <filename>\" line\n",
2376                                     fname, lineno, 0 );
2377 #endif
2378
2379                                 return( 1 );
2380                         }
2381                         if ( be ) {
2382                                 be->be_replogfile = ch_strdup( cargv[1] );
2383                         } else {
2384                                 replogfile = ch_strdup( cargv[1] );
2385                         }
2386
2387                 /* file from which to read additional rootdse attrs */
2388                 } else if ( strcasecmp( cargv[0], "rootDSE" ) == 0) {
2389                         if ( cargc < 2 ) {
2390 #ifdef NEW_LOGGING
2391                                 LDAP_LOG( CONFIG, CRIT, "%s: line %d: "
2392                                         "missing filename in \"rootDSE <filename>\" line.\n",
2393                                         fname, lineno , 0 );
2394 #else
2395                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
2396                                         "missing filename in \"rootDSE <filename>\" line.\n",
2397                                     fname, lineno, 0 );
2398 #endif
2399                                 return 1;
2400                         }
2401
2402                         if( read_root_dse_file( cargv[1] ) ) {
2403 #ifdef NEW_LOGGING
2404                                 LDAP_LOG( CONFIG, CRIT, "%s: line %d: "
2405                                         "could not read \"rootDSE <filename>\" line.\n",
2406                                         fname, lineno , 0 );
2407 #else
2408                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
2409                                         "could not read \"rootDSE <filename>\" line\n",
2410                                     fname, lineno, 0 );
2411 #endif
2412                                 return 1;
2413                         }
2414
2415                 /* maintain lastmodified{by,time} attributes */
2416                 } else if ( strcasecmp( cargv[0], "lastmod" ) == 0 ) {
2417                         if ( cargc < 2 ) {
2418 #ifdef NEW_LOGGING
2419                                 LDAP_LOG( CONFIG, CRIT, 
2420                                            "%s: line %d: missing on|off in \"lastmod <on|off>\""
2421                                            " line.\n", fname, lineno , 0 );
2422 #else
2423                                 Debug( LDAP_DEBUG_ANY,
2424             "%s: line %d: missing on|off in \"lastmod <on|off>\" line\n",
2425                                     fname, lineno, 0 );
2426 #endif
2427
2428                                 return( 1 );
2429                         }
2430
2431                         if ( be == NULL ) {
2432 #ifdef NEW_LOGGING
2433                                 LDAP_LOG( CONFIG, INFO, "%s: line %d: lastmod"
2434                                         " line must appear inside a database definition\n",
2435                                         fname, lineno , 0 );
2436 #else
2437                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: lastmod"
2438                                         " line must appear inside a database definition\n",
2439                                         fname, lineno, 0 );
2440 #endif
2441                                 return 1;
2442
2443                         } else if ( SLAP_NOLASTMODCMD(be) ) {
2444 #ifdef NEW_LOGGING
2445                                 LDAP_LOG( CONFIG, INFO, "%s: line %d: lastmod"
2446                                         " not available for %s database\n",
2447                                         fname, lineno , be->bd_info->bi_type );
2448 #else
2449                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: lastmod"
2450                                         " not available for %s databases\n",
2451                                         fname, lineno, be->bd_info->bi_type );
2452 #endif
2453                                 return 1;
2454                         }
2455
2456                         if ( strcasecmp( cargv[1], "on" ) == 0 ) {
2457                                 SLAP_DBFLAGS(be) &= ~SLAP_DBFLAG_NOLASTMOD;
2458                         } else {
2459                                 SLAP_DBFLAGS(be) |= SLAP_DBFLAG_NOLASTMOD;
2460                         }
2461
2462 #ifdef SIGHUP
2463                 /* turn on/off gentle SIGHUP handling */
2464                 } else if ( strcasecmp( cargv[0], "gentlehup" ) == 0 ) {
2465                         if ( cargc < 2 ) {
2466                                 Debug( LDAP_DEBUG_ANY,
2467     "%s: line %d: missing on|off in \"gentlehup <on|off>\" line\n",
2468                                     fname, lineno, 0 );
2469                                 return( 1 );
2470                         }
2471                         if ( strcasecmp( cargv[1], "off" ) == 0 ) {
2472                                 global_gentlehup = 0;
2473                         } else {
2474                                 global_gentlehup = 1;
2475                         }
2476 #endif
2477
2478                 /* set idle timeout value */
2479                 } else if ( strcasecmp( cargv[0], "idletimeout" ) == 0 ) {
2480                         int i;
2481                         if ( cargc < 2 ) {
2482 #ifdef NEW_LOGGING
2483                                 LDAP_LOG( CONFIG, CRIT, 
2484                                         "%s: line %d: missing timeout value in "
2485                                         "\"idletimeout <seconds>\" line.\n", fname, lineno , 0 );
2486 #else
2487                                 Debug( LDAP_DEBUG_ANY,
2488             "%s: line %d: missing timeout value in \"idletimeout <seconds>\" line\n",
2489                                     fname, lineno, 0 );
2490 #endif
2491
2492                                 return( 1 );
2493                         }
2494
2495                         i = atoi( cargv[1] );
2496
2497                         if( i < 0 ) {
2498 #ifdef NEW_LOGGING
2499                                 LDAP_LOG( CONFIG, CRIT, 
2500                                         "%s: line %d: timeout value (%d) invalid "
2501                                         "\"idletimeout <seconds>\" line.\n", fname, lineno, i );
2502 #else
2503                                 Debug( LDAP_DEBUG_ANY,
2504             "%s: line %d: timeout value (%d) invalid \"idletimeout <seconds>\" line\n",
2505                                     fname, lineno, i );
2506 #endif
2507
2508                                 return( 1 );
2509                         }
2510
2511                         global_idletimeout = i;
2512
2513                 /* include another config file */
2514                 } else if ( strcasecmp( cargv[0], "include" ) == 0 ) {
2515                         if ( cargc < 2 ) {
2516 #ifdef NEW_LOGGING
2517                                 LDAP_LOG( CONFIG, CRIT, 
2518                                         "%s: line %d: missing filename in \"include "
2519                                         "<filename>\" line.\n", fname, lineno , 0 );
2520 #else
2521                                 Debug( LDAP_DEBUG_ANY,
2522     "%s: line %d: missing filename in \"include <filename>\" line\n",
2523                                     fname, lineno, 0 );
2524 #endif
2525
2526                                 return( 1 );
2527                         }
2528                         savefname = ch_strdup( cargv[1] );
2529                         savelineno = lineno;
2530
2531                         if ( read_config( savefname, depth+1 ) != 0 ) {
2532                                 return( 1 );
2533                         }
2534
2535                         free( savefname );
2536                         lineno = savelineno - 1;
2537
2538                 /* location of kerberos srvtab file */
2539                 } else if ( strcasecmp( cargv[0], "srvtab" ) == 0 ) {
2540                         if ( cargc < 2 ) {
2541 #ifdef NEW_LOGGING
2542                                 LDAP_LOG( CONFIG, CRIT, 
2543                                         "%s: line %d: missing filename in \"srvtab "
2544                                         "<filename>\" line.\n", fname, lineno , 0 );
2545 #else
2546                                 Debug( LDAP_DEBUG_ANY,
2547             "%s: line %d: missing filename in \"srvtab <filename>\" line\n",
2548                                     fname, lineno, 0 );
2549 #endif
2550
2551                                 return( 1 );
2552                         }
2553                         ldap_srvtab = ch_strdup( cargv[1] );
2554
2555 #ifdef SLAPD_MODULES
2556                 } else if (strcasecmp( cargv[0], "moduleload") == 0 ) {
2557                    if ( cargc < 2 ) {
2558 #ifdef NEW_LOGGING
2559                            LDAP_LOG( CONFIG, INFO, 
2560                                    "%s: line %d: missing filename in \"moduleload "
2561                                    "<filename>\" line.\n", fname, lineno , 0 );
2562 #else
2563                       Debug( LDAP_DEBUG_ANY,
2564                              "%s: line %d: missing filename in \"moduleload <filename>\" line\n",
2565                              fname, lineno, 0 );
2566 #endif
2567
2568                       exit( EXIT_FAILURE );
2569                    }
2570                    if (module_load(cargv[1], cargc - 2, (cargc > 2) ? cargv + 2 : NULL)) {
2571 #ifdef NEW_LOGGING
2572                            LDAP_LOG( CONFIG, CRIT, 
2573                                    "%s: line %d: failed to load or initialize module %s\n",
2574                                    fname, lineno, cargv[1] );
2575 #else
2576                       Debug( LDAP_DEBUG_ANY,
2577                              "%s: line %d: failed to load or initialize module %s\n",
2578                              fname, lineno, cargv[1]);
2579 #endif
2580
2581                       exit( EXIT_FAILURE );
2582                    }
2583                 } else if (strcasecmp( cargv[0], "modulepath") == 0 ) {
2584                    if ( cargc != 2 ) {
2585 #ifdef NEW_LOGGING
2586                            LDAP_LOG( CONFIG, INFO, 
2587                                   "%s: line %d: missing path in \"modulepath <path>\""
2588                                   " line\n", fname, lineno , 0 );
2589 #else
2590                       Debug( LDAP_DEBUG_ANY,
2591                              "%s: line %d: missing path in \"modulepath <path>\" line\n",
2592                              fname, lineno, 0 );
2593 #endif
2594
2595                       exit( EXIT_FAILURE );
2596                    }
2597                    if (module_path( cargv[1] )) {
2598 #ifdef NEW_LOGGING
2599                            LDAP_LOG( CONFIG, CRIT, 
2600                                   "%s: line %d: failed to set module search path to %s.\n",
2601                                   fname, lineno, cargv[1] );
2602 #else
2603                            Debug( LDAP_DEBUG_ANY,
2604                                   "%s: line %d: failed to set module search path to %s\n",
2605                                   fname, lineno, cargv[1]);
2606 #endif
2607
2608                       exit( EXIT_FAILURE );
2609                    }
2610                    
2611 #endif /*SLAPD_MODULES*/
2612
2613 #ifdef HAVE_TLS
2614                 } else if ( !strcasecmp( cargv[0], "TLSRandFile" ) ) {
2615                         rc = ldap_pvt_tls_set_option( NULL,
2616                                                       LDAP_OPT_X_TLS_RANDOM_FILE,
2617                                                       cargv[1] );
2618                         if ( rc )
2619                                 return rc;
2620
2621                 } else if ( !strcasecmp( cargv[0], "TLSCipherSuite" ) ) {
2622                         rc = ldap_pvt_tls_set_option( NULL,
2623                                                       LDAP_OPT_X_TLS_CIPHER_SUITE,
2624                                                       cargv[1] );
2625                         if ( rc )
2626                                 return rc;
2627
2628                 } else if ( !strcasecmp( cargv[0], "TLSCertificateFile" ) ) {
2629                         rc = ldap_pvt_tls_set_option( NULL,
2630                                                       LDAP_OPT_X_TLS_CERTFILE,
2631                                                       cargv[1] );
2632                         if ( rc )
2633                                 return rc;
2634
2635                 } else if ( !strcasecmp( cargv[0], "TLSCertificateKeyFile" ) ) {
2636                         rc = ldap_pvt_tls_set_option( NULL,
2637                                                       LDAP_OPT_X_TLS_KEYFILE,
2638                                                       cargv[1] );
2639                         if ( rc )
2640                                 return rc;
2641
2642                 } else if ( !strcasecmp( cargv[0], "TLSCACertificatePath" ) ) {
2643                         rc = ldap_pvt_tls_set_option( NULL,
2644                                                       LDAP_OPT_X_TLS_CACERTDIR,
2645                                                       cargv[1] );
2646                         if ( rc )
2647                                 return rc;
2648
2649                 } else if ( !strcasecmp( cargv[0], "TLSCACertificateFile" ) ) {
2650                         rc = ldap_pvt_tls_set_option( NULL,
2651                                                       LDAP_OPT_X_TLS_CACERTFILE,
2652                                                       cargv[1] );
2653                         if ( rc )
2654                                 return rc;
2655                 } else if ( !strcasecmp( cargv[0], "TLSVerifyClient" ) ) {
2656                         if ( isdigit( (unsigned char) cargv[1][0] ) ) {
2657                                 i = atoi(cargv[1]);
2658                                 rc = ldap_pvt_tls_set_option( NULL,
2659                                                       LDAP_OPT_X_TLS_REQUIRE_CERT,
2660                                                       &i );
2661                         } else {
2662                                 rc = ldap_int_tls_config( NULL,
2663                                                       LDAP_OPT_X_TLS_REQUIRE_CERT,
2664                                                       cargv[1] );
2665                         }
2666
2667                         if ( rc )
2668                                 return rc;
2669
2670 #endif
2671
2672                 } else if ( !strcasecmp( cargv[0], "reverse-lookup" ) ) {
2673 #ifdef SLAPD_RLOOKUPS
2674                         if ( cargc < 2 ) {
2675 #ifdef NEW_LOGGING
2676                                 LDAP_LOG( CONFIG, INFO, 
2677                                         "%s: line %d: reverse-lookup: missing \"on\" or \"off\"\n",
2678                                         fname, lineno , 0 );
2679 #else
2680                                 Debug( LDAP_DEBUG_ANY,
2681 "%s: line %d: reverse-lookup: missing \"on\" or \"off\"\n",
2682                                         fname, lineno, 0 );
2683 #endif
2684                                 return( 1 );
2685                         }
2686
2687                         if ( !strcasecmp( cargv[1], "on" ) ) {
2688                                 use_reverse_lookup = 1;
2689                         } else if ( !strcasecmp( cargv[1], "off" ) ) {
2690                                 use_reverse_lookup = 0;
2691                         } else {
2692 #ifdef NEW_LOGGING
2693                                 LDAP_LOG( CONFIG, INFO, 
2694                                         "%s: line %d: reverse-lookup: "
2695                                         "must be \"on\" (default) or \"off\"\n", fname, lineno, 0 );
2696 #else
2697                                 Debug( LDAP_DEBUG_ANY,
2698 "%s: line %d: reverse-lookup: must be \"on\" (default) or \"off\"\n",
2699                                         fname, lineno, 0 );
2700 #endif
2701                                 return( 1 );
2702                         }
2703
2704 #else /* !SLAPD_RLOOKUPS */
2705 #ifdef NEW_LOGGING
2706                         LDAP_LOG( CONFIG, INFO, 
2707                                 "%s: line %d: reverse lookups "
2708                                 "are not configured (ignored).\n", fname, lineno , 0 );
2709 #else
2710                         Debug( LDAP_DEBUG_ANY,
2711 "%s: line %d: reverse lookups are not configured (ignored).\n",
2712                                 fname, lineno, 0 );
2713 #endif
2714 #endif /* !SLAPD_RLOOKUPS */
2715
2716                 /* Netscape plugins */
2717                 } else if ( strcasecmp( cargv[0], "plugin" ) == 0 ) {
2718 #if defined( LDAP_SLAPI )
2719
2720 #ifdef notdef /* allow global plugins, too */
2721                         /*
2722                          * a "plugin" line must be inside a database
2723                          * definition, since we implement pre-,post- 
2724                          * and extended operation plugins
2725                          */
2726                         if ( be == NULL ) {
2727 #ifdef NEW_LOGGING
2728                                 LDAP_LOG( CONFIG, INFO, 
2729                                         "%s: line %d: plugin line must appear "
2730                                         "insid a database definition.\n",
2731                                         fname, lineno, 0 );
2732 #else
2733                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: plugin "
2734                                     "line must appear inside a database "
2735                                     "definition\n", fname, lineno, 0 );
2736 #endif
2737                                 return( 1 );
2738                         }
2739 #endif /* notdef */
2740
2741                         if ( slapi_int_read_config( be, fname, lineno, cargc, cargv ) 
2742                                         != LDAP_SUCCESS )
2743                         {
2744 #ifdef NEW_LOGGING
2745                                 LDAP_LOG( CONFIG, INFO,
2746                                                 "%s: line %d: SLAPI config read failed.\n",
2747                                                 fname, lineno, 0 );
2748 #else
2749                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: SLAPI "
2750                                                 "config read failed.\n", fname, lineno, 0 );
2751 #endif
2752                                 return( 1 );
2753                         }
2754                         slapi_plugins_used++;
2755
2756 #else /* !defined( LDAP_SLAPI ) */
2757 #ifdef NEW_LOGGING
2758                         LDAP_LOG( CONFIG, INFO, 
2759                                 "%s: line %d: SLAPI not supported.\n",
2760                                 fname, lineno, 0 );
2761 #else
2762                         Debug( LDAP_DEBUG_ANY, "%s: line %d: SLAPI "
2763                             "not supported.\n", fname, lineno, 0 );
2764 #endif
2765                         return( 1 );
2766                         
2767 #endif /* !defined( LDAP_SLAPI ) */
2768
2769                 /* Netscape plugins */
2770                 } else if ( strcasecmp( cargv[0], "pluginlog" ) == 0 ) {
2771 #if defined( LDAP_SLAPI )
2772                         if ( cargc < 2 ) {
2773 #ifdef NEW_LOGGING
2774                                 LDAP_LOG( CONFIG, INFO, 
2775                                         "%s: line %d: missing file name "
2776                                         "in pluginlog <filename> line.\n",
2777                                         fname, lineno, 0 );
2778 #else
2779                                 Debug( LDAP_DEBUG_ANY, 
2780                                         "%s: line %d: missing file name "
2781                                         "in pluginlog <filename> line.\n",
2782                                         fname, lineno, 0 );
2783 #endif
2784                                 return( 1 );
2785                         }
2786
2787                         if ( slapi_log_file != NULL ) {
2788                                 ch_free( slapi_log_file );
2789                         }
2790
2791                         slapi_log_file = ch_strdup( cargv[1] );
2792 #endif /* !defined( LDAP_SLAPI ) */
2793
2794                 /* pass anything else to the current backend info/db config routine */
2795                 } else {
2796                         if ( bi != NULL ) {
2797                                 if ( bi->bi_config ) {
2798                                         rc = (*bi->bi_config)( bi, fname, lineno, cargc, cargv );
2799
2800                                         switch ( rc ) {
2801                                         case 0:
2802                                                 break;
2803
2804                                         case SLAP_CONF_UNKNOWN:
2805 #ifdef NEW_LOGGING
2806                                                 LDAP_LOG( CONFIG, INFO, 
2807                                                         "%s: line %d: unknown directive \"%s\" inside "
2808                                                         "backend info definition (ignored).\n",
2809                                                         fname, lineno, cargv[0] );
2810 #else
2811                                                 Debug( LDAP_DEBUG_ANY,
2812 "%s: line %d: unknown directive \"%s\" inside backend info definition (ignored)\n",
2813                                                         fname, lineno, cargv[0] );
2814 #endif
2815                                                 break;
2816
2817                                         default:
2818                                                 return 1;
2819                                         }
2820                                 }
2821
2822                         } else if ( be != NULL ) {
2823                                 if ( be->be_config ) {
2824                                         rc = (*be->be_config)( be, fname, lineno, cargc, cargv );
2825
2826                                         switch ( rc ) {
2827                                         case 0:
2828                                                 break;
2829
2830                                         case SLAP_CONF_UNKNOWN:
2831 #ifdef NEW_LOGGING
2832                                                 LDAP_LOG( CONFIG, INFO, 
2833                                                         "%s: line %d: unknown directive \"%s\" inside "
2834                                                         "backend database definition (ignored).\n",
2835                                                         fname, lineno, cargv[0] );
2836 #else
2837                                                 Debug( LDAP_DEBUG_ANY,
2838 "%s: line %d: unknown directive \"%s\" inside backend database definition (ignored)\n",
2839                                                         fname, lineno, cargv[0] );
2840 #endif
2841                                                 break;
2842
2843                                         default:
2844                                                 return 1;
2845                                         }
2846                                 }
2847
2848                         } else {
2849                                 if ( frontendDB->be_config ) {
2850                                         rc = (*frontendDB->be_config)( frontendDB, fname, lineno, cargc, cargv );
2851
2852                                         switch ( rc ) {
2853                                         case 0:
2854                                                 break;
2855
2856                                         case SLAP_CONF_UNKNOWN:
2857 #ifdef NEW_LOGGING
2858                                                 LDAP_LOG( CONFIG, INFO, 
2859                                                         "%s: line %d: unknown directive \"%s\" inside "
2860                                                         "global database definition (ignored).\n",
2861                                                         fname, lineno, cargv[0] );
2862 #else
2863                                                 Debug( LDAP_DEBUG_ANY,
2864 "%s: line %d: unknown directive \"%s\" inside global database definition (ignored)\n",
2865                                                         fname, lineno, cargv[0] );
2866 #endif
2867                                                 break;
2868
2869                                         default:
2870                                                 return 1;
2871                                         }
2872                                 }
2873                         }
2874                 }
2875                 free( saveline );
2876         }
2877         fclose( fp );
2878
2879         if ( depth == 0 ) ch_free( cargv );
2880
2881         if ( BER_BVISNULL( &frontendDB->be_schemadn ) ) {
2882                 ber_str2bv( SLAPD_SCHEMA_DN, sizeof(SLAPD_SCHEMA_DN)-1, 1,
2883                         &frontendDB->be_schemadn );
2884                 dnNormalize( 0, NULL, NULL, &frontendDB->be_schemadn, &frontendDB->be_schemandn, NULL );
2885         }
2886
2887         if ( load_ucdata( NULL ) < 0 ) return 1;
2888         return( 0 );
2889 }
2890
2891 static int
2892 fp_parse_line(
2893     int         lineno,
2894     char        *line
2895 )
2896 {
2897         char *  token;
2898         char *  logline;
2899         char    logbuf[sizeof("pseudorootpw ***")];
2900
2901         cargc = 0;
2902         token = strtok_quote( line, " \t" );
2903
2904         logline = line;
2905
2906         if ( token && ( strcasecmp( token, "rootpw" ) == 0 ||
2907                 strcasecmp( token, "replica" ) == 0 ||          /* contains "credentials" */
2908                 strcasecmp( token, "bindpw" ) == 0 ||           /* used in back-ldap */
2909                 strcasecmp( token, "pseudorootpw" ) == 0 ||     /* used in back-meta */
2910                 strcasecmp( token, "dbpasswd" ) == 0 ) )        /* used in back-sql */
2911         {
2912                 snprintf( logline = logbuf, sizeof logbuf, "%s ***", token );
2913         }
2914
2915         if ( strtok_quote_ptr ) {
2916                 *strtok_quote_ptr = ' ';
2917         }
2918
2919 #ifdef NEW_LOGGING
2920         LDAP_LOG( CONFIG, DETAIL1, "line %d (%s)\n", lineno, logline , 0 );
2921 #else
2922         Debug( LDAP_DEBUG_CONFIG, "line %d (%s)\n", lineno, logline, 0 );
2923 #endif
2924
2925         if ( strtok_quote_ptr ) {
2926                 *strtok_quote_ptr = '\0';
2927         }
2928
2929         for ( ; token != NULL; token = strtok_quote( NULL, " \t" ) ) {
2930                 if ( cargc == cargv_size - 1 ) {
2931                         char **tmp;
2932                         tmp = ch_realloc( cargv, (cargv_size + ARGS_STEP) *
2933                                             sizeof(*cargv) );
2934                         if ( tmp == NULL ) {
2935 #ifdef NEW_LOGGING
2936                                 LDAP_LOG( CONFIG, ERR, "line %d: out of memory\n", lineno, 0,0 );
2937 #else
2938                                 Debug( LDAP_DEBUG_ANY, 
2939                                                 "line %d: out of memory\n", 
2940                                                 lineno, 0, 0 );
2941 #endif
2942                                 return -1;
2943                         }
2944                         cargv = tmp;
2945                         cargv_size += ARGS_STEP;
2946                 }
2947                 cargv[cargc++] = token;
2948         }
2949         cargv[cargc] = NULL;
2950         return 0;
2951 }
2952
2953 static char *
2954 strtok_quote( char *line, char *sep )
2955 {
2956         int             inquote;
2957         char            *tmp;
2958         static char     *next;
2959
2960         strtok_quote_ptr = NULL;
2961         if ( line != NULL ) {
2962                 next = line;
2963         }
2964         while ( *next && strchr( sep, *next ) ) {
2965                 next++;
2966         }
2967
2968         if ( *next == '\0' ) {
2969                 next = NULL;
2970                 return( NULL );
2971         }
2972         tmp = next;
2973
2974         for ( inquote = 0; *next; ) {
2975                 switch ( *next ) {
2976                 case '"':
2977                         if ( inquote ) {
2978                                 inquote = 0;
2979                         } else {
2980                                 inquote = 1;
2981                         }
2982                         AC_MEMCPY( next, next + 1, strlen( next + 1 ) + 1 );
2983                         break;
2984
2985                 case '\\':
2986                         if ( next[1] )
2987                                 AC_MEMCPY( next,
2988                                             next + 1, strlen( next + 1 ) + 1 );
2989                         next++;         /* dont parse the escaped character */
2990                         break;
2991
2992                 default:
2993                         if ( ! inquote ) {
2994                                 if ( strchr( sep, *next ) != NULL ) {
2995                                         strtok_quote_ptr = next;
2996                                         *next++ = '\0';
2997                                         return( tmp );
2998                                 }
2999                         }
3000                         next++;
3001                         break;
3002                 }
3003         }
3004
3005         return( tmp );
3006 }
3007
3008 static char     buf[BUFSIZ];
3009 static char     *line;
3010 static size_t lmax, lcur;
3011
3012 #define CATLINE( buf ) \
3013         do { \
3014                 size_t len = strlen( buf ); \
3015                 while ( lcur + len + 1 > lmax ) { \
3016                         lmax += BUFSIZ; \
3017                         line = (char *) ch_realloc( line, lmax ); \
3018                 } \
3019                 strcpy( line + lcur, buf ); \
3020                 lcur += len; \
3021         } while( 0 )
3022
3023 static char *
3024 fp_getline( FILE *fp, int *lineno )
3025 {
3026         char            *p;
3027
3028         lcur = 0;
3029         CATLINE( buf );
3030         (*lineno)++;
3031
3032         /* hack attack - keeps us from having to keep a stack of bufs... */
3033         if ( strncasecmp( line, "include", 7 ) == 0 ) {
3034                 buf[0] = '\0';
3035                 return( line );
3036         }
3037
3038         while ( fgets( buf, sizeof(buf), fp ) != NULL ) {
3039                 /* trim off \r\n or \n */
3040                 if ( (p = strchr( buf, '\n' )) != NULL ) {
3041                         if( p > buf && p[-1] == '\r' ) --p;
3042                         *p = '\0';
3043                 }
3044                 
3045                 /* trim off trailing \ and append the next line */
3046                 if ( line[ 0 ] != '\0' 
3047                                 && (p = line + strlen( line ) - 1)[ 0 ] == '\\'
3048                                 && p[ -1 ] != '\\' ) {
3049                         p[ 0 ] = '\0';
3050                         lcur--;
3051
3052                 } else {
3053                         if ( ! isspace( (unsigned char) buf[0] ) ) {
3054                                 return( line );
3055                         }
3056
3057                         /* change leading whitespace to a space */
3058                         buf[0] = ' ';
3059                 }
3060
3061                 CATLINE( buf );
3062                 (*lineno)++;
3063         }
3064         buf[0] = '\0';
3065
3066         return( line[0] ? line : NULL );
3067 }
3068
3069 static void
3070 fp_getline_init( int *lineno )
3071 {
3072         *lineno = -1;
3073         buf[0] = '\0';
3074 }
3075
3076 /* Loads ucdata, returns 1 if loading, 0 if already loaded, -1 on error */
3077 static int
3078 load_ucdata( char *path )
3079 {
3080 #if 0
3081         static int loaded = 0;
3082         int err;
3083         
3084         if ( loaded ) {
3085                 return( 0 );
3086         }
3087         err = ucdata_load( path ? path : SLAPD_DEFAULT_UCDATA, UCDATA_ALL );
3088         if ( err ) {
3089 #ifdef NEW_LOGGING
3090                 LDAP_LOG( CONFIG, CRIT, 
3091                         "load_ucdata: Error %d loading ucdata.\n", err, 0,0 );
3092 #else
3093                 Debug( LDAP_DEBUG_ANY, "error loading ucdata (error %d)\n",
3094                        err, 0, 0 );
3095 #endif
3096
3097                 return( -1 );
3098         }
3099         loaded = 1;
3100         return( 1 );
3101 #else
3102         /* ucdata is now hardcoded */
3103         return( 0 );
3104 #endif
3105 }
3106
3107 void
3108 config_destroy( )
3109 {
3110         ucdata_unload( UCDATA_ALL );
3111         if ( frontendDB ) {
3112                 /* NOTE: in case of early exit, frontendDB can be NULL */
3113                 if ( frontendDB->be_schemandn.bv_val )
3114                         free( frontendDB->be_schemandn.bv_val );
3115                 if ( frontendDB->be_schemadn.bv_val )
3116                         free( frontendDB->be_schemadn.bv_val );
3117                 if ( frontendDB->be_acl )
3118                         acl_destroy( frontendDB->be_acl, NULL );
3119         }
3120         free( line );
3121         if ( slapd_args_file )
3122                 free ( slapd_args_file );
3123         if ( slapd_pid_file )
3124                 free ( slapd_pid_file );
3125         if ( default_passwd_hash )
3126                 ldap_charray_free( default_passwd_hash );
3127 }
3128
3129 static int
3130 add_syncrepl(
3131         Backend *be,
3132         char    **cargv,
3133         int     cargc
3134 )
3135 {
3136         syncinfo_t *si;
3137         syncinfo_t *si_entry;
3138         int     rc = 0;
3139         int duplicated_replica_id = 0;
3140
3141         si = (syncinfo_t *) ch_calloc( 1, sizeof( syncinfo_t ) );
3142
3143         if ( si == NULL ) {
3144 #ifdef NEW_LOGGING
3145                 LDAP_LOG( CONFIG, ERR, "out of memory in add_syncrepl\n", 0, 0,0 );
3146 #else
3147                 Debug( LDAP_DEBUG_ANY, "out of memory in add_syncrepl\n", 0, 0, 0 );
3148 #endif
3149                 return 1;
3150         }
3151
3152         si->si_tls = SYNCINFO_TLS_OFF;
3153         if ( be->be_rootndn.bv_val ) {
3154                 ber_dupbv( &si->si_updatedn, &be->be_rootndn );
3155         }
3156         si->si_bindmethod = LDAP_AUTH_SIMPLE;
3157         si->si_schemachecking = 0;
3158         ber_str2bv( "(objectclass=*)", STRLENOF("(objectclass=*)"), 0,
3159                 &si->si_filterstr );
3160         si->si_base.bv_val = NULL;
3161         si->si_scope = LDAP_SCOPE_SUBTREE;
3162         si->si_attrsonly = 0;
3163         si->si_attrs = (char **) ch_calloc( 1, sizeof( char * ));
3164         si->si_attrs[0] = NULL;
3165         si->si_exattrs = (char **) ch_calloc( 1, sizeof( char * ));
3166         si->si_exattrs[0] = NULL;
3167         si->si_type = LDAP_SYNC_REFRESH_ONLY;
3168         si->si_interval = 86400;
3169         si->si_retryinterval = 0;
3170         si->si_retrynum_init = 0;
3171         si->si_retrynum = 0;
3172         si->si_syncCookie.ctxcsn = NULL;
3173         si->si_syncCookie.octet_str = NULL;
3174         si->si_syncCookie.sid = -1;
3175         si->si_manageDSAit = 0;
3176         si->si_tlimit = 0;
3177         si->si_slimit = 0;
3178         si->si_syncUUID_ndn.bv_val = NULL;
3179         si->si_syncUUID_ndn.bv_len = 0;
3180
3181         si->si_presentlist = NULL;
3182         LDAP_LIST_INIT( &si->si_nonpresentlist );
3183
3184         rc = parse_syncrepl_line( cargv, cargc, si );
3185
3186         LDAP_STAILQ_FOREACH( si_entry, &be->be_syncinfo, si_next ) {
3187                 if ( si->si_rid == si_entry->si_rid ) {
3188 #ifdef NEW_LOGGING
3189                         LDAP_LOG( CONFIG, ERR,
3190                                 "add_syncrepl: duplicated replica id\n", 0, 0,0 );
3191 #else
3192                         Debug( LDAP_DEBUG_ANY,
3193                                 "add_syncrepl: duplicated replica id\n",0, 0, 0 );
3194 #endif
3195                         duplicated_replica_id = 1;
3196                         break;
3197                 }
3198         }
3199
3200         if ( rc < 0 || duplicated_replica_id ) {
3201                 syncinfo_t *si_entry;
3202                 /* Something bad happened - back out */
3203 #ifdef NEW_LOGGING
3204                 LDAP_LOG( CONFIG, ERR, "failed to add syncinfo\n", 0, 0,0 );
3205 #else
3206                 Debug( LDAP_DEBUG_ANY, "failed to add syncinfo\n", 0, 0, 0 );
3207 #endif
3208
3209                 /* If error, remove all syncinfo */
3210                 LDAP_STAILQ_FOREACH( si_entry, &be->be_syncinfo, si_next ) {
3211                         if ( si_entry->si_updatedn.bv_val ) {
3212                                 ch_free( si->si_updatedn.bv_val );
3213                         }
3214                         if ( si_entry->si_filterstr.bv_val ) {
3215                                 ch_free( si->si_filterstr.bv_val );
3216                         }
3217                         if ( si_entry->si_attrs ) {
3218                                 int i = 0;
3219                                 while ( si_entry->si_attrs[i] != NULL ) {
3220                                         ch_free( si_entry->si_attrs[i] );
3221                                         i++;
3222                                 }
3223                                 ch_free( si_entry->si_attrs );
3224                         }
3225                         if ( si_entry->si_exattrs ) {
3226                                 int i = 0;
3227                                 while ( si_entry->si_exattrs[i] != NULL ) {
3228                                         ch_free( si_entry->si_exattrs[i] );
3229                                         i++;
3230                                 }
3231                                 ch_free( si_entry->si_exattrs );
3232                         }
3233                 }
3234
3235                 while ( !LDAP_STAILQ_EMPTY( &be->be_syncinfo )) {
3236                         si_entry = LDAP_STAILQ_FIRST( &be->be_syncinfo );
3237                         LDAP_STAILQ_REMOVE_HEAD( &be->be_syncinfo, si_next );
3238                         ch_free( si_entry );
3239                 }
3240                 LDAP_STAILQ_INIT( &be->be_syncinfo );
3241                 return 1;
3242         } else {
3243 #ifdef NEW_LOGGING
3244                 LDAP_LOG ( CONFIG, RESULTS,
3245                         "add_syncrepl: Config: ** successfully added syncrepl \"%s\"\n",
3246                         si->si_provideruri == NULL ? "(null)" : si->si_provideruri, 0, 0 );
3247 #else
3248                 Debug( LDAP_DEBUG_CONFIG,
3249                         "Config: ** successfully added syncrepl \"%s\"\n",
3250                         si->si_provideruri == NULL ? "(null)" : si->si_provideruri, 0, 0 );
3251 #endif
3252                 if ( !si->si_schemachecking ) {
3253                         SLAP_DBFLAGS(be) |= SLAP_DBFLAG_NO_SCHEMA_CHECK;
3254                 }
3255                 si->si_be = be;
3256                 LDAP_STAILQ_INSERT_TAIL( &be->be_syncinfo, si, si_next );
3257                 return 0;
3258         }
3259 }
3260
3261 #define IDSTR                   "rid"
3262 #define PROVIDERSTR             "provider"
3263 #define SUFFIXSTR               "suffix"
3264 #define UPDATEDNSTR             "updatedn"
3265 #define BINDMETHSTR             "bindmethod"
3266 #define SIMPLESTR               "simple"
3267 #define SASLSTR                 "sasl"
3268 #define BINDDNSTR               "binddn"
3269 #define CREDSTR                 "credentials"
3270 #define OLDAUTHCSTR             "bindprincipal"
3271 #define AUTHCSTR                "authcID"
3272 #define AUTHZSTR                "authzID"
3273 #define SRVTABSTR               "srvtab"
3274 #define SASLMECHSTR             "saslmech"
3275 #define REALMSTR                "realm"
3276 #define SECPROPSSTR             "secprops"
3277 #define STARTTLSSTR             "starttls"
3278 #define CRITICALSTR             "critical"
3279
3280 #define SCHEMASTR               "schemachecking"
3281 #define FILTERSTR               "filter"
3282 #define SEARCHBASESTR   "searchbase"
3283 #define SCOPESTR                "scope"
3284 #define ATTRSSTR                "attrs"
3285 #define ATTRSONLYSTR    "attrsonly"
3286 #define EXATTRSSTR              "exattrs"
3287 #define TYPESTR                 "type"
3288 #define INTERVALSTR             "interval"
3289 #define LASTMODSTR              "lastmod"
3290 #define LMREQSTR                "req"
3291 #define LMGENSTR                "gen"
3292 #define LMNOSTR                 "no"
3293 #define MANAGEDSAITSTR  "manageDSAit"
3294 #define SLIMITSTR               "sizelimit"
3295 #define TLIMITSTR               "timelimit"
3296
3297 #define RETRYSTR                "retry"
3298
3299 #define GOT_ID                  0x0001
3300 #define GOT_PROVIDER    0x0002
3301 #define GOT_METHOD              0x0004
3302 #define GOT_ALL                 0x0007
3303
3304 static int
3305 parse_syncrepl_line(
3306         char            **cargv,
3307         int             cargc,
3308         syncinfo_t      *si
3309 )
3310 {
3311         int     gots = 0;
3312         int     i, j;
3313         char    *hp, *val;
3314         int     nr_attr = 0;
3315
3316         for ( i = 1; i < cargc; i++ ) {
3317                 if ( !strncasecmp( cargv[ i ], IDSTR, sizeof( IDSTR ) - 1 )) {
3318                         int tmp;
3319                         /* '\0' string terminator accounts for '=' */
3320                         val = cargv[ i ] + sizeof( IDSTR );
3321                         tmp= atoi( val );
3322                         if ( tmp >= 1000 || tmp < 0 ) {
3323                                 fprintf( stderr, "Error: parse_syncrepl_line: "
3324                                          "syncrepl id %d is out of range [0..999]\n", tmp );
3325                                 return -1;
3326                         }
3327                         si->si_rid = tmp;
3328                         gots |= GOT_ID;
3329                 } else if ( !strncasecmp( cargv[ i ], PROVIDERSTR,
3330                                         sizeof( PROVIDERSTR ) - 1 )) {
3331                         val = cargv[ i ] + sizeof( PROVIDERSTR );
3332                         si->si_provideruri = ch_strdup( val );
3333                         si->si_provideruri_bv = (BerVarray)
3334                                 ch_calloc( 2, sizeof( struct berval ));
3335                         ber_str2bv( si->si_provideruri, strlen( si->si_provideruri ),
3336                                 0, &si->si_provideruri_bv[0] );
3337                         si->si_provideruri_bv[1].bv_len = 0;
3338                         si->si_provideruri_bv[1].bv_val = NULL;
3339                         gots |= GOT_PROVIDER;
3340                 } else if ( !strncasecmp( cargv[ i ], STARTTLSSTR,
3341                         sizeof(STARTTLSSTR) - 1 ) )
3342                 {
3343                         val = cargv[ i ] + sizeof( STARTTLSSTR );
3344                         if( !strcasecmp( val, CRITICALSTR ) ) {
3345                                 si->si_tls = SYNCINFO_TLS_CRITICAL;
3346                         } else {
3347                                 si->si_tls = SYNCINFO_TLS_ON;
3348                         }
3349                 } else if ( !strncasecmp( cargv[ i ],
3350                         UPDATEDNSTR, sizeof( UPDATEDNSTR ) - 1 ) )
3351                 {
3352                         struct berval updatedn = {0, NULL};
3353                         val = cargv[ i ] + sizeof( UPDATEDNSTR );
3354                         ber_str2bv( val, 0, 0, &updatedn );
3355                         ch_free( si->si_updatedn.bv_val );
3356                         dnNormalize( 0, NULL, NULL, &updatedn, &si->si_updatedn, NULL );
3357                 } else if ( !strncasecmp( cargv[ i ], BINDMETHSTR,
3358                                 sizeof( BINDMETHSTR ) - 1 ) )
3359                 {
3360                         val = cargv[ i ] + sizeof( BINDMETHSTR );
3361                         if ( !strcasecmp( val, SIMPLESTR )) {
3362                                 si->si_bindmethod = LDAP_AUTH_SIMPLE;
3363                                 gots |= GOT_METHOD;
3364                         } else if ( !strcasecmp( val, SASLSTR )) {
3365 #ifdef HAVE_CYRUS_SASL
3366                                 si->si_bindmethod = LDAP_AUTH_SASL;
3367                                 gots |= GOT_METHOD;
3368 #else /* HAVE_CYRUS_SASL */
3369                                 fprintf( stderr, "Error: parse_syncrepl_line: "
3370                                         "not compiled with SASL support\n" );
3371                                 return 1;
3372 #endif /* HAVE_CYRUS_SASL */
3373                         } else {
3374                                 si->si_bindmethod = -1;
3375                         }
3376                 } else if ( !strncasecmp( cargv[ i ],
3377                                 BINDDNSTR, sizeof( BINDDNSTR ) - 1 ) ) {
3378                         val = cargv[ i ] + sizeof( BINDDNSTR );
3379                         si->si_binddn = ch_strdup( val );
3380                 } else if ( !strncasecmp( cargv[ i ],
3381                                 CREDSTR, sizeof( CREDSTR ) - 1 ) ) {
3382                         val = cargv[ i ] + sizeof( CREDSTR );
3383                         si->si_passwd = ch_strdup( val );
3384                 } else if ( !strncasecmp( cargv[ i ],
3385                                 SASLMECHSTR, sizeof( SASLMECHSTR ) - 1 ) ) {
3386                         val = cargv[ i ] + sizeof( SASLMECHSTR );
3387                         si->si_saslmech = ch_strdup( val );
3388                 } else if ( !strncasecmp( cargv[ i ],
3389                                 SECPROPSSTR, sizeof( SECPROPSSTR ) - 1 ) ) {
3390                         val = cargv[ i ] + sizeof( SECPROPSSTR );
3391                         si->si_secprops = ch_strdup( val );
3392                 } else if ( !strncasecmp( cargv[ i ],
3393                                 REALMSTR, sizeof( REALMSTR ) - 1 ) ) {
3394                         val = cargv[ i ] + sizeof( REALMSTR );
3395                         si->si_realm = ch_strdup( val );
3396                 } else if ( !strncasecmp( cargv[ i ],
3397                                 AUTHCSTR, sizeof( AUTHCSTR ) - 1 ) ) {
3398                         val = cargv[ i ] + sizeof( AUTHCSTR );
3399                         si->si_authcId = ch_strdup( val );
3400                 } else if ( !strncasecmp( cargv[ i ],
3401                                 OLDAUTHCSTR, sizeof( OLDAUTHCSTR ) - 1 ) ) {
3402                         /* Old authcID is provided for some backwards compatibility */
3403                         val = cargv[ i ] + sizeof( OLDAUTHCSTR );
3404                         si->si_authcId = ch_strdup( val );
3405                 } else if ( !strncasecmp( cargv[ i ],
3406                                 AUTHZSTR, sizeof( AUTHZSTR ) - 1 ) ) {
3407                         val = cargv[ i ] + sizeof( AUTHZSTR );
3408                         si->si_authzId = ch_strdup( val );
3409                 } else if ( !strncasecmp( cargv[ i ],
3410                                 SCHEMASTR, sizeof( SCHEMASTR ) - 1 ) )
3411                 {
3412                         val = cargv[ i ] + sizeof( SCHEMASTR );
3413                         if ( !strncasecmp( val, "on", STRLENOF( "on" ) )) {
3414                                 si->si_schemachecking = 1;
3415                         } else if ( !strncasecmp( val, "off", STRLENOF( "off" ) ) ) {
3416                                 si->si_schemachecking = 0;
3417                         } else {
3418                                 si->si_schemachecking = 1;
3419                         }
3420                 } else if ( !strncasecmp( cargv[ i ],
3421                         FILTERSTR, sizeof( FILTERSTR ) - 1 ) )
3422                 {
3423                         val = cargv[ i ] + sizeof( FILTERSTR );
3424                         ber_str2bv( val, 0, 1, &si->si_filterstr );
3425                 } else if ( !strncasecmp( cargv[ i ],
3426                         SEARCHBASESTR, sizeof( SEARCHBASESTR ) - 1 ) )
3427                 {
3428                         struct berval bv;
3429                         val = cargv[ i ] + sizeof( SEARCHBASESTR );
3430                         if ( si->si_base.bv_val ) {
3431                                 ch_free( si->si_base.bv_val );
3432                         }
3433                         ber_str2bv( val, 0, 0, &bv );
3434                         if ( dnNormalize( 0, NULL, NULL, &bv, &si->si_base, NULL )) {
3435                                 fprintf( stderr, "Invalid base DN \"%s\"\n", val );
3436                                 return 1;
3437                         }
3438                 } else if ( !strncasecmp( cargv[ i ],
3439                         SCOPESTR, sizeof( SCOPESTR ) - 1 ) )
3440                 {
3441                         val = cargv[ i ] + sizeof( SCOPESTR );
3442                         if ( !strncasecmp( val, "base", STRLENOF( "base" ) )) {
3443                                 si->si_scope = LDAP_SCOPE_BASE;
3444                         } else if ( !strncasecmp( val, "one", STRLENOF( "one" ) )) {
3445                                 si->si_scope = LDAP_SCOPE_ONELEVEL;
3446 #ifdef LDAP_SCOPE_SUBORDINATE
3447                         } else if ( !strcasecmp( val, "subordinate" ) ||
3448                                 !strcasecmp( val, "children" ))
3449                         {
3450                                 si->si_scope = LDAP_SCOPE_SUBORDINATE;
3451 #endif
3452                         } else if ( !strncasecmp( val, "sub", STRLENOF( "sub" ) )) {
3453                                 si->si_scope = LDAP_SCOPE_SUBTREE;
3454                         } else {
3455                                 fprintf( stderr, "Error: parse_syncrepl_line: "
3456                                         "unknown scope \"%s\"\n", val);
3457                                 return 1;
3458                         }
3459                 } else if ( !strncasecmp( cargv[ i ],
3460                         ATTRSONLYSTR, sizeof( ATTRSONLYSTR ) - 1 ) )
3461                 {
3462                         si->si_attrsonly = 1;
3463                 } else if ( !strncasecmp( cargv[ i ],
3464                         ATTRSSTR, sizeof( ATTRSSTR ) - 1 ) )
3465                 {
3466                         val = cargv[ i ] + sizeof( ATTRSSTR );
3467                         str2clist( &si->si_attrs, val, "," );
3468                 } else if ( !strncasecmp( cargv[ i ],
3469                         EXATTRSSTR, sizeof( EXATTRSSTR ) - 1 ) )
3470                 {
3471                         val = cargv[ i ] + sizeof( EXATTRSSTR );
3472                         str2clist( &si->si_exattrs, val, "," );
3473                 } else if ( !strncasecmp( cargv[ i ],
3474                         TYPESTR, sizeof( TYPESTR ) - 1 ) )
3475                 {
3476                         val = cargv[ i ] + sizeof( TYPESTR );
3477                         if ( !strncasecmp( val, "refreshOnly", STRLENOF("refreshOnly") )) {
3478                                 si->si_type = LDAP_SYNC_REFRESH_ONLY;
3479                         } else if ( !strncasecmp( val, "refreshAndPersist",
3480                                 STRLENOF("refreshAndPersist") ))
3481                         {
3482                                 si->si_type = LDAP_SYNC_REFRESH_AND_PERSIST;
3483                                 si->si_interval = 60;
3484                         } else {
3485                                 fprintf( stderr, "Error: parse_syncrepl_line: "
3486                                         "unknown sync type \"%s\"\n", val);
3487                                 return 1;
3488                         }
3489                 } else if ( !strncasecmp( cargv[ i ],
3490                         INTERVALSTR, sizeof( INTERVALSTR ) - 1 ) )
3491                 {
3492                         val = cargv[ i ] + sizeof( INTERVALSTR );
3493                         if ( si->si_type == LDAP_SYNC_REFRESH_AND_PERSIST ) {
3494                                 si->si_interval = 0;
3495                         } else {
3496                                 char *hstr;
3497                                 char *mstr;
3498                                 char *dstr;
3499                                 char *sstr;
3500                                 int dd, hh, mm, ss;
3501                                 dstr = val;
3502                                 hstr = strchr( dstr, ':' );
3503                                 if ( hstr == NULL ) {
3504                                         fprintf( stderr, "Error: parse_syncrepl_line: "
3505                                                 "invalid interval \"%s\"\n", val );
3506                                         return 1;
3507                                 }
3508                                 *hstr++ = '\0';
3509                                 mstr = strchr( hstr, ':' );
3510                                 if ( mstr == NULL ) {
3511                                         fprintf( stderr, "Error: parse_syncrepl_line: "
3512                                                 "invalid interval \"%s\"\n", val );
3513                                         return 1;
3514                                 }
3515                                 *mstr++ = '\0';
3516                                 sstr = strchr( mstr, ':' );
3517                                 if ( sstr == NULL ) {
3518                                         fprintf( stderr, "Error: parse_syncrepl_line: "
3519                                                 "invalid interval \"%s\"\n", val );
3520                                         return 1;
3521                                 }
3522                                 *sstr++ = '\0';
3523
3524                                 dd = atoi( dstr );
3525                                 hh = atoi( hstr );
3526                                 mm = atoi( mstr );
3527                                 ss = atoi( sstr );
3528                                 if (( hh > 24 ) || ( hh < 0 ) ||
3529                                         ( mm > 60 ) || ( mm < 0 ) ||
3530                                         ( ss > 60 ) || ( ss < 0 ) || ( dd < 0 )) {
3531                                         fprintf( stderr, "Error: parse_syncrepl_line: "
3532                                                 "invalid interval \"%s\"\n", val );
3533                                         return 1;
3534                                 }
3535                                 si->si_interval = (( dd * 24 + hh ) * 60 + mm ) * 60 + ss;
3536                         }
3537                         if ( si->si_interval < 0 ) {
3538                                 fprintf( stderr, "Error: parse_syncrepl_line: "
3539                                         "invalid interval \"%ld\"\n",
3540                                         (long) si->si_interval);
3541                                 return 1;
3542                         }
3543                 } else if ( !strncasecmp( cargv[ i ],
3544                         RETRYSTR, sizeof( RETRYSTR ) - 1 ) )
3545                 {
3546                         char *str;
3547                         char **retry_list;
3548                         int j, k, n;
3549
3550                         val = cargv[ i ] + sizeof( RETRYSTR );
3551                         retry_list = (char **) ch_calloc( 1, sizeof( char * ));
3552                         retry_list[0] = NULL;
3553
3554                         str2clist( &retry_list, val, " ,\t" );
3555
3556                         for ( k = 0; retry_list && retry_list[k]; k++ ) ;
3557                         n = k / 2;
3558                         if ( k % 2 ) {
3559                                 fprintf( stderr,
3560                                                 "Error: incomplete syncrepl retry list\n" );
3561                                 for ( k = 0; retry_list && retry_list[k]; k++ ) {
3562                                         ch_free( retry_list[k] );
3563                                 }
3564                                 ch_free( retry_list );
3565                                 exit( EXIT_FAILURE );
3566                         }
3567                         si->si_retryinterval = (time_t *) ch_calloc( n + 1, sizeof( time_t ));
3568                         si->si_retrynum = (int *) ch_calloc( n + 1, sizeof( int ));
3569                         si->si_retrynum_init = (int *) ch_calloc( n + 1, sizeof( int ));
3570                         for ( j = 0; j < n; j++ ) {
3571                                 si->si_retryinterval[j] = atoi( retry_list[j*2] );
3572                                 if ( *retry_list[j*2+1] == '+' ) {
3573                                         si->si_retrynum_init[j] = -1;
3574                                         si->si_retrynum[j] = -1;
3575                                         j++;
3576                                         break;
3577                                 } else {
3578                                         si->si_retrynum_init[j] = atoi( retry_list[j*2+1] );
3579                                         si->si_retrynum[j] = atoi( retry_list[j*2+1] );
3580                                 }
3581                         }
3582                         si->si_retrynum_init[j] = -2;
3583                         si->si_retrynum[j] = -2;
3584                         si->si_retryinterval[j] = 0;
3585                         
3586                         for ( k = 0; retry_list && retry_list[k]; k++ ) {
3587                                 ch_free( retry_list[k] );
3588                         }
3589                         ch_free( retry_list );
3590                 } else if ( !strncasecmp( cargv[ i ],
3591                         MANAGEDSAITSTR, sizeof( MANAGEDSAITSTR ) - 1 ) )
3592                 {
3593                         val = cargv[ i ] + sizeof( MANAGEDSAITSTR );
3594                         si->si_manageDSAit = atoi( val );
3595                 } else if ( !strncasecmp( cargv[ i ],
3596                         SLIMITSTR, sizeof( SLIMITSTR ) - 1 ) )
3597                 {
3598                         val = cargv[ i ] + sizeof( SLIMITSTR );
3599                         si->si_slimit = atoi( val );
3600                 } else if ( !strncasecmp( cargv[ i ],
3601                         TLIMITSTR, sizeof( TLIMITSTR ) - 1 ) )
3602                 {
3603                         val = cargv[ i ] + sizeof( TLIMITSTR );
3604                         si->si_tlimit = atoi( val );
3605                 } else {
3606                         fprintf( stderr, "Error: parse_syncrepl_line: "
3607                                 "unknown keyword \"%s\"\n", cargv[ i ] );
3608                 }
3609         }
3610
3611         if ( gots != GOT_ALL ) {
3612                 fprintf( stderr,
3613                         "Error: Malformed \"syncrepl\" line in slapd config file" );
3614                 return -1;
3615         }
3616
3617         return 0;
3618 }
3619
3620 char **
3621 str2clist( char ***out, char *in, const char *brkstr )
3622 {
3623         char    *str;
3624         char    *s;
3625         char    *lasts;
3626         int     i, j;
3627         const char *text;
3628         char    **new;
3629
3630         /* find last element in list */
3631         for (i = 0; *out && *out[i]; i++);
3632
3633         /* protect the input string from strtok */
3634         str = ch_strdup( in );
3635
3636         if ( *str == '\0' ) {
3637                 free( str );
3638                 return( *out );
3639         }
3640
3641         /* Count words in string */
3642         j=1;
3643         for ( s = str; *s; s++ ) {
3644                 if ( strchr( brkstr, *s ) != NULL ) {
3645                         j++;
3646                 }
3647         }
3648
3649         *out = ch_realloc( *out, ( i + j + 1 ) * sizeof( char * ) );
3650         new = *out + i;
3651         for ( s = ldap_pvt_strtok( str, brkstr, &lasts );
3652                 s != NULL;
3653                 s = ldap_pvt_strtok( NULL, brkstr, &lasts ) )
3654         {
3655                 *new = ch_strdup( s );
3656                 new++;
3657         }
3658
3659         *new = NULL;
3660         free( str );
3661         return( *out );
3662 }