Merge from vendor branch OPENSSL:
[dragonfly.git] / contrib / bind-9.3 / bin / named / lwdnoop.c
1 /*
2  * Copyright (C) 2004  Internet Systems Consortium, Inc. ("ISC")
3  * Copyright (C) 2000, 2001  Internet Software Consortium.
4  *
5  * Permission to use, copy, modify, and distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15  * PERFORMANCE OF THIS SOFTWARE.
16  */
17
18 /* $Id: lwdnoop.c,v 1.6.208.1 2004/03/06 10:21:19 marka Exp $ */
19
20 #include <config.h>
21
22 #include <isc/socket.h>
23 #include <isc/util.h>
24
25 #include <named/types.h>
26 #include <named/lwdclient.h>
27
28 void
29 ns_lwdclient_processnoop(ns_lwdclient_t *client, lwres_buffer_t *b) {
30         lwres_nooprequest_t *req;
31         lwres_noopresponse_t resp;
32         isc_result_t result;
33         lwres_result_t lwres;
34         isc_region_t r;
35         lwres_buffer_t lwb;
36
37         REQUIRE(NS_LWDCLIENT_ISRECVDONE(client));
38         INSIST(client->byaddr == NULL);
39
40         req = NULL;
41
42         result = lwres_nooprequest_parse(client->clientmgr->lwctx,
43                                          b, &client->pkt, &req);
44         if (result != LWRES_R_SUCCESS)
45                 goto out;
46
47         client->pkt.recvlength = LWRES_RECVLENGTH;
48         client->pkt.authtype = 0; /* XXXMLG */
49         client->pkt.authlength = 0;
50         client->pkt.result = LWRES_R_SUCCESS;
51
52         resp.datalength = req->datalength;
53         resp.data = req->data;
54
55         lwres = lwres_noopresponse_render(client->clientmgr->lwctx, &resp,
56                                           &client->pkt, &lwb);
57         if (lwres != LWRES_R_SUCCESS)
58                 goto out;
59
60         r.base = lwb.base;
61         r.length = lwb.used;
62         client->sendbuf = r.base;
63         client->sendlength = r.length;
64         result = ns_lwdclient_sendreply(client, &r);
65         if (result != ISC_R_SUCCESS)
66                 goto out;
67
68         /*
69          * We can now destroy request.
70          */
71         lwres_nooprequest_free(client->clientmgr->lwctx, &req);
72
73         NS_LWDCLIENT_SETSEND(client);
74
75         return;
76
77  out:
78         if (req != NULL)
79                 lwres_nooprequest_free(client->clientmgr->lwctx, &req);
80
81         if (lwb.base != NULL)
82                 lwres_context_freemem(client->clientmgr->lwctx,
83                                       lwb.base, lwb.length);
84
85         ns_lwdclient_errorpktsend(client, LWRES_R_FAILURE);
86 }