[23315] in Source-Commits

home help back first fref pref prev next nref lref last post

/svn/athena r22971 - trunk/athena/bin/hostinfo

daemon@ATHENA.MIT.EDU (rbasch@MIT.EDU)
Sat May 10 12:55:58 2008

Date: Sat, 10 May 2008 12:55:27 -0400 (EDT)
From: rbasch@MIT.EDU
Message-Id: <200805101655.MAA24726@drugstore.mit.edu>
To: source-commits@MIT.EDU
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Author: rbasch
Date: 2008-05-10 12:55:27 -0400 (Sat, 10 May 2008)
New Revision: 22971

Modified:
   trunk/athena/bin/hostinfo/hostinfo.pl
Log:
* athena/bin/hostinfo/hostinfo.pl: Use the default name server(s)
  when no server is specified on the command line, instead of
  assuming that the local host is running a name server.
  Accordingly, do not quote the server argument in shell command
  lines; the check for a valid host name should prevent any
  passing of shell metacharacters.


Modified: trunk/athena/bin/hostinfo/hostinfo.pl
===================================================================
--- trunk/athena/bin/hostinfo/hostinfo.pl	2008-05-10 01:01:35 UTC (rev 22970)
+++ trunk/athena/bin/hostinfo/hostinfo.pl	2008-05-10 16:55:27 UTC (rev 22971)
@@ -22,7 +22,7 @@
 $hostprog = "/usr/athena/bin/host";
 
 $long_output = $show_host = $show_addr = $show_hinfo = $show_mx = 1;
-$server = "localhost";
+$server = "";
 
 sub usage {
     print STDERR "Usage: hostinfo <options> <host-names-or-addresses>\n";
@@ -62,15 +62,15 @@
 	$show_hinfo = $show_mx = 0;
 	next;
     } elsif ($arg eq "-ns") {
-	if ($arg =~ /[^a-zA-Z0-9.-]/) {
-	    print STDERR "Bad hostname '$arg'.\n";
-	    next;
+	$server = shift(@ARGV) || &usage();
+	if ($server =~ /[^a-zA-Z0-9.-]/) {
+	    print STDERR "Bad hostname '$server'.\n";
+	    &usage();
 	}
-	$server = shift(@ARGV);
 	system "$hostprog -t a $server > /dev/null 2>&1";
 	if ($?) {
 	    print STDERR "No such host '$server'.\n\n";
-	    $server = "localhost";
+	    $server = "";
 	}
 	next;
     } elsif ($arg =~ /^-/) {
@@ -86,7 +86,7 @@
     @addr = @mx = ();
 
     if ($show_mx) {
-	open(HOST, "$hostprog -t mx '$arg' '$server' 2>&1 |");
+	open(HOST, "$hostprog -t mx '$arg' $server 2>&1 |");
 	while (<HOST>) {
 	    if (/mail is handled .*by [ \d]*([^ ]*)$/) {
 		push(@mx, $1);
@@ -96,7 +96,7 @@
     }
     chomp (@mx);
 
-    open(HOST, "$hostprog -t a '$arg' '$server' 2>&1 |");
+    open(HOST, "$hostprog -t a '$arg' $server 2>&1 |");
     while (<HOST>) {
 	if (/(.*) has address (.*)$/) {
 	    $host = $1;
@@ -124,7 +124,7 @@
     }
 
     if ($show_hinfo) {
-	open(HOST, "$hostprog -t hinfo '$host' '$server' 2>&1 |");
+	open(HOST, "$hostprog -t hinfo '$host' $server 2>&1 |");
 	while (<HOST>) {
 	    if (/host information (.*)$/) {
 		$hinfo = $1;


home help back first fref pref prev next nref lref last post