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