VirtualBox

source: vbox/trunk/src/VBox/Main/SystemPropertiesImpl.cpp@ 5771

Last change on this file since 5771 was 5771, checked in by vboxsync, 17 years ago

Main, VBoxManage: add setting for webservice authentication library (which can be NULL to disable authentication)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.7 KB
Line 
1/** @file
2 *
3 * VirtualBox COM class implementation
4 */
5
6/*
7 * Copyright (C) 2006-2007 innotek 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
18#include "SystemPropertiesImpl.h"
19#include "VirtualBoxImpl.h"
20#include "MachineImpl.h"
21#include "Logging.h"
22
23// generated header
24#include "SchemaDefs.h"
25
26#include <iprt/path.h>
27#include <iprt/dir.h>
28#include <VBox/param.h>
29#include <VBox/err.h>
30
31// defines
32/////////////////////////////////////////////////////////////////////////////
33
34// constructor / destructor
35/////////////////////////////////////////////////////////////////////////////
36
37HRESULT SystemProperties::FinalConstruct()
38{
39 return S_OK;
40}
41
42void SystemProperties::FinalRelease()
43{
44 if (isReady())
45 uninit ();
46}
47
48// public methods only for internal purposes
49/////////////////////////////////////////////////////////////////////////////
50
51/**
52 * Initializes the system information object.
53 *
54 * @returns COM result indicator
55 */
56HRESULT SystemProperties::init (VirtualBox *aParent)
57{
58 LogFlowMember (("SystemProperties::init()\n"));
59
60 ComAssertRet (aParent, E_FAIL);
61
62 AutoLock alock (this);
63 ComAssertRet (!isReady(), E_UNEXPECTED);
64
65 mParent = aParent;
66
67 setDefaultVDIFolder (NULL);
68 setDefaultMachineFolder (NULL);
69 setRemoteDisplayAuthLibrary (NULL);
70
71 mHWVirtExEnabled = false;
72 mLogHistoryCount = 3;
73
74 setReady(true);
75 return S_OK;
76}
77
78/**
79 * Uninitializes the instance and sets the ready flag to FALSE.
80 * Called either from FinalRelease() or by the parent when it gets destroyed.
81 */
82void SystemProperties::uninit()
83{
84 LogFlowMember (("SystemProperties::uninit()\n"));
85
86 AutoLock alock (this);
87 AssertReturn (isReady(), (void) 0);
88
89 setReady (false);
90}
91
92// ISystemProperties properties
93/////////////////////////////////////////////////////////////////////////////
94
95
96STDMETHODIMP SystemProperties::COMGETTER(MinGuestRAM)(ULONG *minRAM)
97{
98 if (!minRAM)
99 return E_POINTER;
100 AutoLock lock(this);
101 CHECK_READY();
102
103 *minRAM = SchemaDefs::MinGuestRAM;
104
105 return S_OK;
106}
107
108STDMETHODIMP SystemProperties::COMGETTER(MaxGuestRAM)(ULONG *maxRAM)
109{
110 if (!maxRAM)
111 return E_POINTER;
112 AutoLock lock(this);
113 CHECK_READY();
114
115 *maxRAM = SchemaDefs::MaxGuestRAM;
116
117 return S_OK;
118}
119
120STDMETHODIMP SystemProperties::COMGETTER(MinGuestVRAM)(ULONG *minVRAM)
121{
122 if (!minVRAM)
123 return E_POINTER;
124 AutoLock lock(this);
125 CHECK_READY();
126
127 *minVRAM = SchemaDefs::MinGuestVRAM;
128
129 return S_OK;
130}
131
132STDMETHODIMP SystemProperties::COMGETTER(MaxGuestVRAM)(ULONG *maxVRAM)
133{
134 if (!maxVRAM)
135 return E_POINTER;
136 AutoLock lock(this);
137 CHECK_READY();
138
139 *maxVRAM = SchemaDefs::MaxGuestVRAM;
140
141 return S_OK;
142}
143
144STDMETHODIMP SystemProperties::COMGETTER(MaxGuestMonitors)(ULONG *maxMonitors)
145{
146 if (!maxMonitors)
147 return E_POINTER;
148 AutoLock lock(this);
149 CHECK_READY();
150
151 *maxMonitors = SchemaDefs::MaxGuestMonitors;
152
153 return S_OK;
154}
155
156STDMETHODIMP SystemProperties::COMGETTER(MaxVDISize)(ULONG64 *maxVDISize)
157{
158 if (!maxVDISize)
159 return E_POINTER;
160 AutoLock lock(this);
161 CHECK_READY();
162
163 /** The BIOS supports currently 32 bit LBA numbers (implementing the full
164 * 48 bit range is in theory trivial, but the crappy compiler makes things
165 * more difficult). This translates to almost 2 TBytes (to be on the safe
166 * side, the reported limit is 1 MiByte less than that, as the total number
167 * of sectors should fit in 32 bits, too), which should bei enough for
168 * the moment. The virtual ATA disks support complete LBA48 (although for
169 * example iSCSI is also currently limited to 32 bit LBA), so the
170 * theoretical maximum disk size is 128 PiByte. The user interface cannot
171 * cope with this in a reasonable way yet. */
172 *maxVDISize = 2048 * 1024 - 1;
173
174 return S_OK;
175}
176
177STDMETHODIMP SystemProperties::COMGETTER(NetworkAdapterCount)(ULONG *count)
178{
179 if (!count)
180 return E_POINTER;
181 AutoLock lock (this);
182 CHECK_READY();
183
184 *count = SchemaDefs::NetworkAdapterCount;
185
186 return S_OK;
187}
188
189STDMETHODIMP SystemProperties::COMGETTER(SerialPortCount)(ULONG *count)
190{
191 if (!count)
192 return E_POINTER;
193 AutoLock lock (this);
194 CHECK_READY();
195
196 *count = SchemaDefs::SerialPortCount;
197
198 return S_OK;
199}
200
201STDMETHODIMP SystemProperties::COMGETTER(ParallelPortCount)(ULONG *count)
202{
203 if (!count)
204 return E_POINTER;
205 AutoLock lock (this);
206 CHECK_READY();
207
208 *count = SchemaDefs::ParallelPortCount;
209
210 return S_OK;
211}
212
213STDMETHODIMP SystemProperties::COMGETTER(MaxBootPosition)(ULONG *aMaxBootPosition)
214{
215 if (!aMaxBootPosition)
216 return E_POINTER;
217 AutoLock lock (this);
218 CHECK_READY();
219
220 *aMaxBootPosition = SchemaDefs::MaxBootPosition;
221
222 return S_OK;
223}
224
225STDMETHODIMP SystemProperties::COMGETTER(DefaultVDIFolder) (BSTR *aDefaultVDIFolder)
226{
227 if (!aDefaultVDIFolder)
228 return E_POINTER;
229
230 AutoLock alock (this);
231 CHECK_READY();
232
233 mDefaultVDIFolderFull.cloneTo (aDefaultVDIFolder);
234
235 return S_OK;
236}
237
238STDMETHODIMP SystemProperties::COMSETTER(DefaultVDIFolder) (INPTR BSTR aDefaultVDIFolder)
239{
240 AutoLock alock (this);
241 CHECK_READY();
242
243 HRESULT rc = setDefaultVDIFolder (aDefaultVDIFolder);
244 if (FAILED (rc))
245 return rc;
246
247 alock.unlock();
248 return mParent->saveSettings();
249}
250
251STDMETHODIMP SystemProperties::COMGETTER(DefaultMachineFolder) (BSTR *aDefaultMachineFolder)
252{
253 if (!aDefaultMachineFolder)
254 return E_POINTER;
255
256 AutoLock alock (this);
257 CHECK_READY();
258
259 mDefaultMachineFolderFull.cloneTo (aDefaultMachineFolder);
260
261 return S_OK;
262}
263
264STDMETHODIMP SystemProperties::COMSETTER(DefaultMachineFolder) (INPTR BSTR aDefaultMachineFolder)
265{
266 AutoLock alock (this);
267 CHECK_READY();
268
269 HRESULT rc = setDefaultMachineFolder (aDefaultMachineFolder);
270 if (FAILED (rc))
271 return rc;
272
273 alock.unlock();
274 return mParent->saveSettings();
275}
276
277STDMETHODIMP SystemProperties::COMGETTER(RemoteDisplayAuthLibrary) (BSTR *aRemoteDisplayAuthLibrary)
278{
279 if (!aRemoteDisplayAuthLibrary)
280 return E_POINTER;
281
282 AutoLock alock (this);
283 CHECK_READY();
284
285 mRemoteDisplayAuthLibrary.cloneTo (aRemoteDisplayAuthLibrary);
286
287 return S_OK;
288}
289
290STDMETHODIMP SystemProperties::COMSETTER(RemoteDisplayAuthLibrary) (INPTR BSTR aRemoteDisplayAuthLibrary)
291{
292 AutoLock alock (this);
293 CHECK_READY();
294
295 HRESULT rc = setRemoteDisplayAuthLibrary (aRemoteDisplayAuthLibrary);
296 if (FAILED (rc))
297 return rc;
298
299 alock.unlock();
300 return mParent->saveSettings();
301}
302
303STDMETHODIMP SystemProperties::COMGETTER(WebServiceAuthLibrary) (BSTR *aWebServiceAuthLibrary)
304{
305 if (!aWebServiceAuthLibrary)
306 return E_POINTER;
307
308 AutoLock alock (this);
309 CHECK_READY();
310
311 mWebServiceAuthLibrary.cloneTo (aWebServiceAuthLibrary);
312
313 return S_OK;
314}
315
316STDMETHODIMP SystemProperties::COMSETTER(WebServiceAuthLibrary) (INPTR BSTR aWebServiceAuthLibrary)
317{
318 AutoLock alock (this);
319 CHECK_READY();
320
321 HRESULT rc = setWebServiceAuthLibrary (aWebServiceAuthLibrary);
322 if (FAILED (rc))
323 return rc;
324
325 alock.unlock();
326 return mParent->saveSettings();
327}
328
329STDMETHODIMP SystemProperties::COMGETTER(HWVirtExEnabled) (BOOL *enabled)
330{
331 if (!enabled)
332 return E_POINTER;
333
334 AutoLock alock (this);
335 CHECK_READY();
336
337 *enabled = mHWVirtExEnabled;
338
339 return S_OK;
340}
341
342STDMETHODIMP SystemProperties::COMSETTER(HWVirtExEnabled) (BOOL enabled)
343{
344 AutoLock alock (this);
345 CHECK_READY();
346
347 mHWVirtExEnabled = enabled;
348
349 alock.unlock();
350 return mParent->saveSettings();
351}
352
353STDMETHODIMP SystemProperties::COMGETTER(LogHistoryCount) (ULONG *count)
354{
355 if (!count)
356 return E_POINTER;
357
358 AutoLock alock (this);
359 CHECK_READY();
360
361 *count = mLogHistoryCount;
362
363 return S_OK;
364}
365
366STDMETHODIMP SystemProperties::COMSETTER(LogHistoryCount) (ULONG count)
367{
368 AutoLock alock (this);
369 CHECK_READY();
370
371 mLogHistoryCount = count;
372
373 alock.unlock();
374 return mParent->saveSettings();
375}
376
377// public methods only for internal purposes
378/////////////////////////////////////////////////////////////////////////////
379
380HRESULT SystemProperties::loadSettings (CFGNODE aGlobal)
381{
382 AutoLock lock (this);
383 CHECK_READY();
384
385 ComAssertRet (aGlobal, E_FAIL);
386
387 CFGNODE properties = NULL;
388 CFGLDRGetChildNode (aGlobal, "SystemProperties", 0, &properties);
389 ComAssertRet (properties, E_FAIL);
390
391 HRESULT rc = E_FAIL;
392
393 do
394 {
395 Bstr bstr;
396
397 CFGLDRQueryBSTR (properties, "defaultVDIFolder",
398 bstr.asOutParam());
399 rc = setDefaultVDIFolder (bstr);
400 if (FAILED (rc))
401 break;
402
403 CFGLDRQueryBSTR (properties, "defaultMachineFolder",
404 bstr.asOutParam());
405 rc = setDefaultMachineFolder (bstr);
406 if (FAILED (rc))
407 break;
408
409 CFGLDRQueryBSTR (properties, "remoteDisplayAuthLibrary",
410 bstr.asOutParam());
411 rc = setRemoteDisplayAuthLibrary (bstr);
412 if (FAILED (rc))
413 break;
414
415 CFGLDRQueryBSTR (properties, "webServiceAuthLibrary",
416 bstr.asOutParam());
417 rc = setWebServiceAuthLibrary (bstr);
418 if (FAILED (rc))
419 break;
420
421 CFGLDRQueryBool (properties, "HWVirtExEnabled", (bool*)&mHWVirtExEnabled);
422
423 uint32_t u32Count = 3;
424 CFGLDRQueryUInt32 (properties, "LogHistoryCount", &u32Count);
425 mLogHistoryCount = u32Count;
426 }
427 while (0);
428
429 CFGLDRReleaseNode (properties);
430
431 return rc;
432}
433
434HRESULT SystemProperties::saveSettings (CFGNODE aGlobal)
435{
436 AutoLock lock (this);
437 CHECK_READY();
438
439 ComAssertRet (aGlobal, E_FAIL);
440
441 // first, delete the entry
442 CFGNODE properties = NULL;
443 int vrc = CFGLDRGetChildNode (aGlobal, "SystemProperties", 0, &properties);
444 if (VBOX_SUCCESS (vrc))
445 {
446 vrc = CFGLDRDeleteNode (properties);
447 ComAssertRCRet (vrc, E_FAIL);
448 }
449 // then, recreate it
450 vrc = CFGLDRCreateChildNode (aGlobal, "SystemProperties", &properties);
451 ComAssertRCRet (vrc, E_FAIL);
452
453 if (mDefaultVDIFolder)
454 CFGLDRSetBSTR (properties, "defaultVDIFolder",
455 mDefaultVDIFolder);
456
457 if (mDefaultMachineFolder)
458 CFGLDRSetBSTR (properties, "defaultMachineFolder",
459 mDefaultMachineFolder);
460
461 if (mRemoteDisplayAuthLibrary)
462 CFGLDRSetBSTR (properties, "remoteDisplayAuthLibrary",
463 mRemoteDisplayAuthLibrary);
464
465 if (mWebServiceAuthLibrary)
466 CFGLDRSetBSTR (properties, "webServiceAuthLibrary",
467 mWebServiceAuthLibrary);
468
469 CFGLDRSetBool (properties, "HWVirtExEnabled", !!mHWVirtExEnabled);
470
471 CFGLDRSetUInt32 (properties, "LogHistoryCount", mLogHistoryCount);
472
473 return S_OK;
474}
475
476// private methods
477/////////////////////////////////////////////////////////////////////////////
478
479HRESULT SystemProperties::setDefaultVDIFolder (const BSTR aPath)
480{
481 Utf8Str path;
482 if (aPath && *aPath)
483 path = aPath;
484 else
485 path = "VDI";
486
487 // get the full file name
488 char folder [RTPATH_MAX];
489 int vrc = RTPathAbsEx (mParent->homeDir(), path, folder, sizeof (folder));
490 if (VBOX_FAILURE (vrc))
491 return setError (E_FAIL,
492 tr ("Cannot set the default VDI folder to '%ls' (%Vrc)"),
493 path.raw(), vrc);
494
495 mDefaultVDIFolder = path;
496 mDefaultVDIFolderFull = folder;
497
498 return S_OK;
499}
500
501HRESULT SystemProperties::setDefaultMachineFolder (const BSTR aPath)
502{
503 Utf8Str path;
504 if (aPath && *aPath)
505 path = aPath;
506 else
507 path = "Machines";
508
509 // get the full file name
510 char folder [RTPATH_MAX];
511 int vrc = RTPathAbsEx (mParent->homeDir(), path, folder, sizeof (folder));
512 if (VBOX_FAILURE (vrc))
513 return setError (E_FAIL,
514 tr ("Cannot set the default machines folder to '%ls' (%Vrc)"),
515 path.raw(), vrc);
516
517 mDefaultMachineFolder = path;
518 mDefaultMachineFolderFull = folder;
519
520 return S_OK;
521}
522
523HRESULT SystemProperties::setRemoteDisplayAuthLibrary (const BSTR aPath)
524{
525 Utf8Str path;
526 if (aPath && *aPath)
527 path = aPath;
528 else
529 path = "VRDPAuth";
530
531 mRemoteDisplayAuthLibrary = path;
532
533 return S_OK;
534}
535
536HRESULT SystemProperties::setWebServiceAuthLibrary (const BSTR aPath)
537{
538 Utf8Str path;
539 if (aPath && *aPath)
540 path = aPath;
541 else
542 path = "VRDPAuth";
543
544 mWebServiceAuthLibrary = path;
545
546 return S_OK;
547}
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