include: Synchronize DEVMODE layout with PSDK.
[wine/gsoc_dplay.git] / dlls / netapi32 / access.c
blob40b448de6e25fb3704a2ded6a7066786ae8da0bd
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 const WCHAR sAdminUserName[] = {'A','d','m','i','n','i','s','t','r','a','t',
62 'o','r',0};
63 static const WCHAR sGuestUserName[] = {'G','u','e','s','t',0};
65 static struct list user_list = LIST_INIT( user_list );
67 BOOL NETAPI_IsLocalComputer(LPCWSTR ServerName);
69 /************************************************************
70 * NETAPI_ValidateServername
72 * Validates server name
74 static NET_API_STATUS NETAPI_ValidateServername(LPCWSTR ServerName)
76 if (ServerName)
78 if (ServerName[0] == 0)
79 return ERROR_BAD_NETPATH;
80 else if (
81 ((ServerName[0] == '\\') &&
82 (ServerName[1] != '\\'))
84 ((ServerName[0] == '\\') &&
85 (ServerName[1] == '\\') &&
86 (ServerName[2] == 0))
88 return ERROR_INVALID_NAME;
90 return NERR_Success;
93 /************************************************************
94 * NETAPI_FindUser
96 * Looks for a user in the user database.
97 * Returns a pointer to the entry in the user list when the user
98 * is found, NULL otherwise.
100 static struct sam_user* NETAPI_FindUser(LPCWSTR UserName)
102 struct sam_user *user;
104 LIST_FOR_EACH_ENTRY(user, &user_list, struct sam_user, entry)
106 if(lstrcmpW(user->user_name, UserName) == 0)
107 return user;
109 return NULL;
112 /************************************************************
113 * NetUserAdd (NETAPI32.@)
115 NET_API_STATUS WINAPI NetUserAdd(LPCWSTR servername,
116 DWORD level, LPBYTE bufptr, LPDWORD parm_err)
118 NET_API_STATUS status;
119 struct sam_user * su = NULL;
121 FIXME("(%s, %d, %p, %p) stub!\n", debugstr_w(servername), level, bufptr, parm_err);
123 if((status = NETAPI_ValidateServername(servername)) != NERR_Success)
124 return status;
126 switch(level)
128 /* Level 3 and 4 are identical for the purposes of NetUserAdd */
129 case 4:
130 case 3:
131 FIXME("Level 3 and 4 not implemented.\n");
132 /* Fall through */
133 case 2:
134 FIXME("Level 2 not implemented.\n");
135 /* Fall through */
136 case 1:
138 PUSER_INFO_1 ui = (PUSER_INFO_1) bufptr;
139 su = HeapAlloc(GetProcessHeap(), 0, sizeof(struct sam_user));
140 if(!su)
142 status = NERR_InternalError;
143 break;
146 if(lstrlenW(ui->usri1_name) > LM20_UNLEN)
148 status = NERR_BadUsername;
149 break;
152 /*FIXME: do other checks for a valid username */
153 lstrcpyW(su->user_name, ui->usri1_name);
155 if(lstrlenW(ui->usri1_password) > PWLEN)
157 /* Always return PasswordTooShort on invalid passwords. */
158 status = NERR_PasswordTooShort;
159 break;
161 lstrcpyW(su->user_password, ui->usri1_password);
163 su->sec_since_passwd_change = ui->usri1_password_age;
164 su->user_priv = ui->usri1_priv;
165 su->user_flags = ui->usri1_flags;
167 /*FIXME: set the other LPWSTRs to NULL for now */
168 su->home_dir = NULL;
169 su->user_comment = NULL;
170 su->user_logon_script_path = NULL;
172 list_add_head(&user_list, &su->entry);
173 return NERR_Success;
175 default:
176 TRACE("Invalid level %d specified.\n", level);
177 status = ERROR_INVALID_LEVEL;
178 break;
181 if(su)
183 HeapFree(GetProcessHeap(), 0, su->home_dir);
184 HeapFree(GetProcessHeap(), 0, su->user_comment);
185 HeapFree(GetProcessHeap(), 0, su->user_logon_script_path);
186 HeapFree(GetProcessHeap(), 0, su);
188 return status;
191 /************************************************************
192 * NetUserDel (NETAPI32.@)
194 NET_API_STATUS WINAPI NetUserDel(LPCWSTR servername, LPCWSTR username)
196 NET_API_STATUS status;
197 struct sam_user *user;
199 TRACE("(%s, %s)\n", debugstr_w(servername), debugstr_w(username));
201 if((status = NETAPI_ValidateServername(servername))!= NERR_Success)
202 return status;
204 if ((user = NETAPI_FindUser(username)) == NULL)
205 return NERR_UserNotFound;
207 list_remove(&user->entry);
209 HeapFree(GetProcessHeap(), 0, user->home_dir);
210 HeapFree(GetProcessHeap(), 0, user->user_comment);
211 HeapFree(GetProcessHeap(), 0, user->user_logon_script_path);
212 HeapFree(GetProcessHeap(), 0, user);
214 return NERR_Success;
217 /************************************************************
218 * NetUserGetInfo (NETAPI32.@)
220 NET_API_STATUS WINAPI
221 NetUserGetInfo(LPCWSTR servername, LPCWSTR username, DWORD level,
222 LPBYTE* bufptr)
224 NET_API_STATUS status;
225 TRACE("(%s, %s, %d, %p)\n", debugstr_w(servername), debugstr_w(username),
226 level, bufptr);
227 status = NETAPI_ValidateServername(servername);
228 if (status != NERR_Success)
229 return status;
231 if(!NETAPI_IsLocalComputer(servername))
233 FIXME("Only implemented for local computer, but remote server"
234 "%s was requested.\n", debugstr_w(servername));
235 return NERR_InvalidComputer;
238 if(!NETAPI_FindUser(username))
240 TRACE("User %s is unknown.\n", debugstr_w(username));
241 return NERR_UserNotFound;
244 switch (level)
246 case 0:
248 PUSER_INFO_0 ui;
249 int name_sz;
251 name_sz = lstrlenW(username) + 1;
253 /* set up buffer */
254 NetApiBufferAllocate(sizeof(USER_INFO_0) + name_sz * sizeof(WCHAR),
255 (LPVOID *) bufptr);
257 ui = (PUSER_INFO_0) *bufptr;
258 ui->usri0_name = (LPWSTR) (*bufptr + sizeof(USER_INFO_0));
260 /* get data */
261 lstrcpyW(ui->usri0_name, username);
262 break;
265 case 10:
267 PUSER_INFO_10 ui;
268 PUSER_INFO_0 ui0;
269 NET_API_STATUS status;
270 /* sizes of the field buffers in WCHARS */
271 int name_sz, comment_sz, usr_comment_sz, full_name_sz;
273 comment_sz = 1;
274 usr_comment_sz = 1;
275 full_name_sz = 1;
277 /* get data */
278 status = NetUserGetInfo(servername, username, 0, (LPBYTE *) &ui0);
279 if (status != NERR_Success)
281 NetApiBufferFree(ui0);
282 return status;
284 name_sz = lstrlenW(ui0->usri0_name) + 1;
286 /* set up buffer */
287 NetApiBufferAllocate(sizeof(USER_INFO_10) +
288 (name_sz + comment_sz + usr_comment_sz +
289 full_name_sz) * sizeof(WCHAR),
290 (LPVOID *) bufptr);
291 ui = (PUSER_INFO_10) *bufptr;
292 ui->usri10_name = (LPWSTR) (*bufptr + sizeof(USER_INFO_10));
293 ui->usri10_comment = (LPWSTR) (
294 ((PBYTE) ui->usri10_name) + name_sz * sizeof(WCHAR));
295 ui->usri10_usr_comment = (LPWSTR) (
296 ((PBYTE) ui->usri10_comment) + comment_sz * sizeof(WCHAR));
297 ui->usri10_full_name = (LPWSTR) (
298 ((PBYTE) ui->usri10_usr_comment) + usr_comment_sz * sizeof(WCHAR));
300 /* set data */
301 lstrcpyW(ui->usri10_name, ui0->usri0_name);
302 NetApiBufferFree(ui0);
303 ui->usri10_comment[0] = 0;
304 ui->usri10_usr_comment[0] = 0;
305 ui->usri10_full_name[0] = 0;
306 break;
309 case 1:
311 static const WCHAR homedirW[] = {'H','O','M','E',0};
312 PUSER_INFO_1 ui;
313 PUSER_INFO_0 ui0;
314 NET_API_STATUS status;
315 /* sizes of the field buffers in WCHARS */
316 int name_sz, password_sz, home_dir_sz, comment_sz, script_path_sz;
318 password_sz = 1; /* not filled out for security reasons for NetUserGetInfo*/
319 comment_sz = 1;
320 script_path_sz = 1;
322 /* get data */
323 status = NetUserGetInfo(servername, username, 0, (LPBYTE *) &ui0);
324 if (status != NERR_Success)
326 NetApiBufferFree(ui0);
327 return status;
329 name_sz = lstrlenW(ui0->usri0_name) + 1;
330 home_dir_sz = GetEnvironmentVariableW(homedirW, NULL,0);
331 /* set up buffer */
332 NetApiBufferAllocate(sizeof(USER_INFO_1) +
333 (name_sz + password_sz + home_dir_sz +
334 comment_sz + script_path_sz) * sizeof(WCHAR),
335 (LPVOID *) bufptr);
337 ui = (PUSER_INFO_1) *bufptr;
338 ui->usri1_name = (LPWSTR) (ui + 1);
339 ui->usri1_password = ui->usri1_name + name_sz;
340 ui->usri1_home_dir = ui->usri1_password + password_sz;
341 ui->usri1_comment = ui->usri1_home_dir + home_dir_sz;
342 ui->usri1_script_path = ui->usri1_comment + comment_sz;
343 /* set data */
344 lstrcpyW(ui->usri1_name, ui0->usri0_name);
345 NetApiBufferFree(ui0);
346 ui->usri1_password[0] = 0;
347 ui->usri1_password_age = 0;
348 ui->usri1_priv = 0;
349 GetEnvironmentVariableW(homedirW, ui->usri1_home_dir,home_dir_sz);
350 ui->usri1_comment[0] = 0;
351 ui->usri1_flags = 0;
352 ui->usri1_script_path[0] = 0;
353 break;
355 case 2:
356 case 3:
357 case 4:
358 case 11:
359 case 20:
360 case 23:
361 case 1003:
362 case 1005:
363 case 1006:
364 case 1007:
365 case 1008:
366 case 1009:
367 case 1010:
368 case 1011:
369 case 1012:
370 case 1013:
371 case 1014:
372 case 1017:
373 case 1018:
374 case 1020:
375 case 1023:
376 case 1024:
377 case 1025:
378 case 1051:
379 case 1052:
380 case 1053:
382 FIXME("Level %d is not implemented\n", level);
383 return NERR_InternalError;
385 default:
386 TRACE("Invalid level %d is specified\n", level);
387 return ERROR_INVALID_LEVEL;
389 return NERR_Success;
392 /************************************************************
393 * NetUserGetLocalGroups (NETAPI32.@)
395 NET_API_STATUS WINAPI
396 NetUserGetLocalGroups(LPCWSTR servername, LPCWSTR username, DWORD level,
397 DWORD flags, LPBYTE* bufptr, DWORD prefmaxlen,
398 LPDWORD entriesread, LPDWORD totalentries)
400 NET_API_STATUS status;
402 FIXME("(%s, %s, %d, %08x, %p %d, %p, %p) stub!\n",
403 debugstr_w(servername), debugstr_w(username), level, flags, bufptr,
404 prefmaxlen, entriesread, totalentries);
406 status = NETAPI_ValidateServername(servername);
407 if (status != NERR_Success)
408 return status;
410 if (!NETAPI_FindUser(username))
411 return NERR_UserNotFound;
413 if (bufptr) *bufptr = NULL;
414 if (entriesread) *entriesread = 0;
415 if (totalentries) *totalentries = 0;
417 return NERR_Success;
420 /************************************************************
421 * NetUserEnum (NETAPI32.@)
423 NET_API_STATUS WINAPI
424 NetUserEnum(LPCWSTR servername, DWORD level, DWORD filter, LPBYTE* bufptr,
425 DWORD prefmaxlen, LPDWORD entriesread, LPDWORD totalentries,
426 LPDWORD resume_handle)
428 FIXME("(%s,%d, 0x%d,%p,%d,%p,%p,%p) stub!\n", debugstr_w(servername), level,
429 filter, bufptr, prefmaxlen, entriesread, totalentries, resume_handle);
431 return ERROR_ACCESS_DENIED;
434 /************************************************************
435 * ACCESS_QueryAdminDisplayInformation
437 * Creates a buffer with information for the Admin User
439 static void ACCESS_QueryAdminDisplayInformation(PNET_DISPLAY_USER *buf, PDWORD pdwSize)
441 static const WCHAR sAdminUserName[] = {
442 'A','d','m','i','n','i','s','t','r','a','t','o','r',0};
444 /* sizes of the field buffers in WCHARS */
445 int name_sz, comment_sz, full_name_sz;
446 PNET_DISPLAY_USER usr;
448 /* set up buffer */
449 name_sz = lstrlenW(sAdminUserName);
450 comment_sz = 1;
451 full_name_sz = 1;
453 *pdwSize = sizeof(NET_DISPLAY_USER);
454 *pdwSize += (name_sz + comment_sz + full_name_sz) * sizeof(WCHAR);
455 NetApiBufferAllocate(*pdwSize, (LPVOID *) buf);
457 usr = *buf;
458 usr->usri1_name = (LPWSTR) ((PBYTE) usr + sizeof(NET_DISPLAY_USER));
459 usr->usri1_comment = (LPWSTR) (
460 ((PBYTE) usr->usri1_name) + name_sz * sizeof(WCHAR));
461 usr->usri1_full_name = (LPWSTR) (
462 ((PBYTE) usr->usri1_comment) + comment_sz * sizeof(WCHAR));
464 /* set data */
465 lstrcpyW(usr->usri1_name, sAdminUserName);
466 usr->usri1_comment[0] = 0;
467 usr->usri1_flags = UF_SCRIPT | UF_NORMAL_ACCOUNT | UF_DONT_EXPIRE_PASSWD;
468 usr->usri1_full_name[0] = 0;
469 usr->usri1_user_id = 500;
470 usr->usri1_next_index = 0;
473 /************************************************************
474 * ACCESS_QueryGuestDisplayInformation
476 * Creates a buffer with information for the Guest User
478 static void ACCESS_QueryGuestDisplayInformation(PNET_DISPLAY_USER *buf, PDWORD pdwSize)
480 static const WCHAR sGuestUserName[] = {
481 'G','u','e','s','t',0 };
483 /* sizes of the field buffers in WCHARS */
484 int name_sz, comment_sz, full_name_sz;
485 PNET_DISPLAY_USER usr;
487 /* set up buffer */
488 name_sz = lstrlenW(sGuestUserName);
489 comment_sz = 1;
490 full_name_sz = 1;
492 *pdwSize = sizeof(NET_DISPLAY_USER);
493 *pdwSize += (name_sz + comment_sz + full_name_sz) * sizeof(WCHAR);
494 NetApiBufferAllocate(*pdwSize, (LPVOID *) buf);
496 usr = *buf;
497 usr->usri1_name = (LPWSTR) ((PBYTE) usr + sizeof(NET_DISPLAY_USER));
498 usr->usri1_comment = (LPWSTR) (
499 ((PBYTE) usr->usri1_name) + name_sz * sizeof(WCHAR));
500 usr->usri1_full_name = (LPWSTR) (
501 ((PBYTE) usr->usri1_comment) + comment_sz * sizeof(WCHAR));
503 /* set data */
504 lstrcpyW(usr->usri1_name, sGuestUserName);
505 usr->usri1_comment[0] = 0;
506 usr->usri1_flags = UF_ACCOUNTDISABLE | UF_SCRIPT | UF_NORMAL_ACCOUNT |
507 UF_DONT_EXPIRE_PASSWD;
508 usr->usri1_full_name[0] = 0;
509 usr->usri1_user_id = 500;
510 usr->usri1_next_index = 0;
513 /************************************************************
514 * Copies NET_DISPLAY_USER record.
516 static void ACCESS_CopyDisplayUser(const NET_DISPLAY_USER *dest, LPWSTR *dest_buf,
517 PNET_DISPLAY_USER src)
519 LPWSTR str = *dest_buf;
521 src->usri1_name = str;
522 lstrcpyW(src->usri1_name, dest->usri1_name);
523 str = (LPWSTR) (
524 ((PBYTE) str) + (lstrlenW(str) + 1) * sizeof(WCHAR));
526 src->usri1_comment = str;
527 lstrcpyW(src->usri1_comment, dest->usri1_comment);
528 str = (LPWSTR) (
529 ((PBYTE) str) + (lstrlenW(str) + 1) * sizeof(WCHAR));
531 src->usri1_flags = dest->usri1_flags;
533 src->usri1_full_name = str;
534 lstrcpyW(src->usri1_full_name, dest->usri1_full_name);
535 str = (LPWSTR) (
536 ((PBYTE) str) + (lstrlenW(str) + 1) * sizeof(WCHAR));
538 src->usri1_user_id = dest->usri1_user_id;
539 src->usri1_next_index = dest->usri1_next_index;
540 *dest_buf = str;
543 /************************************************************
544 * NetQueryDisplayInformation (NETAPI32.@)
546 * The buffer structure:
547 * - array of fixed size record of the level type
548 * - strings, referenced by the record of the level type
550 NET_API_STATUS WINAPI
551 NetQueryDisplayInformation(
552 LPCWSTR ServerName, DWORD Level, DWORD Index, DWORD EntriesRequested,
553 DWORD PreferredMaximumLength, LPDWORD ReturnedEntryCount,
554 PVOID *SortedBuffer)
556 TRACE("(%s, %d, %d, %d, %d, %p, %p)\n", debugstr_w(ServerName),
557 Level, Index, EntriesRequested, PreferredMaximumLength,
558 ReturnedEntryCount, SortedBuffer);
560 if(!NETAPI_IsLocalComputer(ServerName))
562 FIXME("Only implemented on local computer, but requested for "
563 "remote server %s\n", debugstr_w(ServerName));
564 return ERROR_ACCESS_DENIED;
567 switch (Level)
569 case 1:
571 /* current record */
572 PNET_DISPLAY_USER inf;
573 /* current available strings buffer */
574 LPWSTR str;
575 PNET_DISPLAY_USER admin, guest;
576 DWORD admin_size, guest_size;
577 LPWSTR name = NULL;
578 DWORD dwSize;
580 /* sizes of the field buffers in WCHARS */
581 int name_sz, comment_sz, full_name_sz;
583 /* number of the records, returned in SortedBuffer
584 3 - for current user, Administrator and Guest users
586 int records = 3;
588 FIXME("Level %d partially implemented\n", Level);
589 *ReturnedEntryCount = records;
590 comment_sz = 1;
591 full_name_sz = 1;
593 /* get data */
594 dwSize = UNLEN + 1;
595 NetApiBufferAllocate(dwSize, (LPVOID *) &name);
596 if (!GetUserNameW(name, &dwSize))
598 NetApiBufferFree(name);
599 return ERROR_ACCESS_DENIED;
601 name_sz = dwSize;
602 ACCESS_QueryAdminDisplayInformation(&admin, &admin_size);
603 ACCESS_QueryGuestDisplayInformation(&guest, &guest_size);
605 /* set up buffer */
606 dwSize = sizeof(NET_DISPLAY_USER) * records;
607 dwSize += (name_sz + comment_sz + full_name_sz) * sizeof(WCHAR);
609 NetApiBufferAllocate(dwSize +
610 admin_size - sizeof(NET_DISPLAY_USER) +
611 guest_size - sizeof(NET_DISPLAY_USER),
612 (LPVOID *) SortedBuffer);
613 inf = (PNET_DISPLAY_USER) *SortedBuffer;
614 str = (LPWSTR) ((PBYTE) inf + sizeof(NET_DISPLAY_USER) * records);
615 inf->usri1_name = str;
616 str = (LPWSTR) (
617 ((PBYTE) str) + name_sz * sizeof(WCHAR));
618 inf->usri1_comment = str;
619 str = (LPWSTR) (
620 ((PBYTE) str) + comment_sz * sizeof(WCHAR));
621 inf->usri1_full_name = str;
622 str = (LPWSTR) (
623 ((PBYTE) str) + full_name_sz * sizeof(WCHAR));
625 /* set data */
626 lstrcpyW(inf->usri1_name, name);
627 NetApiBufferFree(name);
628 inf->usri1_comment[0] = 0;
629 inf->usri1_flags =
630 UF_SCRIPT | UF_NORMAL_ACCOUNT | UF_DONT_EXPIRE_PASSWD;
631 inf->usri1_full_name[0] = 0;
632 inf->usri1_user_id = 0;
633 inf->usri1_next_index = 0;
635 inf++;
636 ACCESS_CopyDisplayUser(admin, &str, inf);
637 NetApiBufferFree(admin);
639 inf++;
640 ACCESS_CopyDisplayUser(guest, &str, inf);
641 NetApiBufferFree(guest);
642 break;
645 case 2:
646 case 3:
648 FIXME("Level %d is not implemented\n", Level);
649 break;
652 default:
653 TRACE("Invalid level %d is specified\n", Level);
654 return ERROR_INVALID_LEVEL;
656 return NERR_Success;
659 /************************************************************
660 * NetGetDCName (NETAPI32.@)
662 * Return the name of the primary domain controller (PDC)
665 NET_API_STATUS WINAPI
666 NetGetDCName(LPCWSTR servername, LPCWSTR domainname, LPBYTE *bufptr)
668 FIXME("(%s, %s, %p) stub!\n", debugstr_w(servername),
669 debugstr_w(domainname), bufptr);
670 return NERR_DCNotFound; /* say we can't find a domain controller */
674 /******************************************************************************
675 * NetUserModalsGet (NETAPI32.@)
677 * Retrieves global information for all users and global groups in the security
678 * database.
680 * PARAMS
681 * szServer [I] Specifies the DNS or the NetBIOS name of the remote server
682 * on which the function is to execute.
683 * level [I] Information level of the data.
684 * 0 Return global passwords parameters. bufptr points to a
685 * USER_MODALS_INFO_0 struct.
686 * 1 Return logon server and domain controller information. bufptr
687 * points to a USER_MODALS_INFO_1 struct.
688 * 2 Return domain name and identifier. bufptr points to a
689 * USER_MODALS_INFO_2 struct.
690 * 3 Return lockout information. bufptr points to a USER_MODALS_INFO_3
691 * struct.
692 * pbuffer [I] Buffer that receives the data.
694 * RETURNS
695 * Success: NERR_Success.
696 * Failure:
697 * ERROR_ACCESS_DENIED - the user does not have access to the info.
698 * NERR_InvalidComputer - computer name is invalid.
700 NET_API_STATUS WINAPI NetUserModalsGet(
701 LPCWSTR szServer, DWORD level, LPBYTE *pbuffer)
703 TRACE("(%s %d %p)\n", debugstr_w(szServer), level, pbuffer);
705 switch (level)
707 case 0:
708 /* return global passwords parameters */
709 FIXME("level 0 not implemented!\n");
710 *pbuffer = NULL;
711 return NERR_InternalError;
712 case 1:
713 /* return logon server and domain controller info */
714 FIXME("level 1 not implemented!\n");
715 *pbuffer = NULL;
716 return NERR_InternalError;
717 case 2:
719 /* return domain name and identifier */
720 PUSER_MODALS_INFO_2 umi;
721 LSA_HANDLE policyHandle;
722 LSA_OBJECT_ATTRIBUTES objectAttributes;
723 PPOLICY_ACCOUNT_DOMAIN_INFO domainInfo;
724 NTSTATUS ntStatus;
725 PSID domainIdentifier = NULL;
726 int domainNameLen;
728 ZeroMemory(&objectAttributes, sizeof(objectAttributes));
729 objectAttributes.Length = sizeof(objectAttributes);
731 ntStatus = LsaOpenPolicy(NULL, &objectAttributes,
732 POLICY_VIEW_LOCAL_INFORMATION,
733 &policyHandle);
734 if (ntStatus != STATUS_SUCCESS)
736 WARN("LsaOpenPolicy failed with NT status %x\n",
737 LsaNtStatusToWinError(ntStatus));
738 return ntStatus;
741 ntStatus = LsaQueryInformationPolicy(policyHandle,
742 PolicyAccountDomainInformation,
743 (PVOID *)&domainInfo);
744 if (ntStatus != STATUS_SUCCESS)
746 WARN("LsaQueryInformationPolicy failed with NT status %x\n",
747 LsaNtStatusToWinError(ntStatus));
748 LsaClose(policyHandle);
749 return ntStatus;
752 domainIdentifier = domainInfo->DomainSid;
753 domainNameLen = lstrlenW(domainInfo->DomainName.Buffer) + 1;
754 LsaClose(policyHandle);
756 ntStatus = NetApiBufferAllocate(sizeof(USER_MODALS_INFO_2) +
757 GetLengthSid(domainIdentifier) +
758 domainNameLen * sizeof(WCHAR),
759 (LPVOID *)pbuffer);
761 if (ntStatus != NERR_Success)
763 WARN("NetApiBufferAllocate() failed\n");
764 LsaFreeMemory(domainInfo);
765 return ntStatus;
768 umi = (USER_MODALS_INFO_2 *) *pbuffer;
769 umi->usrmod2_domain_id = (PSID)(*pbuffer +
770 sizeof(USER_MODALS_INFO_2));
771 umi->usrmod2_domain_name = (LPWSTR)(*pbuffer +
772 sizeof(USER_MODALS_INFO_2) + GetLengthSid(domainIdentifier));
774 lstrcpynW(umi->usrmod2_domain_name,
775 domainInfo->DomainName.Buffer,
776 domainNameLen);
777 CopySid(GetLengthSid(domainIdentifier), umi->usrmod2_domain_id,
778 domainIdentifier);
780 LsaFreeMemory(domainInfo);
782 break;
784 case 3:
785 /* return lockout information */
786 FIXME("level 3 not implemented!\n");
787 *pbuffer = NULL;
788 return NERR_InternalError;
789 default:
790 TRACE("Invalid level %d is specified\n", level);
791 *pbuffer = NULL;
792 return ERROR_INVALID_LEVEL;
795 return NERR_Success;
798 /******************************************************************************
799 * NetUserChangePassword (NETAPI32.@)
800 * PARAMS
801 * domainname [I] Optional. Domain on which the user resides or the logon
802 * domain of the current user if NULL.
803 * username [I] Optional. Username to change the password for or the name
804 * of the current user if NULL.
805 * oldpassword [I] The user's current password.
806 * newpassword [I] The password that the user will be changed to using.
808 * RETURNS
809 * Success: NERR_Success.
810 * Failure: NERR_* failure code or win error code.
813 NET_API_STATUS WINAPI NetUserChangePassword(LPCWSTR domainname, LPCWSTR username,
814 LPCWSTR oldpassword, LPCWSTR newpassword)
816 struct sam_user *user;
818 TRACE("(%s, %s, ..., ...)\n", debugstr_w(domainname), debugstr_w(username));
820 if(domainname)
821 FIXME("Ignoring domainname %s.\n", debugstr_w(domainname));
823 if((user = NETAPI_FindUser(username)) == NULL)
824 return NERR_UserNotFound;
826 if(lstrcmpW(user->user_password, oldpassword) != 0)
827 return ERROR_INVALID_PASSWORD;
829 if(lstrlenW(newpassword) > PWLEN)
830 return ERROR_PASSWORD_RESTRICTION;
832 lstrcpyW(user->user_password, newpassword);
834 return NERR_Success;
837 NET_API_STATUS WINAPI NetUseAdd(LMSTR servername, DWORD level, LPBYTE bufptr, LPDWORD parm_err)
839 FIXME("%s %d %p %p stub\n", debugstr_w(servername), level, bufptr, parm_err);
840 return NERR_Success;