diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2011-05-16 19:31:53 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2011-05-16 19:31:53 +0300 |
commit | c8865a0d524f3d545836bd4581329089a357661e (patch) | |
tree | 4fc437a07086c4304e7ec2446be2a504a3dbd507 | |
parent | 50e703a9a92e755f928699b705612cd4153ffb9f (diff) | |
download | grecs-c8865a0d524f3d545836bd4581329089a357661e.tar.gz grecs-c8865a0d524f3d545836bd4581329089a357661e.tar.bz2 |
Add bind testsuite.
* README.submodule: Update URL.
* src/bind-lex.l (grecs_bind_new_source): Scan include path.
* src/grecs.h (grecs_find_include_file): new proto.
* src/preproc.c (try_file): Rename to grecs_find_include_file. Change
signature and return type. All uses updated.
* tests/Makefile.am (EXTRA_DIST): Add new configs.
(TESTSUITE_AT): Add parser-bind.at.
* tests/gcffmt.c: Add -I (-include) option.
* tests/testsuite.at: Include parser-bind.at.
* tests/bind.conf: New file.
* tests/bind.dlz: New file.
* tests/bind.ext.conf: New file.
* tests/bind.int.conf: New file.
* tests/bind.keys: New file.
* tests/parser-bind.at: New file.
-rw-r--r-- | README.submodule | 2 | ||||
-rw-r--r-- | src/bind-lex.l | 17 | ||||
-rw-r--r-- | src/grecs.h | 2 | ||||
-rw-r--r-- | src/preproc.c | 34 | ||||
-rw-r--r-- | tests/Makefile.am | 15 | ||||
-rw-r--r-- | tests/bind.conf | 126 | ||||
-rw-r--r-- | tests/bind.dlz | 33 | ||||
-rw-r--r-- | tests/bind.ext.conf | 25 | ||||
-rw-r--r-- | tests/bind.int.conf | 17 | ||||
-rw-r--r-- | tests/bind.keys | 11 | ||||
-rw-r--r-- | tests/gcffmt.c | 8 | ||||
-rw-r--r-- | tests/parser-bind.at | 95 | ||||
-rw-r--r-- | tests/testsuite.at | 1 |
13 files changed, 363 insertions, 23 deletions
diff --git a/README.submodule b/README.submodule index 03428d4..3067e92 100644 --- a/README.submodule +++ b/README.submodule @@ -29,13 +29,13 @@ operations include value lookups by keyword paths, traversing trees recursively, joining several trees together, reductions, etc. * Usage 1. Install grecs as a submodule: - git submodule git.gnu.org.ua/gitroot/grecs.git grecs + git submodule git://git.gnu.org.ua/grecs.git grecs 2. Add a call to GRECS_SETUP to your configure.ac. It can be as simple as: GRECS_SETUP diff --git a/src/bind-lex.l b/src/bind-lex.l index 12dddf7..a5cf644 100644 --- a/src/bind-lex.l +++ b/src/bind-lex.l @@ -189,17 +189,30 @@ yywrap() int grecs_bind_new_source(const char *name) { grecs_locus_t *loc = grecs_current_locus.file ? &grecs_current_locus : NULL; struct stat st; - FILE *fp = fopen(name, "r"); + FILE *fp; + + if (access(name, F_OK)) { + int ec = errno; + char *tmp = grecs_find_include_file(name, 0); + if (!tmp) { + grecs_error(loc, ec, _("cannot open `%s'"), name); + return 1; + } + name = grecs_install_text(tmp); + free(tmp); + } + + fp = fopen(name, "r"); if (!fp) { grecs_error(loc, errno, _("cannot open `%s'"), name); return 1; - } + } if (fstat(fileno(fp), &st)) { grecs_error(loc, errno, _("can't state %s"), name); fclose(fp); return 1; } if (_push_context(name, st.st_ino, st.st_dev)) { diff --git a/src/grecs.h b/src/grecs.h index b839d71..5eef48d 100644 --- a/src/grecs.h +++ b/src/grecs.h @@ -260,12 +260,14 @@ extern void (*grecs_log_setup_hook)(); size_t grecs_preproc_fill_buffer(char *buf, size_t size); void grecs_preproc_add_include_dir(char *dir); int grecs_preproc_init(const char *name); void grecs_preproc_done(void); int grecs_preproc_run(const char *config_file, const char *extpp); +char *grecs_find_include_file(const char *name, int allow_cwd); + FILE *grecs_preproc_extrn_start(const char *file, pid_t *ppid); void grecs_preproc_extrn_shutdown(pid_t pid); char *grecs_install_text(const char *str); void grecs_destroy_text(void); struct grecs_symtab *grecs_text_table(void); diff --git a/src/preproc.c b/src/preproc.c index 8debdcf..4ab3066 100644 --- a/src/preproc.c +++ b/src/preproc.c @@ -469,14 +469,14 @@ pop_source() pp_line_stmt(); return 0; } -static int -try_file(const char *name, int allow_cwd, int err_not_found, char **newp) +char * +grecs_find_include_file(const char *name, int allow_cwd) { static char *cwd = "."; struct file_data fd; fd.name = name; fd.namelen = strlen(name); @@ -492,22 +492,16 @@ try_file(const char *name, int allow_cwd, int err_not_found, char **newp) grecs_list_remove_tail(include_path); } else pp_list_find(include_path, &fd); if (!fd.found) { pp_list_find(std_include_path, &fd); - - if (!fd.found && err_not_found) { - grecs_error(&LOCUS, 0, - _("%s: No such file or directory"), name); - *newp = NULL; - } + if (!fd.found) + return NULL; } - if (fd.found) - *newp = fd.buf; - return fd.found; + return fd.buf; } static int parse_include(const char *text, int once) { struct wordsplit ws; @@ -532,14 +526,19 @@ parse_include(const char *text, int once) p[len - 1] = 0; p++; } else allow_cwd = 1; - if (p[0] != '/' && try_file(p, allow_cwd, 1, &tmp)) - p = tmp; + if (p[0] != '/') { + p = grecs_find_include_file(p, allow_cwd); + if (!p) + grecs_error(&LOCUS, 0, + _("%s: No such file or directory"), + p); + } } if (p) rc = push_source(p, once); grecs_free(tmp); wordsplit_free(&ws); @@ -570,24 +569,25 @@ grecs_preproc_run(const char *config_file, const char *extpp) if (grecs_preproc_init(config_file)) return 1; if (extpp) { FILE *outfile; char *setup_file; char *cmd = NULL; - - if (try_file("pp-setup", 1, 0, &setup_file)) { + + setup_file = grecs_find_include_file("pp-setup", 1); + if (setup_file) { size_t size = 0; if (grecs_asprintf(&cmd, &size, "%s %s -", extpp, setup_file)) grecs_alloc_die(); grecs_free(setup_file); } else - cmd = grecs_strdup (extpp); + cmd = grecs_strdup(extpp); /*FIXME_DEBUG_F1 (2, "Running preprocessor: `%s'", cmd);*/ outfile = popen(cmd, "w"); - if (!outfile){ + if (!outfile) { grecs_error(NULL, errno, _("Unable to start external preprocessor `%s'"), cmd); grecs_free(cmd); return 1; } diff --git a/tests/Makefile.am b/tests/Makefile.am index f5d1f6f..1b47712 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -11,13 +11,25 @@ # 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 Grecs. If not, see <http://www.gnu.org/licenses/>. -EXTRA_DIST = $(TESTSUITE_AT) testsuite package.m4 gcf1.conf meta1.conf git.conf +EXTRA_DIST = \ + $(TESTSUITE_AT)\ + testsuite\ + package.m4\ + gcf1.conf\ + bind.conf\ + bind.keys\ + bind.int.conf\ + bind.ext.conf\ + bind.dlz\ + meta1.conf\ + git.conf + DISTCLEANFILES = atconfig $(check_SCRIPTS) MAINTAINERCLEANFILES = Makefile.in $(TESTSUITE) ## ------------ ## ## package.m4. ## @@ -48,12 +60,13 @@ TESTSUITE_AT = \ glob00.at\ glob01.at\ glob02.at\ glob03.at\ enum.at\ join.at\ + parser-bind.at\ parser-git.at\ parser-meta1.at\ peek00.at\ peek01.at\ peek02.at\ peek03.at\ diff --git a/tests/bind.conf b/tests/bind.conf new file mode 100644 index 0000000..2579a58 --- /dev/null +++ b/tests/bind.conf @@ -0,0 +1,126 @@ +# Sample Bind configuration file for Grecs testsuite. +# Nothing to copyright, really:) + +acl upd-dyn-vpn { + key vpn.; + 10.11.0.1; + 10.10.0.1; +}; + +acl foo-acl { + key foo.; +}; + +options { + version "Grecs testsuite"; + coresize 0; + directory "/etc/namedb"; + pid-file "/var/log/bind/named.pid"; + allow-transfer { + foo-acl; + }; + allow-query { + any; + }; + serial-query-rate 5; + max-journal-size 5m; + check-names master warn; + check-names slave warn; + check-names response ignore; +}; + +logging { + channel default_channel { + file "/var/log/bind/named.log" versions 9 size 524288; + print-time yes; + print-severity yes; + }; + channel debug_channel { + file "/var/log/bind/named.run" versions 9 size 524288; + print-time yes; + print-severity yes; + severity dynamic; + }; + channel security_channel { + file "/var/log/bind/security" versions 9 size 524288; + print-time yes; + print-severity yes; + }; + channel xfer_in_channel { + file "/var/log/bind/named-xfer.in" versions 9 size 524288; + print-time yes; + }; + channel xfer_out_channel { + file "/var/log/bind/named-xfer.out" versions 9 size 524288; + print-time yes; + }; + channel lamers_channel { + file "/var/log/bind/lamers.log" versions 5 size 524288; + print-time yes; + print-category yes; + }; + channel update_channel { + file "/var/log/bind/update.log" versions 9 size 524288; + print-time yes; + print-category yes; + severity debug 5; + }; + channel notify_channel { + file "/var/log/bind/notify.log" versions 9 size 524288; + print-time yes; + print-category yes; + }; + channel query_channel { + file "/var/log/bind/query.log" versions 9 size 524288; + print-time yes; + }; + category security { + security_channel; + }; + category queries { +# query_channel; + null; + }; + category default { + default_channel; + debug_channel; + }; + category xfer-in { + xfer_in_channel; + }; + category xfer-out { + xfer_out_channel; + }; + category delegation-only { + lamers_channel; + }; + category lame-servers { + lamers_channel; + }; + category update { + update_channel; + }; + category notify { + notify_channel; + }; +}; + +include "bind.keys"; + +controls { + inet 127.0.0.1 port 953 + allow { 127.0.0.1; } keys { "rndc-key"; }; +}; + +view "internal" { + match-clients { + 10.0.0.0/8; + }; + include "bind.int.conf"; +}; + +view "external" { + include "bind.ext.conf"; + include "bind.dlz"; +}; +# Finis coronat opus diff --git a/tests/bind.dlz b/tests/bind.dlz new file mode 100644 index 0000000..ffbbfc9 --- /dev/null +++ b/tests/bind.dlz @@ -0,0 +1,33 @@ +# Sample Bind configuration include file (3) for Grecs testsuite. +# This is a typical (?) DLZ configuraton for BIND. +# +dlz "DLZ" { + database "mysql + {host=localhost socket=/var/run/mysql/mysql.sock dbname=Foo user=bind ssl=false} + {select r.zone from dns_soa r, dns_acl a where r.zone = '%zone%' + and a.network <= inet_aton('%client%') and inet_aton('%client%') <= + a.bcast + and a.view = r.view } + {select r.ttl, r.type, r.mx_priority, + case when r.type='TXT' then concat('\"', r.data, '\"') else r.data end + from dns_records r, dns_acl a, + where r.zone = '%zone%' and r.host = '%record%' + and not (r.type = 'SOA' or r.type = 'NS') + and a.network <= inet_aton('%client%') and inet_aton('%client%') <= + a.bcast + and a.view = r.view } + {select r.ttl, r.type, r.data, r.resp_person, r.serial, + r.refresh, r.retry, r.expire, r.minimum + from dns_soa r, dns_acl a where r.zone = '%zone%' + and (r.type = 'SOA' or r.type='NS') + and a.network <= inet_aton('%client%') and + inet_aton('%client%') <= a.bcast + and a.view = r.view } + {select r.ttl, r.type, r.host, r.mx_priority, case when r.type='TXT' then + concat('\"', r.data, '\"') else r.data end + from dns_records r, dns_acl a where r.zone = '%zone%' + and a.network <= inet_aton('%client%') and + inet_aton('%client%') <= a.bcast + and a.view = r.view } + {select zone from dns_xfr where zone = '%zone%' and client = '%client%'}"; +}; diff --git a/tests/bind.ext.conf b/tests/bind.ext.conf new file mode 100644 index 0000000..b18e8f6 --- /dev/null +++ b/tests/bind.ext.conf @@ -0,0 +1,25 @@ +# Sample Bind configuration include file (2) for Grecs testsuite. + +zone "." { + type hint; + file "named.root"; +}; + +zone "com" { + type delegation-only; +}; + +zone "net" { + type delegation-only; +}; + +zone "0.0.127.IN-ADDR.ARPA" { + type master; + file "local.p"; +}; + +zone "foo.example.net" { + type master; + file "foo.p"; +}; +
\ No newline at end of file diff --git a/tests/bind.int.conf b/tests/bind.int.conf new file mode 100644 index 0000000..faba329 --- /dev/null +++ b/tests/bind.int.conf @@ -0,0 +1,17 @@ +# Sample Bind configuration include file (2) for Grecs testsuite. + +zone "int" { + type master; + file "int.p"; + allow-update { + upd-dyn-vpn; + }; + allow-query { + internal-hosts; + }; + allow-transfer { + 10.11.0.1; + 10.10.0.4; + 127.0.0.1; + }; +};
\ No newline at end of file diff --git a/tests/bind.keys b/tests/bind.keys new file mode 100644 index 0000000..ba43779 --- /dev/null +++ b/tests/bind.keys @@ -0,0 +1,11 @@ +# Sample Bind configuration include file (1) for Grecs testsuite. + +key "rndc-key" { + algorithm hmac-md5; + secret "1111111111111111111111=="; +}; + + + + + diff --git a/tests/gcffmt.c b/tests/gcffmt.c index 51e3037..5dcd640 100644 --- a/tests/gcffmt.c +++ b/tests/gcffmt.c @@ -23,13 +23,13 @@ static void usage(const char *arg, FILE *fp, int code) { fprintf(fp, "usage: %s [-h] [-locus] [-delim=char] [-reduce] [-sort] " - "[-type=grecs|bind|meta1|git] file [file...]\n", + "[-type=grecs|bind|meta1|git] [-Idir] [-include=dir] file [file...]\n", arg); exit(code); } static int node_ident_cmp(struct grecs_node const *a, struct grecs_node const *b) @@ -67,13 +67,17 @@ main(int argc, char **argv) else if (strcasecmp(arg+6, "BIND") == 0) grecs_parser_fun = grecs_bind_parser; else if (strcasecmp(arg+6, "GIT") == 0) grecs_parser_fun = grecs_git_parser; else usage(progname, stderr, 1); - } else if (arg[0] == '-') + } else if (strncmp(arg, "-I", 2) == 0) + grecs_preproc_add_include_dir(arg+2); + else if (strncmp(arg, "-include=", 9) == 0) + grecs_preproc_add_include_dir(arg+9); + else if (arg[0] == '-') usage(progname, stderr, 1); else { file = arg; --argc; break; } diff --git a/tests/parser-bind.at b/tests/parser-bind.at new file mode 100644 index 0000000..b7ae3e1 --- /dev/null +++ b/tests/parser-bind.at @@ -0,0 +1,95 @@ +# This file is part of grecs -*- Autotest -*- +# Copyright (C) 2011 Sergey Poznyakoff +# +# Grecs 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 3, or (at your option) +# any later version. +# +# Grecs 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 Grecs. If not, see <http://www.gnu.org/licenses/>. + +AT_SETUP([BIND-style parser]) +AT_KEYWORDS([parser bind]) + +AT_CHECK([gcffmt -type=bind -I$abs_srcdir $abs_srcdir/bind.conf|sed 's/ *$//'], +[0], +[.acl="upd-dyn-vpn".key: "vpn." +.acl="upd-dyn-vpn".10.11.0.1: +.acl="upd-dyn-vpn".10.10.0.1: +.acl="foo-acl".key: "foo." +.options.version: "Grecs testsuite" +.options.coresize: "0" +.options.directory: "/etc/namedb" +.options.pid-file: "/var/log/bind/named.pid" +.options.allow-transfer.foo-acl: +.options.allow-query.any: +.options.serial-query-rate: "5" +.options.max-journal-size: "5m" +.options.check-names: "master" "warn" +.options.check-names: "slave" "warn" +.options.check-names: "response" "ignore" +.logging.channel="default_channel".file: "/var/log/bind/named.log" "versions" "9" "size" "524288" +.logging.channel="default_channel".print-time: "yes" +.logging.channel="default_channel".print-severity: "yes" +.logging.channel="debug_channel".file: "/var/log/bind/named.run" "versions" "9" "size" "524288" +.logging.channel="debug_channel".print-time: "yes" +.logging.channel="debug_channel".print-severity: "yes" +.logging.channel="debug_channel".severity: "dynamic" +.logging.channel="security_channel".file: "/var/log/bind/security" "versions" "9" "size" "524288" +.logging.channel="security_channel".print-time: "yes" +.logging.channel="security_channel".print-severity: "yes" +.logging.channel="xfer_in_channel".file: "/var/log/bind/named-xfer.in" "versions" "9" "size" "524288" +.logging.channel="xfer_in_channel".print-time: "yes" +.logging.channel="xfer_out_channel".file: "/var/log/bind/named-xfer.out" "versions" "9" "size" "524288" +.logging.channel="xfer_out_channel".print-time: "yes" +.logging.channel="lamers_channel".file: "/var/log/bind/lamers.log" "versions" "5" "size" "524288" +.logging.channel="lamers_channel".print-time: "yes" +.logging.channel="lamers_channel".print-category: "yes" +.logging.channel="update_channel".file: "/var/log/bind/update.log" "versions" "9" "size" "524288" +.logging.channel="update_channel".print-time: "yes" +.logging.channel="update_channel".print-category: "yes" +.logging.channel="update_channel".severity: "debug" "5" +.logging.channel="notify_channel".file: "/var/log/bind/notify.log" "versions" "9" "size" "524288" +.logging.channel="notify_channel".print-time: "yes" +.logging.channel="notify_channel".print-category: "yes" +.logging.channel="query_channel".file: "/var/log/bind/query.log" "versions" "9" "size" "524288" +.logging.channel="query_channel".print-time: "yes" +.logging.category="security".security_channel: +.logging.category="queries".null: +.logging.category="default".default_channel: +.logging.category="default".debug_channel: +.logging.category="xfer-in".xfer_in_channel: +.logging.category="xfer-out".xfer_out_channel: +.logging.category="delegation-only".lamers_channel: +.logging.category="lame-servers".lamers_channel: +.logging.category="update".update_channel: +.logging.category="notify".notify_channel: +.key="rndc-key".algorithm: "hmac-md5" +.key="rndc-key".secret: "1111111111111111111111==" +.controls.inet: "127.0.0.1" "port" "953" "allow" ("127.0.0.1") "keys" ("rndc-key") +.view="internal".match-clients.10.0.0.0/8: +.view="internal".zone="int".type: "master" +.view="internal".zone="int".file: "int.p" +.view="internal".zone="int".allow-update.upd-dyn-vpn: +.view="internal".zone="int".allow-query.internal-hosts: +.view="internal".zone="int".allow-transfer.10.11.0.1: +.view="internal".zone="int".allow-transfer.10.10.0.4: +.view="internal".zone="int".allow-transfer.127.0.0.1: +.view="external".zone=".".type: "hint" +.view="external".zone=".".file: "named.root" +.view="external".zone="com".type: "delegation-only" +.view="external".zone="net".type: "delegation-only" +.view="external".zone="0.0.127.IN-ADDR.ARPA".type: "master" +.view="external".zone="0.0.127.IN-ADDR.ARPA".file: "local.p" +.view="external".zone="foo.example.net".type: "master" +.view="external".zone="foo.example.net".file: "foo.p" +.view="external".dlz="DLZ".database: "mysql\n {host=localhost socket=/var/run/mysql/mysql.sock dbname=Foo user=bind ssl=false}\n {select r.zone from dns_soa r, dns_acl a where r.zone = '%zone%'\n and a.network <= inet_aton('%client%') and inet_aton('%client%') <=\n a.bcast\n and a.view = r.view }\n {select r.ttl, r.type, r.mx_priority,\n case when r.type='TXT' then concat('\"', r.data, '\"') else r.data end\n from dns_records r, dns_acl a,\n where r.zone = '%zone%' and r.host = '%record%'\n and not (r.type = 'SOA' or r.type = 'NS')\n and a.network <= inet_aton('%client%') and inet_aton('%client%') <=\n a.bcast\n and a.view = r.view }\n {select r.ttl, r.type, r.data, r.resp_person, r.serial,\n r.refresh, r.retry, r.expire, r.minimum\n from dns_soa r, dns_acl a where r.zone = '%zone%'\n and (r.type = 'SOA' or r.type='NS')\n and a.network <= inet_aton('%client%') and\n inet_aton('%client%') <= a.bcast\n and a.view = r.view }\n {select r.ttl, r.type, r.host, r.mx_priority, case when r.type='TXT' then\n concat('\"', r.data, '\"') else r.data end\n from dns_records r, dns_acl a where r.zone = '%zone%' \n and a.network <= inet_aton('%client%') and\n inet_aton('%client%') <= a.bcast\n and a.view = r.view }\n {select zone from dns_xfr where zone = '%zone%' and client = '%client%'}" +]) + +AT_CLEANUP diff --git a/tests/testsuite.at b/tests/testsuite.at index b81b45e..5b4c9a4 100644 --- a/tests/testsuite.at +++ b/tests/testsuite.at @@ -70,12 +70,13 @@ m4_include([reduce00.at]) m4_include([reduce01.at]) m4_include([reduce02.at]) m4_include([reduce03.at]) m4_include([join.at]) +m4_include([parser-bind.at]) m4_include([parser-git.at]) m4_include([parser-meta1.at]) m4_include([vercmp.at]) # End of testsuite.at |