2
* OpenVPN -- An application to securely tunnel IP networks
3
* over a single UDP port, with support for SSL/TLS-based
4
* session authentication and key exchange,
5
* packet encryption, packet authentication, and
8
* Copyright (C) 2002-2010 OpenVPN Technologies, Inc. <sales@openvpn.net>
10
* This program is free software; you can redistribute it and/or modify
11
* it under the terms of the GNU General Public License version 2
12
* as published by the Free Software Foundation.
14
* This program is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
* GNU General Public License for more details.
19
* You should have received a copy of the GNU General Public License
20
* along with this program (see the file COPYING included with this
21
* distribution); if not, write to the Free Software Foundation, Inc.,
22
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26
#ifndef OPENVPN_WIN32_H
27
#define OPENVPN_WIN32_H
31
/* location of executables */
32
#define SYS_PATH_ENV_VAR_NAME "SystemRoot" /* environmental variable name that normally contains the system path */
33
#define NETSH_PATH_SUFFIX "\\system32\\netsh.exe"
34
#define WIN_ROUTE_PATH_SUFFIX "\\system32\\route.exe"
35
#define WIN_IPCONFIG_PATH_SUFFIX "\\system32\\ipconfig.exe"
36
#define WIN_NET_PATH_SUFFIX "\\system32\\net.exe"
39
* Win32-specific OpenVPN code, targetted at the mingw
40
* development environment.
43
/* MSVC headers do not define this macro, so do it here */
44
#ifndef IN6_ARE_ADDR_EQUAL
45
#define IN6_ARE_ADDR_EQUAL(a,b) \
46
(memcmp ((const void*)(a), (const void*)(b), sizeof (struct in6_addr)) == 0)
49
void init_win32 (void);
50
void uninit_win32 (void);
52
void set_pause_exit_win32 (void);
54
struct security_attributes
56
SECURITY_ATTRIBUTES sa;
57
SECURITY_DESCRIPTOR sd;
60
#define HANDLE_DEFINED(h) ((h) != NULL && (h) != INVALID_HANDLE_VALUE)
63
* Save old window title.
68
char old_window_title [256];
77
* Event-based notification of incoming TCP connections
80
#define NE32_PERSIST_EVENT (1<<0)
81
#define NE32_WRITE_EVENT (1<<1)
84
defined_net_event_win32 (const struct rw_handle *event)
86
return event->read != NULL;
89
void init_net_event_win32 (struct rw_handle *event, long network_events, socket_descriptor_t sd, unsigned int flags);
90
long reset_net_event_win32 (struct rw_handle *event, socket_descriptor_t sd);
91
void close_net_event_win32 (struct rw_handle *event, socket_descriptor_t sd, unsigned int flags);
94
* A stateful variant of the net_event_win32 functions above
97
struct net_event_win32
99
struct rw_handle handle;
100
socket_descriptor_t sd;
104
void net_event_win32_init (struct net_event_win32 *ne);
105
void net_event_win32_start (struct net_event_win32 *ne, long network_events, socket_descriptor_t sd);
106
void net_event_win32_reset (struct net_event_win32 *ne);
107
void net_event_win32_reset_write (struct net_event_win32 *ne);
108
void net_event_win32_stop (struct net_event_win32 *ne);
109
void net_event_win32_close (struct net_event_win32 *ne);
112
net_event_win32_defined (const struct net_event_win32 *ne)
114
return defined_net_event_win32 (&ne->handle);
117
static inline struct rw_handle *
118
net_event_win32_get_event (struct net_event_win32 *ne)
124
net_event_win32_get_event_mask (const struct net_event_win32 *ne)
126
return ne->event_mask;
130
net_event_win32_clear_selected_events (struct net_event_win32 *ne, long selected_events)
132
ne->event_mask &= ~selected_events;
138
struct win32_signal {
139
# define WSO_MODE_UNDEF 0
140
# define WSO_MODE_SERVICE 1
141
# define WSO_MODE_CONSOLE 2
144
DWORD console_mode_save;
145
bool console_mode_save_defined;
148
extern struct win32_signal win32_signal; /* static/global */
149
extern struct window_title window_title; /* static/global */
151
void win32_signal_clear (struct win32_signal *ws);
153
/* win32_signal_open startup type */
154
#define WSO_NOFORCE 0
155
#define WSO_FORCE_SERVICE 1
156
#define WSO_FORCE_CONSOLE 2
158
void win32_signal_open (struct win32_signal *ws,
159
int force, /* set to WSO force parm */
160
const char *exit_event_name,
161
bool exit_event_initial_state);
163
void win32_signal_close (struct win32_signal *ws);
165
int win32_signal_get (struct win32_signal *ws);
167
void win32_pause (struct win32_signal *ws);
169
bool win32_service_interrupt (struct win32_signal *ws);
172
* Set the text on the window title bar
175
void window_title_clear (struct window_title *wt);
176
void window_title_save (struct window_title *wt);
177
void window_title_restore (const struct window_title *wt);
178
void window_title_generate (const char *title);
181
* We try to do all Win32 I/O using overlapped
182
* (i.e. asynchronous) I/O for a performance win.
184
struct overlapped_io {
185
# define IOSTATE_INITIAL 0
186
# define IOSTATE_QUEUED 1 /* overlapped I/O has been queued */
187
# define IOSTATE_IMMEDIATE_RETURN 2 /* I/O function returned immediately without queueing */
189
OVERLAPPED overlapped;
195
struct sockaddr_in addr;
196
struct sockaddr_in6 addr6;
199
struct buffer buf_init;
203
void overlapped_io_init (struct overlapped_io *o,
204
const struct frame *frame,
208
void overlapped_io_close (struct overlapped_io *o);
211
overlapped_io_active (struct overlapped_io *o)
213
return o->iostate == IOSTATE_QUEUED || o->iostate == IOSTATE_IMMEDIATE_RETURN;
216
char *overlapped_io_state_ascii (const struct overlapped_io *o);
219
* Use to control access to resources that only one
220
* OpenVPN process on a given machine can access at
231
void semaphore_clear (struct semaphore *s);
232
void semaphore_open (struct semaphore *s, const char *name);
233
bool semaphore_lock (struct semaphore *s, int timeout_milliseconds);
234
void semaphore_release (struct semaphore *s);
235
void semaphore_close (struct semaphore *s);
238
* Special global semaphore used to protect network
239
* shell commands from simultaneous instantiation.
241
* It seems you can't run more than one instance
242
* of netsh on the same machine at the same time.
245
extern struct semaphore netcmd_semaphore;
246
void netcmd_semaphore_init (void);
247
void netcmd_semaphore_close (void);
248
void netcmd_semaphore_lock (void);
249
void netcmd_semaphore_release (void);
251
/* Set Win32 security attributes structure to allow all access */
252
bool init_security_attributes_allow_all (struct security_attributes *obj);
254
/* return true if filename is safe to be used on Windows */
255
bool win_safe_filename (const char *fn);
257
/* add constant environmental variables needed by Windows */
260
/* get and set the current windows system path */
261
void set_win_sys_path (const char *newpath, struct env_set *es);
262
void set_win_sys_path_via_env (struct env_set *es);
263
char *get_win_sys_path (void);
265
/* call self in a subprocess */
266
void fork_to_self (const char *cmdline);
268
/* Find temporary directory */
269
const char *win_get_tempdir();
271
/* Convert a string from UTF-8 to UCS-2 */
272
WCHAR *wide_string (const char* utf8, struct gc_arena *gc);