Index: base/services/dhcpcsvc/dhcp/dhclient.c =================================================================== --- base/services/dhcpcsvc/dhcp/dhclient.c (revision 72669) +++ base/services/dhcpcsvc/dhcp/dhclient.c (working copy) @@ -447,6 +447,37 @@ } +void set_domain( PDHCP_ADAPTER Adapter, struct client_lease *new_lease ) { + CHAR Buffer1[MAX_PATH] = "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces\\"; + CHAR Buffer2[MAX_PATH] = "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters"; + HKEY RegKey1, RegKey2; + + strcat(Buffer1, Adapter->DhclientInfo.name); + if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, Buffer1, 0, KEY_WRITE, &RegKey1 ) != ERROR_SUCCESS) + return; + if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, Buffer2, 0, KEY_WRITE, &RegKey2 ) != ERROR_SUCCESS) { + RegCloseKey( RegKey1 ); + return; + } + + + if( new_lease->options[DHO_DOMAIN_NAME].len ) { + DH_DbgPrint(MID_TRACE,("Setting DhcpDomain: %s\n", new_lease->options[DHO_DOMAIN_NAME].data)); + + RegSetValueExA( RegKey1, "DhcpDomain", 0, REG_SZ, + (LPBYTE)new_lease->options[DHO_DOMAIN_NAME].data, new_lease->options[DHO_DOMAIN_NAME].len ); + RegSetValueExA( RegKey2, "DhcpDomain", 0, REG_SZ, + (LPBYTE)new_lease->options[DHO_DOMAIN_NAME].data, new_lease->options[DHO_DOMAIN_NAME].len ); + } else { + RegDeleteValueW( RegKey1, L"DhcpDomain" ); + RegDeleteValueW( RegKey2, L"DhcpDomain" ); + } + + RegCloseKey( RegKey1 ); + RegCloseKey( RegKey2 ); + +} + void setup_adapter( PDHCP_ADAPTER Adapter, struct client_lease *new_lease ) { CHAR Buffer[200] = "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces\\"; struct iaddr netmask; @@ -569,6 +600,7 @@ return; } set_name_servers( Adapter, new_lease ); + set_domain( Adapter, new_lease ); } /* Index: dll/win32/CMakeLists.txt =================================================================== --- dll/win32/CMakeLists.txt (revision 72669) +++ dll/win32/CMakeLists.txt (working copy) @@ -246,7 +246,7 @@ add_subdirectory(wmi) add_subdirectory(wmiutils) add_subdirectory(wmvcore) -add_subdirectory(ws2_32) +#add_subdirectory(ws2_32) add_subdirectory(ws2_32_new) add_subdirectory(ws2help) add_subdirectory(wshirda) Index: dll/win32/dnsapi/dnsapi/query.c =================================================================== --- dll/win32/dnsapi/dnsapi/query.c (revision 72669) +++ dll/win32/dnsapi/dnsapi/query.c (working copy) @@ -53,7 +53,7 @@ PVOID *Reserved) { adns_state astate; - int quflags = 0; + int quflags = adns_qf_search; int adns_error; adns_answer *answer; LPSTR CurrentName; Index: dll/win32/iphlpapi/icmp.c =================================================================== --- dll/win32/iphlpapi/icmp.c (revision 72669) +++ dll/win32/iphlpapi/icmp.c (working copy) @@ -114,8 +114,18 @@ HANDLE WINAPI Icmp6CreateFile(VOID) { icmp_t* icp; + int sid; +#ifdef __REACTOS__ + WSADATA wsaData; - int sid=socket(AF_INET6,SOCK_RAW,IPPROTO_ICMPV6); + if (WSAStartup(MAKEWORD(2, 2), &wsaData) != ERROR_SUCCESS) + { + ERR_(winediag)("Failed to use ICMPV6 (network ping), this requires special permissions.\n"); + return INVALID_HANDLE_VALUE; + } +#endif + + sid=socket(AF_INET6,SOCK_RAW,IPPROTO_ICMPV6); #ifndef __REACTOS__ if (sid < 0) { @@ -133,6 +143,7 @@ if (icp==NULL) { #ifdef __REACTOS__ closesocket(sid); + WSACleanup(); #else close(sid); #endif @@ -180,8 +191,17 @@ static int once; #endif icmp_t* icp; + int sid; +#ifdef __REACTOS__ + WSADATA wsaData; - int sid=socket(AF_INET,SOCK_RAW,IPPROTO_ICMP); + if (WSAStartup(MAKEWORD(2, 2), &wsaData) != ERROR_SUCCESS) + { + ERR_(winediag)("Failed to use ICMPV6 (network ping), this requires special permissions.\n"); + return INVALID_HANDLE_VALUE; + } +#endif + sid=socket(AF_INET,SOCK_RAW,IPPROTO_ICMP); #ifdef __REACTOS__ if (sid < 0) { ERR_(winediag)("Failed to use ICMP (network ping), this requires special permissions.\n"); @@ -204,6 +224,7 @@ if (icp==NULL) { #ifdef __REACTOS__ closesocket(sid); + WSACleanup(); #else if (sid >= 0) close(sid); #endif @@ -235,6 +256,9 @@ if (icp->sid >= 0) close(icp->sid); #endif HeapFree(GetProcessHeap (), 0, icp); +#ifdef __REACTOS__ + WSACleanup(); +#endif return TRUE; } Index: dll/win32/iphlpapi/iphlpapi_main.c =================================================================== --- dll/win32/iphlpapi/iphlpapi_main.c (revision 72669) +++ dll/win32/iphlpapi/iphlpapi_main.c (working copy) @@ -35,17 +35,13 @@ BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) { - WSADATA wsaData; - switch (fdwReason) { case DLL_PROCESS_ATTACH: DisableThreadLibraryCalls( hinstDLL ); interfaceMapInit(); - WSAStartup(MAKEWORD(2, 2), &wsaData); break; case DLL_PROCESS_DETACH: - WSACleanup(); interfaceMapFree(); break; } Index: dll/win32/kernel32/client/compname.c =================================================================== --- dll/win32/kernel32/client/compname.c (revision 72669) +++ dll/win32/kernel32/client/compname.c (working copy) @@ -137,6 +137,7 @@ NTSTATUS Status; BOOL ret = TRUE; DWORD HostSize; + DWORD nBufferSize; if ((nSize == NULL) || (lpBuffer == NULL && *nSize > 0)) @@ -155,11 +156,28 @@ nSize); case ComputerNameDnsDomain: - return GetComputerNameFromRegistry(L"\\Registry\\Machine\\System\\CurrentControlSet" - L"\\Services\\Tcpip\\Parameters", - L"Domain", - lpBuffer, - nSize); + /* Save original buffer size for the second call if neccessery */ + nBufferSize = *nSize; + if (!GetComputerNameFromRegistry(L"\\Registry\\Machine\\System\\CurrentControlSet" + L"\\Services\\Tcpip\\Parameters", + L"DhcpDomain", + lpBuffer, + nSize)) + { + DPRINT1("GetComputerNameFromRegistry(ComputerNameDnsDomain) DhcpDomain: %ld %ld %ld\n", nBufferSize, *nSize, GetLastError()); + /* The value is there, just the buffer is insufficient in length */ + if (GetLastError() == ERROR_MORE_DATA) + return FALSE; + /* Restore original buffer size for the second call */ + *nSize = nBufferSize; + return GetComputerNameFromRegistry(L"\\Registry\\Machine\\System\\CurrentControlSet" + L"\\Services\\Tcpip\\Parameters", + L"Domain", + lpBuffer, + nSize); + } + else + return TRUE; case ComputerNameDnsFullyQualified: ResultString.Length = 0; @@ -195,7 +213,7 @@ RtlFreeUnicodeString(&DomainPart); RtlInitUnicodeString(&DomainPart, NULL); - QueryTable[0].Name = L"Domain"; + QueryTable[0].Name = L"DhcpDomain"; QueryTable[0].Flags = RTL_QUERY_REGISTRY_DIRECT; QueryTable[0].EntryContext = &DomainPart; @@ -207,7 +225,7 @@ NULL, NULL); - if (NT_SUCCESS(Status)) + if (NT_SUCCESS(Status) && DomainPart.Buffer != NULL && wcslen(DomainPart.Buffer) > 0) { Status = RtlAppendUnicodeStringToString(&ResultString, &DomainPart); if ((!NT_SUCCESS(Status)) || (!ret)) @@ -221,6 +239,36 @@ *nSize = ResultString.Length / sizeof(WCHAR) - 1; return TRUE; } + else + { + RtlInitUnicodeString(&DomainPart, NULL); + QueryTable[0].Name = L"Domain"; + QueryTable[0].Flags = RTL_QUERY_REGISTRY_DIRECT; + QueryTable[0].EntryContext = &DomainPart; + + Status = RtlQueryRegistryValues(RTL_REGISTRY_ABSOLUTE, + L"\\Registry\\Machine\\System" + L"\\CurrentControlSet\\Services\\Tcpip" + L"\\Parameters", + QueryTable, + NULL, + NULL); + + if (NT_SUCCESS(Status)) + { + Status = RtlAppendUnicodeStringToString(&ResultString, &DomainPart); + if ((!NT_SUCCESS(Status)) || (!ret)) + { + *nSize = HostSize + DomainPart.Length; + SetLastError(ERROR_MORE_DATA); + RtlFreeUnicodeString(&DomainPart); + return FALSE; + } + RtlFreeUnicodeString(&DomainPart); + *nSize = ResultString.Length / sizeof(WCHAR) - 1; + return TRUE; + } + } } return FALSE; @@ -232,11 +280,9 @@ nSize); case ComputerNamePhysicalDnsDomain: - return GetComputerNameFromRegistry(L"\\Registry\\Machine\\System\\CurrentControlSet" - L"\\Services\\Tcpip\\Parameters", - L"Domain", - lpBuffer, - nSize); + return GetComputerNameExW(ComputerNameDnsDomain, + lpBuffer, + nSize); /* XXX Redo these */ case ComputerNamePhysicalDnsFullyQualified: Index: dll/win32/msafd/CMakeLists.txt =================================================================== --- dll/win32/msafd/CMakeLists.txt (revision 72669) +++ dll/win32/msafd/CMakeLists.txt (working copy) @@ -19,6 +19,6 @@ set_module_type(msafd win32dll UNICODE) target_link_libraries(msafd wine) -add_importlibs(msafd advapi32 msvcrt kernel32 ntdll) +add_importlibs(msafd advapi32 msvcrt kernel32 ws2_32 ntdll) add_pch(msafd msafd.h SOURCE) add_cd_file(TARGET msafd DESTINATION reactos/system32 FOR all) Index: dll/win32/msafd/misc/dllmain.c =================================================================== --- dll/win32/msafd/misc/dllmain.c (revision 72669) +++ dll/win32/msafd/misc/dllmain.c (working copy) @@ -13,6 +13,7 @@ #include #include +#include #include WINE_DEFAULT_DEBUG_CHANNEL(msafd); @@ -19,6 +20,7 @@ HANDLE GlobalHeap; WSPUPCALLTABLE Upcalls; +DWORD CatalogEntryId; /* CatalogEntryId for upcalls */ LPWPUCOMPLETEOVERLAPPEDREQUEST lpWPUCompleteOverlappedRequest; PSOCKET_INFORMATION SocketListHead = NULL; CRITICAL_SECTION SocketListLock; @@ -72,6 +74,22 @@ TRACE("Creating Socket, getting TDI Name - AddressFamily (%d) SocketType (%d) Protocol (%d).\n", AddressFamily, SocketType, Protocol); + if (AddressFamily == AF_UNSPEC && SocketType == 0 && Protocol == 0) + return WSAEINVAL; + + /* Set the defaults */ + if (AddressFamily == AF_UNSPEC) + AddressFamily = AF_INET; + if (SocketType == 0) + SocketType = SOCK_STREAM; + if (Protocol == 0) + { + if (SocketType == SOCK_STREAM) + Protocol = IPPROTO_TCP; + if (SocketType == SOCK_DGRAM) + Protocol = IPPROTO_UDP; + } + /* Get Helper Data and Transport */ Status = SockGetTdiName (&AddressFamily, &SocketType, @@ -2207,7 +2225,8 @@ return 0; default: - break; + *lpErrno = WSAEINVAL; + return SOCKET_ERROR; } SendToHelper: @@ -2244,8 +2263,13 @@ /* FIXME: We should handle some more cases here */ - if (level == SOL_SOCKET) + if (level != SOL_SOCKET) { + *lpErrno = WSAEINVAL; + return SOCKET_ERROR; + } + else + { switch (optname) { case SO_BROADCAST: @@ -2364,6 +2388,7 @@ * lpProcTable = Address of procedure table to initialize * RETURNS: * Status of operation + * @IMPLEMENT */ INT WSPAPI @@ -2376,8 +2401,14 @@ { NTSTATUS Status; - ERR("wVersionRequested (0x%X) \n", wVersionRequested); - Status = NO_ERROR; + if (((LOBYTE(wVersionRequested) == 2) && (HIBYTE(wVersionRequested) < 2)) || (LOBYTE(wVersionRequested) < 2)) + { + ERR("WSPStartup NOT SUPPORTED for version 0x%X\n", wVersionRequested); + return WSAVERNOTSUPPORTED; + } + else + Status = NO_ERROR; + /* FIXME: Enable all cases of WSPStartup status */ Upcalls = UpcallTable; if (Status == NO_ERROR) @@ -2414,6 +2445,8 @@ lpProcTable->lpWSPStringToAddress = WSPStringToAddress; lpWSPData->wVersion = MAKEWORD(2, 2); lpWSPData->wHighVersion = MAKEWORD(2, 2); + /* Save CatalogEntryId for all upcalls */ + CatalogEntryId = lpProtocolInfo->dwCatalogEntryId; } TRACE("Status (%d).\n", Status); @@ -2421,6 +2454,144 @@ } +INT +WSPAPI +WSPAddressToString( + IN LPSOCKADDR lpsaAddress, + IN DWORD dwAddressLength, + IN LPWSAPROTOCOL_INFOW lpProtocolInfo, + OUT LPWSTR lpszAddressString, + IN OUT LPDWORD lpdwAddressStringLength, + OUT LPINT lpErrno) +{ + DWORD size; + WCHAR buffer[54]; /* 32 digits + 7':' + '[' + '%" + 5 digits + ']:' + 5 digits + '\0' */ + WCHAR *p; + + if (!lpsaAddress || !lpszAddressString || !lpdwAddressStringLength) + { + *lpErrno = WSAEFAULT; + return SOCKET_ERROR; + } + + switch (lpsaAddress->sa_family) + { + case AF_INET: + if (dwAddressLength < sizeof(SOCKADDR_IN)) + { + *lpErrno = WSAEINVAL; + return SOCKET_ERROR; + } + swprintf(buffer, L"%u.%u.%u.%u:%u", + (unsigned int)(ntohl(((SOCKADDR_IN *)lpsaAddress)->sin_addr.s_addr) >> 24 & 0xff), + (unsigned int)(ntohl(((SOCKADDR_IN *)lpsaAddress)->sin_addr.s_addr) >> 16 & 0xff), + (unsigned int)(ntohl(((SOCKADDR_IN *)lpsaAddress)->sin_addr.s_addr) >> 8 & 0xff), + (unsigned int)(ntohl(((SOCKADDR_IN *)lpsaAddress)->sin_addr.s_addr) & 0xff), + ntohs(((SOCKADDR_IN *)lpsaAddress)->sin_port)); + + p = wcschr(buffer, L':'); + if (!((SOCKADDR_IN *)lpsaAddress)->sin_port) *p = 0; + break; + default: + *lpErrno = WSAEINVAL; + return SOCKET_ERROR; + } + + size = wcslen(buffer) + 1; + + if (*lpdwAddressStringLength < size) + { + *lpdwAddressStringLength = size; + *lpErrno = WSAENOBUFS; + return SOCKET_ERROR; + } + + *lpdwAddressStringLength = size; + wcscpy(lpszAddressString, buffer); + return 0; +} + +INT +WSPAPI +WSPStringToAddress( + IN LPWSTR AddressString, + IN INT AddressFamily, + IN LPWSAPROTOCOL_INFOW lpProtocolInfo, + OUT LPSOCKADDR lpAddress, + IN OUT LPINT lpAddressLength, + OUT LPINT lpErrno) +{ + int pos = 0; + LONG inetaddr = 0; + LPWSTR *bp = NULL; + SOCKADDR_IN *sockaddr; + + if (!lpAddressLength || !lpAddress || !AddressString) + { + *lpErrno = WSAEINVAL; + return SOCKET_ERROR; + } + + sockaddr = (SOCKADDR_IN *)lpAddress; + + /* Set right adress family */ + if (lpProtocolInfo != NULL) + sockaddr->sin_family = lpProtocolInfo->iAddressFamily; + else + sockaddr->sin_family = AddressFamily; + + /* Report size */ + if (AddressFamily == AF_INET) + { + if (*lpAddressLength < (INT)sizeof(SOCKADDR_IN)) + { + *lpAddressLength = sizeof(SOCKADDR_IN); + *lpErrno = WSAEFAULT; + } + else + { + // translate ip string to ip + + /* rest sockaddr.sin_addr.s_addr + for we need to be sure it is zero when we come to while */ + memset(lpAddress, 0, sizeof(SOCKADDR_IN)); + + /* Set right adress family */ + sockaddr->sin_family = AF_INET; + + /* Get port number */ + pos = wcscspn(AddressString, L":") + 1; + + if (pos < (int)wcslen(AddressString)) + sockaddr->sin_port = wcstol(&AddressString[pos], + bp, + 10); + + else + sockaddr->sin_port = 0; + + /* Get ip number */ + pos = 0; + inetaddr = 0; + + while (pos < (int)wcslen(AddressString)) + { + inetaddr = (inetaddr << 8) + ((UCHAR)wcstol(&AddressString[pos], + bp, + 10)); + pos += wcscspn(&AddressString[pos], L".") + 1; + } + + *lpErrno = 0; + sockaddr->sin_addr.s_addr = inetaddr; + + } + } + + if (!*lpErrno) return 0; + return SOCKET_ERROR; +} + /* * FUNCTION: Cleans up service provider for a client * ARGUMENTS: Index: dll/win32/msafd/misc/stubs.c =================================================================== --- dll/win32/msafd/misc/stubs.c (revision 72669) +++ dll/win32/msafd/misc/stubs.c (working copy) @@ -15,22 +15,6 @@ INT WSPAPI -WSPAddressToString( - IN LPSOCKADDR lpsaAddress, - IN DWORD dwAddressLength, - IN LPWSAPROTOCOL_INFOW lpProtocolInfo, - OUT LPWSTR lpszAddressString, - IN OUT LPDWORD lpdwAddressStringLength, - OUT LPINT lpErrno) -{ - UNIMPLEMENTED; - - return SOCKET_ERROR; -} - - -INT -WSPAPI WSPCancelBlockingCall( OUT LPINT lpErrno) { @@ -102,19 +86,4 @@ return (SOCKET)0; } -INT -WSPAPI -WSPStringToAddress( - IN LPWSTR AddressString, - IN INT AddressFamily, - IN LPWSAPROTOCOL_INFOW lpProtocolInfo, - OUT LPSOCKADDR lpAddress, - IN OUT LPINT lpAddressLength, - OUT LPINT lpErrno) -{ - UNIMPLEMENTED; - - return SOCKET_ERROR; -} - /* EOF */ Index: dll/win32/mswsock/CMakeLists.txt =================================================================== --- dll/win32/mswsock/CMakeLists.txt (revision 72669) +++ dll/win32/mswsock/CMakeLists.txt (working copy) @@ -5,6 +5,8 @@ list(APPEND SOURCE extensions.c + mswhelper.c + nsplookup.c stubs.c precomp.h) @@ -13,7 +15,7 @@ mswsock.rc ${CMAKE_CURRENT_BINARY_DIR}/mswsock.def) -set_module_type(mswsock win32dll UNICODE) -add_importlibs(mswsock ws2_32 msvcrt kernel32) +set_module_type(mswsock win32dll) +add_importlibs(mswsock ws2_32 dnsapi msvcrt kernel32) add_pch(mswsock precomp.h SOURCE) add_cd_file(TARGET mswsock DESTINATION reactos/system32 FOR all) Index: dll/win32/mswsock/mswhelper.c =================================================================== --- dll/win32/mswsock/mswhelper.c (revision 0) +++ dll/win32/mswsock/mswhelper.c (working copy) @@ -0,0 +1,535 @@ +#include "precomp.h" + +#include +#include +#include +#include "sal.h" + +#include "mswhelper.h" + +#define MSW_BUFSIZE 512 +#define MAX_ARRAY_SIZE 5 + +void mswBufferInit( + _Inout_ PMSW_BUFFER mswBuf, + _In_ BYTE* buffer, + _In_ DWORD bufferSize) +{ + RtlZeroMemory(mswBuf,sizeof(*mswBuf)); + RtlZeroMemory(buffer,bufferSize); + mswBuf->bytesMax = bufferSize; + mswBuf->buffer = buffer; + mswBuf->bufendptr = buffer; + mswBuf->bufok = TRUE; +} + +BOOL mswBufferCheck( + _Inout_ PMSW_BUFFER mswBuf, + _In_ DWORD count) +{ + if (mswBuf->bytesUsed + count <= mswBuf->bytesMax) + return TRUE; + + mswBuf->bufok = FALSE; + return FALSE; +} + +BOOL mswBufferIncUsed( + _Inout_ PMSW_BUFFER mswBuf, + _In_ DWORD count) +{ + if (!mswBufferCheck(mswBuf, count)) + return FALSE; + mswBuf->bytesUsed += count; + mswBuf->bufendptr += count; + return TRUE; +} + +inline BYTE* mswBufferEndPtr( + _Inout_ PMSW_BUFFER mswBuf) +{ + return mswBuf->bufendptr; +} + +BOOL mswBufferAppend( + _Inout_ PMSW_BUFFER mswBuf, + _In_ void *dataToAppend, + _In_ DWORD dataSize) +{ + if (!mswBufferCheck(mswBuf, dataSize)) + return FALSE; + + RtlCopyMemory(mswBuf->bufendptr,dataToAppend,dataSize); + mswBuf->bytesUsed += dataSize; + mswBuf->bufendptr += dataSize; + + return TRUE; +} + +BOOL mswBufferAppendStrA( + _Inout_ PMSW_BUFFER mswBuf, + _In_ char* str) +{ + return mswBufferAppend(mswBuf,str,strlen(str)+sizeof(char)); +} + +BOOL mswBufferAppendStrW( + _Inout_ PMSW_BUFFER mswBuf, + _In_ WCHAR* str) +{ + int bytelen; + bytelen = (wcslen(str) + 1) * sizeof(WCHAR); + return mswBufferAppend(mswBuf,str,bytelen); +} + +BOOL mswBufferAppendPtr( + _Inout_ PMSW_BUFFER mswBuf, + _In_ void* ptr) +{ + return mswBufferAppend(mswBuf,&ptr,sizeof(ptr)); +} + +/* lst = pointer to pointer of items + + *lst[0] = 1st item + *lst[1] = 2nd item + ... + lst[n] = NULL = End of List + + itemLength = data in Bytes for each item. + + ptrofs = delta relative to mswBuf.buffer +*/ +BOOL mswBufferAppendLst( + _Inout_ PMSW_BUFFER mswBuf, + _In_ void **lst, + _In_ DWORD itemByteLength, + _In_opt_ int ptrofs) +{ + DWORD lstItemCount; + DWORD lstByteSize; + DWORD lstDataPos; + DWORD i1; + UINT_PTR *ptrSrcLstPos; + + /* calculate size of list */ + ptrSrcLstPos = (UINT_PTR*)lst; + lstItemCount = 0; + while (*ptrSrcLstPos != (UINT_PTR)NULL) + { + lstItemCount++; + ptrSrcLstPos++; + } + + lstByteSize = + /* item-pointer + null-ptr (for end) */ + ( (lstItemCount + 1) * sizeof(UINT_PTR) ) + + /* item-data */ + ( lstItemCount * itemByteLength ); + + if (mswBuf->bytesUsed + lstByteSize > mswBuf->bytesMax) + return FALSE; + + /* calculate position for the data of the first item */ + lstDataPos = + ( (lstItemCount + 1) * sizeof(UINT_PTR) ) + + (DWORD)mswBufferEndPtr(mswBuf); + /* add ptrofs */ + lstDataPos += ptrofs; + + /* write array of Pointer to data */ + for (i1 = 0; i1 < lstItemCount; i1++) + { + if (!mswBufferAppendPtr(mswBuf,(void*)lstDataPos)) + return FALSE; + lstDataPos += sizeof(UINT_PTR); + } + /* end of list */ + if (!mswBufferAppendPtr(mswBuf,NULL)) + return FALSE; + + /* write data */ + ptrSrcLstPos = (UINT_PTR*)lst; + for (i1 = 0; i1 < lstItemCount; i1++) + { + mswBufferAppend(mswBuf,*(BYTE**)ptrSrcLstPos,itemByteLength); + ptrSrcLstPos++; + } + return mswBuf->bufok; +} + +BOOL mswBufferAppendStrLstA( + _Inout_ PMSW_BUFFER mswBuf, + _In_ void **lst, + _In_opt_ int ptrofs) +{ + DWORD lstItemLen[MAX_ARRAY_SIZE]; + DWORD lstItemCount; + DWORD lstByteSize; + DWORD lstDataPos; + DWORD lstDataSize; + DWORD i1; + UINT_PTR *ptrSrcLstPos; + + /* calculate size of list */ + ptrSrcLstPos = (UINT_PTR*)lst; + lstItemCount = 0; + lstDataSize = 0; + while (*ptrSrcLstPos != (UINT_PTR)NULL) + { + if (lstItemCount >= MAX_ARRAY_SIZE) + return FALSE; + i1 = strlen((char*)*ptrSrcLstPos)+sizeof(char); + lstItemLen[lstItemCount] = i1; + lstItemCount++; + lstDataSize += i1; + ptrSrcLstPos++; + } + + lstByteSize = + /* item-pointer + null-ptr (for end) */ + ( (lstItemCount + 1) * sizeof(UINT_PTR) ) + + /* item-data */ + lstDataSize; + + if (mswBuf->bytesUsed + lstByteSize > mswBuf->bytesMax) + return FALSE; + + /* calculate position for the data of the first item */ + lstDataPos = + ( (lstItemCount + 1) * sizeof(UINT_PTR) ) + + (DWORD)mswBufferEndPtr(mswBuf); + /* add ptrofs */ + lstDataPos += ptrofs; + + for (i1 = 0; i1 < lstItemCount; i1++) + { + if (!mswBufferAppendPtr(mswBuf,(void*)lstDataPos)) + return FALSE; + lstDataPos += lstItemLen[i1]; + } + /* end of list */ + if (!mswBufferAppendPtr(mswBuf,NULL)) + return FALSE; + + /* write data */ + ptrSrcLstPos = (UINT_PTR*)lst; + for (i1 = 0; i1 < lstItemCount; i1++) + { + if (!mswBufferAppendStrA(mswBuf,*(char**)ptrSrcLstPos)) + return FALSE; + ptrSrcLstPos++; + } + return mswBuf->bufok; +} + +BOOL mswBufferAppendBlob_Hostent( + _Inout_ PMSW_BUFFER mswBuf, + _Inout_ LPWSAQUERYSETW lpRes, + _In_ char* hostnameA, + _In_ DWORD ip4addr) +{ + PHOSTENT phe; + void* lst[2]; + BYTE* bytesOfs; + + /* blob */ + lpRes->lpBlob = (LPBLOB)mswBufferEndPtr(mswBuf); + if(!mswBufferIncUsed(mswBuf,sizeof(*lpRes->lpBlob))) return FALSE; + + /* cbSize will be set later */ + lpRes->lpBlob->cbSize = 0; + lpRes->lpBlob->pBlobData = mswBufferEndPtr(mswBuf); + + /* hostent */ + phe = (PHOSTENT)lpRes->lpBlob->pBlobData; + bytesOfs = mswBufferEndPtr(mswBuf); + if(!mswBufferIncUsed(mswBuf,sizeof(*phe))) return FALSE; + + phe->h_addrtype = AF_INET; + phe->h_length = 4; /* 4 Byte (IPv4) */ + + /* aliases */ + phe->h_aliases = (char**)(mswBufferEndPtr(mswBuf) - bytesOfs); + if(!mswBufferAppendPtr(mswBuf,NULL)) return FALSE; + + /* addr_list */ + RtlZeroMemory(lst,sizeof(lst)); + if (ip4addr != 0) + lst[0] = (void*)&ip4addr; + phe->h_addr_list = (char**)(mswBufferEndPtr(mswBuf) - bytesOfs); + if(!mswBufferAppendLst(mswBuf,lst,4,-(DWORD)bytesOfs)) return FALSE; + + /* name */ + phe->h_name = (char*)(mswBufferEndPtr(mswBuf) - bytesOfs); + if(!mswBufferAppendStrA(mswBuf,hostnameA)) return FALSE; + + lpRes->lpBlob->cbSize = (DWORD)(mswBufferEndPtr(mswBuf) - bytesOfs); + return mswBuf->bufok; +} + +BOOL mswBufferAppendBlob_Servent( + _Inout_ PMSW_BUFFER mswBuf, + _Inout_ LPWSAQUERYSETW lpRes, + _In_ char* serviceNameA, + _In_ char** serviceAliasesA, + _In_ char* protocolNameA, + _In_ WORD port) +{ + PSERVENT pse; + BYTE* bytesOfs; + + /* blob */ + lpRes->lpBlob = (LPBLOB)mswBufferEndPtr(mswBuf); + if(!mswBufferIncUsed(mswBuf,sizeof(*lpRes->lpBlob))) return FALSE; + + lpRes->lpBlob->cbSize = 0;//later + lpRes->lpBlob->pBlobData = mswBufferEndPtr(mswBuf); + + /* servent */ + pse = (LPSERVENT)lpRes->lpBlob->pBlobData; + bytesOfs = mswBufferEndPtr(mswBuf); + if(!mswBufferIncUsed(mswBuf,sizeof(*pse))) return FALSE; + + pse->s_aliases = (char**)(mswBufferEndPtr(mswBuf) - bytesOfs); + if(!mswBufferAppendStrLstA(mswBuf, + (void**)serviceAliasesA, + -(DWORD)bytesOfs)) return FALSE; + + pse->s_name = (char*)(mswBufferEndPtr(mswBuf) - bytesOfs); + if(!mswBufferAppendStrA(mswBuf,serviceNameA)) return FALSE; + + pse->s_port = htons(port); + + pse->s_proto = (char*)(mswBufferEndPtr(mswBuf) - bytesOfs); + if(!mswBufferAppendStrA(mswBuf,protocolNameA)) return FALSE; + + lpRes->lpBlob->cbSize = (DWORD)(mswBufferEndPtr(mswBuf) - bytesOfs); + return mswBuf->bufok; +} + +BOOL mswBufferAppendAddr_AddrInfoW( + _Inout_ PMSW_BUFFER mswBuf, + _Inout_ LPWSAQUERYSETW lpRes, + _In_ DWORD ip4addr) +{ + LPCSADDR_INFO paddrinfo; + LPSOCKADDR_IN psa; + + lpRes->dwNumberOfCsAddrs = 1; + lpRes->lpcsaBuffer = (LPCSADDR_INFO)mswBufferEndPtr(mswBuf); + + paddrinfo = lpRes->lpcsaBuffer; + if(!mswBufferIncUsed(mswBuf,sizeof(*paddrinfo))) return FALSE; + + paddrinfo->LocalAddr.lpSockaddr = (LPSOCKADDR)mswBufferEndPtr(mswBuf); + if(!mswBufferIncUsed(mswBuf,sizeof(*paddrinfo->LocalAddr.lpSockaddr))) return FALSE; + + paddrinfo->RemoteAddr.lpSockaddr = (LPSOCKADDR)mswBufferEndPtr(mswBuf); + if(!mswBufferIncUsed(mswBuf,sizeof(*paddrinfo->RemoteAddr.lpSockaddr))) return FALSE; + + paddrinfo->iSocketType = SOCK_DGRAM; + paddrinfo->iProtocol = IPPROTO_UDP; + + psa = (LPSOCKADDR_IN)paddrinfo->LocalAddr.lpSockaddr; + paddrinfo->LocalAddr.iSockaddrLength = sizeof(*psa); + psa->sin_family = AF_INET; + psa->sin_port = 0; + psa->sin_addr.s_addr = 0; + RtlZeroMemory(psa->sin_zero,sizeof(psa->sin_zero)); + + psa = (LPSOCKADDR_IN)paddrinfo->RemoteAddr.lpSockaddr; + paddrinfo->RemoteAddr.iSockaddrLength = sizeof(*psa); + psa->sin_family = AF_INET; + psa->sin_port = 0; + psa->sin_addr.s_addr = ip4addr; + RtlZeroMemory(psa->sin_zero,sizeof(psa->sin_zero)); + + return TRUE; +} + +/* ansicode <-> unicode */ +WCHAR* StrA2WHeapAlloc( + _In_opt_ HANDLE hHeap, + _In_ char* aStr) +{ + int aStrByteLen; + int wStrByteLen; + int charLen; + int ret; + WCHAR* wStr; + + if (aStr == NULL) + return NULL; + charLen = strlen(aStr) + 1; + + aStrByteLen = (charLen * sizeof(char)); + wStrByteLen = (charLen * sizeof(WCHAR)); + if (hHeap == 0) + hHeap = GetProcessHeap(); + wStr = HeapAlloc(hHeap,0,wStrByteLen); + if (wStr == NULL) + { + HeapFree(hHeap, 0, wStr); + return NULL; + } + + ret = MultiByteToWideChar(1252, + 0, + aStr, + aStrByteLen, + wStr, + charLen); + + if (ret != charLen) + { + HeapFree(hHeap, 0, wStr); + return NULL; + } + return wStr; +} + +char* StrW2AHeapAlloc( + _In_opt_ HANDLE hHeap, + _In_ WCHAR* wStr) +{ + int charLen; + int aStrByteLen; + int ret; + char* aStr; + + if (wStr == NULL) + return NULL; + charLen = wcslen(wStr) + 1; + + aStrByteLen = (charLen * sizeof(char)); + if (hHeap == 0) + hHeap = GetProcessHeap(); + aStr = HeapAlloc(hHeap,0,aStrByteLen); + if (aStr == NULL) + { + HeapFree(hHeap, 0, aStr); + return NULL; + } + + ret = WideCharToMultiByte(1252, + 0, + wStr, + charLen, + aStr, + aStrByteLen, + NULL, + NULL); + if (ret != aStrByteLen) + { + HeapFree(hHeap, 0, aStr); + return NULL; + } + return aStr; +} + +WCHAR* StrCpyHeapAllocW( + _In_opt_ HANDLE hHeap, + _In_ WCHAR* wStr) +{ + int chLen; + int bLen; + WCHAR* resW; + + if (wStr == NULL) + return NULL; + + if (hHeap == 0) + hHeap = GetProcessHeap(); + chLen = wcslen(wStr); + + bLen = (chLen + 1) * sizeof(WCHAR); + + resW = HeapAlloc(hHeap, 0, bLen); + RtlCopyMemory(resW,wStr,bLen); + return resW; +} + +char* StrCpyHeapAllocA( + _In_opt_ HANDLE hHeap, + _In_ char* aStr) +{ + int chLen; + int bLen; + char* resA; + + if (aStr == NULL) + return NULL; + + if (hHeap == 0) + hHeap = GetProcessHeap(); + chLen = strlen(aStr); + + bLen = (chLen + 1) * sizeof(char); + + resA = HeapAlloc(hHeap, 0, bLen); + RtlCopyMemory(resA,aStr,bLen); + return resA; +} + +char** StrAryCpyHeapAllocA( + _In_opt_ HANDLE hHeap, + _In_ char** aStrAry) +{ + char** aSrcPtr; + char** aDstPtr; + char* aDstNextStr; + DWORD aStrByteLen[MAX_ARRAY_SIZE]; + int bLen; + int bItmLen; + int aCount; + int i1; + char** resA; + + if (hHeap == 0) + hHeap = GetProcessHeap(); + + /* Calculating size of array ... */ + aSrcPtr = aStrAry; + bLen = 0; + aCount = 0; + while (*aSrcPtr != NULL) + { + if (aCount >= MAX_ARRAY_SIZE) + return NULL; + + bItmLen = (strlen(*aSrcPtr) + 1) * sizeof(char); + aStrByteLen[aCount] = bItmLen; + + bLen += sizeof(*aSrcPtr) + bItmLen; + + aSrcPtr++; + aCount++; + } + /* size for NULL-terminator */ + bLen += sizeof(*aSrcPtr); + + /* get memory */ + resA = HeapAlloc(hHeap, 0, bLen); + + /* copy data */ + aSrcPtr = aStrAry; + aDstPtr = resA; + /* pos for the first string */ + aDstNextStr = (char*)(resA + aCount + 1); + for (i1 = 0; i1 < aCount; i1++) + { + bItmLen = aStrByteLen[i1]; + + *aDstPtr = aDstNextStr; + RtlCopyMemory(*aDstPtr,*aSrcPtr,bItmLen); + + aDstNextStr = (char*)((DWORD)aDstNextStr + (DWORD)bItmLen); + aDstPtr++; + aSrcPtr++; + } + /* terminate with NULL */ + *aDstPtr = NULL; + + return resA; +} Index: dll/win32/mswsock/mswhelper.h =================================================================== --- dll/win32/mswsock/mswhelper.h (revision 0) +++ dll/win32/mswsock/mswhelper.h (working copy) @@ -0,0 +1,95 @@ +#ifndef _MSWHELPER_H +#define _MSWHELPER_H + +#include + +typedef struct +{ + DWORD bytesUsed; + DWORD bytesMax; + BYTE* buffer; + // Pointer to the first "unused" byte + BYTE* bufendptr; + // FALSE if on mswBuffer-Function fails + BOOL bufok; +} MSW_BUFFER, *PMSW_BUFFER; + +void mswBufferInit( + _Out_ PMSW_BUFFER mswBuf, + _In_ BYTE* buffer, + _In_ DWORD bufferSize); + +inline BOOL mswBufferCheck( + _Inout_ PMSW_BUFFER mswBuf, + _In_ DWORD count); + +BOOL mswBufferIncUsed( + _Inout_ PMSW_BUFFER mswBuf, + _In_ DWORD count); + +inline BYTE* mswBufferEndPtr( + _Inout_ PMSW_BUFFER mswBuf); + +BOOL mswBufferAppend( + _Inout_ PMSW_BUFFER mswBuf, + _In_ void *dataToAppend, + _In_ DWORD dataSize); + +BOOL mswBufferAppendStrA( + _Inout_ PMSW_BUFFER mswBuf, + _In_ char* str); +BOOL mswBufferAppendStrW( + _Inout_ PMSW_BUFFER mswBuf, + _In_ WCHAR* str); + +BOOL mswBufferAppendPtr( + _Inout_ PMSW_BUFFER mswBuf, + _In_ void* ptr); + +BOOL mswBufferAppendLst( + _Inout_ PMSW_BUFFER mswBuf, + _In_ void **lst, + _In_ DWORD itemByteLength, + _In_opt_ int deltaofs); +BOOL mswBufferAppendStrLstA( + _Inout_ PMSW_BUFFER mswBuf, + _In_ void **lst, + _In_opt_ int ptrofs); +BOOL mswBufferAppendBlob_Hostent( + _Inout_ PMSW_BUFFER mswBuf, + _Inout_ LPWSAQUERYSETW lpRes, + _In_ char* hostnameA, + _In_ DWORD ip4addr); +BOOL mswBufferAppendBlob_Servent( + _Inout_ PMSW_BUFFER mswBuf, + _Inout_ LPWSAQUERYSETW lpRes, + _In_ char* serviceNameA, + _In_ char** serviceAliasesA, + _In_ char* protocolNameA, + _In_ WORD port); +BOOL mswBufferAppendAddr_AddrInfoW( + _Inout_ PMSW_BUFFER mswBuf, + _Inout_ LPWSAQUERYSETW lpRes, + _In_ DWORD ip4addr); + +WCHAR* StrA2WHeapAlloc( + _In_opt_ HANDLE hHeap, + _In_ char* aStr); +char* StrW2AHeapAlloc( + _In_opt_ HANDLE hHeap, + _In_ WCHAR* wStr); +WCHAR* StrCpyHeapAllocW( + _In_opt_ HANDLE hHeap, + _In_ WCHAR* wStr); +char* StrCpyHeapAllocA( + _In_opt_ HANDLE hHeap, + _In_ char* aStr); +/* strary: + ptr1 ... ptrn \0 + data1 ... datan +*/ +char** StrAryCpyHeapAllocA( + _In_opt_ HANDLE hHeap, + _In_ char** aStrAry); + +#endif // _MSWHELPER_H Index: dll/win32/mswsock/nsplookup.c =================================================================== --- dll/win32/mswsock/nsplookup.c (revision 0) +++ dll/win32/mswsock/nsplookup.c (working copy) @@ -0,0 +1,1207 @@ +#include "precomp.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "mswhelper.h" + +#define NSP_CALLID_DNS 0x0001 +#define NSP_CALLID_HOSTNAME 0x0002 +#define NSP_CALLID_HOSTBYNAME 0x0003 +#define NSP_CALLID_SERVICEBYNAME 0x0004 + +#ifndef BUFSIZ +#define BUFSIZ 1024 +#endif // BUFSIZ +#ifndef WS2_INTERNAL_MAX_ALIAS +#define WS2_INTERNAL_MAX_ALIAS 512 +#endif // WS2_INTERNAL_MAX_ALIAS + +//#define IP_LOCALHOST 0x0100007F + +//#define NSP_REDIRECT + +typedef struct +{ + WCHAR* hostnameW; + DWORD addr4; + + WCHAR* servnameW; + WCHAR* servprotoW; + CHAR** servaliasesA; /* array */ + WORD servport; +} WSHOSTINFOINTERN, *PWSHOSTINFOINTERN; + +typedef struct +{ + /* Provider-ID */ + GUID providerId; + /* dwControlFlags (WSALookupServiceBegin) */ + DWORD dwControlFlags; + + /* List for LookupServiceNext-Calls */ + DWORD CallID; + /* call-count of the current CallID. */ + DWORD CallIDCounter; + + /* hostbyname */ + WCHAR* hostnameW; + +#ifdef NSP_REDIRECT + HANDLE rdrLookup; + NSP_ROUTINE rdrproc; +#endif +} WSHANDLEINTERN, *PWSHANDLEINTERN; + +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; + +/* GUIDs - maybe they should be loaded from registry? */ +/* Namespace: 32 */ +static const GUID guid_mswsock_TcpIp = + { /*Data1:*/ 0x22059D40, + /*Data2:*/ 0x7E9E, + /*Data3:*/ 0x11CF, + /*Data4:*/ { 0xAE, 0x5A, 0x00, 0xAA, 0x00, 0xA7, 0x11, 0x2B } + }; + +/* {6642243A-3BA8-4AA6-BAA5-2E0BD71FDD83} */ +/* Namespace: 15 */ +static const GUID guid_mswsock_NLA = + { /*Data1:*/ 0x6642243A, + /*Data2:*/ 0x3BA8, + /*Data3:*/ 0x4AA6, + /*Data4:*/ { 0xBA, 0xA5, 0x2E, 0x0B, 0xD7, 0x1F, 0xDD, 0x83 } + }; + + +#ifdef NSP_REDIRECT +typedef INT (CALLBACK *lpRdrNSPStartup)( + LPGUID lpProviderId, + LPNSP_ROUTINE lpRout); +const rdrLib = "mswsock.dll-original"; +lpRdrNSPStartup rdrNSPStartup; +HANDLE hLib; +NSP_ROUTINE rdrproc_tcpip; +NSP_ROUTINE rdrproc_nla; +#endif + +/* Forwards */ +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 CallID, + _Inout_ LPWSAQUERYSETW lpRes, + _Inout_ LPDWORD lpResLen); +INT +NSP_GetHostNameHeapAllocW( + _Out_ WCHAR** hostname); +INT +NSP_GetHostByNameHeapAllocW( + _In_ WCHAR* name, + _In_ GUID* lpProviderId, + _Out_ PWSHOSTINFOINTERN hostinfo); +INT +NSP_GetServiceByNameHeapAllocW( + _In_ WCHAR* nameW, + _In_ GUID* lpProviderId, + _Out_ PWSHOSTINFOINTERN hostinfo); + +/* Implementations - Internal */ + +INT +WSAAPI +mwsNSPCleanUp( + _In_ LPGUID lpProviderId) +{ + //WSASetLastError(ERROR_CALL_NOT_IMPLEMENTED); + //return ERROR_CALL_NOT_IMPLEMENTED; + return ERROR_SUCCESS; +} + +INT +mwsNSPInit() +{ + return ERROR_SUCCESS; +} + +INT +WSAAPI +mwsNSPLookupServiceBegin( + _In_ LPGUID lpProviderId, + _In_ LPWSAQUERYSETW lpqsRestrictions, + _In_ LPWSASERVICECLASSINFOW lpServiceClassInfo, + _In_ DWORD dwControlFlags, + _Out_ LPHANDLE lphLookup) +{ + PWSHANDLEINTERN pLook; + int wsaErr; + + if (IsEqualGUID(lpProviderId,&guid_mswsock_TcpIp)) + { + //OK + } + else if (IsEqualGUID(lpProviderId,&guid_mswsock_NLA)) + { + WSASetLastError(WSASERVICE_NOT_FOUND); + return SOCKET_ERROR; + } + else return ERROR_CALL_NOT_IMPLEMENTED; + + + /* allocate internal structure */ + pLook = HeapAlloc(GetProcessHeap(),0,sizeof(WSHANDLEINTERN)); + if (!pLook) + { + WSASetLastError(WSAEFAULT); + return SOCKET_ERROR; + } + + *lphLookup = (HANDLE)pLook; + + RtlZeroMemory(pLook,sizeof(*pLook)); + /* Anyway the ControlFlags "should" be needed + in NSPLookupServiceNext. (see doku) But + thats not the fact ATM. */ + pLook->dwControlFlags = dwControlFlags; + pLook->providerId = *lpProviderId; + +#ifdef NSP_REDIRECT + if (IsEqualGUID(lpProviderId,&guid_mswsock_TcpIp)) + { + pLook->rdrproc = rdrproc_tcpip; + } + else if (IsEqualGUID(lpProviderId,&guid_mswsock_NLA)) + { + pLook->rdrproc = rdrproc_nla; + } + else return ERROR_CALL_NOT_IMPLEMENTED; + + if (pLook->rdrproc.NSPLookupServiceBegin( + lpProviderId, + lpqsRestrictions, + lpServiceClassInfo, + dwControlFlags, + &pLook->rdrLookup) == NO_ERROR) + wsaErr = NO_ERROR; + else + wsaErr = WSAGetLastError(); + /* + if (res) + res = WSAGetLastError(); + */ +#else + wsaErr = ERROR_CALL_NOT_IMPLEMENTED; + if (IsEqualGUID(lpqsRestrictions->lpServiceClassId, + &guid_NULL)) + { + wsaErr = ERROR_CALL_NOT_IMPLEMENTED; + } + else if (IsEqualGUID(lpqsRestrictions->lpServiceClassId, + &guid_HOSTNAME)) + { + wsaErr = NSP_LookupServiceBeginW(pLook, + NULL,NULL, + NSP_CALLID_HOSTNAME); + } + else if (IsEqualGUID(lpqsRestrictions->lpServiceClassId, + &guid_INET_HOSTADDRBYNAME)) + { + 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); + } + else if (IsEqualGUID(lpqsRestrictions->lpServiceClassId, + &guid_INET_HOSTADDRBYINETSTRING)) + { + wsaErr = ERROR_CALL_NOT_IMPLEMENTED; + }; +#endif + if (wsaErr != NO_ERROR) + { + WSASetLastError(wsaErr); + return SOCKET_ERROR; + } + return NO_ERROR; +} + +INT +WSAAPI mwsNSPLookupServiceNext( + _In_ HANDLE hLookup, + _In_ DWORD dwControlFlags, + _Inout_ LPDWORD lpdwBufferLength, + //_Out_writes_bytes_to_(*lpdwBufferLength, *lpdwBufferLength) + LPWSAQUERYSETW lpqsResults) +{ + PWSHANDLEINTERN pLook = hLookup; + int wsaErr = 0; + +#ifdef NSP_REDIRECT + INT res; + res = pLook->rdrproc.NSPLookupServiceNext( + pLook->rdrLookup, + dwControlFlags, + lpdwBufferLength, + lpqsResults); + wsaErr = WSAGetLastError(); + if (res != ERROR_SUCCESS) + { + wsaErr = WSAGetLastError(); + if (wsaErr == 0) + wsaErr = 0xFFFFFFFF; + } +#else + + if ( (lpdwBufferLength == NULL) || (*lpdwBufferLength == 0) ) + { + wsaErr = WSA_NOT_ENOUGH_MEMORY; + goto End; + } + + RtlZeroMemory(lpqsResults,*lpdwBufferLength); + lpqsResults->dwSize = sizeof(*lpqsResults); + + wsaErr = NSP_LookupServiceNextW(pLook, + pLook->CallID, + lpqsResults, + lpdwBufferLength); + + +#endif +End: + if (wsaErr != 0) + { + WSASetLastError(wsaErr); + return SOCKET_ERROR; + } + return NO_ERROR; +} + +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) +{ + WSASetLastError(ERROR_CALL_NOT_IMPLEMENTED); + return ERROR_CALL_NOT_IMPLEMENTED; +} + +INT +WSAAPI +mwsNSPLookupServiceEnd( + _In_ HANDLE hLookup) +{ + PWSHANDLEINTERN pLook; + HANDLE hHeap; + INT res; + + res = NO_ERROR; + pLook = (PWSHANDLEINTERN)hLookup; + hHeap = GetProcessHeap(); +#ifdef NSP_REDIRECT + res = pLook->rdrproc.NSPLookupServiceEnd(pLook->rdrLookup); +#endif + if (pLook->hostnameW != NULL) + HeapFree(hHeap,0,pLook->hostnameW); + HeapFree(hHeap,0,pLook); + return res; +} + +INT +WSAAPI mwsNSPSetService( + _In_ LPGUID lpProviderId, + _In_ LPWSASERVICECLASSINFOW lpServiceClassInfo, + _In_ LPWSAQUERYSETW lpqsRegInfo, + _In_ WSAESETSERVICEOP essOperation, + _In_ DWORD dwControlFlags) +{ + WSASetLastError(ERROR_CALL_NOT_IMPLEMENTED); + return ERROR_CALL_NOT_IMPLEMENTED; +} +INT +WSAAPI mwsNSPInstallServiceClass( + _In_ LPGUID lpProviderId, + _In_ LPWSASERVICECLASSINFOW lpServiceClassInfo) +{ + WSASetLastError(ERROR_CALL_NOT_IMPLEMENTED); + return ERROR_CALL_NOT_IMPLEMENTED; +} + +INT +WSAAPI +mwsNSPRemoveServiceClass( + _In_ LPGUID lpProviderId, + _In_ LPGUID lpServiceClassId) +{ + WSASetLastError(ERROR_CALL_NOT_IMPLEMENTED); + return ERROR_CALL_NOT_IMPLEMENTED; +} + +INT +WSAAPI mwsNSPGetServiceClassInfo( + _In_ LPGUID lpProviderId, + _In_ LPDWORD lpdwBufSize, + _In_ LPWSASERVICECLASSINFOW lpServiceClassInfo) +{ + WSASetLastError(ERROR_CALL_NOT_IMPLEMENTED); + return ERROR_CALL_NOT_IMPLEMENTED; +} + +/* + hostnameA / hostnameW + * only used by HOSTBYNAME + * only one should be set + +*/ +INT +NSP_LookupServiceBeginW(PWSHANDLEINTERN data, + CHAR* hostnameA, + WCHAR* hostnameW, + DWORD CallID) +{ + HANDLE hHeap; + + if (data->CallID != 0) + return WSAEFAULT; + data->CallID = CallID; + + if ( (CallID == NSP_CALLID_HOSTBYNAME) || + (CallID == NSP_CALLID_SERVICEBYNAME) ) + { + hHeap = GetProcessHeap(); + + if (data->hostnameW != NULL) + HeapFree(hHeap,0,data->hostnameW); + if (hostnameA != NULL) + { + data->hostnameW = StrA2WHeapAlloc(hHeap,hostnameA); + } + else + { + data->hostnameW = StrCpyHeapAllocW(hHeap, hostnameW); + } + } + + WSASetLastError(0); + + return ERROR_SUCCESS; +} + +INT +NSP_GetHostNameHeapAllocW( + _Out_ WCHAR** hostname) +{ + WCHAR* name; + HANDLE hHeap = GetProcessHeap(); + DWORD bufCharLen = MAX_COMPUTERNAME_LENGTH + 1; + DWORD bufByteLen = bufCharLen * sizeof(WCHAR); + + name = HeapAlloc(hHeap,0,bufByteLen); + + if (!GetComputerNameExW(ComputerNameDnsHostname, + name, + &bufCharLen)) + { + HeapFree(hHeap,0,name); + WSASetLastError(WSAEFAULT); + return SOCKET_ERROR; + } + + *hostname = name; + return ERROR_SUCCESS; +} + +/* This function is far from perfect but it works enough */ +IP4_ADDRESS +FindEntryInHosts(IN CONST WCHAR FAR* wname) +{ + BOOL Found = FALSE; + HANDLE HostsFile; + CHAR HostsDBData[BUFSIZ] = { 0 }; + PCHAR SystemDirectory = HostsDBData; + PCHAR HostsLocation = "\\drivers\\etc\\hosts"; + PCHAR AddressStr, DnsName = NULL, AddrTerm, NameSt, NextLine, ThisLine, Comment; + UINT SystemDirSize = sizeof(HostsDBData) - 1, ValidData = 0; + DWORD ReadSize; + DWORD Address; + CHAR name[MAX_HOSTNAME_LEN+1]; + wcstombs(name, wname, MAX_HOSTNAME_LEN); + + /* We assume that the parameters are valid */ + + if (!GetSystemDirectoryA(SystemDirectory, SystemDirSize)) + { + WSASetLastError(WSANO_RECOVERY); + //WS_DbgPrint(MIN_TRACE, ("Could not get windows system directory.\n")); + return 0; /* Can't get system directory */ + } + + strncat(SystemDirectory, + HostsLocation, + SystemDirSize ); + + HostsFile = CreateFileA(SystemDirectory, + GENERIC_READ, + FILE_SHARE_READ, + NULL, + OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, + NULL); + if (HostsFile == INVALID_HANDLE_VALUE) + { + WSASetLastError(WSANO_RECOVERY); + return 0; + } + + while(!Found && + ReadFile(HostsFile, + HostsDBData + ValidData, + sizeof(HostsDBData) - ValidData, + &ReadSize, + NULL)) + { + ValidData += ReadSize; + ReadSize = 0; + NextLine = ThisLine = HostsDBData; + + /* Find the beginning of the next line */ + while(NextLine < HostsDBData + ValidData && + *NextLine != '\r' && *NextLine != '\n' ) + { + NextLine++; + } + + /* Zero and skip, so we can treat what we have as a string */ + if( NextLine > HostsDBData + ValidData ) + break; + + *NextLine = 0; NextLine++; + + Comment = strchr( ThisLine, '#' ); + if( Comment ) *Comment = 0; /* Terminate at comment start */ + + AddressStr = ThisLine; + /* Find the first space separating the IP address from the DNS name */ + AddrTerm = strchr(ThisLine, ' '); + if (AddrTerm) + { + /* Terminate the address string */ + *AddrTerm = 0; + + /* Find the last space before the DNS name */ + NameSt = strrchr(ThisLine, ' '); + + /* If there is only one space (the one we removed above), then just use the address terminator */ + if (!NameSt) + NameSt = AddrTerm; + + /* Move from the space to the first character of the DNS name */ + NameSt++; + + DnsName = NameSt; + + if (!strcmp(name, DnsName)) + { + Found = TRUE; + break; + } + } + + /* Get rid of everything we read so far */ + while( NextLine <= HostsDBData + ValidData && + isspace (*NextLine)) + { + NextLine++; + } + + if (HostsDBData + ValidData - NextLine <= 0) + break; + + //WS_DbgPrint(MAX_TRACE,("About to move %d chars\n", + // HostsDBData + ValidData - NextLine)); + + memmove(HostsDBData, + NextLine, + HostsDBData + ValidData - NextLine ); + ValidData -= NextLine - HostsDBData; + //WS_DbgPrint(MAX_TRACE,("Valid bytes: %d\n", ValidData)); + } + + CloseHandle(HostsFile); + + if (!Found) + { + //WS_DbgPrint(MAX_TRACE,("Not found\n")); + WSASetLastError(WSANO_DATA); + return 0; + } + + if (strstr(AddressStr, ":")) + { + //DbgPrint("AF_INET6 NOT SUPPORTED!\n"); + WSASetLastError(WSAEINVAL); + return 0; + } + + Address = inet_addr(AddressStr); + if (Address == INADDR_NONE) + { + WSASetLastError(WSAEINVAL); + return 0; + } + + return Address; +} + +INT +NSP_GetHostByNameHeapAllocW( + _In_ WCHAR* name, + _In_ GUID* lpProviderId, + _Out_ PWSHOSTINFOINTERN hostinfo) +{ + HANDLE hHeap = GetProcessHeap(); + enum addr_type + { + GH_INVALID, + GH_IPV6, + GH_IPV4, + GH_RFC1123_DNS + }; + typedef enum addr_type addr_type; + addr_type addr; + INT ret = 0; + WCHAR* found = 0; + DNS_STATUS dns_status = {0}; + /* include/WinDNS.h -- look up DNS_RECORD on MSDN */ + PDNS_RECORD dp; + PDNS_RECORD curr; + WCHAR* tmpHostnameW; + CHAR* tmpHostnameA; + IP4_ADDRESS address; + INT result = ERROR_SUCCESS; + + /* neded to be cleand up if != NULL */ + tmpHostnameW = NULL; + dp = NULL; + + addr = GH_INVALID; + + if (name == NULL) + { + result = ERROR_INVALID_PARAMETER; + goto cleanup; + } + + /* Hostname "" / "localhost" + - convert to "computername" */ + if ( (wcscmp(L"",name) == 0) /*|| + (wcsicmp(L"localhost",name) == 0)*/ ) + { + ret = NSP_GetHostNameHeapAllocW(&tmpHostnameW); + if (ret != ERROR_SUCCESS) + { + result = ret; + goto cleanup; + } + name = tmpHostnameW; + } + + /* Is it an IPv6 address? */ + found = wcschr(name,L':'); + if( found != NULL ) + { + addr = GH_IPV6; + goto act; + } + + /* Is it an IPv4 address? */ + if (!iswalpha(name[0])) + { + addr = GH_IPV4; + goto act; + } + + addr = GH_RFC1123_DNS; + + /* Broken out in case we want to get fancy later */ + act: + switch(addr) + { + case GH_IPV6: + WSASetLastError(ERROR_CALL_NOT_IMPLEMENTED); + result = ERROR_CALL_NOT_IMPLEMENTED; + goto cleanup; + break; + + case GH_INVALID: + WSASetLastError(WSAEFAULT); + result = ERROR_INVALID_PARAMETER; + goto cleanup; + break; + + /* Note: If passed an IP address, MSDN says that gethostbyname() + treats it as an unknown host. + This is different from the unix implementation. Use inet_addr() + */ + case GH_IPV4: + case GH_RFC1123_DNS: + /* DNS_TYPE_A: include/WinDNS.h */ + /* DnsQuery -- lib/dnsapi/dnsapi/query.c */ + + /* Look for the DNS name in the hosts file */ + if ((address = FindEntryInHosts(name)) != 0) + { + hostinfo->hostnameW = StrCpyHeapAllocW(hHeap,name); + hostinfo->addr4 = address; + result = ERROR_SUCCESS; + goto cleanup; + } + + tmpHostnameA = StrW2AHeapAlloc(hHeap, name); + dns_status = DnsQuery(tmpHostnameA, + DNS_TYPE_A, + DNS_QUERY_STANDARD, + /* extra dns servers */ 0, + &dp, + 0); + HeapFree(hHeap, 0, tmpHostnameA); + + if ( (dns_status != 0) || (dp == NULL) ) + { + result = WSAHOST_NOT_FOUND; + goto cleanup; + } + + //ASSERT(dp->wType == DNS_TYPE_A); + //ASSERT(dp->wDataLength == sizeof(DNS_A_DATA)); + curr = dp; + while ( (curr->pNext != NULL) || (curr->wType != DNS_TYPE_A) ) + curr = curr->pNext; + + if (curr->wType != DNS_TYPE_A) + { + result = WSASERVICE_NOT_FOUND; + goto cleanup; + } + + //WS_DbgPrint(MID_TRACE,("populating hostent\n")); + //WS_DbgPrint(MID_TRACE,("pName is (%s)\n", curr->pName)); + //populate_hostent(p->Hostent, + // (PCHAR)curr->pName, + // curr->Data.A.IpAddress); + hostinfo->hostnameW = StrA2WHeapAlloc(hHeap,curr->pName); + hostinfo->addr4 = curr->Data.A.IpAddress; + result = ERROR_SUCCESS; + goto cleanup; + + //WS_DbgPrint(MID_TRACE,("Called DnsQuery, but host not found. Err: %i\n", + // dns_status)); + //WSASetLastError(WSAHOST_NOT_FOUND); + //return NULL; + + break; + + default: + result = WSANO_RECOVERY; + goto cleanup; + break; + } + + result = WSANO_RECOVERY; + +cleanup: + if (dp != NULL) + DnsRecordListFree(dp, DnsFreeRecordList); + if (tmpHostnameW != NULL) + HeapFree(hHeap,0,tmpHostnameW); + return result; +} + +#define SKIPWS(ptr,act) \ +{while(*ptr && isspace(*ptr)) ptr++; if(!*ptr) act;} +#define SKIPANDMARKSTR(ptr,act) \ +{while(*ptr && !isspace(*ptr)) ptr++; \ + if(!*ptr) {act;} else { *ptr = 0; ptr++; }} + +static BOOL +DecodeServEntFromString(IN PCHAR ServiceString, + OUT PCHAR *ServiceName, + OUT PCHAR *PortNumberStr, + OUT PCHAR *ProtocolStr, + IN PCHAR *Aliases, + IN DWORD MaxAlias) +{ + UINT NAliases = 0; + + //WS_DbgPrint(MAX_TRACE, ("Parsing service ent [%s]\n", ServiceString)); + + SKIPWS(ServiceString, return FALSE); + *ServiceName = ServiceString; + SKIPANDMARKSTR(ServiceString, return FALSE); + SKIPWS(ServiceString, return FALSE); + *PortNumberStr = ServiceString; + SKIPANDMARKSTR(ServiceString, ;); + + while( *ServiceString && NAliases < MaxAlias - 1 ) + { + SKIPWS(ServiceString, break); + if( *ServiceString ) + { + SKIPWS(ServiceString, ;); + if( strlen(ServiceString) ) + { + //WS_DbgPrint(MAX_TRACE, ("Alias: %s\n", ServiceString)); + *Aliases++ = ServiceString; + NAliases++; + } + SKIPANDMARKSTR(ServiceString, ;); + } + } + *Aliases = NULL; + + *ProtocolStr = strchr(*PortNumberStr,'/'); + if( !*ProtocolStr ) return FALSE; + **ProtocolStr = 0; (*ProtocolStr)++; + + //WS_DbgPrint(MAX_TRACE, ("Parsing done: %s %s %s %d\n", + // *ServiceName, *ProtocolStr, *PortNumberStr, + // NAliases)); + + return TRUE; +} + +INT +NSP_GetServiceByNameHeapAllocW( + _In_ WCHAR* nameW, + _In_ GUID* lpProviderId, + _Out_ PWSHOSTINFOINTERN hostinfo) +{ + BOOL Found = FALSE; + HANDLE ServicesFile; + CHAR ServiceDBData[BUFSIZ * sizeof(WCHAR)] = { 0 }; + PWCHAR SystemDirectory = (PWCHAR)ServiceDBData; /* Reuse this stack space */ + PWCHAR ServicesFileLocation = L"\\drivers\\etc\\services"; + PCHAR ThisLine = 0, NextLine = 0, ServiceName = 0, PortNumberStr = 0, + ProtocolStr = 0, Comment = 0, EndValid; + PCHAR Aliases[WS2_INTERNAL_MAX_ALIAS] = { 0 }; + PCHAR* AliasPtr; + UINT i = 0, + SystemDirSize = (sizeof(ServiceDBData) / sizeof(WCHAR)) - 1; + DWORD ReadSize = 0; + HANDLE hHeap; + PCHAR nameA = NULL; + PCHAR nameServiceA = NULL; + PCHAR nameProtoA = NULL; + INT res = WSANO_RECOVERY; + + if ( !nameW ) + { + res = WSANO_RECOVERY; + goto End; + } + + hHeap = GetProcessHeap(); + nameA = StrW2AHeapAlloc(hHeap, nameW); + + /* nameA has the form / + we split these now */ + nameProtoA = strchr(nameA,'/'); + if (nameProtoA == NULL) + { + res = WSANO_RECOVERY; + goto End; + } + nameProtoA++; + i = (DWORD)(nameProtoA - nameA - 1); + nameServiceA = (PCHAR)HeapAlloc(hHeap,0,i+1); + StringCbCopyA(nameServiceA, i+1, nameA); + nameServiceA[i] = '\0'; + + if ( !GetSystemDirectoryW( SystemDirectory, SystemDirSize ) ) + { + /* Can't get system directory */ + res = WSANO_RECOVERY; + goto End; + } + + wcsncat( SystemDirectory, + ServicesFileLocation, + SystemDirSize ); + + ServicesFile = CreateFileW(SystemDirectory, + GENERIC_READ, + FILE_SHARE_READ, + NULL, + OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, + NULL ); + + if ( ServicesFile == INVALID_HANDLE_VALUE ) + { + return WSANO_RECOVERY; + } + + /* Scan the services file ... + * + * We will be share the buffer on the lines. If the line does not fit in + * the buffer, then moving it to the beginning of the buffer and read + * the remnants of line from file. + */ + + /* Initial Read */ + ReadFile(ServicesFile, + ServiceDBData, + sizeof( ServiceDBData ) - 1, + &ReadSize, NULL ); + ThisLine = NextLine = ServiceDBData; + EndValid = ServiceDBData + ReadSize; + ServiceDBData[sizeof(ServiceDBData) - 1] = '\0'; + + while(ReadSize) + { + for(; *NextLine != '\r' && *NextLine != '\n'; NextLine++) + { + if(NextLine == EndValid) + { + int LineLen = NextLine - ThisLine; + + if(ThisLine == ServiceDBData) + { + //WS_DbgPrint(MIN_TRACE,("Line too long")); + return WSANO_RECOVERY; + } + + memmove(ServiceDBData, ThisLine, LineLen); + + ReadFile(ServicesFile, ServiceDBData + LineLen, + sizeof( ServiceDBData )-1 - LineLen, + &ReadSize, NULL ); + + EndValid = ServiceDBData + LineLen + ReadSize; + NextLine = ServiceDBData + LineLen; + ThisLine = ServiceDBData; + + if(!ReadSize) break; + } + } + + *NextLine = '\0'; + Comment = strchr( ThisLine, '#' ); + if( Comment ) *Comment = '\0'; /* Terminate at comment start */ + + if (DecodeServEntFromString(ThisLine, + &ServiceName, + &PortNumberStr, + &ProtocolStr, + Aliases, + WS2_INTERNAL_MAX_ALIAS) && + (strlen(nameProtoA) == 0 || strcmp(ProtocolStr, nameProtoA) == 0)) + { + Found = (strcmp(ServiceName, nameServiceA) == 0 || strcmp(PortNumberStr, nameServiceA) == 0); + AliasPtr = Aliases; + while ((!Found) && (*AliasPtr != NULL)) + { + Found = (strcmp(*AliasPtr, nameServiceA) == 0); + AliasPtr++; + } + if (Found) + break; + } + NextLine++; + ThisLine = NextLine; + } + + /* This we'll do no matter what */ + CloseHandle( ServicesFile ); + + if ( !Found ) + { + return WSANO_DATA; + } + + hostinfo->addr4 = 0; + hostinfo->servnameW = StrA2WHeapAlloc(hHeap,ServiceName); + hostinfo->servprotoW = StrA2WHeapAlloc(hHeap,ProtocolStr); + hostinfo->servaliasesA = StrAryCpyHeapAllocA(hHeap,(char**)&Aliases); + hostinfo->servport = atoi(PortNumberStr); + + res = NO_ERROR; + +End: + if (nameA != NULL) + HeapFree(hHeap,0,nameA); + if (nameServiceA != NULL) + HeapFree(hHeap,0,nameServiceA); + return res; +} + +INT +NSP_LookupServiceNextW( + _In_ PWSHANDLEINTERN data, + _In_ DWORD CallID, + _Inout_ LPWSAQUERYSETW lpRes, + _Inout_ LPDWORD lpResLen) +{ + MSW_BUFFER buf; + WSHOSTINFOINTERN hostinfo; + INT result; + HANDLE hHeap = GetProcessHeap(); + WCHAR* ServiceInstanceNameW = NULL; + /* cleanup-vars */ + CHAR* ServiceInstanceNameA = NULL; + CHAR* ServiceProtocolNameA = NULL; + + RtlZeroMemory(&hostinfo,sizeof(hostinfo)); + + /* init and build result-buffer */ + mswBufferInit(&buf,(BYTE*)lpRes,*lpResLen); + mswBufferIncUsed(&buf,sizeof(*lpRes)); + /* QueryDataSet-Size without "blob-data"-size! */ + lpRes->dwSize = sizeof(*lpRes); + lpRes->dwNameSpace = NS_DNS; + + if ( (CallID == NSP_CALLID_HOSTNAME) || + (CallID == NSP_CALLID_HOSTBYNAME) || + (CallID == NSP_CALLID_SERVICEBYNAME) ) + { + if (data->CallIDCounter >= 1) + { + result = WSAENOMORE; + goto End; + } + } + else + { + result = WSANO_RECOVERY; + goto End; + } + data->CallIDCounter++; + + if (CallID == NSP_CALLID_HOSTNAME) + { + result = NSP_GetHostNameHeapAllocW(&hostinfo.hostnameW); + if (result != ERROR_SUCCESS) + goto End; + hostinfo.addr4 = 0; + } + else if (CallID == NSP_CALLID_HOSTBYNAME) + { + result = NSP_GetHostByNameHeapAllocW(data->hostnameW, + &data->providerId, + &hostinfo); + if (result != ERROR_SUCCESS) + goto End; + } + else if (CallID == NSP_CALLID_SERVICEBYNAME) + { + result = NSP_GetServiceByNameHeapAllocW(data->hostnameW, + &data->providerId, + &hostinfo); + if (result != ERROR_SUCCESS) + goto End; + } + else + { + result = WSANO_RECOVERY; // Internal error! + goto End; + } + + if ( ( (LUP_RETURN_BLOB & data->dwControlFlags) != 0) || + ( (LUP_RETURN_NAME & data->dwControlFlags) != 0) ) + { + if (CallID == NSP_CALLID_HOSTNAME || CallID == NSP_CALLID_HOSTBYNAME) + { + ServiceInstanceNameW = hostinfo.hostnameW; + ServiceInstanceNameA = StrW2AHeapAlloc(hHeap,ServiceInstanceNameW); + if (ServiceInstanceNameA == NULL) + { + result = WSAEFAULT; + goto End; + + } + } + if (CallID == NSP_CALLID_SERVICEBYNAME) + { + ServiceInstanceNameW = hostinfo.servnameW; + ServiceInstanceNameA = StrW2AHeapAlloc(hHeap,ServiceInstanceNameW); + if (ServiceInstanceNameA == NULL) + { + result = WSAEFAULT; + goto End; + + } + ServiceProtocolNameA = StrW2AHeapAlloc(hHeap,hostinfo.servprotoW); + if (ServiceProtocolNameA == NULL) + { + result = WSAEFAULT; + goto End; + + } + } + } + + if ((LUP_RETURN_ADDR & data->dwControlFlags) != 0) + { + if(!mswBufferAppendAddr_AddrInfoW(&buf,lpRes,hostinfo.addr4)) + { + *lpResLen = buf.bytesUsed; + result = WSAEFAULT; + goto End; + } + } + + if ((LUP_RETURN_BLOB & data->dwControlFlags) != 0) + { + if (CallID == NSP_CALLID_HOSTBYNAME) + { + /* Write data for PBLOB (hostent) */ + if(!mswBufferAppendBlob_Hostent(&buf, + lpRes, + ServiceInstanceNameA, + hostinfo.addr4)) + { + *lpResLen = buf.bytesUsed; + result = WSAEFAULT; + goto End; + } + } + else if (CallID == NSP_CALLID_SERVICEBYNAME) + { + /* Write data for PBLOB (servent) */ + if(!mswBufferAppendBlob_Servent(&buf, + lpRes, + ServiceInstanceNameA,/* ServiceName */ + hostinfo.servaliasesA, + ServiceProtocolNameA, + hostinfo.servport)) + { + *lpResLen = buf.bytesUsed; + result = WSAEFAULT; + goto End; + } + } + else + { + result = WSANO_RECOVERY; + goto End; + } + } + + if ((LUP_RETURN_NAME & data->dwControlFlags) != 0) + { + /* HostByName sets the ServiceInstanceName to a + (UNICODE)copy of hostent.h_name */ + lpRes->lpszServiceInstanceName = (LPWSTR)mswBufferEndPtr(&buf); + if(!mswBufferAppendStrW(&buf,ServiceInstanceNameW)) + { + lpRes->lpszServiceInstanceName = NULL; + *lpResLen = buf.bytesUsed; + result = WSAEFAULT; + goto End; + } + } + + *lpResLen = buf.bytesUsed; + + result = ERROR_SUCCESS; +End: + /* cleanup */ + if (ServiceInstanceNameA != NULL) + HeapFree(hHeap,0,ServiceInstanceNameA); + if (ServiceProtocolNameA != NULL) + HeapFree(hHeap,0,ServiceProtocolNameA); + if (hostinfo.hostnameW != NULL) + HeapFree(hHeap,0,hostinfo.hostnameW); + if (hostinfo.servnameW != NULL) + HeapFree(hHeap,0,hostinfo.servnameW); + if (hostinfo.servprotoW != NULL) + HeapFree(hHeap,0,hostinfo.servprotoW); + return result; +} + +/* Implementations - Exports */ +/* + * @implemented + */ +int +WINAPI +NSPStartup( + _In_ LPGUID lpProviderId, + _Out_ LPNSP_ROUTINE lpRout + ) +{ + INT ret; + + if ( (lpRout == NULL) || + (lpRout->cbSize != sizeof(NSP_ROUTINE)) ) + { + WSASetLastError(ERROR_INVALID_PARAMETER); + return ERROR_INVALID_PARAMETER; + } + + mwsNSPInit(); + + /* set own Provider GUID - maybe we need + here to set the original mswsock-GUID?! */ + + /* Win2k3 returns + - Version 1.1 + - no NSPIoctl + - sets cbSize to 44! */ + lpRout->dwMajorVersion = 1; + lpRout->dwMinorVersion = 1; + lpRout->cbSize = sizeof(*lpRout)-sizeof(lpRout->NSPIoctl); + lpRout->NSPCleanup = &mwsNSPCleanUp; + lpRout->NSPLookupServiceBegin = &mwsNSPLookupServiceBegin; + lpRout->NSPLookupServiceNext = &mwsNSPLookupServiceNext; + lpRout->NSPLookupServiceEnd = &mwsNSPLookupServiceEnd; + lpRout->NSPSetService = &mwsNSPSetService; + lpRout->NSPInstallServiceClass = &mwsNSPInstallServiceClass; + lpRout->NSPRemoveServiceClass = &mwsNSPRemoveServiceClass; + lpRout->NSPGetServiceClassInfo = &mwsNSPGetServiceClassInfo; + lpRout->NSPIoctl = NULL;// &mwsNSPIoCtl; + + ret = NO_ERROR; + + return ret; +} Index: dll/win32/mswsock/stubs.c =================================================================== --- dll/win32/mswsock/stubs.c (revision 72669) +++ dll/win32/mswsock/stubs.c (working copy) @@ -9,6 +9,7 @@ #include "precomp.h" +#include #include #include @@ -417,24 +418,9 @@ return TRUE; } - /* * @unimplemented */ -INT -WINAPI -NSPStartup( - LPGUID lpProviderId, - LPNSP_ROUTINE lpnspRoutines - ) -{ - return TRUE; -} - - -/* - * @unimplemented - */ int WINAPI WSPStartup( Index: dll/win32/wininet/netconnection.c =================================================================== --- dll/win32/wininet/netconnection.c (revision 72669) +++ dll/win32/wininet/netconnection.c (working copy) @@ -259,7 +259,7 @@ WSADATA wsa_data; DWORD res; - res = WSAStartup(MAKEWORD(1,1), &wsa_data); + res = WSAStartup(MAKEWORD(2,2), &wsa_data); if(res == ERROR_SUCCESS) winsock_loaded = TRUE; else Index: dll/win32/ws2_32_new/CMakeLists.txt =================================================================== --- dll/win32/ws2_32_new/CMakeLists.txt (revision 72669) +++ dll/win32/ws2_32_new/CMakeLists.txt (working copy) @@ -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) Index: dll/win32/ws2_32_new/inc/ws2_32.h =================================================================== --- dll/win32/ws2_32_new/inc/ws2_32.h (revision 72669) +++ dll/win32/ws2_32_new/inc/ws2_32.h (working copy) @@ -35,6 +35,7 @@ #include #include +#include /* Missing definitions */ #define SO_OPENTYPE 0x7008 Index: dll/win32/ws2_32_new/inc/ws2_32p.h =================================================================== --- dll/win32/ws2_32_new/inc/ws2_32p.h (revision 72669) +++ dll/win32/ws2_32_new/inc/ws2_32p.h (working copy) @@ -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; Index: dll/win32/ws2_32_new/src/addrconv.c =================================================================== --- dll/win32/ws2_32_new/src/addrconv.c (revision 72669) +++ dll/win32/ws2_32_new/src/addrconv.c (working copy) @@ -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); Index: dll/win32/ws2_32_new/src/addrinfo.c =================================================================== --- dll/win32/ws2_32_new/src/addrinfo.c (revision 72669) +++ dll/win32/ws2_32_new/src/addrinfo.c (working copy) @@ -90,17 +90,76 @@ ParseV4Address(IN PCWSTR AddressString, OUT PDWORD pAddress) { - IN_ADDR Address; - PCWSTR Terminator; - NTSTATUS Status; + CHAR AnsiAddressString[MAX_HOSTNAME_LEN]; + CHAR * cp = AnsiAddressString; + DWORD val, base; + unsigned char c; + DWORD parts[4], *pp = parts; + if (!AddressString) + return FALSE; + WideCharToMultiByte(CP_ACP, + 0, + AddressString, + -1, + AnsiAddressString, + sizeof(AnsiAddressString), + NULL, + 0); + if (!isdigit(*cp)) return FALSE; - *pAddress = 0; - Status = RtlIpv4StringToAddressW(AddressString, FALSE, &Terminator, &Address); +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; - if (!NT_SUCCESS(Status)) - 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]; - *pAddress = Address.S_un.S_addr; + 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,7 +638,7 @@ /* If we got 0, then fail */ if (wPort == 0) { - return iSocketType ? EAI_SERVICE : EAI_NONAME; + return EAI_SERVICE; } /* Check if this was for both */ @@ -583,8 +645,11 @@ 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,7 +801,7 @@ 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); @@ -743,16 +808,16 @@ /* Check for WSAStartup */ if ((ErrorCode = WsQuickProlog()) != ERROR_SUCCESS) return ErrorCode; - /* Assume NULL */ - *res = NULL; - /* Convert the node name */ - UnicodeNodeName = UnicodeDupFromAnsi((LPSTR)nodename); - if (!UnicodeNodeName) + if (nodename) { - /* Prepare to fail */ - ErrorCode = GetLastError(); - goto Quickie; + 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 */ Index: dll/win32/ws2_32_new/src/dcatalog.c =================================================================== --- dll/win32/ws2_32_new/src/dcatalog.c (revision 72669) +++ dll/win32/ws2_32_new/src/dcatalog.c (working copy) @@ -10,10 +10,11 @@ #include +#define NDEBUG +#include + /* 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, @@ -77,6 +97,10 @@ &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(); Index: dll/win32/ws2_32_new/src/dcatitem.c =================================================================== --- dll/win32/ws2_32_new/src/dcatitem.c (revision 72669) +++ dll/win32/ws2_32_new/src/dcatitem.c (working copy) @@ -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,21 +81,34 @@ &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); return Return; Index: dll/win32/ws2_32_new/src/dprovide.c =================================================================== --- dll/win32/ws2_32_new/src/dprovide.c (revision 72669) +++ dll/win32/ws2_32_new/src/dprovide.c (working copy) @@ -10,6 +10,9 @@ #include +#define NDEBUG +#include + /* 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 Index: dll/win32/ws2_32_new/src/enumprot.c =================================================================== --- dll/win32/ws2_32_new/src/enumprot.c (revision 72669) +++ dll/win32/ws2_32_new/src/enumprot.c (working copy) @@ -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; + 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; } /* - * @unimplemented + * @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; + 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; } + /* - * @unimplemented + * @implemented */ INT WSPAPI @@ -227,13 +265,11 @@ IN OUT LPINT lpProviderDllPathLen, OUT LPINT lpErrno) { - DPRINT("WPUGetProviderPath: %p\n", lpProviderId); - UNIMPLEMENTED; - return 0; + return WSCGetProviderPath(lpProviderId, lpszProviderDllPath, lpProviderDllPathLen, lpErrno); } /* - * @unimplemented + * @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; Index: dll/win32/ws2_32_new/src/getproto.c =================================================================== --- dll/win32/ws2_32_new/src/getproto.c (revision 72669) +++ dll/win32/ws2_32_new/src/getproto.c (working copy) @@ -19,13 +19,18 @@ 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, "System\\CurrentControlSet\\Services\\Tcpip\\Parameters", @@ -39,20 +44,43 @@ "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 */ @@ -59,14 +87,14 @@ 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, @@ -73,6 +101,9 @@ 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); Index: dll/win32/ws2_32_new/src/getxbyxx.c =================================================================== --- dll/win32/ws2_32_new/src/getxbyxx.c (revision 72669) +++ dll/win32/ws2_32_new/src/getxbyxx.c (working copy) @@ -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) + IN INT namelen) { - PCHAR Name; + 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. */ Index: dll/win32/ws2_32_new/src/nscatalo.c =================================================================== --- dll/win32/ws2_32_new/src/nscatalo.c (revision 72669) +++ dll/win32/ws2_32_new/src/nscatalo.c (working copy) @@ -10,9 +10,11 @@ #include +#define NDEBUG +#include + /* 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, @@ -76,6 +96,10 @@ &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", Index: dll/win32/ws2_32_new/src/nscatent.c =================================================================== --- dll/win32/ws2_32_new/src/nscatent.c (revision 72669) +++ dll/win32/ws2_32_new/src/nscatent.c (working copy) @@ -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 Index: dll/win32/ws2_32_new/src/nsquery.c =================================================================== --- dll/win32/ws2_32_new/src/nsquery.c (revision 72669) +++ dll/win32/ws2_32_new/src/nsquery.c (working copy) @@ -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)) Index: dll/win32/ws2_32_new/src/rnr.c =================================================================== --- dll/win32/ws2_32_new/src/rnr.c (revision 72669) +++ dll/win32/ws2_32_new/src/rnr.c (working copy) @@ -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,41 +621,187 @@ } /* - * @unimplemented - */ +* @unimplemented +*/ INT WSAAPI -WSAEnumNameSpaceProvidersA(IN OUT LPDWORD lpdwBufferLength, - OUT LPWSANAMESPACE_INFOA lpnspBuffer) +WSAInstallServiceClassW(IN LPWSASERVICECLASSINFOW lpServiceClassInfo) { - DPRINT("WSAEnumNameSpaceProvidersA: %lx\n", lpnspBuffer); + 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; +} + /* - * @unimplemented + * @implemented */ INT WSAAPI -WSAEnumNameSpaceProvidersW(IN OUT LPDWORD lpdwBufferLength, - OUT LPWSANAMESPACE_INFOW lpnspBuffer) +WSAEnumNameSpaceProvidersA(IN OUT LPDWORD lpdwBufferLength, + OUT LPWSANAMESPACE_INFOA lpnspBuffer) { - DPRINT("WSAEnumNameSpaceProvidersW: %lx\n", lpnspBuffer); - SetLastError(WSAEINVAL); - return SOCKET_ERROR; + DPRINT("WSAEnumNameSpaceProvidersA: %lx\n", lpnspBuffer); + return WSAEnumNameSpaceProvidersInternal(lpdwBufferLength, (LPWSANAMESPACE_INFOA)lpnspBuffer, FALSE); } /* - * @unimplemented + * @implemented */ INT WSAAPI -WSAInstallServiceClassW(IN LPWSASERVICECLASSINFOW lpServiceClassInfo) +WSAEnumNameSpaceProvidersW(IN OUT LPDWORD lpdwBufferLength, + OUT LPWSANAMESPACE_INFOW lpnspBuffer) { - DPRINT("WSAInstallServiceClassW: %lx\n", lpServiceClassInfo); - SetLastError(WSAEINVAL); - return SOCKET_ERROR; + DPRINT("WSAEnumNameSpaceProvidersW: %lx\n", lpnspBuffer); + return WSAEnumNameSpaceProvidersInternal(lpdwBufferLength, (LPWSANAMESPACE_INFOA)lpnspBuffer, TRUE); } /* Index: dll/win32/ws2_32_new/src/send.c =================================================================== --- dll/win32/ws2_32_new/src/send.c (revision 72669) +++ dll/win32/ws2_32_new/src/send.c (working copy) @@ -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) Index: dll/win32/ws2_32_new/src/sockctrl.c =================================================================== --- dll/win32/ws2_32_new/src/sockctrl.c (revision 72669) +++ dll/win32/ws2_32_new/src/sockctrl.c (working copy) @@ -441,6 +441,11 @@ return Status; } + if (!optval && optlen > 0) + { + SetLastError(WSAEFAULT); + return SOCKET_ERROR; + } /* Get the Socket Context */ if ((Socket = WsSockGetSocket(s))) Index: dll/win32/ws2_32_new/src/socklife.c =================================================================== --- dll/win32/ws2_32_new/src/socklife.c (revision 72669) +++ dll/win32/ws2_32_new/src/socklife.c (working copy) @@ -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 */ Index: dll/win32/ws2_32_new/src/startup.c =================================================================== --- dll/win32/ws2_32_new/src/startup.c (revision 72669) +++ dll/win32/ws2_32_new/src/startup.c (working copy) @@ -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 { @@ -160,6 +166,12 @@ break; } + if (lpWSAData == NULL) + { + SetLastError(WSANOTINITIALISED); + return ErrorCode == ERROR_SUCCESS ? WSAEFAULT : ErrorCode; + } + /* Return the Version Requested, unless error */ lpWSAData->wVersion = VersionReturned; @@ -182,6 +194,13 @@ lpWSAData->iMaxSockets = 0; lpWSAData->iMaxUdpDg = 0; } + + /* Requested invalid version (0) */ + if (ErrorCode != ERROR_SUCCESS) + { + SetLastError(WSANOTINITIALISED); + return ErrorCode; + } /* Enter the startup synchronization lock */ WsStartupLock(); @@ -223,7 +242,15 @@ /* 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 */ WsStartupUnlock(); Index: media/drivers/etc/services =================================================================== --- media/drivers/etc/services (revision 72669) +++ media/drivers/etc/services (working copy) @@ -20,18 +20,18 @@ rje 5/udp #Remote Job Entry echo 7/tcp #Echo echo 7/udp #Echo -discard 9/tcp #Discard -discard 9/udp #Discard +discard 9/tcp sink null #Discard +discard 9/udp sink null #Discard systat 11/tcp #Active Users systat 11/udp #Active Users daytime 13/tcp #Daytime (RFC 867) daytime 13/udp #Daytime (RFC 867) -qotd 17/tcp #Quote of the Day -qotd 17/udp #Quote of the Day +qotd 17/tcp quote #Quote of the Day +qotd 17/udp quote #Quote of the Day msp 18/tcp #Message Send Protocol msp 18/udp #Message Send Protocol -chargen 19/tcp #Character Generator -chargen 19/udp #Character Generator +chargen 19/tcp ttytst source #Character Generator +chargen 19/udp ttytst source #Character Generator ftp-data 20/tcp #File Transfer [Default Data] ftp-data 20/udp #File Transfer [Default Data] ftp 21/tcp #File Transfer [Control] @@ -40,10 +40,10 @@ ssh 22/udp #SSH Remote Login Protocol telnet 23/tcp #Telnet telnet 23/udp #Telnet -smtp 25/tcp #Simple Mail Transfer -smtp 25/udp #Simple Mail Transfer -mail 25/tcp #Simple Mail Transfer -mail 25/udp #Simple Mail Transfer +smtp 25/tcp mail #Simple Mail Transfer +#smtp 25/udp mail #Simple Mail Transfer +mail 25/tcp smtp #Simple Mail Transfer +#mail 25/udp smtp #Simple Mail Transfer nsw-fe 27/tcp #NSW User System FE nsw-fe 27/udp #NSW User System FE msg-icp 29/tcp #MSG ICP @@ -52,19 +52,19 @@ msg-auth 31/udp #MSG Authentication dsp 33/tcp #Display Support Protocol dsp 33/udp #Display Support Protocol -time 37/tcp #Time -time 37/udp #Time +time 37/tcp timserver #Time +time 37/udp timserver #Time rap 38/tcp #Route Access Protocol rap 38/udp #Route Access Protocol -rlp 39/tcp #Resource Location Protocol -rlp 39/udp #Resource Location Protocol +rlp 39/tcp resource #Resource Location Protocol +rlp 39/udp resource #Resource Location Protocol graphics 41/tcp #Graphics graphics 41/udp #Graphics name 42/tcp #Host Name Server name 42/udp #Host Name Server -nameserver 42/tcp #Host Name Server -nameserver 42/udp #Host Name Server -nicname 43/tcp #Who Is +nameserver 42/tcp name #Host Name Server +nameserver 42/udp name #Host Name Server +nicname 43/tcp whois #Who Is nicname 43/udp #Who Is mpm-flags 44/tcp #MPM FLAGS Protocol mpm-flags 44/udp #MPM FLAGS Protocol @@ -107,9 +107,9 @@ sql*net 66/tcp #Oracle SQL*NET sql*net 66/udp #Oracle SQL*NET bootps 67/tcp #Bootstrap Protocol Server -bootps 67/udp #Bootstrap Protocol Server +bootps 67/udp dhcps #Bootstrap Protocol Server bootpc 68/tcp #Bootstrap Protocol Client -bootpc 68/udp #Bootstrap Protocol Client +bootpc 68/udp dhcpc #Bootstrap Protocol Client tftp 69/tcp #Trivial File Transfer tftp 69/udp #Trivial File Transfer gopher 70/tcp #Gopher @@ -128,12 +128,12 @@ vettcp 78/udp #vettcp finger 79/tcp #Finger finger 79/udp #Finger -http 80/tcp #World Wide Web HTTP -http 80/udp #World Wide Web HTTP +http 80/tcp www www-http #World Wide Web HTTP +#http 80/udp #World Wide Web HTTP www 80/tcp #World Wide Web HTTP -www 80/udp #World Wide Web HTTP +#www 80/udp #World Wide Web HTTP www-http 80/tcp #World Wide Web HTTP -www-http 80/udp #World Wide Web HTTP +#www-http 80/udp #World Wide Web HTTP hosts2-ns 81/tcp #HOSTS2 Name Server hosts2-ns 81/udp #HOSTS2 Name Server xfer 82/tcp #XFER Utility @@ -146,8 +146,8 @@ mit-ml-dev 85/udp #MIT ML Device mfcobol 86/tcp #Micro Focus Cobol mfcobol 86/udp #Micro Focus Cobol -kerberos 88/tcp #Kerberos -kerberos 88/udp #Kerberos +kerberos 88/tcp krb5 kerberos-sec #Kerberos +kerberos 88/udp krb5 kerberos-sec #Kerberos su-mit-tg 89/tcp #SU/MIT Telnet Gateway su-mit-tg 89/udp #SU/MIT Telnet Gateway dnsix 90/tcp #DNSIX Securit Attribute Token Map @@ -171,7 +171,7 @@ metagram 99/tcp #Metagram Relay metagram 99/udp #Metagram Relay newacct 100/tcp #[unauthorized use] -hostname 101/tcp #NIC Host Name Server +hostname 101/tcp hostnames #NIC Host Name Server hostname 101/udp #NIC Host Name Server iso-tsap 102/tcp #ISO-TSAP Class 0 iso-tsap 102/udp #ISO-TSAP Class 0 @@ -189,15 +189,15 @@ rtelnet 107/udp #Remote Telnet Service snagas 108/tcp #SNA Gateway Access Server snagas 108/udp #SNA Gateway Access Server -pop2 109/tcp #Post Office Protocol - Version 2 +pop2 109/tcp postoffice #Post Office Protocol - Version 2 pop2 109/udp #Post Office Protocol - Version 2 pop3 110/tcp #Post Office Protocol - Version 3 pop3 110/udp #Post Office Protocol - Version 3 -sunrpc 111/tcp #SUN Remote Procedure Call -sunrpc 111/udp #SUN Remote Procedure Call +sunrpc 111/tcp rpcbind portmap #SUN Remote Procedure Call +sunrpc 111/udp rpcbind portmap #SUN Remote Procedure Call mcidas 112/tcp #McIDAS Data Transmission Protocol mcidas 112/udp #McIDAS Data Transmission Protocol -ident 113/tcp +ident 113/tcp ident tap auth 113/tcp #Authentication Service auth 113/udp #Authentication Service sftp 115/tcp #Simple File Transfer Protocol @@ -208,7 +208,7 @@ uucp-path 117/udp #UUCP Path Service sqlserv 118/tcp #SQL Services sqlserv 118/udp #SQL Services -nntp 119/tcp #Network News Transfer Protocol +nntp 119/tcp usenet #Network News Transfer Protocol nntp 119/udp #Network News Transfer Protocol cfdptkt 120/tcp #CFDPTKT cfdptkt 120/udp #CFDPTKT @@ -240,15 +240,15 @@ statsrv 133/udp #Statistics Service ingres-net 134/tcp #INGRES-NET Service ingres-net 134/udp #INGRES-NET Service -epmap 135/tcp #DCE endpoint resolution -epmap 135/udp #DCE endpoint resolution +epmap 135/tcp loc-srv #DCE endpoint resolution +epmap 135/udp loc-srv #DCE endpoint resolution profile 136/tcp #PROFILE Naming System profile 136/udp #PROFILE Naming System -netbios-ns 137/tcp #NETBIOS Name Service -netbios-ns 137/udp #NETBIOS Name Service +netbios-ns 137/tcp nbname #NETBIOS Name Service +netbios-ns 137/udp nbname #NETBIOS Name Service netbios-dgm 138/tcp #NETBIOS Datagram Service -netbios-dgm 138/udp #NETBIOS Datagram Service -netbios-ssn 139/tcp #NETBIOS Session Service +netbios-dgm 138/udp nbdatagram #NETBIOS Datagram Service +netbios-ssn 139/tcp nbsession #NETBIOS Session Service netbios-ssn 139/udp #NETBIOS Session Service emfis-data 140/tcp #EMFIS Data Service emfis-data 140/udp #EMFIS Data Service @@ -256,7 +256,7 @@ emfis-cntl 141/udp #EMFIS Control Service bl-idm 142/tcp #Britton-Lee IDM bl-idm 142/udp #Britton-Lee IDM -imap 143/tcp #Internet Message Access Protocol +imap 143/tcp imap4 #Internet Message Access Protocol imap 143/udp #Internet Message Access Protocol uma 144/tcp #Universal Management Architecture uma 144/udp #Universal Management Architecture @@ -295,7 +295,7 @@ snmp 161/tcp #SNMP snmp 161/udp #SNMP snmptrap 162/tcp #SNMPTRAP -snmptrap 162/udp #SNMPTRAP +snmptrap 162/udp snmp-trap #SNMPTRAP cmip-man 163/tcp #CMIP/TCP Manager cmip-man 163/udp #CMIP/TCP Manager cmip-agent 164/tcp #CMIP/TCP Agent @@ -696,14 +696,14 @@ dsfgw 438/udp #dsfgw dasp 439/tcp #dasp Thomas Obermair dasp 439/udp #dasp tommy@inlab.m.eunet.de -sgcp 440/tcp #sgcp -sgcp 440/udp #sgcp +sgcp 440/tcp #sgcp +sgcp 440/udp #sgcp decvms-sysmgt 441/tcp #decvms-sysmgt decvms-sysmgt 441/udp #decvms-sysmgt cvc_hostd 442/tcp #cvc_hostd cvc_hostd 442/udp #cvc_hostd -https 443/tcp #http protocol over TLS/SSL -https 443/udp #http protocol over TLS/SSL +https 443/tcp MCom #http protocol over TLS/SSL +https 443/udp MCom #http protocol over TLS/SSL snpp 444/tcp #Simple Network Paging Protocol snpp 444/udp #Simple Network Paging Protocol microsoft-ds 445/tcp #Microsoft-DS @@ -817,7 +817,7 @@ iso-ill 499/tcp #ISO ILL Protocol iso-ill 499/udp #ISO ILL Protocol isakmp 500/tcp #isakmp -isakmp 500/udp #isakmp +isakmp 500/udp ike #isakmp stmf 501/tcp #STMF stmf 501/udp #STMF asa-appl-proto 502/tcp #asa-appl-proto @@ -841,11 +841,13 @@ passgo 511/tcp #PassGo passgo 511/udp #PassGo exec 512/tcp #remote process execution; -biff 512/udp #used by mail system to notify users +biff 512/udp comsat #used by mail system to notify users login 513/tcp #remote login a la telnet; -who 513/udp #maintains data bases showing who's +who 513/udp whod #maintains data bases showing who's +cmd 514/tcp shell shell 514/tcp #cmd -printer 515/tcp #spooler +syslog 514/udp +printer 515/tcp spooler #spooler printer 515/udp #spooler videotex 516/tcp #videotex videotex 516/udp #videotex @@ -854,18 +856,18 @@ utime 519/tcp #unixtime utime 519/udp #unixtime efs 520/tcp #extended file name server -router 520/udp #local routing process (on site); +router 520/udp route routed #local routing process (on site); ripng 521/tcp #ripng ripng 521/udp #ripng -ulp 522/tcp #ULP -ulp 522/udp #ULP +ulp 522/tcp #ULP +ulp 522/udp #ULP ibm-db2 523/tcp #IBM-DB2 ibm-db2 523/udp #IBM-DB2 ncp 524/tcp #NCP ncp 524/udp #NCP timed 525/tcp #timeserver -timed 525/udp #timeserver -tempo 526/tcp #newdate +timed 525/udp timeserver #timeserver +tempo 526/tcp newdate #newdate tempo 526/udp #newdate stx 527/tcp #Stock IXChange stx 527/udp #Stock IXChange @@ -873,11 +875,11 @@ custix 528/udp #Customer IXChange irc-serv 529/tcp #IRC-SERV irc-serv 529/udp #IRC-SERV -courier 530/tcp #rpc +courier 530/tcp rpc #rpc courier 530/udp #rpc -conference 531/tcp #chat +conference 531/tcp chat #chat conference 531/udp #chat -netnews 532/tcp #readnews +netnews 532/tcp readnews #readnews netnews 532/udp #readnews netwall 533/tcp #for emergency broadcasts netwall 533/udp #for emergency broadcasts @@ -893,13 +895,13 @@ gdomap 538/udp #gdomap apertus-ldp 539/tcp #Apertus Technologies Load Determination apertus-ldp 539/udp #Apertus Technologies Load Determination -uucp 540/tcp #uucpd -uucp 540/udp #uucpd +uucp 540/tcp uucpd #uucpd +uucp 540/udp #uucpd uucp-rlogin 541/tcp #uucp-rlogin uucp-rlogin 541/udp #uucp-rlogin commerce 542/tcp #commerce commerce 542/udp #commerce -kshell 544/tcp #krcmd +kshell 544/tcp krcmd #krcmd kshell 544/udp #krcmd appleqtcsrvr 545/tcp #appleqtcsrvr appleqtcsrvr 545/udp #appleqtcsrvr @@ -911,7 +913,7 @@ afpovertcp 548/udp #AFP over TCP idfp 549/tcp #IDFP idfp 549/udp #IDFP -new-rwho 550/tcp #new-who +new-rwho 550/tcp new-who #new-who new-rwho 550/udp #new-who cybercash 551/tcp #cybercash cybercash 551/udp #cybercash @@ -921,7 +923,7 @@ pirp 553/udp #pirp rtsp 554/tcp #Real Time Stream Control Protocol rtsp 554/udp #Real Time Stream Control Protocol -remotefs 556/tcp #rfs server +remotefs 556/tcp rfs rfs_server #rfs server remotefs 556/udp #rfs server openvms-sysipc 557/tcp #openvms-sysipc openvms-sysipc 557/udp #openvms-sysipc @@ -930,11 +932,11 @@ teedtap 559/tcp #TEEDTAP teedtap 559/udp #TEEDTAP rmonitor 560/tcp #rmonitord -rmonitor 560/udp #rmonitord +rmonitor 560/udp rmonitord #rmonitord chshell 562/tcp #chcmd chshell 562/udp #chcmd -nntps 563/tcp #nntp protocol over TLS/SSL (was snntp) -nntps 563/udp #nntp protocol over TLS/SSL (was snntp) +nntps 563/tcp snntp #nntp protocol over TLS/SSL (was snntp) +nntps 563/udp snntp #nntp protocol over TLS/SSL (was snntp) 9pfs 564/tcp #plan 9 file service 9pfs 564/udp #plan 9 file service whoami 565/tcp #whoami @@ -1079,7 +1081,7 @@ ginad 634/udp #ginad rlzdbase 635/tcp #RLZ DBase rlzdbase 635/udp #RLZ DBase -ldaps 636/tcp #ldap protocol over TLS/SSL (was sldap) +ldaps 636/tcp sldap #ldap protocol over TLS/SSL (was sldap) ldaps 636/udp #ldap protocol over TLS/SSL (was sldap) lanserver 637/tcp #lanserver lanserver 637/udp #lanserver @@ -1301,8 +1303,8 @@ imaps 993/udp #imap4 protocol over TLS/SSL ircs 994/tcp #irc protocol over TLS/SSL ircs 994/udp #irc protocol over TLS/SSL -pop3s 995/tcp #pop3 protocol over TLS/SSL (was spop3) -pop3s 995/udp #pop3 protocol over TLS/SSL (was spop3) +pop3s 995/tcp spop3 #pop3 protocol over TLS/SSL (was spop3) +pop3s 995/udp spop3 #pop3 protocol over TLS/SSL (was spop3) vsinet 996/tcp #vsinet vsinet 996/udp #vsinet applix 999/udp #Applix ac @@ -2148,7 +2150,7 @@ ricardo-lm 1522/udp #Ricardo North America License Manager cichild-lm 1523/tcp #cichild cichild-lm 1523/udp #cichild -ingreslock 1524/tcp #ingres +ingreslock 1524/tcp ingres #ingres ingreslock 1524/udp #ingres orasrv 1525/tcp #oracle orasrv 1525/udp #oracle @@ -3111,6 +3113,7 @@ isis-bcast 2043/udp #isis-bcast nfs 2049/tcp #Network File System - Sun Microsystems nfs 2049/udp #Network File System - Sun Microsystems +nfsd 2049/udp nfs #Network File System - Sun Microsystems av-emb-config 2050/tcp #Avaya EMB Config Port av-emb-config 2050/udp #Avaya EMB Config Port epnsdp 2051/tcp #EPNSDP Index: sdk/lib/3rdparty/adns/src/setup.c =================================================================== --- sdk/lib/3rdparty/adns/src/setup.c (revision 72669) +++ sdk/lib/3rdparty/adns/src/setup.c (working copy) @@ -572,9 +572,8 @@ #define SECURE_PATH_LEN (MAX_PATH - 64) char PathBuf[MAX_PATH]; struct in_addr addr; - #define ADNS_PFIXED_INFO_BLEN (2048) - PFIXED_INFO network_info = (PFIXED_INFO)_alloca(ADNS_PFIXED_INFO_BLEN); - ULONG network_info_blen = ADNS_PFIXED_INFO_BLEN; + PFIXED_INFO network_info; + ULONG network_info_blen = 0; DWORD network_info_result; PIP_ADDR_STRING pip; const char *network_err_str = ""; @@ -601,6 +600,8 @@ GetWindowsDirectory(PathBuf, SECURE_PATH_LEN); strcat(PathBuf,"\\System32\\Drivers\\etc\\resolv-adns.conf"); readconfig(ads,PathBuf,0); + network_info_result = GetNetworkParams(NULL, &network_info_blen); + network_info = (PFIXED_INFO) malloc((size_t)network_info_blen); network_info_result = GetNetworkParams(network_info, &network_info_blen); if (network_info_result != ERROR_SUCCESS){ switch(network_info_result) { @@ -616,8 +617,13 @@ addr.s_addr = inet_addr(pip->IpAddress.String); if ((addr.s_addr != INADDR_ANY) && (addr.s_addr != INADDR_NONE)) addserver(ads, addr); + if (network_info->DomainName) + ccf_search(ads, "LOCALDOMAIN", -1, network_info->DomainName); + else + ccf_search(ads, "LOCALDOMAIN", -1, ""); } } + if (network_info) free(network_info); #else readconfig(ads,"/etc/resolv.conf",1); readconfig(ads,"/etc/resolv-adns.conf",0); Index: modules/rostests/winetests/ws2_32/sock.c =================================================================== --- modules/rostests/winetests/ws2_32/sock.c (revision 72669) +++ modules/rostests/winetests/ws2_32/sock.c (working copy) @@ -9287,6 +9287,7 @@ CloseHandle(previous_port); } +#ifndef __REACTOS__ /* WSHIoctl is not supported by wshtcpip.dll and crashes. Test should be fixed also! */ static void test_address_list_query(void) { SOCKET_ADDRESS_LIST *address_list; @@ -9349,6 +9350,7 @@ HeapFree(GetProcessHeap(), 0, address_list); closesocket(s); } +#endif static DWORD WINAPI inet_ntoa_thread_proc(void *param) { @@ -9807,7 +9809,9 @@ test_WSAAsyncGetServByName(); test_completion_port(); +#ifndef __REACTOS__ /* WSHIoctl is not supported by wshtcpip.dll and crashes. Test should be fixed also! */ test_address_list_query(); +#endif /* this is an io heavy test, do it at the end so the kernel doesn't start dropping packets */ test_send();