summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/utils_base.c27
-rw-r--r--lib/utils_base.h4
2 files changed, 22 insertions, 9 deletions
diff --git a/lib/utils_base.c b/lib/utils_base.c
index eb1823bb..39032cbd 100644
--- a/lib/utils_base.c
+++ b/lib/utils_base.c
@@ -402,26 +402,37 @@ 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]; 407 unsigned char result[20];
409 char keyname[41]; 408 char keyname[41];
410 char *p=NULL; 409 char *p=NULL;
410#ifdef USE_OPENSSL
411 /*
412 * This code path is chosen if openssl is available (which should be the most common
413 * scenario). Alternatively, the gnulib implementation/
414 *
415 */
416 EVP_MD_CTX *ctx = EVP_MD_CTX_new();
417
418 EVP_DigestInit(ctx, EVP_sha256());
419
420 for(i=0; i<this_monitoring_plugin->argc; i++) {
421 EVP_DigestUpdate(ctx, argv[i], strlen(argv[i]));
422 }
423
424 EVP_DigestFinalXOF(ctx, &result, 20);
425#else
426 struct sha256_ctx ctx;
411 427
412 sha256_init_ctx(&ctx);
413
414 for(i=0; i<this_monitoring_plugin->argc; i++) { 428 for(i=0; i<this_monitoring_plugin->argc; i++) {
415 sha256_process_bytes(argv[i], strlen(argv[i]), &ctx); 429 sha256_process_bytes(argv[i], strlen(argv[i]), &ctx);
416 } 430 }
417 431
418 sha256_finish_ctx(&ctx, &result); 432 sha256_finish_ctx(&ctx, &result);
419 433#endif // FOUNDOPENSSL
420 for (i=0; i<20; ++i) {
421 sprintf(&keyname[2*i], "%02x", result[i]);
422 }
423 keyname[40]='\0'; 434 keyname[40]='\0';
424 435
425 p = strdup(keyname); 436 p = strdup(keyname);
426 if(p==NULL) { 437 if(p==NULL) {
427 die(STATE_UNKNOWN, _("Cannot execute strdup: %s"), strerror(errno)); 438 die(STATE_UNKNOWN, _("Cannot execute strdup: %s"), strerror(errno));
diff --git a/lib/utils_base.h b/lib/utils_base.h
index 59065504..9cb42767 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 */