我创建了一个简单的函数,可以调用该函数以在 Active Directory 中创建全局分发组
<?php
function ldap_createGroup($object_name, $dn, $members, $ldap_conn)
{
$addgroup_ad['cn']="$object_name";
$addgroup_ad['objectClass'][0] = "top";
$addgroup_ad['objectClass'][1] ="group";
$addgroup_ad['groupType']="2";
$addgroup_ad['member']=$members;
$addgroup_ad["sAMAccountName"] =$object_name;
ldap_add($ldap_conn,$dn,$addgroup_ad);
if(ldap_error($ldap_conn) == "Success")
return true;
else
return false;
}
?>
您可以使用以下代码调用此函数
<?php
$ldap_conn = ldap_bind();
$object_name="Test Group";
$dn="CN=".$object_name.",OU=PathToAddGroupTo,OU=All Users,DC=YOURDOMAIN,DC=COM";
$members[] ="CN=User1,OU=PathToAddGroupTo,OU=All Users,DC=YOURDOMAIN,DC=COM";
$members[] ="CN=User2,OU=PathToAddGroupTo,OU=All Users,DC=YOURDOMAIN,DC=COM";
ldap_createGroup($object_name, $dn, $members, $ldap_conn);
?>
我创建的另一个函数是 ldap_bind(),它可以用来绑定到 LDAP 服务器
<?php
function ldap_bind()
{
$ldap_addr = '192.168.1.1'; $ldap_conn = ldap_connect($ldap_addr) or die("Couldn't connect!");
ldap_set_option($ldap_conn, LDAP_OPT_PROTOCOL_VERSION, 3);
$ldap_rdn = "domain_name\\user_account";
$ldap_pass = "user_password";
$flag_ldap = ldap_bind($ldap_conn,$ldap_rdn,$ldap_pass);
return $ldap_conn;
}
?>