Signed-off-by: Dmitry Timoshkov dmitry@baikal.ru --- dlls/dnsapi/tests/Makefile.in | 5 +- dlls/dnsapi/tests/query.c | 111 ++++++++++++++++++++++++++++++++++ 2 files changed, 114 insertions(+), 2 deletions(-) create mode 100644 dlls/dnsapi/tests/query.c
diff --git a/dlls/dnsapi/tests/Makefile.in b/dlls/dnsapi/tests/Makefile.in index 14c8f30fd1..2c48bcec36 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 \ - record.c + record.c \ + query.c diff --git a/dlls/dnsapi/tests/query.c b/dlls/dnsapi/tests/query.c new file mode 100644 index 0000000000..108cd52755 --- /dev/null +++ b/dlls/dnsapi/tests/query.c @@ -0,0 +1,111 @@ +/* + * 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 <stdarg.h> +#include <stdio.h> + +#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 == 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) +{ + test_DnsQuery(); +}
On Fri, 2020-03-06 at 18:55 +0800, Dmitry Timoshkov wrote:
Signed-off-by: Dmitry Timoshkov dmitry@baikal.ru
dlls/dnsapi/tests/Makefile.in | 5 +- dlls/dnsapi/tests/query.c | 111 ++++++++++++++++++++++++++++++++++ 2 files changed, 114 insertions(+), 2 deletions(-)
I get a couple of failures on a Windows machine in a domain:
query.c:43: Test failed: got 9501 query.c:56: DnsQuery_W(L"_ldap._tcp.dc._msdcs.test.local") => 0 query.c:63: target L"win-sk40a5tr7ov.test.local", port 389 query.c:81: Test failed: WSAAddressToStringW error -1 query.c:82: WSAAddressToStringW => L"" query.c:101: Test failed: WSAAddressToStringW error -1 query.c:102: WSAAddressToStringW => L"" 0b78:query: 6 tests executed (0 marked as todo, 3 failures), 0 skipped.
The WSAAddressToStringW errors are gone after calling WSAStartup.