2 dnl lexer, passed through m4 with defs from langauge.i4
4 * Copyright (C)1996-1997 Ian Jackson
6 * This is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with userv; if not, write to the Free Software
18 * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
36 #include <sys/types.h>
49 typedef int directive_fnt(int dtoken);
50 static directive_fnt df_reject, df_execute, df_executefrompath;
51 static directive_fnt df_executefromdirectory, df_executebuiltin;
52 static directive_fnt df_errorstostderr, df_errorstosyslog, df_errorstofile;
53 static directive_fnt dfg_fdwant, dfg_setflag;
54 static directive_fnt df_reset, df_cd, df_userrcfile, df_include;
55 static directive_fnt df_includelookup, df_includedirectory;
56 static directive_fnt df_message, df_error, df_quit, df_eof;
57 static directive_fnt df_if, df_catchquit, df_errorspush;
58 static directive_fnt dfi_includeuserrcfile, dfi_includeclientconfig;
59 /* directive functions return:
60 * 0 for success having scanned up to and including end of line but not beyond,
61 * or tokv_error or tokv_quit.
62 * They expect to parse the whitespace before their parameters (if any).
65 typedef int parmcondition_fnt(int ctoken, char *const *parmvalues, int *rtrue);
66 static parmcondition_fnt pcf_glob, pcf_range, pcf_grep;
67 /* all conditional functions return tokv_error for failure or 0 for success
68 * at parsing and testing, in which case *rtrue is set to 0 or 1.
69 * On success they have scanned up to and including the condition's
70 * terminating newline; the pcf_... functions expect to parse the whitespace
71 * between the parameter name and the condition's arguments.
72 * Otherwise they return tokv_error.
73 * The parameter-based conditionals take a list of parameter values
74 * as obtained from the parameter functions and pa_parameter,
75 * and do _not_ free it.
78 typedef int parameter_fnt(int ptoken, char ***rvalues);
79 static parameter_fnt pf_service;
80 static parameter_fnt pf_callinguser, pf_serviceuser;
81 static parameter_fnt pf_callinggroup, pf_servicegroup;
82 static parameter_fnt pf_callingusershell, pf_serviceusershell;
83 /* Parameter functions return tokv_error or 0 for success at parsing
84 * and determining the value, in which case *rvalues is made to be
85 * a mallocd null-terminated array of pointers to mallocd strings.
86 * freeparm can be used to free such an array.
89 typedef int builtinserviceparse_fnt(char ***rnewargs);
90 static builtinserviceparse_fnt bispa_none, bispa_parameter;
91 /* These parse the arguments to a builtin service, including the
92 * newline at the end of the line. *rnewargs will initially be
93 * null, indicating that no arguments are to be set; the function
94 * may store a mallocd array of mallocd strings in it,
95 * containing the arguments it wishes to have set (null-pointer
99 static int yylex(void);
100 /* Returns a token (which may be an eof or error exception) */
102 static directive_fnt *lr_dir;
103 static parmcondition_fnt *lr_parmcond;
104 static builtinserviceparse_fnt *lr_bispa;
105 static builtinserviceexec_fnt *lr_bisexec;
106 static parameter_fnt *lr_parameter;
107 static int lr_loglevel, lr_logfacility, lr_min, lr_max, *lr_flag;
108 static int lr_flagval, lr_controlend;
109 static int lr_fdwant_readwrite; /* -1=never, 0=opt, 1=always */
111 /* Forward declarations of things used in lexer and parser */
113 struct parser_state {
114 int lineno, reportlineno, notedreferer, isinternal;
115 const char *filename;
116 struct stat filestab;
117 YY_BUFFER_STATE ybuf;
118 struct parser_state *upstate;
121 static struct parser_state *cstate;
123 struct error_handling {
124 int handling; /* One of the error handling modes tokt_ehandlemode */
125 int logfacility, loglevel;
126 int filekeep; /* File is in use by higher-level errors-push, leave it open */
131 static struct error_handling eh = { tokv_word_errorstostderr, 0,0,0,0,0 };
133 static int dequote(char *inplace);
149 lr_min=lr_max= (int)strtoul(yytext,&ep,10);
153 [0-9]{1,8}-[0-9]{1,8} {
155 lr_min= (int)strtoul(yytext,&ep,10);
156 assert(*ep == HYPHEN);
158 lr_max= (int)strtoul(ep,&ep,10);
160 if (lr_max < lr_min) {
161 parseerrprint("fd range has min > max");
168 lr_min= (int)strtoul(yytext,&ep,10);
169 assert(*ep == HYPHEN);
172 return tokv_fdstoend;
174 [\ \t]+ return tokv_lwsp;
175 [\ \t]*\n cstate->lineno++; return tokv_newline;
176 [\ \t]*\#[^\n]*\n cstate->lineno++; return tokv_newline;
178 parseerrprint("missing newline at eof after comment");
181 [^\ \t\n]+ return tokv_barestring;
182 \"([^\\\"\n]|\\[a-z]|\\[0-9]{3}|\\x[0-9A-Fa-f]{2}|\\[:punct:]|\\[ \t]*\n)*\" {
183 return dequote(yytext);
186 parseerrprint("misquoted or unterminated string");
189 <<EOF>> return tokv_eof;