static int app_cvrf_export(const struct oscap_action *action) { struct oscap_source *import_source = oscap_source_new_from_file(action->cvrf_action->f_cvrf); if (import_source == NULL) return OSCAP_ERROR; int result = OSCAP_OK; if (action->cvrf_action->index == 1) { struct cvrf_index *index = cvrf_index_import(import_source); if (index == NULL) { result = OSCAP_ERROR; goto cleanup; } struct oscap_source *export_source = cvrf_index_get_export_source(index); if (oscap_source_save_as(export_source, action->cvrf_action->f_output) != 0) result = OSCAP_ERROR; oscap_source_free(export_source); cvrf_index_free(index); } else { struct cvrf_model *model = cvrf_model_import(import_source); if(model == NULL) { result = OSCAP_ERROR; goto cleanup; } struct oscap_source *export_source = cvrf_model_get_export_source(model); if (oscap_source_save_as(export_source, action->cvrf_action->f_output) != 0) result = OSCAP_ERROR; oscap_source_free(export_source); cvrf_model_free(model); } cleanup: if (oscap_err()) fprintf(stderr, "%s %s\n", OSCAP_ERR_MSG, oscap_err_desc()); /* TODO: Refactor, cvrf_index_parse_xml (called by oscap_source_new_from_file) frees its argument as an unexpected side-effect. * oscap_source_free(import_source); */ free(action->cvrf_action); return result; }
int main(int argc, char **argv) { /* test export */ if (argc == 4 && !strcmp(argv[1], "--export-all")) { struct cvrf_model *model = cvrf_model_import(oscap_source_new_from_file(argv[2])); if(!model) return 1; struct oscap_source *export_source = cvrf_model_get_export_source(model); int ret = oscap_source_save_as(export_source, argv[3]); cvrf_model_free(model); oscap_source_free(export_source); return ret; } else if (argc == 4 && !strcmp(argv[1], "--eval")) { const char *cpe = "Managment Agent for RHEL 7 Hosts"; struct oscap_source *import_source = oscap_source_new_from_file(argv[2]); struct oscap_source *export_source = cvrf_model_get_results_source(import_source, cpe); int ret = oscap_source_save_as(export_source, argv[3]); oscap_source_free(export_source); return ret; } else if (argc == 3 && !strcmp(argv[1], "--validate")) { struct oscap_source *source = oscap_source_new_from_file(argv[2]); int ret = oscap_source_validate(source, reporter, NULL); oscap_source_free(source); return ret; } fprintf(stdout, "Usage: \n\n" " %s --help\n" " %s --export-all input.xml output.xml\n" " %s --eval input.xml results.xml\n" " %s --validate input.xml\n", argv[0], argv[0], argv[0], argv[0]); return 0; }