1
/* Copyright (c) 2009 Sam Trenholme
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions
9
* 1. Redistributions of source code must retain the above copyright
10
* notice, this list of conditions and the following disclaimer.
11
* 2. Redistributions in binary form must reproduce the above copyright
12
* notice, this list of conditions and the following disclaimer in the
13
* documentation and/or other materials provided with the distribution.
15
* This software is provided 'as is' with no guarantees of correctness or
16
* fitness for purpose.
19
/* DwRecurse.c: Used for functions and framework so Deadwood has full
20
* recursive DNS support */
23
#include "DwStr_functions.h"
27
extern int32_t key_n[];
29
/* See if two strings pointing to dname objects are the
30
* same. p1: pointer to the first string; p2: pointer to the second
31
* string; pmax: Maximum possible value for either string
32
* 1 if they are, 0 if they are not, -1 on error */
34
int dwx_dname_issame(uint8_t *p1, uint8_t *p2, uint8_t *pmax1,
36
int len = 0, counter = 0;
42
for(counter = 0; counter < 260; counter++) {
44
if(len > 63 || len < 0) {
45
return -1; /* Invalid length */
51
for(;len >= 0 && counter < 260; len--) {
55
if(p1 > pmax1 || p2 > pmax2) {
66
/* See if two domain names embedded in a Deadwood string object are the
67
* same. 1 if they are, 0 if they are not, -1 on error */
68
int dwx_dname_issame_dw(dw_str *in, uint32_t offset1, uint32_t offset2) {
69
uint8_t *p1 = 0, *p2 = 0, *pmax = 0;
71
if(dw_assert_sanity(in) == -1 ||
72
offset1 > in->len || offset2 > in->len) {
76
p1 = in->str + offset1;
77
p2 = in->str + offset2;
78
pmax = in->str + in->len;
80
return dwx_dname_issame(p1,p2,pmax,pmax);
84
/* See if two domain name objects embedded in different Deadwood string
85
* objects are the same. 1 if they are, 0 if they are not, -1 on error */
86
int dwx_dname_issame_2dw(dw_str *in1, uint32_t offset1, dw_str *in2,
88
uint8_t *p1 = 0, *p2 = 0, *pmax1 = 0, *pmax2 = 0;
90
if(dw_assert_sanity(in1) == -1 || dw_assert_sanity(in2) == -1 ||
91
offset1 > in1->len || offset2 > in2->len) {
95
p1 = in1->str + offset1;
96
p2 = in2->str + offset2;
97
pmax1 = in1->str + in1->len;
98
pmax2 = in2->str + in2->len;
100
return dwx_dname_issame(p1,p2,pmax1,pmax2);
104
/* A complete DNS response is one where:
106
* * If the only response is in the NS area, the response is a SOA response
109
* * If there is an AN area, either the first response is not a CNAME, or
110
* if it is a CNAME, there is a subsequent response that is not a CNAME,
111
* as long as it is a proper CNAME chain. Note that this is a complete
112
* record if they asked for a CNAME.
114
* An incomplete DNS response is one where:
116
* * There is a NS section with NS referrals. Sometimes, the AR
117
* section will have A and AAAA records for the NS records (glue).
119
* * In the AN area there is a CNAME record, but no (what they asked for)
120
* record, or if there is, it's not the same name they asked for.