diff --git a/bootstrap.conf b/bootstrap.conf index 68c4a890c5159f916f323ebf04077510ecc3374b..8a4368b8ccef7beb05dfe74c8816d529af85f184 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 4bc4d69977f2107de3aeaac99c9838d99c76e829..02b999b9513e689bd9220ad56bdc3a1ee350b8aa 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2051,6 +2051,8 @@ virFindFCHostCapableVport; virFormatIntDecimal; virGetDeviceID; virGetDeviceUnprivSGIO; +virGetEnvAllowSUID; +virGetEnvBlockSUID; virGetFCHostNameByWWN; virGetGroupID; virGetGroupList; @@ -2069,6 +2071,7 @@ virIndexToDiskName; virIsCapableFCHost; virIsCapableVport; virIsDevMapperDevice; +virIsSUID; virManageVport; virParseNumber; virParseOwnershipIds; diff --git a/src/util/virutil.c b/src/util/virutil.c index d9e0bc4a42b814c6539c8f85a554854e065d1684..f0bba41c649a2c73ca6e73c4fa6f57662803e796 100644 --- a/src/util/virutil.c +++ b/src/util/virutil.c @@ -2128,3 +2128,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 4b06992346d853b02b49a200bb9f60e2832ddf66..8739e4edb1a0690041e883678272561cc7e3a294 100644 --- a/src/util/virutil.h +++ b/src/util/virutil.h @@ -172,4 +172,8 @@ int virCompareLimitUlong(unsigned long long a, unsigned 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__ */