From 2d4a98d0d33f688378612531c52d965513f7bc96 Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Mon, 1 May 2023 10:44:42 +0200 Subject: [PATCH 01/53] debug: Add macro to mark variables that are only used in DBG statements Some variables that are only assigned to be used in DBG statements will otherwise trigger a "set but not used" warning/error if DEBUG_LEVEL is too low. --- src/libstrongswan/utils/debug.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/libstrongswan/utils/debug.h b/src/libstrongswan/utils/debug.h index 127da579a..06d43ebbf 100644 --- a/src/libstrongswan/utils/debug.h +++ b/src/libstrongswan/utils/debug.h @@ -140,6 +140,11 @@ enum level_t { # define DBG4(...) {} #endif +/** mark variables that are only used in DBG statements */ +#ifndef DBG_UNUSED +# define DBG_UNUSED __attribute__((unused)) +#endif + /** dbg function hook, uses dbg_default() by default */ extern void (*dbg) (debug_t group, level_t level, char *fmt, ...); From d7750dff9b9a55086303402bea6acca2732a493e Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Tue, 18 Apr 2023 16:34:38 +0200 Subject: [PATCH 02/53] asn1: Fix build with DEBUG_LEVEL < 2 --- src/libstrongswan/asn1/asn1.c | 3 ++- src/libstrongswan/asn1/asn1_parser.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libstrongswan/asn1/asn1.c b/src/libstrongswan/asn1/asn1.c index cf684e720..866b3c857 100644 --- a/src/libstrongswan/asn1/asn1.c +++ b/src/libstrongswan/asn1/asn1.c @@ -548,9 +548,10 @@ void asn1_debug_simple_object(chunk_t object, asn1_t type, bool private) case ASN1_UTCTIME: case ASN1_GENERALIZEDTIME: { +#if DEBUG_LEVEL >= 2 time_t time = asn1_to_time(&object, type); - DBG2(DBG_ASN, " '%T'", &time, TRUE); +#endif } return; default: diff --git a/src/libstrongswan/asn1/asn1_parser.c b/src/libstrongswan/asn1/asn1_parser.c index ef724ada7..e48ac3c11 100644 --- a/src/libstrongswan/asn1/asn1_parser.c +++ b/src/libstrongswan/asn1/asn1_parser.c @@ -89,7 +89,7 @@ METHOD(asn1_parser_t, iterate, bool, { chunk_t *blob, *blob1, blob_ori; u_char *start_ptr; - u_int level; + u_int level DBG_UNUSED; asn1Object_t obj; *object = chunk_empty; From f73d8699b346ce00e0690dd1ee4eb1506668dbcb Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Mon, 1 May 2023 10:35:05 +0200 Subject: [PATCH 03/53] crypto-tester: Fix build with DEBUG_LEVEL < 1 --- src/libstrongswan/crypto/crypto_tester.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libstrongswan/crypto/crypto_tester.c b/src/libstrongswan/crypto/crypto_tester.c index b87c4c73a..5cd6ef4d0 100644 --- a/src/libstrongswan/crypto/crypto_tester.c +++ b/src/libstrongswan/crypto/crypto_tester.c @@ -110,6 +110,7 @@ struct private_crypto_tester_t { int bench_size; }; +#if DEBUG_LEVEL >= 1 /** * Get the name of a test vector, if available */ @@ -125,6 +126,7 @@ static const char* get_name(void *sym) #endif return "unknown"; } +#endif #if defined(CLOCK_THREAD_CPUTIME_ID) && defined(HAVE_CLOCK_GETTIME) From b39105b5b4deeff8df2bebf096b5298a8e704166 Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Mon, 1 May 2023 10:38:24 +0200 Subject: [PATCH 04/53] credential-factory: Fix build with DEBUG_LEVEL < 1 --- src/libstrongswan/credentials/credential_factory.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libstrongswan/credentials/credential_factory.c b/src/libstrongswan/credentials/credential_factory.c index 36e6995c7..c46ca5802 100644 --- a/src/libstrongswan/credentials/credential_factory.c +++ b/src/libstrongswan/credentials/credential_factory.c @@ -119,7 +119,7 @@ METHOD(credential_factory_t, create, void*, void *construct = NULL; int failures = 0; uintptr_t level; - enum_name_t *names; + enum_name_t *names DBG_UNUSED; switch (type) { From 5a98f8f4abef53f7d39344bc1e97bfc43df9b821 Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Mon, 1 May 2023 10:37:01 +0200 Subject: [PATCH 05/53] certificate: Fix build with DEBUG_LEVEL < 1 --- src/libstrongswan/credentials/certificates/certificate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libstrongswan/credentials/certificates/certificate.c b/src/libstrongswan/credentials/certificates/certificate.c index f926afca6..91bc0f509 100644 --- a/src/libstrongswan/credentials/certificates/certificate.c +++ b/src/libstrongswan/credentials/certificates/certificate.c @@ -48,7 +48,7 @@ ENUM(cert_validation_names, VALIDATION_GOOD, VALIDATION_REVOKED, bool certificate_is_newer(certificate_t *this, certificate_t *other) { time_t this_update, that_update; - char *type = "certificate"; + char *type DBG_UNUSED = "certificate"; bool newer; if (this->get_type(this) == CERT_X509_CRL) From 1b59031cc3d827249d9f0ffb2316b40e9582f7e9 Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Mon, 1 May 2023 10:46:28 +0200 Subject: [PATCH 06/53] auth-cfg: Fix build with DEBUG_LEVEL < 1 --- src/libstrongswan/credentials/auth_cfg.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libstrongswan/credentials/auth_cfg.c b/src/libstrongswan/credentials/auth_cfg.c index 8c0e9eaff..2bff538d6 100644 --- a/src/libstrongswan/credentials/auth_cfg.c +++ b/src/libstrongswan/credentials/auth_cfg.c @@ -821,7 +821,6 @@ METHOD(auth_cfg_t, complies, bool, signature_params_t *ike_scheme = NULL, *scheme = NULL; u_int strength = 0; auth_rule_t t1, t2; - char *key_type; void *value; e1 = constraints->create_enumerator(constraints); @@ -1110,6 +1109,8 @@ METHOD(auth_cfg_t, complies, bool, * public key strength */ if (success && strength) { + char *key_type DBG_UNUSED; + e2 = create_enumerator(this); while (e2->enumerate(e2, &t2, &strength)) { From a551f80e4fa8f5ece518e8ed4a81a1abe1f8d65d Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Tue, 18 Apr 2023 16:38:18 +0200 Subject: [PATCH 07/53] plugin-loader: Fix build with DEBUG_LEVEL < 3 --- src/libstrongswan/plugins/plugin_loader.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/libstrongswan/plugins/plugin_loader.c b/src/libstrongswan/plugins/plugin_loader.c index 89d3f5de0..30b1aeed0 100644 --- a/src/libstrongswan/plugins/plugin_loader.c +++ b/src/libstrongswan/plugins/plugin_loader.c @@ -755,10 +755,11 @@ static bool load_dependencies(private_plugin_loader_t *this, { bool soft = provided->feature[i].kind == FEATURE_SDEPEND; -#ifndef USE_FUZZING +#if !defined(USE_FUZZING) && DEBUG_LEVEL >= 1 char *name, *provide, *depend; +#if DEBUG_LEVEL >= 3 int indent = level * 2; - +#endif name = provided->entry->plugin->get_name(provided->entry->plugin); provide = plugin_feature_get_string(&provided->feature[0]); depend = plugin_feature_get_string(&provided->feature[i]); @@ -779,7 +780,7 @@ static bool load_dependencies(private_plugin_loader_t *this, } free(provide); free(depend); -#endif /* !USE_FUZZING */ +#endif /* !USE_FUZZING && DEBUG_LEVEL */ if (soft) { /* it's ok if we can't resolve soft dependencies */ @@ -809,7 +810,7 @@ static void load_feature(private_plugin_loader_t *this, return; } -#ifndef USE_FUZZING +#if !defined(USE_FUZZING) && DEBUG_LEVEL >= 1 char *name, *provide; name = provided->entry->plugin->get_name(provided->entry->plugin); @@ -825,7 +826,7 @@ static void load_feature(private_plugin_loader_t *this, provide, name); } free(provide); -#endif /* !USE_FUZZING */ +#endif /* !USE_FUZZING && DEBUG_LEVEL */ } else { /* TODO: we could check the current level and set a different flag when @@ -845,13 +846,12 @@ static void load_provided(private_plugin_loader_t *this, provided_feature_t *provided, int level) { - if (provided->loaded || provided->failed) { return; } -#ifndef USE_FUZZING +#if !defined(USE_FUZZING) && DEBUG_LEVEL >= 3 char *name, *provide; int indent = level * 2; @@ -872,7 +872,7 @@ static void load_provided(private_plugin_loader_t *this, { return; } -#endif /* USE_FUZZING */ +#endif /* USE_FUZZING && DEBUG_LEVEL */ provided->loading = TRUE; load_feature(this, provided, level + 1); From c0a281472f8e6bc7c39fef1656e0da23450e1fb7 Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Tue, 18 Apr 2023 16:42:30 +0200 Subject: [PATCH 08/53] x509: Fix build with DEBUG_LEVEL < 2 for structures that ignore unknown critical extensions --- src/libstrongswan/plugins/x509/x509_ac.c | 5 ++--- src/libstrongswan/plugins/x509/x509_ocsp_response.c | 5 ++--- src/libstrongswan/plugins/x509/x509_pkcs10.c | 5 ++--- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/libstrongswan/plugins/x509/x509_ac.c b/src/libstrongswan/plugins/x509/x509_ac.c index c4acce4fe..2e370f5a7 100644 --- a/src/libstrongswan/plugins/x509/x509_ac.c +++ b/src/libstrongswan/plugins/x509/x509_ac.c @@ -429,7 +429,6 @@ static bool parse_certificate(private_x509_ac_t *this) int extn_oid = OID_UNKNOWN; signature_params_t sig_alg = {}; bool success = FALSE; - bool critical; parser = asn1_parser_create(acObjects, this->encoding); @@ -529,8 +528,8 @@ static bool parse_certificate(private_x509_ac_t *this) extn_oid = asn1_known_oid(object); break; case AC_OBJ_CRITICAL: - critical = object.len && *object.ptr; - DBG2(DBG_ASN, " %s",(critical)?"TRUE":"FALSE"); + DBG2(DBG_ASN, " %s", + object.len && *object.ptr ? "TRUE" : "FALSE"); break; case AC_OBJ_EXTN_VALUE: { diff --git a/src/libstrongswan/plugins/x509/x509_ocsp_response.c b/src/libstrongswan/plugins/x509/x509_ocsp_response.c index 93fbc8173..9954e55ce 100644 --- a/src/libstrongswan/plugins/x509/x509_ocsp_response.c +++ b/src/libstrongswan/plugins/x509/x509_ocsp_response.c @@ -528,7 +528,6 @@ static bool parse_basicOCSPResponse(private_x509_ocsp_response_t *this, u_int responses_level = level0; certificate_t *cert; bool success = FALSE; - bool critical; parser = asn1_parser_create(basicResponseObjects, blob); parser->set_top_level(parser, level0); @@ -573,8 +572,8 @@ static bool parse_basicOCSPResponse(private_x509_ocsp_response_t *this, extn_oid = asn1_known_oid(object); break; case BASIC_RESPONSE_CRITICAL: - critical = object.len && *object.ptr; - DBG2(DBG_ASN, " %s", critical ? "TRUE" : "FALSE"); + DBG2(DBG_ASN, " %s", + object.len && *object.ptr ? "TRUE" : "FALSE"); break; case BASIC_RESPONSE_EXT_VALUE: if (extn_oid == OID_NONCE && diff --git a/src/libstrongswan/plugins/x509/x509_pkcs10.c b/src/libstrongswan/plugins/x509/x509_pkcs10.c index 94a90ebf0..dcf431ea8 100644 --- a/src/libstrongswan/plugins/x509/x509_pkcs10.c +++ b/src/libstrongswan/plugins/x509/x509_pkcs10.c @@ -430,7 +430,6 @@ static bool parse_extension_request(private_x509_pkcs10_t *this, chunk_t blob, i int objectID; int extn_oid = OID_UNKNOWN; bool success = FALSE; - bool critical; parser = asn1_parser_create(extensionRequestObjects, blob); parser->set_top_level(parser, level0); @@ -445,8 +444,8 @@ static bool parse_extension_request(private_x509_pkcs10_t *this, chunk_t blob, i extn_oid = asn1_known_oid(object); break; case PKCS10_EXTN_CRITICAL: - critical = object.len && *object.ptr; - DBG2(DBG_ASN, " %s", critical ? "TRUE" : "FALSE"); + DBG2(DBG_ASN, " %s", + object.len && *object.ptr ? "TRUE" : "FALSE"); break; case PKCS10_EXTN_VALUE: { From 984f8cbcded519cd4992e5564263105fc9da6a9e Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Mon, 1 May 2023 11:07:18 +0200 Subject: [PATCH 09/53] revocation: Fix build with DEBUG_LEVEL < 1 --- src/libstrongswan/plugins/revocation/revocation_validator.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libstrongswan/plugins/revocation/revocation_validator.c b/src/libstrongswan/plugins/revocation/revocation_validator.c index daa9db797..a4e16dffe 100644 --- a/src/libstrongswan/plugins/revocation/revocation_validator.c +++ b/src/libstrongswan/plugins/revocation/revocation_validator.c @@ -683,7 +683,8 @@ static cert_validation_t check_delta_crl(x509_t *subject, x509_t *issuer, u_int timeout) { cert_validation_t valid = VALIDATION_SKIPPED; - certificate_t *best = NULL, *current, *cissuer = (certificate_t*)issuer; + certificate_t *best = NULL, *current; + certificate_t *cissuer DBG_UNUSED = (certificate_t*)issuer; enumerator_t *enumerator; identification_t *id; x509_cdp_t *cdp; @@ -752,7 +753,7 @@ static cert_validation_t check_crl(x509_t *subject, x509_t *issuer, auth_cfg_t *auth, u_int timeout) { cert_validation_t valid = VALIDATION_SKIPPED; - certificate_t *best = NULL, *cissuer = (certificate_t*)issuer; + certificate_t *best = NULL, *cissuer DBG_UNUSED = (certificate_t*)issuer; identification_t *id; x509_cdp_t *cdp; bool uri_found = FALSE; From 7ea431cf70fde4d6cead0f4b894e5a8b07aa3d5b Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Mon, 1 May 2023 11:10:47 +0200 Subject: [PATCH 10/53] constraints: Fix build with DEBUG_LEVEL < 1 --- .../plugins/constraints/constraints_validator.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libstrongswan/plugins/constraints/constraints_validator.c b/src/libstrongswan/plugins/constraints/constraints_validator.c index 0f074c4f5..379bb40f7 100644 --- a/src/libstrongswan/plugins/constraints/constraints_validator.c +++ b/src/libstrongswan/plugins/constraints/constraints_validator.c @@ -352,7 +352,7 @@ static bool has_policy(x509_t *issuer, chunk_t oid) */ static bool check_policy(x509_t *subject, x509_t *issuer) { - certificate_t *cert = (certificate_t*)subject; + certificate_t *cert DBG_UNUSED = (certificate_t*)subject; x509_policy_mapping_t *mapping; x509_cert_policy_t *policy; enumerator_t *enumerator; @@ -485,7 +485,7 @@ static bool has_no_policy_mapping(linked_list_t *chain, int len) { enumerator_t *enumerator, *mappings; x509_policy_mapping_t *mapping; - certificate_t *cert; + certificate_t *cert DBG_UNUSED; x509_t *x509; bool valid = TRUE; @@ -514,7 +514,7 @@ static bool has_no_any_policy(linked_list_t *chain, int len) { enumerator_t *enumerator, *policies; x509_cert_policy_t *policy; - certificate_t *cert; + certificate_t *cert DBG_UNUSED; x509_t *x509; bool valid = TRUE; From a9a2c040bafc6569120ae8c9e8332343c6974e3a Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Tue, 18 Apr 2023 16:44:54 +0200 Subject: [PATCH 11/53] pkcs7: Fix build with DEBUG_LEVEL < 2 --- src/libstrongswan/plugins/pkcs7/pkcs7_signed_data.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/libstrongswan/plugins/pkcs7/pkcs7_signed_data.c b/src/libstrongswan/plugins/pkcs7/pkcs7_signed_data.c index 30d536911..7210b728d 100644 --- a/src/libstrongswan/plugins/pkcs7/pkcs7_signed_data.c +++ b/src/libstrongswan/plugins/pkcs7/pkcs7_signed_data.c @@ -405,7 +405,7 @@ static bool parse(private_pkcs7_signed_data_t *this, chunk_t content) { asn1_parser_t *parser; chunk_t object; - int objectID, version; + int objectID; signerinfo_t *info = NULL; bool success = FALSE; @@ -418,8 +418,7 @@ static bool parse(private_pkcs7_signed_data_t *this, chunk_t content) switch (objectID) { case PKCS7_VERSION: - version = object.len ? (int)*object.ptr : 0; - DBG2(DBG_LIB, " v%d", version); + DBG2(DBG_LIB, " v%d", object.len ? (int)*object.ptr : 0); break; case PKCS7_CONTENT_INFO: this->content = lib->creds->create(lib->creds, @@ -448,8 +447,7 @@ static bool parse(private_pkcs7_signed_data_t *this, chunk_t content) this->signerinfos->insert_last(this->signerinfos, info); break; case PKCS7_SIGNER_INFO_VERSION: - version = object.len ? (int)*object.ptr : 0; - DBG2(DBG_LIB, " v%d", version); + DBG2(DBG_LIB, " v%d", object.len ? (int)*object.ptr : 0); break; case PKCS7_ISSUER: info->issuer = identification_create_from_encoding( From b158c210cdc07a753b88bb9b5cc06a6c98c44e1f Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Tue, 18 Apr 2023 16:46:02 +0200 Subject: [PATCH 12/53] sqlite: Fix build with DEBUG_LEVEL < 2 --- src/libstrongswan/plugins/sqlite/sqlite_plugin.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libstrongswan/plugins/sqlite/sqlite_plugin.c b/src/libstrongswan/plugins/sqlite/sqlite_plugin.c index 58259841c..8812c9947 100644 --- a/src/libstrongswan/plugins/sqlite/sqlite_plugin.c +++ b/src/libstrongswan/plugins/sqlite/sqlite_plugin.c @@ -62,7 +62,9 @@ METHOD(plugin_t, destroy, void, plugin_t *sqlite_plugin_create() { private_sqlite_plugin_t *this; +#if SQLITE_VERSION_NUMBER >= 3005000 && DEBUG_LEVEL >= 2 int threadsafe = 0; +#endif INIT(this, .public = { @@ -74,7 +76,7 @@ plugin_t *sqlite_plugin_create() }, ); -#if SQLITE_VERSION_NUMBER >= 3005000 +#if SQLITE_VERSION_NUMBER >= 3005000 && DEBUG_LEVEL >= 2 threadsafe = sqlite3_threadsafe(); #endif DBG2(DBG_LIB, "using SQLite %s, thread safety %d", From 94cbd6469a2c0a04281cff3ddeb8a5bbf52f498e Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Mon, 1 May 2023 14:57:00 +0200 Subject: [PATCH 13/53] bliss: Fix build with DEBUG_LEVEL < 2 --- src/libstrongswan/plugins/bliss/bliss_private_key.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libstrongswan/plugins/bliss/bliss_private_key.c b/src/libstrongswan/plugins/bliss/bliss_private_key.c index 9eb89c59e..b6ddc72dc 100644 --- a/src/libstrongswan/plugins/bliss/bliss_private_key.c +++ b/src/libstrongswan/plugins/bliss/bliss_private_key.c @@ -186,7 +186,7 @@ static bool sign_bliss(private_bliss_private_key_t *this, hash_algorithm_t alg, int32_t scalar, norm, ui; int16_t *ud, *uz2d, *z2d, value; int i, n; - double mean1 = 0, mean2 = 0, sigma1 = 0, sigma2 = 0; + double mean1 = 0, mean2 = 0, sigma1 DBG_UNUSED = 0, sigma2 DBG_UNUSED = 0; bool accepted, positive, success = FALSE, use_bliss_b; /* Initialize signature */ @@ -907,7 +907,7 @@ static bool create_secret(private_bliss_private_key_t *this, rng_t *rng, { uint8_t seed_buf[32]; uint8_t *f, *g; - uint32_t l2_norm, nks; + uint32_t l2_norm DBG_UNUSED, nks; int i, n; chunk_t seed; size_t seed_len; From 1b58e8c3861875e05bf3ebe1687b18e1d5bac136 Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Tue, 18 Apr 2023 16:48:08 +0200 Subject: [PATCH 14/53] drbg: Fix build with DEBUG_LEVEL < 4 --- src/libstrongswan/plugins/drbg/drbg_hmac.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/libstrongswan/plugins/drbg/drbg_hmac.c b/src/libstrongswan/plugins/drbg/drbg_hmac.c index 704adb580..a0aa05ab9 100644 --- a/src/libstrongswan/plugins/drbg/drbg_hmac.c +++ b/src/libstrongswan/plugins/drbg/drbg_hmac.c @@ -158,7 +158,6 @@ METHOD(drbg_t, generate, bool, private_drbg_hmac_t *this, uint32_t len, uint8_t *out) { size_t delta; - chunk_t output; if (len > MAX_DRBG_BYTES) { @@ -179,7 +178,9 @@ METHOD(drbg_t, generate, bool, { return FALSE; } - output = chunk_create(out, len); +#if DEBUG_LEVEL >= 4 + chunk_t output = chunk_create(out, len); +#endif while (len) { @@ -192,7 +193,7 @@ METHOD(drbg_t, generate, bool, len -= delta; out += delta; } - DBG4(DBG_LIB, "HMAC_DRBG Out: %B", &output); + DBG4(DBG_LIB, "HMAC_DRBG out: %B", &output); if (!update(this, chunk_empty)) { From 777d0ef7b0eebb4a7659f11ba3235e703ead182e Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Tue, 18 Apr 2023 16:49:26 +0200 Subject: [PATCH 15/53] esp-packet: Fix build with DEBUG_LEVEL < 3 --- src/libipsec/esp_packet.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/libipsec/esp_packet.c b/src/libipsec/esp_packet.c index 53de9e291..b19dc9d7d 100644 --- a/src/libipsec/esp_packet.c +++ b/src/libipsec/esp_packet.c @@ -185,8 +185,8 @@ static bool check_padding(chunk_t padding) static bool remove_padding(private_esp_packet_t *this, chunk_t plaintext) { uint8_t next_header, pad_length; - chunk_t padding, payload; bio_reader_t *reader; + chunk_t padding; reader = bio_reader_create(plaintext); if (!reader->read_uint8_end(reader, &next_header) || @@ -209,11 +209,13 @@ static bool remove_padding(private_esp_packet_t *this, chunk_t plaintext) return FALSE; } this->next_header = next_header; - payload = this->payload->get_encoding(this->payload); +#if DEBUG_LEVEL >= 3 + chunk_t encoding = this->payload->get_encoding(this->payload); DBG3(DBG_ESP, "ESP payload:\n payload %B\n padding %B\n " - "padding length = %hhu, next header = %hhu", &payload, &padding, + "padding length = %hhu, next header = %hhu", &encoding, &padding, pad_length, this->next_header); +#endif return TRUE; failed: From bb06b7a4bb9c33670584dc06a9d22f63756660a4 Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Tue, 18 Apr 2023 16:51:21 +0200 Subject: [PATCH 16/53] simaka-manager: Fix counter in log message when getting quintuplets Also fixes the build with DEBUG_LEVEL < 1. --- src/libsimaka/simaka_manager.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libsimaka/simaka_manager.c b/src/libsimaka/simaka_manager.c index 90a76bd71..dec5a2820 100644 --- a/src/libsimaka/simaka_manager.c +++ b/src/libsimaka/simaka_manager.c @@ -314,6 +314,7 @@ METHOD(simaka_manager_t, provider_get_quintuplet, bool, this->lock->unlock(this->lock); return TRUE; } + tried++; } enumerator->destroy(enumerator); this->lock->unlock(this->lock); From 6086029056285316ba2e968ca87468a3d2243e85 Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Tue, 18 Apr 2023 16:57:16 +0200 Subject: [PATCH 17/53] libtls: Fix build with DEBUG_LEVEL < 3 --- src/libtls/tls_eap.c | 2 +- src/libtls/tls_fragmentation.c | 5 +++-- src/libtls/tls_peer.c | 2 +- src/libtls/tls_server.c | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/libtls/tls_eap.c b/src/libtls/tls_eap.c index 4b16504b5..7928299b6 100644 --- a/src/libtls/tls_eap.c +++ b/src/libtls/tls_eap.c @@ -210,7 +210,7 @@ static status_t build_pkt(private_tls_eap_t *this, chunk_t *out) eap_tls_packet_t *pkt; size_t len, reclen, msg_len_offset; status_t status; - char *kind; + char *kind DBG_UNUSED; if (this->is_server) { diff --git a/src/libtls/tls_fragmentation.c b/src/libtls/tls_fragmentation.c index a53b1d004..52149016f 100644 --- a/src/libtls/tls_fragmentation.c +++ b/src/libtls/tls_fragmentation.c @@ -230,7 +230,6 @@ static status_t process_application(private_tls_fragmentation_t *this, while (reader->remaining(reader)) { status_t status; - chunk_t data; if (reader->remaining(reader) > TLS_MAX_FRAGMENT_LEN) { @@ -238,8 +237,10 @@ static status_t process_application(private_tls_fragmentation_t *this, this->alert->add(this->alert, TLS_FATAL, TLS_DECODE_ERROR); return NEED_MORE; } - data = reader->peek(reader); +#if DEBUG_LEVEL >= 3 + chunk_t data = reader->peek(reader); DBG3(DBG_TLS, "%B", &data); +#endif status = this->application->process(this->application, reader); switch (status) { diff --git a/src/libtls/tls_peer.c b/src/libtls/tls_peer.c index edddf3262..78652c064 100644 --- a/src/libtls/tls_peer.c +++ b/src/libtls/tls_peer.c @@ -1112,7 +1112,7 @@ static status_t process_key_update(private_tls_peer_t *this, METHOD(tls_handshake_t, process, status_t, private_tls_peer_t *this, tls_handshake_type_t type, bio_reader_t *reader) { - tls_handshake_type_t expected; + tls_handshake_type_t expected DBG_UNUSED; if (this->tls->get_version_max(this->tls) < TLS_1_3) { diff --git a/src/libtls/tls_server.c b/src/libtls/tls_server.c index 573893f2e..e91e4e440 100644 --- a/src/libtls/tls_server.c +++ b/src/libtls/tls_server.c @@ -1042,7 +1042,7 @@ static status_t process_key_update(private_tls_server_t *this, METHOD(tls_handshake_t, process, status_t, private_tls_server_t *this, tls_handshake_type_t type, bio_reader_t *reader) { - tls_handshake_type_t expected; + tls_handshake_type_t expected DBG_UNUSED; if (this->tls->get_version_max(this->tls) < TLS_1_3) { From 874562fc1c8836af43b0e158e50b8683c59f9fa8 Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Tue, 18 Apr 2023 17:34:58 +0200 Subject: [PATCH 18/53] radius-client: Fix build with DEBUG_LEVEL < 3 --- src/libradius/radius_client.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libradius/radius_client.c b/src/libradius/radius_client.c index f31814140..04dbcb9fc 100644 --- a/src/libradius/radius_client.c +++ b/src/libradius/radius_client.c @@ -84,7 +84,6 @@ METHOD(radius_client_t, request, radius_message_t*, { radius_socket_t *socket; radius_message_t *res; - chunk_t data; /* add our NAS-Identifier */ req->add(req, RAT_NAS_IDENTIFIER, @@ -104,8 +103,10 @@ METHOD(radius_client_t, request, radius_message_t*, DBG1(DBG_CFG, "received RADIUS %N from server '%s'", radius_message_code_names, res->get_code(res), this->config->get_name(this->config)); - data = res->get_encoding(res); +#if DEBUG_LEVEL >= 3 + chunk_t data = res->get_encoding(res); DBG3(DBG_CFG, "%B", &data); +#endif save_state(this, res); if (res->get_code(res) == RMC_ACCESS_ACCEPT) From a0ee0cbf90109b3701ec2d17033636d3520ae982 Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Mon, 1 May 2023 16:30:06 +0200 Subject: [PATCH 19/53] tnccs-11: Fix build with DEBUG_LEVEL < 2 --- src/libtnccs/plugins/tnccs_11/tnccs_11.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/libtnccs/plugins/tnccs_11/tnccs_11.c b/src/libtnccs/plugins/tnccs_11/tnccs_11.c index 4ded303bd..93c43b38a 100644 --- a/src/libtnccs/plugins/tnccs_11/tnccs_11.c +++ b/src/libtnccs/plugins/tnccs_11/tnccs_11.c @@ -277,15 +277,15 @@ static void handle_message(private_tnccs_11_t *this, tnccs_msg_t *msg) } case TNCCS_MSG_ERROR: { - tnccs_error_msg_t *err_msg; +#if DEBUG_LEVEL >= 1 + tnccs_error_msg_t *err_msg = (tnccs_error_msg_t*)msg; tnccs_error_type_t error_type; char *error_msg; - err_msg = (tnccs_error_msg_t*)msg; error_msg = err_msg->get_message(err_msg, &error_type); DBG1(DBG_TNC, "received '%N' TNCCS-Error: %s", tnccs_error_type_names, error_type, error_msg); - +#endif /* we assume that all errors are fatal */ this->fatal_error = TRUE; break; @@ -305,6 +305,7 @@ static void handle_message(private_tnccs_11_t *this, tnccs_msg_t *msg) } case TNCCS_MSG_REASON_STRINGS: { +#if DEBUG_LEVEL >= 2 tnccs_reason_strings_msg_t *reason_msg; chunk_t reason_string, reason_lang; @@ -314,6 +315,7 @@ static void handle_message(private_tnccs_11_t *this, tnccs_msg_t *msg) reason_string.ptr); DBG2(DBG_TNC, "language code is '%.*s'", (int)reason_lang.len, reason_lang.ptr); +#endif break; } default: From 4a28488a7e50722a0bb3b599422c78d7c9e36829 Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Tue, 18 Apr 2023 17:35:36 +0200 Subject: [PATCH 20/53] tnccs-20: Fix build with DEBUG_LEVEL < 2 --- src/libtnccs/plugins/tnccs_20/batch/pb_tnc_batch.c | 10 ++++++---- src/libtnccs/plugins/tnccs_20/tnccs_20_client.c | 6 +++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/libtnccs/plugins/tnccs_20/batch/pb_tnc_batch.c b/src/libtnccs/plugins/tnccs_20/batch/pb_tnc_batch.c index 096e4cc62..48f8bd783 100644 --- a/src/libtnccs/plugins/tnccs_20/batch/pb_tnc_batch.c +++ b/src/libtnccs/plugins/tnccs_20/batch/pb_tnc_batch.c @@ -141,9 +141,7 @@ METHOD(pb_tnc_batch_t, get_encoding, chunk_t, METHOD(pb_tnc_batch_t, add_msg, bool, private_pb_tnc_batch_t *this, pb_tnc_msg_t* msg) { - enum_name_t *msg_type_names; chunk_t msg_value; - pen_type_t msg_type; size_t msg_len; msg->build(msg); @@ -157,7 +155,10 @@ METHOD(pb_tnc_batch_t, add_msg, bool, } this->batch_len += msg_len; - msg_type = msg->get_type(msg); +#if DEBUG_LEVEL >= 2 + pen_type_t msg_type = msg->get_type(msg); + enum_name_t *msg_type_names; + switch (msg_type.vendor_id) { default: @@ -173,6 +174,7 @@ METHOD(pb_tnc_batch_t, add_msg, bool, } DBG2(DBG_TNC, "adding %N/%N message", pen_names, msg_type.vendor_id, msg_type_names, msg_type.type); +#endif this->messages->insert_last(this->messages, msg); return TRUE; } @@ -329,7 +331,7 @@ static status_t process_tnc_msg(private_pb_tnc_batch_t *this) uint32_t vendor_id, msg_type, msg_len, offset; chunk_t data, msg_value; bool noskip_flag; - enum_name_t *msg_type_names; + enum_name_t *msg_type_names DBG_UNUSED; pen_type_t msg_pen_type; status_t status; diff --git a/src/libtnccs/plugins/tnccs_20/tnccs_20_client.c b/src/libtnccs/plugins/tnccs_20/tnccs_20_client.c index 1807d82f9..0e31e729d 100644 --- a/src/libtnccs/plugins/tnccs_20/tnccs_20_client.c +++ b/src/libtnccs/plugins/tnccs_20/tnccs_20_client.c @@ -274,6 +274,7 @@ static void handle_ietf_message(private_tnccs_20_client_t *this, pb_tnc_msg_t *m } case PB_MSG_ASSESSMENT_RESULT: { +#if DEBUG_LEVEL >= 1 pb_assessment_result_msg_t *assess_msg; uint32_t result; @@ -281,6 +282,7 @@ static void handle_ietf_message(private_tnccs_20_client_t *this, pb_tnc_msg_t *m result = assess_msg->get_assessment_result(assess_msg); DBG1(DBG_TNC, "PB-TNC assessment result is '%N'", TNC_IMV_Evaluation_Result_names, result); +#endif break; } case PB_MSG_ACCESS_RECOMMENDATION: @@ -312,7 +314,7 @@ static void handle_ietf_message(private_tnccs_20_client_t *this, pb_tnc_msg_t *m { pb_remediation_parameters_msg_t *rem_msg; pen_type_t parameters_type; - chunk_t parameters, string, lang_code; + chunk_t parameters DBG_UNUSED, string DBG_UNUSED, lang_code; rem_msg = (pb_remediation_parameters_msg_t*)msg; parameters_type = rem_msg->get_parameters_type(rem_msg); @@ -347,6 +349,7 @@ static void handle_ietf_message(private_tnccs_20_client_t *this, pb_tnc_msg_t *m break; case PB_MSG_REASON_STRING: { +#if DEBUG_LEVEL >= 1 pb_reason_string_msg_t *reason_msg; chunk_t reason_string, language_code; @@ -356,6 +359,7 @@ static void handle_ietf_message(private_tnccs_20_client_t *this, pb_tnc_msg_t *m DBG1(DBG_TNC, "reason string is '%.*s' [%.*s]", (int)reason_string.len, reason_string.ptr, (int)language_code.len, language_code.ptr); +#endif break; } default: From 522bd965d134292462af5f595a03283f2229c4e8 Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Tue, 2 May 2023 11:16:22 +0200 Subject: [PATCH 21/53] libtpmtss: Fix build with DEBUG_LEVEL < 2 --- src/libtpmtss/tpm_tss_trousers.c | 7 ++++--- src/libtpmtss/tpm_tss_tss2_session.c | 11 +++++------ src/libtpmtss/tpm_tss_tss2_v2.c | 3 +++ 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/libtpmtss/tpm_tss_trousers.c b/src/libtpmtss/tpm_tss_trousers.c index 50401e853..8c3541eb4 100644 --- a/src/libtpmtss/tpm_tss_trousers.c +++ b/src/libtpmtss/tpm_tss_trousers.c @@ -124,7 +124,6 @@ static bool initialize_context(private_tpm_tss_trousers_t *this) uint32_t version_len; TSS_RESULT result; - TPM_CAP_VERSION_INFO *info; result = Tspi_Context_Create(&this->hContext); if (result != TSS_SUCCESS) @@ -159,12 +158,14 @@ static bool initialize_context(private_tpm_tss_trousers_t *this) return FALSE; } - info = (TPM_CAP_VERSION_INFO *)version_ptr; +#if DEBUG_LEVEL > 2 + TPM_CAP_VERSION_INFO *info = (TPM_CAP_VERSION_INFO *)version_ptr; DBG2(DBG_PTS, "TPM Version Info: Chip Version: %u.%u.%u.%u, " "Spec Level: %u, Errata Rev: %u, Vendor ID: %.4s", info->version.major, info->version.minor, info->version.revMajor, info->version.revMinor, untoh16(&info->specLevel), info->errataRev, info->tpmVendorID); +#endif this->version_info = chunk_clone(chunk_create(version_ptr, version_len)); @@ -466,7 +467,7 @@ METHOD(tpm_tss_t, quote, bool, uint32_t version_info_size, pcr; aik_t *aik; chunk_t aik_blob = chunk_empty; - chunk_t quote_chunk, pcr_digest; + chunk_t quote_chunk DBG_UNUSED, pcr_digest; enumerator_t *enumerator; bool success = FALSE; diff --git a/src/libtpmtss/tpm_tss_tss2_session.c b/src/libtpmtss/tpm_tss_tss2_session.c index 3a7ce29b0..a62b14854 100644 --- a/src/libtpmtss/tpm_tss_tss2_session.c +++ b/src/libtpmtss/tpm_tss_tss2_session.c @@ -133,7 +133,7 @@ METHOD(tpm_tss_tss2_session_t, set_cmd_auths, bool, hasher_t *hasher; pseudo_random_function_t prf_alg; prf_t *prf; - chunk_t data, cp_hash, cp_hmac, nonce_caller, nonce_tpm, session_attributes; + chunk_t data, cp_hash, nonce_caller, nonce_tpm, session_attributes; bool success; uint32_t rval; @@ -233,8 +233,8 @@ METHOD(tpm_tss_tss2_session_t, set_cmd_auths, bool, DBG1(DBG_PTS, "cpHmac computation failed"); return FALSE; } - cp_hmac = chunk_create(cmd.auths[0].hmac.buffer, cmd.auths[0].hmac.size); - DBG2(DBG_PTS, LABEL "cpHmac: %B", &cp_hmac); + DBG2(DBG_PTS, LABEL "cpHmac: %b", cmd.auths[0].hmac.buffer, + cmd.auths[0].hmac.size); rval = Tss2_Sys_SetCmdAuths(this->sys_context, &cmd); if (rval != TSS2_RC_SUCCESS) @@ -319,7 +319,7 @@ METHOD(tpm_tss_tss2_session_t, get_rsp_auths, bool, prf_t *prf; crypter_t *crypter; chunk_t kdf_label = chunk_from_chars('C','F','B', 0x00); - chunk_t data, rp_hash, rp_hmac, nonce_caller, nonce_tpm, session_attributes; + chunk_t data, rp_hash, nonce_caller, nonce_tpm, session_attributes; chunk_t key_mat, aes_key, aes_iv; bool success; uint32_t rval; @@ -410,8 +410,7 @@ METHOD(tpm_tss_tss2_session_t, get_rsp_auths, bool, DBG1(DBG_PTS, "computation of rpHmac failed"); return FALSE; } - rp_hmac = chunk_create(rpHmac.buffer, rpHmac.size); - DBG2(DBG_PTS, LABEL "rpHMAC: %B", &rp_hmac); + DBG2(DBG_PTS, LABEL "rpHMAC: %b", rpHmac.buffer, rpHmac.size); /* verify rpHmac */ if (!memeq(rsp.auths[0].hmac.buffer, rpHmac.buffer, rpHmac.size)) diff --git a/src/libtpmtss/tpm_tss_tss2_v2.c b/src/libtpmtss/tpm_tss_tss2_v2.c index ef56a16eb..6deefe910 100644 --- a/src/libtpmtss/tpm_tss_tss2_v2.c +++ b/src/libtpmtss/tpm_tss_tss2_v2.c @@ -664,6 +664,8 @@ METHOD(tpm_tss_t, get_public, chunk_t, DBG1(DBG_PTS, LABEL "unsupported key type"); return chunk_empty; } + +#if DEBUG_LEVEL >= 1 if (public.publicArea.objectAttributes & TPMA_OBJECT_SIGN_ENCRYPT) { TPMT_ASYM_SCHEME *s; @@ -682,6 +684,7 @@ METHOD(tpm_tss_t, get_public, chunk_t, tpm_alg_id_names, s->algorithm, tpm_alg_id_names, s->mode, s->keyBits.sym); } +#endif return aik_pubkey; } From 0841280cdde884617f5ef40470057633a44d3a1f Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Tue, 2 May 2023 14:11:44 +0200 Subject: [PATCH 22/53] libimcv: Fix build with DEBUG_LEVEL < 3 --- src/libimcv/generic/generic_attr_bool.c | 2 +- src/libimcv/generic/generic_attr_chunk.c | 2 +- src/libimcv/generic/generic_attr_string.c | 2 +- src/libimcv/imc/imc_agent.c | 2 +- src/libimcv/imc/imc_msg.c | 7 ++- src/libimcv/imv/imv_agent.c | 2 +- src/libimcv/imv/imv_msg.c | 5 +- src/libimcv/imv/imv_session_manager.c | 4 +- src/libimcv/pa_tnc/pa_tnc_msg.c | 11 ++-- .../plugins/imc_attestation/imc_attestation.c | 7 +-- src/libimcv/plugins/imc_swima/imc_swima.c | 2 +- src/libimcv/plugins/imc_test/imc_test.c | 12 ++-- .../imv_attestation/imv_attestation_agent.c | 7 +-- .../imv_attestation/imv_attestation_process.c | 4 +- src/libimcv/plugins/imv_hcd/imv_hcd_agent.c | 46 ++++++++------- src/libimcv/plugins/imv_os/imv_os_agent.c | 15 ++--- .../plugins/imv_swima/imv_swima_agent.c | 2 +- .../plugins/imv_swima/imv_swima_state.c | 2 +- src/libimcv/plugins/imv_test/imv_test_agent.c | 6 +- src/libimcv/pts/components/ita/ita_comp_ima.c | 2 +- .../pts/components/ita/ita_comp_tboot.c | 10 ++-- .../pts/components/pts_comp_func_name.c | 2 +- src/libimcv/pts/pts.c | 9 +-- src/libimcv/pts/pts_dh_group.c | 57 +++++++++---------- src/libimcv/pts/pts_ima_bios_list.c | 14 ++--- src/libimcv/pts/pts_ima_event_list.c | 2 +- src/libimcv/pts/pts_meas_algo.c | 57 ++++++++++--------- src/libimcv/suites/test_imcv_swima.c | 4 +- 28 files changed, 153 insertions(+), 144 deletions(-) diff --git a/src/libimcv/generic/generic_attr_bool.c b/src/libimcv/generic/generic_attr_bool.c index 3469ae855..d024f98e9 100644 --- a/src/libimcv/generic/generic_attr_bool.c +++ b/src/libimcv/generic/generic_attr_bool.c @@ -121,7 +121,7 @@ METHOD(pa_tnc_attr_t, build, void, METHOD(pa_tnc_attr_t, process, status_t, private_generic_attr_bool_t *this, uint32_t *offset) { - enum_name_t *pa_attr_names; + enum_name_t *pa_attr_names DBG_UNUSED; bio_reader_t *reader; uint32_t status; diff --git a/src/libimcv/generic/generic_attr_chunk.c b/src/libimcv/generic/generic_attr_chunk.c index e0c9f9135..699e4173f 100644 --- a/src/libimcv/generic/generic_attr_chunk.c +++ b/src/libimcv/generic/generic_attr_chunk.c @@ -96,7 +96,7 @@ METHOD(pa_tnc_attr_t, build, void, METHOD(pa_tnc_attr_t, process, status_t, private_generic_attr_chunk_t *this, uint32_t *offset) { - enum_name_t *pa_attr_names; + enum_name_t *pa_attr_names DBG_UNUSED; *offset = 0; if (this->value.len < this->length) diff --git a/src/libimcv/generic/generic_attr_string.c b/src/libimcv/generic/generic_attr_string.c index 75d3fc4d5..c00c4636c 100644 --- a/src/libimcv/generic/generic_attr_string.c +++ b/src/libimcv/generic/generic_attr_string.c @@ -91,7 +91,7 @@ METHOD(pa_tnc_attr_t, build, void, METHOD(pa_tnc_attr_t, process, status_t, private_generic_attr_string_t *this, uint32_t *offset) { - enum_name_t *pa_attr_names; + enum_name_t *pa_attr_names DBG_UNUSED; u_char *pos; *offset = 0; diff --git a/src/libimcv/imc/imc_agent.c b/src/libimcv/imc/imc_agent.c index 0b3428574..f3aa21f9f 100644 --- a/src/libimcv/imc/imc_agent.c +++ b/src/libimcv/imc/imc_agent.c @@ -346,7 +346,7 @@ METHOD(imc_agent_t, create_state, TNC_Result, { TNC_ConnectionID conn_id; char *tnccs_p = NULL, *tnccs_v = NULL, *t_p = NULL, *t_v = NULL; - bool has_long = FALSE, has_excl = FALSE, has_soh = FALSE; + bool has_long = FALSE, has_excl = FALSE, has_soh DBG_UNUSED = FALSE; uint32_t max_msg_len; conn_id = state->get_connection_id(state); diff --git a/src/libimcv/imc/imc_msg.c b/src/libimcv/imc/imc_msg.c index 44338d70a..2abc2cb2c 100644 --- a/src/libimcv/imc/imc_msg.c +++ b/src/libimcv/imc/imc_msg.c @@ -254,7 +254,6 @@ METHOD(imc_msg_t, receive, TNC_Result, enumerator_t *enumerator; pa_tnc_attr_t *attr; pen_type_t attr_type; - chunk_t msg; bool first = TRUE; if (this->state->has_long(this->state)) @@ -282,8 +281,10 @@ METHOD(imc_msg_t, receive, TNC_Result, this->agent->get_name(this->agent), this->connection_id); } - msg = this->pa_msg->get_encoding(this->pa_msg); +#if DEBUG_LEVEL >= 3 + chunk_t msg = this->pa_msg->get_encoding(this->pa_msg); DBG3(DBG_IMC, "%B", &msg); +#endif switch (this->pa_msg->process(this->pa_msg)) { @@ -522,7 +523,7 @@ METHOD(imc_msg_t, receive, TNC_Result, { ietf_attr_remediation_instr_t *attr_cast; pen_type_t parameters_type; - chunk_t parameters, string, lang_code; + chunk_t parameters DBG_UNUSED, string DBG_UNUSED, lang_code; attr_cast = (ietf_attr_remediation_instr_t*)attr; parameters_type = attr_cast->get_parameters_type(attr_cast); diff --git a/src/libimcv/imv/imv_agent.c b/src/libimcv/imv/imv_agent.c index 6631c5d1f..cf0496090 100644 --- a/src/libimcv/imv/imv_agent.c +++ b/src/libimcv/imv/imv_agent.c @@ -413,7 +413,7 @@ METHOD(imv_agent_t, create_state, TNC_Result, { TNC_ConnectionID conn_id; char *tnccs_p = NULL, *tnccs_v = NULL, *t_p = NULL, *t_v = NULL; - bool has_long = FALSE, has_excl = FALSE, has_soh = FALSE; + bool has_long = FALSE, has_excl = FALSE, has_soh DBG_UNUSED = FALSE; linked_list_t *ar_identities; imv_session_t *session; uint32_t max_msg_len; diff --git a/src/libimcv/imv/imv_msg.c b/src/libimcv/imv/imv_msg.c index 73ac2008e..a1de80849 100644 --- a/src/libimcv/imv/imv_msg.c +++ b/src/libimcv/imv/imv_msg.c @@ -293,7 +293,6 @@ METHOD(imv_msg_t, receive, TNC_Result, linked_list_t *non_fatal_types; enumerator_t *enumerator; pa_tnc_attr_t *attr; - chunk_t msg; if (this->state->has_long(this->state)) { @@ -320,8 +319,10 @@ METHOD(imv_msg_t, receive, TNC_Result, this->agent->get_name(this->agent), this->connection_id); } - msg = this->pa_msg->get_encoding(this->pa_msg); +#if DEBUG_LEVEL >= 3 + chunk_t msg = this->pa_msg->get_encoding(this->pa_msg); DBG3(DBG_IMV, "%B", &msg); +#endif switch (this->pa_msg->process(this->pa_msg)) { diff --git a/src/libimcv/imv/imv_session_manager.c b/src/libimcv/imv/imv_session_manager.c index 9f2ce8df5..4d8216d23 100644 --- a/src/libimcv/imv/imv_session_manager.c +++ b/src/libimcv/imv/imv_session_manager.c @@ -50,7 +50,6 @@ METHOD(imv_session_manager_t, add_session, imv_session_t*, linked_list_t *ar_identities) { enumerator_t *enumerator; - tncif_identity_t *tnc_id; imv_session_t *current, *session = NULL; this->mutex->lock(this->mutex); @@ -77,6 +76,8 @@ METHOD(imv_session_manager_t, add_session, imv_session_t*, } /* Output list of Access Requestor identities */ +#if DEBUG_LEVEL >= 2 + tncif_identity_t *tnc_id; enumerator = ar_identities->create_enumerator(ar_identities); while (enumerator->enumerate(enumerator, &tnc_id)) { @@ -103,6 +104,7 @@ METHOD(imv_session_manager_t, add_session, imv_session_t*, TNC_Authentication_names, tcg_auth_type); } enumerator->destroy(enumerator); +#endif /* DEBUG_LEVEL */ /* create a new session entry */ session = imv_session_create(conn_id, ar_identities); diff --git a/src/libimcv/pa_tnc/pa_tnc_msg.c b/src/libimcv/pa_tnc/pa_tnc_msg.c index 963be7c98..9560e6f12 100644 --- a/src/libimcv/pa_tnc/pa_tnc_msg.c +++ b/src/libimcv/pa_tnc/pa_tnc_msg.c @@ -277,13 +277,10 @@ METHOD(pa_tnc_msg_t, process_ietf_std_errors, bool, { ietf_attr_pa_tnc_error_t *error_attr; pen_type_t error_code, *non_fatal_type; - chunk_t msg_info; - uint32_t offset; bool fatal_current_error = TRUE; error_attr = (ietf_attr_pa_tnc_error_t*)attr; error_code = error_attr->get_error_code(error_attr); - msg_info = error_attr->get_msg_info(error_attr); /* skip errors from non-IETF namespaces and non PA-TNC msg errors */ if (error_code.vendor_id != PEN_IETF || @@ -291,15 +288,17 @@ METHOD(pa_tnc_msg_t, process_ietf_std_errors, bool, { continue; } +#if DEBUG_LEVEL >= 1 + chunk_t msg_info = error_attr->get_msg_info(error_attr); DBG1(DBG_TNC, "received PA-TNC error '%N' concerning message " "0x%08x/0x%08x", pa_tnc_error_code_names, error_code.type, untoh32(msg_info.ptr), untoh32(msg_info.ptr + 4)); - +#endif switch (error_code.type) { case PA_ERROR_INVALID_PARAMETER: - offset = error_attr->get_offset(error_attr); - DBG1(DBG_TNC, " occurred at offset of %u bytes", offset); + DBG1(DBG_TNC, " occurred at offset of %u bytes", + error_attr->get_offset(error_attr)); break; case PA_ERROR_ATTR_TYPE_NOT_SUPPORTED: unsupported_type = diff --git a/src/libimcv/plugins/imc_attestation/imc_attestation.c b/src/libimcv/plugins/imc_attestation/imc_attestation.c index 308fa1e67..abdf27f7f 100644 --- a/src/libimcv/plugins/imc_attestation/imc_attestation.c +++ b/src/libimcv/plugins/imc_attestation/imc_attestation.c @@ -174,19 +174,18 @@ static TNC_Result receive_message(imc_state_t *state, imc_msg_t *in_msg) { ietf_attr_pa_tnc_error_t *error_attr; pen_type_t error_code; - chunk_t msg_info; error_attr = (ietf_attr_pa_tnc_error_t*)attr; error_code = error_attr->get_error_code(error_attr); if (error_code.vendor_id == PEN_TCG) { - msg_info = error_attr->get_msg_info(error_attr); - +#if DEBUG_LEVEL >= 1 + chunk_t msg_info = error_attr->get_msg_info(error_attr); DBG1(DBG_IMC, "received TCG-PTS error '%N'", pts_error_code_names, error_code.type); DBG1(DBG_IMC, "error information: %B", &msg_info); - +#endif /* DEBUG_LEVEL */ result = TNC_RESULT_FATAL; } } diff --git a/src/libimcv/plugins/imc_swima/imc_swima.c b/src/libimcv/plugins/imc_swima/imc_swima.c index 0cd407833..3c9b336d0 100644 --- a/src/libimcv/plugins/imc_swima/imc_swima.c +++ b/src/libimcv/plugins/imc_swima/imc_swima.c @@ -229,7 +229,7 @@ static void fulfill_request(imc_state_t *state, imc_msg_t *msg, size_t msg_len = 64; char error_msg[msg_len], *id_str; bool collect_inventory = TRUE; - int items; + int items DBG_UNUSED; collector = swima_collector_create(); id_str = sw_id_only ? " ID" : ""; diff --git a/src/libimcv/plugins/imc_test/imc_test.c b/src/libimcv/plugins/imc_test/imc_test.c index 4bd1d1c5b..e50d4e83d 100644 --- a/src/libimcv/plugins/imc_test/imc_test.c +++ b/src/libimcv/plugins/imc_test/imc_test.c @@ -293,19 +293,19 @@ static TNC_Result receive_message(imc_state_t *state, imc_msg_t *in_msg) } if (attr_type.type == ITA_ATTR_COMMAND) { - ita_attr_command_t *ita_attr; - - ita_attr = (ita_attr_command_t*)attr; +#if DEBUG_LEVEL >= 1 + ita_attr_command_t *ita_attr = (ita_attr_command_t*)attr; DBG1(DBG_IMC, "received command '%s'", ita_attr->get_command(ita_attr)); +#endif } else if (attr_type.type == ITA_ATTR_DUMMY) { - ita_attr_dummy_t *ita_attr; - - ita_attr = (ita_attr_dummy_t*)attr; +#if DEBUG_LEVEL >= 1 + ita_attr_dummy_t *ita_attr = (ita_attr_dummy_t*)attr; DBG1(DBG_IMC, "received dummy attribute value (%d bytes)", ita_attr->get_size(ita_attr)); +#endif } } enumerator->destroy(enumerator); diff --git a/src/libimcv/plugins/imv_attestation/imv_attestation_agent.c b/src/libimcv/plugins/imv_attestation/imv_attestation_agent.c index 5d0444f44..2e92b8379 100644 --- a/src/libimcv/plugins/imv_attestation/imv_attestation_agent.c +++ b/src/libimcv/plugins/imv_attestation/imv_attestation_agent.c @@ -206,19 +206,18 @@ static TNC_Result receive_msg(private_imv_attestation_agent_t *this, { ietf_attr_pa_tnc_error_t *error_attr; pen_type_t error_code; - chunk_t msg_info; error_attr = (ietf_attr_pa_tnc_error_t*)attr; error_code = error_attr->get_error_code(error_attr); if (error_code.vendor_id == PEN_TCG) { - msg_info = error_attr->get_msg_info(error_attr); - +#if DEBUG_LEVEL >= 1 + chunk_t msg_info = error_attr->get_msg_info(error_attr); DBG1(DBG_IMV, "received TCG-PTS error '%N'", pts_error_code_names, error_code.type); DBG1(DBG_IMV, "error information: %B", &msg_info); - +#endif /* DEBUG_LEVEL */ /* TPM 2.0 doesn't return TPM Version Information */ if (error_code.type != TCG_PTS_TPM_VERS_NOT_SUPPORTED) { diff --git a/src/libimcv/plugins/imv_attestation/imv_attestation_process.c b/src/libimcv/plugins/imv_attestation/imv_attestation_process.c index 6c15aa3e8..cfef7de91 100644 --- a/src/libimcv/plugins/imv_attestation/imv_attestation_process.c +++ b/src/libimcv/plugins/imv_attestation/imv_attestation_process.c @@ -228,7 +228,7 @@ bool imv_attestation_process(pa_tnc_attr_t *attr, imv_msg_t *out_msg, TNC_IMV_Action_Recommendation rec; tcg_pts_attr_file_meas_t *attr_cast; uint16_t request_id; - int arg_int, file_count; + int arg_int, file_count DBG_UNUSED; pts_meas_algorithms_t algo; pts_file_meas_t *measurements; imv_workitem_t *workitem, *found = NULL; @@ -364,6 +364,7 @@ bool imv_attestation_process(pa_tnc_attr_t *attr, imv_msg_t *out_msg, } case TCG_PTS_UNIX_FILE_META: { +#if DEBUG_LEVEL >= 1 tcg_pts_attr_file_meta_t *attr_cast; int file_count; pts_file_meta_t *metadata; @@ -395,6 +396,7 @@ bool imv_attestation_process(pa_tnc_attr_t *attr, imv_msg_t *out_msg, &created, utc, &modified, utc, &accessed, utc); } e->destroy(e); +#endif /* DEBUG_LEVEL */ break; } case TCG_PTS_SIMPLE_COMP_EVID: diff --git a/src/libimcv/plugins/imv_hcd/imv_hcd_agent.c b/src/libimcv/plugins/imv_hcd/imv_hcd_agent.c index 1f6035d1e..612c5e53b 100644 --- a/src/libimcv/plugins/imv_hcd/imv_hcd_agent.c +++ b/src/libimcv/plugins/imv_hcd/imv_hcd_agent.c @@ -175,7 +175,7 @@ static TNC_Result receive_msg(private_imv_hcd_agent_t *this, imv_state_t *state, imv_msg_t *out_msg; imv_hcd_state_t *hcd_state; pa_tnc_attr_t *attr; - enum_name_t *pa_subtype_names; + enum_name_t *pa_subtype_names DBG_UNUSED; pen_type_t type, msg_type; TNC_Result result; bool fatal_error = FALSE, assessment = FALSE; @@ -220,6 +220,7 @@ static TNC_Result receive_msg(private_imv_hcd_agent_t *this, imv_state_t *state, { case IETF_ATTR_FORWARDING_ENABLED: { +#if DEBUG_LEVEL >= 2 ietf_attr_fwd_enabled_t *attr_cast; os_fwd_status_t fwd_status; @@ -227,12 +228,14 @@ static TNC_Result receive_msg(private_imv_hcd_agent_t *this, imv_state_t *state, fwd_status = attr_cast->get_status(attr_cast); DBG2(DBG_IMV, " %N: %N", ietf_attr_names, type.type, os_fwd_status_names, fwd_status); +#endif /* DEBUG_LEVEL */ state->set_action_flags(state, IMV_HCD_ATTR_FORWARDING_ENABLED); break; } case IETF_ATTR_FACTORY_DEFAULT_PWD_ENABLED: { +#if DEBUG_LEVEL >= 2 generic_attr_bool_t *attr_cast; bool status; @@ -240,6 +243,7 @@ static TNC_Result receive_msg(private_imv_hcd_agent_t *this, imv_state_t *state, status = attr_cast->get_status(attr_cast); DBG2(DBG_IMV, " %N: %s", ietf_attr_names, type.type, status ? "yes" : "no"); +#endif /* DEBUG_LEVEL */ state->set_action_flags(state, IMV_HCD_ATTR_DEFAULT_PWD_ENABLED); break; @@ -265,49 +269,47 @@ static TNC_Result receive_msg(private_imv_hcd_agent_t *this, imv_state_t *state, case PWG_HCD_USER_APP_NAME: case PWG_HCD_USER_APP_STRING_VERSION: { - chunk_t value; - - value = attr->get_value(attr); +#if DEBUG_LEVEL >= 2 + chunk_t value = attr->get_value(attr); DBG2(DBG_IMV, " %N: %.*s", pwg_attr_names, type.type, - value.len, value.ptr); + (int)value.len, value.ptr); +#endif /* DEBUG_LEVEL */ break; } case PWG_HCD_FIRMWARE_PATCHES: case PWG_HCD_RESIDENT_APP_PATCHES: case PWG_HCD_USER_APP_PATCHES: { - chunk_t value; - size_t len; - - value = attr->get_value(attr); - len = value.len; +#if DEBUG_LEVEL >= 2 + chunk_t value = attr->get_value(attr); /* remove any trailing LF from patches string */ - if (len && (value.ptr[len - 1] == '\n')) + if (value.len && (value.ptr[value.len - 1] == '\n')) { - len--; + value.len--; } DBG2(DBG_IMV, " %N:%s%.*s", pwg_attr_names, type.type, - len ? "\n" : " ", len, value.ptr); + value.len ? "\n" : " ", (int)value.len, value.ptr); +#endif /* DEBUG_LEVEL */ break; } case PWG_HCD_FIRMWARE_VERSION: case PWG_HCD_RESIDENT_APP_VERSION: case PWG_HCD_USER_APP_VERSION: { - chunk_t value; - - value = attr->get_value(attr); +#if DEBUG_LEVEL >= 2 + chunk_t value = attr->get_value(attr); DBG2(DBG_IMV, " %N: %#B", pwg_attr_names, type.type, &value); +#endif /* DEBUG_LEVEL */ break; } case PWG_HCD_CERTIFICATION_STATE: case PWG_HCD_CONFIGURATION_STATE: { - chunk_t value; - - value = attr->get_value(attr); +#if DEBUG_LEVEL >= 2 + chunk_t value = attr->get_value(attr); DBG2(DBG_IMV, " %N: %B", pwg_attr_names, type.type, &value); +#endif /* DEBUG_LEVEL */ break; } case PWG_HCD_DEFAULT_PWD_ENABLED: @@ -332,6 +334,7 @@ static TNC_Result receive_msg(private_imv_hcd_agent_t *this, imv_state_t *state, } case PWG_HCD_FORWARDING_ENABLED: { +#if DEBUG_LEVEL >= 2 ietf_attr_fwd_enabled_t *attr_cast; os_fwd_status_t fwd_status; @@ -339,11 +342,13 @@ static TNC_Result receive_msg(private_imv_hcd_agent_t *this, imv_state_t *state, fwd_status = attr_cast->get_status(attr_cast); DBG2(DBG_IMV, " %N: %N", pwg_attr_names, type.type, os_fwd_status_names, fwd_status); +#endif /* DEBUG_LEVEL */ break; } case PWG_HCD_VENDOR_SMI_CODE: { +#if DEBUG_LEVEL >= 2 pwg_attr_vendor_smi_code_t *attr_cast; uint32_t smi_code; @@ -351,6 +356,7 @@ static TNC_Result receive_msg(private_imv_hcd_agent_t *this, imv_state_t *state, smi_code = attr_cast->get_vendor_smi_code(attr_cast); DBG2(DBG_IMV, " %N: 0x%06x (%u)", pwg_attr_names, type.type, smi_code, smi_code); +#endif /* DEBUG_LEVEL */ break; } default: @@ -590,7 +596,7 @@ METHOD(imv_agent_if_t, solicit_recommendation, TNC_Result, imv_state_t *state; imv_hcd_state_t* hcd_state; imv_hcd_handshake_state_t handshake_state; - enum_name_t *pa_subtype_names; + enum_name_t *pa_subtype_names DBG_UNUSED; bool missing = FALSE; uint32_t received; int i; diff --git a/src/libimcv/plugins/imv_os/imv_os_agent.c b/src/libimcv/plugins/imv_os/imv_os_agent.c index 0ddda2792..413863204 100644 --- a/src/libimcv/plugins/imv_os/imv_os_agent.c +++ b/src/libimcv/plugins/imv_os/imv_os_agent.c @@ -250,20 +250,17 @@ static TNC_Result receive_msg(private_imv_os_agent_t *this, imv_state_t *state, } case IETF_ATTR_OPERATIONAL_STATUS: { - ietf_attr_op_status_t *attr_cast; - op_status_t op_status; - op_result_t op_result; - time_t last_boot; - state->set_action_flags(state, IMV_OS_ATTR_OPERATIONAL_STATUS); - attr_cast = (ietf_attr_op_status_t*)attr; - op_status = attr_cast->get_status(attr_cast); - op_result = attr_cast->get_result(attr_cast); - last_boot = attr_cast->get_last_use(attr_cast); +#if DEBUG_LEVEL >= 1 + ietf_attr_op_status_t *attr_cast = (ietf_attr_op_status_t*)attr; + op_status_t op_status = attr_cast->get_status(attr_cast); + op_result_t op_result = attr_cast->get_result(attr_cast); + time_t last_boot = attr_cast->get_last_use(attr_cast); DBG1(DBG_IMV, "operational status: %N, result: %N", op_status_names, op_status, op_result_names, op_result); DBG1(DBG_IMV, "last boot: %T", &last_boot, TRUE); +#endif /* DEBUG_LEVEL */ break; } case IETF_ATTR_FORWARDING_ENABLED: diff --git a/src/libimcv/plugins/imv_swima/imv_swima_agent.c b/src/libimcv/plugins/imv_swima/imv_swima_agent.c index a6e6dd126..3bb8aca4a 100644 --- a/src/libimcv/plugins/imv_swima/imv_swima_agent.c +++ b/src/libimcv/plugins/imv_swima/imv_swima_agent.c @@ -134,7 +134,7 @@ static TNC_Result receive_msg(private_imv_swima_agent_t *this, enumerator = in_msg->create_attribute_enumerator(in_msg); while (enumerator->enumerate(enumerator, &attr)) { - uint32_t request_id = 0, last_eid, eid_epoch; + uint32_t request_id = 0, last_eid DBG_UNUSED, eid_epoch; swima_inventory_t *inventory; swima_events_t *events; pen_type_t type; diff --git a/src/libimcv/plugins/imv_swima/imv_swima_state.c b/src/libimcv/plugins/imv_swima/imv_swima_state.c index c6116706b..9695e46a2 100644 --- a/src/libimcv/plugins/imv_swima/imv_swima_state.c +++ b/src/libimcv/plugins/imv_swima/imv_swima_state.c @@ -312,7 +312,7 @@ METHOD(imv_swima_state_t, set_inventory, void, private_imv_swima_state_t *this, swima_inventory_t *inventory) { chunk_t sw_id, sw_locator; - uint32_t record_id; + uint32_t record_id DBG_UNUSED; char *sw_id_str; json_object *jstring; swima_record_t *sw_record; diff --git a/src/libimcv/plugins/imv_test/imv_test_agent.c b/src/libimcv/plugins/imv_test/imv_test_agent.c index 1fe6cab37..27f111e80 100644 --- a/src/libimcv/plugins/imv_test/imv_test_agent.c +++ b/src/libimcv/plugins/imv_test/imv_test_agent.c @@ -163,11 +163,11 @@ static TNC_Result receive_msg(private_imv_test_agent_t *this, imv_state_t *state } else if (attr_type.type == ITA_ATTR_DUMMY) { - ita_attr_dummy_t *ita_attr; - - ita_attr = (ita_attr_dummy_t*)attr; +#if DEBUG_LEVEL >= 1 + ita_attr_dummy_t *ita_attr = (ita_attr_dummy_t*)attr; DBG1(DBG_IMV, "received dummy attribute value (%d bytes)", ita_attr->get_size(ita_attr)); +#endif } } enumerator->destroy(enumerator); diff --git a/src/libimcv/pts/components/ita/ita_comp_ima.c b/src/libimcv/pts/components/ita/ita_comp_ima.c index 08d91c432..9031cda53 100644 --- a/src/libimcv/pts/components/ita/ita_comp_ima.c +++ b/src/libimcv/pts/components/ita/ita_comp_ima.c @@ -964,7 +964,7 @@ METHOD(pts_component_t, get_ref, pts_component_t*, METHOD(pts_component_t, destroy, void, pts_ita_comp_ima_t *this) { - int count; + int count DBG_UNUSED; if (ref_put(&this->ref)) { diff --git a/src/libimcv/pts/components/ita/ita_comp_tboot.c b/src/libimcv/pts/components/ita/ita_comp_tboot.c index 3849ff2a6..f40189d2e 100644 --- a/src/libimcv/pts/components/ita/ita_comp_tboot.c +++ b/src/libimcv/pts/components/ita/ita_comp_tboot.c @@ -192,8 +192,8 @@ METHOD(pts_component_t, verify, status_t, pts_comp_evidence_t *evidence) { bool has_pcr_info; - uint32_t extended_pcr, vid, name; - enum_name_t *names; + uint32_t extended_pcr, vid, name DBG_UNUSED; + enum_name_t *names DBG_UNUSED; pts_meas_algorithms_t algo; pts_pcr_transform_t transform; pts_pcr_t *pcrs; @@ -312,9 +312,9 @@ METHOD(pts_component_t, get_ref, pts_component_t*, METHOD(pts_component_t, destroy, void, pts_ita_comp_tboot_t *this) { - int count; - uint32_t vid, name; - enum_name_t *names; + int count DBG_UNUSED; + uint32_t vid, name DBG_UNUSED; + enum_name_t *names DBG_UNUSED; if (ref_put(&this->ref)) { diff --git a/src/libimcv/pts/components/pts_comp_func_name.c b/src/libimcv/pts/components/pts_comp_func_name.c index 00bd0af17..f66e0eada 100644 --- a/src/libimcv/pts/components/pts_comp_func_name.c +++ b/src/libimcv/pts/components/pts_comp_func_name.c @@ -107,7 +107,7 @@ METHOD(pts_comp_func_name_t, log_, void, { enum_name_t *names, *types; char flags[8]; - int type; + int type DBG_UNUSED; names = imcv_pts_components->get_comp_func_names(imcv_pts_components, this->vid); diff --git a/src/libimcv/pts/pts.c b/src/libimcv/pts/pts.c index 742e45b5a..104f88565 100644 --- a/src/libimcv/pts/pts.c +++ b/src/libimcv/pts/pts.c @@ -798,7 +798,6 @@ METHOD(pts_t, quote, bool, private_pts_t *this, tpm_quote_mode_t *quote_mode, tpm_tss_quote_info_t **quote_info, chunk_t *quote_sig) { - chunk_t pcr_value, pcr_computed; hash_algorithm_t hash_alg; uint32_t pcr, pcr_sel = 0; enumerator_t *enumerator; @@ -810,14 +809,16 @@ METHOD(pts_t, quote, bool, enumerator = this->pcrs->create_enumerator(this->pcrs); while (enumerator->enumerate(enumerator, &pcr)) { +#if DEBUG_LEVEL >= 2 + chunk_t pcr_value; if (this->tpm->read_pcr(this->tpm, pcr, &pcr_value, hash_alg)) { - pcr_computed = this->pcrs->get(this->pcrs, pcr); + chunk_t pcr_computed = this->pcrs->get(this->pcrs, pcr); DBG2(DBG_PTS, "PCR %2d %#B %s", pcr, &pcr_value, chunk_equals(pcr_value, pcr_computed) ? "ok" : "differs"); chunk_free(&pcr_value); - }; - + } +#endif /* add PCR to selection list */ pcr_sel |= (1 << pcr); } diff --git a/src/libimcv/pts/pts_dh_group.c b/src/libimcv/pts/pts_dh_group.c index 91b5f2bfe..9b0d5ced7 100644 --- a/src/libimcv/pts/pts_dh_group.c +++ b/src/libimcv/pts/pts_dh_group.c @@ -26,43 +26,40 @@ bool pts_dh_group_probe(pts_dh_group_t *dh_groups, bool mandatory_dh_groups) enumerator_t *enumerator; key_exchange_method_t dh_group; const char *plugin_name; - char format1[] = " %s PTS DH group %N[%s] available"; - char format2[] = " %s PTS DH group %N not available"; *dh_groups = PTS_DH_GROUP_NONE; enumerator = lib->crypto->create_ke_enumerator(lib->crypto); while (enumerator->enumerate(enumerator, &dh_group, &plugin_name)) { - if (dh_group == MODP_1024_BIT) + pts_dh_group_t mapped = PTS_DH_GROUP_NONE; + + switch (dh_group) { - *dh_groups |= PTS_DH_GROUP_IKE2; - DBG2(DBG_PTS, format1, "optional ", key_exchange_method_names, - dh_group, plugin_name); + case MODP_1024_BIT: + mapped = PTS_DH_GROUP_IKE2; + break; + case MODP_1536_BIT: + mapped = PTS_DH_GROUP_IKE5; + break; + case MODP_2048_BIT: + mapped = PTS_DH_GROUP_IKE14; + break; + case ECP_256_BIT: + mapped = PTS_DH_GROUP_IKE19; + break; + case ECP_384_BIT: + mapped = PTS_DH_GROUP_IKE20; + break; + default: + break; } - else if (dh_group == MODP_1536_BIT) + if (mapped != PTS_DH_GROUP_NONE) { - *dh_groups |= PTS_DH_GROUP_IKE5; - DBG2(DBG_PTS, format1, "optional ", key_exchange_method_names, - dh_group, plugin_name); - } - else if (dh_group == MODP_2048_BIT) - { - *dh_groups |= PTS_DH_GROUP_IKE14; - DBG2(DBG_PTS, format1, "optional ", key_exchange_method_names, - dh_group, plugin_name); - } - else if (dh_group == ECP_256_BIT) - { - *dh_groups |= PTS_DH_GROUP_IKE19; - DBG2(DBG_PTS, format1, "mandatory", key_exchange_method_names, - dh_group, plugin_name); - } - else if (dh_group == ECP_384_BIT) - { - *dh_groups |= PTS_DH_GROUP_IKE20; - DBG2(DBG_PTS, format1, "optional ", key_exchange_method_names, - dh_group, plugin_name); + *dh_groups |= mapped; + DBG2(DBG_PTS, " %s PTS DH group %N[%s] available", + mapped == PTS_DH_GROUP_IKE19 ? "mandatory" : "optional ", + key_exchange_method_names, dh_group, plugin_name); } } enumerator->destroy(enumerator); @@ -79,8 +76,8 @@ bool pts_dh_group_probe(pts_dh_group_t *dh_groups, bool mandatory_dh_groups) } if (mandatory_dh_groups) { - DBG1(DBG_PTS, format2, "mandatory", key_exchange_method_names, - ECP_256_BIT); + DBG1(DBG_PTS, " mandatory PTS DH group %N[%s] available", + key_exchange_method_names, ECP_256_BIT); return FALSE; } diff --git a/src/libimcv/pts/pts_ima_bios_list.c b/src/libimcv/pts/pts_ima_bios_list.c index 47856efa1..a732300c7 100644 --- a/src/libimcv/pts/pts_ima_bios_list.c +++ b/src/libimcv/pts/pts_ima_bios_list.c @@ -201,11 +201,10 @@ pts_ima_bios_list_t* pts_ima_bios_list_create(tpm_tss_t *tpm, char *file, pts_meas_algorithms_t algo) { private_pts_ima_bios_list_t *this; - uint32_t pcr, ev_type, event_type, event_len, seek_len, count = 1; + uint32_t pcr, event_type, event_len, seek_len, count = 1; uint32_t buf_len = 8192; uint8_t event_buf[buf_len]; hash_algorithm_t hash_alg; - chunk_t event; bios_entry_t *entry; struct stat st; ssize_t res; @@ -276,10 +275,12 @@ pts_ima_bios_list_t* pts_ima_bios_list_create(tpm_tss_t *tpm, char *file, { break; } - ev_type = (event_type < EV_EFI_EVENT_BASE) ? - event_type : event_type - EV_EFI_OFFSET; +#if DEBUG_LEVEL >= 2 + uint32_t ev_type = (event_type < EV_EFI_EVENT_BASE) ? + event_type : event_type - EV_EFI_OFFSET; DBG2(DBG_PTS, "%3u %2u %N (%u bytes)", count, pcr, event_type_names, - ev_type, event_len); + ev_type, event_len); +#endif seek_len = (event_len > buf_len) ? event_len - buf_len : 0; event_len -= seek_len; @@ -310,8 +311,7 @@ pts_ima_bios_list_t* pts_ima_bios_list_create(tpm_tss_t *tpm, char *file, default: break; } - event = chunk_create(event_buf, event_len); - DBG3(DBG_PTS,"%B", &event); + DBG3(DBG_PTS, "%b", event_buf, event_len); if (seek_len > 0 && lseek(fd, seek_len, SEEK_CUR) == -1) { diff --git a/src/libimcv/pts/pts_ima_event_list.c b/src/libimcv/pts/pts_ima_event_list.c index 1b4edccd5..031729a27 100644 --- a/src/libimcv/pts/pts_ima_event_list.c +++ b/src/libimcv/pts/pts_ima_event_list.c @@ -139,7 +139,7 @@ pts_ima_event_list_t* pts_ima_event_list_create(char *file, size_t hash_size; char type[IMA_TYPE_LEN_MAX]; char algo_digest[IMA_ALGO_DIGEST_LEN_MAX]; - char *pos, *error = ""; + char *pos, *error DBG_UNUSED = ""; struct stat st; ssize_t res; bool ima_ng; diff --git a/src/libimcv/pts/pts_meas_algo.c b/src/libimcv/pts/pts_meas_algo.c index 0d303aa4a..9fb2555fe 100644 --- a/src/libimcv/pts/pts_meas_algo.c +++ b/src/libimcv/pts/pts_meas_algo.c @@ -34,6 +34,8 @@ ENUM_NEXT(pts_meas_algorithm_names, PTS_MEAS_ALGO_SHA1, PTS_MEAS_ALGO_SHA1, "SHA1"); ENUM_END(pts_meas_algorithm_names, PTS_MEAS_ALGO_SHA1); +#define ALG_UNAVAIL " %s PTS measurement algorithm %N not available" + /** * Described in header. */ @@ -42,48 +44,51 @@ bool pts_meas_algo_probe(pts_meas_algorithms_t *algorithms) enumerator_t *enumerator; hash_algorithm_t hash_alg; const char *plugin_name; - char format1[] = " %s PTS measurement algorithm %N[%s] available"; - char format2[] = " %s PTS measurement algorithm %N not available"; *algorithms = 0; enumerator = lib->crypto->create_hasher_enumerator(lib->crypto); while (enumerator->enumerate(enumerator, &hash_alg, &plugin_name)) { - if (hash_alg == HASH_SHA1) + pts_meas_algorithms_t mapped = 0; + bool mandatory DBG_UNUSED = FALSE; + + switch (hash_alg) { - *algorithms |= PTS_MEAS_ALGO_SHA1; - DBG2(DBG_PTS, format1, "mandatory", hash_algorithm_names, hash_alg, - plugin_name); + case HASH_SHA1: + mapped = PTS_MEAS_ALGO_SHA1; + mandatory = TRUE; + break; + case HASH_SHA256: + mapped = PTS_MEAS_ALGO_SHA256; + mandatory = TRUE; + break; + case HASH_SHA384: + mapped = PTS_MEAS_ALGO_SHA384; + break; + case HASH_SHA512: + mapped = PTS_MEAS_ALGO_SHA512; + break; + default: + break; } - else if (hash_alg == HASH_SHA256) + if (mapped) { - *algorithms |= PTS_MEAS_ALGO_SHA256; - DBG2(DBG_PTS, format1, "mandatory", hash_algorithm_names, hash_alg, - plugin_name); - } - else if (hash_alg == HASH_SHA384) - { - *algorithms |= PTS_MEAS_ALGO_SHA384; - DBG2(DBG_PTS, format1, "optional ", hash_algorithm_names, hash_alg, - plugin_name); - } - else if (hash_alg == HASH_SHA512) - { - *algorithms |= PTS_MEAS_ALGO_SHA512; - DBG2(DBG_PTS, format1, "optional ", hash_algorithm_names, hash_alg, - plugin_name); + *algorithms |= mapped; + DBG2(DBG_PTS, " %s PTS measurement algorithm %N[%s] available", + mandatory ? "mandatory" : "optional ", hash_algorithm_names, + hash_alg, plugin_name); } } enumerator->destroy(enumerator); if (!(*algorithms & PTS_MEAS_ALGO_SHA512)) { - DBG1(DBG_PTS, format2, "optional ", hash_algorithm_names, HASH_SHA512); + DBG1(DBG_PTS, ALG_UNAVAIL, "optional ", hash_algorithm_names, HASH_SHA512); } if (!(*algorithms & PTS_MEAS_ALGO_SHA384)) { - DBG1(DBG_PTS, format2, "optional ", hash_algorithm_names, HASH_SHA384); + DBG1(DBG_PTS, ALG_UNAVAIL, "optional ", hash_algorithm_names, HASH_SHA384); } if ((*algorithms & PTS_MEAS_ALGO_SHA1) && (*algorithms & PTS_MEAS_ALGO_SHA256)) @@ -92,11 +97,11 @@ bool pts_meas_algo_probe(pts_meas_algorithms_t *algorithms) } if (!(*algorithms & PTS_MEAS_ALGO_SHA256)) { - DBG1(DBG_PTS, format2, "mandatory", hash_algorithm_names, HASH_SHA256); + DBG1(DBG_PTS, ALG_UNAVAIL, "mandatory", hash_algorithm_names, HASH_SHA256); } if (!(*algorithms & PTS_MEAS_ALGO_SHA1)) { - DBG1(DBG_PTS, format2, "mandatory", hash_algorithm_names, HASH_SHA1); + DBG1(DBG_PTS, ALG_UNAVAIL, "mandatory", hash_algorithm_names, HASH_SHA1); } return FALSE; } diff --git a/src/libimcv/suites/test_imcv_swima.c b/src/libimcv/suites/test_imcv_swima.c index 80bb58382..175d0cc35 100644 --- a/src/libimcv/suites/test_imcv_swima.c +++ b/src/libimcv/suites/test_imcv_swima.c @@ -1000,9 +1000,9 @@ START_TEST(test_imcv_swima_sw_collector) swima_events_t *events; swima_record_t *sw_record; swima_event_t *sw_event; - chunk_t sw_id, sw_locator, swid_tag; + chunk_t sw_id DBG_UNUSED, sw_locator, swid_tag DBG_UNUSED; enumerator_t *enumerator; - uint8_t source_id; + uint8_t source_id DBG_UNUSED; int item = 0, items; targets = swima_inventory_create(); From 36490eefa34851442a2cfa532567c49078f0ce7f Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Mon, 1 May 2023 11:44:17 +0200 Subject: [PATCH 23/53] backend-manager: Fix build with DEBUG_LEVEL < 3 --- src/libcharon/config/backend_manager.c | 29 ++++++++++++-------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/src/libcharon/config/backend_manager.c b/src/libcharon/config/backend_manager.c index e534adbf2..522115320 100644 --- a/src/libcharon/config/backend_manager.c +++ b/src/libcharon/config/backend_manager.c @@ -196,7 +196,6 @@ static linked_list_t *get_matching_ike_cfgs(private_backend_manager_t *this, ike_version_t version) { ike_cfg_t *current; - char *my_addr, *other_addr; enumerator_t *enumerator; ike_data_t *data; linked_list_t *configs; @@ -218,8 +217,10 @@ static linked_list_t *get_matching_ike_cfgs(private_backend_manager_t *this, while (enumerator->enumerate(enumerator, ¤t)) { - my_addr = current->get_my_addr(current); - other_addr = current->get_other_addr(current); +#if DEBUG_LEVEL >= 2 + char *my_addr = current->get_my_addr(current); + char *other_addr = current->get_other_addr(current); +#endif match = get_ike_match(current, me, other, version); DBG3(DBG_CFG, "ike config match: %d (%s...%s %N)", match, my_addr, other_addr, ike_version_names, current->get_version(current)); @@ -249,7 +250,6 @@ METHOD(backend_manager_t, get_ike_cfg, ike_cfg_t*, linked_list_t *configs; ike_match_entry_t *entry; ike_cfg_t *found = NULL; - char *my_addr, *other_addr; DBG2(DBG_CFG, "looking for an %N config for %H...%H", ike_version_names, version, me, other); @@ -258,11 +258,9 @@ METHOD(backend_manager_t, get_ike_cfg, ike_cfg_t*, if (configs->get_first(configs, (void**)&entry) == SUCCESS) { found = entry->cfg->get_ref(entry->cfg); - - my_addr = found->get_my_addr(found); - other_addr = found->get_other_addr(found); DBG2(DBG_CFG, "found matching ike config: %s...%s with prio %d", - my_addr, other_addr, entry->match); + found->get_my_addr(found), found->get_other_addr(found), + entry->match); } ike_match_entry_list_destroy(configs); @@ -295,8 +293,7 @@ static id_match_t get_peer_match(identification_t *id, auth_cfg_t *auth; identification_t *candidate; id_match_t match = ID_MATCH_NONE; - char *where = local ? "local" : "remote"; - chunk_t data; + char *where DBG_UNUSED = local ? "local" : "remote"; if (!id) { @@ -326,9 +323,11 @@ static id_match_t get_peer_match(identification_t *id, } enumerator->destroy(enumerator); - data = id->get_encoding(id); +#if DEBUG_LEVEL >= 3 + chunk_t data = id->get_encoding(id); DBG3(DBG_CFG, " %s id match: %d (%N: %#B)", where, match, id_type_names, id->get_type(id), &data); +#endif return match; } @@ -452,14 +451,12 @@ METHOD(backend_manager_t, create_peer_cfg_enumerator, enumerator_t*, ike_cfg_match_t match_ike; id_match_t match_peer_me, match_peer_other; match_entry_t *entry; - char *my_addr, *other_addr; match_ike = get_ike_match(ike_cfg, me, other, version); - my_addr = ike_cfg->get_my_addr(ike_cfg); - other_addr = ike_cfg->get_other_addr(ike_cfg); DBG3(DBG_CFG, "peer config \"%s\", ike match: %d (%s...%s %N)", - cfg->get_name(cfg), match_ike, my_addr, other_addr, - ike_version_names, ike_cfg->get_version(ike_cfg)); + cfg->get_name(cfg), match_ike, ike_cfg->get_my_addr(ike_cfg), + ike_cfg->get_other_addr(ike_cfg), ike_version_names, + ike_cfg->get_version(ike_cfg)); if (!match_ike) { From 9b9464fdcdd4b1acaa4771f13c9f6fa00547339a Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Mon, 1 May 2023 11:48:36 +0200 Subject: [PATCH 24/53] generator: Fix build with DEBUG_LEVEL < 2 --- src/libcharon/encoding/generator.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/libcharon/encoding/generator.c b/src/libcharon/encoding/generator.c index 8b3b53b75..3075abcf4 100644 --- a/src/libcharon/encoding/generator.c +++ b/src/libcharon/encoding/generator.c @@ -442,21 +442,20 @@ METHOD(generator_t, get_chunk, chunk_t, METHOD(generator_t, generate_payload, void, private_generator_t *this, payload_t *payload) { - int i, offset_start, rule_count; + int i, rule_count; encoding_rule_t *rules; - payload_type_t payload_type; - - this->data_struct = payload; - payload_type = payload->get_type(payload); - - offset_start = this->out_position - this->buffer; +#if DEBUG_LEVEL >= 2 + int offset_start = this->out_position - this->buffer; +#endif if (this->debug) { DBG2(DBG_ENC, "generating payload of type %N", - payload_type_names, payload_type); + payload_type_names, payload->get_type(payload)); } + this->data_struct = payload; + /* each payload has its own encoding rules */ rule_count = payload->get_encoding_rules(payload, &rules); @@ -559,7 +558,7 @@ METHOD(generator_t, generate_payload, void, if (this->debug) { DBG2(DBG_ENC, "generating %N payload finished", - payload_type_names, payload_type); + payload_type_names, payload->get_type(payload)); DBG3(DBG_ENC, "generated data for this payload %b", this->buffer + offset_start, (u_int)(this->out_position - this->buffer - offset_start)); From 79d49ea05b5f991e851b44c87cfaf1c63a3316a1 Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Mon, 1 May 2023 11:51:57 +0200 Subject: [PATCH 25/53] message: Fix build with DEBUG__LEVEL < 1 --- src/libcharon/encoding/message.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/libcharon/encoding/message.c b/src/libcharon/encoding/message.c index 4494f23fd..1686baeae 100644 --- a/src/libcharon/encoding/message.c +++ b/src/libcharon/encoding/message.c @@ -1270,6 +1270,7 @@ METHOD(message_t, get_notify, notify_payload_t*, return notify; } +#if DEBUG_LEVEL >= 1 /** * get a string representation of the message */ @@ -1472,6 +1473,7 @@ static char* get_string(private_message_t *this, char *buf, int len) snprintf(pos, len, " ]"); return buf; } +#endif METHOD(message_t, disable_sort, void, private_message_t *this) @@ -1668,7 +1670,6 @@ static status_t generate_message(private_message_t *this, keymat_t *keymat, enumerator_t *enumerator; aead_t *aead = NULL; chunk_t hash = chunk_empty; - char str[BUF_LEN]; ike_header_t *ike_header; payload_t *payload, *next; bool encrypting = FALSE; @@ -1739,7 +1740,10 @@ static status_t generate_message(private_message_t *this, keymat_t *keymat, enumerator->destroy(enumerator); } +#if DEBUG_LEVEL >= 1 + char str[BUF_LEN]; DBG1(DBG_ENC, "generating %s", get_string(this, str, sizeof(str))); +#endif if (keymat) { @@ -2627,7 +2631,6 @@ METHOD(message_t, parse_body, status_t, private_message_t *this, keymat_t *keymat) { status_t status = SUCCESS; - char str[BUF_LEN]; DBG2(DBG_ENC, "parsing body of message, first payload is %N", payload_type_names, this->first_payload); @@ -2665,7 +2668,10 @@ METHOD(message_t, parse_body, status_t, return status; } +#if DEBUG_LEVEL >= 1 + char str[BUF_LEN]; DBG1(DBG_ENC, "parsed %s", get_string(this, str, sizeof(str))); +#endif if (keymat && keymat->get_version(keymat) == IKEV1) { @@ -2856,7 +2862,6 @@ METHOD(message_t, add_fragment_v2, status_t, enumerator_t *enumerator; chunk_t data; uint16_t total, num; - size_t len; status_t status; if (!this->frag) @@ -2938,7 +2943,8 @@ METHOD(message_t, add_fragment_v2, status_t, /* we report the length of the complete IKE message when splitting, do the * same here, so add the IKEv2 header len to the reassembled payload data */ - len = 28; +#if DEBUG_LEVEL >= 1 + size_t len = 28; enumerator = create_payload_enumerator(this); while (enumerator->enumerate(enumerator, &payload)) { @@ -2948,6 +2954,8 @@ METHOD(message_t, add_fragment_v2, status_t, DBG1(DBG_ENC, "received fragment #%hu of %hu, reassembled fragmented IKE " "message (%zu bytes)", num, total, len); +#endif /* DEBUG_LEVEL */ + return SUCCESS; } From 5408b50160504cad5e33ee812513fe810f99bece Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Mon, 1 May 2023 11:53:49 +0200 Subject: [PATCH 26/53] ike-sa: Fix build with DEBUG_LEVEL < 1 --- src/libcharon/sa/ike_sa.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/libcharon/sa/ike_sa.c b/src/libcharon/sa/ike_sa.c index 6782f7555..a46a9754c 100644 --- a/src/libcharon/sa/ike_sa.c +++ b/src/libcharon/sa/ike_sa.c @@ -1541,19 +1541,17 @@ METHOD(ike_sa_t, initiate, status_t, #endif /* ME */ ) { - char *addr; - - addr = this->ike_cfg->get_other_addr(this->ike_cfg); if (!this->retry_initiate_interval) { DBG1(DBG_IKE, "unable to resolve %s, initiate aborted", - addr); + this->ike_cfg->get_other_addr(this->ike_cfg)); DESTROY_IF(child_cfg); charon->bus->alert(charon->bus, ALERT_PEER_ADDR_FAILED); return DESTROY_ME; } DBG1(DBG_IKE, "unable to resolve %s, retrying in %ds", - addr, this->retry_initiate_interval); + this->ike_cfg->get_other_addr(this->ike_cfg), + this->retry_initiate_interval); defer_initiate = TRUE; } @@ -1965,13 +1963,13 @@ METHOD(ike_sa_t, reauth, status_t, if (!has_condition(this, COND_ORIGINAL_INITIATOR) && !ike_sa_can_reauthenticate(&this->public)) { - time_t del, now; - - del = this->stats[STAT_DELETE]; - now = time_monotonic(NULL); +#if DEBUG_LEVEL >= 1 + time_t del = this->stats[STAT_DELETE]; + time_t now = time_monotonic(NULL); DBG1(DBG_IKE, "initiator did not reauthenticate as requested, IKE_SA " "%s[%d] will timeout in %V", get_name(this), this->unique_id, &now, &del); +#endif return FAILED; } DBG0(DBG_IKE, "reauthenticating IKE_SA %s[%d]", From 117e13e7f1f12a0168d723278e0695a28e0ab9a4 Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Mon, 1 May 2023 11:55:36 +0200 Subject: [PATCH 27/53] eap-authenticator: Fix build with DEBUG_LEVEL < 1 --- src/libcharon/sa/ikev2/authenticators/eap_authenticator.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libcharon/sa/ikev2/authenticators/eap_authenticator.c b/src/libcharon/sa/ikev2/authenticators/eap_authenticator.c index 976ed623d..5f60af7ca 100644 --- a/src/libcharon/sa/ikev2/authenticators/eap_authenticator.c +++ b/src/libcharon/sa/ikev2/authenticators/eap_authenticator.c @@ -156,7 +156,7 @@ static eap_payload_t* server_initiate_eap(private_eap_authenticator_t *this, identification_t *id; pen_t vendor; eap_payload_t *out; - char *action; + char *action DBG_UNUSED; auth = this->ike_sa->get_auth_cfg(this->ike_sa, FALSE); @@ -641,11 +641,12 @@ METHOD(authenticator_t, process_client, status_t, } if (this->require_mutual && !this->method->is_mutual(this->method)) { /* we require mutual authentication due to EAP-only */ +#if DEBUG_LEVEL >= 1 pen_t vendor; - DBG1(DBG_IKE, "EAP-only authentication requires a mutual and " "MSK deriving EAP method, but %N is not", eap_type_names, this->method->get_type(this->method, &vendor)); +#endif return FAILED; } return SUCCESS; From 675082114cab5335028f26906a4eff645f5bdf00 Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Mon, 1 May 2023 11:57:16 +0200 Subject: [PATCH 28/53] pubkey-authenticator: Fix build with DEBUG_LEVEL < 1 --- .../sa/ikev2/authenticators/pubkey_authenticator.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/libcharon/sa/ikev2/authenticators/pubkey_authenticator.c b/src/libcharon/sa/ikev2/authenticators/pubkey_authenticator.c index 1f8718962..4f83dad10 100644 --- a/src/libcharon/sa/ikev2/authenticators/pubkey_authenticator.c +++ b/src/libcharon/sa/ikev2/authenticators/pubkey_authenticator.c @@ -371,11 +371,13 @@ static status_t sign_signature_auth(private_pubkey_authenticator_t *this, { if (params->scheme == SIGN_RSA_EMSA_PSS) { +#if DEBUG_LEVEL >= 1 rsa_pss_params_t *pss = params->params; DBG1(DBG_IKE, "authentication of '%Y' (myself) with %N_%N_SALT_%zd " "%s", id, signature_scheme_names, params->scheme, hash_algorithm_short_names_upper, pss->hash, pss->salt_len, status == SUCCESS ? "successful" : "failed"); +#endif } else { @@ -573,7 +575,7 @@ METHOD(authenticator_t, process, status_t, key_type_t key_type = KEY_ECDSA; signature_params_t *params; status_t status = NOT_FOUND; - const char *reason = "unsupported"; + const char *reason DBG_UNUSED = "unsupported"; bool online; auth_payload = (auth_payload_t*)message->get_payload(message, PLV2_AUTH); @@ -647,10 +649,12 @@ METHOD(authenticator_t, process, status_t, } else if (params->scheme == SIGN_RSA_EMSA_PSS) { +#if DEBUG_LEVEL >= 1 rsa_pss_params_t *pss = params->params; DBG1(DBG_IKE, "authentication of '%Y' with %N_%N_SALT_%zd " "successful", id, signature_scheme_names, params->scheme, hash_algorithm_short_names_upper, pss->hash, pss->salt_len); +#endif } else { From 7a883c4b37d6e8f1c562d853faedb61c3898c531 Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Mon, 1 May 2023 11:59:46 +0200 Subject: [PATCH 29/53] child-create: Fix build with DEBUG_LEVEL < 1 --- src/libcharon/sa/ikev2/tasks/child_create.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/libcharon/sa/ikev2/tasks/child_create.c b/src/libcharon/sa/ikev2/tasks/child_create.c index daa56a9e5..928264820 100644 --- a/src/libcharon/sa/ikev2/tasks/child_create.c +++ b/src/libcharon/sa/ikev2/tasks/child_create.c @@ -495,7 +495,6 @@ static status_t select_and_install(private_child_create_t *this, bool no_dh, bool ike_auth) { status_t status, status_i, status_o; - child_sa_outbound_state_t out_state; chunk_t nonce_i, nonce_r; chunk_t encr_i = chunk_empty, encr_r = chunk_empty; chunk_t integ_i = chunk_empty, integ_r = chunk_empty; @@ -779,11 +778,14 @@ static status_t select_and_install(private_child_create_t *this, charon->bus->child_keys(charon->bus, this->child_sa, this->initiator, this->dh, nonce_i, nonce_r); +#if DEBUG_LEVEL >= 0 + child_sa_outbound_state_t out_state; + + out_state = this->child_sa->get_outbound_state(this->child_sa); my_ts = linked_list_create_from_enumerator( this->child_sa->create_ts_enumerator(this->child_sa, TRUE)); other_ts = linked_list_create_from_enumerator( this->child_sa->create_ts_enumerator(this->child_sa, FALSE)); - out_state = this->child_sa->get_outbound_state(this->child_sa); DBG0(DBG_IKE, "%sCHILD_SA %s{%d} established " "with SPIs %.8x_i %.8x_o and TS %#R === %#R", @@ -796,6 +798,7 @@ static status_t select_and_install(private_child_create_t *this, my_ts->destroy(my_ts); other_ts->destroy(other_ts); +#endif this->child_sa->set_state(this->child_sa, CHILD_INSTALLED); this->ike_sa->add_child_sa(this->ike_sa, this->child_sa); @@ -1129,13 +1132,13 @@ static bool check_for_generic_label(private_child_create_t *this) { if (generic_label_only(this)) { - sec_label_t *label; - - label = this->config->get_label(this->config); +#if DEBUG_LEVEL >= 1 + sec_label_t *label = this->config->get_label(this->config); DBG1(DBG_IKE, "not establishing CHILD_SA %s{%d} with generic " "label '%s'", this->child_sa->get_name(this->child_sa), this->child_sa->get_unique_id(this->child_sa), label->get_string(label)); +#endif return TRUE; } return FALSE; From 5e32be1bb501815763ba302c5b879faad508016f Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Mon, 1 May 2023 12:03:06 +0200 Subject: [PATCH 30/53] ike-config: Fix build with DEBUG_LEVEL < 1 --- src/libcharon/sa/ikev2/tasks/ike_config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcharon/sa/ikev2/tasks/ike_config.c b/src/libcharon/sa/ikev2/tasks/ike_config.c index c40f1dab1..c962e3006 100644 --- a/src/libcharon/sa/ikev2/tasks/ike_config.c +++ b/src/libcharon/sa/ikev2/tasks/ike_config.c @@ -353,7 +353,7 @@ METHOD(task_t, build_r, status_t, chunk_t value; cp_payload_t *cp = NULL; peer_cfg_t *config; - identification_t *id; + identification_t *id DBG_UNUSED; linked_list_t *vips, *pools; host_t *requested; From 963398c2c35f1f9f425d813df1b3fafc439e79b3 Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Mon, 1 May 2023 12:04:22 +0200 Subject: [PATCH 31/53] ike-init: Fix build with DEBUG_LEVEL < 1 --- src/libcharon/sa/ikev2/tasks/ike_init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcharon/sa/ikev2/tasks/ike_init.c b/src/libcharon/sa/ikev2/tasks/ike_init.c index a73c98ac9..b84c2832a 100644 --- a/src/libcharon/sa/ikev2/tasks/ike_init.c +++ b/src/libcharon/sa/ikev2/tasks/ike_init.c @@ -1035,7 +1035,7 @@ METHOD(task_t, process_i, status_t, case INVALID_KE_PAYLOAD: { chunk_t data; - key_exchange_method_t bad_group; + key_exchange_method_t bad_group DBG_UNUSED; bad_group = this->dh_group; data = notify->get_notification_data(notify); From ab919c62da416f87290955414c53634e13647356 Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Mon, 1 May 2023 12:05:02 +0200 Subject: [PATCH 32/53] keymat_v1: Fix build with DEBUG_LEVEL < 3 --- src/libcharon/sa/ikev1/keymat_v1.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcharon/sa/ikev1/keymat_v1.c b/src/libcharon/sa/ikev1/keymat_v1.c index 64de3d95d..3142270d7 100644 --- a/src/libcharon/sa/ikev1/keymat_v1.c +++ b/src/libcharon/sa/ikev1/keymat_v1.c @@ -799,7 +799,7 @@ METHOD(keymat_v1_t, get_hash_phase2, bool, uint32_t mid, mid_n; chunk_t data = chunk_empty, *n_i, *n_r; bool add_message = TRUE; - char *name = "Hash"; + char *name DBG_UNUSED = "Hash"; if (!this->prf) { /* no keys derived yet */ From 800cef35db4f85b0e529b471220de16e0668e54d Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Mon, 1 May 2023 12:05:59 +0200 Subject: [PATCH 33/53] mode-config: Fix build with DEBUG_LEVEL < 1 --- src/libcharon/sa/ikev1/tasks/mode_config.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libcharon/sa/ikev1/tasks/mode_config.c b/src/libcharon/sa/ikev1/tasks/mode_config.c index db441924c..b718042ea 100644 --- a/src/libcharon/sa/ikev1/tasks/mode_config.c +++ b/src/libcharon/sa/ikev1/tasks/mode_config.c @@ -335,7 +335,7 @@ static status_t build_set(private_mode_config_t *this, message_t *message) chunk_t value; cp_payload_t *cp; peer_cfg_t *config; - identification_t *id; + identification_t *id DBG_UNUSED; linked_list_t *pools, *migrated, *vips; host_t *any4, *any6, *found; char *name; @@ -491,7 +491,7 @@ static status_t build_reply(private_mode_config_t *this, message_t *message) chunk_t value; cp_payload_t *cp; peer_cfg_t *config; - identification_t *id; + identification_t *id DBG_UNUSED; linked_list_t *vips, *pools, *migrated; host_t *requested, *found; From a7ea181f0d79ab3312e5e3e4cdc218f9cfccee91 Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Wed, 3 May 2023 10:52:14 +0200 Subject: [PATCH 34/53] save-keys: Fix build with DEBUG_LEVEL < 0 --- src/libcharon/plugins/save_keys/save_keys_listener.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcharon/plugins/save_keys/save_keys_listener.c b/src/libcharon/plugins/save_keys/save_keys_listener.c index 712787ac9..9565a74f3 100644 --- a/src/libcharon/plugins/save_keys/save_keys_listener.c +++ b/src/libcharon/plugins/save_keys/save_keys_listener.c @@ -420,7 +420,7 @@ save_keys_listener_t *save_keys_listener_create() if (this->path && (this->ike || this->esp)) { - char *keys = "IKE"; + char *keys DBG_UNUSED = "IKE"; if (this->ike && this->esp) { From 86aa454c882a0668d95b06b93dfa102538e6995c Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Wed, 3 May 2023 12:16:15 +0200 Subject: [PATCH 35/53] forecast: Fix build with DEBUG_LEVEL < 2 --- src/libcharon/plugins/forecast/forecast_forwarder.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcharon/plugins/forecast/forecast_forwarder.c b/src/libcharon/plugins/forecast/forecast_forwarder.c index 0fd199b36..e1c5ae465 100644 --- a/src/libcharon/plugins/forecast/forecast_forwarder.c +++ b/src/libcharon/plugins/forecast/forecast_forwarder.c @@ -162,7 +162,7 @@ CALLBACK(receive_casts, bool, struct iphdr hdr; char data[2048]; } buf; - char *type; + char *type DBG_UNUSED; ssize_t len; u_int mark, origin = 0; host_t *src, *dst; From e0eece04650476a21430f23bb1e66a7edd48b93d Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Mon, 1 May 2023 12:06:59 +0200 Subject: [PATCH 36/53] vici: Fix build with DEBUG_LEVEL < 2 --- src/libcharon/plugins/vici/vici_authority.c | 5 ++--- src/libcharon/plugins/vici/vici_config.c | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/libcharon/plugins/vici/vici_authority.c b/src/libcharon/plugins/vici/vici_authority.c index ced43ed83..e79fc2816 100644 --- a/src/libcharon/plugins/vici/vici_authority.c +++ b/src/libcharon/plugins/vici/vici_authority.c @@ -429,12 +429,11 @@ CALLBACK(authority_li, bool, static void log_authority_data(authority_t *authority) { enumerator_t *enumerator; - identification_t *subject; bool first = TRUE; char *uri; - subject = authority->cert->get_subject(authority->cert); - DBG2(DBG_CFG, " cacert = %Y", subject); + DBG2(DBG_CFG, " cacert = %Y", + authority->cert->get_subject(authority->cert)); enumerator = authority->crl_uris->create_enumerator(authority->crl_uris); while (enumerator->enumerate(enumerator, &uri)) diff --git a/src/libcharon/plugins/vici/vici_config.c b/src/libcharon/plugins/vici/vici_config.c index 62f24661f..522122562 100644 --- a/src/libcharon/plugins/vici/vici_config.c +++ b/src/libcharon/plugins/vici/vici_config.c @@ -520,7 +520,7 @@ typedef struct { */ static void log_child_data(child_data_t *data, char *name) { - child_cfg_create_t *cfg = &data->cfg; + child_cfg_create_t *cfg DBG_UNUSED = &data->cfg; #define has_opt(opt) ({ (cfg->options & (opt)) == (opt); }) DBG2(DBG_CFG, " child %s:", name); From 65dc1801cfad39b7e140d234e9b84e0b5b2a89cc Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Mon, 1 May 2023 12:10:11 +0200 Subject: [PATCH 37/53] eap-mschapv2: Fix build with DEBUG_LEVEL < 1 --- src/libcharon/plugins/eap_mschapv2/eap_mschapv2.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libcharon/plugins/eap_mschapv2/eap_mschapv2.c b/src/libcharon/plugins/eap_mschapv2/eap_mschapv2.c index 2e14bd900..1bb54c877 100644 --- a/src/libcharon/plugins/eap_mschapv2/eap_mschapv2.c +++ b/src/libcharon/plugins/eap_mschapv2/eap_mschapv2.c @@ -661,6 +661,7 @@ static chunk_t utf8_to_utf16le(chunk_t utf8) return utf16; } +#if DEBUG_LEVEL >= 1 /** * sanitize a string for printing */ @@ -678,6 +679,7 @@ static char* sanitize(char *str) } return str; } +#endif /* DEBUG_LEVEL */ /** * Returns a chunk of just the username part of the given user identity. @@ -966,7 +968,7 @@ static status_t process_peer_failure(private_eap_mschapv2_t *this, eap_mschapv2_header_t *eap; chunk_t data; char *message, *token, *msg = NULL; - int message_len, error = 0; + int message_len, error DBG_UNUSED = 0; chunk_t challenge = chunk_empty; data = in->get_data(in); From 2d3967cb4cc0ce73ab437bee16c0ae1c7b1e4e47 Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Wed, 3 May 2023 12:22:05 +0200 Subject: [PATCH 38/53] eap-dynamic: Fix build with DEBUG_LEVEL < 2 --- src/libcharon/plugins/eap_dynamic/eap_dynamic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcharon/plugins/eap_dynamic/eap_dynamic.c b/src/libcharon/plugins/eap_dynamic/eap_dynamic.c index 5ecb187f7..40c1456c3 100644 --- a/src/libcharon/plugins/eap_dynamic/eap_dynamic.c +++ b/src/libcharon/plugins/eap_dynamic/eap_dynamic.c @@ -118,7 +118,7 @@ static void select_method(private_eap_dynamic_t *this) { eap_vendor_type_t *entry; linked_list_t *outer = this->types, *inner = this->other_types; - char *who = "peer"; + char *who DBG_UNUSED = "peer"; if (this->other_types && this->prefer_peer) { From cbedbf3ef1fab084babde570e367e07a88f616ac Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Mon, 1 May 2023 12:11:32 +0200 Subject: [PATCH 39/53] eap-radius: Fix build with DEBUG_LEVEL < 1 --- src/libcharon/plugins/eap_radius/eap_radius.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcharon/plugins/eap_radius/eap_radius.c b/src/libcharon/plugins/eap_radius/eap_radius.c index ad7f59581..5cec436c8 100644 --- a/src/libcharon/plugins/eap_radius/eap_radius.c +++ b/src/libcharon/plugins/eap_radius/eap_radius.c @@ -334,7 +334,7 @@ static void process_filter_id(radius_message_t *msg) { enumerator_t *enumerator; int type; - uint8_t tunnel_tag; + uint8_t tunnel_tag DBG_UNUSED; uint32_t tunnel_type; chunk_t filter_id = chunk_empty, data; bool is_esp_tunnel = FALSE; From e252e1b4651bf912b115b07e72de8607a88863da Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Wed, 3 May 2023 12:23:58 +0200 Subject: [PATCH 40/53] eap-ttls: Fix build with DEBUG_LEVEL < 1 --- src/libcharon/plugins/eap_ttls/eap_ttls_peer.c | 15 +++++++-------- src/libcharon/plugins/eap_ttls/eap_ttls_server.c | 12 ++++++------ 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/libcharon/plugins/eap_ttls/eap_ttls_peer.c b/src/libcharon/plugins/eap_ttls/eap_ttls_peer.c index 4c8d33804..63126a5c3 100644 --- a/src/libcharon/plugins/eap_ttls/eap_ttls_peer.c +++ b/src/libcharon/plugins/eap_ttls/eap_ttls_peer.c @@ -79,7 +79,7 @@ METHOD(tls_application_t, process, status_t, pen_t vendor, received_vendor; uint16_t eap_len; size_t eap_pos = 0; - bool concatenated = FALSE; + bool concatenated DBG_UNUSED = FALSE; do { @@ -239,9 +239,6 @@ METHOD(tls_application_t, build, status_t, private_eap_ttls_peer_t *this, bio_writer_t *writer) { chunk_t data; - eap_code_t code; - eap_type_t type; - pen_t vendor; if (this->method == NULL && this->start_phase2) { @@ -261,11 +258,13 @@ METHOD(tls_application_t, build, status_t, if (this->out) { - code = this->out->get_code(this->out); - type = this->out->get_type(this->out, &vendor); +#if DEBUG_LEVEL >= 1 + pen_t vendor; + eap_code_t code = this->out->get_code(this->out); + eap_type_t type = this->out->get_type(this->out, &vendor); DBG1(DBG_IKE, "sending tunneled EAP-TTLS AVP [EAP/%N/%N]", - eap_code_short_names, code, eap_type_short_names, type); - + eap_code_short_names, code, eap_type_short_names, type); +#endif /* get the raw EAP message data */ data = this->out->get_data(this->out); this->avp->build(this->avp, writer, data); diff --git a/src/libcharon/plugins/eap_ttls/eap_ttls_server.c b/src/libcharon/plugins/eap_ttls/eap_ttls_server.c index d7279ce8c..fc97f811c 100644 --- a/src/libcharon/plugins/eap_ttls/eap_ttls_server.c +++ b/src/libcharon/plugins/eap_ttls/eap_ttls_server.c @@ -308,9 +308,6 @@ METHOD(tls_application_t, build, status_t, private_eap_ttls_server_t *this, bio_writer_t *writer) { chunk_t data; - eap_code_t code; - eap_type_t type; - pen_t vendor; if (this->method == NULL && this->start_phase2 && lib->settings->get_bool(lib->settings, @@ -333,10 +330,13 @@ METHOD(tls_application_t, build, status_t, if (this->out) { - code = this->out->get_code(this->out); - type = this->out->get_type(this->out, &vendor); +#if DEBUG_LEVEL >= 1 + pen_t vendor; + eap_code_t code = this->out->get_code(this->out); + eap_type_t type = this->out->get_type(this->out, &vendor); DBG1(DBG_IKE, "sending tunneled EAP-TTLS AVP [EAP/%N/%N]", - eap_code_short_names, code, eap_type_short_names, type); + eap_code_short_names, code, eap_type_short_names, type); +#endif /* get the raw EAP message data */ data = this->out->get_data(this->out); From 68f35b48d8b706b163bca63639338ebbf7620b3a Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Wed, 3 May 2023 12:27:48 +0200 Subject: [PATCH 41/53] eap-peap: Fix build with DEBUG_LEVEL < 1 --- src/libcharon/plugins/eap_peap/eap_peap_peer.c | 2 +- src/libcharon/plugins/eap_peap/eap_peap_server.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libcharon/plugins/eap_peap/eap_peap_peer.c b/src/libcharon/plugins/eap_peap/eap_peap_peer.c index eed40c0a7..95213a328 100644 --- a/src/libcharon/plugins/eap_peap/eap_peap_peer.c +++ b/src/libcharon/plugins/eap_peap/eap_peap_peer.c @@ -191,7 +191,7 @@ METHOD(tls_application_t, build, status_t, { chunk_t data; eap_code_t code; - eap_type_t type; + eap_type_t type DBG_UNUSED; pen_t vendor; if (this->out) diff --git a/src/libcharon/plugins/eap_peap/eap_peap_server.c b/src/libcharon/plugins/eap_peap/eap_peap_server.c index abf63713e..29ab9b451 100644 --- a/src/libcharon/plugins/eap_peap/eap_peap_server.c +++ b/src/libcharon/plugins/eap_peap/eap_peap_server.c @@ -343,7 +343,7 @@ METHOD(tls_application_t, build, status_t, { chunk_t data; eap_code_t code; - eap_type_t type; + eap_type_t type DBG_UNUSED; pen_t vendor; if (!this->ph2_method && this->start_phase2 && From e72ab6a8188df1b2654ef6c4ebf220768f8b0ce5 Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Wed, 3 May 2023 12:28:51 +0200 Subject: [PATCH 42/53] tnc-ifmap: Fix build with DEBUG_LEVEL < 2 --- .../plugins/tnc_ifmap/tnc_ifmap_renew_session_job.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/libcharon/plugins/tnc_ifmap/tnc_ifmap_renew_session_job.c b/src/libcharon/plugins/tnc_ifmap/tnc_ifmap_renew_session_job.c index 601b0f4d1..8e2fbd13c 100644 --- a/src/libcharon/plugins/tnc_ifmap/tnc_ifmap_renew_session_job.c +++ b/src/libcharon/plugins/tnc_ifmap/tnc_ifmap_renew_session_job.c @@ -54,13 +54,10 @@ METHOD(job_t, destroy, void, METHOD(job_t, execute, job_requeue_t, private_tnc_ifmap_renew_session_job_t *this) { - char *session_id; - if (this->ifmap->orphaned(this->ifmap)) { - session_id = this->ifmap->get_session_id(this->ifmap); DBG2(DBG_TNC, "removing orphaned ifmap renewSession job for '%s'", - session_id); + this->ifmap->get_session_id(this->ifmap)); return JOB_REQUEUE_NONE; } else From 35716df9bca8ff330155af1238a7c4a6233c48e0 Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Mon, 1 May 2023 12:12:54 +0200 Subject: [PATCH 43/53] dhcp: Fix build with DEBUG_LEVEL < 1 --- src/libcharon/plugins/dhcp/dhcp_socket.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libcharon/plugins/dhcp/dhcp_socket.c b/src/libcharon/plugins/dhcp/dhcp_socket.c index a3572766d..718936293 100644 --- a/src/libcharon/plugins/dhcp/dhcp_socket.c +++ b/src/libcharon/plugins/dhcp/dhcp_socket.c @@ -304,13 +304,14 @@ static bool discover(private_dhcp_socket_t *this, { dhcp_option_t *option; dhcp_t dhcp; - chunk_t mac; int optlen; optlen = prepare_dhcp(this, transaction, DHCP_DISCOVER, &dhcp); - mac = chunk_from_thing(dhcp.client_hw_addr); +#if DEBUG_LEVEL >= 1 + chunk_t mac = chunk_from_thing(dhcp.client_hw_addr); DBG1(DBG_CFG, "sending DHCP DISCOVER for %#B to %H", &mac, this->dst); +#endif option = (dhcp_option_t*)&dhcp.options[optlen]; option->type = DHCP_PARAM_REQ_LIST; From b0ce4ef8db5aca17ecd86aa4f4fbc63b80dd501e Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Mon, 1 May 2023 12:14:57 +0200 Subject: [PATCH 44/53] ha: Fix build with DEBUG_LEVEL < 1 --- src/libcharon/plugins/ha/ha_child.c | 5 ++++- src/libcharon/plugins/ha/ha_dispatcher.c | 7 +++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/libcharon/plugins/ha/ha_child.c b/src/libcharon/plugins/ha/ha_child.c index 2485b49bb..1081986dd 100644 --- a/src/libcharon/plugins/ha/ha_child.c +++ b/src/libcharon/plugins/ha/ha_child.c @@ -60,7 +60,6 @@ METHOD(listener_t, child_keys, bool, linked_list_t *local_ts, *remote_ts; enumerator_t *enumerator; traffic_selector_t *ts; - u_int seg_i, seg_o; if (this->tunnel && this->tunnel->is_sa(this->tunnel, ike_sa)) { /* do not sync SA between nodes */ @@ -127,6 +126,9 @@ METHOD(listener_t, child_keys, bool, } enumerator->destroy(enumerator); +#if DEBUG_LEVEL >= 1 + u_int seg_i, seg_o; + seg_i = this->kernel->get_segment_spi(this->kernel, ike_sa->get_my_host(ike_sa), child_sa->get_spi(child_sa, TRUE)); seg_o = this->kernel->get_segment_spi(this->kernel, @@ -136,6 +138,7 @@ METHOD(listener_t, child_keys, bool, child_sa->get_unique_id(child_sa), local_ts, remote_ts, seg_i, this->segments->is_active(this->segments, seg_i) ? "*" : "", seg_o, this->segments->is_active(this->segments, seg_o) ? "*" : ""); +#endif /* DEBUG_LEVEL */ local_ts->destroy(local_ts); remote_ts->destroy(remote_ts); diff --git a/src/libcharon/plugins/ha/ha_dispatcher.c b/src/libcharon/plugins/ha/ha_dispatcher.c index 3cf1aa671..08a348b61 100644 --- a/src/libcharon/plugins/ha/ha_dispatcher.c +++ b/src/libcharon/plugins/ha/ha_dispatcher.c @@ -658,7 +658,6 @@ static void process_child_add(private_ha_dispatcher_t *this, uint8_t mode = MODE_TUNNEL, ipcomp = 0; uint16_t encr = 0, integ = 0, len = 0, dh_grp = 0; uint16_t esn = NO_EXT_SEQ_NUMBERS; - u_int seg_i, seg_o; chunk_t nonce_i = chunk_empty, nonce_r = chunk_empty, secret = chunk_empty; chunk_t encr_i, integ_i, encr_r, integ_r; linked_list_t *local_ts, *remote_ts; @@ -858,16 +857,20 @@ static void process_child_add(private_ha_dispatcher_t *this, return; } +#if DEBUG_LEVEL >= 1 + u_int seg_i, seg_o; + seg_i = this->kernel->get_segment_spi(this->kernel, ike_sa->get_my_host(ike_sa), inbound_spi); seg_o = this->kernel->get_segment_spi(this->kernel, ike_sa->get_other_host(ike_sa), outbound_spi); - DBG1(DBG_CFG, "installed HA CHILD_SA %s{%d} %#R === %#R " "(segment in: %d%s, out: %d%s)", child_sa->get_name(child_sa), child_sa->get_unique_id(child_sa), local_ts, remote_ts, seg_i, this->segments->is_active(this->segments, seg_i) ? "*" : "", seg_o, this->segments->is_active(this->segments, seg_o) ? "*" : ""); +#endif /* DEBUG_LEVEL */ + child_sa->install_policies(child_sa); local_ts->destroy_offset(local_ts, offsetof(traffic_selector_t, destroy)); remote_ts->destroy_offset(remote_ts, offsetof(traffic_selector_t, destroy)); From d0ef504614844c8f0a08bcb052212ff6c88dbc32 Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Mon, 1 May 2023 12:16:12 +0200 Subject: [PATCH 45/53] kernel-netlink: Fix build with DEBUG_LEVEL < 2 --- src/libcharon/plugins/kernel_netlink/kernel_netlink_ipsec.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libcharon/plugins/kernel_netlink/kernel_netlink_ipsec.c b/src/libcharon/plugins/kernel_netlink/kernel_netlink_ipsec.c index 35fd7bd6c..7596f0c18 100644 --- a/src/libcharon/plugins/kernel_netlink/kernel_netlink_ipsec.c +++ b/src/libcharon/plugins/kernel_netlink/kernel_netlink_ipsec.c @@ -3067,8 +3067,8 @@ METHOD(kernel_ipsec_t, add_policy, status_t, enumerator_t *enumerator; bool found = FALSE, update = TRUE; char markstr[32] = "", labelstr[128] = ""; - uint32_t cur_priority = 0; - int use_count; + uint32_t cur_priority DBG_UNUSED = 0; + int use_count DBG_UNUSED; /* create a policy */ INIT(policy, @@ -3286,7 +3286,7 @@ METHOD(kernel_ipsec_t, del_policy, status_t, struct nlmsghdr *hdr; struct xfrm_userpolicy_id *policy_id; bool is_installed = TRUE; - uint32_t priority, auto_priority, cur_priority; + uint32_t priority, auto_priority, cur_priority DBG_UNUSED; ipsec_sa_t assigned_sa = { .src = data->src, .dst = data->dst, From 74b2628301777ea50c6c3609bcdc997c3bb1cae3 Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Mon, 1 May 2023 12:17:25 +0200 Subject: [PATCH 46/53] systime-fix: Fix build with DEBUG_LEVEL < 1 --- src/libcharon/plugins/systime_fix/systime_fix_plugin.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/libcharon/plugins/systime_fix/systime_fix_plugin.c b/src/libcharon/plugins/systime_fix/systime_fix_plugin.c index 99af799a8..bbebf82da 100644 --- a/src/libcharon/plugins/systime_fix/systime_fix_plugin.c +++ b/src/libcharon/plugins/systime_fix/systime_fix_plugin.c @@ -145,7 +145,7 @@ static job_requeue_t check_systime(private_systime_fix_plugin_t *this) { enumerator_t *enumerator; ike_sa_t *ike_sa; - char *action; + char *action DBG_UNUSED; job_t *job; if (time(NULL) < this->threshold) @@ -204,7 +204,7 @@ static bool load_validator(private_systime_fix_plugin_t *this) struct tm tm = { .tm_mday = 1, }; - char *str, *fmt, buf[32]; + char *str, *fmt; fmt = lib->settings->get_str(lib->settings, "%s.plugins.%s.threshold_format", "%Y", lib->ns, get_name(this)); @@ -234,8 +234,11 @@ static bool load_validator(private_systime_fix_plugin_t *this) return FALSE; } +#if DEBUG_LEVEL >= 1 + char buf[32]; DBG1(DBG_CFG, "enabling %s, threshold: %s", get_name(this), asctime_r(&tm, buf)); +#endif this->validator = systime_fix_validator_create(this->threshold); return TRUE; } From 4620f43ebad1d49df6f92ac62b40293239d9e430 Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Wed, 3 May 2023 12:29:36 +0200 Subject: [PATCH 47/53] radattr: Fix build with DEBUG_LEVEL < 1 --- src/libcharon/plugins/radattr/radattr_listener.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcharon/plugins/radattr/radattr_listener.c b/src/libcharon/plugins/radattr/radattr_listener.c index 8e18b18dc..9014aece5 100644 --- a/src/libcharon/plugins/radattr/radattr_listener.c +++ b/src/libcharon/plugins/radattr/radattr_listener.c @@ -60,7 +60,7 @@ struct private_radattr_listener_t { static void print_radius_attributes(private_radattr_listener_t *this, message_t *message) { - radius_attribute_type_t type; + radius_attribute_type_t type DBG_UNUSED; enumerator_t *enumerator; notify_payload_t *notify; payload_t *payload; From 72f8794d83ad14d04e0bc19133e12cac30981a5f Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Mon, 1 May 2023 12:18:46 +0200 Subject: [PATCH 48/53] selinux: Fix build with DEBUG_LEVEL < 1 --- src/libcharon/plugins/selinux/selinux_listener.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/libcharon/plugins/selinux/selinux_listener.c b/src/libcharon/plugins/selinux/selinux_listener.c index 7592ca658..396c4b042 100644 --- a/src/libcharon/plugins/selinux/selinux_listener.c +++ b/src/libcharon/plugins/selinux/selinux_listener.c @@ -92,13 +92,14 @@ static bool equals(const void *a_pub, const void *b) static bool install_generic_trap(ike_sa_t *ike_sa, child_sa_t *child_sa) { linked_list_t *local, *remote; - sec_label_t *label; bool success; - label = child_sa->get_label(child_sa); +#if DEBUG_LEVEL >= 1 + sec_label_t *label = child_sa->get_label(child_sa); DBG1(DBG_IKE, "installing trap %s{%d} with generic security label '%s'", child_sa->get_name(child_sa), child_sa->get_unique_id(child_sa), label->get_string(label)); +#endif local = ike_sa_get_dynamic_hosts(ike_sa, TRUE); remote = ike_sa_get_dynamic_hosts(ike_sa, FALSE); @@ -169,12 +170,13 @@ METHOD(listener_t, ike_updown, bool, { while (array_remove(entry->traps, ARRAY_TAIL, &child_sa)) { +#if DEBUG_LEVEL >= 1 sec_label_t *label = child_sa->get_label(child_sa); - DBG1(DBG_IKE, "uninstalling trap %s{%d} with generic security " "label '%s'", child_sa->get_name(child_sa), child_sa->get_unique_id(child_sa), label->get_string(label)); +#endif charon->traps->remove_external(charon->traps, child_sa); child_sa->destroy(child_sa); } From 3804b2adf9a2aa007d1f9145c94304ca255f3f4f Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Mon, 1 May 2023 12:28:03 +0200 Subject: [PATCH 49/53] pki: Fix build with DEBUG_LEVEL < 1 --- src/pki/pki_cert.c | 28 +++++++++++++++------------- src/pki/scep/scep.c | 6 +++--- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/pki/pki_cert.c b/src/pki/pki_cert.c index d5f792a53..80a18b81a 100644 --- a/src/pki/pki_cert.c +++ b/src/pki/pki_cert.c @@ -34,7 +34,7 @@ typedef enum { CERT_TYPE_RA } pki_cert_type_t; -static char *cert_type_label[] = { "Root CA", "Sub CA", "RA" }; +static char *cert_type_label[] DBG_UNUSED = { "Root CA", "Sub CA", "RA" }; /** * Determine certificate type based on X.509 certificate flags @@ -73,7 +73,7 @@ static bool print_cert_info(certificate_t *cert, pki_cert_type_t cert_type) char digest_buf[HASH_SIZE_SHA256]; char base64_buf[HASH_SIZE_SHA256]; chunk_t cert_digest = {digest_buf, HASH_SIZE_SHA256}; - chunk_t cert_id, serial, encoding = chunk_empty; + chunk_t cert_id DBG_UNUSED, serial DBG_UNUSED, encoding = chunk_empty; x509_t *x509; bool success = FALSE; @@ -207,8 +207,7 @@ static bool write_cert(certificate_t *cert, pki_cert_type_t cert_type, bool force) { chunk_t encoding = chunk_empty; - time_t until; - bool written, valid; + bool written; if (path) { @@ -240,12 +239,14 @@ static bool write_cert(certificate_t *cert, pki_cert_type_t cert_type, path = "stdout"; } - valid = cert->get_validity(cert, NULL, NULL, &until); +#if DEBUG_LEVEL >= 1 + time_t until; + bool valid = cert->get_validity(cert, NULL, NULL, &until); DBG1(DBG_APP, "%s cert is %strusted, %s %T, %s'%s'", cert_type_label[cert_type], trusted ? "" : "un", valid ? "valid until" : "invalid since", &until, FALSE, path ? "written to " : "", path ? path : "not written"); - +#endif return TRUE; } @@ -466,16 +467,15 @@ bool pki_cert_extract_cert(chunk_t data, cred_encoding_type_t form) x509_t *x509 = (x509_t*)cert; certificate_t *cert_found = NULL; enumerator_t *certs; - chunk_t serial; - time_t from, until; - bool trusted, valid; + bool trusted DBG_UNUSED; if (!(x509->get_flags(x509) & X509_CA)) { DBG1(DBG_APP, "Issued certificate \"%Y\"", cert->get_subject(cert)); - serial = x509->get_serial(x509); +#if DEBUG_LEVEL >= 1 + chunk_t serial = x509->get_serial(x509); DBG1(DBG_APP, " serial: %#B", &serial); - +#endif if (stored) { DBG1(DBG_APP, "multiple certs received, only first stored"); @@ -490,12 +490,14 @@ bool pki_cert_extract_cert(chunk_t data, cred_encoding_type_t form) (cert_found == cert); certs->destroy(certs); - valid = cert->get_validity(cert, NULL, &from, &until); +#if DEBUG_LEVEL >= 1 + time_t from, until; + bool valid = cert->get_validity(cert, NULL, &from, &until); DBG1(DBG_APP, "Issued certificate is %strusted, " "valid from %T until %T (currently %svalid)", trusted ? "" : "not ", &from, FALSE, &until, FALSE, valid ? "" : "not "); - +#endif if (!cert->get_encoding(cert, form, &cert_encoding)) { DBG1(DBG_APP, "encoding certificate failed"); diff --git a/src/pki/scep/scep.c b/src/pki/scep/scep.c index 7bbef72ee..4684774bb 100644 --- a/src/pki/scep/scep.c +++ b/src/pki/scep/scep.c @@ -38,7 +38,7 @@ static const char *operations[] = { static const char *pkiStatus_values[] = { "0", "2", "3" }; -static const char *pkiStatus_names[] = { +static const char *pkiStatus_names[] DBG_UNUSED = { "SUCCESS", "FAILURE", "PENDING", @@ -47,7 +47,7 @@ static const char *pkiStatus_names[] = { static const char *msgType_values[] = { "3", "17", "19", "20", "21", "22" }; -static const char *msgType_names[] = { +static const char *msgType_names[] DBG_UNUSED = { "CertRep", "RenewalReq", "PKCSReq", @@ -57,7 +57,7 @@ static const char *msgType_names[] = { "Unknown" }; -static const char *failInfo_reasons[] = { +static const char *failInfo_reasons[] DBG_UNUSED = { "badAlg - unrecognized or unsupported algorithm identifier", "badMessageCheck - integrity check failed", "badRequest - transaction not permitted or supported", From 16c2def3ae1ba4bbe8b3b1fb6e4bd80f59796db2 Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Wed, 3 May 2023 12:31:45 +0200 Subject: [PATCH 50/53] conftest: Fix build with DEBUG_LEVEL < 1 --- src/conftest/hooks/force_cookie.c | 5 +++-- src/conftest/hooks/log_id.c | 4 ++++ src/conftest/hooks/log_ke.c | 4 ++++ src/conftest/hooks/log_ts.c | 4 ++++ 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/conftest/hooks/force_cookie.c b/src/conftest/hooks/force_cookie.c index 10b6ec6b0..a2bc0dda1 100644 --- a/src/conftest/hooks/force_cookie.c +++ b/src/conftest/hooks/force_cookie.c @@ -48,12 +48,13 @@ METHOD(listener_t, message, bool, if (payload->get_type(payload) == PLV2_NOTIFY) { notify_payload_t *notify = (notify_payload_t*)payload; - chunk_t data; if (notify->get_notify_type(notify) == COOKIE) { - data = notify->get_notification_data(notify); +#if DEBUG_LEVEL >= 1 + chunk_t data = notify->get_notification_data(notify); DBG1(DBG_CFG, "received COOKIE: %#B", &data); +#endif has_cookie = TRUE; break; } diff --git a/src/conftest/hooks/log_id.c b/src/conftest/hooks/log_id.c index 07caedfc5..15bfae2d4 100644 --- a/src/conftest/hooks/log_id.c +++ b/src/conftest/hooks/log_id.c @@ -35,6 +35,7 @@ METHOD(listener_t, message, bool, private_log_id_t *this, ike_sa_t *ike_sa, message_t *message, bool incoming, bool plain) { +#if DEBUG_LEVEL >= 1 if (incoming && plain) { enumerator_t *enumerator; @@ -62,6 +63,9 @@ METHOD(listener_t, message, bool, enumerator->destroy(enumerator); } return TRUE; +#else + return FALSE; +#endif } METHOD(hook_t, destroy, void, diff --git a/src/conftest/hooks/log_ke.c b/src/conftest/hooks/log_ke.c index 766686dd3..13153bd96 100644 --- a/src/conftest/hooks/log_ke.c +++ b/src/conftest/hooks/log_ke.c @@ -35,6 +35,7 @@ METHOD(listener_t, message, bool, private_log_ke_t *this, ike_sa_t *ike_sa, message_t *message, bool incoming, bool plain) { +#if DEBUG_LEVEL >= 1 if (incoming && plain) { enumerator_t *enumerator; @@ -54,6 +55,9 @@ METHOD(listener_t, message, bool, enumerator->destroy(enumerator); } return TRUE; +#else + return FALSE; +#endif } METHOD(hook_t, destroy, void, diff --git a/src/conftest/hooks/log_ts.c b/src/conftest/hooks/log_ts.c index 5533717ea..f750042ff 100644 --- a/src/conftest/hooks/log_ts.c +++ b/src/conftest/hooks/log_ts.c @@ -35,6 +35,7 @@ METHOD(listener_t, message, bool, private_log_ts_t *this, ike_sa_t *ike_sa, message_t *message, bool incoming, bool plain) { +#if DEBUG_LEVEL >= 1 if (incoming && plain) { enumerator_t *enumerator; @@ -77,6 +78,9 @@ METHOD(listener_t, message, bool, enumerator->destroy(enumerator); } return TRUE; +#else + return FALSE; +#endif } METHOD(hook_t, destroy, void, From 8e78d9fcec88e2262d0acfdf190578f08c4ad6b3 Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Tue, 2 May 2023 14:15:43 +0200 Subject: [PATCH 51/53] sw-collector: Fix build with DEBUG_LEVEL < 1 --- src/sw-collector/sw-collector.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/sw-collector/sw-collector.c b/src/sw-collector/sw-collector.c index 1685fdd29..728db4f4a 100644 --- a/src/sw-collector/sw-collector.c +++ b/src/sw-collector/sw-collector.c @@ -451,7 +451,7 @@ static int list_identifiers(sw_collector_db_t *db, sw_collector_db_query_t type) { enumerator_t *e; char *name, *package, *version; - uint32_t sw_id, count = 0, installed_count = 0, removed_count, installed; + uint32_t sw_id, count = 0, installed_count = 0, installed; e = db->create_sw_enumerator(db, type, NULL); if (!e) @@ -467,14 +467,14 @@ static int list_identifiers(sw_collector_db_t *db, sw_collector_db_query_t type) } count++; } - removed_count = count - installed_count; e->destroy(e); switch (type) { case SW_QUERY_ALL: DBG1(DBG_IMC, "retrieved %u software identities with %u installed " - "and %u removed", count, installed_count, removed_count); + "and %u removed", count, installed_count, + count - installed_count); break; case SW_QUERY_INSTALLED: DBG1(DBG_IMC, "retrieved %u installed software identities", count); @@ -629,7 +629,7 @@ static int migrate(sw_collector_db_t *db) char *package, *arch, *version; char package_filter[BUF_LEN]; - int res, count = 0; + int res, count DBG_UNUSED = 0; int status = EXIT_SUCCESS; enumerator_t *enumerator; From 21f01808ff8770c5ba24817284ba8de99bc88085 Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Tue, 2 May 2023 14:16:02 +0200 Subject: [PATCH 52/53] sec-updater: Fix build with DEBUG_LEVEL < 1 --- src/sec-updater/sec-updater.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sec-updater/sec-updater.c b/src/sec-updater/sec-updater.c index fd0a86372..1df442a21 100644 --- a/src/sec-updater/sec-updater.c +++ b/src/sec-updater/sec-updater.c @@ -173,7 +173,7 @@ static bool update_database(database_t *db, char *package, char *version, while (e->enumerate(e, &vid, &release, &sec_flag)) { char command[BUF_LEN]; - char found_char = ' '; + char found_char DBG_UNUSED = ' '; bool update_version = FALSE; if (streq(version, release)) From 027ba4d12e339107977d53394c8f810296c5ad08 Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Mon, 1 May 2023 12:35:08 +0200 Subject: [PATCH 53/53] github: Add build with DBG completely disabled --- .github/workflows/linux.yml | 3 +++ scripts/test.sh | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index e6211274e..6774da51f 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -45,6 +45,9 @@ jobs: - test: coverage - test: dist - test: nm + - test: no-dbg + - test: no-dbg + compiler: clang - test: fuzzing compiler: clang monolithic: yes diff --git a/scripts/test.sh b/scripts/test.sh index 44698206c..a2e8b20fd 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -221,7 +221,7 @@ wolfssl) printf-builtin) CONFIG="--with-printf-hooks=builtin" ;; -all|codeql|coverage|sonarcloud) +all|codeql|coverage|sonarcloud|no-dbg) if [ "$TEST" = "sonarcloud" ]; then if [ -z "$SONAR_PROJECT" -o -z "$SONAR_ORGANIZATION" -o -z "$SONAR_TOKEN" ]; then echo "The SONAR_PROJECT, SONAR_ORGANIZATION and SONAR_TOKEN" \ @@ -233,6 +233,9 @@ all|codeql|coverage|sonarcloud) # don't run tests, only analyze built code TARGET= fi + if [ "$TEST" = "no-dbg" ]; then + CFLAGS="$CFLAGS -DDEBUG_LEVEL=-1" + fi CONFIG="--enable-all --disable-android-dns --disable-android-log --disable-kernel-pfroute --disable-keychain --disable-lock-profiler --disable-padlock --disable-fuzzing