diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2018-05-29 07:23:51 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2018-05-29 07:23:51 (GMT) |
commit | bb503004b6169640fd3be00ab4c09d49368bdf42 (patch) | |
tree | 9e1d6c017847ea8cee4828c60e29253c602b1486 /win/tclWinFile.c | |
parent | 267cdaec036394312cd843ed142d998f7bbee4f3 (diff) | |
parent | a2ce3dab9b2939f21c06358081d0977ec937e106 (diff) | |
download | tcl-bb503004b6169640fd3be00ab4c09d49368bdf42.zip tcl-bb503004b6169640fd3be00ab4c09d49368bdf42.tar.gz tcl-bb503004b6169640fd3be00ab4c09d49368bdf42.tar.bz2 |
merge 8.6
Diffstat (limited to 'win/tclWinFile.c')
-rw-r--r-- | win/tclWinFile.c | 48 |
1 files changed, 38 insertions, 10 deletions
diff --git a/win/tclWinFile.c b/win/tclWinFile.c index a70717e..0595e6c 100644 --- a/win/tclWinFile.c +++ b/win/tclWinFile.c @@ -1438,34 +1438,62 @@ TclpGetUserHome( * name of user's home directory. */ { char *result = NULL; - USER_INFO_1 *uiPtr, **uiPtrPtr = &uiPtr; + USER_INFO_1 *uiPtr; Tcl_DString ds; int nameLen = -1; - int badDomain = 0; - char *domain; + int rc = 0; + const char *domain; WCHAR *wName, *wHomeDir, *wDomain; WCHAR buf[MAX_PATH]; Tcl_DStringInit(bufferPtr); + wDomain = NULL; - domain = strchr(name, '@'); - if (domain != NULL) { + domain = Tcl_UtfFindFirst(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); - badDomain = NetGetDCName(NULL, wName, (LPBYTE *) &wDomain); + rc = NetGetDCName(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 (NetUserGetInfo(wDomain, wName, 1, (LPBYTE *) uiPtrPtr) == 0) { + while (NetUserGetInfo(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 = NetGetDCName(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')) { size = lstrlenW(wHomeDir); - Tcl_UniCharToUtfDString(wHomeDir, size, - bufferPtr); + Tcl_UniCharToUtfDString(wHomeDir, size, bufferPtr); } else { /* * User exists but has no home dir. Return |