使用C ++从客户端更改Active Directory用户的密码 [英] Change Password of Active Directory User from Client Using C++
问题描述
我正在尝试使用c ++ over SSL(端口636)中的ldap连接到Active Directory。我已成功将我的客户端PC与具有Active的服务器PC连接端口389上的目录。我想通过SSL连接的原因是因为我想
更改并编辑用户的密码。当我尝试编辑像"sn"这样的属性时我能够这样做而不是密码。所以我想通过SSL连接我的客户端PC和服务器PC,并使用
c ++中的ldap应用程序编辑密码。该应用程序在WinCE 8.0 OS上运行。 [服务器PC是Windows Server 2012.]
$
以下是我正在使用的代码:
I'm trying to connect to Active Directory using ldap in c++ over SSL (port 636).I have successfully connected my client PC with the Server PC having Active Directory on the port 389. The reason I want to connect over SSL is because I would like to
change and edit the password of the users. When I try to edit the attributes like "sn" I'm able to do so but not the password. So I would like to connect my client PC with the server PC over SSL and edit the password using the ldap application in
c++. The application is running on a WinCE 8.0 OS. [Server PC is Windows Server 2012.]
Below is the code that I'm using:
string myaarray[5];
wstring IUserList;
LDAP *ldap;
LDAPMessage *entry;
LDAPMessage *answer = NULL;
BerElement *ber;
int result;
int auth_method = LDAP_AUTH_SIMPLE;
int ldap_version = LDAP_VERSION3;
int lv = 0;
int ldap_port = 389;
//TCHAR ldap_dn[128] = _T("Maestrotek.Local");
//TCHAR *ldap_pw = _T("Admin@123");
TCHAR *base_dn = _T("DC=Maestrotek,DC=Local");
int scope = LDAP_SCOPE_SUBTREE;
TCHAR *filter = _T("(&(objectClass=user))");
char *attrs[] = { "memberOf", NULL };
int attrsonly = 0;
int entries_found = 0;
PWCHAR attribute;
PWCHAR *values;
int a = LDAP_PORT;
//if ((ldap = ldap_init(_T("127.0.0.1"), LDAP_PORT)) == NULL) {
if ((ldap = ldap_sslinit(_T("WIN-J48M2AB8EMI.Maestrotek.Local"), LDAP_SSL_PORT,1)) == NULL) {
}
else {
}
result = ldap_set_option(ldap, LDAP_OPT_PROTOCOL_VERSION, &ldap_version);
if (result != LDAP_SUCCESS) {
}
result = ldap_set_option(ldap, LDAP_OPT_SSL, LDAP_OPT_ON);
result = ldap_get_option(ldap, LDAP_OPT_SSL, &lv);
if (result != LDAP_SUCCESS) {
}
if ((void*)lv == LDAP_OPT_ON)
{
}
else
{
ldap_perror(ldap, "ldap_set_option failed!");
}
TCHAR *server = _T("127.0.0.1");
TCHAR *username = _T("Administrator");
TCHAR *password = _T("Admin@123");
TCHAR *DomainName = _T("Maestrotek.Local");
TCHAR *condition = _T("displayName");
l_timeval time;
SEC_WINNT_AUTH_IDENTITY AuthId;
time.tv_sec = 30;
time.tv_usec = 30;
AuthId.User = (unsigned short *)username;
AuthId.UserLength = _tcslen(username);
AuthId.Password = (unsigned short *)password;
AuthId.PasswordLength = _tcslen(password);
AuthId.Domain = (unsigned short *)DomainName;
AuthId.DomainLength = _tcslen(DomainName);
#ifdef UNICODE
AuthId.Flags = SEC_WINNT_AUTH_IDENTITY_UNICODE;
#else
AuthId.Flags = SEC_WINNT_AUTH_IDENTITY_ANSI;
#endif
result = ldap_bind_s(ldap, (PWCHAR)AuthId.User, (PWCHAR)&AuthId,LDAP_AUTH_SIMPLE);
wchar_t *Password[] = { L"Rushali@123",NULL};
struct berval **bvalue = NULL;
int msgid;
int
rc = 0;
LDAPMod attribute2;
LDAPMod *list_of_attrs[2];
attribute2.mod_op = LDAP_MOD_REPLACE;
attribute2.mod_type = L"sn";
attribute2.mod_values = (PWCHAR*)Password;
list_of_attrs[0] = &attribute2;
list_of_attrs[1] = NULL;
wchar_t dnName[100] = { 0 };
char *dn = "CN=Rushali J. Watane,CN=Users,DC=Maestrotek,DC=Local";
mbstowcs(dnName, dn, 100);
PWCHAR dnNameval = (PWCHAR)malloc(sizeof(PWCHAR)* 20);
wcscpy(dnNameval, dnName);
result = ldap_modify_s(ldap, dnNameval, list_of_attrs);
推荐答案
您好,
感谢您在此发帖。
我认为您发布了在错误的论坛上。由于你的平台是wince 8.0操作系统,你可以发布问题
上的target ="_ blank">
以获得更好的支持。
I think that you post on wrong forum. Since your platform is wince 8.0 OS, you could post the issue on wince forum for better support.
我会将此案移至非主题论坛。
I will move the case to off-topic forum.
最佳 此致,
Best Regards,
Hart
这篇关于使用C ++从客户端更改Active Directory用户的密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!