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

369 lines
8.3 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of GETGRNAM</TITLE>
</HEAD><BODY>
<H1>GETGRNAM</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>
getgrnam, getgrnam_r, getgrgid, getgrgid_r - 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 *getgrnam(const char *</B><I>name</I><B>);</B>
<B>struct group *getgrgid(gid_t </B><I>gid</I><B>);</B>
<B>int getgrnam_r(const char *</B><I>name</I><B>, struct group *</B><I>grp</I><B>,</B>
<B> char *</B><I>buf</I><B>, size_t </B><I>buflen</I><B>, struct group **</B><I>result</I><B>);</B>
<B>int getgrgid_r(gid_t </B><I>gid</I><B>, struct group *</B><I>grp</I><B>,</B>
<B> char *</B><I>buf</I><B>, size_t </B><I>buflen</I><B>, struct group **</B><I>result</I><B>);</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>getgrnam_r</B>(),
<B>getgrgid_r</B>():
<DL COMPACT><DT id="1"><DD>
_POSIX_C_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>
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
The
<B>getgrnam</B>()
function returns a pointer to a structure containing
the broken-out fields of the record in the group database
(e.g., the local group file
<I>/etc/group</I>,
NIS, and LDAP)
that matches the group name
<I>name</I>.
<P>
The
<B>getgrgid</B>()
function returns a pointer to a structure containing
the broken-out fields of the record in the group database
that matches the group ID
<I>gid</I>.
<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).
<P>
The
<B>getgrnam_r</B>()
and
<B>getgrgid_r</B>()
functions obtain the same information as
<B>getgrnam</B>()
and
<B>getgrgid</B>(),
but store the retrieved
<I>group</I>
structure
in the space pointed to by
<I>grp</I>.
The string fields pointed to by the members of the
<I>group</I>
structure are stored in the buffer
<I>buf</I>
of size
<I>buflen</I>.
A pointer to the result (in case of success) or NULL (in case no entry
was found or an error occurred) is stored in
<I>*result</I>.
<P>
The call
<P>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;sysconf(_SC_GETGR_R_SIZE_MAX)
<P>
returns either -1, without changing
<I>errno</I>,
or an initial suggested size for
<I>buf</I>.
(If this size is too small,
the call fails with
<B>ERANGE</B>,
in which case the caller can retry with a larger buffer.)
<A NAME="lbAE">&nbsp;</A>
<H2>RETURN VALUE</H2>
The
<B>getgrnam</B>()
and
<B>getgrgid</B>()
functions return a pointer to a
<I>group</I>
structure, or NULL if the matching entry
is not found or an error occurs.
If an error occurs,
<I>errno</I>
is set appropriately.
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><A HREF="/cgi-bin/man/man2html?3+getgrent">getgrent</A></B>(3),
<B>getgrgid</B>(),
or
<B>getgrnam</B>().
(Do not pass the returned pointer to
<B><A HREF="/cgi-bin/man/man2html?3+free">free</A></B>(3).)
<P>
On success,
<B>getgrnam_r</B>()
and
<B>getgrgid_r</B>()
return zero, and set
<I>*result</I>
to
<I>grp</I>.
If no matching group record was found,
these functions return 0 and store NULL in
<I>*result</I>.
In case of error, an error number is returned, and NULL is stored in
<I>*result</I>.
<A NAME="lbAF">&nbsp;</A>
<H2>ERRORS</H2>
<DL COMPACT>
<DT id="2"><B>0</B> or <B>ENOENT</B> or <B>ESRCH</B> or <B>EBADF</B> or <B>EPERM</B> or ...
<DD>
The given
<I>name</I>
or
<I>gid</I>
was not found.
<DT id="3"><B>EINTR</B>
<DD>
A signal was caught; see
<B><A HREF="/cgi-bin/man/man2html?7+signal">signal</A></B>(7).
<DT id="4"><B>EIO</B>
<DD>
I/O error.
<DT id="5"><B>EMFILE</B>
<DD>
The per-process limit on the number of open file descriptors has been reached.
<DT id="6"><B>ENFILE</B>
<DD>
The system-wide limit on the total number of open files has been reached.
<DT id="7"><B>ENOMEM</B>
<DD>
Insufficient memory to allocate
<I>group</I>
structure.
<DT id="8"><B>ERANGE</B>
<DD>
Insufficient buffer space supplied.
</DL>
<A NAME="lbAG">&nbsp;</A>
<H2>FILES</H2>
<DL COMPACT>
<DT id="9"><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>getgrnam</B>()
</TD><TD>Thread safety</TD><TD>MT-Unsafe race:grnam locale<BR></TD></TR>
<TR VALIGN=top><TD>
<B>getgrgid</B>()
</TD><TD>Thread safety</TD><TD>MT-Unsafe race:grgid locale<BR></TD></TR>
<TR VALIGN=top><TD>
<B>getgrnam_r</B>(),
<BR>
<B>getgrgid_r</B>()
</TD><TD>Thread safety</TD><TD>MT-Safe locale<BR></TD></TR>
</TABLE>
<A NAME="lbAI">&nbsp;</A>
<H2>CONFORMING TO</H2>
POSIX.1-2001, POSIX.1-2008, SVr4, 4.3BSD.
<A NAME="lbAJ">&nbsp;</A>
<H2>NOTES</H2>
The formulation given above under &quot;RETURN VALUE&quot; is from POSIX.1.
It does not call &quot;not found&quot; an error, hence does not specify what value
<I>errno</I>
might have in this situation.
But that makes it impossible to recognize
errors.
One might argue that according to POSIX
<I>errno</I>
should be left unchanged if an entry is not found.
Experiments on various
UNIX-like systems show that lots of different values occur in this
situation: 0, ENOENT, EBADF, ESRCH, EWOULDBLOCK, EPERM, and probably others.
<A NAME="lbAK">&nbsp;</A>
<H2>SEE ALSO</H2>
<B><A HREF="/cgi-bin/man/man2html?3+endgrent">endgrent</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+fgetgrent">fgetgrent</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+getgrent">getgrent</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+getpwnam">getpwnam</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+setgrent">setgrent</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?5+group">group</A></B>(5)
<A NAME="lbAL">&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="10"><A HREF="#lbAB">NAME</A><DD>
<DT id="11"><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT id="12"><A HREF="#lbAD">DESCRIPTION</A><DD>
<DT id="13"><A HREF="#lbAE">RETURN VALUE</A><DD>
<DT id="14"><A HREF="#lbAF">ERRORS</A><DD>
<DT id="15"><A HREF="#lbAG">FILES</A><DD>
<DT id="16"><A HREF="#lbAH">ATTRIBUTES</A><DD>
<DT id="17"><A HREF="#lbAI">CONFORMING TO</A><DD>
<DT id="18"><A HREF="#lbAJ">NOTES</A><DD>
<DT id="19"><A HREF="#lbAK">SEE ALSO</A><DD>
<DT id="20"><A HREF="#lbAL">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>