perl/modules/W3C/LinkChecker/bin checklink,4.8,4.9

Update of /sources/public/perl/modules/W3C/LinkChecker/bin
In directory hutz:/tmp/cvs-serv17507/bin

Modified Files:
	checklink 
Log Message:
Make Net::IP and other modules required for restricting access to
private IP addresses optional.


Index: checklink
===================================================================
RCS file: /sources/public/perl/modules/W3C/LinkChecker/bin/checklink,v
retrieving revision 4.8
retrieving revision 4.9
diff -u -d -r4.8 -r4.9
--- checklink	12 Oct 2004 21:54:11 -0000	4.8
+++ checklink	6 Nov 2004 11:39:28 -0000	4.9
@@ -92,9 +92,6 @@
 use HTML::Parser    3.00 qw();
 use HTTP::Request        qw();
 use HTTP::Response       qw();
-use Net::hostent         qw(gethostbyname);
-use Net::IP              qw();
-use Socket               qw(inet_ntoa);
 use Time::HiRes          qw();
 use URI                  qw();
 use URI::Escape          qw();
@@ -214,6 +211,22 @@
   );
 undef $cmdline;
 
+unless ($Opts{Allow_Private_IPs}) {
+  eval {
+    require Net::IP;
+    require Socket;
+    Socket->import('inet_ntoa');
+    require Net::hostent;
+  };
+  if ($@) {
+    die <<".EOF.";
+Allow_Private_IPs is false; this feature requires the Net::IP, Socket, and
+Net::hostent modules:
+$@
+.EOF.
+  }
+}
+
 # Global variables
 # What is our query?
 my $query;
@@ -1778,19 +1791,19 @@
 sub ip_allowed ($)
 {
   my ($uri) = @_;
+  return undef if $Opts{Allow_Private_IPs}; # Short-circuit
+
   my $hostname = undef;
   eval { $hostname = $uri->host() }; # Not all URIs implement host()...
   return undef unless $hostname;
 
   my $addr = my $iptype = my $resp = undef;
-  if (my $host = gethostbyname($hostname)) {
+  if (my $host = Net::hostent::gethostbyname($hostname)) {
     $addr = inet_ntoa($host->addr()) if $host->addr();
     if ($addr && (my $ip = Net::IP->new($addr))) {
       $iptype = $ip->iptype();
     }
   }
-  $iptype = 'PUBLIC'
-    if ($iptype && $iptype eq 'PRIVATE' && $Opts{Allow_Private_IPs});
   if ($iptype && $iptype ne 'PUBLIC') {
     $resp = HTTP::Response->new(403,
     'Checking non-public IP address disallowed by link checker configuration');

Received on Saturday, 6 November 2004 11:39:30 UTC