/src/bind9/lib/dns/rdata/generic/x25_19.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (C) Internet Systems Consortium, Inc. ("ISC") |
3 | | * |
4 | | * SPDX-License-Identifier: MPL-2.0 |
5 | | * |
6 | | * This Source Code Form is subject to the terms of the Mozilla Public |
7 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
8 | | * file, you can obtain one at https://mozilla.org/MPL/2.0/. |
9 | | * |
10 | | * See the COPYRIGHT file distributed with this work for additional |
11 | | * information regarding copyright ownership. |
12 | | */ |
13 | | |
14 | | /* RFC1183 */ |
15 | | |
16 | | #ifndef RDATA_GENERIC_X25_19_C |
17 | | #define RDATA_GENERIC_X25_19_C |
18 | | |
19 | 9.53k | #define RRTYPE_X25_ATTRIBUTES (0) |
20 | | |
21 | | static isc_result_t |
22 | 1.03k | fromtext_x25(ARGS_FROMTEXT) { |
23 | 1.03k | isc_token_t token; |
24 | 1.03k | unsigned int i; |
25 | | |
26 | 1.03k | REQUIRE(type == dns_rdatatype_x25); |
27 | | |
28 | 1.03k | UNUSED(type); |
29 | 1.03k | UNUSED(rdclass); |
30 | 1.03k | UNUSED(origin); |
31 | 1.03k | UNUSED(options); |
32 | 1.03k | UNUSED(callbacks); |
33 | | |
34 | 1.03k | RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_qstring, |
35 | 1.03k | false)); |
36 | 1.03k | if (token.value.as_textregion.length < 4) { |
37 | 4 | RETTOK(DNS_R_SYNTAX); |
38 | 4 | } |
39 | 7.14k | for (i = 0; i < token.value.as_textregion.length; i++) { |
40 | 6.13k | if (!isdigit((unsigned char)token.value.as_textregion.base[i])) |
41 | 10 | { |
42 | 10 | RETTOK(ISC_R_RANGE); |
43 | 10 | } |
44 | 6.13k | } |
45 | 1.01k | RETTOK(txt_fromtext(&token.value.as_textregion, target)); |
46 | 1.01k | return ISC_R_SUCCESS; |
47 | 1.01k | } |
48 | | |
49 | | static isc_result_t |
50 | 662 | totext_x25(ARGS_TOTEXT) { |
51 | 662 | isc_region_t region; |
52 | | |
53 | 662 | UNUSED(tctx); |
54 | | |
55 | 662 | REQUIRE(rdata->type == dns_rdatatype_x25); |
56 | 662 | REQUIRE(rdata->length != 0); |
57 | | |
58 | 662 | dns_rdata_toregion(rdata, ®ion); |
59 | 662 | return txt_totext(®ion, true, target); |
60 | 662 | } |
61 | | |
62 | | static isc_result_t |
63 | 768 | fromwire_x25(ARGS_FROMWIRE) { |
64 | 768 | isc_region_t sr; |
65 | 768 | unsigned int i; |
66 | | |
67 | 768 | REQUIRE(type == dns_rdatatype_x25); |
68 | | |
69 | 768 | UNUSED(type); |
70 | 768 | UNUSED(dctx); |
71 | 768 | UNUSED(rdclass); |
72 | | |
73 | 768 | isc_buffer_activeregion(source, &sr); |
74 | 768 | if (sr.length < 5 || sr.base[0] != (sr.length - 1)) { |
75 | 64 | return DNS_R_FORMERR; |
76 | 64 | } |
77 | 3.76k | for (i = 1; i < sr.length; i++) { |
78 | 3.09k | if (sr.base[i] < 0x30 || sr.base[i] > 0x39) { |
79 | 31 | return DNS_R_FORMERR; |
80 | 31 | } |
81 | 3.09k | } |
82 | 673 | return txt_fromwire(source, target); |
83 | 704 | } |
84 | | |
85 | | static isc_result_t |
86 | 355 | towire_x25(ARGS_TOWIRE) { |
87 | 355 | UNUSED(cctx); |
88 | | |
89 | 355 | REQUIRE(rdata->type == dns_rdatatype_x25); |
90 | 355 | REQUIRE(rdata->length != 0); |
91 | | |
92 | 355 | return mem_tobuffer(target, rdata->data, rdata->length); |
93 | 355 | } |
94 | | |
95 | | static int |
96 | 109k | compare_x25(ARGS_COMPARE) { |
97 | 109k | isc_region_t r1; |
98 | 109k | isc_region_t r2; |
99 | | |
100 | 109k | REQUIRE(rdata1->type == rdata2->type); |
101 | 109k | REQUIRE(rdata1->rdclass == rdata2->rdclass); |
102 | 109k | REQUIRE(rdata1->type == dns_rdatatype_x25); |
103 | 109k | REQUIRE(rdata1->length != 0); |
104 | 109k | REQUIRE(rdata2->length != 0); |
105 | | |
106 | 109k | dns_rdata_toregion(rdata1, &r1); |
107 | 109k | dns_rdata_toregion(rdata2, &r2); |
108 | 109k | return isc_region_compare(&r1, &r2); |
109 | 109k | } |
110 | | |
111 | | static isc_result_t |
112 | 0 | fromstruct_x25(ARGS_FROMSTRUCT) { |
113 | 0 | dns_rdata_x25_t *x25 = source; |
114 | 0 | uint8_t i; |
115 | |
|
116 | 0 | REQUIRE(type == dns_rdatatype_x25); |
117 | 0 | REQUIRE(x25 != NULL); |
118 | 0 | REQUIRE(x25->common.rdtype == type); |
119 | 0 | REQUIRE(x25->common.rdclass == rdclass); |
120 | 0 | REQUIRE(x25->x25 != NULL && x25->x25_len != 0); |
121 | |
|
122 | 0 | UNUSED(type); |
123 | 0 | UNUSED(rdclass); |
124 | |
|
125 | 0 | if (x25->x25_len < 4) { |
126 | 0 | return ISC_R_RANGE; |
127 | 0 | } |
128 | | |
129 | 0 | for (i = 0; i < x25->x25_len; i++) { |
130 | 0 | if (!isdigit((unsigned char)x25->x25[i])) { |
131 | 0 | return ISC_R_RANGE; |
132 | 0 | } |
133 | 0 | } |
134 | | |
135 | 0 | RETERR(uint8_tobuffer(x25->x25_len, target)); |
136 | 0 | return mem_tobuffer(target, x25->x25, x25->x25_len); |
137 | 0 | } |
138 | | |
139 | | static isc_result_t |
140 | 0 | tostruct_x25(ARGS_TOSTRUCT) { |
141 | 0 | dns_rdata_x25_t *x25 = target; |
142 | 0 | isc_region_t r; |
143 | |
|
144 | 0 | REQUIRE(rdata->type == dns_rdatatype_x25); |
145 | 0 | REQUIRE(x25 != NULL); |
146 | 0 | REQUIRE(rdata->length != 0); |
147 | |
|
148 | 0 | DNS_RDATACOMMON_INIT(x25, rdata->type, rdata->rdclass); |
149 | |
|
150 | 0 | dns_rdata_toregion(rdata, &r); |
151 | 0 | x25->x25_len = uint8_fromregion(&r); |
152 | 0 | isc_region_consume(&r, 1); |
153 | 0 | x25->x25 = mem_maybedup(mctx, r.base, x25->x25_len); |
154 | 0 | x25->mctx = mctx; |
155 | 0 | return ISC_R_SUCCESS; |
156 | 0 | } |
157 | | |
158 | | static void |
159 | 0 | freestruct_x25(ARGS_FREESTRUCT) { |
160 | 0 | dns_rdata_x25_t *x25 = source; |
161 | |
|
162 | 0 | REQUIRE(x25 != NULL); |
163 | 0 | REQUIRE(x25->common.rdtype == dns_rdatatype_x25); |
164 | |
|
165 | 0 | if (x25->mctx == NULL) { |
166 | 0 | return; |
167 | 0 | } |
168 | | |
169 | 0 | if (x25->x25 != NULL) { |
170 | 0 | isc_mem_free(x25->mctx, x25->x25); |
171 | 0 | } |
172 | 0 | x25->mctx = NULL; |
173 | 0 | } |
174 | | |
175 | | static isc_result_t |
176 | 0 | additionaldata_x25(ARGS_ADDLDATA) { |
177 | 0 | REQUIRE(rdata->type == dns_rdatatype_x25); |
178 | |
|
179 | 0 | UNUSED(rdata); |
180 | 0 | UNUSED(owner); |
181 | 0 | UNUSED(add); |
182 | 0 | UNUSED(arg); |
183 | |
|
184 | 0 | return ISC_R_SUCCESS; |
185 | 0 | } |
186 | | |
187 | | static isc_result_t |
188 | 0 | digest_x25(ARGS_DIGEST) { |
189 | 0 | isc_region_t r; |
190 | |
|
191 | 0 | REQUIRE(rdata->type == dns_rdatatype_x25); |
192 | |
|
193 | 0 | dns_rdata_toregion(rdata, &r); |
194 | |
|
195 | 0 | return (digest)(arg, &r); |
196 | 0 | } |
197 | | |
198 | | static bool |
199 | 0 | checkowner_x25(ARGS_CHECKOWNER) { |
200 | 0 | REQUIRE(type == dns_rdatatype_x25); |
201 | |
|
202 | 0 | UNUSED(name); |
203 | 0 | UNUSED(type); |
204 | 0 | UNUSED(rdclass); |
205 | 0 | UNUSED(wildcard); |
206 | |
|
207 | 0 | return true; |
208 | 0 | } |
209 | | |
210 | | static bool |
211 | 0 | checknames_x25(ARGS_CHECKNAMES) { |
212 | 0 | REQUIRE(rdata->type == dns_rdatatype_x25); |
213 | |
|
214 | 0 | UNUSED(rdata); |
215 | 0 | UNUSED(owner); |
216 | 0 | UNUSED(bad); |
217 | |
|
218 | 0 | return true; |
219 | 0 | } |
220 | | |
221 | | static int |
222 | 0 | casecompare_x25(ARGS_COMPARE) { |
223 | 0 | return compare_x25(rdata1, rdata2); |
224 | 0 | } |
225 | | |
226 | | #endif /* RDATA_GENERIC_X25_19_C */ |