~ubuntu-branches/ubuntu/raring/maradns/raring

« back to all changes in this revision

Viewing changes to deadwood-2.4.10/src/DwRecurse.c

  • Committer: Bazaar Package Importer
  • Author(s): Kai Hendry
  • Date: 2010-01-24 12:17:40 UTC
  • mfrom: (1.1.13 upstream) (10.1.4 sid)
  • Revision ID: james.westby@ubuntu.com-20100124121740-a4e1fjobwaouz443
Tags: 1.4.02-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (c) 2009 Sam Trenholme
 
2
 *
 
3
 * TERMS
 
4
 *
 
5
 * Redistribution and use in source and binary forms, with or without
 
6
 * modification, are permitted provided that the following conditions
 
7
 * are met:
 
8
 *
 
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.
 
14
 *
 
15
 * This software is provided 'as is' with no guarantees of correctness or
 
16
 * fitness for purpose.
 
17
 */
 
18
 
 
19
/* DwRecurse.c: Used for functions and framework so Deadwood has full
 
20
 * recursive DNS support */
 
21
 
 
22
#include "DwStr.h"
 
23
#include "DwStr_functions.h"
 
24
#include "DwDnsStr.h"
 
25
#include "DwHash.h"
 
26
#include "DwMararc.h"
 
27
extern int32_t key_n[];
 
28
 
 
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 */
 
33
 
 
34
int dwx_dname_issame(uint8_t *p1, uint8_t *p2, uint8_t *pmax1,
 
35
                uint8_t *pmax2) {
 
36
        int len = 0, counter = 0;
 
37
 
 
38
        if(*p1 != *p2) {
 
39
                return 0;
 
40
        }
 
41
 
 
42
        for(counter = 0; counter < 260; counter++) {
 
43
                len = *p1;
 
44
                if(len > 63 || len < 0) {
 
45
                        return -1; /* Invalid length */
 
46
                }
 
47
                if(len == 0) {
 
48
                        return 1; /* Same */
 
49
                }
 
50
 
 
51
                for(;len >= 0 && counter < 260; len--) {
 
52
                        p1++;
 
53
                        p2++;
 
54
                        counter++;
 
55
                        if(p1 > pmax1 || p2 > pmax2) {
 
56
                                return -1;
 
57
                        }
 
58
                        if(*p1 != *p2) {
 
59
                                return 0;
 
60
                        }
 
61
                }
 
62
        }
 
63
        return -1;
 
64
}
 
65
 
 
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;
 
70
 
 
71
        if(dw_assert_sanity(in) == -1 ||
 
72
                        offset1 > in->len || offset2 > in->len) {
 
73
                return -1;
 
74
        }
 
75
 
 
76
        p1 = in->str + offset1;
 
77
        p2 = in->str + offset2;
 
78
        pmax = in->str + in->len;
 
79
 
 
80
        return dwx_dname_issame(p1,p2,pmax,pmax);
 
81
 
 
82
}
 
83
 
 
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,
 
87
                        uint32_t offset2) {
 
88
        uint8_t *p1 = 0, *p2 = 0, *pmax1 = 0, *pmax2 = 0;
 
89
 
 
90
        if(dw_assert_sanity(in1) == -1 || dw_assert_sanity(in2) == -1 ||
 
91
                        offset1 > in1->len || offset2 > in2->len) {
 
92
                return -1;
 
93
        }
 
94
 
 
95
        p1 = in1->str + offset1;
 
96
        p2 = in2->str + offset2;
 
97
        pmax1 = in1->str + in1->len;
 
98
        pmax2 = in2->str + in2->len;
 
99
 
 
100
        return dwx_dname_issame(p1,p2,pmax1,pmax2);
 
101
 
 
102
}
 
103
 
 
104
/* A complete DNS response is one where:
 
105
 *
 
106
 * * If the only response is in the NS area, the response is a SOA response
 
107
 *   (not there)
 
108
 *
 
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.
 
113
 *
 
114
 * An incomplete DNS response is one where:
 
115
 *
 
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).
 
118
 *
 
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.
 
121
 *
 
122
 */
 
123
 
 
124
/* */