summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorKarel Zak2010-12-24 01:07:48 +0100
committerKarel Zak2011-01-03 12:28:48 +0100
commit035507c84b53bceb143d0923e65916cbf90979c7 (patch)
treecddd11c53a78f1fd0ba44b9d8515c4e7ca74e0f5 /lib
parentlibmount: cleanup mount.sym (diff)
downloadkernel-qcow2-util-linux-035507c84b53bceb143d0923e65916cbf90979c7.tar.gz
kernel-qcow2-util-linux-035507c84b53bceb143d0923e65916cbf90979c7.tar.xz
kernel-qcow2-util-linux-035507c84b53bceb143d0923e65916cbf90979c7.zip
lib: [env] consolidate safe_getenv() usage
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/env.c36
1 files changed, 35 insertions, 1 deletions
diff --git a/lib/env.c b/lib/env.c
index 82fadf524..770cadff9 100644
--- a/lib/env.c
+++ b/lib/env.c
@@ -3,11 +3,22 @@
* Added from shadow-utils package
* by Arkadiusz Mi¶kiewicz <misiek@pld.ORG.PL>
*
- */
+ */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#ifdef HAVE_SYS_PRCTL_H
+#include <sys/prctl.h>
+#else
+#define PR_GET_DUMPABLE 3
+#endif
+#if (!defined(HAVE_PRCTL) && defined(linux))
+#include <sys/syscall.h>
+#endif
+#include <unistd.h>
+#include <sys/types.h>
+
#include "env.h"
extern char **environ;
@@ -71,3 +82,26 @@ sanitize_env(void)
}
}
+
+char *safe_getenv(const char *arg)
+{
+ uid_t ruid = getuid();
+
+ if (ruid != 0 || (ruid != geteuid()) || (getgid() != getegid()))
+ return NULL;
+#if HAVE_PRCTL
+ if (prctl(PR_GET_DUMPABLE, 0, 0, 0, 0) == 0)
+ return NULL;
+#else
+#if (defined(linux) && defined(SYS_prctl))
+ if (syscall(SYS_prctl, PR_GET_DUMPABLE, 0, 0, 0, 0) == 0)
+ return NULL;
+#endif
+#endif
+
+#ifdef HAVE___SECURE_GETENV
+ return __secure_getenv(arg);
+#else
+ return getenv(arg);
+#endif
+}