VBoxManageGuestCtrl.cpp revision a7014c99617f226a35a6a46a5b4bddcc6e0c17e0
/* $Id$ */
/** @file
* VBoxManage - Implementation of guestcontrol command.
*/
/*
* Copyright (C) 2010-2011 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include "VBoxManage.h"
#ifndef VBOX_ONLY_DOCS
#include <map>
#include <vector>
#ifdef USE_XPCOM_QUEUE
# include <errno.h>
#endif
#include <signal.h>
#ifdef RT_OS_DARWIN
# include <CoreFoundation/CFRunLoop.h>
#endif
using namespace com;
/**
* IVirtualBoxCallback implementation for handling the GuestControlCallback in
* relation to the "guestcontrol * wait" command.
*/
/** @todo */
/** Set by the signal handler. */
static volatile bool g_fGuestCtrlCanceled = false;
typedef struct COPYCONTEXT
{
bool fVerbose;
bool fDryRun;
bool fHostToGuest;
char *pszUsername;
char *pszPassword;
} COPYCONTEXT, *PCOPYCONTEXT;
/**
* An entry for a source element, including an optional DOS-like wildcard (*,?).
*/
class SOURCEFILEENTRY
{
public:
SOURCEFILEENTRY(const char *pszSource)
{
}
const char* GetSource() const
{
}
const char* GetFilter() const
{
}
private:
{
if ( !RTFileExists(pszPath)
&& !RTDirExists(pszPath))
{
/* No file and no directory -- maybe a filter? */
if ( pszFilename
{
/* Yep, get the actual filter part. */
/* Remove the filter from actual sourcec directory name. */
}
}
return VINF_SUCCESS; /* @todo */
}
private:
};
/**
*/
typedef struct DESTFILEENTRY
{
/*
* Map for holding destination entires, whereas the key is the destination
* directory and the mapped value is a vector holding all elements for this directoy.
*/
/**
* Special exit codes for returning errors/information of a
* started guest process to the command line VBoxManage was started from.
* Useful for e.g. scripting.
*
* @note These are frozen as of 4.1.0.
*/
enum EXITCODEEXEC
{
/* Process exited normally but with an exit code <> 0. */
EXITCODEEXEC_CODE = 16,
EXITCODEEXEC_FAILED = 17,
EXITCODEEXEC_TERM_SIGNAL = 18,
EXITCODEEXEC_TERM_ABEND = 19,
EXITCODEEXEC_TIMEOUT = 20,
EXITCODEEXEC_DOWN = 21,
};
/**
* RTGetOpt-IDs for the guest execution control command line.
*/
enum GETOPTDEF_EXEC
{
};
enum GETOPTDEF_COPYFROM
{
GETOPTDEF_COPYFROM_DRYRUN = 1000,
};
enum GETOPTDEF_COPYTO
{
GETOPTDEF_COPYTO_DRYRUN = 1000,
};
enum GETOPTDEF_MKDIR
{
GETOPTDEF_MKDIR_PASSWORD = 1000,
};
enum GETOPTDEF_STAT
{
GETOPTDEF_STAT_PASSWORD = 1000,
};
enum OUTPUTTYPE
{
OUTPUTTYPE_UNDEFINED = 0,
OUTPUTTYPE_DOS2UNIX = 10,
OUTPUTTYPE_UNIX2DOS = 20
};
static int ctrlCopyDirExists(PCOPYCONTEXT pContext, bool bGuest, const char *pszDir, bool *fExists);
#endif /* VBOX_ONLY_DOCS */
{
"VBoxManage guestcontrol <vmname>|<uuid>\n"
" exec[ute]\n"
" --image <path to program>\n"
" --username <name> --password <password>\n"
" [--dos2unix]\n"
" [--environment \"<NAME>=<VALUE> [<NAME>=<VALUE>]\"]\n"
" [--timeout <msec>] [--unix2dos] [--verbose]\n"
" [--wait-exit] [--wait-stdout] [--wait-stderr]\n"
" [-- [<argument1>] ... [<argumentN>]]\n"
/** @todo Add a "--" parameter (has to be last parameter) to directly execute
"\n"
" copyfrom\n"
" <source on guest> <destination on host>\n"
" --username <name> --password <password>\n"
" [--dryrun] [--follow] [--recursive] [--verbose]\n"
"\n"
" copyto|cp\n"
" <source on host> <destination on guest>\n"
" --username <name> --password <password>\n"
" [--dryrun] [--follow] [--recursive] [--verbose]\n"
"\n"
" createdir[ectory]|mkdir|md\n"
" <director[y|ies] to create on guest>\n"
" --username <name> --password <password>\n"
" [--parents] [--mode <mode>] [--verbose]\n"
"\n"
" stat\n"
" <file element(s) to check on guest>\n"
" --username <name> --password <password>\n"
" [--verbose]\n"
"\n"
" updateadditions\n"
" [--source <guest additions .ISO>] [--verbose]\n"
"\n");
}
#ifndef VBOX_ONLY_DOCS
/**
* Signal handler that sets g_fGuestCtrlCanceled.
*
* This can be executed on any thread in the process, on Windows it may even be
* a thread dedicated to delivering this signal. Do not doing anything
* unnecessary here.
*/
static void guestCtrlSignalHandler(int iSignal)
{
ASMAtomicWriteBool(&g_fGuestCtrlCanceled, true);
}
/**
* Installs a custom signal handler to get notified
* whenever the user wants to intercept the program.
*/
static void ctrlSignalHandlerInstall()
{
#ifdef SIGBREAK
#endif
}
/**
* Uninstalls a previously installed signal handler.
*/
static void ctrlSignalHandlerUninstall()
{
#ifdef SIGBREAK
#endif
}
/**
* Translates a process status to a human readable
* string.
*/
{
switch (enmStatus)
{
return "started";
return "successfully terminated";
return "terminated by signal";
return "abnormally aborted";
return "timed out";
return "timed out, hanging";
return "killed";
return "error";
default:
break;
}
return "unknown";
}
{
int rc = EXITCODEEXEC_SUCCESS;
switch (enmStatus)
{
break;
break;
break;
break;
break;
break;
* not exactly an error of the started process ... */
break;
break;
default:
break;
}
return rc;
}
{
if ( errorInfo.isFullAvailable()
|| errorInfo.isBasicAvailable())
{
/* If we got a VBOX_E_IPRT error we handle the error in a more gentle way
* because it contains more accurate info about what went wrong. */
else
{
RTMsgError("Error details:");
}
return VERR_GENERAL_FAILURE; /** @todo */
}
}
{
return ctrlPrintError(ErrInfo);
}
{
int rc;
&& fCanceled)
{
rc = VERR_CANCELLED;
}
else
{
}
return rc;
}
/**
* Un-initializes the VM after guest control usage.
*/
{
}
/**
* Initializes the VM for IGuest operations.
*
* That is, checks whether it's up and running, if it can be locked (shared
* only) and returns a valid IGuest pointer on success.
*
* @return IPRT status code.
* @param pArg Our command line argument structure.
* @param pszNameOrId The VM's name or UUID.
* @param pGuest Where to return the IGuest interface pointer.
*/
{
/* Lookup VM. */
/* Assume it's an UUID. */
machine.asOutParam()));
return VERR_NOT_FOUND;
/* Machine is running? */
if (machineState != MachineState_Running)
{
RTMsgError("Machine \"%s\" is not running (currently %s)!\n",
return VERR_VM_INVALID_VM_STATE;
}
do
{
/* Open a session for the VM. */
/* Get the associated console. */
/* ... and session machine. */
/* Get IGuest interface. */
} while (0);
}
/**
* Prints the desired guest output to a stream.
*
* @return IPRT status code.
* @param pGuest Pointer to IGuest interface.
* @param uPID PID of guest process to get the output from.
* @param fOutputFlags Output flags of type ProcessOutputFlag.
* @param cMsTimeout Timeout value (in ms) to wait for output.
*/
{
ULONG cbOutputData = 0;
int vrc = VINF_SUCCESS;
{
cbOutputData = 0;
}
else
{
if (cbOutputData > 0)
{
/** @todo r=bird: Use a VFS I/O stream filter for doing this, it's a
* generic problem and the new VFS APIs will handle it more
/*
* If aOutputData is text data from the guest process' stdout or stderr,
* it has a platform dependent line ending. So standardize on
*/
char *pszBufUTF8;
if (RT_SUCCESS(vrc))
{
for (char *s = pszBufUTF8, *d = s;
s++, d++)
{
if (*s == '\r')
{
/* skip over CR, adjust destination */
d--;
}
else if (s != d)
*d = *s;
}
if (RT_FAILURE(vrc))
}
else
}
}
return vrc;
}
/**
* Returns the remaining time (in ms) based on the start time and a set
* timeout value. Returns RT_INDEFINITE_WAIT if no timeout was specified.
*
* @return RTMSINTERVAL Time left (in ms).
* @param u64StartMs Start time (in ms).
* @param u32TimeoutMs Timeout value (in ms).
*/
{
if (!u32TimeoutMs) /* If no timeout specified, wait forever. */
return RT_INDEFINITE_WAIT;
if (u64ElapsedMs >= u32TimeoutMs)
return 0;
return u32TimeoutMs - u64ElapsedMs;
}
/* <Missing docuemntation> */
{
/*
* Parse arguments.
*/
if (pArg->argc < 2) /* At least the command we want to execute in the guest should be present :-). */
static const RTGETOPTDEF s_aOptions[] =
{
};
int ch;
uint32_t cMsTimeout = 0;
bool fOutputBinary = false;
bool fWaitForExit = false;
bool fVerbose = false;
int vrc = VINF_SUCCESS;
&& RT_SUCCESS(vrc))
{
/* For options that require an argument, ValueUnion has received the value. */
switch (ch)
{
case GETOPTDEF_EXEC_DOS2UNIX:
if (eOutputType != OUTPUTTYPE_UNDEFINED)
break;
case 'e': /* Environment */
{
char **papszArg;
int cArgs;
if (RT_FAILURE(vrc))
for (int j = 0; j < cArgs; j++)
break;
}
break;
break;
case 'i':
break;
/** @todo Add a hidden flag. */
case 'p': /* Password */
break;
case 't': /* Timeout */
break;
case GETOPTDEF_EXEC_UNIX2DOS:
if (eOutputType != OUTPUTTYPE_UNDEFINED)
break;
case 'u': /* User name */
break;
case 'v': /* Verbose */
fVerbose = true;
break;
fWaitForExit = true;
break;
fWaitForExit = true;
break;
fWaitForExit = true;
break;
case VINF_GETOPT_NOT_OPTION:
{
else
break;
}
default:
}
}
if (Utf8UserName.isEmpty())
/* Any output conversion not supported yet! */
if (eOutputType != OUTPUTTYPE_UNDEFINED)
/*
* <missing comment indicating that we're done parsing args and started doing something else>
*/
if (fVerbose)
{
if (cMsTimeout == 0)
RTPrintf("Waiting for guest to start process ...\n");
else
}
/* Get current time stamp to later calculate rest of timeout left. */
/* Execute the process. */
int rcProc = RTEXITCODE_FAILURE;
&uPID,
progress.asOutParam());
if (fVerbose)
if (fWaitForExit)
{
if (fVerbose)
{
if (cMsTimeout) /* Wait with a certain timeout. */
{
/* Calculate timeout value left after process has been started. */
/* Is timeout still bigger than current difference? */
if (cMsTimeout > u64Elapsed)
else
}
else /* Wait forever. */
RTPrintf("Waiting for process to exit ...\n");
}
/* Setup signal handling if cancelable. */
bool fCanceledAlready = false;
fCancelable = FALSE;
if (fCancelable)
if (RT_FAILURE(vrc))
/* Wait for process to exit ... */
&& !fCompleted)
{
/* Do we need to output stuff? */
{
if (cMsTimeLeft)
}
{
if (cMsTimeLeft)
}
/* Process async cancelation */
if (g_fGuestCtrlCanceled && !fCanceledAlready)
{
else
g_fGuestCtrlCanceled = false;
}
/* Progress canceled by Main API? */
&& fCanceled)
break;
/* Did we run out of time? */
if ( cMsTimeout
{
break;
}
} /* while */
/* Undo signal handling */
if (fCancelable)
/* Report status back to the user. */
if (fCanceled)
{
if (fVerbose)
RTPrintf("Process execution canceled!\n");
}
else if ( fCompleted
{
else
{
RTPrintf("Exit code=%u (Status=%u [%s], Flags=%u)\n", uRetExitCode, retStatus, ctrlExecProcessStatusToText(retStatus), uRetFlags);
}
}
else
{
if (fVerbose)
RTPrintf("Process execution aborted!\n");
}
}
return RTEXITCODE_FAILURE;
return rcProc;
}
/**
* Creates a copy context structure which then can be used with various
* guest control copy functions. Needs to be free'd with ctrlCopyContextFree().
*
* @return IPRT status code.
* @param pGuest Pointer to IGuest interface to use.
* @param fVerbose Flag indicating if we want to run in verbose mode.
* @param fDryRun Flag indicating if we want to run a dry run only.
* @param fHostToGuest Flag indicating if we want to copy from host to guest
* or vice versa.
* @param pszUsername Username of account to use on the guest side.
* @param pszPassword Password of account to use.
* @param ppContext Pointer which receives the allocated copy context.
*/
bool fHostToGuest,
const char *pszUsername, const char *pszPassword,
{
if (!pContext->pszUsername)
{
return VERR_NO_MEMORY;
}
if (!pContext->pszPassword)
{
return VERR_NO_MEMORY;
}
return VINF_SUCCESS;
}
/**
* Frees are previously allocated copy context structure.
*
* @param pContext Pointer to copy context to free.
*/
{
if (pContext)
{
}
}
/**
* Translates a source path to a destintation path (can be both sides,
* either host or guest). The source root is needed to determine the start
* of the relative source path which also needs to present in the destination
* path.
*
* @return IPRT status code.
* @param pszSourceRoot Source root path. No trailing directory slash!
* @param pszSource Actual source to transform. Must begin with
* the source root path!
* @param pszDest Destination path.
* @param ppszTranslated Pointer to the allocated, translated destination
* path. Must be free'd with RTStrFree().
*/
const char *pszDest, char **ppszTranslated)
{
/* Construct the relative dest destination path by "subtracting" the
* source from the source root, e.g.
*
* source root path = "e:\foo\", source = "e:\foo\bar"
* dest = "d:\baz\"
* translated = "d:\baz\bar\"
*/
char szTranslated[RTPATH_MAX];
int rc;
if (!RTPathFilename(pszDestPath))
{
}
else
{
if (pszDestFileName)
{
}
else
rc = VERR_NO_MEMORY;
}
if (RT_SUCCESS(rc))
{
#if 0
RTPrintf("Root: %s, Source: %s, Dest: %s, Translated: %s\n",
#endif
}
return rc;
}
#ifdef DEBUG_andy
static int tstTranslatePath()
{
RTAssertSetMayPanic(false /* Do not freak out, please. */);
static struct
{
const char *pszSourceRoot;
const char *pszSource;
const char *pszDest;
const char *pszTranslated;
int iResult;
} aTests[] =
{
/* Invalid stuff. */
#ifdef RT_OS_WINDOWS
/* Windows paths. */
#else /* RT_OS_WINDOWS */
{ "/home/test/foo", "/home/test/foo/baz/bar.txt", "/opt/test", "/opt/test/baz/bar.txt", VINF_SUCCESS },
#endif /* !RT_OS_WINDOWS */
/* Mixed paths*/
/** @todo */
{ NULL }
};
{
RTPrintf("\tSourceRoot=%s, Source=%s, Dest=%s\n",
char *pszTranslated = NULL;
{
RTPrintf("\tReturned %Rrc, expected %Rrc\n",
}
else if ( pszTranslated
{
RTPrintf("\tReturned translated path %s, expected %s\n",
}
if (pszTranslated)
{
}
}
return VINF_SUCCESS; /* @todo */
}
#endif
/**
* Creates a directory on the destination, based on the current copy
* context.
*
* @return IPRT status code.
* @param pContext Pointer to current copy control context.
* @param pszDir Directory to create.
*/
{
bool fDirExists;
if ( RT_SUCCESS(rc)
&& fDirExists)
{
return VINF_SUCCESS;
}
return VINF_SUCCESS;
{
0700, DirectoryCreateFlag_Parents);
}
else /* ... or on the host. */
{
if (rc == VERR_ALREADY_EXISTS)
rc = VINF_SUCCESS;
}
return rc;
}
/**
*
* @return IPRT status code.
* @param pContext Pointer to current copy control context.
* @param bGuest true if directory needs to be checked on the guest
* or false if on the host.
* @param pszDir Actual directory to check.
* @param fExists Pointer which receives the result if the
* given directory exists or not.
*/
{
AssertPtrReturn(pContext, false);
AssertPtrReturn(pszDir, false);
AssertPtrReturn(fExists, false);
int rc = VINF_SUCCESS;
if (bGuest)
{
/** @todo Replace with DirectoryExists as soon as API is in place. */
else
*fExists = fDirExists ? true : false;
}
else
return rc;
}
/**
* Checks whether a specific directory exists on the destination, based
* on the current copy context.
*
* @return IPRT status code.
* @param pContext Pointer to current copy control context.
* @param pszDir Actual directory to check.
* @param fExists Pointer which receives the result if the
* given directory exists or not.
*/
bool *fExists)
{
}
/**
* Checks whether a specific directory exists on the source, based
* on the current copy context.
*
* @return IPRT status code.
* @param pContext Pointer to current copy control context.
* @param pszDir Actual directory to check.
* @param fExists Pointer which receives the result if the
* given directory exists or not.
*/
bool *fExists)
{
}
/**
*
* @return IPRT status code.
* @param pContext Pointer to current copy control context.
* @param bGuest true if file needs to be checked on the guest
* or false if on the host.
* @param pszFile Actual file to check.
* @param fExists Pointer which receives the result if the
* given file exists or not.
*/
{
AssertPtrReturn(pContext, false);
AssertPtrReturn(pszFile, false);
AssertPtrReturn(fExists, false);
int rc = VINF_SUCCESS;
if (bOnGuest)
{
else
*fExists = fFileExists ? true : false;
}
else
return rc;
}
/**
* Checks whether a specific file exists on the destination, based on the
* current copy context.
*
* @return IPRT status code.
* @param pContext Pointer to current copy control context.
* @param pszFile Actual file to check.
* @param fExists Pointer which receives the result if the
* given file exists or not.
*/
bool *fExists)
{
}
/**
* Checks whether a specific file exists on the source, based on the
* current copy context.
*
* @return IPRT status code.
* @param pContext Pointer to current copy control context.
* @param pszFile Actual file to check.
* @param fExists Pointer which receives the result if the
* given file exists or not.
*/
bool *fExists)
{
}
/**
* Copies a source file to the destination.
*
* @return IPRT status code.
* @param pContext Pointer to current copy control context.
* @param pszFileSource Source file to copy to the destination.
* @param pszFileDest Name of copied file on the destination.
* @param fFlags Copy flags. No supported at the moment and needs
* to be set to 0.
*/
{
RTPrintf("Copying \"%s\" to \"%s\" ...\n",
return VINF_SUCCESS;
int vrc = VINF_SUCCESS;
if (pContext->fHostToGuest)
{
}
else
{
}
else
{
else
}
return vrc;
}
/**
* Copys a directory (tree) from host to the guest.
*
* @return IPRT status code.
* @param pContext Pointer to current copy control context.
* @param pszSource Source directory on the host to copy to the guest.
* @param pszFilter DOS-style wildcard filter (?, *). Optional.
* @param pszDest Destination directory on the guest.
* @param fFlags Copy flags, such as recursive copying.
* @param pszSubDir Current sub directory to handle. Needs to NULL and only
* is needed for recursion.
*/
const char *pszSubDir /* For recursion. */)
{
/* Filter is optional. */
/* Sub directory is optional. */
/*
* Construct current path.
*/
char szCurDir[RTPATH_MAX];
/* Flag indicating whether the current directory was created on the
* target or not. */
bool fDirCreated = false;
/*
* Open directory without a filter - RTDirOpenFiltered unfortunately
* cannot handle sub directories so we have to do the filtering ourselves.
*/
if (RT_SUCCESS(rc))
{
if (RT_FAILURE(rc))
}
if (RT_SUCCESS(rc))
{
/*
* Enumerate the directory tree.
*/
while (RT_SUCCESS(rc))
{
if (RT_FAILURE(rc))
{
if (rc == VERR_NO_MORE_FILES)
rc = VINF_SUCCESS;
break;
}
{
case RTDIRENTRYTYPE_DIRECTORY:
{
/* Skip "." and ".." entries. */
break;
if (fFlags & CopyFileFlag_Recursive)
{
if (pszSubDir)
else
{
}
if (pszNewSub)
{
}
else
rc = VERR_NO_MEMORY;
}
break;
}
case RTDIRENTRYTYPE_SYMLINK:
if ( (fFlags & CopyFileFlag_Recursive)
&& (fFlags & CopyFileFlag_FollowLinks))
{
/* Fall through to next case is intentional. */
}
else
break;
case RTDIRENTRYTYPE_FILE:
{
if ( pszFilter
{
break; /* Filter does not match. */
}
if (!fDirCreated)
{
char *pszDestDir;
pszDest, &pszDestDir);
if (RT_SUCCESS(rc))
{
fDirCreated = true;
}
}
if (RT_SUCCESS(rc))
{
if (pszFileSource)
{
char *pszFileDest;
pszDest, &pszFileDest);
if (RT_SUCCESS(rc))
{
pszFileDest, 0 /* Flags */);
}
}
}
break;
}
default:
break;
}
if (RT_FAILURE(rc))
break;
}
}
return rc;
}
/**
* Copys a directory (tree) from guest to the host.
*
* @return IPRT status code.
* @param pContext Pointer to current copy control context.
* @param pszSource Source directory on the guest to copy to the host.
* @param pszFilter DOS-style wildcard filter (?, *). Optional.
* @param pszDest Destination directory on the host.
* @param fFlags Copy flags, such as recursive copying.
* @param pszSubDir Current sub directory to handle. Needs to NULL and only
* is needed for recursion.
*/
const char *pszSubDir /* For recursion. */)
{
/* Filter is optional. */
/* Sub directory is optional. */
/*
* Construct current path.
*/
char szCurDir[RTPATH_MAX];
if (RT_FAILURE(rc))
return rc;
/* Flag indicating whether the current directory was created on the
* target or not. */
bool fDirCreated = false;
DirectoryOpenFlag_None /* No flags supported yet. */,
&uDirHandle);
else
{
{
switch (enmType)
{
{
/* Skip "." and ".." entries. */
break;
{
}
if (fFlags & CopyFileFlag_Recursive)
{
if (pszSubDir)
else
{
}
if (pszNewSub)
{
}
else
rc = VERR_NO_MEMORY;
}
break;
}
if ( (fFlags & CopyFileFlag_Recursive)
&& (fFlags & CopyFileFlag_FollowLinks))
{
/* Fall through to next case is intentional. */
}
else
break;
case GuestDirEntryType_File:
{
if ( pszFilter
{
break; /* Filter does not match. */
}
if (!fDirCreated)
{
char *pszDestDir;
pszDest, &pszDestDir);
if (RT_SUCCESS(rc))
{
fDirCreated = true;
}
}
if (RT_SUCCESS(rc))
{
if (pszFileSource)
{
char *pszFileDest;
pszDest, &pszFileDest);
if (RT_SUCCESS(rc))
{
pszFileDest, 0 /* Flags */);
}
}
else
rc = VERR_NO_MEMORY;
}
break;
}
default:
RTPrintf("Warning: Directory entry of type %ld not handled, skipping ...\n",
enmType);
break;
}
if (RT_FAILURE(rc))
break;
}
{
switch (hr)
{
case E_ABORT: /* No more directory entries left to process. */
break;
case VBOX_E_FILE_ERROR: /* Current entry cannot be accessed to
to missing rights. */
{
RTPrintf("Warning: Cannot access \"%s\", skipping ...\n",
szCurDir);
break;
}
default:
break;
}
}
{
if (RT_SUCCESS(rc))
}
}
return rc;
}
/**
* Copys a directory (tree) to the destination, based on the current copy
* context.
*
* @return IPRT status code.
* @param pContext Pointer to current copy control context.
* @param pszSource Source directory to copy to the destination.
* @param pszFilter DOS-style wildcard filter (?, *). Optional.
* @param pszDest Destination directory where to copy in the source
* source directory.
* @param fFlags Copy flags, such as recursive copying.
*/
{
if (pContext->fHostToGuest)
}
/**
* Creates a source root by stripping file names or filters of the specified source.
*
* @return IPRT status code.
* @param pszSource Source to create source root for.
* @param ppszSourceRoot Pointer that receives the allocated source root. Needs
* to be free'd with ctrlCopyFreeSourceRoot().
*/
{
if ( lenRoot
&& lenRoot > 1
{
if (lenRoot > 1)
}
else
{
/* If there's anything (like a file name or a filter),
* strip it! */
}
return VINF_SUCCESS;
}
/**
* Frees a previously allocated source root.
*
* @return IPRT status code.
* @param pszSourceRoot Source root to free.
*/
static void ctrlCopyFreeSourceRoot(char *pszSourceRoot)
{
}
bool fHostToGuest)
{
/** @todo r=bird: This command isn't very unix friendly in general. mkdir
* is much better (partly because it is much simpler of course). The main
* arguments against this is that (1) all but two options conflicts with
* done windows CMD style (though not in a 100% compatible way), and (3)
* that only one source is allowed - efficiently sabotaging default
* wildcard expansion by a unix shell. The best solution here would be
* two different variant, one windowsy (xcopy) and one unixy (gnu cp). */
/*
* IGuest::CopyToGuest is kept as simple as possible to let the developer choose
* what and how to implement the file enumeration/recursive lookup, like VBoxManage
* does in here.
*/
static const RTGETOPTDEF s_aOptions[] =
{
};
int ch;
bool fVerbose = false;
bool fCopyRecursive = false;
bool fDryRun = false;
int vrc = VINF_SUCCESS;
{
/* For options that require an argument, ValueUnion has received the value. */
switch (ch)
{
case GETOPTDEF_COPYTO_DRYRUN:
fDryRun = true;
break;
case GETOPTDEF_COPYTO_FOLLOW:
break;
break;
case 'R': /* Recursive processing */
break;
break;
break;
case 'v': /* Verbose */
fVerbose = true;
break;
case VINF_GETOPT_NOT_OPTION:
{
/* Last argument and no destination specified with
* --target-directory yet? Then use the current
* (= last) argument as destination. */
{
}
else
{
/* Save the source directory. */
}
break;
}
default:
}
}
if (!vecSources.size())
return errorSyntax(USAGE_GUESTCONTROL,
"No source(s) specified!");
return errorSyntax(USAGE_GUESTCONTROL,
"No destination specified!");
if (Utf8UserName.isEmpty())
return errorSyntax(USAGE_GUESTCONTROL,
"No user name specified!");
/*
* Done parsing arguments, do some more preparations.
*/
if (fVerbose)
{
if (fHostToGuest)
RTPrintf("Copying from host to guest ...\n");
else
RTPrintf("Copying from guest to host ...\n");
if (fDryRun)
RTPrintf("Dry run - no files copied!\n");
}
/* Create the copy context -- it contains all information
* the routines need to know when handling the actual copying. */
&pContext);
if (RT_FAILURE(vrc))
{
return RTEXITCODE_FAILURE;
}
/* If the destination is a path, (try to) create it. */
if (!RTPathFilename(pszDest))
{
}
else
{
/* We assume we got a file name as destination -- so strip
* the actual file name and make sure the appropriate
* directories get created. */
}
if (RT_SUCCESS(vrc))
{
/*
* Here starts the actual fun!
* Handle all given sources one by one.
*/
for (unsigned long s = 0; s < vecSources.size(); s++)
{
char *pszSourceRoot;
if (RT_FAILURE(vrc))
{
break;
}
if (fVerbose)
/** @todo Files with filter?? */
bool fSourceIsFile = false;
bool fSourceExists;
if ( cchSource > 1
{
if (pszFilter) /* Directory with filter (so use source root w/o the actual filter). */
else /* Regular directory without filter. */
if (fSourceExists)
{
/* Strip trailing slash from our source element so that other functions
* can use this stuff properly (like RTPathStartsWith). */
}
}
else
{
if ( RT_SUCCESS(vrc)
&& fSourceExists)
{
fSourceIsFile = true;
}
}
if ( RT_SUCCESS(vrc)
&& fSourceExists)
{
if (fSourceIsFile)
{
/* Single file. */
char *pszDestFile;
if (RT_SUCCESS(vrc))
{
pszDestFile, 0 /* Flags */);
}
else
RTMsgError("Unable to translate path for \"%s\", rc=%Rrc\n",
}
else
{
/* Directory (with filter?). */
}
}
if ( RT_SUCCESS(vrc)
&& !fSourceExists)
{
RTMsgError("Warning: Source \"%s\" does not exist, skipping!\n",
continue;
}
else if (RT_FAILURE(vrc))
{
RTMsgError("Error processing \"%s\", rc=%Rrc\n",
break;
}
}
}
}
{
/*
* Parse arguments.
*
* Note! No direct returns here, everyone must go thru the cleanup at the
* end of this function.
*/
static const RTGETOPTDEF s_aOptions[] =
{
};
int ch;
bool fVerbose = false;
&& rcExit == RTEXITCODE_SUCCESS)
{
/* For options that require an argument, ValueUnion has received the value. */
switch (ch)
{
case 'm': /* Mode */
break;
case 'P': /* Create parents */
break;
case GETOPTDEF_MKDIR_PASSWORD: /* Password */
break;
case GETOPTDEF_MKDIR_USERNAME: /* User name */
break;
case 'v': /* Verbose */
fVerbose = true;
break;
case VINF_GETOPT_NOT_OPTION:
{
break;
}
default:
break;
}
}
if (rcExit == RTEXITCODE_SUCCESS)
{
/*
* Create the directories.
*/
{
if (fVerbose)
{
break;
}
it++;
}
}
return rcExit;
}
{
static const RTGETOPTDEF s_aOptions[] =
{
};
int ch;
bool fVerbose = false;
&& rcExit == RTEXITCODE_SUCCESS)
{
/* For options that require an argument, ValueUnion has received the value. */
switch (ch)
{
case GETOPTDEF_STAT_PASSWORD: /* Password */
break;
case GETOPTDEF_STAT_USERNAME: /* User name */
break;
case 'L': /* Dereference */
case 'f': /* File-system */
case 'c': /* Format */
case 't': /* Terse */
break; /* Never reached. */
case 'v': /* Verbose */
fVerbose = true;
break;
case VINF_GETOPT_NOT_OPTION:
{
break;
}
default:
break; /* Never reached. */
}
}
if (rcExit == RTEXITCODE_SUCCESS)
{
/*
* Create the directories.
*/
{
if (fVerbose)
&fExists);
{
break;
}
else
{
/** @todo: Output vbox_stat's stdout output to get more information about
* what happened. */
/* If there's at least one element which does not exist on the guest,
* drop out with exitcode 1. */
if (!fExists)
{
RTPrintf("Cannot stat for element \"%s\": No such file or directory\n",
}
}
it++;
}
}
return rcExit;
}
{
/*
* Check the syntax. We can deduce the correct syntax from the number of
* arguments.
*/
bool fVerbose = false;
static const RTGETOPTDEF s_aOptions[] =
{
};
int ch;
int vrc = VINF_SUCCESS;
&& RT_SUCCESS(vrc))
{
switch (ch)
{
case 's':
break;
case 'v':
fVerbose = true;
break;
default:
}
}
if (fVerbose)
RTPrintf("Updating Guest Additions ...\n");
#ifdef DEBUG_andy
if (Utf8Source.isEmpty())
Utf8Source = "c:\\Downloads\\VBoxGuestAdditions-r67158.iso";
#endif
/* Determine source if not set yet. */
if (Utf8Source.isEmpty())
{
char strTemp[RTPATH_MAX];
/* Check the standard image locations */
else
{
RTMsgError("Source could not be determined! Please use --source to specify a valid source\n");
}
}
{
}
if (RT_SUCCESS(vrc))
{
if (fVerbose)
/* Wait for whole update process to complete. */
progress.asOutParam()));
else
{
if (fVerbose)
else
&& fVerbose)
{
RTPrintf("Guest Additions update successful\n");
}
}
}
}
/**
* Access the guest control store.
*
* @returns program exit code.
* @note see the command line API description for parameters
*/
{
#ifdef DEBUG_andy_disabled
if (RT_FAILURE(tstTranslatePath()))
return RTEXITCODE_FAILURE;
#endif
if (RT_SUCCESS(vrc))
{
int rcExit;
{
}
{
false /* Guest to host */);
}
{
true /* Host to guest */);
}
{
}
{
}
{
}
else
return rcExit;
}
return RTEXITCODE_FAILURE;
}
#endif /* !VBOX_ONLY_DOCS */