[DNSAPI][DNSRSLVR] Parse the hosts file when the resolver is initializing
authorEric Kohl <eric.kohl@reactos.org>
Sat, 23 Nov 2019 16:07:59 +0000 (17:07 +0100)
committerEric Kohl <eric.kohl@reactos.org>
Sat, 23 Nov 2019 16:13:51 +0000 (17:13 +0100)
- Move the hosts file handling from dnsapi.dll to the resolver service. Now, the hosts file is no longer parsed on each query.
- Add support for DNS_QUERY_WIRE_ONLY and DNS_QUERY_NO_WIRE_QUERY flags to R_ResolverQuery.
- GetCurrentTimeInSeconds() should return DWORD instead of DNS_STATUS.

base/services/dnsrslvr/CMakeLists.txt
base/services/dnsrslvr/cache.c
base/services/dnsrslvr/dnsrslvr.c
base/services/dnsrslvr/hostsfile.c [new file with mode: 0644]
base/services/dnsrslvr/precomp.h
base/services/dnsrslvr/rpcserver.c
dll/win32/dnsapi/query.c
sdk/include/reactos/idl/dnsrslvr.idl
sdk/include/reactos/windns_undoc.h

index a2821d9..410715c 100644 (file)
@@ -5,6 +5,7 @@ add_rpc_files(server ${REACTOS_SOURCE_DIR}/sdk/include/reactos/idl/dnsrslvr.idl)
 list(APPEND SOURCE
     cache.c
     dnsrslvr.c
+    hostsfile.c
     rpcserver.c
     precomp.h
     ${CMAKE_CURRENT_BINARY_DIR}/dnsrslvr_s.c)
index 6a6eee4..748a159 100644 (file)
@@ -20,7 +20,7 @@ static BOOL DnsCacheInitialized = FALSE;
 VOID
 DnsIntCacheInitialize(VOID)
 {
-    DPRINT("DnsIntCacheInitialize\n");
+    DPRINT("DnsIntCacheInitialize()\n");
 
     /* Check if we're initialized */
     if (DnsCacheInitialized)
@@ -35,7 +35,7 @@ DnsIntCacheInitialize(VOID)
 VOID
 DnsIntCacheFree(VOID)
 {
-    DPRINT("DnsIntCacheFree\n");
+    DPRINT("DnsIntCacheFree()\n");
 
     /* Check if we're initialized */
     if (!DnsCacheInitialized)
@@ -53,7 +53,7 @@ DnsIntCacheFree(VOID)
 VOID
 DnsIntCacheRemoveEntryItem(PRESOLVER_CACHE_ENTRY CacheEntry)
 {
-    DPRINT("DnsIntCacheRemoveEntryItem %p\n", CacheEntry);
+    DPRINT("DnsIntCacheRemoveEntryItem(%p)\n", CacheEntry);
 
     /* Remove the entry from the list */
     RemoveEntryList(&CacheEntry->CacheLink);
@@ -71,7 +71,7 @@ DnsIntCacheFlush(VOID)
     PLIST_ENTRY Entry;
     PRESOLVER_CACHE_ENTRY CacheEntry;
 
-    DPRINT("DnsIntCacheFlush\n");
+    DPRINT("DnsIntCacheFlush()\n");
 
     /* Lock the cache */
     DnsCacheLock();
@@ -94,15 +94,19 @@ DnsIntCacheFlush(VOID)
     DnsCacheUnlock();
 }
 
-BOOL
-DnsIntCacheGetEntryFromName(LPCWSTR Name,
-                            PDNS_RECORDW *Record)
+DNS_STATUS
+DnsIntCacheGetEntryByName(
+    LPCWSTR Name,
+    WORD wType,
+    DWORD dwFlags,
+    PDNS_RECORDW *Record)
 {
-    BOOL Ret = FALSE;
+    DNS_STATUS Status = DNS_INFO_NO_RECORDS;
     PRESOLVER_CACHE_ENTRY CacheEntry;
     PLIST_ENTRY NextEntry;
 
-    DPRINT("DnsIntCacheGetEntryFromName %ws %p\n", Name, Record);
+    DPRINT("DnsIntCacheGetEntryByName(%S %hu 0x%lx %p)\n",
+           Name, wType, dwFlags, Record);
 
     /* Assume failure */
     *Record = NULL;
@@ -122,7 +126,7 @@ DnsIntCacheGetEntryFromName(LPCWSTR Name,
         {
             /* Copy the entry and return it */
             *Record = DnsRecordSetCopyEx(CacheEntry->Record, DnsCharSetUnicode, DnsCharSetUnicode);
-            Ret = TRUE;
+            Status = ERROR_SUCCESS;
             break;
         }
 
@@ -132,8 +136,7 @@ DnsIntCacheGetEntryFromName(LPCWSTR Name,
     /* Release the cache */
     DnsCacheUnlock();
 
-    /* Return */
-    return Ret;
+    return Status;
 }
 
 BOOL
@@ -143,7 +146,7 @@ DnsIntCacheRemoveEntryByName(LPCWSTR Name)
     PRESOLVER_CACHE_ENTRY CacheEntry;
     PLIST_ENTRY NextEntry;
 
-    DPRINT("DnsIntCacheRemoveEntryByName %ws\n", Name);
+    DPRINT("DnsIntCacheRemoveEntryByName(%S)\n", Name);
 
     /* Lock the cache */
     DnsCacheLock();
@@ -179,7 +182,10 @@ DnsIntCacheAddEntry(PDNS_RECORDW Record)
 {
     PRESOLVER_CACHE_ENTRY Entry;
 
-    DPRINT("DnsIntCacheRemoveEntryByName %p\n", Record);
+    DPRINT("DnsIntCacheAddEntry(%p)\n", Record);
+
+    DPRINT("Name: %S\n", Record->pName);
+    DPRINT("TTL: %lu\n", Record->dwTtl);
 
     /* Lock the cache */
     DnsCacheLock();
index c038405..efcdcee 100644 (file)
@@ -101,6 +101,8 @@ ServiceMain(
 
     DnsIntCacheInitialize();
 
+    ReadHostsFile();
+
     hThread = CreateThread(NULL,
                            0,
                            (LPTHREAD_START_ROUTINE)
diff --git a/base/services/dnsrslvr/hostsfile.c b/base/services/dnsrslvr/hostsfile.c
new file mode 100644 (file)
index 0000000..1f12b87
--- /dev/null
@@ -0,0 +1,396 @@
+/*
+ * COPYRIGHT:   See COPYING in the top level directory
+ * PROJECT:     ReactOS system libraries
+ * FILE:        base/services/dnsrslvr/hostsfile.c
+ * PURPOSE:     HOSTS file routines
+ * PROGRAMERS:  Art Yerkes
+ *              Eric Kohl
+ */
+
+#include "precomp.h"
+
+
+#define NDEBUG
+#include <debug.h>
+
+
+static
+PWSTR
+AnsiToUnicode(
+    PSTR NarrowString)
+{
+    PWSTR WideString;
+    int WideLen;
+
+    WideLen = MultiByteToWideChar(CP_ACP,
+                                  0,
+                                  NarrowString,
+                                  -1,
+                                  NULL,
+                                  0);
+    if (WideLen == 0)
+        return NULL;
+
+    WideString = HeapAlloc(GetProcessHeap(),
+                           0,
+                           WideLen * sizeof(WCHAR));
+    if (WideString == NULL)
+        return NULL;
+
+    MultiByteToWideChar(CP_ACP,
+                        0,
+                        NarrowString,
+                        -1,
+                        WideString,
+                        WideLen);
+
+    return WideString;
+}
+
+
+static
+BOOL
+ParseV4Address(
+    LPCSTR AddressString,
+    OUT PDWORD pAddress)
+{
+    CHAR *cp;
+    DWORD val, base;
+    unsigned char c;
+    DWORD parts[4], *pp = parts;
+
+    cp = (CHAR *)AddressString;
+
+    if (!AddressString)
+        return FALSE;
+
+    if (!isdigit(*cp))
+        return FALSE;
+
+again:
+    /*
+    * Collect number up to ``.''.
+    * Values are specified as for C:
+    * 0x=hex, 0=octal, other=decimal.
+    */
+    val = 0; base = 10;
+    if (*cp == '0')
+    {
+        if (*++cp == 'x' || *cp == 'X')
+            base = 16, cp++;
+        else
+            base = 8;
+    }
+
+    while ((c = *cp))
+    {
+        if (isdigit(c))
+        {
+            val = (val * base) + (c - '0');
+            cp++;
+            continue;
+        }
+
+        if (base == 16 && isxdigit(c))
+        {
+            val = (val << 4) + (c + 10 - (islower(c) ? 'a' : 'A'));
+            cp++;
+            continue;
+        }
+        break;
+    }
+
+    if (*cp == '.')
+    {
+        /*
+        * Internet format:
+        *    a.b.c.d
+        */
+        if (pp >= parts + 4)
+            return FALSE;
+        *pp++ = val;
+        cp++;
+        goto again;
+    }
+
+    /* Check for trailing characters */
+    if (*cp && *cp > ' ')
+        return FALSE;
+
+    if (pp >= parts + 4)
+        return FALSE;
+
+    *pp++ = val;
+    /*
+    * Concoct the address according to
+    * the number of parts specified.
+    */
+    if ((DWORD)(pp - parts) != 4)
+        return FALSE;
+
+    if (parts[0] > 0xff || parts[1] > 0xff || parts[2] > 0xff || parts[3] > 0xff)
+        return FALSE;
+
+    val = (parts[3] << 24) | (parts[2] << 16) | (parts[1] << 8) | parts[0];
+
+    if (pAddress)
+        *pAddress = val;
+
+    return TRUE;
+}
+
+
+static
+VOID
+AddV4HostEntries(
+    PWSTR pszHostName,
+    DWORD dwIpAddress)
+{
+    DNS_RECORDW ARecord, PtrRecord;
+    WCHAR szInAddrArpaName[32];
+
+    /* Prepare the A record */
+    ZeroMemory(&ARecord, sizeof(DNS_RECORDW));
+
+    ARecord.pName = pszHostName;
+    ARecord.wType = DNS_TYPE_A;
+    ARecord.wDataLength = sizeof(DNS_A_DATA);
+    ARecord.dwTtl = 86400;
+
+    ARecord.Data.A.IpAddress = dwIpAddress;
+
+    swprintf(szInAddrArpaName,
+             L"%u.%u.%u.%u.in-addr.arpa",
+             (dwIpAddress >> 24) & 0xFF,
+             (dwIpAddress >> 16) & 0xFF,
+             (dwIpAddress >> 8) & 0xFF,
+             dwIpAddress & 0xFF);
+
+    /* Prepare the PTR record */
+    ZeroMemory(&PtrRecord, sizeof(DNS_RECORDW));
+
+    PtrRecord.pName = szInAddrArpaName;
+    PtrRecord.wType = DNS_TYPE_PTR;
+    PtrRecord.wDataLength = sizeof(DNS_PTR_DATA);
+    PtrRecord.dwTtl = 86400;
+
+    PtrRecord.Data.PTR.pNameHost = pszHostName;
+
+    DnsIntCacheAddEntry(&ARecord);
+    DnsIntCacheAddEntry(&PtrRecord);
+}
+
+
+static
+FILE *
+OpenHostsFile(VOID)
+{
+    PWSTR ExpandedPath;
+    PWSTR DatabasePath;
+    HKEY DatabaseKey;
+    DWORD RegSize = 0;
+    size_t StringLength;
+    FILE *pHostsFile;
+    DWORD dwError;
+
+    ExpandedPath = HeapAlloc(GetProcessHeap(), 0, MAX_PATH * sizeof(WCHAR));
+    if (ExpandedPath == NULL)
+        return NULL;
+
+    /* Open the database path key */
+    dwError = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
+                            L"System\\CurrentControlSet\\Services\\Tcpip\\Parameters",
+                            0,
+                            KEY_READ,
+                            &DatabaseKey);
+    if (dwError == ERROR_SUCCESS)
+    {
+        /* Read the actual path */
+        RegQueryValueExW(DatabaseKey,
+                         L"DatabasePath",
+                         NULL,
+                         NULL,
+                         NULL,
+                         &RegSize);
+
+        DatabasePath = HeapAlloc(GetProcessHeap(), 0, RegSize);
+        if (DatabasePath == NULL)
+        {
+            HeapFree(GetProcessHeap(), 0, ExpandedPath);
+            RegCloseKey(DatabaseKey);
+            return NULL;
+        }
+
+        /* Read the actual path */
+        dwError = RegQueryValueExW(DatabaseKey,
+                                   L"DatabasePath",
+                                   NULL,
+                                   NULL,
+                                   (LPBYTE)DatabasePath,
+                                   &RegSize);
+
+        /* Close the key */
+        RegCloseKey(DatabaseKey);
+
+        if (dwError != ERROR_SUCCESS)
+        {
+            HeapFree(GetProcessHeap(), 0, DatabasePath);
+            HeapFree(GetProcessHeap(), 0, ExpandedPath);
+            return NULL;
+        }
+
+        /* Expand the name */
+        ExpandEnvironmentStringsW(DatabasePath, ExpandedPath, MAX_PATH);
+
+        HeapFree(GetProcessHeap(), 0, DatabasePath);
+    }
+    else
+    {
+        /* Use defalt path */
+        GetSystemDirectoryW(ExpandedPath, MAX_PATH);
+
+        StringCchLengthW(ExpandedPath, MAX_PATH, &StringLength);
+        if (ExpandedPath[StringLength - 1] != L'\\')
+        {
+            /* It isn't, so add it ourselves */
+            StringCchCatW(ExpandedPath, MAX_PATH, L"\\");
+        }
+
+        StringCchCatW(ExpandedPath, MAX_PATH, L"drivers\\etc\\");
+    }
+
+    /* Make sure that the path is backslash-terminated */
+    StringCchLengthW(ExpandedPath, MAX_PATH, &StringLength);
+    if (ExpandedPath[StringLength - 1] != L'\\')
+    {
+        /* It isn't, so add it ourselves */
+        StringCchCatW(ExpandedPath, MAX_PATH, L"\\");
+    }
+
+    /* Add the database name */
+    StringCchCatW(ExpandedPath, MAX_PATH, L"hosts");
+
+    /* Open the hosts file */
+    pHostsFile = _wfopen(ExpandedPath, L"r");
+
+    HeapFree(GetProcessHeap(), 0, ExpandedPath);
+
+    return pHostsFile;
+}
+
+
+BOOL
+ReadHostsFile(VOID)
+{
+    CHAR szLineBuffer[512];
+    FILE *pHostFile = NULL;
+    CHAR *Ptr, *NameStart, *NameEnd, *AddressStart, *AddressEnd;
+    DWORD Address;
+    PWSTR pszHostName;
+
+    pHostFile = OpenHostsFile();
+    if (pHostFile == NULL)
+        return FALSE;
+
+    for (;;)
+    {
+        /* Read a line */
+        if (fgets(szLineBuffer, sizeof(szLineBuffer), pHostFile) == NULL)
+            break;
+
+        NameStart = NameEnd = NULL;
+        AddressStart = AddressEnd = NULL;
+
+        /* Search for the start of the ip address */
+        Ptr = szLineBuffer;
+        for (;;)
+        {
+            if (*Ptr == 0 || *Ptr == '#')
+                break;
+
+            if (!isspace(*Ptr))
+            {
+                AddressStart = Ptr;
+                Ptr = Ptr + 1;
+                break;
+            }
+
+            Ptr = Ptr + 1;
+        }
+
+        /* Search for the end of the ip address */
+        for (;;)
+        {
+            if (*Ptr == 0 || *Ptr == '#')
+                break;
+
+            if (isspace(*Ptr))
+            {
+                AddressEnd = Ptr;
+                Ptr = Ptr + 1;
+                break;
+            }
+
+            Ptr = Ptr + 1;
+        }
+
+        /* Search for the start of the name */
+        for (;;)
+        {
+            if (*Ptr == 0 || *Ptr == '#')
+                break;
+
+            if (!isspace(*Ptr))
+            {
+                NameStart = Ptr;
+                Ptr = Ptr + 1;
+                break;
+            }
+
+            Ptr = Ptr + 1;
+        }
+
+        /* Search for the end of the name */
+        for (;;)
+        {
+            if (*Ptr == 0 || *Ptr == '#')
+                break;
+
+            if (isspace(*Ptr))
+            {
+                NameEnd = Ptr;
+                break;
+            }
+
+            Ptr = Ptr + 1;
+        }
+
+        if (AddressStart == NULL || AddressEnd == NULL ||
+            NameStart == NULL || NameEnd == NULL)
+            continue;
+
+        *AddressEnd = 0;
+        *NameEnd = 0;
+
+        DPRINT("%s ==> %s\n", NameStart, AddressStart);
+
+        if (ParseV4Address(AddressStart, &Address))
+        {
+            DPRINT("IP4: %s ==> 0x%08lx\n", AddressStart, Address);
+
+            pszHostName = AnsiToUnicode(NameStart);
+            if (pszHostName != NULL)
+            {
+                AddV4HostEntries(pszHostName, Address);
+
+                HeapFree(GetProcessHeap(), 0, pszHostName);
+            }
+        }
+    }
+
+    fclose(pHostFile);
+
+    return TRUE;
+}
+
+/* EOF */
index 3983d31..c0bbeec 100644 (file)
@@ -2,6 +2,7 @@
 #define _DNSRSLVR_PCH_
 
 #include <stdarg.h>
+#include <stdio.h>
 
 #define WIN32_NO_STATUS
 #define _INC_WINDOWS
 
 #include <windef.h>
 #include <winbase.h>
+#include <winnls.h>
+#include <winreg.h>
 #include <winsvc.h>
 #include <windns.h>
 #include <windns_undoc.h>
 
+#define NTOS_MODE_USER
 #include <ndk/rtlfuncs.h>
 #include <ndk/obfuncs.h>
 
 #include <dnsrslvr_s.h>
 
+#include <strsafe.h>
+
 typedef struct _RESOLVER_CACHE_ENTRY
 {
     LIST_ENTRY CacheLink;
@@ -37,10 +43,22 @@ VOID DnsIntCacheInitialize(VOID);
 VOID DnsIntCacheRemoveEntryItem(PRESOLVER_CACHE_ENTRY CacheEntry);
 VOID DnsIntCacheFree(VOID);
 VOID DnsIntCacheFlush(VOID);
-BOOL DnsIntCacheGetEntryFromName(LPCWSTR Name,
-                                 PDNS_RECORDW *Record);
+
+DNS_STATUS
+DnsIntCacheGetEntryByName(
+    LPCWSTR Name,
+    WORD wType,
+    DWORD dwFlags,
+    PDNS_RECORDW *Record);
+
 VOID DnsIntCacheAddEntry(PDNS_RECORDW Record);
 BOOL DnsIntCacheRemoveEntryByName(LPCWSTR Name);
 
 
+
+/* hostsfile.c */
+
+BOOL
+ReadHostsFile(VOID);
+
 #endif /* _DNSRSLVR_PCH_ */
index 913d2b3..cb4b947 100644 (file)
@@ -41,30 +41,32 @@ RpcThreadRoutine(LPVOID lpParameter)
     return 0;
 }
 
+/* Function: 0x04 */
 DWORD
 __stdcall
 R_ResolverFlushCache(
-    DNSRSLVR_HANDLE pwszServerName)
+    _In_ DNSRSLVR_HANDLE pwszServerName)
 {
     DPRINT("R_ResolverFlushCache()\n");
 
     // FIXME Should store (and flush) entries by server handle
     DnsIntCacheFlush();
-    return 0;
+    return ERROR_SUCCESS;
 }
 
+/* Function: 0x07 */
 DWORD
 __stdcall
 R_ResolverQuery(
-    DNSRSLVR_HANDLE pszServerName,
-    LPCWSTR pszName,
-    WORD wType,
-    DWORD dwFlags,
-    DWORD *dwRecords,
-    DNS_RECORDW **ppResultRecords)
+    _In_ DNSRSLVR_HANDLE pszServerName,
+    _In_ LPCWSTR pszName,
+    _In_ WORD wType,
+    _In_ DWORD dwFlags,
+    _Inout_ DWORD *dwRecords,
+    _Out_ DNS_RECORDW **ppResultRecords)
 {
     PDNS_RECORDW Record;
-    DNS_STATUS Status;
+    DNS_STATUS Status = ERROR_SUCCESS;
 
     DPRINT("R_ResolverQuery(%S %S %x %lx %p %p)\n",
            pszServerName, pszName, wType, dwFlags, dwRecords, ppResultRecords);
@@ -75,22 +77,41 @@ R_ResolverQuery(
     if ((dwFlags & DNS_QUERY_WIRE_ONLY) != 0 && (dwFlags & DNS_QUERY_NO_WIRE_QUERY) != 0)
         return ERROR_INVALID_PARAMETER;
 
-    if (DnsIntCacheGetEntryFromName(pszName, ppResultRecords))
-    {
-        DPRINT("DNS cache query successful!\n");
-        Status = ERROR_SUCCESS;
-    }
-    else
+    if (dwFlags & DNS_QUERY_WIRE_ONLY)
     {
         DPRINT("DNS query!\n");
         Status = Query_Main(pszName,
                             wType,
                             dwFlags,
                             ppResultRecords);
-        if (Status == ERROR_SUCCESS)
+    }
+    else if (dwFlags & DNS_QUERY_NO_WIRE_QUERY)
+    {
+        DPRINT("DNS cache query!\n");
+        Status = DnsIntCacheGetEntryByName(pszName,
+                                           wType,
+                                           dwFlags,
+                                           ppResultRecords);
+    }
+    else
+    {
+        DPRINT("DNS cache query!\n");
+        Status = DnsIntCacheGetEntryByName(pszName,
+                                           wType,
+                                           dwFlags,
+                                           ppResultRecords);
+        if (Status == DNS_INFO_NO_RECORDS)
         {
-            DPRINT("DNS query successful!\n");
-            DnsIntCacheAddEntry(*ppResultRecords);
+            DPRINT("DNS query!\n");
+            Status = Query_Main(pszName,
+                                wType,
+                                dwFlags,
+                                ppResultRecords);
+            if (Status == ERROR_SUCCESS)
+            {
+                DPRINT("DNS query successful!\n");
+                DnsIntCacheAddEntry(*ppResultRecords);
+            }
         }
     }
 
@@ -125,6 +146,6 @@ void __RPC_USER midl_user_free(void __RPC_FAR * ptr)
     HeapFree(GetProcessHeap(), 0, ptr);
 }
 
-void __RPC_USER WLANSVC_RPC_HANDLE_rundown(DNSRSLVR_HANDLE hClientHandle)
+void __RPC_USER DNSRSLVR_RPC_HANDLE_rundown(DNSRSLVR_HANDLE hClientHandle)
 {
 }
index d830e26..3ffaa41 100644 (file)
@@ -377,97 +377,6 @@ CHAR
     return p;
 }
 
-HANDLE
-OpenNetworkDatabase(LPCWSTR Name)
-{
-    PWSTR ExpandedPath;
-    PWSTR DatabasePath;
-    INT ErrorCode;
-    HKEY DatabaseKey;
-    DWORD RegType;
-    DWORD RegSize = 0;
-    size_t StringLength;
-    HANDLE ret;
-
-    ExpandedPath = HeapAlloc(GetProcessHeap(), 0, MAX_PATH * sizeof(WCHAR));
-    if (!ExpandedPath)
-        return INVALID_HANDLE_VALUE;
-
-    /* Open the database path key */
-    ErrorCode = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
-                              L"System\\CurrentControlSet\\Services\\Tcpip\\Parameters",
-                              0,
-                              KEY_READ,
-                              &DatabaseKey);
-    if (ErrorCode == NO_ERROR)
-    {
-        /* Read the actual path */
-        ErrorCode = RegQueryValueExW(DatabaseKey,
-                                     L"DatabasePath",
-                                     NULL,
-                                     &RegType,
-                                     NULL,
-                                     &RegSize);
-
-        DatabasePath = HeapAlloc(GetProcessHeap(), 0, RegSize);
-        if (!DatabasePath)
-        {
-            HeapFree(GetProcessHeap(), 0, ExpandedPath);
-            return INVALID_HANDLE_VALUE;
-        }
-
-        /* Read the actual path */
-        ErrorCode = RegQueryValueExW(DatabaseKey,
-                                     L"DatabasePath",
-                                     NULL,
-                                     &RegType,
-                                     (LPBYTE)DatabasePath,
-                                     &RegSize);
-
-        /* Close the key */
-        RegCloseKey(DatabaseKey);
-
-        /* Expand the name */
-        ExpandEnvironmentStringsW(DatabasePath, ExpandedPath, MAX_PATH);
-
-        HeapFree(GetProcessHeap(), 0, DatabasePath);
-    }
-    else
-    {
-        /* Use defalt path */
-        GetSystemDirectoryW(ExpandedPath, MAX_PATH);
-        StringCchLengthW(ExpandedPath, MAX_PATH, &StringLength);
-        if (ExpandedPath[StringLength - 1] != L'\\')
-        {
-            /* It isn't, so add it ourselves */
-            StringCchCatW(ExpandedPath, MAX_PATH, L"\\");
-        }
-        StringCchCatW(ExpandedPath, MAX_PATH, L"DRIVERS\\ETC\\");
-    }
-
-    /* Make sure that the path is backslash-terminated */
-    StringCchLengthW(ExpandedPath, MAX_PATH, &StringLength);
-    if (ExpandedPath[StringLength - 1] != L'\\')
-    {
-        /* It isn't, so add it ourselves */
-        StringCchCatW(ExpandedPath, MAX_PATH, L"\\");
-    }
-
-    /* Add the database name */
-    StringCchCatW(ExpandedPath, MAX_PATH, Name);
-
-    /* Return a handle to the file */
-    ret = CreateFileW(ExpandedPath,
-                      FILE_READ_DATA,
-                      FILE_SHARE_READ,
-                      NULL,
-                      OPEN_EXISTING,
-                      FILE_ATTRIBUTE_NORMAL,
-                      NULL);
-
-    HeapFree(GetProcessHeap(), 0, ExpandedPath);
-    return ret;
-}
 
 /* This function is far from perfect but it works enough */
 IP4_ADDRESS
@@ -609,118 +518,6 @@ again:
     return TRUE;
 }
 
-/* This function is far from perfect but it works enough */
-IP4_ADDRESS
-FindEntryInHosts(CONST CHAR * name)
-{
-    BOOL Found = FALSE;
-    HANDLE HostsFile;
-    CHAR HostsDBData[BUFSIZ] = { 0 };
-    PCHAR AddressStr, DnsName = NULL, AddrTerm, NameSt, NextLine, ThisLine, Comment;
-    UINT ValidData = 0;
-    DWORD ReadSize;
-    DWORD Address;
-
-    /* Open the network database */
-    HostsFile = OpenNetworkDatabase(L"hosts");
-    if (HostsFile == INVALID_HANDLE_VALUE)
-    {
-        WSASetLastError(WSANO_RECOVERY);
-        return 0;
-    }
-
-    while (!Found && ReadFile(HostsFile,
-        HostsDBData + ValidData,
-        sizeof(HostsDBData) - ValidData,
-        &ReadSize,
-        NULL))
-    {
-        ValidData += ReadSize;
-        ReadSize = 0;
-        NextLine = ThisLine = HostsDBData;
-
-        /* Find the beginning of the next line */
-        while ((NextLine < HostsDBData + ValidData) &&
-               (*NextLine != '\r') &&
-               (*NextLine != '\n'))
-        {
-            NextLine++;
-        }
-
-        /* Zero and skip, so we can treat what we have as a string */
-        if (NextLine > HostsDBData + ValidData)
-            break;
-
-        *NextLine = 0;
-        NextLine++;
-
-        Comment = strchr(ThisLine, '#');
-        if (Comment)
-            *Comment = 0; /* Terminate at comment start */
-
-        AddressStr = ThisLine;
-        /* Find the first space separating the IP address from the DNS name */
-        AddrTerm = strchr(ThisLine, ' ');
-        if (AddrTerm)
-        {
-            /* Terminate the address string */
-            *AddrTerm = 0;
-
-            /* Find the last space before the DNS name */
-            NameSt = strrchr(ThisLine, ' ');
-
-            /* If there is only one space (the one we removed above), then just use the address terminator */
-            if (!NameSt)
-                NameSt = AddrTerm;
-
-            /* Move from the space to the first character of the DNS name */
-            NameSt++;
-
-            DnsName = NameSt;
-
-            if (!stricmp(name, DnsName) || !stricmp(name, AddressStr))
-            {
-                Found = TRUE;
-                break;
-            }
-        }
-
-        /* Get rid of everything we read so far */
-        while (NextLine <= HostsDBData + ValidData &&
-            isspace(*NextLine))
-        {
-            NextLine++;
-        }
-
-        if (HostsDBData + ValidData - NextLine <= 0)
-            break;
-
-        memmove(HostsDBData, NextLine, HostsDBData + ValidData - NextLine);
-        ValidData -= NextLine - HostsDBData;
-    }
-
-    CloseHandle(HostsFile);
-
-    if (!Found)
-    {
-        WSASetLastError(WSANO_DATA);
-        return 0;
-    }
-
-    if (strstr(AddressStr, ":"))
-    {
-        WSASetLastError(WSAEINVAL);
-        return 0;
-    }
-
-    if (!ParseV4Address(AddressStr, &Address))
-    {
-        WSASetLastError(WSAEINVAL);
-        return 0;
-    }
-
-    return Address;
-}
 
 DNS_STATUS WINAPI
 DnsQuery_W(LPCWSTR Name,
@@ -858,29 +655,6 @@ Query_Main(LPCWSTR Name,
             i++;
         }
 
-        if ((Options & DNS_QUERY_NO_HOSTS_FILE) == 0)
-        {
-            if ((Address = FindEntryInHosts(AnsiName)) != 0)
-            {
-                RtlFreeHeap(RtlGetProcessHeap(), 0, AnsiName);
-                *QueryResultSet = (PDNS_RECORD)RtlAllocateHeap(RtlGetProcessHeap(), 0, sizeof(DNS_RECORD));
-
-                if (NULL == *QueryResultSet)
-                {
-                    return ERROR_OUTOFMEMORY;
-                }
-
-                (*QueryResultSet)->pNext = NULL;
-                (*QueryResultSet)->wType = Type;
-                (*QueryResultSet)->wDataLength = sizeof(DNS_A_DATA);
-                (*QueryResultSet)->Data.A.IpAddress = Address;
-
-                (*QueryResultSet)->pName = (LPSTR)xstrsave(Name);
-
-                return (*QueryResultSet)->pName ? ERROR_SUCCESS : ERROR_OUTOFMEMORY;
-            }
-        }
-
         network_info_result = GetNetworkParams(NULL, &network_info_blen);
         network_info = (PFIXED_INFO)RtlAllocateHeap(RtlGetProcessHeap(), 0, (size_t)network_info_blen);
         if (NULL == network_info)
@@ -1122,7 +896,7 @@ DnsFlushResolverCache(VOID)
     return (Status == ERROR_SUCCESS);
 }
 
-DNS_STATUS
+DWORD
 WINAPI
 GetCurrentTimeInSeconds(VOID)
 {
index 2c0bf7b..cae2e19 100644 (file)
@@ -10,6 +10,9 @@
 cpp_quote("#ifndef _WINDNS_INCLUDED_")
 #include <windns.h>
 cpp_quote("#endif")
+cpp_quote("#ifndef _WINDNS_UNDOC_H_")
+#include <windns_undoc.h>
+cpp_quote("#endif")
 
 typedef [handle, string] LPWSTR DNSRSLVR_HANDLE;
 
index 56cc56d..1b07f61 100644 (file)
@@ -27,7 +27,7 @@ WINAPI
 DnsGetCacheDataTable(
     _Out_ PDNS_CACHE_ENTRY *DnsCache);
 
-DNS_STATUS
+DWORD
 WINAPI
 GetCurrentTimeInSeconds(VOID);