~ubuntu-branches/ubuntu/quantal/open-vm-tools/quantal-201210021442

« back to all changes in this revision

Viewing changes to lib/hgfsServerManagerGuest/hgfsChannelGuestBd.c

  • Committer: Bazaar Package Importer
  • Author(s): Serge Hallyn
  • Date: 2011-03-31 14:20:05 UTC
  • mfrom: (1.4.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20110331142005-3n9red91p7ogkweo
Tags: 2011.03.28-387002-0ubuntu1
* Merge latest upstream git tag.  This has the unlocked_ioctl change
  needed to fix dkms build failures (LP: #727342)
* Changes in debian/rules:
  - work around a bug in toolbox/Makefile, where install-exec-hook is
    not happening.  This needs to get fixed the right way.
  - don't install 'vmware-user' which seems to no longer exist
  - move /etc/xdg into open-vm-toolbox (which should be done using .install)
* debian/open-vm-tools.init: add 'modprobe [-r] vmblock'. (LP: #332323)
* debian/rules and debian/open-vm-toolbox.lintian-overrides:
  - Make vmware-user-suid-wrapper suid-root (LP: #332323)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*********************************************************
 
2
 * Copyright (C) 2010 VMware, Inc. All rights reserved.
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify it
 
5
 * under the terms of the GNU Lesser General Public License as published
 
6
 * by the Free Software Foundation version 2.1 and no later version.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful, but
 
9
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 
10
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the Lesser GNU General Public
 
11
 * License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU Lesser General Public License
 
14
 * along with this program; if not, write to the Free Software Foundation, Inc.,
 
15
 * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA.
 
16
 *
 
17
 *********************************************************/
 
18
 
 
19
/*
 
20
 * hgfsChannel.c --
 
21
 *
 
22
 *    Channel abstraction for the HGFS server.
 
23
 *
 
24
 */
 
25
 
 
26
#include <stdlib.h>
 
27
#include "vm_assert.h"
 
28
#include "vm_atomic.h"
 
29
#include "util.h"
 
30
#include "debug.h"
 
31
#include "hgfsChannelGuestInt.h"
 
32
#include "hgfsServer.h"
 
33
#include "hgfsServerManager.h"
 
34
 
 
35
typedef enum {
 
36
   HGFS_GST_CONN_UNINITIALIZED,
 
37
   HGFS_GST_CONN_NOTCONNECTED,
 
38
   HGFS_GST_CONN_CONNECTED,
 
39
} HgfsGuestConnState;
 
40
 
 
41
 
 
42
/* Since there is only one connection we use globals. */
 
43
typedef struct HgfsGuestConn {
 
44
   Atomic_uint32 refCount;                   /* Reference count. */
 
45
   HgfsGuestConnState state;
 
46
   HgfsServerSessionCallbacks *serverCbTable; /* Server session callbacks. */
 
47
   HgfsServerChannelCallbacks channelCbTable;
 
48
   void *serverSession;
 
49
   size_t packetOutLen;
 
50
   unsigned char *clientPacketOut;                 /* Client supplied buffer. */
 
51
   unsigned char packetOut[HGFS_LARGE_PACKET_MAX]; /* For RPC msg callbacks. */
 
52
} HgfsGuestConn;
 
53
 
 
54
 
 
55
/* Callback functions. */
 
56
static Bool HgfsChannelGuestBdInit(HgfsServerSessionCallbacks *serverCBTable,
 
57
                                   void *rpc,
 
58
                                   void *rpcCallback,
 
59
                                   HgfsGuestConn **connection);
 
60
static void HgfsChannelGuestBdExit(HgfsGuestConn *data);
 
61
static Bool HgfsChannelGuestBdSend(void *data,
 
62
                                   HgfsPacket *packet,
 
63
                                   char *buffer,
 
64
                                   size_t bufferLen,
 
65
                                   HgfsSendFlags flags);
 
66
static Bool HgfsChannelGuestBdReceive(HgfsGuestConn *data,
 
67
                                      char const *packetIn,
 
68
                                      size_t packetInSize,
 
69
                                      char *packetOut,
 
70
                                      size_t *packetOutSize);
 
71
 
 
72
HgfsGuestChannelCBTable gGuestBackdoorOps = {
 
73
   HgfsChannelGuestBdInit,
 
74
   HgfsChannelGuestBdExit,
 
75
   HgfsChannelGuestBdReceive,
 
76
};
 
77
 
 
78
/* Private functions. */
 
79
static Bool HgfsChannelGuestConnConnect(HgfsGuestConn *connData);
 
80
static void HgfsChannelGuestConnDestroy(HgfsGuestConn *connData);
 
81
static Bool HgfsChannelGuestReceiveInternal(HgfsGuestConn *connData,
 
82
                                            char const *packetIn,
 
83
                                            size_t packetInSize,
 
84
                                            char *packetOut,
 
85
                                            size_t *packetOutSize);
 
86
 
 
87
 
 
88
/*
 
89
 *----------------------------------------------------------------------------
 
90
 *
 
91
 * CONNECTION DATA FUNCTIONS
 
92
 *
 
93
 *----------------------------------------------------------------------------
 
94
 */
 
95
 
 
96
 
 
97
/*
 
98
 *----------------------------------------------------------------------------
 
99
 *
 
100
 * HgfsChannelGuestConnGet --
 
101
 *
 
102
 *      Increment connection reference count.
 
103
 *
 
104
 * Results:
 
105
 *      None.
 
106
 *
 
107
 * Side effects:
 
108
 *      None.
 
109
 *
 
110
 *----------------------------------------------------------------------------
 
111
 */
 
112
 
 
113
static void
 
114
HgfsChannelGuestConnGet(HgfsGuestConn *connData)   // IN: connection
 
115
{
 
116
   ASSERT(connData);
 
117
   Atomic_Inc(&connData->refCount);
 
118
}
 
119
 
 
120
 
 
121
/*
 
122
 *----------------------------------------------------------------------------
 
123
 *
 
124
 * HgfsChannelGuestConnPut --
 
125
 *
 
126
 *      Decrement connection reference count.
 
127
 *
 
128
 *      Free connection data if this is the last reference.
 
129
 *
 
130
 * Results:
 
131
 *      None.
 
132
 *
 
133
 * Side effects:
 
134
 *      None.
 
135
 *
 
136
 *----------------------------------------------------------------------------
 
137
 */
 
138
 
 
139
static void
 
140
HgfsChannelGuestConnPut(HgfsGuestConn *connData)   // IN: connection
 
141
{
 
142
   ASSERT(connData);
 
143
   if (Atomic_FetchAndDec(&connData->refCount) == 1) {
 
144
      HgfsChannelGuestConnDestroy(connData);
 
145
   }
 
146
}
 
147
 
 
148
 
 
149
/*
 
150
 *-----------------------------------------------------------------------------
 
151
 *
 
152
 * HgfsChannelGuestConnInit --
 
153
 *
 
154
 *      Initializes the connection.
 
155
 *
 
156
 * Results:
 
157
 *      TRUE always and the channel initialized.
 
158
 *
 
159
 * Side effects:
 
160
 *      None.
 
161
 *
 
162
 *-----------------------------------------------------------------------------
 
163
 */
 
164
 
 
165
static Bool
 
166
HgfsChannelGuestConnInit(HgfsGuestConn **connData,                   // IN/OUT: channel object
 
167
                         HgfsServerSessionCallbacks *serverCBTable)  // IN: server callbacks
 
168
{
 
169
   HgfsGuestConn *conn = NULL;
 
170
 
 
171
   conn = Util_SafeCalloc(1, sizeof *conn);
 
172
 
 
173
   /* Give ourselves a reference of one. */
 
174
   HgfsChannelGuestConnGet(conn);
 
175
   conn->serverCbTable = serverCBTable;
 
176
   conn->state = HGFS_GST_CONN_NOTCONNECTED;
 
177
 
 
178
   *connData = conn;
 
179
   return TRUE;
 
180
}
 
181
 
 
182
 
 
183
/*
 
184
 *-----------------------------------------------------------------------------
 
185
 *
 
186
 * HgfsChannelGuestConnExit --
 
187
 *
 
188
 *      Teardown the connection.
 
189
 *
 
190
 *      Removes the reference and if it is the last will cause the connection
 
191
 *      to be destroyed.
 
192
 *
 
193
 * Results:
 
194
 *      None.
 
195
 *
 
196
 * Side effects:
 
197
 *      None.
 
198
 *
 
199
 *-----------------------------------------------------------------------------
 
200
 */
 
201
 
 
202
static void
 
203
HgfsChannelGuestConnExit(HgfsGuestConn *connData) // IN/OUT: channel object
 
204
{
 
205
   connData->state = HGFS_GST_CONN_UNINITIALIZED;
 
206
 
 
207
   HgfsChannelGuestConnPut(connData);
 
208
}
 
209
 
 
210
 
 
211
/*
 
212
 *-----------------------------------------------------------------------------
 
213
 *
 
214
 * HgfsChannelGuestConnDestroy --
 
215
 *
 
216
 *      Destroy the connection.
 
217
 *
 
218
 * Results:
 
219
 *      None.
 
220
 *
 
221
 * Side effects:
 
222
 *      None.
 
223
 *
 
224
 *-----------------------------------------------------------------------------
 
225
 */
 
226
 
 
227
static void
 
228
HgfsChannelGuestConnDestroy(HgfsGuestConn *connData) // IN/OUT: channel object
 
229
{
 
230
   /* Make sure the server closes it's own session data. */
 
231
   if (NULL != connData->serverSession) {
 
232
      connData->serverCbTable->close(connData->serverSession);
 
233
      connData->serverSession = NULL;
 
234
   }
 
235
   free(connData);
 
236
}
 
237
 
 
238
 
 
239
/*
 
240
 *-----------------------------------------------------------------------------
 
241
 *
 
242
 * HgfsChannelGuestConnCreate --
 
243
 *
 
244
 *      Create's the RPC connection for the HGFS guest if asked.
 
245
 *
 
246
 *      Create the pseudo connection for the guest - state transition.
 
247
 *      (See the comment in the function where the RPC initialization
 
248
 *      is expected to be added.
 
249
 *      This entails is registering our callback to receive messages for the
 
250
 *      connection object passed. We will have the ability to receive
 
251
 *      requests until we unregister our callback.)
 
252
 *
 
253
 *      NOTE: There is only handler and connction that can be used for
 
254
 *      all HGFS guest requests.
 
255
 *
 
256
 * Results:
 
257
 *      None.
 
258
 *
 
259
 * Side effects:
 
260
 *      None.
 
261
 *
 
262
 *-----------------------------------------------------------------------------
 
263
 */
 
264
 
 
265
static void
 
266
HgfsChannelGuestConnCreate(HgfsGuestConn *connData,      // IN: connection
 
267
                           void *rpc,                    // IN: Rpc channel unused
 
268
                           void *rpcCallback)            // IN: Rpc callback unused
 
269
{
 
270
   ASSERT(connData->state == HGFS_GST_CONN_NOTCONNECTED);
 
271
 
 
272
   /*
 
273
    * Rpc may be NULL for some cases. For example, if we
 
274
    * just need to provide an HGFS server connection
 
275
    * not associated with an HGFS only RPC connection.
 
276
    */
 
277
   if (connData->state == HGFS_GST_CONN_NOTCONNECTED) {
 
278
 
 
279
      /* XXX - Here is where we would register an RPC callback if required. */
 
280
 
 
281
      connData->state = HGFS_GST_CONN_CONNECTED;
 
282
      HgfsChannelGuestConnGet(connData);
 
283
   }
 
284
}
 
285
 
 
286
 
 
287
/*
 
288
 *-----------------------------------------------------------------------------
 
289
 *
 
290
 * HgfsChannelGuestConnClose --
 
291
 *
 
292
 *      Closes the connection for the HGFS guest.
 
293
 *
 
294
 *      If required unregisters the callback will prevent us from
 
295
 *      receiving any more requests closing the connection.
 
296
 *
 
297
 * Results:
 
298
 *      TRUE if closed, FALSE if was not connected.
 
299
 *
 
300
 * Side effects:
 
301
 *      None.
 
302
 *
 
303
 *-----------------------------------------------------------------------------
 
304
 */
 
305
 
 
306
static Bool
 
307
HgfsChannelGuestConnClose(HgfsGuestConn *connData,    // IN: Connection
 
308
                          void *rpc,                  // IN: Rpc channel unused
 
309
                          void *rpcCallback)          // IN: Rpc callback unused
 
310
{
 
311
   Bool result = FALSE;
 
312
 
 
313
   if (connData->state == HGFS_GST_CONN_CONNECTED) {
 
314
      /* XXX - Here is where we would unregister an RPC callback. */
 
315
 
 
316
      /* Clear the connection object since we are unregistered. */
 
317
      connData->state = HGFS_GST_CONN_NOTCONNECTED;
 
318
      HgfsChannelGuestConnPut(connData);
 
319
      result = TRUE;
 
320
   }
 
321
   return result;
 
322
}
 
323
 
 
324
 
 
325
/*
 
326
 *-----------------------------------------------------------------------------
 
327
 *
 
328
 * HgfsChannelGuestConnConnect --
 
329
 *
 
330
 *      Send connection to the server.
 
331
 *
 
332
 * Results:
 
333
 *      TRUE if server returns a data object, FALSE if not.
 
334
 *
 
335
 * Side effects:
 
336
 *      None
 
337
 *
 
338
 *-----------------------------------------------------------------------------
 
339
 */
 
340
 
 
341
static Bool
 
342
HgfsChannelGuestConnConnect(HgfsGuestConn *connData)  // IN: our connection data
 
343
{
 
344
   Bool result;
 
345
 
 
346
   connData->channelCbTable.getWriteVa = NULL;
 
347
   connData->channelCbTable.getReadVa = NULL;
 
348
   connData->channelCbTable.putVa = NULL;
 
349
   connData->channelCbTable.send = HgfsChannelGuestBdSend;
 
350
   result = connData->serverCbTable->connect(connData,
 
351
                                             &connData->channelCbTable,
 
352
                                             0,
 
353
                                             &connData->serverSession);
 
354
   if (result) {
 
355
      HgfsChannelGuestConnGet(connData);
 
356
   }
 
357
   return result;
 
358
}
 
359
 
 
360
 
 
361
/*
 
362
 *-----------------------------------------------------------------------------
 
363
 *
 
364
 * HgfsChannelGuestConnDisconnect --
 
365
 *
 
366
 *      Send disconnect to the server.
 
367
 *
 
368
 *      NOTE: The server data will be maintained until
 
369
 *      the connection is totally closed (last reference is gone).
 
370
 *
 
371
 * Results:
 
372
 *      None.
 
373
 *
 
374
 * Side effects:
 
375
 *      None.
 
376
 *
 
377
 *-----------------------------------------------------------------------------
 
378
 */
 
379
 
 
380
static void
 
381
HgfsChannelGuestConnDisconnect(HgfsGuestConn *connData)  // IN: connection
 
382
{
 
383
   if (connData->serverSession != NULL) {
 
384
      /* Tell the server to to disconnect the session. */
 
385
      connData->serverCbTable->disconnect(connData->serverSession);
 
386
      HgfsChannelGuestConnPut(connData);
 
387
   }
 
388
}
 
389
 
 
390
 
 
391
/*
 
392
 *----------------------------------------------------------------------------
 
393
 *
 
394
 * HgfsChannelGuestConnCloseInternal --
 
395
 *
 
396
 *      Close the client and send a disconnect to the server for the session.
 
397
 *
 
398
 * Results:
 
399
 *      None.
 
400
 *
 
401
 * Side effects:
 
402
 *      Closes the client connection and empties the queues.
 
403
 *
 
404
 *----------------------------------------------------------------------------
 
405
 */
 
406
 
 
407
static void
 
408
HgfsChannelGuestConnCloseInternal(HgfsGuestConn *connData, // IN: Connection data
 
409
                                  void *rpc,               // IN: Rpc channel unused
 
410
                                  void *rpcCallback)       // IN: Rpc callback unused
 
411
{
 
412
   /* Close (unregister the backdoor RPC) connection. */
 
413
   if (HgfsChannelGuestConnClose(connData, rpc, rpcCallback)) {
 
414
      /* Disconnect the connection from the server. */
 
415
      HgfsChannelGuestConnDisconnect(connData);
 
416
   }
 
417
}
 
418
 
 
419
 
 
420
/*
 
421
 *----------------------------------------------------------------------------
 
422
 *
 
423
 * HgfsChannelGuestReceiveInternal --
 
424
 *
 
425
 *    Process packet not associated with any session.
 
426
 *
 
427
 *    This function is used in the HGFS server inside Tools.
 
428
 *
 
429
 *    Create an internal session if not already created, and process the packet.
 
430
 *
 
431
 * Results:
 
432
 *    TRUE if received packet ok and processed, FALSE otherwise.
 
433
 *
 
434
 * Side effects:
 
435
 *    None
 
436
 *
 
437
 *----------------------------------------------------------------------------
 
438
 */
 
439
 
 
440
static Bool
 
441
HgfsChannelGuestReceiveInternal(HgfsGuestConn *connData,  // IN: connection
 
442
                                char const *packetIn,     // IN: incoming packet
 
443
                                size_t packetInSize,      // IN: incoming packet size
 
444
                                char *packetOut,          // OUT: outgoing packet
 
445
                                size_t *packetOutSize)    // IN/OUT: outgoing packet size
 
446
{
 
447
   HgfsPacket packet;
 
448
 
 
449
   ASSERT(packetIn);
 
450
   ASSERT(packetOut);
 
451
   ASSERT(packetOutSize);
 
452
 
 
453
   if (connData->state == HGFS_GST_CONN_UNINITIALIZED) {
 
454
      /* The connection was closed as we are exiting, so bail. */
 
455
      *packetOutSize = 0;
 
456
      return FALSE;
 
457
   }
 
458
 
 
459
   /* This is just a ping, return nothing. */
 
460
   if (*packetOutSize == 0) {
 
461
      return TRUE;
 
462
   }
 
463
 
 
464
   /*
 
465
    * Create the session if not already created.
 
466
    * This session is destroyed in HgfsServer_ExitState.
 
467
    */
 
468
   if (connData->serverSession == NULL) {
 
469
      /* Do our guest connect now which will inform the server. */
 
470
      if (!HgfsChannelGuestConnConnect(connData)) {
 
471
         *packetOutSize = 0;
 
472
         return FALSE;
 
473
      }
 
474
   }
 
475
 
 
476
   memset(&packet, 0, sizeof packet);
 
477
   /* For backdoor there is only one iov */
 
478
   packet.iov[0].va = (void *)packetIn;
 
479
   packet.iov[0].len = packetInSize;
 
480
   packet.iovCount = 1;
 
481
   packet.metaPacket = (void *)packetIn;
 
482
   packet.metaPacketSize = packetInSize;
 
483
   packet.replyPacket = packetOut;
 
484
   packet.replyPacketSize = *packetOutSize;
 
485
 
 
486
   /* The server will perform a synchronous processing of requests. */
 
487
   connData->serverCbTable->receive(&packet, connData->serverSession);
 
488
 
 
489
   *packetOutSize = connData->packetOutLen;
 
490
 
 
491
   return TRUE;
 
492
}
 
493
 
 
494
 
 
495
/*
 
496
 *----------------------------------------------------------------------------
 
497
 *
 
498
 * REGISTERED CALLBACK FUNCTIONS
 
499
 *
 
500
 * XXX - Where we would have any internally registered callback routines.
 
501
 * This routine would call HgfsChannelGuestReceiveInternal to process the
 
502
 * request.
 
503
 *
 
504
 *----------------------------------------------------------------------------
 
505
 */
 
506
 
 
507
 
 
508
/*
 
509
 *----------------------------------------------------------------------------
 
510
 *
 
511
 * GUEST CHANNEL CALLBACKS
 
512
 *
 
513
 *----------------------------------------------------------------------------
 
514
 */
 
515
 
 
516
 
 
517
/*
 
518
 *----------------------------------------------------------------------------
 
519
 *
 
520
 * HgfsChannelGuestBdReceive --
 
521
 *
 
522
 *    Process packet not associated with our registered callback.
 
523
 *
 
524
 *
 
525
 * Results:
 
526
 *    TRUE if received packet ok and processed, FALSE otherwise.
 
527
 *
 
528
 * Side effects:
 
529
 *    None
 
530
 *
 
531
 *----------------------------------------------------------------------------
 
532
 */
 
533
 
 
534
Bool
 
535
HgfsChannelGuestBdReceive(HgfsGuestConn *connData,    // IN: connection
 
536
                          char const *packetIn,       // IN: incoming packet
 
537
                          size_t packetInSize,        // IN: incoming packet size
 
538
                          char *packetOut,            // OUT: outgoing packet
 
539
                          size_t *packetOutSize)      // IN/OUT: outgoing packet size
 
540
{
 
541
   Bool result = TRUE;
 
542
 
 
543
   ASSERT(NULL != packetIn);
 
544
   ASSERT(NULL != packetOut);
 
545
   ASSERT(NULL != packetOutSize);
 
546
   ASSERT(NULL != connData);
 
547
 
 
548
   if (NULL == connData) {
 
549
      result = FALSE;
 
550
      goto exit;
 
551
   }
 
552
 
 
553
   connData->packetOutLen = *packetOutSize;
 
554
   connData->clientPacketOut = packetOut;
 
555
 
 
556
   result = HgfsChannelGuestReceiveInternal(connData,
 
557
                                            packetIn,
 
558
                                            packetInSize,
 
559
                                            connData->clientPacketOut,
 
560
                                            packetOutSize);
 
561
 
 
562
   connData->clientPacketOut = NULL;
 
563
   connData->packetOutLen = sizeof connData->packetOut;
 
564
 
 
565
exit:
 
566
   return result;
 
567
}
 
568
 
 
569
 
 
570
/*
 
571
 *-----------------------------------------------------------------------------
 
572
 *
 
573
 * HgfsChannelGuestBdSend --
 
574
 *
 
575
 *      Send reply to the request
 
576
 *
 
577
 * Results:
 
578
 *      Always TRUE.
 
579
 *
 
580
 * Side effects:
 
581
 *      None
 
582
 *
 
583
 *-----------------------------------------------------------------------------
 
584
 */
 
585
 
 
586
static Bool
 
587
HgfsChannelGuestBdSend(void *conn,              // IN: our connection data
 
588
                       HgfsPacket *packet,      // IN/OUT: Hgfs Packet
 
589
                       char *buffer,            // IN: buffer to be sent
 
590
                       size_t bufferLen,        // IN: buffer length
 
591
                       HgfsSendFlags flags)     // IN: Flags to say how to process
 
592
{
 
593
   HgfsGuestConn *connData = conn;
 
594
   unsigned char *packetOut = &connData->packetOut[0];
 
595
 
 
596
   ASSERT(NULL != connData);
 
597
   ASSERT(NULL != packet);
 
598
   ASSERT(NULL != buffer);
 
599
   ASSERT(bufferLen <= HGFS_LARGE_PACKET_MAX &&
 
600
          bufferLen <= packet->replyPacketSize);
 
601
 
 
602
   if (connData->clientPacketOut != NULL) {
 
603
      /* Client passed us an out buffer so use it. */
 
604
      packetOut = connData->clientPacketOut;
 
605
   }
 
606
   ASSERT(bufferLen <= connData->packetOutLen);
 
607
   if (bufferLen > connData->packetOutLen) {
 
608
      bufferLen = connData->packetOutLen;
 
609
   }
 
610
   connData->packetOutLen = (uint32)bufferLen;
 
611
 
 
612
   if (!(flags & HGFS_SEND_NO_COMPLETE)) {
 
613
      connData->serverCbTable->sendComplete(packet,
 
614
                                            connData->serverSession);
 
615
   }
 
616
 
 
617
   return TRUE;
 
618
}
 
619
 
 
620
 
 
621
/*
 
622
 *----------------------------------------------------------------------------
 
623
 *
 
624
 * HgfsChannelGuestBdInit --
 
625
 *
 
626
 *      Called from channel manager.
 
627
 *
 
628
 *      Initializes our channel connections.
 
629
 *
 
630
 * Results:
 
631
 *      Always TRUE.
 
632
 *
 
633
 * Side effects:
 
634
 *      Registers RPC call.
 
635
 *
 
636
 *----------------------------------------------------------------------------
 
637
 */
 
638
 
 
639
static Bool
 
640
HgfsChannelGuestBdInit(HgfsServerSessionCallbacks *serverCBTable,   // IN: server callbacks
 
641
                       void *rpc,                                   // IN: Rpc channel unused
 
642
                       void *rpcCallback,                           // IN: Rpc callback unused
 
643
                       HgfsGuestConn **connection)                  // OUT: connection object
 
644
{
 
645
   HgfsGuestConn *connData = NULL;
 
646
   Bool result;
 
647
 
 
648
   ASSERT(NULL != connection);
 
649
 
 
650
   /* Create our connection object. */
 
651
   result = HgfsChannelGuestConnInit(&connData,
 
652
                                     serverCBTable);
 
653
   if (!result) {
 
654
      Debug("%s: Error: guest connection initialized.\n", __FUNCTION__);
 
655
      goto exit;
 
656
   }
 
657
 
 
658
   /*
 
659
    * Create our connection now with any rpc handle and callback.
 
660
    */
 
661
   HgfsChannelGuestConnCreate(connData,
 
662
                              rpc,
 
663
                              rpcCallback);
 
664
 
 
665
exit:
 
666
   if (!result) {
 
667
      if (NULL != connData) {
 
668
         HgfsChannelGuestBdExit(connData);
 
669
         connData = NULL;
 
670
      }
 
671
   }
 
672
   *connection = connData;
 
673
   Debug("%s: guest initialized.\n", __FUNCTION__);
 
674
   return result;
 
675
}
 
676
 
 
677
 
 
678
/*
 
679
 *----------------------------------------------------------------------------
 
680
 *
 
681
 * HgfsChannelGuestBdExit --
 
682
 *
 
683
 *      Tearsdown our channel connections.
 
684
 *
 
685
 * Results:
 
686
 *      None.
 
687
 *
 
688
 * Side effects:
 
689
 *      Unregisters RPC call.
 
690
 *
 
691
 *----------------------------------------------------------------------------
 
692
 */
 
693
 
 
694
static void
 
695
HgfsChannelGuestBdExit(HgfsGuestConn *connData)
 
696
{
 
697
   ASSERT(NULL != connData);
 
698
 
 
699
   if (NULL != connData) {
 
700
      /* Currently no rpc to unregister. */
 
701
      HgfsChannelGuestConnCloseInternal(connData, NULL, NULL);
 
702
      HgfsChannelGuestConnExit(connData);
 
703
   }
 
704
}