1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
|
/*
Unix SMB/CIFS implementation.
DNS server handler for queries
Copyright (C) 2010 Kai Blin <kai@samba.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "includes.h"
#include "smbd/service_task.h"
#include "libcli/util/werror.h"
#include "librpc/ndr/libndr.h"
#include "librpc/gen_ndr/ndr_dns.h"
#include "librpc/gen_ndr/ndr_dnsp.h"
#include <ldb.h>
#include "param/param.h"
#include "dsdb/samdb/samdb.h"
#include "dsdb/common/util.h"
#include "dns_server/dns_server.h"
#include "libcli/dns/libdns.h"
#include "lib/util/util_net.h"
#include "lib/util/tevent_werror.h"
#include "auth/auth.h"
#include "auth/credentials/credentials.h"
#include "auth/gensec/gensec.h"
#undef DBGC_CLASS
#define DBGC_CLASS DBGC_DNS
static WERROR create_response_rr(const struct dns_name_question *question,
const struct dnsp_DnssrvRpcRecord *rec,
struct dns_res_rec **answers, uint16_t *ancount)
{
struct dns_res_rec *ans = *answers;
uint16_t ai = *ancount;
char *tmp;
uint32_t i;
ZERO_STRUCT(ans[ai]);
switch (rec->wType) {
case DNS_QTYPE_CNAME:
ans[ai].rdata.cname_record = talloc_strdup(ans, rec->data.cname);
W_ERROR_HAVE_NO_MEMORY(ans[ai].rdata.cname_record);
break;
case DNS_QTYPE_A:
ans[ai].rdata.ipv4_record = talloc_strdup(ans, rec->data.ipv4);
W_ERROR_HAVE_NO_MEMORY(ans[ai].rdata.ipv4_record);
break;
case DNS_QTYPE_AAAA:
ans[ai].rdata.ipv6_record = talloc_strdup(ans, rec->data.ipv6);
W_ERROR_HAVE_NO_MEMORY(ans[ai].rdata.ipv6_record);
break;
case DNS_TYPE_NS:
ans[ai].rdata.ns_record = talloc_strdup(ans, rec->data.ns);
W_ERROR_HAVE_NO_MEMORY(ans[ai].rdata.ns_record);
break;
case DNS_QTYPE_SRV:
ans[ai].rdata.srv_record.priority = rec->data.srv.wPriority;
ans[ai].rdata.srv_record.weight = rec->data.srv.wWeight;
ans[ai].rdata.srv_record.port = rec->data.srv.wPort;
ans[ai].rdata.srv_record.target = talloc_strdup(
ans, rec->data.srv.nameTarget);
W_ERROR_HAVE_NO_MEMORY(ans[ai].rdata.srv_record.target);
break;
case DNS_QTYPE_SOA:
ans[ai].rdata.soa_record.mname = talloc_strdup(
ans, rec->data.soa.mname);
W_ERROR_HAVE_NO_MEMORY(ans[ai].rdata.soa_record.mname);
ans[ai].rdata.soa_record.rname = talloc_strdup(
ans, rec->data.soa.rname);
W_ERROR_HAVE_NO_MEMORY(ans[ai].rdata.soa_record.rname);
ans[ai].rdata.soa_record.serial = rec->data.soa.serial;
ans[ai].rdata.soa_record.refresh = rec->data.soa.refresh;
ans[ai].rdata.soa_record.retry = rec->data.soa.retry;
ans[ai].rdata.soa_record.expire = rec->data.soa.expire;
ans[ai].rdata.soa_record.minimum = rec->data.soa.minimum;
break;
case DNS_QTYPE_PTR:
ans[ai].rdata.ptr_record = talloc_strdup(ans, rec->data.ptr);
break;
case DNS_QTYPE_MX:
ans[ai].rdata.mx_record.preference = rec->data.mx.wPriority;
ans[ai].rdata.mx_record.exchange = talloc_strdup(
ans, rec->data.mx.nameTarget);
if (ans[ai].rdata.mx_record.exchange == NULL) {
return WERR_NOMEM;
}
break;
case DNS_QTYPE_TXT:
tmp = talloc_asprintf(ans, "\"%s\"", rec->data.txt.str[0]);
W_ERROR_HAVE_NO_MEMORY(tmp);
for (i=1; i<rec->data.txt.count; i++) {
tmp = talloc_asprintf_append_buffer(
tmp, " \"%s\"", rec->data.txt.str[i]);
W_ERROR_HAVE_NO_MEMORY(tmp);
}
ans[ai].rdata.txt_record.txt = tmp;
break;
default:
DEBUG(0, ("Got unhandled type %u query.\n", rec->wType));
return DNS_ERR(NOT_IMPLEMENTED);
}
ans[ai].name = talloc_strdup(ans, question->name);
W_ERROR_HAVE_NO_MEMORY(ans[ai].name);
ans[ai].rr_type = rec->wType;
ans[ai].rr_class = DNS_QCLASS_IN;
ans[ai].ttl = rec->dwTtlSeconds;
ans[ai].length = UINT16_MAX;
ai++;
*answers = ans;
*ancount = ai;
return WERR_OK;
}
struct ask_forwarder_state {
struct tevent_context *ev;
uint16_t id;
struct dns_name_packet in_packet;
};
static void ask_forwarder_done(struct tevent_req *subreq);
static struct tevent_req *ask_forwarder_send(
TALLOC_CTX *mem_ctx, struct tevent_context *ev,
const char *forwarder, struct dns_name_question *question)
{
struct tevent_req *req, *subreq;
struct ask_forwarder_state *state;
struct dns_name_packet out_packet = { 0, };
DATA_BLOB out_blob;
enum ndr_err_code ndr_err;
req = tevent_req_create(mem_ctx, &state, struct ask_forwarder_state);
if (req == NULL) {
return NULL;
}
state->ev = ev;
generate_random_buffer((uint8_t *)&state->id, sizeof(state->id));
if (!is_ipaddress(forwarder)) {
DEBUG(0, ("Invalid 'dns forwarder' setting '%s', needs to be "
"an IP address\n", forwarder));
tevent_req_werror(req, DNS_ERR(NAME_ERROR));
return tevent_req_post(req, ev);
}
out_packet.id = state->id;
out_packet.operation |= DNS_OPCODE_QUERY | DNS_FLAG_RECURSION_DESIRED;
out_packet.qdcount = 1;
out_packet.questions = question;
ndr_err = ndr_push_struct_blob(
&out_blob, state, &out_packet,
(ndr_push_flags_fn_t)ndr_push_dns_name_packet);
if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
tevent_req_werror(req, DNS_ERR(SERVER_FAILURE));
return tevent_req_post(req, ev);
}
subreq = dns_udp_request_send(state, ev, forwarder, out_blob.data,
out_blob.length);
if (tevent_req_nomem(subreq, req)) {
return tevent_req_post(req, ev);
}
tevent_req_set_callback(subreq, ask_forwarder_done, req);
return req;
}
static void ask_forwarder_done(struct tevent_req *subreq)
{
struct tevent_req *req = tevent_req_callback_data(
subreq, struct tevent_req);
struct ask_forwarder_state *state = tevent_req_data(
req, struct ask_forwarder_state);
DATA_BLOB in_blob;
enum ndr_err_code ndr_err;
WERROR ret;
ret = dns_udp_request_recv(subreq, state,
&in_blob.data, &in_blob.length);
TALLOC_FREE(subreq);
if (tevent_req_werror(req, ret)) {
return;
}
ndr_err = ndr_pull_struct_blob(
&in_blob, state, &state->in_packet,
(ndr_pull_flags_fn_t)ndr_pull_dns_name_packet);
if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
tevent_req_werror(req, DNS_ERR(SERVER_FAILURE));
return;
}
if (state->in_packet.id != state->id) {
tevent_req_werror(req, DNS_ERR(NAME_ERROR));
return;
}
tevent_req_done(req);
}
static WERROR ask_forwarder_recv(
struct tevent_req *req, TALLOC_CTX *mem_ctx,
struct dns_res_rec **answers, uint16_t *ancount,
struct dns_res_rec **nsrecs, uint16_t *nscount,
struct dns_res_rec **additional, uint16_t *arcount)
{
struct ask_forwarder_state *state = tevent_req_data(
req, struct ask_forwarder_state);
struct dns_name_packet *in_packet = &state->in_packet;
WERROR err;
if (tevent_req_is_werror(req, &err)) {
return err;
}
*ancount = in_packet->ancount;
*answers = talloc_move(mem_ctx, &in_packet->answers);
*nscount = in_packet->nscount;
*nsrecs = talloc_move(mem_ctx, &in_packet->nsrecs);
*arcount = in_packet->arcount;
*additional = talloc_move(mem_ctx, &in_packet->additional);
return WERR_OK;
}
static WERROR handle_question(struct dns_server *dns,
TALLOC_CTX *mem_ctx,
const struct dns_name_question *question,
struct dns_res_rec **answers, uint16_t *ancount)
{
struct dns_res_rec *ans = *answers;
WERROR werror;
unsigned int ri;
struct dnsp_DnssrvRpcRecord *recs;
uint16_t rec_count, ai = *ancount;
struct ldb_dn *dn = NULL;
werror = dns_name2dn(dns, mem_ctx, question->name, &dn);
W_ERROR_NOT_OK_RETURN(werror);
werror = dns_lookup_records(dns, mem_ctx, dn, &recs, &rec_count);
W_ERROR_NOT_OK_RETURN(werror);
ans = talloc_realloc(mem_ctx, ans, struct dns_res_rec, rec_count + ai);
if (ans == NULL) {
return WERR_NOMEM;
}
for (ri = 0; ri < rec_count; ri++) {
if ((recs[ri].wType == DNS_TYPE_CNAME) &&
((question->question_type == DNS_QTYPE_A) ||
(question->question_type == DNS_QTYPE_AAAA))) {
struct dns_name_question *new_q =
talloc(mem_ctx, struct dns_name_question);
if (new_q == NULL) {
return WERR_NOMEM;
}
/* We reply with one more record, so grow the array */
ans = talloc_realloc(mem_ctx, ans, struct dns_res_rec,
rec_count + 1);
if (ans == NULL) {
TALLOC_FREE(new_q);
return WERR_NOMEM;
}
/* First put in the CNAME record */
werror = create_response_rr(question, &recs[ri], &ans, &ai);
if (!W_ERROR_IS_OK(werror)) {
return werror;
}
/* And then look up the name it points at.. */
/* First build up the new question */
new_q->question_type = question->question_type;
new_q->question_class = question->question_class;
if (new_q->question_type == DNS_QTYPE_A) {
new_q->name = talloc_strdup(new_q, recs[ri].data.ipv4);
} else if (new_q->question_type == DNS_QTYPE_AAAA) {
new_q->name = talloc_strdup(new_q, recs[ri].data.ipv6);
}
if (new_q->name == NULL) {
TALLOC_FREE(new_q);
return WERR_NOMEM;
}
/* and then call the lookup again */
werror = handle_question(dns, mem_ctx, new_q, &ans, &ai);
if (!W_ERROR_IS_OK(werror)) {
return werror;
}
continue;
}
if ((question->question_type != DNS_QTYPE_ALL) &&
(recs[ri].wType != question->question_type)) {
continue;
}
werror = create_response_rr(question, &recs[ri], &ans, &ai);
if (!W_ERROR_IS_OK(werror)) {
return werror;
}
}
if (ai == 0) {
return DNS_ERR(NAME_ERROR);
}
*ancount = ai;
*answers = ans;
return WERR_OK;
}
static NTSTATUS create_tkey(struct dns_server *dns,
const char* name,
const char* algorithm,
struct dns_server_tkey **tkey)
{
NTSTATUS status;
struct dns_server_tkey_store *store = dns->tkeys;
struct dns_server_tkey *k = talloc_zero(store, struct dns_server_tkey);
if (k == NULL) {
return NT_STATUS_NO_MEMORY;
}
k->name = talloc_strdup(k, name);
if (k->name == NULL) {
return NT_STATUS_NO_MEMORY;
}
k->algorithm = talloc_strdup(k, algorithm);
if (k->algorithm == NULL) {
return NT_STATUS_NO_MEMORY;
}
status = samba_server_gensec_start(k,
dns->task->event_ctx,
dns->task->msg_ctx,
dns->task->lp_ctx,
dns->server_credentials,
"dns",
&k->gensec);
if (!NT_STATUS_IS_OK(status)) {
DEBUG(1, ("Failed to start GENSEC server code: %s\n", nt_errstr(status)));
*tkey = NULL;
return status;
}
gensec_want_feature(k->gensec, GENSEC_FEATURE_SIGN);
status = gensec_start_mech_by_oid(k->gensec, GENSEC_OID_SPNEGO);
if (!NT_STATUS_IS_OK(status)) {
DEBUG(1, ("Failed to start GENSEC server code: %s\n",
nt_errstr(status)));
*tkey = NULL;
return status;
}
if (store->tkeys[store->next_idx] != NULL) {
TALLOC_FREE(store->tkeys[store->next_idx]);
}
store->tkeys[store->next_idx] = k;
(store->next_idx)++;
store->next_idx %= store->size;
*tkey = k;
return NT_STATUS_OK;
}
static NTSTATUS accept_gss_ticket(TALLOC_CTX *mem_ctx,
struct dns_server *dns,
struct dns_server_tkey *tkey,
const DATA_BLOB *key,
DATA_BLOB *reply,
uint16_t *dns_auth_error)
{
NTSTATUS status;
status = gensec_update(tkey->gensec, mem_ctx, dns->task->event_ctx,
*key, reply);
if (NT_STATUS_EQUAL(NT_STATUS_MORE_PROCESSING_REQUIRED, status)) {
*dns_auth_error = DNS_RCODE_OK;
return status;
}
if (NT_STATUS_IS_OK(status)) {
status = gensec_session_info(tkey->gensec, tkey, &tkey->session_info);
if (!NT_STATUS_IS_OK(status)) {
*dns_auth_error = DNS_RCODE_BADKEY;
return status;
}
*dns_auth_error = DNS_RCODE_OK;
}
return status;
}
static WERROR handle_tkey(struct dns_server *dns,
TALLOC_CTX *mem_ctx,
const struct dns_name_packet *in,
struct dns_request_state *state,
struct dns_res_rec **answers,
uint16_t *ancount)
{
struct dns_res_rec *in_tkey = NULL;
struct dns_res_rec *ret_tkey;
uint16_t i;
for (i = 0; i < in->arcount; i++) {
if (in->additional[i].rr_type == DNS_QTYPE_TKEY) {
in_tkey = &in->additional[i];
break;
}
}
/* If this is a TKEY query, it should have a TKEY RR.
* Behaviour is not really specified in RFC 2930 or RFC 3645, but
* FORMAT_ERROR seems to be what BIND uses .*/
if (in_tkey == NULL) {
return DNS_ERR(FORMAT_ERROR);
}
ret_tkey = talloc_zero(mem_ctx, struct dns_res_rec);
if (ret_tkey == NULL) {
return WERR_NOMEM;
}
ret_tkey->name = talloc_strdup(ret_tkey, in_tkey->name);
if (ret_tkey->name == NULL) {
return WERR_NOMEM;
}
ret_tkey->rr_type = DNS_QTYPE_TKEY;
ret_tkey->rr_class = DNS_QCLASS_ANY;
ret_tkey->length = UINT16_MAX;
ret_tkey->rdata.tkey_record.algorithm = talloc_strdup(ret_tkey,
in_tkey->rdata.tkey_record.algorithm);
if (ret_tkey->rdata.tkey_record.algorithm == NULL) {
return WERR_NOMEM;
}
ret_tkey->rdata.tkey_record.inception = in_tkey->rdata.tkey_record.inception;
ret_tkey->rdata.tkey_record.expiration = in_tkey->rdata.tkey_record.expiration;
ret_tkey->rdata.tkey_record.mode = in_tkey->rdata.tkey_record.mode;
switch (in_tkey->rdata.tkey_record.mode) {
case DNS_TKEY_MODE_DH:
/* FIXME: According to RFC 2930, we MUST support this, but we don't.
* Still, claim it's a bad key instead of a bad mode */
ret_tkey->rdata.tkey_record.error = DNS_RCODE_BADKEY;
break;
case DNS_TKEY_MODE_GSSAPI: {
NTSTATUS status;
struct dns_server_tkey *tkey;
DATA_BLOB key;
DATA_BLOB reply;
tkey = dns_find_tkey(dns->tkeys, in->questions[0].name);
if (tkey != NULL && tkey->complete) {
/* TODO: check if the key is still valid */
DEBUG(1, ("Rejecting tkey negotiation for already established key\n"));
ret_tkey->rdata.tkey_record.error = DNS_RCODE_BADNAME;
break;
}
if (tkey == NULL) {
status = create_tkey(dns, in->questions[0].name,
in_tkey->rdata.tkey_record.algorithm,
&tkey);
if (!NT_STATUS_IS_OK(status)) {
ret_tkey->rdata.tkey_record.error = DNS_RCODE_BADKEY;
return ntstatus_to_werror(status);
}
}
key.data = in_tkey->rdata.tkey_record.key_data;
key.length = in_tkey->rdata.tkey_record.key_size;
status = accept_gss_ticket(ret_tkey, dns, tkey, &key, &reply,
&ret_tkey->rdata.tkey_record.error);
if (NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
DEBUG(1, ("More processing required\n"));
ret_tkey->rdata.tkey_record.error = DNS_RCODE_BADKEY;
} else if (NT_STATUS_IS_OK(status)) {
DEBUG(1, ("Tkey handshake completed\n"));
ret_tkey->rdata.tkey_record.key_size = reply.length;
ret_tkey->rdata.tkey_record.key_data = talloc_memdup(ret_tkey,
reply.data,
reply.length);
state->sign = true;
state->key_name = talloc_strdup(mem_ctx, tkey->name);
if (state->key_name == NULL) {
return WERR_NOMEM;
}
} else {
DEBUG(1, ("GSS key negotiation returned %s\n", nt_errstr(status)));
ret_tkey->rdata.tkey_record.error = DNS_RCODE_BADKEY;
}
break;
}
case DNS_TKEY_MODE_DELETE:
/* TODO: implement me */
DEBUG(1, ("Should delete tkey here\n"));
ret_tkey->rdata.tkey_record.error = DNS_RCODE_OK;
break;
case DNS_TKEY_MODE_NULL:
case DNS_TKEY_MODE_SERVER:
case DNS_TKEY_MODE_CLIENT:
case DNS_TKEY_MODE_LAST:
/* We don't have to implement these, return a mode error */
ret_tkey->rdata.tkey_record.error = DNS_RCODE_BADMODE;
break;
default:
DEBUG(1, ("Unsupported TKEY mode %d\n",
in_tkey->rdata.tkey_record.mode));
}
*answers = ret_tkey;
*ancount = 1;
return WERR_OK;
}
struct dns_server_process_query_state {
struct dns_res_rec *answers;
uint16_t ancount;
struct dns_res_rec *nsrecs;
uint16_t nscount;
struct dns_res_rec *additional;
uint16_t arcount;
};
static void dns_server_process_query_got_response(struct tevent_req *subreq);
struct tevent_req *dns_server_process_query_send(
TALLOC_CTX *mem_ctx, struct tevent_context *ev,
struct dns_server *dns, struct dns_request_state *req_state,
const struct dns_name_packet *in)
{
struct tevent_req *req, *subreq;
struct dns_server_process_query_state *state;
req = tevent_req_create(mem_ctx, &state,
struct dns_server_process_query_state);
if (req == NULL) {
return NULL;
}
if (in->qdcount != 1) {
tevent_req_werror(req, DNS_ERR(FORMAT_ERROR));
return tevent_req_post(req, ev);
}
/* Windows returns NOT_IMPLEMENTED on this as well */
if (in->questions[0].question_class == DNS_QCLASS_NONE) {
tevent_req_werror(req, DNS_ERR(NOT_IMPLEMENTED));
return tevent_req_post(req, ev);
}
if (in->questions[0].question_type == DNS_QTYPE_TKEY) {
WERROR err;
err = handle_tkey(dns, state, in, req_state,
&state->answers, &state->ancount);
if (tevent_req_werror(req, err)) {
return tevent_req_post(req, ev);
}
tevent_req_done(req);
return tevent_req_post(req, ev);
}
if (dns_authorative_for_zone(dns, in->questions[0].name)) {
WERROR err;
req_state->flags |= DNS_FLAG_AUTHORITATIVE;
err = handle_question(dns, state, &in->questions[0],
&state->answers, &state->ancount);
if (tevent_req_werror(req, err)) {
return tevent_req_post(req, ev);
}
tevent_req_done(req);
return tevent_req_post(req, ev);
}
if ((req_state->flags & DNS_FLAG_RECURSION_DESIRED) &&
(req_state->flags & DNS_FLAG_RECURSION_AVAIL)) {
DEBUG(2, ("Not authoritative for '%s', forwarding\n",
in->questions[0].name));
subreq = ask_forwarder_send(
state, ev, lpcfg_dns_forwarder(dns->task->lp_ctx),
&in->questions[0]);
if (tevent_req_nomem(subreq, req)) {
return tevent_req_post(req, ev);
}
tevent_req_set_callback(
subreq, dns_server_process_query_got_response, req);
return req;
}
tevent_req_werror(req, DNS_ERR(NAME_ERROR));
return tevent_req_post(req, ev);
}
static void dns_server_process_query_got_response(struct tevent_req *subreq)
{
struct tevent_req *req = tevent_req_callback_data(
subreq, struct tevent_req);
struct dns_server_process_query_state *state = tevent_req_data(
req, struct dns_server_process_query_state);
WERROR err;
err = ask_forwarder_recv(subreq, state,
&state->answers, &state->ancount,
&state->nsrecs, &state->nscount,
&state->additional, &state->arcount);
TALLOC_FREE(subreq);
if (tevent_req_werror(req, err)) {
return;
}
tevent_req_done(req);
}
WERROR dns_server_process_query_recv(
struct tevent_req *req, TALLOC_CTX *mem_ctx,
struct dns_res_rec **answers, uint16_t *ancount,
struct dns_res_rec **nsrecs, uint16_t *nscount,
struct dns_res_rec **additional, uint16_t *arcount)
{
struct dns_server_process_query_state *state = tevent_req_data(
req, struct dns_server_process_query_state);
WERROR err;
if (tevent_req_is_werror(req, &err)) {
return err;
}
*answers = talloc_move(mem_ctx, &state->answers);
*ancount = state->ancount;
*nsrecs = talloc_move(mem_ctx, &state->nsrecs);
*nscount = state->nscount;
*additional = talloc_move(mem_ctx, &state->additional);
*arcount = state->arcount;
return WERR_OK;
}
|