3
* VBoxGuestR3Lib - Ring-3 Support Library for VirtualBox guest additions, host version check.
7
* Copyright (C) 2009 Sun Microsystems, Inc.
9
* This file is part of VirtualBox Open Source Edition (OSE), as
10
* available from http://www.virtualbox.org. This file is free software;
11
* you can redistribute it and/or modify it under the terms of the GNU
12
* General Public License (GPL) as published by the Free Software
13
* Foundation, in version 2 as it comes in the "COPYING" file of the
14
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
17
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
18
* Clara, CA 95054 USA or visit http://www.sun.com if you need
19
* additional information or have any questions.
23
/*******************************************************************************
25
*******************************************************************************/
26
#include <stdio.h> /* Required for sscanf */
27
#include <iprt/string.h>
31
#define WIN32_LEAN_AND_MEAN
35
#include "VBGLR3Internal.h"
38
* Checks for a Guest Additions update by comparing the installed version on the
39
* guest and the reported host version.
41
* @returns VBox status code
43
* @param u32ClientId The client id returned by
44
* VbglR3InfoSvcConnect().
45
* @param pfUpdate Receives pointer to boolean flag indicating
46
* whether an update was found or not.
47
* @param ppszHostVersion Receives pointer of allocated version string.
48
* The returned pointer must be freed using
49
* VbglR3GuestPropReadValueFree(). Always set to
51
* @param ppszGuestVersion Receives pointer of allocated revision string.
52
* The returned pointer must be freed using
53
* VbglR3GuestPropReadValueFree(). Always set to
56
VBGLR3DECL(int) VbglR3HostVersionCheckForUpdate(uint32_t u32ClientId, bool *pfUpdate, char **ppszHostVersion, char **ppszGuestVersion)
58
Assert(u32ClientId > 0);
60
AssertPtr(ppszHostVersion);
61
AssertPtr(ppszGuestVersion);
63
*ppszHostVersion = NULL;
64
*ppszGuestVersion = NULL;
66
/* We assume we have an update initially.
67
Every block down below is allowed to veto */
70
/* Do we need to do all this stuff? */
71
char *pszCheckHostVersion;
72
int rc = VbglR3GuestPropReadValueAlloc(u32ClientId, "/VirtualBox/GuestAdd/CheckHostVersion", &pszCheckHostVersion);
75
if (rc == VERR_NOT_FOUND)
76
rc = VINF_SUCCESS; /* If we don't find the value above we do the check by default */
78
LogFlow(("Could not read check host version flag! rc = %Rrc\n", rc));
82
/* Only don't do the check if we have a valid "0" in it */
83
if (!strcmp(pszCheckHostVersion, "0"))
85
LogRel(("No host version update check performed (disabled).\n"));
88
VbglR3GuestPropReadValueFree(pszCheckHostVersion);
91
/* Collect all needed information */
92
/* Make sure we only notify the user once by comparing the host version with
93
* the last checked host version (if any) */
94
if (RT_SUCCESS(rc) && *pfUpdate)
96
/* Look up host version */
97
rc = VbglR3GuestPropReadValueAlloc(u32ClientId, "/VirtualBox/HostInfo/VBoxVer", ppszHostVersion);
100
LogFlow(("Could not read VBox host version! rc = %Rrc\n", rc));
104
LogFlow(("Host version: %s\n", *ppszHostVersion));
106
/* Get last checked host version */
107
char *pszLastCheckedHostVersion;
108
rc = VbglR3HostVersionLastCheckedLoad(u32ClientId, &pszLastCheckedHostVersion);
111
LogFlow(("Last checked host version: %s\n", pszLastCheckedHostVersion));
112
if (strcmp(*ppszHostVersion, pszLastCheckedHostVersion) == 0)
113
*pfUpdate = false; /* We already notified this version, skip */
114
VbglR3GuestPropReadValueFree(pszLastCheckedHostVersion);
116
else if (rc == VERR_NOT_FOUND) /* Never wrote a last checked host version before */
118
LogFlow(("Never checked a host version before.\n"));
123
/* Look up guest version */
126
rc = VbglR3GetAdditionsVersion(ppszGuestVersion, NULL /* Revision not needed here */);
128
LogFlow(("Could not read VBox guest version! rc = %Rrc\n", rc));
132
/* Do the actual version comparison (if needed, see block(s) above) */
133
if (RT_SUCCESS(rc) && *pfUpdate)
135
if (RTStrVersionCompare(*ppszHostVersion, *ppszGuestVersion) > 0) /* Is host version greater than guest add version? */
137
/* Yay, we have an update! */
138
LogRel(("Guest Additions update found! Please upgrade this machine to the latest Guest Additions.\n"));
147
/* Cleanup on failure */
150
if (*ppszHostVersion)
152
VbglR3GuestPropReadValueFree(*ppszHostVersion);
153
*ppszHostVersion = NULL;
155
if (*ppszGuestVersion)
157
VbglR3GuestPropReadValueFree(*ppszGuestVersion);
158
*ppszGuestVersion = NULL;
165
/** Retrieves the last checked host version.
167
* @returns VBox status code.
169
* @param u32ClientId The client id returned by VbglR3InfoSvcConnect().
170
* @param ppszVer Receives pointer of allocated version string.
171
* The returned pointer must be freed using RTStrFree() on VINF_SUCCESS.
173
VBGLR3DECL(int) VbglR3HostVersionLastCheckedLoad(uint32_t u32ClientId, char **ppszVer)
175
Assert(u32ClientId > 0);
177
return VbglR3GuestPropReadValueAlloc(u32ClientId, "/VirtualBox/GuestAdd/HostVerLastChecked", ppszVer);
181
/** Stores the last checked host version for later lookup.
182
* Requires strings in form of "majorVer.minorVer.build".
184
* @returns VBox status code.
186
* @param u32ClientId The client id returned by VbglR3InfoSvcConnect().
187
* @param pszVer Pointer to version string to store.
189
VBGLR3DECL(int) VbglR3HostVersionLastCheckedStore(uint32_t u32ClientId, const char *pszVer)
191
Assert(u32ClientId > 0);
193
return VbglR3GuestPropWriteValue(u32ClientId, "/VirtualBox/GuestAdd/HostVerLastChecked", pszVer);