X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fcommon%2Fcompat%2Fgetenv.hpp;fp=src%2Fcommon%2Fcompat%2Fgetenv.hpp;h=7a31fef9e0c2614481c52e1f5df11349d7fc4f9c;hb=c9e313bc594f40a86eed237dce222c0fc99c957f;hp=0000000000000000000000000000000000000000;hpb=4878de5c7deb512bbdac4fdfc498907efa06fb7c;p=lttng-tools.git diff --git a/src/common/compat/getenv.hpp b/src/common/compat/getenv.hpp new file mode 100644 index 000000000..7a31fef9e --- /dev/null +++ b/src/common/compat/getenv.hpp @@ -0,0 +1,33 @@ +#ifndef _COMPAT_GETENV_H +#define _COMPAT_GETENV_H + +/* + * Copyright (C) 2015 Mathieu Desnoyers + * + * SPDX-License-Identifier: LGPL-2.1-only + * + */ + +#include +#include +#include +#include + +static inline +int lttng_is_setuid_setgid(void) +{ + return geteuid() != getuid() || getegid() != getgid(); +} + +static inline +char *lttng_secure_getenv(const char *name) +{ + if (lttng_is_setuid_setgid()) { + WARN("Getting environment variable '%s' from setuid/setgid binary refused for security reasons.", + name); + return NULL; + } + return getenv(name); +} + +#endif /* _COMPAT_GETENV_H */