1 | /* $Id: VirtualBoxSDSImpl.h 69785 2017-11-20 20:18:32Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Global COM Class definition
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2015-2017 Oracle Corporation
|
---|
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 (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | #ifndef ____H_VIRTUALBOXSDSIMPL
|
---|
19 | #define ____H_VIRTUALBOXSDSIMPL
|
---|
20 |
|
---|
21 | #include "VirtualBoxBase.h"
|
---|
22 |
|
---|
23 |
|
---|
24 | /**
|
---|
25 | * Per user data.
|
---|
26 | */
|
---|
27 | class VBoxSDSPerUserData
|
---|
28 | {
|
---|
29 | public:
|
---|
30 | /** The SID (secure identifier) for the user. This is the key. */
|
---|
31 | com::Utf8Str m_strUserSid;
|
---|
32 | /** The user name (if we could get it). */
|
---|
33 | com::Utf8Str m_strUsername;
|
---|
34 | /** The VBoxSVC chosen to instantiate CLSID_VirtualBox.
|
---|
35 | * This is NULL if not set. */
|
---|
36 | ComPtr<IVBoxSVCRegistration> m_ptrTheChosenOne;
|
---|
37 | /** Critical section protecting everything here. */
|
---|
38 | RTCRITSECT m_Lock;
|
---|
39 |
|
---|
40 |
|
---|
41 | public:
|
---|
42 | VBoxSDSPerUserData(com::Utf8Str const &a_rStrUserSid, com::Utf8Str const &a_rStrUsername)
|
---|
43 | : m_strUserSid(a_rStrUserSid), m_strUsername(a_rStrUsername)
|
---|
44 | {
|
---|
45 | RTCritSectInit(&m_Lock);
|
---|
46 | }
|
---|
47 |
|
---|
48 | ~VBoxSDSPerUserData()
|
---|
49 | {
|
---|
50 | RTCritSectDelete(&m_Lock);
|
---|
51 | }
|
---|
52 |
|
---|
53 | void i_lock()
|
---|
54 | {
|
---|
55 | RTCritSectEnter(&m_Lock);
|
---|
56 | }
|
---|
57 |
|
---|
58 | void i_unlock()
|
---|
59 | {
|
---|
60 | RTCritSectLeave(&m_Lock);
|
---|
61 | }
|
---|
62 | };
|
---|
63 |
|
---|
64 |
|
---|
65 | /**
|
---|
66 | * The IVirtualBoxSDS implementation.
|
---|
67 | *
|
---|
68 | * This class helps different VBoxSVC processes make sure a user only have a
|
---|
69 | * single VirtualBox instance.
|
---|
70 | *
|
---|
71 | * @note This is a simple internal class living in a privileged process. So, we
|
---|
72 | * do not use the API wrappers as they add complexity. In particular,
|
---|
73 | * they add the auto caller logic, which is an excellent tool to create
|
---|
74 | * unkillable processes. If an API method during development or product
|
---|
75 | * for instance triggers an NT exception like STATUS_ACCESS_VIOLATION, the
|
---|
76 | * caller will be unwound without releasing the caller. When uninit is
|
---|
77 | * called during COM shutdown/whatever, the thread gets stuck waiting for
|
---|
78 | * the long gone caller and cannot be killed (Windows 10, build 16299),
|
---|
79 | * requiring a reboot to continue.
|
---|
80 | *
|
---|
81 | * @todo Would be very nice to get rid of the ATL cruft too here.
|
---|
82 | */
|
---|
83 | class VirtualBoxSDS
|
---|
84 | : public IVirtualBoxSDS
|
---|
85 | , public ATL::CComObjectRootEx<ATL::CComMultiThreadModel>
|
---|
86 | , public ATL::CComCoClass<VirtualBoxSDS, &CLSID_VirtualBoxSDS>
|
---|
87 | {
|
---|
88 | private:
|
---|
89 | typedef std::map<com::Utf8Str, VBoxSDSPerUserData *> UserDataMap_T;
|
---|
90 | /** Per user data map (key is SID string). */
|
---|
91 | UserDataMap_T m_UserDataMap;
|
---|
92 | /** Lock protecting m_UserDataMap.*/
|
---|
93 | RTCRITSECTRW m_MapCritSect;
|
---|
94 |
|
---|
95 | public:
|
---|
96 | DECLARE_CLASSFACTORY_SINGLETON(VirtualBoxSDS)
|
---|
97 | DECLARE_NOT_AGGREGATABLE(VirtualBoxSDS)
|
---|
98 | DECLARE_PROTECT_FINAL_CONSTRUCT()
|
---|
99 |
|
---|
100 | BEGIN_COM_MAP(VirtualBoxSDS)
|
---|
101 | COM_INTERFACE_ENTRY(IVirtualBoxSDS)
|
---|
102 | END_COM_MAP()
|
---|
103 |
|
---|
104 | DECLARE_EMPTY_CTOR_DTOR(VirtualBoxSDS)
|
---|
105 |
|
---|
106 | HRESULT FinalConstruct();
|
---|
107 | void FinalRelease();
|
---|
108 |
|
---|
109 | private:
|
---|
110 |
|
---|
111 | // IVirtualBoxSDS methods
|
---|
112 | HRESULT RegisterVBoxSVC(IVBoxSVCRegistration *aVBoxSVC, LONG aPid, IUnknown **aExistingVirtualBox);
|
---|
113 | HRESULT DeregisterVBoxSVC(IVBoxSVCRegistration *aVBoxSVC, LONG aPid);
|
---|
114 |
|
---|
115 |
|
---|
116 | // Private methods
|
---|
117 |
|
---|
118 | /**
|
---|
119 | * Gets the client user SID of the
|
---|
120 | */
|
---|
121 | static bool i_getClientUserSid(com::Utf8Str *a_pStrSid, com::Utf8Str *a_pStrUsername);
|
---|
122 |
|
---|
123 | /**
|
---|
124 | * Looks up the given user.
|
---|
125 | *
|
---|
126 | * @returns Pointer to the LOCKED per user data. NULL if not found.
|
---|
127 | * @param a_rStrUserSid The user SID.
|
---|
128 | */
|
---|
129 | VBoxSDSPerUserData *i_lookupPerUserData(com::Utf8Str const &a_rStrUserSid);
|
---|
130 |
|
---|
131 | /**
|
---|
132 | * Looks up the given user, creating it if not found
|
---|
133 | *
|
---|
134 | * @returns Pointer to the LOCKED per user data. NULL on allocation error.
|
---|
135 | * @param a_rStrUserSid The user SID.
|
---|
136 | * @param a_rStrUsername The user name if available.
|
---|
137 | */
|
---|
138 | VBoxSDSPerUserData *i_lookupOrCreatePerUserData(com::Utf8Str const &a_rStrUserSid, com::Utf8Str const &a_rStrUsername);
|
---|
139 | };
|
---|
140 |
|
---|
141 |
|
---|
142 | #endif // !____H_VIRTUALBOXSDSIMPL
|
---|
143 | /* vi: set tabstop=4 shiftwidth=4 expandtab: */
|
---|