~ubuntu-branches/ubuntu/precise/virtualbox/precise-updates

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Felix Geyer
  • Date: 2011-07-04 13:02:31 UTC
  • mfrom: (3.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20110704130231-l843es6wqhx614n7
Tags: 4.0.10-dfsg-1ubuntu1
* Merge from Debian unstable, remaining changes:
  - Add Apport hook.
    - debian/virtualbox-ose.files/source_virtualbox-ose.py
    - debian/virtualbox-ose.install
  - Drop *-source packages.
* Add the Modaliases control field manually for maximum backportability.

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
 
37
37
 
38
38
/**
39
 
 * Fallback for vbglR3GetAdditionsVersion.
 
39
 * Fallback for VbglR3GetAdditionsVersion.
40
40
 */
41
41
static int vbglR3GetAdditionsCompileTimeVersion(char **ppszVer, char **ppszVerEx, char **ppszRev)
42
42
{
43
 
    /* Raw version string: major.minor.build. */
 
43
    int rc = VINF_SUCCESS;
44
44
    if (ppszVer)
45
 
    {
46
 
        *ppszVer = RTStrDup(VBOX_VERSION_STRING_RAW);
47
 
        if (!*ppszVer)
48
 
            return VERR_NO_STR_MEMORY;
49
 
    }
50
 
 
51
 
    /* Extended version string: major.minor.build (+ vendor [suffix(es)]). */
52
 
    if (ppszVerEx)
53
 
    {
54
 
        *ppszVerEx = RTStrDup(VBOX_VERSION_STRING);
55
 
        if (!*ppszVerEx)
56
 
            return VERR_NO_STR_MEMORY;
57
 
    }
58
 
 
59
 
    if (ppszRev)
60
 
    {
61
 
        char szRev[64];
62
 
        RTStrPrintf(szRev, sizeof(szRev), "%d", VBOX_SVN_REV);
63
 
        *ppszRev = RTStrDup(szRev);
64
 
        if (!*ppszRev)
 
45
        rc = RTStrDupEx(ppszVer, VBOX_VERSION_STRING_RAW);
 
46
    if (RT_SUCCESS(rc))
 
47
    {
 
48
        if (ppszVerEx)
 
49
            rc = RTStrDupEx(ppszVerEx, VBOX_VERSION_STRING);
 
50
        if (RT_SUCCESS(rc))
65
51
        {
66
 
            if (ppszVer)
 
52
            if (ppszRev)
67
53
            {
68
 
                RTStrFree(*ppszVer);
69
 
                *ppszVer = NULL;
 
54
#if 0
 
55
                char szRev[64];
 
56
                RTStrPrintf(szRev, sizeof(szRev), "%d", VBOX_SVN_REV);
 
57
                rc = RTStrDupEx(ppszRev, szRev);
 
58
#else
 
59
                rc = RTStrDupEx(ppszRev, RT_XSTR(VBOX_SVN_REV));
 
60
#endif
70
61
            }
71
 
            return VERR_NO_STR_MEMORY;
72
 
        }
73
 
    }
 
62
            if (RT_SUCCESS(rc))
 
63
                return VINF_SUCCESS;
74
64
 
75
 
    return VINF_SUCCESS;
 
65
            /* bail out: */
 
66
        }
 
67
        if (ppszVerEx)
 
68
        {
 
69
            RTStrFree(*ppszVerEx);
 
70
            *ppszVerEx = NULL;
 
71
        }
 
72
    }
 
73
    if (ppszVer)
 
74
    {
 
75
        RTStrFree(*ppszVer);
 
76
        *ppszVer = NULL;
 
77
    }
 
78
    return rc;
76
79
}
77
80
 
78
81
#ifdef RT_OS_WINDOWS
 
82
 
79
83
/**
80
84
 * Looks up the storage path handle (registry).
81
85
 *
82
86
 * @returns IPRT status value
83
 
 * @param   hKey        Receives pointer of allocated version string. NULL is
84
 
 *                      accepted. The returned pointer must be closed by
85
 
 *                      vbglR3CloseAdditionsWinStoragePath().
 
87
 * @param   hKey        Receives storage path handle on success.
 
88
 *                      The returned handle must be closed by vbglR3CloseAdditionsWinStoragePath().
86
89
 */
87
 
static int vbglR3GetAdditionsWinStoragePath(PHKEY phKey)
 
90
static int vbglR3QueryAdditionsWinStoragePath(PHKEY phKey)
88
91
{
89
92
    /*
90
93
     * Try get the *installed* version first.
138
141
 *
139
142
 * @returns IPRT status value
140
143
 * @param   hKey        Handle to close, retrieved by
141
 
 *                      vbglR3GetAdditionsWinStoragePath().
 
144
 *                      vbglR3QueryAdditionsWinStoragePath().
142
145
 */
143
146
static int vbglR3CloseAdditionsWinStoragePath(HKEY hKey)
144
147
{
173
176
    return rc;
174
177
}
175
178
 
 
179
#ifdef RT_OS_WINDOWS
 
180
 
 
181
/**
 
182
 * Queries a string value from a specified registry key.
 
183
 *
 
184
 * @return  IPRT status code.
 
185
 * @param   hKey                    Handle of registry key to use.
 
186
 * @param   pszValName              Value name to query value from.
 
187
 * @param   pszBuffer               Pointer to buffer which the queried string value gets stored into.
 
188
 * @param   cchBuffer               Size (in bytes) of buffer.
 
189
 */
 
190
static int vbglR3QueryRegistryString(HKEY hKey, const char *pszValName, char *pszBuffer, size_t cchBuffer)
 
191
{
 
192
    AssertReturn(pszValName, VERR_INVALID_PARAMETER);
 
193
    AssertReturn(pszBuffer, VERR_INVALID_POINTER);
 
194
    AssertReturn(cchBuffer, VERR_INVALID_PARAMETER);
 
195
 
 
196
    int rc;
 
197
    DWORD dwType;
 
198
    DWORD dwSize = (DWORD)cchBuffer;
 
199
    LONG lRet = RegQueryValueEx(hKey, pszValName, NULL, &dwType, (BYTE *)pszBuffer, &dwSize);
 
200
    if (lRet == ERROR_SUCCESS)
 
201
        rc = dwType == REG_SZ ? VINF_SUCCESS : VERR_INVALID_PARAMETER;
 
202
    else
 
203
        rc = RTErrConvertFromWin32(lRet);
 
204
    return rc;
 
205
}
 
206
 
 
207
#endif /* RT_OS_WINDOWS */
 
208
 
176
209
/**
177
210
 * Retrieves the installed Guest Additions version and/or revision.
178
211
 *
180
213
 * @param   ppszVer     Receives pointer of allocated raw version string
181
214
 *                      (major.minor.build). NULL is accepted. The returned
182
215
 *                      pointer must be freed using RTStrFree().*
183
 
 * @param   ppszVerEx   Receives pointer of allocated full version string
 
216
 * @param   ppszVerExt  Receives pointer of allocated full version string
184
217
 *                      (raw version + vendor suffix(es)). NULL is
185
218
 *                      accepted. The returned pointer must be freed using
186
219
 *                      RTStrFree().
188
221
 *                      accepted. The returned pointer must be freed using
189
222
 *                      RTStrFree().
190
223
 */
191
 
VBGLR3DECL(int) VbglR3GetAdditionsVersion(char **ppszVer, char **ppszVerEx, char **ppszRev)
 
224
VBGLR3DECL(int) VbglR3GetAdditionsVersion(char **ppszVer, char **ppszVerExt, char **ppszRev)
192
225
{
 
226
    /*
 
227
     * Zap the return value up front.
 
228
     */
 
229
    if (ppszVer)
 
230
        *ppszVer    = NULL;
 
231
    if (ppszVerExt)
 
232
        *ppszVerExt = NULL;
 
233
    if (ppszRev)
 
234
        *ppszRev    = NULL;
 
235
 
193
236
#ifdef RT_OS_WINDOWS
194
237
    HKEY hKey;
195
 
    int rc = vbglR3GetAdditionsWinStoragePath(&hKey);
 
238
    int rc = vbglR3QueryAdditionsWinStoragePath(&hKey);
196
239
    if (RT_SUCCESS(rc))
197
240
    {
198
 
        /* Version. */
199
 
        LONG l;
200
 
        DWORD dwType;
201
 
        DWORD dwSize = 32;
202
 
        char *pszTmp;
 
241
        /*
 
242
         * Version.
 
243
         */
 
244
        char szTemp[32];
203
245
        if (ppszVer)
204
246
        {
205
 
            pszTmp = (char*)RTMemAlloc(dwSize);
206
 
            if (pszTmp)
207
 
            {
208
 
                l = RegQueryValueEx(hKey, "Version", NULL, &dwType, (BYTE*)(LPCTSTR)pszTmp, &dwSize);
209
 
                if (l == ERROR_SUCCESS)
210
 
                {
211
 
                    if (dwType == REG_SZ)
212
 
                        rc = RTStrDupEx(ppszVer, pszTmp);
213
 
                    else
214
 
                        rc = VERR_INVALID_PARAMETER;
215
 
                }
216
 
                else
217
 
                {
218
 
                    rc = RTErrConvertFromWin32(l);
219
 
                }
220
 
                RTMemFree(pszTmp);
221
 
            }
222
 
            else
223
 
                rc = VERR_NO_MEMORY;
224
 
        }
225
 
        if (ppszVerEx)
226
 
        {
227
 
            dwSize = 32; /* Reset */
228
 
            pszTmp = (char*)RTMemAlloc(dwSize);
229
 
            if (pszTmp)
230
 
            {
231
 
                l = RegQueryValueEx(hKey, "VersionEx", NULL, &dwType, (BYTE*)(LPCTSTR)pszTmp, &dwSize);
232
 
                if (l == ERROR_SUCCESS)
233
 
                {
234
 
                    if (dwType == REG_SZ)
235
 
                        rc = RTStrDupEx(ppszVerEx, pszTmp);
236
 
                    else
237
 
                        rc = VERR_INVALID_PARAMETER;
238
 
                }
239
 
                else
240
 
                {
241
 
                    rc = RTErrConvertFromWin32(l);
242
 
                }
243
 
                RTMemFree(pszTmp);
244
 
            }
245
 
            else
246
 
                rc = VERR_NO_MEMORY;
247
 
        }
248
 
        /* Revision. */
249
 
        if (ppszRev)
250
 
        {
251
 
            dwSize = 32; /* Reset */
252
 
            pszTmp = (char*)RTMemAlloc(dwSize);
253
 
            if (pszTmp)
254
 
            {
255
 
                l = RegQueryValueEx(hKey, "Revision", NULL, &dwType, (BYTE*)(LPCTSTR)pszTmp, &dwSize);
256
 
                if (l == ERROR_SUCCESS)
257
 
                {
258
 
                    if (dwType == REG_SZ)
259
 
                        rc = RTStrDupEx(ppszRev, pszTmp);
260
 
                    else
261
 
                        rc = VERR_INVALID_PARAMETER;
262
 
                }
263
 
                else
264
 
                {
265
 
                    rc = RTErrConvertFromWin32(l);
266
 
                }
267
 
                RTMemFree(pszTmp);
268
 
            }
269
 
            else
270
 
                rc = VERR_NO_MEMORY;
271
 
 
272
 
            if (RT_FAILURE(rc) && ppszVer)
273
 
            {
 
247
            rc = vbglR3QueryRegistryString(hKey, "Version", szTemp, sizeof(szTemp));
 
248
            if (RT_SUCCESS(rc))
 
249
                rc = RTStrDupEx(ppszVer, szTemp);
 
250
        }
 
251
 
 
252
        if (   RT_SUCCESS(rc)
 
253
            && ppszVerExt)
 
254
        {
 
255
            rc = vbglR3QueryRegistryString(hKey, "VersionExt", szTemp, sizeof(szTemp));
 
256
            if (RT_SUCCESS(rc))
 
257
                rc = RTStrDupEx(ppszVerExt, szTemp);
 
258
        }
 
259
 
 
260
        /*
 
261
         * Revision.
 
262
         */
 
263
        if (   RT_SUCCESS(rc)
 
264
            && ppszRev)
 
265
        {
 
266
            rc = vbglR3QueryRegistryString(hKey, "Revision", szTemp, sizeof(szTemp));
 
267
            if (RT_SUCCESS(rc))
 
268
                rc = RTStrDupEx(ppszRev, szTemp);
 
269
        }
 
270
 
 
271
        int rc2 = vbglR3CloseAdditionsWinStoragePath(hKey);
 
272
        if (RT_SUCCESS(rc))
 
273
            rc = rc2;
 
274
 
 
275
        /* Clean up allocated strings on error. */
 
276
        if (RT_FAILURE(rc))
 
277
        {
 
278
            if (ppszVer)
274
279
                RTStrFree(*ppszVer);
275
 
                *ppszVer = NULL;
276
 
            }
 
280
            if (ppszVerExt)
 
281
                RTStrFree(*ppszVerExt);
 
282
            if (ppszRev)
 
283
                RTStrFree(*ppszRev);
277
284
        }
278
 
        rc = vbglR3CloseAdditionsWinStoragePath(hKey);
279
285
    }
280
286
    else
281
287
    {
283
289
         * No registry entries found, return the version string compiled
284
290
         * into this binary.
285
291
         */
286
 
        rc = vbglR3GetAdditionsCompileTimeVersion(ppszVer, ppszVerEx, ppszRev);
 
292
        rc = vbglR3GetAdditionsCompileTimeVersion(ppszVer, ppszVerExt, ppszRev);
287
293
    }
288
294
    return rc;
289
295
 
291
297
    /*
292
298
     * On non-Windows platforms just return the compile-time version string.
293
299
     */
294
 
    return vbglR3GetAdditionsCompileTimeVersion(ppszVer, ppszVerEx, ppszRev);
 
300
    return vbglR3GetAdditionsCompileTimeVersion(ppszVer, ppszVerExt, ppszRev);
295
301
#endif /* !RT_OS_WINDOWS */
296
302
}
297
303
 
309
315
    int rc;
310
316
#ifdef RT_OS_WINDOWS
311
317
    HKEY hKey;
312
 
    rc = vbglR3GetAdditionsWinStoragePath(&hKey);
 
318
    rc = vbglR3QueryAdditionsWinStoragePath(&hKey);
313
319
    if (RT_SUCCESS(rc))
314
320
    {
315
321
        /* Installation directory. */