Author: akhaldi
Date: Tue Sep 20 16:51:28 2016
New Revision: 72750
URL:
http://svn.reactos.org/svn/reactos?rev=72750&view=rev
Log:
[WS2_32] The current ws2_32 served us well, but it's time for ws2_32_new to shine. It
took slightly more than 7 years since Ged brought-in Alex' impressive work on this
module, and thanks to the great follow-up work by Peter Hater, Andreas Maier, Thomas Faber
and everyone else involved in the effort, we now have a chance to retire ws2_32 in favor
of ws2_32_new. The test results speak for the excellent achievements, and this serves as a
platform to continue inspecting and fixing the remaining test failures. Thank you all for
a job well done! Please see CORE-10440 for a summary of the changes performed in this
commit.
Added:
trunk/reactos/dll/win32/ws2_32/
- copied from r72749, trunk/reactos/dll/win32/ws2_32_new/
Removed:
trunk/reactos/dll/win32/ws2_32_new/
Modified:
trunk/reactos/dll/win32/CMakeLists.txt
trunk/reactos/dll/win32/ws2_32/CMakeLists.txt
trunk/reactos/dll/win32/ws2_32/inc/ws2_32p.h
trunk/reactos/dll/win32/ws2_32/src/addrconv.c
trunk/reactos/dll/win32/ws2_32/src/addrinfo.c
trunk/reactos/dll/win32/ws2_32/src/dcatalog.c
trunk/reactos/dll/win32/ws2_32/src/dcatitem.c
trunk/reactos/dll/win32/ws2_32/src/dprovide.c
trunk/reactos/dll/win32/ws2_32/src/enumprot.c
trunk/reactos/dll/win32/ws2_32/src/getproto.c
trunk/reactos/dll/win32/ws2_32/src/getxbyxx.c
trunk/reactos/dll/win32/ws2_32/src/nscatalo.c
trunk/reactos/dll/win32/ws2_32/src/nscatent.c
trunk/reactos/dll/win32/ws2_32/src/nsquery.c
trunk/reactos/dll/win32/ws2_32/src/rnr.c
trunk/reactos/dll/win32/ws2_32/src/send.c
trunk/reactos/dll/win32/ws2_32/src/sockctrl.c
trunk/reactos/dll/win32/ws2_32/src/socklife.c
trunk/reactos/dll/win32/ws2_32/src/startup.c
Modified: trunk/reactos/dll/win32/CMakeLists.txt
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/CMakeLists.txt?r…
==============================================================================
--- trunk/reactos/dll/win32/CMakeLists.txt [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/CMakeLists.txt [iso-8859-1] Tue Sep 20 16:51:28 2016
@@ -247,7 +247,6 @@
add_subdirectory(wmiutils)
add_subdirectory(wmvcore)
add_subdirectory(ws2_32)
-add_subdirectory(ws2_32_new)
add_subdirectory(ws2help)
add_subdirectory(wshirda)
add_subdirectory(wshom.ocx)
Modified: trunk/reactos/dll/win32/ws2_32/CMakeLists.txt
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/ws2_32/CMakeList…
==============================================================================
--- trunk/reactos/dll/win32/ws2_32/CMakeLists.txt [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/ws2_32/CMakeLists.txt [iso-8859-1] Tue Sep 20 16:51:28 2016
@@ -1,6 +1,6 @@
add_definitions(-DLE)
-spec2def(ws2_32_new.dll ws2_32.spec)
+spec2def(ws2_32.dll ws2_32.spec ADD_IMPORTLIB)
include_directories(
inc
@@ -45,13 +45,13 @@
src/wsautil.c
inc/ws2_32.h)
-add_library(ws2_32_new SHARED
+add_library(ws2_32 SHARED
${SOURCE}
ws2_32.rc
- ${CMAKE_CURRENT_BINARY_DIR}/ws2_32_new.def)
+ ${CMAKE_CURRENT_BINARY_DIR}/ws2_32.def)
-set_module_type(ws2_32_new win32dll)
-target_link_libraries(ws2_32_new ${PSEH_LIB})
-add_importlibs(ws2_32_new user32 advapi32 ws2help msvcrt kernel32 ntdll)
-add_pch(ws2_32_new inc/ws2_32.h SOURCE)
-add_cd_file(TARGET ws2_32_new DESTINATION reactos/system32 FOR all)
+set_module_type(ws2_32 win32dll)
+target_link_libraries(ws2_32 ${PSEH_LIB})
+add_importlibs(ws2_32 user32 advapi32 ws2help msvcrt kernel32 ntdll)
+add_pch(ws2_32 inc/ws2_32.h SOURCE)
+add_cd_file(TARGET ws2_32 DESTINATION reactos/system32 FOR all)
Modified: trunk/reactos/dll/win32/ws2_32/inc/ws2_32p.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/ws2_32/inc/ws2_3…
==============================================================================
--- trunk/reactos/dll/win32/ws2_32/inc/ws2_32p.h [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/ws2_32/inc/ws2_32p.h [iso-8859-1] Tue Sep 20 16:51:28 2016
@@ -79,6 +79,7 @@
LONG RefCount;
WSPPROC_TABLE Service;
HINSTANCE DllHandle;
+ WSPUPCALLTABLE UpcallTable;
} TPROVIDER, *PTPROVIDER;
typedef struct _TCATALOG_ENTRY
@@ -210,6 +211,17 @@
PNSCATALOG Catalog;
} ENUM_CONTEXT, *PENUM_CONTEXT;
+typedef struct _NSPROVIDER_ENUM_CONTEXT
+{
+ LPINT Protocols;
+ LPVOID ProtocolBuffer;
+ DWORD BufferLength;
+ DWORD BufferUsed;
+ DWORD Count;
+ BOOLEAN Unicode;
+ INT ErrorCode;
+} NSPROVIDER_ENUM_CONTEXT, *PNSPROVIDER_ENUM_CONTEXT;
+
typedef struct _PROTOCOL_ENUM_CONTEXT
{
LPINT Protocols;
Modified: trunk/reactos/dll/win32/ws2_32/src/addrconv.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/ws2_32/src/addrc…
==============================================================================
--- trunk/reactos/dll/win32/ws2_32/src/addrconv.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/ws2_32/src/addrconv.c [iso-8859-1] Tue Sep 20 16:51:28 2016
@@ -73,6 +73,8 @@
register u_long val, base, n;
register unsigned char c;
u_long parts[4], *pp = parts;
+ if (!cp) return INADDR_ANY;
+ if (!isdigit(*cp)) return INADDR_NONE;
again:
/*
@@ -144,7 +146,7 @@
break;
default:
- return (-1);
+ return (INADDR_NONE);
}
val = htonl(val);
return (val);
Modified: trunk/reactos/dll/win32/ws2_32/src/addrinfo.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/ws2_32/src/addri…
==============================================================================
--- trunk/reactos/dll/win32/ws2_32/src/addrinfo.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/ws2_32/src/addrinfo.c [iso-8859-1] Tue Sep 20 16:51:28 2016
@@ -90,17 +90,76 @@
ParseV4Address(IN PCWSTR AddressString,
OUT PDWORD pAddress)
{
- IN_ADDR Address;
- PCWSTR Terminator;
- NTSTATUS Status;
-
- *pAddress = 0;
- Status = RtlIpv4StringToAddressW(AddressString, FALSE, &Terminator,
&Address);
-
- if (!NT_SUCCESS(Status))
+ CHAR AnsiAddressString[MAX_HOSTNAME_LEN];
+ CHAR * cp = AnsiAddressString;
+ DWORD val, base;
+ unsigned char c;
+ DWORD parts[4], *pp = parts;
+ if (!AddressString)
return FALSE;
-
- *pAddress = Address.S_un.S_addr;
+ WideCharToMultiByte(CP_ACP,
+ 0,
+ AddressString,
+ -1,
+ AnsiAddressString,
+ sizeof(AnsiAddressString),
+ NULL,
+ 0);
+ if (!isdigit(*cp)) return FALSE;
+
+again:
+ /*
+ * Collect number up to ``.''.
+ * Values are specified as for C:
+ * 0x=hex, 0=octal, other=decimal.
+ */
+ val = 0; base = 10;
+ if (*cp == '0') {
+ if (*++cp == 'x' || *cp == 'X')
+ base = 16, cp++;
+ else
+ base = 8;
+ }
+ while ((c = *cp)) {
+ if (isdigit(c)) {
+ val = (val * base) + (c - '0');
+ cp++;
+ continue;
+ }
+ if (base == 16 && isxdigit(c)) {
+ val = (val << 4) + (c + 10 - (islower(c) ? 'a' :
'A'));
+ cp++;
+ continue;
+ }
+ break;
+ }
+ if (*cp == '.') {
+ /*
+ * Internet format:
+ * a.b.c.d
+ */
+ if (pp >= parts + 4) return FALSE;
+ *pp++ = val;
+ cp++;
+ goto again;
+ }
+ /*
+ * Check for trailing characters.
+ */
+ if (*cp) return FALSE;
+
+ *pp++ = val;
+ /*
+ * Concoct the address according to
+ * the number of parts specified.
+ */
+ if ((DWORD)(pp - parts) != 4) return FALSE;
+ if (parts[0] > 0xff || parts[1] > 0xff || parts[2] > 0xff || parts[3] >
0xff) return FALSE;
+ val = (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8) |
parts[3];
+
+ if (pAddress)
+ *pAddress = htonl(val);
+
return TRUE;
}
@@ -530,7 +589,7 @@
pszServiceName,
-1,
AnsiServiceName,
- 256,
+ sizeof(AnsiServiceName),
NULL,
0);
@@ -543,6 +602,7 @@
/* Get the port directly */
wPort = wTcpPort = wUdpPort = htons(wPort);
+#if 0
/* Check if this is both TCP and UDP */
if (iSocketType == 0)
{
@@ -550,9 +610,11 @@
bClone = TRUE;
iSocketType = SOCK_STREAM;
}
+#endif
}
else
{
+ wPort = 0;
/* The port name was a string. Check if this is a UDP socket */
if ((iSocketType == 0) || (iSocketType == SOCK_DGRAM))
{
@@ -576,15 +638,18 @@
/* If we got 0, then fail */
if (wPort == 0)
{
- return iSocketType ? EAI_SERVICE : EAI_NONAME;
+ return EAI_SERVICE;
}
/* Check if this was for both */
if (iSocketType == 0)
{
/* Do the TCP case right now */
- iSocketType = (wTcpPort) ? SOCK_STREAM : SOCK_DGRAM;
- bClone = (wTcpPort && wUdpPort);
+ if (wTcpPort && !wUdpPort)
+ iSocketType = SOCK_STREAM;
+ if (!wTcpPort && wUdpPort)
+ iSocketType = SOCK_DGRAM;
+ //bClone = (wTcpPort && wUdpPort);
}
}
}
@@ -612,7 +677,7 @@
/* Set AI_NUMERICHOST since this is a numeric string */
(*pptResult)->ai_flags |= AI_NUMERICHOST;
- /* Check if the canonical name was requestd */
+ /* Check if the canonical name was requested */
if (iFlags & AI_CANONNAME)
{
/* Get the canonical name */
@@ -657,7 +722,7 @@
pszNodeName,
-1,
AnsiNodeName,
- 256,
+ sizeof(AnsiNodeName),
NULL,
0);
@@ -736,23 +801,23 @@
struct addrinfo FAR * FAR *res)
{
INT ErrorCode;
- LPWSTR UnicodeNodeName;
+ LPWSTR UnicodeNodeName = NULL;
LPWSTR UnicodeServName = NULL;
DPRINT("getaddrinfo: %s, %s, %p, %p\n", nodename, servname, hints, res);
/* Check for WSAStartup */
if ((ErrorCode = WsQuickProlog()) != ERROR_SUCCESS) return ErrorCode;
- /* Assume NULL */
- *res = NULL;
-
/* Convert the node name */
- UnicodeNodeName = UnicodeDupFromAnsi((LPSTR)nodename);
- if (!UnicodeNodeName)
- {
- /* Prepare to fail */
- ErrorCode = GetLastError();
- goto Quickie;
+ if (nodename)
+ {
+ UnicodeNodeName = UnicodeDupFromAnsi((LPSTR)nodename);
+ if (!UnicodeNodeName)
+ {
+ /* Prepare to fail */
+ ErrorCode = GetLastError();
+ goto Quickie;
+ }
}
/* Convert the servname too, if we have one */
@@ -937,7 +1002,7 @@
{
/* Setup the data for it */
ServiceString = ServiceBuffer;
- ServLength = sizeof(ServiceBuffer) / sizeof(WCHAR);
+ ServLength = sizeof(ServiceBuffer) - 1;
}
/* Now call the unicode function */
Modified: trunk/reactos/dll/win32/ws2_32/src/dcatalog.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/ws2_32/src/dcata…
==============================================================================
--- trunk/reactos/dll/win32/ws2_32/src/dcatalog.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/ws2_32/src/dcatalog.c [iso-8859-1] Tue Sep 20 16:51:28 2016
@@ -10,9 +10,10 @@
#include <ws2_32.h>
+#define NDEBUG
+#include <debug.h>
+
/* DATA **********************************************************************/
-
-#define TCCATALOG_NAME "Protocol_Catalog9"
#define WsTcLock()
EnterCriticalSection((LPCRITICAL_SECTION)&Catalog->Lock);
#define WsTcUnlock()
LeaveCriticalSection((LPCRITICAL_SECTION)&Catalog->Lock);
@@ -45,14 +46,33 @@
DWORD RegSize = sizeof(DWORD);
DWORD UniqueId = 0;
DWORD NewData = 0;
+ CHAR* CatalogKeyName;
/* Initialize the catalog lock and namespace list */
InitializeCriticalSection((LPCRITICAL_SECTION)&Catalog->Lock);
InitializeListHead(&Catalog->ProtocolList);
+ /* Read the catalog name */
+ ErrorCode = RegQueryValueEx(ParentKey,
+ "Current_Protocol_Catalog",
+ 0,
+ &RegType,
+ NULL,
+ &RegSize);
+
+ CatalogKeyName = HeapAlloc(WsSockHeap, 0, RegSize);
+
+ /* Read the catalog name */
+ ErrorCode = RegQueryValueEx(ParentKey,
+ "Current_Protocol_Catalog",
+ 0,
+ &RegType,
+ (LPBYTE)CatalogKeyName,
+ &RegSize);
+
/* Open the Catalog Key */
ErrorCode = RegOpenKeyEx(ParentKey,
- TCCATALOG_NAME,
+ CatalogKeyName,
0,
MAXIMUM_ALLOWED,
&CatalogKey);
@@ -67,7 +87,7 @@
{
/* Create the Catalog Name */
ErrorCode = RegCreateKeyEx(ParentKey,
- TCCATALOG_NAME,
+ CatalogKeyName,
0,
NULL,
REG_OPTION_NON_VOLATILE,
@@ -76,6 +96,10 @@
&CatalogKey,
&CreateDisposition);
}
+
+ HeapFree(WsSockHeap, 0, CatalogKeyName);
+ RegType = REG_DWORD;
+ RegSize = sizeof(DWORD);
/* Fail if that didn't work */
if (ErrorCode != ERROR_SUCCESS) return FALSE;
@@ -149,6 +173,7 @@
}
else
{
+ RegSize = sizeof(DWORD);
/* Read the serial number */
ErrorCode = RegQueryValueEx(CatalogKey,
"Serial_Access_Num",
@@ -409,6 +434,7 @@
IN DWORD CatalogEntryId,
IN PTCATALOG_ENTRY *CatalogEntry)
{
+ INT ErrorCode = WSAEINVAL;
PLIST_ENTRY NextEntry = Catalog->ProtocolList.Flink;
PTCATALOG_ENTRY Entry;
@@ -435,6 +461,7 @@
/* Reference the entry and return it */
InterlockedIncrement(&Entry->RefCount);
*CatalogEntry = Entry;
+ ErrorCode = ERROR_SUCCESS;
break;
}
}
@@ -443,7 +470,7 @@
WsTcUnlock();
/* Return */
- return ERROR_SUCCESS;
+ return ErrorCode;
}
DWORD
@@ -458,6 +485,7 @@
INT ErrorCode = WSAEINVAL;
PLIST_ENTRY NextEntry = Catalog->ProtocolList.Flink;
PTCATALOG_ENTRY Entry;
+ DPRINT("WsTcGetEntryFromTriplet: %lx, %lx, %lx, %lx\n", af, type, protocol,
StartId);
/* Assume failure */
*CatalogEntry = NULL;
@@ -494,9 +522,9 @@
if ((Entry->ProtocolInfo.iSocketType == type) || (type == 0))
{
/* Check if Protocol is In Range or if it's wildcard */
- if (((Entry->ProtocolInfo.iProtocol >= protocol) &&
+ if (((Entry->ProtocolInfo.iProtocol <= protocol) &&
((Entry->ProtocolInfo.iProtocol +
- Entry->ProtocolInfo.iProtocolMaxOffset) <= protocol)) ||
+ Entry->ProtocolInfo.iProtocolMaxOffset) >= protocol)) ||
(protocol == 0))
{
/* Check if it doesn't already have a provider */
@@ -580,6 +608,7 @@
{
INT ErrorCode = ERROR_SUCCESS;
PTPROVIDER Provider;
+ DPRINT("WsTcLoadProvider: %p, %p\n", Catalog, CatalogEntry);
/* Lock the catalog */
WsTcLock();
Modified: trunk/reactos/dll/win32/ws2_32/src/dcatitem.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/ws2_32/src/dcati…
==============================================================================
--- trunk/reactos/dll/win32/ws2_32/src/dcatitem.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/ws2_32/src/dcatitem.c [iso-8859-1] Tue Sep 20 16:51:28 2016
@@ -67,6 +67,8 @@
DWORD RegType = REG_BINARY;
HKEY EntryKey;
DWORD Return;
+ LPBYTE Buf;
+ DWORD index;
/* Convert to a 00000xxx string */
sprintf(CatalogEntryName, "%0""12""lu", UniqueId);
@@ -79,20 +81,33 @@
&EntryKey);
/* Get Size of Catalog Entry Structure */
- Return = RegQueryValueExW(EntryKey,
- L"PackedCatalogItem",
+ Return = RegQueryValueEx(EntryKey,
+ "PackedCatalogItem",
0,
NULL,
NULL,
&RegSize);
+ if(!(Buf = HeapAlloc(WsSockHeap, HEAP_ZERO_MEMORY, RegSize)))
+ return ERROR_NOT_ENOUGH_MEMORY;
+
/* Read the Whole Catalog Entry Structure */
- Return = RegQueryValueExW(EntryKey,
- L"PackedCatalogItem",
+ Return = RegQueryValueEx(EntryKey,
+ "PackedCatalogItem",
0,
&RegType,
- (LPBYTE)&CatalogEntry->DllPath,
+ Buf,
&RegSize);
+
+
+ memcpy(CatalogEntry->DllPath, (LPCSTR)Buf, sizeof(CatalogEntry->DllPath));
+ index = sizeof(CatalogEntry->DllPath);
+ if(index < RegSize)
+ {
+ memcpy(&CatalogEntry->ProtocolInfo, &Buf[index],
sizeof(WSAPROTOCOL_INFOW));
+ index += sizeof(WSAPROTOCOL_INFOW);
+ }
+ HeapFree(WsSockHeap, 0, Buf);
/* Done */
RegCloseKey(EntryKey);
Modified: trunk/reactos/dll/win32/ws2_32/src/dprovide.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/ws2_32/src/dprov…
==============================================================================
--- trunk/reactos/dll/win32/ws2_32/src/dprovide.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/ws2_32/src/dprovide.c [iso-8859-1] Tue Sep 20 16:51:28 2016
@@ -10,6 +10,9 @@
#include <ws2_32.h>
+#define NDEBUG
+#include <debug.h>
+
/* FUNCTIONS *****************************************************************/
PTPROVIDER
@@ -18,6 +21,7 @@
{
PTPROVIDER Provider;
+ DPRINT("WsTpAllocate: WsSockHeap %d\n", WsSockHeap);
/* Allocate the object */
Provider = HeapAlloc(WsSockHeap, HEAP_ZERO_MEMORY, sizeof(*Provider));
@@ -35,31 +39,32 @@
IN LPWSAPROTOCOL_INFOW ProtocolInfo)
{
WORD VersionRequested = MAKEWORD(2,2);
- WSPUPCALLTABLE UpcallTable;
LPWSPSTARTUP WSPStartupProc;
WSPDATA WspData;
CHAR ExpandedDllPath[MAX_PATH];
+ DWORD ErrorCode;
+ DPRINT("WsTpInitialize: %p, %p, %p\n", Provider, DllName, ProtocolInfo);
/* Clear the tables */
- RtlZeroMemory(&UpcallTable, sizeof(UpcallTable));
+ RtlZeroMemory(&Provider->UpcallTable, sizeof(WSPUPCALLTABLE));
RtlZeroMemory(&Provider->Service.lpWSPAccept, sizeof(WSPPROC_TABLE));
/* Set up the Upcall Table */
- UpcallTable.lpWPUCloseEvent = WPUCloseEvent;
- UpcallTable.lpWPUCloseSocketHandle = WPUCloseSocketHandle;
- UpcallTable.lpWPUCreateEvent = WPUCreateEvent;
- UpcallTable.lpWPUCreateSocketHandle = WPUCreateSocketHandle;
- UpcallTable.lpWPUFDIsSet = WPUFDIsSet;
- UpcallTable.lpWPUGetProviderPath = WPUGetProviderPath;
- UpcallTable.lpWPUModifyIFSHandle = WPUModifyIFSHandle;
- UpcallTable.lpWPUPostMessage = WPUPostMessage;
- UpcallTable.lpWPUQueryBlockingCallback = WPUQueryBlockingCallback;
- UpcallTable.lpWPUQuerySocketHandleContext = WPUQuerySocketHandleContext;
- UpcallTable.lpWPUQueueApc = WPUQueueApc;
- UpcallTable.lpWPUResetEvent = WPUResetEvent;
- UpcallTable.lpWPUSetEvent = WPUSetEvent;
- UpcallTable.lpWPUOpenCurrentThread = WPUOpenCurrentThread;
- UpcallTable.lpWPUCloseThread = WPUCloseThread;
+ Provider->UpcallTable.lpWPUCloseEvent = WPUCloseEvent;
+ Provider->UpcallTable.lpWPUCloseSocketHandle = WPUCloseSocketHandle;
+ Provider->UpcallTable.lpWPUCreateEvent = WPUCreateEvent;
+ Provider->UpcallTable.lpWPUCreateSocketHandle = WPUCreateSocketHandle;
+ Provider->UpcallTable.lpWPUFDIsSet = WPUFDIsSet;
+ Provider->UpcallTable.lpWPUGetProviderPath = WPUGetProviderPath;
+ Provider->UpcallTable.lpWPUModifyIFSHandle = WPUModifyIFSHandle;
+ Provider->UpcallTable.lpWPUPostMessage = WPUPostMessage;
+ Provider->UpcallTable.lpWPUQueryBlockingCallback = WPUQueryBlockingCallback;
+ Provider->UpcallTable.lpWPUQuerySocketHandleContext =
WPUQuerySocketHandleContext;
+ Provider->UpcallTable.lpWPUQueueApc = WPUQueueApc;
+ Provider->UpcallTable.lpWPUResetEvent = WPUResetEvent;
+ Provider->UpcallTable.lpWPUSetEvent = WPUSetEvent;
+ Provider->UpcallTable.lpWPUOpenCurrentThread = WPUOpenCurrentThread;
+ Provider->UpcallTable.lpWPUCloseThread = WPUCloseThread;
/* Expand the DLL Path */
ExpandEnvironmentStrings(DllName, ExpandedDllPath, MAX_PATH);
@@ -67,18 +72,26 @@
/* Load the DLL */
Provider->DllHandle = LoadLibrary(ExpandedDllPath);
+ if(!Provider->DllHandle)
+ {
+ return SOCKET_ERROR;
+ }
/* Get the pointer to WSPStartup */
WSPStartupProc = (LPWSPSTARTUP)GetProcAddress(Provider->DllHandle,
"WSPStartup");
+ if(!WSPStartupProc)
+ {
+ return SOCKET_ERROR;
+ }
/* Call it */
- (*WSPStartupProc)(VersionRequested,
+ ErrorCode = (*WSPStartupProc)(VersionRequested,
&WspData,
ProtocolInfo,
- UpcallTable,
+ Provider->UpcallTable,
(LPWSPPROC_TABLE)&Provider->Service.lpWSPAccept);
/* Return */
- return ERROR_SUCCESS;
+ return ErrorCode;
}
DWORD
Modified: trunk/reactos/dll/win32/ws2_32/src/enumprot.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/ws2_32/src/enump…
==============================================================================
--- trunk/reactos/dll/win32/ws2_32/src/enumprot.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/ws2_32/src/enumprot.c [iso-8859-1] Tue Sep 20 16:51:28 2016
@@ -31,7 +31,7 @@
ProtocolId = ProtocolSet[i];
/* Loop the list */
- while (ProtocolId != 0)
+ while (ProtocolId != 0 && ProtocolInfo->iProtocol != 0)
{
/* Check if it's within ranges */
if ((ProtocolId >= ProtocolInfo->iProtocol) &&
@@ -188,7 +188,7 @@
}
/*
- * @unimplemented
+ * @implemented
*/
INT
WSAAPI
@@ -196,14 +196,46 @@
OUT LPWSAPROTOCOL_INFOA lpProtocolBuffer,
IN OUT LPDWORD lpdwBufferLength)
{
- DPRINT("WSAEnumProtocolsA: %p\n", lpiProtocols);
- UNIMPLEMENTED;
- SetLastError(WSAEINVAL);
- return SOCKET_ERROR;
-}
-
-/*
- * @unimplemented
+ INT error, i, count;
+ LPWSAPROTOCOL_INFOW protocolInfoW;
+ DWORD size;
+ DPRINT("WSAEnumProtocolsA: %p %p %p\n", lpiProtocols, lpProtocolBuffer,
lpdwBufferLength);
+ if (!lpdwBufferLength)
+ {
+ SetLastError(WSAENOBUFS);
+ return SOCKET_ERROR;
+ }
+ count = WSCEnumProtocols(lpiProtocols, NULL, &size, &error);
+ if (!lpProtocolBuffer || *lpdwBufferLength <
(size/sizeof(WSAPROTOCOL_INFOW))*sizeof(WSAPROTOCOL_INFOA))
+ {
+ *lpdwBufferLength = (size/sizeof(WSAPROTOCOL_INFOW))*sizeof(WSAPROTOCOL_INFOA);
+ SetLastError(WSAENOBUFS);
+ return SOCKET_ERROR;
+ }
+ protocolInfoW = HeapAlloc(WsSockHeap, 0, size);
+ count = WSCEnumProtocols(lpiProtocols, protocolInfoW, &size, &error);
+ if (SOCKET_ERROR == count)
+ {
+ HeapFree(WsSockHeap, 0, protocolInfoW);
+ SetLastError(error);
+ return SOCKET_ERROR;
+ }
+ *lpdwBufferLength = 0;
+ for (i = 0; i < count; i++)
+ {
+ /* Copy the data */
+ RtlMoveMemory(&lpProtocolBuffer[i],
+ &protocolInfoW[i],
+
sizeof(lpProtocolBuffer[0])-sizeof(lpProtocolBuffer[0].szProtocol));
+ wcstombs(lpProtocolBuffer[i].szProtocol, protocolInfoW[i].szProtocol,
sizeof(lpProtocolBuffer[0].szProtocol));
+ *lpdwBufferLength += sizeof(WSAPROTOCOL_INFOA);
+ }
+ HeapFree(WsSockHeap, 0, protocolInfoW);
+ return i;
+}
+
+/*
+ * @implemented
*/
INT
WSAAPI
@@ -211,14 +243,20 @@
OUT LPWSAPROTOCOL_INFOW lpProtocolBuffer,
IN OUT LPDWORD lpdwBufferLength)
{
- DPRINT("WSAEnumProtocolsW: %p\n", lpiProtocols);
- UNIMPLEMENTED;
- SetLastError(WSAEINVAL);
- return SOCKET_ERROR;
-}
-
-/*
- * @unimplemented
+ INT error, count;
+ DPRINT("WSAEnumProtocolsW: %p %p %p\n", lpiProtocols, lpProtocolBuffer,
lpdwBufferLength);
+ count = WSCEnumProtocols(lpiProtocols, lpProtocolBuffer, lpdwBufferLength,
&error);
+ if (SOCKET_ERROR == count)
+ {
+ SetLastError(error);
+ return SOCKET_ERROR;
+ }
+ return count;
+}
+
+
+/*
+ * @implemented
*/
INT
WSPAPI
@@ -227,13 +265,11 @@
IN OUT LPINT lpProviderDllPathLen,
OUT LPINT lpErrno)
{
- DPRINT("WPUGetProviderPath: %p\n", lpProviderId);
- UNIMPLEMENTED;
- return 0;
-}
-
-/*
- * @unimplemented
+ return WSCGetProviderPath(lpProviderId, lpszProviderDllPath, lpProviderDllPathLen,
lpErrno);
+}
+
+/*
+ * @implemented
*/
INT
WSAAPI
@@ -257,7 +293,7 @@
IN OUT LPINT lpProviderDllPathLen,
OUT LPINT lpErrno)
{
- DPRINT("WSCGetProviderPath: %p\n", lpProviderId);
+ DPRINT("WSCGetProviderPath: %p %p %p %p\n", lpProviderId,
lpszProviderDllPath, lpProviderDllPathLen, lpErrno);
UNIMPLEMENTED;
SetLastError(WSAEINVAL);
return SOCKET_ERROR;
Modified: trunk/reactos/dll/win32/ws2_32/src/getproto.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/ws2_32/src/getpr…
==============================================================================
--- trunk/reactos/dll/win32/ws2_32/src/getproto.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/ws2_32/src/getproto.c [iso-8859-1] Tue Sep 20 16:51:28 2016
@@ -19,12 +19,17 @@
WSAAPI
GetProtoOpenNetworkDatabase(PCHAR Name)
{
- CHAR ExpandedPath[MAX_PATH];
- CHAR DatabasePath[MAX_PATH];
+ PCHAR ExpandedPath;
+ PCHAR DatabasePath;
INT ErrorCode;
HKEY DatabaseKey;
DWORD RegType;
- DWORD RegSize = sizeof(DatabasePath);
+ DWORD RegSize = 0;
+ HANDLE ret;
+
+ ExpandedPath = HeapAlloc(WsSockHeap, 0, MAX_PATH);
+ if (!ExpandedPath)
+ return INVALID_HANDLE_VALUE;
/* Open the database path key */
ErrorCode = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
@@ -39,40 +44,66 @@
"DatabasePath",
NULL,
&RegType,
+ NULL,
+ &RegSize);
+
+ DatabasePath = HeapAlloc(WsSockHeap, 0, RegSize);
+ if (!DatabasePath)
+ {
+ HeapFree(WsSockHeap, 0, ExpandedPath);
+ return INVALID_HANDLE_VALUE;
+ }
+
+ /* Read the actual path */
+ ErrorCode = RegQueryValueEx(DatabaseKey,
+ "DatabasePath",
+ NULL,
+ &RegType,
(LPBYTE)DatabasePath,
&RegSize);
+
/* Close the key */
RegCloseKey(DatabaseKey);
/* Expand the name */
ExpandEnvironmentStrings(DatabasePath, ExpandedPath, MAX_PATH);
+
+ HeapFree(WsSockHeap, 0, DatabasePath);
}
else
{
/* Use defalt path */
GetSystemDirectory(ExpandedPath, MAX_PATH);
- strcat(ExpandedPath, "DRIVERS\\ETC\\");
+ if (ExpandedPath[strlen(ExpandedPath) - 1] != '\\')
+ {
+ /* It isn't, so add it ourselves */
+ strncat(ExpandedPath, "\\", MAX_PATH);
+ }
+ strncat(ExpandedPath, "DRIVERS\\ETC\\", MAX_PATH);
}
/* Make sure that the path is backslash-terminated */
if (ExpandedPath[strlen(ExpandedPath) - 1] != '\\')
{
/* It isn't, so add it ourselves */
- strcat(ExpandedPath, "\\");
+ strncat(ExpandedPath, "\\", MAX_PATH);
}
/* Add the database name */
- strcat(ExpandedPath, Name);
+ strncat(ExpandedPath, Name, MAX_PATH);
/* Return a handle to the file */
- return CreateFile(ExpandedPath,
+ ret = CreateFile(ExpandedPath,
FILE_READ_ACCESS,
0,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
+
+ HeapFree(WsSockHeap, 0, ExpandedPath);
+ return ret;
}
PCHAR
@@ -118,9 +149,6 @@
&Read,
NULL)) return NULL;
- /* Null terminate LineBuffer */
- Buffer->LineBuffer[Read] = ANSI_NULL;
-
/* Find out where the line ends */
p1 = Buffer->LineBuffer;
p = strchr(Buffer->LineBuffer, '\n');
@@ -215,7 +243,7 @@
PWSTHREAD Thread;
INT ErrorCode;
PPROTOENT Protoent;
- PVOID GetProtoBuffer;
+ PVOID GetProtoBuffer;
HANDLE DbHandle;
DPRINT("getprotobynumber: %lx\n", number);
@@ -279,7 +307,7 @@
PWSTHREAD Thread;
INT ErrorCode;
PPROTOENT Protoent;
- PVOID GetProtoBuffer;
+ PVOID GetProtoBuffer;
HANDLE DbHandle;
DPRINT("getprotobyname: %s\n", name);
Modified: trunk/reactos/dll/win32/ws2_32/src/getxbyxx.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/ws2_32/src/getxb…
==============================================================================
--- trunk/reactos/dll/win32/ws2_32/src/getxbyxx.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/ws2_32/src/getxbyxx.c [iso-8859-1] Tue Sep 20 16:51:28 2016
@@ -108,9 +108,11 @@
{
PWSAQUERYSETA WsaQuery = (PWSAQUERYSETA)*Results;
INT ErrorCode;
+ DWORD NewLength = Length;
HANDLE RnRHandle;
LPBLOB Blob = NULL;
- PVOID NewResults;
+ PVOID NewResults = NULL;
+ DWORD dwControlFlags = LUP_RETURN_NAME;
/* Assume empty return name */
if (NewName) *NewName = NULL;
@@ -121,12 +123,15 @@
WsaQuery->lpszServiceInstanceName = Name;
WsaQuery->lpServiceClassId = (LPGUID)Type;
WsaQuery->dwNameSpace = NS_ALL;
- WsaQuery->dwNumberOfProtocols = 2;
- WsaQuery->lpafpProtocols = &afp[0];
+ WsaQuery->dwNumberOfProtocols = sizeof(afp)/sizeof(afp[0]);
+ WsaQuery->lpafpProtocols = afp;
+
+ if(!IsEqualGUID(Type, &HostnameGuid))
+ dwControlFlags |= LUP_RETURN_BLOB;
/* Send the Query Request to find a Service */
ErrorCode = WSALookupServiceBeginA(WsaQuery,
- LUP_RETURN_BLOB | LUP_RETURN_NAME,
+ dwControlFlags,
&RnRHandle);
if(ErrorCode == ERROR_SUCCESS)
@@ -136,7 +141,7 @@
/* Service was found, send the real query */
ErrorCode = WSALookupServiceNextA(RnRHandle,
0,
- &Length,
+ &NewLength,
WsaQuery);
/* Return the information requested */
@@ -152,7 +157,7 @@
else
{
/* Check if this was a Hostname lookup */
- if (Type == &HostnameGuid)
+ if (IsEqualGUID(Type, &HostnameGuid))
{
/* Return the name anyways */
if(NewName) *NewName = WsaQuery->lpszServiceInstanceName;
@@ -368,7 +373,7 @@
else
{
/* We failed, so zero it out */
- Hostent = 0;
+ Hostent = NULL;
/* Normalize the error message */
if(GetLastError() == WSASERVICE_NOT_FOUND)
@@ -390,18 +395,25 @@
INT
WSAAPI
gethostname(OUT char FAR * name,
- IN int namelen)
-{
- PCHAR Name;
+ IN INT namelen)
+{
+ PCHAR Name = NULL;
CHAR ResultsBuffer[RNR_BUFFER_SIZE];
PCHAR Results = ResultsBuffer;
DPRINT("gethostname: %p\n", name);
+ if (!name || namelen < 1)
+ {
+ SetLastError(WSAEFAULT);
+ return SOCKET_ERROR;
+ }
/* Get the Hostname in a String */
- if(getxyDataEnt(&Results, RNR_BUFFER_SIZE, NULL, &HostnameGuid, &Name))
+ /* getxyDataEnt does not return blob for HostnameGuid */
+ getxyDataEnt(&Results, RNR_BUFFER_SIZE, NULL, &HostnameGuid, &Name);
+ if(Name)
{
/* Copy it */
- strcpy((LPSTR)name, Name);
+ strncpy((LPSTR)name, Name, namelen-1);
}
/* Check if we received a newly allocated buffer; free it. */
@@ -450,7 +462,7 @@
}
/* Put it into the right syntax */
- sprintf(PortName, "%d/%s", (port & 0xffff), proto);
+ sprintf(PortName, "%d/%s", (ntohs(port) & 0xffff), proto);
/* Get the Service in a Blob */
Blob = getxyDataEnt(&Results, RNR_BUFFER_SIZE, PortName, &IANAGuid, 0);
@@ -471,9 +483,6 @@
{
/* We failed, so zero it out */
Servent = 0;
-
- /* Normalize the error message */
- if(GetLastError() == WSATYPE_NOT_FOUND) SetLastError(WSANO_DATA);
}
/* Check if we received a newly allocated buffer; free it. */
@@ -543,9 +552,6 @@
{
/* We failed, so zero it out */
Servent = 0;
-
- /* Normalize the error message */
- if(GetLastError() == WSATYPE_NOT_FOUND) SetLastError(WSANO_DATA);
}
/* Check if we received a newly allocated buffer; free it. */
Modified: trunk/reactos/dll/win32/ws2_32/src/nscatalo.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/ws2_32/src/nscat…
==============================================================================
--- trunk/reactos/dll/win32/ws2_32/src/nscatalo.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/ws2_32/src/nscatalo.c [iso-8859-1] Tue Sep 20 16:51:28 2016
@@ -10,9 +10,11 @@
#include <ws2_32.h>
+#define NDEBUG
+#include <debug.h>
+
/* DATA **********************************************************************/
-#define NSCATALOG_NAME "NameSpace_Catalog5"
#define WsNcLock()
EnterCriticalSection((LPCRITICAL_SECTION)&Catalog->Lock);
#define WsNcUnlock()
LeaveCriticalSection((LPCRITICAL_SECTION)&Catalog->Lock);
@@ -39,19 +41,37 @@
LONG ErrorCode;
DWORD CreateDisposition;
HKEY CatalogKey, NewKey;
- //DWORD CatalogEntries = 0;
DWORD RegType = REG_DWORD;
DWORD RegSize = sizeof(DWORD);
DWORD UniqueId = 0;
DWORD NewData = 0;
+ CHAR* CatalogKeyName;
/* Initialize the catalog lock and namespace list */
InitializeCriticalSection((LPCRITICAL_SECTION)&Catalog->Lock);
InitializeListHead(&Catalog->CatalogList);
+ /* Read the catalog name */
+ ErrorCode = RegQueryValueEx(ParentKey,
+ "Current_NameSpace_Catalog",
+ 0,
+ &RegType,
+ NULL,
+ &RegSize);
+
+ CatalogKeyName = HeapAlloc(WsSockHeap, 0, RegSize);
+
+ /* Read the catalog name */
+ ErrorCode = RegQueryValueEx(ParentKey,
+ "Current_NameSpace_Catalog",
+ 0,
+ &RegType,
+ (LPBYTE)CatalogKeyName,
+ &RegSize);
+
/* Open the Catalog Key */
ErrorCode = RegOpenKeyEx(ParentKey,
- NSCATALOG_NAME,
+ CatalogKeyName,
0,
MAXIMUM_ALLOWED,
&CatalogKey);
@@ -66,7 +86,7 @@
{
/* Create the Catalog Name */
ErrorCode = RegCreateKeyEx(ParentKey,
- NSCATALOG_NAME,
+ CatalogKeyName,
0,
NULL,
REG_OPTION_NON_VOLATILE,
@@ -75,6 +95,10 @@
&CatalogKey,
&CreateDisposition);
}
+
+ HeapFree(WsSockHeap, 0, CatalogKeyName);
+ RegType = REG_DWORD;
+ RegSize = sizeof(DWORD);
/* Fail if that didn't work */
if (ErrorCode != ERROR_SUCCESS) return FALSE;
@@ -133,6 +157,7 @@
}
else
{
+ RegSize = sizeof(UniqueId);
/* Read the serial number */
ErrorCode = RegQueryValueEx(CatalogKey,
"Serial_Access_Num",
Modified: trunk/reactos/dll/win32/ws2_32/src/nscatent.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/ws2_32/src/nscat…
==============================================================================
--- trunk/reactos/dll/win32/ws2_32/src/nscatent.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/ws2_32/src/nscatent.c [iso-8859-1] Tue Sep 20 16:51:28 2016
@@ -64,103 +64,108 @@
IN HKEY ParentKey,
IN ULONG UniqueId)
{
+ INT ErrorCode;
CHAR CatalogEntryName[13];
HKEY EntryKey;
ULONG RegType = REG_SZ;
ULONG RegSize = MAX_PATH;
+ ULONG RegValue;
/* Convert to a 00000xxx string */
sprintf(CatalogEntryName, "%0""12""i", (int)UniqueId);
/* Open the Entry */
- RegOpenKeyEx(ParentKey,
- CatalogEntryName,
- 0,
- KEY_READ,
- &EntryKey);
-
+ ErrorCode = RegOpenKeyEx(ParentKey,
+ CatalogEntryName,
+ 0,
+ KEY_READ,
+ &EntryKey);
+ if (ErrorCode != ERROR_SUCCESS) return ErrorCode;
/* Read the Library Path */
- RegQueryValueExW(EntryKey,
- L"LibraryPath",
- 0,
- &RegType,
- (LPBYTE)&CatalogEntry->DllPath,
- &RegSize);
-
+ ErrorCode = RegQueryValueExW(EntryKey,
+ L"LibraryPath",
+ 0,
+ &RegType,
+ (LPBYTE)&CatalogEntry->DllPath,
+ &RegSize);
+ if (ErrorCode != ERROR_SUCCESS) goto out;
/* Query Display String Size*/
- RegQueryValueExW(EntryKey,
- L"DisplayString",
- 0,
- NULL,
- NULL,
- &RegSize);
-
+ ErrorCode = RegQueryValueExW(EntryKey,
+ L"DisplayString",
+ 0,
+ NULL,
+ NULL,
+ &RegSize);
+ if (ErrorCode != ERROR_SUCCESS) goto out;
/* Allocate it */
CatalogEntry->ProviderName = (LPWSTR)HeapAlloc(WsSockHeap, 0, RegSize);
/* Read it */
- RegQueryValueExW(EntryKey,
- L"DisplayString",
- 0,
- &RegType,
- (LPBYTE)CatalogEntry->ProviderName,
- &RegSize);
-
+ ErrorCode = RegQueryValueExW(EntryKey,
+ L"DisplayString",
+ 0,
+ &RegType,
+ (LPBYTE)CatalogEntry->ProviderName,
+ &RegSize);
+ if (ErrorCode != ERROR_SUCCESS) goto out;
/* Read the Provider Id */
RegType = REG_BINARY;
RegSize = sizeof(GUID);
- RegQueryValueEx(EntryKey,
- "ProviderId",
- 0,
- &RegType,
- (LPBYTE)&CatalogEntry->ProviderId,
- &RegSize);
-
+ ErrorCode = RegQueryValueEx(EntryKey,
+ "ProviderId",
+ 0,
+ &RegType,
+ (LPBYTE)&CatalogEntry->ProviderId,
+ &RegSize);
+ if (ErrorCode != ERROR_SUCCESS) goto out;
/* Read the Address Family */
RegType = REG_DWORD;
RegSize = sizeof(DWORD);
- RegQueryValueEx(EntryKey,
- "AddressFamily",
- 0,
- &RegType,
- (LPBYTE)&CatalogEntry->AddressFamily,
- &RegSize);
-
+ ErrorCode = RegQueryValueEx(EntryKey,
+ "AddressFamily",
+ 0,
+ &RegType,
+ (LPBYTE)&CatalogEntry->AddressFamily,
+ &RegSize);
+ if (ErrorCode != ERROR_SUCCESS) goto out;
/* Read the Namespace Id */
- RegQueryValueEx(EntryKey,
- "SupportedNamespace",
- 0,
- &RegType,
- (LPBYTE)&CatalogEntry->NamespaceId,
- &RegSize);
-
+ ErrorCode = RegQueryValueEx(EntryKey,
+ "SupportedNamespace",
+ 0,
+ &RegType,
+ (LPBYTE)&CatalogEntry->NamespaceId,
+ &RegSize);
+ if (ErrorCode != ERROR_SUCCESS) goto out;
/* Read the Enabled Flag */
- RegQueryValueEx(EntryKey,
- "Enabled",
- 0,
- &RegType,
- (LPBYTE)&CatalogEntry->Enabled,
- &RegSize);
+ ErrorCode = RegQueryValueEx(EntryKey,
+ "Enabled",
+ 0,
+ &RegType,
+ (LPBYTE)&RegValue,
+ &RegSize);
+ if (ErrorCode != ERROR_SUCCESS) goto out;
+ CatalogEntry->Enabled = RegValue != 0;
/* Read the Version */
- RegQueryValueEx(EntryKey,
- "Version",
- 0,
- &RegType,
- (LPBYTE)&CatalogEntry->Version,
- &RegSize);
-
+ ErrorCode = RegQueryValueEx(EntryKey,
+ "Version",
+ 0,
+ &RegType,
+ (LPBYTE)&CatalogEntry->Version,
+ &RegSize);
+ if (ErrorCode != ERROR_SUCCESS) goto out;
/* Read the Support Service Class Info Flag */
- RegQueryValueEx(EntryKey,
- "Version",
- 0,
- &RegType,
- (LPBYTE)&CatalogEntry->StoresServiceClassInfo,
- &RegSize);
-
+ ErrorCode = RegQueryValueEx(EntryKey,
+ "StoresServiceClassInfo",
+ 0,
+ &RegType,
+ (LPBYTE)&RegValue,
+ &RegSize);
+ CatalogEntry->StoresServiceClassInfo = RegValue != 0;
+out:
/* Done */
RegCloseKey(EntryKey);
- return ERROR_SUCCESS;
+ return ErrorCode;
}
VOID
Modified: trunk/reactos/dll/win32/ws2_32/src/nsquery.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/ws2_32/src/nsque…
==============================================================================
--- trunk/reactos/dll/win32/ws2_32/src/nsquery.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/ws2_32/src/nsquery.c [iso-8859-1] Tue Sep 20 16:51:28 2016
@@ -360,7 +360,7 @@
{
WSASERVICECLASSINFOW ClassInfo;
PNSQUERY_PROVIDER Provider;
- LPWSASERVICECLASSINFOW pClassInfo = NULL;
+ LPWSASERVICECLASSINFOW pClassInfo = &ClassInfo;
PNSQUERY_PROVIDER NextProvider;
PLIST_ENTRY Entry;
INT ErrorCode;
@@ -438,7 +438,7 @@
/* Get the class information */
ClassInfo.lpServiceClassId = Restrictions->lpServiceClassId;
- ErrorCode = WsNcGetServiceClassInfo(Catalog, &ClassInfoSize, &ClassInfo);
+ ErrorCode = WsNcGetServiceClassInfo(Catalog, &ClassInfoSize, pClassInfo);
/* Check if more buffer space is needed */
if ((ErrorCode == SOCKET_ERROR) && (GetLastError() == WSAEFAULT))
Modified: trunk/reactos/dll/win32/ws2_32/src/rnr.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/ws2_32/src/rnr.c…
==============================================================================
--- trunk/reactos/dll/win32/ws2_32/src/rnr.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/ws2_32/src/rnr.c [iso-8859-1] Tue Sep 20 16:51:28 2016
@@ -214,7 +214,7 @@
}
/* Check for a valid handle, then validate and reference it */
- if (!(Query) || !(WsNqValidateAndReference(Query)))
+ if (IsBadReadPtr(Query, sizeof(*Query)) || !WsNqValidateAndReference(Query))
{
/* Fail */
SetLastError(WSA_INVALID_HANDLE);
@@ -249,7 +249,8 @@
DPRINT("WSALookupServiceBeginA: %p\n", lpqsRestrictions);
/* Verifiy pointer */
- if (IsBadReadPtr(lpqsRestrictions, sizeof(*lpqsRestrictions)))
+ if (IsBadReadPtr(lpqsRestrictions, sizeof(*lpqsRestrictions)) ||
+ IsBadReadPtr(lpqsRestrictions->lpServiceClassId,
sizeof(*lpqsRestrictions->lpServiceClassId)))
{
/* Invalid */
SetLastError(WSAEFAULT);
@@ -334,7 +335,8 @@
/* Verify pointers */
if (IsBadWritePtr(lphLookup, sizeof(*lphLookup)) ||
- IsBadReadPtr(lpqsRestrictions, sizeof(*lpqsRestrictions)))
+ IsBadReadPtr(lpqsRestrictions, sizeof(*lpqsRestrictions)) ||
+ IsBadReadPtr(lpqsRestrictions->lpServiceClassId,
sizeof(*lpqsRestrictions->lpServiceClassId)))
{
/* They are invalid; fail */
SetLastError(WSAEFAULT);
@@ -401,8 +403,16 @@
return SOCKET_ERROR;
}
+ /* Verify pointer */
+ if (IsBadWritePtr(lpqsResults, sizeof(*lpqsResults)))
+ {
+ /* It is invalid; fail */
+ SetLastError(WSAEFAULT);
+ return SOCKET_ERROR;
+ }
+
/* Check for a valid handle, then validate and reference it */
- if (!(Query) || !(WsNqValidateAndReference(Query)))
+ if (IsBadReadPtr(Query, sizeof(*Query)) || !WsNqValidateAndReference(Query))
{
/* Fail */
SetLastError(WSA_INVALID_HANDLE);
@@ -611,7 +621,167 @@
}
/*
- * @unimplemented
+* @unimplemented
+*/
+INT
+WSAAPI
+WSAInstallServiceClassW(IN LPWSASERVICECLASSINFOW lpServiceClassInfo)
+{
+ DPRINT("WSAInstallServiceClassW: %lx\n", lpServiceClassInfo);
+ SetLastError(WSAEINVAL);
+ return SOCKET_ERROR;
+}
+
+VOID
+WSAAPI
+NSProviderInfoFromContext(IN PNSCATALOG_ENTRY Entry,
+ IN PNSPROVIDER_ENUM_CONTEXT Context)
+{
+ INT size = Context->Unicode ? sizeof(WSANAMESPACE_INFOW) :
sizeof(WSANAMESPACE_INFOA);
+ /* Calculate ProviderName string size */
+ INT size1 = Entry->ProviderName ? wcslen(Entry->ProviderName) + 1 : 0;
+ INT size2 = Context->Unicode ? size1 * sizeof(WCHAR) : size1 * sizeof(CHAR);
+ WSANAMESPACE_INFOW infoW;
+ /* Fill NS Provider data */
+ infoW.dwNameSpace = Entry->NamespaceId;
+ infoW.dwVersion = Entry->Version;
+ infoW.fActive = Entry->Enabled;
+ RtlMoveMemory(&infoW.NSProviderId,
+ &Entry->ProviderId,
+ sizeof(infoW.NSProviderId));
+ if (size2)
+ {
+ /* Calculate ProviderName string pointer */
+ infoW.lpszIdentifier = (LPWSTR)((ULONG_PTR)Context->ProtocolBuffer +
+ Context->BufferUsed + size);
+ }
+ else
+ {
+ infoW.lpszIdentifier = NULL;
+ }
+
+ /* Check if we'll have space */
+ if ((Context->BufferUsed + size + size2) <=
+ (Context->BufferLength))
+ {
+ /* Copy the data */
+ RtlMoveMemory((PVOID)((ULONG_PTR)Context->ProtocolBuffer +
+ Context->BufferUsed),
+ &infoW,
+ size);
+ if (size2)
+ {
+ /* Entry->ProviderName is LPWSTR */
+ if (Context->Unicode)
+ {
+ RtlMoveMemory((PVOID)((ULONG_PTR)Context->ProtocolBuffer +
+ Context->BufferUsed + size),
+ Entry->ProviderName,
+ size2);
+ }
+ else
+ {
+ /* Call the conversion function */
+ WideCharToMultiByte(CP_ACP,
+ 0,
+ Entry->ProviderName,
+ -1,
+ (LPSTR)((ULONG_PTR)Context->ProtocolBuffer +
+ Context->BufferUsed + size),
+ size2,
+ NULL,
+ NULL);
+
+ }
+ }
+
+ /* Increase the count */
+ Context->Count++;
+ }
+}
+
+BOOL
+WSAAPI
+NSProvidersEnumerationProc(PVOID EnumContext,
+ PNSCATALOG_ENTRY Entry)
+{
+ PNSPROVIDER_ENUM_CONTEXT Context = (PNSPROVIDER_ENUM_CONTEXT)EnumContext;
+
+ /* Calculate ProviderName string size */
+ INT size1 = Entry->ProviderName ? wcslen(Entry->ProviderName) + 1 : 0;
+ INT size2 = Context->Unicode ? size1 * sizeof(WCHAR) : size1 * sizeof(CHAR);
+
+ /* Copy the information */
+ NSProviderInfoFromContext(Entry, Context);
+ Context->BufferUsed += Context->Unicode ? (sizeof(WSANAMESPACE_INFOW)+size2) :
(sizeof(WSANAMESPACE_INFOA)+size2);
+
+ /* Continue enumeration */
+ return TRUE;
+}
+
+INT
+WSAAPI
+WSAEnumNameSpaceProvidersInternal(IN OUT LPDWORD lpdwBufferLength,
+ OUT LPWSANAMESPACE_INFOA lpnspBuffer, BOOLEAN Unicode)
+{
+ INT Status;
+ PWSPROCESS WsProcess;
+ PNSCATALOG Catalog;
+ NSPROVIDER_ENUM_CONTEXT Context;
+ DPRINT("WSAEnumNameSpaceProvidersInternal: %lx\n", lpnspBuffer);
+
+ if (!lpdwBufferLength)
+ {
+ WSASetLastError(WSAEFAULT);
+ return SOCKET_ERROR;
+ }
+ WsProcess = WsGetProcess();
+ /* Create a catalog object from the current one */
+ Catalog = WsProcGetNsCatalog(WsProcess);
+ if (!Catalog)
+ {
+ /* Fail if we couldn't */
+ WSASetLastError(WSA_NOT_ENOUGH_MEMORY);
+ return SOCKET_ERROR;
+ }
+
+ Context.ProtocolBuffer = lpnspBuffer;
+ Context.BufferLength = lpnspBuffer ? *lpdwBufferLength : 0;
+ Context.BufferUsed = 0;
+ Context.Count = 0;
+ Context.Unicode = Unicode;
+ Context.ErrorCode = ERROR_SUCCESS;
+
+ WsNcEnumerateCatalogItems(Catalog, NSProvidersEnumerationProc, &Context);
+
+ /* Get status */
+ Status = Context.Count;
+
+ /* Check the error code */
+ if (Context.ErrorCode == ERROR_SUCCESS)
+ {
+ /* Check if enough space was available */
+ if (Context.BufferLength < Context.BufferUsed)
+ {
+ /* Fail and tell them how much we need */
+ *lpdwBufferLength = Context.BufferUsed;
+ WSASetLastError(WSAEFAULT);
+ Status = SOCKET_ERROR;
+ }
+ }
+ else
+ {
+ /* Failure, normalize error */
+ Status = SOCKET_ERROR;
+ WSASetLastError(Context.ErrorCode);
+ }
+
+ /* Return */
+ return Status;
+}
+
+/*
+ * @implemented
*/
INT
WSAAPI
@@ -619,12 +789,11 @@
OUT LPWSANAMESPACE_INFOA lpnspBuffer)
{
DPRINT("WSAEnumNameSpaceProvidersA: %lx\n", lpnspBuffer);
- SetLastError(WSAEINVAL);
- return SOCKET_ERROR;
-}
-
-/*
- * @unimplemented
+ return WSAEnumNameSpaceProvidersInternal(lpdwBufferLength,
(LPWSANAMESPACE_INFOA)lpnspBuffer, FALSE);
+}
+
+/*
+ * @implemented
*/
INT
WSAAPI
@@ -632,20 +801,7 @@
OUT LPWSANAMESPACE_INFOW lpnspBuffer)
{
DPRINT("WSAEnumNameSpaceProvidersW: %lx\n", lpnspBuffer);
- SetLastError(WSAEINVAL);
- return SOCKET_ERROR;
-}
-
-/*
- * @unimplemented
- */
-INT
-WSAAPI
-WSAInstallServiceClassW(IN LPWSASERVICECLASSINFOW lpServiceClassInfo)
-{
- DPRINT("WSAInstallServiceClassW: %lx\n", lpServiceClassInfo);
- SetLastError(WSAEINVAL);
- return SOCKET_ERROR;
+ return WSAEnumNameSpaceProvidersInternal(lpdwBufferLength,
(LPWSANAMESPACE_INFOA)lpnspBuffer, TRUE);
}
/*
Modified: trunk/reactos/dll/win32/ws2_32/src/send.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/ws2_32/src/send.…
==============================================================================
--- trunk/reactos/dll/win32/ws2_32/src/send.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/ws2_32/src/send.c [iso-8859-1] Tue Sep 20 16:51:28 2016
@@ -31,7 +31,7 @@
LPWSATHREADID ThreadId;
WSABUF Buffers;
DWORD BytesSent;
- DPRINT("send: %lx, %lx, %lx, %p\n", s, flags, len, buf);
+ DPRINT("sendto: %lx, %lx, %lx, %p\n", s, flags, len, buf);
/* Check for WSAStartup */
if ((ErrorCode = WsQuickPrologTid(&ThreadId)) == ERROR_SUCCESS)
Modified: trunk/reactos/dll/win32/ws2_32/src/sockctrl.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/ws2_32/src/sockc…
==============================================================================
--- trunk/reactos/dll/win32/ws2_32/src/sockctrl.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/ws2_32/src/sockctrl.c [iso-8859-1] Tue Sep 20 16:51:28 2016
@@ -441,6 +441,11 @@
return Status;
}
+ if (!optval && optlen > 0)
+ {
+ SetLastError(WSAEFAULT);
+ return SOCKET_ERROR;
+ }
/* Get the Socket Context */
if ((Socket = WsSockGetSocket(s)))
Modified: trunk/reactos/dll/win32/ws2_32/src/socklife.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/ws2_32/src/sockl…
==============================================================================
--- trunk/reactos/dll/win32/ws2_32/src/socklife.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/ws2_32/src/socklife.c [iso-8859-1] Tue Sep 20 16:51:28 2016
@@ -567,6 +567,20 @@
}
/* Check if we got a valid socket */
+ if (Status == WSAEINVAL)
+ {
+ Status = INVALID_SOCKET;
+ ErrorCode = WSAEINVAL;
+ }
+
+ /* Check if we got a valid socket */
+ if (Status == WSAEINVAL)
+ {
+ Status = INVALID_SOCKET;
+ ErrorCode = WSAEINVAL;
+ }
+
+ /* Check if we got a valid socket */
if (Status != INVALID_SOCKET)
{
/* Add an API reference and return */
Modified: trunk/reactos/dll/win32/ws2_32/src/startup.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/ws2_32/src/start…
==============================================================================
--- trunk/reactos/dll/win32/ws2_32/src/startup.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/ws2_32/src/startup.c [iso-8859-1] Tue Sep 20 16:51:28 2016
@@ -83,11 +83,16 @@
WsAsyncTerminateThread();
}
+ DPRINT("WSACleanup RefCount = %ld\n", RefCount);
/* Return success */
ErrorCode = ERROR_SUCCESS;
+
+ /* Clear last error */
+ SetLastError(ERROR_SUCCESS);
}
else
{
+ DPRINT("WSACleanup unintialized\n");
/* Weren't initialized */
SetLastError(ErrorCode);
ErrorCode = SOCKET_ERROR;
@@ -111,7 +116,7 @@
WORD VersionReturned = 0;
DWORD ErrorCode = ERROR_SUCCESS;
PWSPROCESS CurrentProcess;
- DPRINT("WSAStartup: %wx\n", wVersionRequested);
+ DPRINT("WSAStartup: %wx %d.%d\n", wVersionRequested,
LOBYTE(wVersionRequested), HIBYTE(wVersionRequested));
/* Make sure that we went through DLL Init */
if (!WsDllHandle) return WSASYSNOTREADY;
@@ -123,14 +128,15 @@
/* We don't support this unknown version */
ErrorCode = WSAVERNOTSUPPORTED;
+ VersionReturned = MAKEWORD(2, 2);
break;
case 1:
/* We support only 1.0 and 1.1 */
- if (HIBYTE(wVersionRequested) == 0)
+ if (HIBYTE(wVersionRequested) <= 1)
{
/* Caller wants 1.0, return it */
- VersionReturned = wVersionRequested;
+ VersionReturned = MAKEWORD(1, HIBYTE(wVersionRequested));
}
else
{
@@ -158,6 +164,12 @@
/* Return 2.2 */
VersionReturned = MAKEWORD(2, 2);
break;
+ }
+
+ if (lpWSAData == NULL)
+ {
+ SetLastError(WSANOTINITIALISED);
+ return ErrorCode == ERROR_SUCCESS ? WSAEFAULT : ErrorCode;
}
/* Return the Version Requested, unless error */
@@ -181,6 +193,13 @@
{
lpWSAData->iMaxSockets = 0;
lpWSAData->iMaxUdpDg = 0;
+ }
+
+ /* Requested invalid version (0) */
+ if (ErrorCode != ERROR_SUCCESS)
+ {
+ SetLastError(WSANOTINITIALISED);
+ return ErrorCode;
}
/* Enter the startup synchronization lock */
@@ -223,6 +242,14 @@
/* Increase the reference count */
InterlockedIncrement(&CurrentProcess->RefCount);
+ DPRINT("WSAStartup RefCount = %ld\n", CurrentProcess->RefCount);
+
+ /* Clear last error */
+ SetLastError(ERROR_SUCCESS);
+ }
+ else
+ {
+ SetLastError(WSANOTINITIALISED);
}
/* Leave the startup lock */