Commit | Line | Data |
---|---|---|
e8fa9fb0 MD |
1 | #ifndef _COMPAT_GETENV_H |
2 | #define _COMPAT_GETENV_H | |
3 | ||
4 | /* | |
ab5be9fa | 5 | * Copyright (C) 2015 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
e8fa9fb0 | 6 | * |
c922647d | 7 | * SPDX-License-Identifier: LGPL-2.1-only |
e8fa9fb0 | 8 | * |
e8fa9fb0 MD |
9 | */ |
10 | ||
28f23191 JG |
11 | #include <common/error.hpp> |
12 | ||
e8fa9fb0 | 13 | #include <stdlib.h> |
e8fa9fb0 | 14 | #include <sys/types.h> |
28f23191 | 15 | #include <unistd.h> |
e8fa9fb0 | 16 | |
28f23191 | 17 | static inline int lttng_is_setuid_setgid() |
e8fa9fb0 MD |
18 | { |
19 | return geteuid() != getuid() || getegid() != getgid(); | |
20 | } | |
21 | ||
28f23191 | 22 | static inline char *lttng_secure_getenv(const char *name) |
e8fa9fb0 MD |
23 | { |
24 | if (lttng_is_setuid_setgid()) { | |
25 | WARN("Getting environment variable '%s' from setuid/setgid binary refused for security reasons.", | |
28f23191 | 26 | name); |
cd9adb8b | 27 | return nullptr; |
e8fa9fb0 MD |
28 | } |
29 | return getenv(name); | |
30 | } | |
31 | ||
32 | #endif /* _COMPAT_GETENV_H */ |