[SCM] Resolv Wrapper Repository - branch master updated

Michael Adam obnox at samba.org
Thu Sep 1 13:55:37 UTC 2016


The branch, master has been updated
       via  d749ca2 Test a URI query with multiple answers
       via  cc7e8b0 Support multiple URI answers
      from  1e16cd1 rwrap: Remove name compression from URI RR

https://git.samba.org/?p=resolv_wrapper.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit d749ca20c5fced2b1279154ef8a4ca5c5e599dd2
Author: Matt Rogers <mrogers at redhat.com>
Date:   Thu Aug 25 12:59:31 2016 -0400

    Test a URI query with multiple answers
    
    Signed-off-by: Matt Rogers <mrogers at redhat.com
    Reviewed-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Michael Adam <obnox at samba.org>

commit cc7e8b01f88d68c30c84ea9045f8a123f6f30720
Author: Matt Rogers <mrogers at redhat.com>
Date:   Thu Aug 25 12:57:09 2016 -0400

    Support multiple URI answers
    
    Add URI record use of recursion to rwrap_get_record(), for collecting
    multiple URI answers under a single query.  Increase the
    RWRAP_MAX_RECURSION limit to handle more URI records.
    
    Signed-off-by: Matt Rogers <mrogers at redhat.com>
    Reviewed-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Michael Adam <obnox at samba.org>

-----------------------------------------------------------------------

Summary of changes:
 src/resolv_wrapper.c  | 43 ++++++++++++++++++++++++++++++++++++++++++-
 tests/fake_hosts.in   |  2 ++
 tests/test_dns_fake.c | 33 +++++++++++++++++++++++++++------
 3 files changed, 71 insertions(+), 7 deletions(-)


Changeset truncated at 500 lines:

diff --git a/src/resolv_wrapper.c b/src/resolv_wrapper.c
index 7a3c9b7..c6f06e3 100644
--- a/src/resolv_wrapper.c
+++ b/src/resolv_wrapper.c
@@ -151,7 +151,7 @@ static void rwrap_log(enum rwrap_dbglvl_e dbglvl,
 	}							\
 } while(0);
 
-#define RWRAP_MAX_RECURSION 5
+#define RWRAP_MAX_RECURSION 64
 
 /* Priority and weight can be omitted from the hosts file, but need to be part
  * of the output
@@ -786,6 +786,19 @@ static int rwrap_get_record(const char *hostfile, unsigned recursion,
 			    const char *query, int type,
 			    struct rwrap_fake_rr *rr);
 
+static int rwrap_uri_recurse(const char *hostfile, unsigned recursion,
+			     const char *query, struct rwrap_fake_rr *rr)
+{
+	int rc;
+
+	rc = rwrap_get_record(hostfile, recursion, query, ns_t_uri, rr);
+	if (rc == ENOENT) {
+		rc = 0;
+	}
+
+	return rc;
+}
+
 static int rwrap_srv_recurse(const char *hostfile, unsigned recursion,
 			     const char *query, struct rwrap_fake_rr *rr)
 {
@@ -826,6 +839,7 @@ static int rwrap_get_record(const char *hostfile, unsigned recursion,
 	char *key = NULL;
 	char *value = NULL;
 	int rc = ENOENT;
+	unsigned num_uris = 0;
 
 	if (recursion >= RWRAP_MAX_RECURSION) {
 		RWRAP_LOG(RWRAP_LOG_ERROR, "Recursed too deep!\n");
@@ -867,6 +881,18 @@ static int rwrap_get_record(const char *hostfile, unsigned recursion,
 		}
 		q[0] = '\0';
 
+		if (type == ns_t_uri && recursion > 0) {
+			/* Skip non-URI records. */
+			if (!TYPE_MATCH(type, ns_t_uri, rec_type, "URI", key, query)) {
+				continue;
+			}
+			/* Skip previous records based on the recurse depth. */
+			num_uris++;
+			if (num_uris <= recursion) {
+				continue;
+			}
+		}
+
 		if (TYPE_MATCH(type, ns_t_a, rec_type, "A", key, query)) {
 			rc = rwrap_create_fake_a_rr(key, value, rr);
 			break;
@@ -890,6 +916,10 @@ static int rwrap_get_record(const char *hostfile, unsigned recursion,
 		} else if (TYPE_MATCH(type, ns_t_uri,
 				      rec_type, "URI", key, query)) {
 			rc = rwrap_create_fake_uri_rr(key, value, rr);
+			if (rc == 0) {
+				/* Recurse to collect multiple URI answers under a single key. */
+				rc = rwrap_uri_recurse(hostfile, recursion + 1, key, rr + 1);
+			}
 			break;
 		} else if (TYPE_MATCH(type, ns_t_soa,
 				      rec_type, "SOA", key, query)) {
@@ -977,6 +1007,17 @@ static int rwrap_ancount(struct rwrap_fake_rr *rrs, int qtype)
 	int i;
 	int ancount = 0;
 
+	/* For URI return the number of URIs. */
+	if (qtype == ns_t_uri) {
+		for (i = 0; i < RWRAP_MAX_RECURSION; i++) {
+			if (rwrap_known_type(rrs[i].type) &&
+			    rrs[i].type == qtype) {
+				ancount++;
+			}
+		}
+		return ancount;
+	}
+
 	/* Include all RRs in the stack until the sought type
 	 * in the answer section. This is the case i.e. when looking
 	 * up an A record but the name points to a CNAME
diff --git a/tests/fake_hosts.in b/tests/fake_hosts.in
index 1812979..824af57 100644
--- a/tests/fake_hosts.in
+++ b/tests/fake_hosts.in
@@ -13,5 +13,7 @@ A krb5.cwrap.org 127.0.0.23
 A ns1.cwrap.org 127.0.0.24
 A ns2.cwrap.org 127.0.0.25
 URI _vpn.cwrap.org https://vpn.cwrap.org/VPN 2 5
+URI _vpn.cwrap.org https://vpn2.cwrap.org/VPN 2 10
+URI _vpn.cwrap.org https://vpn3.cwrap.org/VPN 2 20
 URI _ftp.cwrap.org ftp://ftp.cwrap.org/public
 PTR 22.0.0.127.in-addr.arpa www.cwrap.org
diff --git a/tests/test_dns_fake.c b/tests/test_dns_fake.c
index 348135c..28ee57a 100644
--- a/tests/test_dns_fake.c
+++ b/tests/test_dns_fake.c
@@ -371,20 +371,20 @@ static void test_res_fake_uri_query(void **state)
 
 	rv = res_nquery(&dnsstate, "_vpn.cwrap.org", ns_c_in, ns_t_uri,
 			answer, sizeof(answer));
-	assert_in_range(rv, 1, 100);
+	assert_in_range(rv, 1, ANSIZE);
 
 	ns_initparse(answer, sizeof(answer), &handle);
 
 	/*
-	 * The query must finish w/o an error, have one answer and the answer
-	 * must be a parseable RR of type URI and have the priority, weight, and
-	 * URI string as in the hosts file.
+	 * The query must finish w/o an error, have three answers and they must be
+	 * a parseable RR of type URI and have the priority, weight, and URI string
+	 * as in the hosts file.
 	 */
 	assert_int_equal(ns_msg_getflag(handle, ns_f_rcode), ns_r_noerror);
-	assert_int_equal(ns_msg_count(handle, ns_s_an), 1);
+	assert_int_equal(ns_msg_count(handle, ns_s_an), 3);
+
 	assert_int_equal(ns_parserr(&handle, ns_s_an, 0, &rr), 0);
 	assert_int_equal(ns_rr_type(rr), ns_t_uri);
-
 	rrdata = ns_rr_rdata(rr);
 	NS_GET16(prio, rrdata);
 	NS_GET16(weight, rrdata);
@@ -392,6 +392,27 @@ static void test_res_fake_uri_query(void **state)
 	assert_int_equal(prio, 2);
 	assert_int_equal(weight, 5);
 	assert_string_equal(rrdata, "https://vpn.cwrap.org/VPN");
+
+	assert_int_equal(ns_parserr(&handle, ns_s_an, 1, &rr), 0);
+	assert_int_equal(ns_rr_type(rr), ns_t_uri);
+	rrdata = ns_rr_rdata(rr);
+	NS_GET16(prio, rrdata);
+	NS_GET16(weight, rrdata);
+
+	assert_int_equal(prio, 2);
+	assert_int_equal(weight, 10);
+	assert_string_equal(rrdata, "https://vpn2.cwrap.org/VPN");
+
+	assert_int_equal(ns_parserr(&handle, ns_s_an, 2, &rr), 0);
+	assert_int_equal(ns_rr_type(rr), ns_t_uri);
+	rrdata = ns_rr_rdata(rr);
+	NS_GET16(prio, rrdata);
+	NS_GET16(weight, rrdata);
+
+	assert_int_equal(prio, 2);
+	assert_int_equal(weight, 20);
+	assert_string_equal(rrdata, "https://vpn3.cwrap.org/VPN");
+
 }
 
 /*


-- 
Resolv Wrapper Repository



More information about the samba-cvs mailing list