From pere@nuug.no  Sun Dec  1 03:54:41 2002
Return-Path: <pere@nuug.no>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 7AF7437B401
	for <FreeBSD-gnats-submit@freebsd.org>; Sun,  1 Dec 2002 03:54:41 -0800 (PST)
Received: from nerdhaven.nuug.no (nerdhaven.nuug.no [158.36.191.135])
	by mx1.FreeBSD.org (Postfix) with ESMTP id DF65543EBE
	for <FreeBSD-gnats-submit@freebsd.org>; Sun,  1 Dec 2002 03:54:40 -0800 (PST)
	(envelope-from pere@nuug.no)
Received: by nerdhaven.nuug.no (Postfix, from userid 1020)
	id EE83612; Sun,  1 Dec 2002 12:54:31 +0100 (CET)
Message-Id: <20021201115431.EE83612@nerdhaven.nuug.no>
Date: Sun,  1 Dec 2002 12:54:31 +0100 (CET)
From: Petter Reinholdtsen <pere@hungry.com>
Reply-To: Petter Reinholdtsen <pere@hungry.com>
To: FreeBSD-gnats-submit@freebsd.org
Cc: pere@hungry.com
Subject: setnetgrent() should return error code
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         45896
>Category:       kern
>Synopsis:       setnetgrent(3) should return error code
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sun Dec 01 04:00:02 PST 2002
>Closed-Date:    
>Last-Modified:  Tue Jul 10 03:41:49 UTC 2012
>Originator:     Petter Reinholdtsen
>Release:        FreeBSD 4.7-RELEASE-p1 i386
>Organization:
The Hungry Programmers
>Environment:
System: FreeBSD nerdhaven.nuug.no 4.7-RELEASE-p1 FreeBSD 4.7-RELEASE-p1 #0: Sun Oct 27 09:49:54 CET 2002 root@nerdhaven.nuug.no:/usr/obj/usr/src/sys/NERDHAVEN i386


	
>Description:
	The current setnetgrent() call do not return any value.  This
	make it impossible to detect the difference between an non-existand
	netgroup, and an empty netgroup.  The same call return 'int' on most
	other Unices (Solaris, HP/UX, Tru64 Unix, Darwin, Linux).  The value
	on these unixes is 1 if the group exist, and 0 if it is missing.
>How-To-Repeat:
	The following code fail on FreeBSD.
		#include <netdb.h>
		int main()
		{
			int found = setnetgrent("non-existand-netgroup");
			return 0;
		}
	
>Fix:
	Change the API for setnetgrent() to return 1 on success, and 0
	on failure.
	
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-standards->freebsd-bugs 
Responsible-Changed-By: mike 
Responsible-Changed-When: Sun Dec 1 07:26:24 PST 2002 
Responsible-Changed-Why:  
Not a standards issue. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=45896 
Responsible-Changed-From-To: freebsd-bugs->dwmalone 
Responsible-Changed-By: dwmalone 
Responsible-Changed-When: Sat Dec 21 07:42:17 PST 2002 
Responsible-Changed-Why:  
I've suggested a patch. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=45896 

From: David Malone <dwmalone@maths.tcd.ie>
To: freebsd-gnats-submit@FreeBSD.org, pere@hungry.com
Cc:  
Subject: Re: bin/45896: setnetgrent() should return error code
Date: Sat, 21 Dec 2002 15:55:09 +0000

 Could you test the following patch and check it does what you wanted?
 
 	David.
 
 Index: gen/getnetgrent.3
 ===================================================================
 RCS file: /cvs/FreeBSD-CVS/src/lib/libc/gen/getnetgrent.3,v
 retrieving revision 1.11
 diff -u -r1.11 getnetgrent.3
 --- gen/getnetgrent.3	18 Dec 2002 10:13:54 -0000	1.11
 +++ gen/getnetgrent.3	21 Dec 2002 15:46:58 -0000
 @@ -49,7 +49,7 @@
  .Fn getnetgrent "char **host" "char **user" "char **domain"
  .Ft int
  .Fn innetgr "const char *netgroup" "const char *host" "const char *user" "const char *domain"
 -.Ft void
 +.Ft int
  .Fn setnetgrent "const char *netgroup"
  .Ft void
  .Fn endnetgrent void
 @@ -105,14 +105,14 @@
  The function
  .Fn getnetgrent
  returns 0 for ``no more netgroup members'' and 1 otherwise.
 -The function
 -.Fn innetgr
 -returns 1 for a successful match and 0 otherwise.
  The functions
 -.Fn setnetgrent
 +.Fn innetgr
  and
 +.Fn setnetgrent
 +return 1 for success and 0 otherwise.
 +The function
  .Fn endnetgrent
 -have no return value.
 +has no return value.
  .Sh FILES
  .Bl -tag -width /etc/netgroup -compact
  .It Pa /etc/netgroup
 Index: gen/getnetgrent.c
 ===================================================================
 RCS file: /cvs/FreeBSD-CVS/src/lib/libc/gen/getnetgrent.c,v
 retrieving revision 1.28
 diff -u -r1.28 getnetgrent.c
 --- gen/getnetgrent.c	25 Apr 2002 18:14:39 -0000	1.28
 +++ gen/getnetgrent.c	21 Dec 2002 15:50:24 -0000
 @@ -137,8 +137,8 @@
  static FILE *netf = (FILE *)0;
  static int parse_netgrp();
  static struct linelist *read_for_group();
 -void setnetgrent(), endnetgrent();
 -int getnetgrent(), innetgr();
 +void endnetgrent();
 +int setnetgrent(), getnetgrent(), innetgr();
  
  #define	LINSIZ	1024	/* Length of netgroup file line */
  
 @@ -148,7 +148,7 @@
   * of netgrp structures. Let parse_netgrp() and read_for_group() do
   * most of the work.
   */
 -void
 +int
  setnetgrent(group)
  	char *group;
  {
 @@ -160,7 +160,7 @@
  	/* Sanity check */
  
  	if (group == NULL || !strlen(group))
 -		return;
 +		return 0;
  
  	if (grouphead.gr == (struct netgrp *)0 ||
  		strcmp(group, grouphead.grname)) {
 @@ -196,7 +196,7 @@
  				/* dohw! */
  				if (netf != NULL)
  					fclose(netf);
 -				return;
 +				return 0;
  			}
  #else
  		if (netf = fopen(_PATH_NETGROUP, "r")) {
 @@ -213,6 +213,7 @@
  		}
  	}
  	nextgrp = grouphead.gr;
 +	return 1;
  }
  
  /*
 Index: gen/getpwent.c
 ===================================================================
 RCS file: /cvs/FreeBSD-CVS/src/lib/libc/gen/getpwent.c,v
 retrieving revision 1.67
 diff -u -r1.67 getpwent.c
 --- gen/getpwent.c	7 May 2002 23:26:00 -0000	1.67
 +++ gen/getpwent.c	21 Dec 2002 15:45:09 -0000
 @@ -64,7 +64,7 @@
  #endif
  #include "un-namespace.h"
  
 -extern void setnetgrent(char *);
 +extern int setnetgrent(char *);
  extern int getnetgrent(char **, char **, char **);
  extern int innetgr(const char *, const char *, const char *, const char *);
  

From: Petter Reinholdtsen <pere@hungry.com>
To: David Malone <dwmalone@maths.tcd.ie>
Cc: freebsd-gnats-submit@FreeBSD.org
Subject: Re: bin/45896: setnetgrent() should return error code
Date: 07 Jan 2003 16:17:40 +0100

 [David Malone]
 > Could you test the following patch and check it does what you wanted?
 
 Checking the source, I believe it does the right thing.
 Unfortunately, I do not have access to a FreeBSD-box where I can
 recompile the c library, so I can't test the patch.
 
 If you have such box, you can fetch
 ftp://ftp.hungry.com/pub/hungry/ng-utils/ng-utils-0.3.tar.gz and see
 if it detects a broken or correct setnetgrent.
 
 Should the patch update a public header file as well?
Responsible-Changed-From-To: dwmalone->freebsd-bugs 
Responsible-Changed-By: eadler 
Responsible-Changed-When: Tue Jul 10 03:41:48 UTC 2012 
Responsible-Changed-Why:  
over to the pool (approved by bugmeister) 

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