From dd249c5d4bbce1c1250322dab8c8d0d69b0dca34 Mon Sep 17 00:00:00 2001 From: christian-2 <49752982+christian-2@users.noreply.github.com> Date: Tue, 13 Dec 2022 23:48:36 +0100 Subject: check_disk: Find accessible mount path if multiple are available (#1820) * fixes #1819 * mount entries also have to be accessible according to get_fs_usage() --- lib/utils_disk.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'lib') diff --git a/lib/utils_disk.c b/lib/utils_disk.c index c7c9126e..4f16068a 100644 --- a/lib/utils_disk.c +++ b/lib/utils_disk.c @@ -28,6 +28,7 @@ #include "common.h" #include "utils_disk.h" +#include "gl/fsusage.h" void np_add_name (struct name_list **list, const char *name) @@ -127,9 +128,12 @@ np_set_best_match(struct parameter_list *desired, struct mount_entry *mount_list size_t name_len = strlen(d->name); size_t best_match_len = 0; struct mount_entry *best_match = NULL; + struct fs_usage fsp; /* set best match if path name exactly matches a mounted device name */ for (me = mount_list; me; me = me->me_next) { + if (get_fs_usage(me->me_mountdir, me->me_devname, &fsp) < 0) + continue; /* skip if permissions do not suffice for accessing device */ if (strcmp(me->me_devname, d->name)==0) best_match = me; } @@ -137,6 +141,8 @@ np_set_best_match(struct parameter_list *desired, struct mount_entry *mount_list /* set best match by directory name if no match was found by devname */ if (! best_match) { for (me = mount_list; me; me = me->me_next) { + if (get_fs_usage(me->me_mountdir, me->me_devname, &fsp) < 0) + continue; /* skip if permissions do not suffice for accessing device */ size_t len = strlen (me->me_mountdir); if ((exact == FALSE && (best_match_len <= len && len <= name_len && (len == 1 || strncmp (me->me_mountdir, d->name, len) == 0))) -- cgit v1.2.3-74-g34f1 From 34c6fae0ca405cddf2d60e76d785fc520d336582 Mon Sep 17 00:00:00 2001 From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> Date: Tue, 31 Jan 2023 15:17:51 +0100 Subject: Replace sha1 with sha256 in utils_base --- lib/utils_base.c | 8 ++++---- lib/utils_base.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/utils_base.c b/lib/utils_base.c index 08fa215c..eb1823bb 100644 --- a/lib/utils_base.c +++ b/lib/utils_base.c @@ -402,20 +402,20 @@ int mp_translate_state (char *state_text) { * parse of argv, so that uniqueness in parameters are reflected there. */ char *_np_state_generate_key() { - struct sha1_ctx ctx; + struct sha256_ctx ctx; int i; char **argv = this_monitoring_plugin->argv; unsigned char result[20]; char keyname[41]; char *p=NULL; - sha1_init_ctx(&ctx); + sha256_init_ctx(&ctx); for(i=0; iargc; i++) { - sha1_process_bytes(argv[i], strlen(argv[i]), &ctx); + sha256_process_bytes(argv[i], strlen(argv[i]), &ctx); } - sha1_finish_ctx(&ctx, &result); + sha256_finish_ctx(&ctx, &result); for (i=0; i<20; ++i) { sprintf(&keyname[2*i], "%02x", result[i]); diff --git a/lib/utils_base.h b/lib/utils_base.h index 9482f23b..59065504 100644 --- a/lib/utils_base.h +++ b/lib/utils_base.h @@ -2,7 +2,7 @@ #define _UTILS_BASE_ /* Header file for Monitoring Plugins utils_base.c */ -#include "sha1.h" +#include "sha256.h" /* This file holds header information for thresholds - use this in preference to individual plugin logic */ -- cgit v1.2.3-74-g34f1 From dd91860a46f04b14bacfab2e97ef745189fc3627 Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Wed, 1 Feb 2023 01:23:04 +0100 Subject: Also link LIB_CRYPTO against tests --- lib/tests/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/tests/Makefile.am b/lib/tests/Makefile.am index a8d7adee..31d79df6 100644 --- a/lib/tests/Makefile.am +++ b/lib/tests/Makefile.am @@ -27,7 +27,7 @@ endif AM_CFLAGS = -g -I$(top_srcdir)/lib -I$(top_srcdir)/gl $(tap_cflags) AM_LDFLAGS = $(tap_ldflags) -ltap -LDADD = $(top_srcdir)/lib/libmonitoringplug.a $(top_srcdir)/gl/libgnu.a +LDADD = $(top_srcdir)/lib/libmonitoringplug.a $(top_srcdir)/gl/libgnu.a $(LIB_CRYPTO) SOURCES = test_utils.c test_disk.c test_tcp.c test_cmd.c test_base64.c test_ini1.c test_ini3.c test_opts1.c test_opts2.c test_opts3.c -- cgit v1.2.3-74-g34f1 From ce1453a45a71df51cddff914e2dcc196f3966a3a Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Wed, 1 Feb 2023 10:56:33 +0100 Subject: Fix hashes in tests since we are using sha256 now --- lib/tests/test_utils.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/tests/test_utils.c b/lib/tests/test_utils.c index f35b7e27..bc00fac1 100644 --- a/lib/tests/test_utils.c +++ b/lib/tests/test_utils.c @@ -309,7 +309,7 @@ main (int argc, char **argv) /* This is the result of running ./test_utils */ temp_string = (char *) _np_state_generate_key(); - ok(!strcmp(temp_string, "83d877b6cdfefb5d6f06101fd6fe76762f21792c"), "Got hash with exe and no parameters" ) || + ok(!strcmp(temp_string, "e2d17f995fd4c020411b85e3e3d0ff7306d4147e"), "Got hash with exe and no parameters" ) || diag( "You are probably running in wrong directory. Must run as ./test_utils" ); @@ -319,7 +319,7 @@ main (int argc, char **argv) this_monitoring_plugin->argv[2] = "--and"; this_monitoring_plugin->argv[3] = "now"; temp_string = (char *) _np_state_generate_key(); - ok(!strcmp(temp_string, "94b5e17bf5abf51cb15aff5f69b96f2f8dac5ecd"), "Got based on expected argv" ); + ok(!strcmp(temp_string, "bd72da9f78ff1419fad921ea5e43ce56508aef6c"), "Got based on expected argv" ); unsetenv("MP_STATE_PATH"); temp_string = (char *) _np_state_calculate_location_prefix(); @@ -342,7 +342,7 @@ main (int argc, char **argv) np_enable_state(NULL, 51); temp_state_key = this_monitoring_plugin->state; ok( !strcmp(temp_state_key->plugin_name, "check_test"), "Got plugin name" ); - ok( !strcmp(temp_state_key->name, "83d877b6cdfefb5d6f06101fd6fe76762f21792c"), "Got generated filename" ); + ok( !strcmp(temp_state_key->name, "e2d17f995fd4c020411b85e3e3d0ff7306d4147e"), "Got generated filename" ); np_enable_state("allowedchars_in_keyname", 77); -- cgit v1.2.3-74-g34f1 From 9898a8ad7dabfabfe80785585a5bbc30b678bdb0 Mon Sep 17 00:00:00 2001 From: Kristian Schuster <116557017+KriSchu@users.noreply.github.com> Date: Sun, 19 Feb 2023 13:44:04 +0100 Subject: utils_disk: add name_prev pointer to struct parameter_list Also added handling of name_prev in np_add_parameter and np_delete_parameter. This make calling the np_delete_parameter function easier, because it requires the previous element as second argument. --- lib/utils_disk.c | 19 +++++++++++++++++-- lib/utils_disk.h | 1 + 2 files changed, 18 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/utils_disk.c b/lib/utils_disk.c index c7c9126e..a1181d37 100644 --- a/lib/utils_disk.c +++ b/lib/utils_disk.c @@ -46,9 +46,10 @@ np_add_parameter(struct parameter_list **list, const char *name) struct parameter_list *current = *list; struct parameter_list *new_path; new_path = (struct parameter_list *) malloc (sizeof *new_path); - new_path->name = (char *) name; + new_path->name = (char *) malloc(strlen(name) + 1); new_path->best_match = NULL; new_path->name_next = NULL; + new_path->name_prev = NULL; new_path->freespace_bytes = NULL; new_path->freespace_units = NULL; new_path->freespace_percent = NULL; @@ -74,13 +75,17 @@ np_add_parameter(struct parameter_list **list, const char *name) new_path->dused_inodes_percent = 0; new_path->dfree_inodes_percent = 0; + strcpy(new_path->name, name); + if (current == NULL) { *list = new_path; + new_path->name_prev = NULL; } else { while (current->name_next) { current = current->name_next; } current->name_next = new_path; + new_path->name_prev = current; } return new_path; } @@ -89,6 +94,9 @@ np_add_parameter(struct parameter_list **list, const char *name) struct parameter_list * np_del_parameter(struct parameter_list *item, struct parameter_list *prev) { + if (item == NULL) { + return NULL; + } struct parameter_list *next; if (item->name_next) @@ -96,10 +104,17 @@ np_del_parameter(struct parameter_list *item, struct parameter_list *prev) else next = NULL; - free(item); + if (next) + next->name_prev = prev; + if (prev) prev->name_next = next; + if (item->name) { + free(item->name); + } + free(item); + return next; } diff --git a/lib/utils_disk.h b/lib/utils_disk.h index bf52e4ce..3b5a45f8 100644 --- a/lib/utils_disk.h +++ b/lib/utils_disk.h @@ -24,6 +24,7 @@ struct parameter_list char *group; struct mount_entry *best_match; struct parameter_list *name_next; + struct parameter_list *name_prev; uintmax_t total, available, available_to_root, used, inodes_free, inodes_free_to_root, inodes_used, inodes_total; double dfree_pct, dused_pct; -- cgit v1.2.3-74-g34f1