Skip to content

Commit

Permalink
Merge pull request #835 from timopollmeier/tls-certificates-host-filt…
Browse files Browse the repository at this point in the history
…er-9.0

Add host_id filter for tls_certificates
  • Loading branch information
mattmundell authored Oct 30, 2019
2 parents b3d5397 + abb8828 commit 6fe0511
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

### Added
- Add option --optimize migrate-relay-sensors [#827](https://github.com/greenbone/gvmd/pull/827)
- Add host_id filter for tls_certificates [#835](https://github.com/greenbone/gvmd/pull/835)

### Changed
- Extend command line options for managing scanners [#815](https://github.com/greenbone/gvmd/pull/815)
Expand Down
31 changes: 30 additions & 1 deletion src/manage_sql_tls_certificates.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,40 @@ gchar *
tls_certificate_extra_where (const char *filter)
{
GString *ret;
gchar *report_id;
gchar *host_id, *report_id;

ret = g_string_new ("");

host_id = filter_term_value (filter, "host_id");
report_id = filter_term_value (filter, "report_id");

if (host_id)
{
gchar *quoted_id;
quoted_id = sql_quote (host_id);
g_string_append_printf
(ret,
" AND (tls_certificates.id IN"
" (WITH host_idents AS"
" (SELECT source_id AS ident_report_id, value AS ident_ip"
" FROM host_identifiers"
" WHERE host = (SELECT id FROM hosts"
" WHERE uuid='%s')"
" AND name = 'ip')"
" SELECT tls_certificate"
" FROM tls_certificate_sources AS sources"
" JOIN tls_certificate_origins AS origins"
" ON origins.id = sources.origin"
" JOIN tls_certificate_locations AS locations"
" ON locations.id = sources.location"
" JOIN host_idents"
" ON origins.origin_id = host_idents.ident_report_id"
" AND locations.host_ip = host_idents.ident_ip)"
" )",
quoted_id);
g_free (quoted_id);
}

if (report_id)
{
gchar *quoted_id;
Expand All @@ -214,6 +242,7 @@ tls_certificate_extra_where (const char *filter)
g_free (quoted_id);
}

g_free (host_id);
g_free (report_id);

return g_string_free (ret, FALSE);
Expand Down
5 changes: 5 additions & 0 deletions src/schema_formats/XML/GMP.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -22975,6 +22975,11 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
<type>iso_time</type>
<summary>Most recent time the TLS certificate was imported or found in a scan</summary>
</column>
<option>
<name>host_id</name>
<type>uuid</type>
<summary>UUID of the host asset where the certificate must be found</summary>
</option>
<option>
<name>report_id</name>
<type>uuid</type>
Expand Down

0 comments on commit 6fe0511

Please sign in to comment.