summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/utils_base.c37
-rw-r--r--lib/utils_base.h4
2 files changed, 33 insertions, 8 deletions
diff --git a/lib/utils_base.c b/lib/utils_base.c
index c458cf6..176fa85 100644
--- a/lib/utils_base.c
+++ b/lib/utils_base.c
@@ -402,26 +402,49 @@ int mp_translate_state (char *state_text) {
402 * parse of argv, so that uniqueness in parameters are reflected there. 402 * parse of argv, so that uniqueness in parameters are reflected there.
403 */ 403 */
404char *_np_state_generate_key() { 404char *_np_state_generate_key() {
405 struct sha256_ctx ctx;
406 int i; 405 int i;
407 char **argv = this_monitoring_plugin->argv; 406 char **argv = this_monitoring_plugin->argv;
408 unsigned char result[20];
409 char keyname[41]; 407 char keyname[41];
410 char *p=NULL; 408 char *p=NULL;
411 409
412 sha256_init_ctx(&ctx); 410 unsigned char *result = malloc(256 * sizeof(unsigned char));
413 411
412 if (result == NULL) {
413 die(STATE_UNKNOWN, _("Failed to allocate memory for hashes: %s"), strerror(errno));
414 }
415
416#ifdef USE_OPENSSL
417 /*
418 * This code path is chosen if openssl is available (which should be the most common
419 * scenario). Alternatively, the gnulib implementation/
420 *
421 */
422 EVP_MD_CTX *ctx = EVP_MD_CTX_new();
423
424 EVP_DigestInit(ctx, EVP_sha256());
425
426 for(i=0; i<this_monitoring_plugin->argc; i++) {
427 EVP_DigestUpdate(ctx, argv[i], strlen(argv[i]));
428 }
429
430 EVP_DigestFinal(ctx, result, NULL);
431#else
432
433 struct sha256_ctx ctx;
434
414 for(i=0; i<this_monitoring_plugin->argc; i++) { 435 for(i=0; i<this_monitoring_plugin->argc; i++) {
415 sha256_process_bytes(argv[i], strlen(argv[i]), &ctx); 436 sha256_process_bytes(argv[i], strlen(argv[i]), &ctx);
416 } 437 }
417 438
418 sha256_finish_ctx(&ctx, &result); 439 sha256_finish_ctx(&ctx, result);
419 440#endif // FOUNDOPENSSL
441
420 for (i=0; i<20; ++i) { 442 for (i=0; i<20; ++i) {
421 sprintf(&keyname[2*i], "%02x", result[i]); 443 sprintf(&keyname[2*i], "%02x", result[i]);
422 } 444 }
445
423 keyname[40]='\0'; 446 keyname[40]='\0';
424 447
425 p = strdup(keyname); 448 p = strdup(keyname);
426 if(p==NULL) { 449 if(p==NULL) {
427 die(STATE_UNKNOWN, _("Cannot execute strdup: %s"), strerror(errno)); 450 die(STATE_UNKNOWN, _("Cannot execute strdup: %s"), strerror(errno));
diff --git a/lib/utils_base.h b/lib/utils_base.h
index 5906550..9cb4276 100644
--- a/lib/utils_base.h
+++ b/lib/utils_base.h
@@ -2,7 +2,9 @@
2#define _UTILS_BASE_ 2#define _UTILS_BASE_
3/* Header file for Monitoring Plugins utils_base.c */ 3/* Header file for Monitoring Plugins utils_base.c */
4 4
5#include "sha256.h" 5#ifndef USE_OPENSSL
6# include "sha256.h"
7#endif
6 8
7/* This file holds header information for thresholds - use this in preference to 9/* This file holds header information for thresholds - use this in preference to
8 individual plugin logic */ 10 individual plugin logic */