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

« back to all changes in this revision

Viewing changes to modules/freebsd/vmhgfs/bdhandler.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 General Public License as published by the
 
6
 * Free Software Foundation version 2 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 GNU General Public License
 
11
 * for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU General Public License along
 
14
 * 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
 * bdhandler.c --
 
21
 *
 
22
 */
 
23
 
 
24
#include "hgfsBd.h"
 
25
#include "rpcout.h"
 
26
#include "channel.h"
 
27
 
 
28
static Bool HgfsBdChannelOpen(HgfsTransportChannel *channel);
 
29
static void HgfsBdChannelClose(HgfsTransportChannel *channel);
 
30
static HgfsKReqObject * HgfsBdChannelAllocate(size_t payloadSize, int flags);
 
31
void HgfsBdChannelFree(HgfsKReqObject *req, size_t payloadSize);
 
32
static int HgfsBdChannelSend(HgfsTransportChannel *channel, HgfsKReqObject *req);
 
33
 
 
34
static HgfsTransportChannel gBdChannel = {
 
35
   .name = "backdoor",
 
36
   .ops.open = HgfsBdChannelOpen,
 
37
   .ops.close = HgfsBdChannelClose,
 
38
   .ops.allocate = HgfsBdChannelAllocate,
 
39
   .ops.free = HgfsBdChannelFree,
 
40
   .ops.send = HgfsBdChannelSend,
 
41
   .priv = NULL,
 
42
   .status = HGFS_CHANNEL_NOTCONNECTED
 
43
};
 
44
 
 
45
 
 
46
/*
 
47
 *-----------------------------------------------------------------------------
 
48
 *
 
49
 * HgfsBdChannelOpen --
 
50
 *
 
51
 *      Open the backdoor in an idempotent way.
 
52
 *
 
53
 * Results:
 
54
 *      TRUE on success, FALSE on failure.
 
55
 *
 
56
 * Side effects:
 
57
 *      None
 
58
 *
 
59
 *-----------------------------------------------------------------------------
 
60
 */
 
61
 
 
62
static Bool
 
63
HgfsBdChannelOpen(HgfsTransportChannel *channel) // IN: Channel
 
64
{
 
65
   Bool ret;
 
66
 
 
67
   if ((ret = HgfsBd_OpenBackdoor((RpcOut **)&channel->priv))) {
 
68
      DEBUG(VM_DEBUG_INFO, "VMware hgfs: %s: backdoor opened.\n", __func__);
 
69
      ASSERT(channel->priv != NULL);
 
70
      channel->status = HGFS_CHANNEL_CONNECTED;
 
71
   }
 
72
 
 
73
   return ret;
 
74
}
 
75
 
 
76
 
 
77
/*
 
78
 *-----------------------------------------------------------------------------
 
79
 *
 
80
 * HgfsBdChannelClose --
 
81
 *
 
82
 *      Close the backdoor in an idempotent way.
 
83
 *
 
84
 * Results:
 
85
 *      None
 
86
 *
 
87
 * Side effects:
 
88
 *      None
 
89
 *
 
90
 *-----------------------------------------------------------------------------
 
91
 */
 
92
 
 
93
static void
 
94
HgfsBdChannelClose(HgfsTransportChannel *channel) // IN: Channel
 
95
{
 
96
   int ret;
 
97
 
 
98
   if (channel->priv == NULL) {
 
99
      return;
 
100
   }
 
101
 
 
102
   ret = HgfsBd_CloseBackdoor((RpcOut **)&channel->priv);
 
103
   if (!ret) {
 
104
      DEBUG(VM_DEBUG_FAIL, "VMware hgfs: %s: Failed to close backdoor.\n", __func__);
 
105
   } else {
 
106
      DEBUG(VM_DEBUG_INFO, "VMware hgfs: %s: backdoor closed.\n", __func__);
 
107
   }
 
108
   channel->status = HGFS_CHANNEL_NOTCONNECTED;
 
109
}
 
110
 
 
111
 
 
112
/*
 
113
 *-----------------------------------------------------------------------------
 
114
 *
 
115
 * HgfsBdChannelAllocate --
 
116
 *
 
117
 *      Allocate request in a way that is suitable for sending through
 
118
 *      backdoor.
 
119
 *
 
120
 * Results:
 
121
 *      NULL on failure; otherwise address of the new request.
 
122
 *
 
123
 * Side effects:
 
124
 *      None
 
125
 *
 
126
 *-----------------------------------------------------------------------------
 
127
 */
 
128
 
 
129
static HgfsKReqObject *
 
130
HgfsBdChannelAllocate(size_t payloadSize,   // IN: Size of allocation
 
131
                      int flags)            // IN:
 
132
{
 
133
   return os_malloc(payloadSize, flags);
 
134
}
 
135
 
 
136
 
 
137
/*
 
138
 *-----------------------------------------------------------------------------
 
139
 *
 
140
 * HgfsBdChannelFree --
 
141
 *
 
142
 *     Free previously allocated request.
 
143
 *
 
144
 * Results:
 
145
 *      None.
 
146
 *
 
147
 * Side effects:
 
148
 *      None.
 
149
 *
 
150
 *-----------------------------------------------------------------------------
 
151
 */
 
152
 
 
153
void
 
154
HgfsBdChannelFree(HgfsKReqObject *req,    // IN:
 
155
                  size_t payloadSize)     // IN:
 
156
{
 
157
   ASSERT(req);
 
158
   os_free(req, payloadSize);
 
159
}
 
160
 
 
161
 
 
162
/*
 
163
 *----------------------------------------------------------------------
 
164
 *
 
165
 * HgfsBdChannelSend --
 
166
 *
 
167
 *     Send a request via backdoor.
 
168
 *
 
169
 * Results:
 
170
 *     0 on success, negative error on failure.
 
171
 *
 
172
 * Side effects:
 
173
 *     None
 
174
 *
 
175
 *----------------------------------------------------------------------
 
176
 */
 
177
 
 
178
static int
 
179
HgfsBdChannelSend(HgfsTransportChannel *channel, // IN: Channel
 
180
                  HgfsKReqObject *req)           // IN: request to send
 
181
{
 
182
   char const *replyPacket = NULL;
 
183
   int ret;
 
184
 
 
185
   ASSERT(req);
 
186
 
 
187
   DEBUG(VM_DEBUG_INFO, "VMware hgfs: %s: backdoor sending.\n", __func__);
 
188
 
 
189
   bcopy(HGFS_SYNC_REQREP_CLIENT_CMD, req->__rpc_packet._command,
 
190
         HGFS_SYNC_REQREP_CLIENT_CMD_LEN);
 
191
 
 
192
   ret = HgfsBd_Dispatch(channel->priv, req->payload, &req->payloadSize,
 
193
                         &replyPacket);
 
194
   os_mutex_lock(req->stateLock);
 
195
 
 
196
   /*
 
197
    * We have a response.  (Maybe.)  Re-lock the request, update its state,
 
198
    * etc.
 
199
    */
 
200
   if ((ret == 0) && (req->state == HGFS_REQ_SUBMITTED)) {
 
201
      DEBUG(VM_DEBUG_INFO, "VMware hgfs: %s: Success in backdoor.\n", __func__);
 
202
      bcopy(replyPacket, req->payload, req->payloadSize);
 
203
      req->state = HGFS_REQ_COMPLETED;
 
204
   } else {
 
205
      DEBUG(VM_DEBUG_INFO, "hgfs: %s: Error in backdoor.\n", __func__);
 
206
      req->state = HGFS_REQ_ERROR;
 
207
   }
 
208
 
 
209
   os_cv_signal(&req->stateCv);
 
210
   os_mutex_unlock(req->stateLock);
 
211
   return ret;
 
212
}
 
213
 
 
214
 
 
215
/*
 
216
 *----------------------------------------------------------------------
 
217
 *
 
218
 * HgfsGetBdChannel --
 
219
 *
 
220
 *     Get backdoor channel.
 
221
 *
 
222
 * Results:
 
223
 *     Always return pointer to back door channel.
 
224
 *
 
225
 * Side effects:
 
226
 *     None
 
227
 *
 
228
 *----------------------------------------------------------------------
 
229
 */
 
230
 
 
231
HgfsTransportChannel*
 
232
HgfsGetBdChannel(void)
 
233
{
 
234
   return &gBdChannel;
 
235
}
 
236