mirror of
https://github.com/reactos/reactos.git
synced 2024-07-06 20:55:16 +00:00
[KERNEL32] Implement NpGetUserNamep()
This commit is contained in:
parent
f7932ba2de
commit
34c39a1336
|
@ -20,17 +20,92 @@ LONG ProcessPipeId;
|
||||||
|
|
||||||
/* FUNCTIONS ******************************************************************/
|
/* FUNCTIONS ******************************************************************/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @implemented
|
||||||
|
*/
|
||||||
static
|
static
|
||||||
BOOL
|
BOOL
|
||||||
NpGetUserNamep(HANDLE hNamedPipe,
|
NpGetUserNamep(HANDLE hNamedPipe,
|
||||||
LPWSTR lpUserName,
|
LPWSTR lpUserName,
|
||||||
DWORD nMaxUserNameSize)
|
DWORD nMaxUserNameSize)
|
||||||
{
|
{
|
||||||
/* FIXME - open the thread token, call ImpersonateNamedPipeClient() and
|
BOOL Ret;
|
||||||
retrieve the user name with GetUserName(), revert the impersonation
|
HANDLE hToken;
|
||||||
and finally restore the thread token */
|
HMODULE hAdvapi;
|
||||||
UNIMPLEMENTED;
|
NTSTATUS Status;
|
||||||
return TRUE;
|
BOOL (WINAPI *pRevertToSelf)(void);
|
||||||
|
BOOL (WINAPI *pGetUserNameW)(LPWSTR lpBuffer, LPDWORD lpnSize);
|
||||||
|
BOOL (WINAPI *pImpersonateNamedPipeClient)(HANDLE hNamedPipe);
|
||||||
|
|
||||||
|
/* Open advapi, we'll funcs from it */
|
||||||
|
hAdvapi = LoadLibraryW(L"advapi32.dll");
|
||||||
|
if (hAdvapi == NULL)
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Import the three required functions */
|
||||||
|
pRevertToSelf = GetProcAddress(hAdvapi, "RevertToSelf");
|
||||||
|
pGetUserNameW = GetProcAddress(hAdvapi, "GetUserNameW");
|
||||||
|
pImpersonateNamedPipeClient = GetProcAddress(hAdvapi, "ImpersonateNamedPipeClient");
|
||||||
|
/* If any couldn't be found, fail */
|
||||||
|
if (pRevertToSelf == NULL || pGetUserNameW == NULL || pImpersonateNamedPipeClient == NULL)
|
||||||
|
{
|
||||||
|
FreeLibrary(hAdvapi);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Now, open the thread token for impersonation */
|
||||||
|
Status = NtOpenThreadToken(NtCurrentThread(), TOKEN_IMPERSONATE, TRUE, &hToken);
|
||||||
|
/* Try to impersonate the pipe client */
|
||||||
|
if (pImpersonateNamedPipeClient(hNamedPipe))
|
||||||
|
{
|
||||||
|
DWORD lpnSize;
|
||||||
|
|
||||||
|
/* It worked, get the user name */
|
||||||
|
lpnSize = nMaxUserNameSize;
|
||||||
|
Ret = pGetUserNameW(lpUserName, &lpnSize);
|
||||||
|
/* Failed to get the thread token? Revert to self */
|
||||||
|
if (!NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
pRevertToSelf();
|
||||||
|
|
||||||
|
FreeLibrary(hAdvapi);
|
||||||
|
return Ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Restore the thread token */
|
||||||
|
Status = NtSetInformationThread(NtCurrentThread(), ThreadImpersonationToken,
|
||||||
|
&hToken, sizeof(HANDLE));
|
||||||
|
/* We cannot fail closing the thread token! */
|
||||||
|
if (!CloseHandle(hToken))
|
||||||
|
{
|
||||||
|
ASSERT(FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set last error if it failed */
|
||||||
|
if (!NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
BaseSetLastNTError(Status);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* If opening the thread token succeed, close it */
|
||||||
|
if (NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
/* We cannot fail closing it! */
|
||||||
|
if (!CloseHandle(hToken))
|
||||||
|
{
|
||||||
|
ASSERT(FALSE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ret = FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
FreeLibrary(hAdvapi);
|
||||||
|
return Ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue