From Jim.Pirzyk@disney.com  Wed Feb  9 13:45:37 2000
Return-Path: <Jim.Pirzyk@disney.com>
Received: from mail11.disney.com (mail11.disney.com [208.246.35.55])
	by builder.freebsd.org (Postfix) with ESMTP id BA518427A
	for <FreeBSD-gnats-submit@freebsd.org>; Wed,  9 Feb 2000 13:45:16 -0800 (PST)
Received: from panic.noceast.dws.disney.com (root@panic.noceast.dws.disney.com [153.6.248.200])
	by mail11.disney.com (8.9.1/8.9.1) with SMTP id NAA01670
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 9 Feb 2000 13:44:16 -0800 (PST)
Received: from louie.fa.disney.com by panic.noceast.dws.disney.com with ESMTP for FreeBSD-gnats-submit@freebsd.org; Wed, 9 Feb 2000 16:44:40 -0500
Received: from snowhite.faf.fa.disney.com (snowhite.faf.fa.disney.com [153.7.115.1])
	by louie.fa.disney.com (8.9.2/8.9.2) with ESMTP id NAA25284
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 9 Feb 2000 13:44:39 -0800 (PST)
	(envelope-from pirzyk@fa.disney.com)
Received: from snoopy.faf.fa.disney.com (snoopy.faf.fa.disney.com [153.7.115.94])
	by snowhite.faf.fa.disney.com (8.9.2/8.9.2) with ESMTP id QAA28367
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 9 Feb 2000 16:44:37 -0500 (EST)
	(envelope-from pirzyk@fa.disney.com)
Received: (from pirzyk@localhost)
	by snoopy.faf.fa.disney.com (8.9.3/8.9.2) id QAA58474;
	Wed, 9 Feb 2000 16:44:37 -0500 (EST)
	(envelope-from pirzyk@fa.disney.com)
Message-Id: <200002092144.QAA58474@snoopy.faf.fa.disney.com>
Date: Wed, 9 Feb 2000 16:44:37 -0500 (EST)
From: pirzyk@hotmail.com
Sender: Jim.Pirzyk@disney.com
Reply-To: pirzyk@hotmail.com
To: FreeBSD-gnats-submit@freebsd.org
Subject: Enhancement to trimdomain library routine in libutil
X-Send-Pr-Version: 3.2

>Number:         16619
>Category:       bin
>Synopsis:       trimdomain does not handle peer domains
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Wed Feb  9 13:50:00 PST 2000
>Closed-Date:    Sat Jun 16 20:15:13 PDT 2001
>Last-Modified:  Sat Jun 16 20:15:31 PDT 2001
>Originator:     Jim Pirzyk
>Release:        FreeBSD 3.4-RELEASE i386
>Organization:
>Environment:

	A standard FreeBSD 3.4 enviroment with mutiple peer domains (i.e.
	foo.example.com and bar.example.com).

>Description:

	when rsh/ssh/telnet into a host in a peer domain, the hostname is
	greater than UT_HOSTNAMELEN and so the IP number gets put into the
	wtmp file.  To releave this, we wanted the domain in common part
	to be parsed out.  i.e if I am on snoopy.foo.example.com and want
	to login to woodstock.bar.example.com the finger info should show
	on woodstock me logged in from snoopy.foo

>How-To-Repeat:

	Just login to a host in a peer domain.

>Fix:
	
*** logwtmp.c.orig	Wed Feb  9 10:42:22 2000
--- logwtmp.c	Wed Feb  9 12:00:19 2000
***************
*** 55,77 ****
  #include <utmp.h>
  
  void
! trimdomain(char *fullhost, int hostsize)
  {
-     static char domain[MAXHOSTNAMELEN];
-     static int first = 1;
-     static size_t dlen;
      char *s, *end;
      int spn, ok;
! 
!     if (first) {
!         first = 0;
!         if (gethostname(domain, sizeof(domain) - 1) == 0 &&
!             (s = strchr(domain, '.')))
!             memmove(domain, s + 1, strlen(s + 1) + 1);
!         else
!             domain[0] = '\0';
!         dlen = strlen(domain);
!     }
  
      if (domain[0] != '\0') {
  	s = fullhost;
--- 55,65 ----
  #include <utmp.h>
  
  void
! _trimdomain(char *fullhost, int hostsize, char *domain)
  {
      char *s, *end;
      int spn, ok;
!     size_t dlen = strlen(domain);
  
      if (domain[0] != '\0') {
  	s = fullhost;
***************
*** 105,110 ****
--- 93,126 ----
              }
      }
  }
+ 
+ void 
+ trimdomain(char *fullhost, int hostsize)
+ {
+     static char domain[MAXHOSTNAMELEN];
+     static int first = 1, dots = 0;
+     int i;
+     size_t len = strlen (fullhost);
+     char *s, *ptr = domain;
+ 
+     if (first) {
+         first = 0;
+         if (gethostname(domain, sizeof(domain) - 1) == 0 &&
+             (s = strchr(domain, '.'))) {
+             memmove(domain, s + 1, strlen(s + 1) + 1);
+             while ((ptr = strchr(ptr+1, '.'))) dots++;
+         } else {
+             domain[0] = '\0';
+         }
+     }
+ 
+     for (i=0, ptr=domain; i < dots && ptr; i++) {
+         _trimdomain(fullhost, hostsize, ptr);
+         if ( strlen (fullhost) != len ) break;
+         ptr = strchr (ptr, '.')+1;
+     }
+ }
+ 
  
  void
  logwtmp(line, name, host)

>Release-Note:
>Audit-Trail:

From: Brian Somers <brian@Awfulhak.org>
To: pirzyk@hotmail.com
Cc: FreeBSD-gnats-submit@FreeBSD.ORG, brian@hak.lan.Awfulhak.org
Subject: Re: bin/16619: Enhancement to trimdomain library routine in libutil 
Date: Fri, 11 Feb 2000 08:46:36 +0000

 > >Number:         16619
 > >Category:       bin
 > >Synopsis:       trimdomain does not handle peer domains
 [.....]
 > >Description:
 > 
 > 	when rsh/ssh/telnet into a host in a peer domain, the hostname is
 > 	greater than UT_HOSTNAMELEN and so the IP number gets put into the
 > 	wtmp file.  To releave this, we wanted the domain in common part
 > 	to be parsed out.  i.e if I am on snoopy.foo.example.com and want
 > 	to login to woodstock.bar.example.com the finger info should show
 > 	on woodstock me logged in from snoopy.foo
 [.....]
 
 No, this is a bad idea.  Last time I was in there, I actually 
 implemented this and realised why....
 
 $ hostname
 confusion.co.uk.FreeBSD.org
 $ slogin freefall.FreeBSD.org
 
 Freefalls logs are now garbage.  This is why name resolution doesn't 
 work this way any more either.
 -- 
 Brian <brian@Awfulhak.org>                        <brian@FreeBSD.org>
       <http://www.Awfulhak.org>                   <brian@OpenBSD.org>
 Don't _EVER_ lose your sense of humour !          <brian@FreeBSD.org.uk>
 
 
 
State-Changed-From-To: open->closed 
State-Changed-By: dd 
State-Changed-When: Sat Jun 16 20:15:13 PDT 2001 
State-Changed-Why:  
As Brian explained, this is a bad idea. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=16619 
>Unformatted:
