Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change: Adjust loading of CPEs to new JSON API #2299

Merged
merged 4 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ include (CPack)

set (GVMD_DATABASE_VERSION 256)

set (GVMD_SCAP_DATABASE_VERSION 21)
set (GVMD_SCAP_DATABASE_VERSION 22)

set (GVMD_CERT_DATABASE_VERSION 8)

Expand Down
38 changes: 30 additions & 8 deletions src/gmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -13473,24 +13473,36 @@
"<title>%s</title>",
cpe_info_iterator_title (&info));
xml_string_append (result,
"<nvd_id>%s</nvd_id>"
"<cpe_name_id>%s</cpe_name_id>"
"<severity>%s</severity>"
"<cve_refs>%s</cve_refs>"
"<status>%s</status>",
cpe_info_iterator_nvd_id (&info)
? cpe_info_iterator_nvd_id (&info)
"<deprecated>%s</deprecated>",
cpe_info_iterator_cpe_name_id (&info)
? cpe_info_iterator_cpe_name_id (&info)

Check warning on line 13481 in src/gmp.c

View check run for this annotation

Codecov / codecov/patch

src/gmp.c#L13480-L13481

Added lines #L13480 - L13481 were not covered by tests
: "",
cpe_info_iterator_severity (&info)
? cpe_info_iterator_severity (&info)
: "",
cpe_info_iterator_cve_refs (&info),
cpe_info_iterator_status (&info)
? cpe_info_iterator_status (&info)
: "");
cpe_info_iterator_deprecated (&info)
? cpe_info_iterator_deprecated (&info)

Check warning on line 13488 in src/gmp.c

View check run for this annotation

Codecov / codecov/patch

src/gmp.c#L13487-L13488

Added lines #L13487 - L13488 were not covered by tests
: "0");

if (get_info_data->details == 1)
{
iterator_t cves;
iterator_t deprecated_by, cves, refs;

init_cpe_deprecated_by_iterator (&deprecated_by,

Check warning on line 13495 in src/gmp.c

View check run for this annotation

Codecov / codecov/patch

src/gmp.c#L13495

Added line #L13495 was not covered by tests
get_iterator_name (&info));
while (next (&deprecated_by))
{
xml_string_append (result,

Check warning on line 13499 in src/gmp.c

View check run for this annotation

Codecov / codecov/patch

src/gmp.c#L13499

Added line #L13499 was not covered by tests
"<deprecated_by cpe_id=\"%s\"/>",
cpe_deprecated_by_iterator_deprecated_by
(&deprecated_by));
}
cleanup_iterator (&deprecated_by);

Check warning on line 13504 in src/gmp.c

View check run for this annotation

Codecov / codecov/patch

src/gmp.c#L13504

Added line #L13504 was not covered by tests

g_string_append (result, "<cves>");
init_cpe_cve_iterator (&cves, get_iterator_name (&info), 0, NULL);
while (next (&cves))
Expand Down Expand Up @@ -13518,6 +13530,16 @@
: "");
cleanup_iterator (&cves);
g_string_append (result, "</cves>");

g_string_append (result, "<references>");
init_cpe_reference_iterator (&refs, get_iterator_name (&info));

Check warning on line 13535 in src/gmp.c

View check run for this annotation

Codecov / codecov/patch

src/gmp.c#L13534-L13535

Added lines #L13534 - L13535 were not covered by tests
while (next (&refs))
xml_string_append (result,

Check warning on line 13537 in src/gmp.c

View check run for this annotation

Codecov / codecov/patch

src/gmp.c#L13537

Added line #L13537 was not covered by tests
"<reference href=\"%s\">%s</reference>",
cpe_reference_iterator_href (&refs),
cpe_reference_iterator_type (&refs));
cleanup_iterator (&refs);
g_string_append (result, "</references>");

Check warning on line 13542 in src/gmp.c

View check run for this annotation

Codecov / codecov/patch

src/gmp.c#L13541-L13542

Added lines #L13541 - L13542 were not covered by tests
}
}
else if (g_strcmp0 ("cve", get_info_data->type) == 0)
Expand Down
23 changes: 18 additions & 5 deletions src/manage.h
Original file line number Diff line number Diff line change
Expand Up @@ -3339,6 +3339,12 @@ manage_scap_update_time ();

/* CPE. */

void
init_cpe_deprecated_by_iterator (iterator_t *, const char *);

const char *
cpe_deprecated_by_iterator_deprecated_by (iterator_t *);

void
init_cpe_cve_iterator (iterator_t *, const char *, int, const char *);

Expand All @@ -3355,23 +3361,30 @@ const char*
cpe_info_iterator_title (iterator_t*);

const char*
cpe_info_iterator_status (iterator_t*);
cpe_info_iterator_deprecated (iterator_t*);

const char *
cpe_info_iterator_severity (iterator_t*);

const char*
cpe_info_iterator_deprecated_by_id (iterator_t*);

const char*
cpe_info_iterator_cve_refs (iterator_t*);

const char*
cpe_info_iterator_nvd_id (iterator_t*);
cpe_info_iterator_cpe_name_id (iterator_t*);

gchar *
cpe_details_xml (const char*);

void
init_cpe_reference_iterator (iterator_t *, const char *);

const char*
cpe_reference_iterator_href (iterator_t *);

const char*
cpe_reference_iterator_type (iterator_t *);


/* CVE. */

const char*
Expand Down
16 changes: 14 additions & 2 deletions src/manage_pg.c
Original file line number Diff line number Diff line change
Expand Up @@ -3525,10 +3525,22 @@
" modification_time integer,"
" title text,"
" status text,"
" deprecated_by_id INTEGER,"
" severity DOUBLE PRECISION DEFAULT 0,"
" cve_refs INTEGER DEFAULT 0,"
" nvd_id text);");
" nvd_id text,"
" deprecated integer,"
" cpe_name_id text);");

sql ("CREATE TABLE scap2.cpe_refs"

Check warning on line 3534 in src/manage_pg.c

View check run for this annotation

Codecov / codecov/patch

src/manage_pg.c#L3534

Added line #L3534 was not covered by tests
" (id SERIAL PRIMARY KEY,"
" cpe INTEGER,"
" ref TEXT,"
" type TEXT);");

sql ("CREATE TABLE scap2.cpes_deprecated_by"

Check warning on line 3540 in src/manage_pg.c

View check run for this annotation

Codecov / codecov/patch

src/manage_pg.c#L3540

Added line #L3540 was not covered by tests
" (id SERIAL PRIMARY KEY,"
" cpe TEXT,"
" deprecated_by TEXT);");

sql ("CREATE TABLE scap2.cpe_match_nodes"
" (id SERIAL PRIMARY KEY,"
Expand Down
Loading
Loading