When running set[ug]id, don't check the environment.

Idea from OpenBSD, but made a bit more generic to handle uncivilized lands
that do not define issetugid.

svn:r1529
This commit is contained in:
Nick Mathewson 2009-11-15 18:59:55 +00:00
parent b4183c732e
commit eb1fa9f78e
11 changed files with 43 additions and 9 deletions

View File

@ -6,6 +6,7 @@ Changes in 1.4.13-stable:
o Rename our replacement compat/sys/_time.h header to avoid build a conflict on HPUX; reported by Kathryn Hogg.
o Build kqueue.c correctly on GNU/kFreeBSD platforms. Patch pulled upstream from Debian.
o Fix a problem with excessive memory allocation when using multiple event priorities.
o When running set[ug]id, don't check the environment. Based on a patch from OpenBSD.
Changes in 1.4.12-stable:

View File

@ -136,7 +136,7 @@ AC_C_INLINE
AC_HEADER_TIME
dnl Checks for library functions.
AC_CHECK_FUNCS(gettimeofday vasprintf fcntl clock_gettime strtok_r strsep getaddrinfo getnameinfo strlcpy inet_ntop signal sigaction strtoll)
AC_CHECK_FUNCS(gettimeofday vasprintf fcntl clock_gettime strtok_r strsep getaddrinfo getnameinfo strlcpy inet_ntop signal sigaction strtoll issetugid geteuid getegid)
AC_CHECK_SIZEOF(long)

View File

@ -131,7 +131,7 @@ devpoll_init(struct event_base *base)
struct devpollop *devpollop;
/* Disable devpoll when this environment variable is set */
if (getenv("EVENT_NODEVPOLL"))
if (evutil_getenv("EVENT_NODEVPOLL"))
return (NULL);
if (!(devpollop = calloc(1, sizeof(struct devpollop))))

View File

@ -113,7 +113,7 @@ epoll_init(struct event_base *base)
struct epollop *epollop;
/* Disable epollueue when this environment variable is set */
if (getenv("EVENT_NOEPOLL"))
if (evutil_getenv("EVENT_NOEPOLL"))
return (NULL);
/* Initalize the kernel queue */

View File

@ -91,6 +91,9 @@ int _evsignal_set_handler(struct event_base *base, int evsignal,
void (*fn)(int));
int _evsignal_restore_handler(struct event_base *base, int evsignal);
/* defined in evutil.c */
const char *evutil_getenv(const char *varname);
#ifdef __cplusplus
}
#endif

View File

@ -193,7 +193,7 @@ event_base_new(void)
if (base->evbase == NULL)
event_errx(1, "%s: no event mechanism available", __func__);
if (getenv("EVENT_SHOW_METHOD"))
if (evutil_getenv("EVENT_SHOW_METHOD"))
event_msgx("libevent using: %s\n",
base->evsel->name);

View File

@ -143,7 +143,7 @@ evport_init(struct event_base *base)
/*
* Disable event ports when this environment variable is set
*/
if (getenv("EVENT_NOEVPORT"))
if (evutil_getenv("EVENT_NOEVPORT"))
return (NULL);
if (!(evpd = calloc(1, sizeof(struct evport_data))))

View File

@ -54,6 +54,9 @@
#endif
#include <stdio.h>
#include <sys/queue.h>
#include "event.h"
#include "event-internal.h"
#include "evutil.h"
#include "log.h"
@ -243,3 +246,31 @@ evutil_vsnprintf(char *buf, size_t buflen, const char *format, va_list ap)
return r;
#endif
}
static int
evutil_issetugid(void)
{
#ifdef _EVENT_HAVE_ISSETUGID
return issetugid();
#else
#ifdef _EVENT_HAVE_GETEUID
if (getuid() != geteuid())
return 1;
#endif
#ifdef _EVENT_HAVE_GETEGID
if (getgid() != getegid())
return 1;
#endif
return 0;
#endif
}
const char *
evutil_getenv(const char *varname)
{
if (evutil_issetugid())
return NULL;
return getenv(varname);
}

View File

@ -63,7 +63,6 @@
#include "event.h"
#include "event-internal.h"
#include "log.h"
#include "event-internal.h"
#define EVLIST_X_KQINKERNEL 0x1000
@ -103,7 +102,7 @@ kq_init(struct event_base *base)
struct kqop *kqueueop;
/* Disable kqueue when this environment variable is set */
if (getenv("EVENT_NOKQUEUE"))
if (evutil_getenv("EVENT_NOKQUEUE"))
return (NULL);
if (!(kqueueop = calloc(1, sizeof(struct kqop))))

2
poll.c
View File

@ -87,7 +87,7 @@ poll_init(struct event_base *base)
struct pollop *pollop;
/* Disable poll when this environment variable is set */
if (getenv("EVENT_NOPOLL"))
if (evutil_getenv("EVENT_NOPOLL"))
return (NULL);
if (!(pollop = calloc(1, sizeof(struct pollop))))

View File

@ -102,7 +102,7 @@ select_init(struct event_base *base)
struct selectop *sop;
/* Disable select when this environment variable is set */
if (getenv("EVENT_NOSELECT"))
if (evutil_getenv("EVENT_NOSELECT"))
return (NULL);
if (!(sop = calloc(1, sizeof(struct selectop))))