Rev 11141: Initial work on .adm file parser by Wilco Baan Hofman
<wilco@baanhofman.nl> and me. in
file:///home/jelmer/bzr.samba/4.0-regwrite/
Jelmer Vernooij
jelmer at samba.org
Sat Jan 13 19:50:39 GMT 2007
------------------------------------------------------------
revno: 11141
revision-id: jelmer at samba.org-20070113195019-yrx40nap220myng0
parent: svn-v2:20737 at 0c0555d6-39d7-0310-84fc-f1cc0bd64818-branches%2fSAMBA_4_0
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: 4.0-regwrite
timestamp: Sat 2007-01-13 20:50:19 +0100
message:
Initial work on .adm file parser by Wilco Baan Hofman <wilco at baanhofman.nl> and me.
added:
source/lib/policy/ policy-20070113165253-mfj7irct13ujxegu-1
source/lib/policy/config.mk config.mk-20070113165302-5amgbz764f0myhw9-1
source/lib/policy/dumpadm.c dumpadm.c-20070113165302-5amgbz764f0myhw9-2
source/lib/policy/lex.l lex.l-20070113165302-5amgbz764f0myhw9-3
source/lib/policy/parse_adm.y parse_adm.y-20070113165302-5amgbz764f0myhw9-4
modified:
source/lib/basic.mk svn-v2:845 at 0c0555d6-39d7-0310-84fc-f1cc0bd64818-branches%2fSAMBA_4_0-source%2flib%2fbasic.mk
source/script/lex_compile.sh svn-v2:9052 at 0c0555d6-39d7-0310-84fc-f1cc0bd64818-branches%2fSAMBA_4_0-source%2fscript%2flex_compile.sh
=== added directory 'source/lib/policy'
=== added file 'source/lib/policy/config.mk'
--- a/source/lib/policy/config.mk 1970-01-01 00:00:00 +0000
+++ b/source/lib/policy/config.mk 2007-01-13 19:50:19 +0000
@@ -0,0 +1,11 @@
+[LIBRARY::LIBPOLICY]
+CFLAGS = -Iheimdal/lib/roken
+OBJ_FILES = lex.o parse_adm.o
+
+lib/policy/lex.c: lib/policy/lex.l
+ @echo "Building $< with $(LEX)"
+ @-$(srcdir)/script/lex_compile.sh "$(LEX)" "$<" "$@" -i
+
+[BINARY::dumpadm]
+OBJ_FILES = dumpadm.o
+PRIVATE_DEPENDENCIES = LIBPOLICY
=== added file 'source/lib/policy/dumpadm.c'
--- a/source/lib/policy/dumpadm.c 1970-01-01 00:00:00 +0000
+++ b/source/lib/policy/dumpadm.c 2007-01-13 19:50:19 +0000
@@ -0,0 +1,35 @@
+/*
+ Unix SMB/CIFS implementation.
+ Copyright (C) 2006 Wilco Baan Hofman <wilco at baanhofman.nl>
+ Copyright (C) 2006 Jelmer Vernooij <jelmer at samba.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#include "includes.h"
+#include "lib/policy/parse_adm.h"
+
+extern FILE *yyin;
+
+extern void yyparse(void);
+
+int main(int argc, char **argv)
+{
+ yyin = fopen("foo.adm", "r");
+ if (yyin == NULL)
+ return -1;
+
+ yyparse();
+}
=== added file 'source/lib/policy/lex.l'
--- a/source/lib/policy/lex.l 1970-01-01 00:00:00 +0000
+++ b/source/lib/policy/lex.l 2007-01-13 19:50:19 +0000
@@ -0,0 +1,143 @@
+/*
+ Unix SMB/CIFS implementation.
+ Copyright (C) 2006 Wilco Baan Hofman <wilco at baanhofman.nl>
+ Copyright (C) 2006 Jelmer Vernooij <jelmer at samba.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+
+%{
+#include "includes.h"
+#include "lib/policy/parse_adm.h"
+#include "lex.h"
+void error_message (const char *format, ...);
+int yyparse (void);
+
+static int lineno = 1;
+static bool utf16 = false;
+
+#define YY_INPUT(buf,result,max_size) \
+{ \
+ if (utf16) { \
+ uint16_t v; \
+ if (fread(&v, 2, 1, yyin) < 1) \
+ result = YY_NULL; \
+ else \
+ result = push_codepoint(buf, v); \
+ } else { \
+ int c = getc(yyin); \
+ result = (c == EOF) ? YY_NULL : (buf[0] = c, 1); \
+ } \
+}
+
+%}
+
+%%
+
+ACTIONLIST { return ACTIONLIST; }
+CATEGORY { return CATEGORY; }
+CHECKBOX { return CHECKBOX; }
+CLASS { return CLASS; }
+DELETE { return DEL; }
+DEFAULT { return DEFAULT; }
+DROPDOWNLIST { return DROPDOWNLIST; }
+EDITTEXT { return EDITTEXT; }
+END { return END; }
+EXPLAIN { return EXPLAIN; }
+ITEMLIST { return ITEMLIST; }
+KEYNAME { return KEYNAME; }
+MACHINE { return MACHINE; }
+MIN { return MINIMUM; }
+MAX { return MAXIMUM; }
+NAME { return NAME; }
+NUMERIC { return NUMERIC; }
+PART { return PART; }
+POLICY { return POLICY; }
+REQUIRED { return REQUIRED; }
+SPIN { return SPIN; }
+SUPPORTED { return SUPPORTED; }
+TEXT { return TEXT; }
+USER { return USER; }
+VALUE { return VALUE; }
+VALUENAME { return VALUENAME; }
+VALUEON { return VALUEON; }
+VALUEOFF { return VALUEOFF; }
+= { return EQUALS; }
+\[strings\] { return STRINGSSECTION; }
+
+[0-9]+ {
+ char *e, *y = yytext;
+ yylval.integer = strtol((const char *)yytext, &e, 0);
+ if(e == y)
+ error_message("malformed constant (%s)", yytext);
+ else
+ return INTEGER;
+ }
+
+[A-Za-z\\{}][{}\-\\A-Za-z0-9_]* {
+ yylval.text = strdup ((const char *)yytext);
+ return LITERAL;
+ }
+
+"!!"[A-Za-z][-A-Za-z0-9_]* {
+ yylval.text = strdup ((const char *)yytext);
+ return LOOKUPLITERAL;
+ }
+[ \t]+
+\n { lineno++; }
+;[^\n]*\n { lineno++; }
+\"([^\n]+)\n { lineno++; yylval.text = strdup((const char *)yytext); return LITERAL; }
+%%
+
+#ifndef yywrap /* XXX */
+int
+yywrap ()
+{
+ return 1;
+}
+#endif
+
+
+void
+error_message (const char *format, ...)
+{
+ va_list args;
+
+ va_start (args, format);
+ fprintf (stderr, "%d:", lineno);
+ vfprintf (stderr, format, args);
+ va_end (args);
+}
+
+struct adm_file *adm_read_file(const char *file)
+{
+ uint8_t c[2];
+ yyin = fopen(file, "r");
+ if (yyin == NULL)
+ return NULL;
+
+ c[0] = getc(yyin);
+ c[1] = getc(yyin);
+ if (c[0] == 0xff && c[1] == 0xfe) {
+ utf16 = true;
+ } else {
+ rewind(yyin);
+ }
+
+ yyparse();
+
+ return NULL; /* FIXME */
+}
=== added file 'source/lib/policy/parse_adm.y'
--- a/source/lib/policy/parse_adm.y 1970-01-01 00:00:00 +0000
+++ b/source/lib/policy/parse_adm.y 2007-01-13 19:50:19 +0000
@@ -0,0 +1,136 @@
+/*
+ Unix SMB/CIFS implementation.
+ Copyright (C) 2006 Wilco Baan Hofman <wilco at baanhofman.nl>
+ Copyright (C) 2006 Jelmer Vernooij <jelmer at samba.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+%{
+#include "config.h"
+#include "lex.h"
+
+void yyerror (const char *s);
+
+%}
+
+%union {
+ char *text;
+ int integer;
+}
+
+%token CATEGORY
+%token CLASS
+%token USER
+%token MACHINE
+%token POLICY
+%token KEYNAME
+%token EXPLAIN
+%token VALUENAME
+%token VALUEON VALUEOFF
+%token PART
+%token ITEMLIST
+%token NAME
+%token VALUE
+%token NUMERIC EDITTEXT TEXT DROPDOWNLIST CHECKBOX
+%token MIN MAX DEFAULT
+%token END
+%token ACTIONLIST
+%token DELETE
+%token SUPPORTED
+%token <text> LITERAL
+%token <integer> INTEGER
+%token <text> LOOKUPLITERAL
+%token CLIENTEXT
+%token REQUIRED
+%token NOSORT
+%token SPIN
+%token EQUALS
+%token STRINGSSECTION
+
+%start admfile
+
+%%
+
+admfile: classes strings;
+
+classes: /* empty */ | class classes;
+
+class: CLASS classvalue categories;
+classvalue: USER|MACHINE;
+
+categories: /* empty */ | category categories;
+
+string: LITERAL | LOOKUPLITERAL;
+
+category: CATEGORY string categoryitems END CATEGORY;
+
+categoryitem: explain | category | policy | keyname;
+categoryitems: categoryitem categoryitems | /* empty */ ;
+
+policy: POLICY string policyitems END POLICY;
+
+policyitems: part policyitems | definition policyitems | /* empty */;
+
+definition: keyname | valuename | valueon | valueoff | explain | min | max | defaultvalue | supported;
+
+valuetype: NUMERIC | EDITTEXT | TEXT | DROPDOWNLIST | CHECKBOX;
+
+part: PART string valuetype partitems END PART;
+
+spin: SPIN INTEGER;
+
+partitem: definition | itemlist | REQUIRED | spin;
+partitems: partitem partitems | /* empty */;
+
+min: MIN INTEGER;
+max: MAX INTEGER;
+defaultvalue: DEFAULT INTEGER;
+
+explain: EXPLAIN string;
+value: NUMERIC INTEGER | DELETE;
+
+valueon: VALUEON value;
+valueoff: VALUEOFF value;
+
+valuename: VALUENAME string;
+keyname: KEYNAME string;
+
+itemlist: ITEMLIST items END ITEMLIST;
+itemname: NAME string;
+itemvalue: VALUE value;
+
+item: itemname | itemvalue | DEFAULT | actionlist;
+items: /* empty */ | item items;
+
+supported: SUPPORTED string;
+
+actionlist: ACTIONLIST actions END ACTIONLIST;
+actions: valuename actions | /* empty */;
+
+variable: LITERAL EQUALS LITERAL;
+variables: variable variables | /* empty */;
+strings: STRINGSSECTION variables;
+
+%%
+
+void
+yyerror (const char *s)
+{
+ error_message ("%s\n", s);
+}
+
+
+
=== modified file 'source/lib/basic.mk'
--- a/source/lib/basic.mk 2006-10-25 14:58:05 +0000
+++ b/source/lib/basic.mk 2007-01-13 19:50:19 +0000
@@ -7,6 +7,7 @@
include tdb/config.mk
include tls/config.mk
include registry/config.mk
+include policy/config.mk
include messaging/config.mk
include events/config.mk
include cmdline/config.mk
=== modified file 'source/script/lex_compile.sh'
--- a/source/script/lex_compile.sh 2006-09-10 10:02:10 +0000
+++ b/source/script/lex_compile.sh 2007-01-13 19:50:19 +0000
@@ -3,6 +3,8 @@
LEX="$1"
SRC="$2"
DEST="$3"
+shift 3
+ARGS="$*"
dir=`dirname $SRC`
file=`basename $SRC`
@@ -17,12 +19,15 @@
fi
fi
TOP=`pwd`
-if cd $dir && $LEX $file; then
+if cd $dir && $LEX $ARGS $file; then
if [ -r $base.yy.c ];then
# we must guarantee that config.h comes first
echo "#include \"config.h\"" > $base.c
sed '/^#/ s|$base.yy\.c|$DEST|' $base.yy.c >> $base.c
rm -f $base.yy.c
+ elif [ ! -r base.c ]; then
+ echo "$base.c nor $base.yy.c generated."
+ exit 1
fi
fi
cd $TOP
More information about the samba-cvs
mailing list