cmd: Updated Korean resource.
[wine/multimedia.git] / dlls / netapi32 / tests / access.c
blobb625c374b258e65a6f13d1daacca5119fd28d09d
1 /*
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
21 #include <stdarg.h>
23 #include <wine/test.h>
24 #include <windef.h>
25 #include <winbase.h>
26 #include <winerror.h>
27 #include <lmaccess.h>
28 #include <lmerr.h>
29 #include <lmapibuf.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',
35 'o','r',0};
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',' ',
38 'U','s','e','r',0};
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;
48 static NET_API_STATUS (WINAPI *pNetUserModalsGet)(LPCWSTR,DWORD,LPBYTE*)=NULL;
50 static int init_access_tests(void)
52 DWORD dwSize;
53 BOOL rc;
55 user_name[0] = 0;
56 dwSize = sizeof(user_name);
57 rc=GetUserNameW(user_name, &dwSize);
58 if (rc==FALSE && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
59 return 0;
60 ok(rc, "User Name Retrieved\n");
62 computer_name[0] = 0;
63 dwSize = sizeof(computer_name);
64 ok(GetComputerNameW(computer_name, &dwSize), "Computer Name Retrieved\n");
65 return 1;
68 static void run_usergetinfo_tests(void)
70 NET_API_STATUS rc;
71 PUSER_INFO_0 ui0 = NULL;
72 PUSER_INFO_10 ui10 = NULL;
73 DWORD dwSize;
75 /* If this one is not defined then none of the others will be defined */
76 if (!pNetUserGetInfo)
77 return;
79 /* Level 0 */
80 rc=pNetUserGetInfo(NULL, sAdminUserName, 0, (LPBYTE *)&ui0);
81 if (rc != NERR_Success) {
82 trace ("Aborting usergetinfo_tests(). NetUserGetInfo: rc=%d\n", rc);
83 return;
85 ok(!lstrcmpW(sAdminUserName, ui0->usri0_name), "This is really user name\n");
86 pNetApiBufferSize(ui0, &dwSize);
87 ok(dwSize >= (sizeof(USER_INFO_0) +
88 (lstrlenW(ui0->usri0_name) + 1) * sizeof(WCHAR)),
89 "Is allocated with NetApiBufferAllocate\n");
91 /* Level 10 */
92 rc=pNetUserGetInfo(NULL, sAdminUserName, 10, (LPBYTE *)&ui10);
93 ok(rc == NERR_Success, "NetUserGetInfo: rc=%d\n", rc);
94 ok(!lstrcmpW(sAdminUserName, ui10->usri10_name), "This is really user name\n");
95 pNetApiBufferSize(ui10, &dwSize);
96 ok(dwSize >= (sizeof(USER_INFO_10) +
97 (lstrlenW(ui10->usri10_name) + 1 +
98 lstrlenW(ui10->usri10_comment) + 1 +
99 lstrlenW(ui10->usri10_usr_comment) + 1 +
100 lstrlenW(ui10->usri10_full_name) + 1) * sizeof(WCHAR)),
101 "Is allocated with NetApiBufferAllocate\n");
103 pNetApiBufferFree(ui0);
104 pNetApiBufferFree(ui10);
106 /* errors handling */
107 rc=pNetUserGetInfo(NULL, sAdminUserName, 10000, (LPBYTE *)&ui0);
108 ok(rc == ERROR_INVALID_LEVEL,"Invalid Level: rc=%d\n",rc);
109 rc=pNetUserGetInfo(NULL, sNonexistentUser, 0, (LPBYTE *)&ui0);
110 ok(rc == NERR_UserNotFound,"Invalid User Name: rc=%d\n",rc);
111 todo_wine {
112 /* FIXME - Currently Wine can't verify whether the network path is good or bad */
113 rc=pNetUserGetInfo(sBadNetPath, sAdminUserName, 0, (LPBYTE *)&ui0);
114 ok(rc == ERROR_BAD_NETPATH || rc == ERROR_NETWORK_UNREACHABLE,
115 "Bad Network Path: rc=%d\n",rc);
117 rc=pNetUserGetInfo(sEmptyStr, sAdminUserName, 0, (LPBYTE *)&ui0);
118 ok(rc == ERROR_BAD_NETPATH || rc == NERR_Success,
119 "Bad Network Path: rc=%d\n",rc);
120 rc=pNetUserGetInfo(sInvalidName, sAdminUserName, 0, (LPBYTE *)&ui0);
121 ok(rc == ERROR_INVALID_NAME,"Invalid Server Name: rc=%d\n",rc);
122 rc=pNetUserGetInfo(sInvalidName2, sAdminUserName, 0, (LPBYTE *)&ui0);
123 ok(rc == ERROR_INVALID_NAME,"Invalid Server Name: rc=%d\n",rc);
126 /* checks Level 1 of NetQueryDisplayInformation */
127 static void run_querydisplayinformation1_tests(void)
129 PNET_DISPLAY_USER Buffer, rec;
130 DWORD Result, EntryCount;
131 DWORD i = 0;
132 BOOL hasAdmin = FALSE;
133 BOOL hasGuest = FALSE;
135 if (!pNetQueryDisplayInformation)
136 return;
140 Result = pNetQueryDisplayInformation(
141 NULL, 1, i, 1000, MAX_PREFERRED_LENGTH, &EntryCount,
142 (PVOID *)&Buffer);
144 ok((Result == ERROR_SUCCESS) || (Result == ERROR_MORE_DATA),
145 "Information Retrieved\n");
146 rec = Buffer;
147 for(; EntryCount > 0; EntryCount--)
149 if (!lstrcmpW(rec->usri1_name, sAdminUserName))
151 ok(!hasAdmin, "One admin user\n");
152 ok(rec->usri1_flags & UF_SCRIPT, "UF_SCRIPT flag is set\n");
153 ok(rec->usri1_flags & UF_NORMAL_ACCOUNT, "UF_NORMAL_ACCOUNT flag is set\n");
154 hasAdmin = TRUE;
156 else if (!lstrcmpW(rec->usri1_name, sGuestUserName))
158 ok(!hasGuest, "One guest record\n");
159 ok(rec->usri1_flags & UF_SCRIPT, "UF_SCRIPT flag is set\n");
160 ok(rec->usri1_flags & UF_NORMAL_ACCOUNT, "UF_NORMAL_ACCOUNT flag is set\n");
161 hasGuest = TRUE;
164 i = rec->usri1_next_index;
165 rec++;
168 pNetApiBufferFree(Buffer);
169 } while (Result == ERROR_MORE_DATA);
171 ok(hasAdmin, "Has Administrator account\n");
174 static void run_usermodalsget_tests(void)
176 NET_API_STATUS rc;
177 USER_MODALS_INFO_2 * umi2 = NULL;
179 rc = pNetUserModalsGet(NULL, 2, (LPBYTE *)&umi2);
180 ok(rc == ERROR_SUCCESS, "NetUserModalsGet failed, rc = %d\n", rc);
182 if (umi2)
183 pNetApiBufferFree(umi2);
186 START_TEST(access)
188 HMODULE hnetapi32=LoadLibraryA("netapi32.dll");
189 pNetApiBufferFree=(void*)GetProcAddress(hnetapi32,"NetApiBufferFree");
190 pNetApiBufferSize=(void*)GetProcAddress(hnetapi32,"NetApiBufferSize");
191 pNetQueryDisplayInformation=(void*)GetProcAddress(hnetapi32,"NetQueryDisplayInformation");
192 pNetUserGetInfo=(void*)GetProcAddress(hnetapi32,"NetUserGetInfo");
193 pNetUserModalsGet=(void*)GetProcAddress(hnetapi32,"NetUserModalsGet");
195 if (!pNetApiBufferSize)
196 trace("It appears there is no netapi32 functionality on this platform\n");
198 if (init_access_tests()) {
199 run_usergetinfo_tests();
200 run_querydisplayinformation1_tests();
201 run_usermodalsget_tests();