[apparmor] [PATCH 03/13] Add generic support extended conditional syntax

John Johansen john.johansen at canonical.com
Tue Feb 14 17:32:25 UTC 2012


  extended conditionals use a syntax of
    cond=value
    cond=(value1 value2)
    cond=(value1,value2)
  where the comma is optional and supported as such because the
  flags syntax used them

  The mount patch extends, and improves on this patch, the changes probably
  should have been separated out but ...

Signed-off-by: John Johansen <john.johansen at canonical.com>
---
 parser/parser_lex.l  |   41 +++++++++++++++++++++++++++++++++++++++++
 parser/parser_yacc.y |    1 +
 2 files changed, 42 insertions(+), 0 deletions(-)

diff --git a/parser/parser_lex.l b/parser/parser_lex.l
index 52f207e..bfcbd57 100644
--- a/parser/parser_lex.l
+++ b/parser/parser_lex.l
@@ -213,6 +213,7 @@ ARROW		->
 LT_EQUAL	<=
 
 %x SUB_NAME
+%x EXTCOND_MODE
 %x NETWORK_MODE
 %x LIST_VAL_MODE
 %x ASSIGN_MODE
@@ -306,6 +307,34 @@ LT_EQUAL	<=
 			}
 }
 
+<EXTCOND_MODE>{
+	{WS}+		{ DUMP_PREPROCESS; /* Eat whitespace */ }
+
+	{EQUALS}	{
+			DUMP_PREPROCESS;
+			return TOK_EQUALS;
+		}
+
+	{OPEN_PAREN}	{
+			DUMP_PREPROCESS;
+			PDEBUG("extcond listv\n");
+			/* Don't push state here as this is a transition
+			 * start condition and we want to return to the start
+			 * condition that invoked <EXTCOND_MODE> when
+			 * SUB_NAME is done
+			 */
+			BEGIN(LIST_VAL_MODE);
+			return TOK_OPENPAREN;
+		}
+
+	[^\n]	{
+			DUMP_PREPROCESS;
+			/* Something we didn't expect */
+			yyerror(_("Found unexpected character: '%s'"), yytext);
+		}
+
+}
+
 <ASSIGN_MODE>{
 	{WS}+		{ DUMP_PREPROCESS; /* Eat whitespace */ }
 
@@ -536,6 +565,18 @@ LT_EQUAL	<=
 			return TOK_OPENPAREN;
 			}
 
+{VARIABLE_NAME}/{WS}*={WS}*	{
+				/* we match to the = in the lexer so that
+				 * can switch scanner state.  By the time
+				 * the parser see the = it may be to late
+				 * as bison may have requested the next
+				 * token from the scanner
+				 */
+				yylval.id = processid(yytext, yyleng);
+				yy_push_state(EXTCOND_MODE);
+				return TOK_CONDID;
+			}
+
 {VARIABLE_NAME}		{
 			DUMP_PREPROCESS;
 			int token = get_keyword_token(yytext);
diff --git a/parser/parser_yacc.y b/parser/parser_yacc.y
index 4e68321..516cf57 100644
--- a/parser/parser_yacc.y
+++ b/parser/parser_yacc.y
@@ -78,6 +78,7 @@ void add_local_entry(struct codomain *cod);
 %}
 
 %token TOK_ID
+%token TOK_CONDID
 %token TOK_CARET
 %token TOK_OPEN
 %token TOK_CLOSE
-- 
1.7.9




More information about the AppArmor mailing list