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