2016-08-23 29 views
2

我想在OpenLDAP中添加一個新用戶,並編寫以下方法來創建一個新用戶。在調用此方法時,必須通過以下變量:如何通過PHP在OpenLDAP中添加新用戶?

  • $ldapconn:由ldap_connect返回。
  • $username:我想創建的用戶名。
  • $password:登錄帳戶的密碼。

public static function createNewUser($ldapconn, $username, $password) { 
    if (!$ldapconn) { return false; } 
    require_once("LDAPConfigurator.php"); 
    $r = ldap_bind($ldapconn, "cn=admin,dc=test,dc=com", "12345X"); 

    // Prepare data 
    $info["cn"]="John Jones"; 
    $info["sn"]="Jones"; 
    $info["mail"]="[email protected]"; 
    $info["objectclass"]="person"; 

    // Add data to directory 
    $r = ldap_add($ldapconn, "cn=John Jones,dc=test,dc=com", $info); 

    return true; 
} 

LDAP連接$ldapconn將這種方法以外被關閉。


準備好的數據從this document複製而來。

我希望它可以在phpLDAPadmin中的「dc = test,dc = com」下爲我顯示一個新的子項。但最後的結果卻是一無所獲出現,並顯示我:

Warning: ldap_add(): Add: Object class violation in /var/www/html/test.php on line 23 

我想請問如何解決這個問題(Object class violation)?

回答

1

「inetOrgPerson」是inetorgperson.schema定義的OpenLDAP中的人員條目的默認對象類。所以,你需要做的,

$info["objectclass"]="inetOrgPerson"; 

如果你想使用自定義的對象類,如「人」,你需要在架構擴展爲inetOrgPerson。

+0

如何集成'$ username'和'$ password'以允許用戶登錄任何openldap客戶端linux機器? – Casper

+0

@CasperLI你的意思是「整合$用戶名和$密碼」? – Roshith

相關問題