]> git.sur5r.net Git - openldap/blob - servers/slapd/config.c
Rework ac/socket.h for HAVE_WINSOCK:
[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                         }
185
186                 /* set database suffixAlias */
187                 } else if ( strcasecmp( cargv[0], "suffixAlias" ) == 0 ) {
188                         if ( cargc < 2 ) {
189                                 Debug( LDAP_DEBUG_ANY,
190                     "%s: line %d: missing alias and aliased_dn in \"suffixAlias <alias> <aliased_dn>\" line\n",
191                                     fname, lineno, 0 );
192                                 return( 1 );
193                         } else if ( cargc < 3 ) {
194                                 Debug( LDAP_DEBUG_ANY,
195                     "%s: line %d: missing aliased_dn in \"suffixAlias <alias> <aliased_dn>\" line\n",
196                                     fname, lineno, 0 );
197                                 return( 1 );
198                         } else if ( cargc > 3 ) {
199                                 Debug( LDAP_DEBUG_ANY,
200     "%s: line %d: extra cruft in suffixAlias line (ignored)\n",
201                                     fname, lineno, 0 );
202                         }
203                         if ( be == NULL ) {
204                                 Debug( LDAP_DEBUG_ANY,
205 "%s: line %d: suffixAlias line must appear inside a database definition (ignored)\n",
206                                     fname, lineno, 0 );
207                         } else {
208                                 char *alias, *aliased_dn;
209
210                                                                 alias = ch_strdup( cargv[1] );
211                                 (void) dn_normalize( alias );
212
213                                 aliased_dn = ch_strdup( cargv[2] );
214                                 (void) dn_normalize( aliased_dn );
215
216
217                                                                 if ( strcasecmp( alias, aliased_dn) == 0 ) {
218                                         Debug( LDAP_DEBUG_ANY,
219 "%s: line %d: suffixAlias %s is not different from aliased dn (ignored)\n",
220                                     fname, lineno, alias );
221                                                                 } else {
222                                         (void) dn_normalize_case( alias );
223                                         (void) dn_normalize_case( aliased_dn );
224                                         charray_add( &be->be_suffixAlias, alias );
225                                         charray_add( &be->be_suffixAlias, aliased_dn );
226                                                                 }
227
228                                                                 free(alias);
229                                                                 free(aliased_dn);
230                         }
231
232                /* set max deref depth */
233                } else if ( strcasecmp( cargv[0], "maxDerefDepth" ) == 0 ) {
234                        if ( cargc < 2 ) {
235                                Debug( LDAP_DEBUG_ANY,
236                    "%s: line %d: missing depth in \"maxDerefDepth <depth>\" line\n",
237                                    fname, lineno, 0 );
238                                return( 1 );
239                        }
240                        if ( be == NULL ) {
241                                Debug( LDAP_DEBUG_ANY,
242 "%s: line %d: depth line must appear inside a database definition (ignored)\n",
243                                    fname, lineno, 0 );
244                        } else {
245                            be->be_maxDerefDepth = atoi (cargv[1]);
246                        }
247
248
249                 /* set magic "root" dn for this database */
250                 } else if ( strcasecmp( cargv[0], "rootdn" ) == 0 ) {
251                         if ( cargc < 2 ) {
252                                 Debug( LDAP_DEBUG_ANY,
253                     "%s: line %d: missing dn in \"rootdn <dn>\" line\n",
254                                     fname, lineno, 0 );
255                                 return( 1 );
256                         }
257                         if ( be == NULL ) {
258                                 Debug( LDAP_DEBUG_ANY,
259 "%s: line %d: rootdn line must appear inside a database definition (ignored)\n",
260                                     fname, lineno, 0 );
261                         } else {
262                                 be->be_root_dn = ch_strdup( cargv[1] );
263                                 be->be_root_ndn = dn_normalize_case( ch_strdup( cargv[1] ) );
264                         }
265
266                 /* set super-secret magic database password */
267                 } else if ( strcasecmp( cargv[0], "rootpw" ) == 0 ) {
268                         if ( cargc < 2 ) {
269                                 Debug( LDAP_DEBUG_ANY,
270             "%s: line %d: missing passwd in \"rootpw <passwd>\" line\n",
271                                     fname, lineno, 0 );
272                                 return( 1 );
273                         }
274                         if ( be == NULL ) {
275                                 Debug( LDAP_DEBUG_ANY,
276 "%s: line %d: rootpw line must appear inside a database definition (ignored)\n",
277                                     fname, lineno, 0 );
278                         } else {
279                                 be->be_root_pw = ch_strdup( cargv[1] );
280                         }
281
282                 /* make this database read-only */
283                 } else if ( strcasecmp( cargv[0], "readonly" ) == 0 ) {
284                         if ( cargc < 2 ) {
285                                 Debug( LDAP_DEBUG_ANY,
286             "%s: line %d: missing on|off in \"readonly <on|off>\" line\n",
287                                     fname, lineno, 0 );
288                                 return( 1 );
289                         }
290                         if ( be == NULL ) {
291                                 Debug( LDAP_DEBUG_ANY,
292 "%s: line %d: readonly line must appear inside a database definition (ignored)\n",
293                                     fname, lineno, 0 );
294                         } else {
295                                 if ( strcasecmp( cargv[1], "on" ) == 0 ) {
296                                         be->be_readonly = 1;
297                                 } else {
298                                         be->be_readonly = 0;
299                                 }
300                         }
301
302                 /* where to send clients when we don't hold it */
303                 } else if ( strcasecmp( cargv[0], "referral" ) == 0 ) {
304                         if ( cargc < 2 ) {
305                                 Debug( LDAP_DEBUG_ANY,
306                     "%s: line %d: missing URL in \"referral <URL>\" line\n",
307                                     fname, lineno, 0 );
308                                 return( 1 );
309                         }
310                         default_referral = (char *) ch_malloc( strlen( cargv[1] )
311                             + sizeof("Referral:\n") + 1 );
312                         strcpy( default_referral, "Referral:\n" );
313                         strcat( default_referral, cargv[1] );
314
315                 /* specify locale */
316                 } else if ( strcasecmp( cargv[0], "locale" ) == 0 ) {
317 #ifdef HAVE_LOCALE_H
318                         char *locale;
319                         if ( cargc < 2 ) {
320                                 Debug( LDAP_DEBUG_ANY,
321         "%s: line %d: missing locale in \"locale <name | on | off>\" line\n",
322                                        fname, lineno, 0 );
323                                 return( 1 );
324                         }
325
326                         locale = (strcasecmp(   cargv[1], "on"  ) == 0 ? ""
327                                   : strcasecmp( cargv[1], "off" ) == 0 ? "C"
328                                   : ch_strdup( cargv[1] )                    );
329
330                         if ( setlocale( LC_CTYPE, locale ) == 0 ) {
331                                 Debug( LDAP_DEBUG_ANY,
332                                        (*locale
333                                         ? "%s: line %d: bad locale \"%s\"\n"
334                                         : "%s: line %d: bad locale\n"),
335                                        fname, lineno, locale );
336                                 return( 1 );
337                         }
338 #else
339                         Debug( LDAP_DEBUG_ANY,
340                                "%s: line %d: \"locale\" unsupported\n",
341                                fname, lineno, 0 );
342                         return( 1 );
343 #endif
344                 /* specify an objectclass */
345                 } else if ( strcasecmp( cargv[0], "objectclass" ) == 0 ) {
346                         parse_oc( be, fname, lineno, cargc, cargv );
347
348                 /* specify an attribute */
349                 } else if ( strcasecmp( cargv[0], "attribute" ) == 0 ) {
350                         attr_syntax_config( fname, lineno, cargc - 1,
351                             &cargv[1] );
352
353                 /* turn on/off schema checking */
354                 } else if ( strcasecmp( cargv[0], "schemacheck" ) == 0 ) {
355                         if ( cargc < 2 ) {
356                                 Debug( LDAP_DEBUG_ANY,
357     "%s: line %d: missing on|off in \"schemacheck <on|off>\" line\n",
358                                     fname, lineno, 0 );
359                                 return( 1 );
360                         }
361                         if ( strcasecmp( cargv[1], "on" ) == 0 ) {
362                                 global_schemacheck = 1;
363                         } else {
364                                 global_schemacheck = 0;
365                         }
366
367                 /* specify access control info */
368                 } else if ( strcasecmp( cargv[0], "access" ) == 0 ) {
369                         parse_acl( be, fname, lineno, cargc, cargv );
370
371                 /* specify default access control info */
372                 } else if ( strcasecmp( cargv[0], "defaultaccess" ) == 0 ) {
373                         if ( cargc < 2 ) {
374                                 Debug( LDAP_DEBUG_ANY,
375             "%s: line %d: missing limit in \"defaultaccess <access>\" line\n",
376                                     fname, lineno, 0 );
377                                 return( 1 );
378                         }
379                         if ( be == NULL ) {
380                                 if ( (global_default_access =
381                                     str2access( cargv[1] )) == -1 ) {
382                                         Debug( LDAP_DEBUG_ANY,
383 "%s: line %d: bad access \"%s\" expecting [self]{none|compare|read|write}\n",
384                                             fname, lineno, cargv[1] );
385                                         return( 1 );
386                                 }
387                         } else {
388                                 if ( (be->be_dfltaccess =
389                                     str2access( cargv[1] )) == -1 ) {
390                                         Debug( LDAP_DEBUG_ANY,
391 "%s: line %d: bad access \"%s\" expecting [self]{none|compare|read|write}\n",
392                                             fname, lineno, cargv[1] );
393                                         return( 1 );
394                                 }
395                         }
396
397                 /* debug level to log things to syslog */
398                 } else if ( strcasecmp( cargv[0], "loglevel" ) == 0 ) {
399                         if ( cargc < 2 ) {
400                                 Debug( LDAP_DEBUG_ANY,
401                     "%s: line %d: missing level in \"loglevel <level>\" line\n",
402                                     fname, lineno, 0 );
403                                 return( 1 );
404                         }
405                         ldap_syslog = atoi( cargv[1] );
406
407                 /* list of replicas of the data in this backend (master only) */
408                 } else if ( strcasecmp( cargv[0], "replica" ) == 0 ) {
409                         if ( cargc < 2 ) {
410                                 Debug( LDAP_DEBUG_ANY,
411             "%s: line %d: missing host in \"replica <host[:port]>\" line\n",
412                                     fname, lineno, 0 );
413                                 return( 1 );
414                         }
415                         if ( be == NULL ) {
416                                 Debug( LDAP_DEBUG_ANY,
417 "%s: line %d: replica line must appear inside a database definition (ignored)\n",
418                                     fname, lineno, 0 );
419                         } else {
420                                 for ( i = 1; i < cargc; i++ ) {
421                                         if ( strncasecmp( cargv[i], "host=", 5 )
422                                             == 0 ) {
423                                                 charray_add( &be->be_replica,
424                                                     ch_strdup( cargv[i] + 5 ) );
425                                                 break;
426                                         }
427                                 }
428                                 if ( i == cargc ) {
429                                         Debug( LDAP_DEBUG_ANY,
430                     "%s: line %d: missing host in \"replica\" line (ignored)\n",
431                                             fname, lineno, 0 );
432                                 }
433                         }
434
435                 /* dn of master entity allowed to write to replica */
436                 } else if ( strcasecmp( cargv[0], "updatedn" ) == 0 ) {
437                         if ( cargc < 2 ) {
438                                 Debug( LDAP_DEBUG_ANY,
439                     "%s: line %d: missing dn in \"updatedn <dn>\" line\n",
440                                     fname, lineno, 0 );
441                                 return( 1 );
442                         }
443                         if ( be == NULL ) {
444                                 Debug( LDAP_DEBUG_ANY,
445 "%s: line %d: updatedn line must appear inside a database definition (ignored)\n",
446                                     fname, lineno, 0 );
447                         } else {
448                                 be->be_update_ndn = ch_strdup( cargv[1] );
449                                 (void) dn_normalize_case( be->be_update_ndn );
450                         }
451
452                 /* replication log file to which changes are appended */
453                 } else if ( strcasecmp( cargv[0], "replogfile" ) == 0 ) {
454                         if ( cargc < 2 ) {
455                                 Debug( LDAP_DEBUG_ANY,
456             "%s: line %d: missing dn in \"replogfile <filename>\" line\n",
457                                     fname, lineno, 0 );
458                                 return( 1 );
459                         }
460                         if ( be ) {
461                                 be->be_replogfile = ch_strdup( cargv[1] );
462                         } else {
463                                 replogfile = ch_strdup( cargv[1] );
464                         }
465
466                 /* maintain lastmodified{by,time} attributes */
467                 } else if ( strcasecmp( cargv[0], "lastmod" ) == 0 ) {
468                         if ( cargc < 2 ) {
469                                 Debug( LDAP_DEBUG_ANY,
470             "%s: line %d: missing on|off in \"lastmod <on|off>\" line\n",
471                                     fname, lineno, 0 );
472                                 return( 1 );
473                         }
474                         if ( strcasecmp( cargv[1], "on" ) == 0 ) {
475                                 if ( be )
476                                         be->be_lastmod = ON;
477                                 else
478                                         global_lastmod = ON;
479                         } else {
480                                 if ( be )
481                                         be->be_lastmod = OFF;
482                                 else
483                                         global_lastmod = OFF;
484                         }
485
486                 /* include another config file */
487                 } else if ( strcasecmp( cargv[0], "include" ) == 0 ) {
488                         if ( cargc < 2 ) {
489                                 Debug( LDAP_DEBUG_ANY,
490     "%s: line %d: missing filename in \"include <filename>\" line\n",
491                                     fname, lineno, 0 );
492                                 return( 1 );
493                         }
494                         savefname = ch_strdup( cargv[1] );
495                         savelineno = lineno;
496
497                         if ( read_config( savefname ) != 0 ) {
498                                 return( 1 );
499                         }
500
501                         free( savefname );
502                         lineno = savelineno - 1;
503
504                 /* location of kerberos srvtab file */
505                 } else if ( strcasecmp( cargv[0], "srvtab" ) == 0 ) {
506                         if ( cargc < 2 ) {
507                                 Debug( LDAP_DEBUG_ANY,
508             "%s: line %d: missing filename in \"srvtab <filename>\" line\n",
509                                     fname, lineno, 0 );
510                                 return( 1 );
511                         }
512                         ldap_srvtab = ch_strdup( cargv[1] );
513
514                 /* pass anything else to the current backend info/db config routine */
515                 } else {
516                         if ( bi != NULL ) {
517                                 if ( bi->bi_config == 0 ) {
518                                         Debug( LDAP_DEBUG_ANY,
519 "%s: line %d: unknown directive \"%s\" inside backend info definition (ignored)\n",
520                                                 fname, lineno, cargv[0] );
521                                 } else {
522                                         if ( (*bi->bi_config)( bi, fname, lineno, cargc, cargv )
523                                                 != 0 )
524                                         {
525                                                 return( 1 );
526                                         }
527                                 }
528                         } else if ( be != NULL ) {
529                                 if ( be->be_config == 0 ) {
530                                         Debug( LDAP_DEBUG_ANY,
531 "%s: line %d: unknown directive \"%s\" inside backend database definition (ignored)\n",
532                                         fname, lineno, cargv[0] );
533                                 } else {
534                                         if ( (*be->be_config)( be, fname, lineno, cargc, cargv )
535                                                 != 0 )
536                                         {
537                                                 return( 1 );
538                                         }
539                                 }
540                         } else {
541                                 Debug( LDAP_DEBUG_ANY,
542 "%s: line %d: unknown directive \"%s\" outside backend info and database definitions (ignored)\n",
543                                     fname, lineno, cargv[0] );
544                         }
545                 }
546         }
547         fclose( fp );
548         return( 0 );
549 }
550
551 static int
552 fp_parse_line(
553     char        *line,
554     int         *argcp,
555     char        **argv
556 )
557 {
558         char *  token;
559
560         *argcp = 0;
561         for ( token = strtok_quote( line, " \t" ); token != NULL;
562             token = strtok_quote( NULL, " \t" ) ) {
563                 if ( *argcp == MAXARGS ) {
564                         Debug( LDAP_DEBUG_ANY, "Too many tokens (max %d)\n",
565                             MAXARGS, 0, 0 );
566                         return( 1 );
567                 }
568                 argv[(*argcp)++] = token;
569         }
570         argv[*argcp] = NULL;
571         return 0;
572 }
573
574 static char *
575 strtok_quote( char *line, char *sep )
576 {
577         int             inquote;
578         char            *tmp;
579         static char     *next;
580
581         if ( line != NULL ) {
582                 next = line;
583         }
584         while ( *next && strchr( sep, *next ) ) {
585                 next++;
586         }
587
588         if ( *next == '\0' ) {
589                 next = NULL;
590                 return( NULL );
591         }
592         tmp = next;
593
594         for ( inquote = 0; *next; ) {
595                 switch ( *next ) {
596                 case '"':
597                         if ( inquote ) {
598                                 inquote = 0;
599                         } else {
600                                 inquote = 1;
601                         }
602                         SAFEMEMCPY( next, next + 1, strlen( next + 1 ) + 1 );
603                         break;
604
605                 case '\\':
606                         if ( next[1] )
607                                 SAFEMEMCPY( next,
608                                             next + 1, strlen( next + 1 ) + 1 );
609                         next++;         /* dont parse the escaped character */
610                         break;
611
612                 default:
613                         if ( ! inquote ) {
614                                 if ( strchr( sep, *next ) != NULL ) {
615                                         *next++ = '\0';
616                                         return( tmp );
617                                 }
618                         }
619                         next++;
620                         break;
621                 }
622         }
623
624         return( tmp );
625 }
626
627 static char     buf[BUFSIZ];
628 static char     *line;
629 static int      lmax, lcur;
630
631 #define CATLINE( buf )  { \
632         int     len; \
633         len = strlen( buf ); \
634         while ( lcur + len + 1 > lmax ) { \
635                 lmax += BUFSIZ; \
636                 line = (char *) ch_realloc( line, lmax ); \
637         } \
638         strcpy( line + lcur, buf ); \
639         lcur += len; \
640 }
641
642 static char *
643 fp_getline( FILE *fp, int *lineno )
644 {
645         char            *p;
646
647         lcur = 0;
648         CATLINE( buf );
649         (*lineno)++;
650
651         /* hack attack - keeps us from having to keep a stack of bufs... */
652         if ( strncasecmp( line, "include", 7 ) == 0 ) {
653                 buf[0] = '\0';
654                 return( line );
655         }
656
657         while ( fgets( buf, sizeof(buf), fp ) != NULL ) {
658                 if ( (p = strchr( buf, '\n' )) != NULL ) {
659                         *p = '\0';
660                 }
661                 if ( ! isspace( (unsigned char) buf[0] ) ) {
662                         return( line );
663                 }
664
665                 CATLINE( buf );
666                 (*lineno)++;
667         }
668         buf[0] = '\0';
669
670         return( line[0] ? line : NULL );
671 }
672
673 static void
674 fp_getline_init( int *lineno )
675 {
676         *lineno = -1;
677         buf[0] = '\0';
678 }