Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10 5/3/83; site umcp-cs.UUCP
Path: utzoo!watmath!clyde!burl!ulysses!mhuxl!houxm!houxz!vax135!floyd!cmcl2!seismo!rlgvax!cvl!umcp-cs!fred
From: fred@umcp-cs.UUCP
Newsgroups: net.sources
Subject: improvement to ``getgrent()''
Message-ID: <7446@umcp-cs.UUCP>
Date: Sun, 10-Jun-84 19:06:44 EDT
Article-I.D.: umcp-cs.7446
Posted: Sun Jun 10 19:06:44 1984
Date-Received: Mon, 11-Jun-84 23:46:53 EDT
Distribution: net
Organization: Univ. of Maryland, Computer Science Dept.
Lines: 64

The routine ``getgrent()'' as distributed with Berkeley Unix 4.1
has a static array declaration:

	#define	MAXGRP	100
	static char *gr_mem[MAXGRP];

This leads to all sorts of problems if the number of members of
any group becomes larger than MAXGRP. You must change the value of
MAXGRP and recompile the library routine, and all the programs
which use it. To solve this problem once and for all, I've modified
the routine to call ``malloc()'' to dynamically allocate enough
space for the array.

Changes to the file ``getgrent.c'' are given in this diff script.
The version of the file it applies to begins with the line:

	/* @(#)getgrent.c	4.1 (Berkeley) 12/21/80 */

+-- (and don't forget to strip off column 1 before running it! ;-) )
V

|56a
|	{
|		int mem_count;
|		char *cp;
|
|		for (cp = p, mem_count = 0; *cp; mem_count++)
|			while (*cp && *cp++ != CM);
|
|		if ((int)(gr_mem = (char **)malloc((int)((mem_count + 1)
|							* sizeof(char *)))) < 1)
|			return(NULL);
|	}
|	group.gr_mem = gr_mem;
|.
|54d
|46a
|	if (gr_mem) {
|		free(gr_mem);
|		gr_mem =  (char **)0;
|	}
|.
|29a
|
|	if (gr_mem) {
|		free(gr_mem);
|		gr_mem =  (char **)0;
|	}
|.
|21a
|
|	if (gr_mem) {
|		free(gr_mem);
|		gr_mem =  (char **)0;
|	}
|.
|14c
|static char **gr_mem = (char **)0;
|.
|8d
|1a
|/* Hacked to allow arbitrary numbers of users in a group: 12-Jan-84 FLB */
|
|.