2 * Copyright 2002 Andriy Palamarchuk
4 * netapi32 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
27 #include "netapi32_misc.h"
28 #include "wine/debug.h"
29 #include "wine/unicode.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(netapi32);
33 const WCHAR sAdminUserName[] = {'A','d','m','i','n','i','s','t','r','a','t',
35 const WCHAR sGuestUserName[] = {'G','u','e','s','t',0};
37 /************************************************************
38 * NETAPI_ValidateServername
40 * Validates server name
42 NET_API_STATUS NETAPI_ValidateServername(LPCWSTR ServerName)
46 if (ServerName[0] == 0)
47 return ERROR_BAD_NETPATH;
49 ((ServerName[0] == '\\') &&
50 (ServerName[1] != '\\'))
52 ((ServerName[0] == '\\') &&
53 (ServerName[1] == '\\') &&
56 return ERROR_INVALID_NAME;
61 /************************************************************
64 * Checks whether the user name indicates current user.
66 BOOL NETAPI_IsKnownUser(LPCWSTR UserName)
68 DWORD dwSize = UNLEN + 1;
72 if (!lstrcmpW(UserName, sAdminUserName) ||
73 !lstrcmpW(UserName, sGuestUserName))
75 NetApiBufferAllocate(dwSize * sizeof(WCHAR), (LPVOID *) &buf);
76 Result = GetUserNameW(buf, &dwSize);
78 Result = Result && !lstrcmpW(UserName, buf);
79 NetApiBufferFree(buf);
84 #define NETAPI_ForceKnownUser(UserName, FailureCode) \
85 if (!NETAPI_IsKnownUser(UserName)) \
87 FIXME("Can't find information for user %s\n", \
88 debugstr_w(UserName)); \
92 /************************************************************
93 * NetUserGetInfo (NETAPI32.@)
96 NetUserGetInfo(LPCWSTR servername, LPCWSTR username, DWORD level,
99 NET_API_STATUS status;
100 TRACE("(%s, %s, %ld, %p)\n", debugstr_w(servername), debugstr_w(username),
102 status = NETAPI_ValidateServername(servername);
103 if (status != NERR_Success)
105 NETAPI_ForceLocalComputer(servername, NERR_InvalidComputer);
106 NETAPI_ForceKnownUser(username, NERR_UserNotFound);
115 name_sz = lstrlenW(username) + 1;
118 NetApiBufferAllocate(sizeof(USER_INFO_0) + name_sz * sizeof(WCHAR),
121 ui = (PUSER_INFO_0) *bufptr;
122 ui->usri0_name = (LPWSTR) (*bufptr + sizeof(USER_INFO_0));
125 lstrcpyW(ui->usri0_name, username);
133 NET_API_STATUS status;
134 /* sizes of the field buffers in WCHARS */
135 int name_sz, comment_sz, usr_comment_sz, full_name_sz;
142 status = NetUserGetInfo(servername, username, 0, (LPBYTE *) &ui0);
143 if (status != NERR_Success)
145 NetApiBufferFree(ui0);
148 name_sz = lstrlenW(ui0->usri0_name) + 1;
151 NetApiBufferAllocate(sizeof(USER_INFO_10) +
152 (name_sz + comment_sz + usr_comment_sz +
153 full_name_sz) * sizeof(WCHAR),
155 ui = (PUSER_INFO_10) *bufptr;
156 ui->usri10_name = (LPWSTR) (*bufptr + sizeof(USER_INFO_10));
157 ui->usri10_comment = (LPWSTR) (
158 ((PBYTE) ui->usri10_name) + name_sz * sizeof(WCHAR));
159 ui->usri10_usr_comment = (LPWSTR) (
160 ((PBYTE) ui->usri10_comment) + comment_sz * sizeof(WCHAR));
161 ui->usri10_full_name = (LPWSTR) (
162 ((PBYTE) ui->usri10_usr_comment) + usr_comment_sz * sizeof(WCHAR));
165 lstrcpyW(ui->usri10_name, ui0->usri0_name);
166 NetApiBufferFree(ui0);
167 ui->usri10_comment[0] = 0;
168 ui->usri10_usr_comment[0] = 0;
169 ui->usri10_full_name[0] = 0;
201 FIXME("Level %ld is not implemented\n", level);
205 ERR("Invalid level %ld is specified\n", level);
206 return ERROR_INVALID_LEVEL;
211 /************************************************************
212 * ACCESS_QueryAdminDisplayInformation
214 * Creates a buffer with information for the Admin User
216 void ACCESS_QueryAdminDisplayInformation(PNET_DISPLAY_USER *buf, PDWORD pdwSize)
218 const WCHAR sAdminUserName[] = {
219 'A','d','m','i','n','i','s','t','r','a','t','o','r',0};
221 /* sizes of the field buffers in WCHARS */
222 int name_sz, comment_sz, full_name_sz;
223 PNET_DISPLAY_USER usr;
226 name_sz = lstrlenW(sAdminUserName);
230 *pdwSize = sizeof(NET_DISPLAY_USER);
231 *pdwSize += (name_sz + comment_sz + full_name_sz) * sizeof(WCHAR);
232 NetApiBufferAllocate(*pdwSize, (LPVOID *) buf);
235 usr->usri1_name = (LPWSTR) ((PBYTE) usr + sizeof(NET_DISPLAY_USER));
236 usr->usri1_comment = (LPWSTR) (
237 ((PBYTE) usr->usri1_name) + name_sz * sizeof(WCHAR));
238 usr->usri1_full_name = (LPWSTR) (
239 ((PBYTE) usr->usri1_comment) + comment_sz * sizeof(WCHAR));
242 lstrcpyW(usr->usri1_name, sAdminUserName);
243 usr->usri1_comment[0] = 0;
244 usr->usri1_flags = UF_SCRIPT | UF_NORMAL_ACCOUNT | UF_DONT_EXPIRE_PASSWD;
245 usr->usri1_full_name[0] = 0;
246 usr->usri1_user_id = 500;
247 usr->usri1_next_index = 0;
250 /************************************************************
251 * ACCESS_QueryGuestDisplayInformation
253 * Creates a buffer with information for the Guest User
255 void ACCESS_QueryGuestDisplayInformation(PNET_DISPLAY_USER *buf, PDWORD pdwSize)
257 const WCHAR sGuestUserName[] = {
258 'G','u','e','s','t',0 };
260 /* sizes of the field buffers in WCHARS */
261 int name_sz, comment_sz, full_name_sz;
262 PNET_DISPLAY_USER usr;
265 name_sz = lstrlenW(sGuestUserName);
269 *pdwSize = sizeof(NET_DISPLAY_USER);
270 *pdwSize += (name_sz + comment_sz + full_name_sz) * sizeof(WCHAR);
271 NetApiBufferAllocate(*pdwSize, (LPVOID *) buf);
274 usr->usri1_name = (LPWSTR) ((PBYTE) usr + sizeof(NET_DISPLAY_USER));
275 usr->usri1_comment = (LPWSTR) (
276 ((PBYTE) usr->usri1_name) + name_sz * sizeof(WCHAR));
277 usr->usri1_full_name = (LPWSTR) (
278 ((PBYTE) usr->usri1_comment) + comment_sz * sizeof(WCHAR));
281 lstrcpyW(usr->usri1_name, sGuestUserName);
282 usr->usri1_comment[0] = 0;
283 usr->usri1_flags = UF_ACCOUNTDISABLE | UF_SCRIPT | UF_NORMAL_ACCOUNT |
284 UF_DONT_EXPIRE_PASSWD;
285 usr->usri1_full_name[0] = 0;
286 usr->usri1_user_id = 500;
287 usr->usri1_next_index = 0;
290 /************************************************************
291 * NetQueryDisplayInformation (NETAPI32.@)
292 * Copies NET_DISPLAY_USER record.
294 void ACCESS_CopyDisplayUser(PNET_DISPLAY_USER dest, LPWSTR *dest_buf,
295 PNET_DISPLAY_USER src)
297 LPWSTR str = *dest_buf;
299 src->usri1_name = str;
300 lstrcpyW(src->usri1_name, dest->usri1_name);
302 ((PBYTE) str) + (lstrlenW(str) + 1) * sizeof(WCHAR));
304 src->usri1_comment = str;
305 lstrcpyW(src->usri1_comment, dest->usri1_comment);
307 ((PBYTE) str) + (lstrlenW(str) + 1) * sizeof(WCHAR));
309 src->usri1_flags = dest->usri1_flags;
311 src->usri1_full_name = str;
312 lstrcpyW(src->usri1_full_name, dest->usri1_full_name);
314 ((PBYTE) str) + (lstrlenW(str) + 1) * sizeof(WCHAR));
316 src->usri1_user_id = dest->usri1_user_id;
317 src->usri1_next_index = dest->usri1_next_index;
321 /************************************************************
322 * NetQueryDisplayInformation (NETAPI32.@)
324 * The buffer structure:
325 * - array of fixed size record of the level type
326 * - strings, referenced by the record of the level type
328 NET_API_STATUS WINAPI
329 NetQueryDisplayInformation(
330 LPWSTR ServerName, DWORD Level, DWORD Index, DWORD EntriesRequested,
331 DWORD PreferredMaximumLength, LPDWORD ReturnedEntryCount,
334 TRACE("(%s, %ld, %ld, %ld, %ld, %p, %p)\n", debugstr_w(ServerName),
335 Level, Index, EntriesRequested, PreferredMaximumLength,
336 ReturnedEntryCount, SortedBuffer);
337 NETAPI_ForceLocalComputer(ServerName, ERROR_ACCESS_DENIED);
343 PNET_DISPLAY_USER inf;
344 /* current available strings buffer */
346 PNET_DISPLAY_USER admin, guest;
347 DWORD admin_size, guest_size;
351 /* sizes of the field buffers in WCHARS */
352 int name_sz, comment_sz, full_name_sz;
354 /* number of the records, returned in SortedBuffer
355 3 - for current user, Administrator and Guest users
359 FIXME("Level %ld partially implemented\n", Level);
360 *ReturnedEntryCount = records;
366 NetApiBufferAllocate(dwSize, (LPVOID *) &name);
367 if (!GetUserNameW(name, &dwSize))
369 NetApiBufferFree(name);
370 return ERROR_ACCESS_DENIED;
373 ACCESS_QueryAdminDisplayInformation(&admin, &admin_size);
374 ACCESS_QueryGuestDisplayInformation(&guest, &guest_size);
377 dwSize = sizeof(NET_DISPLAY_USER) * records;
378 dwSize += (name_sz + comment_sz + full_name_sz) * sizeof(WCHAR);
380 NetApiBufferAllocate(dwSize +
381 admin_size - sizeof(NET_DISPLAY_USER) +
382 guest_size - sizeof(NET_DISPLAY_USER),
383 (LPVOID *) SortedBuffer);
384 inf = (PNET_DISPLAY_USER) *SortedBuffer;
385 str = (LPWSTR) ((PBYTE) inf + sizeof(NET_DISPLAY_USER) * records);
386 inf->usri1_name = str;
388 ((PBYTE) str) + name_sz * sizeof(WCHAR));
389 inf->usri1_comment = str;
391 ((PBYTE) str) + comment_sz * sizeof(WCHAR));
392 inf->usri1_full_name = str;
394 ((PBYTE) str) + full_name_sz * sizeof(WCHAR));
397 lstrcpyW(inf->usri1_name, name);
398 NetApiBufferFree(name);
399 inf->usri1_comment[0] = 0;
401 UF_SCRIPT | UF_NORMAL_ACCOUNT | UF_DONT_EXPIRE_PASSWD;
402 inf->usri1_full_name[0] = 0;
403 inf->usri1_user_id = 0;
404 inf->usri1_next_index = 0;
407 ACCESS_CopyDisplayUser(admin, &str, inf);
408 NetApiBufferFree(admin);
411 ACCESS_CopyDisplayUser(guest, &str, inf);
412 NetApiBufferFree(guest);
419 FIXME("Level %ld is not implemented\n", Level);
424 ERR("Invalid level %ld is specified\n", Level);
425 return ERROR_INVALID_LEVEL;