From mika@s0.cs.caltech.edu  Wed Oct  1 08:25:08 1997
Received: from vlsi.cs.caltech.edu (vlsi.cs.caltech.edu [131.215.131.129])
          by hub.freebsd.org (8.8.7/8.8.7) with SMTP id IAA19683
          for <FreeBSD-gnats-submit@freebsd.org>; Wed, 1 Oct 1997 08:25:07 -0700 (PDT)
Received: from s0.cs.caltech.edu by vlsi.cs.caltech.edu (4.1/1.34.1)
	id AA14870; Wed, 1 Oct 97 08:25:05 PDT
Received: (from mika@localhost)
	by s0.cs.caltech.edu (8.8.7/8.8.7) id IAA00566;
	Wed, 1 Oct 1997 08:25:04 -0700 (PDT)
Message-Id: <199710011525.IAA00566@s0.cs.caltech.edu>
Date: Wed, 1 Oct 1997 08:25:04 -0700 (PDT)
From: mika@cs.caltech.edu
Reply-To: mika@cs.caltech.edu
To: FreeBSD-gnats-submit@freebsd.org
Subject:
X-Send-Pr-Version: 3.2

>Number:         4672
>Category:       bin
>Synopsis:       rdist does not do hard links right when target and source directories differ
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Oct  1 08:30:02 PDT 1997
>Closed-Date:    Fri Feb 02 13:51:52 GMT 2007
>Last-Modified:  Fri Feb 02 13:51:52 GMT 2007
>Originator:     
>Release:        
>Organization:
>Environment:
>Description:
>How-To-Repeat:
>Fix:
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: gnats-admin->freebsd-bugs 
Responsible-Changed-By: joerg 
Responsible-Changed-When: Sun Oct 19 20:25:08 MEST 1997 
Responsible-Changed-Why:  
Misfiled PR. 
Responsible-Changed-From-To: freebsd-bugs->freebsd-ports 
Responsible-Changed-By: mikeh 
Responsible-Changed-When: Sat Jun 16 23:41:43 PDT 2001 
Responsible-Changed-Why:  
rdist isn't in the base system 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=4672 
Responsible-Changed-From-To: freebsd-ports->freebsd-bugs 
Responsible-Changed-By: mikeh 
Responsible-Changed-When: Sun Jun 17 00:25:58 PDT 2001 
Responsible-Changed-Why:  
All the world is not -current. rdist(1) is still available in the base system in 4-stable. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=4672 
State-Changed-From-To: open->feedback 
State-Changed-By: mike 
State-Changed-When: Sat Jul 21 22:59:02 PDT 2001 
State-Changed-Why:  

Does this problem still occur in newer versions of FreeBSD, 
such as 4.3-RELEASE? 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=4672 
State-Changed-From-To: feedback->suspended 
State-Changed-By: kris 
State-Changed-When: Sat Sep 8 01:38:49 PDT 2001 
State-Changed-Why:  
Suspended awaiting fix and committer 

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

From: Lyndon Nerenberg <lyndon@orthanc.ab.ca>
To: freebsd-gnats-submit@FreeBSD.org
Cc:  
Subject: Re: bin/4672 rdist botches hardlink counts
Date: Sun, 06 Oct 2002 01:25:22 -0600

 The call to remotename() is returning a zero-length filename for
 the link source, thus rdist is sending the name of the source's
 directory, and not the complete path to the source file. After
 reading the code, I can't see the purpose of the remotename()
 call, since it doesn't appear that lp->src and lp->pathname can
 ever hold different strings (in the hardlink case). The attached
 patch fixes the problem described in the pr, and quells a couple
 of printf argument warnings from a -Wall compile.
 
 Index: defs.h
 ===================================================================
 RCS file: /home/ncvs/src/usr.bin/rdist/Attic/defs.h,v
 retrieving revision 1.6
 diff -u -r1.6 defs.h
 --- defs.h	1998/04/20 06:20:19	1.6
 +++ defs.h	2002/10/06 07:15:15
 @@ -137,7 +137,7 @@
  struct linkbuf {
  	ino_t	inum;
  	dev_t	devnum;
 -	int	count;
 +	u_int	count;
  	char	pathname[BUFSIZ];
  	char	src[BUFSIZ];
  	char	target[BUFSIZ];
 Index: docmd.c
 ===================================================================
 RCS file: /home/ncvs/src/usr.bin/rdist/Attic/docmd.c,v
 retrieving revision 1.12
 diff -u -r1.12 docmd.c
 --- docmd.c	1999/08/28 01:05:06	1.12
 +++ docmd.c	2002/10/06 07:15:15
 @@ -194,8 +194,8 @@
  			nextihead = ihead->nextp;
  			if ((opts & IGNLNKS) || ihead->count == 0)
  				continue;
 -			log(lfp, "%s: Warning: missing links\n",
 -				ihead->pathname);
 +			log(lfp, "%s: Warning: missing links (%u)\n",
 +				ihead->pathname, ihead->count);
  			free(ihead);
  		}
  	}
 Index: server.c
 ===================================================================
 RCS file: /home/ncvs/src/usr.bin/rdist/Attic/server.c,v
 retrieving revision 1.10
 diff -u -r1.10 server.c
 --- server.c	1999/08/28 01:05:09	1.10
 +++ server.c	2002/10/06 07:15:16
 @@ -334,8 +334,7 @@
  			opts, lp->pathname, rname);
  	else
  		(void) snprintf(buf, sizeof(buf), "k%o %s/%s %s\n",
 -			opts, lp->target,
 -			remotename(lp->pathname, lp->src), rname);
 +			opts, lp->target, lp->pathname, rname);
  
  	if (debug) {
  		printf("lp->src      = %s\n", lp->src);
 @@ -389,14 +388,16 @@
  			log(lfp, "%s: no password entry for uid %d \n",
  				target, stb.st_uid);
  			pw = NULL;
 -			(void)snprintf(user, sizeof(user), ":%lu", stb.st_uid);
 +			(void)snprintf(user, sizeof(user), ":%lu",
 +					(unsigned long)stb.st_uid);
  		}
  	if (gr == NULL || gr->gr_gid != stb.st_gid)
  		if ((gr = getgrgid(stb.st_gid)) == NULL) {
  			log(lfp, "%s: no name for group %d\n",
 -				target, stb.st_gid);
 +				target, (unsigned long)stb.st_gid);
  			gr = NULL;
 -			(void)snprintf(group, sizeof(group), ":%lu", stb.st_gid);
 +			(void)snprintf(group, sizeof(group), ":%lu",
 +					(unsigned long)stb.st_gid);
  		}
  	if (u == 1) {
  		if (opts & VERIFY) {

From: Lyndon Nerenberg <lyndon@orthanc.ab.ca>
To: freebsd-gnats-submit@FreeBSD.org
Cc:  
Subject: Re: bin/4672 rdist botches hardlink counts (take 2)
Date: Sun, 06 Oct 2002 01:42:59 -0600

 Of course, my tests had pathname and src reversed, so remotename
 appeared to be a noop. In fact, it's needed, and the bug is remotename
 not just returning pathname if it contains no '/' characters.
 
 Index: defs.h
 ===================================================================
 RCS file: /home/ncvs/src/usr.bin/rdist/Attic/defs.h,v
 retrieving revision 1.6
 diff -u -r1.6 defs.h
 --- defs.h	1998/04/20 06:20:19	1.6
 +++ defs.h	2002/10/06 07:40:52
 @@ -137,7 +137,7 @@
  struct linkbuf {
  	ino_t	inum;
  	dev_t	devnum;
 -	int	count;
 +	u_int	count;
  	char	pathname[BUFSIZ];
  	char	src[BUFSIZ];
  	char	target[BUFSIZ];
 Index: docmd.c
 ===================================================================
 RCS file: /home/ncvs/src/usr.bin/rdist/Attic/docmd.c,v
 retrieving revision 1.12
 diff -u -r1.12 docmd.c
 --- docmd.c	1999/08/28 01:05:06	1.12
 +++ docmd.c	2002/10/06 07:40:52
 @@ -194,8 +194,8 @@
  			nextihead = ihead->nextp;
  			if ((opts & IGNLNKS) || ihead->count == 0)
  				continue;
 -			log(lfp, "%s: Warning: missing links\n",
 -				ihead->pathname);
 +			log(lfp, "%s: Warning: missing links (%u)\n",
 +				ihead->pathname, ihead->count);
  			free(ihead);
  		}
  	}
 Index: server.c
 ===================================================================
 RCS file: /home/ncvs/src/usr.bin/rdist/Attic/server.c,v
 retrieving revision 1.10
 diff -u -r1.10 server.c
 --- server.c	1999/08/28 01:05:09	1.10
 +++ server.c	2002/10/06 07:40:53
 @@ -315,6 +315,8 @@
  	int len;
  
  	cp = pathname;
 +	if (strchr(cp, '/') == NULL)
 +		return cp;
  	len = strlen(src);
  	if (0 == strncmp(pathname, src, len))
  		cp += len;
 @@ -389,14 +391,16 @@
  			log(lfp, "%s: no password entry for uid %d \n",
  				target, stb.st_uid);
  			pw = NULL;
 -			(void)snprintf(user, sizeof(user), ":%lu", stb.st_uid);
 +			(void)snprintf(user, sizeof(user), ":%lu",
 +					(unsigned long)stb.st_uid);
  		}
  	if (gr == NULL || gr->gr_gid != stb.st_gid)
  		if ((gr = getgrgid(stb.st_gid)) == NULL) {
  			log(lfp, "%s: no name for group %d\n",
 -				target, stb.st_gid);
 +				target, (unsigned long)stb.st_gid);
  			gr = NULL;
 -			(void)snprintf(group, sizeof(group), ":%lu", stb.st_gid);
 +			(void)snprintf(group, sizeof(group), ":%lu",
 +					(unsigned long)stb.st_gid);
  		}
  	if (u == 1) {
  		if (opts & VERIFY) {
State-Changed-From-To: suspended->closed 
State-Changed-By: remko 
State-Changed-When: Fri Feb 2 13:51:51 UTC 2007 
State-Changed-Why:  
rdist does no longer exist in our source tree. Closing the ticket for 
that reason 

http://www.freebsd.org/cgi/query-pr.cgi?pr=4672 
>Unformatted:
Submitter-Id:   current-users
Originator:     Mika Nystroem
Organization:  Caltech Computer Science 
Confidential:   no
Synopsis:       rdist does not do hard links right when target and source directories differ
Severity:       serious
Priority:       medium
Category:       bin
Release:        FreeBSD 3.0-CURRENT i386
Class:          sw-bug
Environment: 
  Two FreeBSD 3.0-CURRENT(as of today systems)

Description: 

 rdist tries to recreate the source link structure exactly on the target
disk.  When the target directory has a different name (path) from the
source directory, the remote rdist attempts to make the links to the
old (source) names, which is incorrect.

How-To-Repeat: 
rdist files with hard links to a differently named directory.


Fix: 
change rdist so that the remote server knows what the remote filename is
(do not send the source filenames---aren't they irrelevant to the target
system?)

457                             (void) snprintf(buf, sizeof(buf), "k%o %s %s\n", opts,
458                                     lp->pathname, rname);
(gdb) step
456                             if (*lp->target == 0)
(gdb) 
457                             (void) snprintf(buf, sizeof(buf), "k%o %s %s\n", opts,
(gdb) print lp->pathname
$23 = "/usr/cit_install/root/bin/test", '\000' <repeats 993 times>
(gdb) print rname
$24 = 0x2c1c0 "["
(gdb) print *lp
$25 = {inum = 450070, devnum = 1030, count = 0, pathname = "/usr/cit_install/root/bin/test", '\000' <repeats 993 times>, target = '\000' <repeats 1023 times>, nextp = 0x0}
(gdb) print rname
$26 = 0x2c1c0 "["

The direct use of lp->pathname here seems incorrect.
I am not sure how to fix it, but somehow the upper-level routines of
rdist do figure out the mappings, so I assume the same could be done
here.. 



