ReactOS 0.4.15-dev-8207-gd73a838
resinfo_reactos.c
Go to the documentation of this file.
1/*
2 * iphlpapi dll implementation -- Setting and storing route information
3 *
4 * These are stubs for functions that set routing information on the target
5 * operating system. They are grouped here because their implementation will
6 * vary widely by operating system.
7 *
8 * Copyright (C) 2004 Art Yerkes
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24#include <config.h>
25#include "iphlpapi_private.h"
26
28
33
35 HKEY ChildKeyHandle,
36 LPWSTR ChildKeyName,
38
41 IN HKEY hInterface,
42 IN LPCWSTR NameServerKey,
43 OUT LPWSTR * OutNameServer)
44{
45 DWORD dwLength, dwType;
46 LPWSTR NameServer;
48
49 /* query ns */
50 dwLength = 0;
51 Status = RegQueryValueExW(hInterface, NameServerKey, NULL, &dwType, NULL, &dwLength);
52
53 if (Status != ERROR_SUCCESS)
54 {
55 /* failed to retrieve size */
56 TRACE("Status %x\n", Status);
57 return Status;
58 }
59
60 /* add terminating null */
61 dwLength += sizeof(WCHAR);
62
63 /* allocate name server */
64 NameServer = HeapAlloc(GetProcessHeap(), 0, dwLength);
65
66 if (!NameServer)
67 {
68 /* no memory */
69 return ERROR_OUTOFMEMORY;
70 }
71
72 /* query ns */
73 Status = RegQueryValueExW(hInterface, NameServerKey, NULL, &dwType, (LPBYTE)NameServer, &dwLength);
74
75 if (Status != ERROR_SUCCESS || dwType != REG_SZ)
76 {
77 /* failed to retrieve ns */
78 HeapFree(GetProcessHeap(), 0, NameServer);
79 return Status;
80 }
81
82 /* null terminate it */
83 NameServer[dwLength / sizeof(WCHAR)] = L'\0';
84
85 /* store result */
86 *OutNameServer = NameServer;
87
88 return STATUS_SUCCESS;
89}
90
91
94 IN HKEY hInterface,
95 IN LPWSTR InterfaceName,
96 PVOID ServerCallbackContext,
98{
100 LPWSTR NameServer;
101 WCHAR Buffer[50];
103 LPWSTR Start, Comma;
104
105 /* query static assigned name server */
106 Status = QueryNameServer(hInterface, L"NameServer", &NameServer);
107 if (Status != ERROR_SUCCESS)
108 {
109 /* query dynamic assigned name server */
110 Status = QueryNameServer(hInterface, L"DhcpNameServer", &NameServer);
111
112 if (Status != ERROR_SUCCESS)
113 {
114 /* failed to retrieve name servers */
115 return Status;
116 }
117 }
118
119 /* enumerate all name servers, terminated by comma */
120 Start = NameServer;
121
122 do
123 {
124 /* find next terminator */
125 Comma = wcschr(Start, L',');
126
127 if (Comma)
128 {
129 /* calculate length */
130 Length = Comma - Start;
131
132 /* copy name server */
134
135 /* null terminate it */
136 Buffer[Length] = L'\0';
137
138 /* perform callback */
139 CallbackRoutine(InterfaceName, Buffer, ServerCallbackContext);
140
141 }
142 else
143 {
144 /* perform callback */
145 CallbackRoutine(InterfaceName, Start, ServerCallbackContext);
146
147 /* last entry */
148 break;
149 }
150
151 /* increment offset */
152 Start = Comma + 1;
153
154 }while(TRUE);
155
156 /* free name server string */
157 HeapFree(GetProcessHeap(), 0, NameServer);
158
159 /* done */
160 return ERROR_SUCCESS;
161}
162
166 PVOID InterfaceCallbackContext)
167{
168 HKEY hKey, hInterface;
170 DWORD NumInterfaces, InterfaceNameLen, Index, Length;
171 LPWSTR InterfaceName;
172
173 /* first open interface key */
174 Status = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces", 0, KEY_READ, &hKey);
175
176 /* check for success */
177 if (Status != ERROR_SUCCESS)
178 {
179 /* failed to open interface key */
180 return Status;
181 }
182
183 /* now get maximum interface name length and number of interfaces */
184 Status = RegQueryInfoKeyW(hKey, NULL, NULL, NULL, &NumInterfaces, &InterfaceNameLen, NULL, NULL, NULL, NULL, NULL, NULL);
185 if (Status != ERROR_SUCCESS)
186 {
187 /* failed to get key info */
189 return Status;
190 }
191
192 /* RegQueryInfoKey does not include terminating null */
193 InterfaceNameLen++;
194
195 /* allocate interface name */
196 InterfaceName = (LPWSTR) HeapAlloc(GetProcessHeap(), 0, InterfaceNameLen * sizeof(WCHAR));
197
198 if (!InterfaceName)
199 {
200 /* no memory */
202 return ERROR_OUTOFMEMORY;
203 }
204
205 /* no enumerate all interfaces */
206 for(Index = 0; Index < NumInterfaces; Index++)
207 {
208 /* query interface name */
209 Length = InterfaceNameLen;
210 Status = RegEnumKeyExW(hKey, Index, InterfaceName, &Length, NULL, NULL, NULL, NULL);
211
212 if (Status == ERROR_SUCCESS)
213 {
214 /* make sure it is null terminated */
215 InterfaceName[Length] = L'\0';
216
217 /* now open child key */
218 Status = RegOpenKeyExW(hKey, InterfaceName, 0, KEY_READ, &hInterface);
219
220 if (Status == ERROR_SUCCESS)
221 {
222 /* perform enumeration callback */
223 CallbackRoutine(hInterface, InterfaceName, InterfaceCallbackContext);
224
225 /* close interface key */
226 RegCloseKey(hInterface);
227 }
228 }
229 }
230
231 /* free interface name */
232 HeapFree(GetProcessHeap(), 0, InterfaceName);
233
234 /* close root interface key */
236
237 /* done */
238 return Status;
239}
240
241VOID
243 IN LPWSTR InterfaceName,
246{
247 /* get context */
249
250 /* increment server count */
251 Data->NumServers++;
252}
253
254VOID
256 HKEY ChildKeyHandle,
257 LPWSTR ChildKeyName,
259{
260 EnumNameServers(ChildKeyHandle, ChildKeyName, CallbackContext, CountNameServerCallback);
261}
262
265 IN PNAME_SERVER_LIST_PRIVATE PrivateData )
266{
268}
269
270VOID
272 IN LPWSTR InterfaceName,
275{
276 /* get context */
278
279 /* convert to ansi ns string */
280 if (WideCharToMultiByte(CP_ACP, 0, Server, -1, Data->pCurrent->IpAddress.String, 16, NULL, NULL))
281 {
282 /* store offset to next name server struct */
283 Data->pCurrent->Next = (struct _IP_ADDR_STRING*)(Data->pCurrent + 1);
284
285 /* move to next entry */
286 Data->pCurrent = Data->pCurrent->Next;
287
288 /* increment server count */
289 Data->NumServers++;
290 }
291 else
292 {
293 /* failed to convert dns server */
294 Data->pCurrent->IpAddress.String[0] = '\0';
295 }
296}
297
298VOID
300 HKEY ChildKeyHandle,
301 LPWSTR ChildKeyName,
303{
304 EnumNameServers(ChildKeyHandle, ChildKeyName, CallbackContext, CreateNameServerListCallback);
305}
306
309 PNAME_SERVER_LIST_PRIVATE PrivateData )
310{
312}
313
316{
317 NAME_SERVER_LIST_PRIVATE PrivateNSEnum;
319 IP_ADDR_STRING * DnsList = NULL;
321
322 PrivateNSEnum.NumServers = 0;
323
324 /* count name servers */
325 Status = CountNameServers(&PrivateNSEnum);
326
327 if (Status != ERROR_SUCCESS)
328 {
329 /* failed to enumerate name servers */
330 return NULL;
331 }
332
333 /* are there any servers */
334 if (PrivateNSEnum.NumServers)
335 {
336 /* allocate dns servers */
337 DnsList = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, PrivateNSEnum.NumServers * sizeof(IP_ADDR_STRING));
338
339 if (!DnsList)
340 {
341 /* no memory */
342 return NULL;
343 }
344 }
345
346 /* allocate private struct */
348
349 if(!ResInfo)
350 {
351 /* no memory */
352 if (DnsList)
353 {
354 /* free dns list */
355 HeapFree( GetProcessHeap(), 0, DnsList);
356 }
357 return NULL;
358 }
359
360 /* are there any servers */
361 if (PrivateNSEnum.NumServers)
362 {
363 /* initialize enumeration context */
364 PrivateNSEnum.NumServers = 0;
365 PrivateNSEnum.pCurrent = DnsList;
366
367 /* enumerate servers */
368 MakeNameServerList( &PrivateNSEnum );
369
370 /* store result */
371 ResInfo->DnsList = DnsList;
372 ResInfo->riCount = PrivateNSEnum.NumServers;
373 }
374
375 /* done */
376 return ResInfo;
377}
378
380{
381 HeapFree(GetProcessHeap(), 0, InfoPtr->DnsList);
382 RtlFreeHeap( GetProcessHeap(), 0, InfoPtr );
383}
#define VOID
Definition: acefi.h:82
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:608
#define RegCloseKey(hKey)
Definition: registry.h:49
Definition: bufpool.h:45
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13
#define ERROR_SUCCESS
Definition: deptool.c:10
static LSTATUS(WINAPI *pRegDeleteTreeW)(HKEY
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3333
LONG WINAPI RegEnumKeyExW(_In_ HKEY hKey, _In_ DWORD dwIndex, _Out_ LPWSTR lpName, _Inout_ LPDWORD lpcbName, _Reserved_ LPDWORD lpReserved, _Out_opt_ LPWSTR lpClass, _Inout_opt_ LPDWORD lpcbClass, _Out_opt_ PFILETIME lpftLastWriteTime)
Definition: reg.c:2504
LONG WINAPI RegQueryInfoKeyW(HKEY hKey, LPWSTR lpClass, LPDWORD lpcClass, LPDWORD lpReserved, LPDWORD lpcSubKeys, LPDWORD lpcMaxSubKeyLen, LPDWORD lpcMaxClassLen, LPDWORD lpcValues, LPDWORD lpcMaxValueNameLen, LPDWORD lpcMaxValueLen, LPDWORD lpcbSecurityDescriptor, PFILETIME lpftLastWriteTime)
Definition: reg.c:3662
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4103
#define wcschr
Definition: compat.h:17
#define GetProcessHeap()
Definition: compat.h:736
#define CP_ACP
Definition: compat.h:109
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
#define WideCharToMultiByte
Definition: compat.h:111
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
static DWORD DWORD * dwLength
Definition: fusion.c:86
unsigned long DWORD
Definition: ntddk_ex.h:95
_Must_inspect_result_ _In_ PFLT_GET_OPERATION_STATUS_CALLBACK CallbackRoutine
Definition: fltkernel.h:1035
FxAutoRegKey hKey
Status
Definition: gdiplustypes.h:25
VOID(* EnumNameServersFunc)(PWCHAR Interface, PWCHAR NameServer, PVOID Data)
#define REG_SZ
Definition: layer.c:22
unsigned int UINT
Definition: ndis.h:50
#define KEY_READ
Definition: nt_native.h:1023
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
#define L(x)
Definition: ntvdm.h:50
IPHLP_RES_INFO ResInfo
Definition: resinfo.c:52
struct _IPHLP_RES_INFO * PIPHLP_RES_INFO
struct _IPHLP_RES_INFO IPHLP_RES_INFO
LSTATUS EnumInterfaces(ENUM_INTERFACE_CALLBACK CallbackRoutine, PVOID InterfaceCallbackContext)
LSTATUS EnumNameServers(IN HKEY hInterface, IN LPWSTR InterfaceName, PVOID ServerCallbackContext, EnumNameServersFunc CallbackRoutine)
VOID disposeResInfo(PIPHLP_RES_INFO InfoPtr)
PIPHLP_RES_INFO getResInfo()
VOID CreateNameServerListCallback(IN LPWSTR InterfaceName, IN LPWSTR Server, IN PVOID CallbackContext)
VOID CountServerCallbackTrampoline(HKEY ChildKeyHandle, LPWSTR ChildKeyName, PVOID CallbackContext)
LSTATUS CountNameServers(IN PNAME_SERVER_LIST_PRIVATE PrivateData)
VOID(* ENUM_INTERFACE_CALLBACK)(HKEY ChildKeyHandle, LPWSTR ChildKeyName, PVOID CallbackContext)
struct _NAME_SERVER_LIST_PRIVATE * PNAME_SERVER_LIST_PRIVATE
LSTATUS MakeNameServerList(PNAME_SERVER_LIST_PRIVATE PrivateData)
VOID CountNameServerCallback(IN LPWSTR InterfaceName, IN LPWSTR Server, IN PVOID CallbackContext)
VOID CreateNameServerListCallbackTrampoline(HKEY ChildKeyHandle, LPWSTR ChildKeyName, PVOID CallbackContext)
LSTATUS QueryNameServer(IN HKEY hInterface, IN LPCWSTR NameServerKey, OUT LPWSTR *OutNameServer)
struct _NAME_SERVER_LIST_PRIVATE NAME_SERVER_LIST_PRIVATE
#define STATUS_SUCCESS
Definition: shellext.h:65
#define TRACE(s)
Definition: solgame.cpp:4
static void Server(int port)
Definition: srltest.c:69
IP_ADDR_STRING * DnsList
Definition: resinfo.h:26
DWORD riCount
Definition: resinfo.h:25
IP_ADDR_STRING * pCurrent
unsigned char * LPBYTE
Definition: typedefs.h:53
#define IN
Definition: typedefs.h:39
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:264
#define OUT
Definition: typedefs.h:40
@ Start
Definition: partlist.h:33
_In_ WDFCOLLECTION _In_ ULONG Index
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
_IRQL_requires_same_ typedef _In_ ULONG _In_ UCHAR _In_ ULONGLONG _In_ ULONGLONG _In_opt_ PEVENT_FILTER_DESCRIPTOR _Inout_opt_ PVOID CallbackContext
Definition: wmitypes.h:60
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185