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