|
|
b3731e |
From bb33136afa333268705c26e4f7e75b93e88db9bd Mon Sep 17 00:00:00 2001
|
|
|
b3731e |
From: Nalin Dahyabhai <nalin@redhat.com>
|
|
|
b3731e |
Date: Tue, 3 May 2016 13:32:25 -0400
|
|
|
b3731e |
Subject: [PATCH 1/3] Use secure_getenv() when it's available
|
|
|
b3731e |
|
|
|
b3731e |
Factor out logic that attempts to only consult the environment when it's
|
|
|
b3731e |
safe to do so into its own function, and use secure_getenv() instead of
|
|
|
b3731e |
getenv() if it's available. Original report from
|
|
|
b3731e |
https://bugzilla.redhat.com/show_bug.cgi?id=1332508
|
|
|
b3731e |
|
|
|
b3731e |
(cherry picked from commit 39b21dac9bc6473365de04d94be0da94941c7c73)
|
|
|
b3731e |
---
|
|
|
b3731e |
configure.ac | 3 ++-
|
|
|
b3731e |
src/lib/hesiod.c | 15 +++++++++++++--
|
|
|
b3731e |
2 files changed, 15 insertions(+), 3 deletions(-)
|
|
|
b3731e |
|
|
|
b3731e |
diff --git a/configure.ac b/configure.ac
|
|
|
b3731e |
index e5e94d4..9098afa 100644
|
|
|
b3731e |
--- a/configure.ac
|
|
|
b3731e |
+++ b/configure.ac
|
|
|
b3731e |
@@ -9,6 +9,7 @@ m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
|
|
|
b3731e |
AC_CONFIG_MACRO_DIR([m4])
|
|
|
b3731e |
AC_CONFIG_SRCDIR([src/lib/hesiod.h])
|
|
|
b3731e |
AC_CONFIG_HEADERS([config.h])
|
|
|
b3731e |
+AC_USE_SYSTEM_EXTENSIONS
|
|
|
b3731e |
|
|
|
b3731e |
# Checks for programs.
|
|
|
b3731e |
AC_PROG_CC
|
|
|
b3731e |
@@ -80,7 +81,7 @@ AC_EGREP_HEADER([pw_expire], [pwd.h],
|
|
|
b3731e |
# Checks for library functions.
|
|
|
b3731e |
AC_FUNC_MALLOC
|
|
|
b3731e |
AC_FUNC_REALLOC
|
|
|
b3731e |
-AC_CHECK_FUNCS([strchr strdup])
|
|
|
b3731e |
+AC_CHECK_FUNCS([strchr strdup secure_getenv])
|
|
|
b3731e |
|
|
|
b3731e |
AC_CONFIG_FILES([
|
|
|
b3731e |
Makefile
|
|
|
b3731e |
diff --git a/src/lib/hesiod.c b/src/lib/hesiod.c
|
|
|
b3731e |
index c96aebe..2738713 100644
|
|
|
b3731e |
--- a/src/lib/hesiod.c
|
|
|
b3731e |
+++ b/src/lib/hesiod.c
|
|
|
b3731e |
@@ -99,6 +99,17 @@ static int read_config_file(struct hesiod_p *ctx, const char *filename);
|
|
|
b3731e |
static char **get_txt_records(struct hesiod_p *ctx, const char *name);
|
|
|
b3731e |
static int cistrcmp(const char *s1, const char *s2);
|
|
|
b3731e |
|
|
|
b3731e |
+static const char *hesiod_getenv(const char *e)
|
|
|
b3731e |
+{
|
|
|
b3731e |
+ if ((getuid() != geteuid()) || (getgid() != getegid()))
|
|
|
b3731e |
+ return NULL;
|
|
|
b3731e |
+#ifdef HAVE_SECURE_GETENV
|
|
|
b3731e |
+ return secure_getenv(e);
|
|
|
b3731e |
+#else
|
|
|
b3731e |
+ return getenv(e);
|
|
|
b3731e |
+#endif
|
|
|
b3731e |
+}
|
|
|
b3731e |
+
|
|
|
b3731e |
/* This function is called to initialize a hesiod_p. */
|
|
|
b3731e |
int hesiod_init(void **context)
|
|
|
b3731e |
{
|
|
|
b3731e |
@@ -109,13 +120,13 @@ int hesiod_init(void **context)
|
|
|
b3731e |
if (ctx)
|
|
|
b3731e |
{
|
|
|
b3731e |
*context = ctx;
|
|
|
b3731e |
- configname = ((getuid() == geteuid()) && (getgid() == getegid())) ? getenv("HESIOD_CONFIG") : NULL;
|
|
|
b3731e |
+ configname = hesiod_getenv("HESIOD_CONFIG");
|
|
|
b3731e |
if (!configname)
|
|
|
b3731e |
configname = SYSCONFDIR "/hesiod.conf";
|
|
|
b3731e |
if (read_config_file(ctx, configname) >= 0)
|
|
|
b3731e |
{
|
|
|
b3731e |
/* The default rhs can be overridden by an environment variable. */
|
|
|
b3731e |
- p = ((getuid() == geteuid()) && (getgid() == getegid())) ? getenv("HES_DOMAIN") : NULL;
|
|
|
b3731e |
+ p = hesiod_getenv("HES_DOMAIN");
|
|
|
b3731e |
if (p)
|
|
|
b3731e |
{
|
|
|
b3731e |
if (ctx->rhs)
|
|
|
b3731e |
--
|
|
|
b3731e |
2.31.0
|
|
|
b3731e |
|