]> git.sur5r.net Git - openldap/blob - servers/slapd/config.c
Fix bad eos in dead code.
[openldap] / servers / slapd / config.c
1 /* config.c - configuration file handling routines */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 1998-2005 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, "%s: line %d: "
1813                                         "schema checking cannot be disabled, option ignored!\n",
1814                                         fname, lineno , 0 );
1815 #else
1816                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1817                                         "schema checking cannot be diabled, option ignored!\n",
1818                                     fname, lineno, 0 );
1819 #endif
1820                         } else {
1821                                 global_schemacheck = 1;
1822                         }
1823
1824                 /* specify access control info */
1825                 } else if ( strcasecmp( cargv[0], "access" ) == 0 ) {
1826                         parse_acl( be, fname, lineno, cargc, cargv );
1827
1828                 /* debug level to log things to syslog */
1829                 } else if ( strcasecmp( cargv[0], "loglevel" ) == 0 ) {
1830                         if ( cargc < 2 ) {
1831 #ifdef NEW_LOGGING
1832                                 LDAP_LOG( CONFIG, CRIT, 
1833                                         "%s: line %d: missing level(s) in \"loglevel <level> [...]\""
1834                                         " line.\n", fname, lineno , 0 );
1835 #else
1836                                 Debug( LDAP_DEBUG_ANY,
1837                     "%s: line %d: missing level(s) in \"loglevel <level> [...]\" line\n",
1838                                     fname, lineno, 0 );
1839 #endif
1840
1841                                 return( 1 );
1842                         }
1843
1844                         ldap_syslog = 0;
1845
1846                         for( i=1; i < cargc; i++ ) {
1847                                 int     level = strtol( cargv[i], &next, 10 );
1848                                 if ( next == NULL || next[0] != '\0' ) {
1849 #ifdef NEW_LOGGING
1850                                         LDAP_LOG( CONFIG, CRIT, 
1851                                                 "%s: line %d: unable to parse level \"%s\" in \"loglevel <level> [...]\""
1852                                                 " line.\n", fname, lineno , cargv[i] );
1853 #else
1854                                         Debug( LDAP_DEBUG_ANY,
1855                                                 "%s: line %d: unable to parse level \"%s\" in \"loglevel <level> [...]\""
1856                                                 " line.\n", fname, lineno , cargv[i] );
1857 #endif
1858                                         return( 1 );
1859                                 }
1860
1861                                 ldap_syslog |= level;
1862                         }
1863
1864                 /* list of sync replication information in this backend (slave only) */
1865                 } else if ( strcasecmp( cargv[0], "syncrepl" ) == 0 ) {
1866
1867                         if ( be == NULL ) {
1868 #ifdef NEW_LOGGING
1869                                 LDAP_LOG( CONFIG, INFO, 
1870                                             "%s: line %d: syncrepl line must appear inside "
1871                                             "a database definition.\n", fname, lineno, 0);
1872 #else
1873                                 Debug( LDAP_DEBUG_ANY,
1874                                             "%s: line %d: syncrepl line must appear inside "
1875                                             "a database definition.\n", fname, lineno, 0);
1876 #endif
1877                                 return 1;
1878
1879                         } else if ( SLAP_SHADOW( be )) {
1880 #ifdef NEW_LOGGING
1881                                 LDAP_LOG( CONFIG, INFO, 
1882                                         "%s: line %d: syncrepl: database already shadowed.\n",
1883                                         fname, lineno, 0);
1884 #else
1885                                 Debug( LDAP_DEBUG_ANY,
1886                                         "%s: line %d: syncrepl: database already shadowed.\n",
1887                                         fname, lineno, 0);
1888 #endif
1889                                 return 1;
1890
1891                         } else if ( add_syncrepl( be, cargv, cargc )) {
1892                                 return 1;
1893                         }
1894
1895                         SLAP_DBFLAGS(be) |= ( SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SYNC_SHADOW );
1896
1897                 /* list of replicas of the data in this backend (master only) */
1898                 } else if ( strcasecmp( cargv[0], "replica" ) == 0 ) {
1899                         if ( cargc < 2 ) {
1900 #ifdef NEW_LOGGING
1901                                 LDAP_LOG( CONFIG, CRIT, 
1902                                         "%s: line %d: missing host or uri in \"replica "
1903                                         " <host[:port]\" line\n", fname, lineno , 0 );
1904 #else
1905                                 Debug( LDAP_DEBUG_ANY,
1906             "%s: line %d: missing host or uri in \"replica <host[:port]>\" line\n",
1907                                     fname, lineno, 0 );
1908 #endif
1909
1910                                 return( 1 );
1911                         }
1912                         if ( be == NULL ) {
1913 #ifdef NEW_LOGGING
1914                                 LDAP_LOG( CONFIG, INFO, 
1915                                             "%s: line %d: replica line must appear inside "
1916                                             "a database definition.\n", fname, lineno, 0);
1917 #else
1918                                 Debug( LDAP_DEBUG_ANY,
1919 "%s: line %d: replica line must appear inside a database definition\n",
1920                                     fname, lineno, 0 );
1921 #endif
1922                                 return 1;
1923
1924                         } else {
1925                                 int nr = -1;
1926
1927                                 for ( i = 1; i < cargc; i++ ) {
1928                                         if ( strncasecmp( cargv[i], "host=", 5 )
1929                                             == 0 ) {
1930                                                 nr = add_replica_info( be, 
1931                                                         cargv[i] + 5 );
1932                                                 break;
1933                                         } else if (strncasecmp( cargv[i], "uri=", 4 )
1934                                             == 0 ) {
1935                                             if ( ldap_url_parse( cargv[ i ] + 4, &ludp )
1936                                                 != LDAP_SUCCESS ) {
1937 #ifdef NEW_LOGGING
1938                                                         LDAP_LOG( CONFIG, INFO, 
1939                                                         "%s: line %d: replica line contains invalid "
1940                                                         "uri definition.\n", fname, lineno, 0);
1941 #else
1942                                                         Debug( LDAP_DEBUG_ANY,
1943                                                         "%s: line %d: replica line contains invalid "
1944                                                         "uri definition.\n", fname, lineno, 0);
1945 #endif
1946                                                         return 1;
1947                                                 }
1948                                                 if (ludp->lud_host == NULL ) {
1949 #ifdef NEW_LOGGING
1950                                                         LDAP_LOG( CONFIG, INFO, 
1951                                                         "%s: line %d: replica line contains invalid "
1952                                                         "uri definition - missing hostname.\n", 
1953                                                         fname, lineno, 0);
1954 #else
1955                                                         Debug( LDAP_DEBUG_ANY,
1956                                                         "%s: line %d: replica line contains invalid "
1957                                                         "uri definition - missing hostname.\n", fname, lineno, 0);
1958 #endif
1959                                                         return 1;
1960                                                 }
1961                                         replicahost = ch_malloc( strlen( cargv[ i ] ) );
1962                                                 if ( replicahost == NULL ) {
1963 #ifdef NEW_LOGGING
1964                                                         LDAP_LOG( CONFIG, ERR, 
1965                                                         "out of memory in read_config\n", 0, 0,0 );
1966 #else
1967                                                         Debug( LDAP_DEBUG_ANY, 
1968                                                         "out of memory in read_config\n", 0, 0, 0 );
1969 #endif
1970                                                         ldap_free_urldesc( ludp );                              
1971                                                         exit( EXIT_FAILURE );
1972                                                 }
1973                                                 sprintf(replicahost, "%s:%d", 
1974                                                         ludp->lud_host, ludp->lud_port);
1975                                                 nr = add_replica_info( be, replicahost );
1976                                                 ldap_free_urldesc( ludp );                              
1977                                                 ch_free(replicahost);
1978                                                 break;
1979                                         }
1980                                 }
1981                                 if ( i == cargc ) {
1982 #ifdef NEW_LOGGING
1983                                         LDAP_LOG( CONFIG, INFO, 
1984                                                 "%s: line %d: missing host or uri in \"replica\" line\n", 
1985                                                 fname, lineno , 0 );
1986 #else
1987                                         Debug( LDAP_DEBUG_ANY,
1988                     "%s: line %d: missing host or uri in \"replica\" line\n",
1989                                             fname, lineno, 0 );
1990 #endif
1991                                         return 1;
1992
1993                                 } else if ( nr == -1 ) {
1994 #ifdef NEW_LOGGING
1995                                         LDAP_LOG( CONFIG, INFO, 
1996                                                    "%s: line %d: unable to add"
1997                                                    " replica \"%s\"\n",
1998                                                    fname, lineno, 
1999                                                    cargv[i] + 5 );
2000 #else
2001                                         Debug( LDAP_DEBUG_ANY,
2002                 "%s: line %d: unable to add replica \"%s\"\n",
2003                                                 fname, lineno, cargv[i] + 5 );
2004 #endif
2005                                         return 1;
2006                                 } else {
2007                                         for ( i = 1; i < cargc; i++ ) {
2008                                                 if ( strncasecmp( cargv[i], "suffix=", 7 ) == 0 ) {
2009
2010                                                         switch ( add_replica_suffix( be, nr, cargv[i] + 7 ) ) {
2011                                                         case 1:
2012 #ifdef NEW_LOGGING
2013                                                                 LDAP_LOG( CONFIG, INFO, 
2014                                                                         "%s: line %d: suffix \"%s\" in \"replica\""
2015                                                                         " line is not valid for backend(ignored)\n",
2016                                                                         fname, lineno, cargv[i] + 7 );
2017 #else
2018                                                                 Debug( LDAP_DEBUG_ANY,
2019                                                                                 "%s: line %d: suffix \"%s\" in \"replica\" line is not valid for backend (ignored)\n",
2020                                                                                 fname, lineno, cargv[i] + 7 );
2021 #endif
2022                                                                 break;
2023
2024                                                         case 2:
2025 #ifdef NEW_LOGGING
2026                                                                 LDAP_LOG( CONFIG, INFO, 
2027                                                                         "%s: line %d: unable to normalize suffix"
2028                                                                         " in \"replica\" line (ignored)\n",
2029                                                                         fname, lineno , 0 );
2030 #else
2031                                                                 Debug( LDAP_DEBUG_ANY,
2032                                                                                  "%s: line %d: unable to normalize suffix in \"replica\" line (ignored)\n",
2033                                                                                  fname, lineno, 0 );
2034 #endif
2035                                                                 break;
2036                                                         }
2037
2038                                                 } else if ( strncasecmp( cargv[i], "attr", 4 ) == 0 ) {
2039                                                         int exclude = 0;
2040                                                         char *arg = cargv[i] + 4;
2041
2042                                                         if ( arg[0] == '!' ) {
2043                                                                 arg++;
2044                                                                 exclude = 1;
2045                                                         }
2046
2047                                                         if ( arg[0] != '=' ) {
2048                                                                 continue;
2049                                                         }
2050
2051                                                         if ( add_replica_attrs( be, nr, arg + 1, exclude ) ) {
2052 #ifdef NEW_LOGGING
2053                                                                 LDAP_LOG( CONFIG, INFO, 
2054                                                                         "%s: line %d: attribute \"%s\" in "
2055                                                                         "\"replica\" line is unknown\n",
2056                                                                         fname, lineno, arg + 1 ); 
2057 #else
2058                                                                 Debug( LDAP_DEBUG_ANY,
2059                                                                                 "%s: line %d: attribute \"%s\" in \"replica\" line is unknown\n",
2060                                                                                 fname, lineno, arg + 1 );
2061 #endif
2062                                                                 return( 1 );
2063                                                         }
2064                                                 }
2065                                         }
2066                                 }
2067                         }
2068
2069                 } else if ( strcasecmp( cargv[0], "replicationInterval" ) == 0 ) {
2070                         /* ignore */
2071
2072                 /* dn of slave entity allowed to write to replica */
2073                 } else if ( strcasecmp( cargv[0], "updatedn" ) == 0 ) {
2074                         if ( cargc < 2 ) {
2075 #ifdef NEW_LOGGING
2076                                 LDAP_LOG( CONFIG, CRIT, 
2077                                         "%s: line %d: missing dn in \"updatedn <dn>\""
2078                                         " line.\n", fname, lineno , 0 );
2079 #else
2080                                 Debug( LDAP_DEBUG_ANY,
2081                     "%s: line %d: missing dn in \"updatedn <dn>\" line\n",
2082                                     fname, lineno, 0 );
2083 #endif
2084
2085                                 return( 1 );
2086                         }
2087                         if ( be == NULL ) {
2088 #ifdef NEW_LOGGING
2089                                 LDAP_LOG( CONFIG, INFO, 
2090                                         "%s: line %d: updatedn line must appear inside "
2091                                         "a database definition\n", 
2092                                         fname, lineno , 0 );
2093 #else
2094                                 Debug( LDAP_DEBUG_ANY,
2095 "%s: line %d: updatedn line must appear inside a database definition\n",
2096                                     fname, lineno, 0 );
2097 #endif
2098                                 return 1;
2099
2100                         } else if ( SLAP_SHADOW(be) ) {
2101 #ifdef NEW_LOGGING
2102                                 LDAP_LOG( CONFIG, INFO, 
2103                                         "%s: line %d: updatedn: database already shadowed.\n",
2104                                         fname, lineno, 0);
2105 #else
2106                                 Debug( LDAP_DEBUG_ANY,
2107                                         "%s: line %d: updatedn: database already shadowed.\n",
2108                                         fname, lineno, 0);
2109 #endif
2110                                 return 1;
2111
2112                         } else {
2113                                 struct berval dn;
2114
2115                                 if ( load_ucdata( NULL ) < 0 ) return 1;
2116
2117                                 dn.bv_val = cargv[1];
2118                                 dn.bv_len = strlen( cargv[1] );
2119
2120                                 rc = dnNormalize( 0, NULL, NULL, &dn, &be->be_update_ndn, NULL );
2121                                 if( rc != LDAP_SUCCESS ) {
2122 #ifdef NEW_LOGGING
2123                                         LDAP_LOG( CONFIG, CRIT, 
2124                                                 "%s: line %d: updatedn DN is invalid.\n",
2125                                                 fname, lineno , 0 );
2126 #else
2127                                         Debug( LDAP_DEBUG_ANY,
2128                                                 "%s: line %d: updatedn DN is invalid\n",
2129                                             fname, lineno, 0 );
2130 #endif
2131                                         return 1;
2132                                 }
2133
2134                         }
2135                         SLAP_DBFLAGS(be) |= ( SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SLURP_SHADOW );
2136
2137                 } else if ( strcasecmp( cargv[0], "updateref" ) == 0 ) {
2138                         if ( cargc < 2 ) {
2139 #ifdef NEW_LOGGING
2140                                 LDAP_LOG( CONFIG, CRIT, "%s: line %d: "
2141                                         "missing url in \"updateref <ldapurl>\" line.\n",
2142                                         fname, lineno , 0 );
2143 #else
2144                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
2145                                         "missing url in \"updateref <ldapurl>\" line\n",
2146                                     fname, lineno, 0 );
2147 #endif
2148
2149                                 return( 1 );
2150                         }
2151                         if ( be == NULL ) {
2152 #ifdef NEW_LOGGING
2153                                 LDAP_LOG( CONFIG, INFO, "%s: line %d: updateref"
2154                                         " line must appear inside a database definition\n",
2155                                         fname, lineno , 0 );
2156 #else
2157                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: updateref"
2158                                         " line must appear inside a database definition\n",
2159                                         fname, lineno, 0 );
2160 #endif
2161                                 return 1;
2162
2163                         } else if ( !SLAP_SHADOW(be) ) {
2164 #ifdef NEW_LOGGING
2165                                 LDAP_LOG( CONFIG, INFO, "%s: line %d: "
2166                                         "updateref line must come after syncrepl or updatedn.\n",
2167                                         fname, lineno , 0 );
2168 #else
2169                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
2170                                         "updateref line must after syncrepl or updatedn.\n",
2171                                     fname, lineno, 0 );
2172 #endif
2173                                 return 1;
2174                         }
2175
2176                         if( validate_global_referral( cargv[1] ) ) {
2177 #ifdef NEW_LOGGING
2178                                 LDAP_LOG( CONFIG, CRIT, "%s: line %d: "
2179                                         "invalid URL (%s) in \"updateref\" line.\n",
2180                                         fname, lineno, cargv[1] );
2181 #else
2182                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
2183                                         "invalid URL (%s) in \"updateref\" line.\n",
2184                                     fname, lineno, cargv[1] );
2185 #endif
2186                                 return 1;
2187                         }
2188
2189                         vals[0].bv_val = cargv[1];
2190                         vals[0].bv_len = strlen( vals[0].bv_val );
2191                         if( value_add( &be->be_update_refs, vals ) ) {
2192                                 return LDAP_OTHER;
2193                         }
2194
2195                 /* replication log file to which changes are appended */
2196                 } else if ( strcasecmp( cargv[0], "replogfile" ) == 0 ) {
2197                         if ( cargc < 2 ) {
2198 #ifdef NEW_LOGGING
2199                                 LDAP_LOG( CONFIG, CRIT, 
2200                                         "%s: line %d: missing filename in \"replogfile <filename>\""
2201                                         " line.\n", fname, lineno , 0 );
2202 #else
2203                                 Debug( LDAP_DEBUG_ANY,
2204             "%s: line %d: missing filename in \"replogfile <filename>\" line\n",
2205                                     fname, lineno, 0 );
2206 #endif
2207
2208                                 return( 1 );
2209                         }
2210                         if ( be ) {
2211                                 be->be_replogfile = ch_strdup( cargv[1] );
2212                         } else {
2213                                 replogfile = ch_strdup( cargv[1] );
2214                         }
2215
2216                 /* file from which to read additional rootdse attrs */
2217                 } else if ( strcasecmp( cargv[0], "rootDSE" ) == 0) {
2218                         if ( cargc < 2 ) {
2219 #ifdef NEW_LOGGING
2220                                 LDAP_LOG( CONFIG, CRIT, "%s: line %d: "
2221                                         "missing filename in \"rootDSE <filename>\" line.\n",
2222                                         fname, lineno , 0 );
2223 #else
2224                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
2225                                         "missing filename in \"rootDSE <filename>\" line.\n",
2226                                     fname, lineno, 0 );
2227 #endif
2228                                 return 1;
2229                         }
2230
2231                         if( read_root_dse_file( cargv[1] ) ) {
2232 #ifdef NEW_LOGGING
2233                                 LDAP_LOG( CONFIG, CRIT, "%s: line %d: "
2234                                         "could not read \"rootDSE <filename>\" line.\n",
2235                                         fname, lineno , 0 );
2236 #else
2237                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
2238                                         "could not read \"rootDSE <filename>\" line\n",
2239                                     fname, lineno, 0 );
2240 #endif
2241                                 return 1;
2242                         }
2243
2244                 /* maintain lastmodified{by,time} attributes */
2245                 } else if ( strcasecmp( cargv[0], "lastmod" ) == 0 ) {
2246                         if ( cargc < 2 ) {
2247 #ifdef NEW_LOGGING
2248                                 LDAP_LOG( CONFIG, CRIT, 
2249                                            "%s: line %d: missing on|off in \"lastmod <on|off>\""
2250                                            " line.\n", fname, lineno , 0 );
2251 #else
2252                                 Debug( LDAP_DEBUG_ANY,
2253             "%s: line %d: missing on|off in \"lastmod <on|off>\" line\n",
2254                                     fname, lineno, 0 );
2255 #endif
2256
2257                                 return( 1 );
2258                         }
2259
2260                         if ( be == NULL ) {
2261 #ifdef NEW_LOGGING
2262                                 LDAP_LOG( CONFIG, INFO, "%s: line %d: lastmod"
2263                                         " line must appear inside a database definition\n",
2264                                         fname, lineno , 0 );
2265 #else
2266                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: lastmod"
2267                                         " line must appear inside a database definition\n",
2268                                         fname, lineno, 0 );
2269 #endif
2270                                 return 1;
2271
2272                         } else if ( SLAP_NOLASTMODCMD(be) ) {
2273 #ifdef NEW_LOGGING
2274                                 LDAP_LOG( CONFIG, INFO, "%s: line %d: lastmod"
2275                                         " not available for %s database\n",
2276                                         fname, lineno , be->bd_info->bi_type );
2277 #else
2278                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: lastmod"
2279                                         " not available for %s databases\n",
2280                                         fname, lineno, be->bd_info->bi_type );
2281 #endif
2282                                 return 1;
2283                         }
2284
2285                         if ( strcasecmp( cargv[1], "on" ) == 0 ) {
2286                                 SLAP_DBFLAGS(be) &= ~SLAP_DBFLAG_NOLASTMOD;
2287                         } else {
2288                                 SLAP_DBFLAGS(be) |= SLAP_DBFLAG_NOLASTMOD;
2289                         }
2290
2291 #ifdef SIGHUP
2292                 /* turn on/off gentle SIGHUP handling */
2293                 } else if ( strcasecmp( cargv[0], "gentlehup" ) == 0 ) {
2294                         if ( cargc < 2 ) {
2295                                 Debug( LDAP_DEBUG_ANY,
2296     "%s: line %d: missing on|off in \"gentlehup <on|off>\" line\n",
2297                                     fname, lineno, 0 );
2298                                 return( 1 );
2299                         }
2300                         if ( strcasecmp( cargv[1], "off" ) == 0 ) {
2301                                 global_gentlehup = 0;
2302                         } else {
2303                                 global_gentlehup = 1;
2304                         }
2305 #endif
2306
2307                 /* set idle timeout value */
2308                 } else if ( strcasecmp( cargv[0], "idletimeout" ) == 0 ) {
2309                         int i;
2310                         if ( cargc < 2 ) {
2311 #ifdef NEW_LOGGING
2312                                 LDAP_LOG( CONFIG, CRIT, 
2313                                         "%s: line %d: missing timeout value in "
2314                                         "\"idletimeout <seconds>\" line.\n", fname, lineno , 0 );
2315 #else
2316                                 Debug( LDAP_DEBUG_ANY,
2317             "%s: line %d: missing timeout value in \"idletimeout <seconds>\" line\n",
2318                                     fname, lineno, 0 );
2319 #endif
2320
2321                                 return( 1 );
2322                         }
2323
2324                         i = atoi( cargv[1] );
2325
2326                         if( i < 0 ) {
2327 #ifdef NEW_LOGGING
2328                                 LDAP_LOG( CONFIG, CRIT, 
2329                                         "%s: line %d: timeout value (%d) invalid "
2330                                         "\"idletimeout <seconds>\" line.\n", fname, lineno, i );
2331 #else
2332                                 Debug( LDAP_DEBUG_ANY,
2333             "%s: line %d: timeout value (%d) invalid \"idletimeout <seconds>\" line\n",
2334                                     fname, lineno, i );
2335 #endif
2336
2337                                 return( 1 );
2338                         }
2339
2340                         global_idletimeout = i;
2341
2342                 /* include another config file */
2343                 } else if ( strcasecmp( cargv[0], "include" ) == 0 ) {
2344                         if ( cargc < 2 ) {
2345 #ifdef NEW_LOGGING
2346                                 LDAP_LOG( CONFIG, CRIT, 
2347                                         "%s: line %d: missing filename in \"include "
2348                                         "<filename>\" line.\n", fname, lineno , 0 );
2349 #else
2350                                 Debug( LDAP_DEBUG_ANY,
2351     "%s: line %d: missing filename in \"include <filename>\" line\n",
2352                                     fname, lineno, 0 );
2353 #endif
2354
2355                                 return( 1 );
2356                         }
2357                         savefname = ch_strdup( cargv[1] );
2358                         savelineno = lineno;
2359
2360                         if ( read_config( savefname, depth+1 ) != 0 ) {
2361                                 return( 1 );
2362                         }
2363
2364                         free( savefname );
2365                         lineno = savelineno - 1;
2366
2367                 /* location of kerberos srvtab file */
2368                 } else if ( strcasecmp( cargv[0], "srvtab" ) == 0 ) {
2369                         if ( cargc < 2 ) {
2370 #ifdef NEW_LOGGING
2371                                 LDAP_LOG( CONFIG, CRIT, 
2372                                         "%s: line %d: missing filename in \"srvtab "
2373                                         "<filename>\" line.\n", fname, lineno , 0 );
2374 #else
2375                                 Debug( LDAP_DEBUG_ANY,
2376             "%s: line %d: missing filename in \"srvtab <filename>\" line\n",
2377                                     fname, lineno, 0 );
2378 #endif
2379
2380                                 return( 1 );
2381                         }
2382                         ldap_srvtab = ch_strdup( cargv[1] );
2383
2384 #ifdef SLAPD_MODULES
2385                 } else if (strcasecmp( cargv[0], "moduleload") == 0 ) {
2386                    if ( cargc < 2 ) {
2387 #ifdef NEW_LOGGING
2388                            LDAP_LOG( CONFIG, INFO, 
2389                                    "%s: line %d: missing filename in \"moduleload "
2390                                    "<filename>\" line.\n", fname, lineno , 0 );
2391 #else
2392                       Debug( LDAP_DEBUG_ANY,
2393                              "%s: line %d: missing filename in \"moduleload <filename>\" line\n",
2394                              fname, lineno, 0 );
2395 #endif
2396
2397                       exit( EXIT_FAILURE );
2398                    }
2399                    if (module_load(cargv[1], cargc - 2, (cargc > 2) ? cargv + 2 : NULL)) {
2400 #ifdef NEW_LOGGING
2401                            LDAP_LOG( CONFIG, CRIT, 
2402                                    "%s: line %d: failed to load or initialize module %s\n",
2403                                    fname, lineno, cargv[1] );
2404 #else
2405                       Debug( LDAP_DEBUG_ANY,
2406                              "%s: line %d: failed to load or initialize module %s\n",
2407                              fname, lineno, cargv[1]);
2408 #endif
2409
2410                       exit( EXIT_FAILURE );
2411                    }
2412                 } else if (strcasecmp( cargv[0], "modulepath") == 0 ) {
2413                    if ( cargc != 2 ) {
2414 #ifdef NEW_LOGGING
2415                            LDAP_LOG( CONFIG, INFO, 
2416                                   "%s: line %d: missing path in \"modulepath <path>\""
2417                                   " line\n", fname, lineno , 0 );
2418 #else
2419                       Debug( LDAP_DEBUG_ANY,
2420                              "%s: line %d: missing path in \"modulepath <path>\" line\n",
2421                              fname, lineno, 0 );
2422 #endif
2423
2424                       exit( EXIT_FAILURE );
2425                    }
2426                    if (module_path( cargv[1] )) {
2427 #ifdef NEW_LOGGING
2428                            LDAP_LOG( CONFIG, CRIT, 
2429                                   "%s: line %d: failed to set module search path to %s.\n",
2430                                   fname, lineno, cargv[1] );
2431 #else
2432                            Debug( LDAP_DEBUG_ANY,
2433                                   "%s: line %d: failed to set module search path to %s\n",
2434                                   fname, lineno, cargv[1]);
2435 #endif
2436
2437                       exit( EXIT_FAILURE );
2438                    }
2439                    
2440 #endif /*SLAPD_MODULES*/
2441
2442 #ifdef HAVE_TLS
2443                 } else if ( !strcasecmp( cargv[0], "TLSRandFile" ) ) {
2444                         rc = ldap_pvt_tls_set_option( NULL,
2445                                                       LDAP_OPT_X_TLS_RANDOM_FILE,
2446                                                       cargv[1] );
2447                         if ( rc )
2448                                 return rc;
2449
2450                 } else if ( !strcasecmp( cargv[0], "TLSCipherSuite" ) ) {
2451                         rc = ldap_pvt_tls_set_option( NULL,
2452                                                       LDAP_OPT_X_TLS_CIPHER_SUITE,
2453                                                       cargv[1] );
2454                         if ( rc )
2455                                 return rc;
2456
2457                 } else if ( !strcasecmp( cargv[0], "TLSCertificateFile" ) ) {
2458                         rc = ldap_pvt_tls_set_option( NULL,
2459                                                       LDAP_OPT_X_TLS_CERTFILE,
2460                                                       cargv[1] );
2461                         if ( rc )
2462                                 return rc;
2463
2464                 } else if ( !strcasecmp( cargv[0], "TLSCertificateKeyFile" ) ) {
2465                         rc = ldap_pvt_tls_set_option( NULL,
2466                                                       LDAP_OPT_X_TLS_KEYFILE,
2467                                                       cargv[1] );
2468                         if ( rc )
2469                                 return rc;
2470
2471                 } else if ( !strcasecmp( cargv[0], "TLSCACertificatePath" ) ) {
2472                         rc = ldap_pvt_tls_set_option( NULL,
2473                                                       LDAP_OPT_X_TLS_CACERTDIR,
2474                                                       cargv[1] );
2475                         if ( rc )
2476                                 return rc;
2477
2478                 } else if ( !strcasecmp( cargv[0], "TLSCACertificateFile" ) ) {
2479                         rc = ldap_pvt_tls_set_option( NULL,
2480                                                       LDAP_OPT_X_TLS_CACERTFILE,
2481                                                       cargv[1] );
2482                         if ( rc )
2483                                 return rc;
2484                 } else if ( !strcasecmp( cargv[0], "TLSVerifyClient" ) ) {
2485                         if ( isdigit( (unsigned char) cargv[1][0] ) ) {
2486                                 i = atoi(cargv[1]);
2487                                 rc = ldap_pvt_tls_set_option( NULL,
2488                                                       LDAP_OPT_X_TLS_REQUIRE_CERT,
2489                                                       &i );
2490                         } else {
2491                                 rc = ldap_int_tls_config( NULL,
2492                                                       LDAP_OPT_X_TLS_REQUIRE_CERT,
2493                                                       cargv[1] );
2494                         }
2495
2496                         if ( rc )
2497                                 return rc;
2498
2499 #endif
2500
2501                 } else if ( !strcasecmp( cargv[0], "reverse-lookup" ) ) {
2502 #ifdef SLAPD_RLOOKUPS
2503                         if ( cargc < 2 ) {
2504 #ifdef NEW_LOGGING
2505                                 LDAP_LOG( CONFIG, INFO, 
2506                                         "%s: line %d: reverse-lookup: missing \"on\" or \"off\"\n",
2507                                         fname, lineno , 0 );
2508 #else
2509                                 Debug( LDAP_DEBUG_ANY,
2510 "%s: line %d: reverse-lookup: missing \"on\" or \"off\"\n",
2511                                         fname, lineno, 0 );
2512 #endif
2513                                 return( 1 );
2514                         }
2515
2516                         if ( !strcasecmp( cargv[1], "on" ) ) {
2517                                 use_reverse_lookup = 1;
2518                         } else if ( !strcasecmp( cargv[1], "off" ) ) {
2519                                 use_reverse_lookup = 0;
2520                         } else {
2521 #ifdef NEW_LOGGING
2522                                 LDAP_LOG( CONFIG, INFO, 
2523                                         "%s: line %d: reverse-lookup: "
2524                                         "must be \"on\" (default) or \"off\"\n", fname, lineno, 0 );
2525 #else
2526                                 Debug( LDAP_DEBUG_ANY,
2527 "%s: line %d: reverse-lookup: must be \"on\" (default) or \"off\"\n",
2528                                         fname, lineno, 0 );
2529 #endif
2530                                 return( 1 );
2531                         }
2532
2533 #else /* !SLAPD_RLOOKUPS */
2534 #ifdef NEW_LOGGING
2535                         LDAP_LOG( CONFIG, INFO, 
2536                                 "%s: line %d: reverse lookups "
2537                                 "are not configured (ignored).\n", fname, lineno , 0 );
2538 #else
2539                         Debug( LDAP_DEBUG_ANY,
2540 "%s: line %d: reverse lookups are not configured (ignored).\n",
2541                                 fname, lineno, 0 );
2542 #endif
2543 #endif /* !SLAPD_RLOOKUPS */
2544
2545                 /* Netscape plugins */
2546                 } else if ( strcasecmp( cargv[0], "plugin" ) == 0 ) {
2547 #if defined( LDAP_SLAPI )
2548
2549 #ifdef notdef /* allow global plugins, too */
2550                         /*
2551                          * a "plugin" line must be inside a database
2552                          * definition, since we implement pre-,post- 
2553                          * and extended operation plugins
2554                          */
2555                         if ( be == NULL ) {
2556 #ifdef NEW_LOGGING
2557                                 LDAP_LOG( CONFIG, INFO, 
2558                                         "%s: line %d: plugin line must appear "
2559                                         "insid a database definition.\n",
2560                                         fname, lineno, 0 );
2561 #else
2562                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: plugin "
2563                                     "line must appear inside a database "
2564                                     "definition\n", fname, lineno, 0 );
2565 #endif
2566                                 return( 1 );
2567                         }
2568 #endif /* notdef */
2569
2570                         if ( slapi_int_read_config( be, fname, lineno, cargc, cargv ) 
2571                                         != LDAP_SUCCESS ) {
2572                                 return( 1 );
2573                         }
2574                         slapi_plugins_used++;
2575
2576 #else /* !defined( LDAP_SLAPI ) */
2577 #ifdef NEW_LOGGING
2578                         LDAP_LOG( CONFIG, INFO, 
2579                                 "%s: line %d: SLAPI not supported.\n",
2580                                 fname, lineno, 0 );
2581 #else
2582                         Debug( LDAP_DEBUG_ANY, "%s: line %d: SLAPI "
2583                             "not supported.\n", fname, lineno, 0 );
2584 #endif
2585                         return( 1 );
2586                         
2587 #endif /* !defined( LDAP_SLAPI ) */
2588
2589                 /* Netscape plugins */
2590                 } else if ( strcasecmp( cargv[0], "pluginlog" ) == 0 ) {
2591 #if defined( LDAP_SLAPI )
2592                         if ( cargc < 2 ) {
2593 #ifdef NEW_LOGGING
2594                                 LDAP_LOG( CONFIG, INFO, 
2595                                         "%s: line %d: missing file name "
2596                                         "in pluginlog <filename> line.\n",
2597                                         fname, lineno, 0 );
2598 #else
2599                                 Debug( LDAP_DEBUG_ANY, 
2600                                         "%s: line %d: missing file name "
2601                                         "in pluginlog <filename> line.\n",
2602                                         fname, lineno, 0 );
2603 #endif
2604                                 return( 1 );
2605                         }
2606
2607                         if ( slapi_log_file != NULL ) {
2608                                 ch_free( slapi_log_file );
2609                         }
2610
2611                         slapi_log_file = ch_strdup( cargv[1] );
2612 #endif /* !defined( LDAP_SLAPI ) */
2613
2614                 /* pass anything else to the current backend info/db config routine */
2615                 } else {
2616                         if ( bi != NULL ) {
2617                                 if ( bi->bi_config ) {
2618                                         rc = (*bi->bi_config)( bi, fname, lineno, cargc, cargv );
2619
2620                                         switch ( rc ) {
2621                                         case 0:
2622                                                 break;
2623
2624                                         case SLAP_CONF_UNKNOWN:
2625 #ifdef NEW_LOGGING
2626                                                 LDAP_LOG( CONFIG, INFO, 
2627                                                         "%s: line %d: unknown directive \"%s\" inside "
2628                                                         "backend info definition (ignored).\n",
2629                                                         fname, lineno, cargv[0] );
2630 #else
2631                                                 Debug( LDAP_DEBUG_ANY,
2632 "%s: line %d: unknown directive \"%s\" inside backend info definition (ignored)\n",
2633                                                         fname, lineno, cargv[0] );
2634 #endif
2635                                                 break;
2636
2637                                         default:
2638                                                 return 1;
2639                                         }
2640                                 }
2641
2642                         } else if ( be != NULL ) {
2643                                 if ( be->be_config ) {
2644                                         rc = (*be->be_config)( be, fname, lineno, cargc, cargv );
2645
2646                                         switch ( rc ) {
2647                                         case 0:
2648                                                 break;
2649
2650                                         case SLAP_CONF_UNKNOWN:
2651 #ifdef NEW_LOGGING
2652                                                 LDAP_LOG( CONFIG, INFO, 
2653                                                         "%s: line %d: unknown directive \"%s\" inside "
2654                                                         "backend database definition (ignored).\n",
2655                                                         fname, lineno, cargv[0] );
2656 #else
2657                                                 Debug( LDAP_DEBUG_ANY,
2658 "%s: line %d: unknown directive \"%s\" inside backend database definition (ignored)\n",
2659                                                         fname, lineno, cargv[0] );
2660 #endif
2661                                                 break;
2662
2663                                         default:
2664                                                 return 1;
2665                                         }
2666                                 }
2667
2668                         } else {
2669 #ifdef NEW_LOGGING
2670                                 LDAP_LOG( CONFIG, INFO, 
2671                                         "%s: line %d: unknown directive \"%s\" outside backend "
2672                                         "info and database definitions (ignored).\n",
2673                                         fname, lineno, cargv[0] );
2674 #else
2675                                 Debug( LDAP_DEBUG_ANY,
2676 "%s: line %d: unknown directive \"%s\" outside backend info and database definitions (ignored)\n",
2677                                     fname, lineno, cargv[0] );
2678 #endif
2679
2680                         }
2681                 }
2682                 free( saveline );
2683         }
2684         fclose( fp );
2685
2686         if ( depth == 0 ) ch_free( cargv );
2687
2688         if ( !global_schemadn.bv_val ) {
2689                 ber_str2bv( SLAPD_SCHEMA_DN, sizeof(SLAPD_SCHEMA_DN)-1, 1,
2690                         &global_schemadn );
2691                 dnNormalize( 0, NULL, NULL, &global_schemadn, &global_schemandn, NULL );
2692         }
2693
2694         if ( load_ucdata( NULL ) < 0 ) return 1;
2695         return( 0 );
2696 }
2697
2698 static int
2699 fp_parse_line(
2700     int         lineno,
2701     char        *line
2702 )
2703 {
2704         char *  token;
2705         char *  logline;
2706         char    logbuf[sizeof("pseudorootpw ***")];
2707
2708         cargc = 0;
2709         token = strtok_quote( line, " \t" );
2710
2711         logline = line;
2712
2713         if ( token && ( strcasecmp( token, "rootpw" ) == 0 ||
2714                 strcasecmp( token, "replica" ) == 0 ||          /* contains "credentials" */
2715                 strcasecmp( token, "bindpw" ) == 0 ||           /* used in back-ldap */
2716                 strcasecmp( token, "pseudorootpw" ) == 0 ||     /* used in back-meta */
2717                 strcasecmp( token, "dbpasswd" ) == 0 ) )        /* used in back-sql */
2718         {
2719                 snprintf( logline = logbuf, sizeof logbuf, "%s ***", token );
2720         }
2721
2722         if ( strtok_quote_ptr ) {
2723                 *strtok_quote_ptr = ' ';
2724         }
2725
2726 #ifdef NEW_LOGGING
2727         LDAP_LOG( CONFIG, DETAIL1, "line %d (%s)\n", lineno, logline , 0 );
2728 #else
2729         Debug( LDAP_DEBUG_CONFIG, "line %d (%s)\n", lineno, logline, 0 );
2730 #endif
2731
2732         if ( strtok_quote_ptr ) {
2733                 *strtok_quote_ptr = '\0';
2734         }
2735
2736         for ( ; token != NULL; token = strtok_quote( NULL, " \t" ) ) {
2737                 if ( cargc == cargv_size - 1 ) {
2738                         char **tmp;
2739                         tmp = ch_realloc( cargv, (cargv_size + ARGS_STEP) *
2740                                             sizeof(*cargv) );
2741                         if ( tmp == NULL ) {
2742 #ifdef NEW_LOGGING
2743                                 LDAP_LOG( CONFIG, ERR, "line %d: out of memory\n", lineno, 0,0 );
2744 #else
2745                                 Debug( LDAP_DEBUG_ANY, 
2746                                                 "line %d: out of memory\n", 
2747                                                 lineno, 0, 0 );
2748 #endif
2749                                 return -1;
2750                         }
2751                         cargv = tmp;
2752                         cargv_size += ARGS_STEP;
2753                 }
2754                 cargv[cargc++] = token;
2755         }
2756         cargv[cargc] = NULL;
2757         return 0;
2758 }
2759
2760 static char *
2761 strtok_quote( char *line, char *sep )
2762 {
2763         int             inquote;
2764         char            *tmp;
2765         static char     *next;
2766
2767         strtok_quote_ptr = NULL;
2768         if ( line != NULL ) {
2769                 next = line;
2770         }
2771         while ( *next && strchr( sep, *next ) ) {
2772                 next++;
2773         }
2774
2775         if ( *next == '\0' ) {
2776                 next = NULL;
2777                 return( NULL );
2778         }
2779         tmp = next;
2780
2781         for ( inquote = 0; *next; ) {
2782                 switch ( *next ) {
2783                 case '"':
2784                         if ( inquote ) {
2785                                 inquote = 0;
2786                         } else {
2787                                 inquote = 1;
2788                         }
2789                         AC_MEMCPY( next, next + 1, strlen( next + 1 ) + 1 );
2790                         break;
2791
2792                 case '\\':
2793                         if ( next[1] )
2794                                 AC_MEMCPY( next,
2795                                             next + 1, strlen( next + 1 ) + 1 );
2796                         next++;         /* dont parse the escaped character */
2797                         break;
2798
2799                 default:
2800                         if ( ! inquote ) {
2801                                 if ( strchr( sep, *next ) != NULL ) {
2802                                         strtok_quote_ptr = next;
2803                                         *next++ = '\0';
2804                                         return( tmp );
2805                                 }
2806                         }
2807                         next++;
2808                         break;
2809                 }
2810         }
2811
2812         return( tmp );
2813 }
2814
2815 static char     buf[BUFSIZ];
2816 static char     *line;
2817 static size_t lmax, lcur;
2818
2819 #define CATLINE( buf ) \
2820         do { \
2821                 size_t len = strlen( buf ); \
2822                 while ( lcur + len + 1 > lmax ) { \
2823                         lmax += BUFSIZ; \
2824                         line = (char *) ch_realloc( line, lmax ); \
2825                 } \
2826                 strcpy( line + lcur, buf ); \
2827                 lcur += len; \
2828         } while( 0 )
2829
2830 static char *
2831 fp_getline( FILE *fp, int *lineno )
2832 {
2833         char            *p;
2834
2835         lcur = 0;
2836         CATLINE( buf );
2837         (*lineno)++;
2838
2839         /* hack attack - keeps us from having to keep a stack of bufs... */
2840         if ( strncasecmp( line, "include", 7 ) == 0 ) {
2841                 buf[0] = '\0';
2842                 return( line );
2843         }
2844
2845         while ( fgets( buf, sizeof(buf), fp ) != NULL ) {
2846                 /* trim off \r\n or \n */
2847                 if ( (p = strchr( buf, '\n' )) != NULL ) {
2848                         if( p > buf && p[-1] == '\r' ) --p;
2849                         *p = '\0';
2850                 }
2851                 
2852                 /* trim off trailing \ and append the next line */
2853                 if ( line[ 0 ] != '\0' 
2854                                 && (p = line + strlen( line ) - 1)[ 0 ] == '\\'
2855                                 && p[ -1 ] != '\\' ) {
2856                         p[ 0 ] = '\0';
2857                         lcur--;
2858
2859                 } else {
2860                         if ( ! isspace( (unsigned char) buf[0] ) ) {
2861                                 return( line );
2862                         }
2863
2864                         /* change leading whitespace to a space */
2865                         buf[0] = ' ';
2866                 }
2867
2868                 CATLINE( buf );
2869                 (*lineno)++;
2870         }
2871         buf[0] = '\0';
2872
2873         return( line[0] ? line : NULL );
2874 }
2875
2876 static void
2877 fp_getline_init( int *lineno )
2878 {
2879         *lineno = -1;
2880         buf[0] = '\0';
2881 }
2882
2883 /* Loads ucdata, returns 1 if loading, 0 if already loaded, -1 on error */
2884 static int
2885 load_ucdata( char *path )
2886 {
2887         static int loaded = 0;
2888         int err;
2889         
2890         if ( loaded ) {
2891                 return( 0 );
2892         }
2893         err = ucdata_load( path ? path : SLAPD_DEFAULT_UCDATA, UCDATA_ALL );
2894         if ( err ) {
2895 #ifdef NEW_LOGGING
2896                 LDAP_LOG( CONFIG, CRIT, 
2897                         "load_ucdata: Error %d loading ucdata.\n", err, 0,0 );
2898 #else
2899                 Debug( LDAP_DEBUG_ANY, "error loading ucdata (error %d)\n",
2900                        err, 0, 0 );
2901 #endif
2902
2903                 return( -1 );
2904         }
2905         loaded = 1;
2906         return( 1 );
2907 }
2908
2909 void
2910 config_destroy( )
2911 {
2912         ucdata_unload( UCDATA_ALL );
2913         free( global_schemandn.bv_val );
2914         free( global_schemadn.bv_val );
2915         free( line );
2916         if ( slapd_args_file )
2917                 free ( slapd_args_file );
2918         if ( slapd_pid_file )
2919                 free ( slapd_pid_file );
2920         if ( default_passwd_hash )
2921                 ldap_charray_free( default_passwd_hash );
2922         acl_destroy( global_acl, NULL );
2923 }
2924
2925 static int
2926 add_syncrepl(
2927         Backend *be,
2928         char    **cargv,
2929         int     cargc
2930 )
2931 {
2932         syncinfo_t *si;
2933         syncinfo_t *si_entry;
2934         int     rc = 0;
2935         int duplicated_replica_id = 0;
2936
2937         si = (syncinfo_t *) ch_calloc( 1, sizeof( syncinfo_t ) );
2938
2939         if ( si == NULL ) {
2940 #ifdef NEW_LOGGING
2941                 LDAP_LOG( CONFIG, ERR, "out of memory in add_syncrepl\n", 0, 0,0 );
2942 #else
2943                 Debug( LDAP_DEBUG_ANY, "out of memory in add_syncrepl\n", 0, 0, 0 );
2944 #endif
2945                 return 1;
2946         }
2947
2948         si->si_tls = SYNCINFO_TLS_OFF;
2949         if ( be->be_rootndn.bv_val ) {
2950                 ber_dupbv( &si->si_updatedn, &be->be_rootndn );
2951         }
2952         si->si_bindmethod = LDAP_AUTH_SIMPLE;
2953         si->si_schemachecking = 0;
2954         ber_str2bv( "(objectclass=*)", STRLENOF("(objectclass=*)"), 1,
2955                 &si->si_filterstr );
2956         si->si_base.bv_val = NULL;
2957         si->si_scope = LDAP_SCOPE_SUBTREE;
2958         si->si_attrsonly = 0;
2959         si->si_attrs = (char **) ch_calloc( 1, sizeof( char * ));
2960         si->si_attrs[0] = NULL;
2961         si->si_exattrs = (char **) ch_calloc( 1, sizeof( char * ));
2962         si->si_exattrs[0] = NULL;
2963         si->si_type = LDAP_SYNC_REFRESH_ONLY;
2964         si->si_interval = 86400;
2965         si->si_retryinterval = NULL;
2966         si->si_retrynum_init = NULL;
2967         si->si_retrynum = NULL;
2968         si->si_syncCookie.ctxcsn = NULL;
2969         si->si_syncCookie.octet_str = NULL;
2970         si->si_syncCookie.sid = -1;
2971         si->si_manageDSAit = 0;
2972         si->si_tlimit = 0;
2973         si->si_slimit = 0;
2974
2975         si->si_presentlist = NULL;
2976         LDAP_LIST_INIT( &si->si_nonpresentlist );
2977         ldap_pvt_thread_mutex_init( &si->si_mutex );
2978
2979         rc = parse_syncrepl_line( cargv, cargc, si );
2980
2981         LDAP_STAILQ_FOREACH( si_entry, &be->be_syncinfo, si_next ) {
2982                 if ( si->si_rid == si_entry->si_rid ) {
2983 #ifdef NEW_LOGGING
2984                         LDAP_LOG( CONFIG, ERR,
2985                                 "add_syncrepl: duplicated replica id\n", 0, 0,0 );
2986 #else
2987                         Debug( LDAP_DEBUG_ANY,
2988                                 "add_syncrepl: duplicated replica id\n",0, 0, 0 );
2989 #endif
2990                         duplicated_replica_id = 1;
2991                         break;
2992                 }
2993         }
2994
2995         if ( rc < 0 || duplicated_replica_id ) {
2996                 Debug( LDAP_DEBUG_ANY, "failed to add syncinfo\n", 0, 0, 0 );
2997                 return 1;
2998         } else {
2999 #ifdef NEW_LOGGING
3000                 LDAP_LOG ( CONFIG, RESULTS,
3001                         "add_syncrepl: Config: ** successfully added syncrepl \"%s\"\n",
3002                         si->si_provideruri == NULL ? "(null)" : si->si_provideruri, 0, 0 );
3003 #else
3004                 Debug( LDAP_DEBUG_CONFIG,
3005                         "Config: ** successfully added syncrepl \"%s\"\n",
3006                         si->si_provideruri == NULL ? "(null)" : si->si_provideruri, 0, 0 );
3007 #endif
3008                 if ( !si->si_schemachecking ) {
3009                         SLAP_DBFLAGS(be) |= SLAP_DBFLAG_NO_SCHEMA_CHECK;
3010                 }
3011                 si->si_be = be;
3012                 LDAP_STAILQ_INSERT_TAIL( &be->be_syncinfo, si, si_next );
3013                 return 0;
3014         }
3015 }
3016
3017 #define IDSTR                   "rid"
3018 #define PROVIDERSTR             "provider"
3019 #define SUFFIXSTR               "suffix"
3020 #define UPDATEDNSTR             "updatedn"
3021 #define BINDMETHSTR             "bindmethod"
3022 #define SIMPLESTR               "simple"
3023 #define SASLSTR                 "sasl"
3024 #define BINDDNSTR               "binddn"
3025 #define CREDSTR                 "credentials"
3026 #define OLDAUTHCSTR             "bindprincipal"
3027 #define AUTHCSTR                "authcID"
3028 #define AUTHZSTR                "authzID"
3029 #define SRVTABSTR               "srvtab"
3030 #define SASLMECHSTR             "saslmech"
3031 #define REALMSTR                "realm"
3032 #define SECPROPSSTR             "secprops"
3033 #define STARTTLSSTR             "starttls"
3034 #define CRITICALSTR             "critical"
3035
3036 #define SCHEMASTR               "schemachecking"
3037 #define FILTERSTR               "filter"
3038 #define SEARCHBASESTR   "searchbase"
3039 #define SCOPESTR                "scope"
3040 #define ATTRSSTR                "attrs"
3041 #define ATTRSONLYSTR    "attrsonly"
3042 #define EXATTRSSTR              "exattrs"
3043 #define TYPESTR                 "type"
3044 #define INTERVALSTR             "interval"
3045 #define LASTMODSTR              "lastmod"
3046 #define LMREQSTR                "req"
3047 #define LMGENSTR                "gen"
3048 #define LMNOSTR                 "no"
3049 #define MANAGEDSAITSTR  "manageDSAit"
3050 #define SLIMITSTR               "sizelimit"
3051 #define TLIMITSTR               "timelimit"
3052
3053 #define RETRYSTR                "retry"
3054
3055 #define GOT_ID                  0x0001
3056 #define GOT_PROVIDER    0x0002
3057 #define GOT_METHOD              0x0004
3058 #define GOT_ALL                 0x0007
3059
3060 static int
3061 parse_syncrepl_line(
3062         char            **cargv,
3063         int             cargc,
3064         syncinfo_t      *si
3065 )
3066 {
3067         int     gots = 0;
3068         int     i, j;
3069         char    *hp, *val;
3070         int     nr_attr = 0;
3071
3072         for ( i = 1; i < cargc; i++ ) {
3073                 if ( !strncasecmp( cargv[ i ], IDSTR, sizeof( IDSTR ) - 1 )) {
3074                         int tmp;
3075                         /* '\0' string terminator accounts for '=' */
3076                         val = cargv[ i ] + sizeof( IDSTR );
3077                         tmp= atoi( val );
3078                         if ( tmp >= 1000 || tmp < 0 ) {
3079                                 fprintf( stderr, "Error: parse_syncrepl_line: "
3080                                          "syncrepl id %d is out of range [0..999]\n", tmp );
3081                                 return -1;
3082                         }
3083                         si->si_rid = tmp;
3084                         gots |= GOT_ID;
3085                 } else if ( !strncasecmp( cargv[ i ], PROVIDERSTR,
3086                                         sizeof( PROVIDERSTR ) - 1 )) {
3087                         val = cargv[ i ] + sizeof( PROVIDERSTR );
3088                         si->si_provideruri = ch_strdup( val );
3089                         si->si_provideruri_bv = (BerVarray)
3090                                 ch_calloc( 2, sizeof( struct berval ));
3091                         ber_str2bv( si->si_provideruri, strlen( si->si_provideruri ),
3092                                 1, &si->si_provideruri_bv[0] );
3093                         si->si_provideruri_bv[1].bv_len = 0;
3094                         si->si_provideruri_bv[1].bv_val = NULL;
3095                         gots |= GOT_PROVIDER;
3096                 } else if ( !strncasecmp( cargv[ i ], STARTTLSSTR,
3097                         sizeof(STARTTLSSTR) - 1 ) )
3098                 {
3099                         val = cargv[ i ] + sizeof( STARTTLSSTR );
3100                         if( !strcasecmp( val, CRITICALSTR ) ) {
3101                                 si->si_tls = SYNCINFO_TLS_CRITICAL;
3102                         } else {
3103                                 si->si_tls = SYNCINFO_TLS_ON;
3104                         }
3105                 } else if ( !strncasecmp( cargv[ i ],
3106                         UPDATEDNSTR, sizeof( UPDATEDNSTR ) - 1 ) )
3107                 {
3108                         struct berval updatedn = {0, NULL};
3109                         val = cargv[ i ] + sizeof( UPDATEDNSTR );
3110                         ber_str2bv( val, 0, 0, &updatedn );
3111                         ch_free( si->si_updatedn.bv_val );
3112                         dnNormalize( 0, NULL, NULL, &updatedn, &si->si_updatedn, NULL );
3113                 } else if ( !strncasecmp( cargv[ i ], BINDMETHSTR,
3114                                 sizeof( BINDMETHSTR ) - 1 ) )
3115                 {
3116                         val = cargv[ i ] + sizeof( BINDMETHSTR );
3117                         if ( !strcasecmp( val, SIMPLESTR )) {
3118                                 si->si_bindmethod = LDAP_AUTH_SIMPLE;
3119                                 gots |= GOT_METHOD;
3120                         } else if ( !strcasecmp( val, SASLSTR )) {
3121 #ifdef HAVE_CYRUS_SASL
3122                                 si->si_bindmethod = LDAP_AUTH_SASL;
3123                                 gots |= GOT_METHOD;
3124 #else /* HAVE_CYRUS_SASL */
3125                                 fprintf( stderr, "Error: parse_syncrepl_line: "
3126                                         "not compiled with SASL support\n" );
3127                                 return -1;
3128 #endif /* HAVE_CYRUS_SASL */
3129                         } else {
3130                                 si->si_bindmethod = -1;
3131                         }
3132                 } else if ( !strncasecmp( cargv[ i ],
3133                                 BINDDNSTR, sizeof( BINDDNSTR ) - 1 ) ) {
3134                         val = cargv[ i ] + sizeof( BINDDNSTR );
3135                         si->si_binddn = ch_strdup( val );
3136                 } else if ( !strncasecmp( cargv[ i ],
3137                                 CREDSTR, sizeof( CREDSTR ) - 1 ) ) {
3138                         val = cargv[ i ] + sizeof( CREDSTR );
3139                         si->si_passwd = ch_strdup( val );
3140                 } else if ( !strncasecmp( cargv[ i ],
3141                                 SASLMECHSTR, sizeof( SASLMECHSTR ) - 1 ) ) {
3142                         val = cargv[ i ] + sizeof( SASLMECHSTR );
3143                         si->si_saslmech = ch_strdup( val );
3144                 } else if ( !strncasecmp( cargv[ i ],
3145                                 SECPROPSSTR, sizeof( SECPROPSSTR ) - 1 ) ) {
3146                         val = cargv[ i ] + sizeof( SECPROPSSTR );
3147                         si->si_secprops = ch_strdup( val );
3148                 } else if ( !strncasecmp( cargv[ i ],
3149                                 REALMSTR, sizeof( REALMSTR ) - 1 ) ) {
3150                         val = cargv[ i ] + sizeof( REALMSTR );
3151                         si->si_realm = ch_strdup( val );
3152                 } else if ( !strncasecmp( cargv[ i ],
3153                                 AUTHCSTR, sizeof( AUTHCSTR ) - 1 ) ) {
3154                         val = cargv[ i ] + sizeof( AUTHCSTR );
3155                         if ( si->si_authcId )
3156                                 ch_free( si->si_authcId );
3157                         si->si_authcId = ch_strdup( val );
3158                 } else if ( !strncasecmp( cargv[ i ],
3159                                 OLDAUTHCSTR, sizeof( OLDAUTHCSTR ) - 1 ) ) {
3160                         /* Old authcID is provided for some backwards compatibility */
3161                         val = cargv[ i ] + sizeof( OLDAUTHCSTR );
3162                         if ( si->si_authcId )
3163                                 ch_free( si->si_authcId );
3164                         si->si_authcId = ch_strdup( val );
3165                 } else if ( !strncasecmp( cargv[ i ],
3166                                 AUTHZSTR, sizeof( AUTHZSTR ) - 1 ) ) {
3167                         val = cargv[ i ] + sizeof( AUTHZSTR );
3168                         si->si_authzId = ch_strdup( val );
3169                 } else if ( !strncasecmp( cargv[ i ],
3170                                 SCHEMASTR, sizeof( SCHEMASTR ) - 1 ) )
3171                 {
3172                         val = cargv[ i ] + sizeof( SCHEMASTR );
3173                         if ( !strncasecmp( val, "on", sizeof( "on" ) - 1 )) {
3174                                 si->si_schemachecking = 1;
3175                         } else if ( !strncasecmp( val, "off", sizeof( "off" ) - 1 ) ) {
3176                                 si->si_schemachecking = 0;
3177                         } else {
3178                                 si->si_schemachecking = 1;
3179                         }
3180                 } else if ( !strncasecmp( cargv[ i ],
3181                         FILTERSTR, sizeof( FILTERSTR ) - 1 ) )
3182                 {
3183                         val = cargv[ i ] + sizeof( FILTERSTR );
3184                         ber_str2bv( val, 0, 1, &si->si_filterstr );
3185                 } else if ( !strncasecmp( cargv[ i ],
3186                         SEARCHBASESTR, sizeof( SEARCHBASESTR ) - 1 ) )
3187                 {
3188                         struct berval bv;
3189                         val = cargv[ i ] + sizeof( SEARCHBASESTR );
3190                         if ( si->si_base.bv_val ) {
3191                                 ch_free( si->si_base.bv_val );
3192                         }
3193                         ber_str2bv( val, 0, 0, &bv );
3194                         if ( dnNormalize( 0, NULL, NULL, &bv, &si->si_base, NULL )) {
3195                                 fprintf( stderr, "Invalid base DN \"%s\"\n", val );
3196                                 return -1;
3197                         }
3198                 } else if ( !strncasecmp( cargv[ i ],
3199                         SCOPESTR, sizeof( SCOPESTR ) - 1 ) )
3200                 {
3201                         val = cargv[ i ] + sizeof( SCOPESTR );
3202                         if ( !strncasecmp( val, "base", sizeof( "base" ) - 1 )) {
3203                                 si->si_scope = LDAP_SCOPE_BASE;
3204                         } else if ( !strncasecmp( val, "one", sizeof( "one" ) - 1 )) {
3205                                 si->si_scope = LDAP_SCOPE_ONELEVEL;
3206 #ifdef LDAP_SCOPE_SUBORDINATE
3207                         } else if ( !strcasecmp( val, "subordinate" ) ||
3208                                 !strcasecmp( val, "children" ))
3209                         {
3210                                 si->si_scope = LDAP_SCOPE_SUBORDINATE;
3211 #endif
3212                         } else if ( !strncasecmp( val, "sub", sizeof( "sub" ) - 1 )) {
3213                                 si->si_scope = LDAP_SCOPE_SUBTREE;
3214                         } else {
3215                                 fprintf( stderr, "Error: parse_syncrepl_line: "
3216                                         "unknown scope \"%s\"\n", val);
3217                                 return -1;
3218                         }
3219                 } else if ( !strncasecmp( cargv[ i ],
3220                         ATTRSONLYSTR, sizeof( ATTRSONLYSTR ) - 1 ) )
3221                 {
3222                         si->si_attrsonly = 1;
3223                 } else if ( !strncasecmp( cargv[ i ],
3224                         ATTRSSTR, sizeof( ATTRSSTR ) - 1 ) )
3225                 {
3226                         val = cargv[ i ] + sizeof( ATTRSSTR );
3227                         str2clist( &si->si_attrs, val, "," );
3228                 } else if ( !strncasecmp( cargv[ i ],
3229                         EXATTRSSTR, sizeof( EXATTRSSTR ) - 1 ) )
3230                 {
3231                         val = cargv[ i ] + sizeof( EXATTRSSTR );
3232                         str2clist( &si->si_exattrs, val, "," );
3233                 } else if ( !strncasecmp( cargv[ i ],
3234                         TYPESTR, sizeof( TYPESTR ) - 1 ) )
3235                 {
3236                         val = cargv[ i ] + sizeof( TYPESTR );
3237                         if ( !strncasecmp( val, "refreshOnly", sizeof("refreshOnly")-1 )) {
3238                                 si->si_type = LDAP_SYNC_REFRESH_ONLY;
3239                         } else if ( !strncasecmp( val, "refreshAndPersist",
3240                                 sizeof("refreshAndPersist")-1 ))
3241                         {
3242                                 si->si_type = LDAP_SYNC_REFRESH_AND_PERSIST;
3243                                 si->si_interval = 60;
3244                         } else {
3245                                 fprintf( stderr, "Error: parse_syncrepl_line: "
3246                                         "unknown sync type \"%s\"\n", val);
3247                                 return -1;
3248                         }
3249                 } else if ( !strncasecmp( cargv[ i ],
3250                         INTERVALSTR, sizeof( INTERVALSTR ) - 1 ) )
3251                 {
3252                         val = cargv[ i ] + sizeof( INTERVALSTR );
3253                         if ( si->si_type == LDAP_SYNC_REFRESH_AND_PERSIST ) {
3254                                 si->si_interval = 0;
3255                         } else {
3256                                 char *hstr;
3257                                 char *mstr;
3258                                 char *dstr;
3259                                 char *sstr;
3260                                 int dd, hh, mm, ss;
3261                                 dstr = val;
3262                                 hstr = strchr( dstr, ':' );
3263                                 if ( hstr == NULL ) {
3264                                         fprintf( stderr, "Error: parse_syncrepl_line: "
3265                                                 "invalid interval \"%s\"\n", val );
3266                                         return -1;
3267                                 }
3268                                 *hstr++ = '\0';
3269                                 mstr = strchr( hstr, ':' );
3270                                 if ( mstr == NULL ) {
3271                                         fprintf( stderr, "Error: parse_syncrepl_line: "
3272                                                 "invalid interval \"%s\"\n", val );
3273                                         return -1;
3274                                 }
3275                                 *mstr++ = '\0';
3276                                 sstr = strchr( mstr, ':' );
3277                                 if ( sstr == NULL ) {
3278                                         fprintf( stderr, "Error: parse_syncrepl_line: "
3279                                                 "invalid interval \"%s\"\n", val );
3280                                         return -1;
3281                                 }
3282                                 *sstr++ = '\0';
3283
3284                                 dd = atoi( dstr );
3285                                 hh = atoi( hstr );
3286                                 mm = atoi( mstr );
3287                                 ss = atoi( sstr );
3288                                 if (( hh > 24 ) || ( hh < 0 ) ||
3289                                         ( mm > 60 ) || ( mm < 0 ) ||
3290                                         ( ss > 60 ) || ( ss < 0 ) || ( dd < 0 )) {
3291                                         fprintf( stderr, "Error: parse_syncrepl_line: "
3292                                                 "invalid interval \"%s\"\n", val );
3293                                         return -1;
3294                                 }
3295                                 si->si_interval = (( dd * 24 + hh ) * 60 + mm ) * 60 + ss;
3296                         }
3297                         if ( si->si_interval < 0 ) {
3298                                 fprintf( stderr, "Error: parse_syncrepl_line: "
3299                                         "invalid interval \"%ld\"\n",
3300                                         (long) si->si_interval);
3301                                 return -1;
3302                         }
3303                 } else if ( !strncasecmp( cargv[ i ],
3304                         RETRYSTR, sizeof( RETRYSTR ) - 1 ) )
3305                 {
3306                         char *str;
3307                         char **retry_list;
3308                         int j, k, n;
3309
3310                         val = cargv[ i ] + sizeof( RETRYSTR );
3311                         retry_list = (char **) ch_calloc( 1, sizeof( char * ));
3312                         retry_list[0] = NULL;
3313
3314                         str2clist( &retry_list, val, " ,\t" );
3315
3316                         for ( k = 0; retry_list && retry_list[k]; k++ ) ;
3317                         n = k / 2;
3318                         if ( k % 2 ) {
3319                                 fprintf( stderr,
3320                                                 "Error: incomplete syncrepl retry list\n" );
3321                                 for ( k = 0; retry_list && retry_list[k]; k++ ) {
3322                                         ch_free( retry_list[k] );
3323                                 }
3324                                 ch_free( retry_list );
3325                                 exit( EXIT_FAILURE );
3326                         }
3327                         si->si_retryinterval = (time_t *) ch_calloc( n + 1, sizeof( time_t ));
3328                         si->si_retrynum = (int *) ch_calloc( n + 1, sizeof( int ));
3329                         si->si_retrynum_init = (int *) ch_calloc( n + 1, sizeof( int ));
3330                         for ( j = 0; j < n; j++ ) {
3331                                 si->si_retryinterval[j] = atoi( retry_list[j*2] );
3332                                 if ( *retry_list[j*2+1] == '+' ) {
3333                                         si->si_retrynum_init[j] = -1;
3334                                         si->si_retrynum[j] = -1;
3335                                         j++;
3336                                         break;
3337                                 } else {
3338                                         si->si_retrynum_init[j] = atoi( retry_list[j*2+1] );
3339                                         si->si_retrynum[j] = atoi( retry_list[j*2+1] );
3340                                 }
3341                         }
3342                         si->si_retrynum_init[j] = -2;
3343                         si->si_retrynum[j] = -2;
3344                         si->si_retryinterval[j] = 0;
3345                         
3346                         for ( k = 0; retry_list && retry_list[k]; k++ ) {
3347                                 ch_free( retry_list[k] );
3348                         }
3349                         ch_free( retry_list );
3350                 } else if ( !strncasecmp( cargv[ i ],
3351                         MANAGEDSAITSTR, sizeof( MANAGEDSAITSTR ) - 1 ) )
3352                 {
3353                         val = cargv[ i ] + sizeof( MANAGEDSAITSTR );
3354                         si->si_manageDSAit = atoi( val );
3355                 } else if ( !strncasecmp( cargv[ i ],
3356                         SLIMITSTR, sizeof( SLIMITSTR ) - 1 ) )
3357                 {
3358                         val = cargv[ i ] + sizeof( SLIMITSTR );
3359                         si->si_slimit = atoi( val );
3360                 } else if ( !strncasecmp( cargv[ i ],
3361                         TLIMITSTR, sizeof( TLIMITSTR ) - 1 ) )
3362                 {
3363                         val = cargv[ i ] + sizeof( TLIMITSTR );
3364                         si->si_tlimit = atoi( val );
3365                 } else {
3366                         fprintf( stderr, "Error: parse_syncrepl_line: "
3367                                 "unknown keyword \"%s\"\n", cargv[ i ] );
3368                         return -1;
3369                 }
3370         }
3371
3372         if ( gots != GOT_ALL ) {
3373                 fprintf( stderr,
3374                         "Error: Malformed \"syncrepl\" line in slapd config file" );
3375                 return -1;
3376         }
3377
3378         return 0;
3379 }
3380
3381 char **
3382 str2clist( char ***out, char *in, const char *brkstr )
3383 {
3384         char    *str;
3385         char    *s;
3386         char    *lasts;
3387         int     i, j;
3388         const char *text;
3389         char    **new;
3390
3391         /* find last element in list */
3392         for (i = 0; *out && *out[i]; i++);
3393
3394         /* protect the input string from strtok */
3395         str = ch_strdup( in );
3396
3397         if ( *str == '\0' ) {
3398                 free( str );
3399                 return( *out );
3400         }
3401
3402         /* Count words in string */
3403         j=1;
3404         for ( s = str; *s; s++ ) {
3405                 if ( strchr( brkstr, *s ) != NULL ) {
3406                         j++;
3407                 }
3408         }
3409
3410         *out = ch_realloc( *out, ( i + j + 1 ) * sizeof( char * ) );
3411         new = *out + i;
3412         for ( s = ldap_pvt_strtok( str, brkstr, &lasts );
3413                 s != NULL;
3414                 s = ldap_pvt_strtok( NULL, brkstr, &lasts ) )
3415         {
3416                 *new = ch_strdup( s );
3417                 new++;
3418         }
3419
3420         *new = NULL;
3421         free( str );
3422         return( *out );
3423 }