php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #79637 ldap_connect ignoring port
Submitted: 2020-05-26 19:30 UTC Modified: 2020-05-27 10:26 UTC
From: bugmenot at bfskm dot 33mail dot com Assigned: cmb (profile)
Status: Not a bug Package: LDAP related
PHP Version: 7.4.6 OS: Linux/ANY
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: bugmenot at bfskm dot 33mail dot com
New email:
PHP Version: OS:

 

 [2020-05-26 19:30 UTC] bugmenot at bfskm dot 33mail dot com
Description:
------------
It turned out that the ldap port argument from ldap_connect($URI,intval(1234)
) was ignored , and the port set in URI made it possible 

( more info here : https://github.com/glpi-project/glpi/issues/7316 )

Test script:
---------------
<?php
//there is a server with ssl on port 6366
// SETTING PORT IN LDAP URL 
$ldaphost = "ldaps://brother.hood.local:6636";
$ldapUsername  = "uid=realuser,cn=Users,dc=hood,dc=local";
$ldapPassword = "ARealUsersPassword";
$ldapUsername  = "cn=inventory_hq_hood_systems,cn=computers,dc=hood,dc=local";
$ldapPassword = "IB3t0nlyGøD_Y0urMøm_AndBillGatesNowMyPassWordIs_TotallyInsecure";

ldap_set_option(NULL, LDAP_OPT_DEBUG_LEVEL, 7);
//FAILS:
//$ds = ldap_connect($ldaphost,intval(6366));
//WORKS
$ds = ldap_connect($ldaphost);
if (!$ds) { echo "No Connection";}


if(!ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3)){
print "Could not set LDAPv3\r\n";
}
else {
   ldap_set_option($ldapconn, LDAP_OPT_REFERRALS, 0);
//  if (!@ldap_start_tls($ds)) {echo "No Starttls";}

// now we need to bind to the ldap server
$bth = ldap_bind($ds, $ldapUsername, $ldapPassword) or die("\r\nCould not connect to LDAP server\r\n");
}

?>

Expected result:
----------------
connect to the port given on second argument

Actual result:
--------------
connects to default port 389

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-05-26 19:34 UTC] bugmenot at bfskm dot 33mail dot com
-: bf at kosmoskosmos dot de +: bugmenot at bfskm dot 33mail dot com -Package: *Network Functions +Package: LDAP related
 [2020-05-26 19:34 UTC] bugmenot at bfskm dot 33mail dot com
...
 [2020-05-27 10:26 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2020-05-27 10:26 UTC] cmb@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

ldap_connect() is "overloaded"; if you call it with two parameters
(which is discouraged), the first parameter has to be the
hostname (not an URI).
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed May 21 16:01:27 2025 UTC