2002-09-23 22:36:50 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2002 Andriy Palamarchuk
|
|
|
|
*
|
|
|
|
* Conformance test of the access functions.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-09-23 22:36:50 +02:00
|
|
|
*/
|
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#include <windef.h>
|
2002-09-23 22:36:50 +02:00
|
|
|
#include <winbase.h>
|
|
|
|
#include <winerror.h>
|
|
|
|
#include <lmaccess.h>
|
|
|
|
#include <lmerr.h>
|
|
|
|
#include <lmapibuf.h>
|
|
|
|
|
2007-03-19 16:48:39 +01:00
|
|
|
#include "wine/test.h"
|
|
|
|
|
2002-09-23 22:36:50 +02:00
|
|
|
WCHAR user_name[UNLEN + 1];
|
|
|
|
WCHAR computer_name[MAX_COMPUTERNAME_LENGTH + 1];
|
|
|
|
|
2007-03-23 11:32:36 +01:00
|
|
|
/* FIXME : Tests should be language independent */
|
2004-04-19 22:12:14 +02:00
|
|
|
static const WCHAR sAdminUserName[] = {'A','d','m','i','n','i','s','t','r','a','t',
|
2002-09-23 22:36:50 +02:00
|
|
|
'o','r',0};
|
2004-04-19 22:12:14 +02:00
|
|
|
static const WCHAR sGuestUserName[] = {'G','u','e','s','t',0};
|
|
|
|
static const WCHAR sNonexistentUser[] = {'N','o','n','e','x','i','s','t','e','n','t',' ',
|
2002-09-23 22:36:50 +02:00
|
|
|
'U','s','e','r',0};
|
2007-03-24 09:00:34 +01:00
|
|
|
static WCHAR sTooLongName[] = {'T','h','i','s',' ','i','s',' ','a',' ','b','a','d',
|
|
|
|
' ','u','s','e','r','n','a','m','e',0};
|
|
|
|
static WCHAR sTooLongPassword[] = {'a','b','c','d','e','f','g','h','a','b','c','d','e','f','g','h',
|
|
|
|
'a','b','c','d','e','f','g','h','a','b','c','d','e','f','g','h','a','b','c','d','e','f','g','h',
|
|
|
|
'a','b','c','d','e','f','g','h','a','b','c','d','e','f','g','h','a','b','c','d','e','f','g','h',
|
|
|
|
'a','b','c','d','e','f','g','h','a','b','c','d','e','f','g','h','a','b','c','d','e','f','g','h',
|
|
|
|
'a','b','c','d','e','f','g','h','a','b','c','d','e','f','g','h','a','b','c','d','e','f','g','h',
|
|
|
|
'a','b','c','d','e','f','g','h','a','b','c','d','e','f','g','h','a','b','c','d','e','f','g','h',
|
|
|
|
'a','b','c','d','e','f','g','h','a','b','c','d','e','f','g','h','a','b','c','d','e','f','g','h',
|
|
|
|
'a','b','c','d','e','f','g','h','a','b','c','d','e','f','g','h','a','b','c','d','e','f','g','h',
|
|
|
|
'a','b','c','d','e','f','g','h','a','b','c','d','e','f','g','h','a','b','c','d','e','f','g','h',
|
|
|
|
'a','b','c','d','e','f','g','h','a','b','c','d','e','f','g','h','a','b','c','d','e','f','g','h',
|
|
|
|
'a','b','c','d','e','f','g','h','a','b','c','d','e','f','g','h','a','b','c','d','e','f','g','h',
|
|
|
|
'a', 0};
|
|
|
|
|
|
|
|
static WCHAR sTestUserName[] = {'t', 'e', 's', 't', 'u', 's', 'e', 'r', 0};
|
|
|
|
static WCHAR sTestUserOldPass[] = {'o', 'l', 'd', 'p', 'a', 's', 's', 0};
|
|
|
|
static WCHAR sTestUserNewPass[] = {'n', 'e', 'w', 'p', 'a', 's', 's', 0};
|
2004-04-19 22:12:14 +02:00
|
|
|
static const WCHAR sBadNetPath[] = {'\\','\\','B','a',' ',' ','p','a','t','h',0};
|
|
|
|
static const WCHAR sInvalidName[] = {'\\',0};
|
|
|
|
static const WCHAR sInvalidName2[] = {'\\','\\',0};
|
|
|
|
static const WCHAR sEmptyStr[] = { 0 };
|
2002-09-23 22:36:50 +02:00
|
|
|
|
2002-12-19 02:04:12 +01:00
|
|
|
static NET_API_STATUS (WINAPI *pNetApiBufferFree)(LPVOID)=NULL;
|
|
|
|
static NET_API_STATUS (WINAPI *pNetApiBufferSize)(LPVOID,LPDWORD)=NULL;
|
|
|
|
static NET_API_STATUS (WINAPI *pNetQueryDisplayInformation)(LPWSTR,DWORD,DWORD,DWORD,DWORD,LPDWORD,PVOID*)=NULL;
|
|
|
|
static NET_API_STATUS (WINAPI *pNetUserGetInfo)(LPCWSTR,LPCWSTR,DWORD,LPBYTE*)=NULL;
|
2006-04-22 16:22:48 +02:00
|
|
|
static NET_API_STATUS (WINAPI *pNetUserModalsGet)(LPCWSTR,DWORD,LPBYTE*)=NULL;
|
2007-03-19 16:48:39 +01:00
|
|
|
static NET_API_STATUS (WINAPI *pNetUserAdd)(LPCWSTR,DWORD,LPBYTE,LPDWORD)=NULL;
|
|
|
|
static NET_API_STATUS (WINAPI *pNetUserChangePassword)(LPCWSTR,LPCWSTR,LPCWSTR,LPCWSTR)=NULL;
|
|
|
|
static NET_API_STATUS (WINAPI *pNetUserDel)(LPCWSTR,LPCWSTR)=NULL;
|
2002-09-23 22:36:50 +02:00
|
|
|
|
2002-12-19 02:04:12 +01:00
|
|
|
static int init_access_tests(void)
|
2002-09-23 22:36:50 +02:00
|
|
|
{
|
|
|
|
DWORD dwSize;
|
2002-12-19 02:04:12 +01:00
|
|
|
BOOL rc;
|
2002-09-23 22:36:50 +02:00
|
|
|
|
|
|
|
user_name[0] = 0;
|
|
|
|
dwSize = sizeof(user_name);
|
2002-12-19 02:04:12 +01:00
|
|
|
rc=GetUserNameW(user_name, &dwSize);
|
|
|
|
if (rc==FALSE && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
|
2007-03-19 09:39:11 +01:00
|
|
|
{
|
2007-03-23 11:32:36 +01:00
|
|
|
skip("GetUserNameW is not available.\n");
|
2002-12-19 02:04:12 +01:00
|
|
|
return 0;
|
2007-03-19 09:39:11 +01:00
|
|
|
}
|
2004-01-27 21:13:03 +01:00
|
|
|
ok(rc, "User Name Retrieved\n");
|
2002-09-23 22:36:50 +02:00
|
|
|
|
|
|
|
computer_name[0] = 0;
|
|
|
|
dwSize = sizeof(computer_name);
|
2004-01-27 21:13:03 +01:00
|
|
|
ok(GetComputerNameW(computer_name, &dwSize), "Computer Name Retrieved\n");
|
2002-12-19 02:04:12 +01:00
|
|
|
return 1;
|
2002-09-23 22:36:50 +02:00
|
|
|
}
|
|
|
|
|
2005-06-20 17:35:54 +02:00
|
|
|
static void run_usergetinfo_tests(void)
|
2002-09-23 22:36:50 +02:00
|
|
|
{
|
2002-12-19 02:04:12 +01:00
|
|
|
NET_API_STATUS rc;
|
2002-09-23 22:36:50 +02:00
|
|
|
PUSER_INFO_0 ui0 = NULL;
|
|
|
|
PUSER_INFO_10 ui10 = NULL;
|
|
|
|
DWORD dwSize;
|
|
|
|
|
|
|
|
/* Level 0 */
|
2002-12-19 02:04:12 +01:00
|
|
|
rc=pNetUserGetInfo(NULL, sAdminUserName, 0, (LPBYTE *)&ui0);
|
2005-03-25 11:24:45 +01:00
|
|
|
if (rc != NERR_Success) {
|
2007-03-19 09:39:11 +01:00
|
|
|
skip("Aborting usergetinfo_tests(). NetUserGetInfo: rc=%d\n", rc);
|
|
|
|
return;
|
2005-03-25 11:24:45 +01:00
|
|
|
}
|
2004-01-27 21:13:03 +01:00
|
|
|
ok(!lstrcmpW(sAdminUserName, ui0->usri0_name), "This is really user name\n");
|
2002-12-19 02:04:12 +01:00
|
|
|
pNetApiBufferSize(ui0, &dwSize);
|
2002-09-23 22:36:50 +02:00
|
|
|
ok(dwSize >= (sizeof(USER_INFO_0) +
|
|
|
|
(lstrlenW(ui0->usri0_name) + 1) * sizeof(WCHAR)),
|
2004-01-27 21:13:03 +01:00
|
|
|
"Is allocated with NetApiBufferAllocate\n");
|
2002-09-23 22:36:50 +02:00
|
|
|
|
|
|
|
/* Level 10 */
|
2002-12-19 02:04:12 +01:00
|
|
|
rc=pNetUserGetInfo(NULL, sAdminUserName, 10, (LPBYTE *)&ui10);
|
2006-10-08 19:35:50 +02:00
|
|
|
ok(rc == NERR_Success, "NetUserGetInfo: rc=%d\n", rc);
|
2004-01-27 21:13:03 +01:00
|
|
|
ok(!lstrcmpW(sAdminUserName, ui10->usri10_name), "This is really user name\n");
|
2002-12-19 02:04:12 +01:00
|
|
|
pNetApiBufferSize(ui10, &dwSize);
|
2002-09-23 22:36:50 +02:00
|
|
|
ok(dwSize >= (sizeof(USER_INFO_10) +
|
|
|
|
(lstrlenW(ui10->usri10_name) + 1 +
|
|
|
|
lstrlenW(ui10->usri10_comment) + 1 +
|
|
|
|
lstrlenW(ui10->usri10_usr_comment) + 1 +
|
|
|
|
lstrlenW(ui10->usri10_full_name) + 1) * sizeof(WCHAR)),
|
2004-01-27 21:13:03 +01:00
|
|
|
"Is allocated with NetApiBufferAllocate\n");
|
2002-09-23 22:36:50 +02:00
|
|
|
|
2002-12-19 02:04:12 +01:00
|
|
|
pNetApiBufferFree(ui0);
|
|
|
|
pNetApiBufferFree(ui10);
|
2002-09-23 22:36:50 +02:00
|
|
|
|
|
|
|
/* errors handling */
|
2002-12-19 02:04:12 +01:00
|
|
|
rc=pNetUserGetInfo(NULL, sAdminUserName, 10000, (LPBYTE *)&ui0);
|
2006-10-08 19:35:50 +02:00
|
|
|
ok(rc == ERROR_INVALID_LEVEL,"Invalid Level: rc=%d\n",rc);
|
2002-12-19 02:04:12 +01:00
|
|
|
rc=pNetUserGetInfo(NULL, sNonexistentUser, 0, (LPBYTE *)&ui0);
|
2006-10-08 19:35:50 +02:00
|
|
|
ok(rc == NERR_UserNotFound,"Invalid User Name: rc=%d\n",rc);
|
2002-09-23 22:36:50 +02:00
|
|
|
todo_wine {
|
|
|
|
/* FIXME - Currently Wine can't verify whether the network path is good or bad */
|
2002-12-19 02:04:12 +01:00
|
|
|
rc=pNetUserGetInfo(sBadNetPath, sAdminUserName, 0, (LPBYTE *)&ui0);
|
2003-09-25 22:29:40 +02:00
|
|
|
ok(rc == ERROR_BAD_NETPATH || rc == ERROR_NETWORK_UNREACHABLE,
|
2006-10-08 19:35:50 +02:00
|
|
|
"Bad Network Path: rc=%d\n",rc);
|
2002-09-23 22:36:50 +02:00
|
|
|
}
|
2002-12-19 02:04:12 +01:00
|
|
|
rc=pNetUserGetInfo(sEmptyStr, sAdminUserName, 0, (LPBYTE *)&ui0);
|
2004-04-05 22:17:45 +02:00
|
|
|
ok(rc == ERROR_BAD_NETPATH || rc == NERR_Success,
|
2006-10-08 19:35:50 +02:00
|
|
|
"Bad Network Path: rc=%d\n",rc);
|
2002-12-19 02:04:12 +01:00
|
|
|
rc=pNetUserGetInfo(sInvalidName, sAdminUserName, 0, (LPBYTE *)&ui0);
|
2006-10-08 19:35:50 +02:00
|
|
|
ok(rc == ERROR_INVALID_NAME,"Invalid Server Name: rc=%d\n",rc);
|
2002-12-19 02:04:12 +01:00
|
|
|
rc=pNetUserGetInfo(sInvalidName2, sAdminUserName, 0, (LPBYTE *)&ui0);
|
2006-10-08 19:35:50 +02:00
|
|
|
ok(rc == ERROR_INVALID_NAME,"Invalid Server Name: rc=%d\n",rc);
|
2002-09-23 22:36:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* checks Level 1 of NetQueryDisplayInformation */
|
2005-06-20 17:35:54 +02:00
|
|
|
static void run_querydisplayinformation1_tests(void)
|
2002-09-23 22:36:50 +02:00
|
|
|
{
|
|
|
|
PNET_DISPLAY_USER Buffer, rec;
|
|
|
|
DWORD Result, EntryCount;
|
|
|
|
DWORD i = 0;
|
|
|
|
BOOL hasAdmin = FALSE;
|
|
|
|
BOOL hasGuest = FALSE;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
2002-12-19 02:04:12 +01:00
|
|
|
Result = pNetQueryDisplayInformation(
|
2002-09-23 22:36:50 +02:00
|
|
|
NULL, 1, i, 1000, MAX_PREFERRED_LENGTH, &EntryCount,
|
|
|
|
(PVOID *)&Buffer);
|
|
|
|
|
|
|
|
ok((Result == ERROR_SUCCESS) || (Result == ERROR_MORE_DATA),
|
2004-01-27 21:13:03 +01:00
|
|
|
"Information Retrieved\n");
|
2002-09-23 22:36:50 +02:00
|
|
|
rec = Buffer;
|
|
|
|
for(; EntryCount > 0; EntryCount--)
|
|
|
|
{
|
|
|
|
if (!lstrcmpW(rec->usri1_name, sAdminUserName))
|
|
|
|
{
|
2004-01-27 21:13:03 +01:00
|
|
|
ok(!hasAdmin, "One admin user\n");
|
|
|
|
ok(rec->usri1_flags & UF_SCRIPT, "UF_SCRIPT flag is set\n");
|
|
|
|
ok(rec->usri1_flags & UF_NORMAL_ACCOUNT, "UF_NORMAL_ACCOUNT flag is set\n");
|
2002-09-23 22:36:50 +02:00
|
|
|
hasAdmin = TRUE;
|
|
|
|
}
|
|
|
|
else if (!lstrcmpW(rec->usri1_name, sGuestUserName))
|
|
|
|
{
|
2004-01-27 21:13:03 +01:00
|
|
|
ok(!hasGuest, "One guest record\n");
|
|
|
|
ok(rec->usri1_flags & UF_SCRIPT, "UF_SCRIPT flag is set\n");
|
|
|
|
ok(rec->usri1_flags & UF_NORMAL_ACCOUNT, "UF_NORMAL_ACCOUNT flag is set\n");
|
2002-09-23 22:36:50 +02:00
|
|
|
hasGuest = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
i = rec->usri1_next_index;
|
|
|
|
rec++;
|
|
|
|
}
|
|
|
|
|
2002-12-19 02:04:12 +01:00
|
|
|
pNetApiBufferFree(Buffer);
|
2002-09-23 22:36:50 +02:00
|
|
|
} while (Result == ERROR_MORE_DATA);
|
|
|
|
|
2004-01-27 21:13:03 +01:00
|
|
|
ok(hasAdmin, "Has Administrator account\n");
|
2002-09-23 22:36:50 +02:00
|
|
|
}
|
|
|
|
|
2006-04-22 16:22:48 +02:00
|
|
|
static void run_usermodalsget_tests(void)
|
|
|
|
{
|
|
|
|
NET_API_STATUS rc;
|
|
|
|
USER_MODALS_INFO_2 * umi2 = NULL;
|
|
|
|
|
|
|
|
rc = pNetUserModalsGet(NULL, 2, (LPBYTE *)&umi2);
|
2006-10-08 19:35:50 +02:00
|
|
|
ok(rc == ERROR_SUCCESS, "NetUserModalsGet failed, rc = %d\n", rc);
|
2006-04-22 16:22:48 +02:00
|
|
|
|
|
|
|
if (umi2)
|
|
|
|
pNetApiBufferFree(umi2);
|
|
|
|
}
|
|
|
|
|
2007-03-19 16:48:39 +01:00
|
|
|
static void run_userhandling_tests(void)
|
|
|
|
{
|
|
|
|
NET_API_STATUS ret;
|
|
|
|
USER_INFO_1 usri;
|
|
|
|
|
|
|
|
usri.usri1_priv = USER_PRIV_USER;
|
|
|
|
usri.usri1_home_dir = NULL;
|
|
|
|
usri.usri1_comment = NULL;
|
|
|
|
usri.usri1_flags = UF_SCRIPT;
|
|
|
|
usri.usri1_script_path = NULL;
|
|
|
|
|
2007-03-24 09:00:34 +01:00
|
|
|
usri.usri1_name = sTooLongName;
|
|
|
|
usri.usri1_password = sTestUserOldPass;
|
|
|
|
|
|
|
|
ret = pNetUserAdd(NULL, 1, (LPBYTE)&usri, NULL);
|
|
|
|
todo_wine ok(ret == NERR_BadUsername, "Adding user with too long username returned 0x%08x\n", ret);
|
|
|
|
|
|
|
|
usri.usri1_name = sTestUserName;
|
|
|
|
usri.usri1_password = sTooLongPassword;
|
|
|
|
|
|
|
|
ret = pNetUserAdd(NULL, 1, (LPBYTE)&usri, NULL);
|
|
|
|
todo_wine ok(ret == NERR_PasswordTooShort, "Adding user with too long password returned 0x%08x\n", ret);
|
|
|
|
|
|
|
|
usri.usri1_name = sTooLongName;
|
|
|
|
usri.usri1_password = sTooLongPassword;
|
|
|
|
|
|
|
|
ret = pNetUserAdd(NULL, 1, (LPBYTE)&usri, NULL);
|
|
|
|
todo_wine ok(ret == NERR_BadUsername,
|
|
|
|
"Adding user with too long username/password returned 0x%08x\n", ret);
|
|
|
|
|
|
|
|
usri.usri1_name = sTestUserName;
|
|
|
|
usri.usri1_password = sTestUserOldPass;
|
|
|
|
|
|
|
|
ret = pNetUserAdd(NULL, 5, (LPBYTE)&usri, NULL);
|
|
|
|
todo_wine ok(ret == ERROR_INVALID_LEVEL, "Adding user with level 5 returned 0x%08x\n", ret);
|
|
|
|
|
2007-03-19 16:48:39 +01:00
|
|
|
ret = pNetUserAdd(NULL, 1, (LPBYTE)&usri, NULL);
|
|
|
|
if(ret == ERROR_ACCESS_DENIED)
|
|
|
|
{
|
|
|
|
skip("Insufficient permissions to add users. Skipping test.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(ret == NERR_UserExists)
|
|
|
|
{
|
|
|
|
skip("User already exists, skipping test to not mess up the system\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ok(ret == NERR_Success, "Adding user failed with error 0x%08x\n", ret);
|
|
|
|
if(ret != NERR_Success)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ret = pNetUserChangePassword(NULL, sTestUserName, sTestUserOldPass,
|
|
|
|
sTestUserNewPass);
|
|
|
|
todo_wine ok(ret == NERR_Success, "Changing the password failed.\n");
|
|
|
|
|
|
|
|
ret = pNetUserDel(NULL, sTestUserName);
|
|
|
|
todo_wine ok(ret == NERR_Success, "Deleting the user failed.\n");
|
|
|
|
}
|
|
|
|
|
2002-09-23 22:36:50 +02:00
|
|
|
START_TEST(access)
|
|
|
|
{
|
2002-12-19 02:04:12 +01:00
|
|
|
HMODULE hnetapi32=LoadLibraryA("netapi32.dll");
|
2007-03-23 11:32:36 +01:00
|
|
|
|
2002-12-19 02:04:12 +01:00
|
|
|
pNetApiBufferFree=(void*)GetProcAddress(hnetapi32,"NetApiBufferFree");
|
|
|
|
pNetApiBufferSize=(void*)GetProcAddress(hnetapi32,"NetApiBufferSize");
|
|
|
|
pNetQueryDisplayInformation=(void*)GetProcAddress(hnetapi32,"NetQueryDisplayInformation");
|
|
|
|
pNetUserGetInfo=(void*)GetProcAddress(hnetapi32,"NetUserGetInfo");
|
2006-04-22 16:22:48 +02:00
|
|
|
pNetUserModalsGet=(void*)GetProcAddress(hnetapi32,"NetUserModalsGet");
|
2007-03-19 16:48:39 +01:00
|
|
|
pNetUserAdd=(void*)GetProcAddress(hnetapi32, "NetUserAdd");
|
|
|
|
pNetUserChangePassword=(void*)GetProcAddress(hnetapi32, "NetUserChangePassword");
|
|
|
|
pNetUserDel=(void*)GetProcAddress(hnetapi32, "NetUserDel");
|
2006-04-22 16:22:48 +02:00
|
|
|
|
2007-03-23 11:32:36 +01:00
|
|
|
/* These functions were introduced with NT. It's safe to assume that
|
|
|
|
* if one is not available, none are.
|
|
|
|
*/
|
|
|
|
if (!pNetApiBufferFree) {
|
|
|
|
skip("Needed functions are not available\n");
|
|
|
|
FreeLibrary(hnetapi32);
|
|
|
|
return;
|
|
|
|
}
|
2002-12-19 02:04:12 +01:00
|
|
|
|
|
|
|
if (init_access_tests()) {
|
|
|
|
run_usergetinfo_tests();
|
|
|
|
run_querydisplayinformation1_tests();
|
2006-04-22 16:22:48 +02:00
|
|
|
run_usermodalsget_tests();
|
2007-03-19 16:48:39 +01:00
|
|
|
run_userhandling_tests();
|
2002-12-19 02:04:12 +01:00
|
|
|
}
|
2007-03-23 11:32:36 +01:00
|
|
|
|
|
|
|
FreeLibrary(hnetapi32);
|
2002-09-23 22:36:50 +02:00
|
|
|
}
|