]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Add helpers for getting env vars in a setuid environment
authorDaniel P. Berrange <berrange@redhat.com>
Wed, 9 Oct 2013 09:52:39 +0000 (10:52 +0100)
committerDaniel P. Berrange <berrange@redhat.com>
Mon, 21 Oct 2013 13:18:47 +0000 (14:18 +0100)
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: Daniel P. Berrange <berrange@redhat.com>
(cherry picked from commit ae53e5d10e434e07079d7e3ba11ec654ba6a256e)

bootstrap.conf
src/libvirt_private.syms
src/util/virutil.c
src/util/virutil.h

index 68c4a890c5159f916f323ebf04077510ecc3374b..8a4368b8ccef7beb05dfe74c8816d529af85f184 100644 (file)
@@ -93,6 +93,7 @@ recv
 regex
 random_r
 sched
+secure_getenv
 send
 setenv
 setsockopt
index 4bc4d69977f2107de3aeaac99c9838d99c76e829..02b999b9513e689bd9220ad56bdc3a1ee350b8aa 100644 (file)
@@ -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;
index d9e0bc4a42b814c6539c8f85a554854e065d1684..f0bba41c649a2c73ca6e73c4fa6f57662803e796 100644 (file)
@@ -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();
+}
index 4b06992346d853b02b49a200bb9f60e2832ddf66..8739e4edb1a0690041e883678272561cc7e3a294 100644 (file)
@@ -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__ */