]> git.sur5r.net Git - openldap/blob - servers/slapd/config.c
fix Release configuration
[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 "ldapconfig.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 struct acl      *global_acl = NULL;
25 int             global_default_access = ACL_READ;
26 char            *replogfile;
27 int             global_lastmod;
28 char            *ldap_srvtab = "";
29
30 char   *slapd_pid_file  = NULL;
31 char   *slapd_args_file = NULL;
32
33 static char     *fp_getline(FILE *fp, int *lineno);
34 static void     fp_getline_init(int *lineno);
35 static int      fp_parse_line(char *line, int *argcp, char **argv);
36
37 static char     *strtok_quote(char *line, char *sep);
38
39 int
40 read_config( char *fname )
41 {
42         FILE    *fp;
43         char    *line, *savefname;
44         int     cargc, savelineno;
45         char    *cargv[MAXARGS];
46         int     lineno, i;
47
48         static BackendInfo *bi = NULL;
49         static BackendDB        *be = NULL;
50
51         if ( (fp = fopen( fname, "r" )) == NULL ) {
52                 ldap_syslog = 1;
53                 Debug( LDAP_DEBUG_ANY,
54                     "could not open config file \"%s\" - absolute path?\n",
55                     fname, 0, 0 );
56                 perror( fname );
57                 return 1;
58         }
59
60         Debug( LDAP_DEBUG_CONFIG, "reading config file %s\n", fname, 0, 0 );
61
62         fp_getline_init( &lineno );
63
64         while ( (line = fp_getline( fp, &lineno )) != NULL ) {
65                 /* skip comments and blank lines */
66                 if ( line[0] == '#' || line[0] == '\0' ) {
67                         continue;
68                 }
69
70                 Debug( LDAP_DEBUG_CONFIG, "line %d (%s)\n", lineno, line, 0 );
71
72                 if ( fp_parse_line( line, &cargc, cargv ) != 0 ) {
73                         return( 1 );
74                 }
75
76                 if ( cargc < 1 ) {
77                         Debug( LDAP_DEBUG_ANY,
78                             "%s: line %d: bad config line (ignored)\n",
79                             fname, lineno, 0 );
80                         continue;
81                 }
82
83                 if ( strcasecmp( cargv[0], "backend" ) == 0 ) {
84                         if ( cargc < 2 ) {
85                                 Debug( LDAP_DEBUG_ANY,
86                 "%s: line %d: missing type in \"backend <type>\" line\n",
87                                     fname, lineno, 0 );
88                                 return( 1 );
89                         }
90
91                         if( be != NULL ) {
92                                 Debug( LDAP_DEBUG_ANY,
93 "%s: line %d: backend line must appear before any database definition\n",
94                                     fname, lineno, 0 );
95                                 return( 1 );
96                         }
97
98                         bi = backend_info( cargv[1] );
99
100                 /* start of a new database definition */
101                 } else if ( strcasecmp( cargv[0], "database" ) == 0 ) {
102                         if ( cargc < 2 ) {
103                                 Debug( LDAP_DEBUG_ANY,
104                 "%s: line %d: missing type in \"database <type>\" line\n",
105                                     fname, lineno, 0 );
106                                 return( 1 );
107                         }
108                         bi = NULL;
109                         be = backend_db_init( cargv[1] );
110
111                 /* assign a default depth limit for alias deref */
112                 be->be_maxDerefDepth = SLAPD_DEFAULT_MAXDEREFDEPTH; 
113
114                 /* get pid file name */
115                 } else if ( strcasecmp( cargv[0], "pidfile" ) == 0 ) {
116                         if ( cargc < 2 ) {
117                                 Debug( LDAP_DEBUG_ANY,
118             "%s: line %d: missing file name in \"pidfile <file>\" line\n",
119                                     fname, lineno, 0 );
120                                 return( 1 );
121                         }
122
123                         slapd_pid_file = ch_strdup( cargv[1] );
124
125                 /* get args file name */
126                 } else if ( strcasecmp( cargv[0], "argsfile" ) == 0 ) {
127                         if ( cargc < 2 ) {
128                                 Debug( LDAP_DEBUG_ANY,
129             "%s: line %d: missing file name in \"argsfile <file>\" line\n",
130                                     fname, lineno, 0 );
131                                 return( 1 );
132                         }
133
134                         slapd_args_file = ch_strdup( cargv[1] );
135
136                 /* set size limit */
137                 } else if ( strcasecmp( cargv[0], "sizelimit" ) == 0 ) {
138                         if ( cargc < 2 ) {
139                                 Debug( LDAP_DEBUG_ANY,
140             "%s: line %d: missing limit in \"sizelimit <limit>\" line\n",
141                                     fname, lineno, 0 );
142                                 return( 1 );
143                         }
144                         if ( be == NULL ) {
145                                 defsize = atoi( cargv[1] );
146                         } else {
147                                 be->be_sizelimit = atoi( cargv[1] );
148                         }
149
150                 /* set time limit */
151                 } else if ( strcasecmp( cargv[0], "timelimit" ) == 0 ) {
152                         if ( cargc < 2 ) {
153                                 Debug( LDAP_DEBUG_ANY,
154             "%s: line %d: missing limit in \"timelimit <limit>\" line\n",
155                                     fname, lineno, 0 );
156                                 return( 1 );
157                         }
158                         if ( be == NULL ) {
159                                 deftime = atoi( cargv[1] );
160                         } else {
161                                 be->be_timelimit = atoi( cargv[1] );
162                         }
163
164                 /* set database suffix */
165                 } else if ( strcasecmp( cargv[0], "suffix" ) == 0 ) {
166                         if ( cargc < 2 ) {
167                                 Debug( LDAP_DEBUG_ANY,
168                     "%s: line %d: missing dn in \"suffix <dn>\" line\n",
169                                     fname, lineno, 0 );
170                                 return( 1 );
171                         } else if ( cargc > 2 ) {
172                                 Debug( LDAP_DEBUG_ANY,
173     "%s: line %d: extra cruft after <dn> in \"suffix %s\" line (ignored)\n",
174                                     fname, lineno, cargv[1] );
175                         }
176                         if ( be == NULL ) {
177                                 Debug( LDAP_DEBUG_ANY,
178 "%s: line %d: suffix line must appear inside a database definition (ignored)\n",
179                                     fname, lineno, 0 );
180                         } else {
181                                 char *dn = ch_strdup( cargv[1] );
182                                 (void) dn_normalize_case( dn );
183                                 charray_add( &be->be_suffix, dn );
184                                 free( dn );
185                         }
186
187                 /* set database suffixAlias */
188                 } else if ( strcasecmp( cargv[0], "suffixAlias" ) == 0 ) {
189                         if ( cargc < 2 ) {
190                                 Debug( LDAP_DEBUG_ANY,
191                     "%s: line %d: missing alias and aliased_dn in \"suffixAlias <alias> <aliased_dn>\" line\n",
192                                     fname, lineno, 0 );
193                                 return( 1 );
194                         } else if ( cargc < 3 ) {
195                                 Debug( LDAP_DEBUG_ANY,
196                     "%s: line %d: missing aliased_dn in \"suffixAlias <alias> <aliased_dn>\" line\n",
197                                     fname, lineno, 0 );
198                                 return( 1 );
199                         } else if ( cargc > 3 ) {
200                                 Debug( LDAP_DEBUG_ANY,
201     "%s: line %d: extra cruft in suffixAlias line (ignored)\n",
202                                     fname, lineno, 0 );
203                         }
204                         if ( be == NULL ) {
205                                 Debug( LDAP_DEBUG_ANY,
206 "%s: line %d: suffixAlias line must appear inside a database definition (ignored)\n",
207                                     fname, lineno, 0 );
208                         } else {
209                                 char *alias, *aliased_dn;
210
211                                                                 alias = ch_strdup( cargv[1] );
212                                 (void) dn_normalize( alias );
213
214                                 aliased_dn = ch_strdup( cargv[2] );
215                                 (void) dn_normalize( aliased_dn );
216
217
218                                                                 if ( strcasecmp( alias, aliased_dn) == 0 ) {
219                                         Debug( LDAP_DEBUG_ANY,
220 "%s: line %d: suffixAlias %s is not different from aliased dn (ignored)\n",
221                                     fname, lineno, alias );
222                                                                 } else {
223                                         (void) dn_normalize_case( alias );
224                                         (void) dn_normalize_case( aliased_dn );
225                                         charray_add( &be->be_suffixAlias, alias );
226                                         charray_add( &be->be_suffixAlias, aliased_dn );
227                                                                 }
228
229                                                                 free(alias);
230                                                                 free(aliased_dn);
231                         }
232
233                /* set max deref depth */
234                } else if ( strcasecmp( cargv[0], "maxDerefDepth" ) == 0 ) {
235                        if ( cargc < 2 ) {
236                                Debug( LDAP_DEBUG_ANY,
237                    "%s: line %d: missing depth in \"maxDerefDepth <depth>\" line\n",
238                                    fname, lineno, 0 );
239                                return( 1 );
240                        }
241                        if ( be == NULL ) {
242                                Debug( LDAP_DEBUG_ANY,
243 "%s: line %d: depth line must appear inside a database definition (ignored)\n",
244                                    fname, lineno, 0 );
245                        } else {
246                            be->be_maxDerefDepth = atoi (cargv[1]);
247                        }
248
249
250                 /* set magic "root" dn for this database */
251                 } else if ( strcasecmp( cargv[0], "rootdn" ) == 0 ) {
252                         if ( cargc < 2 ) {
253                                 Debug( LDAP_DEBUG_ANY,
254                     "%s: line %d: missing dn in \"rootdn <dn>\" line\n",
255                                     fname, lineno, 0 );
256                                 return( 1 );
257                         }
258                         if ( be == NULL ) {
259                                 Debug( LDAP_DEBUG_ANY,
260 "%s: line %d: rootdn line must appear inside a database definition (ignored)\n",
261                                     fname, lineno, 0 );
262                         } else {
263                                 be->be_root_dn = ch_strdup( cargv[1] );
264                                 be->be_root_ndn = dn_normalize_case( ch_strdup( cargv[1] ) );
265                         }
266
267                 /* set super-secret magic database password */
268                 } else if ( strcasecmp( cargv[0], "rootpw" ) == 0 ) {
269                         if ( cargc < 2 ) {
270                                 Debug( LDAP_DEBUG_ANY,
271             "%s: line %d: missing passwd in \"rootpw <passwd>\" line\n",
272                                     fname, lineno, 0 );
273                                 return( 1 );
274                         }
275                         if ( be == NULL ) {
276                                 Debug( LDAP_DEBUG_ANY,
277 "%s: line %d: rootpw line must appear inside a database definition (ignored)\n",
278                                     fname, lineno, 0 );
279                         } else {
280                                 be->be_root_pw = ch_strdup( cargv[1] );
281                         }
282
283                 /* make this database read-only */
284                 } else if ( strcasecmp( cargv[0], "readonly" ) == 0 ) {
285                         if ( cargc < 2 ) {
286                                 Debug( LDAP_DEBUG_ANY,
287             "%s: line %d: missing on|off in \"readonly <on|off>\" line\n",
288                                     fname, lineno, 0 );
289                                 return( 1 );
290                         }
291                         if ( be == NULL ) {
292                                 Debug( LDAP_DEBUG_ANY,
293 "%s: line %d: readonly line must appear inside a database definition (ignored)\n",
294                                     fname, lineno, 0 );
295                         } else {
296                                 if ( strcasecmp( cargv[1], "on" ) == 0 ) {
297                                         be->be_readonly = 1;
298                                 } else {
299                                         be->be_readonly = 0;
300                                 }
301                         }
302
303                 /* where to send clients when we don't hold it */
304                 } else if ( strcasecmp( cargv[0], "referral" ) == 0 ) {
305                         if ( cargc < 2 ) {
306                                 Debug( LDAP_DEBUG_ANY,
307                     "%s: line %d: missing URL in \"referral <URL>\" line\n",
308                                     fname, lineno, 0 );
309                                 return( 1 );
310                         }
311                         default_referral = (char *) ch_malloc( strlen( cargv[1] )
312                             + sizeof("Referral:\n") + 1 );
313                         strcpy( default_referral, "Referral:\n" );
314                         strcat( default_referral, cargv[1] );
315
316                 /* specify locale */
317                 } else if ( strcasecmp( cargv[0], "locale" ) == 0 ) {
318 #ifdef HAVE_LOCALE_H
319                         char *locale;
320                         if ( cargc < 2 ) {
321                                 Debug( LDAP_DEBUG_ANY,
322         "%s: line %d: missing locale in \"locale <name | on | off>\" line\n",
323                                        fname, lineno, 0 );
324                                 return( 1 );
325                         }
326
327                         locale = (strcasecmp(   cargv[1], "on"  ) == 0 ? ""
328                                   : strcasecmp( cargv[1], "off" ) == 0 ? "C"
329                                   : ch_strdup( cargv[1] )                    );
330
331                         if ( setlocale( LC_CTYPE, locale ) == 0 ) {
332                                 Debug( LDAP_DEBUG_ANY,
333                                        (*locale
334                                         ? "%s: line %d: bad locale \"%s\"\n"
335                                         : "%s: line %d: bad locale\n"),
336                                        fname, lineno, locale );
337                                 return( 1 );
338                         }
339 #else
340                         Debug( LDAP_DEBUG_ANY,
341                                "%s: line %d: \"locale\" unsupported\n",
342                                fname, lineno, 0 );
343                         return( 1 );
344 #endif
345                 /* specify an objectclass */
346                 } else if ( strcasecmp( cargv[0], "objectclass" ) == 0 ) {
347                         parse_oc( be, fname, lineno, cargc, cargv );
348
349                 /* specify an attribute */
350                 } else if ( strcasecmp( cargv[0], "attribute" ) == 0 ) {
351                         attr_syntax_config( fname, lineno, cargc - 1,
352                             &cargv[1] );
353
354                 /* turn on/off schema checking */
355                 } else if ( strcasecmp( cargv[0], "schemacheck" ) == 0 ) {
356                         if ( cargc < 2 ) {
357                                 Debug( LDAP_DEBUG_ANY,
358     "%s: line %d: missing on|off in \"schemacheck <on|off>\" line\n",
359                                     fname, lineno, 0 );
360                                 return( 1 );
361                         }
362                         if ( strcasecmp( cargv[1], "on" ) == 0 ) {
363                                 global_schemacheck = 1;
364                         } else {
365                                 global_schemacheck = 0;
366                         }
367
368                 /* specify access control info */
369                 } else if ( strcasecmp( cargv[0], "access" ) == 0 ) {
370                         parse_acl( be, fname, lineno, cargc, cargv );
371
372                 /* specify default access control info */
373                 } else if ( strcasecmp( cargv[0], "defaultaccess" ) == 0 ) {
374                         if ( cargc < 2 ) {
375                                 Debug( LDAP_DEBUG_ANY,
376             "%s: line %d: missing limit in \"defaultaccess <access>\" line\n",
377                                     fname, lineno, 0 );
378                                 return( 1 );
379                         }
380                         if ( be == NULL ) {
381                                 if ( (global_default_access =
382                                     str2access( cargv[1] )) == -1 ) {
383                                         Debug( LDAP_DEBUG_ANY,
384 "%s: line %d: bad access \"%s\" expecting [self]{none|compare|read|write}\n",
385                                             fname, lineno, cargv[1] );
386                                         return( 1 );
387                                 }
388                         } else {
389                                 if ( (be->be_dfltaccess =
390                                     str2access( cargv[1] )) == -1 ) {
391                                         Debug( LDAP_DEBUG_ANY,
392 "%s: line %d: bad access \"%s\" expecting [self]{none|compare|read|write}\n",
393                                             fname, lineno, cargv[1] );
394                                         return( 1 );
395                                 }
396                         }
397
398                 /* debug level to log things to syslog */
399                 } else if ( strcasecmp( cargv[0], "loglevel" ) == 0 ) {
400                         if ( cargc < 2 ) {
401                                 Debug( LDAP_DEBUG_ANY,
402                     "%s: line %d: missing level in \"loglevel <level>\" line\n",
403                                     fname, lineno, 0 );
404                                 return( 1 );
405                         }
406                         ldap_syslog = atoi( cargv[1] );
407
408                 /* list of replicas of the data in this backend (master only) */
409                 } else if ( strcasecmp( cargv[0], "replica" ) == 0 ) {
410                         if ( cargc < 2 ) {
411                                 Debug( LDAP_DEBUG_ANY,
412             "%s: line %d: missing host in \"replica <host[:port]>\" line\n",
413                                     fname, lineno, 0 );
414                                 return( 1 );
415                         }
416                         if ( be == NULL ) {
417                                 Debug( LDAP_DEBUG_ANY,
418 "%s: line %d: replica line must appear inside a database definition (ignored)\n",
419                                     fname, lineno, 0 );
420                         } else {
421                                 for ( i = 1; i < cargc; i++ ) {
422                                         if ( strncasecmp( cargv[i], "host=", 5 )
423                                             == 0 ) {
424                                                 charray_add( &be->be_replica,
425                                                              cargv[i] + 5 );
426                                                 break;
427                                         }
428                                 }
429                                 if ( i == cargc ) {
430                                         Debug( LDAP_DEBUG_ANY,
431                     "%s: line %d: missing host in \"replica\" line (ignored)\n",
432                                             fname, lineno, 0 );
433                                 }
434                         }
435
436                 /* dn of master entity allowed to write to replica */
437                 } else if ( strcasecmp( cargv[0], "updatedn" ) == 0 ) {
438                         if ( cargc < 2 ) {
439                                 Debug( LDAP_DEBUG_ANY,
440                     "%s: line %d: missing dn in \"updatedn <dn>\" line\n",
441                                     fname, lineno, 0 );
442                                 return( 1 );
443                         }
444                         if ( be == NULL ) {
445                                 Debug( LDAP_DEBUG_ANY,
446 "%s: line %d: updatedn line must appear inside a database definition (ignored)\n",
447                                     fname, lineno, 0 );
448                         } else {
449                                 be->be_update_ndn = ch_strdup( cargv[1] );
450                                 (void) dn_normalize_case( be->be_update_ndn );
451                         }
452
453                 /* replication log file to which changes are appended */
454                 } else if ( strcasecmp( cargv[0], "replogfile" ) == 0 ) {
455                         if ( cargc < 2 ) {
456                                 Debug( LDAP_DEBUG_ANY,
457             "%s: line %d: missing dn in \"replogfile <filename>\" line\n",
458                                     fname, lineno, 0 );
459                                 return( 1 );
460                         }
461                         if ( be ) {
462                                 be->be_replogfile = ch_strdup( cargv[1] );
463                         } else {
464                                 replogfile = ch_strdup( cargv[1] );
465                         }
466
467                 /* maintain lastmodified{by,time} attributes */
468                 } else if ( strcasecmp( cargv[0], "lastmod" ) == 0 ) {
469                         if ( cargc < 2 ) {
470                                 Debug( LDAP_DEBUG_ANY,
471             "%s: line %d: missing on|off in \"lastmod <on|off>\" line\n",
472                                     fname, lineno, 0 );
473                                 return( 1 );
474                         }
475                         if ( strcasecmp( cargv[1], "on" ) == 0 ) {
476                                 if ( be )
477                                         be->be_lastmod = ON;
478                                 else
479                                         global_lastmod = ON;
480                         } else {
481                                 if ( be )
482                                         be->be_lastmod = OFF;
483                                 else
484                                         global_lastmod = OFF;
485                         }
486
487                 /* include another config file */
488                 } else if ( strcasecmp( cargv[0], "include" ) == 0 ) {
489                         if ( cargc < 2 ) {
490                                 Debug( LDAP_DEBUG_ANY,
491     "%s: line %d: missing filename in \"include <filename>\" line\n",
492                                     fname, lineno, 0 );
493                                 return( 1 );
494                         }
495                         savefname = ch_strdup( cargv[1] );
496                         savelineno = lineno;
497
498                         if ( read_config( savefname ) != 0 ) {
499                                 return( 1 );
500                         }
501
502                         free( savefname );
503                         lineno = savelineno - 1;
504
505                 /* location of kerberos srvtab file */
506                 } else if ( strcasecmp( cargv[0], "srvtab" ) == 0 ) {
507                         if ( cargc < 2 ) {
508                                 Debug( LDAP_DEBUG_ANY,
509             "%s: line %d: missing filename in \"srvtab <filename>\" line\n",
510                                     fname, lineno, 0 );
511                                 return( 1 );
512                         }
513                         ldap_srvtab = ch_strdup( cargv[1] );
514
515                 /* pass anything else to the current backend info/db config routine */
516                 } else {
517                         if ( bi != NULL ) {
518                                 if ( bi->bi_config == 0 ) {
519                                         Debug( LDAP_DEBUG_ANY,
520 "%s: line %d: unknown directive \"%s\" inside backend info definition (ignored)\n",
521                                                 fname, lineno, cargv[0] );
522                                 } else {
523                                         if ( (*bi->bi_config)( bi, fname, lineno, cargc, cargv )
524                                                 != 0 )
525                                         {
526                                                 return( 1 );
527                                         }
528                                 }
529                         } else if ( be != NULL ) {
530                                 if ( be->be_config == 0 ) {
531                                         Debug( LDAP_DEBUG_ANY,
532 "%s: line %d: unknown directive \"%s\" inside backend database definition (ignored)\n",
533                                         fname, lineno, cargv[0] );
534                                 } else {
535                                         if ( (*be->be_config)( be, fname, lineno, cargc, cargv )
536                                                 != 0 )
537                                         {
538                                                 return( 1 );
539                                         }
540                                 }
541                         } else {
542                                 Debug( LDAP_DEBUG_ANY,
543 "%s: line %d: unknown directive \"%s\" outside backend info and database definitions (ignored)\n",
544                                     fname, lineno, cargv[0] );
545                         }
546                 }
547         }
548         fclose( fp );
549         return( 0 );
550 }
551
552 static int
553 fp_parse_line(
554     char        *line,
555     int         *argcp,
556     char        **argv
557 )
558 {
559         char *  token;
560
561         *argcp = 0;
562         for ( token = strtok_quote( line, " \t" ); token != NULL;
563             token = strtok_quote( NULL, " \t" ) ) {
564                 if ( *argcp == MAXARGS ) {
565                         Debug( LDAP_DEBUG_ANY, "Too many tokens (max %d)\n",
566                             MAXARGS, 0, 0 );
567                         return( 1 );
568                 }
569                 argv[(*argcp)++] = token;
570         }
571         argv[*argcp] = NULL;
572         return 0;
573 }
574
575 static char *
576 strtok_quote( char *line, char *sep )
577 {
578         int             inquote;
579         char            *tmp;
580         static char     *next;
581
582         if ( line != NULL ) {
583                 next = line;
584         }
585         while ( *next && strchr( sep, *next ) ) {
586                 next++;
587         }
588
589         if ( *next == '\0' ) {
590                 next = NULL;
591                 return( NULL );
592         }
593         tmp = next;
594
595         for ( inquote = 0; *next; ) {
596                 switch ( *next ) {
597                 case '"':
598                         if ( inquote ) {
599                                 inquote = 0;
600                         } else {
601                                 inquote = 1;
602                         }
603                         SAFEMEMCPY( next, next + 1, strlen( next + 1 ) + 1 );
604                         break;
605
606                 case '\\':
607                         if ( next[1] )
608                                 SAFEMEMCPY( next,
609                                             next + 1, strlen( next + 1 ) + 1 );
610                         next++;         /* dont parse the escaped character */
611                         break;
612
613                 default:
614                         if ( ! inquote ) {
615                                 if ( strchr( sep, *next ) != NULL ) {
616                                         *next++ = '\0';
617                                         return( tmp );
618                                 }
619                         }
620                         next++;
621                         break;
622                 }
623         }
624
625         return( tmp );
626 }
627
628 static char     buf[BUFSIZ];
629 static char     *line;
630 static int      lmax, lcur;
631
632 #define CATLINE( buf )  { \
633         int     len; \
634         len = strlen( buf ); \
635         while ( lcur + len + 1 > lmax ) { \
636                 lmax += BUFSIZ; \
637                 line = (char *) ch_realloc( line, lmax ); \
638         } \
639         strcpy( line + lcur, buf ); \
640         lcur += len; \
641 }
642
643 static char *
644 fp_getline( FILE *fp, int *lineno )
645 {
646         char            *p;
647
648         lcur = 0;
649         CATLINE( buf );
650         (*lineno)++;
651
652         /* hack attack - keeps us from having to keep a stack of bufs... */
653         if ( strncasecmp( line, "include", 7 ) == 0 ) {
654                 buf[0] = '\0';
655                 return( line );
656         }
657
658         while ( fgets( buf, sizeof(buf), fp ) != NULL ) {
659                 if ( (p = strchr( buf, '\n' )) != NULL ) {
660                         *p = '\0';
661                 }
662                 if ( ! isspace( (unsigned char) buf[0] ) ) {
663                         return( line );
664                 }
665
666                 CATLINE( buf );
667                 (*lineno)++;
668         }
669         buf[0] = '\0';
670
671         return( line[0] ? line : NULL );
672 }
673
674 static void
675 fp_getline_init( int *lineno )
676 {
677         *lineno = -1;
678         buf[0] = '\0';
679 }