X-Git-Url: http://git.liburcu.org/?a=blobdiff_plain;f=liblttng-ust%2Fgetenv.c;h=25740a50c3b7f5e699141d886695a9594a11730e;hb=HEAD;hp=f2222ddbf5ab13dcf4a780fe09473a825dc96f59;hpb=864a1eda22ed99266509ac76451c6f27f91aa17e;p=lttng-ust.git diff --git a/liblttng-ust/getenv.c b/liblttng-ust/getenv.c deleted file mode 100644 index f2222ddb..00000000 --- a/liblttng-ust/getenv.c +++ /dev/null @@ -1,87 +0,0 @@ -/* - * SPDX-License-Identifier: LGPL-2.1-only - * - * Copyright (C) 2017 Mathieu Desnoyers - */ - -#include -#include -#include -#include -#include -#include -#include -#include "getenv.h" - -enum lttng_env_secure { - LTTNG_ENV_SECURE, - LTTNG_ENV_NOT_SECURE, -}; - -struct lttng_env { - const char *key; - enum lttng_env_secure secure; - char *value; -}; - -static struct lttng_env lttng_env[] = { - /* - * LTTNG_UST_DEBUG is used directly by snprintf, because it - * needs to be already set for ERR() used in - * lttng_ust_getenv_init(). - */ - { "LTTNG_UST_DEBUG", LTTNG_ENV_NOT_SECURE, NULL, }, - - /* Env. var. which can be used in setuid/setgid executables. */ - { "LTTNG_UST_WITHOUT_BADDR_STATEDUMP", LTTNG_ENV_NOT_SECURE, NULL, }, - { "LTTNG_UST_REGISTER_TIMEOUT", LTTNG_ENV_NOT_SECURE, NULL, }, - - /* Env. var. which are not fetched in setuid/setgid executables. */ - { "LTTNG_UST_CLOCK_PLUGIN", LTTNG_ENV_SECURE, NULL, }, - { "LTTNG_UST_GETCPU_PLUGIN", LTTNG_ENV_SECURE, NULL, }, - { "LTTNG_UST_ALLOW_BLOCKING", LTTNG_ENV_SECURE, NULL, }, - { "HOME", LTTNG_ENV_SECURE, NULL, }, - { "LTTNG_HOME", LTTNG_ENV_SECURE, NULL, }, -}; - -static -int lttng_is_setuid_setgid(void) -{ - return geteuid() != getuid() || getegid() != getgid(); -} - -char *lttng_getenv(const char *name) -{ - size_t i; - struct lttng_env *e; - bool found = false; - - for (i = 0; i < LTTNG_ARRAY_SIZE(lttng_env); i++) { - e = <tng_env[i]; - - if (strcmp(e->key, name) == 0) { - found = true; - break; - } - } - if (!found) { - return NULL; - } - return e->value; -} - -void lttng_ust_getenv_init(void) -{ - size_t i; - - for (i = 0; i < LTTNG_ARRAY_SIZE(lttng_env); i++) { - struct lttng_env *e = <tng_env[i]; - - if (e->secure == LTTNG_ENV_SECURE && lttng_is_setuid_setgid()) { - ERR("Getting environment variable '%s' from setuid/setgid binary refused for security reasons.", - e->key); - continue; - } - e->value = getenv(e->key); - } -}