1 | /* $Id: VBoxGuestR3LibGuestUser.cpp 47294 2013-07-22 11:19:20Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBoxGuestR3Lib - Ring-3 Support Library for VirtualBox guest additions,
|
---|
4 | * guest user reporting / utility functions.
|
---|
5 | */
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Copyright (C) 2013 Oracle Corporation
|
---|
9 | *
|
---|
10 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
11 | * available from http://www.virtualbox.org. This file is free software;
|
---|
12 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
13 | * General Public License (GPL) as published by the Free Software
|
---|
14 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
15 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
16 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
17 | *
|
---|
18 | * The contents of this file may alternatively be used under the terms
|
---|
19 | * of the Common Development and Distribution License Version 1.0
|
---|
20 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
21 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
22 | * CDDL are applicable instead of those of the GPL.
|
---|
23 | *
|
---|
24 | * You may elect to license modified versions of this file under the
|
---|
25 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
26 | */
|
---|
27 |
|
---|
28 |
|
---|
29 | /*******************************************************************************
|
---|
30 | * Header Files *
|
---|
31 | *******************************************************************************/
|
---|
32 | #include <iprt/assert.h>
|
---|
33 | #include <VBox/log.h>
|
---|
34 | #include <iprt/mem.h>
|
---|
35 | #include <iprt/string.h>
|
---|
36 |
|
---|
37 | #include "VBGLR3Internal.h"
|
---|
38 |
|
---|
39 |
|
---|
40 | /**
|
---|
41 | * Reports a state change of a specific guest user.
|
---|
42 | *
|
---|
43 | * @returns IPRT status value
|
---|
44 | * @param pszUser Guest user name to report state for.
|
---|
45 | * @param pszDomain Domain the guest user's account is bound to.
|
---|
46 | * @param enmState Guest user state to report.
|
---|
47 | * @param puDetails Pointer to state details. Optional.
|
---|
48 | * @param cbDetails Size (in bytes) of state details. Pass 0
|
---|
49 | * if puDetails is NULL.
|
---|
50 | */
|
---|
51 | VBGLR3DECL(int) VbglR3GuestUserReportState(const char *pszUser,
|
---|
52 | const char *pszDomain,
|
---|
53 | VBoxGuestUserState enmState,
|
---|
54 | uint8_t *puDetails,
|
---|
55 | uint32_t cbDetails)
|
---|
56 | {
|
---|
57 | AssertPtrReturn(pszUser, VERR_INVALID_POINTER);
|
---|
58 | /* pszDomain is optional. */
|
---|
59 | /* puDetails is optional. */
|
---|
60 |
|
---|
61 | uint32_t cbBase = sizeof(VMMDevReportGuestUserState);
|
---|
62 | uint32_t cbUser = strlen(pszUser) + 1; /* Include terminating zero */
|
---|
63 | uint32_t cbDomain = pszDomain ? strlen(pszDomain) + 1 /* Dito */ : 0;
|
---|
64 |
|
---|
65 | /* Allocate enough space for all fields. */
|
---|
66 | unsigned long cbSize =
|
---|
67 | cbBase
|
---|
68 | + cbUser
|
---|
69 | + cbDomain
|
---|
70 | + cbDetails;
|
---|
71 |
|
---|
72 | AssertReturn(cbSize, VERR_BUFFER_UNDERFLOW);
|
---|
73 | VMMDevReportGuestUserState *pReport =
|
---|
74 | (VMMDevReportGuestUserState *)RTMemAllocZ(cbSize);
|
---|
75 | if (!pReport)
|
---|
76 | return VERR_NO_MEMORY;
|
---|
77 |
|
---|
78 | int rc = vmmdevInitRequest(&pReport->header, VMMDevReq_ReportGuestUserState);
|
---|
79 | if (RT_SUCCESS(rc))
|
---|
80 | {
|
---|
81 | pReport->header.size = cbSize;
|
---|
82 |
|
---|
83 | pReport->status.state = enmState;
|
---|
84 | pReport->status.cbUser = cbUser;
|
---|
85 | pReport->status.cbDomain = cbDomain;
|
---|
86 | pReport->status.cbDetails = cbDetails;
|
---|
87 |
|
---|
88 | /*
|
---|
89 | * Note: cbOffDynamic contains the first dynamic array entry within
|
---|
90 | * VBoxGuestUserStatus.
|
---|
91 | * Therefore it's vital to *not* change the order of the struct members
|
---|
92 | * without altering this code. Don't try this at home.
|
---|
93 | */
|
---|
94 | uint32_t cbOffDynamic =
|
---|
95 | RT_OFFSETOF(VBoxGuestUserStatus, szUser);
|
---|
96 |
|
---|
97 | /* pDynamic marks the beginning for the dynamically allocated areas. */
|
---|
98 | uint8_t *pDynamic = (uint8_t *)&pReport->status;
|
---|
99 | pDynamic += cbOffDynamic;
|
---|
100 | AssertPtr(pDynamic);
|
---|
101 |
|
---|
102 | memcpy(pDynamic, pszUser, cbUser);
|
---|
103 | if (cbDomain)
|
---|
104 | memcpy(pDynamic + cbUser, pszDomain, cbDomain);
|
---|
105 | if (cbDetails)
|
---|
106 | memcpy(pDynamic + cbUser + cbDomain, puDetails, cbDetails);
|
---|
107 |
|
---|
108 | rc = vbglR3GRPerform(&pReport->header);
|
---|
109 | }
|
---|
110 |
|
---|
111 | RTMemFree(pReport);
|
---|
112 | return rc;
|
---|
113 | }
|
---|
114 |
|
---|