SamQueryInformationDomain:使用 _DOMAIN_PASSWORD_INFORMATION 获取 DOMAIN_PASSWORD_COMPLEX

SamQueryInformationDomain: get DOMAIN_PASSWORD_COMPLEX using _DOMAIN_PASSWORD_INFORMATION

我正在尝试获取密码复杂性,寻找 WINAPI 找到 SamQueryInformationDomain 但似乎没有 public 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 (?) %08x\n", status);
    return;
}

status = SamOpenDomain(hServerHandle, DOMAIN_READ_PASSWORD_PARAMETERS, &builtin, &hDomainHandle);
if (0 != status)
{
    printf("SamOpenDomain Builtin (?) %08x\n", status);
    return;
}

status = SamQueryInformationDomain(hDomainHandle, DomainPasswordInformation, &buff);

if (0 != status)
{
    printf("SamQueryInformation failed with %08x\n", status);
    return ;
}

ULONG properties = buff->Password.PasswordProperties;


printf("SamQueryInformation success with password properties value : %ld\n", properties);
printf("SamQueryInformation success with password MaxPasswordAge value : %ld\n", buff->Password.MaxPasswordAge);
printf("SamQueryInformation success with password MinPasswordAge value : %ld\n", buff->Password.MinPasswordAge);
printf("SamQueryInformation success with password MinPasswordLength value : %ld\n", buff->Password.MinPasswordLength);
printf("SamQueryInformation success with password PasswordHistoryLength value : %ld\n", buff->Password.PasswordHistoryLength);