open-vm-tools 13.1.0
utils.h
Go to the documentation of this file.
1 /*********************************************************
2  * Copyright (c) 2008-2025 Broadcom. All Rights Reserved.
3  * The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU Lesser General Public License as published
7  * by the Free Software Foundation version 2.1 and no later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11  * or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public
12  * License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
17  *
18  *********************************************************/
19 
20 #ifndef _VMWARE_TOOLS_UTILS_H_
21 #define _VMWARE_TOOLS_UTILS_H_
22 
38 #define VMTOOLS_GUEST_SERVICE "vmsvc"
39 #define VMTOOLS_USER_SERVICE "vmusr"
40 
41 #if defined(__cplusplus)
42 # define VMTOOLS_EXTERN_C extern "C"
43 #else
44 # define VMTOOLS_EXTERN_C
45 #endif
46 
47 #include <glib.h>
48 #if defined(G_PLATFORM_WIN32)
49 # include <windows.h>
50 #else
51 # include <signal.h>
52 # include <sys/time.h>
53 #endif
54 
55 #ifndef ABS
56 # define ABS(x) (((x) >= 0) ? (x) : -(x))
57 #endif
58 
59 
72 #if defined(G_PLATFORM_WIN32)
73 # define VMTOOLS_GET_FILENAME_LOCAL(path, err) (gchar *) (path)
74 #else
75 # define VMTOOLS_GET_FILENAME_LOCAL(path, err) g_filename_from_utf8((path), \
76  -1, \
77  NULL, \
78  NULL, \
79  (err))
80 #endif
81 
88 #if defined(G_PLATFORM_WIN32)
89 # define VMTOOLS_RELEASE_FILENAME_LOCAL(path) (void) (path)
90 #else
91 # define VMTOOLS_RELEASE_FILENAME_LOCAL(path) g_free(path)
92 #endif
93 
95 #define VMTOOLS_WRAP_ARRAY(a) VMTools_WrapArray((a), sizeof *(a), G_N_ELEMENTS(a))
96 
97 
98 G_BEGIN_DECLS
99 
100 void
101 vm_free(void *ptr);
102 
103 gboolean
104 VMTools_LoadConfig(const gchar *path,
105  GKeyFileFlags flags,
106  GKeyFile **config,
107  time_t *mtime);
108 
109 gboolean
110 VMTools_AddConfig(GKeyFile *srcConfig,
111  GKeyFile *dstConfig);
112 
113 gboolean
114 VMTools_CompareConfig(GKeyFile *config1,
115  GKeyFile *config2);
116 
117 gboolean
118 VMTools_WriteConfig(const gchar *path,
119  GKeyFile *config,
120  GError **err);
121 
122 gboolean
123 VMTools_ChangeLogFilePath(const gchar *delimiter,
124  const gchar *appendString,
125  const gchar *domain,
126  GKeyFile *conf);
127 
128 gboolean
129 VMTools_ConfigGetBoolean(GKeyFile *config,
130  const gchar *section,
131  const gchar *key,
132  const gboolean defValue);
133 
134 gint
135 VMTools_ConfigGetInteger(GKeyFile *config,
136  const gchar *section,
137  const gchar *key,
138  const gint defValue);
139 
140 gchar *
141 VMTools_ConfigGetString(GKeyFile *config,
142  const gchar *section,
143  const gchar *key,
144  const gchar *defValue);
145 
146 #if defined(G_PLATFORM_WIN32)
147 
148 #define VMTOOLS_WIN_EVENT_SOURCE_NAME L"VMware Tools"
149 
150 #define VMTOOLS_CERT_MSG "Verify that a valid VMware Tools signing "\
151  "certificate is present in the Trusted "\
152  "Publishers certificate store on the system. "\
153  "Refer to the VMware Tools Administration Guide "\
154  "for how to set up a VMware Tools signing "\
155  "certificate."
156 gboolean
157 VMTools_AttachConsole(void);
158 
159 GSource *
160 VMTools_NewHandleSource(HANDLE h);
161 
162 gboolean
163 VMTools_IsPSScriptSigningEnforced(void);
164 
165 gboolean
166 VMTools_IsScriptSignerCertPresent(void);
167 
168 void
169 VMTools_LogWinEvent(const gchar *certMsg);
170 #else
171 
173 typedef gboolean (*SignalSourceCb)(const siginfo_t *, gpointer);
174 
175 GSource *
176 VMTools_NewSignalSource(int signum);
177 
178 gchar *
179 VMTools_GetLibdir(void);
180 
181 #endif
182 
183 void
184 VMTools_SetupEnv(const gchar *appName,
185  GKeyFile *config,
186  gboolean globalVars);
187 
188 GSource *
189 VMTools_CreateTimer(gint timeout);
190 
191 void
193 
194 void
196 
197 gchar *
199 
200 void
202 
203 void
204 VMTools_ResumeLogIO(void);
205 
206 GArray *
207 VMTools_WrapArray(gconstpointer data,
208  guint elemSize,
209  guint count);
210 
211 G_END_DECLS
212 
215 #endif /* _VMWARE_TOOLS_UTILS_H_ */
216 
GArray * VMTools_WrapArray(gconstpointer data, guint elemSize, guint count)
Definition: vmtools.c:60
gboolean VMTools_ChangeLogFilePath(const gchar *delimiter, const gchar *appendString, const gchar *domain, GKeyFile *conf)
Definition: vmtoolsLog.c:2517
gboolean VMTools_ConfigGetBoolean(GKeyFile *config, const gchar *section, const gchar *key, const gboolean defValue)
Definition: vmtoolsConfig.c:496
void VMTools_AcquireLogStateLock(void)
Definition: vmtoolsLog.c:2173
gchar * VMTools_GetLibdir(void)
Definition: vmtoolsMisc.c:56
gint VMTools_ConfigGetInteger(GKeyFile *config, const gchar *section, const gchar *key, const gint defValue)
Definition: vmtoolsConfig.c:541
gchar * VMTools_ConfigGetString(GKeyFile *config, const gchar *section, const gchar *key, const gchar *defValue)
Definition: vmtoolsConfig.c:583
gboolean VMTools_CompareConfig(GKeyFile *config1, GKeyFile *config2)
Definition: vmtoolsConfig.c:278
gchar * VMTools_GetTimeAsString(void)
Definition: vmtoolsLog.c:360
gboolean VMTools_LoadConfig(const gchar *path, GKeyFileFlags flags, GKeyFile **config, time_t *mtime)
Definition: vmtoolsConfig.c:88
gboolean VMTools_WriteConfig(const gchar *path, GKeyFile *config, GError **err)
Definition: vmtoolsConfig.c:421
void VMTools_ReleaseLogStateLock(void)
Definition: vmtoolsLog.c:2184
void VMTools_SuspendLogIO(void)
Definition: vmtoolsLog.c:2195
void VMTools_ResumeLogIO(void)
Definition: vmtoolsLog.c:2206
GSource * VMTools_CreateTimer(gint timeout)
Create a timer based on a monotonic clock source.
Definition: monotonicTimer.c:169
void VMTools_SetupEnv(const gchar *appName, GKeyFile *config, gboolean globalVars)
Definition: vmtoolsMisc.c:676
GSource * VMTools_NewSignalSource(int signum)
Definition: signalSource.c:271
G_BEGIN_DECLS void vm_free(void *ptr)
Definition: vmtools.c:126
gboolean VMTools_AddConfig(GKeyFile *srcConfig, GKeyFile *dstConfig)
Definition: vmtoolsConfig.c:198
gboolean(* SignalSourceCb)(const siginfo_t *, gpointer)
Definition: utils.h:173