git-svn-id: http://svn.openvpn.net/projects/openvpn/branches/BETA21/openvpn@2959 e7ae566f-a301-0410-adde-c780ea21d3b5
james authored on 2008/05/13 05:31:43... | ... |
@@ -22,18 +22,55 @@ |
22 | 22 |
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
23 | 23 |
# |
24 | 24 |
|
25 |
+LDADD = @LIBOBJS@ |
|
26 |
+.PHONY: plugin |
|
27 |
+ |
|
25 | 28 |
# This option prevents autoreconf from overriding our COPYING and |
26 | 29 |
# INSTALL targets: |
27 | 30 |
AUTOMAKE_OPTIONS = foreign |
28 | 31 |
|
29 |
-sbin_PROGRAMS = openvpn |
|
32 |
+MAINTAINERCLEANFILES = \ |
|
33 |
+ config.log config.status \ |
|
34 |
+ $(srcdir)/Makefile.in \ |
|
35 |
+ $(srcdir)/config.h.in $(srcdir)/config.h.in~ $(srcdir)/configure \ |
|
36 |
+ $(srcdir)/install-sh $(srcdir)/ltmain.sh $(srcdir)/missing \ |
|
37 |
+ $(srcdir)/depcomp $(srcdir)/aclocal.m4 \ |
|
38 |
+ $(srcdir)/config.guess $(srcdir)/config.sub \ |
|
39 |
+ $(srcdir)/config-win32.h $(srcdir)/openvpn.spec |
|
40 |
+CLEANFILES = openvpn.8.html |
|
30 | 41 |
|
31 |
-nodist_openvpn_SOURCES = config.h |
|
42 |
+EXTRA_DIST = \ |
|
43 |
+ easy-rsa \ |
|
44 |
+ sample-config-files \ |
|
45 |
+ sample-keys \ |
|
46 |
+ sample-scripts \ |
|
47 |
+ suse \ |
|
48 |
+ tap-win32 \ |
|
49 |
+ contrib \ |
|
50 |
+ debug \ |
|
51 |
+ plugin |
|
52 |
+ |
|
53 |
+SUBDIRS = \ |
|
54 |
+ images \ |
|
55 |
+ service-win32 \ |
|
56 |
+ install-win32 |
|
32 | 57 |
|
33 | 58 |
TESTS = t_lpback.sh t_cltsrv.sh |
34 |
-dist_noinst_SCRIPTS = $(TESTS) |
|
59 |
+sbin_PROGRAMS = openvpn |
|
35 | 60 |
|
36 |
-.PHONY: plugin |
|
61 |
+dist_noinst_HEADERS = \ |
|
62 |
+ config-win32.h |
|
63 |
+ |
|
64 |
+dist_noinst_SCRIPTS = \ |
|
65 |
+ $(TESTS) \ |
|
66 |
+ doclean \ |
|
67 |
+ domake-win |
|
68 |
+ |
|
69 |
+dist_noinst_DATA = \ |
|
70 |
+ openvpn.spec \ |
|
71 |
+ COPYRIGHT.GPL \ |
|
72 |
+ PORTS \ |
|
73 |
+ INSTALL-win32.txt |
|
37 | 74 |
|
38 | 75 |
openvpn_SOURCES = \ |
39 | 76 |
base64.c base64.h \ |
... | ... |
@@ -80,6 +117,7 @@ openvpn_SOURCES = \ |
80 | 80 |
pool.c pool.h \ |
81 | 81 |
proto.c proto.h \ |
82 | 82 |
proxy.c proxy.h \ |
83 |
+ ieproxy.h ieproxy.c \ |
|
83 | 84 |
ps.c ps.h \ |
84 | 85 |
push.c push.h \ |
85 | 86 |
reliable.c reliable.h \ |
... | ... |
@@ -94,44 +132,19 @@ openvpn_SOURCES = \ |
94 | 94 |
status.c status.h \ |
95 | 95 |
syshead.h \ |
96 | 96 |
thread.c thread.h \ |
97 |
- tun.c tun.h |
|
98 |
- |
|
99 |
-LDADD = @LIBOBJS@ |
|
100 |
- |
|
101 |
-man_MANS = openvpn.8 |
|
97 |
+ tun.c tun.h \ |
|
98 |
+ win32.h win32.c \ |
|
99 |
+ cryptoapi.h cryptoapi.c |
|
102 | 100 |
|
103 |
-EXTRA_DIST = \ |
|
104 |
- doclean \ |
|
105 |
- $(man_MANS) \ |
|
106 |
- COPYRIGHT.GPL \ |
|
107 |
- PORTS \ |
|
108 |
- openvpn.spec \ |
|
109 |
- easy-rsa \ |
|
110 |
- sample-config-files \ |
|
111 |
- sample-keys \ |
|
112 |
- sample-scripts \ |
|
113 |
- gentoo \ |
|
114 |
- suse \ |
|
115 |
- openvpn.spec.in \ |
|
116 |
- config-win32.h \ |
|
117 |
- win32.h \ |
|
118 |
- win32.c \ |
|
119 |
- cryptoapi.h \ |
|
120 |
- cryptoapi.c \ |
|
121 |
- makefile.w32 \ |
|
122 |
- makefile.w32-vc \ |
|
123 |
- INSTALL-win32.txt \ |
|
124 |
- tap-win32 \ |
|
125 |
- install-win32 \ |
|
126 |
- service-win32 \ |
|
127 |
- contrib \ |
|
128 |
- debug \ |
|
129 |
- plugin \ |
|
130 |
- management \ |
|
131 |
- images \ |
|
132 |
- ieproxy.c \ |
|
133 |
- ieproxy.h \ |
|
134 |
- domake-win |
|
135 | 101 |
|
136 | 102 |
dist-hook: |
137 | 103 |
cd $(distdir) && for i in $(EXTRA_DIST) ; do find $$i -name .svn -type d -prune -exec rm -rf '{}' ';' ; rm -f `find $$i -type f | grep -E '(^|\/)\.?\#|\~$$|\.s?o$$'` ; done |
104 |
+ |
|
105 |
+if WIN32 |
|
106 |
+dist_noinst_DATA += openvpn.8 |
|
107 |
+nodist_html_DATA = openvpn.8.html |
|
108 |
+openvpn.8.html: $(srcdir)/openvpn.8 |
|
109 |
+ $(MAN2HTML) < $(srcdir)/openvpn.8 > openvpn.8.html |
|
110 |
+else |
|
111 |
+dist_man_MANS = openvpn.8 |
|
112 |
+endif |
... | ... |
@@ -96,10 +96,19 @@ AC_DEFUN([TYPE_SOCKLEN_T], |
96 | 96 |
for arg2 in "struct sockaddr" void; do |
97 | 97 |
for t in int size_t unsigned long "unsigned long"; do |
98 | 98 |
AC_TRY_COMPILE([ |
99 |
+ #ifdef _WIN32 |
|
100 |
+ #include <windows.h> |
|
101 |
+ #define PREFIX1 WINSOCK_API_LINKAGE |
|
102 |
+ #define PREFIX2 PASCAL |
|
103 |
+ #else |
|
99 | 104 |
#include <sys/types.h> |
100 | 105 |
#include <sys/socket.h> |
106 |
+ #define PREFIX1 |
|
107 |
+ #define PREFIX2 |
|
108 |
+ #define SOCKET int |
|
109 |
+ #endif |
|
101 | 110 |
|
102 |
- int getpeername (int, $arg2 *, $t *); |
|
111 |
+ PREFIX1 int PREFIX2 getpeername (SOCKET, $arg2 *, $t *); |
|
103 | 112 |
],[ |
104 | 113 |
$t len; |
105 | 114 |
getpeername(0,0,&len); |
... | ... |
@@ -31,15 +31,9 @@ |
31 | 31 |
* SUCH DAMAGE. |
32 | 32 |
*/ |
33 | 33 |
|
34 |
-#ifdef WIN32 |
|
35 |
-#include "config-win32.h" |
|
36 |
-#else |
|
37 |
-#include "config.h" |
|
38 |
-#endif |
|
39 |
- |
|
40 | 34 |
#include "syshead.h" |
41 | 35 |
|
42 |
-#ifdef ENABLE_HTTP_PROXY |
|
36 |
+#if defined(ENABLE_HTTP_PROXY) || defined(ENABLE_PKCS11) |
|
43 | 37 |
|
44 | 38 |
#include "base64.h" |
45 | 39 |
|
... | ... |
@@ -143,7 +137,7 @@ base64_decode(const char *str, void *data) |
143 | 143 |
return q - (unsigned char *) data; |
144 | 144 |
} |
145 | 145 |
|
146 |
-#endif /* NTLM */ |
|
146 |
+#endif /* NTLM, PKCS#11 */ |
|
147 | 147 |
|
148 | 148 |
#else |
149 | 149 |
static void dummy(void) {} |
34 | 28 |
deleted file mode 100644 |
... | ... |
@@ -1,321 +0,0 @@ |
1 |
-/* |
|
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 |
|
6 |
- * packet compression. |
|
7 |
- * |
|
8 |
- * Copyright (C) 2002-2005 OpenVPN Solutions LLC <info@openvpn.net> |
|
9 |
- * |
|
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. |
|
13 |
- * |
|
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. |
|
18 |
- * |
|
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 |
|
23 |
- */ |
|
24 |
- |
|
25 |
-/* |
|
26 |
- * Configuration header for Win32 using the mingw environment. |
|
27 |
- * Manually edited based on linux version as generated by autoconf. |
|
28 |
- * |
|
29 |
- * config-win32.h is normally generated by copying |
|
30 |
- * config-win32.h.in -> config-win32.h and replacing |
|
31 |
- * [ampersand] VERSION [ampersand] |
|
32 |
- * with the appropriate version #. This is normally |
|
33 |
- * done automatically by configure.ac |
|
34 |
- */ |
|
35 |
- |
|
36 |
-#include <windows.h> |
|
37 |
-#include <winsock2.h> |
|
38 |
-#include "autodefs/defs.h" |
|
39 |
- |
|
40 |
-#define sleep(x) Sleep((x)*1000) |
|
41 |
- |
|
42 |
-#define random rand |
|
43 |
-#define srandom srand |
|
44 |
- |
|
45 |
-typedef unsigned long in_addr_t; |
|
46 |
- |
|
47 |
-#ifndef _SSIZE_T_ |
|
48 |
-#define _SSIZE_T_ |
|
49 |
- typedef unsigned int ssize_t; |
|
50 |
-#endif |
|
51 |
- |
|
52 |
-/* Append a label to program startup title */ |
|
53 |
-/*#define DEBUG_LABEL "DEBUG1"*/ |
|
54 |
- |
|
55 |
-/* Should we print debug info from driver? */ |
|
56 |
-#ifdef PRODUCT_TAP_DEBUG |
|
57 |
-#define TAP_WIN32_DEBUG |
|
58 |
-#endif |
|
59 |
- |
|
60 |
-/* |
|
61 |
- * Minimum TAP-Win32 version number expected by userspace |
|
62 |
- * |
|
63 |
- * The TAP-Win32 version number is defined in tap-win32/SOURCES |
|
64 |
- */ |
|
65 |
-#define TAP_WIN32_MIN_MAJOR 9 |
|
66 |
-#define TAP_WIN32_MIN_MINOR 1 |
|
67 |
- |
|
68 |
-/* Enable client/server capability */ |
|
69 |
-#define ENABLE_CLIENT_SERVER 1 |
|
70 |
- |
|
71 |
-/* Enable client capability only */ |
|
72 |
-/* #undef ENABLE_CLIENT_ONLY */ |
|
73 |
- |
|
74 |
-/* Enable management server capability */ |
|
75 |
-#define ENABLE_MANAGEMENT 1 |
|
76 |
- |
|
77 |
-/* Enable PKCS#11 support */ |
|
78 |
-#define USE_PKCS11 1 |
|
79 |
- |
|
80 |
-/* Enable HTTP proxy support */ |
|
81 |
-#define ENABLE_HTTP_PROXY 1 |
|
82 |
- |
|
83 |
-/* Enable Socks proxy support */ |
|
84 |
-#define ENABLE_SOCKS 1 |
|
85 |
- |
|
86 |
-/* Enable internal fragmentation support */ |
|
87 |
-#define ENABLE_FRAGMENT 1 |
|
88 |
- |
|
89 |
-/* Enable smaller executable size */ |
|
90 |
-/* #undef ENABLE_SMALL */ |
|
91 |
- |
|
92 |
-/* Enable debugging support */ |
|
93 |
-#define ENABLE_DEBUG 1 |
|
94 |
- |
|
95 |
-/* if defined, will allow usage of the --plugin directive */ |
|
96 |
-#define USE_LOAD_LIBRARY |
|
97 |
- |
|
98 |
-/* Dimension size to use for empty array declaration */ |
|
99 |
-#define EMPTY_ARRAY_SIZE 0 |
|
100 |
- |
|
101 |
-/* Define to 1 if you have the `getsockname' function. */ |
|
102 |
-#define HAVE_GETSOCKNAME 1 |
|
103 |
- |
|
104 |
-/* Define to 1 if you have the <openssl/engine.h> header file. */ |
|
105 |
-#define HAVE_OPENSSL_ENGINE_H 1 |
|
106 |
- |
|
107 |
-/* Define to 1 if you have the `ENGINE_load_builtin_engines' function. */ |
|
108 |
-#define HAVE_ENGINE_LOAD_BUILTIN_ENGINES 1 |
|
109 |
- |
|
110 |
-/* Define to 1 if you have the `ENGINE_register_all_complete' function. */ |
|
111 |
-#define HAVE_ENGINE_REGISTER_ALL_COMPLETE 1 |
|
112 |
- |
|
113 |
-/* Define to 1 if you have the `ENGINE_cleanup' function. */ |
|
114 |
-#define HAVE_ENGINE_CLEANUP 1 |
|
115 |
- |
|
116 |
-/* gettimeofday() is implemented in otime.c for Windows */ |
|
117 |
-#define HAVE_GETTIMEOFDAY 1 |
|
118 |
- |
|
119 |
-/* Define to 1 if you have the 'chsize' function. */ |
|
120 |
-#define HAVE_CHSIZE 1 |
|
121 |
- |
|
122 |
-/* Define to 1 if you have the `chdir' function. */ |
|
123 |
-#define HAVE_CHDIR 1 |
|
124 |
- |
|
125 |
-/* Define to 1 if your compiler supports GNU GCC-style variadic macros */ |
|
126 |
-#ifndef _MSC_VER /* Defines MSFT compiler version. Defined as 1200 for MSVC++ 6.0. */ |
|
127 |
-#define HAVE_CPP_VARARG_MACRO_GCC 1 |
|
128 |
-#endif |
|
129 |
- |
|
130 |
-/* Define to 1 if you have the <ctype.h> header file. */ |
|
131 |
-#define HAVE_CTYPE_H 1 |
|
132 |
- |
|
133 |
-/* Define to 1 if you have the <errno.h> header file. */ |
|
134 |
-#define HAVE_ERRNO_H 1 |
|
135 |
- |
|
136 |
-/* Define to 1 if you have the `EVP_CIPHER_CTX_set_key_length' function. */ |
|
137 |
-#define HAVE_EVP_CIPHER_CTX_SET_KEY_LENGTH 1 |
|
138 |
- |
|
139 |
-/* Define to 1 if you have the <fcntl.h> header file. */ |
|
140 |
-#define HAVE_FCNTL_H 1 |
|
141 |
- |
|
142 |
-/* Define to 1 if you have the `getsockopt' function. */ |
|
143 |
-#define HAVE_GETSOCKOPT 1 |
|
144 |
- |
|
145 |
-/* Define to 1 if you have the `inet_ntoa' function. */ |
|
146 |
-#define HAVE_INET_NTOA 1 |
|
147 |
- |
|
148 |
-/* Define to 1 if your system has a GNU libc compatible `malloc' function, and |
|
149 |
- to 0 otherwise. */ |
|
150 |
-#define HAVE_MALLOC 1 |
|
151 |
- |
|
152 |
-/* Define to 1 if you have the `memset' function. */ |
|
153 |
-#define HAVE_MEMSET 1 |
|
154 |
- |
|
155 |
-/* Define to 1 if you have the `setsockopt' function. */ |
|
156 |
-#define HAVE_SETSOCKOPT 1 |
|
157 |
- |
|
158 |
-/* Define to 1 if you have the `socket' function. */ |
|
159 |
-#define HAVE_SOCKET 1 |
|
160 |
- |
|
161 |
-/* Define to 1 if you have the <stdarg.h> header file. */ |
|
162 |
-#define HAVE_STDARG_H 1 |
|
163 |
- |
|
164 |
-/* Define to 1 if you have the <stdint.h> header file. */ |
|
165 |
-#ifndef _MSC_VER |
|
166 |
-#define HAVE_STDINT_H 1 |
|
167 |
-#endif |
|
168 |
- |
|
169 |
-/* Define to 1 if you have the <stdio.h> header file. */ |
|
170 |
-#define HAVE_STDIO_H 1 |
|
171 |
- |
|
172 |
-/* Define to 1 if you have the <stdlib.h> header file. */ |
|
173 |
-#define HAVE_STDLIB_H 1 |
|
174 |
- |
|
175 |
-/* Define to 1 if you have the `strerror' function. */ |
|
176 |
-#define HAVE_STRERROR 1 |
|
177 |
- |
|
178 |
-/* Define to 1 if you have the <strings.h> header file. */ |
|
179 |
-#define HAVE_STRINGS_H 1 |
|
180 |
- |
|
181 |
-/* Define to 1 if you have the <string.h> header file. */ |
|
182 |
-#define HAVE_STRING_H 1 |
|
183 |
- |
|
184 |
-/* Define to 1 if you have the `system' function. */ |
|
185 |
-#define HAVE_SYSTEM 1 |
|
186 |
- |
|
187 |
-/* Define to 1 if you have the <sys/file.h> header file. */ |
|
188 |
-#ifndef _MSC_VER |
|
189 |
-#define HAVE_SYS_FILE_H 1 |
|
190 |
-#endif |
|
191 |
- |
|
192 |
-/* Define to 1 if you have the <sys/stat.h> header file. */ |
|
193 |
-#define HAVE_SYS_STAT_H 1 |
|
194 |
- |
|
195 |
-/* Define to 1 if you have the <sys/time.h> header file. */ |
|
196 |
-#ifndef _MSC_VER |
|
197 |
-#define HAVE_SYS_TIME_H 1 |
|
198 |
-#endif |
|
199 |
- |
|
200 |
-/* Define to 1 if you have the <sys/types.h> header file. */ |
|
201 |
-#define HAVE_SYS_TYPES_H 1 |
|
202 |
- |
|
203 |
-/* Define to 1 if you have the `time' function. */ |
|
204 |
-#define HAVE_TIME 1 |
|
205 |
- |
|
206 |
-/* Define to 1 if you have the <unistd.h> header file. */ |
|
207 |
-#ifndef _MSC_VER |
|
208 |
-#define HAVE_UNISTD_H 1 |
|
209 |
-#endif |
|
210 |
- |
|
211 |
-/* Define to 1 if you have the `vsnprintf' function. */ |
|
212 |
-#define HAVE_VSNPRINTF 1 |
|
213 |
- |
|
214 |
-/* Special Windows version of getpass() defined in io.c */ |
|
215 |
-#define HAVE_GETPASS 1 |
|
216 |
- |
|
217 |
-/* Name of package */ |
|
218 |
-#define PACKAGE PRODUCT_UNIX_NAME |
|
219 |
- |
|
220 |
-/* Define to the address where bug reports for this package should be sent. */ |
|
221 |
-//#define PACKAGE_BUGREPORT "openvpn-users@lists.sourceforge.net" |
|
222 |
- |
|
223 |
-/* Define to the full name of this package. */ |
|
224 |
-#define PACKAGE_NAME PRODUCT_NAME |
|
225 |
- |
|
226 |
-/* Define to the one symbol short name of this package. */ |
|
227 |
-#define PACKAGE_TARNAME PACKAGE |
|
228 |
- |
|
229 |
-/* Define to the version of this package. */ |
|
230 |
-#define PACKAGE_VERSION PRODUCT_VERSION |
|
231 |
- |
|
232 |
-/* Define to the full name and version of this package. */ |
|
233 |
-#ifdef DEBUG_LABEL |
|
234 |
-#define PACKAGE_STRING PACKAGE_NAME " " PACKAGE_VERSION " " DEBUG_LABEL |
|
235 |
-#else |
|
236 |
-#define PACKAGE_STRING PACKAGE_NAME " " PACKAGE_VERSION |
|
237 |
-#endif |
|
238 |
- |
|
239 |
-/* Define as the return type of signal handlers (`int' or `void'). */ |
|
240 |
-#define RETSIGTYPE void |
|
241 |
- |
|
242 |
-/* The size of a `unsigned int', as computed by sizeof. */ |
|
243 |
-#define SIZEOF_UNSIGNED_INT 4 |
|
244 |
- |
|
245 |
-/* The size of a `unsigned long', as computed by sizeof. */ |
|
246 |
-#define SIZEOF_UNSIGNED_LONG 4 |
|
247 |
- |
|
248 |
-/* Define to 1 if you have the ANSI C header files. */ |
|
249 |
-#define STDC_HEADERS 1 |
|
250 |
- |
|
251 |
-/* A string representing our target */ |
|
252 |
-#ifdef _MSC_VER |
|
253 |
-#define TARGET_ALIAS "Win32-MSVC++" |
|
254 |
-#else |
|
255 |
-#define TARGET_ALIAS "Win32-MinGW" |
|
256 |
-#endif |
|
257 |
- |
|
258 |
-/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */ |
|
259 |
-#ifndef _MSC_VER |
|
260 |
-#define TIME_WITH_SYS_TIME 1 |
|
261 |
-#endif |
|
262 |
- |
|
263 |
-/* Use OpenSSL crypto library */ |
|
264 |
-#define USE_CRYPTO 1 |
|
265 |
- |
|
266 |
-/* Use LZO compression library */ |
|
267 |
-#define USE_LZO 1 |
|
268 |
- |
|
269 |
-/* LZO version number */ |
|
270 |
-#define LZO_VERSION_NUM "2" |
|
271 |
- |
|
272 |
-/* Use lzo/ directory prefix for LZO header files (for LZO 2.0) */ |
|
273 |
-#define LZO_HEADER_DIR 1 |
|
274 |
- |
|
275 |
-/* Use OpenSSL SSL library */ |
|
276 |
-#define USE_SSL 1 |
|
277 |
- |
|
278 |
-/* Version number of package */ |
|
279 |
-#define VERSION PACKAGE_VERSION |
|
280 |
- |
|
281 |
-/* Define as `__inline' if that's what the C compiler calls it, or to nothing |
|
282 |
- if it is not supported. */ |
|
283 |
-#define inline __inline |
|
284 |
- |
|
285 |
-/* type to use in place of socklen_t if not defined */ |
|
286 |
-#define socklen_t unsigned int |
|
287 |
- |
|
288 |
-/* 32-bit unsigned type */ |
|
289 |
-#define uint32_t unsigned int |
|
290 |
- |
|
291 |
-/* 16-bit unsigned type */ |
|
292 |
-#define uint16_t unsigned short |
|
293 |
- |
|
294 |
-/* 8-bit unsigned type */ |
|
295 |
-#define uint8_t unsigned char |
|
296 |
- |
|
297 |
-/* Route command */ |
|
298 |
-#define ROUTE_PATH "route" |
|
299 |
- |
|
300 |
-/* Windows doesn't support PTHREAD yet */ |
|
301 |
-#ifdef USE_PTHREAD |
|
302 |
-#error The Windows version of OpenVPN does not support PTHREAD yet |
|
303 |
-#endif |
|
304 |
- |
|
305 |
-#ifdef _MSC_VER |
|
306 |
-/* MSVC++ hacks */ |
|
307 |
-#include <io.h> |
|
308 |
-#include <direct.h> |
|
309 |
-#define vsnprintf _vsnprintf |
|
310 |
-#define vsnwprintf _vsnwprintf |
|
311 |
-#define snwprintf _snwprintf |
|
312 |
-#define write _write |
|
313 |
-#define open _open |
|
314 |
-#define read _read |
|
315 |
-#define close _close |
|
316 |
-#define chdir _chdir |
|
317 |
-#define S_IRUSR 0 |
|
318 |
-#define S_IWUSR 0 |
|
319 |
-typedef int intptr_t; |
|
320 |
-#undef S_NORMAL |
|
321 |
-#endif |
322 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,326 @@ |
0 |
+/* |
|
1 |
+ * OpenVPN -- An application to securely tunnel IP networks |
|
2 |
+ * over a single UDP port, with support for SSL/TLS-based |
|
3 |
+ * session authentication and key exchange, |
|
4 |
+ * packet encryption, packet authentication, and |
|
5 |
+ * packet compression. |
|
6 |
+ * |
|
7 |
+ * Copyright (C) 2002-2005 OpenVPN Solutions LLC <info@openvpn.net> |
|
8 |
+ * |
|
9 |
+ * This program is free software; you can redistribute it and/or modify |
|
10 |
+ * it under the terms of the GNU General Public License version 2 |
|
11 |
+ * as published by the Free Software Foundation. |
|
12 |
+ * |
|
13 |
+ * This program is distributed in the hope that it will be useful, |
|
14 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 |
+ * GNU General Public License for more details. |
|
17 |
+ * |
|
18 |
+ * You should have received a copy of the GNU General Public License |
|
19 |
+ * along with this program (see the file COPYING included with this |
|
20 |
+ * distribution); if not, write to the Free Software Foundation, Inc., |
|
21 |
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
22 |
+ */ |
|
23 |
+ |
|
24 |
+/* |
|
25 |
+ * Configuration header for Win32 using the mingw environment. |
|
26 |
+ * Manually edited based on linux version as generated by autoconf. |
|
27 |
+ * |
|
28 |
+ * config-win32.h is normally generated by copying |
|
29 |
+ * config-win32.h.in -> config-win32.h and replacing |
|
30 |
+ * [ampersand] VERSION [ampersand] |
|
31 |
+ * with the appropriate version #. This is normally |
|
32 |
+ * done automatically by configure.ac |
|
33 |
+ */ |
|
34 |
+ |
|
35 |
+#include <windows.h> |
|
36 |
+#include <winsock2.h> |
|
37 |
+#include "autodefs/defs.h" |
|
38 |
+ |
|
39 |
+#define sleep(x) Sleep((x)*1000) |
|
40 |
+ |
|
41 |
+#define random rand |
|
42 |
+#define srandom srand |
|
43 |
+ |
|
44 |
+typedef unsigned long in_addr_t; |
|
45 |
+ |
|
46 |
+#ifndef _SSIZE_T_ |
|
47 |
+#define _SSIZE_T_ |
|
48 |
+ typedef unsigned int ssize_t; |
|
49 |
+#endif |
|
50 |
+ |
|
51 |
+/* Append a label to program startup title */ |
|
52 |
+/*#define DEBUG_LABEL "DEBUG1"*/ |
|
53 |
+ |
|
54 |
+/* Should we print debug info from driver? */ |
|
55 |
+#ifdef PRODUCT_TAP_DEBUG |
|
56 |
+#define TAP_WIN32_DEBUG |
|
57 |
+#endif |
|
58 |
+ |
|
59 |
+/* |
|
60 |
+ * Minimum TAP-Win32 version number expected by userspace |
|
61 |
+ * |
|
62 |
+ * The TAP-Win32 version number is defined in tap-win32/SOURCES |
|
63 |
+ */ |
|
64 |
+#define TAP_ID @TAP_ID@ |
|
65 |
+#define TAP_WIN32_MIN_MAJOR @TAP_WIN32_MIN_MAJOR@ |
|
66 |
+#define TAP_WIN32_MIN_MINOR @TAP_WIN32_MIN_MINOR@ |
|
67 |
+ |
|
68 |
+/* Enable client/server capability */ |
|
69 |
+#define ENABLE_CLIENT_SERVER 1 |
|
70 |
+ |
|
71 |
+/* Enable client capability only */ |
|
72 |
+/* #undef ENABLE_CLIENT_ONLY */ |
|
73 |
+ |
|
74 |
+/* Enable management server capability */ |
|
75 |
+#define ENABLE_MANAGEMENT 1 |
|
76 |
+ |
|
77 |
+/* Enable PKCS#11 support */ |
|
78 |
+#define USE_PKCS11 1 |
|
79 |
+ |
|
80 |
+/* Enable HTTP proxy support */ |
|
81 |
+#define ENABLE_HTTP_PROXY 1 |
|
82 |
+ |
|
83 |
+/* Enable Socks proxy support */ |
|
84 |
+#define ENABLE_SOCKS 1 |
|
85 |
+ |
|
86 |
+/* Enable internal fragmentation support */ |
|
87 |
+#define ENABLE_FRAGMENT 1 |
|
88 |
+ |
|
89 |
+/* Enable smaller executable size */ |
|
90 |
+/* #undef ENABLE_SMALL */ |
|
91 |
+ |
|
92 |
+/* Enable debugging support */ |
|
93 |
+#define ENABLE_DEBUG 1 |
|
94 |
+ |
|
95 |
+/* if defined, will allow usage of the --plugin directive */ |
|
96 |
+#define USE_LOAD_LIBRARY |
|
97 |
+ |
|
98 |
+/* Dimension size to use for empty array declaration */ |
|
99 |
+#define EMPTY_ARRAY_SIZE 0 |
|
100 |
+ |
|
101 |
+/* Define to 1 if you have the `getsockname' function. */ |
|
102 |
+#define HAVE_GETSOCKNAME 1 |
|
103 |
+ |
|
104 |
+/* Define to 1 if you have the <openssl/engine.h> header file. */ |
|
105 |
+#define HAVE_OPENSSL_ENGINE_H 1 |
|
106 |
+ |
|
107 |
+/* Define to 1 if you have the `ENGINE_load_builtin_engines' function. */ |
|
108 |
+#define HAVE_ENGINE_LOAD_BUILTIN_ENGINES 1 |
|
109 |
+ |
|
110 |
+/* Define to 1 if you have the `ENGINE_register_all_complete' function. */ |
|
111 |
+#define HAVE_ENGINE_REGISTER_ALL_COMPLETE 1 |
|
112 |
+ |
|
113 |
+/* Define to 1 if you have the `ENGINE_cleanup' function. */ |
|
114 |
+#define HAVE_ENGINE_CLEANUP 1 |
|
115 |
+ |
|
116 |
+/* gettimeofday() is implemented in otime.c for Windows */ |
|
117 |
+#define HAVE_GETTIMEOFDAY 1 |
|
118 |
+ |
|
119 |
+/* Define to 1 if you have the 'chsize' function. */ |
|
120 |
+#define HAVE_CHSIZE 1 |
|
121 |
+ |
|
122 |
+/* Define to 1 if you have the `chdir' function. */ |
|
123 |
+#define HAVE_CHDIR 1 |
|
124 |
+ |
|
125 |
+/* Define to 1 if your compiler supports GNU GCC-style variadic macros */ |
|
126 |
+#ifndef _MSC_VER /* Defines MSFT compiler version. Defined as 1200 for MSVC++ 6.0. */ |
|
127 |
+#define HAVE_CPP_VARARG_MACRO_GCC 1 |
|
128 |
+#endif |
|
129 |
+ |
|
130 |
+/* Define to 1 if you have the <ctype.h> header file. */ |
|
131 |
+#define HAVE_CTYPE_H 1 |
|
132 |
+ |
|
133 |
+/* Define to 1 if you have the <errno.h> header file. */ |
|
134 |
+#define HAVE_ERRNO_H 1 |
|
135 |
+ |
|
136 |
+/* Define to 1 if you have the `EVP_CIPHER_CTX_set_key_length' function. */ |
|
137 |
+#define HAVE_EVP_CIPHER_CTX_SET_KEY_LENGTH 1 |
|
138 |
+ |
|
139 |
+/* Define to 1 if you have the <fcntl.h> header file. */ |
|
140 |
+#define HAVE_FCNTL_H 1 |
|
141 |
+ |
|
142 |
+/* Define to 1 if you have the `getsockopt' function. */ |
|
143 |
+#define HAVE_GETSOCKOPT 1 |
|
144 |
+ |
|
145 |
+/* Define to 1 if you have the `inet_ntoa' function. */ |
|
146 |
+#define HAVE_INET_NTOA 1 |
|
147 |
+ |
|
148 |
+/* Define to 1 if your system has a GNU libc compatible `malloc' function, and |
|
149 |
+ to 0 otherwise. */ |
|
150 |
+#define HAVE_MALLOC 1 |
|
151 |
+ |
|
152 |
+/* Define to 1 if you have the `memset' function. */ |
|
153 |
+#define HAVE_MEMSET 1 |
|
154 |
+ |
|
155 |
+/* Define to 1 if you have the `setsockopt' function. */ |
|
156 |
+#define HAVE_SETSOCKOPT 1 |
|
157 |
+ |
|
158 |
+/* Define to 1 if you have the `socket' function. */ |
|
159 |
+#define HAVE_SOCKET 1 |
|
160 |
+ |
|
161 |
+/* Define to 1 if you have the <stdarg.h> header file. */ |
|
162 |
+#define HAVE_STDARG_H 1 |
|
163 |
+ |
|
164 |
+/* Define to 1 if you have the <stdint.h> header file. */ |
|
165 |
+#ifndef _MSC_VER |
|
166 |
+#define HAVE_STDINT_H 1 |
|
167 |
+#endif |
|
168 |
+ |
|
169 |
+/* Define to 1 if you have the <stdio.h> header file. */ |
|
170 |
+#define HAVE_STDIO_H 1 |
|
171 |
+ |
|
172 |
+/* Define to 1 if you have the <stdlib.h> header file. */ |
|
173 |
+#define HAVE_STDLIB_H 1 |
|
174 |
+ |
|
175 |
+/* Define to 1 if you have the `strerror' function. */ |
|
176 |
+#define HAVE_STRERROR 1 |
|
177 |
+ |
|
178 |
+/* Define to 1 if you have the <strings.h> header file. */ |
|
179 |
+#define HAVE_STRINGS_H 1 |
|
180 |
+ |
|
181 |
+/* Define to 1 if you have the <string.h> header file. */ |
|
182 |
+#define HAVE_STRING_H 1 |
|
183 |
+ |
|
184 |
+/* Define to 1 if you have the `system' function. */ |
|
185 |
+#define HAVE_SYSTEM 1 |
|
186 |
+ |
|
187 |
+/* Define to 1 if you have the <sys/file.h> header file. */ |
|
188 |
+#ifndef _MSC_VER |
|
189 |
+#define HAVE_SYS_FILE_H 1 |
|
190 |
+#endif |
|
191 |
+ |
|
192 |
+/* Define to 1 if you have the <sys/stat.h> header file. */ |
|
193 |
+#define HAVE_SYS_STAT_H 1 |
|
194 |
+ |
|
195 |
+/* Define to 1 if you have the <sys/time.h> header file. */ |
|
196 |
+#ifndef _MSC_VER |
|
197 |
+#define HAVE_SYS_TIME_H 1 |
|
198 |
+#endif |
|
199 |
+ |
|
200 |
+/* Define to 1 if you have the <sys/types.h> header file. */ |
|
201 |
+#define HAVE_SYS_TYPES_H 1 |
|
202 |
+ |
|
203 |
+/* Define to 1 if you have the `time' function. */ |
|
204 |
+#define HAVE_TIME 1 |
|
205 |
+ |
|
206 |
+/* Define to 1 if you have the <unistd.h> header file. */ |
|
207 |
+#ifndef _MSC_VER |
|
208 |
+#define HAVE_UNISTD_H 1 |
|
209 |
+#endif |
|
210 |
+ |
|
211 |
+/* Define to 1 if you have the `vsnprintf' function. */ |
|
212 |
+#define HAVE_VSNPRINTF 1 |
|
213 |
+ |
|
214 |
+/* Special Windows version of getpass() defined in io.c */ |
|
215 |
+#define HAVE_GETPASS 1 |
|
216 |
+ |
|
217 |
+/* Name of package */ |
|
218 |
+#define PACKAGE @PACKAGE@ |
|
219 |
+ |
|
220 |
+/* Define to the address where bug reports for this package should be sent. */ |
|
221 |
+//#define PACKAGE_BUGREPORT "openvpn-users@lists.sourceforge.net" |
|
222 |
+ |
|
223 |
+/* Define to the full name of this package. */ |
|
224 |
+#define PACKAGE_NAME @PACKAGE_NAME@ |
|
225 |
+ |
|
226 |
+/* Define to the one symbol short name of this package. */ |
|
227 |
+#define PACKAGE_TARNAME @PACKAGE_TARNAME@ |
|
228 |
+ |
|
229 |
+/* Define to the version of this package. */ |
|
230 |
+#define PACKAGE_VERSION @PACKAGE_VERSION@ |
|
231 |
+ |
|
232 |
+/* Define to the full name and version of this package. */ |
|
233 |
+#ifdef DEBUG_LABEL |
|
234 |
+#define PACKAGE_STRING PACKAGE_NAME " " PACKAGE_VERSION " " DEBUG_LABEL |
|
235 |
+#else |
|
236 |
+#define PACKAGE_STRING PACKAGE_NAME " " PACKAGE_VERSION |
|
237 |
+#endif |
|
238 |
+ |
|
239 |
+/* Define as the return type of signal handlers (`int' or `void'). */ |
|
240 |
+#define RETSIGTYPE void |
|
241 |
+ |
|
242 |
+/* The size of a `unsigned int', as computed by sizeof. */ |
|
243 |
+#define SIZEOF_UNSIGNED_INT 4 |
|
244 |
+ |
|
245 |
+/* The size of a `unsigned long', as computed by sizeof. */ |
|
246 |
+#define SIZEOF_UNSIGNED_LONG 4 |
|
247 |
+ |
|
248 |
+/* Define to 1 if you have the ANSI C header files. */ |
|
249 |
+#define STDC_HEADERS 1 |
|
250 |
+ |
|
251 |
+/* A string representing our target */ |
|
252 |
+#ifdef _MSC_VER |
|
253 |
+#define TARGET_ALIAS "Win32-MSVC++" |
|
254 |
+#else |
|
255 |
+#define TARGET_ALIAS "Win32-MinGW" |
|
256 |
+#endif |
|
257 |
+ |
|
258 |
+/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */ |
|
259 |
+#ifndef _MSC_VER |
|
260 |
+#define TIME_WITH_SYS_TIME 1 |
|
261 |
+#endif |
|
262 |
+ |
|
263 |
+/* Use OpenSSL crypto library */ |
|
264 |
+#define USE_CRYPTO 1 |
|
265 |
+ |
|
266 |
+/* Use LZO compression library */ |
|
267 |
+#define USE_LZO 1 |
|
268 |
+ |
|
269 |
+/* LZO version number */ |
|
270 |
+#define LZO_VERSION_NUM "2" |
|
271 |
+ |
|
272 |
+/* Use lzo/ directory prefix for LZO header files (for LZO 2.0) */ |
|
273 |
+#define LZO_HEADER_DIR 1 |
|
274 |
+ |
|
275 |
+/* Use OpenSSL SSL library */ |
|
276 |
+#define USE_SSL 1 |
|
277 |
+ |
|
278 |
+/* Version number of package */ |
|
279 |
+#define VERSION PACKAGE_VERSION |
|
280 |
+ |
|
281 |
+/* Define as `__inline' if that's what the C compiler calls it, or to nothing |
|
282 |
+ if it is not supported. */ |
|
283 |
+#define inline __inline |
|
284 |
+ |
|
285 |
+/* type to use in place of socklen_t if not defined */ |
|
286 |
+#define socklen_t unsigned int |
|
287 |
+ |
|
288 |
+/* 32-bit unsigned type */ |
|
289 |
+#define uint32_t unsigned int |
|
290 |
+ |
|
291 |
+/* 16-bit unsigned type */ |
|
292 |
+#define uint16_t unsigned short |
|
293 |
+ |
|
294 |
+/* 8-bit unsigned type */ |
|
295 |
+#define uint8_t unsigned char |
|
296 |
+ |
|
297 |
+/* Route command */ |
|
298 |
+#define ROUTE_PATH "route" |
|
299 |
+ |
|
300 |
+/* Windows doesn't support PTHREAD yet */ |
|
301 |
+#ifdef USE_PTHREAD |
|
302 |
+#error The Windows version of OpenVPN does not support PTHREAD yet |
|
303 |
+#endif |
|
304 |
+ |
|
305 |
+#ifdef _MSC_VER |
|
306 |
+/* MSVC++ hacks */ |
|
307 |
+#include <io.h> |
|
308 |
+#include <direct.h> |
|
309 |
+#define vsnprintf _vsnprintf |
|
310 |
+#define vsnwprintf _vsnwprintf |
|
311 |
+#define snwprintf _snwprintf |
|
312 |
+#define write _write |
|
313 |
+#define open _open |
|
314 |
+#define read _read |
|
315 |
+#define close _close |
|
316 |
+#define chdir _chdir |
|
317 |
+#define S_IRUSR 0 |
|
318 |
+#define S_IWUSR 0 |
|
319 |
+typedef int intptr_t; |
|
320 |
+#undef S_NORMAL |
|
321 |
+/* Visual Studio 2005 supports vararg macros */ |
|
322 |
+#if _MSC_VER >= 1400 |
|
323 |
+#define HAVE_CPP_VARARG_MACRO_ISO 1 |
|
324 |
+#endif |
|
325 |
+#endif |
... | ... |
@@ -30,6 +30,39 @@ AC_INIT([OpenVPN], [PRODUCT_VERSION], [openvpn-users@lists.sourceforge.net], [op |
30 | 30 |
AM_CONFIG_HEADER(config.h) |
31 | 31 |
AC_CONFIG_SRCDIR(syshead.h) |
32 | 32 |
|
33 |
+dnl Guess host type. |
|
34 |
+AC_CANONICAL_HOST |
|
35 |
+AC_CANONICAL_SYSTEM |
|
36 |
+AM_INIT_AUTOMAKE(openvpn, [$PACKAGE_VERSION]) |
|
37 |
+ |
|
38 |
+AC_ARG_WITH(cygwin-native, |
|
39 |
+ [ --with-cygwin-native Compile native win32], |
|
40 |
+ [CYGWIN_NATIVE="${withval}"], |
|
41 |
+ [CYGWIN_NATIVE="no"] |
|
42 |
+) |
|
43 |
+ |
|
44 |
+WIN32="no" |
|
45 |
+CYGWIN="no" |
|
46 |
+case "${host}" in |
|
47 |
+ *-mingw32*) |
|
48 |
+ WIN32="yes" |
|
49 |
+ cross_compiling="yes" |
|
50 |
+ ;; |
|
51 |
+ *-cygwin*) |
|
52 |
+ AC_MSG_CHECKING([cygwin mode to use]) |
|
53 |
+ if test "${CYGWIN_NATIVE}" = "yes"; then |
|
54 |
+ AC_MSG_RESULT([Using native win32]) |
|
55 |
+ CFLAGS="${CFLAGS} -mno-cygwin" |
|
56 |
+ CYGWIN="yes" |
|
57 |
+ WIN32="yes" |
|
58 |
+ else |
|
59 |
+ AC_MSG_RESULT([Using cygwin]) |
|
60 |
+ fi |
|
61 |
+ ;; |
|
62 |
+ *) |
|
63 |
+ ;; |
|
64 |
+esac |
|
65 |
+ |
|
33 | 66 |
AC_ARG_ENABLE(lzo, |
34 | 67 |
[ --disable-lzo Disable LZO compression support], |
35 | 68 |
[LZO="$enableval"], |
... | ... |
@@ -183,6 +216,17 @@ AC_ARG_WITH(lzo-lib, |
183 | 183 |
[LDFLAGS="$LDFLAGS -L$withval"] |
184 | 184 |
) |
185 | 185 |
|
186 |
+AC_ARG_WITH(pkcs11-helper-headers, |
|
187 |
+ [ --with-pkcs11-helper-headers=DIR pkcs11-helper Include files location], |
|
188 |
+ [PKCS11_HELPER_HDR_DIR="$withval"] |
|
189 |
+ [CPPFLAGS="$CPPFLAGS -I$withval"] |
|
190 |
+) |
|
191 |
+ |
|
192 |
+AC_ARG_WITH(pkcs11-helper-lib, |
|
193 |
+ [ --with-pkcs11-helper-lib=DIR pkcs11-helper Library location], |
|
194 |
+ [LDFLAGS="$LDFLAGS -L$withval"] |
|
195 |
+) |
|
196 |
+ |
|
186 | 197 |
AC_ARG_WITH(ifconfig-path, |
187 | 198 |
[ --with-ifconfig-path=PATH Path to ifconfig tool], |
188 | 199 |
[IFCONFIG="$withval"], |
... | ... |
@@ -210,11 +254,6 @@ AC_ARG_WITH(mem-check, |
210 | 210 |
[MEMCHECK="$withval"] |
211 | 211 |
) |
212 | 212 |
|
213 |
-dnl Guess host type. |
|
214 |
-AC_CANONICAL_HOST |
|
215 |
-AC_CANONICAL_SYSTEM |
|
216 |
-AM_INIT_AUTOMAKE(openvpn, [$PACKAGE_VERSION]) |
|
217 |
- |
|
218 | 213 |
dnl fix search path, to allow compilers to find syshead.h |
219 | 214 |
CPPFLAGS="$CPPFLAGS -I${srcdir}" |
220 | 215 |
|
... | ... |
@@ -250,10 +289,16 @@ case "$target" in |
250 | 250 |
CPPFLAGS="$CPPFLAGS -no-cpp-precomp" |
251 | 251 |
;; |
252 | 252 |
*mingw*) |
253 |
- AC_MSG_RESULT([WARNING: configure support for mingw is incomplete]) |
|
254 |
- AC_MSG_RESULT([WARNING: use makefile.w32 instead]) |
|
253 |
+ AC_DEFINE(TARGET_WIN32, 1, [Are we running WIN32?]) |
|
255 | 254 |
OPENVPN_ADD_LIBS(-lgdi32) |
256 |
- OPENVPN_ADD_LIBS(-lwsock32) |
|
255 |
+ OPENVPN_ADD_LIBS(-lws2_32) |
|
256 |
+ OPENVPN_ADD_LIBS(-lwininet) |
|
257 |
+ OPENVPN_ADD_LIBS(-lcrypt32) |
|
258 |
+ OPENVPN_ADD_LIBS(-liphlpapi) |
|
259 |
+ OPENVPN_ADD_LIBS(-lwinmm) |
|
260 |
+ ;; |
|
261 |
+*dragonfly*) |
|
262 |
+ AC_DEFINE(TARGET_DRAGONFLY, 1, [Are we running on DragonFlyBSD?]) |
|
257 | 263 |
;; |
258 | 264 |
|
259 | 265 |
esac |
... | ... |
@@ -263,6 +308,12 @@ AC_PROG_CC |
263 | 263 |
AC_PROG_INSTALL |
264 | 264 |
AC_PROG_GCC_TRADITIONAL |
265 | 265 |
|
266 |
+if test "${WIN32}" = "yes"; then |
|
267 |
+ AC_ARG_VAR([MAN2HTML], [man2html utility]) |
|
268 |
+ AC_CHECK_PROGS([MAN2HTML], [man2html]) |
|
269 |
+ test -z "${MAN2HTML}" && AC_MSG_ERROR([man2html is required for win32]) |
|
270 |
+fi |
|
271 |
+ |
|
266 | 272 |
dnl Checks for header files. |
267 | 273 |
AC_HEADER_STDC |
268 | 274 |
|
... | ... |
@@ -274,29 +325,36 @@ AC_TYPE_OFF_T |
274 | 274 |
AC_TYPE_PID_T |
275 | 275 |
AC_TYPE_SIZE_T |
276 | 276 |
AC_TYPE_UID_T |
277 |
+TYPE_SOCKLEN_T |
|
277 | 278 |
AC_HEADER_TIME |
278 | 279 |
AX_CPP_VARARG_MACRO_ISO |
279 | 280 |
AX_CPP_VARARG_MACRO_GCC |
280 | 281 |
AX_EMPTY_ARRAY |
281 | 282 |
|
282 | 283 |
dnl Check for more header files. |
283 |
-AC_HEADER_SYS_WAIT |
|
284 |
-AC_CHECK_HEADERS(sys/time.h sys/socket.h sys/ioctl.h sys/stat.h dnl |
|
284 |
+AC_CHECK_HEADERS(fcntl.h stdlib.h dnl |
|
285 |
+ stdarg.h stdio.h string.h dnl |
|
286 |
+ strings.h ctype.h errno.h dnl |
|
287 |
+) |
|
288 |
+ |
|
289 |
+if test "${WIN32}" != "yes"; then |
|
290 |
+ AC_HEADER_SYS_WAIT |
|
291 |
+ AC_CHECK_HEADERS(sys/time.h sys/socket.h sys/ioctl.h sys/stat.h dnl |
|
285 | 292 |
sys/mman.h fcntl.h sys/file.h stdlib.h stdint.h dnl |
286 | 293 |
stdarg.h unistd.h signal.h stdio.h string.h dnl |
287 | 294 |
strings.h ctype.h errno.h syslog.h pwd.h grp.h dnl |
288 |
- net/if_tun.h stropts.h sys/sockio.h dnl |
|
295 |
+ net/if_tun.h net/tun/if_tun.h stropts.h sys/sockio.h dnl |
|
289 | 296 |
netinet/in.h netinet/in_systm.h dnl |
290 | 297 |
netinet/tcp.h arpa/inet.h dnl |
291 | 298 |
netdb.h sys/uio.h linux/if_tun.h linux/sockios.h dnl |
292 | 299 |
linux/types.h sys/poll.h sys/epoll.h err.h dnl |
293 |
-) |
|
294 |
-AC_CHECK_HEADERS(net/if.h,,, |
|
300 |
+ ) |
|
301 |
+ AC_CHECK_HEADERS(net/if.h,,, |
|
295 | 302 |
[#ifdef HAVE_SYS_SOCKET_H |
296 | 303 |
# include <sys/socket.h> |
297 | 304 |
#endif |
298 | 305 |
]) |
299 |
-AC_CHECK_HEADERS(netinet/ip.h,,, |
|
306 |
+ AC_CHECK_HEADERS(netinet/ip.h,,, |
|
300 | 307 |
[#ifdef HAVE_SYS_TYPES_H |
301 | 308 |
# include <sys/types.h> |
302 | 309 |
#endif |
... | ... |
@@ -307,7 +365,7 @@ AC_CHECK_HEADERS(netinet/ip.h,,, |
307 | 307 |
# include <netinet/in_systm.h> |
308 | 308 |
#endif |
309 | 309 |
]) |
310 |
-AC_CHECK_HEADERS(netinet/if_ether.h,,, |
|
310 |
+ AC_CHECK_HEADERS(netinet/if_ether.h,,, |
|
311 | 311 |
[#ifdef HAVE_SYS_TYPES_H |
312 | 312 |
# include <sys/types.h> |
313 | 313 |
#endif |
... | ... |
@@ -318,16 +376,18 @@ AC_CHECK_HEADERS(netinet/if_ether.h,,, |
318 | 318 |
# include <netinet/in.h> |
319 | 319 |
#endif |
320 | 320 |
]) |
321 |
-AC_CHECK_HEADERS(resolv.h,,, |
|
321 |
+ AC_CHECK_HEADERS(resolv.h,,, |
|
322 | 322 |
[#ifdef HAVE_NETINET_IN_H |
323 | 323 |
# include <netinet/in.h> |
324 | 324 |
#endif |
325 | 325 |
]) |
326 |
-AC_CHECK_HEADERS(linux/errqueue.h,,, |
|
326 |
+ AC_CHECK_HEADERS(linux/errqueue.h,,, |
|
327 | 327 |
[#ifdef HAVE_LINUX_TYPES_H |
328 | 328 |
# include <linux/types.h> |
329 | 329 |
#endif |
330 | 330 |
]) |
331 |
+fi |
|
332 |
+ |
|
331 | 333 |
AC_CACHE_SAVE |
332 | 334 |
|
333 | 335 |
dnl check that in_addr_t is defined |
... | ... |
@@ -398,35 +458,59 @@ AC_CHECK_SIZEOF(unsigned long) |
398 | 398 |
|
399 | 399 |
AC_CACHE_SAVE |
400 | 400 |
|
401 |
-dnl check for other types |
|
402 |
-TYPE_SOCKLEN_T |
|
403 |
-AC_TYPE_SIGNAL |
|
404 |
- |
|
405 |
-dnl Check for libsocket |
|
406 |
-AC_SEARCH_LIBS(socket, socket) |
|
407 |
- |
|
408 |
-dnl Check for libnsl |
|
409 |
-AC_SEARCH_LIBS(inet_ntoa, nsl) |
|
410 |
- |
|
411 |
-dnl Check for libresolv |
|
412 |
-AC_SEARCH_LIBS(gethostbyname, resolv nsl) |
|
413 |
- |
|
414 |
-dnl optional library functions |
|
415 |
-AC_FUNC_FORK |
|
416 | 401 |
AC_CHECK_FUNCS(daemon chroot getpwnam setuid nice system getpid dup dup2 dnl |
417 | 402 |
getpass strerror syslog openlog mlockall getgrnam setgid dnl |
418 | 403 |
setgroups stat flock readv writev setsockopt getsockopt dnl |
419 |
- setsid chdir gettimeofday putenv getpeername unlink dnl |
|
420 |
- poll chsize ftruncate sendmsg recvmsg getsockname) |
|
404 |
+ setsid chdir putenv getpeername unlink dnl |
|
405 |
+ poll chsize ftruncate sendmsg recvmsg getsockname) |
|
421 | 406 |
AC_CACHE_SAVE |
422 | 407 |
|
408 |
+if test "${WIN32}" = "yes"; then |
|
409 |
+ |
|
410 |
+ AC_DEFINE([HAVE_GETTIMEOFDAY], [1], [We fake gettimeofday for win32 at otime.c]) |
|
411 |
+ |
|
412 |
+else |
|
413 |
+ |
|
414 |
+ dnl check for other types |
|
415 |
+ AC_TYPE_SIGNAL |
|
416 |
+ |
|
417 |
+ dnl Check for libsocket |
|
418 |
+ AC_SEARCH_LIBS(socket, socket) |
|
419 |
+ |
|
420 |
+ dnl Check for libnsl |
|
421 |
+ AC_SEARCH_LIBS(inet_ntoa, nsl) |
|
422 |
+ |
|
423 |
+ dnl Check for libresolv |
|
424 |
+ AC_SEARCH_LIBS(gethostbyname, resolv nsl) |
|
425 |
+ |
|
426 |
+ dnl optional library functions |
|
427 |
+ AC_FUNC_FORK |
|
428 |
+ |
|
429 |
+ AC_CHECK_FUNCS(gettimeofday) |
|
430 |
+ |
|
431 |
+ AC_CHECK_FUNCS(socket recv recvfrom send sendto listen dnl |
|
432 |
+ accept connect bind select gethostbyname dnl |
|
433 |
+ inet_ntoa time ctime memset vsnprintf strdup, [], |
|
434 |
+ [AC_MSG_ERROR([Required library function not found])]) |
|
435 |
+ |
|
436 |
+fi |
|
437 |
+ |
|
423 | 438 |
dnl Required library functions |
424 | 439 |
AC_FUNC_MEMCMP |
425 | 440 |
|
426 |
-AC_CHECK_FUNCS(socket recv recvfrom send sendto listen dnl |
|
427 |
- accept connect bind select gethostbyname dnl |
|
428 |
- inet_ntoa time ctime memset vsnprintf strdup, [], |
|
429 |
- [AC_MSG_ERROR([Required library function not found])]) |
|
441 |
+dnl |
|
442 |
+dnl Check for res_init |
|
443 |
+dnl |
|
444 |
+AC_TRY_LINK([ |
|
445 |
+ #include <resolv.h> |
|
446 |
+ ], [ |
|
447 |
+ res_init (); |
|
448 |
+ ], [ |
|
449 |
+ AC_MSG_RESULT([res_init DEFINED]) |
|
450 |
+ AC_DEFINE([HAVE_RES_INIT], 1, [Indicates if res_init is available]) |
|
451 |
+ ], [ |
|
452 |
+ AC_MSG_RESULT([res_init UNDEFINED]) |
|
453 |
+ ]) |
|
430 | 454 |
|
431 | 455 |
dnl |
432 | 456 |
dnl check libraries |
... | ... |
@@ -505,21 +589,23 @@ fi |
505 | 505 |
dnl |
506 | 506 |
dnl Check for dlopen -- first try libc then libdl. |
507 | 507 |
dnl |
508 |
-if test "$PLUGINS" = "yes"; then |
|
509 |
- AC_CHECKING([for libdl Library and Header files]) |
|
510 |
- AC_CHECK_HEADER(dlfcn.h, |
|
511 |
- [AC_CHECK_FUNC(dlopen, |
|
512 |
- [AC_DEFINE(USE_LIBDL, 1, [Use libdl for dynamic library loading])], |
|
513 |
- [AC_CHECK_LIB(dl, dlopen, |
|
514 |
- [ |
|
515 |
- OPENVPN_ADD_LIBS(-ldl) |
|
516 |
- AC_DEFINE(USE_LIBDL, 1, [Use libdl for dynamic library loading]) |
|
517 |
- ], |
|
518 |
- [AC_MSG_RESULT([libdl library not found.])] |
|
519 |
- )], |
|
520 |
- )], |
|
521 |
- [AC_MSG_RESULT([libdl headers not found.])] |
|
522 |
- ) |
|
508 |
+if test "${WIN32}" != "yes"; then |
|
509 |
+ if test "$PLUGINS" = "yes"; then |
|
510 |
+ AC_CHECKING([for libdl Library and Header files]) |
|
511 |
+ AC_CHECK_HEADER(dlfcn.h, |
|
512 |
+ [AC_CHECK_FUNC(dlopen, |
|
513 |
+ [AC_DEFINE(USE_LIBDL, 1, [Use libdl for dynamic library loading])], |
|
514 |
+ [AC_CHECK_LIB(dl, dlopen, |
|
515 |
+ [ |
|
516 |
+ OPENVPN_ADD_LIBS(-ldl) |
|
517 |
+ AC_DEFINE(USE_LIBDL, 1, [Use libdl for dynamic library loading]) |
|
518 |
+ ], |
|
519 |
+ [AC_MSG_RESULT([libdl library not found.])] |
|
520 |
+ )], |
|
521 |
+ )], |
|
522 |
+ [AC_MSG_RESULT([libdl headers not found.])] |
|
523 |
+ ) |
|
524 |
+ fi |
|
523 | 525 |
fi |
524 | 526 |
|
525 | 527 |
dnl |
... | ... |
@@ -572,7 +658,7 @@ if test "$CRYPTO" = "yes"; then |
572 | 572 |
AC_CHECKING([that OpenSSL Library is at least version 0.9.6]) |
573 | 573 |
AC_EGREP_CPP(yes, |
574 | 574 |
[ |
575 |
- #include "openssl/evp.h" |
|
575 |
+ #include <openssl/evp.h> |
|
576 | 576 |
#if SSLEAY_VERSION_NUMBER >= 0x00906000L |
577 | 577 |
yes |
578 | 578 |
#endif |
... | ... |
@@ -692,7 +778,7 @@ fi |
692 | 692 |
|
693 | 693 |
dnl enable strict compiler warnings |
694 | 694 |
if test "$STRICT" = "yes"; then |
695 |
- CFLAGS="$CFLAGS -Wall -Wpointer-arith -Wsign-compare -Wno-unused-parameter -Wno-unused-function" |
|
695 |
+ CFLAGS="$CFLAGS -Wall -Wno-unused-parameter -Wno-unused-function" |
|
696 | 696 |
fi |
697 | 697 |
|
698 | 698 |
dnl enable pedantic compiler warnings |
... | ... |
@@ -715,4 +801,37 @@ if test "$PASSWORD_SAVE" = "yes"; then |
715 | 715 |
AC_DEFINE(ENABLE_PASSWORD_SAVE, 1, [Allow --askpass and --auth-user-pass passwords to be read from a file]) |
716 | 716 |
fi |
717 | 717 |
|
718 |
-AC_OUTPUT(Makefile openvpn.spec) |
|
718 |
+TAP_ID="PRODUCT_TAP_ID" |
|
719 |
+TAP_WIN32_MIN_MAJOR="PRODUCT_TAP_WIN32_MIN_MAJOR" |
|
720 |
+TAP_WIN32_MIN_MINOR="PRODUCT_TAP_WIN32_MIN_MINOR" |
|
721 |
+AC_DEFINE_UNQUOTED(TAP_ID, "${TAP_ID}", [The TAP-Win32 id defined in tap-win32/SOURCES]) |
|
722 |
+AC_DEFINE_UNQUOTED(TAP_WIN32_MIN_MAJOR, ${TAP_WIN32_MIN_MAJOR}, [The TAP-Win32 version number is defined in tap-win32/SOURCES]) |
|
723 |
+AC_DEFINE_UNQUOTED(TAP_WIN32_MIN_MINOR, ${TAP_WIN32_MIN_MINOR}, [The TAP-Win32 version number is defined in tap-win32/SOURCES]) |
|
724 |
+AC_SUBST(TAP_ID) |
|
725 |
+AC_SUBST(TAP_WIN32_MIN_MAJOR) |
|
726 |
+AC_SUBST(TAP_WIN32_MIN_MINOR) |
|
727 |
+ |
|
728 |
+win32datadir="\${datadir}/${PACKAGE}-win32" |
|
729 |
+AC_SUBST(win32datadir) |
|
730 |
+AM_CONDITIONAL(WIN32, test "${WIN32}" = "yes") |
|
731 |
+ |
|
732 |
+# workaround for <autoconf-2.60 |
|
733 |
+if test -z "${docdir}"; then |
|
734 |
+ docdir="\$(datarootdir)/doc/\$(PACKAGE_NAME)" |
|
735 |
+ AC_SUBST([docdir]) |
|
736 |
+fi |
|
737 |
+if test -z "${htmldir}"; then |
|
738 |
+ htmldir="\$(docdir)" |
|
739 |
+ AC_SUBST([htmldir]) |
|
740 |
+fi |
|
741 |
+# end workaround |
|
742 |
+ |
|
743 |
+AC_OUTPUT([ |
|
744 |
+ Makefile |
|
745 |
+ openvpn.spec |
|
746 |
+ config-win32.h |
|
747 |
+ images/Makefile |
|
748 |
+ service-win32/Makefile |
|
749 |
+ install-win32/Makefile |
|
750 |
+ install-win32/settings |
|
751 |
+]) |
... | ... |
@@ -22,16 +22,10 @@ |
22 | 22 |
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
23 | 23 |
*/ |
24 | 24 |
|
25 |
-#ifdef WIN32 |
|
26 |
-#include "config-win32.h" |
|
27 |
-#else |
|
28 |
-#include "config.h" |
|
29 |
-#endif |
|
25 |
+#include "syshead.h" |
|
30 | 26 |
|
31 | 27 |
#ifdef USE_CRYPTO |
32 | 28 |
|
33 |
-#include "syshead.h" |
|
34 |
- |
|
35 | 29 |
#include "crypto.h" |
36 | 30 |
#include "error.h" |
37 | 31 |
#include "misc.h" |
... | ... |
@@ -27,13 +27,18 @@ |
27 | 27 |
* LITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF |
28 | 28 |
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 | 29 |
*/ |
30 |
+ |
|
31 |
+#include "syshead.h" |
|
32 |
+ |
|
33 |
+#ifdef WIN32 |
|
34 |
+ |
|
35 |
+#include <openssl/ssl.h> |
|
36 |
+#include <openssl/err.h> |
|
30 | 37 |
#include <windows.h> |
31 | 38 |
#include <wincrypt.h> |
32 | 39 |
#include <stdio.h> |
33 | 40 |
#include <ctype.h> |
34 | 41 |
#include <assert.h> |
35 |
-#include <openssl/ssl.h> |
|
36 |
-#include <openssl/err.h> |
|
37 | 42 |
|
38 | 43 |
#ifdef __MINGW32_VERSION |
39 | 44 |
/* MinGW w32api is incomplete when it comes to CryptoAPI, as per version 3.1 |
... | ... |
@@ -461,3 +466,7 @@ int SSL_CTX_use_CryptoAPI_certificate(SSL_CTX *ssl_ctx, const char *cert_prop) |
461 | 461 |
} |
462 | 462 |
return 0; |
463 | 463 |
} |
464 |
+ |
|
465 |
+#else |
|
466 |
+static void dummy (void) {} |
|
467 |
+#endif /* WIN32 */ |
... | ... |
@@ -1,16 +1,71 @@ |
1 | 1 |
#!/bin/sh |
2 | 2 |
|
3 |
-# Let's have a fresh start. Remove all files |
|
4 |
-# which are not source files. |
|
3 |
+# Let's have a fresh start. Remove all |
|
4 |
+# generated files. |
|
5 | 5 |
# |
6 | 6 |
# Run this script, then: |
7 |
-# touch * |
|
8 |
-# [apply any patches here] |
|
9 | 7 |
# autoreconf -i -v |
10 | 8 |
# ./configure |
11 | 9 |
# make |
12 | 10 |
# make install |
13 | 11 |
|
14 |
-rm -f *.o openvpn config.cache configure Makefile Makefile.in stamp-h* config.guess config.sub depcomp missing mkinstalldirs config.log config.status config.h config.h.in aclocal.m4 openvpn.spec install-sh |
|
12 |
+rm -f \ |
|
13 |
+ *.o \ |
|
14 |
+ service-win32/*.o \ |
|
15 |
+ service-win32/*.exe \ |
|
16 |
+ *.exe \ |
|
17 |
+ openvpn \ |
|
18 |
+ config.cache \ |
|
19 |
+ configure \ |
|
20 |
+ Makefile \ |
|
21 |
+ Makefile.in \ |
|
22 |
+ stamp-h* \ |
|
23 |
+ config.guess \ |
|
24 |
+ config.sub \ |
|
25 |
+ depcomp \ |
|
26 |
+ missing \ |
|
27 |
+ mkinstalldirs \ |
|
28 |
+ config.log \ |
|
29 |
+ config.status \ |
|
30 |
+ config.h \ |
|
31 |
+ config.h.in \ |
|
32 |
+ aclocal.m4 \ |
|
33 |
+ openvpn.spec \ |
|
34 |
+ install-sh \ |
|
35 |
+ openvpn.8.html \ |
|
36 |
+ config-win32.h \ |
|
37 |
+ install-win32/*.exe \ |
|
38 |
+ install-win32/makensis.log \ |
|
39 |
+ install-win32/settings \ |
|
40 |
+ install-win32/Makefile \ |
|
41 |
+ install-win32/Makefile.in \ |
|
42 |
+ images/Makefile \ |
|
43 |
+ images/Makefile.in \ |
|
44 |
+ service-win32/Makefile \ |
|
45 |
+ service-win32/Makefile.in |
|
15 | 46 |
|
16 |
-rm -rf autom4te*.cache .deps |
|
47 |
+rm -rf \ |
|
48 |
+ autom4te*.cache \ |
|
49 |
+ .deps \ |
|
50 |
+ */.deps \ |
|
51 |
+ windest \ |
|
52 |
+ autodefs \ |
|
53 |
+ gen \ |
|
54 |
+ tapinstall \ |
|
55 |
+ install-win32/tmp |
|
56 |
+ |
|
57 |
+rm -rf \ |
|
58 |
+ tap-win32/objfre_w2k_x86 \ |
|
59 |
+ tap-win32/dist \ |
|
60 |
+ tap-win32/SOURCES \ |
|
61 |
+ tap-win32/tapdrvr.cod \ |
|
62 |
+ tap-win32/buildfre_wnet_amd64.wrn \ |
|
63 |
+ tap-win32/buildfre_w2k_x86.wrn \ |
|
64 |
+ tap-win32/objfre_wnet_amd64 \ |
|
65 |
+ tap-win32/buildfre_wnet_amd64.log \ |
|
66 |
+ tap-win32/buildfre_w2k_x86.log \ |
|
67 |
+ tap-win32/amd64 \ |
|
68 |
+ tap-win32/i386/tap0901.pdb \ |
|
69 |
+ tap-win32/i386/OemWin2k.inf \ |
|
70 |
+ tap-win32/i386/tap0901.map \ |
|
71 |
+ tap-win32/i386/tap0901.sys |
... | ... |
@@ -6,8 +6,14 @@ |
6 | 6 |
# 2000 and higher, and x64 on Windows 2003 and higher. |
7 | 7 |
# For quick start options, see pre-built notes below. |
8 | 8 |
# |
9 |
+# Note that if you are only looking to build the |
|
10 |
+# openvpn user-space binaries (openvpn.exe |
|
11 |
+# and openvpnserv.exe) you can use the |
|
12 |
+# provided autoconf/automake build environment. |
|
13 |
+# |
|
9 | 14 |
# See top-level build configuration and settings in: |
10 | 15 |
# |
16 |
+# version.m4 |
|
11 | 17 |
# install-win32/settings.in |
12 | 18 |
# |
13 | 19 |
# Mandatory prerequisites: |
... | ... |
@@ -105,12 +111,9 @@ install-win32/getprebuilt |
105 | 105 |
# The exception is the last script which gathers together all files from |
106 | 106 |
# GENOUT and builds the installer. |
107 | 107 |
|
108 |
-# Make the OpenVPN user-space component (openvpn.exe) |
|
108 |
+# Make the OpenVPN user-space components (OpenVPN and service) |
|
109 | 109 |
install-win32/makeopenvpn |
110 | 110 |
|
111 |
-# Make the OpenVPN service |
|
112 |
-install-win32/makeservice |
|
113 |
- |
|
114 | 111 |
# Make the OpenVPN TAP driver |
115 | 112 |
install-win32/maketap |
116 | 113 |
|
34 | 28 |
deleted file mode 100755 |
... | ... |
@@ -1,111 +0,0 @@ |
1 |
-#!/sbin/runscript |
|
2 |
- |
|
3 |
-# OpenVPN start/stop script |
|
4 |
-# Adapted to Gentoo by James Yonan |
|
5 |
- |
|
6 |
-# Originally Contributed to the OpenVPN project by |
|
7 |
-# Douglas Keller <doug@voidstar.dyndns.org> |
|
8 |
-# 2002.05.15 |
|
9 |
- |
|
10 |
-# This script does the following: |
|
11 |
-# |
|
12 |
-# - Starts an openvpn process for each .conf file it finds in |
|
13 |
-# /etc/openvpn. |
|
14 |
-# |
|
15 |
-# - If /etc/openvpn/xxx.sh exists for a xxx.conf file then it executes |
|
16 |
-# it before starting openvpn (useful for doing openvpn --mktun...). |
|
17 |
- |
|
18 |
-# - In addition to start/stop you can do: |
|
19 |
-# |
|
20 |
-# service openvpn reload - SIGHUP |
|
21 |
-# service openvpn reopen - SIGUSR1 |
|
22 |
-# service openvpn status - SIGUSR2 |
|
23 |
- |
|
24 |
-# Location of openvpn binary |
|
25 |
-openvpn=/usr/local/sbin/openvpn |
|
26 |
- |
|
27 |
-# PID directory |
|
28 |
-piddir=/var/run/openvpn |
|
29 |
- |
|
30 |
-# Our working directory (.conf files should be here) |
|
31 |
-work=/etc/openvpn |
|
32 |
- |
|
33 |
-# Our options |
|
34 |
-opts="start stop restart condrestart" |
|
35 |
- |
|
36 |
-depend() { |
|
37 |
- need net |
|
38 |
- use dns |
|
39 |
-} |
|
40 |
- |
|
41 |
-start() { |
|
42 |
- ebegin "Starting OpenVPN" |
|
43 |
- |
|
44 |
- # Load the TUN/TAP module |
|
45 |
- /sbin/modprobe tun >/dev/null 2>&1 |
|
46 |
- |
|
47 |
- if [ ! -d $piddir ]; then |
|
48 |
- mkdir $piddir |
|
49 |
- fi |
|
50 |
- |
|
51 |
- cd $work |
|
52 |
- |
|
53 |
- # Start every .conf in $work and run .sh if exists |
|
54 |
- local errors=0 |
|
55 |
- local successes=0 |
|
56 |
- local retstatus=0 |
|
57 |
- for c in `/bin/ls *.conf 2>/dev/null`; do |
|
58 |
- bn=${c%%.conf} |
|
59 |
- if [ -f "$bn.sh" ]; then |
|
60 |
- . $bn.sh |
|
61 |
- fi |
|
62 |
- rm -f $piddir/$bn.pid |
|
63 |
- $openvpn --daemon openvpn-$bn --writepid $piddir/$bn.pid --config $c --cd $work |
|
64 |
- if [ $? = 0 ]; then |
|
65 |
- successes=1 |
|
66 |
- else |
|
67 |
- errors=1 |
|
68 |
- fi |
|
69 |
- done |
|
70 |
- |
|
71 |
- # Decide status based on errors/successes. |
|
72 |
- # If at least one tunnel succeeded, we return success. |
|
73 |
- # If some tunnels succeeded and some failed, we return |
|
74 |
- # success but give a warning. |
|
75 |
- if [ $successes = 1 ]; then |
|
76 |
- if [ $errors = 1 ]; then |
|
77 |
- ewarn "Note: At least one OpenVPN tunnel failed to start" |
|
78 |
- fi |
|
79 |
- else |
|
80 |
- retstatus=1 |
|
81 |
- if [ $errors = 0 ]; then |
|
82 |
- ewarn "Note: No OpenVPN configuration files were found in $work" |
|
83 |
- fi |
|
84 |
- fi |
|
85 |
- eend $retstatus "Error starting OpenVPN" |
|
86 |
-} |
|
87 |
- |
|
88 |
-stop() { |
|
89 |
- ebegin "Stopping OpenVPN" |
|
90 |
- for pidf in `/bin/ls $piddir/*.pid 2>/dev/null`; do |
|
91 |
- if [ -s $pidf ]; then |
|
92 |
- kill `cat $pidf` >/dev/null 2>&1 |
|
93 |
- fi |
|
94 |
- rm -f $pidf |
|
95 |
- done |
|
96 |
- eend 0 |
|
97 |
-} |
|
98 |
- |
|
99 |
-# this should really be in runscript.sh |
|
100 |
-started() { |
|
101 |
- if [ -L "${svcdir}/started/${myservice}" ]; then |
|
102 |
- return 1 |
|
103 |
- else |
|
104 |
- return 0 |
|
105 |
- fi |
|
106 |
-} |
|
107 |
- |
|
108 |
-# attempt to restart ONLY if we are already started |
|
109 |
-condrestart() { |
|
110 |
- started || restart |
|
111 |
-} |
... | ... |
@@ -17,7 +17,11 @@ |
17 | 17 |
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
18 | 18 |
*/ |
19 | 19 |
|
20 |
-#include <WinInet.h> |
|
20 |
+#include "syshead.h" |
|
21 |
+ |
|
22 |
+#ifdef WIN32 |
|
23 |
+ |
|
24 |
+#include <wininet.h> |
|
21 | 25 |
#include <malloc.h> |
22 | 26 |
|
23 | 27 |
LPCTSTR getIeHttpProxyError=NULL; |
... | ... |
@@ -135,3 +139,7 @@ LPCTSTR getIeHttpProxy() |
135 | 135 |
return(NULL); |
136 | 136 |
} |
137 | 137 |
} |
138 |
+ |
|
139 |
+#else |
|
140 |
+static void dummy (void) {} |
|
141 |
+#endif /* WIN32 */ |
0 | 2 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,41 @@ |
0 |
+# |
|
1 |
+# OpenVPN -- An application to securely tunnel IP networks |
|
2 |
+# over a single UDP port, with support for SSL/TLS-based |
|
3 |
+# session authentication and key exchange, |
|
4 |
+# packet encryption, packet authentication, and |
|
5 |
+# packet compression. |
|
6 |
+# |
|
7 |
+# Copyright (C) 2002-2005 OpenVPN Solutions LLC <info@openvpn.net> |
|
8 |
+# |
|
9 |
+# This program is free software; you can redistribute it and/or modify |
|
10 |
+# it under the terms of the GNU General Public License version 2 |
|
11 |
+# as published by the Free Software Foundation. |
|
12 |
+# |
|
13 |
+# This program is distributed in the hope that it will be useful, |
|
14 |
+# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 |
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 |
+# GNU General Public License for more details. |
|
17 |
+# |
|
18 |
+# You should have received a copy of the GNU General Public License |
|
19 |
+# along with this program (see the file COPYING included with this |
|
20 |
+# distribution); if not, write to the Free Software Foundation, Inc., |
|
21 |
+# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
22 |
+# |
|
23 |
+ |
|
24 |
+MAINTAINERCLEANFILES = $(srcdir)/Makefile.in |
|
25 |
+ |
|
26 |
+images = \ |
|
27 |
+ install-whirl.bmp \ |
|
28 |
+ icon.ico |
|
29 |
+ |
|
30 |
+if WIN32 |
|
31 |
+ |
|
32 |
+imagedir = $(win32datadir)/images |
|
33 |
+dist_image_DATA = $(images) |
|
34 |
+ |
|
35 |
+else |
|
36 |
+ |
|
37 |
+dist_noinst_DATA = $(images) |
|
38 |
+ |
|
39 |
+endif |
|
40 |
+ |
2 | 6 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,74 @@ |
0 |
+# |
|
1 |
+# OpenVPN -- An application to securely tunnel IP networks |
|
2 |
+# over a single UDP port, with support for SSL/TLS-based |
|
3 |
+# session authentication and key exchange, |
|
4 |
+# packet encryption, packet authentication, and |
|
5 |
+# packet compression. |
|
6 |
+# |
|
7 |
+# Copyright (C) 2002-2005 OpenVPN Solutions LLC <info@openvpn.net> |
|
8 |
+# |
|
9 |
+# This program is free software; you can redistribute it and/or modify |
|
10 |
+# it under the terms of the GNU General Public License version 2 |
|
11 |
+# as published by the Free Software Foundation. |
|
12 |
+# |
|
13 |
+# This program is distributed in the hope that it will be useful, |
|
14 |
+# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 |
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 |
+# GNU General Public License for more details. |
|
17 |
+# |
|
18 |
+# You should have received a copy of the GNU General Public License |
|
19 |
+# along with this program (see the file COPYING included with this |
|
20 |
+# distribution); if not, write to the Free Software Foundation, Inc., |
|
21 |
+# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
22 |
+# |
|
23 |
+ |
|
24 |
+MAINTAINERCLEANFILES = $(srcdir)/Makefile.in |
|
25 |
+ |
|
26 |
+dist_noinst_DATA = \ |
|
27 |
+ openvpn.nsi \ |
|
28 |
+ setpath.nsi |
|
29 |
+ |
|
30 |
+if WIN32 |
|
31 |
+ |
|
32 |
+nodist_doc_DATA = tmp/license.txt |
|
33 |
+ |
|
34 |
+confdir = $(win32datadir)/config |
|
35 |
+nodist_conf_DATA = \ |
|
36 |
+ tmp/openssl.cnf.sample \ |
|
37 |
+ tmp/client.ovpn \ |
|
38 |
+ tmp/server.ovpn |
|
39 |
+dist_conf_DATA = \ |
|
40 |
+ sample.ovpn |
|
41 |
+ |
|
42 |
+easyrsadir = $(win32datadir)/easy-rsa/Windows |
|
43 |
+nodist_easyrsa_DATA = \ |
|
44 |
+ $(top_srcdir)/easy-rsa/Windows/* |
|
45 |
+ |
|
46 |
+keysdir = $(win32datadir)/sample-keys |
|
47 |
+nodist_keys_DATA = \ |
|
48 |
+ $(top_srcdir)/sample-keys/* |
|
49 |
+ |
|
50 |
+tmp: |
|
51 |
+ mkdir tmp |
|
52 |
+ |
|
53 |
+tmp/client.ovpn: tmp $(top_srcdir)/sample-config-files/client.conf |
|
54 |
+ cp $(top_srcdir)/sample-config-files/client.conf tmp/client.ovpn |
|
55 |
+ |
|
56 |
+tmp/server.ovpn: tmp $(top_srcdir)/sample-config-files/server.conf |
|
57 |
+ cp $(top_srcdir)/sample-config-files/server.conf tmp/server.ovpn |
|
58 |
+ |
|
59 |
+tmp/license.txt: tmp $(top_srcdir)/COPYING $(top_srcdir)/COPYRIGHT.GPL |
|
60 |
+ cat $(top_srcdir)/COPYING $(top_srcdir)/COPYRIGHT.GPL > tmp/license.txt |
|
61 |
+ |
|
62 |
+tmp/openssl.cnf.sample: tmp $(top_srcdir)/easy-rsa/2.0/openssl.cnf |
|
63 |
+ cp $(top_srcdir)/easy-rsa/2.0/openssl.cnf tmp/openssl.cnf.sample |
|
64 |
+ |
|
65 |
+clean-local: |
|
66 |
+ -rm -fr tmp |
|
67 |
+ |
|
68 |
+else |
|
69 |
+ |
|
70 |
+dist_noinst_DATA += sample.ovpn |
|
71 |
+ |
|
72 |
+endif |
|
73 |
+ |
... | ... |
@@ -7,7 +7,7 @@ |
7 | 7 |
if [ -d "$PKCS11_HELPER_DIR" ] ; then |
8 | 8 |
mkdir -p $GENOUT/lib &>/dev/null |
9 | 9 |
for f in libpkcs11-helper-1.dll ; do |
10 |
- cp $PKCS11_HELPER_DIR/bin/$f $GENOUT/lib |
|
10 |
+ cp $PKCS11_HELPER_DIR/usr/local/bin/$f $GENOUT/lib |
|
11 | 11 |
if [ -z "$NO_STRIP" ]; then |
12 | 12 |
strip $GENOUT/lib/$f |
13 | 13 |
fi |
... | ... |
@@ -1,19 +1,37 @@ |
1 | 1 |
#!/bin/sh |
2 | 2 |
|
3 |
+H=`pwd` |
|
4 |
+ |
|
3 | 5 |
# get version.nsi definitions |
4 | 6 |
. autodefs/defs.sh |
5 | 7 |
|
6 | 8 |
if gcc --version &>/dev/null && [ -d "$OPENSSL_DIR" ] && [ -d "$LZO_DIR" ] && [ -d "$PKCS11_HELPER_DIR" ]; then |
7 | 9 |
# build OpenVPN binary |
8 |
- [ "$CLEAN" = "yes" ] && make -f makefile.w32 clean |
|
9 |
- make -f makefile.w32 -j $MAKE_JOBS |
|
10 | 10 |
|
11 |
- # copy OpenVPN executable to GENOUT/bin |
|
11 |
+ if ! [ -f Makefile ]; then |
|
12 |
+ autoreconf -i -v \ |
|
13 |
+ && ./configure \ |
|
14 |
+ --enable-strict \ |
|
15 |
+ --prefix=$H/windest \ |
|
16 |
+ MAN2HTML=true \ |
|
17 |
+ --with-ssl-headers=$H/$OPENSSL_DIR/include \ |
|
18 |
+ --with-ssl-lib=$H/$OPENSSL_DIR/out \ |
|
19 |
+ --with-lzo-headers=$H/$LZO_DIR/include \ |
|
20 |
+ --with-lzo-lib=$H/$LZO_DIR \ |
|
21 |
+ --with-pkcs11-helper-headers=$H/$PKCS11_HELPER_DIR/usr/local/include \ |
|
22 |
+ --with-pkcs11-helper-lib=$H/$PKCS11_HELPER_DIR/usr/local/lib |
|
23 |
+ fi |
|
24 |
+ |
|
25 |
+ make -j $MAKE_JOBS && make install |
|
26 |
+ |
|
27 |
+ # copy OpenVPN and service executables to GENOUT/bin |
|
12 | 28 |
mkdir -p $GENOUT/bin &>/dev/null |
13 |
- cp $PRODUCT_UNIX_NAME.exe $GENOUT/bin |
|
29 |
+ cp windest/sbin/openvpn.exe $GENOUT/bin |
|
30 |
+ cp windest/sbin/openvpnserv.exe $GENOUT/bin |
|
14 | 31 |
if [ -z "$NO_STRIP" ]; then |
15 |
- strip $GENOUT/bin/$PRODUCT_UNIX_NAME.exe |
|
32 |
+ strip $GENOUT/bin/openvpn.exe |
|
33 |
+ strip $GENOUT/bin/openvpnserv.exe |
|
16 | 34 |
fi |
17 | 35 |
else |
18 |
- echo DID NOT BUILD openvpn.exe because one or more of gcc, OPENSSL_DIR, LZO_DIR, or PKCS11_HELPER_DIR directories were missing |
|
36 |
+ echo DID NOT BUILD openvpn.exe and openvpnserv.exe because one or more of gcc, OPENSSL_DIR, LZO_DIR, or PKCS11_HELPER_DIR directories were missing |
|
19 | 37 |
fi |
20 | 38 |
deleted file mode 100644 |
... | ... |
@@ -1,32 +0,0 @@ |
1 |
-#!/bin/sh |
|
2 |
- |
|
3 |
-# get version.nsi definitions |
|
4 |
-. autodefs/defs.sh |
|
5 |
- |
|
6 |
-# build OpenVPN service (openvpnserv.exe) |
|
7 |
-if [ -d "$SVC_TEMPLATE" ] ; then |
|
8 |
- # silly vista security theatre |
|
9 |
- PATCH="/tmp/p.exe" |
|
10 |
- cp `which patch` $PATCH |
|
11 |
- |
|
12 |
- # build service sources |
|
13 |
- cp $SVC_TEMPLATE/service.[ch] service-win32 |
|
14 |
- cd service-win32 |
|
15 |
- cp service.c service.c.orig |
|
16 |
- cp service.h service.h.orig |
|
17 |
- $PATCH <service.patch |
|
18 |
- |
|
19 |
- # compile/link |
|
20 |
- [ "$CLEAN" = "yes" ] && make clean |
|
21 |
- make -j $MAKE_JOBS |
|
22 |
- cd .. |
|
23 |
- |
|
24 |
- # copy service to GENOUT/bin |
|
25 |
- mkdir $GENOUT/bin &>/dev/null |
|
26 |
- cp service-win32/${PRODUCT_UNIX_NAME}serv.exe $GENOUT/bin |
|
27 |
- if [ -z "$NO_STRIP" ]; then |
|
28 |
- strip $GENOUT/bin/${PRODUCT_UNIX_NAME}serv.exe |
|
29 |
- fi |
|
30 |
-else |
|
31 |
- echo OpenVPN service not built -- template directory $SVC_TEMPLATE NOT FOUND |
|
32 |
-fi |
... | ... |
@@ -19,12 +19,12 @@ |
19 | 19 |
|
20 | 20 |
# Include the OpenVPN XML-based GUI exe in the installer. |
21 | 21 |
# May be undefined. |
22 |
-!define OPENVPN_XGUI_DIR "../ovpnxml" |
|
22 |
+;!define OPENVPN_XGUI_DIR "../ovpnxml" |
|
23 | 23 |
|
24 | 24 |
# Prebuilt libraries. DMALLOC is optional. |
25 | 25 |
!define OPENSSL_DIR "../openssl-0.9.7m" |
26 | 26 |
!define LZO_DIR "../lzo-2.02" |
27 |
-!define PKCS11_HELPER_DIR "../pkcs11-helper/usr/local" |
|
27 |
+!define PKCS11_HELPER_DIR "../pkcs11-helper" |
|
28 | 28 |
!define DMALLOC_DIR "../dmalloc-5.4.2" |
29 | 29 |
|
30 | 30 |
# Optional directory of prebuilt OpenVPN binary components, |
... | ... |
@@ -36,10 +36,10 @@ |
36 | 36 |
# Not needed if DRVBINSRC is defined. |
37 | 37 |
!define TISRC "../tapinstall" |
38 | 38 |
|
39 |
-# TAP Adapter parameters. |
|
39 |
+# TAP Adapter parameters. Note that PRODUCT_TAP_ID is |
|
40 |
+# defined in version.m4. |
|
40 | 41 |
!define PRODUCT_TAP_DEVICE_DESCRIPTION "TAP-Win32 Adapter V9" |
41 | 42 |
!define PRODUCT_TAP_PROVIDER "TAP-Win32 Provider V9" |
42 |
-!define PRODUCT_TAP_ID "tap0901" |
|
43 | 43 |
!define PRODUCT_TAP_MAJOR_VER 9 |
44 | 44 |
!define PRODUCT_TAP_MINOR_VER 4 |
45 | 45 |
!define PRODUCT_TAP_RELDATE "01/22/2008" |
... | ... |
@@ -50,10 +50,6 @@ |
50 | 50 |
# Build debugging version of TAP driver |
51 | 51 |
;!define PRODUCT_TAP_DEBUG |
52 | 52 |
|
53 |
-# Service template files service.[ch] (get from Platform SDK). |
|
54 |
-# If undefined, don't build openvpnserv.exe |
|
55 |
-!define SVC_TEMPLATE "../svc-template" |
|
56 |
- |
|
57 | 53 |
# DDK Version. |
58 | 54 |
# DDK distribution is assumed to be in C:\WINDDK\${DDKVER} |
59 | 55 |
!define DDKVER 6001.17121 |
... | ... |
@@ -22,16 +22,10 @@ |
22 | 22 |
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
23 | 23 |
*/ |
24 | 24 |
|
25 |
-#ifdef WIN32 |
|
26 |
-#include "config-win32.h" |
|
27 |
-#else |
|
28 |
-#include "config.h" |
|
29 |
-#endif |
|
25 |
+#include "syshead.h" |
|
30 | 26 |
|
31 | 27 |
#ifdef USE_LZO |
32 | 28 |
|
33 |
-#include "syshead.h" |
|
34 |
- |
|
35 | 29 |
#include "lzo.h" |
36 | 30 |
#include "error.h" |
37 | 31 |
#include "otime.h" |
38 | 32 |
deleted file mode 100755 |
... | ... |
@@ -1,204 +0,0 @@ |
1 |
-# This Makefile builds the user-mode component |
|
2 |
-# of OpenVPN for WIN32 in the MinGW environment. |
|
3 |
-# |
|
4 |
-# Build Dependencies: |
|
5 |
-# mingw (GNU C compiler for windows) |
|
6 |
-# msys (GNU utilities and shell for windows) |
|
7 |
-# OpenSSL (SSL/TLS/crypto library) |
|
8 |
-# LZO (real-time compression library) |
|
9 |
-# Dmalloc (debugging only) |
|
10 |
-# |
|
11 |
-# Targets: |
|
12 |
-# static -- link statically with OpenSSL |
|
13 |
-# dynamic -- link dynamically with OpenSSL |
|
14 |
-# dmalloc -- enable memory debugging using the dmalloc library |
|
15 |
-# |
|
16 |
-# Note that LZO is always linked statically. |
|
17 |
-# |
|
18 |
-# To build openssl-0.9.7d, remember to edit ms\mw.bat |
|
19 |
-# adding '--win32' flag to make command: |
|
20 |
-# |
|
21 |
-# make --win32 -f ms/mingw32.mak |
|
22 |
-# |
|
23 |
-# Now cd to top level openssl directory in a Windows |
|
24 |
-# command-prompt window, and type: |
|
25 |
-# |
|
26 |
-# ms\mw |
|
27 |
-# |
|
28 |
-# See additional .bat scripts in install-win32 for OpenSSL |
|
29 |
-# build setup. |
|
30 |
-# |
|
31 |
-# If you are building with dmalloc debugging support |
|
32 |
-# see windbg.h for additional dmalloc notes. |
|
33 |
- |
|
34 |
-######################################################### |
|
35 |
-# Change these to point to your OpenSSL, LZO, and |
|
36 |
-# (optionally) dmalloc top-level directories. |
|
37 |
-# Normally set as environmental variables before calling |
|
38 |
-# make. |
|
39 |
-# |
|
40 |
-#OPENSSL_DIR = |
|
41 |
-#LZO_DIR = |
|
42 |
-#DMALLOC_DIR = |
|
43 |
-#PKCS11_HELPER_DIR = |
|
44 |
- |
|
45 |
-######################################################### |
|
46 |
- |
|
47 |
-CC = gcc -g -O2 -Wall -Wno-unused-function -Wno-unused-variable -mno-cygwin |
|
48 |
- |
|
49 |
-CC_DMALLOC = gcc -g -O2 -Wall -Wno-unused-function -Wno-unused-variable -mno-cygwin -fno-inline -DDMALLOC |
|
50 |
- |
|
51 |
-INCLUDE_DIRS = -I${OPENSSL_DIR}/include -I${LZO_DIR}/include -I${PKCS11_HELPER_DIR}/include |
|
52 |
- |
|
53 |
-INCLUDE_DIRS_DMALLOC = ${INCLUDE_DIRS} -I${DMALLOC_DIR} |
|
54 |
- |
|
55 |
-LIBS = -llzo2 -lcrypt32 -lWinInet -lws2_32 -lgdi32 -liphlpapi -lwinmm -lpkcs11-helper |
|
56 |
- |
|
57 |
-LIBS_DMALLOC = ${LIBS} -ldmalloc |
|
58 |
- |
|
59 |
-LIB_DIRS = -L${OPENSSL_DIR}/out -L${LZO_DIR} -L${PKCS11_HELPER_DIR}/lib |
|
60 |
- |
|
61 |
-LIB_DIRS_DMALLOC = ${LIB_DIRS} -L${DMALLOC_DIR} |
|
62 |
- |
|
63 |
-EXE = ${PRODUCT_UNIX_NAME}.exe |
|
64 |
- |
|
65 |
-HEADERS = \ |
|
66 |
- base64.h \ |
|
67 |
- basic.h \ |
|
68 |
- buffer.h \ |
|
69 |
- circ_list.h \ |
|
70 |
- common.h \ |
|
71 |
- tap-win32/common.h \ |
|
72 |
- config-win32.h \ |
|
73 |
- crypto.h \ |
|
74 |
- cryptoapi.h \ |
|
75 |
- errlevel.h \ |
|
76 |
- error.h \ |
|
77 |
- event.h \ |
|
78 |
- fdmisc.h \ |
|
79 |
- forward-inline.h \ |
|
80 |
- forward.h \ |
|
81 |
- fragment.h \ |
|
82 |
- gremlin.h \ |
|
83 |
- helper.h \ |
|
84 |
- init.h \ |
|
85 |
- integer.h \ |
|
86 |
- interval.h \ |
|
87 |
- list.h \ |
|
88 |
- lladdr.h \ |
|
89 |
- lzo.h \ |
|
90 |
- manage.h \ |
|
91 |
- mbuf.h \ |
|
92 |
- memdbg.h \ |
|
93 |
- misc.h \ |
|
94 |
- mroute.h \ |
|
95 |
- mss.h \ |
|
96 |
- mtcp.h \ |
|
97 |
- mtu.h \ |
|
98 |
- mudp.h \ |
|
99 |
- multi.h \ |
|
100 |
- ntlm.h \ |
|
101 |
- occ-inline.h \ |
|
102 |
- occ.h \ |
|
103 |
- pkcs11.h \ |
|
104 |
- openvpn.h \ |
|
105 |
- openvpn-plugin.h \ |
|
106 |
- options.h \ |
|
107 |
- otime.h \ |
|
108 |
- packet_id.h \ |
|
109 |
- perf.h \ |
|
110 |
- ping-inline.h \ |
|
111 |
- ping.h \ |
|
112 |
- plugin.h \ |
|
113 |
- pool.h \ |
|
114 |
- proto.h \ |
|
115 |
- proxy.h \ |
|
116 |
- push.h \ |
|
117 |
- reliable.h \ |
|
118 |
- route.h \ |
|
119 |
- schedule.h \ |
|
120 |
- session_id.h \ |
|
121 |
- shaper.h \ |
|
122 |
- sig.h \ |
|
123 |
- socket.h \ |
|
124 |
- socks.h \ |
|
125 |
- ssl.h \ |
|
126 |
- status.h \ |
|
127 |
- syshead.h \ |
|
128 |
- thread.h \ |
|
129 |
- tun.h \ |
|
130 |
- win32.h |
|
131 |
- |
|
132 |
-OBJS = base64.o \ |
|
133 |
- buffer.o \ |
|
134 |
- crypto.o \ |
|
135 |
- cryptoapi.o \ |
|
136 |
- error.o \ |
|
137 |
- event.o \ |
|
138 |
- fdmisc.o \ |
|
139 |
- forward.o \ |
|
140 |
- fragment.o \ |
|
141 |
- gremlin.o \ |
|
142 |
- helper.o \ |
|
143 |
- init.o \ |
|
144 |
- interval.o \ |
|
145 |
- list.o \ |
|
146 |
- lladdr.o \ |
|
147 |
- lzo.o \ |
|
148 |
- manage.o \ |
|
149 |
- mbuf.o \ |
|
150 |
- misc.o \ |
|
151 |
- mroute.o \ |
|
152 |
- mss.o \ |
|
153 |
- mtcp.o \ |
|
154 |
- mtu.o \ |
|
155 |
- mudp.o \ |
|
156 |
- multi.o \ |
|
157 |
- ntlm.o \ |
|
158 |
- occ.o \ |
|
159 |
- pkcs11.o \ |
|
160 |
- openvpn.o \ |
|
161 |
- options.o \ |
|
162 |
- otime.o \ |
|
163 |
- packet_id.o \ |
|
164 |
- perf.o \ |
|
165 |
- ping.o \ |
|
166 |
- plugin.o \ |
|
167 |
- pool.o \ |
|
168 |
- proto.o \ |
|
169 |
- proxy.o \ |
|
170 |
- push.o \ |
|
171 |
- reliable.o \ |
|
172 |
- route.o \ |
|
173 |
- schedule.o \ |
|
174 |
- session_id.o \ |
|
175 |
- shaper.o \ |
|
176 |
- sig.o \ |
|
177 |
- socket.o \ |
|
178 |
- socks.o \ |
|
179 |
- ssl.o \ |
|
180 |
- status.o \ |
|
181 |
- thread.o \ |
|
182 |
- tun.o \ |
|
183 |
- win32.o |
|
184 |
- |
|
185 |
-dynamic : MY_CC = ${CC} |
|
186 |
-dynamic : MY_INCLUDE_DIRS = ${INCLUDE_DIRS} |
|
187 |
-dynamic : ${OBJS} |
|
188 |
- ${MY_CC} -o ${EXE} ${OBJS} ${LIB_DIRS} -lssl32 -leay32 ${LIBS} |
|
189 |
- |
|
190 |
-static : MY_CC = ${CC} |
|
191 |
-static : MY_INCLUDE_DIRS = ${INCLUDE_DIRS} |
|
192 |
-static : ${OBJS} |
|
193 |
- ${CC} -o ${EXE} ${OBJS} ${LIB_DIRS} -lssl -lcrypto ${LIBS} |
|
194 |
- |
|
195 |
-dmalloc : MY_CC = ${CC_DMALLOC} |
|
196 |
-dmalloc : MY_INCLUDE_DIRS = ${INCLUDE_DIRS_DMALLOC} |
|
197 |
-dmalloc : ${OBJS} |
|
198 |
- ${MY_CC} -o ${EXE} ${OBJS} ${LIB_DIRS_DMALLOC} -lssl32 -leay32 ${LIBS_DMALLOC} |
|
199 |
- |
|
200 |
-clean : |
|
201 |
- rm -f ${OBJS} ${EXE} |
|
202 |
- |
|
203 |
-%.o : %.c ${HEADERS} |
|
204 |
- ${MY_CC} ${MY_INCLUDE_DIRS} -c $< -o $@ |
... | ... |
@@ -22,12 +22,6 @@ |
22 | 22 |
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
23 | 23 |
*/ |
24 | 24 |
|
25 |
-#ifdef WIN32 |
|
26 |
-#include "config-win32.h" |
|
27 |
-#else |
|
28 |
-#include "config.h" |
|
29 |
-#endif |
|
30 |
- |
|
31 | 25 |
#include "syshead.h" |
32 | 26 |
|
33 | 27 |
#ifdef ENABLE_MANAGEMENT |
... | ... |
@@ -45,6 +39,10 @@ |
45 | 45 |
|
46 | 46 |
#include "memdbg.h" |
47 | 47 |
|
48 |
+#ifdef ENABLE_PKCS11 |
|
49 |
+#include "pkcs11.h" |
|
50 |
+#endif |
|
51 |
+ |
|
48 | 52 |
#define MANAGEMENT_ECHO_PULL_INFO 0 |
49 | 53 |
|
50 | 54 |
#if MANAGEMENT_ECHO_PULL_INFO |
... | ... |
@@ -82,8 +80,14 @@ man_help () |
82 | 82 |
msg (M_CLIENT, "mute [n] : Set log mute level to n, or show level if n is absent."); |
83 | 83 |
msg (M_CLIENT, "needok type action : Enter confirmation for NEED-OK request of 'type',"); |
84 | 84 |
msg (M_CLIENT, " where action = 'ok' or 'cancel'."); |
85 |
+ msg (M_CLIENT, "needstr type action : Enter confirmation for NEED-STR request of 'type',"); |
|
86 |
+ msg (M_CLIENT, " where action is reply string."); |
|
85 | 87 |
msg (M_CLIENT, "net : (Windows only) Show network info and routing table."); |
86 | 88 |
msg (M_CLIENT, "password type p : Enter password p for a queried OpenVPN password."); |
89 |
+#ifdef ENABLE_PKCS11 |
|
90 |
+ msg (M_CLIENT, "pkcs11-id-count : Get number of available PKCS#11 identities."); |
|
91 |
+ msg (M_CLIENT, "pkcs11-id-get index : Get PKCS#11 identity at index."); |
|
92 |
+#endif |
|
87 | 93 |
msg (M_CLIENT, "signal s : Send signal s to daemon,"); |
88 | 94 |
msg (M_CLIENT, " s = SIGHUP|SIGTERM|SIGUSR1|SIGUSR2."); |
89 | 95 |
msg (M_CLIENT, "state [on|off] [N|all] : Like log, but show state history."); |
... | ... |
@@ -541,6 +545,10 @@ man_up_finalize (struct management *man) |
541 | 541 |
if (strlen (man->connection.up_query.password)) |
542 | 542 |
man->connection.up_query.defined = true; |
543 | 543 |
break; |
544 |
+ case UP_QUERY_NEED_STR: |
|
545 |
+ if (strlen (man->connection.up_query.password)) |
|
546 |
+ man->connection.up_query.defined = true; |
|
547 |
+ break; |
|
544 | 548 |
default: |
545 | 549 |
ASSERT (0); |
546 | 550 |
} |
... | ... |
@@ -604,6 +612,13 @@ man_query_need_ok (struct management *man, const char *type, const char *action) |
604 | 604 |
} |
605 | 605 |
|
606 | 606 |
static void |
607 |
+man_query_need_str (struct management *man, const char *type, const char *action) |
|
608 |
+{ |
|
609 |
+ const bool needed = ((man->connection.up_query_mode == UP_QUERY_NEED_STR) && man->connection.up_query_type); |
|
610 |
+ man_query_user_pass (man, type, action, needed, "needstr-string", man->connection.up_query.password, USER_PASS_LEN); |
|
611 |
+} |
|
612 |
+ |
|
613 |
+static void |
|
607 | 614 |
man_forget_passwords (struct management *man) |
608 | 615 |
{ |
609 | 616 |
ssl_purge_auth (); |
... | ... |
@@ -623,6 +638,33 @@ man_net (struct management *man) |
623 | 623 |
} |
624 | 624 |
} |
625 | 625 |
|
626 |
+#ifdef ENABLE_PKCS11 |
|
627 |
+ |
|
628 |
+static void |
|
629 |
+man_pkcs11_id_count (struct management *man) |
|
630 |
+{ |
|
631 |
+ msg (M_CLIENT, ">PKCS11ID-COUNT:%d", pkcs11_management_id_count ()); |
|
632 |
+} |
|
633 |
+ |
|
634 |
+static void |
|
635 |
+man_pkcs11_id_get (struct management *man, const int index) |
|
636 |
+{ |
|
637 |
+ char *id = NULL; |
|
638 |
+ char *base64 = NULL; |
|
639 |
+ |
|
640 |
+ if (pkcs11_management_id_get (index, &id, &base64)) |
|
641 |
+ msg (M_CLIENT, ">PKCS11ID-ENTRY:'%d', ID:'%s', BLOB:'%s'", index, id, base64); |
|
642 |
+ else |
|
643 |
+ msg (M_CLIENT, ">PKCS11ID-ENTRY:'%d'", index); |
|
644 |
+ |
|
645 |
+ if (id != NULL) |
|
646 |
+ free (id); |
|
647 |
+ if (base64 != NULL) |
|
648 |
+ free (base64); |
|
649 |
+} |
|
650 |
+ |
|
651 |
+#endif |
|
652 |
+ |
|
626 | 653 |
static void |
627 | 654 |
man_hold (struct management *man, const char *cmd) |
628 | 655 |
{ |
... | ... |
@@ -807,6 +849,11 @@ man_dispatch_command (struct management *man, struct status_output *so, const ch |
807 | 807 |
if (man_need (man, p, 2, 0)) |
808 | 808 |
man_query_need_ok (man, p[1], p[2]); |
809 | 809 |
} |
810 |
+ else if (streq (p[0], "needstr")) |
|
811 |
+ { |
|
812 |
+ if (man_need (man, p, 2, 0)) |
|
813 |
+ man_query_need_str (man, p[1], p[2]); |
|
814 |
+ } |
|
810 | 815 |
else if (streq (p[0], "net")) |
811 | 816 |
{ |
812 | 817 |
man_net (man); |
... | ... |
@@ -820,6 +867,17 @@ man_dispatch_command (struct management *man, struct status_output *so, const ch |
820 | 820 |
if (man_need (man, p, 1, 0)) |
821 | 821 |
man_bytecount (man, atoi(p[1])); |
822 | 822 |
} |
823 |
+#ifdef ENABLE_PKCS11 |
|
824 |
+ else if (streq (p[0], "pkcs11-id-count")) |
|
825 |
+ { |
|
826 |
+ man_pkcs11_id_count (man); |
|
827 |
+ } |
|
828 |
+ else if (streq (p[0], "pkcs11-id-get")) |
|
829 |
+ { |
|
830 |
+ if (man_need (man, p, 1, 0)) |
|
831 |
+ man_pkcs11_id_get (man, atoi(p[1])); |
|
832 |
+ } |
|
833 |
+#endif |
|
823 | 834 |
#if 1 |
824 | 835 |
else if (streq (p[0], "test")) |
825 | 836 |
{ |
... | ... |
@@ -2037,6 +2095,12 @@ management_query_user_pass (struct management *man, |
2037 | 2037 |
prefix= "NEED-OK"; |
2038 | 2038 |
alert_type = "confirmation"; |
2039 | 2039 |
} |
2040 |
+ else if (flags & GET_USER_PASS_NEED_STR) |
|
2041 |
+ { |
|
2042 |
+ up_query_mode = UP_QUERY_NEED_STR; |
|
2043 |
+ prefix= "NEED-STR"; |
|
2044 |
+ alert_type = "string"; |
|
2045 |
+ } |
|
2040 | 2046 |
else if (flags & GET_USER_PASS_PASSWORD_ONLY) |
2041 | 2047 |
{ |
2042 | 2048 |
up_query_mode = UP_QUERY_PASS; |
... | ... |
@@ -2054,7 +2118,7 @@ management_query_user_pass (struct management *man, |
2054 | 2054 |
type, |
2055 | 2055 |
alert_type); |
2056 | 2056 |
|
2057 |
- if (flags & GET_USER_PASS_NEED_OK) |
|
2057 |
+ if (flags & (GET_USER_PASS_NEED_OK | GET_USER_PASS_NEED_STR)) |
|
2058 | 2058 |
buf_printf (&alert_msg, " MSG:%s", up->username); |
2059 | 2059 |
|
2060 | 2060 |
man_wait_for_client_connection (man, &signal_received, 0, MWCC_PASSWORD_WAIT); |
... | ... |
@@ -382,7 +382,7 @@ Command examples: |
382 | 382 |
Query for new input and retry. |
383 | 383 |
|
384 | 384 |
COMMAND -- needok (OpenVPN 2.1 or higher) |
385 |
+------------------------------------------ |
|
385 | 386 |
|
386 | 387 |
Confirm a ">NEED-OK" real-time notification, normally used by |
387 | 388 |
OpenVPN to block while waiting for a specific user action. |
... | ... |
@@ -403,6 +403,47 @@ Example: |
403 | 403 |
or |
404 | 404 |
needok token-insertion-request cancel |
405 | 405 |
|
406 |
+COMMAND -- needstr (OpenVPN 2.1 or higher) |
|
407 |
+------------------------------------------- |
|
408 |
+ |
|
409 |
+Confirm a ">NEED-STR" real-time notification, normally used by |
|
410 |
+OpenVPN to block while waiting for a specific user input. |
|
411 |
+ |
|
412 |
+Example: |
|
413 |
+ |
|
414 |
+ OpenVPN needs the user to specify some input, so it sends a |
|
415 |
+ real-time notification: |
|
416 |
+ |
|
417 |
+ >NEED-STR:Need 'name' input MSG:Please specify your name |
|
418 |
+ |
|
419 |
+ The management client, if it is a GUI, can flash a dialog |
|
420 |
+ box containing the text after the "MSG:" marker to the user. |
|
421 |
+ When the user acknowledges the dialog box, |
|
422 |
+ the management client can issue this command: |
|
423 |
+ |
|
424 |
+ needstr name "John" |
|
425 |
+ |
|
426 |
+COMMAND -- pkcs11-id-count (OpenVPN 2.1 or higher) |
|
427 |
+--------------------------------------------------- |
|
428 |
+ |
|
429 |
+Retrieve available number of certificates. |
|
430 |
+ |
|
431 |
+Example: |
|
432 |
+ |
|
433 |
+ pkcs11-id-count |
|
434 |
+ >PKCS11ID-COUNT:5 |
|
435 |
+ |
|
436 |
+COMMAND -- pkcs11-id-get (OpenVPN 2.1 or higher) |
|
437 |
+------------------------------------------------- |
|
438 |
+ |
|
439 |
+Retrieve certificate by index, the ID string should be provided |
|
440 |
+as PKCS#11 identity, the blob is BASE64 encoded certificate. |
|
441 |
+ |
|
442 |
+Example: |
|
443 |
+ |
|
444 |
+ pkcs11-id-get 1 |
|
445 |
+ PKCS11ID-ENTRY:'1', ID:'<snip>', BLOB:'<snip>' |
|
446 |
+ |
|
406 | 447 |
OUTPUT FORMAT |
407 | 448 |
------------- |
408 | 449 |
|
... | ... |
@@ -445,6 +486,10 @@ NEED-OK -- OpenVPN needs the end user to do something, such as |
445 | 445 |
insert a cryptographic token. The "needok" command can |
446 | 446 |
be used to tell OpenVPN to continue. |
447 | 447 |
|
448 |
+NEED-STR -- OpenVPN needs information from end, such as |
|
449 |
+ a certificate to use. The "needstr" command can |
|
450 |
+ be used to tell OpenVPN to continue. |
|
451 |
+ |
|
448 | 452 |
PASSWORD -- Used to tell the management client that OpenVPN |
449 | 453 |
needs a password, also to indicate password |
450 | 454 |
verification failure. |
... | ... |
@@ -460,11 +505,11 @@ as is used by the OpenVPN config file parser. |
460 | 460 |
|
461 | 461 |
Whitespace is a parameter separator. |
462 | 462 |
|
463 |
-Double quotation characters ("") can be used to enclose |
|
464 |
-parameters containing whitespace. |
|
463 |
+Double quotation or single quotation characters ("", '') can be used |
|
464 |
+to enclose parameters containing whitespace. |
|
465 | 465 |
|
466 | 466 |
Backslash-based shell escaping is performed, using the following |
467 |
-mappings: |
|
467 |
+mappings, when not in single quotations: |
|
468 | 468 |
|
469 | 469 |
\\ Maps to a single backslash character (\). |
470 | 470 |
\" Pass a literal doublequote character ("), don't |
... | ... |
@@ -22,12 +22,6 @@ |
22 | 22 |
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
23 | 23 |
*/ |
24 | 24 |
|
25 |
-#ifdef WIN32 |
|
26 |
-#include "config-win32.h" |
|
27 |
-#else |
|
28 |
-#include "config.h" |
|
29 |
-#endif |
|
30 |
- |
|
31 | 25 |
#include "syshead.h" |
32 | 26 |
|
33 | 27 |
#include "buffer.h" |
... | ... |
@@ -206,7 +200,7 @@ run_up_down (const char *command, |
206 | 206 |
ASSERT (arg); |
207 | 207 |
|
208 | 208 |
buf_printf (&cmd, |
209 |
- "%s %d %d %s %s %s", |
|
209 |
+ "\"%s\" %d %d %s %s %s", |
|
210 | 210 |
arg, |
211 | 211 |
tun_mtu, link_mtu, |
212 | 212 |
ifconfig_local, ifconfig_remote, |
... | ... |
@@ -225,7 +219,7 @@ run_up_down (const char *command, |
225 | 225 |
setenv_str (es, "script_type", script_type); |
226 | 226 |
|
227 | 227 |
buf_printf (&cmd, |
228 |
- "%s %s %d %d %s %s %s", |
|
228 |
+ "%s \"%s\" %d %d %s %s %s", |
|
229 | 229 |
command, |
230 | 230 |
arg, |
231 | 231 |
tun_mtu, link_mtu, |
... | ... |
@@ -438,6 +432,7 @@ openvpn_system (const char *command, const struct env_set *es, unsigned int flag |
438 | 438 |
void |
439 | 439 |
warn_if_group_others_accessible (const char* filename) |
440 | 440 |
{ |
441 |
+#ifndef WIN32 |
|
441 | 442 |
#ifdef HAVE_STAT |
442 | 443 |
#if ENABLE_INLINE_FILES |
443 | 444 |
if (strcmp (filename, INLINE_FILE_TAG)) |
... | ... |
@@ -455,6 +450,7 @@ warn_if_group_others_accessible (const char* filename) |
455 | 455 |
} |
456 | 456 |
} |
457 | 457 |
#endif |
458 |
+#endif |
|
458 | 459 |
} |
459 | 460 |
|
460 | 461 |
/* |
... | ... |
@@ -1230,7 +1226,7 @@ get_user_pass (struct user_pass *up, |
1230 | 1230 |
if ((flags & GET_USER_PASS_NOFATAL) != 0) |
1231 | 1231 |
return false; |
1232 | 1232 |
else |
1233 |
- msg (M_FATAL, "ERROR: could not read %s username/password/ok from management interface", prefix); |
|
1233 |
+ msg (M_FATAL, "ERROR: could not read %s username/password/ok/string from management interface", prefix); |
|
1234 | 1234 |
} |
1235 | 1235 |
} |
1236 | 1236 |
else |
... | ... |
@@ -227,7 +227,11 @@ struct user_pass |
227 | 227 |
bool nocache; |
228 | 228 |
|
229 | 229 |
/* max length of username/password */ |
230 |
-# define USER_PASS_LEN 128 |
|
230 |
+# ifdef ENABLE_PKCS11 |
|
231 |
+# define USER_PASS_LEN 4096 |
|
232 |
+# else |
|
233 |
+# define USER_PASS_LEN 128 |
|
234 |
+# endif |
|
231 | 235 |
char username[USER_PASS_LEN]; |
232 | 236 |
char password[USER_PASS_LEN]; |
233 | 237 |
}; |
... | ... |
@@ -242,6 +246,7 @@ bool get_console_input (const char *prompt, const bool echo, char *input, const |
242 | 242 |
#define GET_USER_PASS_PASSWORD_ONLY (1<<2) |
243 | 243 |
#define GET_USER_PASS_NEED_OK (1<<3) |
244 | 244 |
#define GET_USER_PASS_NOFATAL (1<<4) |
245 |
+#define GET_USER_PASS_NEED_STR (1<<5) |
|
245 | 246 |
|
246 | 247 |
bool get_user_pass (struct user_pass *up, |
247 | 248 |
const char *auth_file, |
... | ... |
@@ -3,6 +3,8 @@ |
3 | 3 |
* |
4 | 4 |
* Copyright (C) 2004 William Preston |
5 | 5 |
* |
6 |
+ * *NTLMv2 support and domain name parsing by Miroslav Zajic, Nextsoft s.r.o.* |
|
7 |
+ * |
|
6 | 8 |
* This program is free software; you can redistribute it and/or modify |
7 | 9 |
* it under the terms of the GNU General Public License as published by |
8 | 10 |
* the Free Software Foundation; either version 2 of the License, or |
... | ... |
@@ -19,12 +21,6 @@ |
19 | 19 |
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
20 | 20 |
*/ |
21 | 21 |
|
22 |
-#ifdef WIN32 |
|
23 |
-#include "config-win32.h" |
|
24 |
-#else |
|
25 |
-#include "config.h" |
|
26 |
-#endif |
|
27 |
- |
|
28 | 22 |
#include "syshead.h" |
29 | 23 |
|
30 | 24 |
#if NTLM |
... | ... |
@@ -41,6 +37,21 @@ |
41 | 41 |
|
42 | 42 |
#include "memdbg.h" |
43 | 43 |
|
44 |
+ |
|
45 |
+/* 64bit datatype macros */ |
|
46 |
+#ifdef _MSC_VER |
|
47 |
+ /* MS compilers */ |
|
48 |
+# define UINTEGER64 __int64 |
|
49 |
+# define UINT64(c) c ## Ui64 |
|
50 |
+#else |
|
51 |
+ /* Non MS compilers */ |
|
52 |
+# define UINTEGER64 unsigned long long |
|
53 |
+# define UINT64(c) c ## LL |
|
54 |
+#endif |
|
55 |
+ |
|
56 |
+ |
|
57 |
+ |
|
58 |
+ |
|
44 | 59 |
static void |
45 | 60 |
create_des_keys(const unsigned char *hash, unsigned char *key) |
46 | 61 |
{ |
... | ... |
@@ -70,6 +81,61 @@ gen_md4_hash (const char* data, int data_len, char *result) |
70 | 70 |
memcpy (result, md, 16); |
71 | 71 |
} |
72 | 72 |
|
73 |
+static void |
|
74 |
+gen_hmac_md5 (const char* data, int data_len, const char* key, int key_len,char *result) |
|
75 |
+{ |
|
76 |
+ unsigned int len; |
|
77 |
+ |
|
78 |
+ HMAC_CTX c; |
|
79 |
+ HMAC_Init (&c, key, key_len, EVP_md5()); |
|
80 |
+ HMAC_Update (&c, data, data_len); |
|
81 |
+ HMAC_Final (&c, result, &len); |
|
82 |
+ HMAC_CTX_cleanup(&c); |
|
83 |
+} |
|
84 |
+ |
|
85 |
+static void |
|
86 |
+gen_timestamp (unsigned char *timestamp) |
|
87 |
+{ |
|
88 |
+ /* Copies 8 bytes long timestamp into "timestamp" buffer. |
|
89 |
+ * Timestamp is Little-endian, 64-bit signed value representing the number of tenths of a microsecond since January 1, 1601. |
|
90 |
+ */ |
|
91 |
+ |
|
92 |
+ UINTEGER64 timestamp_ull; |
|
93 |
+ |
|
94 |
+ timestamp_ull = openvpn_time(NULL); |
|
95 |
+ timestamp_ull = (timestamp_ull + UINT64(11644473600)) * UINT64(10000000); |
|
96 |
+ |
|
97 |
+ /* store little endian value */ |
|
98 |
+ timestamp[0]= timestamp_ull & UINT64(0xFF); |
|
99 |
+ timestamp[1]= (timestamp_ull >> 8) & UINT64(0xFF); |
|
100 |
+ timestamp[2]= (timestamp_ull >> 16) & UINT64(0xFF); |
|
101 |
+ timestamp[3]= (timestamp_ull >> 24) & UINT64(0xFF); |
|
102 |
+ timestamp[4]= (timestamp_ull >> 32) & UINT64(0xFF); |
|
103 |
+ timestamp[5]= (timestamp_ull >> 40) & UINT64(0xFF); |
|
104 |
+ timestamp[6]= (timestamp_ull >> 48) & UINT64(0xFF); |
|
105 |
+ timestamp[7]= (timestamp_ull >> 56) & UINT64(0xFF); |
|
106 |
+} |
|
107 |
+ |
|
108 |
+static void |
|
109 |
+gen_nonce (unsigned char *nonce) |
|
110 |
+{ |
|
111 |
+ /* Generates 8 random bytes to be used as client nonce */ |
|
112 |
+ int i; |
|
113 |
+ |
|
114 |
+ for(i=0;i<8;i++){ |
|
115 |
+ nonce[i] = (unsigned char)get_random(); |
|
116 |
+ } |
|
117 |
+} |
|
118 |
+ |
|
119 |
+unsigned char *my_strupr(unsigned char *str) |
|
120 |
+{ |
|
121 |
+ /* converts string to uppercase in place */ |
|
122 |
+ unsigned char *tmp = str;; |
|
123 |
+ |
|
124 |
+ do *str = toupper(*str); while (*(++str)); |
|
125 |
+ return tmp; |
|
126 |
+} |
|
127 |
+ |
|
73 | 128 |
static int |
74 | 129 |
unicodize (char *dst, const char *src) |
75 | 130 |
{ |
... | ... |
@@ -85,6 +151,18 @@ unicodize (char *dst, const char *src) |
85 | 85 |
return i; |
86 | 86 |
} |
87 | 87 |
|
88 |
+static void |
|
89 |
+add_security_buffer(int sb_offset, void *data, int length, unsigned char *msg_buf, int *msg_bufpos) |
|
90 |
+{ |
|
91 |
+ /* Adds security buffer data to a message and sets security buffer's offset and length */ |
|
92 |
+ msg_buf[sb_offset] = (unsigned char)length; |
|
93 |
+ msg_buf[sb_offset + 2] = msg_buf[sb_offset]; |
|
94 |
+ msg_buf[sb_offset + 4] = (unsigned char)(*msg_bufpos & 0xff); |
|
95 |
+ msg_buf[sb_offset + 5] = (unsigned char)((*msg_bufpos >> 8) & 0xff); |
|
96 |
+ memcpy(&msg_buf[*msg_bufpos], data, msg_buf[sb_offset]); |
|
97 |
+ *msg_bufpos += length; |
|
98 |
+} |
|
99 |
+ |
|
88 | 100 |
const char * |
89 | 101 |
ntlm_phase_1 (const struct http_proxy_info *p, struct gc_arena *gc) |
90 | 102 |
{ |
... | ... |
@@ -105,23 +183,56 @@ ntlm_phase_1 (const struct http_proxy_info *p, struct gc_arena *gc) |
105 | 105 |
const char * |
106 | 106 |
ntlm_phase_3 (const struct http_proxy_info *p, const char *phase_2, struct gc_arena *gc) |
107 | 107 |
{ |
108 |
+ /* NTLM handshake |
|
109 |
+ * |
|
110 |
+ * http://davenport.sourceforge.net/ntlm.html |
|
111 |
+ * |
|
112 |
+ */ |
|
113 |
+ |
|
108 | 114 |
char pwbuf[sizeof (p->up.password) * 2]; /* for unicode password */ |
109 | 115 |
char buf2[128]; /* decoded reply from proxy */ |
110 |
- char phase3[146]; |
|
116 |
+ unsigned char phase3[464]; |
|
111 | 117 |
|
112 | 118 |
char md4_hash[21]; |
113 |
- char challenge[8], response[24]; |
|
114 |
- int i, ret_val, buflen; |
|
119 |
+ char challenge[8], ntlm_response[24]; |
|
120 |
+ int i, ret_val; |
|
115 | 121 |
des_cblock key1, key2, key3; |
116 | 122 |
des_key_schedule sched1, sched2, sched3; |
117 | 123 |
|
118 |
- /* try a minimal NTLM handshake |
|
119 |
- * |
|
120 |
- * http://davenport.sourceforge.net/ntlm.html |
|
121 |
- * |
|
122 |
- */ |
|
124 |
+ char ntlmv2_response[144]; |
|
125 |
+ char userdomain_u[256]; /* for uppercase unicode username and domain */ |
|
126 |
+ char userdomain[128]; /* the same as previous but ascii */ |
|
127 |
+ char ntlmv2_hash[16]; |
|
128 |
+ char ntlmv2_hmacmd5[16]; |
|
129 |
+ char *ntlmv2_blob = ntlmv2_response + 16; /* inside ntlmv2_response, length: 128 */ |
|
130 |
+ int ntlmv2_blob_size=0; |
|
131 |
+ int phase3_bufpos = 0x40; /* offset to next security buffer data to be added */ |
|
132 |
+ int len; |
|
133 |
+ |
|
134 |
+ char domain[128]; |
|
135 |
+ char username[128]; |
|
136 |
+ char *separator; |
|
137 |
+ |
|
138 |
+ bool ntlmv2_enabled = (p->auth_method == HTTP_AUTH_NTLM2); |
|
139 |
+ |
|
123 | 140 |
ASSERT (strlen (p->up.username) > 0); |
124 | 141 |
ASSERT (strlen (p->up.password) > 0); |
142 |
+ |
|
143 |
+ /* username parsing */ |
|
144 |
+ separator = strchr(p->up.username, '\\'); |
|
145 |
+ if (separator == NULL) { |
|
146 |
+ strncpy(username, p->up.username, sizeof(username)-1); |
|
147 |
+ username[sizeof(username)-1]=0; |
|
148 |
+ domain[0]=0; |
|
149 |
+ } else { |
|
150 |
+ strncpy(username, separator+1, sizeof(username)-1); |
|
151 |
+ username[sizeof(username)-1]=0; |
|
152 |
+ len = separator - p->up.username; |
|
153 |
+ if (len > sizeof(domain) - 1) len = sizeof(domain) - 1; |
|
154 |
+ strncpy(domain, p->up.username, len); |
|
155 |
+ domain[len]=0; |
|
156 |
+ } |
|
157 |
+ |
|
125 | 158 |
|
126 | 159 |
/* fill 1st 16 bytes with md4 hash, disregard terminating null */ |
127 | 160 |
gen_md4_hash (pwbuf, unicodize (pwbuf, p->up.password) - 2, md4_hash); |
... | ... |
@@ -139,48 +250,95 @@ ntlm_phase_3 (const struct http_proxy_info *p, const char *phase_2, struct gc_ar |
139 | 139 |
challenge[i] = buf2[i+24]; |
140 | 140 |
} |
141 | 141 |
|
142 |
- create_des_keys ((unsigned char *)md4_hash, key1); |
|
143 |
- des_set_key_unchecked ((des_cblock *)key1, sched1); |
|
144 |
- des_ecb_encrypt ((des_cblock *)challenge, (des_cblock *)response, sched1, DES_ENCRYPT); |
|
145 |
- |
|
146 |
- create_des_keys ((unsigned char *)&(md4_hash[7]), key2); |
|
147 |
- des_set_key_unchecked ((des_cblock *)key2, sched2); |
|
148 |
- des_ecb_encrypt ((des_cblock *)challenge, (des_cblock *)&(response[8]), sched2, DES_ENCRYPT); |
|
149 |
- |
|
150 |
- create_des_keys ((unsigned char *)&(md4_hash[14]), key3); |
|
151 |
- des_set_key_unchecked ((des_cblock *)key3, sched3); |
|
152 |
- des_ecb_encrypt ((des_cblock *)challenge, (des_cblock *)&(response[16]), sched3, DES_ENCRYPT); |
|
153 |
- |
|
154 |
- /* clear reply */ |
|
155 |
- memset (phase3, 0, sizeof (phase3)); |
|
156 |
- |
|
157 |
- strcpy (phase3, "NTLMSSP\0"); |
|
158 |
- phase3[8] = 3; /* type 3 */ |
|
159 |
- |
|
160 |
- buflen = 0x58 + strlen (p->up.username); |
|
161 |
- if (buflen > (int) sizeof (phase3)) |
|
162 |
- buflen = sizeof (phase3); |
|
163 |
- |
|
164 |
- phase3[0x10] = buflen; /* lm not used */ |
|
165 |
- phase3[0x20] = buflen; /* default domain (i.e. proxy's domain) */ |
|
166 |
- phase3[0x30] = buflen; /* no workstation name supplied */ |
|
167 |
- phase3[0x38] = buflen; /* no session key */ |
|
168 |
- |
|
169 |
- phase3[0x14] = 24; /* ntlm response is 24 bytes long */ |
|
170 |
- phase3[0x16] = phase3[0x14]; |
|
171 |
- phase3[0x18] = 0x40; /* ntlm offset */ |
|
172 |
- memcpy (&(phase3[0x40]), response, 24); |
|
173 |
- |
|
174 |
- |
|
175 |
- phase3[0x24] = strlen (p->up.username); /* username in ascii */ |
|
176 |
- phase3[0x26] = phase3[0x24]; |
|
177 |
- phase3[0x28] = 0x58; |
|
178 |
- strncpy (&(phase3[0x58]), p->up.username, sizeof (phase3) - 0x58); |
|
179 |
- |
|
142 |
+ if (ntlmv2_enabled){ /* Generate NTLMv2 response */ |
|
143 |
+ |
|
144 |
+ /* NTLMv2 hash */ |
|
145 |
+ my_strupr(strcpy(userdomain, username)); |
|
146 |
+ if (strlen(username) + strlen(domain) < sizeof(userdomain)) |
|
147 |
+ strcat(userdomain, domain); |
|
148 |
+ else |
|
149 |
+ msg (M_INFO, "Warning: Username or domain too long"); |
|
150 |
+ unicodize (userdomain_u, userdomain); |
|
151 |
+ gen_hmac_md5(userdomain_u, 2 * strlen(userdomain), md4_hash, 16, ntlmv2_hash); |
|
152 |
+ |
|
153 |
+ /* NTLMv2 Blob */ |
|
154 |
+ memset(ntlmv2_blob, 0, 128); /* Clear blob buffer */ |
|
155 |
+ ntlmv2_blob[0x00]=1; /* Signature */ |
|
156 |
+ ntlmv2_blob[0x01]=1; /* Signature */ |
|
157 |
+ ntlmv2_blob[0x04]=0; /* Reserved */ |
|
158 |
+ gen_timestamp(&ntlmv2_blob[0x08]); /* 64-bit Timestamp */ |
|
159 |
+ gen_nonce(&ntlmv2_blob[0x10]); /* 64-bit Client Nonce */ |
|
160 |
+ ntlmv2_blob[0x18]=0; /* Unknown, zero should work */ |
|
161 |
+ |
|
162 |
+ /* Add target information block to the blob */ |
|
163 |
+ int tib_len; |
|
164 |
+ if (( *((long *)&buf2[0x14]) & 0x00800000) == 0x00800000){ /* Check for Target Information block */ |
|
165 |
+ tib_len = buf2[0x28];/* Get Target Information block size */ |
|
166 |
+ if (tib_len > 96) tib_len = 96; |
|
167 |
+ char *tib_ptr = buf2 + buf2[0x2c]; /* Get Target Information block pointer */ |
|
168 |
+ memcpy(&ntlmv2_blob[0x1c], tib_ptr, tib_len); /* Copy Target Information block into the blob */ |
|
169 |
+ } else { |
|
170 |
+ tib_len = 0; |
|
171 |
+ } |
|
172 |
+ |
|
173 |
+ ntlmv2_blob[0x1c + tib_len] = 0; /* Unknown, zero works */ |
|
174 |
+ |
|
175 |
+ /* Get blob length */ |
|
176 |
+ ntlmv2_blob_size = 0x20 + tib_len; |
|
177 |
+ |
|
178 |
+ /* Add challenge from message 2 */ |
|
179 |
+ memcpy(&ntlmv2_response[8], challenge, 8); |
|
180 |
+ |
|
181 |
+ /* hmac-md5 */ |
|
182 |
+ gen_hmac_md5(&ntlmv2_response[8], ntlmv2_blob_size + 8, ntlmv2_hash, 16, ntlmv2_hmacmd5); |
|
183 |
+ |
|
184 |
+ /* Add hmac-md5 result to the blob */ |
|
185 |
+ memcpy(ntlmv2_response, ntlmv2_hmacmd5, 16); /* Note: This overwrites challenge previously written at ntlmv2_response[8..15] */ |
|
186 |
+ |
|
187 |
+ } else { /* Generate NTLM response */ |
|
188 |
+ |
|
189 |
+ create_des_keys ((unsigned char *)md4_hash, key1); |
|
190 |
+ des_set_key_unchecked ((des_cblock *)key1, sched1); |
|
191 |
+ des_ecb_encrypt ((des_cblock *)challenge, (des_cblock *)ntlm_response, sched1, DES_ENCRYPT); |
|
192 |
+ |
|
193 |
+ create_des_keys ((unsigned char *)&(md4_hash[7]), key2); |
|
194 |
+ des_set_key_unchecked ((des_cblock *)key2, sched2); |
|
195 |
+ des_ecb_encrypt ((des_cblock *)challenge, (des_cblock *)&(ntlm_response[8]), sched2, DES_ENCRYPT); |
|
196 |
+ |
|
197 |
+ create_des_keys ((unsigned char *)&(md4_hash[14]), key3); |
|
198 |
+ des_set_key_unchecked ((des_cblock *)key3, sched3); |
|
199 |
+ des_ecb_encrypt ((des_cblock *)challenge, (des_cblock *)&(ntlm_response[16]), sched3, DES_ENCRYPT); |
|
200 |
+ } |
|
201 |
+ |
|
202 |
+ |
|
203 |
+ memset (phase3, 0, sizeof (phase3)); /* clear reply */ |
|
204 |
+ |
|
205 |
+ strcpy (phase3, "NTLMSSP\0"); /* signature */ |
|
206 |
+ phase3[8] = 3; /* type 3 */ |
|
207 |
+ |
|
208 |
+ if (ntlmv2_enabled){ /* NTLMv2 response */ |
|
209 |
+ add_security_buffer(0x14, ntlmv2_response, ntlmv2_blob_size + 16, phase3, &phase3_bufpos); |
|
210 |
+ }else{ /* NTLM response */ |
|
211 |
+ add_security_buffer(0x14, ntlm_response, 24, phase3, &phase3_bufpos); |
|
212 |
+ } |
|
213 |
+ |
|
214 |
+ /* username in ascii */ |
|
215 |
+ add_security_buffer(0x24, username, strlen (username), phase3, &phase3_bufpos); |
|
216 |
+ |
|
217 |
+ /* Set domain. If <domain> is empty, default domain will be used (i.e. proxy's domain) */ |
|
218 |
+ add_security_buffer(0x1c, domain, strlen (domain), phase3, &phase3_bufpos); |
|
219 |
+ |
|
220 |
+ |
|
221 |
+ /* other security buffers will be empty */ |
|
222 |
+ phase3[0x10] = phase3_bufpos; /* lm not used */ |
|
223 |
+ phase3[0x30] = phase3_bufpos; /* no workstation name supplied */ |
|
224 |
+ phase3[0x38] = phase3_bufpos; /* no session key */ |
|
225 |
+ |
|
226 |
+ /* flags */ |
|
180 | 227 |
phase3[0x3c] = 0x02; /* negotiate oem */ |
181 | 228 |
phase3[0x3d] = 0x02; /* negotiate ntlm */ |
182 | 229 |
|
183 |
- return ((const char *)make_base64_string2 ((unsigned char *)phase3, buflen, gc)); |
|
230 |
+ return ((const char *)make_base64_string2 ((unsigned char *)phase3, phase3_bufpos, gc)); |
|
184 | 231 |
} |
185 | 232 |
|
186 | 233 |
#else |
... | ... |
@@ -213,6 +213,7 @@ openvpn \- secure IP tunnel daemon. |
213 | 213 |
[\ \fB\-\-ping\fR\ \fIn\fR\ ] |
214 | 214 |
[\ \fB\-\-pkcs11\-cert\-private\fR\ \fI[0|1]...\fR\ ] |
215 | 215 |
[\ \fB\-\-pkcs11\-id\fR\ \fIname\fR\ ] |
216 |
+[\ \fB\-\-pkcs11\-id\-management\fR\ ] |
|
216 | 217 |
[\ \fB\-\-pkcs11\-pin\-cache\fR\ \fIseconds\fR\ ] |
217 | 218 |
[\ \fB\-\-pkcs11\-private\-mode\fR\ \fImode...\fR\ ] |
218 | 219 |
[\ \fB\-\-pkcs11\-protected\-authentication\fR\ \fI[0|1]...\fR\ ] |
... | ... |
@@ -3691,6 +3692,13 @@ by the standalone |
3691 | 3691 |
option. |
3692 | 3692 |
.\"********************************************************* |
3693 | 3693 |
.TP |
3694 |
+.B --pkcs11-id-management |
|
3695 |
+Acquire PKCS#11 id from management interface. In this case a NEED-STR 'pkcs11-id-request' |
|
3696 |
+real-time message will be triggered, application may use pkcs11-id-count command to |
|
3697 |
+retrieve available number of certificates, and pkcs11-id-get command to retrieve certificate |
|
3698 |
+id and certificate body. |
|
3699 |
+.\"********************************************************* |
|
3700 |
+.TP |
|
3694 | 3701 |
.B --pkcs11-pin-cache seconds |
3695 | 3702 |
Specify how many seconds the PIN can be cached, the default is until the token is removed. |
3696 | 3703 |
.\"********************************************************* |
... | ... |
@@ -27,12 +27,6 @@ |
27 | 27 |
* (Christof Meerwald, http://cmeerw.org) |
28 | 28 |
*/ |
29 | 29 |
|
30 |
-#ifdef WIN32 |
|
31 |
-#include "config-win32.h" |
|
32 |
-#else |
|
33 |
-#include "config.h" |
|
34 |
-#endif |
|
35 |
- |
|
36 | 30 |
#include "syshead.h" |
37 | 31 |
|
38 | 32 |
#include "buffer.h" |
... | ... |
@@ -516,10 +510,11 @@ static const char usage_message[] = |
516 | 516 |
" 4 : Use Decrypt.\n" |
517 | 517 |
" 8 : Use Unwrap.\n" |
518 | 518 |
"--pkcs11-cert-private [0|1] ... : Set if login should be performed before\n" |
519 |
- " certificate can be accessed. Set for each provider.\n" |
|
520 |
- "--pkcs11-pin-cache seconds : Number of seconds to cache PIN. The default is -1\n" |
|
521 |
- " cache until token is removed.\n" |
|
522 |
- "--pkcs11-id serialized-id : Identity to use, get using standalone --show-pkcs11-ids\n" |
|
519 |
+ " certificate can be accessed. Set for each provider.\n" |
|
520 |
+ "--pkcs11-pin-cache seconds : Number of seconds to cache PIN. The default is -1\n" |
|
521 |
+ " cache until token is removed.\n" |
|
522 |
+ "--pkcs11-id-management : Acquire identity from management interface.\n" |
|
523 |
+ "--pkcs11-id serialized-id 'id' : Identity to use, get using standalone --show-pkcs11-ids\n" |
|
523 | 524 |
#endif /* ENABLE_PKCS11 */ |
524 | 525 |
"\n" |
525 | 526 |
"SSL Library information:\n" |
... | ... |
@@ -1293,6 +1288,7 @@ show_settings (const struct options *o) |
1293 | 1293 |
} |
1294 | 1294 |
SHOW_INT (pkcs11_pin_cache_period); |
1295 | 1295 |
SHOW_STR (pkcs11_id); |
1296 |
+ SHOW_BOOL (pkcs11_id_management); |
|
1296 | 1297 |
#endif /* ENABLE_PKCS11 */ |
1297 | 1298 |
|
1298 | 1299 |
#if P2MP |
... | ... |
@@ -1766,8 +1762,11 @@ options_postprocess (struct options *options, bool first_time) |
1766 | 1766 |
if (options->pkcs11_providers[0]) |
1767 | 1767 |
{ |
1768 | 1768 |
notnull (options->ca_file, "CA file (--ca)"); |
1769 |
- notnull (options->pkcs11_id, "PKCS#11 id (--pkcs11-id)"); |
|
1770 | 1769 |
|
1770 |
+ if (options->pkcs11_id_management && options->pkcs11_id != NULL) |
|
1771 |
+ msg(M_USAGE, "Parameter --pkcs11-id cannot be used when --pkcs11-id-management is also specified."); |
|
1772 |
+ if (!options->pkcs11_id_management && options->pkcs11_id == NULL) |
|
1773 |
+ msg(M_USAGE, "Parameter --pkcs11-id or --pkcs11-id-management should be specified."); |
|
1771 | 1774 |
if (options->cert_file) |
1772 | 1775 |
msg(M_USAGE, "Parameter --cert cannot be used when --pkcs11-provider is also specified."); |
1773 | 1776 |
if (options->priv_key_file) |
... | ... |
@@ -1870,6 +1869,7 @@ options_postprocess (struct options *options, bool first_time) |
1870 | 1870 |
MUST_BE_UNDEF (pkcs11_providers[0]); |
1871 | 1871 |
MUST_BE_UNDEF (pkcs11_private_mode[0]); |
1872 | 1872 |
MUST_BE_UNDEF (pkcs11_id); |
1873 |
+ MUST_BE_UNDEF (pkcs11_id_management); |
|
1873 | 1874 |
#endif |
1874 | 1875 |
|
1875 | 1876 |
if (pull) |
... | ... |
@@ -5137,6 +5137,11 @@ add_option (struct options *options, |
5137 | 5137 |
VERIFY_PERMISSION (OPT_P_GENERAL); |
5138 | 5138 |
options->pkcs11_id = p[1]; |
5139 | 5139 |
} |
5140 |
+ else if (streq (p[0], "pkcs11-id-management")) |
|
5141 |
+ { |
|
5142 |
+ VERIFY_PERMISSION (OPT_P_GENERAL); |
|
5143 |
+ options->pkcs11_id_management = true; |
|
5144 |
+ } |
|
5140 | 5145 |
#endif |
5141 | 5146 |
#ifdef TUNSETPERSIST |
5142 | 5147 |
else if (streq (p[0], "rmtun")) |
... | ... |
@@ -31,16 +31,10 @@ |
31 | 31 |
* to IPSec. |
32 | 32 |
*/ |
33 | 33 |
|
34 |
-#ifdef WIN32 |
|
35 |
-#include "config-win32.h" |
|
36 |
-#else |
|
37 |
-#include "config.h" |
|
38 |
-#endif |
|
34 |
+#include "syshead.h" |
|
39 | 35 |
|
40 | 36 |
#ifdef USE_CRYPTO |
41 | 37 |
|
42 |
-#include "syshead.h" |
|
43 |
- |
|
44 | 38 |
#include "packet_id.h" |
45 | 39 |
#include "misc.h" |
46 | 40 |
#include "integer.h" |
... | ... |
@@ -22,12 +22,6 @@ |
22 | 22 |
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
23 | 23 |
*/ |
24 | 24 |
|
25 |
-#if defined(WIN32) |
|
26 |
-#include "config-win32.h" |
|
27 |
-#else |
|
28 |
-#include "config.h" |
|
29 |
-#endif |
|
30 |
- |
|
31 | 25 |
#include "syshead.h" |
32 | 26 |
|
33 | 27 |
#if defined(ENABLE_PKCS11) |
... | ... |
@@ -37,6 +31,7 @@ |
37 | 37 |
#include "basic.h" |
38 | 38 |
#include "error.h" |
39 | 39 |
#include "manage.h" |
40 |
+#include "base64.h" |
|
40 | 41 |
#include "pkcs11.h" |
41 | 42 |
|
42 | 43 |
static |
... | ... |
@@ -168,7 +163,7 @@ _pkcs11_openvpn_token_prompt ( |
168 | 168 |
const pkcs11h_token_id_t token, |
169 | 169 |
const unsigned retry |
170 | 170 |
) { |
171 |
- static struct user_pass token_resp; |
|
171 |
+ struct user_pass token_resp; |
|
172 | 172 |
|
173 | 173 |
(void)global_data; |
174 | 174 |
(void)user_data; |
... | ... |
@@ -211,7 +206,7 @@ _pkcs11_openvpn_pin_prompt ( |
211 | 211 |
char * const pin, |
212 | 212 |
const size_t pin_max |
213 | 213 |
) { |
214 |
- static struct user_pass token_pass; |
|
214 |
+ struct user_pass token_pass; |
|
215 | 215 |
char prompt[1024]; |
216 | 216 |
|
217 | 217 |
(void)global_data; |
... | ... |
@@ -389,8 +384,224 @@ pkcs11_logout() { |
389 | 389 |
} |
390 | 390 |
|
391 | 391 |
int |
392 |
+pkcs11_management_id_count () { |
|
393 |
+ pkcs11h_certificate_id_list_t id_list = NULL; |
|
394 |
+ pkcs11h_certificate_id_list_t t = NULL; |
|
395 |
+ CK_RV rv = CKR_OK; |
|
396 |
+ int count = 0; |
|
397 |
+ |
|
398 |
+ dmsg ( |
|
399 |
+ D_PKCS11_DEBUG, |
|
400 |
+ "PKCS#11: pkcs11_management_id_count - entered" |
|
401 |
+ ); |
|
402 |
+ |
|
403 |
+ if ( |
|
404 |
+ (rv = pkcs11h_certificate_enumCertificateIds ( |
|
405 |
+ PKCS11H_ENUM_METHOD_CACHE_EXIST, |
|
406 |
+ NULL, |
|
407 |
+ PKCS11H_PROMPT_MASK_ALLOW_ALL, |
|
408 |
+ NULL, |
|
409 |
+ &id_list |
|
410 |
+ )) != CKR_OK |
|
411 |
+ ) { |
|
412 |
+ msg (M_WARN, "PKCS#11: Cannot get certificate list %ld-'%s'", rv, pkcs11h_getMessage (rv)); |
|
413 |
+ goto cleanup; |
|
414 |
+ } |
|
415 |
+ |
|
416 |
+ for (count = 0, t = id_list; t != NULL; t = t->next) { |
|
417 |
+ count++; |
|
418 |
+ } |
|
419 |
+ |
|
420 |
+cleanup: |
|
421 |
+ |
|
422 |
+ if (id_list != NULL) { |
|
423 |
+ pkcs11h_certificate_freeCertificateIdList (id_list); |
|
424 |
+ id_list = NULL; |
|
425 |
+ } |
|
426 |
+ |
|
427 |
+ dmsg ( |
|
428 |
+ D_PKCS11_DEBUG, |
|
429 |
+ "PKCS#11: pkcs11_management_id_count - return count=%d", |
|
430 |
+ count |
|
431 |
+ ); |
|
432 |
+ |
|
433 |
+ return count; |
|
434 |
+} |
|
435 |
+ |
|
436 |
+bool |
|
437 |
+pkcs11_management_id_get ( |
|
438 |
+ const int index, |
|
439 |
+ char ** id, |
|
440 |
+ char **base64 |
|
441 |
+) { |
|
442 |
+ pkcs11h_certificate_id_list_t id_list = NULL; |
|
443 |
+ pkcs11h_certificate_id_list_t entry = NULL; |
|
444 |
+ pkcs11h_certificate_id_t certificate_id = NULL; |
|
445 |
+ pkcs11h_certificate_t certificate = NULL; |
|
446 |
+ CK_RV rv = CKR_OK; |
|
447 |
+ char *certificate_blob = NULL; |
|
448 |
+ size_t certificate_blob_size = 0; |
|
449 |
+ size_t max; |
|
450 |
+ char *internal_id = NULL; |
|
451 |
+ char *internal_base64 = NULL; |
|
452 |
+ int count = 0; |
|
453 |
+ bool success = false; |
|
454 |
+ |
|
455 |
+ ASSERT (id!=NULL); |
|
456 |
+ ASSERT (base64!=NULL); |
|
457 |
+ |
|
458 |
+ dmsg ( |
|
459 |
+ D_PKCS11_DEBUG, |
|
460 |
+ "PKCS#11: pkcs11_management_id_get - entered index=%d", |
|
461 |
+ index |
|
462 |
+ ); |
|
463 |
+ |
|
464 |
+ *id = NULL; |
|
465 |
+ *base64 = NULL; |
|
466 |
+ |
|
467 |
+ if ( |
|
468 |
+ (rv = pkcs11h_certificate_enumCertificateIds ( |
|
469 |
+ PKCS11H_ENUM_METHOD_CACHE_EXIST, |
|
470 |
+ NULL, |
|
471 |
+ PKCS11H_PROMPT_MASK_ALLOW_ALL, |
|
472 |
+ NULL, |
|
473 |
+ &id_list |
|
474 |
+ )) != CKR_OK |
|
475 |
+ ) { |
|
476 |
+ msg (M_WARN, "PKCS#11: Cannot get certificate list %ld-'%s'", rv, pkcs11h_getMessage (rv)); |
|
477 |
+ goto cleanup; |
|
478 |
+ } |
|
479 |
+ |
|
480 |
+ entry = id_list; |
|
481 |
+ count = 0; |
|
482 |
+ while (entry != NULL && count != index) { |
|
483 |
+ count++; |
|
484 |
+ entry = entry->next; |
|
485 |
+ } |
|
486 |
+ |
|
487 |
+ if (entry == NULL) { |
|
488 |
+ dmsg ( |
|
489 |
+ D_PKCS11_DEBUG, |
|
490 |
+ "PKCS#11: pkcs11_management_id_get - no certificate at index=%d", |
|
491 |
+ index |
|
492 |
+ ); |
|
493 |
+ goto cleanup; |
|
494 |
+ } |
|
495 |
+ |
|
496 |
+ if ( |
|
497 |
+ (rv = pkcs11h_certificate_serializeCertificateId ( |
|
498 |
+ NULL, |
|
499 |
+ &max, |
|
500 |
+ entry->certificate_id |
|
501 |
+ )) != CKR_OK |
|
502 |
+ ) { |
|
503 |
+ msg (M_WARN, "PKCS#11: Cannot serialize certificate id %ld-'%s'", rv, pkcs11h_getMessage (rv)); |
|
504 |
+ goto cleanup; |
|
505 |
+ } |
|
506 |
+ |
|
507 |
+ if ((internal_id = (char *)malloc (max)) == NULL) { |
|
508 |
+ msg (M_FATAL, "PKCS#11: Cannot allocate memory"); |
|
509 |
+ goto cleanup; |
|
510 |
+ } |
|
511 |
+ |
|
512 |
+ if ( |
|
513 |
+ (rv = pkcs11h_certificate_serializeCertificateId ( |
|
514 |
+ internal_id, |
|
515 |
+ &max, |
|
516 |
+ entry->certificate_id |
|
517 |
+ )) != CKR_OK |
|
518 |
+ ) { |
|
519 |
+ msg (M_WARN, "PKCS#11: Cannot serialize certificate id %ld-'%s'", rv, pkcs11h_getMessage (rv)); |
|
520 |
+ goto cleanup; |
|
521 |
+ } |
|
522 |
+ |
|
523 |
+ if ( |
|
524 |
+ (rv = pkcs11h_certificate_create ( |
|
525 |
+ entry->certificate_id, |
|
526 |
+ NULL, |
|
527 |
+ PKCS11H_PROMPT_MASK_ALLOW_ALL, |
|
528 |
+ PKCS11H_PIN_CACHE_INFINITE, |
|
529 |
+ &certificate |
|
530 |
+ )) != CKR_OK |
|
531 |
+ ) { |
|
532 |
+ msg (M_WARN, "PKCS#11: Cannot get certificate %ld-'%s'", rv, pkcs11h_getMessage (rv)); |
|
533 |
+ goto cleanup; |
|
534 |
+ } |
|
535 |
+ |
|
536 |
+ if ( |
|
537 |
+ (rv = pkcs11h_certificate_getCertificateBlob ( |
|
538 |
+ certificate, |
|
539 |
+ NULL, |
|
540 |
+ &certificate_blob_size |
|
541 |
+ )) != CKR_OK |
|
542 |
+ ) { |
|
543 |
+ msg (M_WARN, "PKCS#11: Cannot get certificate blob %ld-'%s'", rv, pkcs11h_getMessage (rv)); |
|
544 |
+ goto cleanup; |
|
545 |
+ } |
|
546 |
+ |
|
547 |
+ if ((certificate_blob = (char *)malloc (certificate_blob_size)) == NULL) { |
|
548 |
+ msg (M_FATAL, "PKCS#11: Cannot allocate memory"); |
|
549 |
+ goto cleanup; |
|
550 |
+ } |
|
551 |
+ |
|
552 |
+ if ( |
|
553 |
+ (rv = pkcs11h_certificate_getCertificateBlob ( |
|
554 |
+ certificate, |
|
555 |
+ certificate_blob, |
|
556 |
+ &certificate_blob_size |
|
557 |
+ )) != CKR_OK |
|
558 |
+ ) { |
|
559 |
+ msg (M_WARN, "PKCS#11: Cannot get certificate blob %ld-'%s'", rv, pkcs11h_getMessage (rv)); |
|
560 |
+ goto cleanup; |
|
561 |
+ } |
|
562 |
+ |
|
563 |
+ if (base64_encode (certificate_blob, certificate_blob_size, &internal_base64) == -1) { |
|
564 |
+ msg (M_WARN, "PKCS#11: Cannot encode certificate"); |
|
565 |
+ goto cleanup; |
|
566 |
+ } |
|
567 |
+ |
|
568 |
+ *id = internal_id; |
|
569 |
+ internal_id = NULL; |
|
570 |
+ *base64 = internal_base64; |
|
571 |
+ internal_base64 = NULL; |
|
572 |
+ success = true; |
|
573 |
+ |
|
574 |
+cleanup: |
|
575 |
+ |
|
576 |
+ if (id_list != NULL) { |
|
577 |
+ pkcs11h_certificate_freeCertificateIdList (id_list); |
|
578 |
+ id_list = NULL; |
|
579 |
+ } |
|
580 |
+ |
|
581 |
+ if (internal_id != NULL) { |
|
582 |
+ free (internal_id); |
|
583 |
+ internal_id = NULL; |
|
584 |
+ } |
|
585 |
+ |
|
586 |
+ if (internal_base64 != NULL) { |
|
587 |
+ free (internal_base64); |
|
588 |
+ internal_base64 = NULL; |
|
589 |
+ } |
|
590 |
+ |
|
591 |
+ if (certificate_blob != NULL) { |
|
592 |
+ free (certificate_blob); |
|
593 |
+ certificate_blob = NULL; |
|
594 |
+ } |
|
595 |
+ |
|
596 |
+ dmsg ( |
|
597 |
+ D_PKCS11_DEBUG, |
|
598 |
+ "PKCS#11: pkcs11_management_id_get - return success=%d, id='%s'", |
|
599 |
+ success ? 1 : 0, |
|
600 |
+ *id |
|
601 |
+ ); |
|
602 |
+ |
|
603 |
+ return success; |
|
604 |
+} |
|
605 |
+ |
|
606 |
+int |
|
392 | 607 |
SSL_CTX_use_pkcs11 ( |
393 | 608 |
SSL_CTX * const ssl_ctx, |
609 |
+ bool pkcs11_id_management, |
|
394 | 610 |
const char * const pkcs11_id |
395 | 611 |
) { |
396 | 612 |
X509 *x509 = NULL; |
... | ... |
@@ -403,23 +614,60 @@ SSL_CTX_use_pkcs11 ( |
403 | 403 |
bool ok = false; |
404 | 404 |
|
405 | 405 |
ASSERT (ssl_ctx!=NULL); |
406 |
- ASSERT (pkcs11_id!=NULL); |
|
406 |
+ ASSERT (pkcs11_id_management || pkcs11_id!=NULL); |
|
407 | 407 |
|
408 | 408 |
dmsg ( |
409 | 409 |
D_PKCS11_DEBUG, |
410 |
- "PKCS#11: SSL_CTX_use_pkcs11 - entered - ssl_ctx=%p, pkcs11_id='%s'", |
|
410 |
+ "PKCS#11: SSL_CTX_use_pkcs11 - entered - ssl_ctx=%p, pkcs11_id_management=%d, pkcs11_id='%s'", |
|
411 | 411 |
(void *)ssl_ctx, |
412 |
+ pkcs11_id_management ? 1 : 0, |
|
412 | 413 |
pkcs11_id |
413 | 414 |
); |
414 | 415 |
|
415 |
- if ( |
|
416 |
- (rv = pkcs11h_certificate_deserializeCertificateId ( |
|
417 |
- &certificate_id, |
|
418 |
- pkcs11_id |
|
419 |
- )) != CKR_OK |
|
420 |
- ) { |
|
421 |
- msg (M_WARN, "PKCS#11: Cannot deserialize id %ld-'%s'", rv, pkcs11h_getMessage (rv)); |
|
422 |
- goto cleanup; |
|
416 |
+ if (pkcs11_id_management) { |
|
417 |
+ struct user_pass id_resp; |
|
418 |
+ |
|
419 |
+ CLEAR (id_resp); |
|
420 |
+ |
|
421 |
+ id_resp.defined = false; |
|
422 |
+ id_resp.nocache = true; |
|
423 |
+ openvpn_snprintf ( |
|
424 |
+ id_resp.username, |
|
425 |
+ sizeof (id_resp.username), |
|
426 |
+ "Please specify PKCS#11 id to use" |
|
427 |
+ ); |
|
428 |
+ |
|
429 |
+ if ( |
|
430 |
+ !get_user_pass ( |
|
431 |
+ &id_resp, |
|
432 |
+ NULL, |
|
433 |
+ "pkcs11-id-request", |
|
434 |
+ GET_USER_PASS_MANAGEMENT|GET_USER_PASS_NEED_STR|GET_USER_PASS_NOFATAL |
|
435 |
+ ) |
|
436 |
+ ) { |
|
437 |
+ goto cleanup; |
|
438 |
+ } |
|
439 |
+ |
|
440 |
+ if ( |
|
441 |
+ (rv = pkcs11h_certificate_deserializeCertificateId ( |
|
442 |
+ &certificate_id, |
|
443 |
+ id_resp.password |
|
444 |
+ )) != CKR_OK |
|
445 |
+ ) { |
|
446 |
+ msg (M_WARN, "PKCS#11: Cannot deserialize id %ld-'%s'", rv, pkcs11h_getMessage (rv)); |
|
447 |
+ goto cleanup; |
|
448 |
+ } |
|
449 |
+ } |
|
450 |
+ else { |
|
451 |
+ if ( |
|
452 |
+ (rv = pkcs11h_certificate_deserializeCertificateId ( |
|
453 |
+ &certificate_id, |
|
454 |
+ pkcs11_id |
|
455 |
+ )) != CKR_OK |
|
456 |
+ ) { |
|
457 |
+ msg (M_WARN, "PKCS#11: Cannot deserialize id %ld-'%s'", rv, pkcs11h_getMessage (rv)); |
|
458 |
+ goto cleanup; |
|
459 |
+ } |
|
423 | 460 |
} |
424 | 461 |
|
425 | 462 |
if ( |
... | ... |
@@ -53,8 +53,19 @@ int |
53 | 53 |
pkcs11_logout(); |
54 | 54 |
|
55 | 55 |
int |
56 |
+pkcs11_management_id_count (); |
|
57 |
+ |
|
58 |
+bool |
|
59 |
+pkcs11_management_id_get ( |
|
60 |
+ const int index, |
|
61 |
+ char ** id, |
|
62 |
+ char **base64 |
|
63 |
+); |
|
64 |
+ |
|
65 |
+int |
|
56 | 66 |
SSL_CTX_use_pkcs11 ( |
57 | 67 |
SSL_CTX * const ssl_ctx, |
68 |
+ bool pkcs11_id_management, |
|
58 | 69 |
const char * const pkcs11_id |
59 | 70 |
); |
60 | 71 |
|
... | ... |
@@ -22,12 +22,6 @@ |
22 | 22 |
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
23 | 23 |
*/ |
24 | 24 |
|
25 |
-#ifdef WIN32 |
|
26 |
-#include "config-win32.h" |
|
27 |
-#else |
|
28 |
-#include "config.h" |
|
29 |
-#endif |
|
30 |
- |
|
31 | 25 |
#include "syshead.h" |
32 | 26 |
|
33 | 27 |
#include "common.h" |
... | ... |
@@ -294,19 +288,21 @@ new_http_proxy (const struct http_proxy_options *o, |
294 | 294 |
p->auth_method = HTTP_AUTH_BASIC; |
295 | 295 |
else if (!strcmp (o->auth_method_string, "ntlm")) |
296 | 296 |
p->auth_method = HTTP_AUTH_NTLM; |
297 |
+ else if (!strcmp (o->auth_method_string, "ntlm2")) |
|
298 |
+ p->auth_method = HTTP_AUTH_NTLM2; |
|
297 | 299 |
else |
298 |
- msg (M_FATAL, "ERROR: unknown HTTP authentication method: '%s' -- only the 'none', 'basic', or 'ntlm' methods are currently supported", |
|
300 |
+ msg (M_FATAL, "ERROR: unknown HTTP authentication method: '%s' -- only the 'none', 'basic', 'ntlm', or 'ntlm2' methods are currently supported", |
|
299 | 301 |
o->auth_method_string); |
300 | 302 |
} |
301 | 303 |
|
302 |
- /* only basic and NTLM authentication supported so far */ |
|
303 |
- if (p->auth_method == HTTP_AUTH_BASIC || p->auth_method == HTTP_AUTH_NTLM) |
|
304 |
+ /* only basic and NTLM/NTLMv2 authentication supported so far */ |
|
305 |
+ if (p->auth_method == HTTP_AUTH_BASIC || p->auth_method == HTTP_AUTH_NTLM || p->auth_method == HTTP_AUTH_NTLM2) |
|
304 | 306 |
{ |
305 | 307 |
get_user_pass_http (p, true); |
306 | 308 |
} |
307 | 309 |
|
308 | 310 |
#if !NTLM |
309 |
- if (p->auth_method == HTTP_AUTH_NTLM) |
|
311 |
+ if (p->auth_method == HTTP_AUTH_NTLM || p->auth_method == HTTP_AUTH_NTLM2) |
|
310 | 312 |
msg (M_FATAL, "Sorry, this version of " PACKAGE_NAME " was built without NTLM Proxy support."); |
311 | 313 |
#endif |
312 | 314 |
|
... | ... |
@@ -374,6 +370,12 @@ establish_http_proxy_passthru (struct http_proxy_info *p, |
374 | 374 |
|
375 | 375 |
#if NTLM |
376 | 376 |
case HTTP_AUTH_NTLM: |
377 |
+ case HTTP_AUTH_NTLM2: |
|
378 |
+ /* keep-alive connection */ |
|
379 |
+ openvpn_snprintf (buf, sizeof(buf), "Proxy-Connection: Keep-Alive"); |
|
380 |
+ if (!send_line_crlf (sd, buf)) |
|
381 |
+ goto error; |
|
382 |
+ |
|
377 | 383 |
openvpn_snprintf (buf, sizeof(buf), "Proxy-Authorization: NTLM %s", |
378 | 384 |
ntlm_phase_1 (p, &gc)); |
379 | 385 |
msg (D_PROXY, "Attempting NTLM Proxy-Authorization phase 1"); |
... | ... |
@@ -411,7 +413,7 @@ establish_http_proxy_passthru (struct http_proxy_info *p, |
411 | 411 |
msg (D_PROXY, "Proxy requires authentication"); |
412 | 412 |
|
413 | 413 |
/* check for NTLM */ |
414 |
- if (p->auth_method == HTTP_AUTH_NTLM) |
|
414 |
+ if (p->auth_method == HTTP_AUTH_NTLM || p->auth_method == HTTP_AUTH_NTLM2) |
|
415 | 415 |
{ |
416 | 416 |
#if NTLM |
417 | 417 |
/* look for the phase 2 response */ |
... | ... |
@@ -456,6 +458,12 @@ establish_http_proxy_passthru (struct http_proxy_info *p, |
456 | 456 |
if (!send_line_crlf (sd, buf)) |
457 | 457 |
goto error; |
458 | 458 |
|
459 |
+ /* keep-alive connection */ |
|
460 |
+ openvpn_snprintf (buf, sizeof(buf), "Proxy-Connection: Keep-Alive"); |
|
461 |
+ if (!send_line_crlf (sd, buf)) |
|
462 |
+ goto error; |
|
463 |
+ |
|
464 |
+ |
|
459 | 465 |
/* send HOST etc, */ |
460 | 466 |
openvpn_sleep (1); |
461 | 467 |
openvpn_snprintf (buf, sizeof(buf), "Host: %s", host); |
... | ... |
@@ -27,16 +27,10 @@ |
27 | 27 |
* so that SSL/TLS can be run over UDP. |
28 | 28 |
*/ |
29 | 29 |
|
30 |
-#ifdef WIN32 |
|
31 |
-#include "config-win32.h" |
|
32 |
-#else |
|
33 |
-#include "config.h" |
|
34 |
-#endif |
|
30 |
+#include "syshead.h" |
|
35 | 31 |
|
36 | 32 |
#if defined(USE_CRYPTO) && defined(USE_SSL) |
37 | 33 |
|
38 |
-#include "syshead.h" |
|
39 |
- |
|
40 | 34 |
#include "buffer.h" |
41 | 35 |
#include "error.h" |
42 | 36 |
#include "common.h" |
... | ... |
@@ -26,12 +26,6 @@ |
26 | 26 |
* Support routines for adding/deleting network routes. |
27 | 27 |
*/ |
28 | 28 |
|
29 |
-#ifdef WIN32 |
|
30 |
-#include "config-win32.h" |
|
31 |
-#else |
|
32 |
-#include "config.h" |
|
33 |
-#endif |
|
34 |
- |
|
35 | 29 |
#include "syshead.h" |
36 | 30 |
|
37 | 31 |
#include "common.h" |
... | ... |
@@ -871,6 +865,23 @@ add_route (struct route *r, const struct tuntap *tt, unsigned int flags, const s |
871 | 871 |
msg (D_ROUTE, "%s", BSTR (&buf)); |
872 | 872 |
status = system_check (BSTR (&buf), es, 0, "ERROR: FreeBSD route add command failed"); |
873 | 873 |
|
874 |
+#elif defined(TARGET_DRAGONFLY) |
|
875 |
+ |
|
876 |
+ buf_printf (&buf, ROUTE_PATH " add"); |
|
877 |
+ |
|
878 |
+#if 0 |
|
879 |
+ if (r->metric_defined) |
|
880 |
+ buf_printf (&buf, " -rtt %d", r->metric); |
|
881 |
+#endif |
|
882 |
+ |
|
883 |
+ buf_printf (&buf, " -net %s %s %s", |
|
884 |
+ network, |
|
885 |
+ gateway, |
|
886 |
+ netmask); |
|
887 |
+ |
|
888 |
+ msg (D_ROUTE, "%s", BSTR (&buf)); |
|
889 |
+ status = system_check (BSTR (&buf), es, 0, "ERROR: DragonFly route add command failed"); |
|
890 |
+ |
|
874 | 891 |
#elif defined(TARGET_DARWIN) |
875 | 892 |
|
876 | 893 |
buf_printf (&buf, ROUTE_PATH " add"); |
... | ... |
@@ -1007,6 +1018,16 @@ delete_route (const struct route *r, const struct tuntap *tt, unsigned int flags |
1007 | 1007 |
msg (D_ROUTE, "%s", BSTR (&buf)); |
1008 | 1008 |
system_check (BSTR (&buf), es, 0, "ERROR: FreeBSD route delete command failed"); |
1009 | 1009 |
|
1010 |
+#elif defined(TARGET_DRAGONFLY) |
|
1011 |
+ |
|
1012 |
+ buf_printf (&buf, ROUTE_PATH " delete -net %s %s %s", |
|
1013 |
+ network, |
|
1014 |
+ gateway, |
|
1015 |
+ netmask); |
|
1016 |
+ |
|
1017 |
+ msg (D_ROUTE, "%s", BSTR (&buf)); |
|
1018 |
+ system_check (BSTR (&buf), es, 0, "ERROR: DragonFly route delete command failed"); |
|
1019 |
+ |
|
1010 | 1020 |
#elif defined(TARGET_DARWIN) |
1011 | 1021 |
|
1012 | 1022 |
buf_printf (&buf, ROUTE_PATH " delete -net %s %s %s", |
... | ... |
@@ -1462,7 +1483,7 @@ get_default_gateway (in_addr_t *gateway) |
1462 | 1462 |
return ret; |
1463 | 1463 |
} |
1464 | 1464 |
|
1465 |
-#elif defined(TARGET_FREEBSD) |
|
1465 |
+#elif defined(TARGET_FREEBSD)||defined(TARGET_DRAGONFLY) |
|
1466 | 1466 |
|
1467 | 1467 |
#include <sys/types.h> |
1468 | 1468 |
#include <sys/socket.h> |
0 | 8 |
deleted file mode 100755 |
... | ... |
@@ -1,25 +0,0 @@ |
1 |
-# This makefile builds the OpenVPN win32 service |
|
2 |
-# wrapper using the mingw environment. |
|
3 |
-# |
|
4 |
-# service.c and service.h should be generated by |
|
5 |
-# applying service.patch to the Platform |
|
6 |
-# SDK service sample. |
|
7 |
- |
|
8 |
-EXE = ${PRODUCT_UNIX_NAME}serv.exe |
|
9 |
- |
|
10 |
-HEADERS = service.h |
|
11 |
- |
|
12 |
-OBJS = openvpnserv.o service.o |
|
13 |
- |
|
14 |
-INCLUDE_DIRS = |
|
15 |
- |
|
16 |
-CC = gcc -g -O2 -Wall -Wno-unused-function -Wno-unused-variable -mno-cygwin |
|
17 |
- |
|
18 |
-all : ${OBJS} |
|
19 |
- ${CC} -o ${EXE} ${OBJS} |
|
20 |
- |
|
21 |
-clean : |
|
22 |
- rm -f ${OBJS} ${EXE} |
|
23 |
- |
|
24 |
-%.o : %.c ${HEADERS} |
|
25 |
- ${CC} ${INCLUDE_DIRS} -c $< -o $@ |
26 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,41 @@ |
0 |
+# |
|
1 |
+# OpenVPN -- An application to securely tunnel IP networks |
|
2 |
+# over a single UDP port, with support for SSL/TLS-based |
|
3 |
+# session authentication and key exchange, |
|
4 |
+# packet encryption, packet authentication, and |
|
5 |
+# packet compression. |
|
6 |
+# |
|
7 |
+# Copyright (C) 2002-2005 OpenVPN Solutions LLC <info@openvpn.net> |
|
8 |
+# |
|
9 |
+# This program is free software; you can redistribute it and/or modify |
|
10 |
+# it under the terms of the GNU General Public License version 2 |
|
11 |
+# as published by the Free Software Foundation. |
|
12 |
+# |
|
13 |
+# This program is distributed in the hope that it will be useful, |
|
14 |
+# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 |
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 |
+# GNU General Public License for more details. |
|
17 |
+# |
|
18 |
+# You should have received a copy of the GNU General Public License |
|
19 |
+# along with this program (see the file COPYING included with this |
|
20 |
+# distribution); if not, write to the Free Software Foundation, Inc., |
|
21 |
+# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
22 |
+# |
|
23 |
+ |
|
24 |
+MAINTAINERCLEANFILES = $(srcdir)/Makefile.in |
|
25 |
+ |
|
26 |
+if WIN32 |
|
27 |
+ |
|
28 |
+sbin_PROGRAMS = openvpnserv |
|
29 |
+ |
|
30 |
+openvpnserv_SOURCES = \ |
|
31 |
+ openvpnserv.c \ |
|
32 |
+ service.h service.c |
|
33 |
+ |
|
34 |
+else |
|
35 |
+ |
|
36 |
+dist_noinst_DATA = \ |
|
37 |
+ openvpnserv.c \ |
|
38 |
+ service.h service.c |
|
39 |
+ |
|
40 |
+endif |
... | ... |
@@ -33,6 +33,11 @@ |
33 | 33 |
* This code is designed to be built with the mingw compiler. |
34 | 34 |
*/ |
35 | 35 |
|
36 |
+#ifdef _MSC_VER |
|
37 |
+#include "config-win32.h" |
|
38 |
+#else |
|
39 |
+#include "config.h" |
|
40 |
+#endif |
|
36 | 41 |
#include <windows.h> |
37 | 42 |
#include <stdlib.h> |
38 | 43 |
#include <stdio.h> |
... | ... |
@@ -65,13 +70,13 @@ struct security_attributes |
65 | 65 |
* Control Manager which will cause an asynchronous call |
66 | 66 |
* of ServiceStop below. |
67 | 67 |
*/ |
68 |
-#define EXIT_EVENT_NAME PRODUCT_UNIX_NAME "_exit_1" |
|
68 |
+#define EXIT_EVENT_NAME PACKAGE "_exit_1" |
|
69 | 69 |
|
70 | 70 |
/* |
71 | 71 |
* Which registry key in HKLM should |
72 | 72 |
* we get config info from? |
73 | 73 |
*/ |
74 |
-#define REG_KEY "SOFTWARE\\" PRODUCT_NAME |
|
74 |
+#define REG_KEY "SOFTWARE\\" PACKAGE_NAME |
|
75 | 75 |
|
76 | 76 |
static HANDLE exit_event = NULL; |
77 | 77 |
|
... | ... |
@@ -398,7 +403,7 @@ VOID ServiceStart (DWORD dwArgc, LPTSTR *lpszArgv) |
398 | 398 |
mysnprintf (log_path, "%s\\%s", log_dir, log_file); |
399 | 399 |
|
400 | 400 |
/* construct command line */ |
401 |
- mysnprintf (command_line, PRODUCT_UNIX_NAME " --service %s 1 --config \"%s\"", |
|
401 |
+ mysnprintf (command_line, PACKAGE " --service %s 1 --config \"%s\"", |
|
402 | 402 |
EXIT_EVENT_NAME, |
403 | 403 |
find_obj.cFileName); |
404 | 404 |
|
... | ... |
@@ -406,7 +411,7 @@ VOID ServiceStart (DWORD dwArgc, LPTSTR *lpszArgv) |
406 | 406 |
be inherited. */ |
407 | 407 |
if (!init_security_attributes_allow_all (&sa)) |
408 | 408 |
{ |
409 |
- MSG (M_SYSERR, "InitializeSecurityDescriptor start_" PRODUCT_UNIX_NAME " failed"); |
|
409 |
+ MSG (M_SYSERR, "InitializeSecurityDescriptor start_" PACKAGE " failed"); |
|
410 | 410 |
goto finish; |
411 | 411 |
} |
412 | 412 |
|
413 | 413 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,693 @@ |
0 |
+/*--------------------------------------------------------------------------- |
|
1 |
+THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF |
|
2 |
+ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED |
|
3 |
+TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A |
|
4 |
+PARTICULAR PURPOSE. |
|
5 |
+ |
|
6 |
+Copyright (C) 1993 - 2000. Microsoft Corporation. All rights reserved. |
|
7 |
+ |
|
8 |
+MODULE: service.c |
|
9 |
+ |
|
10 |
+PURPOSE: Implements functions required by all Windows NT services |
|
11 |
+ |
|
12 |
+FUNCTIONS: |
|
13 |
+ main(int argc, char **argv); |
|
14 |
+ service_ctrl(DWORD dwCtrlCode); |
|
15 |
+ service_main(DWORD dwArgc, LPTSTR *lpszArgv); |
|
16 |
+ CmdInstallService(); |
|
17 |
+ CmdRemoveService(); |
|
18 |
+ CmdStartService(); |
|
19 |
+ CmdDebugService(int argc, char **argv); |
|
20 |
+ ControlHandler ( DWORD dwCtrlType ); |
|
21 |
+ GetLastErrorText( LPTSTR lpszBuf, DWORD dwSize ); |
|
22 |
+ |
|
23 |
+---------------------------------------------------------------------------*/ |
|
24 |
+ |
|
25 |
+#include <windows.h> |
|
26 |
+#include <stdio.h> |
|
27 |
+#include <stdlib.h> |
|
28 |
+#include <process.h> |
|
29 |
+#include <tchar.h> |
|
30 |
+ |
|
31 |
+#include "service.h" |
|
32 |
+ |
|
33 |
+// internal variables |
|
34 |
+SERVICE_STATUS ssStatus; // current status of the service |
|
35 |
+SERVICE_STATUS_HANDLE sshStatusHandle; |
|
36 |
+DWORD dwErr = 0; |
|
37 |
+BOOL bDebug = FALSE; |
|
38 |
+TCHAR szErr[256]; |
|
39 |
+ |
|
40 |
+// internal function prototypes |
|
41 |
+VOID WINAPI service_ctrl(DWORD dwCtrlCode); |
|
42 |
+VOID WINAPI service_main(DWORD dwArgc, LPTSTR *lpszArgv); |
|
43 |
+int CmdInstallService(); |
|
44 |
+int CmdRemoveService(); |
|
45 |
+int CmdStartService(); |
|
46 |
+VOID CmdDebugService(int argc, char **argv); |
|
47 |
+BOOL WINAPI ControlHandler ( DWORD dwCtrlType ); |
|
48 |
+LPTSTR GetLastErrorText( LPTSTR lpszBuf, DWORD dwSize ); |
|
49 |
+ |
|
50 |
+// |
|
51 |
+// FUNCTION: main |
|
52 |
+// |
|
53 |
+// PURPOSE: entrypoint for service |
|
54 |
+// |
|
55 |
+// PARAMETERS: |
|
56 |
+// argc - number of command line arguments |
|
57 |
+// argv - array of command line arguments |
|
58 |
+// |
|
59 |
+// RETURN VALUE: |
|
60 |
+// none |
|
61 |
+// |
|
62 |
+// COMMENTS: |
|
63 |
+// main() either performs the command line task, or |
|
64 |
+// call StartServiceCtrlDispatcher to register the |
|
65 |
+// main service thread. When the this call returns, |
|
66 |
+// the service has stopped, so exit. |
|
67 |
+// |
|
68 |
+int __cdecl main(int argc, char **argv) |
|
69 |
+{ |
|
70 |
+ SERVICE_TABLE_ENTRY dispatchTable[] = |
|
71 |
+ { |
|
72 |
+ { TEXT(SZSERVICENAME), (LPSERVICE_MAIN_FUNCTION)service_main}, |
|
73 |
+ { NULL, NULL} |
|
74 |
+ }; |
|
75 |
+ |
|
76 |
+ if ( (argc > 1) && |
|
77 |
+ ((*argv[1] == '-') || (*argv[1] == '/')) ) |
|
78 |
+ { |
|
79 |
+ if ( _stricmp( "install", argv[1]+1 ) == 0 ) |
|
80 |
+ { |
|
81 |
+ return CmdInstallService(); |
|
82 |
+ } |
|
83 |
+ else if ( _stricmp( "remove", argv[1]+1 ) == 0 ) |
|
84 |
+ { |
|
85 |
+ return CmdRemoveService(); |
|
86 |
+ } |
|
87 |
+ else if ( _stricmp( "start", argv[1]+1 ) == 0) |
|
88 |
+ { |
|
89 |
+ return CmdStartService(); |
|
90 |
+ } |
|
91 |
+ else if ( _stricmp( "debug", argv[1]+1 ) == 0 ) |
|
92 |
+ { |
|
93 |
+ bDebug = TRUE; |
|
94 |
+ CmdDebugService(argc, argv); |
|
95 |
+ } |
|
96 |
+ else |
|
97 |
+ { |
|
98 |
+ goto dispatch; |
|
99 |
+ } |
|
100 |
+ return 0; |
|
101 |
+ } |
|
102 |
+ |
|
103 |
+ // if it doesn't match any of the above parameters |
|
104 |
+ // the service control manager may be starting the service |
|
105 |
+ // so we must call StartServiceCtrlDispatcher |
|
106 |
+ dispatch: |
|
107 |
+ // this is just to be friendly |
|
108 |
+ printf( "%s -install to install the service\n", SZAPPNAME ); |
|
109 |
+ printf( "%s -start to start the service\n", SZAPPNAME ); |
|
110 |
+ printf( "%s -remove to remove the service\n", SZAPPNAME ); |
|
111 |
+ printf( "%s -debug <params> to run as a console app for debugging\n", SZAPPNAME ); |
|
112 |
+ printf( "\nStartServiceCtrlDispatcher being called.\n" ); |
|
113 |
+ printf( "This may take several seconds. Please wait.\n" ); |
|
114 |
+ |
|
115 |
+ if (!StartServiceCtrlDispatcher(dispatchTable)) |
|
116 |
+ AddToMessageLog(MSG_FLAGS_ERROR, TEXT("StartServiceCtrlDispatcher failed.")); |
|
117 |
+ |
|
118 |
+ return 0; |
|
119 |
+} |
|
120 |
+ |
|
121 |
+ |
|
122 |
+ |
|
123 |
+// |
|
124 |
+// FUNCTION: service_main |
|
125 |
+// |
|
126 |
+// PURPOSE: To perform actual initialization of the service |
|
127 |
+// |
|
128 |
+// PARAMETERS: |
|
129 |
+// dwArgc - number of command line arguments |
|
130 |
+// lpszArgv - array of command line arguments |
|
131 |
+// |
|
132 |
+// RETURN VALUE: |
|
133 |
+// none |
|
134 |
+// |
|
135 |
+// COMMENTS: |
|
136 |
+// This routine performs the service initialization and then calls |
|
137 |
+// the user defined ServiceStart() routine to perform majority |
|
138 |
+// of the work. |
|
139 |
+// |
|
140 |
+void WINAPI service_main(DWORD dwArgc, LPTSTR *lpszArgv) |
|
141 |
+{ |
|
142 |
+ |
|
143 |
+ // register our service control handler: |
|
144 |
+ // |
|
145 |
+ sshStatusHandle = RegisterServiceCtrlHandler( TEXT(SZSERVICENAME), service_ctrl); |
|
146 |
+ |
|
147 |
+ if (!sshStatusHandle) |
|
148 |
+ goto cleanup; |
|
149 |
+ |
|
150 |
+ // SERVICE_STATUS members that don't change in example |
|
151 |
+ // |
|
152 |
+ ssStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS; |
|
153 |
+ ssStatus.dwServiceSpecificExitCode = 0; |
|
154 |
+ |
|
155 |
+ |
|
156 |
+ // report the status to the service control manager. |
|
157 |
+ // |
|
158 |
+ if (!ReportStatusToSCMgr( |
|
159 |
+ SERVICE_START_PENDING, // service state |
|
160 |
+ NO_ERROR, // exit code |
|
161 |
+ 3000)) // wait hint |
|
162 |
+ goto cleanup; |
|
163 |
+ |
|
164 |
+ |
|
165 |
+ ServiceStart( dwArgc, lpszArgv ); |
|
166 |
+ |
|
167 |
+ cleanup: |
|
168 |
+ |
|
169 |
+ // try to report the stopped status to the service control manager. |
|
170 |
+ // |
|
171 |
+ if (sshStatusHandle) |
|
172 |
+ (VOID)ReportStatusToSCMgr( |
|
173 |
+ SERVICE_STOPPED, |
|
174 |
+ dwErr, |
|
175 |
+ 0); |
|
176 |
+ |
|
177 |
+ return; |
|
178 |
+} |
|
179 |
+ |
|
180 |
+ |
|
181 |
+ |
|
182 |
+// |
|
183 |
+// FUNCTION: service_ctrl |
|
184 |
+// |
|
185 |
+// PURPOSE: This function is called by the SCM whenever |
|
186 |
+// ControlService() is called on this service. |
|
187 |
+// |
|
188 |
+// PARAMETERS: |
|
189 |
+// dwCtrlCode - type of control requested |
|
190 |
+// |
|
191 |
+// RETURN VALUE: |
|
192 |
+// none |
|
193 |
+// |
|
194 |
+// COMMENTS: |
|
195 |
+// |
|
196 |
+VOID WINAPI service_ctrl(DWORD dwCtrlCode) |
|
197 |
+{ |
|
198 |
+ // Handle the requested control code. |
|
199 |
+ // |
|
200 |
+ switch (dwCtrlCode) |
|
201 |
+ { |
|
202 |
+ // Stop the service. |
|
203 |
+ // |
|
204 |
+ // SERVICE_STOP_PENDING should be reported before |
|
205 |
+ // setting the Stop Event - hServerStopEvent - in |
|
206 |
+ // ServiceStop(). This avoids a race condition |
|
207 |
+ // which may result in a 1053 - The Service did not respond... |
|
208 |
+ // error. |
|
209 |
+ case SERVICE_CONTROL_STOP: |
|
210 |
+ ReportStatusToSCMgr(SERVICE_STOP_PENDING, NO_ERROR, 0); |
|
211 |
+ ServiceStop(); |
|
212 |
+ return; |
|
213 |
+ |
|
214 |
+ // Update the service status. |
|
215 |
+ // |
|
216 |
+ case SERVICE_CONTROL_INTERROGATE: |
|
217 |
+ break; |
|
218 |
+ |
|
219 |
+ // invalid control code |
|
220 |
+ // |
|
221 |
+ default: |
|
222 |
+ break; |
|
223 |
+ |
|
224 |
+ } |
|
225 |
+ |
|
226 |
+ ReportStatusToSCMgr(ssStatus.dwCurrentState, NO_ERROR, 0); |
|
227 |
+} |
|
228 |
+ |
|
229 |
+ |
|
230 |
+ |
|
231 |
+// |
|
232 |
+// FUNCTION: ReportStatusToSCMgr() |
|
233 |
+// |
|
234 |
+// PURPOSE: Sets the current status of the service and |
|
235 |
+// reports it to the Service Control Manager |
|
236 |
+// |
|
237 |
+// PARAMETERS: |
|
238 |
+// dwCurrentState - the state of the service |
|
239 |
+// dwWin32ExitCode - error code to report |
|
240 |
+// dwWaitHint - worst case estimate to next checkpoint |
|
241 |
+// |
|
242 |
+// RETURN VALUE: |
|
243 |
+// TRUE - success |
|
244 |
+// FALSE - failure |
|
245 |
+// |
|
246 |
+// COMMENTS: |
|
247 |
+// |
|
248 |
+BOOL ReportStatusToSCMgr(DWORD dwCurrentState, |
|
249 |
+ DWORD dwWin32ExitCode, |
|
250 |
+ DWORD dwWaitHint) |
|
251 |
+{ |
|
252 |
+ static DWORD dwCheckPoint = 1; |
|
253 |
+ BOOL fResult = TRUE; |
|
254 |
+ |
|
255 |
+ |
|
256 |
+ if ( !bDebug ) // when debugging we don't report to the SCM |
|
257 |
+ { |
|
258 |
+ if (dwCurrentState == SERVICE_START_PENDING) |
|
259 |
+ ssStatus.dwControlsAccepted = 0; |
|
260 |
+ else |
|
261 |
+ ssStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP; |
|
262 |
+ |
|
263 |
+ ssStatus.dwCurrentState = dwCurrentState; |
|
264 |
+ ssStatus.dwWin32ExitCode = dwWin32ExitCode; |
|
265 |
+ ssStatus.dwWaitHint = dwWaitHint; |
|
266 |
+ |
|
267 |
+ if ( ( dwCurrentState == SERVICE_RUNNING ) || |
|
268 |
+ ( dwCurrentState == SERVICE_STOPPED ) ) |
|
269 |
+ ssStatus.dwCheckPoint = 0; |
|
270 |
+ else |
|
271 |
+ ssStatus.dwCheckPoint = dwCheckPoint++; |
|
272 |
+ |
|
273 |
+ |
|
274 |
+ // Report the status of the service to the service control manager. |
|
275 |
+ // |
|
276 |
+ if (!(fResult = SetServiceStatus( sshStatusHandle, &ssStatus))) |
|
277 |
+ { |
|
278 |
+ AddToMessageLog(MSG_FLAGS_ERROR, TEXT("SetServiceStatus")); |
|
279 |
+ } |
|
280 |
+ } |
|
281 |
+ return fResult; |
|
282 |
+} |
|
283 |
+ |
|
284 |
+ |
|
285 |
+ |
|
286 |
+// |
|
287 |
+// FUNCTION: AddToMessageLog(LPTSTR lpszMsg) |
|
288 |
+// |
|
289 |
+// PURPOSE: Allows any thread to log an error message |
|
290 |
+// |
|
291 |
+// PARAMETERS: |
|
292 |
+// lpszMsg - text for message |
|
293 |
+// |
|
294 |
+// RETURN VALUE: |
|
295 |
+// none |
|
296 |
+// |
|
297 |
+// COMMENTS: |
|
298 |
+// |
|
299 |
+void AddToMessageLog(DWORD flags, LPTSTR lpszMsg) |
|
300 |
+{ |
|
301 |
+ TCHAR szMsg [(sizeof(SZSERVICENAME) / sizeof(TCHAR)) + 100 ]; |
|
302 |
+ HANDLE hEventSource; |
|
303 |
+ LPCSTR lpszStrings[2]; |
|
304 |
+ |
|
305 |
+ if ( !bDebug ) |
|
306 |
+ { |
|
307 |
+ if (flags & MSG_FLAGS_SYS_CODE) |
|
308 |
+ dwErr = GetLastError(); |
|
309 |
+ else |
|
310 |
+ dwErr = 0; |
|
311 |
+ |
|
312 |
+ // Use event logging to log the error. |
|
313 |
+ // |
|
314 |
+ hEventSource = RegisterEventSource(NULL, TEXT(SZSERVICENAME)); |
|
315 |
+ |
|
316 |
+ _stprintf(szMsg, TEXT("%s error: %d"), TEXT(SZSERVICENAME), (int)dwErr); |
|
317 |
+ lpszStrings[0] = szMsg; |
|
318 |
+ lpszStrings[1] = lpszMsg; |
|
319 |
+ |
|
320 |
+ if (hEventSource != NULL) |
|
321 |
+ { |
|
322 |
+ ReportEvent(hEventSource, // handle of event source |
|
323 |
+ // event type |
|
324 |
+ (flags & MSG_FLAGS_ERROR) |
|
325 |
+ ? EVENTLOG_ERROR_TYPE : EVENTLOG_INFORMATION_TYPE, |
|
326 |
+ 0, // event category |
|
327 |
+ 0, // event ID |
|
328 |
+ NULL, // current user's SID |
|
329 |
+ 2, // strings in lpszStrings |
|
330 |
+ 0, // no bytes of raw data |
|
331 |
+ lpszStrings, // array of error strings |
|
332 |
+ NULL); // no raw data |
|
333 |
+ |
|
334 |
+ (VOID) DeregisterEventSource(hEventSource); |
|
335 |
+ } |
|
336 |
+ } |
|
337 |
+} |
|
338 |
+ |
|
339 |
+void ResetError (void) |
|
340 |
+{ |
|
341 |
+ dwErr = 0; |
|
342 |
+} |
|
343 |
+ |
|
344 |
+/////////////////////////////////////////////////////////////////// |
|
345 |
+// |
|
346 |
+// The following code handles service installation and removal |
|
347 |
+// |
|
348 |
+ |
|
349 |
+ |
|
350 |
+// |
|
351 |
+// FUNCTION: CmdInstallService() |
|
352 |
+// |
|
353 |
+// PURPOSE: Installs the service |
|
354 |
+// |
|
355 |
+// PARAMETERS: |
|
356 |
+// none |
|
357 |
+// |
|
358 |
+// RETURN VALUE: |
|
359 |
+// 0 if success |
|
360 |
+// |
|
361 |
+// COMMENTS: |
|
362 |
+// |
|
363 |
+int CmdInstallService() |
|
364 |
+{ |
|
365 |
+ SC_HANDLE schService; |
|
366 |
+ SC_HANDLE schSCManager; |
|
367 |
+ |
|
368 |
+ TCHAR szPath[512]; |
|
369 |
+ |
|
370 |
+ int ret = 0; |
|
371 |
+ |
|
372 |
+ if ( GetModuleFileName( NULL, szPath, 512 ) == 0 ) |
|
373 |
+ { |
|
374 |
+ _tprintf(TEXT("Unable to install %s - %s\n"), TEXT(SZSERVICEDISPLAYNAME), GetLastErrorText(szErr, 256)); |
|
375 |
+ return 1; |
|
376 |
+ } |
|
377 |
+ |
|
378 |
+ schSCManager = OpenSCManager( |
|
379 |
+ NULL, // machine (NULL == local) |
|
380 |
+ NULL, // database (NULL == default) |
|
381 |
+ SC_MANAGER_CONNECT | SC_MANAGER_CREATE_SERVICE // access required |
|
382 |
+ ); |
|
383 |
+ if ( schSCManager ) |
|
384 |
+ { |
|
385 |
+ schService = CreateService( |
|
386 |
+ schSCManager, // SCManager database |
|
387 |
+ TEXT(SZSERVICENAME), // name of service |
|
388 |
+ TEXT(SZSERVICEDISPLAYNAME), // name to display |
|
389 |
+ SERVICE_QUERY_STATUS, // desired access |
|
390 |
+ SERVICE_WIN32_OWN_PROCESS, // service type |
|
391 |
+ SERVICE_DEMAND_START, // start type -- alternative: SERVICE_AUTO_START |
|
392 |
+ SERVICE_ERROR_NORMAL, // error control type |
|
393 |
+ szPath, // service's binary |
|
394 |
+ NULL, // no load ordering group |
|
395 |
+ NULL, // no tag identifier |
|
396 |
+ TEXT(SZDEPENDENCIES), // dependencies |
|
397 |
+ NULL, // LocalSystem account |
|
398 |
+ NULL); // no password |
|
399 |
+ |
|
400 |
+ if ( schService ) |
|
401 |
+ { |
|
402 |
+ _tprintf(TEXT("%s installed.\n"), TEXT(SZSERVICEDISPLAYNAME) ); |
|
403 |
+ CloseServiceHandle(schService); |
|
404 |
+ } |
|
405 |
+ else |
|
406 |
+ { |
|
407 |
+ _tprintf(TEXT("CreateService failed - %s\n"), GetLastErrorText(szErr, 256)); |
|
408 |
+ ret = 1; |
|
409 |
+ } |
|
410 |
+ |
|
411 |
+ CloseServiceHandle(schSCManager); |
|
412 |
+ } |
|
413 |
+ else |
|
414 |
+ { |
|
415 |
+ _tprintf(TEXT("OpenSCManager failed - %s\n"), GetLastErrorText(szErr,256)); |
|
416 |
+ ret = 1; |
|
417 |
+ } |
|
418 |
+ return ret; |
|
419 |
+} |
|
420 |
+ |
|
421 |
+// |
|
422 |
+// FUNCTION: CmdStartService() |
|
423 |
+// |
|
424 |
+// PURPOSE: Start the service |
|
425 |
+// |
|
426 |
+// PARAMETERS: |
|
427 |
+// none |
|
428 |
+// |
|
429 |
+// RETURN VALUE: |
|
430 |
+// 0 if success |
|
431 |
+// |
|
432 |
+// COMMENTS: |
|
433 |
+ |
|
434 |
+int CmdStartService() |
|
435 |
+{ |
|
436 |
+ int ret = 0; |
|
437 |
+ |
|
438 |
+ SC_HANDLE schSCManager; |
|
439 |
+ SC_HANDLE schService; |
|
440 |
+ |
|
441 |
+ |
|
442 |
+ // Open a handle to the SC Manager database. |
|
443 |
+ schSCManager = OpenSCManager( |
|
444 |
+ NULL, // local machine |
|
445 |
+ NULL, // ServicesActive database |
|
446 |
+ SC_MANAGER_ALL_ACCESS); // full access rights |
|
447 |
+ |
|
448 |
+ if (NULL == schSCManager) { |
|
449 |
+ _tprintf(TEXT("OpenSCManager failed - %s\n"), GetLastErrorText(szErr,256)); |
|
450 |
+ ret = 1; |
|
451 |
+ } |
|
452 |
+ |
|
453 |
+ schService = OpenService( |
|
454 |
+ schSCManager, // SCM database |
|
455 |
+ SZSERVICENAME, // service name |
|
456 |
+ SERVICE_ALL_ACCESS); |
|
457 |
+ |
|
458 |
+ if (schService == NULL) { |
|
459 |
+ _tprintf(TEXT("OpenService failed - %s\n"), GetLastErrorText(szErr,256)); |
|
460 |
+ ret = 1; |
|
461 |
+ } |
|
462 |
+ |
|
463 |
+ if (!StartService( |
|
464 |
+ schService, // handle to service |
|
465 |
+ 0, // number of arguments |
|
466 |
+ NULL) ) // no arguments |
|
467 |
+ { |
|
468 |
+ _tprintf(TEXT("StartService failed - %s\n"), GetLastErrorText(szErr,256)); |
|
469 |
+ ret = 1; |
|
470 |
+ } |
|
471 |
+ else |
|
472 |
+ { |
|
473 |
+ _tprintf(TEXT("Service Started\n")); |
|
474 |
+ ret = 0; |
|
475 |
+ } |
|
476 |
+ CloseServiceHandle(schService); |
|
477 |
+ CloseServiceHandle(schSCManager); |
|
478 |
+ return ret; |
|
479 |
+} |
|
480 |
+ |
|
481 |
+// |
|
482 |
+// FUNCTION: CmdRemoveService() |
|
483 |
+// |
|
484 |
+// PURPOSE: Stops and removes the service |
|
485 |
+// |
|
486 |
+// PARAMETERS: |
|
487 |
+// none |
|
488 |
+// |
|
489 |
+// RETURN VALUE: |
|
490 |
+// 0 if success |
|
491 |
+// |
|
492 |
+// COMMENTS: |
|
493 |
+// |
|
494 |
+int CmdRemoveService() |
|
495 |
+{ |
|
496 |
+ SC_HANDLE schService; |
|
497 |
+ SC_HANDLE schSCManager; |
|
498 |
+ |
|
499 |
+ int ret = 0; |
|
500 |
+ |
|
501 |
+ schSCManager = OpenSCManager( |
|
502 |
+ NULL, // machine (NULL == local) |
|
503 |
+ NULL, // database (NULL == default) |
|
504 |
+ SC_MANAGER_CONNECT // access required |
|
505 |
+ ); |
|
506 |
+ if ( schSCManager ) |
|
507 |
+ { |
|
508 |
+ schService = OpenService(schSCManager, TEXT(SZSERVICENAME), DELETE | SERVICE_STOP | SERVICE_QUERY_STATUS); |
|
509 |
+ |
|
510 |
+ if (schService) |
|
511 |
+ { |
|
512 |
+ // try to stop the service |
|
513 |
+ if ( ControlService( schService, SERVICE_CONTROL_STOP, &ssStatus ) ) |
|
514 |
+ { |
|
515 |
+ _tprintf(TEXT("Stopping %s."), TEXT(SZSERVICEDISPLAYNAME)); |
|
516 |
+ Sleep( 1000 ); |
|
517 |
+ |
|
518 |
+ while ( QueryServiceStatus( schService, &ssStatus ) ) |
|
519 |
+ { |
|
520 |
+ if ( ssStatus.dwCurrentState == SERVICE_STOP_PENDING ) |
|
521 |
+ { |
|
522 |
+ _tprintf(TEXT(".")); |
|
523 |
+ Sleep( 1000 ); |
|
524 |
+ } |
|
525 |
+ else |
|
526 |
+ break; |
|
527 |
+ } |
|
528 |
+ |
|
529 |
+ if ( ssStatus.dwCurrentState == SERVICE_STOPPED ) |
|
530 |
+ _tprintf(TEXT("\n%s stopped.\n"), TEXT(SZSERVICEDISPLAYNAME) ); |
|
531 |
+ else |
|
532 |
+ { |
|
533 |
+ _tprintf(TEXT("\n%s failed to stop.\n"), TEXT(SZSERVICEDISPLAYNAME) ); |
|
534 |
+ ret = 1; |
|
535 |
+ } |
|
536 |
+ |
|
537 |
+ } |
|
538 |
+ |
|
539 |
+ // now remove the service |
|
540 |
+ if ( DeleteService(schService) ) |
|
541 |
+ _tprintf(TEXT("%s removed.\n"), TEXT(SZSERVICEDISPLAYNAME) ); |
|
542 |
+ else |
|
543 |
+ { |
|
544 |
+ _tprintf(TEXT("DeleteService failed - %s\n"), GetLastErrorText(szErr,256)); |
|
545 |
+ ret = 1; |
|
546 |
+ } |
|
547 |
+ |
|
548 |
+ |
|
549 |
+ CloseServiceHandle(schService); |
|
550 |
+ } |
|
551 |
+ else |
|
552 |
+ { |
|
553 |
+ _tprintf(TEXT("OpenService failed - %s\n"), GetLastErrorText(szErr,256)); |
|
554 |
+ ret = 1; |
|
555 |
+ } |
|
556 |
+ |
|
557 |
+ CloseServiceHandle(schSCManager); |
|
558 |
+ } |
|
559 |
+ else |
|
560 |
+ { |
|
561 |
+ _tprintf(TEXT("OpenSCManager failed - %s\n"), GetLastErrorText(szErr,256)); |
|
562 |
+ ret = 1; |
|
563 |
+ } |
|
564 |
+ return ret; |
|
565 |
+} |
|
566 |
+ |
|
567 |
+ |
|
568 |
+ |
|
569 |
+ |
|
570 |
+/////////////////////////////////////////////////////////////////// |
|
571 |
+// |
|
572 |
+// The following code is for running the service as a console app |
|
573 |
+// |
|
574 |
+ |
|
575 |
+ |
|
576 |
+// |
|
577 |
+// FUNCTION: CmdDebugService(int argc, char ** argv) |
|
578 |
+// |
|
579 |
+// PURPOSE: Runs the service as a console application |
|
580 |
+// |
|
581 |
+// PARAMETERS: |
|
582 |
+// argc - number of command line arguments |
|
583 |
+// argv - array of command line arguments |
|
584 |
+// |
|
585 |
+// RETURN VALUE: |
|
586 |
+// none |
|
587 |
+// |
|
588 |
+// COMMENTS: |
|
589 |
+// |
|
590 |
+void CmdDebugService(int argc, char ** argv) |
|
591 |
+{ |
|
592 |
+ DWORD dwArgc; |
|
593 |
+ LPTSTR *lpszArgv; |
|
594 |
+ |
|
595 |
+#ifdef UNICODE |
|
596 |
+ lpszArgv = CommandLineToArgvW(GetCommandLineW(), &(dwArgc) ); |
|
597 |
+ if (NULL == lpszArgv) |
|
598 |
+ { |
|
599 |
+ // CommandLineToArvW failed!! |
|
600 |
+ _tprintf(TEXT("CmdDebugService CommandLineToArgvW returned NULL\n")); |
|
601 |
+ return; |
|
602 |
+ } |
|
603 |
+#else |
|
604 |
+ dwArgc = (DWORD) argc; |
|
605 |
+ lpszArgv = argv; |
|
606 |
+#endif |
|
607 |
+ |
|
608 |
+ _tprintf(TEXT("Debugging %s.\n"), TEXT(SZSERVICEDISPLAYNAME)); |
|
609 |
+ |
|
610 |
+ SetConsoleCtrlHandler( ControlHandler, TRUE ); |
|
611 |
+ |
|
612 |
+ ServiceStart( dwArgc, lpszArgv ); |
|
613 |
+ |
|
614 |
+#ifdef UNICODE |
|
615 |
+// Must free memory allocated for arguments |
|
616 |
+ |
|
617 |
+ GlobalFree(lpszArgv); |
|
618 |
+#endif // UNICODE |
|
619 |
+ |
|
620 |
+} |
|
621 |
+ |
|
622 |
+ |
|
623 |
+// |
|
624 |
+// FUNCTION: ControlHandler ( DWORD dwCtrlType ) |
|
625 |
+// |
|
626 |
+// PURPOSE: Handled console control events |
|
627 |
+// |
|
628 |
+// PARAMETERS: |
|
629 |
+// dwCtrlType - type of control event |
|
630 |
+// |
|
631 |
+// RETURN VALUE: |
|
632 |
+// True - handled |
|
633 |
+// False - unhandled |
|
634 |
+// |
|
635 |
+// COMMENTS: |
|
636 |
+// |
|
637 |
+BOOL WINAPI ControlHandler ( DWORD dwCtrlType ) |
|
638 |
+{ |
|
639 |
+ switch ( dwCtrlType ) |
|
640 |
+ { |
|
641 |
+ case CTRL_BREAK_EVENT: // use Ctrl+C or Ctrl+Break to simulate |
|
642 |
+ case CTRL_C_EVENT: // SERVICE_CONTROL_STOP in debug mode |
|
643 |
+ _tprintf(TEXT("Stopping %s.\n"), TEXT(SZSERVICEDISPLAYNAME)); |
|
644 |
+ ServiceStop(); |
|
645 |
+ return TRUE; |
|
646 |
+ break; |
|
647 |
+ |
|
648 |
+ } |
|
649 |
+ return FALSE; |
|
650 |
+} |
|
651 |
+ |
|
652 |
+// |
|
653 |
+// FUNCTION: GetLastErrorText |
|
654 |
+// |
|
655 |
+// PURPOSE: copies error message text to string |
|
656 |
+// |
|
657 |
+// PARAMETERS: |
|
658 |
+// lpszBuf - destination buffer |
|
659 |
+// dwSize - size of buffer |
|
660 |
+// |
|
661 |
+// RETURN VALUE: |
|
662 |
+// destination buffer |
|
663 |
+// |
|
664 |
+// COMMENTS: |
|
665 |
+// |
|
666 |
+LPTSTR GetLastErrorText( LPTSTR lpszBuf, DWORD dwSize ) |
|
667 |
+{ |
|
668 |
+ DWORD dwRet; |
|
669 |
+ LPTSTR lpszTemp = NULL; |
|
670 |
+ |
|
671 |
+ dwRet = FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |FORMAT_MESSAGE_ARGUMENT_ARRAY, |
|
672 |
+ NULL, |
|
673 |
+ GetLastError(), |
|
674 |
+ LANG_NEUTRAL, |
|
675 |
+ (LPTSTR)&lpszTemp, |
|
676 |
+ 0, |
|
677 |
+ NULL ); |
|
678 |
+ |
|
679 |
+ // supplied buffer is not long enough |
|
680 |
+ if ( !dwRet || ( (long)dwSize < (long)dwRet+14 ) ) |
|
681 |
+ lpszBuf[0] = TEXT('\0'); |
|
682 |
+ else |
|
683 |
+ { |
|
684 |
+ lpszTemp[lstrlen(lpszTemp)-2] = TEXT('\0'); //remove cr and newline character |
|
685 |
+ _stprintf( lpszBuf, TEXT("%s (0x%x)"), lpszTemp, (int)GetLastError() ); |
|
686 |
+ } |
|
687 |
+ |
|
688 |
+ if ( lpszTemp ) |
|
689 |
+ LocalFree((HLOCAL) lpszTemp ); |
|
690 |
+ |
|
691 |
+ return lpszBuf; |
|
692 |
+} |
0 | 693 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,141 @@ |
0 |
+/*--------------------------------------------------------------------------- |
|
1 |
+THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF |
|
2 |
+ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED |
|
3 |
+TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A |
|
4 |
+PARTICULAR PURPOSE. |
|
5 |
+ |
|
6 |
+Copyright (C) 1993 - 2000. Microsoft Corporation. All rights reserved. |
|
7 |
+ |
|
8 |
+ MODULE: service.h |
|
9 |
+ |
|
10 |
+ Comments: The use of this header file and the accompanying service.c |
|
11 |
+ file simplifies the process of writting a service. You as a developer |
|
12 |
+ simply need to follow the TODO's outlined in this header file, and |
|
13 |
+ implement the ServiceStart() and ServiceStop() functions. |
|
14 |
+ |
|
15 |
+ There is no need to modify the code in service.c. Just add service.c |
|
16 |
+ to your project and link with the following libraries... |
|
17 |
+ |
|
18 |
+ libcmt.lib kernel32.lib advapi.lib shell32.lib |
|
19 |
+ |
|
20 |
+ This code also supports unicode. Be sure to compile both service.c and |
|
21 |
+ and code #include "service.h" with the same Unicode setting. |
|
22 |
+ |
|
23 |
+ Upon completion, your code will have the following command line interface |
|
24 |
+ |
|
25 |
+ <service exe> -? to display this list |
|
26 |
+ <service exe> -install to install the service |
|
27 |
+ <service exe> -remove to remove the service |
|
28 |
+ <service exe> -debug <params> to run as a console app for debugging |
|
29 |
+ |
|
30 |
+ Note: This code also implements Ctrl+C and Ctrl+Break handlers |
|
31 |
+ when using the debug option. These console events cause |
|
32 |
+ your ServiceStop routine to be called |
|
33 |
+ |
|
34 |
+ Also, this code only handles the OWN_SERVICE service type |
|
35 |
+ running in the LOCAL_SYSTEM security context. |
|
36 |
+ |
|
37 |
+ To control your service ( start, stop, etc ) you may use the |
|
38 |
+ Services control panel applet or the NET.EXE program. |
|
39 |
+ |
|
40 |
+ To aid in writing/debugging service, the |
|
41 |
+ SDK contains a utility (MSTOOLS\BIN\SC.EXE) that |
|
42 |
+ can be used to control, configure, or obtain service status. |
|
43 |
+ SC displays complete status for any service/driver |
|
44 |
+ in the service database, and allows any of the configuration |
|
45 |
+ parameters to be easily changed at the command line. |
|
46 |
+ For more information on SC.EXE, type SC at the command line. |
|
47 |
+ |
|
48 |
+ |
|
49 |
+------------------------------------------------------------------------------*/ |
|
50 |
+ |
|
51 |
+#ifndef _SERVICE_H |
|
52 |
+#define _SERVICE_H |
|
53 |
+ |
|
54 |
+ |
|
55 |
+#ifdef __cplusplus |
|
56 |
+extern "C" { |
|
57 |
+#endif |
|
58 |
+ |
|
59 |
+#include "config.h" |
|
60 |
+ |
|
61 |
+////////////////////////////////////////////////////////////////////////////// |
|
62 |
+//// todo: change to desired strings |
|
63 |
+//// |
|
64 |
+// name of the executable |
|
65 |
+#define SZAPPNAME PACKAGE "serv" |
|
66 |
+// internal name of the service |
|
67 |
+#define SZSERVICENAME PACKAGE_NAME "Service" |
|
68 |
+// displayed name of the service |
|
69 |
+#define SZSERVICEDISPLAYNAME PACKAGE_NAME " Service" |
|
70 |
+// list of service dependencies - "dep1\0dep2\0\0" |
|
71 |
+#define SZDEPENDENCIES TAP_ID "\0Dhcp\0\0" |
|
72 |
+////////////////////////////////////////////////////////////////////////////// |
|
73 |
+ |
|
74 |
+ |
|
75 |
+ |
|
76 |
+////////////////////////////////////////////////////////////////////////////// |
|
77 |
+//// todo: ServiceStart()must be defined by in your code. |
|
78 |
+//// The service should use ReportStatusToSCMgr to indicate |
|
79 |
+//// progress. This routine must also be used by StartService() |
|
80 |
+//// to report to the SCM when the service is running. |
|
81 |
+//// |
|
82 |
+//// If a ServiceStop procedure is going to take longer than |
|
83 |
+//// 3 seconds to execute, it should spawn a thread to |
|
84 |
+//// execute the stop code, and return. Otherwise, the |
|
85 |
+//// ServiceControlManager will believe that the service has |
|
86 |
+//// stopped responding |
|
87 |
+//// |
|
88 |
+ VOID ServiceStart(DWORD dwArgc, LPTSTR *lpszArgv); |
|
89 |
+ VOID ServiceStop(); |
|
90 |
+////////////////////////////////////////////////////////////////////////////// |
|
91 |
+ |
|
92 |
+ |
|
93 |
+ |
|
94 |
+////////////////////////////////////////////////////////////////////////////// |
|
95 |
+//// The following are procedures which |
|
96 |
+//// may be useful to call within the above procedures, |
|
97 |
+//// but require no implementation by the user. |
|
98 |
+//// They are implemented in service.c |
|
99 |
+ |
|
100 |
+// |
|
101 |
+// FUNCTION: ReportStatusToSCMgr() |
|
102 |
+// |
|
103 |
+// PURPOSE: Sets the current status of the service and |
|
104 |
+// reports it to the Service Control Manager |
|
105 |
+// |
|
106 |
+// PARAMETERS: |
|
107 |
+// dwCurrentState - the state of the service |
|
108 |
+// dwWin32ExitCode - error code to report |
|
109 |
+// dwWaitHint - worst case estimate to next checkpoint |
|
110 |
+// |
|
111 |
+// RETURN VALUE: |
|
112 |
+// TRUE - success |
|
113 |
+// FALSE - failure |
|
114 |
+// |
|
115 |
+ BOOL ReportStatusToSCMgr(DWORD dwCurrentState, DWORD dwWin32ExitCode, DWORD dwWaitHint); |
|
116 |
+ |
|
117 |
+ |
|
118 |
+// |
|
119 |
+// FUNCTION: AddToMessageLog(LPTSTR lpszMsg) |
|
120 |
+// |
|
121 |
+// PURPOSE: Allows any thread to log an error message |
|
122 |
+// |
|
123 |
+// PARAMETERS: |
|
124 |
+// lpszMsg - text for message |
|
125 |
+// |
|
126 |
+// RETURN VALUE: |
|
127 |
+// none |
|
128 |
+// |
|
129 |
+# define MSG_FLAGS_ERROR (1<<0) |
|
130 |
+# define MSG_FLAGS_SYS_CODE (1<<1) |
|
131 |
+ void AddToMessageLog(DWORD flags, LPTSTR lpszMsg); |
|
132 |
+ void ResetError (void); |
|
133 |
+////////////////////////////////////////////////////////////////////////////// |
|
134 |
+ |
|
135 |
+ |
|
136 |
+#ifdef __cplusplus |
|
137 |
+} |
|
138 |
+#endif |
|
139 |
+ |
|
140 |
+#endif |
0 | 141 |
deleted file mode 100755 |
... | ... |
@@ -1,359 +0,0 @@ |
1 |
-+++ service.c Tue Apr 24 12:20:08 2007 |
|
2 |
-@@ -16,6 +16,7 @@ |
|
3 |
- service_main(DWORD dwArgc, LPTSTR *lpszArgv); |
|
4 |
- CmdInstallService(); |
|
5 |
- CmdRemoveService(); |
|
6 |
-+ CmdStartService(); |
|
7 |
- CmdDebugService(int argc, char **argv); |
|
8 |
- ControlHandler ( DWORD dwCtrlType ); |
|
9 |
- GetLastErrorText( LPTSTR lpszBuf, DWORD dwSize ); |
|
10 |
-@@ -40,8 +41,9 @@ |
|
11 |
- // internal function prototypes |
|
12 |
- VOID WINAPI service_ctrl(DWORD dwCtrlCode); |
|
13 |
- VOID WINAPI service_main(DWORD dwArgc, LPTSTR *lpszArgv); |
|
14 |
--VOID CmdInstallService(); |
|
15 |
--VOID CmdRemoveService(); |
|
16 |
-+int CmdInstallService(); |
|
17 |
-+int CmdRemoveService(); |
|
18 |
-+int CmdStartService(); |
|
19 |
- VOID CmdDebugService(int argc, char **argv); |
|
20 |
- BOOL WINAPI ControlHandler ( DWORD dwCtrlType ); |
|
21 |
- LPTSTR GetLastErrorText( LPTSTR lpszBuf, DWORD dwSize ); |
|
22 |
-@@ -64,7 +66,7 @@ |
|
23 |
- // main service thread. When the this call returns, |
|
24 |
- // the service has stopped, so exit. |
|
25 |
- // |
|
26 |
--void __cdecl main(int argc, char **argv) |
|
27 |
-+int __cdecl main(int argc, char **argv) |
|
28 |
- { |
|
29 |
- SERVICE_TABLE_ENTRY dispatchTable[] = |
|
30 |
- { |
|
31 |
-@@ -77,11 +79,15 @@ |
|
32 |
- { |
|
33 |
- if ( _stricmp( "install", argv[1]+1 ) == 0 ) |
|
34 |
- { |
|
35 |
-- CmdInstallService(); |
|
36 |
-+ return CmdInstallService(); |
|
37 |
- } |
|
38 |
- else if ( _stricmp( "remove", argv[1]+1 ) == 0 ) |
|
39 |
- { |
|
40 |
-- CmdRemoveService(); |
|
41 |
-+ return CmdRemoveService(); |
|
42 |
-+ } |
|
43 |
-+ else if ( _stricmp( "start", argv[1]+1 ) == 0) |
|
44 |
-+ { |
|
45 |
-+ return CmdStartService(); |
|
46 |
- } |
|
47 |
- else if ( _stricmp( "debug", argv[1]+1 ) == 0 ) |
|
48 |
- { |
|
49 |
-@@ -92,7 +98,7 @@ |
|
50 |
- { |
|
51 |
- goto dispatch; |
|
52 |
- } |
|
53 |
-- exit(0); |
|
54 |
-+ return 0; |
|
55 |
- } |
|
56 |
- |
|
57 |
- // if it doesn't match any of the above parameters |
|
58 |
-@@ -101,13 +107,16 @@ |
|
59 |
- dispatch: |
|
60 |
- // this is just to be friendly |
|
61 |
- printf( "%s -install to install the service\n", SZAPPNAME ); |
|
62 |
-+ printf( "%s -start to start the service\n", SZAPPNAME ); |
|
63 |
- printf( "%s -remove to remove the service\n", SZAPPNAME ); |
|
64 |
- printf( "%s -debug <params> to run as a console app for debugging\n", SZAPPNAME ); |
|
65 |
- printf( "\nStartServiceCtrlDispatcher being called.\n" ); |
|
66 |
- printf( "This may take several seconds. Please wait.\n" ); |
|
67 |
- |
|
68 |
- if (!StartServiceCtrlDispatcher(dispatchTable)) |
|
69 |
-- AddToMessageLog(TEXT("StartServiceCtrlDispatcher failed.")); |
|
70 |
-+ AddToMessageLog(MSG_FLAGS_ERROR, TEXT("StartServiceCtrlDispatcher failed.")); |
|
71 |
-+ |
|
72 |
-+ return 0; |
|
73 |
- } |
|
74 |
- |
|
75 |
- |
|
76 |
-@@ -267,7 +276,7 @@ |
|
77 |
- // |
|
78 |
- if (!(fResult = SetServiceStatus( sshStatusHandle, &ssStatus))) |
|
79 |
- { |
|
80 |
-- AddToMessageLog(TEXT("SetServiceStatus")); |
|
81 |
-+ AddToMessageLog(MSG_FLAGS_ERROR, TEXT("SetServiceStatus")); |
|
82 |
- } |
|
83 |
- } |
|
84 |
- return fResult; |
|
85 |
-@@ -288,28 +297,33 @@ |
|
86 |
- // |
|
87 |
- // COMMENTS: |
|
88 |
- // |
|
89 |
--VOID AddToMessageLog(LPTSTR lpszMsg) |
|
90 |
-+void AddToMessageLog(DWORD flags, LPTSTR lpszMsg) |
|
91 |
- { |
|
92 |
- TCHAR szMsg [(sizeof(SZSERVICENAME) / sizeof(TCHAR)) + 100 ]; |
|
93 |
- HANDLE hEventSource; |
|
94 |
-- LPTSTR lpszStrings[2]; |
|
95 |
-+ LPCSTR lpszStrings[2]; |
|
96 |
- |
|
97 |
- if ( !bDebug ) |
|
98 |
- { |
|
99 |
-+ if (flags & MSG_FLAGS_SYS_CODE) |
|
100 |
- dwErr = GetLastError(); |
|
101 |
-+ else |
|
102 |
-+ dwErr = 0; |
|
103 |
- |
|
104 |
- // Use event logging to log the error. |
|
105 |
- // |
|
106 |
- hEventSource = RegisterEventSource(NULL, TEXT(SZSERVICENAME)); |
|
107 |
- |
|
108 |
-- _stprintf(szMsg, TEXT("%s error: %d"), TEXT(SZSERVICENAME), dwErr); |
|
109 |
-+ _stprintf(szMsg, TEXT("%s error: %d"), TEXT(SZSERVICENAME), (int)dwErr); |
|
110 |
- lpszStrings[0] = szMsg; |
|
111 |
- lpszStrings[1] = lpszMsg; |
|
112 |
- |
|
113 |
- if (hEventSource != NULL) |
|
114 |
- { |
|
115 |
- ReportEvent(hEventSource, // handle of event source |
|
116 |
-- EVENTLOG_ERROR_TYPE, // event type |
|
117 |
-+ // event type |
|
118 |
-+ (flags & MSG_FLAGS_ERROR) |
|
119 |
-+ ? EVENTLOG_ERROR_TYPE : EVENTLOG_INFORMATION_TYPE, |
|
120 |
- 0, // event category |
|
121 |
- 0, // event ID |
|
122 |
- NULL, // current user's SID |
|
123 |
-@@ -323,8 +337,10 @@ |
|
124 |
- } |
|
125 |
- } |
|
126 |
- |
|
127 |
-- |
|
128 |
-- |
|
129 |
-+void ResetError (void) |
|
130 |
-+{ |
|
131 |
-+ dwErr = 0; |
|
132 |
-+} |
|
133 |
- |
|
134 |
- /////////////////////////////////////////////////////////////////// |
|
135 |
- // |
|
136 |
-@@ -341,21 +357,23 @@ |
|
137 |
- // none |
|
138 |
- // |
|
139 |
- // RETURN VALUE: |
|
140 |
--// none |
|
141 |
-+// 0 if success |
|
142 |
- // |
|
143 |
- // COMMENTS: |
|
144 |
- // |
|
145 |
--void CmdInstallService() |
|
146 |
-+int CmdInstallService() |
|
147 |
- { |
|
148 |
- SC_HANDLE schService; |
|
149 |
- SC_HANDLE schSCManager; |
|
150 |
- |
|
151 |
- TCHAR szPath[512]; |
|
152 |
- |
|
153 |
-+ int ret = 0; |
|
154 |
-+ |
|
155 |
- if ( GetModuleFileName( NULL, szPath, 512 ) == 0 ) |
|
156 |
- { |
|
157 |
- _tprintf(TEXT("Unable to install %s - %s\n"), TEXT(SZSERVICEDISPLAYNAME), GetLastErrorText(szErr, 256)); |
|
158 |
-- return; |
|
159 |
-+ return 1; |
|
160 |
- } |
|
161 |
- |
|
162 |
- schSCManager = OpenSCManager( |
|
163 |
-@@ -371,7 +389,7 @@ |
|
164 |
- TEXT(SZSERVICEDISPLAYNAME), // name to display |
|
165 |
- SERVICE_QUERY_STATUS, // desired access |
|
166 |
- SERVICE_WIN32_OWN_PROCESS, // service type |
|
167 |
-- SERVICE_DEMAND_START, // start type |
|
168 |
-+ SERVICE_DEMAND_START, // start type -- alternative: SERVICE_AUTO_START |
|
169 |
- SERVICE_ERROR_NORMAL, // error control type |
|
170 |
- szPath, // service's binary |
|
171 |
- NULL, // no load ordering group |
|
172 |
-@@ -388,16 +406,79 @@ |
|
173 |
- else |
|
174 |
- { |
|
175 |
- _tprintf(TEXT("CreateService failed - %s\n"), GetLastErrorText(szErr, 256)); |
|
176 |
-+ ret = 1; |
|
177 |
- } |
|
178 |
- |
|
179 |
- CloseServiceHandle(schSCManager); |
|
180 |
- } |
|
181 |
- else |
|
182 |
-+ { |
|
183 |
- _tprintf(TEXT("OpenSCManager failed - %s\n"), GetLastErrorText(szErr,256)); |
|
184 |
-+ ret = 1; |
|
185 |
-+ } |
|
186 |
-+ return ret; |
|
187 |
- } |
|
188 |
- |
|
189 |
-+// |
|
190 |
-+// FUNCTION: CmdStartService() |
|
191 |
-+// |
|
192 |
-+// PURPOSE: Start the service |
|
193 |
-+// |
|
194 |
-+// PARAMETERS: |
|
195 |
-+// none |
|
196 |
-+// |
|
197 |
-+// RETURN VALUE: |
|
198 |
-+// 0 if success |
|
199 |
-+// |
|
200 |
-+// COMMENTS: |
|
201 |
-+ |
|
202 |
-+int CmdStartService() |
|
203 |
-+{ |
|
204 |
-+ int ret = 0; |
|
205 |
-+ |
|
206 |
-+ SC_HANDLE schSCManager; |
|
207 |
-+ SC_HANDLE schService; |
|
208 |
- |
|
209 |
- |
|
210 |
-+ // Open a handle to the SC Manager database. |
|
211 |
-+ schSCManager = OpenSCManager( |
|
212 |
-+ NULL, // local machine |
|
213 |
-+ NULL, // ServicesActive database |
|
214 |
-+ SC_MANAGER_ALL_ACCESS); // full access rights |
|
215 |
-+ |
|
216 |
-+ if (NULL == schSCManager) { |
|
217 |
-+ _tprintf(TEXT("OpenSCManager failed - %s\n"), GetLastErrorText(szErr,256)); |
|
218 |
-+ ret = 1; |
|
219 |
-+ } |
|
220 |
-+ |
|
221 |
-+ schService = OpenService( |
|
222 |
-+ schSCManager, // SCM database |
|
223 |
-+ SZSERVICENAME, // service name |
|
224 |
-+ SERVICE_ALL_ACCESS); |
|
225 |
-+ |
|
226 |
-+ if (schService == NULL) { |
|
227 |
-+ _tprintf(TEXT("OpenService failed - %s\n"), GetLastErrorText(szErr,256)); |
|
228 |
-+ ret = 1; |
|
229 |
-+ } |
|
230 |
-+ |
|
231 |
-+ if (!StartService( |
|
232 |
-+ schService, // handle to service |
|
233 |
-+ 0, // number of arguments |
|
234 |
-+ NULL) ) // no arguments |
|
235 |
-+ { |
|
236 |
-+ _tprintf(TEXT("StartService failed - %s\n"), GetLastErrorText(szErr,256)); |
|
237 |
-+ ret = 1; |
|
238 |
-+ } |
|
239 |
-+ else |
|
240 |
-+ { |
|
241 |
-+ _tprintf(TEXT("Service Started\n")); |
|
242 |
-+ ret = 0; |
|
243 |
-+ } |
|
244 |
-+ CloseServiceHandle(schService); |
|
245 |
-+ CloseServiceHandle(schSCManager); |
|
246 |
-+ return ret; |
|
247 |
-+} |
|
248 |
-+ |
|
249 |
- // |
|
250 |
- // FUNCTION: CmdRemoveService() |
|
251 |
- // |
|
252 |
-@@ -407,15 +488,17 @@ |
|
253 |
- // none |
|
254 |
- // |
|
255 |
- // RETURN VALUE: |
|
256 |
--// none |
|
257 |
-+// 0 if success |
|
258 |
- // |
|
259 |
- // COMMENTS: |
|
260 |
- // |
|
261 |
--void CmdRemoveService() |
|
262 |
-+int CmdRemoveService() |
|
263 |
- { |
|
264 |
- SC_HANDLE schService; |
|
265 |
- SC_HANDLE schSCManager; |
|
266 |
- |
|
267 |
-+ int ret = 0; |
|
268 |
-+ |
|
269 |
- schSCManager = OpenSCManager( |
|
270 |
- NULL, // machine (NULL == local) |
|
271 |
- NULL, // database (NULL == default) |
|
272 |
-@@ -447,7 +530,10 @@ |
|
273 |
- if ( ssStatus.dwCurrentState == SERVICE_STOPPED ) |
|
274 |
- _tprintf(TEXT("\n%s stopped.\n"), TEXT(SZSERVICEDISPLAYNAME) ); |
|
275 |
- else |
|
276 |
-+ { |
|
277 |
- _tprintf(TEXT("\n%s failed to stop.\n"), TEXT(SZSERVICEDISPLAYNAME) ); |
|
278 |
-+ ret = 1; |
|
279 |
-+ } |
|
280 |
- |
|
281 |
- } |
|
282 |
- |
|
283 |
-@@ -455,18 +541,28 @@ |
|
284 |
- if ( DeleteService(schService) ) |
|
285 |
- _tprintf(TEXT("%s removed.\n"), TEXT(SZSERVICEDISPLAYNAME) ); |
|
286 |
- else |
|
287 |
-+ { |
|
288 |
- _tprintf(TEXT("DeleteService failed - %s\n"), GetLastErrorText(szErr,256)); |
|
289 |
-+ ret = 1; |
|
290 |
-+ } |
|
291 |
- |
|
292 |
- |
|
293 |
- CloseServiceHandle(schService); |
|
294 |
- } |
|
295 |
- else |
|
296 |
-+ { |
|
297 |
- _tprintf(TEXT("OpenService failed - %s\n"), GetLastErrorText(szErr,256)); |
|
298 |
-+ ret = 1; |
|
299 |
-+ } |
|
300 |
- |
|
301 |
- CloseServiceHandle(schSCManager); |
|
302 |
- } |
|
303 |
- else |
|
304 |
-+ { |
|
305 |
- _tprintf(TEXT("OpenSCManager failed - %s\n"), GetLastErrorText(szErr,256)); |
|
306 |
-+ ret = 1; |
|
307 |
-+ } |
|
308 |
-+ return ret; |
|
309 |
- } |
|
310 |
- |
|
311 |
- |
|
312 |
-@@ -587,7 +683,7 @@ |
|
313 |
- else |
|
314 |
- { |
|
315 |
- lpszTemp[lstrlen(lpszTemp)-2] = TEXT('\0'); //remove cr and newline character |
|
316 |
-- _stprintf( lpszBuf, TEXT("%s (0x%x)"), lpszTemp, GetLastError() ); |
|
317 |
-+ _stprintf( lpszBuf, TEXT("%s (0x%x)"), lpszTemp, (int)GetLastError() ); |
|
318 |
- } |
|
319 |
- |
|
320 |
- if ( lpszTemp ) |
|
321 |
-+++ service.h Tue Apr 24 11:58:48 2007 |
|
322 |
-@@ -57,18 +57,19 @@ |
|
323 |
- extern "C" { |
|
324 |
- #endif |
|
325 |
- |
|
326 |
-+#include "../autodefs/defs.h" |
|
327 |
- |
|
328 |
- ////////////////////////////////////////////////////////////////////////////// |
|
329 |
- //// todo: change to desired strings |
|
330 |
- //// |
|
331 |
- // name of the executable |
|
332 |
--#define SZAPPNAME "Simple" |
|
333 |
-+#define SZAPPNAME PRODUCT_UNIX_NAME "serv" |
|
334 |
- // internal name of the service |
|
335 |
--#define SZSERVICENAME "SimpleService" |
|
336 |
-+#define SZSERVICENAME PRODUCT_NAME "Service" |
|
337 |
- // displayed name of the service |
|
338 |
--#define SZSERVICEDISPLAYNAME "Simple Service" |
|
339 |
-+#define SZSERVICEDISPLAYNAME PRODUCT_NAME " Service" |
|
340 |
- // list of service dependencies - "dep1\0dep2\0\0" |
|
341 |
--#define SZDEPENDENCIES "" |
|
342 |
-+#define SZDEPENDENCIES PRODUCT_TAP_ID "\0Dhcp\0\0" |
|
343 |
- ////////////////////////////////////////////////////////////////////////////// |
|
344 |
- |
|
345 |
- |
|
346 |
-@@ -126,7 +127,10 @@ |
|
347 |
- // RETURN VALUE: |
|
348 |
- // none |
|
349 |
- // |
|
350 |
-- void AddToMessageLog(LPTSTR lpszMsg); |
|
351 |
-+# define MSG_FLAGS_ERROR (1<<0) |
|
352 |
-+# define MSG_FLAGS_SYS_CODE (1<<1) |
|
353 |
-+ void AddToMessageLog(DWORD flags, LPTSTR lpszMsg); |
|
354 |
-+ void ResetError (void); |
|
355 |
- ////////////////////////////////////////////////////////////////////////////// |
|
356 |
- |
|
357 |
- |
... | ... |
@@ -31,16 +31,10 @@ |
31 | 31 |
* it is called the key_id and is currently 2 bits long. |
32 | 32 |
*/ |
33 | 33 |
|
34 |
-#ifdef WIN32 |
|
35 |
-#include "config-win32.h" |
|
36 |
-#else |
|
37 |
-#include "config.h" |
|
38 |
-#endif |
|
34 |
+#include "syshead.h" |
|
39 | 35 |
|
40 | 36 |
#if defined(USE_CRYPTO) && defined(USE_SSL) |
41 | 37 |
|
42 |
-#include "syshead.h" |
|
43 |
- |
|
44 | 38 |
#include "error.h" |
45 | 39 |
#include "common.h" |
46 | 40 |
#include "crypto.h" |
... | ... |
@@ -22,12 +22,6 @@ |
22 | 22 |
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
23 | 23 |
*/ |
24 | 24 |
|
25 |
-#ifdef WIN32 |
|
26 |
-#include "config-win32.h" |
|
27 |
-#else |
|
28 |
-#include "config.h" |
|
29 |
-#endif |
|
30 |
- |
|
31 | 25 |
#include "syshead.h" |
32 | 26 |
|
33 | 27 |
#include "socket.h" |
... | ... |
@@ -138,6 +132,9 @@ getaddr (unsigned int flags, |
138 | 138 |
while (true) |
139 | 139 |
{ |
140 | 140 |
/* try hostname lookup */ |
141 |
+#if defined(HAVE_RES_INIT) |
|
142 |
+ res_init (); |
|
143 |
+#endif |
|
141 | 144 |
h = gethostbyname (hostname); |
142 | 145 |
|
143 | 146 |
if (signal_received) |
... | ... |
@@ -2121,11 +2118,13 @@ link_socket_read_tcp (struct link_socket *sock, |
2121 | 2121 |
|
2122 | 2122 |
#if ENABLE_IP_PKTINFO |
2123 | 2123 |
|
2124 |
+#pragma pack(1) /* needed to keep structure size consistent for 32 vs. 64-bit architectures */ |
|
2124 | 2125 |
struct openvpn_pktinfo |
2125 | 2126 |
{ |
2126 | 2127 |
struct cmsghdr cmsghdr; |
2127 | 2128 |
struct in_pktinfo in_pktinfo; |
2128 | 2129 |
}; |
2130 |
+#pragma pack() |
|
2129 | 2131 |
|
2130 | 2132 |
static socklen_t |
2131 | 2133 |
link_socket_read_udp_posix_recvmsg (struct link_socket *sock, |
... | ... |
@@ -29,16 +29,10 @@ |
29 | 29 |
* see RFC 1928, only supports "no authentication" |
30 | 30 |
*/ |
31 | 31 |
|
32 |
-#ifdef WIN32 |
|
33 |
-#include "config-win32.h" |
|
34 |
-#else |
|
35 |
-#include "config.h" |
|
36 |
-#endif |
|
32 |
+#include "syshead.h" |
|
37 | 33 |
|
38 | 34 |
#ifdef ENABLE_SOCKS |
39 | 35 |
|
40 |
-#include "syshead.h" |
|
41 |
- |
|
42 | 36 |
#include "common.h" |
43 | 37 |
#include "misc.h" |
44 | 38 |
#include "win32.h" |
... | ... |
@@ -30,16 +30,10 @@ |
30 | 30 |
* over the same TCP/UDP port. |
31 | 31 |
*/ |
32 | 32 |
|
33 |
-#ifdef WIN32 |
|
34 |
-#include "config-win32.h" |
|
35 |
-#else |
|
36 |
-#include "config.h" |
|
37 |
-#endif |
|
33 |
+#include "syshead.h" |
|
38 | 34 |
|
39 | 35 |
#if defined(USE_CRYPTO) && defined(USE_SSL) |
40 | 36 |
|
41 |
-#include "syshead.h" |
|
42 |
- |
|
43 | 37 |
#include "ssl.h" |
44 | 38 |
#include "error.h" |
45 | 39 |
#include "common.h" |
... | ... |
@@ -1210,7 +1204,7 @@ init_ssl (const struct options *options) |
1210 | 1210 |
if (options->pkcs11_providers[0]) |
1211 | 1211 |
{ |
1212 | 1212 |
/* Load Certificate and Private Key */ |
1213 |
- if (!SSL_CTX_use_pkcs11 (ctx, options->pkcs11_id)) |
|
1213 |
+ if (!SSL_CTX_use_pkcs11 (ctx, options->pkcs11_id_management, options->pkcs11_id)) |
|
1214 | 1214 |
{ |
1215 | 1215 |
msg (M_WARN, "Cannot load certificate \"%s\" using PKCS#11 interface", options->pkcs11_id); |
1216 | 1216 |
goto err; |
... | ... |
@@ -25,6 +25,28 @@ |
25 | 25 |
#ifndef SYSHEAD_H |
26 | 26 |
#define SYSHEAD_H |
27 | 27 |
|
28 |
+/* |
|
29 |
+ * Only include if not during configure |
|
30 |
+ */ |
|
31 |
+#ifndef PACKAGE_NAME |
|
32 |
+#ifdef _MSC_VER |
|
33 |
+#include "config-win32.h" |
|
34 |
+#else |
|
35 |
+#include "config.h" |
|
36 |
+#endif |
|
37 |
+#endif |
|
38 |
+ |
|
39 |
+#if defined(_WIN32) && !defined(WIN32) |
|
40 |
+#define WIN32 |
|
41 |
+#endif |
|
42 |
+ |
|
43 |
+#ifdef WIN32 |
|
44 |
+#include <windows.h> |
|
45 |
+#define sleep(x) Sleep((x)*1000) |
|
46 |
+#define random rand |
|
47 |
+#define srandom srand |
|
48 |
+#endif |
|
49 |
+ |
|
28 | 50 |
#ifdef HAVE_SYS_TYPES_H |
29 | 51 |
#include <sys/types.h> |
30 | 52 |
#endif |
... | ... |
@@ -133,6 +155,10 @@ |
133 | 133 |
#include <netinet/in.h> |
134 | 134 |
#endif |
135 | 135 |
|
136 |
+#ifdef HAVE_RESOLV_H |
|
137 |
+#include <resolv.h> |
|
138 |
+#endif |
|
139 |
+ |
|
136 | 140 |
#ifdef HAVE_SYS_POLL_H |
137 | 141 |
#include <sys/poll.h> |
138 | 142 |
#endif |
... | ... |
@@ -272,9 +298,29 @@ |
272 | 272 |
|
273 | 273 |
#endif /* TARGET_NETBSD */ |
274 | 274 |
|
275 |
+#ifdef TARGET_DRAGONFLY |
|
276 |
+ |
|
277 |
+#ifdef HAVE_SYS_UIO_H |
|
278 |
+#include <sys/uio.h> |
|
279 |
+#endif |
|
280 |
+ |
|
281 |
+#ifdef HAVE_NETINET_IN_SYSTM_H |
|
282 |
+#include <netinet/in_systm.h> |
|
283 |
+#endif |
|
284 |
+ |
|
285 |
+#ifdef HAVE_NETINET_IP_H |
|
286 |
+#include <netinet/ip.h> |
|
287 |
+#endif |
|
288 |
+ |
|
289 |
+#ifdef HAVE_NET_TUN_IF_TUN_H |
|
290 |
+#include <net/tun/if_tun.h> |
|
291 |
+#endif |
|
292 |
+ |
|
293 |
+#endif /* TARGET_DRAGONFLY */ |
|
294 |
+ |
|
275 | 295 |
#ifdef WIN32 |
276 | 296 |
#include <iphlpapi.h> |
277 |
-#include <WinInet.h> |
|
297 |
+#include <wininet.h> |
|
278 | 298 |
#endif |
279 | 299 |
|
280 | 300 |
#ifdef HAVE_SYS_MMAN_H |
... | ... |
@@ -32,7 +32,15 @@ |
32 | 32 |
// common to both. |
33 | 33 |
//=============================================== |
34 | 34 |
|
35 |
-#include "../autodefs/defs.h" |
|
35 |
+#if defined(HAVE_CONFIG_H) |
|
36 |
+#include "config.h" |
|
37 |
+#else |
|
38 |
+#if defined(_MSC_VER) && !defined(TAP_DRIVER_MAJOR_VERSION) |
|
39 |
+#include "config-win32.h" |
|
40 |
+#else |
|
41 |
+#include "../config.h" |
|
42 |
+#endif |
|
43 |
+#endif |
|
36 | 44 |
|
37 | 45 |
//============= |
38 | 46 |
// TAP IOCTLs |
... | ... |
@@ -81,4 +89,4 @@ |
81 | 81 |
// simultaneously. |
82 | 82 |
//========================================================= |
83 | 83 |
|
84 |
-#define TAP_COMPONENT_ID PRODUCT_TAP_ID |
|
84 |
+#define TAP_COMPONENT_ID TAP_ID |
... | ... |
@@ -30,12 +30,6 @@ |
30 | 30 |
* from VTun by Maxim Krasnyansky <max_mk@yahoo.com>. |
31 | 31 |
*/ |
32 | 32 |
|
33 |
-#ifdef WIN32 |
|
34 |
-#include "config-win32.h" |
|
35 |
-#else |
|
36 |
-#include "config.h" |
|
37 |
-#endif |
|
38 |
- |
|
39 | 33 |
#include "syshead.h" |
40 | 34 |
|
41 | 35 |
#include "tun.h" |
... | ... |
@@ -799,7 +793,7 @@ do_ifconfig (struct tuntap *tt, |
799 | 799 |
add_route (&r, tt, 0, es); |
800 | 800 |
} |
801 | 801 |
|
802 |
-#elif defined(TARGET_FREEBSD) |
|
802 |
+#elif defined(TARGET_FREEBSD)||defined(TARGET_DRAGONFLY) |
|
803 | 803 |
|
804 | 804 |
/* example: ifconfig tun2 10.2.0.2 10.2.0.1 mtu 1450 netmask 255.255.255.255 up */ |
805 | 805 |
if (tun) |
... | ... |
@@ -1248,7 +1242,7 @@ close_tun (struct tuntap *tt) |
1248 | 1248 |
} |
1249 | 1249 |
#else |
1250 | 1250 |
openvpn_snprintf (command_line, sizeof (command_line), |
1251 |
- IFCONFIG_PATH "%s addr 0.0.0.0", |
|
1251 |
+ IFCONFIG_PATH " %s 0.0.0.0", |
|
1252 | 1252 |
tt->actual_name |
1253 | 1253 |
); |
1254 | 1254 |
#endif |
... | ... |
@@ -1753,6 +1747,89 @@ read_tun (struct tuntap* tt, uint8_t *buf, int len) |
1753 | 1753 |
return read (tt->fd, buf, len); |
1754 | 1754 |
} |
1755 | 1755 |
|
1756 |
+#elif defined(TARGET_DRAGONFLY) |
|
1757 |
+ |
|
1758 |
+static inline int |
|
1759 |
+dragonfly_modify_read_write_return (int len) |
|
1760 |
+{ |
|
1761 |
+ if (len > 0) |
|
1762 |
+ return len > sizeof (u_int32_t) ? len - sizeof (u_int32_t) : 0; |
|
1763 |
+ else |
|
1764 |
+ return len; |
|
1765 |
+} |
|
1766 |
+ |
|
1767 |
+void |
|
1768 |
+open_tun (const char *dev, const char *dev_type, const char *dev_node, bool ipv6, struct tuntap *tt) |
|
1769 |
+{ |
|
1770 |
+ open_tun_generic (dev, dev_type, dev_node, ipv6, true, true, tt); |
|
1771 |
+ |
|
1772 |
+ if (tt->fd >= 0) |
|
1773 |
+ { |
|
1774 |
+ int i = 0; |
|
1775 |
+ |
|
1776 |
+ /* Disable extended modes */ |
|
1777 |
+ ioctl (tt->fd, TUNSLMODE, &i); |
|
1778 |
+ i = 1; |
|
1779 |
+ ioctl (tt->fd, TUNSIFHEAD, &i); |
|
1780 |
+ } |
|
1781 |
+} |
|
1782 |
+ |
|
1783 |
+void |
|
1784 |
+close_tun (struct tuntap *tt) |
|
1785 |
+{ |
|
1786 |
+ if (tt) |
|
1787 |
+ { |
|
1788 |
+ close_tun_generic (tt); |
|
1789 |
+ free (tt); |
|
1790 |
+ } |
|
1791 |
+} |
|
1792 |
+ |
|
1793 |
+int |
|
1794 |
+write_tun (struct tuntap* tt, uint8_t *buf, int len) |
|
1795 |
+{ |
|
1796 |
+ if (tt->type == DEV_TYPE_TUN) |
|
1797 |
+ { |
|
1798 |
+ u_int32_t type; |
|
1799 |
+ struct iovec iv[2]; |
|
1800 |
+ struct ip *iph; |
|
1801 |
+ |
|
1802 |
+ iph = (struct ip *) buf; |
|
1803 |
+ |
|
1804 |
+ if (tt->ipv6 && iph->ip_v == 6) |
|
1805 |
+ type = htonl (AF_INET6); |
|
1806 |
+ else |
|
1807 |
+ type = htonl (AF_INET); |
|
1808 |
+ |
|
1809 |
+ iv[0].iov_base = (char *)&type; |
|
1810 |
+ iv[0].iov_len = sizeof (type); |
|
1811 |
+ iv[1].iov_base = buf; |
|
1812 |
+ iv[1].iov_len = len; |
|
1813 |
+ |
|
1814 |
+ return dragonfly_modify_read_write_return (writev (tt->fd, iv, 2)); |
|
1815 |
+ } |
|
1816 |
+ else |
|
1817 |
+ return write (tt->fd, buf, len); |
|
1818 |
+} |
|
1819 |
+ |
|
1820 |
+int |
|
1821 |
+read_tun (struct tuntap* tt, uint8_t *buf, int len) |
|
1822 |
+{ |
|
1823 |
+ if (tt->type == DEV_TYPE_TUN) |
|
1824 |
+ { |
|
1825 |
+ u_int32_t type; |
|
1826 |
+ struct iovec iv[2]; |
|
1827 |
+ |
|
1828 |
+ iv[0].iov_base = (char *)&type; |
|
1829 |
+ iv[0].iov_len = sizeof (type); |
|
1830 |
+ iv[1].iov_base = buf; |
|
1831 |
+ iv[1].iov_len = len; |
|
1832 |
+ |
|
1833 |
+ return dragonfly_modify_read_write_return (readv (tt->fd, iv, 2)); |
|
1834 |
+ } |
|
1835 |
+ else |
|
1836 |
+ return read (tt->fd, buf, len); |
|
1837 |
+} |
|
1838 |
+ |
|
1756 | 1839 |
#elif defined(WIN32) |
1757 | 1840 |
|
1758 | 1841 |
int |
... | ... |
@@ -26,12 +26,10 @@ |
26 | 26 |
* Win32-specific OpenVPN code, targetted at the mingw |
27 | 27 |
* development environment. |
28 | 28 |
*/ |
29 |
+#include "syshead.h" |
|
29 | 30 |
|
30 | 31 |
#ifdef WIN32 |
31 | 32 |
|
32 |
-#include "config-win32.h" |
|
33 |
- |
|
34 |
-#include "syshead.h" |
|
35 | 33 |
#include "buffer.h" |
36 | 34 |
#include "error.h" |
37 | 35 |
#include "mtu.h" |