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

Fix: Avoid DB check inserts in cleanup-sequences (backport #2328) #2330

Closed
wants to merge 3 commits into from
Closed
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
67 changes: 67 additions & 0 deletions src/gmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,7 @@
char *certificate; ///< Certificate for client certificate auth.
char *comment; ///< Comment.
char *copy; ///< UUID of resource to copy.
char *kdc; ///< Kerberos KDC (key distribution centers).
int key; ///< Whether the command included a key element.
char *key_phrase; ///< Passphrase for key.
char *key_private; ///< Private key from key.
Expand All @@ -458,6 +459,7 @@
char *auth_algorithm; ///< SNMP Authentication algorithm.
char *privacy_password; ///< SNMP Privacy password.
char *privacy_algorithm; ///< SNMP Privacy algorithm.
char *realm; ///< Kerberos realm.
char *type; ///< Type of credential.
} create_credential_data_t;

Expand All @@ -473,6 +475,7 @@
free (data->certificate);
free (data->comment);
free (data->copy);
free (data->kdc);

Check warning on line 478 in src/gmp.c

View check run for this annotation

Codecov / codecov/patch

src/gmp.c#L478

Added line #L478 was not covered by tests
free (data->key_phrase);
free (data->key_private);
free (data->key_public);
Expand All @@ -483,6 +486,7 @@
free (data->auth_algorithm);
free (data->privacy_password);
free (data->privacy_algorithm);
free (data->realm);

Check warning on line 489 in src/gmp.c

View check run for this annotation

Codecov / codecov/patch

src/gmp.c#L489

Added line #L489 was not covered by tests
free (data->type);

memset (data, 0, sizeof (create_credential_data_t));
Expand Down Expand Up @@ -2513,6 +2517,7 @@
char *comment; ///< Comment.
char *community; ///< SNMP Community string.
char *credential_id; ///< ID of credential to modify.
char *kdc; ///< Kerberos KDC (key distribution centers).
int key; ///< Whether the command included a key element.
char *key_phrase; ///< Passphrase for key.
char *key_private; ///< Private key from key.
Expand All @@ -2522,6 +2527,7 @@
char *password; ///< Password associated with login name.
char *privacy_algorithm; ///< SNMP Privacy algorithm.
char *privacy_password; ///< SNMP Privacy password.
char *realm; ///< Kerberos realm.
} modify_credential_data_t;

/**
Expand All @@ -2538,6 +2544,7 @@
free (data->comment);
free (data->community);
free (data->credential_id);
free (data->kdc);

Check warning on line 2547 in src/gmp.c

View check run for this annotation

Codecov / codecov/patch

src/gmp.c#L2547

Added line #L2547 was not covered by tests
free (data->key_phrase);
free (data->key_private);
free (data->key_public);
Expand All @@ -2546,6 +2553,7 @@
free (data->password);
free (data->privacy_algorithm);
free (data->privacy_password);
free (data->realm);

Check warning on line 2556 in src/gmp.c

View check run for this annotation

Codecov / codecov/patch

src/gmp.c#L2556

Added line #L2556 was not covered by tests

memset (data, 0, sizeof (modify_credential_data_t));
}
Expand Down Expand Up @@ -4086,6 +4094,7 @@
CLIENT_CREATE_CREDENTIAL_COMMENT,
CLIENT_CREATE_CREDENTIAL_COMMUNITY,
CLIENT_CREATE_CREDENTIAL_COPY,
CLIENT_CREATE_CREDENTIAL_KDC,
CLIENT_CREATE_CREDENTIAL_KEY,
CLIENT_CREATE_CREDENTIAL_KEY_PHRASE,
CLIENT_CREATE_CREDENTIAL_KEY_PRIVATE,
Expand All @@ -4096,6 +4105,7 @@
CLIENT_CREATE_CREDENTIAL_PRIVACY,
CLIENT_CREATE_CREDENTIAL_PRIVACY_ALGORITHM,
CLIENT_CREATE_CREDENTIAL_PRIVACY_PASSWORD,
CLIENT_CREATE_CREDENTIAL_REALM,
CLIENT_CREATE_CREDENTIAL_TYPE,
CLIENT_CREATE_FILTER,
CLIENT_CREATE_FILTER_COMMENT,
Expand Down Expand Up @@ -4418,6 +4428,7 @@
CLIENT_MODIFY_CREDENTIAL_CERTIFICATE,
CLIENT_MODIFY_CREDENTIAL_COMMENT,
CLIENT_MODIFY_CREDENTIAL_COMMUNITY,
CLIENT_MODIFY_CREDENTIAL_KDC,
CLIENT_MODIFY_CREDENTIAL_KEY,
CLIENT_MODIFY_CREDENTIAL_KEY_PHRASE,
CLIENT_MODIFY_CREDENTIAL_KEY_PRIVATE,
Expand All @@ -4428,6 +4439,7 @@
CLIENT_MODIFY_CREDENTIAL_PRIVACY,
CLIENT_MODIFY_CREDENTIAL_PRIVACY_ALGORITHM,
CLIENT_MODIFY_CREDENTIAL_PRIVACY_PASSWORD,
CLIENT_MODIFY_CREDENTIAL_REALM,
CLIENT_MODIFY_FILTER,
CLIENT_MODIFY_FILTER_COMMENT,
CLIENT_MODIFY_FILTER_NAME,
Expand Down Expand Up @@ -6281,6 +6293,10 @@
gvm_append_string (&modify_credential_data->community, "");
set_client_state (CLIENT_MODIFY_CREDENTIAL_COMMUNITY);
}
else if (strcasecmp ("KDC", element_name) == 0)

Check warning on line 6296 in src/gmp.c

View check run for this annotation

Codecov / codecov/patch

src/gmp.c#L6296

Added line #L6296 was not covered by tests
{
set_client_state (CLIENT_MODIFY_CREDENTIAL_KDC);

Check warning on line 6298 in src/gmp.c

View check run for this annotation

Codecov / codecov/patch

src/gmp.c#L6298

Added line #L6298 was not covered by tests
}
else if (strcasecmp ("KEY", element_name) == 0)
{
modify_credential_data->key = 1;
Expand All @@ -6300,6 +6316,10 @@
gvm_append_string (&modify_credential_data->privacy_algorithm,
"");
}
else if (strcasecmp ("REALM", element_name) == 0)

Check warning on line 6319 in src/gmp.c

View check run for this annotation

Codecov / codecov/patch

src/gmp.c#L6319

Added line #L6319 was not covered by tests
{
set_client_state (CLIENT_MODIFY_CREDENTIAL_REALM);

Check warning on line 6321 in src/gmp.c

View check run for this annotation

Codecov / codecov/patch

src/gmp.c#L6321

Added line #L6321 was not covered by tests
}
ELSE_READ_OVER;

case CLIENT_MODIFY_CREDENTIAL_KEY:
Expand Down Expand Up @@ -6960,6 +6980,8 @@
set_client_state (CLIENT_CREATE_CREDENTIAL_COMMENT);
else if (strcasecmp ("COMMUNITY", element_name) == 0)
set_client_state (CLIENT_CREATE_CREDENTIAL_COMMUNITY);
else if (strcasecmp ("KDC", element_name) == 0)
set_client_state (CLIENT_CREATE_CREDENTIAL_KDC);

Check warning on line 6984 in src/gmp.c

View check run for this annotation

Codecov / codecov/patch

src/gmp.c#L6983-L6984

Added lines #L6983 - L6984 were not covered by tests
else if (strcasecmp ("KEY", element_name) == 0)
{
create_credential_data->key = 1;
Expand All @@ -6978,6 +7000,8 @@
}
else if (strcasecmp ("PRIVACY", element_name) == 0)
set_client_state (CLIENT_CREATE_CREDENTIAL_PRIVACY);
else if (strcasecmp ("REALM", element_name) == 0)
set_client_state (CLIENT_CREATE_CREDENTIAL_REALM);

Check warning on line 7004 in src/gmp.c

View check run for this annotation

Codecov / codecov/patch

src/gmp.c#L7003-L7004

Added lines #L7003 - L7004 were not covered by tests
else if (strcasecmp ("TYPE", element_name) == 0)
set_client_state (CLIENT_CREATE_CREDENTIAL_TYPE);
ELSE_READ_OVER;
Expand Down Expand Up @@ -12336,6 +12360,19 @@
SEND_TO_CLIENT_OR_FAIL (formats_xml);
g_free (formats_xml);

if (type && (strcmp (type, "krb5") == 0))
{
const char *kdc, *realm;
kdc = credential_iterator_kdc (&credentials);
realm = credential_iterator_realm (&credentials);

Check warning on line 12367 in src/gmp.c

View check run for this annotation

Codecov / codecov/patch

src/gmp.c#L12366-L12367

Added lines #L12366 - L12367 were not covered by tests

SENDF_TO_CLIENT_OR_FAIL

Check warning on line 12369 in src/gmp.c

View check run for this annotation

Codecov / codecov/patch

src/gmp.c#L12369

Added line #L12369 was not covered by tests
("<kdc>%s</kdc>"
"<realm>%s</realm>",
kdc ? kdc : "",
realm ? realm : "");
}

if (type && (strcmp (type, "snmp") == 0))
{
const char *auth_algorithm, *privacy_algorithm;
Expand Down Expand Up @@ -21073,6 +21110,8 @@
create_credential_data->auth_algorithm,
create_credential_data->privacy_password,
create_credential_data->privacy_algorithm,
create_credential_data->kdc,
create_credential_data->realm,

Check warning on line 21114 in src/gmp.c

View check run for this annotation

Codecov / codecov/patch

src/gmp.c#L21113-L21114

Added lines #L21113 - L21114 were not covered by tests
create_credential_data->type,
create_credential_data->allow_insecure,
&new_credential))
Expand Down Expand Up @@ -21180,6 +21219,16 @@
(XML_ERROR_SYNTAX ("create_credential",
"Cannot determine type for new credential"));
break;
case 19:
SEND_TO_CLIENT_OR_FAIL

Check warning on line 21223 in src/gmp.c

View check run for this annotation

Codecov / codecov/patch

src/gmp.c#L21222-L21223

Added lines #L21222 - L21223 were not covered by tests
(XML_ERROR_SYNTAX ("create_credential",
"Selected type requires a kdc"));
break;
case 20:
SEND_TO_CLIENT_OR_FAIL

Check warning on line 21228 in src/gmp.c

View check run for this annotation

Codecov / codecov/patch

src/gmp.c#L21226-L21228

Added lines #L21226 - L21228 were not covered by tests
(XML_ERROR_SYNTAX ("create_credential",
"Selected type requires a realm"));
break;

Check warning on line 21231 in src/gmp.c

View check run for this annotation

Codecov / codecov/patch

src/gmp.c#L21231

Added line #L21231 was not covered by tests
case 99:
SEND_TO_CLIENT_OR_FAIL
(XML_ERROR_SYNTAX ("create_credential",
Expand All @@ -21202,6 +21251,7 @@
CLOSE (CLIENT_CREATE_CREDENTIAL, COMMENT);
CLOSE (CLIENT_CREATE_CREDENTIAL, COMMUNITY);
CLOSE (CLIENT_CREATE_CREDENTIAL, COPY);
CLOSE (CLIENT_CREATE_CREDENTIAL, KDC);

Check warning on line 21254 in src/gmp.c

View check run for this annotation

Codecov / codecov/patch

src/gmp.c#L21254

Added line #L21254 was not covered by tests
CLOSE (CLIENT_CREATE_CREDENTIAL, KEY);
CLOSE (CLIENT_CREATE_CREDENTIAL_KEY, PHRASE);
CLOSE (CLIENT_CREATE_CREDENTIAL_KEY, PRIVATE);
Expand All @@ -21212,6 +21262,7 @@
CLOSE (CLIENT_CREATE_CREDENTIAL, PRIVACY);
CLOSE (CLIENT_CREATE_CREDENTIAL_PRIVACY, ALGORITHM);
CLOSE (CLIENT_CREATE_CREDENTIAL_PRIVACY, PASSWORD);
CLOSE (CLIENT_CREATE_CREDENTIAL, REALM);

Check warning on line 21265 in src/gmp.c

View check run for this annotation

Codecov / codecov/patch

src/gmp.c#L21265

Added line #L21265 was not covered by tests
CLOSE (CLIENT_CREATE_CREDENTIAL, TYPE);

case CLIENT_CREATE_FILTER:
Expand Down Expand Up @@ -24267,6 +24318,8 @@
modify_credential_data->auth_algorithm,
modify_credential_data->privacy_password,
modify_credential_data->privacy_algorithm,
modify_credential_data->kdc,
modify_credential_data->realm,

Check warning on line 24322 in src/gmp.c

View check run for this annotation

Codecov / codecov/patch

src/gmp.c#L24321-L24322

Added lines #L24321 - L24322 were not covered by tests
modify_credential_data->allow_insecure))
{
case 0:
Expand Down Expand Up @@ -24389,6 +24442,7 @@
CLOSE (CLIENT_MODIFY_CREDENTIAL, CERTIFICATE);
CLOSE (CLIENT_MODIFY_CREDENTIAL, COMMENT);
CLOSE (CLIENT_MODIFY_CREDENTIAL, COMMUNITY);
CLOSE (CLIENT_MODIFY_CREDENTIAL, KDC);

Check warning on line 24445 in src/gmp.c

View check run for this annotation

Codecov / codecov/patch

src/gmp.c#L24445

Added line #L24445 was not covered by tests
CLOSE (CLIENT_MODIFY_CREDENTIAL, KEY);
CLOSE (CLIENT_MODIFY_CREDENTIAL_KEY, PHRASE);
CLOSE (CLIENT_MODIFY_CREDENTIAL_KEY, PRIVATE);
Expand All @@ -24399,6 +24453,7 @@
CLOSE (CLIENT_MODIFY_CREDENTIAL, PRIVACY);
CLOSE (CLIENT_MODIFY_CREDENTIAL_PRIVACY, ALGORITHM);
CLOSE (CLIENT_MODIFY_CREDENTIAL_PRIVACY, PASSWORD);
CLOSE (CLIENT_MODIFY_CREDENTIAL, REALM);

Check warning on line 24456 in src/gmp.c

View check run for this annotation

Codecov / codecov/patch

src/gmp.c#L24456

Added line #L24456 was not covered by tests

case CLIENT_MODIFY_FILTER:
{
Expand Down Expand Up @@ -27049,6 +27104,9 @@
APPEND (CLIENT_MODIFY_CREDENTIAL_COMMUNITY,
&modify_credential_data->community);

APPEND (CLIENT_MODIFY_CREDENTIAL_KDC,

Check warning on line 27107 in src/gmp.c

View check run for this annotation

Codecov / codecov/patch

src/gmp.c#L27107

Added line #L27107 was not covered by tests
&modify_credential_data->kdc);

APPEND (CLIENT_MODIFY_CREDENTIAL_KEY_PHRASE,
&modify_credential_data->key_phrase);

Expand All @@ -27073,6 +27131,9 @@
APPEND (CLIENT_MODIFY_CREDENTIAL_PRIVACY_PASSWORD,
&modify_credential_data->privacy_password);

APPEND (CLIENT_MODIFY_CREDENTIAL_REALM,

Check warning on line 27134 in src/gmp.c

View check run for this annotation

Codecov / codecov/patch

src/gmp.c#L27134

Added line #L27134 was not covered by tests
&modify_credential_data->realm);


case CLIENT_MODIFY_REPORT_CONFIG:
modify_report_config_element_text (text, text_len);
Expand Down Expand Up @@ -27180,6 +27241,9 @@
APPEND (CLIENT_CREATE_CREDENTIAL_COPY,
&create_credential_data->copy);

APPEND (CLIENT_CREATE_CREDENTIAL_KDC,

Check warning on line 27244 in src/gmp.c

View check run for this annotation

Codecov / codecov/patch

src/gmp.c#L27244

Added line #L27244 was not covered by tests
&create_credential_data->kdc);

APPEND (CLIENT_CREATE_CREDENTIAL_KEY_PHRASE,
&create_credential_data->key_phrase);

Expand All @@ -27204,6 +27268,9 @@
APPEND (CLIENT_CREATE_CREDENTIAL_PRIVACY_PASSWORD,
&create_credential_data->privacy_password);

APPEND (CLIENT_CREATE_CREDENTIAL_REALM,

Check warning on line 27271 in src/gmp.c

View check run for this annotation

Codecov / codecov/patch

src/gmp.c#L27271

Added line #L27271 was not covered by tests
&create_credential_data->realm);

APPEND (CLIENT_CREATE_CREDENTIAL_TYPE,
&create_credential_data->type);

Expand Down
11 changes: 8 additions & 3 deletions src/manage.c
Original file line number Diff line number Diff line change
Expand Up @@ -975,7 +975,8 @@
manage_create_encryption_key (GSList *log_config,
const db_conn_info_t *database)
{
int ret = manage_option_setup (log_config, database);
int ret = manage_option_setup (log_config, database,

Check warning on line 978 in src/manage.c

View check run for this annotation

Codecov / codecov/patch

src/manage.c#L978

Added line #L978 was not covered by tests
0 /* avoid_db_check_inserts */);
if (ret)
{
printf ("Error setting up log config or database connection.");
Expand Down Expand Up @@ -1039,7 +1040,8 @@
const db_conn_info_t *database,
const char *uid)
{
int ret = manage_option_setup (log_config, database);
int ret = manage_option_setup (log_config, database,

Check warning on line 1043 in src/manage.c

View check run for this annotation

Codecov / codecov/patch

src/manage.c#L1043

Added line #L1043 was not covered by tests
0 /* avoid_db_check_inserts */);
if (ret)
{
printf ("Error setting up log config or database connection.\n");
Expand Down Expand Up @@ -4126,6 +4128,8 @@
return NULL;
else if (strcasecmp (abbreviation, "cc") == 0)
return "client certificate";
else if (strcasecmp (abbreviation, "krb5") == 0)
return "Kerberos 5";

Check warning on line 4132 in src/manage.c

View check run for this annotation

Codecov / codecov/patch

src/manage.c#L4131-L4132

Added lines #L4131 - L4132 were not covered by tests
else if (strcasecmp (abbreviation, "pw") == 0)
return "password only";
else if (strcasecmp (abbreviation, "snmp") == 0)
Expand Down Expand Up @@ -5417,7 +5421,8 @@
return -1;
}

ret = manage_option_setup (log_config, database);
ret = manage_option_setup (log_config, database,

Check warning on line 5424 in src/manage.c

View check run for this annotation

Codecov / codecov/patch

src/manage.c#L5424

Added line #L5424 was not covered by tests
0 /* avoid_db_check_inserts */);
if (ret)
{
if (error_msg)
Expand Down
12 changes: 9 additions & 3 deletions src/manage.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ init_manage (GSList*, const db_conn_info_t *, int, int, int, int,
manage_connection_forker_t, int);

int
init_manage_helper (GSList *, const db_conn_info_t *, int);
init_manage_helper (GSList *, const db_conn_info_t *, int, int);

void
init_manage_process (const db_conn_info_t*);
Expand Down Expand Up @@ -2218,7 +2218,7 @@ int
create_credential (const char*, const char*, const char*, const char*,
const char*, const char*, const char*, const char*,
const char*, const char*, const char*, const char*,
const char*, credential_t*);
const char*, const char*, const char*, credential_t*);

int
copy_credential (const char*, const char*, const char*,
Expand All @@ -2228,7 +2228,7 @@ int
modify_credential (const char*, const char*, const char*, const char*,
const char*, const char*, const char*, const char*,
const char*, const char*, const char*, const char*,
const char*);
const char*, const char*, const char*);

int
delete_credential (const char *, int);
Expand Down Expand Up @@ -2269,6 +2269,12 @@ credential_iterator_privacy_password (iterator_t*);
const char*
credential_iterator_public_key (iterator_t*);

const char*
credential_iterator_kdc (iterator_t*);

const char*
credential_iterator_realm (iterator_t*);

const char*
credential_iterator_private_key (iterator_t*);

Expand Down
Loading
Loading