2 * SPDX-License-Identifier: LGPL-2.1-only
4 * Copyright (C) 2017 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
11 #include <sys/types.h>
12 #include <usterr-signal-safe.h>
13 #include <ust-helper.h>
16 enum lttng_env_secure
{
23 enum lttng_env_secure secure
;
27 static struct lttng_env lttng_env
[] = {
29 * LTTNG_UST_DEBUG is used directly by snprintf, because it
30 * needs to be already set for ERR() used in
31 * lttng_ust_getenv_init().
33 { "LTTNG_UST_DEBUG", LTTNG_ENV_NOT_SECURE
, NULL
, },
35 /* Env. var. which can be used in setuid/setgid executables. */
36 { "LTTNG_UST_WITHOUT_BADDR_STATEDUMP", LTTNG_ENV_NOT_SECURE
, NULL
, },
37 { "LTTNG_UST_REGISTER_TIMEOUT", LTTNG_ENV_NOT_SECURE
, NULL
, },
39 /* Env. var. which are not fetched in setuid/setgid executables. */
40 { "LTTNG_UST_CLOCK_PLUGIN", LTTNG_ENV_SECURE
, NULL
, },
41 { "LTTNG_UST_GETCPU_PLUGIN", LTTNG_ENV_SECURE
, NULL
, },
42 { "LTTNG_UST_ALLOW_BLOCKING", LTTNG_ENV_SECURE
, NULL
, },
43 { "HOME", LTTNG_ENV_SECURE
, NULL
, },
44 { "LTTNG_HOME", LTTNG_ENV_SECURE
, NULL
, },
48 int lttng_is_setuid_setgid(void)
50 return geteuid() != getuid() || getegid() != getgid();
53 char *lttng_ust_getenv(const char *name
)
59 for (i
= 0; i
< LTTNG_ARRAY_SIZE(lttng_env
); i
++) {
62 if (strcmp(e
->key
, name
) == 0) {
73 void lttng_ust_getenv_init(void)
77 for (i
= 0; i
< LTTNG_ARRAY_SIZE(lttng_env
); i
++) {
78 struct lttng_env
*e
= <tng_env
[i
];
80 if (e
->secure
== LTTNG_ENV_SECURE
&& lttng_is_setuid_setgid()) {
81 ERR("Getting environment variable '%s' from setuid/setgid binary refused for security reasons.",
85 e
->value
= getenv(e
->key
);
This page took 0.037446 seconds and 4 git commands to generate.