[apparmor] [PATCH 2/2] Convert FLAGS_MODE start condition to a generic list of values start cond

John Johansen john.johansen at canonical.com
Tue Jan 3 12:04:34 UTC 2012


 From 84a79d7f8f5ea10933644de197b21d5f1ede9f5e Mon Sep 17 00:00:00 2001
From: John Johansen <john.johansen at canonical.com>
Date: Tue, 3 Jan 2012 03:30:20 -0800
Subject: [PATCH 2/2] Convert FLAGS_MODE start condition to a generic list of
  values start cond

Signed-off-by: John Johansen <john.johansen at canonical.com>
---
  parser/parser_lex.l  |   42 ++++++++++++++++++++++++------------------
  parser/parser_misc.c |    2 --
  parser/parser_yacc.y |   21 +++++++++------------
  3 files changed, 33 insertions(+), 32 deletions(-)

diff --git a/parser/parser_lex.l b/parser/parser_lex.l
index f2ff5cf..dbdbaa7 100644
--- a/parser/parser_lex.l
+++ b/parser/parser_lex.l
@@ -185,12 +185,13 @@ ID 		{ID_CHARS}|(,{ID_CHARS})
  IDS		{ID}+
  POST_VAR_ID_CHARS	[^ \t\n"!,=\+]
  POST_VAR_ID 	{POST_VAR_ID_CHARS}|(,{POST_VAR_ID_CHARS})
-
+LIST_VALUE_ID	([^ \t\n"!,()])+
  ALLOWED_QUOTED_ID 	[^\0"]|\\\"
  QUOTED_ID	\"{ALLOWED_QUOTED_ID}*\"
  
  IP		{NUMBER}\.{NUMBER}\.{NUMBER}\.{NUMBER}
  
+FLAGS          flags{WS}*=?{WS}*
  HAT		hat{WS}*
  PROFILE		profile{WS}*
  KEYWORD         [[:alpha:]_]+
@@ -204,7 +205,7 @@ QPATHNAME	\"(\/|{SET_VAR_PREFIX})([^\0"]|\\\")*\"
  
  OPEN_PAREN 	\(
  CLOSE_PAREN	\)
-FLAGSEP		\,
+COMMA		\,
  EQUALS		=
  ADD_ASSIGN	\+=
  ARROW		->
@@ -212,7 +213,7 @@ LT_EQUAL	<=
  
  %x SUB_NAME
  %x NETWORK_MODE
-%x FLAGS_MODE
+%x LIST_VAL_MODE
  %x ASSIGN_MODE
  %x RLIMIT_MODE
  %x CHANGE_PROFILE_MODE
@@ -274,37 +275,40 @@ LT_EQUAL	<=
  		}
  }
  
-<FLAGS_MODE>{
+<LIST_VAL_MODE>{
  	{OPEN_PAREN}	{
  			DUMP_PREPROCESS;
-			PDEBUG("FLag (\n");
+			PDEBUG("listval: )\n");
+			yy_push_state(LIST_VAL_MODE);
  			return TOK_OPENPAREN;
  			}
+
  	{CLOSE_PAREN}	{
  			DUMP_PREPROCESS;
-			PDEBUG("Flag )\n");
+			PDEBUG("listval: )\n");
  			yy_pop_state();
  			return TOK_CLOSEPAREN;
  			}
  
  	{WS}+		{ DUMP_PREPROCESS; /* Eat whitespace */ }
  
-	{FLAGSEP}	{
+	{COMMA}	{
  			DUMP_PREPROCESS;
-			PDEBUG("Flag , \n");
-			return TOK_FLAG_SEP;
+			PDEBUG("listval: , \n");
+			return TOK_COMMA;
  			}
  
  	{EQUALS}	{
  			DUMP_PREPROCESS;
-			PDEBUG("Flag = \n");
+			PDEBUG("listval: = \n");
  			return TOK_EQUALS;
  			}
-	{KEYWORD}	{
+
+	({LIST_VALUE_ID}|{QUOTED_ID})	{
  			DUMP_PREPROCESS;
-			yylval.flag_id = strdup(yytext);
-			PDEBUG("Found flag: \"%s\"\n", yylval.flag_id);
-			return TOK_FLAG_ID;
+			yylval.id = processid(yytext, yyleng);
+			PDEBUG("listval: \"%s\"\n", yylval.id);
+			return TOK_ID;
  			}
  
  	[^\n]		{
@@ -514,6 +518,11 @@ LT_EQUAL	<=
  			return TOK_MODE;
  			}
  
+{FLAGS}			{
+			DUMP_PREPROCESS;
+			return TOK_FLAGS;
+			}
+
  {HAT}			{
  			DUMP_PREPROCESS;
  			yy_push_state(SUB_NAME);
@@ -535,7 +544,7 @@ LT_EQUAL	<=
  {OPEN_PAREN}	{
  			DUMP_PREPROCESS;
  			PDEBUG("FLag (\n");
-			yy_push_state(FLAGS_MODE);
+			yy_push_state(LIST_VAL_MODE);
  			return TOK_OPENPAREN;
  			}
  
@@ -551,9 +560,6 @@ LT_EQUAL	<=
  				PDEBUG("Found (var) id: \"%s\"\n", yylval.id);
  				return TOK_ID;
  				break;
-			case TOK_FLAGS:
-				yy_push_state(FLAGS_MODE);
-				break;
  			case TOK_RLIMIT:
  				yy_push_state(RLIMIT_MODE);
  				break;
diff --git a/parser/parser_misc.c b/parser/parser_misc.c
index 64030ab..ebaa887 100644
--- a/parser/parser_misc.c
+++ b/parser/parser_misc.c
@@ -54,8 +54,6 @@ struct keyword_table {
  };
  
  static struct keyword_table keyword_table[] = {
-	/* flags */
-	{"flags",		TOK_FLAGS},
  	/* network */
  	{"network",		TOK_NETWORK},
  	/* misc keywords */
diff --git a/parser/parser_yacc.y b/parser/parser_yacc.y
index 1b169f0..7e28d37 100644
--- a/parser/parser_yacc.y
+++ b/parser/parser_yacc.y
@@ -112,6 +112,7 @@ void add_local_entry(struct codomain *cod);
  %token TOK_PTRACE
  %token TOK_OPENPAREN
  %token TOK_CLOSEPAREN
+%token TOK_COMMA
  
   /* rlimits */
  %token TOK_RLIMIT
@@ -138,8 +139,6 @@ void add_local_entry(struct codomain *cod);
  
  /* debug flag values */
  %token TOK_FLAGS
-%token TOK_FLAG_SEP
-%token TOK_FLAG_ID
  
  %union {
  	char *id;
@@ -176,7 +175,6 @@ void add_local_entry(struct codomain *cod);
  %type <flags>	flags
  %type <flags>	flagvals
  %type <flags>	flagval
-%type <flag_id>	TOK_FLAG_ID
  %type <cap>	caps
  %type <cap>	capability
  %type <cap>	set_caps
@@ -191,6 +189,7 @@ void add_local_entry(struct codomain *cod);
  %type <boolean> opt_audit_flag
  %type <boolean> opt_owner_flag
  %type <boolean> opt_profile_flag
+%type <boolean> opt_flags
  %type <id>	opt_namespace
  %type <id>	opt_id
  %type <transition> opt_named_transition
@@ -397,17 +396,15 @@ flags:	{ /* nothing */
  		$$ = fv;
  	};
  
-flags:	TOK_FLAGS TOK_EQUALS TOK_OPENPAREN flagvals TOK_CLOSEPAREN
-	{
-		$$ = $4;
-	};
+opt_flags: { /* nothing */ $$ = 0; }
+	| TOK_FLAGS { $$ = 1; }
  
-flags: TOK_OPENPAREN flagvals TOK_CLOSEPAREN
+flags:	opt_flags TOK_OPENPAREN flagvals TOK_CLOSEPAREN
  	{
-		$$ = $2;
-	}
+		$$ = $3;
+	};
  
-flagvals:	flagvals TOK_FLAG_SEP flagval
+flagvals:	flagvals TOK_COMMA flagval
  	{
  		$1.complain = $1.complain || $3.complain;
  		$1.audit = $1.audit || $3.audit;
@@ -434,7 +431,7 @@ flagvals:	flagval
  		$$ = $1;
  	};
  
-flagval:	TOK_FLAG_ID
+flagval:	TOK_ID
  	{
  		struct flagval fv = { 0, 0, 0, 0 };
  		if (strcmp($1, "debug") == 0) {
-- 
1.7.7.3




More information about the AppArmor mailing list