Browse code

openvpnmsica: make adapter renaming non-fatal

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>
(cherry picked from commit b341b1c596931f8a1f77f054ba505b5c1e3547be)

Lev Stipakov authored on 2020/09/03 06:36:43
Showing 5 changed files
... ...
@@ -193,6 +193,6 @@ x_msg_va(const unsigned int flags, const char *format, va_list arglist)
193 193
         }
194 194
     }
195 195
 
196
-    MsiProcessMessage(s->hInstall, INSTALLMESSAGE_ERROR, hRecordProg);
196
+    MsiProcessMessage(s->hInstall, (flags & M_WARN) ? INSTALLMESSAGE_INFO : INSTALLMESSAGE_ERROR, hRecordProg);
197 197
     MsiCloseHandle(hRecordProg);
198 198
 }
... ...
@@ -1096,12 +1096,9 @@ ProcessDeferredAction(_In_ MSIHANDLE hInstall)
1096 1096
             dwResult = tap_create_adapter(NULL, NULL, szHardwareId, &bRebootRequired, &guidAdapter);
1097 1097
             if (dwResult == ERROR_SUCCESS)
1098 1098
             {
1099
-                /* Set adapter name. */
1100
-                dwResult = tap_set_adapter_name(&guidAdapter, szName);
1101
-                if (dwResult != ERROR_SUCCESS)
1102
-                {
1103
-                    tap_delete_adapter(NULL, &guidAdapter, &bRebootRequired);
1104
-                }
1099
+                /* Set adapter name. May fail on some machines, but that is not critical - use silent
1100
+                   flag to mute messagebox and print error only to log */
1101
+                tap_set_adapter_name(&guidAdapter, szName, TRUE);
1105 1102
             }
1106 1103
         }
1107 1104
         else if (wcsncmp(szArg[i], L"deleteN=", 8) == 0)
... ...
@@ -237,7 +237,7 @@ _tmain(int argc, LPCTSTR argv[])
237 237
             }
238 238
 
239 239
             /* Rename the adapter. */
240
-            dwResult = tap_set_adapter_name(&guidAdapter, szName);
240
+            dwResult = tap_set_adapter_name(&guidAdapter, szName, FALSE);
241 241
             if (dwResult != ERROR_SUCCESS)
242 242
             {
243 243
                 StringFromIID((REFIID)&guidAdapter, &szAdapterId);
... ...
@@ -1063,9 +1063,12 @@ ExecCommand(const WCHAR* cmdline)
1063 1063
 DWORD
1064 1064
 tap_set_adapter_name(
1065 1065
     _In_ LPCGUID pguidAdapter,
1066
-    _In_ LPCTSTR szName)
1066
+    _In_ LPCTSTR szName,
1067
+    _In_ BOOL bSilent)
1067 1068
 {
1068 1069
     DWORD dwResult;
1070
+    int msg_flag = bSilent ? M_WARN : M_NONFATAL;
1071
+    msg_flag |= M_ERRNO;
1069 1072
 
1070 1073
     if (pguidAdapter == NULL || szName == NULL)
1071 1074
     {
... ...
@@ -1099,7 +1102,7 @@ tap_set_adapter_name(
1099 1099
     if (dwResult != ERROR_SUCCESS)
1100 1100
     {
1101 1101
         SetLastError(dwResult); /* MSDN does not mention RegOpenKeyEx() to set GetLastError(). But we do have an error code. Set last error manually. */
1102
-        msg(M_NONFATAL | M_ERRNO, "%s: RegOpenKeyEx(HKLM, \"%" PRIsLPTSTR "\") failed", __FUNCTION__, szRegKey);
1102
+        msg(msg_flag, "%s: RegOpenKeyEx(HKLM, \"%" PRIsLPTSTR "\") failed", __FUNCTION__, szRegKey);
1103 1103
         goto cleanup_szAdapterId;
1104 1104
     }
1105 1105
 
... ...
@@ -1108,7 +1111,7 @@ tap_set_adapter_name(
1108 1108
     if (dwResult != ERROR_SUCCESS)
1109 1109
     {
1110 1110
         SetLastError(dwResult);
1111
-        msg(M_NONFATAL | M_ERRNO, "%s: Error reading adapter name", __FUNCTION__);
1111
+        msg(msg_flag, "%s: Error reading adapter name", __FUNCTION__);
1112 1112
         goto cleanup_hKey;
1113 1113
     }
1114 1114
 
... ...
@@ -1126,7 +1129,7 @@ tap_set_adapter_name(
1126 1126
     if (dwResult != ERROR_SUCCESS)
1127 1127
     {
1128 1128
         SetLastError(dwResult);
1129
-        msg(M_NONFATAL | M_ERRNO, "%s: Error renaming adapter", __FUNCTION__);
1129
+        msg(msg_flag, "%s: Error renaming adapter", __FUNCTION__);
1130 1130
         goto cleanup_hKey;
1131 1131
     }
1132 1132
 
... ...
@@ -118,12 +118,16 @@ tap_enable_adapter(
118 118
  *
119 119
  * @param szName        New adapter name - must be unique
120 120
  *
121
+ * @param bSilent       If true, MSI installer won't display message box and
122
+ *                      only print error to log.
123
+ *
121 124
  * @return ERROR_SUCCESS on success; Win32 error code otherwise
122 125
  **/
123 126
 DWORD
124 127
 tap_set_adapter_name(
125 128
     _In_ LPCGUID pguidAdapter,
126
-    _In_ LPCTSTR szName);
129
+    _In_ LPCTSTR szName,
130
+    _In_ BOOL bSilent);
127 131
 
128 132
 
129 133
 /**