The branch, master has been updated via ecd0e6e rwrap: Bump version to 1.1.0. via 5c0ada1 rwrap: Don't dereference NULL when skipping broken records. via 3b3fc1a rwrap: Support asking for A via CNAME via f5c156a rwrap: Recursively add additional data via aa78268 rwrap: Make the rwrap_fake_* functions only fake RRs. via 2782877 rwrap: CNAME record can recurse into A, AAAA or CNAME via 917c3f0 rwrap: SRV record can recurse into A or AAAA. via 0d128c5 rwrap: Use the rwrap_fake_rr structure instead of raw uint8_t pointers. via 154fa40 rwrap: Add data structures and functions to represent and manipulate RRs. via 253753c rwrap: Correctly calculate the response size and return it. via 849bfe0 rwrap: Handle trailing dot in dns names. via dab427e rwrap: Compare dns names case insensitive. via 8bf949f lib: Add resolv_wrapper version 1.0.0. via 70bbb1d selftest: Add the normal dns name as an alias for the main DC. via 9cde3ae testprogs: Set functional domain level to 2003. from a07af1b ctdb-tests: Need to drop public IPs in kill-failover tests
https://git.samba.org/?p=samba.git;a=shortlog;h=master - Log ----------------------------------------------------------------- commit ecd0e6e985ff8719963e31e1395b9ccbd38d94e1 Author: Andreas Schneider <a...@samba.org> Date: Wed Dec 3 15:45:10 2014 +0100 rwrap: Bump version to 1.1.0. Signed-off-by: Andreas Schneider <a...@samba.org> Reviewed-by: Andrew Bartlett <abart...@samba.org> Autobuild-User(master): Andrew Bartlett <abart...@samba.org> Autobuild-Date(master): Sat Dec 6 01:54:12 CET 2014 on sn-devel-104 commit 5c0ada1d570175498a4b97628b6f1dc45a72109a Author: Jakub Hrozek <jakub.hro...@gmail.com> Date: Wed Dec 3 15:45:09 2014 +0100 rwrap: Don't dereference NULL when skipping broken records. CID: 83426 CID: 83425 Signed-off-by: Jakub Hrozek <jakub.hro...@gmail.com> Reviewed-by: Michael Adam <ob...@samba.org> Reviewed-by: Andreas Schneider <a...@samba.org> Signed-off-by: Andreas Schneider <a...@samba.org> Reviewed-by: Andrew Bartlett <abart...@samba.org> commit 3b3fc1a21830d136bc1e571d08913dbec5b06336 Author: Jakub Hrozek <jakub.hro...@gmail.com> Date: Wed Dec 3 15:45:08 2014 +0100 rwrap: Support asking for A via CNAME Adds support for querying for an A record using a name that only expands into a CNAME. Signed-off-by: Jakub Hrozek <jakub.hro...@gmail.com> Reviewed-by: Andreas Schneider <a...@samba.org> Reviewed-by: Guenther Deschner <g...@samba.org> Signed-off-by: Andreas Schneider <a...@samba.org> Reviewed-by: Andrew Bartlett <abart...@samba.org> commit f5c156aac20b468b4324114515e1a951e1304713 Author: Jakub Hrozek <jakub.hro...@gmail.com> Date: Wed Dec 3 15:45:07 2014 +0100 rwrap: Recursively add additional data Change how we construct the fake answer such that the header and question are added first, then the answers and finally additional data. Signed-off-by: Jakub Hrozek <jakub.hro...@gmail.com> Reviewed-by: Andreas Schneider <a...@samba.org> Reviewed-by: Guenther Deschner <g...@samba.org> Signed-off-by: Andreas Schneider <a...@samba.org> Reviewed-by: Andrew Bartlett <abart...@samba.org> commit aa78268a49062d3bd1cb907828a250a01ebbd59a Author: Jakub Hrozek <jakub.hro...@gmail.com> Date: Wed Dec 3 15:45:06 2014 +0100 rwrap: Make the rwrap_fake_* functions only fake RRs. The rwrap_fake_common() function did too much. Remove it and use separate functions to add fake header and question sections. The rwrap_fake_$RR functions will receive packet including the header and question and only add its RR data. This will allow recursive processing later. Signed-off-by: Jakub Hrozek <jakub.hro...@gmail.com> Reviewed-by: Andreas Schneider <a...@samba.org> Reviewed-by: Guenther Deschner <g...@samba.org> Signed-off-by: Andreas Schneider <a...@samba.org> Reviewed-by: Andrew Bartlett <abart...@samba.org> commit 27828774c3633389b5ce5397d8e25fab2e278624 Author: Jakub Hrozek <jakub.hro...@gmail.com> Date: Wed Dec 3 15:45:05 2014 +0100 rwrap: CNAME record can recurse into A, AAAA or CNAME Signed-off-by: Jakub Hrozek <jakub.hro...@gmail.com> Reviewed-by: Andreas Schneider <a...@samba.org> Reviewed-by: Guenther Deschner <g...@samba.org> Signed-off-by: Andreas Schneider <a...@samba.org> Reviewed-by: Andrew Bartlett <abart...@samba.org> commit 917c3f08440c302511bdf06b5ac11b42630bdd28 Author: Jakub Hrozek <jakub.hro...@gmail.com> Date: Wed Dec 3 15:45:04 2014 +0100 rwrap: SRV record can recurse into A or AAAA. When querying for a SRV record, we'll need to include A or AAAA records in additional section. Therefore, keep querying the host file until we can either recurse the A/AAAA records or reach the recursion limit Signed-off-by: Jakub Hrozek <jakub.hro...@gmail.com> Reviewed-by: Andreas Schneider <a...@samba.org> Reviewed-by: Guenther Deschner <g...@samba.org> Signed-off-by: Andreas Schneider <a...@samba.org> Reviewed-by: Andrew Bartlett <abart...@samba.org> commit 0d128c5443283dee86edce60325083647985fe02 Author: Jakub Hrozek <jakub.hro...@gmail.com> Date: Wed Dec 3 15:45:03 2014 +0100 rwrap: Use the rwrap_fake_rr structure instead of raw uint8_t pointers. Currently only one instance of the rwrap_fake_rr structure is used. Recursion will be implemented in a future patch. Signed-off-by: Jakub Hrozek <jakub.hro...@gmail.com> Reviewed-by: Andreas Schneider <a...@samba.org> Reviewed-by: Guenther Deschner <g...@samba.org> Signed-off-by: Andreas Schneider <a...@samba.org> Reviewed-by: Andrew Bartlett <abart...@samba.org> commit 154fa401dc10e9d20f7296d23227c554dead2b44 Author: Jakub Hrozek <jakub.hro...@gmail.com> Date: Wed Dec 3 15:45:02 2014 +0100 rwrap: Add data structures and functions to represent and manipulate RRs. Adds a structure that, using unions represents all supported RRs. Add a bunch of utility functions that can be used to create these structures. Currently the functions are unused. Signed-off-by: Jakub Hrozek <jakub.hro...@gmail.com> Reviewed-by: Andreas Schneider <a...@samba.org> Reviewed-by: Guenther Deschner <g...@samba.org> Signed-off-by: Andreas Schneider <a...@samba.org> Reviewed-by: Andrew Bartlett <abart...@samba.org> commit 253753ca5b641d067bff2056929241540badd66f Author: Andreas Schneider <a...@samba.org> Date: Wed Dec 3 15:45:01 2014 +0100 rwrap: Correctly calculate the response size and return it. Signed-off-by: Andreas Schneider <a...@samba.org> Reviewed-by: Guenther Deschner <g...@samba.org> Reviewed-by: Andrew Bartlett <abart...@samba.org> commit 849bfe09b8275c4f11258d5ecf530a56a6d7e883 Author: Andreas Schneider <a...@samba.org> Date: Wed Dec 3 15:45:00 2014 +0100 rwrap: Handle trailing dot in dns names. Signed-off-by: Andreas Schneider <a...@samba.org> Reviewed-by: Guenther Deschner <g...@samba.org> Reviewed-by: Andrew Bartlett <abart...@samba.org> commit dab427e94eb4f21582ee9211ba4d837e4ed024a3 Author: Jakub Hrozek <jakub.hro...@gmail.com> Date: Wed Dec 3 15:44:59 2014 +0100 rwrap: Compare dns names case insensitive. Signed-off-by: Jakub Hrozek <jakub.hro...@gmail.com> Reviewed-by: Andreas Schneider <a...@samba.org> Reviewed-by: Guenther Deschner <g...@samba.org> Signed-off-by: Andreas Schneider <a...@samba.org> Reviewed-by: Andrew Bartlett <abart...@samba.org> commit 8bf949f343f8da7431d130395e3ac29e4be39889 Author: Andreas Schneider <a...@samba.org> Date: Wed Dec 3 15:44:58 2014 +0100 lib: Add resolv_wrapper version 1.0.0. Signed-off-by: Andreas Schneider <a...@samba.org> Reviewed-by: Andrew Bartlett <abart...@samba.org> commit 70bbb1dd3c8d118fd5a2ff01bd4aa4c00d34998e Author: Andreas Schneider <a...@samba.org> Date: Wed Dec 3 15:44:57 2014 +0100 selftest: Add the normal dns name as an alias for the main DC. Signed-off-by: Andreas Schneider <a...@samba.org> Reviewed-by: Andrew Bartlett <abart...@samba.org> commit 9cde3aec48852c2eb109bcdcf337659743067594 Author: Andreas Schneider <a...@samba.org> Date: Fri Dec 5 17:03:31 2014 +0100 testprogs: Set functional domain level to 2003. The default changed to 2008r2 recently. Signed-off-by: Andreas Schneider <a...@samba.org> Reviewed-by: Andrew Bartlett <abart...@samba.org> ----------------------------------------------------------------------- Summary of changes: lib/resolv_wrapper/resolv_wrapper.c | 1713 ++++++++++++++++++++++++++++++ lib/resolv_wrapper/wscript | 94 ++ selftest/target/Samba4.pm | 9 +- testprogs/blackbox/dbcheck-oldrelease.sh | 2 +- wscript | 1 + wscript_build | 1 + 6 files changed, 1817 insertions(+), 3 deletions(-) create mode 100644 lib/resolv_wrapper/resolv_wrapper.c create mode 100644 lib/resolv_wrapper/wscript Changeset truncated at 500 lines: diff --git a/lib/resolv_wrapper/resolv_wrapper.c b/lib/resolv_wrapper/resolv_wrapper.c new file mode 100644 index 0000000..7211ad0 --- /dev/null +++ b/lib/resolv_wrapper/resolv_wrapper.c @@ -0,0 +1,1713 @@ +/* + * Copyright (c) 2014 Andreas Schneider <a...@samba.org> + * Copyright (c) 2014 Jakub Hrozek <jakub.hro...@gmail.com> + * + * 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. Neither the name of the author nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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 "config.h" + +#include <errno.h> +#include <arpa/inet.h> +#include <netinet/in.h> +#include <sys/types.h> +#include <stdarg.h> +#include <stdlib.h> +#include <stdio.h> +#include <stdbool.h> +#include <string.h> +#include <unistd.h> +#include <ctype.h> + +#include <resolv.h> + +/* GCC has printf type attribute check. */ +#ifdef HAVE_ATTRIBUTE_PRINTF_FORMAT +#define PRINTF_ATTRIBUTE(a,b) __attribute__ ((__format__ (__printf__, a, b))) +#else +#define PRINTF_ATTRIBUTE(a,b) +#endif /* HAVE_ATTRIBUTE_PRINTF_FORMAT */ + +#ifdef HAVE_DESTRUCTOR_ATTRIBUTE +#define DESTRUCTOR_ATTRIBUTE __attribute__ ((destructor)) +#else +#define DESTRUCTOR_ATTRIBUTE +#endif /* HAVE_DESTRUCTOR_ATTRIBUTE */ + +#ifndef RWRAP_DEFAULT_FAKE_TTL +#define RWRAP_DEFAULT_FAKE_TTL 600 +#endif /* RWRAP_DEFAULT_FAKE_TTL */ + +enum rwrap_dbglvl_e { + RWRAP_LOG_ERROR = 0, + RWRAP_LOG_WARN, + RWRAP_LOG_DEBUG, + RWRAP_LOG_TRACE +}; + +#ifdef NDEBUG +# define RWRAP_LOG(...) +#else /* NDEBUG */ + +static void rwrap_log(enum rwrap_dbglvl_e dbglvl, const char *func, const char *format, ...) PRINTF_ATTRIBUTE(3, 4); +# define RWRAP_LOG(dbglvl, ...) rwrap_log((dbglvl), __func__, __VA_ARGS__) + +static void rwrap_log(enum rwrap_dbglvl_e dbglvl, + const char *func, + const char *format, ...) +{ + char buffer[1024]; + va_list va; + const char *d; + unsigned int lvl = 0; + int pid = getpid(); + + d = getenv("RESOLV_WRAPPER_DEBUGLEVEL"); + if (d != NULL) { + lvl = atoi(d); + } + + va_start(va, format); + vsnprintf(buffer, sizeof(buffer), format, va); + va_end(va); + + if (lvl >= dbglvl) { + switch (dbglvl) { + case RWRAP_LOG_ERROR: + fprintf(stderr, + "RWRAP_ERROR(%d) - %s: %s\n", + pid, func, buffer); + break; + case RWRAP_LOG_WARN: + fprintf(stderr, + "RWRAP_WARN(%d) - %s: %s\n", + pid, func, buffer); + break; + case RWRAP_LOG_DEBUG: + fprintf(stderr, + "RWRAP_DEBUG(%d) - %s: %s\n", + pid, func, buffer); + break; + case RWRAP_LOG_TRACE: + fprintf(stderr, + "RWRAP_TRACE(%d) - %s: %s\n", + pid, func, buffer); + break; + } + } +} +#endif /* NDEBUG RWRAP_LOG */ + +#ifndef SAFE_FREE +#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); (x)=NULL;} } while(0) +#endif + +#define NEXT_KEY(buf, key) do { \ + (key) = (buf) ? strpbrk((buf), " \t") : NULL; \ + if ((key) != NULL) { \ + (key)[0] = '\0'; \ + (key)++; \ + } \ + while ((key) != NULL \ + && (isblank((int)(key)[0]))) { \ + (key)++; \ + } \ +} while(0); + +#define RWRAP_MAX_RECURSION 5 + +/* Priority and weight can be omitted from the hosts file, but need to be part + * of the output + */ +#define DFL_SRV_PRIO 1 +#define DFL_SRV_WEIGHT 100 + +struct rwrap_srv_rrdata { + uint16_t port; + uint16_t prio; + uint16_t weight; + char hostname[MAXDNAME]; +}; + +struct rwrap_soa_rrdata { + uint32_t serial; + uint32_t refresh; + uint32_t retry; + uint32_t expire; + uint32_t minimum; + char nameserver[MAXDNAME]; + char mailbox[MAXDNAME]; +}; + +struct rwrap_fake_rr { + union fake_rrdata { + struct in_addr a_rec; + struct in6_addr aaaa_rec; + struct rwrap_srv_rrdata srv_rec; + struct rwrap_soa_rrdata soa_rec; + char cname_rec[MAXDNAME]; + } rrdata; + + char key[MAXDNAME]; + int type; /* ns_t_* */ +}; + +static void rwrap_fake_rr_init(struct rwrap_fake_rr *rr, size_t len) +{ + size_t i; + + for (i = 0; i < len; i++) { + rr[i].type = ns_t_invalid; + } +} + +static int rwrap_create_fake_a_rr(const char *key, + const char *value, + struct rwrap_fake_rr *rr) +{ + int ok; + + ok = inet_pton(AF_INET, value, &rr->rrdata.a_rec); + if (!ok) { + RWRAP_LOG(RWRAP_LOG_ERROR, + "Failed to convert [%s] to binary\n", value); + return -1; + } + + memcpy(rr->key, key, strlen(key) + 1); + rr->type = ns_t_a; + return 0; +} + +static int rwrap_create_fake_aaaa_rr(const char *key, + const char *value, + struct rwrap_fake_rr *rr) +{ + int ok; + + ok = inet_pton(AF_INET6, value, &rr->rrdata.aaaa_rec); + if (!ok) { + RWRAP_LOG(RWRAP_LOG_ERROR, + "Failed to convert [%s] to binary\n", value); + return -1; + } + + memcpy(rr->key, key, strlen(key) + 1); + rr->type = ns_t_aaaa; + return 0; +} + +static int rwrap_create_fake_srv_rr(const char *key, + const char *value, + struct rwrap_fake_rr *rr) +{ + char *str_prio; + char *str_weight; + char *str_port; + const char *hostname; + + /* parse the value into priority, weight, port and hostname + * and check the validity */ + hostname = value; + NEXT_KEY(hostname, str_port); + NEXT_KEY(str_port, str_prio); + NEXT_KEY(str_prio, str_weight); + if (str_port == NULL || hostname == NULL) { + RWRAP_LOG(RWRAP_LOG_ERROR, + "Malformed SRV entry [%s]\n", value); + return -1; + } + + if (str_prio) { + rr->rrdata.srv_rec.prio = atoi(str_prio); + } else { + rr->rrdata.srv_rec.prio = DFL_SRV_PRIO; + } + if (str_weight) { + rr->rrdata.srv_rec.weight = atoi(str_weight); + } else { + rr->rrdata.srv_rec.weight = DFL_SRV_WEIGHT; + } + rr->rrdata.srv_rec.port = atoi(str_port); + memcpy(rr->rrdata.srv_rec.hostname , hostname, strlen(hostname) + 1); + + memcpy(rr->key, key, strlen(key) + 1); + rr->type = ns_t_srv; + return 0; +} + +static int rwrap_create_fake_soa_rr(const char *key, + const char *value, + struct rwrap_fake_rr *rr) +{ + const char *nameserver; + char *mailbox; + char *str_serial; + char *str_refresh; + char *str_retry; + char *str_expire; + char *str_minimum; + + /* parse the value into nameserver, mailbox, serial, refresh, + * retry, expire, minimum and check the validity + */ + nameserver = value; + NEXT_KEY(nameserver, mailbox); + NEXT_KEY(mailbox, str_serial); + NEXT_KEY(str_serial, str_refresh); + NEXT_KEY(str_refresh, str_retry); + NEXT_KEY(str_retry, str_expire); + NEXT_KEY(str_expire, str_minimum); + if (nameserver == NULL || mailbox == NULL || str_serial == NULL || + str_refresh == NULL || str_retry == NULL || str_expire == NULL || + str_minimum == NULL) { + RWRAP_LOG(RWRAP_LOG_ERROR, + "Malformed SOA entry [%s]\n", value); + return -1; + } + + memcpy(rr->rrdata.soa_rec.nameserver, nameserver, strlen(nameserver)+1); + memcpy(rr->rrdata.soa_rec.mailbox, mailbox, strlen(mailbox)+1); + + rr->rrdata.soa_rec.serial = atoi(str_serial); + rr->rrdata.soa_rec.refresh = atoi(str_refresh); + rr->rrdata.soa_rec.retry = atoi(str_retry); + rr->rrdata.soa_rec.expire = atoi(str_expire); + rr->rrdata.soa_rec.minimum = atoi(str_minimum); + + memcpy(rr->key, key, strlen(key) + 1); + rr->type = ns_t_soa; + return 0; +} + +static int rwrap_create_fake_cname_rr(const char *key, + const char *value, + struct rwrap_fake_rr *rr) +{ + memcpy(rr->rrdata.cname_rec , value, strlen(value) + 1); + memcpy(rr->key, key, strlen(key) + 1); + rr->type = ns_t_cname; + return 0; +} + +/* Prepares a fake header with a single response. Advances header_blob */ +static ssize_t rwrap_fake_header(uint8_t **header_blob, size_t remaining, + size_t ancount, size_t arcount) +{ + uint8_t *hb; + HEADER *h; + + if (remaining < NS_HFIXEDSZ) { + RWRAP_LOG(RWRAP_LOG_ERROR, "Buffer too small!\n"); + return -1; + } + + hb = *header_blob; + memset(hb, 0, NS_HFIXEDSZ); + + h = (HEADER *) hb; + h->id = res_randomid(); /* random query ID */ + h->qr = 1; /* response flag */ + h->rd = 1; /* recursion desired */ + h->ra = 1; /* resursion available */ + + h->qdcount = htons(1); /* no. of questions */ + h->ancount = htons(ancount); /* no. of answers */ + h->arcount = htons(arcount); /* no. of add'tl records */ + + hb += NS_HFIXEDSZ; /* move past the header */ + *header_blob = hb; + + return NS_HFIXEDSZ; +} + +static ssize_t rwrap_fake_question(const char *question, + uint16_t type, + uint8_t **question_ptr, + size_t remaining) +{ + uint8_t *qb = *question_ptr; + int n; + + n = ns_name_compress(question, qb, remaining, NULL, NULL); + if (n < 0) { + RWRAP_LOG(RWRAP_LOG_ERROR, + "Failed to compress [%s]\n", question); + return -1; + } + + qb += n; + remaining -= n; + + if (remaining < 2 * sizeof(uint16_t)) { + RWRAP_LOG(RWRAP_LOG_ERROR, "Buffer too small!\n"); + return -1; + } + + NS_PUT16(type, qb); + NS_PUT16(ns_c_in, qb); + + *question_ptr = qb; + return n + 2 * sizeof(uint16_t); +} + +static ssize_t rwrap_fake_rdata_common(uint16_t type, + size_t rdata_size, + const char *key, + size_t remaining, + uint8_t **rdata_ptr) +{ + uint8_t *rd = *rdata_ptr; + ssize_t written = 0; + + written = ns_name_compress(key, rd, remaining, NULL, NULL); + if (written < 0) { + RWRAP_LOG(RWRAP_LOG_ERROR, + "Failed to compress [%s]\n", key); + return -1; + } + rd += written; + remaining -= written; + + if (remaining < 3 * sizeof(uint16_t) + sizeof(uint32_t)) { + RWRAP_LOG(RWRAP_LOG_ERROR, "Buffer too small\n"); + return -1; + } + + NS_PUT16(type, rd); + NS_PUT16(ns_c_in, rd); + NS_PUT32(RWRAP_DEFAULT_FAKE_TTL, rd); + NS_PUT16(rdata_size, rd); + + if (remaining < rdata_size) { + RWRAP_LOG(RWRAP_LOG_ERROR, "Buffer too small\n"); + return -1; + } + + *rdata_ptr = rd; + return written + 3 * sizeof(uint16_t) + sizeof(uint32_t) + rdata_size; +} + +static ssize_t rwrap_fake_a(struct rwrap_fake_rr *rr, + uint8_t *answer_ptr, + size_t anslen) +{ + uint8_t *a = answer_ptr; + ssize_t resp_size; + + if (rr == NULL || rr->type != ns_t_a) { + RWRAP_LOG(RWRAP_LOG_ERROR, + "Malformed record, no or wrong value!\n"); + return -1; + } + RWRAP_LOG(RWRAP_LOG_TRACE, "Adding A RR"); + + resp_size = rwrap_fake_rdata_common(ns_t_a, sizeof(struct in_addr), rr->key, + anslen, &a); + if (resp_size < 0) { + return -1; + } + + memcpy(a, &rr->rrdata.a_rec, sizeof(struct in_addr)); + + return resp_size; +} + +static ssize_t rwrap_fake_aaaa(struct rwrap_fake_rr *rr, + uint8_t *answer, + size_t anslen) +{ + uint8_t *a = answer; + ssize_t resp_size; + + if (rr == NULL || rr->type != ns_t_aaaa) { + RWRAP_LOG(RWRAP_LOG_ERROR, + "Malformed record, no or wrong value!\n"); + return -1; + } + RWRAP_LOG(RWRAP_LOG_TRACE, "Adding AAAA RR"); + + resp_size = rwrap_fake_rdata_common(ns_t_aaaa, sizeof(struct in6_addr), + rr->key, anslen, &a); + if (resp_size < 0) { + return -1; + } + + memcpy(a, &rr->rrdata.aaaa_rec, sizeof(struct in6_addr)); + + return resp_size; +} + +static ssize_t rwrap_fake_srv(struct rwrap_fake_rr *rr, + uint8_t *answer, + size_t anslen) +{ + uint8_t *a = answer; + ssize_t resp_size; + size_t rdata_size; + unsigned char hostname_compressed[MAXDNAME]; + ssize_t compressed_len; + + if (rr == NULL || rr->type != ns_t_srv) { + RWRAP_LOG(RWRAP_LOG_ERROR, + "Malformed record, no or wrong value!\n"); + return -1; + } + RWRAP_LOG(RWRAP_LOG_TRACE, "Adding SRV RR"); + rdata_size = 3 * sizeof(uint16_t); + + /* 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; + } + rdata_size += compressed_len; + -- Samba Shared Repository