summaryrefslogtreecommitdiffstats
path: root/lib/utils_base.c
diff options
context:
space:
mode:
authorRincewindsHat <12514511+RincewindsHat@users.noreply.github.com>2023-03-12 12:14:41 +0100
committerRincewindsHat <12514511+RincewindsHat@users.noreply.github.com>2023-04-18 00:32:43 +0200
commit7c98e2b345b91d8ef3fb1f7a1bcf74194d54c966 (patch)
tree15930ae208f7354ffd7989f68fcbcfc3d4e0bdce /lib/utils_base.c
parent8700f497160cfc2cce8918c8cd8922b7320c510a (diff)
downloadmonitoring-plugins-7c98e2b345b91d8ef3fb1f7a1bcf74194d54c966.tar.gz
Use default OPENSSL sha functions if available
Diffstat (limited to 'lib/utils_base.c')
-rw-r--r--lib/utils_base.c27
1 files changed, 19 insertions, 8 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));