From 592b8906fb8eb45ba2a5dfe924a28d4ec128af74 Mon Sep 17 00:00:00 2001 From: Matt Mundell Date: Tue, 6 Jun 2023 15:47:19 +0200 Subject: [PATCH 1/2] Move target_credential SQL into TARGET_ITERATOR_COLUMNS --- src/manage_sql.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/manage_sql.c b/src/manage_sql.c index eb09ea305..83c76c3bc 100644 --- a/src/manage_sql.c +++ b/src/manage_sql.c @@ -32101,40 +32101,45 @@ modify_target (const char *target_id, const char *name, const char *hosts, { \ "(SELECT name FROM credentials" \ " WHERE credentials.id" \ - " = target_credential (targets.id, 0," \ - " CAST ('ssh' AS text)))", \ + " = (SELECT credential FROM targets_login_data" \ + " WHERE target = targets.id" \ + " AND type = CAST ('ssh' AS text)))", \ "ssh_credential", \ KEYWORD_TYPE_STRING \ }, \ { \ "(SELECT name FROM credentials" \ " WHERE credentials.id" \ - " = target_credential (targets.id, 0," \ - " CAST ('smb' AS text)))", \ + " = (SELECT credential FROM targets_login_data" \ + " WHERE target = targets.id" \ + " AND type = CAST ('smb' AS text)))", \ "smb_credential", \ KEYWORD_TYPE_STRING \ }, \ { \ "(SELECT name FROM credentials" \ " WHERE credentials.id" \ - " = target_credential (targets.id, 0," \ - " CAST ('esxi' AS text)))", \ + " = (SELECT credential FROM targets_login_data" \ + " WHERE target = targets.id" \ + " AND type = CAST ('esxi' AS text)))", \ "esxi_credential", \ KEYWORD_TYPE_STRING \ }, \ { \ "(SELECT name FROM credentials" \ " WHERE credentials.id" \ - " = target_credential (targets.id, 0," \ - " CAST ('snmp' AS text)))", \ + " = (SELECT credential FROM targets_login_data" \ + " WHERE target = targets.id" \ + " AND type = CAST ('snmp' AS text)))", \ "snmp_credential", \ KEYWORD_TYPE_STRING \ }, \ { \ "(SELECT name FROM credentials" \ " WHERE credentials.id" \ - " = target_credential (targets.id, 0," \ - " CAST ('elevate' AS text)))", \ + " = (SELECT credential FROM targets_login_data" \ + " WHERE target = targets.id" \ + " AND type = CAST ('elevate' AS text)))", \ "ssh_elevate_credential", \ KEYWORD_TYPE_STRING \ }, \ From aebcaf8d76bc93f28fd99d763575f0b2ed6c433a Mon Sep 17 00:00:00 2001 From: Matt Mundell Date: Mon, 12 Jun 2023 14:28:01 +0200 Subject: [PATCH 2/2] Inline remaining target_credential cases in TARGET_ITERATOR_COLUMNS --- src/manage_sql.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/manage_sql.c b/src/manage_sql.c index 83c76c3bc..94696ee93 100644 --- a/src/manage_sql.c +++ b/src/manage_sql.c @@ -32054,13 +32054,17 @@ modify_target (const char *target_id, const char *name, const char *hosts, { \ GET_ITERATOR_COLUMNS (targets), \ { "hosts", NULL, KEYWORD_TYPE_STRING }, \ - { "target_credential (id, 0, CAST ('ssh' AS text))", \ + { "(SELECT credential FROM targets_login_data" \ + " WHERE target = targets.id" \ + " AND type = CAST ('ssh' AS text))", \ NULL, \ KEYWORD_TYPE_INTEGER }, \ { "target_login_port (id, 0, CAST ('ssh' AS text))", \ "ssh_port", \ KEYWORD_TYPE_INTEGER }, \ - { "target_credential (id, 0, CAST ('smb' AS text))", \ + { "(SELECT credential FROM targets_login_data" \ + " WHERE target = targets.id" \ + " AND type = CAST ('smb' AS text))", \ NULL, \ KEYWORD_TYPE_INTEGER }, \ { "port_list", NULL, KEYWORD_TYPE_INTEGER }, \ @@ -32083,15 +32087,21 @@ modify_target (const char *target_id, const char *name, const char *hosts, { "reverse_lookup_only", NULL, KEYWORD_TYPE_INTEGER }, \ { "reverse_lookup_unify", NULL, KEYWORD_TYPE_INTEGER }, \ { "alive_test", NULL, KEYWORD_TYPE_INTEGER }, \ - { "target_credential (id, 0, CAST ('esxi' AS text))", \ + { "(SELECT credential FROM targets_login_data" \ + " WHERE target = targets.id" \ + " AND type = CAST ('esxi' AS text))", \ NULL, \ KEYWORD_TYPE_INTEGER }, \ { "0", NULL, KEYWORD_TYPE_INTEGER }, \ - { "target_credential (id, 0, CAST ('snmp' AS text))", \ + { "(SELECT credential FROM targets_login_data" \ + " WHERE target = targets.id" \ + " AND type = CAST ('snmp' AS text))", \ NULL, \ KEYWORD_TYPE_INTEGER }, \ { "0", NULL, KEYWORD_TYPE_INTEGER }, \ - { "target_credential (id, 0, CAST ('elevate' AS text))", \ + { "(SELECT credential FROM targets_login_data" \ + " WHERE target = targets.id" \ + " AND type = CAST ('elevate' AS text))", \ NULL, \ KEYWORD_TYPE_INTEGER }, \ { "0", NULL, KEYWORD_TYPE_INTEGER }, \