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
25 #ifdef HAVE_SYS_WAIT_H
33 #define WIN32_NO_STATUS
43 #include "wine/debug.h"
44 #include "wine/unicode.h"
45 #include "wine/list.h"
47 WINE_DEFAULT_DEBUG_CHANNEL(netapi32
);
49 /* NOTE: So far, this is implemented to support tests that require user logins,
50 * but not designed to handle real user databases. Those should probably
51 * be synced with either the host's user database or with Samba.
53 * FIXME: The user database should hold all the information the USER_INFO_4 struct
54 * needs, but for the first try, I will just implement the USER_INFO_1 fields.
60 WCHAR user_name
[LM20_UNLEN
+1];
61 WCHAR user_password
[PWLEN
+ 1];
62 DWORD sec_since_passwd_change
;
67 LPWSTR user_logon_script_path
;
70 static struct list user_list
= LIST_INIT( user_list
);
72 BOOL
NETAPI_IsLocalComputer(LPCWSTR ServerName
);
74 /************************************************************
75 * NETAPI_ValidateServername
77 * Validates server name
79 static NET_API_STATUS
NETAPI_ValidateServername(LPCWSTR ServerName
)
83 if (ServerName
[0] == 0)
84 return ERROR_BAD_NETPATH
;
86 ((ServerName
[0] == '\\') &&
87 (ServerName
[1] != '\\'))
89 ((ServerName
[0] == '\\') &&
90 (ServerName
[1] == '\\') &&
93 return ERROR_INVALID_NAME
;
98 /************************************************************
101 * Looks for a user in the user database.
102 * Returns a pointer to the entry in the user list when the user
103 * is found, NULL otherwise.
105 static struct sam_user
* NETAPI_FindUser(LPCWSTR UserName
)
107 struct sam_user
*user
;
109 LIST_FOR_EACH_ENTRY(user
, &user_list
, struct sam_user
, entry
)
111 if(lstrcmpW(user
->user_name
, UserName
) == 0)
117 static BOOL
NETAPI_IsCurrentUser(LPCWSTR username
)
119 LPWSTR curr_user
= NULL
;
123 dwSize
= LM20_UNLEN
+1;
124 curr_user
= HeapAlloc(GetProcessHeap(), 0, dwSize
* sizeof(WCHAR
));
127 ERR("Failed to allocate memory for user name.\n");
130 if(!GetUserNameW(curr_user
, &dwSize
))
132 ERR("Failed to get current user's user name.\n");
135 if (!lstrcmpW(curr_user
, username
))
141 HeapFree(GetProcessHeap(), 0, curr_user
);
145 /************************************************************
146 * NetUserAdd (NETAPI32.@)
148 NET_API_STATUS WINAPI
NetUserAdd(LPCWSTR servername
,
149 DWORD level
, LPBYTE bufptr
, LPDWORD parm_err
)
151 NET_API_STATUS status
;
152 struct sam_user
* su
= NULL
;
154 FIXME("(%s, %d, %p, %p) stub!\n", debugstr_w(servername
), level
, bufptr
, parm_err
);
156 if((status
= NETAPI_ValidateServername(servername
)) != NERR_Success
)
161 /* Level 3 and 4 are identical for the purposes of NetUserAdd */
164 FIXME("Level 3 and 4 not implemented.\n");
167 FIXME("Level 2 not implemented.\n");
171 PUSER_INFO_1 ui
= (PUSER_INFO_1
) bufptr
;
172 su
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct sam_user
));
175 status
= NERR_InternalError
;
179 if(lstrlenW(ui
->usri1_name
) > LM20_UNLEN
)
181 status
= NERR_BadUsername
;
185 /*FIXME: do other checks for a valid username */
186 lstrcpyW(su
->user_name
, ui
->usri1_name
);
188 if(lstrlenW(ui
->usri1_password
) > PWLEN
)
190 /* Always return PasswordTooShort on invalid passwords. */
191 status
= NERR_PasswordTooShort
;
194 lstrcpyW(su
->user_password
, ui
->usri1_password
);
196 su
->sec_since_passwd_change
= ui
->usri1_password_age
;
197 su
->user_priv
= ui
->usri1_priv
;
198 su
->user_flags
= ui
->usri1_flags
;
200 /*FIXME: set the other LPWSTRs to NULL for now */
202 su
->user_comment
= NULL
;
203 su
->user_logon_script_path
= NULL
;
205 list_add_head(&user_list
, &su
->entry
);
209 TRACE("Invalid level %d specified.\n", level
);
210 status
= ERROR_INVALID_LEVEL
;
214 HeapFree(GetProcessHeap(), 0, su
);
219 /************************************************************
220 * NetUserDel (NETAPI32.@)
222 NET_API_STATUS WINAPI
NetUserDel(LPCWSTR servername
, LPCWSTR username
)
224 NET_API_STATUS status
;
225 struct sam_user
*user
;
227 TRACE("(%s, %s)\n", debugstr_w(servername
), debugstr_w(username
));
229 if((status
= NETAPI_ValidateServername(servername
))!= NERR_Success
)
232 if ((user
= NETAPI_FindUser(username
)) == NULL
)
233 return NERR_UserNotFound
;
235 list_remove(&user
->entry
);
237 HeapFree(GetProcessHeap(), 0, user
->home_dir
);
238 HeapFree(GetProcessHeap(), 0, user
->user_comment
);
239 HeapFree(GetProcessHeap(), 0, user
->user_logon_script_path
);
240 HeapFree(GetProcessHeap(), 0, user
);
245 /************************************************************
246 * NetUserGetInfo (NETAPI32.@)
248 NET_API_STATUS WINAPI
249 NetUserGetInfo(LPCWSTR servername
, LPCWSTR username
, DWORD level
,
252 NET_API_STATUS status
;
253 TRACE("(%s, %s, %d, %p)\n", debugstr_w(servername
), debugstr_w(username
),
255 status
= NETAPI_ValidateServername(servername
);
256 if (status
!= NERR_Success
)
259 if(!NETAPI_IsLocalComputer(servername
))
261 FIXME("Only implemented for local computer, but remote server"
262 "%s was requested.\n", debugstr_w(servername
));
263 return NERR_InvalidComputer
;
266 if(!NETAPI_FindUser(username
) && !NETAPI_IsCurrentUser(username
))
268 TRACE("User %s is unknown.\n", debugstr_w(username
));
269 return NERR_UserNotFound
;
279 name_sz
= lstrlenW(username
) + 1;
282 NetApiBufferAllocate(sizeof(USER_INFO_0
) + name_sz
* sizeof(WCHAR
),
285 ui
= (PUSER_INFO_0
) *bufptr
;
286 ui
->usri0_name
= (LPWSTR
) (*bufptr
+ sizeof(USER_INFO_0
));
289 lstrcpyW(ui
->usri0_name
, username
);
297 /* sizes of the field buffers in WCHARS */
298 int name_sz
, comment_sz
, usr_comment_sz
, full_name_sz
;
305 status
= NetUserGetInfo(servername
, username
, 0, (LPBYTE
*) &ui0
);
306 if (status
!= NERR_Success
)
308 NetApiBufferFree(ui0
);
311 name_sz
= lstrlenW(ui0
->usri0_name
) + 1;
314 NetApiBufferAllocate(sizeof(USER_INFO_10
) +
315 (name_sz
+ comment_sz
+ usr_comment_sz
+
316 full_name_sz
) * sizeof(WCHAR
),
318 ui
= (PUSER_INFO_10
) *bufptr
;
319 ui
->usri10_name
= (LPWSTR
) (*bufptr
+ sizeof(USER_INFO_10
));
320 ui
->usri10_comment
= (LPWSTR
) (
321 ((PBYTE
) ui
->usri10_name
) + name_sz
* sizeof(WCHAR
));
322 ui
->usri10_usr_comment
= (LPWSTR
) (
323 ((PBYTE
) ui
->usri10_comment
) + comment_sz
* sizeof(WCHAR
));
324 ui
->usri10_full_name
= (LPWSTR
) (
325 ((PBYTE
) ui
->usri10_usr_comment
) + usr_comment_sz
* sizeof(WCHAR
));
328 lstrcpyW(ui
->usri10_name
, ui0
->usri0_name
);
329 NetApiBufferFree(ui0
);
330 ui
->usri10_comment
[0] = 0;
331 ui
->usri10_usr_comment
[0] = 0;
332 ui
->usri10_full_name
[0] = 0;
338 static const WCHAR homedirW
[] = {'H','O','M','E',0};
341 /* sizes of the field buffers in WCHARS */
342 int name_sz
, password_sz
, home_dir_sz
, comment_sz
, script_path_sz
;
344 password_sz
= 1; /* not filled out for security reasons for NetUserGetInfo*/
349 status
= NetUserGetInfo(servername
, username
, 0, (LPBYTE
*) &ui0
);
350 if (status
!= NERR_Success
)
352 NetApiBufferFree(ui0
);
355 name_sz
= lstrlenW(ui0
->usri0_name
) + 1;
356 home_dir_sz
= GetEnvironmentVariableW(homedirW
, NULL
,0);
358 NetApiBufferAllocate(sizeof(USER_INFO_1
) +
359 (name_sz
+ password_sz
+ home_dir_sz
+
360 comment_sz
+ script_path_sz
) * sizeof(WCHAR
),
363 ui
= (PUSER_INFO_1
) *bufptr
;
364 ui
->usri1_name
= (LPWSTR
) (ui
+ 1);
365 ui
->usri1_password
= ui
->usri1_name
+ name_sz
;
366 ui
->usri1_home_dir
= ui
->usri1_password
+ password_sz
;
367 ui
->usri1_comment
= ui
->usri1_home_dir
+ home_dir_sz
;
368 ui
->usri1_script_path
= ui
->usri1_comment
+ comment_sz
;
370 lstrcpyW(ui
->usri1_name
, ui0
->usri0_name
);
371 NetApiBufferFree(ui0
);
372 ui
->usri1_password
[0] = 0;
373 ui
->usri1_password_age
= 0;
375 GetEnvironmentVariableW(homedirW
, ui
->usri1_home_dir
,home_dir_sz
);
376 ui
->usri1_comment
[0] = 0;
378 ui
->usri1_script_path
[0] = 0;
408 FIXME("Level %d is not implemented\n", level
);
409 return NERR_InternalError
;
412 TRACE("Invalid level %d is specified\n", level
);
413 return ERROR_INVALID_LEVEL
;
418 /************************************************************
419 * NetUserGetLocalGroups (NETAPI32.@)
421 NET_API_STATUS WINAPI
422 NetUserGetLocalGroups(LPCWSTR servername
, LPCWSTR username
, DWORD level
,
423 DWORD flags
, LPBYTE
* bufptr
, DWORD prefmaxlen
,
424 LPDWORD entriesread
, LPDWORD totalentries
)
426 NET_API_STATUS status
;
427 const WCHAR admins
[] = {'A','d','m','i','n','i','s','t','r','a','t','o','r','s',0};
429 LOCALGROUP_USERS_INFO_0
* info
;
432 FIXME("(%s, %s, %d, %08x, %p %d, %p, %p) stub!\n",
433 debugstr_w(servername
), debugstr_w(username
), level
, flags
, bufptr
,
434 prefmaxlen
, entriesread
, totalentries
);
436 status
= NETAPI_ValidateServername(servername
);
437 if (status
!= NERR_Success
)
441 NetApiBufferAllocate(size
* sizeof(WCHAR
), (LPVOID
*)¤tuser
);
442 if (!GetUserNameW(currentuser
, &size
)) {
443 NetApiBufferFree(currentuser
);
444 return ERROR_NOT_ENOUGH_MEMORY
;
447 if (lstrcmpiW(username
, currentuser
) && NETAPI_FindUser(username
))
449 NetApiBufferFree(currentuser
);
450 return NERR_UserNotFound
;
453 NetApiBufferFree(currentuser
);
455 size
= sizeof(*info
) + sizeof(admins
);
457 if(prefmaxlen
< size
)
458 status
= ERROR_MORE_DATA
;
460 status
= NetApiBufferAllocate(size
, (LPVOID
*)&info
);
462 if(status
!= NERR_Success
)
469 info
->lgrui0_name
= (LPWSTR
)((LPBYTE
)info
+ sizeof(*info
));
470 lstrcpyW(info
->lgrui0_name
, admins
);
472 *bufptr
= (LPBYTE
)info
;
478 /************************************************************
479 * NetUserEnum (NETAPI32.@)
481 NET_API_STATUS WINAPI
482 NetUserEnum(LPCWSTR servername
, DWORD level
, DWORD filter
, LPBYTE
* bufptr
,
483 DWORD prefmaxlen
, LPDWORD entriesread
, LPDWORD totalentries
,
484 LPDWORD resume_handle
)
486 FIXME("(%s,%d, 0x%d,%p,%d,%p,%p,%p) stub!\n", debugstr_w(servername
), level
,
487 filter
, bufptr
, prefmaxlen
, entriesread
, totalentries
, resume_handle
);
489 return ERROR_ACCESS_DENIED
;
492 /************************************************************
493 * ACCESS_QueryAdminDisplayInformation
495 * Creates a buffer with information for the Admin User
497 static void ACCESS_QueryAdminDisplayInformation(PNET_DISPLAY_USER
*buf
, PDWORD pdwSize
)
499 static const WCHAR sAdminUserName
[] = {
500 'A','d','m','i','n','i','s','t','r','a','t','o','r',0};
502 /* sizes of the field buffers in WCHARS */
503 int name_sz
, comment_sz
, full_name_sz
;
504 PNET_DISPLAY_USER usr
;
507 name_sz
= lstrlenW(sAdminUserName
) + 1;
511 *pdwSize
= sizeof(NET_DISPLAY_USER
);
512 *pdwSize
+= (name_sz
+ comment_sz
+ full_name_sz
) * sizeof(WCHAR
);
513 NetApiBufferAllocate(*pdwSize
, (LPVOID
*) 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
));
523 lstrcpyW(usr
->usri1_name
, sAdminUserName
);
524 usr
->usri1_comment
[0] = 0;
525 usr
->usri1_flags
= UF_SCRIPT
| UF_NORMAL_ACCOUNT
| UF_DONT_EXPIRE_PASSWD
;
526 usr
->usri1_full_name
[0] = 0;
527 usr
->usri1_user_id
= DOMAIN_USER_RID_ADMIN
;
528 usr
->usri1_next_index
= 0;
531 /************************************************************
532 * ACCESS_QueryGuestDisplayInformation
534 * Creates a buffer with information for the Guest User
536 static void ACCESS_QueryGuestDisplayInformation(PNET_DISPLAY_USER
*buf
, PDWORD pdwSize
)
538 static const WCHAR sGuestUserName
[] = {
539 'G','u','e','s','t',0 };
541 /* sizes of the field buffers in WCHARS */
542 int name_sz
, comment_sz
, full_name_sz
;
543 PNET_DISPLAY_USER usr
;
546 name_sz
= lstrlenW(sGuestUserName
) + 1;
550 *pdwSize
= sizeof(NET_DISPLAY_USER
);
551 *pdwSize
+= (name_sz
+ comment_sz
+ full_name_sz
) * sizeof(WCHAR
);
552 NetApiBufferAllocate(*pdwSize
, (LPVOID
*) buf
);
555 usr
->usri1_name
= (LPWSTR
) ((PBYTE
) usr
+ sizeof(NET_DISPLAY_USER
));
556 usr
->usri1_comment
= (LPWSTR
) (
557 ((PBYTE
) usr
->usri1_name
) + name_sz
* sizeof(WCHAR
));
558 usr
->usri1_full_name
= (LPWSTR
) (
559 ((PBYTE
) usr
->usri1_comment
) + comment_sz
* sizeof(WCHAR
));
562 lstrcpyW(usr
->usri1_name
, sGuestUserName
);
563 usr
->usri1_comment
[0] = 0;
564 usr
->usri1_flags
= UF_ACCOUNTDISABLE
| UF_SCRIPT
| UF_NORMAL_ACCOUNT
|
565 UF_DONT_EXPIRE_PASSWD
;
566 usr
->usri1_full_name
[0] = 0;
567 usr
->usri1_user_id
= DOMAIN_USER_RID_GUEST
;
568 usr
->usri1_next_index
= 0;
571 /************************************************************
572 * Copies NET_DISPLAY_USER record.
574 static void ACCESS_CopyDisplayUser(const NET_DISPLAY_USER
*dest
, LPWSTR
*dest_buf
,
575 PNET_DISPLAY_USER src
)
577 LPWSTR str
= *dest_buf
;
579 src
->usri1_name
= str
;
580 lstrcpyW(src
->usri1_name
, dest
->usri1_name
);
582 ((PBYTE
) str
) + (lstrlenW(str
) + 1) * sizeof(WCHAR
));
584 src
->usri1_comment
= str
;
585 lstrcpyW(src
->usri1_comment
, dest
->usri1_comment
);
587 ((PBYTE
) str
) + (lstrlenW(str
) + 1) * sizeof(WCHAR
));
589 src
->usri1_flags
= dest
->usri1_flags
;
591 src
->usri1_full_name
= str
;
592 lstrcpyW(src
->usri1_full_name
, dest
->usri1_full_name
);
594 ((PBYTE
) str
) + (lstrlenW(str
) + 1) * sizeof(WCHAR
));
596 src
->usri1_user_id
= dest
->usri1_user_id
;
597 src
->usri1_next_index
= dest
->usri1_next_index
;
601 /************************************************************
602 * NetQueryDisplayInformation (NETAPI32.@)
604 * The buffer structure:
605 * - array of fixed size record of the level type
606 * - strings, referenced by the record of the level type
608 NET_API_STATUS WINAPI
609 NetQueryDisplayInformation(
610 LPCWSTR ServerName
, DWORD Level
, DWORD Index
, DWORD EntriesRequested
,
611 DWORD PreferredMaximumLength
, LPDWORD ReturnedEntryCount
,
614 TRACE("(%s, %d, %d, %d, %d, %p, %p)\n", debugstr_w(ServerName
),
615 Level
, Index
, EntriesRequested
, PreferredMaximumLength
,
616 ReturnedEntryCount
, SortedBuffer
);
618 if(!NETAPI_IsLocalComputer(ServerName
))
620 FIXME("Only implemented on local computer, but requested for "
621 "remote server %s\n", debugstr_w(ServerName
));
622 return ERROR_ACCESS_DENIED
;
630 PNET_DISPLAY_USER inf
;
631 /* current available strings buffer */
633 PNET_DISPLAY_USER admin
, guest
;
634 DWORD admin_size
, guest_size
;
638 /* sizes of the field buffers in WCHARS */
639 int name_sz
, comment_sz
, full_name_sz
;
641 /* number of the records, returned in SortedBuffer
642 3 - for current user, Administrator and Guest users
646 FIXME("Level %d partially implemented\n", Level
);
647 *ReturnedEntryCount
= records
;
653 NetApiBufferAllocate(dwSize
* sizeof(WCHAR
), (LPVOID
*) &name
);
654 if (!GetUserNameW(name
, &dwSize
))
656 NetApiBufferFree(name
);
657 return ERROR_ACCESS_DENIED
;
660 ACCESS_QueryAdminDisplayInformation(&admin
, &admin_size
);
661 ACCESS_QueryGuestDisplayInformation(&guest
, &guest_size
);
664 dwSize
= sizeof(NET_DISPLAY_USER
) * records
;
665 dwSize
+= (name_sz
+ comment_sz
+ full_name_sz
) * sizeof(WCHAR
);
667 NetApiBufferAllocate(dwSize
+
668 admin_size
- sizeof(NET_DISPLAY_USER
) +
669 guest_size
- sizeof(NET_DISPLAY_USER
),
672 str
= (LPWSTR
) ((PBYTE
) inf
+ sizeof(NET_DISPLAY_USER
) * records
);
673 inf
->usri1_name
= str
;
675 ((PBYTE
) str
) + name_sz
* sizeof(WCHAR
));
676 inf
->usri1_comment
= str
;
678 ((PBYTE
) str
) + comment_sz
* sizeof(WCHAR
));
679 inf
->usri1_full_name
= str
;
681 ((PBYTE
) str
) + full_name_sz
* sizeof(WCHAR
));
684 lstrcpyW(inf
->usri1_name
, name
);
685 NetApiBufferFree(name
);
686 inf
->usri1_comment
[0] = 0;
688 UF_SCRIPT
| UF_NORMAL_ACCOUNT
| UF_DONT_EXPIRE_PASSWD
;
689 inf
->usri1_full_name
[0] = 0;
690 inf
->usri1_user_id
= 0;
691 inf
->usri1_next_index
= 0;
694 ACCESS_CopyDisplayUser(admin
, &str
, inf
);
695 NetApiBufferFree(admin
);
698 ACCESS_CopyDisplayUser(guest
, &str
, inf
);
699 NetApiBufferFree(guest
);
706 FIXME("Level %d is not implemented\n", Level
);
711 TRACE("Invalid level %d is specified\n", Level
);
712 return ERROR_INVALID_LEVEL
;
717 /************************************************************
718 * NetGetDCName (NETAPI32.@)
720 * Return the name of the primary domain controller (PDC)
723 NET_API_STATUS WINAPI
724 NetGetDCName(LPCWSTR servername
, LPCWSTR domainname
, LPBYTE
*bufptr
)
726 FIXME("(%s, %s, %p) stub!\n", debugstr_w(servername
),
727 debugstr_w(domainname
), bufptr
);
728 return NERR_DCNotFound
; /* say we can't find a domain controller */
731 /************************************************************
732 * NetGetAnyDCName (NETAPI32.@)
734 * Return the name of any domain controller (DC) for a
735 * domain that is directly trusted by the specified server
738 NET_API_STATUS WINAPI
NetGetAnyDCName(LPCWSTR servername
, LPCWSTR domainname
, LPBYTE
*bufptr
)
740 FIXME("(%s, %s, %p) stub!\n", debugstr_w(servername
),
741 debugstr_w(domainname
), bufptr
);
742 return ERROR_NO_SUCH_DOMAIN
;
745 /************************************************************
746 * NetGroupEnum (NETAPI32.@)
749 NET_API_STATUS WINAPI
750 NetGroupEnum(LPCWSTR servername
, DWORD level
, LPBYTE
*bufptr
, DWORD prefmaxlen
,
751 LPDWORD entriesread
, LPDWORD totalentries
, LPDWORD resume_handle
)
753 FIXME("(%s, %d, %p, %d, %p, %p, %p) stub!\n", debugstr_w(servername
),
754 level
, bufptr
, prefmaxlen
, entriesread
, totalentries
, resume_handle
);
755 return ERROR_ACCESS_DENIED
;
758 /************************************************************
759 * NetGroupGetInfo (NETAPI32.@)
762 NET_API_STATUS WINAPI
NetGroupGetInfo(LPCWSTR servername
, LPCWSTR groupname
, DWORD level
, LPBYTE
*bufptr
)
764 FIXME("(%s, %s, %d, %p) stub!\n", debugstr_w(servername
), debugstr_w(groupname
), level
, bufptr
);
765 return ERROR_ACCESS_DENIED
;
768 /******************************************************************************
769 * NetUserModalsGet (NETAPI32.@)
771 * Retrieves global information for all users and global groups in the security
775 * szServer [I] Specifies the DNS or the NetBIOS name of the remote server
776 * on which the function is to execute.
777 * level [I] Information level of the data.
778 * 0 Return global passwords parameters. bufptr points to a
779 * USER_MODALS_INFO_0 struct.
780 * 1 Return logon server and domain controller information. bufptr
781 * points to a USER_MODALS_INFO_1 struct.
782 * 2 Return domain name and identifier. bufptr points to a
783 * USER_MODALS_INFO_2 struct.
784 * 3 Return lockout information. bufptr points to a USER_MODALS_INFO_3
786 * pbuffer [I] Buffer that receives the data.
789 * Success: NERR_Success.
791 * ERROR_ACCESS_DENIED - the user does not have access to the info.
792 * NERR_InvalidComputer - computer name is invalid.
794 NET_API_STATUS WINAPI
NetUserModalsGet(
795 LPCWSTR szServer
, DWORD level
, LPBYTE
*pbuffer
)
797 TRACE("(%s %d %p)\n", debugstr_w(szServer
), level
, pbuffer
);
802 /* return global passwords parameters */
803 FIXME("level 0 not implemented!\n");
805 return NERR_InternalError
;
807 /* return logon server and domain controller info */
808 FIXME("level 1 not implemented!\n");
810 return NERR_InternalError
;
813 /* return domain name and identifier */
814 PUSER_MODALS_INFO_2 umi
;
815 LSA_HANDLE policyHandle
;
816 LSA_OBJECT_ATTRIBUTES objectAttributes
;
817 PPOLICY_ACCOUNT_DOMAIN_INFO domainInfo
;
819 PSID domainIdentifier
= NULL
;
822 ZeroMemory(&objectAttributes
, sizeof(objectAttributes
));
823 objectAttributes
.Length
= sizeof(objectAttributes
);
825 ntStatus
= LsaOpenPolicy(NULL
, &objectAttributes
,
826 POLICY_VIEW_LOCAL_INFORMATION
,
828 if (ntStatus
!= STATUS_SUCCESS
)
830 WARN("LsaOpenPolicy failed with NT status %x\n",
831 LsaNtStatusToWinError(ntStatus
));
835 ntStatus
= LsaQueryInformationPolicy(policyHandle
,
836 PolicyAccountDomainInformation
,
837 (PVOID
*)&domainInfo
);
838 if (ntStatus
!= STATUS_SUCCESS
)
840 WARN("LsaQueryInformationPolicy failed with NT status %x\n",
841 LsaNtStatusToWinError(ntStatus
));
842 LsaClose(policyHandle
);
846 domainIdentifier
= domainInfo
->DomainSid
;
847 domainNameLen
= lstrlenW(domainInfo
->DomainName
.Buffer
) + 1;
848 LsaClose(policyHandle
);
850 ntStatus
= NetApiBufferAllocate(sizeof(USER_MODALS_INFO_2
) +
851 GetLengthSid(domainIdentifier
) +
852 domainNameLen
* sizeof(WCHAR
),
855 if (ntStatus
!= NERR_Success
)
857 WARN("NetApiBufferAllocate() failed\n");
858 LsaFreeMemory(domainInfo
);
862 umi
= (USER_MODALS_INFO_2
*) *pbuffer
;
863 umi
->usrmod2_domain_id
= *pbuffer
+ sizeof(USER_MODALS_INFO_2
);
864 umi
->usrmod2_domain_name
= (LPWSTR
)(*pbuffer
+
865 sizeof(USER_MODALS_INFO_2
) + GetLengthSid(domainIdentifier
));
867 lstrcpynW(umi
->usrmod2_domain_name
,
868 domainInfo
->DomainName
.Buffer
,
870 CopySid(GetLengthSid(domainIdentifier
), umi
->usrmod2_domain_id
,
873 LsaFreeMemory(domainInfo
);
878 /* return lockout information */
879 FIXME("level 3 not implemented!\n");
881 return NERR_InternalError
;
883 TRACE("Invalid level %d is specified\n", level
);
885 return ERROR_INVALID_LEVEL
;
891 static char *strdup_unixcp( const WCHAR
*str
)
894 int len
= WideCharToMultiByte( CP_UNIXCP
, 0, str
, -1, NULL
, 0, NULL
, NULL
);
895 if ((ret
= HeapAlloc( GetProcessHeap(), 0, len
)))
896 WideCharToMultiByte( CP_UNIXCP
, 0, str
, -1, ret
, len
, NULL
, NULL
);
900 static NET_API_STATUS
change_password_smb( LPCWSTR domainname
, LPCWSTR username
,
901 LPCWSTR oldpassword
, LPCWSTR newpassword
)
904 NET_API_STATUS ret
= NERR_Success
;
905 static char option_silent
[] = "-s";
906 static char option_user
[] = "-U";
907 static char option_remote
[] = "-r";
908 static char smbpasswd
[] = "smbpasswd";
912 char *server
= NULL
, *user
, *argv
[7], *old
= NULL
, *new = NULL
;
914 if (domainname
&& !(server
= strdup_unixcp( domainname
))) return ERROR_OUTOFMEMORY
;
915 if (!(user
= strdup_unixcp( username
)))
917 ret
= ERROR_OUTOFMEMORY
;
920 if (!(old
= strdup_unixcp( oldpassword
)))
922 ret
= ERROR_OUTOFMEMORY
;
925 if (!(new = strdup_unixcp( newpassword
)))
927 ret
= ERROR_OUTOFMEMORY
;
931 argv
[1] = option_silent
;
932 argv
[2] = option_user
;
936 argv
[4] = option_remote
;
942 if (pipe( pipe_out
) == -1)
944 ret
= NERR_InternalError
;
947 fcntl( pipe_out
[0], F_SETFD
, FD_CLOEXEC
);
948 fcntl( pipe_out
[1], F_SETFD
, FD_CLOEXEC
);
950 switch ((pid
= fork()))
953 close( pipe_out
[0] );
954 close( pipe_out
[1] );
955 ret
= NERR_InternalError
;
958 dup2( pipe_out
[0], 0 );
959 close( pipe_out
[0] );
960 close( pipe_out
[1] );
961 execvp( "smbpasswd", argv
);
962 ERR( "can't execute smbpasswd, is it installed?\n" );
965 close( pipe_out
[0] );
968 write( pipe_out
[1], old
, strlen( old
) );
969 write( pipe_out
[1], "\n", 1 );
970 write( pipe_out
[1], new, strlen( new ) );
971 write( pipe_out
[1], "\n", 1 );
972 write( pipe_out
[1], new, strlen( new ) );
973 write( pipe_out
[1], "\n", 1 );
974 close( pipe_out
[1] );
977 wret
= waitpid(pid
, &status
, 0);
978 } while (wret
< 0 && errno
== EINTR
);
980 if (ret
== NERR_Success
&& (wret
< 0 || !WIFEXITED(status
) || WEXITSTATUS(status
)))
981 ret
= NERR_InternalError
;
984 HeapFree( GetProcessHeap(), 0, server
);
985 HeapFree( GetProcessHeap(), 0, user
);
986 HeapFree( GetProcessHeap(), 0, old
);
987 HeapFree( GetProcessHeap(), 0, new );
990 ERR( "no fork support on this platform\n" );
991 return NERR_InternalError
;
995 /******************************************************************************
996 * NetUserChangePassword (NETAPI32.@)
998 * domainname [I] Optional. Domain on which the user resides or the logon
999 * domain of the current user if NULL.
1000 * username [I] Optional. Username to change the password for or the name
1001 * of the current user if NULL.
1002 * oldpassword [I] The user's current password.
1003 * newpassword [I] The password that the user will be changed to using.
1006 * Success: NERR_Success.
1007 * Failure: NERR_* failure code or win error code.
1010 NET_API_STATUS WINAPI
NetUserChangePassword(LPCWSTR domainname
, LPCWSTR username
,
1011 LPCWSTR oldpassword
, LPCWSTR newpassword
)
1013 struct sam_user
*user
;
1015 TRACE("(%s, %s, ..., ...)\n", debugstr_w(domainname
), debugstr_w(username
));
1017 if (!change_password_smb( domainname
, username
, oldpassword
, newpassword
))
1018 return NERR_Success
;
1021 FIXME("Ignoring domainname %s.\n", debugstr_w(domainname
));
1023 if((user
= NETAPI_FindUser(username
)) == NULL
)
1024 return NERR_UserNotFound
;
1026 if(lstrcmpW(user
->user_password
, oldpassword
) != 0)
1027 return ERROR_INVALID_PASSWORD
;
1029 if(lstrlenW(newpassword
) > PWLEN
)
1030 return ERROR_PASSWORD_RESTRICTION
;
1032 lstrcpyW(user
->user_password
, newpassword
);
1034 return NERR_Success
;
1037 NET_API_STATUS WINAPI
NetUseAdd(LMSTR servername
, DWORD level
, LPBYTE bufptr
, LPDWORD parm_err
)
1039 FIXME("%s %d %p %p stub\n", debugstr_w(servername
), level
, bufptr
, parm_err
);
1040 return NERR_Success
;
1043 NET_API_STATUS WINAPI
NetUseDel(LMSTR servername
, LMSTR usename
, DWORD forcecond
)
1045 FIXME("%s %s %d stub\n", debugstr_w(servername
), debugstr_w(usename
), forcecond
);
1046 return NERR_Success
;