VBoxGuestR3LibAdditions.cpp revision 31a693ce9a8a9ebbecdcea9f24ce7f912aef4cd1
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync/* $Id$ */
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync/** @file
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync * VBoxGuestR3Lib - Ring-3 Support Library for VirtualBox guest additions, Additions Info.
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync */
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync/*
e64031e20c39650a7bc902a3e1aba613b9415deevboxsync * Copyright (C) 2007-2010 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/**
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync * Fallback for vbglR3GetAdditionsVersion.
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync */
e6660f4933111b0649ffa77483102881f4e75c3bvboxsyncstatic int vbglR3GetAdditionsCompileTimeVersion(char **ppszVer, char **ppszRev)
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync{
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync if (ppszVer)
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync {
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync *ppszVer = RTStrDup(VBOX_VERSION_STRING);
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync if (!*ppszVer)
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync return VERR_NO_STR_MEMORY;
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync }
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync if (ppszRev)
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync {
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync char szRev[64];
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync RTStrPrintf(szRev, sizeof(szRev), "%d", VBOX_SVN_REV);
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync *ppszRev = RTStrDup(szRev);
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync if (!*ppszRev)
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync {
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync if (ppszVer)
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync {
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync RTStrFree(*ppszVer);
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync *ppszVer = NULL;
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync }
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync return VERR_NO_STR_MEMORY;
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync }
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync }
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync return VINF_SUCCESS;
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync}
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync#ifdef RT_OS_WINDOWS
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync/**
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync * Looks up the storage path handle (registry).
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync *
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync * @returns IPRT status value
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync * @param hKey Receives pointer of allocated version string. NULL is
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync * accepted. The returned pointer must be closed by
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync * vbglR3CloseAdditionsWinStoragePath().
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync */
e6660f4933111b0649ffa77483102881f4e75c3bvboxsyncstatic int vbglR3GetAdditionsWinStoragePath(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
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync * vbglR3GetAdditionsWinStoragePath().
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
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync/**
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync * Retrieves the installed Guest Additions version and/or revision.
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync *
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync * @returns IPRT status value
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync * @param ppszVer Receives pointer of allocated version string. 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 */
e6660f4933111b0649ffa77483102881f4e75c3bvboxsyncVBGLR3DECL(int) VbglR3GetAdditionsVersion(char **ppszVer, char **ppszRev)
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync{
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync#ifdef RT_OS_WINDOWS
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync HKEY hKey;
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync int rc = vbglR3GetAdditionsWinStoragePath(&hKey);
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync if (RT_SUCCESS(rc))
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync {
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync /* Version. */
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync LONG l;
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync DWORD dwType;
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync DWORD dwSize = 32;
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync char *pszTmp;
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync if (ppszVer)
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync {
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync pszTmp = (char*)RTMemAlloc(dwSize);
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync if (pszTmp)
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync {
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync l = RegQueryValueEx(hKey, "Version", NULL, &dwType, (BYTE*)(LPCTSTR)pszTmp, &dwSize);
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync if (l == ERROR_SUCCESS)
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync {
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync if (dwType == REG_SZ)
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync rc = RTStrDupEx(ppszVer, pszTmp);
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync else
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync rc = VERR_INVALID_PARAMETER;
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync }
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync else
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync {
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync rc = RTErrConvertFromWin32(l);
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync }
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync RTMemFree(pszTmp);
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync }
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync else
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync rc = VERR_NO_MEMORY;
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync }
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync /* Revision. */
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync if (ppszRev)
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync {
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync dwSize = 32; /* Reset */
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync pszTmp = (char*)RTMemAlloc(dwSize);
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync if (pszTmp)
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync {
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync l = RegQueryValueEx(hKey, "Revision", NULL, &dwType, (BYTE*)(LPCTSTR)pszTmp, &dwSize);
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync if (l == ERROR_SUCCESS)
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync {
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync if (dwType == REG_SZ)
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync rc = RTStrDupEx(ppszRev, pszTmp);
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync else
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync rc = VERR_INVALID_PARAMETER;
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync }
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync else
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync {
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync rc = RTErrConvertFromWin32(l);
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync }
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync RTMemFree(pszTmp);
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync }
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync else
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync rc = VERR_NO_MEMORY;
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync if (RT_FAILURE(rc) && ppszVer)
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync {
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync RTStrFree(*ppszVer);
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync *ppszVer = NULL;
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync }
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync }
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync rc = vbglR3CloseAdditionsWinStoragePath(hKey);
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync }
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync else
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync {
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync /*
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync * No registry entries found, return the version string compiled
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync * into this binary.
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync */
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync rc = vbglR3GetAdditionsCompileTimeVersion(ppszVer, 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 */
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync return vbglR3GetAdditionsCompileTimeVersion(ppszVer, 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;
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync rc = vbglR3GetAdditionsWinStoragePath(&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