diff options
author | Richard Sharpe <rsharpe@samba.org> | 2016-05-20 06:31:32 -0700 |
---|---|---|
committer | Andreas Schneider <asn@samba.org> | 2016-05-24 16:35:42 +0200 |
commit | cf5b0fa7b6aa76531c8b57e4f0a0c6dab36a8000 (patch) | |
tree | 31af91e75f868a0738072426688cb44931e1b6a1 | |
parent | 826e7658fea892ad452c9d830674c09777b890b1 (diff) | |
download | resolv_wrapper-cf5b0fa7b6aa76531c8b57e4f0a0c6dab36a8000.tar.gz resolv_wrapper-cf5b0fa7b6aa76531c8b57e4f0a0c6dab36a8000.tar.xz resolv_wrapper-cf5b0fa7b6aa76531c8b57e4f0a0c6dab36a8000.zip |
rwrap: Add support to handle NS records
Signed-off-by: Richard Sharpe <rsharpe@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Jakub Hrozek <jakub.hrozek@posteo.se>
-rw-r--r-- | src/resolv_wrapper.c | 61 |
1 files changed, 60 insertions, 1 deletions
diff --git a/src/resolv_wrapper.c b/src/resolv_wrapper.c index 72005fa..48018be 100644 --- a/src/resolv_wrapper.c +++ b/src/resolv_wrapper.c @@ -231,6 +231,15 @@ static int rwrap_create_fake_aaaa_rr(const char *key, rr->type = ns_t_aaaa; return 0; } +static int rwrap_create_fake_ns_rr(const char *key, + const char *value, + struct rwrap_fake_rr *rr) +{ + memcpy(rr->rrdata.srv_rec.hostname, value, strlen(value) + 1); + memcpy(rr->key, key, strlen(key) + 1); + rr->type = ns_t_ns; + return 0; +} static int rwrap_create_fake_srv_rr(const char *key, const char *value, @@ -473,6 +482,47 @@ static ssize_t rwrap_fake_aaaa(struct rwrap_fake_rr *rr, return resp_size; } +static ssize_t rwrap_fake_ns(struct rwrap_fake_rr *rr, + uint8_t *answer, + size_t anslen) +{ + uint8_t *a = answer; + ssize_t resp_size = 0; + size_t rdata_size; + unsigned char hostname_compressed[MAXDNAME]; + ssize_t compressed_len; + + if (rr == NULL || rr->type != ns_t_ns) { + RWRAP_LOG(RWRAP_LOG_ERROR, + "Malformed record, no or wrong value!\n"); + return -1; + } + RWRAP_LOG(RWRAP_LOG_TRACE, "Adding NS RR"); + + /* Prepare the data to write */ + compressed_len = ns_name_compress(rr->rrdata.srv_rec.hostname, + hostname_compressed, + MAXDNAME, + NULL, + NULL); + if (compressed_len < 0) { + return -1; + } + + /* Is this enough? */ + rdata_size = compressed_len; + + resp_size = rwrap_fake_rdata_common(ns_t_ns, rdata_size, + rr->key, anslen, &a); + if (resp_size < 0) { + return -1; + } + + memcpy(a, hostname_compressed, compressed_len); + + return resp_size; +} + static ssize_t rwrap_fake_srv(struct rwrap_fake_rr *rr, uint8_t *answer, size_t anslen) @@ -666,7 +716,8 @@ static int rwrap_get_record(const char *hostfile, unsigned recursion, } RWRAP_LOG(RWRAP_LOG_TRACE, - "Searching in fake hosts file %s\n", hostfile); + "Searching in fake hosts file %s for %s:%d\n", hostfile, + query, type); fp = fopen(hostfile, "r"); if (fp == NULL) { @@ -706,6 +757,10 @@ static int rwrap_get_record(const char *hostfile, unsigned recursion, rec_type, "AAAA", key, query)) { rc = rwrap_create_fake_aaaa_rr(key, value, rr); break; + } else if (TYPE_MATCH(type, ns_t_ns, + rec_type, "NS", key, query)) { + rc = rwrap_create_fake_ns_rr(key, value, rr); + break; } else if (TYPE_MATCH(type, ns_t_srv, rec_type, "SRV", key, query)) { rc = rwrap_create_fake_srv_rr(key, value, rr); @@ -780,6 +835,7 @@ static inline bool rwrap_known_type(int type) switch (type) { case ns_t_a: case ns_t_aaaa: + case ns_t_ns: case ns_t_srv: case ns_t_soa: case ns_t_cname: @@ -839,6 +895,9 @@ static ssize_t rwrap_add_rr(struct rwrap_fake_rr *rr, case ns_t_aaaa: resp_data = rwrap_fake_aaaa(rr, answer, anslen); break; + case ns_t_ns: + resp_data = rwrap_fake_ns(rr, answer, anslen); + break; case ns_t_srv: resp_data = rwrap_fake_srv(rr, answer, anslen); break; |