]> git.sur5r.net Git - openldap/blob - servers/slapd/config.c
add new logging
[openldap] / servers / slapd / config.c
1 /* config.c - configuration file handling routines */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-2000 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/socket.h>
15
16 #include "lutil.h"
17 #include "ldap_pvt.h"
18 #include "slap.h"
19
20 #define MAXARGS 200
21
22 /*
23  * defaults for various global variables
24  */
25 int             defsize = SLAPD_DEFAULT_SIZELIMIT;
26 int             deftime = SLAPD_DEFAULT_TIMELIMIT;
27 AccessControl   *global_acl = NULL;
28 slap_access_t           global_default_access = ACL_READ;
29 slap_mask_t             global_restrictops = 0;
30 slap_mask_t             global_allows = 0;
31 slap_mask_t             global_disallows = 0;
32 slap_mask_t             global_requires = 0;
33 slap_ssf_set_t  global_ssf_set;
34 char            *replogfile;
35 int             global_lastmod = ON;
36 int             global_idletimeout = 0;
37 char    *global_host = NULL;
38 char    *global_realm = NULL;
39 char            *ldap_srvtab = "";
40 char            *default_passwd_hash;
41 char            *default_search_base = NULL;
42 char            *default_search_nbase = NULL;
43
44 char   *slapd_pid_file  = NULL;
45 char   *slapd_args_file = NULL;
46
47 int nSaslRegexp = 0;
48 SaslRegexp_t *SaslRegexp = NULL;
49
50 static char     *fp_getline(FILE *fp, int *lineno);
51 static void     fp_getline_init(int *lineno);
52 static int      fp_parse_line(char *line, int *argcp, char **argv);
53
54 static char     *strtok_quote(char *line, char *sep);
55 static int      load_ucdata(char *path);
56
57 int
58 read_config( const char *fname )
59 {
60         FILE    *fp;
61         char    *line, *savefname, *saveline;
62         int     cargc, savelineno;
63         char    *cargv[MAXARGS+1];
64         int     lineno, i;
65 #ifdef HAVE_TLS
66         int rc;
67 #endif
68         struct berval *vals[2];
69         struct berval val;
70
71         static BackendInfo *bi = NULL;
72         static BackendDB        *be = NULL;
73
74         vals[0] = &val;
75         vals[1] = NULL;
76
77         if ( (fp = fopen( fname, "r" )) == NULL ) {
78                 ldap_syslog = 1;
79                 Debug( LDAP_DEBUG_ANY,
80                     "could not open config file \"%s\" - absolute path?\n",
81                     fname, 0, 0 );
82                 perror( fname );
83                 return 1;
84         }
85
86 #ifdef NEW_LOGGING
87         LDAP_LOG(( "config", LDAP_LEVEL_ENTRY,
88                    "read_config: reading config file %s\n", fname ));
89 #else
90         Debug( LDAP_DEBUG_CONFIG, "reading config file %s\n", fname, 0, 0 );
91 #endif
92
93
94         fp_getline_init( &lineno );
95
96         while ( (line = fp_getline( fp, &lineno )) != NULL ) {
97                 /* skip comments and blank lines */
98                 if ( line[0] == '#' || line[0] == '\0' ) {
99                         continue;
100                 }
101
102 #ifdef NEW_LOGGING
103                 LDAP_LOG(( "config", LDAP_LEVEL_DETAIL1,
104                            "line %d (%s)\n", lineno, line ));
105 #else
106                 Debug( LDAP_DEBUG_CONFIG, "line %d (%s)\n", lineno, line, 0 );
107 #endif
108
109
110                 /* fp_parse_line is destructive, we save a copy */
111                 saveline = ch_strdup( line );
112
113                 if ( fp_parse_line( line, &cargc, cargv ) != 0 ) {
114                         return( 1 );
115                 }
116
117                 if ( cargc < 1 ) {
118 #ifdef NEW_LOGGING
119                         LDAP_LOG(( "config", LDAP_LEVEL_INFO,
120                                    "%s: line %d: bad config line (ignored)\n",
121                                    fname, lineno ));
122 #else
123                         Debug( LDAP_DEBUG_ANY,
124                             "%s: line %d: bad config line (ignored)\n",
125                             fname, lineno, 0 );
126 #endif
127
128                         continue;
129                 }
130
131                 if ( strcasecmp( cargv[0], "backend" ) == 0 ) {
132                         if ( cargc < 2 ) {
133 #ifdef NEW_LOGGING
134                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
135                                            "%s : line %d: missing type in \"backend\" line.\n",
136                                            fname, lineno ));
137 #else
138                                 Debug( LDAP_DEBUG_ANY,
139                 "%s: line %d: missing type in \"backend <type>\" line\n",
140                                     fname, lineno, 0 );
141 #endif
142
143                                 return( 1 );
144                         }
145
146                         if( be != NULL ) {
147 #ifdef NEW_LOGGING
148                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
149                                            "%s: line %d: backend line must appear before any "
150                                            "database definition.\n", fname, lineno ));
151 #else
152                                 Debug( LDAP_DEBUG_ANY,
153 "%s: line %d: backend line must appear before any database definition\n",
154                                     fname, lineno, 0 );
155 #endif
156
157                                 return( 1 );
158                         }
159
160                         bi = backend_info( cargv[1] );
161
162                         if( bi == NULL ) {
163 #ifdef NEW_LOGGING
164                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
165                                            "read_config: backend %s initialization failed.\n",
166                                            cargv[1] ));
167 #else
168                                 Debug( LDAP_DEBUG_ANY,
169                                         "backend %s initialization failed.\n",
170                                     cargv[1], 0, 0 );
171 #endif
172
173                                 return( 1 );
174                         }
175                 } else if ( strcasecmp( cargv[0], "database" ) == 0 ) {
176                         if ( cargc < 2 ) {
177 #ifdef NEW_LOGGING
178                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
179                                            "%s: line %d: missing type in \"database <type>\" line\n",
180                                            fname, lineno ));
181 #else
182                                 Debug( LDAP_DEBUG_ANY,
183                 "%s: line %d: missing type in \"database <type>\" line\n",
184                                     fname, lineno, 0 );
185 #endif
186
187                                 return( 1 );
188                         }
189
190                         bi = NULL;
191                         be = backend_db_init( cargv[1] );
192
193                         if( be == NULL ) {
194 #ifdef NEW_LOGGING
195                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
196                                            "database %s initialization failed.\n",
197                                            cargv[1] ));
198 #else
199                                 Debug( LDAP_DEBUG_ANY,
200                                         "database %s initialization failed.\n",
201                                     cargv[1], 0, 0 );
202 #endif
203
204                                 return( 1 );
205                         }
206
207                 /* set thread concurrency */
208                 } else if ( strcasecmp( cargv[0], "concurrency" ) == 0 ) {
209                         int c;
210                         if ( cargc < 2 ) {
211 #ifdef NEW_LOGGING
212                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
213                                            "%s: line %d: missing level in \"concurrency <level\" line\n",
214                                            fname, lineno ));
215 #else
216                                 Debug( LDAP_DEBUG_ANY,
217             "%s: line %d: missing level in \"concurrency <level>\" line\n",
218                                     fname, lineno, 0 );
219 #endif
220
221                                 return( 1 );
222                         }
223
224                         c = atoi( cargv[1] );
225
226                         if( c < 1 ) {
227 #ifdef NEW_LOGGING
228                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
229                                            "%s: line %d: invalid level (%d) in "
230                                            "\"concurrency <level>\" line.\n",
231                                            fname, lineno, c ));
232 #else
233                                 Debug( LDAP_DEBUG_ANY,
234             "%s: line %d: invalid level (%d) in \"concurrency <level>\" line\n",
235                                     fname, lineno, c );
236 #endif
237
238                                 return( 1 );
239                         }
240
241                         ldap_pvt_thread_set_concurrency( c );
242
243                 /* default search base */
244                 } else if ( strcasecmp( cargv[0], "defaultSearchBase" ) == 0 ) {
245                         if ( cargc < 2 ) {
246 #ifdef NEW_LOGGING
247                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
248                                            "%s: line %d: missing dn in \"defaultSearchBase <dn\" "
249                                            "line\n", fname, lineno ));
250 #else
251                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
252                                         "missing dn in \"defaultSearchBase <dn>\" line\n",
253                                         fname, lineno, 0 );
254 #endif
255
256                                 return 1;
257
258                         } else if ( cargc > 2 ) {
259 #ifdef NEW_LOGGING
260                                 LDAP_LOG(( "config", LDAP_LEVEL_INFO,
261                                            "%s: line %d: extra cruft after <dn> in "
262                                            "\"defaultSearchBase %s\" line (ignored)\n",
263                                            fname, lineno, cargv[1] ));
264 #else
265                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
266                                         "extra cruft after <dn> in \"defaultSearchBase %s\", "
267                                         "line (ignored)\n",
268                                         fname, lineno, cargv[1] );
269 #endif
270
271                         }
272
273                         if ( bi != NULL || be != NULL ) {
274 #ifdef NEW_LOGGING
275                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
276                                            "%s: line %d: defaultSearchBase line must appear "
277                                            "prior to any backend or database definitions\n",
278                                            fname, lineno ));
279 #else
280                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
281                                         "defaultSearchBaase line must appear prior to "
282                                         "any backend or database definition\n",
283                                     fname, lineno, 0 );
284 #endif
285
286                                 return 1;
287                         }
288
289                         if ( default_search_nbase != NULL ) {
290 #ifdef NEW_LOGGING
291                                 LDAP_LOG(( "config", LDAP_LEVEL_INFO,
292                                            "%s: line %d: default search base \"%s\" already defined "
293                                            "(discarding old)\n", fname, lineno, default_search_base ));
294 #else
295                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
296                                         "default search base \"%s\" already defined "
297                                         "(discarding old)\n",
298                                         fname, lineno, default_search_base );
299 #endif
300
301                                 free( default_search_base );
302                                 free( default_search_nbase );
303                         }
304
305                         default_search_base = ch_strdup( cargv[1] );
306                         default_search_nbase = ch_strdup( cargv[1] );
307
308                         if ( load_ucdata( NULL ) < 0 ) {
309                                 return( 1 );
310                         }
311                         if( dn_normalize( default_search_nbase ) == NULL ) {
312 #ifdef NEW_LOGGING
313                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
314                                            "%s:  %d: invalid default search base \"%s\"\n",
315                                            fname, lineno, default_search_base ));
316 #else
317                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
318                                         "invalid default search base \"%s\"\n",
319                                         fname, lineno, default_search_base );
320 #endif
321
322                                 return 1;
323                         }
324                
325                 /* set maximum threads in thread pool */
326                 } else if ( strcasecmp( cargv[0], "threads" ) == 0 ) {
327                         int c;
328                         if ( cargc < 2 ) {
329 #ifdef NEW_LOGGING
330                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
331                                            "%s: line %d: missing count in \"threads <count>\" line\n",
332                                            fname, lineno ));
333 #else
334                                 Debug( LDAP_DEBUG_ANY,
335             "%s: line %d: missing count in \"threads <count>\" line\n",
336                                     fname, lineno, 0 );
337 #endif
338
339                                 return( 1 );
340                         }
341
342                         c = atoi( cargv[1] );
343
344                         if( c < 0 ) {
345 #ifdef NEW_LOGGING
346                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
347                                            "%s: line %d: invalid level (%d) in \"threads <count>\""
348                                            "line\n",fname, lineno, c ));
349 #else
350                                 Debug( LDAP_DEBUG_ANY,
351             "%s: line %d: invalid level (%d) in \"threads <count>\" line\n",
352                                     fname, lineno, c );
353 #endif
354
355                                 return( 1 );
356                         }
357
358                         ldap_pvt_thread_pool_maxthreads( &connection_pool, c );
359
360                 /* get pid file name */
361                 } else if ( strcasecmp( cargv[0], "pidfile" ) == 0 ) {
362                         if ( cargc < 2 ) {
363 #ifdef NEW_LOGGING
364                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
365                                            "%s: line %d missing file name in \"pidfile <file>\" line.\n",
366                                            fname, lineno ));
367 #else
368                                 Debug( LDAP_DEBUG_ANY,
369             "%s: line %d: missing file name in \"pidfile <file>\" line\n",
370                                     fname, lineno, 0 );
371 #endif
372
373                                 return( 1 );
374                         }
375
376                         slapd_pid_file = ch_strdup( cargv[1] );
377
378                 /* get args file name */
379                 } else if ( strcasecmp( cargv[0], "argsfile" ) == 0 ) {
380                         if ( cargc < 2 ) {
381 #ifdef NEW_LOGGING
382                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
383                                            "%s: %d: missing file name in "
384                                            "\"argsfile <file>\" line.\n",
385                                            fname, lineno ));
386 #else
387                                 Debug( LDAP_DEBUG_ANY,
388             "%s: line %d: missing file name in \"argsfile <file>\" line\n",
389                                     fname, lineno, 0 );
390 #endif
391
392                                 return( 1 );
393                         }
394
395                         slapd_args_file = ch_strdup( cargv[1] );
396
397                 /* default password hash */
398                 } else if ( strcasecmp( cargv[0], "password-hash" ) == 0 ) {
399                         if ( cargc < 2 ) {
400 #ifdef NEW_LOGGING
401                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
402                                            "%s: line %d: missing hash in "
403                                            "\"password-hash <hash>\" line.\n",
404                                            fname, lineno ));
405 #else
406                                 Debug( LDAP_DEBUG_ANY,
407             "%s: line %d: missing hash in \"password-hash <hash>\" line\n",
408                                     fname, lineno, 0 );
409 #endif
410
411                                 return( 1 );
412                         }
413                         if ( default_passwd_hash != NULL ) {
414 #ifdef NEW_LOGGING
415                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
416                                            "%s: line %d: already set default password_hash!\n",
417                                            fname, lineno ));
418 #else
419                                 Debug( LDAP_DEBUG_ANY,
420                                         "%s: line %d: already set default password_hash!\n",
421                                         fname, lineno, 0 );
422 #endif
423
424                                 return 1;
425
426                         } else {
427                                 default_passwd_hash = ch_strdup( cargv[1] );
428                         }
429
430                 /* set SASL host */
431                 } else if ( strcasecmp( cargv[0], "sasl-host" ) == 0 ) {
432                         if ( cargc < 2 ) {
433 #ifdef NEW_LOGGING
434                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
435                                            "%s: line %d: missing host in \"sasl-host <host>\" line\n",
436                                            fname, lineno ));
437 #else
438                                 Debug( LDAP_DEBUG_ANY,
439             "%s: line %d: missing host in \"sasl-host <host>\" line\n",
440                                     fname, lineno, 0 );
441 #endif
442
443                                 return( 1 );
444                         }
445
446                         if ( global_host != NULL ) {
447 #ifdef NEW_LOGGING
448                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
449                                            "%s: line %d: already set sasl-host!\n",
450                                            fname, lineno ));
451 #else
452                                 Debug( LDAP_DEBUG_ANY,
453                                         "%s: line %d: already set sasl-host!\n",
454                                         fname, lineno, 0 );
455 #endif
456
457                                 return 1;
458
459                         } else {
460                                 global_host = ch_strdup( cargv[1] );
461                         }
462
463                 /* set SASL realm */
464                 } else if ( strcasecmp( cargv[0], "sasl-realm" ) == 0 ) {
465                         if ( cargc < 2 ) {
466 #ifdef NEW_LOGGING
467                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
468                                            "%s: line %d: missing realm in \"sasl-realm <realm>\" line.\n",
469                                            fname, lineno ));
470 #else
471                                 Debug( LDAP_DEBUG_ANY,
472             "%s: line %d: missing realm in \"sasl-realm <realm>\" line\n",
473                                     fname, lineno, 0 );
474 #endif
475
476                                 return( 1 );
477                         }
478
479                         if ( global_realm != NULL ) {
480 #ifdef NEW_LOGGING
481                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
482                                            "%s: line %d: already set sasl-realm!\n",
483                                            fname, lineno ));
484 #else
485                                 Debug( LDAP_DEBUG_ANY,
486                                         "%s: line %d: already set sasl-realm!\n",
487                                         fname, lineno, 0 );
488 #endif
489
490                                 return 1;
491
492                         } else {
493                                 global_realm = ch_strdup( cargv[1] );
494                         }
495
496                 } else if ( !strcasecmp( cargv[0], "sasl-regexp" ) 
497                         || !strcasecmp( cargv[0], "saslregexp" ) )
498                 {
499                         int rc;
500                         if ( cargc != 3 ) {
501 #ifdef NEW_LOGGING
502                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
503                                            "%s: line %d: need 2 args in "
504                                            "\"saslregexp <match> <replace>\"\n",
505                                            fname, lineno ));
506 #else
507                                 Debug( LDAP_DEBUG_ANY, 
508                                 "%s: line %d: need 2 args in \"saslregexp <match> <replace>\"\n",
509                                     fname, lineno, 0 );
510 #endif
511
512                                 return( 1 );
513                         }
514                         rc = slap_sasl_regexp_config( cargv[1], cargv[2] );
515                         if ( rc ) {
516                                 return rc;
517                         }
518
519                 /* SASL security properties */
520                 } else if ( strcasecmp( cargv[0], "sasl-secprops" ) == 0 ) {
521                         char *txt;
522
523                         if ( cargc < 2 ) {
524 #ifdef NEW_LOGGING
525                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
526                                            "%s: line %d: missing flags in "
527                                            "\"sasl-secprops <properties>\" line\n",
528                                            fname, lineno ));
529 #else
530                                 Debug( LDAP_DEBUG_ANY,
531             "%s: line %d: missing flags in \"sasl-secprops <properties>\" line\n",
532                                     fname, lineno, 0 );
533 #endif
534
535                                 return 1;
536                         }
537
538                         txt = slap_sasl_secprops( cargv[1] );
539                         if ( txt != NULL ) {
540 #ifdef NEW_LOGGING
541                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
542                                            "%s: line %d sas-secprops: %s\n",
543                                            fname, lineno, txt ));
544 #else
545                                 Debug( LDAP_DEBUG_ANY,
546             "%s: line %d: sasl-secprops: %s\n",
547                                     fname, lineno, txt );
548 #endif
549
550                                 return 1;
551                         }
552
553                 /* set UCDATA path */
554                 } else if ( strcasecmp( cargv[0], "ucdata-path" ) == 0 ) {
555                         int err;
556                         if ( cargc < 2 ) {
557 #ifdef NEW_LOGGING
558                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
559                                            "%s: line %d: missing path in "
560                                            "\"ucdata-path <path>\" line.\n",
561                                            fname, lineno ));
562 #else
563                                 Debug( LDAP_DEBUG_ANY,
564             "%s: line %d: missing path in \"ucdata-path <path>\" line\n",
565                                     fname, lineno, 0 );
566 #endif
567
568                                 return( 1 );
569                         }
570
571                         err = load_ucdata( cargv[1] );
572                         if ( err <= 0 ) {
573                                 if ( err == 0 ) {
574 #ifdef NEW_LOGGING
575                                         LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
576                                                    "%s: line %d: ucdata already loaded, ucdata-path "
577                                                    "must be set earlier in the file and/or be "
578                                                    "specified only once!\n",
579                                                    fname, lineno ));
580 #else
581                                         Debug( LDAP_DEBUG_ANY,
582                                                "%s: line %d: ucdata already loaded, ucdata-path must be set earlier in the file and/or be specified only once!\n",
583                                                fname, lineno, 0 );
584 #endif
585
586                                 }
587                                 return( 1 );
588                         }
589
590                 /* set time limit */
591                 } else if ( strcasecmp( cargv[0], "sizelimit" ) == 0 ) {
592                         if ( cargc < 2 ) {
593 #ifdef NEW_LOGGING
594                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
595                                            "%s: line %d: missing limit in \"sizelimit <limit>\" line.\n",
596                                            fname, lineno ));
597 #else
598                                 Debug( LDAP_DEBUG_ANY,
599             "%s: line %d: missing limit in \"sizelimit <limit>\" line\n",
600                                     fname, lineno, 0 );
601 #endif
602
603                                 return( 1 );
604                         }
605                         if ( be == NULL ) {
606                                 defsize = atoi( cargv[1] );
607                         } else {
608                                 be->be_sizelimit = atoi( cargv[1] );
609                         }
610
611                 /* set time limit */
612                 } else if ( strcasecmp( cargv[0], "timelimit" ) == 0 ) {
613                         if ( cargc < 2 ) {
614 #ifdef NEW_LOGGING
615                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
616                                            "%s: line %d missing limit in \"timelimit <limit>\" line.\n",
617                                            fname, lineno ));
618 #else
619                                 Debug( LDAP_DEBUG_ANY,
620             "%s: line %d: missing limit in \"timelimit <limit>\" line\n",
621                                     fname, lineno, 0 );
622 #endif
623
624                                 return( 1 );
625                         }
626                         if ( be == NULL ) {
627                                 deftime = atoi( cargv[1] );
628                         } else {
629                                 be->be_timelimit = atoi( cargv[1] );
630                         }
631
632                 /* set database suffix */
633                 } else if ( strcasecmp( cargv[0], "suffix" ) == 0 ) {
634                         Backend *tmp_be;
635                         if ( cargc < 2 ) {
636 #ifdef NEW_LOGGING
637                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
638                                            "%s: line %d: missing dn in \"suffix <dn>\" line.\n",
639                                            fname, lineno ));
640 #else
641                                 Debug( LDAP_DEBUG_ANY,
642                     "%s: line %d: missing dn in \"suffix <dn>\" line\n",
643                                     fname, lineno, 0 );
644 #endif
645
646                                 return( 1 );
647                         } else if ( cargc > 2 ) {
648 #ifdef NEW_LOGGING
649                                 LDAP_LOG(( "config", LDAP_LEVEL_INFO,
650                                            "%s: line %d: extra cruft after <dn> in \"suffix %s\""
651                                            " line (ignored).\n", fname, lineno, cargv[1] ));
652 #else
653                                 Debug( LDAP_DEBUG_ANY,
654     "%s: line %d: extra cruft after <dn> in \"suffix %s\" line (ignored)\n",
655                                     fname, lineno, cargv[1] );
656 #endif
657
658                         }
659                         if ( be == NULL ) {
660 #ifdef NEW_LOGGING
661                                 LDAP_LOG(( "config", LDAP_LEVEL_INFO,
662                                            "%s: line %d: suffix line must appear inside a database "
663                                            "definition (ignored).\n", fname, lineno ));
664 #else
665                                 Debug( LDAP_DEBUG_ANY,
666 "%s: line %d: suffix line must appear inside a database definition (ignored)\n",
667                                     fname, lineno, 0 );
668 #endif
669
670                         } else if ( ( tmp_be = select_backend( cargv[1], 0 ) ) == be ) {
671 #ifdef NEW_LOGGING
672                                 LDAP_LOG(( "config", LDAP_LEVEL_INFO,
673                                            "%s: line %d: suffix already served by this backend "
674                                            "(ignored)\n", fname, lineno ));
675 #else
676                                 Debug( LDAP_DEBUG_ANY,
677 "%s: line %d: suffix already served by this backend (ignored)\n",
678                                     fname, lineno, 0 );
679 #endif
680
681                         } else if ( tmp_be  != NULL ) {
682 #ifdef NEW_LOGGING
683                                 LDAP_LOG(( "config", LDAP_LEVEL_INFO,
684                                            "%s: line %d: suffix already served by a preceding "
685                                            "backend \"%s\" (ignored)\n", fname, lineno,
686                                            tmp_be->be_suffix[0] ));
687 #else
688                                 Debug( LDAP_DEBUG_ANY,
689 "%s: line %d: suffix already served by a preceeding backend \"%s\" (ignored)\n",
690                                     fname, lineno, tmp_be->be_suffix[0] );
691 #endif
692
693                         } else {
694                                 char *dn = ch_strdup( cargv[1] );
695                                 if ( load_ucdata( NULL ) < 0 ) {
696                                         return( 1 );
697                                 }
698                                 if( dn_validate( dn ) == NULL ) {
699 #ifdef NEW_LOGGING
700                                         LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
701                                                    "%s: line %d: suffix DN invalid\"%s\"\n",
702                                                    fname, lineno, cargv[1] ));
703 #else
704                                         Debug( LDAP_DEBUG_ANY, "%s: line %d: "
705                                                 "suffix DN invalid \"%s\"\n",
706                                         fname, lineno, cargv[1] );
707 #endif
708
709                                         return 1;
710
711                                 } else if( *dn == '\0' && default_search_nbase != NULL ) {
712 #ifdef NEW_LOGGING
713                                         LDAP_LOG(( "config", LDAP_LEVEL_INFO,
714                                                    "%s: line %d: suffix DN empty and default search "
715                                                    "base provided \"%s\" (assuming okay).\n",
716                                                    fname, lineno, default_search_base ));
717 #else
718                                         Debug( LDAP_DEBUG_ANY, "%s: line %d: "
719                                                 "suffix DN empty and default "
720                                                 "search base provided \"%s\" (assuming okay)\n",
721                                         fname, lineno, default_search_base );
722 #endif
723
724                                 }
725                                 charray_add( &be->be_suffix, dn );
726                                 (void) ldap_pvt_str2upper( dn );
727                                 charray_add( &be->be_nsuffix, dn );
728                                 free( dn );
729                         }
730
731                 /* set database suffixAlias */
732                 } else if ( strcasecmp( cargv[0], "suffixAlias" ) == 0 ) {
733                         Backend *tmp_be;
734                         if ( cargc < 2 ) {
735 #ifdef NEW_LOGGING
736                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
737                                            "%s: line %d: missing alias and aliased_dn in "
738                                            "\"suffixAlias <alias> <aliased_dn>\" line.\n",
739                                            fname, lineno ));
740 #else
741                                 Debug( LDAP_DEBUG_ANY,
742 "%s: line %d: missing alias and aliased_dn in \"suffixAlias <alias> <aliased_dn>\" line\n",
743                                         fname, lineno, 0 );
744 #endif
745
746                                 return( 1 );
747                         } else if ( cargc < 3 ) {
748 #ifdef NEW_LOGGING
749                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
750                                            "%s: line %d: missing aliased_dn in "
751                                            "\"suffixAlias <alias> <aliased_dn>\" line\n",
752                                            fname, lineno ));
753 #else
754                                 Debug( LDAP_DEBUG_ANY,
755 "%s: line %d: missing aliased_dn in \"suffixAlias <alias> <aliased_dn>\" line\n",
756                                 fname, lineno, 0 );
757 #endif
758
759                                 return( 1 );
760                         } else if ( cargc > 3 ) {
761 #ifdef NEW_LOGGING
762                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
763                                            "%s: line %d: extra cruft in suffixAlias line (ignored)\n",
764                                            fname, lineno ));
765 #else
766                                 Debug( LDAP_DEBUG_ANY,
767                                         "%s: line %d: extra cruft in suffixAlias line (ignored)\n",
768                                 fname, lineno, 0 );
769 #endif
770
771                         }
772
773                         if ( be == NULL ) {
774 #ifdef NEW_LOGGING
775                                 LDAP_LOG(( "config", LDAP_LEVEL_INFO,
776                                            "%s: line %d: suffixAlias line must appear inside a "
777                                            "database definition (ignored).\n", fname, lineno ));
778 #else
779                                 Debug( LDAP_DEBUG_ANY,
780                                         "%s: line %d: suffixAlias line"
781                                         " must appear inside a database definition (ignored)\n",
782                                         fname, lineno, 0 );
783 #endif
784
785                         } else if ( (tmp_be = select_backend( cargv[1], 0 )) != NULL ) {
786 #ifdef NEW_LOGGING
787                                 LDAP_LOG(( "config", LDAP_LEVEL_INFO,
788                                            "%s: line %d: suffixAlias served by a preceeding "
789                                            "backend \"%s\" (ignored).\n", fname, lineno,
790                                            tmp_be->be_suffix[0] ));
791 #else
792                                 Debug( LDAP_DEBUG_ANY,
793                                         "%s: line %d: suffixAlias served by"
794                                         "  a preceeding backend \"%s\" (ignored)\n",
795                                         fname, lineno, tmp_be->be_suffix[0] );
796 #endif
797
798
799                         } else if ( (tmp_be = select_backend( cargv[2], 0 )) != NULL ) {
800 #ifdef NEW_LOGGING
801                                 LDAP_LOG(( "config", LDAP_LEVEL_INFO,
802                                            "%s: line %d: suffixAlias derefs to a different backend "
803                                            "a preceeding backend \"%s\" (ignored)\n",
804                                            fname, lineno, tmp_be->be_suffix[0] ));
805 #else
806                                 Debug( LDAP_DEBUG_ANY,
807                                         "%s: line %d: suffixAlias derefs to differnet backend"
808                                         "  a preceeding backend \"%s\" (ignored)\n",
809                                         fname, lineno, tmp_be->be_suffix[0] );
810 #endif
811
812
813                         } else {
814                                 char *alias, *aliased_dn;
815
816                                 alias = ch_strdup( cargv[1] );
817                                 if ( load_ucdata( NULL ) < 0 ) {
818                                         return( 1 );
819                                 }
820                                 (void) dn_normalize( alias );
821
822                                 aliased_dn = ch_strdup( cargv[2] );
823                                 (void) dn_normalize( aliased_dn );
824
825                                 charray_add( &be->be_suffixAlias, alias );
826                                 charray_add( &be->be_suffixAlias, aliased_dn );
827
828                                 free(alias);
829                                 free(aliased_dn);
830                         }
831
832                /* set max deref depth */
833                } else if ( strcasecmp( cargv[0], "maxDerefDepth" ) == 0 ) {
834                                         int i;
835                        if ( cargc < 2 ) {
836 #ifdef NEW_LOGGING
837                                LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
838                                           "%s: line %d: missing depth in \"maxDerefDepth <depth>\""
839                                           " line\n", fname, lineno ));
840 #else
841                                Debug( LDAP_DEBUG_ANY,
842                    "%s: line %d: missing depth in \"maxDerefDepth <depth>\" line\n",
843                                    fname, lineno, 0 );
844 #endif
845
846                                return( 1 );
847                        }
848                        if ( be == NULL ) {
849 #ifdef NEW_LOGGING
850                                LDAP_LOG(( "config", LDAP_LEVEL_INFO,
851                                           "%s: line %d: depth line must appear inside a database "
852                                           "definition (ignored)\n", fname, lineno ));
853 #else
854                                Debug( LDAP_DEBUG_ANY,
855 "%s: line %d: depth line must appear inside a database definition (ignored)\n",
856                                    fname, lineno, 0 );
857 #endif
858
859                        } else if ((i = atoi(cargv[1])) < 0) {
860 #ifdef NEW_LOGGING
861                                LDAP_LOG(( "config", LDAP_LEVEL_INFO,
862                                           "%s: line %d: depth must be positive (ignored).\n",
863                                           fname, lineno ));
864 #else
865                                Debug( LDAP_DEBUG_ANY,
866 "%s: line %d: depth must be positive (ignored)\n",
867                                    fname, lineno, 0 );
868 #endif
869
870
871                        } else {
872                            be->be_max_deref_depth = i;
873                                            }
874
875
876                 /* set magic "root" dn for this database */
877                 } else if ( strcasecmp( cargv[0], "rootdn" ) == 0 ) {
878                         if ( cargc < 2 ) {
879 #ifdef NEW_LOGGING
880                                 LDAP_LOG(( "config", LDAP_LEVEL_INFO,
881                                            "%s: line %d: missing dn in \"rootdn <dn>\" line.\n",
882                                            fname, lineno ));
883 #else
884                                 Debug( LDAP_DEBUG_ANY,
885                     "%s: line %d: missing dn in \"rootdn <dn>\" line\n",
886                                     fname, lineno, 0 );
887 #endif
888
889                                 return( 1 );
890                         }
891                         if ( be == NULL ) {
892 #ifdef NEW_LOGGING
893                                 LDAP_LOG(( "config", LDAP_LEVEL_INFO,
894                                            "%s: line %d: rootdn line must appear inside a database "
895                                            "definition (ignored).\n", fname, lineno ));
896 #else
897                                 Debug( LDAP_DEBUG_ANY,
898 "%s: line %d: rootdn line must appear inside a database definition (ignored)\n",
899                                     fname, lineno, 0 );
900 #endif
901
902                         } else {
903                                 be->be_root_dn = ch_strdup( cargv[1] );
904                                 be->be_root_ndn = ch_strdup( cargv[1] );
905
906                                 if ( load_ucdata( NULL ) < 0 ) {
907                                         return( 1 );
908                                 }
909                                 if( dn_normalize( be->be_root_ndn ) == NULL ) {
910                                         free( be->be_root_dn );
911                                         free( be->be_root_ndn );
912 #ifdef NEW_LOGGING
913                                         LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
914                                                    "%s: line %d: rootdn DN is invalid.\n",
915                                                    fname, lineno ));
916 #else
917                                         Debug( LDAP_DEBUG_ANY,
918 "%s: line %d: rootdn DN is invalid\n",
919                                            fname, lineno, 0 );
920 #endif
921
922                                         return( 1 );
923                                 }
924                         }
925
926                 /* set super-secret magic database password */
927                 } else if ( strcasecmp( cargv[0], "rootpw" ) == 0 ) {
928                         if ( cargc < 2 ) {
929 #ifdef NEW_LOGGING
930                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
931                                            "%s: line %d: missing passwd in \"rootpw <passwd>\""
932                                            " line\n", fname, lineno ));
933 #else
934                                 Debug( LDAP_DEBUG_ANY,
935             "%s: line %d: missing passwd in \"rootpw <passwd>\" line\n",
936                                     fname, lineno, 0 );
937 #endif
938
939                                 return( 1 );
940                         }
941                         if ( be == NULL ) {
942 #ifdef NEW_LOGGING
943                                 LDAP_LOG(( "config", LDAP_LEVEL_INFO,
944                                            "%s: line %d: rootpw line must appear inside a database "
945                                            "definition (ignored)\n", fname, lineno ));
946 #else
947                                 Debug( LDAP_DEBUG_ANY,
948 "%s: line %d: rootpw line must appear inside a database definition (ignored)\n",
949                                     fname, lineno, 0 );
950 #endif
951
952                         } else {
953                                 be->be_root_pw.bv_val = ch_strdup( cargv[1] );
954                                 be->be_root_pw.bv_len = strlen( be->be_root_pw.bv_val );
955                         }
956
957                 /* make this database read-only */
958                 } else if ( strcasecmp( cargv[0], "readonly" ) == 0 ) {
959                         if ( cargc < 2 ) {
960 #ifdef NEW_LOGGING
961                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
962                                            "%s: line %d: missing on|off in \"readonly <on|off>\" line.\n",
963                                            fname, lineno ));
964 #else
965                                 Debug( LDAP_DEBUG_ANY,
966             "%s: line %d: missing on|off in \"readonly <on|off>\" line\n",
967                                     fname, lineno, 0 );
968 #endif
969
970                                 return( 1 );
971                         }
972                         if ( be == NULL ) {
973                                 if ( strcasecmp( cargv[1], "on" ) == 0 ) {
974                                         global_restrictops |= SLAP_RESTRICT_OP_WRITES;
975                                 } else {
976                                         global_restrictops &= ~SLAP_RESTRICT_OP_WRITES;
977                                 }
978                         } else {
979                                 if ( strcasecmp( cargv[1], "on" ) == 0 ) {
980                                         be->be_restrictops |= SLAP_RESTRICT_OP_WRITES;
981                                 } else {
982                                         be->be_restrictops &= ~SLAP_RESTRICT_OP_WRITES;
983                                 }
984                         }
985
986
987                 /* allow these features */
988                 } else if ( strcasecmp( cargv[0], "allows" ) == 0 ||
989                         strcasecmp( cargv[0], "allow" ) == 0 )
990                 {
991                         slap_mask_t     allows;
992
993                         if ( be != NULL ) {
994 #ifdef NEW_LOGGING
995                                 LDAP_LOG(( "config", LDAP_LEVEL_INFO,
996                                            "%s: line %d: allow line must appear prior to "
997                                            "database definitions.\n", fname, lineno ));
998 #else
999                                 Debug( LDAP_DEBUG_ANY,
1000 "%s: line %d: allow line must appear prior to database definitions\n",
1001                                     fname, lineno, 0 );
1002 #endif
1003
1004                         }
1005
1006                         if ( cargc < 2 ) {
1007 #ifdef NEW_LOGGING
1008                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
1009                                            "%s: line %d: missing feature(s) in \"allow <features>\""
1010                                            " line\n", fname, lineno ));
1011 #else
1012                                 Debug( LDAP_DEBUG_ANY,
1013             "%s: line %d: missing feature(s) in \"allow <features>\" line\n",
1014                                     fname, lineno, 0 );
1015 #endif
1016
1017                                 return( 1 );
1018                         }
1019
1020                         allows = 0;
1021
1022                         for( i=1; i < cargc; i++ ) {
1023                                 if( strcasecmp( cargv[i], "tls_2_anon" ) == 0 ) {
1024                                         allows |= SLAP_ALLOW_TLS_2_ANON;
1025
1026                                 } else if( strcasecmp( cargv[i], "none" ) != 0 ) {
1027 #ifdef NEW_LOGGING
1028                                         LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
1029                                                    "%s: line %d: unknown feature %s in "
1030                                                    "\"allow <features>\" line.\n",
1031                                                    fname, lineno, cargv[1] ));
1032 #else
1033                                         Debug( LDAP_DEBUG_ANY,
1034                     "%s: line %d: unknown feature %s in \"allow <features>\" line\n",
1035                                             fname, lineno, cargv[i] );
1036 #endif
1037
1038                                         return( 1 );
1039                                 }
1040                         }
1041
1042                         global_allows = allows;
1043
1044                 /* disallow these features */
1045                 } else if ( strcasecmp( cargv[0], "disallows" ) == 0 ||
1046                         strcasecmp( cargv[0], "disallow" ) == 0 )
1047                 {
1048                         slap_mask_t     disallows;
1049
1050                         if ( be != NULL ) {
1051 #ifdef NEW_LOGGING
1052                                 LDAP_LOG(( "config", LDAP_LEVEL_INFO,
1053                                            "%s: line %d: disallow line must appear prior to "
1054                                            "database definitions.\n", fname, lineno ));
1055 #else
1056                                 Debug( LDAP_DEBUG_ANY,
1057 "%s: line %d: disallow line must appear prior to database definitions\n",
1058                                     fname, lineno, 0 );
1059 #endif
1060
1061                         }
1062
1063                         if ( cargc < 2 ) {
1064 #ifdef NEW_LOGGING
1065                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
1066                                            "%s: line %d: missing feature(s) in \"disallow <features>\""
1067                                            " line.\n", fname, lineno ));
1068 #else
1069                                 Debug( LDAP_DEBUG_ANY,
1070             "%s: line %d: missing feature(s) in \"disallow <features>\" line\n",
1071                                     fname, lineno, 0 );
1072 #endif
1073
1074                                 return( 1 );
1075                         }
1076
1077                         disallows = 0;
1078
1079                         for( i=1; i < cargc; i++ ) {
1080                                 if( strcasecmp( cargv[i], "bind_v2" ) == 0 ) {
1081                                         disallows |= SLAP_DISALLOW_BIND_V2;
1082
1083                                 } else if( strcasecmp( cargv[i], "bind_anon" ) == 0 ) {
1084                                         disallows |= SLAP_DISALLOW_BIND_ANON;
1085
1086                                 } else if( strcasecmp( cargv[i], "bind_anon_cred" ) == 0 ) {
1087                                         disallows |= SLAP_DISALLOW_BIND_ANON_CRED;
1088
1089                                 } else if( strcasecmp( cargv[i], "bind_anon_dn" ) == 0 ) {
1090                                         disallows |= SLAP_DISALLOW_BIND_ANON_DN;
1091
1092                                 } else if( strcasecmp( cargv[i], "bind_simple" ) == 0 ) {
1093                                         disallows |= SLAP_DISALLOW_BIND_SIMPLE;
1094
1095                                 } else if( strcasecmp( cargv[i], "bind_krbv4" ) == 0 ) {
1096                                         disallows |= SLAP_DISALLOW_BIND_KRBV4;
1097
1098                                 } else if( strcasecmp( cargv[i], "tls_authc" ) == 0 ) {
1099                                         disallows |= SLAP_DISALLOW_TLS_AUTHC;
1100
1101                                 } else if( strcasecmp( cargv[i], "none" ) != 0 ) {
1102 #ifdef NEW_LOGGING
1103                                         LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
1104                                                    "%s: line %d: unknownfeature %s in "
1105                                                    "\"disallow <features>\" line.\n",
1106                                                    fname, lineno ));
1107 #else
1108                                         Debug( LDAP_DEBUG_ANY,
1109                     "%s: line %d: unknown feature %s in \"disallow <features>\" line\n",
1110                                             fname, lineno, cargv[i] );
1111 #endif
1112
1113                                         return( 1 );
1114                                 }
1115                         }
1116
1117                         global_disallows = disallows;
1118
1119                 /* require these features */
1120                 } else if ( strcasecmp( cargv[0], "requires" ) == 0 ||
1121                         strcasecmp( cargv[0], "require" ) == 0 )
1122                 {
1123                         slap_mask_t     requires;
1124
1125                         if ( cargc < 2 ) {
1126 #ifdef NEW_LOGGING
1127                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
1128                                            "%s: line %d: missing feature(s) in "
1129                                            "\"require <features>\" line.\n", fname, lineno ));
1130 #else
1131                                 Debug( LDAP_DEBUG_ANY,
1132             "%s: line %d: missing feature(s) in \"require <features>\" line\n",
1133                                     fname, lineno, 0 );
1134 #endif
1135
1136                                 return( 1 );
1137                         }
1138
1139                         requires = 0;
1140
1141                         for( i=1; i < cargc; i++ ) {
1142                                 if( strcasecmp( cargv[i], "bind" ) == 0 ) {
1143                                         requires |= SLAP_REQUIRE_BIND;
1144
1145                                 } else if( strcasecmp( cargv[i], "LDAPv3" ) == 0 ) {
1146                                         requires |= SLAP_REQUIRE_LDAP_V3;
1147
1148                                 } else if( strcasecmp( cargv[i], "authc" ) == 0 ) {
1149                                         requires |= SLAP_REQUIRE_AUTHC;
1150
1151                                 } else if( strcasecmp( cargv[i], "SASL" ) == 0 ) {
1152                                         requires |= SLAP_REQUIRE_SASL;
1153
1154                                 } else if( strcasecmp( cargv[i], "strong" ) == 0 ) {
1155                                         requires |= SLAP_REQUIRE_STRONG;
1156
1157                                 } else if( strcasecmp( cargv[i], "none" ) != 0 ) {
1158 #ifdef NEW_LOGGING
1159                                         LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
1160                                                    "%s: line %d: unknown feature %s in "
1161                                                    "\"require <features>\" line.\n",
1162                                                    fname, lineno ));
1163 #else
1164                                         Debug( LDAP_DEBUG_ANY,
1165                     "%s: line %d: unknown feature %s in \"require <features>\" line\n",
1166                                             fname, lineno, cargv[i] );
1167 #endif
1168
1169                                         return( 1 );
1170                                 }
1171                         }
1172
1173                         if ( be == NULL ) {
1174                                 global_requires = requires;
1175                         } else {
1176                                 be->be_requires = requires;
1177                         }
1178
1179                 /* required security factors */
1180                 } else if ( strcasecmp( cargv[0], "security" ) == 0 ) {
1181                         slap_ssf_set_t *set;
1182
1183                         if ( cargc < 2 ) {
1184 #ifdef NEW_LOGGING
1185                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
1186                                            "%s: line %d: missing factor(s) in \"security <factors>\""
1187                                            " line.\n", fname, lineno ));
1188 #else
1189                                 Debug( LDAP_DEBUG_ANY,
1190             "%s: line %d: missing factor(s) in \"security <factors>\" line\n",
1191                                     fname, lineno, 0 );
1192 #endif
1193
1194                                 return( 1 );
1195                         }
1196
1197                         if ( be == NULL ) {
1198                                 set = &global_ssf_set;
1199                         } else {
1200                                 set = &be->be_ssf_set;
1201                         }
1202
1203                         for( i=1; i < cargc; i++ ) {
1204                                 if( strncasecmp( cargv[i], "ssf=",
1205                                         sizeof("ssf") ) == 0 )
1206                                 {
1207                                         set->sss_ssf =
1208                                                 atoi( &cargv[i][sizeof("ssf")] );
1209
1210                                 } else if( strncasecmp( cargv[i], "transport=",
1211                                         sizeof("transport") ) == 0 )
1212                                 {
1213                                         set->sss_transport =
1214                                                 atoi( &cargv[i][sizeof("transport")] );
1215
1216                                 } else if( strncasecmp( cargv[i], "tls=",
1217                                         sizeof("tls") ) == 0 )
1218                                 {
1219                                         set->sss_tls =
1220                                                 atoi( &cargv[i][sizeof("tls")] );
1221
1222                                 } else if( strncasecmp( cargv[i], "sasl=",
1223                                         sizeof("sasl") ) == 0 )
1224                                 {
1225                                         set->sss_sasl =
1226                                                 atoi( &cargv[i][sizeof("sasl")] );
1227
1228                                 } else if( strncasecmp( cargv[i], "update_ssf=",
1229                                         sizeof("update_ssf") ) == 0 )
1230                                 {
1231                                         set->sss_update_ssf =
1232                                                 atoi( &cargv[i][sizeof("update_ssf")] );
1233
1234                                 } else if( strncasecmp( cargv[i], "update_transport=",
1235                                         sizeof("update_transport") ) == 0 )
1236                                 {
1237                                         set->sss_update_transport =
1238                                                 atoi( &cargv[i][sizeof("update_transport")] );
1239
1240                                 } else if( strncasecmp( cargv[i], "update_tls=",
1241                                         sizeof("update_tls") ) == 0 )
1242                                 {
1243                                         set->sss_update_tls =
1244                                                 atoi( &cargv[i][sizeof("update_tls")] );
1245
1246                                 } else if( strncasecmp( cargv[i], "update_sasl=",
1247                                         sizeof("update_sasl") ) == 0 )
1248                                 {
1249                                         set->sss_update_sasl =
1250                                                 atoi( &cargv[i][sizeof("update_sasl")] );
1251
1252                                 } else {
1253 #ifdef NEW_LOGGING
1254                                         LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
1255                                                    "%s: line %d: unknown factor %S in "
1256                                                    "\"security <factors>\" line.\n",
1257                                                    fname, lineno, cargv[1] ));
1258 #else
1259                                         Debug( LDAP_DEBUG_ANY,
1260                     "%s: line %d: unknown factor %s in \"security <factors>\" line\n",
1261                                             fname, lineno, cargv[i] );
1262 #endif
1263
1264                                         return( 1 );
1265                                 }
1266                         }
1267                 /* where to send clients when we don't hold it */
1268                 } else if ( strcasecmp( cargv[0], "referral" ) == 0 ) {
1269                         if ( cargc < 2 ) {
1270 #ifdef NEW_LOGGING
1271                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
1272                                            "%s: line %d: missing URL in \"referral <URL>\""
1273                                            " line.\n", fname, lineno ));
1274 #else
1275                                 Debug( LDAP_DEBUG_ANY,
1276                     "%s: line %d: missing URL in \"referral <URL>\" line\n",
1277                                     fname, lineno, 0 );
1278 #endif
1279
1280                                 return( 1 );
1281                         }
1282
1283                         vals[0]->bv_val = cargv[1];
1284                         vals[0]->bv_len = strlen( vals[0]->bv_val );
1285                         value_add( &default_referral, vals );
1286
1287 #ifdef NEW_LOGGING
1288                 } else if ( strcasecmp( cargv[0], "logfile" ) == 0 ) {
1289                         FILE *logfile;
1290                         if ( cargc < 2 ) {
1291 #ifdef NEW_LOGGING
1292                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
1293                                            "%s: line %d: Error in logfile directive, "
1294                                            "\"logfile <filename>\"\n", fname, lineno ));
1295 #else
1296                                 Debug( LDAP_DEBUG_ANY,
1297                                        "%s: line %d: Error in logfile directive, \"logfile filename\"\n",
1298                                        fname, lineno, 0 );
1299 #endif
1300
1301                                 return( 1 );
1302                         }
1303                         logfile = fopen( cargv[1], "w" );
1304                         if ( logfile != NULL ) lutil_debug_file( logfile );
1305
1306 #endif
1307                 /* start of a new database definition */
1308                 } else if ( strcasecmp( cargv[0], "debug" ) == 0 ) {
1309                         int level;
1310                         if ( cargc < 3 ) {
1311 #ifdef NEW_LOGGING
1312                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
1313                                            "%s: line %d: Error in debug directive, "
1314                                            "\"debug <subsys> <level>\"\n", fname, lineno ));
1315 #else
1316                                 Debug( LDAP_DEBUG_ANY,
1317                                         "%s: line %d: Error in debug directive, \"debug subsys level\"\n",
1318                                         fname, lineno, 0 );
1319 #endif
1320
1321                                 return( 1 );
1322                         }
1323                         level = atoi( cargv[2] );
1324                         if ( level <= 0 ) level = lutil_mnem2level( cargv[2] );
1325                         lutil_set_debug_level( cargv[1], level );
1326                 /* specify an Object Identifier macro */
1327                 } else if ( strcasecmp( cargv[0], "objectidentifier" ) == 0 ) {
1328                         parse_oidm( fname, lineno, cargc, cargv );
1329
1330                 /* specify an objectclass */
1331                 } else if ( strcasecmp( cargv[0], "objectclass" ) == 0 ) {
1332                         if ( *cargv[1] == '(' ) {
1333                                 char * p;
1334                                 p = strchr(saveline,'(');
1335                                 parse_oc( fname, lineno, p, cargv );
1336                         } else {
1337 #ifdef NEW_LOGGING
1338                                 LDAP_LOG(( "config", LDAP_LEVEL_INFO,
1339                                            "%s: line %d: old objectclass format not supported\n",
1340                                            fname, lineno ));
1341 #else
1342                                 Debug( LDAP_DEBUG_ANY,
1343                                        "%s: line %d: old objectclass format not supported.\n",
1344                                        fname, lineno, 0 );
1345 #endif
1346
1347                         }
1348
1349                 /* specify an attribute type */
1350                 } else if (( strcasecmp( cargv[0], "attributetype" ) == 0 )
1351                         || ( strcasecmp( cargv[0], "attribute" ) == 0 ))
1352                 {
1353                         if ( *cargv[1] == '(' ) {
1354                                 char * p;
1355                                 p = strchr(saveline,'(');
1356                                 parse_at( fname, lineno, p, cargv );
1357                         } else {
1358 #ifdef NEW_LOGGING
1359                                 LDAP_LOG(( "config", LDAP_LEVEL_INFO,
1360                                            "%s: line %d: old attribute type format not supported.\n",
1361                                            fname, lineno ));
1362 #else
1363                                 Debug( LDAP_DEBUG_ANY,
1364     "%s: line %d: old attribute type format not supported.\n",
1365                                     fname, lineno, 0 );
1366 #endif
1367
1368                         }
1369
1370                 /* turn on/off schema checking */
1371                 } else if ( strcasecmp( cargv[0], "schemacheck" ) == 0 ) {
1372                         if ( cargc < 2 ) {
1373 #ifdef NEW_LOGGING
1374                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
1375                                            "%s: line %d: missing on|off in "
1376                                            "\"schemacheck <on|off>\" line.\n",
1377                                            fname, lineno ));
1378 #else
1379                                 Debug( LDAP_DEBUG_ANY,
1380     "%s: line %d: missing on|off in \"schemacheck <on|off>\" line\n",
1381                                     fname, lineno, 0 );
1382 #endif
1383
1384                                 return( 1 );
1385                         }
1386                         if ( strcasecmp( cargv[1], "off" ) == 0 ) {
1387                                 global_schemacheck = 0;
1388                         } else {
1389                                 global_schemacheck = 1;
1390                         }
1391
1392                 /* specify access control info */
1393                 } else if ( strcasecmp( cargv[0], "access" ) == 0 ) {
1394                         parse_acl( be, fname, lineno, cargc, cargv );
1395
1396                 /* debug level to log things to syslog */
1397                 } else if ( strcasecmp( cargv[0], "loglevel" ) == 0 ) {
1398                         if ( cargc < 2 ) {
1399 #ifdef NEW_LOGGING
1400                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
1401                                            "%s: line %d: missing level in \"loglevel <level>\""
1402                                            " line.\n", fname, lineno ));
1403 #else
1404                                 Debug( LDAP_DEBUG_ANY,
1405                     "%s: line %d: missing level in \"loglevel <level>\" line\n",
1406                                     fname, lineno, 0 );
1407 #endif
1408
1409                                 return( 1 );
1410                         }
1411
1412                         ldap_syslog = 0;
1413
1414                         for( i=1; i < cargc; i++ ) {
1415                                 ldap_syslog += atoi( cargv[1] );
1416                         }
1417
1418                 /* list of replicas of the data in this backend (master only) */
1419                 } else if ( strcasecmp( cargv[0], "replica" ) == 0 ) {
1420                         if ( cargc < 2 ) {
1421 #ifdef NEW_LOGGING
1422                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
1423                                            "%s: line %d: missing host in \"replica "
1424                                            " <host[:port]\" line\n", fname, lineno ));
1425 #else
1426                                 Debug( LDAP_DEBUG_ANY,
1427             "%s: line %d: missing host in \"replica <host[:port]>\" line\n",
1428                                     fname, lineno, 0 );
1429 #endif
1430
1431                                 return( 1 );
1432                         }
1433                         if ( be == NULL ) {
1434 #ifdef NEW_LOGGING
1435                                 LDAP_LOG(( "config", LDAP_LEVEL_INFO,
1436                                            "%s: line %d: replica line must appear inside "
1437                                            "a database definition (ignored).\n", fname, lineno ));
1438 #else
1439                                 Debug( LDAP_DEBUG_ANY,
1440 "%s: line %d: replica line must appear inside a database definition (ignored)\n",
1441                                     fname, lineno, 0 );
1442 #endif
1443
1444                         } else {
1445                                 for ( i = 1; i < cargc; i++ ) {
1446                                         if ( strncasecmp( cargv[i], "host=", 5 )
1447                                             == 0 ) {
1448                                                 charray_add( &be->be_replica,
1449                                                              cargv[i] + 5 );
1450                                                 break;
1451                                         }
1452                                 }
1453                                 if ( i == cargc ) {
1454 #ifdef NEW_LOGGING
1455                                         LDAP_LOG(( "config", LDAP_LEVEL_INFO,
1456                                                    "%s: line %d: missing host in \"replica\" "
1457                                                    "line (ignored)\n", fname, lineno ));
1458 #else
1459                                         Debug( LDAP_DEBUG_ANY,
1460                     "%s: line %d: missing host in \"replica\" line (ignored)\n",
1461                                             fname, lineno, 0 );
1462 #endif
1463
1464                                 }
1465                         }
1466
1467                 /* dn of master entity allowed to write to replica */
1468                 } else if ( strcasecmp( cargv[0], "updatedn" ) == 0 ) {
1469                         if ( cargc < 2 ) {
1470 #ifdef NEW_LOGGING
1471                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
1472                                            "%s: line %d: missing dn in \"updatedn <dn>\""
1473                                            " line.\n", fname, lineno ));
1474 #else
1475                                 Debug( LDAP_DEBUG_ANY,
1476                     "%s: line %d: missing dn in \"updatedn <dn>\" line\n",
1477                                     fname, lineno, 0 );
1478 #endif
1479
1480                                 return( 1 );
1481                         }
1482                         if ( be == NULL ) {
1483 #ifdef NEW_LOGGING
1484                                 LDAP_LOG(( "config", LDAP_LEVEL_INFO,
1485                                            "%s: line %d: updatedn line must appear inside "
1486                                            "a database definition (ignored)\n",
1487                                            fname, lineno ));
1488 #else
1489                                 Debug( LDAP_DEBUG_ANY,
1490 "%s: line %d: updatedn line must appear inside a database definition (ignored)\n",
1491                                     fname, lineno, 0 );
1492 #endif
1493
1494                         } else {
1495                                 be->be_update_ndn = ch_strdup( cargv[1] );
1496                                 if ( load_ucdata( NULL ) < 0 ) {
1497                                         return( 1 );
1498                                 }
1499                                 if( dn_normalize( be->be_update_ndn ) == NULL ) {
1500 #ifdef NEW_LOGGING
1501                                         LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
1502                                                    "%s: line %d: updatedn DN is invalid.\n",
1503                                                    fname, lineno ));
1504 #else
1505                                         Debug( LDAP_DEBUG_ANY,
1506 "%s: line %d: updatedn DN is invalid\n",
1507                                             fname, lineno, 0 );
1508 #endif
1509
1510                                         return 1;
1511                                 }
1512                         }
1513
1514                 } else if ( strcasecmp( cargv[0], "updateref" ) == 0 ) {
1515                         if ( cargc < 2 ) {
1516 #ifdef NEW_LOGGING
1517                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
1518                                            "%s: line %d: missing dn in \"updateref <ldapurl>\" "
1519                                            "line.\n", fname, lineno ));
1520 #else
1521                                 Debug( LDAP_DEBUG_ANY,
1522                     "%s: line %d: missing dn in \"updateref <ldapurl>\" line\n",
1523                                     fname, lineno, 0 );
1524 #endif
1525
1526                                 return( 1 );
1527                         }
1528                         if ( be == NULL ) {
1529 #ifdef NEW_LOGGING
1530                                 LDAP_LOG(( "config", LDAP_LEVEL_INFO,
1531                                            "%s: line %d: updateref line must appear inside "
1532                                            "a database definition (ignored)\n", fname, lineno ));
1533 #else
1534                                 Debug( LDAP_DEBUG_ANY,
1535 "%s: line %d: updateref line must appear inside a database definition (ignored)\n",
1536                                     fname, lineno, 0 );
1537 #endif
1538
1539                         } else if ( be->be_update_ndn == NULL ) {
1540 #ifdef NEW_LOGGING
1541                                 LDAP_LOG(( "config", LDAP_LEVEL_INFO,
1542                                            "%s: line %d: updateref line must come after updatedn "
1543                                            "(ignored).\n", fname, lineno ));
1544 #else
1545                                 Debug( LDAP_DEBUG_ANY,
1546 "%s: line %d: updateref line must after updatedn (ignored)\n",
1547                                     fname, lineno, 0 );
1548 #endif
1549
1550                         } else {
1551                                 vals[0]->bv_val = cargv[1];
1552                                 vals[0]->bv_len = strlen( vals[0]->bv_val );
1553                                 value_add( &be->be_update_refs, vals );
1554                         }
1555
1556                 /* replication log file to which changes are appended */
1557                 } else if ( strcasecmp( cargv[0], "replogfile" ) == 0 ) {
1558                         if ( cargc < 2 ) {
1559 #ifdef NEW_LOGGING
1560                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
1561                                            "%s: line %d: missing filename in \"replogfile <filename>\""
1562                                            " line.\n", fname, lineno ));
1563 #else
1564                                 Debug( LDAP_DEBUG_ANY,
1565             "%s: line %d: missing dn in \"replogfile <filename>\" line\n",
1566                                     fname, lineno, 0 );
1567 #endif
1568
1569                                 return( 1 );
1570                         }
1571                         if ( be ) {
1572                                 be->be_replogfile = ch_strdup( cargv[1] );
1573                         } else {
1574                                 replogfile = ch_strdup( cargv[1] );
1575                         }
1576
1577                 /* maintain lastmodified{by,time} attributes */
1578                 } else if ( strcasecmp( cargv[0], "lastmod" ) == 0 ) {
1579                         if ( cargc < 2 ) {
1580 #ifdef NEW_LOGGING
1581                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
1582                                            "%s: line %d: missing on|off in \"lastmod <on|off>\""
1583                                            " line.\n", fname, lineno ));
1584 #else
1585                                 Debug( LDAP_DEBUG_ANY,
1586             "%s: line %d: missing on|off in \"lastmod <on|off>\" line\n",
1587                                     fname, lineno, 0 );
1588 #endif
1589
1590                                 return( 1 );
1591                         }
1592                         if ( strcasecmp( cargv[1], "on" ) == 0 ) {
1593                                 if ( be )
1594                                         be->be_lastmod = ON;
1595                                 else
1596                                         global_lastmod = ON;
1597                         } else {
1598                                 if ( be )
1599                                         be->be_lastmod = OFF;
1600                                 else
1601                                         global_lastmod = OFF;
1602                         }
1603
1604                 /* set idle timeout value */
1605                 } else if ( strcasecmp( cargv[0], "idletimeout" ) == 0 ) {
1606                         int i;
1607                         if ( cargc < 2 ) {
1608 #ifdef NEW_LOGGING
1609                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
1610                                            "%s: line %d: missing timeout value in "
1611                                            "\"idletimeout <seconds>\" line.\n", fname, lineno ));
1612 #else
1613                                 Debug( LDAP_DEBUG_ANY,
1614             "%s: line %d: missing timeout value in \"idletimeout <seconds>\" line\n",
1615                                     fname, lineno, 0 );
1616 #endif
1617
1618                                 return( 1 );
1619                         }
1620
1621                         i = atoi( cargv[1] );
1622
1623                         if( i < 0 ) {
1624 #ifdef NEW_LOGGING
1625                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
1626                                            "%s: line %d: timeout value (%d) invalid "
1627                                            "\"idletimeout <seconds>\" line.\n",
1628                                            fname, lineno, i ));
1629 #else
1630                                 Debug( LDAP_DEBUG_ANY,
1631             "%s: line %d: timeout value (%d) invalid \"idletimeout <seconds>\" line\n",
1632                                     fname, lineno, i );
1633 #endif
1634
1635                                 return( 1 );
1636                         }
1637
1638                         global_idletimeout = i;
1639
1640                 /* include another config file */
1641                 } else if ( strcasecmp( cargv[0], "include" ) == 0 ) {
1642                         if ( cargc < 2 ) {
1643 #ifdef NEW_LOGGING
1644                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
1645                                            "%s: line %d: missing filename in \"include "
1646                                            "<filename>\" line.\n", fname, lineno ));
1647 #else
1648                                 Debug( LDAP_DEBUG_ANY,
1649     "%s: line %d: missing filename in \"include <filename>\" line\n",
1650                                     fname, lineno, 0 );
1651 #endif
1652
1653                                 return( 1 );
1654                         }
1655                         savefname = ch_strdup( cargv[1] );
1656                         savelineno = lineno;
1657
1658                         if ( read_config( savefname ) != 0 ) {
1659                                 return( 1 );
1660                         }
1661
1662                         free( savefname );
1663                         lineno = savelineno - 1;
1664
1665                 /* location of kerberos srvtab file */
1666                 } else if ( strcasecmp( cargv[0], "srvtab" ) == 0 ) {
1667                         if ( cargc < 2 ) {
1668 #ifdef NEW_LOGGING
1669                                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
1670                                            "%s: line %d: missing filename in \"srvtab "
1671                                            "<filename>\" line.\n", fname, lineno ));
1672 #else
1673                                 Debug( LDAP_DEBUG_ANY,
1674             "%s: line %d: missing filename in \"srvtab <filename>\" line\n",
1675                                     fname, lineno, 0 );
1676 #endif
1677
1678                                 return( 1 );
1679                         }
1680                         ldap_srvtab = ch_strdup( cargv[1] );
1681
1682 #ifdef SLAPD_MODULES
1683                 } else if (strcasecmp( cargv[0], "moduleload") == 0 ) {
1684                    if ( cargc < 2 ) {
1685 #ifdef NEW_LOGGING
1686                            LDAP_LOG(( "config", LDAP_LEVEL_INFO,
1687                                       "%s: line %d: missing filename in \"moduleload "
1688                                       "<filename>\" line.\n", fname, lineno ));
1689 #else
1690                       Debug( LDAP_DEBUG_ANY,
1691                              "%s: line %d: missing filename in \"moduleload <filename>\" line\n",
1692                              fname, lineno, 0 );
1693 #endif
1694
1695                       exit( EXIT_FAILURE );
1696                    }
1697                    if (module_load(cargv[1], cargc - 2, (cargc > 2) ? cargv + 2 : NULL)) {
1698 #ifdef NEW_LOGGING
1699                            LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
1700                                       "%s: line %d: failed to load or initialize module %s\n"<
1701                                       fname, lineno, cargv[1] ));
1702 #else
1703                       Debug( LDAP_DEBUG_ANY,
1704                              "%s: line %d: failed to load or initialize module %s\n",
1705                              fname, lineno, cargv[1]);
1706 #endif
1707
1708                       exit( EXIT_FAILURE );
1709                    }
1710                 } else if (strcasecmp( cargv[0], "modulepath") == 0 ) {
1711                    if ( cargc != 2 ) {
1712 #ifdef NEW_LOGGING
1713                            LDAP_LOG(( "config", LDAP_LEVEL_INFO,
1714                                       "%s: line %d: missing path in \"modulepath <path>\""
1715                                       " line\n", fname, lineno ));
1716 #else
1717                       Debug( LDAP_DEBUG_ANY,
1718                              "%s: line %d: missing path in \"modulepath <path>\" line\n",
1719                              fname, lineno, 0 );
1720 #endif
1721
1722                       exit( EXIT_FAILURE );
1723                    }
1724                    if (module_path( cargv[1] )) {
1725 #ifdef NEW_LOGGING
1726                            LDAP_LOG(( "cofig", LDAP_LEVEL_CRIT,
1727                                       "%s: line %d: failed to set module search path to %s.\n",
1728                                       fname, lineno, cargv[1] ));
1729 #else
1730                            Debug( LDAP_DEBUG_ANY,
1731                                   "%s: line %d: failed to set module search path to %s\n",
1732                                   fname, lineno, cargv[1]);
1733 #endif
1734
1735                       exit( EXIT_FAILURE );
1736                    }
1737                    
1738 #endif /*SLAPD_MODULES*/
1739
1740 #ifdef HAVE_TLS
1741                 } else if ( !strcasecmp( cargv[0], "TLSProtocol" ) ) {
1742                         rc = ldap_pvt_tls_set_option( NULL,
1743                                                       LDAP_OPT_X_TLS_PROTOCOL,
1744                                                       cargv[1] );
1745                         if ( rc )
1746                                 return rc;
1747
1748                 } else if ( !strcasecmp( cargv[0], "TLSCipherSuite" ) ) {
1749                         rc = ldap_pvt_tls_set_option( NULL,
1750                                                       LDAP_OPT_X_TLS_CIPHER_SUITE,
1751                                                       cargv[1] );
1752                         if ( rc )
1753                                 return rc;
1754
1755                 } else if ( !strcasecmp( cargv[0], "TLSCertificateFile" ) ) {
1756                         rc = ldap_pvt_tls_set_option( NULL,
1757                                                       LDAP_OPT_X_TLS_CERTFILE,
1758                                                       cargv[1] );
1759                         if ( rc )
1760                                 return rc;
1761
1762                 } else if ( !strcasecmp( cargv[0], "TLSCertificateKeyFile" ) ) {
1763                         rc = ldap_pvt_tls_set_option( NULL,
1764                                                       LDAP_OPT_X_TLS_KEYFILE,
1765                                                       cargv[1] );
1766                         if ( rc )
1767                                 return rc;
1768
1769                 } else if ( !strcasecmp( cargv[0], "TLSCACertificatePath" ) ) {
1770                         rc = ldap_pvt_tls_set_option( NULL,
1771                                                       LDAP_OPT_X_TLS_CACERTDIR,
1772                                                       cargv[1] );
1773                         if ( rc )
1774                                 return rc;
1775
1776                 } else if ( !strcasecmp( cargv[0], "TLSCACertificateFile" ) ) {
1777                         rc = ldap_pvt_tls_set_option( NULL,
1778                                                       LDAP_OPT_X_TLS_CACERTFILE,
1779                                                       cargv[1] );
1780                         if ( rc )
1781                                 return rc;
1782                 } else if ( !strcasecmp( cargv[0], "TLSVerifyClient" ) ) {
1783                         i = atoi(cargv[1]);
1784                         rc = ldap_pvt_tls_set_option( NULL,
1785                                                       LDAP_OPT_X_TLS_REQUIRE_CERT,
1786                                                       &i );
1787                         if ( rc )
1788                                 return rc;
1789
1790 #endif
1791
1792                 /* pass anything else to the current backend info/db config routine */
1793                 } else {
1794                         if ( bi != NULL ) {
1795                                 if ( bi->bi_config == 0 ) {
1796 #ifdef NEW_LOGGING
1797                                         LDAP_LOG(( "config", LDAP_LEVEL_INFO,
1798                                                    "%s: line %d: unknown directive \"%s\" inside "
1799                                                    "backend info definition (ignored).\n",
1800                                                    fname, lineno, cargv[0] ));
1801 #else
1802                                         Debug( LDAP_DEBUG_ANY,
1803 "%s: line %d: unknown directive \"%s\" inside backend info definition (ignored)\n",
1804                                                 fname, lineno, cargv[0] );
1805 #endif
1806
1807                                 } else {
1808                                         if ( (*bi->bi_config)( bi, fname, lineno, cargc, cargv )
1809                                                 != 0 )
1810                                         {
1811                                                 return( 1 );
1812                                         }
1813                                 }
1814                         } else if ( be != NULL ) {
1815                                 if ( be->be_config == 0 ) {
1816 #ifdef NEW_LOGGING
1817                                         LDAP_LOG(( "config", LDAP_LEVEL_INFO,
1818                                                    "%s: line %d: uknown directive \"%s\" inside "
1819                                                    "backend database definition (ignored).\n",
1820                                                    fname, lineno, cargv[0] ));
1821 #else
1822                                         Debug( LDAP_DEBUG_ANY,
1823 "%s: line %d: unknown directive \"%s\" inside backend database definition (ignored)\n",
1824                                         fname, lineno, cargv[0] );
1825 #endif
1826
1827                                 } else {
1828                                         if ( (*be->be_config)( be, fname, lineno, cargc, cargv )
1829                                                 != 0 )
1830                                         {
1831                                                 return( 1 );
1832                                         }
1833                                 }
1834                         } else {
1835 #ifdef NEW_LOGGING
1836                                 LDAP_LOG(( "config", LDAP_LEVEL_INFO,
1837                                            "%s: line %d: unknown directive \"%s\" outside backend "
1838                                            "info and database definitions (ignored).\n",
1839                                            fname, lineno, cargv[0] ));
1840 #else
1841                                 Debug( LDAP_DEBUG_ANY,
1842 "%s: line %d: unknown directive \"%s\" outside backend info and database definitions (ignored)\n",
1843                                     fname, lineno, cargv[0] );
1844 #endif
1845
1846                         }
1847                 }
1848                 free( saveline );
1849         }
1850         fclose( fp );
1851         if ( load_ucdata( NULL ) < 0 ) {
1852                 return( 1 );
1853         }
1854         return( 0 );
1855 }
1856
1857 static int
1858 fp_parse_line(
1859     char        *line,
1860     int         *argcp,
1861     char        **argv
1862 )
1863 {
1864         char *  token;
1865
1866         *argcp = 0;
1867         for ( token = strtok_quote( line, " \t" ); token != NULL;
1868             token = strtok_quote( NULL, " \t" ) ) {
1869                 if ( *argcp == MAXARGS ) {
1870 #ifdef NEW_LOGGING
1871                         LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
1872                                    "fp_parse_line: too many tokens (%d max).\n",
1873                                    MAXARGS ));
1874 #else
1875                         Debug( LDAP_DEBUG_ANY, "Too many tokens (max %d)\n",
1876                             MAXARGS, 0, 0 );
1877 #endif
1878
1879                         return( 1 );
1880                 }
1881                 argv[(*argcp)++] = token;
1882         }
1883         argv[*argcp] = NULL;
1884         return 0;
1885 }
1886
1887 static char *
1888 strtok_quote( char *line, char *sep )
1889 {
1890         int             inquote;
1891         char            *tmp;
1892         static char     *next;
1893
1894         if ( line != NULL ) {
1895                 next = line;
1896         }
1897         while ( *next && strchr( sep, *next ) ) {
1898                 next++;
1899         }
1900
1901         if ( *next == '\0' ) {
1902                 next = NULL;
1903                 return( NULL );
1904         }
1905         tmp = next;
1906
1907         for ( inquote = 0; *next; ) {
1908                 switch ( *next ) {
1909                 case '"':
1910                         if ( inquote ) {
1911                                 inquote = 0;
1912                         } else {
1913                                 inquote = 1;
1914                         }
1915                         AC_MEMCPY( next, next + 1, strlen( next + 1 ) + 1 );
1916                         break;
1917
1918                 case '\\':
1919                         if ( next[1] )
1920                                 AC_MEMCPY( next,
1921                                             next + 1, strlen( next + 1 ) + 1 );
1922                         next++;         /* dont parse the escaped character */
1923                         break;
1924
1925                 default:
1926                         if ( ! inquote ) {
1927                                 if ( strchr( sep, *next ) != NULL ) {
1928                                         *next++ = '\0';
1929                                         return( tmp );
1930                                 }
1931                         }
1932                         next++;
1933                         break;
1934                 }
1935         }
1936
1937         return( tmp );
1938 }
1939
1940 static char     buf[BUFSIZ];
1941 static char     *line;
1942 static int      lmax, lcur;
1943
1944 #define CATLINE( buf )  { \
1945         int     len; \
1946         len = strlen( buf ); \
1947         while ( lcur + len + 1 > lmax ) { \
1948                 lmax += BUFSIZ; \
1949                 line = (char *) ch_realloc( line, lmax ); \
1950         } \
1951         strcpy( line + lcur, buf ); \
1952         lcur += len; \
1953 }
1954
1955 static char *
1956 fp_getline( FILE *fp, int *lineno )
1957 {
1958         char            *p;
1959
1960         lcur = 0;
1961         CATLINE( buf );
1962         (*lineno)++;
1963
1964         /* hack attack - keeps us from having to keep a stack of bufs... */
1965         if ( strncasecmp( line, "include", 7 ) == 0 ) {
1966                 buf[0] = '\0';
1967                 return( line );
1968         }
1969
1970         while ( fgets( buf, sizeof(buf), fp ) != NULL ) {
1971                 if ( (p = strchr( buf, '\n' )) != NULL ) {
1972                         *p = '\0';
1973                 }
1974                 if ( ! isspace( (unsigned char) buf[0] ) ) {
1975                         return( line );
1976                 }
1977
1978                 CATLINE( buf );
1979                 (*lineno)++;
1980         }
1981         buf[0] = '\0';
1982
1983         return( line[0] ? line : NULL );
1984 }
1985
1986 static void
1987 fp_getline_init( int *lineno )
1988 {
1989         *lineno = -1;
1990         buf[0] = '\0';
1991 }
1992
1993 /* Loads ucdata, returns 1 if loading, 0 if already loaded, -1 on error */
1994 static int
1995 load_ucdata( char *path )
1996 {
1997         static int loaded = 0;
1998         int err;
1999         
2000         if ( loaded ) {
2001                 return( 0 );
2002         }
2003         err = ucdata_load( path ? path : SLAPD_DEFAULT_UCDATA,
2004                            UCDATA_CASE|UCDATA_CTYPE|UCDATA_NUM );
2005         if ( err ) {
2006 #ifdef NEW_LOGGING
2007                 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
2008                            "load_ucdata: Error %d loading ucdata.\n", err ));
2009 #else
2010                 Debug( LDAP_DEBUG_ANY, "error loading ucdata (error %d)\n",
2011                        err, 0, 0 );
2012 #endif
2013
2014                 return( -1 );
2015         }
2016         loaded = 1;
2017         return( 1 );
2018 }