OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/chromeos/cros/network_library_impl_base.h" | 5 #include "chrome/browser/chromeos/cros/network_library_impl_base.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
9 #include "base/memory/scoped_vector.h" | 9 #include "base/memory/scoped_vector.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
12 #include "chrome/browser/chromeos/cros/native_network_parser.h" | 12 #include "chrome/browser/chromeos/cros/native_network_parser.h" |
13 #include "chrome/browser/chromeos/cros/network_constants.h" | |
13 #include "chrome/browser/chromeos/cros/onc_network_parser.h" | 14 #include "chrome/browser/chromeos/cros/onc_network_parser.h" |
14 #include "chrome/browser/chromeos/network_login_observer.h" | 15 #include "chrome/browser/chromeos/network_login_observer.h" |
15 #include "chromeos/network/onc/onc_certificate_importer.h" | 16 #include "chromeos/network/onc/onc_certificate_importer.h" |
16 #include "chromeos/network/onc/onc_constants.h" | 17 #include "chromeos/network/onc/onc_constants.h" |
17 #include "chromeos/network/onc/onc_signature.h" | 18 #include "chromeos/network/onc/onc_signature.h" |
18 #include "chromeos/network/onc/onc_utils.h" | 19 #include "chromeos/network/onc/onc_utils.h" |
19 #include "chromeos/network/onc/onc_validator.h" | 20 #include "chromeos/network/onc/onc_validator.h" |
20 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
21 #include "crypto/nss_util.h" // crypto::GetTPMTokenInfo() for 802.1X and VPN. | 22 #include "crypto/nss_util.h" // crypto::GetTPMTokenInfo() for 802.1X and VPN. |
22 #include "grit/generated_resources.h" | 23 #include "grit/generated_resources.h" |
(...skipping 1096 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1119 } | 1120 } |
1120 } | 1121 } |
1121 | 1122 |
1122 std::set<std::string> removal_ids; | 1123 std::set<std::string> removal_ids; |
1123 std::set<std::string>& network_ids(network_source_map_[source]); | 1124 std::set<std::string>& network_ids(network_source_map_[source]); |
1124 network_ids.clear(); | 1125 network_ids.clear(); |
1125 if (has_network_configurations) { | 1126 if (has_network_configurations) { |
1126 VLOG(2) << "ONC file has " << network_configs->GetSize() << " networks"; | 1127 VLOG(2) << "ONC file has " << network_configs->GetSize() << " networks"; |
1127 OncNetworkParser parser(*network_configs, source); | 1128 OncNetworkParser parser(*network_configs, source); |
1128 | 1129 |
1129 // Parse all networks. Bail out if that fails. | |
1130 NetworkOncMap added_onc_map; | |
1131 ScopedVector<Network> networks; | |
1132 for (int i = 0; i < parser.GetNetworkConfigsSize(); i++) { | 1130 for (int i = 0; i < parser.GetNetworkConfigsSize(); i++) { |
1133 // Parse Open Network Configuration blob into a temporary Network object. | 1131 // Parse Open Network Configuration blob into a temporary Network object. |
1134 bool marked_for_removal = false; | 1132 bool marked_for_removal = false; |
1135 Network* network = parser.ParseNetwork(i, &marked_for_removal); | 1133 scoped_ptr<Network> network(parser.ParseNetwork(i, &marked_for_removal)); |
1136 if (!network) { | 1134 if (!network) { |
1137 LOG(ERROR) << "Error during ONC parsing network at index " << i | 1135 LOG(ERROR) << "Error during ONC parsing network at index " << i |
1138 << " from " << onc::GetSourceAsString(source); | 1136 << " from " << onc::GetSourceAsString(source); |
1139 success = false; | 1137 success = false; |
1140 continue; | 1138 continue; |
1141 } | 1139 } |
1142 | 1140 |
1143 // Disallow anything but WiFi and Ethernet for device-level policy (which | 1141 // Disallow anything but WiFi and Ethernet for device-level policy (which |
1144 // corresponds to shared networks). See also http://crosbug.com/28741. | 1142 // corresponds to shared networks). See also http://crosbug.com/28741. |
1145 if (source == onc::ONC_SOURCE_DEVICE_POLICY && | 1143 if (source == onc::ONC_SOURCE_DEVICE_POLICY && |
1146 network->type() != TYPE_WIFI && | 1144 network->type() != TYPE_WIFI && |
1147 network->type() != TYPE_ETHERNET) { | 1145 network->type() != TYPE_ETHERNET) { |
1148 LOG(WARNING) << "Ignoring device-level policy-pushed network of type " | 1146 LOG(WARNING) << "Ignoring device-level policy-pushed network of type " |
1149 << network->type(); | 1147 << network->type(); |
1150 delete network; | |
1151 continue; | 1148 continue; |
1152 } | 1149 } |
1153 | 1150 |
1154 networks.push_back(network); | 1151 if (source == onc::ONC_SOURCE_USER_IMPORT && marked_for_removal) { |
1155 if (!(source == onc::ONC_SOURCE_USER_IMPORT && | 1152 // User import supports the removal of networks by ID. |
1156 marked_for_removal)) { | |
1157 added_onc_map[network->unique_id()] = parser.GetNetworkConfig(i); | |
1158 } | |
1159 | |
1160 if (marked_for_removal) | |
1161 removal_ids.insert(network->unique_id()); | 1153 removal_ids.insert(network->unique_id()); |
1162 } | |
1163 | |
1164 // Update the ONC map. | |
1165 for (NetworkOncMap::iterator iter(added_onc_map.begin()); | |
1166 iter != added_onc_map.end(); ++iter) { | |
1167 const base::DictionaryValue*& entry = network_onc_map_[iter->first]; | |
1168 delete entry; | |
1169 entry = iter->second->DeepCopy(); | |
1170 } | |
1171 | |
1172 // Configure the networks. While doing so, collect unique identifiers of the | |
1173 // networks that are defined in the ONC blob in |network_ids|. They're later | |
1174 // used to clean out any previously-existing networks that had been | |
1175 // configured through policy but are no longer specified in the updated ONC | |
1176 // blob. | |
1177 for (std::vector<Network*>::iterator iter(networks.begin()); | |
1178 iter != networks.end(); ++iter) { | |
1179 Network* network = *iter; | |
1180 | |
1181 // Don't configure a network that is supposed to be removed. For | |
1182 // policy-managed networks, the "remove" functionality of ONC is ignored. | |
1183 if (source == onc::ONC_SOURCE_USER_IMPORT && | |
1184 removal_ids.find(network->unique_id()) != removal_ids.end()) { | |
1185 continue; | 1154 continue; |
1186 } | 1155 } |
1187 | 1156 |
1188 DictionaryValue dict; | 1157 if (marked_for_removal) { |
1158 // Don't configure a network that is supposed to be removed. For | |
Greg Spencer (Chromium)
2012/12/21 17:52:45
nit: You could put the comment above the "if" and
pneubeck (no reviews)
2013/01/08 13:40:23
Done.
| |
1159 // policy-managed networks, the "remove" functionality of ONC is | |
1160 // irrelevant. Instead in general, all previously configured networks | |
Greg Spencer (Chromium)
2012/12/21 17:52:45
nit: add a comma: "Instead, in general,"
pneubeck (no reviews)
2013/01/08 13:40:23
Done.
| |
1161 // that are no longer configured are removed. | |
1162 continue; | |
1163 } | |
1164 | |
1165 // Update the ONC map. | |
1166 const base::DictionaryValue*& entry = | |
1167 network_onc_map_[network->unique_id()]; | |
1168 delete entry; | |
1169 entry = parser.GetNetworkConfig(i)->DeepCopy(); | |
1170 | |
1171 // Configure the network. | |
1172 base::DictionaryValue dict; | |
1189 for (Network::PropertyMap::const_iterator props = | 1173 for (Network::PropertyMap::const_iterator props = |
1190 network->property_map_.begin(); | 1174 network->property_map_.begin(); |
1191 props != network->property_map_.end(); ++props) { | 1175 props != network->property_map_.end(); ++props) { |
1192 std::string key = | 1176 std::string key = |
1193 NativeNetworkParser::property_mapper()->GetKey(props->first); | 1177 NativeNetworkParser::property_mapper()->GetKey(props->first); |
1194 if (!key.empty()) | 1178 if (!key.empty()) |
1195 dict.SetWithoutPathExpansion(key, props->second->DeepCopy()); | 1179 dict.SetWithoutPathExpansion(key, props->second->DeepCopy()); |
1196 else | 1180 else |
1197 VLOG(2) << "Property " << props->first << " will not be sent"; | 1181 VLOG(2) << "Property " << props->first << " will not be sent"; |
1198 } | 1182 } |
1199 | 1183 |
1200 // Set the appropriate profile for |source|. | 1184 // Set the appropriate profile for |source|. |
1201 if (profile != NULL) | 1185 if (profile != NULL) |
1202 dict.SetString(flimflam::kProfileProperty, profile->path); | 1186 dict.SetString(flimflam::kProfileProperty, profile->path); |
1203 | 1187 |
1204 // For Ethernet networks, apply them to the current Ethernet service. | 1188 // For Ethernet networks, apply them to the current Ethernet service. |
1205 if (network->type() == TYPE_ETHERNET) { | 1189 if (network->type() == TYPE_ETHERNET) { |
1206 const EthernetNetwork* ethernet = ethernet_network(); | 1190 const EthernetNetwork* ethernet = ethernet_network(); |
1207 if (ethernet) { | 1191 if (ethernet) { |
1208 CallConfigureService(ethernet->unique_id(), &dict); | 1192 CallConfigureService(ethernet->unique_id(), &dict); |
1209 } else { | 1193 } else { |
1210 LOG(WARNING) << "Tried to import ONC with an Ethernet network when " | 1194 LOG(WARNING) << "Tried to import ONC with an Ethernet network when " |
1211 << "there is no active Ethernet connection."; | 1195 << "there is no active Ethernet connection."; |
1212 } | 1196 } |
1213 } else { | 1197 } else { |
1214 CallConfigureService(network->unique_id(), &dict); | 1198 CallConfigureService(network->unique_id(), &dict); |
1215 } | 1199 } |
1216 | 1200 |
1201 // Store the unique identifier of the network that is defined in the ONC | |
1202 // blob in |network_ids|. The identifiers are later used to clean out any | |
1203 // previously-existing networks that had been configured through policy | |
1204 // but are no longer specified in the updated ONC blob. | |
1217 network_ids.insert(network->unique_id()); | 1205 network_ids.insert(network->unique_id()); |
1218 } | 1206 } |
1219 } | 1207 } |
1220 | 1208 |
1221 if (from_policy) { | 1209 if (from_policy) { |
1222 // For policy-managed networks, go through the list of existing remembered | 1210 // For policy-managed networks, go through the list of existing remembered |
1223 // networks and clean out the ones that no longer have a definition in the | 1211 // networks and clean out the ones that no longer have a definition in the |
1224 // ONC blob. We first collect the networks and do the actual deletion later | 1212 // ONC blob. We first collect the networks and do the actual deletion later |
1225 // because ForgetNetwork() changes the remembered network vectors. | 1213 // because ForgetNetwork() changes the remembered network vectors. |
1226 ForgetNetworksById(source, network_ids, false); | 1214 ForgetNetworksById(source, network_ids, false); |
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1745 GetTpmInfo(); | 1733 GetTpmInfo(); |
1746 return tpm_slot_; | 1734 return tpm_slot_; |
1747 } | 1735 } |
1748 | 1736 |
1749 const std::string& NetworkLibraryImplBase::GetTpmPin() { | 1737 const std::string& NetworkLibraryImplBase::GetTpmPin() { |
1750 GetTpmInfo(); | 1738 GetTpmInfo(); |
1751 return tpm_pin_; | 1739 return tpm_pin_; |
1752 } | 1740 } |
1753 | 1741 |
1754 } // namespace chromeos | 1742 } // namespace chromeos |
OLD | NEW |