Coverage Report

Created: 2025-07-18 07:03

/src/bind9/lib/dns/rdata/generic/minfo_14.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
#ifndef RDATA_GENERIC_MINFO_14_C
15
#define RDATA_GENERIC_MINFO_14_C
16
17
10.7k
#define RRTYPE_MINFO_ATTRIBUTES (0)
18
19
static isc_result_t
20
930
fromtext_minfo(ARGS_FROMTEXT) {
21
930
  isc_token_t token;
22
930
  dns_fixedname_t fn;
23
930
  dns_name_t *name = dns_fixedname_initname(&fn);
24
930
  isc_buffer_t buffer;
25
930
  int i;
26
930
  bool ok;
27
28
930
  REQUIRE(type == dns_rdatatype_minfo);
29
30
930
  UNUSED(type);
31
930
  UNUSED(rdclass);
32
930
  UNUSED(callbacks);
33
34
930
  if (origin == NULL) {
35
8
    origin = dns_rootname;
36
8
  }
37
38
2.76k
  for (i = 0; i < 2; i++) {
39
1.85k
    RETERR(isc_lex_getmastertoken(lexer, &token,
40
1.85k
                isc_tokentype_string, false));
41
1.84k
    buffer_fromregion(&buffer, &token.value.as_region);
42
1.84k
    RETTOK(dns_name_fromtext(name, &buffer, origin, options));
43
1.83k
    RETTOK(dns_name_towire(name, NULL, target));
44
1.83k
    ok = true;
45
1.83k
    if ((options & DNS_RDATA_CHECKNAMES) != 0) {
46
0
      ok = dns_name_ismailbox(name);
47
0
    }
48
1.83k
    if (!ok && (options & DNS_RDATA_CHECKNAMESFAIL) != 0) {
49
0
      RETTOK(DNS_R_BADNAME);
50
0
    }
51
1.83k
    if (!ok && callbacks != NULL) {
52
0
      warn_badname(name, lexer, callbacks);
53
0
    }
54
1.83k
  }
55
917
  return ISC_R_SUCCESS;
56
930
}
57
58
static isc_result_t
59
694
totext_minfo(ARGS_TOTEXT) {
60
694
  isc_region_t region;
61
694
  dns_name_t rmail;
62
694
  dns_name_t email;
63
694
  dns_name_t prefix;
64
694
  unsigned int opts;
65
66
694
  REQUIRE(rdata->type == dns_rdatatype_minfo);
67
694
  REQUIRE(rdata->length != 0);
68
69
694
  dns_name_init(&rmail);
70
694
  dns_name_init(&email);
71
694
  dns_name_init(&prefix);
72
73
694
  dns_rdata_toregion(rdata, &region);
74
75
694
  dns_name_fromregion(&rmail, &region);
76
694
  isc_region_consume(&region, rmail.length);
77
78
694
  dns_name_fromregion(&email, &region);
79
694
  isc_region_consume(&region, email.length);
80
81
694
  opts = name_prefix(&rmail, tctx->origin, &prefix)
82
694
           ? DNS_NAME_OMITFINALDOT
83
694
           : 0;
84
694
  RETERR(dns_name_totext(&prefix, opts, target));
85
86
694
  RETERR(str_totext(" ", target));
87
88
694
  opts = name_prefix(&email, tctx->origin, &prefix)
89
694
           ? DNS_NAME_OMITFINALDOT
90
694
           : 0;
91
694
  return dns_name_totext(&prefix, opts, target);
92
694
}
93
94
static isc_result_t
95
862
fromwire_minfo(ARGS_FROMWIRE) {
96
862
  dns_name_t rmail;
97
862
  dns_name_t email;
98
99
862
  REQUIRE(type == dns_rdatatype_minfo);
100
101
862
  UNUSED(type);
102
862
  UNUSED(rdclass);
103
104
862
  dctx = dns_decompress_setpermitted(dctx, true);
105
106
862
  dns_name_init(&rmail);
107
862
  dns_name_init(&email);
108
109
862
  RETERR(dns_name_fromwire(&rmail, source, dctx, target));
110
745
  return dns_name_fromwire(&email, source, dctx, target);
111
862
}
112
113
static isc_result_t
114
352
towire_minfo(ARGS_TOWIRE) {
115
352
  isc_region_t region;
116
352
  dns_name_t rmail;
117
352
  dns_name_t email;
118
119
352
  REQUIRE(rdata->type == dns_rdatatype_minfo);
120
352
  REQUIRE(rdata->length != 0);
121
122
352
  dns_compress_setpermitted(cctx, true);
123
124
352
  dns_name_init(&rmail);
125
352
  dns_name_init(&email);
126
127
352
  dns_rdata_toregion(rdata, &region);
128
129
352
  dns_name_fromregion(&rmail, &region);
130
352
  isc_region_consume(&region, name_length(&rmail));
131
132
352
  RETERR(dns_name_towire(&rmail, cctx, target));
133
134
350
  dns_name_fromregion(&rmail, &region);
135
350
  isc_region_consume(&region, rmail.length);
136
137
350
  return dns_name_towire(&rmail, cctx, target);
138
352
}
139
140
static int
141
1.64k
compare_minfo(ARGS_COMPARE) {
142
1.64k
  isc_region_t region1;
143
1.64k
  isc_region_t region2;
144
1.64k
  dns_name_t name1;
145
1.64k
  dns_name_t name2;
146
1.64k
  int order;
147
148
1.64k
  REQUIRE(rdata1->type == rdata2->type);
149
1.64k
  REQUIRE(rdata1->rdclass == rdata2->rdclass);
150
1.64k
  REQUIRE(rdata1->type == dns_rdatatype_minfo);
151
1.64k
  REQUIRE(rdata1->length != 0);
152
1.64k
  REQUIRE(rdata2->length != 0);
153
154
1.64k
  dns_name_init(&name1);
155
1.64k
  dns_name_init(&name2);
156
157
1.64k
  dns_rdata_toregion(rdata1, &region1);
158
1.64k
  dns_rdata_toregion(rdata2, &region2);
159
160
1.64k
  dns_name_fromregion(&name1, &region1);
161
1.64k
  dns_name_fromregion(&name2, &region2);
162
163
1.64k
  order = dns_name_rdatacompare(&name1, &name2);
164
1.64k
  if (order != 0) {
165
420
    return order;
166
420
  }
167
168
1.22k
  isc_region_consume(&region1, name_length(&name1));
169
1.22k
  isc_region_consume(&region2, name_length(&name2));
170
171
1.22k
  dns_name_init(&name1);
172
1.22k
  dns_name_init(&name2);
173
174
1.22k
  dns_name_fromregion(&name1, &region1);
175
1.22k
  dns_name_fromregion(&name2, &region2);
176
177
1.22k
  order = dns_name_rdatacompare(&name1, &name2);
178
1.22k
  return order;
179
1.64k
}
180
181
static isc_result_t
182
0
fromstruct_minfo(ARGS_FROMSTRUCT) {
183
0
  dns_rdata_minfo_t *minfo = source;
184
0
  isc_region_t region;
185
186
0
  REQUIRE(type == dns_rdatatype_minfo);
187
0
  REQUIRE(minfo != NULL);
188
0
  REQUIRE(minfo->common.rdtype == type);
189
0
  REQUIRE(minfo->common.rdclass == rdclass);
190
191
0
  UNUSED(type);
192
0
  UNUSED(rdclass);
193
194
0
  dns_name_toregion(&minfo->rmailbox, &region);
195
0
  RETERR(isc_buffer_copyregion(target, &region));
196
0
  dns_name_toregion(&minfo->emailbox, &region);
197
0
  return isc_buffer_copyregion(target, &region);
198
0
}
199
200
static isc_result_t
201
0
tostruct_minfo(ARGS_TOSTRUCT) {
202
0
  dns_rdata_minfo_t *minfo = target;
203
0
  isc_region_t region;
204
0
  dns_name_t name;
205
206
0
  REQUIRE(rdata->type == dns_rdatatype_minfo);
207
0
  REQUIRE(minfo != NULL);
208
0
  REQUIRE(rdata->length != 0);
209
210
0
  minfo->common.rdclass = rdata->rdclass;
211
0
  minfo->common.rdtype = rdata->type;
212
213
0
  dns_name_init(&name);
214
0
  dns_rdata_toregion(rdata, &region);
215
0
  dns_name_fromregion(&name, &region);
216
0
  dns_name_init(&minfo->rmailbox);
217
0
  name_duporclone(&name, mctx, &minfo->rmailbox);
218
0
  isc_region_consume(&region, name_length(&name));
219
220
0
  dns_name_fromregion(&name, &region);
221
0
  dns_name_init(&minfo->emailbox);
222
0
  name_duporclone(&name, mctx, &minfo->emailbox);
223
0
  minfo->mctx = mctx;
224
0
  return ISC_R_SUCCESS;
225
0
}
226
227
static void
228
0
freestruct_minfo(ARGS_FREESTRUCT) {
229
0
  dns_rdata_minfo_t *minfo = source;
230
231
0
  REQUIRE(minfo != NULL);
232
0
  REQUIRE(minfo->common.rdtype == dns_rdatatype_minfo);
233
234
0
  if (minfo->mctx == NULL) {
235
0
    return;
236
0
  }
237
238
0
  dns_name_free(&minfo->rmailbox, minfo->mctx);
239
0
  dns_name_free(&minfo->emailbox, minfo->mctx);
240
0
  minfo->mctx = NULL;
241
0
}
242
243
static isc_result_t
244
0
additionaldata_minfo(ARGS_ADDLDATA) {
245
0
  REQUIRE(rdata->type == dns_rdatatype_minfo);
246
247
0
  UNUSED(rdata);
248
0
  UNUSED(owner);
249
0
  UNUSED(add);
250
0
  UNUSED(arg);
251
252
0
  return ISC_R_SUCCESS;
253
0
}
254
255
static isc_result_t
256
0
digest_minfo(ARGS_DIGEST) {
257
0
  isc_region_t r;
258
0
  dns_name_t name;
259
0
  isc_result_t result;
260
261
0
  REQUIRE(rdata->type == dns_rdatatype_minfo);
262
263
0
  dns_rdata_toregion(rdata, &r);
264
0
  dns_name_init(&name);
265
0
  dns_name_fromregion(&name, &r);
266
0
  result = dns_name_digest(&name, digest, arg);
267
0
  if (result != ISC_R_SUCCESS) {
268
0
    return result;
269
0
  }
270
0
  isc_region_consume(&r, name_length(&name));
271
0
  dns_name_init(&name);
272
0
  dns_name_fromregion(&name, &r);
273
274
0
  return dns_name_digest(&name, digest, arg);
275
0
}
276
277
static bool
278
0
checkowner_minfo(ARGS_CHECKOWNER) {
279
0
  REQUIRE(type == dns_rdatatype_minfo);
280
281
0
  UNUSED(name);
282
0
  UNUSED(type);
283
0
  UNUSED(rdclass);
284
0
  UNUSED(wildcard);
285
286
0
  return true;
287
0
}
288
289
static bool
290
0
checknames_minfo(ARGS_CHECKNAMES) {
291
0
  isc_region_t region;
292
0
  dns_name_t name;
293
294
0
  REQUIRE(rdata->type == dns_rdatatype_minfo);
295
296
0
  UNUSED(owner);
297
298
0
  dns_rdata_toregion(rdata, &region);
299
0
  dns_name_init(&name);
300
0
  dns_name_fromregion(&name, &region);
301
0
  if (!dns_name_ismailbox(&name)) {
302
0
    if (bad != NULL) {
303
0
      dns_name_clone(&name, bad);
304
0
    }
305
0
    return false;
306
0
  }
307
0
  isc_region_consume(&region, name_length(&name));
308
0
  dns_name_fromregion(&name, &region);
309
0
  if (!dns_name_ismailbox(&name)) {
310
0
    if (bad != NULL) {
311
0
      dns_name_clone(&name, bad);
312
0
    }
313
0
    return false;
314
0
  }
315
0
  return true;
316
0
}
317
318
static int
319
0
casecompare_minfo(ARGS_COMPARE) {
320
0
  return compare_minfo(rdata1, rdata2);
321
0
}
322
323
#endif /* RDATA_GENERIC_MINFO_14_C */