Author: phater
Date: Fri Jun 2 21:01:47 2017
New Revision: 74753
URL:
http://svn.reactos.org/svn/reactos?rev=74753&view=rev
Log:
[MSWSOCK] Add wine debug messages on mswsock debug channel.
Better cleanup some failure paths.
Fix some error codes.
Add some error checks.
Add some comments.
Modified:
trunk/reactos/dll/win32/mswsock/CMakeLists.txt
trunk/reactos/dll/win32/mswsock/extensions.c
trunk/reactos/dll/win32/mswsock/nsplookup.c
Modified: trunk/reactos/dll/win32/mswsock/CMakeLists.txt
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/mswsock/CMakeLis…
==============================================================================
--- trunk/reactos/dll/win32/mswsock/CMakeLists.txt [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/mswsock/CMakeLists.txt [iso-8859-1] Fri Jun 2 21:01:47 2017
@@ -16,6 +16,7 @@
${CMAKE_CURRENT_BINARY_DIR}/mswsock.def)
set_module_type(mswsock win32dll UNICODE)
+target_link_libraries(mswsock wine)
add_importlibs(mswsock ws2_32 advapi32 dnsapi msvcrt kernel32 ntdll)
add_pch(mswsock precomp.h SOURCE)
add_cd_file(TARGET mswsock DESTINATION reactos/system32 FOR all)
Modified: trunk/reactos/dll/win32/mswsock/extensions.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/mswsock/extensio…
==============================================================================
--- trunk/reactos/dll/win32/mswsock/extensions.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/mswsock/extensions.c [iso-8859-1] Fri Jun 2 21:01:47 2017
@@ -11,6 +11,9 @@
#include <winsock2.h>
#include <mswsock.h>
+
+#include <wine/debug.h>
+WINE_DEFAULT_DEBUG_CHANNEL(mswsock);
LPFN_TRANSMITFILE pfnTransmitFile = NULL;
LPFN_GETACCEPTEXSOCKADDRS pfnGetAcceptExSockaddrs = NULL;
@@ -28,29 +31,37 @@
LPTRANSMIT_FILE_BUFFERS TransmitBuffers,
DWORD Flags)
{
- GUID TransmitFileGUID = WSAID_TRANSMITFILE;
+ GUID TransmitFileGUID = WSAID_TRANSMITFILE;
DWORD cbBytesReturned;
+ BOOL Ret;
- if (WSAIoctl(Socket,
- SIO_GET_EXTENSION_FUNCTION_POINTER,
- &TransmitFileGUID,
- sizeof(TransmitFileGUID),
- &pfnTransmitFile,
- sizeof(pfnTransmitFile),
- &cbBytesReturned,
- NULL,
- NULL) == SOCKET_ERROR)
+ TRACE("TransmitFile %p %p %ld %ld %p %p %lx\n", Socket, File,
NumberOfBytesToWrite, NumberOfBytesPerSend, Overlapped, TransmitBuffers, Flags);
+ if (!pfnTransmitFile && WSAIoctl(Socket,
+ SIO_GET_EXTENSION_FUNCTION_POINTER,
+ &TransmitFileGUID,
+ sizeof(TransmitFileGUID),
+ &pfnTransmitFile,
+ sizeof(pfnTransmitFile),
+ &cbBytesReturned,
+ NULL,
+ NULL) == SOCKET_ERROR)
{
+ ERR("TransmitFile WSAIoctl %lx\n", WSAGetLastError());
return FALSE;
}
- return pfnTransmitFile(Socket,
- File,
- NumberOfBytesToWrite,
- NumberOfBytesPerSend,
- Overlapped,
- TransmitBuffers,
- Flags);
+ Ret = pfnTransmitFile(Socket,
+ File,
+ NumberOfBytesToWrite,
+ NumberOfBytesPerSend,
+ Overlapped,
+ TransmitBuffers,
+ Flags);
+ if (!Ret)
+ {
+ ERR("TransmitFile %lx\n", WSAGetLastError());
+ }
+ return Ret;
}
/*
@@ -70,42 +81,51 @@
GUID AcceptExGUID = WSAID_ACCEPTEX;
GUID GetAcceptExSockaddrsGUID = WSAID_GETACCEPTEXSOCKADDRS;
DWORD cbBytesReturned;
+ BOOL Ret;
- if (WSAIoctl(ListenSocket,
- SIO_GET_EXTENSION_FUNCTION_POINTER,
- &AcceptExGUID,
- sizeof(AcceptExGUID),
- &pfnAcceptEx,
- sizeof(pfnAcceptEx),
- &cbBytesReturned,
- NULL,
- NULL) == SOCKET_ERROR)
+ TRACE("AcceptEx %p %p %p %ld %ld %ld %p %p\n", ListenSocket, AcceptSocket,
OutputBuffer, ReceiveDataLength, LocalAddressLength, RemoteAddressLength, BytesReceived,
Overlapped);
+ if (!pfnAcceptEx && WSAIoctl(ListenSocket,
+ SIO_GET_EXTENSION_FUNCTION_POINTER,
+ &AcceptExGUID,
+ sizeof(AcceptExGUID),
+ &pfnAcceptEx,
+ sizeof(pfnAcceptEx),
+ &cbBytesReturned,
+ NULL,
+ NULL) == SOCKET_ERROR)
{
+ ERR("AcceptEx WSAIoctl %lx\n", WSAGetLastError());
return FALSE;
}
- if (WSAIoctl(ListenSocket,
- SIO_GET_EXTENSION_FUNCTION_POINTER,
- &GetAcceptExSockaddrsGUID,
- sizeof(GetAcceptExSockaddrsGUID),
- &pfnGetAcceptExSockaddrs,
- sizeof(pfnGetAcceptExSockaddrs),
- &cbBytesReturned,
- NULL,
- NULL) == SOCKET_ERROR)
+ if (!pfnGetAcceptExSockaddrs && WSAIoctl(ListenSocket,
+ SIO_GET_EXTENSION_FUNCTION_POINTER,
+ &GetAcceptExSockaddrsGUID,
+ sizeof(GetAcceptExSockaddrsGUID),
+ &pfnGetAcceptExSockaddrs,
+ sizeof(pfnGetAcceptExSockaddrs),
+ &cbBytesReturned,
+ NULL,
+ NULL) == SOCKET_ERROR)
{
+ ERR("GetAcceptExSockaddrs WSAIoctl %lx\n", WSAGetLastError());
pfnAcceptEx = NULL;
return FALSE;
}
- return pfnAcceptEx(ListenSocket,
- AcceptSocket,
- OutputBuffer,
- ReceiveDataLength,
- LocalAddressLength,
- RemoteAddressLength,
- BytesReceived,
- Overlapped);
+ Ret = pfnAcceptEx(ListenSocket,
+ AcceptSocket,
+ OutputBuffer,
+ ReceiveDataLength,
+ LocalAddressLength,
+ RemoteAddressLength,
+ BytesReceived,
+ Overlapped);
+ if (!Ret)
+ {
+ ERR("AcceptEx %lx\n", WSAGetLastError());
+ }
+ return Ret;
}
@@ -123,16 +143,19 @@
LPSOCKADDR* RemoteSockaddr,
LPINT RemoteSockaddrLength)
{
- if (pfnGetAcceptExSockaddrs)
+ TRACE("AcceptEx %p %ld %ld %ld %p %p %p %p\n", OutputBuffer,
ReceiveDataLength, LocalAddressLength, RemoteAddressLength, LocalSockaddr,
LocalSockaddrLength, RemoteSockaddr, RemoteSockaddrLength);
+ if (!pfnGetAcceptExSockaddrs)
{
- pfnGetAcceptExSockaddrs(OutputBuffer,
- ReceiveDataLength,
- LocalAddressLength,
- RemoteAddressLength,
- LocalSockaddr,
- LocalSockaddrLength,
- RemoteSockaddr,
- RemoteSockaddrLength);
+ ERR("GetAcceptExSockaddrs is NULL\n");
+ return;
}
+ pfnGetAcceptExSockaddrs(OutputBuffer,
+ ReceiveDataLength,
+ LocalAddressLength,
+ RemoteAddressLength,
+ LocalSockaddr,
+ LocalSockaddrLength,
+ RemoteSockaddr,
+ RemoteSockaddrLength);
}
/* EOF */
Modified: trunk/reactos/dll/win32/mswsock/nsplookup.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/mswsock/nsplooku…
==============================================================================
--- trunk/reactos/dll/win32/mswsock/nsplookup.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/mswsock/nsplookup.c [iso-8859-1] Fri Jun 2 21:01:47 2017
@@ -14,8 +14,8 @@
#include "mswhelper.h"
-#define NDEBUG
-#include <debug.h>
+#include <wine/debug.h>
+WINE_DEFAULT_DEBUG_CHANNEL(mswsock);
#define NSP_CALLID_DNS 0x0001
#define NSP_CALLID_HOSTNAME 0x0002
@@ -154,17 +154,21 @@
PWSHANDLEINTERN pLook;
int wsaErr;
+ TRACE("mwsNSPLookupServiceBegin %p %p %p %lx %p\n", lpProviderId,
lpqsRestrictions, lpServiceClassInfo, dwControlFlags, lphLookup);
if (IsEqualGUID(lpProviderId, &guid_mswsock_TcpIp))
{
//OK
+ TRACE("TCPIP query\n");
}
else if (IsEqualGUID(lpProviderId, &guid_mswsock_NLA))
{
+ ERR("NLA queries are not supported yet\n");
WSASetLastError(WSASERVICE_NOT_FOUND);
return SOCKET_ERROR;
}
else
{
+ ERR("Unsupported GUID\n");
return ERROR_CALL_NOT_IMPLEMENTED;
}
@@ -172,6 +176,7 @@
pLook = HeapAlloc(GetProcessHeap(), 0, sizeof(WSHANDLEINTERN));
if (!pLook)
{
+ ERR("Error allocating %d for handle\n", sizeof(WSHANDLEINTERN));
WSASetLastError(WSAEFAULT);
return SOCKET_ERROR;
}
@@ -224,10 +229,12 @@
wsaErr = ERROR_CALL_NOT_IMPLEMENTED;
if (IsEqualGUID(lpqsRestrictions->lpServiceClassId, &guid_NULL))
{
+ ERR("NULL GUID service class is not implemented yet\n");
wsaErr = ERROR_CALL_NOT_IMPLEMENTED;
}
else if (IsEqualGUID(lpqsRestrictions->lpServiceClassId, &guid_HOSTNAME))
{
+ TRACE("HOSTNAME GUID\n");
wsaErr = NSP_LookupServiceBeginW(pLook,
NULL,
NULL,
@@ -236,22 +243,25 @@
else if (IsEqualGUID(lpqsRestrictions->lpServiceClassId,
&guid_INET_HOSTADDRBYNAME))
{
- wsaErr = NSP_LookupServiceBeginW(pLook,
- NULL,
- lpqsRestrictions->lpszServiceInstanceName,
- NSP_CALLID_HOSTBYNAME);
+ TRACE("INET_HOSTADDRBYNAME GUID\n");
+ wsaErr = NSP_LookupServiceBeginW(pLook,
+ NULL,
+ lpqsRestrictions->lpszServiceInstanceName,
+ NSP_CALLID_HOSTBYNAME);
}
else if (IsEqualGUID(lpqsRestrictions->lpServiceClassId,
&guid_INET_SERVICEBYNAME))
{
- wsaErr = NSP_LookupServiceBeginW(pLook,
- NULL,
- lpqsRestrictions->lpszServiceInstanceName,
- NSP_CALLID_SERVICEBYNAME);
+ TRACE("INET_SERVICEBYNAME\n");
+ wsaErr = NSP_LookupServiceBeginW(pLook,
+ NULL,
+ lpqsRestrictions->lpszServiceInstanceName,
+ NSP_CALLID_SERVICEBYNAME);
}
else if (IsEqualGUID(lpqsRestrictions->lpServiceClassId,
&guid_INET_HOSTADDRBYINETSTRING))
{
+ ERR("INET_HOSTADDRBYINETSTRING GUID service class is not implemented
yet\n");
wsaErr = ERROR_CALL_NOT_IMPLEMENTED;
}
@@ -259,6 +269,7 @@
if (wsaErr != NO_ERROR)
{
+ ERR("mwsNSPLookupServiceBegin wsaErr = %d\n", wsaErr);
WSASetLastError(wsaErr);
return SOCKET_ERROR;
}
@@ -276,6 +287,7 @@
PWSHANDLEINTERN pLook = hLookup;
int wsaErr = 0;
+ TRACE("mwsNSPLookupServiceNext %p %lx %p %p\n", pLook, dwControlFlags,
lpdwBufferLength, lpqsResults);
#ifdef NSP_REDIRECT
INT res = pLook->rdrproc.NSPLookupServiceNext(pLook->rdrLookup,
@@ -313,6 +325,7 @@
End:
if (wsaErr != 0)
{
+ ERR("mwsNSPLookupServiceNext wsaErr = %d\n", wsaErr);
WSASetLastError(wsaErr);
return SOCKET_ERROR;
}
@@ -331,7 +344,8 @@
_In_opt_ LPWSACOMPLETION lpCompletion,
_In_ LPWSATHREADID lpThreadId)
{
- WSASetLastError(ERROR_CALL_NOT_IMPLEMENTED);
+ ERR("mwsNSPIoCtl not implemented %p %lx %p %ld %p %ld %p %p %p\n", hLookup,
dwControlCode, lpvInBuffer, cbInBuffer, lpvOutBuffer, cbOutBuffer, lpcbBytesReturned,
lpCompletion, lpThreadId);
+ WSASetLastError(WSAEOPNOTSUPP);
return ERROR_CALL_NOT_IMPLEMENTED;
}
@@ -339,14 +353,11 @@
WSAAPI
mwsNSPLookupServiceEnd(_In_ HANDLE hLookup)
{
- PWSHANDLEINTERN pLook;
- HANDLE hHeap;
- INT res;
-
- res = NO_ERROR;
- pLook = (PWSHANDLEINTERN)hLookup;
- hHeap = GetProcessHeap();
-
+ PWSHANDLEINTERN pLook = (PWSHANDLEINTERN)hLookup;
+ HANDLE hHeap = GetProcessHeap();
+ INT res = NO_ERROR;
+
+ TRACE("mwsNSPLookupServiceEnd %p\n", pLook);
#ifdef NSP_REDIRECT
res = pLook->rdrproc.NSPLookupServiceEnd(pLook->rdrLookup);
#endif
@@ -366,7 +377,8 @@
_In_ WSAESETSERVICEOP essOperation,
_In_ DWORD dwControlFlags)
{
- WSASetLastError(ERROR_CALL_NOT_IMPLEMENTED);
+ ERR("mwsNSPSetService not implemented %p %p %p %d %lx %ld %p %p %p\n",
lpProviderId, lpServiceClassInfo, lpqsRegInfo, essOperation, dwControlFlags);
+ WSASetLastError(WSAEOPNOTSUPP);
return ERROR_CALL_NOT_IMPLEMENTED;
}
@@ -375,7 +387,8 @@
mwsNSPInstallServiceClass(_In_ LPGUID lpProviderId,
_In_ LPWSASERVICECLASSINFOW lpServiceClassInfo)
{
- WSASetLastError(ERROR_CALL_NOT_IMPLEMENTED);
+ ERR("mwsNSPInstallServiceClass not implemented %p %p\n", lpProviderId,
lpServiceClassInfo);
+ WSASetLastError(WSAEOPNOTSUPP);
return ERROR_CALL_NOT_IMPLEMENTED;
}
@@ -384,7 +397,8 @@
mwsNSPRemoveServiceClass(_In_ LPGUID lpProviderId,
_In_ LPGUID lpServiceClassId)
{
- WSASetLastError(ERROR_CALL_NOT_IMPLEMENTED);
+ ERR("mwsNSPRemoveServiceClass not implemented %p %p\n", lpProviderId,
lpServiceClassId);
+ WSASetLastError(WSAEOPNOTSUPP);
return ERROR_CALL_NOT_IMPLEMENTED;
}
@@ -394,7 +408,8 @@
_In_ LPDWORD lpdwBufSize,
_In_ LPWSASERVICECLASSINFOW lpServiceClassInfo)
{
- WSASetLastError(ERROR_CALL_NOT_IMPLEMENTED);
+ ERR("mwsNSPGetServiceClassInfo not implemented %p %p %p\n", lpProviderId,
lpdwBufSize, lpServiceClassInfo);
+ WSASetLastError(WSAEOPNOTSUPP);
return ERROR_CALL_NOT_IMPLEMENTED;
}
@@ -412,6 +427,7 @@
{
HANDLE hHeap;
+ TRACE("NSP_LookupServiceBeginW %p %p %p %lx\n", data, hostnameA, hostnameW,
CallID);
if (data->CallID != 0)
return WSAEFAULT;
@@ -434,8 +450,12 @@
data->hostnameW = StrCpyHeapAllocW(hHeap, hostnameW);
}
}
-
- WSASetLastError(0);
+ else
+ {
+ ERR("NSP_LookupServiceBeginW unsupported CallID\n");
+ WSASetLastError(ERROR_CALL_NOT_IMPLEMENTED);
+ return ERROR_CALL_NOT_IMPLEMENTED;
+ }
return ERROR_SUCCESS;
}
@@ -445,15 +465,23 @@
{
WCHAR* name;
HANDLE hHeap = GetProcessHeap();
- DWORD bufCharLen = MAX_COMPUTERNAME_LENGTH + 1;
- DWORD bufByteLen = bufCharLen * sizeof(WCHAR);
-
- name = HeapAlloc(hHeap, 0, bufByteLen);
-
+ DWORD bufCharLen = 0;
+
+ TRACE("NSP_GetHostNameHeapAllocW %p\n", hostname);
+ /* FIXME Use DnsGetHostName_W when available */
+ GetComputerNameExW(ComputerNameDnsHostname, NULL, &bufCharLen);
+ if (!bufCharLen)
+ {
+ ERR("NSP_GetHostNameHeapAllocW zero size for computername
returned\n");
+ WSASetLastError(WSAEFAULT);
+ return SOCKET_ERROR;
+ }
+ name = HeapAlloc(hHeap, 0, bufCharLen*sizeof(WCHAR));
if (!GetComputerNameExW(ComputerNameDnsHostname,
name,
&bufCharLen))
{
+ ERR("NSP_GetHostNameHeapAllocW error obtaining computername %lx\n",
GetLastError());
HeapFree(hHeap, 0, name);
WSASetLastError(WSAEFAULT);
return SOCKET_ERROR;
@@ -478,10 +506,11 @@
PWCHAR Aliases[WS2_INTERNAL_MAX_ALIAS] = { 0 };
int AliasIndex = 0;
+ TRACE("NSP_GetHostByNameHeapAllocW %p %lx %p\n", data, dwControlFlags,
hostinfo);
/* needed to be cleaned up if != NULL */
dp = NULL;
- if (data->hostnameW == NULL)
+ if (!data->hostnameW)
{
result = ERROR_INVALID_PARAMETER;
goto cleanup;
@@ -489,6 +518,7 @@
if ((data->dwControlFlags & LUP_DEEP) == 0)
{
+ TRACE("NSP_GetHostByNameHeapAllocW LUP_DEEP is not specified. Disabling
recursion\n");
dwQueryFlags |= DNS_QUERY_NO_RECURSION;
}
@@ -502,6 +532,7 @@
NULL);
if (dns_status == ERROR_INVALID_NAME)
{
+ ERR("NSP_GetHostByNameHeapAllocW invalid name\n");
WSASetLastError(WSAEFAULT);
result = ERROR_INVALID_PARAMETER;
goto cleanup;
@@ -509,6 +540,7 @@
if ((dns_status != 0) || (dp == NULL))
{
+ ERR("NSP_GetHostByNameHeapAllocW not found %lx %p\n", dns_status, dp);
result = WSAHOST_NOT_FOUND;
goto cleanup;
}
@@ -520,6 +552,7 @@
{
if (curr->wType == DNS_TYPE_CNAME)
{
+ TRACE("NSP_GetHostByNameHeapAllocW found alias %ws\n",
curr->Data.Cname.pNameHost);
Aliases[AliasIndex++] = curr->Data.Cname.pNameHost;
}
curr = curr->pNext;
@@ -527,6 +560,7 @@
if (curr->wType != DNS_TYPE_A)
{
+ ERR("NSP_GetHostByNameHeapAllocW last record is not of type A %d\n",
curr->wType);
result = WSASERVICE_NOT_FOUND;
goto cleanup;
}
@@ -615,8 +649,9 @@
DWORD RegType;
DWORD RegSize = 0;
size_t StringLength;
- HANDLE ret;
-
+ HANDLE Handle;
+
+ TRACE("OpenNetworkDatabase %p\n", Name);
ExpandedPath = HeapAlloc(GetProcessHeap(), 0, MAX_PATH*sizeof(WCHAR));
if (!ExpandedPath)
return INVALID_HANDLE_VALUE;
@@ -629,6 +664,7 @@
&DatabaseKey);
if (ErrorCode == NO_ERROR)
{
+ TRACE("OpenNetworkDatabase registry key for network database
exist\n");
/* Read the actual path */
ErrorCode = RegQueryValueEx(DatabaseKey,
L"DatabasePath",
@@ -637,9 +673,18 @@
NULL,
&RegSize);
+ if (!RegSize)
+ {
+ ERR("OpenNetworkDatabase RegQueryValueEx failed to return size for
DatabasePath %lx\n", ErrorCode);
+ RegCloseKey(DatabaseKey);
+ HeapFree(GetProcessHeap(), 0, ExpandedPath);
+ return INVALID_HANDLE_VALUE;
+ }
DatabasePath = HeapAlloc(GetProcessHeap(), 0, RegSize);
if (!DatabasePath)
{
+ ERR("OpenNetworkDatabase could not allocate %d for DatabasePath\n",
RegSize);
+ RegCloseKey(DatabaseKey);
HeapFree(GetProcessHeap(), 0, ExpandedPath);
return INVALID_HANDLE_VALUE;
}
@@ -655,6 +700,14 @@
/* Close the key */
RegCloseKey(DatabaseKey);
+ if (ErrorCode)
+ {
+ ERR("OpenNetworkDatabase RegQueryValueEx failed to return value for
DatabasePath %lx\n", ErrorCode);
+ HeapFree(GetProcessHeap(), 0, DatabasePath);
+ HeapFree(GetProcessHeap(), 0, ExpandedPath);
+ return INVALID_HANDLE_VALUE;
+ }
+
/* Expand the name */
ExpandEnvironmentStrings(DatabasePath, ExpandedPath, MAX_PATH);
@@ -662,6 +715,7 @@
}
else
{
+ TRACE("OpenNetworkDatabase registry key for network database doesn't
exist\n");
/* Use defalt path */
GetSystemDirectory(ExpandedPath, MAX_PATH);
StringCchLength(ExpandedPath, MAX_PATH, &StringLength);
@@ -685,16 +739,16 @@
StringCchCat(ExpandedPath, MAX_PATH, Name);
/* Return a handle to the file */
- ret = CreateFile(ExpandedPath,
- FILE_READ_DATA,
- FILE_SHARE_READ,
- NULL,
- OPEN_EXISTING,
- FILE_ATTRIBUTE_NORMAL,
- NULL);
+ Handle = CreateFile(ExpandedPath,
+ FILE_READ_DATA,
+ FILE_SHARE_READ,
+ NULL,
+ OPEN_EXISTING,
+ FILE_ATTRIBUTE_NORMAL,
+ NULL);
HeapFree(GetProcessHeap(), 0, ExpandedPath);
- return ret;
+ return Handle;
}
INT
@@ -704,10 +758,10 @@
{
BOOL Found = FALSE;
HANDLE ServicesFile;
- CHAR ServiceDBData[BUFSIZ * sizeof(WCHAR)] = {0};
+ CHAR ServiceDBData[BUFSIZ * sizeof(WCHAR)] = { 0 };
PCHAR ThisLine = 0, NextLine = 0, ServiceName = 0, PortNumberStr = 0,
ProtocolStr = 0, Comment = 0, EndValid;
- PCHAR Aliases[WS2_INTERNAL_MAX_ALIAS] = {0};
+ PCHAR Aliases[WS2_INTERNAL_MAX_ALIAS] = { 0 };
PCHAR* AliasPtr;
UINT i = 0;
DWORD ReadSize = 0;
@@ -717,8 +771,10 @@
PCHAR nameProtoA = NULL;
INT res = WSANO_RECOVERY;
+ TRACE("NSP_GetServiceByNameHeapAllocW %p %lx %p\n", data, dwControlFlags,
hostinfo);
if (!data->hostnameW)
{
+ ERR("NSP_GetServiceByNameHeapAllocW service name not provided\n");
res = WSANO_RECOVERY;
goto End;
}
@@ -731,6 +787,7 @@
nameProtoA = strchr(nameA, '/');
if (nameProtoA == NULL)
{
+ ERR("NSP_GetServiceByNameHeapAllocW invalid service name %s\n",
nameA);
res = WSANO_RECOVERY;
goto End;
}
@@ -744,6 +801,7 @@
ServicesFile = OpenNetworkDatabase(L"services");
if (ServicesFile == INVALID_HANDLE_VALUE)
{
+ ERR("NSP_GetServiceByNameHeapAllocW unable to open services file\n");
return WSANO_RECOVERY;
}
@@ -755,11 +813,16 @@
*/
/* Initial Read */
- ReadFile(ServicesFile,
- ServiceDBData,
- sizeof( ServiceDBData ) - 1,
- &ReadSize,
- NULL);
+ if (!ReadFile(ServicesFile,
+ ServiceDBData,
+ sizeof( ServiceDBData ) - 1,
+ &ReadSize,
+ NULL))
+ {
+ ERR("NSP_GetServiceByNameHeapAllocW can't read services file
%lx\n", GetLastError());
+ CloseHandle(ServicesFile);
+ return WSANO_RECOVERY;
+ }
ThisLine = NextLine = ServiceDBData;
EndValid = ServiceDBData + ReadSize;
@@ -775,17 +838,21 @@
if (ThisLine == ServiceDBData)
{
- //WS_DbgPrint(MIN_TRACE,("Line too long"));
+ ERR("NSP_GetServiceByNameHeapAllocW line too long\n");
+ CloseHandle(ServicesFile);
return WSANO_RECOVERY;
}
memmove(ServiceDBData, ThisLine, LineLen);
- ReadFile(ServicesFile,
- ServiceDBData + LineLen,
- sizeof( ServiceDBData )-1 - LineLen,
- &ReadSize,
- NULL);
+ if (!ReadFile(ServicesFile,
+ ServiceDBData + LineLen,
+ sizeof( ServiceDBData )-1 - LineLen,
+ &ReadSize,
+ NULL))
+ {
+ break;
+ }
EndValid = ServiceDBData + LineLen + ReadSize;
NextLine = ServiceDBData + LineLen;
@@ -828,6 +895,7 @@
if (!Found)
{
+ ERR("NSP_GetServiceByNameHeapAllocW service not found\n");
return WSANO_DATA;
}
@@ -840,10 +908,10 @@
res = NO_ERROR;
End:
- if (nameA != NULL)
+ if (nameA)
HeapFree(hHeap, 0, nameA);
- if (nameServiceA != NULL)
+ if (nameServiceA)
HeapFree(hHeap, 0, nameServiceA);
return res;
@@ -864,6 +932,9 @@
CHAR* ServiceInstanceNameA = NULL;
CHAR* ServiceProtocolNameA = NULL;
+ TRACE("NSP_LookupServiceNextW %p %lx %p %p\n", data, dwControlFlags, lpRes,
lpResLen);
+ if (!data || (dwControlFlags & (~(DWORD)LUP_FLUSHPREVIOUS)) != 0 || !lpRes ||
!lpResLen || *lpResLen == 0)
+ return WSAEINVAL;
RtlZeroMemory(&hostinfo, sizeof(hostinfo));
/* init and build result-buffer */
@@ -878,15 +949,18 @@
(data->CallID == NSP_CALLID_HOSTBYNAME) ||
(data->CallID == NSP_CALLID_SERVICEBYNAME))
{
+ /* FIXME remember what was returned and continue from there */
if (data->CallIDCounter >= 1)
{
- result = WSAENOMORE;
+ ERR("NSP_LookupServiceNextW LUP_FLUSHPREVIOUS and more than one call not
supported yet\n", data, dwControlFlags, lpRes, lpResLen);
+ result = WSA_E_NO_MORE;
goto End;
}
}
else
{
- result = WSANO_RECOVERY;
+ ERR("NSP_LookupServiceNextW unsupported CallID %lx\n",
data->CallID);
+ result = WSAEOPNOTSUPP;
goto End;
}
data->CallIDCounter++;
@@ -910,7 +984,7 @@
}
else
{
- ASSERT(data->CallID == NSP_CALLID_SERVICEBYNAME);
+ //ASSERT(data->CallID == NSP_CALLID_SERVICEBYNAME);
result = NSP_GetServiceByNameHeapAllocW(data,
dwControlFlags,
&hostinfo);
@@ -925,29 +999,29 @@
{
ServiceInstanceNameW = hostinfo.hostnameW;
ServiceInstanceNameA = StrW2AHeapAlloc(hHeap, ServiceInstanceNameW);
- if (ServiceInstanceNameA == NULL)
+ if (!ServiceInstanceNameA)
{
- result = WSAEFAULT;
+ ERR("NSP_LookupServiceNextW not enough memory\n");
+ result = WSA_NOT_ENOUGH_MEMORY;
goto End;
-
}
}
if (data->CallID == NSP_CALLID_SERVICEBYNAME)
{
ServiceInstanceNameW = hostinfo.servnameW;
ServiceInstanceNameA = StrW2AHeapAlloc(hHeap, ServiceInstanceNameW);
- if (ServiceInstanceNameA == NULL)
+ if (!ServiceInstanceNameA)
{
- result = WSAEFAULT;
+ ERR("NSP_LookupServiceNextW not enough memory\n");
+ result = WSA_NOT_ENOUGH_MEMORY;
goto End;
-
}
ServiceProtocolNameA = StrW2AHeapAlloc(hHeap, hostinfo.servprotoW);
- if (ServiceProtocolNameA == NULL)
+ if (!ServiceProtocolNameA)
{
- result = WSAEFAULT;
+ ERR("NSP_LookupServiceNextW not enough memory\n");
+ result = WSA_NOT_ENOUGH_MEMORY;
goto End;
-
}
}
}
@@ -956,6 +1030,7 @@
{
if (!mswBufferAppendAddr_AddrInfoW(&buf, lpRes, hostinfo.addr4))
{
+ ERR("NSP_LookupServiceNextW provided buffer is too small\n");
*lpResLen = buf.bytesUsed;
result = WSAEFAULT;
goto End;
@@ -973,6 +1048,7 @@
ServiceInstanceNameA,
hostinfo.addr4))
{
+ ERR("NSP_LookupServiceNextW provided buffer is too small\n");
*lpResLen = buf.bytesUsed;
result = WSAEFAULT;
goto End;
@@ -988,6 +1064,7 @@
ServiceProtocolNameA,
hostinfo.servport))
{
+ ERR("NSP_LookupServiceNextW provided buffer is too small\n");
*lpResLen = buf.bytesUsed;
result = WSAEFAULT;
goto End;
@@ -995,7 +1072,8 @@
}
else
{
- result = WSANO_RECOVERY;
+ ERR("NSP_LookupServiceNextW LUP_RETURN_BLOB is supported only for
NSP_CALLID_HOSTBYNAME and NSP_CALLID_SERVICEBYNAME\n");
+ result = WSAEINVAL;
goto End;
}
}
@@ -1007,6 +1085,7 @@
lpRes->lpszServiceInstanceName = (LPWSTR)mswBufferEndPtr(&buf);
if (!mswBufferAppendStrW(&buf, ServiceInstanceNameW))
{
+ ERR("NSP_LookupServiceNextW provided buffer is too small\n");
lpRes->lpszServiceInstanceName = NULL;
*lpResLen = buf.bytesUsed;
result = WSAEFAULT;
@@ -1034,6 +1113,7 @@
if (hostinfo.servprotoW != NULL)
HeapFree(hHeap, 0, hostinfo.servprotoW);
+ TRACE("NSP_LookupServiceNextW returns %d needed bytes %ld\n", result,
buf.bytesUsed);
return result;
}
@@ -1048,10 +1128,11 @@
{
INT ret;
- if ((lpRout == NULL) ||
- (lpRout->cbSize != sizeof(NSP_ROUTINE)))
- {
- WSASetLastError(ERROR_INVALID_PARAMETER);
+ TRACE("NSPStartup %p %p\n", lpProviderId, lpRout);
+ if (!lpRout || (lpRout->cbSize != sizeof(NSP_ROUTINE)))
+ {
+ ERR("NSPStartup invalid parameter\n");
+ WSASetLastError(WSAEINVAL);
return ERROR_INVALID_PARAMETER;
}