Hello!

Attached are 2 usability patches for password authentication on Windows, one for OpenVPN 2.0.0 and OpenVPN-GUI 1.0.

The patches provide the following functionality:
You can provide predefined usernames for password authentication, backward compatibility is guaranteed.

It looks like the following:

Client Config looks like:
=========================
# Ask for username and password
auth-user-pass user.up

# Optionally the win32-gui switch can be set (see for combinations below)
win32-gui

user.up contains:
=================
username
password or stdin or gui (stdin and gui are reserverd keywords)

When password is set, the password is taken.
When stdin or gui is set as the password the user is asked to provide the password only (The username is not queried or is already predefined in the GUI dialog and the focus is set to the password text field).

# Usefull combinations are:
# disabled win32-gui with auth-user-pass username/gui (Best)
============================================================
OpenVPN Userauthentication Dialog (only one dialog appears) with the following information:

Username: gerhard (predefined as from user.up!!!)
Password: Enter the password here

When a private key password is set, it is also queried.

Username is taken from user.up

# win32-gui with auth-user-pass username/stdin  (Best)
======================================================
The following dialog pops up:
Enter Auth Password for user gerhard: Enter the username here

When a private key password is set, it is also queried.

Username is taken from user.up

# win32-gui with auth-user-pass username/gui
============================================
Enter Auth Username [gerhard]: Enter the username here
Enter Auth Password: Enter the password here

When a private key password is set, it is also queried.

# Useless combinations are:
# disabled win32-gui with auth-user-pass username/stdin
=======================================================
OpenVPN is blocked, since the GUI waits for input from stdin, but nothing usefull is sent.

Server side looks like:
=======================
plugin /usr/share/openvpn/plugin/lib/openvpn-auth-pam.so login

It has been tested with MinGW compiler, Windows 2000 and Linux as a server unpatched (2.0.0).

Please let me know whether you integrate the patches in the upcoming OpenVPN 2.0.1 release.

Comments are welcome.

Ciao,
Gerhard
diff -Nur orig\openvpn-2.0\chartable.h openvpn-2.0\chartable.h
--- orig\openvpn-2.0\chartable.h        Thu Jan 01 01:00:00 1970
+++ openvpn-2.0\chartable.h     Sat Apr 30 13:10:18 2005
@@ -0,0 +1,286 @@
+/*
+ *  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 <i...@openvpn.net>
+ *
+ *  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
+ *  (at your option) any later version.
+ *
+ *  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
+ */
+#ifdef WIN32
+ 
+WCHAR unicode_to_ascii[256] = {
+0x0000,
+0x0001,
+0x0002,
+0x0003,
+0x0004,
+0x0005,
+0x0006,
+0x0007,
+0x0008,
+0x0009,
+0x000a,
+0x000b,
+0x000c,
+0x000d,
+0x000e,
+0x000f,
+0x0010,
+0x0011,
+0x0012,
+0x0013,
+0x0014,
+0x0015,
+0x0016,
+0x0017,
+0x0018,
+0x0019,
+0x001a,
+0x001b,
+0x001c,
+0x001d,
+0x001e,
+0x001f,
+0x0020,
+0x0021,
+0x0022,
+0x0023,
+0x0024,
+0x0025,
+0x0026,
+0x0027,
+0x0028,
+0x0029,
+0x002a,
+0x002b,
+0x002c,
+0x002d,
+0x002e,
+0x002f,
+0x0030,
+0x0031,
+0x0032,
+0x0033,
+0x0034,
+0x0035,
+0x0036,
+0x0037,
+0x0038,
+0x0039,
+0x003a,
+0x003b,
+0x003c,
+0x003d,
+0x003e,
+0x003f,
+0x0040,
+0x0041,
+0x0042,
+0x0043,
+0x0044,
+0x0045,
+0x0046,
+0x0047,
+0x0048,
+0x0049,
+0x004a,
+0x004b,
+0x004c,
+0x004d,
+0x004e,
+0x004f,
+0x0050,
+0x0051,
+0x0052,
+0x0053,
+0x0054,
+0x0055,
+0x0056,
+0x0057,
+0x0058,
+0x0059,
+0x005a,
+0x005b,
+0x005c,
+0x005d,
+0x005e,
+0x005f,
+0x0060,
+0x0061,
+0x0062,
+0x0063,
+0x0064,
+0x0065,
+0x0066,
+0x0067,
+0x0068,
+0x0069,
+0x006a,
+0x006b,
+0x006c,
+0x006d,
+0x006e,
+0x006f,
+0x0070,
+0x0071,
+0x0072,
+0x0073,
+0x0074,
+0x0075,
+0x0076,
+0x0077,
+0x0078,
+0x0079,
+0x007a,
+0x007b,
+0x007c,
+0x007d,
+0x007e,
+0x007f,
+0x00c7,
+0x00fc,
+0x00e9,
+0x00e2,
+0x00e4,
+0x00e0,
+0x00e5,
+0x00e7,
+0x00ea,
+0x00eb,
+0x00e8,
+0x00ef,
+0x00ee,
+0x00ec,
+0x00c4,
+0x00c5,
+0x00c9,
+0x00e6,
+0x00c6,
+0x00f4,
+0x00f6,
+0x00f2,
+0x00fb,
+0x00f9,
+0x00ff,
+0x00d6,
+0x00dc,
+0x00f8,
+0x00a3,
+0x00d8,
+0x00d7,
+0x0192,
+0x00e1,
+0x00ed,
+0x00f3,
+0x00fa,
+0x00f1,
+0x00d1,
+0x00aa,
+0x00ba,
+0x00bf,
+0x00ae,
+0x00ac,
+0x00bd,
+0x00bc,
+0x00a1,
+0x00ab,
+0x00bb,
+0x2591,
+0x2592,
+0x2593,
+0x2502,
+0x2524,
+0x00c1,
+0x00c2,
+0x00c0,
+0x00a9,
+0x2563,
+0x2551,
+0x2557,
+0x255d,
+0x00a2,
+0x00a5,
+0x2510,
+0x2514,
+0x2534,
+0x252c,
+0x251c,
+0x2500,
+0x253c,
+0x00e3,
+0x00c3,
+0x255a,
+0x2554,
+0x2569,
+0x2566,
+0x2560,
+0x2550,
+0x256c,
+0x00a4,
+0x00f0,
+0x00d0,
+0x00ca,
+0x00cb,
+0x00c8,
+0x0131,
+0x00cd,
+0x00ce,
+0x00cf,
+0x2518,
+0x250c,
+0x2588,
+0x2584,
+0x00a6,
+0x00cc,
+0x2580,
+0x00d3,
+0x00df,
+0x00d4,
+0x00d2,
+0x00f5,
+0x00d5,
+0x00b5,
+0x00fe,
+0x00de,
+0x00da,
+0x00db,
+0x00d9,
+0x00fd,
+0x00dd,
+0x00af,
+0x00b4,
+0x00ad,
+0x00b1,
+0x2017,
+0x00be,
+0x00b6,
+0x00a7,
+0x00f7,
+0x00b8,
+0x00b0,
+0x00a8,
+0x00b7,
+0x00b9,
+0x00b3,
+0x00b2,
+0x25a0,
+0x00a0
+};
+
+#endif
diff -Nur orig\openvpn-2.0\config-win32.h openvpn-2.0\config-win32.h
--- orig\openvpn-2.0\config-win32.h     Mon Apr 18 04:02:04 2005
+++ openvpn-2.0\config-win32.h  Sat Apr 30 14:22:59 2005
@@ -64,6 +64,7 @@
 
 /* Allow --askpass and --auth-user-pass passwords to be read from a file */
 /* #undef ENABLE_PASSWORD_SAVE */
+#define ENABLE_PASSWORD_SAVE 1
 
 /* Enable client/server capability */
 #define ENABLE_CLIENT_SERVER 1
@@ -221,7 +222,7 @@
 #define PACKAGE_TARNAME "openvpn"
 
 /* Define to the version of this package. */
-#define PACKAGE_VERSION "2.0" /* AUTO_VERSION */
+#define PACKAGE_VERSION "2.0-GUI" /* AUTO_VERSION */
 
 /* Define to the full name and version of this package. */
 #ifdef DEBUG_LABEL
diff -Nur orig\openvpn-2.0\makefile-GUI.w32 openvpn-2.0\makefile-GUI.w32
--- orig\openvpn-2.0\makefile-GUI.w32   Thu Jan 01 01:00:00 1970
+++ openvpn-2.0\makefile-GUI.w32        Sat Apr 30 14:21:38 2005
@@ -0,0 +1,212 @@
+# 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.
+
+OPENSSL = /c/src/openssl-0.9.7f
+LZO = /c/src/lzo-1.08
+DMALLOC = /c/src/dmalloc-5.4.2
+
+# Local Build environment
+OPENSSL = ../openssl-0.9.7g
+LZO = ../lzo-1.08
+
+#########################################################
+
+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}/include -I${LZO}/include
+
+INCLUDE_DIRS_DMALLOC = ${INCLUDE_DIRS} -I${DMALLOC}
+
+LIBS = -llzo -lcrypt32 -lws2_32 -lgdi32 -liphlpapi -lwinmm
+
+LIBS_DMALLOC = ${LIBS} -ldmalloc
+
+LIB_DIRS = -L${OPENSSL}/out -L${LZO}/src/.libs
+
+LIB_DIRS_DMALLOC = ${LIB_DIRS} -L${DMALLOC}
+
+WINDRES = windres.exe
+
+EXE = openvpn.exe
+
+HEADERS = \
+       base64.h \
+       basic.h \
+       buffer.h \
+       circ_list.h \
+       chartable.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 \
+       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 \
+        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 \
+       win32gui.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 \
+       lzo.o \
+       manage.o \
+       mbuf.o \
+       misc.o \
+       mroute.o \
+       mss.o \
+       mtcp.o \
+       mtu.o \
+       mudp.o \
+       multi.o \
+       ntlm.o \
+       occ.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 \
+       win32gui.o \
+       win32gui.res
+
+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 $@
+
+win32gui.res : win32gui.rc win32gui-res.h
+       $(WINDRES) -i win32gui.rc -o win32gui.res -O coff
+
+#      $(WINDRES) -i win32gui.rc -J rc -o win32gui.res -O coff
diff -Nur orig\openvpn-2.0\misc.c openvpn-2.0\misc.c
--- orig\openvpn-2.0\misc.c     Mon Apr 11 05:43:57 2005
+++ openvpn-2.0\misc.c  Mon May 02 22:34:48 2005
@@ -1245,8 +1245,36 @@
       
          if (!password_only && strlen (up->username) == 0)
            msg (M_FATAL, "ERROR: username from %s authfile '%s' is empty", 
prefix, auth_file);
-       }
 
+         if (streq (up->password, "stdin"))
+         {
+               struct buffer user_pass_prompt = alloc_buf_gc (256, &gc);
+
+               buf_printf (&user_pass_prompt,  "Enter %s Password for user %s:"
+                       , prefix, up->username);
+
+               if (!get_console_input (BSTR (&user_pass_prompt), false, 
up->password, USER_PASS_LEN))
+                       msg (M_FATAL, "ERROR: could not not read %s password 
from stdin", prefix);
+         }
+         else if (streq (up->password, "gui"))
+         {
+                 struct buffer user_prompt = alloc_buf_gc (128, &gc);
+                 struct buffer pass_prompt = alloc_buf_gc (128, &gc);
+
+                 buf_printf (&user_prompt, "Enter %s Username [%s]:", prefix, 
up->username);
+                 buf_printf (&pass_prompt, "Enter %s Password:", prefix);
+
+                 if (!get_console_input (BSTR (&user_prompt), true, 
up->username, USER_PASS_LEN))
+                       msg (M_FATAL, "ERROR: could not read %s username from 
stdin", prefix);
+
+                 if (strlen (up->username) == 0)
+                       msg (M_FATAL, "ERROR: %s username is empty", prefix);
+
+                 if (!get_console_input (BSTR (&pass_prompt), false, 
up->password, USER_PASS_LEN))
+                       msg (M_FATAL, "ERROR: could not not read %s password 
from stdin", prefix);
+       
+          }
+       }
       string_mod (up->username, CC_PRINT, CC_CRLF, 0);
       string_mod (up->password, CC_PRINT, CC_CRLF, 0);
 
diff -Nur orig\openvpn-2.0\options.c openvpn-2.0\options.c
--- orig\openvpn-2.0\options.c  Sun Apr 17 00:03:15 2005
+++ openvpn-2.0\options.c       Sat Apr 30 13:16:21 2005
@@ -29,6 +29,7 @@
 
 #ifdef WIN32
 #include "config-win32.h"
+#include "win32gui.h"
 #else
 #include "config.h"
 #endif
@@ -484,6 +485,7 @@
   "                       signaled, will cause " PACKAGE_NAME " to exit.  A 
second\n"
   "                       optional parameter controls the initial state of 
ex.\n"
   "--show-net-up   : Show " PACKAGE_NAME "'s view of routing table and net 
adapter list\n"
+  "--win32-gui     : Get user input via a GUI dialog instead of console 
window.\n"
   "                  after TAP adapter is up and routes have been added.\n"
   "Windows Standalone Options:\n"
   "\n"
@@ -4030,6 +4032,11 @@
          ++i;
          options->exit_event_initial_state = (atoi(p[2]) != 0);
        }
+    }
+  else if (streq (p[0], "win32-gui"))
+    {
+      VERIFY_PERMISSION (OPT_P_GENERAL);
+      enable_userinput_via_dialog_win32();
     }
   else if (streq (p[0], "user") && p[1])
     {
diff -Nur orig\openvpn-2.0\win32.c openvpn-2.0\win32.c
--- orig\openvpn-2.0\win32.c    Mon Apr 11 05:43:58 2005
+++ openvpn-2.0\win32.c Sat Apr 30 13:09:07 2005
@@ -37,6 +37,7 @@
 #include "mtu.h"
 #include "sig.h"
 #include "win32.h"
+#include "win32gui.h"
 
 #include "memdbg.h"
 
@@ -683,7 +684,7 @@
 }
 
 /*
- * Get input from console.
+ * Get input from console or a dialog(--win32-gui).
  *
  * Return false on input error, or if service
  * exit event is signaled.
@@ -704,6 +705,9 @@
 
   in = GetStdHandle (STD_INPUT_HANDLE);
   err = get_orig_stderr ();
+
+  if (use_userinput_dialog_win32())
+    return get_userinput_dialog_win32(prompt, input, capacity);
 
   if (in != INVALID_HANDLE_VALUE
       && err != INVALID_HANDLE_VALUE
diff -Nur orig\openvpn-2.0\win32gui-res.h openvpn-2.0\win32gui-res.h
--- orig\openvpn-2.0\win32gui-res.h     Thu Jan 01 01:00:00 1970
+++ openvpn-2.0\win32gui-res.h  Sat Apr 30 13:11:02 2005
@@ -0,0 +1,29 @@
+/*
+ *  OpenVPN -- An application to securely tunnel IP networks
+ *             over a single TCP/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 <i...@openvpn.net>
+ *
+ *  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
+ *  (at your option) any later version.
+ *
+ *  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
+ */
+
+/* Ask for User Input Dialog */
+#define        IDD_USERINPUT                   100
+#define        EDIT_TEXTBOX                    101
+#define TEXT_LABEL                      102
diff -Nur orig\openvpn-2.0\win32gui.c openvpn-2.0\win32gui.c
--- orig\openvpn-2.0\win32gui.c Thu Jan 01 01:00:00 1970
+++ openvpn-2.0\win32gui.c      Sat Apr 30 13:13:41 2005
@@ -0,0 +1,153 @@
+/*
+ *  OpenVPN -- An application to securely tunnel IP networks
+ *             over a single TCP/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 <i...@openvpn.net>
+ *
+ *  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
+ *  (at your option) any later version.
+ *
+ *  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
+ */
+
+/* This file contains code to get user input from
+ * a windows dialog instead of the console window.
+ * Written by Mathias Sundman, Mar 02, 2005.
+ */
+
+#ifdef WIN32
+
+#include "config-win32.h"
+#include "basic.h"
+#include "win32gui-res.h"
+#include "chartable.h"
+#include <windows.h>
+
+int get_userinput_from_dialog = 0;
+
+struct user_input
+{
+  char response[100];
+  char prompt[100];
+};
+
+int ConvertUnicode2Ascii(WCHAR str_unicode[], char str_ascii[], unsigned int 
str_ascii_size)
+{
+  unsigned int i;
+  unsigned int j;
+  int illegal_chars = false;
+  char *str_unicode_ptr = (char *) str_unicode;
+  for (i=0; (i < wcslen(str_unicode)) && (i < (str_ascii_size - 1)); i++)
+    {
+      for (j=0; j <= 256; j++)
+        {
+          if (j == 256)
+            {
+              illegal_chars = true;
+              j = 0x2e;
+              break;
+            }
+          if (str_unicode[i] == unicode_to_ascii[j]) break;
+        }
+      str_ascii[i] = (char) j;
+   }
+  str_ascii[i] = '\0';
+
+  if (illegal_chars)
+    return(false);
+  else
+    return(true);
+} 
+
+BOOL CALLBACK UserInputDialogFunc (HWND hwndDlg, UINT msg, WPARAM wParam, 
LPARAM lParam)
+{
+  static struct user_input *user_input;
+  static char empty_string[100];
+  WCHAR unicode_input[100];
+
+  switch (msg) {
+
+    case WM_INITDIALOG:
+      user_input = (struct user_input *) lParam;
+      SetDlgItemText(hwndDlg, TEXT_LABEL, user_input->prompt);
+      SetForegroundWindow(hwndDlg);
+      break;
+
+    case WM_COMMAND:
+      switch (LOWORD(wParam)) {
+
+        case IDOK:                     // button
+          GetDlgItemTextW(hwndDlg, EDIT_TEXTBOX, unicode_input, 
sizeof(unicode_input)/2 - 1);
+
+          /* Convert user input from Unicode to Ascii (CP850) */
+          ConvertUnicode2Ascii(unicode_input, user_input->response, 
sizeof(user_input->response) - 1); 
+
+          /* Clear buffers */
+          SetDlgItemText(hwndDlg, EDIT_TEXTBOX, empty_string);
+         CLEAR(unicode_input);
+
+          EndDialog(hwndDlg, LOWORD(wParam));
+          return TRUE;
+
+        case IDCANCEL:
+          EndDialog(hwndDlg, LOWORD(wParam));
+          return TRUE;
+      }
+      break;
+    case WM_CLOSE:
+      EndDialog(hwndDlg, LOWORD(wParam));
+      return TRUE;
+     
+  }
+  return FALSE;
+}
+
+int
+get_userinput_dialog_win32(const char *prompt, char *input, const int capacity)
+{
+
+  struct user_input user_input;
+
+  CLEAR (user_input);
+  strncpy(user_input.prompt, prompt, sizeof(user_input.prompt));
+
+  Sleep(200);
+  if (DialogBoxParam(NULL, (LPCTSTR)IDD_USERINPUT, NULL, 
+     (DLGPROC)UserInputDialogFunc, (LPARAM)&user_input) == IDCANCEL)
+    { 
+      CLEAR(user_input);
+      return false;
+    }
+
+  strncpy(input, user_input.response, capacity);
+  CLEAR(user_input);
+  return true;
+}
+
+void
+enable_userinput_via_dialog_win32()
+{
+  get_userinput_from_dialog = 1;
+}
+
+int
+use_userinput_dialog_win32()
+{
+  return get_userinput_from_dialog;
+}
+
+#endif
+
diff -Nur orig\openvpn-2.0\win32gui.h openvpn-2.0\win32gui.h
--- orig\openvpn-2.0\win32gui.h Thu Jan 01 01:00:00 1970
+++ openvpn-2.0\win32gui.h      Sat Apr 30 13:11:43 2005
@@ -0,0 +1,32 @@
+/*
+ *  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 <i...@openvpn.net>
+ *
+ *  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
+ *  (at your option) any later version.
+ *
+ *  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
+ */
+
+#ifdef WIN32
+
+int get_userinput_dialog_win32(const char *prompt, char *input, const int 
capacity);
+int use_userinput_dialog_win32();
+void enable_userinput_via_dialog_win32();
+
+#endif
diff -Nur orig\openvpn-2.0\win32gui.rc openvpn-2.0\win32gui.rc
--- orig\openvpn-2.0\win32gui.rc        Thu Jan 01 01:00:00 1970
+++ openvpn-2.0\win32gui.rc     Mon May 02 23:03:25 2005
@@ -0,0 +1,39 @@
+/*
+ *  OpenVPN -- An application to securely tunnel IP networks
+ *             over a single TCP/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 <i...@openvpn.net>
+ *
+ *  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
+ *  (at your option) any later version.
+ *
+ *  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
+ */
+
+#include "win32gui-res.h"
+#include <windows.h>
+
+IDD_USERINPUT DIALOGEX 6, 18, 160, 51
+STYLE WS_POPUP | WS_VISIBLE | WS_CAPTION | DS_CENTER | DS_SETFOREGROUND
+EXSTYLE WS_EX_TOPMOST
+CAPTION "OpenVPN"
+FONT 8, "MS Sans Serif"
+BEGIN
+    LTEXT           "", TEXT_LABEL, 6, 6, 147, 10
+    EDITTEXT        EDIT_TEXTBOX, 6, 17, 147, 12, ES_PASSWORD | ES_AUTOHSCROLL
+    PUSHBUTTON      "OK", IDOK, 26, 33, 50, 14
+    PUSHBUTTON      "Cancel", IDCANCEL, 84, 33, 50, 14
+END
diff -Nur orig\openvpn-gui-1.0\Makefile openvpn-gui-1.0\Makefile
--- orig\openvpn-gui-1.0\Makefile       Thu Apr 21 11:33:06 2005
+++ openvpn-gui-1.0\Makefile    Mon May 02 07:54:55 2005
@@ -1,6 +1,6 @@
 # This makefile builds OpenVPN-GUI using the mingw environment.
 
-OPENSSL = /c/OpenSSL
+OPENSSL = /c/work/C/OpenVPN/openssl-0.9.7g
 
 RES_LANG = en
 GUI_VERSION = 1.0
@@ -16,7 +16,7 @@
         openvpn_config.o scripts.o openvpn-gui-$(RES_LANG).res
 
 INCLUDE_DIRS = -I. -I${OPENSSL}/include
-LIB_DIRS = -L${OPENSSL}/lib/MinGW
+LIB_DIRS = -L${OPENSSL}
 
 WARNS = -W -Wall -Wfloat-equal -Wundef -Wshadow -Wpointer-arith 
-Wbad-function-cast \
        -Wcast-align -Wwrite-strings -Wconversion -Wsign-compare \
diff -Nur orig\openvpn-gui-1.0\passphrase.c openvpn-gui-1.0\passphrase.c
--- orig\openvpn-gui-1.0\passphrase.c   Wed Jan 12 15:58:28 2005
+++ openvpn-gui-1.0\passphrase.c        Mon May 02 22:17:46 2005
@@ -151,10 +151,31 @@
   DWORD nCharsWritten;
   struct user_auth user_auth;
 
+  unsigned int auth_len = 21;
+
+  int old_auth = (strncmp(line, "Enter Auth Username:", 20) == 0);
+  int new_auth = (strncmp(line, "Enter Auth Username [", auth_len) == 0);
+
   /* Check for Passphrase prompt */
-  if (strncmp(line, "Enter Auth Username:", 20) == 0) 
+  if (old_auth || new_auth) 
     {
       CLEAR(user_auth);  
+
+      if (new_auth)
+      {
+        char* usernamebegin = line + auth_len;
+        char* usernameend = strchr(line, ']');
+
+        if (usernameend)
+        {
+          unsigned int len = usernameend - usernamebegin;
+
+          if (len > sizeof(user_auth.username)) len = 
sizeof(user_auth.username);
+
+          strncpy(user_auth.username, usernamebegin, len);
+        }
+      }
+      
       if (DialogBoxParam(o.hInstance, 
                          (LPCTSTR)IDD_AUTH_PASSWORD,
                          NULL,
@@ -266,6 +287,14 @@
 
     case WM_INITDIALOG:
       user_auth = (struct user_auth *) lParam;
+
+      SetDlgItemText(hwndDlg, EDIT_AUTH_USERNAME, user_auth->username);
+
+      if (strlen(user_auth->username) > 0)
+      {
+        SetFocus(GetDlgItem(hwndDlg, EDIT_AUTH_PASSWORD));
+      }
+
       SetForegroundWindow(hwndDlg);
       break;
 

Reply via email to