blob: 31559ebaaed8dc6ffd635933d50fdc3c8a684ed7 [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#include <stdio.h>
40#include "eap_tls.h"
41#include "eaptls.tab.h"
42
43void yyerror (YYLTYPE *llocp, struct tls_config * config, const char *s);
44
45extern int yywrap();
46extern int yylex();
47
48
49/* The Lex parser prototype */
50int eaptlslex(YYSTYPE *lvalp, YYLTYPE *llocp);
51
52
53%}
54
55%locations
56%parse-param {struct tls_config * config}
57%pure_parser
58/*%defines */
59%error-verbose
60%debug
61
62%union {
63 char *str;
64 int val;
65 char byte;
66}
67
68
69
70/* In case of error in the lexical analysis */
71%token LEX_ERROR
72
73%token <val> NUM
74
75%token <str> iSTRING
76
77%token <byte> iBYTE
78
79%token CERTS
80%token CAPATH
81%token CRLPATH
82%token CHECK_CN_USERNAME
83
84%%
85
86confparams : /* empty */
87 | confparams CERTS_files
88 | confparams CA_file
89 | confparams CRL_file
90 | confparams CHECK_CN_USERNAME_param
91 | confparams errors
92 {
93 return EINVAL;
94 }
95 ;
96
97errors : LEX_ERROR
98 | error
99 ;
100
101
102CERTS_files : CERTS '=' iSTRING ':' iSTRING ';'
103 {
104 char * certfile, *keyfile;
105 FILE * fl;
106
107 certfile = $3;
108 keyfile = $5;
109 if(certfile == NULL){
110 TRACE_DEBUG(INFO,"%s[EAP TLS plugin] certificate file missing in configuration file",DIAMEAP_EXTENSION);
111 yyerror (&yylloc, config, "cert file missing");
112 YYERROR;
113 }
114 if(keyfile == NULL){
115 TRACE_DEBUG(INFO,"%s[EAP TLS plugin] privateKey file missing in configuration file",DIAMEAP_EXTENSION);
116 yyerror (&yylloc, config, "privateKey file missing");
117 YYERROR;
118 }
119
120 fl = fopen(certfile, "r");
121 if ((fl == NULL) && (*certfile != '/')) {
122 char * tmpfile=certfile;
123 CHECK_MALLOC_DO( certfile = malloc( strlen(tmpfile) + strlen(DEFAULT_EXTENSIONS_PATH) + 2 ),
124 { yyerror (&yylloc, config, "Not enough memory"); YYERROR; } );
125 sprintf(certfile, DEFAULT_EXTENSIONS_PATH "/%s", tmpfile);
126 free(tmpfile);
127 fl = fopen(certfile, "r");
128 }
129 if (fl == NULL) {
130 int ret = errno;
131 TRACE_DEBUG(INFO,"%s[EAP TLS plugin] Unable to open certificate file %s for reading: %s",DIAMEAP_EXTENSION,certfile,strerror(ret));
132 yyerror (&yylloc, config, "Error configuring certificate for EAP-TLS");
133 YYERROR;
134 }
135 fclose(fl);
136
137 fl = fopen(keyfile, "r");
138 if ((fl == NULL) && (*keyfile != '/')) {
139 char * tmpfile=keyfile;
140 CHECK_MALLOC_DO( keyfile = malloc( strlen(tmpfile) + strlen(DEFAULT_EXTENSIONS_PATH) + 2 ),
141 { yyerror (&yylloc, config, "Not enough memory"); YYERROR; } );
142 sprintf(keyfile, DEFAULT_EXTENSIONS_PATH "/%s", tmpfile);
143 free(tmpfile);
144 fl = fopen(keyfile, "r");
145 }
146 if (fl == NULL) {
147 int ret = errno;
148 TRACE_DEBUG(INFO,"%s[EAP TLS plugin] Unable to open privateKey file %s for reading: %s",DIAMEAP_EXTENSION,keyfile,strerror(ret));
149 yyerror (&yylloc, config, "Error configuring privateKey for EAP-TLS");
150 YYERROR;
151 }
152 fclose(fl);
153
154 config->certfile = certfile;
155 config->keyfile = keyfile;
156 }
157 ;
158
159CA_file : CAPATH '=' iSTRING ';'
160 {
161 char * cafile;
162 FILE * fl;
163
164 cafile = $3;
165
166 if(cafile == NULL){
167 TRACE_DEBUG(INFO,"%s[EAP TLS plugin] CA file missing in configuration file",DIAMEAP_EXTENSION);
168 yyerror (&yylloc, config, "cert file missing");
169 YYERROR;
170 }
171
172 fl = fopen(cafile, "r");
173 if ((fl == NULL) && (*cafile != '/')) {
174 char * tmpfile=cafile;
175 CHECK_MALLOC_DO( cafile = malloc( strlen(tmpfile) + strlen(DEFAULT_EXTENSIONS_PATH) + 2 ),
176 { yyerror (&yylloc, config, "Not enough memory"); YYERROR; } );
177 sprintf(cafile, DEFAULT_EXTENSIONS_PATH "/%s", tmpfile);
178 free(tmpfile);
179 fl = fopen(cafile, "r");
180 }
181 if (fl == NULL) {
182 int ret = errno;
183 TRACE_DEBUG(INFO,"%s[EAP TLS plugin] Unable to open CA file %s for reading: %s",DIAMEAP_EXTENSION,cafile,strerror(ret));
184 yyerror (&yylloc, config, "Error configuring CA file for EAP-TLS");
185 YYERROR;
186 }
187 fclose(fl);
188 config->cafile=$3;
189 }
190 ;
191
192CRL_file : CRLPATH '=' iSTRING ';'
193 {
194 char * crlfile;
195 FILE * fl;
196
197 crlfile = $3;
198
199 if(crlfile == NULL){
200 TRACE_DEBUG(FULL+1,"%s[EAP TLS plugin] CRL file missing in configuration file",DIAMEAP_EXTENSION);
201
202 }else{
203
204 fl = fopen(crlfile, "r");
205 if ((fl == NULL) && (*crlfile != '/')) {
206 char * tmpfile=crlfile;
207 CHECK_MALLOC_DO( crlfile = malloc( strlen(tmpfile) + strlen(DEFAULT_EXTENSIONS_PATH) + 2 ),
208 { yyerror (&yylloc, config, "Not enough memory"); YYERROR; } );
209 sprintf(crlfile, DEFAULT_EXTENSIONS_PATH "/%s", tmpfile);
210 free(tmpfile);
211 fl = fopen(crlfile, "r");
212 }
213 if (fl == NULL) {
214 int ret = errno;
215 TRACE_DEBUG(INFO,"%s[EAP TLS plugin] Unable to open CRL file %s for reading: %s",DIAMEAP_EXTENSION,crlfile,strerror(ret));
216 yyerror (&yylloc, config, "Error configuring CRL file for EAP-TLS");
217 YYERROR;
218 }
219 fclose(fl);
220 }
221 config->crlfile=$3;
222 }
223 ;
224
225CHECK_CN_USERNAME_param :
226 CHECK_CN_USERNAME '=' NUM ';'
227 {
228 if((int)$3 == 0){
229 config->check_cert_cn_username = FALSE;
230 }
231 else
232 {
233 config->check_cert_cn_username = TRUE;
234 }
235 }
236 ;
237
238%%
239
240void yyerror(YYLTYPE *llocp, struct tls_config * config,const char *str)
241{
242 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);
243}