Author: tfaber Date: Sat Nov 7 09:38:13 2015 New Revision: 69826
URL: http://svn.reactos.org/svn/reactos?rev=69826&view=rev Log: [WS2_32] - Handle SO_PROTOCOL_INFOA in getsockopt based on ws2_32_new. CORE-10440
Modified: trunk/reactos/dll/win32/ws2_32/CMakeLists.txt trunk/reactos/dll/win32/ws2_32/include/ws2_32.h trunk/reactos/dll/win32/ws2_32/misc/stubs.c
Modified: trunk/reactos/dll/win32/ws2_32/CMakeLists.txt URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/ws2_32/CMakeLists... ============================================================================== --- trunk/reactos/dll/win32/ws2_32/CMakeLists.txt [iso-8859-1] (original) +++ trunk/reactos/dll/win32/ws2_32/CMakeLists.txt [iso-8859-1] Sat Nov 7 09:38:13 2015 @@ -25,7 +25,7 @@ ${CMAKE_CURRENT_BINARY_DIR}/ws2_32.def)
set_module_type(ws2_32 win32dll UNICODE) -target_link_libraries(ws2_32 wine) +target_link_libraries(ws2_32 wine ${PSEH_LIB}) add_delay_importlibs(ws2_32 user32) add_importlibs(ws2_32 advapi32 dnsapi ws2help msvcrt kernel32 ntdll) add_pch(ws2_32 include/ws2_32.h SOURCE)
Modified: trunk/reactos/dll/win32/ws2_32/include/ws2_32.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/ws2_32/include/ws... ============================================================================== --- trunk/reactos/dll/win32/ws2_32/include/ws2_32.h [iso-8859-1] (original) +++ trunk/reactos/dll/win32/ws2_32/include/ws2_32.h [iso-8859-1] Sat Nov 7 09:38:13 2015 @@ -16,10 +16,12 @@
#include <windef.h> #include <winbase.h> +#include <winnls.h> #include <winuser.h> #include <ws2spi.h> #define NTOS_MODE_USER #include <ndk/rtlfuncs.h> +#include <pseh/pseh2.h>
#include <wsahelp.h>
Modified: trunk/reactos/dll/win32/ws2_32/misc/stubs.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/ws2_32/misc/stubs... ============================================================================== --- trunk/reactos/dll/win32/ws2_32/misc/stubs.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/ws2_32/misc/stubs.c [iso-8859-1] Sat Nov 7 09:38:13 2015 @@ -96,6 +96,32 @@ return Error; }
+INT +WSAAPI +MapUnicodeProtocolInfoToAnsi(IN LPWSAPROTOCOL_INFOW UnicodeInfo, + OUT LPWSAPROTOCOL_INFOA AnsiInfo) +{ + INT ReturnValue; + + /* Copy all the data that doesn't need converting */ + RtlCopyMemory(AnsiInfo, + UnicodeInfo, + FIELD_OFFSET(WSAPROTOCOL_INFOA, szProtocol)); + + /* Now convert the protocol string */ + ReturnValue = WideCharToMultiByte(CP_ACP, + 0, + UnicodeInfo->szProtocol, + -1, + AnsiInfo->szProtocol, + sizeof(AnsiInfo->szProtocol), + NULL, + NULL); + if (!ReturnValue) return WSASYSCALLFAILURE; + + /* Return success */ + return ERROR_SUCCESS; +}
/* * @implemented @@ -111,6 +137,9 @@ PCATALOG_ENTRY Provider; INT Errno; int Error; + WSAPROTOCOL_INFOW ProtocolInfo; + PCHAR OldOptVal = NULL; + INT OldOptLen = 0;
if (!WSAINITIALIZED) { @@ -123,6 +152,47 @@ { WSASetLastError(WSAENOTSOCK); return SOCKET_ERROR; + } + + /* Check if ANSI data was requested */ + if ((level == SOL_SOCKET) && (optname == SO_PROTOCOL_INFOA)) + { + /* Validate size and pointers */ + Errno = NO_ERROR; + _SEH2_TRY + { + if (!(optval) || + !(optlen) || + (*optlen < sizeof(WSAPROTOCOL_INFOA))) + { + /* Set return size and error code */ + *optlen = sizeof(WSAPROTOCOL_INFOA); + Errno = WSAEFAULT; + _SEH2_LEAVE; + } + + /* It worked. Save the values */ + OldOptLen = *optlen; + OldOptVal = optval; + + /* Hack them so WSP will know how to deal with it */ + *optlen = sizeof(WSAPROTOCOL_INFOW); + optval = (PCHAR)&ProtocolInfo; + optname = SO_PROTOCOL_INFOW; + } + _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) + { + Errno = WSAEFAULT; + } + _SEH2_END; + + /* Did we encounter invalid parameters? */ + if (Errno != NO_ERROR) + { + /* Fail */ + Error = SOCKET_ERROR; + goto Exit; + } }
Error = Provider->ProcTable.lpWSPGetSockOpt(s, @@ -132,6 +202,28 @@ optlen, &Errno);
+ /* Did we use the A->W hack? */ + if (Error == ERROR_SUCCESS && OldOptVal) + { + /* We did, so we have to convert the unicode info to ansi */ + Errno = MapUnicodeProtocolInfoToAnsi(&ProtocolInfo, + (LPWSAPROTOCOL_INFOA) + OldOptVal); + + /* Return the length */ + _SEH2_TRY + { + *optlen = OldOptLen; + } + _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) + { + Errno = WSAEFAULT; + Error = SOCKET_ERROR; + } + _SEH2_END; + } + +Exit: DereferenceProviderByPointer(Provider);
if (Error == SOCKET_ERROR)