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