OLD | NEW |
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium OS 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 "update_engine/omaha_request_params.h" | 5 #include "update_engine/omaha_request_params.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 #include <sys/utsname.h> | 9 #include <sys/utsname.h> |
10 | 10 |
11 #include <map> | 11 #include <map> |
12 #include <string> | 12 #include <string> |
| 13 #include <vector> |
13 | 14 |
14 #include <base/file_util.h> | 15 #include <base/file_util.h> |
15 #include <base/string_util.h> | 16 #include <base/string_util.h> |
16 | 17 |
17 #include "update_engine/simple_key_value_store.h" | 18 #include "update_engine/simple_key_value_store.h" |
18 #include "update_engine/utils.h" | 19 #include "update_engine/utils.h" |
19 | 20 |
20 #define CALL_MEMBER_FN(object, member) ((object).*(member)) | 21 #define CALL_MEMBER_FN(object, member) ((object).*(member)) |
21 | 22 |
22 using std::map; | 23 using std::map; |
23 using std::string; | 24 using std::string; |
| 25 using std::vector; |
24 | 26 |
25 namespace chromeos_update_engine { | 27 namespace chromeos_update_engine { |
26 | 28 |
27 const char OmahaRequestParams::kUpdateTrackKey[] = "CHROMEOS_RELEASE_TRACK"; | 29 const char OmahaRequestParams::kUpdateTrackKey[] = "CHROMEOS_RELEASE_TRACK"; |
28 | 30 |
29 const char* const OmahaRequestParams::kAppId( | 31 const char* const OmahaRequestParams::kAppId( |
30 "{87efface-864d-49a5-9bb3-4b050a7c227a}"); | 32 "{87efface-864d-49a5-9bb3-4b050a7c227a}"); |
31 const char* const OmahaRequestParams::kOsPlatform("Chrome OS"); | 33 const char* const OmahaRequestParams::kOsPlatform("Chrome OS"); |
32 const char* const OmahaRequestParams::kOsVersion("Indy"); | 34 const char* const OmahaRequestParams::kOsVersion("Indy"); |
33 const char* const OmahaRequestParams::kUpdateUrl( | 35 const char* const OmahaRequestParams::kUpdateUrl( |
34 "https://tools.google.com/service/update2"); | 36 "https://tools.google.com/service/update2"); |
35 | 37 |
36 static const char kHWIDPath[] = "/sys/devices/platform/chromeos_acpi/HWID"; | 38 static const char kHWIDPath[] = "/sys/devices/platform/chromeos_acpi/HWID"; |
37 | 39 |
38 OmahaRequestDeviceParams::OmahaRequestDeviceParams() : | 40 OmahaRequestDeviceParams::OmahaRequestDeviceParams() : |
39 force_build_type_(false), | 41 force_build_type_(false), |
40 forced_official_build_(false) {} | 42 forced_official_build_(false) {} |
41 | 43 |
42 bool OmahaRequestDeviceParams::Init(const std::string& in_app_version, | 44 bool OmahaRequestDeviceParams::Init(const std::string& in_app_version, |
43 const std::string& in_update_url) { | 45 const std::string& in_update_url) { |
44 os_platform = OmahaRequestParams::kOsPlatform; | 46 os_platform = OmahaRequestParams::kOsPlatform; |
45 os_version = OmahaRequestParams::kOsVersion; | 47 os_version = OmahaRequestParams::kOsVersion; |
46 app_version = in_app_version.empty() ? | 48 app_version = in_app_version.empty() ? |
47 GetLsbValue("CHROMEOS_RELEASE_VERSION", "", NULL) : in_app_version; | 49 GetLsbValue("CHROMEOS_RELEASE_VERSION", "", NULL, true) : in_app_version; |
48 os_sp = app_version + "_" + GetMachineType(); | 50 os_sp = app_version + "_" + GetMachineType(); |
49 os_board = GetLsbValue("CHROMEOS_RELEASE_BOARD", "", NULL); | 51 os_board = GetLsbValue("CHROMEOS_RELEASE_BOARD", "", NULL, true); |
50 app_id = GetLsbValue("CHROMEOS_RELEASE_APPID", | 52 app_id = GetLsbValue("CHROMEOS_RELEASE_APPID", |
51 OmahaRequestParams::kAppId, | 53 OmahaRequestParams::kAppId, |
52 NULL); | 54 NULL, |
| 55 true); |
53 app_lang = "en-US"; | 56 app_lang = "en-US"; |
54 app_track = GetLsbValue( | 57 app_track = GetLsbValue( |
55 kUpdateTrackKey, | 58 kUpdateTrackKey, |
56 "", | 59 "", |
57 &chromeos_update_engine::OmahaRequestDeviceParams::IsValidTrack); | 60 &chromeos_update_engine::OmahaRequestDeviceParams::IsValidTrack, |
| 61 true); |
58 hardware_class = GetHardwareClass(); | 62 hardware_class = GetHardwareClass(); |
59 struct stat stbuf; | 63 struct stat stbuf; |
60 | 64 |
61 // Deltas are only okay if the /.nodelta file does not exist. | 65 // Deltas are only okay if the /.nodelta file does not exist. If we don't |
62 // If we don't know (i.e. stat() returns some unexpected error), | 66 // know (i.e. stat() returns some unexpected error), then err on the side of |
63 // then err on the side of caution and say deltas are not okay | 67 // caution and say deltas are not okay. |
64 delta_okay = (stat((root_ + "/.nodelta").c_str(), &stbuf) < 0) && | 68 delta_okay = (stat((root_ + "/.nodelta").c_str(), &stbuf) < 0) && |
65 (errno == ENOENT); | 69 (errno == ENOENT); |
66 | 70 |
| 71 // For now, disable delta updates if the rootfs track is different than the |
| 72 // track that we're sending to the update server because such updates are |
| 73 // destined to fail -- the source rootfs hash will be different than the |
| 74 // expected hash due to the different track in /etc/lsb-release. |
| 75 // |
| 76 // Longer term we should consider an alternative: (a) clients can send |
| 77 // (current_version, current_channel, new_channel) information, or (b) the |
| 78 // build process can make sure releases on separate tracks are identical (i.e, |
| 79 // by not stamping the release with the channel), or (c) the release process |
| 80 // can ensure that different channels get different version numbers. |
| 81 const string rootfs_track = GetLsbValue( |
| 82 kUpdateTrackKey, |
| 83 "", |
| 84 &chromeos_update_engine::OmahaRequestDeviceParams::IsValidTrack, |
| 85 false); |
| 86 delta_okay = delta_okay && rootfs_track == app_track; |
| 87 |
67 update_url = in_update_url.empty() ? | 88 update_url = in_update_url.empty() ? |
68 GetLsbValue("CHROMEOS_AUSERVER", OmahaRequestParams::kUpdateUrl, NULL) : | 89 GetLsbValue("CHROMEOS_AUSERVER", |
| 90 OmahaRequestParams::kUpdateUrl, |
| 91 NULL, |
| 92 true) : |
69 in_update_url; | 93 in_update_url; |
70 return true; | 94 return true; |
71 } | 95 } |
72 | 96 |
73 bool OmahaRequestDeviceParams::SetTrack(const std::string& track) { | 97 bool OmahaRequestDeviceParams::SetTrack(const std::string& track) { |
74 TEST_AND_RETURN_FALSE(IsValidTrack(track)); | 98 TEST_AND_RETURN_FALSE(IsValidTrack(track)); |
75 FilePath kFile(root_ + utils::kStatefulPartition + "/etc/lsb-release"); | 99 FilePath kFile(root_ + utils::kStatefulPartition + "/etc/lsb-release"); |
76 string file_data; | 100 string file_data; |
77 map<string, string> data; | 101 map<string, string> data; |
78 if (file_util::ReadFileToString(kFile, &file_data)) { | 102 if (file_util::ReadFileToString(kFile, &file_data)) { |
(...skipping 17 matching lines...) Expand all Loading... |
96 | 120 |
97 string OmahaRequestDeviceParams::GetDeviceTrack() { | 121 string OmahaRequestDeviceParams::GetDeviceTrack() { |
98 OmahaRequestDeviceParams params; | 122 OmahaRequestDeviceParams params; |
99 // Note that params.app_track is an empty string if the value in | 123 // Note that params.app_track is an empty string if the value in |
100 // lsb-release file is invalid. See Init() for details. | 124 // lsb-release file is invalid. See Init() for details. |
101 return params.Init("", "") ? params.app_track : ""; | 125 return params.Init("", "") ? params.app_track : ""; |
102 } | 126 } |
103 | 127 |
104 string OmahaRequestDeviceParams::GetLsbValue(const string& key, | 128 string OmahaRequestDeviceParams::GetLsbValue(const string& key, |
105 const string& default_value, | 129 const string& default_value, |
106 ValueValidator validator) const { | 130 ValueValidator validator, |
107 string files[] = {string(utils::kStatefulPartition) + "/etc/lsb-release", | 131 bool stateful_override) const { |
108 "/etc/lsb-release"}; | 132 vector<string> files; |
109 for (unsigned int i = 0; i < arraysize(files); ++i) { | 133 if (stateful_override) { |
110 // TODO(adlr): make sure files checked are owned as root (and all | 134 files.push_back(string(utils::kStatefulPartition) + "/etc/lsb-release"); |
111 // their parents are recursively, too). | 135 } |
| 136 files.push_back("/etc/lsb-release"); |
| 137 for (vector<string>::const_iterator it = files.begin(); |
| 138 it != files.end(); ++it) { |
| 139 // TODO(adlr): make sure files checked are owned as root (and all their |
| 140 // parents are recursively, too). |
112 string file_data; | 141 string file_data; |
113 if (!utils::ReadFileToString(root_ + files[i], &file_data)) | 142 if (!utils::ReadFileToString(root_ + *it, &file_data)) |
114 continue; | 143 continue; |
115 | 144 |
116 map<string, string> data = simple_key_value_store::ParseString(file_data); | 145 map<string, string> data = simple_key_value_store::ParseString(file_data); |
117 if (utils::MapContainsKey(data, key)) { | 146 if (utils::MapContainsKey(data, key)) { |
118 const string& value = data[key]; | 147 const string& value = data[key]; |
119 if (validator && !CALL_MEMBER_FN(*this, validator)(value)) { | 148 if (validator && !CALL_MEMBER_FN(*this, validator)(value)) { |
120 continue; | 149 continue; |
121 } | 150 } |
122 return value; | 151 return value; |
123 } | 152 } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 } | 193 } |
165 return false; | 194 return false; |
166 } | 195 } |
167 | 196 |
168 void OmahaRequestDeviceParams::SetBuildTypeOfficial(bool is_official) { | 197 void OmahaRequestDeviceParams::SetBuildTypeOfficial(bool is_official) { |
169 force_build_type_ = true; | 198 force_build_type_ = true; |
170 forced_official_build_ = is_official; | 199 forced_official_build_ = is_official; |
171 } | 200 } |
172 | 201 |
173 } // namespace chromeos_update_engine | 202 } // namespace chromeos_update_engine |
OLD | NEW |