diff --git a/bootstrap.conf b/bootstrap.conf index 8b3721741a..d24a71432c 100644 --- a/bootstrap.conf +++ b/bootstrap.conf @@ -93,6 +93,7 @@ recv regex random_r sched +secure_getenv send setenv setsockopt diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 84c1c28a18..9be6f327e7 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1859,6 +1859,8 @@ virFindFCHostCapableVport; virFormatIntDecimal; virGetDeviceID; virGetDeviceUnprivSGIO; +virGetEnvAllowSUID; +virGetEnvBlockSUID; virGetFCHostNameByWWN; virGetGroupID; virGetGroupList; @@ -1877,6 +1879,7 @@ virIndexToDiskName; virIsCapableFCHost; virIsCapableVport; virIsDevMapperDevice; +virIsSUID; virManageVport; virParseNumber; virParseOwnershipIds; diff --git a/src/util/virutil.c b/src/util/virutil.c index 854c0ad5ec..7e7c1c2d18 100644 --- a/src/util/virutil.c +++ b/src/util/virutil.c @@ -2131,3 +2131,42 @@ cleanup: return rc; } + + +/** + * virGetEnvBlockSUID: + * @name: the environment variable name + * + * Obtain an environment variable which is unsafe to + * use when running setuid. If running setuid, a NULL + * value will be returned + */ +const char *virGetEnvBlockSUID(const char *name) +{ + return secure_getenv(name); +} + + +/** + * virGetEnvBlockSUID: + * @name: the environment variable name + * + * Obtain an environment variable which is safe to + * use when running setuid. The value will be returned + * even when running setuid + */ +const char *virGetEnvAllowSUID(const char *name) +{ + return getenv(name); +} + + +/** + * virIsSUID: + * Return a true value if running setuid. Does not + * check for elevated capabilities bits. + */ +bool virIsSUID(void) +{ + return getuid() != geteuid(); +} diff --git a/src/util/virutil.h b/src/util/virutil.h index 9f6fb200a4..e8765b24a7 100644 --- a/src/util/virutil.h +++ b/src/util/virutil.h @@ -172,4 +172,8 @@ int virCompareLimitUlong(unsigned long long a, unsigned long long b); int virParseOwnershipIds(const char *label, uid_t *uidPtr, gid_t *gidPtr); +const char *virGetEnvBlockSUID(const char *name); +const char *virGetEnvAllowSUID(const char *name); +bool virIsSUID(void); + #endif /* __VIR_UTIL_H__ */