/[pdpsoft]/trunk/grid-mw-security/ees/src/eval_man/pdl.c
ViewVC logotype

Contents of /trunk/grid-mw-security/ees/src/eval_man/pdl.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 891 - (show annotations) (download) (as text)
Sun Oct 11 14:00:29 2009 UTC (12 years, 3 months ago) by aramv
File MIME type: text/x-chdr
File size: 6301 byte(s)
Moved config_file_ok variable into C file
1 #include "pdl.h"
2
3 /* Lex/Yacc stuff */
4 extern FILE * yyin;
5 extern int yylex_destroy(void);
6 extern int yyparse(void);
7 extern int yylex(void);
8 static char* _pdl_path;
9 FILE* config_file;
10 static var_t* plugin_list;
11 static var_t* plugin_list_last;
12 static var_t* current_plugin;
13
14 /* globals */
15 EES_RC config_file_ok;
16
17 EES_RC pdl_init(const char* name){
18 if((config_file = fopen(name,"r")) != NULL){
19 yyin = config_file;
20 yyparse();
21 if(config_file_ok){
22 initialize_plugins();
23 }
24 return EES_SUCCESS;
25 } else {
26 eef_log(LOG_ERR, "Failed to open policy file");
27 return EES_FAILURE;
28 }
29 }
30
31 record_t* concat_strings(record_t* r1, record_t* r2){
32 record_t* new_record;
33 eef_log(LOG_DEBUG, "Concating: %s with %s\n", r1->string, r2->string);
34 if((new_record = malloc(sizeof(record_t)))){
35 if((new_record->string =
36 calloc(1, sizeof(char)*(strlen(r1->string) + strlen(r2->string)+1)))){
37 strncat(new_record->string, r1->string, strlen(r1->string));
38 strncat(new_record->string, r2->string, strlen(r2->string));
39 free(r1->string);
40 free(r1);
41 free(r2->string);
42 free(r2);
43 return new_record;
44 }
45 }
46 return NULL;
47 }
48
49 record_t* concat_strings_with_space(record_t *r1, record_t* r2){
50 record_t *r;
51 eef_log(LOG_DEBUG, "Concating: %s with %s with spaces\n", r1->string, r2->string);
52 if((r = malloc(sizeof(record_t)))){
53 r->string = calloc(1,(sizeof(char)*(strlen(r1->string)+strlen(r2->string)+2)));
54 strncat(r->string, r1->string, strlen(r1->string));
55 strncat(r->string, " ", 1);
56 strncat(r->string, r2->string, strlen(r2->string));
57 free(r1->string);
58 free(r1);
59 free(r2->string);
60 free(r2);
61 return r;
62 }
63 return NULL;
64 }
65
66 int yyerror(char* string){
67 eef_log(LOG_ERR, string);
68 return 0;
69 }
70
71 void set_path(record_t* path){
72 size_t path_size = 0;
73 size_t string_size = (sizeof(char) * (strlen(path->string)+2)); /* size of string + extra slash + null byte */
74 _pdl_path = "";
75
76 /*struct stat sb;*/
77 /*if stat(MODUL*/
78
79 eef_log(LOG_DEBUG, "Found a new path: %s\n", path->string);
80 if(string_size < FILENAME_MAX){
81 path_size = string_size;
82 } else {
83 path_size = FILENAME_MAX;
84 }
85
86 eef_log(LOG_DEBUG,"Modules path: %s\n", path->string);
87
88 if((_pdl_path = calloc(1, path_size))){
89 strncpy(_pdl_path, path->string, path_size);
90 strncat(_pdl_path, "/", 1);
91 }
92 free(path->string);
93 free(path);
94 }
95
96 void add_policy(record_t* policy, rule_t* rule){
97 eef_log(LOG_DEBUG, "Found a new policy: %s\n", policy->string);
98 free(policy->string);
99 free(policy);
100
101 /*free(rule->true_branch);*/
102 /*free(rule->false_branch);*/
103 /*free(rule);*/
104 }
105
106 const char* get_pdl_path(){
107 if(_pdl_path == NULL){
108 return "";
109 }
110 return _pdl_path;
111 }
112
113 rule_t* add_rule(record_t* state, record_t* true_branch, record_t* false_branch){
114 rule_t* new_rule = malloc(sizeof(rule_t));
115 if(state != NULL){
116 eef_log(LOG_DEBUG, "Added a new rule: %s\n", state->string);
117 }
118 if(true_branch != NULL){
119 eef_log(LOG_DEBUG, "True branch: %s\n", true_branch->string);
120 }
121 if(false_branch != NULL){
122 eef_log(LOG_DEBUG, "False branch: %s\n", false_branch->string);
123 }
124 if(state != NULL){
125 free(state->string);
126 }
127 free(state);
128 if(true_branch != NULL){
129 free(true_branch->string);
130 }
131 free(true_branch);
132 if(false_branch != NULL){
133 free(false_branch->string);
134 }
135 free(false_branch);
136 free(new_rule);
137 return new_rule;
138 }
139
140 void remove_policy(record_t* policy){
141 eef_log(LOG_DEBUG, "Deleted policy: %s\n", policy->string);
142 free(policy->string);
143 free(policy);
144 }
145
146 char** _var_to_argv(char* value, int *argc){
147 char *start_of_arg = NULL, *copy_of_value = NULL, **argv = NULL;
148 char *delimiters = " \t";
149 size_t size_of_arg = 0, size_of_array, i = 0;
150 char *str_ptr;
151 copy_of_value = strdup(value);
152 size_of_array = (sizeof(char)*(strlen(copy_of_value)+1));
153 if((argv = calloc(1, size_of_array)) != NULL){
154 start_of_arg = strtok_r(copy_of_value, delimiters, &str_ptr);
155 while(start_of_arg != NULL){
156 size_of_arg = (sizeof(char)*(strlen(start_of_arg)+1));
157 if((argv[i] = calloc(1, size_of_arg))){
158 memcpy(argv[i], start_of_arg, size_of_arg);
159 start_of_arg = strtok_r(NULL, delimiters, &str_ptr);
160 i++;
161 }
162 }
163 }
164 free(copy_of_value);
165 if(i < ARG_MAX){
166 *argc = i;
167 } else {
168 *argc = ARG_MAX;
169 }
170 return argv;
171 }
172
173 void add_variable(record_t* name, record_t* value){
174 eef_log(LOG_DEBUG, "Added variable name: %s\n", name->string);
175 eef_log(LOG_DEBUG, "Added variable value: %s\n", value->string);
176
177 /* allocate and fill fields */
178
179 if((current_plugin = malloc(sizeof(var_t)))){
180 current_plugin->lineno = name->lineno;
181 current_plugin->name = name->string;
182 current_plugin->value = value->string;
183 current_plugin->next = NULL;
184 } else {
185 eef_log(LOG_ERR, "Out of memory!");
186 }
187
188 /* append to the end of the list */
189
190 if(plugin_list){
191 plugin_list_last->next = current_plugin;
192 } else {
193 plugin_list = current_plugin;
194 }
195 plugin_list_last = current_plugin;
196
197 /* clean up */
198
199 free(name->string);
200 free(name);
201 free(value->string);
202 free(value);
203 }
204
205 EES_RC initialize_plugins(){
206 char** argv;
207 int argc;
208
209 var_t* last_plugin = NULL;
210 current_plugin = plugin_list;
211 while(current_plugin && config_file_ok){
212 /* prepare arguments and add to plug-in manager */
213 argv = _var_to_argv(current_plugin->value, &argc);
214 config_file_ok = addPlugin(argc, argv);
215 last_plugin = current_plugin;
216 current_plugin = current_plugin->next;
217 }
218 return EES_SUCCESS;
219 }
220
221 EES_RC clean_variables(){
222 var_t* last_plugin = NULL;
223 current_plugin = plugin_list;
224 while(current_plugin){
225 last_plugin = current_plugin;
226 current_plugin = current_plugin->next;
227 free(last_plugin);
228 }
229 return EES_SUCCESS;
230 }
231
232 EES_RC pdl_term(){
233 free(_pdl_path);
234 clean_variables();
235 if(config_file != NULL){
236 #if HAVE_YYLEX_DESTROY
237 yylex_destroy();
238 #endif
239 if((fclose(config_file)==0) ){
240 return EES_SUCCESS;
241 }
242 }
243 return EES_FAILURE;
244 }
245
246 EES_RC allow_rules(int val){
247 return EES_SUCCESS;
248 }
249
250 EES_RC allowed_policy_rule(const char* label){
251 return EES_SUCCESS;
252 }

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