From ba42e43e970a3a2f5299df4f36fb283c7cc9526b Mon Sep 17 00:00:00 2001 From: fvogel Date: Fri, 18 May 2018 06:18:56 +0000 Subject: Add test filesystem-1.30.1 checking file normalize ~$::tcl_platform(user). This test should currently fail when the computer is connected to a Windows domain controller, due to [9e6b569963]: file normalize ~user fails on Windows --- tests/fileSystem.test | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/fileSystem.test b/tests/fileSystem.test index b805780..edc1df2 100644 --- a/tests/fileSystem.test +++ b/tests/fileSystem.test @@ -264,6 +264,9 @@ removeDirectory dir.dir test filesystem-1.30 {normalisation of nonexistent user} -body { file normalize ~noonewiththisname } -returnCodes error -result {user "noonewiththisname" doesn't exist} +test filesystem-1.30.1 {normalisation of existing user} -body { + catch {file normalize ~$::tcl_platform(user)} +} -result {0} test filesystem-1.31 {link normalisation: link near filesystem root} {testsetplatform} { testsetplatform unix file normalize /foo/../bar -- cgit v0.12 From 423f761169b37ab7bd60fa145f1b2a63c4075db0 Mon Sep 17 00:00:00 2001 From: fvogel Date: Fri, 18 May 2018 19:54:56 +0000 Subject: Fix [9e6b569963]: file normalize ~user fails on Windows --- win/tclWinFile.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/win/tclWinFile.c b/win/tclWinFile.c index 9afe0a9..beab147 100644 --- a/win/tclWinFile.c +++ b/win/tclWinFile.c @@ -1444,6 +1444,7 @@ TclpGetUserHome( char *domain; WCHAR *wName, *wHomeDir, *wDomain, **wDomainPtr = &wDomain; WCHAR buf[MAX_PATH]; + LPCWSTR wServername = NULL; Tcl_DStringInit(bufferPtr); wDomain = NULL; @@ -1458,7 +1459,8 @@ TclpGetUserHome( if (badDomain == 0) { Tcl_DStringInit(&ds); wName = Tcl_UtfToUniCharDString(name, nameLen, &ds); - if (NetUserGetInfo(wDomain, wName, 1, (LPBYTE *) uiPtrPtr) == 0) { + NetGetDCName(NULL, wDomain, (LPBYTE *) &wServername); + if (NetUserGetInfo(wServername, wName, 1, (LPBYTE *) uiPtrPtr) == 0) { wHomeDir = uiPtr->usri1_home_dir; if ((wHomeDir != NULL) && (wHomeDir[0] != L'\0')) { Tcl_UniCharToUtfDString(wHomeDir, lstrlenW(wHomeDir), -- cgit v0.12 From dffe6bc7f17cc047da64213a097fe2f9b3a58865 Mon Sep 17 00:00:00 2001 From: fvogel Date: Sat, 19 May 2018 07:10:43 +0000 Subject: Add test filesystem-1.30.2 {normalisation of nonexistent user specified as user@domain} --- tests/fileSystem.test | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/fileSystem.test b/tests/fileSystem.test index edc1df2..f778112 100644 --- a/tests/fileSystem.test +++ b/tests/fileSystem.test @@ -267,6 +267,9 @@ test filesystem-1.30 {normalisation of nonexistent user} -body { test filesystem-1.30.1 {normalisation of existing user} -body { catch {file normalize ~$::tcl_platform(user)} } -result {0} +test filesystem-1.30.2 {normalisation of nonexistent user specified as user@domain} -body { + file normalize ~nonexistentuser@nonexistentdomain +} -returnCodes error -result {user "nonexistentuser@nonexistentdomain" doesn't exist} test filesystem-1.31 {link normalisation: link near filesystem root} {testsetplatform} { testsetplatform unix file normalize /foo/../bar -- cgit v0.12 From 36a1a69178cf1667f7ddd31ee00274f9e7709139 Mon Sep 17 00:00:00 2001 From: fvogel Date: Wed, 23 May 2018 21:08:01 +0000 Subject: Add support for ~domain\user style user names, with new test test filesystem-1.30.3. Warning: does not yet work. --- tests/fileSystem.test | 3 +++ win/tclWinFile.c | 18 +++++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/tests/fileSystem.test b/tests/fileSystem.test index f778112..277fcd3 100644 --- a/tests/fileSystem.test +++ b/tests/fileSystem.test @@ -270,6 +270,9 @@ test filesystem-1.30.1 {normalisation of existing user} -body { test filesystem-1.30.2 {normalisation of nonexistent user specified as user@domain} -body { file normalize ~nonexistentuser@nonexistentdomain } -returnCodes error -result {user "nonexistentuser@nonexistentdomain" doesn't exist} +test filesystem-1.30.3 {normalisation of nonexistent user specified as domain\user} -body { + file normalize ~nonexistentdomain\\nonexistentuser +} -returnCodes error -result {user "nonexistentdomain\nonexistentuser" doesn't exist} test filesystem-1.31 {link normalisation: link near filesystem root} {testsetplatform} { testsetplatform unix file normalize /foo/../bar diff --git a/win/tclWinFile.c b/win/tclWinFile.c index beab147..b8fb046 100644 --- a/win/tclWinFile.c +++ b/win/tclWinFile.c @@ -1441,11 +1441,13 @@ TclpGetUserHome( Tcl_DString ds; int nameLen = -1; int badDomain = 0; - char *domain; + char *domain, *user; + const char *nameStart; WCHAR *wName, *wHomeDir, *wDomain, **wDomainPtr = &wDomain; WCHAR buf[MAX_PATH]; LPCWSTR wServername = NULL; + nameStart = name; Tcl_DStringInit(bufferPtr); wDomain = NULL; domain = strchr(name, '@'); @@ -1455,10 +1457,20 @@ TclpGetUserHome( badDomain = NetGetDCName(NULL, wName, (LPBYTE *) wDomainPtr); Tcl_DStringFree(&ds); nameLen = domain - name; + } else { + user = strchr(name, '\\'); + if (user != NULL) { + Tcl_DStringInit(&ds); + wName = Tcl_UtfToUniCharDString(name, user - name, &ds); + badDomain = NetGetDCName(NULL, wName, (LPBYTE *) wDomainPtr); + Tcl_DStringFree(&ds); + nameStart = user + 1; + nameLen = name + strlen(name) - 1 - user; + } } if (badDomain == 0) { Tcl_DStringInit(&ds); - wName = Tcl_UtfToUniCharDString(name, nameLen, &ds); + wName = Tcl_UtfToUniCharDString(nameStart, nameLen, &ds); NetGetDCName(NULL, wDomain, (LPBYTE *) &wServername); if (NetUserGetInfo(wServername, wName, 1, (LPBYTE *) uiPtrPtr) == 0) { wHomeDir = uiPtr->usri1_home_dir; @@ -1477,7 +1489,7 @@ TclpGetUserHome( } Tcl_UniCharToUtfDString(buf, size-1, bufferPtr); Tcl_DStringAppend(bufferPtr, "/", -1); - Tcl_DStringAppend(bufferPtr, name, -1); + Tcl_DStringAppend(bufferPtr, nameStart, nameLen); } result = Tcl_DStringValue(bufferPtr); NetApiBufferFree((void *) uiPtr); -- cgit v0.12 From 1c13d543f4934c33e441ef5c77a592b9822a8823 Mon Sep 17 00:00:00 2001 From: sebres Date: Thu, 24 May 2018 20:49:12 +0000 Subject: [9e6b569963] win: if user specified without domain (and local user was not found), try to resolve user-home using current domain, so following code's are similar: file normalize ~$::tcl_platform(user)@$::env(USERDOMAIN) file normalize ~$::tcl_platform(user) --- win/tclWinFile.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/win/tclWinFile.c b/win/tclWinFile.c index 1acc225..a3fad1d 100755 --- a/win/tclWinFile.c +++ b/win/tclWinFile.c @@ -1446,30 +1446,41 @@ TclpGetUserHome( GetProcAddress(userenvInst, "GetProfilesDirectoryW"); if ((netUserGetInfoProc != NULL) && (netGetDCNameProc != NULL) && (netApiBufferFreeProc != NULL) && (getProfilesDirectoryProc != NULL)) { - USER_INFO_1 *uiPtr, **uiPtrPtr = &uiPtr; + USER_INFO_1 *uiPtr; Tcl_DString ds; - int nameLen, badDomain; + int nameLen, rc; char *domain; WCHAR *wName, *wHomeDir, *wDomain; WCHAR buf[MAX_PATH]; - badDomain = 0; + rc = 0; nameLen = -1; wDomain = NULL; domain = strchr(name, '@'); if (domain != NULL) { Tcl_DStringInit(&ds); wName = Tcl_UtfToUniCharDString(domain + 1, -1, &ds); - badDomain = (netGetDCNameProc)(NULL, wName, - (LPBYTE *) &wDomain); + rc = (netGetDCNameProc)(NULL, wName, (LPBYTE *) &wDomain); Tcl_DStringFree(&ds); nameLen = domain - name; } - if (badDomain == 0) { + if (rc == 0) { Tcl_DStringInit(&ds); wName = Tcl_UtfToUniCharDString(name, nameLen, &ds); - if ((netUserGetInfoProc)(wDomain, wName, 1, - (LPBYTE *) uiPtrPtr) == 0) { + while ((netUserGetInfoProc)(wDomain, wName, 1, + (LPBYTE *) &uiPtr) != 0) { + /* + * user does not exists - if domain was not specified, + * try again using current domain. + */ + rc = 1; + if (domain != NULL) break; + /* get current domain */ + rc = (netGetDCNameProc)(NULL, NULL, (LPBYTE *) &wDomain); + if (rc != 0) break; + domain = INT2PTR(-1); /* repeat once */ + } + if (rc == 0) { DWORD i, size = MAX_PATH; wHomeDir = uiPtr->usri1_home_dir; if ((wHomeDir != NULL) && (wHomeDir[0] != L'\0')) { -- cgit v0.12 From 6d943ef7b5327ee4ccdf46fecd74ecbb5f75ca73 Mon Sep 17 00:00:00 2001 From: fvogel Date: Thu, 24 May 2018 20:51:45 +0000 Subject: Remove test filesystem-1.30.3, this is unstestable --- tests/fileSystem.test | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/fileSystem.test b/tests/fileSystem.test index 277fcd3..f778112 100644 --- a/tests/fileSystem.test +++ b/tests/fileSystem.test @@ -270,9 +270,6 @@ test filesystem-1.30.1 {normalisation of existing user} -body { test filesystem-1.30.2 {normalisation of nonexistent user specified as user@domain} -body { file normalize ~nonexistentuser@nonexistentdomain } -returnCodes error -result {user "nonexistentuser@nonexistentdomain" doesn't exist} -test filesystem-1.30.3 {normalisation of nonexistent user specified as domain\user} -body { - file normalize ~nonexistentdomain\\nonexistentuser -} -returnCodes error -result {user "nonexistentdomain\nonexistentuser" doesn't exist} test filesystem-1.31 {link normalisation: link near filesystem root} {testsetplatform} { testsetplatform unix file normalize /foo/../bar -- cgit v0.12 From a0290b85c51fde9541564338e5b7908153f0cc96 Mon Sep 17 00:00:00 2001 From: sebres Date: Fri, 25 May 2018 15:04:27 +0000 Subject: optimized winapi-stubs loading (8.5th only); if user name specified without domain and equals the current user - try safest and fastest way to get current user-home path (without usage of netapi) --- win/tclWinFile.c | 187 ++++++++++++++++++++++++++++++++----------------------- win/tclWinInit.c | 34 ++++++---- win/tclWinInt.h | 2 + 3 files changed, 134 insertions(+), 89 deletions(-) diff --git a/win/tclWinFile.c b/win/tclWinFile.c index a3fad1d..3819960 100755 --- a/win/tclWinFile.c +++ b/win/tclWinFile.c @@ -1422,95 +1422,126 @@ TclpGetUserHome( * name of user's home directory. */ { char *result; - HINSTANCE netapiInst; - HINSTANCE userenvInst; + + static NETAPIBUFFERFREEPROC *netApiBufferFreeProc; + static NETGETDCNAMEPROC *netGetDCNameProc; + static NETUSERGETINFOPROC *netUserGetInfoProc; + static GETPROFILESDIRECTORYPROC *getProfilesDirectoryProc; + static int apistubs = 0; result = NULL; Tcl_DStringInit(bufferPtr); - netapiInst = LoadLibraryA("netapi32.dll"); - userenvInst = LoadLibraryA("userenv.dll"); - if (netapiInst != NULL && userenvInst != NULL) { - NETAPIBUFFERFREEPROC *netApiBufferFreeProc; - NETGETDCNAMEPROC *netGetDCNameProc; - NETUSERGETINFOPROC *netUserGetInfoProc; - GETPROFILESDIRECTORYPROC *getProfilesDirectoryProc; - - netApiBufferFreeProc = (NETAPIBUFFERFREEPROC *) - GetProcAddress(netapiInst, "NetApiBufferFree"); - netGetDCNameProc = (NETGETDCNAMEPROC *) - GetProcAddress(netapiInst, "NetGetDCName"); - netUserGetInfoProc = (NETUSERGETINFOPROC *) - GetProcAddress(netapiInst, "NetUserGetInfo"); - getProfilesDirectoryProc = (GETPROFILESDIRECTORYPROC *) - GetProcAddress(userenvInst, "GetProfilesDirectoryW"); - if ((netUserGetInfoProc != NULL) && (netGetDCNameProc != NULL) - && (netApiBufferFreeProc != NULL) && (getProfilesDirectoryProc != NULL)) { - USER_INFO_1 *uiPtr; - Tcl_DString ds; - int nameLen, rc; - char *domain; - WCHAR *wName, *wHomeDir, *wDomain; - WCHAR buf[MAX_PATH]; - - rc = 0; - nameLen = -1; - wDomain = NULL; - domain = strchr(name, '@'); - if (domain != NULL) { - Tcl_DStringInit(&ds); - wName = Tcl_UtfToUniCharDString(domain + 1, -1, &ds); - rc = (netGetDCNameProc)(NULL, wName, (LPBYTE *) &wDomain); - Tcl_DStringFree(&ds); - nameLen = domain - name; + if (!apistubs) { + HINSTANCE handle; + TCL_DECLARE_MUTEX(initializeMutex) + Tcl_MutexLock(&initializeMutex); + + handle = LoadLibraryA("netapi32.dll"); + if (handle) { + netApiBufferFreeProc = (NETAPIBUFFERFREEPROC *) + GetProcAddress(handle, "NetApiBufferFree"); + netGetDCNameProc = (NETGETDCNAMEPROC *) + GetProcAddress(handle, "NetGetDCName"); + netUserGetInfoProc = (NETUSERGETINFOPROC *) + GetProcAddress(handle, "NetUserGetInfo"); + Tcl_CreateExitHandler(TclpUnloadFile, handle); + } + handle = LoadLibraryA("userenv.dll"); + if (handle) { + getProfilesDirectoryProc = (GETPROFILESDIRECTORYPROC *) + GetProcAddress(handle, "GetProfilesDirectoryW"); + Tcl_CreateExitHandler(TclpUnloadFile, handle); + } + + apistubs = -1; + if ( (netUserGetInfoProc != NULL) && (netGetDCNameProc != NULL) + && (netApiBufferFreeProc != NULL) && (getProfilesDirectoryProc != NULL) + ) { + apistubs = 1; + } + Tcl_MutexUnlock(&initializeMutex); + } + + if (apistubs == 1) { + USER_INFO_1 *uiPtr; + Tcl_DString ds; + int nameLen, rc; + char *domain; + WCHAR *wName, *wHomeDir, *wDomain; + WCHAR buf[MAX_PATH]; + + rc = 0; + nameLen = -1; + wDomain = NULL; + domain = strchr(name, '@'); + if (domain == NULL) { + const char *ptr; + + /* no domain - firstly check it's the current user */ + if ( (ptr = TclpGetUserName(&ds)) != NULL + && strcasecmp(name, ptr) == 0 + ) { + /* try safest and fastest way to get current user home */ + ptr = TclGetEnv("HOME", &ds); + if (ptr != NULL) { + Tcl_JoinPath(1, &ptr, bufferPtr); + rc = 1; + result = Tcl_DStringValue(bufferPtr); + } + } + Tcl_DStringFree(&ds); + } else { + Tcl_DStringInit(&ds); + wName = Tcl_UtfToUniCharDString(domain + 1, -1, &ds); + rc = (netGetDCNameProc)(NULL, wName, (LPBYTE *) &wDomain); + Tcl_DStringFree(&ds); + nameLen = domain - name; + } + if (rc == 0) { + Tcl_DStringInit(&ds); + wName = Tcl_UtfToUniCharDString(name, nameLen, &ds); + while ((netUserGetInfoProc)(wDomain, wName, 1, + (LPBYTE *) &uiPtr) != 0) { + /* + * user does not exists - if domain was not specified, + * try again using current domain. + */ + rc = 1; + if (domain != NULL) break; + /* get current domain */ + rc = (netGetDCNameProc)(NULL, NULL, (LPBYTE *) &wDomain); + if (rc != 0) break; + domain = INT2PTR(-1); /* repeat once */ } if (rc == 0) { - Tcl_DStringInit(&ds); - wName = Tcl_UtfToUniCharDString(name, nameLen, &ds); - while ((netUserGetInfoProc)(wDomain, wName, 1, - (LPBYTE *) &uiPtr) != 0) { - /* - * user does not exists - if domain was not specified, - * try again using current domain. + DWORD i, size = MAX_PATH; + wHomeDir = uiPtr->usri1_home_dir; + if ((wHomeDir != NULL) && (wHomeDir[0] != L'\0')) { + size = lstrlenW(wHomeDir); + Tcl_UniCharToUtfDString(wHomeDir, size, bufferPtr); + } else { + /* + * User exists but has no home dir. Return + * "{GetProfilesDirectory}/". */ - rc = 1; - if (domain != NULL) break; - /* get current domain */ - rc = (netGetDCNameProc)(NULL, NULL, (LPBYTE *) &wDomain); - if (rc != 0) break; - domain = INT2PTR(-1); /* repeat once */ + getProfilesDirectoryProc(buf, &size); + Tcl_UniCharToUtfDString(buf, size-1, bufferPtr); + Tcl_DStringAppend(bufferPtr, "/", 1); + Tcl_DStringAppend(bufferPtr, name, nameLen); } - if (rc == 0) { - DWORD i, size = MAX_PATH; - wHomeDir = uiPtr->usri1_home_dir; - if ((wHomeDir != NULL) && (wHomeDir[0] != L'\0')) { - size = lstrlenW(wHomeDir); - Tcl_UniCharToUtfDString(wHomeDir, size, bufferPtr); - } else { - /* - * User exists but has no home dir. Return - * "{GetProfilesDirectory}/". - */ - getProfilesDirectoryProc(buf, &size); - Tcl_UniCharToUtfDString(buf, size-1, bufferPtr); - Tcl_DStringAppend(bufferPtr, "/", 1); - Tcl_DStringAppend(bufferPtr, name, nameLen); - } - result = Tcl_DStringValue(bufferPtr); - /* be sure we returns normalized path */ - for (i = 0; i < size; ++i){ - if (result[i] == '\\') result[i] = '/'; - } - (*netApiBufferFreeProc)((void *) uiPtr); + result = Tcl_DStringValue(bufferPtr); + /* be sure we returns normalized path */ + for (i = 0; i < size; ++i){ + if (result[i] == '\\') result[i] = '/'; } - Tcl_DStringFree(&ds); - } - if (wDomain != NULL) { - (*netApiBufferFreeProc)((void *) wDomain); + (*netApiBufferFreeProc)((void *) uiPtr); } + Tcl_DStringFree(&ds); + } + if (wDomain != NULL) { + (*netApiBufferFreeProc)((void *) wDomain); } - FreeLibrary(userenvInst); - FreeLibrary(netapiInst); } if (result == NULL) { /* diff --git a/win/tclWinInit.c b/win/tclWinInit.c index 1ba7a31..7fa2b7a 100644 --- a/win/tclWinInit.c +++ b/win/tclWinInit.c @@ -532,6 +532,27 @@ Tcl_GetEncodingNameFromEnvironment( return Tcl_DStringValue(bufPtr); } +const char * +TclpGetUserName( + Tcl_DString *bufferPtr) /* Uninitialized or free DString filled with + * the name of user. */ +{ + Tcl_DStringInit(bufferPtr); + + if (TclGetEnv("USERNAME", bufferPtr) == NULL) { + WCHAR szUserName[UNLEN+1]; + DWORD cchUserNameLen = UNLEN; + + if (!tclWinProcs->getUserName((LPTSTR)szUserName, &cchUserNameLen)) { + return NULL; + } + cchUserNameLen--; + if (tclWinProcs->useWide) cchUserNameLen *= sizeof(WCHAR); + Tcl_WinTCharToUtf((LPTSTR)szUserName, cchUserNameLen, bufferPtr); + } + return Tcl_DStringValue(bufferPtr); +} + /* *--------------------------------------------------------------------------- * @@ -562,8 +583,6 @@ TclpSetVariables( static OSVERSIONINFOW osInfo; static int osInfoInitialized = 0; Tcl_DString ds; - WCHAR szUserName[UNLEN+1]; - DWORD cchUserNameLen = UNLEN; Tcl_SetVar2Ex(interp, "tclDefaultLibrary", NULL, TclGetProcessGlobalValue(&defaultLibraryDir), TCL_GLOBAL_ONLY); @@ -641,15 +660,8 @@ TclpSetVariables( * Note: cchUserNameLen is number of characters including nul terminator. */ - Tcl_DStringInit(&ds); - if (TclGetEnv("USERNAME", &ds) == NULL) { - if (tclWinProcs->getUserName((LPTSTR)szUserName, &cchUserNameLen) != 0) { - int cbUserNameLen = cchUserNameLen - 1; - if (tclWinProcs->useWide) cbUserNameLen *= sizeof(WCHAR); - Tcl_WinTCharToUtf((LPTSTR)szUserName, cbUserNameLen, &ds); - } - } - Tcl_SetVar2(interp, "tcl_platform", "user", Tcl_DStringValue(&ds), + ptr = TclpGetUserName(&ds); + Tcl_SetVar2(interp, "tcl_platform", "user", ptr ? ptr : "", TCL_GLOBAL_ONLY); Tcl_DStringFree(&ds); } diff --git a/win/tclWinInt.h b/win/tclWinInt.h index ccf48bb..af6619f 100644 --- a/win/tclWinInt.h +++ b/win/tclWinInt.h @@ -201,6 +201,8 @@ MODULE_SCOPE void * TclpGetAllocCache(void); MODULE_SCOPE void TclpSetAllocCache(void *); #endif /* TCL_THREADS */ +MODULE_SCOPE const char*TclpGetUserName(Tcl_DString *bufferPtr); + /* Needed by tclWinFile.c and tclWinFCmd.c */ #ifndef FILE_ATTRIBUTE_REPARSE_POINT #define FILE_ATTRIBUTE_REPARSE_POINT 0x00000400 -- cgit v0.12 From f4651a56605698bf681e88594e7a97d8acd50fac Mon Sep 17 00:00:00 2001 From: sebres Date: Fri, 25 May 2018 15:48:50 +0000 Subject: avoid dual init of stubs (possible race condition, 8.5th only) --- win/tclWinFile.c | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/win/tclWinFile.c b/win/tclWinFile.c index 3819960..2395ae1 100755 --- a/win/tclWinFile.c +++ b/win/tclWinFile.c @@ -1436,29 +1436,30 @@ TclpGetUserHome( HINSTANCE handle; TCL_DECLARE_MUTEX(initializeMutex) Tcl_MutexLock(&initializeMutex); - - handle = LoadLibraryA("netapi32.dll"); - if (handle) { - netApiBufferFreeProc = (NETAPIBUFFERFREEPROC *) + if (!apistubs) { + handle = LoadLibraryA("netapi32.dll"); + if (handle) { + netApiBufferFreeProc = (NETAPIBUFFERFREEPROC *) GetProcAddress(handle, "NetApiBufferFree"); - netGetDCNameProc = (NETGETDCNAMEPROC *) + netGetDCNameProc = (NETGETDCNAMEPROC *) GetProcAddress(handle, "NetGetDCName"); - netUserGetInfoProc = (NETUSERGETINFOPROC *) + netUserGetInfoProc = (NETUSERGETINFOPROC *) GetProcAddress(handle, "NetUserGetInfo"); - Tcl_CreateExitHandler(TclpUnloadFile, handle); - } - handle = LoadLibraryA("userenv.dll"); - if (handle) { - getProfilesDirectoryProc = (GETPROFILESDIRECTORYPROC *) + Tcl_CreateExitHandler(TclpUnloadFile, handle); + } + handle = LoadLibraryA("userenv.dll"); + if (handle) { + getProfilesDirectoryProc = (GETPROFILESDIRECTORYPROC *) GetProcAddress(handle, "GetProfilesDirectoryW"); - Tcl_CreateExitHandler(TclpUnloadFile, handle); - } - - apistubs = -1; - if ( (netUserGetInfoProc != NULL) && (netGetDCNameProc != NULL) - && (netApiBufferFreeProc != NULL) && (getProfilesDirectoryProc != NULL) - ) { - apistubs = 1; + Tcl_CreateExitHandler(TclpUnloadFile, handle); + } + + apistubs = -1; + if ( (netUserGetInfoProc != NULL) && (netGetDCNameProc != NULL) + && (netApiBufferFreeProc != NULL) && (getProfilesDirectoryProc != NULL) + ) { + apistubs = 1; + } } Tcl_MutexUnlock(&initializeMutex); } -- cgit v0.12 From 5e7a1545a61ab4e66c1796ad19343e15cd2cc2ba Mon Sep 17 00:00:00 2001 From: sebres Date: Fri, 25 May 2018 15:51:23 +0000 Subject: minor indentation fix (no functional changes) --- win/tclWinFile.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/win/tclWinFile.c b/win/tclWinFile.c index 2395ae1..0bed39e 100755 --- a/win/tclWinFile.c +++ b/win/tclWinFile.c @@ -1440,17 +1440,17 @@ TclpGetUserHome( handle = LoadLibraryA("netapi32.dll"); if (handle) { netApiBufferFreeProc = (NETAPIBUFFERFREEPROC *) - GetProcAddress(handle, "NetApiBufferFree"); + GetProcAddress(handle, "NetApiBufferFree"); netGetDCNameProc = (NETGETDCNAMEPROC *) - GetProcAddress(handle, "NetGetDCName"); + GetProcAddress(handle, "NetGetDCName"); netUserGetInfoProc = (NETUSERGETINFOPROC *) - GetProcAddress(handle, "NetUserGetInfo"); + GetProcAddress(handle, "NetUserGetInfo"); Tcl_CreateExitHandler(TclpUnloadFile, handle); } handle = LoadLibraryA("userenv.dll"); if (handle) { getProfilesDirectoryProc = (GETPROFILESDIRECTORYPROC *) - GetProcAddress(handle, "GetProfilesDirectoryW"); + GetProcAddress(handle, "GetProfilesDirectoryW"); Tcl_CreateExitHandler(TclpUnloadFile, handle); } -- cgit v0.12 From 6a4d06759ed9c9ac3c94860c9d7b17c076f28b7e Mon Sep 17 00:00:00 2001 From: sebres Date: Mon, 28 May 2018 13:13:39 +0000 Subject: win: searching for FQDN in user-name should be utf-8 safe (user-name could contain non-ascii utf-8 chars) --- win/tclWinFile.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/win/tclWinFile.c b/win/tclWinFile.c index 0bed39e..3655321 100755 --- a/win/tclWinFile.c +++ b/win/tclWinFile.c @@ -1468,14 +1468,14 @@ TclpGetUserHome( USER_INFO_1 *uiPtr; Tcl_DString ds; int nameLen, rc; - char *domain; + const char *domain; WCHAR *wName, *wHomeDir, *wDomain; WCHAR buf[MAX_PATH]; rc = 0; nameLen = -1; wDomain = NULL; - domain = strchr(name, '@'); + domain = Tcl_UtfFindFirst(name, '@'); if (domain == NULL) { const char *ptr; -- cgit v0.12