]> git.sur5r.net Git - openldap/blob - servers/slapd/config.c
f73607314a73d3e8e066ed3cd05f94d83bf25b22
[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    *global_ucdata_path = NULL;
40 char            *ldap_srvtab = "";
41 char            *default_passwd_hash;
42 char            *default_search_base = NULL;
43 char            *default_search_nbase = NULL;
44
45 char   *slapd_pid_file  = NULL;
46 char   *slapd_args_file = NULL;
47
48 int nSaslRegexp = 0;
49 SaslRegexp_t *SaslRegexp = NULL;
50
51 static char     *fp_getline(FILE *fp, int *lineno);
52 static void     fp_getline_init(int *lineno);
53 static int      fp_parse_line(char *line, int *argcp, char **argv);
54
55 static char     *strtok_quote(char *line, char *sep);
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         Debug( LDAP_DEBUG_CONFIG, "reading config file %s\n", fname, 0, 0 );
87
88         fp_getline_init( &lineno );
89
90         while ( (line = fp_getline( fp, &lineno )) != NULL ) {
91                 /* skip comments and blank lines */
92                 if ( line[0] == '#' || line[0] == '\0' ) {
93                         continue;
94                 }
95
96                 Debug( LDAP_DEBUG_CONFIG, "line %d (%s)\n", lineno, line, 0 );
97
98                 /* fp_parse_line is destructive, we save a copy */
99                 saveline = ch_strdup( line );
100
101                 if ( fp_parse_line( line, &cargc, cargv ) != 0 ) {
102                         return( 1 );
103                 }
104
105                 if ( cargc < 1 ) {
106                         Debug( LDAP_DEBUG_ANY,
107                             "%s: line %d: bad config line (ignored)\n",
108                             fname, lineno, 0 );
109                         continue;
110                 }
111
112                 if ( strcasecmp( cargv[0], "backend" ) == 0 ) {
113                         if ( cargc < 2 ) {
114                                 Debug( LDAP_DEBUG_ANY,
115                 "%s: line %d: missing type in \"backend <type>\" line\n",
116                                     fname, lineno, 0 );
117                                 return( 1 );
118                         }
119
120                         if( be != NULL ) {
121                                 Debug( LDAP_DEBUG_ANY,
122 "%s: line %d: backend line must appear before any database definition\n",
123                                     fname, lineno, 0 );
124                                 return( 1 );
125                         }
126
127                         bi = backend_info( cargv[1] );
128
129                         if( bi == NULL ) {
130                                 Debug( LDAP_DEBUG_ANY,
131                                         "backend %s initialization failed.\n",
132                                     cargv[1], 0, 0 );
133                                 return( 1 );
134                         }
135
136                 /* start of a new database definition */
137                 } else if ( strcasecmp( cargv[0], "database" ) == 0 ) {
138                         if ( cargc < 2 ) {
139                                 Debug( LDAP_DEBUG_ANY,
140                 "%s: line %d: missing type in \"database <type>\" line\n",
141                                     fname, lineno, 0 );
142                                 return( 1 );
143                         }
144
145                         bi = NULL;
146                         be = backend_db_init( cargv[1] );
147
148                         if( be == NULL ) {
149                                 Debug( LDAP_DEBUG_ANY,
150                                         "database %s initialization failed.\n",
151                                     cargv[1], 0, 0 );
152                                 return( 1 );
153                         }
154
155                 /* set thread concurrency */
156                 } else if ( strcasecmp( cargv[0], "concurrency" ) == 0 ) {
157                         int c;
158                         if ( cargc < 2 ) {
159                                 Debug( LDAP_DEBUG_ANY,
160             "%s: line %d: missing level in \"concurrency <level>\" line\n",
161                                     fname, lineno, 0 );
162                                 return( 1 );
163                         }
164
165                         c = atoi( cargv[1] );
166
167                         if( c < 1 ) {
168                                 Debug( LDAP_DEBUG_ANY,
169             "%s: line %d: invalid level (%d) in \"concurrency <level>\" line\n",
170                                     fname, lineno, c );
171                                 return( 1 );
172                         }
173
174                         ldap_pvt_thread_set_concurrency( c );
175
176                 /* default search base */
177                 } else if ( strcasecmp( cargv[0], "defaultSearchBase" ) == 0 ) {
178                         if ( cargc < 2 ) {
179                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
180                                         "missing dn in \"defaultSearchBase <dn>\" line\n",
181                                         fname, lineno, 0 );
182                                 return 1;
183
184                         } else if ( cargc > 2 ) {
185                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
186                                         "extra cruft after <dn> in \"defaultSearchBase %s\", "
187                                         "line (ignored)\n",
188                                         fname, lineno, cargv[1] );
189                         }
190
191                         if ( bi != NULL || be != NULL ) {
192                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
193                                         "defaultSearchBaase line must appear prior to "
194                                         "any backend or database definition\n",
195                                     fname, lineno, 0 );
196                                 return 1;
197                         }
198
199                         if ( default_search_nbase != NULL ) {
200                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
201                                         "default search base \"%s\" already defined "
202                                         "(discarding old)\n",
203                                         fname, lineno, default_search_base );
204                                 free( default_search_base );
205                                 free( default_search_nbase );
206                         }
207
208                         default_search_base = ch_strdup( cargv[1] );
209                         default_search_nbase = ch_strdup( cargv[1] );
210
211                         if( dn_normalize( default_search_nbase ) == NULL ) {
212                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
213                                         "invalid default search base \"%s\"\n",
214                                         fname, lineno, default_search_base );
215                                 return 1;
216                         }
217                
218                 /* set maximum threads in thread pool */
219                 } else if ( strcasecmp( cargv[0], "threads" ) == 0 ) {
220                         int c;
221                         if ( cargc < 2 ) {
222                                 Debug( LDAP_DEBUG_ANY,
223             "%s: line %d: missing count in \"threads <count>\" line\n",
224                                     fname, lineno, 0 );
225                                 return( 1 );
226                         }
227
228                         c = atoi( cargv[1] );
229
230                         if( c < 0 ) {
231                                 Debug( LDAP_DEBUG_ANY,
232             "%s: line %d: invalid level (%d) in \"threads <count>\" line\n",
233                                     fname, lineno, c );
234                                 return( 1 );
235                         }
236
237                         ldap_pvt_thread_pool_maxthreads( &connection_pool, c );
238
239                 /* get pid file name */
240                 } else if ( strcasecmp( cargv[0], "pidfile" ) == 0 ) {
241                         if ( cargc < 2 ) {
242                                 Debug( LDAP_DEBUG_ANY,
243             "%s: line %d: missing file name in \"pidfile <file>\" line\n",
244                                     fname, lineno, 0 );
245                                 return( 1 );
246                         }
247
248                         slapd_pid_file = ch_strdup( cargv[1] );
249
250                 /* get args file name */
251                 } else if ( strcasecmp( cargv[0], "argsfile" ) == 0 ) {
252                         if ( cargc < 2 ) {
253                                 Debug( LDAP_DEBUG_ANY,
254             "%s: line %d: missing file name in \"argsfile <file>\" line\n",
255                                     fname, lineno, 0 );
256                                 return( 1 );
257                         }
258
259                         slapd_args_file = ch_strdup( cargv[1] );
260
261                 /* default password hash */
262                 } else if ( strcasecmp( cargv[0], "password-hash" ) == 0 ) {
263                         if ( cargc < 2 ) {
264                                 Debug( LDAP_DEBUG_ANY,
265             "%s: line %d: missing hash in \"password-hash <hash>\" line\n",
266                                     fname, lineno, 0 );
267                                 return( 1 );
268                         }
269                         if ( default_passwd_hash != NULL ) {
270                                 Debug( LDAP_DEBUG_ANY,
271                                         "%s: line %d: already set default password_hash!\n",
272                                         fname, lineno, 0 );
273                                 return 1;
274
275                         } else {
276                                 default_passwd_hash = ch_strdup( cargv[1] );
277                         }
278
279                 /* set SASL host */
280                 } else if ( strcasecmp( cargv[0], "sasl-host" ) == 0 ) {
281                         if ( cargc < 2 ) {
282                                 Debug( LDAP_DEBUG_ANY,
283             "%s: line %d: missing host in \"sasl-host <host>\" line\n",
284                                     fname, lineno, 0 );
285                                 return( 1 );
286                         }
287
288                         if ( global_host != NULL ) {
289                                 Debug( LDAP_DEBUG_ANY,
290                                         "%s: line %d: already set sasl-host!\n",
291                                         fname, lineno, 0 );
292                                 return 1;
293
294                         } else {
295                                 global_host = ch_strdup( cargv[1] );
296                         }
297
298                 /* set SASL realm */
299                 } else if ( strcasecmp( cargv[0], "sasl-realm" ) == 0 ) {
300                         if ( cargc < 2 ) {
301                                 Debug( LDAP_DEBUG_ANY,
302             "%s: line %d: missing realm in \"sasl-realm <realm>\" line\n",
303                                     fname, lineno, 0 );
304                                 return( 1 );
305                         }
306
307                         if ( global_realm != NULL ) {
308                                 Debug( LDAP_DEBUG_ANY,
309                                         "%s: line %d: already set sasl-realm!\n",
310                                         fname, lineno, 0 );
311                                 return 1;
312
313                         } else {
314                                 global_realm = ch_strdup( cargv[1] );
315                         }
316
317                 } else if ( !strcasecmp( cargv[0], "sasl-regexp" ) 
318                         || !strcasecmp( cargv[0], "saslregexp" ) )
319                 {
320                         int rc;
321                         if ( cargc != 3 ) {
322                                 Debug( LDAP_DEBUG_ANY, 
323                                 "%s: line %d: need 2 args in \"saslregexp <match> <replace>\"\n",
324                                     fname, lineno, 0 );
325                                 return( 1 );
326                         }
327                         rc = slap_sasl_regexp_config( cargv[1], cargv[2] );
328                         if ( rc ) {
329                                 return rc;
330                         }
331
332                 /* SASL security properties */
333                 } else if ( strcasecmp( cargv[0], "sasl-secprops" ) == 0 ) {
334                         char *txt;
335
336                         if ( cargc < 2 ) {
337                                 Debug( LDAP_DEBUG_ANY,
338             "%s: line %d: missing flags in \"sasl-secprops <properties>\" line\n",
339                                     fname, lineno, 0 );
340                                 return 1;
341                         }
342
343                         txt = slap_sasl_secprops( cargv[1] );
344                         if ( txt != NULL ) {
345                                 Debug( LDAP_DEBUG_ANY,
346             "%s: line %d: sasl-secprops: %s\n",
347                                     fname, lineno, txt );
348                                 return 1;
349                         }
350
351                 /* set UCDATA path */
352                 } else if ( strcasecmp( cargv[0], "ucdata-path" ) == 0 ) {
353                         if ( cargc < 2 ) {
354                                 Debug( LDAP_DEBUG_ANY,
355             "%s: line %d: missing path in \"ucdata-path <path>\" line\n",
356                                     fname, lineno, 0 );
357                                 return( 1 );
358                         }
359
360                         if ( global_ucdata_path != NULL ) {
361                                 Debug( LDAP_DEBUG_ANY,
362                                         "%s: line %d: already set ucdata-path!\n",
363                                         fname, lineno, 0 );
364                                 return 1;
365
366                         } else {
367                                 global_ucdata_path = ch_strdup( cargv[1] );
368                         }
369
370                 /* set time limit */
371                 } else if ( strcasecmp( cargv[0], "sizelimit" ) == 0 ) {
372                         if ( cargc < 2 ) {
373                                 Debug( LDAP_DEBUG_ANY,
374             "%s: line %d: missing limit in \"sizelimit <limit>\" line\n",
375                                     fname, lineno, 0 );
376                                 return( 1 );
377                         }
378                         if ( be == NULL ) {
379                                 defsize = atoi( cargv[1] );
380                         } else {
381                                 be->be_sizelimit = atoi( cargv[1] );
382                         }
383
384                 /* set time limit */
385                 } else if ( strcasecmp( cargv[0], "timelimit" ) == 0 ) {
386                         if ( cargc < 2 ) {
387                                 Debug( LDAP_DEBUG_ANY,
388             "%s: line %d: missing limit in \"timelimit <limit>\" line\n",
389                                     fname, lineno, 0 );
390                                 return( 1 );
391                         }
392                         if ( be == NULL ) {
393                                 deftime = atoi( cargv[1] );
394                         } else {
395                                 be->be_timelimit = atoi( cargv[1] );
396                         }
397
398                 /* set database suffix */
399                 } else if ( strcasecmp( cargv[0], "suffix" ) == 0 ) {
400                         Backend *tmp_be;
401                         if ( cargc < 2 ) {
402                                 Debug( LDAP_DEBUG_ANY,
403                     "%s: line %d: missing dn in \"suffix <dn>\" line\n",
404                                     fname, lineno, 0 );
405                                 return( 1 );
406                         } else if ( cargc > 2 ) {
407                                 Debug( LDAP_DEBUG_ANY,
408     "%s: line %d: extra cruft after <dn> in \"suffix %s\" line (ignored)\n",
409                                     fname, lineno, cargv[1] );
410                         }
411                         if ( be == NULL ) {
412                                 Debug( LDAP_DEBUG_ANY,
413 "%s: line %d: suffix line must appear inside a database definition (ignored)\n",
414                                     fname, lineno, 0 );
415                         } else if ( ( tmp_be = select_backend( cargv[1] ) ) == be ) {
416                                 Debug( LDAP_DEBUG_ANY,
417 "%s: line %d: suffix already served by this backend (ignored)\n",
418                                     fname, lineno, 0 );
419                         } else if ( tmp_be  != NULL ) {
420                                 Debug( LDAP_DEBUG_ANY,
421 "%s: line %d: suffix already served by a preceeding backend \"%s\" (ignored)\n",
422                                     fname, lineno, tmp_be->be_suffix[0] );
423                         } else {
424                                 char *dn = ch_strdup( cargv[1] );
425                                 if( dn_validate( dn ) == NULL ) {
426                                         Debug( LDAP_DEBUG_ANY, "%s: line %d: "
427                                                 "suffix DN invalid \"%s\"\n",
428                                         fname, lineno, cargv[1] );
429                                         return 1;
430
431                                 } else if( *dn == '\0' && default_search_nbase != NULL ) {
432                                         Debug( LDAP_DEBUG_ANY, "%s: line %d: "
433                                                 "suffix DN empty and default "
434                                                 "search base provided \"%s\" (assuming okay)\n",
435                                         fname, lineno, default_search_base );
436                                 }
437                                 charray_add( &be->be_suffix, dn );
438                                 (void) ldap_pvt_str2upper( dn );
439                                 charray_add( &be->be_nsuffix, dn );
440                                 free( dn );
441                         }
442
443                 /* set database suffixAlias */
444                 } else if ( strcasecmp( cargv[0], "suffixAlias" ) == 0 ) {
445                         Backend *tmp_be;
446                         if ( cargc < 2 ) {
447                                 Debug( LDAP_DEBUG_ANY,
448 "%s: line %d: missing alias and aliased_dn in \"suffixAlias <alias> <aliased_dn>\" line\n",
449                                         fname, lineno, 0 );
450                                 return( 1 );
451                         } else if ( cargc < 3 ) {
452                                 Debug( LDAP_DEBUG_ANY,
453 "%s: line %d: missing aliased_dn in \"suffixAlias <alias> <aliased_dn>\" line\n",
454                                 fname, lineno, 0 );
455                                 return( 1 );
456                         } else if ( cargc > 3 ) {
457                                 Debug( LDAP_DEBUG_ANY,
458                                         "%s: line %d: extra cruft in suffixAlias line (ignored)\n",
459                                 fname, lineno, 0 );
460                         }
461
462                         if ( be == NULL ) {
463                                 Debug( LDAP_DEBUG_ANY,
464                                         "%s: line %d: suffixAlias line"
465                                         " must appear inside a database definition (ignored)\n",
466                                         fname, lineno, 0 );
467                         } else if ( (tmp_be = select_backend( cargv[1] )) != NULL ) {
468                                 Debug( LDAP_DEBUG_ANY,
469                                         "%s: line %d: suffixAlias served by"
470                                         "  a preceeding backend \"%s\" (ignored)\n",
471                                         fname, lineno, tmp_be->be_suffix[0] );
472
473                         } else if ( (tmp_be = select_backend( cargv[2] )) != NULL ) {
474                                 Debug( LDAP_DEBUG_ANY,
475                                         "%s: line %d: suffixAlias derefs to differnet backend"
476                                         "  a preceeding backend \"%s\" (ignored)\n",
477                                         fname, lineno, tmp_be->be_suffix[0] );
478
479                         } else {
480                                 char *alias, *aliased_dn;
481
482                                 alias = ch_strdup( cargv[1] );
483                                 (void) dn_normalize( alias );
484
485                                 aliased_dn = ch_strdup( cargv[2] );
486                                 (void) dn_normalize( aliased_dn );
487
488                                 charray_add( &be->be_suffixAlias, alias );
489                                 charray_add( &be->be_suffixAlias, aliased_dn );
490
491                                 free(alias);
492                                 free(aliased_dn);
493                         }
494
495                /* set max deref depth */
496                } else if ( strcasecmp( cargv[0], "maxDerefDepth" ) == 0 ) {
497                                         int i;
498                        if ( cargc < 2 ) {
499                                Debug( LDAP_DEBUG_ANY,
500                    "%s: line %d: missing depth in \"maxDerefDepth <depth>\" line\n",
501                                    fname, lineno, 0 );
502                                return( 1 );
503                        }
504                        if ( be == NULL ) {
505                                Debug( LDAP_DEBUG_ANY,
506 "%s: line %d: depth line must appear inside a database definition (ignored)\n",
507                                    fname, lineno, 0 );
508                        } else if ((i = atoi(cargv[1])) < 0) {
509                                Debug( LDAP_DEBUG_ANY,
510 "%s: line %d: depth must be positive (ignored)\n",
511                                    fname, lineno, 0 );
512
513                        } else {
514                            be->be_max_deref_depth = i;
515                                            }
516
517
518                 /* set magic "root" dn for this database */
519                 } else if ( strcasecmp( cargv[0], "rootdn" ) == 0 ) {
520                         if ( cargc < 2 ) {
521                                 Debug( LDAP_DEBUG_ANY,
522                     "%s: line %d: missing dn in \"rootdn <dn>\" line\n",
523                                     fname, lineno, 0 );
524                                 return( 1 );
525                         }
526                         if ( be == NULL ) {
527                                 Debug( LDAP_DEBUG_ANY,
528 "%s: line %d: rootdn line must appear inside a database definition (ignored)\n",
529                                     fname, lineno, 0 );
530                         } else {
531                                 be->be_root_dn = ch_strdup( cargv[1] );
532                                 be->be_root_ndn = ch_strdup( cargv[1] );
533
534                                 if( dn_normalize( be->be_root_ndn ) == NULL ) {
535                                         free( be->be_root_dn );
536                                         free( be->be_root_ndn );
537                                         Debug( LDAP_DEBUG_ANY,
538 "%s: line %d: rootdn DN is invalid\n",
539                                            fname, lineno, 0 );
540                                         return( 1 );
541                                 }
542                         }
543
544                 /* set super-secret magic database password */
545                 } else if ( strcasecmp( cargv[0], "rootpw" ) == 0 ) {
546                         if ( cargc < 2 ) {
547                                 Debug( LDAP_DEBUG_ANY,
548             "%s: line %d: missing passwd in \"rootpw <passwd>\" line\n",
549                                     fname, lineno, 0 );
550                                 return( 1 );
551                         }
552                         if ( be == NULL ) {
553                                 Debug( LDAP_DEBUG_ANY,
554 "%s: line %d: rootpw line must appear inside a database definition (ignored)\n",
555                                     fname, lineno, 0 );
556                         } else {
557                                 be->be_root_pw.bv_val = ch_strdup( cargv[1] );
558                                 be->be_root_pw.bv_len = strlen( be->be_root_pw.bv_val );
559                         }
560
561                 /* make this database read-only */
562                 } else if ( strcasecmp( cargv[0], "readonly" ) == 0 ) {
563                         if ( cargc < 2 ) {
564                                 Debug( LDAP_DEBUG_ANY,
565             "%s: line %d: missing on|off in \"readonly <on|off>\" line\n",
566                                     fname, lineno, 0 );
567                                 return( 1 );
568                         }
569                         if ( be == NULL ) {
570                                 if ( strcasecmp( cargv[1], "on" ) == 0 ) {
571                                         global_restrictops |= SLAP_RESTRICT_OP_WRITES;
572                                 } else {
573                                         global_restrictops &= ~SLAP_RESTRICT_OP_WRITES;
574                                 }
575                         } else {
576                                 if ( strcasecmp( cargv[1], "on" ) == 0 ) {
577                                         be->be_restrictops |= SLAP_RESTRICT_OP_WRITES;
578                                 } else {
579                                         be->be_restrictops &= ~SLAP_RESTRICT_OP_WRITES;
580                                 }
581                         }
582
583
584                 /* allow these features */
585                 } else if ( strcasecmp( cargv[0], "allows" ) == 0 ||
586                         strcasecmp( cargv[0], "allow" ) == 0 )
587                 {
588                         slap_mask_t     allows;
589
590                         if ( be != NULL ) {
591                                 Debug( LDAP_DEBUG_ANY,
592 "%s: line %d: allow line must appear prior to database definitions\n",
593                                     fname, lineno, 0 );
594                         }
595
596                         if ( cargc < 2 ) {
597                                 Debug( LDAP_DEBUG_ANY,
598             "%s: line %d: missing feature(s) in \"allow <features>\" line\n",
599                                     fname, lineno, 0 );
600                                 return( 1 );
601                         }
602
603                         allows = 0;
604
605                         for( i=1; i < cargc; i++ ) {
606                                 if( strcasecmp( cargv[i], "tls_2_anon" ) == 0 ) {
607                                         allows |= SLAP_ALLOW_TLS_2_ANON;
608
609                                 } else if( strcasecmp( cargv[i], "none" ) != 0 ) {
610                                         Debug( LDAP_DEBUG_ANY,
611                     "%s: line %d: unknown feature %s in \"allow <features>\" line\n",
612                                             fname, lineno, cargv[i] );
613                                         return( 1 );
614                                 }
615                         }
616
617                         global_allows = allows;
618
619                 /* disallow these features */
620                 } else if ( strcasecmp( cargv[0], "disallows" ) == 0 ||
621                         strcasecmp( cargv[0], "disallow" ) == 0 )
622                 {
623                         slap_mask_t     disallows;
624
625                         if ( be != NULL ) {
626                                 Debug( LDAP_DEBUG_ANY,
627 "%s: line %d: disallow line must appear prior to database definitions\n",
628                                     fname, lineno, 0 );
629                         }
630
631                         if ( cargc < 2 ) {
632                                 Debug( LDAP_DEBUG_ANY,
633             "%s: line %d: missing feature(s) in \"disallow <features>\" line\n",
634                                     fname, lineno, 0 );
635                                 return( 1 );
636                         }
637
638                         disallows = 0;
639
640                         for( i=1; i < cargc; i++ ) {
641                                 if( strcasecmp( cargv[i], "bind_v2" ) == 0 ) {
642                                         disallows |= SLAP_DISALLOW_BIND_V2;
643
644                                 } else if( strcasecmp( cargv[i], "bind_anon" ) == 0 ) {
645                                         disallows |= SLAP_DISALLOW_BIND_ANON;
646
647                                 } else if( strcasecmp( cargv[i], "bind_anon_cred" ) == 0 ) {
648                                         disallows |= SLAP_DISALLOW_BIND_ANON_CRED;
649
650                                 } else if( strcasecmp( cargv[i], "bind_anon_dn" ) == 0 ) {
651                                         disallows |= SLAP_DISALLOW_BIND_ANON_DN;
652
653                                 } else if( strcasecmp( cargv[i], "bind_simple" ) == 0 ) {
654                                         disallows |= SLAP_DISALLOW_BIND_SIMPLE;
655
656                                 } else if( strcasecmp( cargv[i], "bind_krbv4" ) == 0 ) {
657                                         disallows |= SLAP_DISALLOW_BIND_KRBV4;
658
659                                 } else if( strcasecmp( cargv[i], "tls_authc" ) == 0 ) {
660                                         disallows |= SLAP_DISALLOW_TLS_AUTHC;
661
662                                 } else if( strcasecmp( cargv[i], "none" ) != 0 ) {
663                                         Debug( LDAP_DEBUG_ANY,
664                     "%s: line %d: unknown feature %s in \"disallow <features>\" line\n",
665                                             fname, lineno, cargv[i] );
666                                         return( 1 );
667                                 }
668                         }
669
670                         global_disallows = disallows;
671
672                 /* require these features */
673                 } else if ( strcasecmp( cargv[0], "requires" ) == 0 ||
674                         strcasecmp( cargv[0], "require" ) == 0 )
675                 {
676                         slap_mask_t     requires;
677
678                         if ( cargc < 2 ) {
679                                 Debug( LDAP_DEBUG_ANY,
680             "%s: line %d: missing feature(s) in \"require <features>\" line\n",
681                                     fname, lineno, 0 );
682                                 return( 1 );
683                         }
684
685                         requires = 0;
686
687                         for( i=1; i < cargc; i++ ) {
688                                 if( strcasecmp( cargv[i], "bind" ) == 0 ) {
689                                         requires |= SLAP_REQUIRE_BIND;
690
691                                 } else if( strcasecmp( cargv[i], "LDAPv3" ) == 0 ) {
692                                         requires |= SLAP_REQUIRE_LDAP_V3;
693
694                                 } else if( strcasecmp( cargv[i], "authc" ) == 0 ) {
695                                         requires |= SLAP_REQUIRE_AUTHC;
696
697                                 } else if( strcasecmp( cargv[i], "SASL" ) == 0 ) {
698                                         requires |= SLAP_REQUIRE_SASL;
699
700                                 } else if( strcasecmp( cargv[i], "strong" ) == 0 ) {
701                                         requires |= SLAP_REQUIRE_STRONG;
702
703                                 } else if( strcasecmp( cargv[i], "none" ) != 0 ) {
704                                         Debug( LDAP_DEBUG_ANY,
705                     "%s: line %d: unknown feature %s in \"require <features>\" line\n",
706                                             fname, lineno, cargv[i] );
707                                         return( 1 );
708                                 }
709                         }
710
711                         if ( be == NULL ) {
712                                 global_requires = requires;
713                         } else {
714                                 be->be_requires = requires;
715                         }
716
717                 /* required security factors */
718                 } else if ( strcasecmp( cargv[0], "security" ) == 0 ) {
719                         slap_ssf_set_t *set;
720
721                         if ( cargc < 2 ) {
722                                 Debug( LDAP_DEBUG_ANY,
723             "%s: line %d: missing factor(s) in \"security <factors>\" line\n",
724                                     fname, lineno, 0 );
725                                 return( 1 );
726                         }
727
728                         if ( be == NULL ) {
729                                 set = &global_ssf_set;
730                         } else {
731                                 set = &be->be_ssf_set;
732                         }
733
734                         for( i=1; i < cargc; i++ ) {
735                                 if( strncasecmp( cargv[i], "ssf=",
736                                         sizeof("ssf") ) == 0 )
737                                 {
738                                         set->sss_ssf =
739                                                 atoi( &cargv[i][sizeof("ssf")] );
740
741                                 } else if( strncasecmp( cargv[i], "transport=",
742                                         sizeof("transport") ) == 0 )
743                                 {
744                                         set->sss_transport =
745                                                 atoi( &cargv[i][sizeof("transport")] );
746
747                                 } else if( strncasecmp( cargv[i], "tls=",
748                                         sizeof("tls") ) == 0 )
749                                 {
750                                         set->sss_tls =
751                                                 atoi( &cargv[i][sizeof("tls")] );
752
753                                 } else if( strncasecmp( cargv[i], "sasl=",
754                                         sizeof("sasl") ) == 0 )
755                                 {
756                                         set->sss_sasl =
757                                                 atoi( &cargv[i][sizeof("sasl")] );
758
759                                 } else if( strncasecmp( cargv[i], "update_ssf=",
760                                         sizeof("update_ssf") ) == 0 )
761                                 {
762                                         set->sss_update_ssf =
763                                                 atoi( &cargv[i][sizeof("update_ssf")] );
764
765                                 } else if( strncasecmp( cargv[i], "update_transport=",
766                                         sizeof("update_transport") ) == 0 )
767                                 {
768                                         set->sss_update_transport =
769                                                 atoi( &cargv[i][sizeof("update_transport")] );
770
771                                 } else if( strncasecmp( cargv[i], "update_tls=",
772                                         sizeof("update_tls") ) == 0 )
773                                 {
774                                         set->sss_update_tls =
775                                                 atoi( &cargv[i][sizeof("update_tls")] );
776
777                                 } else if( strncasecmp( cargv[i], "update_sasl=",
778                                         sizeof("update_sasl") ) == 0 )
779                                 {
780                                         set->sss_update_sasl =
781                                                 atoi( &cargv[i][sizeof("update_sasl")] );
782
783                                 } else {
784                                         Debug( LDAP_DEBUG_ANY,
785                     "%s: line %d: unknown factor %s in \"security <factors>\" line\n",
786                                             fname, lineno, cargv[i] );
787                                         return( 1 );
788                                 }
789                         }
790
791                 
792                 /* where to send clients when we don't hold it */
793                 } else if ( strcasecmp( cargv[0], "referral" ) == 0 ) {
794                         if ( cargc < 2 ) {
795                                 Debug( LDAP_DEBUG_ANY,
796                     "%s: line %d: missing URL in \"referral <URL>\" line\n",
797                                     fname, lineno, 0 );
798                                 return( 1 );
799                         }
800
801                         vals[0]->bv_val = cargv[1];
802                         vals[0]->bv_len = strlen( vals[0]->bv_val );
803                         value_add( &default_referral, vals );
804
805                 } else if ( strcasecmp( cargv[0], "debug" ) == 0 ) {
806                         if ( cargc < 3 ) {
807                                 Debug( LDAP_DEBUG_ANY,
808                                         "%s: line %d: Error in debug directive, \"debug subsys level\"\n",
809                                         fname, lineno, 0 );
810                                 return( 1 );
811                         }
812                         lutil_set_debug_level( cargv[1], atoi( cargv[2] ) );
813                 /* specify an Object Identifier macro */
814                 } else if ( strcasecmp( cargv[0], "objectidentifier" ) == 0 ) {
815                         parse_oidm( fname, lineno, cargc, cargv );
816
817                 /* specify an objectclass */
818                 } else if ( strcasecmp( cargv[0], "objectclass" ) == 0 ) {
819                         if ( *cargv[1] == '(' ) {
820                                 char * p;
821                                 p = strchr(saveline,'(');
822                                 parse_oc( fname, lineno, p, cargv );
823                         } else {
824                                 Debug( LDAP_DEBUG_ANY,
825     "%s: line %d: old objectclass format not supported.\n",
826                                     fname, lineno, 0 );
827                         }
828
829                 /* specify an attribute type */
830                 } else if (( strcasecmp( cargv[0], "attributetype" ) == 0 )
831                         || ( strcasecmp( cargv[0], "attribute" ) == 0 ))
832                 {
833                         if ( *cargv[1] == '(' ) {
834                                 char * p;
835                                 p = strchr(saveline,'(');
836                                 parse_at( fname, lineno, p, cargv );
837                         } else {
838                                 Debug( LDAP_DEBUG_ANY,
839     "%s: line %d: old attribute type format not supported.\n",
840                                     fname, lineno, 0 );
841                         }
842
843                 /* turn on/off schema checking */
844                 } else if ( strcasecmp( cargv[0], "schemacheck" ) == 0 ) {
845                         if ( cargc < 2 ) {
846                                 Debug( LDAP_DEBUG_ANY,
847     "%s: line %d: missing on|off in \"schemacheck <on|off>\" line\n",
848                                     fname, lineno, 0 );
849                                 return( 1 );
850                         }
851                         if ( strcasecmp( cargv[1], "off" ) == 0 ) {
852                                 global_schemacheck = 0;
853                         } else {
854                                 global_schemacheck = 1;
855                         }
856
857                 /* specify access control info */
858                 } else if ( strcasecmp( cargv[0], "access" ) == 0 ) {
859                         parse_acl( be, fname, lineno, cargc, cargv );
860
861                 /* specify default access control info */
862                 } else if ( strcasecmp( cargv[0], "defaultaccess" ) == 0 ) {
863                         slap_access_t access;
864
865                         if ( cargc < 2 ) {
866                                 Debug( LDAP_DEBUG_ANY,
867             "%s: line %d: missing limit in \"defaultaccess <access>\" line\n",
868                                     fname, lineno, 0 );
869                                 return( 1 );
870                         }
871
872                         access = str2access( cargv[1] );
873
874                         if ( access == ACL_INVALID_ACCESS ) {
875                                 Debug( LDAP_DEBUG_ANY,
876                                         "%s: line %d: bad access level \"%s\", "
877                                         "expecting none|auth|compare|search|read|write\n",
878                                     fname, lineno, cargv[1] );
879                                 return( 1 );
880                         }
881
882                         if ( be == NULL ) {
883                                 global_default_access = access;
884                         } else {
885                                 be->be_dfltaccess = access;
886                         }
887
888                 /* debug level to log things to syslog */
889                 } else if ( strcasecmp( cargv[0], "loglevel" ) == 0 ) {
890                         if ( cargc < 2 ) {
891                                 Debug( LDAP_DEBUG_ANY,
892                     "%s: line %d: missing level in \"loglevel <level>\" line\n",
893                                     fname, lineno, 0 );
894                                 return( 1 );
895                         }
896
897                         ldap_syslog = 0;
898
899                         for( i=1; i < cargc; i++ ) {
900                                 ldap_syslog += atoi( cargv[1] );
901                         }
902
903                 /* list of replicas of the data in this backend (master only) */
904                 } else if ( strcasecmp( cargv[0], "replica" ) == 0 ) {
905                         if ( cargc < 2 ) {
906                                 Debug( LDAP_DEBUG_ANY,
907             "%s: line %d: missing host in \"replica <host[:port]>\" line\n",
908                                     fname, lineno, 0 );
909                                 return( 1 );
910                         }
911                         if ( be == NULL ) {
912                                 Debug( LDAP_DEBUG_ANY,
913 "%s: line %d: replica line must appear inside a database definition (ignored)\n",
914                                     fname, lineno, 0 );
915                         } else {
916                                 for ( i = 1; i < cargc; i++ ) {
917                                         if ( strncasecmp( cargv[i], "host=", 5 )
918                                             == 0 ) {
919                                                 charray_add( &be->be_replica,
920                                                              cargv[i] + 5 );
921                                                 break;
922                                         }
923                                 }
924                                 if ( i == cargc ) {
925                                         Debug( LDAP_DEBUG_ANY,
926                     "%s: line %d: missing host in \"replica\" line (ignored)\n",
927                                             fname, lineno, 0 );
928                                 }
929                         }
930
931                 /* dn of master entity allowed to write to replica */
932                 } else if ( strcasecmp( cargv[0], "updatedn" ) == 0 ) {
933                         if ( cargc < 2 ) {
934                                 Debug( LDAP_DEBUG_ANY,
935                     "%s: line %d: missing dn in \"updatedn <dn>\" line\n",
936                                     fname, lineno, 0 );
937                                 return( 1 );
938                         }
939                         if ( be == NULL ) {
940                                 Debug( LDAP_DEBUG_ANY,
941 "%s: line %d: updatedn line must appear inside a database definition (ignored)\n",
942                                     fname, lineno, 0 );
943                         } else {
944                                 be->be_update_ndn = ch_strdup( cargv[1] );
945                                 if( dn_normalize( be->be_update_ndn ) == NULL ) {
946                                         Debug( LDAP_DEBUG_ANY,
947 "%s: line %d: updatedn DN is invalid\n",
948                                             fname, lineno, 0 );
949                                         return 1;
950                                 }
951                         }
952
953                 } else if ( strcasecmp( cargv[0], "updateref" ) == 0 ) {
954                         if ( cargc < 2 ) {
955                                 Debug( LDAP_DEBUG_ANY,
956                     "%s: line %d: missing dn in \"updateref <ldapurl>\" line\n",
957                                     fname, lineno, 0 );
958                                 return( 1 );
959                         }
960                         if ( be == NULL ) {
961                                 Debug( LDAP_DEBUG_ANY,
962 "%s: line %d: updateref line must appear inside a database definition (ignored)\n",
963                                     fname, lineno, 0 );
964                         } else if ( be->be_update_ndn == NULL ) {
965                                 Debug( LDAP_DEBUG_ANY,
966 "%s: line %d: updateref line must after updatedn (ignored)\n",
967                                     fname, lineno, 0 );
968                         } else {
969                                 vals[0]->bv_val = cargv[1];
970                                 vals[0]->bv_len = strlen( vals[0]->bv_val );
971                                 value_add( &be->be_update_refs, vals );
972                         }
973
974                 /* replication log file to which changes are appended */
975                 } else if ( strcasecmp( cargv[0], "replogfile" ) == 0 ) {
976                         if ( cargc < 2 ) {
977                                 Debug( LDAP_DEBUG_ANY,
978             "%s: line %d: missing dn in \"replogfile <filename>\" line\n",
979                                     fname, lineno, 0 );
980                                 return( 1 );
981                         }
982                         if ( be ) {
983                                 be->be_replogfile = ch_strdup( cargv[1] );
984                         } else {
985                                 replogfile = ch_strdup( cargv[1] );
986                         }
987
988                 /* maintain lastmodified{by,time} attributes */
989                 } else if ( strcasecmp( cargv[0], "lastmod" ) == 0 ) {
990                         if ( cargc < 2 ) {
991                                 Debug( LDAP_DEBUG_ANY,
992             "%s: line %d: missing on|off in \"lastmod <on|off>\" line\n",
993                                     fname, lineno, 0 );
994                                 return( 1 );
995                         }
996                         if ( strcasecmp( cargv[1], "on" ) == 0 ) {
997                                 if ( be )
998                                         be->be_lastmod = ON;
999                                 else
1000                                         global_lastmod = ON;
1001                         } else {
1002                                 if ( be )
1003                                         be->be_lastmod = OFF;
1004                                 else
1005                                         global_lastmod = OFF;
1006                         }
1007
1008                 /* set idle timeout value */
1009                 } else if ( strcasecmp( cargv[0], "idletimeout" ) == 0 ) {
1010                         int i;
1011                         if ( cargc < 2 ) {
1012                                 Debug( LDAP_DEBUG_ANY,
1013             "%s: line %d: missing timeout value in \"idletimeout <seconds>\" line\n",
1014                                     fname, lineno, 0 );
1015                                 return( 1 );
1016                         }
1017
1018                         i = atoi( cargv[1] );
1019
1020                         if( i < 0 ) {
1021                                 Debug( LDAP_DEBUG_ANY,
1022             "%s: line %d: timeout value (%d) invalid \"idletimeout <seconds>\" line\n",
1023                                     fname, lineno, i );
1024                                 return( 1 );
1025                         }
1026
1027                         global_idletimeout = i;
1028
1029                 /* include another config file */
1030                 } else if ( strcasecmp( cargv[0], "include" ) == 0 ) {
1031                         if ( cargc < 2 ) {
1032                                 Debug( LDAP_DEBUG_ANY,
1033     "%s: line %d: missing filename in \"include <filename>\" line\n",
1034                                     fname, lineno, 0 );
1035                                 return( 1 );
1036                         }
1037                         savefname = ch_strdup( cargv[1] );
1038                         savelineno = lineno;
1039
1040                         if ( read_config( savefname ) != 0 ) {
1041                                 return( 1 );
1042                         }
1043
1044                         free( savefname );
1045                         lineno = savelineno - 1;
1046
1047                 /* location of kerberos srvtab file */
1048                 } else if ( strcasecmp( cargv[0], "srvtab" ) == 0 ) {
1049                         if ( cargc < 2 ) {
1050                                 Debug( LDAP_DEBUG_ANY,
1051             "%s: line %d: missing filename in \"srvtab <filename>\" line\n",
1052                                     fname, lineno, 0 );
1053                                 return( 1 );
1054                         }
1055                         ldap_srvtab = ch_strdup( cargv[1] );
1056
1057 #ifdef SLAPD_MODULES
1058                 } else if (strcasecmp( cargv[0], "moduleload") == 0 ) {
1059                    if ( cargc < 2 ) {
1060                       Debug( LDAP_DEBUG_ANY,
1061                              "%s: line %d: missing filename in \"moduleload <filename>\" line\n",
1062                              fname, lineno, 0 );
1063                       exit( EXIT_FAILURE );
1064                    }
1065                    if (module_load(cargv[1], cargc - 2, (cargc > 2) ? cargv + 2 : NULL)) {
1066                       Debug( LDAP_DEBUG_ANY,
1067                              "%s: line %d: failed to load or initialize module %s\n",
1068                              fname, lineno, cargv[1]);
1069                       exit( EXIT_FAILURE );
1070                    }
1071                 } else if (strcasecmp( cargv[0], "modulepath") == 0 ) {
1072                    if ( cargc != 2 ) {
1073                       Debug( LDAP_DEBUG_ANY,
1074                              "%s: line %d: missing path in \"modulepath <path>\" line\n",
1075                              fname, lineno, 0 );
1076                       exit( EXIT_FAILURE );
1077                    }
1078                    if (module_path( cargv[1] )) {
1079                       Debug( LDAP_DEBUG_ANY,
1080                              "%s: line %d: failed to set module search path to %s\n",
1081                              fname, lineno, cargv[1]);
1082                       exit( EXIT_FAILURE );
1083                    }
1084                    
1085 #endif /*SLAPD_MODULES*/
1086
1087 #ifdef HAVE_TLS
1088                 } else if ( !strcasecmp( cargv[0], "TLSProtocol" ) ) {
1089                         rc = ldap_pvt_tls_set_option( NULL,
1090                                                       LDAP_OPT_X_TLS_PROTOCOL,
1091                                                       cargv[1] );
1092                         if ( rc )
1093                                 return rc;
1094
1095                 } else if ( !strcasecmp( cargv[0], "TLSCipherSuite" ) ) {
1096                         rc = ldap_pvt_tls_set_option( NULL,
1097                                                       LDAP_OPT_X_TLS_CIPHER_SUITE,
1098                                                       cargv[1] );
1099                         if ( rc )
1100                                 return rc;
1101
1102                 } else if ( !strcasecmp( cargv[0], "TLSCertificateFile" ) ) {
1103                         rc = ldap_pvt_tls_set_option( NULL,
1104                                                       LDAP_OPT_X_TLS_CERTFILE,
1105                                                       cargv[1] );
1106                         if ( rc )
1107                                 return rc;
1108
1109                 } else if ( !strcasecmp( cargv[0], "TLSCertificateKeyFile" ) ) {
1110                         rc = ldap_pvt_tls_set_option( NULL,
1111                                                       LDAP_OPT_X_TLS_KEYFILE,
1112                                                       cargv[1] );
1113                         if ( rc )
1114                                 return rc;
1115
1116                 } else if ( !strcasecmp( cargv[0], "TLSCACertificatePath" ) ) {
1117                         rc = ldap_pvt_tls_set_option( NULL,
1118                                                       LDAP_OPT_X_TLS_CACERTDIR,
1119                                                       cargv[1] );
1120                         if ( rc )
1121                                 return rc;
1122
1123                 } else if ( !strcasecmp( cargv[0], "TLSCACertificateFile" ) ) {
1124                         rc = ldap_pvt_tls_set_option( NULL,
1125                                                       LDAP_OPT_X_TLS_CACERTFILE,
1126                                                       cargv[1] );
1127                         if ( rc )
1128                                 return rc;
1129                 } else if ( !strcasecmp( cargv[0], "TLSVerifyClient" ) ) {
1130                         rc = ldap_pvt_tls_set_option( NULL,
1131                                                       LDAP_OPT_X_TLS_REQUIRE_CERT,
1132                                                       cargv[1] );
1133                         if ( rc )
1134                                 return rc;
1135
1136 #endif
1137
1138                 /* pass anything else to the current backend info/db config routine */
1139                 } else {
1140                         if ( bi != NULL ) {
1141                                 if ( bi->bi_config == 0 ) {
1142                                         Debug( LDAP_DEBUG_ANY,
1143 "%s: line %d: unknown directive \"%s\" inside backend info definition (ignored)\n",
1144                                                 fname, lineno, cargv[0] );
1145                                 } else {
1146                                         if ( (*bi->bi_config)( bi, fname, lineno, cargc, cargv )
1147                                                 != 0 )
1148                                         {
1149                                                 return( 1 );
1150                                         }
1151                                 }
1152                         } else if ( be != NULL ) {
1153                                 if ( be->be_config == 0 ) {
1154                                         Debug( LDAP_DEBUG_ANY,
1155 "%s: line %d: unknown directive \"%s\" inside backend database definition (ignored)\n",
1156                                         fname, lineno, cargv[0] );
1157                                 } else {
1158                                         if ( (*be->be_config)( be, fname, lineno, cargc, cargv )
1159                                                 != 0 )
1160                                         {
1161                                                 return( 1 );
1162                                         }
1163                                 }
1164                         } else {
1165                                 Debug( LDAP_DEBUG_ANY,
1166 "%s: line %d: unknown directive \"%s\" outside backend info and database definitions (ignored)\n",
1167                                     fname, lineno, cargv[0] );
1168                         }
1169                 }
1170                 free( saveline );
1171         }
1172         fclose( fp );
1173         return( 0 );
1174 }
1175
1176 static int
1177 fp_parse_line(
1178     char        *line,
1179     int         *argcp,
1180     char        **argv
1181 )
1182 {
1183         char *  token;
1184
1185         *argcp = 0;
1186         for ( token = strtok_quote( line, " \t" ); token != NULL;
1187             token = strtok_quote( NULL, " \t" ) ) {
1188                 if ( *argcp == MAXARGS ) {
1189                         Debug( LDAP_DEBUG_ANY, "Too many tokens (max %d)\n",
1190                             MAXARGS, 0, 0 );
1191                         return( 1 );
1192                 }
1193                 argv[(*argcp)++] = token;
1194         }
1195         argv[*argcp] = NULL;
1196         return 0;
1197 }
1198
1199 static char *
1200 strtok_quote( char *line, char *sep )
1201 {
1202         int             inquote;
1203         char            *tmp;
1204         static char     *next;
1205
1206         if ( line != NULL ) {
1207                 next = line;
1208         }
1209         while ( *next && strchr( sep, *next ) ) {
1210                 next++;
1211         }
1212
1213         if ( *next == '\0' ) {
1214                 next = NULL;
1215                 return( NULL );
1216         }
1217         tmp = next;
1218
1219         for ( inquote = 0; *next; ) {
1220                 switch ( *next ) {
1221                 case '"':
1222                         if ( inquote ) {
1223                                 inquote = 0;
1224                         } else {
1225                                 inquote = 1;
1226                         }
1227                         AC_MEMCPY( next, next + 1, strlen( next + 1 ) + 1 );
1228                         break;
1229
1230                 case '\\':
1231                         if ( next[1] )
1232                                 AC_MEMCPY( next,
1233                                             next + 1, strlen( next + 1 ) + 1 );
1234                         next++;         /* dont parse the escaped character */
1235                         break;
1236
1237                 default:
1238                         if ( ! inquote ) {
1239                                 if ( strchr( sep, *next ) != NULL ) {
1240                                         *next++ = '\0';
1241                                         return( tmp );
1242                                 }
1243                         }
1244                         next++;
1245                         break;
1246                 }
1247         }
1248
1249         return( tmp );
1250 }
1251
1252 static char     buf[BUFSIZ];
1253 static char     *line;
1254 static int      lmax, lcur;
1255
1256 #define CATLINE( buf )  { \
1257         int     len; \
1258         len = strlen( buf ); \
1259         while ( lcur + len + 1 > lmax ) { \
1260                 lmax += BUFSIZ; \
1261                 line = (char *) ch_realloc( line, lmax ); \
1262         } \
1263         strcpy( line + lcur, buf ); \
1264         lcur += len; \
1265 }
1266
1267 static char *
1268 fp_getline( FILE *fp, int *lineno )
1269 {
1270         char            *p;
1271
1272         lcur = 0;
1273         CATLINE( buf );
1274         (*lineno)++;
1275
1276         /* hack attack - keeps us from having to keep a stack of bufs... */
1277         if ( strncasecmp( line, "include", 7 ) == 0 ) {
1278                 buf[0] = '\0';
1279                 return( line );
1280         }
1281
1282         while ( fgets( buf, sizeof(buf), fp ) != NULL ) {
1283                 if ( (p = strchr( buf, '\n' )) != NULL ) {
1284                         *p = '\0';
1285                 }
1286                 if ( ! isspace( (unsigned char) buf[0] ) ) {
1287                         return( line );
1288                 }
1289
1290                 CATLINE( buf );
1291                 (*lineno)++;
1292         }
1293         buf[0] = '\0';
1294
1295         return( line[0] ? line : NULL );
1296 }
1297
1298 static void
1299 fp_getline_init( int *lineno )
1300 {
1301         *lineno = -1;
1302         buf[0] = '\0';
1303 }