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