diff options
-rw-r--r-- | package/deps.mak | 11 | ||||
-rw-r--r-- | src/common/deps-lib/shibari-common | 2 | ||||
-rw-r--r-- | src/common/shibari_util_canon_domain.c | 20 | ||||
-rw-r--r-- | src/include/shibari/util.h | 3 | ||||
-rw-r--r-- | src/server/shibari_packet_tdb_answer_query.c | 15 | ||||
-rw-r--r-- | src/server/shibari_packet_tdb_axfr.c | 12 |
6 files changed, 48 insertions, 15 deletions
diff --git a/package/deps.mak b/package/deps.mak index 5c87d5b..ffc2c1a 100644 --- a/package/deps.mak +++ b/package/deps.mak @@ -21,6 +21,7 @@ src/common/shibari_log_exit.o src/common/shibari_log_exit.lo: src/common/shibari src/common/shibari_log_query.o src/common/shibari_log_query.lo: src/common/shibari_log_query.c src/include/shibari/log.h src/include/shibari/util.h src/common/shibari_log_queryplus.o src/common/shibari_log_queryplus.lo: src/common/shibari_log_queryplus.c src/include/shibari/log.h src/include/shibari/util.h src/common/shibari_log_start.o src/common/shibari_log_start.lo: src/common/shibari_log_start.c src/include/shibari/log.h +src/common/shibari_util_canon_domain.o src/common/shibari_util_canon_domain.lo: src/common/shibari_util_canon_domain.c src/include/shibari/util.h src/common/shibari_util_get_prefixlen.o src/common/shibari_util_get_prefixlen.lo: src/common/shibari_util_get_prefixlen.c src/include/shibari/util.h src/common/shibari_util_qtype_num.o src/common/shibari_util_qtype_num.lo: src/common/shibari_util_qtype_num.c src/include/shibari/util.h src/common/shibari_util_qtype_str.o src/common/shibari_util_qtype_str.lo: src/common/shibari_util_qtype_str.c src/include/shibari/util.h @@ -33,7 +34,7 @@ src/server/shibari_packet_assert_authority.o src/server/shibari_packet_assert_au src/server/shibari_packet_begin.o src/server/shibari_packet_begin.lo: src/server/shibari_packet_begin.c src/include/shibari/constants.h src/include/shibari/packet.h src/server/shibari_packet_end.o src/server/shibari_packet_end.lo: src/server/shibari_packet_end.c src/include/shibari/packet.h src/server/shibari_packet_init.o src/server/shibari_packet_init.lo: src/server/shibari_packet_init.c src/include/shibari/packet.h -src/server/shibari_packet_tdb_answer_query.o src/server/shibari_packet_tdb_answer_query.lo: src/server/shibari_packet_tdb_answer_query.c src/include/shibari/constants.h src/include/shibari/packet.h src/include/shibari/tdb.h +src/server/shibari_packet_tdb_answer_query.o src/server/shibari_packet_tdb_answer_query.lo: src/server/shibari_packet_tdb_answer_query.c src/include/shibari/constants.h src/include/shibari/packet.h src/include/shibari/tdb.h src/include/shibari/util.h src/server/shibari_packet_tdb_axfr.o src/server/shibari_packet_tdb_axfr.lo: src/server/shibari_packet_tdb_axfr.c src/include/shibari/constants.h src/include/shibari/packet.h src/include/shibari/tdb.h src/include/shibari/util.h src/server/shibari_tdb_entry_parse.o src/server/shibari_tdb_entry_parse.lo: src/server/shibari_tdb_entry_parse.c src/include/shibari/constants.h src/include/shibari/tdb.h src/server/shibari_tdb_extract_domain.o src/server/shibari_tdb_extract_domain.lo: src/server/shibari_tdb_extract_domain.c src/include/shibari/constants.h src/include/shibari/tdb.h @@ -48,12 +49,12 @@ endif libdcache.so.xyzzy: EXTRA_LIBS := libdcache.so.xyzzy: src/cache/dcache_add.lo src/cache/dcache_clean_expired.lo src/cache/dcache_delete.lo src/cache/dcache_free.lo src/cache/dcache_init.lo src/cache/dcache_load.lo src/cache/dcache_save.lo src/cache/dcache_search.lo ifeq ($(strip $(STATIC_LIBS_ARE_PIC)),) -libshibari-common.a.xyzzy: src/common/shibari_log_answer.o src/common/shibari_log_exit.o src/common/shibari_log_query.o src/common/shibari_log_queryplus.o src/common/shibari_log_start.o src/common/shibari_util_qtype_num.o src/common/shibari_util_qtype_str.o src/common/shibari_util_rcode_str.o src/common/shibari_util_get_prefixlen.o +libshibari-common.a.xyzzy: src/common/shibari_log_answer.o src/common/shibari_log_exit.o src/common/shibari_log_query.o src/common/shibari_log_queryplus.o src/common/shibari_log_start.o src/common/shibari_util_qtype_num.o src/common/shibari_util_qtype_str.o src/common/shibari_util_rcode_str.o src/common/shibari_util_canon_domain.o src/common/shibari_util_get_prefixlen.o else -libshibari-common.a.xyzzy: src/common/shibari_log_answer.lo src/common/shibari_log_exit.lo src/common/shibari_log_query.lo src/common/shibari_log_queryplus.lo src/common/shibari_log_start.lo src/common/shibari_util_qtype_num.lo src/common/shibari_util_qtype_str.lo src/common/shibari_util_rcode_str.lo src/common/shibari_util_get_prefixlen.lo +libshibari-common.a.xyzzy: src/common/shibari_log_answer.lo src/common/shibari_log_exit.lo src/common/shibari_log_query.lo src/common/shibari_log_queryplus.lo src/common/shibari_log_start.lo src/common/shibari_util_qtype_num.lo src/common/shibari_util_qtype_str.lo src/common/shibari_util_rcode_str.lo src/common/shibari_util_canon_domain.lo src/common/shibari_util_get_prefixlen.lo endif -libshibari-common.so.xyzzy: EXTRA_LIBS := -lskarnet -libshibari-common.so.xyzzy: src/common/shibari_log_answer.lo src/common/shibari_log_exit.lo src/common/shibari_log_query.lo src/common/shibari_log_queryplus.lo src/common/shibari_log_start.lo src/common/shibari_util_qtype_num.lo src/common/shibari_util_qtype_str.lo src/common/shibari_util_rcode_str.lo src/common/shibari_util_get_prefixlen.lo +libshibari-common.so.xyzzy: EXTRA_LIBS := -ls6dns -lskarnet +libshibari-common.so.xyzzy: src/common/shibari_log_answer.lo src/common/shibari_log_exit.lo src/common/shibari_log_query.lo src/common/shibari_log_queryplus.lo src/common/shibari_log_start.lo src/common/shibari_util_qtype_num.lo src/common/shibari_util_qtype_str.lo src/common/shibari_util_rcode_str.lo src/common/shibari_util_canon_domain.lo src/common/shibari_util_get_prefixlen.lo ifeq ($(strip $(STATIC_LIBS_ARE_PIC)),) libshibari-server.a.xyzzy: src/server/shibari_packet_init.o src/server/shibari_packet_begin.o src/server/shibari_packet_end.o src/server/shibari_packet_add_rr.o src/server/shibari_tdb_entry_parse.o src/server/shibari_tdb_extract_domain.o src/server/shibari_tdb_find_authority.o src/server/shibari_tdb_read_entry.o src/server/shibari_packet_add_glue.o src/server/shibari_packet_assert_authority.o src/server/shibari_packet_tdb_answer_query.o src/server/shibari_packet_tdb_axfr.o else diff --git a/src/common/deps-lib/shibari-common b/src/common/deps-lib/shibari-common index a5c44a4..eed0d4f 100644 --- a/src/common/deps-lib/shibari-common +++ b/src/common/deps-lib/shibari-common @@ -6,5 +6,7 @@ shibari_log_start.o shibari_util_qtype_num.o shibari_util_qtype_str.o shibari_util_rcode_str.o +shibari_util_canon_domain.o shibari_util_get_prefixlen.o +-ls6dns -lskarnet diff --git a/src/common/shibari_util_canon_domain.c b/src/common/shibari_util_canon_domain.c new file mode 100644 index 0000000..ece0c9b --- /dev/null +++ b/src/common/shibari_util_canon_domain.c @@ -0,0 +1,20 @@ +/* ISC license. */ + +#include <stdint.h> +#include <ctype.h> + +#include <s6-dns/s6dns-domain.h> + +#include <shibari/util.h> + +void shibari_util_canon_domain (s6dns_domain_t *canon, s6dns_domain_t const *orig) +{ + uint8_t i = 0 ; + canon->len = orig->len ; + while (i < orig->len) + { + uint8_t len = orig->s[i] ; + canon->s[i++] = len ; + for (; len-- ; i++) canon->s[i] = tolower(orig->s[i]) ; + } +} diff --git a/src/include/shibari/util.h b/src/include/shibari/util.h index 82092a3..8cbaca3 100644 --- a/src/include/shibari/util.h +++ b/src/include/shibari/util.h @@ -5,10 +5,13 @@ #include <stdint.h> +#include <s6-dns/s6dns-domain.h> + extern char const *shibari_util_qtype_str (uint16_t) ; extern uint16_t shibari_util_qtype_num (char const *) ; extern char const *shibari_util_rcode_str (uint16_t) ; +extern void shibari_util_canon_domain (s6dns_domain_t *, s6dns_domain_t const *) ; extern int shibari_util_get_prefixlen (char const *, uint16_t, char const *, uint16_t) ; #endif diff --git a/src/server/shibari_packet_tdb_answer_query.c b/src/server/shibari_packet_tdb_answer_query.c index d9e9474..74b08a2 100644 --- a/src/server/shibari_packet_tdb_answer_query.c +++ b/src/server/shibari_packet_tdb_answer_query.c @@ -2,9 +2,12 @@ #include <skalibs/cdb.h> +#include <s6-dns/s6dns-domain.h> + #include <shibari/constants.h> #include <shibari/tdb.h> #include <shibari/packet.h> +#include <shibari/util.h> static unsigned int childzone (shibari_packet *pkt, cdb const *tdb, s6dns_domain_t const *q, char const *loc, tain const *stamp, uint16_t nplen, uint16_t zplen) { @@ -28,6 +31,7 @@ static unsigned int childzone (shibari_packet *pkt, cdb const *tdb, s6dns_domain unsigned int shibari_packet_tdb_answer_query (shibari_packet *pkt, cdb const *tdb, s6dns_message_header_t const *qhdr, s6dns_domain_t const *q, uint16_t qtype, char const *loc, tain const *stamp) { + s6dns_domain_t ql ; unsigned int rcode = 0 ; uint32_t flagyxdomain = 0 ; int nplen, zplen ; @@ -35,8 +39,9 @@ unsigned int shibari_packet_tdb_answer_query (shibari_packet *pkt, cdb const *td uint16_t wildpos = 0 ; shibari_packet_begin(pkt, qhdr->id, q, qtype) ; + shibari_util_canon_domain(&ql, q) ; pkt->hdr.rd = qhdr->rd ; - zplen = shibari_tdb_find_authority(tdb, q->s, q->len, loc, stamp, &nplen) ; + zplen = shibari_tdb_find_authority(tdb, ql.s, ql.len, loc, stamp, &nplen) ; switch (zplen) { case -2 : return 9 ; @@ -44,7 +49,7 @@ unsigned int shibari_packet_tdb_answer_query (shibari_packet *pkt, cdb const *td default : break ; } if (nplen >= 0 && nplen < zplen) - return childzone(pkt, tdb, q, loc, stamp, nplen, zplen) ; + return childzone(pkt, tdb, &ql, loc, stamp, nplen, zplen) ; pkt->hdr.aa = 1 ; /* we're in the zone, man */ @@ -54,7 +59,7 @@ unsigned int shibari_packet_tdb_answer_query (shibari_packet *pkt, cdb const *td for (;;) { shibari_tdb_entry entry ; - int r = shibari_tdb_read_entry(tdb, &state, &entry, q->s + wildpos, q->len - wildpos, qtype, !!wildpos, loc, stamp, &flagyxdomain) ; + int r = shibari_tdb_read_entry(tdb, &state, &entry, ql.s + wildpos, ql.len - wildpos, qtype, !!wildpos, loc, stamp, &flagyxdomain) ; if (r == -1) return 2 ; if (!r) break ; if (!shibari_packet_add_rr(pkt, &entry, 0, wildpos, 2)) @@ -81,12 +86,12 @@ unsigned int shibari_packet_tdb_answer_query (shibari_packet *pkt, cdb const *td if (!pkt->hdr.counts.an) { - unsigned int r = shibari_packet_assert_authority(pkt, tdb, q->s + zplen, q->len - zplen, zplen, loc, stamp) ; + unsigned int r = shibari_packet_assert_authority(pkt, tdb, ql.s + zplen, ql.len - zplen, zplen, loc, stamp) ; if (r) return r ; } else if (gluetype) { - unsigned int r = shibari_packet_add_glue(pkt, tdb, q->s, q->len, gluetype, q->s + zplen, q->len - zplen, zplen, wildpos, loc, stamp) ; + unsigned int r = shibari_packet_add_glue(pkt, tdb, q->s, q->len, gluetype, ql.s + zplen, ql.len - zplen, zplen, wildpos, loc, stamp) ; if (r) return r ; } diff --git a/src/server/shibari_packet_tdb_axfr.c b/src/server/shibari_packet_tdb_axfr.c index 5613b67..c8ef4e7 100644 --- a/src/server/shibari_packet_tdb_axfr.c +++ b/src/server/shibari_packet_tdb_axfr.c @@ -34,15 +34,15 @@ int shibari_packet_tdb_axfr (buffer *b, char const *axfrok, char const *loc, cdb { shibari_tdb_entry soa ; shibari_tdb_entry cur ; + s6dns_domain_t z = *zone ; uint32_t pos = CDB_TRAVERSE_INIT() ; if (axfrok && axfrok[0] != '*') { - s6dns_domain_t decoded = *zone ; unsigned int zonelen ; size_t len = strlen(axfrok) + 1 ; char zbuf[256] ; - if (!s6dns_domain_decode(&decoded)) return 1 ; - zonelen = s6dns_domain_tostring(zbuf, 256, &decoded) ; + if (!s6dns_domain_decode(&z)) return 1 ; + zonelen = s6dns_domain_tostring(zbuf, 256, &z) ; while (len) { size_t seppos = byte_in(axfrok, len, SEPS, sizeof(SEPS)) ; @@ -53,9 +53,11 @@ int shibari_packet_tdb_axfr (buffer *b, char const *axfrok, char const *loc, cdb if (!len) return 5 ; } + shibari_util_canon_domain(&z, zone) ; + { cdb_find_state state = CDB_FIND_STATE_ZERO ; - int r = shibari_tdb_read_entry(tdb, &state, &soa, zone->s, zone->len, SHIBARI_T_SOA, 0, loc, wstamp, 0) ; + int r = shibari_tdb_read_entry(tdb, &state, &soa, z.s, z.len, SHIBARI_T_SOA, 0, loc, wstamp, 0) ; if (r == -1) return 2 ; if (!r) return 9 ; } @@ -71,7 +73,7 @@ int shibari_packet_tdb_axfr (buffer *b, char const *axfrok, char const *loc, cdb int r = cdb_traverse_next(tdb, &cur.key, &data, &pos) ; if (r == -1) return 2 ; if (!r) break ; - prefixlen = shibari_util_get_prefixlen(cur.key.s, cur.key.len, zone->s, zone->len) ; + prefixlen = shibari_util_get_prefixlen(cur.key.s, cur.key.len, z.s, z.len) ; if (prefixlen == -1) continue ; r = shibari_tdb_entry_parse(&cur, data.s, data.len, SHIBARI_T_ANY, 2, loc, wstamp) ; if (r == -1) return 2 ; |