History log of /openbsd-current/lib/libc/gen/getgrent.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.50 02-Aug-2022 deraadt

1) The yp_bind/yp_unbind and internal _yp_dobind/_yp_unbind sequences shared
dom_binding structs between threads, which is unsafe -- example, dom_vers
signalled retry events, and structs+socket would get deallocated in _yp_unbind.
Change all yp_first (and similar) functions to understand that _yp_dobind now
provides a private dom_binding and socket, which must be released using
_yp_unbind. Use similar methods in the one-step yp_all function.
2) domainname caching in get* is not neccessary now that the domainname cannot
change relative to ypconnect(2)'s decisions.
Many fields in dom_binding struct become unused, so delete them.
ok jmatthew, also tested by miod


# 1.49 17-Jul-2022 deraadt

since yp_bind() and yp_all() don't use open, fstat, read, socket, and other
rich system calls to perform YP/LDAP lookups, there is no need to access()
/var/run/ypbind.lock to "hint" to pledge that it should open up those system
calls.
ok jmatthew, miod


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE OPENBSD_7_1_BASE
# 1.48 02-Jul-2019 deraadt

The "always hint that getpw operation is happening with access() the YP
lock file" would trash errno, creating confusion.
One instance found by richardipsum@fastmail, other two identified from
original commit
ok millert


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.47 13-Sep-2018 millert

Add uid_from_user() and gid_from_group(), derived from pax's cache.c.
It replaces the existing pwcache.c functions user_from_uid(3) and
group_from_gid(3) with the pax equivalents. Adapted from NetBSD
(mycroft) changes from our own pax's cache.c. OK guenther@


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.46 01-Dec-2015 deraadt

modify getpw*(), getgr*(), and getgrouplist() functions to access the
YP lock file unconditionally. This hints to the kernel that a "getpw"
operation is happening, even in the non-YP case. This looks like a
gruesome hack, but helps refine the ways these functions are called
and mandates the right pledge requests. Once the tree is fully annotated
we will know better how to improve the backing store management.
ok semarie espie beck


# 1.45 24-Nov-2015 millert

Use reentrant versions of getpw{nam,uid} and getgr{nam,gid} within
libc to avoid reusing the static buffers returned by the non-reentrant
versions. Since this is inside libc we can use constants for the
buffer sizes instead of having to call sysconf().
OK guenther@ deraadt@


# 1.44 14-Sep-2015 tedu

remove null check before free. from Michael McConville
ok semarie


# 1.43 13-Sep-2015 guenther

Wrap <grp.h> so that calls go direct and the symbols are all weak.


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.42 16-Jan-2015 deraadt

Move to the <limits.h> universe.
review by millert, binary checking process with doug, concept with guenther


# 1.41 15-Sep-2014 guenther

When fopen()ing internal to libc (the API doesn't support the use
of the resulting FILE *), then pass fopen() the 'e' mode letter to
mark it close-on-exec.

ok miod@


Revision tags: OPENBSD_5_6_BASE
# 1.40 12-Mar-2014 schwarze

Make sure that setgrent(), endgrent(), and endpwent() do not clobber
errno; they might do so on open() and close() failures, but by POSIX,
they are not supposed to fail. Note that ignoring failures inside
setgrent() does not matter, the following getgrent() is bound to
fail the same way again, anyway. If you insist on detecting open()
failure, use setgroupent(), even though that is less portable.
While here, remove two pointless (void) casts.
ok millert@ jca@


# 1.39 05-Mar-2014 schwarze

Fix the return values of getpwnam_r(), getpwuid_r(), getgrnam_r(),
and getgrgid_r() to agree with POSIX. Not touching errno handling
yet, which will also need fixing.

Problem originally reported by william at 25thandClement dot com on bugs@.
OK sthen@, and kettenis@ agrees it's "a step in the right direction".


Revision tags: OPENBSD_5_4_BASE OPENBSD_5_5_BASE
# 1.38 17-Apr-2013 tedu

add some prototypes, casts, includes, parenthesis, and whatnot to
silence some warnings.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.37 25-Apr-2011 sthen

Teach sysconf(_SC_GETGR_R_SIZE_MAX) the correct size of a buffer for the
reentrant getgrent functions (getgrgid_r, getgrnam_r).

seems reasonable to millert@, ok deraadt@


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.36 19-Dec-2009 schwarze

Implement proper error handling for getgrent(3), getgrnam(3) and getgrgid(3).

1) Distinguish normal end of data (like eof, YPERR_NOMORE, YPERR_KEY)
from error conditions.
2) Save errno(2) and restore it in case of success, as suggested by deraadt@
and beck@.

While this code is touched,
* move the common code for the yp_first and yp_next calls after the
respective if/else-block; note that free(data) is not needed in case of
failure and that __ypcurrent = NULL does no harm after failing yp_first.
* return 0, not NULL: the return value of grscan is int, not a pointer.

This is the last part of the work done on getgrent.c during c2k9,
heavily relying on the other improvements done at that time.
This has been rotting in my tree far too long.

"get it in" deraadt@; also lightly tested by simon@ some time ago


# 1.35 09-Nov-2009 kurt

Fix the handle locking in stdio to use flockfile/funlockfile
internally when and where required. Macros in <stdio.h> are updated
to automatically call the underlying functions when the process is
threaded to obtain the necessary locking. A private mutex is added
to protect __sglue, the internal list of FILE handles, and another
to protect the one-time initialization. Some routines in libc that
use getc() change to use getc_unlocked() as they're either protected
by their own lock or aren't thread-safe routines anyway.

committing on behalf of and okay guenther@ now that we have install
media space available.


# 1.34 22-Oct-2009 guenther

Back out previous commit, as it caused too much growth for the install
media to fit


# 1.33 21-Oct-2009 guenther

Fix the handle locking in stdio to use flockfile/funlockfile
internally when and where required. Macros in <stdio.h> are updated
to automatically call the underlying functions when the process is
threaded to obtain the necessary locking. A private mutex is added
to protect __sglue, the internal list of FILE handles, and another
to protect the one-time initialization. Some routines in libc that
use getc() change to use getc_unlocked() as they're either protected
by their own lock or aren't thread-safe routines anyway.

ok kurt@, earlier version tested by sthen@ and jj@


Revision tags: OPENBSD_4_6_BASE
# 1.32 07-Jun-2009 schwarze

de-spaghetti:
If code is used from exactly one place, don't jump back dozens of lines to
reach it, only to "goto" back where you came from.
Instead, simply put the code where it belongs.
Also fixes a regression that crept in in rev. 1.30: After clearing the
variable __ypmode, don't try to make decisions based on its former value.
As a bonus, garbage collect the grname variable and the _ypmode enum type.
ok millert@


# 1.31 07-Jun-2009 schwarze

No need to malloc, copy, have a single read access, and free right away.
Thus, garbage collect one variable, one strdup, one free, two ifs,
one else and a couple of assignments. No functional change.
ok millert@


# 1.30 05-Jun-2009 schwarze

The yp_bind(3) return code now distinguishes "YP not active" from "an error
occurred". Based on this, decide to either bail or use the record as is.
Prevents getgrnam(3) and friends from silently skipping YP records
on system errors, for example when out of memory.
Also, calling yp_get_default_domain once is enough.
The first two switch cases are unchanged, just reindented.
ok millert@


# 1.29 05-Jun-2009 schwarze

When parsing a line stating with "+" or "-" in group(5),
check whether YP is active up front, not half-way through the parsing.
This fixes the bug that group names starting with a dash (yuck!)
were skipped when YP was not active, introduced in rev. 1.27.
Besides, the code becomes easier to understand.
The code inside the two switch cases is unchanged, just reindented.
"looks good" millert@


# 1.28 04-Jun-2009 schwarze

in case a handling a +groupname:*:: entry fails due to lack of memory,
do not just skip the entry, but report the error condition;
ok millert@


# 1.27 03-Jun-2009 schwarze

Take advantage of the surprise libc bump to bring in
YP group(5) exclusion, i.e. support -groupname:*:: in /etc/group.
Such groups will be excluded from later +:*::,
in just the same was as it is already done for passwd(5).
I have been running this since the autumn of 2008.
Discussed with several (including deraadt@, millert@, jmc@).


Revision tags: OPENBSD_4_5_BASE
# 1.26 25-Aug-2008 deraadt

correct +name handling; schwarze@usta.de


Revision tags: OPENBSD_4_4_BASE
# 1.25 24-Jun-2008 deraadt

create a private getpwent()-like interface which does not walk the YP
groups map but instead tells us that it is there. then use this interface
in getgrouplist(), and do a single lookup against netid.byname instead to
get all the groups associated with that user
ok kurt, testing by many others


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE
# 1.24 16-May-2007 ray

Wrap some functions, labels, and variables in #ifdefs corresponding
to #ifdefs where they are used. Found by lint by bret dot lambert
at gmail.

OK deraadt@.


Revision tags: OPENBSD_3_8_BASE OPENBSD_3_9_BASE OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.23 08-Aug-2005 espie

zap remaining rcsid.

Kill old files that are no longer compiled.

okay theo


# 1.22 25-Mar-2005 otto

deregister (and deauto!). ok millert@ marco@


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.21 07-Jun-2004 marc

major bump to libc and libpthread to break the dependency of a
particular implementation of libpthread for libc. libc no longer
needs pthread.h to compile.
OK millert@, brad@, tedu@


# 1.20 18-May-2004 jfb

ansify function definitions and zap some `register'

ok millert@


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE
# 1.19 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


# 1.18 01-May-2003 avsm

add missing enumeration case to select to kill gcc warning
millert@ ok


Revision tags: OPENBSD_3_2_BASE OPENBSD_3_3_BASE
# 1.17 06-Jul-2002 deraadt

KNF


# 1.16 24-May-2002 deraadt

try to use strlcpy and snprintf more; ok various


Revision tags: OPENBSD_3_1_BASE
# 1.15 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


Revision tags: OPENBSD_3_0_BASE
# 1.14 11-Sep-2001 pvalchev

repair getgrgid_r() and getgrnam_r() as the standart says; from d@


Revision tags: OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.13 24-Sep-2000 d

unlock, instead of re-lock. fixes PR#1408


Revision tags: OPENBSD_2_7_BASE
# 1.12 08-Jan-2000 d

branches: 1.12.2;
fix sizeof's when aliasing reentrant structures.
(this caused group name lookups to fail)


# 1.11 06-Jan-2000 d

use thread-specific storage for the members list


Revision tags: OPENBSD_2_6_BASE
# 1.10 03-Sep-1999 millert

Use strtol() and strtoul() instead of atoi(). This allows us to catch
errors reasonably and deal correctly with unsigned quantities.


Revision tags: OPENBSD_2_5_BASE
# 1.9 20-Nov-1998 d

Add thread-safety to libc, so that libc_r will build (on i386 at least).
All POSIX libc api now there (to P1003.1c/D10)
(more md stuff is needed for other libc/arch/*)
(setlogin is no longer a special syscall)
Add -pthread option to gcc (that makes it use -lc_r and -D_POSIX_THREADS).
Doc some re-entrant routines
Add libc_r to intro(3)
dig() uses some libc srcs and an extra -I was needed there.
Add more md stuff to libc_r.
Update includes for the pthreads api
Update libc_r TODO


Revision tags: OPENBSD_2_3_BASE OPENBSD_2_4_BASE
# 1.8 19-Dec-1997 deraadt

gid_t is unsigned


Revision tags: OPENBSD_2_2_BASE
# 1.7 09-Jul-1997 millert

Clean up some -Wall complaints.


Revision tags: OPENBSD_2_1_BASE
# 1.6 25-Jan-1997 downsj

sync with NetBSD, changes from PR#3114, Michael.Eriksson@era-t.ericsson.se


Revision tags: OPENBSD_2_0_BASE
# 1.5 15-Sep-1996 tholo

Add a couple of syscalls; bring more prototypes into scope


# 1.4 19-Aug-1996 tholo

Fix RCS ids
Make sure everything uses {SYS,}LIBC_SCCS properly


# 1.3 24-Apr-1996 deraadt

yp_prot.h lies -> use yp.h (from yp.x) instead, change lots of structure
accesses to match. change xdr_domainname() and some other functions to
take "char **" instead of "char *", as rpcgen intended -- helps programs
linking against rpcgen output of yp.x. yp_all() should not free it's
return value. split xdryp.c and yplib.c into ~20 files so binaries like
"csh" need not link in functions like yp_maplist(). NIS+'s YP emulation
code lacks YPPROC_ORDER... attempt to deal nicely.


# 1.2 25-Mar-1996 tholo

Prototype internal functions
Do the right thing in presense of __STDC__


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.49 17-Jul-2022 deraadt

since yp_bind() and yp_all() don't use open, fstat, read, socket, and other
rich system calls to perform YP/LDAP lookups, there is no need to access()
/var/run/ypbind.lock to "hint" to pledge that it should open up those system
calls.
ok jmatthew, miod


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE OPENBSD_7_1_BASE
# 1.48 02-Jul-2019 deraadt

The "always hint that getpw operation is happening with access() the YP
lock file" would trash errno, creating confusion.
One instance found by richardipsum@fastmail, other two identified from
original commit
ok millert


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.47 13-Sep-2018 millert

Add uid_from_user() and gid_from_group(), derived from pax's cache.c.
It replaces the existing pwcache.c functions user_from_uid(3) and
group_from_gid(3) with the pax equivalents. Adapted from NetBSD
(mycroft) changes from our own pax's cache.c. OK guenther@


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.46 01-Dec-2015 deraadt

modify getpw*(), getgr*(), and getgrouplist() functions to access the
YP lock file unconditionally. This hints to the kernel that a "getpw"
operation is happening, even in the non-YP case. This looks like a
gruesome hack, but helps refine the ways these functions are called
and mandates the right pledge requests. Once the tree is fully annotated
we will know better how to improve the backing store management.
ok semarie espie beck


# 1.45 24-Nov-2015 millert

Use reentrant versions of getpw{nam,uid} and getgr{nam,gid} within
libc to avoid reusing the static buffers returned by the non-reentrant
versions. Since this is inside libc we can use constants for the
buffer sizes instead of having to call sysconf().
OK guenther@ deraadt@


# 1.44 14-Sep-2015 tedu

remove null check before free. from Michael McConville
ok semarie


# 1.43 13-Sep-2015 guenther

Wrap <grp.h> so that calls go direct and the symbols are all weak.


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.42 16-Jan-2015 deraadt

Move to the <limits.h> universe.
review by millert, binary checking process with doug, concept with guenther


# 1.41 15-Sep-2014 guenther

When fopen()ing internal to libc (the API doesn't support the use
of the resulting FILE *), then pass fopen() the 'e' mode letter to
mark it close-on-exec.

ok miod@


Revision tags: OPENBSD_5_6_BASE
# 1.40 12-Mar-2014 schwarze

Make sure that setgrent(), endgrent(), and endpwent() do not clobber
errno; they might do so on open() and close() failures, but by POSIX,
they are not supposed to fail. Note that ignoring failures inside
setgrent() does not matter, the following getgrent() is bound to
fail the same way again, anyway. If you insist on detecting open()
failure, use setgroupent(), even though that is less portable.
While here, remove two pointless (void) casts.
ok millert@ jca@


# 1.39 05-Mar-2014 schwarze

Fix the return values of getpwnam_r(), getpwuid_r(), getgrnam_r(),
and getgrgid_r() to agree with POSIX. Not touching errno handling
yet, which will also need fixing.

Problem originally reported by william at 25thandClement dot com on bugs@.
OK sthen@, and kettenis@ agrees it's "a step in the right direction".


Revision tags: OPENBSD_5_4_BASE OPENBSD_5_5_BASE
# 1.38 17-Apr-2013 tedu

add some prototypes, casts, includes, parenthesis, and whatnot to
silence some warnings.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.37 25-Apr-2011 sthen

Teach sysconf(_SC_GETGR_R_SIZE_MAX) the correct size of a buffer for the
reentrant getgrent functions (getgrgid_r, getgrnam_r).

seems reasonable to millert@, ok deraadt@


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.36 19-Dec-2009 schwarze

Implement proper error handling for getgrent(3), getgrnam(3) and getgrgid(3).

1) Distinguish normal end of data (like eof, YPERR_NOMORE, YPERR_KEY)
from error conditions.
2) Save errno(2) and restore it in case of success, as suggested by deraadt@
and beck@.

While this code is touched,
* move the common code for the yp_first and yp_next calls after the
respective if/else-block; note that free(data) is not needed in case of
failure and that __ypcurrent = NULL does no harm after failing yp_first.
* return 0, not NULL: the return value of grscan is int, not a pointer.

This is the last part of the work done on getgrent.c during c2k9,
heavily relying on the other improvements done at that time.
This has been rotting in my tree far too long.

"get it in" deraadt@; also lightly tested by simon@ some time ago


# 1.35 09-Nov-2009 kurt

Fix the handle locking in stdio to use flockfile/funlockfile
internally when and where required. Macros in <stdio.h> are updated
to automatically call the underlying functions when the process is
threaded to obtain the necessary locking. A private mutex is added
to protect __sglue, the internal list of FILE handles, and another
to protect the one-time initialization. Some routines in libc that
use getc() change to use getc_unlocked() as they're either protected
by their own lock or aren't thread-safe routines anyway.

committing on behalf of and okay guenther@ now that we have install
media space available.


# 1.34 22-Oct-2009 guenther

Back out previous commit, as it caused too much growth for the install
media to fit


# 1.33 21-Oct-2009 guenther

Fix the handle locking in stdio to use flockfile/funlockfile
internally when and where required. Macros in <stdio.h> are updated
to automatically call the underlying functions when the process is
threaded to obtain the necessary locking. A private mutex is added
to protect __sglue, the internal list of FILE handles, and another
to protect the one-time initialization. Some routines in libc that
use getc() change to use getc_unlocked() as they're either protected
by their own lock or aren't thread-safe routines anyway.

ok kurt@, earlier version tested by sthen@ and jj@


Revision tags: OPENBSD_4_6_BASE
# 1.32 07-Jun-2009 schwarze

de-spaghetti:
If code is used from exactly one place, don't jump back dozens of lines to
reach it, only to "goto" back where you came from.
Instead, simply put the code where it belongs.
Also fixes a regression that crept in in rev. 1.30: After clearing the
variable __ypmode, don't try to make decisions based on its former value.
As a bonus, garbage collect the grname variable and the _ypmode enum type.
ok millert@


# 1.31 07-Jun-2009 schwarze

No need to malloc, copy, have a single read access, and free right away.
Thus, garbage collect one variable, one strdup, one free, two ifs,
one else and a couple of assignments. No functional change.
ok millert@


# 1.30 05-Jun-2009 schwarze

The yp_bind(3) return code now distinguishes "YP not active" from "an error
occurred". Based on this, decide to either bail or use the record as is.
Prevents getgrnam(3) and friends from silently skipping YP records
on system errors, for example when out of memory.
Also, calling yp_get_default_domain once is enough.
The first two switch cases are unchanged, just reindented.
ok millert@


# 1.29 05-Jun-2009 schwarze

When parsing a line stating with "+" or "-" in group(5),
check whether YP is active up front, not half-way through the parsing.
This fixes the bug that group names starting with a dash (yuck!)
were skipped when YP was not active, introduced in rev. 1.27.
Besides, the code becomes easier to understand.
The code inside the two switch cases is unchanged, just reindented.
"looks good" millert@


# 1.28 04-Jun-2009 schwarze

in case a handling a +groupname:*:: entry fails due to lack of memory,
do not just skip the entry, but report the error condition;
ok millert@


# 1.27 03-Jun-2009 schwarze

Take advantage of the surprise libc bump to bring in
YP group(5) exclusion, i.e. support -groupname:*:: in /etc/group.
Such groups will be excluded from later +:*::,
in just the same was as it is already done for passwd(5).
I have been running this since the autumn of 2008.
Discussed with several (including deraadt@, millert@, jmc@).


Revision tags: OPENBSD_4_5_BASE
# 1.26 25-Aug-2008 deraadt

correct +name handling; schwarze@usta.de


Revision tags: OPENBSD_4_4_BASE
# 1.25 24-Jun-2008 deraadt

create a private getpwent()-like interface which does not walk the YP
groups map but instead tells us that it is there. then use this interface
in getgrouplist(), and do a single lookup against netid.byname instead to
get all the groups associated with that user
ok kurt, testing by many others


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE
# 1.24 16-May-2007 ray

Wrap some functions, labels, and variables in #ifdefs corresponding
to #ifdefs where they are used. Found by lint by bret dot lambert
at gmail.

OK deraadt@.


Revision tags: OPENBSD_3_8_BASE OPENBSD_3_9_BASE OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.23 08-Aug-2005 espie

zap remaining rcsid.

Kill old files that are no longer compiled.

okay theo


# 1.22 25-Mar-2005 otto

deregister (and deauto!). ok millert@ marco@


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.21 07-Jun-2004 marc

major bump to libc and libpthread to break the dependency of a
particular implementation of libpthread for libc. libc no longer
needs pthread.h to compile.
OK millert@, brad@, tedu@


# 1.20 18-May-2004 jfb

ansify function definitions and zap some `register'

ok millert@


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE
# 1.19 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


# 1.18 01-May-2003 avsm

add missing enumeration case to select to kill gcc warning
millert@ ok


Revision tags: OPENBSD_3_2_BASE OPENBSD_3_3_BASE
# 1.17 06-Jul-2002 deraadt

KNF


# 1.16 24-May-2002 deraadt

try to use strlcpy and snprintf more; ok various


Revision tags: OPENBSD_3_1_BASE
# 1.15 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


Revision tags: OPENBSD_3_0_BASE
# 1.14 11-Sep-2001 pvalchev

repair getgrgid_r() and getgrnam_r() as the standart says; from d@


Revision tags: OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.13 24-Sep-2000 d

unlock, instead of re-lock. fixes PR#1408


Revision tags: OPENBSD_2_7_BASE
# 1.12 08-Jan-2000 d

branches: 1.12.2;
fix sizeof's when aliasing reentrant structures.
(this caused group name lookups to fail)


# 1.11 06-Jan-2000 d

use thread-specific storage for the members list


Revision tags: OPENBSD_2_6_BASE
# 1.10 03-Sep-1999 millert

Use strtol() and strtoul() instead of atoi(). This allows us to catch
errors reasonably and deal correctly with unsigned quantities.


Revision tags: OPENBSD_2_5_BASE
# 1.9 20-Nov-1998 d

Add thread-safety to libc, so that libc_r will build (on i386 at least).
All POSIX libc api now there (to P1003.1c/D10)
(more md stuff is needed for other libc/arch/*)
(setlogin is no longer a special syscall)
Add -pthread option to gcc (that makes it use -lc_r and -D_POSIX_THREADS).
Doc some re-entrant routines
Add libc_r to intro(3)
dig() uses some libc srcs and an extra -I was needed there.
Add more md stuff to libc_r.
Update includes for the pthreads api
Update libc_r TODO


Revision tags: OPENBSD_2_3_BASE OPENBSD_2_4_BASE
# 1.8 19-Dec-1997 deraadt

gid_t is unsigned


Revision tags: OPENBSD_2_2_BASE
# 1.7 09-Jul-1997 millert

Clean up some -Wall complaints.


Revision tags: OPENBSD_2_1_BASE
# 1.6 25-Jan-1997 downsj

sync with NetBSD, changes from PR#3114, Michael.Eriksson@era-t.ericsson.se


Revision tags: OPENBSD_2_0_BASE
# 1.5 15-Sep-1996 tholo

Add a couple of syscalls; bring more prototypes into scope


# 1.4 19-Aug-1996 tholo

Fix RCS ids
Make sure everything uses {SYS,}LIBC_SCCS properly


# 1.3 24-Apr-1996 deraadt

yp_prot.h lies -> use yp.h (from yp.x) instead, change lots of structure
accesses to match. change xdr_domainname() and some other functions to
take "char **" instead of "char *", as rpcgen intended -- helps programs
linking against rpcgen output of yp.x. yp_all() should not free it's
return value. split xdryp.c and yplib.c into ~20 files so binaries like
"csh" need not link in functions like yp_maplist(). NIS+'s YP emulation
code lacks YPPROC_ORDER... attempt to deal nicely.


# 1.2 25-Mar-1996 tholo

Prototype internal functions
Do the right thing in presense of __STDC__


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.48 02-Jul-2019 deraadt

The "always hint that getpw operation is happening with access() the YP
lock file" would trash errno, creating confusion.
One instance found by richardipsum@fastmail, other two identified from
original commit
ok millert


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.47 13-Sep-2018 millert

Add uid_from_user() and gid_from_group(), derived from pax's cache.c.
It replaces the existing pwcache.c functions user_from_uid(3) and
group_from_gid(3) with the pax equivalents. Adapted from NetBSD
(mycroft) changes from our own pax's cache.c. OK guenther@


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.46 01-Dec-2015 deraadt

modify getpw*(), getgr*(), and getgrouplist() functions to access the
YP lock file unconditionally. This hints to the kernel that a "getpw"
operation is happening, even in the non-YP case. This looks like a
gruesome hack, but helps refine the ways these functions are called
and mandates the right pledge requests. Once the tree is fully annotated
we will know better how to improve the backing store management.
ok semarie espie beck


# 1.45 24-Nov-2015 millert

Use reentrant versions of getpw{nam,uid} and getgr{nam,gid} within
libc to avoid reusing the static buffers returned by the non-reentrant
versions. Since this is inside libc we can use constants for the
buffer sizes instead of having to call sysconf().
OK guenther@ deraadt@


# 1.44 14-Sep-2015 tedu

remove null check before free. from Michael McConville
ok semarie


# 1.43 13-Sep-2015 guenther

Wrap <grp.h> so that calls go direct and the symbols are all weak.


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.42 16-Jan-2015 deraadt

Move to the <limits.h> universe.
review by millert, binary checking process with doug, concept with guenther


# 1.41 15-Sep-2014 guenther

When fopen()ing internal to libc (the API doesn't support the use
of the resulting FILE *), then pass fopen() the 'e' mode letter to
mark it close-on-exec.

ok miod@


Revision tags: OPENBSD_5_6_BASE
# 1.40 12-Mar-2014 schwarze

Make sure that setgrent(), endgrent(), and endpwent() do not clobber
errno; they might do so on open() and close() failures, but by POSIX,
they are not supposed to fail. Note that ignoring failures inside
setgrent() does not matter, the following getgrent() is bound to
fail the same way again, anyway. If you insist on detecting open()
failure, use setgroupent(), even though that is less portable.
While here, remove two pointless (void) casts.
ok millert@ jca@


# 1.39 05-Mar-2014 schwarze

Fix the return values of getpwnam_r(), getpwuid_r(), getgrnam_r(),
and getgrgid_r() to agree with POSIX. Not touching errno handling
yet, which will also need fixing.

Problem originally reported by william at 25thandClement dot com on bugs@.
OK sthen@, and kettenis@ agrees it's "a step in the right direction".


Revision tags: OPENBSD_5_4_BASE OPENBSD_5_5_BASE
# 1.38 17-Apr-2013 tedu

add some prototypes, casts, includes, parenthesis, and whatnot to
silence some warnings.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.37 25-Apr-2011 sthen

Teach sysconf(_SC_GETGR_R_SIZE_MAX) the correct size of a buffer for the
reentrant getgrent functions (getgrgid_r, getgrnam_r).

seems reasonable to millert@, ok deraadt@


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.36 19-Dec-2009 schwarze

Implement proper error handling for getgrent(3), getgrnam(3) and getgrgid(3).

1) Distinguish normal end of data (like eof, YPERR_NOMORE, YPERR_KEY)
from error conditions.
2) Save errno(2) and restore it in case of success, as suggested by deraadt@
and beck@.

While this code is touched,
* move the common code for the yp_first and yp_next calls after the
respective if/else-block; note that free(data) is not needed in case of
failure and that __ypcurrent = NULL does no harm after failing yp_first.
* return 0, not NULL: the return value of grscan is int, not a pointer.

This is the last part of the work done on getgrent.c during c2k9,
heavily relying on the other improvements done at that time.
This has been rotting in my tree far too long.

"get it in" deraadt@; also lightly tested by simon@ some time ago


# 1.35 09-Nov-2009 kurt

Fix the handle locking in stdio to use flockfile/funlockfile
internally when and where required. Macros in <stdio.h> are updated
to automatically call the underlying functions when the process is
threaded to obtain the necessary locking. A private mutex is added
to protect __sglue, the internal list of FILE handles, and another
to protect the one-time initialization. Some routines in libc that
use getc() change to use getc_unlocked() as they're either protected
by their own lock or aren't thread-safe routines anyway.

committing on behalf of and okay guenther@ now that we have install
media space available.


# 1.34 22-Oct-2009 guenther

Back out previous commit, as it caused too much growth for the install
media to fit


# 1.33 21-Oct-2009 guenther

Fix the handle locking in stdio to use flockfile/funlockfile
internally when and where required. Macros in <stdio.h> are updated
to automatically call the underlying functions when the process is
threaded to obtain the necessary locking. A private mutex is added
to protect __sglue, the internal list of FILE handles, and another
to protect the one-time initialization. Some routines in libc that
use getc() change to use getc_unlocked() as they're either protected
by their own lock or aren't thread-safe routines anyway.

ok kurt@, earlier version tested by sthen@ and jj@


Revision tags: OPENBSD_4_6_BASE
# 1.32 07-Jun-2009 schwarze

de-spaghetti:
If code is used from exactly one place, don't jump back dozens of lines to
reach it, only to "goto" back where you came from.
Instead, simply put the code where it belongs.
Also fixes a regression that crept in in rev. 1.30: After clearing the
variable __ypmode, don't try to make decisions based on its former value.
As a bonus, garbage collect the grname variable and the _ypmode enum type.
ok millert@


# 1.31 07-Jun-2009 schwarze

No need to malloc, copy, have a single read access, and free right away.
Thus, garbage collect one variable, one strdup, one free, two ifs,
one else and a couple of assignments. No functional change.
ok millert@


# 1.30 05-Jun-2009 schwarze

The yp_bind(3) return code now distinguishes "YP not active" from "an error
occurred". Based on this, decide to either bail or use the record as is.
Prevents getgrnam(3) and friends from silently skipping YP records
on system errors, for example when out of memory.
Also, calling yp_get_default_domain once is enough.
The first two switch cases are unchanged, just reindented.
ok millert@


# 1.29 05-Jun-2009 schwarze

When parsing a line stating with "+" or "-" in group(5),
check whether YP is active up front, not half-way through the parsing.
This fixes the bug that group names starting with a dash (yuck!)
were skipped when YP was not active, introduced in rev. 1.27.
Besides, the code becomes easier to understand.
The code inside the two switch cases is unchanged, just reindented.
"looks good" millert@


# 1.28 04-Jun-2009 schwarze

in case a handling a +groupname:*:: entry fails due to lack of memory,
do not just skip the entry, but report the error condition;
ok millert@


# 1.27 03-Jun-2009 schwarze

Take advantage of the surprise libc bump to bring in
YP group(5) exclusion, i.e. support -groupname:*:: in /etc/group.
Such groups will be excluded from later +:*::,
in just the same was as it is already done for passwd(5).
I have been running this since the autumn of 2008.
Discussed with several (including deraadt@, millert@, jmc@).


Revision tags: OPENBSD_4_5_BASE
# 1.26 25-Aug-2008 deraadt

correct +name handling; schwarze@usta.de


Revision tags: OPENBSD_4_4_BASE
# 1.25 24-Jun-2008 deraadt

create a private getpwent()-like interface which does not walk the YP
groups map but instead tells us that it is there. then use this interface
in getgrouplist(), and do a single lookup against netid.byname instead to
get all the groups associated with that user
ok kurt, testing by many others


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE
# 1.24 16-May-2007 ray

Wrap some functions, labels, and variables in #ifdefs corresponding
to #ifdefs where they are used. Found by lint by bret dot lambert
at gmail.

OK deraadt@.


Revision tags: OPENBSD_3_8_BASE OPENBSD_3_9_BASE OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.23 08-Aug-2005 espie

zap remaining rcsid.

Kill old files that are no longer compiled.

okay theo


# 1.22 25-Mar-2005 otto

deregister (and deauto!). ok millert@ marco@


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.21 07-Jun-2004 marc

major bump to libc and libpthread to break the dependency of a
particular implementation of libpthread for libc. libc no longer
needs pthread.h to compile.
OK millert@, brad@, tedu@


# 1.20 18-May-2004 jfb

ansify function definitions and zap some `register'

ok millert@


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE
# 1.19 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


# 1.18 01-May-2003 avsm

add missing enumeration case to select to kill gcc warning
millert@ ok


Revision tags: OPENBSD_3_2_BASE OPENBSD_3_3_BASE
# 1.17 06-Jul-2002 deraadt

KNF


# 1.16 24-May-2002 deraadt

try to use strlcpy and snprintf more; ok various


Revision tags: OPENBSD_3_1_BASE
# 1.15 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


Revision tags: OPENBSD_3_0_BASE
# 1.14 11-Sep-2001 pvalchev

repair getgrgid_r() and getgrnam_r() as the standart says; from d@


Revision tags: OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.13 24-Sep-2000 d

unlock, instead of re-lock. fixes PR#1408


Revision tags: OPENBSD_2_7_BASE
# 1.12 08-Jan-2000 d

branches: 1.12.2;
fix sizeof's when aliasing reentrant structures.
(this caused group name lookups to fail)


# 1.11 06-Jan-2000 d

use thread-specific storage for the members list


Revision tags: OPENBSD_2_6_BASE
# 1.10 03-Sep-1999 millert

Use strtol() and strtoul() instead of atoi(). This allows us to catch
errors reasonably and deal correctly with unsigned quantities.


Revision tags: OPENBSD_2_5_BASE
# 1.9 20-Nov-1998 d

Add thread-safety to libc, so that libc_r will build (on i386 at least).
All POSIX libc api now there (to P1003.1c/D10)
(more md stuff is needed for other libc/arch/*)
(setlogin is no longer a special syscall)
Add -pthread option to gcc (that makes it use -lc_r and -D_POSIX_THREADS).
Doc some re-entrant routines
Add libc_r to intro(3)
dig() uses some libc srcs and an extra -I was needed there.
Add more md stuff to libc_r.
Update includes for the pthreads api
Update libc_r TODO


Revision tags: OPENBSD_2_3_BASE OPENBSD_2_4_BASE
# 1.8 19-Dec-1997 deraadt

gid_t is unsigned


Revision tags: OPENBSD_2_2_BASE
# 1.7 09-Jul-1997 millert

Clean up some -Wall complaints.


Revision tags: OPENBSD_2_1_BASE
# 1.6 25-Jan-1997 downsj

sync with NetBSD, changes from PR#3114, Michael.Eriksson@era-t.ericsson.se


Revision tags: OPENBSD_2_0_BASE
# 1.5 15-Sep-1996 tholo

Add a couple of syscalls; bring more prototypes into scope


# 1.4 19-Aug-1996 tholo

Fix RCS ids
Make sure everything uses {SYS,}LIBC_SCCS properly


# 1.3 24-Apr-1996 deraadt

yp_prot.h lies -> use yp.h (from yp.x) instead, change lots of structure
accesses to match. change xdr_domainname() and some other functions to
take "char **" instead of "char *", as rpcgen intended -- helps programs
linking against rpcgen output of yp.x. yp_all() should not free it's
return value. split xdryp.c and yplib.c into ~20 files so binaries like
"csh" need not link in functions like yp_maplist(). NIS+'s YP emulation
code lacks YPPROC_ORDER... attempt to deal nicely.


# 1.2 25-Mar-1996 tholo

Prototype internal functions
Do the right thing in presense of __STDC__


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.47 13-Sep-2018 millert

Add uid_from_user() and gid_from_group(), derived from pax's cache.c.
It replaces the existing pwcache.c functions user_from_uid(3) and
group_from_gid(3) with the pax equivalents. Adapted from NetBSD
(mycroft) changes from our own pax's cache.c. OK guenther@


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.46 01-Dec-2015 deraadt

modify getpw*(), getgr*(), and getgrouplist() functions to access the
YP lock file unconditionally. This hints to the kernel that a "getpw"
operation is happening, even in the non-YP case. This looks like a
gruesome hack, but helps refine the ways these functions are called
and mandates the right pledge requests. Once the tree is fully annotated
we will know better how to improve the backing store management.
ok semarie espie beck


# 1.45 24-Nov-2015 millert

Use reentrant versions of getpw{nam,uid} and getgr{nam,gid} within
libc to avoid reusing the static buffers returned by the non-reentrant
versions. Since this is inside libc we can use constants for the
buffer sizes instead of having to call sysconf().
OK guenther@ deraadt@


# 1.44 14-Sep-2015 tedu

remove null check before free. from Michael McConville
ok semarie


# 1.43 13-Sep-2015 guenther

Wrap <grp.h> so that calls go direct and the symbols are all weak.


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.42 16-Jan-2015 deraadt

Move to the <limits.h> universe.
review by millert, binary checking process with doug, concept with guenther


# 1.41 15-Sep-2014 guenther

When fopen()ing internal to libc (the API doesn't support the use
of the resulting FILE *), then pass fopen() the 'e' mode letter to
mark it close-on-exec.

ok miod@


Revision tags: OPENBSD_5_6_BASE
# 1.40 12-Mar-2014 schwarze

Make sure that setgrent(), endgrent(), and endpwent() do not clobber
errno; they might do so on open() and close() failures, but by POSIX,
they are not supposed to fail. Note that ignoring failures inside
setgrent() does not matter, the following getgrent() is bound to
fail the same way again, anyway. If you insist on detecting open()
failure, use setgroupent(), even though that is less portable.
While here, remove two pointless (void) casts.
ok millert@ jca@


# 1.39 05-Mar-2014 schwarze

Fix the return values of getpwnam_r(), getpwuid_r(), getgrnam_r(),
and getgrgid_r() to agree with POSIX. Not touching errno handling
yet, which will also need fixing.

Problem originally reported by william at 25thandClement dot com on bugs@.
OK sthen@, and kettenis@ agrees it's "a step in the right direction".


Revision tags: OPENBSD_5_4_BASE OPENBSD_5_5_BASE
# 1.38 17-Apr-2013 tedu

add some prototypes, casts, includes, parenthesis, and whatnot to
silence some warnings.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.37 25-Apr-2011 sthen

Teach sysconf(_SC_GETGR_R_SIZE_MAX) the correct size of a buffer for the
reentrant getgrent functions (getgrgid_r, getgrnam_r).

seems reasonable to millert@, ok deraadt@


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.36 19-Dec-2009 schwarze

Implement proper error handling for getgrent(3), getgrnam(3) and getgrgid(3).

1) Distinguish normal end of data (like eof, YPERR_NOMORE, YPERR_KEY)
from error conditions.
2) Save errno(2) and restore it in case of success, as suggested by deraadt@
and beck@.

While this code is touched,
* move the common code for the yp_first and yp_next calls after the
respective if/else-block; note that free(data) is not needed in case of
failure and that __ypcurrent = NULL does no harm after failing yp_first.
* return 0, not NULL: the return value of grscan is int, not a pointer.

This is the last part of the work done on getgrent.c during c2k9,
heavily relying on the other improvements done at that time.
This has been rotting in my tree far too long.

"get it in" deraadt@; also lightly tested by simon@ some time ago


# 1.35 09-Nov-2009 kurt

Fix the handle locking in stdio to use flockfile/funlockfile
internally when and where required. Macros in <stdio.h> are updated
to automatically call the underlying functions when the process is
threaded to obtain the necessary locking. A private mutex is added
to protect __sglue, the internal list of FILE handles, and another
to protect the one-time initialization. Some routines in libc that
use getc() change to use getc_unlocked() as they're either protected
by their own lock or aren't thread-safe routines anyway.

committing on behalf of and okay guenther@ now that we have install
media space available.


# 1.34 22-Oct-2009 guenther

Back out previous commit, as it caused too much growth for the install
media to fit


# 1.33 21-Oct-2009 guenther

Fix the handle locking in stdio to use flockfile/funlockfile
internally when and where required. Macros in <stdio.h> are updated
to automatically call the underlying functions when the process is
threaded to obtain the necessary locking. A private mutex is added
to protect __sglue, the internal list of FILE handles, and another
to protect the one-time initialization. Some routines in libc that
use getc() change to use getc_unlocked() as they're either protected
by their own lock or aren't thread-safe routines anyway.

ok kurt@, earlier version tested by sthen@ and jj@


Revision tags: OPENBSD_4_6_BASE
# 1.32 07-Jun-2009 schwarze

de-spaghetti:
If code is used from exactly one place, don't jump back dozens of lines to
reach it, only to "goto" back where you came from.
Instead, simply put the code where it belongs.
Also fixes a regression that crept in in rev. 1.30: After clearing the
variable __ypmode, don't try to make decisions based on its former value.
As a bonus, garbage collect the grname variable and the _ypmode enum type.
ok millert@


# 1.31 07-Jun-2009 schwarze

No need to malloc, copy, have a single read access, and free right away.
Thus, garbage collect one variable, one strdup, one free, two ifs,
one else and a couple of assignments. No functional change.
ok millert@


# 1.30 05-Jun-2009 schwarze

The yp_bind(3) return code now distinguishes "YP not active" from "an error
occurred". Based on this, decide to either bail or use the record as is.
Prevents getgrnam(3) and friends from silently skipping YP records
on system errors, for example when out of memory.
Also, calling yp_get_default_domain once is enough.
The first two switch cases are unchanged, just reindented.
ok millert@


# 1.29 05-Jun-2009 schwarze

When parsing a line stating with "+" or "-" in group(5),
check whether YP is active up front, not half-way through the parsing.
This fixes the bug that group names starting with a dash (yuck!)
were skipped when YP was not active, introduced in rev. 1.27.
Besides, the code becomes easier to understand.
The code inside the two switch cases is unchanged, just reindented.
"looks good" millert@


# 1.28 04-Jun-2009 schwarze

in case a handling a +groupname:*:: entry fails due to lack of memory,
do not just skip the entry, but report the error condition;
ok millert@


# 1.27 03-Jun-2009 schwarze

Take advantage of the surprise libc bump to bring in
YP group(5) exclusion, i.e. support -groupname:*:: in /etc/group.
Such groups will be excluded from later +:*::,
in just the same was as it is already done for passwd(5).
I have been running this since the autumn of 2008.
Discussed with several (including deraadt@, millert@, jmc@).


Revision tags: OPENBSD_4_5_BASE
# 1.26 25-Aug-2008 deraadt

correct +name handling; schwarze@usta.de


Revision tags: OPENBSD_4_4_BASE
# 1.25 24-Jun-2008 deraadt

create a private getpwent()-like interface which does not walk the YP
groups map but instead tells us that it is there. then use this interface
in getgrouplist(), and do a single lookup against netid.byname instead to
get all the groups associated with that user
ok kurt, testing by many others


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE
# 1.24 16-May-2007 ray

Wrap some functions, labels, and variables in #ifdefs corresponding
to #ifdefs where they are used. Found by lint by bret dot lambert
at gmail.

OK deraadt@.


Revision tags: OPENBSD_3_8_BASE OPENBSD_3_9_BASE OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.23 08-Aug-2005 espie

zap remaining rcsid.

Kill old files that are no longer compiled.

okay theo


# 1.22 25-Mar-2005 otto

deregister (and deauto!). ok millert@ marco@


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.21 07-Jun-2004 marc

major bump to libc and libpthread to break the dependency of a
particular implementation of libpthread for libc. libc no longer
needs pthread.h to compile.
OK millert@, brad@, tedu@


# 1.20 18-May-2004 jfb

ansify function definitions and zap some `register'

ok millert@


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE
# 1.19 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


# 1.18 01-May-2003 avsm

add missing enumeration case to select to kill gcc warning
millert@ ok


Revision tags: OPENBSD_3_2_BASE OPENBSD_3_3_BASE
# 1.17 06-Jul-2002 deraadt

KNF


# 1.16 24-May-2002 deraadt

try to use strlcpy and snprintf more; ok various


Revision tags: OPENBSD_3_1_BASE
# 1.15 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


Revision tags: OPENBSD_3_0_BASE
# 1.14 11-Sep-2001 pvalchev

repair getgrgid_r() and getgrnam_r() as the standart says; from d@


Revision tags: OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.13 24-Sep-2000 d

unlock, instead of re-lock. fixes PR#1408


Revision tags: OPENBSD_2_7_BASE
# 1.12 08-Jan-2000 d

branches: 1.12.2;
fix sizeof's when aliasing reentrant structures.
(this caused group name lookups to fail)


# 1.11 06-Jan-2000 d

use thread-specific storage for the members list


Revision tags: OPENBSD_2_6_BASE
# 1.10 03-Sep-1999 millert

Use strtol() and strtoul() instead of atoi(). This allows us to catch
errors reasonably and deal correctly with unsigned quantities.


Revision tags: OPENBSD_2_5_BASE
# 1.9 20-Nov-1998 d

Add thread-safety to libc, so that libc_r will build (on i386 at least).
All POSIX libc api now there (to P1003.1c/D10)
(more md stuff is needed for other libc/arch/*)
(setlogin is no longer a special syscall)
Add -pthread option to gcc (that makes it use -lc_r and -D_POSIX_THREADS).
Doc some re-entrant routines
Add libc_r to intro(3)
dig() uses some libc srcs and an extra -I was needed there.
Add more md stuff to libc_r.
Update includes for the pthreads api
Update libc_r TODO


Revision tags: OPENBSD_2_3_BASE OPENBSD_2_4_BASE
# 1.8 19-Dec-1997 deraadt

gid_t is unsigned


Revision tags: OPENBSD_2_2_BASE
# 1.7 09-Jul-1997 millert

Clean up some -Wall complaints.


Revision tags: OPENBSD_2_1_BASE
# 1.6 25-Jan-1997 downsj

sync with NetBSD, changes from PR#3114, Michael.Eriksson@era-t.ericsson.se


Revision tags: OPENBSD_2_0_BASE
# 1.5 15-Sep-1996 tholo

Add a couple of syscalls; bring more prototypes into scope


# 1.4 19-Aug-1996 tholo

Fix RCS ids
Make sure everything uses {SYS,}LIBC_SCCS properly


# 1.3 24-Apr-1996 deraadt

yp_prot.h lies -> use yp.h (from yp.x) instead, change lots of structure
accesses to match. change xdr_domainname() and some other functions to
take "char **" instead of "char *", as rpcgen intended -- helps programs
linking against rpcgen output of yp.x. yp_all() should not free it's
return value. split xdryp.c and yplib.c into ~20 files so binaries like
"csh" need not link in functions like yp_maplist(). NIS+'s YP emulation
code lacks YPPROC_ORDER... attempt to deal nicely.


# 1.2 25-Mar-1996 tholo

Prototype internal functions
Do the right thing in presense of __STDC__


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.46 01-Dec-2015 deraadt

modify getpw*(), getgr*(), and getgrouplist() functions to access the
YP lock file unconditionally. This hints to the kernel that a "getpw"
operation is happening, even in the non-YP case. This looks like a
gruesome hack, but helps refine the ways these functions are called
and mandates the right pledge requests. Once the tree is fully annotated
we will know better how to improve the backing store management.
ok semarie espie beck


# 1.45 24-Nov-2015 millert

Use reentrant versions of getpw{nam,uid} and getgr{nam,gid} within
libc to avoid reusing the static buffers returned by the non-reentrant
versions. Since this is inside libc we can use constants for the
buffer sizes instead of having to call sysconf().
OK guenther@ deraadt@


# 1.44 14-Sep-2015 tedu

remove null check before free. from Michael McConville
ok semarie


# 1.43 13-Sep-2015 guenther

Wrap <grp.h> so that calls go direct and the symbols are all weak.


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.42 16-Jan-2015 deraadt

Move to the <limits.h> universe.
review by millert, binary checking process with doug, concept with guenther


# 1.41 15-Sep-2014 guenther

When fopen()ing internal to libc (the API doesn't support the use
of the resulting FILE *), then pass fopen() the 'e' mode letter to
mark it close-on-exec.

ok miod@


Revision tags: OPENBSD_5_6_BASE
# 1.40 12-Mar-2014 schwarze

Make sure that setgrent(), endgrent(), and endpwent() do not clobber
errno; they might do so on open() and close() failures, but by POSIX,
they are not supposed to fail. Note that ignoring failures inside
setgrent() does not matter, the following getgrent() is bound to
fail the same way again, anyway. If you insist on detecting open()
failure, use setgroupent(), even though that is less portable.
While here, remove two pointless (void) casts.
ok millert@ jca@


# 1.39 05-Mar-2014 schwarze

Fix the return values of getpwnam_r(), getpwuid_r(), getgrnam_r(),
and getgrgid_r() to agree with POSIX. Not touching errno handling
yet, which will also need fixing.

Problem originally reported by william at 25thandClement dot com on bugs@.
OK sthen@, and kettenis@ agrees it's "a step in the right direction".


Revision tags: OPENBSD_5_4_BASE OPENBSD_5_5_BASE
# 1.38 17-Apr-2013 tedu

add some prototypes, casts, includes, parenthesis, and whatnot to
silence some warnings.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.37 25-Apr-2011 sthen

Teach sysconf(_SC_GETGR_R_SIZE_MAX) the correct size of a buffer for the
reentrant getgrent functions (getgrgid_r, getgrnam_r).

seems reasonable to millert@, ok deraadt@


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.36 19-Dec-2009 schwarze

Implement proper error handling for getgrent(3), getgrnam(3) and getgrgid(3).

1) Distinguish normal end of data (like eof, YPERR_NOMORE, YPERR_KEY)
from error conditions.
2) Save errno(2) and restore it in case of success, as suggested by deraadt@
and beck@.

While this code is touched,
* move the common code for the yp_first and yp_next calls after the
respective if/else-block; note that free(data) is not needed in case of
failure and that __ypcurrent = NULL does no harm after failing yp_first.
* return 0, not NULL: the return value of grscan is int, not a pointer.

This is the last part of the work done on getgrent.c during c2k9,
heavily relying on the other improvements done at that time.
This has been rotting in my tree far too long.

"get it in" deraadt@; also lightly tested by simon@ some time ago


# 1.35 09-Nov-2009 kurt

Fix the handle locking in stdio to use flockfile/funlockfile
internally when and where required. Macros in <stdio.h> are updated
to automatically call the underlying functions when the process is
threaded to obtain the necessary locking. A private mutex is added
to protect __sglue, the internal list of FILE handles, and another
to protect the one-time initialization. Some routines in libc that
use getc() change to use getc_unlocked() as they're either protected
by their own lock or aren't thread-safe routines anyway.

committing on behalf of and okay guenther@ now that we have install
media space available.


# 1.34 22-Oct-2009 guenther

Back out previous commit, as it caused too much growth for the install
media to fit


# 1.33 21-Oct-2009 guenther

Fix the handle locking in stdio to use flockfile/funlockfile
internally when and where required. Macros in <stdio.h> are updated
to automatically call the underlying functions when the process is
threaded to obtain the necessary locking. A private mutex is added
to protect __sglue, the internal list of FILE handles, and another
to protect the one-time initialization. Some routines in libc that
use getc() change to use getc_unlocked() as they're either protected
by their own lock or aren't thread-safe routines anyway.

ok kurt@, earlier version tested by sthen@ and jj@


Revision tags: OPENBSD_4_6_BASE
# 1.32 07-Jun-2009 schwarze

de-spaghetti:
If code is used from exactly one place, don't jump back dozens of lines to
reach it, only to "goto" back where you came from.
Instead, simply put the code where it belongs.
Also fixes a regression that crept in in rev. 1.30: After clearing the
variable __ypmode, don't try to make decisions based on its former value.
As a bonus, garbage collect the grname variable and the _ypmode enum type.
ok millert@


# 1.31 07-Jun-2009 schwarze

No need to malloc, copy, have a single read access, and free right away.
Thus, garbage collect one variable, one strdup, one free, two ifs,
one else and a couple of assignments. No functional change.
ok millert@


# 1.30 05-Jun-2009 schwarze

The yp_bind(3) return code now distinguishes "YP not active" from "an error
occurred". Based on this, decide to either bail or use the record as is.
Prevents getgrnam(3) and friends from silently skipping YP records
on system errors, for example when out of memory.
Also, calling yp_get_default_domain once is enough.
The first two switch cases are unchanged, just reindented.
ok millert@


# 1.29 05-Jun-2009 schwarze

When parsing a line stating with "+" or "-" in group(5),
check whether YP is active up front, not half-way through the parsing.
This fixes the bug that group names starting with a dash (yuck!)
were skipped when YP was not active, introduced in rev. 1.27.
Besides, the code becomes easier to understand.
The code inside the two switch cases is unchanged, just reindented.
"looks good" millert@


# 1.28 04-Jun-2009 schwarze

in case a handling a +groupname:*:: entry fails due to lack of memory,
do not just skip the entry, but report the error condition;
ok millert@


# 1.27 03-Jun-2009 schwarze

Take advantage of the surprise libc bump to bring in
YP group(5) exclusion, i.e. support -groupname:*:: in /etc/group.
Such groups will be excluded from later +:*::,
in just the same was as it is already done for passwd(5).
I have been running this since the autumn of 2008.
Discussed with several (including deraadt@, millert@, jmc@).


Revision tags: OPENBSD_4_5_BASE
# 1.26 25-Aug-2008 deraadt

correct +name handling; schwarze@usta.de


Revision tags: OPENBSD_4_4_BASE
# 1.25 24-Jun-2008 deraadt

create a private getpwent()-like interface which does not walk the YP
groups map but instead tells us that it is there. then use this interface
in getgrouplist(), and do a single lookup against netid.byname instead to
get all the groups associated with that user
ok kurt, testing by many others


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE
# 1.24 16-May-2007 ray

Wrap some functions, labels, and variables in #ifdefs corresponding
to #ifdefs where they are used. Found by lint by bret dot lambert
at gmail.

OK deraadt@.


Revision tags: OPENBSD_3_8_BASE OPENBSD_3_9_BASE OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.23 08-Aug-2005 espie

zap remaining rcsid.

Kill old files that are no longer compiled.

okay theo


# 1.22 25-Mar-2005 otto

deregister (and deauto!). ok millert@ marco@


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.21 07-Jun-2004 marc

major bump to libc and libpthread to break the dependency of a
particular implementation of libpthread for libc. libc no longer
needs pthread.h to compile.
OK millert@, brad@, tedu@


# 1.20 18-May-2004 jfb

ansify function definitions and zap some `register'

ok millert@


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE
# 1.19 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


# 1.18 01-May-2003 avsm

add missing enumeration case to select to kill gcc warning
millert@ ok


Revision tags: OPENBSD_3_2_BASE OPENBSD_3_3_BASE
# 1.17 06-Jul-2002 deraadt

KNF


# 1.16 24-May-2002 deraadt

try to use strlcpy and snprintf more; ok various


Revision tags: OPENBSD_3_1_BASE
# 1.15 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


Revision tags: OPENBSD_3_0_BASE
# 1.14 11-Sep-2001 pvalchev

repair getgrgid_r() and getgrnam_r() as the standart says; from d@


Revision tags: OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.13 24-Sep-2000 d

unlock, instead of re-lock. fixes PR#1408


Revision tags: OPENBSD_2_7_BASE
# 1.12 08-Jan-2000 d

branches: 1.12.2;
fix sizeof's when aliasing reentrant structures.
(this caused group name lookups to fail)


# 1.11 06-Jan-2000 d

use thread-specific storage for the members list


Revision tags: OPENBSD_2_6_BASE
# 1.10 03-Sep-1999 millert

Use strtol() and strtoul() instead of atoi(). This allows us to catch
errors reasonably and deal correctly with unsigned quantities.


Revision tags: OPENBSD_2_5_BASE
# 1.9 20-Nov-1998 d

Add thread-safety to libc, so that libc_r will build (on i386 at least).
All POSIX libc api now there (to P1003.1c/D10)
(more md stuff is needed for other libc/arch/*)
(setlogin is no longer a special syscall)
Add -pthread option to gcc (that makes it use -lc_r and -D_POSIX_THREADS).
Doc some re-entrant routines
Add libc_r to intro(3)
dig() uses some libc srcs and an extra -I was needed there.
Add more md stuff to libc_r.
Update includes for the pthreads api
Update libc_r TODO


Revision tags: OPENBSD_2_3_BASE OPENBSD_2_4_BASE
# 1.8 19-Dec-1997 deraadt

gid_t is unsigned


Revision tags: OPENBSD_2_2_BASE
# 1.7 09-Jul-1997 millert

Clean up some -Wall complaints.


Revision tags: OPENBSD_2_1_BASE
# 1.6 25-Jan-1997 downsj

sync with NetBSD, changes from PR#3114, Michael.Eriksson@era-t.ericsson.se


Revision tags: OPENBSD_2_0_BASE
# 1.5 15-Sep-1996 tholo

Add a couple of syscalls; bring more prototypes into scope


# 1.4 19-Aug-1996 tholo

Fix RCS ids
Make sure everything uses {SYS,}LIBC_SCCS properly


# 1.3 24-Apr-1996 deraadt

yp_prot.h lies -> use yp.h (from yp.x) instead, change lots of structure
accesses to match. change xdr_domainname() and some other functions to
take "char **" instead of "char *", as rpcgen intended -- helps programs
linking against rpcgen output of yp.x. yp_all() should not free it's
return value. split xdryp.c and yplib.c into ~20 files so binaries like
"csh" need not link in functions like yp_maplist(). NIS+'s YP emulation
code lacks YPPROC_ORDER... attempt to deal nicely.


# 1.2 25-Mar-1996 tholo

Prototype internal functions
Do the right thing in presense of __STDC__


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision