Skip to content

Commit

Permalink
libdns: Convert dns_udp_request to 0/errno
Browse files Browse the repository at this point in the history
Replaces 5 calls to unix_to_werror with just one

Signed-off-by: Volker Lendecke <[email protected]>
Reviewed-by: Jeremy Allison <[email protected]>
  • Loading branch information
vlendec authored and jrasamba committed Dec 8, 2015
1 parent 190e2c0 commit dfceb51
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 23 deletions.
31 changes: 15 additions & 16 deletions libcli/dns/dns.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@
#include "system/network.h"
#include <tevent.h>
#include "lib/tsocket/tsocket.h"
#include "libcli/util/werror.h"
#include "libcli/dns/libdns.h"
#include "lib/util/tevent_werror.h"
#include "lib/util/tevent_unix.h"
#include "lib/util/samba_util.h"
#include "libcli/util/error.h"
#include "librpc/gen_ndr/dns.h"
Expand Down Expand Up @@ -67,20 +66,20 @@ struct tevent_req *dns_udp_request_send(TALLOC_CTX *mem_ctx,
ret = tsocket_address_inet_from_strings(state, "ip", NULL, 0,
&local_addr);
if (ret != 0) {
tevent_req_werror(req, unix_to_werror(errno));
tevent_req_error(req, errno);
return tevent_req_post(req, ev);
}

ret = tsocket_address_inet_from_strings(state, "ip", server_addr_string,
DNS_SERVICE_PORT, &server_addr);
if (ret != 0) {
tevent_req_werror(req, unix_to_werror(errno));
tevent_req_error(req, errno);
return tevent_req_post(req, ev);
}

ret = tdgram_inet_udp_socket(local_addr, server_addr, state, &dgram);
if (ret != 0) {
tevent_req_werror(req, unix_to_werror(errno));
tevent_req_error(req, errno);
return tevent_req_post(req, ev);
}

Expand Down Expand Up @@ -118,12 +117,12 @@ static void dns_udp_request_get_reply(struct tevent_req *subreq)
TALLOC_FREE(subreq);

if (len == -1 && err != 0) {
tevent_req_werror(req, unix_to_werror(err));
tevent_req_error(req, err);
return;
}

if (len != state->query_len) {
tevent_req_werror(req, WERR_NET_WRITE_FAULT);
tevent_req_error(req, EIO);
return;
}

Expand All @@ -150,7 +149,7 @@ static void dns_udp_request_done(struct tevent_req *subreq)
TALLOC_FREE(subreq);

if (len == -1 && err != 0) {
tevent_req_werror(req, unix_to_werror(err));
tevent_req_error(req, err);
return;
}

Expand All @@ -159,23 +158,23 @@ static void dns_udp_request_done(struct tevent_req *subreq)
tevent_req_done(req);
}

WERROR dns_udp_request_recv(struct tevent_req *req,
TALLOC_CTX *mem_ctx,
uint8_t **reply,
size_t *reply_len)
int dns_udp_request_recv(struct tevent_req *req,
TALLOC_CTX *mem_ctx,
uint8_t **reply,
size_t *reply_len)
{
struct dns_udp_request_state *state = tevent_req_data(req,
struct dns_udp_request_state);
WERROR w_error;
int err;

if (tevent_req_is_werror(req, &w_error)) {
if (tevent_req_is_unix_error(req, &err)) {
tevent_req_received(req);
return w_error;
return err;
}

*reply = talloc_move(mem_ctx, &state->reply);
*reply_len = state->reply_len;
tevent_req_received(req);

return WERR_OK;
return 0;
}
10 changes: 5 additions & 5 deletions libcli/dns/libdns.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ struct tevent_req *dns_udp_request_send(TALLOC_CTX *mem_ctx,
*@param mem_ctx talloc memory context to use for the reply string
*@param reply buffer that will be allocated and filled with the dns reply
*@param reply_len length of the reply buffer
*@return WERROR code depending on the async request result
*@return 0/errno
*/
WERROR dns_udp_request_recv(struct tevent_req *req,
TALLOC_CTX *mem_ctx,
uint8_t **reply,
size_t *reply_len);
int dns_udp_request_recv(struct tevent_req *req,
TALLOC_CTX *mem_ctx,
uint8_t **reply,
size_t *reply_len);

#endif /*__LIBDNS_H__*/
6 changes: 4 additions & 2 deletions source4/dns_server/dns_query.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,14 @@ static void ask_forwarder_done(struct tevent_req *subreq)
req, struct ask_forwarder_state);
DATA_BLOB in_blob;
enum ndr_err_code ndr_err;
WERROR ret;
int ret;

ret = dns_udp_request_recv(subreq, state,
&in_blob.data, &in_blob.length);
TALLOC_FREE(subreq);
if (tevent_req_werror(req, ret)) {

if (ret != 0) {
tevent_req_werror(req, unix_to_werror(ret));
return;
}

Expand Down

0 comments on commit dfceb51

Please sign in to comment.