2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-30 05:57:52 +00:00

4474. [bug] win32: call WSAStartup in fromtext_in_wks so that

getprotobyname and getservbyname work.  [RT #43197]

(cherry picked from commit 82a50a619afa73ae9a212399505b9f1b327128cd)
This commit is contained in:
Mark Andrews 2016-10-05 12:29:00 +11:00
parent fe4d0fbc7c
commit f77ee20a6c
4 changed files with 55 additions and 10 deletions

View File

@ -1,3 +1,6 @@
4474. [bug] win32: call WSAStartup in fromtext_in_wks so that
getprotobyname and getservbyname work. [RT #43197]
4473. [bug] Only call fsync / _commit on regular files. [RT #43196] 4473. [bug] Only call fsync / _commit on regular files. [RT #43196]
4472. [bug] Named could fail to find the correct NSEC3 records when 4472. [bug] Named could fail to find the correct NSEC3 records when

View File

@ -17,6 +17,7 @@ sub.empty TXT sub.empty
sub NS ns.sub sub NS ns.sub
ns.sub A 1.2.3.4 ns.sub A 1.2.3.4
ns.sub AAAA 2002::1.2.3.4 ns.sub AAAA 2002::1.2.3.4
ns.sub WKS 1.2.3.4 udp domain
other.sub TXT other.sub other.sub TXT other.sub
secure NS secure secure NS secure
secure DS 1312 50 100 96EEB2FFD9B00CD4694E78278B5EFDAB0A80446567B69F634DA078F0 secure DS 1312 50 100 96EEB2FFD9B00CD4694E78278B5EFDAB0A80446567B69F634DA078F0

View File

@ -58,6 +58,19 @@
} \ } \
} while (0) } while (0)
#define CHECK(op) \
do { result = (op); \
if (result != ISC_R_SUCCESS) goto cleanup; \
} while (0)
#define CHECKTOK(op) \
do { result = (op); \
if (result != ISC_R_SUCCESS) { \
isc_lex_ungettoken(lexer, &token); \
goto cleanup; \
} \
} while (0)
#define DNS_AS_STR(t) ((t).value.as_textregion.base) #define DNS_AS_STR(t) ((t).value.as_textregion.base)
#define ARGS_FROMTEXT int rdclass, dns_rdatatype_t type, \ #define ARGS_FROMTEXT int rdclass, dns_rdatatype_t type, \

View File

@ -52,6 +52,12 @@ mygetservbyname(const char *name, const char *proto, long *port) {
return (ISC_TF(se != NULL)); return (ISC_TF(se != NULL));
} }
#ifdef _WIN32
#include <windows.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#endif
static inline isc_result_t static inline isc_result_t
fromtext_in_wks(ARGS_FROMTEXT) { fromtext_in_wks(ARGS_FROMTEXT) {
static isc_once_t once = ISC_ONCE_INIT; static isc_once_t once = ISC_ONCE_INIT;
@ -67,6 +73,7 @@ fromtext_in_wks(ARGS_FROMTEXT) {
unsigned int n; unsigned int n;
char service[32]; char service[32];
int i; int i;
isc_result_t result;
REQUIRE(type == dns_rdatatype_wks); REQUIRE(type == dns_rdatatype_wks);
REQUIRE(rdclass == dns_rdataclass_in); REQUIRE(rdclass == dns_rdataclass_in);
@ -78,15 +85,29 @@ fromtext_in_wks(ARGS_FROMTEXT) {
RUNTIME_CHECK(isc_once_do(&once, init_lock) == ISC_R_SUCCESS); RUNTIME_CHECK(isc_once_do(&once, init_lock) == ISC_R_SUCCESS);
#ifdef _WIN32
{
WORD wVersionRequested;
WSADATA wsaData;
int err;
wVersionRequested = MAKEWORD(2, 0);
err = WSAStartup(wVersionRequested, &wsaData );
if (err != 0)
return (ISC_R_FAILURE);
}
#endif
/* /*
* IPv4 dotted quad. * IPv4 dotted quad.
*/ */
RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, CHECK(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
ISC_FALSE)); ISC_FALSE));
isc_buffer_availableregion(target, &region); isc_buffer_availableregion(target, &region);
if (getquad(DNS_AS_STR(token), &addr, lexer, callbacks) != 1) if (getquad(DNS_AS_STR(token), &addr, lexer, callbacks) != 1)
RETTOK(DNS_R_BADDOTTEDQUAD); CHECKTOK(DNS_R_BADDOTTEDQUAD);
if (region.length < 4) if (region.length < 4)
return (ISC_R_NOSPACE); return (ISC_R_NOSPACE);
memmove(region.base, &addr, 4); memmove(region.base, &addr, 4);
@ -95,28 +116,28 @@ fromtext_in_wks(ARGS_FROMTEXT) {
/* /*
* Protocol. * Protocol.
*/ */
RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, CHECK(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
ISC_FALSE)); ISC_FALSE));
proto = strtol(DNS_AS_STR(token), &e, 10); proto = strtol(DNS_AS_STR(token), &e, 10);
if (*e == 0) if (*e == 0)
; ;
else if (!mygetprotobyname(DNS_AS_STR(token), &proto)) else if (!mygetprotobyname(DNS_AS_STR(token), &proto))
RETTOK(DNS_R_UNKNOWNPROTO); CHECKTOK(DNS_R_UNKNOWNPROTO);
if (proto < 0 || proto > 0xff) if (proto < 0 || proto > 0xff)
RETTOK(ISC_R_RANGE); CHECKTOK(ISC_R_RANGE);
if (proto == IPPROTO_TCP) if (proto == IPPROTO_TCP)
ps = "tcp"; ps = "tcp";
else if (proto == IPPROTO_UDP) else if (proto == IPPROTO_UDP)
ps = "udp"; ps = "udp";
RETERR(uint8_tobuffer(proto, target)); CHECK(uint8_tobuffer(proto, target));
memset(bm, 0, sizeof(bm)); memset(bm, 0, sizeof(bm));
do { do {
RETERR(isc_lex_getmastertoken(lexer, &token, CHECK(isc_lex_getmastertoken(lexer, &token,
isc_tokentype_string, ISC_TRUE)); isc_tokentype_string, ISC_TRUE));
if (token.type != isc_tokentype_string) if (token.type != isc_tokentype_string)
break; break;
@ -136,9 +157,9 @@ fromtext_in_wks(ARGS_FROMTEXT) {
; ;
else if (!mygetservbyname(service, ps, &port) && else if (!mygetservbyname(service, ps, &port) &&
!mygetservbyname(DNS_AS_STR(token), ps, &port)) !mygetservbyname(DNS_AS_STR(token), ps, &port))
RETTOK(DNS_R_UNKNOWNSERVICE); CHECKTOK(DNS_R_UNKNOWNSERVICE);
if (port < 0 || port > 0xffff) if (port < 0 || port > 0xffff)
RETTOK(ISC_R_RANGE); CHECKTOK(ISC_R_RANGE);
if (port > maxport) if (port > maxport)
maxport = port; maxport = port;
bm[port / 8] |= (0x80 >> (port % 8)); bm[port / 8] |= (0x80 >> (port % 8));
@ -150,7 +171,14 @@ fromtext_in_wks(ARGS_FROMTEXT) {
isc_lex_ungettoken(lexer, &token); isc_lex_ungettoken(lexer, &token);
n = (maxport + 8) / 8; n = (maxport + 8) / 8;
return (mem_tobuffer(target, bm, n)); result = mem_tobuffer(target, bm, n);
cleanup:
#ifdef _WIN32
WSACleanup();
#endif
return (result);
} }
static inline isc_result_t static inline isc_result_t