我正在尝试获取密码复杂性,正在查找WINAPI找到的SamQueryInformationDomain但似乎没有公开的MSDN文档,也没有头文件。在这里找到了soem C#代码片段,但没有找到为SamQueryInformationDomain剪切的一些示例C++代码。如果可以共享样本代码,那将是一个很大的帮助
经过多次尝试和搜索,我终于找到了
NTSTATUS status, enumDomainStatus, enumUserStatus;
UNICODE_STRING serverName;
ACCESS_MASK mask = 0;
mask = SAM_SERVER_CONNECT | SAM_SERVER_ENUMERATE_DOMAINS | SAM_SERVER_LOOKUP_DOMAIN;
SAMPR_HANDLE hServerHandle, hBuiltinHandle = NULL, hDomainHandle, hUserHandle;
DWORD domainEnumerationContext = 0, domainCountRetourned, userEnumerationContext, userCountRetourned, groupsCountRetourned, i, j, k, aliasCountRetourned, *alias;
PSAMPR_RID_ENUMERATION pEnumDomainBuffer, pEnumUsersBuffer;
PSID domainSid, userSid;
SID builtin = { SID_REVISION, 1, SECURITY_NT_AUTHORITY, {SECURITY_BUILTIN_DOMAIN_RID} };
PGROUP_MEMBERSHIP pGroupMemberShip;
PSAMPR_DOMAIN_INFO_BUFFER buff;
RtlInitUnicodeString(&serverName, L"");
status = SamConnect(&serverName, &hServerHandle, SAM_SERVER_ALL_ACCESS, FALSE);
if (0 != status)
{
printf("SamConnect error (?) %08xn", status);
return;
}
status = SamOpenDomain(hServerHandle, DOMAIN_READ_PASSWORD_PARAMETERS, &builtin, &hDomainHandle);
if (0 != status)
{
printf("SamOpenDomain Builtin (?) %08xn", status);
return;
}
status = SamQueryInformationDomain(hDomainHandle, DomainPasswordInformation, &buff);
if (0 != status)
{
printf("SamQueryInformation failed with %08xn", status);
return ;
}
ULONG properties = buff->Password.PasswordProperties;
printf("SamQueryInformation success with password properties value : %ldn", properties);
printf("SamQueryInformation success with password MaxPasswordAge value : %ldn", buff->Password.MaxPasswordAge);
printf("SamQueryInformation success with password MinPasswordAge value : %ldn", buff->Password.MinPasswordAge);
printf("SamQueryInformation success with password MinPasswordLength value : %ldn", buff->Password.MinPasswordLength);
printf("SamQueryInformation success with password PasswordHistoryLength value : %ldn", buff->Password.PasswordHistoryLength);