From tim@sarc.city.ac.uk  Thu Jun 15 01:03:43 1995
Received: from cripplecock.sarc.city.ac.uk (cripplecock.sarc.city.ac.uk [138.40.91.253])
          by freefall.cdrom.com (8.6.10/8.6.6) with ESMTP id BAA29180
          for <FreeBSD-gnats-submit@freebsd.org>; Thu, 15 Jun 1995 01:03:16 -0700
Received: (from tim@localhost) by cripplecock.sarc.city.ac.uk (8.6.11/8.6.9) id JAA11210; Thu, 15 Jun 1995 09:03:13 +0100
Message-Id: <199506150803.JAA11210@cripplecock.sarc.city.ac.uk>
Date: Thu, 15 Jun 1995 09:03:13 +0100
From: tim@sarc.city.ac.uk
Reply-To: tim@sarc.city.ac.uk
To: FreeBSD-gnats-submit@freebsd.org
Subject: Bad group change with 'install'
X-Send-Pr-Version: 3.2

>Number:         517
>Category:       bin
>Synopsis:       Bad group change with 'install'
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Jun 15 01:10:01 1995
>Closed-Date:    Fri Mar 23 16:42:24 PST 2001
>Last-Modified:  Fri Mar 23 16:46:55 PST 2001
>Originator:     Tim Wilkinson
>Release:        FreeBSD 2.0.5-RELEASE i386
>Organization:
Systems Architecture Research Centre, City Uni. UK.
>Environment:
>Description:

When using 'install' to install software, the '-g' option does not change
the group correctly if the owner is also being set and the /etc/group file
is being checked because of "+groupname" entries in the /etc/passwd file.
Essentially, the information returned by 'getgrnam' is being overwritten
by the subsequent call to 'getpwnam' (which inturn calls 'getgrnam').

>How-To-Repeat:

Add an entry at then end of the password file such as "+operator:*:0:0:::"
then use "install -o root -g kmem" to install a program.  The installed
program will not get the correct group set.

>Fix:
	
The patch below just avoids the problem by changing the order ot the calls
to getgrnam and getpwnam so the group information isn't overwritten.  This
is not so much a fix as a hastily applied bit of sticky tape.

*** xinstall.c.orig	Thu Jun 15 08:19:11 1995
--- xinstall.c	Thu Jun 15 08:19:15 1995
***************
*** 123,132 ****
  		usage();
  
  	/* get group and owner id's */
- 	if (group && !(gp = getgrnam(group)))
- 		err("unknown group %s", group);
  	if (owner && !(pp = getpwnam(owner)))
  		err("unknown user %s", owner);
  
  	no_target = stat(to_name = argv[argc - 1], &to_sb);
  	if (!no_target && (to_sb.st_mode & S_IFMT) == S_IFDIR) {
--- 123,132 ----
  		usage();
  
  	/* get group and owner id's */
  	if (owner && !(pp = getpwnam(owner)))
  		err("unknown user %s", owner);
+ 	if (group && !(gp = getgrnam(group)))
+ 		err("unknown group %s", group);
  
  	no_target = stat(to_name = argv[argc - 1], &to_sb);
  	if (!no_target && (to_sb.st_mode & S_IFMT) == S_IFDIR) {
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->pst 
Responsible-Changed-By: pst 
Responsible-Changed-When: Wed Feb 7 17:32:43 PST 1996 
Responsible-Changed-Why:  
Responsible-Changed-From-To: pst->wpaul 
Responsible-Changed-By: pst 
Responsible-Changed-When: Thu Feb 8 17:24:53 PST 1996 
Responsible-Changed-Why:  
I've applied the workarround, but the real fix is to change getpwnam() 
to call a version of getgrnam() that is reentrant.  This is YP related 
(indirectly). 
State-Changed-From-To: open->suspended 
State-Changed-By: phk 
State-Changed-When: Sun Apr 12 10:47:11 PDT 1998 
State-Changed-Why:  
->suspended 


Responsible-Changed-From-To: wpaul->freebsd-bugs@freebsd.org 
Responsible-Changed-By: phk 
Responsible-Changed-When: Sun Apr 12 10:47:11 PDT 1998 
Responsible-Changed-Why:  
->suspended 
Responsible-Changed-From-To: freebsd-bugs@freebsd.org->freebsd-bugs 
Responsible-Changed-By: steve 
Responsible-Changed-When: Sun May 3 16:09:51 PDT 1998 
Responsible-Changed-Why:  
No need to have the '@freebsd.org' appended. 
State-Changed-From-To: suspended->closed 
State-Changed-By: mpp 
State-Changed-When: Fri Mar 23 16:42:24 PST 2001 
State-Changed-Why:  
install was fixed a long time ago to work around the problem stated 
in the PR.  Since that time, libc has also been modified so that 
the getpw* routines do not call the getgr* routines, which caused 
problems for programs that did something like: 

gp = getgrnam("wheel"); 
pw = getpwnam("jouser"); 

and then found that the data pointed to by "gp" was invalidated by the 
getpwnam() call. 

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


