14
14
// limitations under the License.
15
15
//
16
16
17
+ #include " host_init_verifier.h"
18
+
17
19
#include < errno.h>
18
20
#include < getopt.h>
19
21
#include < pwd.h>
31
33
#include < android-base/parseint.h>
32
34
#include < android-base/strings.h>
33
35
#include < hidl/metadata.h>
36
+ #include < property_info_serializer/property_info_serializer.h>
34
37
35
38
#include " action.h"
36
39
#include " action_manager.h"
@@ -53,6 +56,10 @@ using namespace std::literals;
53
56
using android::base::ParseInt;
54
57
using android::base::ReadFileToString;
55
58
using android::base::Split;
59
+ using android::properties::BuildTrie;
60
+ using android::properties::ParsePropertyInfoFile;
61
+ using android::properties::PropertyInfoArea;
62
+ using android::properties::PropertyInfoEntry;
56
63
57
64
static std::vector<std::string> passwd_files;
58
65
@@ -143,11 +150,12 @@ static Result<void> check_stub(const BuiltinArguments& args) {
143
150
#include " generated_stub_builtin_function_map.h"
144
151
145
152
void PrintUsage () {
146
- std::cout << " usage: host_init_verifier [-p FILE ] <init rc file>\n "
153
+ std::cout << " usage: host_init_verifier [options ] <init rc file>\n "
147
154
" \n "
148
155
" Tests an init script for correctness\n "
149
156
" \n "
150
157
" -p FILE\t Search this passwd file for users and groups\n "
158
+ " --property_contexts=FILE\t Use this file for property_contexts\n "
151
159
<< std::endl;
152
160
}
153
161
@@ -172,23 +180,53 @@ Result<InterfaceInheritanceHierarchyMap> ReadInterfaceInheritanceHierarchy() {
172
180
return result;
173
181
}
174
182
183
+ const PropertyInfoArea* property_info_area;
184
+
185
+ void HandlePropertyContexts (const std::string& filename,
186
+ std::vector<PropertyInfoEntry>* property_infos) {
187
+ auto file_contents = std::string ();
188
+ if (!ReadFileToString (filename, &file_contents)) {
189
+ PLOG (ERROR) << " Could not read properties from '" << filename << " '" ;
190
+ exit (EXIT_FAILURE);
191
+ }
192
+
193
+ auto errors = std::vector<std::string>{};
194
+ ParsePropertyInfoFile (file_contents, property_infos, &errors);
195
+ for (const auto & error : errors) {
196
+ LOG (ERROR) << " Could not read line from '" << filename << " ': " << error;
197
+ }
198
+ if (!errors.empty ()) {
199
+ exit (EXIT_FAILURE);
200
+ }
201
+ }
202
+
175
203
int main (int argc, char ** argv) {
176
204
android::base::InitLogging (argv, &android::base::StdioLogger);
177
205
android::base::SetMinimumLogSeverity (android::base::ERROR);
178
206
207
+ auto property_infos = std::vector<PropertyInfoEntry>();
208
+
179
209
while (true ) {
210
+ static const char kPropertyContexts [] = " property-contexts=" ;
180
211
static const struct option long_options[] = {
181
212
{" help" , no_argument, nullptr , ' h' },
213
+ {kPropertyContexts , required_argument, nullptr , 0 },
182
214
{nullptr , 0 , nullptr , 0 },
183
215
};
184
216
185
- int arg = getopt_long (argc, argv, " p:" , long_options, nullptr );
217
+ int option_index;
218
+ int arg = getopt_long (argc, argv, " p:" , long_options, &option_index);
186
219
187
220
if (arg == -1 ) {
188
221
break ;
189
222
}
190
223
191
224
switch (arg) {
225
+ case 0 :
226
+ if (long_options[option_index].name == kPropertyContexts ) {
227
+ HandlePropertyContexts (optarg , &property_infos);
228
+ }
229
+ break ;
192
230
case ' h' :
193
231
PrintUsage ();
194
232
return EXIT_FAILURE;
@@ -216,6 +254,16 @@ int main(int argc, char** argv) {
216
254
}
217
255
SetKnownInterfaces (*interface_inheritance_hierarchy_map);
218
256
257
+ std::string serialized_contexts;
258
+ std::string trie_error;
259
+ if (!BuildTrie (property_infos, " u:object_r:default_prop:s0" , " string" , &serialized_contexts,
260
+ &trie_error)) {
261
+ LOG (ERROR) << " Unable to serialize property contexts: " << trie_error;
262
+ return EXIT_FAILURE;
263
+ }
264
+
265
+ property_info_area = reinterpret_cast <const PropertyInfoArea*>(serialized_contexts.c_str ());
266
+
219
267
const BuiltinFunctionMap& function_map = GetBuiltinFunctionMap ();
220
268
Action::set_function_map (&function_map);
221
269
ActionManager& am = ActionManager::GetInstance ();
0 commit comments