VBoxGuestR3LibHostVersion.cpp revision 783d3ba78564efa201988c6a3e6f10ba3bef29e2
5bb7b06e9e2186e1f51700e01cfd58f2b5f70937vboxsync * VBoxGuestR3Lib - Ring-3 Support Library for VirtualBox guest additions, host version check.
5bb7b06e9e2186e1f51700e01cfd58f2b5f70937vboxsync * Copyright (C) 2009 Sun Microsystems, Inc.
5bb7b06e9e2186e1f51700e01cfd58f2b5f70937vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
5bb7b06e9e2186e1f51700e01cfd58f2b5f70937vboxsync * available from http://www.virtualbox.org. This file is free software;
5bb7b06e9e2186e1f51700e01cfd58f2b5f70937vboxsync * you can redistribute it and/or modify it under the terms of the GNU
5bb7b06e9e2186e1f51700e01cfd58f2b5f70937vboxsync * General Public License (GPL) as published by the Free Software
5bb7b06e9e2186e1f51700e01cfd58f2b5f70937vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
5bb7b06e9e2186e1f51700e01cfd58f2b5f70937vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
5bb7b06e9e2186e1f51700e01cfd58f2b5f70937vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
5bb7b06e9e2186e1f51700e01cfd58f2b5f70937vboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
5bb7b06e9e2186e1f51700e01cfd58f2b5f70937vboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
5bb7b06e9e2186e1f51700e01cfd58f2b5f70937vboxsync * additional information or have any questions.
5bb7b06e9e2186e1f51700e01cfd58f2b5f70937vboxsync/*******************************************************************************
5bb7b06e9e2186e1f51700e01cfd58f2b5f70937vboxsync* Header Files *
5bb7b06e9e2186e1f51700e01cfd58f2b5f70937vboxsync*******************************************************************************/
6c25b9cd17e54772e285ccac4feea9aa92608918vboxsync * Compares two VirtualBox version strings and returns the result.
6c25b9cd17e54772e285ccac4feea9aa92608918vboxsync * Requires strings in form of "majorVer.minorVer.build".
5bb7b06e9e2186e1f51700e01cfd58f2b5f70937vboxsync * @returns 0 if equal, 1 if Ver1 is greater, 2 if Ver2 is greater.
5bb7b06e9e2186e1f51700e01cfd58f2b5f70937vboxsync * @param pszVer1 First version string to compare.
5bb7b06e9e2186e1f51700e01cfd58f2b5f70937vboxsync * @param pszVer2 First version string to compare.
6c25b9cd17e54772e285ccac4feea9aa92608918vboxsync * @todo Move this to IPRT and add support for more dots, suffixes and whatnot.
5bb7b06e9e2186e1f51700e01cfd58f2b5f70937vboxsyncVBGLR3DECL(int) VbglR3HostVersionCompare(const char *pszVer1, const char *pszVer2)
783d3ba78564efa201988c6a3e6f10ba3bef29e2vboxsync /** @todo r=bird: not checking the return code, may be using uninitialized
783d3ba78564efa201988c6a3e6f10ba3bef29e2vboxsync * variables... I'll fix this when moving into the runtime. */
5bb7b06e9e2186e1f51700e01cfd58f2b5f70937vboxsync sscanf(pszVer1, "%d.%d.%d", &iVer1Major, &iVer1Minor, &iVer1Build);
5bb7b06e9e2186e1f51700e01cfd58f2b5f70937vboxsync sscanf(pszVer2, "%d.%d.%d", &iVer2Major, &iVer2Minor, &iVer2Build);
5bb7b06e9e2186e1f51700e01cfd58f2b5f70937vboxsync int iVer1Final = (iVer1Major * 10000) + (iVer1Minor * 100) + iVer1Build;
5bb7b06e9e2186e1f51700e01cfd58f2b5f70937vboxsync int iVer2Final = (iVer2Major * 10000) + (iVer2Minor * 100) + iVer2Build;
6c25b9cd17e54772e285ccac4feea9aa92608918vboxsync * Checks for a Guest Additions update by comparing the installed version on the
6c25b9cd17e54772e285ccac4feea9aa92608918vboxsync * guest and the reported host version.
892354a49bac7f96155923cf8d2aa68a91c4dbd5vboxsync * @returns VBox status code
6c25b9cd17e54772e285ccac4feea9aa92608918vboxsync * @param u32ClientId The client id returned by
6c25b9cd17e54772e285ccac4feea9aa92608918vboxsync * VbglR3InfoSvcConnect().
6c25b9cd17e54772e285ccac4feea9aa92608918vboxsync * @param pfUpdate Receives pointer to boolean flag indicating
6c25b9cd17e54772e285ccac4feea9aa92608918vboxsync * whether an update was found or not.
6c25b9cd17e54772e285ccac4feea9aa92608918vboxsync * @param ppszHostVersion Receives pointer of allocated version string.
6c25b9cd17e54772e285ccac4feea9aa92608918vboxsync * The returned pointer must be freed using
a66445f2d6971e23a9bccef243bc6000b41c05eevboxsync * VbglR3GuestPropReadValueFree(). Always set to
6c25b9cd17e54772e285ccac4feea9aa92608918vboxsync * @param ppszGuestVersion Receives pointer of allocated revision string.
6c25b9cd17e54772e285ccac4feea9aa92608918vboxsync * The returned pointer must be freed using
a66445f2d6971e23a9bccef243bc6000b41c05eevboxsync * VbglR3GuestPropReadValueFree(). Always set to
6c25b9cd17e54772e285ccac4feea9aa92608918vboxsyncVBGLR3DECL(int) VbglR3HostVersionCheckForUpdate(uint32_t u32ClientId, bool *pfUpdate, char **ppszHostVersion, char **ppszGuestVersion)
d3cb1728da9e60397e81daace4e82d69fb5ff784vboxsync /* We assume we have an update initially.
892354a49bac7f96155923cf8d2aa68a91c4dbd5vboxsync Every block down below is allowed to veto */
5bb7b06e9e2186e1f51700e01cfd58f2b5f70937vboxsync /* Do we need to do all this stuff? */
6c25b9cd17e54772e285ccac4feea9aa92608918vboxsync int rc = VbglR3GuestPropReadValueAlloc(u32ClientId, "/VirtualBox/GuestAdd/CheckHostVersion", &pszCheckHostVersion);
5bb7b06e9e2186e1f51700e01cfd58f2b5f70937vboxsync rc = VINF_SUCCESS; /* If we don't find the value above we do the check by default */
6c25b9cd17e54772e285ccac4feea9aa92608918vboxsync LogFlow(("Could not read check host version flag! rc = %Rrc\n", rc));
5bb7b06e9e2186e1f51700e01cfd58f2b5f70937vboxsync /* Only don't do the check if we have a valid "0" in it */
a66445f2d6971e23a9bccef243bc6000b41c05eevboxsync LogRel(("No host version update check performed (disabled).\n"));
d3cb1728da9e60397e81daace4e82d69fb5ff784vboxsync /* Collect all needed information */
892354a49bac7f96155923cf8d2aa68a91c4dbd5vboxsync /* Make sure we only notify the user once by comparing the host version with
892354a49bac7f96155923cf8d2aa68a91c4dbd5vboxsync * the last checked host version (if any) */
892354a49bac7f96155923cf8d2aa68a91c4dbd5vboxsync /* Look up host version */
892354a49bac7f96155923cf8d2aa68a91c4dbd5vboxsync rc = VbglR3GuestPropReadValueAlloc(u32ClientId, "/VirtualBox/HostInfo/VBoxVer", ppszHostVersion);
6c25b9cd17e54772e285ccac4feea9aa92608918vboxsync LogFlow(("Could not read VBox host version! rc = %Rrc\n", rc));
892354a49bac7f96155923cf8d2aa68a91c4dbd5vboxsync /* Get last checked host version */
892354a49bac7f96155923cf8d2aa68a91c4dbd5vboxsync rc = VbglR3HostVersionLastCheckedLoad(u32ClientId, &pszLastCheckedHostVersion);
892354a49bac7f96155923cf8d2aa68a91c4dbd5vboxsync LogFlow(("Last checked host version: %s\n", pszLastCheckedHostVersion));
892354a49bac7f96155923cf8d2aa68a91c4dbd5vboxsync if (strcmp(*ppszHostVersion, pszLastCheckedHostVersion) == 0)
6c25b9cd17e54772e285ccac4feea9aa92608918vboxsync *pfUpdate = false; /* We already notified this version, skip */
892354a49bac7f96155923cf8d2aa68a91c4dbd5vboxsync VbglR3GuestPropReadValueFree(pszLastCheckedHostVersion);
892354a49bac7f96155923cf8d2aa68a91c4dbd5vboxsync else if (rc == VERR_NOT_FOUND) /* Never wrote a last checked host version before */
a66445f2d6971e23a9bccef243bc6000b41c05eevboxsync LogFlow(("Never checked a host version before.\n"));
d3cb1728da9e60397e81daace4e82d69fb5ff784vboxsync /* Look up guest version */
892354a49bac7f96155923cf8d2aa68a91c4dbd5vboxsync rc = VbglR3GetAdditionsVersion(ppszGuestVersion, NULL /* Revision not needed here */);
6c25b9cd17e54772e285ccac4feea9aa92608918vboxsync LogFlow(("Could not read VBox guest version! rc = %Rrc\n", rc));
892354a49bac7f96155923cf8d2aa68a91c4dbd5vboxsync /* Do the actual version comparison (if needed, see block(s) above) */
892354a49bac7f96155923cf8d2aa68a91c4dbd5vboxsync if (VbglR3HostVersionCompare(*ppszHostVersion, *ppszGuestVersion) == 1) /* Is host version greater than guest add version? */
892354a49bac7f96155923cf8d2aa68a91c4dbd5vboxsync /* Yay, we have an update! */
a66445f2d6971e23a9bccef243bc6000b41c05eevboxsync LogRel(("Guest Additions update found! Please upgrade this machine to the latest Guest Additions.\n"));
892354a49bac7f96155923cf8d2aa68a91c4dbd5vboxsync /* How sad ... */
892354a49bac7f96155923cf8d2aa68a91c4dbd5vboxsync /* Cleanup on failure */
892354a49bac7f96155923cf8d2aa68a91c4dbd5vboxsync/** Retrieves the last checked host version.
892354a49bac7f96155923cf8d2aa68a91c4dbd5vboxsync * @returns VBox status code.
892354a49bac7f96155923cf8d2aa68a91c4dbd5vboxsync * @param u32ClientId The client id returned by VbglR3InfoSvcConnect().
892354a49bac7f96155923cf8d2aa68a91c4dbd5vboxsync * @param ppszVer Receives pointer of allocated version string.
892354a49bac7f96155923cf8d2aa68a91c4dbd5vboxsync * The returned pointer must be freed using RTStrFree() on VINF_SUCCESS.
892354a49bac7f96155923cf8d2aa68a91c4dbd5vboxsyncVBGLR3DECL(int) VbglR3HostVersionLastCheckedLoad(uint32_t u32ClientId, char **ppszVer)
892354a49bac7f96155923cf8d2aa68a91c4dbd5vboxsync return VbglR3GuestPropReadValueAlloc(u32ClientId, "/VirtualBox/GuestAdd/HostVerLastChecked", ppszVer);
892354a49bac7f96155923cf8d2aa68a91c4dbd5vboxsync/** Stores the last checked host version for later lookup.
892354a49bac7f96155923cf8d2aa68a91c4dbd5vboxsync * Requires strings in form of "majorVer.minorVer.build".
892354a49bac7f96155923cf8d2aa68a91c4dbd5vboxsync * @returns VBox status code.
892354a49bac7f96155923cf8d2aa68a91c4dbd5vboxsync * @param u32ClientId The client id returned by VbglR3InfoSvcConnect().
892354a49bac7f96155923cf8d2aa68a91c4dbd5vboxsync * @param pszVer Pointer to version string to store.
892354a49bac7f96155923cf8d2aa68a91c4dbd5vboxsyncVBGLR3DECL(int) VbglR3HostVersionLastCheckedStore(uint32_t u32ClientId, const char *pszVer)