summaryrefslogtreecommitdiffstats
path: root/sbin
diff options
context:
space:
mode:
authorimp <imp@FreeBSD.org>1997-03-02 06:32:42 +0000
committerimp <imp@FreeBSD.org>1997-03-02 06:32:42 +0000
commitae1fecd92ff5ca8a458e9aea38a1a8e34ce18932 (patch)
treefe42ae450fdb908fec487ec8ec504391c270c6bc /sbin
parent4d22a4eaa41eb8752410af0ae776ec87a874cc35 (diff)
downloadFreeBSD-src-ae1fecd92ff5ca8a458e9aea38a1a8e34ce18932.zip
FreeBSD-src-ae1fecd92ff5ca8a458e9aea38a1a8e34ce18932.tar.gz
1) Fix usage to match convention and manual. Fix manual to match usage.
2) Must be root to run preload (OpenBSD ping.c 1.8) 3) Don't print all replies unless verbose and root (from idea in OpenBSD ping.c 1.10 and 1.11) to avoid leaking information available only to root. 4) Remove unused h: from option string to getopt. 5) Make the compiler happy with exit(0) (Lite-2?) Reviewed by: Dan Cross <tenser@spitfire.ecsel.psu.edu> Good candidate for 2.2 and 2.1 (as are many of the 1.17 changes).
Diffstat (limited to 'sbin')
-rw-r--r--sbin/ping/ping.813
-rw-r--r--sbin/ping/ping.c23
2 files changed, 26 insertions, 10 deletions
diff --git a/sbin/ping/ping.8 b/sbin/ping/ping.8
index c42272c..11199b5 100644
--- a/sbin/ping/ping.8
+++ b/sbin/ping/ping.8
@@ -30,7 +30,7 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)ping.8 8.2 (Berkeley) 12/11/93
-.\" $Id: ping.8,v 1.7 1997/02/22 14:33:06 peter Exp $
+.\" $Id: ping.8,v 1.8 1997/03/01 20:19:18 wollman Exp $
.\"
.Dd March 1, 1997
.Dt PING 8
@@ -42,15 +42,20 @@
packets to network hosts
.Sh SYNOPSIS
.Nm ping
-.Op Fl adfnqrvLRQ
+.Op Fl QRadfnqrv
.Op Fl c Ar count
.Op Fl i Ar wait
-.Op Fl I Ar interface
.Op Fl l Ar preload
.Op Fl p Ar pattern
.Op Fl s Ar packetsize
-.Op Fl T Ar ttl
+[
.Ar host
+|
+.Op Fl L
+.Op Fl I Ar interface
+.Op Fl T Ar ttl
+.Ar mcast-group
+]
.Sh DESCRIPTION
.Nm Ping
uses the
diff --git a/sbin/ping/ping.c b/sbin/ping/ping.c
index bb9be21..afb34abc 100644
--- a/sbin/ping/ping.c
+++ b/sbin/ping/ping.c
@@ -45,7 +45,7 @@ static const char copyright[] =
static char sccsid[] = "@(#)ping.c 8.1 (Berkeley) 6/5/93";
*/
static const char rcsid[] =
- "$Id$";
+ "$Id: ping.c,v 1.17 1997/03/01 20:19:18 wollman Exp $";
#endif /* not lint */
/*
@@ -205,7 +205,7 @@ main(argc, argv)
preload = 0;
datap = &outpack[8 + sizeof(struct timeval)];
- while ((ch = getopt(argc, argv, "I:LQRT:c:adfh:i:l:np:qrs:v")) != -1) {
+ while ((ch = getopt(argc, argv, "I:LQRT:c:adfi:l:np:qrs:v")) != -1) {
switch(ch) {
case 'a':
options |= F_AUDIBLE;
@@ -249,6 +249,11 @@ main(argc, argv)
if (*ep || ep == optarg || ultmp > INT_MAX)
errx(EX_USAGE,
"invalid preload value: `%s'", optarg);
+ if (getuid()) {
+ errno = EPERM;
+ err(EX_NOPERM, "-l flag");
+ }
+ options |= F_FLOOD;
preload = ultmp;
break;
case 'L':
@@ -465,6 +470,7 @@ main(argc, argv)
}
finish(0);
/* NOTREACHED */
+ exit(0); /* Make the compiler happy */
}
/*
@@ -653,6 +659,10 @@ pr_pack(buf, cc, from)
* See if it's a reply to something that we sent.
* We can compare IP destination, protocol,
* and ICMP type and ID.
+ *
+ * Only print all the error messages if we are running
+ * as root to avoid leaking information not normally
+ * available to those not running as root.
*/
#ifndef icmp_data
struct ip *oip = &icp->icmp_ip;
@@ -661,7 +671,7 @@ pr_pack(buf, cc, from)
#endif
struct icmp *oicmp = (struct icmp *)(oip + 1);
- if ((options & F_VERBOSE) ||
+ if (((options & F_VERBOSE) && getuid() == 0) ||
(!(options & F_QUIET2) &&
(oip->ip_dst.s_addr ==
((struct sockaddr_in *)&whereto)->sin_addr.s_addr) &&
@@ -1085,7 +1095,7 @@ pr_addr(ina)
struct in_addr ina;
{
struct hostent *hp;
- static char buf[80];
+ static char buf[16 + 3 + MAXHOSTNAMELEN];
if ((options & F_NUMERIC) ||
!(hp = gethostbyaddr((char *)&ina, 4, AF_INET)))
@@ -1157,9 +1167,10 @@ static void
usage(argv0)
const char *argv0;
{
- warnx("usage:");
+ if (strrchr(argv0,'/'))
+ argv0 = strrchr(argv0,'/') + 1;
fprintf(stderr,
- "\t%s [-QRadfnqrv] [-c count] [-i wait] [-l preload] "
+ "usage: %s [-QRadfnqrv] [-c count] [-i wait] [-l preload] "
"[-p pattern]\n\t\t[-s packetsize] "
"[host | [-L] [-I iface] [-T ttl] mcast-group]\n",
argv0);
OpenPOWER on IntegriCloud