1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-25 06:04:04 +03:00

libdns: Convert dns_udp_request to 0/errno

Replaces 5 calls to unix_to_werror with just one

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
This commit is contained in:
Volker Lendecke 2015-12-06 11:31:23 +01:00 committed by Jeremy Allison
parent 190e2c013b
commit dfceb51da8
3 changed files with 24 additions and 23 deletions

View File

@ -23,9 +23,8 @@
#include "system/network.h" #include "system/network.h"
#include <tevent.h> #include <tevent.h>
#include "lib/tsocket/tsocket.h" #include "lib/tsocket/tsocket.h"
#include "libcli/util/werror.h"
#include "libcli/dns/libdns.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 "lib/util/samba_util.h"
#include "libcli/util/error.h" #include "libcli/util/error.h"
#include "librpc/gen_ndr/dns.h" #include "librpc/gen_ndr/dns.h"
@ -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, ret = tsocket_address_inet_from_strings(state, "ip", NULL, 0,
&local_addr); &local_addr);
if (ret != 0) { if (ret != 0) {
tevent_req_werror(req, unix_to_werror(errno)); tevent_req_error(req, errno);
return tevent_req_post(req, ev); return tevent_req_post(req, ev);
} }
ret = tsocket_address_inet_from_strings(state, "ip", server_addr_string, ret = tsocket_address_inet_from_strings(state, "ip", server_addr_string,
DNS_SERVICE_PORT, &server_addr); DNS_SERVICE_PORT, &server_addr);
if (ret != 0) { if (ret != 0) {
tevent_req_werror(req, unix_to_werror(errno)); tevent_req_error(req, errno);
return tevent_req_post(req, ev); return tevent_req_post(req, ev);
} }
ret = tdgram_inet_udp_socket(local_addr, server_addr, state, &dgram); ret = tdgram_inet_udp_socket(local_addr, server_addr, state, &dgram);
if (ret != 0) { if (ret != 0) {
tevent_req_werror(req, unix_to_werror(errno)); tevent_req_error(req, errno);
return tevent_req_post(req, ev); return tevent_req_post(req, ev);
} }
@ -118,12 +117,12 @@ static void dns_udp_request_get_reply(struct tevent_req *subreq)
TALLOC_FREE(subreq); TALLOC_FREE(subreq);
if (len == -1 && err != 0) { if (len == -1 && err != 0) {
tevent_req_werror(req, unix_to_werror(err)); tevent_req_error(req, err);
return; return;
} }
if (len != state->query_len) { if (len != state->query_len) {
tevent_req_werror(req, WERR_NET_WRITE_FAULT); tevent_req_error(req, EIO);
return; return;
} }
@ -150,7 +149,7 @@ static void dns_udp_request_done(struct tevent_req *subreq)
TALLOC_FREE(subreq); TALLOC_FREE(subreq);
if (len == -1 && err != 0) { if (len == -1 && err != 0) {
tevent_req_werror(req, unix_to_werror(err)); tevent_req_error(req, err);
return; return;
} }
@ -159,23 +158,23 @@ static void dns_udp_request_done(struct tevent_req *subreq)
tevent_req_done(req); tevent_req_done(req);
} }
WERROR dns_udp_request_recv(struct tevent_req *req, int dns_udp_request_recv(struct tevent_req *req,
TALLOC_CTX *mem_ctx, TALLOC_CTX *mem_ctx,
uint8_t **reply, uint8_t **reply,
size_t *reply_len) size_t *reply_len)
{ {
struct dns_udp_request_state *state = tevent_req_data(req, struct dns_udp_request_state *state = tevent_req_data(req,
struct dns_udp_request_state); 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); tevent_req_received(req);
return w_error; return err;
} }
*reply = talloc_move(mem_ctx, &state->reply); *reply = talloc_move(mem_ctx, &state->reply);
*reply_len = state->reply_len; *reply_len = state->reply_len;
tevent_req_received(req); tevent_req_received(req);
return WERR_OK; return 0;
} }

View File

@ -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 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 buffer that will be allocated and filled with the dns reply
*@param reply_len length of the reply buffer *@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, int dns_udp_request_recv(struct tevent_req *req,
TALLOC_CTX *mem_ctx, TALLOC_CTX *mem_ctx,
uint8_t **reply, uint8_t **reply,
size_t *reply_len); size_t *reply_len);
#endif /*__LIBDNS_H__*/ #endif /*__LIBDNS_H__*/

View File

@ -203,12 +203,14 @@ static void ask_forwarder_done(struct tevent_req *subreq)
req, struct ask_forwarder_state); req, struct ask_forwarder_state);
DATA_BLOB in_blob; DATA_BLOB in_blob;
enum ndr_err_code ndr_err; enum ndr_err_code ndr_err;
WERROR ret; int ret;
ret = dns_udp_request_recv(subreq, state, ret = dns_udp_request_recv(subreq, state,
&in_blob.data, &in_blob.length); &in_blob.data, &in_blob.length);
TALLOC_FREE(subreq); TALLOC_FREE(subreq);
if (tevent_req_werror(req, ret)) {
if (ret != 0) {
tevent_req_werror(req, unix_to_werror(ret));
return; return;
} }