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

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