📄 access.c
字号:
NET_API_STATUS WINAPI
NetUserEnum(LPCWSTR servername, DWORD level, DWORD filter, LPBYTE* bufptr,
DWORD prefmaxlen, LPDWORD entriesread, LPDWORD totalentries,
LPDWORD resume_handle)
{
FIXME("(%s,%d, 0x%d,%p,%d,%p,%p,%p) stub!\n", debugstr_w(servername), level,
filter, bufptr, prefmaxlen, entriesread, totalentries, resume_handle);
return ERROR_ACCESS_DENIED;
}
/************************************************************
* ACCESS_QueryAdminDisplayInformation
*
* Creates a buffer with information for the Admin User
*/
static void ACCESS_QueryAdminDisplayInformation(PNET_DISPLAY_USER *buf, PDWORD pdwSize)
{
static const WCHAR sAdminUserName[] = {
'A','d','m','i','n','i','s','t','r','a','t','o','r',0};
/* sizes of the field buffers in WCHARS */
int name_sz, comment_sz, full_name_sz;
PNET_DISPLAY_USER usr;
/* set up buffer */
name_sz = lstrlenW(sAdminUserName);
comment_sz = 1;
full_name_sz = 1;
*pdwSize = sizeof(NET_DISPLAY_USER);
*pdwSize += (name_sz + comment_sz + full_name_sz) * sizeof(WCHAR);
NetApiBufferAllocate(*pdwSize, (LPVOID *) buf);
usr = *buf;
usr->usri1_name = (LPWSTR) ((PBYTE) usr + sizeof(NET_DISPLAY_USER));
usr->usri1_comment = (LPWSTR) (
((PBYTE) usr->usri1_name) + name_sz * sizeof(WCHAR));
usr->usri1_full_name = (LPWSTR) (
((PBYTE) usr->usri1_comment) + comment_sz * sizeof(WCHAR));
/* set data */
lstrcpyW(usr->usri1_name, sAdminUserName);
usr->usri1_comment[0] = 0;
usr->usri1_flags = UF_SCRIPT | UF_NORMAL_ACCOUNT | UF_DONT_EXPIRE_PASSWD;
usr->usri1_full_name[0] = 0;
usr->usri1_user_id = 500;
usr->usri1_next_index = 0;
}
/************************************************************
* ACCESS_QueryGuestDisplayInformation
*
* Creates a buffer with information for the Guest User
*/
static void ACCESS_QueryGuestDisplayInformation(PNET_DISPLAY_USER *buf, PDWORD pdwSize)
{
static const WCHAR sGuestUserName[] = {
'G','u','e','s','t',0 };
/* sizes of the field buffers in WCHARS */
int name_sz, comment_sz, full_name_sz;
PNET_DISPLAY_USER usr;
/* set up buffer */
name_sz = lstrlenW(sGuestUserName);
comment_sz = 1;
full_name_sz = 1;
*pdwSize = sizeof(NET_DISPLAY_USER);
*pdwSize += (name_sz + comment_sz + full_name_sz) * sizeof(WCHAR);
NetApiBufferAllocate(*pdwSize, (LPVOID *) buf);
usr = *buf;
usr->usri1_name = (LPWSTR) ((PBYTE) usr + sizeof(NET_DISPLAY_USER));
usr->usri1_comment = (LPWSTR) (
((PBYTE) usr->usri1_name) + name_sz * sizeof(WCHAR));
usr->usri1_full_name = (LPWSTR) (
((PBYTE) usr->usri1_comment) + comment_sz * sizeof(WCHAR));
/* set data */
lstrcpyW(usr->usri1_name, sGuestUserName);
usr->usri1_comment[0] = 0;
usr->usri1_flags = UF_ACCOUNTDISABLE | UF_SCRIPT | UF_NORMAL_ACCOUNT |
UF_DONT_EXPIRE_PASSWD;
usr->usri1_full_name[0] = 0;
usr->usri1_user_id = 500;
usr->usri1_next_index = 0;
}
/************************************************************
* Copies NET_DISPLAY_USER record.
*/
static void ACCESS_CopyDisplayUser(const NET_DISPLAY_USER *dest, LPWSTR *dest_buf,
PNET_DISPLAY_USER src)
{
LPWSTR str = *dest_buf;
src->usri1_name = str;
lstrcpyW(src->usri1_name, dest->usri1_name);
str = (LPWSTR) (
((PBYTE) str) + (lstrlenW(str) + 1) * sizeof(WCHAR));
src->usri1_comment = str;
lstrcpyW(src->usri1_comment, dest->usri1_comment);
str = (LPWSTR) (
((PBYTE) str) + (lstrlenW(str) + 1) * sizeof(WCHAR));
src->usri1_flags = dest->usri1_flags;
src->usri1_full_name = str;
lstrcpyW(src->usri1_full_name, dest->usri1_full_name);
str = (LPWSTR) (
((PBYTE) str) + (lstrlenW(str) + 1) * sizeof(WCHAR));
src->usri1_user_id = dest->usri1_user_id;
src->usri1_next_index = dest->usri1_next_index;
*dest_buf = str;
}
/************************************************************
* NetQueryDisplayInformation (NETAPI32.@)
*
* The buffer structure:
* - array of fixed size record of the level type
* - strings, referenced by the record of the level type
*/
NET_API_STATUS WINAPI
NetQueryDisplayInformation(
LPCWSTR ServerName, DWORD Level, DWORD Index, DWORD EntriesRequested,
DWORD PreferredMaximumLength, LPDWORD ReturnedEntryCount,
PVOID *SortedBuffer)
{
TRACE("(%s, %d, %d, %d, %d, %p, %p)\n", debugstr_w(ServerName),
Level, Index, EntriesRequested, PreferredMaximumLength,
ReturnedEntryCount, SortedBuffer);
if(!NETAPI_IsLocalComputer(ServerName))
{
FIXME("Only implemented on local computer, but requested for "
"remote server %s\n", debugstr_w(ServerName));
return ERROR_ACCESS_DENIED;
}
switch (Level)
{
case 1:
{
/* current record */
PNET_DISPLAY_USER inf;
/* current available strings buffer */
LPWSTR str;
PNET_DISPLAY_USER admin, guest;
DWORD admin_size, guest_size;
LPWSTR name = NULL;
DWORD dwSize;
/* sizes of the field buffers in WCHARS */
int name_sz, comment_sz, full_name_sz;
/* number of the records, returned in SortedBuffer
3 - for current user, Administrator and Guest users
*/
int records = 3;
FIXME("Level %d partially implemented\n", Level);
*ReturnedEntryCount = records;
comment_sz = 1;
full_name_sz = 1;
/* get data */
dwSize = UNLEN + 1;
NetApiBufferAllocate(dwSize, (LPVOID *) &name);
if (!GetUserNameW(name, &dwSize))
{
NetApiBufferFree(name);
return ERROR_ACCESS_DENIED;
}
name_sz = dwSize;
ACCESS_QueryAdminDisplayInformation(&admin, &admin_size);
ACCESS_QueryGuestDisplayInformation(&guest, &guest_size);
/* set up buffer */
dwSize = sizeof(NET_DISPLAY_USER) * records;
dwSize += (name_sz + comment_sz + full_name_sz) * sizeof(WCHAR);
NetApiBufferAllocate(dwSize +
admin_size - sizeof(NET_DISPLAY_USER) +
guest_size - sizeof(NET_DISPLAY_USER),
(LPVOID *) SortedBuffer);
inf = (PNET_DISPLAY_USER) *SortedBuffer;
str = (LPWSTR) ((PBYTE) inf + sizeof(NET_DISPLAY_USER) * records);
inf->usri1_name = str;
str = (LPWSTR) (
((PBYTE) str) + name_sz * sizeof(WCHAR));
inf->usri1_comment = str;
str = (LPWSTR) (
((PBYTE) str) + comment_sz * sizeof(WCHAR));
inf->usri1_full_name = str;
str = (LPWSTR) (
((PBYTE) str) + full_name_sz * sizeof(WCHAR));
/* set data */
lstrcpyW(inf->usri1_name, name);
NetApiBufferFree(name);
inf->usri1_comment[0] = 0;
inf->usri1_flags =
UF_SCRIPT | UF_NORMAL_ACCOUNT | UF_DONT_EXPIRE_PASSWD;
inf->usri1_full_name[0] = 0;
inf->usri1_user_id = 0;
inf->usri1_next_index = 0;
inf++;
ACCESS_CopyDisplayUser(admin, &str, inf);
NetApiBufferFree(admin);
inf++;
ACCESS_CopyDisplayUser(guest, &str, inf);
NetApiBufferFree(guest);
break;
}
case 2:
case 3:
{
FIXME("Level %d is not implemented\n", Level);
break;
}
default:
TRACE("Invalid level %d is specified\n", Level);
return ERROR_INVALID_LEVEL;
}
return NERR_Success;
}
/************************************************************
* NetGetDCName (NETAPI32.@)
*
* Return the name of the primary domain controller (PDC)
*/
NET_API_STATUS WINAPI
NetGetDCName(LPCWSTR servername, LPCWSTR domainname, LPBYTE *bufptr)
{
FIXME("(%s, %s, %p) stub!\n", debugstr_w(servername),
debugstr_w(domainname), bufptr);
return NERR_DCNotFound; /* say we can't find a domain controller */
}
/******************************************************************************
* NetUserModalsGet (NETAPI32.@)
*
* Retrieves global information for all users and global groups in the security
* database.
*
* PARAMS
* szServer [I] Specifies the DNS or the NetBIOS name of the remote server
* on which the function is to execute.
* level [I] Information level of the data.
* 0 Return global passwords parameters. bufptr points to a
* USER_MODALS_INFO_0 struct.
* 1 Return logon server and domain controller information. bufptr
* points to a USER_MODALS_INFO_1 struct.
* 2 Return domain name and identifier. bufptr points to a
* USER_MODALS_INFO_2 struct.
* 3 Return lockout information. bufptr points to a USER_MODALS_INFO_3
* struct.
* pbuffer [I] Buffer that receives the data.
*
* RETURNS
* Success: NERR_Success.
* Failure:
* ERROR_ACCESS_DENIED - the user does not have access to the info.
* NERR_InvalidComputer - computer name is invalid.
*/
NET_API_STATUS WINAPI NetUserModalsGet(
LPCWSTR szServer, DWORD level, LPBYTE *pbuffer)
{
TRACE("(%s %d %p)\n", debugstr_w(szServer), level, pbuffer);
switch (level)
{
case 0:
/* return global passwords parameters */
FIXME("level 0 not implemented!\n");
*pbuffer = NULL;
return NERR_InternalError;
case 1:
/* return logon server and domain controller info */
FIXME("level 1 not implemented!\n");
*pbuffer = NULL;
return NERR_InternalError;
case 2:
{
/* return domain name and identifier */
PUSER_MODALS_INFO_2 umi;
LSA_HANDLE policyHandle;
LSA_OBJECT_ATTRIBUTES objectAttributes;
PPOLICY_ACCOUNT_DOMAIN_INFO domainInfo;
NTSTATUS ntStatus;
PSID domainIdentifier = NULL;
int domainNameLen;
ZeroMemory(&objectAttributes, sizeof(objectAttributes));
objectAttributes.Length = sizeof(objectAttributes);
ntStatus = LsaOpenPolicy(NULL, &objectAttributes,
POLICY_VIEW_LOCAL_INFORMATION,
&policyHandle);
if (ntStatus != STATUS_SUCCESS)
{
WARN("LsaOpenPolicy failed with NT status %x\n",
LsaNtStatusToWinError(ntStatus));
return ntStatus;
}
ntStatus = LsaQueryInformationPolicy(policyHandle,
PolicyAccountDomainInformation,
(PVOID *)&domainInfo);
if (ntStatus != STATUS_SUCCESS)
{
WARN("LsaQueryInformationPolicy failed with NT status %x\n",
LsaNtStatusToWinError(ntStatus));
LsaClose(policyHandle);
return ntStatus;
}
domainIdentifier = domainInfo->DomainSid;
domainNameLen = lstrlenW(domainInfo->DomainName.Buffer) + 1;
LsaClose(policyHandle);
ntStatus = NetApiBufferAllocate(sizeof(USER_MODALS_INFO_2) +
GetLengthSid(domainIdentifier) +
domainNameLen * sizeof(WCHAR),
(LPVOID *)pbuffer);
if (ntStatus != NERR_Success)
{
WARN("NetApiBufferAllocate() failed\n");
LsaFreeMemory(domainInfo);
return ntStatus;
}
umi = (USER_MODALS_INFO_2 *) *pbuffer;
umi->usrmod2_domain_id = (PSID)(*pbuffer +
sizeof(USER_MODALS_INFO_2));
umi->usrmod2_domain_name = (LPWSTR)(*pbuffer +
sizeof(USER_MODALS_INFO_2) + GetLengthSid(domainIdentifier));
lstrcpynW(umi->usrmod2_domain_name,
domainInfo->DomainName.Buffer,
domainNameLen);
CopySid(GetLengthSid(domainIdentifier), umi->usrmod2_domain_id,
domainIdentifier);
LsaFreeMemory(domainInfo);
break;
}
case 3:
/* return lockout information */
FIXME("level 3 not implemented!\n");
*pbuffer = NULL;
return NERR_InternalError;
default:
TRACE("Invalid level %d is specified\n", level);
*pbuffer = NULL;
return ERROR_INVALID_LEVEL;
}
return NERR_Success;
}
/******************************************************************************
* NetUserChangePassword (NETAPI32.@)
* PARAMS
* domainname [I] Optional. Domain on which the user resides or the logon
* domain of the current user if NULL.
* username [I] Optional. Username to change the password for or the name
* of the current user if NULL.
* oldpassword [I] The user's current password.
* newpassword [I] The password that the user will be changed to using.
*
* RETURNS
* Success: NERR_Success.
* Failure: NERR_* failure code or win error code.
*
*/
NET_API_STATUS WINAPI NetUserChangePassword(LPCWSTR domainname, LPCWSTR username,
LPCWSTR oldpassword, LPCWSTR newpassword)
{
struct sam_user *user;
TRACE("(%s, %s, ..., ...)\n", debugstr_w(domainname), debugstr_w(username));
if(domainname)
FIXME("Ignoring domainname %s.\n", debugstr_w(domainname));
if((user = NETAPI_FindUser(username)) == NULL)
return NERR_UserNotFound;
if(lstrcmpW(user->user_password, oldpassword) != 0)
return ERROR_INVALID_PASSWORD;
if(lstrlenW(newpassword) > PWLEN)
return ERROR_PASSWORD_RESTRICTION;
lstrcpyW(user->user_password, newpassword);
return NERR_Success;
}
NET_API_STATUS NetUseAdd(LMSTR servername, DWORD level, LPBYTE bufptr, LPDWORD parm_err)
{
FIXME("%s %d %p %p stub\n", debugstr_w(servername), level, bufptr, parm_err);
return NERR_Success;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -