Skip to content
Snippets Groups Projects
Commit 0d017361 authored by Olav Morken's avatar Olav Morken
Browse files

ldapstatus: Check wheter hostname exists before attempting to connect.

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@1755 44740490-163a-0410-bde0-09ae8108e29a
parent b7fce249
No related branches found
No related tags found
No related merge requests found
...@@ -78,15 +78,24 @@ class sspmod_ldapstatus_Tester { ...@@ -78,15 +78,24 @@ class sspmod_ldapstatus_Tester {
/** /**
* TCP ping implemented in php. * TCP ping implemented in php.
* Warning: Will return Success if hostname is illegal. should be fixed.
* *
* @param $host Hostname * @param string $host Hostname
* @param $port Port number (TCP) * @param int $port Port number (TCP)
*/ */
public function phpping($host, $port) { public function phpping($host, $port) {
assert('is_string($host)');
assert('is_int($port)');
$this->log('ldapstatus phpping(): ping [' . $host . ':' . $port . ']' ); $this->log('ldapstatus phpping(): ping [' . $host . ':' . $port . ']' );
$ips = gethostbynamel($host);
if ($ips === FALSE) {
return array(FALSE, 'Unable to look up hostname ' . $host . '.');
}
if (count($ips) === 0) {
return array(FALSE, 'No IP address found for host ' . $host . '.');
}
$timeout = 1.0; $timeout = 1.0;
$socket = @fsockopen($host, $port, $errno, $errstr, $timeout); $socket = @fsockopen($host, $port, $errno, $errstr, $timeout);
if ($socket) @fclose($socket); if ($socket) @fclose($socket);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment