Skip to content

Commit cc7e8b0

Browse files
Matt Rogersobnoxxx
Matt Rogers
authored andcommitted
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@redhat.com> Reviewed-by: Andreas Schneider <asn@samba.org> Reviewed-by: Michael Adam <obnox@samba.org>
1 parent 1e16cd1 commit cc7e8b0

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

src/resolv_wrapper.c

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ static void rwrap_log(enum rwrap_dbglvl_e dbglvl,
151151
} \
152152
} while(0);
153153

154-
#define RWRAP_MAX_RECURSION 5
154+
#define RWRAP_MAX_RECURSION 64
155155

156156
/* Priority and weight can be omitted from the hosts file, but need to be part
157157
* of the output
@@ -786,6 +786,19 @@ static int rwrap_get_record(const char *hostfile, unsigned recursion,
786786
const char *query, int type,
787787
struct rwrap_fake_rr *rr);
788788

789+
static int rwrap_uri_recurse(const char *hostfile, unsigned recursion,
790+
const char *query, struct rwrap_fake_rr *rr)
791+
{
792+
int rc;
793+
794+
rc = rwrap_get_record(hostfile, recursion, query, ns_t_uri, rr);
795+
if (rc == ENOENT) {
796+
rc = 0;
797+
}
798+
799+
return rc;
800+
}
801+
789802
static int rwrap_srv_recurse(const char *hostfile, unsigned recursion,
790803
const char *query, struct rwrap_fake_rr *rr)
791804
{
@@ -826,6 +839,7 @@ static int rwrap_get_record(const char *hostfile, unsigned recursion,
826839
char *key = NULL;
827840
char *value = NULL;
828841
int rc = ENOENT;
842+
unsigned num_uris = 0;
829843

830844
if (recursion >= RWRAP_MAX_RECURSION) {
831845
RWRAP_LOG(RWRAP_LOG_ERROR, "Recursed too deep!\n");
@@ -867,6 +881,18 @@ static int rwrap_get_record(const char *hostfile, unsigned recursion,
867881
}
868882
q[0] = '\0';
869883

884+
if (type == ns_t_uri && recursion > 0) {
885+
/* Skip non-URI records. */
886+
if (!TYPE_MATCH(type, ns_t_uri, rec_type, "URI", key, query)) {
887+
continue;
888+
}
889+
/* Skip previous records based on the recurse depth. */
890+
num_uris++;
891+
if (num_uris <= recursion) {
892+
continue;
893+
}
894+
}
895+
870896
if (TYPE_MATCH(type, ns_t_a, rec_type, "A", key, query)) {
871897
rc = rwrap_create_fake_a_rr(key, value, rr);
872898
break;
@@ -890,6 +916,10 @@ static int rwrap_get_record(const char *hostfile, unsigned recursion,
890916
} else if (TYPE_MATCH(type, ns_t_uri,
891917
rec_type, "URI", key, query)) {
892918
rc = rwrap_create_fake_uri_rr(key, value, rr);
919+
if (rc == 0) {
920+
/* Recurse to collect multiple URI answers under a single key. */
921+
rc = rwrap_uri_recurse(hostfile, recursion + 1, key, rr + 1);
922+
}
893923
break;
894924
} else if (TYPE_MATCH(type, ns_t_soa,
895925
rec_type, "SOA", key, query)) {
@@ -977,6 +1007,17 @@ static int rwrap_ancount(struct rwrap_fake_rr *rrs, int qtype)
9771007
int i;
9781008
int ancount = 0;
9791009

1010+
/* For URI return the number of URIs. */
1011+
if (qtype == ns_t_uri) {
1012+
for (i = 0; i < RWRAP_MAX_RECURSION; i++) {
1013+
if (rwrap_known_type(rrs[i].type) &&
1014+
rrs[i].type == qtype) {
1015+
ancount++;
1016+
}
1017+
}
1018+
return ancount;
1019+
}
1020+
9801021
/* Include all RRs in the stack until the sought type
9811022
* in the answer section. This is the case i.e. when looking
9821023
* up an A record but the name points to a CNAME

0 commit comments

Comments
 (0)