Blame


1 2540a41a 2014-04-12 pjp /*
2 2540a41a 2014-04-12 pjp * Copyright (c) 2014 Peter J. Philipp. All rights reserved.
3 2540a41a 2014-04-12 pjp * Copyright (c) 2008 Gilles Chehade <gilles@poolp.org>
4 2540a41a 2014-04-12 pjp * Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org>
5 2540a41a 2014-04-12 pjp * Copyright (c) 2002, 2003, 2004 Henning Brauer <henning@openbsd.org>
6 2540a41a 2014-04-12 pjp * Copyright (c) 2001 Markus Friedl. All rights reserved.
7 2540a41a 2014-04-12 pjp * Copyright (c) 2001 Daniel Hartmeier. All rights reserved.
8 2540a41a 2014-04-12 pjp * Copyright (c) 2001 Theo de Raadt. All rights reserved.
9 2540a41a 2014-04-12 pjp *
10 2540a41a 2014-04-12 pjp * Permission to use, copy, modify, and distribute this software for any
11 2540a41a 2014-04-12 pjp * purpose with or without fee is hereby granted, provided that the above
12 2540a41a 2014-04-12 pjp * copyright notice and this permission notice appear in all copies.
13 2540a41a 2014-04-12 pjp *
14 2540a41a 2014-04-12 pjp * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
15 2540a41a 2014-04-12 pjp * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
16 2540a41a 2014-04-12 pjp * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
17 2540a41a 2014-04-12 pjp * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
18 2540a41a 2014-04-12 pjp * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
19 2540a41a 2014-04-12 pjp * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
20 2540a41a 2014-04-12 pjp * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 2540a41a 2014-04-12 pjp */
22 2540a41a 2014-04-12 pjp
23 2540a41a 2014-04-12 pjp %{
24 2540a41a 2014-04-12 pjp #include "include.h"
25 2540a41a 2014-04-12 pjp #include "dns.h"
26 2540a41a 2014-04-12 pjp #include "db.h"
27 2540a41a 2014-04-12 pjp
28 0e7d94ac 2014-05-18 pjp
29 0e7d94ac 2014-05-18 pjp extern void dolog(int, char *, ...);
30 0e7d94ac 2014-05-18 pjp extern char *dns_label(char *, int *);
31 0e7d94ac 2014-05-18 pjp extern u_int8_t find_region(struct sockaddr_storage *, int);
32 0e7d94ac 2014-05-18 pjp extern int insert_region(char *, char *, u_int8_t);
33 0e7d94ac 2014-05-18 pjp extern int insert_axfr(char *, char *);
34 0e7d94ac 2014-05-18 pjp extern int insert_notifyslave(char *, char *);
35 0e7d94ac 2014-05-18 pjp extern int insert_filter(char *, char *);
36 0e7d94ac 2014-05-18 pjp extern int insert_recurse(char *, char *);
37 6f8d6a57 2014-05-18 pjp extern int insert_whitelist(char *, char *);
38 0e7d94ac 2014-05-18 pjp extern int insert_wildcard(char *, char *);
39 0e7d94ac 2014-05-18 pjp extern void slave_shutdown(void);
40 fedd844f 2014-09-27 pjp void yyerror(const char *);
41 0e7d94ac 2014-05-18 pjp
42 6f8d6a57 2014-05-18 pjp extern int whitelist;
43 0e7d94ac 2014-05-18 pjp extern int notify;
44 0e7d94ac 2014-05-18 pjp extern int errno;
45 0e7d94ac 2014-05-18 pjp extern int debug;
46 0e7d94ac 2014-05-18 pjp extern int verbose;
47 0e7d94ac 2014-05-18 pjp extern int bflag;
48 0e7d94ac 2014-05-18 pjp extern int iflag;
49 0e7d94ac 2014-05-18 pjp extern int lflag;
50 0e7d94ac 2014-05-18 pjp extern int nflag;
51 0e7d94ac 2014-05-18 pjp extern int rflag;
52 0e7d94ac 2014-05-18 pjp extern int bcount;
53 0e7d94ac 2014-05-18 pjp extern int icount;
54 0e7d94ac 2014-05-18 pjp extern int ratelimit;
55 0e7d94ac 2014-05-18 pjp extern int ratelimit_packets_per_second;
56 0e7d94ac 2014-05-18 pjp extern u_int16_t port;
57 0e7d94ac 2014-05-18 pjp extern u_int32_t cachesize;
58 0e7d94ac 2014-05-18 pjp extern char *bind_list[255];
59 0e7d94ac 2014-05-18 pjp extern char *interface_list[255];
60 0e7d94ac 2014-05-18 pjp
61 0e7d94ac 2014-05-18 pjp
62 0e7d94ac 2014-05-18 pjp
63 2540a41a 2014-04-12 pjp TAILQ_HEAD(files, file) files = TAILQ_HEAD_INITIALIZER(files);
64 2540a41a 2014-04-12 pjp static struct file {
65 2540a41a 2014-04-12 pjp TAILQ_ENTRY(file) entry;
66 2540a41a 2014-04-12 pjp FILE *stream;
67 2540a41a 2014-04-12 pjp char *name;
68 2540a41a 2014-04-12 pjp int lineno;
69 2540a41a 2014-04-12 pjp int errors;
70 2540a41a 2014-04-12 pjp } *file, *topfile;
71 2540a41a 2014-04-12 pjp
72 2540a41a 2014-04-12 pjp #define STATE_IP 1
73 2540a41a 2014-04-12 pjp #define STATE_ZONE 2
74 2540a41a 2014-04-12 pjp
75 2540a41a 2014-04-12 pjp #define WILDCARDVERSION 6
76 2540a41a 2014-04-12 pjp
77 2540a41a 2014-04-12 pjp #define CONFIG_START 0x1
78 2540a41a 2014-04-12 pjp #define CONFIG_VERSION 0x2
79 2540a41a 2014-04-12 pjp #define CONFIG_REGION 0x4
80 2540a41a 2014-04-12 pjp #define CONFIG_ZONE 0x8
81 2540a41a 2014-04-12 pjp #define CONFIG_INCLUDE 0x10
82 2540a41a 2014-04-12 pjp #define CONFIG_WILDCARDONLYFOR 0x20
83 2540a41a 2014-04-12 pjp #define CONFIG_RECURSEFOR 0x40
84 2540a41a 2014-04-12 pjp #define CONFIG_LOGGING 0x80
85 2540a41a 2014-04-12 pjp #define CONFIG_AXFRFOR 0x100
86 2540a41a 2014-04-12 pjp #define CONFIG_AXFRPORT 0x200
87 2540a41a 2014-04-12 pjp
88 2540a41a 2014-04-12 pjp typedef struct {
89 2540a41a 2014-04-12 pjp union {
90 2540a41a 2014-04-12 pjp char *string;
91 2540a41a 2014-04-12 pjp int intval;
92 2540a41a 2014-04-12 pjp } v;
93 2540a41a 2014-04-12 pjp int lineno;
94 2540a41a 2014-04-12 pjp } YYSTYPE;
95 2540a41a 2014-04-12 pjp
96 fedd844f 2014-09-27 pjp #ifdef __APPLE__
97 fedd844f 2014-09-27 pjp #define YYSTYPE_IS_DECLARED 1
98 fedd844f 2014-09-27 pjp #endif
99 fedd844f 2014-09-27 pjp
100 27110135 2014-11-07 pjp static const char rcsid[] = "$Id: parse.y,v 1.25 2014/11/07 10:33:12 pjp Exp $";
101 2540a41a 2014-04-12 pjp static int version = 0;
102 2540a41a 2014-04-12 pjp static int state = 0;
103 2540a41a 2014-04-12 pjp static uint8_t region = 0;
104 2540a41a 2014-04-12 pjp static uint64_t confstatus = 0;
105 2540a41a 2014-04-12 pjp static DB *mydb;
106 2540a41a 2014-04-12 pjp
107 2540a41a 2014-04-12 pjp YYSTYPE yylval;
108 6a6113d4 2014-04-13 pjp
109 6a6113d4 2014-04-13 pjp
110 2540a41a 2014-04-12 pjp char *converted_name;
111 2540a41a 2014-04-12 pjp int converted_namelen;
112 2540a41a 2014-04-12 pjp DBT key, data;
113 2540a41a 2014-04-12 pjp struct logging logging;
114 2540a41a 2014-04-12 pjp int axfrport = 0;
115 58eafea4 2014-05-17 pjp time_t time_changed;
116 2540a41a 2014-04-12 pjp
117 2540a41a 2014-04-12 pjp
118 2540a41a 2014-04-12 pjp
119 0e7d94ac 2014-05-18 pjp char *check_rr(char *, char *, int, int *);
120 0e7d94ac 2014-05-18 pjp int fill_a(char *, char *, int, char *);
121 0e7d94ac 2014-05-18 pjp int fill_aaaa(char *, char *, int, char *);
122 0e7d94ac 2014-05-18 pjp int fill_balance(char *, char *, int, char *);
123 0e7d94ac 2014-05-18 pjp int fill_ptr(char *, char *, int, char *);
124 0e7d94ac 2014-05-18 pjp int fill_cname(char *, char *, int, char *);
125 0e7d94ac 2014-05-18 pjp int fill_mx(char *, char *, int, int, char *);
126 0e7d94ac 2014-05-18 pjp int fill_naptr(char *, char *, int, int, int, char *, char *, char *, char *);
127 0e7d94ac 2014-05-18 pjp int fill_ns(char *, char *, int, char *);
128 0e7d94ac 2014-05-18 pjp int fill_soa(char *, char *, int, char *, char *, int, int, int, int, int);
129 0e7d94ac 2014-05-18 pjp int fill_spf(char *, char *, int, char *);
130 0e7d94ac 2014-05-18 pjp int fill_sshfp(char *, char *, int, int, int, char *);
131 0e7d94ac 2014-05-18 pjp int fill_srv(char *, char *, int, int, int, int, char *);
132 0e7d94ac 2014-05-18 pjp int fill_txt(char *, char *, int, char *);
133 0e7d94ac 2014-05-18 pjp int findeol(void);
134 0e7d94ac 2014-05-18 pjp int get_ip(char *, int);
135 0e7d94ac 2014-05-18 pjp char *get_prefixlen(char *, char *, int);
136 0e7d94ac 2014-05-18 pjp int get_quotedstring(char *, int);
137 0e7d94ac 2014-05-18 pjp int get_record(struct domain *, char *, int);
138 0e7d94ac 2014-05-18 pjp int get_string(char *, int);
139 0e7d94ac 2014-05-18 pjp int lgetc(int);
140 0e7d94ac 2014-05-18 pjp struct tab * lookup(struct tab *, char *);
141 0e7d94ac 2014-05-18 pjp int lungetc(int);
142 0e7d94ac 2014-05-18 pjp int parse_file(DB *, char *);
143 2540a41a 2014-04-12 pjp struct file *pushfile(const char *, int);
144 0e7d94ac 2014-05-18 pjp int popfile(void);
145 0e7d94ac 2014-05-18 pjp struct rrtab *rrlookup(struct rrtab *, char *);
146 0e7d94ac 2014-05-18 pjp void set_record(struct domain *, char *, int);
147 0e7d94ac 2014-05-18 pjp static int temp_inet_net_pton_ipv6(const char *, void *, size_t);
148 0e7d94ac 2014-05-18 pjp int yyparse(void);
149 2540a41a 2014-04-12 pjp
150 2540a41a 2014-04-12 pjp
151 0e7d94ac 2014-05-18 pjp struct rrtab {
152 0e7d94ac 2014-05-18 pjp char *name;
153 0e7d94ac 2014-05-18 pjp u_int16_t type;
154 0e7d94ac 2014-05-18 pjp } myrrtab[] = {
155 0e7d94ac 2014-05-18 pjp { "a", DNS_TYPE_A } ,
156 0e7d94ac 2014-05-18 pjp { "soa", DNS_TYPE_SOA },
157 0e7d94ac 2014-05-18 pjp { "cname", DNS_TYPE_CNAME },
158 0e7d94ac 2014-05-18 pjp { "ptr", DNS_TYPE_PTR },
159 0e7d94ac 2014-05-18 pjp { "mx", DNS_TYPE_MX },
160 0e7d94ac 2014-05-18 pjp { "aaaa", DNS_TYPE_AAAA },
161 0e7d94ac 2014-05-18 pjp { "ns", DNS_TYPE_NS },
162 0e7d94ac 2014-05-18 pjp { "txt", DNS_TYPE_TXT },
163 0e7d94ac 2014-05-18 pjp { "hint", DNS_TYPE_HINT },
164 0e7d94ac 2014-05-18 pjp { "delegate", DNS_TYPE_DELEGATE },
165 0e7d94ac 2014-05-18 pjp { "balance", DNS_TYPE_BALANCE },
166 0e7d94ac 2014-05-18 pjp { "srv", DNS_TYPE_SRV },
167 0e7d94ac 2014-05-18 pjp { "spf", DNS_TYPE_SPF },
168 0e7d94ac 2014-05-18 pjp { "sshfp", DNS_TYPE_SSHFP },
169 0e7d94ac 2014-05-18 pjp { "naptr", DNS_TYPE_NAPTR },
170 0e7d94ac 2014-05-18 pjp { NULL, 0 },
171 0e7d94ac 2014-05-18 pjp };
172 2540a41a 2014-04-12 pjp
173 2540a41a 2014-04-12 pjp
174 2540a41a 2014-04-12 pjp
175 2540a41a 2014-04-12 pjp
176 2540a41a 2014-04-12 pjp %}
177 2540a41a 2014-04-12 pjp
178 2540a41a 2014-04-12 pjp
179 2540a41a 2014-04-12 pjp %token VERSION OBRACE EBRACE REGION AXFRFOR RECURSEFOR
180 2540a41a 2014-04-12 pjp %token DOT COLON TEXT WOF INCLUDE ZONE COMMA CRLF
181 58eafea4 2014-05-17 pjp %token ERROR AXFRPORT LOGGING OPTIONS FILTER NOTIFY
182 6f8d6a57 2014-05-18 pjp %token WHITELIST
183 2540a41a 2014-04-12 pjp
184 2540a41a 2014-04-12 pjp %token <v.string> POUND
185 2540a41a 2014-04-12 pjp %token <v.string> SEMICOLON
186 2540a41a 2014-04-12 pjp %token <v.string> STRING
187 2540a41a 2014-04-12 pjp %token <v.string> IP
188 2540a41a 2014-04-12 pjp %token <v.string> IPV6
189 2540a41a 2014-04-12 pjp %token <v.string> SLASH
190 2540a41a 2014-04-12 pjp %token <v.string> QUOTEDSTRING
191 2540a41a 2014-04-12 pjp
192 2540a41a 2014-04-12 pjp %token <v.intval> NUMBER
193 2540a41a 2014-04-12 pjp
194 2540a41a 2014-04-12 pjp %type <v.string> quotednumber quotedfilename ipcidr
195 2540a41a 2014-04-12 pjp
196 2540a41a 2014-04-12 pjp %start cmd_list
197 2540a41a 2014-04-12 pjp
198 2540a41a 2014-04-12 pjp %%
199 2540a41a 2014-04-12 pjp cmd_list:
200 2540a41a 2014-04-12 pjp | cmd_list cmd
201 2540a41a 2014-04-12 pjp ;
202 2540a41a 2014-04-12 pjp
203 2540a41a 2014-04-12 pjp cmd :
204 2540a41a 2014-04-12 pjp version
205 2540a41a 2014-04-12 pjp | axfrport
206 2540a41a 2014-04-12 pjp | include
207 2540a41a 2014-04-12 pjp | zone
208 2540a41a 2014-04-12 pjp | region CRLF
209 2540a41a 2014-04-12 pjp | wof CRLF
210 2540a41a 2014-04-12 pjp | axfr CRLF
211 58eafea4 2014-05-17 pjp | notify CRLF
212 6f8d6a57 2014-05-18 pjp | whitelist CRLF
213 c0963faf 2014-05-01 pjp | filter CRLF
214 2540a41a 2014-04-12 pjp | recurse CRLF
215 2540a41a 2014-04-12 pjp | logging
216 2540a41a 2014-04-12 pjp | comment CRLF
217 0f80aa4d 2014-04-15 pjp | options
218 2540a41a 2014-04-12 pjp ;
219 2540a41a 2014-04-12 pjp
220 2540a41a 2014-04-12 pjp
221 2540a41a 2014-04-12 pjp comment:
222 2540a41a 2014-04-12 pjp comment comments
223 2540a41a 2014-04-12 pjp | comments
224 2540a41a 2014-04-12 pjp ;
225 2540a41a 2014-04-12 pjp
226 2540a41a 2014-04-12 pjp comments:
227 2540a41a 2014-04-12 pjp SEMICOLON
228 2540a41a 2014-04-12 pjp | POUND
229 2540a41a 2014-04-12 pjp ;
230 2540a41a 2014-04-12 pjp
231 2540a41a 2014-04-12 pjp version:
232 2540a41a 2014-04-12 pjp VERSION quotednumber SEMICOLON CRLF
233 2540a41a 2014-04-12 pjp {
234 2540a41a 2014-04-12 pjp version = atoi($2);
235 2540a41a 2014-04-12 pjp if (version != WILDCARDVERSION) {
236 2540a41a 2014-04-12 pjp dolog(LOG_ERR, "version of configfile is wrong,"
237 2540a41a 2014-04-12 pjp " must be \"%d\"!\n", WILDCARDVERSION);
238 2540a41a 2014-04-12 pjp return (-1);
239 2540a41a 2014-04-12 pjp }
240 2540a41a 2014-04-12 pjp free ($2);
241 2540a41a 2014-04-12 pjp
242 2540a41a 2014-04-12 pjp confstatus |= CONFIG_VERSION;
243 2540a41a 2014-04-12 pjp }
244 2540a41a 2014-04-12 pjp ;
245 2540a41a 2014-04-12 pjp
246 2540a41a 2014-04-12 pjp axfrport:
247 2540a41a 2014-04-12 pjp AXFRPORT quotednumber SEMICOLON CRLF
248 2540a41a 2014-04-12 pjp {
249 2540a41a 2014-04-12 pjp if ((confstatus & CONFIG_VERSION) != CONFIG_VERSION) {
250 2540a41a 2014-04-12 pjp dolog(LOG_INFO, "There must be a version at the top of the first configfile\n");
251 2540a41a 2014-04-12 pjp return (-1);
252 2540a41a 2014-04-12 pjp }
253 2540a41a 2014-04-12 pjp
254 2540a41a 2014-04-12 pjp axfrport = atoi($2);
255 2540a41a 2014-04-12 pjp free ($2);
256 2540a41a 2014-04-12 pjp }
257 2540a41a 2014-04-12 pjp ;
258 2540a41a 2014-04-12 pjp
259 2540a41a 2014-04-12 pjp quotednumber:
260 2540a41a 2014-04-12 pjp QUOTEDSTRING
261 2540a41a 2014-04-12 pjp {
262 6a6113d4 2014-04-13 pjp if (debug)
263 6a6113d4 2014-04-13 pjp printf("quotednumber is %s\n", $$);
264 2540a41a 2014-04-12 pjp }
265 2540a41a 2014-04-12 pjp ;
266 2540a41a 2014-04-12 pjp
267 2540a41a 2014-04-12 pjp include:
268 2540a41a 2014-04-12 pjp includes CRLF
269 2540a41a 2014-04-12 pjp ;
270 2540a41a 2014-04-12 pjp
271 2540a41a 2014-04-12 pjp includes:
272 2540a41a 2014-04-12 pjp INCLUDE quotedfilename SEMICOLON {
273 2540a41a 2014-04-12 pjp struct file *nfile;
274 2540a41a 2014-04-12 pjp
275 2540a41a 2014-04-12 pjp if ((confstatus & CONFIG_VERSION) != CONFIG_VERSION) {
276 2540a41a 2014-04-12 pjp dolog(LOG_INFO, "There must be a version at the top of the first configfile\n");
277 2540a41a 2014-04-12 pjp return (-1);
278 2540a41a 2014-04-12 pjp }
279 2540a41a 2014-04-12 pjp
280 2540a41a 2014-04-12 pjp if ((nfile = pushfile($2, 0)) == NULL) {
281 2540a41a 2014-04-12 pjp fprintf(stderr, "failed to include file %s\n", $2);
282 2540a41a 2014-04-12 pjp free($2);
283 2540a41a 2014-04-12 pjp return (-1);
284 2540a41a 2014-04-12 pjp }
285 2540a41a 2014-04-12 pjp
286 2540a41a 2014-04-12 pjp free($2);
287 2540a41a 2014-04-12 pjp
288 2540a41a 2014-04-12 pjp file = nfile;
289 2540a41a 2014-04-12 pjp }
290 2540a41a 2014-04-12 pjp ;
291 2540a41a 2014-04-12 pjp
292 2540a41a 2014-04-12 pjp quotedfilename:
293 2540a41a 2014-04-12 pjp QUOTEDSTRING
294 2540a41a 2014-04-12 pjp {
295 6a6113d4 2014-04-13 pjp if (debug)
296 6a6113d4 2014-04-13 pjp printf("quotedfilename is %s\n", $$);
297 2540a41a 2014-04-12 pjp }
298 2540a41a 2014-04-12 pjp ;
299 2540a41a 2014-04-12 pjp
300 2540a41a 2014-04-12 pjp /* zone */
301 2540a41a 2014-04-12 pjp
302 2540a41a 2014-04-12 pjp zone:
303 2540a41a 2014-04-12 pjp ZONE zonelabel zonecontent
304 2540a41a 2014-04-12 pjp {
305 2540a41a 2014-04-12 pjp if ((confstatus & CONFIG_VERSION) != CONFIG_VERSION) {
306 2540a41a 2014-04-12 pjp dolog(LOG_INFO, "There must be a version at the top of the first configfile\n");
307 2540a41a 2014-04-12 pjp return (-1);
308 2540a41a 2014-04-12 pjp }
309 2540a41a 2014-04-12 pjp }
310 2540a41a 2014-04-12 pjp ;
311 2540a41a 2014-04-12 pjp
312 2540a41a 2014-04-12 pjp zonelabel:
313 2540a41a 2014-04-12 pjp QUOTEDSTRING
314 2540a41a 2014-04-12 pjp ;
315 2540a41a 2014-04-12 pjp
316 2540a41a 2014-04-12 pjp zonecontent:
317 2540a41a 2014-04-12 pjp OBRACE zonestatements EBRACE CRLF
318 2540a41a 2014-04-12 pjp | OBRACE CRLF zonestatements EBRACE CRLF
319 2540a41a 2014-04-12 pjp ;
320 2540a41a 2014-04-12 pjp
321 2540a41a 2014-04-12 pjp
322 2540a41a 2014-04-12 pjp zonestatements :
323 2540a41a 2014-04-12 pjp zonestatements zonestatement
324 2540a41a 2014-04-12 pjp | zonestatement
325 2540a41a 2014-04-12 pjp ;
326 2540a41a 2014-04-12 pjp
327 2540a41a 2014-04-12 pjp
328 2540a41a 2014-04-12 pjp zonestatement:
329 2540a41a 2014-04-12 pjp
330 2540a41a 2014-04-12 pjp /* centroid.eu,soa,3600,uranus.centroid.eu.,pjp.solarscale.de.,1258740680,3600,1800,7200,3600 */
331 2540a41a 2014-04-12 pjp
332 2540a41a 2014-04-12 pjp STRING COMMA STRING COMMA NUMBER COMMA STRING COMMA STRING COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER CRLF
333 2540a41a 2014-04-12 pjp {
334 2540a41a 2014-04-12 pjp if (strcasecmp($3, "soa") == 0) {
335 2540a41a 2014-04-12 pjp if (fill_soa($1, $3, $5, $7, $9, $11, $13, $15, $17, $19) < 0) {
336 2540a41a 2014-04-12 pjp return -1;
337 2540a41a 2014-04-12 pjp }
338 2540a41a 2014-04-12 pjp
339 6a6113d4 2014-04-13 pjp if (debug)
340 6a6113d4 2014-04-13 pjp printf("%s SOA\n", $1);
341 2540a41a 2014-04-12 pjp } else {
342 6a6113d4 2014-04-13 pjp if (debug)
343 6a6113d4 2014-04-13 pjp printf("soa error\n");
344 2540a41a 2014-04-12 pjp return -1;
345 2540a41a 2014-04-12 pjp }
346 2540a41a 2014-04-12 pjp
347 2540a41a 2014-04-12 pjp
348 2540a41a 2014-04-12 pjp free ($1);
349 2540a41a 2014-04-12 pjp free ($3);
350 2540a41a 2014-04-12 pjp free ($7);
351 2540a41a 2014-04-12 pjp free ($9);
352 2540a41a 2014-04-12 pjp }
353 2540a41a 2014-04-12 pjp |
354 df34d218 2014-04-21 pjp STRING COMMA STRING COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA QUOTEDSTRING CRLF
355 df34d218 2014-04-21 pjp {
356 df34d218 2014-04-21 pjp if (strcasecmp($3, "sshfp") == 0) {
357 df34d218 2014-04-21 pjp if (fill_sshfp($1, $3, $5, $7, $9, $11) < 0) {
358 df34d218 2014-04-21 pjp return -1;
359 df34d218 2014-04-21 pjp }
360 df34d218 2014-04-21 pjp
361 df34d218 2014-04-21 pjp } else {
362 df34d218 2014-04-21 pjp if (debug)
363 df34d218 2014-04-21 pjp printf("another sshfp record I don't know about?");
364 df34d218 2014-04-21 pjp return (-1);
365 df34d218 2014-04-21 pjp }
366 df34d218 2014-04-21 pjp
367 df34d218 2014-04-21 pjp free ($1);
368 df34d218 2014-04-21 pjp free ($3);
369 df34d218 2014-04-21 pjp free ($11);
370 df34d218 2014-04-21 pjp }
371 df34d218 2014-04-21 pjp |
372 2540a41a 2014-04-12 pjp STRING COMMA STRING COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA STRING CRLF
373 2540a41a 2014-04-12 pjp {
374 2540a41a 2014-04-12 pjp if (strcasecmp($3, "srv") == 0) {
375 2540a41a 2014-04-12 pjp if (fill_srv($1, $3, $5, $7, $9, $11, $13) < 0) {
376 2540a41a 2014-04-12 pjp return -1;
377 2540a41a 2014-04-12 pjp }
378 2540a41a 2014-04-12 pjp
379 2540a41a 2014-04-12 pjp } else {
380 f22153d0 2014-04-13 pjp if (debug)
381 f22153d0 2014-04-13 pjp printf("2 another record I don't know about?");
382 2540a41a 2014-04-12 pjp return (-1);
383 2540a41a 2014-04-12 pjp }
384 2540a41a 2014-04-12 pjp
385 2540a41a 2014-04-12 pjp free ($1);
386 2540a41a 2014-04-12 pjp free ($3);
387 2540a41a 2014-04-12 pjp free ($13);
388 2540a41a 2014-04-12 pjp }
389 2540a41a 2014-04-12 pjp |
390 2540a41a 2014-04-12 pjp STRING COMMA STRING COMMA NUMBER COMMA STRING CRLF {
391 2540a41a 2014-04-12 pjp if (strcasecmp($3, "ns") == 0 ||
392 2540a41a 2014-04-12 pjp strcasecmp($3, "delegate") == 0 ||
393 2540a41a 2014-04-12 pjp strcasecmp($3, "hint") == 0) {
394 2540a41a 2014-04-12 pjp if (fill_ns($1, $3, $5, $7) < 0) {
395 2540a41a 2014-04-12 pjp return -1;
396 2540a41a 2014-04-12 pjp }
397 2540a41a 2014-04-12 pjp
398 6a6113d4 2014-04-13 pjp if (debug)
399 6a6113d4 2014-04-13 pjp printf("%s NS\n", $1);
400 6a6113d4 2014-04-13 pjp
401 2540a41a 2014-04-12 pjp } else if (strcasecmp($3, "ptr") == 0) {
402 2540a41a 2014-04-12 pjp if (fill_ptr($1, $3, $5, $7) < 0) {
403 2540a41a 2014-04-12 pjp return -1;
404 2540a41a 2014-04-12 pjp }
405 6a6113d4 2014-04-13 pjp
406 f22153d0 2014-04-13 pjp if (debug)
407 6a6113d4 2014-04-13 pjp printf("%s PTR\n", $1);
408 6a6113d4 2014-04-13 pjp
409 2540a41a 2014-04-12 pjp } else if (strcasecmp($3, "cname") == 0) {
410 2540a41a 2014-04-12 pjp if (fill_cname($1, $3, $5, $7) < 0) {
411 2540a41a 2014-04-12 pjp return -1;
412 2540a41a 2014-04-12 pjp }
413 6a6113d4 2014-04-13 pjp
414 6a6113d4 2014-04-13 pjp if (debug)
415 6a6113d4 2014-04-13 pjp printf("%s CNAME\n", $3);
416 6a6113d4 2014-04-13 pjp
417 2540a41a 2014-04-12 pjp } else {
418 f22153d0 2014-04-13 pjp if (debug)
419 f22153d0 2014-04-13 pjp printf("%s other\n", $3);
420 2540a41a 2014-04-12 pjp return -1;
421 2540a41a 2014-04-12 pjp }
422 2540a41a 2014-04-12 pjp
423 2540a41a 2014-04-12 pjp free ($1);
424 2540a41a 2014-04-12 pjp free ($3);
425 2540a41a 2014-04-12 pjp free ($7);
426 2540a41a 2014-04-12 pjp }
427 2540a41a 2014-04-12 pjp |
428 2540a41a 2014-04-12 pjp STRING COMMA STRING COMMA NUMBER COMMA IPV6 CRLF {
429 2540a41a 2014-04-12 pjp if (strcasecmp($3, "aaaa") == 0) {
430 2540a41a 2014-04-12 pjp if (fill_aaaa($1, $3, $5, $7) < 0) {
431 2540a41a 2014-04-12 pjp return -1;
432 2540a41a 2014-04-12 pjp }
433 2540a41a 2014-04-12 pjp
434 6a6113d4 2014-04-13 pjp if (debug)
435 6a6113d4 2014-04-13 pjp printf("%s AAAA\n", $1);
436 2540a41a 2014-04-12 pjp } else {
437 6a6113d4 2014-04-13 pjp
438 6a6113d4 2014-04-13 pjp if (debug)
439 6a6113d4 2014-04-13 pjp printf("error AAAA\n");
440 2540a41a 2014-04-12 pjp return (-1);
441 2540a41a 2014-04-12 pjp }
442 2540a41a 2014-04-12 pjp free ($1);
443 2540a41a 2014-04-12 pjp free ($3);
444 2540a41a 2014-04-12 pjp free ($7);
445 2540a41a 2014-04-12 pjp }
446 2540a41a 2014-04-12 pjp |
447 2540a41a 2014-04-12 pjp STRING COMMA STRING COMMA NUMBER COMMA IP CRLF
448 2540a41a 2014-04-12 pjp {
449 2540a41a 2014-04-12 pjp if (strcasecmp($3, "a") == 0) {
450 2540a41a 2014-04-12 pjp if (fill_a($1, $3, $5, $7) < 0) {
451 2540a41a 2014-04-12 pjp return -1;
452 2540a41a 2014-04-12 pjp }
453 2540a41a 2014-04-12 pjp
454 6a6113d4 2014-04-13 pjp if (debug)
455 6a6113d4 2014-04-13 pjp printf("%s A\n", $1);
456 6a6113d4 2014-04-13 pjp
457 2540a41a 2014-04-12 pjp } else if (strcasecmp($3, "balance") == 0) {
458 2540a41a 2014-04-12 pjp if (fill_balance($1, $3, $5, $7) < 0) {
459 2540a41a 2014-04-12 pjp return -1;
460 2540a41a 2014-04-12 pjp }
461 2540a41a 2014-04-12 pjp
462 6a6113d4 2014-04-13 pjp if (debug)
463 6a6113d4 2014-04-13 pjp printf("a balance record?\n");
464 2540a41a 2014-04-12 pjp } else {
465 6a6113d4 2014-04-13 pjp if (debug)
466 6a6113d4 2014-04-13 pjp printf("another a record?\n");
467 2540a41a 2014-04-12 pjp return -1;
468 2540a41a 2014-04-12 pjp }
469 2540a41a 2014-04-12 pjp
470 2540a41a 2014-04-12 pjp free ($1);
471 2540a41a 2014-04-12 pjp free ($3);
472 2540a41a 2014-04-12 pjp free ($7);
473 2540a41a 2014-04-12 pjp }
474 2540a41a 2014-04-12 pjp |
475 2540a41a 2014-04-12 pjp STRING COMMA STRING COMMA NUMBER COMMA NUMBER COMMA STRING CRLF
476 2540a41a 2014-04-12 pjp {
477 2540a41a 2014-04-12 pjp if (strcasecmp($3, "mx") == 0) {
478 2540a41a 2014-04-12 pjp if (fill_mx($1, $3, $5, $7, $9) < 0) {
479 2540a41a 2014-04-12 pjp return -1;
480 2540a41a 2014-04-12 pjp }
481 2540a41a 2014-04-12 pjp
482 6a6113d4 2014-04-13 pjp if (debug)
483 6a6113d4 2014-04-13 pjp printf("%s MX -> %d %s\n", $1, $7, $9);
484 6a6113d4 2014-04-13 pjp
485 2540a41a 2014-04-12 pjp } else {
486 6a6113d4 2014-04-13 pjp if (debug)
487 6a6113d4 2014-04-13 pjp printf("another record I don't know about?");
488 2540a41a 2014-04-12 pjp return (-1);
489 2540a41a 2014-04-12 pjp }
490 2540a41a 2014-04-12 pjp
491 2540a41a 2014-04-12 pjp free ($1);
492 2540a41a 2014-04-12 pjp free ($3);
493 2540a41a 2014-04-12 pjp free ($9);
494 2540a41a 2014-04-12 pjp }
495 2540a41a 2014-04-12 pjp |
496 2540a41a 2014-04-12 pjp STRING COMMA STRING COMMA NUMBER COMMA QUOTEDSTRING CRLF
497 2540a41a 2014-04-12 pjp {
498 2540a41a 2014-04-12 pjp if (strcasecmp($3, "txt") == 0) {
499 2540a41a 2014-04-12 pjp if (fill_txt($1, $3, $5, $7) < 0) {
500 2540a41a 2014-04-12 pjp return -1;
501 2540a41a 2014-04-12 pjp }
502 2540a41a 2014-04-12 pjp
503 6a6113d4 2014-04-13 pjp if (debug)
504 6a6113d4 2014-04-13 pjp printf(" %s TXT -> %s\n", $1, $7);
505 f5989689 2014-04-21 pjp } else if (strcasecmp($3, "spf") == 0) {
506 f5989689 2014-04-21 pjp if (fill_spf($1, $3, $5, $7) < 0) {
507 f5989689 2014-04-21 pjp return -1;
508 f5989689 2014-04-21 pjp }
509 f5989689 2014-04-21 pjp
510 f5989689 2014-04-21 pjp if (debug)
511 f5989689 2014-04-21 pjp printf(" %s SPF -> %s\n", $1, $7);
512 2540a41a 2014-04-12 pjp } else {
513 6a6113d4 2014-04-13 pjp if (debug)
514 f5989689 2014-04-21 pjp printf("another txt/spf like record I don't know?\n");
515 2540a41a 2014-04-12 pjp return (-1);
516 2540a41a 2014-04-12 pjp }
517 2540a41a 2014-04-12 pjp
518 2540a41a 2014-04-12 pjp free ($1);
519 2540a41a 2014-04-12 pjp free ($3);
520 2540a41a 2014-04-12 pjp free ($7);
521 1f1faf13 2014-05-11 pjp }
522 1f1faf13 2014-05-11 pjp |
523 1f1faf13 2014-05-11 pjp STRING COMMA STRING COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA QUOTEDSTRING COMMA QUOTEDSTRING COMMA QUOTEDSTRING COMMA STRING CRLF
524 1f1faf13 2014-05-11 pjp {
525 1f1faf13 2014-05-11 pjp if (strcasecmp($3, "naptr") == 0) {
526 1f1faf13 2014-05-11 pjp if (fill_naptr($1, $3, $5, $7, $9, $11, $13, $15, $17) < 0) {
527 1f1faf13 2014-05-11 pjp return -1;
528 1f1faf13 2014-05-11 pjp }
529 1f1faf13 2014-05-11 pjp
530 1f1faf13 2014-05-11 pjp if (debug)
531 1f1faf13 2014-05-11 pjp printf(" %s NAPTR\n", $1);
532 1f1faf13 2014-05-11 pjp } else {
533 1f1faf13 2014-05-11 pjp if (debug)
534 1f1faf13 2014-05-11 pjp printf("another naptr like record I don't know?\n");
535 1f1faf13 2014-05-11 pjp return (-1);
536 1f1faf13 2014-05-11 pjp }
537 1f1faf13 2014-05-11 pjp
538 1f1faf13 2014-05-11 pjp free ($1);
539 1f1faf13 2014-05-11 pjp free ($3);
540 1f1faf13 2014-05-11 pjp free ($11);
541 1f1faf13 2014-05-11 pjp free ($13);
542 1f1faf13 2014-05-11 pjp free ($15);
543 1f1faf13 2014-05-11 pjp free ($17);
544 2540a41a 2014-04-12 pjp }
545 2540a41a 2014-04-12 pjp | comment CRLF
546 2540a41a 2014-04-12 pjp ;
547 0f80aa4d 2014-04-15 pjp
548 0f80aa4d 2014-04-15 pjp
549 0f80aa4d 2014-04-15 pjp options:
550 0f80aa4d 2014-04-15 pjp OPTIONS optionslabel optionscontent
551 0f80aa4d 2014-04-15 pjp {
552 0f80aa4d 2014-04-15 pjp if ((confstatus & CONFIG_VERSION) != CONFIG_VERSION) {
553 0f80aa4d 2014-04-15 pjp dolog(LOG_INFO, "There must be a version at the top of the first configfile\n");
554 0f80aa4d 2014-04-15 pjp return (-1);
555 0f80aa4d 2014-04-15 pjp }
556 0f80aa4d 2014-04-15 pjp }
557 0f80aa4d 2014-04-15 pjp ;
558 0f80aa4d 2014-04-15 pjp
559 0f80aa4d 2014-04-15 pjp optionslabel:
560 0f80aa4d 2014-04-15 pjp QUOTEDSTRING
561 0f80aa4d 2014-04-15 pjp ;
562 0f80aa4d 2014-04-15 pjp
563 0f80aa4d 2014-04-15 pjp optionscontent:
564 0f80aa4d 2014-04-15 pjp OBRACE optionsstatements EBRACE CRLF
565 0f80aa4d 2014-04-15 pjp | OBRACE CRLF optionsstatements EBRACE CRLF
566 0f80aa4d 2014-04-15 pjp ;
567 0f80aa4d 2014-04-15 pjp
568 0f80aa4d 2014-04-15 pjp optionsstatements:
569 44be7f81 2014-04-16 pjp optionsstatement
570 44be7f81 2014-04-16 pjp | optionsstatements optionsstatement
571 0f80aa4d 2014-04-15 pjp ;
572 0f80aa4d 2014-04-15 pjp
573 0f80aa4d 2014-04-15 pjp optionsstatement:
574 0f80aa4d 2014-04-15 pjp
575 44be7f81 2014-04-16 pjp STRING SEMICOLON CRLF
576 0f80aa4d 2014-04-15 pjp {
577 0f80aa4d 2014-04-15 pjp if (strcasecmp($1, "recurse") == 0) {
578 0f80aa4d 2014-04-15 pjp dolog(LOG_DEBUG, "recursive server on\n");
579 0f80aa4d 2014-04-15 pjp rflag = 0; /* keep it off please! */
580 0f80aa4d 2014-04-15 pjp } else if (strcasecmp($1, "log") == 0) {
581 0f80aa4d 2014-04-15 pjp dolog(LOG_DEBUG, "logging on\n");
582 0f80aa4d 2014-04-15 pjp lflag = 1;
583 0f80aa4d 2014-04-15 pjp }
584 0f80aa4d 2014-04-15 pjp }
585 0f80aa4d 2014-04-15 pjp |
586 44be7f81 2014-04-16 pjp STRING QUOTEDSTRING SEMICOLON CRLF
587 0f80aa4d 2014-04-15 pjp {
588 0f80aa4d 2014-04-15 pjp if (strcasecmp($1, "interface") == 0) {
589 0f80aa4d 2014-04-15 pjp iflag = 1;
590 0f80aa4d 2014-04-15 pjp if (icount > 253) {
591 0f80aa4d 2014-04-15 pjp dolog(LOG_ERR, "too many interface keywords in options\n");
592 0f80aa4d 2014-04-15 pjp return (-1);
593 0f80aa4d 2014-04-15 pjp }
594 2540a41a 2014-04-12 pjp
595 0f80aa4d 2014-04-15 pjp dolog(LOG_DEBUG, "interface \"%s\" added\n", $2);
596 0f80aa4d 2014-04-15 pjp interface_list[icount++] = $2;
597 0f80aa4d 2014-04-15 pjp }
598 0f80aa4d 2014-04-15 pjp
599 0f80aa4d 2014-04-15 pjp }
600 0f80aa4d 2014-04-15 pjp |
601 44be7f81 2014-04-16 pjp STRING NUMBER SEMICOLON CRLF
602 0f80aa4d 2014-04-15 pjp {
603 0f80aa4d 2014-04-15 pjp if (strcasecmp($1, "fork") == 0) {
604 0f80aa4d 2014-04-15 pjp dolog(LOG_DEBUG, "forking %d times\n", $2);
605 0f80aa4d 2014-04-15 pjp nflag = $2;
606 0f80aa4d 2014-04-15 pjp } else if (strcasecmp($1, "port") == 0) {
607 0f80aa4d 2014-04-15 pjp port = $2 & 0xffff;
608 0f80aa4d 2014-04-15 pjp dolog(LOG_DEBUG, "listening on port %d\n", port);
609 4667e76d 2014-05-05 pjp } else if (strcasecmp($1, "ratelimit-pps") == 0) {
610 4667e76d 2014-05-05 pjp if ($2 > 127 || $2 < 1) {
611 4667e76d 2014-05-05 pjp dolog(LOG_ERR, "ratelimit packets per second must be between 1 and 127, or leave it off!\n");
612 4667e76d 2014-05-05 pjp return -1;
613 4667e76d 2014-05-05 pjp }
614 4667e76d 2014-05-05 pjp ratelimit = 1;
615 4667e76d 2014-05-05 pjp ratelimit_packets_per_second = $2;
616 4667e76d 2014-05-05 pjp dolog(LOG_DEBUG, "ratelimiting to %d packets per second", ratelimit_packets_per_second);
617 0f80aa4d 2014-04-15 pjp }
618 0f80aa4d 2014-04-15 pjp
619 0f80aa4d 2014-04-15 pjp }
620 0f80aa4d 2014-04-15 pjp |
621 44be7f81 2014-04-16 pjp STRING ipcidr SEMICOLON CRLF
622 0f80aa4d 2014-04-15 pjp {
623 0f80aa4d 2014-04-15 pjp if (strcasecmp($1, "bind") == 0) {
624 0f80aa4d 2014-04-15 pjp bflag = 1;
625 0f80aa4d 2014-04-15 pjp if (bcount > 253) {
626 0f80aa4d 2014-04-15 pjp dolog(LOG_ERR, "too many bind keywords in options\n");
627 0f80aa4d 2014-04-15 pjp return (-1);
628 0f80aa4d 2014-04-15 pjp }
629 0f80aa4d 2014-04-15 pjp dolog(LOG_DEBUG, "binding to %s\n", $2);
630 0f80aa4d 2014-04-15 pjp bind_list[bcount++] = $2;
631 0f80aa4d 2014-04-15 pjp }
632 0f80aa4d 2014-04-15 pjp
633 0f80aa4d 2014-04-15 pjp }
634 44be7f81 2014-04-16 pjp | comment CRLF
635 0f80aa4d 2014-04-15 pjp ;
636 0f80aa4d 2014-04-15 pjp
637 0f80aa4d 2014-04-15 pjp /* logging below */
638 0f80aa4d 2014-04-15 pjp
639 2540a41a 2014-04-12 pjp logging:
640 2540a41a 2014-04-12 pjp LOGGING logginglabel loggingcontent
641 2540a41a 2014-04-12 pjp {
642 2540a41a 2014-04-12 pjp if ((confstatus & CONFIG_VERSION) != CONFIG_VERSION) {
643 2540a41a 2014-04-12 pjp dolog(LOG_INFO, "There must be a version at the top of the first configfile\n");
644 2540a41a 2014-04-12 pjp return (-1);
645 2540a41a 2014-04-12 pjp }
646 2540a41a 2014-04-12 pjp }
647 2540a41a 2014-04-12 pjp ;
648 2540a41a 2014-04-12 pjp
649 2540a41a 2014-04-12 pjp logginglabel:
650 2540a41a 2014-04-12 pjp QUOTEDSTRING
651 2540a41a 2014-04-12 pjp ;
652 2540a41a 2014-04-12 pjp
653 2540a41a 2014-04-12 pjp loggingcontent:
654 2540a41a 2014-04-12 pjp OBRACE loggingstatements EBRACE CRLF
655 2540a41a 2014-04-12 pjp | OBRACE CRLF loggingstatements EBRACE CRLF
656 2540a41a 2014-04-12 pjp ;
657 2540a41a 2014-04-12 pjp
658 2540a41a 2014-04-12 pjp loggingstatements:
659 2540a41a 2014-04-12 pjp loggingstatement CRLF
660 2540a41a 2014-04-12 pjp | loggingstatements loggingstatement CRLF
661 2540a41a 2014-04-12 pjp ;
662 2540a41a 2014-04-12 pjp
663 2540a41a 2014-04-12 pjp loggingstatement:
664 2540a41a 2014-04-12 pjp STRING STRING SEMICOLON
665 2540a41a 2014-04-12 pjp {
666 2540a41a 2014-04-12 pjp char buf[512];
667 2540a41a 2014-04-12 pjp
668 2540a41a 2014-04-12 pjp if (strcasecmp($1, "logbind") == 0) {
669 2540a41a 2014-04-12 pjp logging.active = 1;
670 2540a41a 2014-04-12 pjp logging.bind = 0;
671 2540a41a 2014-04-12 pjp
672 2540a41a 2014-04-12 pjp gethostname(buf, sizeof(buf));
673 2540a41a 2014-04-12 pjp logging.hostname = strdup(buf);
674 2540a41a 2014-04-12 pjp if (logging.hostname == NULL) {
675 2540a41a 2014-04-12 pjp dolog(LOG_ERR, "strdup failed\n");
676 2540a41a 2014-04-12 pjp return (-1);
677 2540a41a 2014-04-12 pjp }
678 2540a41a 2014-04-12 pjp
679 2540a41a 2014-04-12 pjp if (strcmp($2, "yes") == 0) {
680 2540a41a 2014-04-12 pjp logging.bind = 1;
681 2540a41a 2014-04-12 pjp }
682 2540a41a 2014-04-12 pjp } else if (strcasecmp($1, "logpasswd") == 0) {
683 2540a41a 2014-04-12 pjp
684 2540a41a 2014-04-12 pjp logging.logpasswd = strdup($2);
685 2540a41a 2014-04-12 pjp
686 2540a41a 2014-04-12 pjp if (logging.logpasswd == NULL) {
687 2540a41a 2014-04-12 pjp dolog(LOG_ERR, "strdup failed\n");
688 2540a41a 2014-04-12 pjp return (-1);
689 2540a41a 2014-04-12 pjp }
690 2540a41a 2014-04-12 pjp
691 2540a41a 2014-04-12 pjp } else {
692 f22153d0 2014-04-13 pjp if (debug)
693 f22153d0 2014-04-13 pjp printf("another logging statement I don't know?\n");
694 2540a41a 2014-04-12 pjp return (-1);
695 2540a41a 2014-04-12 pjp }
696 2540a41a 2014-04-12 pjp
697 2540a41a 2014-04-12 pjp }
698 2540a41a 2014-04-12 pjp |
699 2540a41a 2014-04-12 pjp STRING NUMBER SEMICOLON
700 2540a41a 2014-04-12 pjp {
701 2540a41a 2014-04-12 pjp char buf[16];
702 2540a41a 2014-04-12 pjp
703 2540a41a 2014-04-12 pjp if (strcasecmp($1, "logport") == 0) {
704 2540a41a 2014-04-12 pjp snprintf(buf, sizeof(buf), "%d", $2);
705 2540a41a 2014-04-12 pjp logging.logport = strdup(buf);
706 2540a41a 2014-04-12 pjp if (logging.logport == NULL) {
707 2540a41a 2014-04-12 pjp dolog(LOG_ERR, "strdup failed\n");
708 2540a41a 2014-04-12 pjp return (-1);
709 2540a41a 2014-04-12 pjp }
710 2540a41a 2014-04-12 pjp logging.logport2 = $2;
711 2540a41a 2014-04-12 pjp }
712 2540a41a 2014-04-12 pjp }
713 2540a41a 2014-04-12 pjp |
714 2540a41a 2014-04-12 pjp STRING ipcidr SEMICOLON
715 2540a41a 2014-04-12 pjp {
716 2540a41a 2014-04-12 pjp struct addrinfo hints, *res0;
717 2540a41a 2014-04-12 pjp struct sockaddr_in6 *psin6;
718 2540a41a 2014-04-12 pjp struct sockaddr_in *psin;
719 2540a41a 2014-04-12 pjp int error;
720 2540a41a 2014-04-12 pjp
721 2540a41a 2014-04-12 pjp if (strcasecmp($1, "loghost") == 0) {
722 2540a41a 2014-04-12 pjp logging.loghost = strdup($2);
723 2540a41a 2014-04-12 pjp if (logging.loghost == NULL) {
724 2540a41a 2014-04-12 pjp dolog(LOG_ERR, "strdup failed\n");
725 2540a41a 2014-04-12 pjp
726 2540a41a 2014-04-12 pjp return (-1);
727 2540a41a 2014-04-12 pjp }
728 2540a41a 2014-04-12 pjp
729 2540a41a 2014-04-12 pjp if (strchr($2, ':') != NULL) {
730 2540a41a 2014-04-12 pjp memset(&hints, 0, sizeof(hints));
731 2540a41a 2014-04-12 pjp hints.ai_family = AF_INET6;
732 2540a41a 2014-04-12 pjp hints.ai_socktype = SOCK_STREAM;
733 2540a41a 2014-04-12 pjp hints.ai_flags = AI_NUMERICHOST;
734 2540a41a 2014-04-12 pjp
735 2540a41a 2014-04-12 pjp error = getaddrinfo($2, "www", &hints, &res0);
736 2540a41a 2014-04-12 pjp if (error) {
737 2540a41a 2014-04-12 pjp dolog(LOG_ERR, "%s line %d: %s\n",
738 2540a41a 2014-04-12 pjp file->name, file->lineno,
739 2540a41a 2014-04-12 pjp gai_strerror(error));
740 2540a41a 2014-04-12 pjp
741 2540a41a 2014-04-12 pjp return (-1);
742 2540a41a 2014-04-12 pjp }
743 2540a41a 2014-04-12 pjp
744 2540a41a 2014-04-12 pjp if (res0 == NULL) {
745 2540a41a 2014-04-12 pjp dolog(LOG_ERR, "%s line %d: could not"
746 2540a41a 2014-04-12 pjp " determine IPv6 address\n"
747 2540a41a 2014-04-12 pjp , file->name, file->lineno);
748 2540a41a 2014-04-12 pjp return (-1);
749 2540a41a 2014-04-12 pjp }
750 2540a41a 2014-04-12 pjp
751 2540a41a 2014-04-12 pjp psin6 = (struct sockaddr_in6 *)&logging.loghost2;
752 2540a41a 2014-04-12 pjp psin6->sin6_family = res0->ai_family;
753 2540a41a 2014-04-12 pjp memcpy(psin6, res0->ai_addr, res0->ai_addrlen);
754 2540a41a 2014-04-12 pjp freeaddrinfo(res0);
755 2540a41a 2014-04-12 pjp } else {
756 2540a41a 2014-04-12 pjp memset(&hints, 0, sizeof(hints));
757 2540a41a 2014-04-12 pjp
758 2540a41a 2014-04-12 pjp hints.ai_family = AF_INET;
759 2540a41a 2014-04-12 pjp hints.ai_socktype = SOCK_STREAM;
760 2540a41a 2014-04-12 pjp hints.ai_flags = AI_NUMERICHOST;
761 2540a41a 2014-04-12 pjp
762 2540a41a 2014-04-12 pjp error = getaddrinfo($2, "www", &hints, &res0);
763 2540a41a 2014-04-12 pjp if (error) {
764 2540a41a 2014-04-12 pjp dolog(LOG_ERR, "%s line %d: %s\n",
765 2540a41a 2014-04-12 pjp file->name, file->lineno,
766 2540a41a 2014-04-12 pjp gai_strerror(error));
767 2540a41a 2014-04-12 pjp
768 2540a41a 2014-04-12 pjp return (-1);
769 2540a41a 2014-04-12 pjp }
770 2540a41a 2014-04-12 pjp
771 2540a41a 2014-04-12 pjp if (res0 == NULL) {
772 2540a41a 2014-04-12 pjp dolog(LOG_ERR, "%s line %d: could not"
773 2540a41a 2014-04-12 pjp " determine IPv6 address\n"
774 2540a41a 2014-04-12 pjp , file->name, file->lineno);
775 2540a41a 2014-04-12 pjp return (-1);
776 2540a41a 2014-04-12 pjp }
777 2540a41a 2014-04-12 pjp
778 2540a41a 2014-04-12 pjp psin = (struct sockaddr_in *)&logging.loghost2;
779 2540a41a 2014-04-12 pjp psin->sin_family = res0->ai_family;
780 2540a41a 2014-04-12 pjp memcpy(psin, res0->ai_addr, res0->ai_addrlen);
781 2540a41a 2014-04-12 pjp
782 2540a41a 2014-04-12 pjp freeaddrinfo(res0);
783 2540a41a 2014-04-12 pjp }
784 2540a41a 2014-04-12 pjp } else {
785 f22153d0 2014-04-13 pjp if (debug)
786 f22153d0 2014-04-13 pjp printf("2 another logging statement I don't know?\n");
787 2540a41a 2014-04-12 pjp return (-1);
788 2540a41a 2014-04-12 pjp }
789 2540a41a 2014-04-12 pjp }
790 2540a41a 2014-04-12 pjp | comment CRLF
791 2540a41a 2014-04-12 pjp ;
792 6f8d6a57 2014-05-18 pjp
793 6f8d6a57 2014-05-18 pjp /* whitelist "these hosts" { .. } */
794 c0963faf 2014-05-01 pjp
795 6f8d6a57 2014-05-18 pjp whitelist:
796 6f8d6a57 2014-05-18 pjp WHITELIST whitelistlabel whitelistcontent
797 6f8d6a57 2014-05-18 pjp {
798 6f8d6a57 2014-05-18 pjp if ((confstatus & CONFIG_VERSION) != CONFIG_VERSION) {
799 6f8d6a57 2014-05-18 pjp dolog(LOG_INFO, "There must be a version at the top of the first configfile\n");
800 6f8d6a57 2014-05-18 pjp return (-1);
801 6f8d6a57 2014-05-18 pjp }
802 6f8d6a57 2014-05-18 pjp }
803 6f8d6a57 2014-05-18 pjp ;
804 6f8d6a57 2014-05-18 pjp
805 6f8d6a57 2014-05-18 pjp whitelistlabel:
806 6f8d6a57 2014-05-18 pjp QUOTEDSTRING
807 6f8d6a57 2014-05-18 pjp ;
808 6f8d6a57 2014-05-18 pjp
809 6f8d6a57 2014-05-18 pjp whitelistcontent:
810 6f8d6a57 2014-05-18 pjp OBRACE whiteliststatements EBRACE
811 6f8d6a57 2014-05-18 pjp | OBRACE CRLF whiteliststatements EBRACE
812 6f8d6a57 2014-05-18 pjp ;
813 6f8d6a57 2014-05-18 pjp
814 6f8d6a57 2014-05-18 pjp whiteliststatements :
815 6f8d6a57 2014-05-18 pjp whiteliststatements whiteliststatement
816 6f8d6a57 2014-05-18 pjp | whiteliststatement
817 6f8d6a57 2014-05-18 pjp ;
818 6f8d6a57 2014-05-18 pjp
819 6f8d6a57 2014-05-18 pjp whiteliststatement : ipcidr SEMICOLON CRLF
820 6f8d6a57 2014-05-18 pjp {
821 6f8d6a57 2014-05-18 pjp char prefixlength[INET_ADDRSTRLEN];
822 6f8d6a57 2014-05-18 pjp char *dst;
823 6f8d6a57 2014-05-18 pjp
824 6f8d6a57 2014-05-18 pjp
825 6f8d6a57 2014-05-18 pjp if ((dst = get_prefixlen($1, (char *)&prefixlength, sizeof(prefixlength))) == NULL) {
826 6f8d6a57 2014-05-18 pjp return (-1);
827 6f8d6a57 2014-05-18 pjp }
828 6f8d6a57 2014-05-18 pjp
829 6f8d6a57 2014-05-18 pjp if (insert_whitelist(dst, prefixlength) < 0) {
830 6f8d6a57 2014-05-18 pjp dolog(LOG_ERR, "insert_whitelist, line %d\n", file->lineno);
831 6f8d6a57 2014-05-18 pjp return (-1);
832 6f8d6a57 2014-05-18 pjp }
833 6f8d6a57 2014-05-18 pjp
834 6f8d6a57 2014-05-18 pjp if (debug)
835 6f8d6a57 2014-05-18 pjp printf("recurse inserted %s address\n", $1);
836 6f8d6a57 2014-05-18 pjp
837 6f8d6a57 2014-05-18 pjp whitelist = 1;
838 6f8d6a57 2014-05-18 pjp
839 6f8d6a57 2014-05-18 pjp free (dst);
840 6f8d6a57 2014-05-18 pjp free ($1);
841 6f8d6a57 2014-05-18 pjp }
842 6f8d6a57 2014-05-18 pjp | comment CRLF
843 6f8d6a57 2014-05-18 pjp ;
844 6f8d6a57 2014-05-18 pjp
845 c0963faf 2014-05-01 pjp /* filter "these hosts" { .. } */
846 c0963faf 2014-05-01 pjp
847 c0963faf 2014-05-01 pjp filter:
848 c0963faf 2014-05-01 pjp FILTER filterlabel filtercontent
849 c0963faf 2014-05-01 pjp {
850 c0963faf 2014-05-01 pjp if ((confstatus & CONFIG_VERSION) != CONFIG_VERSION) {
851 c0963faf 2014-05-01 pjp dolog(LOG_INFO, "There must be a version at the top of the first configfile\n");
852 c0963faf 2014-05-01 pjp return (-1);
853 c0963faf 2014-05-01 pjp }
854 c0963faf 2014-05-01 pjp }
855 c0963faf 2014-05-01 pjp ;
856 c0963faf 2014-05-01 pjp
857 c0963faf 2014-05-01 pjp filterlabel:
858 c0963faf 2014-05-01 pjp QUOTEDSTRING
859 c0963faf 2014-05-01 pjp ;
860 c0963faf 2014-05-01 pjp
861 c0963faf 2014-05-01 pjp filtercontent:
862 c0963faf 2014-05-01 pjp OBRACE filterstatements EBRACE
863 c0963faf 2014-05-01 pjp | OBRACE CRLF filterstatements EBRACE
864 c0963faf 2014-05-01 pjp ;
865 c0963faf 2014-05-01 pjp
866 c0963faf 2014-05-01 pjp filterstatements :
867 c0963faf 2014-05-01 pjp filterstatements filterstatement
868 c0963faf 2014-05-01 pjp | filterstatement
869 c0963faf 2014-05-01 pjp ;
870 c0963faf 2014-05-01 pjp
871 c0963faf 2014-05-01 pjp filterstatement : ipcidr SEMICOLON CRLF
872 c0963faf 2014-05-01 pjp {
873 c0963faf 2014-05-01 pjp char prefixlength[INET_ADDRSTRLEN];
874 c0963faf 2014-05-01 pjp char *dst;
875 c0963faf 2014-05-01 pjp
876 c0963faf 2014-05-01 pjp
877 c0963faf 2014-05-01 pjp if ((dst = get_prefixlen($1, (char *)&prefixlength, sizeof(prefixlength))) == NULL) {
878 c0963faf 2014-05-01 pjp return (-1);
879 c0963faf 2014-05-01 pjp }
880 c0963faf 2014-05-01 pjp
881 c0963faf 2014-05-01 pjp if (insert_filter(dst, prefixlength) < 0) {
882 c0963faf 2014-05-01 pjp dolog(LOG_ERR, "insert_filter, line %d\n", file->lineno);
883 c0963faf 2014-05-01 pjp return (-1);
884 c0963faf 2014-05-01 pjp }
885 c0963faf 2014-05-01 pjp
886 c0963faf 2014-05-01 pjp if (debug)
887 c0963faf 2014-05-01 pjp printf("recurse inserted %s address\n", $1);
888 2540a41a 2014-04-12 pjp
889 c0963faf 2014-05-01 pjp free (dst);
890 c0963faf 2014-05-01 pjp free ($1);
891 c0963faf 2014-05-01 pjp }
892 c0963faf 2014-05-01 pjp | comment CRLF
893 c0963faf 2014-05-01 pjp ;
894 58eafea4 2014-05-17 pjp
895 58eafea4 2014-05-17 pjp
896 58eafea4 2014-05-17 pjp /* notify "these hosts" { .. } */
897 58eafea4 2014-05-17 pjp
898 58eafea4 2014-05-17 pjp notify:
899 58eafea4 2014-05-17 pjp NOTIFY notifylabel notifycontent
900 58eafea4 2014-05-17 pjp {
901 58eafea4 2014-05-17 pjp if ((confstatus & CONFIG_VERSION) != CONFIG_VERSION) {
902 58eafea4 2014-05-17 pjp dolog(LOG_INFO, "There must be a version at the top of the first configfile\n");
903 58eafea4 2014-05-17 pjp return (-1);
904 58eafea4 2014-05-17 pjp }
905 58eafea4 2014-05-17 pjp }
906 58eafea4 2014-05-17 pjp ;
907 58eafea4 2014-05-17 pjp
908 58eafea4 2014-05-17 pjp notifylabel:
909 58eafea4 2014-05-17 pjp QUOTEDSTRING
910 58eafea4 2014-05-17 pjp ;
911 58eafea4 2014-05-17 pjp
912 58eafea4 2014-05-17 pjp notifycontent:
913 58eafea4 2014-05-17 pjp OBRACE notifystatements EBRACE
914 58eafea4 2014-05-17 pjp | OBRACE CRLF notifystatements EBRACE
915 58eafea4 2014-05-17 pjp ;
916 58eafea4 2014-05-17 pjp
917 58eafea4 2014-05-17 pjp notifystatements :
918 58eafea4 2014-05-17 pjp notifystatements notifystatement
919 58eafea4 2014-05-17 pjp | notifystatement
920 58eafea4 2014-05-17 pjp ;
921 58eafea4 2014-05-17 pjp
922 58eafea4 2014-05-17 pjp notifystatement : ipcidr SEMICOLON CRLF
923 58eafea4 2014-05-17 pjp {
924 58eafea4 2014-05-17 pjp char prefixlength[INET_ADDRSTRLEN];
925 58eafea4 2014-05-17 pjp char *dst;
926 58eafea4 2014-05-17 pjp
927 c0963faf 2014-05-01 pjp
928 58eafea4 2014-05-17 pjp if ((dst = get_prefixlen($1, (char *)&prefixlength, sizeof(prefixlength))) == NULL) {
929 58eafea4 2014-05-17 pjp return (-1);
930 58eafea4 2014-05-17 pjp }
931 c0963faf 2014-05-01 pjp
932 58eafea4 2014-05-17 pjp if (insert_notifyslave(dst, prefixlength) < 0) {
933 58eafea4 2014-05-17 pjp dolog(LOG_ERR, "insert_notifyslave, line %d\n", file->lineno);
934 58eafea4 2014-05-17 pjp return (-1);
935 58eafea4 2014-05-17 pjp }
936 58eafea4 2014-05-17 pjp
937 58eafea4 2014-05-17 pjp notify++;
938 58eafea4 2014-05-17 pjp
939 58eafea4 2014-05-17 pjp free (dst);
940 58eafea4 2014-05-17 pjp free ($1);
941 58eafea4 2014-05-17 pjp }
942 58eafea4 2014-05-17 pjp | comment CRLF
943 58eafea4 2014-05-17 pjp ;
944 58eafea4 2014-05-17 pjp
945 2540a41a 2014-04-12 pjp /* axfr-for "these hosts" { .. } */
946 2540a41a 2014-04-12 pjp
947 2540a41a 2014-04-12 pjp axfr:
948 2540a41a 2014-04-12 pjp AXFRFOR axfrlabel axfrcontent
949 2540a41a 2014-04-12 pjp {
950 2540a41a 2014-04-12 pjp if ((confstatus & CONFIG_VERSION) != CONFIG_VERSION) {
951 2540a41a 2014-04-12 pjp dolog(LOG_INFO, "There must be a version at the top of the first configfile\n");
952 2540a41a 2014-04-12 pjp return (-1);
953 2540a41a 2014-04-12 pjp }
954 2540a41a 2014-04-12 pjp }
955 2540a41a 2014-04-12 pjp ;
956 2540a41a 2014-04-12 pjp
957 2540a41a 2014-04-12 pjp axfrlabel:
958 2540a41a 2014-04-12 pjp QUOTEDSTRING
959 2540a41a 2014-04-12 pjp ;
960 2540a41a 2014-04-12 pjp
961 2540a41a 2014-04-12 pjp axfrcontent:
962 2540a41a 2014-04-12 pjp OBRACE axfrstatements EBRACE
963 2540a41a 2014-04-12 pjp | OBRACE CRLF axfrstatements EBRACE
964 2540a41a 2014-04-12 pjp ;
965 2540a41a 2014-04-12 pjp
966 2540a41a 2014-04-12 pjp axfrstatements :
967 2540a41a 2014-04-12 pjp axfrstatements axfrstatement
968 2540a41a 2014-04-12 pjp | axfrstatement
969 2540a41a 2014-04-12 pjp ;
970 2540a41a 2014-04-12 pjp
971 2540a41a 2014-04-12 pjp axfrstatement : ipcidr SEMICOLON CRLF
972 2540a41a 2014-04-12 pjp {
973 2540a41a 2014-04-12 pjp char prefixlength[INET_ADDRSTRLEN];
974 2540a41a 2014-04-12 pjp char *dst;
975 2540a41a 2014-04-12 pjp
976 2540a41a 2014-04-12 pjp
977 2540a41a 2014-04-12 pjp if ((dst = get_prefixlen($1, (char *)&prefixlength, sizeof(prefixlength))) == NULL) {
978 2540a41a 2014-04-12 pjp return (-1);
979 2540a41a 2014-04-12 pjp }
980 2540a41a 2014-04-12 pjp
981 2540a41a 2014-04-12 pjp if (insert_axfr(dst, prefixlength) < 0) {
982 2540a41a 2014-04-12 pjp dolog(LOG_ERR, "insert_axfr, line %d\n", file->lineno);
983 2540a41a 2014-04-12 pjp return (-1);
984 2540a41a 2014-04-12 pjp }
985 2540a41a 2014-04-12 pjp
986 6a6113d4 2014-04-13 pjp if (debug)
987 6a6113d4 2014-04-13 pjp printf("recurse inserted %s address\n", $1);
988 6a6113d4 2014-04-13 pjp
989 2540a41a 2014-04-12 pjp free (dst);
990 2540a41a 2014-04-12 pjp free ($1);
991 2540a41a 2014-04-12 pjp }
992 2540a41a 2014-04-12 pjp | comment CRLF
993 2540a41a 2014-04-12 pjp ;
994 2540a41a 2014-04-12 pjp
995 2540a41a 2014-04-12 pjp /* recurse-for "these hosts" { .. } */
996 2540a41a 2014-04-12 pjp
997 2540a41a 2014-04-12 pjp recurse:
998 2540a41a 2014-04-12 pjp RECURSEFOR recurselabel recursecontent
999 2540a41a 2014-04-12 pjp {
1000 2540a41a 2014-04-12 pjp if ((confstatus & CONFIG_VERSION) != CONFIG_VERSION) {
1001 2540a41a 2014-04-12 pjp dolog(LOG_INFO, "There must be a version at the top of the first configfile\n");
1002 2540a41a 2014-04-12 pjp return (-1);
1003 2540a41a 2014-04-12 pjp }
1004 2540a41a 2014-04-12 pjp }
1005 2540a41a 2014-04-12 pjp ;
1006 2540a41a 2014-04-12 pjp
1007 2540a41a 2014-04-12 pjp recurselabel:
1008 2540a41a 2014-04-12 pjp QUOTEDSTRING
1009 2540a41a 2014-04-12 pjp ;
1010 2540a41a 2014-04-12 pjp
1011 2540a41a 2014-04-12 pjp recursecontent:
1012 2540a41a 2014-04-12 pjp OBRACE recursestatements EBRACE
1013 2540a41a 2014-04-12 pjp | OBRACE CRLF recursestatements EBRACE
1014 2540a41a 2014-04-12 pjp ;
1015 2540a41a 2014-04-12 pjp
1016 2540a41a 2014-04-12 pjp recursestatements :
1017 2540a41a 2014-04-12 pjp recursestatements recursestatement
1018 2540a41a 2014-04-12 pjp | recursestatement
1019 2540a41a 2014-04-12 pjp ;
1020 2540a41a 2014-04-12 pjp
1021 2540a41a 2014-04-12 pjp recursestatement : ipcidr SEMICOLON CRLF
1022 2540a41a 2014-04-12 pjp {
1023 2540a41a 2014-04-12 pjp char prefixlength[INET_ADDRSTRLEN];
1024 2540a41a 2014-04-12 pjp char *dst;
1025 2540a41a 2014-04-12 pjp
1026 2540a41a 2014-04-12 pjp if ((dst = get_prefixlen($1, (char *)&prefixlength, sizeof(prefixlength))) == NULL) {
1027 2540a41a 2014-04-12 pjp return (-1);
1028 2540a41a 2014-04-12 pjp }
1029 2540a41a 2014-04-12 pjp
1030 2540a41a 2014-04-12 pjp if (insert_recurse(dst, prefixlength) < 0) {
1031 2540a41a 2014-04-12 pjp dolog(LOG_ERR, "insert_recurse, line %d\n", file->lineno);
1032 2540a41a 2014-04-12 pjp return (-1);
1033 2540a41a 2014-04-12 pjp }
1034 2540a41a 2014-04-12 pjp
1035 6a6113d4 2014-04-13 pjp if (debug)
1036 6a6113d4 2014-04-13 pjp printf("recurse inserted %s address\n", $1);
1037 2540a41a 2014-04-12 pjp
1038 2540a41a 2014-04-12 pjp free (dst);
1039 2540a41a 2014-04-12 pjp free ($1);
1040 2540a41a 2014-04-12 pjp }
1041 2540a41a 2014-04-12 pjp | comment CRLF
1042 2540a41a 2014-04-12 pjp ;
1043 2540a41a 2014-04-12 pjp
1044 2540a41a 2014-04-12 pjp
1045 2540a41a 2014-04-12 pjp /* wildcard-only-for "these hosts" { .. } */
1046 2540a41a 2014-04-12 pjp
1047 2540a41a 2014-04-12 pjp wof:
1048 2540a41a 2014-04-12 pjp WOF woflabel wofcontent
1049 2540a41a 2014-04-12 pjp {
1050 2540a41a 2014-04-12 pjp if ((confstatus & CONFIG_VERSION) != CONFIG_VERSION) {
1051 2540a41a 2014-04-12 pjp dolog(LOG_INFO, "There must be a version at the top of the first configfile\n");
1052 2540a41a 2014-04-12 pjp return (-1);
1053 2540a41a 2014-04-12 pjp }
1054 2540a41a 2014-04-12 pjp }
1055 2540a41a 2014-04-12 pjp ;
1056 2540a41a 2014-04-12 pjp
1057 2540a41a 2014-04-12 pjp woflabel:
1058 2540a41a 2014-04-12 pjp QUOTEDSTRING
1059 2540a41a 2014-04-12 pjp ;
1060 2540a41a 2014-04-12 pjp
1061 2540a41a 2014-04-12 pjp wofcontent:
1062 2540a41a 2014-04-12 pjp OBRACE wofstatements EBRACE
1063 2540a41a 2014-04-12 pjp | OBRACE CRLF wofstatements EBRACE
1064 2540a41a 2014-04-12 pjp ;
1065 2540a41a 2014-04-12 pjp
1066 2540a41a 2014-04-12 pjp wofstatements :
1067 2540a41a 2014-04-12 pjp wofstatements wofstatement
1068 2540a41a 2014-04-12 pjp | wofstatement
1069 2540a41a 2014-04-12 pjp ;
1070 2540a41a 2014-04-12 pjp
1071 2540a41a 2014-04-12 pjp wofstatement : ipcidr SEMICOLON CRLF
1072 2540a41a 2014-04-12 pjp {
1073 2540a41a 2014-04-12 pjp char prefixlength[INET_ADDRSTRLEN];
1074 2540a41a 2014-04-12 pjp char *dst;
1075 2540a41a 2014-04-12 pjp
1076 2540a41a 2014-04-12 pjp if ((dst = get_prefixlen($1, (char *)&prefixlength, sizeof(prefixlength))) == NULL) {
1077 2540a41a 2014-04-12 pjp
1078 2540a41a 2014-04-12 pjp return (-1);
1079 2540a41a 2014-04-12 pjp }
1080 2540a41a 2014-04-12 pjp
1081 2540a41a 2014-04-12 pjp if (insert_wildcard(dst, prefixlength) < 0) {
1082 2540a41a 2014-04-12 pjp dolog(LOG_ERR, "insert_wildcard, line %d\n", file->lineno);
1083 2540a41a 2014-04-12 pjp return (-1);
1084 2540a41a 2014-04-12 pjp }
1085 2540a41a 2014-04-12 pjp
1086 6a6113d4 2014-04-13 pjp if (debug)
1087 6a6113d4 2014-04-13 pjp printf("wildcard inserted %s address\n", $1);
1088 2540a41a 2014-04-12 pjp
1089 2540a41a 2014-04-12 pjp free (dst);
1090 2540a41a 2014-04-12 pjp free ($1);
1091 2540a41a 2014-04-12 pjp }
1092 2540a41a 2014-04-12 pjp | comment CRLF
1093 2540a41a 2014-04-12 pjp ;
1094 2540a41a 2014-04-12 pjp
1095 2540a41a 2014-04-12 pjp
1096 2540a41a 2014-04-12 pjp /* region "lacnic" { .. } */
1097 2540a41a 2014-04-12 pjp
1098 2540a41a 2014-04-12 pjp region:
1099 2540a41a 2014-04-12 pjp REGION regionlabel regioncontent
1100 2540a41a 2014-04-12 pjp {
1101 2540a41a 2014-04-12 pjp if ((confstatus & CONFIG_VERSION) != CONFIG_VERSION) {
1102 2540a41a 2014-04-12 pjp dolog(LOG_INFO, "There must be a version at the top of the first configfile\n");
1103 2540a41a 2014-04-12 pjp return (-1);
1104 2540a41a 2014-04-12 pjp }
1105 2540a41a 2014-04-12 pjp
1106 2540a41a 2014-04-12 pjp region++;
1107 2540a41a 2014-04-12 pjp }
1108 2540a41a 2014-04-12 pjp ;
1109 2540a41a 2014-04-12 pjp
1110 2540a41a 2014-04-12 pjp regionlabel:
1111 2540a41a 2014-04-12 pjp QUOTEDSTRING
1112 2540a41a 2014-04-12 pjp ;
1113 2540a41a 2014-04-12 pjp
1114 2540a41a 2014-04-12 pjp regioncontent:
1115 2540a41a 2014-04-12 pjp OBRACE regionstatements EBRACE
1116 2540a41a 2014-04-12 pjp | OBRACE CRLF regionstatements EBRACE
1117 2540a41a 2014-04-12 pjp ;
1118 2540a41a 2014-04-12 pjp
1119 2540a41a 2014-04-12 pjp regionstatements :
1120 2540a41a 2014-04-12 pjp regionstatements regionstatement
1121 2540a41a 2014-04-12 pjp | regionstatement
1122 2540a41a 2014-04-12 pjp ;
1123 2540a41a 2014-04-12 pjp
1124 2540a41a 2014-04-12 pjp regionstatement : ipcidr SEMICOLON CRLF
1125 2540a41a 2014-04-12 pjp {
1126 2540a41a 2014-04-12 pjp char prefixlength[INET_ADDRSTRLEN];
1127 2540a41a 2014-04-12 pjp char *dst;
1128 2540a41a 2014-04-12 pjp
1129 2540a41a 2014-04-12 pjp if ((dst = get_prefixlen($1, (char *)&prefixlength, sizeof(prefixlength))) == NULL) {
1130 2540a41a 2014-04-12 pjp return (-1);
1131 2540a41a 2014-04-12 pjp }
1132 2540a41a 2014-04-12 pjp
1133 2540a41a 2014-04-12 pjp if (insert_region(dst, prefixlength, region) < 0) {
1134 2540a41a 2014-04-12 pjp dolog(LOG_ERR, "insert_region, line %d\n", file->lineno);
1135 2540a41a 2014-04-12 pjp return (-1);
1136 2540a41a 2014-04-12 pjp }
1137 6a6113d4 2014-04-13 pjp
1138 6a6113d4 2014-04-13 pjp if (debug)
1139 6a6113d4 2014-04-13 pjp printf("%s ipv4 address\n", dst);
1140 2540a41a 2014-04-12 pjp
1141 2540a41a 2014-04-12 pjp free (dst);
1142 2540a41a 2014-04-12 pjp free ($1);
1143 2540a41a 2014-04-12 pjp }
1144 2540a41a 2014-04-12 pjp | comment CRLF
1145 2540a41a 2014-04-12 pjp ;
1146 2540a41a 2014-04-12 pjp
1147 2540a41a 2014-04-12 pjp ipcidr:
1148 2540a41a 2014-04-12 pjp IP
1149 2540a41a 2014-04-12 pjp | IPV6
1150 2540a41a 2014-04-12 pjp ;
1151 2540a41a 2014-04-12 pjp
1152 2540a41a 2014-04-12 pjp
1153 2540a41a 2014-04-12 pjp %%
1154 2540a41a 2014-04-12 pjp
1155 2540a41a 2014-04-12 pjp struct tab {
1156 2540a41a 2014-04-12 pjp char *val;
1157 2540a41a 2014-04-12 pjp int num;
1158 2540a41a 2014-04-12 pjp int state;
1159 2540a41a 2014-04-12 pjp };
1160 2540a41a 2014-04-12 pjp
1161 2540a41a 2014-04-12 pjp
1162 2540a41a 2014-04-12 pjp struct tab cmdtab[] = {
1163 2540a41a 2014-04-12 pjp { "axfrport", AXFRPORT, 0},
1164 2540a41a 2014-04-12 pjp { "axfr-for", AXFRFOR, STATE_IP },
1165 6f8d6a57 2014-05-18 pjp { "whitelist", WHITELIST, STATE_IP },
1166 c0963faf 2014-05-01 pjp { "filter", FILTER, STATE_IP },
1167 0f80aa4d 2014-04-15 pjp { "include", INCLUDE, 0 },
1168 0f80aa4d 2014-04-15 pjp { "logging", LOGGING, 0 },
1169 0f80aa4d 2014-04-15 pjp { "options", OPTIONS, 0 },
1170 2540a41a 2014-04-12 pjp { "recurse-for", RECURSEFOR, STATE_IP },
1171 0f80aa4d 2014-04-15 pjp { "region", REGION, STATE_IP },
1172 2540a41a 2014-04-12 pjp { "wildcard-only-for", WOF, STATE_IP },
1173 0f80aa4d 2014-04-15 pjp { "version", VERSION, 0 },
1174 2540a41a 2014-04-12 pjp { "zone", ZONE, 0 },
1175 58eafea4 2014-05-17 pjp { "notify", NOTIFY, STATE_IP },
1176 2540a41a 2014-04-12 pjp { NULL, 0, 0}};
1177 0e7d94ac 2014-05-18 pjp
1178 0e7d94ac 2014-05-18 pjp
1179 0e7d94ac 2014-05-18 pjp
1180 0e7d94ac 2014-05-18 pjp void
1181 0e7d94ac 2014-05-18 pjp yyerror(const char *str)
1182 0e7d94ac 2014-05-18 pjp {
1183 0e7d94ac 2014-05-18 pjp dolog(LOG_ERR, "%s file: %s line: %d\n", str, file->name, file->lineno);
1184 0e7d94ac 2014-05-18 pjp slave_shutdown();
1185 0e7d94ac 2014-05-18 pjp exit (1);
1186 0e7d94ac 2014-05-18 pjp }
1187 0e7d94ac 2014-05-18 pjp
1188 0e7d94ac 2014-05-18 pjp int
1189 0e7d94ac 2014-05-18 pjp yywrap()
1190 0e7d94ac 2014-05-18 pjp {
1191 0e7d94ac 2014-05-18 pjp return 1;
1192 0e7d94ac 2014-05-18 pjp }
1193 2540a41a 2014-04-12 pjp
1194 2540a41a 2014-04-12 pjp int
1195 0e7d94ac 2014-05-18 pjp parse_file(DB *db, char *filename)
1196 0e7d94ac 2014-05-18 pjp {
1197 0e7d94ac 2014-05-18 pjp int errors;
1198 0e7d94ac 2014-05-18 pjp
1199 0e7d94ac 2014-05-18 pjp mydb = db;
1200 0e7d94ac 2014-05-18 pjp
1201 0e7d94ac 2014-05-18 pjp memset(&logging, 0, sizeof(struct logging));
1202 0e7d94ac 2014-05-18 pjp logging.active = 0;
1203 0e7d94ac 2014-05-18 pjp
1204 0e7d94ac 2014-05-18 pjp
1205 0e7d94ac 2014-05-18 pjp if ((file = pushfile(filename, 0)) == NULL) {
1206 0e7d94ac 2014-05-18 pjp return (-1);
1207 0e7d94ac 2014-05-18 pjp }
1208 0e7d94ac 2014-05-18 pjp
1209 0e7d94ac 2014-05-18 pjp topfile = file;
1210 0e7d94ac 2014-05-18 pjp
1211 0e7d94ac 2014-05-18 pjp if (yyparse() < 0) {
1212 0e7d94ac 2014-05-18 pjp dolog(LOG_ERR, "error: %s line: %d\n", file->name, file->lineno);
1213 0e7d94ac 2014-05-18 pjp return (-1);
1214 0e7d94ac 2014-05-18 pjp }
1215 0e7d94ac 2014-05-18 pjp errors = file->errors;
1216 0e7d94ac 2014-05-18 pjp popfile();
1217 0e7d94ac 2014-05-18 pjp
1218 0e7d94ac 2014-05-18 pjp dolog(LOG_INFO, "configuration file read\n");
1219 0e7d94ac 2014-05-18 pjp
1220 0e7d94ac 2014-05-18 pjp return 0;
1221 0e7d94ac 2014-05-18 pjp }
1222 0e7d94ac 2014-05-18 pjp
1223 0e7d94ac 2014-05-18 pjp int
1224 2540a41a 2014-04-12 pjp yylex()
1225 2540a41a 2014-04-12 pjp {
1226 2540a41a 2014-04-12 pjp struct tab *p;
1227 2540a41a 2014-04-12 pjp static char buf[512];
1228 2540a41a 2014-04-12 pjp static char dst[INET6_ADDRSTRLEN];
1229 2540a41a 2014-04-12 pjp char *cp = NULL;
1230 2540a41a 2014-04-12 pjp int c, cpos;
1231 2540a41a 2014-04-12 pjp static int setupstate = 0;
1232 2540a41a 2014-04-12 pjp
1233 2540a41a 2014-04-12 pjp
1234 2540a41a 2014-04-12 pjp do {
1235 2540a41a 2014-04-12 pjp c = lgetc(0);
1236 2540a41a 2014-04-12 pjp } while ((c == ' ') || (c == '\t'));
1237 2540a41a 2014-04-12 pjp
1238 2540a41a 2014-04-12 pjp if (c == EOF)
1239 2540a41a 2014-04-12 pjp return 0;
1240 2540a41a 2014-04-12 pjp
1241 2540a41a 2014-04-12 pjp if (c == '\n') {
1242 2540a41a 2014-04-12 pjp file->lineno++;
1243 2540a41a 2014-04-12 pjp
1244 2540a41a 2014-04-12 pjp while ((c = lgetc(0)) != EOF && (c == '\n' || c == '\t'))
1245 2540a41a 2014-04-12 pjp if (c == '\n')
1246 2540a41a 2014-04-12 pjp file->lineno++;
1247 2540a41a 2014-04-12 pjp lungetc(c);
1248 2540a41a 2014-04-12 pjp
1249 2540a41a 2014-04-12 pjp
1250 2540a41a 2014-04-12 pjp #ifdef LEXDEBUG
1251 6a6113d4 2014-04-13 pjp if (debug)
1252 6a6113d4 2014-04-13 pjp printf("returning %s\n", "crlf");
1253 2540a41a 2014-04-12 pjp #endif
1254 2540a41a 2014-04-12 pjp
1255 2540a41a 2014-04-12 pjp return CRLF;
1256 2540a41a 2014-04-12 pjp }
1257 2540a41a 2014-04-12 pjp
1258 2540a41a 2014-04-12 pjp switch (state) {
1259 2540a41a 2014-04-12 pjp case STATE_IP:
1260 2540a41a 2014-04-12 pjp if (c == ':' || isalnum(c)) {
1261 2540a41a 2014-04-12 pjp lungetc(c);
1262 32e5d54a 2014-04-14 pjp get_ip(buf, sizeof(buf) - 1);
1263 2540a41a 2014-04-12 pjp
1264 2540a41a 2014-04-12 pjp yylval.v.string = strdup(buf);
1265 2540a41a 2014-04-12 pjp if (yylval.v.string == NULL) {
1266 2540a41a 2014-04-12 pjp dolog(LOG_ERR, "yylex: %s\n", strerror(errno));
1267 2540a41a 2014-04-12 pjp slave_shutdown();
1268 2540a41a 2014-04-12 pjp exit(1);
1269 2540a41a 2014-04-12 pjp }
1270 2540a41a 2014-04-12 pjp #ifdef LEXDEBUG
1271 6a6113d4 2014-04-13 pjp if (debug)
1272 6a6113d4 2014-04-13 pjp printf("returning %s\n", "IP");
1273 2540a41a 2014-04-12 pjp #endif
1274 2540a41a 2014-04-12 pjp return (IP);
1275 2540a41a 2014-04-12 pjp }
1276 2540a41a 2014-04-12 pjp /* FALLTHROUGH */
1277 2540a41a 2014-04-12 pjp default:
1278 2540a41a 2014-04-12 pjp if (c == '}') {
1279 2540a41a 2014-04-12 pjp #ifdef LEXDEBUG
1280 6a6113d4 2014-04-13 pjp if (debug)
1281 6a6113d4 2014-04-13 pjp printf("returning %s\n", "ebrace");
1282 2540a41a 2014-04-12 pjp #endif
1283 2540a41a 2014-04-12 pjp setupstate = 0;
1284 2540a41a 2014-04-12 pjp state = 0;
1285 2540a41a 2014-04-12 pjp return EBRACE;
1286 2540a41a 2014-04-12 pjp }
1287 2540a41a 2014-04-12 pjp
1288 2540a41a 2014-04-12 pjp if (c == '{') {
1289 2540a41a 2014-04-12 pjp if (setupstate)
1290 2540a41a 2014-04-12 pjp state = setupstate;
1291 2540a41a 2014-04-12 pjp #ifdef LEXDEBUG
1292 6a6113d4 2014-04-13 pjp if (debug)
1293 6a6113d4 2014-04-13 pjp printf("returning %s\n", "obrace");
1294 2540a41a 2014-04-12 pjp #endif
1295 2540a41a 2014-04-12 pjp return OBRACE;
1296 2540a41a 2014-04-12 pjp }
1297 2540a41a 2014-04-12 pjp
1298 2540a41a 2014-04-12 pjp if (c == '/') {
1299 2540a41a 2014-04-12 pjp #ifdef LEXDEBUG
1300 6a6113d4 2014-04-13 pjp if (debug)
1301 6a6113d4 2014-04-13 pjp printf("returning %s\n", "slash");
1302 2540a41a 2014-04-12 pjp #endif
1303 2540a41a 2014-04-12 pjp return SLASH;
1304 2540a41a 2014-04-12 pjp }
1305 2540a41a 2014-04-12 pjp
1306 2540a41a 2014-04-12 pjp if (c == ',') {
1307 2540a41a 2014-04-12 pjp #ifdef LEXDEBUG
1308 6a6113d4 2014-04-13 pjp if (debug)
1309 6a6113d4 2014-04-13 pjp printf("returning %s\n", "comma");
1310 2540a41a 2014-04-12 pjp #endif
1311 2540a41a 2014-04-12 pjp return COMMA;
1312 2540a41a 2014-04-12 pjp }
1313 2540a41a 2014-04-12 pjp
1314 2540a41a 2014-04-12 pjp
1315 2540a41a 2014-04-12 pjp if (c == ';') {
1316 2540a41a 2014-04-12 pjp while ((c = lgetc(0)) != EOF && c != '\n');
1317 2540a41a 2014-04-12 pjp lungetc(c);
1318 2540a41a 2014-04-12 pjp #ifdef LEXDEBUG
1319 6a6113d4 2014-04-13 pjp if (debug)
1320 6a6113d4 2014-04-13 pjp printf("returning %s\n", "semicolon");
1321 2540a41a 2014-04-12 pjp #endif
1322 2540a41a 2014-04-12 pjp return SEMICOLON;
1323 2540a41a 2014-04-12 pjp }
1324 2540a41a 2014-04-12 pjp
1325 2540a41a 2014-04-12 pjp if (c == '#') {
1326 2540a41a 2014-04-12 pjp while ((c = lgetc(0)) != EOF && c != '\n');
1327 2540a41a 2014-04-12 pjp lungetc(c);
1328 2540a41a 2014-04-12 pjp #ifdef LEXDEBUG
1329 6a6113d4 2014-04-13 pjp if (debug)
1330 6a6113d4 2014-04-13 pjp printf("returning %s\n", "pound");
1331 2540a41a 2014-04-12 pjp #endif
1332 2540a41a 2014-04-12 pjp return POUND;
1333 2540a41a 2014-04-12 pjp }
1334 2540a41a 2014-04-12 pjp
1335 2540a41a 2014-04-12 pjp if (c == '"') {
1336 bd293faa 2014-04-13 pjp get_quotedstring(buf, sizeof(buf) - 1);
1337 2540a41a 2014-04-12 pjp
1338 bd293faa 2014-04-13 pjp if ((cp = strrchr(buf, '"'))) {
1339 2540a41a 2014-04-12 pjp cpos = cp - buf;
1340 2540a41a 2014-04-12 pjp c = buf[cpos];
1341 2540a41a 2014-04-12 pjp buf[cpos] = '\0';
1342 2540a41a 2014-04-12 pjp }
1343 2540a41a 2014-04-12 pjp
1344 2540a41a 2014-04-12 pjp yylval.v.string = strdup(buf);
1345 2540a41a 2014-04-12 pjp if (yylval.v.string == NULL) {
1346 2540a41a 2014-04-12 pjp dolog(LOG_ERR, "yylex: %s\n", strerror(errno));
1347 2540a41a 2014-04-12 pjp slave_shutdown();
1348 2540a41a 2014-04-12 pjp exit(1);
1349 2540a41a 2014-04-12 pjp }
1350 2540a41a 2014-04-12 pjp
1351 2540a41a 2014-04-12 pjp #ifdef LEXDEBUG
1352 6a6113d4 2014-04-13 pjp if (debug)
1353 6a6113d4 2014-04-13 pjp printf("returning %s\n", "quotedstring");
1354 2540a41a 2014-04-12 pjp #endif
1355 2540a41a 2014-04-12 pjp return QUOTEDSTRING;
1356 2540a41a 2014-04-12 pjp }
1357 2540a41a 2014-04-12 pjp
1358 2540a41a 2014-04-12 pjp if (c == '*') {
1359 2540a41a 2014-04-12 pjp yylval.v.string = strdup("*");
1360 2540a41a 2014-04-12 pjp if (yylval.v.string == NULL) {
1361 2540a41a 2014-04-12 pjp dolog(LOG_ERR, "yylex: %s\n", strerror(errno));
1362 2540a41a 2014-04-12 pjp slave_shutdown();
1363 2540a41a 2014-04-12 pjp exit(1);
1364 2540a41a 2014-04-12 pjp }
1365 2540a41a 2014-04-12 pjp #ifdef LEXDEBUG
1366 6a6113d4 2014-04-13 pjp if (debug)
1367 6a6113d4 2014-04-13 pjp printf("returning %s\n", "string");
1368 2540a41a 2014-04-12 pjp #endif
1369 2540a41a 2014-04-12 pjp return STRING;
1370 2540a41a 2014-04-12 pjp }
1371 2540a41a 2014-04-12 pjp
1372 2540a41a 2014-04-12 pjp if (isalnum(c) || c == '.' || c == ':' || c == '-' || c == '_') {
1373 2540a41a 2014-04-12 pjp lungetc(c);
1374 32e5d54a 2014-04-14 pjp get_string(buf, sizeof(buf) - 1);
1375 2540a41a 2014-04-12 pjp
1376 2540a41a 2014-04-12 pjp if ((cp = strpbrk(buf, " \n"))) {
1377 2540a41a 2014-04-12 pjp cpos = cp - buf;
1378 2540a41a 2014-04-12 pjp c = buf[cpos];
1379 2540a41a 2014-04-12 pjp buf[cpos] = '\0';
1380 2540a41a 2014-04-12 pjp }
1381 2540a41a 2014-04-12 pjp
1382 2540a41a 2014-04-12 pjp p = lookup(cmdtab, buf);
1383 2540a41a 2014-04-12 pjp if (p != NULL) {
1384 2540a41a 2014-04-12 pjp #ifdef LEXDEBUG
1385 6a6113d4 2014-04-13 pjp if (debug)
1386 6a6113d4 2014-04-13 pjp printf("returning %s\n", p->val);
1387 2540a41a 2014-04-12 pjp #endif
1388 2540a41a 2014-04-12 pjp yylval.v.string = strdup(p->val);
1389 2540a41a 2014-04-12 pjp if (yylval.v.string == NULL) {
1390 2540a41a 2014-04-12 pjp dolog(LOG_ERR, "yylex: %s\n", strerror(errno));
1391 2540a41a 2014-04-12 pjp slave_shutdown();
1392 2540a41a 2014-04-12 pjp exit(1);
1393 2540a41a 2014-04-12 pjp }
1394 2540a41a 2014-04-12 pjp setupstate = p->state;
1395 2540a41a 2014-04-12 pjp return (p->num);
1396 2540a41a 2014-04-12 pjp }
1397 2540a41a 2014-04-12 pjp
1398 2540a41a 2014-04-12 pjp yylval.v.string = strdup(buf);
1399 2540a41a 2014-04-12 pjp if (yylval.v.string == NULL) {
1400 2540a41a 2014-04-12 pjp dolog(LOG_ERR, "yylex: %s\n", strerror(errno));
1401 2540a41a 2014-04-12 pjp slave_shutdown();
1402 2540a41a 2014-04-12 pjp exit(1);
1403 2540a41a 2014-04-12 pjp }
1404 2540a41a 2014-04-12 pjp
1405 2540a41a 2014-04-12 pjp
1406 2540a41a 2014-04-12 pjp memset(&dst, 0, sizeof(dst));
1407 2540a41a 2014-04-12 pjp if (strchr(buf, ':') != NULL) {
1408 2540a41a 2014-04-12 pjp if (inet_net_pton(AF_INET6, buf, &dst, sizeof(dst)) == -1) {
1409 2540a41a 2014-04-12 pjp if (errno == EAFNOSUPPORT &&
1410 2540a41a 2014-04-12 pjp temp_inet_net_pton_ipv6(buf, &dst, sizeof(dst)) != -1)
1411 f22153d0 2014-04-13 pjp #if LEXDEBUG
1412 f22153d0 2014-04-13 pjp if (debug)
1413 f22153d0 2014-04-13 pjp printf("returning IPV6\n");
1414 f22153d0 2014-04-13 pjp #endif
1415 2540a41a 2014-04-12 pjp return IPV6;
1416 2540a41a 2014-04-12 pjp } else {
1417 2540a41a 2014-04-12 pjp
1418 f22153d0 2014-04-13 pjp #if LEXDEBUG
1419 f22153d0 2014-04-13 pjp if (debug)
1420 f22153d0 2014-04-13 pjp printf("returning IPV6\n");
1421 f22153d0 2014-04-13 pjp #endif
1422 2540a41a 2014-04-12 pjp return IPV6;
1423 2540a41a 2014-04-12 pjp }
1424 2540a41a 2014-04-12 pjp }
1425 2540a41a 2014-04-12 pjp
1426 2540a41a 2014-04-12 pjp memset(&dst, 0, sizeof(dst));
1427 2540a41a 2014-04-12 pjp if (strchr(buf, '.') != NULL &&
1428 2540a41a 2014-04-12 pjp inet_net_pton(AF_INET, buf, &dst, sizeof(dst)) != -1){
1429 6a6113d4 2014-04-13 pjp #if LEXDEBUG
1430 6a6113d4 2014-04-13 pjp if (debug)
1431 6a6113d4 2014-04-13 pjp printf("returning %s\n", "IP");
1432 2540a41a 2014-04-12 pjp #endif
1433 2540a41a 2014-04-12 pjp return IP;
1434 2540a41a 2014-04-12 pjp }
1435 2540a41a 2014-04-12 pjp
1436 2540a41a 2014-04-12 pjp for (cp = &buf[0]; *cp != '\0'; cp++) {
1437 27110135 2014-11-07 pjp if ((! isdigit((int)*cp)) && (*cp != '.'))
1438 2540a41a 2014-04-12 pjp break;
1439 2540a41a 2014-04-12 pjp }
1440 2540a41a 2014-04-12 pjp
1441 2540a41a 2014-04-12 pjp if (*cp != '\0' || (buf[0] == '.' && buf[1] == '\0')) {
1442 2540a41a 2014-04-12 pjp #ifdef LEXDEBUG
1443 44be7f81 2014-04-16 pjp printf("returning %s (%s)\n", "STRING", buf);
1444 2540a41a 2014-04-12 pjp #endif
1445 2540a41a 2014-04-12 pjp return (STRING);
1446 2540a41a 2014-04-12 pjp }
1447 2540a41a 2014-04-12 pjp
1448 2540a41a 2014-04-12 pjp #ifdef LEXDEBUG
1449 2540a41a 2014-04-12 pjp dolog(LOG_DEBUG, "returning %s\n", "NUMBER");
1450 2540a41a 2014-04-12 pjp #endif
1451 2540a41a 2014-04-12 pjp
1452 2540a41a 2014-04-12 pjp free (yylval.v.string);
1453 2540a41a 2014-04-12 pjp yylval.v.intval = atoi(buf);
1454 2540a41a 2014-04-12 pjp
1455 2540a41a 2014-04-12 pjp return (NUMBER);
1456 2540a41a 2014-04-12 pjp }
1457 2540a41a 2014-04-12 pjp
1458 2540a41a 2014-04-12 pjp break;
1459 2540a41a 2014-04-12 pjp }
1460 2540a41a 2014-04-12 pjp
1461 2540a41a 2014-04-12 pjp return (c);
1462 2540a41a 2014-04-12 pjp }
1463 2540a41a 2014-04-12 pjp
1464 2540a41a 2014-04-12 pjp int
1465 bd293faa 2014-04-13 pjp get_quotedstring(char *buf, int n)
1466 2540a41a 2014-04-12 pjp {
1467 2540a41a 2014-04-12 pjp int i, c;
1468 bd293faa 2014-04-13 pjp int stack = 0;
1469 2540a41a 2014-04-12 pjp char *cs;
1470 2540a41a 2014-04-12 pjp
1471 2540a41a 2014-04-12 pjp cs = buf;
1472 2540a41a 2014-04-12 pjp
1473 2540a41a 2014-04-12 pjp for (i = 0; --n > 0; ++i) {
1474 2540a41a 2014-04-12 pjp c = lgetc(0);
1475 bd293faa 2014-04-13 pjp if (c == '\n') {
1476 2540a41a 2014-04-12 pjp *cs = '\0';
1477 bd293faa 2014-04-13 pjp lungetc(c);
1478 2540a41a 2014-04-12 pjp return (0);
1479 bd293faa 2014-04-13 pjp } else if (c == '"') {
1480 bd293faa 2014-04-13 pjp if (stack == 0) {
1481 ac22afcb 2014-04-14 pjp *cs++ = c;
1482 bd293faa 2014-04-13 pjp *cs = '\0';
1483 bd293faa 2014-04-13 pjp return (0);
1484 bd293faa 2014-04-13 pjp } else {
1485 bd293faa 2014-04-13 pjp stack--;
1486 bd293faa 2014-04-13 pjp }
1487 bd293faa 2014-04-13 pjp } else if (c == '\\') {
1488 bd293faa 2014-04-13 pjp if (stack == 0) {
1489 bd293faa 2014-04-13 pjp stack++;
1490 bd293faa 2014-04-13 pjp continue;
1491 bd293faa 2014-04-13 pjp } else {
1492 bd293faa 2014-04-13 pjp stack--;
1493 bd293faa 2014-04-13 pjp }
1494 bd293faa 2014-04-13 pjp } else
1495 bd293faa 2014-04-13 pjp stack = 0;
1496 bd293faa 2014-04-13 pjp
1497 2540a41a 2014-04-12 pjp
1498 2540a41a 2014-04-12 pjp *cs++ = c;
1499 2540a41a 2014-04-12 pjp }
1500 2540a41a 2014-04-12 pjp
1501 2540a41a 2014-04-12 pjp return (1);
1502 2540a41a 2014-04-12 pjp }
1503 2540a41a 2014-04-12 pjp
1504 2540a41a 2014-04-12 pjp int
1505 32e5d54a 2014-04-14 pjp get_string(char *buf, int n)
1506 2540a41a 2014-04-12 pjp {
1507 2540a41a 2014-04-12 pjp int i, c;
1508 2540a41a 2014-04-12 pjp char *cs;
1509 2540a41a 2014-04-12 pjp
1510 2540a41a 2014-04-12 pjp cs = buf;
1511 2540a41a 2014-04-12 pjp
1512 2540a41a 2014-04-12 pjp for (i = 0; --n > 0; ++i) {
1513 2540a41a 2014-04-12 pjp c = lgetc(0);
1514 2540a41a 2014-04-12 pjp if (c == '\n' || c == ' ' || c == ',' || c == ';' || ! (isprint(c) || c == '-' || c == '_')) {
1515 2540a41a 2014-04-12 pjp *cs = '\0';
1516 2540a41a 2014-04-12 pjp lungetc(c);
1517 2540a41a 2014-04-12 pjp return (0);
1518 2540a41a 2014-04-12 pjp }
1519 2540a41a 2014-04-12 pjp
1520 2540a41a 2014-04-12 pjp *cs++ = c;
1521 2540a41a 2014-04-12 pjp }
1522 2540a41a 2014-04-12 pjp
1523 2540a41a 2014-04-12 pjp return (1);
1524 2540a41a 2014-04-12 pjp }
1525 2540a41a 2014-04-12 pjp
1526 2540a41a 2014-04-12 pjp struct rrtab *
1527 2540a41a 2014-04-12 pjp rrlookup(struct rrtab *p, char *keyword)
1528 2540a41a 2014-04-12 pjp {
1529 2540a41a 2014-04-12 pjp
1530 2540a41a 2014-04-12 pjp for (; p->name != NULL; p++) {
1531 2540a41a 2014-04-12 pjp if (strcasecmp(p->name, keyword) == 0)
1532 2540a41a 2014-04-12 pjp return (p);
1533 2540a41a 2014-04-12 pjp }
1534 2540a41a 2014-04-12 pjp
1535 2540a41a 2014-04-12 pjp return (NULL);
1536 2540a41a 2014-04-12 pjp }
1537 2540a41a 2014-04-12 pjp
1538 2540a41a 2014-04-12 pjp struct tab *
1539 2540a41a 2014-04-12 pjp lookup(struct tab *cmdtab, char *keyword)
1540 2540a41a 2014-04-12 pjp {
1541 2540a41a 2014-04-12 pjp struct tab *p;
1542 2540a41a 2014-04-12 pjp
1543 2540a41a 2014-04-12 pjp for (p = cmdtab; p->val != NULL; p++) {
1544 2540a41a 2014-04-12 pjp if (strcmp(p->val, keyword) == 0)
1545 2540a41a 2014-04-12 pjp return (p);
1546 2540a41a 2014-04-12 pjp }
1547 2540a41a 2014-04-12 pjp
1548 2540a41a 2014-04-12 pjp return (NULL);
1549 2540a41a 2014-04-12 pjp }
1550 2540a41a 2014-04-12 pjp
1551 2540a41a 2014-04-12 pjp int
1552 32e5d54a 2014-04-14 pjp get_ip(char *buf, int n)
1553 2540a41a 2014-04-12 pjp {
1554 2540a41a 2014-04-12 pjp int i, c;
1555 2540a41a 2014-04-12 pjp char *cs;
1556 2540a41a 2014-04-12 pjp
1557 2540a41a 2014-04-12 pjp cs = buf;
1558 2540a41a 2014-04-12 pjp
1559 2540a41a 2014-04-12 pjp for (i = 0; --n > 0; ++i) {
1560 2540a41a 2014-04-12 pjp c = lgetc(0);
1561 2540a41a 2014-04-12 pjp if (c == ',' || c == '\n' || ! (isalnum(c) || c == '/' || c == ':' || c == '.')) {
1562 2540a41a 2014-04-12 pjp *cs = '\0';
1563 2540a41a 2014-04-12 pjp lungetc(c);
1564 2540a41a 2014-04-12 pjp return (0);
1565 2540a41a 2014-04-12 pjp }
1566 2540a41a 2014-04-12 pjp
1567 2540a41a 2014-04-12 pjp *cs++ = c;
1568 2540a41a 2014-04-12 pjp }
1569 2540a41a 2014-04-12 pjp
1570 2540a41a 2014-04-12 pjp return (1);
1571 2540a41a 2014-04-12 pjp }
1572 2540a41a 2014-04-12 pjp
1573 2540a41a 2014-04-12 pjp char *
1574 2540a41a 2014-04-12 pjp check_rr(char *domainname, char *mytype, int itype, int *converted_namelen)
1575 2540a41a 2014-04-12 pjp {
1576 2540a41a 2014-04-12 pjp struct rrtab *rr;
1577 2540a41a 2014-04-12 pjp char *converted_name, *p;
1578 2540a41a 2014-04-12 pjp int i;
1579 2540a41a 2014-04-12 pjp
1580 2540a41a 2014-04-12 pjp
1581 2540a41a 2014-04-12 pjp if ((rr = rrlookup(myrrtab, mytype)) == NULL) {
1582 2540a41a 2014-04-12 pjp dolog(LOG_ERR, "error input line %d\n", file->lineno);
1583 2540a41a 2014-04-12 pjp slave_shutdown();
1584 2540a41a 2014-04-12 pjp exit(1);
1585 2540a41a 2014-04-12 pjp }
1586 2540a41a 2014-04-12 pjp
1587 2540a41a 2014-04-12 pjp if (rr->type != itype) {
1588 2540a41a 2014-04-12 pjp dolog(LOG_ERR, "error input line %d, expected itype = %d, had %d\n", file->lineno, itype, rr->type);
1589 2540a41a 2014-04-12 pjp return NULL;
1590 2540a41a 2014-04-12 pjp }
1591 2540a41a 2014-04-12 pjp
1592 2540a41a 2014-04-12 pjp if (strlen(domainname) > (DNS_MAXNAME - 2)) {
1593 2540a41a 2014-04-12 pjp dolog(LOG_ERR, "domain name too long, line %d\n", file->lineno);
1594 2540a41a 2014-04-12 pjp slave_shutdown();
1595 2540a41a 2014-04-12 pjp exit(1);
1596 2540a41a 2014-04-12 pjp }
1597 2540a41a 2014-04-12 pjp
1598 2540a41a 2014-04-12 pjp for (i = 0, p = domainname; i < strlen(domainname); i++) {
1599 27110135 2014-11-07 pjp *p = tolower((int)*p);
1600 2540a41a 2014-04-12 pjp p++;
1601 2540a41a 2014-04-12 pjp }
1602 2540a41a 2014-04-12 pjp
1603 2540a41a 2014-04-12 pjp if ((strlen(domainname) == 1) && (domainname[0] == '.')) {
1604 2540a41a 2014-04-12 pjp converted_name = malloc(1);
1605 2540a41a 2014-04-12 pjp if (converted_name == NULL) {
1606 2540a41a 2014-04-12 pjp dolog(LOG_ERR, "malloc failed\n");
1607 2540a41a 2014-04-12 pjp slave_shutdown();
1608 2540a41a 2014-04-12 pjp exit(1);
1609 2540a41a 2014-04-12 pjp }
1610 2540a41a 2014-04-12 pjp
1611 2540a41a 2014-04-12 pjp *converted_namelen = 1;
1612 2540a41a 2014-04-12 pjp *converted_name = '\0';
1613 2540a41a 2014-04-12 pjp } else if ((strlen(domainname) == 1) && (domainname[0] == '*')) {
1614 2540a41a 2014-04-12 pjp converted_name = malloc(1);
1615 2540a41a 2014-04-12 pjp if (converted_name == NULL) {
1616 2540a41a 2014-04-12 pjp dolog(LOG_ERR, "malloc failed\n");
1617 2540a41a 2014-04-12 pjp slave_shutdown();
1618 2540a41a 2014-04-12 pjp exit(1);
1619 2540a41a 2014-04-12 pjp }
1620 2540a41a 2014-04-12 pjp
1621 2540a41a 2014-04-12 pjp *converted_namelen = 1;
1622 2540a41a 2014-04-12 pjp *converted_name = '*';
1623 2540a41a 2014-04-12 pjp } else {
1624 2540a41a 2014-04-12 pjp converted_name = dns_label(domainname, converted_namelen);
1625 2540a41a 2014-04-12 pjp
1626 2540a41a 2014-04-12 pjp if (converted_name == NULL) {
1627 2540a41a 2014-04-12 pjp dolog(LOG_ERR, "error processing domain name line %d\n", file->lineno);
1628 2540a41a 2014-04-12 pjp slave_shutdown();
1629 2540a41a 2014-04-12 pjp exit(1);
1630 2540a41a 2014-04-12 pjp }
1631 2540a41a 2014-04-12 pjp }
1632 2540a41a 2014-04-12 pjp
1633 2540a41a 2014-04-12 pjp return (converted_name);
1634 2540a41a 2014-04-12 pjp }
1635 2540a41a 2014-04-12 pjp
1636 2540a41a 2014-04-12 pjp int
1637 2540a41a 2014-04-12 pjp fill_cname(char *name, char *type, int myttl, char *hostname)
1638 2540a41a 2014-04-12 pjp {
1639 2540a41a 2014-04-12 pjp struct domain sdomain;
1640 2540a41a 2014-04-12 pjp char *myname, *converted_name;
1641 2540a41a 2014-04-12 pjp int len, converted_namelen;
1642 2540a41a 2014-04-12 pjp int i ;
1643 2540a41a 2014-04-12 pjp
1644 2540a41a 2014-04-12 pjp for (i = 0; i < strlen(name); i++) {
1645 27110135 2014-11-07 pjp name[i] = tolower((int)name[i]);
1646 2540a41a 2014-04-12 pjp }
1647 2540a41a 2014-04-12 pjp
1648 2540a41a 2014-04-12 pjp converted_name = check_rr(name, type, DNS_TYPE_CNAME, &converted_namelen);
1649 2540a41a 2014-04-12 pjp if (converted_name == NULL) {
1650 2540a41a 2014-04-12 pjp return -1;
1651 2540a41a 2014-04-12 pjp }
1652 2540a41a 2014-04-12 pjp
1653 2540a41a 2014-04-12 pjp memset(&sdomain, 0, sizeof(sdomain));
1654 2540a41a 2014-04-12 pjp if (get_record(&sdomain, converted_name, converted_namelen) < 0) {
1655 2540a41a 2014-04-12 pjp return (-1);
1656 2540a41a 2014-04-12 pjp }
1657 2540a41a 2014-04-12 pjp
1658 2540a41a 2014-04-12 pjp #ifdef __linux__
1659 35d93ac7 2014-04-13 pjp strncpy((char *)sdomain.zonename, (char *)name, DNS_MAXNAME + 1);
1660 2540a41a 2014-04-12 pjp sdomain.zonename[DNS_MAXNAME] = '\0';
1661 2540a41a 2014-04-12 pjp #else
1662 35d93ac7 2014-04-13 pjp strlcpy((char *)sdomain.zonename, (char *)name, DNS_MAXNAME + 1);
1663 2540a41a 2014-04-12 pjp #endif
1664 2540a41a 2014-04-12 pjp memcpy(sdomain.zone, converted_name, converted_namelen);
1665 2540a41a 2014-04-12 pjp sdomain.zonelen = converted_namelen;
1666 2540a41a 2014-04-12 pjp
1667 2540a41a 2014-04-12 pjp sdomain.ttl = myttl;
1668 2540a41a 2014-04-12 pjp
1669 2540a41a 2014-04-12 pjp myname = dns_label(hostname, (int *)&len);
1670 2540a41a 2014-04-12 pjp if (myname == NULL) {
1671 2540a41a 2014-04-12 pjp dolog(LOG_INFO, "illegal nameserver, skipping line %d\n", file->lineno);
1672 2540a41a 2014-04-12 pjp return 0;
1673 2540a41a 2014-04-12 pjp }
1674 2540a41a 2014-04-12 pjp
1675 2540a41a 2014-04-12 pjp if (len > 0xff || len < 0) {
1676 2540a41a 2014-04-12 pjp dolog(LOG_INFO, "illegal len value , line %d\n", file->lineno);
1677 2540a41a 2014-04-12 pjp return -1;
1678 2540a41a 2014-04-12 pjp }
1679 2540a41a 2014-04-12 pjp
1680 2540a41a 2014-04-12 pjp sdomain.cnamelen = len;
1681 2540a41a 2014-04-12 pjp memcpy((char *)&sdomain.cname[0], myname, len);
1682 2540a41a 2014-04-12 pjp
1683 2540a41a 2014-04-12 pjp free(myname);
1684 2540a41a 2014-04-12 pjp
1685 2540a41a 2014-04-12 pjp sdomain.flags |= DOMAIN_HAVE_CNAME;
1686 2540a41a 2014-04-12 pjp
1687 2540a41a 2014-04-12 pjp set_record(&sdomain, converted_name, converted_namelen);
1688 2540a41a 2014-04-12 pjp
1689 2540a41a 2014-04-12 pjp if (converted_name)
1690 2540a41a 2014-04-12 pjp free (converted_name);
1691 2540a41a 2014-04-12 pjp
1692 2540a41a 2014-04-12 pjp return (0);
1693 2540a41a 2014-04-12 pjp
1694 2540a41a 2014-04-12 pjp }
1695 2540a41a 2014-04-12 pjp
1696 2540a41a 2014-04-12 pjp int
1697 2540a41a 2014-04-12 pjp fill_ptr(char *name, char *type, int myttl, char *hostname)
1698 2540a41a 2014-04-12 pjp {
1699 2540a41a 2014-04-12 pjp struct domain sdomain;
1700 2540a41a 2014-04-12 pjp int len, converted_namelen;
1701 2540a41a 2014-04-12 pjp char *myname, *converted_name;
1702 2540a41a 2014-04-12 pjp int i;
1703 2540a41a 2014-04-12 pjp
1704 2540a41a 2014-04-12 pjp for (i = 0; i < strlen(name); i++) {
1705 27110135 2014-11-07 pjp name[i] = tolower((int)name[i]);
1706 2540a41a 2014-04-12 pjp }
1707 2540a41a 2014-04-12 pjp
1708 2540a41a 2014-04-12 pjp converted_name = check_rr(name, type, DNS_TYPE_PTR, &converted_namelen);
1709 2540a41a 2014-04-12 pjp if (converted_name == NULL) {
1710 2540a41a 2014-04-12 pjp return -1;
1711 2540a41a 2014-04-12 pjp }
1712 2540a41a 2014-04-12 pjp
1713 2540a41a 2014-04-12 pjp memset(&sdomain, 0, sizeof(sdomain));
1714 2540a41a 2014-04-12 pjp if (get_record(&sdomain, converted_name, converted_namelen) < 0) {
1715 2540a41a 2014-04-12 pjp return (-1);
1716 2540a41a 2014-04-12 pjp }
1717 2540a41a 2014-04-12 pjp
1718 2540a41a 2014-04-12 pjp #ifdef __linux__
1719 35d93ac7 2014-04-13 pjp strncpy((char *)sdomain.zonename, (char *)name, DNS_MAXNAME + 1);
1720 2540a41a 2014-04-12 pjp sdomain.zonename[DNS_MAXNAME] = '\0';
1721 2540a41a 2014-04-12 pjp #else
1722 35d93ac7 2014-04-13 pjp strlcpy((char *)sdomain.zonename, (char *)name, DNS_MAXNAME + 1);
1723 2540a41a 2014-04-12 pjp #endif
1724 2540a41a 2014-04-12 pjp memcpy(sdomain.zone, converted_name, converted_namelen);
1725 2540a41a 2014-04-12 pjp sdomain.zonelen = converted_namelen;
1726 2540a41a 2014-04-12 pjp
1727 2540a41a 2014-04-12 pjp sdomain.ttl = myttl;
1728 2540a41a 2014-04-12 pjp
1729 2540a41a 2014-04-12 pjp myname = dns_label(hostname, (int *)&len);
1730 2540a41a 2014-04-12 pjp if (myname == NULL) {
1731 2540a41a 2014-04-12 pjp dolog(LOG_INFO, "illegal nameserver, skipping line %d\n", file->lineno);
1732 2540a41a 2014-04-12 pjp return 0;
1733 2540a41a 2014-04-12 pjp }
1734 2540a41a 2014-04-12 pjp
1735 2540a41a 2014-04-12 pjp if (len > 0xff || len < 0) {
1736 2540a41a 2014-04-12 pjp dolog(LOG_INFO, "illegal len value , line %d\n", file->lineno);
1737 2540a41a 2014-04-12 pjp return -1;
1738 2540a41a 2014-04-12 pjp }
1739 2540a41a 2014-04-12 pjp
1740 2540a41a 2014-04-12 pjp sdomain.ptrlen = len;
1741 2540a41a 2014-04-12 pjp memcpy((char *)&sdomain.ptr[0], myname, len);
1742 2540a41a 2014-04-12 pjp
1743 2540a41a 2014-04-12 pjp free(myname);
1744 2540a41a 2014-04-12 pjp
1745 2540a41a 2014-04-12 pjp sdomain.flags |= DOMAIN_HAVE_PTR;
1746 f5989689 2014-04-21 pjp
1747 f5989689 2014-04-21 pjp set_record(&sdomain, converted_name, converted_namelen);
1748 f5989689 2014-04-21 pjp
1749 f5989689 2014-04-21 pjp if (converted_name)
1750 f5989689 2014-04-21 pjp free (converted_name);
1751 f5989689 2014-04-21 pjp
1752 f5989689 2014-04-21 pjp return (0);
1753 f5989689 2014-04-21 pjp
1754 f5989689 2014-04-21 pjp }
1755 f5989689 2014-04-21 pjp
1756 f5989689 2014-04-21 pjp /* based on fill_txt */
1757 f5989689 2014-04-21 pjp int
1758 f5989689 2014-04-21 pjp fill_spf(char *name, char *type, int myttl, char *msg)
1759 f5989689 2014-04-21 pjp {
1760 f5989689 2014-04-21 pjp struct domain sdomain;
1761 f5989689 2014-04-21 pjp int converted_namelen;
1762 f5989689 2014-04-21 pjp char *converted_name;
1763 f5989689 2014-04-21 pjp int len, i;
1764 f5989689 2014-04-21 pjp
1765 f5989689 2014-04-21 pjp for (i = 0; i < strlen(name); i++) {
1766 27110135 2014-11-07 pjp name[i] = tolower((int)name[i]);
1767 f5989689 2014-04-21 pjp }
1768 f5989689 2014-04-21 pjp
1769 f5989689 2014-04-21 pjp if ((len = strlen(msg)) > 255) {
1770 f5989689 2014-04-21 pjp dolog(LOG_ERR, "SPF record too long line %d\n", file->lineno);
1771 f5989689 2014-04-21 pjp return (-1);
1772 f5989689 2014-04-21 pjp }
1773 f5989689 2014-04-21 pjp
1774 f5989689 2014-04-21 pjp converted_name = check_rr(name, type, DNS_TYPE_SPF, &converted_namelen);
1775 f5989689 2014-04-21 pjp if (converted_name == NULL) {
1776 f5989689 2014-04-21 pjp return -1;
1777 f5989689 2014-04-21 pjp }
1778 f5989689 2014-04-21 pjp
1779 f5989689 2014-04-21 pjp memset(&sdomain, 0, sizeof(sdomain));
1780 f5989689 2014-04-21 pjp if (get_record(&sdomain, converted_name, converted_namelen) < 0) {
1781 f5989689 2014-04-21 pjp return (-1);
1782 f5989689 2014-04-21 pjp }
1783 f5989689 2014-04-21 pjp
1784 f5989689 2014-04-21 pjp #ifdef __linux__
1785 f5989689 2014-04-21 pjp strncpy((char *)sdomain.zonename, (char *)name, DNS_MAXNAME + 1);
1786 f5989689 2014-04-21 pjp sdomain.zonename[DNS_MAXNAME] = '\0';
1787 f5989689 2014-04-21 pjp #else
1788 f5989689 2014-04-21 pjp strlcpy((char *)sdomain.zonename, (char *)name, DNS_MAXNAME + 1);
1789 f5989689 2014-04-21 pjp #endif
1790 f5989689 2014-04-21 pjp memcpy(sdomain.zone, converted_name, converted_namelen);
1791 f5989689 2014-04-21 pjp sdomain.zonelen = converted_namelen;
1792 2540a41a 2014-04-12 pjp
1793 f5989689 2014-04-21 pjp sdomain.ttl = myttl;
1794 f5989689 2014-04-21 pjp
1795 f5989689 2014-04-21 pjp memcpy(&sdomain.spf, msg, len);
1796 f5989689 2014-04-21 pjp sdomain.spflen = len;
1797 f5989689 2014-04-21 pjp
1798 f5989689 2014-04-21 pjp sdomain.flags |= DOMAIN_HAVE_SPF;
1799 1f1faf13 2014-05-11 pjp
1800 1f1faf13 2014-05-11 pjp set_record(&sdomain, converted_name, converted_namelen);
1801 1f1faf13 2014-05-11 pjp
1802 1f1faf13 2014-05-11 pjp if (converted_name)
1803 1f1faf13 2014-05-11 pjp free (converted_name);
1804 1f1faf13 2014-05-11 pjp
1805 1f1faf13 2014-05-11 pjp return (0);
1806 1f1faf13 2014-05-11 pjp
1807 1f1faf13 2014-05-11 pjp }
1808 1f1faf13 2014-05-11 pjp
1809 1f1faf13 2014-05-11 pjp
1810 1f1faf13 2014-05-11 pjp int
1811 1f1faf13 2014-05-11 pjp fill_naptr(char *name, char *type, int myttl, int order, int preference, char *flags, char *services, char *regexp, char *replacement)
1812 1f1faf13 2014-05-11 pjp {
1813 1f1faf13 2014-05-11 pjp struct domain sdomain;
1814 1f1faf13 2014-05-11 pjp int converted_namelen;
1815 1f1faf13 2014-05-11 pjp char *converted_name, *naptrname;
1816 1f1faf13 2014-05-11 pjp int flagslen, serviceslen, regexplen, replacementlen;
1817 1f1faf13 2014-05-11 pjp int i, naptr_namelen;
1818 1f1faf13 2014-05-11 pjp
1819 1f1faf13 2014-05-11 pjp for (i = 0; i < strlen(name); i++) {
1820 27110135 2014-11-07 pjp name[i] = tolower((int)name[i]);
1821 1f1faf13 2014-05-11 pjp }
1822 1f1faf13 2014-05-11 pjp
1823 1f1faf13 2014-05-11 pjp if ((flagslen = strlen(flags)) > 255 ||
1824 1f1faf13 2014-05-11 pjp (serviceslen = strlen(services)) > 255 ||
1825 1f1faf13 2014-05-11 pjp (regexplen = strlen(regexp)) > 255 ||
1826 1f1faf13 2014-05-11 pjp (replacementlen = strlen(replacement)) > 255) {
1827 f5989689 2014-04-21 pjp
1828 1f1faf13 2014-05-11 pjp dolog(LOG_ERR, "NAPTR record too long line %d\n", file->lineno);
1829 1f1faf13 2014-05-11 pjp return (-1);
1830 1f1faf13 2014-05-11 pjp }
1831 1f1faf13 2014-05-11 pjp
1832 1f1faf13 2014-05-11 pjp converted_name = check_rr(name, type, DNS_TYPE_NAPTR, &converted_namelen);
1833 1f1faf13 2014-05-11 pjp if (converted_name == NULL) {
1834 1f1faf13 2014-05-11 pjp return -1;
1835 1f1faf13 2014-05-11 pjp }
1836 1f1faf13 2014-05-11 pjp
1837 1f1faf13 2014-05-11 pjp memset(&sdomain, 0, sizeof(sdomain));
1838 1f1faf13 2014-05-11 pjp if (get_record(&sdomain, converted_name, converted_namelen) < 0) {
1839 1f1faf13 2014-05-11 pjp return (-1);
1840 1f1faf13 2014-05-11 pjp }
1841 1f1faf13 2014-05-11 pjp
1842 1f1faf13 2014-05-11 pjp #ifdef __linux__
1843 1f1faf13 2014-05-11 pjp strncpy((char *)sdomain.zonename, (char *)name, DNS_MAXNAME + 1);
1844 1f1faf13 2014-05-11 pjp sdomain.zonename[DNS_MAXNAME] = '\0';
1845 1f1faf13 2014-05-11 pjp #else
1846 1f1faf13 2014-05-11 pjp strlcpy((char *)sdomain.zonename, (char *)name, DNS_MAXNAME + 1);
1847 1f1faf13 2014-05-11 pjp #endif
1848 1f1faf13 2014-05-11 pjp memcpy(sdomain.zone, converted_name, converted_namelen);
1849 1f1faf13 2014-05-11 pjp sdomain.zonelen = converted_namelen;
1850 1f1faf13 2014-05-11 pjp
1851 1f1faf13 2014-05-11 pjp sdomain.ttl = myttl;
1852 1f1faf13 2014-05-11 pjp
1853 1f1faf13 2014-05-11 pjp sdomain.naptr[sdomain.naptr_count].order = order;
1854 1f1faf13 2014-05-11 pjp sdomain.naptr[sdomain.naptr_count].preference = preference;
1855 1f1faf13 2014-05-11 pjp
1856 1f1faf13 2014-05-11 pjp memcpy(&sdomain.naptr[sdomain.naptr_count].flags, flags, flagslen);
1857 1f1faf13 2014-05-11 pjp sdomain.naptr[sdomain.naptr_count].flagslen = flagslen;
1858 1f1faf13 2014-05-11 pjp
1859 1f1faf13 2014-05-11 pjp memcpy(&sdomain.naptr[sdomain.naptr_count].services, services, serviceslen);
1860 1f1faf13 2014-05-11 pjp sdomain.naptr[sdomain.naptr_count].serviceslen = serviceslen;
1861 1f1faf13 2014-05-11 pjp
1862 1f1faf13 2014-05-11 pjp memcpy(&sdomain.naptr[sdomain.naptr_count].regexp, regexp, regexplen);
1863 1f1faf13 2014-05-11 pjp sdomain.naptr[sdomain.naptr_count].regexplen = regexplen;
1864 1f1faf13 2014-05-11 pjp
1865 1f1faf13 2014-05-11 pjp naptrname = check_rr(replacement, type, DNS_TYPE_NAPTR, &naptr_namelen);
1866 3edf28ef 2014-05-11 pjp if (naptrname == NULL) {
1867 1f1faf13 2014-05-11 pjp return -1;
1868 1f1faf13 2014-05-11 pjp }
1869 1f1faf13 2014-05-11 pjp
1870 1f1faf13 2014-05-11 pjp memcpy(&sdomain.naptr[sdomain.naptr_count].replacement, naptrname, naptr_namelen);
1871 1f1faf13 2014-05-11 pjp sdomain.naptr[sdomain.naptr_count].replacementlen = naptr_namelen;
1872 1f1faf13 2014-05-11 pjp
1873 1f1faf13 2014-05-11 pjp sdomain.naptr_count++;
1874 1f1faf13 2014-05-11 pjp
1875 1f1faf13 2014-05-11 pjp sdomain.flags |= DOMAIN_HAVE_NAPTR;
1876 1f1faf13 2014-05-11 pjp
1877 2540a41a 2014-04-12 pjp set_record(&sdomain, converted_name, converted_namelen);
1878 2540a41a 2014-04-12 pjp
1879 3edf28ef 2014-05-11 pjp if (naptrname)
1880 3edf28ef 2014-05-11 pjp free (naptrname);
1881 3edf28ef 2014-05-11 pjp
1882 2540a41a 2014-04-12 pjp if (converted_name)
1883 2540a41a 2014-04-12 pjp free (converted_name);
1884 2540a41a 2014-04-12 pjp
1885 2540a41a 2014-04-12 pjp return (0);
1886 2540a41a 2014-04-12 pjp
1887 2540a41a 2014-04-12 pjp }
1888 2540a41a 2014-04-12 pjp
1889 2540a41a 2014-04-12 pjp int
1890 2540a41a 2014-04-12 pjp fill_txt(char *name, char *type, int myttl, char *msg)
1891 2540a41a 2014-04-12 pjp {
1892 2540a41a 2014-04-12 pjp struct domain sdomain;
1893 2540a41a 2014-04-12 pjp int converted_namelen;
1894 2540a41a 2014-04-12 pjp char *converted_name;
1895 2540a41a 2014-04-12 pjp int len, i;
1896 2540a41a 2014-04-12 pjp
1897 2540a41a 2014-04-12 pjp for (i = 0; i < strlen(name); i++) {
1898 27110135 2014-11-07 pjp name[i] = tolower((int)name[i]);
1899 2540a41a 2014-04-12 pjp }
1900 2540a41a 2014-04-12 pjp
1901 2540a41a 2014-04-12 pjp if ((len = strlen(msg)) > 255) {
1902 2540a41a 2014-04-12 pjp dolog(LOG_ERR, "TXT record too long line %d\n", file->lineno);
1903 2540a41a 2014-04-12 pjp return (-1);
1904 2540a41a 2014-04-12 pjp }
1905 2540a41a 2014-04-12 pjp
1906 2540a41a 2014-04-12 pjp converted_name = check_rr(name, type, DNS_TYPE_TXT, &converted_namelen);
1907 2540a41a 2014-04-12 pjp if (converted_name == NULL) {
1908 2540a41a 2014-04-12 pjp return -1;
1909 2540a41a 2014-04-12 pjp }
1910 2540a41a 2014-04-12 pjp
1911 2540a41a 2014-04-12 pjp memset(&sdomain, 0, sizeof(sdomain));
1912 2540a41a 2014-04-12 pjp if (get_record(&sdomain, converted_name, converted_namelen) < 0) {
1913 2540a41a 2014-04-12 pjp return (-1);
1914 2540a41a 2014-04-12 pjp }
1915 2540a41a 2014-04-12 pjp
1916 2540a41a 2014-04-12 pjp #ifdef __linux__
1917 35d93ac7 2014-04-13 pjp strncpy((char *)sdomain.zonename, (char *)name, DNS_MAXNAME + 1);
1918 2540a41a 2014-04-12 pjp sdomain.zonename[DNS_MAXNAME] = '\0';
1919 2540a41a 2014-04-12 pjp #else
1920 35d93ac7 2014-04-13 pjp strlcpy((char *)sdomain.zonename, (char *)name, DNS_MAXNAME + 1);
1921 2540a41a 2014-04-12 pjp #endif
1922 2540a41a 2014-04-12 pjp memcpy(sdomain.zone, converted_name, converted_namelen);
1923 2540a41a 2014-04-12 pjp sdomain.zonelen = converted_namelen;
1924 2540a41a 2014-04-12 pjp
1925 2540a41a 2014-04-12 pjp sdomain.ttl = myttl;
1926 2540a41a 2014-04-12 pjp
1927 2540a41a 2014-04-12 pjp memcpy(&sdomain.txt, msg, len);
1928 2540a41a 2014-04-12 pjp sdomain.txtlen = len;
1929 2540a41a 2014-04-12 pjp
1930 2540a41a 2014-04-12 pjp sdomain.flags |= DOMAIN_HAVE_TXT;
1931 df34d218 2014-04-21 pjp
1932 df34d218 2014-04-21 pjp set_record(&sdomain, converted_name, converted_namelen);
1933 df34d218 2014-04-21 pjp
1934 df34d218 2014-04-21 pjp if (converted_name)
1935 df34d218 2014-04-21 pjp free (converted_name);
1936 df34d218 2014-04-21 pjp
1937 df34d218 2014-04-21 pjp return (0);
1938 df34d218 2014-04-21 pjp
1939 df34d218 2014-04-21 pjp }
1940 df34d218 2014-04-21 pjp
1941 df34d218 2014-04-21 pjp /* based on fill_srv */
1942 df34d218 2014-04-21 pjp int
1943 df34d218 2014-04-21 pjp fill_sshfp(char *name, char *type, int myttl, int alg, int fptype, char *fingerprint)
1944 df34d218 2014-04-21 pjp {
1945 df34d218 2014-04-21 pjp struct domain sdomain;
1946 df34d218 2014-04-21 pjp int converted_namelen;
1947 df34d218 2014-04-21 pjp char *converted_name;
1948 d67bdb62 2014-04-22 pjp char *p, *ep, save;
1949 df34d218 2014-04-21 pjp int len, i;
1950 df34d218 2014-04-21 pjp
1951 df34d218 2014-04-21 pjp for (i = 0; i < strlen(name); i++) {
1952 27110135 2014-11-07 pjp name[i] = tolower((int)name[i]);
1953 df34d218 2014-04-21 pjp }
1954 df34d218 2014-04-21 pjp
1955 df34d218 2014-04-21 pjp converted_name = check_rr(name, type, DNS_TYPE_SSHFP, &converted_namelen);
1956 df34d218 2014-04-21 pjp if (converted_name == NULL) {
1957 df34d218 2014-04-21 pjp return -1;
1958 df34d218 2014-04-21 pjp }
1959 2540a41a 2014-04-12 pjp
1960 df34d218 2014-04-21 pjp memset(&sdomain, 0, sizeof(sdomain));
1961 df34d218 2014-04-21 pjp if (get_record(&sdomain, converted_name, converted_namelen) < 0) {
1962 df34d218 2014-04-21 pjp return (-1);
1963 df34d218 2014-04-21 pjp }
1964 df34d218 2014-04-21 pjp
1965 df34d218 2014-04-21 pjp #ifdef __linux__
1966 df34d218 2014-04-21 pjp strncpy((char *)sdomain.zonename, (char *)name, DNS_MAXNAME + 1);
1967 df34d218 2014-04-21 pjp sdomain.zonename[DNS_MAXNAME] = '\0';
1968 df34d218 2014-04-21 pjp #else
1969 df34d218 2014-04-21 pjp strlcpy((char *)sdomain.zonename, (char *)name, DNS_MAXNAME + 1);
1970 df34d218 2014-04-21 pjp #endif
1971 df34d218 2014-04-21 pjp memcpy(sdomain.zone, converted_name, converted_namelen);
1972 df34d218 2014-04-21 pjp sdomain.zonelen = converted_namelen;
1973 df34d218 2014-04-21 pjp
1974 df34d218 2014-04-21 pjp if (sdomain.sshfp_count >= RECORD_COUNT) {
1975 df34d218 2014-04-21 pjp dolog(LOG_INFO, "%s: too many SSHFP records for zone \"%s\", skipping line %d\n", file->name, name, file->lineno);
1976 df34d218 2014-04-21 pjp return (-1);
1977 df34d218 2014-04-21 pjp }
1978 df34d218 2014-04-21 pjp
1979 df34d218 2014-04-21 pjp sdomain.ttl = myttl;
1980 df34d218 2014-04-21 pjp
1981 df34d218 2014-04-21 pjp sdomain.sshfp[sdomain.sshfp_count].algorithm = alg;
1982 df34d218 2014-04-21 pjp sdomain.sshfp[sdomain.sshfp_count].fptype = fptype;
1983 df34d218 2014-04-21 pjp
1984 df34d218 2014-04-21 pjp switch (fptype) {
1985 df34d218 2014-04-21 pjp case 1:
1986 df34d218 2014-04-21 pjp len = sdomain.sshfp[sdomain.sshfp_count].fplen = DNS_SSHFP_SIZE_SHA1;
1987 df34d218 2014-04-21 pjp break;
1988 df34d218 2014-04-21 pjp case 2:
1989 df34d218 2014-04-21 pjp len = sdomain.sshfp[sdomain.sshfp_count].fplen = DNS_SSHFP_SIZE_SHA256;
1990 df34d218 2014-04-21 pjp break;
1991 df34d218 2014-04-21 pjp default:
1992 df34d218 2014-04-21 pjp dolog(LOG_ERR, "sshfp: unknown fingerprint type!\n");
1993 df34d218 2014-04-21 pjp return -1;
1994 df34d218 2014-04-21 pjp }
1995 df34d218 2014-04-21 pjp
1996 d67bdb62 2014-04-22 pjp p = fingerprint;
1997 d67bdb62 2014-04-22 pjp for (i = 0; i < len; i++) {
1998 d67bdb62 2014-04-22 pjp save = p[2];
1999 d67bdb62 2014-04-22 pjp p[2] = '\0';
2000 d67bdb62 2014-04-22 pjp sdomain.sshfp[sdomain.sshfp_count].fingerprint[i] = strtol(p, &ep, 16);
2001 d67bdb62 2014-04-22 pjp p[2] = save;
2002 d67bdb62 2014-04-22 pjp p += 2;
2003 d67bdb62 2014-04-22 pjp }
2004 df34d218 2014-04-21 pjp
2005 df34d218 2014-04-21 pjp
2006 df34d218 2014-04-21 pjp sdomain.sshfp_count++;
2007 df34d218 2014-04-21 pjp
2008 df34d218 2014-04-21 pjp sdomain.flags |= DOMAIN_HAVE_SSHFP;
2009 df34d218 2014-04-21 pjp
2010 2540a41a 2014-04-12 pjp set_record(&sdomain, converted_name, converted_namelen);
2011 2540a41a 2014-04-12 pjp
2012 2540a41a 2014-04-12 pjp if (converted_name)
2013 2540a41a 2014-04-12 pjp free (converted_name);
2014 2540a41a 2014-04-12 pjp
2015 2540a41a 2014-04-12 pjp return (0);
2016 2540a41a 2014-04-12 pjp
2017 2540a41a 2014-04-12 pjp }
2018 2540a41a 2014-04-12 pjp
2019 2540a41a 2014-04-12 pjp int
2020 2540a41a 2014-04-12 pjp fill_srv(char *name, char *type, int myttl, int priority, int weight, int port, char *srvhost)
2021 2540a41a 2014-04-12 pjp {
2022 2540a41a 2014-04-12 pjp struct domain sdomain;
2023 2540a41a 2014-04-12 pjp int converted_namelen;
2024 2540a41a 2014-04-12 pjp char *converted_name;
2025 2540a41a 2014-04-12 pjp char *srvname;
2026 2540a41a 2014-04-12 pjp int len, i;
2027 2540a41a 2014-04-12 pjp
2028 2540a41a 2014-04-12 pjp for (i = 0; i < strlen(name); i++) {
2029 27110135 2014-11-07 pjp name[i] = tolower((int)name[i]);
2030 2540a41a 2014-04-12 pjp }
2031 2540a41a 2014-04-12 pjp
2032 2540a41a 2014-04-12 pjp converted_name = check_rr(name, type, DNS_TYPE_SRV, &converted_namelen);
2033 2540a41a 2014-04-12 pjp if (converted_name == NULL) {
2034 2540a41a 2014-04-12 pjp return -1;
2035 2540a41a 2014-04-12 pjp }
2036 2540a41a 2014-04-12 pjp
2037 2540a41a 2014-04-12 pjp memset(&sdomain, 0, sizeof(sdomain));
2038 2540a41a 2014-04-12 pjp if (get_record(&sdomain, converted_name, converted_namelen) < 0) {
2039 2540a41a 2014-04-12 pjp return (-1);
2040 2540a41a 2014-04-12 pjp }
2041 2540a41a 2014-04-12 pjp
2042 2540a41a 2014-04-12 pjp #ifdef __linux__
2043 35d93ac7 2014-04-13 pjp strncpy((char *)sdomain.zonename, (char *)name, DNS_MAXNAME + 1);
2044 2540a41a 2014-04-12 pjp sdomain.zonename[DNS_MAXNAME] = '\0';
2045 2540a41a 2014-04-12 pjp #else
2046 35d93ac7 2014-04-13 pjp strlcpy((char *)sdomain.zonename, (char *)name, DNS_MAXNAME + 1);
2047 2540a41a 2014-04-12 pjp #endif
2048 2540a41a 2014-04-12 pjp memcpy(sdomain.zone, converted_name, converted_namelen);
2049 2540a41a 2014-04-12 pjp sdomain.zonelen = converted_namelen;
2050 2540a41a 2014-04-12 pjp
2051 2540a41a 2014-04-12 pjp if (sdomain.srv_count >= RECORD_COUNT) {
2052 2540a41a 2014-04-12 pjp dolog(LOG_INFO, "%s: too many SRV records for zone \"%s\", skipping line %d\n", file->name, name, file->lineno);
2053 2540a41a 2014-04-12 pjp return (-1);
2054 2540a41a 2014-04-12 pjp }
2055 2540a41a 2014-04-12 pjp
2056 2540a41a 2014-04-12 pjp sdomain.ttl = myttl;
2057 2540a41a 2014-04-12 pjp
2058 2540a41a 2014-04-12 pjp sdomain.srv[sdomain.srv_count].priority = priority;
2059 2540a41a 2014-04-12 pjp sdomain.srv[sdomain.srv_count].weight = weight;
2060 2540a41a 2014-04-12 pjp sdomain.srv[sdomain.srv_count].port = port;
2061 2540a41a 2014-04-12 pjp
2062 2540a41a 2014-04-12 pjp srvname = dns_label(srvhost, &len);
2063 2540a41a 2014-04-12 pjp if (srvname == NULL) {
2064 2540a41a 2014-04-12 pjp dolog(LOG_INFO, "illegal srv server, skipping line %d\n", file->lineno);
2065 2540a41a 2014-04-12 pjp return (-1);
2066 2540a41a 2014-04-12 pjp }
2067 2540a41a 2014-04-12 pjp
2068 2540a41a 2014-04-12 pjp
2069 2540a41a 2014-04-12 pjp sdomain.srv[sdomain.srv_count].targetlen = len;
2070 2540a41a 2014-04-12 pjp memcpy((char *)&sdomain.srv[sdomain.srv_count].target, srvname, len);
2071 2540a41a 2014-04-12 pjp
2072 2540a41a 2014-04-12 pjp /* bad hack workaround !!! */
2073 2540a41a 2014-04-12 pjp if (strcmp(srvhost, ".") == 0 && len > 1)
2074 2540a41a 2014-04-12 pjp sdomain.srv[sdomain.srv_count].targetlen = 1;
2075 2540a41a 2014-04-12 pjp
2076 2540a41a 2014-04-12 pjp free (srvname);
2077 2540a41a 2014-04-12 pjp
2078 2540a41a 2014-04-12 pjp sdomain.srv_count++;
2079 2540a41a 2014-04-12 pjp
2080 2540a41a 2014-04-12 pjp sdomain.flags |= DOMAIN_HAVE_SRV;
2081 2540a41a 2014-04-12 pjp
2082 2540a41a 2014-04-12 pjp set_record(&sdomain, converted_name, converted_namelen);
2083 2540a41a 2014-04-12 pjp
2084 2540a41a 2014-04-12 pjp if (converted_name)
2085 2540a41a 2014-04-12 pjp free (converted_name);
2086 2540a41a 2014-04-12 pjp
2087 2540a41a 2014-04-12 pjp return (0);
2088 2540a41a 2014-04-12 pjp
2089 2540a41a 2014-04-12 pjp }
2090 2540a41a 2014-04-12 pjp
2091 2540a41a 2014-04-12 pjp int
2092 2540a41a 2014-04-12 pjp fill_mx(char *name, char *type, int myttl, int priority, char *mxhost)
2093 2540a41a 2014-04-12 pjp {
2094 2540a41a 2014-04-12 pjp struct domain sdomain;
2095 2540a41a 2014-04-12 pjp int converted_namelen;
2096 2540a41a 2014-04-12 pjp char *converted_name;
2097 2540a41a 2014-04-12 pjp char *mxname;
2098 2540a41a 2014-04-12 pjp int len, i;
2099 2540a41a 2014-04-12 pjp
2100 2540a41a 2014-04-12 pjp for (i = 0; i < strlen(name); i++) {
2101 27110135 2014-11-07 pjp name[i] = tolower((int)name[i]);
2102 2540a41a 2014-04-12 pjp }
2103 2540a41a 2014-04-12 pjp
2104 2540a41a 2014-04-12 pjp converted_name = check_rr(name, type, DNS_TYPE_MX, &converted_namelen);
2105 2540a41a 2014-04-12 pjp if (converted_name == NULL) {
2106 2540a41a 2014-04-12 pjp return -1;
2107 2540a41a 2014-04-12 pjp }
2108 2540a41a 2014-04-12 pjp
2109 2540a41a 2014-04-12 pjp memset(&sdomain, 0, sizeof(sdomain));
2110 2540a41a 2014-04-12 pjp if (get_record(&sdomain, converted_name, converted_namelen) < 0) {
2111 2540a41a 2014-04-12 pjp return (-1);
2112 2540a41a 2014-04-12 pjp }
2113 2540a41a 2014-04-12 pjp
2114 2540a41a 2014-04-12 pjp #ifdef __linux__
2115 35d93ac7 2014-04-13 pjp strncpy((char *)sdomain.zonename, (char *)name, DNS_MAXNAME + 1);
2116 2540a41a 2014-04-12 pjp sdomain.zonename[DNS_MAXNAME] = '\0';
2117 2540a41a 2014-04-12 pjp #else
2118 35d93ac7 2014-04-13 pjp strlcpy((char *)sdomain.zonename, (char *)name, DNS_MAXNAME + 1);
2119 2540a41a 2014-04-12 pjp #endif
2120 2540a41a 2014-04-12 pjp memcpy(sdomain.zone, converted_name, converted_namelen);
2121 2540a41a 2014-04-12 pjp sdomain.zonelen = converted_namelen;
2122 2540a41a 2014-04-12 pjp
2123 2540a41a 2014-04-12 pjp if (sdomain.mx_count >= RECORD_COUNT) {
2124 6a6113d4 2014-04-13 pjp dolog(LOG_INFO, "%s: too many MX records for zone \"%s\", skipping line %d\n", file->name, name, file->lineno);
2125 2540a41a 2014-04-12 pjp return (-1);
2126 2540a41a 2014-04-12 pjp }
2127 2540a41a 2014-04-12 pjp
2128 2540a41a 2014-04-12 pjp sdomain.ttl = myttl;
2129 2540a41a 2014-04-12 pjp sdomain.mx[sdomain.mx_count].preference = priority;
2130 2540a41a 2014-04-12 pjp
2131 2540a41a 2014-04-12 pjp mxname = dns_label(mxhost, &len);
2132 2540a41a 2014-04-12 pjp if (mxname == NULL) {
2133 2540a41a 2014-04-12 pjp dolog(LOG_INFO, "illegal mx server, skipping line %d\n", file->lineno);
2134 2540a41a 2014-04-12 pjp return (-1);
2135 2540a41a 2014-04-12 pjp }
2136 2540a41a 2014-04-12 pjp
2137 2540a41a 2014-04-12 pjp sdomain.mx[sdomain.mx_count].exchangelen = len;
2138 2540a41a 2014-04-12 pjp memcpy((char *)&sdomain.mx[sdomain.mx_count].exchange, mxname, len);
2139 2540a41a 2014-04-12 pjp free (mxname);
2140 2540a41a 2014-04-12 pjp
2141 2540a41a 2014-04-12 pjp sdomain.mx_count++;
2142 2540a41a 2014-04-12 pjp
2143 2540a41a 2014-04-12 pjp sdomain.flags |= DOMAIN_HAVE_MX;
2144 2540a41a 2014-04-12 pjp
2145 2540a41a 2014-04-12 pjp set_record(&sdomain, converted_name, converted_namelen);
2146 2540a41a 2014-04-12 pjp
2147 2540a41a 2014-04-12 pjp if (converted_name)
2148 2540a41a 2014-04-12 pjp free (converted_name);
2149 2540a41a 2014-04-12 pjp
2150 2540a41a 2014-04-12 pjp return (0);
2151 2540a41a 2014-04-12 pjp
2152 2540a41a 2014-04-12 pjp }
2153 2540a41a 2014-04-12 pjp
2154 2540a41a 2014-04-12 pjp int
2155 2540a41a 2014-04-12 pjp fill_balance(char *name, char *type, int myttl, char *a)
2156 2540a41a 2014-04-12 pjp {
2157 2540a41a 2014-04-12 pjp struct domain sdomain;
2158 2540a41a 2014-04-12 pjp int converted_namelen;
2159 2540a41a 2014-04-12 pjp char *converted_name;
2160 2540a41a 2014-04-12 pjp struct sockaddr_in sin;
2161 2540a41a 2014-04-12 pjp in_addr_t *ia;
2162 2540a41a 2014-04-12 pjp int i;
2163 2540a41a 2014-04-12 pjp
2164 2540a41a 2014-04-12 pjp for (i = 0; i < strlen(name); i++) {
2165 27110135 2014-11-07 pjp name[i] = tolower((int)name[i]);
2166 2540a41a 2014-04-12 pjp }
2167 2540a41a 2014-04-12 pjp
2168 2540a41a 2014-04-12 pjp converted_name = check_rr(name, type, DNS_TYPE_BALANCE, &converted_namelen);
2169 2540a41a 2014-04-12 pjp if (converted_name == NULL) {
2170 2540a41a 2014-04-12 pjp return -1;
2171 2540a41a 2014-04-12 pjp }
2172 2540a41a 2014-04-12 pjp
2173 2540a41a 2014-04-12 pjp memset(&sdomain, 0, sizeof(sdomain));
2174 2540a41a 2014-04-12 pjp if (get_record(&sdomain, converted_name, converted_namelen) < 0) {
2175 2540a41a 2014-04-12 pjp return (-1);
2176 2540a41a 2014-04-12 pjp }
2177 2540a41a 2014-04-12 pjp
2178 2540a41a 2014-04-12 pjp #ifdef __linux__
2179 35d93ac7 2014-04-13 pjp strncpy((char *)sdomain.zonename, (char *)name, DNS_MAXNAME + 1);
2180 2540a41a 2014-04-12 pjp sdomain.zonename[DNS_MAXNAME] = '\0';
2181 2540a41a 2014-04-12 pjp #else
2182 35d93ac7 2014-04-13 pjp strlcpy((char *)sdomain.zonename, (char *)name, DNS_MAXNAME + 1);
2183 2540a41a 2014-04-12 pjp #endif
2184 2540a41a 2014-04-12 pjp memcpy(sdomain.zone, converted_name, converted_namelen);
2185 2540a41a 2014-04-12 pjp sdomain.zonelen = converted_namelen;
2186 2540a41a 2014-04-12 pjp
2187 2540a41a 2014-04-12 pjp if (sdomain.a_count >= RECORD_COUNT) {
2188 2540a41a 2014-04-12 pjp dolog(LOG_INFO, "%s: too many BALANCE records for zone \"%s\", skipping line %d\n", file->name, name, file->lineno);
2189 2540a41a 2014-04-12 pjp return (-1);
2190 2540a41a 2014-04-12 pjp }
2191 2540a41a 2014-04-12 pjp
2192 2540a41a 2014-04-12 pjp sdomain.ttl = myttl;
2193 2540a41a 2014-04-12 pjp ia = (in_addr_t *)&sdomain.a[sdomain.a_count];
2194 2540a41a 2014-04-12 pjp
2195 2540a41a 2014-04-12 pjp if ((*ia = inet_addr(a)) == INADDR_ANY) {
2196 2540a41a 2014-04-12 pjp dolog(LOG_INFO, "could not parse BALANCE record on line %d\n", file->lineno);
2197 2540a41a 2014-04-12 pjp return (-1);
2198 2540a41a 2014-04-12 pjp }
2199 2540a41a 2014-04-12 pjp
2200 2540a41a 2014-04-12 pjp
2201 2540a41a 2014-04-12 pjp memset(&sin, 0, sizeof(sin));
2202 2540a41a 2014-04-12 pjp sin.sin_addr.s_addr = *ia;
2203 2540a41a 2014-04-12 pjp sin.sin_family = AF_INET;
2204 2540a41a 2014-04-12 pjp sdomain.region[sdomain.a_count] = find_region((struct sockaddr_storage *)&sin, AF_INET);
2205 2540a41a 2014-04-12 pjp
2206 2540a41a 2014-04-12 pjp sdomain.a_count++;
2207 2540a41a 2014-04-12 pjp sdomain.a_ptr = 0;
2208 2540a41a 2014-04-12 pjp
2209 2540a41a 2014-04-12 pjp sdomain.flags |= DOMAIN_HAVE_A;
2210 2540a41a 2014-04-12 pjp
2211 2540a41a 2014-04-12 pjp set_record(&sdomain, converted_name, converted_namelen);
2212 2540a41a 2014-04-12 pjp
2213 2540a41a 2014-04-12 pjp if (converted_name)
2214 2540a41a 2014-04-12 pjp free (converted_name);
2215 2540a41a 2014-04-12 pjp
2216 2540a41a 2014-04-12 pjp return (0);
2217 2540a41a 2014-04-12 pjp
2218 2540a41a 2014-04-12 pjp }
2219 2540a41a 2014-04-12 pjp
2220 2540a41a 2014-04-12 pjp int
2221 2540a41a 2014-04-12 pjp fill_a(char *name, char *type, int myttl, char *a)
2222 2540a41a 2014-04-12 pjp {
2223 2540a41a 2014-04-12 pjp struct domain sdomain;
2224 2540a41a 2014-04-12 pjp int converted_namelen;
2225 2540a41a 2014-04-12 pjp char *converted_name;
2226 2540a41a 2014-04-12 pjp in_addr_t *ia;
2227 2540a41a 2014-04-12 pjp int i;
2228 2540a41a 2014-04-12 pjp
2229 2540a41a 2014-04-12 pjp for (i = 0; i < strlen(name); i++) {
2230 27110135 2014-11-07 pjp name[i] = tolower((int)name[i]);
2231 2540a41a 2014-04-12 pjp }
2232 2540a41a 2014-04-12 pjp
2233 2540a41a 2014-04-12 pjp converted_name = check_rr(name, type, DNS_TYPE_A, &converted_namelen);
2234 2540a41a 2014-04-12 pjp if (converted_name == NULL) {
2235 2540a41a 2014-04-12 pjp return -1;
2236 2540a41a 2014-04-12 pjp }
2237 2540a41a 2014-04-12 pjp
2238 2540a41a 2014-04-12 pjp memset(&sdomain, 0, sizeof(sdomain));
2239 2540a41a 2014-04-12 pjp if (get_record(&sdomain, converted_name, converted_namelen) < 0) {
2240 2540a41a 2014-04-12 pjp return (-1);
2241 2540a41a 2014-04-12 pjp }
2242 2540a41a 2014-04-12 pjp
2243 2540a41a 2014-04-12 pjp #ifdef __linux__
2244 35d93ac7 2014-04-13 pjp strncpy((char *)sdomain.zonename, (char *)name, DNS_MAXNAME + 1);
2245 2540a41a 2014-04-12 pjp sdomain.zonename[DNS_MAXNAME] = '\0';
2246 2540a41a 2014-04-12 pjp #else
2247 35d93ac7 2014-04-13 pjp strlcpy((char *)sdomain.zonename, (char *)name, DNS_MAXNAME + 1);
2248 2540a41a 2014-04-12 pjp #endif
2249 2540a41a 2014-04-12 pjp memcpy(sdomain.zone, converted_name, converted_namelen);
2250 2540a41a 2014-04-12 pjp sdomain.zonelen = converted_namelen;
2251 2540a41a 2014-04-12 pjp
2252 2540a41a 2014-04-12 pjp if (sdomain.a_count >= RECORD_COUNT) {
2253 2540a41a 2014-04-12 pjp dolog(LOG_INFO, "%s: too many A records for zone \"%s\", skipping line %d\n", file->name, name, file->lineno);
2254 2540a41a 2014-04-12 pjp return (-1);
2255 2540a41a 2014-04-12 pjp }
2256 2540a41a 2014-04-12 pjp
2257 2540a41a 2014-04-12 pjp sdomain.ttl = myttl;
2258 2540a41a 2014-04-12 pjp ia = (in_addr_t *)&sdomain.a[sdomain.a_count];
2259 2540a41a 2014-04-12 pjp
2260 2540a41a 2014-04-12 pjp if ((*ia = inet_addr(a)) == INADDR_ANY) {
2261 2540a41a 2014-04-12 pjp dolog(LOG_INFO, "could not parse A record on line %d\n", file->lineno);
2262 2540a41a 2014-04-12 pjp return (-1);
2263 2540a41a 2014-04-12 pjp }
2264 2540a41a 2014-04-12 pjp
2265 2540a41a 2014-04-12 pjp sdomain.region[sdomain.a_count] = 0xff;
2266 2540a41a 2014-04-12 pjp
2267 2540a41a 2014-04-12 pjp sdomain.a_count++;
2268 2540a41a 2014-04-12 pjp sdomain.a_ptr = 0;
2269 2540a41a 2014-04-12 pjp
2270 2540a41a 2014-04-12 pjp sdomain.flags |= DOMAIN_HAVE_A;
2271 2540a41a 2014-04-12 pjp
2272 2540a41a 2014-04-12 pjp set_record(&sdomain, converted_name, converted_namelen);
2273 2540a41a 2014-04-12 pjp
2274 2540a41a 2014-04-12 pjp if (converted_name)
2275 2540a41a 2014-04-12 pjp free (converted_name);
2276 2540a41a 2014-04-12 pjp
2277 2540a41a 2014-04-12 pjp return (0);
2278 2540a41a 2014-04-12 pjp
2279 2540a41a 2014-04-12 pjp }
2280 2540a41a 2014-04-12 pjp
2281 2540a41a 2014-04-12 pjp
2282 2540a41a 2014-04-12 pjp int
2283 2540a41a 2014-04-12 pjp fill_aaaa(char *name, char *type, int myttl, char *aaaa)
2284 2540a41a 2014-04-12 pjp {
2285 2540a41a 2014-04-12 pjp struct domain sdomain;
2286 2540a41a 2014-04-12 pjp int converted_namelen;
2287 2540a41a 2014-04-12 pjp char *converted_name;
2288 2540a41a 2014-04-12 pjp struct in6_addr *ia6;
2289 2540a41a 2014-04-12 pjp int i;
2290 2540a41a 2014-04-12 pjp
2291 2540a41a 2014-04-12 pjp
2292 2540a41a 2014-04-12 pjp for (i = 0; i < strlen(name); i++) {
2293 27110135 2014-11-07 pjp name[i] = tolower((int)name[i]);
2294 2540a41a 2014-04-12 pjp }
2295 2540a41a 2014-04-12 pjp
2296 2540a41a 2014-04-12 pjp converted_name = check_rr(name, type, DNS_TYPE_AAAA, &converted_namelen);
2297 2540a41a 2014-04-12 pjp if (converted_name == NULL) {
2298 2540a41a 2014-04-12 pjp return -1;
2299 2540a41a 2014-04-12 pjp }
2300 2540a41a 2014-04-12 pjp
2301 2540a41a 2014-04-12 pjp memset(&sdomain, 0, sizeof(sdomain));
2302 2540a41a 2014-04-12 pjp if (get_record(&sdomain, converted_name, converted_namelen) < 0) {
2303 2540a41a 2014-04-12 pjp return (-1);
2304 2540a41a 2014-04-12 pjp }
2305 2540a41a 2014-04-12 pjp
2306 2540a41a 2014-04-12 pjp #ifdef __linux__
2307 35d93ac7 2014-04-13 pjp strncpy((char *)sdomain.zonename, (char *)name, DNS_MAXNAME + 1);
2308 2540a41a 2014-04-12 pjp sdomain.zonename[DNS_MAXNAME] = '\0';
2309 2540a41a 2014-04-12 pjp #else
2310 35d93ac7 2014-04-13 pjp strlcpy((char *)sdomain.zonename, (char *)name, DNS_MAXNAME + 1);
2311 2540a41a 2014-04-12 pjp #endif
2312 2540a41a 2014-04-12 pjp memcpy(sdomain.zone, converted_name, converted_namelen);
2313 2540a41a 2014-04-12 pjp sdomain.zonelen = converted_namelen;
2314 2540a41a 2014-04-12 pjp
2315 2540a41a 2014-04-12 pjp if (sdomain.aaaa_count >= RECORD_COUNT) {
2316 6a6113d4 2014-04-13 pjp dolog(LOG_INFO, "%s: too many AAAA records for zone \"%s\", skipping line %d\n", file->name, name, file->lineno);
2317 2540a41a 2014-04-12 pjp return (-1);
2318 2540a41a 2014-04-12 pjp }
2319 2540a41a 2014-04-12 pjp
2320 2540a41a 2014-04-12 pjp sdomain.ttl = myttl;
2321 2540a41a 2014-04-12 pjp ia6 = (struct in6_addr *)&sdomain.aaaa[sdomain.aaaa_count];
2322 2540a41a 2014-04-12 pjp if (inet_pton(AF_INET6, (char *)aaaa, (char *)ia6) != 1) {
2323 6a6113d4 2014-04-13 pjp dolog(LOG_INFO, "AAAA \"%s\" unparseable line %d\n", aaaa, file->lineno);
2324 2540a41a 2014-04-12 pjp return -1;
2325 2540a41a 2014-04-12 pjp }
2326 2540a41a 2014-04-12 pjp
2327 2540a41a 2014-04-12 pjp sdomain.aaaa_count++;
2328 2540a41a 2014-04-12 pjp sdomain.aaaa_ptr = 0;
2329 2540a41a 2014-04-12 pjp
2330 2540a41a 2014-04-12 pjp sdomain.flags |= DOMAIN_HAVE_AAAA;
2331 2540a41a 2014-04-12 pjp
2332 2540a41a 2014-04-12 pjp set_record(&sdomain, converted_name, converted_namelen);
2333 2540a41a 2014-04-12 pjp
2334 2540a41a 2014-04-12 pjp if (converted_name)
2335 2540a41a 2014-04-12 pjp free (converted_name);
2336 2540a41a 2014-04-12 pjp
2337 2540a41a 2014-04-12 pjp return (0);
2338 2540a41a 2014-04-12 pjp
2339 2540a41a 2014-04-12 pjp }
2340 2540a41a 2014-04-12 pjp
2341 2540a41a 2014-04-12 pjp
2342 2540a41a 2014-04-12 pjp int
2343 2540a41a 2014-04-12 pjp fill_ns(char *name, char *type, int myttl, char *nameserver)
2344 2540a41a 2014-04-12 pjp {
2345 2540a41a 2014-04-12 pjp struct domain sdomain;
2346 2540a41a 2014-04-12 pjp int len, converted_namelen;
2347 2540a41a 2014-04-12 pjp char *myname, *converted_name;
2348 2540a41a 2014-04-12 pjp char *n;
2349 2540a41a 2014-04-12 pjp int nstype, i;
2350 2540a41a 2014-04-12 pjp
2351 2540a41a 2014-04-12 pjp
2352 2540a41a 2014-04-12 pjp for (i = 0; i < strlen(name); i++) {
2353 27110135 2014-11-07 pjp name[i] = tolower((int)name[i]);
2354 2540a41a 2014-04-12 pjp }
2355 2540a41a 2014-04-12 pjp
2356 2540a41a 2014-04-12 pjp if (strcasecmp(type, "ns") == 0) {
2357 2540a41a 2014-04-12 pjp converted_name = check_rr(name, type, DNS_TYPE_NS, &converted_namelen);
2358 2540a41a 2014-04-12 pjp nstype = 0;
2359 2540a41a 2014-04-12 pjp } else if (strcasecmp(type, "hint") == 0) {
2360 2540a41a 2014-04-12 pjp converted_name = check_rr(name, type, DNS_TYPE_HINT, &converted_namelen);
2361 2540a41a 2014-04-12 pjp nstype = NS_TYPE_HINT;
2362 2540a41a 2014-04-12 pjp } else {
2363 2540a41a 2014-04-12 pjp converted_name = check_rr(name, type, DNS_TYPE_DELEGATE, &converted_namelen);
2364 2540a41a 2014-04-12 pjp nstype = NS_TYPE_DELEGATE;
2365 2540a41a 2014-04-12 pjp }
2366 2540a41a 2014-04-12 pjp
2367 2540a41a 2014-04-12 pjp if (converted_name == NULL) {
2368 2540a41a 2014-04-12 pjp return -1;
2369 2540a41a 2014-04-12 pjp }
2370 2540a41a 2014-04-12 pjp
2371 2540a41a 2014-04-12 pjp memset(&sdomain, 0, sizeof(sdomain));
2372 2540a41a 2014-04-12 pjp if (get_record(&sdomain, converted_name, converted_namelen) < 0) {
2373 2540a41a 2014-04-12 pjp return (-1);
2374 2540a41a 2014-04-12 pjp }
2375 2540a41a 2014-04-12 pjp
2376 2540a41a 2014-04-12 pjp #ifdef __linux__
2377 35d93ac7 2014-04-13 pjp strncpy((char *)sdomain.zonename, (char *)name, DNS_MAXNAME + 1);
2378 2540a41a 2014-04-12 pjp sdomain.zonename[DNS_MAXNAME] = '\0';
2379 2540a41a 2014-04-12 pjp #else
2380 35d93ac7 2014-04-13 pjp strlcpy((char *)sdomain.zonename, (char *)name, DNS_MAXNAME + 1);
2381 2540a41a 2014-04-12 pjp #endif
2382 2540a41a 2014-04-12 pjp memcpy(sdomain.zone, converted_name, converted_namelen);
2383 2540a41a 2014-04-12 pjp sdomain.zonelen = converted_namelen;
2384 2540a41a 2014-04-12 pjp
2385 2540a41a 2014-04-12 pjp if (sdomain.ns_count >= RECORD_COUNT) {
2386 6a6113d4 2014-04-13 pjp dolog(LOG_INFO, "%s: too many NS records for zone \"%s\", skipping line %d\n", file->name, name, file->lineno);
2387 2540a41a 2014-04-12 pjp return (-1);
2388 2540a41a 2014-04-12 pjp }
2389 2540a41a 2014-04-12 pjp
2390 2540a41a 2014-04-12 pjp sdomain.ttl = myttl;
2391 2540a41a 2014-04-12 pjp
2392 2540a41a 2014-04-12 pjp myname = dns_label(nameserver, (int *)&len);
2393 2540a41a 2014-04-12 pjp if (myname == NULL) {
2394 2540a41a 2014-04-12 pjp dolog(LOG_INFO, "illegal nameserver, skipping line %d\n", file->lineno);
2395 2540a41a 2014-04-12 pjp return 0;
2396 2540a41a 2014-04-12 pjp }
2397 2540a41a 2014-04-12 pjp
2398 2540a41a 2014-04-12 pjp if (len > 0xff || len < 0) {
2399 2540a41a 2014-04-12 pjp dolog(LOG_INFO, "illegal len value , line %d\n", file->lineno);
2400 2540a41a 2014-04-12 pjp return -1;
2401 2540a41a 2014-04-12 pjp }
2402 2540a41a 2014-04-12 pjp
2403 2540a41a 2014-04-12 pjp n = (char *)sdomain.ns[sdomain.ns_count].nsserver;
2404 2540a41a 2014-04-12 pjp sdomain.ns[sdomain.ns_count].nslen = len;
2405 2540a41a 2014-04-12 pjp memcpy((char *)n, myname, sdomain.ns[sdomain.ns_count].nslen);
2406 2540a41a 2014-04-12 pjp
2407 2540a41a 2014-04-12 pjp free(myname);
2408 2540a41a 2014-04-12 pjp
2409 2540a41a 2014-04-12 pjp sdomain.ns_count++;
2410 2540a41a 2014-04-12 pjp sdomain.ns_ptr = 0;
2411 2540a41a 2014-04-12 pjp sdomain.ns_type = nstype;
2412 2540a41a 2014-04-12 pjp
2413 2540a41a 2014-04-12 pjp sdomain.flags |= DOMAIN_HAVE_NS;
2414 2540a41a 2014-04-12 pjp
2415 2540a41a 2014-04-12 pjp set_record(&sdomain, converted_name, converted_namelen);
2416 2540a41a 2014-04-12 pjp
2417 2540a41a 2014-04-12 pjp if (converted_name)
2418 2540a41a 2014-04-12 pjp free (converted_name);
2419 2540a41a 2014-04-12 pjp
2420 2540a41a 2014-04-12 pjp return (0);
2421 2540a41a 2014-04-12 pjp
2422 2540a41a 2014-04-12 pjp }
2423 2540a41a 2014-04-12 pjp
2424 2540a41a 2014-04-12 pjp
2425 2540a41a 2014-04-12 pjp /* centroid.eu,soa,3600,uranus.centroid.eu.,pjp.solarscale.de.,1258740680,3600,1800,7200,3600 */
2426 2540a41a 2014-04-12 pjp int
2427 2540a41a 2014-04-12 pjp fill_soa(char *name, char *type, int myttl, char *auth, char *contact, int serial, int retry, int refresh, int expire, int ttl)
2428 2540a41a 2014-04-12 pjp {
2429 2540a41a 2014-04-12 pjp struct domain sdomain;
2430 2540a41a 2014-04-12 pjp int len, converted_namelen;
2431 2540a41a 2014-04-12 pjp char *myname, *converted_name;
2432 2540a41a 2014-04-12 pjp int i;
2433 2540a41a 2014-04-12 pjp
2434 2540a41a 2014-04-12 pjp for (i = 0; i < strlen(name); i++) {
2435 27110135 2014-11-07 pjp name[i] = tolower((int)name[i]);
2436 2540a41a 2014-04-12 pjp }
2437 2540a41a 2014-04-12 pjp
2438 2540a41a 2014-04-12 pjp converted_name = check_rr(name, type, DNS_TYPE_SOA, &converted_namelen);
2439 2540a41a 2014-04-12 pjp if (converted_name == NULL) {
2440 2540a41a 2014-04-12 pjp dolog(LOG_ERR, "error input line %d\n", file->lineno);
2441 2540a41a 2014-04-12 pjp return (-1);
2442 2540a41a 2014-04-12 pjp }
2443 2540a41a 2014-04-12 pjp
2444 2540a41a 2014-04-12 pjp memset(&sdomain, 0, sizeof(sdomain));
2445 2540a41a 2014-04-12 pjp if (get_record(&sdomain, converted_name, converted_namelen) < 0) {
2446 2540a41a 2014-04-12 pjp return (-1);
2447 2540a41a 2014-04-12 pjp }
2448 2540a41a 2014-04-12 pjp
2449 2540a41a 2014-04-12 pjp #ifdef __linux__
2450 35d93ac7 2014-04-13 pjp strncpy((char *)sdomain.zonename, (char *)name, DNS_MAXNAME + 1);
2451 2540a41a 2014-04-12 pjp sdomain.zonename[DNS_MAXNAME] = '\0';
2452 2540a41a 2014-04-12 pjp #else
2453 35d93ac7 2014-04-13 pjp strlcpy((char *)sdomain.zonename, (char *)name, DNS_MAXNAME + 1);
2454 2540a41a 2014-04-12 pjp #endif
2455 2540a41a 2014-04-12 pjp memcpy(sdomain.zone, converted_name, converted_namelen);
2456 2540a41a 2014-04-12 pjp sdomain.zonelen = converted_namelen;
2457 2540a41a 2014-04-12 pjp
2458 2540a41a 2014-04-12 pjp sdomain.ttl = myttl;
2459 2540a41a 2014-04-12 pjp
2460 2540a41a 2014-04-12 pjp myname = dns_label(auth, (int *)&len);
2461 2540a41a 2014-04-12 pjp if (myname == NULL) {
2462 2540a41a 2014-04-12 pjp dolog(LOG_INFO, "illegal nameserver, skipping line %d\n", file->lineno);
2463 2540a41a 2014-04-12 pjp return 0;
2464 2540a41a 2014-04-12 pjp }
2465 2540a41a 2014-04-12 pjp
2466 2540a41a 2014-04-12 pjp if (len > 0xff || len < 0) {
2467 2540a41a 2014-04-12 pjp dolog(LOG_INFO, "illegal len value , line %d\n", file->lineno);
2468 2540a41a 2014-04-12 pjp return -1;
2469 2540a41a 2014-04-12 pjp }
2470 2540a41a 2014-04-12 pjp
2471 2540a41a 2014-04-12 pjp sdomain.soa.nsserver_len = len;
2472 2540a41a 2014-04-12 pjp memcpy((char *)&sdomain.soa.nsserver[0], myname, len);
2473 2540a41a 2014-04-12 pjp
2474 2540a41a 2014-04-12 pjp free(myname);
2475 2540a41a 2014-04-12 pjp
2476 2540a41a 2014-04-12 pjp myname = dns_label(contact, (int *)&len);
2477 2540a41a 2014-04-12 pjp if (myname == NULL) {
2478 2540a41a 2014-04-12 pjp dolog(LOG_INFO, "illegal nameserver, skipping line %d\n", file->lineno);
2479 2540a41a 2014-04-12 pjp return 0;
2480 2540a41a 2014-04-12 pjp }
2481 2540a41a 2014-04-12 pjp
2482 2540a41a 2014-04-12 pjp if (len > 0xff || len < 0) {
2483 2540a41a 2014-04-12 pjp dolog(LOG_INFO, "illegal len value , line %d\n", file->lineno);
2484 2540a41a 2014-04-12 pjp return -1;
2485 2540a41a 2014-04-12 pjp }
2486 2540a41a 2014-04-12 pjp
2487 2540a41a 2014-04-12 pjp sdomain.soa.rp_len = len;
2488 2540a41a 2014-04-12 pjp memcpy((char *)&sdomain.soa.responsible_person[0], myname, len);
2489 2540a41a 2014-04-12 pjp
2490 2540a41a 2014-04-12 pjp free (myname);
2491 2540a41a 2014-04-12 pjp
2492 2540a41a 2014-04-12 pjp sdomain.soa.serial = serial;
2493 2540a41a 2014-04-12 pjp sdomain.soa.refresh = refresh;
2494 2540a41a 2014-04-12 pjp sdomain.soa.retry = retry;
2495 2540a41a 2014-04-12 pjp sdomain.soa.expire = expire;
2496 2540a41a 2014-04-12 pjp sdomain.soa.minttl = ttl;
2497 2540a41a 2014-04-12 pjp
2498 2540a41a 2014-04-12 pjp sdomain.flags |= DOMAIN_HAVE_SOA;
2499 2540a41a 2014-04-12 pjp
2500 2540a41a 2014-04-12 pjp set_record(&sdomain, converted_name, converted_namelen);
2501 2540a41a 2014-04-12 pjp
2502 2540a41a 2014-04-12 pjp if (converted_name)
2503 2540a41a 2014-04-12 pjp free (converted_name);
2504 2540a41a 2014-04-12 pjp
2505 2540a41a 2014-04-12 pjp return (0);
2506 2540a41a 2014-04-12 pjp
2507 2540a41a 2014-04-12 pjp }
2508 2540a41a 2014-04-12 pjp
2509 2540a41a 2014-04-12 pjp
2510 2540a41a 2014-04-12 pjp int
2511 2540a41a 2014-04-12 pjp get_record(struct domain *sdomain, char *converted_name, int converted_namelen)
2512 2540a41a 2014-04-12 pjp {
2513 2540a41a 2014-04-12 pjp DB *db = mydb; /* XXX */
2514 2540a41a 2014-04-12 pjp
2515 2540a41a 2014-04-12 pjp memset(&key, 0, sizeof(key));
2516 2540a41a 2014-04-12 pjp memset(&data, 0, sizeof(data));
2517 2540a41a 2014-04-12 pjp
2518 2540a41a 2014-04-12 pjp key.data = (char *)converted_name;
2519 2540a41a 2014-04-12 pjp key.size = converted_namelen;
2520 2540a41a 2014-04-12 pjp
2521 2540a41a 2014-04-12 pjp data.data = NULL;
2522 2540a41a 2014-04-12 pjp data.size = 0;
2523 2540a41a 2014-04-12 pjp
2524 2540a41a 2014-04-12 pjp if (db->get(db, NULL, &key, &data, 0) == 0) {
2525 22a36b57 2014-05-18 pjp
2526 2540a41a 2014-04-12 pjp if (data.size != sizeof(struct domain)) {
2527 2540a41a 2014-04-12 pjp dolog(LOG_INFO, "damaged btree database\n");
2528 2540a41a 2014-04-12 pjp return -1;
2529 2540a41a 2014-04-12 pjp }
2530 2540a41a 2014-04-12 pjp
2531 2540a41a 2014-04-12 pjp memcpy((char *)sdomain, (char *)data.data, data.size);
2532 2540a41a 2014-04-12 pjp } else {
2533 6a6113d4 2014-04-13 pjp if (debug)
2534 6a6113d4 2014-04-13 pjp dolog(LOG_INFO, "db->get: %s\n", strerror(errno));
2535 2540a41a 2014-04-12 pjp }
2536 2540a41a 2014-04-12 pjp
2537 2540a41a 2014-04-12 pjp return 0;
2538 2540a41a 2014-04-12 pjp }
2539 2540a41a 2014-04-12 pjp
2540 2540a41a 2014-04-12 pjp
2541 2540a41a 2014-04-12 pjp void
2542 2540a41a 2014-04-12 pjp set_record(struct domain *sdomain, char *converted_name, int converted_namelen)
2543 2540a41a 2014-04-12 pjp {
2544 2540a41a 2014-04-12 pjp DB *db = mydb; /* XXX */
2545 2540a41a 2014-04-12 pjp int ret;
2546 2540a41a 2014-04-12 pjp
2547 2540a41a 2014-04-12 pjp /* everythign in parse.y should get this flag! */
2548 2540a41a 2014-04-12 pjp sdomain->flags |= DOMAIN_STATIC_ZONE;
2549 2540a41a 2014-04-12 pjp
2550 2540a41a 2014-04-12 pjp memset(&key, 0, sizeof(key));
2551 2540a41a 2014-04-12 pjp memset(&data, 0, sizeof(data));
2552 2540a41a 2014-04-12 pjp
2553 2540a41a 2014-04-12 pjp key.data = (char *)converted_name;
2554 2540a41a 2014-04-12 pjp key.size = converted_namelen;
2555 2540a41a 2014-04-12 pjp
2556 2540a41a 2014-04-12 pjp data.data = (void*)sdomain;
2557 2540a41a 2014-04-12 pjp data.size = sizeof(struct domain);
2558 2540a41a 2014-04-12 pjp
2559 2540a41a 2014-04-12 pjp if ((ret = db->put(db, NULL, &key, &data, 0)) != 0) {
2560 2540a41a 2014-04-12 pjp dolog(LOG_INFO, "db->put: %s\n" , db_strerror(ret));
2561 2540a41a 2014-04-12 pjp return;
2562 2540a41a 2014-04-12 pjp }
2563 2540a41a 2014-04-12 pjp
2564 2540a41a 2014-04-12 pjp return;
2565 2540a41a 2014-04-12 pjp }
2566 2540a41a 2014-04-12 pjp
2567 2540a41a 2014-04-12 pjp
2568 2540a41a 2014-04-12 pjp struct file *
2569 2540a41a 2014-04-12 pjp pushfile(const char *name, int secret)
2570 2540a41a 2014-04-12 pjp {
2571 58eafea4 2014-05-17 pjp struct stat sb;
2572 2540a41a 2014-04-12 pjp struct file *nfile;
2573 58eafea4 2014-05-17 pjp int fd;
2574 2540a41a 2014-04-12 pjp
2575 2540a41a 2014-04-12 pjp if ((nfile = calloc(1, sizeof(struct file))) == NULL) {
2576 58eafea4 2014-05-17 pjp dolog(LOG_INFO, "warn: malloc\n");
2577 2540a41a 2014-04-12 pjp return (NULL);
2578 2540a41a 2014-04-12 pjp }
2579 2540a41a 2014-04-12 pjp if ((nfile->name = strdup(name)) == NULL) {
2580 58eafea4 2014-05-17 pjp dolog(LOG_INFO, "warn: malloc\n");
2581 2540a41a 2014-04-12 pjp free(nfile);
2582 2540a41a 2014-04-12 pjp return (NULL);
2583 2540a41a 2014-04-12 pjp }
2584 2540a41a 2014-04-12 pjp if ((nfile->stream = fopen(nfile->name, "r")) == NULL) {
2585 58eafea4 2014-05-17 pjp dolog(LOG_INFO, "warn: %s\n", nfile->name);
2586 2540a41a 2014-04-12 pjp free(nfile->name);
2587 2540a41a 2014-04-12 pjp free(nfile);
2588 2540a41a 2014-04-12 pjp return (NULL);
2589 2540a41a 2014-04-12 pjp }
2590 58eafea4 2014-05-17 pjp
2591 58eafea4 2014-05-17 pjp fd = fileno(nfile->stream);
2592 58eafea4 2014-05-17 pjp if (fstat(fd, &sb) < 0) {
2593 58eafea4 2014-05-17 pjp dolog(LOG_INFO, "warn: %s\n", strerror(errno));
2594 58eafea4 2014-05-17 pjp }
2595 58eafea4 2014-05-17 pjp
2596 58eafea4 2014-05-17 pjp /* get the highest time of all included files */
2597 58eafea4 2014-05-17 pjp if (time_changed < sb.st_ctime)
2598 58eafea4 2014-05-17 pjp time_changed = (time_t)sb.st_ctime; /* ufs1 is only 32 bits */
2599 58eafea4 2014-05-17 pjp
2600 2540a41a 2014-04-12 pjp nfile->lineno = 1;
2601 2540a41a 2014-04-12 pjp TAILQ_INSERT_TAIL(&files, nfile, entry);
2602 2540a41a 2014-04-12 pjp return (nfile);
2603 2540a41a 2014-04-12 pjp }
2604 2540a41a 2014-04-12 pjp
2605 2540a41a 2014-04-12 pjp #define MAXPUSHBACK 128
2606 2540a41a 2014-04-12 pjp
2607 2540a41a 2014-04-12 pjp char *parsebuf;
2608 2540a41a 2014-04-12 pjp int parseindex;
2609 2540a41a 2014-04-12 pjp char pushback_buffer[MAXPUSHBACK];
2610 2540a41a 2014-04-12 pjp int pushback_index = 0;
2611 2540a41a 2014-04-12 pjp
2612 2540a41a 2014-04-12 pjp
2613 2540a41a 2014-04-12 pjp int
2614 2540a41a 2014-04-12 pjp lgetc(int quotec)
2615 2540a41a 2014-04-12 pjp {
2616 bd293faa 2014-04-13 pjp int c;
2617 2540a41a 2014-04-12 pjp
2618 2540a41a 2014-04-12 pjp if (parsebuf) {
2619 2540a41a 2014-04-12 pjp /* Read character from the parsebuffer instead of input. */
2620 2540a41a 2014-04-12 pjp if (parseindex >= 0) {
2621 2540a41a 2014-04-12 pjp c = parsebuf[parseindex++];
2622 2540a41a 2014-04-12 pjp if (c != '\0')
2623 2540a41a 2014-04-12 pjp return (c);
2624 2540a41a 2014-04-12 pjp parsebuf = NULL;
2625 2540a41a 2014-04-12 pjp } else
2626 2540a41a 2014-04-12 pjp parseindex++;
2627 2540a41a 2014-04-12 pjp }
2628 2540a41a 2014-04-12 pjp
2629 2540a41a 2014-04-12 pjp if (pushback_index)
2630 2540a41a 2014-04-12 pjp return (pushback_buffer[--pushback_index]);
2631 2540a41a 2014-04-12 pjp
2632 2540a41a 2014-04-12 pjp if (quotec) {
2633 2540a41a 2014-04-12 pjp if ((c = getc(file->stream)) == EOF) {
2634 2540a41a 2014-04-12 pjp yyerror("reached end of file while parsing "
2635 2540a41a 2014-04-12 pjp "quoted string");
2636 2540a41a 2014-04-12 pjp if (file == topfile || popfile() == EOF)
2637 2540a41a 2014-04-12 pjp return (EOF);
2638 2540a41a 2014-04-12 pjp return (quotec);
2639 2540a41a 2014-04-12 pjp }
2640 2540a41a 2014-04-12 pjp return (c);
2641 2540a41a 2014-04-12 pjp }
2642 2540a41a 2014-04-12 pjp
2643 bd293faa 2014-04-13 pjp while ((c = getc(file->stream)) == EOF) {
2644 2540a41a 2014-04-12 pjp if (file == topfile || popfile() == EOF)
2645 2540a41a 2014-04-12 pjp return (EOF);
2646 2540a41a 2014-04-12 pjp }
2647 2540a41a 2014-04-12 pjp return (c);
2648 2540a41a 2014-04-12 pjp }
2649 2540a41a 2014-04-12 pjp
2650 2540a41a 2014-04-12 pjp int
2651 2540a41a 2014-04-12 pjp popfile(void)
2652 2540a41a 2014-04-12 pjp {
2653 2540a41a 2014-04-12 pjp struct file *prev;
2654 2540a41a 2014-04-12 pjp
2655 2540a41a 2014-04-12 pjp if ((prev = TAILQ_PREV(file, files, entry)) != NULL)
2656 2540a41a 2014-04-12 pjp prev->errors += file->errors;
2657 2540a41a 2014-04-12 pjp
2658 2540a41a 2014-04-12 pjp TAILQ_REMOVE(&files, file, entry);
2659 2540a41a 2014-04-12 pjp fclose(file->stream);
2660 2540a41a 2014-04-12 pjp free(file->name);
2661 2540a41a 2014-04-12 pjp free(file);
2662 2540a41a 2014-04-12 pjp file = prev;
2663 2540a41a 2014-04-12 pjp return (file ? 0 : EOF);
2664 2540a41a 2014-04-12 pjp }
2665 2540a41a 2014-04-12 pjp
2666 2540a41a 2014-04-12 pjp
2667 2540a41a 2014-04-12 pjp int
2668 2540a41a 2014-04-12 pjp lungetc(int c)
2669 2540a41a 2014-04-12 pjp {
2670 2540a41a 2014-04-12 pjp if (c == EOF)
2671 2540a41a 2014-04-12 pjp return (EOF);
2672 2540a41a 2014-04-12 pjp if (parsebuf) {
2673 2540a41a 2014-04-12 pjp parseindex--;
2674 2540a41a 2014-04-12 pjp if (parseindex >= 0)
2675 2540a41a 2014-04-12 pjp return (c);
2676 2540a41a 2014-04-12 pjp }
2677 2540a41a 2014-04-12 pjp if (pushback_index < MAXPUSHBACK-1)
2678 2540a41a 2014-04-12 pjp return (pushback_buffer[pushback_index++] = c);
2679 2540a41a 2014-04-12 pjp else
2680 2540a41a 2014-04-12 pjp return (EOF);
2681 2540a41a 2014-04-12 pjp }
2682 2540a41a 2014-04-12 pjp
2683 2540a41a 2014-04-12 pjp int
2684 2540a41a 2014-04-12 pjp findeol(void)
2685 2540a41a 2014-04-12 pjp {
2686 2540a41a 2014-04-12 pjp int c;
2687 2540a41a 2014-04-12 pjp
2688 2540a41a 2014-04-12 pjp parsebuf = NULL;
2689 2540a41a 2014-04-12 pjp pushback_index = 0;
2690 2540a41a 2014-04-12 pjp
2691 2540a41a 2014-04-12 pjp /* skip to either EOF or the first real EOL */
2692 2540a41a 2014-04-12 pjp while (1) {
2693 2540a41a 2014-04-12 pjp c = lgetc(0);
2694 2540a41a 2014-04-12 pjp if (c == '\n') {
2695 2540a41a 2014-04-12 pjp file->lineno++;
2696 2540a41a 2014-04-12 pjp break;
2697 2540a41a 2014-04-12 pjp }
2698 2540a41a 2014-04-12 pjp if (c == EOF)
2699 2540a41a 2014-04-12 pjp break;
2700 2540a41a 2014-04-12 pjp }
2701 2540a41a 2014-04-12 pjp return (ERROR);
2702 2540a41a 2014-04-12 pjp }
2703 2540a41a 2014-04-12 pjp
2704 2540a41a 2014-04-12 pjp
2705 2540a41a 2014-04-12 pjp /*
2706 2540a41a 2014-04-12 pjp * from opensmtpd, the license at the top is compatible with this stuff
2707 2540a41a 2014-04-12 pjp */
2708 2540a41a 2014-04-12 pjp
2709 2540a41a 2014-04-12 pjp static int
2710 2540a41a 2014-04-12 pjp temp_inet_net_pton_ipv6(const char *src, void *dst, size_t size)
2711 2540a41a 2014-04-12 pjp {
2712 2540a41a 2014-04-12 pjp int ret;
2713 2540a41a 2014-04-12 pjp int bits;
2714 2540a41a 2014-04-12 pjp char buf[sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:255:255:255:255/128")];
2715 2540a41a 2014-04-12 pjp char *sep;
2716 27110135 2014-11-07 pjp #if defined __OpenBSD__ || defined __FreeBSD__
2717 2540a41a 2014-04-12 pjp const char *errstr;
2718 27110135 2014-11-07 pjp #endif
2719 2540a41a 2014-04-12 pjp
2720 2540a41a 2014-04-12 pjp #ifndef __linux__
2721 2540a41a 2014-04-12 pjp if (strlcpy(buf, src, sizeof buf) >= sizeof buf) {
2722 2540a41a 2014-04-12 pjp errno = EMSGSIZE;
2723 2540a41a 2014-04-12 pjp return (-1);
2724 2540a41a 2014-04-12 pjp }
2725 2540a41a 2014-04-12 pjp #else
2726 2540a41a 2014-04-12 pjp strncpy(buf, src, sizeof(buf));
2727 2540a41a 2014-04-12 pjp buf[sizeof(buf) - 1] = '\0';
2728 2540a41a 2014-04-12 pjp #endif
2729 2540a41a 2014-04-12 pjp
2730 2540a41a 2014-04-12 pjp sep = strchr(buf, '/');
2731 2540a41a 2014-04-12 pjp if (sep != NULL)
2732 2540a41a 2014-04-12 pjp *sep++ = '\0';
2733 2540a41a 2014-04-12 pjp
2734 2540a41a 2014-04-12 pjp ret = inet_pton(AF_INET6, buf, dst);
2735 2540a41a 2014-04-12 pjp if (ret != 1) {
2736 2540a41a 2014-04-12 pjp return (-1);
2737 2540a41a 2014-04-12 pjp }
2738 2540a41a 2014-04-12 pjp
2739 2540a41a 2014-04-12 pjp if (sep == NULL)
2740 2540a41a 2014-04-12 pjp return 128;
2741 2540a41a 2014-04-12 pjp
2742 27110135 2014-11-07 pjp #if ! defined __linux__ && ! defined __APPLE__ && ! defined __NetBSD__
2743 2540a41a 2014-04-12 pjp bits = strtonum(sep, 0, 128, &errstr);
2744 2540a41a 2014-04-12 pjp if (errstr)
2745 2540a41a 2014-04-12 pjp return (-1);
2746 27110135 2014-11-07 pjp #else
2747 27110135 2014-11-07 pjp bits = atoi(sep);
2748 2540a41a 2014-04-12 pjp #endif
2749 2540a41a 2014-04-12 pjp
2750 2540a41a 2014-04-12 pjp return bits;
2751 2540a41a 2014-04-12 pjp }
2752 2540a41a 2014-04-12 pjp
2753 2540a41a 2014-04-12 pjp
2754 2540a41a 2014-04-12 pjp char *
2755 2540a41a 2014-04-12 pjp get_prefixlen(char *input, char *prefixlength, int plsize)
2756 2540a41a 2014-04-12 pjp {
2757 2540a41a 2014-04-12 pjp int af = AF_INET;
2758 2540a41a 2014-04-12 pjp int prefixlen;
2759 2540a41a 2014-04-12 pjp char *ret, *p;
2760 2540a41a 2014-04-12 pjp
2761 2540a41a 2014-04-12 pjp if (strchr(input, ':') != NULL)
2762 2540a41a 2014-04-12 pjp af = AF_INET6;
2763 2540a41a 2014-04-12 pjp
2764 2540a41a 2014-04-12 pjp prefixlen = inet_net_pton(af, input, prefixlength, plsize);
2765 2540a41a 2014-04-12 pjp if (prefixlen < 0) {
2766 2540a41a 2014-04-12 pjp if (errno == EAFNOSUPPORT) {
2767 2540a41a 2014-04-12 pjp prefixlen = temp_inet_net_pton_ipv6(input, prefixlength, plsize);
2768 2540a41a 2014-04-12 pjp } else {
2769 f22153d0 2014-04-13 pjp if (debug)
2770 f22153d0 2014-04-13 pjp printf("not address family %d (%s)\n", af, input);
2771 2540a41a 2014-04-12 pjp return (NULL);
2772 2540a41a 2014-04-12 pjp }
2773 2540a41a 2014-04-12 pjp }
2774 2540a41a 2014-04-12 pjp
2775 2540a41a 2014-04-12 pjp if ((p = strchr(input, '/')) != NULL) {
2776 2540a41a 2014-04-12 pjp *p++ = '\0';
2777 2540a41a 2014-04-12 pjp } else {
2778 2540a41a 2014-04-12 pjp if (af == AF_INET)
2779 2540a41a 2014-04-12 pjp p = "32";
2780 2540a41a 2014-04-12 pjp else
2781 2540a41a 2014-04-12 pjp p = "128";
2782 2540a41a 2014-04-12 pjp }
2783 2540a41a 2014-04-12 pjp
2784 2540a41a 2014-04-12 pjp snprintf(prefixlength, plsize, "%s", p);
2785 2540a41a 2014-04-12 pjp ret = strdup(input);
2786 2540a41a 2014-04-12 pjp return (ret);
2787 2540a41a 2014-04-12 pjp }