/[pdpsoft]/trunk/grid-mw-security/ees/plugin_examples/plugin_transformer/src/transformer.c
ViewVC logotype

Contents of /trunk/grid-mw-security/ees/plugin_examples/plugin_transformer/src/transformer.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2149 - (show annotations) (download) (as text)
Fri Jan 14 22:21:32 2011 UTC (11 years ago) by okoeroo
File MIME type: text/x-chdr
File size: 8803 byte(s)
The first (untested) implementation of the transformer plugin.
There are still some TODOs to fix.


1 #include "eef_plugin.h"
2 #include <getopt.h>
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <pwd.h>
6 #include <sys/stat.h>
7
8
9 #define SPECIAL_EES_OBLIGATION_LIST_ATTR_ID "http://authz-interop.org/xacml/attribute/trans-obligation"
10 #define SPECIAL_EES_OBLIGATION_LIST_DELIMITER "?attrId="
11
12
13 EES_PL_RC set_var_as_string(const char* name, char* value);
14 EES_PL_RC set_var_as_int(const char* name, int value);
15 EES_PL_RC set_var_as_void_p(const char* name, void* value, size_t size);
16 char* get_var_as_string(char* name);
17 int get_var_as_int(char* name);
18 void* get_var_as_void_p(char* name);
19
20
21 EES_PL_RC plugin_initialize(int argc, char* argv[]){
22 aos_dump_argslist();
23
24 return EES_PL_SUCCESS;
25 }
26
27
28 EES_PL_RC plugin_terminate(){
29 return EES_PL_SUCCESS;
30 }
31
32
33 EES_PL_RC plugin_run(){
34 aos_context_t *_context = NULL;
35 aos_attribute_t *_tmp_attr = NULL;
36 aos_context_t *_context_oblig = NULL;
37 aos_attribute_t *_tmp_attr_oblig = NULL;
38
39 char *_tmp_attr_id = NULL;
40 int i = 0;
41
42 /* TODO: needs to change */
43 char ** list_of_obligations = NULL;
44 int list_of_obligations_cnt = 0;
45 list_of_obligations = malloc (sizeof (char *) * 42);
46
47
48 EEF_log(LOG_INFO, "Running %s\n", EEF_getRunningPluginName());
49
50 /* Debug */
51 aos_dump_argslist();
52
53 /* Search for a special Environment attributeId that lists the Obligation Id's to search for and transform */
54 rewindContexts(NULL);
55 while((_context = getNextContext(ENVIRONMENT, NULL))){
56 rewindAttributes(_context);
57 while((_tmp_attr = getNextAttribute(_context))){
58 _tmp_attr_id = getAttributeId(_tmp_attr);
59 if(_tmp_attr_id){
60 if(strncmp(_tmp_attr_id, SPECIAL_EES_OBLIGATION_LIST_ATTR_ID, strlen(SPECIAL_EES_OBLIGATION_LIST_ATTR_ID)) == 1){
61 /* Get Obligation Name to fetch */
62 list_of_obligations[list_of_obligations_cnt] = getAttributeValueAsString (_tmp_attr);
63 list_of_obligations_cnt++;
64
65 /* TODO: remove limitation */
66 if(list_of_obligations_cnt == 42){
67 EEF_log(LOG_INFO, "Too many obligations to transform, sorry, going to fail. (hardcoded max is 42\n");
68 return EES_PL_FAILURE;
69 }
70 }
71 }
72 }
73 }
74
75
76 /* Search the Environment attributes for attributes to transform to Obligations, when found, register the obligations. */
77 for (i = 0; i < list_of_obligations_cnt; i++){
78 rewindContexts(NULL);
79 while((_context = getNextContext(ENVIRONMENT, NULL))){
80 rewindAttributes(_context);
81 while((_tmp_attr = getNextAttribute(_context))){
82 _tmp_attr_id = getAttributeId(_tmp_attr);
83 if(_tmp_attr_id){
84 if(strncmp(_tmp_attr_id, list_of_obligations[i], strlen(list_of_obligations[i])) == 0){
85 /* TODO: Each attribute will have its own obligation context, this must be optimized */
86 if((_context_oblig = createContext(OBLIGATION)) != NULL){
87 setContextObligationId(_context_oblig, list_of_obligations[i]);
88 if((_tmp_attr_oblig = createAttribute())){
89 /* TODO: Strip first part */
90 setAttributeId(_tmp_attr_oblig, getAttributeId(_tmp_attr));
91 setAttributeIssuer(_tmp_attr_oblig, getAttributeIssuer(_tmp_attr));
92 setAttributeType(_tmp_attr_oblig, getAttributeType(_tmp_attr));
93 setAttributeValue(_tmp_attr_oblig, getAttributeValueAsVoidPointer(_tmp_attr), 0);
94 addAttribute(_context, _tmp_attr_oblig);
95 }
96 addContext(_context);
97 }
98 }
99 }
100 }
101 }
102 }
103 return EES_PL_SUCCESS;
104 }
105
106
107
108 EES_PL_RC set_var_as_string(const char* name, char* value){
109 aos_context_t* context;
110 aos_attribute_t* attribute;
111 char* attribute_name;
112
113 if(value == NULL){
114 /*EEF_log(LOG_ERR, "Value cannot be NULL\n");*/
115 return EES_PL_FAILURE;
116 }
117
118 rewindContexts(NULL);
119 if((context = getNextContext(NONE, NULL)) == NULL){
120 if ((context = createContext (NONE)) != NULL){
121 addContext (context);
122 } else {
123 EEF_log(LOG_ERR, "Unable to get context\n");
124 return EES_PL_FAILURE;
125 }
126 }
127
128 /* store attribute names in AOS for lookup during run */
129 if((attribute = createAttribute())){
130 if(asprintf(&attribute_name, "%s_%s", name, EEF_getRunningPluginName())){
131 setAttributeId( attribute, attribute_name);
132 free(attribute_name);
133 }
134 setAttributeValue(attribute, (void*) value, strlen(value)+1);
135 addAttribute(context, attribute);
136 }
137
138 return EES_PL_SUCCESS;
139 }
140
141
142 EES_PL_RC set_var_as_void_p(const char* name, void* value, size_t size){
143 aos_context_t* context;
144 aos_attribute_t* attribute;
145 char* attribute_name;
146
147 /* store attribute names in AOS for lookup during run */
148
149 rewindContexts(NULL);
150 while((context = getNextContext(NONE, NULL))){
151 if(context){
152 break;
153 }
154 }
155 if(context == NULL){
156 context = createContext (NONE);
157 addContext (context);
158 }
159
160 if(context == NULL){
161 EEF_log(LOG_ERR, "Unable to get context\n");
162 return EES_PL_FAILURE;
163 }
164
165 if((attribute = createAttribute())){
166 if(asprintf(&attribute_name, "%s_%s", name, EEF_getRunningPluginName())){
167 setAttributeId( attribute, attribute_name);
168 free(attribute_name);
169 }
170 setAttributeValue(attribute, value, size);
171 addAttribute(context, attribute);
172 }
173 return EES_PL_SUCCESS;
174 }
175
176 EES_PL_RC set_var_as_int(const char* name, int value){
177 aos_context_t* context;
178 aos_attribute_t* attribute;
179 char* attribute_name;
180
181 /* store attribute names in AOS for lookup during run */
182
183 rewindContexts(NULL);
184 while((context = getNextContext(NONE, NULL))){
185 if(context){
186 break;
187 }
188 }
189 if(context == NULL){
190 context = createContext (NONE);
191 addContext (context);
192 }
193
194 if(context == NULL){
195 EEF_log(LOG_ERR, "Unable to get context\n");
196 return EES_PL_FAILURE;
197 }
198
199 if((attribute = createAttribute())){
200 if(asprintf(&attribute_name, "%s_%s", name, EEF_getRunningPluginName())){
201 setAttributeId( attribute, attribute_name);
202 free(attribute_name);
203 }
204 setAttributeValue(attribute, &value, sizeof(int));
205 addAttribute(context, attribute);
206 }
207 return EES_PL_SUCCESS;
208 }
209
210 char* get_var_as_string(char* name){
211 char* localname;
212 aos_context_t * context;
213 aos_attribute_t* attribute;
214
215 asprintf(&localname, "%s_%s", name, EEF_getRunningPluginName());
216
217 rewindContexts(NULL);
218 while((context = getNextContext(NONE, NULL))){
219 rewindAttributes(context);
220 while((attribute = getNextAttribute(context))){
221 if(strcmp(getAttributeId(attribute), localname) == 0){
222 free(localname);
223 return getAttributeValueAsString(attribute);
224 }
225 }
226 }
227 free(localname);
228 return NULL;
229 }
230
231 int get_var_as_int(char* name){
232 char* localname;
233 aos_context_t * context;
234 aos_attribute_t* attribute;
235
236 /* Free this */
237 asprintf(&localname, "%s_%s", name, EEF_getRunningPluginName());
238
239 rewindContexts(NULL);
240 while((context = getNextContext(NONE, NULL))){
241 rewindAttributes(context);
242 while((attribute = getNextAttribute(context))){
243 if(strcmp(getAttributeId(attribute), localname) == 0){
244 free(localname);
245 return getAttributeValueAsInt(attribute);
246 }
247 }
248 }
249 free(localname);
250 return -1;
251 }
252
253 void* get_var_as_void_p(char* name){
254 char* localname;
255 aos_context_t * context;
256 aos_attribute_t* attribute;
257
258 /* Free this */
259 asprintf(&localname, "%s_%s", name, EEF_getRunningPluginName());
260
261 rewindContexts(NULL);
262 while((context = getNextContext(NONE, NULL))){
263 rewindAttributes(context);
264 while((attribute = getNextAttribute(context))){
265 if(strcmp(getAttributeId(attribute), localname) == 0){
266 free(localname);
267 return *((void**) getAttributeValueAsVoidPointer(attribute));
268 }
269 }
270 }
271 free(localname);
272 return NULL;
273 }
274

grid.support@nikhef.nl
ViewVC Help
Powered by ViewVC 1.1.28