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
24 #define WIN32_NO_STATUS
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.
51 WCHAR user_name
[LM20_UNLEN
+1];
52 WCHAR user_password
[PWLEN
+ 1];
53 DWORD sec_since_passwd_change
;
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
)
74 if (ServerName
[0] == 0)
75 return ERROR_BAD_NETPATH
;
77 ((ServerName
[0] == '\\') &&
78 (ServerName
[1] != '\\'))
80 ((ServerName
[0] == '\\') &&
81 (ServerName
[1] == '\\') &&
84 return ERROR_INVALID_NAME
;
89 /************************************************************
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)
108 static BOOL
NETAPI_IsCurrentUser(LPCWSTR username
)
110 LPWSTR curr_user
= NULL
;
114 dwSize
= LM20_UNLEN
+1;
115 curr_user
= HeapAlloc(GetProcessHeap(), 0, dwSize
* sizeof(WCHAR
));
118 ERR("Failed to allocate memory for user name.\n");
121 if(!GetUserNameW(curr_user
, &dwSize
))
123 ERR("Failed to get current user's user name.\n");
126 if (!lstrcmpW(curr_user
, username
))
132 HeapFree(GetProcessHeap(), 0, curr_user
);
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
)
152 /* Level 3 and 4 are identical for the purposes of NetUserAdd */
155 FIXME("Level 3 and 4 not implemented.\n");
158 FIXME("Level 2 not implemented.\n");
162 PUSER_INFO_1 ui
= (PUSER_INFO_1
) bufptr
;
163 su
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct sam_user
));
166 status
= NERR_InternalError
;
170 if(lstrlenW(ui
->usri1_name
) > LM20_UNLEN
)
172 status
= NERR_BadUsername
;
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
;
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 */
193 su
->user_comment
= NULL
;
194 su
->user_logon_script_path
= NULL
;
196 list_add_head(&user_list
, &su
->entry
);
200 TRACE("Invalid level %d specified.\n", level
);
201 status
= ERROR_INVALID_LEVEL
;
205 HeapFree(GetProcessHeap(), 0, su
);
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
)
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
);
236 /************************************************************
237 * NetUserGetInfo (NETAPI32.@)
239 NET_API_STATUS WINAPI
240 NetUserGetInfo(LPCWSTR servername
, LPCWSTR username
, DWORD level
,
243 NET_API_STATUS status
;
244 TRACE("(%s, %s, %d, %p)\n", debugstr_w(servername
), debugstr_w(username
),
246 status
= NETAPI_ValidateServername(servername
);
247 if (status
!= NERR_Success
)
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
;
270 name_sz
= lstrlenW(username
) + 1;
273 NetApiBufferAllocate(sizeof(USER_INFO_0
) + name_sz
* sizeof(WCHAR
),
276 ui
= (PUSER_INFO_0
) *bufptr
;
277 ui
->usri0_name
= (LPWSTR
) (*bufptr
+ sizeof(USER_INFO_0
));
280 lstrcpyW(ui
->usri0_name
, username
);
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
;
297 status
= NetUserGetInfo(servername
, username
, 0, (LPBYTE
*) &ui0
);
298 if (status
!= NERR_Success
)
300 NetApiBufferFree(ui0
);
303 name_sz
= lstrlenW(ui0
->usri0_name
) + 1;
306 NetApiBufferAllocate(sizeof(USER_INFO_10
) +
307 (name_sz
+ comment_sz
+ usr_comment_sz
+
308 full_name_sz
) * sizeof(WCHAR
),
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
));
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;
330 static const WCHAR homedirW
[] = {'H','O','M','E',0};
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*/
342 status
= NetUserGetInfo(servername
, username
, 0, (LPBYTE
*) &ui0
);
343 if (status
!= NERR_Success
)
345 NetApiBufferFree(ui0
);
348 name_sz
= lstrlenW(ui0
->usri0_name
) + 1;
349 home_dir_sz
= GetEnvironmentVariableW(homedirW
, NULL
,0);
351 NetApiBufferAllocate(sizeof(USER_INFO_1
) +
352 (name_sz
+ password_sz
+ home_dir_sz
+
353 comment_sz
+ script_path_sz
) * sizeof(WCHAR
),
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
;
363 lstrcpyW(ui
->usri1_name
, ui0
->usri0_name
);
364 NetApiBufferFree(ui0
);
365 ui
->usri1_password
[0] = 0;
366 ui
->usri1_password_age
= 0;
368 GetEnvironmentVariableW(homedirW
, ui
->usri1_home_dir
,home_dir_sz
);
369 ui
->usri1_comment
[0] = 0;
371 ui
->usri1_script_path
[0] = 0;
401 FIXME("Level %d is not implemented\n", level
);
402 return NERR_InternalError
;
405 TRACE("Invalid level %d is specified\n", level
);
406 return ERROR_INVALID_LEVEL
;
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
;
420 const WCHAR admins
[] = {'A','d','m','i','n','i','s','t','r','a','t','o','r','s',0};
422 LOCALGROUP_USERS_INFO_0
* info
;
425 FIXME("(%s, %s, %d, %08x, %p %d, %p, %p) stub!\n",
426 debugstr_w(servername
), debugstr_w(username
), level
, flags
, bufptr
,
427 prefmaxlen
, entriesread
, totalentries
);
429 status
= NETAPI_ValidateServername(servername
);
430 if (status
!= NERR_Success
)
434 NetApiBufferAllocate(size
* sizeof(WCHAR
), (LPVOID
*)¤tuser
);
435 GetUserNameW(currentuser
, &size
);
437 if (lstrcmpiW(username
, currentuser
) && NETAPI_FindUser(username
))
439 NetApiBufferFree(currentuser
);
440 return NERR_UserNotFound
;
443 NetApiBufferFree(currentuser
);
445 size
= sizeof(*info
) + sizeof(admins
);
447 if(prefmaxlen
< size
)
448 status
= ERROR_MORE_DATA
;
450 status
= NetApiBufferAllocate(size
, (LPVOID
*)&info
);
452 if(status
!= NERR_Success
)
459 info
->lgrui0_name
= (LPWSTR
)((LPBYTE
)info
+ sizeof(*info
));
460 lstrcpyW(info
->lgrui0_name
, admins
);
462 *bufptr
= (LPBYTE
)info
;
468 /************************************************************
469 * NetUserEnum (NETAPI32.@)
471 NET_API_STATUS WINAPI
472 NetUserEnum(LPCWSTR servername
, DWORD level
, DWORD filter
, LPBYTE
* bufptr
,
473 DWORD prefmaxlen
, LPDWORD entriesread
, LPDWORD totalentries
,
474 LPDWORD resume_handle
)
476 FIXME("(%s,%d, 0x%d,%p,%d,%p,%p,%p) stub!\n", debugstr_w(servername
), level
,
477 filter
, bufptr
, prefmaxlen
, entriesread
, totalentries
, resume_handle
);
479 return ERROR_ACCESS_DENIED
;
482 /************************************************************
483 * ACCESS_QueryAdminDisplayInformation
485 * Creates a buffer with information for the Admin User
487 static void ACCESS_QueryAdminDisplayInformation(PNET_DISPLAY_USER
*buf
, PDWORD pdwSize
)
489 static const WCHAR sAdminUserName
[] = {
490 'A','d','m','i','n','i','s','t','r','a','t','o','r',0};
492 /* sizes of the field buffers in WCHARS */
493 int name_sz
, comment_sz
, full_name_sz
;
494 PNET_DISPLAY_USER usr
;
497 name_sz
= lstrlenW(sAdminUserName
) + 1;
501 *pdwSize
= sizeof(NET_DISPLAY_USER
);
502 *pdwSize
+= (name_sz
+ comment_sz
+ full_name_sz
) * sizeof(WCHAR
);
503 NetApiBufferAllocate(*pdwSize
, (LPVOID
*) buf
);
506 usr
->usri1_name
= (LPWSTR
) ((PBYTE
) usr
+ sizeof(NET_DISPLAY_USER
));
507 usr
->usri1_comment
= (LPWSTR
) (
508 ((PBYTE
) usr
->usri1_name
) + name_sz
* sizeof(WCHAR
));
509 usr
->usri1_full_name
= (LPWSTR
) (
510 ((PBYTE
) usr
->usri1_comment
) + comment_sz
* sizeof(WCHAR
));
513 lstrcpyW(usr
->usri1_name
, sAdminUserName
);
514 usr
->usri1_comment
[0] = 0;
515 usr
->usri1_flags
= UF_SCRIPT
| UF_NORMAL_ACCOUNT
| UF_DONT_EXPIRE_PASSWD
;
516 usr
->usri1_full_name
[0] = 0;
517 usr
->usri1_user_id
= DOMAIN_USER_RID_ADMIN
;
518 usr
->usri1_next_index
= 0;
521 /************************************************************
522 * ACCESS_QueryGuestDisplayInformation
524 * Creates a buffer with information for the Guest User
526 static void ACCESS_QueryGuestDisplayInformation(PNET_DISPLAY_USER
*buf
, PDWORD pdwSize
)
528 static const WCHAR sGuestUserName
[] = {
529 'G','u','e','s','t',0 };
531 /* sizes of the field buffers in WCHARS */
532 int name_sz
, comment_sz
, full_name_sz
;
533 PNET_DISPLAY_USER usr
;
536 name_sz
= lstrlenW(sGuestUserName
) + 1;
540 *pdwSize
= sizeof(NET_DISPLAY_USER
);
541 *pdwSize
+= (name_sz
+ comment_sz
+ full_name_sz
) * sizeof(WCHAR
);
542 NetApiBufferAllocate(*pdwSize
, (LPVOID
*) buf
);
545 usr
->usri1_name
= (LPWSTR
) ((PBYTE
) usr
+ sizeof(NET_DISPLAY_USER
));
546 usr
->usri1_comment
= (LPWSTR
) (
547 ((PBYTE
) usr
->usri1_name
) + name_sz
* sizeof(WCHAR
));
548 usr
->usri1_full_name
= (LPWSTR
) (
549 ((PBYTE
) usr
->usri1_comment
) + comment_sz
* sizeof(WCHAR
));
552 lstrcpyW(usr
->usri1_name
, sGuestUserName
);
553 usr
->usri1_comment
[0] = 0;
554 usr
->usri1_flags
= UF_ACCOUNTDISABLE
| UF_SCRIPT
| UF_NORMAL_ACCOUNT
|
555 UF_DONT_EXPIRE_PASSWD
;
556 usr
->usri1_full_name
[0] = 0;
557 usr
->usri1_user_id
= DOMAIN_USER_RID_GUEST
;
558 usr
->usri1_next_index
= 0;
561 /************************************************************
562 * Copies NET_DISPLAY_USER record.
564 static void ACCESS_CopyDisplayUser(const NET_DISPLAY_USER
*dest
, LPWSTR
*dest_buf
,
565 PNET_DISPLAY_USER src
)
567 LPWSTR str
= *dest_buf
;
569 src
->usri1_name
= str
;
570 lstrcpyW(src
->usri1_name
, dest
->usri1_name
);
572 ((PBYTE
) str
) + (lstrlenW(str
) + 1) * sizeof(WCHAR
));
574 src
->usri1_comment
= str
;
575 lstrcpyW(src
->usri1_comment
, dest
->usri1_comment
);
577 ((PBYTE
) str
) + (lstrlenW(str
) + 1) * sizeof(WCHAR
));
579 src
->usri1_flags
= dest
->usri1_flags
;
581 src
->usri1_full_name
= str
;
582 lstrcpyW(src
->usri1_full_name
, dest
->usri1_full_name
);
584 ((PBYTE
) str
) + (lstrlenW(str
) + 1) * sizeof(WCHAR
));
586 src
->usri1_user_id
= dest
->usri1_user_id
;
587 src
->usri1_next_index
= dest
->usri1_next_index
;
591 /************************************************************
592 * NetQueryDisplayInformation (NETAPI32.@)
594 * The buffer structure:
595 * - array of fixed size record of the level type
596 * - strings, referenced by the record of the level type
598 NET_API_STATUS WINAPI
599 NetQueryDisplayInformation(
600 LPCWSTR ServerName
, DWORD Level
, DWORD Index
, DWORD EntriesRequested
,
601 DWORD PreferredMaximumLength
, LPDWORD ReturnedEntryCount
,
604 TRACE("(%s, %d, %d, %d, %d, %p, %p)\n", debugstr_w(ServerName
),
605 Level
, Index
, EntriesRequested
, PreferredMaximumLength
,
606 ReturnedEntryCount
, SortedBuffer
);
608 if(!NETAPI_IsLocalComputer(ServerName
))
610 FIXME("Only implemented on local computer, but requested for "
611 "remote server %s\n", debugstr_w(ServerName
));
612 return ERROR_ACCESS_DENIED
;
620 PNET_DISPLAY_USER inf
;
621 /* current available strings buffer */
623 PNET_DISPLAY_USER admin
, guest
;
624 DWORD admin_size
, guest_size
;
628 /* sizes of the field buffers in WCHARS */
629 int name_sz
, comment_sz
, full_name_sz
;
631 /* number of the records, returned in SortedBuffer
632 3 - for current user, Administrator and Guest users
636 FIXME("Level %d partially implemented\n", Level
);
637 *ReturnedEntryCount
= records
;
643 NetApiBufferAllocate(dwSize
* sizeof(WCHAR
), (LPVOID
*) &name
);
644 if (!GetUserNameW(name
, &dwSize
))
646 NetApiBufferFree(name
);
647 return ERROR_ACCESS_DENIED
;
650 ACCESS_QueryAdminDisplayInformation(&admin
, &admin_size
);
651 ACCESS_QueryGuestDisplayInformation(&guest
, &guest_size
);
654 dwSize
= sizeof(NET_DISPLAY_USER
) * records
;
655 dwSize
+= (name_sz
+ comment_sz
+ full_name_sz
) * sizeof(WCHAR
);
657 NetApiBufferAllocate(dwSize
+
658 admin_size
- sizeof(NET_DISPLAY_USER
) +
659 guest_size
- sizeof(NET_DISPLAY_USER
),
662 str
= (LPWSTR
) ((PBYTE
) inf
+ sizeof(NET_DISPLAY_USER
) * records
);
663 inf
->usri1_name
= str
;
665 ((PBYTE
) str
) + name_sz
* sizeof(WCHAR
));
666 inf
->usri1_comment
= str
;
668 ((PBYTE
) str
) + comment_sz
* sizeof(WCHAR
));
669 inf
->usri1_full_name
= str
;
671 ((PBYTE
) str
) + full_name_sz
* sizeof(WCHAR
));
674 lstrcpyW(inf
->usri1_name
, name
);
675 NetApiBufferFree(name
);
676 inf
->usri1_comment
[0] = 0;
678 UF_SCRIPT
| UF_NORMAL_ACCOUNT
| UF_DONT_EXPIRE_PASSWD
;
679 inf
->usri1_full_name
[0] = 0;
680 inf
->usri1_user_id
= 0;
681 inf
->usri1_next_index
= 0;
684 ACCESS_CopyDisplayUser(admin
, &str
, inf
);
685 NetApiBufferFree(admin
);
688 ACCESS_CopyDisplayUser(guest
, &str
, inf
);
689 NetApiBufferFree(guest
);
696 FIXME("Level %d is not implemented\n", Level
);
701 TRACE("Invalid level %d is specified\n", Level
);
702 return ERROR_INVALID_LEVEL
;
707 /************************************************************
708 * NetGetDCName (NETAPI32.@)
710 * Return the name of the primary domain controller (PDC)
713 NET_API_STATUS WINAPI
714 NetGetDCName(LPCWSTR servername
, LPCWSTR domainname
, LPBYTE
*bufptr
)
716 FIXME("(%s, %s, %p) stub!\n", debugstr_w(servername
),
717 debugstr_w(domainname
), bufptr
);
718 return NERR_DCNotFound
; /* say we can't find a domain controller */
721 /************************************************************
722 * NetGroupEnum (NETAPI32.@)
725 NET_API_STATUS WINAPI
726 NetGroupEnum(LPCWSTR servername
, DWORD level
, LPBYTE
*bufptr
, DWORD prefmaxlen
,
727 LPDWORD entriesread
, LPDWORD totalentries
, LPDWORD resume_handle
)
729 FIXME("(%s, %d, %p, %d, %p, %p, %p) stub!\n", debugstr_w(servername
),
730 level
, bufptr
, prefmaxlen
, entriesread
, totalentries
, resume_handle
);
731 return ERROR_ACCESS_DENIED
;
734 /************************************************************
735 * NetGroupGetInfo (NETAPI32.@)
738 NET_API_STATUS WINAPI
NetGroupGetInfo(LPCWSTR servername
, LPCWSTR groupname
, DWORD level
, LPBYTE
*bufptr
)
740 FIXME("(%s, %s, %d, %p) stub!\n", debugstr_w(servername
), debugstr_w(groupname
), level
, bufptr
);
741 return ERROR_ACCESS_DENIED
;
744 /******************************************************************************
745 * NetUserModalsGet (NETAPI32.@)
747 * Retrieves global information for all users and global groups in the security
751 * szServer [I] Specifies the DNS or the NetBIOS name of the remote server
752 * on which the function is to execute.
753 * level [I] Information level of the data.
754 * 0 Return global passwords parameters. bufptr points to a
755 * USER_MODALS_INFO_0 struct.
756 * 1 Return logon server and domain controller information. bufptr
757 * points to a USER_MODALS_INFO_1 struct.
758 * 2 Return domain name and identifier. bufptr points to a
759 * USER_MODALS_INFO_2 struct.
760 * 3 Return lockout information. bufptr points to a USER_MODALS_INFO_3
762 * pbuffer [I] Buffer that receives the data.
765 * Success: NERR_Success.
767 * ERROR_ACCESS_DENIED - the user does not have access to the info.
768 * NERR_InvalidComputer - computer name is invalid.
770 NET_API_STATUS WINAPI
NetUserModalsGet(
771 LPCWSTR szServer
, DWORD level
, LPBYTE
*pbuffer
)
773 TRACE("(%s %d %p)\n", debugstr_w(szServer
), level
, pbuffer
);
778 /* return global passwords parameters */
779 FIXME("level 0 not implemented!\n");
781 return NERR_InternalError
;
783 /* return logon server and domain controller info */
784 FIXME("level 1 not implemented!\n");
786 return NERR_InternalError
;
789 /* return domain name and identifier */
790 PUSER_MODALS_INFO_2 umi
;
791 LSA_HANDLE policyHandle
;
792 LSA_OBJECT_ATTRIBUTES objectAttributes
;
793 PPOLICY_ACCOUNT_DOMAIN_INFO domainInfo
;
795 PSID domainIdentifier
= NULL
;
798 ZeroMemory(&objectAttributes
, sizeof(objectAttributes
));
799 objectAttributes
.Length
= sizeof(objectAttributes
);
801 ntStatus
= LsaOpenPolicy(NULL
, &objectAttributes
,
802 POLICY_VIEW_LOCAL_INFORMATION
,
804 if (ntStatus
!= STATUS_SUCCESS
)
806 WARN("LsaOpenPolicy failed with NT status %x\n",
807 LsaNtStatusToWinError(ntStatus
));
811 ntStatus
= LsaQueryInformationPolicy(policyHandle
,
812 PolicyAccountDomainInformation
,
813 (PVOID
*)&domainInfo
);
814 if (ntStatus
!= STATUS_SUCCESS
)
816 WARN("LsaQueryInformationPolicy failed with NT status %x\n",
817 LsaNtStatusToWinError(ntStatus
));
818 LsaClose(policyHandle
);
822 domainIdentifier
= domainInfo
->DomainSid
;
823 domainNameLen
= lstrlenW(domainInfo
->DomainName
.Buffer
) + 1;
824 LsaClose(policyHandle
);
826 ntStatus
= NetApiBufferAllocate(sizeof(USER_MODALS_INFO_2
) +
827 GetLengthSid(domainIdentifier
) +
828 domainNameLen
* sizeof(WCHAR
),
831 if (ntStatus
!= NERR_Success
)
833 WARN("NetApiBufferAllocate() failed\n");
834 LsaFreeMemory(domainInfo
);
838 umi
= (USER_MODALS_INFO_2
*) *pbuffer
;
839 umi
->usrmod2_domain_id
= *pbuffer
+ sizeof(USER_MODALS_INFO_2
);
840 umi
->usrmod2_domain_name
= (LPWSTR
)(*pbuffer
+
841 sizeof(USER_MODALS_INFO_2
) + GetLengthSid(domainIdentifier
));
843 lstrcpynW(umi
->usrmod2_domain_name
,
844 domainInfo
->DomainName
.Buffer
,
846 CopySid(GetLengthSid(domainIdentifier
), umi
->usrmod2_domain_id
,
849 LsaFreeMemory(domainInfo
);
854 /* return lockout information */
855 FIXME("level 3 not implemented!\n");
857 return NERR_InternalError
;
859 TRACE("Invalid level %d is specified\n", level
);
861 return ERROR_INVALID_LEVEL
;
867 /******************************************************************************
868 * NetUserChangePassword (NETAPI32.@)
870 * domainname [I] Optional. Domain on which the user resides or the logon
871 * domain of the current user if NULL.
872 * username [I] Optional. Username to change the password for or the name
873 * of the current user if NULL.
874 * oldpassword [I] The user's current password.
875 * newpassword [I] The password that the user will be changed to using.
878 * Success: NERR_Success.
879 * Failure: NERR_* failure code or win error code.
882 NET_API_STATUS WINAPI
NetUserChangePassword(LPCWSTR domainname
, LPCWSTR username
,
883 LPCWSTR oldpassword
, LPCWSTR newpassword
)
885 struct sam_user
*user
;
887 TRACE("(%s, %s, ..., ...)\n", debugstr_w(domainname
), debugstr_w(username
));
890 FIXME("Ignoring domainname %s.\n", debugstr_w(domainname
));
892 if((user
= NETAPI_FindUser(username
)) == NULL
)
893 return NERR_UserNotFound
;
895 if(lstrcmpW(user
->user_password
, oldpassword
) != 0)
896 return ERROR_INVALID_PASSWORD
;
898 if(lstrlenW(newpassword
) > PWLEN
)
899 return ERROR_PASSWORD_RESTRICTION
;
901 lstrcpyW(user
->user_password
, newpassword
);
906 NET_API_STATUS WINAPI
NetUseAdd(LMSTR servername
, DWORD level
, LPBYTE bufptr
, LPDWORD parm_err
)
908 FIXME("%s %d %p %p stub\n", debugstr_w(servername
), level
, bufptr
, parm_err
);