From: Mathieu Desnoyers Date: Thu, 23 Apr 2015 22:48:43 +0000 (-0400) Subject: Fix: add missing getenv wrapper X-Git-Tag: v2.6.1~2 X-Git-Url: http://git.liburcu.org/?p=lttng-ust.git;a=commitdiff_plain;h=c67ad70ef8b57f81015f30e16fba62e940388832 Fix: add missing getenv wrapper Required for old glibc. Signed-off-by: Mathieu Desnoyers --- diff --git a/liblttng-ust/Makefile.am b/liblttng-ust/Makefile.am index e2e1baaa..10797d05 100644 --- a/liblttng-ust/Makefile.am +++ b/liblttng-ust/Makefile.am @@ -46,7 +46,8 @@ liblttng_ust_runtime_la_SOURCES = \ lttng-ust-uuid.h \ error.h \ tracef.c \ - lttng-ust-tracef-provider.h + lttng-ust-tracef-provider.h \ + getenv.h if HAVE_PERF_EVENT liblttng_ust_runtime_la_SOURCES += \ diff --git a/liblttng-ust/getenv.h b/liblttng-ust/getenv.h new file mode 100644 index 00000000..05864fb8 --- /dev/null +++ b/liblttng-ust/getenv.h @@ -0,0 +1,44 @@ +#ifndef _COMPAT_GETENV_H +#define _COMPAT_GETENV_H + +/* + * Copyright (C) 2015 - Mathieu Desnoyers + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; only + * version 2.1 of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#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()) { + ERR("Getting environment variable '%s' from setuid/setgid binary refused for security reasons.", + name); + return NULL; + } + return getenv(name); +} + +#endif /* _COMPAT_GETENV_H */