+#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 */
* 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;
}
}
+
+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
+}
$(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
#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;
* 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)
{
{
char *filename;
- filename = blkid_safe_getenv("BLKID_FILE");
+ filename = safe_getenv("BLKID_FILE");
if (filename)
filename = blkid_strdup(filename);
else if (conf)
#include "blkdev.h"
#include "blkidP.h"
-
+#include "env.h"
static int parse_evaluate(struct blkid_config *conf, char *s)
{
FILE *f;
if (!filename)
- filename = blkid_safe_getenv("BLKID_CONF");
+ filename = safe_getenv("BLKID_CONF");
if (!filename)
filename = BLKID_CONFIG_FILE;
$(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
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
#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>
#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)
{
*/
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;
}
*/
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;
}
*/
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;
}