PHP ldap_modify访问不足

时间:2012-10-25 22:03:59

标签: php ldap openldap

我使用ldap_modify与OpenLDAP 2.4.32和PHP 5.4.6获取的访问错误不足。

提供错误的php函数如下所示:

function set_user($dn, $password, $data)
{
  /* This function sets the users infomation */

  // Get Configuration Items
  $ldapServer = $this->config->item('ldapServer');
  $ldapDCRoot = $this->config->item('ldapDCRoot');


  // Connect to LDAP
  $ldapConnection = ldap_connect($ldapServer);

  if($ldapConnection)
  {
    $r = ldap_bind($ldapConnection, $dn, $password);
    if ($r)
    {
      // Bind completed successfully
      $r = ldap_modify($ldapConnection, $dn, $data);
      return True;
    }
    die("Unsuccessful Bind");
  }
  die("Can't connect to LDAP");
}

$ dn是用户尝试更改其信息及密码的完整DN。 $ data是他们正在更新的值,现在数据只包含要更改$ data ['mobile'] =“newPhoneNumber”的电话号码。除了实际上从未真正写过数据之外,这一切似乎都在起作用。

openldap文件包含在下面,因为您可以看到ACL说我应该可以写入它。

include     /etc/openldap/schema/corba.schema
include     /etc/openldap/schema/core.schema
include     /etc/openldap/schema/cosine.schema
include     /etc/openldap/schema/duaconf.schema
include     /etc/openldap/schema/dyngroup.schema
include     /etc/openldap/schema/inetorgperson.schema
include     /etc/openldap/schema/java.schema
include     /etc/openldap/schema/misc.schema
include     /etc/openldap/schema/nis.schema
include     /etc/openldap/schema/openldap.schema
include     /etc/openldap/schema/ppolicy.schema
include     /etc/openldap/schema/collective.schema

allow bind_v2

pidfile     /var/run/openldap/slapd.pid
argsfile    /var/run/openldap/slapd.args

TLSCertificateFile /etc/pki/tls/certs/slapd.pem
TLSCertificateKeyFile /etc/pki/tls/certs/slapd.pem

access to *
    by self write
    by users read
    by anonymous auth


database    bdb
suffix      "dc=example,dc=com"
checkpoint  1024 15
rootdn      "cn=manager,dc=example,dc=com"
rootpw          REDACTED

directory   /var/lib/ldap

index objectClass                       eq,pres
index ou,cn,mail,surname,givenname      eq,pres,sub
index uidNumber,gidNumber,loginShell    eq,pres
index uid,memberUid                     eq,pres,sub
index nisMapName,nisMapEntry            eq,pres,sub

问题是为什么PHP不能更新值而不是访问错误?

2 个答案:

答案 0 :(得分:2)

要调试您的问题,我建议您使用命令行工具 ldapmodify 发出相同的请求。您可能需要将其安装到您的系统中(Redhat openldap-clients,Debian slapd)。

LDAP Utilities

通过设置调试级别-d,您可以获得比php库提供的有关您的调用返回不充分访问错误的原因的更多信息。

虽然我从未使用 ldapmodify 执行此操作,但我已将其与 ldapsearch 一起使用并取得了巨大成功。所以可能需要一些搜索或ldapmodify --help来弄清楚如何使用它。

我想这个命令看起来像这样:

ldapmodify -d 7 -h ldap.server.com -D bind_dn -w bind_password -f /tmp/entrymods

答案 1 :(得分:0)

我在更改Active Directory密码时遇到了一些问题。也许这也有助于其他人:

第一:您需要安全连接,否则LDAP会拒绝更改密码。

$this->ldap_ds = ldap_connect($this->hostname);
//some protocol options
ldap_set_option($this->ldap_ds, LDAP_OPT_REFERRALS, 0);
ldap_set_option($this->ldap_ds, LDAP_OPT_PROTOCOL_VERSION, 3);

// start secure connection on port 636
ldap_start_tls($this->ldap_ds);

第二:在我的系统上,我在启动安全连接时出现问题,我现在解决了这个问题,编辑/etc/ldap/ldap.conf

# TLS_CACERT    /etc/ssl/certs/ca-certificates.crt
TLS_REQCERT never

3rd:对于活动目录,我们使用了unicodePwd字段而不是userPassword字段。此字段需要Unicode中的String。

$entry["unicodePwd"] = iconv("UTF-8", "UTF-16LE", '"' . $newPassword . '"');

第4名:要更改密码,您无法使用modify,而应使用mod_replace功能。

ldap_mod_replace($ldapConnection, $user_dn, $entry);
相关问题