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

Add host_id filter for tls_certificates #835

Merged
Merged
Changes from 1 commit
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
32 changes: 31 additions & 1 deletion src/manage_sql_tls_certificates.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,41 @@ 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"
" WHERE origins.origin_id"
mattmundell marked this conversation as resolved.
Show resolved Hide resolved
" IN (SELECT ident_report_id FROM host_idents)"
" AND locations.host_ip"
" IN (SELECT ident_ip FROM host_idents)"
" ))",
quoted_id);
g_free (quoted_id);
}

if (report_id)
{
gchar *quoted_id;
Expand All @@ -214,6 +243,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