]> git.lttng.org Git - lttng-ust.git/commitdiff
Fix: add missing getenv wrapper
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 23 Apr 2015 22:48:43 +0000 (18:48 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 23 Apr 2015 22:51:04 +0000 (18:51 -0400)
Required for old glibc.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
liblttng-ust/Makefile.am
liblttng-ust/getenv.h [new file with mode: 0644]

index e2e1baaab9b8a8e7e5c049948aaf1b8a7eaa0e46..10797d05ff1f22a35a8639c4fca14c96895381c9 100644 (file)
@@ -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 (file)
index 0000000..05864fb
--- /dev/null
@@ -0,0 +1,44 @@
+#ifndef _COMPAT_GETENV_H
+#define _COMPAT_GETENV_H
+
+/*
+ * Copyright (C) 2015 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * 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 <stdlib.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <usterr-signal-safe.h>
+
+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 */
This page took 0.030401 seconds and 4 git commands to generate.