2 * Copyright (C) 2017 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; only
7 * version 2.1 of the License.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 #include <sys/types.h>
24 #include <usterr-signal-safe.h>
28 enum lttng_env_secure
{
35 enum lttng_env_secure secure
;
39 static struct lttng_env lttng_env
[] = {
41 * LTTNG_UST_DEBUG is used directly by snprintf, because it
42 * needs to be already set for ERR() used in
43 * lttng_ust_getenv_init().
45 { "LTTNG_UST_DEBUG", LTTNG_ENV_NOT_SECURE
, NULL
, },
47 /* Env. var. which can be used in setuid/setgid executables. */
48 { "LTTNG_UST_WITHOUT_BADDR_STATEDUMP", LTTNG_ENV_NOT_SECURE
, NULL
, },
49 { "LTTNG_UST_REGISTER_TIMEOUT", LTTNG_ENV_NOT_SECURE
, NULL
, },
51 /* Env. var. which are not fetched in setuid/setgid executables. */
52 { "LTTNG_UST_CLOCK_PLUGIN", LTTNG_ENV_SECURE
, NULL
, },
53 { "LTTNG_UST_GETCPU_PLUGIN", LTTNG_ENV_SECURE
, NULL
, },
54 { "LTTNG_UST_ALLOW_BLOCKING", LTTNG_ENV_SECURE
, NULL
, },
55 { "HOME", LTTNG_ENV_SECURE
, NULL
, },
56 { "LTTNG_HOME", LTTNG_ENV_SECURE
, NULL
, },
60 int lttng_is_setuid_setgid(void)
62 return geteuid() != getuid() || getegid() != getgid();
65 char *lttng_getenv(const char *name
)
71 for (i
= 0; i
< LTTNG_ARRAY_SIZE(lttng_env
); i
++) {
74 if (strcmp(e
->key
, name
) == 0) {
85 void lttng_ust_getenv_init(void)
89 for (i
= 0; i
< LTTNG_ARRAY_SIZE(lttng_env
); i
++) {
90 struct lttng_env
*e
= <tng_env
[i
];
92 if (e
->secure
== LTTNG_ENV_SECURE
&& lttng_is_setuid_setgid()) {
93 ERR("Getting environment variable '%s' from setuid/setgid binary refused for security reasons.",
97 e
->value
= getenv(e
->key
);
This page took 0.044602 seconds and 4 git commands to generate.