18
18
19
19
#include " pch.h"
20
20
21
- // #include <iostream >
21
+ #include < algorithm >
22
22
23
23
#include " ./enforcer.h"
24
24
#include " ./persist/watcher_ex.h"
@@ -39,6 +39,7 @@ bool Enforcer :: enforce(string matcher, Scope scope) {
39
39
// }()
40
40
41
41
this ->func_map .scope = scope;
42
+ this ->func_map .LoadFunctionMap ();
42
43
43
44
if (!this ->enabled )
44
45
return true ;
@@ -52,16 +53,19 @@ bool Enforcer :: enforce(string matcher, Scope scope) {
52
53
else
53
54
exp_string = matcher;
54
55
56
+
55
57
unordered_map <string, RoleManager*> rm_map;
56
58
bool ok = this ->model ->m .find (" g" ) != this ->model ->m .end ();
59
+
57
60
if (ok) {
58
61
for (unordered_map <string, Assertion*> :: iterator it = this ->model ->m [" g" ].assertion_map .begin () ; it != this ->model ->m [" g" ].assertion_map .end () ; it++){
59
62
RoleManager* rm = it->second ->rm ;
63
+ int char_count = int (count (it->second ->value .begin (), it->second ->value .end (), ' _' ));
60
64
int index = int (exp_string.find ((it->first )+" (" ));
61
65
if (index != string::npos)
62
- exp_string.insert (index +(it->first +" (" ).length ()- 1 , (it-> first )+ " _rm " );
63
- PushPointer (this ->func_map .scope , (void *)rm, (it-> first )+ " _rm " );
64
- this ->func_map .AddFunction (it->first , GFunction);
66
+ exp_string.insert (index +(it->first +" (" ).length (), " rm, " );
67
+ PushPointer (this ->func_map .scope , (void *)rm, " rm " );
68
+ this ->func_map .AddFunction (it->first , GFunction, char_count + 1 );
65
69
}
66
70
}
67
71
@@ -94,7 +98,7 @@ bool Enforcer :: enforce(string matcher, Scope scope) {
94
98
PushStringPropToObject (this ->func_map .scope , " p" , p_vals[j], token);
95
99
}
96
100
97
- this ->func_map .Eval (exp_string);
101
+ this ->func_map .Evaluate (exp_string);
98
102
99
103
// TODO
100
104
// log.LogPrint("Result: ", result)
@@ -134,15 +138,17 @@ bool Enforcer :: enforce(string matcher, Scope scope) {
134
138
break ;
135
139
}
136
140
} else {
137
- this ->func_map .Eval (exp_string);
141
+ bool isValid = this ->func_map .Evaluate (exp_string);
142
+ if (!isValid)
143
+ return false ;
138
144
bool result = this ->func_map .GetBooleanResult ();
145
+
139
146
// TODO
140
147
// log.LogPrint("Result: ", result)
141
-
142
148
if (result)
143
- policy_effects[ 0 ] = Effect::Allow;
149
+ policy_effects. push_back ( Effect::Allow) ;
144
150
else
145
- policy_effects[ 0 ] = Effect::Indeterminate;
151
+ policy_effects. push_back ( Effect::Indeterminate) ;
146
152
}
147
153
148
154
// TODO
@@ -200,7 +206,7 @@ Enforcer* Enforcer :: NewEnforcer(Model* m, Adapter* adapter) {
200
206
201
207
e->Initialize ();
202
208
203
- if (e->adapter != NULL ) {
209
+ if (e->adapter -> file_path != " " ) {
204
210
e->LoadPolicy ();
205
211
}
206
212
return e;
@@ -346,7 +352,6 @@ void Enforcer :: ClearPolicy() {
346
352
void Enforcer :: LoadPolicy() {
347
353
this ->model ->ClearPolicy ();
348
354
this ->adapter ->LoadPolicy (this ->model );
349
-
350
355
this ->model ->PrintPolicy ();
351
356
352
357
if (this ->auto_build_role_links ) {
0 commit comments