@@ -57,8 +57,9 @@ bool Model :: HasSection(string sec) {
5757void Model :: LoadSection(Model* model, ConfigInterface* cfg, string sec) {
5858 int i = 1 ;
5959 while (true ) {
60- if (!LoadAssertion (model, cfg, sec, sec+GetKeySuffix (i)))
60+ if (!LoadAssertion (model, cfg, sec, sec+GetKeySuffix (i))){
6161 break ;
62+ }
6263 else
6364 i++;
6465 }
@@ -91,14 +92,14 @@ bool Model :: AddDef(string sec, string key, string value) {
9192 ast->tokens = Split (ast->value , " ," );
9293 for (int i = 0 ; i < ast->tokens .size () ; i++)
9394 ast->tokens [i] = key + " _" + Trim (ast->tokens [i]);
94- } else if (sec == " m" )
95- ast->value = RemoveComments (ast->value );
95+ }
9696 else
97- ast->value = RemoveComments (EscapeAssertion ( ast->value ) );
97+ ast->value = RemoveComments (ast->value );
9898
99- if (m.find (sec) ! = m.end ())
99+ if (m.find (sec) = = m.end ())
100100 m[sec] = AssertionMap ();
101101 ast->policy = vector<vector<string>>{};
102+
102103 m[sec].assertion_map [key] = ast;
103104
104105 return true ;
@@ -161,9 +162,8 @@ void Model :: BuildIncrementalRoleLinks(RoleManager* rm, policy_op op, string se
161162
162163// BuildRoleLinks initializes the roles in RBAC.
163164void Model :: BuildRoleLinks(RoleManager* rm) {
164- for (unordered_map<string, Assertion*> :: iterator it = this ->m [" g" ].assertion_map .begin () ; it != this ->m [" g" ].assertion_map .end () ; it++) {
165+ for (unordered_map<string, Assertion*> :: iterator it = this ->m [" g" ].assertion_map .begin () ; it != this ->m [" g" ].assertion_map .end () ; it++)
165166 (it->second )->BuildRoleLinks (rm);
166- }
167167}
168168
169169// PrintPolicy prints the policy to log.
@@ -187,13 +187,15 @@ void Model :: PrintPolicy() {
187187
188188// ClearPolicy clears all current policy.
189189void Model :: ClearPolicy() {
190- for (unordered_map<string, Assertion*> :: iterator it = this ->m [" p" ].assertion_map .begin () ; it != this ->m [" p" ].assertion_map .end () ; it++)
190+ for (unordered_map<string, Assertion*> :: iterator it = this ->m [" p" ].assertion_map .begin () ; it != this ->m [" p" ].assertion_map .end () ; it++){
191191 if ((it->second )->policy .size () > 0 )
192192 (it->second )->policy .clear ();
193+ }
193194
194- for (unordered_map<string, Assertion*> :: iterator it = this ->m [" g" ].assertion_map .begin () ; it != this ->m [" g" ].assertion_map .end () ; it++)
195+ for (unordered_map<string, Assertion*> :: iterator it = this ->m [" g" ].assertion_map .begin () ; it != this ->m [" g" ].assertion_map .end () ; it++){
195196 if ((it->second )->policy .size () > 0 )
196197 (it->second )->policy .clear ();
198+ }
197199}
198200
199201// GetPolicy gets all rules in a policy.
@@ -222,7 +224,7 @@ vector<vector<string>> Model :: GetFilteredPolicy(string sec, string p_type, int
222224
223225// HasPolicy determines whether a model has the specified policy rule.
224226bool Model :: HasPolicy(string sec, string p_type, vector<string> rule) {
225- vector<vector<string>> policy ( m[sec].assertion_map [p_type]->policy ) ;
227+ vector<vector<string>> policy = m[sec].assertion_map [p_type]->policy ;
226228 for (int i=0 ; i < policy.size () ; i++)
227229 if (ArrayEquals (rule, policy[i]))
228230 return true ;
@@ -236,6 +238,7 @@ bool Model :: AddPolicy(string sec, string p_type, vector<string> rule) {
236238 m[sec].assertion_map [p_type]->policy .push_back (rule);
237239 return true ;
238240 }
241+
239242 return false ;
240243}
241244
@@ -266,17 +269,19 @@ bool Model :: RemovePolicy(string sec, string p_type, vector<string> rule) {
266269// RemovePolicies removes policy rules from the model.
267270bool Model :: RemovePolicies(string sec, string p_type, vector<vector<string>> rules) {
268271 OUTER: for (int j = 0 ; j < rules.size (); j++) {
269- for (int i = 0 ; i < this ->m [sec].assertion_map [p_type]->policy .size (); i++)
270- if (ArrayEquals (rules[j], this ->m [sec].assertion_map [p_type]->policy [i])) {
272+ for (int i = 0 ; i < this ->m [sec].assertion_map [p_type]->policy .size (); i++){
273+ if (ArrayEquals (rules[j], this ->m [sec].assertion_map [p_type]->policy [i]))
271274 goto OUTER;
272275 }
273276 return false ;
274277 }
275278
276- for (int j = 0 ; j < rules.size (); j++)
277- for (int i = 0 ; i < this ->m [sec].assertion_map [p_type]->policy .size (); i++)
279+ for (int j = 0 ; j < rules.size (); j++){
280+ for (int i = 0 ; i < this ->m [sec].assertion_map [p_type]->policy .size (); i++){
278281 if (ArrayEquals (rules[j], this ->m [sec].assertion_map [p_type]->policy [i]))
279282 this ->m [sec].assertion_map [p_type]->policy .erase (this ->m [sec].assertion_map [p_type]->policy .begin () + i);
283+ }
284+ }
280285
281286 return true ;
282287}
@@ -289,8 +294,8 @@ pair<bool, vector<vector<string>>> Model :: RemoveFilteredPolicy(string sec, str
289294 bool res = false ;
290295 for (int i = 0 ; i < policy.size () ; i++){
291296 bool matched = true ;
292- for (int i = 0 ; i < field_values.size () ; i ++) {
293- if (field_values[i ] != " " && (policy[i])[field_index+i ] != field_values[i ]) {
297+ for (int j = 0 ; j < field_values.size () ; j ++) {
298+ if (field_values[j ] != " " && (policy[i])[field_index+j ] != field_values[j ]) {
294299 matched = false ;
295300 break ;
296301 }
0 commit comments