Commit Diff
Diff:
d2ab023e44d7e0e3775008d33abcd8eacd46ba38
6401de33cd4de79149b42ac698eedbc40faf7f1c
Commit:
6401de33cd4de79149b42ac698eedbc40faf7f1c
Tree:
7de03ffed1ba55a92439d66942323597f419cb49
Author:
pjp <pjp@delphinusdns.org>
Committer:
pjp <pjp@delphinusdns.org>
Date:
Mon Jun 26 20:28:50 2017 UTC
Message:
Change from Berkeley DB to tree(3) macros. I have for simplicity sake kept the BerkeleyDB db format but had to rename every variable which was a lot of work. Add db.c - this is the new delphinusdns DB routines wrapping tree(3). TLSA was not honored in AXFR, fix that. That's a major bug for 1.1.0. Tested on FreeBSD, OpenBSD and Linux Raspbian.
blob - 076d471921496a45dc917c98c8e252df2c095695
blob + 97466d227fa839df65bbcabbf3f1993026af4ed8
--- Makefile.linux
+++ Makefile.linux
@@ -1,18 +1,18 @@
CC=gcc
#CFLAGS=-DDEBUG
CFLAGS=
-LDADD= -ldb -lresolv -lcrypto -lrt -lbsd
+LDADD= -lresolv -lcrypto -lrt -lbsd
YACC=bison
AR=ar
all: delphinusdnsd dd-convert
-delphinusdnsd: additional.o parse.o delphinusdnsd.o reply.o region.o log.o axfr.o filter.o ratelimit.o whitelist.o base64.o dnssec.o util.o ent.o
- $(CC) $(CFLAGS) -o delphinusdnsd/delphinusdnsd additional.o delphinusdnsd.o parse.o reply.o region.o log.o axfr.o filter.o ratelimit.o whitelist.o base64.o dnssec.o util.o ent.o $(LDADD)
+delphinusdnsd: additional.o parse.o delphinusdnsd.o reply.o region.o log.o axfr.o filter.o ratelimit.o whitelist.o base64.o dnssec.o util.o ent.o db.o
+ $(CC) $(CFLAGS) -o delphinusdnsd/delphinusdnsd additional.o delphinusdnsd.o parse.o reply.o region.o log.o axfr.o filter.o ratelimit.o whitelist.o base64.o dnssec.o util.o ent.o db.o $(LDADD)
dd-convert: dd-convert.o util.o dnssec.o parse.o base64.o ent.o
- $(CC) $(CFLAGS) -o dd-convert/dd-convert dd-convert.o util.o dnssec.o base64.o parse.o ent.o $(LDADD)
+ $(CC) $(CFLAGS) -o dd-convert/dd-convert dd-convert.o util.o dnssec.o base64.o parse.o ent.o db.o $(LDADD)
dd-convert.o: dd-convert.c
blob - 07167f3e1f0470990ad807b18f64406aad42537f
blob + 2b4a5196c4af6b0482b1947b64228b93e24bb3f6
--- axfr.c
+++ axfr.c
@@ -30,12 +30,12 @@
#include "ddd-db.h"
-void axfrloop(int *, int, char **, DB *);
-void axfr_connection(int, char *, int, DB *);
-int build_header(DB *, char *, char *, struct question *, int);
-int build_soa(DB *, char *, int, struct domain *, struct question *);
-int checklabel(DB *, struct domain *, struct domain *, struct question *);
-void gather_notifydomains(DB *);
+void axfrloop(int *, int, char **, ddDB *);
+void axfr_connection(int, char *, int, ddDB *);
+int build_header(ddDB *, char *, char *, struct question *, int);
+int build_soa(ddDB *, char *, int, struct domain *, struct question *);
+int checklabel(ddDB *, struct domain *, struct domain *, struct question *);
+void gather_notifydomains(ddDB *);
void init_axfr(void);
void init_notifyslave(void);
int insert_axfr(char *, char *);
@@ -44,12 +44,12 @@ void notifypacket(int, void *, void *, int);
void notifyslaves(int *);
void reap(int);
-extern int get_record_size(DB *, char *, int);
+extern int get_record_size(ddDB *, char *, int);
extern in_addr_t getmask(int);
extern int getmask6(int, struct sockaddr_in6 *);
extern void reply_fmterror(struct sreply *);
extern void reply_nxdomain(struct sreply *);
-extern struct domain * get_soa(DB *, struct question *);
+extern struct domain * get_soa(ddDB *, struct question *);
extern void * find_substruct(struct domain *, u_int16_t);
extern int compress_label(u_char *, int, int);
extern u_int16_t create_anyreply(struct sreply *, char *, int, int, int);
@@ -99,9 +99,14 @@ static struct notifyentry {
SLIST_ENTRY(notifyentry) notify_entry;
} *notn2, *notnp;
+extern int domaincmp(struct node *e1, struct node *e2);
+RB_HEAD(domaintree, node) rbhead;
+RB_PROTOTYPE_STATIC(domaintree, node, entry, domaincmp)
+RB_GENERATE_STATIC(domaintree, node, entry, domaincmp)
-static const char rcsid[] = "$Id: axfr.c,v 1.8 2016/07/06 05:12:50 pjp Exp $";
+static const char rcsid[] = "$Id: axfr.c,v 1.9 2017/06/26 20:28:50 pjp Exp $";
+
/*
* INIT_AXFR - initialize the axfr singly linked list
*/
@@ -296,7 +301,7 @@ insert_notifyslave(char *address, char *prefixlen)
}
void
-axfrloop(int *afd, int sockcount, char **ident, DB *db)
+axfrloop(int *afd, int sockcount, char **ident, ddDB *db)
{
fd_set rset;
@@ -638,7 +643,7 @@ axfrloop(int *afd, int sockcount, char **ident, DB *db
*/
void
-axfr_connection(int so, char *address, int is_ipv6, DB *db)
+axfr_connection(int so, char *address, int is_ipv6, ddDB *db)
{
char buf[4000];
@@ -656,14 +661,14 @@ axfr_connection(int so, char *address, int is_ipv6, DB
u_int16_t *tmp;
+ struct node *n, *nx;
struct dns_header *dh, *odh;
struct sreply sreply;
struct question *question, *fq;
struct domain *soa = NULL, *sdomain = NULL, *nsdomain = NULL, *savesd = NULL;
struct domain_ns *savesdns;
- DBT key, data;
- DBC *cursor;
+ ddDBT key, data;
for (;;) {
len = recv(so, p + offset, sizeof(buf) - offset, 0);
@@ -756,7 +761,7 @@ axfr_connection(int so, char *address, int is_ipv6, DB
data.data = NULL;
data.size = rs;
- ret = db->get(db, NULL, &key, &data, 0);
+ ret = db->get(db, &key, &data);
if (ret != 0) {
sdomain = get_soa(db, question);
@@ -830,22 +835,11 @@ axfr_connection(int so, char *address, int is_ipv6, DB
outlen = build_soa(db, (reply + 2), outlen, soa, question);
rrcount = 1;
- if (db->cursor(db, NULL, &cursor, 0) != 0) {
- dolog(LOG_INFO, "db->cursor: %s\n", strerror(errno));
- goto drop;
- }
-
memset(&key, 0, sizeof(key));
memset(&data, 0, sizeof(data));
-
- if (cursor->c_get(cursor, &key, &data, DB_FIRST) != 0) {
- dolog(LOG_INFO, "cursor->c_get: %s\n", strerror(errno));
- goto drop;
- }
-
- do {
- rs = data.size;
+ RB_FOREACH_SAFE(n, domaintree, &rbhead, nx) {
+ rs = n->datalen;
if ((sdomain = calloc(1, rs)) == NULL) {
dolog(LOG_INFO, "calloc: %s\n", strerror(errno));
goto drop;
@@ -855,8 +849,8 @@ axfr_connection(int so, char *address, int is_ipv6, DB
goto drop;
}
- memcpy((char *)sdomain, (char *)data.data, data.size);
- memcpy((char *)savesd, (char *)data.data, data.size);
+ memcpy((char*)sdomain,(char*)n->data, rs);
+ memcpy((char*)savesd,(char*)n->data, rs);
if (checklabel(db, sdomain, soa, question)) {
fq = build_fake_question(sdomain->zone, sdomain->zonelen, 0);
@@ -892,7 +886,7 @@ axfr_connection(int so, char *address, int is_ipv6, DB
data.data = NULL;
data.size = rs;
- ret = db->get(db, NULL, &key, &data, 0);
+ ret = db->get(db, &key, &data);
if (ret != 0) {
free_question(fq);
continue;
@@ -957,10 +951,8 @@ axfr_connection(int so, char *address, int is_ipv6, DB
free(savesd);
savesd = NULL;
}
- } while (cursor->c_get(cursor, &key, &data, DB_NEXT) == 0);
+ } /* RB_FOREACH */
- cursor->c_close(cursor);
-
outlen = build_soa(db, (reply + 2), outlen, soa, question);
rrcount++;
@@ -1030,7 +1022,7 @@ reap(int sig)
*/
int
-build_header(DB *db, char *reply, char *buf, struct question *q, int answercount)
+build_header(ddDB *db, char *reply, char *buf, struct question *q, int answercount)
{
struct dns_header *odh;
u_int16_t outlen;
@@ -1065,7 +1057,7 @@ build_header(DB *db, char *reply, char *buf, struct qu
*/
int
-build_soa(DB *db, char *reply, int offset, struct domain *sd, struct question *q)
+build_soa(ddDB *db, char *reply, int offset, struct domain *sd, struct question *q)
{
char *p;
char *label;
@@ -1180,14 +1172,14 @@ build_soa(DB *db, char *reply, int offset, struct doma
}
int
-checklabel(DB *db, struct domain *sd, struct domain *soa, struct question *q)
+checklabel(ddDB *db, struct domain *sd, struct domain *soa, struct question *q)
{
struct domain *tmpsd;
char *p;
int plen, ret;
int rs;
- DBT key, data;
+ ddDBT key, data;
if (memcmp(sd, soa, sizeof(struct domain)) == 0)
return 1;
@@ -1218,8 +1210,8 @@ checklabel(DB *db, struct domain *sd, struct domain *s
data.data = NULL;
data.size = rs;
- ret = db->get(db, NULL, &key, &data, 0);
- if (ret == DB_NOTFOUND) {
+ ret = db->get(db, &key, &data);
+ if (ret == DDDB_NOTFOUND) {
plen -= (*p + 1);
p = (p + (*p + 1));
@@ -1262,10 +1254,9 @@ checklabel(DB *db, struct domain *sd, struct domain *s
}
void
-gather_notifydomains(DB *db)
+gather_notifydomains(ddDB *db)
{
- DBT key, data;
- DBC *cursor;
+ ddDBT key, data;
time_t now, soatime;
struct tm *tm;
@@ -1273,6 +1264,7 @@ gather_notifydomains(DB *db)
char timestring[128];
char buf[128];
+ struct node *n, *nx;
struct domain *sd;
struct domain_soa *sdsoa = NULL;
@@ -1287,24 +1279,12 @@ gather_notifydomains(DB *db)
now = time(NULL);
- if (db->cursor(db, NULL, &cursor, 0) != 0) {
- dolog(LOG_INFO, "db->cursor: %s\n", strerror(errno));
- return;
- }
-
memset(&key, 0, sizeof(key));
memset(&data, 0, sizeof(data));
+ RB_FOREACH_SAFE(n, domaintree, &rbhead, nx) {
+ sd = (struct domain *)n->data;
- if (cursor->c_get(cursor, &key, &data, DB_FIRST) != 0) {
- dolog(LOG_INFO, "cursor->c_get: %s\n", strerror(errno));
- cursor->c_close(cursor);
- return;
- }
-
- do {
- sd = (struct domain *)data.data;
-
if ((sd->flags & DOMAIN_HAVE_SOA) == DOMAIN_HAVE_SOA) {
sdsoa = (struct domain_soa *)find_substruct(sd, INTERNAL_TYPE_SOA);
notn2 = malloc(sizeof(struct notifyentry));
@@ -1346,9 +1326,7 @@ gather_notifydomains(DB *db)
memset(&key, 0, sizeof(key));
memset(&data, 0, sizeof(data));
- } while (cursor->c_get(cursor, &key, &data, DB_NEXT) == 0);
-
- cursor->c_close(cursor);
+ }
return;
}
blob - e66ae29dfb7d132698ec926fd368acb9a4a3467e
blob + 57d9681d954052eee560767606e96d03e4c08eba
--- dd-convert/Makefile.freebsd
+++ dd-convert/Makefile.freebsd
@@ -2,11 +2,11 @@
PROG=dd-convert
-SRCS=dd-convert.c parse.y base64.c dnssec.c util.c ent.c
+SRCS=dd-convert.c parse.y base64.c dnssec.c util.c ent.c db.c
-CFLAGS= -Wall -g -I/usr/local/include/db5 -I${.CURDIR}/..
-LDFLAGS= -Wall -g -L/usr/local/lib/db5
-LDADD= -lcrypto -lssl -ldb
+CFLAGS= -Wall -g -I${.CURDIR}/..
+LDFLAGS= -Wall -g
+LDADD= -lcrypto -lssl
OBJDIR=.
BINDIR=/usr/local/sbin
blob - 86c52b503c6017ec160324a9d5c24a8ebb57e320
blob + 85cb9e3338512b5c47529395262664c6fd0429f7
--- dd-convert/Makefile.netbsd
+++ dd-convert/Makefile.netbsd
@@ -2,12 +2,12 @@
PROG=dd-convert
-SRCS=dd-convert.c parse.y base64.c dnssec.c util.c ent.c
+SRCS=dd-convert.c parse.y base64.c dnssec.c util.c ent.c db.c
-CFLAGS= -g -I/usr/pkg/include/db5/
+CFLAGS= -g
CFLAGS+= -I${.CURDIR}/..
LDFLAGS= -g -L/usr/pkg/lib -R/usr/pkg/lib
-LDADD= -lcrypto -lssl -ldb5
+LDADD= -lcrypto -lssl
OBJDIR=.
BINDIR=/usr/local/sbin
blob - 39c82222a38d0493ea84c75c959578f7f9ce1542
blob + b819329213ee7b8695dd562d4b8d0e86eaeea3d8
--- dd-convert/Makefile.openbsd
+++ dd-convert/Makefile.openbsd
@@ -2,11 +2,11 @@
PROG=dd-convert
-SRCS=dd-convert.c parse.y base64.c dnssec.c util.c ent.c
+SRCS=dd-convert.c parse.y base64.c dnssec.c util.c ent.c db.c
-CFLAGS= -Wall -g -I/usr/local/include/db4 -I${.CURDIR}/..
-LDFLAGS= -Wall -g -L/usr/local/lib/db4
-LDADD= -lcrypto -lssl -ldb
+CFLAGS= -Wall -g -I${.CURDIR}/..
+LDFLAGS= -Wall -g
+LDADD= -lcrypto -lssl
OBJDIR=.
BINDIR=/usr/local/sbin
blob - /dev/null
blob + a08856e8709b7f50d6e10a33a022ce129ded4e8c (mode 644)
--- /dev/null
+++ db.c
@@ -0,0 +1,141 @@
+/*
+ * Copyright (c) 2017 Peter J. Philipp
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include "ddd-include.h"
+#include "ddd-dns.h"
+#include "ddd-db.h"
+
+
+
+int
+domaincmp(struct node *e1, struct node *e2)
+{
+ if (e1->len < e2->len)
+ return -1;
+ else if (e1->len > e2->len)
+ return 1;
+ else {
+ return (memcmp(e1->domainname, e2->domainname, e1->len));
+ }
+}
+
+
+RB_HEAD(domaintree, node) rbhead = RB_INITIALIZER(&rbhead);
+RB_PROTOTYPE(domaintree, node, entry, domaincmp)
+RB_GENERATE(domaintree, node, entry, domaincmp)
+
+
+
+ddDB *
+dddbopen(void)
+{
+ ddDB *db;
+
+ db = calloc(1, sizeof(ddDB));
+ if (db == NULL) {
+ errno = ENOMEM;
+ return NULL;
+ }
+
+ db->put = dddbput;
+ db->get = dddbget;
+ db->close = dddbclose;
+ db->offset = 0;
+
+ return (db);
+}
+
+int
+dddbput(ddDB *db, ddDBT *key, ddDBT *data)
+{
+ struct node find, *n, *res;
+ char *map;
+
+ if (data->size > SIZENODE) {
+ errno = E2BIG;
+ return -1;
+ }
+
+ strlcpy(find.domainname, key->data, sizeof(find.domainname));
+ find.len = key->size;
+
+ res = RB_FIND(domaintree, &rbhead, &find);
+ if (res == NULL) {
+ /* does not exist, create it */
+
+ map = (char *)mmap(NULL, SIZENODE, PROT_READ|PROT_WRITE,MAP_ANON|MAP_SHARED,-1, 0);
+ if (map == MAP_FAILED) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ n = calloc(sizeof(struct node), 1);
+ if (n == NULL) {
+ errno = ENOMEM;
+ return -1;
+ }
+ memset(n, 0, sizeof(struct node));
+ n->len = key->size;
+ memcpy(n->domainname, key->data, n->len);
+ n->data = map;
+ n->datalen = data->size;
+ memcpy(map, data->data, data->size);
+
+ RB_INSERT(domaintree, &rbhead, n);
+ } else {
+ res->datalen = data->size;
+ memcpy(res->data, data->data, data->size);
+ }
+
+ return 0;
+}
+
+int
+dddbget(ddDB *db, ddDBT *key, ddDBT *data)
+{
+ struct node find, *res;
+
+ strlcpy(find.domainname, key->data, sizeof(find.domainname));
+ find.len = key->size;
+
+ res = RB_FIND(domaintree, &rbhead, &find);
+ if (res == NULL) {
+ return -1;
+ }
+
+ data->size = res->datalen;
+ data->data = res->data;
+
+ return 0;
+}
+
+int
+dddbclose(ddDB *db)
+{
+ return 0;
+}
blob - 4105ad1b96d0e56598a5faf86bdf4f2541d80eae
blob + 6b9b7e4d460167c02ff2f634a4d5dece1646acd5
--- dd-convert.c
+++ dd-convert.c
@@ -42,31 +42,31 @@ int verbose = 0;
/* prototypes */
void dolog(int pri, char *fmt, ...);
-int add_dnskey(DB *, char *, char *);
+int add_dnskey(ddDB *, char *, char *);
char * parse_keyfile(int, uint32_t *, uint16_t *, uint8_t *, uint8_t *, char *, int *);
char * create_key(char *, int, int, int, int);
-int dump_db(DB *, FILE *, char *);
+int dump_db(ddDB *, FILE *, char *);
char * alg_to_name(int);
int alg_to_rsa(int);
-int construct_nsec3(DB *, char *, int, char *);
-int calculate_rrsigs(DB *, char *, char *, char *, int);
-int sign_dnskey(DB *, char *, char *, char *, int, struct domain *);
-int sign_a(DB *, char *, char *, int, struct domain *);
-int sign_mx(DB *, char *, char *, int, struct domain *);
-int sign_ns(DB *, char *, char *, int, struct domain *);
-int sign_srv(DB *, char *, char *, int, struct domain *);
-int sign_cname(DB *, char *, char *, int, struct domain *);
-int sign_soa(DB *, char *, char *, int, struct domain *);
-int sign_txt(DB *, char *, char *, int, struct domain *);
-int sign_aaaa(DB *, char *, char *, int, struct domain *);
-int sign_ptr(DB *, char *, char *, int, struct domain *);
-int sign_nsec3(DB *, char *, char *, int, struct domain *);
-int sign_nsec3param(DB *, char *, char *, int, struct domain *);
-int sign_naptr(DB *, char *, char *, int, struct domain *);
-int sign_sshfp(DB *, char *, char *, int, struct domain *);
-int sign_tlsa(DB *, char *, char *, int, struct domain *);
-int sign_ds(DB *, char *, char *, int, struct domain *);
-int create_ds(DB *, char *, char *);
+int construct_nsec3(ddDB *, char *, int, char *);
+int calculate_rrsigs(ddDB *, char *, char *, char *, int);
+int sign_dnskey(ddDB *, char *, char *, char *, int, struct domain *);
+int sign_a(ddDB *, char *, char *, int, struct domain *);
+int sign_mx(ddDB *, char *, char *, int, struct domain *);
+int sign_ns(ddDB *, char *, char *, int, struct domain *);
+int sign_srv(ddDB *, char *, char *, int, struct domain *);
+int sign_cname(ddDB *, char *, char *, int, struct domain *);
+int sign_soa(ddDB *, char *, char *, int, struct domain *);
+int sign_txt(ddDB *, char *, char *, int, struct domain *);
+int sign_aaaa(ddDB *, char *, char *, int, struct domain *);
+int sign_ptr(ddDB *, char *, char *, int, struct domain *);
+int sign_nsec3(ddDB *, char *, char *, int, struct domain *);
+int sign_nsec3param(ddDB *, char *, char *, int, struct domain *);
+int sign_naptr(ddDB *, char *, char *, int, struct domain *);
+int sign_sshfp(ddDB *, char *, char *, int, struct domain *);
+int sign_tlsa(ddDB *, char *, char *, int, struct domain *);
+int sign_ds(ddDB *, char *, char *, int, struct domain *);
+int create_ds(ddDB *, char *, char *);
u_int keytag(u_char *key, u_int keysize);
void pack(char *, char *, int);
void pack32(char *, u_int32_t);
@@ -77,7 +77,7 @@ u_int64_t timethuman(time_t);
char * bitmap2human(char *, int);
char * bin2hex(char *, int);
int print_sd(FILE *, struct domain *);
-void cleanup(DB *, char *);
+void cleanup(ddDB *, char *);
void usage(void);
@@ -137,7 +137,7 @@ extern char * convert_name(char *name, int namelen);
extern int mybase64_encode(u_char const *, size_t, char *, size_t);
extern int mybase64_decode(char const *, u_char *, size_t);
-extern struct domain * lookup_zone(DB *, struct question *, int *, int *, char *);
+extern struct domain * lookup_zone(ddDB *, struct question *, int *, int *, char *);
extern struct question *build_fake_question(char *, int, u_int16_t);
extern char * dns_label(char *, int *);
extern void * find_substruct(struct domain *, u_int16_t);
@@ -146,8 +146,12 @@ extern char *get_dns_type(int, int);
extern char * hash_name(char *, int, struct nsec3param *);
extern char * base32hex_encode(u_char *input, int len);
+extern int domaincmp(struct node *e1, struct node *e2);
+RB_HEAD(domaintree, node) rbhead;
+RB_GENERATE_STATIC(domaintree, node, entry, domaincmp)
+
int
main(int argc, char *argv[])
{
@@ -155,7 +159,7 @@ main(int argc, char *argv[])
struct stat sb;
int ch;
- int ret, bits = 2048;
+ int bits = 2048;
int ttl = 3600;
int create_zsk = 0;
int create_ksk = 0;
@@ -164,8 +168,6 @@ main(int argc, char *argv[])
int iterations = 10;
u_int32_t mask = (MASK_PARSE_FILE | MASK_ADD_DNSKEY | MASK_CONSTRUCT_NSEC3 | MASK_CALCULATE_RRSIGS | MASK_CREATE_DS | MASK_DUMP_DB);
- key_t key;
-
char *salt = "-";
char *zonefile = NULL;
char *zonename = NULL;
@@ -174,10 +176,8 @@ main(int argc, char *argv[])
char *ksk_key = NULL;
char *zsk_key = NULL;
char *tmpdir;
- char tmppath[] = "./tmp.XXXXXXXXXX";
- DB *db;
- DB_ENV *dbenv;
+ ddDB *db;
while ((ch = getopt(argc, argv, "a:B:e:hI:i:Kk:m:n:o:s:t:vZz:")) != -1) {
@@ -314,44 +314,12 @@ main(int argc, char *argv[])
#endif
/* open the database(s) */
- if ((ret = db_env_create(&dbenv, 0)) != 0) {
- fprintf(stderr, "db_env_create: %s\n", db_strerror(ret));
+ db = dddbopen();
+ if (db == NULL) {
+ dolog(LOG_INFO, "dddbopen() failed\n");
exit(1);
}
- if ((tmpdir = mkdtemp(tmppath)) == NULL) {
- perror("mkdtemp");
- exit(1);
- }
-
- key = ftok(tmpdir, 1);
- if (key == (key_t)-1) {
- perror("ftok");
- exit(1);
- }
-
- if ((ret = dbenv->set_shm_key(dbenv, key)) != 0) {
- fprintf(stderr, "dbenv->set_shm_key failed\n");
- exit(1);
- }
-
- if ((ret = dbenv->open(dbenv, tmpdir, DB_CREATE | \
- DB_INIT_LOCK | DB_INIT_MPOOL | DB_SYSTEM_MEM, \
- S_IRUSR | S_IWUSR)) != 0) {
- fprintf(stderr, "dbenv->open: %s\n", db_strerror(ret));
- exit(1);
- }
-
- if (db_create((DB **)&db, (DB_ENV*)dbenv, 0) != 0) {
- perror("db_create");
- exit(1);
- }
-
- if (db->open(db, NULL, "ddc.db", NULL, DB_BTREE, DB_CREATE, 0600) != 0) {
- perror("db->open");
- exit(1);
- }
-
/* now we start reading our configfile */
if ((mask & MASK_PARSE_FILE) && parse_file(db, zonefile) < 0) {
@@ -458,7 +426,7 @@ dolog(int pri, char *fmt, ...)
}
int
-add_dnskey(DB *db, char *zsk_key, char *ksk_key)
+add_dnskey(ddDB *db, char *zsk_key, char *ksk_key)
{
char key[4096];
char buf[512];
@@ -607,13 +575,13 @@ parse_keyfile(int fd, uint32_t *ttl, uint16_t *flags,
}
int
-dump_db(DB *db, FILE *of, char *zonename)
+dump_db(ddDB *db, FILE *of, char *zonename)
{
int j, rs;
- DBT key, data;
- DBC *cursor;
+ ddDBT key, data;
+ struct node *n, *nx;
struct question *q;
struct domain *sdomain;
@@ -645,30 +613,18 @@ dump_db(DB *db, FILE *of, char *zonename)
return -1;
}
- if (db->cursor(db, NULL, &cursor, 0) != 0) {
- dolog(LOG_INFO, "db->cursor: %s\n", strerror(errno));
- exit(1);
- }
-
memset(&key, 0, sizeof(key));
memset(&data, 0, sizeof(data));
- if (cursor->c_get(cursor, &key, &data, DB_FIRST) != 0) {
- dolog(LOG_INFO, "cursor->c_get: %s\n", strerror(errno));
- exit(1);
- }
-
-
j = 0;
- do {
-
- rs = data.size;
+ RB_FOREACH_SAFE(n, domaintree, &rbhead, nx) {
+ rs = n->datalen;
if ((sdomain = calloc(1, rs)) == NULL) {
dolog(LOG_INFO, "calloc: %s\n", strerror(errno));
exit(1);
}
- memcpy((char *)sdomain, (char *)data.data, data.size);
+ memcpy((char *)sdomain, (char *)n->data, n->datalen);
if (strcmp(sdomain->zonename, zonename) == 0)
continue;
@@ -680,7 +636,7 @@ dump_db(DB *db, FILE *of, char *zonename)
j++;
- } while (cursor->c_get(cursor, &key, &data, DB_NEXT) == 0);
+ }
fprintf(of, "}\n");
@@ -960,11 +916,9 @@ alg_to_rsa(int algorithm)
}
int
-calculate_rrsigs(DB *db, char *zonename, char *zsk_key, char *ksk_key, int expiry)
+calculate_rrsigs(ddDB *db, char *zonename, char *zsk_key, char *ksk_key, int expiry)
{
- DBT key, data;
- DBC *cursor;
-
+ struct node *n, *nx;
struct domain *sd;
int j, rs;
@@ -988,31 +942,16 @@ calculate_rrsigs(DB *db, char *zonename, char *zsk_key
expiredon = EXPIREDON;
#endif
- /* set cursor on database */
-
- if (db->cursor(db, NULL, &cursor, 0) != 0) {
- dolog(LOG_INFO, "db->cursor: %s\n", strerror(errno));
- exit(1);
- }
-
- memset(&key, 0, sizeof(key));
- memset(&data, 0, sizeof(data));
-
- if (cursor->c_get(cursor, &key, &data, DB_FIRST) != 0) {
- dolog(LOG_INFO, "cursor->c_get: %s\n", strerror(errno));
- exit(1);
- }
-
-
j = 0;
- do {
- rs = data.size;
+
+ RB_FOREACH_SAFE(n, domaintree, &rbhead, nx) {
+ rs = n->datalen;
if ((sd = calloc(1, rs)) == NULL) {
dolog(LOG_INFO, "calloc: %s\n", strerror(errno));
exit(1);
}
- memcpy((char *)sd, (char *)data.data, data.size);
+ memcpy((char *)sd, (char *)n->data, n->datalen);
if (sd->flags & DOMAIN_HAVE_DNSKEY)
if (sign_dnskey(db, zonename, zsk_key, ksk_key, expiry, sd) < 0) {
@@ -1096,7 +1035,7 @@ calculate_rrsigs(DB *db, char *zonename, char *zsk_key
}
j++;
- } while (cursor->c_get(cursor, &key, &data, DB_NEXT) == 0);
+ }
return 0;
@@ -1107,7 +1046,7 @@ calculate_rrsigs(DB *db, char *zonename, char *zsk_key
*/
int
-sign_soa(DB *db, char *zonename, char *zsk_key, int expiry, struct domain *sd)
+sign_soa(ddDB *db, char *zonename, char *zsk_key, int expiry, struct domain *sd)
{
struct domain_soa *sdsoa;
@@ -1338,7 +1277,7 @@ sign_soa(DB *db, char *zonename, char *zsk_key, int ex
*/
int
-sign_txt(DB *db, char *zonename, char *zsk_key, int expiry, struct domain *sd)
+sign_txt(ddDB *db, char *zonename, char *zsk_key, int expiry, struct domain *sd)
{
struct domain_txt *sdtxt;
@@ -1556,7 +1495,7 @@ sign_txt(DB *db, char *zonename, char *zsk_key, int ex
*/
int
-sign_aaaa(DB *db, char *zonename, char *zsk_key, int expiry, struct domain *sd)
+sign_aaaa(ddDB *db, char *zonename, char *zsk_key, int expiry, struct domain *sd)
{
struct domain_aaaa *sdaaaa;
@@ -1831,7 +1770,7 @@ sign_aaaa(DB *db, char *zonename, char *zsk_key, int e
*/
int
-sign_nsec3(DB *db, char *zonename, char *zsk_key, int expiry, struct domain *sd)
+sign_nsec3(ddDB *db, char *zonename, char *zsk_key, int expiry, struct domain *sd)
{
struct domain_nsec3 *sdnsec3;
@@ -2071,7 +2010,7 @@ sign_nsec3(DB *db, char *zonename, char *zsk_key, int
*/
int
-sign_nsec3param(DB *db, char *zonename, char *zsk_key, int expiry, struct domain *sd)
+sign_nsec3param(ddDB *db, char *zonename, char *zsk_key, int expiry, struct domain *sd)
{
struct domain_nsec3param *sdnsec3;
@@ -2302,7 +2241,7 @@ sign_nsec3param(DB *db, char *zonename, char *zsk_key,
*/
int
-sign_cname(DB *db, char *zonename, char *zsk_key, int expiry, struct domain *sd)
+sign_cname(ddDB *db, char *zonename, char *zsk_key, int expiry, struct domain *sd)
{
struct domain_cname *sdc;
@@ -2518,7 +2457,7 @@ sign_cname(DB *db, char *zonename, char *zsk_key, int
*/
int
-sign_ptr(DB *db, char *zonename, char *zsk_key, int expiry, struct domain *sd)
+sign_ptr(ddDB *db, char *zonename, char *zsk_key, int expiry, struct domain *sd)
{
struct domain_ptr *sdptr;
@@ -2734,7 +2673,7 @@ sign_ptr(DB *db, char *zonename, char *zsk_key, int ex
*/
int
-sign_naptr(DB *db, char *zonename, char *zsk_key, int expiry, struct domain *sd)
+sign_naptr(ddDB *db, char *zonename, char *zsk_key, int expiry, struct domain *sd)
{
struct domain_naptr *sdnaptr;
@@ -3030,7 +2969,7 @@ sign_naptr(DB *db, char *zonename, char *zsk_key, int
*/
int
-sign_srv(DB *db, char *zonename, char *zsk_key, int expiry, struct domain *sd)
+sign_srv(ddDB *db, char *zonename, char *zsk_key, int expiry, struct domain *sd)
{
struct domain_srv *sdsrv;
@@ -3314,7 +3253,7 @@ sign_srv(DB *db, char *zonename, char *zsk_key, int ex
*/
int
-sign_sshfp(DB *db, char *zonename, char *zsk_key, int expiry, struct domain *sd)
+sign_sshfp(ddDB *db, char *zonename, char *zsk_key, int expiry, struct domain *sd)
{
struct domain_sshfp *sdsshfp;
@@ -3594,7 +3533,7 @@ sign_sshfp(DB *db, char *zonename, char *zsk_key, int
*/
int
-sign_tlsa(DB *db, char *zonename, char *zsk_key, int expiry, struct domain *sd)
+sign_tlsa(ddDB *db, char *zonename, char *zsk_key, int expiry, struct domain *sd)
{
struct domain_tlsa *sdtlsa;
@@ -3876,7 +3815,7 @@ sign_tlsa(DB *db, char *zonename, char *zsk_key, int e
*/
int
-sign_ds(DB *db, char *zonename, char *zsk_key, int expiry, struct domain *sd)
+sign_ds(ddDB *db, char *zonename, char *zsk_key, int expiry, struct domain *sd)
{
struct domain_ds *sdds;
@@ -4158,7 +4097,7 @@ sign_ds(DB *db, char *zonename, char *zsk_key, int exp
*/
int
-sign_ns(DB *db, char *zonename, char *zsk_key, int expiry, struct domain *sd)
+sign_ns(ddDB *db, char *zonename, char *zsk_key, int expiry, struct domain *sd)
{
struct domain_ns *sdns;
@@ -4433,7 +4372,7 @@ sign_ns(DB *db, char *zonename, char *zsk_key, int exp
*/
int
-sign_mx(DB *db, char *zonename, char *zsk_key, int expiry, struct domain *sd)
+sign_mx(ddDB *db, char *zonename, char *zsk_key, int expiry, struct domain *sd)
{
struct domain_mx *sdmx;
@@ -4711,7 +4650,7 @@ sign_mx(DB *db, char *zonename, char *zsk_key, int exp
*/
int
-sign_a(DB *db, char *zonename, char *zsk_key, int expiry, struct domain *sd)
+sign_a(ddDB *db, char *zonename, char *zsk_key, int expiry, struct domain *sd)
{
struct domain_a *sda;
@@ -4982,7 +4921,7 @@ sign_a(DB *db, char *zonename, char *zsk_key, int expi
}
int
-create_ds(DB *db, char *zonename, char *ksk_key)
+create_ds(ddDB *db, char *zonename, char *ksk_key)
{
FILE *f;
@@ -5182,7 +5121,7 @@ create_ds(DB *db, char *zonename, char *ksk_key)
*/
int
-sign_dnskey(DB *db, char *zonename, char *zsk_key, char *ksk_key, int expiry, struct domain *sd)
+sign_dnskey(ddDB *db, char *zonename, char *zsk_key, char *ksk_key, int expiry, struct domain *sd)
{
struct domain_dnskey *sddk;
@@ -5873,20 +5812,13 @@ timethuman(time_t timet)
}
int
-construct_nsec3(DB *db, char *zone, int iterations, char *salt)
+construct_nsec3(ddDB *db, char *zone, int iterations, char *salt)
{
+ struct node *n, *nx;
- DBT key, data;
- DBC *cursor;
-
struct domain *sd;
struct question *q;
-#if 0
- struct domain_rrsig *sdrr;
- struct domain_dnskey *sddk;
- struct rrsig *rss;
- int len;
-#endif
+
struct nsec3param n3p;
struct domain_nsec3param *sdn3p;
@@ -5946,32 +5878,16 @@ construct_nsec3(DB *db, char *zone, int iterations, ch
n3p.saltlen = sdn3p->nsec3param.saltlen;
memcpy(&n3p.salt, sdn3p->nsec3param.salt, n3p.saltlen);
- /* set cursor on database */
-
- if (db->cursor(db, NULL, &cursor, 0) != 0) {
- dolog(LOG_INFO, "db->cursor: %s\n", strerror(errno));
- exit(1);
- }
-
- memset(&key, 0, sizeof(key));
- memset(&data, 0, sizeof(data));
-
- if (cursor->c_get(cursor, &key, &data, DB_FIRST) != 0) {
- dolog(LOG_INFO, "cursor->c_get: %s\n", strerror(errno));
- exit(1);
- }
-
-
j = 0;
- do {
-
- rs = data.size;
+
+ RB_FOREACH_SAFE(n, domaintree, &rbhead, nx) {
+ rs = n->datalen;
if ((sd = calloc(1, rs)) == NULL) {
dolog(LOG_INFO, "calloc: %s\n", strerror(errno));
exit(1);
}
- memcpy((char *)sd, (char *)data.data, data.size);
+ memcpy((char *)sd, (char *)n->data, n->datalen);
hashname = hash_name(sd->zone, sd->zonelen, &n3p);
@@ -6052,7 +5968,7 @@ construct_nsec3(DB *db, char *zone, int iterations, ch
TAILQ_INSERT_TAIL(&head, n1, entries);
}
- } while (cursor->c_get(cursor, &key, &data, DB_NEXT) == 0);
+ } /* RB_FOREACH_SAFE */
TAILQ_FOREACH(n2, &head, entries) {
np = TAILQ_NEXT(n2, entries);
@@ -6772,13 +6688,12 @@ usage(void)
}
void
-cleanup(DB *db, char *tmpdir)
+cleanup(ddDB *db, char *tmpdir)
{
DIR *dirp;
struct dirent *dp;
struct stat sb;
- db->close(db, 0);
if (chdir(tmpdir) < 0) {
return;
}
blob - 77d319010d2d59484289461a9823c0295c2940b0
blob + 5a3b9a4324e30c1512e036c1695c53c879073372
--- ddd-db.h
+++ ddd-db.h
@@ -28,6 +28,9 @@
#ifndef _DB_H
#define _DB_H
+#include <sys/types.h>
+#include <limits.h>
+
#define CONFFILE "/etc/delphinusdns.conf"
#define DEFAULT_SOCKET 64
@@ -431,6 +434,43 @@ struct logging {
char *logpasswd;
};
+
+typedef struct {
+ size_t size;
+ char *data;
+} ddDBT;
+
+typedef struct __dddb {
+ int (*put)(struct __dddb *, ddDBT *, ddDBT *);
+ int (*get)(struct __dddb *, ddDBT *, ddDBT *);
+ int (*close)(struct __dddb *);
+ int (*remove)(struct __dddb *, ddDBT *);
+ size_t offset;
+ size_t size;
+ char *nodes;
+} ddDB;
+
+
+#define SIZENODE ( sizeof(struct domain) + sizeof(struct domain_soa) + \
+ sizeof(struct domain_rrsig) + sizeof(struct domain_a) + \
+ sizeof(struct domain_aaaa) + sizeof(struct domain_mx) + \
+ sizeof(struct domain_ns) + sizeof(struct domain_cname) + \
+ sizeof(struct domain_ptr) + sizeof(struct domain_txt) + \
+ sizeof(struct domain_srv) + sizeof(struct domain_sshfp) + \
+ sizeof(struct domain_tlsa) + sizeof(struct domain_naptr) + \
+ sizeof(struct domain_dnskey) + sizeof(struct domain_nsec) + \
+ sizeof(struct domain_nsec3) + \
+ sizeof(struct domain_nsec3param) + sizeof(struct domain_ds) )
+
+struct node {
+ RB_ENTRY(node) entry; /* the node entry */
+ char domainname[256]; /* domain name key name */
+ int len; /* length of domain name */
+ char *data; /* data it points to */
+ size_t datalen; /* the length of the data */
+};
+
+
struct cfg {
int udp[DEFAULT_SOCKET]; /* udp sockets */
int tcp[DEFAULT_SOCKET]; /* tcp socket */
@@ -439,12 +479,19 @@ struct cfg {
int recurse; /* recurse socket */
int log; /* logging socket */
int sockcount; /* set sockets */
- DB *db; /* database */
+ ddDB *db; /* database */
};
+
-
-int parse_file(DB *db, char *);
-DB * opendatabase(DB *);
+ddDB * dddbopen(void);
+int dddbget(ddDB *, ddDBT *, ddDBT *);
+int dddbput(ddDB *, ddDBT *, ddDBT *);
+int dddbclose(ddDB *);
+
+#define DDDB_NOTFOUND (-1)
+
+int parse_file(ddDB *db, char *);
+ddDB * opendatabase(ddDB *);
#endif /* _DB_H */
blob - d9fcf1c47f3b7d3e156a640716fe78021489f411
blob + 4315ff122b1dc51f9e885033e1a6acd07fd65ba3
--- ddd-include.h
+++ ddd-include.h
@@ -37,6 +37,12 @@
#include <sys/queue.h>
#include <sys/mman.h>
#include <sys/wait.h>
+#if __linux__
+#define __unused
+#include <bsd/sys/tree.h>
+#else
+#include <sys/tree.h>
+#endif
#include <net/if.h>
@@ -60,7 +66,6 @@
#include <errno.h>
#include <syslog.h>
#include <ctype.h>
-#include <db.h>
#include <pwd.h>
#include <ifaddrs.h>
#include <dirent.h>
blob - 02a8a2ef05a7cacbfd9c69470d30195cceddbb77
blob + de5213bdfc502b8ef7cb8d2f5cff6cec4415a309
--- delphinusdnsd/Makefile.freebsd
+++ delphinusdnsd/Makefile.freebsd
@@ -2,13 +2,12 @@
PROG=delphinusdnsd
-SRCS=delphinusdnsd.c parse.y reply.c additional.c region.c log.c axfr.c filter.c ratelimit.c whitelist.c base64.c dnssec.c util.c ent.c
+SRCS=delphinusdnsd.c parse.y reply.c additional.c region.c log.c axfr.c filter.c ratelimit.c whitelist.c base64.c dnssec.c util.c ent.c db.c
-#CFLAGS= -DDEBUG -g -Wall
-CFLAGS= -Wall -g -I/usr/local/include/db5
+CFLAGS= -Wall -g
CFLAGS+= -I${.CURDIR}/..
-LDFLAGS= -Wall -g -L/usr/local/lib/db5
-LDADD= -lcrypto -lssl -ldb
+LDFLAGS= -Wall -g
+LDADD= -lcrypto -lssl
LDLIBS=
OBJDIR=.
blob - c732666951c6106e293f3c087d07c0629e79d386
blob + 1d3e38e3a31e87480893931facd974702d8ca83a
--- delphinusdnsd/Makefile.netbsd
+++ delphinusdnsd/Makefile.netbsd
@@ -2,12 +2,12 @@
PROG=delphinusdnsd
-SRCS=delphinusdnsd.c parse.y reply.c additional.c region.c log.c axfr.c filter.c ratelimit.c whitelist.c base64.c dnssec.c util.c ent.c
+SRCS=delphinusdnsd.c parse.y reply.c additional.c region.c log.c axfr.c filter.c ratelimit.c whitelist.c base64.c dnssec.c util.c ent.c db.c
-CFLAGS= -g -I/usr/pkg/include/db5/
+CFLAGS= -g
CFLAGS+= -I${.CURDIR}/..
LDFLAGS= -g -L/usr/pkg/lib -R/usr/pkg/lib
-LDADD= -lcrypto -lssl -ldb5
+LDADD= -lcrypto -lssl
OBJDIR=.
blob - 126bd636ecd133c0b5fabad7a3f50911deb17af5
blob + 572e2c896ddc49d59dbecf3feacf7c74609388d4
--- delphinusdnsd/Makefile.openbsd
+++ delphinusdnsd/Makefile.openbsd
@@ -2,13 +2,13 @@
PROG=delphinusdnsd
-SRCS=delphinusdnsd.c parse.y reply.c additional.c region.c log.c axfr.c filter.c ratelimit.c whitelist.c base64.c dnssec.c util.c ent.c
+SRCS=delphinusdnsd.c parse.y reply.c additional.c region.c log.c axfr.c filter.c ratelimit.c whitelist.c base64.c dnssec.c util.c ent.c db.c
#CFLAGS= -DDEBUG -g -Wall
-CFLAGS= -Wall -g -I/usr/local/include/db4
+CFLAGS= -Wall -g
CFLAGS+= -I${.CURDIR}/..
-LDFLAGS= -Wall -g -L/usr/local/lib/db4
-LDADD= -lcrypto -lssl -ldb
+LDFLAGS= -Wall -g
+LDADD= -lcrypto -lssl
LDLIBS=
OBJDIR=.
blob - ebf32d26911bf13fce62d4a2e99cbe54ae6062c6
blob + 5a52ae914baad43252753fc01cc7a9daa3ea1a79
--- delphinusdnsd.c
+++ delphinusdnsd.c
@@ -33,7 +33,7 @@
/* prototypes */
extern void add_rrlimit(int, u_int16_t *, int, char *);
-extern void axfrloop(int *, int, char **, DB *);
+extern void axfrloop(int *, int, char **, ddDB *);
extern struct question *build_fake_question(char *, int, u_int16_t);
extern int check_ent(char *, int);
extern int check_rrlimit(int, u_int16_t *, int, char *);
@@ -48,59 +48,59 @@ extern char * get_dns_type(int, int);
extern void init_dnssec(void);
extern void init_recurse(void);
extern void init_region(void);
-extern int init_entlist(DB *);
+extern int init_entlist(ddDB *);
extern void init_filter(void);
extern void init_notifyslave(void);
extern void init_whitelist(void);
-extern struct domain * lookup_zone(DB *, struct question *, int *, int *, char *);
+extern struct domain * lookup_zone(ddDB *, struct question *, int *, int *, char *);
extern int memcasecmp(u_char *, u_char *, int);
-extern void recurseloop(int sp, int *, DB *);
+extern void recurseloop(int sp, int *, ddDB *);
extern void receivelog(char *, int);
-extern int reply_a(struct sreply *, DB *);
-extern int reply_aaaa(struct sreply *, DB *);
+extern int reply_a(struct sreply *, ddDB *);
+extern int reply_aaaa(struct sreply *, ddDB *);
extern int reply_any(struct sreply *);
extern int reply_badvers(struct sreply *);
extern int reply_nodata(struct sreply *);
extern int reply_cname(struct sreply *);
extern int reply_fmterror(struct sreply *);
extern int reply_notimpl(struct sreply *);
-extern int reply_nxdomain(struct sreply *, DB *);
-extern int reply_noerror(struct sreply *, DB *);
+extern int reply_nxdomain(struct sreply *, ddDB *);
+extern int reply_noerror(struct sreply *, ddDB *);
extern int reply_soa(struct sreply *);
-extern int reply_mx(struct sreply *, DB *);
-extern int reply_naptr(struct sreply *, DB *);
-extern int reply_ns(struct sreply *, DB *);
+extern int reply_mx(struct sreply *, ddDB *);
+extern int reply_naptr(struct sreply *, ddDB *);
+extern int reply_ns(struct sreply *, ddDB *);
extern int reply_ptr(struct sreply *);
extern int reply_refused(struct sreply *);
-extern int reply_srv(struct sreply *, DB *);
+extern int reply_srv(struct sreply *, ddDB *);
extern int reply_sshfp(struct sreply *);
extern int reply_tlsa(struct sreply *);
extern int reply_txt(struct sreply *);
extern int reply_version(struct sreply *);
-extern int reply_rrsig(struct sreply *, DB *);
+extern int reply_rrsig(struct sreply *, ddDB *);
extern int reply_dnskey(struct sreply *);
extern int reply_ds(struct sreply *);
extern int reply_nsec(struct sreply *);
-extern int reply_nsec3(struct sreply *, DB *);
+extern int reply_nsec3(struct sreply *, ddDB *);
extern int reply_nsec3param(struct sreply *);
extern int remotelog(int, char *, ...);
extern char *rrlimit_setup(int);
extern char *dns_label(char *, int *);
extern void slave_shutdown(void);
-extern int get_record_size(DB *, char *, int);
+extern int get_record_size(ddDB *, char *, int);
extern void * find_substruct(struct domain *, u_int16_t);
struct question *build_question(char *, int, int);
void build_reply(struct sreply *, int, char *, int, struct question *, struct sockaddr *, socklen_t, struct domain *, struct domain *, u_int8_t, int, int, struct recurses *, char *);
int compress_label(u_char *, u_int16_t, int);
int free_question(struct question *);
-struct domain * get_soa(DB *, struct question *);
+struct domain * get_soa(ddDB *, struct question *);
int lookup_type(int);
void mainloop(struct cfg *);
void master_reload(int);
void master_shutdown(int);
void recurseheader(struct srecurseheader *, int, struct sockaddr_storage *, struct sockaddr_storage *, int);
-void setup_master(DB *, DB_ENV *, char **);
+void setup_master(ddDB *, char **);
void slave_signal(int);
/* aliases */
@@ -125,8 +125,6 @@ extern int dnssec;
static int reload = 0;
static int mshutdown = 0;
static int msig;
-static char *database;
-static char mydatabase[512];
static char *rptr;
static int ratelimit_backlog;
@@ -169,7 +167,7 @@ static struct tcps {
} *tn1, *tnp, *tntmp;
-static const char rcsid[] = "$Id: delphinusdnsd.c,v 1.10 2017/03/14 08:23:09 pjp Exp $";
+static const char rcsid[] = "$Id: delphinusdnsd.c,v 1.11 2017/06/26 20:28:50 pjp Exp $";
/*
* MAIN - set up arguments, set up database, set up sockets, call mainloop
@@ -184,11 +182,11 @@ main(int argc, char *argv[])
static int afd[DEFAULT_SOCKET];
static int uafd[DEFAULT_SOCKET];
int lfd = -1;
- int fd, n;
+ int n;
int ch, i, j;
int gai_error;
- int salen, ret;
+ int salen;
int found = 0;
int on = 1;
@@ -206,11 +204,8 @@ main(int argc, char *argv[])
struct sockaddr_in6 *sin6;
struct cfg *cfg;
- static DB_ENV *dbenv;
- static DB *db;
+ static ddDB *db;
- key_t key;
-
if (geteuid() != 0) {
fprintf(stderr, "must be started as root\n"); /* .. dolt */
exit(1);
@@ -306,89 +301,15 @@ main(int argc, char *argv[])
*ptr = 0;
- if ((ret = db_env_create(&dbenv, 0)) != 0) {
- dolog(LOG_INFO, "db_env_create: %s\n", db_strerror(ret));
- slave_shutdown();
- exit(1);
- }
+ /* open internal database */
- key = ftok("/usr/local/sbin/delphinusdnsd", 1);
- if (key == (key_t)-1) {
- dolog(LOG_INFO, "ftok failed, does /usr/local/sbin/delphinusdnsd exist?\n");
+ db = dddbopen();
+ if (db == NULL) {
+ dolog(LOG_INFO, "dddbopen() failed\n");
slave_shutdown();
exit(1);
}
-
- if ((ret = dbenv->set_shm_key(dbenv, key)) != 0) {
- dolog(LOG_INFO, "dbenv->set_shm_key failed\n");
- slave_shutdown();
- exit(1);
- }
-
- /* set cache size , if requested */
-
- if (cachesize) {
- if ((ret = dbenv->set_cachesize(dbenv, 0, cachesize, 0)) != 0) {
- dolog(LOG_INFO, "dbenv->set_cachesize: %s\n",
- db_strerror(ret));
- slave_shutdown();
- exit(1);
- }
- }
-
- (void)mkdir(MYDB_PATH, 0700);
- snprintf(mydatabase, sizeof(mydatabase), "%s/%ld",
- MYDB_PATH, (long)getpid());
-
- if (mkdir(mydatabase, 0750) < 0) {
- if (errno != EEXIST) {
- dolog(LOG_ERR, "mkdir: %s\n", strerror(errno));
- exit(1);
- }
- }
-
- if ((ret = dbenv->open(dbenv, mydatabase, DB_CREATE | \
- DB_INIT_LOCK | DB_INIT_MPOOL | DB_SYSTEM_MEM, \
- S_IRUSR | S_IWUSR)) != 0) {
- dolog(LOG_INFO, "dbenv->open failed: %s\n", db_strerror(ret));
- slave_shutdown();
- exit(1);
- }
-
- if (db_create((DB **)&db, (DB_ENV *)dbenv, 0) != 0) {
- dolog(LOG_INFO, "db_create: %s\n", strerror(errno));
- slave_shutdown();
- exit(1);
- }
-
- /*
- * we want to run multiple instances of different versions so we'll
- * make a temporary database...
- */
-
-
- snprintf(mydatabase, sizeof(mydatabase), "%s/%ld/ddd.db",
- MYDB_PATH, (long)getpid());
-
- (void)unlink(mydatabase);
-
- database = mydatabase;
-
-
- fd = open(database, O_WRONLY | O_CREAT, 0600);
- if (fd < 0) {
- dolog(LOG_INFO, "open: %s\n", strerror(errno));
- }
- close(fd);
-
- if (db->open(db, NULL, database, NULL, DB_BTREE, DB_CREATE, 0600) != 0) {
- dolog(LOG_INFO, "db->open: %s\n", strerror(errno));
- db->close(db, DB_NOSYNC);
- slave_shutdown();
- exit(1);
- }
-
/* make a master program that holds the pidfile, boss of ... eek */
pid = fork();
@@ -399,7 +320,7 @@ main(int argc, char *argv[])
case 0:
break;
default:
- setup_master(db, dbenv, av);
+ setup_master(db, av);
/* NOTREACHED */
exit(1);
}
@@ -1459,7 +1380,7 @@ out:
*/
struct domain *
-get_soa(DB *db, struct question *question)
+get_soa(ddDB *db, struct question *question)
{
struct domain *sd = NULL;
@@ -1467,7 +1388,7 @@ get_soa(DB *db, struct question *question)
int ret = 0;
int rs;
- DBT key, data;
+ ddDBT key, data;
char *p;
@@ -1494,7 +1415,7 @@ get_soa(DB *db, struct question *question)
data.data = NULL;
data.size = rs;
- ret = db->get(db, NULL, &key, &data, 0);
+ ret = db->get(db, &key, &data);
if (ret != 0) {
plen -= (*p + 1);
p = (p + (*p + 1));
@@ -3114,12 +3035,12 @@ recurseheader(struct srecurseheader *rh, int proto, st
*/
void
-setup_master(DB *db, DB_ENV *dbenv, char **av)
+setup_master(ddDB *db, char **av)
{
- DB *destroy;
+ //ddDB *destroy;
char buf[512];
pid_t pid;
- int fd, ret;
+ int fd;
#if !defined __APPLE__
setproctitle("delphinusdnsd master");
@@ -3155,20 +3076,7 @@ setup_master(DB *db, DB_ENV *dbenv, char **av)
if (mshutdown) {
dolog(LOG_INFO, "shutting down on signal %d\n", msig);
unlink(PIDFILE);
- db->close(db, 0);
-
- if (db_create((DB **)&destroy, (DB_ENV *)dbenv, 0) != 0) {
- dolog(LOG_INFO, "db_create: %s\n", strerror(errno));
- }
-
- ret = destroy->remove(destroy, database, NULL, 0);
- if (ret != 0) {
- dolog(LOG_INFO, "db->remove: %s\n", db_strerror(ret));
- }
-
- dbenv->close(dbenv, 0);
-
/* clean up our database */
pid = getpid();
snprintf(buf, sizeof(buf), "%s/%lu/__db.001", MYDB_PATH,
@@ -3196,18 +3104,6 @@ setup_master(DB *db, DB_ENV *dbenv, char **av)
}
unlink(PIDFILE);
- db->close(db, 0);
-
- if (db_create((DB **)&destroy, (DB_ENV *)dbenv, 0) != 0) {
- dolog(LOG_INFO, "db_create: %s\n", strerror(errno));
- }
-
- ret = destroy->remove(destroy, database, NULL, 0);
- if (ret != 0) {
- dolog(LOG_INFO, "db->remove: %s\n", db_strerror(ret));
- }
-
- dbenv->close(dbenv, 0);
/* clean up our database */
pid = getpid();
blob - ea0adaaaa1c4a07f71a7fb3cc114bbcc07ef1da7
blob + edf816a46b2fc6ba6c86dda43c87b722a2decae0
--- dnssec.c
+++ dnssec.c
@@ -39,25 +39,25 @@ int insert_nsec3(char *zonename, char *domainname, cha
char * find_next_closer_nsec3(char *zonename, int zonelen, char *hashname);
char * find_match_nsec3(char *zonename, int zonelen, char *hashname);
char * find_match_nsec3_ent(char *zonename, int zonelen, char *hashname);
-struct domain * find_nsec(char *name, int namelen, struct domain *sd, DB *db);
-struct domain * find_nsec3_match_qname(char *name, int namelen, struct domain *sd, DB *db);
-struct domain * find_nsec3_match_closest(char *name, int namelen, struct domain *sd, DB *db);
-struct domain * find_nsec3_wildcard_closest(char *name, int namelen, struct domain *sd, DB *db);
+struct domain * find_nsec(char *name, int namelen, struct domain *sd, ddDB *db);
+struct domain * find_nsec3_match_qname(char *name, int namelen, struct domain *sd, ddDB *db);
+struct domain * find_nsec3_match_closest(char *name, int namelen, struct domain *sd, ddDB *db);
+struct domain * find_nsec3_wildcard_closest(char *name, int namelen, struct domain *sd, ddDB *db);
char * convert_name(char *name, int namelen);
int nsec_comp(const void *a, const void *b);
int nsec3_comp(const void *a, const void *b);
int count_dots(char *name);
-struct domain * find_closest_encloser(DB *db, char *name, int namelen);
+struct domain * find_closest_encloser(ddDB *db, char *name, int namelen);
char * find_next_closer_name(char *, int, char *, int, int *);
char * hash_name(char *name, int len, struct nsec3param *n3p);
char * base32hex_encode(u_char *input, int len);
int base32hex_decode(u_char *, u_char *);
void mysetbit(u_char *, int);
-extern int get_record_size(DB *, char *, int);
+extern int get_record_size(ddDB *, char *, int);
extern char * dns_label(char *, int *);
extern void dolog(int, char *, ...);
-extern int checklabel(DB *, struct domain *, struct domain *, struct question *);
+extern int checklabel(ddDB *, struct domain *, struct domain *, struct question *);
extern struct question *build_fake_question(char *, int, u_int16_t);
extern int free_question(struct question *);
extern void * find_substruct(struct domain *, u_int16_t);
@@ -292,9 +292,9 @@ find_match_nsec3(char *zonename, int zonelen, char *ha
/* FIND_NSEC */
/* finds the right nsec domainname in a zone */
struct domain *
-find_nsec(char *name, int namelen, struct domain *sd, DB *db)
+find_nsec(char *name, int namelen, struct domain *sd, ddDB *db)
{
- DBT key, data;
+ ddDBT key, data;
char *table, *tmp;
char *nsecname;
struct domainnames {
@@ -356,7 +356,7 @@ find_nsec(char *name, int namelen, struct domain *sd,
data.data = NULL;
data.size = rs;
- ret = db->get(db, NULL, &key, &data, 0);
+ ret = db->get(db, &key, &data);
if (ret != 0) {
free (nsecname);
free (humanname);
@@ -424,7 +424,7 @@ find_nsec(char *name, int namelen, struct domain *sd,
data.data = NULL;
data.size = rs;
- ret = db->get(db, NULL, &key, &data, 0);
+ ret = db->get(db, &key, &data);
if (ret != 0) {
free (humanname);
free (table);
@@ -498,7 +498,7 @@ find_nsec(char *name, int namelen, struct domain *sd,
data.data = NULL;
data.size = rs;
- ret = db->get(db, NULL, &key, &data, 0);
+ ret = db->get(db, &key, &data);
if (ret != 0) {
free (backname);
free (sd0);
@@ -667,7 +667,7 @@ find_next_closer_name(char *qname, int qlen, char *clo
*/
struct domain *
-find_closest_encloser(DB *db, char *name, int namelen)
+find_closest_encloser(ddDB *db, char *name, int namelen)
{
struct domain *sd = NULL;
@@ -675,7 +675,7 @@ find_closest_encloser(DB *db, char *name, int namelen)
int ret = 0;
int rs;
- DBT key, data;
+ ddDBT key, data;
char *p;
@@ -706,7 +706,7 @@ find_closest_encloser(DB *db, char *name, int namelen)
data.data = NULL;
data.size = rs;
- ret = db->get(db, NULL, &key, &data, 0);
+ ret = db->get(db, &key, &data);
if (ret != 0) {
plen -= (*p + 1);
p = (p + (*p + 1));
@@ -929,9 +929,9 @@ base32hex_encode(u_char *input, int len)
*/
struct domain *
-find_nsec3_match_closest(char *name, int namelen, struct domain *sd, DB *db)
+find_nsec3_match_closest(char *name, int namelen, struct domain *sd, ddDB *db)
{
- DBT key, data;
+ ddDBT key, data;
char *hashname;
char *backname;
@@ -999,7 +999,7 @@ find_nsec3_match_closest(char *name, int namelen, stru
data.data = NULL;
data.size = rs;
- ret = db->get(db, NULL, &key, &data, 0);
+ ret = db->get(db, &key, &data);
if (ret != 0) {
free (backname);
free (sd0);
@@ -1021,9 +1021,9 @@ find_nsec3_match_closest(char *name, int namelen, stru
*
*/
struct domain *
-find_nsec3_wildcard_closest(char *name, int namelen, struct domain *sd, DB *db)
+find_nsec3_wildcard_closest(char *name, int namelen, struct domain *sd, ddDB *db)
{
- DBT key, data;
+ ddDBT key, data;
char *hashname;
char *backname;
@@ -1094,7 +1094,7 @@ find_nsec3_wildcard_closest(char *name, int namelen, s
data.data = NULL;
data.size = rs;
- ret = db->get(db, NULL, &key, &data, 0);
+ ret = db->get(db, &key, &data);
if (ret != 0) {
free (backname);
free (sd0);
@@ -1116,9 +1116,9 @@ find_nsec3_wildcard_closest(char *name, int namelen, s
*
*/
struct domain *
-find_nsec3_cover_next_closer(char *name, int namelen, struct domain *sd, DB *db)
+find_nsec3_cover_next_closer(char *name, int namelen, struct domain *sd, ddDB *db)
{
- DBT key, data;
+ ddDBT key, data;
char *hashname;
char *backname;
@@ -1189,7 +1189,7 @@ find_nsec3_cover_next_closer(char *name, int namelen,
data.data = NULL;
data.size = rs;
- ret = db->get(db, NULL, &key, &data, 0);
+ ret = db->get(db, &key, &data);
if (ret != 0) {
free (backname);
free (sd0);
@@ -1213,9 +1213,9 @@ find_nsec3_cover_next_closer(char *name, int namelen,
*/
struct domain *
-find_nsec3_match_qname(char *name, int namelen, struct domain *sd, DB *db)
+find_nsec3_match_qname(char *name, int namelen, struct domain *sd, ddDB *db)
{
- DBT key, data;
+ ddDBT key, data;
char *hashname;
char *backname;
@@ -1275,7 +1275,7 @@ find_nsec3_match_qname(char *name, int namelen, struct
data.data = NULL;
data.size = rs;
- ret = db->get(db, NULL, &key, &data, 0);
+ ret = db->get(db, &key, &data);
if (ret != 0) {
free (backname);
free (sd0);
blob - fb919c0498d075b2efe1776fce15b31b6a13532a
blob + 57986c4a072a8f7279e83c01ca917eddba656031
--- ent.c
+++ ent.c
@@ -34,7 +34,7 @@
#include "ddd-dns.h"
#include "ddd-db.h"
-int init_entlist(DB *);
+int init_entlist(ddDB *);
int check_ent(char *, int);
static int ent_contains(char *, int, char *, int);
@@ -45,6 +45,7 @@ extern int debug, verbose;
SLIST_HEAD(listhead, ententry) enthead;
+
static struct ententry {
char *name;
int len;
@@ -53,40 +54,44 @@ static struct ententry {
} *ent2, *entp;
-static const char rcsid[] = "$Id: ent.c,v 1.1 2017/01/09 14:26:50 pjp Exp $";
+static const char rcsid[] = "$Id: ent.c,v 1.2 2017/06/26 20:28:50 pjp Exp $";
+
+#if 0
+int
+domaincmp(struct node *e1, struct node *e2)
+{
+ if (e1->len < e2->len)
+ return -1;
+ else if (e1->len > e2->len)
+ return 1;
+ else {
+ return (memcmp(e1->domainname, e2->domainname, e1->len));
+ }
+}
+#endif
+
+extern int domaincmp(struct node *e1, struct node *e2);
+
+
+RB_HEAD(domaintree, node) rbhead;
+RB_PROTOTYPE_STATIC(domaintree, node, entry, domaincmp)
+RB_GENERATE_STATIC(domaintree, node, entry, domaincmp)
+
/*
* INIT_ENTLIST - initialize the ent singly linked list
*/
int
-init_entlist(DB *db)
+init_entlist(ddDB *db)
{
- DBT key, data;
- DBC *cursor;
+ struct node *n, *nx;
struct domain *sd = NULL;
- int curs;
SLIST_INIT(&enthead);
- if (db->cursor(db, NULL, &cursor, 0) != 0) {
- dolog(LOG_INFO, "db->cursor: %s\n", strerror(errno));
- return -1;
- }
-
- memset(&key, 0, sizeof(key));
- memset(&data, 0, sizeof(data));
-
- /* herd all ENT candidates into our ent-list */
- curs = cursor->c_get(cursor, &key, &data, DB_FIRST);
- do {
-
- if (curs != 0) {
- dolog(LOG_INFO, "cursor->c_get: %s\n", strerror(errno));
- return -1;
- }
-
- sd = (struct domain *)data.data;
+ RB_FOREACH_SAFE(n, domaintree, &rbhead, nx) {
+ sd = (struct domain *)n->data;
ent2 = malloc(sizeof(struct ententry));
if (ent2 == NULL) {
dolog(LOG_INFO, "malloc: %s\n", strerror(errno));
@@ -105,11 +110,7 @@ init_entlist(DB *db)
ent2->flags = sd->flags;
SLIST_INSERT_HEAD(&enthead, ent2, ent_entry);
-
- memset(&key, 0, sizeof(key));
- memset(&data, 0, sizeof(data));
-
- } while ((curs = cursor->c_get(cursor, &key, &data, DB_NEXT)) == 0);
+ }
return 0;
blob - 026f5e33ea22ade44674ec5d1bd9e3b870d75736
blob + 06b965ace6090cc29286cbeade61eb408bc78458
--- parse.y
+++ parse.y
@@ -40,7 +40,7 @@ extern int insert_whitelist(char *, char *);
extern void slave_shutdown(void);
extern int mybase64_encode(u_char const *, size_t, char *, size_t);
extern int mybase64_decode(char const *, u_char *, size_t);
-extern int get_record_size(DB *, char *, int);
+extern int get_record_size(ddDB *, char *, int);
extern void * find_substruct(struct domain *, u_int16_t);
void yyerror(const char *);
@@ -103,12 +103,12 @@ typedef struct {
#define YYSTYPE_IS_DECLARED 1
#endif
-static const char rcsid[] = "$Id: parse.y,v 1.44 2017/03/14 08:23:09 pjp Exp $";
+static const char rcsid[] = "$Id: parse.y,v 1.45 2017/06/26 20:28:50 pjp Exp $";
static int version = 0;
static int state = 0;
static uint8_t region = 0;
static uint64_t confstatus = 0;
-static DB *mydb;
+static ddDB *mydb;
static char *current_zone = NULL;
YYSTYPE yylval;
@@ -116,7 +116,7 @@ YYSTYPE yylval;
char *converted_name;
int converted_namelen;
-DBT key, data;
+ddDBT key, data;
struct logging logging;
int axfrport = 0;
time_t time_changed;
@@ -153,7 +153,7 @@ int hex2bin(char *, int, char *);
int lgetc(int);
struct tab * lookup(struct tab *, char *);
int lungetc(int);
-int parse_file(DB *, char *);
+int parse_file(ddDB *, char *);
struct file *pushfile(const char *, int);
int popfile(void);
struct rrtab *rrlookup(char *);
@@ -1222,7 +1222,7 @@ yywrap()
}
int
-parse_file(DB *db, char *filename)
+parse_file(ddDB *db, char *filename)
{
int errors;
@@ -1681,7 +1681,7 @@ check_rr(char *domainname, char *mytype, int itype, in
int
fill_cname(char *name, char *type, int myttl, char *hostname)
{
- DB *db = mydb;
+ ddDB *db = mydb;
void *sdomain, *tp;
struct domain *ssd;
struct domain_cname *ssd_cname;
@@ -1773,7 +1773,7 @@ fill_cname(char *name, char *type, int myttl, char *ho
int
fill_ptr(char *name, char *type, int myttl, char *hostname)
{
- DB *db = mydb;
+ ddDB *db = mydb;
void *sdomain, *tp;
struct domain *ssd;
struct domain_ptr *ssd_ptr;
@@ -1863,7 +1863,7 @@ fill_ptr(char *name, char *type, int myttl, char *host
int
fill_dnskey(char *name, char *type, u_int32_t myttl, u_int16_t flags, u_int8_t protocol, u_int8_t algorithm, char *pubkey)
{
- DB *db = mydb;
+ ddDB *db = mydb;
void *sdomain, *tp;
struct domain *ssd;
struct domain_dnskey *ssd_dnskey;
@@ -1950,7 +1950,7 @@ fill_dnskey(char *name, char *type, u_int32_t myttl, u
int
fill_rrsig(char *name, char *type, u_int32_t myttl, char *typecovered, u_int8_t algorithm, u_int8_t labels, u_int32_t original_ttl, u_int64_t sig_expiration, u_int64_t sig_inception, u_int16_t keytag, char *signers_name, char *signature)
{
- DB *db = mydb;
+ ddDB *db = mydb;
void *sdomain, *tp;
struct domain *ssd;
struct domain_rrsig *ssd_rrsig;
@@ -2099,7 +2099,7 @@ fill_rrsig(char *name, char *type, u_int32_t myttl, ch
int
fill_ds(char *name, char *type, u_int32_t myttl, u_int16_t keytag, u_int8_t algorithm, u_int8_t digesttype, char *digest)
{
- DB *db = mydb;
+ ddDB *db = mydb;
void *sdomain, *tp;
struct domain *ssd;
struct domain_ds *ssd_ds;
@@ -2188,7 +2188,7 @@ fill_ds(char *name, char *type, u_int32_t myttl, u_int
int
fill_nsec3(char *name, char *type, u_int32_t myttl, u_int8_t algorithm, u_int8_t flags, u_int16_t iterations, char *salt, char *nextname, char *bitmap)
{
- DB *db = mydb;
+ ddDB *db = mydb;
void *sdomain, *tp;
struct domain *ssd;
struct domain_nsec3 *ssd_nsec3;
@@ -2296,7 +2296,7 @@ fill_nsec3(char *name, char *type, u_int32_t myttl, u_
int
fill_nsec3param(char *name, char *type, u_int32_t myttl, u_int8_t algorithm, u_int8_t flags, u_int16_t iterations, char *salt)
{
- DB *db = mydb;
+ ddDB *db = mydb;
void *sdomain, *tp;
struct domain *ssd;
struct domain_nsec3param *ssd_nsec3param;
@@ -2383,7 +2383,7 @@ fill_nsec3param(char *name, char *type, u_int32_t mytt
int
fill_nsec(char *name, char *type, u_int32_t myttl, char *domainname, char *bitmap)
{
- DB *db = mydb;
+ ddDB *db = mydb;
void *sdomain, *tp;
struct domain *ssd;
struct domain_nsec *ssd_nsec;
@@ -2483,7 +2483,7 @@ fill_nsec(char *name, char *type, u_int32_t myttl, cha
int
fill_naptr(char *name, char *type, int myttl, int order, int preference, char *flags, char *services, char *regexp, char *replacement)
{
- DB *db = mydb;
+ ddDB *db = mydb;
void *sdomain, *tp;
struct domain *ssd;
struct domain_naptr *ssd_naptr;
@@ -2593,7 +2593,7 @@ fill_naptr(char *name, char *type, int myttl, int orde
int
fill_txt(char *name, char *type, int myttl, char *msg)
{
- DB *db = mydb;
+ ddDB *db = mydb;
void *sdomain, *tp;
struct domain *ssd;
struct domain_txt *ssd_txt;
@@ -2679,7 +2679,7 @@ fill_txt(char *name, char *type, int myttl, char *msg)
int
fill_tlsa(char *name, char *type, int myttl, uint8_t usage, uint8_t selector, uint8_t matchtype, char *data)
{
- DB *db = mydb;
+ ddDB *db = mydb;
void *sdomain, *tp;
struct domain *ssd;
struct domain_tlsa *ssd_tlsa;
@@ -2791,7 +2791,7 @@ fill_tlsa(char *name, char *type, int myttl, uint8_t u
int
fill_sshfp(char *name, char *type, int myttl, int alg, int fptype, char *fingerprint)
{
- DB *db = mydb;
+ ddDB *db = mydb;
void *sdomain, *tp;
struct domain *ssd;
struct domain_sshfp *ssd_sshfp;
@@ -2902,7 +2902,7 @@ fill_sshfp(char *name, char *type, int myttl, int alg,
int
fill_srv(char *name, char *type, int myttl, int priority, int weight, int port, char *srvhost)
{
- DB *db = mydb;
+ ddDB *db = mydb;
void *sdomain, *tp;
struct domain *ssd;
struct domain_srv *ssd_srv;
@@ -3006,7 +3006,7 @@ fill_srv(char *name, char *type, int myttl, int priori
int
fill_mx(char *name, char *type, int myttl, int priority, char *mxhost)
{
- DB *db = mydb;
+ ddDB *db = mydb;
void *sdomain, *tp;
struct domain *ssd;
struct domain_mx *ssd_mx;
@@ -3105,7 +3105,7 @@ fill_mx(char *name, char *type, int myttl, int priorit
int
fill_a(char *name, char *type, int myttl, char *a)
{
- DB *db = mydb;
+ ddDB *db = mydb;
void *sdomain, *tp;
struct domain *ssd;
struct domain_a *ssd_a;
@@ -3199,7 +3199,7 @@ fill_a(char *name, char *type, int myttl, char *a)
int
fill_aaaa(char *name, char *type, int myttl, char *aaaa)
{
- DB *db = mydb;
+ ddDB *db = mydb;
void *sdomain, *tp;
struct domain_aaaa *ssd_aaaa;
struct domain *ssd;
@@ -3295,7 +3295,7 @@ fill_aaaa(char *name, char *type, int myttl, char *aaa
int
fill_ns(char *name, char *type, int myttl, char *nameserver)
{
- DB *db = mydb;
+ ddDB *db = mydb;
void *sdomain, *tp;
struct domain *ssd;
struct domain_ns *ssd_ns;
@@ -3419,7 +3419,7 @@ fill_ns(char *name, char *type, int myttl, char *names
int
fill_soa(char *name, char *type, int myttl, char *auth, char *contact, int serial, int refresh, int retry, int expire, int ttl)
{
- DB *db = mydb;
+ ddDB *db = mydb;
void *sdomain, *tp;
struct domain *ssd;
struct domain_soa *ssd_soa;
@@ -3541,7 +3541,7 @@ fill_soa(char *name, char *type, int myttl, char *auth
int
get_record(struct domain *sdomain, char *converted_name, int converted_namelen)
{
- DB *db = mydb; /* XXX */
+ ddDB *db = mydb; /* XXX */
memset(&key, 0, sizeof(key));
memset(&data, 0, sizeof(data));
@@ -3552,7 +3552,7 @@ get_record(struct domain *sdomain, char *converted_nam
data.data = NULL;
data.size = 0;
- if (db->get(db, NULL, &key, &data, 0) == 0) {
+ if (db->get(db, &key, &data) == 0) {
memcpy((char *)sdomain, (char *)data.data, data.size);
} else {
@@ -3569,7 +3569,7 @@ get_record(struct domain *sdomain, char *converted_nam
void
set_record(struct domain *sdomain, int rs, char *converted_name, int converted_namelen)
{
- DB *db = mydb; /* XXX */
+ ddDB *db = mydb; /* XXX */
int ret;
/* everythign in parse.y should get this flag! */
@@ -3584,8 +3584,8 @@ set_record(struct domain *sdomain, int rs, char *conve
data.data = (void*)sdomain;
data.size = rs;
- if ((ret = db->put(db, NULL, &key, &data, 0)) != 0) {
- dolog(LOG_INFO, "db->put: %s\n" , db_strerror(ret));
+ if ((ret = db->put(db, &key, &data)) != 0) {
+ //dolog(LOG_INFO, "db->put: %s\n" , db_strerror(ret));
return;
}
blob - 02c0fa94a421307a957cc2bbe4d5b87b34866833
blob + 6a3abdf5e168713d0288d9d2051739f2b9fcaf33
--- region.c
+++ region.c
@@ -35,20 +35,20 @@ int getmask6(int, struct sockaddr_in6 *);
void init_region(void);
int insert_region(char *, char *, u_int8_t);
-SLIST_HEAD(listhead, entry) head;
+SLIST_HEAD(listhead, regionentry) regionhead;
-static struct entry {
+static struct regionentry {
char name[INET6_ADDRSTRLEN];
int family;
struct sockaddr_storage hostmask;
struct sockaddr_storage netmask;
u_int8_t region;
u_int8_t prefixlen;
- SLIST_ENTRY(entry) region_entry;
+ SLIST_ENTRY(regionentry) region_entry;
} *n2, *np;
-static const char rcsid[] = "$Id: region.c,v 1.3 2016/07/06 05:12:51 pjp Exp $";
+static const char rcsid[] = "$Id: region.c,v 1.4 2017/06/26 20:28:50 pjp Exp $";
/*
* INIT_REGION - initialize the region singly linked list
@@ -57,14 +57,15 @@ static const char rcsid[] = "$Id: region.c,v 1.3 2016/
void
init_region(void)
{
- SLIST_INIT(&head);
+ SLIST_INIT(&regionhead);
return;
}
/*
* INSERT_REGION - insert particular address and prefix length and region
* into the
- * singly linked list at "head", if the address contains
+ * singly linked list at "regionhead", if the address
+ * contains
* a colon then it is assumed to be an IPv6 address.
* return -1 on error, 0 on successful insertion
*/
@@ -78,7 +79,7 @@ insert_region(char *address, char *prefixlen, u_int8_t
int ret;
pnum = atoi(prefixlen);
- n2 = malloc(sizeof(struct entry)); /* Insert after. */
+ n2 = malloc(sizeof(struct regionentry)); /* Insert after. */
if (strchr(address, ':') != NULL) {
n2->family = AF_INET6;
@@ -106,7 +107,7 @@ insert_region(char *address, char *prefixlen, u_int8_t
}
- SLIST_INSERT_HEAD(&head, n2, region_entry);
+ SLIST_INSERT_HEAD(&regionhead, n2, region_entry);
return (0);
}
@@ -133,7 +134,7 @@ find_region(struct sockaddr_storage *sst, int family)
u_int8_t region = 0xff;
u_int8_t prefixlen = 0;
- SLIST_FOREACH(np, &head, region_entry) {
+ SLIST_FOREACH(np, &regionhead, region_entry) {
if (np->family == AF_INET) {
if (family != AF_INET)
continue;
blob - 24f472933d2d14fdeef483bb386d5f2c53851181
blob + 34150ae72bea84e18eed7413a533a8e221e4ccaa
--- reply.c
+++ reply.c
@@ -32,7 +32,7 @@
/* prototypes */
-extern int checklabel(DB *, struct domain *, struct domain *, struct question *);
+extern int checklabel(ddDB *, struct domain *, struct domain *, struct question *);
extern int additional_nsec3(char *, int, int, struct domain *, char *, int, int);
extern int additional_a(char *, int, struct domain *, char *, int, int, int *);
extern int additional_aaaa(char *, int, struct domain *, char *, int, int, int *);
@@ -45,52 +45,52 @@ extern struct question *build_fake_question(char *, i
extern int compress_label(u_char *, int, int);
extern void dolog(int, char *, ...);
extern int free_question(struct question *);
-extern struct domain * lookup_zone(DB *, struct question *, int *, int *, char *);
+extern struct domain * lookup_zone(ddDB *, struct question *, int *, int *, char *);
extern void slave_shutdown(void);
extern void * find_substruct(struct domain *, u_int16_t);
-extern int get_record_size(DB *, char *, int);
+extern int get_record_size(ddDB *, char *, int);
extern char * dns_label(char *, int *);
extern int lookup_type(int internal_type);
-struct domain *Lookup_zone(DB *, char *, u_int16_t, u_int16_t, int);
+struct domain *Lookup_zone(ddDB *, char *, u_int16_t, u_int16_t, int);
u_int16_t create_anyreply(struct sreply *, char *, int, int, int);
-int reply_a(struct sreply *, DB *);
-int reply_nsec3(struct sreply *, DB *);
+int reply_a(struct sreply *, ddDB *);
+int reply_nsec3(struct sreply *, ddDB *);
int reply_nsec3param(struct sreply *);
int reply_nsec(struct sreply *);
int reply_dnskey(struct sreply *);
int reply_ds(struct sreply *);
-int reply_rrsig(struct sreply *, DB *);
-int reply_aaaa(struct sreply *, DB *);
-int reply_mx(struct sreply *, DB *);
-int reply_ns(struct sreply *, DB *);
+int reply_rrsig(struct sreply *, ddDB *);
+int reply_aaaa(struct sreply *, ddDB *);
+int reply_mx(struct sreply *, ddDB *);
+int reply_ns(struct sreply *, ddDB *);
int reply_notimpl(struct sreply *);
-int reply_nxdomain(struct sreply *, DB *);
-int reply_noerror(struct sreply *, DB *);
+int reply_nxdomain(struct sreply *, ddDB *);
+int reply_noerror(struct sreply *, ddDB *);
int reply_badvers(struct sreply *);
int reply_nodata(struct sreply *);
int reply_soa(struct sreply *);
int reply_ptr(struct sreply *);
int reply_txt(struct sreply *);
int reply_version(struct sreply *);
-int reply_srv(struct sreply *, DB *);
-int reply_naptr(struct sreply *, DB *);
+int reply_srv(struct sreply *, ddDB *);
+int reply_naptr(struct sreply *, ddDB *);
int reply_sshfp(struct sreply *);
int reply_tlsa(struct sreply *);
int reply_cname(struct sreply *);
int reply_any(struct sreply *);
int reply_refused(struct sreply *);
int reply_fmterror(struct sreply *);
-void update_db(DB *, struct domain *);
-struct domain * find_nsec(char *name, int namelen, struct domain *sd, DB *db);
+void update_db(ddDB *, struct domain *);
+struct domain * find_nsec(char *name, int namelen, struct domain *sd, ddDB *db);
int nsec_comp(const void *a, const void *b);
char * convert_name(char *name, int namelen);
int count_dots(char *name);
char * base32hex_encode(u_char *input, int len);
-struct domain * find_nsec3_cover_next_closer(char *name, int namelen, struct domain *sd, DB *db);
-struct domain * find_nsec3_match_closest(char *name, int namelen, struct domain *sd, DB *db);
-struct domain * find_nsec3_wildcard_closest(char *name, int namelen, struct domain *sd, DB *db);
-struct domain * find_nsec3_match_qname(char *name, int namelen, struct domain *sd, DB *db);
+struct domain * find_nsec3_cover_next_closer(char *name, int namelen, struct domain *sd, ddDB *db);
+struct domain * find_nsec3_match_closest(char *name, int namelen, struct domain *sd, ddDB *db);
+struct domain * find_nsec3_wildcard_closest(char *name, int namelen, struct domain *sd, ddDB *db);
+struct domain * find_nsec3_match_qname(char *name, int namelen, struct domain *sd, ddDB *db);
extern int debug, verbose, dnssec;
extern char *versionstring;
@@ -109,7 +109,7 @@ extern uint8_t vslen;
outlen = tmplen; \
} while (0);
-static const char rcsid[] = "$Id: reply.c,v 1.53 2017/03/14 08:23:09 pjp Exp $";
+static const char rcsid[] = "$Id: reply.c,v 1.54 2017/06/26 20:28:50 pjp Exp $";
/*
* REPLY_A() - replies a DNS question (*q) on socket (so)
@@ -117,7 +117,7 @@ static const char rcsid[] = "$Id: reply.c,v 1.53 2017/
*/
int
-reply_a(struct sreply *sreply, DB *db)
+reply_a(struct sreply *sreply, ddDB *db)
{
char *reply = sreply->replybuf;
struct dns_header *odh;
@@ -478,7 +478,7 @@ out:
*/
int
-reply_nsec3(struct sreply *sreply, DB *db)
+reply_nsec3(struct sreply *sreply, ddDB *db)
{
char *reply = sreply->replybuf;
struct dns_header *odh;
@@ -1219,7 +1219,7 @@ out:
int
-reply_rrsig(struct sreply *sreply, DB *db)
+reply_rrsig(struct sreply *sreply, ddDB *db)
{
char *reply = sreply->replybuf;
struct dns_header *odh;
@@ -1384,7 +1384,7 @@ out:
*/
int
-reply_aaaa(struct sreply *sreply, DB *db)
+reply_aaaa(struct sreply *sreply, ddDB *db)
{
char *reply = sreply->replybuf;
struct dns_header *odh;
@@ -1554,7 +1554,7 @@ out:
*/
int
-reply_mx(struct sreply *sreply, DB *db)
+reply_mx(struct sreply *sreply, ddDB *db)
{
char *reply = sreply->replybuf;
struct dns_header *odh;
@@ -1727,7 +1727,7 @@ out:
*/
int
-reply_ns(struct sreply *sreply, DB *db)
+reply_ns(struct sreply *sreply, ddDB *db)
{
char *reply = sreply->replybuf;
struct dns_header *odh;
@@ -3187,7 +3187,7 @@ out:
int
-reply_naptr(struct sreply *sreply, DB *db)
+reply_naptr(struct sreply *sreply, ddDB *db)
{
char *reply = sreply->replybuf;
struct dns_header *odh;
@@ -3390,7 +3390,7 @@ out:
int
-reply_srv(struct sreply *sreply, DB *db)
+reply_srv(struct sreply *sreply, ddDB *db)
{
char *reply = sreply->replybuf;
struct dns_header *odh;
@@ -3635,7 +3635,7 @@ reply_notimpl(struct sreply *sreply)
*/
int
-reply_nxdomain(struct sreply *sreply, DB *db)
+reply_nxdomain(struct sreply *sreply, ddDB *db)
{
char *reply = sreply->replybuf;
struct dns_header *odh;
@@ -4164,7 +4164,7 @@ reply_fmterror(struct sreply *sreply)
*/
int
-reply_noerror(struct sreply *sreply, DB *db)
+reply_noerror(struct sreply *sreply, ddDB *db)
{
char *reply = sreply->replybuf;
struct dns_header *odh;
@@ -4487,11 +4487,11 @@ out:
}
void
-update_db(DB *db, struct domain *sd)
+update_db(ddDB *db, struct domain *sd)
{
int ret;
int i = 0;
- DBT key, data;
+ ddDBT key, data;
do {
@@ -4510,7 +4510,7 @@ update_db(DB *db, struct domain *sd)
data.data = (char *)sd;
data.size = sd->len;
- ret = db->put(db, NULL, &key, &data, 0);
+ ret = db->put(db, &key, &data);
} while (ret != 0);
return;
@@ -4521,7 +4521,7 @@ update_db(DB *db, struct domain *sd)
*/
struct domain *
-Lookup_zone(DB *db, char *name, u_int16_t namelen, u_int16_t type, int wildcard)
+Lookup_zone(ddDB *db, char *name, u_int16_t namelen, u_int16_t type, int wildcard)
{
struct domain *sd;
struct question *fakequestion;
@@ -4658,6 +4658,7 @@ u_int16_t
create_anyreply(struct sreply *sreply, char *reply, int rlen, int offset, int soa)
{
int a_count, aaaa_count, ns_count, mx_count, srv_count, sshfp_count;
+ int tlsa_count, typelen;
int ds_count, dnskey_count;
int naptr_count, rrsig_count;
int internal_type;
@@ -4682,6 +4683,7 @@ create_anyreply(struct sreply *sreply, char *reply, in
struct domain_ns *sdns = NULL;
struct domain_mx *sdmx = NULL;
struct domain_sshfp *sdsshfp = NULL;
+ struct domain_tlsa *sdtlsa = NULL;
struct domain_nsec *sdnsec = NULL;
struct domain_rrsig *sdrrsig = NULL;
struct domain_ds *sdds = NULL;
@@ -4699,7 +4701,8 @@ create_anyreply(struct sreply *sreply, char *reply, in
u_int16_t *dnskey_flags, *nsec3param_iterations;
u_int16_t *nsec3_iterations;
u_int8_t *sshfp_alg, *sshfp_fptype, *ds_alg, *ds_digesttype;
- u_int8_t *dnskey_protocol, *dnskey_alg;
+ u_int8_t *dnskey_protocol, *dnskey_alg, *tlsa_usage, *tlsa_selector;
+ u_int8_t *tlsa_matchtype;
u_int8_t *nsec3param_alg, *nsec3param_flags, *nsec3param_saltlen;
u_int8_t *nsec3_alg, *nsec3_flags, *nsec3_saltlen, *nsec3_hashlen;
char *name, *p;
@@ -5399,6 +5402,73 @@ create_anyreply(struct sreply *sreply, char *reply, in
offset += (sdtxt->txtlen + 1);
answer->rdlength = htons(sdtxt->txtlen + 1);
+
+ }
+ if (sd->flags & DOMAIN_HAVE_TLSA) {
+ if ((sdtlsa = (struct domain_tlsa *)find_substruct(sd, INTERNAL_TYPE_TLSA)) == NULL)
+ return 0;
+
+ tlsa_count = 0;
+ do {
+ if ((offset + q->hdr->namelen) > rlen) {
+ goto truncate;
+ }
+
+ memcpy(&reply[offset], q->hdr->name, q->hdr->namelen);
+ offset += q->hdr->namelen;
+
+ if ((tmplen = compress_label((u_char*)reply, offset, q->hdr->namelen)) > 0) {
+ offset = tmplen;
+ }
+
+
+ if (offset + 12 > rlen)
+ goto truncate;
+
+ answer = (struct answer *)&reply[offset];
+
+ answer->type = htons(DNS_TYPE_TLSA);
+ answer->class = htons(DNS_CLASS_IN);
+ answer->ttl = htonl(sd->ttl[INTERNAL_TYPE_TLSA]);
+
+ typelen = sdtlsa->tlsa[tlsa_count].matchtype == 1 ? DNS_TLSA_SIZE_SHA256 : DNS_TLSA_SIZE_SHA512;
+ answer->rdlength = htons((3 * sizeof(u_int8_t)) + typelen);
+
+ offset += 10; /* up to rdata length */
+
+ tlsa_usage = (u_int8_t *)&reply[offset];
+ *tlsa_usage = sdtlsa->tlsa[tlsa_count].usage;
+
+ offset++;
+
+ tlsa_selector = (u_int8_t *)&reply[offset];
+ *tlsa_selector = sdtlsa->tlsa[tlsa_count].selector;
+
+ offset++;
+
+ tlsa_matchtype = (u_int8_t *)&reply[offset];
+ *tlsa_matchtype = sdtlsa->tlsa[tlsa_count].matchtype;
+
+ offset++;
+
+ if (offset + sdtlsa->tlsa[tlsa_count].datalen > rlen)
+ goto truncate;
+
+ memcpy((char *)&reply[offset], (char *)sdtlsa->tlsa[tlsa_count].data, sdtlsa->tlsa[tlsa_count].datalen);
+
+ offset += sdtlsa->tlsa[tlsa_count].datalen;
+
+ /* can we afford to write another header? if no truncate */
+ if (sdtlsa->tlsa_count > 1 && (offset + 12 + 3 + sdtlsa->tlsa[tlsa_count].datalen) > rlen) {
+ goto truncate;
+ }
+
+ answer->rdlength = htons(&reply[offset] - answer->rdata);
+ } while (++tlsa_count < RECORD_COUNT && --sdtlsa->tlsa_count);
+
+ NTOHS(odh->answer);
+ odh->answer += tlsa_count;
+ HTONS(odh->answer);
}
if (sd->flags & DOMAIN_HAVE_SSHFP) {
blob - 5bf3f65a19237334d9b38b9c5d760240ea4626a3
blob + 59b7c09f2e783e5492f926ddc3f3edbe4ef734ab
--- util.c
+++ util.c
@@ -36,9 +36,9 @@
int label_count(char *);
char * dns_label(char *, int *);
void slave_shutdown(void);
-int get_record_size(DB *, char *, int);
+int get_record_size(ddDB *, char *, int);
void * find_substruct(struct domain *, u_int16_t);
-struct domain * lookup_zone(DB *, struct question *, int *, int *, char *);
+struct domain * lookup_zone(ddDB *, struct question *, int *, int *, char *);
u_int16_t check_qtype(struct domain *, u_int16_t, int, int *);
struct question *build_fake_question(char *, int, u_int16_t);
@@ -188,10 +188,10 @@ slave_shutdown(void)
*/
int
-get_record_size(DB *db, char *converted_name, int converted_namelen)
+get_record_size(ddDB *db, char *converted_name, int converted_namelen)
{
struct domain *sdomain;
- DBT key, data;
+ ddDBT key, data;
int ret;
memset(&key, 0, sizeof(key));
@@ -203,13 +203,10 @@ get_record_size(DB *db, char *converted_name, int conv
data.data = NULL;
data.size = sizeof(struct domain);
- if ((ret = db->get(db, NULL, &key, &data, 0)) == 0) {
+ if ((ret = db->get(db, &key, &data)) == 0) {
sdomain = (struct domain *)data.data;
return (sdomain->len);
- } else {
- if (debug && ret != DB_NOTFOUND )
- dolog(LOG_INFO, "db->get: %s\n", strerror(errno));
- }
+ }
return sizeof(struct domain);
}
@@ -324,7 +321,7 @@ find_substruct(struct domain *ssd, u_int16_t type)
struct domain *
-lookup_zone(DB *db, struct question *question, int *returnval, int *lzerrno, char *replystring)
+lookup_zone(ddDB *db, struct question *question, int *returnval, int *lzerrno, char *replystring)
{
struct domain *sd = NULL;
@@ -337,7 +334,7 @@ lookup_zone(DB *db, struct question *question, int *re
char *p;
- DBT key, data;
+ ddDBT key, data;
p = question->hdr->name;
plen = question->hdr->namelen;
@@ -367,7 +364,7 @@ lookup_zone(DB *db, struct question *question, int *re
data.data = NULL;
data.size = rs;
- ret = db->get(db, NULL, &key, &data, 0);
+ ret = db->get(db, &key, &data);
if (ret != 0) {
nsec3:
/*
@@ -402,7 +399,7 @@ nsec3:
data.data = NULL;
data.size = rs;
- ret = db->get(db, NULL, &key, &data, 0);
+ ret = db->get(db, &key, &data);
if (ret == 0)
memcpy((char *)sd, (char *)data.data, data.size);
if (ret == 0 && (sd->flags & DOMAIN_HAVE_SOA)) {
repomaster@centroid.eu