VirtualBox

source: vbox/trunk/src/VBox/Additions/common/VBoxGuest/lib/VBoxGuestR3LibGuestUser.cpp@ 75853

Last change on this file since 75853 was 73097, checked in by vboxsync, 6 years ago

*: Made RT_UOFFSETOF, RT_OFFSETOF, RT_UOFFSETOF_ADD and RT_OFFSETOF_ADD work like builtin_offsetof() and require compile time resolvable requests, adding RT_UOFFSETOF_DYN for the dynamic questions that can only be answered at runtime.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.3 KB
Line 
1/* $Id: VBoxGuestR3LibGuestUser.cpp 73097 2018-07-12 21:06:33Z 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-2017 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 "VBoxGuestR3LibInternal.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 */
51VBGLR3DECL(int) VbglR3GuestUserReportState(const char *pszUser, const char *pszDomain, VBoxGuestUserState enmState,
52 uint8_t *puDetails, uint32_t cbDetails)
53{
54 AssertPtrReturn(pszUser, VERR_INVALID_POINTER);
55 /* pszDomain is optional. */
56 /* puDetails is optional. */
57 AssertReturn(cbDetails == 0 || puDetails != NULL, VERR_INVALID_PARAMETER);
58 AssertReturn(cbDetails < 16U*_1M, VERR_OUT_OF_RANGE);
59
60 uint32_t cbBase = sizeof(VMMDevReportGuestUserState);
61 uint32_t cbUser = (uint32_t)strlen(pszUser) + 1; /* Include terminating zero */
62 uint32_t cbDomain = pszDomain ? (uint32_t)strlen(pszDomain) + 1 /* Ditto */ : 0;
63
64 /* Allocate enough space for all fields. */
65 uint32_t cbSize = cbBase
66 + cbUser
67 + cbDomain
68 + cbDetails;
69 VMMDevReportGuestUserState *pReport = (VMMDevReportGuestUserState *)RTMemAllocZ(cbSize);
70 if (!pReport)
71 return VERR_NO_MEMORY;
72
73 int rc = vmmdevInitRequest(&pReport->header, VMMDevReq_ReportGuestUserState);
74 if (RT_SUCCESS(rc))
75 {
76 pReport->header.size = cbSize;
77
78 pReport->status.state = enmState;
79 pReport->status.cbUser = cbUser;
80 pReport->status.cbDomain = cbDomain;
81 pReport->status.cbDetails = cbDetails;
82
83 /*
84 * Note: cbOffDynamic contains the first dynamic array entry within
85 * VBoxGuestUserStatus.
86 * Therefore it's vital to *not* change the order of the struct members
87 * without altering this code. Don't try this at home.
88 */
89 uint32_t cbOffDynamic = RT_UOFFSETOF(VBoxGuestUserStatus, szUser);
90
91 /* pDynamic marks the beginning for the dynamically allocated areas. */
92 uint8_t *pDynamic = (uint8_t *)&pReport->status;
93 pDynamic += cbOffDynamic;
94 AssertPtr(pDynamic);
95
96 memcpy(pDynamic, pszUser, cbUser);
97 if (cbDomain)
98 memcpy(pDynamic + cbUser, pszDomain, cbDomain);
99 if (cbDetails)
100 memcpy(pDynamic + cbUser + cbDomain, puDetails, cbDetails);
101
102 rc = vbglR3GRPerform(&pReport->header);
103 }
104
105 RTMemFree(pReport);
106 return rc;
107}
108
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette