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