1 | /** @file
|
---|
2 | *
|
---|
3 | * VirtualBox COM class implementation
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006 InnoTek Systemberatung GmbH
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License as published by the Free Software Foundation,
|
---|
13 | * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
|
---|
14 | * distribution. VirtualBox OSE is distributed in the hope that it will
|
---|
15 | * be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | *
|
---|
17 | * If you received this file as part of a commercial VirtualBox
|
---|
18 | * distribution, then only the terms of your commercial VirtualBox
|
---|
19 | * license agreement apply instead of the previous paragraph.
|
---|
20 | */
|
---|
21 |
|
---|
22 | #include "GuestImpl.h"
|
---|
23 | #include "ConsoleImpl.h"
|
---|
24 | #include "VMMDev.h"
|
---|
25 |
|
---|
26 | #include "Logging.h"
|
---|
27 |
|
---|
28 | #include <VBox/VBoxDev.h>
|
---|
29 |
|
---|
30 | // defines
|
---|
31 | /////////////////////////////////////////////////////////////////////////////
|
---|
32 |
|
---|
33 | // constructor / destructor
|
---|
34 | /////////////////////////////////////////////////////////////////////////////
|
---|
35 |
|
---|
36 | DEFINE_EMPTY_CTOR_DTOR (Guest)
|
---|
37 |
|
---|
38 | HRESULT Guest::FinalConstruct()
|
---|
39 | {
|
---|
40 | return S_OK;
|
---|
41 | }
|
---|
42 |
|
---|
43 | void Guest::FinalRelease()
|
---|
44 | {
|
---|
45 | uninit ();
|
---|
46 | }
|
---|
47 |
|
---|
48 | // public methods only for internal purposes
|
---|
49 | /////////////////////////////////////////////////////////////////////////////
|
---|
50 |
|
---|
51 | /**
|
---|
52 | * Initializes the guest object.
|
---|
53 | */
|
---|
54 | HRESULT Guest::init (Console *aParent)
|
---|
55 | {
|
---|
56 | LogFlowThisFunc (("aParent=%p\n", aParent));
|
---|
57 |
|
---|
58 | ComAssertRet (aParent, E_INVALIDARG);
|
---|
59 |
|
---|
60 | /* Enclose the state transition NotReady->InInit->Ready */
|
---|
61 | AutoInitSpan autoInitSpan (this);
|
---|
62 | AssertReturn (autoInitSpan.isOk(), E_UNEXPECTED);
|
---|
63 |
|
---|
64 | unconst (mParent) = aParent;
|
---|
65 |
|
---|
66 | /* mData.mAdditionsActive is FALSE */
|
---|
67 |
|
---|
68 | /* Confirm a successful initialization when it's the case */
|
---|
69 | autoInitSpan.setSucceeded();
|
---|
70 |
|
---|
71 | return S_OK;
|
---|
72 | }
|
---|
73 |
|
---|
74 | /**
|
---|
75 | * Uninitializes the instance and sets the ready flag to FALSE.
|
---|
76 | * Called either from FinalRelease() or by the parent when it gets destroyed.
|
---|
77 | */
|
---|
78 | void Guest::uninit()
|
---|
79 | {
|
---|
80 | LogFlowThisFunc (("\n"));
|
---|
81 |
|
---|
82 | /* Enclose the state transition Ready->InUninit->NotReady */
|
---|
83 | AutoUninitSpan autoUninitSpan (this);
|
---|
84 | if (autoUninitSpan.uninitDone())
|
---|
85 | return;
|
---|
86 |
|
---|
87 | unconst (mParent).setNull();
|
---|
88 | }
|
---|
89 |
|
---|
90 | // IGuest properties
|
---|
91 | /////////////////////////////////////////////////////////////////////////////
|
---|
92 |
|
---|
93 | STDMETHODIMP Guest::COMGETTER(OSTypeId) (BSTR *aOSTypeId)
|
---|
94 | {
|
---|
95 | if (!aOSTypeId)
|
---|
96 | return E_POINTER;
|
---|
97 |
|
---|
98 | AutoCaller autoCaller (this);
|
---|
99 | CheckComRCReturnRC (autoCaller.rc());
|
---|
100 |
|
---|
101 | AutoReaderLock alock (this);
|
---|
102 |
|
---|
103 | // redirect the call to IMachine if no additions are installed
|
---|
104 | if (mData.mAdditionsVersion.isNull())
|
---|
105 | return mParent->machine()->COMGETTER(OSTypeId) (aOSTypeId);
|
---|
106 |
|
---|
107 | mData.mOSTypeId.cloneTo (aOSTypeId);
|
---|
108 |
|
---|
109 | return S_OK;
|
---|
110 | }
|
---|
111 |
|
---|
112 | STDMETHODIMP Guest::COMGETTER(AdditionsActive) (BOOL *aAdditionsActive)
|
---|
113 | {
|
---|
114 | if (!aAdditionsActive)
|
---|
115 | return E_POINTER;
|
---|
116 |
|
---|
117 | AutoCaller autoCaller (this);
|
---|
118 | CheckComRCReturnRC (autoCaller.rc());
|
---|
119 |
|
---|
120 | AutoReaderLock alock (this);
|
---|
121 |
|
---|
122 | *aAdditionsActive = mData.mAdditionsActive;
|
---|
123 |
|
---|
124 | return S_OK;
|
---|
125 | }
|
---|
126 |
|
---|
127 | STDMETHODIMP Guest::COMGETTER(AdditionsVersion) (BSTR *aAdditionsVersion)
|
---|
128 | {
|
---|
129 | if (!aAdditionsVersion)
|
---|
130 | return E_POINTER;
|
---|
131 |
|
---|
132 | AutoCaller autoCaller (this);
|
---|
133 | CheckComRCReturnRC (autoCaller.rc());
|
---|
134 |
|
---|
135 | AutoReaderLock alock (this);
|
---|
136 |
|
---|
137 | mData.mAdditionsVersion.cloneTo (aAdditionsVersion);
|
---|
138 |
|
---|
139 | return S_OK;
|
---|
140 | }
|
---|
141 |
|
---|
142 | STDMETHODIMP Guest::SetCredentials(INPTR BSTR aUserName, INPTR BSTR aPassword,
|
---|
143 | INPTR BSTR aDomain, BOOL aAllowInteractiveLogon)
|
---|
144 | {
|
---|
145 | if (!aUserName || !aPassword || !aDomain)
|
---|
146 | return E_INVALIDARG;
|
---|
147 |
|
---|
148 | AutoCaller autoCaller (this);
|
---|
149 | CheckComRCReturnRC (autoCaller.rc());
|
---|
150 |
|
---|
151 | /* forward the information to the VMM device */
|
---|
152 | VMMDev *vmmDev = mParent->getVMMDev();
|
---|
153 | if (vmmDev)
|
---|
154 | {
|
---|
155 | uint32_t u32Flags = VMMDEV_SETCREDENTIALS_GUESTLOGON;
|
---|
156 | if (!aAllowInteractiveLogon)
|
---|
157 | u32Flags = VMMDEV_SETCREDENTIALS_NOLOCALLOGON;
|
---|
158 |
|
---|
159 | vmmDev->getVMMDevPort()->pfnSetCredentials(vmmDev->getVMMDevPort(),
|
---|
160 | Utf8Str(aUserName).raw(), Utf8Str(aPassword).raw(),
|
---|
161 | Utf8Str(aDomain).raw(), u32Flags);
|
---|
162 | return S_OK;
|
---|
163 | }
|
---|
164 |
|
---|
165 | return setError (E_FAIL,
|
---|
166 | tr ("VMM device is not available (is the VM running?)"));
|
---|
167 | }
|
---|
168 |
|
---|
169 |
|
---|
170 | // public methods only for internal purposes
|
---|
171 | /////////////////////////////////////////////////////////////////////////////
|
---|
172 |
|
---|
173 | void Guest::setAdditionsVersion (Bstr aVersion)
|
---|
174 | {
|
---|
175 | AssertReturnVoid (!aVersion.isEmpty());
|
---|
176 |
|
---|
177 | AutoCaller autoCaller (this);
|
---|
178 | AssertComRCReturnVoid (autoCaller.rc());
|
---|
179 |
|
---|
180 | AutoLock alock (this);
|
---|
181 |
|
---|
182 | mData.mAdditionsVersion = aVersion;
|
---|
183 | /* this implies that Additions are active */
|
---|
184 | mData.mAdditionsActive = TRUE;
|
---|
185 | }
|
---|