From ahd@dumbo.hh.kew.com  Mon Apr  7 20:22:13 1997
Received: from dumbo.hh.kew.com (root@dumbo.hh.kew.com [192.195.203.133])
          by freefall.freebsd.org (8.8.5/8.8.5) with ESMTP id UAA12191
          for <FreeBSD-gnats-submit@freebsd.org>; Mon, 7 Apr 1997 20:22:03 -0700 (PDT)
Received: (from root@localhost)
	by dumbo.hh.kew.com (8.8.5/8.8.5) id XAA14775;
	Mon, 7 Apr 1997 23:21:55 -0400 (EDT)
Message-Id: <199704080321.XAA14775@dumbo.hh.kew.com>
Date: Mon, 7 Apr 1997 23:21:55 -0400 (EDT)
From: Drew Derbyshire <ahd@kew.com>
Reply-To: ahd@kew.com
To: FreeBSD-gnats-submit@freebsd.org, ahd@dumbo.hh.kew.com
Subject: uucpd.c should normalize host names
X-Send-Pr-Version: 3.2

>Number:         3225
>Category:       ports
>Synopsis:       [PATCH] uucpd.c should normalize host names as login does
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    dinoex
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Apr  7 20:30:01 PDT 1997
>Closed-Date:    Fri Mar 29 22:31:42 PST 2002
>Last-Modified:  Fri Mar 29 22:31:42 PST 2002
>Originator:     Drew Derbyshire
>Release:        FreeBSD 2.2-RELEASE i386 (uucpd.c 1.11 from 3.x-current)
>Organization:
Kendra Electronic Wonderworks, Stoneham MA
>Environment:

	uucpd.c instaleld to answer uucico login on port 540

>Description:

	uucpd.c tends to end up with the remote host name logged
	as IP addresses because it always checks for and/or presents
	the full host name.  login, on the other hand, automatically
	strips the domain off the host name if the local and remote
	domains matches.

>How-To-Repeat:

	Login via port 540 from a host in the local domain longer
	with a host name longer than 32 characters.

>Fix:

	Patch follows.  Note that I moved the retrieval of the host
	name into a common routine which is called at startup; this
	may slow the initial presentation of the prompt, but does
	not affect overall performance because the login host would
	always be logged before control is passed to UUCICO.

	I also replaced the local prototype for the logwtmp with the
	proper header file, and removed the redundant <sys/param.h>
	header.
	
	
*** uucpd.c	1997/04/06 03:52:14	1.12
--- uucpd.c	1997/04/06 03:55:06
***************
*** 33,39 ****
   * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   *
!  *	$Id: uucpd.c,v 1.12 1997/04/06 03:52:14 ahd Exp $
   */
  
  #ifndef lint
--- 33,39 ----
   * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   *
!  *	$Id: uucpd.c,v 1.11 1997/04/01 20:39:59 joerg Exp ahd $
   */
  
  #ifndef lint
***************
*** 70,76 ****
  #include <string.h>
  #include <utmp.h>
  #include <syslog.h>
! #include <sys/param.h>
  #include "pathnames.h"
  
  #if (MAXLOGNAME-1) > UT_NAMESIZE
--- 70,76 ----
  #include <string.h>
  #include <utmp.h>
  #include <syslog.h>
! #include <libutil.h>
  #include "pathnames.h"
  
  #if (MAXLOGNAME-1) > UT_NAMESIZE
***************
*** 86,91 ****
--- 86,92 ----
  struct	sockaddr_in myctladdr;
  int mypid;
  
+ char remotehost[MAXHOSTNAMELEN];
  char Username[64], Logname[64];
  char *nenv[] = {
  	Username,
***************
*** 93,136 ****
  	NULL,
  };
  extern char **environ;
- extern void logwtmp(char *line, char *name, char *host);
  
! void doit(struct sockaddr_in *sinp);
  void dologout(void);
  int readline(char start[], int num, int passw);
! void dologin(struct passwd *pw, struct sockaddr_in *sin);
  
  void main(int argc, char **argv)
  {
  	environ = nenv;
  	close(1); close(2);
  	dup(0); dup(0);
- 	hisaddrlen = sizeof (hisctladdr);
  	openlog("uucpd", LOG_PID, LOG_DAEMON);
! 	if (getpeername(0, (struct sockaddr *)&hisctladdr, &hisaddrlen) < 0) {
! 		syslog(LOG_ERR, "getpeername: %m");
! 		_exit(1);
! 	}
! 	doit(&hisctladdr);
  	dologout();
  	exit(0);
  }
  
! void badlogin(char *name, struct sockaddr_in *sin)
  {
- 	char remotehost[MAXHOSTNAMELEN];
- 	struct hostent *hp = gethostbyaddr((char *)&sin->sin_addr,
- 		sizeof (struct in_addr), AF_INET);
- 
- 	if (hp) {
- 		strncpy(remotehost, hp->h_name, sizeof (remotehost));
- 		endhostent();
- 	} else
- 		strncpy(remotehost, inet_ntoa(sin->sin_addr),
- 		    sizeof (remotehost));
- 
- 	remotehost[sizeof remotehost - 1] = '\0';
- 
  	syslog(LOG_NOTICE, "LOGIN FAILURE FROM %s", remotehost);
  	syslog(LOG_AUTHPRIV|LOG_NOTICE,
  	    "LOGIN FAILURE FROM %s, %s", remotehost, name);
--- 94,120 ----
  	NULL,
  };
  extern char **environ;
  
! void doit();
  void dologout(void);
  int readline(char start[], int num, int passw);
! void dologin(struct passwd *pw);
! void getremotehostname( void );
  
  void main(int argc, char **argv)
  {
  	environ = nenv;
  	close(1); close(2);
  	dup(0); dup(0);
  	openlog("uucpd", LOG_PID, LOG_DAEMON);
!       getremotehostname( );
! 	doit();
  	dologout();
  	exit(0);
  }
  
! void badlogin(char *name)
  {
  	syslog(LOG_NOTICE, "LOGIN FAILURE FROM %s", remotehost);
  	syslog(LOG_AUTHPRIV|LOG_NOTICE,
  	    "LOGIN FAILURE FROM %s, %s", remotehost, name);
***************
*** 139,145 ****
  	exit(1);
  }
  
! void doit(struct sockaddr_in *sinp)
  {
  	char user[64], passwd[64];
  	char *xpasswd, *crypt();
--- 123,129 ----
  	exit(1);
  }
  
! void doit()
  {
  	char user[64], passwd[64];
  	char *xpasswd, *crypt();
***************
*** 180,186 ****
  				pwdok = 0;
  		}
  		if (!pwdok)
! 			badlogin(user, sinp);
  	}
  	alarm(0);
  	sprintf(Username, "USER=%s", pw->pw_name);
--- 164,170 ----
  				pwdok = 0;
  		}
  		if (!pwdok)
! 			badlogin(user);
  	}
  	alarm(0);
  	sprintf(Username, "USER=%s", pw->pw_name);
***************
*** 189,195 ****
  		syslog(LOG_ERR, "fork: %m");
  		_exit(1);
  	} else if (s == 0) {
! 		dologin(pw, sinp);
  		setgid(pw->pw_gid);
  		initgroups(pw->pw_name, pw->pw_gid);
  		chdir(pw->pw_dir);
--- 173,179 ----
  		syslog(LOG_ERR, "fork: %m");
  		_exit(1);
  	} else if (s == 0) {
! 		dologin(pw);
  		setgid(pw->pw_gid);
  		initgroups(pw->pw_name, pw->pw_gid);
  		chdir(pw->pw_dir);
***************
*** 243,263 ****
  /*
   * Record login in wtmp file.
   */
! void dologin(struct passwd *pw, struct sockaddr_in *sin)
  {
  	char line[32];
- 	char remotehost[MAXHOSTNAMELEN];
  	int f;
  	time_t cur_time;
- 	struct hostent *hp = gethostbyaddr((char *)&sin->sin_addr,
- 		sizeof (struct in_addr), AF_INET);
- 
- 	if (hp) {
- 		strncpy(remotehost, hp->h_name, sizeof (remotehost));
- 		endhostent();
- 	} else
- 		strncpy(remotehost, inet_ntoa(sin->sin_addr),
- 		    sizeof (remotehost));
  	/* hack, but must be unique and no tty line */
  	sprintf(line, "uucp%ld", getpid());
  	time(&cur_time);
--- 227,237 ----
  /*
   * Record login in wtmp file.
   */
! void dologin(struct passwd *pw)
  {
  	char line[32];
  	int f;
  	time_t cur_time;
  	/* hack, but must be unique and no tty line */
  	sprintf(line, "uucp%ld", getpid());
  	time(&cur_time);
***************
*** 272,275 ****
--- 246,291 ----
  		(void) close(f);
  	}
  	logwtmp(line, pw->pw_name, remotehost);
+ }
+ 
+ void
+ getremotehostname()
+ {
+ 	char localhost[MAXHOSTNAMELEN];
+ 	char *p, *domain;
+ 
+ 	struct  sockaddr_in hisctladdr;
+ 	int hisaddrlen = sizeof hisctladdr;
+ 	struct hostent *hp;
+ 
+ 	/* Determine local (admin) domain name, if any */
+ 	domain = NULL;
+ 	if (gethostname(localhost, sizeof(localhost)) < 0)
+ 		syslog(LOG_ERR, "couldn't get local hostname: %m");
+ 	else
+ 		domain = strchr(localhost, '.');
+ 
+ 	/* Get remote sock info of stdin, in particular IP addr */
+ 	hisaddrlen = sizeof (hisctladdr);
+ 	if (getpeername(0, (struct sockaddr *)&hisctladdr, &hisaddrlen) < 0) {
+ 		syslog(LOG_ERR, "getpeername: %m");
+ 		_exit(1);
+ 	}
+ 
+ 	/* Now get remote name from IP address */
+ 	hp = gethostbyaddr((char *)&hisctladdr.sin_addr,
+ 			   sizeof (struct in_addr), AF_INET);
+ 
+ 	if (hp) {
+ 		SCPYN(remotehost, hp->h_name );
+ 		remotehost[ sizeof remotehost - 1] = '\0';
+ 
+ 		/* Drop domain if system in in same domain */
+ 		if (domain && (p = strchr(remotehost, '.')) &&
+ 		    strcasecmp(p, domain) == 0)
+ 			*p = 0;
+ 		endhostent();
+ 	} else
+ 		SCPYN(remotehost, inet_ntoa(hisctladdr.sin_addr));
+ 
  }

>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->feedback 
State-Changed-By: iedowse 
State-Changed-When: Sat Jan 19 13:11:30 PST 2002 
State-Changed-Why:  

Does this problem still exist? Note that UUCP is no longer part of 
the base system in -CURRENT, so maybe this should be addressed at 
the freebsd-uucp port first. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=3225 
Responsible-Changed-From-To: freebsd-bugs->dinoex 
Responsible-Changed-By: dinoex 
Responsible-Changed-When: Thu Jan 31 23:15:08 PST 2002 
Responsible-Changed-Why:  
Now part of ports, I will look into this 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=3225 

From: dirk.meyer@dinoex.sub.org (Dirk Meyer)
To: freebsd-gnats-submit@FreeBSD.org, ahd@kew.com
Cc:  
Subject: Re: ports/3225: [PATCH] uucpd.c should normalize host
	names as login does
Date: Mon, 04 Feb 2002 21:07:59 +0100

 The code to resove hostnames have changed much,
 Please verify is your problem still exists,
 and send in a new patch.
 
 kind regards Dirk
 
 - Dirk Meyer, Im Grund 4, 34317 Habichtswald, Germany
 [dirk.meyer@dinoex.sub.org],[dirk.meyer@guug.de],[dinoex@FreeBSD.org]
State-Changed-From-To: feedback->closed 
State-Changed-By: dinoex 
State-Changed-When: Fri Mar 29 22:30:46 PST 2002 
State-Changed-Why:  
No response, uucpd has changed in between, so some of the points  
are already committed. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=3225 
>Unformatted:
