VirtualBox

source: vbox/trunk/src/VBox/Additions/common/VBoxGuest/lib/VBoxGuestR3LibGuestUser.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: 4.6 KB
Line 
1/* $Id: VBoxGuestR3LibGuestUser.cpp 98103 2023-01-17 14:15:46Z 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-2023 Oracle and/or its affiliates.
9 *
10 * This file is part of VirtualBox base platform packages, as
11 * available from https://www.virtualbox.org.
12 *
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation, in version 3 of the
16 * License.
17 *
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, see <https://www.gnu.org/licenses>.
25 *
26 * The contents of this file may alternatively be used under the terms
27 * of the Common Development and Distribution License Version 1.0
28 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
29 * in the VirtualBox distribution, in which case the provisions of the
30 * CDDL are applicable instead of those of the GPL.
31 *
32 * You may elect to license modified versions of this file under the
33 * terms and conditions of either the GPL or the CDDL or both.
34 *
35 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
36 */
37
38
39/*********************************************************************************************************************************
40* Header Files *
41*********************************************************************************************************************************/
42#include <iprt/assert.h>
43#include <VBox/log.h>
44#include <iprt/errcore.h>
45#include <iprt/mem.h>
46#include <iprt/string.h>
47
48#include "VBoxGuestR3LibInternal.h"
49
50
51/**
52 * Reports a state change of a specific guest user.
53 *
54 * @returns IPRT status value
55 * @param pszUser Guest user name to report state for.
56 * @param pszDomain Domain the guest user's account is bound to.
57 * @param enmState Guest user state to report.
58 * @param puDetails Pointer to state details. Optional.
59 * @param cbDetails Size (in bytes) of state details. Pass 0
60 * if puDetails is NULL.
61 */
62VBGLR3DECL(int) VbglR3GuestUserReportState(const char *pszUser, const char *pszDomain, VBoxGuestUserState enmState,
63 uint8_t *puDetails, uint32_t cbDetails)
64{
65 AssertPtrReturn(pszUser, VERR_INVALID_POINTER);
66 /* pszDomain is optional. */
67 /* puDetails is optional. */
68 AssertReturn(cbDetails == 0 || puDetails != NULL, VERR_INVALID_PARAMETER);
69 AssertReturn(cbDetails < 16U*_1M, VERR_OUT_OF_RANGE);
70
71 uint32_t cbBase = sizeof(VMMDevReportGuestUserState);
72 uint32_t cbUser = (uint32_t)strlen(pszUser) + 1; /* Include terminating zero */
73 uint32_t cbDomain = pszDomain ? (uint32_t)strlen(pszDomain) + 1 /* Ditto */ : 0;
74
75 /* Allocate enough space for all fields. */
76 uint32_t cbSize = cbBase
77 + cbUser
78 + cbDomain
79 + cbDetails;
80 VMMDevReportGuestUserState *pReport = (VMMDevReportGuestUserState *)RTMemAllocZ(cbSize);
81 if (!pReport)
82 return VERR_NO_MEMORY;
83
84 int rc = vmmdevInitRequest(&pReport->header, VMMDevReq_ReportGuestUserState);
85 if (RT_SUCCESS(rc))
86 {
87 pReport->header.size = cbSize;
88
89 pReport->status.state = enmState;
90 pReport->status.cbUser = cbUser;
91 pReport->status.cbDomain = cbDomain;
92 pReport->status.cbDetails = cbDetails;
93
94 /*
95 * Note: cbOffDynamic contains the first dynamic array entry within
96 * VBoxGuestUserStatus.
97 * Therefore it's vital to *not* change the order of the struct members
98 * without altering this code. Don't try this at home.
99 */
100 uint32_t cbOffDynamic = RT_UOFFSETOF(VBoxGuestUserStatus, szUser);
101
102 /* pDynamic marks the beginning for the dynamically allocated areas. */
103 uint8_t *pDynamic = (uint8_t *)&pReport->status;
104 pDynamic += cbOffDynamic;
105 AssertPtr(pDynamic);
106
107 memcpy(pDynamic, pszUser, cbUser);
108 if (cbDomain)
109 memcpy(pDynamic + cbUser, pszDomain, cbDomain);
110 if (cbDetails)
111 memcpy(pDynamic + cbUser + cbDomain, puDetails, cbDetails);
112
113 rc = vbglR3GRPerform(&pReport->header);
114 }
115
116 RTMemFree(pReport);
117 return rc;
118}
119
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use