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