使用 samaccountname 修改 AD LDAP 对象

Modifying AD LDAP objects with samaccountname

我有一个可以运行的 php 脚本,但我需要将其更改为使用 AD 帐户 (samaccountname) 而不是此示例中的 CN;

<?php

$base_dn="CN=Peter Parker,OU=Subcontainer,OU=Subcontainer,OU=Container,
DC=domain,DC=com";
$ldapconn = ldap_connect("host.domain.com") or die("Could not connect to LDAP server.");

if ($ldapconn)
{
    $ldapbind = ldap_bind($ldapconn, $ldapusername, $ldappassword);

    if ($ldapbind)
    {
        echo "LDAP bind successful ...";
    }
    else
    {
        echo "LDAP bind failed ...";
    }
}

$newinfo['ipphone']="555";
ldap_modify($ldapconn,$base_dn,$newinfo);
?>

本意是为 AD 中的用户修改 ipphone 对象,但我不能使用 CN,因为此输入对于任务来说不够独特。如果帐户的基本 DN 中的 CN 是用户的描述性名称,我是不是运气不好?

您必须提供 ldap_modify 您要更改的帐户的专有名称 (DN)。没有办法解决这个问题。

如果您一开始只知道 sAMAccountName,那么您可以先在域中搜索帐户,然后从结果中获取 distinguishedName 属性。

要搜索,请使用 ldap_search 过滤器“(sAMAccountName=username)”