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

219 lines
5.2 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of GETENV</TITLE>
</HEAD><BODY>
<H1>GETENV</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>
getenv, secure_getenv - get an environment variable
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<PRE>
<B>#include &lt;<A HREF="file:///usr/include/stdlib.h">stdlib.h</A>&gt;</B>
<B>char *getenv(const char *</B><I>name</I><B>);</B>
<B>char *secure_getenv(const char *</B><I>name</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>secure_getenv</B>():
_GNU_SOURCE
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
The
<B>getenv</B>()
function searches the environment list to find the
environment variable
<I>name</I>,
and returns a pointer to the corresponding
<I>value</I>
string.
<P>
The GNU-specific
<B>secure_getenv</B>()
function is just like
<B>getenv</B>()
except that it returns NULL in cases where &quot;secure execution&quot; is required.
Secure execution is required if one of the following conditions
was true when the program run by the calling process was loaded:
<DL COMPACT>
<DT id="1">*<DD>
the process's effective user ID did not match its real user ID or
the process's effective group ID did not match its real group ID
(typically this is the result of executing a set-user-ID or
set-group-ID program);
<DT id="2">*<DD>
the effective capability bit was set on the executable file; or
<DT id="3">*<DD>
the process has a nonempty permitted capability set.
</DL>
<P>
Secure execution may also be required if triggered
by some Linux security modules.
<P>
The
<B>secure_getenv</B>()
function is intended for use in general-purpose libraries
to avoid vulnerabilities that could occur if
set-user-ID or set-group-ID programs accidentally
trusted the environment.
<A NAME="lbAE">&nbsp;</A>
<H2>RETURN VALUE</H2>
The
<B>getenv</B>()
function returns a pointer to the value in the
environment, or NULL if there is no match.
<A NAME="lbAF">&nbsp;</A>
<H2>VERSIONS</H2>
<B>secure_getenv</B>()
first appeared in glibc 2.17.
<A NAME="lbAG">&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>getenv</B>(),
<B>secure_getenv</B>()
</TD><TD>Thread safety</TD><TD>MT-Safe env<BR></TD></TR>
</TABLE>
<A NAME="lbAH">&nbsp;</A>
<H2>CONFORMING TO</H2>
<B>getenv</B>():
POSIX.1-2001, POSIX.1-2008, C89, C99, SVr4, 4.3BSD.
<P>
<B>secure_getenv</B>()
is a GNU extension.
<A NAME="lbAI">&nbsp;</A>
<H2>NOTES</H2>
The strings in the environment list are of the form <I>name=value</I>.
<P>
As typically implemented,
<B>getenv</B>()
returns a pointer to a string within the environment list.
The caller must take care not to modify this string,
since that would change the environment of the process.
<P>
The implementation of
<B>getenv</B>()
is not required to be reentrant.
The string pointed to by the return value of
<B>getenv</B>()
may be statically allocated,
and can be modified by a subsequent call to
<B>getenv</B>(),
<B><A HREF="/cgi-bin/man/man2html?3+putenv">putenv</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+setenv">setenv</A></B>(3),
or
<B><A HREF="/cgi-bin/man/man2html?3+unsetenv">unsetenv</A></B>(3).
<P>
The &quot;secure execution&quot; mode of
<B>secure_getenv</B>()
is controlled by the
<B>AT_SECURE</B>
flag contained in the auxiliary vector passed from the kernel to user space.
<A NAME="lbAJ">&nbsp;</A>
<H2>SEE ALSO</H2>
<B><A HREF="/cgi-bin/man/man2html?3+clearenv">clearenv</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+getauxval">getauxval</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+putenv">putenv</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+setenv">setenv</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+unsetenv">unsetenv</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?7+capabilities">capabilities</A></B>(7),
<B><A HREF="/cgi-bin/man/man2html?7+environ">environ</A></B>(7)
<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="4"><A HREF="#lbAB">NAME</A><DD>
<DT id="5"><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT id="6"><A HREF="#lbAD">DESCRIPTION</A><DD>
<DT id="7"><A HREF="#lbAE">RETURN VALUE</A><DD>
<DT id="8"><A HREF="#lbAF">VERSIONS</A><DD>
<DT id="9"><A HREF="#lbAG">ATTRIBUTES</A><DD>
<DT id="10"><A HREF="#lbAH">CONFORMING TO</A><DD>
<DT id="11"><A HREF="#lbAI">NOTES</A><DD>
<DT id="12"><A HREF="#lbAJ">SEE ALSO</A><DD>
<DT id="13"><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>