1 |
|
---|
2 | /* $Id: GuestSessionImpl.h 42673 2012-08-08 08:07:09Z vboxsync $ */
|
---|
3 | /** @file
|
---|
4 | * VirtualBox Main - XXX.
|
---|
5 | */
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Copyright (C) 2012 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 |
|
---|
19 | #ifndef ____H_GUESTSESSIONIMPL
|
---|
20 | #define ____H_GUESTSESSIONIMPL
|
---|
21 |
|
---|
22 | #include "VirtualBoxBase.h"
|
---|
23 |
|
---|
24 | #include "GuestCtrlImplPrivate.h"
|
---|
25 | #include "GuestProcessImpl.h"
|
---|
26 | #include "GuestDirectoryImpl.h"
|
---|
27 | #include "GuestFileImpl.h"
|
---|
28 | #include "GuestFsObjInfoImpl.h"
|
---|
29 |
|
---|
30 | class Guest;
|
---|
31 |
|
---|
32 | /**
|
---|
33 | * Abstract base class for a lenghtly per-session operation which
|
---|
34 | * runs in a Main worker thread.
|
---|
35 | */
|
---|
36 | class GuestSessionTask
|
---|
37 | {
|
---|
38 | public:
|
---|
39 |
|
---|
40 | GuestSessionTask(GuestSession *pSession);
|
---|
41 |
|
---|
42 | virtual ~GuestSessionTask(void);
|
---|
43 |
|
---|
44 | public:
|
---|
45 |
|
---|
46 | virtual int Run(void) = 0;
|
---|
47 | virtual int RunAsync(const Utf8Str &strDesc, ComObjPtr<Progress> &pProgress) = 0;
|
---|
48 |
|
---|
49 | int setProgress(ULONG uPercent);
|
---|
50 | int setProgressSuccess(void);
|
---|
51 | int setProgressErrorMsg(HRESULT hr, const Utf8Str &strMsg);
|
---|
52 |
|
---|
53 | protected:
|
---|
54 |
|
---|
55 | Utf8Str mDesc;
|
---|
56 | GuestSession *mSession;
|
---|
57 | /** Progress object for getting updated when running
|
---|
58 | * asynchronously. Optional. */
|
---|
59 | ComObjPtr<Progress> mProgress;
|
---|
60 | };
|
---|
61 |
|
---|
62 | /**
|
---|
63 | * Task for copying files from host to the guest.
|
---|
64 | */
|
---|
65 | class SessionTaskCopyTo : public GuestSessionTask
|
---|
66 | {
|
---|
67 | public:
|
---|
68 |
|
---|
69 | SessionTaskCopyTo(GuestSession *pSession,
|
---|
70 | const Utf8Str &strSource, const Utf8Str &strDest, uint32_t uFlags);
|
---|
71 |
|
---|
72 | virtual ~SessionTaskCopyTo(void);
|
---|
73 |
|
---|
74 | public:
|
---|
75 |
|
---|
76 | int Run(void);
|
---|
77 | int RunAsync(const Utf8Str &strDesc, ComObjPtr<Progress> &pProgress);
|
---|
78 | static int taskThread(RTTHREAD Thread, void *pvUser);
|
---|
79 |
|
---|
80 | protected:
|
---|
81 |
|
---|
82 | Utf8Str mSource;
|
---|
83 | Utf8Str mDest;
|
---|
84 | uint32_t mCopyFileFlags;
|
---|
85 | };
|
---|
86 |
|
---|
87 | /**
|
---|
88 | * Task for copying files from guest to the host.
|
---|
89 | */
|
---|
90 | class SessionTaskCopyFrom : public GuestSessionTask
|
---|
91 | {
|
---|
92 | public:
|
---|
93 |
|
---|
94 | SessionTaskCopyFrom(GuestSession *pSession,
|
---|
95 | const Utf8Str &strSource, const Utf8Str &strDest, uint32_t uFlags);
|
---|
96 |
|
---|
97 | virtual ~SessionTaskCopyFrom(void);
|
---|
98 |
|
---|
99 | public:
|
---|
100 |
|
---|
101 | int Run(void);
|
---|
102 | int RunAsync(const Utf8Str &strDesc, ComObjPtr<Progress> &pProgress);
|
---|
103 | static int taskThread(RTTHREAD Thread, void *pvUser);
|
---|
104 |
|
---|
105 | protected:
|
---|
106 |
|
---|
107 | Utf8Str mSource;
|
---|
108 | Utf8Str mDest;
|
---|
109 | uint32_t mFlags;
|
---|
110 | };
|
---|
111 |
|
---|
112 | /**
|
---|
113 | * Guest session implementation.
|
---|
114 | */
|
---|
115 | class ATL_NO_VTABLE GuestSession :
|
---|
116 | public VirtualBoxBase,
|
---|
117 | VBOX_SCRIPTABLE_IMPL(IGuestSession)
|
---|
118 | {
|
---|
119 | public:
|
---|
120 | /** @name COM and internal init/term/mapping cruft.
|
---|
121 | * @{ */
|
---|
122 | VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(GuestSession, IGuestSession)
|
---|
123 | DECLARE_NOT_AGGREGATABLE(GuestSession)
|
---|
124 | DECLARE_PROTECT_FINAL_CONSTRUCT()
|
---|
125 | BEGIN_COM_MAP(GuestSession)
|
---|
126 | VBOX_DEFAULT_INTERFACE_ENTRIES(IGuestSession)
|
---|
127 | END_COM_MAP()
|
---|
128 | DECLARE_EMPTY_CTOR_DTOR(GuestSession)
|
---|
129 |
|
---|
130 | int init(Guest *aGuest, ULONG aSessionID, Utf8Str aUser, Utf8Str aPassword, Utf8Str aDomain, Utf8Str aName);
|
---|
131 | void uninit(void);
|
---|
132 | HRESULT FinalConstruct(void);
|
---|
133 | void FinalRelease(void);
|
---|
134 | /** @} */
|
---|
135 |
|
---|
136 | /** @name IGuestSession properties.
|
---|
137 | * @{ */
|
---|
138 | STDMETHOD(COMGETTER(User))(BSTR *aName);
|
---|
139 | STDMETHOD(COMGETTER(Domain))(BSTR *aDomain);
|
---|
140 | STDMETHOD(COMGETTER(Name))(BSTR *aName);
|
---|
141 | STDMETHOD(COMGETTER(Id))(ULONG *aId);
|
---|
142 | STDMETHOD(COMGETTER(Timeout))(ULONG *aTimeout);
|
---|
143 | STDMETHOD(COMSETTER(Timeout))(ULONG aTimeout);
|
---|
144 | STDMETHOD(COMGETTER(Environment))(ComSafeArrayOut(BSTR, aEnvironment));
|
---|
145 | STDMETHOD(COMSETTER(Environment))(ComSafeArrayIn(IN_BSTR, aEnvironment));
|
---|
146 | STDMETHOD(COMGETTER(Processes))(ComSafeArrayOut(IGuestProcess *, aProcesses));
|
---|
147 | STDMETHOD(COMGETTER(Directories))(ComSafeArrayOut(IGuestDirectory *, aDirectories));
|
---|
148 | STDMETHOD(COMGETTER(Files))(ComSafeArrayOut(IGuestFile *, aFiles));
|
---|
149 | /** @} */
|
---|
150 |
|
---|
151 | /** @name IGuestSession methods.
|
---|
152 | * @{ */
|
---|
153 | STDMETHOD(Close)(void);
|
---|
154 | STDMETHOD(CopyFrom)(IN_BSTR aSource, IN_BSTR aDest, ComSafeArrayIn(CopyFileFlag_T, aFlags), IProgress **aProgress);
|
---|
155 | STDMETHOD(CopyTo)(IN_BSTR aSource, IN_BSTR aDest, ComSafeArrayIn(CopyFileFlag_T, aFlags), IProgress **aProgress);
|
---|
156 | STDMETHOD(DirectoryCreate)(IN_BSTR aPath, ULONG aMode, ComSafeArrayIn(DirectoryCreateFlag_T, aFlags), IGuestDirectory **aDirectory);
|
---|
157 | STDMETHOD(DirectoryCreateTemp)(IN_BSTR aTemplate, ULONG aMode, IN_BSTR aName, IGuestDirectory **aDirectory);
|
---|
158 | STDMETHOD(DirectoryExists)(IN_BSTR aPath, BOOL *aExists);
|
---|
159 | STDMETHOD(DirectoryOpen)(IN_BSTR aPath, IN_BSTR aFilter, ComSafeArrayIn(DirectoryOpenFlag_T, aFlags), IGuestDirectory **aDirectory);
|
---|
160 | STDMETHOD(DirectoryQueryInfo)(IN_BSTR aPath, IGuestFsObjInfo **aInfo);
|
---|
161 | STDMETHOD(DirectoryRemove)(IN_BSTR aPath);
|
---|
162 | STDMETHOD(DirectoryRemoveRecursive)(IN_BSTR aPath, ComSafeArrayIn(DirectoryRemoveRecFlag_T, aFlags), IProgress **aProgress);
|
---|
163 | STDMETHOD(DirectoryRename)(IN_BSTR aSource, IN_BSTR aDest, ComSafeArrayIn(PathRenameFlag_T, aFlags));
|
---|
164 | STDMETHOD(DirectorySetACL)(IN_BSTR aPath, IN_BSTR aACL);
|
---|
165 | STDMETHOD(EnvironmentClear)(void);
|
---|
166 | STDMETHOD(EnvironmentGet)(IN_BSTR aName, BSTR *aValue);
|
---|
167 | STDMETHOD(EnvironmentSet)(IN_BSTR aName, IN_BSTR aValue);
|
---|
168 | STDMETHOD(EnvironmentUnset)(IN_BSTR aName);
|
---|
169 | STDMETHOD(FileCreateTemp)(IN_BSTR aTemplate, ULONG aMode, IN_BSTR aName, IGuestFile **aFile);
|
---|
170 | STDMETHOD(FileExists)(IN_BSTR aPath, BOOL *aExists);
|
---|
171 | STDMETHOD(FileRemove)(IN_BSTR aPath);
|
---|
172 | STDMETHOD(FileOpen)(IN_BSTR aPath, IN_BSTR aOpenMode, IN_BSTR aDisposition, ULONG aCreationMode, LONG64 aOffset, IGuestFile **aFile);
|
---|
173 | STDMETHOD(FileQueryInfo)(IN_BSTR aPath, IGuestFsObjInfo **aInfo);
|
---|
174 | STDMETHOD(FileQuerySize)(IN_BSTR aPath, LONG64 *aSize);
|
---|
175 | STDMETHOD(FileRename)(IN_BSTR aSource, IN_BSTR aDest, ComSafeArrayIn(PathRenameFlag_T, aFlags));
|
---|
176 | STDMETHOD(FileSetACL)(IN_BSTR aPath, IN_BSTR aACL);
|
---|
177 | STDMETHOD(ProcessCreate)(IN_BSTR aCommand, ComSafeArrayIn(IN_BSTR, aArguments), ComSafeArrayIn(IN_BSTR, aEnvironment),
|
---|
178 | ComSafeArrayIn(ProcessCreateFlag_T, aFlags), ULONG aTimeoutMS, IGuestProcess **aProcess);
|
---|
179 | STDMETHOD(ProcessCreateEx)(IN_BSTR aCommand, ComSafeArrayIn(IN_BSTR, aArguments), ComSafeArrayIn(IN_BSTR, aEnvironment),
|
---|
180 | ComSafeArrayIn(ProcessCreateFlag_T, aFlags), ULONG aTimeoutMS,
|
---|
181 | ProcessPriority_T aPriority, ComSafeArrayIn(LONG, aAffinity),
|
---|
182 | IGuestProcess **aProcess);
|
---|
183 | STDMETHOD(ProcessGet)(ULONG aPID, IGuestProcess **aProcess);
|
---|
184 | #if 0
|
---|
185 | STDMETHOD(SetTimeout)(ULONG aTimeoutMS);
|
---|
186 | #endif
|
---|
187 | STDMETHOD(SymlinkCreate)(IN_BSTR aSource, IN_BSTR aTarget, SymlinkType_T aType);
|
---|
188 | STDMETHOD(SymlinkExists)(IN_BSTR aSymlink, BOOL *aExists);
|
---|
189 | STDMETHOD(SymlinkRead)(IN_BSTR aSymlink, ComSafeArrayIn(SymlinkReadFlag_T, aFlags), BSTR *aTarget);
|
---|
190 | STDMETHOD(SymlinkRemoveDirectory)(IN_BSTR aPath);
|
---|
191 | STDMETHOD(SymlinkRemoveFile)(IN_BSTR aFile);
|
---|
192 | /** @} */
|
---|
193 |
|
---|
194 | private:
|
---|
195 |
|
---|
196 | typedef std::vector <ComObjPtr<GuestDirectory> > SessionDirectories;
|
---|
197 | typedef std::vector <ComObjPtr<GuestFile> > SessionFiles;
|
---|
198 | /** Map of guest processes. The key specifies the internal process number.
|
---|
199 | * To retrieve the process' guest PID use the Id() method of the IProcess interface. */
|
---|
200 | typedef std::map <uint32_t, ComObjPtr<GuestProcess> > SessionProcesses;
|
---|
201 |
|
---|
202 | public:
|
---|
203 | /** @name Public internal methods.
|
---|
204 | * @{ */
|
---|
205 | int directoryClose(ComObjPtr<GuestDirectory> pDirectory);
|
---|
206 | int directoryCreateInternal(const Utf8Str &strPath, uint32_t uMode, uint32_t uFlags, ComObjPtr<GuestDirectory> &pDirectory);
|
---|
207 | int directoryOpenInternal(const Utf8Str &strPath, const Utf8Str &strFilter, uint32_t uFlags, ComObjPtr<GuestDirectory> &pDirectory);
|
---|
208 | int dispatchToProcess(uint32_t uContextID, uint32_t uFunction, void *pvData, size_t cbData);
|
---|
209 | int fileClose(ComObjPtr<GuestFile> pFile);
|
---|
210 | int fileOpenInternal(const Utf8Str &strPath, const Utf8Str &strOpenMode, const Utf8Str &strDisposition,
|
---|
211 | uint32_t uCreationMode, int64_t iOffset, ComObjPtr<GuestFile> &pFile);
|
---|
212 | int fileQueryInfoInternal(const Utf8Str &strPath, GuestFsObjData &objData);
|
---|
213 | int fileQuerySizeInternal(const Utf8Str &strPath, int64_t *pllSize);
|
---|
214 | const GuestCredentials &getCredentials(void);
|
---|
215 | const GuestEnvironment &getEnvironment(void);
|
---|
216 | Utf8Str getName(void);
|
---|
217 | uint32_t getProtocolVersion(void) { return mData.mProtocolVersion; }
|
---|
218 | int processClose(ComObjPtr<GuestProcess> pProcess);
|
---|
219 | int processCreateExInteral(GuestProcessStartupInfo &procInfo, ComObjPtr<GuestProcess> &pProgress);
|
---|
220 | inline bool processExists(uint32_t uProcessID, ComObjPtr<GuestProcess> *pProcess);
|
---|
221 | inline int processGetByPID(ULONG uPID, ComObjPtr<GuestProcess> *pProcess);
|
---|
222 | int startTaskAsync(const Utf8Str &strTaskDesc, GuestSessionTask *pTask, ComObjPtr<Progress> &pProgress);
|
---|
223 | int queryInfo(void);
|
---|
224 | /** @} */
|
---|
225 |
|
---|
226 | private:
|
---|
227 |
|
---|
228 | struct Data
|
---|
229 | {
|
---|
230 | /** Guest control protocol version to be used.
|
---|
231 | * Guest Additions < VBox 4.2 have version 1,
|
---|
232 | * any newer version will have version 2. */
|
---|
233 | uint32_t mProtocolVersion;
|
---|
234 | /** Flag indicating if this is an internal session
|
---|
235 | * or not. Internal session are not accessible by clients. */
|
---|
236 | bool fInternal;
|
---|
237 | /** Pointer to the parent (Guest). */
|
---|
238 | Guest *mParent;
|
---|
239 | /** The session credentials. */
|
---|
240 | GuestCredentials mCredentials;
|
---|
241 | /** The (optional) session name. */
|
---|
242 | Utf8Str mName;
|
---|
243 | /** The session ID. */
|
---|
244 | ULONG mId;
|
---|
245 | /** The session timeout. Default is 30s. */
|
---|
246 | ULONG mTimeout;
|
---|
247 | /** The session's environment block. Can be
|
---|
248 | * overwritten/extended by ProcessCreate(Ex). */
|
---|
249 | GuestEnvironment mEnvironment;
|
---|
250 | /** Directory objects bound to this session. */
|
---|
251 | SessionDirectories mDirectories;
|
---|
252 | /** File objects bound to this session. */
|
---|
253 | SessionFiles mFiles;
|
---|
254 | /** Process objects bound to this session. */
|
---|
255 | SessionProcesses mProcesses;
|
---|
256 | } mData;
|
---|
257 | };
|
---|
258 |
|
---|
259 | #endif /* !____H_GUESTSESSIONIMPL */
|
---|
260 |
|
---|