Changes: Ready for 5.13
[man-pages.git] / man3 / getenv.3
blobdeac999fc56d5da8b479fb808809179e2685f6f9
1 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
2 .\" and Copyright (C) 2007, 2012 Michael Kerrisk <mtk.manpages@gmail.com>
3 .\"
4 .\" %%%LICENSE_START(VERBATIM)
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.
13 .\"
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.
21 .\"
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
24 .\" %%%LICENSE_END
25 .\"
26 .\" References consulted:
27 .\"     Linux libc source code
28 .\"     Lewine's "POSIX Programmer's Guide" (O'Reilly & Associates, 1991)
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 .\"
33 .TH GETENV 3  2021-03-22 "GNU" "Linux Programmer's Manual"
34 .SH NAME
35 getenv, secure_getenv \- get an environment variable
36 .SH SYNOPSIS
37 .nf
38 .B #include <stdlib.h>
39 .PP
40 .BI "char *getenv(const char *" name );
41 .BI "char *secure_getenv(const char *" name );
42 .fi
43 .PP
44 .RS -4
45 Feature Test Macro Requirements for glibc (see
46 .BR feature_test_macros (7)):
47 .RE
48 .PP
49 .BR secure_getenv ():
50 .nf
51     _GNU_SOURCE
52 .fi
53 .SH DESCRIPTION
54 The
55 .BR getenv ()
56 function searches the environment list to find the
57 environment variable
58 .IR name ,
59 and returns a pointer to the corresponding
60 .I value
61 string.
62 .PP
63 The GNU-specific
64 .BR secure_getenv ()
65 function is just like
66 .BR getenv ()
67 except that it returns NULL in cases where "secure execution" is required.
68 Secure execution is required if one of the following conditions
69 was true when the program run by the calling process was loaded:
70 .IP * 3
71 the process's effective user ID did not match its real user ID or
72 the process's effective group ID did not match its real group ID
73 (typically this is the result of executing a set-user-ID or
74 set-group-ID program);
75 .IP *
76 the effective capability bit was set on the executable file; or
77 .IP *
78 the process has a nonempty permitted capability set.
79 .PP
80 Secure execution may also be required if triggered
81 by some Linux security modules.
82 .PP
83 The
84 .BR secure_getenv ()
85 function is intended for use in general-purpose libraries
86 to avoid vulnerabilities that could occur if
87 set-user-ID or set-group-ID programs accidentally
88 trusted the environment.
89 .SH RETURN VALUE
90 The
91 .BR getenv ()
92 function returns a pointer to the value in the
93 environment, or NULL if there is no match.
94 .SH VERSIONS
95 .BR secure_getenv ()
96 first appeared in glibc 2.17.
97 .SH ATTRIBUTES
98 For an explanation of the terms used in this section, see
99 .BR attributes (7).
100 .ad l
103 allbox;
104 lbx lb lb
105 l l l.
106 Interface       Attribute       Value
108 .BR getenv (),
109 .BR secure_getenv ()
110 T}      Thread safety   MT-Safe env
114 .sp 1
115 .SH CONFORMING TO
116 .BR getenv ():
117 POSIX.1-2001, POSIX.1-2008, C89, C99, SVr4, 4.3BSD.
119 .BR secure_getenv ()
120 is a GNU extension.
121 .SH NOTES
122 The strings in the environment list are of the form \fIname=value\fP.
124 As typically implemented,
125 .BR getenv ()
126 returns a pointer to a string within the environment list.
127 The caller must take care not to modify this string,
128 since that would change the environment of the process.
130 The implementation of
131 .BR getenv ()
132 is not required to be reentrant.
133 The string pointed to by the return value of
134 .BR getenv ()
135 may be statically allocated,
136 and can be modified by a subsequent call to
137 .BR getenv (),
138 .BR putenv (3),
139 .BR setenv (3),
141 .BR unsetenv (3).
143 The "secure execution" mode of
144 .BR secure_getenv ()
145 is controlled by the
146 .B AT_SECURE
147 flag contained in the auxiliary vector passed from the kernel to user space.
148 .SH SEE ALSO
149 .BR clearenv (3),
150 .BR getauxval (3),
151 .BR putenv (3),
152 .BR setenv (3),
153 .BR unsetenv (3),
154 .BR capabilities (7),
155 .BR environ (7)