2 * Copyright 2002 Andriy Palamarchuk
4 * Conformance test of the access functions.
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.
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.
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
30 #include "wine/test.h"
32 WCHAR user_name
[UNLEN
+ 1];
33 WCHAR computer_name
[MAX_COMPUTERNAME_LENGTH
+ 1];
35 static const WCHAR sAdminUserName
[] = {'A','d','m','i','n','i','s','t','r','a','t',
37 static const WCHAR sGuestUserName
[] = {'G','u','e','s','t',0};
38 static const WCHAR sNonexistentUser
[] = {'N','o','n','e','x','i','s','t','e','n','t',' ',
40 static const WCHAR sTestUserName
[] = {'t', 'e', 's', 't', 'u', 's', 'e', 'r', 0};
41 static const WCHAR sTestUserOldPass
[] = {'o', 'l', 'd', 'p', 'a', 's', 's', 0};
42 static const WCHAR sTestUserNewPass
[] = {'n', 'e', 'w', 'p', 'a', 's', 's', 0};
43 static const WCHAR sBadNetPath
[] = {'\\','\\','B','a',' ',' ','p','a','t','h',0};
44 static const WCHAR sInvalidName
[] = {'\\',0};
45 static const WCHAR sInvalidName2
[] = {'\\','\\',0};
46 static const WCHAR sEmptyStr
[] = { 0 };
48 static NET_API_STATUS (WINAPI
*pNetApiBufferFree
)(LPVOID
)=NULL
;
49 static NET_API_STATUS (WINAPI
*pNetApiBufferSize
)(LPVOID
,LPDWORD
)=NULL
;
50 static NET_API_STATUS (WINAPI
*pNetQueryDisplayInformation
)(LPWSTR
,DWORD
,DWORD
,DWORD
,DWORD
,LPDWORD
,PVOID
*)=NULL
;
51 static NET_API_STATUS (WINAPI
*pNetUserGetInfo
)(LPCWSTR
,LPCWSTR
,DWORD
,LPBYTE
*)=NULL
;
52 static NET_API_STATUS (WINAPI
*pNetUserModalsGet
)(LPCWSTR
,DWORD
,LPBYTE
*)=NULL
;
53 static NET_API_STATUS (WINAPI
*pNetUserAdd
)(LPCWSTR
,DWORD
,LPBYTE
,LPDWORD
)=NULL
;
54 static NET_API_STATUS (WINAPI
*pNetUserChangePassword
)(LPCWSTR
,LPCWSTR
,LPCWSTR
,LPCWSTR
)=NULL
;
55 static NET_API_STATUS (WINAPI
*pNetUserDel
)(LPCWSTR
,LPCWSTR
)=NULL
;
57 static int init_access_tests(void)
63 dwSize
= sizeof(user_name
);
64 rc
=GetUserNameW(user_name
, &dwSize
);
65 if (rc
==FALSE
&& GetLastError()==ERROR_CALL_NOT_IMPLEMENTED
)
67 skip("netapi32 functions seem to be missing.\n");
70 ok(rc
, "User Name Retrieved\n");
73 dwSize
= sizeof(computer_name
);
74 ok(GetComputerNameW(computer_name
, &dwSize
), "Computer Name Retrieved\n");
78 static void run_usergetinfo_tests(void)
81 PUSER_INFO_0 ui0
= NULL
;
82 PUSER_INFO_10 ui10
= NULL
;
85 /* If this one is not defined then none of the others will be defined */
88 skip("netapi32 functions seem to be missing.\n");
93 rc
=pNetUserGetInfo(NULL
, sAdminUserName
, 0, (LPBYTE
*)&ui0
);
94 if (rc
!= NERR_Success
) {
95 skip("Aborting usergetinfo_tests(). NetUserGetInfo: rc=%d\n", rc
);
98 ok(!lstrcmpW(sAdminUserName
, ui0
->usri0_name
), "This is really user name\n");
99 pNetApiBufferSize(ui0
, &dwSize
);
100 ok(dwSize
>= (sizeof(USER_INFO_0
) +
101 (lstrlenW(ui0
->usri0_name
) + 1) * sizeof(WCHAR
)),
102 "Is allocated with NetApiBufferAllocate\n");
105 rc
=pNetUserGetInfo(NULL
, sAdminUserName
, 10, (LPBYTE
*)&ui10
);
106 ok(rc
== NERR_Success
, "NetUserGetInfo: rc=%d\n", rc
);
107 ok(!lstrcmpW(sAdminUserName
, ui10
->usri10_name
), "This is really user name\n");
108 pNetApiBufferSize(ui10
, &dwSize
);
109 ok(dwSize
>= (sizeof(USER_INFO_10
) +
110 (lstrlenW(ui10
->usri10_name
) + 1 +
111 lstrlenW(ui10
->usri10_comment
) + 1 +
112 lstrlenW(ui10
->usri10_usr_comment
) + 1 +
113 lstrlenW(ui10
->usri10_full_name
) + 1) * sizeof(WCHAR
)),
114 "Is allocated with NetApiBufferAllocate\n");
116 pNetApiBufferFree(ui0
);
117 pNetApiBufferFree(ui10
);
119 /* errors handling */
120 rc
=pNetUserGetInfo(NULL
, sAdminUserName
, 10000, (LPBYTE
*)&ui0
);
121 ok(rc
== ERROR_INVALID_LEVEL
,"Invalid Level: rc=%d\n",rc
);
122 rc
=pNetUserGetInfo(NULL
, sNonexistentUser
, 0, (LPBYTE
*)&ui0
);
123 ok(rc
== NERR_UserNotFound
,"Invalid User Name: rc=%d\n",rc
);
125 /* FIXME - Currently Wine can't verify whether the network path is good or bad */
126 rc
=pNetUserGetInfo(sBadNetPath
, sAdminUserName
, 0, (LPBYTE
*)&ui0
);
127 ok(rc
== ERROR_BAD_NETPATH
|| rc
== ERROR_NETWORK_UNREACHABLE
,
128 "Bad Network Path: rc=%d\n",rc
);
130 rc
=pNetUserGetInfo(sEmptyStr
, sAdminUserName
, 0, (LPBYTE
*)&ui0
);
131 ok(rc
== ERROR_BAD_NETPATH
|| rc
== NERR_Success
,
132 "Bad Network Path: rc=%d\n",rc
);
133 rc
=pNetUserGetInfo(sInvalidName
, sAdminUserName
, 0, (LPBYTE
*)&ui0
);
134 ok(rc
== ERROR_INVALID_NAME
,"Invalid Server Name: rc=%d\n",rc
);
135 rc
=pNetUserGetInfo(sInvalidName2
, sAdminUserName
, 0, (LPBYTE
*)&ui0
);
136 ok(rc
== ERROR_INVALID_NAME
,"Invalid Server Name: rc=%d\n",rc
);
139 /* checks Level 1 of NetQueryDisplayInformation */
140 static void run_querydisplayinformation1_tests(void)
142 PNET_DISPLAY_USER Buffer
, rec
;
143 DWORD Result
, EntryCount
;
145 BOOL hasAdmin
= FALSE
;
146 BOOL hasGuest
= FALSE
;
148 if (!pNetQueryDisplayInformation
)
150 skip("netapi32 functions seem to be missing.\n");
156 Result
= pNetQueryDisplayInformation(
157 NULL
, 1, i
, 1000, MAX_PREFERRED_LENGTH
, &EntryCount
,
160 ok((Result
== ERROR_SUCCESS
) || (Result
== ERROR_MORE_DATA
),
161 "Information Retrieved\n");
163 for(; EntryCount
> 0; EntryCount
--)
165 if (!lstrcmpW(rec
->usri1_name
, sAdminUserName
))
167 ok(!hasAdmin
, "One admin user\n");
168 ok(rec
->usri1_flags
& UF_SCRIPT
, "UF_SCRIPT flag is set\n");
169 ok(rec
->usri1_flags
& UF_NORMAL_ACCOUNT
, "UF_NORMAL_ACCOUNT flag is set\n");
172 else if (!lstrcmpW(rec
->usri1_name
, sGuestUserName
))
174 ok(!hasGuest
, "One guest record\n");
175 ok(rec
->usri1_flags
& UF_SCRIPT
, "UF_SCRIPT flag is set\n");
176 ok(rec
->usri1_flags
& UF_NORMAL_ACCOUNT
, "UF_NORMAL_ACCOUNT flag is set\n");
180 i
= rec
->usri1_next_index
;
184 pNetApiBufferFree(Buffer
);
185 } while (Result
== ERROR_MORE_DATA
);
187 ok(hasAdmin
, "Has Administrator account\n");
190 static void run_usermodalsget_tests(void)
193 USER_MODALS_INFO_2
* umi2
= NULL
;
195 rc
= pNetUserModalsGet(NULL
, 2, (LPBYTE
*)&umi2
);
196 ok(rc
== ERROR_SUCCESS
, "NetUserModalsGet failed, rc = %d\n", rc
);
199 pNetApiBufferFree(umi2
);
202 static void run_userhandling_tests(void)
207 if(!pNetUserAdd
|| !pNetUserChangePassword
|| !pNetUserDel
)
209 skip("Functions for modifying the user database missing. Skipping test.\n");
213 usri
.usri1_name
= (LPWSTR
) sTestUserName
;
214 usri
.usri1_password
= (LPWSTR
) sTestUserOldPass
;
215 usri
.usri1_priv
= USER_PRIV_USER
;
216 usri
.usri1_home_dir
= NULL
;
217 usri
.usri1_comment
= NULL
;
218 usri
.usri1_flags
= UF_SCRIPT
;
219 usri
.usri1_script_path
= NULL
;
221 ret
= pNetUserAdd(NULL
, 1, (LPBYTE
)&usri
, NULL
);
222 if(ret
== ERROR_ACCESS_DENIED
)
224 skip("Insufficient permissions to add users. Skipping test.\n");
227 if(ret
== NERR_UserExists
)
229 skip("User already exists, skipping test to not mess up the system\n");
233 ok(ret
== NERR_Success
, "Adding user failed with error 0x%08x\n", ret
);
234 if(ret
!= NERR_Success
)
237 ret
= pNetUserChangePassword(NULL
, sTestUserName
, sTestUserOldPass
,
239 todo_wine
ok(ret
== NERR_Success
, "Changing the password failed.\n");
241 ret
= pNetUserDel(NULL
, sTestUserName
);
242 todo_wine
ok(ret
== NERR_Success
, "Deleting the user failed.\n");
247 HMODULE hnetapi32
=LoadLibraryA("netapi32.dll");
248 pNetApiBufferFree
=(void*)GetProcAddress(hnetapi32
,"NetApiBufferFree");
249 pNetApiBufferSize
=(void*)GetProcAddress(hnetapi32
,"NetApiBufferSize");
250 pNetQueryDisplayInformation
=(void*)GetProcAddress(hnetapi32
,"NetQueryDisplayInformation");
251 pNetUserGetInfo
=(void*)GetProcAddress(hnetapi32
,"NetUserGetInfo");
252 pNetUserModalsGet
=(void*)GetProcAddress(hnetapi32
,"NetUserModalsGet");
253 pNetUserAdd
=(void*)GetProcAddress(hnetapi32
, "NetUserAdd");
254 pNetUserChangePassword
=(void*)GetProcAddress(hnetapi32
, "NetUserChangePassword");
255 pNetUserDel
=(void*)GetProcAddress(hnetapi32
, "NetUserDel");
257 if (!pNetApiBufferSize
)
258 trace("It appears there is no netapi32 functionality on this platform\n");
260 if (init_access_tests()) {
261 run_usergetinfo_tests();
262 run_querydisplayinformation1_tests();
263 run_usermodalsget_tests();
264 run_userhandling_tests();