summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--README.submodule2
-rw-r--r--src/bind-lex.l17
-rw-r--r--src/grecs.h2
-rw-r--r--src/preproc.c34
-rw-r--r--tests/Makefile.am15
-rw-r--r--tests/bind.conf126
-rw-r--r--tests/bind.dlz33
-rw-r--r--tests/bind.ext.conf25
-rw-r--r--tests/bind.int.conf17
-rw-r--r--tests/bind.keys11
-rw-r--r--tests/gcffmt.c8
-rw-r--r--tests/parser-bind.at95
-rw-r--r--tests/testsuite.at1
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
@@ -32,7 +32,7 @@ recursively, joining several trees together, reductions, etc.
32 32
331. Install grecs as a submodule: 331. Install grecs as a submodule:
34 34
35 git submodule git.gnu.org.ua/gitroot/grecs.git grecs 35 git submodule git://git.gnu.org.ua/grecs.git grecs
36 36
372. Add a call to GRECS_SETUP to your configure.ac. It can be as 372. Add a call to GRECS_SETUP to your configure.ac. It can be as
38simple as: 38simple as:
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
@@ -192,11 +192,24 @@ grecs_bind_new_source(const char *name)
192 grecs_locus_t *loc = grecs_current_locus.file ? 192 grecs_locus_t *loc = grecs_current_locus.file ?
193 &grecs_current_locus : NULL; 193 &grecs_current_locus : NULL;
194 struct stat st; 194 struct stat st;
195 FILE *fp = fopen(name, "r"); 195 FILE *fp;
196
197 if (access(name, F_OK)) {
198 int ec = errno;
199 char *tmp = grecs_find_include_file(name, 0);
200 if (!tmp) {
201 grecs_error(loc, ec, _("cannot open `%s'"), name);
202 return 1;
203 }
204 name = grecs_install_text(tmp);
205 free(tmp);
206 }
207
208 fp = fopen(name, "r");
196 if (!fp) { 209 if (!fp) {
197 grecs_error(loc, errno, _("cannot open `%s'"), name); 210 grecs_error(loc, errno, _("cannot open `%s'"), name);
198 return 1; 211 return 1;
199 } 212 }
200 if (fstat(fileno(fp), &st)) { 213 if (fstat(fileno(fp), &st)) {
201 grecs_error(loc, errno, _("can't state %s"), name); 214 grecs_error(loc, errno, _("can't state %s"), name);
202 fclose(fp); 215 fclose(fp);
diff --git a/src/grecs.h b/src/grecs.h
index b839d71..5eef48d 100644
--- a/src/grecs.h
+++ b/src/grecs.h
@@ -263,6 +263,8 @@ int grecs_preproc_init(const char *name);
263void grecs_preproc_done(void); 263void grecs_preproc_done(void);
264int grecs_preproc_run(const char *config_file, const char *extpp); 264int grecs_preproc_run(const char *config_file, const char *extpp);
265 265
266char *grecs_find_include_file(const char *name, int allow_cwd);
267
266FILE *grecs_preproc_extrn_start(const char *file, pid_t *ppid); 268FILE *grecs_preproc_extrn_start(const char *file, pid_t *ppid);
267void grecs_preproc_extrn_shutdown(pid_t pid); 269void grecs_preproc_extrn_shutdown(pid_t pid);
268 270
diff --git a/src/preproc.c b/src/preproc.c
index 8debdcf..4ab3066 100644
--- a/src/preproc.c
+++ b/src/preproc.c
@@ -472,8 +472,8 @@ pop_source()
472 return 0; 472 return 0;
473} 473}
474 474
475static int 475char *
476try_file(const char *name, int allow_cwd, int err_not_found, char **newp) 476grecs_find_include_file(const char *name, int allow_cwd)
477{ 477{
478 static char *cwd = "."; 478 static char *cwd = ".";
479 struct file_data fd; 479 struct file_data fd;
@@ -495,16 +495,10 @@ try_file(const char *name, int allow_cwd, int err_not_found, char **newp)
495 495
496 if (!fd.found) { 496 if (!fd.found) {
497 pp_list_find(std_include_path, &fd); 497 pp_list_find(std_include_path, &fd);
498 498 if (!fd.found)
499 if (!fd.found && err_not_found) { 499 return NULL;
500 grecs_error(&LOCUS, 0,
501 _("%s: No such file or directory"), name);
502 *newp = NULL;
503 }
504 } 500 }
505 if (fd.found) 501 return fd.buf;
506 *newp = fd.buf;
507 return fd.found;
508} 502}
509 503
510static int 504static int
@@ -535,8 +529,13 @@ parse_include(const char *text, int once)
535 else 529 else
536 allow_cwd = 1; 530 allow_cwd = 1;
537 531
538 if (p[0] != '/' && try_file(p, allow_cwd, 1, &tmp)) 532 if (p[0] != '/') {
539 p = tmp; 533 p = grecs_find_include_file(p, allow_cwd);
534 if (!p)
535 grecs_error(&LOCUS, 0,
536 _("%s: No such file or directory"),
537 p);
538 }
540 } 539 }
541 540
542 if (p) 541 if (p)
@@ -573,18 +572,19 @@ grecs_preproc_run(const char *config_file, const char *extpp)
573 FILE *outfile; 572 FILE *outfile;
574 char *setup_file; 573 char *setup_file;
575 char *cmd = NULL; 574 char *cmd = NULL;
576 575
577 if (try_file("pp-setup", 1, 0, &setup_file)) { 576 setup_file = grecs_find_include_file("pp-setup", 1);
577 if (setup_file) {
578 size_t size = 0; 578 size_t size = 0;
579 if (grecs_asprintf(&cmd, &size, 579 if (grecs_asprintf(&cmd, &size,
580 "%s %s -", extpp, setup_file)) 580 "%s %s -", extpp, setup_file))
581 grecs_alloc_die(); 581 grecs_alloc_die();
582 grecs_free(setup_file); 582 grecs_free(setup_file);
583 } else 583 } else
584 cmd = grecs_strdup (extpp); 584 cmd = grecs_strdup(extpp);
585 /*FIXME_DEBUG_F1 (2, "Running preprocessor: `%s'", cmd);*/ 585 /*FIXME_DEBUG_F1 (2, "Running preprocessor: `%s'", cmd);*/
586 outfile = popen(cmd, "w"); 586 outfile = popen(cmd, "w");
587 if (!outfile){ 587 if (!outfile) {
588 grecs_error(NULL, errno, 588 grecs_error(NULL, errno,
589 _("Unable to start external preprocessor `%s'"), 589 _("Unable to start external preprocessor `%s'"),
590 cmd); 590 cmd);
diff --git a/tests/Makefile.am b/tests/Makefile.am
index f5d1f6f..1b47712 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -14,7 +14,19 @@
14# You should have received a copy of the GNU General Public License 14# You should have received a copy of the GNU General Public License
15# along with Grecs. If not, see <http://www.gnu.org/licenses/>. 15# along with Grecs. If not, see <http://www.gnu.org/licenses/>.
16 16
17EXTRA_DIST = $(TESTSUITE_AT) testsuite package.m4 gcf1.conf meta1.conf git.conf 17EXTRA_DIST = \
18 $(TESTSUITE_AT)\
19 testsuite\
20 package.m4\
21 gcf1.conf\
22 bind.conf\
23 bind.keys\
24 bind.int.conf\
25 bind.ext.conf\
26 bind.dlz\
27 meta1.conf\
28 git.conf
29
18DISTCLEANFILES = atconfig $(check_SCRIPTS) 30DISTCLEANFILES = atconfig $(check_SCRIPTS)
19MAINTAINERCLEANFILES = Makefile.in $(TESTSUITE) 31MAINTAINERCLEANFILES = Makefile.in $(TESTSUITE)
20 32
@@ -51,6 +63,7 @@ TESTSUITE_AT = \
51 glob03.at\ 63 glob03.at\
52 enum.at\ 64 enum.at\
53 join.at\ 65 join.at\
66 parser-bind.at\
54 parser-git.at\ 67 parser-git.at\
55 parser-meta1.at\ 68 parser-meta1.at\
56 peek00.at\ 69 peek00.at\
diff --git a/tests/bind.conf b/tests/bind.conf
new file mode 100644
index 0000000..2579a58
--- a/dev/null
+++ b/tests/bind.conf
@@ -0,0 +1,126 @@
1# Sample Bind configuration file for Grecs testsuite.
2# Nothing to copyright, really:)
3
4acl upd-dyn-vpn {
5 key vpn.;
6 10.11.0.1;
7 10.10.0.1;
8};
9
10acl foo-acl {
11 key foo.;
12};
13
14options {
15 version "Grecs testsuite";
16 coresize 0;
17 directory "/etc/namedb";
18 pid-file "/var/log/bind/named.pid";
19 allow-transfer {
20 foo-acl;
21 };
22 allow-query {
23 any;
24 };
25 serial-query-rate 5;
26 max-journal-size 5m;
27 check-names master warn;
28 check-names slave warn;
29 check-names response ignore;
30};
31
32 logging{
33 channel default_channel{
34 file "/var/log/bind/named.log" versions 9 size 524288;
35 print-time yes;
36 print-severity yes;
37 };
38 channel debug_channel {
39 file "/var/log/bind/named.run" versions 9 size 524288;
40 print-time yes;
41 print-severity yes;
42 severity dynamic;
43 };
44 channel security_channel {
45 file "/var/log/bind/security" versions 9 size 524288;
46 print-time yes;
47 print-severity yes;
48 };
49 channel xfer_in_channel {
50 file "/var/log/bind/named-xfer.in" versions 9 size 524288;
51 print-time yes;
52 };
53 channel xfer_out_channel {
54 file"/var/log/bind/named-xfer.out" versions 9 size 524288;
55 print-time yes;
56 };
57 channel lamers_channel {
58 file "/var/log/bind/lamers.log" versions 5 size 524288;
59 print-time yes;
60 print-category yes;
61 };
62 channel update_channel {
63 file "/var/log/bind/update.log" versions 9 size 524288;
64 print-time yes;
65 print-category yes;
66 severity debug 5;
67 };
68 channel notify_channel {
69 file "/var/log/bind/notify.log" versions 9 size 524288;
70 print-time yes;
71 print-category yes;
72 };
73 channel query_channel {
74 file "/var/log/bind/query.log" versions 9 size 524288;
75 print-time yes;
76 };
77 category security {
78 security_channel;
79 };
80 category queries {
81 # query_channel;
82 null;
83 };
84 category default {
85 default_channel;
86 debug_channel;
87 };
88 category xfer-in {
89 xfer_in_channel;
90 };
91 category xfer-out {
92 xfer_out_channel;
93 };
94 category delegation-only {
95 lamers_channel;
96 };
97 category lame-servers {
98 lamers_channel;
99 };
100 category update {
101 update_channel;
102 };
103 category notify {
104 notify_channel;
105 };
106};
107
108include "bind.keys";
109
110controls {
111 inet 127.0.0.1 port 953
112 allow { 127.0.0.1; } keys { "rndc-key"; };
113};
114
115view "internal" {
116 match-clients {
117 10.0.0.0/8;
118 };
119 include "bind.int.conf";
120};
121
122view "external" {
123 include "bind.ext.conf";
124 include "bind.dlz";
125};
126# Finis coronat opus
diff --git a/tests/bind.dlz b/tests/bind.dlz
new file mode 100644
index 0000000..ffbbfc9
--- a/dev/null
+++ b/tests/bind.dlz
@@ -0,0 +1,33 @@
1# Sample Bind configuration include file (3) for Grecs testsuite.
2# This is a typical (?) DLZ configuraton for BIND.
3#
4dlz "DLZ" {
5 database "mysql
6 {host=localhost socket=/var/run/mysql/mysql.sock dbname=Foo user=bind ssl=false}
7 {select r.zone from dns_soa r, dns_acl a where r.zone = '%zone%'
8 and a.network <= inet_aton('%client%') and inet_aton('%client%') <=
9 a.bcast
10 and a.view = r.view }
11 {select r.ttl, r.type, r.mx_priority,
12 case when r.type='TXT' then concat('\"', r.data, '\"') else r.data end
13 from dns_records r, dns_acl a,
14 where r.zone = '%zone%' and r.host = '%record%'
15 and not (r.type = 'SOA' or r.type = 'NS')
16 and a.network <= inet_aton('%client%') and inet_aton('%client%') <=
17 a.bcast
18 and a.view = r.view }
19 {select r.ttl, r.type, r.data, r.resp_person, r.serial,
20 r.refresh, r.retry, r.expire, r.minimum
21 from dns_soa r, dns_acl a where r.zone = '%zone%'
22 and (r.type = 'SOA' or r.type='NS')
23 and a.network <= inet_aton('%client%') and
24 inet_aton('%client%') <= a.bcast
25 and a.view = r.view }
26 {select r.ttl, r.type, r.host, r.mx_priority, case when r.type='TXT' then
27 concat('\"', r.data, '\"') else r.data end
28 from dns_records r, dns_acl a where r.zone = '%zone%'
29 and a.network <= inet_aton('%client%') and
30 inet_aton('%client%') <= a.bcast
31 and a.view = r.view }
32 {select zone from dns_xfr where zone = '%zone%' and client = '%client%'}";
33};
diff --git a/tests/bind.ext.conf b/tests/bind.ext.conf
new file mode 100644
index 0000000..b18e8f6
--- a/dev/null
+++ b/tests/bind.ext.conf
@@ -0,0 +1,25 @@
1# Sample Bind configuration include file (2) for Grecs testsuite.
2
3zone "." {
4 type hint;
5 file "named.root";
6};
7
8zone "com" {
9 type delegation-only;
10};
11
12zone "net" {
13 type delegation-only;
14};
15
16zone "0.0.127.IN-ADDR.ARPA" {
17 type master;
18 file "local.p";
19};
20
21zone "foo.example.net" {
22 type master;
23 file "foo.p";
24};
25 \ 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
--- a/dev/null
+++ b/tests/bind.int.conf
@@ -0,0 +1,17 @@
1# Sample Bind configuration include file (2) for Grecs testsuite.
2
3zone "int" {
4 type master;
5 file "int.p";
6 allow-update {
7 upd-dyn-vpn;
8 };
9 allow-query {
10 internal-hosts;
11 };
12 allow-transfer {
13 10.11.0.1;
14 10.10.0.4;
15 127.0.0.1;
16 };
17}; \ No newline at end of file
diff --git a/tests/bind.keys b/tests/bind.keys
new file mode 100644
index 0000000..ba43779
--- a/dev/null
+++ b/tests/bind.keys
@@ -0,0 +1,11 @@
1# Sample Bind configuration include file (1) for Grecs testsuite.
2
3key "rndc-key" {
4 algorithm hmac-md5;
5 secret "1111111111111111111111==";
6};
7
8
9
10
11
diff --git a/tests/gcffmt.c b/tests/gcffmt.c
index 51e3037..5dcd640 100644
--- a/tests/gcffmt.c
+++ b/tests/gcffmt.c
@@ -26,7 +26,7 @@ usage(const char *arg, FILE *fp, int code)
26{ 26{
27 fprintf(fp, 27 fprintf(fp,
28 "usage: %s [-h] [-locus] [-delim=char] [-reduce] [-sort] " 28 "usage: %s [-h] [-locus] [-delim=char] [-reduce] [-sort] "
29 "[-type=grecs|bind|meta1|git] file [file...]\n", 29 "[-type=grecs|bind|meta1|git] [-Idir] [-include=dir] file [file...]\n",
30 arg); 30 arg);
31 exit(code); 31 exit(code);
32} 32}
@@ -70,7 +70,11 @@ main(int argc, char **argv)
70 grecs_parser_fun = grecs_git_parser; 70 grecs_parser_fun = grecs_git_parser;
71 else 71 else
72 usage(progname, stderr, 1); 72 usage(progname, stderr, 1);
73 } else if (arg[0] == '-') 73 } else if (strncmp(arg, "-I", 2) == 0)
74 grecs_preproc_add_include_dir(arg+2);
75 else if (strncmp(arg, "-include=", 9) == 0)
76 grecs_preproc_add_include_dir(arg+9);
77 else if (arg[0] == '-')
74 usage(progname, stderr, 1); 78 usage(progname, stderr, 1);
75 else { 79 else {
76 file = arg; 80 file = arg;
diff --git a/tests/parser-bind.at b/tests/parser-bind.at
new file mode 100644
index 0000000..b7ae3e1
--- a/dev/null
+++ b/tests/parser-bind.at
@@ -0,0 +1,95 @@
1# This file is part of grecs -*- Autotest -*-
2# Copyright (C) 2011 Sergey Poznyakoff
3#
4# Grecs is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation; either version 3, or (at your option)
7# any later version.
8#
9# Grecs is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with Grecs. If not, see <http://www.gnu.org/licenses/>.
16
17AT_SETUP([BIND-style parser])
18AT_KEYWORDS([parser bind])
19
20AT_CHECK([gcffmt -type=bind -I$abs_srcdir $abs_srcdir/bind.conf|sed 's/ *$//'],
21[0],
22[.acl="upd-dyn-vpn".key: "vpn."
23.acl="upd-dyn-vpn".10.11.0.1:
24.acl="upd-dyn-vpn".10.10.0.1:
25.acl="foo-acl".key: "foo."
26.options.version: "Grecs testsuite"
27.options.coresize: "0"
28.options.directory: "/etc/namedb"
29.options.pid-file: "/var/log/bind/named.pid"
30.options.allow-transfer.foo-acl:
31.options.allow-query.any:
32.options.serial-query-rate: "5"
33.options.max-journal-size: "5m"
34.options.check-names: "master" "warn"
35.options.check-names: "slave" "warn"
36.options.check-names: "response" "ignore"
37.logging.channel="default_channel".file: "/var/log/bind/named.log" "versions" "9" "size" "524288"
38.logging.channel="default_channel".print-time: "yes"
39.logging.channel="default_channel".print-severity: "yes"
40.logging.channel="debug_channel".file: "/var/log/bind/named.run" "versions" "9" "size" "524288"
41.logging.channel="debug_channel".print-time: "yes"
42.logging.channel="debug_channel".print-severity: "yes"
43.logging.channel="debug_channel".severity: "dynamic"
44.logging.channel="security_channel".file: "/var/log/bind/security" "versions" "9" "size" "524288"
45.logging.channel="security_channel".print-time: "yes"
46.logging.channel="security_channel".print-severity: "yes"
47.logging.channel="xfer_in_channel".file: "/var/log/bind/named-xfer.in" "versions" "9" "size" "524288"
48.logging.channel="xfer_in_channel".print-time: "yes"
49.logging.channel="xfer_out_channel".file: "/var/log/bind/named-xfer.out" "versions" "9" "size" "524288"
50.logging.channel="xfer_out_channel".print-time: "yes"
51.logging.channel="lamers_channel".file: "/var/log/bind/lamers.log" "versions" "5" "size" "524288"
52.logging.channel="lamers_channel".print-time: "yes"
53.logging.channel="lamers_channel".print-category: "yes"
54.logging.channel="update_channel".file: "/var/log/bind/update.log" "versions" "9" "size" "524288"
55.logging.channel="update_channel".print-time: "yes"
56.logging.channel="update_channel".print-category: "yes"
57.logging.channel="update_channel".severity: "debug" "5"
58.logging.channel="notify_channel".file: "/var/log/bind/notify.log" "versions" "9" "size" "524288"
59.logging.channel="notify_channel".print-time: "yes"
60.logging.channel="notify_channel".print-category: "yes"
61.logging.channel="query_channel".file: "/var/log/bind/query.log" "versions" "9" "size" "524288"
62.logging.channel="query_channel".print-time: "yes"
63.logging.category="security".security_channel:
64.logging.category="queries".null:
65.logging.category="default".default_channel:
66.logging.category="default".debug_channel:
67.logging.category="xfer-in".xfer_in_channel:
68.logging.category="xfer-out".xfer_out_channel:
69.logging.category="delegation-only".lamers_channel:
70.logging.category="lame-servers".lamers_channel:
71.logging.category="update".update_channel:
72.logging.category="notify".notify_channel:
73.key="rndc-key".algorithm: "hmac-md5"
74.key="rndc-key".secret: "1111111111111111111111=="
75.controls.inet: "127.0.0.1" "port" "953" "allow" ("127.0.0.1") "keys" ("rndc-key")
76.view="internal".match-clients.10.0.0.0/8:
77.view="internal".zone="int".type: "master"
78.view="internal".zone="int".file: "int.p"
79.view="internal".zone="int".allow-update.upd-dyn-vpn:
80.view="internal".zone="int".allow-query.internal-hosts:
81.view="internal".zone="int".allow-transfer.10.11.0.1:
82.view="internal".zone="int".allow-transfer.10.10.0.4:
83.view="internal".zone="int".allow-transfer.127.0.0.1:
84.view="external".zone=".".type: "hint"
85.view="external".zone=".".file: "named.root"
86.view="external".zone="com".type: "delegation-only"
87.view="external".zone="net".type: "delegation-only"
88.view="external".zone="0.0.127.IN-ADDR.ARPA".type: "master"
89.view="external".zone="0.0.127.IN-ADDR.ARPA".file: "local.p"
90.view="external".zone="foo.example.net".type: "master"
91.view="external".zone="foo.example.net".file: "foo.p"
92.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%'}"
93])
94
95AT_CLEANUP
diff --git a/tests/testsuite.at b/tests/testsuite.at
index b81b45e..5b4c9a4 100644
--- a/tests/testsuite.at
+++ b/tests/testsuite.at
@@ -73,6 +73,7 @@ m4_include([reduce03.at])
73 73
74m4_include([join.at]) 74m4_include([join.at])
75 75
76m4_include([parser-bind.at])
76m4_include([parser-git.at]) 77m4_include([parser-git.at])
77m4_include([parser-meta1.at]) 78m4_include([parser-meta1.at])
78 79

Return to:

Send suggestions and report system problems to the System administrator.