]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
4474. [bug] win32: call WSAStartup in fromtext_in_wks so that
authorMark Andrews <marka@isc.org>
Wed, 5 Oct 2016 01:29:00 +0000 (12:29 +1100)
committerMark Andrews <marka@isc.org>
Wed, 5 Oct 2016 01:29:23 +0000 (12:29 +1100)
                        getprotobyname and getservbyname work.  [RT #43197]

(cherry picked from commit 82a50a619afa73ae9a212399505b9f1b327128cd)

CHANGES
bin/tests/system/verify/zones/unsigned.db
lib/dns/rdata.c
lib/dns/rdata/in_1/wks_11.c

diff --git a/CHANGES b/CHANGES
index 8a7bf7eb591b474aa2e23a3bc77b7819d5c09686..aff5b4e192266df1312e7f0124ec0e66af1560d8 100644 (file)
--- 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
index 1df3847bab0933e0f0645178703b14b2b02baa8b..109e13868cb7afa1653f804b4b3ada93472a8b4a 100644 (file)
@@ -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
index 83dc7f8281d0298c6a945743527a2604411fd8a7..6b6f3d18687c66252b9254e9f46d26c6f241ac6d 100644 (file)
                } \
        } 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, \
index 01c80225f09f2f8fc731df93e6bdcb5280b6704f..5141c9f89ac4f7106e4d2105b611a4b87f68c0f6 100644 (file)
@@ -52,6 +52,12 @@ mygetservbyname(const char *name, const char *proto, long *port) {
        return (ISC_TF(se != NULL));
 }
 
+#ifdef _WIN32
+#include <windows.h>
+#include <winsock2.h>
+#include <ws2tcpip.h>
+#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, &region);
        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