Skip to content

Commit dc7e536

Browse files
author
Côme Bernigaud
committed
Merge branch 'pull-request/2536' into PHP-7.0
* pull-request/2536: ext/ldap/test: Test that ldap_connect() uses defaults from ldap.conf (openldap) ext/ldap: Allow default host from ldap.conf to work.
2 parents 46bb35a + 49d1cdc commit dc7e536

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

ext/ldap/ldap.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ PHP_FUNCTION(ldap_connect)
366366
{
367367
int rc = LDAP_SUCCESS;
368368
char *url = host;
369-
if (!ldap_is_ldap_url(url)) {
369+
if (url && !ldap_is_ldap_url(url)) {
370370
int urllen = hostlen + sizeof( "ldap://:65535" );
371371

372372
if (port <= 0 || port > 65535) {
@@ -376,7 +376,7 @@ PHP_FUNCTION(ldap_connect)
376376
}
377377

378378
url = emalloc(urllen);
379-
snprintf( url, urllen, "ldap://%s:%ld", host ? host : "", port );
379+
snprintf( url, urllen, "ldap://%s:%ld", host, port );
380380
}
381381

382382
#ifdef LDAP_API_FEATURE_X_OPENLDAP
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
ldap_connect() - Connection using default host from openldap's ldap.conf
3+
--CREDITS--
4+
David Caldwell <david@galvanix.com>
5+
--SKIPIF--
6+
<?php
7+
require_once('skipif.inc');
8+
ob_start();
9+
phpinfo();
10+
if (!preg_match("/vendor name => openldap/i", ob_get_clean()))
11+
die("skip not openldap");
12+
?>
13+
--FILE--
14+
<?php
15+
$conf=tempnam("/tmp","ldap.conf");
16+
file_put_contents($conf, "uri ldaps://example.com:3141/");
17+
putenv("LDAPCONF=$conf");
18+
$link = ldap_connect();
19+
ldap_get_option($link, LDAP_OPT_HOST_NAME, $host);
20+
var_dump($host);
21+
unlink($conf);
22+
?>
23+
===DONE===
24+
--EXPECTF--
25+
string(16) "example.com:3141"
26+
===DONE===

0 commit comments

Comments
 (0)