netapi32: Remove unneeded cast.
[wine.git] / dlls / netapi32 / access.c
blobf79323918f6e3e3918ce436b92d4d126a8da2e5c
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 /************************************************************
109 * NetUserAdd (NETAPI32.@)
111 NET_API_STATUS WINAPI NetUserAdd(LPCWSTR servername,
112 DWORD level, LPBYTE bufptr, LPDWORD parm_err)
114 NET_API_STATUS status;
115 struct sam_user * su = NULL;
117 FIXME("(%s, %d, %p, %p) stub!\n", debugstr_w(servername), level, bufptr, parm_err);
119 if((status = NETAPI_ValidateServername(servername)) != NERR_Success)
120 return status;
122 switch(level)
124 /* Level 3 and 4 are identical for the purposes of NetUserAdd */
125 case 4:
126 case 3:
127 FIXME("Level 3 and 4 not implemented.\n");
128 /* Fall through */
129 case 2:
130 FIXME("Level 2 not implemented.\n");
131 /* Fall through */
132 case 1:
134 PUSER_INFO_1 ui = (PUSER_INFO_1) bufptr;
135 su = HeapAlloc(GetProcessHeap(), 0, sizeof(struct sam_user));
136 if(!su)
138 status = NERR_InternalError;
139 break;
142 if(lstrlenW(ui->usri1_name) > LM20_UNLEN)
144 status = NERR_BadUsername;
145 break;
148 /*FIXME: do other checks for a valid username */
149 lstrcpyW(su->user_name, ui->usri1_name);
151 if(lstrlenW(ui->usri1_password) > PWLEN)
153 /* Always return PasswordTooShort on invalid passwords. */
154 status = NERR_PasswordTooShort;
155 break;
157 lstrcpyW(su->user_password, ui->usri1_password);
159 su->sec_since_passwd_change = ui->usri1_password_age;
160 su->user_priv = ui->usri1_priv;
161 su->user_flags = ui->usri1_flags;
163 /*FIXME: set the other LPWSTRs to NULL for now */
164 su->home_dir = NULL;
165 su->user_comment = NULL;
166 su->user_logon_script_path = NULL;
168 list_add_head(&user_list, &su->entry);
169 return NERR_Success;
171 default:
172 TRACE("Invalid level %d specified.\n", level);
173 status = ERROR_INVALID_LEVEL;
174 break;
177 HeapFree(GetProcessHeap(), 0, su);
179 return status;
182 /************************************************************
183 * NetUserDel (NETAPI32.@)
185 NET_API_STATUS WINAPI NetUserDel(LPCWSTR servername, LPCWSTR username)
187 NET_API_STATUS status;
188 struct sam_user *user;
190 TRACE("(%s, %s)\n", debugstr_w(servername), debugstr_w(username));
192 if((status = NETAPI_ValidateServername(servername))!= NERR_Success)
193 return status;
195 if ((user = NETAPI_FindUser(username)) == NULL)
196 return NERR_UserNotFound;
198 list_remove(&user->entry);
200 HeapFree(GetProcessHeap(), 0, user->home_dir);
201 HeapFree(GetProcessHeap(), 0, user->user_comment);
202 HeapFree(GetProcessHeap(), 0, user->user_logon_script_path);
203 HeapFree(GetProcessHeap(), 0, user);
205 return NERR_Success;
208 /************************************************************
209 * NetUserGetInfo (NETAPI32.@)
211 NET_API_STATUS WINAPI
212 NetUserGetInfo(LPCWSTR servername, LPCWSTR username, DWORD level,
213 LPBYTE* bufptr)
215 NET_API_STATUS status;
216 TRACE("(%s, %s, %d, %p)\n", debugstr_w(servername), debugstr_w(username),
217 level, bufptr);
218 status = NETAPI_ValidateServername(servername);
219 if (status != NERR_Success)
220 return status;
222 if(!NETAPI_IsLocalComputer(servername))
224 FIXME("Only implemented for local computer, but remote server"
225 "%s was requested.\n", debugstr_w(servername));
226 return NERR_InvalidComputer;
229 if(!NETAPI_FindUser(username))
231 TRACE("User %s is unknown.\n", debugstr_w(username));
232 return NERR_UserNotFound;
235 switch (level)
237 case 0:
239 PUSER_INFO_0 ui;
240 int name_sz;
242 name_sz = lstrlenW(username) + 1;
244 /* set up buffer */
245 NetApiBufferAllocate(sizeof(USER_INFO_0) + name_sz * sizeof(WCHAR),
246 (LPVOID *) bufptr);
248 ui = (PUSER_INFO_0) *bufptr;
249 ui->usri0_name = (LPWSTR) (*bufptr + sizeof(USER_INFO_0));
251 /* get data */
252 lstrcpyW(ui->usri0_name, username);
253 break;
256 case 10:
258 PUSER_INFO_10 ui;
259 PUSER_INFO_0 ui0;
260 NET_API_STATUS status;
261 /* sizes of the field buffers in WCHARS */
262 int name_sz, comment_sz, usr_comment_sz, full_name_sz;
264 comment_sz = 1;
265 usr_comment_sz = 1;
266 full_name_sz = 1;
268 /* get data */
269 status = NetUserGetInfo(servername, username, 0, (LPBYTE *) &ui0);
270 if (status != NERR_Success)
272 NetApiBufferFree(ui0);
273 return status;
275 name_sz = lstrlenW(ui0->usri0_name) + 1;
277 /* set up buffer */
278 NetApiBufferAllocate(sizeof(USER_INFO_10) +
279 (name_sz + comment_sz + usr_comment_sz +
280 full_name_sz) * sizeof(WCHAR),
281 (LPVOID *) bufptr);
282 ui = (PUSER_INFO_10) *bufptr;
283 ui->usri10_name = (LPWSTR) (*bufptr + sizeof(USER_INFO_10));
284 ui->usri10_comment = (LPWSTR) (
285 ((PBYTE) ui->usri10_name) + name_sz * sizeof(WCHAR));
286 ui->usri10_usr_comment = (LPWSTR) (
287 ((PBYTE) ui->usri10_comment) + comment_sz * sizeof(WCHAR));
288 ui->usri10_full_name = (LPWSTR) (
289 ((PBYTE) ui->usri10_usr_comment) + usr_comment_sz * sizeof(WCHAR));
291 /* set data */
292 lstrcpyW(ui->usri10_name, ui0->usri0_name);
293 NetApiBufferFree(ui0);
294 ui->usri10_comment[0] = 0;
295 ui->usri10_usr_comment[0] = 0;
296 ui->usri10_full_name[0] = 0;
297 break;
300 case 1:
302 static const WCHAR homedirW[] = {'H','O','M','E',0};
303 PUSER_INFO_1 ui;
304 PUSER_INFO_0 ui0;
305 NET_API_STATUS status;
306 /* sizes of the field buffers in WCHARS */
307 int name_sz, password_sz, home_dir_sz, comment_sz, script_path_sz;
309 password_sz = 1; /* not filled out for security reasons for NetUserGetInfo*/
310 comment_sz = 1;
311 script_path_sz = 1;
313 /* get data */
314 status = NetUserGetInfo(servername, username, 0, (LPBYTE *) &ui0);
315 if (status != NERR_Success)
317 NetApiBufferFree(ui0);
318 return status;
320 name_sz = lstrlenW(ui0->usri0_name) + 1;
321 home_dir_sz = GetEnvironmentVariableW(homedirW, NULL,0);
322 /* set up buffer */
323 NetApiBufferAllocate(sizeof(USER_INFO_1) +
324 (name_sz + password_sz + home_dir_sz +
325 comment_sz + script_path_sz) * sizeof(WCHAR),
326 (LPVOID *) bufptr);
328 ui = (PUSER_INFO_1) *bufptr;
329 ui->usri1_name = (LPWSTR) (ui + 1);
330 ui->usri1_password = ui->usri1_name + name_sz;
331 ui->usri1_home_dir = ui->usri1_password + password_sz;
332 ui->usri1_comment = ui->usri1_home_dir + home_dir_sz;
333 ui->usri1_script_path = ui->usri1_comment + comment_sz;
334 /* set data */
335 lstrcpyW(ui->usri1_name, ui0->usri0_name);
336 NetApiBufferFree(ui0);
337 ui->usri1_password[0] = 0;
338 ui->usri1_password_age = 0;
339 ui->usri1_priv = 0;
340 GetEnvironmentVariableW(homedirW, ui->usri1_home_dir,home_dir_sz);
341 ui->usri1_comment[0] = 0;
342 ui->usri1_flags = 0;
343 ui->usri1_script_path[0] = 0;
344 break;
346 case 2:
347 case 3:
348 case 4:
349 case 11:
350 case 20:
351 case 23:
352 case 1003:
353 case 1005:
354 case 1006:
355 case 1007:
356 case 1008:
357 case 1009:
358 case 1010:
359 case 1011:
360 case 1012:
361 case 1013:
362 case 1014:
363 case 1017:
364 case 1018:
365 case 1020:
366 case 1023:
367 case 1024:
368 case 1025:
369 case 1051:
370 case 1052:
371 case 1053:
373 FIXME("Level %d is not implemented\n", level);
374 return NERR_InternalError;
376 default:
377 TRACE("Invalid level %d is specified\n", level);
378 return ERROR_INVALID_LEVEL;
380 return NERR_Success;
383 /************************************************************
384 * NetUserGetLocalGroups (NETAPI32.@)
386 NET_API_STATUS WINAPI
387 NetUserGetLocalGroups(LPCWSTR servername, LPCWSTR username, DWORD level,
388 DWORD flags, LPBYTE* bufptr, DWORD prefmaxlen,
389 LPDWORD entriesread, LPDWORD totalentries)
391 NET_API_STATUS status;
393 FIXME("(%s, %s, %d, %08x, %p %d, %p, %p) stub!\n",
394 debugstr_w(servername), debugstr_w(username), level, flags, bufptr,
395 prefmaxlen, entriesread, totalentries);
397 status = NETAPI_ValidateServername(servername);
398 if (status != NERR_Success)
399 return status;
401 if (!NETAPI_FindUser(username))
402 return NERR_UserNotFound;
404 if (bufptr) *bufptr = NULL;
405 if (entriesread) *entriesread = 0;
406 if (totalentries) *totalentries = 0;
408 return NERR_Success;
411 /************************************************************
412 * NetUserEnum (NETAPI32.@)
414 NET_API_STATUS WINAPI
415 NetUserEnum(LPCWSTR servername, DWORD level, DWORD filter, LPBYTE* bufptr,
416 DWORD prefmaxlen, LPDWORD entriesread, LPDWORD totalentries,
417 LPDWORD resume_handle)
419 FIXME("(%s,%d, 0x%d,%p,%d,%p,%p,%p) stub!\n", debugstr_w(servername), level,
420 filter, bufptr, prefmaxlen, entriesread, totalentries, resume_handle);
422 return ERROR_ACCESS_DENIED;
425 /************************************************************
426 * ACCESS_QueryAdminDisplayInformation
428 * Creates a buffer with information for the Admin User
430 static void ACCESS_QueryAdminDisplayInformation(PNET_DISPLAY_USER *buf, PDWORD pdwSize)
432 static const WCHAR sAdminUserName[] = {
433 'A','d','m','i','n','i','s','t','r','a','t','o','r',0};
435 /* sizes of the field buffers in WCHARS */
436 int name_sz, comment_sz, full_name_sz;
437 PNET_DISPLAY_USER usr;
439 /* set up buffer */
440 name_sz = lstrlenW(sAdminUserName);
441 comment_sz = 1;
442 full_name_sz = 1;
444 *pdwSize = sizeof(NET_DISPLAY_USER);
445 *pdwSize += (name_sz + comment_sz + full_name_sz) * sizeof(WCHAR);
446 NetApiBufferAllocate(*pdwSize, (LPVOID *) buf);
448 usr = *buf;
449 usr->usri1_name = (LPWSTR) ((PBYTE) usr + sizeof(NET_DISPLAY_USER));
450 usr->usri1_comment = (LPWSTR) (
451 ((PBYTE) usr->usri1_name) + name_sz * sizeof(WCHAR));
452 usr->usri1_full_name = (LPWSTR) (
453 ((PBYTE) usr->usri1_comment) + comment_sz * sizeof(WCHAR));
455 /* set data */
456 lstrcpyW(usr->usri1_name, sAdminUserName);
457 usr->usri1_comment[0] = 0;
458 usr->usri1_flags = UF_SCRIPT | UF_NORMAL_ACCOUNT | UF_DONT_EXPIRE_PASSWD;
459 usr->usri1_full_name[0] = 0;
460 usr->usri1_user_id = 500;
461 usr->usri1_next_index = 0;
464 /************************************************************
465 * ACCESS_QueryGuestDisplayInformation
467 * Creates a buffer with information for the Guest User
469 static void ACCESS_QueryGuestDisplayInformation(PNET_DISPLAY_USER *buf, PDWORD pdwSize)
471 static const WCHAR sGuestUserName[] = {
472 'G','u','e','s','t',0 };
474 /* sizes of the field buffers in WCHARS */
475 int name_sz, comment_sz, full_name_sz;
476 PNET_DISPLAY_USER usr;
478 /* set up buffer */
479 name_sz = lstrlenW(sGuestUserName);
480 comment_sz = 1;
481 full_name_sz = 1;
483 *pdwSize = sizeof(NET_DISPLAY_USER);
484 *pdwSize += (name_sz + comment_sz + full_name_sz) * sizeof(WCHAR);
485 NetApiBufferAllocate(*pdwSize, (LPVOID *) buf);
487 usr = *buf;
488 usr->usri1_name = (LPWSTR) ((PBYTE) usr + sizeof(NET_DISPLAY_USER));
489 usr->usri1_comment = (LPWSTR) (
490 ((PBYTE) usr->usri1_name) + name_sz * sizeof(WCHAR));
491 usr->usri1_full_name = (LPWSTR) (
492 ((PBYTE) usr->usri1_comment) + comment_sz * sizeof(WCHAR));
494 /* set data */
495 lstrcpyW(usr->usri1_name, sGuestUserName);
496 usr->usri1_comment[0] = 0;
497 usr->usri1_flags = UF_ACCOUNTDISABLE | UF_SCRIPT | UF_NORMAL_ACCOUNT |
498 UF_DONT_EXPIRE_PASSWD;
499 usr->usri1_full_name[0] = 0;
500 usr->usri1_user_id = 500;
501 usr->usri1_next_index = 0;
504 /************************************************************
505 * Copies NET_DISPLAY_USER record.
507 static void ACCESS_CopyDisplayUser(const NET_DISPLAY_USER *dest, LPWSTR *dest_buf,
508 PNET_DISPLAY_USER src)
510 LPWSTR str = *dest_buf;
512 src->usri1_name = str;
513 lstrcpyW(src->usri1_name, dest->usri1_name);
514 str = (LPWSTR) (
515 ((PBYTE) str) + (lstrlenW(str) + 1) * sizeof(WCHAR));
517 src->usri1_comment = str;
518 lstrcpyW(src->usri1_comment, dest->usri1_comment);
519 str = (LPWSTR) (
520 ((PBYTE) str) + (lstrlenW(str) + 1) * sizeof(WCHAR));
522 src->usri1_flags = dest->usri1_flags;
524 src->usri1_full_name = str;
525 lstrcpyW(src->usri1_full_name, dest->usri1_full_name);
526 str = (LPWSTR) (
527 ((PBYTE) str) + (lstrlenW(str) + 1) * sizeof(WCHAR));
529 src->usri1_user_id = dest->usri1_user_id;
530 src->usri1_next_index = dest->usri1_next_index;
531 *dest_buf = str;
534 /************************************************************
535 * NetQueryDisplayInformation (NETAPI32.@)
537 * The buffer structure:
538 * - array of fixed size record of the level type
539 * - strings, referenced by the record of the level type
541 NET_API_STATUS WINAPI
542 NetQueryDisplayInformation(
543 LPCWSTR ServerName, DWORD Level, DWORD Index, DWORD EntriesRequested,
544 DWORD PreferredMaximumLength, LPDWORD ReturnedEntryCount,
545 PVOID *SortedBuffer)
547 TRACE("(%s, %d, %d, %d, %d, %p, %p)\n", debugstr_w(ServerName),
548 Level, Index, EntriesRequested, PreferredMaximumLength,
549 ReturnedEntryCount, SortedBuffer);
551 if(!NETAPI_IsLocalComputer(ServerName))
553 FIXME("Only implemented on local computer, but requested for "
554 "remote server %s\n", debugstr_w(ServerName));
555 return ERROR_ACCESS_DENIED;
558 switch (Level)
560 case 1:
562 /* current record */
563 PNET_DISPLAY_USER inf;
564 /* current available strings buffer */
565 LPWSTR str;
566 PNET_DISPLAY_USER admin, guest;
567 DWORD admin_size, guest_size;
568 LPWSTR name = NULL;
569 DWORD dwSize;
571 /* sizes of the field buffers in WCHARS */
572 int name_sz, comment_sz, full_name_sz;
574 /* number of the records, returned in SortedBuffer
575 3 - for current user, Administrator and Guest users
577 int records = 3;
579 FIXME("Level %d partially implemented\n", Level);
580 *ReturnedEntryCount = records;
581 comment_sz = 1;
582 full_name_sz = 1;
584 /* get data */
585 dwSize = UNLEN + 1;
586 NetApiBufferAllocate(dwSize, (LPVOID *) &name);
587 if (!GetUserNameW(name, &dwSize))
589 NetApiBufferFree(name);
590 return ERROR_ACCESS_DENIED;
592 name_sz = dwSize;
593 ACCESS_QueryAdminDisplayInformation(&admin, &admin_size);
594 ACCESS_QueryGuestDisplayInformation(&guest, &guest_size);
596 /* set up buffer */
597 dwSize = sizeof(NET_DISPLAY_USER) * records;
598 dwSize += (name_sz + comment_sz + full_name_sz) * sizeof(WCHAR);
600 NetApiBufferAllocate(dwSize +
601 admin_size - sizeof(NET_DISPLAY_USER) +
602 guest_size - sizeof(NET_DISPLAY_USER),
603 SortedBuffer);
604 inf = (PNET_DISPLAY_USER) *SortedBuffer;
605 str = (LPWSTR) ((PBYTE) inf + sizeof(NET_DISPLAY_USER) * records);
606 inf->usri1_name = str;
607 str = (LPWSTR) (
608 ((PBYTE) str) + name_sz * sizeof(WCHAR));
609 inf->usri1_comment = str;
610 str = (LPWSTR) (
611 ((PBYTE) str) + comment_sz * sizeof(WCHAR));
612 inf->usri1_full_name = str;
613 str = (LPWSTR) (
614 ((PBYTE) str) + full_name_sz * sizeof(WCHAR));
616 /* set data */
617 lstrcpyW(inf->usri1_name, name);
618 NetApiBufferFree(name);
619 inf->usri1_comment[0] = 0;
620 inf->usri1_flags =
621 UF_SCRIPT | UF_NORMAL_ACCOUNT | UF_DONT_EXPIRE_PASSWD;
622 inf->usri1_full_name[0] = 0;
623 inf->usri1_user_id = 0;
624 inf->usri1_next_index = 0;
626 inf++;
627 ACCESS_CopyDisplayUser(admin, &str, inf);
628 NetApiBufferFree(admin);
630 inf++;
631 ACCESS_CopyDisplayUser(guest, &str, inf);
632 NetApiBufferFree(guest);
633 break;
636 case 2:
637 case 3:
639 FIXME("Level %d is not implemented\n", Level);
640 break;
643 default:
644 TRACE("Invalid level %d is specified\n", Level);
645 return ERROR_INVALID_LEVEL;
647 return NERR_Success;
650 /************************************************************
651 * NetGetDCName (NETAPI32.@)
653 * Return the name of the primary domain controller (PDC)
656 NET_API_STATUS WINAPI
657 NetGetDCName(LPCWSTR servername, LPCWSTR domainname, LPBYTE *bufptr)
659 FIXME("(%s, %s, %p) stub!\n", debugstr_w(servername),
660 debugstr_w(domainname), bufptr);
661 return NERR_DCNotFound; /* say we can't find a domain controller */
665 /******************************************************************************
666 * NetUserModalsGet (NETAPI32.@)
668 * Retrieves global information for all users and global groups in the security
669 * database.
671 * PARAMS
672 * szServer [I] Specifies the DNS or the NetBIOS name of the remote server
673 * on which the function is to execute.
674 * level [I] Information level of the data.
675 * 0 Return global passwords parameters. bufptr points to a
676 * USER_MODALS_INFO_0 struct.
677 * 1 Return logon server and domain controller information. bufptr
678 * points to a USER_MODALS_INFO_1 struct.
679 * 2 Return domain name and identifier. bufptr points to a
680 * USER_MODALS_INFO_2 struct.
681 * 3 Return lockout information. bufptr points to a USER_MODALS_INFO_3
682 * struct.
683 * pbuffer [I] Buffer that receives the data.
685 * RETURNS
686 * Success: NERR_Success.
687 * Failure:
688 * ERROR_ACCESS_DENIED - the user does not have access to the info.
689 * NERR_InvalidComputer - computer name is invalid.
691 NET_API_STATUS WINAPI NetUserModalsGet(
692 LPCWSTR szServer, DWORD level, LPBYTE *pbuffer)
694 TRACE("(%s %d %p)\n", debugstr_w(szServer), level, pbuffer);
696 switch (level)
698 case 0:
699 /* return global passwords parameters */
700 FIXME("level 0 not implemented!\n");
701 *pbuffer = NULL;
702 return NERR_InternalError;
703 case 1:
704 /* return logon server and domain controller info */
705 FIXME("level 1 not implemented!\n");
706 *pbuffer = NULL;
707 return NERR_InternalError;
708 case 2:
710 /* return domain name and identifier */
711 PUSER_MODALS_INFO_2 umi;
712 LSA_HANDLE policyHandle;
713 LSA_OBJECT_ATTRIBUTES objectAttributes;
714 PPOLICY_ACCOUNT_DOMAIN_INFO domainInfo;
715 NTSTATUS ntStatus;
716 PSID domainIdentifier = NULL;
717 int domainNameLen;
719 ZeroMemory(&objectAttributes, sizeof(objectAttributes));
720 objectAttributes.Length = sizeof(objectAttributes);
722 ntStatus = LsaOpenPolicy(NULL, &objectAttributes,
723 POLICY_VIEW_LOCAL_INFORMATION,
724 &policyHandle);
725 if (ntStatus != STATUS_SUCCESS)
727 WARN("LsaOpenPolicy failed with NT status %x\n",
728 LsaNtStatusToWinError(ntStatus));
729 return ntStatus;
732 ntStatus = LsaQueryInformationPolicy(policyHandle,
733 PolicyAccountDomainInformation,
734 (PVOID *)&domainInfo);
735 if (ntStatus != STATUS_SUCCESS)
737 WARN("LsaQueryInformationPolicy failed with NT status %x\n",
738 LsaNtStatusToWinError(ntStatus));
739 LsaClose(policyHandle);
740 return ntStatus;
743 domainIdentifier = domainInfo->DomainSid;
744 domainNameLen = lstrlenW(domainInfo->DomainName.Buffer) + 1;
745 LsaClose(policyHandle);
747 ntStatus = NetApiBufferAllocate(sizeof(USER_MODALS_INFO_2) +
748 GetLengthSid(domainIdentifier) +
749 domainNameLen * sizeof(WCHAR),
750 (LPVOID *)pbuffer);
752 if (ntStatus != NERR_Success)
754 WARN("NetApiBufferAllocate() failed\n");
755 LsaFreeMemory(domainInfo);
756 return ntStatus;
759 umi = (USER_MODALS_INFO_2 *) *pbuffer;
760 umi->usrmod2_domain_id = (PSID)(*pbuffer +
761 sizeof(USER_MODALS_INFO_2));
762 umi->usrmod2_domain_name = (LPWSTR)(*pbuffer +
763 sizeof(USER_MODALS_INFO_2) + GetLengthSid(domainIdentifier));
765 lstrcpynW(umi->usrmod2_domain_name,
766 domainInfo->DomainName.Buffer,
767 domainNameLen);
768 CopySid(GetLengthSid(domainIdentifier), umi->usrmod2_domain_id,
769 domainIdentifier);
771 LsaFreeMemory(domainInfo);
773 break;
775 case 3:
776 /* return lockout information */
777 FIXME("level 3 not implemented!\n");
778 *pbuffer = NULL;
779 return NERR_InternalError;
780 default:
781 TRACE("Invalid level %d is specified\n", level);
782 *pbuffer = NULL;
783 return ERROR_INVALID_LEVEL;
786 return NERR_Success;
789 /******************************************************************************
790 * NetUserChangePassword (NETAPI32.@)
791 * PARAMS
792 * domainname [I] Optional. Domain on which the user resides or the logon
793 * domain of the current user if NULL.
794 * username [I] Optional. Username to change the password for or the name
795 * of the current user if NULL.
796 * oldpassword [I] The user's current password.
797 * newpassword [I] The password that the user will be changed to using.
799 * RETURNS
800 * Success: NERR_Success.
801 * Failure: NERR_* failure code or win error code.
804 NET_API_STATUS WINAPI NetUserChangePassword(LPCWSTR domainname, LPCWSTR username,
805 LPCWSTR oldpassword, LPCWSTR newpassword)
807 struct sam_user *user;
809 TRACE("(%s, %s, ..., ...)\n", debugstr_w(domainname), debugstr_w(username));
811 if(domainname)
812 FIXME("Ignoring domainname %s.\n", debugstr_w(domainname));
814 if((user = NETAPI_FindUser(username)) == NULL)
815 return NERR_UserNotFound;
817 if(lstrcmpW(user->user_password, oldpassword) != 0)
818 return ERROR_INVALID_PASSWORD;
820 if(lstrlenW(newpassword) > PWLEN)
821 return ERROR_PASSWORD_RESTRICTION;
823 lstrcpyW(user->user_password, newpassword);
825 return NERR_Success;
828 NET_API_STATUS WINAPI NetUseAdd(LMSTR servername, DWORD level, LPBYTE bufptr, LPDWORD parm_err)
830 FIXME("%s %d %p %p stub\n", debugstr_w(servername), level, bufptr, parm_err);
831 return NERR_Success;