Blame man3/getgrent.3

Packit 7cfc04
.\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
Packit 7cfc04
.\"
Packit 7cfc04
.\" %%%LICENSE_START(VERBATIM)
Packit 7cfc04
.\" Permission is granted to make and distribute verbatim copies of this
Packit 7cfc04
.\" manual provided the copyright notice and this permission notice are
Packit 7cfc04
.\" preserved on all copies.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Permission is granted to copy and distribute modified versions of this
Packit 7cfc04
.\" manual under the conditions for verbatim copying, provided that the
Packit 7cfc04
.\" entire resulting derived work is distributed under the terms of a
Packit 7cfc04
.\" permission notice identical to this one.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Since the Linux kernel and libraries are constantly changing, this
Packit 7cfc04
.\" manual page may be incorrect or out-of-date.  The author(s) assume no
Packit 7cfc04
.\" responsibility for errors or omissions, or for damages resulting from
Packit 7cfc04
.\" the use of the information contained herein.  The author(s) may not
Packit 7cfc04
.\" have taken the same level of care in the production of this manual,
Packit 7cfc04
.\" which is licensed free of charge, as they might when working
Packit 7cfc04
.\" professionally.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Formatted or processed versions of this manual, if unaccompanied by
Packit 7cfc04
.\" the source, must acknowledge the copyright and authors of this work.
Packit 7cfc04
.\" %%%LICENSE_END
Packit 7cfc04
.\"
Packit 7cfc04
.\" References consulted:
Packit 7cfc04
.\"     Linux libc source code
Packit 7cfc04
.\"     Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
Packit 7cfc04
.\"     386BSD man pages
Packit 7cfc04
.\" Modified Sat Jul 24 19:29:54 1993 by Rik Faith (faith@cs.unc.edu)
Packit 7cfc04
.TH GETGRENT 3  2017-09-15 "" "Linux Programmer's Manual"
Packit 7cfc04
.SH NAME
Packit 7cfc04
getgrent, setgrent, endgrent \- get group file entry
Packit 7cfc04
.SH SYNOPSIS
Packit 7cfc04
.nf
Packit 7cfc04
.B #include <sys/types.h>
Packit 7cfc04
.B #include <grp.h>
Packit 7cfc04
.PP
Packit 7cfc04
.B struct group *getgrent(void);
Packit 7cfc04
.PP
Packit 7cfc04
.B void setgrent(void);
Packit 7cfc04
.PP
Packit 7cfc04
.B void endgrent(void);
Packit 7cfc04
.fi
Packit 7cfc04
.PP
Packit 7cfc04
.in -4n
Packit 7cfc04
Feature Test Macro Requirements for glibc (see
Packit 7cfc04
.BR feature_test_macros (7)):
Packit 7cfc04
.in
Packit 7cfc04
.PP
Packit 7cfc04
.PD 0
Packit 7cfc04
.ad l
Packit 7cfc04
.BR setgrent ():
Packit 7cfc04
.RS 4
Packit 7cfc04
_XOPEN_SOURCE\ >=\ 500
Packit 7cfc04
.\"    || _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
Packit 7cfc04
    || /* Glibc since 2.19: */ _DEFAULT_SOURCE
Packit 7cfc04
    || /* Glibc versions <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
Packit 7cfc04
.RE
Packit 7cfc04
.PP
Packit 7cfc04
.BR getgrent (),
Packit 7cfc04
.BR endgrent ():
Packit 7cfc04
.RS 4
Packit 7cfc04
Since glibc 2.22:
Packit 7cfc04
    _XOPEN_SOURCE\ >=\ 500 ||
Packit 7cfc04
.\"        || _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
Packit 7cfc04
        _DEFAULT_SOURCE
Packit 7cfc04
.br
Packit 7cfc04
Glibc 2.21 and earlier
Packit 7cfc04
    _XOPEN_SOURCE\ >=\ 500
Packit 7cfc04
.\"        || _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
Packit 7cfc04
        || /* Since glibc 2.12: */ _POSIX_C_SOURCE\ >=\ 200809L
Packit 7cfc04
        || /* Glibc versions <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
Packit 7cfc04
.RE
Packit 7cfc04
.PD
Packit 7cfc04
.ad b
Packit 7cfc04
.SH DESCRIPTION
Packit 7cfc04
The
Packit 7cfc04
.BR getgrent ()
Packit 7cfc04
function returns a pointer to a structure containing
Packit 7cfc04
the broken-out fields of a record in the group database
Packit 7cfc04
(e.g., the local group file
Packit 7cfc04
.IR /etc/group ,
Packit 7cfc04
NIS, and LDAP).
Packit 7cfc04
The first time
Packit 7cfc04
.BR getgrent ()
Packit 7cfc04
is called,
Packit 7cfc04
it returns the first entry; thereafter, it returns successive entries.
Packit 7cfc04
.PP
Packit 7cfc04
The
Packit 7cfc04
.BR setgrent ()
Packit 7cfc04
function rewinds to the beginning
Packit 7cfc04
of the group database, to allow repeated scans.
Packit 7cfc04
.PP
Packit 7cfc04
The
Packit 7cfc04
.BR endgrent ()
Packit 7cfc04
function is used to close the group database
Packit 7cfc04
after all processing has been performed.
Packit 7cfc04
.PP
Packit 7cfc04
The \fIgroup\fP structure is defined in \fI<grp.h>\fP as follows:
Packit 7cfc04
.PP
Packit 7cfc04
.in +4n
Packit 7cfc04
.EX
Packit 7cfc04
struct group {
Packit 7cfc04
    char   *gr_name;        /* group name */
Packit 7cfc04
    char   *gr_passwd;      /* group password */
Packit 7cfc04
    gid_t   gr_gid;         /* group ID */
Packit 7cfc04
    char  **gr_mem;         /* NULL-terminated array of pointers
Packit 7cfc04
                               to names of group members */
Packit 7cfc04
};
Packit 7cfc04
.EE
Packit 7cfc04
.in
Packit 7cfc04
.PP
Packit 7cfc04
For more information about the fields of this structure, see
Packit 7cfc04
.BR group (5).
Packit 7cfc04
.SH RETURN VALUE
Packit 7cfc04
The
Packit 7cfc04
.BR getgrent ()
Packit 7cfc04
function returns a pointer to a
Packit 7cfc04
.I group
Packit 7cfc04
structure,
Packit 7cfc04
or NULL if there are no more entries or an error occurs.
Packit 7cfc04
.PP
Packit 7cfc04
Upon error,
Packit 7cfc04
.I errno
Packit 7cfc04
may be set.
Packit 7cfc04
If one wants to check
Packit 7cfc04
.I errno
Packit 7cfc04
after the call, it should be set to zero before the call.
Packit 7cfc04
.PP
Packit 7cfc04
The return value may point to a static area, and may be overwritten
Packit 7cfc04
by subsequent calls to
Packit 7cfc04
.BR getgrent (),
Packit 7cfc04
.BR getgrgid (3),
Packit 7cfc04
or
Packit 7cfc04
.BR getgrnam (3).
Packit 7cfc04
(Do not pass the returned pointer to
Packit 7cfc04
.BR free (3).)
Packit 7cfc04
.SH ERRORS
Packit 7cfc04
.TP
Packit 7cfc04
.B EAGAIN
Packit 7cfc04
The service was temporarily unavailable; try again later.
Packit 7cfc04
For NSS backends in glibc this indicates a temporary error talking to the backend.
Packit 7cfc04
The error may correct itself, retrying later is suggested.
Packit 7cfc04
.TP
Packit 7cfc04
.B EINTR
Packit 7cfc04
A signal was caught; see
Packit 7cfc04
.BR signal (7).
Packit 7cfc04
.TP
Packit 7cfc04
.B EIO
Packit 7cfc04
I/O error.
Packit 7cfc04
.TP
Packit 7cfc04
.B EMFILE
Packit 7cfc04
The per-process limit on the number of open file descriptors has been reached.
Packit 7cfc04
.TP
Packit 7cfc04
.B ENFILE
Packit 7cfc04
The system-wide limit on the total number of open files has been reached.
Packit 7cfc04
.TP
Packit 7cfc04
.\" not in POSIX
Packit 7cfc04
.B ENOENT
Packit 7cfc04
A necessary input file cannot be found.
Packit 7cfc04
For NSS backends in glibc this indicates the backend is not correctly configured.
Packit 7cfc04
.TP
Packit 7cfc04
.B ENOMEM
Packit 7cfc04
.\" not in POSIX
Packit 7cfc04
Insufficient memory to allocate
Packit 7cfc04
.I group
Packit 7cfc04
structure.
Packit 7cfc04
.TP
Packit 7cfc04
.B ERANGE
Packit 7cfc04
Insufficient buffer space supplied.
Packit 7cfc04
.SH FILES
Packit 7cfc04
.TP
Packit 7cfc04
.I /etc/group
Packit 7cfc04
local group database file
Packit 7cfc04
.SH ATTRIBUTES
Packit 7cfc04
For an explanation of the terms used in this section, see
Packit 7cfc04
.BR attributes (7).
Packit 7cfc04
.TS
Packit 7cfc04
allbox;
Packit 7cfc04
lbw11 lb lb
Packit 7cfc04
l l l.
Packit 7cfc04
Interface	Attribute	Value
Packit 7cfc04
T{
Packit 7cfc04
.BR getgrent ()
Packit 7cfc04
T}	Thread safety	T{
Packit 7cfc04
MT-Unsafe race:grent
Packit 7cfc04
.br
Packit 7cfc04
race:grentbuf locale
Packit 7cfc04
T}
Packit 7cfc04
T{
Packit 7cfc04
.BR setgrent (),
Packit 7cfc04
.BR endgrent ()
Packit 7cfc04
T}	Thread safety	MT-Unsafe race:grent locale
Packit 7cfc04
.TE
Packit 7cfc04
.PP
Packit 7cfc04
In the above table,
Packit 7cfc04
.I grent
Packit 7cfc04
in
Packit 7cfc04
.I race:grent
Packit 7cfc04
signifies that if any of the functions
Packit 7cfc04
.BR setgrent (),
Packit 7cfc04
.BR getgrent (),
Packit 7cfc04
or
Packit 7cfc04
.BR endgrent ()
Packit 7cfc04
are used in parallel in different threads of a program,
Packit 7cfc04
then data races could occur.
Packit 7cfc04
.SH CONFORMING TO
Packit 7cfc04
POSIX.1-2001, POSIX.1-2008, SVr4, 4.3BSD.
Packit 7cfc04
.SH SEE ALSO
Packit 7cfc04
.BR fgetgrent (3),
Packit 7cfc04
.BR getgrent_r (3),
Packit 7cfc04
.BR getgrgid (3),
Packit 7cfc04
.BR getgrnam (3),
Packit 7cfc04
.BR getgrouplist (3),
Packit 7cfc04
.BR putgrent (3),
Packit 7cfc04
.BR group (5)
Packit 7cfc04
.SH COLOPHON
Packit 7cfc04
This page is part of release 4.15 of the Linux
Packit 7cfc04
.I man-pages
Packit 7cfc04
project.
Packit 7cfc04
A description of the project,
Packit 7cfc04
information about reporting bugs,
Packit 7cfc04
and the latest version of this page,
Packit 7cfc04
can be found at
Packit 7cfc04
\%https://www.kernel.org/doc/man\-pages/.