From 11cb57a0bf4b9a8b00ba278848712817cb325fc4 Mon Sep 17 00:00:00 2001 From: Bill Zissimopoulos Date: Fri, 27 Oct 2017 15:12:18 -0700 Subject: [PATCH] dll: np: pass username as argument to launcher --- src/dll/np.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/dll/np.c b/src/dll/np.c index 09a2d689..09010b28 100644 --- a/src/dll/np.c +++ b/src/dll/np.c @@ -17,6 +17,7 @@ #include #include +#include #include #include @@ -147,7 +148,7 @@ static inline BOOLEAN FspNpParseRemoteName(PWSTR RemoteName, return TRUE; } -static inline BOOLEAN FspNpParseUserName(PWSTR RemoteName, +static inline BOOLEAN FspNpParseRemoteUserName(PWSTR RemoteName, PWSTR UserName, ULONG UserNameSize/* in chars */) { PWSTR ClassName, InstanceName, P; @@ -168,6 +169,12 @@ static inline BOOLEAN FspNpParseUserName(PWSTR RemoteName, return FALSE; } +static inline BOOLEAN FspNpGetLocalUserName( + PWSTR UserName, ULONG UserNameSize/* in chars */) +{ + return GetUserName(UserName, &UserNameSize); +} + static inline DWORD FspNpCallLauncherPipe(PWSTR PipeBuf, ULONG SendSize, ULONG RecvSize) { DWORD NpResult; @@ -489,6 +496,7 @@ DWORD APIENTRY NPAddConnection(LPNETRESOURCEW lpNetResource, LPWSTR lpPassword, WCHAR LocalNameBuf[3]; PWSTR ClassName, InstanceName, RemoteName, P; ULONG ClassNameLen, InstanceNameLen; + WCHAR LocalUserName[UNLEN + 1]; DWORD CredentialsKind; PWSTR PipeBuf = 0; #if defined(FSP_NP_CREDENTIAL_MANAGER) @@ -517,6 +525,9 @@ DWORD APIENTRY NPAddConnection(LPNETRESOURCEW lpNetResource, LPWSTR lpPassword, return WN_ALREADY_CONNECTED; } + if (!FspNpGetLocalUserName(LocalUserName, sizeof LocalUserName / sizeof LocalUserName[0])) + LocalUserName[0] = L'\0'; + FspNpGetCredentialsKind(lpRemoteName, &CredentialsKind); #if defined(FSP_NP_CREDENTIAL_MANAGER) @@ -571,6 +582,7 @@ DWORD APIENTRY NPAddConnection(LPNETRESOURCEW lpNetResource, LPWSTR lpPassword, memcpy(P, InstanceName, InstanceNameLen * sizeof(WCHAR)); P += InstanceNameLen; *P++ = L'\0'; lstrcpyW(P, RemoteName); P += lstrlenW(RemoteName) + 1; lstrcpyW(P, LocalNameBuf); P += lstrlenW(LocalNameBuf) + 1; + lstrcpyW(P, LocalUserName); P += lstrlenW(LocalUserName) + 1; if (FSP_NP_CREDENTIALS_USERPASS == CredentialsKind) { lstrcpyW(P, lpUserName); P += lstrlenW(lpUserName) + 1; @@ -721,7 +733,7 @@ DWORD APIENTRY NPAddConnection3(HWND hwndOwner, lstrcpyW(UserName, L"UNSPECIFIED"); Password[0] = L'\0'; if (FSP_NP_CREDENTIALS_PASSWORD == CredentialsKind) - FspNpParseUserName(RemoteName, UserName, sizeof UserName / sizeof UserName[0]); + FspNpParseRemoteUserName(RemoteName, UserName, sizeof UserName / sizeof UserName[0]); do { NpResult = FspNpGetCredentials(