我使用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");
}
Run Code Online (Sandbox Code Playgroud)
$ 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
Run Code Online (Sandbox Code Playgroud)
问题是为什么PHP不能更新值而不是访问错误?
要调试您的问题,我建议使用命令行工具ldapmodify发出相同的请求。您可能需要将其安装到您的系统(Redhat openldap-clients
、Debian slapd
)。
通过设置调试级别,-d
您有望获得比 php 库提供的更多信息,了解您的调用返回访问不足错误的原因。
虽然我从未使用ldapmodify执行过此操作,但我将其与ldapsearch一起使用并取得了巨大成功。因此,可能需要一些搜索或ldapmodify --help
弄清楚如何使用它。
我想该命令看起来像这样:
ldapmodify -d 7 -h ldap.server.com -D bind_dn -w bind_password -f /tmp/entrymods
Run Code Online (Sandbox Code Playgroud)