Subject: toolchain/24843: cross-'build.sh release' fails with wrong passwd/group database on FreeBSD host
To: None <gnats-bugs@gnats.NetBSD.org>
From: None <t-ogawa@triaez.kaisei.org>
List: netbsd-bugs
Date: 03/18/2004 22:31:04
>Number:         24843
>Category:       toolchain
>Synopsis:       cross-'build.sh release' fails with wrong passwd/group database on FreeBSD host
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    toolchain-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Mar 18 22:32:00 UTC 2004
>Closed-Date:
>Last-Modified:
>Originator:     OGAWA Takaya
>Release:        NetBSD 1.6ZK around Mar 12 2004
>Organization:
Individual
>Environment:
FreeBSD sam.example.com 5.2.1-RELEASE FreeBSD 5.2.1-RELEASE #5: Thu Feb 26 20:18:37 JST 2004     root@sam.example.com:/usr/obj/usr/src/sys/SAM  i386

>Description:
On FreeBSD host, trying to build a release using the following command
completed with these unusual binary sets:

    % ls -l $RELEASEDIR/i386/binary/sets/*.tgz
    -rw-r--r--  1 ogawa  wheel        20  3 19 05:59 base.tgz  <--- XXX
    -rw-r--r--  1 ogawa  wheel  21203656  3 19 06:01 comp.tgz
    -rw-r--r--  1 ogawa  wheel        20  3 19 06:01 etc.tgz   <--- XXX
    -rw-r--r--  1 ogawa  wheel   3035165  3 19 06:01 games.tgz
    -rw-r--r--  1 ogawa  wheel   7352315  3 19 06:02 man.tgz
    -rw-r--r--  1 ogawa  wheel   2661430  3 19 06:02 misc.tgz
    -rw-r--r--  1 ogawa  wheel   1979214  3 19 06:02 text.tgz
    -rw-r--r--  1 ogawa  wheel   5743149  3 19 06:03 xbase.tgz
    -rw-r--r--  1 ogawa  wheel  10653694  3 19 06:04 xcomp.tgz

Though I had wiped out the build log (sorry), after having looked around
what went wrong, I found out a strange entry in
$DESTDIR/etc/mtree/set.base:

./usr/sbin/postdrop type=file uname=root gname=lmadmin mode=0255 sha1= ....
                                               ^^^^^^^
The lmadmin is this HOST's group, not TARGET's one.
set.etc also contained a similar entry with host's group field.

>How-To-Repeat:
Try "build.sh release" on a FreeBSD host.


>Fix:
On FreeBSD hosts, the following conditions are met:

	HAVE_USER_FROM_UID
	!HAVE_PWCACHE_USERDB

Currently libnbcompat.a will be built including pwcache_userdb()
and pwcache_groupdb() but not user_from_uid() and user_from_gid() and
will use host's ones.
This is the problem because host's user_from_{uid,gid}() do not take
care of user-provided routines via NetBSD's pwcache_userdb().

So we need to use NetBSD-provided user_from_{uid,gid}() regardless
of their existance in the host environment.

I propose the patch below:

Index: lib/libc/gen/pwcache.c
===================================================================
RCS file: /cvs/netbsd/src/lib/libc/gen/pwcache.c,v
retrieving revision 1.25
diff -u -r1.25 pwcache.c
--- lib/libc/gen/pwcache.c	13 Oct 2003 07:41:22 -0000	1.25
+++ lib/libc/gen/pwcache.c	18 Mar 2004 21:08:46 -0000
@@ -66,6 +66,10 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
+#if HAVE_NBTOOL_CONFIG_H
+#include "nbtool_config.h"
+#endif
+
 #include <sys/cdefs.h>
 #if defined(LIBC_SCCS) && !defined(lint)
 #if 0
@@ -240,7 +244,6 @@
 	return (0);
 }
 
-#if !HAVE_USER_FROM_UID
 /*
  * user_from_uid()
  *	caches the name (if any) for the uid. If noname clear, we always
@@ -380,7 +383,6 @@
 	}
 	return (ptr->name);
 }
-#endif /* HAVE_USER_FROM_UID */
 
 /*
  * uid_from_user()
Index: tools/compat/compat_defs.h
===================================================================
RCS file: /cvs/netbsd/src/tools/compat/compat_defs.h,v
retrieving revision 1.31
diff -u -r1.31 compat_defs.h
--- tools/compat/compat_defs.h	27 Oct 2003 00:12:42 -0000	1.31
+++ tools/compat/compat_defs.h	18 Mar 2004 21:09:15 -0000
@@ -238,6 +238,10 @@
 int gid_from_group(const char *, gid_t *);
 int pwcache_groupdb(int (*)(int), void (*)(void),
 		struct group * (*)(const char *), struct group * (*)(gid_t));
+# if HAVE_USER_FROM_UID
+#  define user_from_uid __nbcompat_user_from_uid
+#  define group_from_gid __nbcompat_group_from_gid
+# endif
 #endif
 
 #if !HAVE_PWRITE
Index: tools/compat/compat_pwd.h
===================================================================
RCS file: /cvs/netbsd/src/tools/compat/compat_pwd.h,v
retrieving revision 1.2
diff -u -r1.2 compat_pwd.h
--- tools/compat/compat_pwd.h	3 Jul 2002 17:17:04 -0000	1.2
+++ tools/compat/compat_pwd.h	18 Mar 2004 21:09:15 -0000
@@ -41,11 +41,6 @@
 
 /* A very special version of <pwd.h> for pwd_mkdb(8) and __nbcompat_pwscan(3). */
 
-#if HAVE_USER_FROM_UID
-#define user_from_uid __nbcompat_system_user_from_uid
-#define group_from_gid __nbcompat_system_group_from_gid
-#endif
-
 #include "../../include/pwd.h"
 
 #define passwd __nbcompat_passwd

>Release-Note:
>Audit-Trail:
>Unformatted: