/[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 589 - (show annotations) (download) (as text)
Wed Jul 22 10:16:59 2009 UTC (12 years, 6 months ago) by aramv
File MIME type: text/x-chdr
File size: 4222 byte(s)
Changed flow of code a bit. Checking return values etc
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include "pdl.h"
4 #include "ng_log.h"
5 #include "plugin_manager.h"
6 #include "ees_config.h"
7
8 NG_RC pdl_init(const char* name){
9 file = NULL;
10 if((file = fopen(name,"r")) != NULL){
11 yyin = file;
12 return NG_SUCCESS;
13 } else {
14 ng_log(LOG_ERR, "Failed to open policy file");
15 return NG_FAILURE;
16 }
17 }
18
19 record_t* concat_strings(record_t* r1, record_t* r2){
20 record_t* new_record;
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 strcat(new_record->string, r1->string);
25 strcat(new_record->string, 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 ng_log(LOG_NOTICE, "Concating: %s with %s", r1->string, r2->string);
38 record_t *r;
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_ERR, string);
60 }
61
62 void set_path(record_t* path){
63 ng_log(LOG_ERR, "Found a new path: %s\n", path->string);
64 free(path->string);
65 free(path);
66 }
67
68 void add_policy(record_t* policy, rule_t* rule){
69 ng_log(LOG_ERR, "Found a new policy: %s\n", policy->string);
70 /*ng_log(LOG_ERR, "Found a new rule: %s\n", rule->string);*/
71 free(policy->string);
72 free(policy);
73
74 /*free(rule->true_branch);*/
75 /*free(rule->false_branch);*/
76 /*free(rule);*/
77 }
78
79 const char* pdl_path(){
80 return _pdl_path;
81 }
82
83 rule_t* add_rule(record_t* state, record_t* true_branch, record_t* false_branch){
84 rule_t* new_rule = malloc(sizeof(rule_t));
85 if(state != NULL){
86 ng_log(LOG_ERR, "Added a new rule: %s\n", state->string);
87 }
88 if(true_branch != NULL){
89 ng_log(LOG_ERR, "True branch: %s\n", true_branch->string);
90 }
91 if(false_branch != NULL){
92 ng_log(LOG_ERR, "False branch: %s\n", false_branch->string);
93 }
94 if(state != NULL){
95 free(state->string);
96 }
97 free(state);
98 if(true_branch != NULL){
99 free(true_branch->string);
100 }
101 free(true_branch);
102 if(false_branch != NULL){
103 free(false_branch->string);
104 }
105 free(false_branch);
106 free(new_rule);
107 return new_rule;
108 }
109
110 void remove_policy(record_t* policy){
111 ng_log(LOG_ERR, "Deleted policy: %s\n", policy->string);
112 free(policy->string);
113 free(policy);
114 }
115
116 char** _var_to_argv(char* value, int *argc){
117 char *start_of_arg = NULL, *copy_of_value = NULL, **argv = NULL;
118 char *delimiters = " \t";
119 int size_of_arg = 0, size_of_array, i = 0;
120 char *str_ptr;
121 copy_of_value = strdup(value);
122 size_of_array = (sizeof(char)*(strlen(copy_of_value)+1));
123 if((argv = calloc(1, size_of_array)) != NULL){
124 start_of_arg = strtok_r(copy_of_value, delimiters, &str_ptr);
125 while(start_of_arg != NULL){
126 size_of_arg = (sizeof(char)*(strlen(start_of_arg)+1));
127 if((argv[i] = calloc(1, size_of_arg))){
128 memcpy(argv[i], start_of_arg, size_of_arg);
129 start_of_arg = strtok_r(NULL, delimiters, &str_ptr);
130 i++;
131 }
132 }
133 }
134 free(copy_of_value);
135 *argc = i;
136 return argv;
137 }
138
139 void add_variable(record_t* name, record_t* value){
140 char** argv;
141 int argc;
142 ng_log(LOG_ERR, "Added variable name: %s\n", name->string);
143 ng_log(LOG_ERR, "Added variable value: %s\n", value->string);
144 argv = _var_to_argv(value->string, &argc);
145 add_plugin(argc, argv);
146 free(name->string);
147 free(name);
148 free(value->string);
149 free(value);
150 }
151
152 NG_RC pdl_term(){
153 if(file != NULL){
154 #if HAVE_YYLEX_DESTROY
155 yylex_destroy();
156 #endif
157 if((fclose(file)==0) ){
158 return NG_SUCCESS;
159 }
160 }
161 return NG_FAILURE;
162 }
163
164 NG_RC allow_rules(int val){
165 return NG_SUCCESS;
166 }
167
168 NG_RC allowed_policy_rule(const char* label){
169 return NG_SUCCESS;
170 }

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