【发布时间】:2012-12-10 07:14:55
【问题描述】:
我已经为此困扰了几天。我尝试了各种解决方案均无济于事。请帮忙...
问题:我们有两个域控制器,它们不在我们的管理之下。我们能够通过端口 389 上的 LDAP 进行连接,但无法通过端口 636 安全地连接。
我们正在开发一个系统,允许使用多种自助服务设施,其中之一是密码恢复工具。直到重置用户密码为止。
我找到了一些代码via the PHP manual,它似乎可以满足我们的需要,但似乎无法让它发挥作用。
这是我到目前为止的代码
if ($caller==="change"){
if (($newPword1 === NULL)||($newPword1 === "" )){ return false;}
if (($newPword2 === NULL)||($newPword2 === "" )){ return false;}
if ($newPword1 != $newPword2) {
$result["ERROR"]="1";
$result["DETAILS"]="Your new password and the confirmation must match!";
exit();
}
try {
$adldap = new adLDAP();
} catch (adLDAPException $e) {
$result["ERROR"]="1";
$result["DETAILS"]="An error occurred in adLDAP";
echo json_encode($result);
exit();
}
$userinfo = $adldap->user()->info($username, array("givenname","dn","lockouttime"));
$res = $userinfo[0]["lockouttime"];
$userDN = $userinfo[0]["dn"];
$firstName = $userinfo[0]["givenname"];
$authUser = $adldap->authenticate($username,$currentPword);
if ($authUser){
try {
$adminUsername = $domain."\\".$adminUsername;
$srvDN = "LDAP://".$server."/";
try {
$ADSI = new COM("LDAP:");
} catch (exception $e){
$result["ERROR"]="1";
$result["ERRORmsg"]=$e->getMessage();
echo json_encode($result);
exit();
}
try {
$user = $ADSI->OpenDSObject($srvDN.$userDN, $adminUsername, $adminPassword, 1);
} catch (exception $e){
$result["ERROR"]="2";
$result["ERRORmsg"]= $e->getMessage();
echo json_encode($result);
exit();
}
try { //set password
if ($user){
$result["object"]="Success";
} else {
$result["object"]="Failed";
}
$user->SetPassword($newPword1); //line:114 -> error occurring on this line
$user->SetInfo();
$result["ERROR"]="0";
$result["DETAILS"]="Thank you $firstName[0]<br><strong>Your password has been changed</strong><br><br>This may take up to 30 minutes to take effect depending on your location";
} catch (exception $e) {
$result["ERROR"]="3";
$result["ERRORmsg"]=$e." - ".$e->getMessage();
$result["DETAILS"]="An Error Occurred.";
}
unset($user);
unset($ADSI);
} catch (exception $e){
$result["ERROR"]="1";
$result["DETAILS"]="An Error Occurred in the ADSI COM";
echo json_encode($result);
exit();
}
} else {
if ($res[0] != "0"){
$result["ERROR"]="1";
$result["DETAILS"]="Im sorry $firstName[0].<br>Your account is now locked. Please contact the IT Service Desk for advice";
} else {
$result["ERROR"]="1";
$result["DETAILS"]="Im sorry $firstName[0].<br>Your current password is incorrect";
}
}
在测试中$result["object"] 返回“成功”。但是代码似乎在$user->SetPassword($newPword1); 行上失败了。
返回的错误是:
ERROR -> "3"
object -> "Success"
ERRORmsg -> "exception 'com_exception' with message '<b>Source:</b> Unknown<br/><b>Description:</b> Unknown' in C:\inetpub\wwwroot\<path>\<filename>.php:114
Stack trace:
#0 C:\inetpub\wwwroot\<path>\<filename>.php(114): variant->SetPassword('P@ssw0rd')
#1 {main} - <b>Source:</b> Unknown<br/><b>Description:</b> Unknown"
DETAILS -> "An Error Occurred."
以上代码位于 IIS Web 服务器上的 php 文档中,用户可通过 https 浏览页面调用该文档
您能提供任何建议或指导吗?
【问题讨论】:
-
我很确定 AD 对于不在明文 LDAP 上设置密码非常挑剔。您需要它们来启用基于 LDAP 的 SSL。
-
你试过phpLdapAdmin吗?
-
2012 年 12 月 29 日 16:46 更新 我已经能够证明
new COM("LDAP:")成功初始化和$ADSI->OpenDSObject成功打开 AD 对象。我已尝试针对其他用户 AD 帐户,但脚本在同一行失败 **2012 年 12 月 29 日 17:57 ** 已将$user->SetPassword($newPword1);替换为$user->Put("pwdLastSet",0);并成功更新了相应的 AD 属性。所以这表明 ADSI 连接正在工作 -
有谁知道 GSS-API/Kerberos 是否允许我通过与 ldap_sasl 绑定来执行此操作?
标签: php iis active-directory adsi change-password