ReactOS 0.4.15-dev-7659-ga55345b
precomp.h File Reference
#include <stdarg.h>
#include <stdio.h>
#include <windef.h>
#include <winbase.h>
#include <winnls.h>
#include <winreg.h>
#include <winsvc.h>
#include <windns.h>
#include <windns_undoc.h>
#include <ndk/rtlfuncs.h>
#include <ndk/obfuncs.h>
#include <dnsrslvr_s.h>
#include <strsafe.h>
Include dependency graph for precomp.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _RESOLVER_CACHE_ENTRY
 
struct  _RESOLVER_CACHE
 

Macros

#define WIN32_NO_STATUS
 
#define _INC_WINDOWS
 
#define COM_NO_WINDOWS_H
 
#define NTOS_MODE_USER
 
#define CACHE_FLUSH_HOSTS_FILE_ENTRIES   0x00000001
 
#define CACHE_FLUSH_NON_HOSTS_FILE_ENTRIES   0x00000002
 
#define CACHE_FLUSH_ALL   0x00000003
 

Typedefs

typedef struct _RESOLVER_CACHE_ENTRY RESOLVER_CACHE_ENTRY
 
typedef struct _RESOLVER_CACHE_ENTRYPRESOLVER_CACHE_ENTRY
 
typedef struct _RESOLVER_CACHE RESOLVER_CACHE
 
typedef struct _RESOLVER_CACHEPRESOLVER_CACHE
 

Functions

VOID DnsIntCacheInitialize (VOID)
 
VOID DnsIntCacheRemoveEntryItem (PRESOLVER_CACHE_ENTRY CacheEntry)
 
VOID DnsIntCacheFree (VOID)
 
DNS_STATUS DnsIntCacheFlush (_In_ ULONG ulFlags)
 
DNS_STATUS DnsIntFlushCacheEntry (_In_ LPCWSTR pszName, _In_ WORD wType)
 
DNS_STATUS DnsIntCacheGetEntryByName (LPCWSTR Name, WORD wType, DWORD dwFlags, PDNS_RECORDW *Record)
 
VOID DnsIntCacheAddEntry (_In_ PDNS_RECORDW Record, _In_ BOOL bHostsFileEntry)
 
BOOL DnsIntCacheRemoveEntryByName (_In_ LPCWSTR Name)
 
DNS_STATUS DnsIntCacheGetEntries (_Out_ DNS_CACHE_ENTRY **ppCacheEntries)
 
BOOL ReadHostsFile (VOID)
 

Macro Definition Documentation

◆ _INC_WINDOWS

#define _INC_WINDOWS

Definition at line 8 of file precomp.h.

◆ CACHE_FLUSH_ALL

#define CACHE_FLUSH_ALL   0x00000003

Definition at line 49 of file precomp.h.

◆ CACHE_FLUSH_HOSTS_FILE_ENTRIES

#define CACHE_FLUSH_HOSTS_FILE_ENTRIES   0x00000001

Definition at line 47 of file precomp.h.

◆ CACHE_FLUSH_NON_HOSTS_FILE_ENTRIES

#define CACHE_FLUSH_NON_HOSTS_FILE_ENTRIES   0x00000002

Definition at line 48 of file precomp.h.

◆ COM_NO_WINDOWS_H

#define COM_NO_WINDOWS_H

Definition at line 9 of file precomp.h.

◆ NTOS_MODE_USER

#define NTOS_MODE_USER

Definition at line 19 of file precomp.h.

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 7 of file precomp.h.

Typedef Documentation

◆ PRESOLVER_CACHE

◆ PRESOLVER_CACHE_ENTRY

◆ RESOLVER_CACHE

◆ RESOLVER_CACHE_ENTRY

Function Documentation

◆ DnsIntCacheAddEntry()

VOID DnsIntCacheAddEntry ( _In_ PDNS_RECORDW  Record,
_In_ BOOL  bHostsFileEntry 
)

Definition at line 233 of file cache.c.

236{
238
239 DPRINT("DnsIntCacheAddEntry(%p %u)\n",
240 Record, bHostsFileEntry);
241
242 DPRINT("Name: %S\n", Record->pName);
243 DPRINT("TTL: %lu\n", Record->dwTtl);
244
245 /* Lock the cache */
246 DnsCacheLock();
247
248 /* Match the Id with all the entries in the List */
249 Entry = (PRESOLVER_CACHE_ENTRY)HeapAlloc(GetProcessHeap(), 0, sizeof(*Entry));
250 if (!Entry)
251 return;
252
253 Entry->bHostsFileEntry = bHostsFileEntry;
255
256 /* Insert it to our List */
258
259 /* Release the cache */
261}
#define DnsCacheUnlock()
Definition: cache.c:18
static RESOLVER_CACHE DnsCache
Definition: cache.c:14
#define DnsCacheLock()
Definition: cache.c:17
struct _RESOLVER_CACHE_ENTRY * PRESOLVER_CACHE_ENTRY
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
PDNS_RECORD WINAPI DnsRecordSetCopyEx(PDNS_RECORD src_set, DNS_CHARSET in, DNS_CHARSET out)
Definition: record.c:712
#define InsertTailList(ListHead, Entry)
#define DPRINT
Definition: sndvol32.h:71
base of all file and directory entries
Definition: entries.h:83
Definition: precomp.h:28
LIST_ENTRY RecordList
Definition: precomp.h:36
@ DnsCharSetUnicode
Definition: windns.h:111
_In_ struct _KBUGCHECK_REASON_CALLBACK_RECORD * Record
Definition: ketypes.h:268

Referenced by AddIpv4HostEntries(), AddIpv6HostEntries(), and R_ResolverQuery().

◆ DnsIntCacheFlush()

DNS_STATUS DnsIntCacheFlush ( _In_ ULONG  ulFlags)

Definition at line 69 of file cache.c.

71{
72 PLIST_ENTRY Entry, NextEntry;
73 PRESOLVER_CACHE_ENTRY CacheEntry;
74
75 DPRINT("DnsIntCacheFlush(%lu)\n", ulFlags);
76
77 /* Lock the cache */
79
80 /* Loop every entry */
82 while (Entry != &DnsCache.RecordList)
83 {
84 NextEntry = Entry->Flink;
85
86 /* Get this entry */
87 CacheEntry = CONTAINING_RECORD(Entry, RESOLVER_CACHE_ENTRY, CacheLink);
88
89 /* Remove it from list */
90 if (((ulFlags & CACHE_FLUSH_HOSTS_FILE_ENTRIES) && (CacheEntry->bHostsFileEntry != FALSE)) ||
91 ((ulFlags & CACHE_FLUSH_NON_HOSTS_FILE_ENTRIES) && (CacheEntry->bHostsFileEntry == FALSE)))
93
94 /* Move to the next entry */
95 Entry = NextEntry;
96 }
97
98 /* Unlock the cache */
100
101 return ERROR_SUCCESS;
102}
VOID DnsIntCacheRemoveEntryItem(PRESOLVER_CACHE_ENTRY CacheEntry)
Definition: cache.c:54
#define CACHE_FLUSH_NON_HOSTS_FILE_ENTRIES
Definition: precomp.h:48
#define CACHE_FLUSH_HOSTS_FILE_ENTRIES
Definition: precomp.h:47
#define ERROR_SUCCESS
Definition: deptool.c:10
#define FALSE
Definition: types.h:117
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
BOOL bHostsFileEntry
Definition: precomp.h:30
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260

Referenced by DnsIntCacheFree(), and R_ResolverFlushCache().

◆ DnsIntCacheFree()

VOID DnsIntCacheFree ( VOID  )

Definition at line 36 of file cache.c.

37{
38 DPRINT("DnsIntCacheFree()\n");
39
40 /* Check if we're initialized */
42 return;
43
45 return;
46
48
51}
static BOOL DnsCacheInitialized
Definition: cache.c:15
DNS_STATUS DnsIntCacheFlush(_In_ ULONG ulFlags)
Definition: cache.c:69
#define CACHE_FLUSH_ALL
Definition: precomp.h:49
CRITICAL_SECTION Lock
Definition: precomp.h:37
void WINAPI DeleteCriticalSection(PCRITICAL_SECTION)

Referenced by ServiceControlHandler(), and ServiceMain().

◆ DnsIntCacheGetEntries()

DNS_STATUS DnsIntCacheGetEntries ( _Out_ DNS_CACHE_ENTRY **  ppCacheEntries)

Definition at line 264 of file cache.c.

266{
267 PRESOLVER_CACHE_ENTRY CacheEntry;
268 PLIST_ENTRY NextEntry;
269 PDNS_CACHE_ENTRY pLastEntry = NULL, pNewEntry;
270
271 /* Lock the cache */
272 DnsCacheLock();
273
274 *ppCacheEntries = NULL;
275
276 NextEntry = DnsCache.RecordList.Flink;
277 while (NextEntry != &DnsCache.RecordList)
278 {
279 /* Get the Current Entry */
280 CacheEntry = CONTAINING_RECORD(NextEntry, RESOLVER_CACHE_ENTRY, CacheLink);
281
282 DPRINT("1 %S %lu\n", CacheEntry->Record->pName, CacheEntry->Record->wType);
283 if (CacheEntry->Record->pNext)
284 {
285 DPRINT("2 %S %lu\n", CacheEntry->Record->pNext->pName, CacheEntry->Record->pNext->wType);
286 }
287
288 pNewEntry = midl_user_allocate(sizeof(DNS_CACHE_ENTRY));
289 if (pNewEntry == NULL)
290 {
291 return ERROR_OUTOFMEMORY;
292 }
293
294 pNewEntry->pszName = midl_user_allocate((wcslen(CacheEntry->Record->pName) + 1) * sizeof(WCHAR));
295 if (pNewEntry->pszName == NULL)
296 {
297 return ERROR_OUTOFMEMORY;
298 }
299
300 wcscpy(pNewEntry->pszName, CacheEntry->Record->pName);
301 pNewEntry->wType1 = CacheEntry->Record->wType;
302 pNewEntry->wType2 = 0;
303 pNewEntry->wFlags = 0;
304
305 if (pLastEntry == NULL)
306 *ppCacheEntries = pNewEntry;
307 else
308 pLastEntry->pNext = pNewEntry;
309 pLastEntry = pNewEntry;
310
311 NextEntry = NextEntry->Flink;
312 }
313
314 /* Release the cache */
316
317 return ERROR_SUCCESS;
318}
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13
#define NULL
Definition: types.h:112
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
#define midl_user_allocate
Definition: rpc.h:44
Definition: windns_undoc.h:9
struct _DNS_CACHE_ENTRY * pNext
Definition: windns_undoc.h:10
WORD wType
Definition: windns.h:600
LPWSTR pName
Definition: windns.h:599
struct _DnsRecordW * pNext
Definition: windns.h:598
PDNS_RECORDW Record
Definition: precomp.h:31
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by CRrReadCache().

◆ DnsIntCacheGetEntryByName()

DNS_STATUS DnsIntCacheGetEntryByName ( LPCWSTR  Name,
WORD  wType,
DWORD  dwFlags,
PDNS_RECORDW Record 
)

Definition at line 150 of file cache.c.

155{
156 DNS_STATUS Status = DNS_INFO_NO_RECORDS;
157 PRESOLVER_CACHE_ENTRY CacheEntry;
158 PLIST_ENTRY NextEntry;
159
160 DPRINT("DnsIntCacheGetEntryByName(%S %hu 0x%lx %p)\n",
161 Name, wType, dwFlags, Record);
162
163 /* Assume failure */
164 *Record = NULL;
165
166 /* Lock the cache */
167 DnsCacheLock();
168
169 /* Match the Id with all the entries in the List */
170 NextEntry = DnsCache.RecordList.Flink;
171 while (NextEntry != &DnsCache.RecordList)
172 {
173 /* Get the Current Entry */
174 CacheEntry = CONTAINING_RECORD(NextEntry, RESOLVER_CACHE_ENTRY, CacheLink);
175
176 /* Check if this is the Catalog Entry ID we want */
177 if (_wcsicmp(CacheEntry->Record->pName, Name) == 0)
178 {
179 /* Copy the entry and return it */
182 break;
183 }
184
185 NextEntry = NextEntry->Flink;
186 }
187
188 /* Release the cache */
190
191 return Status;
192}
Status
Definition: gdiplustypes.h:25
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1176
#define DNS_INFO_NO_RECORDS
Definition: winerror.h:1861

Referenced by R_ResolverQuery().

◆ DnsIntCacheInitialize()

VOID DnsIntCacheInitialize ( VOID  )

Definition at line 21 of file cache.c.

22{
23 DPRINT("DnsIntCacheInitialize()\n");
24
25 /* Check if we're initialized */
27 return;
28
29 /* Initialize the cache lock and namespace list */
33}
#define TRUE
Definition: types.h:120
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
VOID WINAPI InitializeCriticalSection(OUT LPCRITICAL_SECTION lpCriticalSection)
Definition: synch.c:751

Referenced by ServiceMain().

◆ DnsIntCacheRemoveEntryByName()

BOOL DnsIntCacheRemoveEntryByName ( _In_ LPCWSTR  Name)

◆ DnsIntCacheRemoveEntryItem()

VOID DnsIntCacheRemoveEntryItem ( PRESOLVER_CACHE_ENTRY  CacheEntry)

Definition at line 54 of file cache.c.

55{
56 DPRINT("DnsIntCacheRemoveEntryItem(%p)\n", CacheEntry);
57
58 /* Remove the entry from the list */
59 RemoveEntryList(&CacheEntry->CacheLink);
60
61 /* Free record */
63
64 /* Delete us */
65 HeapFree(GetProcessHeap(), 0, CacheEntry);
66}
#define HeapFree(x, y, z)
Definition: compat.h:735
VOID WINAPI DnsRecordListFree(PDNS_RECORD list, DNS_FREE_TYPE type)
Definition: record.c:526
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986
LIST_ENTRY CacheLink
Definition: precomp.h:29
@ DnsFreeRecordList
Definition: windns.h:139

Referenced by DnsIntCacheFlush(), DnsIntCacheRemoveEntryByName(), and DnsIntFlushCacheEntry().

◆ DnsIntFlushCacheEntry()

DNS_STATUS DnsIntFlushCacheEntry ( _In_ LPCWSTR  pszName,
_In_ WORD  wType 
)

Definition at line 106 of file cache.c.

109{
110 PLIST_ENTRY Entry, NextEntry;
111 PRESOLVER_CACHE_ENTRY CacheEntry;
112
113 DPRINT("DnsIntFlushCacheEntry(%S %x)\n", pszName, wType);
114
115 /* Lock the cache */
116 DnsCacheLock();
117
118 /* Loop every entry */
120 while (Entry != &DnsCache.RecordList)
121 {
122 NextEntry = Entry->Flink;
123
124 /* Get this entry */
125 CacheEntry = CONTAINING_RECORD(Entry, RESOLVER_CACHE_ENTRY, CacheLink);
126
127 /* Remove it from the list */
128 if ((_wcsicmp(CacheEntry->Record->pName, pszName) == 0) &&
129 (CacheEntry->bHostsFileEntry == FALSE))
130 {
131 if ((wType == DNS_TYPE_ANY) ||
132 (CacheEntry->Record->wType == wType))
133 {
134 DnsIntCacheRemoveEntryItem(CacheEntry);
135 }
136 }
137
138 /* Move to the next entry */
139 Entry = NextEntry;
140 }
141
142 /* Unlock the cache */
144
145 return ERROR_SUCCESS;
146}
#define DNS_TYPE_ANY
Definition: windns.h:94

Referenced by R_ResolverFlushCacheEntry().

◆ ReadHostsFile()

BOOL ReadHostsFile ( VOID  )

Definition at line 291 of file hostsfile.c.

292{
293 CHAR szLineBuffer[512];
294 FILE *pHostFile = NULL;
295 CHAR *Ptr, *NameStart, *NameEnd, *AddressStart, *AddressEnd;
296 struct in_addr Ipv4Address;
297 struct in6_addr Ipv6Address;
298 PWSTR pszHostName;
299
300 pHostFile = OpenHostsFile();
301 if (pHostFile == NULL)
302 return FALSE;
303
304 for (;;)
305 {
306 /* Read a line */
307 if (fgets(szLineBuffer, sizeof(szLineBuffer), pHostFile) == NULL)
308 break;
309
310 NameStart = NameEnd = NULL;
311 AddressStart = AddressEnd = NULL;
312
313 /* Search for the start of the ip address */
314 Ptr = szLineBuffer;
315 for (;;)
316 {
317 if (*Ptr == 0 || *Ptr == '#')
318 break;
319
320 if (!isspace(*Ptr))
321 {
322 AddressStart = Ptr;
323 Ptr = Ptr + 1;
324 break;
325 }
326
327 Ptr = Ptr + 1;
328 }
329
330 /* Search for the end of the ip address */
331 for (;;)
332 {
333 if (*Ptr == 0 || *Ptr == '#')
334 break;
335
336 if (isspace(*Ptr))
337 {
338 AddressEnd = Ptr;
339 Ptr = Ptr + 1;
340 break;
341 }
342
343 Ptr = Ptr + 1;
344 }
345
346 /* Search for the start of the name */
347 for (;;)
348 {
349 if (*Ptr == 0 || *Ptr == '#')
350 break;
351
352 if (!isspace(*Ptr))
353 {
354 NameStart = Ptr;
355 Ptr = Ptr + 1;
356 break;
357 }
358
359 Ptr = Ptr + 1;
360 }
361
362 /* Search for the end of the name */
363 for (;;)
364 {
365 if (*Ptr == 0 || *Ptr == '#')
366 break;
367
368 if (isspace(*Ptr))
369 {
370 NameEnd = Ptr;
371 break;
372 }
373
374 Ptr = Ptr + 1;
375 }
376
377 if (AddressStart == NULL || AddressEnd == NULL ||
378 NameStart == NULL || NameEnd == NULL)
379 continue;
380
381 *AddressEnd = 0;
382 *NameEnd = 0;
383
384 DPRINT("%s ==> %s\n", NameStart, AddressStart);
385
386 if (ParseIpv4Address(AddressStart, &Ipv4Address))
387 {
388 DPRINT("IPv4: %s\n", AddressStart);
389
390 pszHostName = AnsiToUnicode(NameStart);
391 if (pszHostName != NULL)
392 {
393 AddIpv4HostEntries(pszHostName, &Ipv4Address);
394 HeapFree(GetProcessHeap(), 0, pszHostName);
395 }
396 }
397 else if (ParseIpv6Address(AddressStart, &Ipv6Address))
398 {
399 DPRINT("IPv6: %s\n", AddressStart);
400
401 pszHostName = AnsiToUnicode(NameStart);
402 if (pszHostName != NULL)
403 {
404 AddIpv6HostEntries(pszHostName, &Ipv6Address);
405 HeapFree(GetProcessHeap(), 0, pszHostName);
406 }
407 }
408 }
409
410 fclose(pHostFile);
411
412 return TRUE;
413}
#define isspace(c)
Definition: acclib.h:69
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
static BOOL ParseIpv6Address(_In_ LPCSTR AddressString, _Out_ PIN6_ADDR pAddress)
Definition: hostsfile.c:76
static FILE * OpenHostsFile(VOID)
Definition: hostsfile.c:194
static VOID AddIpv4HostEntries(PWSTR pszHostName, PIN_ADDR pAddress)
Definition: hostsfile.c:95
static BOOL ParseIpv4Address(_In_ PCSTR AddressString, _Out_ PIN_ADDR pAddress)
Definition: hostsfile.c:56
static PWSTR AnsiToUnicode(PSTR NarrowString)
Definition: hostsfile.c:22
static VOID AddIpv6HostEntries(PWSTR pszHostName, PIN6_ADDR pAddress)
Definition: hostsfile.c:140
_Check_return_opt_ _CRTIMP char *__cdecl fgets(_Out_writes_z_(_MaxCount) char *_Buf, _In_ int _MaxCount, _Inout_ FILE *_File)
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
Definition: tcpip.h:126
uint16_t * PWSTR
Definition: typedefs.h:56
char CHAR
Definition: xmlstorage.h:175

Referenced by ServiceMain().