summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.github/workflows/test.yml4
-rw-r--r--lib/parse_ini.c32
-rw-r--r--plugins-root/Makefile.am6
-rw-r--r--plugins-root/check_dhcp.c2
-rw-r--r--plugins/check_curl.c17
-rw-r--r--plugins/check_http.c5
-rw-r--r--plugins/check_snmp.c4
-rw-r--r--plugins/popen.c2
-rw-r--r--plugins/runcmd.c2
9 files changed, 48 insertions, 26 deletions
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index 9297a757..c4975f1d 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -49,10 +49,10 @@ jobs:
49 fail-fast: false 49 fail-fast: false
50 matrix: 50 matrix:
51 distro: 51 distro:
52 - 'debian:testing' 52 - 'debian:stable'
53 #... 53 #...
54 include: 54 include:
55 - distro: 'debian:testing' 55 - distro: 'debian:stable'
56 prepare: .github/prepare_debian.sh 56 prepare: .github/prepare_debian.sh
57 #... 57 #...
58 steps: 58 steps:
diff --git a/lib/parse_ini.c b/lib/parse_ini.c
index 0cc864ae..09c0dc4f 100644
--- a/lib/parse_ini.c
+++ b/lib/parse_ini.c
@@ -36,6 +36,7 @@
36 */ 36 */
37typedef struct { 37typedef struct {
38 char *file; 38 char *file;
39 bool file_string_on_heap;
39 char *stanza; 40 char *stanza;
40} np_ini_info; 41} np_ini_info;
41 42
@@ -95,16 +96,22 @@ parse_locator(const char *locator, const char *def_stanza, np_ini_info *i)
95 i->stanza = malloc(sizeof(char) * (stanza_len + 1)); 96 i->stanza = malloc(sizeof(char) * (stanza_len + 1));
96 strncpy(i->stanza, locator, stanza_len); 97 strncpy(i->stanza, locator, stanza_len);
97 i->stanza[stanza_len] = '\0'; 98 i->stanza[stanza_len] = '\0';
98 } else /* otherwise we use the default stanza */ 99 } else {/* otherwise we use the default stanza */
99 i->stanza = strdup(def_stanza); 100 i->stanza = strdup(def_stanza);
101 }
100 102
101 if (i->stanza == NULL) 103 if (i->stanza == NULL)
102 die(STATE_UNKNOWN, _("malloc() failed!\n")); 104 die(STATE_UNKNOWN, _("malloc() failed!\n"));
103 105
104 /* check whether there's an @file part */ 106 /* check whether there's an @file part */
105 i->file = stanza_len == locator_len 107 if (stanza_len == locator_len) {
106 ? default_file() 108 i->file = default_file();
107 : strdup(&(locator[stanza_len + 1])); 109 i->file_string_on_heap = false;
110 } else {
111 i->file = strdup(&(locator[stanza_len + 1]));
112 i->file_string_on_heap = true;
113 }
114
108 if (i->file == NULL || i->file[0] == '\0') 115 if (i->file == NULL || i->file[0] == '\0')
109 die(STATE_UNKNOWN, 116 die(STATE_UNKNOWN,
110 _("Cannot find config file in any standard location.\n")); 117 _("Cannot find config file in any standard location.\n"));
@@ -136,7 +143,10 @@ np_get_defaults(const char *locator, const char *default_section)
136 _("Invalid section '%s' in config file '%s'\n"), i.stanza, 143 _("Invalid section '%s' in config file '%s'\n"), i.stanza,
137 i.file); 144 i.file);
138 145
139 free(i.file); 146 if (i.file_string_on_heap) {
147 free(i.file);
148 }
149
140 if (inifile != stdin) 150 if (inifile != stdin)
141 fclose(inifile); 151 fclose(inifile);
142 free(i.stanza); 152 free(i.stanza);
@@ -358,14 +368,18 @@ add_option(FILE *f, np_arg_list **optlst)
358static char * 368static char *
359default_file(void) 369default_file(void)
360{ 370{
361 char **p, *ini_file; 371 char *ini_file;
362 372
363 if ((ini_file = getenv("MP_CONFIG_FILE")) != NULL || 373 if ((ini_file = getenv("MP_CONFIG_FILE")) != NULL ||
364 (ini_file = default_file_in_path()) != NULL) 374 (ini_file = default_file_in_path()) != NULL) {
365 return ini_file; 375 return ini_file;
366 for (p = default_ini_path_names; *p != NULL; p++) 376 }
367 if (access(*p, F_OK) == 0) 377
378 for (char **p = default_ini_path_names; *p != NULL; p++) {
379 if (access(*p, F_OK) == 0) {
368 return *p; 380 return *p;
381 }
382 }
369 return NULL; 383 return NULL;
370} 384}
371 385
diff --git a/plugins-root/Makefile.am b/plugins-root/Makefile.am
index 40aa020d..a80229e2 100644
--- a/plugins-root/Makefile.am
+++ b/plugins-root/Makefile.am
@@ -26,7 +26,7 @@ EXTRA_PROGRAMS = pst3
26 26
27EXTRA_DIST = t pst3.c 27EXTRA_DIST = t pst3.c
28 28
29BASEOBJS = ../plugins/utils.o ../lib/libmonitoringplug.a ../gl/libgnu.a $(LIB_CRYPTO) 29BASEOBJS = ../plugins/utils.o ../lib/libmonitoringplug.a ../gl/libgnu.a
30NETOBJS = ../plugins/netutils.o $(BASEOBJS) $(EXTRA_NETOBJS) 30NETOBJS = ../plugins/netutils.o $(BASEOBJS) $(EXTRA_NETOBJS)
31NETLIBS = $(NETOBJS) $(SOCKETLIBS) 31NETLIBS = $(NETOBJS) $(SOCKETLIBS)
32 32
@@ -80,8 +80,8 @@ install-exec-local: $(noinst_PROGRAMS)
80 80
81############################################################################## 81##############################################################################
82# the actual targets 82# the actual targets
83check_dhcp_LDADD = @LTLIBINTL@ $(NETLIBS) 83check_dhcp_LDADD = @LTLIBINTL@ $(NETLIBS) $(LIB_CRYPTO)
84check_icmp_LDADD = @LTLIBINTL@ $(NETLIBS) $(SOCKETLIBS) 84check_icmp_LDADD = @LTLIBINTL@ $(NETLIBS) $(SOCKETLIBS) $(LIB_CRYPTO)
85 85
86# -m64 needed at compiler and linker phase 86# -m64 needed at compiler and linker phase
87pst3_CFLAGS = @PST3CFLAGS@ 87pst3_CFLAGS = @PST3CFLAGS@
diff --git a/plugins-root/check_dhcp.c b/plugins-root/check_dhcp.c
index 6b07df51..4b8f5e27 100644
--- a/plugins-root/check_dhcp.c
+++ b/plugins-root/check_dhcp.c
@@ -497,7 +497,7 @@ int send_dhcp_discover(int sock){
497 memcpy(&discover_packet.options[opts],&requested_address,sizeof(requested_address)); 497 memcpy(&discover_packet.options[opts],&requested_address,sizeof(requested_address));
498 opts += sizeof(requested_address); 498 opts += sizeof(requested_address);
499 } 499 }
500 discover_packet.options[opts++]=DHCP_OPTION_END; 500 discover_packet.options[opts++]= (char)DHCP_OPTION_END;
501 501
502 /* unicast fields */ 502 /* unicast fields */
503 if(unicast) 503 if(unicast)
diff --git a/plugins/check_curl.c b/plugins/check_curl.c
index 8f9a21d2..fbb197f7 100644
--- a/plugins/check_curl.c
+++ b/plugins/check_curl.c
@@ -223,6 +223,7 @@ curlhelp_ssl_library ssl_library = CURLHELP_SSL_LIBRARY_UNKNOWN;
223int curl_http_version = CURL_HTTP_VERSION_NONE; 223int curl_http_version = CURL_HTTP_VERSION_NONE;
224bool automatic_decompression = false; 224bool automatic_decompression = false;
225char *cookie_jar_file = NULL; 225char *cookie_jar_file = NULL;
226bool haproxy_protocol = false;
226 227
227bool process_arguments (int, char**); 228bool process_arguments (int, char**);
228void handle_curl_option_return_code (CURLcode res, const char* option); 229void handle_curl_option_return_code (CURLcode res, const char* option);
@@ -520,6 +521,11 @@ check_http (void)
520 handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_CONNECTTIMEOUT, socket_timeout), "CURLOPT_CONNECTTIMEOUT"); 521 handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_CONNECTTIMEOUT, socket_timeout), "CURLOPT_CONNECTTIMEOUT");
521 handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_TIMEOUT, socket_timeout), "CURLOPT_TIMEOUT"); 522 handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_TIMEOUT, socket_timeout), "CURLOPT_TIMEOUT");
522 523
524 /* enable haproxy protocol */
525 if (haproxy_protocol) {
526 handle_curl_option_return_code(curl_easy_setopt(curl, CURLOPT_HAPROXYPROTOCOL, 1L), "CURLOPT_HAPROXYPROTOCOL");
527 }
528
523 // fill dns resolve cache to make curl connect to the given server_address instead of the host_name, only required for ssl, because we use the host_name later on to make SNI happy 529 // fill dns resolve cache to make curl connect to the given server_address instead of the host_name, only required for ssl, because we use the host_name later on to make SNI happy
524 if(use_ssl && host_name != NULL) { 530 if(use_ssl && host_name != NULL) {
525 if ( (res=lookup_host (server_address, addrstr, DEFAULT_BUFFER_SIZE/2)) != 0) { 531 if ( (res=lookup_host (server_address, addrstr, DEFAULT_BUFFER_SIZE/2)) != 0) {
@@ -1384,7 +1390,8 @@ process_arguments (int argc, char **argv)
1384 CA_CERT_OPTION, 1390 CA_CERT_OPTION,
1385 HTTP_VERSION_OPTION, 1391 HTTP_VERSION_OPTION,
1386 AUTOMATIC_DECOMPRESSION, 1392 AUTOMATIC_DECOMPRESSION,
1387 COOKIE_JAR 1393 COOKIE_JAR,
1394 HAPROXY_PROTOCOL
1388 }; 1395 };
1389 1396
1390 int option = 0; 1397 int option = 0;
@@ -1431,6 +1438,7 @@ process_arguments (int argc, char **argv)
1431 {"http-version", required_argument, 0, HTTP_VERSION_OPTION}, 1438 {"http-version", required_argument, 0, HTTP_VERSION_OPTION},
1432 {"enable-automatic-decompression", no_argument, 0, AUTOMATIC_DECOMPRESSION}, 1439 {"enable-automatic-decompression", no_argument, 0, AUTOMATIC_DECOMPRESSION},
1433 {"cookie-jar", required_argument, 0, COOKIE_JAR}, 1440 {"cookie-jar", required_argument, 0, COOKIE_JAR},
1441 {"haproxy-protocol", no_argument, 0, HAPROXY_PROTOCOL},
1434 {0, 0, 0, 0} 1442 {0, 0, 0, 0}
1435 }; 1443 };
1436 1444
@@ -1841,6 +1849,9 @@ process_arguments (int argc, char **argv)
1841 case COOKIE_JAR: 1849 case COOKIE_JAR:
1842 cookie_jar_file = optarg; 1850 cookie_jar_file = optarg;
1843 break; 1851 break;
1852 case HAPROXY_PROTOCOL:
1853 haproxy_protocol = true;
1854 break;
1844 case '?': 1855 case '?':
1845 /* print short usage statement if args not parsable */ 1856 /* print short usage statement if args not parsable */
1846 usage5 (); 1857 usage5 ();
@@ -2060,6 +2071,8 @@ print_help (void)
2060 printf (" %s\n", _("1.0 = HTTP/1.0, 1.1 = HTTP/1.1, 2.0 = HTTP/2 (HTTP/2 will fail without -S)")); 2071 printf (" %s\n", _("1.0 = HTTP/1.0, 1.1 = HTTP/1.1, 2.0 = HTTP/2 (HTTP/2 will fail without -S)"));
2061 printf (" %s\n", "--enable-automatic-decompression"); 2072 printf (" %s\n", "--enable-automatic-decompression");
2062 printf (" %s\n", _("Enable automatic decompression of body (CURLOPT_ACCEPT_ENCODING).")); 2073 printf (" %s\n", _("Enable automatic decompression of body (CURLOPT_ACCEPT_ENCODING)."));
2074 printf(" %s\n", "--haproxy-protocol");
2075 printf(" %s\n", _("Send HAProxy proxy protocol v1 header (CURLOPT_HAPROXYPROTOCOL)."));
2063 printf (" %s\n", "---cookie-jar=FILE"); 2076 printf (" %s\n", "---cookie-jar=FILE");
2064 printf (" %s\n", _("Store cookies in the cookie jar and send them out when requested.")); 2077 printf (" %s\n", _("Store cookies in the cookie jar and send them out when requested."));
2065 printf ("\n"); 2078 printf ("\n");
@@ -2144,7 +2157,7 @@ print_usage (void)
2144 printf (" [-b proxy_auth] [-f <ok|warning|critical|follow|sticky|stickyport|curl>]\n"); 2157 printf (" [-b proxy_auth] [-f <ok|warning|critical|follow|sticky|stickyport|curl>]\n");
2145 printf (" [-e <expect>] [-d string] [-s string] [-l] [-r <regex> | -R <case-insensitive regex>]\n"); 2158 printf (" [-e <expect>] [-d string] [-s string] [-l] [-r <regex> | -R <case-insensitive regex>]\n");
2146 printf (" [-P string] [-m <min_pg_size>:<max_pg_size>] [-4|-6] [-N] [-M <age>]\n"); 2159 printf (" [-P string] [-m <min_pg_size>:<max_pg_size>] [-4|-6] [-N] [-M <age>]\n");
2147 printf (" [-A string] [-k string] [-S <version>] [--sni]\n"); 2160 printf (" [-A string] [-k string] [-S <version>] [--sni] [--haproxy-protocol]\n");
2148 printf (" [-T <content-type>] [-j method]\n"); 2161 printf (" [-T <content-type>] [-j method]\n");
2149 printf (" [--http-version=<version>] [--enable-automatic-decompression]\n"); 2162 printf (" [--http-version=<version>] [--enable-automatic-decompression]\n");
2150 printf (" [--cookie-jar=<cookie jar file>\n"); 2163 printf (" [--cookie-jar=<cookie jar file>\n");
diff --git a/plugins/check_http.c b/plugins/check_http.c
index 110f1188..425ce86b 100644
--- a/plugins/check_http.c
+++ b/plugins/check_http.c
@@ -472,9 +472,8 @@ bool process_arguments (int argc, char **argv)
472 http_method = strdup (optarg); 472 http_method = strdup (optarg);
473 char *tmp; 473 char *tmp;
474 if ((tmp = strstr(http_method, ":")) != NULL) { 474 if ((tmp = strstr(http_method, ":")) != NULL) {
475 tmp[0] = '\0'; 475 tmp[0] = '\0'; // set the ":" in the middle to 0
476 http_method = http_method; 476 http_method_proxy = ++tmp; // this points to the second part
477 http_method_proxy = ++tmp;
478 } 477 }
479 break; 478 break;
480 case 'd': /* string or substring */ 479 case 'd': /* string or substring */
diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c
index 7ee9d0ca..295aa9b5 100644
--- a/plugins/check_snmp.c
+++ b/plugins/check_snmp.c
@@ -691,7 +691,6 @@ process_arguments (int argc, char **argv)
691{ 691{
692 char *ptr; 692 char *ptr;
693 int c = 1; 693 int c = 1;
694 int ii = 0;
695 size_t j = 0, jj = 0; 694 size_t j = 0, jj = 0;
696 695
697 int option = 0; 696 int option = 0;
@@ -848,7 +847,6 @@ process_arguments (int argc, char **argv)
848 numoids = j; 847 numoids = j;
849 if (c == 'E' || c == 'e') { 848 if (c == 'E' || c == 'e') {
850 jj++; 849 jj++;
851 ii++;
852 while (j+1 >= eval_size) { 850 while (j+1 >= eval_size) {
853 eval_size += OID_COUNT_STEP; 851 eval_size += OID_COUNT_STEP;
854 eval_method = realloc(eval_method, eval_size * sizeof(*eval_method)); 852 eval_method = realloc(eval_method, eval_size * sizeof(*eval_method));
@@ -875,7 +873,6 @@ process_arguments (int argc, char **argv)
875 memset(eval_method + eval_size - OID_COUNT_STEP, 0, 8); 873 memset(eval_method + eval_size - OID_COUNT_STEP, 0, 8);
876 } 874 }
877 eval_method[jj++] = CRIT_STRING; 875 eval_method[jj++] = CRIT_STRING;
878 ii++;
879 break; 876 break;
880 case 'R': /* regex */ 877 case 'R': /* regex */
881 cflags = REG_ICASE; 878 cflags = REG_ICASE;
@@ -896,7 +893,6 @@ process_arguments (int argc, char **argv)
896 memset(eval_method + eval_size - OID_COUNT_STEP, 0, 8); 893 memset(eval_method + eval_size - OID_COUNT_STEP, 0, 8);
897 } 894 }
898 eval_method[jj++] = CRIT_REGEX; 895 eval_method[jj++] = CRIT_REGEX;
899 ii++;
900 break; 896 break;
901 897
902 /* Format */ 898 /* Format */
diff --git a/plugins/popen.c b/plugins/popen.c
index 036bc608..54e63bc5 100644
--- a/plugins/popen.c
+++ b/plugins/popen.c
@@ -105,7 +105,7 @@ spopen (const char *cmdstring)
105#endif 105#endif
106 106
107 env[0] = strdup("LC_ALL=C"); 107 env[0] = strdup("LC_ALL=C");
108 env[1] = '\0'; 108 env[1] = NULL;
109 109
110 /* if no command was passed, return with no error */ 110 /* if no command was passed, return with no error */
111 if (cmdstring == NULL) 111 if (cmdstring == NULL)
diff --git a/plugins/runcmd.c b/plugins/runcmd.c
index 32fd6b96..ed49bb99 100644
--- a/plugins/runcmd.c
+++ b/plugins/runcmd.c
@@ -115,7 +115,7 @@ np_runcmd_open(const char *cmdstring, int *pfd, int *pfderr)
115 if(!np_pids) NP_RUNCMD_INIT; 115 if(!np_pids) NP_RUNCMD_INIT;
116 116
117 env[0] = strdup("LC_ALL=C"); 117 env[0] = strdup("LC_ALL=C");
118 env[1] = '\0'; 118 env[1] = NULL;
119 119
120 /* make copy of command string so strtok() doesn't silently modify it */ 120 /* make copy of command string so strtok() doesn't silently modify it */
121 /* (the calling program may want to access it later) */ 121 /* (the calling program may want to access it later) */