Commit b611dac7 authored by Francois Gouget's avatar Francois Gouget Committed by Alexandre Julliard

On Win9x netapi32.dll does not export a single API so we do a

GetProcAddress for each of them and skip the tests when necessary. On Win9x GetUserNameW and GetComputerNameW are stubs. Improve error reporting in access.c.
parent 305ead62
...@@ -38,40 +38,54 @@ const WCHAR sInvalidName[] = {'\\',0}; ...@@ -38,40 +38,54 @@ const WCHAR sInvalidName[] = {'\\',0};
const WCHAR sInvalidName2[] = {'\\','\\',0}; const WCHAR sInvalidName2[] = {'\\','\\',0};
const WCHAR sEmptyStr[] = { 0 }; const WCHAR sEmptyStr[] = { 0 };
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;
void init_access_tests(void) static int init_access_tests(void)
{ {
DWORD dwSize; DWORD dwSize;
BOOL rc;
user_name[0] = 0; user_name[0] = 0;
dwSize = sizeof(user_name); dwSize = sizeof(user_name);
ok(GetUserNameW(user_name, &dwSize), "User Name Retrieved"); rc=GetUserNameW(user_name, &dwSize);
if (rc==FALSE && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
return 0;
ok(rc, "User Name Retrieved");
computer_name[0] = 0; computer_name[0] = 0;
dwSize = sizeof(computer_name); dwSize = sizeof(computer_name);
ok(GetComputerNameW(computer_name, &dwSize), "Computer Name Retrieved"); ok(GetComputerNameW(computer_name, &dwSize), "Computer Name Retrieved");
return 1;
} }
void run_usergetinfo_tests(void) void run_usergetinfo_tests(void)
{ {
NET_API_STATUS rc;
PUSER_INFO_0 ui0 = NULL; PUSER_INFO_0 ui0 = NULL;
PUSER_INFO_10 ui10 = NULL; PUSER_INFO_10 ui10 = NULL;
DWORD dwSize; DWORD dwSize;
/* If this one is not defined then none of the others will be defined */
if (!pNetUserGetInfo)
return;
/* Level 0 */ /* Level 0 */
ok(NetUserGetInfo(NULL, sAdminUserName, 0, (LPBYTE *)&ui0) == NERR_Success, rc=pNetUserGetInfo(NULL, sAdminUserName, 0, (LPBYTE *)&ui0);
"NetUserGetInfo is successful"); ok(rc == NERR_Success, "NetUserGetInfo: rc=%ld", rc);
ok(!lstrcmpW(sAdminUserName, ui0->usri0_name), "This is really user name"); ok(!lstrcmpW(sAdminUserName, ui0->usri0_name), "This is really user name");
NetApiBufferSize(ui0, &dwSize); pNetApiBufferSize(ui0, &dwSize);
ok(dwSize >= (sizeof(USER_INFO_0) + ok(dwSize >= (sizeof(USER_INFO_0) +
(lstrlenW(ui0->usri0_name) + 1) * sizeof(WCHAR)), (lstrlenW(ui0->usri0_name) + 1) * sizeof(WCHAR)),
"Is allocated with NetApiBufferAllocate"); "Is allocated with NetApiBufferAllocate");
/* Level 10 */ /* Level 10 */
ok(NetUserGetInfo(NULL, sAdminUserName, 10, (LPBYTE *)&ui10) == NERR_Success, rc=pNetUserGetInfo(NULL, sAdminUserName, 10, (LPBYTE *)&ui10);
"NetUserGetInfo is successful"); ok(rc == NERR_Success, "NetUserGetInfo: rc=%ld", rc);
ok(!lstrcmpW(sAdminUserName, ui10->usri10_name), "This is really user name"); ok(!lstrcmpW(sAdminUserName, ui10->usri10_name), "This is really user name");
NetApiBufferSize(ui10, &dwSize); pNetApiBufferSize(ui10, &dwSize);
ok(dwSize >= (sizeof(USER_INFO_10) + ok(dwSize >= (sizeof(USER_INFO_10) +
(lstrlenW(ui10->usri10_name) + 1 + (lstrlenW(ui10->usri10_name) + 1 +
lstrlenW(ui10->usri10_comment) + 1 + lstrlenW(ui10->usri10_comment) + 1 +
...@@ -79,25 +93,25 @@ void run_usergetinfo_tests(void) ...@@ -79,25 +93,25 @@ void run_usergetinfo_tests(void)
lstrlenW(ui10->usri10_full_name) + 1) * sizeof(WCHAR)), lstrlenW(ui10->usri10_full_name) + 1) * sizeof(WCHAR)),
"Is allocated with NetApiBufferAllocate"); "Is allocated with NetApiBufferAllocate");
NetApiBufferFree(ui0); pNetApiBufferFree(ui0);
NetApiBufferFree(ui10); pNetApiBufferFree(ui10);
/* errors handling */ /* errors handling */
ok(NetUserGetInfo(NULL, sAdminUserName, 10000, (LPBYTE *)&ui0) == ERROR_INVALID_LEVEL, rc=pNetUserGetInfo(NULL, sAdminUserName, 10000, (LPBYTE *)&ui0);
"Invalid Level"); ok(rc == ERROR_INVALID_LEVEL,"Invalid Level: rc=%ld",rc);
ok(NetUserGetInfo(NULL, sNonexistentUser, 0, (LPBYTE *)&ui0) == NERR_UserNotFound, rc=pNetUserGetInfo(NULL, sNonexistentUser, 0, (LPBYTE *)&ui0);
"Invalid User Name"); ok(rc == NERR_UserNotFound,"Invalid User Name: rc=%ld",rc);
todo_wine { todo_wine {
/* FIXME - Currently Wine can't verify whether the network path is good or bad */ /* FIXME - Currently Wine can't verify whether the network path is good or bad */
ok(NetUserGetInfo(sBadNetPath, sAdminUserName, 0, (LPBYTE *)&ui0) == ERROR_BAD_NETPATH, rc=pNetUserGetInfo(sBadNetPath, sAdminUserName, 0, (LPBYTE *)&ui0);
"Bad Network Path"); ok(rc == ERROR_BAD_NETPATH,"Bad Network Path: rc=%ld",rc);
} }
ok(NetUserGetInfo(sEmptyStr, sAdminUserName, 0, (LPBYTE *)&ui0) == ERROR_BAD_NETPATH, rc=pNetUserGetInfo(sEmptyStr, sAdminUserName, 0, (LPBYTE *)&ui0);
"Bad Network Path"); ok(rc == ERROR_BAD_NETPATH,"Bad Network Path: rc=%ld",rc);
ok(NetUserGetInfo(sInvalidName, sAdminUserName, 0, (LPBYTE *)&ui0) == ERROR_INVALID_NAME, rc=pNetUserGetInfo(sInvalidName, sAdminUserName, 0, (LPBYTE *)&ui0);
"Invalid Server Name"); ok(rc == ERROR_INVALID_NAME,"Invalid Server Name: rc=%ld",rc);
ok(NetUserGetInfo(sInvalidName2, sAdminUserName, 0, (LPBYTE *)&ui0) == ERROR_INVALID_NAME, rc=pNetUserGetInfo(sInvalidName2, sAdminUserName, 0, (LPBYTE *)&ui0);
"Invalid Server Name"); ok(rc == ERROR_INVALID_NAME,"Invalid Server Name: rc=%ld",rc);
} }
/* checks Level 1 of NetQueryDisplayInformation */ /* checks Level 1 of NetQueryDisplayInformation */
...@@ -109,9 +123,12 @@ void run_querydisplayinformation1_tests(void) ...@@ -109,9 +123,12 @@ void run_querydisplayinformation1_tests(void)
BOOL hasAdmin = FALSE; BOOL hasAdmin = FALSE;
BOOL hasGuest = FALSE; BOOL hasGuest = FALSE;
if (!pNetQueryDisplayInformation)
return;
do do
{ {
Result = NetQueryDisplayInformation( Result = pNetQueryDisplayInformation(
NULL, 1, i, 1000, MAX_PREFERRED_LENGTH, &EntryCount, NULL, 1, i, 1000, MAX_PREFERRED_LENGTH, &EntryCount,
(PVOID *)&Buffer); (PVOID *)&Buffer);
...@@ -139,7 +156,7 @@ void run_querydisplayinformation1_tests(void) ...@@ -139,7 +156,7 @@ void run_querydisplayinformation1_tests(void)
rec++; rec++;
} }
NetApiBufferFree(Buffer); pNetApiBufferFree(Buffer);
} while (Result == ERROR_MORE_DATA); } while (Result == ERROR_MORE_DATA);
ok(hasAdmin, "Has Administrator account"); ok(hasAdmin, "Has Administrator account");
...@@ -148,7 +165,16 @@ void run_querydisplayinformation1_tests(void) ...@@ -148,7 +165,16 @@ void run_querydisplayinformation1_tests(void)
START_TEST(access) START_TEST(access)
{ {
init_access_tests(); HMODULE hnetapi32=LoadLibraryA("netapi32.dll");
run_usergetinfo_tests(); pNetApiBufferFree=(void*)GetProcAddress(hnetapi32,"NetApiBufferFree");
run_querydisplayinformation1_tests(); pNetApiBufferSize=(void*)GetProcAddress(hnetapi32,"NetApiBufferSize");
pNetQueryDisplayInformation=(void*)GetProcAddress(hnetapi32,"NetQueryDisplayInformation");
pNetUserGetInfo=(void*)GetProcAddress(hnetapi32,"NetUserGetInfo");
if (!pNetApiBufferSize)
trace("It appears there is no netapi32 functionality on this platform\n");
if (init_access_tests()) {
run_usergetinfo_tests();
run_querydisplayinformation1_tests();
}
} }
...@@ -26,40 +26,57 @@ ...@@ -26,40 +26,57 @@
#include <lmapibuf.h> #include <lmapibuf.h>
#include <lmaccess.h> #include <lmaccess.h>
static NET_API_STATUS (WINAPI *pNetApiBufferAllocate)(DWORD,LPVOID*)=NULL;
static NET_API_STATUS (WINAPI *pNetApiBufferFree)(LPVOID)=NULL;
static NET_API_STATUS (WINAPI *pNetApiBufferReallocate)(LPVOID,DWORD,LPVOID*)=NULL;
static NET_API_STATUS (WINAPI *pNetApiBufferSize)(LPVOID,LPDWORD)=NULL;
void run_apibuf_tests(void) void run_apibuf_tests(void)
{ {
VOID *p; VOID *p;
DWORD dwSize; DWORD dwSize;
if (!pNetApiBufferAllocate)
return;
/* test normal logic */ /* test normal logic */
ok(NetApiBufferAllocate(1024, (LPVOID *)&p) == NERR_Success, ok(pNetApiBufferAllocate(1024, (LPVOID *)&p) == NERR_Success,
"Reserved memory"); "Reserved memory");
ok(NetApiBufferSize(p, &dwSize) == NERR_Success, "Got size"); ok(pNetApiBufferSize(p, &dwSize) == NERR_Success, "Got size");
ok(dwSize >= 1024, "The size is correct"); ok(dwSize >= 1024, "The size is correct");
ok(NetApiBufferReallocate(p, 1500, (LPVOID *) &p) == NERR_Success, ok(pNetApiBufferReallocate(p, 1500, (LPVOID *) &p) == NERR_Success,
"Reallocated"); "Reallocated");
ok(NetApiBufferSize(p, &dwSize) == NERR_Success, "Got size"); ok(pNetApiBufferSize(p, &dwSize) == NERR_Success, "Got size");
ok(dwSize >= 1500, "The size is correct"); ok(dwSize >= 1500, "The size is correct");
ok(NetApiBufferFree(p) == NERR_Success, "Freed"); ok(pNetApiBufferFree(p) == NERR_Success, "Freed");
/* test errors handling */ /* test errors handling */
ok(NetApiBufferFree(p) == NERR_Success, "Freed"); ok(pNetApiBufferFree(p) == NERR_Success, "Freed");
ok(NetApiBufferSize(p, &dwSize) == NERR_Success, "Got size"); ok(pNetApiBufferSize(p, &dwSize) == NERR_Success, "Got size");
ok(dwSize >= 0, "The size"); ok(dwSize >= 0, "The size");
ok(NetApiBufferSize(NULL, &dwSize) == ERROR_INVALID_PARAMETER, "Error for NULL pointer"); ok(pNetApiBufferSize(NULL, &dwSize) == ERROR_INVALID_PARAMETER, "Error for NULL pointer");
/* 0-length buffer */ /* 0-length buffer */
ok(NetApiBufferAllocate(0, (LPVOID *)&p) == NERR_Success, ok(pNetApiBufferAllocate(0, (LPVOID *)&p) == NERR_Success,
"Reserved memory"); "Reserved memory");
ok(NetApiBufferSize(p, &dwSize) == NERR_Success, "Got size"); ok(pNetApiBufferSize(p, &dwSize) == NERR_Success, "Got size");
ok((dwSize >= 0) && (dwSize < 0xFFFFFFFF),"The size of the 0-length buffer"); ok((dwSize >= 0) && (dwSize < 0xFFFFFFFF),"The size of the 0-length buffer");
ok(NetApiBufferFree(p) == NERR_Success, "Freed"); ok(pNetApiBufferFree(p) == NERR_Success, "Freed");
} }
START_TEST(apibuf) START_TEST(apibuf)
{ {
HMODULE hnetapi32=LoadLibraryA("netapi32.dll");
pNetApiBufferAllocate=(void*)GetProcAddress(hnetapi32,"NetApiBufferAllocate");
pNetApiBufferFree=(void*)GetProcAddress(hnetapi32,"NetApiBufferFree");
pNetApiBufferReallocate=(void*)GetProcAddress(hnetapi32,"NetApiBufferReallocate");
pNetApiBufferSize=(void*)GetProcAddress(hnetapi32,"NetApiBufferSize");
if (!pNetApiBufferSize)
trace("It appears there is no netapi32 functionality on this platform\n");
run_apibuf_tests(); run_apibuf_tests();
} }
...@@ -27,64 +27,69 @@ ...@@ -27,64 +27,69 @@
#include "lmwksta.h" #include "lmwksta.h"
#include "lmapibuf.h" #include "lmapibuf.h"
typedef NET_API_STATUS (WINAPI *NetpGetComputerName_func)(LPWSTR *Buffer); 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;
WCHAR user_name[UNLEN + 1]; WCHAR user_name[UNLEN + 1];
WCHAR computer_name[MAX_COMPUTERNAME_LENGTH + 1]; WCHAR computer_name[MAX_COMPUTERNAME_LENGTH + 1];
void init_wksta_tests(void) static int init_wksta_tests(void)
{ {
DWORD dwSize; DWORD dwSize;
BOOL rc;
user_name[0] = 0; user_name[0] = 0;
dwSize = sizeof(user_name); dwSize = sizeof(user_name);
ok(GetUserNameW(user_name, &dwSize), "User Name Retrieved"); rc=GetUserNameW(user_name, &dwSize);
if (rc==FALSE && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
return 0;
ok(rc, "User Name Retrieved");
computer_name[0] = 0; computer_name[0] = 0;
dwSize = sizeof(computer_name); dwSize = sizeof(computer_name);
ok(GetComputerNameW(computer_name, &dwSize), "Computer Name Retrieved"); ok(GetComputerNameW(computer_name, &dwSize), "Computer Name Retrieved");
return 1;
} }
void run_get_comp_name_tests(void) static void run_get_comp_name_tests(void)
{ {
HANDLE hnetapi32 = GetModuleHandleA("netapi32.dll"); WCHAR empty[] = {0};
if (hnetapi32) LPWSTR ws = empty;
{ if (!pNetpGetComputerName)
WCHAR empty[] = {0}; return;
LPWSTR ws = empty;
NetpGetComputerName_func pNetpGetComputerName; ok(pNetpGetComputerName(&ws) == NERR_Success, "Computer name is retrieved");
pNetpGetComputerName = (NetpGetComputerName_func)GetProcAddress(hnetapi32,"NetpGetComputerName"); ok(!lstrcmpW(computer_name, ws), "This is really computer name");
if (pNetpGetComputerName) pNetApiBufferFree(ws);
{
ok((*pNetpGetComputerName)(&ws) == NERR_Success, "Computer name is retrieved");
ok(!lstrcmpW(computer_name, ws), "This is really computer name");
NetApiBufferFree(ws);
}
}
} }
void run_wkstausergetinfo_tests(void) static void run_wkstausergetinfo_tests(void)
{ {
LPWKSTA_USER_INFO_0 ui0 = NULL; LPWKSTA_USER_INFO_0 ui0 = NULL;
LPWKSTA_USER_INFO_1 ui1 = NULL; LPWKSTA_USER_INFO_1 ui1 = NULL;
LPWKSTA_USER_INFO_1101 ui1101 = NULL; LPWKSTA_USER_INFO_1101 ui1101 = NULL;
DWORD dwSize; DWORD dwSize;
if (!pNetWkstaUserGetInfo)
return;
/* Level 0 */ /* Level 0 */
ok(NetWkstaUserGetInfo(NULL, 0, (LPBYTE *)&ui0) == NERR_Success, ok(pNetWkstaUserGetInfo(NULL, 0, (LPBYTE *)&ui0) == NERR_Success,
"NetWkstaUserGetInfo is successful"); "NetWkstaUserGetInfo is successful");
ok(!lstrcmpW(user_name, ui0->wkui0_username), "This is really user name"); ok(!lstrcmpW(user_name, ui0->wkui0_username), "This is really user name");
NetApiBufferSize(ui0, &dwSize); pNetApiBufferSize(ui0, &dwSize);
ok(dwSize >= (sizeof(WKSTA_USER_INFO_0) + ok(dwSize >= (sizeof(WKSTA_USER_INFO_0) +
lstrlenW(ui0->wkui0_username) * sizeof(WCHAR)), lstrlenW(ui0->wkui0_username) * sizeof(WCHAR)),
"Is allocated with NetApiBufferAllocate"); "Is allocated with NetApiBufferAllocate");
/* Level 1 */ /* Level 1 */
ok(NetWkstaUserGetInfo(NULL, 1, (LPBYTE *)&ui1) == NERR_Success, ok(pNetWkstaUserGetInfo(NULL, 1, (LPBYTE *)&ui1) == NERR_Success,
"NetWkstaUserGetInfo is successful"); "NetWkstaUserGetInfo is successful");
ok(lstrcmpW(ui1->wkui1_username, ui0->wkui0_username) == 0, ok(lstrcmpW(ui1->wkui1_username, ui0->wkui0_username) == 0,
"the same name as returned for level 0"); "the same name as returned for level 0");
NetApiBufferSize(ui1, &dwSize); pNetApiBufferSize(ui1, &dwSize);
ok(dwSize >= (sizeof(WKSTA_USER_INFO_1) + ok(dwSize >= (sizeof(WKSTA_USER_INFO_1) +
(lstrlenW(ui1->wkui1_username) + (lstrlenW(ui1->wkui1_username) +
lstrlenW(ui1->wkui1_logon_domain) + lstrlenW(ui1->wkui1_logon_domain) +
...@@ -93,27 +98,36 @@ void run_wkstausergetinfo_tests(void) ...@@ -93,27 +98,36 @@ void run_wkstausergetinfo_tests(void)
"Is allocated with NetApiBufferAllocate"); "Is allocated with NetApiBufferAllocate");
/* Level 1101 */ /* Level 1101 */
ok(NetWkstaUserGetInfo(NULL, 1101, (LPBYTE *)&ui1101) == NERR_Success, ok(pNetWkstaUserGetInfo(NULL, 1101, (LPBYTE *)&ui1101) == NERR_Success,
"NetWkstaUserGetInfo is successful"); "NetWkstaUserGetInfo is successful");
ok(lstrcmpW(ui1101->wkui1101_oth_domains, ui1->wkui1_oth_domains) == 0, ok(lstrcmpW(ui1101->wkui1101_oth_domains, ui1->wkui1_oth_domains) == 0,
"the same oth_domains as returned for level 1"); "the same oth_domains as returned for level 1");
NetApiBufferSize(ui1101, &dwSize); pNetApiBufferSize(ui1101, &dwSize);
ok(dwSize >= (sizeof(WKSTA_USER_INFO_1101) + ok(dwSize >= (sizeof(WKSTA_USER_INFO_1101) +
lstrlenW(ui1101->wkui1101_oth_domains) * sizeof(WCHAR)), lstrlenW(ui1101->wkui1101_oth_domains) * sizeof(WCHAR)),
"Is allocated with NetApiBufferAllocate"); "Is allocated with NetApiBufferAllocate");
NetApiBufferFree(ui0); pNetApiBufferFree(ui0);
NetApiBufferFree(ui1); pNetApiBufferFree(ui1);
NetApiBufferFree(ui1101); pNetApiBufferFree(ui1101);
/* errors handling */ /* errors handling */
ok(NetWkstaUserGetInfo(NULL, 10000, (LPBYTE *)&ui0) == ERROR_INVALID_LEVEL, ok(pNetWkstaUserGetInfo(NULL, 10000, (LPBYTE *)&ui0) == ERROR_INVALID_LEVEL,
"Invalid level"); "Invalid level");
} }
START_TEST(wksta) START_TEST(wksta)
{ {
init_wksta_tests(); HMODULE hnetapi32=LoadLibraryA("netapi32.dll");
run_get_comp_name_tests(); pNetApiBufferFree=(void*)GetProcAddress(hnetapi32,"NetApiBufferFree");
run_wkstausergetinfo_tests(); pNetApiBufferSize=(void*)GetProcAddress(hnetapi32,"NetApiBufferSize");
pNetpGetComputerName=(void*)GetProcAddress(hnetapi32,"NetpGetComputerName");
pNetWkstaUserGetInfo=(void*)GetProcAddress(hnetapi32,"NetWkstaUserGetInfo");
if (!pNetApiBufferSize)
trace("It appears there is no netapi32 functionality on this platform\n");
if (init_wksta_tests()) {
run_get_comp_name_tests();
run_wkstausergetinfo_tests();
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment