]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
openvpnmsica: make adapter renaming non-fatal
authorLev Stipakov <lev@openvpn.net>
Wed, 2 Sep 2020 21:36:43 +0000 (00:36 +0300)
committerGert Doering <gert@greenie.muc.de>
Fri, 4 Sep 2020 19:22:15 +0000 (21:22 +0200)
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.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
Acked-by: Simon Rozman <simon@rozman.si>
Message-Id: <20200902213643.401-1-lstipakov@gmail.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg20875.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
src/openvpnmsica/dllmain.c
src/openvpnmsica/openvpnmsica.c
src/tapctl/main.c
src/tapctl/tap.c
src/tapctl/tap.h

index 201fd9af464a961527efa688192eb46d800bd7c5..34946ed8cfeafa7a9673acf983c1eef3c2d220ae 100644 (file)
@@ -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);
 }
index 31e90bd2db2c4fc6266a59f2ad036b278c735b2b..f203f736ae75e053218a404b0903f50f8ac56bc1 100644 (file)
@@ -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)
index 31bb2ec7283e8c3a0e74da6ef6255741fe90b494..d5bc72909bb5771af44e6c1e9fa2de77c478d641 100644 (file)
@@ -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);
index e36d1328762cc5883b9155da49c02268c1464dcc..dd4a10a3149c905e47e52e97dc1f27bab5ec1325 100644 (file)
@@ -1063,9 +1063,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)
     {
@@ -1099,7 +1102,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;
     }
 
@@ -1108,7 +1111,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;
     }
 
@@ -1126,7 +1129,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;
     }
 
index 102de32d62e5abd0e6c715af54154ca7ef8c702d..63d791c9854c0d67bbb6a8f90642613fa5735db4 100644 (file)
@@ -118,12 +118,16 @@ tap_enable_adapter(
  *
  * @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);
 
 
 /**