source: libabac/rt2.l @ d0efdec

mei_rt2
Last change on this file since d0efdec was 2e9455f, checked in by Mei <mei@…>, 11 years ago

1) added namespace
2) tweak ?This,
3) allowing linking role/oset as constraining conditions
4) adding access_tests regression testing that uses GENI's access policy
5) added couple multi contexts regression tests
6) add compression/uncompression calls to abac_encode_string/abac_decode_string
(libstrongwan only allows 512 char for attribute rule storage)
7) add attribute_now option to creddy that takes a whole char string for attribute
rule

  • Property mode set to 100644
File size: 8.6 KB
Line 
1%option stack
2%x BOOLEAN_S
3%x INTEGER_S
4%x FLOAT_S
5%x TIME_S
6%x URN_S
7%x STRING_S
8%x KEYID_S
9%x RANGE_S
10
11%top{
12#include <stdio.h>
13#include <string.h>
14/* lex generated one */
15#include "rt2.h"
16#include "abac_m64.h"
17
18static int debug=0;
19
20/* when using canned test string */
21char INPUT_LINE[] = "usc.playground <- usc.employee.friend";
22char *yyfptr = INPUT_LINE; /* assigned with default */
23char *yyfptr_encoded=NULL;
24
25/* with yacc */
26extern YYSTYPE yylval;
27
28#undef YY_INPUT
29#define YY_INPUT(buf,result,max_size) \
30    { \
31    if(yyfptr != NULL) { \
32      if(debug) printf("YY_INPUT, input max size is %d\n",max_size); \
33      char* c = strncpy(buf,yyfptr,max_size); \
34      if (max_size > 0) buf[max_size-1] = '\0'; \
35      if(strlen(yyfptr) > max_size) yyfptr = yyfptr + max_size-1;  \
36        else yyfptr=NULL; \
37      result = (c == NULL ) ? YY_NULL : strlen(buf); \
38      if(debug) printf("YY_INPUT, buf size is %d\n",result); \
39      } else { \
40         buf[0] = '\0'; \
41         result = YY_NULL; \
42    } \
43    }
44
45}
46
47DIGIT    [0-9]
48%%
49\.           { if(debug) fprintf(yyout, " DOT " );
50             return DOT; }
51keyid        { yylval.string=strdup(yytext);
52             if(debug) fprintf(yyout," KEYTYPE ");
53             return KEYTYPE; }
54<KEYID_S>[a-zA-Z0-9]+ {
55             yylval.string=strdup(yytext);
56             if(debug) fprintf(yyout," KEYID_CONSTANT ");
57             return KEYID_CONSTANT; }
58oset         { if(debug) fprintf(yyout," OSET ");
59             return OSET; }
60role         { if(debug) fprintf(yyout," ROLE ");
61             return ROLE; }
62principal    { if(debug) fprintf(yyout," PRINCIPAL ");
63             return PRINCIPAL; }
64this         { if(debug) fprintf(yyout," THIS ");
65             return THIS; }
66This         { if(debug) fprintf(yyout," THIS ");
67             return THIS; }
68integer      { yylval.string=strdup(yytext);
69             if(debug) fprintf(yyout," OTYPE(INTEGER) ");
70             return OTYPE; }
71<INTEGER_S>{DIGIT}+ {
72             yylval.string=strdup(yytext);
73             if(debug) fprintf(yyout," OTYPE_CONSTANT(INTEGER) ");
74             return OTYPE_CONSTANT; }
75<INTEGER_S>[-]{DIGIT}+ {
76             yylval.string=strdup(yytext);
77             if(debug) fprintf(yyout," OTYPE_CONSTANT(INTEGER) ");
78             return OTYPE_CONSTANT; }
79boolean      { yylval.string =strdup(yytext);
80             if(debug) fprintf(yyout," OTYPE(BOOLEAN) ");
81             return OTYPE; }
82<BOOLEAN_S>true|false {
83             yylval.string=strdup(yytext);
84             if(debug) fprintf(yyout," OTYPE_CONSTANT(BOOLEAN) ");
85             return OTYPE_CONSTANT; }
86<BOOLEAN_S,INTEGER_S,FLOAT_S,URN_S,STRING_S,TIME_S>[?][A-Z][\-_a-zA-Z0-9]* {
87             yylval.string=strdup(yytext+1);
88             if(debug) fprintf(yyout," VARIABLE_CONSTANT(%s) ",yylval.string);
89             return VARIABLE_CONSTANT; }
90<BOOLEAN_S,INTEGER_S,FLOAT_S,URN_S,STRING_S,TIME_S>[?] {
91             yylval.string=strdup(yytext+1);
92             if(debug) fprintf(yyout," QMARK ");
93             return QMARK; }
94<BOOLEAN_S,INTEGER_S,FLOAT_S,URN_S,STRING_S,TIME_S>\[ {
95             if(debug) fprintf(yyout," LSQUARE ");
96             return LSQUARE; }
97<BOOLEAN_S,INTEGER_S,FLOAT_S,URN_S,STRING_S,TIME_S>\] {
98             if(debug) fprintf(yyout," RSQUARE ");
99             return RSQUARE; }
100<BOOLEAN_S,INTEGER_S,FLOAT_S,URN_S,STRING_S,TIME_S>\: {
101             if(debug) fprintf(yyout," COLON ");
102             return COLON; }
103float        { yylval.string =strdup(yytext);
104             if(debug) fprintf(yyout," OTYPE(FLOAT) ");
105             return OTYPE; }
106<FLOAT_S>-{DIGIT}+"."{DIGIT}+ |
107<FLOAT_S>{DIGIT}+"."{DIGIT}+ |
108<FLOAT_S>{DIGIT}+ |
109<FLOAT_S>-{DIGIT}+ {
110             yylval.string=strdup(yytext);
111             if(debug) fprintf(yyout," OTYPE_CONSTANT(FLOAT) ");
112             return OTYPE_CONSTANT; }
113time         { yylval.string=strdup(yytext);
114             if(debug) fprintf(yyout," OTYPE(TIME) ");
115             return OTYPE; }
116<TIME_S>{DIGIT}{DIGIT}*"T"{DIGIT}* {
117             yylval.string=strdup(yytext);
118             if(debug) fprintf(yyout," OTYPE_CONSTANT(TIME) ");
119             return OTYPE_CONSTANT; }
120urn          { yylval.string=strdup(yytext);
121             if(debug) fprintf(yyout," OTYPE(URN) ");
122             return OTYPE; }
123<URN_S>[']([^']|\\')*['] |
124<URN_S>["]([^"]|\")*["] {
125             yylval.string=strdup(yytext);
126             if(debug) fprintf(yyout," OTYPE_CONSTANT(URN)(%s) ",yylval.string);
127             return OTYPE_CONSTANT; }
128string       { yylval.string=strdup(yytext);
129             if(debug) fprintf(yyout," OTYPE(STRING) ");
130             return OTYPE; }
131<STRING_S>[']([^']|\\')*['] |
132<STRING_S>["]([^"]|\")*["] {
133             yylval.string=strdup(yytext);
134             if(debug) fprintf(yyout," OTYPE_CONSTANT(STRING)(%s) ", yylval.string);
135             return OTYPE_CONSTANT; }
136<RANGE_S>\[ {
137             if(debug) fprintf(yyout," LSQUARE ");
138             return LSQUARE; }
139<RANGE_S>\] {
140             if(debug) fprintf(yyout," RSQUARE ");
141             return RSQUARE; }
142<RANGE_S>\.\. {
143             if(debug) fprintf(yyout," DOTDOT ");
144             return DOTDOT; }
145<RANGE_S>, {
146             if(debug) fprintf(yyout," COMMA ");
147             return COMMA; }
148<RANGE_S>true|false {
149             yylval.string=strdup(yytext);
150             if(debug) fprintf(yyout," VALUE(BOOLEAN)(%s) ", yylval.string);
151             return VALUE; }
152<RANGE_S>[']([^']|\\')*['] |
153<RANGE_S>["]([^"]|\")*["] {
154             yylval.string=strdup(yytext);
155             if(debug) fprintf(yyout," VALUE(STRING)(%s) ", yylval.string);
156             return VALUE; }
157<RANGE_S>{DIGIT}+ |
158<RANGE_S>-{DIGIT}+ |
159<RANGE_S>-{DIGIT}.{DIGIT}+ |
160<RANGE_S>{DIGIT}.{DIGIT}+ |
161<RANGE_S>{DIGIT}+T{DIGIT}+ {
162             yylval.string=strdup(yytext);
163             if(debug) fprintf(yyout," VALUE(%s) ",yylval.string);
164             return VALUE; }
165[a-zA-Z0-9][\-_a-zA-Z0-9]* {
166             yylval.string=strdup(yytext);
167             if(debug) fprintf(yyout," IDEN(%s) ", yylval.string);
168             return IDEN; }
169\<-          { if(debug) fprintf(yyout," DERIVE ");
170             return DERIVE; }
171&            { if(debug) fprintf(yyout, " AND " );
172             return AND; }
173,            { if(debug) fprintf(yyout, " COMMA ");
174             return COMMA; }
175\(           { if(debug) fprintf(yyout, " LPAREN ");
176             return LPAREN; }
177\)           { if(debug) fprintf(yyout, " RPAREN ");
178             return RPAREN; }
179\[           { if(debug) fprintf(yyout, " LSQUARE ");
180             return LSQUARE; }
181\]           { if(debug) fprintf(yyout, " RSQUARE ");
182             return RSQUARE; }
183\:           { if(debug) fprintf(yyout, " COLON ");
184             return COLON; }
185\?           { if(debug) fprintf(yyout, " QMARK ");
186             return QMARK; }
187\n           { /* ignore end-of-line */; }
188[ \t]+       { /* ignore whitespace */; }
189%%
190
191void abac_ll_reset_yyfptr(char *str) {
192    yyfptr=str;
193    yyfptr_encoded=abac_encode_string(str);
194}
195
196char* abac_ll_get_yyfptr() {
197    return yyfptr;
198}
199
200char *abac_ll_get_yyfptr_encoded() {
201    return yyfptr_encoded;
202}
203
204/* if using external file input, output */
205void abac_ll_reset_yyin(FILE *new_yyin) {
206    yyin=new_yyin;
207}
208
209void abac_ll_reset_yyout(FILE *new_yyout) {
210    if(yyout) {
211      fflush(yyout);
212      fclose(yyout);
213    }
214    yyout=new_yyout;
215}
216
217void abac_ll_flush_yyout() {
218    if(yyout)
219      fflush(yyout);
220}
221
222FILE *abac_ll_get_yyin() {
223    if(yyin) return yyin;
224    else return stdin;
225}
226FILE *abac_ll_get_yyout() {
227    if(yyout) return yyout;
228    else return stdout;
229}
230
231void abac_ll_push_keyid_yystate()
232{
233    if(debug) fprintf(yyout, "\n push keyid state\n");
234    yy_push_state(KEYID_S);
235}
236
237void abac_ll_push_range_yystate()
238{
239    if(debug) fprintf(yyout, "\n push range state\n");
240    yy_push_state(RANGE_S);
241}
242
243void abac_ll_push_yystate(char *str)
244{
245   if(strcmp(str,"boolean")==0) {
246      if(debug) fprintf(yyout, "\n push boolean state\n");
247      yy_push_state(BOOLEAN_S);
248      return;
249   }
250   if(strcmp(str,"integer")==0) {
251      if(debug) fprintf(yyout, "\n push integer state\n");
252      yy_push_state(INTEGER_S);
253      return;
254   }
255   if(strcmp(str,"float")==0) {
256      if(debug) fprintf(yyout, "\n push float state\n");
257      yy_push_state(FLOAT_S);
258      return;
259   }
260   if(strcmp(str,"time")==0) {
261      if(debug) fprintf(yyout, "\n push time state\n");
262      yy_push_state(TIME_S);
263      return;
264   }
265   if(strcmp(str,"urn")==0) {
266      if(debug) fprintf(yyout, "\n push urn state\n");
267      yy_push_state(URN_S);
268      return;
269   }
270   if(strcmp(str,"string")==0) {
271      if(debug) fprintf(yyout, "\n push string state\n");
272      yy_push_state(STRING_S);
273      return;
274   }
275   
276   if(debug) fprintf(yyout, "eek.. lost in push_state\n");
277}
278
279void abac_ll_pop_yystate()
280{
281   if(debug) fprintf(yyout, " pop a state\n");
282   yy_pop_state();
283}
Note: See TracBrowser for help on using the repository browser.