open-vm-tools 11.3.5
guestrpc.h
Go to the documentation of this file.
1 /*********************************************************
2  * Copyright (C) 2008,2014-2016,2018-2020 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 #ifndef _VMWARE_TOOLS_GUESTRPC_H_
20 #define _VMWARE_TOOLS_GUESTRPC_H_
21 
39 #include <glib.h>
40 #include "vmware/tools/utils.h"
41 
42 G_BEGIN_DECLS
43 
45 #define RPCIN_SETRETVALS RpcChannel_SetRetVals
46 #define RPCIN_SETRETVALSF RpcChannel_SetRetValsF
47 
50 #define RPCCHANNEL_SEND_PERMISSION_DENIED "Permission denied"
51 
52 typedef struct _RpcChannel RpcChannel;
53 
55 typedef struct RpcInData {
57  const char *name;
62  const char *args;
64  size_t argsSize;
69  char *result;
71  size_t resultLen;
76  gboolean freeResult;
78  void *appCtx;
80  void *clientData;
82 
83 typedef enum RpcChannelType {
84  RPCCHANNEL_TYPE_INACTIVE,
85  RPCCHANNEL_TYPE_BKDOOR,
86  RPCCHANNEL_TYPE_PRIV_VSOCK,
87  RPCCHANNEL_TYPE_UNPRIV_VSOCK
88 } RpcChannelType;
89 
94 typedef gboolean (*RpcIn_Callback)(RpcInData *data);
95 
96 
98 typedef struct RpcChannelCallback {
100  const char *name;
104  gpointer clientData;
106  gpointer xdrIn;
113  gpointer xdrOut;
118  size_t xdrInSize;
120 
128 typedef void (*RpcChannelResetCb)(RpcChannel *chan,
129  gboolean success,
130  gpointer data);
131 
138 typedef void (*RpcChannelFailureCb)(gpointer _state);
139 
140 
141 gboolean
142 RpcChannel_Start(RpcChannel *chan);
143 
144 void
145 RpcChannel_Stop(RpcChannel *chan);
146 
147 RpcChannelType
148 RpcChannel_GetType(RpcChannel *chan);
149 
150 gboolean
151 RpcChannel_Send(RpcChannel *chan,
152  char const *data,
153  size_t dataLen,
154  char **result,
155  size_t *resultLen);
156 
157 void
158 RpcChannel_Free(void *ptr);
159 
160 #if !defined(USE_RPCI_ONLY)
161 gboolean
162 RpcChannel_BuildXdrCommand(const char *cmd,
163  void *xdrProc,
164  void *xdrData,
165  char **result,
166  size_t *resultLen);
167 gboolean
168 RpcChannel_Dispatch(RpcInData *data);
169 
170 void
171 RpcChannel_Setup(RpcChannel *chan,
172  const gchar *appName,
173  GMainContext *mainCtx,
174  gpointer appCtx,
175  RpcChannelResetCb resetCb,
176  gpointer resetData,
177  RpcChannelFailureCb failureCb,
178  guint maxFailures);
179 
180 void
181 RpcChannel_RegisterCallback(RpcChannel *chan,
182  RpcChannelCallback *rpc);
183 
184 void
185 RpcChannel_UnregisterCallback(RpcChannel *chan,
186  RpcChannelCallback *rpc);
187 #endif
188 
189 RpcChannel *
190 RpcChannel_Create(void);
191 
192 void
193 RpcChannel_Destroy(RpcChannel *chan);
194 
195 gboolean
196 RpcChannel_SetRetVals(RpcInData *data,
197  char const *result,
198  gboolean retVal);
199 
200 gboolean
201 RpcChannel_SetRetValsF(RpcInData *data,
202  char *result,
203  gboolean retVal);
204 
205 gboolean
206 RpcChannel_SendOneRaw(const char *data,
207  size_t dataLen,
208  char **result,
209  size_t *resultLen);
210 
211 #if defined(__linux__) || defined(_WIN32)
212 gboolean
213 RpcChannel_SendOneRawPriv(const char *data,
214  size_t dataLen,
215  char **result,
216  size_t *resultLen);
217 #endif
218 
219 gboolean
220 RpcChannel_SendOne(char **reply,
221  size_t *repLen,
222  const char *reqFmt,
223  ...);
224 
225 #if defined(__linux__) || defined(_WIN32)
226 gboolean
227 RpcChannel_SendOnePriv(char **reply,
228  size_t *repLen,
229  const char *reqFmt,
230  ...);
231 #endif
232 
233 RpcChannel *
234 RpcChannel_New(void);
235 
236 #if defined(__linux__) || defined(_WIN32)
237 RpcChannel *
238 VSockChannel_New(int flags);
239 #endif
240 
241 void
242 RpcChannel_SetBackdoorOnly(void);
243 
244 RpcChannel *
245 BackdoorChannel_New(void);
246 
247 G_END_DECLS
248 
251 #endif
252 
gboolean(* RpcIn_Callback)(RpcInData *data)
Definition: guestrpc.h:94
void(* RpcChannelFailureCb)(gpointer _state)
Definition: guestrpc.h:138
struct RpcInData RpcInData
void(* RpcChannelResetCb)(RpcChannel *chan, gboolean success, gpointer data)
Definition: guestrpc.h:128
struct RpcChannelCallback RpcChannelCallback
Definition: guestrpc.h:98
size_t xdrInSize
Definition: guestrpc.h:118
gpointer clientData
Definition: guestrpc.h:104
gpointer xdrIn
Definition: guestrpc.h:106
const char * name
Definition: guestrpc.h:100
gpointer xdrOut
Definition: guestrpc.h:113
RpcIn_Callback callback
Definition: guestrpc.h:102
Definition: guestrpc.h:55
const char * name
Definition: guestrpc.h:57
gboolean freeResult
Definition: guestrpc.h:76
char * result
Definition: guestrpc.h:69
size_t argsSize
Definition: guestrpc.h:64
const char * args
Definition: guestrpc.h:62
void * appCtx
Definition: guestrpc.h:78
void * clientData
Definition: guestrpc.h:80
size_t resultLen
Definition: guestrpc.h:71