ReactOS 0.4.16-dev-125-g798ea90
wksta.c
Go to the documentation of this file.
1/*
2 * Copyright 2002 Andriy Palamarchuk
3 *
4 * Conformance test of the workstation functions.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21#include <stdarg.h>
22
23#include "wine/test.h"
24#include "windef.h"
25#include "winbase.h"
26#include "wingdi.h"
27#include "winnls.h"
28#include "winresrc.h" /* Ensure we use Unicode defns with native headers */
29#include "nb30.h"
30#include "lmcons.h"
31#include "lmerr.h"
32#include "lmwksta.h"
33#include "lmapibuf.h"
34#include "lmjoin.h"
35
36static NET_API_STATUS (WINAPI *pNetApiBufferFree)(LPVOID)=NULL;
37static NET_API_STATUS (WINAPI *pNetApiBufferSize)(LPVOID,LPDWORD)=NULL;
38static NET_API_STATUS (WINAPI *pNetpGetComputerName)(LPWSTR*)=NULL;
39static NET_API_STATUS (WINAPI *pNetWkstaUserGetInfo)(LPWSTR,DWORD,PBYTE*)=NULL;
40static NET_API_STATUS (WINAPI *pNetWkstaTransportEnum)(LPWSTR,DWORD,LPBYTE*,
42static NET_API_STATUS (WINAPI *pNetGetJoinInformation)(LPCWSTR,LPWSTR*,PNETSETUP_JOIN_STATUS);
43
44static WCHAR user_name[UNLEN + 1];
46
48{
50 BOOL rc;
51
52 user_name[0] = 0;
56 win_skip("GetUserNameW is not implemented\n");
57 return FALSE;
58 }
59 ok(rc, "User Name Retrieved\n");
60
61 computer_name[0] = 0;
63 ok(GetComputerNameW(computer_name, &dwSize), "Computer Name Retrieved\n");
64 return TRUE;
65}
66
67static void run_get_comp_name_tests(void)
68{
69 LPWSTR ws = NULL;
70
71 ok(pNetpGetComputerName(&ws) == NERR_Success, "Computer name is retrieved\n");
72 ok(!lstrcmpW(computer_name, ws), "This is really computer name\n");
73 pNetApiBufferFree(ws);
74}
75
77{
83
84 /* Level 0 */
85 rc = pNetWkstaUserGetInfo(NULL, 0, (LPBYTE *)&ui0);
86 if (rc == NERR_WkstaNotStarted)
87 {
88 skip("Workstation service not running\n");
89 return;
90 }
91 ok(!rc && ui0, "got %d and %p (expected NERR_Success and != NULL\n", rc, ui0);
92
93 /* This failure occurred when I ran sshd as service and didn't authenticate
94 * Since the test dereferences ui0, the rest of this test is worthless
95 */
96 if (!ui0)
97 {
98 return;
99 }
100
101 ok(!lstrcmpW(user_name, ui0->wkui0_username), "This is really user name\n");
102 pNetApiBufferSize(ui0, &dwSize);
103 ok(dwSize >= (sizeof(WKSTA_USER_INFO_0) +
104 lstrlenW(ui0->wkui0_username) * sizeof(WCHAR)),
105 "Is allocated with NetApiBufferAllocate\n");
106
107 /* Level 1 */
108 ok(pNetWkstaUserGetInfo(NULL, 1, (LPBYTE *)&ui1) == NERR_Success,
109 "NetWkstaUserGetInfo is successful\n");
110 ok(lstrcmpW(ui1->wkui1_username, ui0->wkui0_username) == 0,
111 "the same name as returned for level 0\n");
112 pNetApiBufferSize(ui1, &dwSize);
113 ok(dwSize >= (sizeof(WKSTA_USER_INFO_1) +
114 (lstrlenW(ui1->wkui1_username) +
117 lstrlenW(ui1->wkui1_logon_server)) * sizeof(WCHAR)),
118 "Is allocated with NetApiBufferAllocate\n");
119
120 /* Level 1101 */
121 ok(pNetWkstaUserGetInfo(NULL, 1101, (LPBYTE *)&ui1101) == NERR_Success,
122 "NetWkstaUserGetInfo is successful\n");
124 "the same oth_domains as returned for level 1\n");
125 pNetApiBufferSize(ui1101, &dwSize);
126 ok(dwSize >= (sizeof(WKSTA_USER_INFO_1101) +
127 lstrlenW(ui1101->wkui1101_oth_domains) * sizeof(WCHAR)),
128 "Is allocated with NetApiBufferAllocate\n");
129
130 pNetApiBufferFree(ui0);
131 pNetApiBufferFree(ui1);
132 pNetApiBufferFree(ui1101);
133
134 /* errors handling */
135 ok(pNetWkstaUserGetInfo(NULL, 10000, (LPBYTE *)&ui0) == ERROR_INVALID_LEVEL,
136 "Invalid level\n");
137}
138
140{
141 LPBYTE bufPtr;
142 NET_API_STATUS apiReturn;
143 DWORD entriesRead, totalEntries;
144
145 /* 1st check: is param 2 (level) correct? (only if param 5 passed?) */
146 apiReturn = pNetWkstaTransportEnum(NULL, 1, NULL, MAX_PREFERRED_LENGTH,
147 NULL, &totalEntries, NULL);
148 ok(apiReturn == ERROR_INVALID_LEVEL || apiReturn == ERROR_INVALID_PARAMETER,
149 "NetWkstaTransportEnum returned %d\n", apiReturn);
150
151 /* 2nd check: is param 5 passed? (only if level passes?) */
152 apiReturn = pNetWkstaTransportEnum(NULL, 0, NULL, MAX_PREFERRED_LENGTH,
153 NULL, &totalEntries, NULL);
154
155 /* if no network adapter present, bail, the rest of the test will fail */
156 if (apiReturn == ERROR_NETWORK_UNREACHABLE)
157 return;
158
159 ok(apiReturn == STATUS_ACCESS_VIOLATION || apiReturn == ERROR_INVALID_PARAMETER,
160 "NetWkstaTransportEnum returned %d\n", apiReturn);
161
162 /* 3rd check: is param 3 passed? */
163 apiReturn = pNetWkstaTransportEnum(NULL, 0, NULL, MAX_PREFERRED_LENGTH,
164 NULL, NULL, NULL);
165 ok(apiReturn == STATUS_ACCESS_VIOLATION || apiReturn == RPC_X_NULL_REF_POINTER || apiReturn == ERROR_INVALID_PARAMETER,
166 "NetWkstaTransportEnum returned %d\n", apiReturn);
167
168 /* 4th check: is param 6 passed? */
169 apiReturn = pNetWkstaTransportEnum(NULL, 0, &bufPtr, MAX_PREFERRED_LENGTH,
170 &entriesRead, NULL, NULL);
171 ok(apiReturn == RPC_X_NULL_REF_POINTER,
172 "NetWkstaTransportEnum returned %d\n", apiReturn);
173
174 /* final check: valid return, actually get data back */
175 apiReturn = pNetWkstaTransportEnum(NULL, 0, &bufPtr, MAX_PREFERRED_LENGTH,
176 &entriesRead, &totalEntries, NULL);
177 ok(apiReturn == NERR_Success || apiReturn == ERROR_NETWORK_UNREACHABLE || apiReturn == NERR_WkstaNotStarted,
178 "NetWkstaTransportEnum returned %d\n", apiReturn);
179 if (apiReturn == NERR_Success) {
180 /* WKSTA_TRANSPORT_INFO_0 *transports = (WKSTA_TRANSPORT_INFO_0 *)bufPtr; */
181
182 ok(bufPtr != NULL, "got data back\n");
183 ok(entriesRead > 0, "read at least one transport\n");
184 ok(totalEntries > 0 || broken(totalEntries == 0) /* Win7 */,
185 "at least one transport\n");
186 pNetApiBufferFree(bufPtr);
187 }
188}
189
190static void run_wkstajoininfo_tests(void)
191{
194 NETSETUP_JOIN_STATUS buffertype = 0xdada;
195 /* NT4 doesn't have this function */
196 if (!pNetGetJoinInformation) {
197 win_skip("NetGetJoinInformation not available\n");
198 return;
199 }
200
201 ret = pNetGetJoinInformation(NULL, NULL, NULL);
202 ok(ret == ERROR_INVALID_PARAMETER, "NetJoinGetInformation returned unexpected 0x%08x\n", ret);
203 ok(buffertype == 0xdada, "buffertype set to unexpected value %d\n", buffertype);
204
205 ret = pNetGetJoinInformation(NULL, &buffer, &buffertype);
206 ok(ret == NERR_Success, "NetJoinGetInformation returned unexpected 0x%08x\n", ret);
207 ok(buffertype != 0xdada && buffertype != NetSetupUnknownStatus, "buffertype set to unexpected value %d\n", buffertype);
208 trace("workstation joined to %s with status %d\n", wine_dbgstr_w(buffer), buffertype);
209 pNetApiBufferFree(buffer);
210}
211
213{
214 HMODULE hnetapi32=LoadLibraryA("netapi32.dll");
215
216 pNetApiBufferFree=(void*)GetProcAddress(hnetapi32,"NetApiBufferFree");
217 pNetApiBufferSize=(void*)GetProcAddress(hnetapi32,"NetApiBufferSize");
218 pNetpGetComputerName=(void*)GetProcAddress(hnetapi32,"NetpGetComputerName");
219 pNetWkstaUserGetInfo=(void*)GetProcAddress(hnetapi32,"NetWkstaUserGetInfo");
220 pNetWkstaTransportEnum=(void*)GetProcAddress(hnetapi32,"NetWkstaTransportEnum");
221 pNetGetJoinInformation=(void*)GetProcAddress(hnetapi32,"NetGetJoinInformation");
222
223 /* These functions were introduced with NT. It's safe to assume that
224 * if one is not available, none are.
225 */
226 if (!pNetApiBufferFree) {
227 win_skip("Needed functions are not available\n");
228 FreeLibrary(hnetapi32);
229 return;
230 }
231
232 if (init_wksta_tests()) {
233 if (pNetpGetComputerName)
235 else
236 win_skip("Function NetpGetComputerName not available\n");
240 }
241
242 FreeLibrary(hnetapi32);
243}
#define trace
Definition: atltest.h:70
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define broken(x)
Definition: atltest.h:178
#define START_TEST(x)
Definition: atltest.h:75
#define ARRAY_SIZE(A)
Definition: main.h:20
BOOL WINAPI GetComputerNameW(LPWSTR lpBuffer, LPDWORD lpnSize)
Definition: compname.c:446
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
BOOL WINAPI GetUserNameW(LPWSTR lpszName, LPDWORD lpSize)
Definition: misc.c:291
#define ERROR_CALL_NOT_IMPLEMENTED
Definition: compat.h:102
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define GetProcAddress(x, y)
Definition: compat.h:753
#define FreeLibrary(x)
Definition: compat.h:748
#define lstrlenW
Definition: compat.h:750
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryA(LPCSTR lpLibFileName)
Definition: loader.c:111
int WINAPI lstrcmpW(LPCWSTR str1, LPCWSTR str2)
Definition: locale.c:4242
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLuint buffer
Definition: glext.h:5915
#define wine_dbgstr_w
Definition: kernel32.h:34
#define NET_API_STATUS
Definition: lmcons.h:8
#define MAX_PREFERRED_LENGTH
Definition: lmcons.h:48
#define NERR_WkstaNotStarted
Definition: lmerr.h:26
#define NERR_Success
Definition: lmerr.h:5
@ NetSetupUnknownStatus
Definition: lmjoin.h:10
enum _NETSETUP_JOIN_STATUS NETSETUP_JOIN_STATUS
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:56
static LPWSTR PNETSETUP_JOIN_STATUS
Definition: wksta.c:42
static void run_wkstajoininfo_tests(void)
Definition: wksta.c:190
static BOOL init_wksta_tests(void)
Definition: wksta.c:47
static void run_wkstatransportenum_tests(void)
Definition: wksta.c:139
static void run_wkstausergetinfo_tests(void)
Definition: wksta.c:76
static DWORD
Definition: wksta.c:39
static WCHAR computer_name[MAX_COMPUTERNAME_LENGTH+1]
Definition: wksta.c:45
static LPDWORD
Definition: wksta.c:37
static void run_get_comp_name_tests(void)
Definition: wksta.c:67
static WCHAR user_name[UNLEN+1]
Definition: wksta.c:44
DWORD NET_API_STATUS
Definition: ms-dtyp.idl:91
#define LPVOID
Definition: nt_native.h:45
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:242
BYTE * PBYTE
Definition: pedump.c:66
#define win_skip
Definition: test.h:163
const char * ws
Definition: skip_ws.cpp:7
#define UNLEN
Definition: sspi.c:28
LPWSTR wkui0_username
Definition: lmwksta.h:202
LPWSTR wkui1101_oth_domains
Definition: lmwksta.h:209
LPWSTR wkui1_oth_domains
Definition: lmwksta.h:206
LPWSTR wkui1_username
Definition: lmwksta.h:204
LPWSTR wkui1_logon_domain
Definition: lmwksta.h:205
LPWSTR wkui1_logon_server
Definition: lmwksta.h:207
unsigned char * LPBYTE
Definition: typedefs.h:53
int ret
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define MAX_COMPUTERNAME_LENGTH
Definition: winbase.h:243
#define WINAPI
Definition: msvc.h:6
#define ERROR_INVALID_LEVEL
Definition: winerror.h:196
#define ERROR_NETWORK_UNREACHABLE
Definition: winerror.h:734
#define RPC_X_NULL_REF_POINTER
Definition: winerror.h:1087
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185