diff options
author | Karel Zak | 2010-12-24 01:07:48 +0100 |
---|---|---|
committer | Karel Zak | 2011-01-03 12:28:48 +0100 |
commit | 035507c84b53bceb143d0923e65916cbf90979c7 (patch) | |
tree | cddd11c53a78f1fd0ba44b9d8515c4e7ca74e0f5 /lib | |
parent | libmount: cleanup mount.sym (diff) | |
download | kernel-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.c | 36 |
1 files changed, 35 insertions, 1 deletions
@@ -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 +} |