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