summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/env.h6
-rw-r--r--lib/env.c36
-rw-r--r--shlibs/blkid/src/Makefile.am3
-rw-r--r--shlibs/blkid/src/cache.c32
-rw-r--r--shlibs/blkid/src/config.c4
-rw-r--r--shlibs/mount/src/Makefile.am3
-rw-r--r--shlibs/mount/src/init.c2
-rw-r--r--shlibs/mount/src/utils.c38
8 files changed, 54 insertions, 70 deletions
diff --git a/include/env.h b/include/env.h
index d69b4f295..bcd0f7ead 100644
--- a/include/env.h
+++ b/include/env.h
@@ -1,2 +1,8 @@
+#ifndef UTIL_LINUX_ENV_H
+#define UTIL_LINUX_ENV_H
+
extern void sanitize_env (void);
+extern char *safe_getenv(const char *arg);
+
+#endif /* UTIL_LINUX_ENV_H */
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
+}
diff --git a/shlibs/blkid/src/Makefile.am b/shlibs/blkid/src/Makefile.am
index 47d2a370a..b0701cb7b 100644
--- a/shlibs/blkid/src/Makefile.am
+++ b/shlibs/blkid/src/Makefile.am
@@ -32,7 +32,8 @@ libblkid_la_SOURCES = cache.c dev.c devname.c devno.c getsize.c llseek.c \
$(top_srcdir)/lib/canonicalize.c \
$(top_srcdir)/lib/md5.c \
$(top_srcdir)/lib/crc32.c \
- $(top_srcdir)/include/list.h
+ $(top_srcdir)/include/list.h \
+ $(top_srcdir)/lib/env.c
nodist_libblkid_la_SOURCES = blkid.h
diff --git a/shlibs/blkid/src/cache.c b/shlibs/blkid/src/cache.c
index e71176b50..6f53dc99a 100644
--- a/shlibs/blkid/src/cache.c
+++ b/shlibs/blkid/src/cache.c
@@ -18,18 +18,11 @@
#endif
#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
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
#include "blkidP.h"
+#include "env.h"
int blkid_debug_mask = 0;
@@ -58,27 +51,6 @@ int blkid_debug_mask = 0;
* the cache file is required in this situation.
*/
-char *blkid_safe_getenv(const char *arg)
-{
- if ((getuid() != 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
-}
-
#if 0 /* ifdef CONFIG_BLKID_DEBUG */
static blkid_debug_dump_cache(int mask, blkid_cache cache)
{
@@ -126,7 +98,7 @@ char *blkid_get_cache_filename(struct blkid_config *conf)
{
char *filename;
- filename = blkid_safe_getenv("BLKID_FILE");
+ filename = safe_getenv("BLKID_FILE");
if (filename)
filename = blkid_strdup(filename);
else if (conf)
diff --git a/shlibs/blkid/src/config.c b/shlibs/blkid/src/config.c
index fcc7b6f12..e4d25ba46 100644
--- a/shlibs/blkid/src/config.c
+++ b/shlibs/blkid/src/config.c
@@ -28,7 +28,7 @@
#include "blkdev.h"
#include "blkidP.h"
-
+#include "env.h"
static int parse_evaluate(struct blkid_config *conf, char *s)
{
@@ -120,7 +120,7 @@ struct blkid_config *blkid_read_config(const char *filename)
FILE *f;
if (!filename)
- filename = blkid_safe_getenv("BLKID_CONF");
+ filename = safe_getenv("BLKID_CONF");
if (!filename)
filename = BLKID_CONFIG_FILE;
diff --git a/shlibs/mount/src/Makefile.am b/shlibs/mount/src/Makefile.am
index 6c241ba2d..f552ebee9 100644
--- a/shlibs/mount/src/Makefile.am
+++ b/shlibs/mount/src/Makefile.am
@@ -18,7 +18,8 @@ libmount_la_SOURCES = mountP.h version.c utils.c test.c init.c cache.c \
$(top_srcdir)/include/list.h \
$(top_srcdir)/lib/mangle.c \
$(top_srcdir)/lib/canonicalize.c \
- $(top_srcdir)/lib/strutils.c
+ $(top_srcdir)/lib/strutils.c \
+ $(top_srcdir)/lib/env.c
nodist_libmount_la_SOURCES = mountP.h
diff --git a/shlibs/mount/src/init.c b/shlibs/mount/src/init.c
index 2dfab58f3..d80a2d8ca 100644
--- a/shlibs/mount/src/init.c
+++ b/shlibs/mount/src/init.c
@@ -33,7 +33,7 @@ void mnt_init_debug(int mask)
if (libmount_debug_mask & MNT_DEBUG_INIT)
return;
if (!mask) {
- char *str = mnt_getenv_safe("LIBMOUNT_DEBUG");
+ char *str = getenv("LIBMOUNT_DEBUG");
if (str)
libmount_debug_mask = strtoul(str, 0, 0);
} else
diff --git a/shlibs/mount/src/utils.c b/shlibs/mount/src/utils.c
index ff3c90cdb..c97144dcb 100644
--- a/shlibs/mount/src/utils.c
+++ b/shlibs/mount/src/utils.c
@@ -14,14 +14,6 @@
#include <errno.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 <sys/stat.h>
#include <ctype.h>
#include <sys/types.h>
@@ -34,29 +26,7 @@
#include "mountP.h"
#include "mangle.h"
#include "canonicalize.h"
-
-char *mnt_getenv_safe(const char *arg)
-{
- return getenv(arg);
-
- if ((getuid() != 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
-}
+#include "env.h"
int endswith(const char *s, const char *sx)
{
@@ -635,7 +605,7 @@ done:
*/
const char *mnt_get_fstab_path(void)
{
- const char *p = mnt_getenv_safe("LIBMOUNT_FSTAB");
+ const char *p = safe_getenv("LIBMOUNT_FSTAB");
return p ? : _PATH_MNTTAB;
}
@@ -649,7 +619,7 @@ const char *mnt_get_fstab_path(void)
*/
const char *mnt_get_mtab_path(void)
{
- const char *p = mnt_getenv_safe("LIBMOUNT_MTAB");
+ const char *p = safe_getenv("LIBMOUNT_MTAB");
return p ? : _PATH_MOUNTED;
}
@@ -660,7 +630,7 @@ const char *mnt_get_mtab_path(void)
*/
const char *mnt_get_utab_path(void)
{
- const char *p = mnt_getenv_safe("LIBMOUNT_UTAB");
+ const char *p = safe_getenv("LIBMOUNT_UTAB");
return p ? : MNT_PATH_UTAB;
}