tzfile.5, tzselect.8: sync from tzdb upstream
[man-pages.git] / man3 / getenv.3
blobb9f9ed2c2d6b609c323f3c31615d532479e3cfa4
1 '\" t
2 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
3 .\" and Copyright (C) 2007, 2012 Michael Kerrisk <mtk.manpages@gmail.com>
4 .\"
5 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
6 .\"
7 .\" References consulted:
8 .\"     Linux libc source code
9 .\"     Lewine's "POSIX Programmer's Guide" (O'Reilly & Associates, 1991)
10 .\"     386BSD man pages
11 .\" Modified Sat Jul 24 19:30:29 1993 by Rik Faith (faith@cs.unc.edu)
12 .\" Modified Fri Feb 14 21:47:50 1997 by Andries Brouwer (aeb@cwi.nl)
13 .\"
14 .TH getenv 3 (date) "Linux man-pages (unreleased)"
15 .SH NAME
16 getenv, secure_getenv \- get an environment variable
17 .SH LIBRARY
18 Standard C library
19 .RI ( libc ", " \-lc )
20 .SH SYNOPSIS
21 .nf
22 .B #include <stdlib.h>
23 .PP
24 .BI "char *getenv(const char *" name );
25 .BI "char *secure_getenv(const char *" name );
26 .fi
27 .PP
28 .RS -4
29 Feature Test Macro Requirements for glibc (see
30 .BR feature_test_macros (7)):
31 .RE
32 .PP
33 .BR secure_getenv ():
34 .nf
35     _GNU_SOURCE
36 .fi
37 .SH DESCRIPTION
38 The
39 .BR getenv ()
40 function searches the environment list to find the
41 environment variable
42 .IR name ,
43 and returns a pointer to the corresponding
44 .I value
45 string.
46 .PP
47 The GNU-specific
48 .BR secure_getenv ()
49 function is just like
50 .BR getenv ()
51 except that it returns NULL in cases where "secure execution" is required.
52 Secure execution is required if one of the following conditions
53 was true when the program run by the calling process was loaded:
54 .IP \[bu] 3
55 the process's effective user ID did not match its real user ID or
56 the process's effective group ID did not match its real group ID
57 (typically this is the result of executing a set-user-ID or
58 set-group-ID program);
59 .IP \[bu]
60 the effective capability bit was set on the executable file; or
61 .IP \[bu]
62 the process has a nonempty permitted capability set.
63 .PP
64 Secure execution may also be required if triggered
65 by some Linux security modules.
66 .PP
67 The
68 .BR secure_getenv ()
69 function is intended for use in general-purpose libraries
70 to avoid vulnerabilities that could occur if
71 set-user-ID or set-group-ID programs accidentally
72 trusted the environment.
73 .SH RETURN VALUE
74 The
75 .BR getenv ()
76 function returns a pointer to the value in the
77 environment, or NULL if there is no match.
78 .SH VERSIONS
79 .BR secure_getenv ()
80 first appeared in glibc 2.17.
81 .SH ATTRIBUTES
82 For an explanation of the terms used in this section, see
83 .BR attributes (7).
84 .ad l
85 .nh
86 .TS
87 allbox;
88 lbx lb lb
89 l l l.
90 Interface       Attribute       Value
92 .BR getenv (),
93 .BR secure_getenv ()
94 T}      Thread safety   MT-Safe env
95 .TE
96 .hy
97 .ad
98 .sp 1
99 .SH STANDARDS
100 .BR getenv ():
101 POSIX.1-2001, POSIX.1-2008, C99, SVr4, 4.3BSD.
103 .BR secure_getenv ()
104 is a GNU extension.
105 .SH NOTES
106 The strings in the environment list are of the form \fIname=value\fP.
108 As typically implemented,
109 .BR getenv ()
110 returns a pointer to a string within the environment list.
111 The caller must take care not to modify this string,
112 since that would change the environment of the process.
114 The implementation of
115 .BR getenv ()
116 is not required to be reentrant.
117 The string pointed to by the return value of
118 .BR getenv ()
119 may be statically allocated,
120 and can be modified by a subsequent call to
121 .BR getenv (),
122 .BR putenv (3),
123 .BR setenv (3),
125 .BR unsetenv (3).
127 The "secure execution" mode of
128 .BR secure_getenv ()
129 is controlled by the
130 .B AT_SECURE
131 flag contained in the auxiliary vector passed from the kernel to user space.
132 .SH SEE ALSO
133 .BR clearenv (3),
134 .BR getauxval (3),
135 .BR putenv (3),
136 .BR setenv (3),
137 .BR unsetenv (3),
138 .BR capabilities (7),
139 .BR environ (7)