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. Fix: Change the API for setnetgrent() to return 1 on success, and 0 on failure. How-To-Repeat: The following code fail on FreeBSD. #include <netdb.h> int main() { int found = setnetgrent("non-existand-netgroup"); return 0; }
Responsible Changed From-To: freebsd-standards->freebsd-bugs Not a standards issue.
Responsible Changed From-To: freebsd-bugs->dwmalone I've suggested a patch.
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 *);
[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 over to the pool (approved by bugmeister)
The patch, after cleaning up some fuzz, does resolve the reported issue.
For bugs matching the following conditions: - Status == In Progress - Assignee == "bugs@FreeBSD.org" - Last Modified Year <= 2017 Do - Set Status to "Open"
This appears to have been fixed long ago (it was correct in base r1573), so I'm going to close it.