提交 25ebb2f8 编写于 作者: D Daniel P. Berrange

Add helpers for getting env vars in a setuid environment

Care must be taken accessing env variables when running
setuid. Introduce a virGetEnvAllowSUID for env vars which
are safe to use in a setuid environment, and another
virGetEnvBlockSUID for vars which are not safe. Also add
a virIsSUID helper method for any other non-env var code
to use.
Signed-off-by: NDaniel P. Berrange <berrange@redhat.com>
(cherry picked from commit ae53e5d1)
上级 1adbe4fa
...@@ -93,6 +93,7 @@ recv ...@@ -93,6 +93,7 @@ recv
regex regex
random_r random_r
sched sched
secure_getenv
send send
setenv setenv
setsockopt setsockopt
......
...@@ -2051,6 +2051,8 @@ virFindFCHostCapableVport; ...@@ -2051,6 +2051,8 @@ virFindFCHostCapableVport;
virFormatIntDecimal; virFormatIntDecimal;
virGetDeviceID; virGetDeviceID;
virGetDeviceUnprivSGIO; virGetDeviceUnprivSGIO;
virGetEnvAllowSUID;
virGetEnvBlockSUID;
virGetFCHostNameByWWN; virGetFCHostNameByWWN;
virGetGroupID; virGetGroupID;
virGetGroupList; virGetGroupList;
...@@ -2069,6 +2071,7 @@ virIndexToDiskName; ...@@ -2069,6 +2071,7 @@ virIndexToDiskName;
virIsCapableFCHost; virIsCapableFCHost;
virIsCapableVport; virIsCapableVport;
virIsDevMapperDevice; virIsDevMapperDevice;
virIsSUID;
virManageVport; virManageVport;
virParseNumber; virParseNumber;
virParseOwnershipIds; virParseOwnershipIds;
......
...@@ -2128,3 +2128,42 @@ cleanup: ...@@ -2128,3 +2128,42 @@ cleanup:
return rc; 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();
}
...@@ -172,4 +172,8 @@ int virCompareLimitUlong(unsigned long long a, unsigned long b); ...@@ -172,4 +172,8 @@ int virCompareLimitUlong(unsigned long long a, unsigned long b);
int virParseOwnershipIds(const char *label, uid_t *uidPtr, gid_t *gidPtr); 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__ */ #endif /* __VIR_UTIL_H__ */
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册