@@ -151,7 +151,7 @@ static void rwrap_log(enum rwrap_dbglvl_e dbglvl,
151
151
} \
152
152
} while(0);
153
153
154
- #define RWRAP_MAX_RECURSION 5
154
+ #define RWRAP_MAX_RECURSION 64
155
155
156
156
/* Priority and weight can be omitted from the hosts file, but need to be part
157
157
* of the output
@@ -786,6 +786,19 @@ static int rwrap_get_record(const char *hostfile, unsigned recursion,
786
786
const char * query , int type ,
787
787
struct rwrap_fake_rr * rr );
788
788
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
+
789
802
static int rwrap_srv_recurse (const char * hostfile , unsigned recursion ,
790
803
const char * query , struct rwrap_fake_rr * rr )
791
804
{
@@ -826,6 +839,7 @@ static int rwrap_get_record(const char *hostfile, unsigned recursion,
826
839
char * key = NULL ;
827
840
char * value = NULL ;
828
841
int rc = ENOENT ;
842
+ unsigned num_uris = 0 ;
829
843
830
844
if (recursion >= RWRAP_MAX_RECURSION ) {
831
845
RWRAP_LOG (RWRAP_LOG_ERROR , "Recursed too deep!\n" );
@@ -867,6 +881,18 @@ static int rwrap_get_record(const char *hostfile, unsigned recursion,
867
881
}
868
882
q [0 ] = '\0' ;
869
883
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
+
870
896
if (TYPE_MATCH (type , ns_t_a , rec_type , "A" , key , query )) {
871
897
rc = rwrap_create_fake_a_rr (key , value , rr );
872
898
break ;
@@ -890,6 +916,10 @@ static int rwrap_get_record(const char *hostfile, unsigned recursion,
890
916
} else if (TYPE_MATCH (type , ns_t_uri ,
891
917
rec_type , "URI" , key , query )) {
892
918
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
+ }
893
923
break ;
894
924
} else if (TYPE_MATCH (type , ns_t_soa ,
895
925
rec_type , "SOA" , key , query )) {
@@ -977,6 +1007,17 @@ static int rwrap_ancount(struct rwrap_fake_rr *rrs, int qtype)
977
1007
int i ;
978
1008
int ancount = 0 ;
979
1009
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
+
980
1021
/* Include all RRs in the stack until the sought type
981
1022
* in the answer section. This is the case i.e. when looking
982
1023
* up an A record but the name points to a CNAME
0 commit comments