Skip to contentSkip to conversation

MSVC fixes

Openvpn-devel In review Heiko Hund 6 participants 37 messages Feb 16, 2012 – Jun 29, 2012

lore
Share & tools
lore

Heiko Hund

author
#0 lore raw

Hi,

this patch series fixes several issues when building for Windows with the MSVC buildsystem discovered today:

[PATCH 1/4] replace check for TARGET_WIN32 with WIN32 [PATCH 2/4] do not use mode_t on Windows
[PATCH 3/4] use the underscore version of stat on Windows [PATCH 4/4] make MSVC link against shell32 as well

For details check the commit messages of the individual patches.

Regards
Heiko

Signature · 8 lines
Heiko Hund | Software Engineer | Phone +49-721-25516-237 | Fax -200
Astaro a Sophos Company | Amalienbadstr. 41 Bau 52 | 76227 Karlsruhe | Germany
Commercial Register: Mannheim HRA 702710 | Headquarter Location: Karlsruhe
 
Represented by the General Partner Astaro Verwaltungs GmbH
Amalienbadstraße 41 Bau 52 | 76227 Karlsruhe | Germany 
Commercial Register: Mannheim HRB 708248 | Executive Board: Gert Hansen,
Markus Hennig, Jan Hichert, Günter Junk, Dr. Frank Nellissen
author
#1 lore raw

PATCH 1/4 replace check for TARGET_WIN32 with WIN32

Use of TARGET_WIN32 breaks MSVC builds as it is only defined for mingw builds done with the autotools buildsystem.

---
 misc.c    |    6 +++---
 misc.h    |    6 +++---
 openvpn.c |    2 +-
 3 files changed, 7 insertions(+), 7 deletions(-)
misc.c +3 -3
index 58096fa..a07780f 100644
@@ -356,7 +356,7 @@ int
 openvpn_chdir (const char* dir)
 {
 #ifdef HAVE_CHDIR
-#ifdef TARGET_WIN32
+#ifdef WIN32
   int res;
   struct gc_arena gc = gc_new ();
   res = _wchdir (wide_string (dir, &gc));
@@ -598,7 +598,7 @@ openvpn_system (const char *command, const struct env_set *es, unsigned int flag
   /*
    * execute the command
    */
-#ifdef TARGET_WIN32
+#ifdef WIN32
   gc = gc_new ();
   ret = _wsystem (wide_string (command, &gc));
   gc_free (&gc);
@@ -627,7 +627,7 @@ openvpn_system (const char *command, const struct env_set *es, unsigned int flag
 int
 openvpn_access (const char *path, int mode)
 {
-#ifdef TARGET_WIN32
+#ifdef WIN32
   struct gc_arena gc = gc_new ();
   int ret = _waccess (wide_string (path, &gc), mode);
   gc_free (&gc);
misc.h +3 -3
index 2413f53..8c0bae1 100644
@@ -147,7 +147,7 @@ openvpn_run_script (const struct argv *a, const struct env_set *es, const unsign
   return openvpn_execve_check(a, es, flags | S_SCRIPT, msg);
 };
 
-#ifdef TARGET_WIN32
+#ifdef WIN32
 FILE * openvpn_fopen (const char *path, const char *mode);
 #else
 static inline FILE *
@@ -157,7 +157,7 @@ openvpn_fopen (const char *path, const char *mode)
 }
 #endif
 
-#ifdef TARGET_WIN32
+#ifdef WIN32
 int openvpn_open (const char *path, int flags, mode_t mode);
 #else
 static inline int
@@ -167,7 +167,7 @@ openvpn_open (const char *path, int flags, mode_t mode)
 }
 #endif
 
-#ifdef TARGET_WIN32
+#ifdef WIN32
 int openvpn_stat (const char *path, struct stat *buf);
 #else
 static inline int
openvpn.c +1 -1
index 84289d2..b2175a1 100644
@@ -131,7 +131,7 @@ main (int argc, char *argv[])
   return 1;
 #endif
 
-#ifdef TARGET_WIN32
+#ifdef WIN32
   SetConsoleOutputCP (CP_UTF8);
 #endif
 
Signature · 1 line
1.7.5.4
#2 lore raw

Re: [Openvpn-devel] [PATCH 1/4] replace check for TARGET_WIN32 with WIN32

Hi,

Quoted 2 lines · Heiko Hund

Use of TARGET_WIN32 breaks MSVC builds as it is only defined for mingw builds done with the autotools buildsystem.

ACK. I think it's reasonable to have exactly one CPP symbol to identify "building in the windows 32bit environment".

I have no particular preference, and there are less TARGET_WIN32s in the code - so get rid of that one :-)

(Yes, we should get rid of all the windows build cruft, but the focus for now is "have something that *builds* and can be tagged as 2.3-alpha1").

gert

Signature · 4 lines
USENET is *not* the non-clickable part of WWW!
                                                           //www.muc.de/~gert/
Gert Doering - Munich, Germany                             [email protected]...
fax: +49-89-35655025                        [email protected]...
author
#3 lore raw

PATCH 2/4 do not use mode_t on Windows

In reply to Heiko Hund

The MSVC headers do not define mode_t. open() uses an int for the permissions instead. Fixes building with the MSVC based buildsystem.

---
 misc.h  |    2 +-
 win32.c |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
misc.h +1 -1
index 8c0bae1..e7a0b55 100644
@@ -158,7 +158,7 @@ openvpn_fopen (const char *path, const char *mode)
 #endif
 
 #ifdef WIN32
-int openvpn_open (const char *path, int flags, mode_t mode);
+int openvpn_open (const char *path, int flags, int mode);
 #else
 static inline int
 openvpn_open (const char *path, int flags, mode_t mode)
win32.c +1 -1
index 5b38918..a8f4ed9 100644
@@ -1064,7 +1064,7 @@ openvpn_fopen (const char *path, const char *mode)
 }
 
 int
-openvpn_open (const char *path, int flags, mode_t mode)
+openvpn_open (const char *path, int flags, int mode)
 {
   struct gc_arena gc = gc_new ();
   int fd = _wopen (wide_string (path, &gc), flags, mode);
Signature · 1 line
1.7.5.4
#4 lore raw

Re: [Openvpn-devel] [PATCH 2/4] do not use mode_t on Windows

Hi,

Quoted 3 lines · Heiko Hund

The MSVC headers do not define mode_t. open() uses an int for the permissions instead. Fixes building with the MSVC based buildsystem.

ACK.

(I was slightly worried that this might break mingw building, but David assures me that you've tested this :-) ).

gert

Signature · 4 lines
USENET is *not* the non-clickable part of WWW!
                                                           //www.muc.de/~gert/
Gert Doering - Munich, Germany                             [email protected]...
fax: +49-89-35655025                        [email protected]...
#5 lore raw

Re: [Openvpn-devel] [PATCH 2/4] do not use mode_t on Windows

In reply to Heiko Hund

I stopped following all OpenVPN changes.
It seems like more changes are entered than should without proper review.

Anyway, this is not the correct solution. Correct solution is to have config-msvc.h and have:
---
#define mode_t int
---

And in autoconf (if mingw does not have this as well):
AC_CHECK_DECLS(

    [mode_t],
    ,
    [AC_DEFINE([mode_t],[int], [Emulate mode_t])],
    [[
        #include <fcntl.h>
    ]]

)

Quoted 50 lines · Heiko Hund

The MSVC headers do not define mode_t. open() uses an int for the permissions instead. Fixes building with the MSVC based buildsystem.

---
 misc.h  |    2 +-
 win32.c |    2 +-

 2 files changed, 2 insertions(+), 2 deletions(-)
misc.h +1 -1
index 8c0bae1..e7a0b55 100644
@@ -158,7 +158,7 @@ openvpn_fopen (const char *path, const char *mode)
  #endif
 
  #ifdef WIN32
-int openvpn_open (const char *path, int flags, mode_t mode);
+int openvpn_open (const char *path, int flags, int mode);
  #else

 static inline int
 openvpn_open (const char *path, int flags, mode_t mode)

win32.c +0 -0
index 5b38918..a8f4ed9 100644
@@ -1064,7 +1064,7 @@ openvpn_fopen (const char *path, const char *mode)
  }
 

 int

win32.c +1 -1
-openvpn_open (const char *path, int flags, mode_t mode)
+openvpn_open (const char *path, int flags, int mode)

 {
  struct gc_arena gc = gc_new ();
  int fd = _wopen (wide_string (path, &gc), flags, mode); --
1.7.5.4

------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning Cloud computing makes use of virtualization - but cloud computing also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
Openvpn-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

author
#6 lore raw

Re: [Openvpn-devel] [PATCH 2/4] do not use mode_t on Windows

Alon,

Quoted 4 lines · On Thursday 16 February 2012 18:34:34 Alon Bar-Lev wrote:

Anyway, this is not the correct solution. Correct solution is to have config-msvc.h and have:
---
#define mode_t int

I don't think that a MSVC specific header will do good. mode_t shouldn't actually be used in mingw either, even if they define it. I stumbled over such glue code a couple of times and the only reason I can come up with why they have it is backwards compatibility with old code. So it's rather a general WIN32 thing. And I absolutely agree that putting all the WIN32 stuff into win32.[ch] would make the code prettier. I just don't feel enough itch to approach this scratching myself.

Heiko

Signature · 8 lines
Heiko Hund | Software Engineer | Phone +49-721-25516-237 | Fax -200
Astaro a Sophos Company | Amalienbadstr. 41 Bau 52 | 76227 Karlsruhe | Germany
Commercial Register: Mannheim HRA 702710 | Headquarter Location: Karlsruhe
 
Represented by the General Partner Astaro Verwaltungs GmbH
Amalienbadstraße 41 Bau 52 | 76227 Karlsruhe | Germany 
Commercial Register: Mannheim HRB 708248 | Executive Board: Gert Hansen,
Markus Hennig, Jan Hichert, Günter Junk, Dr. Frank Nellissen
#7 lore raw

Re: [Openvpn-devel] [PATCH 2/4] do not use mode_t on Windows

Quoted 8 lines · Heiko Hund

Alon,

Quoted 4 lines · On Thursday 16 February 2012 18:34:34 Alon Bar-Lev wrote:

Anyway, this is not the correct solution. Correct solution is to have config-msvc.h and have:
---
#define mode_t int

Quoted 8 lines

I don't think that a MSVC specific header will do good. mode_t shouldn't actually be used in mingw either, even if they define it. I stumbled over such glue code a couple of times and the only reason I can come up with why they have it is backwards compatibility with old code. So it's rather a general WIN32 thing. And I absolutely agree that putting all the WIN32 stuff into win32.[ch] would make the code prettier. I just don't feel enough itch to approach this scratching myself.

You will be surprised how mingw is better in this sense. Anyway, as I wrote commit whatever you need for now, we will clean up the build system soon.

Alon.

author
#8 lore raw

PATCH 3/4 use the underscore version of stat on Windows

In reply to Heiko Hund

MSVC does not know wstat(). Instead _wstat() must be used here. Unfortunately _wstat() takes a 'struct _stat'. A type 'stat_t' is introduced to handle this situation in a portable way.

---
 misc.h  |    6 ++++--
 pf.c    |    2 +-
 win32.c |    4 ++--
 3 files changed, 7 insertions(+), 5 deletions(-)
misc.h +4 -2
index e7a0b55..55d494f 100644
@@ -168,10 +168,12 @@ openvpn_open (const char *path, int flags, mode_t mode)
 #endif
 
 #ifdef WIN32
-int openvpn_stat (const char *path, struct stat *buf);
+typedef struct _stat stat_t;
+int openvpn_stat (const char *path, stat_t *buf);
 #else
+typedef struct stat stat_t;
 static inline int
-openvpn_stat (const char *path, struct stat *buf)
+openvpn_stat (const char *path, stat_t *buf)
 {
   return stat (path, buf);
 }
pf.c +1 -1
index a0e9fc8..67cd28f 100644
@@ -498,7 +498,7 @@ pf_check_reload (struct context *c)
       && c->c2.pf.filename
       && event_timeout_trigger (&c->c2.pf.reload, &c->c2.timeval, ETT_DEFAULT))
     {
-      struct stat s;
+      stat_t s;
       if (!openvpn_stat (c->c2.pf.filename, &s))
 	{
 	  if (s.st_mtime > c->c2.pf.file_last_mod)
win32.c +2 -2
index a8f4ed9..4efc8df 100644
@@ -1073,10 +1073,10 @@ openvpn_open (const char *path, int flags, int mode)
 }
 
 int
-openvpn_stat (const char *path, struct stat *buf)
+openvpn_stat (const char *path, stat_t *buf)
 {
   struct gc_arena gc = gc_new ();
-  int res = wstat (wide_string (path, &gc), buf);
+  int res = _wstat (wide_string (path, &gc), buf);
   gc_free (&gc);
   return res;
 }
Signature · 1 line
1.7.5.4
#9 lore raw

Re: [Openvpn-devel] [PATCH 3/4] use the underscore version of stat on Windows

Hi,

Quoted 3 lines · Heiko Hund

MSVC does not know wstat(). Instead _wstat() must be used here. Unfortunately _wstat() takes a 'struct _stat'. A type 'stat_t' is introduced to handle this situation in a portable way.

Semi-ACK.

In general, ACK, though it might be a bit easier to understand the code if there were an explantory comment at the typedef, and the type would be called "openvpn_stat_t" or such - so that when referenced in pf.c, it's clear that this is not something "from the build environment" but "local".

gert

Signature · 4 lines
USENET is *not* the non-clickable part of WWW!
                                                           //www.muc.de/~gert/
Gert Doering - Munich, Germany                             [email protected]...
fax: +49-89-35655025                        [email protected]...
#10 lore raw

PATCH v2 1/1 use the underscore version of stat on Windows

From: Heiko Hund <[email protected]...>

MSVC does not know wstat(). Instead _wstat() must be used here. Unfortunately _wstat() takes a 'struct _stat'. A type 'stat_t' is introduced to handle this situation in a portable way.

[v2: Use openvpn_stat_t instead of stat_t (David Sommerseth)]

---
 misc.h  |    6 ++++--
 pf.c    |    2 +-
 win32.c |    4 ++--
 3 files changed, 7 insertions(+), 5 deletions(-)
misc.h +4 -2
index e7a0b55..bdada42 100644
@@ -168,10 +168,12 @@ openvpn_open (const char *path, int flags, mode_t mode)
 #endif
 
 #ifdef WIN32
-int openvpn_stat (const char *path, struct stat *buf);
+typedef struct _stat openvpn_stat_t;
+int openvpn_stat (const char *path, openvpn_stat_t *buf);
 #else
+typedef struct stat openvpn_stat_t;
 static inline int
-openvpn_stat (const char *path, struct stat *buf)
+openvpn_stat (const char *path, openvpn_stat_t *buf)
 {
   return stat (path, buf);
 }
pf.c +1 -1
index a0e9fc8..0ef839e 100644
@@ -498,7 +498,7 @@ pf_check_reload (struct context *c)
       && c->c2.pf.filename
       && event_timeout_trigger (&c->c2.pf.reload, &c->c2.timeval, ETT_DEFAULT))
     {
-      struct stat s;
+      openvpn_stat_t s;
       if (!openvpn_stat (c->c2.pf.filename, &s))
 	{
 	  if (s.st_mtime > c->c2.pf.file_last_mod)
win32.c +2 -2
index a8f4ed9..2ba97fc 100644
@@ -1073,10 +1073,10 @@ openvpn_open (const char *path, int flags, int mode)
 }
 
 int
-openvpn_stat (const char *path, struct stat *buf)
+openvpn_stat (const char *path, openvpn_stat_t *buf)
 {
   struct gc_arena gc = gc_new ();
-  int res = wstat (wide_string (path, &gc), buf);
+  int res = _wstat (wide_string (path, &gc), buf);
   gc_free (&gc);
   return res;
 }
Signature · 1 line
1.7.4.4
#11 lore raw

Re: [Openvpn-devel] [PATCH v2] use the underscore version of stat on Windows

Hi,

Quoted 10 lines · David Sommerseth

From: Heiko Hund <[email protected]...>

MSVC does not know wstat(). Instead _wstat() must be used here. Unfortunately _wstat() takes a 'struct _stat'. A type 'stat_t' is introduced to handle this situation in a portable way.

[v2: Use openvpn_stat_t instead of stat_t (David Sommerseth)]

ACK!

gert

Signature · 4 lines
USENET is *not* the non-clickable part of WWW!
                                                           //www.muc.de/~gert/
Gert Doering - Munich, Germany                             [email protected]...
fax: +49-89-35655025                        [email protected]...
#12 lore raw

Re: [Openvpn-devel] [PATCH v2] use the underscore version of stat on Windows

In reply to David Sommerseth

Again,
All conditional statements should be within single config.h or config-msvc.h or sysheader.h or anything.
Doing conditional inline makes code complex and unmaintainable. But as you adds loooooooong patches without proper review I guess it is not that important.
Alon.

Quoted 78 lines · David Sommerseth

From: Heiko Hund <[email protected]...>

MSVC does not know wstat(). Instead _wstat() must be used here. Unfortunately _wstat() takes a 'struct _stat'. A type 'stat_t' is introduced to handle this situation in a portable way.

[v2: Use openvpn_stat_t instead of stat_t (David Sommerseth)]

---
 misc.h  |    6 ++++--
 pf.c    |    2 +-
 win32.c |    4 ++--

 3 files changed, 7 insertions(+), 5 deletions(-)
misc.h +3 -1
index e7a0b55..bdada42 100644
@@ -168,10 +168,12 @@ openvpn_open (const char *path, int flags, mode_t mode)
  #endif
 
  #ifdef WIN32
-int openvpn_stat (const char *path, struct stat *buf);
+typedef struct _stat openvpn_stat_t;
+int openvpn_stat (const char *path, openvpn_stat_t *buf);
  #else
+typedef struct stat openvpn_stat_t;

 static inline int

misc.h +1 -1
-openvpn_stat (const char *path, struct stat *buf)
+openvpn_stat (const char *path, openvpn_stat_t *buf)

 {
  return stat (path, buf);
 }

pf.c +0 -0
index a0e9fc8..0ef839e 100644
@@ -498,7 +498,7 @@ pf_check_reload (struct context *c)

      && c->c2.pf.filename
      && event_timeout_trigger (&c->c2.pf.reload, &c->c2.timeval, ETT_DEFAULT)) {
-      struct stat s;
+      openvpn_stat_t s;
      if (!openvpn_stat (c->c2.pf.filename, &s))
       {
         if (s.st_mtime > c->c2.pf.file_last_mod)

win32.c +0 -0
index a8f4ed9..2ba97fc 100644
@@ -1073,10 +1073,10 @@ openvpn_open (const char *path, int flags, int mode)
  }
 

 int

win32.c +1 -1
-openvpn_stat (const char *path, struct stat *buf)
+openvpn_stat (const char *path, openvpn_stat_t *buf)

 {
  struct gc_arena gc = gc_new ();
-  int res = wstat (wide_string (path, &gc), buf);
+  int res = _wstat (wide_string (path, &gc), buf); gc_free (&gc);
  return res;
 }
--
1.7.4.4

------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning Cloud computing makes use of virtualization - but cloud computing also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
Openvpn-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

author
#13 lore raw

PATCH 4/4 make MSVC link against shell32 as well

In reply to Heiko Hund

Windows API CommandLineToArgvW(), introduced in Windows unicode path commit 71bbbd76c62630c88441237d72fe5b61f0b45b2a, is defined therein.

---
 win/msvc.mak.in |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
win/msvc.mak.in +1 -1
index 115e395..191f370 100644
@@ -31,7 +31,7 @@ LZO_DYNAMIC = lzo2.lib
 
 INCLUDE_DIRS = -I$(OPENSSL)/include -I$(POLARSSL)/include -I$(LZO)/include -I$(PKCS11_HELPER)/include
 
-LIBS = $(OPENSSL_DYNAMIC) $(POLARSSL_DYNAMIC) $(PKCS11_HELPER_DYNAMIC) $(LZO_DYNAMIC) ws2_32.lib crypt32.lib iphlpapi.lib winmm.lib user32.lib gdi32.lib advapi32.lib wininet.lib
+LIBS = $(OPENSSL_DYNAMIC) $(POLARSSL_DYNAMIC) $(PKCS11_HELPER_DYNAMIC) $(LZO_DYNAMIC) ws2_32.lib crypt32.lib iphlpapi.lib winmm.lib user32.lib gdi32.lib advapi32.lib wininet.lib shell32.lib
 
 LIB_DIRS = -LIBPATH:$(OPENSSL)\lib -LIBPATH:$(POLARSSL)\build\library -LIBPATH:$(PKCS11_HELPER)\lib -LIBPATH:$(LZO)\lib
 
Signature · 1 line
1.7.5.4
#14 lore raw

Re: [Openvpn-devel] [PATCH 4/4] make MSVC link against shell32 as well

Hi,

Quoted 4 lines · Heiko Hund

Windows API CommandLineToArgvW(), introduced in Windows unicode path commit 71bbbd76c62630c88441237d72fe5b61f0b45b2a, is defined therein.

Since you've tested it and it makes Samuli happy -> ACK :-)

gert

Signature · 4 lines
USENET is *not* the non-clickable part of WWW!
                                                           //www.muc.de/~gert/
Gert Doering - Munich, Germany                             [email protected]...
fax: +49-89-35655025                        [email protected]...
#15 lore raw

Re: [Openvpn-devel] [PATCH 4/4] make MSVC link against shell32 as well

In reply to Heiko Hund
Quoted 2 lines · Heiko Hund

Windows API CommandLineToArgvW(), introduced in Windows unicode path commit 71bbbd76c62630c88441237d72fe5b61f0b45b2a, is defined therein.

Usually this should be avoided and get command-line from wmain().

author
#16 lore raw

Re: [Openvpn-devel] [PATCH 4/4] make MSVC link against shell32 as well

Alon,

Quoted 5 lines · On Thursday 16 February 2012 18:37:21 Alon Bar-Lev wrote:
Quoted 2 lines · Heiko Hund

Windows API CommandLineToArgvW(), introduced in Windows unicode path commit 71bbbd76c62630c88441237d72fe5b61f0b45b2a, is defined therein.

Usually this should be avoided and get command-line from wmain().

the general idea is to make Unicode things happen without changing the openvpn code too much in a very Windows specific way. Converting UCS-2 to UTF-8 directly where input and output is happening and passing it through the rest of openvpn as char* does that. I don't see any benefit in converting openvpn into a native unicode binary.

Regards
Heiko

Signature · 8 lines
Heiko Hund | Software Engineer | Phone +49-721-25516-237 | Fax -200
Astaro a Sophos Company | Amalienbadstr. 41 Bau 52 | 76227 Karlsruhe | Germany
Commercial Register: Mannheim HRA 702710 | Headquarter Location: Karlsruhe
 
Represented by the General Partner Astaro Verwaltungs GmbH
Amalienbadstraße 41 Bau 52 | 76227 Karlsruhe | Germany 
Commercial Register: Mannheim HRB 708248 | Executive Board: Gert Hansen,
Markus Hennig, Jan Hichert, Günter Junk, Dr. Frank Nellissen
#17 lore raw

Re: [Openvpn-devel] [PATCH 4/4] make MSVC link against shell32 as well

Quoted 7 lines · Heiko Hund

Alon,

Quoted 4 lines · On Thursday 16 February 2012 18:37:21 Alon Bar-Lev wrote:
Quoted 2 lines · Heiko Hund

Windows API CommandLineToArgvW(), introduced in Windows unicode path commit 71bbbd76c62630c88441237d72fe5b61f0b45b2a, is defined therein.

Quoted 7 lines
Quoted 1 line

Usually this should be avoided and get command-line from wmain().

the general idea is to make Unicode things happen without changing the openvpn code too much in a very Windows specific way. Converting UCS-2 to UTF-8 directly where input and output is happening and passing it through the rest of openvpn as char* does that. I don't see any benefit in converting openvpn into a native unicode binary.

I agree.
Compiling entry point as wmain and not main is not bigger change than any other change in the unicode patch.
Anyway as it seem we have an opportunity window to cleanup the mess, so apply whatever needed in orderer to make it work and then we revise it.
Personally, I don't think this unicode patch was ready to be merged...

Alon.

#18 lore raw

PATCH 1/1 cleanup: windows: convert argv (UCS-2 to UTF-8) at earliest

Discussed at [1].

Use wmain under windows, drop the custom parsing and shell32 linkage.

There is no need for gc magic as this allocation is static.

[1] http://permalink.gmane.org/gmane.network.openvpn.devel/5433

---
 src/openvpn/Makefile.am     |    6 +++++-
 src/openvpn/openvpn.c       |   37 ++++++++++++++++++++++++++++++++++++-
 src/openvpn/openvpn.vcxproj |   10 ++++++----
 src/openvpn/options.c       |   27 ---------------------------
 4 files changed, 47 insertions(+), 33 deletions(-)
 mode change 100644 => 100755 src/openvpn/openvpn.vcxproj
src/openvpn/Makefile.am +5 -1
index 4e485e7..0506b11 100644
@@ -27,6 +27,10 @@ AM_CFLAGS = \
 	$(OPTIONAL_CRYPTO_CFLAGS) \
 	$(OPTIONAL_LZO_CFLAGS) \
 	$(OPTIONAL_PKCS11_HELPER_CFLAGS)
+if WIN32
+# we want unicode entry point but not the macro
+AM_CFLAGS += -municode -UUNICODE
+endif
 
 sbin_PROGRAMS = openvpn
 
@@ -118,5 +122,5 @@ openvpn_LDADD = \
 	$(OPTIONAL_DL_LIBS)
 if WIN32
 openvpn_SOURCES += openvpn_win32_resources.rc
-openvpn_LDADD += -lgdi32 -lws2_32 -lwininet -lcrypt32 -liphlpapi -lwinmm -lshell32
+openvpn_LDADD += -lgdi32 -lws2_32 -lwininet -lcrypt32 -liphlpapi -lwinmm
 endif
src/openvpn/openvpn.c +36 -1
index 3db1b86..6e70a58 100644
@@ -127,8 +127,9 @@ tunnel_point_to_point (struct context *c)
  * @param argc - Commandline argument count.
  * @param argv - Commandline argument values.
  */
+static
 int
-main (int argc, char *argv[])
+openvpn_main (int argc, char *argv[])
 {
   struct context c;
 
@@ -289,3 +290,37 @@ main (int argc, char *argv[])
   openvpn_exit (OPENVPN_EXIT_STATUS_GOOD);  /* exit point */
   return 0;			            /* NOTREACHED */
 }
+
+#ifdef WIN32
+int
+wmain (int argc, wchar_t *wargv[]) {
+  char **argv;
+  int ret;
+  int i;
+
+  if ((argv = calloc(argc+1, sizeof(char*))) == NULL)
+    return 1;
+
+  for (i = 0; i < argc; i++)
+    {
+      int n = WideCharToMultiByte (CP_UTF8, 0, wargv[i], -1, NULL, 0, NULL, NULL);
+      argv[i] = malloc (n);
+      WideCharToMultiByte (CP_UTF8, 0, wargv[i], -1, argv[i], n, NULL, NULL);
+    }
+
+  ret = openvpn_main(argc, argv);
+
+  for (i=0; i < argc; i++ )
+    {
+      free (argv[i]);
+    }
+  free(argv);
+
+  return ret;
+}
+#else
+int
+main (int argc, char *argv[]) {
+	return openvpn_main(argc, argv);
+}
+#endif
src/openvpn/openvpn.vcxproj +6 -4
old mode 100644
new mode 100755
index 51e19af..452876f
@@ -18,12 +18,12 @@
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
     <ConfigurationType>Application</ConfigurationType>
-    <CharacterSet>MultiByte</CharacterSet>
     <WholeProgramOptimization>true</WholeProgramOptimization>
+    <CharacterSet>Unicode</CharacterSet>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
     <ConfigurationType>Application</ConfigurationType>
-    <CharacterSet>MultiByte</CharacterSet>
+    <CharacterSet>Unicode</CharacterSet>
   </PropertyGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
   <ImportGroup Label="ExtensionSettings">
@@ -56,12 +56,13 @@
       </PrecompiledHeader>
       <WarningLevel>Level3</WarningLevel>
       <DebugInformationFormat>EditAndContinue</DebugInformationFormat>
+      <UndefinePreprocessorDefinitions>UNICODE</UndefinePreprocessorDefinitions>
     </ClCompile>
     <ResourceCompile>
       <AdditionalIncludeDirectories>$(SOURCEBASE);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
     </ResourceCompile>
     <Link>
-      <AdditionalDependencies>libeay32.lib;ssleay32.lib;lzo2.lib;pkcs11-helper.dll.lib;gdi32.lib;ws2_32.lib;wininet.lib;crypt32.lib;iphlpapi.lib;winmm.lib;shell32.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalDependencies>libeay32.lib;ssleay32.lib;lzo2.lib;pkcs11-helper.dll.lib;gdi32.lib;ws2_32.lib;wininet.lib;crypt32.lib;iphlpapi.lib;winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
       <AdditionalLibraryDirectories>$(OPENSSL_HOME)/lib;$(LZO_HOME)/lib;$(PKCS11H_HOME)/lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
       <GenerateDebugInformation>true</GenerateDebugInformation>
       <SubSystem>Console</SubSystem>
@@ -80,12 +81,13 @@
       </PrecompiledHeader>
       <WarningLevel>Level3</WarningLevel>
       <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
+      <UndefinePreprocessorDefinitions>UNICODE</UndefinePreprocessorDefinitions>
     </ClCompile>
     <ResourceCompile>
       <AdditionalIncludeDirectories>$(SOURCEBASE);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
     </ResourceCompile>
     <Link>
-      <AdditionalDependencies>libeay32.lib;ssleay32.lib;lzo2.lib;pkcs11-helper.dll.lib;gdi32.lib;ws2_32.lib;wininet.lib;crypt32.lib;iphlpapi.lib;winmm.lib;shell32.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalDependencies>libeay32.lib;ssleay32.lib;lzo2.lib;pkcs11-helper.dll.lib;gdi32.lib;ws2_32.lib;wininet.lib;crypt32.lib;iphlpapi.lib;winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
       <AdditionalLibraryDirectories>$(OPENSSL_HOME)/lib;$(LZO_HOME)/lib;$(PKCS11H_HOME)/lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
       <GenerateDebugInformation>true</GenerateDebugInformation>
       <SubSystem>Console</SubSystem>
src/openvpn/options.c +0 -27
index 25786f6..66241b4 100644
@@ -3832,33 +3832,6 @@ parse_argv (struct options *options,
 {
   int i, j;
 
-#ifdef WIN32
-  /*
-   * Windows replaces Unicode characters in argv[] that are not present
-   * in the current codepage with '?'. Get the wide char command line and
-   * convert it to UTF-8 ourselves.
-   */
-  int wargc;
-  WCHAR **wargv;
-  char **uargv;
-
-  wargv = CommandLineToArgvW (GetCommandLineW (), &wargc);
-  if (wargv == NULL || wargc != argc)
-    usage ();
-
-  uargv = gc_malloc (wargc * sizeof (*uargv), false, &options->gc);
-
-  for (i = 0; i < wargc; i++)
-    {
-      int n = WideCharToMultiByte (CP_UTF8, 0, wargv[i], -1, NULL, 0, NULL, NULL);
-      uargv[i] = gc_malloc (n, false, &options->gc);
-      WideCharToMultiByte (CP_UTF8, 0, wargv[i], -1, uargv[i], n, NULL, NULL);
-    }
-
-  LocalFree (wargv);
-  argv = uargv;
-#endif
-
   /* usage message */
   if (argc <= 1)
     usage ();
Signature · 1 line
1.7.3.4
#19 lore raw

Re: [Openvpn-devel] [PATCH] cleanup: windows: convert argv (UCS-2 to UTF-8) at earliest

Please review/test.

Quoted 184 lines · Alon Bar-Lev

Discussed at [1].

Use wmain under windows, drop the custom parsing and shell32 linkage.

There is no need for gc magic as this allocation is static.

[1] http://permalink.gmane.org/gmane.network.openvpn.devel/5433

---
 src/openvpn/Makefile.am     |    6 +++++- src/openvpn/openvpn.c       |   37 ++++++++++++++++++++++++++++++++++++- src/openvpn/openvpn.vcxproj |   10 ++++++---- src/openvpn/options.c       |   27 ---------------------------

 4 files changed, 47 insertions(+), 33 deletions(-)

 mode change 100644 => 100755 src/openvpn/openvpn.vcxproj

src/openvpn/Makefile.am +4 -0
index 4e485e7..0506b11 100644
@@ -27,6 +27,10 @@ AM_CFLAGS = \
        $(OPTIONAL_CRYPTO_CFLAGS) \
        $(OPTIONAL_LZO_CFLAGS) \
        $(OPTIONAL_PKCS11_HELPER_CFLAGS)
+if WIN32
+# we want unicode entry point but not the macro
+AM_CFLAGS += -municode -UUNICODE
+endif
 

 sbin_PROGRAMS = openvpn

src/openvpn/Makefile.am +0 -0
@@ -118,5 +122,5 @@ openvpn_LDADD = \
        $(OPTIONAL_DL_LIBS)

 if WIN32
 openvpn_SOURCES += openvpn_win32_resources.rc

src/openvpn/Makefile.am +1 -1
-openvpn_LDADD += -lgdi32 -lws2_32 -lwininet -lcrypt32 -liphlpapi -lwinmm -lshell32
+openvpn_LDADD += -lgdi32 -lws2_32 -lwininet -lcrypt32 -liphlpapi -lwinmm

 endif

src/openvpn/openvpn.c +1 -0
index 3db1b86..6e70a58 100644
@@ -127,8 +127,9 @@ tunnel_point_to_point (struct context *c)
  * @param argc - Commandline argument count.
  * @param argv - Commandline argument values.
  */
+static

 int

src/openvpn/openvpn.c +1 -1
-main (int argc, char *argv[])
+openvpn_main (int argc, char *argv[])

 {
  struct context c;

src/openvpn/openvpn.c +0 -0
@@ -289,3 +290,37 @@ main (int argc, char *argv[])

  openvpn_exit (OPENVPN_EXIT_STATUS_GOOD);  /* exit point */ return 0;                                /* NOTREACHED */ }

src/openvpn/openvpn.c +34 -0
+
+#ifdef WIN32
+int
+wmain (int argc, wchar_t *wargv[]) {
+  char **argv;
+  int ret;
+  int i;
+
+  if ((argv = calloc(argc+1, sizeof(char*))) == NULL)
+    return 1;
+
+  for (i = 0; i < argc; i++)
+    {
+      int n = WideCharToMultiByte (CP_UTF8, 0, wargv[i], -1, NULL, 0, NULL, NULL);
+      argv[i] = malloc (n);
+      WideCharToMultiByte (CP_UTF8, 0, wargv[i], -1, argv[i], n, NULL, NULL);
+    }
+
+  ret = openvpn_main(argc, argv);
+
+  for (i=0; i < argc; i++ )
+    {
+      free (argv[i]);
+    }
+  free(argv);
+
+  return ret;
+}
+#else
+int
+main (int argc, char *argv[]) {
+       return openvpn_main(argc, argv);
+}
+#endif
src/openvpn/openvpn.vcxproj +0 -0
old mode 100644
new mode 100755
index 51e19af..452876f
@@ -18,12 +18,12 @@

  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> <ConfigurationType>Application</ConfigurationType>
-    <CharacterSet>MultiByte</CharacterSet> <WholeProgramOptimization>true</WholeProgramOptimization>
+    <CharacterSet>Unicode</CharacterSet>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> <ConfigurationType>Application</ConfigurationType>
-    <CharacterSet>MultiByte</CharacterSet>
+    <CharacterSet>Unicode</CharacterSet>
  </PropertyGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
  <ImportGroup Label="ExtensionSettings">

src/openvpn/openvpn.vcxproj +0 -0
@@ -56,12 +56,13 @@

      </PrecompiledHeader>
      <WarningLevel>Level3</WarningLevel>
      <DebugInformationFormat>EditAndContinue</DebugInformationFormat>
+      <UndefinePreprocessorDefinitions>UNICODE</UndefinePreprocessorDefinitions>
    </ClCompile>
    <ResourceCompile>
      <AdditionalIncludeDirectories>$(SOURCEBASE);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
    </ResourceCompile>
    <Link>
-      <AdditionalDependencies>libeay32.lib;ssleay32.lib;lzo2.lib;pkcs11-helper.dll.lib;gdi32.lib;ws2_32.lib;wininet.lib;crypt32.lib;iphlpapi.lib;winmm.lib;shell32.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalDependencies>libeay32.lib;ssleay32.lib;lzo2.lib;pkcs11-helper.dll.lib;gdi32.lib;ws2_32.lib;wininet.lib;crypt32.lib;iphlpapi.lib;winmm.lib;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalLibraryDirectories>$(OPENSSL_HOME)/lib;$(LZO_HOME)/lib;$(PKCS11H_HOME)/lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> <GenerateDebugInformation>true</GenerateDebugInformation>
      <SubSystem>Console</SubSystem>

src/openvpn/openvpn.vcxproj +0 -0
@@ -80,12 +81,13 @@

      </PrecompiledHeader>
      <WarningLevel>Level3</WarningLevel>
      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
+      <UndefinePreprocessorDefinitions>UNICODE</UndefinePreprocessorDefinitions>
    </ClCompile>
    <ResourceCompile>
      <AdditionalIncludeDirectories>$(SOURCEBASE);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
    </ResourceCompile>
    <Link>
-      <AdditionalDependencies>libeay32.lib;ssleay32.lib;lzo2.lib;pkcs11-helper.dll.lib;gdi32.lib;ws2_32.lib;wininet.lib;crypt32.lib;iphlpapi.lib;winmm.lib;shell32.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalDependencies>libeay32.lib;ssleay32.lib;lzo2.lib;pkcs11-helper.dll.lib;gdi32.lib;ws2_32.lib;wininet.lib;crypt32.lib;iphlpapi.lib;winmm.lib;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalLibraryDirectories>$(OPENSSL_HOME)/lib;$(LZO_HOME)/lib;$(PKCS11H_HOME)/lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> <GenerateDebugInformation>true</GenerateDebugInformation>
      <SubSystem>Console</SubSystem>

src/openvpn/options.c +0 -28
index 25786f6..66241b4 100644
@@ -3832,33 +3832,6 @@ parse_argv (struct options *options,
  {
   int i, j;
 
-#ifdef WIN32
-  /*
-   * Windows replaces Unicode characters in argv[] that are not present
-   * in the current codepage with '?'. Get the wide char command line and
-   * convert it to UTF-8 ourselves.
-   */
-  int wargc;
-  WCHAR **wargv;
-  char **uargv;
-
-  wargv = CommandLineToArgvW (GetCommandLineW (), &wargc);
-  if (wargv == NULL || wargc != argc)
-    usage ();
-
-  uargv = gc_malloc (wargc * sizeof (*uargv), false, &options->gc);
-
-  for (i = 0; i < wargc; i++)
-    {
-      int n = WideCharToMultiByte (CP_UTF8, 0, wargv[i], -1, NULL, 0, NULL, NULL);
-      uargv[i] = gc_malloc (n, false, &options->gc);
-      WideCharToMultiByte (CP_UTF8, 0, wargv[i], -1, uargv[i], n, NULL, NULL);
-    }
-
-  LocalFree (wargv);
-  argv = uargv;
-#endif
-
   /* usage message */
   if (argc <= 1)
     usage ();
--

1.7.3.4

#20 lore raw

Re: [Openvpn-devel] [PATCH] cleanup: windows: convert argv (UCS-2 to UTF-8) at earliest

In reply to Alon Bar-Lev

Hi,

As promised in yesterday's IRC meeting (summary coming today), I tested this patch on Windows 7 (64-bit). So far I've had no luck, but don't think the problems have anything to do with this patch.

Anyways, I cross-compiled latest "master" with this patch applied and "bin" and "lib" directories on top of an existing openvpn-2.3-alpha1 install. The old "bin" directory was renamed to make sure none of it was used. I then renamed "openvpn.ovpn" to "ääliö.ovpn" and "ta.key" to "ääliö.key" using Windows Explorer. Then I updated the configuration file to point to these files using Notepad (and later Wordpad).

OpenVPN-GUI (Heiko's new version) detected the configuration file properly, showing "ääliö" as one available connection option. However, it output the following when trying to connect:

Options error: --tls-auth fails with 'ääliö.key': No such file or
directory

Git Bash showed the file as ??li?.key, which could mean Windows Explorer is using a single-byte character set.

Windows command prompt shows the characters properly, but issuing "openvpn --config ääliö.ovpn" gives the same error as OpenVPN-GUI above, except that 'ääliö.key' shows faulty glyphs[1]. This also triggers an interesting bug in the command prompt[2]

Anyways, as the Windows 7 install is English-language, I suspect it's using a single-byte character set instead of UCS-2. I'll continue debugging, but any pointers are obviously much appreciated!

Samuli

[1] <http://users.utu.fi/sjsepp/cmd.png>
[2] Typing an "ä" or "ö" moves the (invisible) cursor forward one character, but each backspace will delete two characters instead of one. This does not happen until openvpn has been (unsuccessfully) started.

Quoted 181 lines

Discussed at [1].

Use wmain under windows, drop the custom parsing and shell32 linkage.

There is no need for gc magic as this allocation is static.

[1] http://permalink.gmane.org/gmane.network.openvpn.devel/5433

---
 src/openvpn/Makefile.am     |    6 +++++-
 src/openvpn/openvpn.c       |   37 ++++++++++++++++++++++++++++++++++++-
 src/openvpn/openvpn.vcxproj |   10 ++++++----
 src/openvpn/options.c       |   27 ---------------------------
 4 files changed, 47 insertions(+), 33 deletions(-)
 mode change 100644 => 100755 src/openvpn/openvpn.vcxproj
src/openvpn/Makefile.am +5 -1
index 4e485e7..0506b11 100644
@@ -27,6 +27,10 @@ AM_CFLAGS = \
 	$(OPTIONAL_CRYPTO_CFLAGS) \
 	$(OPTIONAL_LZO_CFLAGS) \
 	$(OPTIONAL_PKCS11_HELPER_CFLAGS)
+if WIN32
+# we want unicode entry point but not the macro
+AM_CFLAGS += -municode -UUNICODE
+endif
 
 sbin_PROGRAMS = openvpn
 
@@ -118,5 +122,5 @@ openvpn_LDADD = \
 	$(OPTIONAL_DL_LIBS)
 if WIN32
 openvpn_SOURCES += openvpn_win32_resources.rc
-openvpn_LDADD += -lgdi32 -lws2_32 -lwininet -lcrypt32 -liphlpapi -lwinmm -lshell32
+openvpn_LDADD += -lgdi32 -lws2_32 -lwininet -lcrypt32 -liphlpapi -lwinmm
 endif
src/openvpn/openvpn.c +36 -1
index 3db1b86..6e70a58 100644
@@ -127,8 +127,9 @@ tunnel_point_to_point (struct context *c)
  * @param argc - Commandline argument count.
  * @param argv - Commandline argument values.
  */
+static
 int
-main (int argc, char *argv[])
+openvpn_main (int argc, char *argv[])
 {
   struct context c;
 
@@ -289,3 +290,37 @@ main (int argc, char *argv[])
   openvpn_exit (OPENVPN_EXIT_STATUS_GOOD);  /* exit point */
   return 0;			            /* NOTREACHED */
 }
+
+#ifdef WIN32
+int
+wmain (int argc, wchar_t *wargv[]) {
+  char **argv;
+  int ret;
+  int i;
+
+  if ((argv = calloc(argc+1, sizeof(char*))) == NULL)
+    return 1;
+
+  for (i = 0; i < argc; i++)
+    {
+      int n = WideCharToMultiByte (CP_UTF8, 0, wargv[i], -1, NULL, 0, NULL, NULL);
+      argv[i] = malloc (n);
+      WideCharToMultiByte (CP_UTF8, 0, wargv[i], -1, argv[i], n, NULL, NULL);
+    }
+
+  ret = openvpn_main(argc, argv);
+
+  for (i=0; i < argc; i++ )
+    {
+      free (argv[i]);
+    }
+  free(argv);
+
+  return ret;
+}
+#else
+int
+main (int argc, char *argv[]) {
+	return openvpn_main(argc, argv);
+}
+#endif
src/openvpn/openvpn.vcxproj +6 -4
old mode 100644
new mode 100755
index 51e19af..452876f
@@ -18,12 +18,12 @@
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
     <ConfigurationType>Application</ConfigurationType>
-    <CharacterSet>MultiByte</CharacterSet>
     <WholeProgramOptimization>true</WholeProgramOptimization>
+    <CharacterSet>Unicode</CharacterSet>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
     <ConfigurationType>Application</ConfigurationType>
-    <CharacterSet>MultiByte</CharacterSet>
+    <CharacterSet>Unicode</CharacterSet>
   </PropertyGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
   <ImportGroup Label="ExtensionSettings">
@@ -56,12 +56,13 @@
       </PrecompiledHeader>
       <WarningLevel>Level3</WarningLevel>
       <DebugInformationFormat>EditAndContinue</DebugInformationFormat>
+      <UndefinePreprocessorDefinitions>UNICODE</UndefinePreprocessorDefinitions>
     </ClCompile>
     <ResourceCompile>
       <AdditionalIncludeDirectories>$(SOURCEBASE);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
     </ResourceCompile>
     <Link>
-      <AdditionalDependencies>libeay32.lib;ssleay32.lib;lzo2.lib;pkcs11-helper.dll.lib;gdi32.lib;ws2_32.lib;wininet.lib;crypt32.lib;iphlpapi.lib;winmm.lib;shell32.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalDependencies>libeay32.lib;ssleay32.lib;lzo2.lib;pkcs11-helper.dll.lib;gdi32.lib;ws2_32.lib;wininet.lib;crypt32.lib;iphlpapi.lib;winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
       <AdditionalLibraryDirectories>$(OPENSSL_HOME)/lib;$(LZO_HOME)/lib;$(PKCS11H_HOME)/lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
       <GenerateDebugInformation>true</GenerateDebugInformation>
       <SubSystem>Console</SubSystem>
@@ -80,12 +81,13 @@
       </PrecompiledHeader>
       <WarningLevel>Level3</WarningLevel>
       <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
+      <UndefinePreprocessorDefinitions>UNICODE</UndefinePreprocessorDefinitions>
     </ClCompile>
     <ResourceCompile>
       <AdditionalIncludeDirectories>$(SOURCEBASE);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
     </ResourceCompile>
     <Link>
-      <AdditionalDependencies>libeay32.lib;ssleay32.lib;lzo2.lib;pkcs11-helper.dll.lib;gdi32.lib;ws2_32.lib;wininet.lib;crypt32.lib;iphlpapi.lib;winmm.lib;shell32.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalDependencies>libeay32.lib;ssleay32.lib;lzo2.lib;pkcs11-helper.dll.lib;gdi32.lib;ws2_32.lib;wininet.lib;crypt32.lib;iphlpapi.lib;winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
       <AdditionalLibraryDirectories>$(OPENSSL_HOME)/lib;$(LZO_HOME)/lib;$(PKCS11H_HOME)/lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
       <GenerateDebugInformation>true</GenerateDebugInformation>
       <SubSystem>Console</SubSystem>
src/openvpn/options.c +0 -27
index 25786f6..66241b4 100644
@@ -3832,33 +3832,6 @@ parse_argv (struct options *options,
 {
   int i, j;
 
-#ifdef WIN32
-  /*
-   * Windows replaces Unicode characters in argv[] that are not present
-   * in the current codepage with '?'. Get the wide char command line and
-   * convert it to UTF-8 ourselves.
-   */
-  int wargc;
-  WCHAR **wargv;
-  char **uargv;
-
-  wargv = CommandLineToArgvW (GetCommandLineW (), &wargc);
-  if (wargv == NULL || wargc != argc)
-    usage ();
-
-  uargv = gc_malloc (wargc * sizeof (*uargv), false, &options->gc);
-
-  for (i = 0; i < wargc; i++)
-    {
-      int n = WideCharToMultiByte (CP_UTF8, 0, wargv[i], -1, NULL, 0, NULL, NULL);
-      uargv[i] = gc_malloc (n, false, &options->gc);
-      WideCharToMultiByte (CP_UTF8, 0, wargv[i], -1, uargv[i], n, NULL, NULL);
-    }
-
-  LocalFree (wargv);
-  argv = uargv;
-#endif
-
   /* usage message */
   if (argc <= 1)
     usage ();
#21 lore raw

Re: [Openvpn-devel] [PATCH] cleanup: windows: convert argv (UCS-2 to UTF-8) at earliest

Hello Samuli,

Curios: Did you manage to get it work using master without my patch?

If not, to make it easy...

Use Windows Explorer and rename the key file to something non-ascii. Then open openvpn configuration using UTF-8 editor and modify key file there. This should work, as we do not use unicode/conversion command-line.

Next step would be to remove the key from configuration and use it in command-line.

Alon.

2012/4/27 Samuli Seppänen <[email protected]...>:

Quoted 222 lines

Hi,

As promised in yesterday's IRC meeting (summary coming today), I tested this patch on Windows 7 (64-bit). So far I've had no luck, but don't think the problems have anything to do with this patch.

Anyways, I cross-compiled latest "master" with this patch applied and "bin" and "lib" directories on top of an existing openvpn-2.3-alpha1 install. The old "bin" directory was renamed to make sure none of it was used. I then renamed "openvpn.ovpn" to "ääliö.ovpn" and "ta.key" to "ääliö.key" using Windows Explorer. Then I updated the configuration file to point to these files using Notepad (and later Wordpad).

OpenVPN-GUI (Heiko's new version) detected the configuration file properly, showing "ääliö" as one available connection option. However, it output the following when trying to connect:

   Options error: --tls-auth fails with 'ääliö.key': No such file or directory

Git Bash showed the file as ??li?.key, which could mean Windows Explorer is using a single-byte character set.

Windows command prompt shows the characters properly, but issuing "openvpn --config ääliö.ovpn" gives the same error as OpenVPN-GUI above, except that 'ääliö.key' shows faulty glyphs[1]. This also triggers an interesting bug in the command prompt[2]

Anyways, as the Windows 7 install is English-language, I suspect it's using a single-byte character set instead of UCS-2. I'll continue debugging, but any pointers are obviously much appreciated!

Samuli

[1] <http://users.utu.fi/sjsepp/cmd.png>
[2] Typing an "ä" or "ö" moves the (invisible) cursor forward one character, but each backspace will delete two characters instead of one. This does not happen until openvpn has been (unsuccessfully) started.

Quoted 181 lines

Discussed at [1].

Use wmain under windows, drop the custom parsing and shell32 linkage.

There is no need for gc magic as this allocation is static.

[1] http://permalink.gmane.org/gmane.network.openvpn.devel/5433

---
 src/openvpn/Makefile.am     |    6 +++++- src/openvpn/openvpn.c       |   37 ++++++++++++++++++++++++++++++++++++- src/openvpn/openvpn.vcxproj |   10 ++++++---- src/openvpn/options.c       |   27 ---------------------------

 4 files changed, 47 insertions(+), 33 deletions(-)

 mode change 100644 => 100755 src/openvpn/openvpn.vcxproj

src/openvpn/Makefile.am +4 -0
index 4e485e7..0506b11 100644
@@ -27,6 +27,10 @@ AM_CFLAGS = \
       $(OPTIONAL_CRYPTO_CFLAGS) \
       $(OPTIONAL_LZO_CFLAGS) \
       $(OPTIONAL_PKCS11_HELPER_CFLAGS)
+if WIN32
+# we want unicode entry point but not the macro
+AM_CFLAGS += -municode -UUNICODE
+endif
 

 sbin_PROGRAMS = openvpn

src/openvpn/Makefile.am +0 -0
@@ -118,5 +122,5 @@ openvpn_LDADD = \
       $(OPTIONAL_DL_LIBS)

 if WIN32
 openvpn_SOURCES += openvpn_win32_resources.rc

src/openvpn/Makefile.am +1 -1
-openvpn_LDADD += -lgdi32 -lws2_32 -lwininet -lcrypt32 -liphlpapi -lwinmm -lshell32
+openvpn_LDADD += -lgdi32 -lws2_32 -lwininet -lcrypt32 -liphlpapi -lwinmm

 endif

src/openvpn/openvpn.c +1 -0
index 3db1b86..6e70a58 100644
@@ -127,8 +127,9 @@ tunnel_point_to_point (struct context *c)
   * @param argc - Commandline argument count.
   * @param argv - Commandline argument values.
   */
+static

 int

src/openvpn/openvpn.c +1 -1
-main (int argc, char *argv[])
+openvpn_main (int argc, char *argv[])

 {
   struct context c;

src/openvpn/openvpn.c +0 -0
@@ -289,3 +290,37 @@ main (int argc, char *argv[])

   openvpn_exit (OPENVPN_EXIT_STATUS_GOOD);  /* exit point */ return 0;                              /* NOTREACHED */ }

src/openvpn/openvpn.c +34 -0
+
+#ifdef WIN32
+int
+wmain (int argc, wchar_t *wargv[]) {
+  char **argv;
+  int ret;
+  int i;
+
+  if ((argv = calloc(argc+1, sizeof(char*))) == NULL)
+    return 1;
+
+  for (i = 0; i < argc; i++)
+    {
+      int n = WideCharToMultiByte (CP_UTF8, 0, wargv[i], -1, NULL, 0, NULL, NULL);
+      argv[i] = malloc (n);
+      WideCharToMultiByte (CP_UTF8, 0, wargv[i], -1, argv[i], n, NULL, NULL);
+    }
+
+  ret = openvpn_main(argc, argv);
+
+  for (i=0; i < argc; i++ )
+    {
+      free (argv[i]);
+    }
+  free(argv);
+
+  return ret;
+}
+#else
+int
+main (int argc, char *argv[]) {
+     return openvpn_main(argc, argv);
+}
+#endif
src/openvpn/openvpn.vcxproj +0 -0
old mode 100644
new mode 100755
index 51e19af..452876f
@@ -18,12 +18,12 @@

   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> <ConfigurationType>Application</ConfigurationType>
-    <CharacterSet>MultiByte</CharacterSet> <WholeProgramOptimization>true</WholeProgramOptimization>
+    <CharacterSet>Unicode</CharacterSet>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> <ConfigurationType>Application</ConfigurationType>
-    <CharacterSet>MultiByte</CharacterSet>
+    <CharacterSet>Unicode</CharacterSet>
   </PropertyGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
   <ImportGroup Label="ExtensionSettings">

src/openvpn/openvpn.vcxproj +0 -0
@@ -56,12 +56,13 @@

       </PrecompiledHeader>
       <WarningLevel>Level3</WarningLevel>
       <DebugInformationFormat>EditAndContinue</DebugInformationFormat>
+      <UndefinePreprocessorDefinitions>UNICODE</UndefinePreprocessorDefinitions>
     </ClCompile>
     <ResourceCompile>
       <AdditionalIncludeDirectories>$(SOURCEBASE);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
     </ResourceCompile>
     <Link>
-      <AdditionalDependencies>libeay32.lib;ssleay32.lib;lzo2.lib;pkcs11-helper.dll.lib;gdi32.lib;ws2_32.lib;wininet.lib;crypt32.lib;iphlpapi.lib;winmm.lib;shell32.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalDependencies>libeay32.lib;ssleay32.lib;lzo2.lib;pkcs11-helper.dll.lib;gdi32.lib;ws2_32.lib;wininet.lib;crypt32.lib;iphlpapi.lib;winmm.lib;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalLibraryDirectories>$(OPENSSL_HOME)/lib;$(LZO_HOME)/lib;$(PKCS11H_HOME)/lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> <GenerateDebugInformation>true</GenerateDebugInformation>
       <SubSystem>Console</SubSystem>

src/openvpn/openvpn.vcxproj +0 -0
@@ -80,12 +81,13 @@

       </PrecompiledHeader>
       <WarningLevel>Level3</WarningLevel>
       <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
+      <UndefinePreprocessorDefinitions>UNICODE</UndefinePreprocessorDefinitions>
     </ClCompile>
     <ResourceCompile>
       <AdditionalIncludeDirectories>$(SOURCEBASE);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
     </ResourceCompile>
     <Link>
-      <AdditionalDependencies>libeay32.lib;ssleay32.lib;lzo2.lib;pkcs11-helper.dll.lib;gdi32.lib;ws2_32.lib;wininet.lib;crypt32.lib;iphlpapi.lib;winmm.lib;shell32.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalDependencies>libeay32.lib;ssleay32.lib;lzo2.lib;pkcs11-helper.dll.lib;gdi32.lib;ws2_32.lib;wininet.lib;crypt32.lib;iphlpapi.lib;winmm.lib;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalLibraryDirectories>$(OPENSSL_HOME)/lib;$(LZO_HOME)/lib;$(PKCS11H_HOME)/lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> <GenerateDebugInformation>true</GenerateDebugInformation>
       <SubSystem>Console</SubSystem>

src/openvpn/options.c +0 -27
index 25786f6..66241b4 100644
@@ -3832,33 +3832,6 @@ parse_argv (struct options *options,
  {
    int i, j;
 
-#ifdef WIN32
-  /*
-   * Windows replaces Unicode characters in argv[] that are not present
-   * in the current codepage with '?'. Get the wide char command line and
-   * convert it to UTF-8 ourselves.
-   */
-  int wargc;
-  WCHAR **wargv;
-  char **uargv;
-
-  wargv = CommandLineToArgvW (GetCommandLineW (), &wargc);
-  if (wargv == NULL || wargc != argc)
-    usage ();
-
-  uargv = gc_malloc (wargc * sizeof (*uargv), false, &options->gc);
-
-  for (i = 0; i < wargc; i++)
-    {
-      int n = WideCharToMultiByte (CP_UTF8, 0, wargv[i], -1, NULL, 0, NULL, NULL);
-      uargv[i] = gc_malloc (n, false, &options->gc);
-      WideCharToMultiByte (CP_UTF8, 0, wargv[i], -1, uargv[i], n, NULL, NULL);
-    }
-
-  LocalFree (wargv);
-  argv = uargv;
-#endif
-
    /* usage message */
    if (argc <= 1)
      usage ();
#22 lore raw

Re: [Openvpn-devel] [PATCH] cleanup: windows: convert argv (UCS-2 to UTF-8) at earliest

Quoted 4 lines

Hello Samuli,

Curios: Did you manage to get it work using master without my patch?

Nope, although I only tested it briefly. I'll try that again just in case.

Quoted 10 lines

If not, to make it easy...

Use Windows Explorer and rename the key file to something non-ascii. Then open openvpn configuration using UTF-8 editor and modify key file there. This should work, as we do not use unicode/conversion command-line.

Next step would be to remove the key from configuration and use it in command-line.

Alon.

Thanks, I'll try that.

Samuli

Quoted 223 lines

2012/4/27 Samuli Seppänen <[email protected]...>:

Quoted 221 lines

Hi,

As promised in yesterday's IRC meeting (summary coming today), I tested this patch on Windows 7 (64-bit). So far I've had no luck, but don't think the problems have anything to do with this patch.

Anyways, I cross-compiled latest "master" with this patch applied and "bin" and "lib" directories on top of an existing openvpn-2.3-alpha1 install. The old "bin" directory was renamed to make sure none of it was used. I then renamed "openvpn.ovpn" to "ääliö.ovpn" and "ta.key" to "ääliö.key" using Windows Explorer. Then I updated the configuration file to point to these files using Notepad (and later Wordpad).

OpenVPN-GUI (Heiko's new version) detected the configuration file properly, showing "ääliö" as one available connection option. However, it output the following when trying to connect:

Options error: --tls-auth fails with 'ääliö.key': No such file or
directory

Git Bash showed the file as ??li?.key, which could mean Windows Explorer is using a single-byte character set.

Windows command prompt shows the characters properly, but issuing "openvpn --config ääliö.ovpn" gives the same error as OpenVPN-GUI above, except that 'ääliö.key' shows faulty glyphs[1]. This also triggers an interesting bug in the command prompt[2]

Anyways, as the Windows 7 install is English-language, I suspect it's using a single-byte character set instead of UCS-2. I'll continue debugging, but any pointers are obviously much appreciated!

Samuli

[1] <http://users.utu.fi/sjsepp/cmd.png>
[2] Typing an "ä" or "ö" moves the (invisible) cursor forward one character, but each backspace will delete two characters instead of one. This does not happen until openvpn has been (unsuccessfully) started.

Quoted 181 lines

Discussed at [1].

Use wmain under windows, drop the custom parsing and shell32 linkage.

There is no need for gc magic as this allocation is static.

[1] http://permalink.gmane.org/gmane.network.openvpn.devel/5433

---
 src/openvpn/Makefile.am     |    6 +++++-
 src/openvpn/openvpn.c       |   37 ++++++++++++++++++++++++++++++++++++-
 src/openvpn/openvpn.vcxproj |   10 ++++++----
 src/openvpn/options.c       |   27 ---------------------------
 4 files changed, 47 insertions(+), 33 deletions(-)
 mode change 100644 => 100755 src/openvpn/openvpn.vcxproj
src/openvpn/Makefile.am +5 -1
index 4e485e7..0506b11 100644
@@ -27,6 +27,10 @@ AM_CFLAGS = \
      $(OPTIONAL_CRYPTO_CFLAGS) \
      $(OPTIONAL_LZO_CFLAGS) \
      $(OPTIONAL_PKCS11_HELPER_CFLAGS)
+if WIN32
+# we want unicode entry point but not the macro
+AM_CFLAGS += -municode -UUNICODE
+endif
 
 sbin_PROGRAMS = openvpn
 
@@ -118,5 +122,5 @@ openvpn_LDADD = \
      $(OPTIONAL_DL_LIBS)
 if WIN32
 openvpn_SOURCES += openvpn_win32_resources.rc
-openvpn_LDADD += -lgdi32 -lws2_32 -lwininet -lcrypt32 -liphlpapi -lwinmm -lshell32
+openvpn_LDADD += -lgdi32 -lws2_32 -lwininet -lcrypt32 -liphlpapi -lwinmm
 endif
src/openvpn/openvpn.c +36 -1
index 3db1b86..6e70a58 100644
@@ -127,8 +127,9 @@ tunnel_point_to_point (struct context *c)
  * @param argc - Commandline argument count.
  * @param argv - Commandline argument values.
  */
+static
 int
-main (int argc, char *argv[])
+openvpn_main (int argc, char *argv[])
 {
   struct context c;
 
@@ -289,3 +290,37 @@ main (int argc, char *argv[])
   openvpn_exit (OPENVPN_EXIT_STATUS_GOOD);  /* exit point */
   return 0;                              /* NOTREACHED */
 }
+
+#ifdef WIN32
+int
+wmain (int argc, wchar_t *wargv[]) {
+  char **argv;
+  int ret;
+  int i;
+
+  if ((argv = calloc(argc+1, sizeof(char*))) == NULL)
+    return 1;
+
+  for (i = 0; i < argc; i++)
+    {
+      int n = WideCharToMultiByte (CP_UTF8, 0, wargv[i], -1, NULL, 0, NULL, NULL);
+      argv[i] = malloc (n);
+      WideCharToMultiByte (CP_UTF8, 0, wargv[i], -1, argv[i], n, NULL, NULL);
+    }
+
+  ret = openvpn_main(argc, argv);
+
+  for (i=0; i < argc; i++ )
+    {
+      free (argv[i]);
+    }
+  free(argv);
+
+  return ret;
+}
+#else
+int
+main (int argc, char *argv[]) {
+     return openvpn_main(argc, argv);
+}
+#endif
src/openvpn/openvpn.vcxproj +6 -4
old mode 100644
new mode 100755
index 51e19af..452876f
@@ -18,12 +18,12 @@
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
     <ConfigurationType>Application</ConfigurationType>
-    <CharacterSet>MultiByte</CharacterSet>
     <WholeProgramOptimization>true</WholeProgramOptimization>
+    <CharacterSet>Unicode</CharacterSet>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
     <ConfigurationType>Application</ConfigurationType>
-    <CharacterSet>MultiByte</CharacterSet>
+    <CharacterSet>Unicode</CharacterSet>
   </PropertyGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
   <ImportGroup Label="ExtensionSettings">
@@ -56,12 +56,13 @@
       </PrecompiledHeader>
       <WarningLevel>Level3</WarningLevel>
       <DebugInformationFormat>EditAndContinue</DebugInformationFormat>
+      <UndefinePreprocessorDefinitions>UNICODE</UndefinePreprocessorDefinitions>
     </ClCompile>
     <ResourceCompile>
       <AdditionalIncludeDirectories>$(SOURCEBASE);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
     </ResourceCompile>
     <Link>
-      <AdditionalDependencies>libeay32.lib;ssleay32.lib;lzo2.lib;pkcs11-helper.dll.lib;gdi32.lib;ws2_32.lib;wininet.lib;crypt32.lib;iphlpapi.lib;winmm.lib;shell32.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalDependencies>libeay32.lib;ssleay32.lib;lzo2.lib;pkcs11-helper.dll.lib;gdi32.lib;ws2_32.lib;wininet.lib;crypt32.lib;iphlpapi.lib;winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
       <AdditionalLibraryDirectories>$(OPENSSL_HOME)/lib;$(LZO_HOME)/lib;$(PKCS11H_HOME)/lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
       <GenerateDebugInformation>true</GenerateDebugInformation>
       <SubSystem>Console</SubSystem>
@@ -80,12 +81,13 @@
       </PrecompiledHeader>
       <WarningLevel>Level3</WarningLevel>
       <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
+      <UndefinePreprocessorDefinitions>UNICODE</UndefinePreprocessorDefinitions>
     </ClCompile>
     <ResourceCompile>
       <AdditionalIncludeDirectories>$(SOURCEBASE);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
     </ResourceCompile>
     <Link>
-      <AdditionalDependencies>libeay32.lib;ssleay32.lib;lzo2.lib;pkcs11-helper.dll.lib;gdi32.lib;ws2_32.lib;wininet.lib;crypt32.lib;iphlpapi.lib;winmm.lib;shell32.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalDependencies>libeay32.lib;ssleay32.lib;lzo2.lib;pkcs11-helper.dll.lib;gdi32.lib;ws2_32.lib;wininet.lib;crypt32.lib;iphlpapi.lib;winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
       <AdditionalLibraryDirectories>$(OPENSSL_HOME)/lib;$(LZO_HOME)/lib;$(PKCS11H_HOME)/lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
       <GenerateDebugInformation>true</GenerateDebugInformation>
       <SubSystem>Console</SubSystem>
src/openvpn/options.c +0 -27
index 25786f6..66241b4 100644
@@ -3832,33 +3832,6 @@ parse_argv (struct options *options,
 {
   int i, j;
 
-#ifdef WIN32
-  /*
-   * Windows replaces Unicode characters in argv[] that are not present
-   * in the current codepage with '?'. Get the wide char command line and
-   * convert it to UTF-8 ourselves.
-   */
-  int wargc;
-  WCHAR **wargv;
-  char **uargv;
-
-  wargv = CommandLineToArgvW (GetCommandLineW (), &wargc);
-  if (wargv == NULL || wargc != argc)
-    usage ();
-
-  uargv = gc_malloc (wargc * sizeof (*uargv), false, &options->gc);
-
-  for (i = 0; i < wargc; i++)
-    {
-      int n = WideCharToMultiByte (CP_UTF8, 0, wargv[i], -1, NULL, 0, NULL, NULL);
-      uargv[i] = gc_malloc (n, false, &options->gc);
-      WideCharToMultiByte (CP_UTF8, 0, wargv[i], -1, uargv[i], n, NULL, NULL);
-    }
-
-  LocalFree (wargv);
-  argv = uargv;
-#endif
-
   /* usage message */
   if (argc <= 1)
     usage ();
#23 lore raw

Re: [Openvpn-devel] [PATCH] cleanup: windows: convert argv (UCS-2 to UTF-8) at earliest

Hello,

Here is a simple program that will make it easier for you....

The file in ca and pkcs12 parameters is found when using Hebrew.

Alon.

---
#include <Windows.h>

int main(void) {
	WCHAR cmdline[] =
L"s:\\Temp\\openvpn\\build-win32\\src\\openvpn\\.libs\\openvpn.exe
--dev tap --tls-client --ca c:\\temp\\עברית\\ניסוי.txt --pkcs12
c:\\temp\\עברית\\ניסוי.txt";
	STARTUPINFO si;
	PROCESS_INFORMATION pi;
	ZeroMemory(&si, sizeof(si));
	si.cb = sizeof(si);
	ZeroMemory(&pi, sizeof(pi));
	CreateProcessW(
		NULL,
		cmdline,
		NULL,
		NULL,
		TRUE,
		0,
		NULL,
		NULL,
		&si,
		&pi
	);
	return 0;
}

---

2012/4/27 Samuli Seppänen <[email protected]...>:

Quoted 247 lines
Quoted 4 lines

Hello Samuli,

Curios: Did you manage to get it work using master without my patch?

Nope, although I only tested it briefly. I'll try that again just in case.

Quoted 10 lines

If not, to make it easy...

Use Windows Explorer and rename the key file to something non-ascii. Then open openvpn configuration using UTF-8 editor and modify key file there. This should work, as we do not use unicode/conversion command-line.

Next step would be to remove the key from configuration and use it in command-line.

Alon.

Thanks, I'll try that.

Samuli

Quoted 223 lines

2012/4/27 Samuli Seppänen <[email protected]...>:

Quoted 221 lines

Hi,

As promised in yesterday's IRC meeting (summary coming today), I tested this patch on Windows 7 (64-bit). So far I've had no luck, but don't think the problems have anything to do with this patch.

Anyways, I cross-compiled latest "master" with this patch applied and "bin" and "lib" directories on top of an existing openvpn-2.3-alpha1 install. The old "bin" directory was renamed to make sure none of it was used. I then renamed "openvpn.ovpn" to "ääliö.ovpn" and "ta.key" to "ääliö.key" using Windows Explorer. Then I updated the configuration file to point to these files using Notepad (and later Wordpad).

OpenVPN-GUI (Heiko's new version) detected the configuration file properly, showing "ääliö" as one available connection option. However, it output the following when trying to connect:

   Options error: --tls-auth fails with 'ääliö.key': No such file or directory

Git Bash showed the file as ??li?.key, which could mean Windows Explorer is using a single-byte character set.

Windows command prompt shows the characters properly, but issuing "openvpn --config ääliö.ovpn" gives the same error as OpenVPN-GUI above, except that 'ääliö.key' shows faulty glyphs[1]. This also triggers an interesting bug in the command prompt[2]

Anyways, as the Windows 7 install is English-language, I suspect it's using a single-byte character set instead of UCS-2. I'll continue debugging, but any pointers are obviously much appreciated!

Samuli

[1] <http://users.utu.fi/sjsepp/cmd.png>
[2] Typing an "ä" or "ö" moves the (invisible) cursor forward one character, but each backspace will delete two characters instead of one. This does not happen until openvpn has been (unsuccessfully) started.

Quoted 181 lines

Discussed at [1].

Use wmain under windows, drop the custom parsing and shell32 linkage.

There is no need for gc magic as this allocation is static.

[1] http://permalink.gmane.org/gmane.network.openvpn.devel/5433

---
 src/openvpn/Makefile.am     |    6 +++++- src/openvpn/openvpn.c       |   37 ++++++++++++++++++++++++++++++++++++- src/openvpn/openvpn.vcxproj |   10 ++++++---- src/openvpn/options.c       |   27 ---------------------------

 4 files changed, 47 insertions(+), 33 deletions(-)

 mode change 100644 => 100755 src/openvpn/openvpn.vcxproj

src/openvpn/Makefile.am +4 -0
index 4e485e7..0506b11 100644
@@ -27,6 +27,10 @@ AM_CFLAGS = \
       $(OPTIONAL_CRYPTO_CFLAGS) \
       $(OPTIONAL_LZO_CFLAGS) \
       $(OPTIONAL_PKCS11_HELPER_CFLAGS)
+if WIN32
+# we want unicode entry point but not the macro
+AM_CFLAGS += -municode -UUNICODE
+endif
 

 sbin_PROGRAMS = openvpn

src/openvpn/Makefile.am +0 -0
@@ -118,5 +122,5 @@ openvpn_LDADD = \
       $(OPTIONAL_DL_LIBS)

 if WIN32
 openvpn_SOURCES += openvpn_win32_resources.rc

src/openvpn/Makefile.am +1 -1
-openvpn_LDADD += -lgdi32 -lws2_32 -lwininet -lcrypt32 -liphlpapi -lwinmm -lshell32
+openvpn_LDADD += -lgdi32 -lws2_32 -lwininet -lcrypt32 -liphlpapi -lwinmm

 endif

src/openvpn/openvpn.c +1 -0
index 3db1b86..6e70a58 100644
@@ -127,8 +127,9 @@ tunnel_point_to_point (struct context *c)
   * @param argc - Commandline argument count.
   * @param argv - Commandline argument values.
   */
+static

 int

src/openvpn/openvpn.c +1 -1
-main (int argc, char *argv[])
+openvpn_main (int argc, char *argv[])

 {
   struct context c;

src/openvpn/openvpn.c +0 -0
@@ -289,3 +290,37 @@ main (int argc, char *argv[])

   openvpn_exit (OPENVPN_EXIT_STATUS_GOOD);  /* exit point */ return 0;                              /* NOTREACHED */ }

src/openvpn/openvpn.c +34 -0
+
+#ifdef WIN32
+int
+wmain (int argc, wchar_t *wargv[]) {
+  char **argv;
+  int ret;
+  int i;
+
+  if ((argv = calloc(argc+1, sizeof(char*))) == NULL)
+    return 1;
+
+  for (i = 0; i < argc; i++)
+    {
+      int n = WideCharToMultiByte (CP_UTF8, 0, wargv[i], -1, NULL, 0, NULL, NULL);
+      argv[i] = malloc (n);
+      WideCharToMultiByte (CP_UTF8, 0, wargv[i], -1, argv[i], n, NULL, NULL);
+    }
+
+  ret = openvpn_main(argc, argv);
+
+  for (i=0; i < argc; i++ )
+    {
+      free (argv[i]);
+    }
+  free(argv);
+
+  return ret;
+}
+#else
+int
+main (int argc, char *argv[]) {
+     return openvpn_main(argc, argv);
+}
+#endif
src/openvpn/openvpn.vcxproj +0 -0
old mode 100644
new mode 100755
index 51e19af..452876f
@@ -18,12 +18,12 @@

   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> <ConfigurationType>Application</ConfigurationType>
-    <CharacterSet>MultiByte</CharacterSet> <WholeProgramOptimization>true</WholeProgramOptimization>
+    <CharacterSet>Unicode</CharacterSet>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> <ConfigurationType>Application</ConfigurationType>
-    <CharacterSet>MultiByte</CharacterSet>
+    <CharacterSet>Unicode</CharacterSet>
   </PropertyGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
   <ImportGroup Label="ExtensionSettings">

src/openvpn/openvpn.vcxproj +0 -0
@@ -56,12 +56,13 @@

       </PrecompiledHeader>
       <WarningLevel>Level3</WarningLevel>
       <DebugInformationFormat>EditAndContinue</DebugInformationFormat>
+      <UndefinePreprocessorDefinitions>UNICODE</UndefinePreprocessorDefinitions>
     </ClCompile>
     <ResourceCompile>
       <AdditionalIncludeDirectories>$(SOURCEBASE);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
     </ResourceCompile>
     <Link>
-      <AdditionalDependencies>libeay32.lib;ssleay32.lib;lzo2.lib;pkcs11-helper.dll.lib;gdi32.lib;ws2_32.lib;wininet.lib;crypt32.lib;iphlpapi.lib;winmm.lib;shell32.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalDependencies>libeay32.lib;ssleay32.lib;lzo2.lib;pkcs11-helper.dll.lib;gdi32.lib;ws2_32.lib;wininet.lib;crypt32.lib;iphlpapi.lib;winmm.lib;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalLibraryDirectories>$(OPENSSL_HOME)/lib;$(LZO_HOME)/lib;$(PKCS11H_HOME)/lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> <GenerateDebugInformation>true</GenerateDebugInformation>
       <SubSystem>Console</SubSystem>

src/openvpn/openvpn.vcxproj +0 -0
@@ -80,12 +81,13 @@

       </PrecompiledHeader>
       <WarningLevel>Level3</WarningLevel>
       <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
+      <UndefinePreprocessorDefinitions>UNICODE</UndefinePreprocessorDefinitions>
     </ClCompile>
     <ResourceCompile>
       <AdditionalIncludeDirectories>$(SOURCEBASE);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
     </ResourceCompile>
     <Link>
-      <AdditionalDependencies>libeay32.lib;ssleay32.lib;lzo2.lib;pkcs11-helper.dll.lib;gdi32.lib;ws2_32.lib;wininet.lib;crypt32.lib;iphlpapi.lib;winmm.lib;shell32.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalDependencies>libeay32.lib;ssleay32.lib;lzo2.lib;pkcs11-helper.dll.lib;gdi32.lib;ws2_32.lib;wininet.lib;crypt32.lib;iphlpapi.lib;winmm.lib;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalLibraryDirectories>$(OPENSSL_HOME)/lib;$(LZO_HOME)/lib;$(PKCS11H_HOME)/lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> <GenerateDebugInformation>true</GenerateDebugInformation>
       <SubSystem>Console</SubSystem>

src/openvpn/options.c +0 -27
index 25786f6..66241b4 100644
@@ -3832,33 +3832,6 @@ parse_argv (struct options *options,
  {
    int i, j;
 
-#ifdef WIN32
-  /*
-   * Windows replaces Unicode characters in argv[] that are not present
-   * in the current codepage with '?'. Get the wide char command line and
-   * convert it to UTF-8 ourselves.
-   */
-  int wargc;
-  WCHAR **wargv;
-  char **uargv;
-
-  wargv = CommandLineToArgvW (GetCommandLineW (), &wargc);
-  if (wargv == NULL || wargc != argc)
-    usage ();
-
-  uargv = gc_malloc (wargc * sizeof (*uargv), false, &options->gc);
-
-  for (i = 0; i < wargc; i++)
-    {
-      int n = WideCharToMultiByte (CP_UTF8, 0, wargv[i], -1, NULL, 0, NULL, NULL);
-      uargv[i] = gc_malloc (n, false, &options->gc);
-      WideCharToMultiByte (CP_UTF8, 0, wargv[i], -1, uargv[i], n, NULL, NULL);
-    }
-
-  LocalFree (wargv);
-  argv = uargv;
-#endif
-
    /* usage message */
    if (argc <= 1)
      usage ();
author
#24 lore raw

Re: [Openvpn-devel] [PATCH] cleanup: windows: convert argv (UCS-2 to UTF-8) at earliest

In reply to Samuli Seppänen
Quoted 6 lines · On Friday 27 April 2012 09:54:15 Samuli Seppänen wrote:

Anyways, I cross-compiled latest "master" with this patch applied and "bin" and "lib" directories on top of an existing openvpn-2.3-alpha1 install. The old "bin" directory was renamed to make sure none of it was used. I then renamed "openvpn.ovpn" to "ääliö.ovpn" and "ta.key" to "ääliö.key" using Windows Explorer. Then I updated the configuration file to point to these files using Notepad (and later Wordpad).

Notepad saves UTF-8 files with BOM, which is very uncommon. Maybe that was the problem. I ran into that when I was testing my patch. You might want to try using Notepad++ and save it as UTF-8 without BOM.

HTH
Heiko

Signature · 2 lines
Heiko Hund | Software Engineer | Tel +49-721-25516-237 | Fax -200
SOPHOS NSG | Amalienbadstr. 41 Bau 52 | 76227 Karlsruhe | Germany
#25 lore raw

Re: [Openvpn-devel] [PATCH] cleanup: windows: convert argv (UCS-2 to UTF-8) at earliest

Quoted 8 lines · On Friday 27 April 2012 09:54:15 Samuli Seppänen wrote:
Quoted 6 lines

Anyways, I cross-compiled latest "master" with this patch applied and "bin" and "lib" directories on top of an existing openvpn-2.3-alpha1 install. The old "bin" directory was renamed to make sure none of it was used. I then renamed "openvpn.ovpn" to "ääliö.ovpn" and "ta.key" to "ääliö.key" using Windows Explorer. Then I updated the configuration file to point to these files using Notepad (and later Wordpad).

Quoted 6 lines

Notepad saves UTF-8 files with BOM, which is very uncommon. Maybe that was the problem. I ran into that when I was testing my patch. You might want to try using Notepad++ and save it as UTF-8 without BOM.

HTH
Heiko

I'll give Notepad++ a try, thanks!

Samuli

#26 lore raw

Re: [Openvpn-devel] [PATCH] cleanup: windows: convert argv (UCS-2 to UTF-8) at earliest

In reply to Heiko Hund

Il 27.04.2012 12:18, Heiko Hund ha scritto:

Quoted 7 lines · On Friday 27 April 2012 09:54:15 Samuli Seppänen wrote:
Quoted 6 lines

Anyways, I cross-compiled latest "master" with this patch applied and "bin" and "lib" directories on top of an existing openvpn-2.3-alpha1 install. The old "bin" directory was renamed to make sure none of it was used. I then renamed "openvpn.ovpn" to "ääliö.ovpn" and "ta.key" to "ääliö.key" using Windows Explorer. Then I updated the configuration file to point to these files using Notepad (and later Wordpad).

Quoted 6 lines

Notepad saves UTF-8 files with BOM, which is very uncommon. Maybe that was the problem. I ran into that when I was testing my patch. You might want to try using Notepad++ and save it as UTF-8 without BOM.

HTH
Heiko

Saved the configuration file to UTF-8 without BOM - after this I got no complaints from OpenVPN-GUI. Launching OpenVPN from the command prompt also worked... tls-auth was undefined in the config, and openvpn called like this:

Quoted 1 line

openvpn --config ääliö.ovpn --tls-auth ääliö.key 1

Only minor issue was that the command prompt displayed funky characters instead of the proper ones:

<http://users.utu.fi/sjsepp/cmd2.png>

Thanks for the tip, Heiko!

Signature · 5 lines
Samuli Seppänen
Community Manager
OpenVPN Technologies, Inc

irc freenode net: mattock
#27 lore raw

Re: [Openvpn-devel] [PATCH] cleanup: windows: convert argv (UCS-2 to UTF-8) at earliest

Quoted 20 lines

Il 27.04.2012 12:18, Heiko Hund ha scritto:

Quoted 7 lines · On Friday 27 April 2012 09:54:15 Samuli Seppänen wrote:
Quoted 6 lines

Anyways, I cross-compiled latest "master" with this patch applied and "bin" and "lib" directories on top of an existing openvpn-2.3-alpha1 install. The old "bin" directory was renamed to make sure none of it was used. I then renamed "openvpn.ovpn" to "ääliö.ovpn" and "ta.key" to "ääliö.key" using Windows Explorer. Then I updated the configuration file to point to these files using Notepad (and later Wordpad).

Quoted 6 lines

Notepad saves UTF-8 files with BOM, which is very uncommon. Maybe that was the problem. I ran into that when I was testing my patch. You might want to try using Notepad++ and save it as UTF-8 without BOM.

HTH
Heiko

Saved the configuration file to UTF-8 without BOM - after this I got no complaints from OpenVPN-GUI. Launching OpenVPN from the command prompt also worked... tls-auth was undefined in the config, and openvpn called like this:

Quoted 8 lines
Quoted 1 line

openvpn --config ääliö.ovpn --tls-auth ääliö.key 1

Only minor issue was that the command prompt displayed funky characters instead of the proper ones:

<http://users.utu.fi/sjsepp/cmd2.png>

Thanks for the tip, Heiko!

OpenVPN 2.3-alpha1 also behaves in the exactly same way. Is that to be expected?

Signature · 5 lines
Samuli Seppänen
Community Manager
OpenVPN Technologies, Inc

irc freenode net: mattock
#28 lore raw

Re: [Openvpn-devel] [PATCH] cleanup: windows: convert argv (UCS-2 to UTF-8) at earliest

In reply to Samuli Seppänen

2012/4/27 Samuli Seppänen <[email protected]...>:

Quoted 12 lines

Il 27.04.2012 12:18, Heiko Hund ha scritto:

Quoted 11 lines · On Friday 27 April 2012 09:54:15 Samuli Seppänen wrote:
Quoted 6 lines

Anyways, I cross-compiled latest "master" with this patch applied and "bin" and "lib" directories on top of an existing openvpn-2.3-alpha1 install. The old "bin" directory was renamed to make sure none of it was used. I then renamed "openvpn.ovpn" to "ääliö.ovpn" and "ta.key" to "ääliö.key" using Windows Explorer. Then I updated the configuration file to point to these files using Notepad (and later Wordpad).

Notepad saves UTF-8 files with BOM, which is very uncommon. Maybe that was the problem. I ran into that when I was testing my patch. You might want to try using Notepad++ and save it as UTF-8 without BOM.

Quoted 6 lines
Quoted 2 lines

HTH
Heiko

Saved the configuration file to UTF-8 without BOM - after this I got no complaints from OpenVPN-GUI. Launching OpenVPN from the command prompt also worked... tls-auth was undefined in the config, and openvpn called like this:

if bom is a problem we should handle it properly in options.c, as we cannot expect users to understand bom issues.

Quoted 7 lines
Quoted 2 lines

openvpn --config ääliö.ovpn --tls-auth ääliö.key 1

Only minor issue was that the command prompt displayed funky characters instead of the proper ones:

<http://users.utu.fi/sjsepp/cmd2.png>

Yes. this is OK.

Alon.

#29 lore raw

Re: [Openvpn-devel] [PATCH] cleanup: windows: convert argv (UCS-2 to UTF-8) at earliest

News?

Quoted 34 lines · Alon Bar-Lev

2012/4/27 Samuli Seppänen <[email protected]...>:

Quoted 12 lines

Il 27.04.2012 12:18, Heiko Hund ha scritto:

Quoted 11 lines · On Friday 27 April 2012 09:54:15 Samuli Seppänen wrote:
Quoted 6 lines

Anyways, I cross-compiled latest "master" with this patch applied and "bin" and "lib" directories on top of an existing openvpn-2.3-alpha1 install. The old "bin" directory was renamed to make sure none of it was used. I then renamed "openvpn.ovpn" to "ääliö.ovpn" and "ta.key" to "ääliö.key" using Windows Explorer. Then I updated the configuration file to point to these files using Notepad (and later Wordpad).

Notepad saves UTF-8 files with BOM, which is very uncommon. Maybe that was the problem. I ran into that when I was testing my patch. You might want to try using Notepad++ and save it as UTF-8 without BOM.

Quoted 6 lines
Quoted 2 lines

HTH
Heiko

Saved the configuration file to UTF-8 without BOM - after this I got no complaints from OpenVPN-GUI. Launching OpenVPN from the command prompt also worked... tls-auth was undefined in the config, and openvpn called like this:

if bom is a problem we should handle it properly in options.c, as we cannot expect users to understand bom issues.

Quoted 7 lines
Quoted 2 lines

openvpn --config ääliö.ovpn --tls-auth ääliö.key 1

Only minor issue was that the command prompt displayed funky characters instead of the proper ones:

<http://users.utu.fi/sjsepp/cmd2.png>

Yes. this is OK.

Alon.

#30 lore raw

Re: [Openvpn-devel] [PATCH] cleanup: windows: convert argv (UCS-2 to UTF-8) at earliest

In reply to Alon Bar-Lev

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 25 lines · Alon Bar-Lev

2012/4/27 Samuli Seppänen <[email protected]...>:

Quoted 14 lines

Il 27.04.2012 12:18, Heiko Hund ha scritto:

Quoted 13 lines · On Friday 27 April 2012 09:54:15 Samuli Seppänen wrote:
Quoted 7 lines

Anyways, I cross-compiled latest "master" with this patch applied and "bin" and "lib" directories on top of an existing openvpn-2.3-alpha1 install. The old "bin" directory was renamed to make sure none of it was used. I then renamed "openvpn.ovpn" to "ääliö.ovpn" and "ta.key" to "ääliö.key" using Windows Explorer. Then I updated the configuration file to point to these files using Notepad (and later Wordpad).

Notepad saves UTF-8 files with BOM, which is very uncommon. Maybe that was the problem. I ran into that when I was testing my patch. You might want to try using Notepad++ and save it as UTF-8 without BOM.

Quoted 5 lines
Quoted 1 line

HTH Heiko

Saved the configuration file to UTF-8 without BOM - after this I got no complaints from OpenVPN-GUI. Launching OpenVPN from the command prompt also worked... tls-auth was undefined in the config, and openvpn called like this:

if bom is a problem we should handle it properly in options.c, as we cannot expect users to understand bom issues.

Quoted 1 line
Quoted 8 lines
Quoted 6 lines
Quoted 1 line

openvpn --config ääliö.ovpn --tls-auth ääliö.key 1

Only minor issue was that the command prompt displayed funky characters instead of the proper ones:

<http://users.utu.fi/sjsepp/cmd2.png>

Yes. this is OK.

Just so that I understand this more properly. The reason this is okay, is that because cmd.exe is not UTF-8 capable when displaying the log data?

kind regards,

David Sommerseth
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEUEARECAAYFAk+iMy8ACgkQDC186MBRfrp8LACeNRzTrcdd8JWyzTEJ3B5Kv1ye iFsAmNM0T3LgxrlJeg3I+7F1aoMSqpw=
=PhBy
-----END PGP SIGNATURE-----

#31 lore raw

Re: [Openvpn-devel] [PATCH] cleanup: windows: convert argv (UCS-2 to UTF-8) at earliest

Quoted 35 lines · David Sommerseth

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 30 lines · Alon Bar-Lev

2012/4/27 Samuli Seppänen <[email protected]...>:

Quoted 14 lines

Il 27.04.2012 12:18, Heiko Hund ha scritto:

Quoted 13 lines · On Friday 27 April 2012 09:54:15 Samuli Seppänen wrote:
Quoted 7 lines

Anyways, I cross-compiled latest "master" with this patch applied and "bin" and "lib" directories on top of an existing openvpn-2.3-alpha1 install. The old "bin" directory was renamed to make sure none of it was used. I then renamed "openvpn.ovpn" to "ääliö.ovpn" and "ta.key" to "ääliö.key" using Windows Explorer. Then I updated the configuration file to point to these files using Notepad (and later Wordpad).

Notepad saves UTF-8 files with BOM, which is very uncommon. Maybe that was the problem. I ran into that when I was testing my patch. You might want to try using Notepad++ and save it as UTF-8 without BOM.

Quoted 5 lines
Quoted 1 line

HTH Heiko

Saved the configuration file to UTF-8 without BOM - after this I got no complaints from OpenVPN-GUI. Launching OpenVPN from the command prompt also worked... tls-auth was undefined in the config, and openvpn called like this:

if bom is a problem we should handle it properly in options.c, as we cannot expect users to understand bom issues.

Quoted 6 lines
Quoted 2 lines

openvpn --config ääliö.ovpn --tls-auth ääliö.key 1

Only minor issue was that the command prompt displayed funky characters instead of the proper ones:

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

<http://users.utu.fi/sjsepp/cmd2.png>

Yes. this is OK.

Just so that I understand this more properly.  The reason this is okay, is that because cmd.exe is not UTF-8 capable when displaying the log data?

Yes.
The cmd uses the plain old DOS code page, and needs special fonts. If you add --log parameter you will see this correctly.

Alon.

#32 lore raw

Re: [Openvpn-devel] [PATCH] cleanup: windows: convert argv (UCS-2 to UTF-8) at earliest

Quoted 36 lines
Quoted 33 lines · David Sommerseth

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 29 lines · Alon Bar-Lev

2012/4/27 Samuli Seppänen <[email protected]...>:

Quoted 14 lines

Il 27.04.2012 12:18, Heiko Hund ha scritto:

Quoted 13 lines · On Friday 27 April 2012 09:54:15 Samuli Seppänen wrote:
Quoted 7 lines

Anyways, I cross-compiled latest "master" with this patch applied and "bin" and "lib" directories on top of an existing openvpn-2.3-alpha1 install. The old "bin" directory was renamed to make sure none of it was used. I then renamed "openvpn.ovpn" to "ääliö.ovpn" and "ta.key" to "ääliö.key" using Windows Explorer. Then I updated the configuration file to point to these files using Notepad (and later Wordpad).

Notepad saves UTF-8 files with BOM, which is very uncommon. Maybe that was the problem. I ran into that when I was testing my patch. You might want to try using Notepad++ and save it as UTF-8 without BOM.

Quoted 5 lines
Quoted 1 line

HTH Heiko

Saved the configuration file to UTF-8 without BOM - after this I got no complaints from OpenVPN-GUI. Launching OpenVPN from the command prompt also worked... tls-auth was undefined in the config, and openvpn called like this:

if bom is a problem we should handle it properly in options.c, as we cannot expect users to understand bom issues.

Quoted 5 lines
Quoted 1 line

openvpn --config ääliö.ovpn --tls-auth ääliö.key 1

Only minor issue was that the command prompt displayed funky characters instead of the proper ones:

<http://users.utu.fi/sjsepp/cmd2.png>

Yes. this is OK.

Quoted 9 lines
Quoted 3 lines

Just so that I understand this more properly. The reason this is okay, is that because cmd.exe is not UTF-8 capable when displaying the log data?

Yes.
The cmd uses the plain old DOS code page, and needs special fonts. If you add --log parameter you will see this correctly.

Alon.

Tested with --log parameter. The logfile[1] seems to use the UTF-8 encoding, and with proper viewers/editors the Scandinavian characters (a/o umlauts, ä/ö) look just fine. On Windows most editors/viewers[3] display funky two-byte characters, but that's probably expected.

[1] An example log file is available here, search for "tls_auth_file":
<http://users.utu.fi/sjsepp/openvpn-log.txt>
[2] E.g. less and vi (in Git Bash), Wordpad, etc.

Signature · 5 lines
Samuli Seppänen
Community Manager
OpenVPN Technologies, Inc

irc freenode net: mattock
#33 lore raw

Re: [Openvpn-devel] [PATCH] cleanup: windows: convert argv (UCS-2 to UTF-8) at earliest

Quoted 45 lines · Samuli Seppänen
Quoted 36 lines
Quoted 33 lines · David Sommerseth

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 29 lines · Alon Bar-Lev

2012/4/27 Samuli Seppänen <[email protected]...>:

Quoted 14 lines

Il 27.04.2012 12:18, Heiko Hund ha scritto:

Quoted 13 lines · On Friday 27 April 2012 09:54:15 Samuli Seppänen wrote:
Quoted 7 lines

Anyways, I cross-compiled latest "master" with this patch applied and "bin" and "lib" directories on top of an existing openvpn-2.3-alpha1 install. The old "bin" directory was renamed to make sure none of it was used. I then renamed "openvpn.ovpn" to "ääliö.ovpn" and "ta.key" to "ääliö.key" using Windows Explorer. Then I updated the configuration file to point to these files using Notepad (and later Wordpad).

Notepad saves UTF-8 files with BOM, which is very uncommon. Maybe that was the problem. I ran into that when I was testing my patch. You might want to try using Notepad++ and save it as UTF-8 without BOM.

Quoted 5 lines
Quoted 1 line

HTH Heiko

Saved the configuration file to UTF-8 without BOM - after this I got no complaints from OpenVPN-GUI. Launching OpenVPN from the command prompt also worked... tls-auth was undefined in the config, and openvpn called like this:

if bom is a problem we should handle it properly in options.c, as we cannot expect users to understand bom issues.

Quoted 5 lines
Quoted 1 line

openvpn --config ääliö.ovpn --tls-auth ääliö.key 1

Only minor issue was that the command prompt displayed funky characters instead of the proper ones:

<http://users.utu.fi/sjsepp/cmd2.png>

Yes. this is OK.

Quoted 9 lines
Quoted 3 lines

Just so that I understand this more properly.  The reason this is okay, is that because cmd.exe is not UTF-8 capable when displaying the log data?

Yes.
The cmd uses the plain old DOS code page, and needs special fonts. If you add --log parameter you will see this correctly.

Alon.

Quoted 9 lines

Tested with --log parameter. The logfile[1] seems to use the UTF-8 encoding, and with proper viewers/editors the Scandinavian characters (a/o umlauts, ä/ö) look just fine. On Windows most editors/viewers[3] display funky two-byte characters, but that's probably expected.

[1] An example log file is available here, search for "tls_auth_file":
<http://users.utu.fi/sjsepp/openvpn-log.txt>
[2] E.g. less and vi (in Git Bash), Wordpad, etc.

So I guess now we are good.
Is anything else missing?

Alon.

#34 lore raw

Re: [Openvpn-devel] [PATCH] cleanup: windows: convert argv (UCS-2 to UTF-8) at earliest

Please apply.
https://github.com/alonbl/openvpn/compare/master...unicode

Quoted 60 lines · Alon Bar-Lev
Quoted 45 lines · Samuli Seppänen
Quoted 36 lines
Quoted 33 lines · David Sommerseth

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 29 lines · Alon Bar-Lev

2012/4/27 Samuli Seppänen <[email protected]...>:

Quoted 14 lines

Il 27.04.2012 12:18, Heiko Hund ha scritto:

Quoted 13 lines · On Friday 27 April 2012 09:54:15 Samuli Seppänen wrote:
Quoted 7 lines

Anyways, I cross-compiled latest "master" with this patch applied and "bin" and "lib" directories on top of an existing openvpn-2.3-alpha1 install. The old "bin" directory was renamed to make sure none of it was used. I then renamed "openvpn.ovpn" to "ääliö.ovpn" and "ta.key" to "ääliö.key" using Windows Explorer. Then I updated the configuration file to point to these files using Notepad (and later Wordpad).

Notepad saves UTF-8 files with BOM, which is very uncommon. Maybe that was the problem. I ran into that when I was testing my patch. You might want to try using Notepad++ and save it as UTF-8 without BOM.

Quoted 5 lines
Quoted 1 line

HTH Heiko

Saved the configuration file to UTF-8 without BOM - after this I got no complaints from OpenVPN-GUI. Launching OpenVPN from the command prompt also worked... tls-auth was undefined in the config, and openvpn called like this:

if bom is a problem we should handle it properly in options.c, as we cannot expect users to understand bom issues.

Quoted 5 lines
Quoted 1 line

openvpn --config ääliö.ovpn --tls-auth ääliö.key 1

Only minor issue was that the command prompt displayed funky characters instead of the proper ones:

<http://users.utu.fi/sjsepp/cmd2.png>

Yes. this is OK.

Quoted 9 lines
Quoted 3 lines

Just so that I understand this more properly.  The reason this is okay, is that because cmd.exe is not UTF-8 capable when displaying the log data?

Yes.
The cmd uses the plain old DOS code page, and needs special fonts. If you add --log parameter you will see this correctly.

Alon.

Quoted 9 lines

Tested with --log parameter. The logfile[1] seems to use the UTF-8 encoding, and with proper viewers/editors the Scandinavian characters (a/o umlauts, ä/ö) look just fine. On Windows most editors/viewers[3] display funky two-byte characters, but that's probably expected.

[1] An example log file is available here, search for "tls_auth_file":
<http://users.utu.fi/sjsepp/openvpn-log.txt>
[2] E.g. less and vi (in Git Bash), Wordpad, etc.

So I guess now we are good.
Is anything else missing?

Alon.

#35 lore raw

Re: [Openvpn-devel] [PATCH] cleanup: windows: convert argv (UCS-2 to UTF-8) at earliest

In reply to Alon Bar-Lev
Quoted 8 lines · Alon Bar-Lev

Discussed at [1].

Use wmain under windows, drop the custom parsing and shell32 linkage.

There is no need for gc magic as this allocation is static.

[1] http://permalink.gmane.org/gmane.network.openvpn.devel/5433

Quoted 8 lines
---
 src/openvpn/Makefile.am     |    6 +++++-
 src/openvpn/openvpn.c       |   37 ++++++++++++++++++++++++++++++++++++-
 src/openvpn/openvpn.vcxproj |   10 ++++++----
 src/openvpn/options.c       |   27 ---------------------------
 4 files changed, 47 insertions(+), 33 deletions(-)
 mode change 100644 => 100755 src/openvpn/openvpn.vcxproj

This patch has been applied to master through lazy consensus.

The patch has been tested and seems to work perfectly fine, and it have been discussed in a developers meeting as a reasonable patch to include. Thus no reason to delay inclusion any longer.

commit 74370aa89df9285a95084616e9c2d3c8464760b9

Author: Alon Bar-Lev <[email protected]...>
Date:   Sat Mar 24 22:31:10 2012 +0200
    cleanup: windows: convert argv (UCS-2 to UTF-8) at earliest
      
    Signed-off-by: Alon Bar-Lev <[email protected]...>
    Message-Id: [email protected]...
    URL: http://article.gmane.org/gmane.network.openvpn.devel/6063
    Tested-by: Samuli Seppänen <[email protected]...>
    Signed-off-by: David Sommerseth <[email protected]...>

kind regards,

David Sommerseth

Acked-by Gert Doering Acked-by Gert Doering Acked-by Gert Doering
#36 lore raw
In reply to Heiko Hund

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 10 lines · Heiko Hund

Hi,

this patch series fixes several issues when building for Windows with the MSVC buildsystem discovered today:

[PATCH 1/4] replace check for TARGET_WIN32 with WIN32 [PATCH 2/4] do not use mode_t on Windows [PATCH 3/4] use the underscore version of stat on Windows [PATCH 4/4] make MSVC link against shell32 as well

For details check the commit messages of the individual patches.

All patches applied to master on -testing and -stable trees. For patch 3/4, a v2 patch was applied.

commit 76a3c405549bf02902846a9bd0e7d0f3a25a5b4d

Author: Heiko Hund <[email protected]...>
Date:   Thu Feb 16 18:30:38 2012 +0100

replace check for TARGET_WIN32 with WIN32

Use of TARGET_WIN32 breaks MSVC builds as it is only defined for mingw builds done with the autotools buildsystem.

commit d0109cbf459409a84963668c78f444c97ec2b349

Author: Heiko Hund <[email protected]...>
Date:   Thu Feb 16 18:30:39 2012 +0100

do not use mode_t on Windows

The MSVC headers do not define mode_t. open() uses an int for the permissions instead. Fixes building with the MSVC based buildsystem.

commit a13cd253ca1ce987e4feca7d80bd19ff749f7787

Author: Heiko Hund <[email protected]...>
Date:   Thu Feb 16 18:30:40 2012 +0100

use the underscore version of stat on Windows

MSVC does not know wstat(). Instead _wstat() must be used here. Unfortunately _wstat() takes a 'struct _stat'. A type 'stat_t' is introduced to handle this situation in a portable way.

[v2: Use openvpn_stat_t instead of stat_t (David Sommerseth)]

commit 67fe36f888d72d2c9c2b8dac849159a229400367

Author: Heiko Hund <[email protected]...>
Date:   Thu Feb 16 18:30:41 2012 +0100
    make MSVC link against shell32 as well

    Windows API CommandLineToArgvW(), introduced in Windows unicode path
    commit 71bbbd76c62630c88441237d72fe5b61f0b45b2a, is defined therein.

    Signed-off-by: Heiko Hund <[email protected]...>
    Acked-by: Gert Doering <[email protected]...>
    Signed-off-by: David Sommerseth <[email protected]...>

kind regards,

David Sommerseth

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk8+KHgACgkQDC186MBRfrrEQwCfSZXxIf3+E+iR3+0h+HI6R5KV utwAn36V2rzrGZvdeStrp6rjG/mOtZME
=XnhK
-----END PGP SIGNATURE-----