VirtualBox

source: vbox/trunk/src/VBox/Additions/common/VBoxGuest/lib/VBoxGuestR3LibHostVersion.cpp

Last change on this file was 98103, checked in by vboxsync, 16 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.2 KB
Line 
1/* $Id: */
2/** @file
3 * VBoxGuestR3Lib - Ring-3 Support Library for VirtualBox guest additions, host version check.
4 */
5
6/*
7 * Copyright (C) 2009-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * The contents of this file may alternatively be used under the terms
26 * of the Common Development and Distribution License Version 1.0
27 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
28 * in the VirtualBox distribution, in which case the provisions of the
29 * CDDL are applicable instead of those of the GPL.
30 *
31 * You may elect to license modified versions of this file under the
32 * terms and conditions of either the GPL or the CDDL or both.
33 *
34 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
35 */
36
37
38/*********************************************************************************************************************************
39* Header Files *
40*********************************************************************************************************************************/
41#include <iprt/string.h>
42#include <VBox/log.h>
43
44#ifdef RT_OS_WINDOWS
45 #define WIN32_LEAN_AND_MEAN
46 #include <iprt/win/windows.h>
47#endif
48
49#include "VBoxGuestR3LibInternal.h"
50
51
52/**
53 * Checks for a Guest Additions update by comparing the installed version on the
54 * guest and the reported host version.
55 *
56 * @returns VBox status code
57 *
58 * @param idClient The client id returned by
59 * VbglR3InfoSvcConnect().
60 * @param pfUpdate Receives pointer to boolean flag indicating
61 * whether an update was found or not.
62 * @param ppszHostVersion Receives pointer of allocated version string.
63 * The returned pointer must be freed using
64 * VbglR3GuestPropReadValueFree(). Always set to
65 * NULL.
66 * @param ppszGuestVersion Receives pointer of allocated revision string.
67 * The returned pointer must be freed using
68 * VbglR3GuestPropReadValueFree(). Always set to
69 * NULL.
70 */
71VBGLR3DECL(int) VbglR3HostVersionCheckForUpdate(HGCMCLIENTID idClient, bool *pfUpdate, char **ppszHostVersion, char **ppszGuestVersion)
72{
73#ifdef VBOX_WITH_GUEST_PROPS
74 Assert(idClient > 0);
75 AssertPtr(pfUpdate);
76 AssertPtr(ppszHostVersion);
77 AssertPtr(ppszGuestVersion);
78
79 *ppszHostVersion = NULL;
80 *ppszGuestVersion = NULL;
81
82 /* We assume we have an update initially.
83 Every block down below is allowed to veto */
84 *pfUpdate = true;
85
86 /* Do we need to do all this stuff? */
87 char *pszCheckHostVersion;
88 int rc = VbglR3GuestPropReadValueAlloc(idClient, "/VirtualBox/GuestAdd/CheckHostVersion", &pszCheckHostVersion);
89 if (RT_FAILURE(rc))
90 {
91 if (rc == VERR_NOT_FOUND)
92 rc = VINF_SUCCESS; /* If we don't find the value above we do the check by default */
93 else
94 LogFlow(("Could not read check host version flag! rc = %Rrc\n", rc));
95 }
96 else
97 {
98 /* Only don't do the check if we have a valid "0" in it */
99 if (!strcmp(pszCheckHostVersion, "0"))
100 {
101 LogRel(("No host version update check performed (disabled).\n"));
102 *pfUpdate = false;
103 }
104 VbglR3GuestPropReadValueFree(pszCheckHostVersion);
105 }
106
107 /* Collect all needed information */
108 /* Make sure we only notify the user once by comparing the host version with
109 * the last checked host version (if any) */
110 if (RT_SUCCESS(rc) && *pfUpdate)
111 {
112 /* Look up host version */
113 rc = VbglR3GuestPropReadValueAlloc(idClient, "/VirtualBox/HostInfo/VBoxVer", ppszHostVersion);
114 if (RT_FAILURE(rc))
115 {
116 LogFlow(("Could not read VBox host version! rc = %Rrc\n", rc));
117 }
118 else
119 {
120 LogFlow(("Host version: %s\n", *ppszHostVersion));
121
122 /* Get last checked host version */
123 char *pszLastCheckedHostVersion;
124 rc = VbglR3HostVersionLastCheckedLoad(idClient, &pszLastCheckedHostVersion);
125 if (RT_SUCCESS(rc))
126 {
127 LogFlow(("Last checked host version: %s\n", pszLastCheckedHostVersion));
128 if (strcmp(*ppszHostVersion, pszLastCheckedHostVersion) == 0)
129 *pfUpdate = false; /* We already notified this version, skip */
130 VbglR3GuestPropReadValueFree(pszLastCheckedHostVersion);
131 }
132 else if (rc == VERR_NOT_FOUND) /* Never wrote a last checked host version before */
133 {
134 LogFlow(("Never checked a host version before.\n"));
135 rc = VINF_SUCCESS;
136 }
137 }
138
139 /* Look up guest version */
140 if (RT_SUCCESS(rc))
141 {
142 rc = VbglR3GetAdditionsVersion(ppszGuestVersion, NULL /* Extended version not needed here */,
143 NULL /* Revision not needed here */);
144 if (RT_FAILURE(rc))
145 LogFlow(("Could not read VBox guest version! rc = %Rrc\n", rc));
146 }
147 }
148
149 /* Do the actual version comparison (if needed, see block(s) above) */
150 if (RT_SUCCESS(rc) && *pfUpdate)
151 {
152 if (RTStrVersionCompare(*ppszHostVersion, *ppszGuestVersion) > 0) /* Is host version greater than guest add version? */
153 {
154 /* Yay, we have an update! */
155 LogRel(("Guest Additions update found! Please upgrade this machine to the latest Guest Additions.\n"));
156 }
157 else
158 {
159 /* How sad ... */
160 *pfUpdate = false;
161 }
162 }
163
164 /* Cleanup on failure */
165 if (RT_FAILURE(rc))
166 {
167 if (*ppszHostVersion)
168 {
169 VbglR3GuestPropReadValueFree(*ppszHostVersion);
170 *ppszHostVersion = NULL;
171 }
172 if (*ppszGuestVersion)
173 {
174 VbglR3GuestPropReadValueFree(*ppszGuestVersion);
175 *ppszGuestVersion = NULL;
176 }
177 }
178 return rc;
179#else /* !VBOX_WITH_GUEST_PROPS */
180 RT_NOREF(idClient, pfUpdate, ppszHostVersion, ppszGuestVersion);
181 return VERR_NOT_SUPPORTED;
182#endif
183}
184
185
186/** Retrieves the last checked host version.
187 *
188 * @returns VBox status code.
189 *
190 * @param idClient The client id returned by VbglR3InfoSvcConnect().
191 * @param ppszVer Receives pointer of allocated version string.
192 * The returned pointer must be freed using RTStrFree() on VINF_SUCCESS.
193 */
194VBGLR3DECL(int) VbglR3HostVersionLastCheckedLoad(HGCMCLIENTID idClient, char **ppszVer)
195{
196#ifdef VBOX_WITH_GUEST_PROPS
197 Assert(idClient > 0);
198 AssertPtr(ppszVer);
199 return VbglR3GuestPropReadValueAlloc(idClient, "/VirtualBox/GuestAdd/HostVerLastChecked", ppszVer);
200#else /* !VBOX_WITH_GUEST_PROPS */
201 RT_NOREF(idClient, ppszVer);
202 return VERR_NOT_SUPPORTED;
203#endif
204}
205
206
207/** Stores the last checked host version for later lookup.
208 * Requires strings in form of "majorVer.minorVer.build".
209 *
210 * @returns VBox status code.
211 *
212 * @param idClient The client id returned by VbglR3InfoSvcConnect().
213 * @param pszVer Pointer to version string to store.
214 */
215VBGLR3DECL(int) VbglR3HostVersionLastCheckedStore(HGCMCLIENTID idClient, const char *pszVer)
216{
217#ifdef VBOX_WITH_GUEST_PROPS
218 Assert(idClient > 0);
219 AssertPtr(pszVer);
220 return VbglR3GuestPropWriteValue(idClient, "/VirtualBox/GuestAdd/HostVerLastChecked", pszVer);
221#else /* !VBOX_WITH_GUEST_PROPS */
222 RT_NOREF(idClient, pszVer);
223 return VERR_NOT_SUPPORTED;
224#endif
225}
226
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use