netapi32: Make sure NetUserGetInfo can find the current user.

This commit is contained in:
Kai Blin 2008-07-02 12:26:35 +02:00 committed by Alexandre Julliard
parent bdf180d2a2
commit 20213e49f2
2 changed files with 34 additions and 1 deletions

View File

@ -105,6 +105,34 @@ static struct sam_user* NETAPI_FindUser(LPCWSTR UserName)
return NULL; return NULL;
} }
static BOOL NETAPI_IsCurrentUser(LPCWSTR username)
{
LPWSTR curr_user = NULL;
DWORD dwSize;
BOOL ret = FALSE;
dwSize = LM20_UNLEN+1;
curr_user = HeapAlloc(GetProcessHeap(), 0, dwSize);
if(!curr_user)
{
ERR("Failed to allocate memory for user name.\n");
goto end;
}
if(!GetUserNameW(curr_user, &dwSize))
{
ERR("Failed to get current user's user name.\n");
goto end;
}
if (!lstrcmpW(curr_user, username))
{
ret = TRUE;
}
end:
HeapFree(GetProcessHeap(), 0, curr_user);
return ret;
}
/************************************************************ /************************************************************
* NetUserAdd (NETAPI32.@) * NetUserAdd (NETAPI32.@)
*/ */
@ -226,7 +254,7 @@ NetUserGetInfo(LPCWSTR servername, LPCWSTR username, DWORD level,
return NERR_InvalidComputer; return NERR_InvalidComputer;
} }
if(!NETAPI_FindUser(username)) if(!NETAPI_FindUser(username) && !NETAPI_IsCurrentUser(username))
{ {
TRACE("User %s is unknown.\n", debugstr_w(username)); TRACE("User %s is unknown.\n", debugstr_w(username));
return NERR_UserNotFound; return NERR_UserNotFound;

View File

@ -142,6 +142,11 @@ static void run_usergetinfo_tests(void)
pNetApiBufferFree(ui0); pNetApiBufferFree(ui0);
pNetApiBufferFree(ui10); pNetApiBufferFree(ui10);
/* NetUserGetInfo should always work for the current user. */
rc=pNetUserGetInfo(NULL, user_name, 0, (LPBYTE*)&ui0);
ok(rc == NERR_Success, "NetUsetGetInfo for current user failed: 0x%08x.\n", rc);
pNetApiBufferFree(ui0);
/* errors handling */ /* errors handling */
rc=pNetUserGetInfo(NULL, sTestUserName, 10000, (LPBYTE *)&ui0); rc=pNetUserGetInfo(NULL, sTestUserName, 10000, (LPBYTE *)&ui0);
ok(rc == ERROR_INVALID_LEVEL,"Invalid Level: rc=%d\n",rc); ok(rc == ERROR_INVALID_LEVEL,"Invalid Level: rc=%d\n",rc);