Revision: 1755
Author: olavmrk
Date: Tue Sep 15 01:30:46 2009
Log: ldapstatus: Check wheter hostname exists before attempting to connect.
http://code.google.com/p/simplesamlphp/source/detail?r=1755

Modified:
  /trunk/modules/ldapstatus/lib/Tester.php

=======================================
--- /trunk/modules/ldapstatus/lib/Tester.php    Mon Mar  2 03:46:21 2009
+++ /trunk/modules/ldapstatus/lib/Tester.php    Tue Sep 15 01:30:46 2009
@@ -78,15 +78,24 @@

        /**
         * TCP ping implemented in php.
-        * Warning: Will return Success if hostname is illegal. should be fixed.
         *
-        * @param $host Hostname
-        * @param $port Port number (TCP)
+        * @param string $host Hostname
+        * @param int $port Port number (TCP)
         */
        public function phpping($host, $port) {
-
+               assert('is_string($host)');
+               assert('is_int($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;
                $socket = @fsockopen($host, $port, $errno, $errstr, $timeout);
                if ($socket) @fclose($socket);

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"simpleSAMLphp commits" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/simplesamlphp-commits?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to