]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
Moved branch into official BETA21 position.
authorjames <james@e7ae566f-a301-0410-adde-c780ea21d3b5>
Mon, 12 May 2008 20:31:43 +0000 (20:31 +0000)
committerjames <james@e7ae566f-a301-0410-adde-c780ea21d3b5>
Mon, 12 May 2008 20:31:43 +0000 (20:31 +0000)
git-svn-id: http://svn.openvpn.net/projects/openvpn/branches/BETA21/openvpn@2959 e7ae566f-a301-0410-adde-c780ea21d3b5

90 files changed:
.svnignore
Makefile.am
acinclude.m4
base64.c
buffer.c
config-win32.h.in [moved from config-win32.h with 95% similarity]
configure.ac
crypto.c
cryptoapi.c
doclean
domake-win
error.c
error.h
event.c
fdmisc.c
forward.c
fragment.c
gentoo/openvpn.init [deleted file]
gremlin.c
helper.c
ieproxy.c
images/.svnignore [new file with mode: 0644]
images/Makefile.am [new file with mode: 0644]
init.c
install-win32/.svnignore
install-win32/Makefile.am [new file with mode: 0644]
install-win32/getpkcs11helper
install-win32/makeopenvpn
install-win32/makeservice [deleted file]
install-win32/settings.in
interval.c
list.c
lladdr.c
lzo.c
makefile.w32 [deleted file]
manage.c
manage.h
management/management-notes.txt
mbuf.c
misc.c
misc.h
mroute.c
mss.c
mtcp.c
mtu.c
mudp.c
multi.c
ntlm.c
occ.c
openvpn.8
openvpn.c
options.c
options.h
otime.c
packet_id.c
perf.c
ping.c
pkcs11.c
pkcs11.h
plugin.c
pool.c
proto.c
proxy.c
proxy.h
ps.c
push.c
reliable.c
route.c
schedule.c
service-win32/.svnignore [new file with mode: 0644]
service-win32/Makefile [deleted file]
service-win32/Makefile.am [new file with mode: 0644]
service-win32/mkpatch [deleted file]
service-win32/openvpnserv.c
service-win32/service.c [new file with mode: 0644]
service-win32/service.h [new file with mode: 0644]
service-win32/service.patch [deleted file]
session_id.c
shaper.c
sig.c
socket.c
socks.c
ssl.c
status.c
syshead.h
tap-win32/common.h
thread.c
tun.c
version.m4
win32.c

index 9bc4b41a8164170ae74c761f9ef856fc003d04c9..5dd7a468e9d6137e388314dc7fb37e5952be7637 100644 (file)
@@ -3,6 +3,7 @@
 *.patch
 *.diff
 *.tmp
+*.html
 tmp*
 log*
 files
index 84a89c2ff3c35d8485cc2e475ae39013c1395ffb..f8ce6f55e65b0ec1cb0a0273a10ac888000134d1 100644 (file)
 #  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 #
 
+LDADD = @LIBOBJS@
+.PHONY: plugin
+
 # This option prevents autoreconf from overriding our COPYING and
 # INSTALL targets:
 AUTOMAKE_OPTIONS = foreign
 
-sbin_PROGRAMS = openvpn
+MAINTAINERCLEANFILES = \
+       config.log config.status \
+       $(srcdir)/Makefile.in \
+       $(srcdir)/config.h.in $(srcdir)/config.h.in~ $(srcdir)/configure \
+       $(srcdir)/install-sh $(srcdir)/ltmain.sh $(srcdir)/missing \
+       $(srcdir)/depcomp $(srcdir)/aclocal.m4 \
+       $(srcdir)/config.guess $(srcdir)/config.sub \
+       $(srcdir)/config-win32.h $(srcdir)/openvpn.spec
+CLEANFILES = openvpn.8.html
 
-nodist_openvpn_SOURCES = config.h
+EXTRA_DIST = \
+       easy-rsa \
+       sample-config-files \
+       sample-keys \
+       sample-scripts \
+       suse \
+       tap-win32 \
+       contrib \
+       debug \
+       plugin
+
+SUBDIRS = \
+       images \
+       service-win32 \
+       install-win32
 
 TESTS = t_lpback.sh t_cltsrv.sh
-dist_noinst_SCRIPTS = $(TESTS)
+sbin_PROGRAMS = openvpn
 
-.PHONY: plugin
+dist_noinst_HEADERS = \
+       config-win32.h
+
+dist_noinst_SCRIPTS = \
+       $(TESTS) \
+       doclean \
+       domake-win
+
+dist_noinst_DATA = \
+       openvpn.spec \
+       COPYRIGHT.GPL \
+       PORTS \
+       INSTALL-win32.txt
 
 openvpn_SOURCES = \
         base64.c base64.h \
@@ -80,6 +117,7 @@ openvpn_SOURCES = \
        pool.c pool.h \
        proto.c proto.h \
        proxy.c proxy.h \
+       ieproxy.h ieproxy.c \
         ps.c ps.h \
        push.c push.h \
        reliable.c reliable.h \
@@ -94,44 +132,19 @@ openvpn_SOURCES = \
        status.c status.h \
        syshead.h \
        thread.c thread.h \
-       tun.c tun.h
-
-LDADD = @LIBOBJS@
-
-man_MANS = openvpn.8
+       tun.c tun.h \
+       win32.h win32.c \
+       cryptoapi.h cryptoapi.c
 
-EXTRA_DIST = \
-       doclean \
-       $(man_MANS) \
-       COPYRIGHT.GPL \
-       PORTS \
-       openvpn.spec \
-       easy-rsa \
-       sample-config-files \
-       sample-keys \
-       sample-scripts \
-       gentoo \
-       suse \
-       openvpn.spec.in \
-       config-win32.h \
-       win32.h \
-       win32.c \
-       cryptoapi.h \
-       cryptoapi.c \
-       makefile.w32 \
-        makefile.w32-vc \
-       INSTALL-win32.txt \
-       tap-win32 \
-       install-win32 \
-       service-win32 \
-       contrib \
-       debug \
-       plugin \
-        management \
-       images \
-       ieproxy.c \
-       ieproxy.h \
-       domake-win
 
 dist-hook:
        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
+
+if WIN32
+dist_noinst_DATA += openvpn.8
+nodist_html_DATA = openvpn.8.html
+openvpn.8.html: $(srcdir)/openvpn.8
+       $(MAN2HTML) < $(srcdir)/openvpn.8 > openvpn.8.html
+else
+dist_man_MANS = openvpn.8
+endif
index f164bacb2ffb70a024ea4e94ca296e6f4116f38a..f099de539894feaa771ff0f2637e944e37e08f67 100644 (file)
@@ -96,10 +96,19 @@ AC_DEFUN([TYPE_SOCKLEN_T],
          for arg2 in "struct sockaddr" void; do
             for t in int size_t unsigned long "unsigned long"; do
                AC_TRY_COMPILE([
+                  #ifdef _WIN32
+                  #include <windows.h>
+                  #define PREFIX1 WINSOCK_API_LINKAGE
+                  #define PREFIX2 PASCAL
+                  #else
                   #include <sys/types.h>
                   #include <sys/socket.h>
+                  #define PREFIX1
+                  #define PREFIX2
+                  #define SOCKET int
+                  #endif
 
-                  int getpeername (int, $arg2 *, $t *);
+                  PREFIX1 int PREFIX2 getpeername (SOCKET, $arg2 *, $t *);
                ],[
                   $t len;
                   getpeername(0,0,&len);
index a69633d40bb02d7de31667781d40c9e4d2271b3d..7d876a67d1a5834c60f19a073f91f7e13703ca9b 100644 (file)
--- a/base64.c
+++ b/base64.c
  * SUCH DAMAGE.
  */
 
-#ifdef WIN32
-#include "config-win32.h"
-#else
-#include "config.h"
-#endif
-
 #include "syshead.h"
 
-#ifdef ENABLE_HTTP_PROXY
+#if defined(ENABLE_HTTP_PROXY) || defined(ENABLE_PKCS11)
 
 #include "base64.h"
 
@@ -143,7 +137,7 @@ base64_decode(const char *str, void *data)
     return q - (unsigned char *) data;
 }
 
-#endif /* NTLM */
+#endif /* NTLM, PKCS#11 */
 
 #else
 static void dummy(void) {}
index 64307eff2975c082bba37b643fbc316580556684..93c7930dafb98f8d1a6420b43b70fb6d3676f530 100644 (file)
--- a/buffer.c
+++ b/buffer.c
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#ifdef WIN32
-#include "config-win32.h"
-#else
-#include "config.h"
-#endif
-
 #include "syshead.h"
 
 #include "common.h"
similarity index 95%
rename from config-win32.h
rename to config-win32.h.in
index 4fe1d07b50cbbbde662da6512ad862901866a901..44d9f305841acbd70eab49f30bad62b7dd0a586e 100644 (file)
@@ -62,8 +62,9 @@ typedef unsigned long in_addr_t;
  *
  * The TAP-Win32 version number is defined in tap-win32/SOURCES
  */
-#define TAP_WIN32_MIN_MAJOR 9
-#define TAP_WIN32_MIN_MINOR 1
+#define TAP_ID @TAP_ID@
+#define TAP_WIN32_MIN_MAJOR @TAP_WIN32_MIN_MAJOR@
+#define TAP_WIN32_MIN_MINOR @TAP_WIN32_MIN_MINOR@
 
 /* Enable client/server capability */
 #define ENABLE_CLIENT_SERVER 1
@@ -215,19 +216,19 @@ typedef unsigned long in_addr_t;
 #define HAVE_GETPASS 1
 
 /* Name of package */
-#define PACKAGE PRODUCT_UNIX_NAME
+#define PACKAGE @PACKAGE@
 
 /* Define to the address where bug reports for this package should be sent. */
 //#define PACKAGE_BUGREPORT "openvpn-users@lists.sourceforge.net"
 
 /* Define to the full name of this package. */
-#define PACKAGE_NAME PRODUCT_NAME
+#define PACKAGE_NAME @PACKAGE_NAME@
 
 /* Define to the one symbol short name of this package. */
-#define PACKAGE_TARNAME PACKAGE
+#define PACKAGE_TARNAME @PACKAGE_TARNAME@
 
 /* Define to the version of this package. */
-#define PACKAGE_VERSION PRODUCT_VERSION
+#define PACKAGE_VERSION @PACKAGE_VERSION@
 
 /* Define to the full name and version of this package. */
 #ifdef DEBUG_LABEL
@@ -318,4 +319,8 @@ typedef unsigned long in_addr_t;
 #define S_IWUSR 0
 typedef int intptr_t;
 #undef S_NORMAL
+/* Visual Studio 2005 supports vararg macros */
+#if _MSC_VER >= 1400
+#define HAVE_CPP_VARARG_MACRO_ISO 1
+#endif
 #endif
index 1302494b88f8a78e01c8f5354a7ef523f0dcf09a..ee8ae0b9661261cb72a14e1311e9bceb870cad65 100644 (file)
@@ -30,6 +30,39 @@ AC_INIT([OpenVPN], [PRODUCT_VERSION], [openvpn-users@lists.sourceforge.net], [op
 AM_CONFIG_HEADER(config.h)
 AC_CONFIG_SRCDIR(syshead.h)
 
+dnl Guess host type.
+AC_CANONICAL_HOST
+AC_CANONICAL_SYSTEM
+AM_INIT_AUTOMAKE(openvpn, [$PACKAGE_VERSION])
+
+AC_ARG_WITH(cygwin-native,
+       [  --with-cygwin-native              Compile native win32],
+       [CYGWIN_NATIVE="${withval}"],
+       [CYGWIN_NATIVE="no"]
+)
+
+WIN32="no"
+CYGWIN="no"
+case "${host}" in
+       *-mingw32*)
+               WIN32="yes"
+               cross_compiling="yes"
+       ;;
+       *-cygwin*)
+               AC_MSG_CHECKING([cygwin mode to use])
+               if test "${CYGWIN_NATIVE}" = "yes"; then
+                       AC_MSG_RESULT([Using native win32])
+                       CFLAGS="${CFLAGS} -mno-cygwin"
+                       CYGWIN="yes"
+                       WIN32="yes"
+               else
+                       AC_MSG_RESULT([Using cygwin])
+               fi
+       ;;
+       *)
+       ;;
+esac
+
 AC_ARG_ENABLE(lzo,
    [  --disable-lzo           Disable LZO compression support],
    [LZO="$enableval"],
@@ -183,6 +216,17 @@ AC_ARG_WITH(lzo-lib,
    [LDFLAGS="$LDFLAGS -L$withval"] 
 )
 
+AC_ARG_WITH(pkcs11-helper-headers,
+   [  --with-pkcs11-helper-headers=DIR pkcs11-helper Include files location],
+   [PKCS11_HELPER_HDR_DIR="$withval"]
+   [CPPFLAGS="$CPPFLAGS -I$withval"] 
+)
+
+AC_ARG_WITH(pkcs11-helper-lib,
+   [  --with-pkcs11-helper-lib=DIR     pkcs11-helper Library location],
+   [LDFLAGS="$LDFLAGS -L$withval"] 
+)
+
 AC_ARG_WITH(ifconfig-path,
    [  --with-ifconfig-path=PATH   Path to ifconfig tool],
    [IFCONFIG="$withval"],
@@ -210,11 +254,6 @@ AC_ARG_WITH(mem-check,
    [MEMCHECK="$withval"]
 )
 
-dnl Guess host type.
-AC_CANONICAL_HOST
-AC_CANONICAL_SYSTEM
-AM_INIT_AUTOMAKE(openvpn, [$PACKAGE_VERSION])
-
 dnl fix search path, to allow compilers to find syshead.h
 CPPFLAGS="$CPPFLAGS -I${srcdir}"
 
@@ -250,10 +289,16 @@ case "$target" in
        CPPFLAGS="$CPPFLAGS -no-cpp-precomp"
        ;;
 *mingw*)
-       AC_MSG_RESULT([WARNING: configure support for mingw is incomplete])
-       AC_MSG_RESULT([WARNING: use makefile.w32 instead])
+       AC_DEFINE(TARGET_WIN32, 1, [Are we running WIN32?])
        OPENVPN_ADD_LIBS(-lgdi32)
-       OPENVPN_ADD_LIBS(-lwsock32)
+       OPENVPN_ADD_LIBS(-lws2_32)
+       OPENVPN_ADD_LIBS(-lwininet)
+       OPENVPN_ADD_LIBS(-lcrypt32)
+       OPENVPN_ADD_LIBS(-liphlpapi)
+       OPENVPN_ADD_LIBS(-lwinmm)
+       ;;
+*dragonfly*)
+       AC_DEFINE(TARGET_DRAGONFLY, 1, [Are we running on DragonFlyBSD?])
        ;;
        
 esac
@@ -263,6 +308,12 @@ AC_PROG_CC
 AC_PROG_INSTALL
 AC_PROG_GCC_TRADITIONAL
 
+if test "${WIN32}" = "yes"; then
+       AC_ARG_VAR([MAN2HTML], [man2html utility])
+       AC_CHECK_PROGS([MAN2HTML], [man2html])
+       test -z "${MAN2HTML}" && AC_MSG_ERROR([man2html is required for win32])
+fi
+
 dnl Checks for header files.
 AC_HEADER_STDC
 
@@ -274,29 +325,36 @@ AC_TYPE_OFF_T
 AC_TYPE_PID_T
 AC_TYPE_SIZE_T
 AC_TYPE_UID_T
+TYPE_SOCKLEN_T
 AC_HEADER_TIME
 AX_CPP_VARARG_MACRO_ISO
 AX_CPP_VARARG_MACRO_GCC
 AX_EMPTY_ARRAY
 
 dnl Check for more header files.
-AC_HEADER_SYS_WAIT
-AC_CHECK_HEADERS(sys/time.h sys/socket.h sys/ioctl.h sys/stat.h dnl
+AC_CHECK_HEADERS(fcntl.h stdlib.h dnl
+                stdarg.h stdio.h string.h dnl
+                strings.h ctype.h errno.h dnl
+)
+
+if test "${WIN32}" != "yes"; then
+   AC_HEADER_SYS_WAIT
+   AC_CHECK_HEADERS(sys/time.h sys/socket.h sys/ioctl.h sys/stat.h dnl
                 sys/mman.h fcntl.h sys/file.h stdlib.h stdint.h dnl
                 stdarg.h unistd.h signal.h stdio.h string.h dnl
                 strings.h ctype.h errno.h syslog.h pwd.h grp.h dnl
-                net/if_tun.h stropts.h sys/sockio.h dnl
+                net/if_tun.h net/tun/if_tun.h stropts.h sys/sockio.h dnl
                 netinet/in.h netinet/in_systm.h dnl
                 netinet/tcp.h arpa/inet.h dnl
                 netdb.h sys/uio.h linux/if_tun.h linux/sockios.h dnl
                 linux/types.h sys/poll.h sys/epoll.h err.h dnl
-)
-AC_CHECK_HEADERS(net/if.h,,,
+   )
+   AC_CHECK_HEADERS(net/if.h,,,
                 [#ifdef HAVE_SYS_SOCKET_H 
                  # include <sys/socket.h>
                  #endif
                 ])
-AC_CHECK_HEADERS(netinet/ip.h,,,
+   AC_CHECK_HEADERS(netinet/ip.h,,,
                 [#ifdef HAVE_SYS_TYPES_H
                  # include <sys/types.h>
                  #endif
@@ -307,7 +365,7 @@ AC_CHECK_HEADERS(netinet/ip.h,,,
                  # include <netinet/in_systm.h>
                  #endif
                 ])
-AC_CHECK_HEADERS(netinet/if_ether.h,,,
+   AC_CHECK_HEADERS(netinet/if_ether.h,,,
                 [#ifdef HAVE_SYS_TYPES_H
                  # include <sys/types.h>
                  #endif
@@ -318,16 +376,18 @@ AC_CHECK_HEADERS(netinet/if_ether.h,,,
                  # include <netinet/in.h>
                  #endif
                 ])
-AC_CHECK_HEADERS(resolv.h,,,
+   AC_CHECK_HEADERS(resolv.h,,,
                 [#ifdef HAVE_NETINET_IN_H 
                  # include <netinet/in.h>
                  #endif
                 ])
-AC_CHECK_HEADERS(linux/errqueue.h,,,
+   AC_CHECK_HEADERS(linux/errqueue.h,,,
        [#ifdef HAVE_LINUX_TYPES_H
         # include <linux/types.h>
         #endif
        ])
+fi
+
 AC_CACHE_SAVE
 
 dnl check that in_addr_t is defined
@@ -398,35 +458,59 @@ AC_CHECK_SIZEOF(unsigned long)
 
 AC_CACHE_SAVE
 
-dnl check for other types
-TYPE_SOCKLEN_T
-AC_TYPE_SIGNAL
-
-dnl Check for libsocket
-AC_SEARCH_LIBS(socket, socket)
-
-dnl Check for libnsl
-AC_SEARCH_LIBS(inet_ntoa, nsl)
-
-dnl Check for libresolv
-AC_SEARCH_LIBS(gethostbyname, resolv nsl)
-
-dnl optional library functions
-AC_FUNC_FORK
 AC_CHECK_FUNCS(daemon chroot getpwnam setuid nice system getpid dup dup2 dnl
               getpass strerror syslog openlog mlockall getgrnam setgid dnl
               setgroups stat flock readv writev setsockopt getsockopt dnl
-              setsid chdir gettimeofday putenv getpeername unlink dnl
-               poll chsize ftruncate sendmsg recvmsg getsockname)
+              setsid chdir putenv getpeername unlink dnl
+              poll chsize ftruncate sendmsg recvmsg getsockname)
 AC_CACHE_SAVE
 
+if test "${WIN32}" = "yes"; then
+
+       AC_DEFINE([HAVE_GETTIMEOFDAY], [1], [We fake gettimeofday for win32 at otime.c])
+
+else
+
+       dnl check for other types
+       AC_TYPE_SIGNAL
+
+       dnl Check for libsocket
+       AC_SEARCH_LIBS(socket, socket)
+
+       dnl Check for libnsl
+       AC_SEARCH_LIBS(inet_ntoa, nsl)
+
+       dnl Check for libresolv
+       AC_SEARCH_LIBS(gethostbyname, resolv nsl)
+
+       dnl optional library functions
+       AC_FUNC_FORK
+
+       AC_CHECK_FUNCS(gettimeofday)
+
+       AC_CHECK_FUNCS(socket recv recvfrom send sendto listen dnl
+                      accept connect bind select gethostbyname dnl
+                      inet_ntoa time ctime memset vsnprintf strdup, [],
+                      [AC_MSG_ERROR([Required library function not found])])
+
+fi
+
 dnl Required library functions
 AC_FUNC_MEMCMP
 
-AC_CHECK_FUNCS(socket recv recvfrom send sendto listen dnl
-              accept connect bind select gethostbyname dnl
-               inet_ntoa time ctime memset vsnprintf strdup, [],
-              [AC_MSG_ERROR([Required library function not found])])
+dnl
+dnl Check for res_init
+dnl
+AC_TRY_LINK([
+    #include <resolv.h>
+  ], [
+    res_init ();
+  ], [
+    AC_MSG_RESULT([res_init DEFINED])
+    AC_DEFINE([HAVE_RES_INIT], 1, [Indicates if res_init is available])
+  ], [
+    AC_MSG_RESULT([res_init UNDEFINED])
+  ])
 
 dnl
 dnl check libraries
@@ -505,21 +589,23 @@ fi
 dnl
 dnl Check for dlopen -- first try libc then libdl.
 dnl
-if test "$PLUGINS" = "yes"; then
-   AC_CHECKING([for libdl Library and Header files])
-   AC_CHECK_HEADER(dlfcn.h,
-        [AC_CHECK_FUNC(dlopen,
-            [AC_DEFINE(USE_LIBDL, 1, [Use libdl for dynamic library loading])],
-            [AC_CHECK_LIB(dl, dlopen,
-               [
-                   OPENVPN_ADD_LIBS(-ldl)
-                  AC_DEFINE(USE_LIBDL, 1, [Use libdl for dynamic library loading])
-               ],
-               [AC_MSG_RESULT([libdl library not found.])]
-           )],
-        )],
-        [AC_MSG_RESULT([libdl headers not found.])]
-   )
+if test "${WIN32}" != "yes"; then
+   if test "$PLUGINS" = "yes"; then
+      AC_CHECKING([for libdl Library and Header files])
+      AC_CHECK_HEADER(dlfcn.h,
+           [AC_CHECK_FUNC(dlopen,
+               [AC_DEFINE(USE_LIBDL, 1, [Use libdl for dynamic library loading])],
+               [AC_CHECK_LIB(dl, dlopen,
+                  [
+                      OPENVPN_ADD_LIBS(-ldl)
+                     AC_DEFINE(USE_LIBDL, 1, [Use libdl for dynamic library loading])
+                  ],
+                  [AC_MSG_RESULT([libdl library not found.])]
+              )],
+           )],
+           [AC_MSG_RESULT([libdl headers not found.])]
+      )
+   fi
 fi
 
 dnl
@@ -572,7 +658,7 @@ if test "$CRYPTO" = "yes"; then
                   AC_CHECKING([that OpenSSL Library is at least version 0.9.6])
                   AC_EGREP_CPP(yes,
                     [
-                      #include "openssl/evp.h"
+                      #include <openssl/evp.h>
                       #if SSLEAY_VERSION_NUMBER >= 0x00906000L
                         yes
                       #endif
@@ -692,7 +778,7 @@ fi
 
 dnl enable strict compiler warnings
 if test "$STRICT" = "yes"; then
-   CFLAGS="$CFLAGS -Wall -Wpointer-arith -Wsign-compare -Wno-unused-parameter -Wno-unused-function"
+   CFLAGS="$CFLAGS -Wall -Wno-unused-parameter -Wno-unused-function"
 fi
 
 dnl enable pedantic compiler warnings
@@ -715,4 +801,37 @@ if test "$PASSWORD_SAVE" = "yes"; then
    AC_DEFINE(ENABLE_PASSWORD_SAVE, 1, [Allow --askpass and --auth-user-pass passwords to be read from a file])
 fi
 
-AC_OUTPUT(Makefile openvpn.spec)
+TAP_ID="PRODUCT_TAP_ID"
+TAP_WIN32_MIN_MAJOR="PRODUCT_TAP_WIN32_MIN_MAJOR"
+TAP_WIN32_MIN_MINOR="PRODUCT_TAP_WIN32_MIN_MINOR"
+AC_DEFINE_UNQUOTED(TAP_ID, "${TAP_ID}", [The TAP-Win32 id defined in tap-win32/SOURCES])
+AC_DEFINE_UNQUOTED(TAP_WIN32_MIN_MAJOR, ${TAP_WIN32_MIN_MAJOR}, [The TAP-Win32 version number is defined in tap-win32/SOURCES])
+AC_DEFINE_UNQUOTED(TAP_WIN32_MIN_MINOR, ${TAP_WIN32_MIN_MINOR}, [The TAP-Win32 version number is defined in tap-win32/SOURCES])
+AC_SUBST(TAP_ID)
+AC_SUBST(TAP_WIN32_MIN_MAJOR)
+AC_SUBST(TAP_WIN32_MIN_MINOR)
+
+win32datadir="\${datadir}/${PACKAGE}-win32"
+AC_SUBST(win32datadir)
+AM_CONDITIONAL(WIN32, test "${WIN32}" = "yes")
+
+# workaround for <autoconf-2.60
+if test -z "${docdir}"; then
+       docdir="\$(datarootdir)/doc/\$(PACKAGE_NAME)"
+       AC_SUBST([docdir])
+fi
+if test -z "${htmldir}"; then
+       htmldir="\$(docdir)"
+       AC_SUBST([htmldir])
+fi
+# end workaround
+
+AC_OUTPUT([
+       Makefile
+       openvpn.spec
+       config-win32.h
+       images/Makefile
+       service-win32/Makefile
+       install-win32/Makefile
+       install-win32/settings
+])
index 5b723b3d12bf3e9f1a941912684d149f19bb70bd..81d4f48ada38edac49d12fea8e9bbb7aa68a6112 100644 (file)
--- a/crypto.c
+++ b/crypto.c
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#ifdef WIN32
-#include "config-win32.h"
-#else
-#include "config.h"
-#endif
+#include "syshead.h"
 
 #ifdef USE_CRYPTO
 
-#include "syshead.h"
-
 #include "crypto.h"
 #include "error.h"
 #include "misc.h"
index 275fec98d8365b338b8074d053bcba74ecb88737..9324b2731412c8991146f2996c4f8fb18b8f585e 100644 (file)
  * LITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
+
+#include "syshead.h"
+
+#ifdef WIN32
+
+#include <openssl/ssl.h>
+#include <openssl/err.h>
 #include <windows.h>
 #include <wincrypt.h>
 #include <stdio.h>
 #include <ctype.h>
 #include <assert.h>
-#include <openssl/ssl.h>
-#include <openssl/err.h>
 
 #ifdef __MINGW32_VERSION
 /* 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)
     }
     return 0;
 }
+
+#else
+static void dummy (void) {}
+#endif                         /* WIN32 */
diff --git a/doclean b/doclean
index 5ffde4e4b78707474e09b5b058add09bf91f9e22..63bf5ae4b9cb5ca3a460ee349ff9404c086e7421 100755 (executable)
--- a/doclean
+++ b/doclean
@@ -1,16 +1,71 @@
 #!/bin/sh
 
-# Let's have a fresh start.  Remove all files
-# which are not source files.
+# Let's have a fresh start.  Remove all
+# generated files.
 #
 # Run this script, then:
-#        touch *
-#        [apply any patches here]
 #        autoreconf -i -v
 #        ./configure
 #        make
 #        make install
 
-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
+rm -f \
+    *.o \
+    service-win32/*.o \
+    service-win32/*.exe \
+    *.exe \
+    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 \
+    openvpn.8.html \
+    config-win32.h \
+    install-win32/*.exe \
+    install-win32/makensis.log \
+    install-win32/settings \
+    install-win32/Makefile \
+    install-win32/Makefile.in \
+    images/Makefile \
+    images/Makefile.in \
+    service-win32/Makefile \
+    service-win32/Makefile.in
 
-rm -rf autom4te*.cache .deps
+rm -rf \
+    autom4te*.cache \
+    .deps \
+    */.deps \
+    windest \
+    autodefs \
+    gen \
+    tapinstall \
+    install-win32/tmp
+
+rm -rf \
+    tap-win32/objfre_w2k_x86 \
+    tap-win32/dist \
+    tap-win32/SOURCES \
+    tap-win32/tapdrvr.cod \
+    tap-win32/buildfre_wnet_amd64.wrn \
+    tap-win32/buildfre_w2k_x86.wrn \
+    tap-win32/objfre_wnet_amd64 \
+    tap-win32/buildfre_wnet_amd64.log \
+    tap-win32/buildfre_w2k_x86.log \
+    tap-win32/amd64 \
+    tap-win32/i386/tap0901.pdb \
+    tap-win32/i386/OemWin2k.inf \
+    tap-win32/i386/tap0901.map \
+    tap-win32/i386/tap0901.sys
index 275865601a27d25fe6a653ef4da706e0dc83ccc2..a6fb194e416d26c55f5a12b0922f69b8f0c8e7a3 100644 (file)
@@ -6,8 +6,14 @@
 # 2000 and higher, and x64 on Windows 2003 and higher.
 # For quick start options, see pre-built notes below.
 #
+# Note that if you are only looking to build the
+# openvpn user-space binaries (openvpn.exe
+# and openvpnserv.exe) you can use the
+# provided autoconf/automake build environment.
+#
 # See top-level build configuration and settings in:
 #
+#   version.m4
 #   install-win32/settings.in
 #
 # Mandatory prerequisites:
@@ -105,12 +111,9 @@ install-win32/getprebuilt
 # The exception is the last script which gathers together all files from
 # GENOUT and builds the installer.
 
-# Make the OpenVPN user-space component (openvpn.exe)
+# Make the OpenVPN user-space components (OpenVPN and service)
 install-win32/makeopenvpn
 
-# Make the OpenVPN service
-install-win32/makeservice
-
 # Make the OpenVPN TAP driver
 install-win32/maketap
 
diff --git a/error.c b/error.c
index de23b3d17a35b417e84028c087ca595742edd4c9..bb5909a7ec33247cb93a6d5070add9458cda624c 100644 (file)
--- a/error.c
+++ b/error.c
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#ifdef WIN32
-#include "config-win32.h"
-#else
-#include "config.h"
-#endif
-
 #include "syshead.h"
 
 #include "error.h"
diff --git a/error.h b/error.h
index 148ca61f90b814392bece7081d9a474795b040fc..f2eaa1263588064509995c5208636ec8680483a3 100644 (file)
--- a/error.h
+++ b/error.h
 
 /* #define ABORT_ON_ERROR */
 
+#ifdef ENABLE_PKCS11
+#define ERR_BUF_SIZE 8192
+#else
 #define ERR_BUF_SIZE 1024
+#endif
 
 struct gc_arena;
 
diff --git a/event.c b/event.c
index 4d82fd3abd984416ff385b195160bb9ac46cd5c5..35c31e731038f0735a30d0b16fb55eed3f5ac214 100644 (file)
--- a/event.c
+++ b/event.c
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#ifdef WIN32
-#include "config-win32.h"
-#else
-#include "config.h"
-#endif
-
 #include "syshead.h"
 
 #include "buffer.h"
index eb7a6fcd2990a36b077de3e191241ebb372baf38..08fb2759a32fd9f1e00d1a6dfdd0921972f7a3db 100644 (file)
--- a/fdmisc.c
+++ b/fdmisc.c
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#ifdef WIN32
-#include "config-win32.h"
-#else
-#include "config.h"
-#endif
-
 #include "syshead.h"
 
 #include "fdmisc.h"
index 6887a3caf777f74b449d19f79b67c3d3c0eb3fb8..a38dd14abc6544f0c00e7402cd2d4c214c173633 100644 (file)
--- a/forward.c
+++ b/forward.c
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#ifdef WIN32
-#include "config-win32.h"
-#else
-#include "config.h"
-#endif
-
 #include "syshead.h"
 
 #include "forward.h"
index ead098a02aa502a39910cdc8cd7368e1127d93f5..992b8c85735bf0fa6b63de58cf63b85267dabdea 100644 (file)
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#ifdef WIN32
-#include "config-win32.h"
-#else
-#include "config.h"
-#endif
-
 #include "syshead.h"
 
 #ifdef ENABLE_FRAGMENT
diff --git a/gentoo/openvpn.init b/gentoo/openvpn.init
deleted file mode 100755 (executable)
index 99fa8b2..0000000
+++ /dev/null
@@ -1,111 +0,0 @@
-#!/sbin/runscript
-
-# OpenVPN start/stop script
-# Adapted to Gentoo by James Yonan
-
-# Originally Contributed to the OpenVPN project by
-# Douglas Keller <doug@voidstar.dyndns.org>
-# 2002.05.15
-
-# This script does the following:
-#
-# - Starts an openvpn process for each .conf file it finds in
-#   /etc/openvpn.
-#
-# - If /etc/openvpn/xxx.sh exists for a xxx.conf file then it executes
-#   it before starting openvpn (useful for doing openvpn --mktun...).
-
-# - In addition to start/stop you can do:
-#
-#   service openvpn reload - SIGHUP
-#   service openvpn reopen - SIGUSR1
-#   service openvpn status - SIGUSR2
-
-# Location of openvpn binary
-openvpn=/usr/local/sbin/openvpn
-
-# PID directory
-piddir=/var/run/openvpn
-
-# Our working directory (.conf files should be here)
-work=/etc/openvpn
-
-# Our options
-opts="start stop restart condrestart"
-
-depend() {
-    need net
-    use dns
-}
-
-start() {
-    ebegin "Starting OpenVPN"
-
-    # Load the TUN/TAP module
-    /sbin/modprobe tun >/dev/null 2>&1
-
-    if [ ! -d  $piddir ]; then
-       mkdir $piddir
-    fi
-
-    cd $work
-
-    # Start every .conf in $work and run .sh if exists
-    local errors=0
-    local successes=0
-    local retstatus=0
-    for c in `/bin/ls *.conf 2>/dev/null`; do
-       bn=${c%%.conf}
-       if [ -f "$bn.sh" ]; then
-           . $bn.sh
-       fi
-       rm -f $piddir/$bn.pid
-       $openvpn --daemon openvpn-$bn --writepid $piddir/$bn.pid --config $c --cd $work
-       if [ $? = 0 ]; then
-           successes=1
-       else
-           errors=1
-       fi
-    done
-
-    # Decide status based on errors/successes.
-    # If at least one tunnel succeeded, we return success.
-    # If some tunnels succeeded and some failed, we return
-    #   success but give a warning.
-    if [ $successes = 1 ]; then
-       if [ $errors = 1 ]; then
-           ewarn "Note: At least one OpenVPN tunnel failed to start"
-       fi
-    else
-       retstatus=1
-       if [ $errors = 0 ]; then
-           ewarn "Note: No OpenVPN configuration files were found in $work"
-       fi
-    fi
-    eend $retstatus "Error starting OpenVPN"
-}
-
-stop() {
-    ebegin "Stopping OpenVPN"
-    for pidf in `/bin/ls $piddir/*.pid 2>/dev/null`; do
-       if [ -s $pidf ]; then
-           kill `cat $pidf` >/dev/null 2>&1
-       fi
-       rm -f $pidf
-    done
-    eend 0
-}
-
-# this should really be in runscript.sh
-started() {
-    if [ -L "${svcdir}/started/${myservice}" ]; then
-       return 1
-    else
-       return 0
-    fi
-}
-
-# attempt to restart ONLY if we are already started
-condrestart() {
-    started || restart
-}
index 0a3cf19d3cc34e63f761ba0dee0a15c7ab9772cf..93b73209e2237dc2926cbdf9e7211549e9059f3d 100644 (file)
--- a/gremlin.c
+++ b/gremlin.c
  * network outages when the --gremlin option is used.
  */
 
-#ifdef WIN32
-#include "config-win32.h"
-#else
-#include "config.h"
-#endif
-
 #include "syshead.h"
 
 #ifdef ENABLE_DEBUG
index d2b3d6fa915036acda92e808983c2e75f31473e9..a2166876a646e7f3584e0a19572d72cec3ca36d1 100644 (file)
--- a/helper.c
+++ b/helper.c
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#ifdef WIN32
-#include "config-win32.h"
-#else
-#include "config.h"
-#endif
-
 #include "syshead.h"
 
 #include "forward.h"
index 42b067b2c2de170cd919c10538654d1e6f55754b..89977a821aca72c114403edcaf87facdf5e36dc5 100644 (file)
--- a/ieproxy.c
+++ b/ieproxy.c
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#include <WinInet.h>
+#include "syshead.h"
+
+#ifdef WIN32
+
+#include <wininet.h>
 #include <malloc.h>
 
 LPCTSTR getIeHttpProxyError=NULL;
@@ -135,3 +139,7 @@ LPCTSTR getIeHttpProxy()
     return(NULL);
   }
 }
+
+#else
+static void dummy (void) {}
+#endif                         /* WIN32 */
diff --git a/images/.svnignore b/images/.svnignore
new file mode 100644 (file)
index 0000000..282522d
--- /dev/null
@@ -0,0 +1,2 @@
+Makefile
+Makefile.in
diff --git a/images/Makefile.am b/images/Makefile.am
new file mode 100644 (file)
index 0000000..d633e4d
--- /dev/null
@@ -0,0 +1,41 @@
+#
+#  OpenVPN -- An application to securely tunnel IP networks
+#             over a single UDP port, with support for SSL/TLS-based
+#             session authentication and key exchange,
+#             packet encryption, packet authentication, and
+#             packet compression.
+#
+#  Copyright (C) 2002-2005 OpenVPN Solutions LLC <info@openvpn.net>
+#
+#  This program is free software; you can redistribute it and/or modify
+#  it under the terms of the GNU General Public License version 2
+#  as published by the Free Software Foundation.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program (see the file COPYING included with this
+#  distribution); if not, write to the Free Software Foundation, Inc.,
+#  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+#
+
+MAINTAINERCLEANFILES = $(srcdir)/Makefile.in
+
+images = \
+       install-whirl.bmp \
+       icon.ico
+
+if WIN32
+
+imagedir = $(win32datadir)/images
+dist_image_DATA = $(images)
+
+else
+
+dist_noinst_DATA = $(images)
+
+endif
+
diff --git a/init.c b/init.c
index ab736f1bdc898f1df94c8de68dbc42c4966e8e8e..c7aa7bed4e8c476e03166c5a3d750eaecee565c9 100644 (file)
--- a/init.c
+++ b/init.c
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#ifdef WIN32
-#include "config-win32.h"
-#else
-#include "config.h"
-#endif
-
 #include "syshead.h"
 
 #include "win32.h"
index f3e20069c316c75956384cb7c9c75be8a1113167..6bf320b3343036fe9e5d9dc7f29fb9bc377ec8fb 100644 (file)
@@ -1 +1,5 @@
 openvpn.nsi
+settings
+Makefile
+Makefile.in
+tmp
diff --git a/install-win32/Makefile.am b/install-win32/Makefile.am
new file mode 100644 (file)
index 0000000..80fd4be
--- /dev/null
@@ -0,0 +1,74 @@
+#
+#  OpenVPN -- An application to securely tunnel IP networks
+#             over a single UDP port, with support for SSL/TLS-based
+#             session authentication and key exchange,
+#             packet encryption, packet authentication, and
+#             packet compression.
+#
+#  Copyright (C) 2002-2005 OpenVPN Solutions LLC <info@openvpn.net>
+#
+#  This program is free software; you can redistribute it and/or modify
+#  it under the terms of the GNU General Public License version 2
+#  as published by the Free Software Foundation.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program (see the file COPYING included with this
+#  distribution); if not, write to the Free Software Foundation, Inc.,
+#  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+#
+
+MAINTAINERCLEANFILES = $(srcdir)/Makefile.in
+
+dist_noinst_DATA = \
+       openvpn.nsi \
+       setpath.nsi
+
+if WIN32
+
+nodist_doc_DATA = tmp/license.txt
+
+confdir = $(win32datadir)/config
+nodist_conf_DATA = \
+       tmp/openssl.cnf.sample \
+       tmp/client.ovpn \
+       tmp/server.ovpn
+dist_conf_DATA = \
+       sample.ovpn
+
+easyrsadir = $(win32datadir)/easy-rsa/Windows
+nodist_easyrsa_DATA = \
+       $(top_srcdir)/easy-rsa/Windows/*
+
+keysdir = $(win32datadir)/sample-keys
+nodist_keys_DATA = \
+       $(top_srcdir)/sample-keys/*
+
+tmp:
+       mkdir tmp
+
+tmp/client.ovpn:       tmp $(top_srcdir)/sample-config-files/client.conf
+       cp $(top_srcdir)/sample-config-files/client.conf tmp/client.ovpn
+
+tmp/server.ovpn:       tmp $(top_srcdir)/sample-config-files/server.conf
+       cp $(top_srcdir)/sample-config-files/server.conf tmp/server.ovpn
+
+tmp/license.txt:       tmp $(top_srcdir)/COPYING $(top_srcdir)/COPYRIGHT.GPL
+       cat $(top_srcdir)/COPYING $(top_srcdir)/COPYRIGHT.GPL > tmp/license.txt
+
+tmp/openssl.cnf.sample:        tmp $(top_srcdir)/easy-rsa/2.0/openssl.cnf
+       cp $(top_srcdir)/easy-rsa/2.0/openssl.cnf tmp/openssl.cnf.sample
+
+clean-local:
+       -rm -fr tmp
+
+else
+
+dist_noinst_DATA += sample.ovpn
+
+endif
+
index 2a34c6e3f5d3fc90988734198dc52964652a6299..8fcfdd40964bea597fbb60c6324e330acc3c4241 100644 (file)
@@ -7,7 +7,7 @@
 if [ -d "$PKCS11_HELPER_DIR" ] ; then
     mkdir -p $GENOUT/lib &>/dev/null    
     for f in libpkcs11-helper-1.dll ; do
-       cp $PKCS11_HELPER_DIR/bin/$f $GENOUT/lib
+       cp $PKCS11_HELPER_DIR/usr/local/bin/$f $GENOUT/lib
         if [ -z "$NO_STRIP" ]; then
            strip $GENOUT/lib/$f
        fi
index e3aef48aecdf84de7b9ffa5e361c6f89a8804dce..c1a805ddd4648ad5ed3f00ec38bf9dade42dfae2 100644 (file)
@@ -1,19 +1,37 @@
 #!/bin/sh
 
+H=`pwd`
+
 # get version.nsi definitions
 . autodefs/defs.sh
 
 if gcc --version &>/dev/null && [ -d "$OPENSSL_DIR" ] && [ -d "$LZO_DIR" ] && [ -d "$PKCS11_HELPER_DIR" ]; then
     # build OpenVPN binary
-    [ "$CLEAN" = "yes" ] && make -f makefile.w32 clean
-    make -f makefile.w32 -j $MAKE_JOBS
 
-    # copy OpenVPN executable to GENOUT/bin
+    if ! [ -f Makefile ]; then
+       autoreconf -i -v \
+       && ./configure \
+           --enable-strict \
+           --prefix=$H/windest \
+           MAN2HTML=true \
+           --with-ssl-headers=$H/$OPENSSL_DIR/include \
+           --with-ssl-lib=$H/$OPENSSL_DIR/out \
+           --with-lzo-headers=$H/$LZO_DIR/include \
+           --with-lzo-lib=$H/$LZO_DIR \
+           --with-pkcs11-helper-headers=$H/$PKCS11_HELPER_DIR/usr/local/include \
+           --with-pkcs11-helper-lib=$H/$PKCS11_HELPER_DIR/usr/local/lib
+    fi
+
+    make -j $MAKE_JOBS && make install
+
+    # copy OpenVPN and service executables to GENOUT/bin
     mkdir -p $GENOUT/bin &>/dev/null
-    cp $PRODUCT_UNIX_NAME.exe $GENOUT/bin
+    cp windest/sbin/openvpn.exe $GENOUT/bin
+    cp windest/sbin/openvpnserv.exe $GENOUT/bin
     if [ -z "$NO_STRIP" ]; then
-       strip $GENOUT/bin/$PRODUCT_UNIX_NAME.exe
+       strip $GENOUT/bin/openvpn.exe
+       strip $GENOUT/bin/openvpnserv.exe
     fi
 else
-    echo DID NOT BUILD openvpn.exe because one or more of gcc, OPENSSL_DIR, LZO_DIR, or PKCS11_HELPER_DIR directories were missing
+    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
 fi
diff --git a/install-win32/makeservice b/install-win32/makeservice
deleted file mode 100644 (file)
index 647e178..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-#!/bin/sh
-
-# get version.nsi definitions
-. autodefs/defs.sh
-
-# build OpenVPN service (openvpnserv.exe)
-if [ -d "$SVC_TEMPLATE" ] ; then
-    # silly vista security theatre
-    PATCH="/tmp/p.exe"
-    cp `which patch` $PATCH
-
-    # build service sources
-    cp $SVC_TEMPLATE/service.[ch] service-win32
-    cd service-win32
-    cp service.c service.c.orig
-    cp service.h service.h.orig
-    $PATCH <service.patch
-
-    # compile/link
-    [ "$CLEAN" = "yes" ] && make clean
-    make -j $MAKE_JOBS
-    cd ..
-
-    # copy service to GENOUT/bin
-    mkdir $GENOUT/bin &>/dev/null
-    cp service-win32/${PRODUCT_UNIX_NAME}serv.exe $GENOUT/bin
-    if [ -z "$NO_STRIP" ]; then
-       strip $GENOUT/bin/${PRODUCT_UNIX_NAME}serv.exe
-    fi
-else
-    echo OpenVPN service not built -- template directory $SVC_TEMPLATE NOT FOUND
-fi
index b6789eed666e9c7098361f6d0c8d2ffc40616f13..ecf7a2ca7d99c34e69a6959afb2ab94642531e49 100644 (file)
 
 # Include the OpenVPN XML-based GUI exe in the installer.
 # May be undefined.
-!define OPENVPN_XGUI_DIR "../ovpnxml"
+;!define OPENVPN_XGUI_DIR "../ovpnxml"
 
 # Prebuilt libraries.  DMALLOC is optional.
 !define OPENSSL_DIR      "../openssl-0.9.7m"
 !define LZO_DIR                  "../lzo-2.02"
-!define PKCS11_HELPER_DIR "../pkcs11-helper/usr/local"
+!define PKCS11_HELPER_DIR "../pkcs11-helper"
 !define DMALLOC_DIR      "../dmalloc-5.4.2"
 
 # Optional directory of prebuilt OpenVPN binary components,
 # Not needed if DRVBINSRC is defined.
 !define TISRC  "../tapinstall"
 
-# TAP Adapter parameters.
+# TAP Adapter parameters.  Note that PRODUCT_TAP_ID is
+# defined in version.m4.
 !define PRODUCT_TAP_DEVICE_DESCRIPTION  "TAP-Win32 Adapter V9"
 !define PRODUCT_TAP_PROVIDER            "TAP-Win32 Provider V9"
-!define PRODUCT_TAP_ID                 "tap0901"
 !define PRODUCT_TAP_MAJOR_VER           9
 !define PRODUCT_TAP_MINOR_VER           4
 !define PRODUCT_TAP_RELDATE             "01/22/2008"
 # Build debugging version of TAP driver
 ;!define PRODUCT_TAP_DEBUG
 
-# Service template files service.[ch] (get from Platform SDK).
-# If undefined, don't build openvpnserv.exe
-!define SVC_TEMPLATE "../svc-template"
-
 # DDK Version.
 # DDK distribution is assumed to be in C:\WINDDK\${DDKVER}
 !define DDKVER      6001.17121
index 7221e038ae1e02663c61b11379053717147b829b..d9aa1e9a150f5a84f7cd4788452d13ee185cddc8 100644 (file)
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#ifdef WIN32
-#include "config-win32.h"
-#else
-#include "config.h"
-#endif
-
 #include "syshead.h"
 
 #include "interval.h"
diff --git a/list.c b/list.c
index bdd16084afd24cf76e19cc741c95a8fa71bf9ce6..8849957a122c27a2e520b702fb7a5084c2399026 100644 (file)
--- a/list.c
+++ b/list.c
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#ifdef WIN32
-#include "config-win32.h"
-#else
-#include "config.h"
-#endif
-
 #include "syshead.h"
 
 #if P2MP_SERVER
index 1daa37992b5f793bc979cf7185993265158432b7..ad28dcf7effd3685d2d9abc64bbc1f75db2ac5af 100644 (file)
--- a/lladdr.c
+++ b/lladdr.c
@@ -2,12 +2,6 @@
  * Support routine for configuring link layer address 
  */
 
-#ifdef WIN32
-#include "config-win32.h"
-#else
-#include "config.h"
-#endif
-
 #include "syshead.h"
 #include "error.h"
 #include "misc.h"
diff --git a/lzo.c b/lzo.c
index c16e035cba0261be873ad61234168173f71a9571..536e21e5ef5676c056f642988f621bd89f77b3ab 100644 (file)
--- a/lzo.c
+++ b/lzo.c
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#ifdef WIN32
-#include "config-win32.h"
-#else
-#include "config.h"
-#endif
+#include "syshead.h"
 
 #ifdef USE_LZO
 
-#include "syshead.h"
-
 #include "lzo.h"
 #include "error.h"
 #include "otime.h"
diff --git a/makefile.w32 b/makefile.w32
deleted file mode 100755 (executable)
index 1623ec8..0000000
+++ /dev/null
@@ -1,204 +0,0 @@
-# This Makefile builds the user-mode component
-# of OpenVPN for WIN32 in the MinGW environment.
-#
-# Build Dependencies:
-#      mingw           (GNU C compiler for windows)
-#      msys            (GNU utilities and shell for windows)
-#      OpenSSL         (SSL/TLS/crypto library)
-#      LZO             (real-time compression library)
-#       Dmalloc         (debugging only)
-#
-# Targets:
-#      static -- link statically with OpenSSL
-#       dynamic -- link dynamically with OpenSSL
-#       dmalloc -- enable memory debugging using the dmalloc library 
-#
-# Note that LZO is always linked statically.
-#
-# To build openssl-0.9.7d, remember to edit ms\mw.bat
-# adding '--win32' flag to make command:
-#
-#   make --win32 -f ms/mingw32.mak
-#
-# Now cd to top level openssl directory in a Windows
-# command-prompt window, and type:
-#
-#   ms\mw
-#
-# See additional .bat scripts in install-win32 for OpenSSL
-# build setup.
-#
-# If you are building with dmalloc debugging support
-# see windbg.h for additional dmalloc notes.
-
-#########################################################
-# Change these to point to your OpenSSL, LZO, and
-# (optionally) dmalloc top-level directories.
-# Normally set as environmental variables before calling
-# make.
-#
-#OPENSSL_DIR = 
-#LZO_DIR = 
-#DMALLOC_DIR = 
-#PKCS11_HELPER_DIR =
-
-#########################################################
-
-CC = gcc -g -O2 -Wall -Wno-unused-function -Wno-unused-variable -mno-cygwin
-
-CC_DMALLOC = gcc -g -O2 -Wall -Wno-unused-function -Wno-unused-variable -mno-cygwin -fno-inline -DDMALLOC
-
-INCLUDE_DIRS = -I${OPENSSL_DIR}/include -I${LZO_DIR}/include -I${PKCS11_HELPER_DIR}/include
-
-INCLUDE_DIRS_DMALLOC = ${INCLUDE_DIRS} -I${DMALLOC_DIR}
-
-LIBS = -llzo2 -lcrypt32 -lWinInet -lws2_32 -lgdi32 -liphlpapi -lwinmm -lpkcs11-helper
-
-LIBS_DMALLOC = ${LIBS} -ldmalloc
-
-LIB_DIRS = -L${OPENSSL_DIR}/out -L${LZO_DIR} -L${PKCS11_HELPER_DIR}/lib
-
-LIB_DIRS_DMALLOC = ${LIB_DIRS} -L${DMALLOC_DIR}
-
-EXE = ${PRODUCT_UNIX_NAME}.exe
-
-HEADERS = \
-       base64.h \
-       basic.h \
-       buffer.h \
-       circ_list.h \
-       common.h \
-       tap-win32/common.h \
-        config-win32.h \
-       crypto.h \
-       cryptoapi.h \
-       errlevel.h \
-       error.h \
-       event.h \
-        fdmisc.h \
-       forward-inline.h \
-       forward.h \
-       fragment.h \
-        gremlin.h \
-       helper.h \
-       init.h \
-       integer.h \
-       interval.h \
-       list.h \
-       lladdr.h \
-       lzo.h \
-       manage.h \
-       mbuf.h \
-       memdbg.h \
-       misc.h \
-       mroute.h \
-       mss.h \
-       mtcp.h \
-       mtu.h \
-       mudp.h \
-       multi.h \
-       ntlm.h \
-       occ-inline.h \
-       occ.h \
-       pkcs11.h \
-        openvpn.h \
-       openvpn-plugin.h \
-       options.h \
-       otime.h \
-       packet_id.h \
-       perf.h \
-       ping-inline.h \
-       ping.h \
-       plugin.h \
-       pool.h \
-        proto.h \
-       proxy.h \
-       push.h \
-       reliable.h \
-       route.h \
-       schedule.h \
-       session_id.h \
-        shaper.h \
-       sig.h \
-       socket.h \
-       socks.h \
-       ssl.h \
-        status.h \
-       syshead.h \
-        thread.h \
-       tun.h \
-       win32.h
-
-OBJS =  base64.o \
-       buffer.o \
-       crypto.o \
-       cryptoapi.o \
-       error.o \
-       event.o \
-       fdmisc.o \
-       forward.o \
-        fragment.o \
-       gremlin.o \
-       helper.o \
-       init.o \
-       interval.o \
-        list.o \
-       lladdr.o \
-       lzo.o \
-       manage.o \
-       mbuf.o \
-       misc.o \
-       mroute.o \
-       mss.o \
-       mtcp.o \
-       mtu.o \
-       mudp.o \
-       multi.o \
-       ntlm.o \
-       occ.o \
-       pkcs11.o \
-        openvpn.o \
-       options.o \
-       otime.o \
-       packet_id.o \
-       perf.o \
-       ping.o \
-       plugin.o \
-        pool.o \
-       proto.o \
-       proxy.o \
-       push.o \
-       reliable.o \
-        route.o \
-       schedule.o \
-       session_id.o \
-       shaper.o \
-       sig.o \
-       socket.o \
-        socks.o \
-       ssl.o \
-       status.o \
-       thread.o \
-       tun.o \
-       win32.o
-
-dynamic : MY_CC = ${CC}
-dynamic : MY_INCLUDE_DIRS = ${INCLUDE_DIRS}
-dynamic : ${OBJS}
-       ${MY_CC} -o ${EXE} ${OBJS} ${LIB_DIRS} -lssl32 -leay32 ${LIBS}
-
-static : MY_CC = ${CC}
-static : MY_INCLUDE_DIRS = ${INCLUDE_DIRS}
-static : ${OBJS}
-       ${CC} -o ${EXE} ${OBJS} ${LIB_DIRS} -lssl -lcrypto ${LIBS}
-
-dmalloc : MY_CC = ${CC_DMALLOC}
-dmalloc : MY_INCLUDE_DIRS = ${INCLUDE_DIRS_DMALLOC}
-dmalloc : ${OBJS}
-       ${MY_CC} -o ${EXE} ${OBJS} ${LIB_DIRS_DMALLOC} -lssl32 -leay32 ${LIBS_DMALLOC}
-
-clean :
-       rm -f ${OBJS} ${EXE}
-
-%.o : %.c ${HEADERS}
-       ${MY_CC} ${MY_INCLUDE_DIRS} -c $< -o $@
index 558b01bd2826503f6211d6d42f492e8e4c1863d1..090f691cccc06fbc63cb348695279f1406ddc452 100644 (file)
--- a/manage.c
+++ b/manage.c
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#ifdef WIN32
-#include "config-win32.h"
-#else
-#include "config.h"
-#endif
-
 #include "syshead.h"
 
 #ifdef ENABLE_MANAGEMENT
 
 #include "memdbg.h"
 
+#ifdef ENABLE_PKCS11
+#include "pkcs11.h"
+#endif
+
 #define MANAGEMENT_ECHO_PULL_INFO 0
 
 #if MANAGEMENT_ECHO_PULL_INFO
@@ -82,8 +80,14 @@ man_help ()
   msg (M_CLIENT, "mute [n]               : Set log mute level to n, or show level if n is absent.");
   msg (M_CLIENT, "needok type action     : Enter confirmation for NEED-OK request of 'type',");
   msg (M_CLIENT, "                         where action = 'ok' or 'cancel'.");
+  msg (M_CLIENT, "needstr type action    : Enter confirmation for NEED-STR request of 'type',");
+  msg (M_CLIENT, "                         where action is reply string.");
   msg (M_CLIENT, "net                    : (Windows only) Show network info and routing table.");
   msg (M_CLIENT, "password type p        : Enter password p for a queried OpenVPN password.");
+#ifdef ENABLE_PKCS11
+  msg (M_CLIENT, "pkcs11-id-count        : Get number of available PKCS#11 identities.");
+  msg (M_CLIENT, "pkcs11-id-get index    : Get PKCS#11 identity at index.");
+#endif
   msg (M_CLIENT, "signal s               : Send signal s to daemon,");
   msg (M_CLIENT, "                         s = SIGHUP|SIGTERM|SIGUSR1|SIGUSR2.");
   msg (M_CLIENT, "state [on|off] [N|all] : Like log, but show state history.");
@@ -541,6 +545,10 @@ man_up_finalize (struct management *man)
       if (strlen (man->connection.up_query.password))
        man->connection.up_query.defined = true;
       break;
+    case UP_QUERY_NEED_STR:
+      if (strlen (man->connection.up_query.password))
+       man->connection.up_query.defined = true;
+      break;
     default:
       ASSERT (0);
     }
@@ -603,6 +611,13 @@ man_query_need_ok (struct management *man, const char *type, const char *action)
   man_query_user_pass (man, type, action, needed, "needok-confirmation", man->connection.up_query.password, USER_PASS_LEN);
 }
 
+static void
+man_query_need_str (struct management *man, const char *type, const char *action)
+{
+  const bool needed = ((man->connection.up_query_mode == UP_QUERY_NEED_STR) && man->connection.up_query_type);
+  man_query_user_pass (man, type, action, needed, "needstr-string", man->connection.up_query.password, USER_PASS_LEN);
+}
+
 static void
 man_forget_passwords (struct management *man)
 {
@@ -623,6 +638,33 @@ man_net (struct management *man)
     }
 }
 
+#ifdef ENABLE_PKCS11
+
+static void
+man_pkcs11_id_count (struct management *man)
+{
+  msg (M_CLIENT, ">PKCS11ID-COUNT:%d", pkcs11_management_id_count ());
+}
+
+static void
+man_pkcs11_id_get (struct management *man, const int index)
+{
+  char *id = NULL;
+  char *base64 = NULL;
+
+  if (pkcs11_management_id_get (index, &id, &base64))
+    msg (M_CLIENT, ">PKCS11ID-ENTRY:'%d', ID:'%s', BLOB:'%s'", index, id, base64);
+  else
+    msg (M_CLIENT, ">PKCS11ID-ENTRY:'%d'", index);
+
+  if (id != NULL)
+    free (id);
+  if (base64 != NULL)
+    free (base64);
+}
+
+#endif
+
 static void
 man_hold (struct management *man, const char *cmd)
 {
@@ -807,6 +849,11 @@ man_dispatch_command (struct management *man, struct status_output *so, const ch
       if (man_need (man, p, 2, 0))
        man_query_need_ok (man, p[1], p[2]);
     }
+  else if (streq (p[0], "needstr"))
+    {
+      if (man_need (man, p, 2, 0))
+       man_query_need_str (man, p[1], p[2]);
+    }
   else if (streq (p[0], "net"))
     {
       man_net (man);
@@ -820,6 +867,17 @@ man_dispatch_command (struct management *man, struct status_output *so, const ch
       if (man_need (man, p, 1, 0))
        man_bytecount (man, atoi(p[1]));
     }
+#ifdef ENABLE_PKCS11
+  else if (streq (p[0], "pkcs11-id-count"))
+    {
+      man_pkcs11_id_count (man);
+    }
+  else if (streq (p[0], "pkcs11-id-get"))
+    {
+      if (man_need (man, p, 1, 0))
+       man_pkcs11_id_get (man, atoi(p[1]));
+    }
+#endif
 #if 1
   else if (streq (p[0], "test"))
     {
@@ -2037,6 +2095,12 @@ management_query_user_pass (struct management *man,
          prefix= "NEED-OK";
          alert_type = "confirmation";
        }
+      else if (flags & GET_USER_PASS_NEED_STR)
+        {
+         up_query_mode = UP_QUERY_NEED_STR;
+         prefix= "NEED-STR";
+         alert_type = "string";
+       }
       else if (flags & GET_USER_PASS_PASSWORD_ONLY)
        {
          up_query_mode = UP_QUERY_PASS;
@@ -2054,7 +2118,7 @@ management_query_user_pass (struct management *man,
                  type,
                  alert_type);
 
-      if (flags & GET_USER_PASS_NEED_OK)
+      if (flags & (GET_USER_PASS_NEED_OK | GET_USER_PASS_NEED_STR))
        buf_printf (&alert_msg, " MSG:%s", up->username);
 
       man_wait_for_client_connection (man, &signal_received, 0, MWCC_PASSWORD_WAIT);
index 9150fb1eee0baa9040582da48327fa1eea078176..fed14b79642bc83e3ac4b10f7495e9ed1ea26ef4 100644 (file)
--- a/manage.h
+++ b/manage.h
@@ -222,6 +222,7 @@ struct man_settings {
 #define UP_QUERY_USER_PASS 1
 #define UP_QUERY_PASS      2
 #define UP_QUERY_NEED_OK   3
+#define UP_QUERY_NEED_STR  4
 
 /* states */
 #define MS_INITIAL          0  /* all sockets are closed */
index dcbc7ced9d4d89265b17b12959b2ae3dab94d34b..73f82a51b2b297f8d23ce2711adb9023b19b6807 100644 (file)
@@ -382,7 +382,7 @@ Command examples:
                          Query for new input and retry.
 
 COMMAND -- needok  (OpenVPN 2.1 or higher)
---------------------------------------
+------------------------------------------
 
 Confirm a ">NEED-OK" real-time notification, normally used by
 OpenVPN to block while waiting for a specific user action.
@@ -403,6 +403,47 @@ Example:
   or
      needok token-insertion-request cancel
 
+COMMAND -- needstr  (OpenVPN 2.1 or higher)
+-------------------------------------------
+
+Confirm a ">NEED-STR" real-time notification, normally used by
+OpenVPN to block while waiting for a specific user input.
+
+Example:
+
+  OpenVPN needs the user to specify some input, so it sends a
+  real-time notification:
+
+    >NEED-STR:Need 'name' input MSG:Please specify your name
+
+  The management client, if it is a GUI, can flash a dialog
+  box containing the text after the "MSG:" marker to the user.
+  When the user acknowledges the dialog box,
+  the management client can issue this command:
+
+     needstr name "John"
+
+COMMAND -- pkcs11-id-count  (OpenVPN 2.1 or higher)
+---------------------------------------------------
+
+Retrieve available number of certificates.
+
+Example:
+
+     pkcs11-id-count
+     >PKCS11ID-COUNT:5
+
+COMMAND -- pkcs11-id-get  (OpenVPN 2.1 or higher)
+-------------------------------------------------
+
+Retrieve certificate by index, the ID string should be provided
+as PKCS#11 identity, the blob is BASE64 encoded certificate.
+
+Example:
+
+     pkcs11-id-get 1
+     PKCS11ID-ENTRY:'1', ID:'<snip>', BLOB:'<snip>'
+
 OUTPUT FORMAT
 -------------
 
@@ -445,6 +486,10 @@ NEED-OK  -- OpenVPN needs the end user to do something, such as
             insert a cryptographic token.  The "needok" command can
             be used to tell OpenVPN to continue.
 
+NEED-STR -- OpenVPN needs information from end, such as
+            a certificate to use.  The "needstr" command can
+            be used to tell OpenVPN to continue.
+
 PASSWORD -- Used to tell the management client that OpenVPN
             needs a password, also to indicate password
             verification failure.
@@ -460,11 +505,11 @@ as is used by the OpenVPN config file parser.
 
 Whitespace is a parameter separator.
 
-Double  quotation characters ("") can be used to enclose
-parameters containing whitespace.
+Double quotation or single quotation characters ("", '') can be used
+to enclose parameters containing whitespace.
 
 Backslash-based shell escaping is performed, using the following
-mappings:
+mappings, when not in single quotations:
 
 \\       Maps to a single backslash character (\).
 \"       Pass a literal doublequote character ("), don't
diff --git a/mbuf.c b/mbuf.c
index 871bdbabf87a15c2a0c68049f76828a406b2c536..ac348ab9ff79896bff1a3e4b79a79f6ed2e7c0f7 100644 (file)
--- a/mbuf.c
+++ b/mbuf.c
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#ifdef WIN32
-#include "config-win32.h"
-#else
-#include "config.h"
-#endif
-
 #include "syshead.h"
 
 #if P2MP
diff --git a/misc.c b/misc.c
index 2821408a4433933af86b727f508bf57809436b1d..f4edefa34d4cec6da0957d0aac573c16ba193537 100644 (file)
--- a/misc.c
+++ b/misc.c
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#ifdef WIN32
-#include "config-win32.h"
-#else
-#include "config.h"
-#endif
-
 #include "syshead.h"
 
 #include "buffer.h"
@@ -206,7 +200,7 @@ run_up_down (const char *command,
       ASSERT (arg);
 
       buf_printf (&cmd,
-                 "%s %d %d %s %s %s",
+                 "\"%s\" %d %d %s %s %s",
                  arg,
                  tun_mtu, link_mtu,
                  ifconfig_local, ifconfig_remote,
@@ -225,7 +219,7 @@ run_up_down (const char *command,
       setenv_str (es, "script_type", script_type);
 
       buf_printf (&cmd,
-                 "%s %s %d %d %s %s %s",
+                 "%s \"%s\" %d %d %s %s %s",
                  command,
                  arg,
                  tun_mtu, link_mtu,
@@ -438,6 +432,7 @@ openvpn_system (const char *command, const struct env_set *es, unsigned int flag
 void
 warn_if_group_others_accessible (const char* filename)
 {
+#ifndef WIN32
 #ifdef HAVE_STAT
 #if ENABLE_INLINE_FILES
   if (strcmp (filename, INLINE_FILE_TAG))
@@ -455,6 +450,7 @@ warn_if_group_others_accessible (const char* filename)
        }
     }
 #endif
+#endif
 }
 
 /*
@@ -1230,7 +1226,7 @@ get_user_pass (struct user_pass *up,
              if ((flags & GET_USER_PASS_NOFATAL) != 0)
                return false;
              else
-               msg (M_FATAL, "ERROR: could not read %s username/password/ok from management interface", prefix);
+               msg (M_FATAL, "ERROR: could not read %s username/password/ok/string from management interface", prefix);
            }
        }
       else
diff --git a/misc.h b/misc.h
index 5b7f227cb029e9e82aa91186311ca62fc72650fe..f01695fb1059dd8a076cdca7bca7d58e1eec2d93 100644 (file)
--- a/misc.h
+++ b/misc.h
@@ -227,7 +227,11 @@ struct user_pass
   bool nocache;
 
 /* max length of username/password */
-# define USER_PASS_LEN 128
+# ifdef ENABLE_PKCS11
+#   define USER_PASS_LEN 4096
+# else
+#   define USER_PASS_LEN 128
+# endif
   char username[USER_PASS_LEN];
   char password[USER_PASS_LEN];
 };
@@ -242,6 +246,7 @@ bool get_console_input (const char *prompt, const bool echo, char *input, const
 #define GET_USER_PASS_PASSWORD_ONLY (1<<2)
 #define GET_USER_PASS_NEED_OK       (1<<3)
 #define GET_USER_PASS_NOFATAL       (1<<4)
+#define GET_USER_PASS_NEED_STR      (1<<5)
 
 bool get_user_pass (struct user_pass *up,
                    const char *auth_file,
index a7d1215bae65f364db82347f094aa23226cdd3b3..5922b8a783290dffb0f780659dc9dee9fab6f127 100644 (file)
--- a/mroute.c
+++ b/mroute.c
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#ifdef WIN32
-#include "config-win32.h"
-#else
-#include "config.h"
-#endif
-
 #include "syshead.h"
 
 #if P2MP_SERVER
diff --git a/mss.c b/mss.c
index 25e77b0512f31274b4be07829a4b407203344b5b..deaa02e853fd9b90be0325a42777cc93f093e879 100644 (file)
--- a/mss.c
+++ b/mss.c
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#ifdef WIN32
-#include "config-win32.h"
-#else
-#include "config.h"
-#endif
-
 #include "syshead.h"
 #include "error.h"
 #include "mss.h"
diff --git a/mtcp.c b/mtcp.c
index 6ec99740aca66943335ea5fb74c65246c8a2808f..555b1e8a7fa49fbe620cb305f13e393af83c0644 100644 (file)
--- a/mtcp.c
+++ b/mtcp.c
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#ifdef WIN32
-#include "config-win32.h"
-#else
-#include "config.h"
-#endif
-
 #include "syshead.h"
 
 #if P2MP_SERVER
diff --git a/mtu.c b/mtu.c
index 14df3b675e1bb2ac916f547dd6ee1868b1ca7ab7..1b93bf0d190035b3b0a0ac74c66377b454ca9838 100644 (file)
--- a/mtu.c
+++ b/mtu.c
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#ifdef WIN32
-#include "config-win32.h"
-#else
-#include "config.h"
-#endif
-
 #include "syshead.h"
 
 #include "common.h"
diff --git a/mudp.c b/mudp.c
index fa2ae17c5e097fbe05d65c08f4aa526aff98236a..a430d60870ed47393de835b97b54588d5d9a42dc 100644 (file)
--- a/mudp.c
+++ b/mudp.c
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#ifdef WIN32
-#include "config-win32.h"
-#else
-#include "config.h"
-#endif
-
 #include "syshead.h"
 
 #if P2MP_SERVER
diff --git a/multi.c b/multi.c
index fa924f1bdf853aa91967a6ac57878f37379a9f26..2a74cdaec43ef97fe84b23935db4f264b98f6b79 100644 (file)
--- a/multi.c
+++ b/multi.c
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#ifdef WIN32
-#include "config-win32.h"
-#else
-#include "config.h"
-#endif
-
 #include "syshead.h"
 
 #if P2MP_SERVER
diff --git a/ntlm.c b/ntlm.c
index 4e12047a87585785b9ab1adbb3beb9826bc72511..ff4e2f5e0b1e441fb43cf9412d37be439ab7b427 100644 (file)
--- a/ntlm.c
+++ b/ntlm.c
@@ -3,6 +3,8 @@
  *
  *  Copyright (C) 2004 William Preston
  *
+ *  *NTLMv2 support and domain name parsing by Miroslav Zajic, Nextsoft s.r.o.*
+ *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
  *  the Free Software Foundation; either version 2 of the License, or
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#ifdef WIN32
-#include "config-win32.h"
-#else
-#include "config.h"
-#endif
-
 #include "syshead.h"
 
 #if NTLM
 
 #include "memdbg.h"
 
+
+/* 64bit datatype macros */
+#ifdef _MSC_VER 
+       /* MS compilers */
+#      define UINTEGER64 __int64
+#      define UINT64(c) c ## Ui64
+#else 
+       /* Non MS compilers */
+#      define UINTEGER64 unsigned long long
+#      define UINT64(c) c ## LL
+#endif
+
+
+
+
 static void
 create_des_keys(const unsigned char *hash, unsigned char *key)
 {
@@ -70,6 +81,61 @@ gen_md4_hash (const char* data, int data_len, char *result)
   memcpy (result, md, 16);
 }
 
+static void
+gen_hmac_md5 (const char* data, int data_len, const char* key, int key_len,char *result)
+{
+       unsigned int len;
+
+       HMAC_CTX c;
+       HMAC_Init (&c, key, key_len, EVP_md5());
+       HMAC_Update (&c, data, data_len);
+       HMAC_Final (&c, result, &len);
+       HMAC_CTX_cleanup(&c);
+}
+
+static void
+gen_timestamp (unsigned char *timestamp)
+{ 
+       /* Copies 8 bytes long timestamp into "timestamp" buffer. 
+        * Timestamp is Little-endian, 64-bit signed value representing the number of tenths of a microsecond since January 1, 1601.
+        */
+
+       UINTEGER64 timestamp_ull;
+
+       timestamp_ull = openvpn_time(NULL);
+       timestamp_ull = (timestamp_ull + UINT64(11644473600)) * UINT64(10000000);
+
+       /* store little endian value */
+       timestamp[0]= timestamp_ull & UINT64(0xFF);
+       timestamp[1]= (timestamp_ull  >> 8)  & UINT64(0xFF);
+       timestamp[2]= (timestamp_ull  >> 16) & UINT64(0xFF);
+       timestamp[3]= (timestamp_ull  >> 24) & UINT64(0xFF);
+       timestamp[4]= (timestamp_ull  >> 32) & UINT64(0xFF);
+       timestamp[5]= (timestamp_ull  >> 40) & UINT64(0xFF);
+       timestamp[6]= (timestamp_ull  >> 48) & UINT64(0xFF);
+       timestamp[7]= (timestamp_ull  >> 56) & UINT64(0xFF);
+}
+
+static void
+gen_nonce (unsigned char *nonce)
+{ 
+       /* Generates 8 random bytes to be used as client nonce */
+       int i;
+
+       for(i=0;i<8;i++){
+               nonce[i] = (unsigned char)get_random();
+       }
+}
+
+unsigned char *my_strupr(unsigned char *str)
+{ 
+       /* converts string to uppercase in place */
+       unsigned char *tmp = str;;
+
+       do *str = toupper(*str); while (*(++str));
+       return tmp;
+}
+
 static int
 unicodize (char *dst, const char *src)
 {
@@ -85,6 +151,18 @@ unicodize (char *dst, const char *src)
   return i;
 }
 
+static void
+add_security_buffer(int sb_offset, void *data, int length, unsigned char *msg_buf, int *msg_bufpos)
+{
+       /* Adds security buffer data to a message and sets security buffer's offset and length */
+       msg_buf[sb_offset] = (unsigned char)length;
+       msg_buf[sb_offset + 2] = msg_buf[sb_offset];
+       msg_buf[sb_offset + 4] = (unsigned char)(*msg_bufpos & 0xff);
+       msg_buf[sb_offset + 5] = (unsigned char)((*msg_bufpos >> 8) & 0xff);
+       memcpy(&msg_buf[*msg_bufpos], data, msg_buf[sb_offset]);
+       *msg_bufpos += length;
+}
+
 const char *
 ntlm_phase_1 (const struct http_proxy_info *p, struct gc_arena *gc)
 {
@@ -105,23 +183,56 @@ ntlm_phase_1 (const struct http_proxy_info *p, struct gc_arena *gc)
 const char *
 ntlm_phase_3 (const struct http_proxy_info *p, const char *phase_2, struct gc_arena *gc)
 {
+       /* NTLM handshake
+        *
+        * http://davenport.sourceforge.net/ntlm.html
+        *
+        */
+       
   char pwbuf[sizeof (p->up.password) * 2]; /* for unicode password */
   char buf2[128]; /* decoded reply from proxy */
-  char phase3[146];
+  unsigned char phase3[464];
 
   char md4_hash[21];
-  char challenge[8], response[24];
-  int i, ret_val, buflen;
+  char challenge[8], ntlm_response[24];
+  int i, ret_val;
   des_cblock key1, key2, key3;
   des_key_schedule sched1, sched2, sched3;
 
-  /* try a minimal NTLM handshake
-   *
-   * http://davenport.sourceforge.net/ntlm.html
-   *
-   */
+       char ntlmv2_response[144];
+       char userdomain_u[256]; /* for uppercase unicode username and domain */
+       char userdomain[128];   /* the same as previous but ascii */
+       char ntlmv2_hash[16];
+       char ntlmv2_hmacmd5[16];
+       char *ntlmv2_blob = ntlmv2_response + 16; /* inside ntlmv2_response, length: 128 */
+       int ntlmv2_blob_size=0;
+       int phase3_bufpos = 0x40; /* offset to next security buffer data to be added */
+       int len;
+
+       char domain[128];
+       char username[128];
+       char *separator;
+
+       bool ntlmv2_enabled = (p->auth_method == HTTP_AUTH_NTLM2);
+
   ASSERT (strlen (p->up.username) > 0);
   ASSERT (strlen (p->up.password) > 0);
+       
+       /* username parsing */
+       separator = strchr(p->up.username, '\\');
+       if (separator == NULL) {
+               strncpy(username, p->up.username, sizeof(username)-1);
+               username[sizeof(username)-1]=0;
+               domain[0]=0;
+       } else {
+               strncpy(username, separator+1, sizeof(username)-1);
+               username[sizeof(username)-1]=0;
+               len = separator - p->up.username;
+               if (len > sizeof(domain) - 1) len = sizeof(domain) - 1;
+               strncpy(domain, p->up.username,  len);
+               domain[len]=0;
+       }
+
 
   /* fill 1st 16 bytes with md4 hash, disregard terminating null */
   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
     challenge[i] = buf2[i+24];
   }
 
-  create_des_keys ((unsigned char *)md4_hash, key1);
-  des_set_key_unchecked ((des_cblock *)key1, sched1);
-  des_ecb_encrypt ((des_cblock *)challenge, (des_cblock *)response, sched1, DES_ENCRYPT);
-
-  create_des_keys ((unsigned char *)&(md4_hash[7]), key2);
-  des_set_key_unchecked ((des_cblock *)key2, sched2);
-  des_ecb_encrypt ((des_cblock *)challenge, (des_cblock *)&(response[8]), sched2, DES_ENCRYPT);
-
-  create_des_keys ((unsigned char *)&(md4_hash[14]), key3);
-  des_set_key_unchecked ((des_cblock *)key3, sched3);
-  des_ecb_encrypt ((des_cblock *)challenge, (des_cblock *)&(response[16]), sched3, DES_ENCRYPT);
-
-  /* clear reply */
-  memset (phase3, 0, sizeof (phase3));
-
-  strcpy (phase3, "NTLMSSP\0");
-  phase3[8] = 3; /* type 3 */
-
-  buflen = 0x58 + strlen (p->up.username);
-  if (buflen > (int) sizeof (phase3))
-    buflen = sizeof (phase3);
-
-  phase3[0x10] = buflen; /* lm not used */
-  phase3[0x20] = buflen; /* default domain (i.e. proxy's domain) */
-  phase3[0x30] = buflen; /* no workstation name supplied */
-  phase3[0x38] = buflen; /* no session key */
-
-  phase3[0x14] = 24; /* ntlm response is 24 bytes long */
-  phase3[0x16] = phase3[0x14];
-  phase3[0x18] = 0x40; /* ntlm offset */
-  memcpy (&(phase3[0x40]), response, 24);
-
-
-  phase3[0x24] = strlen (p->up.username); /* username in ascii */
-  phase3[0x26] = phase3[0x24];
-  phase3[0x28] = 0x58;
-  strncpy (&(phase3[0x58]), p->up.username, sizeof (phase3) - 0x58);
-
+       if (ntlmv2_enabled){ /* Generate NTLMv2 response */
+               
+               /* NTLMv2 hash */
+               my_strupr(strcpy(userdomain, username));
+               if (strlen(username) + strlen(domain) < sizeof(userdomain))
+                       strcat(userdomain, domain);
+               else
+                       msg (M_INFO, "Warning: Username or domain too long");
+               unicodize (userdomain_u, userdomain);
+               gen_hmac_md5(userdomain_u, 2 * strlen(userdomain), md4_hash, 16, ntlmv2_hash);
+
+               /* NTLMv2 Blob */
+               memset(ntlmv2_blob, 0, 128);                /* Clear blob buffer */ 
+               ntlmv2_blob[0x00]=1;                        /* Signature */
+               ntlmv2_blob[0x01]=1;                        /* Signature */
+               ntlmv2_blob[0x04]=0;                        /* Reserved */
+               gen_timestamp(&ntlmv2_blob[0x08]);          /* 64-bit Timestamp */
+               gen_nonce(&ntlmv2_blob[0x10]);              /* 64-bit Client Nonce */
+               ntlmv2_blob[0x18]=0;                        /* Unknown, zero should work */
+
+               /* Add target information block to the blob */
+               int tib_len;
+               if (( *((long *)&buf2[0x14]) & 0x00800000) == 0x00800000){ /* Check for Target Information block */
+                       tib_len = buf2[0x28];/* Get Target Information block size */
+                       if (tib_len > 96) tib_len = 96;
+                       char *tib_ptr = buf2 + buf2[0x2c]; /* Get Target Information block pointer */
+                       memcpy(&ntlmv2_blob[0x1c], tib_ptr, tib_len); /* Copy Target Information block into the blob */
+               } else {
+                       tib_len = 0;
+               }
+
+               ntlmv2_blob[0x1c + tib_len] = 0;            /* Unknown, zero works */ 
+
+               /* Get blob length */
+               ntlmv2_blob_size = 0x20 + tib_len; 
+
+               /* Add challenge from message 2 */
+               memcpy(&ntlmv2_response[8], challenge, 8);
+
+               /* hmac-md5 */
+               gen_hmac_md5(&ntlmv2_response[8], ntlmv2_blob_size + 8, ntlmv2_hash, 16, ntlmv2_hmacmd5);
+               
+               /* Add hmac-md5 result to the blob */
+               memcpy(ntlmv2_response, ntlmv2_hmacmd5, 16); /* Note: This overwrites challenge previously written at ntlmv2_response[8..15] */
+       
+       } else { /* Generate NTLM response */
+
+               create_des_keys ((unsigned char *)md4_hash, key1);
+               des_set_key_unchecked ((des_cblock *)key1, sched1);
+               des_ecb_encrypt ((des_cblock *)challenge, (des_cblock *)ntlm_response, sched1, DES_ENCRYPT);
+
+               create_des_keys ((unsigned char *)&(md4_hash[7]), key2);
+               des_set_key_unchecked ((des_cblock *)key2, sched2);
+               des_ecb_encrypt ((des_cblock *)challenge, (des_cblock *)&(ntlm_response[8]), sched2, DES_ENCRYPT);
+
+               create_des_keys ((unsigned char *)&(md4_hash[14]), key3);
+               des_set_key_unchecked ((des_cblock *)key3, sched3);
+               des_ecb_encrypt ((des_cblock *)challenge, (des_cblock *)&(ntlm_response[16]), sched3, DES_ENCRYPT);
+       }
+       
+       
+       memset (phase3, 0, sizeof (phase3)); /* clear reply */
+
+       strcpy (phase3, "NTLMSSP\0"); /* signature */
+       phase3[8] = 3; /* type 3 */
+
+       if (ntlmv2_enabled){ /* NTLMv2 response */
+               add_security_buffer(0x14, ntlmv2_response, ntlmv2_blob_size + 16, phase3, &phase3_bufpos);
+       }else{ /* NTLM response */
+               add_security_buffer(0x14, ntlm_response, 24, phase3, &phase3_bufpos);
+       }
+       
+       /* username in ascii */
+       add_security_buffer(0x24, username, strlen (username), phase3, &phase3_bufpos);
+
+       /* Set domain. If <domain> is empty, default domain will be used (i.e. proxy's domain) */ 
+       add_security_buffer(0x1c, domain, strlen (domain), phase3, &phase3_bufpos);
+       
+
+       /* other security buffers will be empty */
+       phase3[0x10] = phase3_bufpos; /* lm not used */
+       phase3[0x30] = phase3_bufpos; /* no workstation name supplied */
+       phase3[0x38] = phase3_bufpos; /* no session key */
+       
+       /* flags */
   phase3[0x3c] = 0x02; /* negotiate oem */
   phase3[0x3d] = 0x02; /* negotiate ntlm */
 
-  return ((const char *)make_base64_string2 ((unsigned char *)phase3, buflen, gc));
+  return ((const char *)make_base64_string2 ((unsigned char *)phase3, phase3_bufpos, gc));
 }
 
 #else
diff --git a/occ.c b/occ.c
index 6b136dc331dc65839eb243a47e8ab33db044d4a8..1add9d0f07c1904302fdef6a2bdd595761a15210 100644 (file)
--- a/occ.c
+++ b/occ.c
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#ifdef WIN32
-#include "config-win32.h"
-#else
-#include "config.h"
-#endif
-
 #include "syshead.h"
 
 #ifdef ENABLE_OCC
index cf818b3f62dabc1b945576efe1d4caccda5a675e..8a239f9fccf2d048c188d897abed65a644caa8cf 100644 (file)
--- a/openvpn.8
+++ b/openvpn.8
@@ -213,6 +213,7 @@ openvpn \- secure IP tunnel daemon.
 [\ \fB\-\-ping\fR\ \fIn\fR\ ]
 [\ \fB\-\-pkcs11\-cert\-private\fR\ \fI[0|1]...\fR\ ]
 [\ \fB\-\-pkcs11\-id\fR\ \fIname\fR\ ]
+[\ \fB\-\-pkcs11\-id\-management\fR\ ]
 [\ \fB\-\-pkcs11\-pin\-cache\fR\ \fIseconds\fR\ ]
 [\ \fB\-\-pkcs11\-private\-mode\fR\ \fImode...\fR\ ]
 [\ \fB\-\-pkcs11\-protected\-authentication\fR\ \fI[0|1]...\fR\ ]
@@ -3691,6 +3692,13 @@ by the standalone
 option.
 .\"*********************************************************
 .TP
+.B --pkcs11-id-management
+Acquire PKCS#11 id from management interface. In this case a NEED-STR 'pkcs11-id-request'
+real-time message will be triggered, application may use pkcs11-id-count command to
+retrieve available number of certificates, and pkcs11-id-get command to retrieve certificate
+id and certificate body.
+.\"*********************************************************
+.TP
 .B --pkcs11-pin-cache seconds
 Specify how many seconds the PIN can be cached, the default is until the token is removed.
 .\"*********************************************************
index 66ade224cfea3c30e394ae424ee5fc919a1567f7..d3c36f96c4404a456507925310fd2ca0fe0e4a5a 100644 (file)
--- a/openvpn.c
+++ b/openvpn.c
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#ifdef WIN32
-#include "config-win32.h"
-#else
-#include "config.h"
-#endif
-
 #include "syshead.h"
 
 #include "init.h"
index 944c84f88ba825931f1d3b76ad435225bcc4ddb4..1acfd6b5b13ad43f0acc6bf0e0e021c5798a700c 100644 (file)
--- a/options.c
+++ b/options.c
  *   (Christof Meerwald, http://cmeerw.org)
  */
 
-#ifdef WIN32
-#include "config-win32.h"
-#else
-#include "config.h"
-#endif
-
 #include "syshead.h"
 
 #include "buffer.h"
@@ -516,10 +510,11 @@ static const char usage_message[] =
   "                              4       : Use Decrypt.\n"
   "                              8       : Use Unwrap.\n"
   "--pkcs11-cert-private [0|1] ... : Set if login should be performed before\n"
-  "                              certificate can be accessed. Set for each provider.\n"
-  "--pkcs11-pin-cache seconds  : Number of seconds to cache PIN. The default is -1\n"
-  "                              cache until token is removed.\n"
-  "--pkcs11-id serialized-id   : Identity to use, get using standalone --show-pkcs11-ids\n"
+  "                                  certificate can be accessed. Set for each provider.\n"
+  "--pkcs11-pin-cache seconds      : Number of seconds to cache PIN. The default is -1\n"
+  "                                  cache until token is removed.\n"
+  "--pkcs11-id-management          : Acquire identity from management interface.\n"
+  "--pkcs11-id serialized-id 'id'  : Identity to use, get using standalone --show-pkcs11-ids\n"
 #endif                 /* ENABLE_PKCS11 */
  "\n"
   "SSL Library information:\n"
@@ -1293,6 +1288,7 @@ show_settings (const struct options *o)
   }
   SHOW_INT (pkcs11_pin_cache_period);
   SHOW_STR (pkcs11_id);
+  SHOW_BOOL (pkcs11_id_management);
 #endif                 /* ENABLE_PKCS11 */
 
 #if P2MP
@@ -1766,8 +1762,11 @@ options_postprocess (struct options *options, bool first_time)
       if (options->pkcs11_providers[0])
        {
         notnull (options->ca_file, "CA file (--ca)");
-       notnull (options->pkcs11_id, "PKCS#11 id (--pkcs11-id)");
 
+       if (options->pkcs11_id_management && options->pkcs11_id != NULL)
+         msg(M_USAGE, "Parameter --pkcs11-id cannot be used when --pkcs11-id-management is also specified.");
+       if (!options->pkcs11_id_management && options->pkcs11_id == NULL)
+         msg(M_USAGE, "Parameter --pkcs11-id or --pkcs11-id-management should be specified.");
        if (options->cert_file)
          msg(M_USAGE, "Parameter --cert cannot be used when --pkcs11-provider is also specified.");
        if (options->priv_key_file)
@@ -1870,6 +1869,7 @@ options_postprocess (struct options *options, bool first_time)
       MUST_BE_UNDEF (pkcs11_providers[0]);
       MUST_BE_UNDEF (pkcs11_private_mode[0]);
       MUST_BE_UNDEF (pkcs11_id);
+      MUST_BE_UNDEF (pkcs11_id_management);
 #endif
 
       if (pull)
@@ -5137,6 +5137,11 @@ add_option (struct options *options,
       VERIFY_PERMISSION (OPT_P_GENERAL);
       options->pkcs11_id = p[1];
     }
+  else if (streq (p[0], "pkcs11-id-management"))
+    {
+      VERIFY_PERMISSION (OPT_P_GENERAL);
+      options->pkcs11_id_management = true;
+    }
 #endif
 #ifdef TUNSETPERSIST
   else if (streq (p[0], "rmtun"))
index 2667b71c40f5207e78644696310284300e0456b4..607df0f31796ef2712b41eeeb5d9b679ce0d6829 100644 (file)
--- a/options.h
+++ b/options.h
@@ -419,6 +419,7 @@ struct options
   bool pkcs11_cert_private[MAX_PARMS];
   int pkcs11_pin_cache_period;
   const char *pkcs11_id;
+  bool pkcs11_id_management;
 #endif
 
 #ifdef WIN32
diff --git a/otime.c b/otime.c
index d21b08be2d6b44221bdafc78bfadb66d0b2b2706..394eea37011ada335e9ee0e5b56eb66b3c223685 100644 (file)
--- a/otime.c
+++ b/otime.c
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#ifdef WIN32
-#include "config-win32.h"
-#else
-#include "config.h"
-#endif
-
 #include "syshead.h"
 
 #include "otime.h"
index 6bc5b6bd3946d0c29e436f913c12f91365ae4711..08e5974362b28f087c7b2a217c42c38e97014cbb 100644 (file)
  * to IPSec.
  */
 
-#ifdef WIN32
-#include "config-win32.h"
-#else
-#include "config.h"
-#endif
+#include "syshead.h"
 
 #ifdef USE_CRYPTO
 
-#include "syshead.h"
-
 #include "packet_id.h"
 #include "misc.h"
 #include "integer.h"
diff --git a/perf.c b/perf.c
index 3abf8c56f7548536ceac070d6cae713f9b02bf4f..85dea4520655ea604b35369cd31f0c6fbe1788a5 100644 (file)
--- a/perf.c
+++ b/perf.c
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#ifdef WIN32
-#include "config-win32.h"
-#else
-#include "config.h"
-#endif
-
 #include "syshead.h"
 
 #include "perf.h"
diff --git a/ping.c b/ping.c
index bee35431c591eb6cd7d28c5bbad5ef3bc06b8d8c..622408f5ccb28df6128a22106b716db66fc2df05 100644 (file)
--- a/ping.c
+++ b/ping.c
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#ifdef WIN32
-#include "config-win32.h"
-#else
-#include "config.h"
-#endif
-
 #include "syshead.h"
 
 #include "ping.h"
index 9a6ed77c9cb93f276aed9367e5400d802fed0ff8..da8e8fda3931ab2f583c553c8c092d690c87aa46 100644 (file)
--- a/pkcs11.c
+++ b/pkcs11.c
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#if defined(WIN32)
-#include "config-win32.h"
-#else
-#include "config.h"
-#endif
-
 #include "syshead.h"
 
 #if defined(ENABLE_PKCS11)
@@ -37,6 +31,7 @@
 #include "basic.h"
 #include "error.h"
 #include "manage.h"
+#include "base64.h"
 #include "pkcs11.h"
 
 static
@@ -168,7 +163,7 @@ _pkcs11_openvpn_token_prompt (
        const pkcs11h_token_id_t token,
        const unsigned retry
 ) {
-       static struct user_pass token_resp;
+       struct user_pass token_resp;
 
        (void)global_data;
        (void)user_data;
@@ -211,7 +206,7 @@ _pkcs11_openvpn_pin_prompt (
        char * const pin,
        const size_t pin_max
 ) {
-       static struct user_pass token_pass;
+       struct user_pass token_pass;
        char prompt[1024];
 
        (void)global_data;
@@ -388,9 +383,225 @@ pkcs11_logout() {
        return pkcs11h_logout () == CKR_OK;
 }
 
+int
+pkcs11_management_id_count () {
+       pkcs11h_certificate_id_list_t id_list = NULL;
+       pkcs11h_certificate_id_list_t t = NULL;
+       CK_RV rv = CKR_OK;
+       int count = 0;
+
+       dmsg (
+               D_PKCS11_DEBUG,
+               "PKCS#11: pkcs11_management_id_count - entered"
+       );
+
+       if (
+               (rv = pkcs11h_certificate_enumCertificateIds (
+                       PKCS11H_ENUM_METHOD_CACHE_EXIST,
+                       NULL,
+                       PKCS11H_PROMPT_MASK_ALLOW_ALL,
+                       NULL,
+                       &id_list
+               )) != CKR_OK
+       ) {
+               msg (M_WARN, "PKCS#11: Cannot get certificate list %ld-'%s'", rv, pkcs11h_getMessage (rv));
+               goto cleanup;
+       }
+
+       for (count = 0, t = id_list; t != NULL; t = t->next) {
+               count++;
+       }
+
+cleanup:
+
+       if (id_list != NULL) {
+               pkcs11h_certificate_freeCertificateIdList (id_list);
+               id_list = NULL;
+       }
+
+       dmsg (
+               D_PKCS11_DEBUG,
+               "PKCS#11: pkcs11_management_id_count - return count=%d",
+               count
+       );
+
+       return count;
+}
+
+bool
+pkcs11_management_id_get (
+       const int index,
+       char ** id,
+       char **base64
+) {
+       pkcs11h_certificate_id_list_t id_list = NULL;
+       pkcs11h_certificate_id_list_t entry = NULL;
+       pkcs11h_certificate_id_t certificate_id = NULL;
+       pkcs11h_certificate_t certificate = NULL;
+       CK_RV rv = CKR_OK;
+       char *certificate_blob = NULL;
+       size_t certificate_blob_size = 0;
+       size_t max;
+       char *internal_id = NULL;
+       char *internal_base64 = NULL;
+       int count = 0;
+       bool success = false;
+
+       ASSERT (id!=NULL);
+       ASSERT (base64!=NULL);
+
+       dmsg (
+               D_PKCS11_DEBUG,
+               "PKCS#11: pkcs11_management_id_get - entered index=%d",
+               index
+       );
+
+       *id = NULL;
+       *base64 = NULL;
+
+       if (
+               (rv = pkcs11h_certificate_enumCertificateIds (
+                       PKCS11H_ENUM_METHOD_CACHE_EXIST,
+                       NULL,
+                       PKCS11H_PROMPT_MASK_ALLOW_ALL,
+                       NULL,
+                       &id_list
+               )) != CKR_OK
+       ) {
+               msg (M_WARN, "PKCS#11: Cannot get certificate list %ld-'%s'", rv, pkcs11h_getMessage (rv));
+               goto cleanup;
+       }
+
+       entry = id_list;
+       count = 0;
+       while (entry != NULL && count != index) {
+               count++;
+               entry = entry->next;
+       }
+
+       if (entry == NULL) {
+               dmsg (
+                       D_PKCS11_DEBUG,
+                       "PKCS#11: pkcs11_management_id_get - no certificate at index=%d",
+                       index
+               );
+               goto cleanup;
+       }
+
+       if (
+               (rv = pkcs11h_certificate_serializeCertificateId (
+                       NULL,
+                       &max,
+                       entry->certificate_id
+               )) != CKR_OK
+       ) {
+               msg (M_WARN, "PKCS#11: Cannot serialize certificate id %ld-'%s'", rv, pkcs11h_getMessage (rv));
+               goto cleanup;
+       }
+
+       if ((internal_id = (char *)malloc (max)) == NULL) {
+               msg (M_FATAL, "PKCS#11: Cannot allocate memory");
+               goto cleanup;
+       }
+
+       if (
+               (rv = pkcs11h_certificate_serializeCertificateId (
+                       internal_id,
+                       &max,
+                       entry->certificate_id
+               )) != CKR_OK
+       ) {
+               msg (M_WARN, "PKCS#11: Cannot serialize certificate id %ld-'%s'", rv, pkcs11h_getMessage (rv));
+               goto cleanup;
+       }
+
+       if (
+               (rv = pkcs11h_certificate_create (
+                       entry->certificate_id,
+                       NULL,
+                       PKCS11H_PROMPT_MASK_ALLOW_ALL,
+                       PKCS11H_PIN_CACHE_INFINITE,
+                       &certificate
+               )) != CKR_OK
+       ) {
+               msg (M_WARN, "PKCS#11: Cannot get certificate %ld-'%s'", rv, pkcs11h_getMessage (rv));
+               goto cleanup;
+       }
+
+       if (
+               (rv = pkcs11h_certificate_getCertificateBlob (
+                       certificate,
+                       NULL,
+                       &certificate_blob_size
+               )) != CKR_OK
+       ) {
+               msg (M_WARN, "PKCS#11: Cannot get certificate blob %ld-'%s'", rv, pkcs11h_getMessage (rv));
+               goto cleanup;
+       }
+
+       if ((certificate_blob = (char *)malloc (certificate_blob_size)) == NULL) {
+               msg (M_FATAL, "PKCS#11: Cannot allocate memory");
+               goto cleanup;
+       }
+
+       if (
+               (rv = pkcs11h_certificate_getCertificateBlob (
+                       certificate,
+                       certificate_blob,
+                       &certificate_blob_size
+               )) != CKR_OK
+       ) {
+               msg (M_WARN, "PKCS#11: Cannot get certificate blob %ld-'%s'", rv, pkcs11h_getMessage (rv));
+               goto cleanup;
+       }
+
+       if (base64_encode (certificate_blob, certificate_blob_size, &internal_base64) == -1) {
+               msg (M_WARN, "PKCS#11: Cannot encode certificate");
+               goto cleanup;
+       }
+
+       *id = internal_id;
+       internal_id = NULL;
+       *base64 = internal_base64;
+       internal_base64 = NULL;
+       success = true;
+       
+cleanup:
+
+       if (id_list != NULL) {
+               pkcs11h_certificate_freeCertificateIdList (id_list);
+               id_list = NULL;
+       }
+
+       if (internal_id != NULL) {
+               free (internal_id);
+               internal_id = NULL;
+       }
+
+       if (internal_base64 != NULL) {
+               free (internal_base64);
+               internal_base64 = NULL;
+       }
+
+       if (certificate_blob != NULL) {
+               free (certificate_blob);
+               certificate_blob = NULL;
+       }
+
+       dmsg (
+               D_PKCS11_DEBUG,
+               "PKCS#11: pkcs11_management_id_get - return success=%d, id='%s'",
+               success ? 1 : 0,
+               *id
+       );
+
+       return success;
+}
+
 int
 SSL_CTX_use_pkcs11 (
        SSL_CTX * const ssl_ctx,
+       bool pkcs11_id_management,
        const char * const pkcs11_id
 ) {
        X509 *x509 = NULL;
@@ -403,23 +614,60 @@ SSL_CTX_use_pkcs11 (
        bool ok = false;
 
        ASSERT (ssl_ctx!=NULL);
-       ASSERT (pkcs11_id!=NULL);
+       ASSERT (pkcs11_id_management || pkcs11_id!=NULL);
 
        dmsg (
                D_PKCS11_DEBUG,
-               "PKCS#11: SSL_CTX_use_pkcs11 - entered - ssl_ctx=%p, pkcs11_id='%s'",
+               "PKCS#11: SSL_CTX_use_pkcs11 - entered - ssl_ctx=%p, pkcs11_id_management=%d, pkcs11_id='%s'",
                (void *)ssl_ctx,
+               pkcs11_id_management ? 1 : 0,
                pkcs11_id
        );
 
-       if (
-               (rv = pkcs11h_certificate_deserializeCertificateId (
-                       &certificate_id,
-                       pkcs11_id
-               )) != CKR_OK
-       ) {
-               msg (M_WARN, "PKCS#11: Cannot deserialize id %ld-'%s'", rv, pkcs11h_getMessage (rv));
-               goto cleanup;
+       if (pkcs11_id_management) {
+               struct user_pass id_resp;
+
+               CLEAR (id_resp);
+
+               id_resp.defined = false;
+               id_resp.nocache = true;
+               openvpn_snprintf (
+                       id_resp.username,
+                       sizeof (id_resp.username),
+                       "Please specify PKCS#11 id to use"
+               );
+
+               if (
+                       !get_user_pass (
+                               &id_resp,
+                               NULL,
+                               "pkcs11-id-request",
+                               GET_USER_PASS_MANAGEMENT|GET_USER_PASS_NEED_STR|GET_USER_PASS_NOFATAL
+                       )
+               ) {
+                       goto cleanup;
+               }
+
+               if (
+                       (rv = pkcs11h_certificate_deserializeCertificateId (
+                               &certificate_id,
+                               id_resp.password
+                       )) != CKR_OK
+               ) {
+                       msg (M_WARN, "PKCS#11: Cannot deserialize id %ld-'%s'", rv, pkcs11h_getMessage (rv));
+                       goto cleanup;
+               }
+       }
+       else {
+               if (
+                       (rv = pkcs11h_certificate_deserializeCertificateId (
+                               &certificate_id,
+                               pkcs11_id
+                       )) != CKR_OK
+               ) {
+                       msg (M_WARN, "PKCS#11: Cannot deserialize id %ld-'%s'", rv, pkcs11h_getMessage (rv));
+                       goto cleanup;
+               }
        }
 
        if (
index 4b207e73b6478c3d6fd04fc42938b7e1aad6456a..14dd178a77551718906d4b056a3402307e40d3fa 100644 (file)
--- a/pkcs11.h
+++ b/pkcs11.h
@@ -52,9 +52,20 @@ pkcs11_addProvider (
 int
 pkcs11_logout();
 
+int
+pkcs11_management_id_count ();
+
+bool
+pkcs11_management_id_get (
+       const int index,
+       char ** id,
+       char **base64
+);
+
 int
 SSL_CTX_use_pkcs11 (
        SSL_CTX * const ssl_ctx,
+       bool pkcs11_id_management,
        const char * const pkcs11_id
 );
 
index 7bf69124bf59adb6f05d239ced5bf9ff0b156349..a337e46937bc9373b34a6aa7f2d8f733fb1e5a14 100644 (file)
--- a/plugin.c
+++ b/plugin.c
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#ifdef WIN32
-#include "config-win32.h"
-#else
-#include "config.h"
-#endif
-
 #include "syshead.h"
 
 #ifdef ENABLE_PLUGIN
diff --git a/pool.c b/pool.c
index cb666b80238c05b521b0b56c644be9da7f45e21a..6f19d79e60cd7adb9a902ac4ce39f9984b475b56 100644 (file)
--- a/pool.c
+++ b/pool.c
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#ifdef WIN32
-#include "config-win32.h"
-#else
-#include "config.h"
-#endif
-
 #include "syshead.h"
 
 #include "pool.h"
diff --git a/proto.c b/proto.c
index 4e8a30924c99bee4f25d9001de6db9a56684a82d..20eb9d596f32cba1045879e957f3226c018b0653 100644 (file)
--- a/proto.c
+++ b/proto.c
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#ifdef WIN32
-#include "config-win32.h"
-#else
-#include "config.h"
-#endif
-
 #include "syshead.h"
 
 #include "proto.h"
diff --git a/proxy.c b/proxy.c
index 8b208a68135150493590430119f7d016f86fcec6..620f23c0a4d6ee000e83633210541ec8158e30a2 100644 (file)
--- a/proxy.c
+++ b/proxy.c
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#ifdef WIN32
-#include "config-win32.h"
-#else
-#include "config.h"
-#endif
-
 #include "syshead.h"
 
 #include "common.h"
@@ -294,19 +288,21 @@ new_http_proxy (const struct http_proxy_options *o,
        p->auth_method = HTTP_AUTH_BASIC;
       else if (!strcmp (o->auth_method_string, "ntlm"))
        p->auth_method = HTTP_AUTH_NTLM;
+      else if (!strcmp (o->auth_method_string, "ntlm2"))
+       p->auth_method = HTTP_AUTH_NTLM2;
       else
-       msg (M_FATAL, "ERROR: unknown HTTP authentication method: '%s' -- only the 'none', 'basic', or 'ntlm' methods are currently supported",
+       msg (M_FATAL, "ERROR: unknown HTTP authentication method: '%s' -- only the 'none', 'basic', 'ntlm', or 'ntlm2' methods are currently supported",
             o->auth_method_string);
     }
 
-  /* only basic and NTLM authentication supported so far */
-  if (p->auth_method == HTTP_AUTH_BASIC || p->auth_method == HTTP_AUTH_NTLM)
+  /* only basic and NTLM/NTLMv2 authentication supported so far */
+  if (p->auth_method == HTTP_AUTH_BASIC || p->auth_method == HTTP_AUTH_NTLM || p->auth_method == HTTP_AUTH_NTLM2)
     {
       get_user_pass_http (p, true);
     }
 
 #if !NTLM
-  if (p->auth_method == HTTP_AUTH_NTLM)
+  if (p->auth_method == HTTP_AUTH_NTLM || p->auth_method == HTTP_AUTH_NTLM2)
     msg (M_FATAL, "Sorry, this version of " PACKAGE_NAME " was built without NTLM Proxy support.");
 #endif
 
@@ -374,6 +370,12 @@ establish_http_proxy_passthru (struct http_proxy_info *p,
 
 #if NTLM
     case HTTP_AUTH_NTLM:
+    case HTTP_AUTH_NTLM2:
+      /* keep-alive connection */
+      openvpn_snprintf (buf, sizeof(buf), "Proxy-Connection: Keep-Alive");
+      if (!send_line_crlf (sd, buf))
+       goto error;
+
       openvpn_snprintf (buf, sizeof(buf), "Proxy-Authorization: NTLM %s",
                        ntlm_phase_1 (p, &gc));
       msg (D_PROXY, "Attempting NTLM Proxy-Authorization phase 1");
@@ -411,7 +413,7 @@ establish_http_proxy_passthru (struct http_proxy_info *p,
       msg (D_PROXY, "Proxy requires authentication");
 
       /* check for NTLM */
-      if (p->auth_method == HTTP_AUTH_NTLM)
+      if (p->auth_method == HTTP_AUTH_NTLM || p->auth_method == HTTP_AUTH_NTLM2)
         {
 #if NTLM
           /* look for the phase 2 response */
@@ -456,6 +458,12 @@ establish_http_proxy_passthru (struct http_proxy_info *p,
           if (!send_line_crlf (sd, buf))
             goto error;
 
+          /* keep-alive connection */
+          openvpn_snprintf (buf, sizeof(buf), "Proxy-Connection: Keep-Alive");
+          if (!send_line_crlf (sd, buf))
+            goto error;
+
+          
           /* send HOST etc, */
           openvpn_sleep (1);
           openvpn_snprintf (buf, sizeof(buf), "Host: %s", host);
diff --git a/proxy.h b/proxy.h
index 235f5f01400b1af17fca40e03c8098e822027706..1417dbcaffdc4601b3be77424c7a9c70bdfb6c2c 100644 (file)
--- a/proxy.h
+++ b/proxy.h
@@ -59,6 +59,7 @@ void show_win_proxy_settings (const int msglevel);
 #define HTTP_AUTH_BASIC 1
 #define HTTP_AUTH_NTLM  2
 #define HTTP_AUTH_N     3
+#define HTTP_AUTH_NTLM2 4
 
 struct http_proxy_options {
   const char *server;
diff --git a/ps.c b/ps.c
index 49b1a2cba257ca055e8b912777f343d901165b74..430a138bc98c2d4a808e20aa4d72a1d20711ef63 100644 (file)
--- a/ps.c
+++ b/ps.c
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#ifdef WIN32
-#include "config-win32.h"
-#else
-#include "config.h"
-#endif
-
 #include "syshead.h"
 
 #if PORT_SHARE
diff --git a/push.c b/push.c
index a725eb598ff21d7eadd28794c142ddd573c5dcfc..d5a757a2926e2978685b6e98bd448f4758ab508c 100644 (file)
--- a/push.c
+++ b/push.c
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#ifdef WIN32
-#include "config-win32.h"
-#else
-#include "config.h"
-#endif
-
 #include "syshead.h"
 
 #include "push.h"
index 01e1d0ae16f7523674a6daac46023fad31d27b12..854e2b0ccf3657eb3bec93f7f8a1ba79cc752cf7 100644 (file)
  * so that SSL/TLS can be run over UDP.
  */
 
-#ifdef WIN32
-#include "config-win32.h"
-#else
-#include "config.h"
-#endif
+#include "syshead.h"
 
 #if defined(USE_CRYPTO) && defined(USE_SSL)
 
-#include "syshead.h"
-
 #include "buffer.h"
 #include "error.h"
 #include "common.h"
diff --git a/route.c b/route.c
index 507ef38f301bf530881adc67aa6bc5132706fd73..0a7e032676b0fdf42417ecbf931e78ac69f511f2 100644 (file)
--- a/route.c
+++ b/route.c
  * Support routines for adding/deleting network routes.
  */
 
-#ifdef WIN32
-#include "config-win32.h"
-#else
-#include "config.h"
-#endif
-
 #include "syshead.h"
 
 #include "common.h"
@@ -871,6 +865,23 @@ add_route (struct route *r, const struct tuntap *tt, unsigned int flags, const s
   msg (D_ROUTE, "%s", BSTR (&buf));
   status = system_check (BSTR (&buf), es, 0, "ERROR: FreeBSD route add command failed");
 
+#elif defined(TARGET_DRAGONFLY)
+
+  buf_printf (&buf, ROUTE_PATH " add");
+
+#if 0
+  if (r->metric_defined)
+    buf_printf (&buf, " -rtt %d", r->metric);
+#endif
+
+  buf_printf (&buf, " -net %s %s %s",
+             network,
+             gateway,
+             netmask);
+
+  msg (D_ROUTE, "%s", BSTR (&buf));
+  status = system_check (BSTR (&buf), es, 0, "ERROR: DragonFly route add command failed");
+
 #elif defined(TARGET_DARWIN)
 
   buf_printf (&buf, ROUTE_PATH " add");
@@ -1007,6 +1018,16 @@ delete_route (const struct route *r, const struct tuntap *tt, unsigned int flags
   msg (D_ROUTE, "%s", BSTR (&buf));
   system_check (BSTR (&buf), es, 0, "ERROR: FreeBSD route delete command failed");
 
+#elif defined(TARGET_DRAGONFLY)
+
+  buf_printf (&buf, ROUTE_PATH " delete -net %s %s %s",
+             network,
+             gateway,
+             netmask);
+
+  msg (D_ROUTE, "%s", BSTR (&buf));
+  system_check (BSTR (&buf), es, 0, "ERROR: DragonFly route delete command failed");
+
 #elif defined(TARGET_DARWIN)
 
   buf_printf (&buf, ROUTE_PATH " delete -net %s %s %s",
@@ -1462,7 +1483,7 @@ get_default_gateway (in_addr_t *gateway)
   return ret;
 }
 
-#elif defined(TARGET_FREEBSD)
+#elif defined(TARGET_FREEBSD)||defined(TARGET_DRAGONFLY)
 
 #include <sys/types.h>
 #include <sys/socket.h>
index 25aec209676224c0f7bd19058f2c17c4ff0d82de..af32e830e5028680823ffcb4710abc38827dfd49 100644 (file)
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#ifdef WIN32
-#include "config-win32.h"
-#else
-#include "config.h"
-#endif
-
 #include "syshead.h"
 
 #if P2MP_SERVER
diff --git a/service-win32/.svnignore b/service-win32/.svnignore
new file mode 100644 (file)
index 0000000..df25b75
--- /dev/null
@@ -0,0 +1,8 @@
+*.exe
+*.obj
+*.o
+.deps
+Makefile.in
+Makefile
+service.h
+service.c
diff --git a/service-win32/Makefile b/service-win32/Makefile
deleted file mode 100755 (executable)
index 9a3cb5d..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-# This makefile builds the OpenVPN win32 service
-# wrapper using the mingw environment.
-#
-# service.c and service.h should be generated by
-# applying service.patch to the Platform
-# SDK service sample.
-
-EXE = ${PRODUCT_UNIX_NAME}serv.exe
-
-HEADERS = service.h
-
-OBJS = openvpnserv.o service.o
-
-INCLUDE_DIRS =
-
-CC = gcc -g -O2 -Wall -Wno-unused-function -Wno-unused-variable -mno-cygwin
-
-all : ${OBJS}
-       ${CC} -o ${EXE} ${OBJS}
-
-clean :
-       rm -f ${OBJS} ${EXE}
-
-%.o : %.c ${HEADERS}
-       ${CC} ${INCLUDE_DIRS} -c $< -o $@
diff --git a/service-win32/Makefile.am b/service-win32/Makefile.am
new file mode 100644 (file)
index 0000000..97c5ef6
--- /dev/null
@@ -0,0 +1,41 @@
+#
+#  OpenVPN -- An application to securely tunnel IP networks
+#             over a single UDP port, with support for SSL/TLS-based
+#             session authentication and key exchange,
+#             packet encryption, packet authentication, and
+#             packet compression.
+#
+#  Copyright (C) 2002-2005 OpenVPN Solutions LLC <info@openvpn.net>
+#
+#  This program is free software; you can redistribute it and/or modify
+#  it under the terms of the GNU General Public License version 2
+#  as published by the Free Software Foundation.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program (see the file COPYING included with this
+#  distribution); if not, write to the Free Software Foundation, Inc.,
+#  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+#
+
+MAINTAINERCLEANFILES = $(srcdir)/Makefile.in
+
+if WIN32
+
+sbin_PROGRAMS = openvpnserv
+
+openvpnserv_SOURCES = \
+       openvpnserv.c \
+       service.h service.c
+
+else
+
+dist_noinst_DATA = \
+       openvpnserv.c \
+       service.h service.c
+
+endif
diff --git a/service-win32/mkpatch b/service-win32/mkpatch
deleted file mode 100755 (executable)
index 83652e1..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-# build service.[ch] patch against original
-# SDK sample
-diff -ub service.c.orig service.c | u2d >service.patch
-diff -ub service.h.orig service.h | u2d >>service.patch
index 76323ca8e854ab4baa200684c2fb7444da5641e1..6cdce26246b1b6ade60d3026762aa4203c4b8377 100755 (executable)
  * This code is designed to be built with the mingw compiler.
  */
 
+#ifdef _MSC_VER
+#include "config-win32.h"
+#else
+#include "config.h"
+#endif
 #include <windows.h>
 #include <stdlib.h>
 #include <stdio.h>
@@ -65,13 +70,13 @@ struct security_attributes
  * Control Manager which will cause an asynchronous call
  * of ServiceStop below.
  */
-#define EXIT_EVENT_NAME PRODUCT_UNIX_NAME "_exit_1"
+#define EXIT_EVENT_NAME PACKAGE "_exit_1"
 
 /*
  * Which registry key in HKLM should
  * we get config info from?
  */
-#define REG_KEY "SOFTWARE\\" PRODUCT_NAME
+#define REG_KEY "SOFTWARE\\" PACKAGE_NAME
 
 static HANDLE exit_event = NULL;
 
@@ -398,7 +403,7 @@ VOID ServiceStart (DWORD dwArgc, LPTSTR *lpszArgv)
          mysnprintf (log_path, "%s\\%s", log_dir, log_file);
 
          /* construct command line */
-         mysnprintf (command_line, PRODUCT_UNIX_NAME " --service %s 1 --config \"%s\"",
+         mysnprintf (command_line, PACKAGE " --service %s 1 --config \"%s\"",
                      EXIT_EVENT_NAME,
                      find_obj.cFileName);
 
@@ -406,7 +411,7 @@ VOID ServiceStart (DWORD dwArgc, LPTSTR *lpszArgv)
             be inherited. */
          if (!init_security_attributes_allow_all (&sa))
            {
-             MSG (M_SYSERR, "InitializeSecurityDescriptor start_" PRODUCT_UNIX_NAME " failed");
+             MSG (M_SYSERR, "InitializeSecurityDescriptor start_" PACKAGE " failed");
              goto finish;
            }
 
diff --git a/service-win32/service.c b/service-win32/service.c
new file mode 100644 (file)
index 0000000..d5211bd
--- /dev/null
@@ -0,0 +1,693 @@
+/*---------------------------------------------------------------------------
+THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
+ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED
+TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
+PARTICULAR PURPOSE.
+
+Copyright (C) 1993 - 2000.  Microsoft Corporation.  All rights reserved.
+
+MODULE:   service.c
+
+PURPOSE:  Implements functions required by all Windows NT services
+
+FUNCTIONS:
+  main(int argc, char **argv);
+  service_ctrl(DWORD dwCtrlCode);
+  service_main(DWORD dwArgc, LPTSTR *lpszArgv);
+  CmdInstallService();
+  CmdRemoveService();
+  CmdStartService();
+  CmdDebugService(int argc, char **argv);
+  ControlHandler ( DWORD dwCtrlType );
+  GetLastErrorText( LPTSTR lpszBuf, DWORD dwSize );
+
+---------------------------------------------------------------------------*/
+
+#include <windows.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <process.h>
+#include <tchar.h>
+
+#include "service.h"
+
+// internal variables
+SERVICE_STATUS          ssStatus;       // current status of the service
+SERVICE_STATUS_HANDLE   sshStatusHandle;
+DWORD                   dwErr = 0;
+BOOL                    bDebug = FALSE;
+TCHAR                   szErr[256];
+
+// internal function prototypes
+VOID WINAPI service_ctrl(DWORD dwCtrlCode);
+VOID WINAPI service_main(DWORD dwArgc, LPTSTR *lpszArgv);
+int CmdInstallService();
+int CmdRemoveService();
+int CmdStartService();
+VOID CmdDebugService(int argc, char **argv);
+BOOL WINAPI ControlHandler ( DWORD dwCtrlType );
+LPTSTR GetLastErrorText( LPTSTR lpszBuf, DWORD dwSize );
+
+//
+//  FUNCTION: main
+//
+//  PURPOSE: entrypoint for service
+//
+//  PARAMETERS:
+//    argc - number of command line arguments
+//    argv - array of command line arguments
+//
+//  RETURN VALUE:
+//    none
+//
+//  COMMENTS:
+//    main() either performs the command line task, or
+//    call StartServiceCtrlDispatcher to register the
+//    main service thread.  When the this call returns,
+//    the service has stopped, so exit.
+//
+int __cdecl main(int argc, char **argv)
+{
+   SERVICE_TABLE_ENTRY dispatchTable[] =
+   {
+      { TEXT(SZSERVICENAME), (LPSERVICE_MAIN_FUNCTION)service_main},
+      { NULL, NULL}
+   };
+
+   if ( (argc > 1) &&
+        ((*argv[1] == '-') || (*argv[1] == '/')) )
+   {
+      if ( _stricmp( "install", argv[1]+1 ) == 0 )
+      {
+         return CmdInstallService();
+      }
+      else if ( _stricmp( "remove", argv[1]+1 ) == 0 )
+      {
+         return CmdRemoveService();
+      }
+         else if ( _stricmp( "start", argv[1]+1 ) == 0)
+         {
+                 return CmdStartService();
+      }
+      else if ( _stricmp( "debug", argv[1]+1 ) == 0 )
+      {
+         bDebug = TRUE;
+         CmdDebugService(argc, argv);
+      }
+      else
+      {
+         goto dispatch;
+      }
+      return 0;
+   }
+
+   // if it doesn't match any of the above parameters
+   // the service control manager may be starting the service
+   // so we must call StartServiceCtrlDispatcher
+   dispatch:
+   // this is just to be friendly
+   printf( "%s -install          to install the service\n", SZAPPNAME );
+   printf( "%s -start                   to start the service\n", SZAPPNAME );
+   printf( "%s -remove           to remove the service\n", SZAPPNAME );
+   printf( "%s -debug <params>   to run as a console app for debugging\n", SZAPPNAME );
+   printf( "\nStartServiceCtrlDispatcher being called.\n" );
+   printf( "This may take several seconds.  Please wait.\n" );
+
+   if (!StartServiceCtrlDispatcher(dispatchTable))
+      AddToMessageLog(MSG_FLAGS_ERROR, TEXT("StartServiceCtrlDispatcher failed."));
+
+   return 0;
+}
+
+
+
+//
+//  FUNCTION: service_main
+//
+//  PURPOSE: To perform actual initialization of the service
+//
+//  PARAMETERS:
+//    dwArgc   - number of command line arguments
+//    lpszArgv - array of command line arguments
+//
+//  RETURN VALUE:
+//    none
+//
+//  COMMENTS:
+//    This routine performs the service initialization and then calls
+//    the user defined ServiceStart() routine to perform majority
+//    of the work.
+//
+void WINAPI service_main(DWORD dwArgc, LPTSTR *lpszArgv)
+{
+
+   // register our service control handler:
+   //
+   sshStatusHandle = RegisterServiceCtrlHandler( TEXT(SZSERVICENAME), service_ctrl);
+
+   if (!sshStatusHandle)
+      goto cleanup;
+
+   // SERVICE_STATUS members that don't change in example
+   //
+   ssStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
+   ssStatus.dwServiceSpecificExitCode = 0;
+
+
+   // report the status to the service control manager.
+   //
+   if (!ReportStatusToSCMgr(
+                           SERVICE_START_PENDING, // service state
+                           NO_ERROR,              // exit code
+                           3000))                 // wait hint
+      goto cleanup;
+
+
+   ServiceStart( dwArgc, lpszArgv );
+
+   cleanup:
+
+   // try to report the stopped status to the service control manager.
+   //
+   if (sshStatusHandle)
+      (VOID)ReportStatusToSCMgr(
+                               SERVICE_STOPPED,
+                               dwErr,
+                               0);
+
+   return;
+}
+
+
+
+//
+//  FUNCTION: service_ctrl
+//
+//  PURPOSE: This function is called by the SCM whenever
+//           ControlService() is called on this service.
+//
+//  PARAMETERS:
+//    dwCtrlCode - type of control requested
+//
+//  RETURN VALUE:
+//    none
+//
+//  COMMENTS:
+//
+VOID WINAPI service_ctrl(DWORD dwCtrlCode)
+{
+   // Handle the requested control code.
+   //
+   switch (dwCtrlCode)
+   {
+   // Stop the service.
+   //
+   // SERVICE_STOP_PENDING should be reported before
+   // setting the Stop Event - hServerStopEvent - in
+   // ServiceStop().  This avoids a race condition
+   // which may result in a 1053 - The Service did not respond...
+   // error.
+   case SERVICE_CONTROL_STOP:
+      ReportStatusToSCMgr(SERVICE_STOP_PENDING, NO_ERROR, 0);
+      ServiceStop();
+      return;
+
+      // Update the service status.
+      //
+   case SERVICE_CONTROL_INTERROGATE:
+      break;
+
+      // invalid control code
+      //
+   default:
+      break;
+
+   }
+
+   ReportStatusToSCMgr(ssStatus.dwCurrentState, NO_ERROR, 0);
+}
+
+
+
+//
+//  FUNCTION: ReportStatusToSCMgr()
+//
+//  PURPOSE: Sets the current status of the service and
+//           reports it to the Service Control Manager
+//
+//  PARAMETERS:
+//    dwCurrentState - the state of the service
+//    dwWin32ExitCode - error code to report
+//    dwWaitHint - worst case estimate to next checkpoint
+//
+//  RETURN VALUE:
+//    TRUE  - success
+//    FALSE - failure
+//
+//  COMMENTS:
+//
+BOOL ReportStatusToSCMgr(DWORD dwCurrentState,
+                         DWORD dwWin32ExitCode,
+                         DWORD dwWaitHint)
+{
+   static DWORD dwCheckPoint = 1;
+   BOOL fResult = TRUE;
+
+
+   if ( !bDebug ) // when debugging we don't report to the SCM
+   {
+      if (dwCurrentState == SERVICE_START_PENDING)
+         ssStatus.dwControlsAccepted = 0;
+      else
+         ssStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP;
+
+      ssStatus.dwCurrentState = dwCurrentState;
+      ssStatus.dwWin32ExitCode = dwWin32ExitCode;
+      ssStatus.dwWaitHint = dwWaitHint;
+
+      if ( ( dwCurrentState == SERVICE_RUNNING ) ||
+           ( dwCurrentState == SERVICE_STOPPED ) )
+         ssStatus.dwCheckPoint = 0;
+      else
+         ssStatus.dwCheckPoint = dwCheckPoint++;
+
+
+      // Report the status of the service to the service control manager.
+      //
+      if (!(fResult = SetServiceStatus( sshStatusHandle, &ssStatus)))
+      {
+         AddToMessageLog(MSG_FLAGS_ERROR, TEXT("SetServiceStatus"));
+      }
+   }
+   return fResult;
+}
+
+
+
+//
+//  FUNCTION: AddToMessageLog(LPTSTR lpszMsg)
+//
+//  PURPOSE: Allows any thread to log an error message
+//
+//  PARAMETERS:
+//    lpszMsg - text for message
+//
+//  RETURN VALUE:
+//    none
+//
+//  COMMENTS:
+//
+void AddToMessageLog(DWORD flags, LPTSTR lpszMsg)
+{
+   TCHAR szMsg [(sizeof(SZSERVICENAME) / sizeof(TCHAR)) + 100 ];
+   HANDLE  hEventSource;
+   LPCSTR  lpszStrings[2];
+
+   if ( !bDebug )
+   {
+     if (flags & MSG_FLAGS_SYS_CODE)
+      dwErr = GetLastError();
+     else
+       dwErr = 0;
+
+      // Use event logging to log the error.
+      //
+      hEventSource = RegisterEventSource(NULL, TEXT(SZSERVICENAME));
+
+      _stprintf(szMsg, TEXT("%s error: %d"), TEXT(SZSERVICENAME), (int)dwErr);
+      lpszStrings[0] = szMsg;
+      lpszStrings[1] = lpszMsg;
+
+      if (hEventSource != NULL)
+      {
+         ReportEvent(hEventSource, // handle of event source
+                    // event type
+                     (flags & MSG_FLAGS_ERROR)
+                      ? EVENTLOG_ERROR_TYPE : EVENTLOG_INFORMATION_TYPE,
+                     0,                    // event category
+                     0,                    // event ID
+                     NULL,                 // current user's SID
+                     2,                    // strings in lpszStrings
+                     0,                    // no bytes of raw data
+                     lpszStrings,          // array of error strings
+                     NULL);                // no raw data
+
+         (VOID) DeregisterEventSource(hEventSource);
+      }
+   }
+}
+
+void ResetError (void)
+{
+  dwErr = 0;
+}
+
+///////////////////////////////////////////////////////////////////
+//
+//  The following code handles service installation and removal
+//
+
+
+//
+//  FUNCTION: CmdInstallService()
+//
+//  PURPOSE: Installs the service
+//
+//  PARAMETERS:
+//    none
+//
+//  RETURN VALUE:
+//    0 if success
+//
+//  COMMENTS:
+//
+int CmdInstallService()
+{
+   SC_HANDLE   schService;
+   SC_HANDLE   schSCManager;
+
+   TCHAR szPath[512];
+
+   int ret = 0;
+
+   if ( GetModuleFileName( NULL, szPath, 512 ) == 0 )
+   {
+      _tprintf(TEXT("Unable to install %s - %s\n"), TEXT(SZSERVICEDISPLAYNAME), GetLastErrorText(szErr, 256));
+      return 1;
+   }
+
+   schSCManager = OpenSCManager(
+                               NULL,                   // machine (NULL == local)
+                               NULL,                   // database (NULL == default)
+                               SC_MANAGER_CONNECT | SC_MANAGER_CREATE_SERVICE  // access required
+                               );
+   if ( schSCManager )
+   {
+      schService = CreateService(
+                                schSCManager,               // SCManager database
+                                TEXT(SZSERVICENAME),        // name of service
+                                TEXT(SZSERVICEDISPLAYNAME), // name to display
+                                SERVICE_QUERY_STATUS,         // desired access
+                                SERVICE_WIN32_OWN_PROCESS,  // service type
+                               SERVICE_DEMAND_START,        // start type -- alternative: SERVICE_AUTO_START
+                                SERVICE_ERROR_NORMAL,       // error control type
+                                szPath,                     // service's binary
+                                NULL,                       // no load ordering group
+                                NULL,                       // no tag identifier
+                                TEXT(SZDEPENDENCIES),       // dependencies
+                                NULL,                       // LocalSystem account
+                                NULL);                      // no password
+
+      if ( schService )
+      {
+         _tprintf(TEXT("%s installed.\n"), TEXT(SZSERVICEDISPLAYNAME) );
+         CloseServiceHandle(schService);
+      }
+      else
+      {
+         _tprintf(TEXT("CreateService failed - %s\n"), GetLastErrorText(szErr, 256));
+        ret = 1;
+      }
+
+      CloseServiceHandle(schSCManager);
+   }
+   else
+     {
+      _tprintf(TEXT("OpenSCManager failed - %s\n"), GetLastErrorText(szErr,256));
+       ret = 1;
+     }
+   return ret;
+}
+
+//
+//  FUNCTION: CmdStartService()
+//
+//  PURPOSE: Start the service
+//
+//  PARAMETERS:
+//    none
+//
+//  RETURN VALUE:
+//    0 if success
+//
+//  COMMENTS:
+
+int CmdStartService()
+{
+  int ret = 0;
+
+  SC_HANDLE schSCManager;
+  SC_HANDLE schService;
+
+
+    // Open a handle to the SC Manager database. 
+    schSCManager = OpenSCManager( 
+       NULL,                    // local machine 
+       NULL,                    // ServicesActive database 
+       SC_MANAGER_ALL_ACCESS);  // full access rights 
+   
+    if (NULL == schSCManager) {
+       _tprintf(TEXT("OpenSCManager failed - %s\n"), GetLastErrorText(szErr,256));
+       ret = 1;
+    }
+
+    schService = OpenService( 
+        schSCManager,          // SCM database 
+        SZSERVICENAME,         // service name
+        SERVICE_ALL_ACCESS); 
+
+    if (schService == NULL) {
+      _tprintf(TEXT("OpenService failed - %s\n"), GetLastErrorText(szErr,256));
+       ret = 1;
+    }
+    if (!StartService(
+            schService,  // handle to service 
+            0,           // number of arguments 
+            NULL) )      // no arguments 
+    {
+      _tprintf(TEXT("StartService failed - %s\n"), GetLastErrorText(szErr,256));
+       ret = 1;
+    }
+    else
+       {
+               _tprintf(TEXT("Service Started\n"));
+       ret = 0;
+       }
+    CloseServiceHandle(schService); 
+    CloseServiceHandle(schSCManager);
+    return ret;
+}
+
+//
+//  FUNCTION: CmdRemoveService()
+//
+//  PURPOSE: Stops and removes the service
+//
+//  PARAMETERS:
+//    none
+//
+//  RETURN VALUE:
+//    0 if success
+//
+//  COMMENTS:
+//
+int CmdRemoveService()
+{
+   SC_HANDLE   schService;
+   SC_HANDLE   schSCManager;
+
+   int ret = 0;
+
+   schSCManager = OpenSCManager(
+                               NULL,                   // machine (NULL == local)
+                               NULL,                   // database (NULL == default)
+                               SC_MANAGER_CONNECT   // access required
+                               );
+   if ( schSCManager )
+   {
+      schService = OpenService(schSCManager, TEXT(SZSERVICENAME), DELETE | SERVICE_STOP | SERVICE_QUERY_STATUS);
+
+      if (schService)
+      {
+         // try to stop the service
+         if ( ControlService( schService, SERVICE_CONTROL_STOP, &ssStatus ) )
+         {
+            _tprintf(TEXT("Stopping %s."), TEXT(SZSERVICEDISPLAYNAME));
+            Sleep( 1000 );
+
+            while ( QueryServiceStatus( schService, &ssStatus ) )
+            {
+               if ( ssStatus.dwCurrentState == SERVICE_STOP_PENDING )
+               {
+                  _tprintf(TEXT("."));
+                  Sleep( 1000 );
+               }
+               else
+                  break;
+            }
+
+            if ( ssStatus.dwCurrentState == SERVICE_STOPPED )
+               _tprintf(TEXT("\n%s stopped.\n"), TEXT(SZSERVICEDISPLAYNAME) );
+            else
+             {
+               _tprintf(TEXT("\n%s failed to stop.\n"), TEXT(SZSERVICEDISPLAYNAME) );
+               ret = 1;
+             }
+
+         }
+
+         // now remove the service
+         if ( DeleteService(schService) )
+            _tprintf(TEXT("%s removed.\n"), TEXT(SZSERVICEDISPLAYNAME) );
+         else
+          {
+            _tprintf(TEXT("DeleteService failed - %s\n"), GetLastErrorText(szErr,256));
+            ret = 1;
+          }
+
+
+         CloseServiceHandle(schService);
+      }
+      else
+       {
+         _tprintf(TEXT("OpenService failed - %s\n"), GetLastErrorText(szErr,256));
+         ret = 1;
+       }
+
+      CloseServiceHandle(schSCManager);
+   }
+   else
+     {
+      _tprintf(TEXT("OpenSCManager failed - %s\n"), GetLastErrorText(szErr,256));
+       ret = 1;
+     }
+   return ret;
+}
+
+
+
+
+///////////////////////////////////////////////////////////////////
+//
+//  The following code is for running the service as a console app
+//
+
+
+//
+//  FUNCTION: CmdDebugService(int argc, char ** argv)
+//
+//  PURPOSE: Runs the service as a console application
+//
+//  PARAMETERS:
+//    argc - number of command line arguments
+//    argv - array of command line arguments
+//
+//  RETURN VALUE:
+//    none
+//
+//  COMMENTS:
+//
+void CmdDebugService(int argc, char ** argv)
+{
+   DWORD dwArgc;
+   LPTSTR *lpszArgv;
+
+#ifdef UNICODE
+   lpszArgv = CommandLineToArgvW(GetCommandLineW(), &(dwArgc) );
+   if (NULL == lpszArgv)
+   {
+       // CommandLineToArvW failed!!
+       _tprintf(TEXT("CmdDebugService CommandLineToArgvW returned NULL\n"));
+       return;
+   }
+#else
+   dwArgc   = (DWORD) argc;
+   lpszArgv = argv;
+#endif
+
+   _tprintf(TEXT("Debugging %s.\n"), TEXT(SZSERVICEDISPLAYNAME));
+
+   SetConsoleCtrlHandler( ControlHandler, TRUE );
+
+   ServiceStart( dwArgc, lpszArgv );
+
+#ifdef UNICODE
+// Must free memory allocated for arguments
+
+   GlobalFree(lpszArgv);
+#endif // UNICODE
+
+}
+
+
+//
+//  FUNCTION: ControlHandler ( DWORD dwCtrlType )
+//
+//  PURPOSE: Handled console control events
+//
+//  PARAMETERS:
+//    dwCtrlType - type of control event
+//
+//  RETURN VALUE:
+//    True - handled
+//    False - unhandled
+//
+//  COMMENTS:
+//
+BOOL WINAPI ControlHandler ( DWORD dwCtrlType )
+{
+   switch ( dwCtrlType )
+   {
+   case CTRL_BREAK_EVENT:  // use Ctrl+C or Ctrl+Break to simulate
+   case CTRL_C_EVENT:      // SERVICE_CONTROL_STOP in debug mode
+      _tprintf(TEXT("Stopping %s.\n"), TEXT(SZSERVICEDISPLAYNAME));
+      ServiceStop();
+      return TRUE;
+      break;
+
+   }
+   return FALSE;
+}
+
+//
+//  FUNCTION: GetLastErrorText
+//
+//  PURPOSE: copies error message text to string
+//
+//  PARAMETERS:
+//    lpszBuf - destination buffer
+//    dwSize - size of buffer
+//
+//  RETURN VALUE:
+//    destination buffer
+//
+//  COMMENTS:
+//
+LPTSTR GetLastErrorText( LPTSTR lpszBuf, DWORD dwSize )
+{
+   DWORD dwRet;
+   LPTSTR lpszTemp = NULL;
+
+   dwRet = FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |FORMAT_MESSAGE_ARGUMENT_ARRAY,
+                          NULL,
+                          GetLastError(),
+                          LANG_NEUTRAL,
+                          (LPTSTR)&lpszTemp,
+                          0,
+                          NULL );
+
+   // supplied buffer is not long enough
+   if ( !dwRet || ( (long)dwSize < (long)dwRet+14 ) )
+      lpszBuf[0] = TEXT('\0');
+   else
+   {
+      lpszTemp[lstrlen(lpszTemp)-2] = TEXT('\0');  //remove cr and newline character
+      _stprintf( lpszBuf, TEXT("%s (0x%x)"), lpszTemp, (int)GetLastError() );
+   }
+
+   if ( lpszTemp )
+      LocalFree((HLOCAL) lpszTemp );
+
+   return lpszBuf;
+}
diff --git a/service-win32/service.h b/service-win32/service.h
new file mode 100644 (file)
index 0000000..028d075
--- /dev/null
@@ -0,0 +1,141 @@
+/*---------------------------------------------------------------------------
+THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
+ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED
+TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
+PARTICULAR PURPOSE.
+
+Copyright (C) 1993 - 2000.  Microsoft Corporation.  All rights reserved.
+
+ MODULE: service.h
+
+ Comments:  The use of this header file and the accompanying service.c
+ file simplifies the process of writting a service.  You as a developer
+ simply need to follow the TODO's outlined in this header file, and
+ implement the ServiceStart() and ServiceStop() functions.
+
+ There is no need to modify the code in service.c.  Just add service.c
+ to your project and link with the following libraries...
+
+ libcmt.lib kernel32.lib advapi.lib shell32.lib
+
+ This code also supports unicode.  Be sure to compile both service.c and
+ and code #include "service.h" with the same Unicode setting.
+
+ Upon completion, your code will have the following command line interface
+
+ <service exe> -?                to display this list
+ <service exe> -install          to install the service
+ <service exe> -remove           to remove the service
+ <service exe> -debug <params>   to run as a console app for debugging
+
+ Note: This code also implements Ctrl+C and Ctrl+Break handlers
+       when using the debug option.  These console events cause
+       your ServiceStop routine to be called
+
+       Also, this code only handles the OWN_SERVICE service type
+       running in the LOCAL_SYSTEM security context.
+
+       To control your service ( start, stop, etc ) you may use the
+       Services control panel applet or the NET.EXE program.
+
+       To aid in writing/debugging service, the
+       SDK contains a utility (MSTOOLS\BIN\SC.EXE) that
+       can be used to control, configure, or obtain service status.
+       SC displays complete status for any service/driver
+       in the service database, and allows any of the configuration
+       parameters to be easily changed at the command line.
+       For more information on SC.EXE, type SC at the command line.
+
+
+------------------------------------------------------------------------------*/
+
+#ifndef _SERVICE_H
+#define _SERVICE_H
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "config.h"
+
+//////////////////////////////////////////////////////////////////////////////
+//// todo: change to desired strings
+////
+// name of the executable
+#define SZAPPNAME            PACKAGE "serv"
+// internal name of the service
+#define SZSERVICENAME        PACKAGE_NAME "Service"
+// displayed name of the service
+#define SZSERVICEDISPLAYNAME PACKAGE_NAME " Service"
+// list of service dependencies - "dep1\0dep2\0\0"
+#define SZDEPENDENCIES       TAP_ID "\0Dhcp\0\0"
+//////////////////////////////////////////////////////////////////////////////
+
+
+
+//////////////////////////////////////////////////////////////////////////////
+//// todo: ServiceStart()must be defined by in your code.
+////       The service should use ReportStatusToSCMgr to indicate
+////       progress.  This routine must also be used by StartService()
+////       to report to the SCM when the service is running.
+////
+////       If a ServiceStop procedure is going to take longer than
+////       3 seconds to execute, it should spawn a thread to
+////       execute the stop code, and return.  Otherwise, the
+////       ServiceControlManager will believe that the service has
+////       stopped responding
+////
+   VOID ServiceStart(DWORD dwArgc, LPTSTR *lpszArgv);
+   VOID ServiceStop();
+//////////////////////////////////////////////////////////////////////////////
+
+
+
+//////////////////////////////////////////////////////////////////////////////
+//// The following are procedures which
+//// may be useful to call within the above procedures,
+//// but require no implementation by the user.
+//// They are implemented in service.c
+
+//
+//  FUNCTION: ReportStatusToSCMgr()
+//
+//  PURPOSE: Sets the current status of the service and
+//           reports it to the Service Control Manager
+//
+//  PARAMETERS:
+//    dwCurrentState - the state of the service
+//    dwWin32ExitCode - error code to report
+//    dwWaitHint - worst case estimate to next checkpoint
+//
+//  RETURN VALUE:
+//    TRUE  - success
+//    FALSE - failure
+//
+   BOOL ReportStatusToSCMgr(DWORD dwCurrentState, DWORD dwWin32ExitCode, DWORD dwWaitHint);
+
+
+//
+//  FUNCTION: AddToMessageLog(LPTSTR lpszMsg)
+//
+//  PURPOSE: Allows any thread to log an error message
+//
+//  PARAMETERS:
+//    lpszMsg - text for message
+//
+//  RETURN VALUE:
+//    none
+//
+#  define MSG_FLAGS_ERROR     (1<<0)
+#  define MSG_FLAGS_SYS_CODE  (1<<1)
+   void AddToMessageLog(DWORD flags, LPTSTR lpszMsg);
+   void ResetError (void);
+//////////////////////////////////////////////////////////////////////////////
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/service-win32/service.patch b/service-win32/service.patch
deleted file mode 100755 (executable)
index 8e4ddf9..0000000
+++ /dev/null
@@ -1,359 +0,0 @@
---- service.c.orig     Tue Apr 24 14:49:30 2007
-+++ service.c  Tue Apr 24 12:20:08 2007
-@@ -16,6 +16,7 @@
-   service_main(DWORD dwArgc, LPTSTR *lpszArgv);
-   CmdInstallService();
-   CmdRemoveService();
-+  CmdStartService();
-   CmdDebugService(int argc, char **argv);
-   ControlHandler ( DWORD dwCtrlType );
-   GetLastErrorText( LPTSTR lpszBuf, DWORD dwSize );
-@@ -40,8 +41,9 @@
- // internal function prototypes
- VOID WINAPI service_ctrl(DWORD dwCtrlCode);
- VOID WINAPI service_main(DWORD dwArgc, LPTSTR *lpszArgv);
--VOID CmdInstallService();
--VOID CmdRemoveService();
-+int CmdInstallService();
-+int CmdRemoveService();
-+int CmdStartService();
- VOID CmdDebugService(int argc, char **argv);
- BOOL WINAPI ControlHandler ( DWORD dwCtrlType );
- LPTSTR GetLastErrorText( LPTSTR lpszBuf, DWORD dwSize );
-@@ -64,7 +66,7 @@
- //    main service thread.  When the this call returns,
- //    the service has stopped, so exit.
- //
--void __cdecl main(int argc, char **argv)
-+int __cdecl main(int argc, char **argv)
- {
-    SERVICE_TABLE_ENTRY dispatchTable[] =
-    {
-@@ -77,11 +79,15 @@
-    {
-       if ( _stricmp( "install", argv[1]+1 ) == 0 )
-       {
--         CmdInstallService();
-+         return CmdInstallService();
-       }
-       else if ( _stricmp( "remove", argv[1]+1 ) == 0 )
-       {
--         CmdRemoveService();
-+         return CmdRemoveService();
-+      }
-+        else if ( _stricmp( "start", argv[1]+1 ) == 0)
-+        {
-+                return CmdStartService();
-       }
-       else if ( _stricmp( "debug", argv[1]+1 ) == 0 )
-       {
-@@ -92,7 +98,7 @@
-       {
-          goto dispatch;
-       }
--      exit(0);
-+      return 0;
-    }
-    // if it doesn't match any of the above parameters
-@@ -101,13 +107,16 @@
-    dispatch:
-    // this is just to be friendly
-    printf( "%s -install          to install the service\n", SZAPPNAME );
-+   printf( "%s -start                  to start the service\n", SZAPPNAME );
-    printf( "%s -remove           to remove the service\n", SZAPPNAME );
-    printf( "%s -debug <params>   to run as a console app for debugging\n", SZAPPNAME );
-    printf( "\nStartServiceCtrlDispatcher being called.\n" );
-    printf( "This may take several seconds.  Please wait.\n" );
-    if (!StartServiceCtrlDispatcher(dispatchTable))
--      AddToMessageLog(TEXT("StartServiceCtrlDispatcher failed."));
-+      AddToMessageLog(MSG_FLAGS_ERROR, TEXT("StartServiceCtrlDispatcher failed."));
-+
-+   return 0;
- }
-@@ -267,7 +276,7 @@
-       //
-       if (!(fResult = SetServiceStatus( sshStatusHandle, &ssStatus)))
-       {
--         AddToMessageLog(TEXT("SetServiceStatus"));
-+         AddToMessageLog(MSG_FLAGS_ERROR, TEXT("SetServiceStatus"));
-       }
-    }
-    return fResult;
-@@ -288,28 +297,33 @@
- //
- //  COMMENTS:
- //
--VOID AddToMessageLog(LPTSTR lpszMsg)
-+void AddToMessageLog(DWORD flags, LPTSTR lpszMsg)
- {
-    TCHAR szMsg [(sizeof(SZSERVICENAME) / sizeof(TCHAR)) + 100 ];
-    HANDLE  hEventSource;
--   LPTSTR  lpszStrings[2];
-+   LPCSTR  lpszStrings[2];
-    if ( !bDebug )
-    {
-+     if (flags & MSG_FLAGS_SYS_CODE)
-       dwErr = GetLastError();
-+     else
-+       dwErr = 0;
-       // Use event logging to log the error.
-       //
-       hEventSource = RegisterEventSource(NULL, TEXT(SZSERVICENAME));
--      _stprintf(szMsg, TEXT("%s error: %d"), TEXT(SZSERVICENAME), dwErr);
-+      _stprintf(szMsg, TEXT("%s error: %d"), TEXT(SZSERVICENAME), (int)dwErr);
-       lpszStrings[0] = szMsg;
-       lpszStrings[1] = lpszMsg;
-       if (hEventSource != NULL)
-       {
-          ReportEvent(hEventSource, // handle of event source
--                     EVENTLOG_ERROR_TYPE,  // event type
-+                   // event type
-+                     (flags & MSG_FLAGS_ERROR)
-+                     ? EVENTLOG_ERROR_TYPE : EVENTLOG_INFORMATION_TYPE,
-                      0,                    // event category
-                      0,                    // event ID
-                      NULL,                 // current user's SID
-@@ -323,8 +337,10 @@
-    }
- }
--
--
-+void ResetError (void)
-+{
-+  dwErr = 0;
-+}
- ///////////////////////////////////////////////////////////////////
- //
-@@ -341,21 +357,23 @@
- //    none
- //
- //  RETURN VALUE:
--//    none
-+//    0 if success
- //
- //  COMMENTS:
- //
--void CmdInstallService()
-+int CmdInstallService()
- {
-    SC_HANDLE   schService;
-    SC_HANDLE   schSCManager;
-    TCHAR szPath[512];
-+   int ret = 0;
-+
-    if ( GetModuleFileName( NULL, szPath, 512 ) == 0 )
-    {
-       _tprintf(TEXT("Unable to install %s - %s\n"), TEXT(SZSERVICEDISPLAYNAME), GetLastErrorText(szErr, 256));
--      return;
-+      return 1;
-    }
-    schSCManager = OpenSCManager(
-@@ -371,7 +389,7 @@
-                                 TEXT(SZSERVICEDISPLAYNAME), // name to display
-                                 SERVICE_QUERY_STATUS,         // desired access
-                                 SERVICE_WIN32_OWN_PROCESS,  // service type
--                                SERVICE_DEMAND_START,       // start type
-+                              SERVICE_DEMAND_START,        // start type -- alternative: SERVICE_AUTO_START
-                                 SERVICE_ERROR_NORMAL,       // error control type
-                                 szPath,                     // service's binary
-                                 NULL,                       // no load ordering group
-@@ -388,16 +406,79 @@
-       else
-       {
-          _tprintf(TEXT("CreateService failed - %s\n"), GetLastErrorText(szErr, 256));
-+       ret = 1;
-       }
-       CloseServiceHandle(schSCManager);
-    }
-    else
-+     {
-       _tprintf(TEXT("OpenSCManager failed - %s\n"), GetLastErrorText(szErr,256));
-+       ret = 1;
-+     }
-+   return ret;
- }
-+//
-+//  FUNCTION: CmdStartService()
-+//
-+//  PURPOSE: Start the service
-+//
-+//  PARAMETERS:
-+//    none
-+//
-+//  RETURN VALUE:
-+//    0 if success
-+//
-+//  COMMENTS:
-+
-+int CmdStartService()
-+{
-+  int ret = 0;
-+
-+  SC_HANDLE schSCManager;
-+  SC_HANDLE schService;
-+    // Open a handle to the SC Manager database. 
-+    schSCManager = OpenSCManager( 
-+       NULL,                    // local machine 
-+       NULL,                    // ServicesActive database 
-+       SC_MANAGER_ALL_ACCESS);  // full access rights 
-+   
-+    if (NULL == schSCManager) {
-+       _tprintf(TEXT("OpenSCManager failed - %s\n"), GetLastErrorText(szErr,256));
-+       ret = 1;
-+    }
-+
-+    schService = OpenService( 
-+        schSCManager,          // SCM database 
-+        SZSERVICENAME,         // service name
-+        SERVICE_ALL_ACCESS); 
-+
-+    if (schService == NULL) {
-+      _tprintf(TEXT("OpenService failed - %s\n"), GetLastErrorText(szErr,256));
-+       ret = 1;
-+    }
-+ 
-+    if (!StartService(
-+            schService,  // handle to service 
-+            0,           // number of arguments 
-+            NULL) )      // no arguments 
-+    {
-+      _tprintf(TEXT("StartService failed - %s\n"), GetLastErrorText(szErr,256));
-+       ret = 1;
-+    }
-+    else
-+      {
-+              _tprintf(TEXT("Service Started\n"));
-+       ret = 0;
-+      }
-+    CloseServiceHandle(schService); 
-+    CloseServiceHandle(schSCManager);
-+    return ret;
-+}
-+
- //
- //  FUNCTION: CmdRemoveService()
- //
-@@ -407,15 +488,17 @@
- //    none
- //
- //  RETURN VALUE:
--//    none
-+//    0 if success
- //
- //  COMMENTS:
- //
--void CmdRemoveService()
-+int CmdRemoveService()
- {
-    SC_HANDLE   schService;
-    SC_HANDLE   schSCManager;
-+   int ret = 0;
-+
-    schSCManager = OpenSCManager(
-                                NULL,                   // machine (NULL == local)
-                                NULL,                   // database (NULL == default)
-@@ -447,7 +530,10 @@
-             if ( ssStatus.dwCurrentState == SERVICE_STOPPED )
-                _tprintf(TEXT("\n%s stopped.\n"), TEXT(SZSERVICEDISPLAYNAME) );
-             else
-+            {
-                _tprintf(TEXT("\n%s failed to stop.\n"), TEXT(SZSERVICEDISPLAYNAME) );
-+              ret = 1;
-+            }
-          }
-@@ -455,18 +541,28 @@
-          if ( DeleteService(schService) )
-             _tprintf(TEXT("%s removed.\n"), TEXT(SZSERVICEDISPLAYNAME) );
-          else
-+         {
-             _tprintf(TEXT("DeleteService failed - %s\n"), GetLastErrorText(szErr,256));
-+           ret = 1;
-+         }
-          CloseServiceHandle(schService);
-       }
-       else
-+      {
-          _tprintf(TEXT("OpenService failed - %s\n"), GetLastErrorText(szErr,256));
-+        ret = 1;
-+      }
-       CloseServiceHandle(schSCManager);
-    }
-    else
-+     {
-       _tprintf(TEXT("OpenSCManager failed - %s\n"), GetLastErrorText(szErr,256));
-+       ret = 1;
-+     }
-+   return ret;
- }
-@@ -587,7 +683,7 @@
-    else
-    {
-       lpszTemp[lstrlen(lpszTemp)-2] = TEXT('\0');  //remove cr and newline character
--      _stprintf( lpszBuf, TEXT("%s (0x%x)"), lpszTemp, GetLastError() );
-+      _stprintf( lpszBuf, TEXT("%s (0x%x)"), lpszTemp, (int)GetLastError() );
-    }
-    if ( lpszTemp )
---- service.h.orig     Tue Apr 24 14:49:30 2007
-+++ service.h  Tue Apr 24 11:58:48 2007
-@@ -57,18 +57,19 @@
- extern "C" {
- #endif
-+#include "../autodefs/defs.h"
- //////////////////////////////////////////////////////////////////////////////
- //// todo: change to desired strings
- ////
- // name of the executable
--#define SZAPPNAME            "Simple"
-+#define SZAPPNAME            PRODUCT_UNIX_NAME "serv"
- // internal name of the service
--#define SZSERVICENAME        "SimpleService"
-+#define SZSERVICENAME        PRODUCT_NAME "Service"
- // displayed name of the service
--#define SZSERVICEDISPLAYNAME "Simple Service"
-+#define SZSERVICEDISPLAYNAME PRODUCT_NAME " Service"
- // list of service dependencies - "dep1\0dep2\0\0"
--#define SZDEPENDENCIES       ""
-+#define SZDEPENDENCIES       PRODUCT_TAP_ID "\0Dhcp\0\0"
- //////////////////////////////////////////////////////////////////////////////
-@@ -126,7 +127,10 @@
- //  RETURN VALUE:
- //    none
- //
--   void AddToMessageLog(LPTSTR lpszMsg);
-+#  define MSG_FLAGS_ERROR     (1<<0)
-+#  define MSG_FLAGS_SYS_CODE  (1<<1)
-+   void AddToMessageLog(DWORD flags, LPTSTR lpszMsg);
-+   void ResetError (void);
- //////////////////////////////////////////////////////////////////////////////
index 66c24429de1a6dd4bc13f5d84290fe671ae79813..158a6cf03f5402a7f5620e4327de68fd5f136d23 100644 (file)
  * it is called the key_id and is currently 2 bits long.
  */
 
-#ifdef WIN32
-#include "config-win32.h"
-#else
-#include "config.h"
-#endif
+#include "syshead.h"
 
 #if defined(USE_CRYPTO) && defined(USE_SSL)
 
-#include "syshead.h"
-
 #include "error.h"
 #include "common.h"
 #include "crypto.h"
index f3b06cb898fc1a625089ad57313e5d90930a42e8..2024cda3f3508e0b17e392a60dce732be75b5f91 100644 (file)
--- a/shaper.c
+++ b/shaper.c
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#ifdef WIN32
-#include "config-win32.h"
-#else
-#include "config.h"
-#endif
 #include "syshead.h"
 #include "shaper.h"
 #include "memdbg.h"
diff --git a/sig.c b/sig.c
index 9d8756b54f7a62cc9ffc41a2a0acdbb8d5a08241..58c37b30ceca98b0565bf734601b6c2f86e3c1bc 100644 (file)
--- a/sig.c
+++ b/sig.c
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#ifdef WIN32
-#include "config-win32.h"
-#else
-#include "config.h"
-#endif
-
 #include "syshead.h"
 
 #include "buffer.h"
index e9cc1aedbc06cc9f08ee015c34779c79c4e6b6ab..78686efcfaf4400839a01e371c6062c7121aad5e 100644 (file)
--- a/socket.c
+++ b/socket.c
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#ifdef WIN32
-#include "config-win32.h"
-#else
-#include "config.h"
-#endif
-
 #include "syshead.h"
 
 #include "socket.h"
@@ -138,6 +132,9 @@ getaddr (unsigned int flags,
       while (true)
        {
          /* try hostname lookup */
+#if defined(HAVE_RES_INIT)
+         res_init ();
+#endif
          h = gethostbyname (hostname);
 
          if (signal_received)
@@ -2121,11 +2118,13 @@ link_socket_read_tcp (struct link_socket *sock,
 
 #if ENABLE_IP_PKTINFO
 
+#pragma pack(1) /* needed to keep structure size consistent for 32 vs. 64-bit architectures */
 struct openvpn_pktinfo
 {
   struct cmsghdr cmsghdr;
   struct in_pktinfo in_pktinfo;
 };
+#pragma pack()
 
 static socklen_t
 link_socket_read_udp_posix_recvmsg (struct link_socket *sock,
diff --git a/socks.c b/socks.c
index cc9d82f29e7586923fc33e3db457bd9359f4d0d1..79e11707556bd486c9974ced8419e8bbc228b86e 100644 (file)
--- a/socks.c
+++ b/socks.c
  * see RFC 1928, only supports "no authentication"
  */
 
-#ifdef WIN32
-#include "config-win32.h"
-#else
-#include "config.h"
-#endif
+#include "syshead.h"
 
 #ifdef ENABLE_SOCKS
 
-#include "syshead.h"
-
 #include "common.h"
 #include "misc.h"
 #include "win32.h"
diff --git a/ssl.c b/ssl.c
index c587b8cff61ca008ad1248814d4b271e48284f82..4cc6b768ca9f1b16a40be6e5128f58d183f9569e 100644 (file)
--- a/ssl.c
+++ b/ssl.c
  * over the same TCP/UDP port.
  */
 
-#ifdef WIN32
-#include "config-win32.h"
-#else
-#include "config.h"
-#endif
+#include "syshead.h"
 
 #if defined(USE_CRYPTO) && defined(USE_SSL)
 
-#include "syshead.h"
-
 #include "ssl.h"
 #include "error.h"
 #include "common.h"
@@ -1210,7 +1204,7 @@ init_ssl (const struct options *options)
       if (options->pkcs11_providers[0])
         {
          /* Load Certificate and Private Key */
-        if (!SSL_CTX_use_pkcs11 (ctx, options->pkcs11_id))
+        if (!SSL_CTX_use_pkcs11 (ctx, options->pkcs11_id_management, options->pkcs11_id))
           {
             msg (M_WARN, "Cannot load certificate \"%s\" using PKCS#11 interface", options->pkcs11_id);
             goto err;
index da1be143b0f309dd1840364c86e1a3d8187e1810..d18641ebb47e993fdb13df1d6ade29ef3406d4c2 100644 (file)
--- a/status.c
+++ b/status.c
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#ifdef WIN32
-#include "config-win32.h"
-#else
-#include "config.h"
-#endif
-
 #include "syshead.h"
 
 #include "status.h"
index 2a29ee025de2007652396b25a8631454118c751b..58e59c631baad13c57485c163102b180e7c8b673 100644 (file)
--- a/syshead.h
+++ b/syshead.h
 #ifndef SYSHEAD_H
 #define SYSHEAD_H
 
+/*
+ * Only include if not during configure
+ */
+#ifndef PACKAGE_NAME
+#ifdef _MSC_VER
+#include "config-win32.h"
+#else
+#include "config.h"
+#endif
+#endif
+
+#if defined(_WIN32) && !defined(WIN32)
+#define WIN32
+#endif
+
+#ifdef WIN32
+#include <windows.h>
+#define sleep(x) Sleep((x)*1000)
+#define random rand
+#define srandom srand
+#endif
+
 #ifdef HAVE_SYS_TYPES_H
 #include <sys/types.h>
 #endif
 #include <netinet/in.h>
 #endif
 
+#ifdef HAVE_RESOLV_H
+#include <resolv.h>
+#endif
+
 #ifdef HAVE_SYS_POLL_H
 #include <sys/poll.h>
 #endif
 
 #endif /* TARGET_NETBSD */
 
+#ifdef TARGET_DRAGONFLY
+
+#ifdef HAVE_SYS_UIO_H
+#include <sys/uio.h>
+#endif
+
+#ifdef HAVE_NETINET_IN_SYSTM_H
+#include <netinet/in_systm.h>
+#endif
+
+#ifdef HAVE_NETINET_IP_H
+#include <netinet/ip.h>
+#endif
+
+#ifdef HAVE_NET_TUN_IF_TUN_H
+#include <net/tun/if_tun.h>
+#endif
+
+#endif /* TARGET_DRAGONFLY */
+
 #ifdef WIN32
 #include <iphlpapi.h>
-#include <WinInet.h>
+#include <wininet.h>
 #endif
 
 #ifdef HAVE_SYS_MMAN_H
index df2024d637ee221d3f0c473c8558867af35e1dab..93e4750edd6ed0c02d512a0ef8af15a1f1174d8c 100755 (executable)
 // common to both.
 //===============================================
 
-#include "../autodefs/defs.h"
+#if defined(HAVE_CONFIG_H)
+#include "config.h"
+#else
+#if defined(_MSC_VER) && !defined(TAP_DRIVER_MAJOR_VERSION)
+#include "config-win32.h"
+#else
+#include "../config.h"
+#endif
+#endif
 
 //=============
 // TAP IOCTLs
@@ -81,4 +89,4 @@
 // simultaneously.
 //=========================================================
 
-#define TAP_COMPONENT_ID PRODUCT_TAP_ID
+#define TAP_COMPONENT_ID TAP_ID
index dc246c1c71f697fd61ba00e6fc6cd2298d0afa0e..e8d924795dbf2cd2fb5319800b79f02ee6ed3c64 100644 (file)
--- a/thread.c
+++ b/thread.c
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#ifdef WIN32
-#include "config-win32.h"
-#else
-#include "config.h"
-#endif
-
 #include "syshead.h"
 
 #ifdef USE_PTHREAD
diff --git a/tun.c b/tun.c
index 349a4dec239e967d8392e85fc83fe8d0421cccd3..3877ca8faf7b42f6c8ee722ca7e4e70ed724f9cb 100644 (file)
--- a/tun.c
+++ b/tun.c
  * from VTun by Maxim Krasnyansky <max_mk@yahoo.com>.
  */
 
-#ifdef WIN32
-#include "config-win32.h"
-#else
-#include "config.h"
-#endif
-
 #include "syshead.h"
 
 #include "tun.h"
@@ -799,7 +793,7 @@ do_ifconfig (struct tuntap *tt,
          add_route (&r, tt, 0, es);
        }
 
-#elif defined(TARGET_FREEBSD)
+#elif defined(TARGET_FREEBSD)||defined(TARGET_DRAGONFLY)
 
       /* example: ifconfig tun2 10.2.0.2 10.2.0.1 mtu 1450 netmask 255.255.255.255 up */
       if (tun)
@@ -1248,7 +1242,7 @@ close_tun (struct tuntap *tt)
              }
 #else
            openvpn_snprintf (command_line, sizeof (command_line),
-                       IFCONFIG_PATH "%s addr 0.0.0.0",
+                       IFCONFIG_PATH " %s 0.0.0.0",
                        tt->actual_name
                        );
 #endif
@@ -1753,6 +1747,89 @@ read_tun (struct tuntap* tt, uint8_t *buf, int len)
     return read (tt->fd, buf, len);
 }
 
+#elif defined(TARGET_DRAGONFLY)
+
+static inline int
+dragonfly_modify_read_write_return (int len)
+{
+  if (len > 0)
+    return len > sizeof (u_int32_t) ? len - sizeof (u_int32_t) : 0;
+  else
+    return len;
+}
+
+void
+open_tun (const char *dev, const char *dev_type, const char *dev_node, bool ipv6, struct tuntap *tt)
+{
+  open_tun_generic (dev, dev_type, dev_node, ipv6, true, true, tt);
+
+  if (tt->fd >= 0)
+    {
+      int i = 0;
+
+      /* Disable extended modes */
+      ioctl (tt->fd, TUNSLMODE, &i);
+      i = 1;
+      ioctl (tt->fd, TUNSIFHEAD, &i);
+    }
+}
+
+void
+close_tun (struct tuntap *tt)
+{
+  if (tt)
+    {
+      close_tun_generic (tt);
+      free (tt);
+    }
+}
+
+int
+write_tun (struct tuntap* tt, uint8_t *buf, int len)
+{
+  if (tt->type == DEV_TYPE_TUN)
+    {
+      u_int32_t type;
+      struct iovec iv[2];
+      struct ip *iph;
+
+      iph = (struct ip *) buf;
+
+      if (tt->ipv6 && iph->ip_v == 6)
+        type = htonl (AF_INET6);
+      else 
+        type = htonl (AF_INET);
+
+      iv[0].iov_base = (char *)&type;
+      iv[0].iov_len = sizeof (type);
+      iv[1].iov_base = buf;
+      iv[1].iov_len = len;
+
+      return dragonfly_modify_read_write_return (writev (tt->fd, iv, 2));
+    }
+  else
+    return write (tt->fd, buf, len);
+}
+
+int
+read_tun (struct tuntap* tt, uint8_t *buf, int len)
+{
+  if (tt->type == DEV_TYPE_TUN)
+    {
+      u_int32_t type;
+      struct iovec iv[2];
+
+      iv[0].iov_base = (char *)&type;
+      iv[0].iov_len = sizeof (type);
+      iv[1].iov_base = buf;
+      iv[1].iov_len = len;
+
+      return dragonfly_modify_read_write_return (readv (tt->fd, iv, 2));
+    }
+  else
+    return read (tt->fd, buf, len);
+}
+
 #elif defined(WIN32)
 
 int
index fd4de2d407bed29a7902fc18b4a6ebb18f8bfef8..4a1335c4931746a0591c60cd7d244bba1f2fe1e4 100644 (file)
@@ -1,2 +1,6 @@
 dnl define the OpenVPN version
-define(PRODUCT_VERSION,[2.1_rc7b])
+define(PRODUCT_VERSION,[2.1_rc7c])
+dnl define the TAP version
+define(PRODUCT_TAP_ID,[tap0901])
+define(PRODUCT_TAP_WIN32_MIN_MAJOR,[9])
+define(PRODUCT_TAP_WIN32_MIN_MINOR,[1])
diff --git a/win32.c b/win32.c
index f9a80fc2715747d2079ec6c038845a7de840e683..dde1ef7daec0c411e6f61c1813c54c2db1742dcf 100644 (file)
--- a/win32.c
+++ b/win32.c
  * Win32-specific OpenVPN code, targetted at the mingw
  * development environment.
  */
+#include "syshead.h"
 
 #ifdef WIN32
 
-#include "config-win32.h"
-
-#include "syshead.h"
 #include "buffer.h"
 #include "error.h"
 #include "mtu.h"