VirtualBox

source: vbox/trunk/src/VBox/Main/include/GuestCtrlImplPrivate.h@ 98846

Last change on this file since 98846 was 98816, checked in by vboxsync, 22 months ago

Guest Control: Added GuestFsObjData::FromGuestDirEntryEx(). bugref:9783

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 50.1 KB
Line 
1/* $Id: GuestCtrlImplPrivate.h 98816 2023-03-02 13:02:15Z vboxsync $ */
2/** @file
3 * Internal helpers/structures for guest control functionality.
4 */
5
6/*
7 * Copyright (C) 2011-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28#ifndef MAIN_INCLUDED_GuestCtrlImplPrivate_h
29#define MAIN_INCLUDED_GuestCtrlImplPrivate_h
30#ifndef RT_WITHOUT_PRAGMA_ONCE
31# pragma once
32#endif
33
34#include "ConsoleImpl.h"
35#include "Global.h"
36
37#include <iprt/asm.h>
38#include <iprt/env.h>
39#include <iprt/semaphore.h>
40#include <iprt/cpp/utils.h>
41
42#include <VBox/com/com.h>
43#include <VBox/com/ErrorInfo.h>
44#include <VBox/com/string.h>
45#include <VBox/com/VirtualBox.h>
46#include <VBox/err.h> /* VERR_GSTCTL_GUEST_ERROR */
47
48#include <map>
49#include <vector>
50
51using namespace com;
52
53#ifdef VBOX_WITH_GUEST_CONTROL
54# include <VBox/GuestHost/GuestControl.h>
55# include <VBox/HostServices/GuestControlSvc.h>
56using namespace guestControl;
57#endif
58
59/** Vector holding a process' CPU affinity. */
60typedef std::vector<LONG> ProcessAffinity;
61/** Vector holding process startup arguments. */
62typedef std::vector<Utf8Str> ProcessArguments;
63
64class GuestToolboxStreamBlock;
65class GuestSession;
66
67
68/**
69 * Simple structure mantaining guest credentials.
70 */
71struct GuestCredentials
72{
73 Utf8Str mUser;
74 Utf8Str mPassword;
75 Utf8Str mDomain;
76};
77
78
79/**
80 * Wrapper around the RTEnv API, unusable base class.
81 *
82 * @remarks Feel free to elevate this class to iprt/cpp/env.h as RTCEnv.
83 */
84class GuestEnvironmentBase
85{
86public:
87 /**
88 * Default constructor.
89 *
90 * The user must invoke one of the init methods before using the object.
91 */
92 GuestEnvironmentBase(void)
93 : m_hEnv(NIL_RTENV)
94 , m_cRefs(1)
95 , m_fFlags(0)
96 { }
97
98 /**
99 * Destructor.
100 */
101 virtual ~GuestEnvironmentBase(void)
102 {
103 Assert(m_cRefs <= 1);
104 int vrc = RTEnvDestroy(m_hEnv); AssertRC(vrc);
105 m_hEnv = NIL_RTENV;
106 }
107
108 /**
109 * Retains a reference to this object.
110 * @returns New reference count.
111 * @remarks Sharing an object is currently only safe if no changes are made to
112 * it because RTENV does not yet implement any locking. For the only
113 * purpose we need this, implementing IGuestProcess::environment by
114 * using IGuestSession::environmentBase, that's fine as the session
115 * base environment is immutable.
116 */
117 uint32_t retain(void)
118 {
119 uint32_t cRefs = ASMAtomicIncU32(&m_cRefs);
120 Assert(cRefs > 1); Assert(cRefs < _1M);
121 return cRefs;
122
123 }
124 /** Useful shortcut. */
125 uint32_t retainConst(void) const { return unconst(this)->retain(); }
126
127 /**
128 * Releases a reference to this object, deleting the object when reaching zero.
129 * @returns New reference count.
130 */
131 uint32_t release(void)
132 {
133 uint32_t cRefs = ASMAtomicDecU32(&m_cRefs);
134 Assert(cRefs < _1M);
135 if (cRefs == 0)
136 delete this;
137 return cRefs;
138 }
139
140 /** Useful shortcut. */
141 uint32_t releaseConst(void) const { return unconst(this)->retain(); }
142
143 /**
144 * Checks if the environment has been successfully initialized or not.
145 *
146 * @returns @c true if initialized, @c false if not.
147 */
148 bool isInitialized(void) const
149 {
150 return m_hEnv != NIL_RTENV;
151 }
152
153 /**
154 * Returns the variable count.
155 * @return Number of variables.
156 * @sa RTEnvCountEx
157 */
158 uint32_t count(void) const
159 {
160 return RTEnvCountEx(m_hEnv);
161 }
162
163 /**
164 * Deletes the environment change record entirely.
165 *
166 * The count() method will return zero after this call.
167 *
168 * @sa RTEnvReset
169 */
170 void reset(void)
171 {
172 int vrc = RTEnvReset(m_hEnv);
173 AssertRC(vrc);
174 }
175
176 /**
177 * Exports the environment change block as an array of putenv style strings.
178 *
179 *
180 * @returns VINF_SUCCESS or VERR_NO_MEMORY.
181 * @param pArray The output array.
182 */
183 int queryPutEnvArray(std::vector<com::Utf8Str> *pArray) const
184 {
185 uint32_t cVars = RTEnvCountEx(m_hEnv);
186 try
187 {
188 pArray->resize(cVars);
189 for (uint32_t iVar = 0; iVar < cVars; iVar++)
190 {
191 const char *psz = RTEnvGetByIndexRawEx(m_hEnv, iVar);
192 AssertReturn(psz, VERR_INTERNAL_ERROR_3); /* someone is racing us! */
193 (*pArray)[iVar] = psz;
194 }
195 return VINF_SUCCESS;
196 }
197 catch (std::bad_alloc &)
198 {
199 return VERR_NO_MEMORY;
200 }
201 }
202
203 /**
204 * Applies an array of putenv style strings.
205 *
206 * @returns IPRT status code.
207 * @param rArray The array with the putenv style strings.
208 * @param pidxError Where to return the index causing trouble on
209 * failure. Optional.
210 * @sa RTEnvPutEx
211 */
212 int applyPutEnvArray(const std::vector<com::Utf8Str> &rArray, size_t *pidxError = NULL)
213 {
214 size_t const cArray = rArray.size();
215 for (size_t i = 0; i < cArray; i++)
216 {
217 int vrc = RTEnvPutEx(m_hEnv, rArray[i].c_str());
218 if (RT_FAILURE(vrc))
219 {
220 if (pidxError)
221 *pidxError = i;
222 return vrc;
223 }
224 }
225 return VINF_SUCCESS;
226 }
227
228 /**
229 * Applies the changes from another environment to this.
230 *
231 * @returns IPRT status code.
232 * @param rChanges Reference to an environment which variables will be
233 * imported and, if it's a change record, schedule
234 * variable unsets will be applied.
235 * @sa RTEnvApplyChanges
236 */
237 int applyChanges(const GuestEnvironmentBase &rChanges)
238 {
239 return RTEnvApplyChanges(m_hEnv, rChanges.m_hEnv);
240 }
241
242 /**
243 * See RTEnvQueryUtf8Block for details.
244 * @returns IPRT status code.
245 * @param ppszzBlock Where to return the block pointer.
246 * @param pcbBlock Where to optionally return the block size.
247 * @sa RTEnvQueryUtf8Block
248 */
249 int queryUtf8Block(char **ppszzBlock, size_t *pcbBlock)
250 {
251 return RTEnvQueryUtf8Block(m_hEnv, true /*fSorted*/, ppszzBlock, pcbBlock);
252 }
253
254 /**
255 * Frees what queryUtf8Block returned, NULL ignored.
256 * @sa RTEnvFreeUtf8Block
257 */
258 static void freeUtf8Block(char *pszzBlock)
259 {
260 return RTEnvFreeUtf8Block(pszzBlock);
261 }
262
263 /**
264 * Applies a block on the format returned by queryUtf8Block.
265 *
266 * @returns IPRT status code.
267 * @param pszzBlock Pointer to the block.
268 * @param cbBlock The size of the block.
269 * @param fNoEqualMeansUnset Whether the lack of a '=' (equal) sign in a
270 * string means it should be unset (@c true), or if
271 * it means the variable should be defined with an
272 * empty value (@c false, the default).
273 * @todo move this to RTEnv!
274 */
275 int copyUtf8Block(const char *pszzBlock, size_t cbBlock, bool fNoEqualMeansUnset = false)
276 {
277 int vrc = VINF_SUCCESS;
278 while (cbBlock > 0 && *pszzBlock != '\0')
279 {
280 const char *pszEnd = (const char *)memchr(pszzBlock, '\0', cbBlock);
281 if (!pszEnd)
282 return VERR_BUFFER_UNDERFLOW;
283 int vrc2;
284 if (fNoEqualMeansUnset || strchr(pszzBlock, '='))
285 vrc2 = RTEnvPutEx(m_hEnv, pszzBlock);
286 else
287 vrc2 = RTEnvSetEx(m_hEnv, pszzBlock, "");
288 if (RT_FAILURE(vrc2) && RT_SUCCESS(vrc))
289 vrc = vrc2;
290
291 /* Advance. */
292 cbBlock -= pszEnd - pszzBlock;
293 if (cbBlock < 2)
294 return VERR_BUFFER_UNDERFLOW;
295 cbBlock--;
296 pszzBlock = pszEnd + 1;
297 }
298
299 /* The remainder must be zero padded. */
300 if (RT_SUCCESS(vrc))
301 {
302 if (ASMMemIsZero(pszzBlock, cbBlock))
303 return VINF_SUCCESS;
304 return VERR_TOO_MUCH_DATA;
305 }
306 return vrc;
307 }
308
309 /**
310 * Get an environment variable.
311 *
312 * @returns IPRT status code.
313 * @param rName The variable name.
314 * @param pValue Where to return the value.
315 * @sa RTEnvGetEx
316 */
317 int getVariable(const com::Utf8Str &rName, com::Utf8Str *pValue) const
318 {
319 size_t cchNeeded;
320 int vrc = RTEnvGetEx(m_hEnv, rName.c_str(), NULL, 0, &cchNeeded);
321 if ( RT_SUCCESS(vrc)
322 || vrc == VERR_BUFFER_OVERFLOW)
323 {
324 try
325 {
326 pValue->reserve(cchNeeded + 1);
327 vrc = RTEnvGetEx(m_hEnv, rName.c_str(), pValue->mutableRaw(), pValue->capacity(), NULL);
328 pValue->jolt();
329 }
330 catch (std::bad_alloc &)
331 {
332 vrc = VERR_NO_STR_MEMORY;
333 }
334 }
335 return vrc;
336 }
337
338 /**
339 * Checks if the given variable exists.
340 *
341 * @returns @c true if it exists, @c false if not or if it's an scheduled unset
342 * in a environment change record.
343 * @param rName The variable name.
344 * @sa RTEnvExistEx
345 */
346 bool doesVariableExist(const com::Utf8Str &rName) const
347 {
348 return RTEnvExistEx(m_hEnv, rName.c_str());
349 }
350
351 /**
352 * Set an environment variable.
353 *
354 * @returns IPRT status code.
355 * @param rName The variable name.
356 * @param rValue The value of the variable.
357 * @sa RTEnvSetEx
358 */
359 int setVariable(const com::Utf8Str &rName, const com::Utf8Str &rValue)
360 {
361 return RTEnvSetEx(m_hEnv, rName.c_str(), rValue.c_str());
362 }
363
364 /**
365 * Unset an environment variable.
366 *
367 * @returns IPRT status code.
368 * @param rName The variable name.
369 * @sa RTEnvUnsetEx
370 */
371 int unsetVariable(const com::Utf8Str &rName)
372 {
373 return RTEnvUnsetEx(m_hEnv, rName.c_str());
374 }
375
376protected:
377 /**
378 * Copy constructor.
379 * @throws HRESULT
380 */
381 GuestEnvironmentBase(const GuestEnvironmentBase &rThat, bool fChangeRecord, uint32_t fFlags = 0)
382 : m_hEnv(NIL_RTENV)
383 , m_cRefs(1)
384 , m_fFlags(fFlags)
385 {
386 int vrc = cloneCommon(rThat, fChangeRecord);
387 if (RT_FAILURE(vrc))
388 throw Global::vboxStatusCodeToCOM(vrc);
389 }
390
391 /**
392 * Common clone/copy method with type conversion abilities.
393 *
394 * @returns IPRT status code.
395 * @param rThat The object to clone.
396 * @param fChangeRecord Whether the this instance is a change record (true)
397 * or normal (false) environment.
398 */
399 int cloneCommon(const GuestEnvironmentBase &rThat, bool fChangeRecord)
400 {
401 int vrc = VINF_SUCCESS;
402 RTENV hNewEnv = NIL_RTENV;
403 if (rThat.m_hEnv != NIL_RTENV)
404 {
405 /*
406 * Clone it.
407 */
408 if (RTEnvIsChangeRecord(rThat.m_hEnv) == fChangeRecord)
409 vrc = RTEnvClone(&hNewEnv, rThat.m_hEnv);
410 else
411 {
412 /* Need to type convert it. */
413 if (fChangeRecord)
414 vrc = RTEnvCreateChangeRecordEx(&hNewEnv, rThat.m_fFlags);
415 else
416 vrc = RTEnvCreateEx(&hNewEnv, rThat.m_fFlags);
417 if (RT_SUCCESS(vrc))
418 {
419 vrc = RTEnvApplyChanges(hNewEnv, rThat.m_hEnv);
420 if (RT_FAILURE(vrc))
421 RTEnvDestroy(hNewEnv);
422 }
423 }
424 }
425 else
426 {
427 /*
428 * Create an empty one so the object works smoothly.
429 * (Relevant for GuestProcessStartupInfo and internal commands.)
430 */
431 if (fChangeRecord)
432 vrc = RTEnvCreateChangeRecordEx(&hNewEnv, rThat.m_fFlags);
433 else
434 vrc = RTEnvCreateEx(&hNewEnv, rThat.m_fFlags);
435 }
436 if (RT_SUCCESS(vrc))
437 {
438 RTEnvDestroy(m_hEnv);
439 m_hEnv = hNewEnv;
440 m_fFlags = rThat.m_fFlags;
441 }
442 return vrc;
443 }
444
445
446 /** The environment change record. */
447 RTENV m_hEnv;
448 /** Reference counter. */
449 uint32_t volatile m_cRefs;
450 /** RTENV_CREATE_F_XXX. */
451 uint32_t m_fFlags;
452};
453
454class GuestEnvironmentChanges;
455
456
457/**
458 * Wrapper around the RTEnv API for a normal environment.
459 */
460class GuestEnvironment : public GuestEnvironmentBase
461{
462public:
463 /**
464 * Default constructor.
465 *
466 * The user must invoke one of the init methods before using the object.
467 */
468 GuestEnvironment(void)
469 : GuestEnvironmentBase()
470 { }
471
472 /**
473 * Copy operator.
474 * @param rThat The object to copy.
475 * @throws HRESULT
476 */
477 GuestEnvironment(const GuestEnvironment &rThat)
478 : GuestEnvironmentBase(rThat, false /*fChangeRecord*/)
479 { }
480
481 /**
482 * Copy operator.
483 * @param rThat The object to copy.
484 * @throws HRESULT
485 */
486 GuestEnvironment(const GuestEnvironmentBase &rThat)
487 : GuestEnvironmentBase(rThat, false /*fChangeRecord*/)
488 { }
489
490 /**
491 * Initialize this as a normal environment block.
492 * @returns IPRT status code.
493 * @param fFlags RTENV_CREATE_F_XXX
494 */
495 int initNormal(uint32_t fFlags)
496 {
497 AssertReturn(m_hEnv == NIL_RTENV, VERR_WRONG_ORDER);
498 m_fFlags = fFlags;
499 return RTEnvCreateEx(&m_hEnv, fFlags);
500 }
501
502 /**
503 * Replaces this environemnt with that in @a rThat.
504 *
505 * @returns IPRT status code
506 * @param rThat The environment to copy. If it's a different type
507 * we'll convert the data to a normal environment block.
508 */
509 int copy(const GuestEnvironmentBase &rThat)
510 {
511 return cloneCommon(rThat, false /*fChangeRecord*/);
512 }
513
514 /**
515 * @copydoc copy()
516 */
517 GuestEnvironment &operator=(const GuestEnvironmentBase &rThat)
518 {
519 int vrc = copy(rThat);
520 if (RT_FAILURE(vrc))
521 throw Global::vboxStatusCodeToCOM(vrc);
522 return *this;
523 }
524
525 /** @copydoc copy() */
526 GuestEnvironment &operator=(const GuestEnvironment &rThat)
527 { return operator=((const GuestEnvironmentBase &)rThat); }
528
529 /** @copydoc copy() */
530 GuestEnvironment &operator=(const GuestEnvironmentChanges &rThat)
531 { return operator=((const GuestEnvironmentBase &)rThat); }
532
533};
534
535
536/**
537 * Wrapper around the RTEnv API for a environment change record.
538 *
539 * This class is used as a record of changes to be applied to a different
540 * environment block (in VBoxService before launching a new process).
541 */
542class GuestEnvironmentChanges : public GuestEnvironmentBase
543{
544public:
545 /**
546 * Default constructor.
547 *
548 * The user must invoke one of the init methods before using the object.
549 */
550 GuestEnvironmentChanges(void)
551 : GuestEnvironmentBase()
552 { }
553
554 /**
555 * Copy operator.
556 * @param rThat The object to copy.
557 * @throws HRESULT
558 */
559 GuestEnvironmentChanges(const GuestEnvironmentChanges &rThat)
560 : GuestEnvironmentBase(rThat, true /*fChangeRecord*/)
561 { }
562
563 /**
564 * Copy operator.
565 * @param rThat The object to copy.
566 * @throws HRESULT
567 */
568 GuestEnvironmentChanges(const GuestEnvironmentBase &rThat)
569 : GuestEnvironmentBase(rThat, true /*fChangeRecord*/)
570 { }
571
572 /**
573 * Initialize this as a environment change record.
574 * @returns IPRT status code.
575 * @param fFlags RTENV_CREATE_F_XXX
576 */
577 int initChangeRecord(uint32_t fFlags)
578 {
579 AssertReturn(m_hEnv == NIL_RTENV, VERR_WRONG_ORDER);
580 m_fFlags = fFlags;
581 return RTEnvCreateChangeRecordEx(&m_hEnv, fFlags);
582 }
583
584 /**
585 * Replaces this environemnt with that in @a rThat.
586 *
587 * @returns IPRT status code
588 * @param rThat The environment to copy. If it's a different type
589 * we'll convert the data to a set of changes.
590 */
591 int copy(const GuestEnvironmentBase &rThat)
592 {
593 return cloneCommon(rThat, true /*fChangeRecord*/);
594 }
595
596 /**
597 * @copydoc copy()
598 */
599 GuestEnvironmentChanges &operator=(const GuestEnvironmentBase &rThat)
600 {
601 int vrc = copy(rThat);
602 if (RT_FAILURE(vrc))
603 throw Global::vboxStatusCodeToCOM(vrc);
604 return *this;
605 }
606
607 /** @copydoc copy() */
608 GuestEnvironmentChanges &operator=(const GuestEnvironmentChanges &rThat)
609 { return operator=((const GuestEnvironmentBase &)rThat); }
610
611 /** @copydoc copy() */
612 GuestEnvironmentChanges &operator=(const GuestEnvironment &rThat)
613 { return operator=((const GuestEnvironmentBase &)rThat); }
614};
615
616/**
617 * Class for keeping guest error information.
618 */
619class GuestErrorInfo
620{
621public:
622
623 /**
624 * Enumeration for specifying the guest error type.
625 */
626 enum Type
627 {
628 /** Guest error is anonymous. Avoid this. */
629 Type_Anonymous = 0,
630 /** Guest error is from a guest session. */
631 Type_Session,
632 /** Guest error is from a guest process. */
633 Type_Process,
634 /** Guest error is from a guest file object. */
635 Type_File,
636 /** Guest error is from a guest directory object. */
637 Type_Directory,
638 /** Guest error is from a file system operation. */
639 Type_Fs,
640#ifdef VBOX_WITH_GSTCTL_TOOLBOX_SUPPORT
641 /** Guest error is from a the built-in toolbox "vbox_ls" command. */
642 Type_ToolLs,
643 /** Guest error is from a the built-in toolbox "vbox_rm" command. */
644 Type_ToolRm,
645 /** Guest error is from a the built-in toolbox "vbox_mkdir" command. */
646 Type_ToolMkDir,
647 /** Guest error is from a the built-in toolbox "vbox_mktemp" command. */
648 Type_ToolMkTemp,
649 /** Guest error is from a the built-in toolbox "vbox_stat" command. */
650 Type_ToolStat,
651#endif /* VBOX_WITH_GSTCTL_TOOLBOX_SUPPORT */
652 /** The usual 32-bit hack. */
653 Type_32BIT_HACK = 0x7fffffff
654 };
655
656 /**
657 * Initialization constructor.
658 *
659 * @param eType Error type to use.
660 * @param vrc VBox status code to use.
661 * @param pcszWhat Subject to use.
662 */
663 GuestErrorInfo(GuestErrorInfo::Type eType, int vrc, const char *pcszWhat)
664 {
665 int vrc2 = setV(eType, vrc, pcszWhat);
666 if (RT_FAILURE(vrc2))
667 throw vrc2;
668 }
669
670 /**
671 * Returns the VBox status code for this error.
672 *
673 * @returns VBox status code.
674 */
675 int getVrc(void) const { return mVrc; }
676
677 /**
678 * Returns the type of this error.
679 *
680 * @returns Error type.
681 */
682 Type getType(void) const { return mType; }
683
684 /**
685 * Returns the subject of this error.
686 *
687 * @returns Subject as a string.
688 */
689 Utf8Str getWhat(void) const { return mWhat; }
690
691 /**
692 * Sets the error information using a variable arguments list (va_list).
693 *
694 * @returns VBox status code.
695 * @param eType Error type to use.
696 * @param vrc VBox status code to use.
697 * @param pcszWhat Subject to use.
698 */
699 int setV(GuestErrorInfo::Type eType, int vrc, const char *pcszWhat)
700 {
701 mType = eType;
702 mVrc = vrc;
703 mWhat = pcszWhat;
704
705 return VINF_SUCCESS;
706 }
707
708protected:
709
710 /** Error type. */
711 Type mType;
712 /** VBox status (error) code. */
713 int mVrc;
714 /** Subject string related to this error. */
715 Utf8Str mWhat;
716};
717
718/**
719 * Structure for keeping all the relevant guest directory
720 * information around.
721 */
722struct GuestDirectoryOpenInfo
723{
724 GuestDirectoryOpenInfo(void)
725 : menmFilter(GSTCTLDIRFILTER_NONE)
726 , mFlags(0) { }
727
728 /** The directory path. */
729 Utf8Str mPath;
730 /** The filter to use (wildcard style). */
731 Utf8Str mFilter;
732 /** The filter option to use. */
733 GSTCTLDIRFILTER menmFilter;
734 /** Opening flags (of type GSTCTLDIRFILTER_XXX). */
735 uint32_t mFlags;
736};
737
738
739/**
740 * Structure for keeping all the relevant guest file
741 * information around.
742 */
743struct GuestFileOpenInfo
744{
745 GuestFileOpenInfo(void)
746 : mAccessMode((FileAccessMode_T)0)
747 , mOpenAction((FileOpenAction_T)0)
748 , mSharingMode((FileSharingMode_T)0)
749 , mCreationMode(0)
750 , mfOpenEx(0) { }
751
752 /**
753 * Validates a file open info.
754 *
755 * @returns \c true if valid, \c false if not.
756 */
757 bool IsValid(void) const
758 {
759 if (mfOpenEx) /** @todo Open flags not implemented yet. */
760 return false;
761
762 switch (mOpenAction)
763 {
764 case FileOpenAction_OpenExisting:
765 break;
766 case FileOpenAction_OpenOrCreate:
767 break;
768 case FileOpenAction_CreateNew:
769 break;
770 case FileOpenAction_CreateOrReplace:
771 break;
772 case FileOpenAction_OpenExistingTruncated:
773 {
774 if ( mAccessMode == FileAccessMode_ReadOnly
775 || mAccessMode == FileAccessMode_AppendOnly
776 || mAccessMode == FileAccessMode_AppendRead)
777 return false;
778 break;
779 }
780 case FileOpenAction_AppendOrCreate: /* Deprecated, do not use. */
781 break;
782 default:
783 AssertFailedReturn(false);
784 break;
785 }
786
787 return true; /** @todo Do we need more checks here? */
788 }
789
790 /** The filename. */
791 Utf8Str mFilename;
792 /** The file access mode. */
793 FileAccessMode_T mAccessMode;
794 /** The file open action. */
795 FileOpenAction_T mOpenAction;
796 /** The file sharing mode. */
797 FileSharingMode_T mSharingMode;
798 /** Octal creation mode. */
799 uint32_t mCreationMode;
800 /** Extended open flags (currently none defined). */
801 uint32_t mfOpenEx;
802};
803
804
805/**
806 * Helper class for guest file system operations.
807 */
808class GuestFs
809{
810 DECLARE_TRANSLATE_METHODS(GuestFs)
811
812private:
813
814 /* Not directly instantiable. */
815 GuestFs(void) { }
816
817public:
818
819 static Utf8Str guestErrorToString(const GuestErrorInfo &guestErrorInfo);
820};
821
822
823/**
824 * Structure representing information of a
825 * file system object.
826 */
827struct GuestFsObjData
828{
829 GuestFsObjData(const Utf8Str &strName = "")
830 : mType(FsObjType_Unknown)
831 , mObjectSize(0)
832 , mAllocatedSize(0)
833 , mAccessTime(0)
834 , mBirthTime(0)
835 , mChangeTime(0)
836 , mModificationTime(0)
837 , mUID(0)
838 , mGID(0)
839 , mNodeID(0)
840 , mNodeIDDevice(0)
841 , mNumHardLinks(0)
842 , mDeviceNumber(0)
843 , mGenerationID(0)
844 , mUserFlags(0) { mName = strName; }
845
846 void Init(const Utf8Str &strName) { mName = strName; }
847
848#ifdef VBOX_WITH_GSTCTL_TOOLBOX_AS_CMDS
849 int FromGuestDirEntryEx(PCGSTCTLDIRENTRYEX pDirEntryEx, const Utf8Str &strUser = "", const Utf8Str &strGroups = "");
850 int FromGuestFsObjInfo(PCGSTCTLFSOBJINFO pFsObjInfo, const Utf8Str &strUser = "", const Utf8Str &strGroups = "",
851 const void *pvACL = NULL, size_t cbACL = 0);
852#endif
853
854#ifdef VBOX_WITH_GSTCTL_TOOLBOX_SUPPORT
855 /** @name Helper functions to extract the data from a certin VBoxService tool's guest stream block.
856 * @{ */
857 int FromToolboxLs(const GuestToolboxStreamBlock &strmBlk, bool fLong);
858 int FromToolboxRm(const GuestToolboxStreamBlock &strmBlk);
859 int FromToolboxStat(const GuestToolboxStreamBlock &strmBlk);
860 int FromToolboxMkTemp(const GuestToolboxStreamBlock &strmBlk);
861 /** @} */
862#endif
863
864#ifdef VBOX_WITH_GSTCTL_TOOLBOX_SUPPORT
865 /** @name Static helper functions to work with time from stream block keys.
866 * @{ */
867 static PRTTIMESPEC TimeSpecFromKey(const GuestToolboxStreamBlock &strmBlk, const Utf8Str &strKey, PRTTIMESPEC pTimeSpec);
868 static int64_t UnixEpochNsFromKey(const GuestToolboxStreamBlock &strmBlk, const Utf8Str &strKey);
869 /** @} */
870#endif
871
872 /** @name helper functions to work with IPRT stuff.
873 * @{ */
874 RTFMODE GetFileMode(void) const;
875 /** @} */
876
877 Utf8Str mName;
878 FsObjType_T mType;
879 Utf8Str mFileAttrs;
880 int64_t mObjectSize;
881 int64_t mAllocatedSize;
882 int64_t mAccessTime;
883 int64_t mBirthTime;
884 int64_t mChangeTime;
885 int64_t mModificationTime;
886 Utf8Str mUserName;
887 int32_t mUID;
888 int32_t mGID;
889 Utf8Str mGroupName;
890 Utf8Str mACL;
891 int64_t mNodeID;
892 uint32_t mNodeIDDevice;
893 uint32_t mNumHardLinks;
894 uint32_t mDeviceNumber;
895 uint32_t mGenerationID;
896 uint32_t mUserFlags;
897};
898
899
900/**
901 * Structure for keeping all the relevant guest session
902 * startup parameters around.
903 */
904class GuestSessionStartupInfo
905{
906public:
907
908 GuestSessionStartupInfo(void)
909 : mID(UINT32_MAX)
910 , mIsInternal(false /* Non-internal session */)
911 , mOpenTimeoutMS(30 * 1000 /* 30s opening timeout */)
912 , mOpenFlags(0 /* No opening flags set */) { }
913
914 /** The session's friendly name. Optional. */
915 Utf8Str mName;
916 /** The session's unique ID. Used to encode a context ID.
917 * UINT32_MAX if not initialized. */
918 uint32_t mID;
919 /** Flag indicating if this is an internal session
920 * or not. Internal session are not accessible by
921 * public API clients. */
922 bool mIsInternal;
923 /** Timeout (in ms) used for opening the session. */
924 uint32_t mOpenTimeoutMS;
925 /** Session opening flags. */
926 uint32_t mOpenFlags;
927};
928
929
930/**
931 * Structure for keeping all the relevant guest process
932 * startup parameters around.
933 */
934class GuestProcessStartupInfo
935{
936public:
937
938 GuestProcessStartupInfo(void)
939 : mFlags(ProcessCreateFlag_None)
940 , mTimeoutMS(UINT32_MAX /* No timeout by default */)
941 , mPriority(ProcessPriority_Default)
942 , mAffinity(0) { }
943
944 /** The process' friendly name. */
945 Utf8Str mName;
946 /** The executable. */
947 Utf8Str mExecutable;
948 /** Arguments vector (starting with argument \#0). */
949 ProcessArguments mArguments;
950 /** The process environment change record. */
951 GuestEnvironmentChanges mEnvironmentChanges;
952 /** Process creation flags. */
953 uint32_t mFlags;
954 /** Timeout (in ms) the process is allowed to run.
955 * Specify UINT32_MAX if no timeout (unlimited run time) is given. */
956 ULONG mTimeoutMS;
957 /** Process priority. */
958 ProcessPriority_T mPriority;
959 /** Process affinity. At the moment we
960 * only support 64 VCPUs. API and
961 * guest can do more already! */
962 uint64_t mAffinity;
963};
964
965
966/**
967 * Class representing the "value" side of a "key=value" pair.
968 */
969class GuestToolboxStreamValue
970{
971public:
972
973 GuestToolboxStreamValue(void) { }
974 GuestToolboxStreamValue(const char *pszValue)
975 : mValue(pszValue) {}
976
977 GuestToolboxStreamValue(const GuestToolboxStreamValue& aThat)
978 : mValue(aThat.mValue) { }
979
980 /** Copy assignment operator. */
981 GuestToolboxStreamValue &operator=(GuestToolboxStreamValue const &a_rThat) RT_NOEXCEPT
982 {
983 mValue = a_rThat.mValue;
984
985 return *this;
986 }
987
988 Utf8Str mValue;
989};
990
991/** Map containing "key=value" pairs of a guest process stream. */
992typedef std::pair< Utf8Str, GuestToolboxStreamValue > GuestCtrlStreamPair;
993typedef std::map < Utf8Str, GuestToolboxStreamValue > GuestCtrlStreamPairMap;
994typedef std::map < Utf8Str, GuestToolboxStreamValue >::iterator GuestCtrlStreamPairMapIter;
995typedef std::map < Utf8Str, GuestToolboxStreamValue >::const_iterator GuestCtrlStreamPairMapIterConst;
996
997/**
998 * Class representing a block of stream pairs (key=value). Each block in a raw guest
999 * output stream is separated by "\0\0", each pair is separated by "\0". The overall
1000 * end of a guest stream is marked by "\0\0\0\0".
1001 *
1002 * Only used for the busybox-like toolbox commands within VBoxService.
1003 * Deprecated, do not use anymore.
1004 */
1005class GuestToolboxStreamBlock
1006{
1007public:
1008
1009 GuestToolboxStreamBlock(void);
1010
1011 virtual ~GuestToolboxStreamBlock(void);
1012
1013public:
1014
1015 void Clear(void);
1016
1017#ifdef DEBUG
1018 void DumpToLog(void) const;
1019#endif
1020
1021 const char *GetString(const char *pszKey) const;
1022 size_t GetCount(void) const;
1023 int GetVrc(bool fSucceedIfNotFound = false) const;
1024 int GetInt64Ex(const char *pszKey, int64_t *piVal) const;
1025 int64_t GetInt64(const char *pszKey) const;
1026 int GetUInt32Ex(const char *pszKey, uint32_t *puVal) const;
1027 uint32_t GetUInt32(const char *pszKey, uint32_t uDefault = 0) const;
1028 int32_t GetInt32(const char *pszKey, int32_t iDefault = 0) const;
1029
1030 bool IsEmpty(void) { return mPairs.empty(); }
1031
1032 int SetValue(const char *pszKey, const char *pszValue);
1033
1034protected:
1035
1036 GuestCtrlStreamPairMap mPairs;
1037};
1038
1039/** Vector containing multiple allocated stream pair objects. */
1040typedef std::vector< GuestToolboxStreamBlock > GuestCtrlStreamObjects;
1041typedef std::vector< GuestToolboxStreamBlock >::iterator GuestCtrlStreamObjectsIter;
1042typedef std::vector< GuestToolboxStreamBlock >::const_iterator GuestCtrlStreamObjectsIterConst;
1043
1044/**
1045 * Class for parsing machine-readable guest process output by VBoxService'
1046 * toolbox commands ("vbox_ls", "vbox_stat" etc), aka "guest stream".
1047 *
1048 * Deprecated, do not use anymore.
1049 */
1050class GuestToolboxStream
1051{
1052
1053public:
1054
1055 GuestToolboxStream();
1056
1057 virtual ~GuestToolboxStream();
1058
1059public:
1060
1061 int AddData(const BYTE *pbData, size_t cbData);
1062
1063 void Destroy();
1064
1065#ifdef DEBUG
1066 void Dump(const char *pszFile);
1067#endif
1068
1069 size_t GetOffset() { return m_offBuffer; }
1070
1071 size_t GetSize() { return m_cbUsed; }
1072
1073 int ParseBlock(GuestToolboxStreamBlock &streamBlock);
1074
1075protected:
1076
1077 /** Maximum allowed size the stream buffer can grow to.
1078 * Defaults to 32 MB. */
1079 size_t m_cbMax;
1080 /** Currently allocated size of internal stream buffer. */
1081 size_t m_cbAllocated;
1082 /** Currently used size at m_offBuffer. */
1083 size_t m_cbUsed;
1084 /** Current byte offset within the internal stream buffer. */
1085 size_t m_offBuffer;
1086 /** Internal stream buffer. */
1087 BYTE *m_pbBuffer;
1088};
1089
1090class Guest;
1091class Progress;
1092
1093class GuestWaitEventPayload
1094{
1095
1096public:
1097
1098 GuestWaitEventPayload(void)
1099 : uType(0)
1100 , cbData(0)
1101 , pvData(NULL)
1102 { }
1103
1104 /**
1105 * Initialization constructor.
1106 *
1107 * @throws VBox status code (vrc).
1108 *
1109 * @param uTypePayload Payload type to set.
1110 * @param pvPayload Pointer to payload data to set (deep copy).
1111 * @param cbPayload Size (in bytes) of payload data to set.
1112 */
1113 GuestWaitEventPayload(uint32_t uTypePayload, const void *pvPayload, uint32_t cbPayload)
1114 : uType(0)
1115 , cbData(0)
1116 , pvData(NULL)
1117 {
1118 int vrc = copyFrom(uTypePayload, pvPayload, cbPayload);
1119 if (RT_FAILURE(vrc))
1120 throw vrc;
1121 }
1122
1123 virtual ~GuestWaitEventPayload(void)
1124 {
1125 Clear();
1126 }
1127
1128 GuestWaitEventPayload& operator=(const GuestWaitEventPayload &that)
1129 {
1130 CopyFromDeep(that);
1131 return *this;
1132 }
1133
1134public:
1135
1136 void Clear(void)
1137 {
1138 if (pvData)
1139 {
1140 Assert(cbData);
1141 RTMemFree(pvData);
1142 cbData = 0;
1143 pvData = NULL;
1144 }
1145 uType = 0;
1146 }
1147
1148 int CopyFromDeep(const GuestWaitEventPayload &payload)
1149 {
1150 return copyFrom(payload.uType, payload.pvData, payload.cbData);
1151 }
1152
1153 const void* Raw(void) const { return pvData; }
1154
1155 size_t Size(void) const { return cbData; }
1156
1157 uint32_t Type(void) const { return uType; }
1158
1159 void* MutableRaw(void) { return pvData; }
1160
1161 Utf8Str ToString(void)
1162 {
1163 const char *pszStr = (const char *)pvData;
1164 size_t cbStr = cbData;
1165
1166 if (RT_FAILURE(RTStrValidateEncodingEx(pszStr, cbStr,
1167 RTSTR_VALIDATE_ENCODING_ZERO_TERMINATED | RTSTR_VALIDATE_ENCODING_EXACT_LENGTH)))
1168 {
1169 AssertFailed();
1170 return "";
1171 }
1172
1173 return Utf8Str(pszStr, cbStr);
1174 }
1175
1176protected:
1177
1178 int copyFrom(uint32_t uTypePayload, const void *pvPayload, uint32_t cbPayload)
1179 {
1180 if (cbPayload > _64K) /* Paranoia. */
1181 return VERR_TOO_MUCH_DATA;
1182
1183 Clear();
1184
1185 int vrc = VINF_SUCCESS;
1186 if (cbPayload)
1187 {
1188 pvData = RTMemAlloc(cbPayload);
1189 if (pvData)
1190 {
1191 uType = uTypePayload;
1192
1193 memcpy(pvData, pvPayload, cbPayload);
1194 cbData = cbPayload;
1195 }
1196 else
1197 vrc = VERR_NO_MEMORY;
1198 }
1199 else
1200 {
1201 uType = uTypePayload;
1202
1203 pvData = NULL;
1204 cbData = 0;
1205 }
1206
1207 return vrc;
1208 }
1209
1210protected:
1211
1212 /** Type of payload. */
1213 uint32_t uType;
1214 /** Size (in bytes) of payload. */
1215 uint32_t cbData;
1216 /** Pointer to actual payload data. */
1217 void *pvData;
1218};
1219
1220class GuestWaitEventBase
1221{
1222
1223protected:
1224
1225 GuestWaitEventBase(void);
1226 virtual ~GuestWaitEventBase(void);
1227
1228public:
1229
1230 uint32_t ContextID(void) const { return mCID; };
1231 int GuestResult(void) const { return mGuestRc; }
1232 bool HasGuestError(void) const { return mVrc == VERR_GSTCTL_GUEST_ERROR; }
1233 int Result(void) const { return mVrc; }
1234 GuestWaitEventPayload &Payload(void) { return mPayload; }
1235 int SignalInternal(int vrc, int vrcGuest, const GuestWaitEventPayload *pPayload);
1236 int Wait(RTMSINTERVAL uTimeoutMS);
1237
1238protected:
1239
1240 int Init(uint32_t uCID);
1241
1242protected:
1243
1244 /** Shutdown indicator. */
1245 bool mfAborted;
1246 /** Associated context ID (CID). */
1247 uint32_t mCID;
1248 /** The event semaphore for triggering the actual event. */
1249 RTSEMEVENT mEventSem;
1250 /** The event's overall result.
1251 * If set to VERR_GSTCTL_GUEST_ERROR, mGuestRc will contain the actual
1252 * error code from the guest side. */
1253 int mVrc;
1254 /** The event'S overall result from the guest side.
1255 * If used, mVrc must be set to VERR_GSTCTL_GUEST_ERROR. */
1256 int mGuestRc;
1257 /** The event's payload data. Optional. */
1258 GuestWaitEventPayload mPayload;
1259};
1260
1261/** List of public guest event types. */
1262typedef std::list < VBoxEventType_T > GuestEventTypes;
1263
1264class GuestWaitEvent : public GuestWaitEventBase
1265{
1266
1267public:
1268
1269 GuestWaitEvent(void);
1270 virtual ~GuestWaitEvent(void);
1271
1272public:
1273
1274 int Init(uint32_t uCID);
1275 int Init(uint32_t uCID, const GuestEventTypes &lstEvents);
1276 int Cancel(void);
1277 const ComPtr<IEvent> Event(void) const { return mEvent; }
1278 int SignalExternal(IEvent *pEvent);
1279 const GuestEventTypes &Types(void) const { return mEventTypes; }
1280 size_t TypeCount(void) const { return mEventTypes.size(); }
1281
1282protected:
1283
1284 /** List of public event types this event should
1285 * be signalled on. Optional. */
1286 GuestEventTypes mEventTypes;
1287 /** Pointer to the actual public event, if any. */
1288 ComPtr<IEvent> mEvent;
1289};
1290/** Map of pointers to guest events. The primary key
1291 * contains the context ID. */
1292typedef std::map < uint32_t, GuestWaitEvent* > GuestWaitEvents;
1293/** Map of wait events per public guest event. Nice for
1294 * faster lookups when signalling a whole event group. */
1295typedef std::map < VBoxEventType_T, GuestWaitEvents > GuestEventGroup;
1296
1297class GuestBase
1298{
1299
1300public:
1301
1302 GuestBase(void);
1303 virtual ~GuestBase(void);
1304
1305public:
1306
1307 /** Signals a wait event using a public guest event; also used for
1308 * for external event listeners. */
1309 int signalWaitEvent(VBoxEventType_T aType, IEvent *aEvent);
1310 /** Signals a wait event using a guest vrc. */
1311 int signalWaitEventInternal(PVBOXGUESTCTRLHOSTCBCTX pCbCtx, int vrcGuest, const GuestWaitEventPayload *pPayload);
1312 /** Signals a wait event without letting public guest events know,
1313 * extended director's cut version. */
1314 int signalWaitEventInternalEx(PVBOXGUESTCTRLHOSTCBCTX pCbCtx, int vrc, int vrcGuest, const GuestWaitEventPayload *pPayload);
1315
1316public:
1317
1318 int baseInit(void);
1319 void baseUninit(void);
1320 int cancelWaitEvents(void);
1321 int dispatchGeneric(PVBOXGUESTCTRLHOSTCBCTX pCtxCb, PVBOXGUESTCTRLHOSTCALLBACK pSvcCb);
1322 int generateContextID(uint32_t uSessionID, uint32_t uObjectID, uint32_t *puContextID);
1323 int registerWaitEvent(uint32_t uSessionID, uint32_t uObjectID, GuestWaitEvent **ppEvent);
1324 int registerWaitEventEx(uint32_t uSessionID, uint32_t uObjectID, const GuestEventTypes &lstEvents, GuestWaitEvent **ppEvent);
1325 int unregisterWaitEvent(GuestWaitEvent *pEvent);
1326 int waitForEvent(GuestWaitEvent *pEvent, uint32_t uTimeoutMS, VBoxEventType_T *pType, IEvent **ppEvent);
1327
1328public:
1329
1330 static FsObjType_T fileModeToFsObjType(RTFMODE fMode);
1331 static const char *fsObjTypeToStr(FsObjType_T enmType);
1332 static const char *pathStyleToStr(PathStyle_T enmPathStyle);
1333 static Utf8Str getErrorAsString(const Utf8Str &strAction, const GuestErrorInfo& guestErrorInfo);
1334 static Utf8Str getErrorAsString(const GuestErrorInfo &guestErrorInfo);
1335
1336protected:
1337
1338 /** Pointer to the console object. Needed
1339 * for HGCM (VMMDev) communication. */
1340 Console *mConsole;
1341 /** The next context ID counter component for this object. */
1342 uint32_t mNextContextID;
1343 /** Local listener for handling the waiting events
1344 * internally. */
1345 ComPtr<IEventListener> mLocalListener;
1346 /** Critical section for wait events access. */
1347 RTCRITSECT mWaitEventCritSect;
1348 /** Map of registered wait events per event group. */
1349 GuestEventGroup mWaitEventGroups;
1350 /** Map of registered wait events. */
1351 GuestWaitEvents mWaitEvents;
1352};
1353
1354/**
1355 * Virtual class (interface) for guest objects (processes, files, ...) --
1356 * contains all per-object callback management.
1357 */
1358class GuestObject : public GuestBase
1359{
1360 friend class GuestSession;
1361
1362public:
1363
1364 GuestObject(void);
1365 virtual ~GuestObject(void);
1366
1367public:
1368
1369 ULONG getObjectID(void) { return mObjectID; }
1370
1371protected:
1372
1373 /**
1374 * Called by IGuestSession when the session status has been changed.
1375 *
1376 * @returns VBox status code.
1377 * @param enmSessionStatus New session status.
1378 */
1379 virtual int i_onSessionStatusChange(GuestSessionStatus_T enmSessionStatus) = 0;
1380
1381 /**
1382 * Called by IGuestSession right before this object gets
1383 * unregistered (removed) from the public object list.
1384 */
1385 virtual int i_onUnregister(void) = 0;
1386
1387 /** Callback dispatcher -- must be implemented by the actual object. */
1388 virtual int i_callbackDispatcher(PVBOXGUESTCTRLHOSTCBCTX pCbCtx, PVBOXGUESTCTRLHOSTCALLBACK pSvcCb) = 0;
1389
1390protected:
1391
1392 int bindToSession(Console *pConsole, GuestSession *pSession, uint32_t uObjectID);
1393 int registerWaitEvent(const GuestEventTypes &lstEvents, GuestWaitEvent **ppEvent);
1394 int sendMessage(uint32_t uFunction, uint32_t cParms, PVBOXHGCMSVCPARM paParms);
1395
1396protected:
1397
1398 /** @name Common parameters for all derived objects. They have their own
1399 * mData structure to keep their specific data around.
1400 * @{ */
1401 /** Pointer to parent session. Per definition
1402 * this objects *always* lives shorter than the
1403 * parent.
1404 * @todo r=bird: When wanting to use mSession in the
1405 * IGuestProcess::getEnvironment() implementation I wanted to access
1406 * GuestSession::mData::mpBaseEnvironment. Seeing the comment in
1407 * GuestProcess::terminate() saying:
1408 * "Now only API clients still can hold references to it."
1409 * and recalling seeing similar things in VirtualBox.xidl or some such place,
1410 * I'm wondering how this "per definition" behavior is enforced. Is there any
1411 * GuestProcess:uninit() call or similar magic that invalidates objects that
1412 * GuestSession loses track of in place like GuestProcess::terminate() that I've
1413 * failed to spot?
1414 *
1415 * Please enlighten me.
1416 */
1417 GuestSession *mSession;
1418 /** The object ID -- must be unique for each guest
1419 * object and is encoded into the context ID. Must
1420 * be set manually when initializing the object.
1421 *
1422 * For guest processes this is the internal PID,
1423 * for guest files this is the internal file ID. */
1424 uint32_t mObjectID;
1425 /** @} */
1426};
1427
1428/** Returns the path separator based on \a a_enmPathStyle as a C-string. */
1429#define PATH_STYLE_SEP_STR(a_enmPathStyle) (a_enmPathStyle == PathStyle_DOS ? "\\" : "/")
1430#if defined(RT_OS_WINDOWS) || defined(RT_OS_OS2)
1431# define PATH_STYLE_NATIVE PathStyle_DOS
1432#else
1433# define PATH_STYLE_NATIVE PathStyle_UNIX
1434#endif
1435
1436/**
1437 * Class for handling guest / host path functions.
1438 */
1439class GuestPath
1440{
1441private:
1442
1443 /**
1444 * Default constructor.
1445 *
1446 * Not directly instantiable (yet).
1447 */
1448 GuestPath(void) { }
1449
1450public:
1451
1452 /** @name Static helper functions.
1453 * @{ */
1454 static int BuildDestinationPath(const Utf8Str &strSrcPath, PathStyle_T enmSrcPathStyle, Utf8Str &strDstPath, PathStyle_T enmDstPathStyle);
1455 static int Translate(Utf8Str &strPath, PathStyle_T enmSrcPathStyle, PathStyle_T enmDstPathStyle, bool fForce = false);
1456 /** @} */
1457};
1458
1459
1460/*******************************************************************************
1461* Callback data structures. *
1462* *
1463* These structures make up the actual low level HGCM callback data sent from *
1464* the guest back to the host. *
1465*******************************************************************************/
1466
1467/**
1468 * The guest control callback data header. Must come first
1469 * on each callback structure defined below this struct.
1470 */
1471typedef struct CALLBACKDATA_HEADER
1472{
1473 /** Context ID to identify callback data. This is
1474 * and *must* be the very first parameter in this
1475 * structure to still be backwards compatible. */
1476 uint32_t uContextID;
1477} CALLBACKDATA_HEADER;
1478/** Pointer to a CALLBACKDATA_HEADER struct. */
1479typedef CALLBACKDATA_HEADER *PCALLBACKDATA_HEADER;
1480
1481/**
1482 * Host service callback data when a HGCM client disconnected.
1483 */
1484typedef struct CALLBACKDATA_CLIENT_DISCONNECTED
1485{
1486 /** Callback data header. */
1487 CALLBACKDATA_HEADER hdr;
1488} CALLBACKDATA_CLIENT_DISCONNECTED;
1489/** Pointer to a CALLBACKDATA_CLIENT_DISCONNECTED struct. */
1490typedef CALLBACKDATA_CLIENT_DISCONNECTED *PCALLBACKDATA_CLIENT_DISCONNECTED;
1491
1492/**
1493 * Host service callback data for a generic guest reply.
1494 */
1495typedef struct CALLBACKDATA_MSG_REPLY
1496{
1497 /** Callback data header. */
1498 CALLBACKDATA_HEADER hdr;
1499 /** Notification type. */
1500 uint32_t uType;
1501 /** Notification result. Note: int vs. uint32! */
1502 uint32_t rc;
1503 /** Pointer to optional payload. */
1504 void *pvPayload;
1505 /** Payload size (in bytes). */
1506 uint32_t cbPayload;
1507} CALLBACKDATA_MSG_REPLY;
1508/** Pointer to a CALLBACKDATA_MSG_REPLY struct. */
1509typedef CALLBACKDATA_MSG_REPLY *PCALLBACKDATA_MSG_REPLY;
1510
1511/**
1512 * Host service callback data for guest session notifications.
1513 */
1514typedef struct CALLBACKDATA_SESSION_NOTIFY
1515{
1516 /** Callback data header. */
1517 CALLBACKDATA_HEADER hdr;
1518 /** Notification type. */
1519 uint32_t uType;
1520 /** Notification result. Note: int vs. uint32! */
1521 uint32_t uResult;
1522} CALLBACKDATA_SESSION_NOTIFY;
1523/** Pointer to a CALLBACKDATA_SESSION_NOTIFY struct. */
1524typedef CALLBACKDATA_SESSION_NOTIFY *PCALLBACKDATA_SESSION_NOTIFY;
1525
1526/**
1527 * Host service callback data for guest process status notifications.
1528 */
1529typedef struct CALLBACKDATA_PROC_STATUS
1530{
1531 /** Callback data header. */
1532 CALLBACKDATA_HEADER hdr;
1533 /** The process ID (PID). */
1534 uint32_t uPID;
1535 /** The process status. */
1536 uint32_t uStatus;
1537 /** Optional flags, varies, based on u32Status. */
1538 uint32_t uFlags;
1539 /** Optional data buffer (not used atm). */
1540 void *pvData;
1541 /** Size of optional data buffer (not used atm). */
1542 uint32_t cbData;
1543} CALLBACKDATA_PROC_STATUS;
1544/** Pointer to a CALLBACKDATA_PROC_OUTPUT struct. */
1545typedef CALLBACKDATA_PROC_STATUS* PCALLBACKDATA_PROC_STATUS;
1546
1547/**
1548 * Host service callback data for guest process output notifications.
1549 */
1550typedef struct CALLBACKDATA_PROC_OUTPUT
1551{
1552 /** Callback data header. */
1553 CALLBACKDATA_HEADER hdr;
1554 /** The process ID (PID). */
1555 uint32_t uPID;
1556 /** The handle ID (stdout/stderr). */
1557 uint32_t uHandle;
1558 /** Optional flags (not used atm). */
1559 uint32_t uFlags;
1560 /** Optional data buffer. */
1561 void *pvData;
1562 /** Size (in bytes) of optional data buffer. */
1563 uint32_t cbData;
1564} CALLBACKDATA_PROC_OUTPUT;
1565/** Pointer to a CALLBACKDATA_PROC_OUTPUT struct. */
1566typedef CALLBACKDATA_PROC_OUTPUT *PCALLBACKDATA_PROC_OUTPUT;
1567
1568/**
1569 * Host service callback data guest process input notifications.
1570 */
1571typedef struct CALLBACKDATA_PROC_INPUT
1572{
1573 /** Callback data header. */
1574 CALLBACKDATA_HEADER hdr;
1575 /** The process ID (PID). */
1576 uint32_t uPID;
1577 /** Current input status. */
1578 uint32_t uStatus;
1579 /** Optional flags. */
1580 uint32_t uFlags;
1581 /** Size (in bytes) of processed input data. */
1582 uint32_t uProcessed;
1583} CALLBACKDATA_PROC_INPUT;
1584/** Pointer to a CALLBACKDATA_PROC_INPUT struct. */
1585typedef CALLBACKDATA_PROC_INPUT *PCALLBACKDATA_PROC_INPUT;
1586
1587/**
1588 * General guest file notification callback.
1589 */
1590typedef struct CALLBACKDATA_FILE_NOTIFY
1591{
1592 /** Callback data header. */
1593 CALLBACKDATA_HEADER hdr;
1594 /** Notification type. */
1595 uint32_t uType;
1596 /** IPRT result of overall operation. */
1597 uint32_t rc;
1598 union
1599 {
1600 struct
1601 {
1602 /** Guest file handle. */
1603 uint32_t uHandle;
1604 } open;
1605 /** Note: Close does not have any additional data (yet). */
1606 struct
1607 {
1608 /** How much data (in bytes) have been read. */
1609 uint32_t cbData;
1610 /** Actual data read (if any). */
1611 void *pvData;
1612 } read;
1613 struct
1614 {
1615 /** How much data (in bytes) have been successfully written. */
1616 uint32_t cbWritten;
1617 } write;
1618 struct
1619 {
1620 /** New file offset after successful seek. */
1621 uint64_t uOffActual;
1622 } seek;
1623 struct
1624 {
1625 /** New file offset after successful tell. */
1626 uint64_t uOffActual;
1627 } tell;
1628 struct
1629 {
1630 /** The new file siz.e */
1631 uint64_t cbSize;
1632 } SetSize;
1633 } u;
1634} CALLBACKDATA_FILE_NOTIFY;
1635/** Pointer to a CALLBACKDATA_FILE_NOTIFY, struct. */
1636typedef CALLBACKDATA_FILE_NOTIFY *PCALLBACKDATA_FILE_NOTIFY;
1637
1638/**
1639 * Callback data for guest directory operations.
1640 */
1641typedef struct CALLBACKDATA_DIR_NOTIFY
1642{
1643 /** Callback data header. */
1644 CALLBACKDATA_HEADER hdr;
1645 /** Notification type. */
1646 uint32_t uType;
1647 /** IPRT result of overall operation. */
1648 uint32_t rc;
1649 union
1650 {
1651 struct
1652 {
1653 /** Pointer to directory information. */
1654 PGSTCTLFSOBJINFO pObjInfo;
1655 } info;
1656 struct
1657 {
1658 /** Guest directory handle. */
1659 uint32_t uHandle;
1660 } open;
1661 /** Note: Close does not have any additional data (yet). */
1662 struct
1663 {
1664 /** Pointer to directory entry information. */
1665 PGSTCTLDIRENTRYEX pEntry;
1666 /** Size (in bytes) of directory entry information. */
1667 uint32_t cbEntry;
1668 /** Resolved user name.
1669 * This is the object owner for UNIX-y Oses. */
1670 char *pszUser;
1671 /** Size (in bytes) of \a pszUser. */
1672 uint32_t cbUser;
1673 /** Resolved user group(s). */
1674 char *pszGroups;
1675 /** Size (in bytes) of \a pszGroups. */
1676 uint32_t cbGroups;
1677 } read;
1678 } u;
1679} CALLBACKDATA_DIR_NOTIFY;
1680/** Pointer to a CALLBACKDATA_DIR_NOTIFY struct. */
1681typedef CALLBACKDATA_DIR_NOTIFY *PCALLBACKDATA_DIR_NOTIFY;
1682
1683/**
1684 * Callback data for guest file system operations.
1685 */
1686typedef struct CALLBACKDATA_FS_NOTIFY
1687{
1688 /** Callback data header. */
1689 CALLBACKDATA_HEADER hdr;
1690 /** Notification type (of type GUEST_FS_NOTIFYTYPE_XXX). */
1691 uint32_t uType;
1692 /** IPRT result of overall operation. */
1693 uint32_t rc;
1694 union
1695 {
1696 struct
1697 {
1698 GSTCTLFSOBJINFO objInfo;
1699 /** Resolved user name. */
1700 char *pszUser;
1701 /** Size (in bytes) of \a pszUser. */
1702 uint32_t cbUser;
1703 /** Resolved user group(s). */
1704 char *pszGroups;
1705 /** Size (in bytes) of \a pszGroups. */
1706 uint32_t cbGroups;
1707 } QueryInfo;
1708 struct
1709 {
1710 /** Path of created temporary file / directory. */
1711 char *pszPath;
1712 /** Size (in bytes) of \a pszPath. */
1713 uint32_t cbPath;
1714 } CreateTemp;
1715 } u;
1716} CALLBACKDATA_FS_NOTIFY;
1717/** Pointer to a CALLBACKDATA_FS_NOTIFY struct. */
1718typedef CALLBACKDATA_FS_NOTIFY *PCALLBACKDATA_FS_NOTIFY;
1719#endif /* !MAIN_INCLUDED_GuestCtrlImplPrivate_h */
1720
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