From owner-freebsd-bugs Mon Apr 7 20:30:04 1997 Return-Path: Received: (from root@localhost) by freefall.freebsd.org (8.8.5/8.8.5) id UAA12569 for bugs-outgoing; Mon, 7 Apr 1997 20:30:04 -0700 (PDT) Received: (from gnats@localhost) by freefall.freebsd.org (8.8.5/8.8.5) id UAA12563; Mon, 7 Apr 1997 20:30:02 -0700 (PDT) Resent-Date: Mon, 7 Apr 1997 20:30:02 -0700 (PDT) Resent-Message-Id: <199704080330.UAA12563@freefall.freebsd.org> Resent-From: gnats (GNATS Management) Resent-To: freebsd-bugs Resent-Reply-To: FreeBSD-gnats@freefall.FreeBSD.org, ahd@kew.com 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 ; 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 Reply-To: ahd@kew.com To: FreeBSD-gnats-submit@freebsd.org, ahd@dumbo.hh.kew.com X-Send-Pr-Version: 3.2 Subject: misc/3225: uucpd.c should normalize host names Sender: owner-bugs@freebsd.org X-Loop: FreeBSD.org Precedence: bulk >Number: 3225 >Category: misc >Synopsis: uucpd.c should normalize host names as login does >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Mon Apr 7 20:30:01 PDT 1997 >Last-Modified: >Originator: Drew Derbyshire >Organization: Kendra Electronic Wonderworks, Stoneham MA >Release: FreeBSD 2.2-RELEASE i386 (uucpd.c 1.11 from 3.x-current) >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 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 #include #include ! #include #include "pathnames.h" #if (MAXLOGNAME-1) > UT_NAMESIZE --- 70,76 ---- #include #include #include ! #include #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)); + } >Audit-Trail: >Unformatted: