[apparmor] [PATCH 04/11] parser: Simplify change_profile grammar rules
Tyler Hicks
tyhicks at canonical.com
Wed May 25 20:59:36 UTC 2016
Make future modifications to the change_profile grammar rules easier by
simplifying things. First, the change_profile rule handling is collapsed
into a single grammar rule. The inputs to the grammar rule are given
helpful variable names to make it harder to mix up which variable we're
dealing with. Finally, the two separate calls to new_entry() are unified
into a single call.
Signed-off-by: Tyler Hicks <tyhicks at canonical.com>
---
parser/parser_yacc.y | 30 +++++++++++++-----------------
1 file changed, 13 insertions(+), 17 deletions(-)
diff --git a/parser/parser_yacc.y b/parser/parser_yacc.y
index 2d95066..91c6d68 100644
--- a/parser/parser_yacc.y
+++ b/parser/parser_yacc.y
@@ -241,7 +241,6 @@ void add_local_entry(Profile *prof);
%type <flags> flagval
%type <cap> caps
%type <cap> capability
-%type <id> change_profile_head
%type <user_entry> change_profile
%type <set_var> TOK_SET_VAR
%type <bool_var> TOK_BOOL_VAR
@@ -1475,28 +1474,25 @@ file_mode: TOK_MODE
free($1);
}
-change_profile_head: TOK_CHANGE_PROFILE opt_id
- {
- if ($2 && !($2[0] == '/' || strncmp($2, "@{", 2) == 0))
- yyerror(_("Exec condition must begin with '/'."));
- $$ = $2;
- }
-
-change_profile: change_profile_head opt_named_transition TOK_END_OF_RULE
+change_profile: TOK_CHANGE_PROFILE opt_id opt_named_transition TOK_END_OF_RULE
{
struct cod_entry *entry;
+ char *exec = $2;
+ char *target = $3;
- if ($2) {
- PDEBUG("Matched change_profile: tok_id (%s)\n", $2);
- entry = new_entry($2, AA_CHANGE_PROFILE, $1);
- } else {
- char *rule = strdup("**");
- if (!rule)
- yyerror(_("Memory allocation error."));
+ if (exec && !(exec[0] == '/' || strncmp(exec, "@{", 2) == 0))
+ yyerror(_("Exec condition must begin with '/'."));
+ if (target) {
+ PDEBUG("Matched change_profile: tok_id (%s)\n", target);
+ } else {
PDEBUG("Matched change_profile,\n");
- entry = new_entry(rule, AA_CHANGE_PROFILE, $1);
+ target = strdup("**");
+ if (!target)
+ yyerror(_("Memory allocation error."));
}
+
+ entry = new_entry(target, AA_CHANGE_PROFILE, exec);
if (!entry)
yyerror(_("Memory allocation error."));
--
2.7.4
More information about the AppArmor
mailing list