[comp.bugs.4bsd] What mode should `whois' be?

earle@smeagol.UUCP (Greg Earle) (12/04/86)

When I run `whois' as root, everything works fine.  When I run `whois' as
any plain user, I get:

whois: bind: Permission denied

Permissions:
-rwxr-xr-x  1 root     staff       49152 Jan 23  1986 /usr/ucb/whois

Should `whois' be setuid root, or is there some other problem involved?

This is on a Sun-3/160M; Sun OS 3.0.
-- 
	Greg Earle		UUCP: sdcrdcf!smeagol!earle; attmail!earle
	JPL			ARPA: elroy!smeagol!earle@csvax.caltech.edu
				      smeagol!earle@usc-oberon.usc.edu
				AT&T: +1 818 354 0876

My mind is a potato field...

bzs@bu-cs.BU.EDU (Barry Shein) (12/05/86)

From: earle@smeagol.UUCP (Greg Earle)
>When I run `whois' as root, everything works fine.  When I run `whois' as
>any plain user, I get:
>
>whois: bind: Permission denied

Yes, whois tries to bind the whois socket as provided by /etc/services
(officially 43.) This requires root priviliges, setuid it if you want it
to work.

You also realize, I hope, that by default it is trying to make an
ARPAnet link across to SRI-NIC, so you'll have to be able to route
there (or specify a local server via -h on the command line.)

It's not a bug. It even works when set up properly.

	-Barry Shein, Boston University

budd@bu-cs.BU.EDU (Philip Budne) (12/05/86)

Funny this should come up Barry.  I just recompiled our copy of
nicname (nee whois) to REMOVE the bind.  The NIC will still talk to
you AND more than one person cane run the program at a time!!

	Phil Budne
	Boston University - (dis)Information Services

steve@mimsy.UUCP (Steve D. Miller) (12/05/86)

AHA!  I looked at the source, and here's the *real* problem:

	struct sockaddr sin;

	sin.sin_family = AF_INET;
	if (bind(&sin, sizeof(sin)) < 0) ...

   It's not trying to bind to any particular port on the local machine;
it just wants the kernel to pick one for it.  Unfortunately, the
kernel does so only if no address is specified (all-zeroes), and this
is specifying a garbage address.

   There are two fixes:

	(1)  Remove the bind() call entirely; the connect() will
	pick a local socket automagically, as Phil Budne (budd@bu-cs)
	stated.

	(2)  stick a "bzero((char *)&sin, sizeof(sin))" just before
	the "sin.sin_family = AF_INET".  It will then bind a proper
	address, and everything will work as advertised.

   Time to send another bug report to Sun...

	-Steve
-- 
Spoken: Steve Miller 	ARPA:	steve@mimsy.umd.edu	Phone: +1-301-454-4251
CSNet:	steve@mimsy 	UUCP:	{seismo,allegra}!mimsy!steve
USPS: Computer Science Dept., University of Maryland, College Park, MD 20742

brunner@sri-spam.istc.sri.com (Thomas Eric Brunner) (12/07/86)

>>whois: bind: Permission denied

>You also realize, I hope, that by default it is trying to make an
>ARPAnet link across to SRI-NIC, so you'll have to be able to route
>there (or specify a local server via -h on the command line.)

Note too that whois occasionally fails, even when one is only tens of
meters "remote" from SRI-NIC, try more than once, or twice, or ...

-- 
Cheers!
/teb 

jordan@ucbarpa.Berkeley.EDU (Jordan Hayes) (12/07/86)

Steve D. Miller <steve@mimsy.UUCP> writes:

	struct sockaddr sin;

	sin.sin_family = AF_INET;
	if (bind(&sin, sizeof(sin)) < 0) ...

[ I assume you mean bind(s, &sin, sizeof(sin)) since bind() takes 3
arguments ]

	It's not trying to bind to any particular port on the local
	machine; it just wants the kernel to pick one for it.
	Unfortunately, the kernel does so only if no address is
	specified (all-zeroes), and this is specifying a garbage
	address.

That's weird ... the 4.3 source says

	struct sockaddr_in	sin;

	sin.sin_family = hp->h_addrtype;
	if (bind(s,&sin, sizeof(sin)) < 0) ...

More portable, but still far from the point -- clients that talk to
Internet Services (I.e., those with RFC's) shouldn't bind the socket
locally -- the server should do that for you. You can't enforce the
protected ports across non-BSD systems. You certainly shouldn't try to
with whois ...

/jordan