VirtualBox

source: vbox/trunk/src/VBox/Main/include/VirtualBoxSDSImpl.h@ 69775

Last change on this file since 69775 was 69775, checked in by vboxsync, 7 years ago

VBoxSDS/Plan/B: More complete code.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.0 KB
Line 
1/* $Id: VirtualBoxSDSImpl.h 69775 2017-11-20 16:36:34Z 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 "VirtualBoxSDSWrap.h"
22#include "TokenWrap.h"
23
24#ifdef RT_OS_WINDOWS
25# include "win/resource.h"
26#endif
27
28 /**
29 * The MediumLockToken class automates cleanup of a Medium lock.
30 */
31class ATL_NO_VTABLE VirtualBoxToken :
32 public TokenWrap
33{
34public:
35
36 DECLARE_EMPTY_CTOR_DTOR(VirtualBoxToken)
37
38 HRESULT FinalConstruct();
39 void FinalRelease();
40
41 // public initializer/uninitializer for internal purposes only
42 HRESULT init(const std::wstring& wstrUserName);
43 void uninit();
44
45 /**
46 * Fabrique method to create and initialize COM token object.
47 *
48 * @param aToken Pointer to result Token COM object.
49 * @param wstrUserName User name of client for that we create the token
50 */
51 static HRESULT CreateToken(ComPtr<IToken>& aToken, const std::wstring& wstrUserName);
52
53 // Trace COM reference counting in debug mode
54#ifdef RT_STRICT
55 virtual ULONG InternalAddRef();
56 virtual ULONG InternalRelease();
57#endif
58
59private:
60
61 // wrapped IToken methods
62 HRESULT abandon(AutoCaller &aAutoCaller);
63 HRESULT dummy();
64
65 // data
66 struct Data
67 {
68 std::wstring wstrUserName;
69 };
70
71 Data m;
72};
73
74#ifdef VBOX_WITH_SDS_PLAN_B
75/**
76 * Per user data.
77 */
78class VBoxSDSPerUserData
79{
80public:
81 /** The SID (secure identifier) for the user. This is the key. */
82 com::Utf8Str m_strUserSid;
83 /** The user name (if we could get it). */
84 com::Utf8Str m_strUsername;
85 /** The VBoxSVC chosen to instantiate CLSID_VirtualBox.
86 * This is NULL if not set. */
87 ComPtr<IVBoxSVCRegistration> m_ptrTheChosenOne;
88 /** Critical section protecting everything here. */
89 RTCRITSECT m_Lock;
90
91
92public:
93 VBoxSDSPerUserData(com::Utf8Str const &a_rStrUserSid, com::Utf8Str const &a_rStrUsername)
94 : m_strUserSid(a_rStrUserSid), m_strUsername(a_rStrUsername)
95 {
96 RTCritSectInit(&m_Lock);
97 }
98
99 ~VBoxSDSPerUserData()
100 {
101 RTCritSectDelete(&m_Lock);
102 }
103
104 void i_lock()
105 {
106 RTCritSectEnter(&m_Lock);
107 }
108
109 void i_unlock()
110 {
111 RTCritSectLeave(&m_Lock);
112 }
113};
114#endif
115
116
117class ATL_NO_VTABLE VirtualBoxSDS :
118 public VirtualBoxSDSWrap
119#ifdef RT_OS_WINDOWS
120 , public ATL::CComCoClass<VirtualBoxSDS, &CLSID_VirtualBoxSDS>
121#endif
122{
123#ifdef VBOX_WITH_SDS_PLAN_B
124private:
125 typedef std::map<com::Utf8Str, VBoxSDSPerUserData *> UserDataMap_T;
126 /** Per user data map (key is SID string). */
127 UserDataMap_T m_UserDataMap;
128 /** Lock protecting m_UserDataMap.*/
129 RTCRITSECTRW m_MapCritSect;
130#endif
131
132public:
133
134 DECLARE_CLASSFACTORY_SINGLETON(VirtualBoxSDS)
135
136 //DECLARE_REGISTRY_RESOURCEID(IDR_VIRTUALBOX)
137
138 // Kind of redundant (VirtualBoxSDSWrap declares itself not aggregatable
139 // and CComCoClass<VirtualBoxSDS, &CLSID_VirtualBoxSDS> as aggregatable,
140 // the former is the first inheritance), but the C multiple inheritance
141 // rules and the class factory in VBoxSDS.cpp needs this to disambiguate.
142 DECLARE_NOT_AGGREGATABLE(VirtualBoxSDS)
143
144 DECLARE_EMPTY_CTOR_DTOR(VirtualBoxSDS)
145
146 HRESULT FinalConstruct();
147 void FinalRelease();
148
149 // public initializers/uninitializers for internal purposes only
150 HRESULT init();
151 void uninit();
152
153private:
154
155 // Wrapped IVirtualBoxSDS properties
156
157 /**
158 * Returns the instance of VirtualBox for client.
159 * It impersonates client and returns his VirtualBox instance
160 * either from cahce or makes new one.
161 */
162 HRESULT getVirtualBox(ComPtr<IVirtualBox> &aVirtualBox, ComPtr<IToken> &aToken);
163
164 /* SDS plan B interfaces: */
165 HRESULT registerVBoxSVC(const ComPtr<IVBoxSVCRegistration> &aVBoxSVC, LONG aPid, ComPtr<IUnknown> &aExistingVirtualBox);
166 HRESULT deregisterVBoxSVC(const ComPtr<IVBoxSVCRegistration> &aVBoxSVC, LONG aPid);
167
168 // Wrapped IVirtualBoxSDS methods
169
170 // Private methods
171
172 /**
173 * Gets the cliedt user SID of the
174 */
175 static bool i_getClientUserSID(com::Utf8Str *a_pStrSid, com::Utf8Str *a_pStrUsername);
176
177#ifdef VBOX_WITH_SDS_PLAN_B
178 /**
179 * Looks up the given user.
180 *
181 * @returns Pointer to the LOCKED per user data. NULL if not found.
182 * @param a_rStrUserSid The user SID.
183 */
184 VBoxSDSPerUserData *i_lookupPerUserData(com::Utf8Str const &a_rUserSid);
185
186 /**
187 * Looks up the given user, creating it if not found
188 *
189 * @returns Pointer to the LOCKED per user data. NULL on allocation error.
190 * @param a_rStrUserSid The user SID.
191 * @param a_rStrUsername The user name if available.
192 */
193 VBoxSDSPerUserData *i_lookupOrCreatePerUserData(com::Utf8Str const &a_rStrUserSid, com::Utf8Str const &a_rStrUsername);
194
195#else
196 /**
197 * Gets the current user name of current thread
198 */
199 int GetCurrentUserName(std::wstring& wstrUserName);
200
201 /**
202 * Prints current user name of this thread to the log
203 * @param prefix string fragment that will be inserted at the beginning
204 * of the logging line
205 */
206 void LogUserName(char *prefix);
207
208 /**
209 * Thread that periodically checks items in cache and cleans obsolete items
210 */
211 static DWORD WINAPI CheckCacheThread(LPVOID);
212
213 // data fields
214 class VirtualBoxCache;
215 static VirtualBoxCache m_cache;
216 friend VirtualBoxToken;
217#endif
218};
219
220
221#endif // !____H_VIRTUALBOXSDSIMPL
222/* vi: set tabstop=4 shiftwidth=4 expandtab: */
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