]> git.sur5r.net Git - openldap/blob - servers/slapd/config.c
syntax and mr plugins
[openldap] / servers / slapd / config.c
1 /* config.c - configuration file handling routines */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-2002 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 "lutil.h"
19 #include "ldap_pvt.h"
20 #include "slap.h"
21
22 #define ARGS_STEP       512
23
24 /*
25  * defaults for various global variables
26  */
27 struct slap_limits_set deflimit = {
28         SLAPD_DEFAULT_TIMELIMIT,        /* backward compatible limits */
29         0,
30
31         SLAPD_DEFAULT_SIZELIMIT,        /* backward compatible limits */
32         0,
33         -1                              /* no limit on unchecked size */
34 };
35
36 AccessControl   *global_acl = NULL;
37 slap_access_t           global_default_access = ACL_READ;
38 slap_mask_t             global_restrictops = 0;
39 slap_mask_t             global_allows = 0;
40 slap_mask_t             global_disallows = 0;
41 slap_mask_t             global_requires = 0;
42 slap_ssf_set_t  global_ssf_set;
43 char            *replogfile;
44 int             global_gentlehup = 0;
45 int             global_idletimeout = 0;
46 char    *global_host = NULL;
47 char    *global_realm = NULL;
48 char            *ldap_srvtab = "";
49 char            *default_passwd_hash = NULL;
50 int             cargc = 0, cargv_size = 0;
51 char    **cargv;
52 struct berval default_search_base = { 0, NULL };
53 struct berval default_search_nbase = { 0, NULL };
54 unsigned                num_subordinates = 0;
55 #ifdef SLAPD_SCHEMA_DN
56 struct berval global_schemadn = { 0, NULL };
57 struct berval global_schemandn = { 0, NULL };
58 #endif
59
60 ber_len_t sockbuf_max_incoming = SLAP_SB_MAX_INCOMING_DEFAULT;
61 ber_len_t sockbuf_max_incoming_auth= SLAP_SB_MAX_INCOMING_AUTH;
62
63 char   *slapd_pid_file  = NULL;
64 char   *slapd_args_file = NULL;
65
66 char   *strtok_quote_ptr;
67
68 #ifdef SLAPD_RLOOKUPS
69 int use_reverse_lookup = 1;
70 #else /* !SLAPD_RLOOKUPS */
71 int use_reverse_lookup = 0;
72 #endif /* !SLAPD_RLOOKUPS */
73
74 static char     *fp_getline(FILE *fp, int *lineno);
75 static void     fp_getline_init(int *lineno);
76 static int      fp_parse_line(int lineno, char *line);
77
78 static char     *strtok_quote(char *line, char *sep);
79 static int      load_ucdata(char *path);
80
81 int
82 read_config( const char *fname, int depth )
83 {
84         FILE    *fp;
85         char    *line, *savefname, *saveline;
86         int savelineno;
87         int     lineno, i;
88         int rc;
89         struct berval vals[2];
90
91         static int lastmod = 1;
92         static BackendInfo *bi = NULL;
93         static BackendDB        *be = NULL;
94
95         vals[1].bv_val = NULL;
96
97         if ( depth == 0 ) {
98                 cargv = ch_calloc( ARGS_STEP + 1, sizeof(*cargv) );
99                 cargv_size = ARGS_STEP + 1;
100         }
101
102         if ( (fp = fopen( fname, "r" )) == NULL ) {
103                 ldap_syslog = 1;
104 #ifdef NEW_LOGGING
105                 LDAP_LOG( CONFIG, ENTRY, 
106                         "read_config: " "could not open config file \"%s\": %s (%d)\n",
107                     fname, strerror(errno), errno );
108 #else
109                 Debug( LDAP_DEBUG_ANY,
110                     "could not open config file \"%s\": %s (%d)\n",
111                     fname, strerror(errno), errno );
112 #endif
113                 return 1;
114         }
115
116 #ifdef NEW_LOGGING
117         LDAP_LOG( CONFIG, ENTRY, 
118                 "read_config: reading config file %s\n", fname, 0, 0 );
119 #else
120         Debug( LDAP_DEBUG_CONFIG, "reading config file %s\n", fname, 0, 0 );
121 #endif
122
123
124         fp_getline_init( &lineno );
125
126         while ( (line = fp_getline( fp, &lineno )) != NULL ) {
127                 /* skip comments and blank lines */
128                 if ( line[0] == '#' || line[0] == '\0' ) {
129                         continue;
130                 }
131
132                 /* fp_parse_line is destructive, we save a copy */
133                 saveline = ch_strdup( line );
134
135                 if ( fp_parse_line( lineno, line ) != 0 ) {
136                         return( 1 );
137                 }
138
139                 if ( cargc < 1 ) {
140 #ifdef NEW_LOGGING
141                         LDAP_LOG( CONFIG, INFO, 
142                                 "%s: line %d: bad config line (ignored)\n", fname, lineno, 0 );
143 #else
144                         Debug( LDAP_DEBUG_ANY,
145                             "%s: line %d: bad config line (ignored)\n",
146                             fname, lineno, 0 );
147 #endif
148
149                         continue;
150                 }
151
152                 if ( strcasecmp( cargv[0], "backend" ) == 0 ) {
153                         if ( cargc < 2 ) {
154 #ifdef NEW_LOGGING
155                                 LDAP_LOG( CONFIG, CRIT, 
156                                            "%s : line %d: missing type in \"backend\" line.\n",
157                                            fname, lineno, 0 );
158 #else
159                                 Debug( LDAP_DEBUG_ANY,
160                 "%s: line %d: missing type in \"backend <type>\" line\n",
161                                     fname, lineno, 0 );
162 #endif
163
164                                 return( 1 );
165                         }
166
167                         if( be != NULL ) {
168 #ifdef NEW_LOGGING
169                                 LDAP_LOG( CONFIG, CRIT, 
170                                            "%s: line %d: backend line must appear before any "
171                                            "database definition.\n", fname, lineno , 0 );
172 #else
173                                 Debug( LDAP_DEBUG_ANY,
174 "%s: line %d: backend line must appear before any database definition\n",
175                                     fname, lineno, 0 );
176 #endif
177
178                                 return( 1 );
179                         }
180
181                         bi = backend_info( cargv[1] );
182
183                         if( bi == NULL ) {
184 #ifdef NEW_LOGGING
185                                 LDAP_LOG( CONFIG, CRIT, 
186                                            "read_config: backend %s initialization failed.\n",
187                                            cargv[1], 0, 0 );
188 #else
189                                 Debug( LDAP_DEBUG_ANY,
190                                         "backend %s initialization failed.\n",
191                                     cargv[1], 0, 0 );
192 #endif
193
194                                 return( 1 );
195                         }
196                 } else if ( strcasecmp( cargv[0], "database" ) == 0 ) {
197                         if ( cargc < 2 ) {
198 #ifdef NEW_LOGGING
199                                 LDAP_LOG( CONFIG, CRIT, 
200                                         "%s: line %d: missing type in \"database <type>\" line\n",
201                                         fname, lineno, 0 );
202 #else
203                                 Debug( LDAP_DEBUG_ANY,
204                 "%s: line %d: missing type in \"database <type>\" line\n",
205                                     fname, lineno, 0 );
206 #endif
207
208                                 return( 1 );
209                         }
210
211                         bi = NULL;
212                         be = backend_db_init( cargv[1] );
213
214                         if( be == NULL ) {
215 #ifdef NEW_LOGGING
216                                 LDAP_LOG( CONFIG, CRIT, 
217                                         "database %s initialization failed.\n", cargv[1], 0, 0 );
218 #else
219                                 Debug( LDAP_DEBUG_ANY,
220                                         "database %s initialization failed.\n",
221                                     cargv[1], 0, 0 );
222 #endif
223
224                                 return( 1 );
225                         }
226
227                 /* set thread concurrency */
228                 } else if ( strcasecmp( cargv[0], "concurrency" ) == 0 ) {
229                         int c;
230                         if ( cargc < 2 ) {
231 #ifdef NEW_LOGGING
232                                 LDAP_LOG( CONFIG, CRIT, 
233                                         "%s: line %d: missing level in \"concurrency <level\" "
234                                         " line\n", fname, lineno, 0 );
235 #else
236                                 Debug( LDAP_DEBUG_ANY,
237             "%s: line %d: missing level in \"concurrency <level>\" line\n",
238                                     fname, lineno, 0 );
239 #endif
240
241                                 return( 1 );
242                         }
243
244                         c = atoi( cargv[1] );
245
246                         if( c < 1 ) {
247 #ifdef NEW_LOGGING
248                                 LDAP_LOG( CONFIG, CRIT, 
249                                         "%s: line %d: invalid level (%d) in "
250                                         "\"concurrency <level>\" line.\n", fname, lineno, c );
251 #else
252                                 Debug( LDAP_DEBUG_ANY,
253             "%s: line %d: invalid level (%d) in \"concurrency <level>\" line\n",
254                                     fname, lineno, c );
255 #endif
256
257                                 return( 1 );
258                         }
259
260                         ldap_pvt_thread_set_concurrency( c );
261
262                 /* set sockbuf max */
263                 } else if ( strcasecmp( cargv[0], "sockbuf_max_incoming" ) == 0 ) {
264                         long max;
265                         if ( cargc < 2 ) {
266 #ifdef NEW_LOGGING
267                                 LDAP_LOG( CONFIG, CRIT, 
268                                    "%s: line %d: missing max in \"sockbuf_max_incoming "
269                                    "<bytes>\" line\n", fname, lineno, 0 );
270 #else
271                                 Debug( LDAP_DEBUG_ANY,
272                                            "%s: line %d: missing max in \"sockbuf_max_incoming <bytes>\" line\n",
273                                     fname, lineno, 0 );
274 #endif
275
276                                 return( 1 );
277                         }
278
279                         max = atol( cargv[1] );
280
281                         if( max < 0 ) {
282 #ifdef NEW_LOGGING
283                                 LDAP_LOG( CONFIG, CRIT, 
284                                            "%s: line %d: invalid max value (%ld) in "
285                                            "\"sockbuf_max_incoming <bytes>\" line.\n",
286                                            fname, lineno, max );
287 #else
288                                 Debug( LDAP_DEBUG_ANY,
289                                         "%s: line %d: invalid max value (%ld) in "
290                                         "\"sockbuf_max_incoming <bytes>\" line.\n",
291                                     fname, lineno, max );
292 #endif
293
294                                 return( 1 );
295                         }
296
297                         sockbuf_max_incoming = max;
298
299                 /* set sockbuf max authenticated */
300                 } else if ( strcasecmp( cargv[0], "sockbuf_max_incoming_auth" ) == 0 ) {
301                         long max;
302                         if ( cargc < 2 ) {
303 #ifdef NEW_LOGGING
304                                 LDAP_LOG( CONFIG, CRIT, 
305                                    "%s: line %d: missing max in \"sockbuf_max_incoming_auth "
306                                    "<bytes>\" line\n", fname, lineno, 0 );
307 #else
308                                 Debug( LDAP_DEBUG_ANY,
309                                            "%s: line %d: missing max in \"sockbuf_max_incoming_auth <bytes>\" line\n",
310                                     fname, lineno, 0 );
311 #endif
312
313                                 return( 1 );
314                         }
315
316                         max = atol( cargv[1] );
317
318                         if( max < 0 ) {
319 #ifdef NEW_LOGGING
320                                 LDAP_LOG( CONFIG, CRIT, 
321                                            "%s: line %d: invalid max value (%ld) in "
322                                            "\"sockbuf_max_incoming_auth <bytes>\" line.\n",
323                                            fname, lineno, max );
324 #else
325                                 Debug( LDAP_DEBUG_ANY,
326                                         "%s: line %d: invalid max value (%ld) in "
327                                         "\"sockbuf_max_incoming_auth <bytes>\" line.\n",
328                                     fname, lineno, max );
329 #endif
330
331                                 return( 1 );
332                         }
333
334                         sockbuf_max_incoming_auth = max;
335
336                 /* default search base */
337                 } else if ( strcasecmp( cargv[0], "defaultSearchBase" ) == 0 ) {
338                         if ( cargc < 2 ) {
339 #ifdef NEW_LOGGING
340                                 LDAP_LOG( CONFIG, CRIT, 
341                                         "%s: line %d: missing dn in \"defaultSearchBase <dn\" "
342                                         "line\n", fname, lineno, 0 );
343 #else
344                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
345                                         "missing dn in \"defaultSearchBase <dn>\" line\n",
346                                         fname, lineno, 0 );
347 #endif
348
349                                 return 1;
350
351                         } else if ( cargc > 2 ) {
352 #ifdef NEW_LOGGING
353                                 LDAP_LOG( CONFIG, INFO, 
354                                         "%s: line %d: extra cruft after <dn> in "
355                                         "\"defaultSearchBase %s\" line (ignored)\n",
356                                         fname, lineno, cargv[1] );
357 #else
358                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
359                                         "extra cruft after <dn> in \"defaultSearchBase %s\", "
360                                         "line (ignored)\n",
361                                         fname, lineno, cargv[1] );
362 #endif
363                         }
364
365                         if ( bi != NULL || be != NULL ) {
366 #ifdef NEW_LOGGING
367                                 LDAP_LOG( CONFIG, CRIT, 
368                                         "%s: line %d: defaultSearchBase line must appear "
369                                         "prior to any backend or database definitions\n",
370                                         fname, lineno, 0 );
371 #else
372                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
373                                         "defaultSearchBaase line must appear prior to "
374                                         "any backend or database definition\n",
375                                     fname, lineno, 0 );
376 #endif
377
378                                 return 1;
379                         }
380
381                         if ( default_search_nbase.bv_len ) {
382 #ifdef NEW_LOGGING
383                                 LDAP_LOG( CONFIG, INFO, "%s: line %d: "
384                                         "default search base \"%s\" already defined "
385                                         "(discarding old)\n", fname, lineno,
386                                         default_search_base.bv_val );
387 #else
388                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
389                                         "default search base \"%s\" already defined "
390                                         "(discarding old)\n",
391                                         fname, lineno, default_search_base.bv_val );
392 #endif
393
394                                 free( default_search_base.bv_val );
395                                 free( default_search_nbase.bv_val );
396                         }
397
398                         if ( load_ucdata( NULL ) < 0 ) return 1;
399
400                         {
401                                 struct berval dn;
402
403                                 dn.bv_val = cargv[1];
404                                 dn.bv_len = strlen( dn.bv_val );
405
406                                 rc = dnPrettyNormal( NULL, &dn,
407                                         &default_search_base,
408                                         &default_search_nbase );
409
410                                 if( rc != LDAP_SUCCESS ) {
411 #ifdef NEW_LOGGING
412                                         LDAP_LOG( CONFIG, CRIT, 
413                                                 "%s: line %d: defaultSearchBase DN is invalid.\n",
414                                                 fname, lineno, 0 );
415 #else
416                                         Debug( LDAP_DEBUG_ANY,
417                                                 "%s: line %d: defaultSearchBase DN is invalid\n",
418                                            fname, lineno, 0 );
419 #endif
420                                         return( 1 );
421                                 }
422                         }
423
424                 /* set maximum threads in thread pool */
425                 } else if ( strcasecmp( cargv[0], "threads" ) == 0 ) {
426                         int c;
427                         if ( cargc < 2 ) {
428 #ifdef NEW_LOGGING
429                                 LDAP_LOG( CONFIG, CRIT, 
430                                         "%s: line %d: missing count in \"threads <count>\" line\n",
431                                         fname, lineno, 0 );
432 #else
433                                 Debug( LDAP_DEBUG_ANY,
434             "%s: line %d: missing count in \"threads <count>\" line\n",
435                                     fname, lineno, 0 );
436 #endif
437
438                                 return( 1 );
439                         }
440
441                         c = atoi( cargv[1] );
442
443                         if( c < 0 ) {
444 #ifdef NEW_LOGGING
445                                 LDAP_LOG( CONFIG, CRIT, 
446                                            "%s: line %d: invalid level (%d) in \"threads <count>\""
447                                            "line\n", fname, lineno, c );
448 #else
449                                 Debug( LDAP_DEBUG_ANY,
450             "%s: line %d: invalid level (%d) in \"threads <count>\" line\n",
451                                     fname, lineno, c );
452 #endif
453
454                                 return( 1 );
455                         }
456
457                         ldap_pvt_thread_pool_maxthreads( &connection_pool, c );
458
459                         /* save for later use */
460                         connection_pool_max = c;
461
462                 /* get pid file name */
463                 } else if ( strcasecmp( cargv[0], "pidfile" ) == 0 ) {
464                         if ( cargc < 2 ) {
465 #ifdef NEW_LOGGING
466                                 LDAP_LOG( CONFIG, CRIT, 
467                                         "%s: line %d missing file name in \"pidfile <file>\" "
468                                         "line.\n", fname, lineno, 0 );
469 #else
470                                 Debug( LDAP_DEBUG_ANY,
471             "%s: line %d: missing file name in \"pidfile <file>\" line\n",
472                                     fname, lineno, 0 );
473 #endif
474
475                                 return( 1 );
476                         }
477
478                         slapd_pid_file = ch_strdup( cargv[1] );
479
480                 /* get args file name */
481                 } else if ( strcasecmp( cargv[0], "argsfile" ) == 0 ) {
482                         if ( cargc < 2 ) {
483 #ifdef NEW_LOGGING
484                                 LDAP_LOG( CONFIG, CRIT, 
485                                            "%s: %d: missing file name in "
486                                            "\"argsfile <file>\" line.\n",
487                                            fname, lineno, 0 );
488 #else
489                                 Debug( LDAP_DEBUG_ANY,
490             "%s: line %d: missing file name in \"argsfile <file>\" line\n",
491                                     fname, lineno, 0 );
492 #endif
493
494                                 return( 1 );
495                         }
496
497                         slapd_args_file = ch_strdup( cargv[1] );
498
499                 /* default password hash */
500                 } else if ( strcasecmp( cargv[0], "password-hash" ) == 0 ) {
501                         if ( cargc < 2 ) {
502 #ifdef NEW_LOGGING
503                                 LDAP_LOG( CONFIG, CRIT, 
504                                            "%s: line %d: missing hash in "
505                                            "\"password-hash <hash>\" line.\n",
506                                            fname, lineno, 0 );
507 #else
508                                 Debug( LDAP_DEBUG_ANY,
509             "%s: line %d: missing hash in \"password-hash <hash>\" line\n",
510                                     fname, lineno, 0 );
511 #endif
512
513                                 return( 1 );
514                         }
515                         if ( default_passwd_hash != NULL ) {
516 #ifdef NEW_LOGGING
517                                 LDAP_LOG( CONFIG, CRIT, 
518                                            "%s: line %d: already set default password_hash!\n",
519                                            fname, lineno, 0 );
520 #else
521                                 Debug( LDAP_DEBUG_ANY,
522                                         "%s: line %d: already set default password_hash!\n",
523                                         fname, lineno, 0 );
524 #endif
525
526                                 return 1;
527
528                         }
529
530                         if ( lutil_passwd_scheme( cargv[1] ) == 0 ) {
531 #ifdef NEW_LOGGING
532                                 LDAP_LOG( CONFIG, CRIT, 
533                                            "%s: line %d: password scheme \"%s\" not available\n",
534                                            fname, lineno, cargv[1] );
535 #else
536                                 Debug( LDAP_DEBUG_ANY,
537                                         "%s: line %d: password scheme \"%s\" not available\n",
538                                         fname, lineno, cargv[1] );
539 #endif
540                                 return 1;
541                         }
542
543                         default_passwd_hash = ch_strdup( cargv[1] );
544
545                 } else if ( strcasecmp( cargv[0], "password-crypt-salt-format" ) == 0 ) 
546                 {
547                         if ( cargc < 2 ) {
548 #ifdef NEW_LOGGING
549                                 LDAP_LOG( CONFIG, CRIT, 
550                                         "%s: line %d: missing format in "
551                                         "\"password-crypt-salt-format <format>\" line\n",
552                                         fname, lineno, 0 );
553 #else
554                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: missing format in "
555                                         "\"password-crypt-salt-format <format>\" line\n",
556                                     fname, lineno, 0 );
557 #endif
558
559                                 return 1;
560                         }
561
562                         lutil_salt_format( cargv[1] );
563
564 #ifdef HAVE_CYRUS_SASL
565                 /* SASL config options */
566                 } else if ( strncasecmp( cargv[0], "sasl", 4 ) == 0 ) {
567                         if ( slap_sasl_config( cargc, cargv, line, fname, lineno ) )
568                                 return 1;
569 #endif /* HAVE_CYRUS_SASL */
570
571                 /* set UCDATA path */
572                 } else if ( strcasecmp( cargv[0], "ucdata-path" ) == 0 ) {
573                         int err;
574                         if ( cargc < 2 ) {
575 #ifdef NEW_LOGGING
576                                 LDAP_LOG( CONFIG, CRIT, 
577                                            "%s: line %d: missing path in "
578                                            "\"ucdata-path <path>\" line.\n", fname, lineno, 0  );
579 #else
580                                 Debug( LDAP_DEBUG_ANY,
581             "%s: line %d: missing path in \"ucdata-path <path>\" line\n",
582                                     fname, lineno, 0 );
583 #endif
584
585                                 return( 1 );
586                         }
587
588                         err = load_ucdata( cargv[1] );
589                         if ( err <= 0 ) {
590                                 if ( err == 0 ) {
591 #ifdef NEW_LOGGING
592                                         LDAP_LOG( CONFIG, CRIT, 
593                                                    "%s: line %d: ucdata already loaded, ucdata-path "
594                                                    "must be set earlier in the file and/or be "
595                                                    "specified only once!\n", fname, lineno, 0 );
596 #else
597                                         Debug( LDAP_DEBUG_ANY,
598                                                "%s: line %d: ucdata already loaded, ucdata-path must be set earlier in the file and/or be specified only once!\n",
599                                                fname, lineno, 0 );
600 #endif
601
602                                 }
603                                 return( 1 );
604                         }
605
606                 /* set size limit */
607                 } else if ( strcasecmp( cargv[0], "sizelimit" ) == 0 ) {
608                         int rc = 0, i;
609                         struct slap_limits_set *lim;
610                         
611                         if ( cargc < 2 ) {
612 #ifdef NEW_LOGGING
613                                 LDAP_LOG( CONFIG, CRIT, 
614                                    "%s: line %d: missing limit in \"sizelimit <limit>\" "
615                                    "line.\n", fname, lineno, 0 );
616 #else
617                                 Debug( LDAP_DEBUG_ANY,
618             "%s: line %d: missing limit in \"sizelimit <limit>\" line\n",
619                                     fname, lineno, 0 );
620 #endif
621
622                                 return( 1 );
623                         }
624
625                         if ( be == NULL ) {
626                                 lim = &deflimit;
627                         } else {
628                                 lim = &be->be_def_limit;
629                         }
630
631                         for ( i = 1; i < cargc; i++ ) {
632                                 if ( strncasecmp( cargv[i], "size", 4 ) == 0 ) {
633                                         rc = parse_limit( cargv[i], lim );
634                                 } else {
635                                         lim->lms_s_soft = atoi( cargv[i] );
636                                         lim->lms_s_hard = 0;
637                                 }
638
639                                 if ( rc ) {
640 #ifdef NEW_LOGGING
641                                         LDAP_LOG( CONFIG, CRIT, 
642                                                 "%s: line %d: unable "
643                                                    "to parse value \"%s\" in \"sizelimit "
644                                                    "<limit>\" line.\n", fname, lineno, cargv[i] );
645 #else
646                                         Debug( LDAP_DEBUG_ANY,
647                                                 "%s: line %d: unable "
648                                                 "to parse value \"%s\" "
649                                                 "in \"sizelimit "
650                                                 "<limit>\" line\n",
651                                                 fname, lineno, cargv[i] );
652 #endif
653                                 }
654                         }
655
656                 /* set time limit */
657                 } else if ( strcasecmp( cargv[0], "timelimit" ) == 0 ) {
658                         int rc = 0, i;
659                         struct slap_limits_set *lim;
660                         
661                         if ( cargc < 2 ) {
662 #ifdef NEW_LOGGING
663                                 LDAP_LOG( CONFIG, CRIT, 
664                                         "%s: line %d missing limit in \"timelimit <limit>\" "
665                                         "line.\n", fname, lineno, 0 );
666 #else
667                                 Debug( LDAP_DEBUG_ANY,
668             "%s: line %d: missing limit in \"timelimit <limit>\" line\n",
669                                     fname, lineno, 0 );
670 #endif
671
672                                 return( 1 );
673                         }
674                         
675                         if ( be == NULL ) {
676                                 lim = &deflimit;
677                         } else {
678                                 lim = &be->be_def_limit;
679                         }
680
681                         for ( i = 1; i < cargc; i++ ) {
682                                 if ( strncasecmp( cargv[i], "time", 4 ) == 0 ) {
683                                         rc = parse_limit( cargv[i], lim );
684                                 } else {
685                                         lim->lms_t_soft = atoi( cargv[i] );
686                                         lim->lms_t_hard = 0;
687                                 }
688
689                                 if ( rc ) {
690 #ifdef NEW_LOGGING
691                                         LDAP_LOG( CONFIG, CRIT, 
692                                                     "%s: line %d: unable to parse value \"%s\" "
693                                                    "in \"timelimit <limit>\" line.\n",
694                                                    fname, lineno, cargv[i] );
695 #else
696                                         Debug( LDAP_DEBUG_ANY,
697                                                 "%s: line %d: unable "
698                                                 "to parse value \"%s\" "
699                                                 "in \"timelimit "
700                                                 "<limit>\" line\n",
701                                                 fname, lineno, cargv[i] );
702 #endif
703                                 }
704                         }
705
706                 /* set regex-based limits */
707                 } else if ( strcasecmp( cargv[0], "limits" ) == 0 ) {
708                         if ( be == NULL ) {
709 #ifdef NEW_LOGGING
710                                 LDAP_LOG( CONFIG, WARNING, 
711                                            "%s: line %d \"limits\" allowed only in database "
712                                            "environment.\n", fname, lineno, 0 );
713 #else
714                                 Debug( LDAP_DEBUG_ANY,
715         "%s: line %d \"limits\" allowed only in database environment.\n%s",
716                                         fname, lineno, "" );
717 #endif
718                                 return( 1 );
719                         }
720
721                         if ( parse_limits( be, fname, lineno, cargc, cargv ) ) {
722                                 return( 1 );
723                         }
724
725                 /* mark this as a subordinate database */
726                 } else if ( strcasecmp( cargv[0], "subordinate" ) == 0 ) {
727                         if ( be == NULL ) {
728 #ifdef NEW_LOGGING
729                                 LDAP_LOG( CONFIG, INFO, "%s: line %d: "
730                                         "subordinate keyword must appear inside a database "
731                                         "definition.\n", fname, lineno, 0 );
732 #else
733                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: suffix line "
734                                         "must appear inside a database definition.\n",
735                                     fname, lineno, 0 );
736 #endif
737                                 return 1;
738
739                         } else {
740                                 be->be_flags |= SLAP_BFLAG_GLUE_SUBORDINATE;
741                                 num_subordinates++;
742                         }
743
744                 /* set database suffix */
745                 } else if ( strcasecmp( cargv[0], "suffix" ) == 0 ) {
746                         Backend *tmp_be;
747                         struct berval dn, pdn, ndn;
748
749                         if ( cargc < 2 ) {
750 #ifdef NEW_LOGGING
751                                 LDAP_LOG( CONFIG, CRIT, 
752                                         "%s: line %d: missing dn in \"suffix <dn>\" line.\n",
753                                         fname, lineno, 0 );
754 #else
755                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
756                                         "missing dn in \"suffix <dn>\" line\n",
757                                     fname, lineno, 0 );
758 #endif
759
760                                 return( 1 );
761
762                         } else if ( cargc > 2 ) {
763 #ifdef NEW_LOGGING
764                                 LDAP_LOG( CONFIG, INFO, 
765                                         "%s: line %d: extra cruft after <dn> in \"suffix %s\""
766                                         " line (ignored).\n", fname, lineno, cargv[1] );
767 #else
768                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: extra cruft "
769                                         "after <dn> in \"suffix %s\" line (ignored)\n",
770                                     fname, lineno, cargv[1] );
771 #endif
772                         }
773
774                         if ( be == NULL ) {
775 #ifdef NEW_LOGGING
776                                 LDAP_LOG( CONFIG, INFO, 
777                                         "%s: line %d: suffix line must appear inside a database "
778                                         "definition.\n", fname, lineno, 0 );
779 #else
780                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: suffix line "
781                                         "must appear inside a database definition\n",
782                                     fname, lineno, 0 );
783 #endif
784                                 return( 1 );
785
786 #if defined(SLAPD_MONITOR_DN)
787                         /* "cn=Monitor" is reserved for monitoring slap */
788                         } else if ( strcasecmp( cargv[1], SLAPD_MONITOR_DN ) == 0 ) {
789 #ifdef NEW_LOGGING
790                                 LDAP_LOG( CONFIG, CRIT, "%s: line %d: \""
791                                         SLAPD_MONITOR_DN "\" is reserved for monitoring slapd\n", 
792                                         fname, lineno, 0 );
793 #else
794                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: \""
795                                         SLAPD_MONITOR_DN "\" is reserved for monitoring slapd\n", 
796                                         fname, lineno, 0 );
797 #endif
798                                 return( 1 );
799 #endif /* SLAPD_MONITOR_DN */
800                         }
801
802                         if ( load_ucdata( NULL ) < 0 ) return 1;
803
804                         dn.bv_val = cargv[1];
805                         dn.bv_len = strlen( cargv[1] );
806
807                         rc = dnPrettyNormal( NULL, &dn, &pdn, &ndn );
808                         if( rc != LDAP_SUCCESS ) {
809 #ifdef NEW_LOGGING
810                                 LDAP_LOG( CONFIG, CRIT, 
811                                         "%s: line %d: suffix DN is invalid.\n",
812                                         fname, lineno, 0 );
813 #else
814                                 Debug( LDAP_DEBUG_ANY,
815                                         "%s: line %d: suffix DN is invalid\n",
816                                    fname, lineno, 0 );
817 #endif
818                                 return( 1 );
819                         }
820
821                         tmp_be = select_backend( &ndn, 0, 0 );
822                         if ( tmp_be == be ) {
823 #ifdef NEW_LOGGING
824                                 LDAP_LOG( CONFIG, INFO, 
825                                         "%s: line %d: suffix already served by this backend "
826                                         "(ignored)\n", fname, lineno, 0 );
827 #else
828                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: suffix "
829                                         "already served by this backend (ignored)\n",
830                                     fname, lineno, 0 );
831 #endif
832                                 free( pdn.bv_val );
833                                 free( ndn.bv_val );
834
835                         } else if ( tmp_be  != NULL ) {
836 #ifdef NEW_LOGGING
837                                 LDAP_LOG( CONFIG, INFO, 
838                                         "%s: line %d: suffix already served by a preceding "
839                                         "backend \"%s\"\n", fname, lineno,
840                                         tmp_be->be_suffix[0].bv_val );
841 #else
842                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: suffix "
843                                         "already served by a preceeding backend \"%s\"\n",
844                                     fname, lineno, tmp_be->be_suffix[0].bv_val );
845 #endif
846                                 free( pdn.bv_val );
847                                 free( ndn.bv_val );
848                                 return( 1 );
849
850                         } else if( pdn.bv_len == 0 && default_search_nbase.bv_len ) {
851 #ifdef NEW_LOGGING
852                                         LDAP_LOG( CONFIG, INFO, 
853                                                 "%s: line %d: suffix DN empty and default search "
854                                                 "base provided \"%s\" (assuming okay).\n",
855                                                 fname, lineno, default_search_base.bv_val );
856 #else
857                                         Debug( LDAP_DEBUG_ANY, "%s: line %d: "
858                                                 "suffix DN empty and default "
859                                                 "search base provided \"%s\" (assuming okay)\n",
860                                         fname, lineno, default_search_base.bv_val );
861 #endif
862                         }
863
864                         ber_bvarray_add( &be->be_suffix, &pdn );
865                         ber_bvarray_add( &be->be_nsuffix, &ndn );
866
867                 /* set database suffixAlias */
868                 } else if ( strcasecmp( cargv[0], "suffixAlias" ) == 0 ) {
869                         Backend *tmp_be;
870                         struct berval alias, palias, nalias;
871                         struct berval aliased, paliased, naliased;
872
873                         if ( cargc < 2 ) {
874 #ifdef NEW_LOGGING
875                                 LDAP_LOG( CONFIG, CRIT, 
876                                         "%s: line %d: missing alias and aliased_dn in "
877                                         "\"suffixAlias <alias> <aliased_dn>\" line.\n",
878                                         fname, lineno, 0 );
879 #else
880                                 Debug( LDAP_DEBUG_ANY,
881                                         "%s: line %d: missing alias and aliased_dn in "
882                                         "\"suffixAlias <alias> <aliased_dn>\" line.\n",
883                                         fname, lineno, 0 );
884 #endif
885
886                                 return( 1 );
887                         } else if ( cargc < 3 ) {
888 #ifdef NEW_LOGGING
889                                 LDAP_LOG( CONFIG, CRIT, 
890                                         "%s: line %d: missing aliased_dn in "
891                                         "\"suffixAlias <alias> <aliased_dn>\" line\n",
892                                         fname, lineno, 0 );
893 #else
894                                 Debug( LDAP_DEBUG_ANY,
895                                         "%s: line %d: missing aliased_dn in "
896                                         "\"suffixAlias <alias> <aliased_dn>\" line\n",
897                                         fname, lineno, 0 );
898 #endif
899                                 return( 1 );
900
901                         } else if ( cargc > 3 ) {
902 #ifdef NEW_LOGGING
903                                 LDAP_LOG( CONFIG, CRIT, 
904                                         "%s: line %d: extra cruft in suffixAlias line (ignored)\n",
905                                         fname, lineno, 0 );
906 #else
907                                 Debug( LDAP_DEBUG_ANY,
908                                         "%s: line %d: extra cruft in suffixAlias line (ignored)\n",
909                                         fname, lineno, 0 );
910 #endif
911                         }
912
913                         if ( be == NULL ) {
914 #ifdef NEW_LOGGING
915                                 LDAP_LOG( CONFIG, INFO, 
916                                         "%s: line %d: suffix line must appear inside a database "
917                                         "definition.\n", fname, lineno, 0 );
918 #else
919                                 Debug( LDAP_DEBUG_ANY,
920                                         "%s: line %d: suffixAlias line"
921                                         " must appear inside a database definition.\n",
922                                         fname, lineno, 0 );
923 #endif
924                                 return 1;
925                         }
926
927                         if ( load_ucdata( NULL ) < 0 ) return 1;
928                         
929                         alias.bv_val = cargv[1];
930                         alias.bv_len = strlen( cargv[1] );
931
932                         rc = dnPrettyNormal( NULL, &alias, &palias, &nalias );
933                         if( rc != LDAP_SUCCESS ) {
934 #ifdef NEW_LOGGING
935                                 LDAP_LOG( CONFIG, CRIT, 
936                                         "%s: line %d: alias DN is invalid.\n", fname, lineno, 0 );
937 #else
938                                 Debug( LDAP_DEBUG_ANY,
939                                         "%s: line %d: alias DN is invalid\n",
940                                    fname, lineno, 0 );
941 #endif
942                                 return( 1 );
943                         }
944
945                         tmp_be = select_backend( &nalias, 0, 0 );
946                         free( nalias.bv_val );
947                         if ( tmp_be && tmp_be != be ) {
948 #ifdef NEW_LOGGING
949                                 LDAP_LOG( CONFIG, INFO, 
950                                         "%s: line %d: suffixAlias served by a preceeding "
951                                         "backend \"%s\"\n", fname, lineno, 
952                                         tmp_be->be_suffix[0].bv_val );
953 #else
954                                 Debug( LDAP_DEBUG_ANY,
955                                         "%s: line %d: suffixAlias served by"
956                                         "  a preceeding backend \"%s\"\n",
957                                         fname, lineno, tmp_be->be_suffix[0].bv_val );
958 #endif
959                                 free( palias.bv_val );
960                                 return -1;
961                         }
962
963                         aliased.bv_val = cargv[2];
964                         aliased.bv_len = strlen( cargv[2] );
965
966                         rc = dnPrettyNormal( NULL, &aliased, &paliased, &naliased );
967                         if( rc != LDAP_SUCCESS ) {
968 #ifdef NEW_LOGGING
969                                 LDAP_LOG( CONFIG, CRIT, 
970                                         "%s: line %d: aliased DN is invalid.\n", fname, lineno,0 );
971 #else
972                                 Debug( LDAP_DEBUG_ANY,
973                                         "%s: line %d: aliased DN is invalid\n",
974                                    fname, lineno, 0 );
975 #endif
976                                 free( palias.bv_val );
977                                 return( 1 );
978                         }
979
980                         tmp_be = select_backend( &naliased, 0, 0 );
981                         free( naliased.bv_val );
982                         if ( tmp_be && tmp_be != be ) {
983 #ifdef NEW_LOGGING
984                                 LDAP_LOG( CONFIG, INFO, 
985                                         "%s: line %d: suffixAlias derefs to a different backend "
986                                         "a preceeding backend \"%s\"\n",
987                                         fname, lineno, tmp_be->be_suffix[0].bv_val );
988 #else
989                                 Debug( LDAP_DEBUG_ANY,
990                                         "%s: line %d: suffixAlias derefs to differnet backend"
991                                         "  a preceeding backend \"%s\"\n",
992                                         fname, lineno, tmp_be->be_suffix[0].bv_val );
993 #endif
994                                 free( palias.bv_val );
995                                 free( paliased.bv_val );
996                                 return -1;
997                         }
998
999                         ber_bvarray_add( &be->be_suffixAlias, &palias ); 
1000                         ber_bvarray_add( &be->be_suffixAlias, &paliased );
1001
1002                /* set max deref depth */
1003                } else if ( strcasecmp( cargv[0], "maxDerefDepth" ) == 0 ) {
1004                                         int i;
1005                        if ( cargc < 2 ) {
1006 #ifdef NEW_LOGGING
1007                                LDAP_LOG( CONFIG, CRIT, 
1008                                           "%s: line %d: missing depth in \"maxDerefDepth <depth>\""
1009                                           " line\n", fname, lineno, 0 );
1010 #else
1011                                Debug( LDAP_DEBUG_ANY,
1012                    "%s: line %d: missing depth in \"maxDerefDepth <depth>\" line\n",
1013                                    fname, lineno, 0 );
1014 #endif
1015
1016                                return( 1 );
1017                        }
1018                        if ( be == NULL ) {
1019 #ifdef NEW_LOGGING
1020                                LDAP_LOG( CONFIG, INFO, 
1021                                           "%s: line %d: depth line must appear inside a database "
1022                                           "definition.\n", fname, lineno ,0 );
1023 #else
1024                                Debug( LDAP_DEBUG_ANY,
1025 "%s: line %d: depth line must appear inside a database definition.\n",
1026                                    fname, lineno, 0 );
1027 #endif
1028                                                         return 1;
1029
1030                        } else if ((i = atoi(cargv[1])) < 0) {
1031 #ifdef NEW_LOGGING
1032                                LDAP_LOG( CONFIG, INFO, 
1033                                           "%s: line %d: depth must be positive.\n",
1034                                           fname, lineno ,0 );
1035 #else
1036                                Debug( LDAP_DEBUG_ANY,
1037 "%s: line %d: depth must be positive.\n",
1038                                    fname, lineno, 0 );
1039 #endif
1040                                                         return 1;
1041
1042
1043                        } else {
1044                            be->be_max_deref_depth = i;
1045                                            }
1046
1047
1048                 /* set magic "root" dn for this database */
1049                 } else if ( strcasecmp( cargv[0], "rootdn" ) == 0 ) {
1050                         if ( cargc < 2 ) {
1051 #ifdef NEW_LOGGING
1052                                 LDAP_LOG( CONFIG, INFO, 
1053                                            "%s: line %d: missing dn in \"rootdn <dn>\" line.\n",
1054                                            fname, lineno ,0 );
1055 #else
1056                                 Debug( LDAP_DEBUG_ANY,
1057                     "%s: line %d: missing dn in \"rootdn <dn>\" line\n",
1058                                     fname, lineno, 0 );
1059 #endif
1060
1061                                 return( 1 );
1062                         }
1063
1064                         if ( be == NULL ) {
1065 #ifdef NEW_LOGGING
1066                                 LDAP_LOG( CONFIG, INFO, 
1067                                            "%s: line %d: rootdn line must appear inside a database "
1068                                            "definition.\n", fname, lineno ,0 );
1069 #else
1070                                 Debug( LDAP_DEBUG_ANY,
1071 "%s: line %d: rootdn line must appear inside a database definition.\n",
1072                                     fname, lineno, 0 );
1073 #endif
1074                                 return 1;
1075
1076                         } else {
1077                                 struct berval dn;
1078                                 
1079                                 if ( load_ucdata( NULL ) < 0 ) return 1;
1080
1081                                 dn.bv_val = cargv[1];
1082                                 dn.bv_len = strlen( cargv[1] );
1083
1084                                 rc = dnPrettyNormal( NULL, &dn,
1085                                         &be->be_rootdn,
1086                                         &be->be_rootndn );
1087
1088                                 if( rc != LDAP_SUCCESS ) {
1089 #ifdef NEW_LOGGING
1090                                         LDAP_LOG( CONFIG, CRIT, 
1091                                                 "%s: line %d: rootdn DN is invalid.\n", 
1092                                                 fname, lineno ,0 );
1093 #else
1094                                         Debug( LDAP_DEBUG_ANY,
1095                                                 "%s: line %d: rootdn DN is invalid\n",
1096                                            fname, lineno, 0 );
1097 #endif
1098                                         return( 1 );
1099                                 }
1100                         }
1101
1102                 /* set super-secret magic database password */
1103                 } else if ( strcasecmp( cargv[0], "rootpw" ) == 0 ) {
1104                         if ( cargc < 2 ) {
1105 #ifdef NEW_LOGGING
1106                                 LDAP_LOG( CONFIG, CRIT, 
1107                                         "%s: line %d: missing passwd in \"rootpw <passwd>\""
1108                                         " line\n", fname, lineno ,0 );
1109 #else
1110                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1111                                         "missing passwd in \"rootpw <passwd>\" line\n",
1112                                     fname, lineno, 0 );
1113 #endif
1114
1115                                 return( 1 );
1116                         }
1117
1118                         if ( be == NULL ) {
1119 #ifdef NEW_LOGGING
1120                                 LDAP_LOG( CONFIG, INFO, "%s: line %d: "
1121                                         "rootpw line must appear inside a database "
1122                                         "definition.\n", fname, lineno ,0 );
1123 #else
1124                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1125                                         "rootpw line must appear inside a database "
1126                                         "definition.\n",
1127                                     fname, lineno, 0 );
1128 #endif
1129                                 return 1;
1130
1131                         } else {
1132                                 Backend *tmp_be = select_backend( &be->be_rootndn, 0, 0 );
1133
1134                                 if( tmp_be != be ) {
1135 #ifdef NEW_LOGGING
1136                                         LDAP_LOG( CONFIG, INFO,
1137                                                 "%s: line %d: "
1138                                                 "rootpw can only be set when rootdn is under suffix\n",
1139                                                 fname, lineno, "" );
1140 #else
1141                                         Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1142                                                 "rootpw can only be set when rootdn is under suffix\n",
1143                                         fname, lineno, 0 );
1144 #endif
1145                                         return 1;
1146                                 }
1147
1148                                 be->be_rootpw.bv_val = ch_strdup( cargv[1] );
1149                                 be->be_rootpw.bv_len = strlen( be->be_rootpw.bv_val );
1150                         }
1151
1152                 /* make this database read-only */
1153                 } else if ( strcasecmp( cargv[0], "readonly" ) == 0 ) {
1154                         if ( cargc < 2 ) {
1155 #ifdef NEW_LOGGING
1156                                 LDAP_LOG( CONFIG, CRIT, 
1157                                         "%s: line %d: missing on|off in \"readonly <on|off>\" "
1158                                         "line.\n", fname, lineno ,0 );
1159 #else
1160                                 Debug( LDAP_DEBUG_ANY,
1161             "%s: line %d: missing on|off in \"readonly <on|off>\" line\n",
1162                                     fname, lineno, 0 );
1163 #endif
1164
1165                                 return( 1 );
1166                         }
1167                         if ( be == NULL ) {
1168                                 if ( strcasecmp( cargv[1], "on" ) == 0 ) {
1169                                         global_restrictops |= SLAP_RESTRICT_OP_WRITES;
1170                                 } else {
1171                                         global_restrictops &= ~SLAP_RESTRICT_OP_WRITES;
1172                                 }
1173                         } else {
1174                                 if ( strcasecmp( cargv[1], "on" ) == 0 ) {
1175                                         be->be_restrictops |= SLAP_RESTRICT_OP_WRITES;
1176                                 } else {
1177                                         be->be_restrictops &= ~SLAP_RESTRICT_OP_WRITES;
1178                                 }
1179                         }
1180
1181
1182                 /* allow these features */
1183                 } else if ( strcasecmp( cargv[0], "allows" ) == 0 ||
1184                         strcasecmp( cargv[0], "allow" ) == 0 )
1185                 {
1186                         slap_mask_t     allows;
1187
1188                         if ( be != NULL ) {
1189 #ifdef NEW_LOGGING
1190                                 LDAP_LOG( CONFIG, INFO, 
1191                                            "%s: line %d: allow line must appear prior to "
1192                                            "database definitions.\n", fname, lineno ,0 );
1193 #else
1194                                 Debug( LDAP_DEBUG_ANY,
1195 "%s: line %d: allow line must appear prior to database definitions\n",
1196                                     fname, lineno, 0 );
1197 #endif
1198
1199                         }
1200
1201                         if ( cargc < 2 ) {
1202 #ifdef NEW_LOGGING
1203                                 LDAP_LOG( CONFIG, CRIT, 
1204                                            "%s: line %d: missing feature(s) in \"allow <features>\""
1205                                            " line\n", fname, lineno ,0 );
1206 #else
1207                                 Debug( LDAP_DEBUG_ANY,
1208             "%s: line %d: missing feature(s) in \"allow <features>\" line\n",
1209                                     fname, lineno, 0 );
1210 #endif
1211
1212                                 return( 1 );
1213                         }
1214
1215                         allows = 0;
1216
1217                         for( i=1; i < cargc; i++ ) {
1218                                 if( strcasecmp( cargv[i], "bind_v2" ) == 0 ) {
1219                                         allows |= SLAP_ALLOW_BIND_V2;
1220
1221                                 } else if( strcasecmp( cargv[i], "bind_anon_cred" ) == 0 ) {
1222                                         allows |= SLAP_ALLOW_BIND_ANON_CRED;
1223
1224                                 } else if( strcasecmp( cargv[i], "bind_anon_dn" ) == 0 ) {
1225                                         allows |= SLAP_ALLOW_BIND_ANON_DN;
1226
1227                                 } else if( strcasecmp( cargv[i], "none" ) != 0 ) {
1228 #ifdef NEW_LOGGING
1229                                         LDAP_LOG( CONFIG, CRIT, 
1230                                                    "%s: line %d: unknown feature %s in "
1231                                                    "\"allow <features>\" line.\n",
1232                                                    fname, lineno, cargv[1] );
1233 #else
1234                                         Debug( LDAP_DEBUG_ANY,
1235                     "%s: line %d: unknown feature %s in \"allow <features>\" line\n",
1236                                             fname, lineno, cargv[i] );
1237 #endif
1238
1239                                         return( 1 );
1240                                 }
1241                         }
1242
1243                         global_allows = allows;
1244
1245                 /* disallow these features */
1246                 } else if ( strcasecmp( cargv[0], "disallows" ) == 0 ||
1247                         strcasecmp( cargv[0], "disallow" ) == 0 )
1248                 {
1249                         slap_mask_t     disallows;
1250
1251                         if ( be != NULL ) {
1252 #ifdef NEW_LOGGING
1253                                 LDAP_LOG( CONFIG, INFO, 
1254                                            "%s: line %d: disallow line must appear prior to "
1255                                            "database definitions.\n", fname, lineno ,0 );
1256 #else
1257                                 Debug( LDAP_DEBUG_ANY,
1258 "%s: line %d: disallow line must appear prior to database definitions\n",
1259                                     fname, lineno, 0 );
1260 #endif
1261
1262                         }
1263
1264                         if ( cargc < 2 ) {
1265 #ifdef NEW_LOGGING
1266                                 LDAP_LOG( CONFIG, CRIT, 
1267                                         "%s: line %d: missing feature(s) in \"disallow <features>\""
1268                                         " line.\n", fname, lineno ,0 );
1269 #else
1270                                 Debug( LDAP_DEBUG_ANY,
1271             "%s: line %d: missing feature(s) in \"disallow <features>\" line\n",
1272                                     fname, lineno, 0 );
1273 #endif
1274
1275                                 return( 1 );
1276                         }
1277
1278                         disallows = 0;
1279
1280                         for( i=1; i < cargc; i++ ) {
1281                                 if( strcasecmp( cargv[i], "bind_anon" ) == 0 ) {
1282                                         disallows |= SLAP_DISALLOW_BIND_ANON;
1283
1284                                 } else if( strcasecmp( cargv[i], "bind_simple" ) == 0 ) {
1285                                         disallows |= SLAP_DISALLOW_BIND_SIMPLE;
1286
1287                                 } else if( strcasecmp( cargv[i], "bind_simple_unprotected" ) == 0 ) {
1288                                         disallows |= SLAP_DISALLOW_BIND_SIMPLE_UNPROTECTED;
1289
1290                                 } else if( strcasecmp( cargv[i], "bind_krbv4" ) == 0 ) {
1291                                         disallows |= SLAP_DISALLOW_BIND_KRBV4;
1292
1293                                 } else if( strcasecmp( cargv[i], "tls_2_anon" ) == 0 ) {
1294                                         disallows |= SLAP_DISALLOW_TLS_2_ANON;
1295
1296                                 } else if( strcasecmp( cargv[i], "tls_authc" ) == 0 ) {
1297                                         disallows |= SLAP_DISALLOW_TLS_AUTHC;
1298
1299                                 } else if( strcasecmp( cargv[i], "none" ) != 0 ) {
1300 #ifdef NEW_LOGGING
1301                                         LDAP_LOG( CONFIG, CRIT, 
1302                                                 "%s: line %d: unknown feature %s in "
1303                                                 "\"disallow <features>\" line.\n",
1304                                                 fname, lineno, cargv[i] );
1305 #else
1306                                         Debug( LDAP_DEBUG_ANY,
1307                     "%s: line %d: unknown feature %s in \"disallow <features>\" line\n",
1308                                             fname, lineno, cargv[i] );
1309 #endif
1310
1311                                         return( 1 );
1312                                 }
1313                         }
1314
1315                         global_disallows = disallows;
1316
1317                 /* require these features */
1318                 } else if ( strcasecmp( cargv[0], "requires" ) == 0 ||
1319                         strcasecmp( cargv[0], "require" ) == 0 )
1320                 {
1321                         slap_mask_t     requires;
1322
1323                         if ( cargc < 2 ) {
1324 #ifdef NEW_LOGGING
1325                                 LDAP_LOG( CONFIG, CRIT, 
1326                                            "%s: line %d: missing feature(s) in "
1327                                            "\"require <features>\" line.\n", fname, lineno ,0 );
1328 #else
1329                                 Debug( LDAP_DEBUG_ANY,
1330             "%s: line %d: missing feature(s) in \"require <features>\" line\n",
1331                                     fname, lineno, 0 );
1332 #endif
1333
1334                                 return( 1 );
1335                         }
1336
1337                         requires = 0;
1338
1339                         for( i=1; i < cargc; i++ ) {
1340                                 if( strcasecmp( cargv[i], "bind" ) == 0 ) {
1341                                         requires |= SLAP_REQUIRE_BIND;
1342
1343                                 } else if( strcasecmp( cargv[i], "LDAPv3" ) == 0 ) {
1344                                         requires |= SLAP_REQUIRE_LDAP_V3;
1345
1346                                 } else if( strcasecmp( cargv[i], "authc" ) == 0 ) {
1347                                         requires |= SLAP_REQUIRE_AUTHC;
1348
1349                                 } else if( strcasecmp( cargv[i], "SASL" ) == 0 ) {
1350                                         requires |= SLAP_REQUIRE_SASL;
1351
1352                                 } else if( strcasecmp( cargv[i], "strong" ) == 0 ) {
1353                                         requires |= SLAP_REQUIRE_STRONG;
1354
1355                                 } else if( strcasecmp( cargv[i], "none" ) != 0 ) {
1356 #ifdef NEW_LOGGING
1357                                         LDAP_LOG( CONFIG, CRIT, 
1358                                                    "%s: line %d: unknown feature %s in "
1359                                                    "\"require <features>\" line.\n", 
1360                                                    fname, lineno , cargv[i] );
1361 #else
1362                                         Debug( LDAP_DEBUG_ANY,
1363                     "%s: line %d: unknown feature %s in \"require <features>\" line\n",
1364                                             fname, lineno, cargv[i] );
1365 #endif
1366
1367                                         return( 1 );
1368                                 }
1369                         }
1370
1371                         if ( be == NULL ) {
1372                                 global_requires = requires;
1373                         } else {
1374                                 be->be_requires = requires;
1375                         }
1376
1377                 /* required security factors */
1378                 } else if ( strcasecmp( cargv[0], "security" ) == 0 ) {
1379                         slap_ssf_set_t *set;
1380
1381                         if ( cargc < 2 ) {
1382 #ifdef NEW_LOGGING
1383                                 LDAP_LOG( CONFIG, CRIT, 
1384                                         "%s: line %d: missing factor(s) in \"security <factors>\""
1385                                         " line.\n", fname, lineno ,0 );
1386 #else
1387                                 Debug( LDAP_DEBUG_ANY,
1388             "%s: line %d: missing factor(s) in \"security <factors>\" line\n",
1389                                     fname, lineno, 0 );
1390 #endif
1391
1392                                 return( 1 );
1393                         }
1394
1395                         if ( be == NULL ) {
1396                                 set = &global_ssf_set;
1397                         } else {
1398                                 set = &be->be_ssf_set;
1399                         }
1400
1401                         for( i=1; i < cargc; i++ ) {
1402                                 if( strncasecmp( cargv[i], "ssf=",
1403                                         sizeof("ssf") ) == 0 )
1404                                 {
1405                                         set->sss_ssf =
1406                                                 atoi( &cargv[i][sizeof("ssf")] );
1407
1408                                 } else if( strncasecmp( cargv[i], "transport=",
1409                                         sizeof("transport") ) == 0 )
1410                                 {
1411                                         set->sss_transport =
1412                                                 atoi( &cargv[i][sizeof("transport")] );
1413
1414                                 } else if( strncasecmp( cargv[i], "tls=",
1415                                         sizeof("tls") ) == 0 )
1416                                 {
1417                                         set->sss_tls =
1418                                                 atoi( &cargv[i][sizeof("tls")] );
1419
1420                                 } else if( strncasecmp( cargv[i], "sasl=",
1421                                         sizeof("sasl") ) == 0 )
1422                                 {
1423                                         set->sss_sasl =
1424                                                 atoi( &cargv[i][sizeof("sasl")] );
1425
1426                                 } else if( strncasecmp( cargv[i], "update_ssf=",
1427                                         sizeof("update_ssf") ) == 0 )
1428                                 {
1429                                         set->sss_update_ssf =
1430                                                 atoi( &cargv[i][sizeof("update_ssf")] );
1431
1432                                 } else if( strncasecmp( cargv[i], "update_transport=",
1433                                         sizeof("update_transport") ) == 0 )
1434                                 {
1435                                         set->sss_update_transport =
1436                                                 atoi( &cargv[i][sizeof("update_transport")] );
1437
1438                                 } else if( strncasecmp( cargv[i], "update_tls=",
1439                                         sizeof("update_tls") ) == 0 )
1440                                 {
1441                                         set->sss_update_tls =
1442                                                 atoi( &cargv[i][sizeof("update_tls")] );
1443
1444                                 } else if( strncasecmp( cargv[i], "update_sasl=",
1445                                         sizeof("update_sasl") ) == 0 )
1446                                 {
1447                                         set->sss_update_sasl =
1448                                                 atoi( &cargv[i][sizeof("update_sasl")] );
1449
1450                                 } else {
1451 #ifdef NEW_LOGGING
1452                                         LDAP_LOG( CONFIG, CRIT, 
1453                                                    "%s: line %d: unknown factor %S in "
1454                                                    "\"security <factors>\" line.\n",
1455                                                    fname, lineno, cargv[1] );
1456 #else
1457                                         Debug( LDAP_DEBUG_ANY,
1458                     "%s: line %d: unknown factor %s in \"security <factors>\" line\n",
1459                                             fname, lineno, cargv[i] );
1460 #endif
1461
1462                                         return( 1 );
1463                                 }
1464                         }
1465                 /* where to send clients when we don't hold it */
1466                 } else if ( strcasecmp( cargv[0], "referral" ) == 0 ) {
1467                         if ( cargc < 2 ) {
1468 #ifdef NEW_LOGGING
1469                                 LDAP_LOG( CONFIG, CRIT, 
1470                                         "%s: line %d: missing URL in \"referral <URL>\""
1471                                         " line.\n", fname, lineno , 0 );
1472 #else
1473                                 Debug( LDAP_DEBUG_ANY,
1474                     "%s: line %d: missing URL in \"referral <URL>\" line\n",
1475                                     fname, lineno, 0 );
1476 #endif
1477
1478                                 return( 1 );
1479                         }
1480
1481                         if( validate_global_referral( cargv[1] ) ) {
1482 #ifdef NEW_LOGGING
1483                                 LDAP_LOG( CONFIG, CRIT, 
1484                                         "%s: line %d: invalid URL (%s) in \"referral\" line.\n",
1485                                         fname, lineno, cargv[1]  );
1486 #else
1487                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1488                                         "invalid URL (%s) in \"referral\" line.\n",
1489                                     fname, lineno, cargv[1] );
1490 #endif
1491                                 return 1;
1492                         }
1493
1494                         vals[0].bv_val = cargv[1];
1495                         vals[0].bv_len = strlen( vals[0].bv_val );
1496                         value_add( &default_referral, vals );
1497
1498 #ifdef NEW_LOGGING
1499                 } else if ( strcasecmp( cargv[0], "logfile" ) == 0 ) {
1500                         FILE *logfile;
1501                         if ( cargc < 2 ) {
1502 #ifdef NEW_LOGGING
1503                                 LDAP_LOG( CONFIG, CRIT, 
1504                                         "%s: line %d: Error in logfile directive, "
1505                                         "\"logfile <filename>\"\n", fname, lineno , 0 );
1506 #else
1507                                 Debug( LDAP_DEBUG_ANY,
1508                                        "%s: line %d: Error in logfile directive, \"logfile filename\"\n",
1509                                        fname, lineno, 0 );
1510 #endif
1511
1512                                 return( 1 );
1513                         }
1514                         logfile = fopen( cargv[1], "w" );
1515                         if ( logfile != NULL ) lutil_debug_file( logfile  );
1516
1517 #endif
1518                 /* start of a new database definition */
1519                 } else if ( strcasecmp( cargv[0], "debug" ) == 0 ) {
1520                         int level;
1521                         if ( cargc < 3 ) {
1522 #ifdef NEW_LOGGING
1523                                 LDAP_LOG( CONFIG, CRIT, 
1524                                            "%s: line %d: Error in debug directive, "
1525                                            "\"debug <subsys> <level>\"\n", fname, lineno , 0 );
1526 #else
1527                                 Debug( LDAP_DEBUG_ANY,
1528                                         "%s: line %d: Error in debug directive, \"debug subsys level\"\n",
1529                                         fname, lineno, 0 );
1530 #endif
1531
1532                                 return( 1 );
1533                         }
1534                         level = atoi( cargv[2] );
1535                         if ( level <= 0 ) level = lutil_mnem2level( cargv[2] );
1536                         lutil_set_debug_level( cargv[1], level );
1537                 /* specify an Object Identifier macro */
1538                 } else if ( strcasecmp( cargv[0], "objectidentifier" ) == 0 ) {
1539                         rc = parse_oidm( fname, lineno, cargc, cargv );
1540                         if( rc ) return rc;
1541
1542                 /* specify an objectclass */
1543                 } else if ( strcasecmp( cargv[0], "objectclass" ) == 0 ) {
1544                         if ( *cargv[1] == '(' ) {
1545                                 char * p;
1546                                 p = strchr(saveline,'(');
1547                                 rc = parse_oc( fname, lineno, p, cargv );
1548                                 if( rc ) return rc;
1549
1550                         } else {
1551 #ifdef NEW_LOGGING
1552                                 LDAP_LOG( CONFIG, INFO, 
1553                                         "%s: line %d: old objectclass format not supported\n",
1554                                         fname, lineno , 0 );
1555 #else
1556                                 Debug( LDAP_DEBUG_ANY,
1557                                        "%s: line %d: old objectclass format not supported.\n",
1558                                        fname, lineno, 0 );
1559 #endif
1560                         }
1561
1562                 /* specify an attribute type */
1563                 } else if (( strcasecmp( cargv[0], "attributetype" ) == 0 )
1564                         || ( strcasecmp( cargv[0], "attribute" ) == 0 ))
1565                 {
1566                         if ( *cargv[1] == '(' ) {
1567                                 char * p;
1568                                 p = strchr(saveline,'(');
1569                                 rc = parse_at( fname, lineno, p, cargv );
1570                                 if( rc ) return rc;
1571
1572                         } else {
1573 #ifdef NEW_LOGGING
1574                                 LDAP_LOG( CONFIG, INFO, 
1575                                         "%s: line %d: old attribute type format not supported.\n",
1576                                         fname, lineno , 0 );
1577 #else
1578                                 Debug( LDAP_DEBUG_ANY,
1579     "%s: line %d: old attribute type format not supported.\n",
1580                                     fname, lineno, 0 );
1581 #endif
1582
1583                         }
1584
1585                 /* turn on/off schema checking */
1586                 } else if ( strcasecmp( cargv[0], "schemacheck" ) == 0 ) {
1587                         if ( cargc < 2 ) {
1588 #ifdef NEW_LOGGING
1589                                 LDAP_LOG( CONFIG, CRIT, 
1590                                         "%s: line %d: missing on|off in \"schemacheck <on|off>\""
1591                                         " line.\n", fname, lineno , 0 );
1592 #else
1593                                 Debug( LDAP_DEBUG_ANY,
1594     "%s: line %d: missing on|off in \"schemacheck <on|off>\" line\n",
1595                                     fname, lineno, 0 );
1596 #endif
1597
1598                                 return( 1 );
1599                         }
1600                         if ( strcasecmp( cargv[1], "off" ) == 0 ) {
1601 #ifdef NEW_LOGGING
1602                                 LDAP_LOG( CONFIG, CRIT, 
1603                                         "%s: line %d: schema checking disabled! your mileage may "
1604                                         "vary!\n", fname, lineno , 0 );
1605 #else
1606                                 Debug( LDAP_DEBUG_ANY,
1607                                         "%s: line %d: schema checking disabled! your mileage may vary!\n",
1608                                     fname, lineno, 0 );
1609 #endif
1610                                 global_schemacheck = 0;
1611                         } else {
1612                                 global_schemacheck = 1;
1613                         }
1614
1615                 /* specify access control info */
1616                 } else if ( strcasecmp( cargv[0], "access" ) == 0 ) {
1617                         parse_acl( be, fname, lineno, cargc, cargv );
1618
1619                 /* debug level to log things to syslog */
1620                 } else if ( strcasecmp( cargv[0], "loglevel" ) == 0 ) {
1621                         if ( cargc < 2 ) {
1622 #ifdef NEW_LOGGING
1623                                 LDAP_LOG( CONFIG, CRIT, 
1624                                         "%s: line %d: missing level in \"loglevel <level>\""
1625                                         " line.\n", fname, lineno , 0 );
1626 #else
1627                                 Debug( LDAP_DEBUG_ANY,
1628                     "%s: line %d: missing level in \"loglevel <level>\" line\n",
1629                                     fname, lineno, 0 );
1630 #endif
1631
1632                                 return( 1 );
1633                         }
1634
1635                         ldap_syslog = 0;
1636
1637                         for( i=1; i < cargc; i++ ) {
1638                                 ldap_syslog += atoi( cargv[1] );
1639                         }
1640
1641                 /* list of replicas of the data in this backend (master only) */
1642                 } else if ( strcasecmp( cargv[0], "replica" ) == 0 ) {
1643                         if ( cargc < 2 ) {
1644 #ifdef NEW_LOGGING
1645                                 LDAP_LOG( CONFIG, CRIT, 
1646                                         "%s: line %d: missing host in \"replica "
1647                                         " <host[:port]\" line\n", fname, lineno , 0 );
1648 #else
1649                                 Debug( LDAP_DEBUG_ANY,
1650             "%s: line %d: missing host in \"replica <host[:port]>\" line\n",
1651                                     fname, lineno, 0 );
1652 #endif
1653
1654                                 return( 1 );
1655                         }
1656                         if ( be == NULL ) {
1657 #ifdef NEW_LOGGING
1658                                 LDAP_LOG( CONFIG, INFO, 
1659                                             "%s: line %d: replica line must appear inside "
1660                                             "a database definition.\n", fname, lineno, 0);
1661 #else
1662                                 Debug( LDAP_DEBUG_ANY,
1663 "%s: line %d: replica line must appear inside a database definition\n",
1664                                     fname, lineno, 0 );
1665 #endif
1666                                 return 1;
1667
1668                         } else {
1669                                 int nr = -1;
1670
1671                                 for ( i = 1; i < cargc; i++ ) {
1672                                         if ( strncasecmp( cargv[i], "host=", 5 )
1673                                             == 0 ) {
1674                                                 nr = add_replica_info( be, 
1675                                                         cargv[i] + 5 );
1676                                                 break;
1677                                         }
1678                                 }
1679                                 if ( i == cargc ) {
1680 #ifdef NEW_LOGGING
1681                                         LDAP_LOG( CONFIG, INFO, 
1682                                                 "%s: line %d: missing host in \"replica\" line\n", 
1683                                                 fname, lineno , 0 );
1684 #else
1685                                         Debug( LDAP_DEBUG_ANY,
1686                     "%s: line %d: missing host in \"replica\" line\n",
1687                                             fname, lineno, 0 );
1688 #endif
1689                                         return 1;
1690
1691                                 } else if ( nr == -1 ) {
1692 #ifdef NEW_LOGGING
1693                                         LDAP_LOG( CONFIG, INFO, 
1694                                                    "%s: line %d: unable to add"
1695                                                    " replica \"%s\"\n",
1696                                                    fname, lineno, 
1697                                                    cargv[i] + 5 );
1698 #else
1699                                         Debug( LDAP_DEBUG_ANY,
1700                 "%s: line %d: unable to add replica \"%s\"\n",
1701                                                 fname, lineno, cargv[i] + 5 );
1702 #endif
1703                                         return 1;
1704                                 } else {
1705                                         for ( i = 1; i < cargc; i++ ) {
1706                                                 if ( strncasecmp( cargv[i], "suffix=", 7 ) == 0 ) {
1707
1708                                                         switch ( add_replica_suffix( be, nr, cargv[i] + 7 ) ) {
1709                                                         case 1:
1710 #ifdef NEW_LOGGING
1711                                                                 LDAP_LOG( CONFIG, INFO, 
1712                                                                         "%s: line %d: suffix \"%s\" in \"replica\""
1713                                                                         " line is not valid for backend(ignored)\n",
1714                                                                         fname, lineno, cargv[i] + 7 );
1715 #else
1716                                                                 Debug( LDAP_DEBUG_ANY,
1717                                                                                 "%s: line %d: suffix \"%s\" in \"replica\" line is not valid for backend (ignored)\n",
1718                                                                                 fname, lineno, cargv[i] + 7 );
1719 #endif
1720                                                                 break;
1721
1722                                                         case 2:
1723 #ifdef NEW_LOGGING
1724                                                                 LDAP_LOG( CONFIG, INFO, 
1725                                                                         "%s: line %d: unable to normalize suffix"
1726                                                                         " in \"replica\" line (ignored)\n",
1727                                                                         fname, lineno , 0 );
1728 #else
1729                                                                 Debug( LDAP_DEBUG_ANY,
1730                                                                                  "%s: line %d: unable to normalize suffix in \"replica\" line (ignored)\n",
1731                                                                                  fname, lineno, 0 );
1732 #endif
1733                                                                 break;
1734                                                         }
1735
1736                                                 } else if ( strncasecmp( cargv[i], "attr", 4 ) == 0 ) {
1737                                                         int exclude = 0;
1738                                                         char *arg = cargv[i] + 4;
1739
1740                                                         if ( arg[0] == '!' ) {
1741                                                                 arg++;
1742                                                                 exclude = 1;
1743                                                         }
1744
1745                                                         if ( arg[0] != '=' ) {
1746                                                                 continue;
1747                                                         }
1748
1749                                                         if ( add_replica_attrs( be, nr, arg + 1, exclude ) ) {
1750 #ifdef NEW_LOGGING
1751                                                                 LDAP_LOG( CONFIG, INFO, 
1752                                                                         "%s: line %d: attribute \"%s\" in "
1753                                                                         "\"replica\" line is unknown\n",
1754                                                                         fname, lineno, arg + 1 ); 
1755 #else
1756                                                                 Debug( LDAP_DEBUG_ANY,
1757                                                                                 "%s: line %d: attribute \"%s\" in \"replica\" line is unknown\n",
1758                                                                                 fname, lineno, arg + 1 );
1759 #endif
1760                                                                 return( 1 );
1761                                                         }
1762                                                 }
1763                                         }
1764                                 }
1765                         }
1766
1767                 /* dn of master entity allowed to write to replica */
1768                 } else if ( strcasecmp( cargv[0], "updatedn" ) == 0 ) {
1769                         if ( cargc < 2 ) {
1770 #ifdef NEW_LOGGING
1771                                 LDAP_LOG( CONFIG, CRIT, 
1772                                         "%s: line %d: missing dn in \"updatedn <dn>\""
1773                                         " line.\n", fname, lineno , 0 );
1774 #else
1775                                 Debug( LDAP_DEBUG_ANY,
1776                     "%s: line %d: missing dn in \"updatedn <dn>\" line\n",
1777                                     fname, lineno, 0 );
1778 #endif
1779
1780                                 return( 1 );
1781                         }
1782                         if ( be == NULL ) {
1783 #ifdef NEW_LOGGING
1784                                 LDAP_LOG( CONFIG, INFO, 
1785                                         "%s: line %d: updatedn line must appear inside "
1786                                         "a database definition\n", 
1787                                         fname, lineno , 0 );
1788 #else
1789                                 Debug( LDAP_DEBUG_ANY,
1790 "%s: line %d: updatedn line must appear inside a database definition\n",
1791                                     fname, lineno, 0 );
1792 #endif
1793                                 return 1;
1794
1795                         } else {
1796                                 struct berval dn;
1797
1798                                 if ( load_ucdata( NULL ) < 0 ) return 1;
1799
1800                                 dn.bv_val = cargv[1];
1801                                 dn.bv_len = strlen( cargv[1] );
1802
1803                                 rc = dnNormalize2( NULL, &dn, &be->be_update_ndn );
1804                                 if( rc != LDAP_SUCCESS ) {
1805 #ifdef NEW_LOGGING
1806                                         LDAP_LOG( CONFIG, CRIT, 
1807                                                 "%s: line %d: updatedn DN is invalid.\n",
1808                                                 fname, lineno , 0 );
1809 #else
1810                                         Debug( LDAP_DEBUG_ANY,
1811                                                 "%s: line %d: updatedn DN is invalid\n",
1812                                             fname, lineno, 0 );
1813 #endif
1814                                         return 1;
1815                                 }
1816                         }
1817
1818                 } else if ( strcasecmp( cargv[0], "updateref" ) == 0 ) {
1819                         if ( cargc < 2 ) {
1820 #ifdef NEW_LOGGING
1821                                 LDAP_LOG( CONFIG, CRIT, "%s: line %d: "
1822                                         "missing url in \"updateref <ldapurl>\" line.\n",
1823                                         fname, lineno , 0 );
1824 #else
1825                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1826                                         "missing url in \"updateref <ldapurl>\" line\n",
1827                                     fname, lineno, 0 );
1828 #endif
1829
1830                                 return( 1 );
1831                         }
1832                         if ( be == NULL ) {
1833 #ifdef NEW_LOGGING
1834                                 LDAP_LOG( CONFIG, INFO, "%s: line %d: updateref"
1835                                         " line must appear inside a database definition\n",
1836                                         fname, lineno , 0 );
1837 #else
1838                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: updateref"
1839                                         " line must appear inside a database definition\n",
1840                                         fname, lineno, 0 );
1841 #endif
1842                                 return 1;
1843
1844                         } else if ( !be->be_update_ndn.bv_len ) {
1845 #ifdef NEW_LOGGING
1846                                 LDAP_LOG( CONFIG, INFO, "%s: line %d: "
1847                                         "updateref line must come after updatedn.\n",
1848                                         fname, lineno , 0 );
1849 #else
1850                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1851                                         "updateref line must after updatedn.\n",
1852                                     fname, lineno, 0 );
1853 #endif
1854                                 return 1;
1855                         }
1856
1857                         if( validate_global_referral( cargv[1] ) ) {
1858 #ifdef NEW_LOGGING
1859                                 LDAP_LOG( CONFIG, CRIT, "%s: line %d: "
1860                                         "invalid URL (%s) in \"updateref\" line.\n",
1861                                         fname, lineno, cargv[1] );
1862 #else
1863                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1864                                         "invalid URL (%s) in \"updateref\" line.\n",
1865                                     fname, lineno, cargv[1] );
1866 #endif
1867                                 return 1;
1868                         }
1869
1870                         vals[0].bv_val = cargv[1];
1871                         vals[0].bv_len = strlen( vals[0].bv_val );
1872                         value_add( &be->be_update_refs, vals );
1873
1874                 /* replication log file to which changes are appended */
1875                 } else if ( strcasecmp( cargv[0], "replogfile" ) == 0 ) {
1876                         if ( cargc < 2 ) {
1877 #ifdef NEW_LOGGING
1878                                 LDAP_LOG( CONFIG, CRIT, 
1879                                         "%s: line %d: missing filename in \"replogfile <filename>\""
1880                                         " line.\n", fname, lineno , 0 );
1881 #else
1882                                 Debug( LDAP_DEBUG_ANY,
1883             "%s: line %d: missing filename in \"replogfile <filename>\" line\n",
1884                                     fname, lineno, 0 );
1885 #endif
1886
1887                                 return( 1 );
1888                         }
1889                         if ( be ) {
1890                                 be->be_replogfile = ch_strdup( cargv[1] );
1891                         } else {
1892                                 replogfile = ch_strdup( cargv[1] );
1893                         }
1894
1895                 /* file from which to read additional rootdse attrs */
1896                 } else if ( strcasecmp( cargv[0], "rootDSE" ) == 0) {
1897                         if ( cargc < 2 ) {
1898 #ifdef NEW_LOGGING
1899                                 LDAP_LOG( CONFIG, CRIT, "%s: line %d: "
1900                                         "missing filename in \"rootDSE <filename>\" line.\n",
1901                                         fname, lineno , 0 );
1902 #else
1903                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1904                                         "missing filename in \"rootDSE <filename>\" line.\n",
1905                                     fname, lineno, 0 );
1906 #endif
1907                                 return 1;
1908                         }
1909
1910                         if( read_root_dse_file( cargv[1] ) ) {
1911 #ifdef NEW_LOGGING
1912                                 LDAP_LOG( CONFIG, CRIT, "%s: line %d: "
1913                                         "could not read \"rootDSE <filename>\" line.\n",
1914                                         fname, lineno , 0 );
1915 #else
1916                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1917                                         "could not read \"rootDSE <filename>\" line\n",
1918                                     fname, lineno, 0 );
1919 #endif
1920                                 return 1;
1921                         }
1922
1923                 /* maintain lastmodified{by,time} attributes */
1924                 } else if ( strcasecmp( cargv[0], "lastmod" ) == 0 ) {
1925                         if ( cargc < 2 ) {
1926 #ifdef NEW_LOGGING
1927                                 LDAP_LOG( CONFIG, CRIT, 
1928                                            "%s: line %d: missing on|off in \"lastmod <on|off>\""
1929                                            " line.\n", fname, lineno , 0 );
1930 #else
1931                                 Debug( LDAP_DEBUG_ANY,
1932             "%s: line %d: missing on|off in \"lastmod <on|off>\" line\n",
1933                                     fname, lineno, 0 );
1934 #endif
1935
1936                                 return( 1 );
1937                         }
1938                         if ( strcasecmp( cargv[1], "on" ) == 0 ) {
1939                                 if ( be ) {
1940                                         be->be_flags &= ~SLAP_BFLAG_NOLASTMOD;
1941                                 } else {
1942                                         lastmod = 1;
1943                                 }
1944                         } else {
1945                                 if ( be ) {
1946                                         be->be_flags |= SLAP_BFLAG_NOLASTMOD;
1947                                 } else {
1948                                         lastmod = 0;
1949                                 }
1950                         }
1951
1952 #ifdef SIGHUP
1953                 /* turn on/off gentle SIGHUP handling */
1954                 } else if ( strcasecmp( cargv[0], "gentlehup" ) == 0 ) {
1955                         if ( cargc < 2 ) {
1956                                 Debug( LDAP_DEBUG_ANY,
1957     "%s: line %d: missing on|off in \"gentlehup <on|off>\" line\n",
1958                                     fname, lineno, 0 );
1959                                 return( 1 );
1960                         }
1961                         if ( strcasecmp( cargv[1], "off" ) == 0 ) {
1962                                 global_gentlehup = 0;
1963                         } else {
1964                                 global_gentlehup = 1;
1965                         }
1966 #endif
1967
1968                 /* set idle timeout value */
1969                 } else if ( strcasecmp( cargv[0], "idletimeout" ) == 0 ) {
1970                         int i;
1971                         if ( cargc < 2 ) {
1972 #ifdef NEW_LOGGING
1973                                 LDAP_LOG( CONFIG, CRIT, 
1974                                         "%s: line %d: missing timeout value in "
1975                                         "\"idletimeout <seconds>\" line.\n", fname, lineno , 0 );
1976 #else
1977                                 Debug( LDAP_DEBUG_ANY,
1978             "%s: line %d: missing timeout value in \"idletimeout <seconds>\" line\n",
1979                                     fname, lineno, 0 );
1980 #endif
1981
1982                                 return( 1 );
1983                         }
1984
1985                         i = atoi( cargv[1] );
1986
1987                         if( i < 0 ) {
1988 #ifdef NEW_LOGGING
1989                                 LDAP_LOG( CONFIG, CRIT, 
1990                                         "%s: line %d: timeout value (%d) invalid "
1991                                         "\"idletimeout <seconds>\" line.\n", fname, lineno, i );
1992 #else
1993                                 Debug( LDAP_DEBUG_ANY,
1994             "%s: line %d: timeout value (%d) invalid \"idletimeout <seconds>\" line\n",
1995                                     fname, lineno, i );
1996 #endif
1997
1998                                 return( 1 );
1999                         }
2000
2001                         global_idletimeout = i;
2002
2003                 /* include another config file */
2004                 } else if ( strcasecmp( cargv[0], "include" ) == 0 ) {
2005                         if ( cargc < 2 ) {
2006 #ifdef NEW_LOGGING
2007                                 LDAP_LOG( CONFIG, CRIT, 
2008                                         "%s: line %d: missing filename in \"include "
2009                                         "<filename>\" line.\n", fname, lineno , 0 );
2010 #else
2011                                 Debug( LDAP_DEBUG_ANY,
2012     "%s: line %d: missing filename in \"include <filename>\" line\n",
2013                                     fname, lineno, 0 );
2014 #endif
2015
2016                                 return( 1 );
2017                         }
2018                         savefname = ch_strdup( cargv[1] );
2019                         savelineno = lineno;
2020
2021                         if ( read_config( savefname, depth+1 ) != 0 ) {
2022                                 return( 1 );
2023                         }
2024
2025                         free( savefname );
2026                         lineno = savelineno - 1;
2027
2028                 /* location of kerberos srvtab file */
2029                 } else if ( strcasecmp( cargv[0], "srvtab" ) == 0 ) {
2030                         if ( cargc < 2 ) {
2031 #ifdef NEW_LOGGING
2032                                 LDAP_LOG( CONFIG, CRIT, 
2033                                         "%s: line %d: missing filename in \"srvtab "
2034                                         "<filename>\" line.\n", fname, lineno , 0 );
2035 #else
2036                                 Debug( LDAP_DEBUG_ANY,
2037             "%s: line %d: missing filename in \"srvtab <filename>\" line\n",
2038                                     fname, lineno, 0 );
2039 #endif
2040
2041                                 return( 1 );
2042                         }
2043                         ldap_srvtab = ch_strdup( cargv[1] );
2044
2045 #ifdef SLAPD_MODULES
2046                 } else if (strcasecmp( cargv[0], "moduleload") == 0 ) {
2047                    if ( cargc < 2 ) {
2048 #ifdef NEW_LOGGING
2049                            LDAP_LOG( CONFIG, INFO, 
2050                                    "%s: line %d: missing filename in \"moduleload "
2051                                    "<filename>\" line.\n", fname, lineno , 0 );
2052 #else
2053                       Debug( LDAP_DEBUG_ANY,
2054                              "%s: line %d: missing filename in \"moduleload <filename>\" line\n",
2055                              fname, lineno, 0 );
2056 #endif
2057
2058                       exit( EXIT_FAILURE );
2059                    }
2060                    if (module_load(cargv[1], cargc - 2, (cargc > 2) ? cargv + 2 : NULL)) {
2061 #ifdef NEW_LOGGING
2062                            LDAP_LOG( CONFIG, CRIT, 
2063                                    "%s: line %d: failed to load or initialize module %s\n",
2064                                    fname, lineno, cargv[1] );
2065 #else
2066                       Debug( LDAP_DEBUG_ANY,
2067                              "%s: line %d: failed to load or initialize module %s\n",
2068                              fname, lineno, cargv[1]);
2069 #endif
2070
2071                       exit( EXIT_FAILURE );
2072                    }
2073                 } else if (strcasecmp( cargv[0], "modulepath") == 0 ) {
2074                    if ( cargc != 2 ) {
2075 #ifdef NEW_LOGGING
2076                            LDAP_LOG( CONFIG, INFO, 
2077                                   "%s: line %d: missing path in \"modulepath <path>\""
2078                                   " line\n", fname, lineno , 0 );
2079 #else
2080                       Debug( LDAP_DEBUG_ANY,
2081                              "%s: line %d: missing path in \"modulepath <path>\" line\n",
2082                              fname, lineno, 0 );
2083 #endif
2084
2085                       exit( EXIT_FAILURE );
2086                    }
2087                    if (module_path( cargv[1] )) {
2088 #ifdef NEW_LOGGING
2089                            LDAP_LOG( CONFIG, CRIT, 
2090                                   "%s: line %d: failed to set module search path to %s.\n",
2091                                   fname, lineno, cargv[1] );
2092 #else
2093                            Debug( LDAP_DEBUG_ANY,
2094                                   "%s: line %d: failed to set module search path to %s\n",
2095                                   fname, lineno, cargv[1]);
2096 #endif
2097
2098                       exit( EXIT_FAILURE );
2099                    }
2100                    
2101 #endif /*SLAPD_MODULES*/
2102
2103 #ifdef HAVE_TLS
2104                 } else if ( !strcasecmp( cargv[0], "TLSRandFile" ) ) {
2105                         rc = ldap_pvt_tls_set_option( NULL,
2106                                                       LDAP_OPT_X_TLS_RANDOM_FILE,
2107                                                       cargv[1] );
2108                         if ( rc )
2109                                 return rc;
2110
2111                 } else if ( !strcasecmp( cargv[0], "TLSCipherSuite" ) ) {
2112                         rc = ldap_pvt_tls_set_option( NULL,
2113                                                       LDAP_OPT_X_TLS_CIPHER_SUITE,
2114                                                       cargv[1] );
2115                         if ( rc )
2116                                 return rc;
2117
2118                 } else if ( !strcasecmp( cargv[0], "TLSCertificateFile" ) ) {
2119                         rc = ldap_pvt_tls_set_option( NULL,
2120                                                       LDAP_OPT_X_TLS_CERTFILE,
2121                                                       cargv[1] );
2122                         if ( rc )
2123                                 return rc;
2124
2125                 } else if ( !strcasecmp( cargv[0], "TLSCertificateKeyFile" ) ) {
2126                         rc = ldap_pvt_tls_set_option( NULL,
2127                                                       LDAP_OPT_X_TLS_KEYFILE,
2128                                                       cargv[1] );
2129                         if ( rc )
2130                                 return rc;
2131
2132                 } else if ( !strcasecmp( cargv[0], "TLSCACertificatePath" ) ) {
2133                         rc = ldap_pvt_tls_set_option( NULL,
2134                                                       LDAP_OPT_X_TLS_CACERTDIR,
2135                                                       cargv[1] );
2136                         if ( rc )
2137                                 return rc;
2138
2139                 } else if ( !strcasecmp( cargv[0], "TLSCACertificateFile" ) ) {
2140                         rc = ldap_pvt_tls_set_option( NULL,
2141                                                       LDAP_OPT_X_TLS_CACERTFILE,
2142                                                       cargv[1] );
2143                         if ( rc )
2144                                 return rc;
2145                 } else if ( !strcasecmp( cargv[0], "TLSVerifyClient" ) ) {
2146                         if ( isdigit( (unsigned char) cargv[1][0] ) ) {
2147                                 i = atoi(cargv[1]);
2148                                 rc = ldap_pvt_tls_set_option( NULL,
2149                                                       LDAP_OPT_X_TLS_REQUIRE_CERT,
2150                                                       &i );
2151                         } else {
2152                                 rc = ldap_int_tls_config( NULL,
2153                                                       LDAP_OPT_X_TLS_REQUIRE_CERT,
2154                                                       cargv[1] );
2155                         }
2156
2157                         if ( rc )
2158                                 return rc;
2159
2160 #endif
2161
2162                 } else if ( !strcasecmp( cargv[0], "reverse-lookup" ) ) {
2163 #ifdef SLAPD_RLOOKUPS
2164                         if ( cargc < 2 ) {
2165 #ifdef NEW_LOGGING
2166                                 LDAP_LOG( CONFIG, INFO, 
2167                                         "%s: line %d: reverse-lookup: missing \"on\" or \"off\"\n",
2168                                         fname, lineno , 0 );
2169 #else
2170                                 Debug( LDAP_DEBUG_ANY,
2171 "%s: line %d: reverse-lookup: missing \"on\" or \"off\"\n",
2172                                         fname, lineno, 0 );
2173 #endif
2174                                 return( 1 );
2175                         }
2176
2177                         if ( !strcasecmp( cargv[1], "on" ) ) {
2178                                 use_reverse_lookup = 1;
2179                         } else if ( !strcasecmp( cargv[1], "off" ) ) {
2180                                 use_reverse_lookup = 0;
2181                         } else {
2182 #ifdef NEW_LOGGING
2183                                 LDAP_LOG( CONFIG, INFO, 
2184                                         "%s: line %d: reverse-lookup: "
2185                                         "must be \"on\" (default) or \"off\"\n", fname, lineno, 0 );
2186 #else
2187                                 Debug( LDAP_DEBUG_ANY,
2188 "%s: line %d: reverse-lookup: must be \"on\" (default) or \"off\"\n",
2189                                         fname, lineno, 0 );
2190 #endif
2191                                 return( 1 );
2192                         }
2193
2194 #else /* !SLAPD_RLOOKUPS */
2195 #ifdef NEW_LOGGING
2196                         LDAP_LOG( CONFIG, INFO, 
2197                                 "%s: line %d: reverse lookups "
2198                                 "are not configured (ignored).\n", fname, lineno , 0 );
2199 #else
2200                         Debug( LDAP_DEBUG_ANY,
2201 "%s: line %d: reverse lookups are not configured (ignored).\n",
2202                                 fname, lineno, 0 );
2203 #endif
2204 #endif /* !SLAPD_RLOOKUPS */
2205
2206                 /* pass anything else to the current backend info/db config routine */
2207                 } else {
2208                         if ( bi != NULL ) {
2209                                 if ( bi->bi_config == 0 ) {
2210 #ifdef NEW_LOGGING
2211                                         LDAP_LOG( CONFIG, INFO, 
2212                                                 "%s: line %d: unknown directive \"%s\" inside "
2213                                                 "backend info definition (ignored).\n",
2214                                                 fname, lineno, cargv[0] );
2215 #else
2216                                         Debug( LDAP_DEBUG_ANY,
2217 "%s: line %d: unknown directive \"%s\" inside backend info definition (ignored)\n",
2218                                                 fname, lineno, cargv[0] );
2219 #endif
2220
2221                                 } else {
2222                                         if ( (*bi->bi_config)( bi, fname, lineno, cargc, cargv )
2223                                                 != 0 )
2224                                         {
2225                                                 return( 1 );
2226                                         }
2227                                 }
2228                         } else if ( be != NULL ) {
2229                                 if ( be->be_config == 0 ) {
2230 #ifdef NEW_LOGGING
2231                                         LDAP_LOG( CONFIG, INFO, 
2232                                                 "%s: line %d: uknown directive \"%s\" inside "
2233                                                 "backend database definition (ignored).\n",
2234                                                 fname, lineno, cargv[0] );
2235 #else
2236                                         Debug( LDAP_DEBUG_ANY,
2237 "%s: line %d: unknown directive \"%s\" inside backend database definition (ignored)\n",
2238                                         fname, lineno, cargv[0] );
2239 #endif
2240
2241                                 } else {
2242                                         if ( (*be->be_config)( be, fname, lineno, cargc, cargv )
2243                                                 != 0 )
2244                                         {
2245                                                 return( 1 );
2246                                         }
2247                                 }
2248                         } else {
2249 #ifdef NEW_LOGGING
2250                                 LDAP_LOG( CONFIG, INFO, 
2251                                         "%s: line %d: unknown directive \"%s\" outside backend "
2252                                         "info and database definitions (ignored).\n",
2253                                         fname, lineno, cargv[0] );
2254 #else
2255                                 Debug( LDAP_DEBUG_ANY,
2256 "%s: line %d: unknown directive \"%s\" outside backend info and database definitions (ignored)\n",
2257                                     fname, lineno, cargv[0] );
2258 #endif
2259
2260                         }
2261                 }
2262                 free( saveline );
2263         }
2264         fclose( fp );
2265
2266         if ( depth == 0 ) ch_free( cargv );
2267
2268         if ( load_ucdata( NULL ) < 0 ) return 1;
2269         return( 0 );
2270 }
2271
2272 static int
2273 fp_parse_line(
2274     int         lineno,
2275     char        *line
2276 )
2277 {
2278         char *  token;
2279         char *  logline;
2280         char    logbuf[sizeof("pseudorootpw ***")];
2281
2282         cargc = 0;
2283         token = strtok_quote( line, " \t" );
2284
2285         logline = line;
2286
2287         if ( token && ( strcasecmp( token, "rootpw" ) == 0 ||
2288                 strcasecmp( token, "replica" ) == 0 ||          /* contains "credentials" */
2289                 strcasecmp( token, "bindpw" ) == 0 ||           /* used in back-ldap */
2290                 strcasecmp( token, "pseudorootpw" ) == 0 ||     /* used in back-meta */
2291                 strcasecmp( token, "dbpasswd" ) == 0 ) )        /* used in back-sql */
2292         {
2293                 snprintf( logline = logbuf, sizeof logbuf, "%s ***", token );
2294         }
2295
2296         if ( strtok_quote_ptr ) {
2297                 *strtok_quote_ptr = ' ';
2298         }
2299
2300 #ifdef NEW_LOGGING
2301         LDAP_LOG( CONFIG, DETAIL1, "line %d (%s)\n", lineno, logline , 0 );
2302 #else
2303         Debug( LDAP_DEBUG_CONFIG, "line %d (%s)\n", lineno, logline, 0 );
2304 #endif
2305
2306         if ( strtok_quote_ptr ) {
2307                 *strtok_quote_ptr = '\0';
2308         }
2309
2310         for ( ; token != NULL; token = strtok_quote( NULL, " \t" ) ) {
2311                 if ( cargc == cargv_size - 1 ) {
2312                         char **tmp;
2313                         tmp = ch_realloc( cargv, (cargv_size + ARGS_STEP) *
2314                                             sizeof(*cargv) );
2315                         if ( tmp == NULL ) {
2316 #ifdef NEW_LOGGING
2317                                 LDAP_LOG( CONFIG, ERR, "line %d: out of memory\n", lineno, 0,0 );
2318 #else
2319                                 Debug( LDAP_DEBUG_ANY, 
2320                                                 "line %d: out of memory\n", 
2321                                                 lineno, 0, 0 );
2322 #endif
2323                                 return -1;
2324                         }
2325                         cargv = tmp;
2326                         cargv_size += ARGS_STEP;
2327                 }
2328                 cargv[cargc++] = token;
2329         }
2330         cargv[cargc] = NULL;
2331         return 0;
2332 }
2333
2334 static char *
2335 strtok_quote( char *line, char *sep )
2336 {
2337         int             inquote;
2338         char            *tmp;
2339         static char     *next;
2340
2341         strtok_quote_ptr = NULL;
2342         if ( line != NULL ) {
2343                 next = line;
2344         }
2345         while ( *next && strchr( sep, *next ) ) {
2346                 next++;
2347         }
2348
2349         if ( *next == '\0' ) {
2350                 next = NULL;
2351                 return( NULL );
2352         }
2353         tmp = next;
2354
2355         for ( inquote = 0; *next; ) {
2356                 switch ( *next ) {
2357                 case '"':
2358                         if ( inquote ) {
2359                                 inquote = 0;
2360                         } else {
2361                                 inquote = 1;
2362                         }
2363                         AC_MEMCPY( next, next + 1, strlen( next + 1 ) + 1 );
2364                         break;
2365
2366                 case '\\':
2367                         if ( next[1] )
2368                                 AC_MEMCPY( next,
2369                                             next + 1, strlen( next + 1 ) + 1 );
2370                         next++;         /* dont parse the escaped character */
2371                         break;
2372
2373                 default:
2374                         if ( ! inquote ) {
2375                                 if ( strchr( sep, *next ) != NULL ) {
2376                                         strtok_quote_ptr = next;
2377                                         *next++ = '\0';
2378                                         return( tmp );
2379                                 }
2380                         }
2381                         next++;
2382                         break;
2383                 }
2384         }
2385
2386         return( tmp );
2387 }
2388
2389 static char     buf[BUFSIZ];
2390 static char     *line;
2391 static size_t lmax, lcur;
2392
2393 #define CATLINE( buf ) \
2394         do { \
2395                 size_t len = strlen( buf ); \
2396                 while ( lcur + len + 1 > lmax ) { \
2397                         lmax += BUFSIZ; \
2398                         line = (char *) ch_realloc( line, lmax ); \
2399                 } \
2400                 strcpy( line + lcur, buf ); \
2401                 lcur += len; \
2402         } while( 0 )
2403
2404 static char *
2405 fp_getline( FILE *fp, int *lineno )
2406 {
2407         char            *p;
2408
2409         lcur = 0;
2410         CATLINE( buf );
2411         (*lineno)++;
2412
2413         /* hack attack - keeps us from having to keep a stack of bufs... */
2414         if ( strncasecmp( line, "include", 7 ) == 0 ) {
2415                 buf[0] = '\0';
2416                 return( line );
2417         }
2418
2419         while ( fgets( buf, sizeof(buf), fp ) != NULL ) {
2420                 /* trim off \r\n or \n */
2421                 if ( (p = strchr( buf, '\n' )) != NULL ) {
2422                         if( p > buf && p[-1] == '\r' ) --p;
2423                         *p = '\0';
2424                 }
2425                 
2426                 /* trim off trailing \ and append the next line */
2427                 if ( line[ 0 ] != '\0' 
2428                                 && (p = line + strlen( line ) - 1)[ 0 ] == '\\'
2429                                 && p[ -1 ] != '\\' ) {
2430                         p[ 0 ] = '\0';
2431                         lcur--;
2432
2433                 } else {
2434                         if ( ! isspace( (unsigned char) buf[0] ) ) {
2435                                 return( line );
2436                         }
2437
2438                         /* change leading whitespace to a space */
2439                         buf[0] = ' ';
2440                 }
2441
2442                 CATLINE( buf );
2443                 (*lineno)++;
2444         }
2445         buf[0] = '\0';
2446
2447         return( line[0] ? line : NULL );
2448 }
2449
2450 static void
2451 fp_getline_init( int *lineno )
2452 {
2453         *lineno = -1;
2454         buf[0] = '\0';
2455 }
2456
2457 /* Loads ucdata, returns 1 if loading, 0 if already loaded, -1 on error */
2458 static int
2459 load_ucdata( char *path )
2460 {
2461         static int loaded = 0;
2462         int err;
2463         
2464         if ( loaded ) {
2465                 return( 0 );
2466         }
2467         err = ucdata_load( path ? path : SLAPD_DEFAULT_UCDATA, UCDATA_ALL );
2468         if ( err ) {
2469 #ifdef NEW_LOGGING
2470                 LDAP_LOG( CONFIG, CRIT, 
2471                         "load_ucdata: Error %d loading ucdata.\n", err, 0,0 );
2472 #else
2473                 Debug( LDAP_DEBUG_ANY, "error loading ucdata (error %d)\n",
2474                        err, 0, 0 );
2475 #endif
2476
2477                 return( -1 );
2478         }
2479         loaded = 1;
2480         return( 1 );
2481 }
2482
2483 void
2484 config_destroy( )
2485 {
2486         ucdata_unload( UCDATA_ALL );
2487         free( line );
2488         if ( slapd_args_file )
2489                 free ( slapd_args_file );
2490         if ( slapd_pid_file )
2491                 free ( slapd_pid_file );
2492         acl_destroy( global_acl, NULL );
2493 }