summaryrefslogtreecommitdiff
path: root/src/VBox/Additions/common/VBoxService/VBoxServiceUtils.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/VBox/Additions/common/VBoxService/VBoxServiceUtils.cpp')
-rw-r--r--src/VBox/Additions/common/VBoxService/VBoxServiceUtils.cpp74
1 files changed, 68 insertions, 6 deletions
diff --git a/src/VBox/Additions/common/VBoxService/VBoxServiceUtils.cpp b/src/VBox/Additions/common/VBoxService/VBoxServiceUtils.cpp
index 6dcff3a8..9302a843 100644
--- a/src/VBox/Additions/common/VBoxService/VBoxServiceUtils.cpp
+++ b/src/VBox/Additions/common/VBoxService/VBoxServiceUtils.cpp
@@ -4,7 +4,7 @@
*/
/*
- * Copyright (C) 2009-2010 Oracle Corporation
+ * Copyright (C) 2009-2012 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
@@ -47,8 +47,12 @@
* @param puTimestamp Where to return the timestamp. This is only set
* on success. Optional.
*/
-int VBoxServiceReadProp(uint32_t u32ClientId, const char *pszPropName, char **ppszValue, char **ppszFlags, uint64_t *puTimestamp)
+int VBoxServiceReadProp(uint32_t u32ClientId, const char *pszPropName,
+ char **ppszValue, char **ppszFlags, uint64_t *puTimestamp)
{
+ AssertPtrReturn(pszPropName, VERR_INVALID_POINTER);
+ AssertPtrReturn(ppszValue, VERR_INVALID_POINTER);
+
uint32_t cbBuf = _1K;
void *pvBuf = NULL;
int rc;
@@ -106,7 +110,8 @@ int VBoxServiceReadProp(uint32_t u32ClientId, const char *pszPropName, char **pp
break; /* done */
}
- RTMemFree(pvBuf);
+ if (pvBuf)
+ RTMemFree(pvBuf);
return rc;
}
@@ -121,14 +126,14 @@ int VBoxServiceReadProp(uint32_t u32ClientId, const char *pszPropName, char **pp
* @param pu32 Where to store the 32-bit value.
*
*/
-int VBoxServiceReadPropUInt32(uint32_t u32ClientId, const char *pszPropName, uint32_t *pu32, uint32_t u32Min, uint32_t u32Max)
+int VBoxServiceReadPropUInt32(uint32_t u32ClientId, const char *pszPropName,
+ uint32_t *pu32, uint32_t u32Min, uint32_t u32Max)
{
char *pszValue;
int rc = VBoxServiceReadProp(u32ClientId, pszPropName, &pszValue,
- NULL /* ppszFlags */, NULL /* puTimestamp */);
+ NULL /* ppszFlags */, NULL /* puTimestamp */);
if (RT_SUCCESS(rc))
{
- AssertPtr(pu32);
char *pszNext;
rc = RTStrToUInt32Ex(pszValue, &pszNext, 0, pu32);
if ( RT_SUCCESS(rc)
@@ -144,6 +149,63 @@ int VBoxServiceReadPropUInt32(uint32_t u32ClientId, const char *pszPropName, uin
/**
+ * Reads a guest property from the host side.
+ *
+ * @returns IPRT status code, fully bitched.
+ * @param u32ClientId The HGCM client ID for the guest property session.
+ * @param pszPropName The property name.
+ * @param fReadOnly Whether or not this property needs to be read only
+ * by the guest side. Otherwise VERR_ACCESS_DENIED will
+ * be returned.
+ * @param ppszValue Where to return the value. This is always set
+ * to NULL. Free it using RTStrFree().
+ * @param ppszFlags Where to return the value flags. Free it
+ * using RTStrFree(). Optional.
+ * @param puTimestamp Where to return the timestamp. This is only set
+ * on success. Optional.
+ */
+int VBoxServiceReadHostProp(uint32_t u32ClientId, const char *pszPropName, bool fReadOnly,
+ char **ppszValue, char **ppszFlags, uint64_t *puTimestamp)
+{
+ AssertPtrReturn(ppszValue, VERR_INVALID_PARAMETER);
+
+ char *pszValue = NULL;
+ char *pszFlags = NULL;
+ int rc = VBoxServiceReadProp(u32ClientId, pszPropName, &pszValue, &pszFlags, puTimestamp);
+ if (RT_SUCCESS(rc))
+ {
+ /* Check security bits. */
+ if ( fReadOnly /* Do we except a guest read-only property */
+ && !RTStrStr(pszFlags, "RDONLYGUEST"))
+ {
+ /* If we want a property which is read-only on the guest
+ * and it is *not* marked as such, deny access! */
+ rc = VERR_ACCESS_DENIED;
+ }
+
+ if (RT_SUCCESS(rc))
+ {
+ *ppszValue = pszValue;
+
+ if (ppszFlags)
+ *ppszFlags = pszFlags;
+ else if (pszFlags)
+ RTStrFree(pszFlags);
+ }
+ else
+ {
+ if (pszValue)
+ RTStrFree(pszValue);
+ if (pszFlags)
+ RTStrFree(pszFlags);
+ }
+ }
+
+ return rc;
+}
+
+
+/**
* Wrapper around VbglR3GuestPropWriteValue that does value formatting and
* logging.
*