From bb4ee2fb6e34235ee9d2056d1b2c88a2270d01b8 Mon Sep 17 00:00:00 2001 From: An-Cheng Huang Date: Tue, 19 Feb 2008 16:20:24 -0800 Subject: exit after encountering parse error when handling default values. --- src/set.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/set.c b/src/set.c index 44f1263..d961fb8 100644 --- a/src/set.c +++ b/src/set.c @@ -336,10 +336,8 @@ handle_default(vtw_path *mpath, vtw_path *tpath, char *exclude) } memset(&def, 0, sizeof(def)); if ((status = parse_def(&def, tpath->path, FALSE))) { - fprintf(stderr, "parse error in [%s]\n", tpath->path); - pop_path(tpath); /* definition */ - pop_path(tpath); /* child */ - continue; + /* template parse error. abort. */ + bye("Parse error in [%s]\n", tpath->path); } if (def.def_default) { push_path(mpath, uename); -- cgit v1.2.3 From 4e0206da1f3080f0c0729e6b6f252a147cf2a9cb Mon Sep 17 00:00:00 2001 From: An-Cheng Huang Date: Tue, 19 Feb 2008 17:22:33 -0800 Subject: add template validation tool, check_tmpl --- .gitignore | 1 + Makefile.am | 2 ++ debian/lintian | 2 +- src/check_tmpl.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 src/check_tmpl.c (limited to 'src') diff --git a/.gitignore b/.gitignore index 358c973..765492c 100644 --- a/.gitignore +++ b/.gitignore @@ -27,6 +27,7 @@ libtool /src/my_commit /src/my_set /src/my_delete +/src/check_tmpl /src/cli_def.c /src/cli_parse.c /src/cli_parse.h diff --git a/Makefile.am b/Makefile.am index ef92de7..9e55aa1 100644 --- a/Makefile.am +++ b/Makefile.am @@ -25,9 +25,11 @@ LDADD = src/libvyatta-cfg.la sbin_PROGRAMS = src/my_commit sbin_PROGRAMS += src/my_delete sbin_PROGRAMS += src/my_set +sbin_PROGRAMS += src/check_tmpl src_my_commit_SOURCES = src/commit.c src_my_delete_SOURCES = src/delete.c src_my_set_SOURCES = src/set.c +src_check_tmpl_SOURCES = src/check_tmpl.c sbin_SCRIPTS = scripts/xorp_tmpl_tool sbin_SCRIPTS += scripts/vyatta-validate-type.pl diff --git a/debian/lintian b/debian/lintian index ad0df30..70110bf 100644 --- a/debian/lintian +++ b/debian/lintian @@ -3,4 +3,4 @@ vyatta-cfg: dir-or-file-in-opt vyatta-cfg: binary-or-shlib-defines-rpath ./opt/vyatta/sbin/my_set /opt/vyatta/lib vyatta-cfg: binary-or-shlib-defines-rpath ./opt/vyatta/sbin/my_commit /opt/vyatta/lib vyatta-cfg: binary-or-shlib-defines-rpath ./opt/vyatta/sbin/my_delete /opt/vyatta/lib -vyatta-cfg: binary-or-shlib-defines-rpath ./opt/vyatta/sbin/rl_passwd /opt/vyatta/lib +vyatta-cfg: binary-or-shlib-defines-rpath ./opt/vyatta/sbin/check_tmpl /opt/vyatta/lib diff --git a/src/check_tmpl.c b/src/check_tmpl.c new file mode 100644 index 0000000..8be1a7f --- /dev/null +++ b/src/check_tmpl.c @@ -0,0 +1,69 @@ +#include +#include + +#include "cli_val.h" + +int +check_line_continuation(FILE *ftmpl) +{ + char buf[256]; + int line = 0; + while (fgets(buf, 256, ftmpl) != NULL) { + int len = strlen(buf); + ++line; + if (len < 2 || buf[len - 1] != '\n' || !isblank(buf[len - 2])) { + continue; + } + len -= 3; + while (len >= 0 && isblank(buf[len])) { + --len; + } + if (len >= 0 && buf[len] == '\\') { + printf("Warning: \"backslash + space\" detected at the end of line %d.\n" + " This will not work as line continuation.\n", + line); + continue; + } + } + return 0; +} + +int +main(int argc, char **argv) +{ + int status = 0; + vtw_def def; + FILE *ftmpl = NULL; + + if (argc != 2) { + printf("Usage: check_tmpl \n"); + exit(-1); + } + + memset(&def, 0, sizeof(def)); + status = parse_def(&def, argv[1], 0); + if (status == -5) { + printf("Cannot open [%s]\n", argv[1]); + exit(-1); + } else if (status != 0) { + printf("Parse error in [%s]\n", argv[1]); + exit(-1); + } + + if ((ftmpl = fopen(argv[1], "r")) == NULL) { + printf("Cannot open [%s]\n", argv[1]); + exit(-1); + } + + /* check for other errors */ + if (check_line_continuation(ftmpl) != 0) { + exit(-1); + } + fseek(ftmpl, 0, SEEK_SET); + + fclose(ftmpl); + + printf("OK\n"); + return 0; +} + -- cgit v1.2.3