From 8dc3e01d5186c8a4be47a435b3a7e5835d05c01a Mon Sep 17 00:00:00 2001 From: Dmitry Timoshkov Date: Fri, 6 Mar 2020 20:28:35 +0800 Subject: [PATCH] dnsapi/tests: Add some DnsQuery tests. Signed-off-by: Dmitry Timoshkov Signed-off-by: Hans Leidekker Signed-off-by: Alexandre Julliard --- dlls/dnsapi/tests/Makefile.in | 3 +- dlls/dnsapi/tests/query.c | 115 ++++++++++++++++++++++++++++++++++ 2 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 dlls/dnsapi/tests/query.c diff --git a/dlls/dnsapi/tests/Makefile.in b/dlls/dnsapi/tests/Makefile.in index 14c8f30fd1f..f476103b096 100644 --- a/dlls/dnsapi/tests/Makefile.in +++ b/dlls/dnsapi/tests/Makefile.in @@ -1,7 +1,8 @@ TESTDLL = dnsapi.dll -IMPORTS = dnsapi +IMPORTS = dnsapi ws2_32 C_SRCS = \ cache.c \ name.c \ + query.c \ record.c diff --git a/dlls/dnsapi/tests/query.c b/dlls/dnsapi/tests/query.c new file mode 100644 index 00000000000..5ec5181bd02 --- /dev/null +++ b/dlls/dnsapi/tests/query.c @@ -0,0 +1,115 @@ +/* + * Copyright 2020 Dmitry Timoshkov + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include +#include + +#include "windef.h" +#include "winbase.h" +#include "winnls.h" +#include "windns.h" +#include "winsock2.h" +#include "ws2ipdef.h" + +#include "wine/test.h" + +#define NS_MAXDNAME 1025 + +static void test_DnsQuery(void) +{ + WCHAR domain[MAX_PATH]; + WCHAR name[NS_MAXDNAME]; + DWORD ret, size; + DNS_RECORDW *rec; + DNS_STATUS status; + + wcscpy(domain, L"_ldap._tcp.deadbeef"); + status = DnsQuery_W(L"", DNS_TYPE_SRV, DNS_QUERY_STANDARD, NULL, &rec, NULL); + ok(status == DNS_ERROR_RCODE_NAME_ERROR || status == DNS_INFO_NO_RECORDS || status == ERROR_INVALID_NAME /* XP */, "got %u\n", status); + + wcscpy(domain, L"_ldap._tcp.dc._msdcs."); + size = ARRAY_SIZE(domain) - wcslen(domain); + ret = GetComputerNameExW(ComputerNameDnsDomain, domain + wcslen(domain), &size); + ok(ret, "GetComputerNameEx error %u\n", GetLastError()); + if (!size) + { + skip("computer is not in a domain\n"); + return; + } + + status = DnsQuery_W(domain, DNS_TYPE_SRV, DNS_QUERY_STANDARD, NULL, &rec, NULL); + trace("DnsQuery_W(%s) => %d\n", wine_dbgstr_w(domain), status); + if (status != ERROR_SUCCESS) + { + skip("domain %s doesn't have an SRV entry\n", wine_dbgstr_w(domain)); + return; + } + + trace("target %s, port %d\n", wine_dbgstr_w(rec->Data.Srv.pNameTarget), rec->Data.Srv.wPort); + + wcsncpy(name, rec->Data.Srv.pNameTarget, ARRAY_SIZE(name)); + DnsRecordListFree(rec, DnsFreeRecordList); + + /* IPv4 */ + status = DnsQuery_W(name, DNS_TYPE_A, DNS_QUERY_STANDARD, NULL, &rec, NULL); + ok(status == ERROR_SUCCESS || status == DNS_ERROR_RCODE_NAME_ERROR, "DnsQuery_W(%s) => %d\n", wine_dbgstr_w(name), status); + if (status == ERROR_SUCCESS) + { + SOCKADDR_IN addr; + WCHAR buf[IP4_ADDRESS_STRING_LENGTH]; + + addr.sin_family = AF_INET; + addr.sin_port = 0; + addr.sin_addr.s_addr = rec->Data.A.IpAddress; + size = sizeof(buf); + ret = WSAAddressToStringW((SOCKADDR *)&addr, sizeof(addr), NULL, buf, &size); + ok(!ret, "WSAAddressToStringW error %d\n", ret); + trace("WSAAddressToStringW => %s\n", wine_dbgstr_w(buf)); + + DnsRecordListFree(rec, DnsFreeRecordList); + } + + /* IPv6 */ + status = DnsQuery_W(name, DNS_TYPE_AAAA, DNS_QUERY_STANDARD, NULL, &rec, NULL); + ok(status == ERROR_SUCCESS || status == DNS_ERROR_RCODE_NAME_ERROR, "DnsQuery_W(%s) => %d\n", wine_dbgstr_w(name), status); + if (status == ERROR_SUCCESS) + { + SOCKADDR_IN6 addr; + WCHAR buf[IP6_ADDRESS_STRING_LENGTH]; + + addr.sin6_family = AF_INET6; + addr.sin6_port = 0; + addr.sin6_scope_id = 0; + memcpy(addr.sin6_addr.s6_addr, &rec->Data.AAAA.Ip6Address, sizeof(rec->Data.AAAA.Ip6Address)); + size = sizeof(buf); + ret = WSAAddressToStringW((SOCKADDR *)&addr, sizeof(addr), NULL, buf, &size); + ok(!ret, "WSAAddressToStringW error %d\n", ret); + trace("WSAAddressToStringW => %s\n", wine_dbgstr_w(buf)); + + DnsRecordListFree(rec, DnsFreeRecordList); + } +} + +START_TEST(query) +{ + WSADATA data; + + WSAStartup(MAKEWORD(2, 2), &data); + + test_DnsQuery(); +}