void TailoringWindow::setProfileDescription(const QString& description) { struct oscap_text_iterator* descriptions = xccdf_profile_get_description(mProfile); struct oscap_text* descText = 0; while (oscap_text_iterator_has_more(descriptions)) { struct oscap_text* descCandidate = oscap_text_iterator_next(descriptions); if (!descText || strcmp(oscap_text_get_lang(descCandidate), OSCAP_LANG_DEFAULT) == 0) descText = descCandidate; } oscap_text_iterator_free(descriptions); if (descText) { oscap_text_set_text(descText, description.toUtf8().constData()); oscap_text_set_lang(descText, OSCAP_LANG_DEFAULT); } else { // FIXME: we cannot add new title using this API :-( throw TailoringWindowException("Not suitable oscap_text found that we could edit to change profile description."); } assert(getProfileDescription() == description); }
void TailoringWindow::setProfileTitle(const QString& title) { struct oscap_text_iterator* titles = xccdf_profile_get_title(mProfile); struct oscap_text* titleText = 0; while (oscap_text_iterator_has_more(titles)) { struct oscap_text* titleCandidate = oscap_text_iterator_next(titles); if (!titleText || strcmp(oscap_text_get_lang(titleCandidate), OSCAP_LANG_DEFAULT) == 0) titleText = titleCandidate; } oscap_text_iterator_free(titles); if (titleText) { oscap_text_set_text(titleText, title.toUtf8().constData()); oscap_text_set_lang(titleText, OSCAP_LANG_DEFAULT); } else { // FIXME: we cannot add new title using this API :-( throw TailoringWindowException("Not suitable oscap_text found that we could edit to change profile title."); } assert(getProfileTitle() == title); }
QString oscapTextIteratorGetPreferred(struct oscap_text_iterator* it, const QString& lang) { char* preferred_s = oscap_textlist_get_preferred_plaintext(it, lang.isEmpty() ? NULL : lang.toUtf8().constData()); oscap_text_iterator_free(it); const QString ret(preferred_s != NULL ? QString::fromUtf8(preferred_s) : QObject::tr("(none)")); free(preferred_s); return ret; }
QString oscapItemGetReadableDescription(struct xccdf_item *item, struct xccdf_policy *policy, const QString& lang) { struct oscap_text_iterator* desc_it = xccdf_item_get_description(item); oscap_text* unresolved = oscap_textlist_get_preferred_text(desc_it, lang.isEmpty() ? NULL : lang.toUtf8().constData()); oscap_text_iterator_free(desc_it); if (!unresolved) return ""; char* resolved = xccdf_policy_substitute(oscap_text_get_text(unresolved), policy); const QString ret = QString::fromUtf8(resolved); free(resolved); return ret; }
QString oscapItemGetReadableTitle(struct xccdf_item* item, struct xccdf_policy* policy, const QString& lang) { struct oscap_text_iterator* title_it = xccdf_item_get_title(item); char* unresolved = oscap_textlist_get_preferred_plaintext(title_it, lang.isEmpty() ? NULL : lang.toUtf8().constData()); oscap_text_iterator_free(title_it); if (!unresolved) return ""; char* resolved = xccdf_policy_substitute(Qt::escape(QString::fromUtf8(unresolved)).toUtf8().constData(), policy); free(unresolved); const QString ret = QString::fromUtf8(resolved); free(resolved); return ret; }
OSCAP_FOR(oscap_text, child, oscap_iterator_new(child_list)) { if (oscap_text_get_overrides(child)) continue; OSCAP_FOR(oscap_text, parent, oscap_iterator_new(parent_list)) { if (oscap_streq(oscap_text_get_lang(child), oscap_text_get_lang(parent))) { char *text = oscap_sprintf("%s%s", oscap_text_get_text(parent), oscap_text_get_text(child)); oscap_text_set_text(child, text); free(text); if (more) more(child, parent); break; } } oscap_text_iterator_free(parent_iter); }
void xccdf_print_textlist(struct oscap_text_iterator *txt, int depth, int max, const char *ellipsis) { if (txt == NULL) return; printf("\n"); while (oscap_text_iterator_has_more(txt)) { struct oscap_text *text = oscap_text_iterator_next(txt); xccdf_print_depth(depth); xccdf_print_max_text(text, max, ellipsis); printf("\n"); } oscap_text_iterator_free(txt); }
static int print_versions(const struct oscap_action *action) { printf("OpenSCAP command line tool (oscap) %s\n" "Copyright 2009--2016 Red Hat Inc., Durham, North Carolina.\n\n", oscap_get_version()); printf("==== Supported specifications ====\n"); printf("XCCDF Version: %s\n", xccdf_benchmark_supported()); printf("OVAL Version: %s\n", oval_definition_model_supported()); printf("CPE Version: %s\n", cpe_dict_model_supported()); printf("CVSS Version: %s\n", cvss_model_supported()); printf("CVE Version: %s\n", cve_model_supported()); printf("Asset Identification Version: %s\n", "1.1"); printf("Asset Reporting Format Version: %s\n", "1.1"); printf("\n"); printf("==== Capabilities added by auto-loaded plugins ====\n"); const char * const *known_plugins = check_engine_plugin_get_known_plugins(); bool known_plugin_found = false; while (*known_plugins) { struct check_engine_plugin_def *plugin = check_engine_plugin_load(*known_plugins); if (plugin) { printf("%s (from %s)\n", check_engine_plugin_get_capabilities(plugin), *known_plugins); check_engine_plugin_unload(plugin); known_plugin_found = true; } known_plugins++; } if (!known_plugin_found) printf("No plugins have been auto-loaded...\n"); // We do not report failure when a known plugin doesn't load properly, that's because they // are optional and we don't know if it's not there or if it just failed to load. oscap_clearerr(); printf("\n"); printf("==== Paths ====\n"); printf("Schema files: %s\n", oscap_path_to_schemas()); printf("Default CPE files: %s\n", oscap_path_to_cpe()); #if defined(OVAL_PROBES_ENABLED) printf("Probes: %s\n", oval_probe_ext_getdir()); #endif printf("\n"); printf("==== Inbuilt CPE names ====\n"); char default_cpe_path[PATH_MAX]; snprintf(default_cpe_path, PATH_MAX, "%s/openscap-cpe-dict.xml", oscap_path_to_cpe()); struct oscap_source *source = oscap_source_new_from_file(default_cpe_path); struct cpe_dict_model* cpe_dict = cpe_dict_model_import_source(source); oscap_source_free(source); if (cpe_dict != NULL) { struct cpe_item_iterator* cpe_items = cpe_dict_model_get_items(cpe_dict); while (cpe_item_iterator_has_more(cpe_items)) { struct cpe_item* cpe_item = cpe_item_iterator_next(cpe_items); struct oscap_text_iterator* titles = cpe_item_get_titles(cpe_item); char* str_title = oscap_textlist_get_preferred_plaintext(titles, NULL); oscap_text_iterator_free(titles); struct cpe_name* name = cpe_item_get_name(cpe_item); char * str_name = cpe_name_get_as_format(name, CPE_FORMAT_URI); printf("%s - %s\n", str_title, str_name); free(str_name); free(str_title); } cpe_item_iterator_free(cpe_items); cpe_dict_model_free(cpe_dict); } printf("\n"); #if defined(OVAL_PROBES_ENABLED) printf("==== Supported OVAL objects and associated OpenSCAP probes ====\n"); printf("%-14s%-28s %-28s\n", "OVAL family", "OVAL object", "OpenSCAP probe"); printf("%-14s%-28s %-28s\n", "----------", "----------", "----------"); oval_probe_meta_list(stdout, OVAL_PROBEMETA_LIST_DYNAMIC | OVAL_PROBEMETA_LIST_OTYPE); #endif return OSCAP_OK; }