ReactOS  0.4.14-dev-77-gd9e7c48
nsplookup.c File Reference
#include "precomp.h"
#include <stdlib.h>
#include <ws2spi.h>
#include <nspapi.h>
#include <windef.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 26 of file nsplookup.c.

◆ NDEBUG

#define NDEBUG

Definition at line 17 of file nsplookup.c.

◆ NSP_CALLID_DNS

#define NSP_CALLID_DNS   0x0001

Definition at line 20 of file nsplookup.c.

◆ NSP_CALLID_HOSTBYNAME

#define NSP_CALLID_HOSTBYNAME   0x0003

Definition at line 22 of file nsplookup.c.

◆ NSP_CALLID_HOSTNAME

#define NSP_CALLID_HOSTNAME   0x0002

Definition at line 21 of file nsplookup.c.

◆ NSP_CALLID_SERVICEBYNAME

#define NSP_CALLID_SERVICEBYNAME   0x0004

Definition at line 23 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 551 of file nsplookup.c.

◆ SKIPWS

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

Definition at line 548 of file nsplookup.c.

◆ WS2_INTERNAL_MAX_ALIAS

#define WS2_INTERNAL_MAX_ALIAS   512

Definition at line 29 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 557 of file nsplookup.c.

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

Referenced by NSP_GetServiceByNameHeapAllocW().

◆ mswNSPStartup()

INT WINAPI mswNSPStartup ( LPGUID  lpProviderId,
LPNSP_ROUTINE  lpRout 
)

◆ mwsNSPCleanUp()

INT WSAAPI mwsNSPCleanUp ( _In_ LPGUID  lpProviderId)

Definition at line 133 of file nsplookup.c.

134 {
135  //WSASetLastError(ERROR_CALL_NOT_IMPLEMENTED);
136  //return ERROR_CALL_NOT_IMPLEMENTED;
137  return ERROR_SUCCESS;
138 }
#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 393 of file nsplookup.c.

396 {
399 }
VOID WSAAPI WSASetLastError(IN INT iError)
Definition: dllmain.c:123
#define ERROR_CALL_NOT_IMPLEMENTED
Definition: compat.h:92

Referenced by NSPStartup().

◆ mwsNSPInit()

INT mwsNSPInit ( VOID  )

Definition at line 141 of file nsplookup.c.

142 {
143  return ERROR_SUCCESS;
144 }
#define ERROR_SUCCESS
Definition: deptool.c:10

Referenced by NSPStartup().

◆ mwsNSPInstallServiceClass()

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

Definition at line 375 of file nsplookup.c.

377 {
380 }
VOID WSAAPI WSASetLastError(IN INT iError)
Definition: dllmain.c:123
#define ERROR_CALL_NOT_IMPLEMENTED
Definition: compat.h:92

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 324 of file nsplookup.c.

333 {
336 }
VOID WSAAPI WSASetLastError(IN INT iError)
Definition: dllmain.c:123
#define ERROR_CALL_NOT_IMPLEMENTED
Definition: compat.h:92

◆ mwsNSPLookupServiceBegin()

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

Definition at line 148 of file nsplookup.c.

153 {
154  PWSHANDLEINTERN pLook;
155  int wsaErr;
156 
157  if (IsEqualGUID(lpProviderId, &guid_mswsock_TcpIp))
158  {
159  //OK
160  }
161  else if (IsEqualGUID(lpProviderId, &guid_mswsock_NLA))
162  {
164  return SOCKET_ERROR;
165  }
166  else
167  {
169  }
170 
171  /* allocate internal structure */
172  pLook = HeapAlloc(GetProcessHeap(), 0, sizeof(WSHANDLEINTERN));
173  if (!pLook)
174  {
176  return SOCKET_ERROR;
177  }
178 
179  *lphLookup = (HANDLE)pLook;
180 
181  RtlZeroMemory(pLook, sizeof(*pLook));
182 
183  /* Anyway the ControlFlags "should" be needed
184  in NSPLookupServiceNext. (see doku) But
185  thats not the fact ATM. */
186  pLook->dwControlFlags = dwControlFlags;
187  pLook->providerId = *lpProviderId;
188 
189 #ifdef NSP_REDIRECT
190 
191  if (IsEqualGUID(lpProviderId, &guid_mswsock_TcpIp))
192  {
193  pLook->rdrproc = rdrproc_tcpip;
194  }
195  else if (IsEqualGUID(lpProviderId, &guid_mswsock_NLA))
196  {
197  pLook->rdrproc = rdrproc_nla;
198  }
199  else
200  {
202  }
203 
204  if (pLook->rdrproc.NSPLookupServiceBegin(lpProviderId,
205  lpqsRestrictions,
206  lpServiceClassInfo,
207  dwControlFlags,
208  &pLook->rdrLookup) == NO_ERROR)
209  {
210  wsaErr = NO_ERROR;
211  }
212  else
213  {
214  wsaErr = WSAGetLastError();
215  }
216 
217  /*
218  if (res)
219  res = WSAGetLastError();
220  */
221 
222 #else /* NSP_REDIRECT */
223 
225  if (IsEqualGUID(lpqsRestrictions->lpServiceClassId, &guid_NULL))
226  {
228  }
229  else if (IsEqualGUID(lpqsRestrictions->lpServiceClassId, &guid_HOSTNAME))
230  {
231  wsaErr = NSP_LookupServiceBeginW(pLook,
232  NULL,
233  NULL,
235  }
236  else if (IsEqualGUID(lpqsRestrictions->lpServiceClassId,
238  {
239  wsaErr = NSP_LookupServiceBeginW(pLook,
240  NULL,
241  lpqsRestrictions->lpszServiceInstanceName,
243  }
244  else if (IsEqualGUID(lpqsRestrictions->lpServiceClassId,
246  {
247  wsaErr = NSP_LookupServiceBeginW(pLook,
248  NULL,
249  lpqsRestrictions->lpszServiceInstanceName,
251  }
252  else if (IsEqualGUID(lpqsRestrictions->lpServiceClassId,
254  {
256  }
257 
258 #endif /* NSP_REDIRECT */
259 
260  if (wsaErr != NO_ERROR)
261  {
262  WSASetLastError(wsaErr);
263  return SOCKET_ERROR;
264  }
265  return NO_ERROR;
266 }
#define NSP_CALLID_HOSTNAME
Definition: nsplookup.c:21
#define SOCKET_ERROR
Definition: winsock.h:333
static const GUID guid_INET_HOSTADDRBYNAME
Definition: nsplookup.c:60
#define WSAEFAULT
Definition: winerror.h:1945
#define WSASERVICE_NOT_FOUND
Definition: winerror.h:1995
#define NSP_CALLID_SERVICEBYNAME
Definition: nsplookup.c:23
DWORD dwControlFlags
Definition: nsplookup.c:47
static const GUID guid_INET_HOSTADDRBYINETSTRING
Definition: nsplookup.c:59
#define NO_ERROR
Definition: dderror.h:5
static const GUID guid_mswsock_NLA
Definition: nsplookup.c:72
GUID providerId
Definition: nsplookup.c:46
smooth NULL
Definition: ftsmooth.c:416
VOID WSAAPI WSASetLastError(IN INT iError)
Definition: dllmain.c:123
#define NSP_CALLID_HOSTBYNAME
Definition: nsplookup.c:22
INT WSAAPI WSAGetLastError(VOID)
Definition: dllmain.c:112
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
static const GUID guid_NULL
Definition: nsplookup.c:57
PVOID HANDLE
Definition: typedefs.h:71
INT NSP_LookupServiceBeginW(PWSHANDLEINTERN data, CHAR *hostnameA, WCHAR *hostnameW, DWORD CallID)
Definition: nsplookup.c:408
static const GUID guid_mswsock_TcpIp
Definition: nsplookup.c:65
BOOL WINAPI IsEqualGUID(REFGUID rguid1, REFGUID rguid2)
Definition: compobj.c:4021
#define ERROR_CALL_NOT_IMPLEMENTED
Definition: compat.h:92
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
static const GUID guid_HOSTNAME
Definition: nsplookup.c:58
static const GUID guid_INET_SERVICEBYNAME
Definition: nsplookup.c:61

Referenced by NSPStartup().

◆ mwsNSPLookupServiceEnd()

INT WSAAPI mwsNSPLookupServiceEnd ( _In_ HANDLE  hLookup)

Definition at line 340 of file nsplookup.c.

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

Referenced by NSPStartup().

◆ mwsNSPLookupServiceNext()

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

Definition at line 270 of file nsplookup.c.

275 {
276  PWSHANDLEINTERN pLook = hLookup;
277  int wsaErr = 0;
278 
279 #ifdef NSP_REDIRECT
280 
281  INT res = pLook->rdrproc.NSPLookupServiceNext(pLook->rdrLookup,
282  dwControlFlags,
284  lpqsResults);
285  wsaErr = WSAGetLastError();
286  if (res != ERROR_SUCCESS)
287  {
288  wsaErr = WSAGetLastError();
289 
290  if (wsaErr == 0)
291  wsaErr = 0xFFFFFFFF;
292  }
293 
294 #else /* NSP_REDIRECT */
295 
296  if ((lpdwBufferLength == NULL) || (*lpdwBufferLength == 0))
297  {
298  wsaErr = WSA_NOT_ENOUGH_MEMORY;
299  goto End;
300  }
301 
302  RtlZeroMemory(lpqsResults, *lpdwBufferLength);
303  lpqsResults->dwSize = sizeof(*lpqsResults);
304 
305  wsaErr = NSP_LookupServiceNextW(pLook,
306  dwControlFlags,
307  lpqsResults,
309 
310 
311 #endif /* NSP_REDIRECT */
312 
313 End:
314  if (wsaErr != 0)
315  {
316  WSASetLastError(wsaErr);
317  return SOCKET_ERROR;
318  }
319  return NO_ERROR;
320 }
#define SOCKET_ERROR
Definition: winsock.h:333
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NO_ERROR
Definition: dderror.h:5
int32_t INT
Definition: typedefs.h:56
INT NSP_LookupServiceNextW(_In_ PWSHANDLEINTERN data, _In_ DWORD dwControlFlags, _Inout_ LPWSAQUERYSETW lpRes, _Inout_ LPDWORD lpResLen)
Definition: nsplookup.c:853
smooth NULL
Definition: ftsmooth.c:416
VOID WSAAPI WSASetLastError(IN INT iError)
Definition: dllmain.c:123
INT WSAAPI WSAGetLastError(VOID)
Definition: dllmain.c:112
#define WSA_NOT_ENOUGH_MEMORY
Definition: winsock2.h:593
GLuint res
Definition: glext.h:9613
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
_In_ _In_opt_ _Out_writes_bytes_to_opt_ lpdwBufferLength _Inout_ LPDWORD lpdwBufferLength
Definition: winhttp.h:675

Referenced by NSPStartup().

◆ mwsNSPRemoveServiceClass()

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

Definition at line 384 of file nsplookup.c.

386 {
389 }
VOID WSAAPI WSASetLastError(IN INT iError)
Definition: dllmain.c:123
#define ERROR_CALL_NOT_IMPLEMENTED
Definition: compat.h:92

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 363 of file nsplookup.c.

368 {
371 }
VOID WSAAPI WSASetLastError(IN INT iError)
Definition: dllmain.c:123
#define ERROR_CALL_NOT_IMPLEMENTED
Definition: compat.h:92

Referenced by NSPStartup().

◆ NSP_GetHostByNameHeapAllocW()

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

Definition at line 467 of file nsplookup.c.

470 {
471  HANDLE hHeap = GetProcessHeap();
472  DNS_STATUS dns_status = { 0 };
473  /* include/WinDNS.h -- look up DNS_RECORD on MSDN */
474  PDNS_RECORDW dp;
475  PDNS_RECORDW curr;
477  DWORD dwQueryFlags = DNS_QUERY_STANDARD;
478  PWCHAR Aliases[WS2_INTERNAL_MAX_ALIAS] = { 0 };
479  int AliasIndex = 0;
480 
481  /* needed to be cleaned up if != NULL */
482  dp = NULL;
483 
484  if (data->hostnameW == NULL)
485  {
487  goto cleanup;
488  }
489 
490  if ((data->dwControlFlags & LUP_DEEP) == 0)
491  {
492  dwQueryFlags |= DNS_QUERY_NO_RECURSION;
493  }
494 
495  /* DNS_TYPE_A: include/WinDNS.h */
496  /* DnsQuery -- lib/dnsapi/dnsapi/query.c */
497  dns_status = DnsQuery_W(data->hostnameW,
498  DNS_TYPE_A,
499  dwQueryFlags,
500  NULL /* extra dns servers */,
501  &dp,
502  NULL);
503  if (dns_status == ERROR_INVALID_NAME)
504  {
507  goto cleanup;
508  }
509 
510  if ((dns_status != 0) || (dp == NULL))
511  {
513  goto cleanup;
514  }
515 
516  //ASSERT(dp->wType == DNS_TYPE_A);
517  //ASSERT(dp->wDataLength == sizeof(DNS_A_DATA));
518  curr = dp;
519  while ((curr->pNext != NULL) || (curr->wType != DNS_TYPE_A))
520  {
521  if (curr->wType == DNS_TYPE_CNAME)
522  {
523  Aliases[AliasIndex++] = curr->Data.Cname.pNameHost;
524  }
525  curr = curr->pNext;
526  }
527 
528  if (curr->wType != DNS_TYPE_A)
529  {
531  goto cleanup;
532  }
533  hostinfo->hostnameW = StrCpyHeapAllocW(hHeap, curr->pName);
534  hostinfo->addr4 = curr->Data.A.IpAddress;
535  if (AliasIndex)
536  {
537  hostinfo->servaliasesA = StrAryCpyHeapAllocWToA(hHeap, (WCHAR**)&Aliases);
538  }
540 
541 cleanup:
542  if (dp != NULL)
544 
545  return result;
546 }
DNS_A_DATA A
Definition: windns.h:609
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
#define DNS_TYPE_A
Definition: windns.h:41
#define WSAEFAULT
Definition: winerror.h:1945
#define WSAHOST_NOT_FOUND
Definition: winerror.h:2000
WCHAR * StrCpyHeapAllocW(_In_opt_ HANDLE hHeap, _In_ WCHAR *wStr)
Definition: mswhelper.c:484
#define ERROR_SUCCESS
Definition: deptool.c:10
#define WSASERVICE_NOT_FOUND
Definition: winerror.h:1995
#define WS2_INTERNAL_MAX_ALIAS
Definition: nsplookup.c:29
#define DNS_QUERY_STANDARD
Definition: windns.h:8
#define LUP_DEEP
Definition: winsock2.h:510
uint16_t * PWCHAR
Definition: typedefs.h:54
int32_t INT
Definition: typedefs.h:56
#define DNS_QUERY_NO_RECURSION
Definition: windns.h:11
smooth NULL
Definition: ftsmooth.c:416
#define DNS_TYPE_CNAME
Definition: windns.h:45
LPWSTR pNameHost
Definition: windns.h:319
VOID WSAAPI WSASetLastError(IN INT iError)
Definition: dllmain.c:123
union _DnsRecordW::@3172 Data
IP4_ADDRESS IpAddress
Definition: windns.h:246
#define GetProcessHeap()
Definition: compat.h:395
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned long DWORD
Definition: ntddk_ex.h:95
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
VOID WINAPI DnsRecordListFree(PDNS_RECORD list, DNS_FREE_TYPE type)
Definition: record.c:526
WORD wType
Definition: windns.h:600
char ** StrAryCpyHeapAllocWToA(_In_opt_ HANDLE hHeap, _In_ WCHAR **wStrAry)
Definition: mswhelper.c:596
struct _DnsRecordW * pNext
Definition: windns.h:598
char * cleanup(char *str)
Definition: wpickclick.c:99
#define ERROR_INVALID_NAME
Definition: compat.h:93
DNS_STATUS WINAPI DnsQuery_W(LPCWSTR Name, WORD Type, DWORD Options, PIP4_ARRAY Servers, PDNS_RECORD *QueryResultSet, PVOID *Reserved)
Definition: query.c:725
GLuint64EXT * result
Definition: glext.h:11304
DNS_PTR_DATAW Cname
Definition: windns.h:611
LPWSTR pName
Definition: windns.h:599

Referenced by NSP_LookupServiceNextW().

◆ NSP_GetHostNameHeapAllocW()

INT NSP_GetHostNameHeapAllocW ( _Out_ WCHAR **  hostname)

Definition at line 444 of file nsplookup.c.

445 {
446  WCHAR* name;
447  HANDLE hHeap = GetProcessHeap();
448  DWORD bufCharLen = MAX_COMPUTERNAME_LENGTH + 1;
449  DWORD bufByteLen = bufCharLen * sizeof(WCHAR);
450 
451  name = HeapAlloc(hHeap, 0, bufByteLen);
452 
453  if (!GetComputerNameExW(ComputerNameDnsHostname,
454  name,
455  &bufCharLen))
456  {
457  HeapFree(hHeap, 0, name);
459  return SOCKET_ERROR;
460  }
461 
462  *hostname = name;
463  return ERROR_SUCCESS;
464 }
#define SOCKET_ERROR
Definition: winsock.h:333
#define WSAEFAULT
Definition: winerror.h:1945
#define ERROR_SUCCESS
Definition: deptool.c:10
BOOL WINAPI GetComputerNameExW(COMPUTER_NAME_FORMAT NameType, LPWSTR lpBuffer, LPDWORD nSize)
Definition: compname.c:213
char * hostname
Definition: ftp.c:88
VOID WSAAPI WSASetLastError(IN INT iError)
Definition: dllmain.c:123
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned long DWORD
Definition: ntddk_ex.h:95
#define MAX_COMPUTERNAME_LENGTH
Definition: winbase.h:240
Definition: name.c:36
#define HeapFree(x, y, z)
Definition: compat.h:394
GLuint const GLchar * name
Definition: glext.h:6031

Referenced by NSP_LookupServiceNextW().

◆ NSP_GetServiceByNameHeapAllocW()

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

Definition at line 701 of file nsplookup.c.

704 {
705  BOOL Found = FALSE;
706  HANDLE ServicesFile;
707  CHAR ServiceDBData[BUFSIZ * sizeof(WCHAR)] = {0};
708  PCHAR ThisLine = 0, NextLine = 0, ServiceName = 0, PortNumberStr = 0,
709  ProtocolStr = 0, Comment = 0, EndValid;
710  PCHAR Aliases[WS2_INTERNAL_MAX_ALIAS] = {0};
711  PCHAR* AliasPtr;
712  UINT i = 0;
713  DWORD ReadSize = 0;
714  HANDLE hHeap;
715  PCHAR nameA = NULL;
716  PCHAR nameServiceA = NULL;
717  PCHAR nameProtoA = NULL;
719 
720  if (!data->hostnameW)
721  {
723  goto End;
724  }
725 
726  hHeap = GetProcessHeap();
727  nameA = StrW2AHeapAlloc(hHeap, data->hostnameW);
728 
729  /* nameA has the form <service-name>/<protocol>
730  we split these now */
731  nameProtoA = strchr(nameA, '/');
732  if (nameProtoA == NULL)
733  {
735  goto End;
736  }
737 
738  nameProtoA++;
739  i = (DWORD)(nameProtoA - nameA - 1);
740  nameServiceA = (PCHAR)HeapAlloc(hHeap, 0, i + 1);
741  StringCbCopyA(nameServiceA, i + 1, nameA);
742  nameServiceA[i] = '\0';
743 
744  ServicesFile = OpenNetworkDatabase(L"services");
745  if (ServicesFile == INVALID_HANDLE_VALUE)
746  {
747  return WSANO_RECOVERY;
748  }
749 
750  /* Scan the services file ...
751  *
752  * We will be share the buffer on the lines. If the line does not fit in
753  * the buffer, then moving it to the beginning of the buffer and read
754  * the remnants of line from file.
755  */
756 
757  /* Initial Read */
758  ReadFile(ServicesFile,
759  ServiceDBData,
760  sizeof( ServiceDBData ) - 1,
761  &ReadSize,
762  NULL);
763 
764  ThisLine = NextLine = ServiceDBData;
765  EndValid = ServiceDBData + ReadSize;
766  ServiceDBData[sizeof(ServiceDBData) - 1] = '\0';
767 
768  while (ReadSize)
769  {
770  for (; *NextLine != '\r' && *NextLine != '\n'; NextLine++)
771  {
772  if (NextLine == EndValid)
773  {
774  int LineLen = NextLine - ThisLine;
775 
776  if (ThisLine == ServiceDBData)
777  {
778  //WS_DbgPrint(MIN_TRACE,("Line too long"));
779  return WSANO_RECOVERY;
780  }
781 
782  memmove(ServiceDBData, ThisLine, LineLen);
783 
784  ReadFile(ServicesFile,
785  ServiceDBData + LineLen,
786  sizeof( ServiceDBData )-1 - LineLen,
787  &ReadSize,
788  NULL);
789 
790  EndValid = ServiceDBData + LineLen + ReadSize;
791  NextLine = ServiceDBData + LineLen;
792  ThisLine = ServiceDBData;
793 
794  if (!ReadSize) break;
795  }
796  }
797 
798  *NextLine = '\0';
799  Comment = strchr(ThisLine, '#');
800 
801  if (Comment)
802  *Comment = '\0'; /* Terminate at comment start */
803 
804  if (DecodeServEntFromString(ThisLine,
805  &ServiceName,
806  &PortNumberStr,
807  &ProtocolStr,
808  Aliases,
810  (strlen(nameProtoA) == 0 || strcmp(ProtocolStr, nameProtoA) == 0))
811  {
812  Found = (strcmp(ServiceName, nameServiceA) == 0 || strcmp(PortNumberStr, nameServiceA) == 0);
813  AliasPtr = Aliases;
814  while ((!Found) && (*AliasPtr != NULL))
815  {
816  Found = (strcmp(*AliasPtr, nameServiceA) == 0);
817  AliasPtr++;
818  }
819  if (Found)
820  break;
821  }
822  NextLine++;
823  ThisLine = NextLine;
824  }
825 
826  /* This we'll do no matter what */
827  CloseHandle(ServicesFile);
828 
829  if (!Found)
830  {
831  return WSANO_DATA;
832  }
833 
834  hostinfo->addr4 = 0;
835  hostinfo->servnameW = StrA2WHeapAlloc(hHeap, ServiceName);
836  hostinfo->servprotoW = StrA2WHeapAlloc(hHeap, ProtocolStr);
837  hostinfo->servaliasesA = StrAryCpyHeapAllocA(hHeap, (char**)&Aliases);
838  hostinfo->servport = atoi(PortNumberStr);
839 
840  res = NO_ERROR;
841 
842 End:
843  if (nameA != NULL)
844  HeapFree(hHeap, 0, nameA);
845 
846  if (nameServiceA != NULL)
847  HeapFree(hHeap, 0, nameServiceA);
848 
849  return res;
850 }
signed char * PCHAR
Definition: retypes.h:7
#define memmove(s1, s2, n)
Definition: mkisofs.h:881
#define CloseHandle
Definition: compat.h:398
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define WS2_INTERNAL_MAX_ALIAS
Definition: nsplookup.c:29
char CHAR
Definition: xmlstorage.h:175
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
#define BUFSIZ
Definition: nsplookup.c:26
char * StrW2AHeapAlloc(_In_opt_ HANDLE hHeap, _In_ WCHAR *wStr)
Definition: mswhelper.c:442
#define NO_ERROR
Definition: dderror.h:5
#define DWORD
Definition: nt_native.h:44
int32_t INT
Definition: typedefs.h:56
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
char ** StrAryCpyHeapAllocA(_In_opt_ HANDLE hHeap, _In_ char **aStrAry)
Definition: mswhelper.c:530
unsigned int BOOL
Definition: ntddk_ex.h:94
HANDLE WSAAPI OpenNetworkDatabase(_In_ LPCWSTR Name)
Definition: nsplookup.c:609
WCHAR * StrA2WHeapAlloc(_In_opt_ HANDLE hHeap, _In_ char *aStr)
Definition: mswhelper.c:399
smooth NULL
Definition: ftsmooth.c:416
STRSAFEAPI StringCbCopyA(STRSAFE_LPSTR pszDest, size_t cbDest, STRSAFE_LPCSTR pszSrc)
Definition: strsafe.h:161
return Found
Definition: dirsup.c:1270
#define PCHAR
Definition: match.c:90
static BOOL DecodeServEntFromString(IN PCHAR ServiceString, OUT PCHAR *ServiceName, OUT PCHAR *PortNumberStr, OUT PCHAR *ProtocolStr, IN PCHAR *Aliases, IN DWORD MaxAlias)
Definition: nsplookup.c:557
#define WSANO_RECOVERY
Definition: winerror.h:2002
LPTSTR ServiceName
Definition: ServiceMain.c:15
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define WSANO_DATA
Definition: winerror.h:2003
unsigned long DWORD
Definition: ntddk_ex.h:95
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
static const WCHAR L[]
Definition: oid.c:1250
unsigned int UINT
Definition: ndis.h:50
char * strchr(const char *String, int ch)
Definition: utclib.c:501
_Check_return_ int __cdecl atoi(_In_z_ const char *_Str)
GLuint res
Definition: glext.h:9613
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
BOOL WINAPI ReadFile(IN HANDLE hFile, IN LPVOID lpBuffer, IN DWORD nNumberOfBytesToRead, OUT LPDWORD lpNumberOfBytesRead OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:123
#define HeapFree(x, y, z)
Definition: compat.h:394
BOOLEAN NextLine
Definition: bootvid.c:28

Referenced by NSP_LookupServiceNextW().

◆ NSP_LookupServiceBeginW()

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

Definition at line 408 of file nsplookup.c.

412 {
413  HANDLE hHeap;
414 
415  if (data->CallID != 0)
416  return WSAEFAULT;
417 
418  data->CallID = CallID;
419 
420  if ((CallID == NSP_CALLID_HOSTBYNAME) ||
421  (CallID == NSP_CALLID_SERVICEBYNAME))
422  {
423  hHeap = GetProcessHeap();
424 
425  if (data->hostnameW != NULL)
426  HeapFree(hHeap, 0, data->hostnameW);
427 
428  if (hostnameA != NULL)
429  {
430  data->hostnameW = StrA2WHeapAlloc(hHeap, hostnameA);
431  }
432  else
433  {
434  data->hostnameW = StrCpyHeapAllocW(hHeap, hostnameW);
435  }
436  }
437 
438  WSASetLastError(0);
439 
440  return ERROR_SUCCESS;
441 }
#define WSAEFAULT
Definition: winerror.h:1945
WCHAR * StrCpyHeapAllocW(_In_opt_ HANDLE hHeap, _In_ WCHAR *wStr)
Definition: mswhelper.c:484
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NSP_CALLID_SERVICEBYNAME
Definition: nsplookup.c:23
WCHAR * StrA2WHeapAlloc(_In_opt_ HANDLE hHeap, _In_ char *aStr)
Definition: mswhelper.c:399
smooth NULL
Definition: ftsmooth.c:416
VOID WSAAPI WSASetLastError(IN INT iError)
Definition: dllmain.c:123
#define NSP_CALLID_HOSTBYNAME
Definition: nsplookup.c:22
#define GetProcessHeap()
Definition: compat.h:395
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
#define HeapFree(x, y, z)
Definition: compat.h:394

Referenced by mwsNSPLookupServiceBegin().

◆ NSP_LookupServiceNextW()

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

Definition at line 853 of file nsplookup.c.

857 {
858  MSW_BUFFER buf;
859  WSHOSTINFOINTERN hostinfo;
860  INT result;
861  HANDLE hHeap = GetProcessHeap();
862  WCHAR* ServiceInstanceNameW = NULL;
863  /* cleanup-vars */
864  CHAR* ServiceInstanceNameA = NULL;
865  CHAR* ServiceProtocolNameA = NULL;
866 
867  RtlZeroMemory(&hostinfo, sizeof(hostinfo));
868 
869  /* init and build result-buffer */
870  mswBufferInit(&buf, (BYTE*)lpRes, *lpResLen);
871  mswBufferIncUsed(&buf, sizeof(*lpRes));
872 
873  /* QueryDataSet-Size without "blob-data"-size! */
874  lpRes->dwSize = sizeof(*lpRes);
875  lpRes->dwNameSpace = NS_DNS;
876 
877  if ((data->CallID == NSP_CALLID_HOSTNAME) ||
878  (data->CallID == NSP_CALLID_HOSTBYNAME) ||
879  (data->CallID == NSP_CALLID_SERVICEBYNAME))
880  {
881  if (data->CallIDCounter >= 1)
882  {
883  result = WSAENOMORE;
884  goto End;
885  }
886  }
887  else
888  {
890  goto End;
891  }
892  data->CallIDCounter++;
893 
894  if (data->CallID == NSP_CALLID_HOSTNAME)
895  {
897 
898  if (result != ERROR_SUCCESS)
899  goto End;
900 
901  hostinfo.addr4 = 0;
902  }
903  else if (data->CallID == NSP_CALLID_HOSTBYNAME)
904  {
906  dwControlFlags,
907  &hostinfo);
908  if (result != ERROR_SUCCESS)
909  goto End;
910  }
911  else
912  {
915  dwControlFlags,
916  &hostinfo);
917  if (result != ERROR_SUCCESS)
918  goto End;
919  }
920 
921  if (((LUP_RETURN_BLOB & data->dwControlFlags) != 0) ||
922  ((LUP_RETURN_NAME & data->dwControlFlags) != 0))
923  {
924  if (data->CallID == NSP_CALLID_HOSTNAME || data->CallID == NSP_CALLID_HOSTBYNAME)
925  {
926  ServiceInstanceNameW = hostinfo.hostnameW;
927  ServiceInstanceNameA = StrW2AHeapAlloc(hHeap, ServiceInstanceNameW);
928  if (ServiceInstanceNameA == NULL)
929  {
930  result = WSAEFAULT;
931  goto End;
932 
933  }
934  }
935  if (data->CallID == NSP_CALLID_SERVICEBYNAME)
936  {
937  ServiceInstanceNameW = hostinfo.servnameW;
938  ServiceInstanceNameA = StrW2AHeapAlloc(hHeap, ServiceInstanceNameW);
939  if (ServiceInstanceNameA == NULL)
940  {
941  result = WSAEFAULT;
942  goto End;
943 
944  }
945  ServiceProtocolNameA = StrW2AHeapAlloc(hHeap, hostinfo.servprotoW);
946  if (ServiceProtocolNameA == NULL)
947  {
948  result = WSAEFAULT;
949  goto End;
950 
951  }
952  }
953  }
954 
955  if ((LUP_RETURN_ADDR & data->dwControlFlags) != 0)
956  {
957  if (!mswBufferAppendAddr_AddrInfoW(&buf, lpRes, hostinfo.addr4))
958  {
959  *lpResLen = buf.bytesUsed;
960  result = WSAEFAULT;
961  goto End;
962  }
963  }
964 
965  if ((LUP_RETURN_BLOB & data->dwControlFlags) != 0)
966  {
967  if (data->CallID == NSP_CALLID_HOSTBYNAME)
968  {
969  /* Write data for PBLOB (hostent) */
971  lpRes,
972  (LUP_RETURN_ALIASES & data->dwControlFlags) != 0 ? hostinfo.servaliasesA : NULL,
973  ServiceInstanceNameA,
974  hostinfo.addr4))
975  {
976  *lpResLen = buf.bytesUsed;
977  result = WSAEFAULT;
978  goto End;
979  }
980  }
981  else if (data->CallID == NSP_CALLID_SERVICEBYNAME)
982  {
983  /* Write data for PBLOB (servent) */
985  lpRes,
986  ServiceInstanceNameA,/* ServiceName */
987  (LUP_RETURN_ALIASES & data->dwControlFlags) != 0 ? hostinfo.servaliasesA : NULL,
988  ServiceProtocolNameA,
989  hostinfo.servport))
990  {
991  *lpResLen = buf.bytesUsed;
992  result = WSAEFAULT;
993  goto End;
994  }
995  }
996  else
997  {
999  goto End;
1000  }
1001  }
1002 
1003  if ((LUP_RETURN_NAME & data->dwControlFlags) != 0)
1004  {
1005  /* HostByName sets the ServiceInstanceName to a
1006  (UNICODE)copy of hostent.h_name */
1007  lpRes->lpszServiceInstanceName = (LPWSTR)mswBufferEndPtr(&buf);
1008  if (!mswBufferAppendStrW(&buf, ServiceInstanceNameW))
1009  {
1010  lpRes->lpszServiceInstanceName = NULL;
1011  *lpResLen = buf.bytesUsed;
1012  result = WSAEFAULT;
1013  goto End;
1014  }
1015  }
1016 
1017  *lpResLen = buf.bytesUsed;
1018 
1020 End:
1021  /* cleanup */
1022  if (ServiceInstanceNameA != NULL)
1023  HeapFree(hHeap, 0, ServiceInstanceNameA);
1024 
1025  if (ServiceProtocolNameA != NULL)
1026  HeapFree(hHeap, 0, ServiceProtocolNameA);
1027 
1028  if (hostinfo.hostnameW != NULL)
1029  HeapFree(hHeap, 0, hostinfo.hostnameW);
1030 
1031  if (hostinfo.servnameW != NULL)
1032  HeapFree(hHeap, 0, hostinfo.servnameW);
1033 
1034  if (hostinfo.servprotoW != NULL)
1035  HeapFree(hHeap, 0, hostinfo.servprotoW);
1036 
1037  return result;
1038 }
#define NSP_CALLID_HOSTNAME
Definition: nsplookup.c:21
#define WSAEFAULT
Definition: winerror.h:1945
BOOL mswBufferAppendStrW(_Inout_ PMSW_BUFFER mswBuf, _In_ WCHAR *str)
Definition: mswhelper.c:78
#define ERROR_SUCCESS
Definition: deptool.c:10
#define LUP_RETURN_NAME
Definition: winsock2.h:514
#define NSP_CALLID_SERVICEBYNAME
Definition: nsplookup.c:23
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
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
char CHAR
Definition: xmlstorage.h:175
void mswBufferInit(_Inout_ PMSW_BUFFER mswBuf, _In_ BYTE *buffer, _In_ DWORD bufferSize)
Definition: mswhelper.c:15
#define NS_DNS
Definition: nspapi.h:16
char * StrW2AHeapAlloc(_In_opt_ HANDLE hHeap, _In_ WCHAR *wStr)
Definition: mswhelper.c:442
int32_t INT
Definition: typedefs.h:56
WCHAR * servnameW
Definition: nsplookup.c:39
WCHAR * servprotoW
Definition: nsplookup.c:40
INT NSP_GetHostNameHeapAllocW(_Out_ WCHAR **hostname)
Definition: nsplookup.c:444
smooth NULL
Definition: ftsmooth.c:416
CHAR ** servaliasesA
Definition: nsplookup.c:41
INT NSP_GetServiceByNameHeapAllocW(_In_ PWSHANDLEINTERN data, _In_ DWORD dwControlFlags, _Out_ PWSHOSTINFOINTERN hostinfo)
Definition: nsplookup.c:701
#define NSP_CALLID_HOSTBYNAME
Definition: nsplookup.c:22
#define WSANO_RECOVERY
Definition: winerror.h:2002
#define GetProcessHeap()
Definition: compat.h:395
BYTE * mswBufferEndPtr(_Inout_ PMSW_BUFFER mswBuf)
Definition: mswhelper.c:51
__wchar_t WCHAR
Definition: xmlstorage.h:180
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
unsigned char BYTE
Definition: mem.h:68
#define LUP_RETURN_ADDR
Definition: winsock2.h:518
#define LUP_RETURN_BLOB
Definition: winsock2.h:519
INT NSP_GetHostByNameHeapAllocW(_In_ PWSHANDLEINTERN data, _In_ DWORD dwControlFlags, _Out_ PWSHOSTINFOINTERN hostinfo)
Definition: nsplookup.c:467
BOOL mswBufferIncUsed(_Inout_ PMSW_BUFFER mswBuf, _In_ DWORD count)
Definition: mswhelper.c:39
WCHAR * hostnameW
Definition: nsplookup.c:37
#define WSAENOMORE
Definition: winerror.h:1989
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
BOOL mswBufferAppendAddr_AddrInfoW(_Inout_ PMSW_BUFFER mswBuf, _Inout_ LPWSAQUERYSETW lpRes, _In_ DWORD ip4addr)
Definition: mswhelper.c:352
WCHAR * LPWSTR
Definition: xmlstorage.h:184
BOOL mswBufferAppendBlob_Hostent(_Inout_ PMSW_BUFFER mswBuf, _Inout_ LPWSAQUERYSETW lpRes, _In_ char **hostAliasesA, _In_ char *hostnameA, _In_ DWORD ip4addr)
Definition: mswhelper.c:227
GLuint64EXT * result
Definition: glext.h:11304
#define HeapFree(x, y, z)
Definition: compat.h:394
#define LUP_RETURN_ALIASES
Definition: winsock2.h:520

Referenced by mwsNSPLookupServiceNext().

◆ NSPStartup()

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

Definition at line 1046 of file nsplookup.c.

1048 {
1049  INT ret;
1050 
1051  if ((lpRout == NULL) ||
1052  (lpRout->cbSize != sizeof(NSP_ROUTINE)))
1053  {
1055  return ERROR_INVALID_PARAMETER;
1056  }
1057 
1058  mwsNSPInit();
1059 
1060  /* set own Provider GUID - maybe we need
1061  here to set the original mswsock-GUID?! */
1062 
1063  /* Win2k3 returns
1064  - Version 1.1
1065  - no NSPIoctl
1066  - sets cbSize to 44! */
1067  lpRout->dwMajorVersion = 1;
1068  lpRout->dwMinorVersion = 1;
1069  lpRout->cbSize = sizeof(*lpRout) - sizeof(lpRout->NSPIoctl);
1070  lpRout->NSPCleanup = &mwsNSPCleanUp;
1071  lpRout->NSPLookupServiceBegin = &mwsNSPLookupServiceBegin;
1072  lpRout->NSPLookupServiceNext = &mwsNSPLookupServiceNext;
1073  lpRout->NSPLookupServiceEnd = &mwsNSPLookupServiceEnd;
1074  lpRout->NSPSetService = &mwsNSPSetService;
1075  lpRout->NSPInstallServiceClass = &mwsNSPInstallServiceClass;
1076  lpRout->NSPRemoveServiceClass = &mwsNSPRemoveServiceClass;
1077  lpRout->NSPGetServiceClassInfo = &mwsNSPGetServiceClassInfo;
1078  lpRout->NSPIoctl = NULL;// &mwsNSPIoCtl;
1079 
1080  ret = NO_ERROR;
1081 
1082  return ret;
1083 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
#define NO_ERROR
Definition: dderror.h:5
int32_t INT
Definition: typedefs.h:56
INT WSAAPI mwsNSPGetServiceClassInfo(_In_ LPGUID lpProviderId, _In_ LPDWORD lpdwBufSize, _In_ LPWSASERVICECLASSINFOW lpServiceClassInfo)
Definition: nsplookup.c:393
smooth NULL
Definition: ftsmooth.c:416
INT WSAAPI mwsNSPInstallServiceClass(_In_ LPGUID lpProviderId, _In_ LPWSASERVICECLASSINFOW lpServiceClassInfo)
Definition: nsplookup.c:375
VOID WSAAPI WSASetLastError(IN INT iError)
Definition: dllmain.c:123
INT WSAAPI mwsNSPLookupServiceNext(_In_ HANDLE hLookup, _In_ DWORD dwControlFlags, _Inout_ LPDWORD lpdwBufferLength, LPWSAQUERYSETW lpqsResults)
Definition: nsplookup.c:270
INT mwsNSPInit(VOID)
Definition: nsplookup.c:141
int ret
INT WSAAPI mwsNSPSetService(_In_ LPGUID lpProviderId, _In_ LPWSASERVICECLASSINFOW lpServiceClassInfo, _In_ LPWSAQUERYSETW lpqsRegInfo, _In_ WSAESETSERVICEOP essOperation, _In_ DWORD dwControlFlags)
Definition: nsplookup.c:363
INT WSAAPI mwsNSPRemoveServiceClass(_In_ LPGUID lpProviderId, _In_ LPGUID lpServiceClassId)
Definition: nsplookup.c:384
INT WSAAPI mwsNSPLookupServiceBegin(_In_ LPGUID lpProviderId, _In_ LPWSAQUERYSETW lpqsRestrictions, _In_ LPWSASERVICECLASSINFOW lpServiceClassInfo, _In_ DWORD dwControlFlags, _Out_ LPHANDLE lphLookup)
Definition: nsplookup.c:148
INT WSAAPI mwsNSPCleanUp(_In_ LPGUID lpProviderId)
Definition: nsplookup.c:133
INT WSAAPI mwsNSPLookupServiceEnd(_In_ HANDLE hLookup)
Definition: nsplookup.c:340

◆ OpenNetworkDatabase()

HANDLE WSAAPI OpenNetworkDatabase ( _In_ LPCWSTR  Name)

Definition at line 609 of file nsplookup.c.

610 {
611  PWSTR ExpandedPath;
613  INT ErrorCode;
614  HKEY DatabaseKey;
615  DWORD RegType;
616  DWORD RegSize = 0;
617  size_t StringLength;
618  HANDLE ret;
619 
620  ExpandedPath = HeapAlloc(GetProcessHeap(), 0, MAX_PATH*sizeof(WCHAR));
621  if (!ExpandedPath)
622  return INVALID_HANDLE_VALUE;
623 
624  /* Open the database path key */
626  L"System\\CurrentControlSet\\Services\\Tcpip\\Parameters",
627  0,
628  KEY_READ,
629  &DatabaseKey);
630  if (ErrorCode == NO_ERROR)
631  {
632  /* Read the actual path */
633  ErrorCode = RegQueryValueEx(DatabaseKey,
634  L"DatabasePath",
635  NULL,
636  &RegType,
637  NULL,
638  &RegSize);
639 
640  DatabasePath = HeapAlloc(GetProcessHeap(), 0, RegSize);
641  if (!DatabasePath)
642  {
643  HeapFree(GetProcessHeap(), 0, ExpandedPath);
644  return INVALID_HANDLE_VALUE;
645  }
646 
647  /* Read the actual path */
648  ErrorCode = RegQueryValueEx(DatabaseKey,
649  L"DatabasePath",
650  NULL,
651  &RegType,
653  &RegSize);
654 
655  /* Close the key */
656  RegCloseKey(DatabaseKey);
657 
658  /* Expand the name */
660 
662  }
663  else
664  {
665  /* Use defalt path */
666  GetSystemDirectory(ExpandedPath, MAX_PATH);
667  StringCchLength(ExpandedPath, MAX_PATH, &StringLength);
668  if (ExpandedPath[StringLength - 1] != L'\\')
669  {
670  /* It isn't, so add it ourselves */
671  StringCchCat(ExpandedPath, MAX_PATH, L"\\");
672  }
673  StringCchCat(ExpandedPath, MAX_PATH, L"DRIVERS\\ETC\\");
674  }
675 
676  /* Make sure that the path is backslash-terminated */
677  StringCchLength(ExpandedPath, MAX_PATH, &StringLength);
678  if (ExpandedPath[StringLength - 1] != L'\\')
679  {
680  /* It isn't, so add it ourselves */
681  StringCchCat(ExpandedPath, MAX_PATH, L"\\");
682  }
683 
684  /* Add the database name */
685  StringCchCat(ExpandedPath, MAX_PATH, Name);
686 
687  /* Return a handle to the file */
688  ret = CreateFile(ExpandedPath,
691  NULL,
694  NULL);
695 
696  HeapFree(GetProcessHeap(), 0, ExpandedPath);
697  return ret;
698 }
#define RegQueryValueEx
Definition: winreg.h:524
#define StringCchLength
Definition: strsafe.h:829
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4436
#define KEY_READ
Definition: nt_native.h:1023
uint16_t * PWSTR
Definition: typedefs.h:54
#define ExpandEnvironmentStrings
Definition: winbase.h:3591
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
#define StringCchCat
Definition: strsafe.h:317
#define NO_ERROR
Definition: dderror.h:5
int32_t INT
Definition: typedefs.h:56
#define FILE_SHARE_READ
Definition: compat.h:125
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned char * LPBYTE
Definition: typedefs.h:52
#define FILE_READ_DATA
Definition: nt_native.h:628
smooth NULL
Definition: ftsmooth.c:416
#define OPEN_EXISTING
Definition: compat.h:426
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_PATH
Definition: compat.h:26
unsigned long DWORD
Definition: ntddk_ex.h:95
int ret
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
static const WCHAR L[]
Definition: oid.c:1250
#define GetSystemDirectory
Definition: winbase.h:3659
PWSTR DatabasePath
Definition: database.c:31
#define RegOpenKeyEx
Definition: winreg.h:520
IN OUT PVCB OUT PDIRENT OUT PBCB IN BOOLEAN CreateFile
Definition: fatprocs.h:904
#define HeapFree(x, y, z)
Definition: compat.h:394
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12

Referenced by NSP_GetServiceByNameHeapAllocW().

Variable Documentation

◆ guid_HOSTNAME

const GUID guid_HOSTNAME = SVCID_HOSTNAME
static

Definition at line 58 of file nsplookup.c.

Referenced by mwsNSPLookupServiceBegin().

◆ guid_INET_HOSTADDRBYINETSTRING

const GUID guid_INET_HOSTADDRBYINETSTRING = SVCID_INET_HOSTADDRBYINETSTRING
static

Definition at line 59 of file nsplookup.c.

Referenced by mwsNSPLookupServiceBegin().

◆ guid_INET_HOSTADDRBYNAME

const GUID guid_INET_HOSTADDRBYNAME = SVCID_INET_HOSTADDRBYNAME
static

Definition at line 60 of file nsplookup.c.

Referenced by mwsNSPLookupServiceBegin().

◆ guid_INET_SERVICEBYNAME

const GUID guid_INET_SERVICEBYNAME = SVCID_INET_SERVICEBYNAME
static

Definition at line 61 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 72 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 65 of file nsplookup.c.

Referenced by mwsNSPLookupServiceBegin().

◆ guid_NULL

const GUID guid_NULL = {0}
static

Definition at line 57 of file nsplookup.c.

Referenced by mwsNSPLookupServiceBegin().