blob: 543d4042f058539e16236bfb521d792b8f5c9e1c [file] [log] [blame]
Brian Waters13d96012017-12-08 16:53:31 -06001/*****************************************************************************************************
2 * Software License Agreement (BSD License)
3 * Author : Souheil Ben Ayed <souheil@tera.ics.keio.ac.jp>
4 *
5 * Copyright (c) 2009-2010, Souheil Ben Ayed, Teraoka Laboratory of Keio University, and the WIDE Project
6 * All rights reserved.
7 *
8 * Redistribution and use of this software in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
10 *
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 *
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 *
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by Souheil Ben Ayed <souheil@tera.ics.keio.ac.jp>.
21 *
22 * 4. Neither the name of Souheil Ben Ayed, Teraoka Laboratory of Keio University or the WIDE Project nor the
23 * names of its contributors may be used to endorse or promote products
24 * derived from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' AND ANY
27 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
28 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
29 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY
30 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
31 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
33 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 *****************************************************************************************************/
37
38
39%{
40#include <stdio.h>
41#include "diameap_common.h"
42#include "diameap.tab.h"
43
44void yyerror (YYLTYPE *llocp, struct diameap_conf * config, const char *s);
45
46extern int yywrap();
47extern int yylex();
48
49
50/* The Lex parser prototype */
51int diameaplex(YYSTYPE *lvalp, YYLTYPE *llocp);
52
53
54%}
55
56%locations
57%parse-param {struct diameap_conf * config}
58%pure_parser
59/*%defines */
60%error-verbose
61%debug
62
63%union {
64 char *str;
65 int val;
66 char byte;
67}
68
69
70
71/* In case of error in the lexical analysis */
72%token LEX_ERROR
73
74%token <val> NUM
75
76%token <str> iSTRING
77
78%token <byte> iBYTE
79
80%token EAPMETHOD
81%token AUTHORIZE
82%token MODE
83%token DIAMEAP_MYSQL
84%token MAX_INVALID_EAP_PACKET
85%token MULTI_ROUND_TIMEOUT
86%token CHECK_USER_IDENTITY
87
88%%
89
90confparams : /* empty */
91 | confparams EAPmethod
92 | confparams Authorize
93 | confparams DiamEAP_MySQL
94 | confparams MAX_Invalid_EAP_Packet
95 | confparams Multi_Round_Timeout
96 | confparams Check_User_Identity
97 | confparams errors
98 {
99 yyerror(&yylloc, config, "Unrecognized configuration parameter.");
100 return EINVAL;
101 }
102 ;
103
104errors : LEX_ERROR
105 | error
106 ;
107
108
109EAPmethod : EAPMETHOD '=' iSTRING ':' NUM ':' NUM ':' iSTRING ':' iSTRING ';'
110 {
111 char * infile, *cfile;
112 FILE * fl;
113
114 infile = $9;
115 fl = fopen(infile, "r");
116 if ((fl == NULL) && (*infile != '/')) {
117 char * tmpfile=infile;
118 CHECK_MALLOC_DO( infile = malloc( strlen(tmpfile) + strlen(DEFAULT_EXTENSIONS_PATH) + 2 ),
119 { yyerror (&yylloc, config, "Not enough memory"); YYERROR; } );
120 sprintf(infile, DEFAULT_EXTENSIONS_PATH "/%s", tmpfile);
121 free(tmpfile);
122 fl = fopen(infile, "r");
123 }
124 if (fl == NULL) {
125 int ret = errno;
126 TRACE_DEBUG(INFO, "Unable to open %s plugin file %s for reading: %s", $3, infile, strerror(ret));
127 yyerror (&yylloc, config, "Error adding EAP Plugin");
128 YYERROR;
129 }
130 fclose(fl);
131
132 cfile = $11;
133
134 if(strlen(cfile)>0){
135 fl = fopen(cfile, "r");
136 if ((fl == NULL) && (*cfile != '/')) {
137 char * tmp = cfile;
138 CHECK_MALLOC_DO( cfile = malloc( strlen(tmp) + strlen(DEFAULT_CONF_PATH) + 2 ),
139 { yyerror (&yylloc, config, "Not enough memory"); YYERROR; } );
140 sprintf(cfile, DEFAULT_CONF_PATH "/%s", tmp);
141 free(tmp);
142 fl = fopen(cfile, "r");
143 }
144 if (fl == NULL) {
145
146 }
147 if(fl)
148 fclose(fl);
149 }
150
151 diameap_plugin_add($3,(char)$5,(char)$7,infile,cfile);
152 }
153 ;
154
155Authorize : AUTHORIZE '=' NUM ';'
156 {
157 if((int)$3)
158 config->authorize=1;
159 }
160 ;
161
162
163DiamEAP_MySQL : DIAMEAP_MYSQL '=' iSTRING ',' iSTRING ',' iSTRING ',' iSTRING ';'
164 {
165 diameap_set_mysql_param($3,$5,$7,$9);
166 }
167 ;
168
169MAX_Invalid_EAP_Packet : MAX_INVALID_EAP_PACKET '=' NUM ';'
170 {
171 config->max_invalid_eap_packet=(int)$3;
172 };
173
174Multi_Round_Timeout : MULTI_ROUND_TIMEOUT '=' NUM ';'
175 {
176 config->multi_round_time_out=(unsigned int)$3;
177 };
178
179Check_User_Identity: CHECK_USER_IDENTITY '=' NUM ';'
180 {
181 if((int)$3){
182 check_user_identity = TRUE;
183 }else{
184 check_user_identity = FALSE;
185 }
186 };
187
188
189%%
190
191void yyerror(YYLTYPE *llocp, struct diameap_conf * config,const char *str)
192{
193 fprintf(stderr,"Error in %s ( on line %i column %i -> line %i column %i) : %s\n",config->conffile, llocp->first_line, llocp->first_column, llocp->last_line, llocp->last_column, str);
194}