man-pages/man3/getgrent.3.html
2021-03-31 01:06:50 +01:00

311 lines
7.5 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of GETGRENT</TITLE>
</HEAD><BODY>
<H1>GETGRENT</H1>
Section: Linux Programmer's Manual (3)<BR>Updated: 2017-09-15<BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
getgrent, setgrent, endgrent - get group file entry
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<PRE>
<B>#include &lt;<A HREF="file:///usr/include/sys/types.h">sys/types.h</A>&gt;</B>
<B>#include &lt;<A HREF="file:///usr/include/grp.h">grp.h</A>&gt;</B>
<B>struct group *getgrent(void);</B>
<B>void setgrent(void);</B>
<B>void endgrent(void);</B>
</PRE>
<P>
Feature Test Macro Requirements for glibc (see
<B><A HREF="/cgi-bin/man/man2html?7+feature_test_macros">feature_test_macros</A></B>(7)):
<P>
<B>setgrent</B>():
<DL COMPACT><DT id="1"><DD>
_XOPEN_SOURCE&nbsp;&gt;=&nbsp;500
<BR>&nbsp;&nbsp;&nbsp;&nbsp;||&nbsp;/*&nbsp;Glibc&nbsp;since&nbsp;2.19:&nbsp;*/&nbsp;_DEFAULT_SOURCE
<BR>&nbsp;&nbsp;&nbsp;&nbsp;||&nbsp;/*&nbsp;Glibc&nbsp;versions&nbsp;&lt;=&nbsp;2.19:&nbsp;*/&nbsp;_BSD_SOURCE&nbsp;||&nbsp;_SVID_SOURCE
</DL>
<P>
<B>getgrent</B>(),
<B>endgrent</B>():
<DL COMPACT><DT id="2"><DD>
Since glibc 2.22:
<BR>&nbsp;&nbsp;&nbsp;&nbsp;_XOPEN_SOURCE&nbsp;&gt;=&nbsp;500&nbsp;||
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_DEFAULT_SOURCE
<BR>
Glibc 2.21 and earlier
<BR>&nbsp;&nbsp;&nbsp;&nbsp;_XOPEN_SOURCE&nbsp;&gt;=&nbsp;500
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;||&nbsp;/*&nbsp;Since&nbsp;glibc&nbsp;2.12:&nbsp;*/&nbsp;_POSIX_C_SOURCE&nbsp;&gt;=&nbsp;200809L
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;||&nbsp;/*&nbsp;Glibc&nbsp;versions&nbsp;&lt;=&nbsp;2.19:&nbsp;*/&nbsp;_BSD_SOURCE&nbsp;||&nbsp;_SVID_SOURCE
</DL>
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
The
<B>getgrent</B>()
function returns a pointer to a structure containing
the broken-out fields of a record in the group database
(e.g., the local group file
<I>/etc/group</I>,
NIS, and LDAP).
The first time
<B>getgrent</B>()
is called,
it returns the first entry; thereafter, it returns successive entries.
<P>
The
<B>setgrent</B>()
function rewinds to the beginning
of the group database, to allow repeated scans.
<P>
The
<B>endgrent</B>()
function is used to close the group database
after all processing has been performed.
<P>
The <I>group</I> structure is defined in <I>&lt;<A HREF="file:///usr/include/grp.h">grp.h</A>&gt;</I> as follows:
<P>
struct group {
<BR>&nbsp;&nbsp;&nbsp;&nbsp;char&nbsp;&nbsp;&nbsp;*gr_name;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;group&nbsp;name&nbsp;*/
<BR>&nbsp;&nbsp;&nbsp;&nbsp;char&nbsp;&nbsp;&nbsp;*gr_passwd;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;group&nbsp;password&nbsp;*/
<BR>&nbsp;&nbsp;&nbsp;&nbsp;gid_t&nbsp;&nbsp;&nbsp;gr_gid;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;group&nbsp;ID&nbsp;*/
<BR>&nbsp;&nbsp;&nbsp;&nbsp;char&nbsp;&nbsp;**gr_mem;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;NULL-terminated&nbsp;array&nbsp;of&nbsp;pointers
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;to&nbsp;names&nbsp;of&nbsp;group&nbsp;members&nbsp;*/
};
<P>
For more information about the fields of this structure, see
<B><A HREF="/cgi-bin/man/man2html?5+group">group</A></B>(5).
<A NAME="lbAE">&nbsp;</A>
<H2>RETURN VALUE</H2>
The
<B>getgrent</B>()
function returns a pointer to a
<I>group</I>
structure,
or NULL if there are no more entries or an error occurs.
<P>
Upon error,
<I>errno</I>
may be set.
If one wants to check
<I>errno</I>
after the call, it should be set to zero before the call.
<P>
The return value may point to a static area, and may be overwritten
by subsequent calls to
<B>getgrent</B>(),
<B><A HREF="/cgi-bin/man/man2html?3+getgrgid">getgrgid</A></B>(3),
or
<B><A HREF="/cgi-bin/man/man2html?3+getgrnam">getgrnam</A></B>(3).
(Do not pass the returned pointer to
<B><A HREF="/cgi-bin/man/man2html?3+free">free</A></B>(3).)
<A NAME="lbAF">&nbsp;</A>
<H2>ERRORS</H2>
<DL COMPACT>
<DT id="3"><B>EAGAIN</B>
<DD>
The service was temporarily unavailable; try again later.
For NSS backends in glibc this indicates a temporary error talking to the backend.
The error may correct itself, retrying later is suggested.
<DT id="4"><B>EINTR</B>
<DD>
A signal was caught; see
<B><A HREF="/cgi-bin/man/man2html?7+signal">signal</A></B>(7).
<DT id="5"><B>EIO</B>
<DD>
I/O error.
<DT id="6"><B>EMFILE</B>
<DD>
The per-process limit on the number of open file descriptors has been reached.
<DT id="7"><B>ENFILE</B>
<DD>
The system-wide limit on the total number of open files has been reached.
<DT id="8">
<DD>
<B>ENOENT</B>
A necessary input file cannot be found.
For NSS backends in glibc this indicates the backend is not correctly configured.
<DT id="9"><B>ENOMEM</B>
<DD>
Insufficient memory to allocate
<I>group</I>
structure.
<DT id="10"><B>ERANGE</B>
<DD>
Insufficient buffer space supplied.
</DL>
<A NAME="lbAG">&nbsp;</A>
<H2>FILES</H2>
<DL COMPACT>
<DT id="11"><I>/etc/group</I>
<DD>
local group database file
</DL>
<A NAME="lbAH">&nbsp;</A>
<H2>ATTRIBUTES</H2>
For an explanation of the terms used in this section, see
<B><A HREF="/cgi-bin/man/man2html?7+attributes">attributes</A></B>(7).
<TABLE BORDER>
<TR VALIGN=top><TD><B>Interface</B></TD><TD><B>Attribute</B></TD><TD><B>Value</B><BR></TD></TR>
<TR VALIGN=top><TD>
<B>getgrent</B>()
</TD><TD>Thread safety</TD><TD>
MT-Unsafe race:grent
<BR>
race:grentbuf locale
<BR></TD></TR>
<TR VALIGN=top><TD>
<B>setgrent</B>(),
<B>endgrent</B>()
</TD><TD>Thread safety</TD><TD>MT-Unsafe race:grent locale<BR></TD></TR>
</TABLE>
<P>
In the above table,
<I>grent</I>
in
<I>race:grent</I>
signifies that if any of the functions
<B>setgrent</B>(),
<B>getgrent</B>(),
or
<B>endgrent</B>()
are used in parallel in different threads of a program,
then data races could occur.
<A NAME="lbAI">&nbsp;</A>
<H2>CONFORMING TO</H2>
POSIX.1-2001, POSIX.1-2008, SVr4, 4.3BSD.
<A NAME="lbAJ">&nbsp;</A>
<H2>SEE ALSO</H2>
<B><A HREF="/cgi-bin/man/man2html?3+fgetgrent">fgetgrent</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+getgrent_r">getgrent_r</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+getgrgid">getgrgid</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+getgrnam">getgrnam</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+getgrouplist">getgrouplist</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+putgrent">putgrent</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?5+group">group</A></B>(5)
<A NAME="lbAK">&nbsp;</A>
<H2>COLOPHON</H2>
This page is part of release 5.05 of the Linux
<I>man-pages</I>
project.
A description of the project,
information about reporting bugs,
and the latest version of this page,
can be found at
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="12"><A HREF="#lbAB">NAME</A><DD>
<DT id="13"><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT id="14"><A HREF="#lbAD">DESCRIPTION</A><DD>
<DT id="15"><A HREF="#lbAE">RETURN VALUE</A><DD>
<DT id="16"><A HREF="#lbAF">ERRORS</A><DD>
<DT id="17"><A HREF="#lbAG">FILES</A><DD>
<DT id="18"><A HREF="#lbAH">ATTRIBUTES</A><DD>
<DT id="19"><A HREF="#lbAI">CONFORMING TO</A><DD>
<DT id="20"><A HREF="#lbAJ">SEE ALSO</A><DD>
<DT id="21"><A HREF="#lbAK">COLOPHON</A><DD>
</DL>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:05:44 GMT, March 31, 2021
</BODY>
</HTML>