open-vm-tools 12.4.0
guestrpc.h
Go to the documentation of this file.
1 /*********************************************************
2  * Copyright (C) 2008,2014-2016,2018-2020,2023 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 /*
40  * glib.h should not be placed inside `extern "C"' blocks.
41  * However, this header is often placed inside such blocks.
42  * Here we change back into C++ for glib.h
43  */
44 #ifdef __cplusplus
45 extern "C++" {
46 #endif
47 #include <glib.h>
48 #ifdef __cplusplus
49 }
50 #endif
51 
52 #include "vmware/tools/utils.h"
53 
54 G_BEGIN_DECLS
55 
57 #define RPCIN_SETRETVALS RpcChannel_SetRetVals
58 #define RPCIN_SETRETVALSF RpcChannel_SetRetValsF
59 
62 #define RPCCHANNEL_SEND_PERMISSION_DENIED "Permission denied"
63 
64 typedef struct _RpcChannel RpcChannel;
65 
67 typedef struct RpcInData {
69  const char *name;
74  const char *args;
76  size_t argsSize;
81  char *result;
83  size_t resultLen;
88  gboolean freeResult;
90  void *appCtx;
92  void *clientData;
94 
95 typedef enum RpcChannelType {
96  RPCCHANNEL_TYPE_INACTIVE,
97  RPCCHANNEL_TYPE_BKDOOR,
98  RPCCHANNEL_TYPE_PRIV_VSOCK,
99  RPCCHANNEL_TYPE_UNPRIV_VSOCK
100 } RpcChannelType;
101 
106 typedef gboolean (*RpcIn_Callback)(RpcInData *data);
107 
108 
110 typedef struct RpcChannelCallback {
112  const char *name;
116  gpointer clientData;
118  gpointer xdrIn;
125  gpointer xdrOut;
130  size_t xdrInSize;
132 
140 typedef void (*RpcChannelResetCb)(RpcChannel *chan,
141  gboolean success,
142  gpointer data);
143 
150 typedef void (*RpcChannelFailureCb)(gpointer _state);
151 
152 
153 gboolean
154 RpcChannel_Start(RpcChannel *chan);
155 
156 void
157 RpcChannel_Stop(RpcChannel *chan);
158 
159 RpcChannelType
160 RpcChannel_GetType(RpcChannel *chan);
161 
162 gboolean
163 RpcChannel_Send(RpcChannel *chan,
164  char const *data,
165  size_t dataLen,
166  char **result,
167  size_t *resultLen);
168 
169 void
170 RpcChannel_Free(void *ptr);
171 
172 #if !defined(USE_RPCI_ONLY)
173 gboolean
174 RpcChannel_BuildXdrCommand(const char *cmd,
175  void *xdrProc,
176  void *xdrData,
177  char **result,
178  size_t *resultLen);
179 gboolean
180 RpcChannel_Dispatch(RpcInData *data);
181 
182 void
183 RpcChannel_Setup(RpcChannel *chan,
184  const gchar *appName,
185  GMainContext *mainCtx,
186  gpointer appCtx,
187  RpcChannelResetCb resetCb,
188  gpointer resetData,
189  RpcChannelFailureCb failureCb,
190  guint maxFailures);
191 
192 void
193 RpcChannel_RegisterCallback(RpcChannel *chan,
194  RpcChannelCallback *rpc);
195 
196 void
197 RpcChannel_UnregisterCallback(RpcChannel *chan,
198  RpcChannelCallback *rpc);
199 #endif
200 
201 RpcChannel *
202 RpcChannel_Create(void);
203 
204 void
205 RpcChannel_Destroy(RpcChannel *chan);
206 
207 gboolean
208 RpcChannel_SetRetVals(RpcInData *data,
209  char const *result,
210  gboolean retVal);
211 
212 gboolean
213 RpcChannel_SetRetValsF(RpcInData *data,
214  char *result,
215  gboolean retVal);
216 
217 gboolean
218 RpcChannel_SendOneRaw(const char *data,
219  size_t dataLen,
220  char **result,
221  size_t *resultLen);
222 
223 #if defined(__linux__) || defined(_WIN32)
224 gboolean
225 RpcChannel_SendOneRawPriv(const char *data,
226  size_t dataLen,
227  char **result,
228  size_t *resultLen);
229 #endif
230 
231 gboolean
232 RpcChannel_SendOne(char **reply,
233  size_t *repLen,
234  const char *reqFmt,
235  ...);
236 
237 #if defined(__linux__) || defined(_WIN32)
238 gboolean
239 RpcChannel_SendOnePriv(char **reply,
240  size_t *repLen,
241  const char *reqFmt,
242  ...);
243 #endif
244 
245 RpcChannel *
246 RpcChannel_New(void);
247 
248 #if defined(__linux__) || defined(_WIN32)
249 RpcChannel *
250 VSockChannel_New(int flags);
251 #endif
252 
253 void
254 RpcChannel_SetBackdoorOnly(void);
255 
256 RpcChannel *
257 BackdoorChannel_New(void);
258 
259 G_END_DECLS
260 
263 #endif
264 
gboolean(* RpcIn_Callback)(RpcInData *data)
Definition: guestrpc.h:106
void(* RpcChannelFailureCb)(gpointer _state)
Definition: guestrpc.h:150
struct RpcInData RpcInData
void(* RpcChannelResetCb)(RpcChannel *chan, gboolean success, gpointer data)
Definition: guestrpc.h:140
struct RpcChannelCallback RpcChannelCallback
Definition: guestrpc.h:110
size_t xdrInSize
Definition: guestrpc.h:130
gpointer clientData
Definition: guestrpc.h:116
gpointer xdrIn
Definition: guestrpc.h:118
const char * name
Definition: guestrpc.h:112
gpointer xdrOut
Definition: guestrpc.h:125
RpcIn_Callback callback
Definition: guestrpc.h:114
Definition: guestrpc.h:67
const char * name
Definition: guestrpc.h:69
gboolean freeResult
Definition: guestrpc.h:88
char * result
Definition: guestrpc.h:81
size_t argsSize
Definition: guestrpc.h:76
const char * args
Definition: guestrpc.h:74
void * appCtx
Definition: guestrpc.h:90
void * clientData
Definition: guestrpc.h:92
size_t resultLen
Definition: guestrpc.h:83