Blame
Date:
Sat Aug 1 09:01:52 2020 UTC
Message:
move extended RCODE's out of the RCODE section those are only 0x00 through 0x0F make a section that shows extended RCODE's that are added to a EDNS0 tag.
0001
2015-09-13
pjp
/*
0002
2018-10-19
pjp
* Copyright (c) 2015-2018 Peter J. Philipp
0003
2015-09-13
pjp
* All rights reserved.
0004
2015-09-13
pjp
*
0005
2015-09-13
pjp
* Redistribution and use in source and binary forms, with or without
0006
2015-09-13
pjp
* modification, are permitted provided that the following conditions
0007
2015-09-13
pjp
* are met:
0008
2015-09-13
pjp
* 1. Redistributions of source code must retain the above copyright
0009
2015-09-13
pjp
* notice, this list of conditions and the following disclaimer.
0010
2015-09-13
pjp
* 2. Redistributions in binary form must reproduce the above copyright
0011
2015-09-13
pjp
* notice, this list of conditions and the following disclaimer in the
0012
2015-09-13
pjp
* documentation and/or other materials provided with the distribution.
0013
2015-09-13
pjp
* 3. The name of the author may not be used to endorse or promote products
0014
2015-09-13
pjp
* derived from this software without specific prior written permission
0015
2015-09-13
pjp
*
0016
2015-09-13
pjp
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
0017
2015-09-13
pjp
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
0018
2015-09-13
pjp
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
0019
2015-09-13
pjp
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
0020
2015-09-13
pjp
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
0021
2015-09-13
pjp
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
0022
2015-09-13
pjp
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
0023
2015-09-13
pjp
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0024
2015-09-13
pjp
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
0025
2015-09-13
pjp
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0026
2015-09-13
pjp
*
0027
2015-09-13
pjp
*/
0028
2017-10-26
pjp
0029
2017-10-26
pjp
/*
0030
2020-07-19
pjp
* $Id: dnssec.c,v 1.31 2020/07/19 07:09:02 pjp Exp $
0031
2017-10-26
pjp
*/
0032
2017-10-26
pjp
0033
2019-06-06
pjp
#include <sys/types.h>
0034
2019-06-06
pjp
#include <sys/socket.h>
0035
2019-06-06
pjp
#include <sys/select.h>
0036
2019-06-06
pjp
#include <sys/wait.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-06-06
pjp
#include <string.h>
0045
2019-06-06
pjp
#include <unistd.h>
0046
2019-06-06
pjp
#include <syslog.h>
0047
2019-06-06
pjp
#include <errno.h>
0048
2019-06-06
pjp
#include <signal.h>
0049
2019-06-06
pjp
#include <ctype.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-06-06
pjp
#else /* not linux */
0062
2019-06-06
pjp
#include <sys/queue.h>
0063
2019-06-06
pjp
#include <sys/tree.h>
0064
2019-06-06
pjp
#ifdef __FreeBSD__
0065
2019-06-06
pjp
#include "imsg.h"
0066
2019-06-06
pjp
#else
0067
2019-06-06
pjp
#include <imsg.h>
0068
2019-06-06
pjp
#endif /* __FreeBSD__ */
0069
2019-06-06
pjp
#endif /* __linux__ */
0070
2019-06-06
pjp
0071
2016-07-06
pjp
#include "ddd-dns.h"
0072
2016-07-06
pjp
#include "ddd-db.h"
0073
2016-07-06
pjp
0074
2015-09-13
pjp
#include <openssl/sha.h>
0075
2015-09-13
pjp
0076
2015-09-13
pjp
/* prototypes */
0077
2015-09-13
pjp
0078
2015-09-13
pjp
void init_dnssec(void);
0079
2015-09-13
pjp
int insert_apex(char *zonename, char *zone, int zonelen);
0080
2015-09-13
pjp
int insert_nsec3(char *zonename, char *domainname, char *dname, int dnamelen);
0081
2015-09-14
pjp
char * find_next_closer_nsec3(char *zonename, int zonelen, char *hashname);
0082
2015-09-14
pjp
char * find_match_nsec3(char *zonename, int zonelen, char *hashname);
0083
2017-01-11
pjp
char * find_match_nsec3_ent(char *zonename, int zonelen, char *hashname);
0084
2019-02-15
pjp
struct rbtree * find_nsec(char *name, int namelen, struct rbtree *rbt, ddDB *db);
0085
2019-02-15
pjp
struct rbtree * find_nsec3_match_qname(char *name, int namelen, struct rbtree *, ddDB *db);
0086
2019-02-15
pjp
struct rbtree * find_nsec3_match_closest(char *name, int namelen, struct rbtree *, ddDB *db);
0087
2019-02-15
pjp
struct rbtree * find_nsec3_wildcard_closest(char *name, int namelen, struct rbtree *, ddDB *db);
0088
2015-09-13
pjp
char * convert_name(char *name, int namelen);
0089
2015-09-13
pjp
int nsec_comp(const void *a, const void *b);
0090
2015-09-13
pjp
int nsec3_comp(const void *a, const void *b);
0091
2015-09-13
pjp
int count_dots(char *name);
0092
2019-02-15
pjp
struct rbtree * find_closest_encloser(ddDB *db, char *name, int namelen);
0093
2016-01-22
pjp
char * find_next_closer_name(char *, int, char *, int, int *);
0094
2015-09-13
pjp
char * hash_name(char *name, int len, struct nsec3param *n3p);
0095
2015-09-13
pjp
char * base32hex_encode(u_char *input, int len);
0096
2015-11-17
pjp
int base32hex_decode(u_char *, u_char *);
0097
2015-11-17
pjp
void mysetbit(u_char *, int);
0098
2015-09-13
pjp
0099
2017-06-26
pjp
extern int get_record_size(ddDB *, char *, int);
0100
2015-09-13
pjp
extern char * dns_label(char *, int *);
0101
2015-09-13
pjp
extern void dolog(int, char *, ...);
0102
2019-02-15
pjp
extern int checklabel(ddDB *, struct rbtree *, struct rbtree *, struct question *);
0103
2015-09-13
pjp
extern int free_question(struct question *);
0104
2017-01-11
pjp
extern int check_ent(char *, int);
0105
2017-01-11
pjp
extern int memcasecmp(u_char *, u_char *, int);
0106
2015-09-13
pjp
0107
2019-02-15
pjp
extern struct rbtree * find_rrset(ddDB *db, char *name, int len);
0108
2019-02-15
pjp
extern struct rrset * find_rr(struct rbtree *rbt, u_int16_t rrtype);
0109
2019-02-15
pjp
extern int add_rr(struct rbtree *rbt, char *name, int len, u_int16_t rrtype, void *rdata);
0110
2019-02-15
pjp
0111
2015-09-13
pjp
SLIST_HEAD(listhead, dnssecentry) dnssechead;
0112
2015-09-13
pjp
0113
2015-09-14
pjp
static struct nsec3entry {
0114
2015-09-14
pjp
char domainname[DNS_MAXNAME + 1];
0115
2015-09-14
pjp
char dname[DNS_MAXNAME];
0116
2015-09-14
pjp
int dnamelen;
0117
2015-09-14
pjp
TAILQ_ENTRY(nsec3entry) nsec3_entries;
0118
2015-09-14
pjp
} *n3, *ns3p;
0119
2015-09-14
pjp
0120
2015-09-13
pjp
static struct dnssecentry {
0121
2015-09-13
pjp
char zonename[DNS_MAXNAME + 1];
0122
2015-09-13
pjp
char zone[DNS_MAXNAME];
0123
2015-09-13
pjp
int zonelen;
0124
2015-09-13
pjp
SLIST_ENTRY(dnssecentry) dnssec_entry;
0125
2019-02-15
pjp
TAILQ_HEAD(aa, nsec3entry) nsec3head;
0126
2015-09-13
pjp
} *dn, *dnp;
0127
2015-09-13
pjp
0128
2015-09-13
pjp
0129
2015-09-13
pjp
void
0130
2015-09-13
pjp
init_dnssec(void)
0131
2015-09-13
pjp
{
0132
2015-09-13
pjp
SLIST_INIT(&dnssechead);
0133
2015-09-13
pjp
return;
0134
2015-09-13
pjp
}
0135
2015-09-13
pjp
0136
2015-09-13
pjp
int
0137
2015-09-13
pjp
insert_apex(char *zonename, char *zone, int zonelen)
0138
2015-09-13
pjp
{
0139
2015-09-13
pjp
dn = calloc(1, sizeof(struct dnssecentry));
0140
2015-09-13
pjp
if (dn == NULL) {
0141
2015-09-13
pjp
return -1;
0142
2015-09-13
pjp
}
0143
2015-09-13
pjp
0144
2015-09-13
pjp
strlcpy(dn->zonename, zonename, DNS_MAXNAME + 1);
0145
2015-09-13
pjp
0146
2015-09-13
pjp
if (zonelen > DNS_MAXNAME) {
0147
2015-09-13
pjp
free (dn);
0148
2015-09-13
pjp
return -1;
0149
2015-09-13
pjp
}
0150
2015-09-13
pjp
0151
2015-09-13
pjp
memcpy(dn->zone, zone, zonelen);
0152
2015-09-13
pjp
dn->zonelen = zonelen;
0153
2015-09-13
pjp
0154
2015-09-14
pjp
TAILQ_INIT(&dn->nsec3head);
0155
2015-09-13
pjp
0156
2015-09-13
pjp
SLIST_INSERT_HEAD(&dnssechead, dn, dnssec_entry);
0157
2015-09-13
pjp
0158
2015-09-13
pjp
return (0);
0159
2015-09-13
pjp
}
0160
2015-09-13
pjp
0161
2015-09-13
pjp
int
0162
2015-09-13
pjp
insert_nsec3(char *zonename, char *domainname, char *dname, int dnamelen)
0163
2015-09-13
pjp
{
0164
2015-09-13
pjp
0165
2015-09-13
pjp
SLIST_FOREACH(dnp, &dnssechead, dnssec_entry) {
0166
2015-09-13
pjp
if (strcasecmp(dnp->zonename, zonename) == 0)
0167
2015-09-13
pjp
break;
0168
2015-09-13
pjp
}
0169
2015-09-13
pjp
0170
2015-09-13
pjp
if (dnp == NULL)
0171
2015-09-13
pjp
return -1;
0172
2015-09-13
pjp
0173
2015-09-14
pjp
n3 = calloc(1, sizeof(struct nsec3entry));
0174
2015-09-13
pjp
if (n3 == NULL)
0175
2015-09-13
pjp
return -1;
0176
2015-09-13
pjp
0177
2015-09-13
pjp
strlcpy(n3->domainname, domainname, DNS_MAXNAME + 1);
0178
2015-09-13
pjp
0179
2015-09-13
pjp
if (dnamelen > DNS_MAXNAME) {
0180
2015-09-13
pjp
free (n3);
0181
2015-09-13
pjp
return -1;
0182
2015-09-13
pjp
}
0183
2015-09-13
pjp
0184
2015-09-13
pjp
memcpy(n3->dname, dname, dnamelen);
0185
2015-09-13
pjp
n3->dnamelen = dnamelen;
0186
2015-09-13
pjp
0187
2015-09-14
pjp
0188
2015-11-07
pjp
/*
0189
2015-11-07
pjp
* sort the tailq here
0190
2015-11-07
pjp
*/
0191
2015-11-07
pjp
0192
2015-11-07
pjp
if (TAILQ_EMPTY(&dn->nsec3head)) {
0193
2015-11-07
pjp
TAILQ_INSERT_TAIL(&dn->nsec3head, n3, nsec3_entries);
0194
2015-11-07
pjp
} else {
0195
2015-11-07
pjp
ns3p = TAILQ_FIRST(&dn->nsec3head);
0196
2015-11-07
pjp
if (strcmp(n3->domainname, ns3p->domainname) < 0) {
0197
2015-11-07
pjp
TAILQ_INSERT_BEFORE(ns3p, n3, nsec3_entries);
0198
2015-11-07
pjp
} else {
0199
2015-11-07
pjp
while ((ns3p = TAILQ_NEXT(ns3p, nsec3_entries)) != NULL) {
0200
2015-11-07
pjp
if (strcmp(n3->domainname, ns3p->domainname) < 0) {
0201
2015-11-07
pjp
TAILQ_INSERT_BEFORE(ns3p, n3, nsec3_entries);
0202
2015-11-07
pjp
break;
0203
2015-11-07
pjp
}
0204
2015-11-07
pjp
}
0205
2015-11-07
pjp
}
0206
2015-11-07
pjp
if (ns3p == NULL) {
0207
2015-11-07
pjp
TAILQ_INSERT_TAIL(&dn->nsec3head, n3, nsec3_entries);
0208
2015-11-07
pjp
}
0209
2015-11-07
pjp
}
0210
2015-11-07
pjp
0211
2015-11-07
pjp
0212
2015-09-14
pjp
return (0);
0213
2015-09-14
pjp
}
0214
2015-09-14
pjp
0215
2015-09-14
pjp
char *
0216
2015-09-14
pjp
find_next_closer_nsec3(char *zonename, int zonelen, char *hashname)
0217
2015-09-14
pjp
{
0218
2015-09-14
pjp
int hashlen;
0219
2015-09-14
pjp
0220
2015-09-14
pjp
hashlen = strlen(hashname);
0221
2015-09-14
pjp
0222
2015-09-14
pjp
SLIST_FOREACH(dnp, &dnssechead, dnssec_entry) {
0223
2015-09-14
pjp
if (zonelen == dnp->zonelen &&
0224
2015-09-14
pjp
(memcmp(dnp->zone, zonename, zonelen) == 0))
0225
2015-09-13
pjp
break;
0226
2015-09-14
pjp
}
0227
2015-09-14
pjp
0228
2015-09-14
pjp
if (dnp == NULL)
0229
2015-09-14
pjp
return NULL;
0230
2015-09-14
pjp
0231
2015-09-14
pjp
/* we have found the zone, now find the next closer hash for nsec3 */
0232
2015-09-14
pjp
0233
2015-09-14
pjp
TAILQ_FOREACH(n3, &dnp->nsec3head, nsec3_entries) {
0234
2015-09-14
pjp
if (strncasecmp(hashname, n3->domainname, hashlen) <= 0) {
0235
2015-09-14
pjp
break;
0236
2015-09-14
pjp
}
0237
2015-09-14
pjp
}
0238
2015-09-13
pjp
0239
2015-09-14
pjp
if (n3 == NULL) {
0240
2017-09-06
pjp
/* returning NULL is not recommended here */
0241
2019-02-15
pjp
ns3p = TAILQ_LAST(&dnp->nsec3head, aa);
0242
2017-09-06
pjp
return (ns3p->domainname);
0243
2015-09-14
pjp
}
0244
2015-09-13
pjp
0245
2016-01-22
pjp
#if DEBUG
0246
2015-09-14
pjp
dolog(LOG_INFO, "resolved at %s\n", n3->domainname);
0247
2015-09-14
pjp
#endif
0248
2015-09-14
pjp
0249
2019-02-15
pjp
if ((ns3p = TAILQ_PREV(n3, aa, nsec3_entries)) != NULL) {
0250
2015-09-14
pjp
return (ns3p->domainname);
0251
2015-09-14
pjp
} else {
0252
2019-02-15
pjp
ns3p = TAILQ_LAST(&dnp->nsec3head, aa);
0253
2015-09-14
pjp
return (ns3p->domainname);
0254
2015-09-14
pjp
}
0255
2015-09-14
pjp
0256
2015-09-14
pjp
/* NOTREACHED */
0257
2015-09-14
pjp
return (NULL);
0258
2015-09-13
pjp
}
0259
2015-09-13
pjp
0260
2019-02-18
pjp
#if 0
0261
2015-09-14
pjp
char *
0262
2017-01-11
pjp
find_match_nsec3_ent(char *zonename, int zonelen, char *hashname)
0263
2017-01-11
pjp
{
0264
2017-01-11
pjp
int hashlen;
0265
2017-01-11
pjp
int count;
0266
2017-01-11
pjp
0267
2017-01-11
pjp
hashlen = strlen(hashname);
0268
2017-01-11
pjp
0269
2017-01-11
pjp
SLIST_FOREACH(dnp, &dnssechead, dnssec_entry) {
0270
2017-01-11
pjp
if (zonelen == dnp->zonelen &&
0271
2017-01-11
pjp
(memcasecmp(dnp->zone, zonename, zonelen) == 0))
0272
2017-01-11
pjp
break;
0273
2017-01-11
pjp
}
0274
2017-01-11
pjp
0275
2017-01-11
pjp
if (dnp == NULL)
0276
2017-01-11
pjp
return NULL;
0277
2017-01-11
pjp
0278
2017-01-11
pjp
/* we have found the zone, now find the next closer hash for nsec3 */
0279
2017-01-11
pjp
0280
2017-01-11
pjp
count = 0;
0281
2017-01-11
pjp
TAILQ_FOREACH(n3, &dnp->nsec3head, nsec3_entries) {
0282
2017-01-11
pjp
if (strncasecmp(hashname, n3->domainname, hashlen) < 0) {
0283
2017-01-11
pjp
if (count == 0)
0284
2019-02-15
pjp
n3 = TAILQ_LAST(&dnp->nsec3head, aa);
0285
2017-01-11
pjp
else
0286
2019-02-15
pjp
n3 = TAILQ_PREV(n3, aa, nsec3_entries);
0287
2017-01-11
pjp
break;
0288
2017-01-11
pjp
}
0289
2017-01-11
pjp
count++;
0290
2017-01-11
pjp
}
0291
2017-01-11
pjp
0292
2017-01-11
pjp
if (n3 == NULL) {
0293
2017-01-11
pjp
return NULL;
0294
2017-01-11
pjp
}
0295
2017-01-11
pjp
0296
2017-01-11
pjp
#ifdef DEBUG
0297
2017-01-11
pjp
dolog(LOG_INFO, "resolved at %s\n", n3->domainname);
0298
2017-01-11
pjp
#endif
0299
2017-01-11
pjp
0300
2017-01-11
pjp
return (n3->domainname);
0301
2017-01-11
pjp
}
0302
2019-02-18
pjp
#endif
0303
2017-01-11
pjp
0304
2017-01-11
pjp
char *
0305
2015-09-14
pjp
find_match_nsec3(char *zonename, int zonelen, char *hashname)
0306
2015-09-14
pjp
{
0307
2015-09-14
pjp
int hashlen;
0308
2015-09-14
pjp
0309
2015-09-14
pjp
hashlen = strlen(hashname);
0310
2015-09-14
pjp
0311
2015-09-14
pjp
SLIST_FOREACH(dnp, &dnssechead, dnssec_entry) {
0312
2015-09-14
pjp
if (zonelen == dnp->zonelen &&
0313
2015-09-14
pjp
(memcmp(dnp->zone, zonename, zonelen) == 0))
0314
2015-09-14
pjp
break;
0315
2015-09-14
pjp
}
0316
2015-09-14
pjp
0317
2015-09-14
pjp
if (dnp == NULL)
0318
2015-09-14
pjp
return NULL;
0319
2015-09-14
pjp
0320
2015-09-14
pjp
/* we have found the zone, now find the next closer hash for nsec3 */
0321
2015-09-14
pjp
0322
2015-09-14
pjp
TAILQ_FOREACH(n3, &dnp->nsec3head, nsec3_entries) {
0323
2015-09-14
pjp
if (strncasecmp(hashname, n3->domainname, hashlen) == 0) {
0324
2015-09-14
pjp
break;
0325
2015-09-14
pjp
}
0326
2015-09-14
pjp
}
0327
2015-09-14
pjp
0328
2015-09-14
pjp
if (n3 == NULL) {
0329
2015-09-14
pjp
return NULL;
0330
2015-09-14
pjp
}
0331
2015-09-14
pjp
0332
2015-09-14
pjp
#ifdef DEBUG
0333
2015-09-14
pjp
dolog(LOG_INFO, "resolved at %s\n", n3->domainname);
0334
2015-09-14
pjp
#endif
0335
2015-09-14
pjp
0336
2015-09-14
pjp
return (n3->domainname);
0337
2015-09-14
pjp
}
0338
2015-09-14
pjp
0339
2015-09-14
pjp
0340
2015-09-13
pjp
/* FIND_NSEC */
0341
2015-09-13
pjp
/* finds the right nsec domainname in a zone */
0342
2019-02-15
pjp
struct rbtree *
0343
2019-02-15
pjp
find_nsec(char *name, int namelen, struct rbtree *rbt, ddDB *db)
0344
2015-09-13
pjp
{
0345
2015-09-13
pjp
char *table, *tmp;
0346
2015-09-13
pjp
char *nsecname;
0347
2015-09-13
pjp
struct domainnames {
0348
2015-09-13
pjp
char name[DNS_MAXNAME + 1];
0349
2015-09-13
pjp
char next[DNS_MAXNAME + 1];
0350
2015-09-13
pjp
} *dn;
0351
2015-09-13
pjp
0352
2019-02-15
pjp
struct rbtree *rbt0;
0353
2019-02-15
pjp
struct rrset *rrset = NULL;
0354
2019-02-15
pjp
struct rr *rrp = NULL;
0355
2015-09-13
pjp
char *humanname;
0356
2015-09-13
pjp
char tmpname[DNS_MAXNAME];
0357
2015-09-13
pjp
int tmplen;
0358
2019-02-15
pjp
char *backname;
0359
2015-09-13
pjp
int backnamelen;
0360
2015-09-13
pjp
int i, names = 100;
0361
2015-09-13
pjp
int j;
0362
2015-09-13
pjp
0363
2015-09-13
pjp
humanname = convert_name(name, namelen);
0364
2015-09-13
pjp
0365
2019-02-15
pjp
if ((rrset = find_rr(rbt, DNS_TYPE_NSEC)) == NULL) {
0366
2015-09-13
pjp
free (humanname);
0367
2015-09-13
pjp
return (NULL);
0368
2015-09-13
pjp
}
0369
2015-09-13
pjp
0370
2019-02-15
pjp
rrp = TAILQ_FIRST(&rrset->rr_head);
0371
2019-02-15
pjp
if (rrp == NULL) {
0372
2019-02-15
pjp
free(humanname);
0373
2019-02-15
pjp
return (NULL);
0374
2019-02-15
pjp
}
0375
2019-02-15
pjp
0376
2015-09-13
pjp
table = calloc(names, sizeof(struct domainnames));
0377
2015-09-13
pjp
if (table == NULL) {
0378
2015-09-13
pjp
free (humanname);
0379
2015-09-13
pjp
return (NULL);
0380
2015-09-13
pjp
}
0381
2015-09-13
pjp
0382
2015-09-13
pjp
dn = (struct domainnames *)table;
0383
2019-02-15
pjp
strlcpy(dn->name, rbt->humanname, DNS_MAXNAME + 1);
0384
2019-02-15
pjp
nsecname = convert_name(((struct nsec *)rrp->rdata)->next_domain_name, ((struct nsec *)rrp->rdata)->ndn_len);
0385
2015-09-13
pjp
strlcpy(dn->next, nsecname, DNS_MAXNAME + 1);
0386
2015-09-13
pjp
0387
2019-02-15
pjp
rbt0 = find_rrset(db, ((struct nsec *)rrp->rdata)->next_domain_name, ((struct nsec *)rrp->rdata)->ndn_len);
0388
2019-02-15
pjp
if (rbt0 == NULL) {
0389
2015-09-13
pjp
free (nsecname);
0390
2015-09-13
pjp
free (humanname);
0391
2015-09-13
pjp
free (table);
0392
2015-09-13
pjp
return (NULL);
0393
2015-09-13
pjp
}
0394
2015-09-13
pjp
0395
2019-02-15
pjp
if ((rrset = find_rr(rbt0, DNS_TYPE_NSEC)) == NULL) {
0396
2015-09-13
pjp
free (nsecname);
0397
2015-09-13
pjp
free (humanname);
0398
2015-09-13
pjp
free (table);
0399
2015-09-13
pjp
return (NULL);
0400
2015-09-13
pjp
}
0401
2015-09-13
pjp
0402
2019-02-15
pjp
rrp = TAILQ_FIRST(&rrset->rr_head);
0403
2019-02-15
pjp
if (rrp == NULL) {
0404
2020-07-18
pjp
free(nsecname);
0405
2019-02-15
pjp
free(humanname);
0406
2015-09-13
pjp
return (NULL);
0407
2015-09-13
pjp
}
0408
2015-09-13
pjp
0409
2015-09-13
pjp
i = 1;
0410
2019-02-15
pjp
while (strcasecmp(nsecname, rbt->humanname) != 0) {
0411
2015-09-13
pjp
/* grow our table */
0412
2015-09-13
pjp
if (i == names - 1) {
0413
2015-09-13
pjp
names += 100;
0414
2015-09-13
pjp
0415
2015-09-13
pjp
tmp = realloc(table, names * sizeof(struct domainnames));
0416
2015-09-13
pjp
if (tmp == NULL) {
0417
2015-09-13
pjp
free (nsecname);
0418
2015-09-13
pjp
free (humanname);
0419
2015-09-13
pjp
free (table);
0420
2015-09-13
pjp
return (NULL);
0421
2015-09-13
pjp
}
0422
2015-09-13
pjp
table = tmp;
0423
2015-09-13
pjp
}
0424
2015-09-13
pjp
0425
2015-09-13
pjp
dn = ((struct domainnames *)table) + i;
0426
2015-09-13
pjp
0427
2015-09-13
pjp
free (nsecname);
0428
2019-02-15
pjp
strlcpy(dn->name, rbt0->humanname, DNS_MAXNAME + 1);
0429
2019-02-15
pjp
nsecname = convert_name(((struct nsec *)rrp->rdata)->next_domain_name, ((struct nsec *)rrp->rdata)->ndn_len);
0430
2015-09-13
pjp
strlcpy(dn->next, nsecname, DNS_MAXNAME + 1);
0431
2015-09-13
pjp
0432
2019-02-15
pjp
memcpy(tmpname, ((struct nsec *)rrp->rdata)->next_domain_name, ((struct nsec *)rrp->rdata)->ndn_len);
0433
2019-02-15
pjp
tmplen = ((struct nsec *)rrp->rdata)->ndn_len;
0434
2015-09-13
pjp
0435
2015-09-13
pjp
0436
2019-02-15
pjp
rbt0 = find_rrset(db, tmpname, tmplen);
0437
2019-02-15
pjp
if (rbt0 == NULL) {
0438
2020-07-18
pjp
free (nsecname);
0439
2015-09-13
pjp
free (humanname);
0440
2015-09-13
pjp
free (table);
0441
2015-09-13
pjp
return (NULL);
0442
2015-09-13
pjp
}
0443
2015-09-13
pjp
0444
2019-02-15
pjp
if ((rrset = find_rr(rbt0, DNS_TYPE_NSEC)) == NULL) {
0445
2020-07-18
pjp
free (nsecname);
0446
2015-09-13
pjp
free (humanname);
0447
2015-09-13
pjp
free (table);
0448
2015-09-13
pjp
return (NULL);
0449
2015-09-13
pjp
}
0450
2015-09-13
pjp
0451
2015-09-13
pjp
i++;
0452
2015-09-13
pjp
}
0453
2015-09-13
pjp
0454
2015-09-13
pjp
free (nsecname);
0455
2015-09-13
pjp
dn = ((struct domainnames *)table) + i;
0456
2015-09-13
pjp
strlcpy(dn->next, ".", DNS_MAXNAME + 1);
0457
2015-09-13
pjp
strlcpy(dn->name, humanname, DNS_MAXNAME + 1);
0458
2015-09-13
pjp
0459
2015-09-13
pjp
i++;
0460
2015-09-13
pjp
0461
2015-09-13
pjp
/* now we sort the shebang */
0462
2015-09-13
pjp
0463
2015-09-13
pjp
qsort(table, i, sizeof(struct domainnames), nsec_comp);
0464
2015-09-13
pjp
0465
2015-09-13
pjp
for (j = 0; j < i; j++) {
0466
2015-09-13
pjp
dn = ((struct domainnames *)table) + j;
0467
2015-09-13
pjp
0468
2015-09-13
pjp
#if DEBUG
0469
2019-02-18
pjp
printf("%s\n", dn->name);
0470
2015-09-13
pjp
#endif
0471
2015-09-13
pjp
0472
2015-09-13
pjp
if (strcmp(dn->next, ".") == 0)
0473
2015-09-13
pjp
break;
0474
2015-09-13
pjp
}
0475
2015-09-13
pjp
0476
2015-09-13
pjp
dn = ((struct domainnames *)table) + (j - 1);
0477
2015-09-13
pjp
0478
2015-09-13
pjp
/* found it, get it via db after converting it */
0479
2015-09-13
pjp
0480
2015-09-13
pjp
/* free what we don't need */
0481
2015-09-13
pjp
free (humanname);
0482
2015-09-13
pjp
0483
2015-09-13
pjp
backname = dns_label(dn->name, &backnamelen);
0484
2015-09-13
pjp
free (table);
0485
2015-09-13
pjp
0486
2015-09-13
pjp
0487
2019-02-15
pjp
rbt0 = find_rrset(db, backname, backnamelen);
0488
2019-02-15
pjp
if (rbt0 == NULL) {
0489
2015-09-13
pjp
free (backname);
0490
2015-09-13
pjp
return (NULL);
0491
2015-09-13
pjp
}
0492
2015-09-13
pjp
0493
2015-09-13
pjp
free (backname);
0494
2019-02-15
pjp
return (rbt0);
0495
2015-09-13
pjp
}
0496
2015-09-13
pjp
0497
2015-09-13
pjp
char *
0498
2015-09-13
pjp
convert_name(char *name, int namelen)
0499
2015-09-13
pjp
{
0500
2015-09-13
pjp
char *ret;
0501
2015-09-13
pjp
char *p, *p0;
0502
2015-09-13
pjp
int plen;
0503
2015-09-13
pjp
int i;
0504
2015-09-13
pjp
0505
2020-07-16
pjp
if (namelen <= 0)
0506
2019-02-05
pjp
return NULL;
0507
2019-02-05
pjp
0508
2015-09-13
pjp
ret = calloc(namelen + 1, 1);
0509
2015-09-13
pjp
if (ret == NULL) {
0510
2015-09-13
pjp
return NULL;
0511
2020-07-19
pjp
}
0512
2020-07-19
pjp
0513
2020-07-19
pjp
/* short circuit root */
0514
2020-07-19
pjp
if (namelen == 1 && name[1] == '\0') {
0515
2020-07-19
pjp
ret[0] = '.';
0516
2020-07-19
pjp
return (ret);
0517
2020-07-16
pjp
}
0518
2020-07-16
pjp
0519
2015-09-13
pjp
memcpy(ret, name + 1, namelen - 1);
0520
2015-09-13
pjp
0521
2015-09-13
pjp
p0 = ret;
0522
2015-09-13
pjp
p = name;
0523
2015-09-13
pjp
plen = namelen;
0524
2015-09-13
pjp
0525
2020-07-16
pjp
while (plen >= 0 && *p != 0) {
0526
2020-07-16
pjp
if (*p > DNS_MAXLABEL) {
0527
2020-07-16
pjp
dolog(LOG_INFO, "compression in dns name\n");
0528
2020-07-16
pjp
free (ret);
0529
2020-07-16
pjp
return NULL;
0530
2020-07-16
pjp
}
0531
2015-09-13
pjp
for (i = 0; i < *p; i++) {
0532
2015-09-13
pjp
*p0++ = p[i + 1];
0533
2015-09-13
pjp
}
0534
2015-09-13
pjp
*p0++ = '.';
0535
2015-09-13
pjp
plen -= (*p + 1);
0536
2020-07-16
pjp
p += (*p + 1);
0537
2015-09-13
pjp
}
0538
2015-09-13
pjp
0539
2015-09-13
pjp
return (ret);
0540
2015-09-13
pjp
}
0541
2015-09-13
pjp
0542
2015-09-13
pjp
/* canonical sort compare */
0543
2015-09-13
pjp
0544
2015-09-13
pjp
int
0545
2015-09-13
pjp
nsec_comp(const void *a, const void *b)
0546
2015-09-13
pjp
{
0547
2015-09-13
pjp
struct domainnames {
0548
2015-09-13
pjp
char name[DNS_MAXNAME + 1];
0549
2015-09-13
pjp
char next[DNS_MAXNAME + 1];
0550
2015-09-13
pjp
};
0551
2015-09-13
pjp
struct domainnames *dn0, *dn1;
0552
2015-09-13
pjp
int dots0, dots1;
0553
2015-09-13
pjp
0554
2015-09-13
pjp
dn0 = (struct domainnames *)a;
0555
2015-09-13
pjp
dn1 = (struct domainnames *)b;
0556
2015-09-13
pjp
0557
2015-09-13
pjp
/* count the dots we need this for canonical compare */
0558
2015-09-13
pjp
0559
2015-09-13
pjp
dots0 = count_dots(dn0->name);
0560
2015-09-13
pjp
dots1 = count_dots(dn1->name);
0561
2015-09-13
pjp
0562
2015-09-13
pjp
if (dots0 > dots1)
0563
2015-09-13
pjp
return 1;
0564
2015-09-13
pjp
else if (dots1 > dots0)
0565
2015-09-13
pjp
return -1;
0566
2015-09-13
pjp
0567
2015-09-13
pjp
0568
2015-09-13
pjp
/* we have a tie, strcmp them */
0569
2015-09-13
pjp
0570
2015-09-13
pjp
return (strcmp(dn0->name, dn1->name));
0571
2015-09-13
pjp
}
0572
2015-09-13
pjp
0573
2015-09-13
pjp
/* much like nsec_comp */
0574
2015-09-13
pjp
0575
2015-09-13
pjp
int
0576
2015-09-13
pjp
nsec3_comp(const void *a, const void *b)
0577
2015-09-13
pjp
{
0578
2015-09-13
pjp
struct domainnames {
0579
2015-09-13
pjp
char name[DNS_MAXNAME + 1];
0580
2015-09-13
pjp
char next[DNS_MAXNAME + 1];
0581
2015-09-13
pjp
};
0582
2015-09-13
pjp
struct domainnames *dn0, *dn1;
0583
2015-09-13
pjp
0584
2015-09-13
pjp
dn0 = (struct domainnames *)a;
0585
2015-09-13
pjp
dn1 = (struct domainnames *)b;
0586
2015-09-13
pjp
0587
2015-09-13
pjp
return (strcmp(dn0->name, dn1->name));
0588
2015-09-13
pjp
}
0589
2015-09-13
pjp
0590
2015-09-13
pjp
int
0591
2015-09-13
pjp
count_dots(char *name)
0592
2015-09-13
pjp
{
0593
2015-09-13
pjp
int i;
0594
2015-09-13
pjp
int ret = 0;
0595
2015-09-13
pjp
0596
2015-09-13
pjp
0597
2015-09-13
pjp
for (i = 0; i < strlen(name); i++) {
0598
2015-09-13
pjp
if (name[i] == '.')
0599
2015-09-13
pjp
ret++;
0600
2015-09-13
pjp
}
0601
2015-09-13
pjp
0602
2015-09-13
pjp
return(ret);
0603
2015-09-13
pjp
}
0604
2015-09-13
pjp
0605
2015-09-13
pjp
/*
0606
2016-01-22
pjp
* FIND_NEXT_CLOSER - find the next closer name
0607
2015-09-13
pjp
*/
0608
2015-09-13
pjp
0609
2016-01-22
pjp
char *
0610
2016-01-22
pjp
find_next_closer_name(char *qname, int qlen, char *closestname, int clen, int *rlen)
0611
2015-09-13
pjp
{
0612
2016-01-22
pjp
static char save[DNS_MAXNAME];
0613
2015-09-13
pjp
0614
2015-09-13
pjp
int plen;
0615
2016-01-22
pjp
int qcount = 0;
0616
2016-01-22
pjp
int ccount = 0;
0617
2016-01-22
pjp
int discard;
0618
2015-09-13
pjp
0619
2016-01-22
pjp
char *p;
0620
2015-09-13
pjp
0621
2016-01-22
pjp
p = qname;
0622
2016-01-22
pjp
plen = qlen;
0623
2016-01-22
pjp
0624
2016-01-22
pjp
do {
0625
2016-01-22
pjp
plen -= (*p + 1);
0626
2016-01-22
pjp
p = (p + (*p + 1));
0627
2016-01-22
pjp
qcount++;
0628
2016-01-22
pjp
} while (*p);
0629
2016-01-22
pjp
0630
2016-01-22
pjp
p = closestname;
0631
2016-01-22
pjp
plen = clen;
0632
2016-01-22
pjp
0633
2016-01-22
pjp
do {
0634
2016-01-22
pjp
plen -= (*p + 1);
0635
2016-01-22
pjp
p = (p + (*p + 1));
0636
2016-01-22
pjp
ccount++;
0637
2016-01-22
pjp
} while (*p);
0638
2016-01-22
pjp
0639
2016-01-22
pjp
0640
2016-01-22
pjp
discard = qcount - (ccount + 1);
0641
2016-01-22
pjp
if (discard < 0)
0642
2016-01-22
pjp
return NULL;
0643
2016-01-22
pjp
0644
2016-01-22
pjp
p = qname;
0645
2016-01-22
pjp
plen = qlen;
0646
2016-01-22
pjp
0647
2016-01-22
pjp
while (*p && discard > 0) {
0648
2016-01-22
pjp
plen -= (*p + 1);
0649
2016-01-22
pjp
p = (p + (*p + 1));
0650
2016-01-22
pjp
discard--;
0651
2016-01-22
pjp
}
0652
2016-01-22
pjp
0653
2016-01-22
pjp
*rlen = plen;
0654
2016-01-22
pjp
memcpy(save, p, plen);
0655
2016-01-22
pjp
0656
2016-01-22
pjp
return ((char *)&save);
0657
2016-01-22
pjp
}
0658
2016-01-22
pjp
0659
2016-01-22
pjp
/*
0660
2016-01-22
pjp
* FIND_CLOSEST_ENCLOSER - find the closest encloser record
0661
2016-01-22
pjp
*/
0662
2016-01-22
pjp
0663
2019-02-15
pjp
struct rbtree *
0664
2017-06-26
pjp
find_closest_encloser(ddDB *db, char *name, int namelen)
0665
2016-01-22
pjp
{
0666
2019-02-15
pjp
struct rbtree *rbt = NULL;
0667
2019-02-15
pjp
struct rrset *rrset = NULL;
0668
2016-01-22
pjp
0669
2016-01-22
pjp
int plen;
0670
2016-01-22
pjp
0671
2016-01-22
pjp
char *p;
0672
2016-01-22
pjp
0673
2016-01-22
pjp
p = name;
0674
2016-01-22
pjp
plen = namelen;
0675
2016-01-22
pjp
0676
2016-01-22
pjp
/* advance one label */
0677
2016-01-22
pjp
plen -= (*p + 1);
0678
2016-01-22
pjp
p = (p + (*p + 1));
0679
2016-01-22
pjp
0680
2016-01-22
pjp
0681
2016-01-22
pjp
do {
0682
2019-02-15
pjp
rbt = find_rrset(db, p, plen);
0683
2019-02-15
pjp
if (rbt == NULL) {
0684
2015-09-13
pjp
plen -= (*p + 1);
0685
2015-09-13
pjp
p = (p + (*p + 1));
0686
2015-09-13
pjp
continue;
0687
2015-09-13
pjp
}
0688
2015-09-13
pjp
0689
2019-02-15
pjp
if ((rrset = find_rr(rbt, DNS_TYPE_NSEC3)) != NULL) {
0690
2015-09-13
pjp
plen -= (*p + 1);
0691
2015-09-13
pjp
p = (p + (*p + 1));
0692
2015-09-13
pjp
continue;
0693
2015-09-13
pjp
}
0694
2015-09-13
pjp
0695
2019-02-15
pjp
return (rbt);
0696
2015-09-13
pjp
} while (*p);
0697
2015-09-13
pjp
0698
2015-09-13
pjp
return NULL;
0699
2015-09-13
pjp
}
0700
2015-09-13
pjp
0701
2015-09-13
pjp
char *
0702
2015-09-13
pjp
hash_name(char *name, int len, struct nsec3param *n3p)
0703
2015-09-13
pjp
{
0704
2015-09-13
pjp
SHA_CTX ctx;
0705
2015-09-13
pjp
u_char md[20];
0706
2015-09-13
pjp
int i;
0707
2015-09-13
pjp
0708
2015-09-13
pjp
if (n3p->algorithm != 1) {
0709
2015-09-13
pjp
dolog(LOG_INFO, "wrong algorithm: %d, expected 1\n", n3p->algorithm);
0710
2015-09-13
pjp
return NULL;
0711
2015-09-13
pjp
}
0712
2015-09-13
pjp
0713
2015-09-13
pjp
SHA1_Init(&ctx);
0714
2015-09-13
pjp
SHA1_Update(&ctx, name, len);
0715
2015-09-13
pjp
SHA1_Update(&ctx, n3p->salt, n3p->saltlen);
0716
2015-09-13
pjp
SHA1_Final(md, &ctx);
0717
2015-09-13
pjp
0718
2015-09-13
pjp
for (i = 0; i < n3p->iterations; i++) {
0719
2015-09-13
pjp
SHA1_Init(&ctx);
0720
2015-09-13
pjp
SHA1_Update(&ctx, md, sizeof(md));
0721
2015-09-13
pjp
SHA1_Update(&ctx, n3p->salt, n3p->saltlen);
0722
2015-09-13
pjp
SHA1_Final(md, &ctx);
0723
2015-09-13
pjp
}
0724
2015-09-13
pjp
0725
2016-10-20
pjp
0726
2016-10-20
pjp
return(base32hex_encode(md, sizeof(md)));
0727
2015-09-13
pjp
}
0728
2015-09-13
pjp
0729
2015-11-17
pjp
void
0730
2015-11-17
pjp
mysetbit(u_char *input, int pos)
0731
2015-11-17
pjp
{
0732
2015-11-17
pjp
int bit;
0733
2015-11-17
pjp
int byte;
0734
2015-11-17
pjp
0735
2015-11-17
pjp
byte = pos / 8;
0736
2015-11-17
pjp
bit = pos % 8;
0737
2015-11-17
pjp
0738
2015-11-17
pjp
switch (bit) {
0739
2015-11-17
pjp
case 0:
0740
2015-11-17
pjp
input[byte] |= 128;
0741
2015-11-17
pjp
break;
0742
2015-11-17
pjp
case 1:
0743
2015-11-17
pjp
input[byte] |= 64;
0744
2015-11-17
pjp
break;
0745
2015-11-17
pjp
case 2:
0746
2015-11-17
pjp
input[byte] |= 32;
0747
2015-11-17
pjp
break;
0748
2015-11-17
pjp
case 3:
0749
2015-11-17
pjp
input[byte] |= 16;
0750
2015-11-17
pjp
break;
0751
2015-11-17
pjp
case 4:
0752
2015-11-17
pjp
input[byte] |= 8;
0753
2015-11-17
pjp
break;
0754
2015-11-17
pjp
case 5:
0755
2015-11-17
pjp
input[byte] |= 4;
0756
2015-11-17
pjp
break;
0757
2015-11-17
pjp
case 6:
0758
2015-11-17
pjp
input[byte] |= 2;
0759
2015-11-17
pjp
break;
0760
2015-11-17
pjp
case 7:
0761
2015-11-17
pjp
input[byte] |= 1;
0762
2015-11-17
pjp
break;
0763
2015-11-17
pjp
}
0764
2015-11-17
pjp
0765
2015-11-17
pjp
return;
0766
2015-11-17
pjp
}
0767
2015-11-17
pjp
0768
2015-11-17
pjp
int
0769
2015-11-17
pjp
base32hex_decode(u_char *input, u_char *output)
0770
2015-11-17
pjp
{
0771
2015-11-17
pjp
u_int8_t tmp;
0772
2015-11-17
pjp
u_char *character = "0123456789abcdefghijklmnopqrstuv=";
0773
2015-11-17
pjp
u_char *start = character, *p = character;
0774
2015-11-17
pjp
int i, j;
0775
2015-11-17
pjp
int len;
0776
2015-11-17
pjp
int bit = 0;
0777
2015-11-17
pjp
0778
2015-11-17
pjp
len = (strlen(input) * 5) / 8;
0779
2015-11-17
pjp
0780
2015-11-17
pjp
memset(output, 0, len);
0781
2015-11-17
pjp
0782
2015-11-17
pjp
for (i = 0; i < strlen(input); i++) {
0783
2015-11-17
pjp
if (input[i] == '=')
0784
2015-11-17
pjp
continue;
0785
2015-11-17
pjp
0786
2015-11-17
pjp
input[i] = tolower(input[i]);
0787
2015-11-17
pjp
for (p = character; *p && *p != input[i]; p++);
0788
2015-12-01
pjp
if (*p == '\0')
0789
2015-11-17
pjp
return 0;
0790
2015-11-17
pjp
0791
2015-11-17
pjp
tmp = (p - start);
0792
2015-11-17
pjp
tmp <<= 3;
0793
2015-11-17
pjp
0794
2015-11-17
pjp
for (j = 0; j < 5; j++) {
0795
2015-11-17
pjp
if (tmp & 128)
0796
2015-11-17
pjp
mysetbit(output, bit);
0797
2015-11-17
pjp
0798
2015-11-17
pjp
bit++;
0799
2015-11-17
pjp
tmp <<= 1;
0800
2015-11-17
pjp
}
0801
2015-11-17
pjp
}
0802
2015-11-17
pjp
0803
2015-11-17
pjp
return (len);
0804
2015-11-17
pjp
}
0805
2015-11-17
pjp
0806
2015-11-17
pjp
0807
2015-11-17
pjp
0808
2015-09-13
pjp
char *
0809
2015-09-13
pjp
base32hex_encode(u_char *input, int len)
0810
2015-09-13
pjp
{
0811
2015-09-13
pjp
u_char *ui;
0812
2015-09-13
pjp
u_int64_t tb = 0;
0813
2015-09-13
pjp
int i;
0814
2015-09-13
pjp
u_char *p;
0815
2019-07-05
pjp
static char ret[64];
0816
2015-09-13
pjp
0817
2015-09-13
pjp
u_char *character = "0123456789abcdefghijklmnopqrstuv=";
0818
2015-09-13
pjp
0819
2015-11-19
pjp
memset(&ret, 0, sizeof(ret));
0820
2015-09-13
pjp
p = &ret[0];
0821
2015-09-13
pjp
ui = input;
0822
2015-09-13
pjp
0823
2015-09-13
pjp
for (i = 0; i < len; i += 5) {
0824
2015-09-13
pjp
tb = (*ui & 0xff);
0825
2015-09-13
pjp
tb <<= 8;
0826
2015-09-13
pjp
0827
2015-09-13
pjp
if (i < len)
0828
2015-09-13
pjp
ui++;
0829
2015-09-13
pjp
else
0830
2015-09-13
pjp
*ui = 0;
0831
2015-09-13
pjp
0832
2015-09-13
pjp
tb |= (*ui & 0xff);
0833
2015-09-13
pjp
tb <<= 8;
0834
2015-09-13
pjp
0835
2015-09-13
pjp
if (i < len)
0836
2015-09-13
pjp
ui++;
0837
2015-09-13
pjp
else
0838
2015-09-13
pjp
*ui = 0;
0839
2015-09-13
pjp
0840
2015-09-13
pjp
tb |= (*ui & 0xff);
0841
2015-09-13
pjp
0842
2015-09-13
pjp
tb <<= 8;
0843
2015-09-13
pjp
0844
2015-09-13
pjp
if (i < len)
0845
2015-09-13
pjp
ui++;
0846
2015-09-13
pjp
else
0847
2015-09-13
pjp
*ui = 0;
0848
2015-09-13
pjp
0849
2015-09-13
pjp
tb |= (*ui & 0xff);
0850
2015-09-13
pjp
0851
2015-09-13
pjp
tb <<= 8;
0852
2015-09-13
pjp
0853
2015-09-13
pjp
if (i < len)
0854
2015-09-13
pjp
ui++;
0855
2015-09-13
pjp
else
0856
2015-09-13
pjp
*ui = 0;
0857
2015-09-13
pjp
0858
2015-09-13
pjp
tb |= (*ui & 0xff);
0859
2015-09-13
pjp
0860
2015-09-13
pjp
if (i < len)
0861
2015-09-13
pjp
ui++;
0862
2015-09-13
pjp
else
0863
2015-09-13
pjp
*ui = 0;
0864
2015-09-13
pjp
0865
2015-09-13
pjp
*(p + 7) = character[(tb & 0x1f)];
0866
2015-09-13
pjp
tb >>= 5;
0867
2015-09-13
pjp
*(p + 6) = character[(tb & 0x1f)];
0868
2015-09-13
pjp
tb >>= 5;
0869
2015-09-13
pjp
*(p + 5) = character[(tb & 0x1f)];
0870
2015-09-13
pjp
tb >>= 5;
0871
2015-09-13
pjp
*(p + 4) = character[(tb & 0x1f)];
0872
2015-09-13
pjp
tb >>= 5;
0873
2015-09-13
pjp
*(p + 3) = character[(tb & 0x1f)];
0874
2015-09-13
pjp
tb >>= 5;
0875
2015-09-13
pjp
*(p + 2) = character[(tb & 0x1f)];
0876
2015-09-13
pjp
tb >>= 5;
0877
2015-09-13
pjp
*(p + 1) = character[(tb & 0x1f)];
0878
2015-09-13
pjp
tb >>= 5;
0879
2015-09-13
pjp
*(p + 0) = character[(tb & 0x1f)];
0880
2015-09-13
pjp
0881
2015-09-13
pjp
p += 8;
0882
2015-09-13
pjp
}
0883
2015-09-13
pjp
0884
2015-09-13
pjp
return (ret);
0885
2015-09-13
pjp
}
0886
2015-09-13
pjp
0887
2015-09-13
pjp
/*
0888
2015-09-13
pjp
* FIND_NSEC3_MATCH_CLOSEST - find the closest matching encloser
0889
2015-09-13
pjp
*
0890
2015-09-13
pjp
*/
0891
2015-09-13
pjp
0892
2019-02-15
pjp
struct rbtree *
0893
2019-02-15
pjp
find_nsec3_match_closest(char *name, int namelen, struct rbtree *rbt, ddDB *db)
0894
2015-09-13
pjp
{
0895
2015-09-13
pjp
char *hashname;
0896
2015-09-13
pjp
char *backname;
0897
2015-09-14
pjp
char *dname;
0898
2015-09-13
pjp
int backnamelen;
0899
2019-02-15
pjp
struct rbtree *rbt0;
0900
2019-02-15
pjp
struct rrset *rrset = NULL;
0901
2019-02-15
pjp
struct rr *rrp = NULL;
0902
2015-09-13
pjp
0903
2019-02-15
pjp
if ((rrset = find_rr(rbt, DNS_TYPE_NSEC3PARAM)) == NULL) {
0904
2015-09-13
pjp
return NULL;
0905
2015-09-13
pjp
}
0906
2019-02-15
pjp
if ((rrp = TAILQ_FIRST(&rrset->rr_head)) == NULL) {
0907
2019-02-15
pjp
return NULL;
0908
2019-02-15
pjp
}
0909
2015-09-13
pjp
0910
2015-09-13
pjp
/* first off find the next closer record */
0911
2019-02-15
pjp
rbt0 = find_closest_encloser(db, name, namelen);
0912
2019-02-15
pjp
if (rbt0 == NULL) {
0913
2015-09-13
pjp
return NULL;
0914
2015-09-13
pjp
}
0915
2015-09-13
pjp
0916
2015-09-13
pjp
#if DEBUG
0917
2019-02-15
pjp
dolog(LOG_INFO, "next closer = %s\n", rbt0->humanname);
0918
2015-09-13
pjp
#endif
0919
2015-09-13
pjp
0920
2019-02-15
pjp
hashname = hash_name(rbt0->zone, rbt0->zonelen, (struct nsec3param *)rrp->rdata);
0921
2015-09-13
pjp
if (hashname == NULL) {
0922
2015-09-13
pjp
dolog(LOG_INFO, "unable to get hashname\n");
0923
2015-09-13
pjp
return NULL;
0924
2015-09-13
pjp
}
0925
2015-09-13
pjp
0926
2015-09-13
pjp
#if DEBUG
0927
2015-09-13
pjp
dolog(LOG_INFO, "hashname = %s\n", hashname);
0928
2015-09-13
pjp
#endif
0929
2019-02-15
pjp
dname = find_match_nsec3(rbt->zone, rbt->zonelen, hashname);
0930
2015-09-13
pjp
0931
2015-09-14
pjp
if (dname == NULL) {
0932
2015-09-13
pjp
return NULL;
0933
2015-09-13
pjp
}
0934
2015-09-13
pjp
0935
2015-09-13
pjp
/* found it, get it via db after converting it */
0936
2015-09-13
pjp
0937
2015-09-14
pjp
#ifdef DEBUG
0938
2015-09-14
pjp
dolog(LOG_INFO, "converting %s\n", dname);
0939
2015-09-14
pjp
#endif
0940
2015-09-14
pjp
backname = dns_label(dname, &backnamelen);
0941
2015-09-13
pjp
0942
2019-02-15
pjp
rbt0 = find_rrset(db, backname, backnamelen);
0943
2019-02-15
pjp
if (rbt0 == NULL) {
0944
2015-09-13
pjp
free (backname);
0945
2015-09-13
pjp
return (NULL);
0946
2015-09-13
pjp
}
0947
2015-09-13
pjp
0948
2015-09-13
pjp
free (backname);
0949
2015-09-13
pjp
0950
2015-09-14
pjp
#ifdef DEBUG
0951
2019-02-15
pjp
dolog(LOG_INFO, "returning %s\n", rbt0->humanname);
0952
2015-09-14
pjp
#endif
0953
2019-02-15
pjp
return (rbt0);
0954
2015-09-13
pjp
}
0955
2015-09-13
pjp
0956
2015-09-13
pjp
/*
0957
2015-09-13
pjp
* FIND_NSEC3_WILDCARD_CLOSEST - finds the right nsec3 domainname in a zone
0958
2015-09-13
pjp
*
0959
2015-09-13
pjp
*/
0960
2019-02-15
pjp
struct rbtree *
0961
2019-02-15
pjp
find_nsec3_wildcard_closest(char *name, int namelen, struct rbtree *rbt, ddDB *db)
0962
2015-09-13
pjp
{
0963
2020-04-11
pjp
struct rbtree *rbt0 = NULL;
0964
2020-04-11
pjp
struct rrset *rrset = NULL;
0965
2020-04-11
pjp
struct rr *rrp = NULL;
0966
2020-04-11
pjp
0967
2015-09-13
pjp
char *hashname;
0968
2015-09-13
pjp
char *backname;
0969
2015-09-14
pjp
char *dname;
0970
2020-04-11
pjp
char *p;
0971
2015-09-13
pjp
char wildcard[DNS_MAXNAME + 1];
0972
2020-04-11
pjp
0973
2015-09-13
pjp
int backnamelen;
0974
2020-04-11
pjp
int ret;
0975
2015-09-13
pjp
0976
2019-02-15
pjp
if ((rrset = find_rr(rbt, DNS_TYPE_NSEC3PARAM)) == NULL) {
0977
2015-09-13
pjp
return NULL;
0978
2015-09-13
pjp
}
0979
2019-02-15
pjp
if ((rrp = TAILQ_FIRST(&rrset->rr_head)) == NULL) {
0980
2019-02-15
pjp
return NULL;
0981
2019-02-15
pjp
}
0982
2015-09-13
pjp
0983
2015-09-13
pjp
/* first off find the next closer record */
0984
2019-02-15
pjp
rbt0 = find_closest_encloser(db, name, namelen);
0985
2019-02-15
pjp
if (rbt0 == NULL) {
0986
2015-09-13
pjp
return NULL;
0987
2015-09-13
pjp
}
0988
2015-09-13
pjp
0989
2015-09-13
pjp
#if DEBUG
0990
2019-02-15
pjp
dolog(LOG_INFO, "next closer = %s\n", rbt0->humanname);
0991
2015-09-13
pjp
#endif
0992
2020-04-11
pjp
p = rbt0->humanname;
0993
2020-04-11
pjp
ret = snprintf(wildcard, sizeof(wildcard), "*.%s", p);
0994
2020-04-11
pjp
if (ret >= sizeof(wildcard)) {
0995
2020-04-11
pjp
dolog(LOG_INFO, "result was truncated\n");
0996
2020-04-11
pjp
return NULL;
0997
2020-04-11
pjp
}
0998
2015-09-13
pjp
0999
2015-09-13
pjp
backname = dns_label(wildcard, &backnamelen);
1000
2015-09-13
pjp
1001
2019-02-15
pjp
hashname = hash_name(backname, backnamelen, (struct nsec3param *)rrp->rdata);
1002
2015-09-13
pjp
if (hashname == NULL) {
1003
2015-09-13
pjp
dolog(LOG_INFO, "unable to get hashname\n");
1004
2015-09-13
pjp
return NULL;
1005
2015-09-13
pjp
}
1006
2015-09-13
pjp
1007
2015-09-13
pjp
#if DEBUG
1008
2015-09-13
pjp
dolog(LOG_INFO, "hashname = %s\n", hashname);
1009
2015-09-13
pjp
#endif
1010
2015-09-13
pjp
1011
2019-02-15
pjp
dname = find_next_closer_nsec3(rbt->zone, rbt->zonelen, hashname);
1012
2015-09-13
pjp
1013
2015-09-13
pjp
/* found it, get it via db after converting it */
1014
2020-07-08
pjp
1015
2015-09-14
pjp
#ifdef DEBUG
1016
2015-09-14
pjp
dolog(LOG_INFO, "converting %s\n", dname);
1017
2015-09-14
pjp
#endif
1018
2015-09-14
pjp
backname = dns_label(dname, &backnamelen);
1019
2015-09-13
pjp
1020
2019-02-15
pjp
rbt0 = find_rrset(db, backname, backnamelen);
1021
2019-02-15
pjp
if (rbt0 == NULL) {
1022
2015-09-13
pjp
free (backname);
1023
2015-09-13
pjp
return (NULL);
1024
2015-09-13
pjp
}
1025
2015-09-13
pjp
1026
2015-09-13
pjp
1027
2015-09-13
pjp
free (backname);
1028
2015-09-13
pjp
1029
2015-09-14
pjp
#ifdef DEBUG
1030
2019-02-15
pjp
dolog(LOG_INFO, "returning %s\n", rbt0->humanname);
1031
2015-09-14
pjp
#endif
1032
2019-02-15
pjp
return (rbt0);
1033
2015-09-13
pjp
}
1034
2015-09-13
pjp
1035
2015-09-13
pjp
/*
1036
2015-09-13
pjp
* FIND_NSEC3_COVER_NEXT_CLOSER - finds the right nsec3 domainname in a zone
1037
2015-09-13
pjp
*
1038
2015-09-13
pjp
*/
1039
2019-02-15
pjp
struct rbtree *
1040
2019-02-15
pjp
find_nsec3_cover_next_closer(char *name, int namelen, struct rbtree *rbt, ddDB *db)
1041
2015-09-13
pjp
{
1042
2015-09-13
pjp
char *hashname;
1043
2015-09-13
pjp
char *backname;
1044
2015-09-14
pjp
char *dname;
1045
2015-09-13
pjp
int backnamelen;
1046
2019-02-15
pjp
struct rrset *rrset = NULL;
1047
2019-02-15
pjp
struct rr *rrp = NULL;
1048
2016-01-22
pjp
char *ncn;
1049
2016-01-22
pjp
int ncnlen;
1050
2019-02-15
pjp
struct rbtree *rbt0;
1051
2015-09-13
pjp
1052
2019-02-15
pjp
if ((rrset = find_rr(rbt, DNS_TYPE_NSEC3PARAM)) == NULL) {
1053
2015-09-13
pjp
return NULL;
1054
2015-09-13
pjp
}
1055
2019-02-15
pjp
if ((rrp = TAILQ_FIRST(&rrset->rr_head)) == NULL) {
1056
2019-02-15
pjp
return NULL;
1057
2019-02-15
pjp
}
1058
2015-09-13
pjp
1059
2015-09-13
pjp
/* first off find the next closer record */
1060
2019-02-15
pjp
rbt0 = find_closest_encloser(db, name, namelen);
1061
2019-02-15
pjp
if (rbt0 == NULL) {
1062
2015-09-13
pjp
return NULL;
1063
2015-09-13
pjp
}
1064
2015-09-13
pjp
1065
2019-02-15
pjp
ncn = find_next_closer_name(name, namelen, rbt0->zone, rbt0->zonelen, &ncnlen);
1066
2017-09-06
pjp
if (ncn == NULL) {
1067
2016-01-22
pjp
return NULL;
1068
2017-09-06
pjp
}
1069
2015-09-13
pjp
1070
2019-02-15
pjp
hashname = hash_name(ncn, ncnlen, (struct nsec3param *)rrp->rdata);
1071
2015-09-13
pjp
if (hashname == NULL) {
1072
2015-09-13
pjp
dolog(LOG_INFO, "unable to get hashname\n");
1073
2015-09-13
pjp
return NULL;
1074
2015-09-13
pjp
}
1075
2015-09-13
pjp
1076
2015-09-13
pjp
#if DEBUG
1077
2015-09-13
pjp
dolog(LOG_INFO, "hashname = %s\n", hashname);
1078
2015-09-13
pjp
#endif
1079
2015-09-13
pjp
1080
2015-09-14
pjp
/* free what we don't need */
1081
2015-09-13
pjp
1082
2019-02-15
pjp
dname = find_next_closer_nsec3(rbt->zone, rbt->zonelen, hashname);
1083
2015-09-14
pjp
if (dname == NULL)
1084
2015-09-13
pjp
return NULL;
1085
2015-09-13
pjp
1086
2015-09-13
pjp
1087
2015-09-14
pjp
#ifdef DEBUG
1088
2015-09-14
pjp
dolog(LOG_INFO, "converting %s\n", dname);
1089
2015-09-14
pjp
#endif
1090
2015-09-13
pjp
1091
2015-09-14
pjp
backname = dns_label(dname, &backnamelen);
1092
2015-09-13
pjp
1093
2019-02-15
pjp
if ((rbt0 = find_rrset(db, backname, backnamelen)) == NULL) {
1094
2015-09-13
pjp
free (backname);
1095
2015-09-13
pjp
return (NULL);
1096
2015-09-13
pjp
}
1097
2015-09-13
pjp
1098
2015-09-13
pjp
1099
2015-09-13
pjp
free (backname);
1100
2015-09-13
pjp
1101
2015-09-14
pjp
#ifdef DEBUG
1102
2019-02-15
pjp
dolog(LOG_INFO, "returning %s\n", rbt0->humanname);
1103
2015-09-14
pjp
#endif
1104
2015-09-14
pjp
1105
2019-02-15
pjp
return (rbt0);
1106
2015-09-13
pjp
}
1107
2015-09-13
pjp
1108
2015-09-13
pjp
/*
1109
2015-09-13
pjp
* FIND_NSEC3_MATCH_QNAME - find the matching QNAME and return NSEC3
1110
2015-09-13
pjp
*
1111
2015-09-13
pjp
*/
1112
2015-09-13
pjp
1113
2019-02-15
pjp
struct rbtree *
1114
2019-02-15
pjp
find_nsec3_match_qname(char *name, int namelen, struct rbtree *rbt, ddDB *db)
1115
2015-09-13
pjp
{
1116
2015-09-13
pjp
char *hashname;
1117
2015-09-13
pjp
char *backname;
1118
2015-09-14
pjp
char *dname;
1119
2015-09-13
pjp
int backnamelen;
1120
2019-02-18
pjp
struct rbtree *rbt0 = NULL;
1121
2019-02-15
pjp
struct rrset *rrset = NULL;
1122
2019-02-15
pjp
struct rr *rrp = NULL;
1123
2015-09-13
pjp
1124
2019-02-18
pjp
1125
2019-02-15
pjp
if ((rrset = find_rr(rbt, DNS_TYPE_NSEC3PARAM)) == NULL) {
1126
2015-09-13
pjp
return NULL;
1127
2015-09-13
pjp
}
1128
2019-02-15
pjp
if ((rrp = TAILQ_FIRST(&rrset->rr_head)) == NULL) {
1129
2019-02-15
pjp
return NULL;
1130
2019-02-15
pjp
}
1131
2015-09-13
pjp
1132
2019-02-15
pjp
hashname = hash_name(name, namelen, (struct nsec3param *)rrp->rdata);
1133
2015-09-13
pjp
if (hashname == NULL) {
1134
2015-09-13
pjp
dolog(LOG_INFO, "unable to get hashname\n");
1135
2015-09-13
pjp
return NULL;
1136
2015-09-13
pjp
}
1137
2015-09-13
pjp
1138
2015-09-13
pjp
#if DEBUG
1139
2015-09-13
pjp
dolog(LOG_INFO, "hashname = %s\n", hashname);
1140
2015-09-13
pjp
#endif
1141
2017-01-11
pjp
1142
2019-02-18
pjp
#if 0
1143
2017-01-11
pjp
if (check_ent(name, namelen))
1144
2019-02-15
pjp
dname = find_match_nsec3_ent(rbt->zone, rbt->zonelen, hashname);
1145
2017-01-11
pjp
else
1146
2019-02-18
pjp
#endif
1147
2019-02-18
pjp
1148
2019-02-18
pjp
dname = find_match_nsec3(rbt->zone, rbt->zonelen, hashname);
1149
2015-09-13
pjp
1150
2019-02-18
pjp
if (dname == NULL) {
1151
2015-09-13
pjp
return NULL;
1152
2019-02-18
pjp
}
1153
2015-09-13
pjp
1154
2015-09-13
pjp
/* found it, get it via db after converting it */
1155
2015-09-13
pjp
1156
2015-09-14
pjp
#if DEBUG
1157
2015-09-14
pjp
dolog(LOG_INFO, "converting %s\n", dname);
1158
2015-09-14
pjp
#endif
1159
2015-09-13
pjp
1160
2015-09-14
pjp
backname = dns_label(dname, &backnamelen);
1161
2019-02-18
pjp
if (backname == NULL) {
1162
2019-02-18
pjp
return NULL;
1163
2019-02-18
pjp
}
1164
2019-02-18
pjp
1165
2019-02-15
pjp
rbt0 = find_rrset(db, backname, backnamelen);
1166
2019-02-15
pjp
if (rbt0 == NULL) {
1167
2015-09-13
pjp
free (backname);
1168
2015-09-13
pjp
return (NULL);
1169
2015-09-13
pjp
}
1170
2015-09-13
pjp
1171
2015-09-13
pjp
1172
2015-09-13
pjp
free (backname);
1173
2015-09-13
pjp
1174
2015-09-14
pjp
#ifdef DEBUG
1175
2019-02-15
pjp
dolog(LOG_INFO, "returning %s\n", rbt0->humanname);
1176
2015-09-14
pjp
#endif
1177
2015-09-14
pjp
1178
2019-02-15
pjp
return (rbt0);
1179
2015-09-13
pjp
}
repomaster@centroid.eu