* Functionality to utilize the hgfs server in bora/lib as a tools plugin.
*/
+#if defined(_WIN32)
+#include <windows.h>
+#endif // defined(_WIN32)
#include <string.h>
#define G_LOG_DOMAIN "hgfsd"
}
+#if defined(_WIN32)
+/**
+ * Starts the client driver service.
+ *
+ * @param[in] serviceControlManager Service Control Manager handle.
+ * @param[in] driverName Name of the driver service to start.
+ *
+ * @return ERROR_SUCCESS on success, an appropriate error otherwise.
+ */
+
+static DWORD
+HgfsServerStartClientService(SC_HANDLE serviceControlManager, // IN: control manager
+ PCWSTR driverName) // IN: driver name
+{
+ SC_HANDLE service;
+ DWORD result = ERROR_SUCCESS;
+
+ g_info("%s: starting service %S\n", __FUNCTION__, driverName);
+
+ /*
+ * Open the handle to the existing service.
+ */
+ service = OpenServiceW(serviceControlManager, driverName, SERVICE_ALL_ACCESS);
+ if (NULL == service) {
+ result = GetLastError();
+ g_warning("%s: Error: open service %S = %d \n", __FUNCTION__, driverName, result);
+ goto exit;
+ }
+
+ /*
+ * Start the execution of the service (i.e. start the driver).
+ */
+ if (!StartServiceW(service, 0, NULL)) {
+ result = GetLastError();
+
+ if (ERROR_SERVICE_ALREADY_RUNNING == result) {
+ result = ERROR_SUCCESS;
+ } else {
+ g_warning("%s: Error: start service %S = %d \n", __FUNCTION__, driverName, result);
+ }
+ goto exit;
+ }
+
+exit:
+ if (NULL != service) {
+ CloseServiceHandle(service);
+ }
+
+ return result;
+}
+#endif // defined(_WIN32)
+
+
+/**
+ * Start the HGFS client redirector.
+ *
+ * @return None.
+ */
+
+static void
+HgfsServerStartClientRedirector(void)
+{
+#if defined(_WIN32)
+ SC_HANDLE serviceControlManager = NULL;
+ PCWSTR driverName = L"vmhgfs";
+ DWORD result = ERROR_SUCCESS;
+
+ serviceControlManager = OpenSCManagerW(NULL, NULL, SERVICE_START);
+ if (NULL == serviceControlManager) {
+ result = GetLastError();
+ g_warning("%s: Error: Open SC Manager = %d \n", __FUNCTION__, result);
+ goto exit;
+ }
+ result = HgfsServerStartClientService(serviceControlManager, driverName);
+
+exit:
+ if (NULL != serviceControlManager) {
+ CloseServiceHandle(serviceControlManager);
+ }
+#endif // defined(_WIN32)
+}
+
+
/**
* Returns the registration data for the HGFS server.
*
return NULL;
}
+ if (TOOLS_IS_MAIN_SERVICE(ctx)) {
+ /* Start the Shared Folders redirector client. */
+ HgfsServerStartClientRedirector();
+ }
+
mgrData = g_malloc0(sizeof *mgrData);
HgfsServerManager_DataInit(mgrData,
ctx->name,