chiark / gitweb /
Parser fixes:
[userv.git] / parser.c
1 /*
2  * userv - parser.c
3  * configuration file parser; this file is actually #included from
4  * lexer.c, which is generated using flex from lexer.l, in turn from
5  * lexer.l.m4.  It's in a separate file so that we don't have to worry
6  * about m4 quoting &c., but we have to #include it so that the C
7  * objects from the lexer are available.
8  *
9  * Copyright (C)1996-1999,2001,2006,2012 Ian Jackson
10  *
11  * This is free software; you can redistribute it and/or modify it
12  * under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful, but
17  * WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19  * General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with userv; if not, write to the Free Software
23  * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24  */
25
26 static int parse_file(const char *string, int *didexist);
27 static int parser(int allowce);
28 int parse_string(const char *string, const char *descrip, int isinternal);
29
30 /*
31  * Error-handling routines
32  */
33
34 static void closeerrorfile(void) {
35   if (eh.file && !eh.filekeep) {
36     if (fclose(eh.file)) {
37       eh.handling= tokv_word_errorstostderr;
38       parseerrprint("error writing to error log file `%s': %s",
39                     eh.filename,strerror(errno));
40     }
41     free(eh.filename);
42   }
43   eh.handling= 0;
44   eh.file= 0; eh.filename= 0; eh.filekeep= 0;
45 }
46
47 static void senderrmsg(const char *errmsg, int useehandling) {
48   char suberrmsg[MAX_ERRMSG_LEN];
49   int e;
50   time_t now;
51   struct tm *lt;
52
53   switch (useehandling) {
54   case tokv_word_errorstostderr:
55     senderrmsgstderr(errmsg);
56     break;
57   case tokv_word_errorstosyslog:
58     ensurelogopen(eh.logfacility);
59     syslog(eh.loglevel,"%s",errmsg);
60     break;
61   case tokv_word_errorstofile:
62     if (time(&now)==-1) syscallerror("get current time");
63     lt= localtime(&now); if (!lt) syscallerror("convert current time");
64     if (fprintf(eh.file,"%d-%02d-%02d %02d:%02d:%02d: uservd: %s\n",
65                 lt->tm_year+1900, lt->tm_mon+1, lt->tm_mday,
66                 lt->tm_hour, lt->tm_min, lt->tm_sec,
67                 errmsg) == EOF) {
68       e= errno;
69       closeerrorfile(); eh.handling= tokv_word_errorstofile;
70       snyprintf(suberrmsg,sizeof(suberrmsg),
71                 "error writing to error log file `%.*s': %s;"
72                 " reverting to errors-to-stderr",
73                 (int)(sizeof(suberrmsg)>>1),eh.filename,strerror(e));
74       senderrmsg(suberrmsg,eh.handling);
75       senderrmsg(errmsg,eh.handling);
76     }
77     break;
78   default:
79     abort();
80   }
81 }
82
83 static void errwhere(struct parser_state *tstate, char *bufput, int bufputlen) {
84   static const char suffix[]= "references ...";
85   char errmsg[MAX_ERRMSG_LEN];
86   
87   if (!tstate) {
88     strnycpy(bufput,"<initialisation>: ",bufputlen);
89     return;
90   }
91   if (!tstate->notedreferer && tstate->upstate && !tstate->upstate->isinternal) {
92     errwhere(tstate->upstate,errmsg,sizeof(errmsg)-sizeof(suffix));
93     strcat(errmsg,suffix);
94     senderrmsg(errmsg,eh.handling);
95     tstate->notedreferer= 1;
96   }
97   snyprintf(bufput,bufputlen,"%.*s:%d: ",bufputlen-10,
98             tstate->filename,tstate->reportlineno);
99 }
100
101 int parseerrprint(const char *fmt, ...) {
102   va_list al;
103   char errmsg[MAX_ERRMSG_LEN];
104
105   va_start(al,fmt);
106   errwhere(cstate,errmsg,sizeof(errmsg)>>1);
107   vsnytprintfcat(errmsg,sizeof(errmsg),fmt,al);
108   senderrmsg(errmsg,eh.handling);
109   va_end(al);
110
111   return tokv_error;
112 }
113
114 static int unexpected(int found, int wanted, const char *wantedstr) {
115   /* pass wanted==-1 if you know it's not what you wanted;
116    * otherwise this function will check it for you.
117    */
118   if (found == wanted) return 0;
119   if (found == tokv_error) return found;
120   return parseerrprint("found %s, expected %s",printtoken(found),wantedstr);
121 }
122
123 static int stringoverflow(const char *where) {
124   return parseerrprint("string buffer became far too large building %s",where);
125 }
126
127 /*
128  * General assistance functions
129  */
130
131 static void freecharparray(char **array) {
132   char **pp;
133
134   if (!array) return;
135   for (pp=array; *pp; pp++) free(*pp);
136   free(array);
137 }
138
139 static void countnewlines(void) {
140   char *p;
141   for (p=yytext; *p; p++)
142     if (*p == '\n')
143       cstate->lineno++;
144 }
145
146 static int dequote(char *inplace) {
147   char *p, *q, buf[4], *bep;
148   int v;
149
150   p=q=inplace;
151   assert(*p=='"');  p++;
152   while (*p && *p != '"') {
153     if (*p != '\\') { *q++= *p++; continue; }
154     switch (*++p) {
155     case 'n': *q++= '\n'; p++; continue;
156     case 'r': *q++= '\r'; p++; continue;
157     case 't': *q++= '\t'; p++; continue;
158     case 'x':
159       p++;
160       if (!((buf[0]= *p++) && (buf[1]= *p++)))
161         return parseerrprint("quoted string ends inside \\x<hex> sequence");
162       buf[2]= 0;
163       v= strtoul(buf,&bep,16);
164       if (bep != buf+2)
165         return parseerrprint("invalid \\<hex> sequence \\x%s in quoted string",buf);
166       assert(!(v & ~0xff));
167       *q++= v;
168       continue;
169     default:
170       if (ISCHAR(isalpha,*p))
171         return parseerrprint("unknown \\<letter> sequence \\%c in quoted string",*p);
172       if (ISCHAR(isdigit,*p)) {
173         if (!((buf[0]= *p++) && (buf[1]= *p++) && (buf[2]= *p++))) abort();
174         buf[3]= 0; v= strtoul(buf,&bep,8);
175         if (bep != buf+3 || (v & ~0xff))
176           return parseerrprint("invalid \\<octal> sequence \\%s in quoted string",buf);
177         *q++= v; continue;
178       } else if (ISCHAR(ispunct,*p)) {
179         *q++= *p++; continue;
180       } else {
181         while (*p==' ' || *p=='\t') p++;
182         v= *p++; assert(v=='\n');
183       }
184     }
185   }
186   assert(*p); p++; assert(!*p);
187   *q++= 0;
188   return tokv_quotedstring;
189 }
190
191 const char *printtoken(int token) {
192   /* Returns pointer to static buffer, overwritten by next call. */
193   static const char keywordfmt[]= "keyword `%s'";
194   static const char operatorfmt[]= "operator `%s'";
195   
196   static char buf[250];
197   
198   char *q;
199   const char *p;
200   int i, c, l;
201   
202   if ((token & tokm_repres) == tokr_word) {
203     assert(strlen(yytext)+sizeof(keywordfmt)<sizeof(buf));
204     snyprintf(buf,sizeof(buf),keywordfmt,yytext);
205     return buf;
206   } else if (token & tokt_number) {
207     snyprintf(buf,sizeof(buf),"number %d",lr_min); return buf;
208   } else if (token & tokt_fdrange && token & tokr_word) {
209     snyprintf(buf,sizeof(buf),"fd %s",buf); return buf;
210   } else if (token & tokt_fdrange && lr_max==-1) {
211     snyprintf(buf,sizeof(buf),"fdrange %d-",lr_min); return buf;
212   } else if (token & tokt_fdrange) {
213     snyprintf(buf,sizeof(buf),"fdrange %d-%d",lr_min,lr_max); return buf;
214   } else if ((token & tokm_repres) == tokr_punct) {
215     assert(strlen(yytext)+sizeof(operatorfmt)<sizeof(buf));
216     snyprintf(buf,sizeof(buf),operatorfmt,yytext);
217     return buf;
218   } else if (token & tokt_string) {
219     switch (token) {
220     case tokv_barestring: strcpy(buf,"unquoted string (bare word)"); break;
221     case tokv_quotedstring: strcpy(buf,"quoted string"); break;
222     default: abort();
223     }
224     strcat(buf," `");
225     l= strlen(buf); i= sizeof(buf)-l-2; p= yytext; q= buf+l;
226     while ((c= *p++)) {
227       if (i-- <= 0) { q--; strcpy(q-3,"..."); break; }
228       if (ISCHAR(isspace,c)) c= ' ';
229       else if (!ISCHAR(isprint,c) || ISCHAR(iscntrl,c)) c= '?';
230       else *q++= c;
231     }
232     strcpy(q,"'");
233     return buf;
234   } else {
235     switch (token) {
236     case tokv_lwsp:    return "linear whitespace";
237     case tokv_newline: return "newline (or comment followed by newline)";
238     case tokv_eof:     return "end of input file";
239     case tokv_error:   return "syntax error token";
240     default:
241       sprintf(buf,"token#0%o",token); return buf;
242     }
243   }
244 }
245
246 static const char *string2path(const char *in) {
247   /* Returned pointers become invalid on next call.
248    * May return 0, having printed an error message.
249    */
250   static char *p;
251   static int pl;
252   
253   if (strncmp(in,"~/",2)) return in;
254   if (makeroom(&p,&pl,strlen(serviceuser_dir)+1+strlen(in+2)+1)) {
255     stringoverflow("pathname");
256     return 0;
257   }
258   snyprintf(p,pl,"%s/%s",serviceuser_dir,in+2);
259   return p;
260 }
261
262 /*
263  * Parser component functions for parsing parameters to directives
264  *
265  * Functions pa_... parse just one parameter,
266  *  and return tokv_error or 0, having scanned exactly what they were expecting
267  * Functions paa_... parse complete parameter lists, including the leading lwsp,
268  *  and return tokv_error or 0, having scanned up to and including the newline
269  *
270  * For any function which takes `const char **rv' the
271  * value returned in *rv is overwritten by repeated calls to
272  * any of those functions (whether the same or another).
273  */
274
275 static int pa_mnl(void) {
276   return unexpected(yylex(),tokv_newline,"newline");
277 }
278 static int pa_mwsp(void) {
279   return unexpected(yylex(),tokv_lwsp,"linear whitespace");
280 }
281
282 static int pa_string(const char **rv) {
283   static char *p= 0;
284   static int pl= 0;
285
286   int r, l;
287
288   r= pa_mwsp(); if (r) return r;
289   r= yylex(); if (r == tokv_error) return r;
290   if ((r & tokm_repres) == tokr_nonstring) return unexpected(r,-1,"string");
291   l= strlen(yytext)+1;
292   if (makeroom(&p,&pl,l)) return stringoverflow("string argument");
293   strcpy(p,yytext); *rv= p;
294
295   return 0;
296 }  
297
298 static int pa_numberdollar(int *value_r) {
299   /* Also parses the whitespace beforehand. */
300   int r;
301
302   r= pa_mwsp(); if (r) return r;
303   r= yylex(); if (r == tokv_error || r == tokv_dollar) return r;
304   if (unexpected(r,tokv_ordinal,"expected number or dollar")) return tokv_error;
305   *value_r= lr_min;
306   return r;
307 }
308
309 static int paa_1string(const char **rv) {
310   int r;
311
312   r= pa_string(rv); if (r) return r;
313   return pa_mnl();
314 }  
315
316 static int paa_1path(const char **rv) {
317   const char *cp;
318   int r;
319   
320   r= paa_1string(&cp); if (r) return r;
321   *rv= string2path(cp); if (!*rv) return tokv_error;
322   return 0;
323 }
324
325 static int paa_pathargs(const char **path_r, char ***newargs_r) {
326   /* Repeated calls do _not_ overwrite newargs_r; caller must free.
327    * Repeated calls _do_ overwrite string returned in path_r.
328    * Any call to this function invalidates previous returns in *rv.
329    */
330   char **newargs;
331   const char *string;
332   int used, size, r;
333
334   r= pa_string(&string); if (r == tokv_error) return r;
335   *path_r= string2path(string); if (!*path_r) return tokv_error;
336   
337   used=0; size=0;
338   newargs= xmalloc(sizeof(char*)*(size+1));
339
340   for (;;) {
341     r= yylex(); if (r == tokv_error) goto error;
342     if (r==tokv_newline) break;
343     if (unexpected(r,tokv_lwsp,"newline after or whitespace between arguments")) {
344       r= tokv_error; goto error;
345     }
346     r= yylex(); if (r==tokv_error) goto error;
347     if ((r & tokm_repres) == tokr_nonstring) {
348       r= unexpected(r,-1,"string for command argument");
349       goto error;
350     }
351     if (used>=size) {
352       if (used >= MAX_ARGSDEFVAR) {
353         r= parseerrprint("far too many arguments to service program");
354         goto error;
355       }
356       size= (used+5)<<1;
357       newargs= xrealloc(newargs,sizeof(char*)*(size+1));
358     }
359     newargs[used++]= xstrsave(yytext);
360   }
361   newargs[used]= 0;
362   *newargs_r= newargs;
363   return 0;
364   
365 error:
366   newargs[used]=0;
367   freecharparray(newargs);
368   return r;
369 }
370
371 static int paa_message(const char **message_r) {
372   /* Returned value is invalidated by repeated calls. */
373   static char *buildbuf;
374   static int buildbuflen;
375   const char *usetext;
376
377   int r, tl;
378
379   r= pa_mwsp(); if (r) return r;
380   tl= 1;
381   if (makeroom(&buildbuf,&buildbuflen,50)) return stringoverflow("start of message");
382   buildbuf[0]= 0;
383   for (;;) {
384     r= yylex(); if (r == tokv_error) return r;
385     if (r == tokv_eof)
386       return parseerrprint("unexpected end of file in message text");
387     if (r == tokv_newline) break;
388     usetext= r == tokv_lwsp ? " " : yytext;
389     tl+= strlen(usetext);
390     if (makeroom(&buildbuf,&buildbuflen,tl)) return stringoverflow("message");
391     strcat(buildbuf,usetext);
392   }
393   *message_r= buildbuf;
394   return 0;
395 }
396
397 /*
398  * Skipping routines (used by e.g. the `if' code).
399  */
400
401 static int skiptoeol(void) {
402   /* Returns 0 if OK, having just parsed the newline
403    * or tokv_error if an error occurs, leaving the position at the error
404    * (which may be EOF or a syntax error token).
405    */
406   int token;
407
408   do { token= yylex(); }
409   while (token != tokv_newline && !(token & tokt_exception));
410   if (token == tokv_newline) return 0;
411   if (token == tokv_error) return token;
412   assert(token == tokv_eof);
413   return parseerrprint("unexpected end of file while looking for end of line");
414 }
415
416 static int skip(int allowce) {
417   /* Scans a piece of config without executing it.  Returns
418    * tokv_error (leaving the parsing state at the error),
419    * or the tokt_controlend token with type allowce if one
420    * was found (in which case rest of line, including any whitespace
421    * after tokt_controlend, has not been parsed), or tokv_eof.
422    */
423   int token, r;
424
425   for (;;) { /* loop over lines */
426     cstate->reportlineno= cstate->lineno;
427     do { token= yylex(); } while (token == tokv_lwsp || token == tokv_newline);
428     if (token & tokt_exception) {
429       return token;
430     } else if (token & tokt_controlend) {
431       if (allowce == lr_controlend) return token;
432       else return unexpected(token,-1,"control structure end of a different kind");
433     } else if (token & tokt_controlstart) {
434       r= token;
435       while (r & tokt_controlstart) {
436         r= skiptoeol(); if (r) return r;
437         cstate->reportlineno= cstate->lineno;
438         r= skip(token); if (r & tokt_exception) return r;
439       }
440     } else if (!(token & tokt_directive) && !(token & tokt_condop)) {
441       return parseerrprint("not a directive (or conditional operator) "
442                            "while looking for control structure end");
443     }
444     r= skiptoeol(); if (r) return r;
445   }
446 }
447
448 /*
449  * Routines for parsing and getting the values of parameters
450  */
451
452 static void parm_1string(char ***rvalues, const char *tocopy) {
453   char **a;
454   a= xmalloc(sizeof(char*)*2);
455   a[0]= xstrsave(tocopy);
456   a[1]= 0;
457   *rvalues= a;
458 }
459
460 static char *parm_ulong(unsigned long ul) {
461   char *p;
462   int l;
463
464   l= CHAR_BIT*sizeof(unsigned long)/3+4;
465   p= xmalloc(l);
466   snyprintf(p,l,"%lu",ul);
467   return p;
468 }
469
470 static int parm_usernameuid(char ***rvalues, const char *name, uid_t id) {
471   char **a;
472   
473   a= xmalloc(sizeof(char*)*3);
474   a[0]= xstrsave(name);
475   a[1]= parm_ulong(id);
476   a[2]= 0;
477   *rvalues= a;
478   return 0;
479 }
480
481 static int parm_groups(char ***rvalues, int size,
482                        gid_t *gids, const char *const *groups) {
483   char **a;
484   int i;
485   
486   if (size >= 2 && gids[0] == gids[1]) { size--; gids++; groups++; }
487   a= xmalloc(sizeof(char*)*(size+1)*2);
488   for (i=0; i<size; i++) {
489     a[i]= xstrsave(groups[i]);
490     a[size+i]= parm_ulong(gids[i]);
491   }
492   a[size*2]= 0;
493   *rvalues= a;
494   return 0;
495 }  
496
497 static int pf_service(int ptoken, char ***rvalues) {
498   parm_1string(rvalues,service); return 0;
499 }
500
501 static int pf_callinguser(int ptoken, char ***rvalues) {
502   return parm_usernameuid(rvalues,loginname,request_mbuf.callinguid);
503 }
504
505 static int pf_serviceuser(int ptoken, char ***rvalues) {
506   return parm_usernameuid(rvalues,serviceuser,serviceuser_uid);
507 }
508
509 static int pf_callinggroup(int ptoken, char ***rvalues) {
510   return parm_groups(rvalues,request_mbuf.ngids,calling_gids,calling_groups);
511 }
512
513 static int pf_servicegroup(int ptoken, char ***rvalues) {
514   return parm_groups(rvalues,service_ngids,service_gids,service_groups);
515 }
516
517 static int pf_callingusershell(int ptoken, char ***rvalues) {
518   parm_1string(rvalues,callinguser_shell); return 0;
519 }
520
521 static int pf_serviceusershell(int ptoken, char ***rvalues) {
522   parm_1string(rvalues,serviceuser_shell); return 0;
523 }
524
525 static int pa_parameter(char ***rvalues, char **rname) {
526   /* Scans a single parameter token and calls the appropriate parameter
527    * function, returning tokv_error (leaving the parser state wherever),
528    * or 0 on success (having just parsed the parameter name).
529    * If rname is non-null then the name of the parameter (malloc'd) will
530    * be stored in it.
531    *
532    * Caller must free *rvalues using freecharparray.
533    */
534   int token, r, i;
535   char *name;
536
537   token= yylex(); if (token == tokv_error) return token;
538   name= xstrsave(yytext);
539   if ((token & tokm_repres) != tokr_nonstring &&
540       !memcmp(yytext,"u-",2) && strlen(yytext)>=3) {
541     for (i=0;
542          i<request_mbuf.nvars && strcmp(yytext+2,defvararray[i].key);
543          i++);
544     if (i>=request_mbuf.nvars) {
545       *rvalues= xmalloc(sizeof(char*));
546       **rvalues= 0;
547     } else {
548       parm_1string(rvalues,defvararray[i].value);
549     }
550   } else if (token & tokt_parameter) {
551     r= (lr_parameter)(token,rvalues);
552     if (r) { free(name); return r; }
553   } else {
554     free(name);
555     return unexpected(token,-1,"parameter name");
556   }
557   debug_dumpparameter(name,*rvalues);
558   if (rname) *rname= name;
559   else free(name);
560   return 0;
561 }
562
563 /*
564  * Routines for parsing conditions, including
565  * parameter-based conditional functions (parmcondition's).
566  */
567
568 int pcf_glob(int ctoken, char *const *pv, int *rtrue) {
569   int token, actrue, r;
570   char *const *pp;
571
572   actrue= 0;
573   r= pa_mwsp(); if (r) return r;
574   for (;;) {
575     token= yylex();
576     if ((token & tokm_repres) == tokr_nonstring)
577       return unexpected(token,-1,"glob pattern");
578     for (pp= pv; !actrue && *pp; pp++) if (!fnmatch(yytext,*pp,0)) actrue= 1;
579     token= yylex(); 
580     if (token == tokv_newline) break;
581     if (unexpected(token,tokv_lwsp,"newline after or whitespace between glob patterns"))
582       return tokv_error;
583   }
584   *rtrue= actrue;
585   return 0;
586 }
587
588 int pcf_range(int ctoken, char *const *pv, int *rtrue) {
589   int mintoken, min, maxtoken, max, r;
590   char *const *pp;
591   char *ep;
592   unsigned long v;
593
594   r= pa_mwsp(); if (r) return r;
595   mintoken= pa_numberdollar(&min); if (mintoken == tokv_error) return mintoken;
596   r= pa_mwsp(); if (r) return r;
597   maxtoken= pa_numberdollar(&max); if (maxtoken == tokv_error) return maxtoken;
598   r= pa_mnl(); if (r) return r;
599   for (pp= pv; *pp; pp++) {
600     v= strtoul(*pp,&ep,10); if (*ep) continue;
601     if (mintoken != tokv_dollar && v < min) continue;
602     if (maxtoken != tokv_dollar && v > max) continue;
603     *rtrue= 1; return 0;
604   }
605   *rtrue= 0; return 0;
606 }
607
608 int pcf_grep(int ctoken, char *const *pv, int *rtrue) {
609   FILE *file;
610   const char *cp;
611   char *const *pp;
612   char *buf, *p;
613   int r, maxlen, l, c, actrue, posstrue;
614   
615   r= paa_1path(&cp); if (r) return r;
616   file= fopen(cp,"r");
617   if (!file)
618     return parseerrprint("unable to open file `%s' for grep: %s",cp,strerror(errno));
619   maxlen= 0;
620   for (pp= pv; *pp; pp++) { l= strlen(*pp); if (l > maxlen) maxlen= l; }
621   buf= xmalloc(maxlen+2); actrue= 0; c= 0;
622   while (!actrue && c!=EOF) {
623     c= getc(file); if (c==EOF) break;
624     if (ISCHAR(isspace,c)) continue;
625     l= maxlen+1; p= buf;
626     while (l>0 && c!='\n' && c!=EOF) { *p++= c; l--; c= getc(file); } 
627     if (c=='\n' || c==EOF || ISCHAR(isspace,c)) {
628       while (p>buf && ISCHAR(isspace,p[-1])) --p;
629       *p= 0; posstrue= 0;
630       for (pp= pv; !posstrue && *pp; pp++)
631         if (!strcmp(*pp,buf)) posstrue= 1;
632     } else {
633       posstrue= 0;
634     }
635     if (c!='\n' && c!=EOF) {
636       for (;;) {
637         c= getc(file);
638         if (c==EOF || c=='\n') break;
639         if (!ISCHAR(isspace,c)) posstrue= 0;
640       }
641     }
642     if (posstrue) actrue= 1;
643   }
644   if (ferror(file)) {
645     parseerrprint("error while reading `%s' for grep: %s",cp,strerror(errno));
646     fclose(file); free(buf); return tokv_error;
647   }
648   assert(actrue || feof(file));
649   fclose(file); free(buf); *rtrue= actrue;
650   return 0;
651
652
653 static int pa_condition(int *rtrue) {
654   /* Scans up to and including the newline following the condition;
655    * may scan more than one line if the condition is a multi-line
656    * one.  Returns 0 (setting *rtrue, and parsing up to and including
657    * the last newline) or tokv_error.
658    * Expects to scan the whitespace before its condition.
659    */
660   int r, token, andor, ctrue, actrue;
661   char **parmvalues;
662
663   r= pa_mwsp(); if (r) return r;
664   token= yylex();
665   if (token == tokv_error) {
666     return token;
667   } else if (token == tokv_not) {
668     r= pa_condition(&ctrue); if (r) return r;
669     *rtrue= !ctrue; return 0;
670   } else if (token == tokv_openparen) {
671     andor= 0; actrue= -1;
672     for (;;) {
673       cstate->reportlineno= cstate->lineno;
674       r= pa_condition(&ctrue); if (r) return r;
675       switch (andor) {
676       case 0:         assert(actrue==-1); actrue= ctrue;           break;
677       case tokv_and:  assert(actrue>=0); actrue= actrue && ctrue;  break;
678       case tokv_or:   assert(actrue>=0); actrue= actrue || ctrue;  break;
679       default:        abort();
680       }
681       do { token= yylex(); } while (token == tokv_lwsp);
682       if (token == tokv_error) return token;
683       if (token == tokv_closeparen) break;
684       if (andor) {
685         r= unexpected(token,andor,"same conjunction as before"); if (r) return r;
686       } else {
687         if (token != tokv_and && token != tokv_or)
688           return unexpected(token,-1,"first conjunction inside connective");
689         andor= token;
690       }
691     }
692     r= pa_mnl(); if (r) return r;
693     *rtrue= actrue; return 0;
694   } else if (token & tokt_parmcondition) {
695     r= pa_mwsp(); if (r) return r;
696     r= pa_parameter(&parmvalues,0); if (r) return r;
697     r= (lr_parmcond)(token,parmvalues,rtrue); freecharparray(parmvalues);
698     return r;
699   } else {
700     return unexpected(token,-1,"condition");
701   }
702 }
703
704 /*
705  * Directive functions and associated `common code' functions
706  */
707
708 /* Directives specifying the service program (execute-... and reset) */
709
710 static void execreset(void) {
711   execute= 0;
712   execbuiltin= 0;
713   free(execpath); execpath= 0;
714   freecharparray(execargs); execargs= 0;
715 }
716
717 int df_reject(int dtoken) {
718   int r;
719   
720   r= pa_mnl(); if (r) return r;
721   execreset();
722   execute= tokv_word_reject;
723   return 0;
724 }
725
726 int df_executefrompath(int dtoken) {
727   int r;
728   
729   r= pa_mnl(); if (r) return r;
730   execreset();
731   execute= tokv_word_executefrompath;
732   return 0;
733 }
734
735 int df_execute(int dtoken) {
736   const char *rv;
737   char **newargs;
738   int r;
739
740   r= paa_pathargs(&rv,&newargs); if (r) return r;
741   execreset();
742   execute= tokv_word_execute;
743   execargs= newargs;
744   execpath= xstrsave(rv);
745   return 0;
746 }
747
748 int df_executefromdirectory(int dtoken) {
749   const char *p, *q, *rv;
750   struct stat stab;
751   char *fn, **newargs;
752   int l, r;
753
754   r= paa_pathargs(&rv,&newargs); if (r) return r;
755   p= strrchr(service,'/'); if (p) p++; else p= service;
756   if (!*p || !ISCHAR(isalnum,*p)) {
757     parseerrprint("execute-from-directory requires initial char of service "
758                   "portion to be alphanumeric (service portion was `%s')",
759                   p);
760     freecharparray(newargs);
761     return tokv_error;
762   }
763   for (q=p+1; *q; q++) {
764     if (!ISCHAR(isalnum,*q) && *q != '-') {
765       parseerrprint("execute-from-directory requires service portion to "
766                     "contain only alphanumerics and hyphens (was `%s')",
767                     p);
768       freecharparray(newargs);
769       return tokv_error;
770     }
771   }
772   l= strlen(rv)+1+strlen(p)+1;
773   fn= xmalloc(l);
774   snyprintf(fn,l,"%s/%s",rv,p);
775   if (stat(fn,&stab)) {
776     if (errno == ENOENT) { free(fn); freecharparray(newargs); return 0; }
777     parseerrprint("failed to stat `%s' for execute-from-directory: %s",
778                   fn,strerror(errno));
779     free(fn); freecharparray(newargs); return tokv_error;
780   }
781   if (!S_ISREG(stab.st_mode)) {
782     parseerrprint("file `%s' in execute-from-directory is not an ordinary file"
783                   " or link to one (mode=0%lo)",fn,(unsigned long)stab.st_mode);
784     free(fn); freecharparray(newargs); return tokv_error;
785   }
786   execreset();
787   execute= tokv_word_executefromdirectory;
788   execargs= newargs;
789   execpath= fn;
790   return 0;
791 }
792
793 /* Parsing builtin service requests (execute-builtin) */
794
795 static int bispa_none(char ***rnewargs) {
796   return pa_mnl();
797 }
798
799 static int bispa_parameter(char ***rnewargs) {
800   int r, i;
801   char **parmvalues, *name, **newargs;
802   
803   r= pa_mwsp(); if (r) return r;
804   r= pa_parameter(&parmvalues,&name); if (r) return r;
805   for (i=0; parmvalues[i]; i++);
806   newargs= xmalloc(sizeof(char*)*(i+2));
807   newargs[0]= name;
808   memcpy(newargs+1,parmvalues,sizeof(char*)*(i+1));
809   free(parmvalues);
810   r= pa_mnl(); if (r) { free(newargs); return r; }
811   *rnewargs= newargs;
812   return 0;
813 }
814
815 int df_executebuiltin(int dtoken) {
816   int r;
817   builtinserviceexec_fnt *bisexec;
818   char *newpath, **newargs;
819
820   r= pa_mwsp(); if (r) return r;
821   r= yylex(); if (r == tokv_error) return r;
822   if (!(r & tokt_builtinservice)) return unexpected(r,-1,"builtin service name");
823   bisexec= lr_bisexec;
824   newpath= xstrsave(yytext);
825   newargs= 0;
826   r= lr_bispa(&newargs); if (r) { free(newpath); return r; }
827
828   execreset();
829   execute= tokv_word_executebuiltin;
830   execbuiltin= bisexec;
831   execpath= newpath;
832   execargs= newargs;
833   return 0;
834 }
835
836 /* Directives for changing other execution parameters */
837
838 int dfg_setflag(int dtoken) {
839   int r;
840
841   r= pa_mnl(); if (r) return r;
842   *lr_flag= lr_flagval;
843   return 0;
844 }
845
846 int df_reset(int dtoken) {
847   int r;
848
849   r= pa_mnl(); if (r) return r;
850   r= parse_string(RESET_CONFIGURATION,"<builtin reset configuration>",1);
851   return r;
852 }
853
854 int dfg_fdwant(int dtoken) {
855   int fdmin, fdmax, r, needreadwrite, havereadwrite, fd;
856
857   needreadwrite= lr_fdwant_readwrite;
858   r= pa_mwsp(); if (r) return r;
859   r= yylex(); if (r == tokv_error) return r;
860   if (!(r & tokt_fdrange)) return unexpected(r,-1,"file descriptor range");
861   fdmin= lr_min; fdmax= lr_max;
862   if (fdmin<0 || fdmin>MAX_ALLOW_FD ||
863       (fdmax != -1 && fdmax<0) || fdmax>MAX_ALLOW_FD)
864     return parseerrprint("file descriptor in range is negative or far too large");
865   r= yylex(); if (r == tokv_error) return r;
866   if (r == tokv_newline) {
867     if (needreadwrite > 0)
868       return parseerrprint("read or write is required");
869     havereadwrite= 0;
870   } else if (r == tokv_lwsp) {
871     if (needreadwrite < 0)
872       return parseerrprint("read or write not allowed");
873     r= yylex(); if (r == tokv_error) return r;
874     if (!(r & tokt_readwrite))
875       return unexpected(r,-1,"read or write (or perhaps newline)");
876     havereadwrite= r;
877     r= pa_mnl(); if (r) return r;
878   } else {
879     return unexpected(r,-1,"whitespace before read or write or newline");
880   }
881   ensurefdarray(fdmin);
882   if (fdmax == -1) {
883     if (!(dtoken == tokv_word_rejectfd || dtoken == tokv_word_ignorefd))
884       return parseerrprint("unspecified maximum only allowed"
885                            " with reject-fd and ignore-fd");
886     fdmax= fdarrayused-1;
887     restfdwantstate= dtoken;
888     restfdwantrw= havereadwrite;
889   }
890   ensurefdarray(fdmax);
891   for (fd=fdmin; fd<=fdmax; fd++) {
892     fdarray[fd].wantstate= dtoken;
893     fdarray[fd].wantrw= havereadwrite;
894   }
895   return 0;
896 }
897
898 /* Directives for changing error handling */
899
900 int df_errorstostderr(int dtoken) {
901   int r;
902   
903   r= pa_mnl(); if (r) return r;
904   closeerrorfile(); eh.handling= dtoken;
905   return 0;
906 }
907
908 int df_errorstosyslog(int dtoken) {
909   int token, level, facility;
910
911   facility= DEFUSERLOGFACILITY;
912   level= DEFUSERLOGLEVEL;
913   token= yylex();
914   if (token == tokv_lwsp) {
915     token= yylex(); if (token == tokv_error) return token;
916     if (!(token & tokt_logfacility))
917       return unexpected(token,-1,"syslog facility (or end of line)");
918     facility= lr_logfacility;
919     token= yylex();
920   }    
921   if (token == tokv_lwsp) {
922     token= yylex(); if (token == tokv_error) return token;
923     if (!(token & tokt_loglevel))
924       return unexpected(token,-1,"syslog level (or end of line) after facility");
925     level= lr_loglevel;
926     token= yylex();
927   }
928   if (unexpected(token,tokv_newline,"end of line after errors-to-syslog"))
929     return tokv_error;
930   closeerrorfile(); eh.handling= tokv_word_errorstosyslog;
931   eh.logfacility= facility; eh.loglevel= level;
932   return 0;
933 }
934
935 int df_errorstofile(int dtoken) {
936   const char *cp;
937   FILE *file;
938   int r;
939   
940   r= paa_1path(&cp); if (r) return r;
941   file= fopen(cp,"a");
942   if (!file)
943     return parseerrprint("unable to open error log file `%s': %s",cp,strerror(errno));
944   if (setvbuf(file,0,_IOLBF,MAX_ERRMSG_LEN)) {
945     parseerrprint("unable to set line buffering on errors file: %s",strerror(errno));
946     fclose(file); return tokv_error;
947   }
948   closeerrorfile(); eh.handling= tokv_word_errorstofile;
949   eh.file= file; eh.filename= xstrsave(cp);
950   return 0;
951 }
952
953 /* Directives for including other files or configuration data */
954
955 int dfi_includeuserrcfile(int dtoken) {
956   int r;
957
958   r= pa_mnl(); if (r) return r;
959   assert(userrcfile);
960   return parse_file(userrcfile,0);
961 }
962
963 int dfi_includeclientconfig(int dtoken) {
964   int r;
965
966   r= pa_mnl(); if (r) return r;
967   assert(overridedata);
968   return parse_string(overridedata,"<configuration override data>",0);
969 }
970
971 int df_include(int dtoken) {
972   const char *cp;
973   int r, found;
974
975   r= paa_1path(&cp); if (r) return r;
976   r= parse_file(cp,&found); if (r) return r;
977   if (found || dtoken == tokv_word_includeifexist) return 0;
978   return parseerrprint(dtoken == tokv_word_includesysconfig ?
979                        "system configuration file `%s' does not exist" :
980                        "included file `%s' does not exist",
981                        cp);
982 }
983
984 int df_includedirectory(int dtoken) {
985   static char *buildbuf=0;
986   static int buildbuflen=0;
987   
988   int r, cpl, tel, c, found;
989   DIR *d;
990   struct dirent *de;
991   const char *p, *cpget;
992   char *cp;
993   
994   r= paa_1path(&cpget); if (r) return r;
995   d= opendir(cpget);
996   if (!d)
997     return parseerrprint("unable to open directory `%s': %s",cpget,strerror(errno));
998   cp= xstrsave(cpget);
999   cpl= strlen(cp);
1000   while ((de= readdir(d))) {
1001     tel= strlen(de->d_name);
1002     if (!tel) continue;
1003     p= de->d_name;
1004     if (!*p || !ISCHAR(isalnum,*p)) continue;
1005     while ((c= *++p)) if (!(ISCHAR(isalnum,c) || c=='-')) break;
1006     if (c) continue;
1007     if (makeroom(&buildbuf,&buildbuflen,cpl+1+tel+1)) {
1008       stringoverflow("pathname in directory");
1009       r= tokv_error; goto x_err;
1010     }
1011     snyprintf(buildbuf,buildbuflen,"%s/%s",cp,de->d_name);
1012     r= parse_file(buildbuf,&found); if (r) goto x_err;
1013     if (!found) {
1014       r= parseerrprint("unable to open file `%s' in included directory `%s': %s",
1015                        de->d_name,cp,strerror(errno));
1016       goto x_err;
1017     }
1018   }
1019   if (closedir(d)) {
1020     parseerrprint("error closing directory `%s': %s",cp,strerror(errno));
1021     free(cp);
1022     return tokv_error;
1023   }
1024   free(cp);
1025   return 0;
1026
1027 x_err:
1028   closedir(d);
1029   free(cp);
1030   return r;
1031 }
1032
1033 int df_includelookup(int dtoken) {
1034   static char *buildbuf=0;
1035   int buildbuflen=0;
1036   
1037   char **parmvalues, **pp, *p, *q, *cp;
1038   const char *cpget;
1039   struct stat stab;
1040   int r, done, thisdone, cpl, c;
1041
1042   r= pa_mwsp(); if (r) return r;
1043   r= pa_parameter(&parmvalues,0); if (r) return r;
1044   r= paa_1path(&cpget); if (r) { freecharparray(parmvalues); return r; }
1045   if (stat(cpget,&stab)) {
1046     parseerrprint("unable to access directory `%s': %s",cpget,strerror(errno));
1047     freecharparray(parmvalues); return tokv_error;
1048   }
1049   if (!S_ISDIR(stab.st_mode)) {
1050     parseerrprint("object `%s' is not a directory or link to one",cpget);
1051     freecharparray(parmvalues); return tokv_error;
1052   }
1053   done= 0;
1054   cp= xstrsave(cpget);
1055   cpl= strlen(cp);
1056   if (!parmvalues[0]) {
1057     if (makeroom(&buildbuf,&buildbuflen,cpl+1+sizeof(NONEINCLUDELOOKUP))) {
1058       stringoverflow("pathname in directory for lookup of undefined parameter");
1059       r= tokv_error; goto x_err;
1060     }
1061     snyprintf(buildbuf,buildbuflen,"%s/" NONEINCLUDELOOKUP,cp);
1062     r= parse_file(buildbuf,&thisdone); if (r) goto x_err;
1063     if (thisdone) done= 1;
1064   } else {
1065     for (pp=parmvalues;
1066          *pp && (!done || dtoken == tokv_word_includelookupall);
1067          pp++) {
1068       if (makeroom(&buildbuf,&buildbuflen,
1069                    cpl+1+strlen(*pp)*2+3+sizeof(EMPTYINCLUDELOOKUP)+1)) {
1070         stringoverflow("pathname in directory for lookup");
1071         r= tokv_error; goto x_err;
1072       }
1073       strcpy(buildbuf,cp);
1074       p= *pp; q= buildbuf+cpl;
1075       *q++= '/';
1076       if (!*p) {
1077         strcpy(q,EMPTYINCLUDELOOKUP);
1078       } else {
1079         if (*p=='.') *q++= ':';
1080         while ((c= *p++)) {
1081           if (c=='/') {
1082             *q++= ':';
1083             c= '-';
1084           } else if (!((c >= '0' && c <= '9') ||
1085                        (c >= 'a' && c <= 'z') ||
1086                        c == '-' || c == '_')) {
1087             *q++= ':';
1088           }
1089           *q++= c;
1090         }
1091         *q++= 0;
1092       }
1093       r= parse_file(buildbuf,&thisdone);
1094       if (r) goto x_err;
1095       if (thisdone) done= 1;
1096     }
1097   }
1098   if (!done) {
1099     if (makeroom(&buildbuf,&buildbuflen,
1100                  cpl+1+sizeof(DEFAULTINCLUDELOOKUP))) {
1101       stringoverflow("pathname in directory for lookup of default");
1102       r= tokv_error; goto x_err;
1103     }
1104     snyprintf(buildbuf,buildbuflen,"%s/" DEFAULTINCLUDELOOKUP,cp);
1105     r= parse_file(buildbuf,0); if (r) goto x_err;
1106   }
1107   r= 0;
1108   
1109 x_err:
1110   freecharparray(parmvalues);
1111   free(cp);
1112   return r;
1113 }
1114
1115 /* Control constructs */
1116
1117 int df_catchquit(int dtoken) {
1118   int r;
1119
1120   r= pa_mnl(); if (r) return r;
1121   r= parser(tokv_word_catchquit);
1122   if (r == tokv_quit || r == tokv_error) {
1123     if (r == tokv_error) {
1124       r= parse_string(RESET_CONFIGURATION,
1125                       "<builtin reset configuration (caught error)>",1);
1126       assert(!r);
1127     }
1128     r= skip(tokv_word_catchquit);
1129   }
1130   if (r & tokt_controlend) {
1131     assert(r == tokv_word_hctac);
1132     r= pa_mnl();
1133   }
1134   return r;
1135 }
1136
1137 int df_if(int dtoken) {
1138   int r, true, done;
1139   
1140   done= 0;
1141   do {
1142     r= pa_condition(&true); if (r) return r;
1143     if (!done && true) { r= parser(tokv_word_if); done= 1; }
1144     else { r= skip(tokv_word_if); }
1145     if (!(r & tokt_controlend)) return r;
1146   } while (r == tokv_word_elif);
1147   if (r == tokv_word_else) {
1148     r= pa_mnl(); if (r) return r;
1149     cstate->reportlineno= cstate->lineno;
1150     if (done) r= skip(tokv_word_if);
1151     else r= parser(tokv_word_if);
1152     if (!(r & tokt_controlend)) return r;
1153   }
1154   if (unexpected(r,tokv_word_fi,"`fi' to end `if'")) return tokv_error;
1155   return pa_mnl();
1156 }
1157
1158 int df_errorspush(int dt) {
1159   struct error_handling save;
1160   int r;
1161
1162   r= pa_mnl(); if (r) return r;
1163
1164   save= eh;
1165   eh.filekeep= 1;
1166
1167   r= parser(tokv_word_errorspush);
1168
1169   closeerrorfile();
1170   eh= save;
1171
1172   if (r & tokt_controlend) {
1173     assert(r == tokv_word_srorre);
1174     r= pa_mnl();
1175   }
1176   return r;
1177 }
1178
1179 /* Miscelleanous directives */
1180
1181 int df_cd(int dtoken) {
1182   const char *cp;
1183   int r;
1184
1185   r= paa_1path(&cp); if (r) return r;
1186   if (!chdir(cp)) return 0;
1187   return parseerrprint("unable to change directory to `%s': %s",cp,strerror(errno));
1188 }
1189
1190 int df_userrcfile(int dtoken) {
1191   const char *cp;
1192   int r;
1193
1194   r= paa_1path(&cp); if (r) return r;
1195   free(userrcfile); userrcfile= xstrsave(cp);
1196   return 0;
1197 }
1198
1199 int df_message(int dtoken) {
1200   const char *mp;
1201   int r;
1202
1203   r= paa_message(&mp); if (r) return r;
1204   parseerrprint("`message' directive: %s",mp);
1205   return 0;
1206 }
1207
1208 int df_error(int dtoken) {
1209   const char *mp;
1210   int r;
1211
1212   r= paa_message(&mp); if (r) return r;
1213   return parseerrprint("`error' directive: %s",mp);
1214 }
1215
1216 int df_eof(int dtoken) {
1217   int r;
1218
1219   r= pa_mnl(); if (r) return r;
1220   return tokv_eof;
1221 }
1222
1223 int df_quit(int dtoken) {
1224   int r;
1225
1226   r= pa_mnl(); if (r) return r;
1227   return tokv_quit;
1228 }
1229
1230 /*
1231  * Main parser routines
1232  */
1233       
1234 static void parser_push(struct parser_state *usestate,
1235                         const char *newfile,
1236                         const struct stat *newfilestab,
1237                         YY_BUFFER_STATE ybuf,
1238                         int isinternal) {
1239   usestate->lineno= 1;
1240   usestate->reportlineno= 1;
1241   usestate->filename= newfile;
1242   usestate->filestab= *newfilestab;
1243   usestate->notedreferer= 0;
1244   usestate->isinternal= isinternal;
1245   usestate->ybuf= ybuf;
1246   usestate->upstate= cstate;
1247
1248   cstate= usestate;
1249   yy_switch_to_buffer(ybuf);
1250 }
1251
1252 static void parser_pop(void) {
1253   struct parser_state *oldstate;
1254
1255   oldstate= cstate;
1256   cstate= cstate->upstate;
1257   if (cstate) yy_switch_to_buffer(cstate->ybuf);
1258   yy_delete_buffer(oldstate->ybuf);
1259 }
1260
1261 int parse_string(const char *string, const char *descrip, int isinternal) {
1262   /* Returns the same things as parser, except that tokv_eof is turned
1263    * into 0.  *string must be statically allocated or copied, so that
1264    * it is not overwritten while the parsing takes place (unlike with
1265    * parse_file).
1266    */
1267   static const struct stat blankstab;
1268   
1269   struct parser_state usestate;
1270   YY_BUFFER_STATE ybuf;
1271   int r;
1272
1273   ybuf= yy_scan_string(string);
1274   if (!ybuf) syscallerror("unable to create flex buffer for internal string");
1275   parser_push(&usestate,descrip,&blankstab,ybuf,isinternal);
1276   
1277   r= parser(0);
1278
1279   parser_pop();
1280   if (r == tokv_eof) r= 0;
1281   return r;
1282 }
1283
1284 static int parse_file(const char *string, int *didexist) {
1285   /* Returns the same things as parser, except that tokv_eof is turned
1286    * into 0.  If *didexist is 0 then errno will have been set.
1287    * *string will be copied by parse_file so it may be be overwritten
1288    * during the parsing (so, for example, yytext need not be copied).
1289    */
1290   static int fileparselevel= 0;
1291   
1292   struct parser_state usestate, *checkrecurse;
1293   YY_BUFFER_STATE ybuf;
1294   int r;
1295   FILE *file;
1296   char *filename;
1297   struct stat newstab;
1298
1299   if (fileparselevel >= MAX_INCLUDE_NEST)
1300     return parseerrprint("too many nested levels of included files");
1301   file= fopen(string,"r");
1302   if (!file) {
1303     if (errno == ENOENT) {
1304       if (didexist) *didexist= 0;
1305       return 0;
1306     }
1307     return parseerrprint("unable to open config file `%s': %s",string,strerror(errno));
1308   }
1309   r= fstat(fileno(file),&newstab); if (r) syscallerror("unable to fstat new file");
1310   for (checkrecurse= cstate; checkrecurse; checkrecurse= checkrecurse->upstate) {
1311     if (!checkrecurse->filestab.st_mode) continue;
1312     if (newstab.st_dev==checkrecurse->filestab.st_dev &&
1313         newstab.st_ino==checkrecurse->filestab.st_ino) {
1314       fclose(file);
1315       return parseerrprint("recursion detected - config file `%s' calls itself",string);
1316     }
1317   }
1318   
1319   if (didexist) *didexist= 1;
1320
1321   ybuf= yy_create_buffer(file,YY_BUF_SIZE);
1322   if (!ybuf) syscallerror("unable to create flex buffer for file");
1323   filename= xstrsave(string);
1324   parser_push(&usestate,filename,&newstab,ybuf,0);
1325   fileparselevel++;
1326   
1327   r= parser(0);
1328   if (ferror(file))
1329     r= parseerrprint("error reading configuration file `%s'",string);
1330
1331   fileparselevel--;
1332   parser_pop();
1333   free(filename);
1334   fclose(file);
1335   if (r == tokv_eof) r= 0;
1336   return r;
1337 }
1338
1339 static int parser(int allowce) {
1340   /* Returns:
1341    *  an exception (error, eof or quit)
1342    *   then rest of `file' is uninteresting
1343    * or
1344    *  token if allowce was !0 and equal to token's controlend
1345    *   then rest of `file' (including rest of line with the
1346    *   controlend - even the whitespace) not scanned yet
1347    */
1348   int token, r;
1349
1350   for (;;) { /* loop over lines */
1351     cstate->reportlineno= cstate->lineno;
1352     do { token= yylex(); } while (token == tokv_lwsp);
1353     if (token & tokt_exception) {
1354       return token;
1355     } else if (token & tokt_controlend) {
1356       if (lr_controlend == allowce) return token;
1357       else return unexpected(token,-1,"directive (not this kind of"
1358                              " control structure end)");
1359     } else if (token & tokt_directive) {
1360       if ((token & tokt_internal) && !cstate->isinternal)
1361         return unexpected(token,-1,"published directive, not internal-use-only one");
1362       r= (lr_dir)(token); if (r) { assert(r & tokt_exception); return r; }
1363     } else if (token == tokv_newline) {
1364       /* ignore blank lines (and comment-only lines) */
1365     } else {
1366       return unexpected(token,-1,"directive");
1367     }
1368   }
1369 }