From c62000d38e9476ed58c7daea3484982e638cfc3c Mon Sep 17 00:00:00 2001 From: hater <7element@mail.bg> Date: Wed, 4 Nov 2015 11:31:58 +0200 Subject: [PATCH] Read database path from registry and disable debug messages --- reactos/dll/win32/ws2_32_new/src/getproto.c | 49 +++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 9 deletions(-) diff --git a/reactos/dll/win32/ws2_32_new/src/getproto.c b/reactos/dll/win32/ws2_32_new/src/getproto.c index 45d5809..825a1eb 100644 --- a/reactos/dll/win32/ws2_32_new/src/getproto.c +++ b/reactos/dll/win32/ws2_32_new/src/getproto.c @@ -10,7 +10,7 @@ #include -//#define NDEBUG +#define NDEBUG #include /* FUNCTIONS *****************************************************************/ @@ -19,12 +19,17 @@ HANDLE WSAAPI GetProtoOpenNetworkDatabase(PCHAR Name) { - CHAR ExpandedPath[MAX_PATH]; - CHAR DatabasePath[MAX_PATH]; + PCHAR ExpandedPath; + PCHAR DatabasePath; INT ErrorCode; HKEY DatabaseKey; DWORD RegType; - DWORD RegSize = sizeof(DatabasePath); + DWORD RegSize = 0; + HANDLE ret; + + ExpandedPath = HeapAlloc(WsSockHeap, 0, MAX_PATH); + if (!ExpandedPath) + return INVALID_HANDLE_VALUE; /* Open the database path key */ ErrorCode = RegOpenKeyEx(HKEY_LOCAL_MACHINE, @@ -39,40 +44,66 @@ GetProtoOpenNetworkDatabase(PCHAR Name) "DatabasePath", NULL, &RegType, + NULL, + &RegSize); + + DatabasePath = HeapAlloc(WsSockHeap, 0, RegSize); + if (!DatabasePath) + { + HeapFree(WsSockHeap, 0, ExpandedPath); + return INVALID_HANDLE_VALUE; + } + + /* Read the actual path */ + ErrorCode = RegQueryValueEx(DatabaseKey, + "DatabasePath", + NULL, + &RegType, (LPBYTE)DatabasePath, &RegSize); + /* Close the key */ RegCloseKey(DatabaseKey); /* Expand the name */ ExpandEnvironmentStrings(DatabasePath, ExpandedPath, MAX_PATH); + + HeapFree(WsSockHeap, 0, DatabasePath); } else { /* Use defalt path */ GetSystemDirectory(ExpandedPath, MAX_PATH); - strcat(ExpandedPath, "DRIVERS\\ETC\\"); + if (ExpandedPath[strlen(ExpandedPath) - 1] != '\\') + { + /* It isn't, so add it ourselves */ + strncat(ExpandedPath, "\\", MAX_PATH); + } + strncat(ExpandedPath, "DRIVERS\\ETC\\", MAX_PATH); } /* Make sure that the path is backslash-terminated */ if (ExpandedPath[strlen(ExpandedPath) - 1] != '\\') { /* It isn't, so add it ourselves */ - strcat(ExpandedPath, "\\"); + strncat(ExpandedPath, "\\", MAX_PATH); } /* Add the database name */ - strcat(ExpandedPath, Name); + strncat(ExpandedPath, Name, MAX_PATH); /* Return a handle to the file */ - return CreateFile(ExpandedPath, + ret = CreateFile(ExpandedPath, FILE_READ_ACCESS, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, - NULL); + NULL); + + HeapFree(WsSockHeap, 0, ExpandedPath); + return ret; } PCHAR -- 1.9.5.msysgit.0