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

Amended if clauses for the Test if the ssh_elevate_credential differs from the ssh_credential #1586

1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Deprecated
### Removed
### Fixed
- Amended Test, if the ssh elevate credential is different from the ssh credential [#1586](https://github.com/greenbone/gvmd/pull/1586)

[Unreleased]: https://github.com/greenbone/gvmd/compare/v21.4.1...gvmd-21.04

Expand Down
43 changes: 25 additions & 18 deletions src/manage_sql.c
Original file line number Diff line number Diff line change
Expand Up @@ -30669,7 +30669,7 @@ create_target (const char* name, const char* asset_hosts_filter,
if (ssh_elevate_credential && (!ssh_credential))
return 14;

if (ssh_elevate_credential == ssh_credential)
if (ssh_credential && (ssh_elevate_credential == ssh_credential))
return 15;

sql_begin_immediate ();
Expand Down Expand Up @@ -31119,7 +31119,9 @@ delete_target (const char *target_id, int ultimate)
* 18 invalid SSH credential type, 19 invalid SMB credential type,
* 20 invalid ESXi credential type, 21 invalid SNMP credential type,
* 22 failed to find SSH elevate cred, 23 invalid SSH elevate
* credential type, 99 permission denied, -1 error.
* credential type, 24 SSH elevate credential without SSH credential,
* 25 SSH elevate credential equals SSH credential,
* 99 permission denied, -1 error.
*/
int
modify_target (const char *target_id, const char *name, const char *hosts,
Expand All @@ -31133,6 +31135,8 @@ modify_target (const char *target_id, const char *name, const char *hosts,
const char *allow_simultaneous_ips)
{
target_t target;
credential_t ssh_credential = 0;
credential_t ssh_elevate_credential = 0;

assert (target_id);

Expand All @@ -31152,18 +31156,6 @@ modify_target (const char *target_id, const char *name, const char *hosts,
return 13;
}

if (ssh_elevate_credential_id && (!ssh_credential_id))
{
sql_rollback ();
return 24;
}

if (ssh_elevate_credential_id == ssh_credential_id)
{
sql_rollback ();
return 25;
}

target = 0;
if (find_target_with_permission (target_id, &target, "modify_target"))
{
Expand Down Expand Up @@ -31284,8 +31276,6 @@ modify_target (const char *target_id, const char *name, const char *hosts,

if (ssh_credential_id)
{
credential_t ssh_credential;

if (target_in_use (target))
{
sql_rollback ();
Expand Down Expand Up @@ -31340,8 +31330,6 @@ modify_target (const char *target_id, const char *name, const char *hosts,

if (ssh_elevate_credential_id)
{
credential_t ssh_elevate_credential;

if (target_in_use (target))
{
sql_rollback ();
Expand Down Expand Up @@ -31506,6 +31494,25 @@ modify_target (const char *target_id, const char *name, const char *hosts,
set_target_login_data (target, "snmp", 0, 0);
}

if (ssh_credential_id || ssh_elevate_credential_id)
{
if (!ssh_credential_id)
ssh_credential = target_ssh_credential (target);
if (!ssh_elevate_credential_id)
ssh_elevate_credential = target_ssh_elevate_credential (target);

if (ssh_elevate_credential && !ssh_credential)
{
sql_rollback ();
return 24;
}
if (ssh_credential && (ssh_credential == ssh_elevate_credential))
{
sql_rollback ();
return 25;
}
}

if (exclude_hosts)
{
gchar *quoted_exclude_hosts, *quoted_hosts, *clean, *clean_exclude;
Expand Down