summaryrefslogtreecommitdiffstats
path: root/lib/utils_base.c
diff options
context:
space:
mode:
authorLorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>2023-10-15 20:07:33 (GMT)
committerLorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>2023-10-15 20:07:33 (GMT)
commit685c2931dfc3cb67b7605eba143598512a66c037 (patch)
tree4d73bf71eb19e7c63f3d649fa969c63104a4b456 /lib/utils_base.c
parent0875351a8385d6587133c2af541d102f31c17a46 (diff)
parentbf70f5f847e3407af572d1768cca747af270b993 (diff)
downloadmonitoring-plugins-685c2931dfc3cb67b7605eba143598512a66c037.tar.gz
Merge branch 'master' into dev/check_ssh-patches
Diffstat (limited to 'lib/utils_base.c')
-rw-r--r--lib/utils_base.c33
1 files changed, 26 insertions, 7 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 */
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[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));