VirtualBox

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

Last change on this file since 78554 was 76553, checked in by vboxsync, 6 years ago

scm --update-copyright-year

  • 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 76553 2019-01-01 01:45:53Z 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-2019 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/errcore.h>
35#include <iprt/mem.h>
36#include <iprt/string.h>
37
38#include "VBoxGuestR3LibInternal.h"
39
40
41/**
42 * Reports a state change of a specific guest user.
43 *
44 * @returns IPRT status value
45 * @param pszUser Guest user name to report state for.
46 * @param pszDomain Domain the guest user's account is bound to.
47 * @param enmState Guest user state to report.
48 * @param puDetails Pointer to state details. Optional.
49 * @param cbDetails Size (in bytes) of state details. Pass 0
50 * if puDetails is NULL.
51 */
52VBGLR3DECL(int) VbglR3GuestUserReportState(const char *pszUser, const char *pszDomain, VBoxGuestUserState enmState,
53 uint8_t *puDetails, uint32_t cbDetails)
54{
55 AssertPtrReturn(pszUser, VERR_INVALID_POINTER);
56 /* pszDomain is optional. */
57 /* puDetails is optional. */
58 AssertReturn(cbDetails == 0 || puDetails != NULL, VERR_INVALID_PARAMETER);
59 AssertReturn(cbDetails < 16U*_1M, VERR_OUT_OF_RANGE);
60
61 uint32_t cbBase = sizeof(VMMDevReportGuestUserState);
62 uint32_t cbUser = (uint32_t)strlen(pszUser) + 1; /* Include terminating zero */
63 uint32_t cbDomain = pszDomain ? (uint32_t)strlen(pszDomain) + 1 /* Ditto */ : 0;
64
65 /* Allocate enough space for all fields. */
66 uint32_t cbSize = cbBase
67 + cbUser
68 + cbDomain
69 + cbDetails;
70 VMMDevReportGuestUserState *pReport = (VMMDevReportGuestUserState *)RTMemAllocZ(cbSize);
71 if (!pReport)
72 return VERR_NO_MEMORY;
73
74 int rc = vmmdevInitRequest(&pReport->header, VMMDevReq_ReportGuestUserState);
75 if (RT_SUCCESS(rc))
76 {
77 pReport->header.size = cbSize;
78
79 pReport->status.state = enmState;
80 pReport->status.cbUser = cbUser;
81 pReport->status.cbDomain = cbDomain;
82 pReport->status.cbDetails = cbDetails;
83
84 /*
85 * Note: cbOffDynamic contains the first dynamic array entry within
86 * VBoxGuestUserStatus.
87 * Therefore it's vital to *not* change the order of the struct members
88 * without altering this code. Don't try this at home.
89 */
90 uint32_t cbOffDynamic = RT_UOFFSETOF(VBoxGuestUserStatus, szUser);
91
92 /* pDynamic marks the beginning for the dynamically allocated areas. */
93 uint8_t *pDynamic = (uint8_t *)&pReport->status;
94 pDynamic += cbOffDynamic;
95 AssertPtr(pDynamic);
96
97 memcpy(pDynamic, pszUser, cbUser);
98 if (cbDomain)
99 memcpy(pDynamic + cbUser, pszDomain, cbDomain);
100 if (cbDetails)
101 memcpy(pDynamic + cbUser + cbDomain, puDetails, cbDetails);
102
103 rc = vbglR3GRPerform(&pReport->header);
104 }
105
106 RTMemFree(pReport);
107 return rc;
108}
109
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