さて、私はこれで何と楽しい旅をしてきたのでしょう。
あなたが抱えている問題は、マシンがサーバーの証明書を有効なものとして受け入れないことです。これに対する簡単な回避策は、ldap.conf ファイルまたは環境変数で行われるチェックを無効にすることです。
/etc/openldap/ldap.conf
( Windows の場合)でファイルを編集するc:\openldap\sysconf\ldap.conf
か、まだ存在しない場合は作成して、次の行を挿入します。
TLS_REQCERT never
LDAPTLS_REQCERT
...または、値で名前が付けられた環境変数を作成できますnever
。
これらのいずれかを実行すると、次のスクリプトが機能しました。
<?php
// Settings
$host = 'server.domain.local';
$port = 389;
$user = 'administrator';
$pass = 'password';
// Connect, set options and bind
$ds = ldap_connect($host, $port);
if (!ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3)) exit('Could not disable referrals');
if (!ldap_set_option($ds, LDAP_OPT_REFERRALS, 0)) exit('Could not disable referrals');
if (!ldap_start_tls($ds)) exit('Could not start TLS');
if (!ldap_bind($ds, $user, $pass)) exit('Bind operation failed');
// A quick list operation to make sure it worked
if (!$result = ldap_list($ds, 'dc=domain,dc=local', 'objectClass=*')) exit('List operation failed');
print_r(ldap_get_entries($ds, $result));
面倒なことに、どちらputenv('LDAPTLS_REQCERT=never');
も機能しません$_ENV['LDAPTLS_REQCERT'] = 'never';
-構成ファイルを作成するか、変数を静的に設定する必要があります。
証明書を検証したい場合は、OpenLDAP を適切に構成する方法についてさらに読む必要があります。
このソース: