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
30 #include "netapi32_misc.h"
31 #include "wine/debug.h"
32 #include "wine/unicode.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(netapi32);
36 static const WCHAR sAdminUserName[] = {'A','d','m','i','n','i','s','t','r','a','t',
38 static const WCHAR sGuestUserName[] = {'G','u','e','s','t',0};
40 /************************************************************
41 * NETAPI_ValidateServername
43 * Validates server name
45 NET_API_STATUS NETAPI_ValidateServername(LPCWSTR ServerName)
49 if (ServerName[0] == 0)
50 return ERROR_BAD_NETPATH;
52 ((ServerName[0] == '\\') &&
53 (ServerName[1] != '\\'))
55 ((ServerName[0] == '\\') &&
56 (ServerName[1] == '\\') &&
59 return ERROR_INVALID_NAME;
64 /************************************************************
67 * Checks whether the user name indicates current user.
69 BOOL NETAPI_IsKnownUser(LPCWSTR UserName)
71 DWORD dwSize = UNLEN + 1;
75 if (!lstrcmpW(UserName, sAdminUserName) ||
76 !lstrcmpW(UserName, sGuestUserName))
78 NetApiBufferAllocate(dwSize * sizeof(WCHAR), (LPVOID *) &buf);
79 Result = GetUserNameW(buf, &dwSize);
81 Result = Result && !lstrcmpW(UserName, buf);
82 NetApiBufferFree(buf);
87 #define NETAPI_ForceKnownUser(UserName, FailureCode) \
88 if (!NETAPI_IsKnownUser(UserName)) \
90 FIXME("Can't find information for user %s\n", \
91 debugstr_w(UserName)); \
95 /************************************************************
96 * NetUserGetInfo (NETAPI32.@)
99 NetUserGetInfo(LPCWSTR servername, LPCWSTR username, DWORD level,
102 NET_API_STATUS status;
103 TRACE("(%s, %s, %ld, %p)\n", debugstr_w(servername), debugstr_w(username),
105 status = NETAPI_ValidateServername(servername);
106 if (status != NERR_Success)
108 NETAPI_ForceLocalComputer(servername, NERR_InvalidComputer);
109 NETAPI_ForceKnownUser(username, NERR_UserNotFound);
118 name_sz = lstrlenW(username) + 1;
121 NetApiBufferAllocate(sizeof(USER_INFO_0) + name_sz * sizeof(WCHAR),
124 ui = (PUSER_INFO_0) *bufptr;
125 ui->usri0_name = (LPWSTR) (*bufptr + sizeof(USER_INFO_0));
128 lstrcpyW(ui->usri0_name, username);
136 NET_API_STATUS status;
137 /* sizes of the field buffers in WCHARS */
138 int name_sz, comment_sz, usr_comment_sz, full_name_sz;
145 status = NetUserGetInfo(servername, username, 0, (LPBYTE *) &ui0);
146 if (status != NERR_Success)
148 NetApiBufferFree(ui0);
151 name_sz = lstrlenW(ui0->usri0_name) + 1;
154 NetApiBufferAllocate(sizeof(USER_INFO_10) +
155 (name_sz + comment_sz + usr_comment_sz +
156 full_name_sz) * sizeof(WCHAR),
158 ui = (PUSER_INFO_10) *bufptr;
159 ui->usri10_name = (LPWSTR) (*bufptr + sizeof(USER_INFO_10));
160 ui->usri10_comment = (LPWSTR) (
161 ((PBYTE) ui->usri10_name) + name_sz * sizeof(WCHAR));
162 ui->usri10_usr_comment = (LPWSTR) (
163 ((PBYTE) ui->usri10_comment) + comment_sz * sizeof(WCHAR));
164 ui->usri10_full_name = (LPWSTR) (
165 ((PBYTE) ui->usri10_usr_comment) + usr_comment_sz * sizeof(WCHAR));
168 lstrcpyW(ui->usri10_name, ui0->usri0_name);
169 NetApiBufferFree(ui0);
170 ui->usri10_comment[0] = 0;
171 ui->usri10_usr_comment[0] = 0;
172 ui->usri10_full_name[0] = 0;
178 static const WCHAR homedirW[] = {'H','O','M','E',0};
181 NET_API_STATUS status;
182 /* sizes of the field buffers in WCHARS */
183 int name_sz, password_sz, home_dir_sz, comment_sz, script_path_sz;
185 password_sz = 1; /* not filled out for security reasons for NetUserGetInfo*/
190 status = NetUserGetInfo(servername, username, 0, (LPBYTE *) &ui0);
191 if (status != NERR_Success)
193 NetApiBufferFree(ui0);
196 name_sz = lstrlenW(ui0->usri0_name) + 1;
197 home_dir_sz = GetEnvironmentVariableW(homedirW, NULL,0);
199 NetApiBufferAllocate(sizeof(USER_INFO_1) +
200 (name_sz + password_sz + home_dir_sz +
201 comment_sz + script_path_sz) * sizeof(WCHAR),
204 ui = (PUSER_INFO_1) *bufptr;
205 ui->usri1_name = (LPWSTR) (ui + 1);
206 ui->usri1_password = ui->usri1_name + name_sz;
207 ui->usri1_home_dir = ui->usri1_password + password_sz;
208 ui->usri1_comment = ui->usri1_home_dir + home_dir_sz;
209 ui->usri1_script_path = ui->usri1_comment + comment_sz;
211 lstrcpyW(ui->usri1_name, ui0->usri0_name);
212 NetApiBufferFree(ui0);
213 ui->usri1_password[0] = 0;
214 ui->usri1_password_age = 0;
216 GetEnvironmentVariableW(homedirW, ui->usri1_home_dir,home_dir_sz);
217 ui->usri1_comment[0] = 0;
219 ui->usri1_script_path[0] = 0;
249 FIXME("Level %ld is not implemented\n", level);
253 ERR("Invalid level %ld is specified\n", level);
254 return ERROR_INVALID_LEVEL;
261 /************************************************************
262 * NetUserEnum (NETAPI32.@)
264 NET_API_STATUS WINAPI
265 NetUserEnum(LPCWSTR servername, DWORD level, DWORD filter, LPBYTE* bufptr,
266 DWORD prefmaxlen, LPDWORD entriesread, LPDWORD totalentries,
267 LPDWORD resume_handle)
270 return ERROR_ACCESS_DENIED;
273 /************************************************************
274 * ACCESS_QueryAdminDisplayInformation
276 * Creates a buffer with information for the Admin User
278 void ACCESS_QueryAdminDisplayInformation(PNET_DISPLAY_USER *buf, PDWORD pdwSize)
280 static const WCHAR sAdminUserName[] = {
281 'A','d','m','i','n','i','s','t','r','a','t','o','r',0};
283 /* sizes of the field buffers in WCHARS */
284 int name_sz, comment_sz, full_name_sz;
285 PNET_DISPLAY_USER usr;
288 name_sz = lstrlenW(sAdminUserName);
292 *pdwSize = sizeof(NET_DISPLAY_USER);
293 *pdwSize += (name_sz + comment_sz + full_name_sz) * sizeof(WCHAR);
294 NetApiBufferAllocate(*pdwSize, (LPVOID *) buf);
297 usr->usri1_name = (LPWSTR) ((PBYTE) usr + sizeof(NET_DISPLAY_USER));
298 usr->usri1_comment = (LPWSTR) (
299 ((PBYTE) usr->usri1_name) + name_sz * sizeof(WCHAR));
300 usr->usri1_full_name = (LPWSTR) (
301 ((PBYTE) usr->usri1_comment) + comment_sz * sizeof(WCHAR));
304 lstrcpyW(usr->usri1_name, sAdminUserName);
305 usr->usri1_comment[0] = 0;
306 usr->usri1_flags = UF_SCRIPT | UF_NORMAL_ACCOUNT | UF_DONT_EXPIRE_PASSWD;
307 usr->usri1_full_name[0] = 0;
308 usr->usri1_user_id = 500;
309 usr->usri1_next_index = 0;
312 /************************************************************
313 * ACCESS_QueryGuestDisplayInformation
315 * Creates a buffer with information for the Guest User
317 void ACCESS_QueryGuestDisplayInformation(PNET_DISPLAY_USER *buf, PDWORD pdwSize)
319 static const WCHAR sGuestUserName[] = {
320 'G','u','e','s','t',0 };
322 /* sizes of the field buffers in WCHARS */
323 int name_sz, comment_sz, full_name_sz;
324 PNET_DISPLAY_USER usr;
327 name_sz = lstrlenW(sGuestUserName);
331 *pdwSize = sizeof(NET_DISPLAY_USER);
332 *pdwSize += (name_sz + comment_sz + full_name_sz) * sizeof(WCHAR);
333 NetApiBufferAllocate(*pdwSize, (LPVOID *) buf);
336 usr->usri1_name = (LPWSTR) ((PBYTE) usr + sizeof(NET_DISPLAY_USER));
337 usr->usri1_comment = (LPWSTR) (
338 ((PBYTE) usr->usri1_name) + name_sz * sizeof(WCHAR));
339 usr->usri1_full_name = (LPWSTR) (
340 ((PBYTE) usr->usri1_comment) + comment_sz * sizeof(WCHAR));
343 lstrcpyW(usr->usri1_name, sGuestUserName);
344 usr->usri1_comment[0] = 0;
345 usr->usri1_flags = UF_ACCOUNTDISABLE | UF_SCRIPT | UF_NORMAL_ACCOUNT |
346 UF_DONT_EXPIRE_PASSWD;
347 usr->usri1_full_name[0] = 0;
348 usr->usri1_user_id = 500;
349 usr->usri1_next_index = 0;
352 /************************************************************
353 * NetQueryDisplayInformation (NETAPI32.@)
354 * Copies NET_DISPLAY_USER record.
356 void ACCESS_CopyDisplayUser(PNET_DISPLAY_USER dest, LPWSTR *dest_buf,
357 PNET_DISPLAY_USER src)
359 LPWSTR str = *dest_buf;
361 src->usri1_name = str;
362 lstrcpyW(src->usri1_name, dest->usri1_name);
364 ((PBYTE) str) + (lstrlenW(str) + 1) * sizeof(WCHAR));
366 src->usri1_comment = str;
367 lstrcpyW(src->usri1_comment, dest->usri1_comment);
369 ((PBYTE) str) + (lstrlenW(str) + 1) * sizeof(WCHAR));
371 src->usri1_flags = dest->usri1_flags;
373 src->usri1_full_name = str;
374 lstrcpyW(src->usri1_full_name, dest->usri1_full_name);
376 ((PBYTE) str) + (lstrlenW(str) + 1) * sizeof(WCHAR));
378 src->usri1_user_id = dest->usri1_user_id;
379 src->usri1_next_index = dest->usri1_next_index;
383 /************************************************************
384 * NetQueryDisplayInformation (NETAPI32.@)
386 * The buffer structure:
387 * - array of fixed size record of the level type
388 * - strings, referenced by the record of the level type
390 NET_API_STATUS WINAPI
391 NetQueryDisplayInformation(
392 LPWSTR ServerName, DWORD Level, DWORD Index, DWORD EntriesRequested,
393 DWORD PreferredMaximumLength, LPDWORD ReturnedEntryCount,
396 TRACE("(%s, %ld, %ld, %ld, %ld, %p, %p)\n", debugstr_w(ServerName),
397 Level, Index, EntriesRequested, PreferredMaximumLength,
398 ReturnedEntryCount, SortedBuffer);
399 NETAPI_ForceLocalComputer(ServerName, ERROR_ACCESS_DENIED);
405 PNET_DISPLAY_USER inf;
406 /* current available strings buffer */
408 PNET_DISPLAY_USER admin, guest;
409 DWORD admin_size, guest_size;
413 /* sizes of the field buffers in WCHARS */
414 int name_sz, comment_sz, full_name_sz;
416 /* number of the records, returned in SortedBuffer
417 3 - for current user, Administrator and Guest users
421 FIXME("Level %ld partially implemented\n", Level);
422 *ReturnedEntryCount = records;
428 NetApiBufferAllocate(dwSize, (LPVOID *) &name);
429 if (!GetUserNameW(name, &dwSize))
431 NetApiBufferFree(name);
432 return ERROR_ACCESS_DENIED;
435 ACCESS_QueryAdminDisplayInformation(&admin, &admin_size);
436 ACCESS_QueryGuestDisplayInformation(&guest, &guest_size);
439 dwSize = sizeof(NET_DISPLAY_USER) * records;
440 dwSize += (name_sz + comment_sz + full_name_sz) * sizeof(WCHAR);
442 NetApiBufferAllocate(dwSize +
443 admin_size - sizeof(NET_DISPLAY_USER) +
444 guest_size - sizeof(NET_DISPLAY_USER),
445 (LPVOID *) SortedBuffer);
446 inf = (PNET_DISPLAY_USER) *SortedBuffer;
447 str = (LPWSTR) ((PBYTE) inf + sizeof(NET_DISPLAY_USER) * records);
448 inf->usri1_name = str;
450 ((PBYTE) str) + name_sz * sizeof(WCHAR));
451 inf->usri1_comment = str;
453 ((PBYTE) str) + comment_sz * sizeof(WCHAR));
454 inf->usri1_full_name = str;
456 ((PBYTE) str) + full_name_sz * sizeof(WCHAR));
459 lstrcpyW(inf->usri1_name, name);
460 NetApiBufferFree(name);
461 inf->usri1_comment[0] = 0;
463 UF_SCRIPT | UF_NORMAL_ACCOUNT | UF_DONT_EXPIRE_PASSWD;
464 inf->usri1_full_name[0] = 0;
465 inf->usri1_user_id = 0;
466 inf->usri1_next_index = 0;
469 ACCESS_CopyDisplayUser(admin, &str, inf);
470 NetApiBufferFree(admin);
473 ACCESS_CopyDisplayUser(guest, &str, inf);
474 NetApiBufferFree(guest);
481 FIXME("Level %ld is not implemented\n", Level);
486 ERR("Invalid level %ld is specified\n", Level);
487 return ERROR_INVALID_LEVEL;
492 /************************************************************
493 * NetGetDCName (NETAPI32.@)
495 * Return the name of the primary domain controller (PDC)
498 NET_API_STATUS WINAPI
499 NetGetDCName(LPWSTR servername, LPWSTR domainname, LPBYTE *bufptr)
502 return NERR_DCNotFound; /* say we can't find a domain controller */
506 /************************************************************
507 * NetUserModalsGet (NETAPI32.@)
509 NET_API_STATUS WINAPI NetUserModalsGet(LPCWSTR szServer, DWORD level, LPBYTE *pbuffer)
511 FIXME("%s %ld %p\n", debugstr_w( szServer ), level, pbuffer );
512 return NERR_InternalError;
515 NET_API_STATUS WINAPI NetLocalGroupAdd( LPCWSTR servername, DWORD level,
516 LPBYTE buf, LPDWORD parm_err)
518 FIXME("%s %ld %p %p\n", debugstr_w( servername ), level, buf, parm_err);
522 NET_API_STATUS WINAPI NetLocalGroupSetMembers( LPCWSTR servername,
523 LPCWSTR groupname, DWORD level, LPBYTE buf, DWORD totalentries)
525 FIXME("%s %s %ld %p %ld\n", debugstr_w(servername), debugstr_w(groupname),
526 level, buf, totalentries);