2002-09-11 04:35:17 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2002 Andriy Palamarchuk
|
|
|
|
*
|
|
|
|
* Conformance test of the workstation 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-11 04:35:17 +02:00
|
|
|
*/
|
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
2002-09-11 04:35:17 +02:00
|
|
|
#include "wine/test.h"
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "windef.h"
|
2002-09-11 04:35:17 +02:00
|
|
|
#include "winbase.h"
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "wingdi.h"
|
|
|
|
#include "winnls.h"
|
2003-07-19 00:53:49 +02:00
|
|
|
#include "winresrc.h" /* Ensure we use Unicode defns with native headers */
|
2002-09-11 04:35:17 +02:00
|
|
|
#include "nb30.h"
|
|
|
|
#include "lmcons.h"
|
|
|
|
#include "lmerr.h"
|
|
|
|
#include "lmwksta.h"
|
|
|
|
#include "lmapibuf.h"
|
|
|
|
|
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 *pNetpGetComputerName)(LPWSTR*)=NULL;
|
|
|
|
static NET_API_STATUS (WINAPI *pNetWkstaUserGetInfo)(LPWSTR,DWORD,PBYTE*)=NULL;
|
2003-04-30 02:48:56 +02:00
|
|
|
static NET_API_STATUS (WINAPI *pNetWkstaTransportEnum)(LPWSTR,DWORD,LPBYTE*,
|
|
|
|
DWORD,LPDWORD,LPDWORD,LPDWORD)=NULL;
|
2002-09-11 04:35:17 +02:00
|
|
|
|
2010-10-01 13:36:54 +02:00
|
|
|
static WCHAR user_name[UNLEN + 1];
|
|
|
|
static WCHAR computer_name[MAX_COMPUTERNAME_LENGTH + 1];
|
2002-09-23 22:36:50 +02:00
|
|
|
|
2002-12-19 02:04:12 +01:00
|
|
|
static int init_wksta_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;
|
2008-02-25 10:02:26 +01:00
|
|
|
dwSize = sizeof(user_name)/sizeof(user_name[0]);
|
2002-12-19 02:04:12 +01:00
|
|
|
rc=GetUserNameW(user_name, &dwSize);
|
2007-03-23 11:32:36 +01:00
|
|
|
if (rc==FALSE && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED) {
|
2009-02-23 10:42:43 +01:00
|
|
|
win_skip("GetUserNameW is not implemented\n");
|
2002-12-19 02:04:12 +01:00
|
|
|
return 0;
|
2007-03-23 11:32:36 +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;
|
2008-02-25 10:02:26 +01:00
|
|
|
dwSize = sizeof(computer_name)/sizeof(computer_name[0]);
|
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
|
|
|
}
|
|
|
|
|
2002-12-19 02:04:12 +01:00
|
|
|
static void run_get_comp_name_tests(void)
|
2002-09-11 04:35:17 +02:00
|
|
|
{
|
2004-04-20 04:14:00 +02:00
|
|
|
LPWSTR ws = NULL;
|
2002-12-19 02:04:12 +01:00
|
|
|
|
2004-01-27 21:13:03 +01:00
|
|
|
ok(pNetpGetComputerName(&ws) == NERR_Success, "Computer name is retrieved\n");
|
|
|
|
ok(!lstrcmpW(computer_name, ws), "This is really computer name\n");
|
2002-12-19 02:04:12 +01:00
|
|
|
pNetApiBufferFree(ws);
|
2002-09-11 04:35:17 +02:00
|
|
|
}
|
|
|
|
|
2002-12-19 02:04:12 +01:00
|
|
|
static void run_wkstausergetinfo_tests(void)
|
2002-09-11 04:35:17 +02:00
|
|
|
{
|
|
|
|
LPWKSTA_USER_INFO_0 ui0 = NULL;
|
|
|
|
LPWKSTA_USER_INFO_1 ui1 = NULL;
|
|
|
|
LPWKSTA_USER_INFO_1101 ui1101 = NULL;
|
|
|
|
DWORD dwSize;
|
|
|
|
|
|
|
|
/* Level 0 */
|
2002-12-19 02:04:12 +01:00
|
|
|
ok(pNetWkstaUserGetInfo(NULL, 0, (LPBYTE *)&ui0) == NERR_Success,
|
2008-05-06 08:05:08 +02:00
|
|
|
"NetWkstaUserGetInfo is unsuccessful\n");
|
|
|
|
|
|
|
|
ok(ui0 != NULL, "ui0 is NULL\n");
|
2008-06-13 19:49:13 +02:00
|
|
|
/* This failure occurred when I ran sshd as service and didn't authenticate
|
2008-05-06 08:05:08 +02:00
|
|
|
* Since the test dereferences ui0, the rest of this test is worthless
|
|
|
|
*/
|
|
|
|
if (!ui0)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-01-27 21:13:03 +01:00
|
|
|
ok(!lstrcmpW(user_name, ui0->wkui0_username), "This is really user name\n");
|
2002-12-19 02:04:12 +01:00
|
|
|
pNetApiBufferSize(ui0, &dwSize);
|
2002-09-11 04:35:17 +02:00
|
|
|
ok(dwSize >= (sizeof(WKSTA_USER_INFO_0) +
|
|
|
|
lstrlenW(ui0->wkui0_username) * sizeof(WCHAR)),
|
2004-01-27 21:13:03 +01:00
|
|
|
"Is allocated with NetApiBufferAllocate\n");
|
2002-09-11 04:35:17 +02:00
|
|
|
|
|
|
|
/* Level 1 */
|
2002-12-19 02:04:12 +01:00
|
|
|
ok(pNetWkstaUserGetInfo(NULL, 1, (LPBYTE *)&ui1) == NERR_Success,
|
2004-01-27 21:13:03 +01:00
|
|
|
"NetWkstaUserGetInfo is successful\n");
|
2002-09-11 04:35:17 +02:00
|
|
|
ok(lstrcmpW(ui1->wkui1_username, ui0->wkui0_username) == 0,
|
2004-01-27 21:13:03 +01:00
|
|
|
"the same name as returned for level 0\n");
|
2002-12-19 02:04:12 +01:00
|
|
|
pNetApiBufferSize(ui1, &dwSize);
|
2002-09-11 04:35:17 +02:00
|
|
|
ok(dwSize >= (sizeof(WKSTA_USER_INFO_1) +
|
|
|
|
(lstrlenW(ui1->wkui1_username) +
|
|
|
|
lstrlenW(ui1->wkui1_logon_domain) +
|
|
|
|
lstrlenW(ui1->wkui1_oth_domains) +
|
|
|
|
lstrlenW(ui1->wkui1_logon_server)) * sizeof(WCHAR)),
|
2004-01-27 21:13:03 +01:00
|
|
|
"Is allocated with NetApiBufferAllocate\n");
|
2002-09-11 04:35:17 +02:00
|
|
|
|
|
|
|
/* Level 1101 */
|
2002-12-19 02:04:12 +01:00
|
|
|
ok(pNetWkstaUserGetInfo(NULL, 1101, (LPBYTE *)&ui1101) == NERR_Success,
|
2004-01-27 21:13:03 +01:00
|
|
|
"NetWkstaUserGetInfo is successful\n");
|
2002-09-11 04:35:17 +02:00
|
|
|
ok(lstrcmpW(ui1101->wkui1101_oth_domains, ui1->wkui1_oth_domains) == 0,
|
2004-01-27 21:13:03 +01:00
|
|
|
"the same oth_domains as returned for level 1\n");
|
2002-12-19 02:04:12 +01:00
|
|
|
pNetApiBufferSize(ui1101, &dwSize);
|
2002-09-11 04:35:17 +02:00
|
|
|
ok(dwSize >= (sizeof(WKSTA_USER_INFO_1101) +
|
|
|
|
lstrlenW(ui1101->wkui1101_oth_domains) * sizeof(WCHAR)),
|
2004-01-27 21:13:03 +01:00
|
|
|
"Is allocated with NetApiBufferAllocate\n");
|
2002-09-11 04:35:17 +02:00
|
|
|
|
2002-12-19 02:04:12 +01:00
|
|
|
pNetApiBufferFree(ui0);
|
|
|
|
pNetApiBufferFree(ui1);
|
|
|
|
pNetApiBufferFree(ui1101);
|
2002-09-11 04:35:17 +02:00
|
|
|
|
|
|
|
/* errors handling */
|
2002-12-19 02:04:12 +01:00
|
|
|
ok(pNetWkstaUserGetInfo(NULL, 10000, (LPBYTE *)&ui0) == ERROR_INVALID_LEVEL,
|
2004-01-27 21:13:03 +01:00
|
|
|
"Invalid level\n");
|
2002-09-11 04:35:17 +02:00
|
|
|
}
|
|
|
|
|
2003-04-30 02:48:56 +02:00
|
|
|
static void run_wkstatransportenum_tests(void)
|
|
|
|
{
|
|
|
|
LPBYTE bufPtr;
|
|
|
|
NET_API_STATUS apiReturn;
|
|
|
|
DWORD entriesRead, totalEntries;
|
|
|
|
|
|
|
|
/* 1st check: is param 2 (level) correct? (only if param 5 passed?) */
|
|
|
|
apiReturn = pNetWkstaTransportEnum(NULL, 1, NULL, MAX_PREFERRED_LENGTH,
|
|
|
|
NULL, &totalEntries, NULL);
|
2003-09-25 22:29:40 +02:00
|
|
|
ok(apiReturn == ERROR_INVALID_LEVEL || apiReturn == ERROR_INVALID_PARAMETER,
|
2006-10-08 19:35:50 +02:00
|
|
|
"NetWkstaTransportEnum returned %d\n", apiReturn);
|
2003-04-30 02:48:56 +02:00
|
|
|
|
|
|
|
/* 2nd check: is param 5 passed? (only if level passes?) */
|
|
|
|
apiReturn = pNetWkstaTransportEnum(NULL, 0, NULL, MAX_PREFERRED_LENGTH,
|
|
|
|
NULL, &totalEntries, NULL);
|
|
|
|
|
|
|
|
/* if no network adapter present, bail, the rest of the test will fail */
|
|
|
|
if (apiReturn == ERROR_NETWORK_UNREACHABLE)
|
|
|
|
return;
|
|
|
|
|
2003-09-25 22:29:40 +02:00
|
|
|
ok(apiReturn == STATUS_ACCESS_VIOLATION || apiReturn == ERROR_INVALID_PARAMETER,
|
2006-10-08 19:35:50 +02:00
|
|
|
"NetWkstaTransportEnum returned %d\n", apiReturn);
|
2003-04-30 02:48:56 +02:00
|
|
|
|
|
|
|
/* 3rd check: is param 3 passed? */
|
|
|
|
apiReturn = pNetWkstaTransportEnum(NULL, 0, NULL, MAX_PREFERRED_LENGTH,
|
|
|
|
NULL, NULL, NULL);
|
2005-03-14 11:05:58 +01:00
|
|
|
ok(apiReturn == STATUS_ACCESS_VIOLATION || apiReturn == RPC_X_NULL_REF_POINTER || apiReturn == ERROR_INVALID_PARAMETER,
|
2006-10-08 19:35:50 +02:00
|
|
|
"NetWkstaTransportEnum returned %d\n", apiReturn);
|
2003-04-30 02:48:56 +02:00
|
|
|
|
|
|
|
/* 4th check: is param 6 passed? */
|
|
|
|
apiReturn = pNetWkstaTransportEnum(NULL, 0, &bufPtr, MAX_PREFERRED_LENGTH,
|
|
|
|
&entriesRead, NULL, NULL);
|
2004-01-27 21:13:03 +01:00
|
|
|
ok(apiReturn == RPC_X_NULL_REF_POINTER, "null pointer\n");
|
2003-04-30 02:48:56 +02:00
|
|
|
|
|
|
|
/* final check: valid return, actually get data back */
|
|
|
|
apiReturn = pNetWkstaTransportEnum(NULL, 0, &bufPtr, MAX_PREFERRED_LENGTH,
|
|
|
|
&entriesRead, &totalEntries, NULL);
|
2003-09-25 22:29:40 +02:00
|
|
|
ok(apiReturn == NERR_Success || apiReturn == ERROR_NETWORK_UNREACHABLE,
|
2006-10-08 19:35:50 +02:00
|
|
|
"NetWkstaTransportEnum returned %d\n", apiReturn);
|
2003-04-30 02:48:56 +02:00
|
|
|
if (apiReturn == NERR_Success) {
|
|
|
|
/* WKSTA_TRANSPORT_INFO_0 *transports = (WKSTA_TRANSPORT_INFO_0 *)bufPtr; */
|
|
|
|
|
2004-01-27 21:13:03 +01:00
|
|
|
ok(bufPtr != NULL, "got data back\n");
|
|
|
|
ok(entriesRead > 0, "read at least one transport\n");
|
2009-08-24 14:19:11 +02:00
|
|
|
ok(totalEntries > 0 || broken(totalEntries == 0) /* Win7 */,
|
|
|
|
"at least one transport\n");
|
2003-06-23 05:32:28 +02:00
|
|
|
pNetApiBufferFree(bufPtr);
|
2003-04-30 02:48:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-09-11 04:35:17 +02:00
|
|
|
START_TEST(wksta)
|
|
|
|
{
|
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");
|
|
|
|
pNetpGetComputerName=(void*)GetProcAddress(hnetapi32,"NetpGetComputerName");
|
|
|
|
pNetWkstaUserGetInfo=(void*)GetProcAddress(hnetapi32,"NetWkstaUserGetInfo");
|
2003-04-30 02:48:56 +02:00
|
|
|
pNetWkstaTransportEnum=(void*)GetProcAddress(hnetapi32,"NetWkstaTransportEnum");
|
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) {
|
2009-02-23 10:42:43 +01:00
|
|
|
win_skip("Needed functions are not available\n");
|
2007-03-23 11:32:36 +01:00
|
|
|
FreeLibrary(hnetapi32);
|
|
|
|
return;
|
|
|
|
}
|
2002-12-19 02:04:12 +01:00
|
|
|
|
|
|
|
if (init_wksta_tests()) {
|
2009-08-24 14:19:11 +02:00
|
|
|
if (pNetpGetComputerName)
|
|
|
|
run_get_comp_name_tests();
|
|
|
|
else
|
|
|
|
win_skip("Function NetpGetComputerName not available\n");
|
2002-12-19 02:04:12 +01:00
|
|
|
run_wkstausergetinfo_tests();
|
2003-04-30 02:48:56 +02:00
|
|
|
run_wkstatransportenum_tests();
|
2002-12-19 02:04:12 +01:00
|
|
|
}
|
2007-03-23 11:32:36 +01:00
|
|
|
|
|
|
|
FreeLibrary(hnetapi32);
|
2002-09-11 04:35:17 +02:00
|
|
|
}
|