/[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 783 - (show annotations) (download) (as text)
Mon Sep 14 15:22:35 2009 UTC (12 years, 4 months ago) by aramv
File MIME type: text/x-chdr
File size: 4832 byte(s)
Made _pdl_path and file extern
1 #include "pdl.h"
2 FILE* file;
3 char* _pdl_path;
4
5 EES_RC pdl_init(const char* name){
6 if((file = fopen(name,"r")) != NULL){
7 yyin = file;
8 yyparse();
9 return EES_SUCCESS;
10 } else {
11 ng_log(LOG_ERR, "Failed to open policy file");
12 return EES_FAILURE;
13 }
14 }
15
16 record_t* concat_strings(record_t* r1, record_t* r2){
17 record_t* new_record;
18 ng_log(LOG_DEBUG, "Concating: %s with %s", r1->string, r2->string);
19 printf("Concating: %s with %s\n", r1->string, r2->string);
20 if((new_record = malloc(sizeof(record_t)))){
21 if((new_record->string =
22 calloc(1, sizeof(char)*(strlen(r1->string) + strlen(r2->string)+1)))){
23 strcat(new_record->string, r1->string);
24 strcat(new_record->string, r2->string);
25 free(r1->string);
26 free(r1);
27 free(r2->string);
28 free(r2);
29 return new_record;
30 }
31 }
32 return NULL;
33 }
34
35 record_t* concat_strings_with_space(record_t *r1, record_t* r2){
36 record_t *r;
37 ng_log(LOG_DEBUG, "Concating: %s with %s", r1->string, r2->string);
38 printf("Concating: %s with %s\n", r1->string, r2->string);
39 if((r = malloc(sizeof(record_t)))){
40 if((r1->string[strlen(r1->string)-1]=='"') &&
41 (r2->string[strlen(r2->string)-1]=='"')){
42 r = concat_strings(r1, r2);
43 } else {
44 r->string = calloc(1,(sizeof(char)*(strlen(r1->string)+strlen(r2->string)+2)));
45 strcat(r->string, r1->string);
46 strcat(r->string, " ");
47 strcat(r->string, r2->string);
48 }
49 free(r1->string);
50 free(r1);
51 free(r2->string);
52 free(r2);
53 return r;
54 }
55 return NULL;
56 }
57
58 int yyerror(const char* string){
59 return ng_log(LOG_DEBUG, string);
60 }
61
62 void set_path(record_t* path){
63 size_t path_size = 0;
64 size_t string_size = (sizeof(char) * (strlen(path->string)+1));
65 ng_log(LOG_DEBUG, "Found a new path: %s\n", path->string);
66 if(string_size < FILENAME_MAX){
67 path_size = string_size;
68 } else {
69 path_size = FILENAME_MAX;
70 }
71
72 printf("Modules path: %s\n", path->string);
73
74 if((_pdl_path = calloc(1, path_size))){
75 strncpy(_pdl_path, path->string, path_size);
76 }
77 free(path->string);
78 free(path);
79 }
80
81 void add_policy(record_t* policy, rule_t* rule){
82 ng_log(LOG_DEBUG, "Found a new policy: %s\n", policy->string);
83 /*ng_log(LOG_DEBUG, "Found a new rule: %s\n", rule->string);*/
84 free(policy->string);
85 free(policy);
86
87 /*free(rule->true_branch);*/
88 /*free(rule->false_branch);*/
89 /*free(rule);*/
90 }
91
92 const char* pdl_path(){
93 return _pdl_path;
94 }
95
96 rule_t* add_rule(record_t* state, record_t* true_branch, record_t* false_branch){
97 rule_t* new_rule = malloc(sizeof(rule_t));
98 if(state != NULL){
99 ng_log(LOG_DEBUG, "Added a new rule: %s\n", state->string);
100 }
101 if(true_branch != NULL){
102 ng_log(LOG_DEBUG, "True branch: %s\n", true_branch->string);
103 }
104 if(false_branch != NULL){
105 ng_log(LOG_DEBUG, "False branch: %s\n", false_branch->string);
106 }
107 if(state != NULL){
108 free(state->string);
109 }
110 free(state);
111 if(true_branch != NULL){
112 free(true_branch->string);
113 }
114 free(true_branch);
115 if(false_branch != NULL){
116 free(false_branch->string);
117 }
118 free(false_branch);
119 free(new_rule);
120 return new_rule;
121 }
122
123 void remove_policy(record_t* policy){
124 ng_log(LOG_DEBUG, "Deleted policy: %s\n", policy->string);
125 free(policy->string);
126 free(policy);
127 }
128
129 char** _var_to_argv(char* value, int *argc){
130 char *start_of_arg = NULL, *copy_of_value = NULL, **argv = NULL;
131 char *delimiters = " \t";
132 size_t size_of_arg = 0, size_of_array, i = 0;
133 char *str_ptr;
134 copy_of_value = strdup(value);
135 size_of_array = (sizeof(char)*(strlen(copy_of_value)+1));
136 if((argv = calloc(1, size_of_array)) != NULL){
137 start_of_arg = strtok_r(copy_of_value, delimiters, &str_ptr);
138 while(start_of_arg != NULL){
139 size_of_arg = (sizeof(char)*(strlen(start_of_arg)+1));
140 if((argv[i] = calloc(1, size_of_arg))){
141 memcpy(argv[i], start_of_arg, size_of_arg);
142 start_of_arg = strtok_r(NULL, delimiters, &str_ptr);
143 i++;
144 }
145 }
146 }
147 free(copy_of_value);
148 *argc = i;
149 return argv;
150 }
151
152 void add_variable(record_t* name, record_t* value){
153 char** argv;
154 int argc;
155 ng_log(LOG_DEBUG, "Added variable name: %s\n", name->string);
156 ng_log(LOG_DEBUG, "Added variable value: %s\n", value->string);
157 printf("Added variable name: %s\n", name->string);
158 printf("Added variable value: %s\n", value->string);
159 argv = _var_to_argv(value->string, &argc);
160 add_plugin(argc, argv);
161 free(name->string);
162 free(name);
163 free(value->string);
164 free(value);
165 }
166
167 EES_RC pdl_term(){
168 free(_pdl_path);
169 if(file != NULL){
170 #if HAVE_YYLEX_DESTROY
171 yylex_destroy();
172 #endif
173 if((fclose(file)==0) ){
174 return EES_SUCCESS;
175 }
176 }
177 return EES_FAILURE;
178 }
179
180 EES_RC allow_rules(int val){
181 return EES_SUCCESS;
182 }
183
184 EES_RC allowed_policy_rule(const char* label){
185 return EES_SUCCESS;
186 }

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