diff options
author | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2023-09-21 10:03:52 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-21 10:03:52 (GMT) |
commit | 7e81cb3c1fb4123bd4d423b2c9e86538dec19e39 (patch) | |
tree | 1ef0975b2a059daa7b8552aaf6371b3320ef477b /lib/utils_base.c | |
parent | 220455a11e8f1dd3a86ac4725cf0c799c8e3b21b (diff) | |
parent | d5d0b50e89ee600b6a605344aad004c60b88994d (diff) | |
download | monitoring-plugins-7e81cb3c1fb4123bd4d423b2c9e86538dec19e39.tar.gz |
Merge pull request #1868 from RincewindsHat/compiler_warning_part_3
Replace deprecated TLS client functions
Diffstat (limited to 'lib/utils_base.c')
-rw-r--r-- | lib/utils_base.c | 33 |
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 | */ |
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)); |