From steve@Math.Berkeley.EDU  Tue Aug 20 06:29:14 2002
Return-Path: <steve@Math.Berkeley.EDU>
Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 4F62F37B400
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 20 Aug 2002 06:29:14 -0700 (PDT)
Received: from Math.Berkeley.EDU (gold.Math.Berkeley.EDU [169.229.58.61])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 9485D43E77
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 20 Aug 2002 06:29:13 -0700 (PDT)
	(envelope-from steve@Math.Berkeley.EDU)
Received: from bootjack.math.berkeley.edu (root@bootjack.Math.Berkeley.EDU [169.229.58.46])
	by Math.Berkeley.EDU (8.12.3/8.12.3) with ESMTP id g7KDTD0n019833
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 20 Aug 2002 06:29:13 -0700 (PDT)
Received: from bootjack.math.berkeley.edu (steve@localhost [127.0.0.1])
	by bootjack.math.berkeley.edu (8.12.3/8.12.3) with ESMTP id g7KDTC80038541
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 20 Aug 2002 06:29:12 -0700 (PDT)
	(envelope-from steve@bootjack.math.berkeley.edu)
Received: (from steve@localhost)
	by bootjack.math.berkeley.edu (8.12.3/8.12.3/Submit) id g7KDTCIY038540;
	Tue, 20 Aug 2002 06:29:12 -0700 (PDT)
Message-Id: <200208201329.g7KDTCIY038540@bootjack.math.berkeley.edu>
Date: Tue, 20 Aug 2002 06:29:12 -0700 (PDT)
From: Steve Sizemore <steve@ls.berkeley.edu>
Reply-To: Steve Sizemore <steve@ls.berkeley.edu>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: pw groupshow doesn't include the login group
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         41817
>Category:       bin
>Synopsis:       [patch] pw(8): pw groupshow doesn't include the login group
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Aug 20 06:30:02 PDT 2002
>Closed-Date:    
>Last-Modified:  Fri Jun 15 23:53:34 GMT 2007
>Originator:     Steve Sizemore
>Release:        FreeBSD 4.6.2-RELEASE i386
>Organization:
UC Berkeley College of Letters & Science
>Environment:
System: FreeBSD bootjack.math.berkeley.edu 4.6.2-RELEASE FreeBSD 4.6.2-RELEASE #0: Sat Aug 17 08:31:09 PDT 2002 root@chevalley.math.berkeley.edu:/usr/obj/usr/src/sys/MATH i386

>Description:
	The groupshow option of the pw command is supposed to show all
	members of a group. In fact, it only shows the members which
	are listed in the /etc/group file, omitting the default login
	groups specified in /etc/passwd.

>How-To-Repeat:
	/usr/sbin/pw groupshow operator

>Fix:

	


>Release-Note:
>Audit-Trail:

From: Steve Sizemore <steve@Math.Berkeley.EDU>
To: Juan Salaverria <rael@vectorstar.net>
Cc: freebsd-gnats-submit@FreeBSD.org, steve@ls.berkeley.edu
Subject: Re: misc/41817: pw groupshow doesn't include the login group
Date: Sat, 31 Aug 2002 07:09:19 -0700

 Hi, Juan - thanks for the reply.
 
 On Sat, Aug 31, 2002 at 04:36:57AM -0300, Juan Salaverria wrote:
 > Hi, I'm not sure if this is a bug of the program, because this 
 > behaviour is explained in the FreeBSD Handbook on the 
 > http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/users-groups.html
 > page (look at the "Example 8-8. Adding Somebody to a Group Using pw(8)"
 > entry) 
 > 
 > I sent an email to the maintainer a couple weeks ago, asking 
 > about the nature of this problem, and I didn't get any response yet.
 > 
 > If it's a bug, maybe I can submit a patch to take care of the initial
 > groups listed at the /etc/passwd file.
 
 I would maintain that it's a bug, either in pw, or in the man page.
 The man page doesn't mention the limitation pointed out in the
 Handbook. (I hadn't seen that section of the Handbook - thanks for
 pointing it out.) Displaying all of the members of a group is a useful
 function, which pw would fill if it performed according to the man
 page. I couldn't find any other system program which would do that.
 
 Of course, it's easy to write a program to do it, but why duplicate
 the function of an existing program? (Assuming that pw can actually
 be fixed easily to do that...)
 
 For me, it's not a critical problem, so I'm happy enough to wait
 for a response from the maintainer. 
 
 Thanks.
 Steve
 -- 
 Steve Sizemore <steve@ls.berkeley.edu>, (510) 642-8570
 Unix System Manager
     Dept. of Mathematics and College of Letters and Science
     University of California, Berkeley

From: Juan Salaverria <rael@vectorstar.net>
To: freebsd-gnats-submit@FreeBSD.org
Cc:  
Subject: Re: misc/41817: pw groupshow doesn't include the login group
Date: 04 Sep 2002 20:42:08 -0300

 Hi Steve, I spent some time at weekend and made a patch to 
 deal with this problem. Please take a look at it, I tested it 
 with few users and it's working. If you found any problem just 
 tell me and I'll work on it. 
 Cheers, 
 
 Juan 
 
 
 diff -ruN usr.sbin/pw.ori/pw_group.c usr.sbin/pw/pw_group.c 
 --- usr.sbin/pw.ori/pw_group.c  Wed Jun 28 16:19:04 2000 
 +++ usr.sbin/pw/pw_group.c      Mon Sep  2 09:10:20 2002 
 @@ -38,6 +38,7 @@ 
 #include "bitmap.h" 
 
 
 +static int     chk_usrname(char ** mem, char * usr); 
 static int      print_group(struct group * grp, int pretty); 
 static gid_t    gr_gidpolicy(struct userconf * cnf, struct cargs * 
 args); 
 
 @@ -51,6 +52,12 @@ 
         struct group   *grp = NULL; 
         int             grmembers = 0; 
         char           **members = NULL; 
 +        int            pwmembers = 0; 
 +        int            idx = 0; 
 +        int            idx_gr_mem = 0; 
 +        int            last_gr_mem= 0; 
 +       struct passwd   *usr_pass=NULL; 
 +        char           **pass_mem= NULL; 
 
         static struct group fakegroup = 
         { 
 @@ -95,6 +102,33 @@ 
         } 
         grp = (a_name != NULL) ? GETGRNAM(a_name->val) :
 GETGRGID((gid_t) 
 atoi(a_gid->val)); 
 
 +       /* This is to take care of the initial groups defined in the
 passwd 
 file */ 
 +        if (grp != NULL) { 
 +               extendarray(&pass_mem, &pwmembers, 200); 
 +               while (grp->gr_mem[idx] != NULL) ++idx; 
 +               last_gr_mem = idx; 
 +       
 +               SETPWENT(); 
 +               idx = 0; 
 +               while ((usr_pass= GETPWENT()) != NULL) { 
 +               
 +                       if ( (gid_t) usr_pass->pw_gid == (gid_t)
 grp->gr_gid ) { 
 +                               if (extendarray(&pass_mem, &pwmembers,
 idx + 2) != -1) { 
 +                                        pass_mem[idx] = 
 malloc(strlen(usr_pass->pw_name)+1); 
 +                                        strcpy(pass_mem[idx], 
 usr_pass->pw_name); 
 +                                       if (!chk_usrname(grp->gr_mem,
 pass_mem[idx])) { 
 +                                              
 grp->gr_mem[last_gr_mem+idx_gr_mem] = pass_mem[idx]; 
 +                                               idx_gr_mem++; 
 +                                       } 
 +                               idx++; 
 +                               } 
 +                       } 
 +               } 
 +               pass_mem[idx] = NULL; 
 +               grp->gr_mem[last_gr_mem+idx_gr_mem] = NULL; 
 +               ENDPWENT(); 
 +        } 
 + 
         if (mode == M_UPDATE || mode == M_DELETE || mode == M_PRINT) { 
                 if (a_name == NULL && grp == NULL)      /* Try harder */
                         grp = GETGRGID(atoi(a_gid->val)); 
 @@ -349,4 +383,18 @@ 
                 fputs("\n\n", stdout); 
         } 
         return EXIT_SUCCESS; 
 +} 
 + 
 +static int 
 +chk_usrname(char ** mem, char * usr) 
 +{ 
 +int u = 0; 
 + 
 +       while (mem[u] != NULL) { 
 +               if(!strcmp(mem[u],usr)) 
 +                       return 1; 
 +       u++; 
 +       } 
 + 
 +return 0; 
 }
 
 

From: Juan Salaverria <rael@vectorstar.net>
To: "freebsd-gnats-submit@FreeBSD.org" <freebsd-gnats-submit@FreeBSD.org>
Cc:  
Subject: Re: misc/41817: pw groupshow doesn't include the login group
Date: 04 Sep 2002 21:53:22 -0300

 Hi, I found some problems in the patch with white spaces.
 Here's the same patch with those problems fixed.
 
 Thanks
 
 Juan
 
 --- usr.sbin/pw/pw_group.c.ori	Wed Sep  4 21:24:49 2002
 +++ usr.sbin/pw/pw_group.c	Wed Sep  4 21:35:38 2002
 @@ -37,7 +37,7 @@
  #include "pw.h"
  #include "bitmap.h"
  
 -
 +static int     chk_usrname(char ** mem, char * usr);
  static int      print_group(struct group * grp, int pretty);
  static gid_t    gr_gidpolicy(struct userconf * cnf, struct cargs * args);
  
 @@ -51,6 +51,12 @@
  	struct group   *grp = NULL;
  	int	        grmembers = 0;
  	char           **members = NULL;
 +	int            pwmembers = 0;
 +	int            idx = 0;
 +	int            idx_gr_mem = 0;
 +	int            last_gr_mem= 0;
 +	struct passwd   *usr_pass=NULL;
 +	char           **pass_mem= NULL;
  
  	static struct group fakegroup =
  	{
 @@ -94,6 +100,33 @@
  		}
  	}
  	grp = (a_name != NULL) ? GETGRNAM(a_name->val) : GETGRGID((gid_t) atoi(a_gid->val));
 + 
 +	/* This is to take care of the initial groups defined in the passwd file */
 +	if (grp != NULL) {
 +		extendarray(&pass_mem, &pwmembers, 200);
 +		while (grp->gr_mem[idx] != NULL) ++idx;
 +		last_gr_mem = idx;
 +
 +		SETPWENT();
 +		idx = 0;
 +		while ((usr_pass= GETPWENT()) != NULL) {
 +
 +			if ( (gid_t) usr_pass->pw_gid == (gid_t) grp->gr_gid ) {
 +				if (extendarray(&pass_mem, &pwmembers, idx + 2) != -1) {
 +					pass_mem[idx] = malloc(strlen(usr_pass->pw_name)+1);
 +					strcpy(pass_mem[idx], usr_pass->pw_name);
 +					if (!chk_usrname(grp->gr_mem, pass_mem[idx])) {
 +						grp->gr_mem[last_gr_mem+idx_gr_mem] = pass_mem[idx];
 +						idx_gr_mem++;
 +					}
 +				idx++;
 +				}
 +			}
 +		}
 +		pass_mem[idx] = NULL;
 +		grp->gr_mem[last_gr_mem+idx_gr_mem] = NULL;
 +		ENDPWENT();
 +	}
  
  	if (mode == M_UPDATE || mode == M_DELETE || mode == M_PRINT) {
  		if (a_name == NULL && grp == NULL)	/* Try harder */
 @@ -350,3 +383,18 @@
  	}
  	return EXIT_SUCCESS;
  }
 + 
 +static int
 +chk_usrname(char ** mem, char * usr)
 +{
 +int u = 0;
 +
 +	while (mem[u] != NULL) {
 +		if(!strcmp(mem[u],usr))
 +			return 1;
 +	u++;
 +	}
 +
 +return 0;
 +}
 +
 
 

From: Juan Salaverria <rael@vectorstar.net>
To: freebsd-gnats-submit@FreeBSD.org
Cc:  
Subject: Re: misc/41817: pw groupshow doesn't include the login group
Date: 03 Sep 2002 21:48:48 -0300

 Hi Steve, I spent some time at weekend and made a patch to 
 deal with this problem. Please take a look at it, I tested it
 with few users and it's working. If you found any problem just
 tell me and I'll work on it.
 Cheers,
 
 Juan
 
 
 diff -ruN usr.sbin/pw.ori/pw_group.c usr.sbin/pw/pw_group.c
 --- usr.sbin/pw.ori/pw_group.c	Wed Jun 28 16:19:04 2000
 +++ usr.sbin/pw/pw_group.c	Mon Sep  2 09:10:20 2002
 @@ -38,6 +38,7 @@
  #include "bitmap.h"
  
  
 +static int 	chk_usrname(char ** mem, char * usr);
  static int      print_group(struct group * grp, int pretty);
  static gid_t    gr_gidpolicy(struct userconf * cnf, struct cargs *
 args);
  
 @@ -51,6 +52,12 @@
  	struct group   *grp = NULL;
  	int	        grmembers = 0;
  	char           **members = NULL;
 +        int		pwmembers = 0;
 +        int		idx = 0;
 +        int		idx_gr_mem = 0;
 +        int		last_gr_mem= 0;
 +	struct passwd	*usr_pass=NULL;
 +        char		**pass_mem= NULL;
  
  	static struct group fakegroup =
  	{
 @@ -95,6 +102,33 @@
  	}
  	grp = (a_name != NULL) ? GETGRNAM(a_name->val) : GETGRGID((gid_t)
 atoi(a_gid->val));
  
 +	/* This is to take care of the initial groups defined in the passwd
 file */ 
 +        if (grp != NULL) {
 +		extendarray(&pass_mem, &pwmembers, 200);
 +        	while (grp->gr_mem[idx] != NULL) ++idx;
 +		last_gr_mem = idx;
 +	
 +		SETPWENT();
 +		idx = 0;
 +		while ((usr_pass= GETPWENT()) != NULL) {
 + 		
 +			if ( (gid_t) usr_pass->pw_gid == (gid_t) grp->gr_gid ) {
 +				if (extendarray(&pass_mem, &pwmembers, idx + 2) != -1) {
 +                                        pass_mem[idx] =
 malloc(strlen(usr_pass->pw_name)+1);
 +                                        strcpy(pass_mem[idx],
 usr_pass->pw_name);
 +					if (!chk_usrname(grp->gr_mem, pass_mem[idx])) {
 +						grp->gr_mem[last_gr_mem+idx_gr_mem] = pass_mem[idx];
 +						idx_gr_mem++;
 +					}
 +				idx++;
 +                        	}
 +			}
 +		}
 +        	pass_mem[idx] = NULL;
 +		grp->gr_mem[last_gr_mem+idx_gr_mem] = NULL;
 +		ENDPWENT();
 +        }
 +
  	if (mode == M_UPDATE || mode == M_DELETE || mode == M_PRINT) {
  		if (a_name == NULL && grp == NULL)	/* Try harder */
  			grp = GETGRGID(atoi(a_gid->val));
 @@ -349,4 +383,18 @@
  		fputs("\n\n", stdout);
  	}
  	return EXIT_SUCCESS;
 +}
 +
 +static int
 +chk_usrname(char ** mem, char * usr)
 +{
 +int u = 0;
 +
 +	while (mem[u] != NULL) {
 +		if(!strcmp(mem[u],usr))
 +			return 1;
 +	u++;
 +	}
 +
 +return 0;
  }
 
 
 
>Unformatted:
