Blame
Date:
Sat Aug 1 09:01:52 2020 UTC
Message:
move extended RCODE's out of the RCODE section those are only 0x00 through 0x0F make a section that shows extended RCODE's that are added to a EDNS0 tag.
0001
2019-02-07
pjp
/*
0002
2019-02-07
pjp
* Copyright (c) 2019 Peter J. Philipp
0003
2019-02-07
pjp
* All rights reserved.
0004
2019-02-07
pjp
*
0005
2019-02-07
pjp
* Redistribution and use in source and binary forms, with or without
0006
2019-02-07
pjp
* modification, are permitted provided that the following conditions
0007
2019-02-07
pjp
* are met:
0008
2019-02-07
pjp
* 1. Redistributions of source code must retain the above copyright
0009
2019-02-07
pjp
* notice, this list of conditions and the following disclaimer.
0010
2019-02-07
pjp
* 2. Redistributions in binary form must reproduce the above copyright
0011
2019-02-07
pjp
* notice, this list of conditions and the following disclaimer in the
0012
2019-02-07
pjp
* documentation and/or other materials provided with the distribution.
0013
2019-02-07
pjp
* 3. The name of the author may not be used to endorse or promote products
0014
2019-02-07
pjp
* derived from this software without specific prior written permission
0015
2019-02-07
pjp
*
0016
2019-02-07
pjp
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
0017
2019-02-07
pjp
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
0018
2019-02-07
pjp
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
0019
2019-02-07
pjp
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
0020
2019-02-07
pjp
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
0021
2019-02-07
pjp
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
0022
2019-02-07
pjp
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
0023
2019-02-07
pjp
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0024
2019-02-07
pjp
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
0025
2019-02-07
pjp
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0026
2019-02-07
pjp
*
0027
2019-02-07
pjp
*/
0028
2019-02-07
pjp
/*
0029
2020-07-28
pjp
* $Id: raxfr.c,v 1.61 2020/07/28 05:17:05 pjp Exp $
0030
2019-02-07
pjp
*/
0031
2019-02-07
pjp
0032
2019-06-06
pjp
#include <sys/types.h>
0033
2019-11-02
pjp
#include <sys/select.h>
0034
2019-06-06
pjp
#include <sys/socket.h>
0035
2019-11-02
pjp
#include <sys/uio.h>
0036
2019-11-02
pjp
#include <sys/stat.h>
0037
2019-06-06
pjp
0038
2019-06-06
pjp
#include <netinet/in.h>
0039
2019-06-06
pjp
#include <arpa/inet.h>
0040
2019-06-06
pjp
#include <netdb.h>
0041
2019-06-06
pjp
0042
2019-06-06
pjp
#include <stdio.h>
0043
2019-06-06
pjp
#include <stdlib.h>
0044
2019-11-02
pjp
#include <stdint.h>
0045
2019-06-06
pjp
#include <string.h>
0046
2019-06-06
pjp
#include <ctype.h>
0047
2019-06-06
pjp
#include <errno.h>
0048
2019-11-01
pjp
#include <unistd.h>
0049
2019-11-01
pjp
#include <syslog.h>
0050
2019-06-06
pjp
0051
2019-06-06
pjp
#ifdef __linux__
0052
2019-06-06
pjp
#include <grp.h>
0053
2019-06-06
pjp
#define __USE_BSD 1
0054
2019-06-06
pjp
#include <endian.h>
0055
2019-06-06
pjp
#include <bsd/stdlib.h>
0056
2019-06-06
pjp
#include <bsd/string.h>
0057
2019-06-06
pjp
#include <bsd/sys/queue.h>
0058
2019-06-06
pjp
#define __unused
0059
2019-06-06
pjp
#include <bsd/sys/tree.h>
0060
2019-06-06
pjp
#include <bsd/sys/endian.h>
0061
2019-11-01
pjp
#include "imsg.h"
0062
2019-11-19
pjp
#include "endian.h"
0063
2019-06-06
pjp
#else /* not linux */
0064
2019-06-06
pjp
#include <sys/queue.h>
0065
2019-06-06
pjp
#include <sys/tree.h>
0066
2019-11-02
pjp
#ifdef __FreeBSD__
0067
2019-11-02
pjp
#include "imsg.h"
0068
2019-11-18
pjp
#include "endian.h"
0069
2019-11-02
pjp
#else
0070
2019-11-01
pjp
#include <imsg.h>
0071
2019-11-02
pjp
#endif /* __FreeBSD__ */
0072
2019-06-06
pjp
#endif /* __linux__ */
0073
2019-06-06
pjp
0074
2019-11-05
pjp
#include <openssl/evp.h>
0075
2019-10-10
pjp
#include <openssl/bn.h>
0076
2019-10-10
pjp
#include <openssl/hmac.h>
0077
2019-06-06
pjp
0078
2019-02-07
pjp
#include "ddd-dns.h"
0079
2019-02-07
pjp
#include "ddd-db.h"
0080
2019-02-07
pjp
0081
2019-11-02
pjp
0082
2019-11-02
pjp
#define MY_SOCK_TIMEOUT -10
0083
2019-11-02
pjp
0084
2019-11-01
pjp
SLIST_HEAD(rzones ,rzone) rzones;
0085
2019-11-02
pjp
LIST_HEAD(, myschedule) myschedules = LIST_HEAD_INITIALIZER(myschedules);
0086
2019-11-01
pjp
0087
2019-11-02
pjp
struct myschedule {
0088
2019-11-02
pjp
char zonename[DNS_MAXNAME + 1];
0089
2019-11-02
pjp
time_t when;
0090
2019-11-02
pjp
int action;
0091
2019-11-03
pjp
#define SCHEDULE_ACTION_RESTART 0x1
0092
2019-11-02
pjp
#define SCHEDULE_ACTION_REFRESH 0x2
0093
2019-11-02
pjp
#define SCHEDULE_ACTION_RETRY 0x3
0094
2019-11-02
pjp
LIST_ENTRY(myschedule) myschedule_entry;
0095
2019-11-02
pjp
} *sp0, *sp1, *spn;
0096
2019-11-02
pjp
0097
2019-11-02
pjp
0098
2019-11-02
pjp
0099
2020-07-08
pjp
int raxfr_a(FILE *, u_char *, u_char *, u_char *, struct soa *, u_int16_t, HMAC_CTX *);
0100
2020-07-08
pjp
int raxfr_aaaa(FILE *, u_char *, u_char *, u_char *, struct soa *, u_int16_t, HMAC_CTX *);
0101
2020-07-08
pjp
int raxfr_cname(FILE *, u_char *, u_char *, u_char *, struct soa *, u_int16_t, HMAC_CTX *);
0102
2020-07-08
pjp
int raxfr_ns(FILE *, u_char *, u_char *, u_char *, struct soa *, u_int16_t, HMAC_CTX *);
0103
2020-07-23
pjp
int raxfr_caa(FILE *, u_char *, u_char *, u_char *, struct soa *, u_int16_t, HMAC_CTX *);
0104
2020-07-23
pjp
int raxfr_rp(FILE *, u_char *, u_char *, u_char *, struct soa *, u_int16_t, HMAC_CTX *);
0105
2020-07-23
pjp
int raxfr_hinfo(FILE *, u_char *, u_char *, u_char *, struct soa *, u_int16_t, HMAC_CTX *);
0106
2020-07-08
pjp
int raxfr_ptr(FILE *, u_char *, u_char *, u_char *, struct soa *, u_int16_t, HMAC_CTX *);
0107
2020-07-08
pjp
int raxfr_mx(FILE *, u_char *, u_char *, u_char *, struct soa *, u_int16_t, HMAC_CTX *);
0108
2020-07-08
pjp
int raxfr_txt(FILE *, u_char *, u_char *, u_char *, struct soa *, u_int16_t, HMAC_CTX *);
0109
2020-07-08
pjp
int raxfr_dnskey(FILE *, u_char *, u_char *, u_char *, struct soa *, u_int16_t, HMAC_CTX *);
0110
2020-07-08
pjp
int raxfr_rrsig(FILE *, u_char *, u_char *, u_char *, struct soa *, u_int16_t, HMAC_CTX *);
0111
2020-07-08
pjp
int raxfr_nsec3param(FILE *, u_char *, u_char *, u_char *, struct soa *, u_int16_t, HMAC_CTX *);
0112
2020-07-08
pjp
int raxfr_nsec3(FILE *, u_char *, u_char *, u_char *, struct soa *, u_int16_t, HMAC_CTX *);
0113
2020-07-08
pjp
int raxfr_ds(FILE *, u_char *, u_char *, u_char *, struct soa *, u_int16_t, HMAC_CTX *);
0114
2020-07-08
pjp
int raxfr_sshfp(FILE *, u_char *, u_char *, u_char *, struct soa *, u_int16_t, HMAC_CTX *);
0115
2020-07-08
pjp
int raxfr_tlsa(FILE *, u_char *, u_char *, u_char *, struct soa *, u_int16_t, HMAC_CTX *);
0116
2020-07-08
pjp
int raxfr_srv(FILE *, u_char *, u_char *, u_char *, struct soa *, u_int16_t, HMAC_CTX *);
0117
2020-07-08
pjp
int raxfr_naptr(FILE *, u_char *, u_char *, u_char *, struct soa *, u_int16_t, HMAC_CTX *);
0118
2020-07-27
pjp
int raxfr_soa(FILE *, u_char *, u_char *, u_char *, struct soa *, int, u_int32_t, u_int16_t, HMAC_CTX *, struct soa_constraints *);
0119
2019-10-10
pjp
0120
2019-02-07
pjp
u_int16_t raxfr_skip(FILE *, u_char *, u_char *);
0121
2020-07-27
pjp
int raxfr_peek(FILE *, u_char *, u_char *, u_char *, int *, int, u_int16_t *, u_int32_t, HMAC_CTX *, char *, int, int);
0122
2019-11-05
pjp
int raxfr_tsig(FILE *f, u_char *p, u_char *estart, u_char *end, struct soa *mysoa, u_int16_t rdlen, HMAC_CTX *ctx, char *, int);
0123
2020-07-06
pjp
0124
2020-07-06
pjp
0125
2020-06-25
pjp
void replicantloop(ddDB *, struct imsgbuf *);
0126
2019-11-02
pjp
static void schedule_refresh(char *, time_t);
0127
2019-11-02
pjp
static void schedule_retry(char *, time_t);
0128
2019-11-03
pjp
static void schedule_restart(char *, time_t);
0129
2019-11-02
pjp
static void schedule_delete(struct myschedule *);
0130
2019-11-06
pjp
static int rand_restarttime(void);
0131
2019-11-02
pjp
int64_t get_remote_soa(struct rzone *rzone);
0132
2019-11-03
pjp
int do_raxfr(FILE *, struct rzone *);
0133
2019-11-19
pjp
int pull_rzone(struct rzone *, time_t);
0134
2019-11-01
pjp
0135
2020-07-06
pjp
extern int fill_a(ddDB *, char *, char *, int, char *);
0136
2020-07-06
pjp
extern int fill_aaaa(ddDB *, char *, char *, int, char *);
0137
2020-07-06
pjp
extern int fill_ptr(ddDB *, char *, char *, int, char *);
0138
2020-07-06
pjp
extern int fill_cname(ddDB *, char *, char *, int, char *);
0139
2020-07-06
pjp
extern int fill_mx(ddDB *, char *, char *, int, int, char *);
0140
2020-07-06
pjp
extern int fill_naptr(ddDB *, char *, char *, int, int, int, char *, char *, char *, char *);
0141
2020-07-06
pjp
extern int fill_ns(ddDB *, char *, char *, int, char *);
0142
2020-07-06
pjp
extern int fill_soa(ddDB *, char *, char *, int, char *, char *, int, int, int, int, int);
0143
2020-07-06
pjp
extern int fill_sshfp(ddDB *, char *, char *, int, int, int, char *);
0144
2020-07-06
pjp
extern int fill_srv(ddDB *, char *, char *, int, int, int, int, char *);
0145
2020-07-06
pjp
extern int fill_tlsa(ddDB *, char *, char *,int, uint8_t, uint8_t, uint8_t, char *);
0146
2020-07-06
pjp
extern int fill_txt(ddDB *, char *, char *, int, char *);
0147
2020-07-06
pjp
extern int fill_dnskey(ddDB *, char *, char *, u_int32_t, u_int16_t, u_int8_t, u_int8_t, char *);
0148
2020-07-06
pjp
extern int fill_rrsig(ddDB *, char *, char *, u_int32_t, char *, u_int8_t, u_int8_t, u_int32_t, u_int64_t, u_int64_t, u_int16_t, char *, char *);
0149
2020-07-06
pjp
extern int fill_nsec(ddDB *, char *, char *, u_int32_t, char *, char *);
0150
2020-07-06
pjp
extern int fill_nsec3param(ddDB *, char *, char *, u_int32_t, u_int8_t, u_int8_t, u_int16_t, char *);
0151
2020-07-06
pjp
extern int fill_nsec3(ddDB *, char *, char *, u_int32_t, u_int8_t, u_int8_t, u_int16_t, char *, char *, char *);
0152
2020-07-06
pjp
extern int fill_ds(ddDB *, char *, char *, u_int32_t, u_int16_t, u_int8_t, u_int8_t, char *);
0153
2020-07-06
pjp
0154
2019-02-07
pjp
extern int memcasecmp(u_char *, u_char *, int);
0155
2019-02-07
pjp
extern char * dns_label(char *, int *);
0156
2019-02-07
pjp
extern char *get_dns_type(int, int);
0157
2019-02-07
pjp
extern int mybase64_encode(u_char const *, size_t, char *, size_t);
0158
2019-02-07
pjp
extern char *bin2hex(char *, int);
0159
2019-02-07
pjp
extern char *bitmap2human(char *, int);
0160
2019-02-07
pjp
extern char *convert_name(char *, int);
0161
2019-02-07
pjp
extern char *base32hex_encode(u_char *, int);
0162
2019-02-07
pjp
extern u_int64_t timethuman(time_t);
0163
2019-02-24
pjp
extern char * expand_compression(u_char *, u_char *, u_char *, u_char *, int *, int);
0164
2019-11-01
pjp
extern void dolog(int, char *, ...);
0165
2020-07-06
pjp
extern struct rbtree * find_rrset(ddDB *db, char *name, int namelen);
0166
2019-11-02
pjp
extern struct rrset * find_rr(struct rbtree *rbt, u_int16_t rrtype);
0167
2019-11-02
pjp
extern struct question *build_question(char *, int, int, char *);
0168
2020-07-27
pjp
extern int lookup_axfr(FILE *, int, char *, struct soa *, u_int32_t, char *, char *, int *, int *, int *, struct soa_constraints *);
0169
2019-11-02
pjp
extern int find_tsig_key(char *, int, char *, int);
0170
2019-11-05
pjp
extern int tsig_pseudoheader(char *, uint16_t, time_t, HMAC_CTX *);
0171
2019-02-07
pjp
0172
2019-12-03
pjp
extern void pack(char *, char *, int);
0173
2019-12-03
pjp
extern void pack32(char *, u_int32_t);
0174
2019-12-03
pjp
extern void pack16(char *, u_int16_t);
0175
2019-12-03
pjp
extern void pack8(char *, u_int8_t);
0176
2019-12-03
pjp
extern uint32_t unpack32(char *);
0177
2019-12-03
pjp
extern uint16_t unpack16(char *);
0178
2019-12-03
pjp
extern void unpack(char *, char *, int);
0179
2019-11-02
pjp
0180
2020-07-26
pjp
extern int dn_contains(char *, int, char *, int);
0181
2019-12-03
pjp
0182
2020-07-26
pjp
0183
2019-02-08
pjp
/* The following alias helps with bounds checking all input, needed! */
0184
2019-02-07
pjp
0185
2019-02-08
pjp
#define BOUNDS_CHECK(cur, begin, rdlen, end) do { \
0186
2019-02-08
pjp
if ((cur - begin) > rdlen) { \
0187
2019-02-08
pjp
return -1; \
0188
2019-02-08
pjp
} \
0189
2019-02-08
pjp
if (cur > end) \
0190
2019-02-08
pjp
return -1; \
0191
2019-02-08
pjp
} while (0)
0192
2019-02-07
pjp
0193
2019-11-02
pjp
static struct raxfr_logic supported[] = {
0194
2019-11-02
pjp
{ DNS_TYPE_A, 0, raxfr_a },
0195
2019-11-02
pjp
{ DNS_TYPE_NS, 0, raxfr_ns },
0196
2019-11-02
pjp
{ DNS_TYPE_MX, 0, raxfr_mx },
0197
2019-11-02
pjp
{ DNS_TYPE_PTR, 0, raxfr_ptr },
0198
2019-11-02
pjp
{ DNS_TYPE_AAAA, 0, raxfr_aaaa },
0199
2019-11-02
pjp
{ DNS_TYPE_CNAME, 0, raxfr_cname },
0200
2019-11-02
pjp
{ DNS_TYPE_TXT, 0, raxfr_txt },
0201
2019-11-02
pjp
{ DNS_TYPE_DNSKEY, 1, raxfr_dnskey },
0202
2019-11-02
pjp
{ DNS_TYPE_RRSIG, 1, raxfr_rrsig },
0203
2019-11-02
pjp
{ DNS_TYPE_NSEC3PARAM, 1, raxfr_nsec3param },
0204
2019-11-02
pjp
{ DNS_TYPE_NSEC3, 1, raxfr_nsec3 },
0205
2019-11-02
pjp
{ DNS_TYPE_DS, 1, raxfr_ds },
0206
2019-11-02
pjp
{ DNS_TYPE_SSHFP, 0, raxfr_sshfp },
0207
2019-11-02
pjp
{ DNS_TYPE_TLSA, 0, raxfr_tlsa },
0208
2019-11-02
pjp
{ DNS_TYPE_SRV, 0, raxfr_srv },
0209
2019-11-02
pjp
{ DNS_TYPE_NAPTR, 0, raxfr_naptr },
0210
2020-07-23
pjp
{ DNS_TYPE_RP, 0, raxfr_rp },
0211
2020-07-23
pjp
{ DNS_TYPE_HINFO, 0, raxfr_hinfo },
0212
2020-07-23
pjp
{ DNS_TYPE_CAA, 0, raxfr_caa },
0213
2019-11-02
pjp
{ 0, 0, NULL }
0214
2019-11-02
pjp
};
0215
2019-02-07
pjp
0216
2019-02-07
pjp
0217
2019-02-07
pjp
int
0218
2020-07-27
pjp
raxfr_peek(FILE *f, u_char *p, u_char *estart, u_char *end, int *rrtype, int soacount, u_int16_t *rdlen, u_int32_t format, HMAC_CTX *ctx, char *zonename, int zonelen, int axfr)
0219
2019-02-07
pjp
{
0220
2019-02-07
pjp
int rrlen;
0221
2019-02-07
pjp
char *save;
0222
2019-02-07
pjp
char *humanname;
0223
2019-02-07
pjp
u_char expand[256];
0224
2019-02-07
pjp
u_char *q = p;
0225
2019-12-03
pjp
u_int16_t rtype, rclass, rdtmp;
0226
2019-12-03
pjp
u_int32_t rttl;
0227
2019-02-07
pjp
int elen = 0;
0228
2019-02-07
pjp
int max = sizeof(expand);
0229
2019-02-07
pjp
char *hightype;
0230
2019-02-07
pjp
int i;
0231
2019-02-07
pjp
0232
2019-02-08
pjp
0233
2019-02-07
pjp
memset(&expand, 0, sizeof(expand));
0234
2019-02-07
pjp
save = expand_compression(q, estart, end, (u_char *)&expand, &elen, max);
0235
2019-02-07
pjp
if (save == NULL) {
0236
2019-02-07
pjp
fprintf(stderr, "expanding compression failure 0\n");
0237
2019-02-07
pjp
return -1;
0238
2019-02-07
pjp
} else
0239
2019-02-07
pjp
q = save;
0240
2019-02-07
pjp
0241
2019-02-08
pjp
if ((q + 2) > end)
0242
2019-02-08
pjp
return -1;
0243
2019-02-08
pjp
0244
2020-07-26
pjp
0245
2019-12-03
pjp
rtype = unpack16(q);
0246
2019-02-07
pjp
q += 2;
0247
2019-02-08
pjp
0248
2019-02-08
pjp
if ((q + 2) > end)
0249
2019-02-08
pjp
return -1;
0250
2019-02-08
pjp
0251
2019-12-03
pjp
rclass = unpack16(q);
0252
2019-02-07
pjp
q += 2;
0253
2019-02-08
pjp
0254
2019-02-08
pjp
if ((q + 4) > end)
0255
2019-02-08
pjp
return -1;
0256
2019-02-08
pjp
0257
2019-12-03
pjp
rttl = unpack32(q);
0258
2019-02-07
pjp
q += 4;
0259
2019-02-08
pjp
0260
2019-02-08
pjp
if ((q + 2) > end)
0261
2019-02-08
pjp
return -1;
0262
2019-02-08
pjp
0263
2019-12-03
pjp
rdtmp = unpack16(q);
0264
2019-12-04
pjp
pack16((char *)rdlen, ntohs(rdtmp));
0265
2019-12-04
pjp
0266
2019-02-07
pjp
q += 2;
0267
2019-02-07
pjp
0268
2019-12-04
pjp
pack32((char *)rrtype, ntohs(rtype));
0269
2019-02-07
pjp
0270
2019-10-10
pjp
if (ctx != NULL) {
0271
2019-10-10
pjp
if (*rrtype != DNS_TYPE_TSIG) {
0272
2019-10-10
pjp
HMAC_Update(ctx, p, q - p);
0273
2019-10-10
pjp
}
0274
2019-10-10
pjp
}
0275
2019-10-10
pjp
0276
2019-10-10
pjp
if (*rrtype == 41 || *rrtype == DNS_TYPE_TSIG)
0277
2019-02-07
pjp
goto out;
0278
2019-02-07
pjp
0279
2019-02-07
pjp
humanname = convert_name(expand, elen);
0280
2019-02-07
pjp
if (humanname == NULL) {
0281
2019-02-07
pjp
return -1;
0282
2019-02-07
pjp
}
0283
2019-02-07
pjp
0284
2020-07-26
pjp
/* check for poison */
0285
2020-07-27
pjp
if (axfr && !dn_contains(expand, elen, zonename, zonelen)) {
0286
2020-07-26
pjp
char *humanzone;
0287
2020-07-26
pjp
0288
2020-07-26
pjp
humanzone = convert_name(zonename, zonelen);
0289
2020-07-26
pjp
dolog(LOG_INFO, "possible poison in AXFR, %s not part of %s", humanname, humanzone);
0290
2020-07-26
pjp
free(humanname);
0291
2020-07-26
pjp
free(humanzone);
0292
2020-07-26
pjp
return -1;
0293
2020-07-26
pjp
}
0294
2020-07-26
pjp
0295
2019-12-03
pjp
hightype = get_dns_type(ntohs(rtype), 0);
0296
2019-12-03
pjp
0297
2019-02-07
pjp
for (i = 0; i < strlen(hightype); i++)
0298
2019-02-07
pjp
hightype[i] = tolower(hightype[i]);
0299
2019-02-07
pjp
0300
2019-02-07
pjp
if (f != NULL) {
0301
2019-02-07
pjp
0302
2019-02-07
pjp
if (soacount < 1) {
0303
2019-02-07
pjp
if ((format & INDENT_FORMAT))
0304
2019-12-03
pjp
fprintf(f, " %s,%s,%d,", (*humanname == '\0' ? "." : humanname), hightype , ntohl(rttl));
0305
2019-02-07
pjp
else if ((format & ZONE_FORMAT)) {
0306
2019-12-03
pjp
fprintf(f, " %s,%s,%d,", (*humanname == '\0' ? "." : humanname), hightype , ntohl(rttl));
0307
2019-02-07
pjp
} else
0308
2019-12-03
pjp
fprintf(f, "%s,%s,%d,", (*humanname == '\0' ? "." : humanname), hightype , ntohl(rttl));
0309
2019-02-07
pjp
} else {
0310
2019-02-07
pjp
if ((format & INDENT_FORMAT))
0311
2019-12-03
pjp
fprintf(f, " %s,%s,%d,", (*humanname == '\0' ? "." : humanname), hightype , ntohl(rttl));
0312
2019-02-07
pjp
else if ((format & ZONE_FORMAT)) {
0313
2019-02-07
pjp
if (*rrtype != DNS_TYPE_SOA) {
0314
2019-12-03
pjp
fprintf(f, " %s,%s,%d,", (*humanname == '\0' ? "." : humanname), hightype , ntohl(rttl));
0315
2019-02-07
pjp
}
0316
2019-02-07
pjp
} else {
0317
2019-12-03
pjp
fprintf(f, "%s,%s,%d,", (*humanname == '\0' ? "." : humanname), hightype , ntohl(rttl));
0318
2019-02-07
pjp
}
0319
2019-02-07
pjp
}
0320
2019-02-07
pjp
}
0321
2019-02-07
pjp
0322
2019-02-15
pjp
fflush(f);
0323
2019-02-15
pjp
0324
2019-02-07
pjp
free(humanname);
0325
2019-02-07
pjp
0326
2019-02-07
pjp
out:
0327
2019-02-07
pjp
rrlen = (q - estart);
0328
2019-02-07
pjp
return (rrlen);
0329
2019-02-07
pjp
}
0330
2019-02-07
pjp
0331
2019-02-07
pjp
u_int16_t
0332
2019-02-07
pjp
raxfr_skip(FILE *f, u_char *p, u_char *estart)
0333
2019-02-07
pjp
{
0334
2019-02-07
pjp
u_char *q;
0335
2019-12-03
pjp
u_int16_t rdlen;
0336
2019-02-07
pjp
0337
2019-02-07
pjp
if ((q = p - 2) <= estart)
0338
2019-02-07
pjp
return 0;
0339
2019-02-07
pjp
0340
2019-12-03
pjp
rdlen = unpack16(q);
0341
2019-02-07
pjp
0342
2019-12-03
pjp
return ((u_int16_t)ntohs(rdlen));
0343
2019-02-07
pjp
}
0344
2019-02-07
pjp
0345
2019-02-07
pjp
int
0346
2020-07-27
pjp
raxfr_soa(FILE *f, u_char *p, u_char *estart, u_char *end, struct soa *mysoa, int soacount, u_int32_t format, u_int16_t rdlen, HMAC_CTX *ctx, struct soa_constraints *constraints)
0347
2019-02-07
pjp
{
0348
2019-12-03
pjp
u_int32_t rvalue;
0349
2019-02-07
pjp
char *save, *humanname;
0350
2019-02-07
pjp
u_char *q = p;
0351
2019-02-07
pjp
u_char expand[256];
0352
2019-02-07
pjp
int max = sizeof(expand);
0353
2019-02-07
pjp
int elen = 0;
0354
2019-02-07
pjp
int soalimit = (format & ZONE_FORMAT) ? 1 : 2;
0355
2019-02-07
pjp
0356
2019-02-07
pjp
memset(&expand, 0, sizeof(expand));
0357
2019-02-07
pjp
save = expand_compression(q, estart, end, (u_char *)&expand, &elen, max);
0358
2019-02-07
pjp
if (save == NULL) {
0359
2019-02-07
pjp
fprintf(stderr, "expanding compression failure 2\n");
0360
2019-02-07
pjp
return -1;
0361
2019-02-07
pjp
} else {
0362
2019-02-07
pjp
q = save;
0363
2019-02-07
pjp
}
0364
2019-02-07
pjp
0365
2019-02-08
pjp
BOUNDS_CHECK(q, p, rdlen, end);
0366
2019-02-08
pjp
0367
2019-02-07
pjp
memset(&mysoa->nsserver, 0, sizeof(mysoa->nsserver));
0368
2019-02-07
pjp
memcpy(&mysoa->nsserver, expand, elen);
0369
2019-02-07
pjp
mysoa->nsserver_len = elen;
0370
2019-02-07
pjp
humanname = convert_name(mysoa->nsserver, mysoa->nsserver_len);
0371
2019-02-07
pjp
if (humanname == NULL) {
0372
2019-02-07
pjp
return -1;
0373
2019-02-07
pjp
}
0374
2019-02-07
pjp
0375
2019-02-07
pjp
if (soacount < soalimit) {
0376
2019-02-08
pjp
if (f != NULL) {
0377
2019-02-08
pjp
if (*humanname == '\0')
0378
2019-02-08
pjp
fprintf(f, ".,");
0379
2019-02-08
pjp
else
0380
2019-02-08
pjp
fprintf(f, "%s,", humanname);
0381
2019-02-08
pjp
}
0382
2019-02-07
pjp
}
0383
2019-02-07
pjp
0384
2019-02-07
pjp
free(humanname);
0385
2019-02-07
pjp
0386
2019-02-07
pjp
elen = 0;
0387
2019-02-07
pjp
memset(&expand, 0, sizeof(expand));
0388
2019-02-07
pjp
save = expand_compression(q, estart, end, (u_char *)&expand, &elen, max);
0389
2019-02-07
pjp
if (save == NULL) {
0390
2019-02-07
pjp
fprintf(stderr, "expanding compression failure 4\n");
0391
2019-02-07
pjp
return -1;
0392
2019-02-07
pjp
} else {
0393
2019-02-07
pjp
q = save;
0394
2019-02-07
pjp
}
0395
2019-02-07
pjp
0396
2019-02-08
pjp
BOUNDS_CHECK(q, p, rdlen, end);
0397
2019-02-08
pjp
0398
2019-02-07
pjp
memset(&mysoa->responsible_person, 0, sizeof(mysoa->responsible_person));
0399
2019-02-07
pjp
memcpy(&mysoa->responsible_person, expand, elen);
0400
2019-02-07
pjp
mysoa->rp_len = elen;
0401
2019-02-07
pjp
0402
2019-02-07
pjp
humanname = convert_name(mysoa->responsible_person, mysoa->rp_len);
0403
2019-02-07
pjp
if (humanname == NULL) {
0404
2019-02-07
pjp
return -1;
0405
2019-02-07
pjp
}
0406
2019-02-07
pjp
0407
2019-02-07
pjp
if (soacount < soalimit) {
0408
2019-02-08
pjp
if (f != NULL) {
0409
2019-02-08
pjp
if (*humanname == '\0')
0410
2019-02-08
pjp
fprintf(f, ".,");
0411
2019-02-08
pjp
else
0412
2019-02-08
pjp
fprintf(f, "%s,", humanname);
0413
2019-02-08
pjp
}
0414
2019-02-07
pjp
}
0415
2019-02-07
pjp
0416
2019-02-07
pjp
free(humanname);
0417
2019-02-07
pjp
0418
2019-02-08
pjp
BOUNDS_CHECK((q + 4), p, rdlen, end);
0419
2019-12-03
pjp
rvalue = unpack32(q);
0420
2019-12-03
pjp
mysoa->serial = rvalue;
0421
2019-02-07
pjp
q += sizeof(u_int32_t);
0422
2019-02-08
pjp
BOUNDS_CHECK((q + 4), p, rdlen, end);
0423
2019-12-03
pjp
rvalue = unpack32(q);
0424
2019-12-03
pjp
mysoa->refresh = rvalue;
0425
2019-02-07
pjp
q += sizeof(u_int32_t);
0426
2019-02-08
pjp
BOUNDS_CHECK((q + 4), p, rdlen, end);
0427
2019-12-03
pjp
rvalue = unpack32(q);
0428
2019-12-03
pjp
mysoa->retry = rvalue;
0429
2019-02-07
pjp
q += sizeof(u_int32_t);
0430
2019-02-08
pjp
BOUNDS_CHECK((q + 4), p, rdlen, end);
0431
2019-12-03
pjp
rvalue = unpack32(q);
0432
2019-12-03
pjp
mysoa->expire = rvalue;
0433
2019-02-07
pjp
q += sizeof(u_int32_t);
0434
2019-02-08
pjp
BOUNDS_CHECK((q + 4), p, rdlen, end);
0435
2019-12-03
pjp
rvalue = unpack32(q);
0436
2019-12-03
pjp
mysoa->minttl = rvalue;
0437
2019-02-07
pjp
q += sizeof(u_int32_t);
0438
2020-07-27
pjp
0439
2020-07-27
pjp
if (constraints->refresh > ntohl(mysoa->refresh) ||
0440
2020-07-27
pjp
constraints->retry > ntohl(mysoa->retry) ||
0441
2020-07-27
pjp
constraints->expire > ntohl(mysoa->expire)) {
0442
2020-07-27
pjp
dolog(LOG_INFO, "raxfr_soa: refresh/retry/expire values were below SOA constraints %u/%u, %u/%u, %u/%u, bailing out!\n", constraints->refresh, ntohl(mysoa->refresh), constraints->retry, ntohl(mysoa->retry), constraints->expire, ntohl(mysoa->expire));
0443
2020-07-27
pjp
0444
2020-07-27
pjp
if (f != NULL) {
0445
2020-07-27
pjp
fprintf(f, "constraints failure\n");
0446
2020-07-27
pjp
fflush(f);
0447
2020-07-27
pjp
}
0448
2020-07-27
pjp
0449
2020-07-27
pjp
return -1;
0450
2020-07-27
pjp
}
0451
2019-02-07
pjp
0452
2019-02-07
pjp
if (soacount < soalimit) {
0453
2019-02-07
pjp
if (f != NULL) {
0454
2019-02-07
pjp
fprintf(f, "%d,%d,%d,%d,%d\n", ntohl(mysoa->serial),
0455
2019-02-07
pjp
ntohl(mysoa->refresh), ntohl(mysoa->retry),
0456
2019-02-07
pjp
ntohl(mysoa->expire), ntohl(mysoa->minttl));
0457
2019-02-07
pjp
}
0458
2019-02-07
pjp
}
0459
2019-10-10
pjp
0460
2019-10-10
pjp
if (ctx != NULL)
0461
2019-10-10
pjp
HMAC_Update(ctx, p, q - p);
0462
2019-02-07
pjp
0463
2019-02-07
pjp
return (q - estart);
0464
2019-02-07
pjp
}
0465
2019-02-07
pjp
0466
2019-02-07
pjp
int
0467
2020-07-08
pjp
raxfr_rrsig(FILE *f, u_char *p, u_char *estart, u_char *end, struct soa *mysoa, u_int16_t rdlen, HMAC_CTX *ctx)
0468
2019-02-07
pjp
{
0469
2019-02-07
pjp
struct rrsig rs;
0470
2019-02-07
pjp
char *save, *humanname;
0471
2019-02-07
pjp
u_char *q = p;
0472
2019-02-07
pjp
u_char expand[256];
0473
2019-02-07
pjp
int max = sizeof(expand);
0474
2019-02-07
pjp
int elen = 0;
0475
2019-12-03
pjp
u_int16_t tmp;
0476
2019-12-03
pjp
u_int32_t tmp4;
0477
2019-02-07
pjp
int len;
0478
2019-02-07
pjp
u_char *b;
0479
2019-02-07
pjp
0480
2019-02-08
pjp
BOUNDS_CHECK((q + 2), p, rdlen, end);
0481
2019-12-03
pjp
tmp = unpack16(q);
0482
2019-12-03
pjp
rs.type_covered = ntohs(tmp);
0483
2019-02-07
pjp
q += 2;
0484
2019-02-08
pjp
BOUNDS_CHECK((q + 1), p, rdlen, end);
0485
2019-02-07
pjp
rs.algorithm = *q++;
0486
2019-02-08
pjp
BOUNDS_CHECK((q + 1), p, rdlen, end);
0487
2019-02-07
pjp
rs.labels = *q++;
0488
2019-02-08
pjp
BOUNDS_CHECK((q + 4), p, rdlen, end);
0489
2019-12-03
pjp
tmp4 = unpack32(q);
0490
2019-12-03
pjp
rs.original_ttl = ntohl(tmp4);
0491
2019-02-07
pjp
q += 4;
0492
2019-02-08
pjp
BOUNDS_CHECK((q + 4), p, rdlen, end);
0493
2019-12-03
pjp
tmp4 = unpack32(q);
0494
2019-12-03
pjp
rs.signature_expiration = ntohl(tmp4);
0495
2019-02-07
pjp
q += 4;
0496
2019-02-08
pjp
BOUNDS_CHECK((q + 4), p, rdlen, end);
0497
2019-12-03
pjp
tmp4 = unpack32(q);
0498
2019-12-03
pjp
rs.signature_inception = ntohl(tmp4);
0499
2019-02-07
pjp
q += 4;
0500
2019-02-08
pjp
BOUNDS_CHECK((q + 2), p, rdlen, end);
0501
2019-12-03
pjp
tmp = unpack16(q);
0502
2019-12-03
pjp
rs.key_tag = ntohs(tmp);
0503
2019-02-07
pjp
q += 2;
0504
2019-02-07
pjp
0505
2019-02-07
pjp
memset(&expand, 0, sizeof(expand));
0506
2019-02-07
pjp
save = expand_compression(q, estart, end, (u_char *)&expand, &elen, max);
0507
2019-02-07
pjp
if (save == NULL) {
0508
2019-02-07
pjp
fprintf(stderr, "expanding compression failure 2\n");
0509
2019-02-07
pjp
return -1;
0510
2019-02-07
pjp
} else {
0511
2019-02-07
pjp
q = save;
0512
2019-02-07
pjp
}
0513
2019-02-07
pjp
0514
2019-02-07
pjp
memcpy(&rs.signers_name, expand, elen);
0515
2019-02-07
pjp
rs.signame_len = elen;
0516
2019-02-07
pjp
0517
2019-02-07
pjp
rs.signature_len = (rdlen - (q - p));
0518
2019-02-07
pjp
0519
2019-02-07
pjp
if (rs.signature_len > sizeof(rs.signature))
0520
2019-02-07
pjp
return -1;
0521
2019-02-07
pjp
memcpy(&rs.signature, q, rs.signature_len);
0522
2019-02-07
pjp
q += rs.signature_len;
0523
2019-02-07
pjp
0524
2019-02-07
pjp
b = calloc(1, 2 * rs.signature_len);
0525
2019-02-07
pjp
if (b == NULL)
0526
2019-02-07
pjp
return -1;
0527
2019-02-07
pjp
0528
2019-02-07
pjp
if ((len = mybase64_encode(rs.signature, rs.signature_len, b, rs.signature_len * 2)) < 0) {
0529
2019-02-07
pjp
free(b);
0530
2019-02-07
pjp
return -1;
0531
2019-02-07
pjp
}
0532
2019-02-07
pjp
0533
2019-02-07
pjp
b[len] = '\0';
0534
2019-02-07
pjp
0535
2019-02-07
pjp
0536
2019-02-07
pjp
humanname = convert_name(expand, elen);
0537
2019-02-07
pjp
if (humanname == NULL) {
0538
2019-02-07
pjp
free(b);
0539
2019-02-07
pjp
return -1;
0540
2019-02-07
pjp
}
0541
2020-07-06
pjp
0542
2020-07-08
pjp
if (f != NULL) {
0543
2020-07-08
pjp
fprintf(f, "%s,%u,%u,%u,%llu,%llu,%u,%s,\"%s\"\n",
0544
2020-07-08
pjp
get_dns_type(rs.type_covered, 0),
0545
2020-07-08
pjp
rs.algorithm, rs.labels, rs.original_ttl,
0546
2020-07-08
pjp
timethuman(rs.signature_expiration),
0547
2019-02-07
pjp
timethuman(rs.signature_inception),
0548
2019-02-08
pjp
rs.key_tag,
0549
2019-02-08
pjp
(*humanname == '\0' ? "." : humanname), b);
0550
2019-02-07
pjp
}
0551
2020-07-08
pjp
0552
2019-02-07
pjp
0553
2019-02-07
pjp
free(humanname);
0554
2019-02-07
pjp
free(b);
0555
2019-02-07
pjp
0556
2019-10-10
pjp
if (ctx != NULL)
0557
2019-10-10
pjp
HMAC_Update(ctx, p, q - p);
0558
2019-10-10
pjp
0559
2019-02-07
pjp
return (q - estart);
0560
2019-02-07
pjp
}
0561
2019-02-07
pjp
0562
2019-02-07
pjp
int
0563
2020-07-23
pjp
raxfr_caa(FILE *f, u_char *p, u_char *estart, u_char *end, struct soa *mysoa, u_int16_t rdlen, HMAC_CTX *ctx)
0564
2020-07-23
pjp
{
0565
2020-07-23
pjp
struct caa caa;
0566
2020-07-23
pjp
u_char *q = p;
0567
2020-07-23
pjp
int i;
0568
2020-07-23
pjp
0569
2020-07-23
pjp
BOUNDS_CHECK((p + 1), q, rdlen, end);
0570
2020-07-23
pjp
caa.flags = *p;
0571
2020-07-23
pjp
p++;
0572
2020-07-23
pjp
BOUNDS_CHECK((p + 1), q, rdlen, end);
0573
2020-07-23
pjp
caa.taglen = *p;
0574
2020-07-23
pjp
p++;
0575
2020-07-23
pjp
BOUNDS_CHECK((p + caa.taglen), q, rdlen, end);
0576
2020-07-23
pjp
memcpy(&caa.tag, p, caa.taglen);
0577
2020-07-23
pjp
p += caa.taglen;
0578
2020-07-23
pjp
BOUNDS_CHECK((p + (rdlen - 2 - caa.taglen)), q, rdlen, end);
0579
2020-07-23
pjp
caa.valuelen = rdlen - 2 - caa.taglen;
0580
2020-07-23
pjp
memcpy(&caa.value, p, caa.valuelen);
0581
2020-07-23
pjp
p += caa.valuelen;
0582
2020-07-23
pjp
0583
2020-07-23
pjp
if (f != NULL) {
0584
2020-07-23
pjp
fprintf(f, "%u,", caa.flags);
0585
2020-07-23
pjp
for (i = 0; i < caa.taglen; i++) {
0586
2020-07-23
pjp
fprintf(f, "%c", caa.tag[i]);
0587
2020-07-23
pjp
}
0588
2020-07-23
pjp
fprintf(f, ",\"");
0589
2020-07-23
pjp
for (i = 0; i < caa.valuelen; i++) {
0590
2020-07-23
pjp
fprintf(f, "%c", caa.value[i]);
0591
2020-07-23
pjp
}
0592
2020-07-23
pjp
fprintf(f, "\"\n");
0593
2020-07-23
pjp
}
0594
2020-07-23
pjp
0595
2020-07-23
pjp
if (ctx != NULL)
0596
2020-07-23
pjp
HMAC_Update(ctx, q, p - q);
0597
2020-07-23
pjp
0598
2020-07-23
pjp
return (p - estart);
0599
2020-07-23
pjp
}
0600
2020-07-23
pjp
0601
2020-07-23
pjp
0602
2020-07-23
pjp
int
0603
2020-07-23
pjp
raxfr_hinfo(FILE *f, u_char *p, u_char *estart, u_char *end, struct soa *mysoa, u_int16_t rdlen, HMAC_CTX *ctx)
0604
2020-07-23
pjp
{
0605
2020-07-23
pjp
struct hinfo hinfo;
0606
2020-07-23
pjp
u_char *q = p;
0607
2020-07-23
pjp
int i;
0608
2020-07-23
pjp
0609
2020-07-23
pjp
BOUNDS_CHECK((p + 1), q, rdlen, end);
0610
2020-07-23
pjp
hinfo.cpulen = *p;
0611
2020-07-23
pjp
p++;
0612
2020-07-23
pjp
BOUNDS_CHECK((p + hinfo.cpulen), q, rdlen, end);
0613
2020-07-23
pjp
memcpy(&hinfo.cpu, p, hinfo.cpulen);
0614
2020-07-23
pjp
p += hinfo.cpulen;
0615
2020-07-23
pjp
BOUNDS_CHECK((p + 1), q, rdlen, end);
0616
2020-07-23
pjp
hinfo.oslen = *p;
0617
2020-07-23
pjp
p++;
0618
2020-07-23
pjp
BOUNDS_CHECK((p + hinfo.oslen), q, rdlen, end);
0619
2020-07-23
pjp
memcpy(&hinfo.os, p, hinfo.oslen);
0620
2020-07-23
pjp
p += hinfo.oslen;
0621
2020-07-23
pjp
0622
2020-07-23
pjp
if (f != NULL) {
0623
2020-07-23
pjp
fprintf(f, "\"");
0624
2020-07-23
pjp
for (i = 0; i < hinfo.cpulen; i++) {
0625
2020-07-23
pjp
fprintf(f, "%c", hinfo.cpu[i]);
0626
2020-07-23
pjp
}
0627
2020-07-23
pjp
fprintf(f, "\",\"");
0628
2020-07-23
pjp
for (i = 0; i < hinfo.oslen; i++) {
0629
2020-07-23
pjp
fprintf(f, "%c", hinfo.os[i]);
0630
2020-07-23
pjp
}
0631
2020-07-23
pjp
fprintf(f, "\"\n");
0632
2020-07-23
pjp
}
0633
2020-07-23
pjp
0634
2020-07-23
pjp
if (ctx != NULL)
0635
2020-07-23
pjp
HMAC_Update(ctx, q, p - q);
0636
2020-07-23
pjp
0637
2020-07-23
pjp
return (p - estart);
0638
2020-07-23
pjp
}
0639
2020-07-23
pjp
0640
2020-07-23
pjp
int
0641
2020-07-08
pjp
raxfr_ds(FILE *f, u_char *p, u_char *estart, u_char *end, struct soa *mysoa, u_int16_t rdlen, HMAC_CTX *ctx)
0642
2020-07-08
pjp
{
0643
2019-02-07
pjp
struct ds d;
0644
2019-12-03
pjp
u_int16_t tmpshort;
0645
2019-02-08
pjp
u_char *q = p;
0646
2019-02-07
pjp
0647
2019-02-08
pjp
BOUNDS_CHECK((p + 2), q, rdlen, end);
0648
2019-12-03
pjp
tmpshort = unpack16(p);
0649
2019-12-03
pjp
d.key_tag = ntohs(tmpshort);
0650
2019-02-07
pjp
p += 2;
0651
2019-02-08
pjp
BOUNDS_CHECK((p + 1), q, rdlen, end);
0652
2019-02-07
pjp
d.algorithm = *p++;
0653
2019-02-08
pjp
BOUNDS_CHECK((p + 1), q, rdlen, end);
0654
2019-02-07
pjp
d.digest_type = *p++;
0655
2019-02-08
pjp
0656
2019-02-08
pjp
if ((rdlen - 4) < 0)
0657
2019-02-08
pjp
return -1;
0658
2019-02-07
pjp
d.digestlen = (rdlen - 4);
0659
2019-02-07
pjp
if (d.digestlen > sizeof(d.digest))
0660
2019-02-07
pjp
return -1;
0661
2019-02-07
pjp
memcpy(&d.digest, p, d.digestlen);
0662
2019-02-07
pjp
p += d.digestlen;
0663
2019-02-07
pjp
0664
2019-02-07
pjp
0665
2020-07-08
pjp
if (f != NULL) {
0666
2020-07-08
pjp
fprintf(f, "%u,%u,%u,\"%s\"\n", d.key_tag, d.algorithm,
0667
2020-07-08
pjp
d.digest_type, bin2hex(d.digest, d.digestlen));
0668
2019-02-07
pjp
}
0669
2019-02-07
pjp
0670
2019-10-10
pjp
if (ctx != NULL)
0671
2019-10-10
pjp
HMAC_Update(ctx, q, p - q);
0672
2019-10-10
pjp
0673
2019-02-07
pjp
return (p - estart);
0674
2019-02-07
pjp
}
0675
2019-02-07
pjp
0676
2019-02-07
pjp
int
0677
2020-07-08
pjp
raxfr_sshfp(FILE *f, u_char *p, u_char *estart, u_char *end, struct soa *mysoa, u_int16_t rdlen, HMAC_CTX *ctx)
0678
2019-02-07
pjp
{
0679
2019-02-07
pjp
struct sshfp s;
0680
2019-02-07
pjp
char *hex;
0681
2019-02-08
pjp
u_char *q = p;
0682
2019-02-07
pjp
0683
2019-02-08
pjp
BOUNDS_CHECK((p + 1), q, rdlen, end);
0684
2019-02-07
pjp
s.algorithm = *p++;
0685
2019-02-08
pjp
BOUNDS_CHECK((p + 1), q, rdlen, end);
0686
2019-02-07
pjp
s.fptype = *p++;
0687
2019-02-07
pjp
0688
2019-02-08
pjp
if (rdlen - 2 < 0)
0689
2019-02-08
pjp
return -1;
0690
2019-02-08
pjp
0691
2019-02-07
pjp
s.fplen = (rdlen - 2);
0692
2019-02-07
pjp
if (s.fplen > sizeof(s.fingerprint))
0693
2019-02-07
pjp
return -1;
0694
2019-02-07
pjp
0695
2019-02-07
pjp
memcpy(&s.fingerprint, p, s.fplen);
0696
2019-02-07
pjp
p += s.fplen;
0697
2019-02-07
pjp
0698
2019-02-07
pjp
hex = bin2hex(s.fingerprint, s.fplen);
0699
2019-02-07
pjp
0700
2020-07-08
pjp
if (f != NULL) {
0701
2020-07-08
pjp
fprintf(f, "%u,%u,\"%s\"\n", s.algorithm, s.fptype, hex);
0702
2019-02-07
pjp
}
0703
2019-02-07
pjp
0704
2019-10-10
pjp
if (ctx != NULL)
0705
2019-10-10
pjp
HMAC_Update(ctx, q, p - q);
0706
2019-10-10
pjp
0707
2019-02-07
pjp
return (p - estart);
0708
2019-02-07
pjp
}
0709
2019-02-07
pjp
0710
2019-02-07
pjp
int
0711
2020-07-08
pjp
raxfr_dnskey(FILE *f, u_char *p, u_char *estart, u_char *end, struct soa *mysoa, u_int16_t rdlen, HMAC_CTX *ctx)
0712
2019-02-07
pjp
{
0713
2019-02-07
pjp
struct dnskey dk;
0714
2019-12-03
pjp
u_int16_t tmpshort;
0715
2019-02-07
pjp
char *b;
0716
2019-02-08
pjp
u_char *q = p;
0717
2019-02-07
pjp
int len;
0718
2019-02-07
pjp
0719
2019-02-08
pjp
BOUNDS_CHECK((p + 2), q, rdlen, end);
0720
2019-12-03
pjp
tmpshort = unpack16(p);
0721
2019-12-03
pjp
dk.flags = ntohs(tmpshort);
0722
2019-02-07
pjp
p += 2;
0723
2019-02-08
pjp
BOUNDS_CHECK((p + 1), q, rdlen, end);
0724
2019-02-07
pjp
dk.protocol = *p++;
0725
2019-02-08
pjp
BOUNDS_CHECK((p + 1), q, rdlen, end);
0726
2019-02-07
pjp
dk.algorithm = *p++;
0727
2019-02-07
pjp
0728
2019-02-08
pjp
if (rdlen - 4 < 0)
0729
2019-02-08
pjp
return -1;
0730
2019-02-07
pjp
dk.publickey_len = (rdlen - 4);
0731
2019-02-07
pjp
if (dk.publickey_len > sizeof(dk.public_key))
0732
2019-02-07
pjp
return -1;
0733
2019-02-07
pjp
0734
2019-02-07
pjp
memcpy(&dk.public_key, p, dk.publickey_len);
0735
2019-02-07
pjp
p += dk.publickey_len;
0736
2019-02-07
pjp
0737
2019-02-07
pjp
b = calloc(1, dk.publickey_len * 2);
0738
2019-02-07
pjp
if (b == NULL) {
0739
2019-02-07
pjp
perror("calloc");
0740
2019-02-07
pjp
return -1;
0741
2019-02-07
pjp
}
0742
2019-02-07
pjp
0743
2019-02-07
pjp
if ((len = mybase64_encode(dk.public_key, dk.publickey_len, b, dk.publickey_len * 2)) < 0) {
0744
2019-02-07
pjp
free(b);
0745
2019-02-07
pjp
return -1;
0746
2019-02-07
pjp
}
0747
2019-02-07
pjp
0748
2019-02-07
pjp
b[len] = '\0';
0749
2019-02-07
pjp
0750
2020-07-08
pjp
if (f != NULL) {
0751
2020-07-08
pjp
fprintf(f, "%u,%u,%u,\"%s\"\n", dk.flags, dk.protocol,
0752
2020-07-08
pjp
dk.algorithm, b);
0753
2019-02-07
pjp
}
0754
2019-02-07
pjp
0755
2019-02-07
pjp
free(b);
0756
2019-10-10
pjp
0757
2019-10-10
pjp
if (ctx != NULL)
0758
2019-10-10
pjp
HMAC_Update(ctx, q, p - q);
0759
2019-10-10
pjp
0760
2019-02-07
pjp
return (p - estart);
0761
2019-02-07
pjp
}
0762
2019-02-07
pjp
0763
2019-02-07
pjp
0764
2019-02-07
pjp
int
0765
2020-07-08
pjp
raxfr_mx(FILE *f, u_char *p, u_char *estart, u_char *end, struct soa *mysoa, u_int16_t rdlen, HMAC_CTX *ctx)
0766
2019-02-07
pjp
{
0767
2019-12-03
pjp
u_int16_t mxpriority;
0768
2019-02-07
pjp
char *save, *humanname;
0769
2019-02-07
pjp
u_char *q = p;
0770
2019-02-07
pjp
u_char expand[256];
0771
2019-02-07
pjp
int max = sizeof(expand);
0772
2019-02-07
pjp
int elen = 0;
0773
2019-02-07
pjp
0774
2019-02-08
pjp
BOUNDS_CHECK((q + 2), p, rdlen, end);
0775
2019-12-03
pjp
mxpriority = unpack16(q);
0776
2019-02-07
pjp
0777
2020-07-08
pjp
if (f != NULL)
0778
2020-07-08
pjp
fprintf(f, "%u,", ntohs(mxpriority));
0779
2019-02-07
pjp
0780
2019-02-07
pjp
q += 2;
0781
2019-02-07
pjp
0782
2019-02-07
pjp
memset(&expand, 0, sizeof(expand));
0783
2019-02-07
pjp
save = expand_compression(q, estart, end, (u_char *)&expand, &elen, max);
0784
2019-02-07
pjp
if (save == NULL) {
0785
2019-02-07
pjp
fprintf(stderr, "expanding compression failure 2\n");
0786
2019-02-07
pjp
return -1;
0787
2019-02-07
pjp
} else {
0788
2019-02-07
pjp
q = save;
0789
2019-02-07
pjp
}
0790
2019-02-07
pjp
0791
2019-02-07
pjp
humanname = convert_name(expand, elen);
0792
2019-02-07
pjp
if (humanname == NULL) {
0793
2019-02-07
pjp
return -1;
0794
2019-02-07
pjp
}
0795
2019-02-07
pjp
0796
2020-07-08
pjp
if (f != NULL) {
0797
2020-07-08
pjp
if (*humanname == '\0')
0798
2020-07-08
pjp
fprintf(f, ".\n");
0799
2020-07-08
pjp
else
0800
2020-07-08
pjp
fprintf(f, "%s\n", humanname);
0801
2019-02-08
pjp
}
0802
2019-02-07
pjp
0803
2019-02-07
pjp
free(humanname);
0804
2019-02-07
pjp
0805
2019-10-10
pjp
if (ctx != NULL)
0806
2019-10-10
pjp
HMAC_Update(ctx, p, q - p);
0807
2019-10-10
pjp
0808
2019-02-07
pjp
return (q - estart);
0809
2019-02-07
pjp
}
0810
2019-02-07
pjp
0811
2019-02-07
pjp
int
0812
2020-07-08
pjp
raxfr_ptr(FILE *f, u_char *p, u_char *estart, u_char *end, struct soa *mysoa, u_int16_t rdlen, HMAC_CTX *ctx)
0813
2019-02-07
pjp
{
0814
2020-07-08
pjp
return (raxfr_ns(f, p, estart, end, mysoa, rdlen, ctx));
0815
2019-02-07
pjp
}
0816
2019-02-07
pjp
0817
2019-02-07
pjp
int
0818
2020-07-08
pjp
raxfr_nsec3(FILE *f, u_char *p, u_char *estart, u_char *end, struct soa *mysoa, u_int16_t rdlen, HMAC_CTX *ctx)
0819
2019-02-07
pjp
{
0820
2019-02-07
pjp
struct nsec3 n;
0821
2019-12-03
pjp
u_int16_t iter;
0822
2019-02-07
pjp
u_char *brr = p; /* begin of rd record :-) */
0823
2019-02-07
pjp
0824
2019-02-08
pjp
BOUNDS_CHECK((p + 1), brr, rdlen, end);
0825
2019-02-07
pjp
n.algorithm = *p++;
0826
2019-02-08
pjp
BOUNDS_CHECK((p + 1), brr, rdlen, end);
0827
2019-02-07
pjp
n.flags = *p++;
0828
2019-02-07
pjp
0829
2019-02-08
pjp
BOUNDS_CHECK((p + 2), brr, rdlen, end);
0830
2019-12-03
pjp
iter = unpack16(p);
0831
2019-12-03
pjp
n.iterations = ntohs(iter);
0832
2019-02-07
pjp
p += 2;
0833
2019-02-07
pjp
0834
2019-02-08
pjp
BOUNDS_CHECK((p + 1), brr, rdlen, end);
0835
2019-02-07
pjp
n.saltlen = *p++;
0836
2019-02-07
pjp
memcpy(&n.salt, p, n.saltlen);
0837
2019-02-07
pjp
p += n.saltlen;
0838
2019-02-07
pjp
0839
2019-02-08
pjp
BOUNDS_CHECK((p + 1), brr, rdlen, end);
0840
2019-02-07
pjp
n.nextlen = *p++;
0841
2019-02-07
pjp
memcpy(&n.next, p, n.nextlen);
0842
2019-02-07
pjp
p += n.nextlen;
0843
2019-02-07
pjp
0844
2019-02-08
pjp
0845
2019-02-08
pjp
if (((rdlen - (p - brr)) + 1) < 0)
0846
2019-02-08
pjp
return -1;
0847
2019-02-08
pjp
0848
2019-02-08
pjp
/* XXX */
0849
2019-02-11
pjp
n.bitmap_len = (rdlen - (p - brr));
0850
2019-02-07
pjp
if (n.bitmap_len > sizeof(n.bitmap))
0851
2019-02-07
pjp
return -1;
0852
2019-02-07
pjp
0853
2019-02-07
pjp
memcpy(&n.bitmap, p, n.bitmap_len);
0854
2019-02-07
pjp
p += n.bitmap_len;
0855
2019-02-07
pjp
0856
2019-02-07
pjp
bitmap2human(n.bitmap, n.bitmap_len);
0857
2019-02-07
pjp
0858
2020-07-08
pjp
if (f != NULL) {
0859
2020-07-08
pjp
fprintf(f, "%u,%u,%u,\"%s\",\"%s\",\"%s\"\n", n.algorithm,
0860
2020-07-08
pjp
n.flags, n.iterations,
0861
2020-07-08
pjp
(n.saltlen == 0 ? "-" :
0862
2020-07-08
pjp
bin2hex(n.salt, n.saltlen)),
0863
2020-07-08
pjp
base32hex_encode(n.next, n.nextlen),
0864
2020-07-06
pjp
bitmap2human(n.bitmap, n.bitmap_len));
0865
2019-02-07
pjp
}
0866
2019-02-07
pjp
0867
2019-10-10
pjp
if (ctx != NULL)
0868
2019-10-10
pjp
HMAC_Update(ctx, brr, p - brr);
0869
2019-10-10
pjp
0870
2019-02-07
pjp
return (p - estart);
0871
2019-02-07
pjp
}
0872
2019-02-07
pjp
0873
2019-02-07
pjp
int
0874
2020-07-08
pjp
raxfr_nsec3param(FILE *f, u_char *p, u_char *estart, u_char *end, struct soa *mysoa, u_int16_t rdlen, HMAC_CTX *ctx)
0875
2019-02-07
pjp
{
0876
2019-02-07
pjp
struct nsec3param np;
0877
2019-12-03
pjp
u_int16_t iter;
0878
2019-02-07
pjp
char *hex;
0879
2019-02-08
pjp
u_char *q = p;
0880
2019-02-07
pjp
0881
2019-02-08
pjp
BOUNDS_CHECK((p + 1), q, rdlen, end);
0882
2019-02-07
pjp
np.algorithm = *p++;
0883
2019-02-08
pjp
BOUNDS_CHECK((p + 1), q, rdlen, end);
0884
2019-02-07
pjp
np.flags = *p++;
0885
2019-02-08
pjp
BOUNDS_CHECK((p + 2), q, rdlen, end);
0886
2019-12-03
pjp
iter = unpack16(p);
0887
2019-12-03
pjp
np.iterations = ntohs(iter);
0888
2019-02-07
pjp
p += 2;
0889
2019-02-08
pjp
BOUNDS_CHECK((p + 1), q, rdlen, end);
0890
2019-02-07
pjp
np.saltlen = *p++;
0891
2019-02-08
pjp
BOUNDS_CHECK((p + np.saltlen), q, rdlen, end);
0892
2019-02-07
pjp
memcpy(&np.salt, p, np.saltlen);
0893
2019-02-07
pjp
p += np.saltlen;
0894
2019-02-07
pjp
0895
2019-02-07
pjp
hex = bin2hex(np.salt, np.saltlen);
0896
2019-02-07
pjp
0897
2020-07-08
pjp
if (f != NULL) {
0898
2020-07-08
pjp
fprintf(f, "%u,%u,%u,\"%s\"\n", np.algorithm, np.flags,
0899
2020-07-08
pjp
np.iterations,
0900
2019-02-07
pjp
(np.saltlen == 0 ? "-" : bin2hex(np.salt, np.saltlen)));
0901
2019-02-07
pjp
}
0902
2019-02-07
pjp
0903
2019-10-10
pjp
if (ctx != NULL)
0904
2019-10-10
pjp
HMAC_Update(ctx, q, p - q);
0905
2019-10-10
pjp
0906
2019-02-07
pjp
return (p - estart);
0907
2019-02-07
pjp
}
0908
2019-02-07
pjp
0909
2019-02-07
pjp
0910
2019-02-07
pjp
int
0911
2020-07-08
pjp
raxfr_txt(FILE *f, u_char *p, u_char *estart, u_char *end, struct soa *mysoa, u_int16_t rdlen, HMAC_CTX *ctx)
0912
2019-02-07
pjp
{
0913
2019-02-07
pjp
u_int8_t len;
0914
2019-02-07
pjp
int i;
0915
2019-02-08
pjp
u_char *q = p;
0916
2019-02-07
pjp
0917
2019-04-30
pjp
BOUNDS_CHECK(p, q, rdlen, end);
0918
2019-04-30
pjp
len = rdlen;
0919
2019-02-07
pjp
0920
2019-02-07
pjp
if (f != NULL)
0921
2019-02-07
pjp
fprintf(f, "\"");
0922
2019-02-07
pjp
0923
2019-04-30
pjp
for (i = 0; i < rdlen; i++) {
0924
2019-04-30
pjp
if (i % 256 == 0)
0925
2019-04-30
pjp
continue;
0926
2019-04-30
pjp
0927
2019-02-07
pjp
if (f != NULL)
0928
2019-04-30
pjp
fprintf(f, "%c", p[i]);
0929
2019-02-07
pjp
}
0930
2019-02-07
pjp
if (f != NULL)
0931
2019-02-07
pjp
fprintf(f, "\"\n");
0932
2019-04-30
pjp
0933
2019-04-30
pjp
p += i;
0934
2019-02-07
pjp
0935
2019-10-10
pjp
if (ctx != NULL)
0936
2019-10-10
pjp
HMAC_Update(ctx, q, p - q);
0937
2019-02-07
pjp
0938
2019-02-07
pjp
return (p - estart);
0939
2019-02-07
pjp
}
0940
2019-02-07
pjp
0941
2019-02-07
pjp
int
0942
2020-07-23
pjp
raxfr_rp(FILE *f, u_char *p, u_char *estart, u_char *end, struct soa *mysoa, u_int16_t rdlen, HMAC_CTX *ctx)
0943
2020-07-23
pjp
{
0944
2020-07-23
pjp
char *save, *humanname;
0945
2020-07-23
pjp
u_char *q = p;
0946
2020-07-23
pjp
u_char expand[256];
0947
2020-07-23
pjp
int max = sizeof(expand);
0948
2020-07-23
pjp
int elen = 0;
0949
2020-07-23
pjp
0950
2020-07-23
pjp
memset(&expand, 0, sizeof(expand));
0951
2020-07-23
pjp
save = expand_compression(q, estart, end, (u_char *)&expand, &elen, max);
0952
2020-07-23
pjp
if (save == NULL) {
0953
2020-07-23
pjp
fprintf(stderr, "expanding compression failure 2\n");
0954
2020-07-23
pjp
return -1;
0955
2020-07-23
pjp
} else {
0956
2020-07-23
pjp
q = save;
0957
2020-07-23
pjp
}
0958
2020-07-23
pjp
0959
2020-07-23
pjp
humanname = convert_name(expand, elen);
0960
2020-07-23
pjp
if (humanname == NULL) {
0961
2020-07-23
pjp
return -1;
0962
2020-07-23
pjp
}
0963
2020-07-23
pjp
0964
2020-07-23
pjp
if (f != NULL) {
0965
2020-07-23
pjp
fprintf(f, "%s,", humanname);
0966
2020-07-23
pjp
}
0967
2020-07-23
pjp
0968
2020-07-23
pjp
free(humanname);
0969
2020-07-23
pjp
0970
2020-07-23
pjp
memset(&expand, 0, sizeof(expand));
0971
2020-07-23
pjp
elen = 0;
0972
2020-07-23
pjp
save = expand_compression(q, estart, end, (u_char *)&expand, &elen, max);
0973
2020-07-23
pjp
if (save == NULL) {
0974
2020-07-23
pjp
fprintf(stderr, "expanding compression failure 2\n");
0975
2020-07-23
pjp
return -1;
0976
2020-07-23
pjp
} else {
0977
2020-07-23
pjp
q = save;
0978
2020-07-23
pjp
}
0979
2020-07-23
pjp
0980
2020-07-23
pjp
humanname = convert_name(expand, elen);
0981
2020-07-23
pjp
if (humanname == NULL) {
0982
2020-07-23
pjp
return -1;
0983
2020-07-23
pjp
}
0984
2020-07-23
pjp
0985
2020-07-23
pjp
if (f != NULL) {
0986
2020-07-23
pjp
fprintf(f, "%s\n", humanname);
0987
2020-07-23
pjp
}
0988
2020-07-23
pjp
0989
2020-07-23
pjp
free(humanname);
0990
2020-07-23
pjp
0991
2020-07-23
pjp
0992
2020-07-23
pjp
0993
2020-07-23
pjp
0994
2020-07-23
pjp
0995
2020-07-23
pjp
if (ctx != NULL) {
0996
2020-07-23
pjp
HMAC_Update(ctx, p, q - p);
0997
2020-07-23
pjp
}
0998
2020-07-23
pjp
0999
2020-07-23
pjp
return (q - estart);
1000
2020-07-23
pjp
}
1001
2020-07-23
pjp
1002
2020-07-23
pjp
int
1003
2020-07-08
pjp
raxfr_ns(FILE *f, u_char *p, u_char *estart, u_char *end, struct soa *mysoa, u_int16_t rdlen, HMAC_CTX *ctx)
1004
2020-07-08
pjp
{
1005
2020-07-08
pjp
char *save, *humanname;
1006
2020-07-08
pjp
u_char *q = p;
1007
2020-07-08
pjp
u_char expand[256];
1008
2020-07-08
pjp
int max = sizeof(expand);
1009
2020-07-08
pjp
int elen = 0;
1010
2020-07-08
pjp
1011
2020-07-08
pjp
memset(&expand, 0, sizeof(expand));
1012
2020-07-08
pjp
save = expand_compression(q, estart, end, (u_char *)&expand, &elen, max);
1013
2020-07-08
pjp
if (save == NULL) {
1014
2020-07-08
pjp
fprintf(stderr, "expanding compression failure 2\n");
1015
2020-07-08
pjp
return -1;
1016
2020-07-08
pjp
} else {
1017
2020-07-08
pjp
q = save;
1018
2020-07-08
pjp
}
1019
2020-07-08
pjp
1020
2020-07-08
pjp
humanname = convert_name(expand, elen);
1021
2020-07-08
pjp
if (humanname == NULL) {
1022
2020-07-08
pjp
return -1;
1023
2020-07-08
pjp
}
1024
2020-07-08
pjp
1025
2020-07-08
pjp
if (f != NULL) {
1026
2020-07-08
pjp
if (*humanname == '\0')
1027
2020-07-08
pjp
fprintf(f, ".\n");
1028
2020-07-08
pjp
else
1029
2020-07-08
pjp
fprintf(f, "%s\n", humanname);
1030
2020-07-08
pjp
}
1031
2020-07-08
pjp
1032
2020-07-08
pjp
free(humanname);
1033
2020-07-08
pjp
1034
2020-07-08
pjp
if (ctx != NULL) {
1035
2020-07-08
pjp
HMAC_Update(ctx, p, q - p);
1036
2020-07-08
pjp
}
1037
2020-07-08
pjp
1038
2020-07-08
pjp
return (q - estart);
1039
2020-07-08
pjp
}
1040
2020-07-08
pjp
1041
2019-02-07
pjp
int
1042
2020-07-08
pjp
raxfr_cname(FILE *f, u_char *p, u_char *estart, u_char *end, struct soa *mysoa, u_int16_t rdlen, HMAC_CTX *ctx)
1043
2019-02-07
pjp
{
1044
2020-07-08
pjp
return (raxfr_ns(f, p, estart, end, mysoa, rdlen, ctx));
1045
2019-02-07
pjp
}
1046
2019-02-07
pjp
1047
2019-02-07
pjp
1048
2019-02-07
pjp
int
1049
2020-07-08
pjp
raxfr_aaaa(FILE *f, u_char *p, u_char *estart, u_char *end, struct soa *mysoa, u_int16_t rdlen, HMAC_CTX *ctx)
1050
2019-02-07
pjp
{
1051
2019-02-07
pjp
char buf[INET6_ADDRSTRLEN];
1052
2019-12-03
pjp
struct in6_addr ia;
1053
2019-02-08
pjp
u_char *q = p;
1054
2019-02-07
pjp
1055
2019-12-03
pjp
BOUNDS_CHECK((p + sizeof(ia)), q, rdlen, end);
1056
2019-12-03
pjp
unpack((char *)&ia, p, sizeof(struct in6_addr));
1057
2019-12-03
pjp
inet_ntop(AF_INET6, &ia, buf, sizeof(buf));
1058
2019-02-07
pjp
1059
2020-07-08
pjp
if (f != NULL)
1060
2020-07-08
pjp
fprintf(f, "%s\n", buf);
1061
2019-02-07
pjp
1062
2019-12-03
pjp
p += sizeof(ia);
1063
2019-02-07
pjp
1064
2019-10-10
pjp
if (ctx != NULL)
1065
2019-10-10
pjp
HMAC_Update(ctx, q, p - q);
1066
2019-10-10
pjp
1067
2019-02-07
pjp
return (p - estart);
1068
2019-02-07
pjp
}
1069
2019-02-07
pjp
1070
2019-02-07
pjp
int
1071
2020-07-08
pjp
raxfr_a(FILE *f, u_char *p, u_char *estart, u_char *end, struct soa *mysoa, u_int16_t rdlen, HMAC_CTX *ctx)
1072
2019-02-07
pjp
{
1073
2019-02-07
pjp
char buf[INET_ADDRSTRLEN];
1074
2019-12-03
pjp
struct in_addr ia;
1075
2019-02-08
pjp
u_char *q = p;
1076
2019-02-07
pjp
1077
2019-12-03
pjp
BOUNDS_CHECK((p + sizeof(ia)), q, rdlen, end);
1078
2019-12-03
pjp
ia.s_addr = unpack32(p);
1079
2019-02-07
pjp
1080
2019-12-03
pjp
inet_ntop(AF_INET, &ia, buf, sizeof(buf));
1081
2019-02-07
pjp
1082
2020-07-08
pjp
if (f != NULL)
1083
2020-07-08
pjp
fprintf(f, "%s\n", buf);
1084
2019-02-07
pjp
1085
2019-12-03
pjp
p += sizeof(ia);
1086
2019-02-07
pjp
1087
2019-10-10
pjp
if (ctx != NULL)
1088
2019-10-10
pjp
HMAC_Update(ctx, q, p - q);
1089
2019-10-10
pjp
1090
2019-02-07
pjp
return (p - estart);
1091
2019-02-08
pjp
}
1092
2019-02-08
pjp
1093
2019-02-08
pjp
int
1094
2020-07-08
pjp
raxfr_tlsa(FILE *f, u_char *p, u_char *estart, u_char *end, struct soa *mysoa, u_int16_t rdlen, HMAC_CTX *ctx)
1095
2019-02-08
pjp
{
1096
2019-02-08
pjp
struct tlsa t;
1097
2019-02-08
pjp
u_char *q = p;
1098
2019-02-08
pjp
1099
2019-02-08
pjp
BOUNDS_CHECK((p + 1), q, rdlen, end);
1100
2019-02-08
pjp
t.usage = *p++;
1101
2019-02-08
pjp
BOUNDS_CHECK((p + 1), q, rdlen, end);
1102
2019-02-08
pjp
t.selector = *p++;
1103
2019-02-08
pjp
BOUNDS_CHECK((p + 1), q, rdlen, end);
1104
2019-02-08
pjp
t.matchtype = *p++;
1105
2019-02-08
pjp
1106
2019-02-08
pjp
if (rdlen - 3 < 0)
1107
2019-02-08
pjp
return -1;
1108
2019-02-08
pjp
1109
2019-02-08
pjp
t.datalen = (rdlen - 3);
1110
2019-02-08
pjp
1111
2019-02-08
pjp
if (t.datalen > sizeof(t.data))
1112
2019-02-08
pjp
return -1;
1113
2019-02-08
pjp
1114
2019-02-08
pjp
memcpy(&t.data, p, t.datalen);
1115
2019-02-08
pjp
p += t.datalen;
1116
2019-02-08
pjp
1117
2020-07-08
pjp
if (f != NULL) {
1118
2020-07-08
pjp
fprintf(f, "%u,%u,%u,\"%s\"\n", t.usage, t.selector,
1119
2020-07-08
pjp
t.matchtype, bin2hex(t.data, t.datalen));
1120
2019-02-08
pjp
}
1121
2019-02-08
pjp
1122
2019-10-10
pjp
if (ctx != NULL)
1123
2019-10-10
pjp
HMAC_Update(ctx, q, p - q);
1124
2019-10-10
pjp
1125
2019-02-08
pjp
return (p - estart);
1126
2019-02-08
pjp
}
1127
2019-02-08
pjp
1128
2019-02-08
pjp
int
1129
2020-07-08
pjp
raxfr_srv(FILE *f, u_char *p, u_char *estart, u_char *end, struct soa *mysoa, u_int16_t rdlen, HMAC_CTX *ctx)
1130
2019-02-08
pjp
{
1131
2019-12-03
pjp
u_int16_t tmp16;
1132
2019-02-08
pjp
struct srv s;
1133
2019-02-08
pjp
char *save, *humanname;
1134
2019-02-08
pjp
u_char *q = p;
1135
2019-02-08
pjp
u_char expand[256];
1136
2019-02-08
pjp
int max = sizeof(expand);
1137
2019-02-08
pjp
int elen = 0;
1138
2019-02-08
pjp
1139
2019-02-08
pjp
BOUNDS_CHECK((q + 2), p, rdlen, end);
1140
2019-12-03
pjp
tmp16 = unpack16(q);
1141
2019-12-03
pjp
s.priority = ntohs(tmp16);
1142
2019-02-08
pjp
q += 2;
1143
2019-02-08
pjp
BOUNDS_CHECK((q + 2), p, rdlen, end);
1144
2019-12-03
pjp
tmp16 = unpack16(q);
1145
2019-12-03
pjp
s.weight = ntohs(tmp16);
1146
2019-02-08
pjp
q += 2;
1147
2019-02-08
pjp
BOUNDS_CHECK((q + 2), p, rdlen, end);
1148
2019-12-03
pjp
tmp16 = unpack16(q);
1149
2019-12-03
pjp
s.port = ntohs(tmp16);
1150
2019-02-08
pjp
q += 2;
1151
2019-02-08
pjp
1152
2019-02-08
pjp
memset(&expand, 0, sizeof(expand));
1153
2019-02-08
pjp
save = expand_compression(q, estart, end, (u_char *)&expand, &elen, max);
1154
2019-02-08
pjp
if (save == NULL) {
1155
2019-02-08
pjp
fprintf(stderr, "expanding compression failure 2\n");
1156
2019-02-08
pjp
return -1;
1157
2019-02-08
pjp
} else {
1158
2019-02-08
pjp
q = save;
1159
2019-02-08
pjp
}
1160
2019-02-08
pjp
1161
2019-02-08
pjp
humanname = convert_name(expand, elen);
1162
2019-02-08
pjp
if (humanname == NULL) {
1163
2019-02-08
pjp
return -1;
1164
2019-02-08
pjp
}
1165
2019-02-08
pjp
1166
2020-07-08
pjp
if (f != NULL) {
1167
2020-07-08
pjp
if (*humanname == '\0')
1168
2020-07-08
pjp
fprintf(f, "%u,%u,%u,.\n", s.priority, s.weight, s.port);
1169
2020-07-08
pjp
else
1170
2020-07-08
pjp
fprintf(f, "%u,%u,%u,%s\n", s.priority, s.weight,
1171
2020-07-08
pjp
s.port, humanname);
1172
2019-02-08
pjp
}
1173
2019-02-08
pjp
1174
2019-02-08
pjp
free(humanname);
1175
2019-02-08
pjp
1176
2019-10-10
pjp
if (ctx != NULL)
1177
2019-10-10
pjp
HMAC_Update(ctx, p, q - p);
1178
2019-10-10
pjp
1179
2019-02-08
pjp
return (q - estart);
1180
2019-02-08
pjp
}
1181
2019-02-08
pjp
1182
2019-02-08
pjp
int
1183
2020-07-08
pjp
raxfr_naptr(FILE *f, u_char *p, u_char *estart, u_char *end, struct soa *mysoa, u_int16_t rdlen, HMAC_CTX *ctx)
1184
2019-02-08
pjp
{
1185
2019-12-03
pjp
u_int16_t tmp16;
1186
2019-02-08
pjp
struct naptr n;
1187
2019-02-08
pjp
char *save, *humanname;
1188
2019-02-08
pjp
u_char *q = p;
1189
2019-02-08
pjp
u_char expand[256];
1190
2019-02-08
pjp
int max = sizeof(expand);
1191
2019-02-08
pjp
int elen = 0;
1192
2019-02-08
pjp
int len, i;
1193
2019-02-08
pjp
1194
2019-02-08
pjp
BOUNDS_CHECK((q + 2), p, rdlen, end);
1195
2019-12-03
pjp
tmp16 = unpack16(q);
1196
2019-12-03
pjp
n.order = ntohs(tmp16);
1197
2019-02-08
pjp
q += 2;
1198
2019-02-08
pjp
BOUNDS_CHECK((q + 2), p, rdlen, end);
1199
2019-12-03
pjp
tmp16 = unpack16(q);
1200
2019-12-03
pjp
n.preference = ntohs(tmp16);
1201
2019-02-08
pjp
q += 2;
1202
2019-02-08
pjp
1203
2019-02-08
pjp
if (f != NULL) {
1204
2019-02-08
pjp
fprintf(f, "%u,%u,", n.order, n.preference);
1205
2019-02-08
pjp
}
1206
2019-02-08
pjp
1207
2019-02-08
pjp
1208
2019-02-08
pjp
/* flags */
1209
2019-02-08
pjp
BOUNDS_CHECK((q + 1), p, rdlen, end);
1210
2019-02-08
pjp
len = *q;
1211
2019-02-08
pjp
q++;
1212
2019-02-08
pjp
1213
2019-02-08
pjp
if (f != NULL) {
1214
2019-02-08
pjp
fprintf(f, "\"");
1215
2019-02-08
pjp
for (i = 0; i < len; i++) {
1216
2019-02-08
pjp
BOUNDS_CHECK((q + 1), p, rdlen, end);
1217
2019-02-08
pjp
fprintf(f, "%c", *q++);
1218
2019-02-08
pjp
}
1219
2019-02-08
pjp
fprintf(f, "\",");
1220
2019-02-08
pjp
}
1221
2019-02-08
pjp
/* services */
1222
2019-02-08
pjp
BOUNDS_CHECK((q + 1), p, rdlen, end);
1223
2019-02-08
pjp
len = *q;
1224
2019-02-08
pjp
q++;
1225
2019-02-08
pjp
1226
2019-02-08
pjp
if (f != NULL) {
1227
2019-02-08
pjp
fprintf(f, "\"");
1228
2019-02-08
pjp
for (i = 0; i < len; i++) {
1229
2019-02-08
pjp
BOUNDS_CHECK((q + 1), p, rdlen, end);
1230
2019-02-08
pjp
fprintf(f, "%c", *q++);
1231
2019-02-08
pjp
}
1232
2019-02-08
pjp
fprintf(f, "\",");
1233
2019-02-08
pjp
}
1234
2019-02-08
pjp
/* regexp */
1235
2019-02-08
pjp
BOUNDS_CHECK((q + 1), p, rdlen, end);
1236
2019-02-08
pjp
len = *q;
1237
2019-02-08
pjp
q++;
1238
2019-02-08
pjp
1239
2019-02-08
pjp
if (f != NULL) {
1240
2019-02-08
pjp
fprintf(f, "\"");
1241
2019-02-08
pjp
for (i = 0; i < len; i++) {
1242
2019-02-08
pjp
BOUNDS_CHECK((q + 1), p, rdlen, end);
1243
2019-02-08
pjp
fprintf(f, "%c", *q++);
1244
2019-02-08
pjp
}
1245
2019-02-08
pjp
fprintf(f, "\",");
1246
2019-02-08
pjp
}
1247
2019-02-08
pjp
1248
2019-02-08
pjp
memset(&expand, 0, sizeof(expand));
1249
2019-02-08
pjp
save = expand_compression(q, estart, end, (u_char *)&expand, &elen, max);
1250
2019-02-08
pjp
if (save == NULL) {
1251
2019-02-08
pjp
fprintf(stderr, "expanding compression failure 2\n");
1252
2019-02-08
pjp
return -1;
1253
2019-02-08
pjp
} else {
1254
2019-02-08
pjp
q = save;
1255
2019-02-08
pjp
}
1256
2019-02-08
pjp
1257
2019-02-08
pjp
humanname = convert_name(expand, elen);
1258
2019-02-08
pjp
if (humanname == NULL) {
1259
2019-02-08
pjp
return -1;
1260
2019-02-08
pjp
}
1261
2019-02-08
pjp
1262
2019-02-08
pjp
if (f != NULL) {
1263
2019-02-08
pjp
if (*humanname == '\0')
1264
2019-02-08
pjp
fprintf(f, ".\n");
1265
2019-02-08
pjp
else
1266
2019-02-08
pjp
fprintf(f, "%s\n", humanname);
1267
2019-02-08
pjp
}
1268
2019-02-08
pjp
1269
2019-02-08
pjp
free(humanname);
1270
2019-02-08
pjp
1271
2019-10-10
pjp
if (ctx != NULL)
1272
2019-10-10
pjp
HMAC_Update(ctx, p, q - p);
1273
2019-10-10
pjp
1274
2019-02-08
pjp
return (q - estart);
1275
2019-10-10
pjp
}
1276
2019-10-10
pjp
1277
2019-10-10
pjp
int
1278
2019-11-05
pjp
raxfr_tsig(FILE *f, u_char *p, u_char *estart, u_char *end, struct soa *mysoa, u_int16_t rdlen, HMAC_CTX *ctx, char *mac, int standardanswer)
1279
2019-10-10
pjp
{
1280
2019-10-10
pjp
struct dns_tsigrr *sdt;
1281
2019-10-10
pjp
char *save;
1282
2019-10-10
pjp
char *keyname = NULL, *algname = NULL;
1283
2019-10-10
pjp
char *rawkeyname = NULL, *rawalgname = NULL;
1284
2019-10-10
pjp
char *otherdata;
1285
2019-10-10
pjp
u_char expand[256];
1286
2019-10-10
pjp
u_char *q = p;
1287
2019-12-03
pjp
u_int16_t rtype, rclass, origid, tsigerror, otherlen;
1288
2019-12-03
pjp
u_int32_t rttl;
1289
2019-10-10
pjp
int rlen, rrlen = -1;
1290
2019-10-10
pjp
int elen = 0;
1291
2019-10-10
pjp
int max = sizeof(expand);
1292
2019-10-10
pjp
int rawkeynamelen, rawalgnamelen;
1293
2019-10-10
pjp
int macsize = 32;
1294
2019-10-10
pjp
1295
2019-10-10
pjp
memset(&expand, 0, sizeof(expand));
1296
2019-10-10
pjp
save = expand_compression(q, estart, end, (u_char *)&expand, &elen, max);
1297
2019-10-10
pjp
if (save == NULL) {
1298
2019-10-10
pjp
fprintf(stderr, "expanding compression failure 0\n");
1299
2019-10-10
pjp
goto out;
1300
2019-10-10
pjp
} else
1301
2019-10-10
pjp
q = save;
1302
2019-10-10
pjp
1303
2019-10-10
pjp
keyname = convert_name(expand, elen);
1304
2019-10-10
pjp
if (keyname == NULL) {
1305
2019-10-10
pjp
goto out;
1306
2019-10-10
pjp
}
1307
2019-10-10
pjp
1308
2019-10-10
pjp
rawkeyname = malloc(elen);
1309
2019-10-10
pjp
if (rawkeyname == NULL)
1310
2019-10-10
pjp
goto out;
1311
2019-10-10
pjp
1312
2019-10-10
pjp
memcpy(rawkeyname, expand, elen);
1313
2019-10-10
pjp
rawkeynamelen = elen;
1314
2019-10-10
pjp
1315
2019-10-10
pjp
if ((q + 2) > end)
1316
2019-10-10
pjp
goto out;
1317
2019-10-10
pjp
1318
2019-12-03
pjp
rtype = unpack16(q);
1319
2019-10-10
pjp
q += 2;
1320
2019-10-10
pjp
1321
2019-12-03
pjp
if (ntohs(rtype) != DNS_TYPE_TSIG)
1322
2019-10-10
pjp
goto out;
1323
2019-10-10
pjp
1324
2019-10-10
pjp
if ((q + 2) > end)
1325
2019-10-10
pjp
goto out;
1326
2019-10-10
pjp
1327
2019-12-03
pjp
rclass = unpack16(q);
1328
2019-10-10
pjp
q += 2;
1329
2019-10-10
pjp
1330
2019-12-03
pjp
if (ntohs(rclass) != DNS_CLASS_ANY)
1331
2019-10-10
pjp
goto out;
1332
2019-10-10
pjp
1333
2019-10-10
pjp
if ((q + 4) > end)
1334
2019-10-10
pjp
goto out;
1335
2019-10-10
pjp
1336
2019-12-03
pjp
rttl = unpack32(q);
1337
2019-10-10
pjp
q += 4;
1338
2019-10-10
pjp
1339
2019-12-03
pjp
if (rttl != 0)
1340
2019-10-10
pjp
goto out;
1341
2019-10-10
pjp
1342
2019-10-10
pjp
/* skip rdlen because raxfr_peek already got it */
1343
2019-10-10
pjp
if ((q + 2) > end)
1344
2019-10-10
pjp
goto out;
1345
2019-10-10
pjp
q += 2;
1346
2019-10-10
pjp
1347
2019-10-10
pjp
rlen = (q - estart);
1348
2019-10-10
pjp
1349
2019-10-10
pjp
memset(&expand, 0, sizeof(expand));
1350
2019-10-10
pjp
elen = 0;
1351
2019-10-10
pjp
save = expand_compression(q, estart, end, (u_char *)&expand, &elen, max);
1352
2019-10-10
pjp
if (save == NULL) {
1353
2019-10-10
pjp
fprintf(stderr, "expanding compression failure 0\n");
1354
2019-10-10
pjp
goto out;
1355
2019-10-10
pjp
} else
1356
2019-10-10
pjp
q = save;
1357
2019-10-10
pjp
1358
2019-10-10
pjp
1359
2019-10-10
pjp
algname = convert_name(expand, elen);
1360
2019-10-10
pjp
if (algname == NULL) {
1361
2019-10-10
pjp
goto out;
1362
2019-10-10
pjp
}
1363
2019-10-10
pjp
1364
2019-10-10
pjp
rawalgname = malloc(elen);
1365
2019-10-10
pjp
if (rawalgname == NULL)
1366
2019-10-10
pjp
goto out;
1367
2019-10-10
pjp
memcpy(rawalgname, expand, elen);
1368
2019-10-10
pjp
rawalgnamelen = elen;
1369
2019-10-10
pjp
1370
2019-10-10
pjp
if (strcasecmp(algname, "hmac-sha256.") != 0) {
1371
2019-10-10
pjp
goto out;
1372
2019-10-10
pjp
}
1373
2019-10-10
pjp
1374
2019-10-10
pjp
if ((q + sizeof(struct dns_tsigrr)) > end) {
1375
2019-10-10
pjp
goto out;
1376
2019-10-10
pjp
}
1377
2019-10-10
pjp
1378
2019-10-10
pjp
sdt = (struct dns_tsigrr *)q;
1379
2019-10-10
pjp
q += sizeof(struct dns_tsigrr);
1380
2019-10-10
pjp
1381
2019-10-10
pjp
if ((q + 2) > end)
1382
2019-10-10
pjp
goto out;
1383
2019-10-10
pjp
1384
2019-12-03
pjp
origid = unpack16(q);
1385
2019-10-10
pjp
q += 2;
1386
2019-10-10
pjp
1387
2019-10-10
pjp
if ((q + 2) > end)
1388
2019-10-10
pjp
goto out;
1389
2019-10-10
pjp
1390
2019-12-03
pjp
tsigerror = unpack16(q);
1391
2019-10-10
pjp
q += 2;
1392
2019-10-10
pjp
1393
2019-10-10
pjp
if ((q + 2) > end)
1394
2019-10-10
pjp
goto out;
1395
2019-10-10
pjp
1396
2019-12-03
pjp
otherlen = unpack16(q);
1397
2019-10-10
pjp
q += 2;
1398
2019-10-10
pjp
1399
2019-10-10
pjp
otherdata = q;
1400
2019-12-03
pjp
q += ntohs(otherlen);
1401
2019-10-10
pjp
1402
2019-10-10
pjp
if ((q - estart) != (rdlen + rlen)) {
1403
2019-10-10
pjp
goto out;
1404
2019-10-10
pjp
}
1405
2019-10-10
pjp
1406
2019-10-10
pjp
/* do something with the gathered data */
1407
2019-10-10
pjp
1408
2019-10-10
pjp
if (standardanswer) {
1409
2019-10-10
pjp
/* dns message */
1410
2019-10-10
pjp
HMAC_Update(ctx, rawkeyname, rawkeynamelen);
1411
2019-12-03
pjp
HMAC_Update(ctx, (char *)&rclass, 2);
1412
2019-12-03
pjp
HMAC_Update(ctx, (char *)&rttl, 4);
1413
2019-10-10
pjp
HMAC_Update(ctx, rawalgname, rawalgnamelen);
1414
2019-10-10
pjp
HMAC_Update(ctx, (char *)&sdt->timefudge, 8);
1415
2019-12-03
pjp
HMAC_Update(ctx, (char *)&tsigerror, 2);
1416
2019-12-03
pjp
HMAC_Update(ctx, (char *)&otherlen, 2);
1417
2019-12-03
pjp
if (ntohs(otherlen))
1418
2019-12-03
pjp
HMAC_Update(ctx, otherdata, ntohs(otherlen));
1419
2019-10-10
pjp
1420
2019-11-19
pjp
} else {
1421
2019-10-10
pjp
HMAC_Update(ctx, (char *)&sdt->timefudge, 8);
1422
2019-11-19
pjp
}
1423
2019-10-10
pjp
1424
2019-11-19
pjp
if (HMAC_Final(ctx, mac, &macsize) != 1) {
1425
2019-11-19
pjp
goto out;
1426
2019-11-19
pjp
}
1427
2019-10-10
pjp
1428
2019-11-19
pjp
#if __OpenBSD__
1429
2019-11-19
pjp
if (timingsafe_memcmp(sdt->mac, mac, macsize) != 0) {
1430
2019-11-19
pjp
#else
1431
2019-11-19
pjp
if (memcmp(sdt->mac, mac, macsize) != 0) {
1432
2019-11-19
pjp
#endif
1433
2019-11-05
pjp
#if 0
1434
2019-10-10
pjp
int i;
1435
2019-10-10
pjp
1436
2019-10-10
pjp
printf("the given mac: ");
1437
2019-10-10
pjp
for (i = 0; i < macsize; i++) {
1438
2019-10-10
pjp
printf("%02x", sdt->mac[i] & 0xff);
1439
2019-10-10
pjp
}
1440
2019-10-10
pjp
printf(" does not equal the calculated mac: ");
1441
2019-10-10
pjp
for (i = 0; i < macsize; i++) {
1442
2019-10-10
pjp
printf("%02x", mac[i] & 0xff);
1443
2019-10-10
pjp
}
1444
2019-10-10
pjp
printf("\n");
1445
2019-10-10
pjp
#endif
1446
2019-10-10
pjp
1447
2019-10-10
pjp
goto out;
1448
2019-10-10
pjp
}
1449
2019-10-10
pjp
1450
2019-10-10
pjp
rrlen = (q - estart);
1451
2019-10-10
pjp
1452
2019-10-10
pjp
out:
1453
2019-10-10
pjp
free(keyname);
1454
2019-10-10
pjp
free(algname);
1455
2019-10-10
pjp
free(rawkeyname);
1456
2019-10-10
pjp
free(rawalgname);
1457
2019-10-10
pjp
return (rrlen);
1458
2019-11-01
pjp
}
1459
2019-11-01
pjp
1460
2019-11-01
pjp
1461
2019-11-01
pjp
void
1462
2020-06-25
pjp
replicantloop(ddDB *db, struct imsgbuf *ibuf)
1463
2019-11-01
pjp
{
1464
2019-11-02
pjp
struct rzone *lrz, *lrz0;
1465
2019-11-02
pjp
time_t now, lastnow;
1466
2019-11-04
pjp
int sel, endspurt = 0;
1467
2019-11-02
pjp
int idata;
1468
2019-11-02
pjp
int64_t serial;
1469
2019-11-02
pjp
struct rbtree *rbt;
1470
2019-11-02
pjp
struct rrset *rrset;
1471
2019-11-02
pjp
struct rr *rrp;
1472
2019-11-02
pjp
struct timeval tv;
1473
2019-11-04
pjp
fd_set rset;
1474
2019-11-04
pjp
int max = 0;
1475
2019-11-01
pjp
1476
2019-11-04
pjp
struct imsg imsg;
1477
2019-11-04
pjp
ssize_t n, datalen;
1478
2019-11-04
pjp
char *dn = NULL;
1479
2019-11-04
pjp
char *humanconv = NULL;
1480
2019-11-02
pjp
1481
2019-11-18
pjp
int period, tot_refresh = 0, zonecount = 1;
1482
2019-11-18
pjp
int add_period = 0;
1483
2019-11-04
pjp
1484
2019-11-18
pjp
1485
2019-11-01
pjp
#if __OpenBSD__
1486
2019-11-01
pjp
if (pledge("stdio wpath rpath cpath inet", NULL) < 0) {
1487
2019-11-01
pjp
perror("pledge");
1488
2019-11-01
pjp
exit(1);
1489
2019-11-01
pjp
}
1490
2019-11-01
pjp
#endif
1491
2019-11-01
pjp
1492
2019-11-02
pjp
lastnow = time(NULL);
1493
2019-11-02
pjp
1494
2019-11-02
pjp
SLIST_FOREACH_SAFE(lrz, &rzones, rzone_entry, lrz0) {
1495
2019-11-01
pjp
if (lrz->zonename == NULL)
1496
2019-11-01
pjp
continue;
1497
2019-11-01
pjp
1498
2019-11-01
pjp
dolog(LOG_INFO, "adding SOA values to zone %s\n", lrz->zonename);
1499
2019-11-04
pjp
rbt = find_rrset(db, lrz->zone, lrz->zonelen);
1500
2019-11-02
pjp
if (rbt == NULL) {
1501
2019-11-02
pjp
dolog(LOG_INFO, "%s has no apex, removing zone from replicant engine\n", lrz->zonename);
1502
2019-11-02
pjp
SLIST_REMOVE(&rzones, lrz, rzone, rzone_entry);
1503
2019-11-02
pjp
continue;
1504
2019-11-02
pjp
}
1505
2019-11-02
pjp
1506
2019-11-02
pjp
rrset = find_rr(rbt, DNS_TYPE_SOA);
1507
2019-11-02
pjp
if (rrset == NULL) {
1508
2019-11-02
pjp
dolog(LOG_INFO, "%s has no SOA, removing zone from replicant engine\n", lrz->zonename);
1509
2019-11-02
pjp
SLIST_REMOVE(&rzones, lrz, rzone, rzone_entry);
1510
2019-11-02
pjp
continue;
1511
2019-11-02
pjp
}
1512
2019-11-02
pjp
rrp = TAILQ_FIRST(&rrset->rr_head);
1513
2019-11-02
pjp
if (rrp == NULL) {
1514
2019-11-02
pjp
dolog(LOG_INFO, "SOA record corrupted for zone %s, removing zone from replicant engine\n", lrz->zonename);
1515
2019-11-02
pjp
SLIST_REMOVE(&rzones, lrz, rzone, rzone_entry);
1516
2019-11-02
pjp
continue;
1517
2019-11-02
pjp
}
1518
2019-11-02
pjp
1519
2019-11-02
pjp
lrz->soa.serial = ((struct soa *)rrp->rdata)->serial;
1520
2019-11-02
pjp
lrz->soa.refresh = ((struct soa *)rrp->rdata)->refresh;
1521
2019-11-02
pjp
lrz->soa.retry = ((struct soa *)rrp->rdata)->retry;
1522
2019-11-02
pjp
lrz->soa.expire = ((struct soa *)rrp->rdata)->expire;
1523
2019-11-02
pjp
1524
2019-11-02
pjp
dolog(LOG_INFO, "%s -> %u, %u, %u, %u\n", lrz->zonename,
1525
2019-11-02
pjp
lrz->soa.serial, lrz->soa.refresh, lrz->soa.retry,
1526
2019-11-02
pjp
lrz->soa.expire);
1527
2019-11-02
pjp
1528
2019-11-18
pjp
zonecount++;
1529
2019-11-18
pjp
tot_refresh += lrz->soa.refresh;
1530
2019-11-18
pjp
1531
2019-11-18
pjp
}
1532
2019-11-18
pjp
1533
2019-11-18
pjp
period = (tot_refresh / zonecount) / zonecount;
1534
2019-11-18
pjp
add_period = period;
1535
2019-11-18
pjp
1536
2019-11-18
pjp
SLIST_FOREACH_SAFE(lrz, &rzones, rzone_entry, lrz0) {
1537
2019-11-18
pjp
if (lrz->zonename == NULL)
1538
2019-11-18
pjp
continue;
1539
2019-11-18
pjp
1540
2019-11-02
pjp
now = time(NULL);
1541
2019-11-18
pjp
now += period;
1542
2019-11-18
pjp
dolog(LOG_INFO, "refreshing %s at %s\n", lrz->zonename, ctime(&now));
1543
2019-11-18
pjp
schedule_refresh(lrz->zonename, now);
1544
2019-11-18
pjp
period += add_period;
1545
2019-11-02
pjp
}
1546
2019-11-04
pjp
1547
2019-11-01
pjp
for (;;) {
1548
2019-11-04
pjp
FD_ZERO(&rset);
1549
2019-11-02
pjp
if (endspurt) {
1550
2019-11-02
pjp
tv.tv_sec = 0;
1551
2019-11-02
pjp
tv.tv_usec = 5000;
1552
2019-11-02
pjp
} else {
1553
2019-11-03
pjp
tv.tv_sec = 1;
1554
2019-11-02
pjp
tv.tv_usec = 0;
1555
2019-11-02
pjp
}
1556
2019-11-04
pjp
1557
2019-11-04
pjp
FD_SET(ibuf->fd, &rset);
1558
2019-11-04
pjp
1559
2019-11-04
pjp
if (ibuf->fd > max)
1560
2019-11-04
pjp
max = ibuf->fd;
1561
2019-11-04
pjp
1562
2019-11-02
pjp
1563
2019-11-04
pjp
sel = select(max + 1, &rset, NULL, NULL, &tv);
1564
2019-11-02
pjp
if (sel == -1) {
1565
2019-11-02
pjp
dolog(LOG_INFO, "select error: %s\n", strerror(errno));
1566
2019-11-02
pjp
continue;
1567
2019-11-02
pjp
}
1568
2019-11-02
pjp
1569
2019-11-01
pjp
now = time(NULL);
1570
2019-11-01
pjp
1571
2019-11-02
pjp
/* some time safety */
1572
2019-11-02
pjp
if (now < lastnow) {
1573
2019-11-02
pjp
/* we had time go backwards, this is bad */
1574
2019-11-02
pjp
dolog(LOG_ERR, "time went backwards! rescheduling all schedules on refresh timeouts...\n");
1575
2019-11-01
pjp
1576
2019-11-02
pjp
/* blow away all schedules and redo them */
1577
2019-11-02
pjp
while (!LIST_EMPTY(&myschedules)) {
1578
2019-11-02
pjp
sp0 = LIST_FIRST(&myschedules);
1579
2019-11-02
pjp
LIST_REMOVE(sp0, myschedule_entry);
1580
2019-11-02
pjp
free(sp0);
1581
2019-11-02
pjp
}
1582
2019-11-02
pjp
1583
2019-11-02
pjp
SLIST_FOREACH(lrz, &rzones, rzone_entry) {
1584
2019-11-02
pjp
if (lrz->zonename == NULL)
1585
2019-11-02
pjp
continue;
1586
2019-11-02
pjp
schedule_refresh(lrz->zonename, now + lrz->soa.refresh);
1587
2019-11-02
pjp
}
1588
2019-11-02
pjp
1589
2019-11-02
pjp
lastnow = now;
1590
2019-11-02
pjp
continue;
1591
2019-11-02
pjp
}
1592
2019-11-02
pjp
1593
2019-11-02
pjp
lastnow = now;
1594
2019-11-02
pjp
1595
2019-11-04
pjp
if (FD_ISSET(ibuf->fd, &rset)) {
1596
2019-11-04
pjp
if ((n = imsg_read(ibuf)) < 0 && errno != EAGAIN) {
1597
2019-11-04
pjp
dolog(LOG_ERR, "imsg read failure %s\n", strerror(errno));
1598
2019-11-04
pjp
continue;
1599
2019-11-04
pjp
}
1600
2019-11-04
pjp
if (n == 0) {
1601
2019-11-04
pjp
/* child died? */
1602
2020-07-07
pjp
dolog(LOG_INFO, "sigpipe on child? raxfr process exiting.\n");
1603
2019-11-04
pjp
continue;
1604
2019-11-04
pjp
}
1605
2019-11-04
pjp
1606
2019-11-04
pjp
for (;;) {
1607
2019-11-04
pjp
if ((n = imsg_get(ibuf, &imsg)) < 0) {
1608
2019-11-04
pjp
dolog(LOG_ERR, "imsg read error: %s\n", strerror(errno));
1609
2019-11-04
pjp
break;
1610
2019-11-04
pjp
} else {
1611
2019-11-04
pjp
if (n == 0)
1612
2019-11-04
pjp
break;
1613
2019-11-04
pjp
1614
2019-11-04
pjp
datalen = imsg.hdr.len - IMSG_HEADER_SIZE;
1615
2019-11-04
pjp
1616
2019-11-04
pjp
switch(imsg.hdr.type) {
1617
2019-11-04
pjp
case IMSG_NOTIFY_MESSAGE:
1618
2019-11-04
pjp
dn = malloc(datalen);
1619
2019-11-04
pjp
if (dn == NULL) {
1620
2019-11-04
pjp
dolog(LOG_INFO, "malloc: %s\n", strerror(errno));
1621
2019-11-04
pjp
break;
1622
2019-11-04
pjp
}
1623
2019-11-04
pjp
1624
2019-11-04
pjp
memcpy(dn, imsg.data, datalen);
1625
2019-11-04
pjp
1626
2019-11-04
pjp
SLIST_FOREACH(lrz, &rzones, rzone_entry) {
1627
2019-11-04
pjp
if (lrz->zonename == NULL)
1628
2019-11-04
pjp
continue;
1629
2019-11-04
pjp
1630
2019-11-04
pjp
if (datalen == lrz->zonelen &&
1631
2019-11-04
pjp
memcasecmp(lrz->zone, dn, datalen) == 0)
1632
2019-11-04
pjp
break;
1633
2019-11-04
pjp
}
1634
2019-11-04
pjp
1635
2019-11-04
pjp
if (lrz != NULL) {
1636
2019-11-19
pjp
dolog(LOG_DEBUG, "zone %s is being notified now\n", lrz->zonename);
1637
2019-11-19
pjp
if ((serial = get_remote_soa(lrz)) == MY_SOCK_TIMEOUT) {
1638
2019-11-19
pjp
dolog(LOG_INFO, "timeout upon notify, dropping\n");
1639
2019-11-19
pjp
} else if (serial > lrz->soa.serial) {
1640
2019-11-19
pjp
/* initiate AXFR and update zone */
1641
2020-02-01
pjp
dolog(LOG_INFO, "zone %s new higher serial detected (%lld vs. %d)\n", lrz->zonename, serial, lrz->soa.serial);
1642
2019-11-04
pjp
1643
2019-11-19
pjp
if (pull_rzone(lrz, now) < 0) {
1644
2019-11-19
pjp
dolog(LOG_INFO, "AXFR failed\n");
1645
2019-11-19
pjp
} else {
1646
2019-11-06
pjp
schedule_restart(lrz->zonename, now + rand_restarttime());
1647
2019-11-04
pjp
endspurt = 1;
1648
2019-11-19
pjp
}
1649
2019-11-19
pjp
} /* else serial ... */
1650
2019-11-04
pjp
} else {
1651
2019-11-04
pjp
humanconv = convert_name(dn, datalen);
1652
2019-11-04
pjp
if (humanconv != NULL) {
1653
2019-11-04
pjp
dolog(LOG_DEBUG, "couldn't find an rzone for domainame %s\n", humanconv);
1654
2019-11-04
pjp
free(humanconv);
1655
2019-11-04
pjp
}
1656
2019-11-04
pjp
}
1657
2019-11-04
pjp
1658
2019-11-04
pjp
free(dn);
1659
2019-11-04
pjp
break;
1660
2019-11-04
pjp
} /* switch */
1661
2019-11-04
pjp
1662
2019-11-04
pjp
imsg_free(&imsg);
1663
2019-11-04
pjp
}
1664
2019-11-04
pjp
}
1665
2019-11-19
pjp
1666
2019-11-19
pjp
continue;
1667
2019-11-04
pjp
}
1668
2019-11-04
pjp
1669
2019-11-02
pjp
LIST_FOREACH_SAFE(sp0, &myschedules, myschedule_entry, sp1) {
1670
2019-11-02
pjp
if (sp0->when <= now) {
1671
2019-11-02
pjp
/* we hit a timeout on refresh */
1672
2019-11-02
pjp
if (sp0->action == SCHEDULE_ACTION_REFRESH) {
1673
2019-11-02
pjp
SLIST_FOREACH(lrz, &rzones, rzone_entry) {
1674
2019-11-02
pjp
if (lrz->zonename == NULL)
1675
2019-11-02
pjp
continue;
1676
2019-11-02
pjp
1677
2019-11-02
pjp
if (strcmp(sp0->zonename, lrz->zonename) == 0)
1678
2019-11-02
pjp
break;
1679
2019-11-02
pjp
}
1680
2019-11-02
pjp
1681
2019-11-02
pjp
if (lrz != NULL) {
1682
2019-11-02
pjp
dolog(LOG_DEBUG, "zone %s is being refreshed now\n", sp0->zonename);
1683
2019-11-02
pjp
/* must delete before adding any more */
1684
2019-11-02
pjp
schedule_delete(sp0);
1685
2019-11-02
pjp
if ((serial = get_remote_soa(lrz)) == MY_SOCK_TIMEOUT) {
1686
2019-11-19
pjp
dolog(LOG_ERR, "SOA lookup for zone %s failed\n", lrz->zonename);
1687
2019-11-02
pjp
/* we didn't get a reply and our socket timed out */
1688
2019-11-02
pjp
schedule_retry(lrz->zonename, now + lrz->soa.retry);
1689
2019-11-02
pjp
/* schedule a retry and go on */
1690
2019-11-02
pjp
} else if (serial > lrz->soa.serial) {
1691
2019-11-02
pjp
/* initiate AXFR and update zone */
1692
2020-01-31
pjp
dolog(LOG_INFO, "zone %s new higher serial detected (%lld vs. %d)\n", lrz->zonename, serial, lrz->soa.serial);
1693
2019-11-02
pjp
1694
2019-11-19
pjp
if (pull_rzone(lrz, now) < 0) {
1695
2019-11-19
pjp
dolog(LOG_ERR, "AXFR for zone %s failed\n", lrz->zonename);
1696
2019-11-02
pjp
schedule_retry(lrz->zonename, now + lrz->soa.retry);
1697
2019-11-02
pjp
goto out;
1698
2019-11-02
pjp
}
1699
2019-11-02
pjp
1700
2019-11-03
pjp
/* schedule restart */
1701
2019-11-06
pjp
schedule_restart(lrz->zonename, now + rand_restarttime());
1702
2019-11-06
pjp
endspurt = 1;
1703
2019-11-03
pjp
} else {
1704
2019-11-03
pjp
schedule_refresh(lrz->zonename, now + lrz->soa.refresh);
1705
2019-11-02
pjp
}
1706
2019-11-02
pjp
}
1707
2019-11-19
pjp
1708
2019-11-19
pjp
goto out;
1709
2019-11-02
pjp
} else if (sp0->action == SCHEDULE_ACTION_RETRY) {
1710
2019-11-02
pjp
/* we hit a timeout on retry */
1711
2019-11-02
pjp
1712
2019-11-02
pjp
SLIST_FOREACH(lrz, &rzones, rzone_entry) {
1713
2019-11-02
pjp
if (lrz->zonename == NULL)
1714
2019-11-02
pjp
continue;
1715
2019-11-02
pjp
1716
2019-11-02
pjp
if (strcmp(sp0->zonename, lrz->zonename) == 0)
1717
2019-11-02
pjp
break;
1718
2019-11-02
pjp
}
1719
2019-11-02
pjp
1720
2019-11-02
pjp
if (lrz != NULL) {
1721
2019-11-19
pjp
dolog(LOG_INFO, "AXFR for zone %s is being retried now\n", sp0->zonename);
1722
2019-11-02
pjp
schedule_delete(sp0);
1723
2019-11-02
pjp
if ((serial = get_remote_soa(lrz)) == MY_SOCK_TIMEOUT) {
1724
2019-11-19
pjp
dolog(LOG_ERR, "SOA lookup for zone %s failed\n", lrz->zonename);
1725
2019-11-02
pjp
/* we didn't get a reply and our socket timed out */
1726
2019-11-02
pjp
schedule_retry(lrz->zonename, now + lrz->soa.retry);
1727
2019-11-02
pjp
/* schedule a retry and go on */
1728
2019-11-19
pjp
goto out;
1729
2019-11-02
pjp
} else if (serial > lrz->soa.serial) {
1730
2019-11-02
pjp
/* initiate AXFR and update zone */
1731
2019-11-02
pjp
1732
2020-02-01
pjp
dolog(LOG_INFO, "zone %s new higher serial detected (%lld vs. %d)\n", lrz->zonename, serial, lrz->soa.serial);
1733
2019-11-02
pjp
1734
2019-11-19
pjp
if (pull_rzone(lrz, now) < 0) {
1735
2019-11-19
pjp
dolog(LOG_ERR, "AXFR for zone %s failed\n", lrz->zonename);
1736
2019-11-02
pjp
schedule_retry(lrz->zonename, now + lrz->soa.retry);
1737
2019-11-02
pjp
goto out;
1738
2019-11-02
pjp
}
1739
2019-11-02
pjp
1740
2019-11-03
pjp
/* schedule restart */
1741
2019-11-06
pjp
schedule_restart(lrz->zonename, now + rand_restarttime());
1742
2019-11-02
pjp
endspurt = 1;
1743
2019-11-03
pjp
} else {
1744
2019-11-03
pjp
schedule_refresh(lrz->zonename, now + lrz->soa.refresh);
1745
2019-11-03
pjp
}
1746
2019-11-02
pjp
}
1747
2019-11-19
pjp
1748
2019-11-19
pjp
goto out;
1749
2019-11-03
pjp
} else if (sp0->action == SCHEDULE_ACTION_RESTART) {
1750
2019-11-03
pjp
/* we hit a scheduling on restarting, nothing can save you now! */
1751
2019-11-03
pjp
dolog(LOG_INFO, "I'm supposed to restart now, RESTART\n");
1752
2019-11-02
pjp
1753
2019-11-02
pjp
idata = 1;
1754
2020-06-25
pjp
imsg_compose(ibuf, IMSG_RELOAD_MESSAGE,
1755
2019-11-02
pjp
0, 0, -1, &idata, sizeof(idata));
1756
2020-06-25
pjp
msgbuf_write(&ibuf->w);
1757
2020-06-25
pjp
for (;;)
1758
2020-06-25
pjp
sleep(1);
1759
2019-11-02
pjp
}
1760
2019-11-02
pjp
1761
2019-11-03
pjp
}
1762
2019-11-02
pjp
out:
1763
2019-11-02
pjp
continue;
1764
2019-11-02
pjp
} /* LIST_FOREACH schedules */
1765
2019-11-02
pjp
} /* for (;;) */
1766
2019-11-02
pjp
1767
2019-11-02
pjp
/* NOTREACHED */
1768
2019-11-02
pjp
}
1769
2019-11-02
pjp
1770
2019-11-02
pjp
static void
1771
2019-11-02
pjp
schedule_refresh(char *zonename, time_t seconds)
1772
2019-11-02
pjp
{
1773
2019-11-02
pjp
sp0 = calloc(1, sizeof(struct myschedule));
1774
2019-11-02
pjp
if (sp0 == NULL)
1775
2019-11-02
pjp
return;
1776
2019-11-02
pjp
1777
2019-11-02
pjp
strlcpy(sp0->zonename, zonename, sizeof(sp0->zonename));
1778
2019-11-02
pjp
sp0->when = seconds;
1779
2019-11-02
pjp
sp0->action = SCHEDULE_ACTION_REFRESH;
1780
2019-11-02
pjp
1781
2019-11-02
pjp
LIST_INSERT_HEAD(&myschedules, sp0, myschedule_entry);
1782
2019-11-02
pjp
}
1783
2019-11-02
pjp
1784
2019-11-02
pjp
static void
1785
2019-11-02
pjp
schedule_retry(char *zonename, time_t seconds)
1786
2019-11-02
pjp
{
1787
2019-11-02
pjp
sp0 = calloc(1, sizeof(struct myschedule));
1788
2019-11-02
pjp
if (sp0 == NULL)
1789
2019-11-02
pjp
return;
1790
2019-11-02
pjp
1791
2019-11-02
pjp
strlcpy(sp0->zonename, zonename, sizeof(sp0->zonename));
1792
2019-11-02
pjp
sp0->when = seconds;
1793
2019-11-02
pjp
sp0->action = SCHEDULE_ACTION_RETRY;
1794
2019-11-02
pjp
1795
2019-11-02
pjp
LIST_INSERT_HEAD(&myschedules, sp0, myschedule_entry);
1796
2019-11-02
pjp
1797
2019-11-02
pjp
}
1798
2019-11-02
pjp
1799
2019-11-02
pjp
static void
1800
2019-11-03
pjp
schedule_restart(char *zonename, time_t seconds)
1801
2019-11-02
pjp
{
1802
2020-04-07
pjp
1803
2020-04-07
pjp
LIST_FOREACH(sp0, &myschedules, myschedule_entry) {
1804
2020-04-07
pjp
if (sp0->action == SCHEDULE_ACTION_RESTART)
1805
2020-04-07
pjp
break;
1806
2020-04-07
pjp
}
1807
2020-04-07
pjp
1808
2020-04-07
pjp
if (sp0 != NULL) {
1809
2020-04-07
pjp
dolog(LOG_INFO, "found an existing restart entry, scheduling restart at %s", ctime(&sp0->when));
1810
2020-04-07
pjp
return;
1811
2020-04-07
pjp
}
1812
2020-04-07
pjp
1813
2019-11-02
pjp
sp0 = calloc(1, sizeof(struct myschedule));
1814
2019-11-02
pjp
if (sp0 == NULL)
1815
2019-11-02
pjp
return;
1816
2019-11-02
pjp
1817
2019-11-02
pjp
strlcpy(sp0->zonename, zonename, sizeof(sp0->zonename));
1818
2019-11-02
pjp
sp0->when = seconds;
1819
2019-11-03
pjp
sp0->action = SCHEDULE_ACTION_RESTART;
1820
2019-11-02
pjp
1821
2019-11-02
pjp
LIST_INSERT_HEAD(&myschedules, sp0, myschedule_entry);
1822
2019-11-02
pjp
1823
2019-11-04
pjp
dolog(LOG_INFO, "scheduling restart at %s", ctime(&seconds));
1824
2019-11-02
pjp
}
1825
2019-11-02
pjp
1826
2019-11-02
pjp
static void
1827
2019-11-02
pjp
schedule_delete(struct myschedule *sched)
1828
2019-11-02
pjp
{
1829
2019-11-19
pjp
sched->action = 0;
1830
2019-11-02
pjp
LIST_REMOVE(sched, myschedule_entry);
1831
2019-11-02
pjp
free(sched);
1832
2019-11-02
pjp
}
1833
2019-11-02
pjp
1834
2019-11-02
pjp
/*
1835
2019-11-02
pjp
* get the remote serial from the SOA, via TCP
1836
2019-11-02
pjp
*/
1837
2019-11-02
pjp
1838
2019-11-02
pjp
int64_t
1839
2019-11-02
pjp
get_remote_soa(struct rzone *rzone)
1840
2019-11-02
pjp
{
1841
2019-11-02
pjp
int so;
1842
2019-11-02
pjp
struct sockaddr_in sin;
1843
2019-11-02
pjp
struct sockaddr_in6 sin6;
1844
2019-11-02
pjp
struct sockaddr *sa;
1845
2019-11-02
pjp
struct soa mysoa;
1846
2019-11-02
pjp
socklen_t slen = sizeof(struct sockaddr_in);
1847
2019-11-02
pjp
1848
2019-11-05
pjp
char tsigpass[512];
1849
2019-11-05
pjp
char *keyname;
1850
2019-11-05
pjp
int tsigpasslen, keynamelen;
1851
2019-11-02
pjp
int len, i, answers;
1852
2019-11-02
pjp
int numansw, numaddi, numauth;
1853
2019-11-02
pjp
int rrtype, soacount = 0;
1854
2019-11-02
pjp
u_int16_t rdlen;
1855
2019-11-02
pjp
char query[512];
1856
2019-11-05
pjp
char *reply, *dupreply;
1857
2019-11-02
pjp
struct raxfr_logic *sr;
1858
2019-11-02
pjp
struct question *q;
1859
2019-11-02
pjp
struct whole_header {
1860
2019-11-02
pjp
struct dns_header dh;
1861
2019-11-02
pjp
} *wh, *rwh;
1862
2019-11-02
pjp
1863
2019-11-02
pjp
u_char *p, *name;
1864
2019-11-02
pjp
1865
2019-11-02
pjp
u_char *end, *estart;
1866
2019-11-02
pjp
int totallen, zonelen, rrlen;
1867
2019-11-02
pjp
int replysize = 0;
1868
2019-12-03
pjp
u_int16_t *tcpsize;
1869
2019-11-02
pjp
u_int16_t *plen;
1870
2019-11-02
pjp
u_int16_t tcplen;
1871
2019-11-02
pjp
1872
2019-11-02
pjp
FILE *f = NULL;
1873
2019-11-02
pjp
int format = 0;
1874
2019-11-05
pjp
int dotsig = 1;
1875
2019-11-05
pjp
time_t now;
1876
2019-11-05
pjp
1877
2019-11-05
pjp
char shabuf[32];
1878
2019-11-05
pjp
char *algname = NULL;
1879
2019-11-02
pjp
1880
2019-11-05
pjp
HMAC_CTX *ctx;
1881
2019-11-05
pjp
uint16_t hmaclen;
1882
2019-11-05
pjp
int sacount = 0;
1883
2019-11-05
pjp
1884
2019-11-02
pjp
1885
2019-11-02
pjp
if ((so = socket(rzone->storage.ss_family, SOCK_STREAM, 0)) < 0) {
1886
2019-11-02
pjp
dolog(LOG_INFO, "get_remote_soa: %s\n", strerror(errno));
1887
2019-11-02
pjp
return MY_SOCK_TIMEOUT;
1888
2019-11-02
pjp
}
1889
2019-11-02
pjp
1890
2019-11-02
pjp
if (rzone->storage.ss_family == AF_INET6) {
1891
2019-11-02
pjp
memset(&sin6, 0, sizeof(sin6));
1892
2019-11-02
pjp
sin6.sin6_family = AF_INET6;
1893
2019-11-02
pjp
sin6.sin6_port = htons(rzone->masterport);
1894
2019-11-02
pjp
memcpy(&sin6.sin6_addr, (void *)&((struct sockaddr_in6 *)(&rzone->storage))->sin6_addr, sizeof(struct in6_addr));
1895
2019-11-19
pjp
#ifndef __linux__
1896
2019-11-02
pjp
sin6.sin6_len = sizeof(struct sockaddr_in6);
1897
2019-11-19
pjp
#endif
1898
2019-11-02
pjp
sa = (struct sockaddr *)&sin6;
1899
2019-11-02
pjp
slen = sizeof(struct sockaddr_in6);
1900
2019-11-02
pjp
} else {
1901
2019-11-02
pjp
memset(&sin, 0, sizeof(sin));
1902
2019-11-02
pjp
sin.sin_family = AF_INET;
1903
2019-11-02
pjp
sin.sin_port = htons(rzone->masterport);
1904
2019-11-02
pjp
sin.sin_addr.s_addr = ((struct sockaddr_in *)(&rzone->storage))->sin_addr.s_addr;
1905
2019-11-02
pjp
sa = (struct sockaddr *)&sin;
1906
2019-11-02
pjp
}
1907
2019-11-02
pjp
1908
2020-03-10
pjp
if (rzone->tsigkey != NULL && strcmp(rzone->tsigkey, "NOKEY") != 0) {
1909
2019-11-05
pjp
1910
2019-11-05
pjp
keyname = dns_label(rzone->tsigkey, &keynamelen);
1911
2019-11-05
pjp
if (keyname == NULL) {
1912
2019-11-05
pjp
dolog(LOG_ERR, "dns_label failed\n");
1913
2019-11-05
pjp
close(so);
1914
2019-11-05
pjp
return MY_SOCK_TIMEOUT;
1915
2019-11-05
pjp
}
1916
2019-11-05
pjp
1917
2019-11-05
pjp
if ((tsigpasslen = find_tsig_key(keyname, keynamelen, (char *)&tsigpass, sizeof(tsigpass))) < 0) {
1918
2019-11-05
pjp
dolog(LOG_ERR, "do not have a record of TSIG key %s\n", rzone->tsigkey);
1919
2019-11-05
pjp
close(so);
1920
2019-11-05
pjp
return MY_SOCK_TIMEOUT;
1921
2019-11-05
pjp
}
1922
2019-11-05
pjp
1923
2019-11-05
pjp
dotsig = 1;
1924
2019-11-05
pjp
1925
2019-11-05
pjp
} else {
1926
2019-11-05
pjp
dotsig = 0;
1927
2019-11-05
pjp
}
1928
2019-11-05
pjp
1929
2019-11-02
pjp
if (connect(so, sa, slen) < 0) {
1930
2019-11-02
pjp
dolog(LOG_INFO, "connect to master %s port %u: %s\n", rzone->master, rzone->masterport, strerror(errno));
1931
2019-11-05
pjp
close(so);
1932
2019-11-05
pjp
return(MY_SOCK_TIMEOUT);
1933
2019-11-02
pjp
}
1934
2019-11-02
pjp
1935
2019-11-02
pjp
1936
2019-11-02
pjp
1937
2019-11-02
pjp
replysize = 0xffff;
1938
2019-11-02
pjp
memset(&query, 0, sizeof(query));
1939
2019-11-02
pjp
1940
2019-11-02
pjp
tcpsize = (u_int16_t *)&query[0];
1941
2019-11-02
pjp
wh = (struct whole_header *)&query[2];
1942
2019-11-02
pjp
1943
2019-11-02
pjp
wh->dh.id = htons(arc4random() & 0xffff);
1944
2019-11-02
pjp
wh->dh.query = 0;
1945
2019-11-02
pjp
wh->dh.question = htons(1);
1946
2019-11-02
pjp
wh->dh.answer = 0;
1947
2019-11-02
pjp
wh->dh.nsrr = 0;
1948
2019-11-05
pjp
wh->dh.additional = 0;
1949
2019-11-02
pjp
1950
2019-11-02
pjp
SET_DNS_QUERY(&wh->dh);
1951
2019-11-02
pjp
SET_DNS_RECURSION(&wh->dh);
1952
2019-11-02
pjp
1953
2019-11-02
pjp
1954
2019-11-02
pjp
HTONS(wh->dh.query);
1955
2019-11-02
pjp
1956
2019-11-02
pjp
totallen = sizeof(struct whole_header) + 2;
1957
2019-11-02
pjp
1958
2019-11-02
pjp
name = dns_label(rzone->zonename, &len);
1959
2019-11-02
pjp
if (name == NULL) {
1960
2019-11-02
pjp
close(so);
1961
2019-11-02
pjp
return(MY_SOCK_TIMEOUT);
1962
2019-11-02
pjp
}
1963
2019-11-02
pjp
1964
2019-11-02
pjp
zonelen = len;
1965
2019-11-02
pjp
1966
2019-11-02
pjp
p = (char *)&wh[1];
1967
2019-11-02
pjp
1968
2019-11-02
pjp
memcpy(p, name, len);
1969
2019-11-02
pjp
totallen += len;
1970
2019-11-02
pjp
1971
2019-12-03
pjp
pack16(&query[totallen], htons(DNS_TYPE_SOA));
1972
2019-11-02
pjp
totallen += sizeof(u_int16_t);
1973
2019-11-02
pjp
1974
2019-12-03
pjp
pack16(&query[totallen], htons(DNS_CLASS_IN));
1975
2019-11-02
pjp
totallen += sizeof(u_int16_t);
1976
2019-11-02
pjp
1977
2019-11-05
pjp
/* we have a key, attach a TSIG payload */
1978
2019-11-05
pjp
if (dotsig) {
1979
2019-11-05
pjp
ctx = HMAC_CTX_new();
1980
2019-11-05
pjp
HMAC_Init_ex(ctx, tsigpass, tsigpasslen, EVP_sha256(), NULL);
1981
2019-11-05
pjp
HMAC_Update(ctx, &query[2], totallen - 2);
1982
2019-11-02
pjp
1983
2019-11-05
pjp
now = time(NULL);
1984
2019-12-11
pjp
if (tsig_pseudoheader(rzone->tsigkey, DEFAULT_TSIG_FUDGE, now, ctx) < 0) {
1985
2019-11-05
pjp
fprintf(stderr, "tsig_pseudoheader failed\n");
1986
2019-11-05
pjp
return(MY_SOCK_TIMEOUT);
1987
2019-11-05
pjp
}
1988
2019-11-02
pjp
1989
2019-11-05
pjp
HMAC_Final(ctx, shabuf, &len);
1990
2019-11-02
pjp
1991
2019-11-05
pjp
if (len != 32) {
1992
2019-11-05
pjp
fprintf(stderr, "not expected len != 32\n");
1993
2019-11-05
pjp
return(MY_SOCK_TIMEOUT);
1994
2019-11-05
pjp
}
1995
2019-11-02
pjp
1996
2019-11-05
pjp
HMAC_CTX_free(ctx);
1997
2019-11-05
pjp
1998
2019-11-05
pjp
memcpy(&query[totallen], keyname, keynamelen);
1999
2019-11-05
pjp
totallen += keynamelen;
2000
2019-11-05
pjp
2001
2019-12-03
pjp
pack16(&query[totallen], htons(DNS_TYPE_TSIG));
2002
2019-11-05
pjp
totallen += 2;
2003
2019-11-05
pjp
2004
2019-12-03
pjp
pack16(&query[totallen], htons(DNS_CLASS_ANY));
2005
2019-11-05
pjp
totallen += 2;
2006
2019-11-05
pjp
2007
2019-12-03
pjp
pack32(&query[totallen], 0);
2008
2019-11-05
pjp
totallen += 4;
2009
2019-11-05
pjp
2010
2019-11-05
pjp
algname = dns_label("hmac-sha256", &len);
2011
2019-11-05
pjp
if (algname == NULL) {
2012
2019-11-05
pjp
return(MY_SOCK_TIMEOUT);
2013
2019-11-05
pjp
}
2014
2019-11-05
pjp
2015
2019-11-05
pjp
/* rdlen */
2016
2019-12-03
pjp
pack16(&query[totallen], htons(len + 2 + 4 + 2 + 2 + 32 + 2 + 2 + 2));
2017
2019-11-05
pjp
totallen += 2;
2018
2019-11-05
pjp
2019
2019-11-05
pjp
/* algorithm name */
2020
2019-11-05
pjp
memcpy(&query[totallen], algname, len);
2021
2019-11-05
pjp
totallen += len;
2022
2019-11-05
pjp
2023
2019-11-05
pjp
free(algname);
2024
2019-11-05
pjp
2025
2019-11-05
pjp
/* time 1 */
2026
2019-12-06
pjp
if (sizeof(time_t) == 4) /* 32-bit time_t */
2027
2019-12-06
pjp
pack16(&query[totallen], 0);
2028
2019-12-06
pjp
else
2029
2019-12-06
pjp
pack16(&query[totallen], htons((now >> 32) & 0xffff));
2030
2019-11-05
pjp
totallen += 2;
2031
2019-11-05
pjp
2032
2019-11-05
pjp
/* time 2 */
2033
2019-12-03
pjp
pack32(&query[totallen], htonl((now & 0xffffffff)));
2034
2019-11-05
pjp
totallen += 4;
2035
2019-11-05
pjp
2036
2019-11-05
pjp
/* fudge */
2037
2019-12-11
pjp
pack16(&query[totallen], htons(DEFAULT_TSIG_FUDGE));
2038
2019-11-05
pjp
totallen += 2;
2039
2019-11-05
pjp
2040
2019-11-05
pjp
/* hmac size */
2041
2019-12-03
pjp
pack16(&query[totallen], htons(sizeof(shabuf)));
2042
2019-11-05
pjp
totallen += 2;
2043
2019-11-05
pjp
2044
2019-11-05
pjp
/* hmac */
2045
2019-11-05
pjp
memcpy(&query[totallen], shabuf, sizeof(shabuf));
2046
2019-11-05
pjp
totallen += sizeof(shabuf);
2047
2019-11-05
pjp
2048
2019-11-05
pjp
/* original id */
2049
2019-12-03
pjp
pack16(&query[totallen], wh->dh.id);
2050
2019-11-05
pjp
totallen += 2;
2051
2019-11-05
pjp
2052
2019-11-05
pjp
/* error */
2053
2019-12-03
pjp
pack16(&query[totallen], 0);
2054
2019-11-05
pjp
totallen += 2;
2055
2019-11-05
pjp
2056
2019-11-05
pjp
/* other len */
2057
2019-12-03
pjp
pack16(&query[totallen], 0);
2058
2019-11-05
pjp
totallen += 2;
2059
2019-11-05
pjp
2060
2019-11-05
pjp
wh->dh.additional = htons(1);
2061
2019-11-05
pjp
}
2062
2019-11-05
pjp
2063
2019-12-04
pjp
pack16((char *)tcpsize, htons(totallen - 2));
2064
2019-11-05
pjp
2065
2019-11-02
pjp
if (send(so, query, totallen, 0) < 0) {
2066
2019-11-02
pjp
close(so);
2067
2019-11-02
pjp
return(MY_SOCK_TIMEOUT);
2068
2019-11-02
pjp
}
2069
2019-11-02
pjp
2070
2019-11-02
pjp
/* catch reply */
2071
2019-11-02
pjp
2072
2019-11-02
pjp
reply = calloc(1, replysize + 2);
2073
2019-11-02
pjp
if (reply == NULL) {
2074
2019-11-02
pjp
dolog(LOG_INFO, "calloc: %s\n", strerror(errno));
2075
2019-11-02
pjp
close(so);
2076
2019-11-02
pjp
return(MY_SOCK_TIMEOUT);
2077
2019-11-02
pjp
}
2078
2019-11-05
pjp
dupreply = calloc(1, replysize + 2);
2079
2019-11-05
pjp
if (dupreply == NULL) {
2080
2019-11-05
pjp
dolog(LOG_INFO, "calloc: %s\n", strerror(errno));
2081
2019-11-05
pjp
close(so);
2082
2019-11-05
pjp
return(MY_SOCK_TIMEOUT);
2083
2019-11-05
pjp
}
2084
2019-11-02
pjp
2085
2019-11-02
pjp
if ((len = recv(so, reply, 2, MSG_PEEK | MSG_WAITALL)) < 0) {
2086
2019-11-02
pjp
dolog(LOG_INFO, "recv: %s\n", strerror(errno));
2087
2019-11-02
pjp
close(so);
2088
2019-11-05
pjp
free(reply); free(dupreply);
2089
2019-11-02
pjp
return(MY_SOCK_TIMEOUT);
2090
2019-11-02
pjp
}
2091
2019-11-02
pjp
2092
2019-11-02
pjp
plen = (u_int16_t *)reply;
2093
2019-11-02
pjp
tcplen = ntohs(*plen);
2094
2019-11-02
pjp
2095
2019-11-02
pjp
if ((len = recv(so, reply, tcplen + 2, MSG_WAITALL)) < 0) {
2096
2019-11-02
pjp
dolog(LOG_INFO, "recv: %s\n", strerror(errno));
2097
2019-11-02
pjp
close(so);
2098
2019-11-05
pjp
free(reply); free(dupreply);
2099
2019-11-02
pjp
return(MY_SOCK_TIMEOUT);
2100
2019-11-02
pjp
}
2101
2019-11-02
pjp
2102
2019-11-05
pjp
memcpy(dupreply, reply, len);
2103
2019-11-02
pjp
rwh = (struct whole_header *)&reply[2];
2104
2019-11-02
pjp
2105
2019-11-02
pjp
end = &reply[len];
2106
2019-11-02
pjp
2107
2019-11-02
pjp
if (rwh->dh.id != wh->dh.id) {
2108
2019-11-02
pjp
dolog(LOG_INFO, "DNS ID mismatch\n");
2109
2019-11-02
pjp
close(so);
2110
2019-11-05
pjp
free(reply); free(dupreply);
2111
2019-11-02
pjp
return(MY_SOCK_TIMEOUT);
2112
2019-11-02
pjp
}
2113
2019-11-02
pjp
2114
2019-11-02
pjp
if (!(htons(rwh->dh.query) & DNS_REPLY)) {
2115
2019-11-02
pjp
dolog(LOG_INFO, "NOT a DNS reply\n");
2116
2019-11-02
pjp
close(so);
2117
2019-11-05
pjp
free(reply); free(dupreply);
2118
2019-11-02
pjp
return(MY_SOCK_TIMEOUT);
2119
2019-11-02
pjp
}
2120
2019-11-02
pjp
2121
2019-11-02
pjp
numansw = ntohs(rwh->dh.answer);
2122
2019-11-02
pjp
numauth = ntohs(rwh->dh.nsrr);
2123
2019-11-02
pjp
numaddi = ntohs(rwh->dh.additional);
2124
2019-11-02
pjp
answers = numansw + numauth + numaddi;
2125
2019-11-02
pjp
2126
2019-11-02
pjp
if (answers < 1) {
2127
2019-11-02
pjp
dolog(LOG_INFO, "NO ANSWER provided\n");
2128
2019-11-02
pjp
close(so);
2129
2019-11-05
pjp
free(reply); free(dupreply);
2130
2019-11-02
pjp
return(MY_SOCK_TIMEOUT);
2131
2019-11-02
pjp
}
2132
2019-11-02
pjp
2133
2019-11-05
pjp
q = build_question((char *)dupreply + 2, len - 2, wh->dh.additional, NULL);
2134
2019-11-02
pjp
if (q == NULL) {
2135
2019-11-02
pjp
dolog(LOG_INFO, "failed to build_question\n");
2136
2019-11-02
pjp
close(so);
2137
2019-11-05
pjp
free(reply); free(dupreply);
2138
2019-11-02
pjp
return(MY_SOCK_TIMEOUT);
2139
2019-11-02
pjp
}
2140
2019-11-02
pjp
2141
2019-11-05
pjp
if (memcasecmp(q->hdr->name, name, q->hdr->namelen) != 0) {
2142
2019-11-02
pjp
dolog(LOG_INFO, "question name not for what we asked\n");
2143
2019-11-02
pjp
close(so);
2144
2019-11-05
pjp
free(reply); free(dupreply);
2145
2019-11-02
pjp
return(MY_SOCK_TIMEOUT);
2146
2019-11-02
pjp
}
2147
2019-11-02
pjp
2148
2019-11-05
pjp
if (ntohs(q->hdr->qclass) != DNS_CLASS_IN || ntohs(q->hdr->qtype) != DNS_TYPE_SOA) {
2149
2019-11-02
pjp
dolog(LOG_INFO, "wrong class or type\n");
2150
2019-11-02
pjp
close(so);
2151
2019-11-05
pjp
free(reply); free(dupreply);
2152
2019-11-02
pjp
return(MY_SOCK_TIMEOUT);
2153
2019-11-02
pjp
}
2154
2019-11-05
pjp
2155
2019-11-02
pjp
2156
2019-11-02
pjp
p = (u_char *)&rwh[1];
2157
2019-11-02
pjp
2158
2019-11-02
pjp
p += q->hdr->namelen;
2159
2019-11-02
pjp
p += sizeof(u_int16_t); /* type */
2160
2019-11-02
pjp
p += sizeof(u_int16_t); /* class */
2161
2019-11-02
pjp
2162
2019-11-02
pjp
/* end of question */
2163
2019-11-02
pjp
2164
2019-11-02
pjp
2165
2019-11-02
pjp
estart = (u_char *)&rwh->dh;
2166
2019-11-02
pjp
2167
2019-11-05
pjp
if (dotsig) {
2168
2019-11-05
pjp
ctx = HMAC_CTX_new();
2169
2019-11-05
pjp
HMAC_Init_ex(ctx, tsigpass, tsigpasslen, EVP_sha256(), NULL);
2170
2019-11-05
pjp
hmaclen = htons(32);
2171
2019-11-05
pjp
HMAC_Update(ctx, (char *)&hmaclen, sizeof(hmaclen));
2172
2019-11-05
pjp
HMAC_Update(ctx, shabuf, sizeof(shabuf));
2173
2019-11-05
pjp
hmaclen = rwh->dh.additional; /* save additional */
2174
2019-11-05
pjp
NTOHS(rwh->dh.additional);
2175
2019-11-19
pjp
if (rwh->dh.additional)
2176
2019-11-19
pjp
rwh->dh.additional--;
2177
2019-11-05
pjp
HTONS(rwh->dh.additional);
2178
2019-11-05
pjp
HMAC_Update(ctx, estart, (p - estart));
2179
2019-11-05
pjp
rwh->dh.additional = hmaclen; /* restore additional */
2180
2019-11-05
pjp
}
2181
2019-11-05
pjp
2182
2019-11-05
pjp
2183
2019-11-02
pjp
for (i = answers; i > 0; i--) {
2184
2020-07-27
pjp
if ((rrlen = raxfr_peek(f, p, estart, end, &rrtype, 0, &rdlen, format, (dotsig == 1) ? ctx : NULL, name, zonelen, 0)) < 0) {
2185
2019-11-02
pjp
dolog(LOG_INFO, "not a SOA reply, or ERROR\n");
2186
2019-11-02
pjp
close(so);
2187
2019-11-05
pjp
free(reply); free(dupreply);
2188
2019-11-02
pjp
return(MY_SOCK_TIMEOUT);
2189
2019-11-02
pjp
}
2190
2019-11-02
pjp
2191
2019-11-05
pjp
if (rrtype != DNS_TYPE_TSIG)
2192
2019-11-05
pjp
p = (estart + rrlen);
2193
2019-11-02
pjp
2194
2019-11-02
pjp
if (rrtype == DNS_TYPE_SOA) {
2195
2020-07-27
pjp
if ((len = raxfr_soa(f, p, estart, end, &mysoa, soacount, format, rdlen, (dotsig == 1) ? ctx : NULL, &rz->constraints)) < 0) {
2196
2019-11-02
pjp
dolog(LOG_INFO, "raxfr_soa failed\n");
2197
2019-11-02
pjp
close(so);
2198
2019-11-05
pjp
free(reply); free(dupreply);
2199
2019-11-02
pjp
return(MY_SOCK_TIMEOUT);
2200
2019-11-02
pjp
}
2201
2019-11-02
pjp
p = (estart + len);
2202
2019-11-02
pjp
soacount++;
2203
2019-11-05
pjp
} else if (dotsig && (rrtype == DNS_TYPE_TSIG)) {
2204
2019-11-05
pjp
/* do tsig checks here */
2205
2019-11-05
pjp
if ((len = raxfr_tsig(f,p,estart,end,&mysoa,rdlen,ctx, (char *)&shabuf, (sacount++ == 0) ? 1 : 0)) < 0) {
2206
2019-11-05
pjp
fprintf(stderr, "error with TSIG record\n");
2207
2019-11-05
pjp
close(so);
2208
2019-11-05
pjp
free(reply); free(dupreply);
2209
2019-11-05
pjp
return(MY_SOCK_TIMEOUT);
2210
2019-11-05
pjp
}
2211
2019-11-05
pjp
2212
2019-11-05
pjp
p = (estart + len);
2213
2019-11-02
pjp
} else {
2214
2019-11-02
pjp
for (sr = supported; sr->rrtype != 0; sr++) {
2215
2019-11-02
pjp
if (rrtype == sr->rrtype) {
2216
2020-07-08
pjp
if ((len = (*sr->raxfr)(f, p, estart, end, &mysoa, rdlen, (dotsig == 1) ? ctx : NULL)) < 0) {
2217
2019-11-02
pjp
dolog(LOG_INFO, "error with rrtype %d\n", sr->rrtype);
2218
2019-11-02
pjp
close(so);
2219
2019-11-05
pjp
free(reply); free(dupreply);
2220
2019-11-02
pjp
return(MY_SOCK_TIMEOUT);
2221
2019-11-02
pjp
}
2222
2019-11-02
pjp
p = (estart + len);
2223
2019-11-02
pjp
break;
2224
2019-11-02
pjp
}
2225
2019-11-02
pjp
}
2226
2019-11-02
pjp
2227
2019-11-02
pjp
if (sr->rrtype == 0) {
2228
2019-11-05
pjp
if (rrtype != 41 && rrtype != 250) {
2229
2019-11-02
pjp
dolog(LOG_INFO, "unsupported RRTYPE %u\n", rrtype);
2230
2019-11-02
pjp
close(so);
2231
2019-11-05
pjp
free(reply); free(dupreply);
2232
2019-11-02
pjp
return(MY_SOCK_TIMEOUT);
2233
2019-11-02
pjp
}
2234
2019-11-02
pjp
}
2235
2019-11-02
pjp
} /* rrtype == DNS_TYPE_SOA */
2236
2019-11-02
pjp
2237
2019-11-02
pjp
2238
2019-11-02
pjp
} /* for () */
2239
2019-11-02
pjp
2240
2019-11-05
pjp
free(reply); free(dupreply);
2241
2019-11-02
pjp
2242
2019-11-02
pjp
close(so);
2243
2019-11-05
pjp
2244
2019-11-05
pjp
if (dotsig) {
2245
2019-11-05
pjp
HMAC_CTX_free(ctx);
2246
2019-11-05
pjp
}
2247
2019-11-05
pjp
2248
2019-11-02
pjp
return ((int64_t)ntohl(mysoa.serial));
2249
2019-11-02
pjp
}
2250
2019-11-02
pjp
2251
2019-11-02
pjp
int
2252
2019-11-03
pjp
do_raxfr(FILE *f, struct rzone *rzone)
2253
2019-11-02
pjp
{
2254
2019-11-02
pjp
int so;
2255
2019-11-02
pjp
struct sockaddr_in sin;
2256
2019-11-02
pjp
struct sockaddr_in6 sin6;
2257
2019-11-02
pjp
struct sockaddr *sa;
2258
2019-11-02
pjp
socklen_t slen = sizeof(struct sockaddr_in);
2259
2019-11-02
pjp
2260
2019-11-04
pjp
u_int window = 32768;
2261
2019-11-02
pjp
char tsigpass[512];
2262
2019-11-02
pjp
char humanpass[1024];
2263
2019-11-02
pjp
char *keyname;
2264
2019-11-02
pjp
int tsigpasslen, keynamelen;
2265
2019-11-04
pjp
u_int32_t format = (TCP_FORMAT | ZONE_FORMAT);
2266
2019-11-03
pjp
int len, dotsig = 1;
2267
2019-11-05
pjp
int segment = 0;
2268
2019-11-05
pjp
int answers = 0;
2269
2019-11-05
pjp
int additionalcount = 0;
2270
2019-11-02
pjp
2271
2019-11-02
pjp
struct soa mysoa;
2272
2019-11-02
pjp
2273
2019-11-02
pjp
2274
2019-11-02
pjp
if ((so = socket(rzone->storage.ss_family, SOCK_STREAM, 0)) < 0) {
2275
2019-11-02
pjp
dolog(LOG_INFO, "get_remote_soa: %s\n", strerror(errno));
2276
2019-11-02
pjp
return -1;
2277
2019-11-02
pjp
}
2278
2019-11-02
pjp
2279
2019-11-02
pjp
#ifndef __linux__
2280
2019-11-02
pjp
/* biggen the window */
2281
2019-11-02
pjp
2282
2019-11-04
pjp
while (window && setsockopt(so, SOL_SOCKET, SO_RCVBUF, &window, sizeof(window)) != -1)
2283
2019-11-02
pjp
window <<= 1;
2284
2019-11-02
pjp
#endif
2285
2019-11-02
pjp
2286
2019-11-02
pjp
if (rzone->storage.ss_family == AF_INET6) {
2287
2019-11-02
pjp
memset(&sin6, 0, sizeof(sin6));
2288
2019-11-02
pjp
sin6.sin6_family = AF_INET6;
2289
2019-11-02
pjp
sin6.sin6_port = htons(rzone->masterport);
2290
2019-11-02
pjp
memcpy(&sin6.sin6_addr, (void *)&((struct sockaddr_in6 *)(&rzone->storage))->sin6_addr, sizeof(struct in6_addr));
2291
2019-11-19
pjp
#ifndef __linux__
2292
2019-11-02
pjp
sin6.sin6_len = sizeof(struct sockaddr_in6);
2293
2019-11-19
pjp
#endif
2294
2019-11-02
pjp
sa = (struct sockaddr *)&sin6;
2295
2019-11-02
pjp
slen = sizeof(struct sockaddr_in6);
2296
2019-11-02
pjp
} else {
2297
2019-11-02
pjp
memset(&sin, 0, sizeof(sin));
2298
2019-11-02
pjp
sin.sin_family = AF_INET;
2299
2019-11-02
pjp
sin.sin_port = htons(rzone->masterport);
2300
2019-11-02
pjp
sin.sin_addr.s_addr = ((struct sockaddr_in *)(&rzone->storage))->sin_addr.s_addr;
2301
2019-11-02
pjp
sa = (struct sockaddr *)&sin;
2302
2019-11-02
pjp
}
2303
2019-11-02
pjp
2304
2019-11-02
pjp
if (connect(so, sa, slen) < 0) {
2305
2019-11-02
pjp
dolog(LOG_INFO, "connect to master %s port %u: %s\n", rzone->master, rzone->masterport, strerror(errno));
2306
2019-11-02
pjp
close(so);
2307
2019-11-02
pjp
return -1;
2308
2019-11-02
pjp
}
2309
2019-11-02
pjp
2310
2020-03-10
pjp
if (rzone->tsigkey != NULL && strcmp(rzone->tsigkey, "NOKEY") != 0) {
2311
2019-11-03
pjp
keyname = dns_label(rzone->tsigkey, &keynamelen);
2312
2019-11-03
pjp
if (keyname == NULL) {
2313
2019-11-03
pjp
dolog(LOG_ERR, "dns_label failed\n");
2314
2019-11-03
pjp
close(so);
2315
2019-11-03
pjp
return -1;
2316
2019-11-03
pjp
}
2317
2019-11-03
pjp
2318
2019-11-03
pjp
if ((tsigpasslen = find_tsig_key(keyname, keynamelen, (char *)&tsigpass, sizeof(tsigpass))) < 0) {
2319
2019-11-03
pjp
dolog(LOG_ERR, "do not have a record of TSIG key %s\n", rzone->tsigkey);
2320
2019-11-03
pjp
close(so);
2321
2019-11-03
pjp
return -1;
2322
2019-11-03
pjp
}
2323
2019-11-03
pjp
2324
2019-11-03
pjp
free(keyname);
2325
2019-11-03
pjp
2326
2019-11-03
pjp
if ((len = mybase64_encode(tsigpass, tsigpasslen, humanpass, sizeof(humanpass))) < 0) {
2327
2019-11-03
pjp
dolog(LOG_ERR, "base64_encode() failed\n");
2328
2019-11-03
pjp
close(so);
2329
2019-11-03
pjp
return -1;
2330
2019-11-03
pjp
}
2331
2019-11-03
pjp
2332
2019-11-03
pjp
humanpass[len] = '\0';
2333
2019-11-03
pjp
} else {
2334
2019-11-03
pjp
dotsig = 0;
2335
2019-11-03
pjp
}
2336
2019-11-03
pjp
2337
2019-11-04
pjp
segment = 0;
2338
2019-11-05
pjp
answers = 0;
2339
2019-11-05
pjp
additionalcount = 0;
2340
2019-11-03
pjp
2341
2020-07-26
pjp
if ((format & ZONE_FORMAT) && f != NULL)
2342
2020-07-26
pjp
fprintf(f, "zone \"%s\" {\n", rzone->zonename);
2343
2020-07-26
pjp
2344
2020-07-27
pjp
if (lookup_axfr(f, so, rzone->zonename, &mysoa, format, ((dotsig == 0) ? NULL : rzone->tsigkey), humanpass, &segment, &answers, &additionalcount, &rzone->constraints) < 0) {
2345
2020-07-26
pjp
/* close the zone */
2346
2020-07-26
pjp
if ((format & ZONE_FORMAT) && f != NULL)
2347
2020-07-26
pjp
fprintf(f, "}\n");
2348
2020-07-26
pjp
2349
2019-11-03
pjp
dolog(LOG_ERR, "lookup_axfr() failed\n");
2350
2019-11-02
pjp
close(so);
2351
2019-11-02
pjp
return -1;
2352
2019-11-02
pjp
}
2353
2020-07-26
pjp
2354
2020-07-26
pjp
if ((format & ZONE_FORMAT) && f != NULL)
2355
2020-07-26
pjp
fprintf(f, "}\n");
2356
2019-11-03
pjp
2357
2019-11-03
pjp
close(so);
2358
2019-11-03
pjp
return (0);
2359
2019-11-03
pjp
}
2360
2019-11-03
pjp
2361
2019-11-03
pjp
2362
2019-11-03
pjp
int
2363
2019-11-19
pjp
pull_rzone(struct rzone *rzone, time_t now)
2364
2019-11-03
pjp
{
2365
2020-07-28
pjp
int fd;
2366
2019-11-03
pjp
char *p, *q;
2367
2020-07-28
pjp
char save;
2368
2019-11-03
pjp
FILE *f;
2369
2019-11-03
pjp
char buf[PATH_MAX];
2370
2019-11-03
pjp
2371
2019-11-04
pjp
p = strrchr(rzone->filename, '/');
2372
2019-11-03
pjp
if (p == NULL) {
2373
2019-11-04
pjp
dolog(LOG_INFO, "can't determine temporary filename from %s\n", rzone->filename);
2374
2019-11-02
pjp
return -1;
2375
2019-11-02
pjp
}
2376
2019-11-02
pjp
2377
2019-11-03
pjp
p++;
2378
2019-11-03
pjp
q = p;
2379
2019-11-03
pjp
if (*p == '\0') {
2380
2019-11-04
pjp
dolog(LOG_INFO, "can't determine temporary filename from %s (2)\n", rzone->filename);
2381
2019-11-03
pjp
return -1;
2382
2019-11-03
pjp
}
2383
2019-11-02
pjp
2384
2020-07-28
pjp
save = *p;
2385
2020-07-28
pjp
*p = '\0';
2386
2020-07-28
pjp
2387
2020-07-28
pjp
if (access(".", W_OK | R_OK) == -1) {
2388
2020-07-28
pjp
dolog(LOG_INFO, "%s: %s (must be writable and readable by %s)\n", rzone->filename, strerror(errno), DEFAULT_PRIVILEGE);
2389
2020-07-28
pjp
*p = save;
2390
2020-07-28
pjp
return -1;
2391
2020-07-28
pjp
}
2392
2020-07-28
pjp
2393
2020-07-28
pjp
*p = save;
2394
2019-11-03
pjp
snprintf(buf, sizeof(buf), "%s.XXXXXXXXXXXXXX", p);
2395
2020-07-28
pjp
if ((fd = mkstemp(buf)) == -1) {
2396
2020-07-28
pjp
dolog(LOG_INFO, "mkstemp: %s\n", rzone->filename, strerror(errno));
2397
2019-11-03
pjp
return -1;
2398
2019-11-03
pjp
}
2399
2019-11-02
pjp
2400
2019-11-19
pjp
p = &buf[0];
2401
2019-11-03
pjp
umask(022);
2402
2019-11-03
pjp
2403
2020-07-28
pjp
f = fdopen(fd, "w");
2404
2019-11-03
pjp
if (f == NULL) {
2405
2020-07-28
pjp
dolog(LOG_INFO, "fdopen %s: %s\n", rzone->zonename, strerror(errno));
2406
2019-11-02
pjp
return -1;
2407
2019-11-02
pjp
}
2408
2019-11-03
pjp
2409
2019-12-07
pjp
#if __linux__
2410
2019-12-07
pjp
fprintf(f, "; REPLICANT file for zone %s gotten on %ld\n\n", rzone->zonename, now);
2411
2019-12-07
pjp
#else
2412
2019-11-04
pjp
fprintf(f, "; REPLICANT file for zone %s gotten on %lld\n\n", rzone->zonename, now);
2413
2019-12-07
pjp
#endif
2414
2019-11-03
pjp
2415
2019-11-04
pjp
if (do_raxfr(f, rzone) < 0) {
2416
2019-11-03
pjp
dolog(LOG_INFO, "do_raxfr failed\n");
2417
2019-11-03
pjp
return -1;
2418
2019-11-03
pjp
}
2419
2019-11-03
pjp
2420
2019-11-03
pjp
fclose(f);
2421
2019-11-03
pjp
2422
2019-11-03
pjp
unlink(q);
2423
2019-11-03
pjp
if (link(p, q) < 0) {
2424
2019-11-03
pjp
dolog(LOG_ERR, "can't link %s to %s\n", p, q);
2425
2019-11-03
pjp
return -1;
2426
2019-11-03
pjp
}
2427
2019-11-03
pjp
2428
2019-11-03
pjp
unlink(p);
2429
2019-11-03
pjp
2430
2019-11-03
pjp
return 0;
2431
2019-11-06
pjp
}
2432
2019-11-06
pjp
2433
2019-11-06
pjp
/*
2434
2019-11-06
pjp
* restarttime is 80 seconds plus a random interval between 0 and 39
2435
2019-11-06
pjp
*/
2436
2019-11-06
pjp
2437
2019-11-06
pjp
static int
2438
2019-11-06
pjp
rand_restarttime(void)
2439
2019-11-06
pjp
{
2440
2019-11-06
pjp
return (80 + (arc4random() % 40));
2441
2019-02-07
pjp
}
repomaster@centroid.eu