| 1 |
%{ |
| 2 |
/********************************************************************* |
| 3 |
* |
| 4 |
* Authors: Vincenzo Ciaschini - [email protected] |
| 5 |
* Valerio Venturi - [email protected] |
| 6 |
* |
| 7 |
* Copyright (c) Members of the EGEE Collaboration. 2004-2010. |
| 8 |
* See http://www.eu-egee.org/partners/ for details on the copyright holders. |
| 9 |
* |
| 10 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 11 |
* you may not use this file except in compliance with the License. |
| 12 |
* You may obtain a copy of the License at |
| 13 |
* |
| 14 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 15 |
* |
| 16 |
* Unless required by applicable law or agreed to in writing, software |
| 17 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 18 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 19 |
* See the License for the specific language governing permissions and |
| 20 |
* limitations under the License. |
| 21 |
* |
| 22 |
* Parts of this code may be based upon or even include verbatim pieces, |
| 23 |
* originally written by other people, in which case the original header |
| 24 |
* follows. |
| 25 |
* |
| 26 |
*********************************************************************/ |
| 27 |
#include "config.h" |
| 28 |
#include <stdio.h> |
| 29 |
#include <string.h> |
| 30 |
#include <stdlib.h> |
| 31 |
#include <ctype.h> |
| 32 |
|
| 33 |
#include "parsertypes.h" |
| 34 |
#include "listfunc.h" |
| 35 |
|
| 36 |
char **parse_subjects(char *string); |
| 37 |
void signingerror(void *policies, void *scanner, char const *msg); |
| 38 |
extern int signinglex(void *, void *scanner); |
| 39 |
%} |
| 40 |
|
| 41 |
%error-verbose |
| 42 |
%pure-parser |
| 43 |
%name-prefix="signing" |
| 44 |
%parse-param {struct policy ***policies} |
| 45 |
%parse-param {void *scanner} |
| 46 |
%lex-param {void *scanner} |
| 47 |
|
| 48 |
%union{ |
| 49 |
char *string; |
| 50 |
struct condition *cond; |
| 51 |
struct policy *policy; |
| 52 |
void *array; |
| 53 |
} |
| 54 |
|
| 55 |
%token <string> SUBJECTS |
| 56 |
%token COND_SUBJECTS |
| 57 |
%token COND_BANNED |
| 58 |
%token GLOBUS |
| 59 |
%token POS_RIGHTS |
| 60 |
%token NEG_RIGHTS |
| 61 |
%token CA_SIGN |
| 62 |
%token ACCESS_ID_CA |
| 63 |
%token ACCESS_ID_ANYBODY |
| 64 |
%token X509 |
| 65 |
|
| 66 |
%type <policy> eacl_entry |
| 67 |
%type <policy> access_identity |
| 68 |
%type <cond> realcondition |
| 69 |
%type <array> restrictions |
| 70 |
%type <policy> access_identities |
| 71 |
%% |
| 72 |
|
| 73 |
eacl: eacl_entry { *policies = (struct policy **)listadd((char**)(*policies), (char*)($1)); } |
| 74 |
| eacl eacl_entry { *policies = (struct policy **)listadd((char**)(*policies), (char*)($2)); } |
| 75 |
|
| 76 |
eacl_entry: access_identities POS_RIGHTS GLOBUS CA_SIGN restrictions { |
| 77 |
if ($1) { |
| 78 |
$$->conds = (struct condition**)($5); |
| 79 |
} |
| 80 |
$$ = $1; |
| 81 |
} |
| 82 |
| access_identities NEG_RIGHTS GLOBUS CA_SIGN restrictions { |
| 83 |
/* Ignore this. Globus does. */ |
| 84 |
free($1); |
| 85 |
$$ = NULL; |
| 86 |
} |
| 87 |
|
| 88 |
access_identities: access_identity { |
| 89 |
$$ = $1; |
| 90 |
} |
| 91 |
|
| 92 |
restrictions: realcondition { |
| 93 |
$$ = listadd(NULL, (char*)($1)); |
| 94 |
} |
| 95 |
| realcondition restrictions { |
| 96 |
$$ = listadd($2, (char*)($1)); |
| 97 |
} |
| 98 |
|
| 99 |
|
| 100 |
access_identity: ACCESS_ID_CA X509 SUBJECTS { |
| 101 |
$$ = (struct policy *)calloc(1, sizeof(struct policy)); |
| 102 |
|
| 103 |
if ($$) { |
| 104 |
char **subjects = parse_subjects($3); |
| 105 |
$$->caname = strdup(subjects[0]); |
| 106 |
free(subjects); |
| 107 |
$$->type = TYPE_SIGNING; |
| 108 |
} |
| 109 |
|
| 110 |
if ($$ && !$$->caname) { |
| 111 |
free($$); |
| 112 |
$$ = NULL; |
| 113 |
} |
| 114 |
} |
| 115 |
| ACCESS_ID_ANYBODY { |
| 116 |
$$ = (struct policy *)calloc(1, sizeof(struct policy)); |
| 117 |
} |
| 118 |
|
| 119 |
realcondition: COND_SUBJECTS GLOBUS SUBJECTS { |
| 120 |
$$ = (struct condition*)malloc(sizeof(struct condition)); |
| 121 |
if ($$) { |
| 122 |
$$->positive = 1; |
| 123 |
$$->original = strdup($3); |
| 124 |
$$->subjects = parse_subjects($$->original); |
| 125 |
if (!$$->subjects) { |
| 126 |
free($$->original); |
| 127 |
free($$); |
| 128 |
$$ = NULL; |
| 129 |
} |
| 130 |
} |
| 131 |
} |
| 132 |
| COND_BANNED GLOBUS SUBJECTS { |
| 133 |
$$ = (struct condition*)malloc(sizeof(struct condition)); |
| 134 |
|
| 135 |
if ($$) { |
| 136 |
$$->positive = 0; |
| 137 |
$$->original = strdup($3); |
| 138 |
$$->subjects = parse_subjects($$->original); |
| 139 |
if (!$$->subjects) { |
| 140 |
free($$->original); |
| 141 |
free($$); |
| 142 |
$$ = NULL; |
| 143 |
} |
| 144 |
} |
| 145 |
} |
| 146 |
; |
| 147 |
|
| 148 |
%% |
| 149 |
|
| 150 |
char **parse_subjects(char *string) |
| 151 |
{ |
| 152 |
char **list = NULL; |
| 153 |
char divider; |
| 154 |
|
| 155 |
if (!string) |
| 156 |
return NULL; |
| 157 |
|
| 158 |
do { |
| 159 |
divider = string[0]; |
| 160 |
|
| 161 |
if (divider == '\'' || divider == '"') { |
| 162 |
char *end = strchr(string + 1, divider); |
| 163 |
if (!end) |
| 164 |
return list; |
| 165 |
*end = '\0'; |
| 166 |
|
| 167 |
list = (char**)listadd(list, string+1); |
| 168 |
string = ++end; |
| 169 |
while (isspace(*string)) |
| 170 |
string++; |
| 171 |
} |
| 172 |
else if (divider == '\0') |
| 173 |
break; |
| 174 |
else { |
| 175 |
list = (char**)listadd(list, string); |
| 176 |
string += strlen(string); |
| 177 |
} |
| 178 |
} while (string && string[0] != '\0'); |
| 179 |
|
| 180 |
return list; |
| 181 |
} |
| 182 |
|
| 183 |
#if 0 |
| 184 |
int main() |
| 185 |
{ |
| 186 |
signingdebug = 1; |
| 187 |
void **arg = NULL; |
| 188 |
void *scanner=NULL; |
| 189 |
signinglex_init(&scanner); |
| 190 |
signingset_debug(1, scanner); |
| 191 |
return signingparse(arg, scanner); |
| 192 |
} |
| 193 |
#endif |
| 194 |
void signingerror(UNUSED(void *policies), UNUSED(void *scanner), UNUSED(char const *msg)) |
| 195 |
{ |
| 196 |
} |