e6660f4933111b0649ffa77483102881f4e75c3bvboxsync/* $Id$ */
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync/** @file
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync * VBoxGuestR3Lib - Ring-3 Support Library for VirtualBox guest additions, Additions Info.
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync */
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync/*
85668909c68b5d0e67c89d6042535b41c4bffeccvboxsync * Copyright (C) 2007-2011 Oracle Corporation
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync *
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync * available from http://www.virtualbox.org. This file is free software;
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync * you can redistribute it and/or modify it under the terms of the GNU
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync * General Public License (GPL) as published by the Free Software
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync *
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync * The contents of this file may alternatively be used under the terms
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync * of the Common Development and Distribution License Version 1.0
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync * VirtualBox OSE distribution, in which case the provisions of the
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync * CDDL are applicable instead of those of the GPL.
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync *
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync * You may elect to license modified versions of this file under the
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync * terms and conditions of either the GPL or the CDDL or both.
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync */
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync/*******************************************************************************
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync* Header Files *
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync*******************************************************************************/
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync#include <iprt/mem.h>
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync#include <iprt/string.h>
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync#include <VBox/log.h>
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync#include <VBox/version.h>
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync#include "VBGLR3Internal.h"
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync/**
093c337304805480b08e8d03146675b52a24997fvboxsync * Fallback for VbglR3GetAdditionsVersion.
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync */
8df35be0631db6b3ca2d388aa7f3e17f1782d093vboxsyncstatic int vbglR3GetAdditionsCompileTimeVersion(char **ppszVer, char **ppszVerEx, char **ppszRev)
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync{
093c337304805480b08e8d03146675b52a24997fvboxsync int rc = VINF_SUCCESS;
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync if (ppszVer)
093c337304805480b08e8d03146675b52a24997fvboxsync rc = RTStrDupEx(ppszVer, VBOX_VERSION_STRING_RAW);
093c337304805480b08e8d03146675b52a24997fvboxsync if (RT_SUCCESS(rc))
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync {
093c337304805480b08e8d03146675b52a24997fvboxsync if (ppszVerEx)
093c337304805480b08e8d03146675b52a24997fvboxsync rc = RTStrDupEx(ppszVerEx, VBOX_VERSION_STRING);
093c337304805480b08e8d03146675b52a24997fvboxsync if (RT_SUCCESS(rc))
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync {
093c337304805480b08e8d03146675b52a24997fvboxsync if (ppszRev)
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync {
093c337304805480b08e8d03146675b52a24997fvboxsync#if 0
093c337304805480b08e8d03146675b52a24997fvboxsync char szRev[64];
093c337304805480b08e8d03146675b52a24997fvboxsync RTStrPrintf(szRev, sizeof(szRev), "%d", VBOX_SVN_REV);
093c337304805480b08e8d03146675b52a24997fvboxsync rc = RTStrDupEx(ppszRev, szRev);
093c337304805480b08e8d03146675b52a24997fvboxsync#else
093c337304805480b08e8d03146675b52a24997fvboxsync rc = RTStrDupEx(ppszRev, RT_XSTR(VBOX_SVN_REV));
093c337304805480b08e8d03146675b52a24997fvboxsync#endif
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync }
093c337304805480b08e8d03146675b52a24997fvboxsync if (RT_SUCCESS(rc))
093c337304805480b08e8d03146675b52a24997fvboxsync return VINF_SUCCESS;
093c337304805480b08e8d03146675b52a24997fvboxsync
093c337304805480b08e8d03146675b52a24997fvboxsync /* bail out: */
093c337304805480b08e8d03146675b52a24997fvboxsync }
093c337304805480b08e8d03146675b52a24997fvboxsync if (ppszVerEx)
093c337304805480b08e8d03146675b52a24997fvboxsync {
093c337304805480b08e8d03146675b52a24997fvboxsync RTStrFree(*ppszVerEx);
093c337304805480b08e8d03146675b52a24997fvboxsync *ppszVerEx = NULL;
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync }
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync }
093c337304805480b08e8d03146675b52a24997fvboxsync if (ppszVer)
093c337304805480b08e8d03146675b52a24997fvboxsync {
093c337304805480b08e8d03146675b52a24997fvboxsync RTStrFree(*ppszVer);
093c337304805480b08e8d03146675b52a24997fvboxsync *ppszVer = NULL;
093c337304805480b08e8d03146675b52a24997fvboxsync }
093c337304805480b08e8d03146675b52a24997fvboxsync return rc;
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync}
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync#ifdef RT_OS_WINDOWS
093c337304805480b08e8d03146675b52a24997fvboxsync
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync/**
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync * Looks up the storage path handle (registry).
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync *
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync * @returns IPRT status value
daeb051c6c4d8fcda0a95a11b5a5406f722c2a70vboxsync * @param hKey Receives storage path handle on success.
daeb051c6c4d8fcda0a95a11b5a5406f722c2a70vboxsync * The returned handle must be closed by vbglR3CloseAdditionsWinStoragePath().
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync */
093c337304805480b08e8d03146675b52a24997fvboxsyncstatic int vbglR3QueryAdditionsWinStoragePath(PHKEY phKey)
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync{
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync /*
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync * Try get the *installed* version first.
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync */
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync LONG r;
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync
ce0bfa085d0cb5e498b310e0931ff036204a9bc3vboxsync /* Check the built in vendor path first. */
ce0bfa085d0cb5e498b310e0931ff036204a9bc3vboxsync char szPath[255];
ce0bfa085d0cb5e498b310e0931ff036204a9bc3vboxsync RTStrPrintf(szPath, sizeof(szPath), "SOFTWARE\\%s\\VirtualBox Guest Additions", VBOX_VENDOR_SHORT);
ce0bfa085d0cb5e498b310e0931ff036204a9bc3vboxsync r = RegOpenKeyEx(HKEY_LOCAL_MACHINE, szPath, 0, KEY_READ, phKey);
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync# ifdef RT_ARCH_AMD64
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync if (r != ERROR_SUCCESS)
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync {
ce0bfa085d0cb5e498b310e0931ff036204a9bc3vboxsync /* Check Wow6432Node. */
ce0bfa085d0cb5e498b310e0931ff036204a9bc3vboxsync RTStrPrintf(szPath, sizeof(szPath), "SOFTWARE\\Wow6432Node\\%s\\VirtualBox Guest Additions", VBOX_VENDOR_SHORT);
ce0bfa085d0cb5e498b310e0931ff036204a9bc3vboxsync r = RegOpenKeyEx(HKEY_LOCAL_MACHINE, szPath, 0, KEY_READ, phKey);
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync }
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync# endif
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync
ce0bfa085d0cb5e498b310e0931ff036204a9bc3vboxsync /* Check the "Sun" path first. */
ce0bfa085d0cb5e498b310e0931ff036204a9bc3vboxsync if (r != ERROR_SUCCESS)
ce0bfa085d0cb5e498b310e0931ff036204a9bc3vboxsync {
ce0bfa085d0cb5e498b310e0931ff036204a9bc3vboxsync r = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Sun\\VirtualBox Guest Additions", 0, KEY_READ, phKey);
ce0bfa085d0cb5e498b310e0931ff036204a9bc3vboxsync# ifdef RT_ARCH_AMD64
ce0bfa085d0cb5e498b310e0931ff036204a9bc3vboxsync if (r != ERROR_SUCCESS)
ce0bfa085d0cb5e498b310e0931ff036204a9bc3vboxsync {
ce0bfa085d0cb5e498b310e0931ff036204a9bc3vboxsync /* Check Wow6432Node (for new entries). */
ce0bfa085d0cb5e498b310e0931ff036204a9bc3vboxsync r = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Wow6432Node\\Sun\\VirtualBox Guest Additions", 0, KEY_READ, phKey);
ce0bfa085d0cb5e498b310e0931ff036204a9bc3vboxsync }
ce0bfa085d0cb5e498b310e0931ff036204a9bc3vboxsync# endif
ce0bfa085d0cb5e498b310e0931ff036204a9bc3vboxsync }
ce0bfa085d0cb5e498b310e0931ff036204a9bc3vboxsync
ce0bfa085d0cb5e498b310e0931ff036204a9bc3vboxsync /* Still no luck? Then try the old "Sun xVM" paths ... */
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync if (r != ERROR_SUCCESS)
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync {
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync r = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Sun\\xVM VirtualBox Guest Additions", 0, KEY_READ, phKey);
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync# ifdef RT_ARCH_AMD64
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync if (r != ERROR_SUCCESS)
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync {
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync /* Check Wow6432Node (for new entries). */
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync r = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Wow6432Node\\Sun\\xVM VirtualBox Guest Additions", 0, KEY_READ, phKey);
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync }
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync# endif
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync }
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync return RTErrConvertFromWin32(r);
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync}
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync/**
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync * Closes the storage path handle (registry).
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync *
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync * @returns IPRT status value
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync * @param hKey Handle to close, retrieved by
093c337304805480b08e8d03146675b52a24997fvboxsync * vbglR3QueryAdditionsWinStoragePath().
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync */
e6660f4933111b0649ffa77483102881f4e75c3bvboxsyncstatic int vbglR3CloseAdditionsWinStoragePath(HKEY hKey)
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync{
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync return RTErrConvertFromWin32(RegCloseKey(hKey));
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync}
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync#endif /* RT_OS_WINDOWS */
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync
1cca6326f8d4b7e11408cd2037ffd69820a70858vboxsync/**
1cca6326f8d4b7e11408cd2037ffd69820a70858vboxsync * Reports the Guest Additions status of a certain facility to the host.
1cca6326f8d4b7e11408cd2037ffd69820a70858vboxsync *
1cca6326f8d4b7e11408cd2037ffd69820a70858vboxsync * @returns IPRT status value
3e6252b2be1a3a887c3aa202a7e19b3a04804eedvboxsync * @param enmFacility The facility to report the status on.
3e6252b2be1a3a887c3aa202a7e19b3a04804eedvboxsync * @param enmStatus The new status of the facility.
3e6252b2be1a3a887c3aa202a7e19b3a04804eedvboxsync * @param fReserved Reserved for future use (what?).
1cca6326f8d4b7e11408cd2037ffd69820a70858vboxsync */
31a693ce9a8a9ebbecdcea9f24ce7f912aef4cd1vboxsyncVBGLR3DECL(int) VbglR3ReportAdditionsStatus(VBoxGuestFacilityType enmFacility,
31a693ce9a8a9ebbecdcea9f24ce7f912aef4cd1vboxsync VBoxGuestFacilityStatus enmStatusCurrent,
3e6252b2be1a3a887c3aa202a7e19b3a04804eedvboxsync uint32_t fReserved)
1cca6326f8d4b7e11408cd2037ffd69820a70858vboxsync{
1cca6326f8d4b7e11408cd2037ffd69820a70858vboxsync VMMDevReportGuestStatus Report;
1cca6326f8d4b7e11408cd2037ffd69820a70858vboxsync RT_ZERO(Report);
1cca6326f8d4b7e11408cd2037ffd69820a70858vboxsync int rc = vmmdevInitRequest((VMMDevRequestHeader*)&Report, VMMDevReq_ReportGuestStatus);
1cca6326f8d4b7e11408cd2037ffd69820a70858vboxsync if (RT_SUCCESS(rc))
1cca6326f8d4b7e11408cd2037ffd69820a70858vboxsync {
3e6252b2be1a3a887c3aa202a7e19b3a04804eedvboxsync Report.guestStatus.facility = enmFacility;
3e6252b2be1a3a887c3aa202a7e19b3a04804eedvboxsync Report.guestStatus.status = enmStatusCurrent;
3e6252b2be1a3a887c3aa202a7e19b3a04804eedvboxsync Report.guestStatus.flags = fReserved;
1cca6326f8d4b7e11408cd2037ffd69820a70858vboxsync
1cca6326f8d4b7e11408cd2037ffd69820a70858vboxsync rc = vbglR3GRPerform(&Report.header);
1cca6326f8d4b7e11408cd2037ffd69820a70858vboxsync }
1cca6326f8d4b7e11408cd2037ffd69820a70858vboxsync return rc;
1cca6326f8d4b7e11408cd2037ffd69820a70858vboxsync}
1cca6326f8d4b7e11408cd2037ffd69820a70858vboxsync
d08276b7d04bedada205a398be0ec08825498850vboxsync#ifdef RT_OS_WINDOWS
093c337304805480b08e8d03146675b52a24997fvboxsync
daeb051c6c4d8fcda0a95a11b5a5406f722c2a70vboxsync/**
daeb051c6c4d8fcda0a95a11b5a5406f722c2a70vboxsync * Queries a string value from a specified registry key.
daeb051c6c4d8fcda0a95a11b5a5406f722c2a70vboxsync *
daeb051c6c4d8fcda0a95a11b5a5406f722c2a70vboxsync * @return IPRT status code.
daeb051c6c4d8fcda0a95a11b5a5406f722c2a70vboxsync * @param hKey Handle of registry key to use.
daeb051c6c4d8fcda0a95a11b5a5406f722c2a70vboxsync * @param pszValName Value name to query value from.
daeb051c6c4d8fcda0a95a11b5a5406f722c2a70vboxsync * @param pszBuffer Pointer to buffer which the queried string value gets stored into.
daeb051c6c4d8fcda0a95a11b5a5406f722c2a70vboxsync * @param cchBuffer Size (in bytes) of buffer.
daeb051c6c4d8fcda0a95a11b5a5406f722c2a70vboxsync */
125438a68de6babc63185d666b1b6c3beb48307evboxsyncstatic int vbglR3QueryRegistryString(HKEY hKey, const char *pszValName, char *pszBuffer, size_t cchBuffer)
ae913ac9ffc89ee2a83992937b57f30e983185aavboxsync{
ae913ac9ffc89ee2a83992937b57f30e983185aavboxsync AssertReturn(pszValName, VERR_INVALID_PARAMETER);
ae913ac9ffc89ee2a83992937b57f30e983185aavboxsync AssertReturn(pszBuffer, VERR_INVALID_POINTER);
ae913ac9ffc89ee2a83992937b57f30e983185aavboxsync AssertReturn(cchBuffer, VERR_INVALID_PARAMETER);
ae913ac9ffc89ee2a83992937b57f30e983185aavboxsync
125438a68de6babc63185d666b1b6c3beb48307evboxsync int rc;
ae913ac9ffc89ee2a83992937b57f30e983185aavboxsync DWORD dwType;
ae913ac9ffc89ee2a83992937b57f30e983185aavboxsync DWORD dwSize = (DWORD)cchBuffer;
125438a68de6babc63185d666b1b6c3beb48307evboxsync LONG lRet = RegQueryValueEx(hKey, pszValName, NULL, &dwType, (BYTE *)pszBuffer, &dwSize);
ae913ac9ffc89ee2a83992937b57f30e983185aavboxsync if (lRet == ERROR_SUCCESS)
125438a68de6babc63185d666b1b6c3beb48307evboxsync rc = dwType == REG_SZ ? VINF_SUCCESS : VERR_INVALID_PARAMETER;
ae913ac9ffc89ee2a83992937b57f30e983185aavboxsync else
ae913ac9ffc89ee2a83992937b57f30e983185aavboxsync rc = RTErrConvertFromWin32(lRet);
ae913ac9ffc89ee2a83992937b57f30e983185aavboxsync return rc;
ae913ac9ffc89ee2a83992937b57f30e983185aavboxsync}
ae913ac9ffc89ee2a83992937b57f30e983185aavboxsync
d08276b7d04bedada205a398be0ec08825498850vboxsync#endif /* RT_OS_WINDOWS */
ae913ac9ffc89ee2a83992937b57f30e983185aavboxsync
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync/**
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync * Retrieves the installed Guest Additions version and/or revision.
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync *
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync * @returns IPRT status value
8df35be0631db6b3ca2d388aa7f3e17f1782d093vboxsync * @param ppszVer Receives pointer of allocated raw version string
8df35be0631db6b3ca2d388aa7f3e17f1782d093vboxsync * (major.minor.build). NULL is accepted. The returned
8df35be0631db6b3ca2d388aa7f3e17f1782d093vboxsync * pointer must be freed using RTStrFree().*
ae913ac9ffc89ee2a83992937b57f30e983185aavboxsync * @param ppszVerExt Receives pointer of allocated full version string
8df35be0631db6b3ca2d388aa7f3e17f1782d093vboxsync * (raw version + vendor suffix(es)). NULL is
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync * accepted. The returned pointer must be freed using
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync * RTStrFree().
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync * @param ppszRev Receives pointer of allocated revision string. NULL is
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync * accepted. The returned pointer must be freed using
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync * RTStrFree().
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync */
ae913ac9ffc89ee2a83992937b57f30e983185aavboxsyncVBGLR3DECL(int) VbglR3GetAdditionsVersion(char **ppszVer, char **ppszVerExt, char **ppszRev)
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync{
093c337304805480b08e8d03146675b52a24997fvboxsync /*
093c337304805480b08e8d03146675b52a24997fvboxsync * Zap the return value up front.
093c337304805480b08e8d03146675b52a24997fvboxsync */
093c337304805480b08e8d03146675b52a24997fvboxsync if (ppszVer)
125438a68de6babc63185d666b1b6c3beb48307evboxsync *ppszVer = NULL;
ae913ac9ffc89ee2a83992937b57f30e983185aavboxsync if (ppszVerExt)
ae913ac9ffc89ee2a83992937b57f30e983185aavboxsync *ppszVerExt = NULL;
093c337304805480b08e8d03146675b52a24997fvboxsync if (ppszRev)
125438a68de6babc63185d666b1b6c3beb48307evboxsync *ppszRev = NULL;
093c337304805480b08e8d03146675b52a24997fvboxsync
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync#ifdef RT_OS_WINDOWS
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync HKEY hKey;
093c337304805480b08e8d03146675b52a24997fvboxsync int rc = vbglR3QueryAdditionsWinStoragePath(&hKey);
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync if (RT_SUCCESS(rc))
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync {
093c337304805480b08e8d03146675b52a24997fvboxsync /*
093c337304805480b08e8d03146675b52a24997fvboxsync * Version.
093c337304805480b08e8d03146675b52a24997fvboxsync */
ae913ac9ffc89ee2a83992937b57f30e983185aavboxsync char szTemp[32];
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync if (ppszVer)
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync {
ae913ac9ffc89ee2a83992937b57f30e983185aavboxsync rc = vbglR3QueryRegistryString(hKey, "Version", szTemp, sizeof(szTemp));
ae913ac9ffc89ee2a83992937b57f30e983185aavboxsync if (RT_SUCCESS(rc))
ae913ac9ffc89ee2a83992937b57f30e983185aavboxsync rc = RTStrDupEx(ppszVer, szTemp);
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync }
ae913ac9ffc89ee2a83992937b57f30e983185aavboxsync
ae913ac9ffc89ee2a83992937b57f30e983185aavboxsync if ( RT_SUCCESS(rc)
ae913ac9ffc89ee2a83992937b57f30e983185aavboxsync && ppszVerExt)
8df35be0631db6b3ca2d388aa7f3e17f1782d093vboxsync {
ae913ac9ffc89ee2a83992937b57f30e983185aavboxsync rc = vbglR3QueryRegistryString(hKey, "VersionExt", szTemp, sizeof(szTemp));
ae913ac9ffc89ee2a83992937b57f30e983185aavboxsync if (RT_SUCCESS(rc))
ae913ac9ffc89ee2a83992937b57f30e983185aavboxsync rc = RTStrDupEx(ppszVerExt, szTemp);
8df35be0631db6b3ca2d388aa7f3e17f1782d093vboxsync }
093c337304805480b08e8d03146675b52a24997fvboxsync
093c337304805480b08e8d03146675b52a24997fvboxsync /*
093c337304805480b08e8d03146675b52a24997fvboxsync * Revision.
093c337304805480b08e8d03146675b52a24997fvboxsync */
ae913ac9ffc89ee2a83992937b57f30e983185aavboxsync if ( RT_SUCCESS(rc)
ae913ac9ffc89ee2a83992937b57f30e983185aavboxsync && ppszRev)
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync {
ae913ac9ffc89ee2a83992937b57f30e983185aavboxsync rc = vbglR3QueryRegistryString(hKey, "Revision", szTemp, sizeof(szTemp));
ae913ac9ffc89ee2a83992937b57f30e983185aavboxsync if (RT_SUCCESS(rc))
ae913ac9ffc89ee2a83992937b57f30e983185aavboxsync rc = RTStrDupEx(ppszRev, szTemp);
ae913ac9ffc89ee2a83992937b57f30e983185aavboxsync }
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync
ae913ac9ffc89ee2a83992937b57f30e983185aavboxsync int rc2 = vbglR3CloseAdditionsWinStoragePath(hKey);
ae913ac9ffc89ee2a83992937b57f30e983185aavboxsync if (RT_SUCCESS(rc))
ae913ac9ffc89ee2a83992937b57f30e983185aavboxsync rc = rc2;
125438a68de6babc63185d666b1b6c3beb48307evboxsync
125438a68de6babc63185d666b1b6c3beb48307evboxsync /* Clean up allocated strings on error. */
125438a68de6babc63185d666b1b6c3beb48307evboxsync if (RT_FAILURE(rc))
ae913ac9ffc89ee2a83992937b57f30e983185aavboxsync {
125438a68de6babc63185d666b1b6c3beb48307evboxsync if (ppszVer)
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync RTStrFree(*ppszVer);
125438a68de6babc63185d666b1b6c3beb48307evboxsync if (ppszVerExt)
ae913ac9ffc89ee2a83992937b57f30e983185aavboxsync RTStrFree(*ppszVerExt);
125438a68de6babc63185d666b1b6c3beb48307evboxsync if (ppszRev)
ae913ac9ffc89ee2a83992937b57f30e983185aavboxsync RTStrFree(*ppszRev);
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync }
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync }
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync else
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync {
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync /*
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync * No registry entries found, return the version string compiled
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync * into this binary.
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync */
ae913ac9ffc89ee2a83992937b57f30e983185aavboxsync rc = vbglR3GetAdditionsCompileTimeVersion(ppszVer, ppszVerExt, ppszRev);
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync }
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync return rc;
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync#else /* !RT_OS_WINDOWS */
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync /*
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync * On non-Windows platforms just return the compile-time version string.
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync */
ae913ac9ffc89ee2a83992937b57f30e983185aavboxsync return vbglR3GetAdditionsCompileTimeVersion(ppszVer, ppszVerExt, ppszRev);
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync#endif /* !RT_OS_WINDOWS */
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync}
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync/**
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync * Retrieves the installation path of Guest Additions.
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync *
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync * @returns IPRT status value
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync * @param ppszPath Receives pointer of allocated installation path string.
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync * The returned pointer must be freed using
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync * RTStrFree().
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync */
e6660f4933111b0649ffa77483102881f4e75c3bvboxsyncVBGLR3DECL(int) VbglR3GetAdditionsInstallationPath(char **ppszPath)
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync{
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync int rc;
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync#ifdef RT_OS_WINDOWS
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync HKEY hKey;
093c337304805480b08e8d03146675b52a24997fvboxsync rc = vbglR3QueryAdditionsWinStoragePath(&hKey);
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync if (RT_SUCCESS(rc))
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync {
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync /* Installation directory. */
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync DWORD dwType;
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync DWORD dwSize = _MAX_PATH * sizeof(char);
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync char *pszTmp = (char*)RTMemAlloc(dwSize + 1);
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync if (pszTmp)
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync {
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync LONG l = RegQueryValueEx(hKey, "InstallDir", NULL, &dwType, (BYTE*)(LPCTSTR)pszTmp, &dwSize);
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync if ((l != ERROR_SUCCESS) && (l != ERROR_FILE_NOT_FOUND))
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync {
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync rc = RTErrConvertFromNtStatus(l);
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync }
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync else
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync {
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync if (dwType == REG_SZ)
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync rc = RTStrDupEx(ppszPath, pszTmp);
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync else
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync rc = VERR_INVALID_PARAMETER;
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync if (RT_SUCCESS(rc))
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync {
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync /* Flip slashes. */
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync for (char *pszTmp2 = ppszPath[0]; *pszTmp2; ++pszTmp2)
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync if (*pszTmp2 == '\\')
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync *pszTmp2 = '/';
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync }
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync }
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync RTMemFree(pszTmp);
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync }
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync else
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync rc = VERR_NO_MEMORY;
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync rc = vbglR3CloseAdditionsWinStoragePath(hKey);
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync }
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync#else
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync /** @todo implement me */
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync rc = VERR_NOT_IMPLEMENTED;
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync#endif
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync return rc;
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync}
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync