Skip to content

Commit 1bb295e

Browse files
author
Côme Bernigaud
committed
Merge branch 'PHP-7.0' into PHP-7.1
* PHP-7.0: ext/ldap/test: Test that ldap_connect() uses defaults from ldap.conf (openldap) ext/ldap: Allow default host from ldap.conf to work. Conflicts: ext/ldap/ldap.c
2 parents b11393f + dc7e536 commit 1bb295e

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
@@ -415,7 +415,7 @@ PHP_FUNCTION(ldap_connect)
415415
{
416416
int rc = LDAP_SUCCESS;
417417
char *url = host;
418-
if (!ldap_is_ldap_url(url)) {
418+
if (url && !ldap_is_ldap_url(url)) {
419419
int urllen = hostlen + sizeof( "ldap://:65535" );
420420

421421
if (port <= 0 || port > 65535) {
@@ -425,7 +425,7 @@ PHP_FUNCTION(ldap_connect)
425425
}
426426

427427
url = emalloc(urllen);
428-
snprintf( url, urllen, "ldap://%s:" ZEND_LONG_FMT, host ? host : "", port );
428+
snprintf( url, urllen, "ldap://%s:" ZEND_LONG_FMT, host, port );
429429
}
430430

431431
#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 <[email protected]>
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)