1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273
|
/*********************************************************
* Copyright (C) 2006 VMware, Inc. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation version 2.1 and no later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
*********************************************************/
/*
* hgfsServerManagerGuest.c --
*
* Functionality to utilize the hgfs server in bora/lib from within
* a guest application.
*
*/
#include "rpcout.h"
#include "rpcin.h"
#include "hgfsServerPolicy.h"
#include "hgfsServer.h"
#include "hgfsChannel.h"
#include "hgfsServerManager.h"
#include "vm_app.h"
#include "vm_assert.h"
#include "hgfs.h"
static Bool HgfsServerManagerRpcInDispatch(char const **result,
size_t *resultLen,
const char *name,
const char *args,
size_t argsSize,
void *clientData);
/*
*----------------------------------------------------------------------------
*
* HgfsChannel_Init --
*
* Sets up the channel for HGFS.
*
* NOTE: Initialize the Hgfs server for only for now.
* This will move into a separate file when full interface implemented.
*
* Results:
* TRUE on success, FALSE on failure.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------------
*/
Bool
HgfsChannel_Init(void *data) // IN: Unused rpc data
{
HgfsServerSessionCallbacks *serverCBTable = NULL;
return HgfsServer_InitState(&serverCBTable, NULL);
}
/*
*----------------------------------------------------------------------------
*
* HgfsChannel_Exit --
*
* Close the channel for HGFS.
*
* NOTE: Close open sessions in the HGFS server currently.
* This will move into a separate file when full interface implemented.
*
* Results:
* None.
*
* Side effects:
* Closes the worker group and all the channels.
*
*----------------------------------------------------------------------------
*/
void
HgfsChannel_Exit(void *data) // IN: Unused rpc data
{
ASSERT(data != NULL);
HgfsServer_ExitState();
}
/*
*----------------------------------------------------------------------------
*
* HgfsServerManagerRpcInDispatch --
*
* Handles hgfs requests.
*
* Results:
* TRUE on success, FALSE on error.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------------
*/
static Bool
HgfsServerManagerRpcInDispatch(char const **result, // OUT
size_t *resultLen, // OUT
const char *name, // IN
const char *args, // IN
size_t argsSize, // IN
void *clientData) // Unused
{
size_t packetSize;
static char packet[HGFS_LARGE_PACKET_MAX];
ASSERT(clientData == NULL);
if (argsSize == 0) {
return RpcIn_SetRetVals(result, resultLen, "1 argument required", FALSE);
}
ASSERT(args[0] == ' ');
packetSize = argsSize - 1;
HgfsServer_ProcessPacket((char const *)(args + 1), packet, &packetSize, 0);
*result = packet;
*resultLen = packetSize;
return TRUE;
}
/*
*-----------------------------------------------------------------------------
*
* HgfsServerManager_CapReg --
*
* Tell the vmx that the specified guest app can (or no longer can)
* receive hgfs requests.
*
* Results:
* TRUE on success, FALSE on failure.
*
* Side effects:
* None.
*
*-----------------------------------------------------------------------------
*/
Bool
HgfsServerManager_CapReg(const char *appName, // IN
Bool enable) // IN
{
/*
* Register/unregister this channel as an hgfs server.
*/
if (!RpcOut_sendOne(NULL, NULL, "tools.capability.hgfs_server %s %s",
appName, enable ? "1" : "0")) {
return FALSE;
}
return TRUE;
}
/*
*----------------------------------------------------------------------------
*
* HgfsServerManager_Register --
*
* Registers the hgfs server to be used in classic synchronous fashion.
*
* Results:
* TRUE on success, FALSE on failure.
*
* Side effects:
* Hgfs packets sent to this channel will be handled.
*
*----------------------------------------------------------------------------
*/
Bool
HgfsServerManager_Register(void *rpcIn, // IN: RpcIn channel
const char *appName) // IN: App with HGFS server
{
RpcIn *myRpcIn = (RpcIn *)rpcIn;
/*
* myRpcIn may be NULL for some cases. When we run the tools as
* a guest application in a non-VMware VM, for example, we do not
* have a backdoor.
*/
ASSERT(appName);
/*
* Passing NULL here is safe because the shares maintained by the guest
* policy server never change, invalidating the need for an invalidate
* function.
*/
if (!HgfsServerPolicy_Init(NULL)) {
return FALSE;
}
if (!HgfsChannel_Init(myRpcIn)) {
HgfsServerPolicy_Cleanup();
return FALSE;
}
if (NULL != myRpcIn) {
RpcIn_RegisterCallback(myRpcIn, HGFS_SYNC_REQREP_CMD,
HgfsServerManagerRpcInDispatch, NULL);
}
/*
* Prior to WS55, the VMX did not know about the "hgfs_server"
* capability. This doesn't mean that the HGFS server wasn't needed, it's
* just that the capability was introduced in CS 225439 so that the VMX
* could decide which HGFS server to communicate with.
*
* Long story short, we shouldn't care if this function fails.
*/
if (NULL != myRpcIn) {
HgfsServerManager_CapReg(appName, TRUE);
}
return TRUE;
}
/*
*----------------------------------------------------------------------------
*
* HgfsServerManager_Unregister --
*
* Cleans up the hgfs server.
*
* Results:
* None.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------------
*/
void
HgfsServerManager_Unregister(void *rpcIn, // IN: RpcIn channel
const char *appName) // IN: App with HGFS server
{
RpcIn *myRpcIn = (RpcIn *)rpcIn;
ASSERT(myRpcIn);
ASSERT(appName);
HgfsServerManager_CapReg(appName, FALSE);
RpcIn_UnregisterCallback(myRpcIn, HGFS_SYNC_REQREP_CMD);
HgfsChannel_Exit(myRpcIn);
HgfsServerPolicy_Cleanup();
}
|