ReactOS 0.4.15-dev-7931-gfd331f1
nsplookup.c File Reference
#include "precomp.h"
#include <stdlib.h>
#include <ws2spi.h>
#include <nspapi.h>
#include <winuser.h>
#include <windns.h>
#include <guiddef.h>
#include <svcguid.h>
#include <iptypes.h>
#include <strsafe.h>
#include <winreg.h>
#include "mswhelper.h"
#include <debug.h>
Include dependency graph for nsplookup.c:

Go to the source code of this file.

Classes

struct  WSHOSTINFOINTERN
 
struct  WSHANDLEINTERN
 

Macros

#define NDEBUG
 
#define NSP_CALLID_DNS   0x0001
 
#define NSP_CALLID_HOSTNAME   0x0002
 
#define NSP_CALLID_HOSTBYNAME   0x0003
 
#define NSP_CALLID_SERVICEBYNAME   0x0004
 
#define BUFSIZ   1024
 
#define WS2_INTERNAL_MAX_ALIAS   512
 
#define SKIPWS(ptr, act)   {while(*ptr && isspace(*ptr)) ptr++; if(!*ptr) act;}
 
#define SKIPANDMARKSTR(ptr, act)
 

Typedefs

typedef struct WSHOSTINFOINTERNPWSHOSTINFOINTERN
 
typedef struct WSHANDLEINTERNPWSHANDLEINTERN
 

Functions

INT WINAPI mswNSPStartup (LPGUID lpProviderId, LPNSP_ROUTINE lpRout)
 
INT NSP_LookupServiceBeginW (PWSHANDLEINTERN data, CHAR *hostnameA, WCHAR *hostnameW, DWORD CallID)
 
INT NSP_LookupServiceNextW (_In_ PWSHANDLEINTERN data, _In_ DWORD dwControlFlags, _Inout_ LPWSAQUERYSETW lpRes, _Inout_ LPDWORD lpResLen)
 
INT NSP_GetHostNameHeapAllocW (_Out_ WCHAR **hostname)
 
INT NSP_GetHostByNameHeapAllocW (_In_ PWSHANDLEINTERN data, _In_ DWORD dwControlFlags, _Out_ PWSHOSTINFOINTERN hostinfo)
 
INT NSP_GetServiceByNameHeapAllocW (_In_ PWSHANDLEINTERN data, _In_ DWORD dwControlFlags, _Out_ PWSHOSTINFOINTERN hostinfo)
 
INT WSAAPI mwsNSPCleanUp (_In_ LPGUID lpProviderId)
 
INT mwsNSPInit (VOID)
 
INT WSAAPI mwsNSPLookupServiceBegin (_In_ LPGUID lpProviderId, _In_ LPWSAQUERYSETW lpqsRestrictions, _In_ LPWSASERVICECLASSINFOW lpServiceClassInfo, _In_ DWORD dwControlFlags, _Out_ LPHANDLE lphLookup)
 
INT WSAAPI mwsNSPLookupServiceNext (_In_ HANDLE hLookup, _In_ DWORD dwControlFlags, _Inout_ LPDWORD lpdwBufferLength, LPWSAQUERYSETW lpqsResults)
 
INT WSAAPI mwsNSPIoCtl (_In_ HANDLE hLookup, _In_ DWORD dwControlCode, _In_reads_bytes_(cbInBuffer) LPVOID lpvInBuffer, _In_ DWORD cbInBuffer, _Out_writes_bytes_to_(cbOutBuffer, *lpcbBytesReturned) LPVOID lpvOutBuffer, _In_ DWORD cbOutBuffer, _Out_ LPDWORD lpcbBytesReturned, _In_opt_ LPWSACOMPLETION lpCompletion, _In_ LPWSATHREADID lpThreadId)
 
INT WSAAPI mwsNSPLookupServiceEnd (_In_ HANDLE hLookup)
 
INT WSAAPI mwsNSPSetService (_In_ LPGUID lpProviderId, _In_ LPWSASERVICECLASSINFOW lpServiceClassInfo, _In_ LPWSAQUERYSETW lpqsRegInfo, _In_ WSAESETSERVICEOP essOperation, _In_ DWORD dwControlFlags)
 
INT WSAAPI mwsNSPInstallServiceClass (_In_ LPGUID lpProviderId, _In_ LPWSASERVICECLASSINFOW lpServiceClassInfo)
 
INT WSAAPI mwsNSPRemoveServiceClass (_In_ LPGUID lpProviderId, _In_ LPGUID lpServiceClassId)
 
INT WSAAPI mwsNSPGetServiceClassInfo (_In_ LPGUID lpProviderId, _In_ LPDWORD lpdwBufSize, _In_ LPWSASERVICECLASSINFOW lpServiceClassInfo)
 
static BOOL DecodeServEntFromString (IN PCHAR ServiceString, OUT PCHAR *ServiceName, OUT PCHAR *PortNumberStr, OUT PCHAR *ProtocolStr, IN PCHAR *Aliases, IN DWORD MaxAlias)
 
HANDLE WSAAPI OpenNetworkDatabase (_In_ LPCWSTR Name)
 
int WINAPI NSPStartup (_In_ LPGUID lpProviderId, _Out_ LPNSP_ROUTINE lpRout)
 

Variables

static const GUID guid_NULL = {0}
 
static const GUID guid_HOSTNAME = SVCID_HOSTNAME
 
static const GUID guid_INET_HOSTADDRBYINETSTRING = SVCID_INET_HOSTADDRBYINETSTRING
 
static const GUID guid_INET_HOSTADDRBYNAME = SVCID_INET_HOSTADDRBYNAME
 
static const GUID guid_INET_SERVICEBYNAME = SVCID_INET_SERVICEBYNAME
 
static const GUID guid_mswsock_TcpIp
 
static const GUID guid_mswsock_NLA
 

Macro Definition Documentation

◆ BUFSIZ

#define BUFSIZ   1024

Definition at line 25 of file nsplookup.c.

◆ NDEBUG

#define NDEBUG

Definition at line 16 of file nsplookup.c.

◆ NSP_CALLID_DNS

#define NSP_CALLID_DNS   0x0001

Definition at line 19 of file nsplookup.c.

◆ NSP_CALLID_HOSTBYNAME

#define NSP_CALLID_HOSTBYNAME   0x0003

Definition at line 21 of file nsplookup.c.

◆ NSP_CALLID_HOSTNAME

#define NSP_CALLID_HOSTNAME   0x0002

Definition at line 20 of file nsplookup.c.

◆ NSP_CALLID_SERVICEBYNAME

#define NSP_CALLID_SERVICEBYNAME   0x0004

Definition at line 22 of file nsplookup.c.

◆ SKIPANDMARKSTR

#define SKIPANDMARKSTR (   ptr,
  act 
)
Value:
{while(*ptr && !isspace(*ptr)) ptr++; \
if(!*ptr) {act;} else { *ptr = 0; ptr++; }}
#define isspace(c)
Definition: acclib.h:69
static PVOID ptr
Definition: dispmode.c:27

Definition at line 550 of file nsplookup.c.

◆ SKIPWS

#define SKIPWS (   ptr,
  act 
)    {while(*ptr && isspace(*ptr)) ptr++; if(!*ptr) act;}

Definition at line 547 of file nsplookup.c.

◆ WS2_INTERNAL_MAX_ALIAS

#define WS2_INTERNAL_MAX_ALIAS   512

Definition at line 28 of file nsplookup.c.

Typedef Documentation

◆ PWSHANDLEINTERN

◆ PWSHOSTINFOINTERN

Function Documentation

◆ DecodeServEntFromString()

static BOOL DecodeServEntFromString ( IN PCHAR  ServiceString,
OUT PCHAR ServiceName,
OUT PCHAR PortNumberStr,
OUT PCHAR ProtocolStr,
IN PCHAR Aliases,
IN DWORD  MaxAlias 
)
static

Definition at line 556 of file nsplookup.c.

562{
563 UINT NAliases = 0;
564
565 //WS_DbgPrint(MAX_TRACE, ("Parsing service ent [%s]\n", ServiceString));
566
567 SKIPWS(ServiceString, return FALSE);
568 *ServiceName = ServiceString;
569 SKIPANDMARKSTR(ServiceString, return FALSE);
570 SKIPWS(ServiceString, return FALSE);
571 *PortNumberStr = ServiceString;
572 SKIPANDMARKSTR(ServiceString, ;);
573
574 while (*ServiceString && NAliases < MaxAlias - 1)
575 {
576 SKIPWS(ServiceString, break);
577 if (*ServiceString)
578 {
579 SKIPWS(ServiceString, ;);
580 if (strlen(ServiceString))
581 {
582 //WS_DbgPrint(MAX_TRACE, ("Alias: %s\n", ServiceString));
583 *Aliases++ = ServiceString;
584 NAliases++;
585 }
586 SKIPANDMARKSTR(ServiceString, ;);
587 }
588 }
589 *Aliases = NULL;
590
591 *ProtocolStr = strchr(*PortNumberStr, '/');
592
593 if (!*ProtocolStr)
594 return FALSE;
595
596 **ProtocolStr = 0;
597 (*ProtocolStr)++;
598
599 //WS_DbgPrint(MAX_TRACE, ("Parsing done: %s %s %s %d\n",
600 // *ServiceName, *ProtocolStr, *PortNumberStr,
601 // NAliases));
602
603 return TRUE;
604}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
char * strchr(const char *String, int ch)
Definition: utclib.c:501
static WCHAR ServiceName[]
Definition: browser.c:19
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
unsigned int UINT
Definition: ndis.h:50
#define SKIPWS(ptr, act)
Definition: nsplookup.c:547
#define SKIPANDMARKSTR(ptr, act)
Definition: nsplookup.c:550

Referenced by NSP_GetServiceByNameHeapAllocW().

◆ mswNSPStartup()

INT WINAPI mswNSPStartup ( LPGUID  lpProviderId,
LPNSP_ROUTINE  lpRout 
)

◆ mwsNSPCleanUp()

INT WSAAPI mwsNSPCleanUp ( _In_ LPGUID  lpProviderId)

Definition at line 132 of file nsplookup.c.

133{
134 //WSASetLastError(ERROR_CALL_NOT_IMPLEMENTED);
135 //return ERROR_CALL_NOT_IMPLEMENTED;
136 return ERROR_SUCCESS;
137}
#define ERROR_SUCCESS
Definition: deptool.c:10

Referenced by NSPStartup().

◆ mwsNSPGetServiceClassInfo()

INT WSAAPI mwsNSPGetServiceClassInfo ( _In_ LPGUID  lpProviderId,
_In_ LPDWORD  lpdwBufSize,
_In_ LPWSASERVICECLASSINFOW  lpServiceClassInfo 
)

Definition at line 392 of file nsplookup.c.

395{
398}
#define ERROR_CALL_NOT_IMPLEMENTED
Definition: compat.h:102
VOID WSAAPI WSASetLastError(IN INT iError)
Definition: dllmain.c:123

Referenced by NSPStartup().

◆ mwsNSPInit()

INT mwsNSPInit ( VOID  )

Definition at line 140 of file nsplookup.c.

141{
142 return ERROR_SUCCESS;
143}

Referenced by NSPStartup().

◆ mwsNSPInstallServiceClass()

INT WSAAPI mwsNSPInstallServiceClass ( _In_ LPGUID  lpProviderId,
_In_ LPWSASERVICECLASSINFOW  lpServiceClassInfo 
)

Definition at line 374 of file nsplookup.c.

Referenced by NSPStartup().

◆ mwsNSPIoCtl()

INT WSAAPI mwsNSPIoCtl ( _In_ HANDLE  hLookup,
_In_ DWORD  dwControlCode,
_In_reads_bytes_(cbInBuffer) LPVOID  lpvInBuffer,
_In_ DWORD  cbInBuffer,
_Out_writes_bytes_to_(cbOutBuffer, *lpcbBytesReturned) LPVOID  lpvOutBuffer,
_In_ DWORD  cbOutBuffer,
_Out_ LPDWORD  lpcbBytesReturned,
_In_opt_ LPWSACOMPLETION  lpCompletion,
_In_ LPWSATHREADID  lpThreadId 
)

Definition at line 323 of file nsplookup.c.

◆ mwsNSPLookupServiceBegin()

INT WSAAPI mwsNSPLookupServiceBegin ( _In_ LPGUID  lpProviderId,
_In_ LPWSAQUERYSETW  lpqsRestrictions,
_In_ LPWSASERVICECLASSINFOW  lpServiceClassInfo,
_In_ DWORD  dwControlFlags,
_Out_ LPHANDLE  lphLookup 
)

Definition at line 147 of file nsplookup.c.

152{
153 PWSHANDLEINTERN pLook;
154 int wsaErr;
155
156 if (IsEqualGUID(lpProviderId, &guid_mswsock_TcpIp))
157 {
158 //OK
159 }
160 else if (IsEqualGUID(lpProviderId, &guid_mswsock_NLA))
161 {
163 return SOCKET_ERROR;
164 }
165 else
166 {
168 }
169
170 /* allocate internal structure */
171 pLook = HeapAlloc(GetProcessHeap(), 0, sizeof(WSHANDLEINTERN));
172 if (!pLook)
173 {
175 return SOCKET_ERROR;
176 }
177
178 *lphLookup = (HANDLE)pLook;
179
180 RtlZeroMemory(pLook, sizeof(*pLook));
181
182 /* Anyway the ControlFlags "should" be needed
183 in NSPLookupServiceNext. (see doku) But
184 thats not the fact ATM. */
185 pLook->dwControlFlags = dwControlFlags;
186 pLook->providerId = *lpProviderId;
187
188#ifdef NSP_REDIRECT
189
190 if (IsEqualGUID(lpProviderId, &guid_mswsock_TcpIp))
191 {
192 pLook->rdrproc = rdrproc_tcpip;
193 }
194 else if (IsEqualGUID(lpProviderId, &guid_mswsock_NLA))
195 {
196 pLook->rdrproc = rdrproc_nla;
197 }
198 else
199 {
201 }
202
203 if (pLook->rdrproc.NSPLookupServiceBegin(lpProviderId,
204 lpqsRestrictions,
205 lpServiceClassInfo,
206 dwControlFlags,
207 &pLook->rdrLookup) == NO_ERROR)
208 {
209 wsaErr = NO_ERROR;
210 }
211 else
212 {
213 wsaErr = WSAGetLastError();
214 }
215
216 /*
217 if (res)
218 res = WSAGetLastError();
219 */
220
221#else /* NSP_REDIRECT */
222
224 if (IsEqualGUID(lpqsRestrictions->lpServiceClassId, &guid_NULL))
225 {
227 }
228 else if (IsEqualGUID(lpqsRestrictions->lpServiceClassId, &guid_HOSTNAME))
229 {
230 wsaErr = NSP_LookupServiceBeginW(pLook,
231 NULL,
232 NULL,
234 }
235 else if (IsEqualGUID(lpqsRestrictions->lpServiceClassId,
237 {
238 wsaErr = NSP_LookupServiceBeginW(pLook,
239 NULL,
240 lpqsRestrictions->lpszServiceInstanceName,
242 }
243 else if (IsEqualGUID(lpqsRestrictions->lpServiceClassId,
245 {
246 wsaErr = NSP_LookupServiceBeginW(pLook,
247 NULL,
248 lpqsRestrictions->lpszServiceInstanceName,
250 }
251 else if (IsEqualGUID(lpqsRestrictions->lpServiceClassId,
253 {
255 }
256
257#endif /* NSP_REDIRECT */
258
259 if (wsaErr != NO_ERROR)
260 {
261 WSASetLastError(wsaErr);
262 return SOCKET_ERROR;
263 }
264 return NO_ERROR;
265}
#define NO_ERROR
Definition: dderror.h:5
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
static const GUID guid_INET_HOSTADDRBYINETSTRING
Definition: nsplookup.c:58
static const GUID guid_mswsock_TcpIp
Definition: nsplookup.c:64
static const GUID guid_NULL
Definition: nsplookup.c:56
#define NSP_CALLID_SERVICEBYNAME
Definition: nsplookup.c:22
static const GUID guid_HOSTNAME
Definition: nsplookup.c:57
static const GUID guid_INET_SERVICEBYNAME
Definition: nsplookup.c:60
static const GUID guid_INET_HOSTADDRBYNAME
Definition: nsplookup.c:59
INT NSP_LookupServiceBeginW(PWSHANDLEINTERN data, CHAR *hostnameA, WCHAR *hostnameW, DWORD CallID)
Definition: nsplookup.c:407
static const GUID guid_mswsock_NLA
Definition: nsplookup.c:71
#define NSP_CALLID_HOSTNAME
Definition: nsplookup.c:20
#define NSP_CALLID_HOSTBYNAME
Definition: nsplookup.c:21
#define IsEqualGUID(rguid1, rguid2)
Definition: guiddef.h:147
DWORD dwControlFlags
Definition: nsplookup.c:46
GUID providerId
Definition: nsplookup.c:45
PVOID HANDLE
Definition: typedefs.h:73
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define WSASERVICE_NOT_FOUND
Definition: winerror.h:1995
#define WSAEFAULT
Definition: winerror.h:1945
int PASCAL FAR WSAGetLastError(void)
Definition: dllmain.c:112
#define SOCKET_ERROR
Definition: winsock.h:333

Referenced by NSPStartup().

◆ mwsNSPLookupServiceEnd()

INT WSAAPI mwsNSPLookupServiceEnd ( _In_ HANDLE  hLookup)

Definition at line 339 of file nsplookup.c.

340{
341 PWSHANDLEINTERN pLook;
342 HANDLE hHeap;
343 INT res;
344
345 res = NO_ERROR;
346 pLook = (PWSHANDLEINTERN)hLookup;
347 hHeap = GetProcessHeap();
348
349#ifdef NSP_REDIRECT
350 res = pLook->rdrproc.NSPLookupServiceEnd(pLook->rdrLookup);
351#endif
352
353 if (pLook->hostnameW != NULL)
354 HeapFree(hHeap, 0, pLook->hostnameW);
355
356 HeapFree(hHeap, 0, pLook);
357 return res;
358}
#define HeapFree(x, y, z)
Definition: compat.h:735
GLuint res
Definition: glext.h:9613
struct WSHANDLEINTERN * PWSHANDLEINTERN
WCHAR * hostnameW
Definition: nsplookup.c:49
int32_t INT
Definition: typedefs.h:58

Referenced by NSPStartup().

◆ mwsNSPLookupServiceNext()

INT WSAAPI mwsNSPLookupServiceNext ( _In_ HANDLE  hLookup,
_In_ DWORD  dwControlFlags,
_Inout_ LPDWORD  lpdwBufferLength,
LPWSAQUERYSETW  lpqsResults 
)

Definition at line 269 of file nsplookup.c.

274{
275 PWSHANDLEINTERN pLook = hLookup;
276 int wsaErr = 0;
277
278#ifdef NSP_REDIRECT
279
280 INT res = pLook->rdrproc.NSPLookupServiceNext(pLook->rdrLookup,
281 dwControlFlags,
283 lpqsResults);
284 wsaErr = WSAGetLastError();
285 if (res != ERROR_SUCCESS)
286 {
287 wsaErr = WSAGetLastError();
288
289 if (wsaErr == 0)
290 wsaErr = 0xFFFFFFFF;
291 }
292
293#else /* NSP_REDIRECT */
294
295 if ((lpdwBufferLength == NULL) || (*lpdwBufferLength == 0))
296 {
297 wsaErr = WSA_NOT_ENOUGH_MEMORY;
298 goto End;
299 }
300
301 RtlZeroMemory(lpqsResults, *lpdwBufferLength);
302 lpqsResults->dwSize = sizeof(*lpqsResults);
303
304 wsaErr = NSP_LookupServiceNextW(pLook,
305 dwControlFlags,
306 lpqsResults,
308
309
310#endif /* NSP_REDIRECT */
311
312End:
313 if (wsaErr != 0)
314 {
315 WSASetLastError(wsaErr);
316 return SOCKET_ERROR;
317 }
318 return NO_ERROR;
319}
INT NSP_LookupServiceNextW(_In_ PWSHANDLEINTERN data, _In_ DWORD dwControlFlags, _Inout_ LPWSAQUERYSETW lpRes, _Inout_ LPDWORD lpResLen)
Definition: nsplookup.c:852
_In_ _In_opt_ _Out_writes_bytes_to_opt_ lpdwBufferLength _Inout_ LPDWORD lpdwBufferLength
Definition: winhttp.h:675
#define WSA_NOT_ENOUGH_MEMORY
Definition: winsock2.h:620

Referenced by NSPStartup().

◆ mwsNSPRemoveServiceClass()

INT WSAAPI mwsNSPRemoveServiceClass ( _In_ LPGUID  lpProviderId,
_In_ LPGUID  lpServiceClassId 
)

Definition at line 383 of file nsplookup.c.

Referenced by NSPStartup().

◆ mwsNSPSetService()

INT WSAAPI mwsNSPSetService ( _In_ LPGUID  lpProviderId,
_In_ LPWSASERVICECLASSINFOW  lpServiceClassInfo,
_In_ LPWSAQUERYSETW  lpqsRegInfo,
_In_ WSAESETSERVICEOP  essOperation,
_In_ DWORD  dwControlFlags 
)

Definition at line 362 of file nsplookup.c.

Referenced by NSPStartup().

◆ NSP_GetHostByNameHeapAllocW()

INT NSP_GetHostByNameHeapAllocW ( _In_ PWSHANDLEINTERN  data,
_In_ DWORD  dwControlFlags,
_Out_ PWSHOSTINFOINTERN  hostinfo 
)

Definition at line 466 of file nsplookup.c.

469{
470 HANDLE hHeap = GetProcessHeap();
471 DNS_STATUS dns_status = { 0 };
472 /* include/WinDNS.h -- look up DNS_RECORD on MSDN */
473 PDNS_RECORDW dp;
474 PDNS_RECORDW curr;
476 DWORD dwQueryFlags = DNS_QUERY_STANDARD;
477 PWCHAR Aliases[WS2_INTERNAL_MAX_ALIAS] = { 0 };
478 int AliasIndex = 0;
479
480 /* needed to be cleaned up if != NULL */
481 dp = NULL;
482
483 if (data->hostnameW == NULL)
484 {
486 goto cleanup;
487 }
488
489 if ((data->dwControlFlags & LUP_DEEP) == 0)
490 {
491 dwQueryFlags |= DNS_QUERY_NO_RECURSION;
492 }
493
494 /* DNS_TYPE_A: include/WinDNS.h */
495 /* DnsQuery -- lib/dnsapi/dnsapi/query.c */
496 dns_status = DnsQuery_W(data->hostnameW,
498 dwQueryFlags,
499 NULL /* extra dns servers */,
500 &dp,
501 NULL);
502 if (dns_status == ERROR_INVALID_NAME)
503 {
506 goto cleanup;
507 }
508
509 if ((dns_status != 0) || (dp == NULL))
510 {
512 goto cleanup;
513 }
514
515 //ASSERT(dp->wType == DNS_TYPE_A);
516 //ASSERT(dp->wDataLength == sizeof(DNS_A_DATA));
517 curr = dp;
518 while ((curr->pNext != NULL) || (curr->wType != DNS_TYPE_A))
519 {
520 if (curr->wType == DNS_TYPE_CNAME)
521 {
522 Aliases[AliasIndex++] = curr->Data.Cname.pNameHost;
523 }
524 curr = curr->pNext;
525 }
526
527 if (curr->wType != DNS_TYPE_A)
528 {
530 goto cleanup;
531 }
532 hostinfo->hostnameW = StrCpyHeapAllocW(hHeap, curr->pName);
533 hostinfo->addr4 = curr->Data.A.IpAddress;
534 if (AliasIndex)
535 {
536 hostinfo->servaliasesA = StrAryCpyHeapAllocWToA(hHeap, (WCHAR**)&Aliases);
537 }
539
540cleanup:
541 if (dp != NULL)
543
544 return result;
545}
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define ERROR_INVALID_NAME
Definition: compat.h:103
DNS_STATUS WINAPI DnsQuery_W(LPCWSTR Name, WORD Type, DWORD Options, PVOID Extra, PDNS_RECORD *QueryResultSet, PVOID *Reserved)
Definition: query.c:469
VOID WINAPI DnsRecordListFree(PDNS_RECORD list, DNS_FREE_TYPE type)
Definition: record.c:526
static void cleanup(void)
Definition: main.c:1335
unsigned long DWORD
Definition: ntddk_ex.h:95
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLuint64EXT * result
Definition: glext.h:11304
char ** StrAryCpyHeapAllocWToA(_In_opt_ HANDLE hHeap, _In_ WCHAR **wStrAry)
Definition: mswhelper.c:596
WCHAR * StrCpyHeapAllocW(_In_opt_ HANDLE hHeap, _In_ WCHAR *wStr)
Definition: mswhelper.c:484
#define WS2_INTERNAL_MAX_ALIAS
Definition: nsplookup.c:28
IP4_ADDRESS IpAddress
Definition: windns.h:246
LPWSTR pNameHost
Definition: windns.h:319
WORD wType
Definition: windns.h:600
LPWSTR pName
Definition: windns.h:599
struct _DnsRecordW * pNext
Definition: windns.h:598
DNS_A_DATA A
Definition: windns.h:609
union _DnsRecordW::@3310 Data
DNS_PTR_DATAW Cname
Definition: windns.h:611
uint16_t * PWCHAR
Definition: typedefs.h:56
#define DNS_QUERY_NO_RECURSION
Definition: windns.h:11
#define DNS_QUERY_STANDARD
Definition: windns.h:8
@ DnsFreeRecordList
Definition: windns.h:139
#define DNS_TYPE_CNAME
Definition: windns.h:45
#define DNS_TYPE_A
Definition: windns.h:41
#define WSAHOST_NOT_FOUND
Definition: winerror.h:2000
#define LUP_DEEP
Definition: winsock2.h:510
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by NSP_LookupServiceNextW().

◆ NSP_GetHostNameHeapAllocW()

INT NSP_GetHostNameHeapAllocW ( _Out_ WCHAR **  hostname)

Definition at line 443 of file nsplookup.c.

444{
445 WCHAR* name;
446 HANDLE hHeap = GetProcessHeap();
447 DWORD bufCharLen = MAX_COMPUTERNAME_LENGTH + 1;
448 DWORD bufByteLen = bufCharLen * sizeof(WCHAR);
449
450 name = HeapAlloc(hHeap, 0, bufByteLen);
451
452 if (!GetComputerNameExW(ComputerNameDnsHostname,
453 name,
454 &bufCharLen))
455 {
456 HeapFree(hHeap, 0, name);
458 return SOCKET_ERROR;
459 }
460
461 *hostname = name;
462 return ERROR_SUCCESS;
463}
char * hostname
Definition: ftp.c:88
BOOL WINAPI GetComputerNameExW(COMPUTER_NAME_FORMAT NameType, LPWSTR lpBuffer, LPDWORD nSize)
Definition: compname.c:216
Definition: name.c:39
#define MAX_COMPUTERNAME_LENGTH
Definition: winbase.h:243

Referenced by NSP_LookupServiceNextW().

◆ NSP_GetServiceByNameHeapAllocW()

INT NSP_GetServiceByNameHeapAllocW ( _In_ PWSHANDLEINTERN  data,
_In_ DWORD  dwControlFlags,
_Out_ PWSHOSTINFOINTERN  hostinfo 
)

Definition at line 700 of file nsplookup.c.

703{
704 BOOL Found = FALSE;
705 HANDLE ServicesFile;
706 CHAR ServiceDBData[BUFSIZ * sizeof(WCHAR)] = {0};
707 PCHAR ThisLine = 0, NextLine = 0, ServiceName = 0, PortNumberStr = 0,
708 ProtocolStr = 0, Comment = 0, EndValid;
709 PCHAR Aliases[WS2_INTERNAL_MAX_ALIAS] = {0};
710 PCHAR* AliasPtr;
711 UINT i = 0;
712 DWORD ReadSize = 0;
713 HANDLE hHeap;
714 PCHAR nameA = NULL;
715 PCHAR nameServiceA = NULL;
716 PCHAR nameProtoA = NULL;
718
719 if (!data->hostnameW)
720 {
722 goto End;
723 }
724
725 hHeap = GetProcessHeap();
726 nameA = StrW2AHeapAlloc(hHeap, data->hostnameW);
727
728 /* nameA has the form <service-name>/<protocol>
729 we split these now */
730 nameProtoA = strchr(nameA, '/');
731 if (nameProtoA == NULL)
732 {
734 goto End;
735 }
736
737 nameProtoA++;
738 i = (DWORD)(nameProtoA - nameA - 1);
739 nameServiceA = (PCHAR)HeapAlloc(hHeap, 0, i + 1);
740 StringCbCopyA(nameServiceA, i + 1, nameA);
741 nameServiceA[i] = '\0';
742
743 ServicesFile = OpenNetworkDatabase(L"services");
744 if (ServicesFile == INVALID_HANDLE_VALUE)
745 {
746 return WSANO_RECOVERY;
747 }
748
749 /* Scan the services file ...
750 *
751 * We will be share the buffer on the lines. If the line does not fit in
752 * the buffer, then moving it to the beginning of the buffer and read
753 * the remnants of line from file.
754 */
755
756 /* Initial Read */
757 ReadFile(ServicesFile,
758 ServiceDBData,
759 sizeof( ServiceDBData ) - 1,
760 &ReadSize,
761 NULL);
762
763 ThisLine = NextLine = ServiceDBData;
764 EndValid = ServiceDBData + ReadSize;
765 ServiceDBData[sizeof(ServiceDBData) - 1] = '\0';
766
767 while (ReadSize)
768 {
769 for (; *NextLine != '\r' && *NextLine != '\n'; NextLine++)
770 {
771 if (NextLine == EndValid)
772 {
773 int LineLen = NextLine - ThisLine;
774
775 if (ThisLine == ServiceDBData)
776 {
777 //WS_DbgPrint(MIN_TRACE,("Line too long"));
778 return WSANO_RECOVERY;
779 }
780
781 memmove(ServiceDBData, ThisLine, LineLen);
782
783 ReadFile(ServicesFile,
784 ServiceDBData + LineLen,
785 sizeof( ServiceDBData )-1 - LineLen,
786 &ReadSize,
787 NULL);
788
789 EndValid = ServiceDBData + LineLen + ReadSize;
790 NextLine = ServiceDBData + LineLen;
791 ThisLine = ServiceDBData;
792
793 if (!ReadSize) break;
794 }
795 }
796
797 *NextLine = '\0';
798 Comment = strchr(ThisLine, '#');
799
800 if (Comment)
801 *Comment = '\0'; /* Terminate at comment start */
802
803 if (DecodeServEntFromString(ThisLine,
805 &PortNumberStr,
806 &ProtocolStr,
807 Aliases,
809 (strlen(nameProtoA) == 0 || strcmp(ProtocolStr, nameProtoA) == 0))
810 {
811 Found = (strcmp(ServiceName, nameServiceA) == 0 || strcmp(PortNumberStr, nameServiceA) == 0);
812 AliasPtr = Aliases;
813 while ((!Found) && (*AliasPtr != NULL))
814 {
815 Found = (strcmp(*AliasPtr, nameServiceA) == 0);
816 AliasPtr++;
817 }
818 if (Found)
819 break;
820 }
821 NextLine++;
822 ThisLine = NextLine;
823 }
824
825 /* This we'll do no matter what */
826 CloseHandle(ServicesFile);
827
828 if (!Found)
829 {
830 return WSANO_DATA;
831 }
832
833 hostinfo->addr4 = 0;
834 hostinfo->servnameW = StrA2WHeapAlloc(hHeap, ServiceName);
835 hostinfo->servprotoW = StrA2WHeapAlloc(hHeap, ProtocolStr);
836 hostinfo->servaliasesA = StrAryCpyHeapAllocA(hHeap, (char**)&Aliases);
837 hostinfo->servport = atoi(PortNumberStr);
838
839 res = NO_ERROR;
840
841End:
842 if (nameA != NULL)
843 HeapFree(hHeap, 0, nameA);
844
845 if (nameServiceA != NULL)
846 HeapFree(hHeap, 0, nameServiceA);
847
848 return res;
849}
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
@ Comment
Definition: asmpp.cpp:34
return Found
Definition: dirsup.c:1270
#define CloseHandle
Definition: compat.h:739
#define ReadFile(a, b, c, d, e)
Definition: compat.h:742
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
unsigned int BOOL
Definition: ntddk_ex.h:94
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
_Check_return_ int __cdecl atoi(_In_z_ const char *_Str)
#define PCHAR
Definition: match.c:90
#define memmove(s1, s2, n)
Definition: mkisofs.h:881
WCHAR * StrA2WHeapAlloc(_In_opt_ HANDLE hHeap, _In_ char *aStr)
Definition: mswhelper.c:399
char * StrW2AHeapAlloc(_In_opt_ HANDLE hHeap, _In_ WCHAR *wStr)
Definition: mswhelper.c:442
char ** StrAryCpyHeapAllocA(_In_opt_ HANDLE hHeap, _In_ char **aStrAry)
Definition: mswhelper.c:530
HANDLE WSAAPI OpenNetworkDatabase(_In_ LPCWSTR Name)
Definition: nsplookup.c:608
#define BUFSIZ
Definition: nsplookup.c:25
static BOOL DecodeServEntFromString(IN PCHAR ServiceString, OUT PCHAR *ServiceName, OUT PCHAR *PortNumberStr, OUT PCHAR *ProtocolStr, IN PCHAR *Aliases, IN DWORD MaxAlias)
Definition: nsplookup.c:556
#define DWORD
Definition: nt_native.h:44
#define L(x)
Definition: ntvdm.h:50
BOOLEAN NextLine(PCHAR LineBuffer, ULONG BufferSize, FILE *File)
Definition: parser.c:230
STRSAFEAPI StringCbCopyA(STRSAFE_LPSTR pszDest, size_t cbDest, STRSAFE_LPCSTR pszSrc)
Definition: strsafe.h:161
char * PCHAR
Definition: typedefs.h:51
#define WSANO_DATA
Definition: winerror.h:2003
#define WSANO_RECOVERY
Definition: winerror.h:2002
char CHAR
Definition: xmlstorage.h:175

Referenced by NSP_LookupServiceNextW().

◆ NSP_LookupServiceBeginW()

INT NSP_LookupServiceBeginW ( PWSHANDLEINTERN  data,
CHAR hostnameA,
WCHAR hostnameW,
DWORD  CallID 
)

Definition at line 407 of file nsplookup.c.

411{
412 HANDLE hHeap;
413
414 if (data->CallID != 0)
415 return WSAEFAULT;
416
417 data->CallID = CallID;
418
419 if ((CallID == NSP_CALLID_HOSTBYNAME) ||
420 (CallID == NSP_CALLID_SERVICEBYNAME))
421 {
422 hHeap = GetProcessHeap();
423
424 if (data->hostnameW != NULL)
425 HeapFree(hHeap, 0, data->hostnameW);
426
427 if (hostnameA != NULL)
428 {
429 data->hostnameW = StrA2WHeapAlloc(hHeap, hostnameA);
430 }
431 else
432 {
433 data->hostnameW = StrCpyHeapAllocW(hHeap, hostnameW);
434 }
435 }
436
438
439 return ERROR_SUCCESS;
440}

Referenced by mwsNSPLookupServiceBegin().

◆ NSP_LookupServiceNextW()

INT NSP_LookupServiceNextW ( _In_ PWSHANDLEINTERN  data,
_In_ DWORD  dwControlFlags,
_Inout_ LPWSAQUERYSETW  lpRes,
_Inout_ LPDWORD  lpResLen 
)

Definition at line 852 of file nsplookup.c.

856{
858 WSHOSTINFOINTERN hostinfo;
859 INT result;
860 HANDLE hHeap = GetProcessHeap();
861 WCHAR* ServiceInstanceNameW = NULL;
862 /* cleanup-vars */
863 CHAR* ServiceInstanceNameA = NULL;
864 CHAR* ServiceProtocolNameA = NULL;
865
866 RtlZeroMemory(&hostinfo, sizeof(hostinfo));
867
868 /* init and build result-buffer */
869 mswBufferInit(&buf, (BYTE*)lpRes, *lpResLen);
870 mswBufferIncUsed(&buf, sizeof(*lpRes));
871
872 /* QueryDataSet-Size without "blob-data"-size! */
873 lpRes->dwSize = sizeof(*lpRes);
874 lpRes->dwNameSpace = NS_DNS;
875
876 if ((data->CallID == NSP_CALLID_HOSTNAME) ||
877 (data->CallID == NSP_CALLID_HOSTBYNAME) ||
878 (data->CallID == NSP_CALLID_SERVICEBYNAME))
879 {
880 if (data->CallIDCounter >= 1)
881 {
883 goto End;
884 }
885 }
886 else
887 {
889 goto End;
890 }
891 data->CallIDCounter++;
892
893 if (data->CallID == NSP_CALLID_HOSTNAME)
894 {
896
897 if (result != ERROR_SUCCESS)
898 goto End;
899
900 hostinfo.addr4 = 0;
901 }
902 else if (data->CallID == NSP_CALLID_HOSTBYNAME)
903 {
905 dwControlFlags,
906 &hostinfo);
907 if (result != ERROR_SUCCESS)
908 goto End;
909 }
910 else
911 {
914 dwControlFlags,
915 &hostinfo);
916 if (result != ERROR_SUCCESS)
917 goto End;
918 }
919
920 if (((LUP_RETURN_BLOB & data->dwControlFlags) != 0) ||
921 ((LUP_RETURN_NAME & data->dwControlFlags) != 0))
922 {
923 if (data->CallID == NSP_CALLID_HOSTNAME || data->CallID == NSP_CALLID_HOSTBYNAME)
924 {
925 ServiceInstanceNameW = hostinfo.hostnameW;
926 ServiceInstanceNameA = StrW2AHeapAlloc(hHeap, ServiceInstanceNameW);
927 if (ServiceInstanceNameA == NULL)
928 {
930 goto End;
931
932 }
933 }
934 if (data->CallID == NSP_CALLID_SERVICEBYNAME)
935 {
936 ServiceInstanceNameW = hostinfo.servnameW;
937 ServiceInstanceNameA = StrW2AHeapAlloc(hHeap, ServiceInstanceNameW);
938 if (ServiceInstanceNameA == NULL)
939 {
941 goto End;
942
943 }
944 ServiceProtocolNameA = StrW2AHeapAlloc(hHeap, hostinfo.servprotoW);
945 if (ServiceProtocolNameA == NULL)
946 {
948 goto End;
949
950 }
951 }
952 }
953
954 if ((LUP_RETURN_ADDR & data->dwControlFlags) != 0)
955 {
956 if (!mswBufferAppendAddr_AddrInfoW(&buf, lpRes, hostinfo.addr4))
957 {
958 *lpResLen = buf.bytesUsed;
960 goto End;
961 }
962 }
963
964 if ((LUP_RETURN_BLOB & data->dwControlFlags) != 0)
965 {
966 if (data->CallID == NSP_CALLID_HOSTBYNAME)
967 {
968 /* Write data for PBLOB (hostent) */
970 lpRes,
971 (LUP_RETURN_ALIASES & data->dwControlFlags) != 0 ? hostinfo.servaliasesA : NULL,
972 ServiceInstanceNameA,
973 hostinfo.addr4))
974 {
975 *lpResLen = buf.bytesUsed;
977 goto End;
978 }
979 }
980 else if (data->CallID == NSP_CALLID_SERVICEBYNAME)
981 {
982 /* Write data for PBLOB (servent) */
984 lpRes,
985 ServiceInstanceNameA,/* ServiceName */
986 (LUP_RETURN_ALIASES & data->dwControlFlags) != 0 ? hostinfo.servaliasesA : NULL,
987 ServiceProtocolNameA,
988 hostinfo.servport))
989 {
990 *lpResLen = buf.bytesUsed;
992 goto End;
993 }
994 }
995 else
996 {
998 goto End;
999 }
1000 }
1001
1002 if ((LUP_RETURN_NAME & data->dwControlFlags) != 0)
1003 {
1004 /* HostByName sets the ServiceInstanceName to a
1005 (UNICODE)copy of hostent.h_name */
1006 lpRes->lpszServiceInstanceName = (LPWSTR)mswBufferEndPtr(&buf);
1007 if (!mswBufferAppendStrW(&buf, ServiceInstanceNameW))
1008 {
1009 lpRes->lpszServiceInstanceName = NULL;
1010 *lpResLen = buf.bytesUsed;
1011 result = WSAEFAULT;
1012 goto End;
1013 }
1014 }
1015
1016 *lpResLen = buf.bytesUsed;
1017
1019End:
1020 /* cleanup */
1021 if (ServiceInstanceNameA != NULL)
1022 HeapFree(hHeap, 0, ServiceInstanceNameA);
1023
1024 if (ServiceProtocolNameA != NULL)
1025 HeapFree(hHeap, 0, ServiceProtocolNameA);
1026
1027 if (hostinfo.hostnameW != NULL)
1028 HeapFree(hHeap, 0, hostinfo.hostnameW);
1029
1030 if (hostinfo.servnameW != NULL)
1031 HeapFree(hHeap, 0, hostinfo.servnameW);
1032
1033 if (hostinfo.servprotoW != NULL)
1034 HeapFree(hHeap, 0, hostinfo.servprotoW);
1035
1036 return result;
1037}
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define ASSERT(a)
Definition: mode.c:44
BOOL mswBufferIncUsed(_Inout_ PMSW_BUFFER mswBuf, _In_ DWORD count)
Definition: mswhelper.c:39
BOOL mswBufferAppendAddr_AddrInfoW(_Inout_ PMSW_BUFFER mswBuf, _Inout_ LPWSAQUERYSETW lpRes, _In_ DWORD ip4addr)
Definition: mswhelper.c:352
BOOL mswBufferAppendStrW(_Inout_ PMSW_BUFFER mswBuf, _In_ WCHAR *str)
Definition: mswhelper.c:78
BOOL mswBufferAppendBlob_Hostent(_Inout_ PMSW_BUFFER mswBuf, _Inout_ LPWSAQUERYSETW lpRes, _In_ char **hostAliasesA, _In_ char *hostnameA, _In_ DWORD ip4addr)
Definition: mswhelper.c:227
void mswBufferInit(_Inout_ PMSW_BUFFER mswBuf, _In_ BYTE *buffer, _In_ DWORD bufferSize)
Definition: mswhelper.c:15
BYTE * mswBufferEndPtr(_Inout_ PMSW_BUFFER mswBuf)
Definition: mswhelper.c:51
BOOL mswBufferAppendBlob_Servent(_Inout_ PMSW_BUFFER mswBuf, _Inout_ LPWSAQUERYSETW lpRes, _In_ char *serviceNameA, _In_ char **serviceAliasesA, _In_ char *protocolNameA, _In_ WORD port)
Definition: mswhelper.c:294
#define NS_DNS
Definition: nspapi.h:16
INT NSP_GetHostNameHeapAllocW(_Out_ WCHAR **hostname)
Definition: nsplookup.c:443
INT NSP_GetServiceByNameHeapAllocW(_In_ PWSHANDLEINTERN data, _In_ DWORD dwControlFlags, _Out_ PWSHOSTINFOINTERN hostinfo)
Definition: nsplookup.c:700
INT NSP_GetHostByNameHeapAllocW(_In_ PWSHANDLEINTERN data, _In_ DWORD dwControlFlags, _Out_ PWSHOSTINFOINTERN hostinfo)
Definition: nsplookup.c:466
WCHAR * servprotoW
Definition: nsplookup.c:39
CHAR ** servaliasesA
Definition: nsplookup.c:40
WCHAR * hostnameW
Definition: nsplookup.c:36
WCHAR * servnameW
Definition: nsplookup.c:38
#define WSAENOMORE
Definition: winerror.h:1989
#define LUP_RETURN_BLOB
Definition: winsock2.h:519
#define LUP_RETURN_ALIASES
Definition: winsock2.h:520
#define LUP_RETURN_ADDR
Definition: winsock2.h:518
#define LUP_RETURN_NAME
Definition: winsock2.h:514
WCHAR * LPWSTR
Definition: xmlstorage.h:184
unsigned char BYTE
Definition: xxhash.c:193

Referenced by mwsNSPLookupServiceNext().

◆ NSPStartup()

int WINAPI NSPStartup ( _In_ LPGUID  lpProviderId,
_Out_ LPNSP_ROUTINE  lpRout 
)

Definition at line 1045 of file nsplookup.c.

1047{
1048 INT ret;
1049
1050 if ((lpRout == NULL) ||
1051 (lpRout->cbSize != sizeof(NSP_ROUTINE)))
1052 {
1055 }
1056
1057 mwsNSPInit();
1058
1059 /* set own Provider GUID - maybe we need
1060 here to set the original mswsock-GUID?! */
1061
1062 /* Win2k3 returns
1063 - Version 1.1
1064 - no NSPIoctl
1065 - sets cbSize to 44! */
1066 lpRout->dwMajorVersion = 1;
1067 lpRout->dwMinorVersion = 1;
1068 lpRout->cbSize = sizeof(*lpRout) - sizeof(lpRout->NSPIoctl);
1069 lpRout->NSPCleanup = &mwsNSPCleanUp;
1070 lpRout->NSPLookupServiceBegin = &mwsNSPLookupServiceBegin;
1071 lpRout->NSPLookupServiceNext = &mwsNSPLookupServiceNext;
1072 lpRout->NSPLookupServiceEnd = &mwsNSPLookupServiceEnd;
1073 lpRout->NSPSetService = &mwsNSPSetService;
1074 lpRout->NSPInstallServiceClass = &mwsNSPInstallServiceClass;
1075 lpRout->NSPRemoveServiceClass = &mwsNSPRemoveServiceClass;
1076 lpRout->NSPGetServiceClassInfo = &mwsNSPGetServiceClassInfo;
1077 lpRout->NSPIoctl = NULL;// &mwsNSPIoCtl;
1078
1079 ret = NO_ERROR;
1080
1081 return ret;
1082}
INT WSAAPI mwsNSPCleanUp(_In_ LPGUID lpProviderId)
Definition: nsplookup.c:132
INT WSAAPI mwsNSPLookupServiceEnd(_In_ HANDLE hLookup)
Definition: nsplookup.c:339
INT WSAAPI mwsNSPLookupServiceBegin(_In_ LPGUID lpProviderId, _In_ LPWSAQUERYSETW lpqsRestrictions, _In_ LPWSASERVICECLASSINFOW lpServiceClassInfo, _In_ DWORD dwControlFlags, _Out_ LPHANDLE lphLookup)
Definition: nsplookup.c:147
INT WSAAPI mwsNSPInstallServiceClass(_In_ LPGUID lpProviderId, _In_ LPWSASERVICECLASSINFOW lpServiceClassInfo)
Definition: nsplookup.c:374
INT WSAAPI mwsNSPSetService(_In_ LPGUID lpProviderId, _In_ LPWSASERVICECLASSINFOW lpServiceClassInfo, _In_ LPWSAQUERYSETW lpqsRegInfo, _In_ WSAESETSERVICEOP essOperation, _In_ DWORD dwControlFlags)
Definition: nsplookup.c:362
INT WSAAPI mwsNSPRemoveServiceClass(_In_ LPGUID lpProviderId, _In_ LPGUID lpServiceClassId)
Definition: nsplookup.c:383
INT mwsNSPInit(VOID)
Definition: nsplookup.c:140
INT WSAAPI mwsNSPGetServiceClassInfo(_In_ LPGUID lpProviderId, _In_ LPDWORD lpdwBufSize, _In_ LPWSASERVICECLASSINFOW lpServiceClassInfo)
Definition: nsplookup.c:392
INT WSAAPI mwsNSPLookupServiceNext(_In_ HANDLE hLookup, _In_ DWORD dwControlFlags, _Inout_ LPDWORD lpdwBufferLength, LPWSAQUERYSETW lpqsResults)
Definition: nsplookup.c:269
int ret

◆ OpenNetworkDatabase()

HANDLE WSAAPI OpenNetworkDatabase ( _In_ LPCWSTR  Name)

Definition at line 608 of file nsplookup.c.

609{
610 PWSTR ExpandedPath;
613 HKEY DatabaseKey;
614 DWORD RegType;
615 DWORD RegSize = 0;
616 size_t StringLength;
617 HANDLE ret;
618
619 ExpandedPath = HeapAlloc(GetProcessHeap(), 0, MAX_PATH*sizeof(WCHAR));
620 if (!ExpandedPath)
622
623 /* Open the database path key */
625 L"System\\CurrentControlSet\\Services\\Tcpip\\Parameters",
626 0,
627 KEY_READ,
628 &DatabaseKey);
629 if (ErrorCode == NO_ERROR)
630 {
631 /* Read the actual path */
632 ErrorCode = RegQueryValueEx(DatabaseKey,
633 L"DatabasePath",
634 NULL,
635 &RegType,
636 NULL,
637 &RegSize);
638
639 DatabasePath = HeapAlloc(GetProcessHeap(), 0, RegSize);
640 if (!DatabasePath)
641 {
642 HeapFree(GetProcessHeap(), 0, ExpandedPath);
644 }
645
646 /* Read the actual path */
647 ErrorCode = RegQueryValueEx(DatabaseKey,
648 L"DatabasePath",
649 NULL,
650 &RegType,
652 &RegSize);
653
654 /* Close the key */
655 RegCloseKey(DatabaseKey);
656
657 /* Expand the name */
659
661 }
662 else
663 {
664 /* Use defalt path */
665 GetSystemDirectory(ExpandedPath, MAX_PATH);
666 StringCchLength(ExpandedPath, MAX_PATH, &StringLength);
667 if (ExpandedPath[StringLength - 1] != L'\\')
668 {
669 /* It isn't, so add it ourselves */
670 StringCchCat(ExpandedPath, MAX_PATH, L"\\");
671 }
672 StringCchCat(ExpandedPath, MAX_PATH, L"DRIVERS\\ETC\\");
673 }
674
675 /* Make sure that the path is backslash-terminated */
676 StringCchLength(ExpandedPath, MAX_PATH, &StringLength);
677 if (ExpandedPath[StringLength - 1] != L'\\')
678 {
679 /* It isn't, so add it ourselves */
680 StringCchCat(ExpandedPath, MAX_PATH, L"\\");
681 }
682
683 /* Add the database name */
684 StringCchCat(ExpandedPath, MAX_PATH, Name);
685
686 /* Return a handle to the file */
687 ret = CreateFile(ExpandedPath,
690 NULL,
693 NULL);
694
695 HeapFree(GetProcessHeap(), 0, ExpandedPath);
696 return ret;
697}
#define RegCloseKey(hKey)
Definition: registry.h:49
#define OPEN_EXISTING
Definition: compat.h:775
#define MAX_PATH
Definition: compat.h:34
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
#define FILE_SHARE_READ
Definition: compat.h:136
PWSTR DatabasePath
Definition: database.c:31
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4436
#define FILE_READ_DATA
Definition: nt_native.h:628
#define KEY_READ
Definition: nt_native.h:1023
#define StringCchLength
Definition: strsafe.h:829
#define StringCchCat
Definition: strsafe.h:317
uint16_t * PWSTR
Definition: typedefs.h:56
unsigned char * LPBYTE
Definition: typedefs.h:53
#define GetSystemDirectory
Definition: winbase.h:3842
#define ExpandEnvironmentStrings
Definition: winbase.h:3774
#define CreateFile
Definition: winbase.h:3749
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define RegOpenKeyEx
Definition: winreg.h:520
#define RegQueryValueEx
Definition: winreg.h:524

Referenced by NSP_GetServiceByNameHeapAllocW().

Variable Documentation

◆ guid_HOSTNAME

const GUID guid_HOSTNAME = SVCID_HOSTNAME
static

Definition at line 57 of file nsplookup.c.

Referenced by mwsNSPLookupServiceBegin().

◆ guid_INET_HOSTADDRBYINETSTRING

const GUID guid_INET_HOSTADDRBYINETSTRING = SVCID_INET_HOSTADDRBYINETSTRING
static

Definition at line 58 of file nsplookup.c.

Referenced by mwsNSPLookupServiceBegin().

◆ guid_INET_HOSTADDRBYNAME

const GUID guid_INET_HOSTADDRBYNAME = SVCID_INET_HOSTADDRBYNAME
static

Definition at line 59 of file nsplookup.c.

Referenced by mwsNSPLookupServiceBegin().

◆ guid_INET_SERVICEBYNAME

const GUID guid_INET_SERVICEBYNAME = SVCID_INET_SERVICEBYNAME
static

Definition at line 60 of file nsplookup.c.

Referenced by mwsNSPLookupServiceBegin().

◆ guid_mswsock_NLA

const GUID guid_mswsock_NLA
static
Initial value:
= { 0x6642243A,
0x3BA8,
0x4AA6,
{0xBA, 0xA5, 0x2E, 0x0B, 0xD7, 0x1F, 0xDD, 0x83}}

Definition at line 71 of file nsplookup.c.

Referenced by mwsNSPLookupServiceBegin().

◆ guid_mswsock_TcpIp

const GUID guid_mswsock_TcpIp
static
Initial value:
= { 0x22059D40,
0x7E9E,
0x11CF,
{0xAE, 0x5A, 0x00, 0xAA, 0x00, 0xA7, 0x11, 0x2B}}

Definition at line 64 of file nsplookup.c.

Referenced by mwsNSPLookupServiceBegin().

◆ guid_NULL

const GUID guid_NULL = {0}
static

Definition at line 56 of file nsplookup.c.

Referenced by mwsNSPLookupServiceBegin().