~ubuntu-branches/ubuntu/raring/virtualbox-ose/raring

« back to all changes in this revision

Viewing changes to src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR3LibHostVersion.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Felix Geyer
  • Date: 2009-12-18 16:44:29 UTC
  • mfrom: (0.3.3 upstream) (0.4.6 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091218164429-jd34ccexpv5na11a
Tags: 3.1.2-dfsg-1ubuntu1
* Merge from Debian unstable (LP: #498219), remaining changes:
  - Disable update action
    - debian/patches/u01-disable-update-action.dpatch
  - VirtualBox should go in Accessories, not in System tools (LP: #288590)
    - debian/virtualbox-ose-qt.files/virtualbox-ose.desktop
  - Add Apport hook
    - debian/virtualbox-ose.files/source_virtualbox-ose.py
    - debian/virtualbox-ose.install
  - Add Launchpad integration
    - debian/control
    - debian/lpi-bug.xpm
    - debian/patches/u02-lp-integration.dpatch
* Fixes the following bugs:
  - Kernel module fails to build with Linux >= 2.6.32 (LP: #474625)
  - X.Org drivers need to be rebuilt against X-Server 1.7 (LP: #495935)
  - The *-source packages try to build the kernel modules even though the
    kernel headers aren't available (LP: #473334)
* Replace *-source packages with transitional packages for *-dkms.
* Adapt u01-disable-update-action.dpatch and u02-lp-integration.dpatch for
  new upstream version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Id: */
 
2
/** @file
 
3
 * VBoxGuestR3Lib - Ring-3 Support Library for VirtualBox guest additions, host version check.
 
4
 */
 
5
 
 
6
/*
 
7
 * Copyright (C) 2009 Sun Microsystems, Inc.
 
8
 *
 
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.
 
16
 *
 
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.
 
20
 */
 
21
 
 
22
 
 
23
/*******************************************************************************
 
24
*   Header Files                                                               *
 
25
*******************************************************************************/
 
26
#include <stdio.h>          /* Required for sscanf */
 
27
#include <iprt/string.h>
 
28
#include <VBox/log.h>
 
29
 
 
30
#ifdef RT_OS_WINDOWS
 
31
 #define WIN32_LEAN_AND_MEAN
 
32
 #include <windows.h>
 
33
#endif
 
34
 
 
35
#include "VBGLR3Internal.h"
 
36
 
 
37
/**
 
38
 * Checks for a Guest Additions update by comparing the installed version on the
 
39
 * guest and the reported host version.
 
40
 *
 
41
 * @returns VBox status code
 
42
 *
 
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
 
50
 *                              NULL.
 
51
 * @param   ppszGuestVersion    Receives pointer of allocated revision string.
 
52
 *                              The returned pointer must be freed using
 
53
 *                              VbglR3GuestPropReadValueFree().  Always set to
 
54
 *                              NULL.
 
55
 */
 
56
VBGLR3DECL(int) VbglR3HostVersionCheckForUpdate(uint32_t u32ClientId, bool *pfUpdate, char **ppszHostVersion, char **ppszGuestVersion)
 
57
{
 
58
    Assert(u32ClientId > 0);
 
59
    AssertPtr(pfUpdate);
 
60
    AssertPtr(ppszHostVersion);
 
61
    AssertPtr(ppszGuestVersion);
 
62
 
 
63
    *ppszHostVersion = NULL;
 
64
    *ppszGuestVersion = NULL;
 
65
 
 
66
    /* We assume we have an update initially.
 
67
       Every block down below is allowed to veto */
 
68
    *pfUpdate = true;
 
69
 
 
70
    /* Do we need to do all this stuff? */
 
71
    char *pszCheckHostVersion;
 
72
    int rc = VbglR3GuestPropReadValueAlloc(u32ClientId, "/VirtualBox/GuestAdd/CheckHostVersion", &pszCheckHostVersion);
 
73
    if (RT_FAILURE(rc))
 
74
    {
 
75
        if (rc == VERR_NOT_FOUND)
 
76
            rc = VINF_SUCCESS; /* If we don't find the value above we do the check by default */
 
77
        else
 
78
            LogFlow(("Could not read check host version flag! rc = %Rrc\n", rc));
 
79
    }
 
80
    else
 
81
    {
 
82
        /* Only don't do the check if we have a valid "0" in it */
 
83
        if (!strcmp(pszCheckHostVersion, "0"))
 
84
        {
 
85
            LogRel(("No host version update check performed (disabled).\n"));
 
86
            *pfUpdate = false;
 
87
        }
 
88
        VbglR3GuestPropReadValueFree(pszCheckHostVersion);
 
89
    }
 
90
 
 
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)
 
95
    {
 
96
        /* Look up host version */
 
97
        rc = VbglR3GuestPropReadValueAlloc(u32ClientId, "/VirtualBox/HostInfo/VBoxVer", ppszHostVersion);
 
98
        if (RT_FAILURE(rc))
 
99
        {
 
100
            LogFlow(("Could not read VBox host version! rc = %Rrc\n", rc));
 
101
        }
 
102
        else
 
103
        {
 
104
            LogFlow(("Host version: %s\n", *ppszHostVersion));
 
105
 
 
106
            /* Get last checked host version */
 
107
            char *pszLastCheckedHostVersion;
 
108
            rc = VbglR3HostVersionLastCheckedLoad(u32ClientId, &pszLastCheckedHostVersion);
 
109
            if (RT_SUCCESS(rc))
 
110
            {
 
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);
 
115
            }
 
116
            else if (rc == VERR_NOT_FOUND) /* Never wrote a last checked host version before */
 
117
            {
 
118
                LogFlow(("Never checked a host version before.\n"));
 
119
                rc = VINF_SUCCESS;
 
120
            }
 
121
        }
 
122
 
 
123
        /* Look up guest version */
 
124
        if (RT_SUCCESS(rc))
 
125
        {
 
126
            rc = VbglR3GetAdditionsVersion(ppszGuestVersion, NULL /* Revision not needed here */);
 
127
            if (RT_FAILURE(rc))
 
128
                LogFlow(("Could not read VBox guest version! rc = %Rrc\n", rc));
 
129
        }
 
130
    }
 
131
 
 
132
    /* Do the actual version comparison (if needed, see block(s) above) */
 
133
    if (RT_SUCCESS(rc) && *pfUpdate)
 
134
    {
 
135
        if (RTStrVersionCompare(*ppszHostVersion, *ppszGuestVersion) > 0) /* Is host version greater than guest add version? */
 
136
        {
 
137
            /* Yay, we have an update! */
 
138
            LogRel(("Guest Additions update found! Please upgrade this machine to the latest Guest Additions.\n"));
 
139
        }
 
140
        else
 
141
        {
 
142
            /* How sad ... */
 
143
            *pfUpdate = false;
 
144
        }
 
145
    }
 
146
 
 
147
    /* Cleanup on failure */
 
148
    if (RT_FAILURE(rc))
 
149
    {
 
150
        if (*ppszHostVersion)
 
151
        {
 
152
            VbglR3GuestPropReadValueFree(*ppszHostVersion);
 
153
            *ppszHostVersion = NULL;
 
154
        }
 
155
        if (*ppszGuestVersion)
 
156
        {
 
157
            VbglR3GuestPropReadValueFree(*ppszGuestVersion);
 
158
            *ppszGuestVersion = NULL;
 
159
        }
 
160
    }
 
161
    return rc;
 
162
}
 
163
 
 
164
 
 
165
/** Retrieves the last checked host version.
 
166
 *
 
167
 * @returns VBox status code.
 
168
 *
 
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.
 
172
 */
 
173
VBGLR3DECL(int) VbglR3HostVersionLastCheckedLoad(uint32_t u32ClientId, char **ppszVer)
 
174
{
 
175
    Assert(u32ClientId > 0);
 
176
    Assert(ppszVer);
 
177
    return VbglR3GuestPropReadValueAlloc(u32ClientId, "/VirtualBox/GuestAdd/HostVerLastChecked", ppszVer);
 
178
}
 
179
 
 
180
 
 
181
/** Stores the last checked host version for later lookup.
 
182
 *  Requires strings in form of "majorVer.minorVer.build".
 
183
 *
 
184
 * @returns VBox status code.
 
185
 *
 
186
 * @param   u32ClientId     The client id returned by VbglR3InfoSvcConnect().
 
187
 * @param   pszVer          Pointer to version string to store.
 
188
 */
 
189
VBGLR3DECL(int) VbglR3HostVersionLastCheckedStore(uint32_t u32ClientId, const char *pszVer)
 
190
{
 
191
    Assert(u32ClientId > 0);
 
192
    Assert(pszVer);
 
193
    return VbglR3GuestPropWriteValue(u32ClientId, "/VirtualBox/GuestAdd/HostVerLastChecked", pszVer);
 
194
}