在 C++ 中使用 Winldap.h 获取 maxPwdAge
Get maxPwdAge using Winldap.h in C++
如何在 C++ 中使用 winldap.h 获取 maxPwdAge?我能够获取用户的所有条目,但由于 maxPwdAge 属性 属于域,我不知道如何读取并获取所需的值。
下面是我用来获取 maxPwdAge 的代码
std::string Imaxpasswordage = "";
result = ldap_search_s(ldap, _T("DC=XXXXXX,DC=XXXXXX"), scope, _T("(maxPwdAge=*)"),
NULL, attrsonly, &answer);
if (result != LDAP_SUCCESS) {
error = result;
return result;
}
entries_found = ldap_count_entries(ldap, answer);
for (entry = ldap_first_entry(ldap, answer);
entry != NULL;
entry = ldap_next_entry(ldap, entry)) {
for (attribute = ldap_first_attribute(ldap, entry, &ber);
attribute != NULL;
attribute = ldap_next_attribute(ldap, entry, ber)) {
if ((values = ldap_get_values(ldap, entry, attribute)) != NULL) {
int compare = wcscmp(attribute, _T("maxPwdAge"));
if (compare == 0)
{
for (int i = 0; values[i] != NULL; i++)
{
char Temp[2000];
wcstombs(Temp, values[i], 2000);
std::wstring str(values[i]);
std::string str0(str.begin() + 1, str.end());
Imaxpasswordage = str0;
break;
}
ldap_value_free(values);
}
}
}
}
如何在 C++ 中使用 winldap.h 获取 maxPwdAge?我能够获取用户的所有条目,但由于 maxPwdAge 属性 属于域,我不知道如何读取并获取所需的值。
下面是我用来获取 maxPwdAge 的代码
std::string Imaxpasswordage = "";
result = ldap_search_s(ldap, _T("DC=XXXXXX,DC=XXXXXX"), scope, _T("(maxPwdAge=*)"),
NULL, attrsonly, &answer);
if (result != LDAP_SUCCESS) {
error = result;
return result;
}
entries_found = ldap_count_entries(ldap, answer);
for (entry = ldap_first_entry(ldap, answer);
entry != NULL;
entry = ldap_next_entry(ldap, entry)) {
for (attribute = ldap_first_attribute(ldap, entry, &ber);
attribute != NULL;
attribute = ldap_next_attribute(ldap, entry, ber)) {
if ((values = ldap_get_values(ldap, entry, attribute)) != NULL) {
int compare = wcscmp(attribute, _T("maxPwdAge"));
if (compare == 0)
{
for (int i = 0; values[i] != NULL; i++)
{
char Temp[2000];
wcstombs(Temp, values[i], 2000);
std::wstring str(values[i]);
std::string str0(str.begin() + 1, str.end());
Imaxpasswordage = str0;
break;
}
ldap_value_free(values);
}
}
}
}