widl: Replace write_name() by get_name() to make the code more readable.
[wine.git] / dlls / netapi32 / access.c
blob5da07a617fd1c35e09e1cde31295c29c45637be9
1 /*
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <stdarg.h>
23 #include "ntstatus.h"
24 #define WIN32_NO_STATUS
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winerror.h"
28 #include "lmcons.h"
29 #include "lmaccess.h"
30 #include "lmapibuf.h"
31 #include "lmerr.h"
32 #include "lmuse.h"
33 #include "ntsecapi.h"
34 #include "wine/debug.h"
35 #include "wine/unicode.h"
36 #include "wine/list.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(netapi32);
40 /* NOTE: So far, this is implemented to support tests that require user logins,
41 * but not designed to handle real user databases. Those should probably
42 * be synced with either the host's user database or with Samba.
44 * FIXME: The user database should hold all the information the USER_INFO_4 struct
45 * needs, but for the first try, I will just implement the USER_INFO_1 fields.
48 struct sam_user
50 struct list entry;
51 WCHAR user_name[LM20_UNLEN+1];
52 WCHAR user_password[PWLEN + 1];
53 DWORD sec_since_passwd_change;
54 DWORD user_priv;
55 LPWSTR home_dir;
56 LPWSTR user_comment;
57 DWORD user_flags;
58 LPWSTR user_logon_script_path;
61 static struct list user_list = LIST_INIT( user_list );
63 BOOL NETAPI_IsLocalComputer(LPCWSTR ServerName);
65 /************************************************************
66 * NETAPI_ValidateServername
68 * Validates server name
70 static NET_API_STATUS NETAPI_ValidateServername(LPCWSTR ServerName)
72 if (ServerName)
74 if (ServerName[0] == 0)
75 return ERROR_BAD_NETPATH;
76 else if (
77 ((ServerName[0] == '\\') &&
78 (ServerName[1] != '\\'))
80 ((ServerName[0] == '\\') &&
81 (ServerName[1] == '\\') &&
82 (ServerName[2] == 0))
84 return ERROR_INVALID_NAME;
86 return NERR_Success;
89 /************************************************************
90 * NETAPI_FindUser
92 * Looks for a user in the user database.
93 * Returns a pointer to the entry in the user list when the user
94 * is found, NULL otherwise.
96 static struct sam_user* NETAPI_FindUser(LPCWSTR UserName)
98 struct sam_user *user;
100 LIST_FOR_EACH_ENTRY(user, &user_list, struct sam_user, entry)
102 if(lstrcmpW(user->user_name, UserName) == 0)
103 return user;
105 return NULL;
108 static BOOL NETAPI_IsCurrentUser(LPCWSTR username)
110 LPWSTR curr_user = NULL;
111 DWORD dwSize;
112 BOOL ret = FALSE;
114 dwSize = LM20_UNLEN+1;
115 curr_user = HeapAlloc(GetProcessHeap(), 0, dwSize);
116 if(!curr_user)
118 ERR("Failed to allocate memory for user name.\n");
119 goto end;
121 if(!GetUserNameW(curr_user, &dwSize))
123 ERR("Failed to get current user's user name.\n");
124 goto end;
126 if (!lstrcmpW(curr_user, username))
128 ret = TRUE;
131 end:
132 HeapFree(GetProcessHeap(), 0, curr_user);
133 return ret;
136 /************************************************************
137 * NetUserAdd (NETAPI32.@)
139 NET_API_STATUS WINAPI NetUserAdd(LPCWSTR servername,
140 DWORD level, LPBYTE bufptr, LPDWORD parm_err)
142 NET_API_STATUS status;
143 struct sam_user * su = NULL;
145 FIXME("(%s, %d, %p, %p) stub!\n", debugstr_w(servername), level, bufptr, parm_err);
147 if((status = NETAPI_ValidateServername(servername)) != NERR_Success)
148 return status;
150 switch(level)
152 /* Level 3 and 4 are identical for the purposes of NetUserAdd */
153 case 4:
154 case 3:
155 FIXME("Level 3 and 4 not implemented.\n");
156 /* Fall through */
157 case 2:
158 FIXME("Level 2 not implemented.\n");
159 /* Fall through */
160 case 1:
162 PUSER_INFO_1 ui = (PUSER_INFO_1) bufptr;
163 su = HeapAlloc(GetProcessHeap(), 0, sizeof(struct sam_user));
164 if(!su)
166 status = NERR_InternalError;
167 break;
170 if(lstrlenW(ui->usri1_name) > LM20_UNLEN)
172 status = NERR_BadUsername;
173 break;
176 /*FIXME: do other checks for a valid username */
177 lstrcpyW(su->user_name, ui->usri1_name);
179 if(lstrlenW(ui->usri1_password) > PWLEN)
181 /* Always return PasswordTooShort on invalid passwords. */
182 status = NERR_PasswordTooShort;
183 break;
185 lstrcpyW(su->user_password, ui->usri1_password);
187 su->sec_since_passwd_change = ui->usri1_password_age;
188 su->user_priv = ui->usri1_priv;
189 su->user_flags = ui->usri1_flags;
191 /*FIXME: set the other LPWSTRs to NULL for now */
192 su->home_dir = NULL;
193 su->user_comment = NULL;
194 su->user_logon_script_path = NULL;
196 list_add_head(&user_list, &su->entry);
197 return NERR_Success;
199 default:
200 TRACE("Invalid level %d specified.\n", level);
201 status = ERROR_INVALID_LEVEL;
202 break;
205 HeapFree(GetProcessHeap(), 0, su);
207 return status;
210 /************************************************************
211 * NetUserDel (NETAPI32.@)
213 NET_API_STATUS WINAPI NetUserDel(LPCWSTR servername, LPCWSTR username)
215 NET_API_STATUS status;
216 struct sam_user *user;
218 TRACE("(%s, %s)\n", debugstr_w(servername), debugstr_w(username));
220 if((status = NETAPI_ValidateServername(servername))!= NERR_Success)
221 return status;
223 if ((user = NETAPI_FindUser(username)) == NULL)
224 return NERR_UserNotFound;
226 list_remove(&user->entry);
228 HeapFree(GetProcessHeap(), 0, user->home_dir);
229 HeapFree(GetProcessHeap(), 0, user->user_comment);
230 HeapFree(GetProcessHeap(), 0, user->user_logon_script_path);
231 HeapFree(GetProcessHeap(), 0, user);
233 return NERR_Success;
236 /************************************************************
237 * NetUserGetInfo (NETAPI32.@)
239 NET_API_STATUS WINAPI
240 NetUserGetInfo(LPCWSTR servername, LPCWSTR username, DWORD level,
241 LPBYTE* bufptr)
243 NET_API_STATUS status;
244 TRACE("(%s, %s, %d, %p)\n", debugstr_w(servername), debugstr_w(username),
245 level, bufptr);
246 status = NETAPI_ValidateServername(servername);
247 if (status != NERR_Success)
248 return status;
250 if(!NETAPI_IsLocalComputer(servername))
252 FIXME("Only implemented for local computer, but remote server"
253 "%s was requested.\n", debugstr_w(servername));
254 return NERR_InvalidComputer;
257 if(!NETAPI_FindUser(username) && !NETAPI_IsCurrentUser(username))
259 TRACE("User %s is unknown.\n", debugstr_w(username));
260 return NERR_UserNotFound;
263 switch (level)
265 case 0:
267 PUSER_INFO_0 ui;
268 int name_sz;
270 name_sz = lstrlenW(username) + 1;
272 /* set up buffer */
273 NetApiBufferAllocate(sizeof(USER_INFO_0) + name_sz * sizeof(WCHAR),
274 (LPVOID *) bufptr);
276 ui = (PUSER_INFO_0) *bufptr;
277 ui->usri0_name = (LPWSTR) (*bufptr + sizeof(USER_INFO_0));
279 /* get data */
280 lstrcpyW(ui->usri0_name, username);
281 break;
284 case 10:
286 PUSER_INFO_10 ui;
287 PUSER_INFO_0 ui0;
288 NET_API_STATUS status;
289 /* sizes of the field buffers in WCHARS */
290 int name_sz, comment_sz, usr_comment_sz, full_name_sz;
292 comment_sz = 1;
293 usr_comment_sz = 1;
294 full_name_sz = 1;
296 /* get data */
297 status = NetUserGetInfo(servername, username, 0, (LPBYTE *) &ui0);
298 if (status != NERR_Success)
300 NetApiBufferFree(ui0);
301 return status;
303 name_sz = lstrlenW(ui0->usri0_name) + 1;
305 /* set up buffer */
306 NetApiBufferAllocate(sizeof(USER_INFO_10) +
307 (name_sz + comment_sz + usr_comment_sz +
308 full_name_sz) * sizeof(WCHAR),
309 (LPVOID *) bufptr);
310 ui = (PUSER_INFO_10) *bufptr;
311 ui->usri10_name = (LPWSTR) (*bufptr + sizeof(USER_INFO_10));
312 ui->usri10_comment = (LPWSTR) (
313 ((PBYTE) ui->usri10_name) + name_sz * sizeof(WCHAR));
314 ui->usri10_usr_comment = (LPWSTR) (
315 ((PBYTE) ui->usri10_comment) + comment_sz * sizeof(WCHAR));
316 ui->usri10_full_name = (LPWSTR) (
317 ((PBYTE) ui->usri10_usr_comment) + usr_comment_sz * sizeof(WCHAR));
319 /* set data */
320 lstrcpyW(ui->usri10_name, ui0->usri0_name);
321 NetApiBufferFree(ui0);
322 ui->usri10_comment[0] = 0;
323 ui->usri10_usr_comment[0] = 0;
324 ui->usri10_full_name[0] = 0;
325 break;
328 case 1:
330 static const WCHAR homedirW[] = {'H','O','M','E',0};
331 PUSER_INFO_1 ui;
332 PUSER_INFO_0 ui0;
333 NET_API_STATUS status;
334 /* sizes of the field buffers in WCHARS */
335 int name_sz, password_sz, home_dir_sz, comment_sz, script_path_sz;
337 password_sz = 1; /* not filled out for security reasons for NetUserGetInfo*/
338 comment_sz = 1;
339 script_path_sz = 1;
341 /* get data */
342 status = NetUserGetInfo(servername, username, 0, (LPBYTE *) &ui0);
343 if (status != NERR_Success)
345 NetApiBufferFree(ui0);
346 return status;
348 name_sz = lstrlenW(ui0->usri0_name) + 1;
349 home_dir_sz = GetEnvironmentVariableW(homedirW, NULL,0);
350 /* set up buffer */
351 NetApiBufferAllocate(sizeof(USER_INFO_1) +
352 (name_sz + password_sz + home_dir_sz +
353 comment_sz + script_path_sz) * sizeof(WCHAR),
354 (LPVOID *) bufptr);
356 ui = (PUSER_INFO_1) *bufptr;
357 ui->usri1_name = (LPWSTR) (ui + 1);
358 ui->usri1_password = ui->usri1_name + name_sz;
359 ui->usri1_home_dir = ui->usri1_password + password_sz;
360 ui->usri1_comment = ui->usri1_home_dir + home_dir_sz;
361 ui->usri1_script_path = ui->usri1_comment + comment_sz;
362 /* set data */
363 lstrcpyW(ui->usri1_name, ui0->usri0_name);
364 NetApiBufferFree(ui0);
365 ui->usri1_password[0] = 0;
366 ui->usri1_password_age = 0;
367 ui->usri1_priv = 0;
368 GetEnvironmentVariableW(homedirW, ui->usri1_home_dir,home_dir_sz);
369 ui->usri1_comment[0] = 0;
370 ui->usri1_flags = 0;
371 ui->usri1_script_path[0] = 0;
372 break;
374 case 2:
375 case 3:
376 case 4:
377 case 11:
378 case 20:
379 case 23:
380 case 1003:
381 case 1005:
382 case 1006:
383 case 1007:
384 case 1008:
385 case 1009:
386 case 1010:
387 case 1011:
388 case 1012:
389 case 1013:
390 case 1014:
391 case 1017:
392 case 1018:
393 case 1020:
394 case 1023:
395 case 1024:
396 case 1025:
397 case 1051:
398 case 1052:
399 case 1053:
401 FIXME("Level %d is not implemented\n", level);
402 return NERR_InternalError;
404 default:
405 TRACE("Invalid level %d is specified\n", level);
406 return ERROR_INVALID_LEVEL;
408 return NERR_Success;
411 /************************************************************
412 * NetUserGetLocalGroups (NETAPI32.@)
414 NET_API_STATUS WINAPI
415 NetUserGetLocalGroups(LPCWSTR servername, LPCWSTR username, DWORD level,
416 DWORD flags, LPBYTE* bufptr, DWORD prefmaxlen,
417 LPDWORD entriesread, LPDWORD totalentries)
419 NET_API_STATUS status;
421 FIXME("(%s, %s, %d, %08x, %p %d, %p, %p) stub!\n",
422 debugstr_w(servername), debugstr_w(username), level, flags, bufptr,
423 prefmaxlen, entriesread, totalentries);
425 status = NETAPI_ValidateServername(servername);
426 if (status != NERR_Success)
427 return status;
429 if (!NETAPI_FindUser(username))
430 return NERR_UserNotFound;
432 if (bufptr) *bufptr = NULL;
433 if (entriesread) *entriesread = 0;
434 if (totalentries) *totalentries = 0;
436 return NERR_Success;
439 /************************************************************
440 * NetUserEnum (NETAPI32.@)
442 NET_API_STATUS WINAPI
443 NetUserEnum(LPCWSTR servername, DWORD level, DWORD filter, LPBYTE* bufptr,
444 DWORD prefmaxlen, LPDWORD entriesread, LPDWORD totalentries,
445 LPDWORD resume_handle)
447 FIXME("(%s,%d, 0x%d,%p,%d,%p,%p,%p) stub!\n", debugstr_w(servername), level,
448 filter, bufptr, prefmaxlen, entriesread, totalentries, resume_handle);
450 return ERROR_ACCESS_DENIED;
453 /************************************************************
454 * ACCESS_QueryAdminDisplayInformation
456 * Creates a buffer with information for the Admin User
458 static void ACCESS_QueryAdminDisplayInformation(PNET_DISPLAY_USER *buf, PDWORD pdwSize)
460 static const WCHAR sAdminUserName[] = {
461 'A','d','m','i','n','i','s','t','r','a','t','o','r',0};
463 /* sizes of the field buffers in WCHARS */
464 int name_sz, comment_sz, full_name_sz;
465 PNET_DISPLAY_USER usr;
467 /* set up buffer */
468 name_sz = lstrlenW(sAdminUserName);
469 comment_sz = 1;
470 full_name_sz = 1;
472 *pdwSize = sizeof(NET_DISPLAY_USER);
473 *pdwSize += (name_sz + comment_sz + full_name_sz) * sizeof(WCHAR);
474 NetApiBufferAllocate(*pdwSize, (LPVOID *) buf);
476 usr = *buf;
477 usr->usri1_name = (LPWSTR) ((PBYTE) usr + sizeof(NET_DISPLAY_USER));
478 usr->usri1_comment = (LPWSTR) (
479 ((PBYTE) usr->usri1_name) + name_sz * sizeof(WCHAR));
480 usr->usri1_full_name = (LPWSTR) (
481 ((PBYTE) usr->usri1_comment) + comment_sz * sizeof(WCHAR));
483 /* set data */
484 lstrcpyW(usr->usri1_name, sAdminUserName);
485 usr->usri1_comment[0] = 0;
486 usr->usri1_flags = UF_SCRIPT | UF_NORMAL_ACCOUNT | UF_DONT_EXPIRE_PASSWD;
487 usr->usri1_full_name[0] = 0;
488 usr->usri1_user_id = 500;
489 usr->usri1_next_index = 0;
492 /************************************************************
493 * ACCESS_QueryGuestDisplayInformation
495 * Creates a buffer with information for the Guest User
497 static void ACCESS_QueryGuestDisplayInformation(PNET_DISPLAY_USER *buf, PDWORD pdwSize)
499 static const WCHAR sGuestUserName[] = {
500 'G','u','e','s','t',0 };
502 /* sizes of the field buffers in WCHARS */
503 int name_sz, comment_sz, full_name_sz;
504 PNET_DISPLAY_USER usr;
506 /* set up buffer */
507 name_sz = lstrlenW(sGuestUserName);
508 comment_sz = 1;
509 full_name_sz = 1;
511 *pdwSize = sizeof(NET_DISPLAY_USER);
512 *pdwSize += (name_sz + comment_sz + full_name_sz) * sizeof(WCHAR);
513 NetApiBufferAllocate(*pdwSize, (LPVOID *) buf);
515 usr = *buf;
516 usr->usri1_name = (LPWSTR) ((PBYTE) usr + sizeof(NET_DISPLAY_USER));
517 usr->usri1_comment = (LPWSTR) (
518 ((PBYTE) usr->usri1_name) + name_sz * sizeof(WCHAR));
519 usr->usri1_full_name = (LPWSTR) (
520 ((PBYTE) usr->usri1_comment) + comment_sz * sizeof(WCHAR));
522 /* set data */
523 lstrcpyW(usr->usri1_name, sGuestUserName);
524 usr->usri1_comment[0] = 0;
525 usr->usri1_flags = UF_ACCOUNTDISABLE | UF_SCRIPT | UF_NORMAL_ACCOUNT |
526 UF_DONT_EXPIRE_PASSWD;
527 usr->usri1_full_name[0] = 0;
528 usr->usri1_user_id = 500;
529 usr->usri1_next_index = 0;
532 /************************************************************
533 * Copies NET_DISPLAY_USER record.
535 static void ACCESS_CopyDisplayUser(const NET_DISPLAY_USER *dest, LPWSTR *dest_buf,
536 PNET_DISPLAY_USER src)
538 LPWSTR str = *dest_buf;
540 src->usri1_name = str;
541 lstrcpyW(src->usri1_name, dest->usri1_name);
542 str = (LPWSTR) (
543 ((PBYTE) str) + (lstrlenW(str) + 1) * sizeof(WCHAR));
545 src->usri1_comment = str;
546 lstrcpyW(src->usri1_comment, dest->usri1_comment);
547 str = (LPWSTR) (
548 ((PBYTE) str) + (lstrlenW(str) + 1) * sizeof(WCHAR));
550 src->usri1_flags = dest->usri1_flags;
552 src->usri1_full_name = str;
553 lstrcpyW(src->usri1_full_name, dest->usri1_full_name);
554 str = (LPWSTR) (
555 ((PBYTE) str) + (lstrlenW(str) + 1) * sizeof(WCHAR));
557 src->usri1_user_id = dest->usri1_user_id;
558 src->usri1_next_index = dest->usri1_next_index;
559 *dest_buf = str;
562 /************************************************************
563 * NetQueryDisplayInformation (NETAPI32.@)
565 * The buffer structure:
566 * - array of fixed size record of the level type
567 * - strings, referenced by the record of the level type
569 NET_API_STATUS WINAPI
570 NetQueryDisplayInformation(
571 LPCWSTR ServerName, DWORD Level, DWORD Index, DWORD EntriesRequested,
572 DWORD PreferredMaximumLength, LPDWORD ReturnedEntryCount,
573 PVOID *SortedBuffer)
575 TRACE("(%s, %d, %d, %d, %d, %p, %p)\n", debugstr_w(ServerName),
576 Level, Index, EntriesRequested, PreferredMaximumLength,
577 ReturnedEntryCount, SortedBuffer);
579 if(!NETAPI_IsLocalComputer(ServerName))
581 FIXME("Only implemented on local computer, but requested for "
582 "remote server %s\n", debugstr_w(ServerName));
583 return ERROR_ACCESS_DENIED;
586 switch (Level)
588 case 1:
590 /* current record */
591 PNET_DISPLAY_USER inf;
592 /* current available strings buffer */
593 LPWSTR str;
594 PNET_DISPLAY_USER admin, guest;
595 DWORD admin_size, guest_size;
596 LPWSTR name = NULL;
597 DWORD dwSize;
599 /* sizes of the field buffers in WCHARS */
600 int name_sz, comment_sz, full_name_sz;
602 /* number of the records, returned in SortedBuffer
603 3 - for current user, Administrator and Guest users
605 int records = 3;
607 FIXME("Level %d partially implemented\n", Level);
608 *ReturnedEntryCount = records;
609 comment_sz = 1;
610 full_name_sz = 1;
612 /* get data */
613 dwSize = UNLEN + 1;
614 NetApiBufferAllocate(dwSize, (LPVOID *) &name);
615 if (!GetUserNameW(name, &dwSize))
617 NetApiBufferFree(name);
618 return ERROR_ACCESS_DENIED;
620 name_sz = dwSize;
621 ACCESS_QueryAdminDisplayInformation(&admin, &admin_size);
622 ACCESS_QueryGuestDisplayInformation(&guest, &guest_size);
624 /* set up buffer */
625 dwSize = sizeof(NET_DISPLAY_USER) * records;
626 dwSize += (name_sz + comment_sz + full_name_sz) * sizeof(WCHAR);
628 NetApiBufferAllocate(dwSize +
629 admin_size - sizeof(NET_DISPLAY_USER) +
630 guest_size - sizeof(NET_DISPLAY_USER),
631 SortedBuffer);
632 inf = (PNET_DISPLAY_USER) *SortedBuffer;
633 str = (LPWSTR) ((PBYTE) inf + sizeof(NET_DISPLAY_USER) * records);
634 inf->usri1_name = str;
635 str = (LPWSTR) (
636 ((PBYTE) str) + name_sz * sizeof(WCHAR));
637 inf->usri1_comment = str;
638 str = (LPWSTR) (
639 ((PBYTE) str) + comment_sz * sizeof(WCHAR));
640 inf->usri1_full_name = str;
641 str = (LPWSTR) (
642 ((PBYTE) str) + full_name_sz * sizeof(WCHAR));
644 /* set data */
645 lstrcpyW(inf->usri1_name, name);
646 NetApiBufferFree(name);
647 inf->usri1_comment[0] = 0;
648 inf->usri1_flags =
649 UF_SCRIPT | UF_NORMAL_ACCOUNT | UF_DONT_EXPIRE_PASSWD;
650 inf->usri1_full_name[0] = 0;
651 inf->usri1_user_id = 0;
652 inf->usri1_next_index = 0;
654 inf++;
655 ACCESS_CopyDisplayUser(admin, &str, inf);
656 NetApiBufferFree(admin);
658 inf++;
659 ACCESS_CopyDisplayUser(guest, &str, inf);
660 NetApiBufferFree(guest);
661 break;
664 case 2:
665 case 3:
667 FIXME("Level %d is not implemented\n", Level);
668 break;
671 default:
672 TRACE("Invalid level %d is specified\n", Level);
673 return ERROR_INVALID_LEVEL;
675 return NERR_Success;
678 /************************************************************
679 * NetGetDCName (NETAPI32.@)
681 * Return the name of the primary domain controller (PDC)
684 NET_API_STATUS WINAPI
685 NetGetDCName(LPCWSTR servername, LPCWSTR domainname, LPBYTE *bufptr)
687 FIXME("(%s, %s, %p) stub!\n", debugstr_w(servername),
688 debugstr_w(domainname), bufptr);
689 return NERR_DCNotFound; /* say we can't find a domain controller */
692 /************************************************************
693 * NetGroupEnum (NETAPI32.@)
696 NET_API_STATUS WINAPI
697 NetGroupEnum(LPCWSTR servername, DWORD level, LPBYTE *bufptr, DWORD prefmaxlen,
698 LPDWORD entriesread, LPDWORD totalentries, LPDWORD resume_handle)
700 FIXME("(%s, %d, %p, %d, %p, %p, %p) stub!\n", debugstr_w(servername),
701 level, bufptr, prefmaxlen, entriesread, totalentries, resume_handle);
702 return ERROR_ACCESS_DENIED;
705 /******************************************************************************
706 * NetUserModalsGet (NETAPI32.@)
708 * Retrieves global information for all users and global groups in the security
709 * database.
711 * PARAMS
712 * szServer [I] Specifies the DNS or the NetBIOS name of the remote server
713 * on which the function is to execute.
714 * level [I] Information level of the data.
715 * 0 Return global passwords parameters. bufptr points to a
716 * USER_MODALS_INFO_0 struct.
717 * 1 Return logon server and domain controller information. bufptr
718 * points to a USER_MODALS_INFO_1 struct.
719 * 2 Return domain name and identifier. bufptr points to a
720 * USER_MODALS_INFO_2 struct.
721 * 3 Return lockout information. bufptr points to a USER_MODALS_INFO_3
722 * struct.
723 * pbuffer [I] Buffer that receives the data.
725 * RETURNS
726 * Success: NERR_Success.
727 * Failure:
728 * ERROR_ACCESS_DENIED - the user does not have access to the info.
729 * NERR_InvalidComputer - computer name is invalid.
731 NET_API_STATUS WINAPI NetUserModalsGet(
732 LPCWSTR szServer, DWORD level, LPBYTE *pbuffer)
734 TRACE("(%s %d %p)\n", debugstr_w(szServer), level, pbuffer);
736 switch (level)
738 case 0:
739 /* return global passwords parameters */
740 FIXME("level 0 not implemented!\n");
741 *pbuffer = NULL;
742 return NERR_InternalError;
743 case 1:
744 /* return logon server and domain controller info */
745 FIXME("level 1 not implemented!\n");
746 *pbuffer = NULL;
747 return NERR_InternalError;
748 case 2:
750 /* return domain name and identifier */
751 PUSER_MODALS_INFO_2 umi;
752 LSA_HANDLE policyHandle;
753 LSA_OBJECT_ATTRIBUTES objectAttributes;
754 PPOLICY_ACCOUNT_DOMAIN_INFO domainInfo;
755 NTSTATUS ntStatus;
756 PSID domainIdentifier = NULL;
757 int domainNameLen;
759 ZeroMemory(&objectAttributes, sizeof(objectAttributes));
760 objectAttributes.Length = sizeof(objectAttributes);
762 ntStatus = LsaOpenPolicy(NULL, &objectAttributes,
763 POLICY_VIEW_LOCAL_INFORMATION,
764 &policyHandle);
765 if (ntStatus != STATUS_SUCCESS)
767 WARN("LsaOpenPolicy failed with NT status %x\n",
768 LsaNtStatusToWinError(ntStatus));
769 return ntStatus;
772 ntStatus = LsaQueryInformationPolicy(policyHandle,
773 PolicyAccountDomainInformation,
774 (PVOID *)&domainInfo);
775 if (ntStatus != STATUS_SUCCESS)
777 WARN("LsaQueryInformationPolicy failed with NT status %x\n",
778 LsaNtStatusToWinError(ntStatus));
779 LsaClose(policyHandle);
780 return ntStatus;
783 domainIdentifier = domainInfo->DomainSid;
784 domainNameLen = lstrlenW(domainInfo->DomainName.Buffer) + 1;
785 LsaClose(policyHandle);
787 ntStatus = NetApiBufferAllocate(sizeof(USER_MODALS_INFO_2) +
788 GetLengthSid(domainIdentifier) +
789 domainNameLen * sizeof(WCHAR),
790 (LPVOID *)pbuffer);
792 if (ntStatus != NERR_Success)
794 WARN("NetApiBufferAllocate() failed\n");
795 LsaFreeMemory(domainInfo);
796 return ntStatus;
799 umi = (USER_MODALS_INFO_2 *) *pbuffer;
800 umi->usrmod2_domain_id = (PSID)(*pbuffer +
801 sizeof(USER_MODALS_INFO_2));
802 umi->usrmod2_domain_name = (LPWSTR)(*pbuffer +
803 sizeof(USER_MODALS_INFO_2) + GetLengthSid(domainIdentifier));
805 lstrcpynW(umi->usrmod2_domain_name,
806 domainInfo->DomainName.Buffer,
807 domainNameLen);
808 CopySid(GetLengthSid(domainIdentifier), umi->usrmod2_domain_id,
809 domainIdentifier);
811 LsaFreeMemory(domainInfo);
813 break;
815 case 3:
816 /* return lockout information */
817 FIXME("level 3 not implemented!\n");
818 *pbuffer = NULL;
819 return NERR_InternalError;
820 default:
821 TRACE("Invalid level %d is specified\n", level);
822 *pbuffer = NULL;
823 return ERROR_INVALID_LEVEL;
826 return NERR_Success;
829 /******************************************************************************
830 * NetUserChangePassword (NETAPI32.@)
831 * PARAMS
832 * domainname [I] Optional. Domain on which the user resides or the logon
833 * domain of the current user if NULL.
834 * username [I] Optional. Username to change the password for or the name
835 * of the current user if NULL.
836 * oldpassword [I] The user's current password.
837 * newpassword [I] The password that the user will be changed to using.
839 * RETURNS
840 * Success: NERR_Success.
841 * Failure: NERR_* failure code or win error code.
844 NET_API_STATUS WINAPI NetUserChangePassword(LPCWSTR domainname, LPCWSTR username,
845 LPCWSTR oldpassword, LPCWSTR newpassword)
847 struct sam_user *user;
849 TRACE("(%s, %s, ..., ...)\n", debugstr_w(domainname), debugstr_w(username));
851 if(domainname)
852 FIXME("Ignoring domainname %s.\n", debugstr_w(domainname));
854 if((user = NETAPI_FindUser(username)) == NULL)
855 return NERR_UserNotFound;
857 if(lstrcmpW(user->user_password, oldpassword) != 0)
858 return ERROR_INVALID_PASSWORD;
860 if(lstrlenW(newpassword) > PWLEN)
861 return ERROR_PASSWORD_RESTRICTION;
863 lstrcpyW(user->user_password, newpassword);
865 return NERR_Success;
868 NET_API_STATUS WINAPI NetUseAdd(LMSTR servername, DWORD level, LPBYTE bufptr, LPDWORD parm_err)
870 FIXME("%s %d %p %p stub\n", debugstr_w(servername), level, bufptr, parm_err);
871 return NERR_Success;