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

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