Blame
Date:
Sat Nov 8 20:28:31 2014 UTC
Message:
0.9.0 is the last version of Wildcarddnsd, the succeeding project is called Delphinusdnsd and will have its first release around November 15th, 2015. The new project page is at http://delphinusdns.centroid.eu.
0001
2014-04-12
pjp
/*
0002
2014-04-12
pjp
* Copyright (c) 2014 Peter J. Philipp. All rights reserved.
0003
2014-04-12
pjp
* Copyright (c) 2008 Gilles Chehade <gilles@poolp.org>
0004
2014-04-12
pjp
* Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org>
0005
2014-04-12
pjp
* Copyright (c) 2002, 2003, 2004 Henning Brauer <henning@openbsd.org>
0006
2014-04-12
pjp
* Copyright (c) 2001 Markus Friedl. All rights reserved.
0007
2014-04-12
pjp
* Copyright (c) 2001 Daniel Hartmeier. All rights reserved.
0008
2014-04-12
pjp
* Copyright (c) 2001 Theo de Raadt. All rights reserved.
0009
2014-04-12
pjp
*
0010
2014-04-12
pjp
* Permission to use, copy, modify, and distribute this software for any
0011
2014-04-12
pjp
* purpose with or without fee is hereby granted, provided that the above
0012
2014-04-12
pjp
* copyright notice and this permission notice appear in all copies.
0013
2014-04-12
pjp
*
0014
2014-04-12
pjp
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
0015
2014-04-12
pjp
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
0016
2014-04-12
pjp
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
0017
2014-04-12
pjp
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
0018
2014-04-12
pjp
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
0019
2014-04-12
pjp
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
0020
2014-04-12
pjp
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
0021
2014-04-12
pjp
*/
0022
2014-04-12
pjp
0023
2014-04-12
pjp
%{
0024
2014-04-12
pjp
#include "include.h"
0025
2014-04-12
pjp
#include "dns.h"
0026
2014-04-12
pjp
#include "db.h"
0027
2014-04-12
pjp
0028
2014-05-18
pjp
0029
2014-05-18
pjp
extern void dolog(int, char *, ...);
0030
2014-05-18
pjp
extern char *dns_label(char *, int *);
0031
2014-05-18
pjp
extern u_int8_t find_region(struct sockaddr_storage *, int);
0032
2014-05-18
pjp
extern int insert_region(char *, char *, u_int8_t);
0033
2014-05-18
pjp
extern int insert_axfr(char *, char *);
0034
2014-05-18
pjp
extern int insert_notifyslave(char *, char *);
0035
2014-05-18
pjp
extern int insert_filter(char *, char *);
0036
2014-05-18
pjp
extern int insert_recurse(char *, char *);
0037
2014-05-18
pjp
extern int insert_whitelist(char *, char *);
0038
2014-05-18
pjp
extern int insert_wildcard(char *, char *);
0039
2014-05-18
pjp
extern void slave_shutdown(void);
0040
2014-09-27
pjp
void yyerror(const char *);
0041
2014-05-18
pjp
0042
2014-05-18
pjp
extern int whitelist;
0043
2014-05-18
pjp
extern int notify;
0044
2014-05-18
pjp
extern int errno;
0045
2014-05-18
pjp
extern int debug;
0046
2014-05-18
pjp
extern int verbose;
0047
2014-05-18
pjp
extern int bflag;
0048
2014-05-18
pjp
extern int iflag;
0049
2014-05-18
pjp
extern int lflag;
0050
2014-05-18
pjp
extern int nflag;
0051
2014-05-18
pjp
extern int rflag;
0052
2014-05-18
pjp
extern int bcount;
0053
2014-05-18
pjp
extern int icount;
0054
2014-05-18
pjp
extern int ratelimit;
0055
2014-05-18
pjp
extern int ratelimit_packets_per_second;
0056
2014-05-18
pjp
extern u_int16_t port;
0057
2014-05-18
pjp
extern u_int32_t cachesize;
0058
2014-05-18
pjp
extern char *bind_list[255];
0059
2014-05-18
pjp
extern char *interface_list[255];
0060
2014-05-18
pjp
0061
2014-05-18
pjp
0062
2014-05-18
pjp
0063
2014-04-12
pjp
TAILQ_HEAD(files, file) files = TAILQ_HEAD_INITIALIZER(files);
0064
2014-04-12
pjp
static struct file {
0065
2014-04-12
pjp
TAILQ_ENTRY(file) entry;
0066
2014-04-12
pjp
FILE *stream;
0067
2014-04-12
pjp
char *name;
0068
2014-04-12
pjp
int lineno;
0069
2014-04-12
pjp
int errors;
0070
2014-04-12
pjp
} *file, *topfile;
0071
2014-04-12
pjp
0072
2014-04-12
pjp
#define STATE_IP 1
0073
2014-04-12
pjp
#define STATE_ZONE 2
0074
2014-04-12
pjp
0075
2014-04-12
pjp
#define WILDCARDVERSION 6
0076
2014-04-12
pjp
0077
2014-04-12
pjp
#define CONFIG_START 0x1
0078
2014-04-12
pjp
#define CONFIG_VERSION 0x2
0079
2014-04-12
pjp
#define CONFIG_REGION 0x4
0080
2014-04-12
pjp
#define CONFIG_ZONE 0x8
0081
2014-04-12
pjp
#define CONFIG_INCLUDE 0x10
0082
2014-04-12
pjp
#define CONFIG_WILDCARDONLYFOR 0x20
0083
2014-04-12
pjp
#define CONFIG_RECURSEFOR 0x40
0084
2014-04-12
pjp
#define CONFIG_LOGGING 0x80
0085
2014-04-12
pjp
#define CONFIG_AXFRFOR 0x100
0086
2014-04-12
pjp
#define CONFIG_AXFRPORT 0x200
0087
2014-04-12
pjp
0088
2014-04-12
pjp
typedef struct {
0089
2014-04-12
pjp
union {
0090
2014-04-12
pjp
char *string;
0091
2014-04-12
pjp
int intval;
0092
2014-04-12
pjp
} v;
0093
2014-04-12
pjp
int lineno;
0094
2014-04-12
pjp
} YYSTYPE;
0095
2014-04-12
pjp
0096
2014-09-27
pjp
#ifdef __APPLE__
0097
2014-09-27
pjp
#define YYSTYPE_IS_DECLARED 1
0098
2014-09-27
pjp
#endif
0099
2014-09-27
pjp
0100
2014-11-07
pjp
static const char rcsid[] = "$Id: parse.y,v 1.25 2014/11/07 10:33:12 pjp Exp $";
0101
2014-04-12
pjp
static int version = 0;
0102
2014-04-12
pjp
static int state = 0;
0103
2014-04-12
pjp
static uint8_t region = 0;
0104
2014-04-12
pjp
static uint64_t confstatus = 0;
0105
2014-04-12
pjp
static DB *mydb;
0106
2014-04-12
pjp
0107
2014-04-12
pjp
YYSTYPE yylval;
0108
2014-04-13
pjp
0109
2014-04-13
pjp
0110
2014-04-12
pjp
char *converted_name;
0111
2014-04-12
pjp
int converted_namelen;
0112
2014-04-12
pjp
DBT key, data;
0113
2014-04-12
pjp
struct logging logging;
0114
2014-04-12
pjp
int axfrport = 0;
0115
2014-05-17
pjp
time_t time_changed;
0116
2014-04-12
pjp
0117
2014-04-12
pjp
0118
2014-04-12
pjp
0119
2014-05-18
pjp
char *check_rr(char *, char *, int, int *);
0120
2014-05-18
pjp
int fill_a(char *, char *, int, char *);
0121
2014-05-18
pjp
int fill_aaaa(char *, char *, int, char *);
0122
2014-05-18
pjp
int fill_balance(char *, char *, int, char *);
0123
2014-05-18
pjp
int fill_ptr(char *, char *, int, char *);
0124
2014-05-18
pjp
int fill_cname(char *, char *, int, char *);
0125
2014-05-18
pjp
int fill_mx(char *, char *, int, int, char *);
0126
2014-05-18
pjp
int fill_naptr(char *, char *, int, int, int, char *, char *, char *, char *);
0127
2014-05-18
pjp
int fill_ns(char *, char *, int, char *);
0128
2014-05-18
pjp
int fill_soa(char *, char *, int, char *, char *, int, int, int, int, int);
0129
2014-05-18
pjp
int fill_spf(char *, char *, int, char *);
0130
2014-05-18
pjp
int fill_sshfp(char *, char *, int, int, int, char *);
0131
2014-05-18
pjp
int fill_srv(char *, char *, int, int, int, int, char *);
0132
2014-05-18
pjp
int fill_txt(char *, char *, int, char *);
0133
2014-05-18
pjp
int findeol(void);
0134
2014-05-18
pjp
int get_ip(char *, int);
0135
2014-05-18
pjp
char *get_prefixlen(char *, char *, int);
0136
2014-05-18
pjp
int get_quotedstring(char *, int);
0137
2014-05-18
pjp
int get_record(struct domain *, char *, int);
0138
2014-05-18
pjp
int get_string(char *, int);
0139
2014-05-18
pjp
int lgetc(int);
0140
2014-05-18
pjp
struct tab * lookup(struct tab *, char *);
0141
2014-05-18
pjp
int lungetc(int);
0142
2014-05-18
pjp
int parse_file(DB *, char *);
0143
2014-04-12
pjp
struct file *pushfile(const char *, int);
0144
2014-05-18
pjp
int popfile(void);
0145
2014-05-18
pjp
struct rrtab *rrlookup(struct rrtab *, char *);
0146
2014-05-18
pjp
void set_record(struct domain *, char *, int);
0147
2014-05-18
pjp
static int temp_inet_net_pton_ipv6(const char *, void *, size_t);
0148
2014-05-18
pjp
int yyparse(void);
0149
2014-04-12
pjp
0150
2014-04-12
pjp
0151
2014-05-18
pjp
struct rrtab {
0152
2014-05-18
pjp
char *name;
0153
2014-05-18
pjp
u_int16_t type;
0154
2014-05-18
pjp
} myrrtab[] = {
0155
2014-05-18
pjp
{ "a", DNS_TYPE_A } ,
0156
2014-05-18
pjp
{ "soa", DNS_TYPE_SOA },
0157
2014-05-18
pjp
{ "cname", DNS_TYPE_CNAME },
0158
2014-05-18
pjp
{ "ptr", DNS_TYPE_PTR },
0159
2014-05-18
pjp
{ "mx", DNS_TYPE_MX },
0160
2014-05-18
pjp
{ "aaaa", DNS_TYPE_AAAA },
0161
2014-05-18
pjp
{ "ns", DNS_TYPE_NS },
0162
2014-05-18
pjp
{ "txt", DNS_TYPE_TXT },
0163
2014-05-18
pjp
{ "hint", DNS_TYPE_HINT },
0164
2014-05-18
pjp
{ "delegate", DNS_TYPE_DELEGATE },
0165
2014-05-18
pjp
{ "balance", DNS_TYPE_BALANCE },
0166
2014-05-18
pjp
{ "srv", DNS_TYPE_SRV },
0167
2014-05-18
pjp
{ "spf", DNS_TYPE_SPF },
0168
2014-05-18
pjp
{ "sshfp", DNS_TYPE_SSHFP },
0169
2014-05-18
pjp
{ "naptr", DNS_TYPE_NAPTR },
0170
2014-05-18
pjp
{ NULL, 0 },
0171
2014-05-18
pjp
};
0172
2014-04-12
pjp
0173
2014-04-12
pjp
0174
2014-04-12
pjp
0175
2014-04-12
pjp
0176
2014-04-12
pjp
%}
0177
2014-04-12
pjp
0178
2014-04-12
pjp
0179
2014-04-12
pjp
%token VERSION OBRACE EBRACE REGION AXFRFOR RECURSEFOR
0180
2014-04-12
pjp
%token DOT COLON TEXT WOF INCLUDE ZONE COMMA CRLF
0181
2014-05-17
pjp
%token ERROR AXFRPORT LOGGING OPTIONS FILTER NOTIFY
0182
2014-05-18
pjp
%token WHITELIST
0183
2014-04-12
pjp
0184
2014-04-12
pjp
%token <v.string> POUND
0185
2014-04-12
pjp
%token <v.string> SEMICOLON
0186
2014-04-12
pjp
%token <v.string> STRING
0187
2014-04-12
pjp
%token <v.string> IP
0188
2014-04-12
pjp
%token <v.string> IPV6
0189
2014-04-12
pjp
%token <v.string> SLASH
0190
2014-04-12
pjp
%token <v.string> QUOTEDSTRING
0191
2014-04-12
pjp
0192
2014-04-12
pjp
%token <v.intval> NUMBER
0193
2014-04-12
pjp
0194
2014-04-12
pjp
%type <v.string> quotednumber quotedfilename ipcidr
0195
2014-04-12
pjp
0196
2014-04-12
pjp
%start cmd_list
0197
2014-04-12
pjp
0198
2014-04-12
pjp
%%
0199
2014-04-12
pjp
cmd_list:
0200
2014-04-12
pjp
| cmd_list cmd
0201
2014-04-12
pjp
;
0202
2014-04-12
pjp
0203
2014-04-12
pjp
cmd :
0204
2014-04-12
pjp
version
0205
2014-04-12
pjp
| axfrport
0206
2014-04-12
pjp
| include
0207
2014-04-12
pjp
| zone
0208
2014-04-12
pjp
| region CRLF
0209
2014-04-12
pjp
| wof CRLF
0210
2014-04-12
pjp
| axfr CRLF
0211
2014-05-17
pjp
| notify CRLF
0212
2014-05-18
pjp
| whitelist CRLF
0213
2014-05-01
pjp
| filter CRLF
0214
2014-04-12
pjp
| recurse CRLF
0215
2014-04-12
pjp
| logging
0216
2014-04-12
pjp
| comment CRLF
0217
2014-04-15
pjp
| options
0218
2014-04-12
pjp
;
0219
2014-04-12
pjp
0220
2014-04-12
pjp
0221
2014-04-12
pjp
comment:
0222
2014-04-12
pjp
comment comments
0223
2014-04-12
pjp
| comments
0224
2014-04-12
pjp
;
0225
2014-04-12
pjp
0226
2014-04-12
pjp
comments:
0227
2014-04-12
pjp
SEMICOLON
0228
2014-04-12
pjp
| POUND
0229
2014-04-12
pjp
;
0230
2014-04-12
pjp
0231
2014-04-12
pjp
version:
0232
2014-04-12
pjp
VERSION quotednumber SEMICOLON CRLF
0233
2014-04-12
pjp
{
0234
2014-04-12
pjp
version = atoi($2);
0235
2014-04-12
pjp
if (version != WILDCARDVERSION) {
0236
2014-04-12
pjp
dolog(LOG_ERR, "version of configfile is wrong,"
0237
2014-04-12
pjp
" must be \"%d\"!\n", WILDCARDVERSION);
0238
2014-04-12
pjp
return (-1);
0239
2014-04-12
pjp
}
0240
2014-04-12
pjp
free ($2);
0241
2014-04-12
pjp
0242
2014-04-12
pjp
confstatus |= CONFIG_VERSION;
0243
2014-04-12
pjp
}
0244
2014-04-12
pjp
;
0245
2014-04-12
pjp
0246
2014-04-12
pjp
axfrport:
0247
2014-04-12
pjp
AXFRPORT quotednumber SEMICOLON CRLF
0248
2014-04-12
pjp
{
0249
2014-04-12
pjp
if ((confstatus & CONFIG_VERSION) != CONFIG_VERSION) {
0250
2014-04-12
pjp
dolog(LOG_INFO, "There must be a version at the top of the first configfile\n");
0251
2014-04-12
pjp
return (-1);
0252
2014-04-12
pjp
}
0253
2014-04-12
pjp
0254
2014-04-12
pjp
axfrport = atoi($2);
0255
2014-04-12
pjp
free ($2);
0256
2014-04-12
pjp
}
0257
2014-04-12
pjp
;
0258
2014-04-12
pjp
0259
2014-04-12
pjp
quotednumber:
0260
2014-04-12
pjp
QUOTEDSTRING
0261
2014-04-12
pjp
{
0262
2014-04-13
pjp
if (debug)
0263
2014-04-13
pjp
printf("quotednumber is %s\n", $$);
0264
2014-04-12
pjp
}
0265
2014-04-12
pjp
;
0266
2014-04-12
pjp
0267
2014-04-12
pjp
include:
0268
2014-04-12
pjp
includes CRLF
0269
2014-04-12
pjp
;
0270
2014-04-12
pjp
0271
2014-04-12
pjp
includes:
0272
2014-04-12
pjp
INCLUDE quotedfilename SEMICOLON {
0273
2014-04-12
pjp
struct file *nfile;
0274
2014-04-12
pjp
0275
2014-04-12
pjp
if ((confstatus & CONFIG_VERSION) != CONFIG_VERSION) {
0276
2014-04-12
pjp
dolog(LOG_INFO, "There must be a version at the top of the first configfile\n");
0277
2014-04-12
pjp
return (-1);
0278
2014-04-12
pjp
}
0279
2014-04-12
pjp
0280
2014-04-12
pjp
if ((nfile = pushfile($2, 0)) == NULL) {
0281
2014-04-12
pjp
fprintf(stderr, "failed to include file %s\n", $2);
0282
2014-04-12
pjp
free($2);
0283
2014-04-12
pjp
return (-1);
0284
2014-04-12
pjp
}
0285
2014-04-12
pjp
0286
2014-04-12
pjp
free($2);
0287
2014-04-12
pjp
0288
2014-04-12
pjp
file = nfile;
0289
2014-04-12
pjp
}
0290
2014-04-12
pjp
;
0291
2014-04-12
pjp
0292
2014-04-12
pjp
quotedfilename:
0293
2014-04-12
pjp
QUOTEDSTRING
0294
2014-04-12
pjp
{
0295
2014-04-13
pjp
if (debug)
0296
2014-04-13
pjp
printf("quotedfilename is %s\n", $$);
0297
2014-04-12
pjp
}
0298
2014-04-12
pjp
;
0299
2014-04-12
pjp
0300
2014-04-12
pjp
/* zone */
0301
2014-04-12
pjp
0302
2014-04-12
pjp
zone:
0303
2014-04-12
pjp
ZONE zonelabel zonecontent
0304
2014-04-12
pjp
{
0305
2014-04-12
pjp
if ((confstatus & CONFIG_VERSION) != CONFIG_VERSION) {
0306
2014-04-12
pjp
dolog(LOG_INFO, "There must be a version at the top of the first configfile\n");
0307
2014-04-12
pjp
return (-1);
0308
2014-04-12
pjp
}
0309
2014-04-12
pjp
}
0310
2014-04-12
pjp
;
0311
2014-04-12
pjp
0312
2014-04-12
pjp
zonelabel:
0313
2014-04-12
pjp
QUOTEDSTRING
0314
2014-04-12
pjp
;
0315
2014-04-12
pjp
0316
2014-04-12
pjp
zonecontent:
0317
2014-04-12
pjp
OBRACE zonestatements EBRACE CRLF
0318
2014-04-12
pjp
| OBRACE CRLF zonestatements EBRACE CRLF
0319
2014-04-12
pjp
;
0320
2014-04-12
pjp
0321
2014-04-12
pjp
0322
2014-04-12
pjp
zonestatements :
0323
2014-04-12
pjp
zonestatements zonestatement
0324
2014-04-12
pjp
| zonestatement
0325
2014-04-12
pjp
;
0326
2014-04-12
pjp
0327
2014-04-12
pjp
0328
2014-04-12
pjp
zonestatement:
0329
2014-04-12
pjp
0330
2014-04-12
pjp
/* centroid.eu,soa,3600,uranus.centroid.eu.,pjp.solarscale.de.,1258740680,3600,1800,7200,3600 */
0331
2014-04-12
pjp
0332
2014-04-12
pjp
STRING COMMA STRING COMMA NUMBER COMMA STRING COMMA STRING COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER CRLF
0333
2014-04-12
pjp
{
0334
2014-04-12
pjp
if (strcasecmp($3, "soa") == 0) {
0335
2014-04-12
pjp
if (fill_soa($1, $3, $5, $7, $9, $11, $13, $15, $17, $19) < 0) {
0336
2014-04-12
pjp
return -1;
0337
2014-04-12
pjp
}
0338
2014-04-12
pjp
0339
2014-04-13
pjp
if (debug)
0340
2014-04-13
pjp
printf("%s SOA\n", $1);
0341
2014-04-12
pjp
} else {
0342
2014-04-13
pjp
if (debug)
0343
2014-04-13
pjp
printf("soa error\n");
0344
2014-04-12
pjp
return -1;
0345
2014-04-12
pjp
}
0346
2014-04-12
pjp
0347
2014-04-12
pjp
0348
2014-04-12
pjp
free ($1);
0349
2014-04-12
pjp
free ($3);
0350
2014-04-12
pjp
free ($7);
0351
2014-04-12
pjp
free ($9);
0352
2014-04-12
pjp
}
0353
2014-04-12
pjp
|
0354
2014-04-21
pjp
STRING COMMA STRING COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA QUOTEDSTRING CRLF
0355
2014-04-21
pjp
{
0356
2014-04-21
pjp
if (strcasecmp($3, "sshfp") == 0) {
0357
2014-04-21
pjp
if (fill_sshfp($1, $3, $5, $7, $9, $11) < 0) {
0358
2014-04-21
pjp
return -1;
0359
2014-04-21
pjp
}
0360
2014-04-21
pjp
0361
2014-04-21
pjp
} else {
0362
2014-04-21
pjp
if (debug)
0363
2014-04-21
pjp
printf("another sshfp record I don't know about?");
0364
2014-04-21
pjp
return (-1);
0365
2014-04-21
pjp
}
0366
2014-04-21
pjp
0367
2014-04-21
pjp
free ($1);
0368
2014-04-21
pjp
free ($3);
0369
2014-04-21
pjp
free ($11);
0370
2014-04-21
pjp
}
0371
2014-04-21
pjp
|
0372
2014-04-12
pjp
STRING COMMA STRING COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA STRING CRLF
0373
2014-04-12
pjp
{
0374
2014-04-12
pjp
if (strcasecmp($3, "srv") == 0) {
0375
2014-04-12
pjp
if (fill_srv($1, $3, $5, $7, $9, $11, $13) < 0) {
0376
2014-04-12
pjp
return -1;
0377
2014-04-12
pjp
}
0378
2014-04-12
pjp
0379
2014-04-12
pjp
} else {
0380
2014-04-13
pjp
if (debug)
0381
2014-04-13
pjp
printf("2 another record I don't know about?");
0382
2014-04-12
pjp
return (-1);
0383
2014-04-12
pjp
}
0384
2014-04-12
pjp
0385
2014-04-12
pjp
free ($1);
0386
2014-04-12
pjp
free ($3);
0387
2014-04-12
pjp
free ($13);
0388
2014-04-12
pjp
}
0389
2014-04-12
pjp
|
0390
2014-04-12
pjp
STRING COMMA STRING COMMA NUMBER COMMA STRING CRLF {
0391
2014-04-12
pjp
if (strcasecmp($3, "ns") == 0 ||
0392
2014-04-12
pjp
strcasecmp($3, "delegate") == 0 ||
0393
2014-04-12
pjp
strcasecmp($3, "hint") == 0) {
0394
2014-04-12
pjp
if (fill_ns($1, $3, $5, $7) < 0) {
0395
2014-04-12
pjp
return -1;
0396
2014-04-12
pjp
}
0397
2014-04-12
pjp
0398
2014-04-13
pjp
if (debug)
0399
2014-04-13
pjp
printf("%s NS\n", $1);
0400
2014-04-13
pjp
0401
2014-04-12
pjp
} else if (strcasecmp($3, "ptr") == 0) {
0402
2014-04-12
pjp
if (fill_ptr($1, $3, $5, $7) < 0) {
0403
2014-04-12
pjp
return -1;
0404
2014-04-12
pjp
}
0405
2014-04-13
pjp
0406
2014-04-13
pjp
if (debug)
0407
2014-04-13
pjp
printf("%s PTR\n", $1);
0408
2014-04-13
pjp
0409
2014-04-12
pjp
} else if (strcasecmp($3, "cname") == 0) {
0410
2014-04-12
pjp
if (fill_cname($1, $3, $5, $7) < 0) {
0411
2014-04-12
pjp
return -1;
0412
2014-04-12
pjp
}
0413
2014-04-13
pjp
0414
2014-04-13
pjp
if (debug)
0415
2014-04-13
pjp
printf("%s CNAME\n", $3);
0416
2014-04-13
pjp
0417
2014-04-12
pjp
} else {
0418
2014-04-13
pjp
if (debug)
0419
2014-04-13
pjp
printf("%s other\n", $3);
0420
2014-04-12
pjp
return -1;
0421
2014-04-12
pjp
}
0422
2014-04-12
pjp
0423
2014-04-12
pjp
free ($1);
0424
2014-04-12
pjp
free ($3);
0425
2014-04-12
pjp
free ($7);
0426
2014-04-12
pjp
}
0427
2014-04-12
pjp
|
0428
2014-04-12
pjp
STRING COMMA STRING COMMA NUMBER COMMA IPV6 CRLF {
0429
2014-04-12
pjp
if (strcasecmp($3, "aaaa") == 0) {
0430
2014-04-12
pjp
if (fill_aaaa($1, $3, $5, $7) < 0) {
0431
2014-04-12
pjp
return -1;
0432
2014-04-12
pjp
}
0433
2014-04-12
pjp
0434
2014-04-13
pjp
if (debug)
0435
2014-04-13
pjp
printf("%s AAAA\n", $1);
0436
2014-04-12
pjp
} else {
0437
2014-04-13
pjp
0438
2014-04-13
pjp
if (debug)
0439
2014-04-13
pjp
printf("error AAAA\n");
0440
2014-04-12
pjp
return (-1);
0441
2014-04-12
pjp
}
0442
2014-04-12
pjp
free ($1);
0443
2014-04-12
pjp
free ($3);
0444
2014-04-12
pjp
free ($7);
0445
2014-04-12
pjp
}
0446
2014-04-12
pjp
|
0447
2014-04-12
pjp
STRING COMMA STRING COMMA NUMBER COMMA IP CRLF
0448
2014-04-12
pjp
{
0449
2014-04-12
pjp
if (strcasecmp($3, "a") == 0) {
0450
2014-04-12
pjp
if (fill_a($1, $3, $5, $7) < 0) {
0451
2014-04-12
pjp
return -1;
0452
2014-04-12
pjp
}
0453
2014-04-12
pjp
0454
2014-04-13
pjp
if (debug)
0455
2014-04-13
pjp
printf("%s A\n", $1);
0456
2014-04-13
pjp
0457
2014-04-12
pjp
} else if (strcasecmp($3, "balance") == 0) {
0458
2014-04-12
pjp
if (fill_balance($1, $3, $5, $7) < 0) {
0459
2014-04-12
pjp
return -1;
0460
2014-04-12
pjp
}
0461
2014-04-12
pjp
0462
2014-04-13
pjp
if (debug)
0463
2014-04-13
pjp
printf("a balance record?\n");
0464
2014-04-12
pjp
} else {
0465
2014-04-13
pjp
if (debug)
0466
2014-04-13
pjp
printf("another a record?\n");
0467
2014-04-12
pjp
return -1;
0468
2014-04-12
pjp
}
0469
2014-04-12
pjp
0470
2014-04-12
pjp
free ($1);
0471
2014-04-12
pjp
free ($3);
0472
2014-04-12
pjp
free ($7);
0473
2014-04-12
pjp
}
0474
2014-04-12
pjp
|
0475
2014-04-12
pjp
STRING COMMA STRING COMMA NUMBER COMMA NUMBER COMMA STRING CRLF
0476
2014-04-12
pjp
{
0477
2014-04-12
pjp
if (strcasecmp($3, "mx") == 0) {
0478
2014-04-12
pjp
if (fill_mx($1, $3, $5, $7, $9) < 0) {
0479
2014-04-12
pjp
return -1;
0480
2014-04-12
pjp
}
0481
2014-04-12
pjp
0482
2014-04-13
pjp
if (debug)
0483
2014-04-13
pjp
printf("%s MX -> %d %s\n", $1, $7, $9);
0484
2014-04-13
pjp
0485
2014-04-12
pjp
} else {
0486
2014-04-13
pjp
if (debug)
0487
2014-04-13
pjp
printf("another record I don't know about?");
0488
2014-04-12
pjp
return (-1);
0489
2014-04-12
pjp
}
0490
2014-04-12
pjp
0491
2014-04-12
pjp
free ($1);
0492
2014-04-12
pjp
free ($3);
0493
2014-04-12
pjp
free ($9);
0494
2014-04-12
pjp
}
0495
2014-04-12
pjp
|
0496
2014-04-12
pjp
STRING COMMA STRING COMMA NUMBER COMMA QUOTEDSTRING CRLF
0497
2014-04-12
pjp
{
0498
2014-04-12
pjp
if (strcasecmp($3, "txt") == 0) {
0499
2014-04-12
pjp
if (fill_txt($1, $3, $5, $7) < 0) {
0500
2014-04-12
pjp
return -1;
0501
2014-04-12
pjp
}
0502
2014-04-12
pjp
0503
2014-04-13
pjp
if (debug)
0504
2014-04-13
pjp
printf(" %s TXT -> %s\n", $1, $7);
0505
2014-04-21
pjp
} else if (strcasecmp($3, "spf") == 0) {
0506
2014-04-21
pjp
if (fill_spf($1, $3, $5, $7) < 0) {
0507
2014-04-21
pjp
return -1;
0508
2014-04-21
pjp
}
0509
2014-04-21
pjp
0510
2014-04-21
pjp
if (debug)
0511
2014-04-21
pjp
printf(" %s SPF -> %s\n", $1, $7);
0512
2014-04-12
pjp
} else {
0513
2014-04-13
pjp
if (debug)
0514
2014-04-21
pjp
printf("another txt/spf like record I don't know?\n");
0515
2014-04-12
pjp
return (-1);
0516
2014-04-12
pjp
}
0517
2014-04-12
pjp
0518
2014-04-12
pjp
free ($1);
0519
2014-04-12
pjp
free ($3);
0520
2014-04-12
pjp
free ($7);
0521
2014-04-12
pjp
}
0522
2014-05-11
pjp
|
0523
2014-05-11
pjp
STRING COMMA STRING COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA QUOTEDSTRING COMMA QUOTEDSTRING COMMA QUOTEDSTRING COMMA STRING CRLF
0524
2014-05-11
pjp
{
0525
2014-05-11
pjp
if (strcasecmp($3, "naptr") == 0) {
0526
2014-05-11
pjp
if (fill_naptr($1, $3, $5, $7, $9, $11, $13, $15, $17) < 0) {
0527
2014-05-11
pjp
return -1;
0528
2014-05-11
pjp
}
0529
2014-05-11
pjp
0530
2014-05-11
pjp
if (debug)
0531
2014-05-11
pjp
printf(" %s NAPTR\n", $1);
0532
2014-05-11
pjp
} else {
0533
2014-05-11
pjp
if (debug)
0534
2014-05-11
pjp
printf("another naptr like record I don't know?\n");
0535
2014-05-11
pjp
return (-1);
0536
2014-05-11
pjp
}
0537
2014-05-11
pjp
0538
2014-05-11
pjp
free ($1);
0539
2014-05-11
pjp
free ($3);
0540
2014-05-11
pjp
free ($11);
0541
2014-05-11
pjp
free ($13);
0542
2014-05-11
pjp
free ($15);
0543
2014-05-11
pjp
free ($17);
0544
2014-05-11
pjp
}
0545
2014-04-12
pjp
| comment CRLF
0546
2014-04-12
pjp
;
0547
2014-04-15
pjp
0548
2014-04-15
pjp
0549
2014-04-15
pjp
options:
0550
2014-04-15
pjp
OPTIONS optionslabel optionscontent
0551
2014-04-15
pjp
{
0552
2014-04-15
pjp
if ((confstatus & CONFIG_VERSION) != CONFIG_VERSION) {
0553
2014-04-15
pjp
dolog(LOG_INFO, "There must be a version at the top of the first configfile\n");
0554
2014-04-15
pjp
return (-1);
0555
2014-04-15
pjp
}
0556
2014-04-15
pjp
}
0557
2014-04-15
pjp
;
0558
2014-04-15
pjp
0559
2014-04-15
pjp
optionslabel:
0560
2014-04-15
pjp
QUOTEDSTRING
0561
2014-04-15
pjp
;
0562
2014-04-15
pjp
0563
2014-04-15
pjp
optionscontent:
0564
2014-04-15
pjp
OBRACE optionsstatements EBRACE CRLF
0565
2014-04-15
pjp
| OBRACE CRLF optionsstatements EBRACE CRLF
0566
2014-04-15
pjp
;
0567
2014-04-15
pjp
0568
2014-04-15
pjp
optionsstatements:
0569
2014-04-16
pjp
optionsstatement
0570
2014-04-16
pjp
| optionsstatements optionsstatement
0571
2014-04-15
pjp
;
0572
2014-04-15
pjp
0573
2014-04-15
pjp
optionsstatement:
0574
2014-04-15
pjp
0575
2014-04-16
pjp
STRING SEMICOLON CRLF
0576
2014-04-15
pjp
{
0577
2014-04-15
pjp
if (strcasecmp($1, "recurse") == 0) {
0578
2014-04-15
pjp
dolog(LOG_DEBUG, "recursive server on\n");
0579
2014-04-15
pjp
rflag = 0; /* keep it off please! */
0580
2014-04-15
pjp
} else if (strcasecmp($1, "log") == 0) {
0581
2014-04-15
pjp
dolog(LOG_DEBUG, "logging on\n");
0582
2014-04-15
pjp
lflag = 1;
0583
2014-04-15
pjp
}
0584
2014-04-15
pjp
}
0585
2014-04-15
pjp
|
0586
2014-04-16
pjp
STRING QUOTEDSTRING SEMICOLON CRLF
0587
2014-04-15
pjp
{
0588
2014-04-15
pjp
if (strcasecmp($1, "interface") == 0) {
0589
2014-04-15
pjp
iflag = 1;
0590
2014-04-15
pjp
if (icount > 253) {
0591
2014-04-15
pjp
dolog(LOG_ERR, "too many interface keywords in options\n");
0592
2014-04-15
pjp
return (-1);
0593
2014-04-15
pjp
}
0594
2014-04-12
pjp
0595
2014-04-15
pjp
dolog(LOG_DEBUG, "interface \"%s\" added\n", $2);
0596
2014-04-15
pjp
interface_list[icount++] = $2;
0597
2014-04-15
pjp
}
0598
2014-04-15
pjp
0599
2014-04-15
pjp
}
0600
2014-04-15
pjp
|
0601
2014-04-16
pjp
STRING NUMBER SEMICOLON CRLF
0602
2014-04-15
pjp
{
0603
2014-04-15
pjp
if (strcasecmp($1, "fork") == 0) {
0604
2014-04-15
pjp
dolog(LOG_DEBUG, "forking %d times\n", $2);
0605
2014-04-15
pjp
nflag = $2;
0606
2014-04-15
pjp
} else if (strcasecmp($1, "port") == 0) {
0607
2014-04-15
pjp
port = $2 & 0xffff;
0608
2014-04-15
pjp
dolog(LOG_DEBUG, "listening on port %d\n", port);
0609
2014-05-05
pjp
} else if (strcasecmp($1, "ratelimit-pps") == 0) {
0610
2014-05-05
pjp
if ($2 > 127 || $2 < 1) {
0611
2014-05-05
pjp
dolog(LOG_ERR, "ratelimit packets per second must be between 1 and 127, or leave it off!\n");
0612
2014-05-05
pjp
return -1;
0613
2014-05-05
pjp
}
0614
2014-05-05
pjp
ratelimit = 1;
0615
2014-05-05
pjp
ratelimit_packets_per_second = $2;
0616
2014-05-05
pjp
dolog(LOG_DEBUG, "ratelimiting to %d packets per second", ratelimit_packets_per_second);
0617
2014-04-15
pjp
}
0618
2014-04-15
pjp
0619
2014-04-15
pjp
}
0620
2014-04-15
pjp
|
0621
2014-04-16
pjp
STRING ipcidr SEMICOLON CRLF
0622
2014-04-15
pjp
{
0623
2014-04-15
pjp
if (strcasecmp($1, "bind") == 0) {
0624
2014-04-15
pjp
bflag = 1;
0625
2014-04-15
pjp
if (bcount > 253) {
0626
2014-04-15
pjp
dolog(LOG_ERR, "too many bind keywords in options\n");
0627
2014-04-15
pjp
return (-1);
0628
2014-04-15
pjp
}
0629
2014-04-15
pjp
dolog(LOG_DEBUG, "binding to %s\n", $2);
0630
2014-04-15
pjp
bind_list[bcount++] = $2;
0631
2014-04-15
pjp
}
0632
2014-04-15
pjp
0633
2014-04-15
pjp
}
0634
2014-04-16
pjp
| comment CRLF
0635
2014-04-15
pjp
;
0636
2014-04-15
pjp
0637
2014-04-15
pjp
/* logging below */
0638
2014-04-15
pjp
0639
2014-04-12
pjp
logging:
0640
2014-04-12
pjp
LOGGING logginglabel loggingcontent
0641
2014-04-12
pjp
{
0642
2014-04-12
pjp
if ((confstatus & CONFIG_VERSION) != CONFIG_VERSION) {
0643
2014-04-12
pjp
dolog(LOG_INFO, "There must be a version at the top of the first configfile\n");
0644
2014-04-12
pjp
return (-1);
0645
2014-04-12
pjp
}
0646
2014-04-12
pjp
}
0647
2014-04-12
pjp
;
0648
2014-04-12
pjp
0649
2014-04-12
pjp
logginglabel:
0650
2014-04-12
pjp
QUOTEDSTRING
0651
2014-04-12
pjp
;
0652
2014-04-12
pjp
0653
2014-04-12
pjp
loggingcontent:
0654
2014-04-12
pjp
OBRACE loggingstatements EBRACE CRLF
0655
2014-04-12
pjp
| OBRACE CRLF loggingstatements EBRACE CRLF
0656
2014-04-12
pjp
;
0657
2014-04-12
pjp
0658
2014-04-12
pjp
loggingstatements:
0659
2014-04-12
pjp
loggingstatement CRLF
0660
2014-04-12
pjp
| loggingstatements loggingstatement CRLF
0661
2014-04-12
pjp
;
0662
2014-04-12
pjp
0663
2014-04-12
pjp
loggingstatement:
0664
2014-04-12
pjp
STRING STRING SEMICOLON
0665
2014-04-12
pjp
{
0666
2014-04-12
pjp
char buf[512];
0667
2014-04-12
pjp
0668
2014-04-12
pjp
if (strcasecmp($1, "logbind") == 0) {
0669
2014-04-12
pjp
logging.active = 1;
0670
2014-04-12
pjp
logging.bind = 0;
0671
2014-04-12
pjp
0672
2014-04-12
pjp
gethostname(buf, sizeof(buf));
0673
2014-04-12
pjp
logging.hostname = strdup(buf);
0674
2014-04-12
pjp
if (logging.hostname == NULL) {
0675
2014-04-12
pjp
dolog(LOG_ERR, "strdup failed\n");
0676
2014-04-12
pjp
return (-1);
0677
2014-04-12
pjp
}
0678
2014-04-12
pjp
0679
2014-04-12
pjp
if (strcmp($2, "yes") == 0) {
0680
2014-04-12
pjp
logging.bind = 1;
0681
2014-04-12
pjp
}
0682
2014-04-12
pjp
} else if (strcasecmp($1, "logpasswd") == 0) {
0683
2014-04-12
pjp
0684
2014-04-12
pjp
logging.logpasswd = strdup($2);
0685
2014-04-12
pjp
0686
2014-04-12
pjp
if (logging.logpasswd == NULL) {
0687
2014-04-12
pjp
dolog(LOG_ERR, "strdup failed\n");
0688
2014-04-12
pjp
return (-1);
0689
2014-04-12
pjp
}
0690
2014-04-12
pjp
0691
2014-04-12
pjp
} else {
0692
2014-04-13
pjp
if (debug)
0693
2014-04-13
pjp
printf("another logging statement I don't know?\n");
0694
2014-04-12
pjp
return (-1);
0695
2014-04-12
pjp
}
0696
2014-04-12
pjp
0697
2014-04-12
pjp
}
0698
2014-04-12
pjp
|
0699
2014-04-12
pjp
STRING NUMBER SEMICOLON
0700
2014-04-12
pjp
{
0701
2014-04-12
pjp
char buf[16];
0702
2014-04-12
pjp
0703
2014-04-12
pjp
if (strcasecmp($1, "logport") == 0) {
0704
2014-04-12
pjp
snprintf(buf, sizeof(buf), "%d", $2);
0705
2014-04-12
pjp
logging.logport = strdup(buf);
0706
2014-04-12
pjp
if (logging.logport == NULL) {
0707
2014-04-12
pjp
dolog(LOG_ERR, "strdup failed\n");
0708
2014-04-12
pjp
return (-1);
0709
2014-04-12
pjp
}
0710
2014-04-12
pjp
logging.logport2 = $2;
0711
2014-04-12
pjp
}
0712
2014-04-12
pjp
}
0713
2014-04-12
pjp
|
0714
2014-04-12
pjp
STRING ipcidr SEMICOLON
0715
2014-04-12
pjp
{
0716
2014-04-12
pjp
struct addrinfo hints, *res0;
0717
2014-04-12
pjp
struct sockaddr_in6 *psin6;
0718
2014-04-12
pjp
struct sockaddr_in *psin;
0719
2014-04-12
pjp
int error;
0720
2014-04-12
pjp
0721
2014-04-12
pjp
if (strcasecmp($1, "loghost") == 0) {
0722
2014-04-12
pjp
logging.loghost = strdup($2);
0723
2014-04-12
pjp
if (logging.loghost == NULL) {
0724
2014-04-12
pjp
dolog(LOG_ERR, "strdup failed\n");
0725
2014-04-12
pjp
0726
2014-04-12
pjp
return (-1);
0727
2014-04-12
pjp
}
0728
2014-04-12
pjp
0729
2014-04-12
pjp
if (strchr($2, ':') != NULL) {
0730
2014-04-12
pjp
memset(&hints, 0, sizeof(hints));
0731
2014-04-12
pjp
hints.ai_family = AF_INET6;
0732
2014-04-12
pjp
hints.ai_socktype = SOCK_STREAM;
0733
2014-04-12
pjp
hints.ai_flags = AI_NUMERICHOST;
0734
2014-04-12
pjp
0735
2014-04-12
pjp
error = getaddrinfo($2, "www", &hints, &res0);
0736
2014-04-12
pjp
if (error) {
0737
2014-04-12
pjp
dolog(LOG_ERR, "%s line %d: %s\n",
0738
2014-04-12
pjp
file->name, file->lineno,
0739
2014-04-12
pjp
gai_strerror(error));
0740
2014-04-12
pjp
0741
2014-04-12
pjp
return (-1);
0742
2014-04-12
pjp
}
0743
2014-04-12
pjp
0744
2014-04-12
pjp
if (res0 == NULL) {
0745
2014-04-12
pjp
dolog(LOG_ERR, "%s line %d: could not"
0746
2014-04-12
pjp
" determine IPv6 address\n"
0747
2014-04-12
pjp
, file->name, file->lineno);
0748
2014-04-12
pjp
return (-1);
0749
2014-04-12
pjp
}
0750
2014-04-12
pjp
0751
2014-04-12
pjp
psin6 = (struct sockaddr_in6 *)&logging.loghost2;
0752
2014-04-12
pjp
psin6->sin6_family = res0->ai_family;
0753
2014-04-12
pjp
memcpy(psin6, res0->ai_addr, res0->ai_addrlen);
0754
2014-04-12
pjp
freeaddrinfo(res0);
0755
2014-04-12
pjp
} else {
0756
2014-04-12
pjp
memset(&hints, 0, sizeof(hints));
0757
2014-04-12
pjp
0758
2014-04-12
pjp
hints.ai_family = AF_INET;
0759
2014-04-12
pjp
hints.ai_socktype = SOCK_STREAM;
0760
2014-04-12
pjp
hints.ai_flags = AI_NUMERICHOST;
0761
2014-04-12
pjp
0762
2014-04-12
pjp
error = getaddrinfo($2, "www", &hints, &res0);
0763
2014-04-12
pjp
if (error) {
0764
2014-04-12
pjp
dolog(LOG_ERR, "%s line %d: %s\n",
0765
2014-04-12
pjp
file->name, file->lineno,
0766
2014-04-12
pjp
gai_strerror(error));
0767
2014-04-12
pjp
0768
2014-04-12
pjp
return (-1);
0769
2014-04-12
pjp
}
0770
2014-04-12
pjp
0771
2014-04-12
pjp
if (res0 == NULL) {
0772
2014-04-12
pjp
dolog(LOG_ERR, "%s line %d: could not"
0773
2014-04-12
pjp
" determine IPv6 address\n"
0774
2014-04-12
pjp
, file->name, file->lineno);
0775
2014-04-12
pjp
return (-1);
0776
2014-04-12
pjp
}
0777
2014-04-12
pjp
0778
2014-04-12
pjp
psin = (struct sockaddr_in *)&logging.loghost2;
0779
2014-04-12
pjp
psin->sin_family = res0->ai_family;
0780
2014-04-12
pjp
memcpy(psin, res0->ai_addr, res0->ai_addrlen);
0781
2014-04-12
pjp
0782
2014-04-12
pjp
freeaddrinfo(res0);
0783
2014-04-12
pjp
}
0784
2014-04-12
pjp
} else {
0785
2014-04-13
pjp
if (debug)
0786
2014-04-13
pjp
printf("2 another logging statement I don't know?\n");
0787
2014-04-12
pjp
return (-1);
0788
2014-04-12
pjp
}
0789
2014-04-12
pjp
}
0790
2014-04-12
pjp
| comment CRLF
0791
2014-04-12
pjp
;
0792
2014-04-12
pjp
0793
2014-05-18
pjp
/* whitelist "these hosts" { .. } */
0794
2014-05-18
pjp
0795
2014-05-18
pjp
whitelist:
0796
2014-05-18
pjp
WHITELIST whitelistlabel whitelistcontent
0797
2014-05-18
pjp
{
0798
2014-05-18
pjp
if ((confstatus & CONFIG_VERSION) != CONFIG_VERSION) {
0799
2014-05-18
pjp
dolog(LOG_INFO, "There must be a version at the top of the first configfile\n");
0800
2014-05-18
pjp
return (-1);
0801
2014-05-18
pjp
}
0802
2014-05-18
pjp
}
0803
2014-05-18
pjp
;
0804
2014-05-18
pjp
0805
2014-05-18
pjp
whitelistlabel:
0806
2014-05-18
pjp
QUOTEDSTRING
0807
2014-05-18
pjp
;
0808
2014-05-18
pjp
0809
2014-05-18
pjp
whitelistcontent:
0810
2014-05-18
pjp
OBRACE whiteliststatements EBRACE
0811
2014-05-18
pjp
| OBRACE CRLF whiteliststatements EBRACE
0812
2014-05-18
pjp
;
0813
2014-05-18
pjp
0814
2014-05-18
pjp
whiteliststatements :
0815
2014-05-18
pjp
whiteliststatements whiteliststatement
0816
2014-05-18
pjp
| whiteliststatement
0817
2014-05-18
pjp
;
0818
2014-05-18
pjp
0819
2014-05-18
pjp
whiteliststatement : ipcidr SEMICOLON CRLF
0820
2014-05-18
pjp
{
0821
2014-05-18
pjp
char prefixlength[INET_ADDRSTRLEN];
0822
2014-05-18
pjp
char *dst;
0823
2014-05-18
pjp
0824
2014-05-18
pjp
0825
2014-05-18
pjp
if ((dst = get_prefixlen($1, (char *)&prefixlength, sizeof(prefixlength))) == NULL) {
0826
2014-05-18
pjp
return (-1);
0827
2014-05-18
pjp
}
0828
2014-05-18
pjp
0829
2014-05-18
pjp
if (insert_whitelist(dst, prefixlength) < 0) {
0830
2014-05-18
pjp
dolog(LOG_ERR, "insert_whitelist, line %d\n", file->lineno);
0831
2014-05-18
pjp
return (-1);
0832
2014-05-18
pjp
}
0833
2014-05-18
pjp
0834
2014-05-18
pjp
if (debug)
0835
2014-05-18
pjp
printf("recurse inserted %s address\n", $1);
0836
2014-05-18
pjp
0837
2014-05-18
pjp
whitelist = 1;
0838
2014-05-18
pjp
0839
2014-05-18
pjp
free (dst);
0840
2014-05-18
pjp
free ($1);
0841
2014-05-18
pjp
}
0842
2014-05-18
pjp
| comment CRLF
0843
2014-05-18
pjp
;
0844
2014-05-18
pjp
0845
2014-05-01
pjp
/* filter "these hosts" { .. } */
0846
2014-05-01
pjp
0847
2014-05-01
pjp
filter:
0848
2014-05-01
pjp
FILTER filterlabel filtercontent
0849
2014-05-01
pjp
{
0850
2014-05-01
pjp
if ((confstatus & CONFIG_VERSION) != CONFIG_VERSION) {
0851
2014-05-01
pjp
dolog(LOG_INFO, "There must be a version at the top of the first configfile\n");
0852
2014-05-01
pjp
return (-1);
0853
2014-05-01
pjp
}
0854
2014-05-01
pjp
}
0855
2014-05-01
pjp
;
0856
2014-05-01
pjp
0857
2014-05-01
pjp
filterlabel:
0858
2014-05-01
pjp
QUOTEDSTRING
0859
2014-05-01
pjp
;
0860
2014-05-01
pjp
0861
2014-05-01
pjp
filtercontent:
0862
2014-05-01
pjp
OBRACE filterstatements EBRACE
0863
2014-05-01
pjp
| OBRACE CRLF filterstatements EBRACE
0864
2014-05-01
pjp
;
0865
2014-05-01
pjp
0866
2014-05-01
pjp
filterstatements :
0867
2014-05-01
pjp
filterstatements filterstatement
0868
2014-05-01
pjp
| filterstatement
0869
2014-05-01
pjp
;
0870
2014-05-01
pjp
0871
2014-05-01
pjp
filterstatement : ipcidr SEMICOLON CRLF
0872
2014-05-01
pjp
{
0873
2014-05-01
pjp
char prefixlength[INET_ADDRSTRLEN];
0874
2014-05-01
pjp
char *dst;
0875
2014-05-01
pjp
0876
2014-05-01
pjp
0877
2014-05-01
pjp
if ((dst = get_prefixlen($1, (char *)&prefixlength, sizeof(prefixlength))) == NULL) {
0878
2014-05-01
pjp
return (-1);
0879
2014-05-01
pjp
}
0880
2014-05-01
pjp
0881
2014-05-01
pjp
if (insert_filter(dst, prefixlength) < 0) {
0882
2014-05-01
pjp
dolog(LOG_ERR, "insert_filter, line %d\n", file->lineno);
0883
2014-05-01
pjp
return (-1);
0884
2014-05-01
pjp
}
0885
2014-05-01
pjp
0886
2014-05-01
pjp
if (debug)
0887
2014-05-01
pjp
printf("recurse inserted %s address\n", $1);
0888
2014-05-01
pjp
0889
2014-05-01
pjp
free (dst);
0890
2014-05-01
pjp
free ($1);
0891
2014-05-01
pjp
}
0892
2014-05-01
pjp
| comment CRLF
0893
2014-05-01
pjp
;
0894
2014-05-01
pjp
0895
2014-05-01
pjp
0896
2014-05-17
pjp
/* notify "these hosts" { .. } */
0897
2014-05-17
pjp
0898
2014-05-17
pjp
notify:
0899
2014-05-17
pjp
NOTIFY notifylabel notifycontent
0900
2014-05-17
pjp
{
0901
2014-05-17
pjp
if ((confstatus & CONFIG_VERSION) != CONFIG_VERSION) {
0902
2014-05-17
pjp
dolog(LOG_INFO, "There must be a version at the top of the first configfile\n");
0903
2014-05-17
pjp
return (-1);
0904
2014-05-17
pjp
}
0905
2014-05-17
pjp
}
0906
2014-05-17
pjp
;
0907
2014-05-17
pjp
0908
2014-05-17
pjp
notifylabel:
0909
2014-05-17
pjp
QUOTEDSTRING
0910
2014-05-17
pjp
;
0911
2014-05-17
pjp
0912
2014-05-17
pjp
notifycontent:
0913
2014-05-17
pjp
OBRACE notifystatements EBRACE
0914
2014-05-17
pjp
| OBRACE CRLF notifystatements EBRACE
0915
2014-05-17
pjp
;
0916
2014-05-17
pjp
0917
2014-05-17
pjp
notifystatements :
0918
2014-05-17
pjp
notifystatements notifystatement
0919
2014-05-17
pjp
| notifystatement
0920
2014-05-17
pjp
;
0921
2014-05-17
pjp
0922
2014-05-17
pjp
notifystatement : ipcidr SEMICOLON CRLF
0923
2014-05-17
pjp
{
0924
2014-05-17
pjp
char prefixlength[INET_ADDRSTRLEN];
0925
2014-05-17
pjp
char *dst;
0926
2014-05-17
pjp
0927
2014-05-17
pjp
0928
2014-05-17
pjp
if ((dst = get_prefixlen($1, (char *)&prefixlength, sizeof(prefixlength))) == NULL) {
0929
2014-05-17
pjp
return (-1);
0930
2014-05-17
pjp
}
0931
2014-05-17
pjp
0932
2014-05-17
pjp
if (insert_notifyslave(dst, prefixlength) < 0) {
0933
2014-05-17
pjp
dolog(LOG_ERR, "insert_notifyslave, line %d\n", file->lineno);
0934
2014-05-17
pjp
return (-1);
0935
2014-05-17
pjp
}
0936
2014-05-17
pjp
0937
2014-05-17
pjp
notify++;
0938
2014-05-17
pjp
0939
2014-05-17
pjp
free (dst);
0940
2014-05-17
pjp
free ($1);
0941
2014-05-17
pjp
}
0942
2014-05-17
pjp
| comment CRLF
0943
2014-05-17
pjp
;
0944
2014-05-17
pjp
0945
2014-04-12
pjp
/* axfr-for "these hosts" { .. } */
0946
2014-04-12
pjp
0947
2014-04-12
pjp
axfr:
0948
2014-04-12
pjp
AXFRFOR axfrlabel axfrcontent
0949
2014-04-12
pjp
{
0950
2014-04-12
pjp
if ((confstatus & CONFIG_VERSION) != CONFIG_VERSION) {
0951
2014-04-12
pjp
dolog(LOG_INFO, "There must be a version at the top of the first configfile\n");
0952
2014-04-12
pjp
return (-1);
0953
2014-04-12
pjp
}
0954
2014-04-12
pjp
}
0955
2014-04-12
pjp
;
0956
2014-04-12
pjp
0957
2014-04-12
pjp
axfrlabel:
0958
2014-04-12
pjp
QUOTEDSTRING
0959
2014-04-12
pjp
;
0960
2014-04-12
pjp
0961
2014-04-12
pjp
axfrcontent:
0962
2014-04-12
pjp
OBRACE axfrstatements EBRACE
0963
2014-04-12
pjp
| OBRACE CRLF axfrstatements EBRACE
0964
2014-04-12
pjp
;
0965
2014-04-12
pjp
0966
2014-04-12
pjp
axfrstatements :
0967
2014-04-12
pjp
axfrstatements axfrstatement
0968
2014-04-12
pjp
| axfrstatement
0969
2014-04-12
pjp
;
0970
2014-04-12
pjp
0971
2014-04-12
pjp
axfrstatement : ipcidr SEMICOLON CRLF
0972
2014-04-12
pjp
{
0973
2014-04-12
pjp
char prefixlength[INET_ADDRSTRLEN];
0974
2014-04-12
pjp
char *dst;
0975
2014-04-12
pjp
0976
2014-04-12
pjp
0977
2014-04-12
pjp
if ((dst = get_prefixlen($1, (char *)&prefixlength, sizeof(prefixlength))) == NULL) {
0978
2014-04-12
pjp
return (-1);
0979
2014-04-12
pjp
}
0980
2014-04-12
pjp
0981
2014-04-12
pjp
if (insert_axfr(dst, prefixlength) < 0) {
0982
2014-04-12
pjp
dolog(LOG_ERR, "insert_axfr, line %d\n", file->lineno);
0983
2014-04-12
pjp
return (-1);
0984
2014-04-12
pjp
}
0985
2014-04-12
pjp
0986
2014-04-13
pjp
if (debug)
0987
2014-04-13
pjp
printf("recurse inserted %s address\n", $1);
0988
2014-04-13
pjp
0989
2014-04-12
pjp
free (dst);
0990
2014-04-12
pjp
free ($1);
0991
2014-04-12
pjp
}
0992
2014-04-12
pjp
| comment CRLF
0993
2014-04-12
pjp
;
0994
2014-04-12
pjp
0995
2014-04-12
pjp
/* recurse-for "these hosts" { .. } */
0996
2014-04-12
pjp
0997
2014-04-12
pjp
recurse:
0998
2014-04-12
pjp
RECURSEFOR recurselabel recursecontent
0999
2014-04-12
pjp
{
1000
2014-04-12
pjp
if ((confstatus & CONFIG_VERSION) != CONFIG_VERSION) {
1001
2014-04-12
pjp
dolog(LOG_INFO, "There must be a version at the top of the first configfile\n");
1002
2014-04-12
pjp
return (-1);
1003
2014-04-12
pjp
}
1004
2014-04-12
pjp
}
1005
2014-04-12
pjp
;
1006
2014-04-12
pjp
1007
2014-04-12
pjp
recurselabel:
1008
2014-04-12
pjp
QUOTEDSTRING
1009
2014-04-12
pjp
;
1010
2014-04-12
pjp
1011
2014-04-12
pjp
recursecontent:
1012
2014-04-12
pjp
OBRACE recursestatements EBRACE
1013
2014-04-12
pjp
| OBRACE CRLF recursestatements EBRACE
1014
2014-04-12
pjp
;
1015
2014-04-12
pjp
1016
2014-04-12
pjp
recursestatements :
1017
2014-04-12
pjp
recursestatements recursestatement
1018
2014-04-12
pjp
| recursestatement
1019
2014-04-12
pjp
;
1020
2014-04-12
pjp
1021
2014-04-12
pjp
recursestatement : ipcidr SEMICOLON CRLF
1022
2014-04-12
pjp
{
1023
2014-04-12
pjp
char prefixlength[INET_ADDRSTRLEN];
1024
2014-04-12
pjp
char *dst;
1025
2014-04-12
pjp
1026
2014-04-12
pjp
if ((dst = get_prefixlen($1, (char *)&prefixlength, sizeof(prefixlength))) == NULL) {
1027
2014-04-12
pjp
return (-1);
1028
2014-04-12
pjp
}
1029
2014-04-12
pjp
1030
2014-04-12
pjp
if (insert_recurse(dst, prefixlength) < 0) {
1031
2014-04-12
pjp
dolog(LOG_ERR, "insert_recurse, line %d\n", file->lineno);
1032
2014-04-12
pjp
return (-1);
1033
2014-04-12
pjp
}
1034
2014-04-12
pjp
1035
2014-04-13
pjp
if (debug)
1036
2014-04-13
pjp
printf("recurse inserted %s address\n", $1);
1037
2014-04-12
pjp
1038
2014-04-12
pjp
free (dst);
1039
2014-04-12
pjp
free ($1);
1040
2014-04-12
pjp
}
1041
2014-04-12
pjp
| comment CRLF
1042
2014-04-12
pjp
;
1043
2014-04-12
pjp
1044
2014-04-12
pjp
1045
2014-04-12
pjp
/* wildcard-only-for "these hosts" { .. } */
1046
2014-04-12
pjp
1047
2014-04-12
pjp
wof:
1048
2014-04-12
pjp
WOF woflabel wofcontent
1049
2014-04-12
pjp
{
1050
2014-04-12
pjp
if ((confstatus & CONFIG_VERSION) != CONFIG_VERSION) {
1051
2014-04-12
pjp
dolog(LOG_INFO, "There must be a version at the top of the first configfile\n");
1052
2014-04-12
pjp
return (-1);
1053
2014-04-12
pjp
}
1054
2014-04-12
pjp
}
1055
2014-04-12
pjp
;
1056
2014-04-12
pjp
1057
2014-04-12
pjp
woflabel:
1058
2014-04-12
pjp
QUOTEDSTRING
1059
2014-04-12
pjp
;
1060
2014-04-12
pjp
1061
2014-04-12
pjp
wofcontent:
1062
2014-04-12
pjp
OBRACE wofstatements EBRACE
1063
2014-04-12
pjp
| OBRACE CRLF wofstatements EBRACE
1064
2014-04-12
pjp
;
1065
2014-04-12
pjp
1066
2014-04-12
pjp
wofstatements :
1067
2014-04-12
pjp
wofstatements wofstatement
1068
2014-04-12
pjp
| wofstatement
1069
2014-04-12
pjp
;
1070
2014-04-12
pjp
1071
2014-04-12
pjp
wofstatement : ipcidr SEMICOLON CRLF
1072
2014-04-12
pjp
{
1073
2014-04-12
pjp
char prefixlength[INET_ADDRSTRLEN];
1074
2014-04-12
pjp
char *dst;
1075
2014-04-12
pjp
1076
2014-04-12
pjp
if ((dst = get_prefixlen($1, (char *)&prefixlength, sizeof(prefixlength))) == NULL) {
1077
2014-04-12
pjp
1078
2014-04-12
pjp
return (-1);
1079
2014-04-12
pjp
}
1080
2014-04-12
pjp
1081
2014-04-12
pjp
if (insert_wildcard(dst, prefixlength) < 0) {
1082
2014-04-12
pjp
dolog(LOG_ERR, "insert_wildcard, line %d\n", file->lineno);
1083
2014-04-12
pjp
return (-1);
1084
2014-04-12
pjp
}
1085
2014-04-12
pjp
1086
2014-04-13
pjp
if (debug)
1087
2014-04-13
pjp
printf("wildcard inserted %s address\n", $1);
1088
2014-04-12
pjp
1089
2014-04-12
pjp
free (dst);
1090
2014-04-12
pjp
free ($1);
1091
2014-04-12
pjp
}
1092
2014-04-12
pjp
| comment CRLF
1093
2014-04-12
pjp
;
1094
2014-04-12
pjp
1095
2014-04-12
pjp
1096
2014-04-12
pjp
/* region "lacnic" { .. } */
1097
2014-04-12
pjp
1098
2014-04-12
pjp
region:
1099
2014-04-12
pjp
REGION regionlabel regioncontent
1100
2014-04-12
pjp
{
1101
2014-04-12
pjp
if ((confstatus & CONFIG_VERSION) != CONFIG_VERSION) {
1102
2014-04-12
pjp
dolog(LOG_INFO, "There must be a version at the top of the first configfile\n");
1103
2014-04-12
pjp
return (-1);
1104
2014-04-12
pjp
}
1105
2014-04-12
pjp
1106
2014-04-12
pjp
region++;
1107
2014-04-12
pjp
}
1108
2014-04-12
pjp
;
1109
2014-04-12
pjp
1110
2014-04-12
pjp
regionlabel:
1111
2014-04-12
pjp
QUOTEDSTRING
1112
2014-04-12
pjp
;
1113
2014-04-12
pjp
1114
2014-04-12
pjp
regioncontent:
1115
2014-04-12
pjp
OBRACE regionstatements EBRACE
1116
2014-04-12
pjp
| OBRACE CRLF regionstatements EBRACE
1117
2014-04-12
pjp
;
1118
2014-04-12
pjp
1119
2014-04-12
pjp
regionstatements :
1120
2014-04-12
pjp
regionstatements regionstatement
1121
2014-04-12
pjp
| regionstatement
1122
2014-04-12
pjp
;
1123
2014-04-12
pjp
1124
2014-04-12
pjp
regionstatement : ipcidr SEMICOLON CRLF
1125
2014-04-12
pjp
{
1126
2014-04-12
pjp
char prefixlength[INET_ADDRSTRLEN];
1127
2014-04-12
pjp
char *dst;
1128
2014-04-12
pjp
1129
2014-04-12
pjp
if ((dst = get_prefixlen($1, (char *)&prefixlength, sizeof(prefixlength))) == NULL) {
1130
2014-04-12
pjp
return (-1);
1131
2014-04-12
pjp
}
1132
2014-04-12
pjp
1133
2014-04-12
pjp
if (insert_region(dst, prefixlength, region) < 0) {
1134
2014-04-12
pjp
dolog(LOG_ERR, "insert_region, line %d\n", file->lineno);
1135
2014-04-12
pjp
return (-1);
1136
2014-04-12
pjp
}
1137
2014-04-13
pjp
1138
2014-04-13
pjp
if (debug)
1139
2014-04-13
pjp
printf("%s ipv4 address\n", dst);
1140
2014-04-12
pjp
1141
2014-04-12
pjp
free (dst);
1142
2014-04-12
pjp
free ($1);
1143
2014-04-12
pjp
}
1144
2014-04-12
pjp
| comment CRLF
1145
2014-04-12
pjp
;
1146
2014-04-12
pjp
1147
2014-04-12
pjp
ipcidr:
1148
2014-04-12
pjp
IP
1149
2014-04-12
pjp
| IPV6
1150
2014-04-12
pjp
;
1151
2014-04-12
pjp
1152
2014-04-12
pjp
1153
2014-04-12
pjp
%%
1154
2014-04-12
pjp
1155
2014-04-12
pjp
struct tab {
1156
2014-04-12
pjp
char *val;
1157
2014-04-12
pjp
int num;
1158
2014-04-12
pjp
int state;
1159
2014-04-12
pjp
};
1160
2014-04-12
pjp
1161
2014-04-12
pjp
1162
2014-04-12
pjp
struct tab cmdtab[] = {
1163
2014-04-12
pjp
{ "axfrport", AXFRPORT, 0},
1164
2014-04-12
pjp
{ "axfr-for", AXFRFOR, STATE_IP },
1165
2014-05-18
pjp
{ "whitelist", WHITELIST, STATE_IP },
1166
2014-05-01
pjp
{ "filter", FILTER, STATE_IP },
1167
2014-04-15
pjp
{ "include", INCLUDE, 0 },
1168
2014-04-15
pjp
{ "logging", LOGGING, 0 },
1169
2014-04-15
pjp
{ "options", OPTIONS, 0 },
1170
2014-04-12
pjp
{ "recurse-for", RECURSEFOR, STATE_IP },
1171
2014-04-15
pjp
{ "region", REGION, STATE_IP },
1172
2014-04-12
pjp
{ "wildcard-only-for", WOF, STATE_IP },
1173
2014-04-15
pjp
{ "version", VERSION, 0 },
1174
2014-04-12
pjp
{ "zone", ZONE, 0 },
1175
2014-05-17
pjp
{ "notify", NOTIFY, STATE_IP },
1176
2014-04-12
pjp
{ NULL, 0, 0}};
1177
2014-04-12
pjp
1178
2014-05-18
pjp
1179
2014-05-18
pjp
1180
2014-05-18
pjp
void
1181
2014-05-18
pjp
yyerror(const char *str)
1182
2014-05-18
pjp
{
1183
2014-05-18
pjp
dolog(LOG_ERR, "%s file: %s line: %d\n", str, file->name, file->lineno);
1184
2014-05-18
pjp
slave_shutdown();
1185
2014-05-18
pjp
exit (1);
1186
2014-05-18
pjp
}
1187
2014-05-18
pjp
1188
2014-05-18
pjp
int
1189
2014-05-18
pjp
yywrap()
1190
2014-05-18
pjp
{
1191
2014-05-18
pjp
return 1;
1192
2014-05-18
pjp
}
1193
2014-05-18
pjp
1194
2014-04-12
pjp
int
1195
2014-05-18
pjp
parse_file(DB *db, char *filename)
1196
2014-05-18
pjp
{
1197
2014-05-18
pjp
int errors;
1198
2014-05-18
pjp
1199
2014-05-18
pjp
mydb = db;
1200
2014-05-18
pjp
1201
2014-05-18
pjp
memset(&logging, 0, sizeof(struct logging));
1202
2014-05-18
pjp
logging.active = 0;
1203
2014-05-18
pjp
1204
2014-05-18
pjp
1205
2014-05-18
pjp
if ((file = pushfile(filename, 0)) == NULL) {
1206
2014-05-18
pjp
return (-1);
1207
2014-05-18
pjp
}
1208
2014-05-18
pjp
1209
2014-05-18
pjp
topfile = file;
1210
2014-05-18
pjp
1211
2014-05-18
pjp
if (yyparse() < 0) {
1212
2014-05-18
pjp
dolog(LOG_ERR, "error: %s line: %d\n", file->name, file->lineno);
1213
2014-05-18
pjp
return (-1);
1214
2014-05-18
pjp
}
1215
2014-05-18
pjp
errors = file->errors;
1216
2014-05-18
pjp
popfile();
1217
2014-05-18
pjp
1218
2014-05-18
pjp
dolog(LOG_INFO, "configuration file read\n");
1219
2014-05-18
pjp
1220
2014-05-18
pjp
return 0;
1221
2014-05-18
pjp
}
1222
2014-05-18
pjp
1223
2014-05-18
pjp
int
1224
2014-04-12
pjp
yylex()
1225
2014-04-12
pjp
{
1226
2014-04-12
pjp
struct tab *p;
1227
2014-04-12
pjp
static char buf[512];
1228
2014-04-12
pjp
static char dst[INET6_ADDRSTRLEN];
1229
2014-04-12
pjp
char *cp = NULL;
1230
2014-04-12
pjp
int c, cpos;
1231
2014-04-12
pjp
static int setupstate = 0;
1232
2014-04-12
pjp
1233
2014-04-12
pjp
1234
2014-04-12
pjp
do {
1235
2014-04-12
pjp
c = lgetc(0);
1236
2014-04-12
pjp
} while ((c == ' ') || (c == '\t'));
1237
2014-04-12
pjp
1238
2014-04-12
pjp
if (c == EOF)
1239
2014-04-12
pjp
return 0;
1240
2014-04-12
pjp
1241
2014-04-12
pjp
if (c == '\n') {
1242
2014-04-12
pjp
file->lineno++;
1243
2014-04-12
pjp
1244
2014-04-12
pjp
while ((c = lgetc(0)) != EOF && (c == '\n' || c == '\t'))
1245
2014-04-12
pjp
if (c == '\n')
1246
2014-04-12
pjp
file->lineno++;
1247
2014-04-12
pjp
lungetc(c);
1248
2014-04-12
pjp
1249
2014-04-12
pjp
1250
2014-04-12
pjp
#ifdef LEXDEBUG
1251
2014-04-13
pjp
if (debug)
1252
2014-04-13
pjp
printf("returning %s\n", "crlf");
1253
2014-04-12
pjp
#endif
1254
2014-04-12
pjp
1255
2014-04-12
pjp
return CRLF;
1256
2014-04-12
pjp
}
1257
2014-04-12
pjp
1258
2014-04-12
pjp
switch (state) {
1259
2014-04-12
pjp
case STATE_IP:
1260
2014-04-12
pjp
if (c == ':' || isalnum(c)) {
1261
2014-04-12
pjp
lungetc(c);
1262
2014-04-14
pjp
get_ip(buf, sizeof(buf) - 1);
1263
2014-04-12
pjp
1264
2014-04-12
pjp
yylval.v.string = strdup(buf);
1265
2014-04-12
pjp
if (yylval.v.string == NULL) {
1266
2014-04-12
pjp
dolog(LOG_ERR, "yylex: %s\n", strerror(errno));
1267
2014-04-12
pjp
slave_shutdown();
1268
2014-04-12
pjp
exit(1);
1269
2014-04-12
pjp
}
1270
2014-04-12
pjp
#ifdef LEXDEBUG
1271
2014-04-13
pjp
if (debug)
1272
2014-04-13
pjp
printf("returning %s\n", "IP");
1273
2014-04-12
pjp
#endif
1274
2014-04-12
pjp
return (IP);
1275
2014-04-12
pjp
}
1276
2014-04-12
pjp
/* FALLTHROUGH */
1277
2014-04-12
pjp
default:
1278
2014-04-12
pjp
if (c == '}') {
1279
2014-04-12
pjp
#ifdef LEXDEBUG
1280
2014-04-13
pjp
if (debug)
1281
2014-04-13
pjp
printf("returning %s\n", "ebrace");
1282
2014-04-12
pjp
#endif
1283
2014-04-12
pjp
setupstate = 0;
1284
2014-04-12
pjp
state = 0;
1285
2014-04-12
pjp
return EBRACE;
1286
2014-04-12
pjp
}
1287
2014-04-12
pjp
1288
2014-04-12
pjp
if (c == '{') {
1289
2014-04-12
pjp
if (setupstate)
1290
2014-04-12
pjp
state = setupstate;
1291
2014-04-12
pjp
#ifdef LEXDEBUG
1292
2014-04-13
pjp
if (debug)
1293
2014-04-13
pjp
printf("returning %s\n", "obrace");
1294
2014-04-12
pjp
#endif
1295
2014-04-12
pjp
return OBRACE;
1296
2014-04-12
pjp
}
1297
2014-04-12
pjp
1298
2014-04-12
pjp
if (c == '/') {
1299
2014-04-12
pjp
#ifdef LEXDEBUG
1300
2014-04-13
pjp
if (debug)
1301
2014-04-13
pjp
printf("returning %s\n", "slash");
1302
2014-04-12
pjp
#endif
1303
2014-04-12
pjp
return SLASH;
1304
2014-04-12
pjp
}
1305
2014-04-12
pjp
1306
2014-04-12
pjp
if (c == ',') {
1307
2014-04-12
pjp
#ifdef LEXDEBUG
1308
2014-04-13
pjp
if (debug)
1309
2014-04-13
pjp
printf("returning %s\n", "comma");
1310
2014-04-12
pjp
#endif
1311
2014-04-12
pjp
return COMMA;
1312
2014-04-12
pjp
}
1313
2014-04-12
pjp
1314
2014-04-12
pjp
1315
2014-04-12
pjp
if (c == ';') {
1316
2014-04-12
pjp
while ((c = lgetc(0)) != EOF && c != '\n');
1317
2014-04-12
pjp
lungetc(c);
1318
2014-04-12
pjp
#ifdef LEXDEBUG
1319
2014-04-13
pjp
if (debug)
1320
2014-04-13
pjp
printf("returning %s\n", "semicolon");
1321
2014-04-12
pjp
#endif
1322
2014-04-12
pjp
return SEMICOLON;
1323
2014-04-12
pjp
}
1324
2014-04-12
pjp
1325
2014-04-12
pjp
if (c == '#') {
1326
2014-04-12
pjp
while ((c = lgetc(0)) != EOF && c != '\n');
1327
2014-04-12
pjp
lungetc(c);
1328
2014-04-12
pjp
#ifdef LEXDEBUG
1329
2014-04-13
pjp
if (debug)
1330
2014-04-13
pjp
printf("returning %s\n", "pound");
1331
2014-04-12
pjp
#endif
1332
2014-04-12
pjp
return POUND;
1333
2014-04-12
pjp
}
1334
2014-04-12
pjp
1335
2014-04-12
pjp
if (c == '"') {
1336
2014-04-13
pjp
get_quotedstring(buf, sizeof(buf) - 1);
1337
2014-04-12
pjp
1338
2014-04-13
pjp
if ((cp = strrchr(buf, '"'))) {
1339
2014-04-12
pjp
cpos = cp - buf;
1340
2014-04-12
pjp
c = buf[cpos];
1341
2014-04-12
pjp
buf[cpos] = '\0';
1342
2014-04-12
pjp
}
1343
2014-04-12
pjp
1344
2014-04-12
pjp
yylval.v.string = strdup(buf);
1345
2014-04-12
pjp
if (yylval.v.string == NULL) {
1346
2014-04-12
pjp
dolog(LOG_ERR, "yylex: %s\n", strerror(errno));
1347
2014-04-12
pjp
slave_shutdown();
1348
2014-04-12
pjp
exit(1);
1349
2014-04-12
pjp
}
1350
2014-04-12
pjp
1351
2014-04-12
pjp
#ifdef LEXDEBUG
1352
2014-04-13
pjp
if (debug)
1353
2014-04-13
pjp
printf("returning %s\n", "quotedstring");
1354
2014-04-12
pjp
#endif
1355
2014-04-12
pjp
return QUOTEDSTRING;
1356
2014-04-12
pjp
}
1357
2014-04-12
pjp
1358
2014-04-12
pjp
if (c == '*') {
1359
2014-04-12
pjp
yylval.v.string = strdup("*");
1360
2014-04-12
pjp
if (yylval.v.string == NULL) {
1361
2014-04-12
pjp
dolog(LOG_ERR, "yylex: %s\n", strerror(errno));
1362
2014-04-12
pjp
slave_shutdown();
1363
2014-04-12
pjp
exit(1);
1364
2014-04-12
pjp
}
1365
2014-04-12
pjp
#ifdef LEXDEBUG
1366
2014-04-13
pjp
if (debug)
1367
2014-04-13
pjp
printf("returning %s\n", "string");
1368
2014-04-12
pjp
#endif
1369
2014-04-12
pjp
return STRING;
1370
2014-04-12
pjp
}
1371
2014-04-12
pjp
1372
2014-04-12
pjp
if (isalnum(c) || c == '.' || c == ':' || c == '-' || c == '_') {
1373
2014-04-12
pjp
lungetc(c);
1374
2014-04-14
pjp
get_string(buf, sizeof(buf) - 1);
1375
2014-04-12
pjp
1376
2014-04-12
pjp
if ((cp = strpbrk(buf, " \n"))) {
1377
2014-04-12
pjp
cpos = cp - buf;
1378
2014-04-12
pjp
c = buf[cpos];
1379
2014-04-12
pjp
buf[cpos] = '\0';
1380
2014-04-12
pjp
}
1381
2014-04-12
pjp
1382
2014-04-12
pjp
p = lookup(cmdtab, buf);
1383
2014-04-12
pjp
if (p != NULL) {
1384
2014-04-12
pjp
#ifdef LEXDEBUG
1385
2014-04-13
pjp
if (debug)
1386
2014-04-13
pjp
printf("returning %s\n", p->val);
1387
2014-04-12
pjp
#endif
1388
2014-04-12
pjp
yylval.v.string = strdup(p->val);
1389
2014-04-12
pjp
if (yylval.v.string == NULL) {
1390
2014-04-12
pjp
dolog(LOG_ERR, "yylex: %s\n", strerror(errno));
1391
2014-04-12
pjp
slave_shutdown();
1392
2014-04-12
pjp
exit(1);
1393
2014-04-12
pjp
}
1394
2014-04-12
pjp
setupstate = p->state;
1395
2014-04-12
pjp
return (p->num);
1396
2014-04-12
pjp
}
1397
2014-04-12
pjp
1398
2014-04-12
pjp
yylval.v.string = strdup(buf);
1399
2014-04-12
pjp
if (yylval.v.string == NULL) {
1400
2014-04-12
pjp
dolog(LOG_ERR, "yylex: %s\n", strerror(errno));
1401
2014-04-12
pjp
slave_shutdown();
1402
2014-04-12
pjp
exit(1);
1403
2014-04-12
pjp
}
1404
2014-04-12
pjp
1405
2014-04-12
pjp
1406
2014-04-12
pjp
memset(&dst, 0, sizeof(dst));
1407
2014-04-12
pjp
if (strchr(buf, ':') != NULL) {
1408
2014-04-12
pjp
if (inet_net_pton(AF_INET6, buf, &dst, sizeof(dst)) == -1) {
1409
2014-04-12
pjp
if (errno == EAFNOSUPPORT &&
1410
2014-04-12
pjp
temp_inet_net_pton_ipv6(buf, &dst, sizeof(dst)) != -1)
1411
2014-04-13
pjp
#if LEXDEBUG
1412
2014-04-13
pjp
if (debug)
1413
2014-04-13
pjp
printf("returning IPV6\n");
1414
2014-04-13
pjp
#endif
1415
2014-04-12
pjp
return IPV6;
1416
2014-04-12
pjp
} else {
1417
2014-04-12
pjp
1418
2014-04-13
pjp
#if LEXDEBUG
1419
2014-04-13
pjp
if (debug)
1420
2014-04-13
pjp
printf("returning IPV6\n");
1421
2014-04-13
pjp
#endif
1422
2014-04-12
pjp
return IPV6;
1423
2014-04-12
pjp
}
1424
2014-04-12
pjp
}
1425
2014-04-12
pjp
1426
2014-04-12
pjp
memset(&dst, 0, sizeof(dst));
1427
2014-04-12
pjp
if (strchr(buf, '.') != NULL &&
1428
2014-04-12
pjp
inet_net_pton(AF_INET, buf, &dst, sizeof(dst)) != -1){
1429
2014-04-13
pjp
#if LEXDEBUG
1430
2014-04-13
pjp
if (debug)
1431
2014-04-13
pjp
printf("returning %s\n", "IP");
1432
2014-04-12
pjp
#endif
1433
2014-04-12
pjp
return IP;
1434
2014-04-12
pjp
}
1435
2014-04-12
pjp
1436
2014-04-12
pjp
for (cp = &buf[0]; *cp != '\0'; cp++) {
1437
2014-11-07
pjp
if ((! isdigit((int)*cp)) && (*cp != '.'))
1438
2014-04-12
pjp
break;
1439
2014-04-12
pjp
}
1440
2014-04-12
pjp
1441
2014-04-12
pjp
if (*cp != '\0' || (buf[0] == '.' && buf[1] == '\0')) {
1442
2014-04-12
pjp
#ifdef LEXDEBUG
1443
2014-04-16
pjp
printf("returning %s (%s)\n", "STRING", buf);
1444
2014-04-12
pjp
#endif
1445
2014-04-12
pjp
return (STRING);
1446
2014-04-12
pjp
}
1447
2014-04-12
pjp
1448
2014-04-12
pjp
#ifdef LEXDEBUG
1449
2014-04-12
pjp
dolog(LOG_DEBUG, "returning %s\n", "NUMBER");
1450
2014-04-12
pjp
#endif
1451
2014-04-12
pjp
1452
2014-04-12
pjp
free (yylval.v.string);
1453
2014-04-12
pjp
yylval.v.intval = atoi(buf);
1454
2014-04-12
pjp
1455
2014-04-12
pjp
return (NUMBER);
1456
2014-04-12
pjp
}
1457
2014-04-12
pjp
1458
2014-04-12
pjp
break;
1459
2014-04-12
pjp
}
1460
2014-04-12
pjp
1461
2014-04-12
pjp
return (c);
1462
2014-04-12
pjp
}
1463
2014-04-12
pjp
1464
2014-04-12
pjp
int
1465
2014-04-13
pjp
get_quotedstring(char *buf, int n)
1466
2014-04-12
pjp
{
1467
2014-04-12
pjp
int i, c;
1468
2014-04-13
pjp
int stack = 0;
1469
2014-04-12
pjp
char *cs;
1470
2014-04-12
pjp
1471
2014-04-12
pjp
cs = buf;
1472
2014-04-12
pjp
1473
2014-04-12
pjp
for (i = 0; --n > 0; ++i) {
1474
2014-04-12
pjp
c = lgetc(0);
1475
2014-04-13
pjp
if (c == '\n') {
1476
2014-04-12
pjp
*cs = '\0';
1477
2014-04-13
pjp
lungetc(c);
1478
2014-04-12
pjp
return (0);
1479
2014-04-13
pjp
} else if (c == '"') {
1480
2014-04-13
pjp
if (stack == 0) {
1481
2014-04-14
pjp
*cs++ = c;
1482
2014-04-13
pjp
*cs = '\0';
1483
2014-04-13
pjp
return (0);
1484
2014-04-13
pjp
} else {
1485
2014-04-13
pjp
stack--;
1486
2014-04-13
pjp
}
1487
2014-04-13
pjp
} else if (c == '\\') {
1488
2014-04-13
pjp
if (stack == 0) {
1489
2014-04-13
pjp
stack++;
1490
2014-04-13
pjp
continue;
1491
2014-04-13
pjp
} else {
1492
2014-04-13
pjp
stack--;
1493
2014-04-13
pjp
}
1494
2014-04-13
pjp
} else
1495
2014-04-13
pjp
stack = 0;
1496
2014-04-13
pjp
1497
2014-04-12
pjp
1498
2014-04-12
pjp
*cs++ = c;
1499
2014-04-12
pjp
}
1500
2014-04-12
pjp
1501
2014-04-12
pjp
return (1);
1502
2014-04-12
pjp
}
1503
2014-04-12
pjp
1504
2014-04-12
pjp
int
1505
2014-04-14
pjp
get_string(char *buf, int n)
1506
2014-04-12
pjp
{
1507
2014-04-12
pjp
int i, c;
1508
2014-04-12
pjp
char *cs;
1509
2014-04-12
pjp
1510
2014-04-12
pjp
cs = buf;
1511
2014-04-12
pjp
1512
2014-04-12
pjp
for (i = 0; --n > 0; ++i) {
1513
2014-04-12
pjp
c = lgetc(0);
1514
2014-04-12
pjp
if (c == '\n' || c == ' ' || c == ',' || c == ';' || ! (isprint(c) || c == '-' || c == '_')) {
1515
2014-04-12
pjp
*cs = '\0';
1516
2014-04-12
pjp
lungetc(c);
1517
2014-04-12
pjp
return (0);
1518
2014-04-12
pjp
}
1519
2014-04-12
pjp
1520
2014-04-12
pjp
*cs++ = c;
1521
2014-04-12
pjp
}
1522
2014-04-12
pjp
1523
2014-04-12
pjp
return (1);
1524
2014-04-12
pjp
}
1525
2014-04-12
pjp
1526
2014-04-12
pjp
struct rrtab *
1527
2014-04-12
pjp
rrlookup(struct rrtab *p, char *keyword)
1528
2014-04-12
pjp
{
1529
2014-04-12
pjp
1530
2014-04-12
pjp
for (; p->name != NULL; p++) {
1531
2014-04-12
pjp
if (strcasecmp(p->name, keyword) == 0)
1532
2014-04-12
pjp
return (p);
1533
2014-04-12
pjp
}
1534
2014-04-12
pjp
1535
2014-04-12
pjp
return (NULL);
1536
2014-04-12
pjp
}
1537
2014-04-12
pjp
1538
2014-04-12
pjp
struct tab *
1539
2014-04-12
pjp
lookup(struct tab *cmdtab, char *keyword)
1540
2014-04-12
pjp
{
1541
2014-04-12
pjp
struct tab *p;
1542
2014-04-12
pjp
1543
2014-04-12
pjp
for (p = cmdtab; p->val != NULL; p++) {
1544
2014-04-12
pjp
if (strcmp(p->val, keyword) == 0)
1545
2014-04-12
pjp
return (p);
1546
2014-04-12
pjp
}
1547
2014-04-12
pjp
1548
2014-04-12
pjp
return (NULL);
1549
2014-04-12
pjp
}
1550
2014-04-12
pjp
1551
2014-04-12
pjp
int
1552
2014-04-14
pjp
get_ip(char *buf, int n)
1553
2014-04-12
pjp
{
1554
2014-04-12
pjp
int i, c;
1555
2014-04-12
pjp
char *cs;
1556
2014-04-12
pjp
1557
2014-04-12
pjp
cs = buf;
1558
2014-04-12
pjp
1559
2014-04-12
pjp
for (i = 0; --n > 0; ++i) {
1560
2014-04-12
pjp
c = lgetc(0);
1561
2014-04-12
pjp
if (c == ',' || c == '\n' || ! (isalnum(c) || c == '/' || c == ':' || c == '.')) {
1562
2014-04-12
pjp
*cs = '\0';
1563
2014-04-12
pjp
lungetc(c);
1564
2014-04-12
pjp
return (0);
1565
2014-04-12
pjp
}
1566
2014-04-12
pjp
1567
2014-04-12
pjp
*cs++ = c;
1568
2014-04-12
pjp
}
1569
2014-04-12
pjp
1570
2014-04-12
pjp
return (1);
1571
2014-04-12
pjp
}
1572
2014-04-12
pjp
1573
2014-04-12
pjp
char *
1574
2014-04-12
pjp
check_rr(char *domainname, char *mytype, int itype, int *converted_namelen)
1575
2014-04-12
pjp
{
1576
2014-04-12
pjp
struct rrtab *rr;
1577
2014-04-12
pjp
char *converted_name, *p;
1578
2014-04-12
pjp
int i;
1579
2014-04-12
pjp
1580
2014-04-12
pjp
1581
2014-04-12
pjp
if ((rr = rrlookup(myrrtab, mytype)) == NULL) {
1582
2014-04-12
pjp
dolog(LOG_ERR, "error input line %d\n", file->lineno);
1583
2014-04-12
pjp
slave_shutdown();
1584
2014-04-12
pjp
exit(1);
1585
2014-04-12
pjp
}
1586
2014-04-12
pjp
1587
2014-04-12
pjp
if (rr->type != itype) {
1588
2014-04-12
pjp
dolog(LOG_ERR, "error input line %d, expected itype = %d, had %d\n", file->lineno, itype, rr->type);
1589
2014-04-12
pjp
return NULL;
1590
2014-04-12
pjp
}
1591
2014-04-12
pjp
1592
2014-04-12
pjp
if (strlen(domainname) > (DNS_MAXNAME - 2)) {
1593
2014-04-12
pjp
dolog(LOG_ERR, "domain name too long, line %d\n", file->lineno);
1594
2014-04-12
pjp
slave_shutdown();
1595
2014-04-12
pjp
exit(1);
1596
2014-04-12
pjp
}
1597
2014-04-12
pjp
1598
2014-04-12
pjp
for (i = 0, p = domainname; i < strlen(domainname); i++) {
1599
2014-11-07
pjp
*p = tolower((int)*p);
1600
2014-04-12
pjp
p++;
1601
2014-04-12
pjp
}
1602
2014-04-12
pjp
1603
2014-04-12
pjp
if ((strlen(domainname) == 1) && (domainname[0] == '.')) {
1604
2014-04-12
pjp
converted_name = malloc(1);
1605
2014-04-12
pjp
if (converted_name == NULL) {
1606
2014-04-12
pjp
dolog(LOG_ERR, "malloc failed\n");
1607
2014-04-12
pjp
slave_shutdown();
1608
2014-04-12
pjp
exit(1);
1609
2014-04-12
pjp
}
1610
2014-04-12
pjp
1611
2014-04-12
pjp
*converted_namelen = 1;
1612
2014-04-12
pjp
*converted_name = '\0';
1613
2014-04-12
pjp
} else if ((strlen(domainname) == 1) && (domainname[0] == '*')) {
1614
2014-04-12
pjp
converted_name = malloc(1);
1615
2014-04-12
pjp
if (converted_name == NULL) {
1616
2014-04-12
pjp
dolog(LOG_ERR, "malloc failed\n");
1617
2014-04-12
pjp
slave_shutdown();
1618
2014-04-12
pjp
exit(1);
1619
2014-04-12
pjp
}
1620
2014-04-12
pjp
1621
2014-04-12
pjp
*converted_namelen = 1;
1622
2014-04-12
pjp
*converted_name = '*';
1623
2014-04-12
pjp
} else {
1624
2014-04-12
pjp
converted_name = dns_label(domainname, converted_namelen);
1625
2014-04-12
pjp
1626
2014-04-12
pjp
if (converted_name == NULL) {
1627
2014-04-12
pjp
dolog(LOG_ERR, "error processing domain name line %d\n", file->lineno);
1628
2014-04-12
pjp
slave_shutdown();
1629
2014-04-12
pjp
exit(1);
1630
2014-04-12
pjp
}
1631
2014-04-12
pjp
}
1632
2014-04-12
pjp
1633
2014-04-12
pjp
return (converted_name);
1634
2014-04-12
pjp
}
1635
2014-04-12
pjp
1636
2014-04-12
pjp
int
1637
2014-04-12
pjp
fill_cname(char *name, char *type, int myttl, char *hostname)
1638
2014-04-12
pjp
{
1639
2014-04-12
pjp
struct domain sdomain;
1640
2014-04-12
pjp
char *myname, *converted_name;
1641
2014-04-12
pjp
int len, converted_namelen;
1642
2014-04-12
pjp
int i ;
1643
2014-04-12
pjp
1644
2014-04-12
pjp
for (i = 0; i < strlen(name); i++) {
1645
2014-11-07
pjp
name[i] = tolower((int)name[i]);
1646
2014-04-12
pjp
}
1647
2014-04-12
pjp
1648
2014-04-12
pjp
converted_name = check_rr(name, type, DNS_TYPE_CNAME, &converted_namelen);
1649
2014-04-12
pjp
if (converted_name == NULL) {
1650
2014-04-12
pjp
return -1;
1651
2014-04-12
pjp
}
1652
2014-04-12
pjp
1653
2014-04-12
pjp
memset(&sdomain, 0, sizeof(sdomain));
1654
2014-04-12
pjp
if (get_record(&sdomain, converted_name, converted_namelen) < 0) {
1655
2014-04-12
pjp
return (-1);
1656
2014-04-12
pjp
}
1657
2014-04-12
pjp
1658
2014-04-12
pjp
#ifdef __linux__
1659
2014-04-13
pjp
strncpy((char *)sdomain.zonename, (char *)name, DNS_MAXNAME + 1);
1660
2014-04-12
pjp
sdomain.zonename[DNS_MAXNAME] = '\0';
1661
2014-04-12
pjp
#else
1662
2014-04-13
pjp
strlcpy((char *)sdomain.zonename, (char *)name, DNS_MAXNAME + 1);
1663
2014-04-12
pjp
#endif
1664
2014-04-12
pjp
memcpy(sdomain.zone, converted_name, converted_namelen);
1665
2014-04-12
pjp
sdomain.zonelen = converted_namelen;
1666
2014-04-12
pjp
1667
2014-04-12
pjp
sdomain.ttl = myttl;
1668
2014-04-12
pjp
1669
2014-04-12
pjp
myname = dns_label(hostname, (int *)&len);
1670
2014-04-12
pjp
if (myname == NULL) {
1671
2014-04-12
pjp
dolog(LOG_INFO, "illegal nameserver, skipping line %d\n", file->lineno);
1672
2014-04-12
pjp
return 0;
1673
2014-04-12
pjp
}
1674
2014-04-12
pjp
1675
2014-04-12
pjp
if (len > 0xff || len < 0) {
1676
2014-04-12
pjp
dolog(LOG_INFO, "illegal len value , line %d\n", file->lineno);
1677
2014-04-12
pjp
return -1;
1678
2014-04-12
pjp
}
1679
2014-04-12
pjp
1680
2014-04-12
pjp
sdomain.cnamelen = len;
1681
2014-04-12
pjp
memcpy((char *)&sdomain.cname[0], myname, len);
1682
2014-04-12
pjp
1683
2014-04-12
pjp
free(myname);
1684
2014-04-12
pjp
1685
2014-04-12
pjp
sdomain.flags |= DOMAIN_HAVE_CNAME;
1686
2014-04-12
pjp
1687
2014-04-12
pjp
set_record(&sdomain, converted_name, converted_namelen);
1688
2014-04-12
pjp
1689
2014-04-12
pjp
if (converted_name)
1690
2014-04-12
pjp
free (converted_name);
1691
2014-04-12
pjp
1692
2014-04-12
pjp
return (0);
1693
2014-04-12
pjp
1694
2014-04-12
pjp
}
1695
2014-04-12
pjp
1696
2014-04-12
pjp
int
1697
2014-04-12
pjp
fill_ptr(char *name, char *type, int myttl, char *hostname)
1698
2014-04-12
pjp
{
1699
2014-04-12
pjp
struct domain sdomain;
1700
2014-04-12
pjp
int len, converted_namelen;
1701
2014-04-12
pjp
char *myname, *converted_name;
1702
2014-04-12
pjp
int i;
1703
2014-04-12
pjp
1704
2014-04-12
pjp
for (i = 0; i < strlen(name); i++) {
1705
2014-11-07
pjp
name[i] = tolower((int)name[i]);
1706
2014-04-12
pjp
}
1707
2014-04-12
pjp
1708
2014-04-12
pjp
converted_name = check_rr(name, type, DNS_TYPE_PTR, &converted_namelen);
1709
2014-04-12
pjp
if (converted_name == NULL) {
1710
2014-04-12
pjp
return -1;
1711
2014-04-12
pjp
}
1712
2014-04-12
pjp
1713
2014-04-12
pjp
memset(&sdomain, 0, sizeof(sdomain));
1714
2014-04-12
pjp
if (get_record(&sdomain, converted_name, converted_namelen) < 0) {
1715
2014-04-12
pjp
return (-1);
1716
2014-04-12
pjp
}
1717
2014-04-12
pjp
1718
2014-04-12
pjp
#ifdef __linux__
1719
2014-04-13
pjp
strncpy((char *)sdomain.zonename, (char *)name, DNS_MAXNAME + 1);
1720
2014-04-12
pjp
sdomain.zonename[DNS_MAXNAME] = '\0';
1721
2014-04-12
pjp
#else
1722
2014-04-13
pjp
strlcpy((char *)sdomain.zonename, (char *)name, DNS_MAXNAME + 1);
1723
2014-04-12
pjp
#endif
1724
2014-04-12
pjp
memcpy(sdomain.zone, converted_name, converted_namelen);
1725
2014-04-12
pjp
sdomain.zonelen = converted_namelen;
1726
2014-04-12
pjp
1727
2014-04-12
pjp
sdomain.ttl = myttl;
1728
2014-04-12
pjp
1729
2014-04-12
pjp
myname = dns_label(hostname, (int *)&len);
1730
2014-04-12
pjp
if (myname == NULL) {
1731
2014-04-12
pjp
dolog(LOG_INFO, "illegal nameserver, skipping line %d\n", file->lineno);
1732
2014-04-12
pjp
return 0;
1733
2014-04-12
pjp
}
1734
2014-04-12
pjp
1735
2014-04-12
pjp
if (len > 0xff || len < 0) {
1736
2014-04-12
pjp
dolog(LOG_INFO, "illegal len value , line %d\n", file->lineno);
1737
2014-04-12
pjp
return -1;
1738
2014-04-12
pjp
}
1739
2014-04-12
pjp
1740
2014-04-12
pjp
sdomain.ptrlen = len;
1741
2014-04-12
pjp
memcpy((char *)&sdomain.ptr[0], myname, len);
1742
2014-04-12
pjp
1743
2014-04-12
pjp
free(myname);
1744
2014-04-12
pjp
1745
2014-04-12
pjp
sdomain.flags |= DOMAIN_HAVE_PTR;
1746
2014-04-12
pjp
1747
2014-04-12
pjp
set_record(&sdomain, converted_name, converted_namelen);
1748
2014-04-13
pjp
1749
2014-04-13
pjp
if (converted_name)
1750
2014-04-13
pjp
free (converted_name);
1751
2014-04-13
pjp
1752
2014-04-13
pjp
return (0);
1753
2014-04-13
pjp
1754
2014-04-13
pjp
}
1755
2014-04-13
pjp
1756
2014-04-21
pjp
/* based on fill_txt */
1757
2014-04-13
pjp
int
1758
2014-04-21
pjp
fill_spf(char *name, char *type, int myttl, char *msg)
1759
2014-04-21
pjp
{
1760
2014-04-21
pjp
struct domain sdomain;
1761
2014-04-21
pjp
int converted_namelen;
1762
2014-04-21
pjp
char *converted_name;
1763
2014-04-21
pjp
int len, i;
1764
2014-04-21
pjp
1765
2014-04-21
pjp
for (i = 0; i < strlen(name); i++) {
1766
2014-11-07
pjp
name[i] = tolower((int)name[i]);
1767
2014-04-21
pjp
}
1768
2014-04-21
pjp
1769
2014-04-21
pjp
if ((len = strlen(msg)) > 255) {
1770
2014-04-21
pjp
dolog(LOG_ERR, "SPF record too long line %d\n", file->lineno);
1771
2014-04-21
pjp
return (-1);
1772
2014-04-21
pjp
}
1773
2014-04-21
pjp
1774
2014-04-21
pjp
converted_name = check_rr(name, type, DNS_TYPE_SPF, &converted_namelen);
1775
2014-04-21
pjp
if (converted_name == NULL) {
1776
2014-04-21
pjp
return -1;
1777
2014-04-21
pjp
}
1778
2014-04-21
pjp
1779
2014-04-21
pjp
memset(&sdomain, 0, sizeof(sdomain));
1780
2014-04-21
pjp
if (get_record(&sdomain, converted_name, converted_namelen) < 0) {
1781
2014-04-21
pjp
return (-1);
1782
2014-04-21
pjp
}
1783
2014-04-21
pjp
1784
2014-04-21
pjp
#ifdef __linux__
1785
2014-04-21
pjp
strncpy((char *)sdomain.zonename, (char *)name, DNS_MAXNAME + 1);
1786
2014-04-21
pjp
sdomain.zonename[DNS_MAXNAME] = '\0';
1787
2014-04-21
pjp
#else
1788
2014-04-21
pjp
strlcpy((char *)sdomain.zonename, (char *)name, DNS_MAXNAME + 1);
1789
2014-04-21
pjp
#endif
1790
2014-04-21
pjp
memcpy(sdomain.zone, converted_name, converted_namelen);
1791
2014-04-21
pjp
sdomain.zonelen = converted_namelen;
1792
2014-04-21
pjp
1793
2014-04-21
pjp
sdomain.ttl = myttl;
1794
2014-04-21
pjp
1795
2014-04-21
pjp
memcpy(&sdomain.spf, msg, len);
1796
2014-04-21
pjp
sdomain.spflen = len;
1797
2014-04-21
pjp
1798
2014-04-21
pjp
sdomain.flags |= DOMAIN_HAVE_SPF;
1799
2014-04-21
pjp
1800
2014-04-21
pjp
set_record(&sdomain, converted_name, converted_namelen);
1801
2014-04-21
pjp
1802
2014-04-21
pjp
if (converted_name)
1803
2014-04-21
pjp
free (converted_name);
1804
2014-04-21
pjp
1805
2014-04-21
pjp
return (0);
1806
2014-04-21
pjp
1807
2014-04-21
pjp
}
1808
2014-04-21
pjp
1809
2014-05-11
pjp
1810
2014-04-21
pjp
int
1811
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
2014-05-11
pjp
{
1813
2014-05-11
pjp
struct domain sdomain;
1814
2014-05-11
pjp
int converted_namelen;
1815
2014-05-11
pjp
char *converted_name, *naptrname;
1816
2014-05-11
pjp
int flagslen, serviceslen, regexplen, replacementlen;
1817
2014-05-11
pjp
int i, naptr_namelen;
1818
2014-05-11
pjp
1819
2014-05-11
pjp
for (i = 0; i < strlen(name); i++) {
1820
2014-11-07
pjp
name[i] = tolower((int)name[i]);
1821
2014-05-11
pjp
}
1822
2014-05-11
pjp
1823
2014-05-11
pjp
if ((flagslen = strlen(flags)) > 255 ||
1824
2014-05-11
pjp
(serviceslen = strlen(services)) > 255 ||
1825
2014-05-11
pjp
(regexplen = strlen(regexp)) > 255 ||
1826
2014-05-11
pjp
(replacementlen = strlen(replacement)) > 255) {
1827
2014-05-11
pjp
1828
2014-05-11
pjp
dolog(LOG_ERR, "NAPTR record too long line %d\n", file->lineno);
1829
2014-05-11
pjp
return (-1);
1830
2014-05-11
pjp
}
1831
2014-05-11
pjp
1832
2014-05-11
pjp
converted_name = check_rr(name, type, DNS_TYPE_NAPTR, &converted_namelen);
1833
2014-05-11
pjp
if (converted_name == NULL) {
1834
2014-05-11
pjp
return -1;
1835
2014-05-11
pjp
}
1836
2014-05-11
pjp
1837
2014-05-11
pjp
memset(&sdomain, 0, sizeof(sdomain));
1838
2014-05-11
pjp
if (get_record(&sdomain, converted_name, converted_namelen) < 0) {
1839
2014-05-11
pjp
return (-1);
1840
2014-05-11
pjp
}
1841
2014-05-11
pjp
1842
2014-05-11
pjp
#ifdef __linux__
1843
2014-05-11
pjp
strncpy((char *)sdomain.zonename, (char *)name, DNS_MAXNAME + 1);
1844
2014-05-11
pjp
sdomain.zonename[DNS_MAXNAME] = '\0';
1845
2014-05-11
pjp
#else
1846
2014-05-11
pjp
strlcpy((char *)sdomain.zonename, (char *)name, DNS_MAXNAME + 1);
1847
2014-05-11
pjp
#endif
1848
2014-05-11
pjp
memcpy(sdomain.zone, converted_name, converted_namelen);
1849
2014-05-11
pjp
sdomain.zonelen = converted_namelen;
1850
2014-05-11
pjp
1851
2014-05-11
pjp
sdomain.ttl = myttl;
1852
2014-05-11
pjp
1853
2014-05-11
pjp
sdomain.naptr[sdomain.naptr_count].order = order;
1854
2014-05-11
pjp
sdomain.naptr[sdomain.naptr_count].preference = preference;
1855
2014-05-11
pjp
1856
2014-05-11
pjp
memcpy(&sdomain.naptr[sdomain.naptr_count].flags, flags, flagslen);
1857
2014-05-11
pjp
sdomain.naptr[sdomain.naptr_count].flagslen = flagslen;
1858
2014-05-11
pjp
1859
2014-05-11
pjp
memcpy(&sdomain.naptr[sdomain.naptr_count].services, services, serviceslen);
1860
2014-05-11
pjp
sdomain.naptr[sdomain.naptr_count].serviceslen = serviceslen;
1861
2014-05-11
pjp
1862
2014-05-11
pjp
memcpy(&sdomain.naptr[sdomain.naptr_count].regexp, regexp, regexplen);
1863
2014-05-11
pjp
sdomain.naptr[sdomain.naptr_count].regexplen = regexplen;
1864
2014-05-11
pjp
1865
2014-05-11
pjp
naptrname = check_rr(replacement, type, DNS_TYPE_NAPTR, &naptr_namelen);
1866
2014-05-11
pjp
if (naptrname == NULL) {
1867
2014-05-11
pjp
return -1;
1868
2014-05-11
pjp
}
1869
2014-05-11
pjp
1870
2014-05-11
pjp
memcpy(&sdomain.naptr[sdomain.naptr_count].replacement, naptrname, naptr_namelen);
1871
2014-05-11
pjp
sdomain.naptr[sdomain.naptr_count].replacementlen = naptr_namelen;
1872
2014-05-11
pjp
1873
2014-05-11
pjp
sdomain.naptr_count++;
1874
2014-05-11
pjp
1875
2014-05-11
pjp
sdomain.flags |= DOMAIN_HAVE_NAPTR;
1876
2014-05-11
pjp
1877
2014-05-11
pjp
set_record(&sdomain, converted_name, converted_namelen);
1878
2014-05-11
pjp
1879
2014-05-11
pjp
if (naptrname)
1880
2014-05-11
pjp
free (naptrname);
1881
2014-05-11
pjp
1882
2014-05-11
pjp
if (converted_name)
1883
2014-05-11
pjp
free (converted_name);
1884
2014-05-11
pjp
1885
2014-05-11
pjp
return (0);
1886
2014-05-11
pjp
1887
2014-05-11
pjp
}
1888
2014-05-11
pjp
1889
2014-05-11
pjp
int
1890
2014-04-12
pjp
fill_txt(char *name, char *type, int myttl, char *msg)
1891
2014-04-12
pjp
{
1892
2014-04-12
pjp
struct domain sdomain;
1893
2014-04-12
pjp
int converted_namelen;
1894
2014-04-12
pjp
char *converted_name;
1895
2014-04-12
pjp
int len, i;
1896
2014-04-12
pjp
1897
2014-04-12
pjp
for (i = 0; i < strlen(name); i++) {
1898
2014-11-07
pjp
name[i] = tolower((int)name[i]);
1899
2014-04-12
pjp
}
1900
2014-04-12
pjp
1901
2014-04-12
pjp
if ((len = strlen(msg)) > 255) {
1902
2014-04-12
pjp
dolog(LOG_ERR, "TXT record too long line %d\n", file->lineno);
1903
2014-04-12
pjp
return (-1);
1904
2014-04-12
pjp
}
1905
2014-04-12
pjp
1906
2014-04-12
pjp
converted_name = check_rr(name, type, DNS_TYPE_TXT, &converted_namelen);
1907
2014-04-12
pjp
if (converted_name == NULL) {
1908
2014-04-12
pjp
return -1;
1909
2014-04-12
pjp
}
1910
2014-04-12
pjp
1911
2014-04-12
pjp
memset(&sdomain, 0, sizeof(sdomain));
1912
2014-04-12
pjp
if (get_record(&sdomain, converted_name, converted_namelen) < 0) {
1913
2014-04-12
pjp
return (-1);
1914
2014-04-12
pjp
}
1915
2014-04-12
pjp
1916
2014-04-12
pjp
#ifdef __linux__
1917
2014-04-13
pjp
strncpy((char *)sdomain.zonename, (char *)name, DNS_MAXNAME + 1);
1918
2014-04-12
pjp
sdomain.zonename[DNS_MAXNAME] = '\0';
1919
2014-04-12
pjp
#else
1920
2014-04-13
pjp
strlcpy((char *)sdomain.zonename, (char *)name, DNS_MAXNAME + 1);
1921
2014-04-12
pjp
#endif
1922
2014-04-12
pjp
memcpy(sdomain.zone, converted_name, converted_namelen);
1923
2014-04-12
pjp
sdomain.zonelen = converted_namelen;
1924
2014-04-12
pjp
1925
2014-04-12
pjp
sdomain.ttl = myttl;
1926
2014-04-12
pjp
1927
2014-04-12
pjp
memcpy(&sdomain.txt, msg, len);
1928
2014-04-12
pjp
sdomain.txtlen = len;
1929
2014-04-12
pjp
1930
2014-04-12
pjp
sdomain.flags |= DOMAIN_HAVE_TXT;
1931
2014-04-12
pjp
1932
2014-04-12
pjp
set_record(&sdomain, converted_name, converted_namelen);
1933
2014-04-13
pjp
1934
2014-04-13
pjp
if (converted_name)
1935
2014-04-13
pjp
free (converted_name);
1936
2014-04-13
pjp
1937
2014-04-13
pjp
return (0);
1938
2014-04-13
pjp
1939
2014-04-13
pjp
}
1940
2014-04-13
pjp
1941
2014-04-21
pjp
/* based on fill_srv */
1942
2014-04-13
pjp
int
1943
2014-04-21
pjp
fill_sshfp(char *name, char *type, int myttl, int alg, int fptype, char *fingerprint)
1944
2014-04-21
pjp
{
1945
2014-04-21
pjp
struct domain sdomain;
1946
2014-04-21
pjp
int converted_namelen;
1947
2014-04-21
pjp
char *converted_name;
1948
2014-04-22
pjp
char *p, *ep, save;
1949
2014-04-21
pjp
int len, i;
1950
2014-04-21
pjp
1951
2014-04-21
pjp
for (i = 0; i < strlen(name); i++) {
1952
2014-11-07
pjp
name[i] = tolower((int)name[i]);
1953
2014-04-21
pjp
}
1954
2014-04-21
pjp
1955
2014-04-21
pjp
converted_name = check_rr(name, type, DNS_TYPE_SSHFP, &converted_namelen);
1956
2014-04-21
pjp
if (converted_name == NULL) {
1957
2014-04-21
pjp
return -1;
1958
2014-04-21
pjp
}
1959
2014-04-21
pjp
1960
2014-04-21
pjp
memset(&sdomain, 0, sizeof(sdomain));
1961
2014-04-21
pjp
if (get_record(&sdomain, converted_name, converted_namelen) < 0) {
1962
2014-04-21
pjp
return (-1);
1963
2014-04-21
pjp
}
1964
2014-04-21
pjp
1965
2014-04-21
pjp
#ifdef __linux__
1966
2014-04-21
pjp
strncpy((char *)sdomain.zonename, (char *)name, DNS_MAXNAME + 1);
1967
2014-04-21
pjp
sdomain.zonename[DNS_MAXNAME] = '\0';
1968
2014-04-21
pjp
#else
1969
2014-04-21
pjp
strlcpy((char *)sdomain.zonename, (char *)name, DNS_MAXNAME + 1);
1970
2014-04-21
pjp
#endif
1971
2014-04-21
pjp
memcpy(sdomain.zone, converted_name, converted_namelen);
1972
2014-04-21
pjp
sdomain.zonelen = converted_namelen;
1973
2014-04-21
pjp
1974
2014-04-21
pjp
if (sdomain.sshfp_count >= RECORD_COUNT) {
1975
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
2014-04-21
pjp
return (-1);
1977
2014-04-21
pjp
}
1978
2014-04-21
pjp
1979
2014-04-21
pjp
sdomain.ttl = myttl;
1980
2014-04-21
pjp
1981
2014-04-21
pjp
sdomain.sshfp[sdomain.sshfp_count].algorithm = alg;
1982
2014-04-21
pjp
sdomain.sshfp[sdomain.sshfp_count].fptype = fptype;
1983
2014-04-21
pjp
1984
2014-04-21
pjp
switch (fptype) {
1985
2014-04-21
pjp
case 1:
1986
2014-04-21
pjp
len = sdomain.sshfp[sdomain.sshfp_count].fplen = DNS_SSHFP_SIZE_SHA1;
1987
2014-04-21
pjp
break;
1988
2014-04-21
pjp
case 2:
1989
2014-04-21
pjp
len = sdomain.sshfp[sdomain.sshfp_count].fplen = DNS_SSHFP_SIZE_SHA256;
1990
2014-04-21
pjp
break;
1991
2014-04-21
pjp
default:
1992
2014-04-21
pjp
dolog(LOG_ERR, "sshfp: unknown fingerprint type!\n");
1993
2014-04-21
pjp
return -1;
1994
2014-04-21
pjp
}
1995
2014-04-21
pjp
1996
2014-04-22
pjp
p = fingerprint;
1997
2014-04-22
pjp
for (i = 0; i < len; i++) {
1998
2014-04-22
pjp
save = p[2];
1999
2014-04-22
pjp
p[2] = '\0';
2000
2014-04-22
pjp
sdomain.sshfp[sdomain.sshfp_count].fingerprint[i] = strtol(p, &ep, 16);
2001
2014-04-22
pjp
p[2] = save;
2002
2014-04-22
pjp
p += 2;
2003
2014-04-22
pjp
}
2004
2014-04-21
pjp
2005
2014-04-21
pjp
2006
2014-04-21
pjp
sdomain.sshfp_count++;
2007
2014-04-21
pjp
2008
2014-04-21
pjp
sdomain.flags |= DOMAIN_HAVE_SSHFP;
2009
2014-04-21
pjp
2010
2014-04-21
pjp
set_record(&sdomain, converted_name, converted_namelen);
2011
2014-04-21
pjp
2012
2014-04-21
pjp
if (converted_name)
2013
2014-04-21
pjp
free (converted_name);
2014
2014-04-21
pjp
2015
2014-04-21
pjp
return (0);
2016
2014-04-21
pjp
2017
2014-04-21
pjp
}
2018
2014-04-21
pjp
2019
2014-04-21
pjp
int
2020
2014-04-12
pjp
fill_srv(char *name, char *type, int myttl, int priority, int weight, int port, char *srvhost)
2021
2014-04-12
pjp
{
2022
2014-04-12
pjp
struct domain sdomain;
2023
2014-04-12
pjp
int converted_namelen;
2024
2014-04-12
pjp
char *converted_name;
2025
2014-04-12
pjp
char *srvname;
2026
2014-04-12
pjp
int len, i;
2027
2014-04-12
pjp
2028
2014-04-12
pjp
for (i = 0; i < strlen(name); i++) {
2029
2014-11-07
pjp
name[i] = tolower((int)name[i]);
2030
2014-04-12
pjp
}
2031
2014-04-12
pjp
2032
2014-04-12
pjp
converted_name = check_rr(name, type, DNS_TYPE_SRV, &converted_namelen);
2033
2014-04-12
pjp
if (converted_name == NULL) {
2034
2014-04-12
pjp
return -1;
2035
2014-04-12
pjp
}
2036
2014-04-12
pjp
2037
2014-04-12
pjp
memset(&sdomain, 0, sizeof(sdomain));
2038
2014-04-12
pjp
if (get_record(&sdomain, converted_name, converted_namelen) < 0) {
2039
2014-04-12
pjp
return (-1);
2040
2014-04-12
pjp
}
2041
2014-04-12
pjp
2042
2014-04-12
pjp
#ifdef __linux__
2043
2014-04-13
pjp
strncpy((char *)sdomain.zonename, (char *)name, DNS_MAXNAME + 1);
2044
2014-04-12
pjp
sdomain.zonename[DNS_MAXNAME] = '\0';
2045
2014-04-12
pjp
#else
2046
2014-04-13
pjp
strlcpy((char *)sdomain.zonename, (char *)name, DNS_MAXNAME + 1);
2047
2014-04-12
pjp
#endif
2048
2014-04-12
pjp
memcpy(sdomain.zone, converted_name, converted_namelen);
2049
2014-04-12
pjp
sdomain.zonelen = converted_namelen;
2050
2014-04-12
pjp
2051
2014-04-12
pjp
if (sdomain.srv_count >= RECORD_COUNT) {
2052
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
2014-04-12
pjp
return (-1);
2054
2014-04-12
pjp
}
2055
2014-04-12
pjp
2056
2014-04-12
pjp
sdomain.ttl = myttl;
2057
2014-04-12
pjp
2058
2014-04-12
pjp
sdomain.srv[sdomain.srv_count].priority = priority;
2059
2014-04-12
pjp
sdomain.srv[sdomain.srv_count].weight = weight;
2060
2014-04-12
pjp
sdomain.srv[sdomain.srv_count].port = port;
2061
2014-04-12
pjp
2062
2014-04-12
pjp
srvname = dns_label(srvhost, &len);
2063
2014-04-12
pjp
if (srvname == NULL) {
2064
2014-04-12
pjp
dolog(LOG_INFO, "illegal srv server, skipping line %d\n", file->lineno);
2065
2014-04-12
pjp
return (-1);
2066
2014-04-12
pjp
}
2067
2014-04-12
pjp
2068
2014-04-12
pjp
2069
2014-04-12
pjp
sdomain.srv[sdomain.srv_count].targetlen = len;
2070
2014-04-12
pjp
memcpy((char *)&sdomain.srv[sdomain.srv_count].target, srvname, len);
2071
2014-04-12
pjp
2072
2014-04-12
pjp
/* bad hack workaround !!! */
2073
2014-04-12
pjp
if (strcmp(srvhost, ".") == 0 && len > 1)
2074
2014-04-12
pjp
sdomain.srv[sdomain.srv_count].targetlen = 1;
2075
2014-04-12
pjp
2076
2014-04-12
pjp
free (srvname);
2077
2014-04-12
pjp
2078
2014-04-12
pjp
sdomain.srv_count++;
2079
2014-04-12
pjp
2080
2014-04-12
pjp
sdomain.flags |= DOMAIN_HAVE_SRV;
2081
2014-04-12
pjp
2082
2014-04-12
pjp
set_record(&sdomain, converted_name, converted_namelen);
2083
2014-04-12
pjp
2084
2014-04-12
pjp
if (converted_name)
2085
2014-04-12
pjp
free (converted_name);
2086
2014-04-12
pjp
2087
2014-04-12
pjp
return (0);
2088
2014-04-12
pjp
2089
2014-04-12
pjp
}
2090
2014-04-12
pjp
2091
2014-04-12
pjp
int
2092
2014-04-12
pjp
fill_mx(char *name, char *type, int myttl, int priority, char *mxhost)
2093
2014-04-12
pjp
{
2094
2014-04-12
pjp
struct domain sdomain;
2095
2014-04-12
pjp
int converted_namelen;
2096
2014-04-12
pjp
char *converted_name;
2097
2014-04-12
pjp
char *mxname;
2098
2014-04-12
pjp
int len, i;
2099
2014-04-12
pjp
2100
2014-04-12
pjp
for (i = 0; i < strlen(name); i++) {
2101
2014-11-07
pjp
name[i] = tolower((int)name[i]);
2102
2014-04-12
pjp
}
2103
2014-04-12
pjp
2104
2014-04-12
pjp
converted_name = check_rr(name, type, DNS_TYPE_MX, &converted_namelen);
2105
2014-04-12
pjp
if (converted_name == NULL) {
2106
2014-04-12
pjp
return -1;
2107
2014-04-12
pjp
}
2108
2014-04-12
pjp
2109
2014-04-12
pjp
memset(&sdomain, 0, sizeof(sdomain));
2110
2014-04-12
pjp
if (get_record(&sdomain, converted_name, converted_namelen) < 0) {
2111
2014-04-12
pjp
return (-1);
2112
2014-04-12
pjp
}
2113
2014-04-12
pjp
2114
2014-04-12
pjp
#ifdef __linux__
2115
2014-04-13
pjp
strncpy((char *)sdomain.zonename, (char *)name, DNS_MAXNAME + 1);
2116
2014-04-12
pjp
sdomain.zonename[DNS_MAXNAME] = '\0';
2117
2014-04-12
pjp
#else
2118
2014-04-13
pjp
strlcpy((char *)sdomain.zonename, (char *)name, DNS_MAXNAME + 1);
2119
2014-04-12
pjp
#endif
2120
2014-04-12
pjp
memcpy(sdomain.zone, converted_name, converted_namelen);
2121
2014-04-12
pjp
sdomain.zonelen = converted_namelen;
2122
2014-04-12
pjp
2123
2014-04-12
pjp
if (sdomain.mx_count >= RECORD_COUNT) {
2124
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
2014-04-12
pjp
return (-1);
2126
2014-04-12
pjp
}
2127
2014-04-12
pjp
2128
2014-04-12
pjp
sdomain.ttl = myttl;
2129
2014-04-12
pjp
sdomain.mx[sdomain.mx_count].preference = priority;
2130
2014-04-12
pjp
2131
2014-04-12
pjp
mxname = dns_label(mxhost, &len);
2132
2014-04-12
pjp
if (mxname == NULL) {
2133
2014-04-12
pjp
dolog(LOG_INFO, "illegal mx server, skipping line %d\n", file->lineno);
2134
2014-04-12
pjp
return (-1);
2135
2014-04-12
pjp
}
2136
2014-04-12
pjp
2137
2014-04-12
pjp
sdomain.mx[sdomain.mx_count].exchangelen = len;
2138
2014-04-12
pjp
memcpy((char *)&sdomain.mx[sdomain.mx_count].exchange, mxname, len);
2139
2014-04-12
pjp
free (mxname);
2140
2014-04-12
pjp
2141
2014-04-12
pjp
sdomain.mx_count++;
2142
2014-04-12
pjp
2143
2014-04-12
pjp
sdomain.flags |= DOMAIN_HAVE_MX;
2144
2014-04-12
pjp
2145
2014-04-12
pjp
set_record(&sdomain, converted_name, converted_namelen);
2146
2014-04-12
pjp
2147
2014-04-12
pjp
if (converted_name)
2148
2014-04-12
pjp
free (converted_name);
2149
2014-04-12
pjp
2150
2014-04-12
pjp
return (0);
2151
2014-04-12
pjp
2152
2014-04-12
pjp
}
2153
2014-04-12
pjp
2154
2014-04-12
pjp
int
2155
2014-04-12
pjp
fill_balance(char *name, char *type, int myttl, char *a)
2156
2014-04-12
pjp
{
2157
2014-04-12
pjp
struct domain sdomain;
2158
2014-04-12
pjp
int converted_namelen;
2159
2014-04-12
pjp
char *converted_name;
2160
2014-04-12
pjp
struct sockaddr_in sin;
2161
2014-04-12
pjp
in_addr_t *ia;
2162
2014-04-12
pjp
int i;
2163
2014-04-12
pjp
2164
2014-04-12
pjp
for (i = 0; i < strlen(name); i++) {
2165
2014-11-07
pjp
name[i] = tolower((int)name[i]);
2166
2014-04-12
pjp
}
2167
2014-04-12
pjp
2168
2014-04-12
pjp
converted_name = check_rr(name, type, DNS_TYPE_BALANCE, &converted_namelen);
2169
2014-04-12
pjp
if (converted_name == NULL) {
2170
2014-04-12
pjp
return -1;
2171
2014-04-12
pjp
}
2172
2014-04-12
pjp
2173
2014-04-12
pjp
memset(&sdomain, 0, sizeof(sdomain));
2174
2014-04-12
pjp
if (get_record(&sdomain, converted_name, converted_namelen) < 0) {
2175
2014-04-12
pjp
return (-1);
2176
2014-04-12
pjp
}
2177
2014-04-12
pjp
2178
2014-04-12
pjp
#ifdef __linux__
2179
2014-04-13
pjp
strncpy((char *)sdomain.zonename, (char *)name, DNS_MAXNAME + 1);
2180
2014-04-12
pjp
sdomain.zonename[DNS_MAXNAME] = '\0';
2181
2014-04-12
pjp
#else
2182
2014-04-13
pjp
strlcpy((char *)sdomain.zonename, (char *)name, DNS_MAXNAME + 1);
2183
2014-04-12
pjp
#endif
2184
2014-04-12
pjp
memcpy(sdomain.zone, converted_name, converted_namelen);
2185
2014-04-12
pjp
sdomain.zonelen = converted_namelen;
2186
2014-04-12
pjp
2187
2014-04-12
pjp
if (sdomain.a_count >= RECORD_COUNT) {
2188
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
2014-04-12
pjp
return (-1);
2190
2014-04-12
pjp
}
2191
2014-04-12
pjp
2192
2014-04-12
pjp
sdomain.ttl = myttl;
2193
2014-04-12
pjp
ia = (in_addr_t *)&sdomain.a[sdomain.a_count];
2194
2014-04-12
pjp
2195
2014-04-12
pjp
if ((*ia = inet_addr(a)) == INADDR_ANY) {
2196
2014-04-12
pjp
dolog(LOG_INFO, "could not parse BALANCE record on line %d\n", file->lineno);
2197
2014-04-12
pjp
return (-1);
2198
2014-04-12
pjp
}
2199
2014-04-12
pjp
2200
2014-04-12
pjp
2201
2014-04-12
pjp
memset(&sin, 0, sizeof(sin));
2202
2014-04-12
pjp
sin.sin_addr.s_addr = *ia;
2203
2014-04-12
pjp
sin.sin_family = AF_INET;
2204
2014-04-12
pjp
sdomain.region[sdomain.a_count] = find_region((struct sockaddr_storage *)&sin, AF_INET);
2205
2014-04-12
pjp
2206
2014-04-12
pjp
sdomain.a_count++;
2207
2014-04-12
pjp
sdomain.a_ptr = 0;
2208
2014-04-12
pjp
2209
2014-04-12
pjp
sdomain.flags |= DOMAIN_HAVE_A;
2210
2014-04-12
pjp
2211
2014-04-12
pjp
set_record(&sdomain, converted_name, converted_namelen);
2212
2014-04-12
pjp
2213
2014-04-12
pjp
if (converted_name)
2214
2014-04-12
pjp
free (converted_name);
2215
2014-04-12
pjp
2216
2014-04-12
pjp
return (0);
2217
2014-04-12
pjp
2218
2014-04-12
pjp
}
2219
2014-04-12
pjp
2220
2014-04-12
pjp
int
2221
2014-04-12
pjp
fill_a(char *name, char *type, int myttl, char *a)
2222
2014-04-12
pjp
{
2223
2014-04-12
pjp
struct domain sdomain;
2224
2014-04-12
pjp
int converted_namelen;
2225
2014-04-12
pjp
char *converted_name;
2226
2014-04-12
pjp
in_addr_t *ia;
2227
2014-04-12
pjp
int i;
2228
2014-04-12
pjp
2229
2014-04-12
pjp
for (i = 0; i < strlen(name); i++) {
2230
2014-11-07
pjp
name[i] = tolower((int)name[i]);
2231
2014-04-12
pjp
}
2232
2014-04-12
pjp
2233
2014-04-12
pjp
converted_name = check_rr(name, type, DNS_TYPE_A, &converted_namelen);
2234
2014-04-12
pjp
if (converted_name == NULL) {
2235
2014-04-12
pjp
return -1;
2236
2014-04-12
pjp
}
2237
2014-04-12
pjp
2238
2014-04-12
pjp
memset(&sdomain, 0, sizeof(sdomain));
2239
2014-04-12
pjp
if (get_record(&sdomain, converted_name, converted_namelen) < 0) {
2240
2014-04-12
pjp
return (-1);
2241
2014-04-12
pjp
}
2242
2014-04-12
pjp
2243
2014-04-12
pjp
#ifdef __linux__
2244
2014-04-13
pjp
strncpy((char *)sdomain.zonename, (char *)name, DNS_MAXNAME + 1);
2245
2014-04-12
pjp
sdomain.zonename[DNS_MAXNAME] = '\0';
2246
2014-04-12
pjp
#else
2247
2014-04-13
pjp
strlcpy((char *)sdomain.zonename, (char *)name, DNS_MAXNAME + 1);
2248
2014-04-12
pjp
#endif
2249
2014-04-12
pjp
memcpy(sdomain.zone, converted_name, converted_namelen);
2250
2014-04-12
pjp
sdomain.zonelen = converted_namelen;
2251
2014-04-12
pjp
2252
2014-04-12
pjp
if (sdomain.a_count >= RECORD_COUNT) {
2253
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
2014-04-12
pjp
return (-1);
2255
2014-04-12
pjp
}
2256
2014-04-12
pjp
2257
2014-04-12
pjp
sdomain.ttl = myttl;
2258
2014-04-12
pjp
ia = (in_addr_t *)&sdomain.a[sdomain.a_count];
2259
2014-04-12
pjp
2260
2014-04-12
pjp
if ((*ia = inet_addr(a)) == INADDR_ANY) {
2261
2014-04-12
pjp
dolog(LOG_INFO, "could not parse A record on line %d\n", file->lineno);
2262
2014-04-12
pjp
return (-1);
2263
2014-04-12
pjp
}
2264
2014-04-12
pjp
2265
2014-04-12
pjp
sdomain.region[sdomain.a_count] = 0xff;
2266
2014-04-12
pjp
2267
2014-04-12
pjp
sdomain.a_count++;
2268
2014-04-12
pjp
sdomain.a_ptr = 0;
2269
2014-04-12
pjp
2270
2014-04-12
pjp
sdomain.flags |= DOMAIN_HAVE_A;
2271
2014-04-12
pjp
2272
2014-04-12
pjp
set_record(&sdomain, converted_name, converted_namelen);
2273
2014-04-12
pjp
2274
2014-04-12
pjp
if (converted_name)
2275
2014-04-12
pjp
free (converted_name);
2276
2014-04-12
pjp
2277
2014-04-12
pjp
return (0);
2278
2014-04-12
pjp
2279
2014-04-12
pjp
}
2280
2014-04-12
pjp
2281
2014-04-12
pjp
2282
2014-04-12
pjp
int
2283
2014-04-12
pjp
fill_aaaa(char *name, char *type, int myttl, char *aaaa)
2284
2014-04-12
pjp
{
2285
2014-04-12
pjp
struct domain sdomain;
2286
2014-04-12
pjp
int converted_namelen;
2287
2014-04-12
pjp
char *converted_name;
2288
2014-04-12
pjp
struct in6_addr *ia6;
2289
2014-04-12
pjp
int i;
2290
2014-04-12
pjp
2291
2014-04-12
pjp
2292
2014-04-12
pjp
for (i = 0; i < strlen(name); i++) {
2293
2014-11-07
pjp
name[i] = tolower((int)name[i]);
2294
2014-04-12
pjp
}
2295
2014-04-12
pjp
2296
2014-04-12
pjp
converted_name = check_rr(name, type, DNS_TYPE_AAAA, &converted_namelen);
2297
2014-04-12
pjp
if (converted_name == NULL) {
2298
2014-04-12
pjp
return -1;
2299
2014-04-12
pjp
}
2300
2014-04-12
pjp
2301
2014-04-12
pjp
memset(&sdomain, 0, sizeof(sdomain));
2302
2014-04-12
pjp
if (get_record(&sdomain, converted_name, converted_namelen) < 0) {
2303
2014-04-12
pjp
return (-1);
2304
2014-04-12
pjp
}
2305
2014-04-12
pjp
2306
2014-04-12
pjp
#ifdef __linux__
2307
2014-04-13
pjp
strncpy((char *)sdomain.zonename, (char *)name, DNS_MAXNAME + 1);
2308
2014-04-12
pjp
sdomain.zonename[DNS_MAXNAME] = '\0';
2309
2014-04-12
pjp
#else
2310
2014-04-13
pjp
strlcpy((char *)sdomain.zonename, (char *)name, DNS_MAXNAME + 1);
2311
2014-04-12
pjp
#endif
2312
2014-04-12
pjp
memcpy(sdomain.zone, converted_name, converted_namelen);
2313
2014-04-12
pjp
sdomain.zonelen = converted_namelen;
2314
2014-04-12
pjp
2315
2014-04-12
pjp
if (sdomain.aaaa_count >= RECORD_COUNT) {
2316
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
2014-04-12
pjp
return (-1);
2318
2014-04-12
pjp
}
2319
2014-04-12
pjp
2320
2014-04-12
pjp
sdomain.ttl = myttl;
2321
2014-04-12
pjp
ia6 = (struct in6_addr *)&sdomain.aaaa[sdomain.aaaa_count];
2322
2014-04-12
pjp
if (inet_pton(AF_INET6, (char *)aaaa, (char *)ia6) != 1) {
2323
2014-04-13
pjp
dolog(LOG_INFO, "AAAA \"%s\" unparseable line %d\n", aaaa, file->lineno);
2324
2014-04-12
pjp
return -1;
2325
2014-04-12
pjp
}
2326
2014-04-12
pjp
2327
2014-04-12
pjp
sdomain.aaaa_count++;
2328
2014-04-12
pjp
sdomain.aaaa_ptr = 0;
2329
2014-04-12
pjp
2330
2014-04-12
pjp
sdomain.flags |= DOMAIN_HAVE_AAAA;
2331
2014-04-12
pjp
2332
2014-04-12
pjp
set_record(&sdomain, converted_name, converted_namelen);
2333
2014-04-12
pjp
2334
2014-04-12
pjp
if (converted_name)
2335
2014-04-12
pjp
free (converted_name);
2336
2014-04-12
pjp
2337
2014-04-12
pjp
return (0);
2338
2014-04-12
pjp
2339
2014-04-12
pjp
}
2340
2014-04-12
pjp
2341
2014-04-12
pjp
2342
2014-04-12
pjp
int
2343
2014-04-12
pjp
fill_ns(char *name, char *type, int myttl, char *nameserver)
2344
2014-04-12
pjp
{
2345
2014-04-12
pjp
struct domain sdomain;
2346
2014-04-12
pjp
int len, converted_namelen;
2347
2014-04-12
pjp
char *myname, *converted_name;
2348
2014-04-12
pjp
char *n;
2349
2014-04-12
pjp
int nstype, i;
2350
2014-04-12
pjp
2351
2014-04-12
pjp
2352
2014-04-12
pjp
for (i = 0; i < strlen(name); i++) {
2353
2014-11-07
pjp
name[i] = tolower((int)name[i]);
2354
2014-04-12
pjp
}
2355
2014-04-12
pjp
2356
2014-04-12
pjp
if (strcasecmp(type, "ns") == 0) {
2357
2014-04-12
pjp
converted_name = check_rr(name, type, DNS_TYPE_NS, &converted_namelen);
2358
2014-04-12
pjp
nstype = 0;
2359
2014-04-12
pjp
} else if (strcasecmp(type, "hint") == 0) {
2360
2014-04-12
pjp
converted_name = check_rr(name, type, DNS_TYPE_HINT, &converted_namelen);
2361
2014-04-12
pjp
nstype = NS_TYPE_HINT;
2362
2014-04-12
pjp
} else {
2363
2014-04-12
pjp
converted_name = check_rr(name, type, DNS_TYPE_DELEGATE, &converted_namelen);
2364
2014-04-12
pjp
nstype = NS_TYPE_DELEGATE;
2365
2014-04-12
pjp
}
2366
2014-04-12
pjp
2367
2014-04-12
pjp
if (converted_name == NULL) {
2368
2014-04-12
pjp
return -1;
2369
2014-04-12
pjp
}
2370
2014-04-12
pjp
2371
2014-04-12
pjp
memset(&sdomain, 0, sizeof(sdomain));
2372
2014-04-12
pjp
if (get_record(&sdomain, converted_name, converted_namelen) < 0) {
2373
2014-04-12
pjp
return (-1);
2374
2014-04-12
pjp
}
2375
2014-04-12
pjp
2376
2014-04-12
pjp
#ifdef __linux__
2377
2014-04-13
pjp
strncpy((char *)sdomain.zonename, (char *)name, DNS_MAXNAME + 1);
2378
2014-04-12
pjp
sdomain.zonename[DNS_MAXNAME] = '\0';
2379
2014-04-12
pjp
#else
2380
2014-04-13
pjp
strlcpy((char *)sdomain.zonename, (char *)name, DNS_MAXNAME + 1);
2381
2014-04-12
pjp
#endif
2382
2014-04-12
pjp
memcpy(sdomain.zone, converted_name, converted_namelen);
2383
2014-04-12
pjp
sdomain.zonelen = converted_namelen;
2384
2014-04-12
pjp
2385
2014-04-12
pjp
if (sdomain.ns_count >= RECORD_COUNT) {
2386
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
2014-04-12
pjp
return (-1);
2388
2014-04-12
pjp
}
2389
2014-04-12
pjp
2390
2014-04-12
pjp
sdomain.ttl = myttl;
2391
2014-04-12
pjp
2392
2014-04-12
pjp
myname = dns_label(nameserver, (int *)&len);
2393
2014-04-12
pjp
if (myname == NULL) {
2394
2014-04-12
pjp
dolog(LOG_INFO, "illegal nameserver, skipping line %d\n", file->lineno);
2395
2014-04-12
pjp
return 0;
2396
2014-04-12
pjp
}
2397
2014-04-12
pjp
2398
2014-04-12
pjp
if (len > 0xff || len < 0) {
2399
2014-04-12
pjp
dolog(LOG_INFO, "illegal len value , line %d\n", file->lineno);
2400
2014-04-12
pjp
return -1;
2401
2014-04-12
pjp
}
2402
2014-04-12
pjp
2403
2014-04-12
pjp
n = (char *)sdomain.ns[sdomain.ns_count].nsserver;
2404
2014-04-12
pjp
sdomain.ns[sdomain.ns_count].nslen = len;
2405
2014-04-12
pjp
memcpy((char *)n, myname, sdomain.ns[sdomain.ns_count].nslen);
2406
2014-04-12
pjp
2407
2014-04-12
pjp
free(myname);
2408
2014-04-12
pjp
2409
2014-04-12
pjp
sdomain.ns_count++;
2410
2014-04-12
pjp
sdomain.ns_ptr = 0;
2411
2014-04-12
pjp
sdomain.ns_type = nstype;
2412
2014-04-12
pjp
2413
2014-04-12
pjp
sdomain.flags |= DOMAIN_HAVE_NS;
2414
2014-04-12
pjp
2415
2014-04-12
pjp
set_record(&sdomain, converted_name, converted_namelen);
2416
2014-04-12
pjp
2417
2014-04-12
pjp
if (converted_name)
2418
2014-04-12
pjp
free (converted_name);
2419
2014-04-12
pjp
2420
2014-04-12
pjp
return (0);
2421
2014-04-12
pjp
2422
2014-04-12
pjp
}
2423
2014-04-12
pjp
2424
2014-04-12
pjp
2425
2014-04-12
pjp
/* centroid.eu,soa,3600,uranus.centroid.eu.,pjp.solarscale.de.,1258740680,3600,1800,7200,3600 */
2426
2014-04-12
pjp
int
2427
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
2014-04-12
pjp
{
2429
2014-04-12
pjp
struct domain sdomain;
2430
2014-04-12
pjp
int len, converted_namelen;
2431
2014-04-12
pjp
char *myname, *converted_name;
2432
2014-04-12
pjp
int i;
2433
2014-04-12
pjp
2434
2014-04-12
pjp
for (i = 0; i < strlen(name); i++) {
2435
2014-11-07
pjp
name[i] = tolower((int)name[i]);
2436
2014-04-12
pjp
}
2437
2014-04-12
pjp
2438
2014-04-12
pjp
converted_name = check_rr(name, type, DNS_TYPE_SOA, &converted_namelen);
2439
2014-04-12
pjp
if (converted_name == NULL) {
2440
2014-04-12
pjp
dolog(LOG_ERR, "error input line %d\n", file->lineno);
2441
2014-04-12
pjp
return (-1);
2442
2014-04-12
pjp
}
2443
2014-04-12
pjp
2444
2014-04-12
pjp
memset(&sdomain, 0, sizeof(sdomain));
2445
2014-04-12
pjp
if (get_record(&sdomain, converted_name, converted_namelen) < 0) {
2446
2014-04-12
pjp
return (-1);
2447
2014-04-12
pjp
}
2448
2014-04-12
pjp
2449
2014-04-12
pjp
#ifdef __linux__
2450
2014-04-13
pjp
strncpy((char *)sdomain.zonename, (char *)name, DNS_MAXNAME + 1);
2451
2014-04-12
pjp
sdomain.zonename[DNS_MAXNAME] = '\0';
2452
2014-04-12
pjp
#else
2453
2014-04-13
pjp
strlcpy((char *)sdomain.zonename, (char *)name, DNS_MAXNAME + 1);
2454
2014-04-12
pjp
#endif
2455
2014-04-12
pjp
memcpy(sdomain.zone, converted_name, converted_namelen);
2456
2014-04-12
pjp
sdomain.zonelen = converted_namelen;
2457
2014-04-12
pjp
2458
2014-04-12
pjp
sdomain.ttl = myttl;
2459
2014-04-12
pjp
2460
2014-04-12
pjp
myname = dns_label(auth, (int *)&len);
2461
2014-04-12
pjp
if (myname == NULL) {
2462
2014-04-12
pjp
dolog(LOG_INFO, "illegal nameserver, skipping line %d\n", file->lineno);
2463
2014-04-12
pjp
return 0;
2464
2014-04-12
pjp
}
2465
2014-04-12
pjp
2466
2014-04-12
pjp
if (len > 0xff || len < 0) {
2467
2014-04-12
pjp
dolog(LOG_INFO, "illegal len value , line %d\n", file->lineno);
2468
2014-04-12
pjp
return -1;
2469
2014-04-12
pjp
}
2470
2014-04-12
pjp
2471
2014-04-12
pjp
sdomain.soa.nsserver_len = len;
2472
2014-04-12
pjp
memcpy((char *)&sdomain.soa.nsserver[0], myname, len);
2473
2014-04-12
pjp
2474
2014-04-12
pjp
free(myname);
2475
2014-04-12
pjp
2476
2014-04-12
pjp
myname = dns_label(contact, (int *)&len);
2477
2014-04-12
pjp
if (myname == NULL) {
2478
2014-04-12
pjp
dolog(LOG_INFO, "illegal nameserver, skipping line %d\n", file->lineno);
2479
2014-04-12
pjp
return 0;
2480
2014-04-12
pjp
}
2481
2014-04-12
pjp
2482
2014-04-12
pjp
if (len > 0xff || len < 0) {
2483
2014-04-12
pjp
dolog(LOG_INFO, "illegal len value , line %d\n", file->lineno);
2484
2014-04-12
pjp
return -1;
2485
2014-04-12
pjp
}
2486
2014-04-12
pjp
2487
2014-04-12
pjp
sdomain.soa.rp_len = len;
2488
2014-04-12
pjp
memcpy((char *)&sdomain.soa.responsible_person[0], myname, len);
2489
2014-04-12
pjp
2490
2014-04-12
pjp
free (myname);
2491
2014-04-12
pjp
2492
2014-04-12
pjp
sdomain.soa.serial = serial;
2493
2014-04-12
pjp
sdomain.soa.refresh = refresh;
2494
2014-04-12
pjp
sdomain.soa.retry = retry;
2495
2014-04-12
pjp
sdomain.soa.expire = expire;
2496
2014-04-12
pjp
sdomain.soa.minttl = ttl;
2497
2014-04-12
pjp
2498
2014-04-12
pjp
sdomain.flags |= DOMAIN_HAVE_SOA;
2499
2014-04-12
pjp
2500
2014-04-12
pjp
set_record(&sdomain, converted_name, converted_namelen);
2501
2014-04-12
pjp
2502
2014-04-12
pjp
if (converted_name)
2503
2014-04-12
pjp
free (converted_name);
2504
2014-04-12
pjp
2505
2014-04-12
pjp
return (0);
2506
2014-04-12
pjp
2507
2014-04-12
pjp
}
2508
2014-04-12
pjp
2509
2014-04-12
pjp
2510
2014-04-12
pjp
int
2511
2014-04-12
pjp
get_record(struct domain *sdomain, char *converted_name, int converted_namelen)
2512
2014-04-12
pjp
{
2513
2014-04-12
pjp
DB *db = mydb; /* XXX */
2514
2014-04-12
pjp
2515
2014-04-12
pjp
memset(&key, 0, sizeof(key));
2516
2014-04-12
pjp
memset(&data, 0, sizeof(data));
2517
2014-04-12
pjp
2518
2014-04-12
pjp
key.data = (char *)converted_name;
2519
2014-04-12
pjp
key.size = converted_namelen;
2520
2014-04-12
pjp
2521
2014-04-12
pjp
data.data = NULL;
2522
2014-04-12
pjp
data.size = 0;
2523
2014-04-12
pjp
2524
2014-04-12
pjp
if (db->get(db, NULL, &key, &data, 0) == 0) {
2525
2014-05-18
pjp
2526
2014-04-12
pjp
if (data.size != sizeof(struct domain)) {
2527
2014-04-12
pjp
dolog(LOG_INFO, "damaged btree database\n");
2528
2014-04-12
pjp
return -1;
2529
2014-04-12
pjp
}
2530
2014-04-12
pjp
2531
2014-04-12
pjp
memcpy((char *)sdomain, (char *)data.data, data.size);
2532
2014-04-12
pjp
} else {
2533
2014-04-13
pjp
if (debug)
2534
2014-04-13
pjp
dolog(LOG_INFO, "db->get: %s\n", strerror(errno));
2535
2014-04-12
pjp
}
2536
2014-04-12
pjp
2537
2014-04-12
pjp
return 0;
2538
2014-04-12
pjp
}
2539
2014-04-12
pjp
2540
2014-04-12
pjp
2541
2014-04-12
pjp
void
2542
2014-04-12
pjp
set_record(struct domain *sdomain, char *converted_name, int converted_namelen)
2543
2014-04-12
pjp
{
2544
2014-04-12
pjp
DB *db = mydb; /* XXX */
2545
2014-04-12
pjp
int ret;
2546
2014-04-12
pjp
2547
2014-04-12
pjp
/* everythign in parse.y should get this flag! */
2548
2014-04-12
pjp
sdomain->flags |= DOMAIN_STATIC_ZONE;
2549
2014-04-12
pjp
2550
2014-04-12
pjp
memset(&key, 0, sizeof(key));
2551
2014-04-12
pjp
memset(&data, 0, sizeof(data));
2552
2014-04-12
pjp
2553
2014-04-12
pjp
key.data = (char *)converted_name;
2554
2014-04-12
pjp
key.size = converted_namelen;
2555
2014-04-12
pjp
2556
2014-04-12
pjp
data.data = (void*)sdomain;
2557
2014-04-12
pjp
data.size = sizeof(struct domain);
2558
2014-04-12
pjp
2559
2014-04-12
pjp
if ((ret = db->put(db, NULL, &key, &data, 0)) != 0) {
2560
2014-04-12
pjp
dolog(LOG_INFO, "db->put: %s\n" , db_strerror(ret));
2561
2014-04-12
pjp
return;
2562
2014-04-12
pjp
}
2563
2014-04-12
pjp
2564
2014-04-12
pjp
return;
2565
2014-04-12
pjp
}
2566
2014-04-12
pjp
2567
2014-04-12
pjp
2568
2014-04-12
pjp
struct file *
2569
2014-04-12
pjp
pushfile(const char *name, int secret)
2570
2014-04-12
pjp
{
2571
2014-05-17
pjp
struct stat sb;
2572
2014-04-12
pjp
struct file *nfile;
2573
2014-05-17
pjp
int fd;
2574
2014-04-12
pjp
2575
2014-04-12
pjp
if ((nfile = calloc(1, sizeof(struct file))) == NULL) {
2576
2014-05-17
pjp
dolog(LOG_INFO, "warn: malloc\n");
2577
2014-04-12
pjp
return (NULL);
2578
2014-04-12
pjp
}
2579
2014-04-12
pjp
if ((nfile->name = strdup(name)) == NULL) {
2580
2014-05-17
pjp
dolog(LOG_INFO, "warn: malloc\n");
2581
2014-04-12
pjp
free(nfile);
2582
2014-04-12
pjp
return (NULL);
2583
2014-04-12
pjp
}
2584
2014-04-12
pjp
if ((nfile->stream = fopen(nfile->name, "r")) == NULL) {
2585
2014-05-17
pjp
dolog(LOG_INFO, "warn: %s\n", nfile->name);
2586
2014-04-12
pjp
free(nfile->name);
2587
2014-04-12
pjp
free(nfile);
2588
2014-04-12
pjp
return (NULL);
2589
2014-04-12
pjp
}
2590
2014-05-17
pjp
2591
2014-05-17
pjp
fd = fileno(nfile->stream);
2592
2014-05-17
pjp
if (fstat(fd, &sb) < 0) {
2593
2014-05-17
pjp
dolog(LOG_INFO, "warn: %s\n", strerror(errno));
2594
2014-05-17
pjp
}
2595
2014-05-17
pjp
2596
2014-05-17
pjp
/* get the highest time of all included files */
2597
2014-05-17
pjp
if (time_changed < sb.st_ctime)
2598
2014-05-17
pjp
time_changed = (time_t)sb.st_ctime; /* ufs1 is only 32 bits */
2599
2014-05-17
pjp
2600
2014-04-12
pjp
nfile->lineno = 1;
2601
2014-04-12
pjp
TAILQ_INSERT_TAIL(&files, nfile, entry);
2602
2014-04-12
pjp
return (nfile);
2603
2014-04-12
pjp
}
2604
2014-04-12
pjp
2605
2014-04-12
pjp
#define MAXPUSHBACK 128
2606
2014-04-12
pjp
2607
2014-04-12
pjp
char *parsebuf;
2608
2014-04-12
pjp
int parseindex;
2609
2014-04-12
pjp
char pushback_buffer[MAXPUSHBACK];
2610
2014-04-12
pjp
int pushback_index = 0;
2611
2014-04-12
pjp
2612
2014-04-12
pjp
2613
2014-04-12
pjp
int
2614
2014-04-12
pjp
lgetc(int quotec)
2615
2014-04-12
pjp
{
2616
2014-04-13
pjp
int c;
2617
2014-04-12
pjp
2618
2014-04-12
pjp
if (parsebuf) {
2619
2014-04-12
pjp
/* Read character from the parsebuffer instead of input. */
2620
2014-04-12
pjp
if (parseindex >= 0) {
2621
2014-04-12
pjp
c = parsebuf[parseindex++];
2622
2014-04-12
pjp
if (c != '\0')
2623
2014-04-12
pjp
return (c);
2624
2014-04-12
pjp
parsebuf = NULL;
2625
2014-04-12
pjp
} else
2626
2014-04-12
pjp
parseindex++;
2627
2014-04-12
pjp
}
2628
2014-04-12
pjp
2629
2014-04-12
pjp
if (pushback_index)
2630
2014-04-12
pjp
return (pushback_buffer[--pushback_index]);
2631
2014-04-12
pjp
2632
2014-04-12
pjp
if (quotec) {
2633
2014-04-12
pjp
if ((c = getc(file->stream)) == EOF) {
2634
2014-04-12
pjp
yyerror("reached end of file while parsing "
2635
2014-04-12
pjp
"quoted string");
2636
2014-04-12
pjp
if (file == topfile || popfile() == EOF)
2637
2014-04-12
pjp
return (EOF);
2638
2014-04-12
pjp
return (quotec);
2639
2014-04-12
pjp
}
2640
2014-04-12
pjp
return (c);
2641
2014-04-12
pjp
}
2642
2014-04-12
pjp
2643
2014-04-13
pjp
while ((c = getc(file->stream)) == EOF) {
2644
2014-04-12
pjp
if (file == topfile || popfile() == EOF)
2645
2014-04-12
pjp
return (EOF);
2646
2014-04-12
pjp
}
2647
2014-04-12
pjp
return (c);
2648
2014-04-12
pjp
}
2649
2014-04-12
pjp
2650
2014-04-12
pjp
int
2651
2014-04-12
pjp
popfile(void)
2652
2014-04-12
pjp
{
2653
2014-04-12
pjp
struct file *prev;
2654
2014-04-12
pjp
2655
2014-04-12
pjp
if ((prev = TAILQ_PREV(file, files, entry)) != NULL)
2656
2014-04-12
pjp
prev->errors += file->errors;
2657
2014-04-12
pjp
2658
2014-04-12
pjp
TAILQ_REMOVE(&files, file, entry);
2659
2014-04-12
pjp
fclose(file->stream);
2660
2014-04-12
pjp
free(file->name);
2661
2014-04-12
pjp
free(file);
2662
2014-04-12
pjp
file = prev;
2663
2014-04-12
pjp
return (file ? 0 : EOF);
2664
2014-04-12
pjp
}
2665
2014-04-12
pjp
2666
2014-04-12
pjp
2667
2014-04-12
pjp
int
2668
2014-04-12
pjp
lungetc(int c)
2669
2014-04-12
pjp
{
2670
2014-04-12
pjp
if (c == EOF)
2671
2014-04-12
pjp
return (EOF);
2672
2014-04-12
pjp
if (parsebuf) {
2673
2014-04-12
pjp
parseindex--;
2674
2014-04-12
pjp
if (parseindex >= 0)
2675
2014-04-12
pjp
return (c);
2676
2014-04-12
pjp
}
2677
2014-04-12
pjp
if (pushback_index < MAXPUSHBACK-1)
2678
2014-04-12
pjp
return (pushback_buffer[pushback_index++] = c);
2679
2014-04-12
pjp
else
2680
2014-04-12
pjp
return (EOF);
2681
2014-04-12
pjp
}
2682
2014-04-12
pjp
2683
2014-04-12
pjp
int
2684
2014-04-12
pjp
findeol(void)
2685
2014-04-12
pjp
{
2686
2014-04-12
pjp
int c;
2687
2014-04-12
pjp
2688
2014-04-12
pjp
parsebuf = NULL;
2689
2014-04-12
pjp
pushback_index = 0;
2690
2014-04-12
pjp
2691
2014-04-12
pjp
/* skip to either EOF or the first real EOL */
2692
2014-04-12
pjp
while (1) {
2693
2014-04-12
pjp
c = lgetc(0);
2694
2014-04-12
pjp
if (c == '\n') {
2695
2014-04-12
pjp
file->lineno++;
2696
2014-04-12
pjp
break;
2697
2014-04-12
pjp
}
2698
2014-04-12
pjp
if (c == EOF)
2699
2014-04-12
pjp
break;
2700
2014-04-12
pjp
}
2701
2014-04-12
pjp
return (ERROR);
2702
2014-04-12
pjp
}
2703
2014-04-12
pjp
2704
2014-04-12
pjp
2705
2014-04-12
pjp
/*
2706
2014-04-12
pjp
* from opensmtpd, the license at the top is compatible with this stuff
2707
2014-04-12
pjp
*/
2708
2014-04-12
pjp
2709
2014-04-12
pjp
static int
2710
2014-04-12
pjp
temp_inet_net_pton_ipv6(const char *src, void *dst, size_t size)
2711
2014-04-12
pjp
{
2712
2014-04-12
pjp
int ret;
2713
2014-04-12
pjp
int bits;
2714
2014-04-12
pjp
char buf[sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:255:255:255:255/128")];
2715
2014-04-12
pjp
char *sep;
2716
2014-11-07
pjp
#if defined __OpenBSD__ || defined __FreeBSD__
2717
2014-04-12
pjp
const char *errstr;
2718
2014-11-07
pjp
#endif
2719
2014-04-12
pjp
2720
2014-04-12
pjp
#ifndef __linux__
2721
2014-04-12
pjp
if (strlcpy(buf, src, sizeof buf) >= sizeof buf) {
2722
2014-04-12
pjp
errno = EMSGSIZE;
2723
2014-04-12
pjp
return (-1);
2724
2014-04-12
pjp
}
2725
2014-04-12
pjp
#else
2726
2014-04-12
pjp
strncpy(buf, src, sizeof(buf));
2727
2014-04-12
pjp
buf[sizeof(buf) - 1] = '\0';
2728
2014-04-12
pjp
#endif
2729
2014-04-12
pjp
2730
2014-04-12
pjp
sep = strchr(buf, '/');
2731
2014-04-12
pjp
if (sep != NULL)
2732
2014-04-12
pjp
*sep++ = '\0';
2733
2014-04-12
pjp
2734
2014-04-12
pjp
ret = inet_pton(AF_INET6, buf, dst);
2735
2014-04-12
pjp
if (ret != 1) {
2736
2014-04-12
pjp
return (-1);
2737
2014-04-12
pjp
}
2738
2014-04-12
pjp
2739
2014-04-12
pjp
if (sep == NULL)
2740
2014-04-12
pjp
return 128;
2741
2014-04-12
pjp
2742
2014-11-07
pjp
#if ! defined __linux__ && ! defined __APPLE__ && ! defined __NetBSD__
2743
2014-04-12
pjp
bits = strtonum(sep, 0, 128, &errstr);
2744
2014-04-12
pjp
if (errstr)
2745
2014-04-12
pjp
return (-1);
2746
2014-11-07
pjp
#else
2747
2014-11-07
pjp
bits = atoi(sep);
2748
2014-04-12
pjp
#endif
2749
2014-04-12
pjp
2750
2014-04-12
pjp
return bits;
2751
2014-04-12
pjp
}
2752
2014-04-12
pjp
2753
2014-04-12
pjp
2754
2014-04-12
pjp
char *
2755
2014-04-12
pjp
get_prefixlen(char *input, char *prefixlength, int plsize)
2756
2014-04-12
pjp
{
2757
2014-04-12
pjp
int af = AF_INET;
2758
2014-04-12
pjp
int prefixlen;
2759
2014-04-12
pjp
char *ret, *p;
2760
2014-04-12
pjp
2761
2014-04-12
pjp
if (strchr(input, ':') != NULL)
2762
2014-04-12
pjp
af = AF_INET6;
2763
2014-04-12
pjp
2764
2014-04-12
pjp
prefixlen = inet_net_pton(af, input, prefixlength, plsize);
2765
2014-04-12
pjp
if (prefixlen < 0) {
2766
2014-04-12
pjp
if (errno == EAFNOSUPPORT) {
2767
2014-04-12
pjp
prefixlen = temp_inet_net_pton_ipv6(input, prefixlength, plsize);
2768
2014-04-12
pjp
} else {
2769
2014-04-13
pjp
if (debug)
2770
2014-04-13
pjp
printf("not address family %d (%s)\n", af, input);
2771
2014-04-12
pjp
return (NULL);
2772
2014-04-12
pjp
}
2773
2014-04-12
pjp
}
2774
2014-04-12
pjp
2775
2014-04-12
pjp
if ((p = strchr(input, '/')) != NULL) {
2776
2014-04-12
pjp
*p++ = '\0';
2777
2014-04-12
pjp
} else {
2778
2014-04-12
pjp
if (af == AF_INET)
2779
2014-04-12
pjp
p = "32";
2780
2014-04-12
pjp
else
2781
2014-04-12
pjp
p = "128";
2782
2014-04-12
pjp
}
2783
2014-04-12
pjp
2784
2014-04-12
pjp
snprintf(prefixlength, plsize, "%s", p);
2785
2014-04-12
pjp
ret = strdup(input);
2786
2014-04-12
pjp
return (ret);
2787
2014-04-12
pjp
}
repomaster@centroid.eu