e6660f4933111b0649ffa77483102881f4e75c3bvboxsync * VBoxGuestR3Lib - Ring-3 Support Library for VirtualBox guest additions, Additions Info.
85668909c68b5d0e67c89d6042535b41c4bffeccvboxsync * Copyright (C) 2007-2011 Oracle Corporation
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 * 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 * 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* Header Files *
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync*******************************************************************************/
093c337304805480b08e8d03146675b52a24997fvboxsync * Fallback for VbglR3GetAdditionsVersion.
8df35be0631db6b3ca2d388aa7f3e17f1782d093vboxsyncstatic int vbglR3GetAdditionsCompileTimeVersion(char **ppszVer, char **ppszVerEx, char **ppszRev)
093c337304805480b08e8d03146675b52a24997fvboxsync RTStrPrintf(szRev, sizeof(szRev), "%d", VBOX_SVN_REV);
093c337304805480b08e8d03146675b52a24997fvboxsync /* bail out: */
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync * Looks up the storage path handle (registry).
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync * @returns IPRT status value
daeb051c6c4d8fcda0a95a11b5a5406f722c2a70vboxsync * @param hKey Receives storage path handle on success.
daeb051c6c4d8fcda0a95a11b5a5406f722c2a70vboxsync * The returned handle must be closed by vbglR3CloseAdditionsWinStoragePath().
093c337304805480b08e8d03146675b52a24997fvboxsyncstatic int vbglR3QueryAdditionsWinStoragePath(PHKEY phKey)
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync * Try get the *installed* version first.
ce0bfa085d0cb5e498b310e0931ff036204a9bc3vboxsync /* Check the built in vendor path first. */
ce0bfa085d0cb5e498b310e0931ff036204a9bc3vboxsync RTStrPrintf(szPath, sizeof(szPath), "SOFTWARE\\%s\\VirtualBox Guest Additions", VBOX_VENDOR_SHORT);
ce0bfa085d0cb5e498b310e0931ff036204a9bc3vboxsync r = RegOpenKeyEx(HKEY_LOCAL_MACHINE, szPath, 0, KEY_READ, phKey);
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);
ce0bfa085d0cb5e498b310e0931ff036204a9bc3vboxsync /* Check the "Sun" path first. */
ce0bfa085d0cb5e498b310e0931ff036204a9bc3vboxsync r = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Sun\\VirtualBox Guest Additions", 0, KEY_READ, phKey);
ce0bfa085d0cb5e498b310e0931ff036204a9bc3vboxsync /* Check Wow6432Node (for new entries). */
ce0bfa085d0cb5e498b310e0931ff036204a9bc3vboxsync r = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Wow6432Node\\Sun\\VirtualBox Guest Additions", 0, KEY_READ, phKey);
ce0bfa085d0cb5e498b310e0931ff036204a9bc3vboxsync /* Still no luck? Then try the old "Sun xVM" paths ... */
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync r = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Sun\\xVM VirtualBox Guest Additions", 0, KEY_READ, phKey);
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync /* Check Wow6432Node (for new entries). */
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync r = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Wow6432Node\\Sun\\xVM VirtualBox Guest Additions", 0, KEY_READ, phKey);
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync * Closes the storage path handle (registry).
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync * @returns IPRT status value
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync * @param hKey Handle to close, retrieved by
093c337304805480b08e8d03146675b52a24997fvboxsync * vbglR3QueryAdditionsWinStoragePath().
e6660f4933111b0649ffa77483102881f4e75c3bvboxsyncstatic int vbglR3CloseAdditionsWinStoragePath(HKEY hKey)
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync#endif /* RT_OS_WINDOWS */
1cca6326f8d4b7e11408cd2037ffd69820a70858vboxsync * Reports the Guest Additions status of a certain facility to the host.
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?).
31a693ce9a8a9ebbecdcea9f24ce7f912aef4cd1vboxsyncVBGLR3DECL(int) VbglR3ReportAdditionsStatus(VBoxGuestFacilityType enmFacility,
1cca6326f8d4b7e11408cd2037ffd69820a70858vboxsync int rc = vmmdevInitRequest((VMMDevRequestHeader*)&Report, VMMDevReq_ReportGuestStatus);
daeb051c6c4d8fcda0a95a11b5a5406f722c2a70vboxsync * Queries a string value from a specified registry key.
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.
125438a68de6babc63185d666b1b6c3beb48307evboxsyncstatic int vbglR3QueryRegistryString(HKEY hKey, const char *pszValName, char *pszBuffer, size_t cchBuffer)
125438a68de6babc63185d666b1b6c3beb48307evboxsync LONG lRet = RegQueryValueEx(hKey, pszValName, NULL, &dwType, (BYTE *)pszBuffer, &dwSize);
125438a68de6babc63185d666b1b6c3beb48307evboxsync rc = dwType == REG_SZ ? VINF_SUCCESS : VERR_INVALID_PARAMETER;
d08276b7d04bedada205a398be0ec08825498850vboxsync#endif /* RT_OS_WINDOWS */
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync * Retrieves the installed Guest Additions version and/or revision.
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().
ae913ac9ffc89ee2a83992937b57f30e983185aavboxsyncVBGLR3DECL(int) VbglR3GetAdditionsVersion(char **ppszVer, char **ppszVerExt, char **ppszRev)
093c337304805480b08e8d03146675b52a24997fvboxsync * Zap the return value up front.
093c337304805480b08e8d03146675b52a24997fvboxsync int rc = vbglR3QueryAdditionsWinStoragePath(&hKey);
ae913ac9ffc89ee2a83992937b57f30e983185aavboxsync rc = vbglR3QueryRegistryString(hKey, "Version", szTemp, sizeof(szTemp));
ae913ac9ffc89ee2a83992937b57f30e983185aavboxsync rc = vbglR3QueryRegistryString(hKey, "VersionExt", szTemp, sizeof(szTemp));
093c337304805480b08e8d03146675b52a24997fvboxsync * Revision.
ae913ac9ffc89ee2a83992937b57f30e983185aavboxsync rc = vbglR3QueryRegistryString(hKey, "Revision", szTemp, sizeof(szTemp));
ae913ac9ffc89ee2a83992937b57f30e983185aavboxsync int rc2 = vbglR3CloseAdditionsWinStoragePath(hKey);
125438a68de6babc63185d666b1b6c3beb48307evboxsync /* Clean up allocated strings on error. */
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync * No registry entries found, return the version string compiled
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync * into this binary.
ae913ac9ffc89ee2a83992937b57f30e983185aavboxsync rc = vbglR3GetAdditionsCompileTimeVersion(ppszVer, ppszVerExt, ppszRev);
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync#else /* !RT_OS_WINDOWS */
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync * On non-Windows platforms just return the compile-time version string.
ae913ac9ffc89ee2a83992937b57f30e983185aavboxsync return vbglR3GetAdditionsCompileTimeVersion(ppszVer, ppszVerExt, ppszRev);
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync#endif /* !RT_OS_WINDOWS */
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync * Retrieves the installation path of Guest Additions.
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().
e6660f4933111b0649ffa77483102881f4e75c3bvboxsyncVBGLR3DECL(int) VbglR3GetAdditionsInstallationPath(char **ppszPath)
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync /* Installation directory. */
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync LONG l = RegQueryValueEx(hKey, "InstallDir", NULL, &dwType, (BYTE*)(LPCTSTR)pszTmp, &dwSize);
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync if ((l != ERROR_SUCCESS) && (l != ERROR_FILE_NOT_FOUND))
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync /* Flip slashes. */
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync for (char *pszTmp2 = ppszPath[0]; *pszTmp2; ++pszTmp2)
e6660f4933111b0649ffa77483102881f4e75c3bvboxsync /** @todo implement me */