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
22 #include <sys/types.h>
23 #include <usterr-signal-safe.h>
27 enum lttng_env_secure
{
34 enum lttng_env_secure secure
;
38 static struct lttng_env lttng_env
[] = {
40 * LTTNG_UST_DEBUG is used directly by snprintf, because it
41 * needs to be already set for ERR() used in
42 * lttng_ust_getenv_init().
44 { "LTTNG_UST_DEBUG", LTTNG_ENV_NOT_SECURE
, NULL
, },
46 /* Env. var. which can be used in setuid/setgid executables. */
47 { "LTTNG_UST_WITHOUT_BADDR_STATEDUMP", LTTNG_ENV_NOT_SECURE
, NULL
, },
48 { "LTTNG_UST_REGISTER_TIMEOUT", LTTNG_ENV_NOT_SECURE
, NULL
, },
50 /* Env. var. which are not fetched in setuid/setgid executables. */
51 { "LTTNG_UST_CLOCK_PLUGIN", LTTNG_ENV_SECURE
, NULL
, },
52 { "LTTNG_UST_GETCPU_PLUGIN", LTTNG_ENV_SECURE
, NULL
, },
53 { "LTTNG_UST_BLOCKING_RETRY_TIMEOUT", LTTNG_ENV_SECURE
, NULL
, },
54 { "HOME", LTTNG_ENV_SECURE
, NULL
, },
55 { "LTTNG_HOME", LTTNG_ENV_SECURE
, NULL
, },
59 int lttng_is_setuid_setgid(void)
61 return geteuid() != getuid() || getegid() != getgid();
64 char *lttng_getenv(const char *name
)
70 for (i
= 0; i
< LTTNG_ARRAY_SIZE(lttng_env
); i
++) {
73 if (strcmp(e
->key
, name
) == 0) {
84 void lttng_ust_getenv_init(void)
88 for (i
= 0; i
< LTTNG_ARRAY_SIZE(lttng_env
); i
++) {
89 struct lttng_env
*e
= <tng_env
[i
];
91 if (e
->secure
== LTTNG_ENV_SECURE
&& lttng_is_setuid_setgid()) {
92 ERR("Getting environment variable '%s' from setuid/setgid binary refused for security reasons.",
96 e
->value
= getenv(e
->key
);
This page took 0.031594 seconds and 4 git commands to generate.