1GETENV(3)                  Linux Programmer's Manual                 GETENV(3)
2
3
4

NAME

6       getenv, secure_getenv - get an environment variable
7

SYNOPSIS

9       #include <stdlib.h>
10
11       char *getenv(const char *name);
12
13       char *secure_getenv(const char *name);
14
15   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
16
17       secure_getenv(): _GNU_SOURCE
18

DESCRIPTION

20       The  getenv()  function searches the environment list to find the envi‐
21       ronment variable name, and returns a pointer to the corresponding value
22       string.
23
24       The  GNU-specific secure_getenv() function is just like getenv() except
25       that it returns NULL in cases where  "secure  execution"  is  required.
26       Secure  execution  is  required  if one of the following conditions was
27       true when the program run by the calling process was loaded:
28
29       *  the process's effective user ID did not match its real  user  ID  or
30          the  process's  effective  group  ID did not match its real group ID
31          (typically this is the result of executing  a  set-user-ID  or  set-
32          group-ID program);
33
34       *  the effective capability bit was set on the executable file; or
35
36       *  the process has a nonempty permitted capability set.
37
38       Secure  execution may also be required if triggered by some Linux secu‐
39       rity modules.
40
41       The secure_getenv() function is intended  for  use  in  general-purpose
42       libraries  to  avoid vulnerabilities that could occur if set-user-ID or
43       set-group-ID programs accidentally trusted the environment.
44

RETURN VALUE

46       The getenv() function returns a pointer to the value  in  the  environ‐
47       ment, or NULL if there is no match.
48

VERSIONS

50       secure_getenv() first appeared in glibc 2.17.
51

ATTRIBUTES

53       For   an   explanation   of   the  terms  used  in  this  section,  see
54       attributes(7).
55
56       ┌──────────────────────────┬───────────────┬─────────────┐
57Interface                 Attribute     Value       
58       ├──────────────────────────┼───────────────┼─────────────┤
59getenv(), secure_getenv() │ Thread safety │ MT-Safe env │
60       └──────────────────────────┴───────────────┴─────────────┘

CONFORMING TO

62       getenv(): POSIX.1-2001, POSIX.1-2008, C89, C99, SVr4, 4.3BSD.
63
64       secure_getenv() is a GNU extension.
65

NOTES

67       The strings in the environment list are of the form name=value.
68
69       As typically implemented, getenv() returns a pointer to a string within
70       the  environment  list.   The  caller must take care not to modify this
71       string, since that would change the environment of the process.
72
73       The implementation of getenv() is not required to  be  reentrant.   The
74       string  pointed  to  by  the return value of getenv() may be statically
75       allocated, and can be  modified  by  a  subsequent  call  to  getenv(),
76       putenv(3), setenv(3), or unsetenv(3).
77
78       The  "secure  execution"  mode  of secure_getenv() is controlled by the
79       AT_SECURE flag contained in the auxiliary vector passed from the kernel
80       to user space.
81

SEE ALSO

83       clearenv(3), getauxval(3), putenv(3), setenv(3), unsetenv(3), capabili‐
84       ties(7), environ(7)
85

COLOPHON

87       This page is part of release 5.04 of the Linux  man-pages  project.   A
88       description  of  the project, information about reporting bugs, and the
89       latest    version    of    this    page,    can     be     found     at
90       https://www.kernel.org/doc/man-pages/.
91
92
93
94GNU                               2017-09-15                         GETENV(3)
Impressum