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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include <wine/test.h>
31 WCHAR user_name[UNLEN + 1];
32 WCHAR computer_name[MAX_COMPUTERNAME_LENGTH + 1];
34 static const WCHAR sAdminUserName[] = {'A','d','m','i','n','i','s','t','r','a','t',
36 static const WCHAR sGuestUserName[] = {'G','u','e','s','t',0};
37 static const WCHAR sNonexistentUser[] = {'N','o','n','e','x','i','s','t','e','n','t',' ',
39 static const WCHAR sBadNetPath[] = {'\\','\\','B','a',' ',' ','p','a','t','h',0};
40 static const WCHAR sInvalidName[] = {'\\',0};
41 static const WCHAR sInvalidName2[] = {'\\','\\',0};
42 static const WCHAR sEmptyStr[] = { 0 };
44 static NET_API_STATUS (WINAPI *pNetApiBufferFree)(LPVOID)=NULL;
45 static NET_API_STATUS (WINAPI *pNetApiBufferSize)(LPVOID,LPDWORD)=NULL;
46 static NET_API_STATUS (WINAPI *pNetQueryDisplayInformation)(LPWSTR,DWORD,DWORD,DWORD,DWORD,LPDWORD,PVOID*)=NULL;
47 static NET_API_STATUS (WINAPI *pNetUserGetInfo)(LPCWSTR,LPCWSTR,DWORD,LPBYTE*)=NULL;
49 static int init_access_tests(void)
55 dwSize = sizeof(user_name);
56 rc=GetUserNameW(user_name, &dwSize);
57 if (rc==FALSE && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
59 ok(rc, "User Name Retrieved\n");
62 dwSize = sizeof(computer_name);
63 ok(GetComputerNameW(computer_name, &dwSize), "Computer Name Retrieved\n");
67 void run_usergetinfo_tests(void)
70 PUSER_INFO_0 ui0 = NULL;
71 PUSER_INFO_10 ui10 = NULL;
74 /* If this one is not defined then none of the others will be defined */
79 rc=pNetUserGetInfo(NULL, sAdminUserName, 0, (LPBYTE *)&ui0);
80 if (rc != NERR_Success) {
81 trace ("Aborting usergetinfo_tests(). NetUserGetInfo: rc=%ld\n", rc);
84 ok(!lstrcmpW(sAdminUserName, ui0->usri0_name), "This is really user name\n");
85 pNetApiBufferSize(ui0, &dwSize);
86 ok(dwSize >= (sizeof(USER_INFO_0) +
87 (lstrlenW(ui0->usri0_name) + 1) * sizeof(WCHAR)),
88 "Is allocated with NetApiBufferAllocate\n");
91 rc=pNetUserGetInfo(NULL, sAdminUserName, 10, (LPBYTE *)&ui10);
92 ok(rc == NERR_Success, "NetUserGetInfo: rc=%ld\n", rc);
93 ok(!lstrcmpW(sAdminUserName, ui10->usri10_name), "This is really user name\n");
94 pNetApiBufferSize(ui10, &dwSize);
95 ok(dwSize >= (sizeof(USER_INFO_10) +
96 (lstrlenW(ui10->usri10_name) + 1 +
97 lstrlenW(ui10->usri10_comment) + 1 +
98 lstrlenW(ui10->usri10_usr_comment) + 1 +
99 lstrlenW(ui10->usri10_full_name) + 1) * sizeof(WCHAR)),
100 "Is allocated with NetApiBufferAllocate\n");
102 pNetApiBufferFree(ui0);
103 pNetApiBufferFree(ui10);
105 /* errors handling */
106 rc=pNetUserGetInfo(NULL, sAdminUserName, 10000, (LPBYTE *)&ui0);
107 ok(rc == ERROR_INVALID_LEVEL,"Invalid Level: rc=%ld\n",rc);
108 rc=pNetUserGetInfo(NULL, sNonexistentUser, 0, (LPBYTE *)&ui0);
109 ok(rc == NERR_UserNotFound,"Invalid User Name: rc=%ld\n",rc);
111 /* FIXME - Currently Wine can't verify whether the network path is good or bad */
112 rc=pNetUserGetInfo(sBadNetPath, sAdminUserName, 0, (LPBYTE *)&ui0);
113 ok(rc == ERROR_BAD_NETPATH || rc == ERROR_NETWORK_UNREACHABLE,
114 "Bad Network Path: rc=%ld\n",rc);
116 rc=pNetUserGetInfo(sEmptyStr, sAdminUserName, 0, (LPBYTE *)&ui0);
117 ok(rc == ERROR_BAD_NETPATH || rc == NERR_Success,
118 "Bad Network Path: rc=%ld\n",rc);
119 rc=pNetUserGetInfo(sInvalidName, sAdminUserName, 0, (LPBYTE *)&ui0);
120 ok(rc == ERROR_INVALID_NAME,"Invalid Server Name: rc=%ld\n",rc);
121 rc=pNetUserGetInfo(sInvalidName2, sAdminUserName, 0, (LPBYTE *)&ui0);
122 ok(rc == ERROR_INVALID_NAME,"Invalid Server Name: rc=%ld\n",rc);
125 /* checks Level 1 of NetQueryDisplayInformation */
126 void run_querydisplayinformation1_tests(void)
128 PNET_DISPLAY_USER Buffer, rec;
129 DWORD Result, EntryCount;
131 BOOL hasAdmin = FALSE;
132 BOOL hasGuest = FALSE;
134 if (!pNetQueryDisplayInformation)
139 Result = pNetQueryDisplayInformation(
140 NULL, 1, i, 1000, MAX_PREFERRED_LENGTH, &EntryCount,
143 ok((Result == ERROR_SUCCESS) || (Result == ERROR_MORE_DATA),
144 "Information Retrieved\n");
146 for(; EntryCount > 0; EntryCount--)
148 if (!lstrcmpW(rec->usri1_name, sAdminUserName))
150 ok(!hasAdmin, "One admin user\n");
151 ok(rec->usri1_flags & UF_SCRIPT, "UF_SCRIPT flag is set\n");
152 ok(rec->usri1_flags & UF_NORMAL_ACCOUNT, "UF_NORMAL_ACCOUNT flag is set\n");
155 else if (!lstrcmpW(rec->usri1_name, sGuestUserName))
157 ok(!hasGuest, "One guest record\n");
158 ok(rec->usri1_flags & UF_SCRIPT, "UF_SCRIPT flag is set\n");
159 ok(rec->usri1_flags & UF_NORMAL_ACCOUNT, "UF_NORMAL_ACCOUNT flag is set\n");
163 i = rec->usri1_next_index;
167 pNetApiBufferFree(Buffer);
168 } while (Result == ERROR_MORE_DATA);
170 ok(hasAdmin, "Has Administrator account\n");
175 HMODULE hnetapi32=LoadLibraryA("netapi32.dll");
176 pNetApiBufferFree=(void*)GetProcAddress(hnetapi32,"NetApiBufferFree");
177 pNetApiBufferSize=(void*)GetProcAddress(hnetapi32,"NetApiBufferSize");
178 pNetQueryDisplayInformation=(void*)GetProcAddress(hnetapi32,"NetQueryDisplayInformation");
179 pNetUserGetInfo=(void*)GetProcAddress(hnetapi32,"NetUserGetInfo");
180 if (!pNetApiBufferSize)
181 trace("It appears there is no netapi32 functionality on this platform\n");
183 if (init_access_tests()) {
184 run_usergetinfo_tests();
185 run_querydisplayinformation1_tests();