]> git.sur5r.net Git - openldap/blob - servers/slapd/config.c
3a9e7b4d61dd193ab94cb6132b3259d83c7f8c4e
[openldap] / servers / slapd / config.c
1 /* config.c - configuration file handling routines */
2
3 #include "portable.h"
4
5 #include <stdio.h>
6 #ifdef HAVE_LOCALE_H
7 #include <locale.h>
8 #endif
9
10 #include <ac/string.h>
11 #include <ac/ctype.h>
12 #include <ac/socket.h>
13
14 #include "ldap_defaults.h"
15 #include "slap.h"
16
17 #define MAXARGS 100
18
19 /*
20  * defaults for various global variables
21  */
22 int             defsize = SLAPD_DEFAULT_SIZELIMIT;
23 int             deftime = SLAPD_DEFAULT_TIMELIMIT;
24 AccessControl   *global_acl = NULL;
25 int             global_default_access = ACL_READ;
26 char            *replogfile;
27 int             global_lastmod;
28 int             global_idletimeout = 0;
29 char    *global_realm = NULL;
30 char            *ldap_srvtab = "";
31
32 char   *slapd_pid_file  = NULL;
33 char   *slapd_args_file = NULL;
34
35 static char     *fp_getline(FILE *fp, int *lineno);
36 static void     fp_getline_init(int *lineno);
37 static int      fp_parse_line(char *line, int *argcp, char **argv);
38
39 static char     *strtok_quote(char *line, char *sep);
40
41 int
42 read_config( char *fname )
43 {
44         FILE    *fp;
45         char    *line, *savefname, *saveline;
46         int     cargc, savelineno;
47         char    *cargv[MAXARGS];
48         int     lineno, i;
49 #ifdef HAVE_TLS
50         int rc;
51 #endif
52         struct berval *vals[2];
53         struct berval val;
54
55         static BackendInfo *bi = NULL;
56         static BackendDB        *be = NULL;
57
58         vals[0] = &val;
59         vals[1] = NULL;
60
61         if ( (fp = fopen( fname, "r" )) == NULL ) {
62                 ldap_syslog = 1;
63                 Debug( LDAP_DEBUG_ANY,
64                     "could not open config file \"%s\" - absolute path?\n",
65                     fname, 0, 0 );
66                 perror( fname );
67                 return 1;
68         }
69
70         Debug( LDAP_DEBUG_CONFIG, "reading config file %s\n", fname, 0, 0 );
71
72         if ( schema_init( ) != 0 ) {
73                 Debug( LDAP_DEBUG_ANY,
74                     "error initializing the schema\n",
75                     0, 0, 0 );
76                 return( 1 );
77         }
78
79         fp_getline_init( &lineno );
80
81         while ( (line = fp_getline( fp, &lineno )) != NULL ) {
82                 /* skip comments and blank lines */
83                 if ( line[0] == '#' || line[0] == '\0' ) {
84                         continue;
85                 }
86
87                 Debug( LDAP_DEBUG_CONFIG, "line %d (%s)\n", lineno, line, 0 );
88
89                 /* fp_parse_line is destructive, we save a copy */
90                 saveline = ch_strdup( line );
91
92                 if ( fp_parse_line( line, &cargc, cargv ) != 0 ) {
93                         return( 1 );
94                 }
95
96                 if ( cargc < 1 ) {
97                         Debug( LDAP_DEBUG_ANY,
98                             "%s: line %d: bad config line (ignored)\n",
99                             fname, lineno, 0 );
100                         continue;
101                 }
102
103                 if ( strcasecmp( cargv[0], "backend" ) == 0 ) {
104                         if ( cargc < 2 ) {
105                                 Debug( LDAP_DEBUG_ANY,
106                 "%s: line %d: missing type in \"backend <type>\" line\n",
107                                     fname, lineno, 0 );
108                                 return( 1 );
109                         }
110
111                         if( be != NULL ) {
112                                 Debug( LDAP_DEBUG_ANY,
113 "%s: line %d: backend line must appear before any database definition\n",
114                                     fname, lineno, 0 );
115                                 return( 1 );
116                         }
117
118                         bi = backend_info( cargv[1] );
119
120                 /* start of a new database definition */
121                 } else if ( strcasecmp( cargv[0], "database" ) == 0 ) {
122                         if ( cargc < 2 ) {
123                                 Debug( LDAP_DEBUG_ANY,
124                 "%s: line %d: missing type in \"database <type>\" line\n",
125                                     fname, lineno, 0 );
126                                 return( 1 );
127                         }
128                         bi = NULL;
129                         be = backend_db_init( cargv[1] );
130
131                 /* assign a default depth limit for alias deref */
132                 be->be_max_deref_depth = SLAPD_DEFAULT_MAXDEREFDEPTH; 
133
134                 /* get pid file name */
135                 } else if ( strcasecmp( cargv[0], "pidfile" ) == 0 ) {
136                         if ( cargc < 2 ) {
137                                 Debug( LDAP_DEBUG_ANY,
138             "%s: line %d: missing file name in \"pidfile <file>\" line\n",
139                                     fname, lineno, 0 );
140                                 return( 1 );
141                         }
142
143                         slapd_pid_file = ch_strdup( cargv[1] );
144
145                 /* get args file name */
146                 } else if ( strcasecmp( cargv[0], "argsfile" ) == 0 ) {
147                         if ( cargc < 2 ) {
148                                 Debug( LDAP_DEBUG_ANY,
149             "%s: line %d: missing file name in \"argsfile <file>\" line\n",
150                                     fname, lineno, 0 );
151                                 return( 1 );
152                         }
153
154                         slapd_args_file = ch_strdup( cargv[1] );
155
156                 /* set DIGEST realm */
157                 } else if ( strcasecmp( cargv[0], "digest-realm" ) == 0 ) {
158                         if ( cargc < 2 ) {
159                                 Debug( LDAP_DEBUG_ANY,
160             "%s: line %d: missing realm in \"digest-realm <realm>\" line\n",
161                                     fname, lineno, 0 );
162                                 return( 1 );
163                         }
164                         if ( be != NULL ) {
165                                 be->be_realm = ch_strdup( cargv[1] );
166
167                         } else if ( global_realm != NULL ) {
168                                 Debug( LDAP_DEBUG_ANY,
169                                         "%s: line %d: already set global realm!\n",
170                                         fname, lineno, 0 );
171                                 return 1;
172
173                         } else {
174                                 global_realm = ch_strdup( cargv[1] );
175                         }
176
177                 /* set time limit */
178                 } else if ( strcasecmp( cargv[0], "sizelimit" ) == 0 ) {
179                         if ( cargc < 2 ) {
180                                 Debug( LDAP_DEBUG_ANY,
181             "%s: line %d: missing limit in \"sizelimit <limit>\" line\n",
182                                     fname, lineno, 0 );
183                                 return( 1 );
184                         }
185                         if ( be == NULL ) {
186                                 defsize = atoi( cargv[1] );
187                         } else {
188                                 be->be_sizelimit = atoi( cargv[1] );
189                         }
190
191                 /* set time limit */
192                 } else if ( strcasecmp( cargv[0], "timelimit" ) == 0 ) {
193                         if ( cargc < 2 ) {
194                                 Debug( LDAP_DEBUG_ANY,
195             "%s: line %d: missing limit in \"timelimit <limit>\" line\n",
196                                     fname, lineno, 0 );
197                                 return( 1 );
198                         }
199                         if ( be == NULL ) {
200                                 deftime = atoi( cargv[1] );
201                         } else {
202                                 be->be_timelimit = atoi( cargv[1] );
203                         }
204
205                 /* set database suffix */
206                 } else if ( strcasecmp( cargv[0], "suffix" ) == 0 ) {
207                         if ( cargc < 2 ) {
208                                 Debug( LDAP_DEBUG_ANY,
209                     "%s: line %d: missing dn in \"suffix <dn>\" line\n",
210                                     fname, lineno, 0 );
211                                 return( 1 );
212                         } else if ( cargc > 2 ) {
213                                 Debug( LDAP_DEBUG_ANY,
214     "%s: line %d: extra cruft after <dn> in \"suffix %s\" line (ignored)\n",
215                                     fname, lineno, cargv[1] );
216                         }
217                         if ( be == NULL ) {
218                                 Debug( LDAP_DEBUG_ANY,
219 "%s: line %d: suffix line must appear inside a database definition (ignored)\n",
220                                     fname, lineno, 0 );
221                         } else {
222                                 char *dn = ch_strdup( cargv[1] );
223                                 (void) dn_normalize( dn );
224                                 charray_add( &be->be_suffix, dn );
225                                 (void) str2upper( dn );
226                                 charray_add( &be->be_nsuffix, dn );
227                                 free( dn );
228                         }
229
230                /* set max deref depth */
231                } else if ( strcasecmp( cargv[0], "maxDerefDepth" ) == 0 ) {
232                                         int i;
233                        if ( cargc < 2 ) {
234                                Debug( LDAP_DEBUG_ANY,
235                    "%s: line %d: missing depth in \"maxDerefDepth <depth>\" line\n",
236                                    fname, lineno, 0 );
237                                return( 1 );
238                        }
239                        if ( be == NULL ) {
240                                Debug( LDAP_DEBUG_ANY,
241 "%s: line %d: depth line must appear inside a database definition (ignored)\n",
242                                    fname, lineno, 0 );
243                        } else if ((i = atoi(cargv[1])) < 0) {
244                                Debug( LDAP_DEBUG_ANY,
245 "%s: line %d: depth must be positive (ignored)\n",
246                                    fname, lineno, 0 );
247
248                        } else {
249                            be->be_max_deref_depth = i;
250                                            }
251
252
253                 /* set magic "root" dn for this database */
254                 } else if ( strcasecmp( cargv[0], "rootdn" ) == 0 ) {
255                         if ( cargc < 2 ) {
256                                 Debug( LDAP_DEBUG_ANY,
257                     "%s: line %d: missing dn in \"rootdn <dn>\" line\n",
258                                     fname, lineno, 0 );
259                                 return( 1 );
260                         }
261                         if ( be == NULL ) {
262                                 Debug( LDAP_DEBUG_ANY,
263 "%s: line %d: rootdn line must appear inside a database definition (ignored)\n",
264                                     fname, lineno, 0 );
265                         } else {
266                                 be->be_root_dn = ch_strdup( cargv[1] );
267                                 be->be_root_ndn = dn_normalize_case( ch_strdup( cargv[1] ) );
268                         }
269
270                 /* set super-secret magic database password */
271                 } else if ( strcasecmp( cargv[0], "rootpw" ) == 0 ) {
272                         if ( cargc < 2 ) {
273                                 Debug( LDAP_DEBUG_ANY,
274             "%s: line %d: missing passwd in \"rootpw <passwd>\" line\n",
275                                     fname, lineno, 0 );
276                                 return( 1 );
277                         }
278                         if ( be == NULL ) {
279                                 Debug( LDAP_DEBUG_ANY,
280 "%s: line %d: rootpw line must appear inside a database definition (ignored)\n",
281                                     fname, lineno, 0 );
282                         } else {
283                                 be->be_root_pw = ch_strdup( cargv[1] );
284                         }
285
286                 /* make this database read-only */
287                 } else if ( strcasecmp( cargv[0], "readonly" ) == 0 ) {
288                         if ( cargc < 2 ) {
289                                 Debug( LDAP_DEBUG_ANY,
290             "%s: line %d: missing on|off in \"readonly <on|off>\" line\n",
291                                     fname, lineno, 0 );
292                                 return( 1 );
293                         }
294                         if ( be == NULL ) {
295                                 Debug( LDAP_DEBUG_ANY,
296 "%s: line %d: readonly line must appear inside a database definition (ignored)\n",
297                                     fname, lineno, 0 );
298                         } else {
299                                 if ( strcasecmp( cargv[1], "on" ) == 0 ) {
300                                         be->be_readonly = 1;
301                                 } else {
302                                         be->be_readonly = 0;
303                                 }
304                         }
305
306                 /* where to send clients when we don't hold it */
307                 } else if ( strcasecmp( cargv[0], "referral" ) == 0 ) {
308                         if ( cargc < 2 ) {
309                                 Debug( LDAP_DEBUG_ANY,
310                     "%s: line %d: missing URL in \"referral <URL>\" line\n",
311                                     fname, lineno, 0 );
312                                 return( 1 );
313                         }
314
315                         vals[0]->bv_val = cargv[1];
316                         vals[0]->bv_len = strlen( vals[0]->bv_val );
317                         value_add( &default_referral, vals );
318
319                 /* specify locale */
320                 } else if ( strcasecmp( cargv[0], "locale" ) == 0 ) {
321 #ifdef HAVE_LOCALE_H
322                         char *locale;
323                         if ( cargc < 2 ) {
324                                 Debug( LDAP_DEBUG_ANY,
325         "%s: line %d: missing locale in \"locale <name | on | off>\" line\n",
326                                        fname, lineno, 0 );
327                                 return( 1 );
328                         }
329
330                         locale = (strcasecmp(   cargv[1], "on"  ) == 0 ? ""
331                                   : strcasecmp( cargv[1], "off" ) == 0 ? "C"
332                                   : ch_strdup( cargv[1] )                    );
333
334                         if ( setlocale( LC_CTYPE, locale ) == 0 ) {
335                                 Debug( LDAP_DEBUG_ANY,
336                                        (*locale
337                                         ? "%s: line %d: bad locale \"%s\"\n"
338                                         : "%s: line %d: bad locale\n"),
339                                        fname, lineno, locale );
340                                 return( 1 );
341                         }
342 #else
343                         Debug( LDAP_DEBUG_ANY,
344                                "%s: line %d: \"locale\" unsupported\n",
345                                fname, lineno, 0 );
346                         return( 1 );
347 #endif
348                 /* specify an objectclass */
349                 } else if ( strcasecmp( cargv[0], "objectclass" ) == 0 ) {
350                         if ( *cargv[1] == '(' ) {
351                                 char * p;
352                                 p = strchr(saveline,'(');
353                                 parse_oc( fname, lineno, p );
354                         } else {
355                                 parse_oc_old( be, fname, lineno, cargc, cargv );
356                         }
357
358                 /* specify an attribute */
359                 } else if ( strcasecmp( cargv[0], "attribute" ) == 0 ) {
360                         if ( *cargv[1] == '(' ) {
361                                 char * p;
362                                 p = strchr(saveline,'(');
363                                 parse_at( fname, lineno, p );
364                         } else {
365                                 attr_syntax_config( fname, lineno, cargc - 1,
366                                     &cargv[1] );
367                         }
368
369                 /* turn on/off schema checking */
370                 } else if ( strcasecmp( cargv[0], "schemacheck" ) == 0 ) {
371                         if ( cargc < 2 ) {
372                                 Debug( LDAP_DEBUG_ANY,
373     "%s: line %d: missing on|off in \"schemacheck <on|off>\" line\n",
374                                     fname, lineno, 0 );
375                                 return( 1 );
376                         }
377                         if ( strcasecmp( cargv[1], "off" ) == 0 ) {
378                                 global_schemacheck = 0;
379                         } else {
380                                 global_schemacheck = 1;
381                         }
382
383                 /* specify access control info */
384                 } else if ( strcasecmp( cargv[0], "access" ) == 0 ) {
385                         parse_acl( be, fname, lineno, cargc, cargv );
386
387                 /* specify default access control info */
388                 } else if ( strcasecmp( cargv[0], "defaultaccess" ) == 0 ) {
389                         if ( cargc < 2 ) {
390                                 Debug( LDAP_DEBUG_ANY,
391             "%s: line %d: missing limit in \"defaultaccess <access>\" line\n",
392                                     fname, lineno, 0 );
393                                 return( 1 );
394                         }
395                         if ( be == NULL ) {
396                                 if ( ACL_IS_INVALID(ACL_SET(global_default_access,
397                                                 str2access(cargv[1]))) )
398                                 {
399                                         Debug( LDAP_DEBUG_ANY,
400 "%s: line %d: bad access \"%s\" expecting [self]{none|compare|read|write}\n",
401                                             fname, lineno, cargv[1] );
402                                         return( 1 );
403                                 }
404                         } else {
405                                 if ( ACL_IS_INVALID(ACL_SET(be->be_dfltaccess,
406                                                 str2access(cargv[1]))) )
407                                 {
408                                         Debug( LDAP_DEBUG_ANY,
409                                                 "%s: line %d: bad access \"%s\", "
410                                                 "expecting [self]{none|compare|search|read|write}\n",
411                                             fname, lineno, cargv[1] );
412                                         return( 1 );
413                                 }
414                         }
415
416                 /* debug level to log things to syslog */
417                 } else if ( strcasecmp( cargv[0], "loglevel" ) == 0 ) {
418                         if ( cargc < 2 ) {
419                                 Debug( LDAP_DEBUG_ANY,
420                     "%s: line %d: missing level in \"loglevel <level>\" line\n",
421                                     fname, lineno, 0 );
422                                 return( 1 );
423                         }
424                         ldap_syslog = atoi( cargv[1] );
425
426                 /* list of replicas of the data in this backend (master only) */
427                 } else if ( strcasecmp( cargv[0], "replica" ) == 0 ) {
428                         if ( cargc < 2 ) {
429                                 Debug( LDAP_DEBUG_ANY,
430             "%s: line %d: missing host in \"replica <host[:port]>\" line\n",
431                                     fname, lineno, 0 );
432                                 return( 1 );
433                         }
434                         if ( be == NULL ) {
435                                 Debug( LDAP_DEBUG_ANY,
436 "%s: line %d: replica line must appear inside a database definition (ignored)\n",
437                                     fname, lineno, 0 );
438                         } else {
439                                 for ( i = 1; i < cargc; i++ ) {
440                                         if ( strncasecmp( cargv[i], "host=", 5 )
441                                             == 0 ) {
442                                                 charray_add( &be->be_replica,
443                                                              cargv[i] + 5 );
444                                                 break;
445                                         }
446                                 }
447                                 if ( i == cargc ) {
448                                         Debug( LDAP_DEBUG_ANY,
449                     "%s: line %d: missing host in \"replica\" line (ignored)\n",
450                                             fname, lineno, 0 );
451                                 }
452                         }
453
454                 /* dn of master entity allowed to write to replica */
455                 } else if ( strcasecmp( cargv[0], "updatedn" ) == 0 ) {
456                         if ( cargc < 2 ) {
457                                 Debug( LDAP_DEBUG_ANY,
458                     "%s: line %d: missing dn in \"updatedn <dn>\" line\n",
459                                     fname, lineno, 0 );
460                                 return( 1 );
461                         }
462                         if ( be == NULL ) {
463                                 Debug( LDAP_DEBUG_ANY,
464 "%s: line %d: updatedn line must appear inside a database definition (ignored)\n",
465                                     fname, lineno, 0 );
466                         } else {
467                                 be->be_update_ndn = ch_strdup( cargv[1] );
468                                 (void) dn_normalize_case( be->be_update_ndn );
469                         }
470
471                 } else if ( strcasecmp( cargv[0], "updateref" ) == 0 ) {
472                         if ( cargc < 2 ) {
473                                 Debug( LDAP_DEBUG_ANY,
474                     "%s: line %d: missing dn in \"updateref <ldapurl>\" line\n",
475                                     fname, lineno, 0 );
476                                 return( 1 );
477                         }
478                         if ( be == NULL ) {
479                                 Debug( LDAP_DEBUG_ANY,
480 "%s: line %d: updateref line must appear inside a database definition (ignored)\n",
481                                     fname, lineno, 0 );
482                         } else if ( be->be_update_ndn == NULL ) {
483                                 Debug( LDAP_DEBUG_ANY,
484 "%s: line %d: updateref line must after updatedn (ignored)\n",
485                                     fname, lineno, 0 );
486                         } else {
487                                 vals[0]->bv_val = cargv[1];
488                                 vals[0]->bv_len = strlen( vals[0]->bv_val );
489                                 value_add( &be->be_update_refs, vals );
490                         }
491
492                 /* replication log file to which changes are appended */
493                 } else if ( strcasecmp( cargv[0], "replogfile" ) == 0 ) {
494                         if ( cargc < 2 ) {
495                                 Debug( LDAP_DEBUG_ANY,
496             "%s: line %d: missing dn in \"replogfile <filename>\" line\n",
497                                     fname, lineno, 0 );
498                                 return( 1 );
499                         }
500                         if ( be ) {
501                                 be->be_replogfile = ch_strdup( cargv[1] );
502                         } else {
503                                 replogfile = ch_strdup( cargv[1] );
504                         }
505
506                 /* maintain lastmodified{by,time} attributes */
507                 } else if ( strcasecmp( cargv[0], "lastmod" ) == 0 ) {
508                         if ( cargc < 2 ) {
509                                 Debug( LDAP_DEBUG_ANY,
510             "%s: line %d: missing on|off in \"lastmod <on|off>\" line\n",
511                                     fname, lineno, 0 );
512                                 return( 1 );
513                         }
514                         if ( strcasecmp( cargv[1], "on" ) == 0 ) {
515                                 if ( be )
516                                         be->be_lastmod = ON;
517                                 else
518                                         global_lastmod = ON;
519                         } else {
520                                 if ( be )
521                                         be->be_lastmod = OFF;
522                                 else
523                                         global_lastmod = OFF;
524                         }
525
526                 /* set idle timeout value */
527                 } else if ( strcasecmp( cargv[0], "idletimeout" ) == 0 ) {
528                         int i;
529                         if ( cargc < 2 ) {
530                                 Debug( LDAP_DEBUG_ANY,
531             "%s: line %d: missing timeout value in \"idletimeout <seconds>\" line\n",
532                                     fname, lineno, 0 );
533                                 return( 1 );
534                         }
535
536                         i = atoi( cargv[1] );
537
538                         if( i < 0 ) {
539                                 Debug( LDAP_DEBUG_ANY,
540             "%s: line %d: timeout value (%d) invalid \"idletimeout <seconds>\" line\n",
541                                     fname, lineno, i );
542                                 return( 1 );
543                         }
544
545                         global_idletimeout = i;
546
547                 /* include another config file */
548                 } else if ( strcasecmp( cargv[0], "include" ) == 0 ) {
549                         if ( cargc < 2 ) {
550                                 Debug( LDAP_DEBUG_ANY,
551     "%s: line %d: missing filename in \"include <filename>\" line\n",
552                                     fname, lineno, 0 );
553                                 return( 1 );
554                         }
555                         savefname = ch_strdup( cargv[1] );
556                         savelineno = lineno;
557
558                         if ( read_config( savefname ) != 0 ) {
559                                 return( 1 );
560                         }
561
562                         free( savefname );
563                         lineno = savelineno - 1;
564
565                 /* location of kerberos srvtab file */
566                 } else if ( strcasecmp( cargv[0], "srvtab" ) == 0 ) {
567                         if ( cargc < 2 ) {
568                                 Debug( LDAP_DEBUG_ANY,
569             "%s: line %d: missing filename in \"srvtab <filename>\" line\n",
570                                     fname, lineno, 0 );
571                                 return( 1 );
572                         }
573                         ldap_srvtab = ch_strdup( cargv[1] );
574
575 #ifdef SLAPD_MODULES
576                 } else if (strcasecmp( cargv[0], "loadmodule") == 0 ) {
577                    if ( cargc < 2 ) {
578                       Debug( LDAP_DEBUG_ANY,
579                              "%s: line %d: missing filename in \"loadmodule <filename>\" line\n",
580                              fname, lineno, 0 );
581                       exit( 1 );
582                    }
583                    if (!load_module(cargv[1], cargc - 2, (cargc > 2) ? cargv + 2 : NULL)) {
584                       Debug( LDAP_DEBUG_ANY,
585                              "%s: line %d: failed to load or initialize module %s\n",
586                              fname, lineno, cargv[1]);
587                       exit( 1 );
588                    }
589                    
590 #endif /*SLAPD_MODULES*/
591
592 #ifdef HAVE_TLS
593                 } else if ( !strcasecmp( cargv[0], "TLSProtocol" ) ) {
594                         rc = ldap_pvt_tls_set_option( NULL,
595                                                       LDAP_OPT_X_TLS_PROTOCOL,
596                                                       cargv[1] );
597                         if ( rc )
598                                 return rc;
599
600                 } else if ( !strcasecmp( cargv[0], "TLSCipherSuite" ) ) {
601                         rc = ldap_pvt_tls_set_option( NULL,
602                                                       LDAP_OPT_X_TLS_CIPHER_SUITE,
603                                                       cargv[1] );
604                         if ( rc )
605                                 return rc;
606
607                 } else if ( !strcasecmp( cargv[0], "TLSCertificateFile" ) ) {
608                         rc = ldap_pvt_tls_set_option( NULL,
609                                                       LDAP_OPT_X_TLS_CERTFILE,
610                                                       cargv[1] );
611                         if ( rc )
612                                 return rc;
613
614                 } else if ( !strcasecmp( cargv[0], "TLSCertificateKeyFile" ) ) {
615                         rc = ldap_pvt_tls_set_option( NULL,
616                                                       LDAP_OPT_X_TLS_KEYFILE,
617                                                       cargv[1] );
618                         if ( rc )
619                                 return rc;
620
621                 } else if ( !strcasecmp( cargv[0], "TLSCACertificatePath" ) ) {
622                         rc = ldap_pvt_tls_set_option( NULL,
623                                                       LDAP_OPT_X_TLS_CACERTDIR,
624                                                       cargv[1] );
625                         if ( rc )
626                                 return rc;
627
628                 } else if ( !strcasecmp( cargv[0], "TLSCACertificateFile" ) ) {
629                         rc = ldap_pvt_tls_set_option( NULL,
630                                                       LDAP_OPT_X_TLS_CACERTFILE,
631                                                       cargv[1] );
632                         if ( rc )
633                                 return rc;
634                 } else if ( !strcasecmp( cargv[0], "TLSVerifyClient" ) ) {
635                         rc = ldap_pvt_tls_set_option( NULL,
636                                                       LDAP_OPT_X_TLS_REQUIRE_CERT,
637                                                       cargv[1] );
638                         if ( rc )
639                                 return rc;
640
641 #endif
642
643                 /* pass anything else to the current backend info/db config routine */
644                 } else {
645                         if ( bi != NULL ) {
646                                 if ( bi->bi_config == 0 ) {
647                                         Debug( LDAP_DEBUG_ANY,
648 "%s: line %d: unknown directive \"%s\" inside backend info definition (ignored)\n",
649                                                 fname, lineno, cargv[0] );
650                                 } else {
651                                         if ( (*bi->bi_config)( bi, fname, lineno, cargc, cargv )
652                                                 != 0 )
653                                         {
654                                                 return( 1 );
655                                         }
656                                 }
657                         } else if ( be != NULL ) {
658                                 if ( be->be_config == 0 ) {
659                                         Debug( LDAP_DEBUG_ANY,
660 "%s: line %d: unknown directive \"%s\" inside backend database definition (ignored)\n",
661                                         fname, lineno, cargv[0] );
662                                 } else {
663                                         if ( (*be->be_config)( be, fname, lineno, cargc, cargv )
664                                                 != 0 )
665                                         {
666                                                 return( 1 );
667                                         }
668                                 }
669                         } else {
670                                 Debug( LDAP_DEBUG_ANY,
671 "%s: line %d: unknown directive \"%s\" outside backend info and database definitions (ignored)\n",
672                                     fname, lineno, cargv[0] );
673                         }
674                 }
675                 free( saveline );
676         }
677         fclose( fp );
678         return( 0 );
679 }
680
681 static int
682 fp_parse_line(
683     char        *line,
684     int         *argcp,
685     char        **argv
686 )
687 {
688         char *  token;
689
690         *argcp = 0;
691         for ( token = strtok_quote( line, " \t" ); token != NULL;
692             token = strtok_quote( NULL, " \t" ) ) {
693                 if ( *argcp == MAXARGS ) {
694                         Debug( LDAP_DEBUG_ANY, "Too many tokens (max %d)\n",
695                             MAXARGS, 0, 0 );
696                         return( 1 );
697                 }
698                 argv[(*argcp)++] = token;
699         }
700         argv[*argcp] = NULL;
701         return 0;
702 }
703
704 static char *
705 strtok_quote( char *line, char *sep )
706 {
707         int             inquote;
708         char            *tmp;
709         static char     *next;
710
711         if ( line != NULL ) {
712                 next = line;
713         }
714         while ( *next && strchr( sep, *next ) ) {
715                 next++;
716         }
717
718         if ( *next == '\0' ) {
719                 next = NULL;
720                 return( NULL );
721         }
722         tmp = next;
723
724         for ( inquote = 0; *next; ) {
725                 switch ( *next ) {
726                 case '"':
727                         if ( inquote ) {
728                                 inquote = 0;
729                         } else {
730                                 inquote = 1;
731                         }
732                         SAFEMEMCPY( next, next + 1, strlen( next + 1 ) + 1 );
733                         break;
734
735                 case '\\':
736                         if ( next[1] )
737                                 SAFEMEMCPY( next,
738                                             next + 1, strlen( next + 1 ) + 1 );
739                         next++;         /* dont parse the escaped character */
740                         break;
741
742                 default:
743                         if ( ! inquote ) {
744                                 if ( strchr( sep, *next ) != NULL ) {
745                                         *next++ = '\0';
746                                         return( tmp );
747                                 }
748                         }
749                         next++;
750                         break;
751                 }
752         }
753
754         return( tmp );
755 }
756
757 static char     buf[BUFSIZ];
758 static char     *line;
759 static int      lmax, lcur;
760
761 #define CATLINE( buf )  { \
762         int     len; \
763         len = strlen( buf ); \
764         while ( lcur + len + 1 > lmax ) { \
765                 lmax += BUFSIZ; \
766                 line = (char *) ch_realloc( line, lmax ); \
767         } \
768         strcpy( line + lcur, buf ); \
769         lcur += len; \
770 }
771
772 static char *
773 fp_getline( FILE *fp, int *lineno )
774 {
775         char            *p;
776
777         lcur = 0;
778         CATLINE( buf );
779         (*lineno)++;
780
781         /* hack attack - keeps us from having to keep a stack of bufs... */
782         if ( strncasecmp( line, "include", 7 ) == 0 ) {
783                 buf[0] = '\0';
784                 return( line );
785         }
786
787         while ( fgets( buf, sizeof(buf), fp ) != NULL ) {
788                 if ( (p = strchr( buf, '\n' )) != NULL ) {
789                         *p = '\0';
790                 }
791                 if ( ! isspace( (unsigned char) buf[0] ) ) {
792                         return( line );
793                 }
794
795                 CATLINE( buf );
796                 (*lineno)++;
797         }
798         buf[0] = '\0';
799
800         return( line[0] ? line : NULL );
801 }
802
803 static void
804 fp_getline_init( int *lineno )
805 {
806         *lineno = -1;
807         buf[0] = '\0';
808 }