1818
1919#include " pch.h"
2020
21- // #include <iostream >
21+ #include < algorithm >
2222
2323#include " ./enforcer.h"
2424#include " ./persist/watcher_ex.h"
@@ -39,6 +39,7 @@ bool Enforcer :: enforce(string matcher, Scope scope) {
3939 // }()
4040
4141 this ->func_map .scope = scope;
42+ this ->func_map .LoadFunctionMap ();
4243
4344 if (!this ->enabled )
4445 return true ;
@@ -52,16 +53,19 @@ bool Enforcer :: enforce(string matcher, Scope scope) {
5253 else
5354 exp_string = matcher;
5455
56+
5557 unordered_map <string, RoleManager*> rm_map;
5658 bool ok = this ->model ->m .find (" g" ) != this ->model ->m .end ();
59+
5760 if (ok) {
5861 for (unordered_map <string, Assertion*> :: iterator it = this ->model ->m [" g" ].assertion_map .begin () ; it != this ->model ->m [" g" ].assertion_map .end () ; it++){
5962 RoleManager* rm = it->second ->rm ;
63+ int char_count = int (count (it->second ->value .begin (), it->second ->value .end (), ' _' ));
6064 int index = int (exp_string.find ((it->first )+" (" ));
6165 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 );
6569 }
6670 }
6771
@@ -94,7 +98,7 @@ bool Enforcer :: enforce(string matcher, Scope scope) {
9498 PushStringPropToObject (this ->func_map .scope , " p" , p_vals[j], token);
9599 }
96100
97- this ->func_map .Eval (exp_string);
101+ this ->func_map .Evaluate (exp_string);
98102
99103 // TODO
100104 // log.LogPrint("Result: ", result)
@@ -134,15 +138,17 @@ bool Enforcer :: enforce(string matcher, Scope scope) {
134138 break ;
135139 }
136140 } else {
137- this ->func_map .Eval (exp_string);
141+ bool isValid = this ->func_map .Evaluate (exp_string);
142+ if (!isValid)
143+ return false ;
138144 bool result = this ->func_map .GetBooleanResult ();
145+
139146 // TODO
140147 // log.LogPrint("Result: ", result)
141-
142148 if (result)
143- policy_effects[ 0 ] = Effect::Allow;
149+ policy_effects. push_back ( Effect::Allow) ;
144150 else
145- policy_effects[ 0 ] = Effect::Indeterminate;
151+ policy_effects. push_back ( Effect::Indeterminate) ;
146152 }
147153
148154 // TODO
@@ -200,7 +206,7 @@ Enforcer* Enforcer :: NewEnforcer(Model* m, Adapter* adapter) {
200206
201207 e->Initialize ();
202208
203- if (e->adapter != NULL ) {
209+ if (e->adapter -> file_path != " " ) {
204210 e->LoadPolicy ();
205211 }
206212 return e;
@@ -346,7 +352,6 @@ void Enforcer :: ClearPolicy() {
346352void Enforcer :: LoadPolicy() {
347353 this ->model ->ClearPolicy ();
348354 this ->adapter ->LoadPolicy (this ->model );
349-
350355 this ->model ->PrintPolicy ();
351356
352357 if (this ->auto_build_role_links ) {
0 commit comments