*** conf.h.orig	Tue Mar 31 16:00:07 1992
--- conf.h	Tue Mar 31 16:01:40 1992
***************
*** 92,97 ****
--- 92,98 ----
  # define NAMED_BIND	1	/* use Berkeley Internet Domain Server */
  /*# define TTYNAME	1	/* set macro y to basename of tty device */
  /*# define NOTUNIX	1	/* Define if msgs lack a UNIX "From " line */
+ #define AUTHUSER	1       /* Define to support the 'ident' protocol */
  
  /*
   * Enable non-standard SMTP mods for talking to the DEC mail11v3 program.
*** sendmail.h.orig	Tue Jul 28 04:34:20 1992
--- sendmail.h	Tue Jul 28 04:35:57 1992
***************
*** 713,718 ****
--- 713,719 ----
  EXTERN char	*QueueDir;	/* location of queue directory */
  EXTERN char	*FileName;	/* name to print on error messages */
  EXTERN char	*SmtpPhase;	/* current phase in SMTP processing */
+ EXTERN char	*RealUser; 	/* name of user we're talking to (RFC931) */
  EXTERN char	*MyHostName;	/* name of this host for SMTP messages */
  EXTERN char	*RealHostName;	/* name of host we are talking to */
  EXTERN char	*DeclHostName;	/* declared name of host we are talking to */
*** deliver.c.orig	Tue Mar 31 15:55:01 1992
--- deliver.c	Tue Mar 31 15:55:26 1992
***************
*** 225,230 ****
--- 225,240 ----
  
  	define('g', tfrombuf, e);		/* translated sender address */
  	define('h', host, e);			/* to host */
+ 	
+ #ifdef AUTHUSER
+ 	if (RealHostName)
+ 	  define('S', RealHostName, CurEnv);
+ 	
+ 	/* RFC 931 sender name---2/7/91 DJB */
+ 	if (RealUser)
+ 	  define('F', RealUser, CurEnv);
+ #endif
+ 
  	Errors = 0;
  	pvp = pv;
  	*pvp++ = m->m_argv[0];
*** envelope.c.orig	Tue Mar 31 15:55:01 1992
--- envelope.c	Tue Mar 31 15:55:26 1992
***************
*** 476,482 ****
--- 476,497 ----
  #ifdef LOG
  			if (LogLevel >= 1)
  			    if (realname == from && RealHostName != NULL)
+ #ifdef AUTHUSER
  				syslog(LOG_NOTICE,
+ 				   "from=%s unparseable, received from %s%s%s",
+ 				   from, 
+ 				   RealUser ? RealUser : "",
+ 				   RealUser ? "@" : "",
+ 				   RealHostName);
+ 			    else
+ 				syslog(LOG_NOTICE,
+ 				    "Unparseable username %s wants from=%s",
+ 				       realname, 
+ 				       RealUser ? RealUser : "",
+ 				       RealUser ? "@" : "",
+ 				       from);
+ #else /* !AUTHUSER */
+ 				syslog(LOG_NOTICE,
  				    "from=%s unparseable, received from %s",
  				    from, RealHostName);
  			    else
***************
*** 483,488 ****
--- 498,504 ----
  				syslog(LOG_NOTICE,
  				    "Unparseable username %s wants from=%s",
  				    realname, from);
+ #endif /* !AUTHUSER */
  #endif /* LOG */
  		}
  		from = newstr(realname);
*** headers.c.orig	Tue Mar 31 15:55:01 1992
--- headers.c	Tue Mar 31 15:55:26 1992
***************
*** 477,486 ****
--- 477,496 ----
  		else
  			(void)sprintf(hbuf, "%.90s (%s)", 
  			    RealHostName, inet_ntoa(RealHostAddr.sin_addr));
+ #ifdef AUTHUSER
  		syslog(LOG_INFO,
+ 		    "%s: from=%s, size=%ld, class=%d, received from %s%s%s\n",
+ 		    CurEnv->e_id, CurEnv->e_from.q_paddr, CurEnv->e_msgsize,
+ 		    CurEnv->e_class, 
+ 		       RealUser ? RealUser : "",
+ 		       RealUser ? "@" : "",
+ 		       name);
+ #else
+ 		syslog(LOG_INFO,
  		    "%s: from=%s, size=%ld, class=%d, received from %s",
  		    CurEnv->e_id, CurEnv->e_from.q_paddr, CurEnv->e_msgsize,
  		    CurEnv->e_class, name);
+ #endif /* !AUTHUSER */		
  	}
  #endif /* LOG */
  }
*** main.c.orig	Tue Mar 31 15:55:01 1992
--- main.c	Tue Mar 31 15:55:27 1992
***************
*** 48,53 ****
--- 48,59 ----
  # define MAXHOSTNAMELEN	64
  #endif /* !MAXHOSTNAMELEN */
  
+ #ifdef AUTHUSER
+ #include <netdb.h>
+ #include <errno.h>
+ #include <pwd.h>
+ #endif
+   
  #ifdef lint
  int	edata, end;
  #endif /* lint */
***************
*** 876,881 ****
--- 882,988 ----
  #endif /* DAEMON */
  	}
  	
+ #ifdef AUTHUSER	
+ 	{
+ 	  extern int auth_fd2();
+ 	  extern char *auth_tcpuser3();
+ 	  
+ 	  unsigned long inlocal;
+ 	  unsigned long inremote;
+ 	  unsigned short local;
+ 	  unsigned short remote;
+ 	  char *user;
+ 
+ 	  
+ 	  /* RFC 931 support added 2/7/91 by DJB */
+ 	  /* We could just use auth_xline but we don't */
+ 	  /* know the supposed username yet. */
+ 	  
+ 	  if (InChannel == NULL)
+ 	    user = NULL;
+ 	  else if (auth_fd2(fileno(InChannel),
+ 			    &inlocal, &inremote, 
+ 			    &local, &remote) != -1)
+ 	  {
+           /* 30 second timeout added by pen@lysator.liu.se */
+ 	    user = auth_tcpuser3(inlocal, inremote, local, remote, 30);
+ 	    if (!user)
+ 	      user = NULL;
+ 	  }
+ 	  else
+ 	  {
+ 	    if (errno != ENOTSOCK)
+ 	      user = NULL;
+ 	    else
+ 	    {
+ 	      struct passwd *pwd;
+ 
+ 	      pwd = getpwuid(getuid());
+ 	      if (!pwd)
+ 		user = NULL;
+ 	      else
+ 		user = pwd->pw_name;
+ 	    }
+ 	  }
+ 
+ 	  if (user)
+ 	    RealUser = newstr(user);
+ 	  else
+ 	    RealUser = NULL;
+ 	}
+ 
+ 	if (RealHostName == NULL)
+ 	{
+ 	  int len = sizeof(RealHostAddr);
+ 	  struct hostent *hp, *gethostbyaddr();
+ 	  char buf[200];
+ 	  
+ 	  
+ 	  if (InChannel &&
+ 	      getpeername(fileno(InChannel), &RealHostAddr, &len) != -1 &&
+ 	      RealHostAddr.sin_family == AF_INET)
+ 	  {
+ 	    /* determine host name */
+ 	    hp = gethostbyaddr((char *) &RealHostAddr.sin_addr,
+ 			       sizeof RealHostAddr.sin_addr, AF_INET);
+ 	    if (hp != NULL)
+ 	      (void) strcpy(buf, hp->h_name);
+ 	    else
+ 	    {
+ 	      extern char *inet_ntoa();
+ 	      
+ 	      /* produce a dotted quad */
+ 	      (void) sprintf(buf, "[%s]",
+ 			     inet_ntoa(RealHostAddr.sin_addr));
+ 	    }
+ 	    
+ 	    RealHostName = newstr(buf);
+ 	  }
+ 	  else
+ 	    if (InChannel && errno == ENOTSOCK)
+ 	    {
+ 	      char hname[256];
+ 	      
+ 	      /* determine host name */
+ 	      if (gethostname(hname, sizeof(hname)-1) != -1)
+ 	      {
+ 		hp = gethostbyname(hname);
+ 		if (hp != NULL)
+ 		  (void) strcpy(buf, hp->h_name);
+ 		else
+ 		{
+ 		  extern char *inet_ntoa();
+ 		  
+ 		  /* produce a dotted quad */
+ 		  (void) sprintf(buf, "[%s]",
+ 				 inet_ntoa(RealHostAddr.sin_addr));
+ 		}
+ 		
+ 		RealHostName = newstr(buf);
+ 	      }
+ 	    }
+ 	}
+ #endif /* AUTHUSER */
+ 
  #ifdef SMTP
  	/*
  	**  If running SMTP protocol, start collecting and executing
*** srvrsmtp.c.orig	Tue Mar 31 15:55:01 1992
--- srvrsmtp.c	Tue Mar 31 15:55:27 1992
***************
*** 272,277 ****
--- 272,285 ----
  				break;
  			define('s', sendinghost, CurEnv);
  			define('r', "SMTP", CurEnv);
+ #ifdef AUTHUSER
+ 			/* I want the _real_ hostname too.. */
+ 			if (RealHostName)
+ 				define('S', RealHostName, CurEnv);
+ 			/* RFC 931 sender name---2/7/91 DJB */
+ 			if (RealUser)
+ 			  define('F', RealUser, CurEnv);
+ #endif
  			initsys();
  			setproctitle("%s %s: %s", CurEnv->e_id,
  				CurHostName, inp);
