diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/utils_base.c | 33 | ||||
-rw-r--r-- | lib/utils_base.h | 4 |
2 files changed, 29 insertions, 8 deletions
diff --git a/lib/utils_base.c b/lib/utils_base.c index c458cf6..0f52126 100644 --- a/lib/utils_base.c +++ b/lib/utils_base.c | |||
@@ -402,26 +402,45 @@ 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 | */ |
404 | char *_np_state_generate_key() { | 404 | char *_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[256]; |
413 | 411 | ||
412 | #ifdef USE_OPENSSL | ||
413 | /* | ||
414 | * This code path is chosen if openssl is available (which should be the most common | ||
415 | * scenario). Alternatively, the gnulib implementation/ | ||
416 | * | ||
417 | */ | ||
418 | EVP_MD_CTX *ctx = EVP_MD_CTX_new(); | ||
419 | |||
420 | EVP_DigestInit(ctx, EVP_sha256()); | ||
421 | |||
422 | for(i=0; i<this_monitoring_plugin->argc; i++) { | ||
423 | EVP_DigestUpdate(ctx, argv[i], strlen(argv[i])); | ||
424 | } | ||
425 | |||
426 | EVP_DigestFinal(ctx, result, NULL); | ||
427 | #else | ||
428 | |||
429 | struct sha256_ctx ctx; | ||
430 | |||
414 | for(i=0; i<this_monitoring_plugin->argc; i++) { | 431 | for(i=0; i<this_monitoring_plugin->argc; i++) { |
415 | sha256_process_bytes(argv[i], strlen(argv[i]), &ctx); | 432 | sha256_process_bytes(argv[i], strlen(argv[i]), &ctx); |
416 | } | 433 | } |
417 | 434 | ||
418 | sha256_finish_ctx(&ctx, &result); | 435 | sha256_finish_ctx(&ctx, result); |
419 | 436 | #endif // FOUNDOPENSSL | |
437 | |||
420 | for (i=0; i<20; ++i) { | 438 | for (i=0; i<20; ++i) { |
421 | sprintf(&keyname[2*i], "%02x", result[i]); | 439 | sprintf(&keyname[2*i], "%02x", result[i]); |
422 | } | 440 | } |
441 | |||
423 | keyname[40]='\0'; | 442 | keyname[40]='\0'; |
424 | 443 | ||
425 | p = strdup(keyname); | 444 | p = strdup(keyname); |
426 | if(p==NULL) { | 445 | if(p==NULL) { |
427 | die(STATE_UNKNOWN, _("Cannot execute strdup: %s"), strerror(errno)); | 446 | 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 */ |