X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fnetwork.c;h=484e610053bc3d4248c127de9e82a32dcd693f52;hb=8c5927c52f4eefebaad3a6ecadc253ee9007ebb5;hp=46ec059fb66e7fc516ca43bd06d4efa5ac51005f;hpb=3e2272cea52a2dace364c82fbcfeecf9dd9fbd34;p=collectd.git diff --git a/src/network.c b/src/network.c index 46ec059f..484e6100 100644 --- a/src/network.c +++ b/src/network.c @@ -29,7 +29,6 @@ #include "plugin.h" #include "common.h" -#include "configfile.h" #include "utils_fbhash.h" #include "utils_cache.h" #include "utils_complain.h" @@ -304,7 +303,7 @@ static char *send_buffer; static char *send_buffer_ptr; static int send_buffer_fill; static cdtime_t send_buffer_last_update; -static value_list_t send_buffer_vl = VALUE_LIST_STATIC; +static value_list_t send_buffer_vl = VALUE_LIST_INIT; static pthread_mutex_t send_buffer_lock = PTHREAD_MUTEX_INITIALIZER; /* XXX: These counters are incremented from one place only. The spot in which @@ -1149,7 +1148,7 @@ static int parse_part_sign_sha256 (sockent_t *se, /* {{{ */ if (memcmp (pss.hash, hash, sizeof (pss.hash)) != 0) { WARNING ("network plugin: Verifying HMAC-SHA-256 signature failed: " - "Hash mismatch."); + "Hash mismatch. Username: %s", pss.username); } else { @@ -1233,8 +1232,8 @@ static int parse_part_encr_aes256 (sockent_t *se, /* {{{ */ /* Make sure at least the header if available. */ if (buffer_len <= PART_ENCRYPTION_AES256_SIZE) { - ERROR ("network plugin: Decryption failed: " - "Discarding short packet."); + NOTICE ("network plugin: parse_part_encr_aes256: " + "Discarding short packet."); return (-1); } @@ -1249,8 +1248,8 @@ static int parse_part_encr_aes256 (sockent_t *se, /* {{{ */ if ((part_size <= PART_ENCRYPTION_AES256_SIZE) || (part_size > buffer_len)) { - ERROR ("network plugin: Decryption failed: " - "Discarding part with invalid size."); + NOTICE ("network plugin: parse_part_encr_aes256: " + "Discarding part with invalid size."); return (-1); } @@ -1261,19 +1260,15 @@ static int parse_part_encr_aes256 (sockent_t *se, /* {{{ */ if ((username_len == 0) || (username_len > (part_size - (PART_ENCRYPTION_AES256_SIZE + 1)))) { - ERROR ("network plugin: Decryption failed: " - "Discarding part with invalid username length."); + NOTICE ("network plugin: parse_part_encr_aes256: " + "Discarding part with invalid username length."); return (-1); } assert (username_len > 0); pea.username = malloc (username_len + 1); if (pea.username == NULL) - { - ERROR ("network plugin: Decryption failed: " - "malloc() failed."); return (-ENOMEM); - } BUFFER_READ (pea.username, username_len); pea.username[username_len] = 0; @@ -1288,8 +1283,7 @@ static int parse_part_encr_aes256 (sockent_t *se, /* {{{ */ pea.username); if (cypher == NULL) { - ERROR ("network plugin: Decryption failed: " - "Failed to get cypher. Username: %s", pea.username); + ERROR ("network plugin: Failed to get cypher. Username: %s", pea.username); sfree (pea.username); return (-1); } @@ -1322,8 +1316,7 @@ static int parse_part_encr_aes256 (sockent_t *se, /* {{{ */ buffer + buffer_offset, payload_len); if (memcmp (hash, pea.hash, sizeof (hash)) != 0) { - ERROR ("network plugin: Decryption failed: " - "Checksum mismatch. Username: %s", pea.username); + ERROR ("network plugin: Checksum mismatch. Username: %s", pea.username); sfree (pea.username); return (-1); } @@ -1438,7 +1431,12 @@ static int parse_packet (sockent_t *se, /* {{{ */ status = parse_part_encr_aes256 (se, &buffer, &buffer_size, flags); if (status != 0) + { + ERROR ("network plugin: Decrypting AES256 " + "part failed " + "with status %i.", status); break; + } } #if HAVE_LIBGCRYPT else if ((se->data.server.security_level == SECURITY_LEVEL_ENCRYPT) @@ -2087,33 +2085,28 @@ static int sockent_init_crypto (sockent_t *se) /* {{{ */ } else /* (se->type == SOCKENT_TYPE_SERVER) */ { - if (se->data.server.security_level > SECURITY_LEVEL_NONE) + if ((se->data.server.security_level > SECURITY_LEVEL_NONE) + && (se->data.server.auth_file == NULL)) + { + ERROR ("network plugin: Server socket with security requested, " + "but no \"AuthFile\" is configured."); + return (-1); + } + if (se->data.server.auth_file != NULL) { if (network_init_gcrypt () < 0) { - ERROR ("network plugin: Cannot configure server socket with " - "security: Failed to initialize crypto library."); + ERROR ("network plugin: Cannot configure server socket with security: " + "Failed to initialize crypto library."); return (-1); } - if (se->data.server.auth_file == NULL) - { - ERROR ("network plugin: Server socket with " - "security requested, but no " - "password file is configured."); - return (-1); - } - } - if (se->data.server.auth_file != NULL) - { se->data.server.userdb = fbh_create (se->data.server.auth_file); if (se->data.server.userdb == NULL) { - ERROR ("network plugin: Reading password file " - "`%s' failed.", + ERROR ("network plugin: Reading password file \"%s\" failed.", se->data.server.auth_file); - if (se->data.server.security_level > SECURITY_LEVEL_NONE) - return (-1); + return (-1); } } } @@ -3393,7 +3386,6 @@ static int network_stats_read (void) /* {{{ */ vl.values = values; vl.values_len = 2; vl.time = 0; - sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "network", sizeof (vl.plugin)); /* Octets received / sent */ @@ -3451,14 +3443,6 @@ static int network_init (void) return (0); have_init = 1; -#if HAVE_LIBGCRYPT - if (network_init_gcrypt () < 0) - { - ERROR ("network plugin: Failed to initialize crypto library."); - return (-1); - } -#endif - if (network_config_stats) plugin_register_read ("network", network_stats_read);