SUMMARY: sendmail and getpeername() on fd 0

From: Jochen Bern (bern@penthesilea.uni-trier.de)
Date: Mon Apr 19 1999 - 10:55:06 CDT


Original Question:

> while fiddling with the sendmail setups, I noticed some odd behaviour
> with getpeername(0, ...) both on SunOS and Solaris. sendmail's idea
> of how this should turn out is a return value of -1 and an errno of
> ENOTSOCK, which is caught (in sendmail's src/daemon.c:getauthinfo(),
> if you want to check there) and causes the $_ macro (verified sender)
> to be set to "user@localhost" [...] Now watch what the SUNs do:
   
   (Short short version: SunOS correctly returns ENOTSOCK except for
   'cat File | Prog', then sometimes returns OK, sometimes ENOTCONN
   = socket not connected; Solaris 2.4 correctly returns ENOTSOCK for
   'Prog < File', but errno's not mentioned in the manpage for 'Prog'
   and 'cat File | Prog'.)

Addendum:

   I forgot to mention that sendmail seems to catch the SunOS/cat|Prog/
   OK case correctly, too, because the "remote host name" returned has
   length 0. Plus two other special cases I didn't see actually occur
   in my tests (maybe meant for other OSes or uses).

Solution:

   Upgrade to 2.6 if possible.
   
   If you have to stay with SunOS, do '(cat File ; sleep 1) | Prog'
   (or longer) instead of 'cat File | Prog'.
   
   (Live with it else.)

Background info:

   Sockets were in fact broken WRT this kind of situation in pre-2.6
   Solaris; SUN redid sockets for 2.6 more or less from scratch, and
   I received confirmation that my test programs run fine on 2.6
   through 2.8.
   
   The problem with SunOS is best summarized by Per Hedeland:
> In SunOS 4, as in most if not all BSD or BSD-derived Unices, pipes are
> implemented using socketpair(), i.e. they are in fact sockets. The
> reason you get the ENOTCONN is probably because by the time sendmail
> gets around to do the getpeername(), 'cat' has already written its
> output and exited - i.e. the socket is no longer connected. This also
> means that sendmail AFAIK can't reliably find out what was at the other
> end or that the socket was in fact "local" [...].

Thanks to:

   Kari E. Hurtta
   John Beck
   Casper Dik <casper@holland.sun.com>
   Per Hedeland

Kind regards,
                                                                J. Bern

-- 
  /\  /""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""\
 /  \/ bern@uni-trier.de/bern@ti.uni-trier.de| P.O. box 1203 | Ham: \/\
/ J. \ (Accepting PGP, MIME, SUNAttachments) | D-54202 Trier | DD0KZ/  \
\Bern/ finger bern@informatik.uni-trier.de       | Email autoreply  \  /
 \  /\ http://www.informatik.uni-trier.de/~bern/ | on subject '##'  /\/
  \/  \____________________________________________________________/



This archive was generated by hypermail 2.1.2 : Fri Sep 28 2001 - 23:13:18 CDT