-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path75b6419892259a9f6d7a1266962f318e08fb2d01.diff
103 lines (99 loc) · 3.66 KB
/
75b6419892259a9f6d7a1266962f318e08fb2d01.diff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
diff --git a/chrome/updater/net/network_fetcher_win.cc b/chrome/updater/net/network_fetcher_win.cc
index 9b44987a8ddbc..c8092d28bdd0d 100644
--- a/chrome/updater/net/network_fetcher_win.cc
+++ b/chrome/updater/net/network_fetcher_win.cc
@@ -21,6 +21,7 @@
#include "base/sequence_checker.h"
#include "base/strings/sys_string_conversions.h"
#include "base/strings/utf_string_conversions.h"
+#include "base/win/windows_version.h"
#include "chrome/updater/net/network.h"
#include "chrome/updater/policy/service.h"
#include "chrome/updater/updater_scope.h"
@@ -37,6 +38,54 @@
namespace updater {
namespace {
+std::wstring FromCharOrEmpty(const wchar_t* str) {
+ return str ? std::wstring(str) : std::wstring();
+}
+
+// Wrapper for WINHTTP_CURRENT_USER_IE_PROXY_CONFIG structure.
+// According to MSDN, callers must free strings with GlobalFree.
+class ScopedIeProxyConfig {
+ public:
+ ScopedIeProxyConfig();
+ ScopedIeProxyConfig(const ScopedIeProxyConfig&) = delete;
+ ScopedIeProxyConfig& operator=(const ScopedIeProxyConfig&) = delete;
+ ~ScopedIeProxyConfig();
+
+ WINHTTP_CURRENT_USER_IE_PROXY_CONFIG* receive() { return &ie_proxy_config_; }
+
+ bool auto_detect() const { return ie_proxy_config_.fAutoDetect; }
+ std::wstring auto_config_url() const {
+ return FromCharOrEmpty(ie_proxy_config_.lpszAutoConfigUrl);
+ }
+ std::wstring proxy() const {
+ return FromCharOrEmpty(ie_proxy_config_.lpszProxy);
+ }
+ std::wstring proxy_bypass() const {
+ return FromCharOrEmpty(ie_proxy_config_.lpszProxyBypass);
+ }
+
+ private:
+ WINHTTP_CURRENT_USER_IE_PROXY_CONFIG ie_proxy_config_ = {};
+};
+
+ScopedIeProxyConfig::ScopedIeProxyConfig() {
+ ie_proxy_config_.fAutoDetect = false;
+ ie_proxy_config_.lpszAutoConfigUrl = nullptr;
+ ie_proxy_config_.lpszProxy = nullptr;
+ ie_proxy_config_.lpszProxyBypass = nullptr;
+}
+
+ScopedIeProxyConfig::~ScopedIeProxyConfig() {
+ if (ie_proxy_config_.lpszAutoConfigUrl)
+ ::GlobalFree(ie_proxy_config_.lpszAutoConfigUrl);
+
+ if (ie_proxy_config_.lpszProxy)
+ ::GlobalFree(ie_proxy_config_.lpszProxy);
+
+ if (ie_proxy_config_.lpszProxyBypass)
+ ::GlobalFree(ie_proxy_config_.lpszProxyBypass);
+}
+
// Factory method for the proxy configuration strategy.
scoped_refptr<winhttp::ProxyConfiguration> GetProxyConfiguration(
std::optional<PolicyServiceProxyConfiguration>
@@ -53,7 +102,32 @@ scoped_refptr<winhttp::ProxyConfiguration> GetProxyConfiguration(
L""});
}
VLOG(1) << "Using the system configuration for proxy.";
- return base::MakeRefCounted<winhttp::AutoProxyConfiguration>();
+ const base::win::OSInfo* os_info = base::win::OSInfo::GetInstance();
+ const bool supports_automatic_proxy =
+ os_info->version() >= base::win::Version::WIN8_1;
+ if (supports_automatic_proxy) {
+ return base::MakeRefCounted<winhttp::AutoProxyConfiguration>();
+ }
+
+ ScopedImpersonation impersonate_user;
+ if (IsLocalSystemUser()) {
+ VLOG(2) << "Running as SYSTEM, impersonate the current user.";
+ base::win::ScopedHandle user_token = GetUserTokenFromCurrentSessionId();
+ if (user_token.IsValid()) {
+ impersonate_user.Impersonate(user_token.Get());
+ }
+ }
+
+ ScopedIeProxyConfig ie_proxy_config;
+ if (::WinHttpGetIEProxyConfigForCurrentUser(ie_proxy_config.receive())) {
+ return base::MakeRefCounted<winhttp::ProxyConfiguration>(winhttp::ProxyInfo{
+ ie_proxy_config.auto_detect(), ie_proxy_config.auto_config_url(),
+ ie_proxy_config.proxy(), ie_proxy_config.proxy_bypass()});
+ } else {
+ PLOG(ERROR) << "Failed to get proxy for current user";
+ }
+
+ return base::MakeRefCounted<winhttp::ProxyConfiguration>();
}
class NetworkFetcher : public update_client::NetworkFetcher {