OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "update_engine/omaha_request_prep_action.h" | 5 #include "update_engine/omaha_request_prep_action.h" |
6 #include <sys/utsname.h> | 6 #include <sys/utsname.h> |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <string> | 8 #include <string> |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "update_engine/utils.h" | 10 #include "update_engine/utils.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 } | 21 } |
22 } // namespace {} | 22 } // namespace {} |
23 | 23 |
24 namespace chromeos_update_engine { | 24 namespace chromeos_update_engine { |
25 | 25 |
26 void OmahaRequestPrepAction::PerformAction() { | 26 void OmahaRequestPrepAction::PerformAction() { |
27 // TODO(adlr): honor force_full_update_ | 27 // TODO(adlr): honor force_full_update_ |
28 ScopedActionCompleter completer(processor_, this); | 28 ScopedActionCompleter completer(processor_, this); |
29 string machine_id; | 29 string machine_id; |
30 TEST_AND_RETURN(GetMachineId(&machine_id)); | 30 TEST_AND_RETURN(GetMachineId(&machine_id)); |
31 const string version(GetLsbValue("GOOGLE_RELEASE")); | 31 const string version(GetLsbValue("CHROMEOS_RELEASE_VERSION", "")); |
32 const string sp(version + "_" + GetMachineType()); | 32 const string sp(version + "_" + GetMachineType()); |
33 const string track(GetLsbValue("GOOGLE_TRACK")); | 33 const string track(GetLsbValue("CHROMEOS_RELEASE_TRACK", "")); |
| 34 const string update_url(GetLsbValue("CHROMEOS_AUSERVER", |
| 35 UpdateCheckParams::kUpdateUrl)); |
34 | 36 |
35 UpdateCheckParams out(machine_id, // machine_id | 37 UpdateCheckParams out(machine_id, // machine_id |
36 machine_id, // user_id (use machine_id) | 38 machine_id, // user_id (use machine_id) |
37 UpdateCheckParams::kOsPlatform, | 39 UpdateCheckParams::kOsPlatform, |
38 UpdateCheckParams::kOsVersion, | 40 UpdateCheckParams::kOsVersion, |
39 sp, // e.g. 0.2.3.3_i686 | 41 sp, // e.g. 0.2.3.3_i686 |
40 UpdateCheckParams::kAppId, | 42 UpdateCheckParams::kAppId, |
41 version, // app version (from lsb-release) | 43 version, // app version (from lsb-release) |
42 "en-US", //lang | 44 "en-US", // lang |
43 track); // track | 45 track, // track |
| 46 UpdateCheckParams::kUpdateUrl); |
44 | 47 |
45 CHECK(HasOutputPipe()); | 48 CHECK(HasOutputPipe()); |
46 SetOutputObject(out); | 49 SetOutputObject(out); |
47 completer.set_success(true); | 50 completer.set_success(true); |
48 } | 51 } |
49 | 52 |
50 namespace { | 53 namespace { |
51 const size_t kGuidDataByteLength = 128 / 8; | 54 const size_t kGuidDataByteLength = 128 / 8; |
52 const string::size_type kGuidStringLength = 38; | 55 const string::size_type kGuidStringLength = 38; |
53 // Formats 16 bytes (128 bits) of data as a GUID: | 56 // Formats 16 bytes (128 bits) of data as a GUID: |
(...skipping 28 matching lines...) Expand all Loading... |
82 TEST_AND_RETURN_FALSE_ERRNO(rc > 0); | 85 TEST_AND_RETURN_FALSE_ERRNO(rc > 0); |
83 bytes_read += rc; | 86 bytes_read += rc; |
84 } | 87 } |
85 string guid = GuidFromData(buf); | 88 string guid = GuidFromData(buf); |
86 TEST_AND_RETURN_FALSE( | 89 TEST_AND_RETURN_FALSE( |
87 utils::WriteFile(omaha_id_path.c_str(), guid.data(), guid.size())); | 90 utils::WriteFile(omaha_id_path.c_str(), guid.data(), guid.size())); |
88 *out_id = guid; | 91 *out_id = guid; |
89 return true; | 92 return true; |
90 } | 93 } |
91 | 94 |
92 std::string OmahaRequestPrepAction::GetLsbValue(const std::string& key) const { | 95 string OmahaRequestPrepAction::GetLsbValue( |
| 96 const string& key, const string& default_value) const { |
93 string files[] = {string(utils::kStatefulPartition) + "/etc/lsb-release", | 97 string files[] = {string(utils::kStatefulPartition) + "/etc/lsb-release", |
94 "/etc/lsb-release"}; | 98 "/etc/lsb-release"}; |
95 for (unsigned int i = 0; i < arraysize(files); i++) { | 99 for (unsigned int i = 0; i < arraysize(files); i++) { |
| 100 // TODO(adlr): make sure files checked are owned as root (and all |
| 101 // their parents are recursively, too). |
96 string file_data; | 102 string file_data; |
97 if (!utils::ReadFileToString(root_ + files[i], &file_data)) | 103 if (!utils::ReadFileToString(root_ + files[i], &file_data)) |
98 continue; | 104 continue; |
99 string::size_type pos = 0; | 105 string::size_type pos = 0; |
100 if (!utils::StringHasPrefix(file_data, key + "=")) { | 106 if (!utils::StringHasPrefix(file_data, key + "=")) { |
101 pos = file_data.find(string("\n") + key + "="); | 107 pos = file_data.find(string("\n") + key + "="); |
102 if (pos != string::npos) | 108 if (pos != string::npos) |
103 pos++; // advance past \n | 109 pos++; // advance past \n |
104 } | 110 } |
105 if (pos == string::npos) | 111 if (pos == string::npos) |
106 continue; | 112 continue; |
107 pos += key.size() + 1; // advance past the key and the '=' | 113 pos += key.size() + 1; // advance past the key and the '=' |
108 string::size_type endpos = file_data.find('\n', pos); | 114 string::size_type endpos = file_data.find('\n', pos); |
109 string::size_type length = | 115 string::size_type length = |
110 (endpos == string::npos ? string::npos : endpos - pos); | 116 (endpos == string::npos ? string::npos : endpos - pos); |
111 return file_data.substr(pos, length); | 117 return file_data.substr(pos, length); |
112 } | 118 } |
113 // not found | 119 // not found |
114 return ""; | 120 return default_value; |
115 } | 121 } |
116 | 122 |
117 std::string OmahaRequestPrepAction::GetMachineType() const { | 123 string OmahaRequestPrepAction::GetMachineType() const { |
118 struct utsname buf; | 124 struct utsname buf; |
119 string ret; | 125 string ret; |
120 if (uname(&buf) == 0) | 126 if (uname(&buf) == 0) |
121 ret = buf.machine; | 127 ret = buf.machine; |
122 return ret; | 128 return ret; |
123 } | 129 } |
124 | 130 |
125 } // namespace chromeos_update_engine | 131 } // namespace chromeos_update_engine |
OLD | NEW |