summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/parse_ini.c4
-rw-r--r--lib/tests/Makefile.am2
-rw-r--r--lib/tests/test_cmd.c14
-rw-r--r--lib/tests/test_disk.c4
-rwxr-xr-xlib/tests/test_ini3.t2
-rwxr-xr-xlib/tests/test_opts3.t2
-rw-r--r--lib/tests/test_utils.c8
-rw-r--r--lib/utils_base.c16
-rw-r--r--lib/utils_base.h2
-rw-r--r--lib/utils_cmd.c2
-rw-r--r--lib/utils_disk.c19
-rw-r--r--lib/utils_disk.h1
12 files changed, 46 insertions, 30 deletions
diff --git a/lib/parse_ini.c b/lib/parse_ini.c
index 25abc89..547af43 100644
--- a/lib/parse_ini.c
+++ b/lib/parse_ini.c
@@ -78,7 +78,7 @@ static char *default_file_in_path(void);
78/* 78/*
79 * Parse_locator decomposes a string of the form 79 * Parse_locator decomposes a string of the form
80 * [stanza][@filename] 80 * [stanza][@filename]
81 * into its seperate parts. 81 * into its separate parts.
82 */ 82 */
83static void 83static void
84parse_locator(const char *locator, const char *def_stanza, np_ini_info *i) 84parse_locator(const char *locator, const char *def_stanza, np_ini_info *i)
@@ -169,7 +169,7 @@ read_defaults(FILE *f, const char *stanza, np_arg_list **opts)
169 if (isspace(c)) 169 if (isspace(c))
170 continue; 170 continue;
171 switch (c) { 171 switch (c) {
172 /* globble up coment lines */ 172 /* globble up comment lines */
173 case ';': 173 case ';':
174 case '#': 174 case '#':
175 GOBBLE_TO(f, c, '\n'); 175 GOBBLE_TO(f, c, '\n');
diff --git a/lib/tests/Makefile.am b/lib/tests/Makefile.am
index a8d7ade..31d79df 100644
--- a/lib/tests/Makefile.am
+++ b/lib/tests/Makefile.am
@@ -27,7 +27,7 @@ endif
27 27
28AM_CFLAGS = -g -I$(top_srcdir)/lib -I$(top_srcdir)/gl $(tap_cflags) 28AM_CFLAGS = -g -I$(top_srcdir)/lib -I$(top_srcdir)/gl $(tap_cflags)
29AM_LDFLAGS = $(tap_ldflags) -ltap 29AM_LDFLAGS = $(tap_ldflags) -ltap
30LDADD = $(top_srcdir)/lib/libmonitoringplug.a $(top_srcdir)/gl/libgnu.a 30LDADD = $(top_srcdir)/lib/libmonitoringplug.a $(top_srcdir)/gl/libgnu.a $(LIB_CRYPTO)
31 31
32SOURCES = 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 32SOURCES = 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
33 33
diff --git a/lib/tests/test_cmd.c b/lib/tests/test_cmd.c
index 29ca42a..4bb60aa 100644
--- a/lib/tests/test_cmd.c
+++ b/lib/tests/test_cmd.c
@@ -176,14 +176,14 @@ main (int argc, char **argv)
176 ok (result == UNSET, "(initialised) Checking exit code is reset"); 176 ok (result == UNSET, "(initialised) Checking exit code is reset");
177 177
178 command = (char *)malloc(COMMAND_LINE); 178 command = (char *)malloc(COMMAND_LINE);
179 strcpy(command, "/bin/echo3456 non-existant command"); 179 strcpy(command, "/bin/echo3456 non-existent command");
180 result = cmd_run (command, &chld_out, &chld_err, 0); 180 result = cmd_run (command, &chld_out, &chld_err, 0);
181 181
182 ok (chld_out.lines == 0, 182 ok (chld_out.lines == 0,
183 "Non existant command, so no output"); 183 "Non existent command, so no output");
184 ok (chld_err.lines == 0, 184 ok (chld_err.lines == 0,
185 "No stderr either"); 185 "No stderr either");
186 ok (result == 3, "Get return code 3 (?) for non-existant command"); 186 ok (result == 3, "Get return code 3 (?) for non-existent command");
187 187
188 188
189 /* ensure everything is empty again */ 189 /* ensure everything is empty again */
@@ -192,14 +192,14 @@ main (int argc, char **argv)
192 result = UNSET; 192 result = UNSET;
193 193
194 command = (char *)malloc(COMMAND_LINE); 194 command = (char *)malloc(COMMAND_LINE);
195 strcpy(command, "/bin/sh non-existant-file"); 195 strcpy(command, "/bin/sh non-existent-file");
196 result = cmd_run (command, &chld_out, &chld_err, 0); 196 result = cmd_run (command, &chld_out, &chld_err, 0);
197 197
198 ok (chld_out.lines == 0, 198 ok (chld_out.lines == 0,
199 "/bin/sh returns no stdout when file is missing..."); 199 "/bin/sh returns no stdout when file is missing...");
200 ok (chld_err.lines == 1, 200 ok (chld_err.lines == 1,
201 "...but does give an error line"); 201 "...but does give an error line");
202 ok (strstr(chld_err.line[0],"non-existant-file") != NULL, "And missing filename is in error message"); 202 ok (strstr(chld_err.line[0],"non-existent-file") != NULL, "And missing filename is in error message");
203 ok (result != 0, "Get non-zero return code from /bin/sh"); 203 ok (result != 0, "Get non-zero return code from /bin/sh");
204 204
205 205
@@ -219,11 +219,11 @@ main (int argc, char **argv)
219 result = UNSET; 219 result = UNSET;
220 220
221 command = (char *)malloc(COMMAND_LINE); 221 command = (char *)malloc(COMMAND_LINE);
222 strcpy(command, "/bin/non-existant-command"); 222 strcpy(command, "/bin/non-existent-command");
223 result = cmd_run (command, &chld_out, &chld_err, 0); 223 result = cmd_run (command, &chld_out, &chld_err, 0);
224 224
225 ok (chld_out.lines == 0, 225 ok (chld_out.lines == 0,
226 "/bin/non-existant-command returns no stdout..."); 226 "/bin/non-existent-command returns no stdout...");
227 ok (chld_err.lines == 0, 227 ok (chld_err.lines == 0,
228 "...and no stderr output either"); 228 "...and no stderr output either");
229 ok (result == 3, "Get return code 3 = UNKNOWN when command does not exist"); 229 ok (result == 3, "Get return code 3 = UNKNOWN when command does not exist");
diff --git a/lib/tests/test_disk.c b/lib/tests/test_disk.c
index f6477ac..9bd68c7 100644
--- a/lib/tests/test_disk.c
+++ b/lib/tests/test_disk.c
@@ -88,10 +88,10 @@ main (int argc, char **argv)
88 cflags, 3,strdup("regex on dev names:")); 88 cflags, 3,strdup("regex on dev names:"));
89 np_test_mount_entry_regex(dummy_mount_list, strdup("/foo"), 89 np_test_mount_entry_regex(dummy_mount_list, strdup("/foo"),
90 cflags, 0, 90 cflags, 0,
91 strdup("regex on non existant dev/path:")); 91 strdup("regex on non existent dev/path:"));
92 np_test_mount_entry_regex(dummy_mount_list, strdup("/Foo"), 92 np_test_mount_entry_regex(dummy_mount_list, strdup("/Foo"),
93 cflags | REG_ICASE,0, 93 cflags | REG_ICASE,0,
94 strdup("regi on non existant dev/path:")); 94 strdup("regi on non existent dev/path:"));
95 np_test_mount_entry_regex(dummy_mount_list, strdup("/c.t0"), 95 np_test_mount_entry_regex(dummy_mount_list, strdup("/c.t0"),
96 cflags, 3, 96 cflags, 3,
97 strdup("partial devname regex match:")); 97 strdup("partial devname regex match:"));
diff --git a/lib/tests/test_ini3.t b/lib/tests/test_ini3.t
index a2ca94a..41169db 100755
--- a/lib/tests/test_ini3.t
+++ b/lib/tests/test_ini3.t
@@ -10,7 +10,7 @@ if (! -e "./test_ini3") {
10# array of argument arrays 10# array of argument arrays
11# - First value is the expected return code 11# - First value is the expected return code
12# - 2nd value is the NAGIOS_CONFIG_PATH 12# - 2nd value is the NAGIOS_CONFIG_PATH
13# TODO: looks like we look in default path after looking trough this variable - shall we? 13# TODO: looks like we look in default path after looking through this variable - shall we?
14# - 3rd value is the plugin name 14# - 3rd value is the plugin name
15# - 4th is the ini locator 15# - 4th is the ini locator
16my @TESTS = ( 16my @TESTS = (
diff --git a/lib/tests/test_opts3.t b/lib/tests/test_opts3.t
index 8d974ca..d77a35c 100755
--- a/lib/tests/test_opts3.t
+++ b/lib/tests/test_opts3.t
@@ -10,7 +10,7 @@ if (! -e "./test_opts3") {
10# array of argument arrays 10# array of argument arrays
11# - First value is the expected return code 11# - First value is the expected return code
12# - 2nd value is the NAGIOS_CONFIG_PATH 12# - 2nd value is the NAGIOS_CONFIG_PATH
13# TODO: looks like we look in default path after looking trough this variable - shall we? 13# TODO: looks like we look in default path after looking through this variable - shall we?
14# - 3rd value is the plugin name 14# - 3rd value is the plugin name
15# - 4th and up are arguments 15# - 4th and up are arguments
16my @TESTS = ( 16my @TESTS = (
diff --git a/lib/tests/test_utils.c b/lib/tests/test_utils.c
index f35b7e2..7b10494 100644
--- a/lib/tests/test_utils.c
+++ b/lib/tests/test_utils.c
@@ -309,7 +309,7 @@ main (int argc, char **argv)
309 309
310 /* This is the result of running ./test_utils */ 310 /* This is the result of running ./test_utils */
311 temp_string = (char *) _np_state_generate_key(); 311 temp_string = (char *) _np_state_generate_key();
312 ok(!strcmp(temp_string, "83d877b6cdfefb5d6f06101fd6fe76762f21792c"), "Got hash with exe and no parameters" ) || 312 ok(!strcmp(temp_string, "e2d17f995fd4c020411b85e3e3d0ff7306d4147e"), "Got hash with exe and no parameters" ) ||
313 diag( "You are probably running in wrong directory. Must run as ./test_utils" ); 313 diag( "You are probably running in wrong directory. Must run as ./test_utils" );
314 314
315 315
@@ -319,7 +319,7 @@ main (int argc, char **argv)
319 this_monitoring_plugin->argv[2] = "--and"; 319 this_monitoring_plugin->argv[2] = "--and";
320 this_monitoring_plugin->argv[3] = "now"; 320 this_monitoring_plugin->argv[3] = "now";
321 temp_string = (char *) _np_state_generate_key(); 321 temp_string = (char *) _np_state_generate_key();
322 ok(!strcmp(temp_string, "94b5e17bf5abf51cb15aff5f69b96f2f8dac5ecd"), "Got based on expected argv" ); 322 ok(!strcmp(temp_string, "bd72da9f78ff1419fad921ea5e43ce56508aef6c"), "Got based on expected argv" );
323 323
324 unsetenv("MP_STATE_PATH"); 324 unsetenv("MP_STATE_PATH");
325 temp_string = (char *) _np_state_calculate_location_prefix(); 325 temp_string = (char *) _np_state_calculate_location_prefix();
@@ -342,7 +342,7 @@ main (int argc, char **argv)
342 np_enable_state(NULL, 51); 342 np_enable_state(NULL, 51);
343 temp_state_key = this_monitoring_plugin->state; 343 temp_state_key = this_monitoring_plugin->state;
344 ok( !strcmp(temp_state_key->plugin_name, "check_test"), "Got plugin name" ); 344 ok( !strcmp(temp_state_key->plugin_name, "check_test"), "Got plugin name" );
345 ok( !strcmp(temp_state_key->name, "83d877b6cdfefb5d6f06101fd6fe76762f21792c"), "Got generated filename" ); 345 ok( !strcmp(temp_state_key->name, "e2d17f995fd4c020411b85e3e3d0ff7306d4147e"), "Got generated filename" );
346 346
347 347
348 np_enable_state("allowedchars_in_keyname", 77); 348 np_enable_state("allowedchars_in_keyname", 77);
@@ -395,7 +395,7 @@ main (int argc, char **argv)
395 ok( temp_state_data==NULL, "Older data version gives NULL" ); 395 ok( temp_state_data==NULL, "Older data version gives NULL" );
396 temp_state_key->data_version=54; 396 temp_state_key->data_version=54;
397 397
398 temp_state_key->_filename="var/nonexistant"; 398 temp_state_key->_filename="var/nonexistent";
399 temp_state_data = np_state_read(); 399 temp_state_data = np_state_read();
400 ok( temp_state_data==NULL, "Missing file gives NULL" ); 400 ok( temp_state_data==NULL, "Missing file gives NULL" );
401 ok( this_monitoring_plugin->state->state_data==NULL, "No state information" ); 401 ok( this_monitoring_plugin->state->state_data==NULL, "No state information" );
diff --git a/lib/utils_base.c b/lib/utils_base.c
index 08fa215..c458cf6 100644
--- a/lib/utils_base.c
+++ b/lib/utils_base.c
@@ -24,7 +24,7 @@
24* 24*
25*****************************************************************************/ 25*****************************************************************************/
26 26
27#include "common.h" 27#include "../plugins/common.h"
28#include <stdarg.h> 28#include <stdarg.h>
29#include "utils_base.h" 29#include "utils_base.h"
30#include <ctype.h> 30#include <ctype.h>
@@ -319,18 +319,18 @@ char *np_extract_value(const char *varlist, const char *name, char sep) {
319 319
320 while (1) { 320 while (1) {
321 /* Strip any leading space */ 321 /* Strip any leading space */
322 for (varlist; isspace(varlist[0]); varlist++); 322 for (; isspace(varlist[0]); varlist++);
323 323
324 if (strncmp(name, varlist, strlen(name)) == 0) { 324 if (strncmp(name, varlist, strlen(name)) == 0) {
325 varlist += strlen(name); 325 varlist += strlen(name);
326 /* strip trailing spaces */ 326 /* strip trailing spaces */
327 for (varlist; isspace(varlist[0]); varlist++); 327 for (; isspace(varlist[0]); varlist++);
328 328
329 if (varlist[0] == '=') { 329 if (varlist[0] == '=') {
330 /* We matched the key, go past the = sign */ 330 /* We matched the key, go past the = sign */
331 varlist++; 331 varlist++;
332 /* strip leading spaces */ 332 /* strip leading spaces */
333 for (varlist; isspace(varlist[0]); varlist++); 333 for (; isspace(varlist[0]); varlist++);
334 334
335 if (tmp = index(varlist, sep)) { 335 if (tmp = index(varlist, sep)) {
336 /* Value is delimited by a comma */ 336 /* Value is delimited by a comma */
@@ -402,20 +402,20 @@ 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 sha1_ctx ctx; 405 struct sha256_ctx ctx;
406 int i; 406 int i;
407 char **argv = this_monitoring_plugin->argv; 407 char **argv = this_monitoring_plugin->argv;
408 unsigned char result[20]; 408 unsigned char result[20];
409 char keyname[41]; 409 char keyname[41];
410 char *p=NULL; 410 char *p=NULL;
411 411
412 sha1_init_ctx(&ctx); 412 sha256_init_ctx(&ctx);
413 413
414 for(i=0; i<this_monitoring_plugin->argc; i++) { 414 for(i=0; i<this_monitoring_plugin->argc; i++) {
415 sha1_process_bytes(argv[i], strlen(argv[i]), &ctx); 415 sha256_process_bytes(argv[i], strlen(argv[i]), &ctx);
416 } 416 }
417 417
418 sha1_finish_ctx(&ctx, &result); 418 sha256_finish_ctx(&ctx, &result);
419 419
420 for (i=0; i<20; ++i) { 420 for (i=0; i<20; ++i) {
421 sprintf(&keyname[2*i], "%02x", result[i]); 421 sprintf(&keyname[2*i], "%02x", result[i]);
diff --git a/lib/utils_base.h b/lib/utils_base.h
index 9482f23..5906550 100644
--- a/lib/utils_base.h
+++ b/lib/utils_base.h
@@ -2,7 +2,7 @@
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 "sha1.h" 5#include "sha256.h"
6 6
7/* This file holds header information for thresholds - use this in preference to 7/* This file holds header information for thresholds - use this in preference to
8 individual plugin logic */ 8 individual plugin logic */
diff --git a/lib/utils_cmd.c b/lib/utils_cmd.c
index 795840d..8b8e570 100644
--- a/lib/utils_cmd.c
+++ b/lib/utils_cmd.c
@@ -161,7 +161,7 @@ _cmd_open (char *const *argv, int *pfd, int *pfderr)
161 } 161 }
162 162
163 /* parent picks up execution here */ 163 /* parent picks up execution here */
164 /* close childs descriptors in our address space */ 164 /* close children descriptors in our address space */
165 close (pfd[1]); 165 close (pfd[1]);
166 close (pfderr[1]); 166 close (pfderr[1]);
167 167
diff --git a/lib/utils_disk.c b/lib/utils_disk.c
index 4f16068..468769b 100644
--- a/lib/utils_disk.c
+++ b/lib/utils_disk.c
@@ -47,9 +47,10 @@ np_add_parameter(struct parameter_list **list, const char *name)
47 struct parameter_list *current = *list; 47 struct parameter_list *current = *list;
48 struct parameter_list *new_path; 48 struct parameter_list *new_path;
49 new_path = (struct parameter_list *) malloc (sizeof *new_path); 49 new_path = (struct parameter_list *) malloc (sizeof *new_path);
50 new_path->name = (char *) name; 50 new_path->name = (char *) malloc(strlen(name) + 1);
51 new_path->best_match = NULL; 51 new_path->best_match = NULL;
52 new_path->name_next = NULL; 52 new_path->name_next = NULL;
53 new_path->name_prev = NULL;
53 new_path->freespace_bytes = NULL; 54 new_path->freespace_bytes = NULL;
54 new_path->freespace_units = NULL; 55 new_path->freespace_units = NULL;
55 new_path->freespace_percent = NULL; 56 new_path->freespace_percent = NULL;
@@ -75,13 +76,17 @@ np_add_parameter(struct parameter_list **list, const char *name)
75 new_path->dused_inodes_percent = 0; 76 new_path->dused_inodes_percent = 0;
76 new_path->dfree_inodes_percent = 0; 77 new_path->dfree_inodes_percent = 0;
77 78
79 strcpy(new_path->name, name);
80
78 if (current == NULL) { 81 if (current == NULL) {
79 *list = new_path; 82 *list = new_path;
83 new_path->name_prev = NULL;
80 } else { 84 } else {
81 while (current->name_next) { 85 while (current->name_next) {
82 current = current->name_next; 86 current = current->name_next;
83 } 87 }
84 current->name_next = new_path; 88 current->name_next = new_path;
89 new_path->name_prev = current;
85 } 90 }
86 return new_path; 91 return new_path;
87} 92}
@@ -90,6 +95,9 @@ np_add_parameter(struct parameter_list **list, const char *name)
90struct parameter_list * 95struct parameter_list *
91np_del_parameter(struct parameter_list *item, struct parameter_list *prev) 96np_del_parameter(struct parameter_list *item, struct parameter_list *prev)
92{ 97{
98 if (item == NULL) {
99 return NULL;
100 }
93 struct parameter_list *next; 101 struct parameter_list *next;
94 102
95 if (item->name_next) 103 if (item->name_next)
@@ -97,10 +105,17 @@ np_del_parameter(struct parameter_list *item, struct parameter_list *prev)
97 else 105 else
98 next = NULL; 106 next = NULL;
99 107
100 free(item); 108 if (next)
109 next->name_prev = prev;
110
101 if (prev) 111 if (prev)
102 prev->name_next = next; 112 prev->name_next = next;
103 113
114 if (item->name) {
115 free(item->name);
116 }
117 free(item);
118
104 return next; 119 return next;
105} 120}
106 121
diff --git a/lib/utils_disk.h b/lib/utils_disk.h
index bf52e4c..3b5a45f 100644
--- a/lib/utils_disk.h
+++ b/lib/utils_disk.h
@@ -24,6 +24,7 @@ struct parameter_list
24 char *group; 24 char *group;
25 struct mount_entry *best_match; 25 struct mount_entry *best_match;
26 struct parameter_list *name_next; 26 struct parameter_list *name_next;
27 struct parameter_list *name_prev;
27 uintmax_t total, available, available_to_root, used, 28 uintmax_t total, available, available_to_root, used,
28 inodes_free, inodes_free_to_root, inodes_used, inodes_total; 29 inodes_free, inodes_free_to_root, inodes_used, inodes_total;
29 double dfree_pct, dused_pct; 30 double dfree_pct, dused_pct;