-
Notifications
You must be signed in to change notification settings - Fork 7.9k
ext/ldap: Use FCC for rebind_proc callback #17369
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,22 +12,31 @@ require_once('skipifbindfailure.inc'); | |
?> | ||
--FILE-- | ||
<?php | ||
/*** NOTE: THE CALLBACK IS NOT CALLED AS WE DON'T TEST THE REBINDING HAPPENS AS WE NEED MULTIPLE LDAP SERVERS ***/ | ||
|
||
require "connect.inc"; | ||
|
||
function rebind_proc ($ds, $ldap_url) { | ||
global $user; | ||
global $passwd; | ||
global $protocol_version; | ||
function rebind_proc ($ldap, $referral) { | ||
global $user; | ||
global $passwd; | ||
global $protocol_version; | ||
|
||
// required by most modern LDAP servers, use LDAPv3 | ||
ldap_set_option($a, LDAP_OPT_PROTOCOL_VERSION, $protocol_version); | ||
// required by most modern LDAP servers, use LDAPv3 | ||
ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, $protocol_version); | ||
|
||
if (!ldap_bind($a, $user, $passwd)) { | ||
if (!ldap_bind($ldap, $user, $passwd)) { | ||
// Failure | ||
print "Cannot bind"; | ||
} | ||
return 1; | ||
} | ||
// Success | ||
return 0; | ||
} | ||
|
||
$link = ldap_connect_and_bind($uri, $user, $passwd, $protocol_version); | ||
ldap_set_option($link, LDAP_OPT_PROTOCOL_VERSION, 3); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The version option seems pointless? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I took this from the user notes of https://www.php.net/manual/en/function.ldap-set-rebind-proc.php There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay sure, can't harm I guess. |
||
ldap_set_option($link, LDAP_OPT_REFERRALS, true); | ||
|
||
var_dump(ldap_set_rebind_proc($link, "rebind_proc")); | ||
var_dump(ldap_set_rebind_proc($link, null)); | ||
?> | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
--TEST-- | ||
ldap_set_rebind_proc() with a trampoline | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, the test seems kinda pointless, but it would also be a shame to get rid of this effort... |
||
--EXTENSIONS-- | ||
ldap | ||
--SKIPIF-- | ||
<?php | ||
if (!function_exists('ldap_set_rebind_proc')) die("skip ldap_set_rebind_proc() not available"); | ||
require_once('skipifbindfailure.inc'); | ||
?> | ||
--FILE-- | ||
<?php | ||
/*** NOTE: THE TRAMPOLINE IS NOT CALLED AS WE DON'T TEST THE REBINDING HAPPENS AS WE NEED MULTIPLE LDAP SERVERS ***/ | ||
|
||
require "connect.inc"; | ||
|
||
class TrampolineTest { | ||
public function __construct(private $user, private $password, private $protocol_version) {} | ||
public function __call(string $name, array $arguments) { | ||
echo 'Trampoline for ', $name, PHP_EOL; | ||
var_dump(count($arguments)); | ||
if ($name === 'trampolineThrow') { | ||
throw new Exception('boo'); | ||
} | ||
if ($name === 'trampolineWrongType') { | ||
return ['not an int']; | ||
} | ||
// required by most modern LDAP servers, use LDAPv3 | ||
ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, $this->$protocol_version); | ||
if (!ldap_bind($ldap, $this->$user, $this->$password)) { | ||
// Failure | ||
print "Cannot bind"; | ||
return 1; | ||
} | ||
// Success | ||
return 0; | ||
} | ||
} | ||
$o = new TrampolineTest($user, $passwd, $protocol_version); | ||
$callback = [$o, 'trampoline']; | ||
$callbackThrow = [$o, 'trampolineThrow']; | ||
$callbackWrongType = [$o, 'trampolineWrongType']; | ||
|
||
$link = ldap_connect_and_bind($uri, $user, $passwd, $protocol_version); | ||
var_dump(ldap_set_rebind_proc($link, $callback)); | ||
var_dump(ldap_set_rebind_proc($link, null)); | ||
var_dump(ldap_set_rebind_proc($link, $callbackThrow)); | ||
var_dump(ldap_set_rebind_proc($link, null)); | ||
var_dump(ldap_set_rebind_proc($link, $callbackWrongType)); | ||
|
||
var_dump(ldap_unbind($link)); | ||
try { | ||
var_dump(ldap_set_rebind_proc($link, $callback)); | ||
} catch (Throwable $e) { | ||
echo $e::class, ': ', $e->getMessage(), PHP_EOL; | ||
} | ||
|
||
?> | ||
--EXPECT-- | ||
bool(true) | ||
bool(true) | ||
bool(true) | ||
bool(true) | ||
bool(true) | ||
bool(true) | ||
Error: LDAP connection has already been closed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is probably the nightly issue: the condition seems inverted.