diff --git a/CHANGES b/CHANGES index 8a7bf7eb59..aff5b4e192 100644 --- a/CHANGES +++ b/CHANGES @@ -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] 4472. [bug] Named could fail to find the correct NSEC3 records when diff --git a/bin/tests/system/verify/zones/unsigned.db b/bin/tests/system/verify/zones/unsigned.db index 1df3847bab..109e13868c 100644 --- a/bin/tests/system/verify/zones/unsigned.db +++ b/bin/tests/system/verify/zones/unsigned.db @@ -17,6 +17,7 @@ sub.empty TXT sub.empty sub NS ns.sub ns.sub A 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 secure NS secure secure DS 1312 50 100 96EEB2FFD9B00CD4694E78278B5EFDAB0A80446567B69F634DA078F0 diff --git a/lib/dns/rdata.c b/lib/dns/rdata.c index 83dc7f8281..6b6f3d1868 100644 --- a/lib/dns/rdata.c +++ b/lib/dns/rdata.c @@ -58,6 +58,19 @@ } \ } 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 ARGS_FROMTEXT int rdclass, dns_rdatatype_t type, \ diff --git a/lib/dns/rdata/in_1/wks_11.c b/lib/dns/rdata/in_1/wks_11.c index 01c80225f0..5141c9f89a 100644 --- a/lib/dns/rdata/in_1/wks_11.c +++ b/lib/dns/rdata/in_1/wks_11.c @@ -52,6 +52,12 @@ mygetservbyname(const char *name, const char *proto, long *port) { return (ISC_TF(se != NULL)); } +#ifdef _WIN32 +#include +#include +#include +#endif + static inline isc_result_t fromtext_in_wks(ARGS_FROMTEXT) { static isc_once_t once = ISC_ONCE_INIT; @@ -67,6 +73,7 @@ fromtext_in_wks(ARGS_FROMTEXT) { unsigned int n; char service[32]; int i; + isc_result_t result; REQUIRE(type == dns_rdatatype_wks); 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); +#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. */ - RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, + CHECK(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, ISC_FALSE)); isc_buffer_availableregion(target, ®ion); if (getquad(DNS_AS_STR(token), &addr, lexer, callbacks) != 1) - RETTOK(DNS_R_BADDOTTEDQUAD); + CHECKTOK(DNS_R_BADDOTTEDQUAD); if (region.length < 4) return (ISC_R_NOSPACE); memmove(region.base, &addr, 4); @@ -95,28 +116,28 @@ fromtext_in_wks(ARGS_FROMTEXT) { /* * Protocol. */ - RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, + CHECK(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, ISC_FALSE)); proto = strtol(DNS_AS_STR(token), &e, 10); if (*e == 0) ; else if (!mygetprotobyname(DNS_AS_STR(token), &proto)) - RETTOK(DNS_R_UNKNOWNPROTO); + CHECKTOK(DNS_R_UNKNOWNPROTO); if (proto < 0 || proto > 0xff) - RETTOK(ISC_R_RANGE); + CHECKTOK(ISC_R_RANGE); if (proto == IPPROTO_TCP) ps = "tcp"; else if (proto == IPPROTO_UDP) ps = "udp"; - RETERR(uint8_tobuffer(proto, target)); + CHECK(uint8_tobuffer(proto, target)); memset(bm, 0, sizeof(bm)); do { - RETERR(isc_lex_getmastertoken(lexer, &token, + CHECK(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, ISC_TRUE)); if (token.type != isc_tokentype_string) break; @@ -136,9 +157,9 @@ fromtext_in_wks(ARGS_FROMTEXT) { ; else if (!mygetservbyname(service, ps, &port) && !mygetservbyname(DNS_AS_STR(token), ps, &port)) - RETTOK(DNS_R_UNKNOWNSERVICE); + CHECKTOK(DNS_R_UNKNOWNSERVICE); if (port < 0 || port > 0xffff) - RETTOK(ISC_R_RANGE); + CHECKTOK(ISC_R_RANGE); if (port > maxport) maxport = port; bm[port / 8] |= (0x80 >> (port % 8)); @@ -150,7 +171,14 @@ fromtext_in_wks(ARGS_FROMTEXT) { isc_lex_ungettoken(lexer, &token); 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