Skip to contentSkip to conversation

openvpnmsica: make adapter renaming non-fatal

PATCH Superseded Lev Stipakov 4 participants 8 messages Sep 2, 2020 – Sep 4, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 openvpnmsica: make adapter renaming non-fatal

From: Lev Stipakov <[email protected]...>

For some users renaming adapter mysteriously fails
(https://github.com/OpenVPN/openvpn-build/issues/187),

Since renaming is just a a "nice to have", make it not fatail.

---
 src/openvpnmsica/openvpnmsica.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
src/openvpnmsica/openvpnmsica.c +2 -1
index 31e90bd2..d5b3f09e 100644
@@ -1100,7 +1100,8 @@ ProcessDeferredAction(_In_ MSIHANDLE hInstall)
                 dwResult = tap_set_adapter_name(&guidAdapter, szName);
                 if (dwResult != ERROR_SUCCESS)
                 {
-                    tap_delete_adapter(NULL, &guidAdapter, &bRebootRequired);
+                    /* failed renaming is not a fatal error, continue */
+                    dwResult = ERROR_SUCCESS;
                 }
             }
         }
Signature · 1 line
2.17.1
#1 lore raw

Hi

Quoted 18 lines · Lev Stipakov

From: Lev Stipakov <[email protected]...>

For some users renaming adapter mysteriously fails
(https://github.com/OpenVPN/openvpn-build/issues/187),

Since renaming is just a a "nice to have", make it not fatail.

---
 src/openvpnmsica/openvpnmsica.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
src/openvpnmsica/openvpnmsica.c +0 -0
index 31e90bd2..d5b3f09e 100644

src/openvpnmsica/openvpnmsica.c ProcessDeferredAction(_In_ MSIHANDLE hInstall) · line 1106

Quoted 8 lines
src/openvpnmsica/openvpnmsica.c +2 -1
@@ -1100,7 +1100,8 @@ ProcessDeferredAction(_In_ MSIHANDLE hInstall)
                 dwResult = tap_set_adapter_name(&guidAdapter, szName);
                 if (dwResult != ERROR_SUCCESS)
                 {
-                    tap_delete_adapter(NULL, &guidAdapter,
 &bRebootRequired);
+                    /* failed renaming is not a fatal error, continue */
+                    dwResult = ERROR_SUCCESS;
 

This looks strange. If we are going to rewrite dwResult, why set it and check it at all, just call
tap_set_adapter() without storing the return value and add the comment.

Or, better, print a warning message saying the rename failed.

Selva

Quoted 13 lines
src/openvpnmsica/openvpnmsica.c +0 -0
                 }
             }
         }

--
2.17.1

_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

#2 lore raw

Hi,

Quoted 9 lines

src/openvpnmsica/openvpnmsica.c ProcessDeferredAction(_In_ MSIHANDLE hInstall) · line 1104

Quoted 5 lines
                 if (dwResult != ERROR_SUCCESS)
                 {
src/openvpnmsica/openvpnmsica.c +2 -1
-                    tap_delete_adapter(NULL, &guidAdapter, &bRebootRequired);
+                    /* failed renaming is not a fatal error, continue */
+                    dwResult = ERROR_SUCCESS;

This looks strange. If we are going to rewrite dwResult, why set it and check it at all, just call tap_set_adapter() without storing the return value and add the comment.

I think this is good for documentation purposes - that we are aware that function may fail, but in this case it is not fatal and we continue.

Quoted 1 line

Or, better, print a warning message saying the rename failed.

Warning is printed inside tap_delete_adapter().

Signature · 1 line
-Lev
#3 lore raw

Hi

Quoted 11 lines · Lev Stipakov

Hi,

Quoted 3 lines
Quoted 3 lines
                 if (dwResult != ERROR_SUCCESS)
                 {

- tap_delete_adapter(NULL, &guidAdapter,

&bRebootRequired);

Quoted 1 line
Quoted 1 line

+ /* failed renaming is not a fatal error, continue

*/

Quoted 3 lines
Quoted 1 line

+ dwResult = ERROR_SUCCESS;

Quoted 7 lines
Quoted 1 line

This looks strange. If we are going to rewrite dwResult, why set it and

check it at all, just call

Quoted 1 line

tap_set_adapter() without storing the return value and add the comment.

I think this is good for documentation purposes - that we are aware that function may fail, but in this case it is not fatal and we continue.

That's achieved also by just adding a comment that we don't check the return value as failure is not fatal. Anyway, this works too.

Quoted 5 lines
Quoted 2 lines

Or, better, print a warning message saying the rename failed.

Warning is printed inside tap_delete_adapter().

tap_delete_adapter() is not called here. I was suggesting that if we do check the return value, let us also print a warning that renaming failed. That can't be done anywhere except just before converting the error to SUCCESS.

Selva

#4 lore raw

Hi,

Quoted 3 lines
Quoted 1 line

Warning is printed inside tap_delete_adapter().

tap_delete_adapter() is not called here.

Right, I managed to mistype tap_set_adapter_name().

Quoted 3 lines

I was suggesting that if we do check the return value, let us also print a warning that renaming failed. That can't be done anywhere except just before converting the error to SUCCESS.

I realized that warning inside tap_set_adapter_name() also displays a messagebox, which we probably don't want to show.

I'll send a v2 which prints warning and doesn't display a messagebox.

Signature · 1 line
-Lev
#5 lore raw

PATCH v2 1/1 openvpnmsica: make adapter renaming non-fatal

From: Lev Stipakov <[email protected]...>

For some users renaming adapter

Local Area Connection > OpenVPN TAP-Windows6

mysteriously fails, see https://github.com/OpenVPN/openvpn-build/issues/187

Since renaming is just a "nice to have", make it non-fatal and, in case of error, only log message and don't display messagebox.

---

v2: only log error, don't display messagebox

 src/openvpnmsica/dllmain.c      |  2 +-
 src/openvpnmsica/openvpnmsica.c |  9 +++------
 src/tapctl/main.c               |  2 +-
 src/tapctl/tap.c                | 11 +++++++----
 src/tapctl/tap.h                |  6 +++++-
 5 files changed, 17 insertions(+), 13 deletions(-)
src/openvpnmsica/dllmain.c +1 -1
index 201fd9af..34946ed8 100644
@@ -193,6 +193,6 @@ x_msg_va(const unsigned int flags, const char *format, va_list arglist)
         }
     }
 
-    MsiProcessMessage(s->hInstall, INSTALLMESSAGE_ERROR, hRecordProg);
+    MsiProcessMessage(s->hInstall, (flags & M_WARN) ? INSTALLMESSAGE_INFO : INSTALLMESSAGE_ERROR, hRecordProg);
     MsiCloseHandle(hRecordProg);
 }
src/openvpnmsica/openvpnmsica.c +3 -6
index 31e90bd2..f203f736 100644
@@ -1096,12 +1096,9 @@ ProcessDeferredAction(_In_ MSIHANDLE hInstall)
             dwResult = tap_create_adapter(NULL, NULL, szHardwareId, &bRebootRequired, &guidAdapter);
             if (dwResult == ERROR_SUCCESS)
             {
-                /* Set adapter name. */
-                dwResult = tap_set_adapter_name(&guidAdapter, szName);
-                if (dwResult != ERROR_SUCCESS)
-                {
-                    tap_delete_adapter(NULL, &guidAdapter, &bRebootRequired);
-                }
+                /* Set adapter name. May fail on some machines, but that is not critical - use silent
+                   flag to mute messagebox and print error only to log */
+                tap_set_adapter_name(&guidAdapter, szName, TRUE);
             }
         }
         else if (wcsncmp(szArg[i], L"deleteN=", 8) == 0)
src/tapctl/main.c +1 -1
index 31bb2ec7..d5bc7290 100644
@@ -237,7 +237,7 @@ _tmain(int argc, LPCTSTR argv[])
             }
 
             /* Rename the adapter. */
-            dwResult = tap_set_adapter_name(&guidAdapter, szName);
+            dwResult = tap_set_adapter_name(&guidAdapter, szName, FALSE);
             if (dwResult != ERROR_SUCCESS)
             {
                 StringFromIID((REFIID)&guidAdapter, &szAdapterId);
src/tapctl/tap.c +7 -4
index 7cb3dedc..0dfe239f 100644
@@ -1140,9 +1140,12 @@ ExecCommand(const WCHAR* cmdline)
 DWORD
 tap_set_adapter_name(
     _In_ LPCGUID pguidAdapter,
-    _In_ LPCTSTR szName)
+    _In_ LPCTSTR szName,
+    _In_ BOOL bSilent)
 {
     DWORD dwResult;
+    int msg_flag = bSilent ? M_WARN : M_NONFATAL;
+    msg_flag |= M_ERRNO;
 
     if (pguidAdapter == NULL || szName == NULL)
     {
@@ -1176,7 +1179,7 @@ tap_set_adapter_name(
     if (dwResult != ERROR_SUCCESS)
     {
         SetLastError(dwResult); /* MSDN does not mention RegOpenKeyEx() to set GetLastError(). But we do have an error code. Set last error manually. */
-        msg(M_NONFATAL | M_ERRNO, "%s: RegOpenKeyEx(HKLM, \"%" PRIsLPTSTR "\") failed", __FUNCTION__, szRegKey);
+        msg(msg_flag, "%s: RegOpenKeyEx(HKLM, \"%" PRIsLPTSTR "\") failed", __FUNCTION__, szRegKey);
         goto cleanup_szAdapterId;
     }
 
@@ -1185,7 +1188,7 @@ tap_set_adapter_name(
     if (dwResult != ERROR_SUCCESS)
     {
         SetLastError(dwResult);
-        msg(M_NONFATAL | M_ERRNO, "%s: Error reading adapter name", __FUNCTION__);
+        msg(msg_flag, "%s: Error reading adapter name", __FUNCTION__);
         goto cleanup_hKey;
     }
 
@@ -1203,7 +1206,7 @@ tap_set_adapter_name(
     if (dwResult != ERROR_SUCCESS)
     {
         SetLastError(dwResult);
-        msg(M_NONFATAL | M_ERRNO, "%s: Error renaming adapter", __FUNCTION__);
+        msg(msg_flag, "%s: Error renaming adapter", __FUNCTION__);
         goto cleanup_hKey;
     }
 
src/tapctl/tap.h +5 -1
index 102de32d..1f531cf2 100644
@@ -117,13 +117,17 @@ tap_enable_adapter(
  * @param pguidAdapter  A pointer to GUID that contains network adapter ID.
  *
  * @param szName        New adapter name - must be unique
+ *
+ * @param bSilent       If true, MSI installer won't display message box and
+ *                      only print error to log.
  *
  * @return ERROR_SUCCESS on success; Win32 error code otherwise
  **/
 DWORD
 tap_set_adapter_name(
     _In_ LPCGUID pguidAdapter,
-    _In_ LPCTSTR szName);
+    _In_ LPCTSTR szName,
+    _In_ BOOL bSilent);
 
 
 /**
Signature · 1 line
2.17.1
Acked-by on v2 1/1
#6 lore raw

Hi,

Quoted 166 lines

-----Original Message-----
From: Lev Stipakov <[email protected]...>
Sent: Wednesday, September 2, 2020 11:37 PM
To: [email protected]
Cc: Lev Stipakov <[email protected]...>
Subject: [Openvpn-devel] [PATCH v2] openvpnmsica: make adapter renaming non-fatal

From: Lev Stipakov <[email protected]...>

For some users renaming adapter

Local Area Connection > OpenVPN TAP-Windows6

mysteriously fails, see https://github.com/OpenVPN/openvpn-
build/issues/187

Since renaming is just a "nice to have", make it non-fatal and, in case of error, only log message and don't display messagebox.

---

v2: only log error, don't display messagebox

 src/openvpnmsica/dllmain.c      |  2 +-
 src/openvpnmsica/openvpnmsica.c |  9 +++------
 src/tapctl/main.c               |  2 +-
 src/tapctl/tap.c                | 11 +++++++----
 src/tapctl/tap.h                |  6 +++++-
 5 files changed, 17 insertions(+), 13 deletions(-)
src/openvpnmsica/dllmain.c +1 -1
index 201fd9af..34946ed8 100644
@@ -193,6 +193,6 @@ x_msg_va(const unsigned int flags, const char
 *format, va_list arglist)
         }
     }
 
-    MsiProcessMessage(s->hInstall, INSTALLMESSAGE_ERROR, hRecordProg);
+    MsiProcessMessage(s->hInstall, (flags & M_WARN) ?
 INSTALLMESSAGE_INFO : INSTALLMESSAGE_ERROR, hRecordProg);
     MsiCloseHandle(hRecordProg);

}

src/openvpnmsica/openvpnmsica.c +1 -6
index 31e90bd2..f203f736 100644
@@ -1096,12 +1096,9 @@ ProcessDeferredAction(_In_ MSIHANDLE hInstall)
             dwResult = tap_create_adapter(NULL, NULL, szHardwareId,
 &bRebootRequired, &guidAdapter);
             if (dwResult == ERROR_SUCCESS)
             {
-                /* Set adapter name. */
-                dwResult = tap_set_adapter_name(&guidAdapter, szName);
-                if (dwResult != ERROR_SUCCESS)
-                {
-                    tap_delete_adapter(NULL, &guidAdapter,
 &bRebootRequired);
-                }
+                /* Set adapter name. May fail on some machines, but

that is not critical - use silent
+ flag to mute messagebox and print error only to log
*/

src/openvpnmsica/openvpnmsica.c +1 -0
+                tap_set_adapter_name(&guidAdapter, szName, TRUE);
             }
         }
         else if (wcsncmp(szArg[i], L"deleteN=", 8) == 0)
src/tapctl/main.c +1 -1
index 31bb2ec7..d5bc7290 100644
@@ -237,7 +237,7 @@ _tmain(int argc, LPCTSTR argv[])
             }
 
             /* Rename the adapter. */
-            dwResult = tap_set_adapter_name(&guidAdapter, szName);
+            dwResult = tap_set_adapter_name(&guidAdapter, szName,
 FALSE);
             if (dwResult != ERROR_SUCCESS)
             {
                 StringFromIID((REFIID)&guidAdapter, &szAdapterId);
src/tapctl/tap.c +4 -1
index 7cb3dedc..0dfe239f 100644
@@ -1140,9 +1140,12 @@ ExecCommand(const WCHAR* cmdline)
 DWORD
 tap_set_adapter_name(
     _In_ LPCGUID pguidAdapter,
-    _In_ LPCTSTR szName)
+    _In_ LPCTSTR szName,
+    _In_ BOOL bSilent)
 {
     DWORD dwResult;
+    int msg_flag = bSilent ? M_WARN : M_NONFATAL;
+    msg_flag |= M_ERRNO;
 
     if (pguidAdapter == NULL || szName == NULL)
     {
@@ -1176,7 +1179,7 @@ tap_set_adapter_name(
     if (dwResult != ERROR_SUCCESS)
     {
         SetLastError(dwResult); /* MSDN does not mention RegOpenKeyEx()

to set GetLastError(). But we do have an error code. Set last error manually. */
- msg(M_NONFATAL | M_ERRNO, "%s: RegOpenKeyEx(HKLM, \"%"
PRIsLPTSTR "\") failed", __FUNCTION__, szRegKey);
+ msg(msg_flag, "%s: RegOpenKeyEx(HKLM, \"%" PRIsLPTSTR "\")

failed", __FUNCTION__, szRegKey);
         goto cleanup_szAdapterId;
     }
src/tapctl/tap.c +2 -2
@@ -1185,7 +1188,7 @@ tap_set_adapter_name(
     if (dwResult != ERROR_SUCCESS)
     {
         SetLastError(dwResult);
-        msg(M_NONFATAL | M_ERRNO, "%s: Error reading adapter name",
 __FUNCTION__);
+        msg(msg_flag, "%s: Error reading adapter name", __FUNCTION__);
         goto cleanup_hKey;
     }
@@ -1203,7 +1206,7 @@ tap_set_adapter_name(
     if (dwResult != ERROR_SUCCESS)
     {
         SetLastError(dwResult);
-        msg(M_NONFATAL | M_ERRNO, "%s: Error renaming adapter",
 __FUNCTION__);
+        msg(msg_flag, "%s: Error renaming adapter", __FUNCTION__);
         goto cleanup_hKey;
     }
src/tapctl/tap.h +0 -0
index 102de32d..1f531cf2 100644
@@ -117,13 +117,17 @@ tap_enable_adapter(
  * @param pguidAdapter  A pointer to GUID that contains network adapter

ID.
*
* @param szName New adapter name - must be unique
+ *
+ * @param bSilent If true, MSI installer won't display message
box and
+ * only print error to log.
*
* @return ERROR_SUCCESS on success; Win32 error code otherwise **/
DWORD
tap_set_adapter_name(
_In_ LPCGUID pguidAdapter,

src/tapctl/tap.h +2 -2
-    _In_ LPCTSTR szName);
+    _In_ LPCTSTR szName,
+    _In_ BOOL bSilent);
 
 
 /**
--

2.17.1

Quoted 4 lines

_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

I have reviewed the code, compiled it, built MSI, tested it.

Although I could not create a phantom TUN adapter to reproduce the issue. Renaming "Ethernet" adapter to "OpenVPN TAP-Windows6" and trying to install MSI next displayed an error in evaluation phase that a foreign adapter with the same name already exists - which is expected.

This patch is about solving the situation when:
1. There are no apparent TAP-Windows6 or Wintun adapters present => installation decides to create one.
2. Once adapter is created, the renaming to the desired name fails (as if the name is already taken).

I agree with everybody that having a consistently named adapter after initial setup is nice, but not that essential to make the installation fail. So...

Regards,
Simon

#7 lore raw
In reply to Lev Stipakov

Your patch has been applied to the master and release/2.5 branch.

Thanks for coming up with the solution & testing & reviewing it!

The comment line is a bit long... uncrustify will catch it next time.

I have not tested anything, trusting Lev and Simon here :-) (but from a cursory glance, the change looks nice and reasonable)

commit b341b1c596931f8a1f77f054ba505b5c1e3547be (master) commit 567e277f1cbaa8059319a8feea4c08edf77b6a5a (release/2.5)

Author: Lev Stipakov
Date:   Thu Sep 3 00:36:43 2020 +0300
     openvpnmsica: make adapter renaming non-fatal

     Signed-off-by: Lev Stipakov <[email protected]...>
     Acked-by: Simon Rozman <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg20875.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering