]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/getenv.3
dlinfo.3: ATTRIBUTES: Note function that is thread-safe
[thirdparty/man-pages.git] / man3 / getenv.3
CommitLineData
fea681da 1.\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
4e1927c6 2.\" and Copyright (C) 2007, 2012 Michael Kerrisk <mtk.manpages@gmail.com>
fea681da 3.\"
93015253 4.\" %%%LICENSE_START(VERBATIM)
fea681da
MK
5.\" Permission is granted to make and distribute verbatim copies of this
6.\" manual provided the copyright notice and this permission notice are
7.\" preserved on all copies.
8.\"
9.\" Permission is granted to copy and distribute modified versions of this
10.\" manual under the conditions for verbatim copying, provided that the
11.\" entire resulting derived work is distributed under the terms of a
12.\" permission notice identical to this one.
c13182ef 13.\"
fea681da
MK
14.\" Since the Linux kernel and libraries are constantly changing, this
15.\" manual page may be incorrect or out-of-date. The author(s) assume no
16.\" responsibility for errors or omissions, or for damages resulting from
17.\" the use of the information contained herein. The author(s) may not
18.\" have taken the same level of care in the production of this manual,
19.\" which is licensed free of charge, as they might when working
20.\" professionally.
c13182ef 21.\"
fea681da
MK
22.\" Formatted or processed versions of this manual, if unaccompanied by
23.\" the source, must acknowledge the copyright and authors of this work.
4b72fb64 24.\" %%%LICENSE_END
fea681da
MK
25.\"
26.\" References consulted:
27.\" Linux libc source code
9f6d3345 28.\" Lewine's "POSIX Programmer's Guide" (O'Reilly & Associates, 1991)
fea681da
MK
29.\" 386BSD man pages
30.\" Modified Sat Jul 24 19:30:29 1993 by Rik Faith (faith@cs.unc.edu)
31.\" Modified Fri Feb 14 21:47:50 1997 by Andries Brouwer (aeb@cwi.nl)
32.\"
fe0fefbf 33.TH GETENV 3 2015-03-02 "GNU" "Linux Programmer's Manual"
fea681da 34.SH NAME
4e1927c6 35getenv, secure_getenv \- get an environment variable
fea681da
MK
36.SH SYNOPSIS
37.nf
38.B #include <stdlib.h>
39.sp
40.BI "char *getenv(const char *" name );
4e1927c6
MK
41
42.BI "char *secure_getenv(const char *" name );
fea681da 43.fi
4e1927c6
MK
44.sp
45.in -4n
46Feature Test Macro Requirements for glibc (see
47.BR feature_test_macros (7)):
48.in
49.sp
760655c2 50.BR secure_getenv ():
4e1927c6 51_GNU_SOURCE
fea681da 52.SH DESCRIPTION
60a90ecd
MK
53The
54.BR getenv ()
9f6d3345
MK
55function searches the environment list to find the
56environment variable
57.IR name ,
58and returns a pointer to the corresponding
59.I value
60string.
4e1927c6
MK
61
62The GNU-specific
63.BR secure_getenv ()
64function is just like
65.BR getenv ()
66except that it returns NULL in cases where "secure execution" is required.
67Secure execution is required if one of the following conditions
68was true when the program run by the calling process was loaded:
69.IP * 3
70the process's effective user ID did not match its real user ID or
71the process's effective group ID did not match its real group ID
72(typically this is the result of executing a set-user-ID or
73set-group-ID program);
74.IP *
75the effective capability bit was set on the executable file; or
76.IP *
77the process has a nonempty permitted capability set.
78.PP
79Secure execution may also required if triggered
80by some Linux security modules.
81
82The
83.BR secure_getenv ()
84function is intended for use in general-purpose libraries
85to avoid vulnerabilities that could occur if
86set-user-ID or set-group-ID programs accidentally
87trusted the environment.
47297adb 88.SH RETURN VALUE
60a90ecd
MK
89The
90.BR getenv ()
91function returns a pointer to the value in the
fea681da 92environment, or NULL if there is no match.
7484d5a7
MK
93.SH VERSIONS
94.BR secure_getenv ()
95first appeared in glibc 2.17.
bdb80008
PH
96.SH ATTRIBUTES
97For an explanation of the terms used in this section, see
98.BR attributes (7).
99.TS
100allbox;
101lbw25 lb lb
102l l l.
103Interface Attribute Value
104T{
105.BR getenv (),
106.BR secure_getenv ()
107T} Thread safety MT-Safe env
108.TE
47297adb 109.SH CONFORMING TO
4e1927c6 110.BR getenv ():
8ae90f8e 111POSIX.1-2001, POSIX.1-2008, C89, C99, SVr4, 4.3BSD.
4e1927c6
MK
112
113.BR secure_getenv ()
114is a GNU extension.
9f6d3345
MK
115.SH NOTES
116The strings in the environment list are of the form \fIname=value\fP.
117
118As typically implemented,
119.BR getenv ()
120returns a pointer to a string within the environment list.
121The caller must take care not to modify this string,
122since that would change the environment of the process.
123
124The implementation of
125.BR getenv ()
126is not required to be reentrant.
127The string pointed to by the return value of
128.BR getenv ()
129may be statically allocated,
130and can be modified by a subsequent call to
131.BR getenv (),
132.BR putenv (3),
133.BR setenv (3),
134or
135.BR unsetenv (3).
4e1927c6
MK
136
137The "secure execution" mode of
138.BR secure_getenv ()
139is controlled by the
140.B AT_SECURE
141flag contained in the auxiliary vector passed from the kernel to user space.
47297adb 142.SH SEE ALSO
fea681da 143.BR clearenv (3),
80380b8e 144.BR getauxval (3),
fea681da
MK
145.BR putenv (3),
146.BR setenv (3),
147.BR unsetenv (3),
4e1927c6 148.BR capabilities (7),
aa949e2d 149.BR environ (7)