]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
Support non-ASCII TAP adapter names on Windows
authorHeiko Hund <heiko.hund@sophos.com>
Tue, 15 Oct 2013 09:23:42 +0000 (11:23 +0200)
committerGert Doering <gert@greenie.muc.de>
Wed, 23 Oct 2013 17:36:57 +0000 (19:36 +0200)
Currently the TAP adapter name is fetched as an OEM string, which
is problematic if it contains non-ASCII characters and is to used
with netsh. The logfile also contains these non UTF-8 characters.

This patch fetches the name from the registry as UCS-2 and converts
it right into UTF-8 before it's used.

Signed-off-by: Heiko Hund <heiko.hund@sophos.com>
Acked-by: Josh Cepek <josh.cepek@usa.net>
Message-Id: <1381829022-15244-1-git-send-email-heiko.hund@sophos.com>
URL: http://article.gmane.org/gmane.network.openvpn.devel/7913
Signed-off-by: Gert Doering <gert@greenie.muc.de>
src/openvpn/tun.c

index 86a43f22ac6856fd8c82aef8230571e7d3f3db41..9f53b23bca81c27beafcc905b624c65835714424 100644 (file)
@@ -3141,9 +3141,9 @@ get_panel_reg (struct gc_arena *gc)
       char enum_name[256];
       char connection_string[256];
       HKEY connection_key;
-      char name_data[256];
+      WCHAR name_data[256];
       DWORD name_type;
-      const char name_string[] = "Name";
+      const WCHAR name_string[] = L"Name";
 
       len = sizeof (enum_name);
       status = RegEnumKeyEx(
@@ -3177,12 +3177,12 @@ get_panel_reg (struct gc_arena *gc)
       else
        {
          len = sizeof (name_data);
-         status = RegQueryValueEx(
+         status = RegQueryValueExW(
                                   connection_key,
                                   name_string,
                                   NULL,
                                   &name_type,
-                                  name_data,
+                                  (LPBYTE) name_data,
                                   &len);
 
          if (status != ERROR_SUCCESS || name_type != REG_SZ)
@@ -3190,10 +3190,15 @@ get_panel_reg (struct gc_arena *gc)
                 NETWORK_CONNECTIONS_KEY, connection_string, name_string);
          else
            {
+              int n;
+              LPSTR name;
              struct panel_reg *reg;
 
              ALLOC_OBJ_CLEAR_GC (reg, struct panel_reg, gc);
-             reg->name = string_alloc (name_data, gc);
+              n = WideCharToMultiByte (CP_UTF8, 0, name_data, -1, NULL, 0, NULL, NULL);
+              name = gc_malloc (n, false, gc);
+              WideCharToMultiByte (CP_UTF8, 0, name_data, -1, name, n, NULL, NULL);
+              reg->name = name;
              reg->guid = string_alloc (enum_name, gc);
                      
              /* link into return list */