summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorOdd Stranne <odd@mullvad.net>2018-10-03 12:54:03 +0200
committerOdd Stranne <odd@mullvad.net>2018-10-03 12:54:03 +0200
commit161983f8b14d099450ec6377f40c2d772bfdf235 (patch)
tree87ee39d2d297c8072076998298c1dd80b98ef484
parente61f0cf6fb0f29bda264d13dab44be8ff482c66a (diff)
parente50e4dd398625838138ba06c1a172f4dde8ce817 (diff)
downloadmullvadvpn-161983f8b14d099450ec6377f40c2d772bfdf235.tar.xz
mullvadvpn-161983f8b14d099450ec6377f40c2d772bfdf235.zip
Merge branch 'win-installer-ident-tap'
-rw-r--r--CHANGELOG.md3
-rw-r--r--windows/nsis-plugins/src/driverlogic/context.cpp37
-rw-r--r--windows/nsis-plugins/src/driverlogic/context.h2
3 files changed, 38 insertions, 4 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 292ddfc053..00a21f2ef4 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -26,6 +26,9 @@ Line wrap the file at 100 chars. Th
### Changed
- Auto-hide scrollbars on macOS only, leaving them visible on other platforms.
+### Fixed
+#### Windows
+- Use different method for identifying network interfaces during installation.
## [2018.4-beta1] - 2018-10-01
### Added
diff --git a/windows/nsis-plugins/src/driverlogic/context.cpp b/windows/nsis-plugins/src/driverlogic/context.cpp
index 9c003b440c..178cc337d1 100644
--- a/windows/nsis-plugins/src/driverlogic/context.cpp
+++ b/windows/nsis-plugins/src/driverlogic/context.cpp
@@ -102,6 +102,24 @@ void LogAllAdapters(wmi::Connection &connection)
PluginLogWithDetails(L"Adapters known to WMI", details);
}
+std::wstring DoubleBackslashes(const std::wstring &str)
+{
+ auto result(str);
+
+ size_t offset = 0;
+
+ for (size_t index = 0; index < str.size(); ++index)
+ {
+ if (L'\\' == str[index])
+ {
+ result.insert(index + offset, 1, L'\\');
+ ++offset;
+ }
+ }
+
+ return result;
+}
+
} // anonymous namespace
Context::BaselineStatus Context::establishBaseline(const std::wstring &textBlock)
@@ -177,7 +195,7 @@ std::set<Context::VirtualNic> Context::ParseVirtualNics(const std::wstring &text
nic.node = text.at(line);
nic.name = std::wstring(nameDelimiter + 2);
- nic.alias = GetNicAlias(nic.name);
+ nic.alias = GetNicAlias(nic.node, nic.name);
nics.emplace(std::move(nic));
line += 4;
@@ -187,13 +205,26 @@ std::set<Context::VirtualNic> Context::ParseVirtualNics(const std::wstring &text
}
//static
-std::wstring Context::GetNicAlias(const std::wstring &name)
+std::wstring Context::GetNicAlias(const std::wstring &node, const std::wstring &name)
{
static wmi::Connection connection(wmi::Connection::Namespace::Cimv2);
std::wstringstream ss;
- ss << L"SELECT * from Win32_NetworkAdapter WHERE Name = \"" << name << L"\"";
+ //
+ // The name cannot be used when querying WMI, because WMI sometimes normalizes the
+ // names in its dataset, thereby destroying their uniqueness.
+ //
+ // E.g. if a network interface has a name of "TAP-Windows Adapter V9 #2" it will
+ // sometimes be reported by WMI as "TAP-Windows Adapter V9".
+ //
+ // Also, the node string cannot be used as-is. We have to double the backslashes in it
+ // or the string will be rejected by WMI.
+ //
+
+ const auto formattedNode = DoubleBackslashes(node);
+
+ ss << L"SELECT * FROM Win32_NetworkAdapter WHERE PNPDeviceID = \"" << formattedNode << L"\"";
auto resultset = connection.query(ss.str().c_str());
diff --git a/windows/nsis-plugins/src/driverlogic/context.h b/windows/nsis-plugins/src/driverlogic/context.h
index 53d2ddeedc..b9d34f68d5 100644
--- a/windows/nsis-plugins/src/driverlogic/context.h
+++ b/windows/nsis-plugins/src/driverlogic/context.h
@@ -44,7 +44,7 @@ public:
private:
static std::set<VirtualNic> ParseVirtualNics(const std::wstring &textBlock);
- static std::wstring GetNicAlias(const std::wstring &name);
+ static std::wstring GetNicAlias(const std::wstring &node, const std::wstring &name);
std::set<VirtualNic> m_baseline;
std::set<VirtualNic> m_currentState;