diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-21 04:59:33 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-21 04:59:33 +0000 |
commit | 857a92991db30f538ea8858a2dfda0fe606353e3 (patch) | |
tree | dcf97aa3a41925c05670bb640cdd495fc1083f72 /lib/ext2fs/getenv.c | |
parent | Adding debian version 1.47.0-2.4. (diff) | |
download | e2fsprogs-857a92991db30f538ea8858a2dfda0fe606353e3.tar.xz e2fsprogs-857a92991db30f538ea8858a2dfda0fe606353e3.zip |
Merging upstream version 1.47.1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'lib/ext2fs/getenv.c')
-rw-r--r-- | lib/ext2fs/getenv.c | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/lib/ext2fs/getenv.c b/lib/ext2fs/getenv.c new file mode 100644 index 0000000..409a78a --- /dev/null +++ b/lib/ext2fs/getenv.c @@ -0,0 +1,57 @@ +/* + * getenv.c --- implement a safe getenv for use by the ext2fs library + * + * Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, + * 2002 by Theodore Ts'o. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ +#if !defined(__FreeBSD__) && !defined(__NetBSD__) && !defined(__OpenBSD__) +#define _XOPEN_SOURCE 600 +#define _DARWIN_C_SOURCE +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif +#endif + +#include "config.h" +#include <stdlib.h> +#if HAVE_UNISTD_H +#include <unistd.h> +#endif +#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 "ext2fs.h" + +char *ext2fs_safe_getenv(const char *arg) +{ + if ((getuid() != geteuid()) || (getgid() != getegid())) + return NULL; +#ifdef 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 + +#if defined(HAVE_SECURE_GETENV) + return secure_getenv(arg); +#elif defined(HAVE___SECURE_GETENV) + return __secure_getenv(arg); +#else + return getenv(arg); +#endif +} |