summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/Makefile.am2
-rw-r--r--plugins/check_by_ssh.c10
-rw-r--r--plugins/check_dig.c4
-rw-r--r--plugins/check_disk.c24
-rw-r--r--plugins/check_dns.c8
-rw-r--r--plugins/check_fping.c6
-rw-r--r--plugins/check_game.c4
-rw-r--r--plugins/check_hpjd.c2
-rw-r--r--plugins/check_http.c116
-rw-r--r--plugins/check_ldap.c8
-rw-r--r--plugins/check_load.c2
-rw-r--r--plugins/check_mrtgtraf.c2
-rw-r--r--plugins/check_mysql.c2
-rw-r--r--plugins/check_mysql_query.c4
-rw-r--r--plugins/check_nagios.c2
-rw-r--r--plugins/check_nt.c52
-rw-r--r--plugins/check_ntp.c20
-rw-r--r--plugins/check_ntp_peer.c36
-rw-r--r--plugins/check_ntp_time.c16
-rw-r--r--plugins/check_nwstat.c204
-rw-r--r--plugins/check_overcr.c2
-rw-r--r--plugins/check_pgsql.c2
-rw-r--r--plugins/check_ping.c72
-rw-r--r--plugins/check_procs.c34
-rw-r--r--plugins/check_radius.c2
-rw-r--r--plugins/check_real.c2
-rw-r--r--plugins/check_smtp.c95
-rw-r--r--plugins/check_snmp.c60
-rw-r--r--plugins/check_ssh.c4
-rw-r--r--plugins/check_swap.c16
-rw-r--r--plugins/check_tcp.c33
-rw-r--r--plugins/check_time.c2
-rw-r--r--plugins/check_ups.c60
-rw-r--r--plugins/check_users.c68
-rw-r--r--plugins/negate.c2
-rw-r--r--plugins/netutils.h2
-rw-r--r--plugins/sslutils.c173
-rw-r--r--plugins/t/check_by_ssh.t10
-rw-r--r--plugins/t/check_http.t6
-rw-r--r--plugins/t/check_tcp.t4
-rwxr-xr-xplugins/tests/check_http.t4
-rwxr-xr-xplugins/tests/check_snmp.t27
-rw-r--r--plugins/urlize.c2
-rw-r--r--plugins/utils.c67
-rw-r--r--plugins/utils.h2
45 files changed, 691 insertions, 584 deletions
diff --git a/plugins/Makefile.am b/plugins/Makefile.am
index 4781e0f..0eb0255 100644
--- a/plugins/Makefile.am
+++ b/plugins/Makefile.am
@@ -102,7 +102,7 @@ check_tcp_LDADD = $(SSLOBJS) $(NETLIBS) $(SSLLIBS)
102check_time_LDADD = $(NETLIBS) 102check_time_LDADD = $(NETLIBS)
103check_ntp_time_LDADD = $(NETLIBS) $(MATHLIBS) 103check_ntp_time_LDADD = $(NETLIBS) $(MATHLIBS)
104check_ups_LDADD = $(NETLIBS) 104check_ups_LDADD = $(NETLIBS)
105check_users_LDADD = $(BASEOBJS) popen.o 105check_users_LDADD = $(BASEOBJS)
106check_by_ssh_LDADD = $(NETLIBS) 106check_by_ssh_LDADD = $(NETLIBS)
107check_ide_smart_LDADD = $(BASEOBJS) 107check_ide_smart_LDADD = $(BASEOBJS)
108negate_LDADD = $(BASEOBJS) 108negate_LDADD = $(BASEOBJS)
diff --git a/plugins/check_by_ssh.c b/plugins/check_by_ssh.c
index 8752016..c5f0d52 100644
--- a/plugins/check_by_ssh.c
+++ b/plugins/check_by_ssh.c
@@ -281,8 +281,8 @@ process_arguments (int argc, char **argv)
281 case 'C': /* Command for remote machine */ 281 case 'C': /* Command for remote machine */
282 commands++; 282 commands++;
283 if (commands > 1) 283 if (commands > 1)
284 asprintf (&remotecmd, "%s;echo STATUS CODE: $?;", remotecmd); 284 xasprintf (&remotecmd, "%s;echo STATUS CODE: $?;", remotecmd);
285 asprintf (&remotecmd, "%s%s", remotecmd, optarg); 285 xasprintf (&remotecmd, "%s%s", remotecmd, optarg);
286 break; 286 break;
287 case 'S': /* skip n (or all) lines on stdout */ 287 case 'S': /* skip n (or all) lines on stdout */
288 if (optarg == NULL) 288 if (optarg == NULL)
@@ -328,13 +328,13 @@ process_arguments (int argc, char **argv)
328 if (strlen(remotecmd) == 0) { 328 if (strlen(remotecmd) == 0) {
329 for (; c < argc; c++) 329 for (; c < argc; c++)
330 if (strlen(remotecmd) > 0) 330 if (strlen(remotecmd) > 0)
331 asprintf (&remotecmd, "%s %s", remotecmd, argv[c]); 331 xasprintf (&remotecmd, "%s %s", remotecmd, argv[c]);
332 else 332 else
333 asprintf (&remotecmd, "%s", argv[c]); 333 xasprintf (&remotecmd, "%s", argv[c]);
334 } 334 }
335 335
336 if (commands > 1 || passive) 336 if (commands > 1 || passive)
337 asprintf (&remotecmd, "%s;echo STATUS CODE: $?;", remotecmd); 337 xasprintf (&remotecmd, "%s;echo STATUS CODE: $?;", remotecmd);
338 338
339 if (remotecmd == NULL || strlen (remotecmd) <= 1) 339 if (remotecmd == NULL || strlen (remotecmd) <= 1)
340 usage_va(_("No remotecmd")); 340 usage_va(_("No remotecmd"));
diff --git a/plugins/check_dig.c b/plugins/check_dig.c
index 06f59c8..893e0a1 100644
--- a/plugins/check_dig.c
+++ b/plugins/check_dig.c
@@ -87,7 +87,7 @@ main (int argc, char **argv)
87 usage_va(_("Could not parse arguments")); 87 usage_va(_("Could not parse arguments"));
88 88
89 /* get the command to run */ 89 /* get the command to run */
90 asprintf (&command_line, "%s @%s -p %d %s -t %s %s", 90 xasprintf (&command_line, "%s @%s -p %d %s -t %s %s",
91 PATH_TO_DIG, dns_server, server_port, query_address, record_type, dig_args); 91 PATH_TO_DIG, dns_server, server_port, query_address, record_type, dig_args);
92 92
93 alarm (timeout_interval); 93 alarm (timeout_interval);
@@ -306,7 +306,7 @@ print_help (void)
306{ 306{
307 char *myport; 307 char *myport;
308 308
309 asprintf (&myport, "%d", DEFAULT_PORT); 309 xasprintf (&myport, "%d", DEFAULT_PORT);
310 310
311 print_revision (progname, NP_VERSION); 311 print_revision (progname, NP_VERSION);
312 312
diff --git a/plugins/check_disk.c b/plugins/check_disk.c
index f889764..f8e913e 100644
--- a/plugins/check_disk.c
+++ b/plugins/check_disk.c
@@ -320,7 +320,7 @@ main (int argc, char **argv)
320 } 320 }
321 321
322 /* Nb: *_high_tide are unset when == UINT_MAX */ 322 /* Nb: *_high_tide are unset when == UINT_MAX */
323 asprintf (&perf, "%s %s", perf, 323 xasprintf (&perf, "%s %s", perf,
324 perfdata ((!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir, 324 perfdata ((!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir,
325 path->dused_units, units, 325 path->dused_units, units,
326 (warning_high_tide != UINT_MAX ? TRUE : FALSE), warning_high_tide, 326 (warning_high_tide != UINT_MAX ? TRUE : FALSE), warning_high_tide,
@@ -331,20 +331,20 @@ main (int argc, char **argv)
331 if (disk_result==STATE_OK && erronly && !verbose) 331 if (disk_result==STATE_OK && erronly && !verbose)
332 continue; 332 continue;
333 333
334 asprintf (&output, "%s %s %.0f %s (%.0f%%", 334 xasprintf (&output, "%s %s %.0f %s (%.0f%%",
335 output, 335 output,
336 (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir, 336 (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir,
337 path->dfree_units, 337 path->dfree_units,
338 units, 338 units,
339 path->dfree_pct); 339 path->dfree_pct);
340 if (path->dused_inodes_percent < 0) { 340 if (path->dused_inodes_percent < 0) {
341 asprintf(&output, "%s inode=-);", output); 341 xasprintf(&output, "%s inode=-);", output);
342 } else { 342 } else {
343 asprintf(&output, "%s inode=%.0f%%);", output, path->dfree_inodes_percent ); 343 xasprintf(&output, "%s inode=%.0f%%);", output, path->dfree_inodes_percent );
344 } 344 }
345 345
346 /* TODO: Need to do a similar debug line 346 /* TODO: Need to do a similar debug line
347 asprintf (&details, _("%s\n\ 347 xasprintf (&details, _("%s\n\
348%.0f of %.0f %s (%.0f%% inode=%.0f%%) free on %s (type %s mounted on %s) warn:%lu crit:%lu warn%%:%.0f%% crit%%:%.0f%%"), 348%.0f of %.0f %s (%.0f%% inode=%.0f%%) free on %s (type %s mounted on %s) warn:%lu crit:%lu warn%%:%.0f%% crit%%:%.0f%%"),
349 details, dfree_units, dtotal_units, units, dfree_pct, inode_space_pct, 349 details, dfree_units, dtotal_units, units, dfree_pct, inode_space_pct,
350 me->me_devname, me->me_type, me->me_mountdir, 350 me->me_devname, me->me_type, me->me_mountdir,
@@ -356,7 +356,7 @@ main (int argc, char **argv)
356 } 356 }
357 357
358 if (verbose >= 2) 358 if (verbose >= 2)
359 asprintf (&output, "%s%s", output, details); 359 xasprintf (&output, "%s%s", output, details);
360 360
361 361
362 printf ("DISK %s%s%s|%s\n", state_text (result), (erronly && result==STATE_OK) ? "" : preamble, output, perf); 362 printf ("DISK %s%s%s|%s\n", state_text (result), (erronly && result==STATE_OK) ? "" : preamble, output, perf);
@@ -473,13 +473,13 @@ process_arguments (int argc, char **argv)
473 if (*optarg == '@') { 473 if (*optarg == '@') {
474 warn_freespace_percent = optarg; 474 warn_freespace_percent = optarg;
475 } else { 475 } else {
476 asprintf(&warn_freespace_percent, "@%s", optarg); 476 xasprintf(&warn_freespace_percent, "@%s", optarg);
477 } 477 }
478 } else { 478 } else {
479 if (*optarg == '@') { 479 if (*optarg == '@') {
480 warn_freespace_units = optarg; 480 warn_freespace_units = optarg;
481 } else { 481 } else {
482 asprintf(&warn_freespace_units, "@%s", optarg); 482 xasprintf(&warn_freespace_units, "@%s", optarg);
483 } 483 }
484 } 484 }
485 break; 485 break;
@@ -494,13 +494,13 @@ process_arguments (int argc, char **argv)
494 if (*optarg == '@') { 494 if (*optarg == '@') {
495 crit_freespace_percent = optarg; 495 crit_freespace_percent = optarg;
496 } else { 496 } else {
497 asprintf(&crit_freespace_percent, "@%s", optarg); 497 xasprintf(&crit_freespace_percent, "@%s", optarg);
498 } 498 }
499 } else { 499 } else {
500 if (*optarg == '@') { 500 if (*optarg == '@') {
501 crit_freespace_units = optarg; 501 crit_freespace_units = optarg;
502 } else { 502 } else {
503 asprintf(&crit_freespace_units, "@%s", optarg); 503 xasprintf(&crit_freespace_units, "@%s", optarg);
504 } 504 }
505 } 505 }
506 break; 506 break;
@@ -509,14 +509,14 @@ process_arguments (int argc, char **argv)
509 if (*optarg == '@') { 509 if (*optarg == '@') {
510 warn_freeinodes_percent = optarg; 510 warn_freeinodes_percent = optarg;
511 } else { 511 } else {
512 asprintf(&warn_freeinodes_percent, "@%s", optarg); 512 xasprintf(&warn_freeinodes_percent, "@%s", optarg);
513 } 513 }
514 break; 514 break;
515 case 'K': /* critical inode threshold */ 515 case 'K': /* critical inode threshold */
516 if (*optarg == '@') { 516 if (*optarg == '@') {
517 crit_freeinodes_percent = optarg; 517 crit_freeinodes_percent = optarg;
518 } else { 518 } else {
519 asprintf(&crit_freeinodes_percent, "@%s", optarg); 519 xasprintf(&crit_freeinodes_percent, "@%s", optarg);
520 } 520 }
521 break; 521 break;
522 case 'u': 522 case 'u':
diff --git a/plugins/check_dns.c b/plugins/check_dns.c
index 73b560c..91af730 100644
--- a/plugins/check_dns.c
+++ b/plugins/check_dns.c
@@ -103,7 +103,7 @@ main (int argc, char **argv)
103 } 103 }
104 104
105 /* get the command to run */ 105 /* get the command to run */
106 asprintf (&command_line, "%s %s %s", NSLOOKUP_COMMAND, query_address, dns_server); 106 xasprintf (&command_line, "%s %s %s", NSLOOKUP_COMMAND, query_address, dns_server);
107 107
108 alarm (timeout_interval); 108 alarm (timeout_interval);
109 gettimeofday (&tv, NULL); 109 gettimeofday (&tv, NULL);
@@ -208,19 +208,19 @@ main (int argc, char **argv)
208 for (i=0; i<expected_address_cnt; i++) { 208 for (i=0; i<expected_address_cnt; i++) {
209 /* check if we get a match and prepare an error string */ 209 /* check if we get a match and prepare an error string */
210 if (strcmp(address, expected_address[i]) == 0) result = STATE_OK; 210 if (strcmp(address, expected_address[i]) == 0) result = STATE_OK;
211 asprintf(&temp_buffer, "%s%s; ", temp_buffer, expected_address[i]); 211 xasprintf(&temp_buffer, "%s%s; ", temp_buffer, expected_address[i]);
212 } 212 }
213 if (result == STATE_CRITICAL) { 213 if (result == STATE_CRITICAL) {
214 /* Strip off last semicolon... */ 214 /* Strip off last semicolon... */
215 temp_buffer[strlen(temp_buffer)-2] = '\0'; 215 temp_buffer[strlen(temp_buffer)-2] = '\0';
216 asprintf(&msg, _("expected '%s' but got '%s'"), temp_buffer, address); 216 xasprintf(&msg, _("expected '%s' but got '%s'"), temp_buffer, address);
217 } 217 }
218 } 218 }
219 219
220 /* check if authoritative */ 220 /* check if authoritative */
221 if (result == STATE_OK && expect_authority && non_authoritative) { 221 if (result == STATE_OK && expect_authority && non_authoritative) {
222 result = STATE_CRITICAL; 222 result = STATE_CRITICAL;
223 asprintf(&msg, _("server %s is not authoritative for %s"), dns_server, query_address); 223 xasprintf(&msg, _("server %s is not authoritative for %s"), dns_server, query_address);
224 } 224 }
225 225
226 microsec = deltime (tv); 226 microsec = deltime (tv);
diff --git a/plugins/check_fping.c b/plugins/check_fping.c
index dd3f86d..675a547 100644
--- a/plugins/check_fping.c
+++ b/plugins/check_fping.c
@@ -92,11 +92,11 @@ main (int argc, char **argv)
92 92
93 /* compose the command */ 93 /* compose the command */
94 if (target_timeout) 94 if (target_timeout)
95 asprintf(&option_string, "%s-t %d ", option_string, target_timeout); 95 xasprintf(&option_string, "%s-t %d ", option_string, target_timeout);
96 if (packet_interval) 96 if (packet_interval)
97 asprintf(&option_string, "%s-p %d ", option_string, packet_interval); 97 xasprintf(&option_string, "%s-p %d ", option_string, packet_interval);
98 98
99 asprintf (&command_line, "%s %s-b %d -c %d %s", PATH_TO_FPING, 99 xasprintf (&command_line, "%s %s-b %d -c %d %s", PATH_TO_FPING,
100 option_string, packet_size, packet_count, server); 100 option_string, packet_size, packet_count, server);
101 101
102 if (verbose) 102 if (verbose)
diff --git a/plugins/check_game.c b/plugins/check_game.c
index 5496c4d..89bb4b1 100644
--- a/plugins/check_game.c
+++ b/plugins/check_game.c
@@ -84,11 +84,11 @@ main (int argc, char **argv)
84 result = STATE_OK; 84 result = STATE_OK;
85 85
86 /* create the command line to execute */ 86 /* create the command line to execute */
87 asprintf (&command_line, "%s -raw %s -%s %s", 87 xasprintf (&command_line, "%s -raw %s -%s %s",
88 PATH_TO_QSTAT, QSTAT_DATA_DELIMITER, game_type, server_ip); 88 PATH_TO_QSTAT, QSTAT_DATA_DELIMITER, game_type, server_ip);
89 89
90 if (port) 90 if (port)
91 asprintf (&command_line, "%s:%-d", command_line, port); 91 xasprintf (&command_line, "%s:%-d", command_line, port);
92 92
93 if (verbose > 0) 93 if (verbose > 0)
94 printf ("%s\n", command_line); 94 printf ("%s\n", command_line);
diff --git a/plugins/check_hpjd.c b/plugins/check_hpjd.c
index 51a0099..60e922e 100644
--- a/plugins/check_hpjd.c
+++ b/plugins/check_hpjd.c
@@ -227,7 +227,7 @@ main (int argc, char **argv)
227 227
228 /* might not be the problem, but most likely is. */ 228 /* might not be the problem, but most likely is. */
229 result = STATE_UNKNOWN ; 229 result = STATE_UNKNOWN ;
230 asprintf (&errmsg, "%s : Timeout from host %s\n", errmsg, address ); 230 xasprintf (&errmsg, "%s : Timeout from host %s\n", errmsg, address );
231 231
232 } 232 }
233 233
diff --git a/plugins/check_http.c b/plugins/check_http.c
index 315848f..77a235e 100644
--- a/plugins/check_http.c
+++ b/plugins/check_http.c
@@ -58,8 +58,8 @@ enum {
58 58
59#ifdef HAVE_SSL 59#ifdef HAVE_SSL
60int check_cert = FALSE; 60int check_cert = FALSE;
61int days_till_exp;
62int ssl_version; 61int ssl_version;
62int days_till_exp_warn, days_till_exp_crit;
63char *randbuff; 63char *randbuff;
64X509 *server_cert; 64X509 *server_cert;
65# define my_recv(buf, len) ((use_ssl) ? np_net_ssl_read(buf, len) : read(sd, buf, len)) 65# define my_recv(buf, len) ((use_ssl) ? np_net_ssl_read(buf, len) : read(sd, buf, len))
@@ -147,7 +147,7 @@ main (int argc, char **argv)
147 /* Set default URL. Must be malloced for subsequent realloc if --onredirect=follow */ 147 /* Set default URL. Must be malloced for subsequent realloc if --onredirect=follow */
148 server_url = strdup(HTTP_URL); 148 server_url = strdup(HTTP_URL);
149 server_url_length = strlen(server_url); 149 server_url_length = strlen(server_url);
150 asprintf (&user_agent, "User-Agent: check_http/v%s (nagios-plugins %s)", 150 xasprintf (&user_agent, "User-Agent: check_http/v%s (nagios-plugins %s)",
151 NP_VERSION, VERSION); 151 NP_VERSION, VERSION);
152 152
153 /* Parse extra opts if any */ 153 /* Parse extra opts if any */
@@ -178,6 +178,7 @@ process_arguments (int argc, char **argv)
178{ 178{
179 int c = 1; 179 int c = 1;
180 char *p; 180 char *p;
181 char *temp;
181 182
182 enum { 183 enum {
183 INVERT_REGEX = CHAR_MAX + 1, 184 INVERT_REGEX = CHAR_MAX + 1,
@@ -264,7 +265,7 @@ process_arguments (int argc, char **argv)
264 warning_thresholds = optarg; 265 warning_thresholds = optarg;
265 break; 266 break;
266 case 'A': /* User Agent String */ 267 case 'A': /* User Agent String */
267 asprintf (&user_agent, "User-Agent: %s", optarg); 268 xasprintf (&user_agent, "User-Agent: %s", optarg);
268 break; 269 break;
269 case 'k': /* Additional headers */ 270 case 'k': /* Additional headers */
270 if (http_opt_headers_count == 0) 271 if (http_opt_headers_count == 0)
@@ -272,7 +273,7 @@ process_arguments (int argc, char **argv)
272 else 273 else
273 http_opt_headers = realloc (http_opt_headers, sizeof (char *) * (++http_opt_headers_count)); 274 http_opt_headers = realloc (http_opt_headers, sizeof (char *) * (++http_opt_headers_count));
274 http_opt_headers[http_opt_headers_count - 1] = optarg; 275 http_opt_headers[http_opt_headers_count - 1] = optarg;
275 /* asprintf (&http_opt_headers, "%s", optarg); */ 276 /* xasprintf (&http_opt_headers, "%s", optarg); */
276 break; 277 break;
277 case 'L': /* show html link */ 278 case 'L': /* show html link */
278 display_html = TRUE; 279 display_html = TRUE;
@@ -282,13 +283,25 @@ process_arguments (int argc, char **argv)
282 break; 283 break;
283 case 'C': /* Check SSL cert validity */ 284 case 'C': /* Check SSL cert validity */
284#ifdef HAVE_SSL 285#ifdef HAVE_SSL
285 if (!is_intnonneg (optarg)) 286 if ((temp=strchr(optarg,','))!=NULL) {
286 usage2 (_("Invalid certificate expiration period"), optarg); 287 *temp='\0';
288 if (!is_intnonneg (temp))
289 usage2 (_("Invalid certificate expiration period"), optarg);
290 days_till_exp_warn = atoi(optarg);
291 *temp=',';
292 temp++;
293 if (!is_intnonneg (temp))
294 usage2 (_("Invalid certificate expiration period"), temp);
295 days_till_exp_crit = atoi (temp);
296 }
287 else { 297 else {
288 days_till_exp = atoi (optarg); 298 days_till_exp_crit=0;
289 check_cert = TRUE; 299 if (!is_intnonneg (optarg))
300 usage2 (_("Invalid certificate expiration period"), optarg);
301 days_till_exp_warn = atoi (optarg);
290 } 302 }
291 /* Fall through to -S option */ 303 check_cert = TRUE;
304 /* Fall through to -S option */
292#endif 305#endif
293 case 'S': /* use SSL */ 306 case 'S': /* use SSL */
294#ifndef HAVE_SSL 307#ifndef HAVE_SSL
@@ -381,7 +394,7 @@ process_arguments (int argc, char **argv)
381 server_expect_yn = 1; 394 server_expect_yn = 1;
382 break; 395 break;
383 case 'T': /* Content-type */ 396 case 'T': /* Content-type */
384 asprintf (&http_content_type, "%s", optarg); 397 xasprintf (&http_content_type, "%s", optarg);
385 break; 398 break;
386 case 'l': /* linespan */ 399 case 'l': /* linespan */
387 cflags &= ~REG_NEWLINE; 400 cflags &= ~REG_NEWLINE;
@@ -677,31 +690,31 @@ check_document_dates (const char *headers, char **msg)
677 690
678 /* Done parsing the body. Now check the dates we (hopefully) parsed. */ 691 /* Done parsing the body. Now check the dates we (hopefully) parsed. */
679 if (!server_date || !*server_date) { 692 if (!server_date || !*server_date) {
680 asprintf (msg, _("%sServer date unknown, "), *msg); 693 xasprintf (msg, _("%sServer date unknown, "), *msg);
681 date_result = max_state_alt(STATE_UNKNOWN, date_result); 694 date_result = max_state_alt(STATE_UNKNOWN, date_result);
682 } else if (!document_date || !*document_date) { 695 } else if (!document_date || !*document_date) {
683 asprintf (msg, _("%sDocument modification date unknown, "), *msg); 696 xasprintf (msg, _("%sDocument modification date unknown, "), *msg);
684 date_result = max_state_alt(STATE_CRITICAL, date_result); 697 date_result = max_state_alt(STATE_CRITICAL, date_result);
685 } else { 698 } else {
686 time_t srv_data = parse_time_string (server_date); 699 time_t srv_data = parse_time_string (server_date);
687 time_t doc_data = parse_time_string (document_date); 700 time_t doc_data = parse_time_string (document_date);
688 701
689 if (srv_data <= 0) { 702 if (srv_data <= 0) {
690 asprintf (msg, _("%sServer date \"%100s\" unparsable, "), *msg, server_date); 703 xasprintf (msg, _("%sServer date \"%100s\" unparsable, "), *msg, server_date);
691 date_result = max_state_alt(STATE_CRITICAL, date_result); 704 date_result = max_state_alt(STATE_CRITICAL, date_result);
692 } else if (doc_data <= 0) { 705 } else if (doc_data <= 0) {
693 asprintf (msg, _("%sDocument date \"%100s\" unparsable, "), *msg, document_date); 706 xasprintf (msg, _("%sDocument date \"%100s\" unparsable, "), *msg, document_date);
694 date_result = max_state_alt(STATE_CRITICAL, date_result); 707 date_result = max_state_alt(STATE_CRITICAL, date_result);
695 } else if (doc_data > srv_data + 30) { 708 } else if (doc_data > srv_data + 30) {
696 asprintf (msg, _("%sDocument is %d seconds in the future, "), *msg, (int)doc_data - (int)srv_data); 709 xasprintf (msg, _("%sDocument is %d seconds in the future, "), *msg, (int)doc_data - (int)srv_data);
697 date_result = max_state_alt(STATE_CRITICAL, date_result); 710 date_result = max_state_alt(STATE_CRITICAL, date_result);
698 } else if (doc_data < srv_data - maximum_age) { 711 } else if (doc_data < srv_data - maximum_age) {
699 int n = (srv_data - doc_data); 712 int n = (srv_data - doc_data);
700 if (n > (60 * 60 * 24 * 2)) { 713 if (n > (60 * 60 * 24 * 2)) {
701 asprintf (msg, _("%sLast modified %.1f days ago, "), *msg, ((float) n) / (60 * 60 * 24)); 714 xasprintf (msg, _("%sLast modified %.1f days ago, "), *msg, ((float) n) / (60 * 60 * 24));
702 date_result = max_state_alt(STATE_CRITICAL, date_result); 715 date_result = max_state_alt(STATE_CRITICAL, date_result);
703 } else { 716 } else {
704 asprintf (msg, _("%sLast modified %d:%02d:%02d ago, "), *msg, n / (60 * 60), (n / 60) % 60, n % 60); 717 xasprintf (msg, _("%sLast modified %d:%02d:%02d ago, "), *msg, n / (60 * 60), (n / 60) % 60, n % 60);
705 date_result = max_state_alt(STATE_CRITICAL, date_result); 718 date_result = max_state_alt(STATE_CRITICAL, date_result);
706 } 719 }
707 } 720 }
@@ -810,7 +823,7 @@ check_http (void)
810 if (result != STATE_OK) 823 if (result != STATE_OK)
811 return result; 824 return result;
812 if (check_cert == TRUE) { 825 if (check_cert == TRUE) {
813 result = np_net_ssl_check_cert(days_till_exp); 826 result = np_net_ssl_check_cert(days_till_exp_warn, days_till_exp_crit);
814 np_net_ssl_cleanup(); 827 np_net_ssl_cleanup();
815 if (sd) close(sd); 828 if (sd) close(sd);
816 return result; 829 return result;
@@ -818,10 +831,10 @@ check_http (void)
818 } 831 }
819#endif /* HAVE_SSL */ 832#endif /* HAVE_SSL */
820 833
821 asprintf (&buf, "%s %s %s\r\n%s\r\n", http_method, server_url, host_name ? "HTTP/1.1" : "HTTP/1.0", user_agent); 834 xasprintf (&buf, "%s %s %s\r\n%s\r\n", http_method, server_url, host_name ? "HTTP/1.1" : "HTTP/1.0", user_agent);
822 835
823 /* tell HTTP/1.1 servers not to keep the connection alive */ 836 /* tell HTTP/1.1 servers not to keep the connection alive */
824 asprintf (&buf, "%sConnection: close\r\n", buf); 837 xasprintf (&buf, "%sConnection: close\r\n", buf);
825 838
826 /* optionally send the host header info */ 839 /* optionally send the host header info */
827 if (host_name) { 840 if (host_name) {
@@ -832,16 +845,16 @@ check_http (void)
832 */ 845 */
833 if ((use_ssl == FALSE && server_port == HTTP_PORT) || 846 if ((use_ssl == FALSE && server_port == HTTP_PORT) ||
834 (use_ssl == TRUE && server_port == HTTPS_PORT)) 847 (use_ssl == TRUE && server_port == HTTPS_PORT))
835 asprintf (&buf, "%sHost: %s\r\n", buf, host_name); 848 xasprintf (&buf, "%sHost: %s\r\n", buf, host_name);
836 else 849 else
837 asprintf (&buf, "%sHost: %s:%d\r\n", buf, host_name, server_port); 850 xasprintf (&buf, "%sHost: %s:%d\r\n", buf, host_name, server_port);
838 } 851 }
839 852
840 /* optionally send any other header tag */ 853 /* optionally send any other header tag */
841 if (http_opt_headers_count) { 854 if (http_opt_headers_count) {
842 for (i = 0; i < http_opt_headers_count ; i++) { 855 for (i = 0; i < http_opt_headers_count ; i++) {
843 for ((pos = strtok(http_opt_headers[i], INPUT_DELIMITER)); pos; (pos = strtok(NULL, INPUT_DELIMITER))) 856 for ((pos = strtok(http_opt_headers[i], INPUT_DELIMITER)); pos; (pos = strtok(NULL, INPUT_DELIMITER)))
844 asprintf (&buf, "%s%s\r\n", buf, pos); 857 xasprintf (&buf, "%s%s\r\n", buf, pos);
845 } 858 }
846 /* This cannot be free'd here because a redirection will then try to access this and segfault */ 859 /* This cannot be free'd here because a redirection will then try to access this and segfault */
847 /* Covered in a testcase in tests/check_http.t */ 860 /* Covered in a testcase in tests/check_http.t */
@@ -851,29 +864,29 @@ check_http (void)
851 /* optionally send the authentication info */ 864 /* optionally send the authentication info */
852 if (strlen(user_auth)) { 865 if (strlen(user_auth)) {
853 base64_encode_alloc (user_auth, strlen (user_auth), &auth); 866 base64_encode_alloc (user_auth, strlen (user_auth), &auth);
854 asprintf (&buf, "%sAuthorization: Basic %s\r\n", buf, auth); 867 xasprintf (&buf, "%sAuthorization: Basic %s\r\n", buf, auth);
855 } 868 }
856 869
857 /* optionally send the proxy authentication info */ 870 /* optionally send the proxy authentication info */
858 if (strlen(proxy_auth)) { 871 if (strlen(proxy_auth)) {
859 base64_encode_alloc (proxy_auth, strlen (proxy_auth), &auth); 872 base64_encode_alloc (proxy_auth, strlen (proxy_auth), &auth);
860 asprintf (&buf, "%sProxy-Authorization: Basic %s\r\n", buf, auth); 873 xasprintf (&buf, "%sProxy-Authorization: Basic %s\r\n", buf, auth);
861 } 874 }
862 875
863 /* either send http POST data (any data, not only POST)*/ 876 /* either send http POST data (any data, not only POST)*/
864 if (http_post_data) { 877 if (http_post_data) {
865 if (http_content_type) { 878 if (http_content_type) {
866 asprintf (&buf, "%sContent-Type: %s\r\n", buf, http_content_type); 879 xasprintf (&buf, "%sContent-Type: %s\r\n", buf, http_content_type);
867 } else { 880 } else {
868 asprintf (&buf, "%sContent-Type: application/x-www-form-urlencoded\r\n", buf); 881 xasprintf (&buf, "%sContent-Type: application/x-www-form-urlencoded\r\n", buf);
869 } 882 }
870 883
871 asprintf (&buf, "%sContent-Length: %i\r\n\r\n", buf, (int)strlen (http_post_data)); 884 xasprintf (&buf, "%sContent-Length: %i\r\n\r\n", buf, (int)strlen (http_post_data));
872 asprintf (&buf, "%s%s%s", buf, http_post_data, CRLF); 885 xasprintf (&buf, "%s%s%s", buf, http_post_data, CRLF);
873 } 886 }
874 else { 887 else {
875 /* or just a newline so the server knows we're done with the request */ 888 /* or just a newline so the server knows we're done with the request */
876 asprintf (&buf, "%s%s", buf, CRLF); 889 xasprintf (&buf, "%s%s", buf, CRLF);
877 } 890 }
878 891
879 if (verbose) printf ("%s\n", buf); 892 if (verbose) printf ("%s\n", buf);
@@ -883,7 +896,7 @@ check_http (void)
883 full_page = strdup(""); 896 full_page = strdup("");
884 while ((i = my_recv (buffer, MAX_INPUT_BUFFER-1)) > 0) { 897 while ((i = my_recv (buffer, MAX_INPUT_BUFFER-1)) > 0) {
885 buffer[i] = '\0'; 898 buffer[i] = '\0';
886 asprintf (&full_page_new, "%s%s", full_page, buffer); 899 xasprintf (&full_page_new, "%s%s", full_page, buffer);
887 free (full_page); 900 free (full_page);
888 full_page = full_page_new; 901 full_page = full_page_new;
889 pagesize += i; 902 pagesize += i;
@@ -968,11 +981,11 @@ check_http (void)
968 /* make sure the status line matches the response we are looking for */ 981 /* make sure the status line matches the response we are looking for */
969 if (!expected_statuscode (status_line, server_expect)) { 982 if (!expected_statuscode (status_line, server_expect)) {
970 if (server_port == HTTP_PORT) 983 if (server_port == HTTP_PORT)
971 asprintf (&msg, 984 xasprintf (&msg,
972 _("Invalid HTTP response received from host: %s\n"), 985 _("Invalid HTTP response received from host: %s\n"),
973 status_line); 986 status_line);
974 else 987 else
975 asprintf (&msg, 988 xasprintf (&msg,
976 _("Invalid HTTP response received from host on port %d: %s\n"), 989 _("Invalid HTTP response received from host on port %d: %s\n"),
977 server_port, status_line); 990 server_port, status_line);
978 die (STATE_CRITICAL, "HTTP CRITICAL - %s", msg); 991 die (STATE_CRITICAL, "HTTP CRITICAL - %s", msg);
@@ -981,7 +994,7 @@ check_http (void)
981 /* Bypass normal status line check if server_expect was set by user and not default */ 994 /* Bypass normal status line check if server_expect was set by user and not default */
982 /* NOTE: After this if/else block msg *MUST* be an asprintf-allocated string */ 995 /* NOTE: After this if/else block msg *MUST* be an asprintf-allocated string */
983 if ( server_expect_yn ) { 996 if ( server_expect_yn ) {
984 asprintf (&msg, 997 xasprintf (&msg,
985 _("Status line output matched \"%s\" - "), server_expect); 998 _("Status line output matched \"%s\" - "), server_expect);
986 if (verbose) 999 if (verbose)
987 printf ("%s\n",msg); 1000 printf ("%s\n",msg);
@@ -1004,12 +1017,12 @@ check_http (void)
1004 } 1017 }
1005 /* server errors result in a critical state */ 1018 /* server errors result in a critical state */
1006 else if (http_status >= 500) { 1019 else if (http_status >= 500) {
1007 asprintf (&msg, _("%s - "), status_line); 1020 xasprintf (&msg, _("%s - "), status_line);
1008 result = STATE_CRITICAL; 1021 result = STATE_CRITICAL;
1009 } 1022 }
1010 /* client errors result in a warning state */ 1023 /* client errors result in a warning state */
1011 else if (http_status >= 400) { 1024 else if (http_status >= 400) {
1012 asprintf (&msg, _("%s - "), status_line); 1025 xasprintf (&msg, _("%s - "), status_line);
1013 result = max_state_alt(STATE_WARNING, result); 1026 result = max_state_alt(STATE_WARNING, result);
1014 } 1027 }
1015 /* check redirected page if specified */ 1028 /* check redirected page if specified */
@@ -1019,11 +1032,11 @@ check_http (void)
1019 redir (header, status_line); 1032 redir (header, status_line);
1020 else 1033 else
1021 result = max_state_alt(onredirect, result); 1034 result = max_state_alt(onredirect, result);
1022 asprintf (&msg, _("%s - "), status_line); 1035 xasprintf (&msg, _("%s - "), status_line);
1023 } /* end if (http_status >= 300) */ 1036 } /* end if (http_status >= 300) */
1024 else { 1037 else {
1025 /* Print OK status anyway */ 1038 /* Print OK status anyway */
1026 asprintf (&msg, _("%s - "), status_line); 1039 xasprintf (&msg, _("%s - "), status_line);
1027 } 1040 }
1028 1041
1029 } /* end else (server_expect_yn) */ 1042 } /* end else (server_expect_yn) */
@@ -1043,7 +1056,7 @@ check_http (void)
1043 if(output_string_search[sizeof(output_string_search)-1]!='\0') { 1056 if(output_string_search[sizeof(output_string_search)-1]!='\0') {
1044 bcopy("...",&output_string_search[sizeof(output_string_search)-4],4); 1057 bcopy("...",&output_string_search[sizeof(output_string_search)-4],4);
1045 } 1058 }
1046 asprintf (&msg, _("%sstring '%s' not found on '%s://%s:%d%s', "), msg, output_string_search, use_ssl ? "https" : "http", host_name ? host_name : server_address, server_port, server_url); 1059 xasprintf (&msg, _("%sstring '%s' not found on '%s://%s:%d%s', "), msg, output_string_search, use_ssl ? "https" : "http", host_name ? host_name : server_address, server_port, server_url);
1047 result = STATE_CRITICAL; 1060 result = STATE_CRITICAL;
1048 } 1061 }
1049 } 1062 }
@@ -1056,15 +1069,15 @@ check_http (void)
1056 } 1069 }
1057 else if ((errcode == REG_NOMATCH && invert_regex == 0) || (errcode == 0 && invert_regex == 1)) { 1070 else if ((errcode == REG_NOMATCH && invert_regex == 0) || (errcode == 0 && invert_regex == 1)) {
1058 if (invert_regex == 0) 1071 if (invert_regex == 0)
1059 asprintf (&msg, _("%spattern not found, "), msg); 1072 xasprintf (&msg, _("%spattern not found, "), msg);
1060 else 1073 else
1061 asprintf (&msg, _("%spattern found, "), msg); 1074 xasprintf (&msg, _("%spattern found, "), msg);
1062 result = STATE_CRITICAL; 1075 result = STATE_CRITICAL;
1063 } 1076 }
1064 else { 1077 else {
1065 /* FIXME: Shouldn't that be UNKNOWN? */ 1078 /* FIXME: Shouldn't that be UNKNOWN? */
1066 regerror (errcode, &preg, errbuf, MAX_INPUT_BUFFER); 1079 regerror (errcode, &preg, errbuf, MAX_INPUT_BUFFER);
1067 asprintf (&msg, _("%sExecute Error: %s, "), msg, errbuf); 1080 xasprintf (&msg, _("%sExecute Error: %s, "), msg, errbuf);
1068 result = STATE_CRITICAL; 1081 result = STATE_CRITICAL;
1069 } 1082 }
1070 } 1083 }
@@ -1080,10 +1093,10 @@ check_http (void)
1080 */ 1093 */
1081 page_len = pagesize; 1094 page_len = pagesize;
1082 if ((max_page_len > 0) && (page_len > max_page_len)) { 1095 if ((max_page_len > 0) && (page_len > max_page_len)) {
1083 asprintf (&msg, _("%spage size %d too large, "), msg, page_len); 1096 xasprintf (&msg, _("%spage size %d too large, "), msg, page_len);
1084 result = max_state_alt(STATE_WARNING, result); 1097 result = max_state_alt(STATE_WARNING, result);
1085 } else if ((min_page_len > 0) && (page_len < min_page_len)) { 1098 } else if ((min_page_len > 0) && (page_len < min_page_len)) {
1086 asprintf (&msg, _("%spage size %d too small, "), msg, page_len); 1099 xasprintf (&msg, _("%spage size %d too small, "), msg, page_len);
1087 result = max_state_alt(STATE_WARNING, result); 1100 result = max_state_alt(STATE_WARNING, result);
1088 } 1101 }
1089 1102
@@ -1094,7 +1107,7 @@ check_http (void)
1094 msg[strlen(msg)-3] = '\0'; 1107 msg[strlen(msg)-3] = '\0';
1095 1108
1096 /* check elapsed time */ 1109 /* check elapsed time */
1097 asprintf (&msg, 1110 xasprintf (&msg,
1098 _("%s - %d bytes in %.3f second response time %s|%s %s"), 1111 _("%s - %d bytes in %.3f second response time %s|%s %s"),
1099 msg, page_len, elapsed_time, 1112 msg, page_len, elapsed_time,
1100 (display_html ? "</A>" : ""), 1113 (display_html ? "</A>" : ""),
@@ -1201,7 +1214,7 @@ redir (char *pos, char *status_line)
1201 if ((url[0] != '/')) { 1214 if ((url[0] != '/')) {
1202 if ((x = strrchr(server_url, '/'))) 1215 if ((x = strrchr(server_url, '/')))
1203 *x = '\0'; 1216 *x = '\0';
1204 asprintf (&url, "%s/%s", server_url, url); 1217 xasprintf (&url, "%s/%s", server_url, url);
1205 } 1218 }
1206 i = server_port; 1219 i = server_port;
1207 strcpy (type, server_type); 1220 strcpy (type, server_type);
@@ -1427,6 +1440,13 @@ print_help (void)
1427 printf (" %s\n", _("a STATE_OK is returned. When the certificate is still valid, but for less than")); 1440 printf (" %s\n", _("a STATE_OK is returned. When the certificate is still valid, but for less than"));
1428 printf (" %s\n", _("14 days, a STATE_WARNING is returned. A STATE_CRITICAL will be returned when")); 1441 printf (" %s\n", _("14 days, a STATE_WARNING is returned. A STATE_CRITICAL will be returned when"));
1429 printf (" %s\n", _("the certificate is expired.")); 1442 printf (" %s\n", _("the certificate is expired."));
1443
1444 printf (" %s\n\n", "CHECK CERTIFICATE: check_http -H www.verisign.com -C 30,14");
1445 printf (" %s\n", _("When the certificate of 'www.verisign.com' is valid for more than 30 days,"));
1446 printf (" %s\n", _("a STATE_OK is returned. When the certificate is still valid, but for less than"));
1447 printf (" %s\n", _("30 days, but more than 14 days, a STATE_WARNING is returned."));
1448 printf (" %s\n", _("A STATE_CRITICAL will be returned when certificate expires in less than 14 days"));
1449
1430#endif 1450#endif
1431 1451
1432 printf (UT_SUPPORT); 1452 printf (UT_SUPPORT);
@@ -1444,6 +1464,6 @@ print_usage (void)
1444 printf (" [-b proxy_auth] [-f <ok|warning|critcal|follow|sticky|stickyport>]\n"); 1464 printf (" [-b proxy_auth] [-f <ok|warning|critcal|follow|sticky|stickyport>]\n");
1445 printf (" [-e <expect>] [-s string] [-l] [-r <regex> | -R <case-insensitive regex>]\n"); 1465 printf (" [-e <expect>] [-s string] [-l] [-r <regex> | -R <case-insensitive regex>]\n");
1446 printf (" [-P string] [-m <min_pg_size>:<max_pg_size>] [-4|-6] [-N] [-M <age>]\n"); 1466 printf (" [-P string] [-m <min_pg_size>:<max_pg_size>] [-4|-6] [-N] [-M <age>]\n");
1447 printf (" [-A string] [-k string] [-S <version>] [--sni] [-C <age>] [-T <content-type>]\n"); 1467 printf (" [-A string] [-k string] [-S <version>] [--sni] [-C <warn_age>[,<crit_age>]]\n");
1448 printf (" [-j method]\n"); 1468 printf (" [-T <content-type>] [-j method]\n");
1449} 1469}
diff --git a/plugins/check_ldap.c b/plugins/check_ldap.c
index f83f139..65db851 100644
--- a/plugins/check_ldap.c
+++ b/plugins/check_ldap.c
@@ -99,7 +99,7 @@ main (int argc, char *argv[])
99 textdomain (PACKAGE); 99 textdomain (PACKAGE);
100 100
101 if (strstr(argv[0],"check_ldaps")) { 101 if (strstr(argv[0],"check_ldaps")) {
102 asprintf (&progname, "check_ldaps"); 102 xasprintf (&progname, "check_ldaps");
103 } 103 }
104 104
105 /* Parse extra opts if any */ 105 /* Parse extra opts if any */
@@ -145,7 +145,7 @@ main (int argc, char *argv[])
145#endif 145#endif
146 146
147 if (ld_port == LDAPS_PORT || ssl_on_connect) { 147 if (ld_port == LDAPS_PORT || ssl_on_connect) {
148 asprintf (&SERVICE, "LDAPS"); 148 xasprintf (&SERVICE, "LDAPS");
149#if defined(HAVE_LDAP_SET_OPTION) && defined(LDAP_OPT_X_TLS) 149#if defined(HAVE_LDAP_SET_OPTION) && defined(LDAP_OPT_X_TLS)
150 /* ldaps: set option tls */ 150 /* ldaps: set option tls */
151 tls = LDAP_OPT_X_TLS_HARD; 151 tls = LDAP_OPT_X_TLS_HARD;
@@ -162,7 +162,7 @@ main (int argc, char *argv[])
162 return STATE_CRITICAL; 162 return STATE_CRITICAL;
163#endif /* LDAP_OPT_X_TLS */ 163#endif /* LDAP_OPT_X_TLS */
164 } else if (starttls) { 164 } else if (starttls) {
165 asprintf (&SERVICE, "LDAP-TLS"); 165 xasprintf (&SERVICE, "LDAP-TLS");
166#if defined(HAVE_LDAP_SET_OPTION) && defined(HAVE_LDAP_START_TLS_S) 166#if defined(HAVE_LDAP_SET_OPTION) && defined(HAVE_LDAP_START_TLS_S)
167 /* ldap with startTLS: set option version */ 167 /* ldap with startTLS: set option version */
168 if (ldap_get_option(ld,LDAP_OPT_PROTOCOL_VERSION, &version) == LDAP_OPT_SUCCESS ) 168 if (ldap_get_option(ld,LDAP_OPT_PROTOCOL_VERSION, &version) == LDAP_OPT_SUCCESS )
@@ -389,7 +389,7 @@ void
389print_help (void) 389print_help (void)
390{ 390{
391 char *myport; 391 char *myport;
392 asprintf (&myport, "%d", DEFAULT_PORT); 392 xasprintf (&myport, "%d", DEFAULT_PORT);
393 393
394 print_revision (progname, NP_VERSION); 394 print_revision (progname, NP_VERSION);
395 395
diff --git a/plugins/check_load.c b/plugins/check_load.c
index 1bdb06a..780ffff 100644
--- a/plugins/check_load.c
+++ b/plugins/check_load.c
@@ -186,7 +186,7 @@ main (int argc, char **argv)
186 /* we got this far, so assume OK until we've measured */ 186 /* we got this far, so assume OK until we've measured */
187 result = STATE_OK; 187 result = STATE_OK;
188 188
189 asprintf(&status_line, _("load average: %.2f, %.2f, %.2f"), la1, la5, la15); 189 xasprintf(&status_line, _("load average: %.2f, %.2f, %.2f"), la1, la5, la15);
190 190
191 for(i = 0; i < 3; i++) { 191 for(i = 0; i < 3; i++) {
192 if(la[i] > cload[i]) { 192 if(la[i] > cload[i]) {
diff --git a/plugins/check_mrtgtraf.c b/plugins/check_mrtgtraf.c
index 4fd9bc0..a822651 100644
--- a/plugins/check_mrtgtraf.c
+++ b/plugins/check_mrtgtraf.c
@@ -191,7 +191,7 @@ main (int argc, char **argv)
191 result = STATE_WARNING; 191 result = STATE_WARNING;
192 } 192 }
193 193
194 asprintf (&error_message, _("%s. In = %0.1f %s, %s. Out = %0.1f %s|%s %s\n"), 194 xasprintf (&error_message, _("%s. In = %0.1f %s, %s. Out = %0.1f %s|%s %s\n"),
195 (use_average == TRUE) ? _("Avg") : _("Max"), adjusted_incoming_rate, 195 (use_average == TRUE) ? _("Avg") : _("Max"), adjusted_incoming_rate,
196 incoming_speed_rating, (use_average == TRUE) ? _("Avg") : _("Max"), 196 incoming_speed_rating, (use_average == TRUE) ? _("Avg") : _("Max"),
197 adjusted_outgoing_rate, outgoing_speed_rating, 197 adjusted_outgoing_rate, outgoing_speed_rating,
diff --git a/plugins/check_mysql.c b/plugins/check_mysql.c
index d9b4e53..4fbdc2b 100644
--- a/plugins/check_mysql.c
+++ b/plugins/check_mysql.c
@@ -369,7 +369,7 @@ void
369print_help (void) 369print_help (void)
370{ 370{
371 char *myport; 371 char *myport;
372 asprintf (&myport, "%d", MYSQL_PORT); 372 xasprintf (&myport, "%d", MYSQL_PORT);
373 373
374 print_revision (progname, NP_VERSION); 374 print_revision (progname, NP_VERSION);
375 375
diff --git a/plugins/check_mysql_query.c b/plugins/check_mysql_query.c
index cf9d8df..0bb83c3 100644
--- a/plugins/check_mysql_query.c
+++ b/plugins/check_mysql_query.c
@@ -233,7 +233,7 @@ process_arguments (int argc, char **argv)
233 print_help (); 233 print_help ();
234 exit (STATE_OK); 234 exit (STATE_OK);
235 case 'q': 235 case 'q':
236 asprintf(&sql_query, "%s", optarg); 236 xasprintf(&sql_query, "%s", optarg);
237 break; 237 break;
238 case 'w': 238 case 'w':
239 warning = optarg; 239 warning = optarg;
@@ -277,7 +277,7 @@ void
277print_help (void) 277print_help (void)
278{ 278{
279 char *myport; 279 char *myport;
280 asprintf (&myport, "%d", MYSQL_PORT); 280 xasprintf (&myport, "%d", MYSQL_PORT);
281 281
282 print_revision (progname, NP_VERSION); 282 print_revision (progname, NP_VERSION);
283 283
diff --git a/plugins/check_nagios.c b/plugins/check_nagios.c
index 6485aa9..c8cdbc0 100644
--- a/plugins/check_nagios.c
+++ b/plugins/check_nagios.c
@@ -137,7 +137,7 @@ main (int argc, char **argv)
137 chld_out.line[i][pos+1] = 0x0; 137 chld_out.line[i][pos+1] = 0x0;
138 } 138 }
139 if ( cols >= expected_cols ) { 139 if ( cols >= expected_cols ) {
140 asprintf (&procargs, "%s", chld_out.line[i] + pos); 140 xasprintf (&procargs, "%s", chld_out.line[i] + pos);
141 strip (procargs); 141 strip (procargs);
142 142
143 /* Some ps return full pathname for command. This removes path */ 143 /* Some ps return full pathname for command. This removes path */
diff --git a/plugins/check_nt.c b/plugins/check_nt.c
index 60806bb..89c4d8d 100644
--- a/plugins/check_nt.c
+++ b/plugins/check_nt.c
@@ -135,13 +135,13 @@ int main(int argc, char **argv){
135 135
136 case CHECK_CLIENTVERSION: 136 case CHECK_CLIENTVERSION:
137 137
138 asprintf(&send_buffer, "%s&1", req_password); 138 xasprintf(&send_buffer, "%s&1", req_password);
139 fetch_data (server_address, server_port, send_buffer); 139 fetch_data (server_address, server_port, send_buffer);
140 if (value_list != NULL && strcmp(recv_buffer, value_list) != 0) { 140 if (value_list != NULL && strcmp(recv_buffer, value_list) != 0) {
141 asprintf (&output_message, _("Wrong client version - running: %s, required: %s"), recv_buffer, value_list); 141 xasprintf (&output_message, _("Wrong client version - running: %s, required: %s"), recv_buffer, value_list);
142 return_code = STATE_WARNING; 142 return_code = STATE_WARNING;
143 } else { 143 } else {
144 asprintf (&output_message, "%s", recv_buffer); 144 xasprintf (&output_message, "%s", recv_buffer);
145 return_code = STATE_OK; 145 return_code = STATE_OK;
146 } 146 }
147 break; 147 break;
@@ -167,7 +167,7 @@ int main(int argc, char **argv){
167 lvalue_list[2+offset]<=(unsigned long)100) { 167 lvalue_list[2+offset]<=(unsigned long)100) {
168 168
169 /* Send request and retrieve data */ 169 /* Send request and retrieve data */
170 asprintf(&send_buffer,"%s&2&%lu",req_password,lvalue_list[0+offset]); 170 xasprintf(&send_buffer,"%s&2&%lu",req_password,lvalue_list[0+offset]);
171 fetch_data (server_address, server_port, send_buffer); 171 fetch_data (server_address, server_port, send_buffer);
172 172
173 utilization=strtoul(recv_buffer,NULL,10); 173 utilization=strtoul(recv_buffer,NULL,10);
@@ -178,11 +178,11 @@ int main(int argc, char **argv){
178 else if(utilization >= lvalue_list[1+offset] && return_code<STATE_WARNING) 178 else if(utilization >= lvalue_list[1+offset] && return_code<STATE_WARNING)
179 return_code=STATE_WARNING; 179 return_code=STATE_WARNING;
180 180
181 asprintf(&output_message,_(" %lu%% (%lu min average)"), utilization, lvalue_list[0+offset]); 181 xasprintf(&output_message,_(" %lu%% (%lu min average)"), utilization, lvalue_list[0+offset]);
182 asprintf(&temp_string,"%s%s",temp_string,output_message); 182 xasprintf(&temp_string,"%s%s",temp_string,output_message);
183 asprintf(&perfdata,_(" '%lu min avg Load'=%lu%%;%lu;%lu;0;100"), lvalue_list[0+offset], utilization, 183 xasprintf(&perfdata,_(" '%lu min avg Load'=%lu%%;%lu;%lu;0;100"), lvalue_list[0+offset], utilization,
184 lvalue_list[1+offset], lvalue_list[2+offset]); 184 lvalue_list[1+offset], lvalue_list[2+offset]);
185 asprintf(&temp_string_perf,"%s%s",temp_string_perf,perfdata); 185 xasprintf(&temp_string_perf,"%s%s",temp_string_perf,perfdata);
186 offset+=3; /* move across the array */ 186 offset+=3; /* move across the array */
187 } 187 }
188 188
@@ -196,13 +196,13 @@ int main(int argc, char **argv){
196 196
197 case CHECK_UPTIME: 197 case CHECK_UPTIME:
198 198
199 asprintf(&send_buffer, "%s&3", req_password); 199 xasprintf(&send_buffer, "%s&3", req_password);
200 fetch_data (server_address, server_port, send_buffer); 200 fetch_data (server_address, server_port, send_buffer);
201 uptime=strtoul(recv_buffer,NULL,10); 201 uptime=strtoul(recv_buffer,NULL,10);
202 updays = uptime / 86400; 202 updays = uptime / 86400;
203 uphours = (uptime % 86400) / 3600; 203 uphours = (uptime % 86400) / 3600;
204 upminutes = ((uptime % 86400) % 3600) / 60; 204 upminutes = ((uptime % 86400) % 3600) / 60;
205 asprintf(&output_message,_("System Uptime - %u day(s) %u hour(s) %u minute(s)"),updays,uphours, upminutes); 205 xasprintf(&output_message,_("System Uptime - %u day(s) %u hour(s) %u minute(s)"),updays,uphours, upminutes);
206 if (check_critical_value==TRUE && uptime <= critical_value) 206 if (check_critical_value==TRUE && uptime <= critical_value)
207 return_code=STATE_CRITICAL; 207 return_code=STATE_CRITICAL;
208 else if (check_warning_value==TRUE && uptime <= warning_value) 208 else if (check_warning_value==TRUE && uptime <= warning_value)
@@ -218,7 +218,7 @@ int main(int argc, char **argv){
218 else if (strlen(value_list)!=1) 218 else if (strlen(value_list)!=1)
219 output_message = strdup (_("wrong -l argument")); 219 output_message = strdup (_("wrong -l argument"));
220 else { 220 else {
221 asprintf(&send_buffer,"%s&4&%s", req_password, value_list); 221 xasprintf(&send_buffer,"%s&4&%s", req_password, value_list);
222 fetch_data (server_address, server_port, send_buffer); 222 fetch_data (server_address, server_port, send_buffer);
223 fds=strtok(recv_buffer,"&"); 223 fds=strtok(recv_buffer,"&");
224 tds=strtok(NULL,"&"); 224 tds=strtok(NULL,"&");
@@ -232,10 +232,10 @@ int main(int argc, char **argv){
232 warning_used_space = ((float)warning_value / 100) * total_disk_space; 232 warning_used_space = ((float)warning_value / 100) * total_disk_space;
233 critical_used_space = ((float)critical_value / 100) * total_disk_space; 233 critical_used_space = ((float)critical_value / 100) * total_disk_space;
234 234
235 asprintf(&temp_string,_("%s:\\ - total: %.2f Gb - used: %.2f Gb (%.0f%%) - free %.2f Gb (%.0f%%)"), 235 xasprintf(&temp_string,_("%s:\\ - total: %.2f Gb - used: %.2f Gb (%.0f%%) - free %.2f Gb (%.0f%%)"),
236 value_list, total_disk_space / 1073741824, (total_disk_space - free_disk_space) / 1073741824, 236 value_list, total_disk_space / 1073741824, (total_disk_space - free_disk_space) / 1073741824,
237 percent_used_space, free_disk_space / 1073741824, (free_disk_space / total_disk_space)*100); 237 percent_used_space, free_disk_space / 1073741824, (free_disk_space / total_disk_space)*100);
238 asprintf(&temp_string_perf,_("'%s:\\ Used Space'=%.2fGb;%.2f;%.2f;0.00;%.2f"), value_list, 238 xasprintf(&temp_string_perf,_("'%s:\\ Used Space'=%.2fGb;%.2f;%.2f;0.00;%.2f"), value_list,
239 (total_disk_space - free_disk_space) / 1073741824, warning_used_space / 1073741824, 239 (total_disk_space - free_disk_space) / 1073741824, warning_used_space / 1073741824,
240 critical_used_space / 1073741824, total_disk_space / 1073741824); 240 critical_used_space / 1073741824, total_disk_space / 1073741824);
241 241
@@ -262,7 +262,7 @@ int main(int argc, char **argv){
262 output_message = strdup (_("No service/process specified")); 262 output_message = strdup (_("No service/process specified"));
263 else { 263 else {
264 preparelist(value_list); /* replace , between services with & to send the request */ 264 preparelist(value_list); /* replace , between services with & to send the request */
265 asprintf(&send_buffer,"%s&%u&%s&%s", req_password,(vars_to_check==CHECK_SERVICESTATE)?5:6, 265 xasprintf(&send_buffer,"%s&%u&%s&%s", req_password,(vars_to_check==CHECK_SERVICESTATE)?5:6,
266 (show_all==TRUE) ? "ShowAll" : "ShowFail",value_list); 266 (show_all==TRUE) ? "ShowAll" : "ShowFail",value_list);
267 fetch_data (server_address, server_port, send_buffer); 267 fetch_data (server_address, server_port, send_buffer);
268 return_code=atoi(strtok(recv_buffer,"&")); 268 return_code=atoi(strtok(recv_buffer,"&"));
@@ -273,7 +273,7 @@ int main(int argc, char **argv){
273 273
274 case CHECK_MEMUSE: 274 case CHECK_MEMUSE:
275 275
276 asprintf(&send_buffer,"%s&7", req_password); 276 xasprintf(&send_buffer,"%s&7", req_password);
277 fetch_data (server_address, server_port, send_buffer); 277 fetch_data (server_address, server_port, send_buffer);
278 mem_commitLimit=atof(strtok(recv_buffer,"&")); 278 mem_commitLimit=atof(strtok(recv_buffer,"&"));
279 mem_commitByte=atof(strtok(NULL,"&")); 279 mem_commitByte=atof(strtok(NULL,"&"));
@@ -283,10 +283,10 @@ int main(int argc, char **argv){
283 283
284 /* Divisor should be 1048567, not 3044515, as we are measuring "Commit Charge" here, 284 /* Divisor should be 1048567, not 3044515, as we are measuring "Commit Charge" here,
285 which equals RAM + Pagefiles. */ 285 which equals RAM + Pagefiles. */
286 asprintf(&output_message,_("Memory usage: total:%.2f Mb - used: %.2f Mb (%.0f%%) - free: %.2f Mb (%.0f%%)"), 286 xasprintf(&output_message,_("Memory usage: total:%.2f Mb - used: %.2f Mb (%.0f%%) - free: %.2f Mb (%.0f%%)"),
287 mem_commitLimit / 1048567, mem_commitByte / 1048567, percent_used_space, 287 mem_commitLimit / 1048567, mem_commitByte / 1048567, percent_used_space,
288 (mem_commitLimit - mem_commitByte) / 1048567, (mem_commitLimit - mem_commitByte) / mem_commitLimit * 100); 288 (mem_commitLimit - mem_commitByte) / 1048567, (mem_commitLimit - mem_commitByte) / mem_commitLimit * 100);
289 asprintf(&perfdata,_("'Memory usage'=%.2fMb;%.2f;%.2f;0.00;%.2f"), mem_commitByte / 1048567, 289 xasprintf(&perfdata,_("'Memory usage'=%.2fMb;%.2f;%.2f;0.00;%.2f"), mem_commitByte / 1048567,
290 warning_used_space / 1048567, critical_used_space / 1048567, mem_commitLimit / 1048567); 290 warning_used_space / 1048567, critical_used_space / 1048567, mem_commitLimit / 1048567);
291 291
292 return_code=STATE_OK; 292 return_code=STATE_OK;
@@ -331,12 +331,12 @@ int main(int argc, char **argv){
331 strtok (value_list, "&"); /* burn the first parameters */ 331 strtok (value_list, "&"); /* burn the first parameters */
332 description = strtok (NULL, "&"); 332 description = strtok (NULL, "&");
333 counter_unit = strtok (NULL, "&"); 333 counter_unit = strtok (NULL, "&");
334 asprintf (&send_buffer, "%s&8&%s", req_password, value_list); 334 xasprintf (&send_buffer, "%s&8&%s", req_password, value_list);
335 fetch_data (server_address, server_port, send_buffer); 335 fetch_data (server_address, server_port, send_buffer);
336 counter_value = atof (recv_buffer); 336 counter_value = atof (recv_buffer);
337 337
338 if (description == NULL) 338 if (description == NULL)
339 asprintf (&output_message, "%.f", counter_value); 339 xasprintf (&output_message, "%.f", counter_value);
340 else if (isPercent) 340 else if (isPercent)
341 { 341 {
342 counter_unit = strdup ("%"); 342 counter_unit = strdup ("%");
@@ -371,13 +371,13 @@ int main(int argc, char **argv){
371 { 371 {
372 /* Let's format the output string, finally... */ 372 /* Let's format the output string, finally... */
373 if (strstr(description, "%") == NULL) { 373 if (strstr(description, "%") == NULL) {
374 asprintf (&output_message, "%s = %.2f %s", description, counter_value, counter_unit); 374 xasprintf (&output_message, "%s = %.2f %s", description, counter_value, counter_unit);
375 } else { 375 } else {
376 /* has formatting, will segv if wrong */ 376 /* has formatting, will segv if wrong */
377 asprintf (&output_message, description, counter_value); 377 xasprintf (&output_message, description, counter_value);
378 } 378 }
379 asprintf (&output_message, "%s |", output_message); 379 xasprintf (&output_message, "%s |", output_message);
380 asprintf (&output_message,"%s %s", output_message, 380 xasprintf (&output_message,"%s %s", output_message,
381 fperfdata (description, counter_value, 381 fperfdata (description, counter_value,
382 counter_unit, 1, warning_value, 1, critical_value, 382 counter_unit, 1, warning_value, 1, critical_value,
383 (!(isPercent) && (minval != NULL)), fminval, 383 (!(isPercent) && (minval != NULL)), fminval,
@@ -410,7 +410,7 @@ int main(int argc, char **argv){
410 output_message = strdup (_("No counter specified")); 410 output_message = strdup (_("No counter specified"));
411 else { 411 else {
412 preparelist(value_list); /* replace , between services with & to send the request */ 412 preparelist(value_list); /* replace , between services with & to send the request */
413 asprintf(&send_buffer,"%s&9&%s", req_password,value_list); 413 xasprintf(&send_buffer,"%s&9&%s", req_password,value_list);
414 fetch_data (server_address, server_port, send_buffer); 414 fetch_data (server_address, server_port, send_buffer);
415 age_in_minutes = atoi(strtok(recv_buffer,"&")); 415 age_in_minutes = atoi(strtok(recv_buffer,"&"));
416 description = strtok(NULL,"&"); 416 description = strtok(NULL,"&");
@@ -439,13 +439,13 @@ int main(int argc, char **argv){
439 if (value_list==NULL) 439 if (value_list==NULL)
440 output_message = strdup (_("No counter specified")); 440 output_message = strdup (_("No counter specified"));
441 else { 441 else {
442 asprintf(&send_buffer,"%s&10&%s", req_password,value_list); 442 xasprintf(&send_buffer,"%s&10&%s", req_password,value_list);
443 fetch_data (server_address, server_port, send_buffer); 443 fetch_data (server_address, server_port, send_buffer);
444 if (!strncmp(recv_buffer,"ERROR",5)) { 444 if (!strncmp(recv_buffer,"ERROR",5)) {
445 printf("NSClient - %s\n",recv_buffer); 445 printf("NSClient - %s\n",recv_buffer);
446 exit(STATE_UNKNOWN); 446 exit(STATE_UNKNOWN);
447 } 447 }
448 asprintf(&output_message,"%s",recv_buffer); 448 xasprintf(&output_message,"%s",recv_buffer);
449 return_code=STATE_OK; 449 return_code=STATE_OK;
450 } 450 }
451 break; 451 break;
diff --git a/plugins/check_ntp.c b/plugins/check_ntp.c
index ac89def..76d19ba 100644
--- a/plugins/check_ntp.c
+++ b/plugins/check_ntp.c
@@ -800,28 +800,28 @@ int main(int argc, char *argv[]){
800 800
801 switch (result) { 801 switch (result) {
802 case STATE_CRITICAL : 802 case STATE_CRITICAL :
803 asprintf(&result_line, _("NTP CRITICAL:")); 803 xasprintf(&result_line, _("NTP CRITICAL:"));
804 break; 804 break;
805 case STATE_WARNING : 805 case STATE_WARNING :
806 asprintf(&result_line, _("NTP WARNING:")); 806 xasprintf(&result_line, _("NTP WARNING:"));
807 break; 807 break;
808 case STATE_OK : 808 case STATE_OK :
809 asprintf(&result_line, _("NTP OK:")); 809 xasprintf(&result_line, _("NTP OK:"));
810 break; 810 break;
811 default : 811 default :
812 asprintf(&result_line, _("NTP UNKNOWN:")); 812 xasprintf(&result_line, _("NTP UNKNOWN:"));
813 break; 813 break;
814 } 814 }
815 if(offset_result == STATE_UNKNOWN){ 815 if(offset_result == STATE_UNKNOWN){
816 asprintf(&result_line, "%s %s", result_line, _("Offset unknown")); 816 xasprintf(&result_line, "%s %s", result_line, _("Offset unknown"));
817 asprintf(&perfdata_line, ""); 817 xasprintf(&perfdata_line, "");
818 } else { 818 } else {
819 asprintf(&result_line, "%s %s %.10g secs", result_line, _("Offset"), offset); 819 xasprintf(&result_line, "%s %s %.10g secs", result_line, _("Offset"), offset);
820 asprintf(&perfdata_line, "%s", perfd_offset(offset)); 820 xasprintf(&perfdata_line, "%s", perfd_offset(offset));
821 } 821 }
822 if (do_jitter) { 822 if (do_jitter) {
823 asprintf(&result_line, "%s, jitter=%f", result_line, jitter); 823 xasprintf(&result_line, "%s, jitter=%f", result_line, jitter);
824 asprintf(&perfdata_line, "%s %s", perfdata_line, perfd_jitter(jitter)); 824 xasprintf(&perfdata_line, "%s %s", perfdata_line, perfd_jitter(jitter));
825 } 825 }
826 printf("%s|%s\n", result_line, perfdata_line); 826 printf("%s|%s\n", result_line, perfdata_line);
827 827
diff --git a/plugins/check_ntp_peer.c b/plugins/check_ntp_peer.c
index 62ac9ae..f0dd2d8 100644
--- a/plugins/check_ntp_peer.c
+++ b/plugins/check_ntp_peer.c
@@ -295,7 +295,7 @@ int ntp_request(const char *host, double *offset, int *offset_result, double *ji
295 /* If there's no sync.peer, query all candidates and use the best one */ 295 /* If there's no sync.peer, query all candidates and use the best one */
296 if (PEER_SEL(peers[i].status) >= min_peer_sel){ 296 if (PEER_SEL(peers[i].status) >= min_peer_sel){
297 if(verbose) printf("Getting offset, jitter and stratum for peer %.2x\n", ntohs(peers[i].assoc)); 297 if(verbose) printf("Getting offset, jitter and stratum for peer %.2x\n", ntohs(peers[i].assoc));
298 asprintf(&data, ""); 298 xasprintf(&data, "");
299 do{ 299 do{
300 setup_control_request(&req, OP_READVAR, 2); 300 setup_control_request(&req, OP_READVAR, 2);
301 req.assoc = peers[i].assoc; 301 req.assoc = peers[i].assoc;
@@ -318,7 +318,7 @@ int ntp_request(const char *host, double *offset, int *offset_result, double *ji
318 DBG(print_ntp_control_message(&req)); 318 DBG(print_ntp_control_message(&req));
319 319
320 if(!(req.op&REM_ERROR)) 320 if(!(req.op&REM_ERROR))
321 asprintf(&data, "%s%s", data, req.data); 321 xasprintf(&data, "%s%s", data, req.data);
322 } while(req.op&REM_MORE); 322 } while(req.op&REM_MORE);
323 323
324 if(req.op&REM_ERROR) { 324 if(req.op&REM_ERROR) {
@@ -603,41 +603,41 @@ int main(int argc, char *argv[]){
603 603
604 switch (result) { 604 switch (result) {
605 case STATE_CRITICAL : 605 case STATE_CRITICAL :
606 asprintf(&result_line, _("NTP CRITICAL:")); 606 xasprintf(&result_line, _("NTP CRITICAL:"));
607 break; 607 break;
608 case STATE_WARNING : 608 case STATE_WARNING :
609 asprintf(&result_line, _("NTP WARNING:")); 609 xasprintf(&result_line, _("NTP WARNING:"));
610 break; 610 break;
611 case STATE_OK : 611 case STATE_OK :
612 asprintf(&result_line, _("NTP OK:")); 612 xasprintf(&result_line, _("NTP OK:"));
613 break; 613 break;
614 default : 614 default :
615 asprintf(&result_line, _("NTP UNKNOWN:")); 615 xasprintf(&result_line, _("NTP UNKNOWN:"));
616 break; 616 break;
617 } 617 }
618 if(!syncsource_found) 618 if(!syncsource_found)
619 asprintf(&result_line, "%s %s,", result_line, _("Server not synchronized")); 619 xasprintf(&result_line, "%s %s,", result_line, _("Server not synchronized"));
620 else if(li_alarm) 620 else if(li_alarm)
621 asprintf(&result_line, "%s %s,", result_line, _("Server has the LI_ALARM bit set")); 621 xasprintf(&result_line, "%s %s,", result_line, _("Server has the LI_ALARM bit set"));
622 622
623 if(offset_result == STATE_UNKNOWN){ 623 if(offset_result == STATE_UNKNOWN){
624 asprintf(&result_line, "%s %s", result_line, _("Offset unknown")); 624 xasprintf(&result_line, "%s %s", result_line, _("Offset unknown"));
625 asprintf(&perfdata_line, ""); 625 xasprintf(&perfdata_line, "");
626 } else { 626 } else {
627 asprintf(&result_line, "%s %s %.10g secs", result_line, _("Offset"), offset); 627 xasprintf(&result_line, "%s %s %.10g secs", result_line, _("Offset"), offset);
628 asprintf(&perfdata_line, "%s", perfd_offset(offset)); 628 xasprintf(&perfdata_line, "%s", perfd_offset(offset));
629 } 629 }
630 if (do_jitter) { 630 if (do_jitter) {
631 asprintf(&result_line, "%s, jitter=%f", result_line, jitter); 631 xasprintf(&result_line, "%s, jitter=%f", result_line, jitter);
632 asprintf(&perfdata_line, "%s %s", perfdata_line, perfd_jitter(jitter)); 632 xasprintf(&perfdata_line, "%s %s", perfdata_line, perfd_jitter(jitter));
633 } 633 }
634 if (do_stratum) { 634 if (do_stratum) {
635 asprintf(&result_line, "%s, stratum=%i", result_line, stratum); 635 xasprintf(&result_line, "%s, stratum=%i", result_line, stratum);
636 asprintf(&perfdata_line, "%s %s", perfdata_line, perfd_stratum(stratum)); 636 xasprintf(&perfdata_line, "%s %s", perfdata_line, perfd_stratum(stratum));
637 } 637 }
638 if (do_truechimers) { 638 if (do_truechimers) {
639 asprintf(&result_line, "%s, truechimers=%i", result_line, num_truechimers); 639 xasprintf(&result_line, "%s, truechimers=%i", result_line, num_truechimers);
640 asprintf(&perfdata_line, "%s %s", perfdata_line, perfd_truechimers(num_truechimers)); 640 xasprintf(&perfdata_line, "%s %s", perfdata_line, perfd_truechimers(num_truechimers));
641 } 641 }
642 printf("%s|%s\n", result_line, perfdata_line); 642 printf("%s|%s\n", result_line, perfdata_line);
643 643
diff --git a/plugins/check_ntp_time.c b/plugins/check_ntp_time.c
index f0f74b4..d543d6b 100644
--- a/plugins/check_ntp_time.c
+++ b/plugins/check_ntp_time.c
@@ -564,24 +564,24 @@ int main(int argc, char *argv[]){
564 564
565 switch (result) { 565 switch (result) {
566 case STATE_CRITICAL : 566 case STATE_CRITICAL :
567 asprintf(&result_line, _("NTP CRITICAL:")); 567 xasprintf(&result_line, _("NTP CRITICAL:"));
568 break; 568 break;
569 case STATE_WARNING : 569 case STATE_WARNING :
570 asprintf(&result_line, _("NTP WARNING:")); 570 xasprintf(&result_line, _("NTP WARNING:"));
571 break; 571 break;
572 case STATE_OK : 572 case STATE_OK :
573 asprintf(&result_line, _("NTP OK:")); 573 xasprintf(&result_line, _("NTP OK:"));
574 break; 574 break;
575 default : 575 default :
576 asprintf(&result_line, _("NTP UNKNOWN:")); 576 xasprintf(&result_line, _("NTP UNKNOWN:"));
577 break; 577 break;
578 } 578 }
579 if(offset_result == STATE_UNKNOWN){ 579 if(offset_result == STATE_UNKNOWN){
580 asprintf(&result_line, "%s %s", result_line, _("Offset unknown")); 580 xasprintf(&result_line, "%s %s", result_line, _("Offset unknown"));
581 asprintf(&perfdata_line, ""); 581 xasprintf(&perfdata_line, "");
582 } else { 582 } else {
583 asprintf(&result_line, "%s %s %.10g secs", result_line, _("Offset"), offset); 583 xasprintf(&result_line, "%s %s %.10g secs", result_line, _("Offset"), offset);
584 asprintf(&perfdata_line, "%s", perfd_offset(offset)); 584 xasprintf(&perfdata_line, "%s", perfd_offset(offset));
585 } 585 }
586 printf("%s|%s\n", result_line, perfdata_line); 586 printf("%s|%s\n", result_line, perfdata_line);
587 587
diff --git a/plugins/check_nwstat.c b/plugins/check_nwstat.c
index 81c5575..6ebe8f8 100644
--- a/plugins/check_nwstat.c
+++ b/plugins/check_nwstat.c
@@ -191,7 +191,7 @@ main(int argc, char **argv) {
191 netware_version = strdup(""); 191 netware_version = strdup("");
192 else { 192 else {
193 recv_buffer[strlen(recv_buffer)-1]=0; 193 recv_buffer[strlen(recv_buffer)-1]=0;
194 asprintf (&netware_version,_("NetWare %s: "),recv_buffer); 194 xasprintf (&netware_version,_("NetWare %s: "),recv_buffer);
195 } 195 }
196 } else 196 } else
197 netware_version = strdup(""); 197 netware_version = strdup("");
@@ -215,7 +215,7 @@ main(int argc, char **argv) {
215 close(sd); 215 close(sd);
216 my_tcp_connect (server_address, server_port, &sd); 216 my_tcp_connect (server_address, server_port, &sd);
217 217
218 asprintf (&send_buffer,"UTIL%s\r\n",temp_buffer); 218 xasprintf (&send_buffer,"UTIL%s\r\n",temp_buffer);
219 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer)); 219 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
220 if (result!=STATE_OK) 220 if (result!=STATE_OK)
221 return result; 221 return result;
@@ -236,7 +236,7 @@ main(int argc, char **argv) {
236 else if (check_warning_value==TRUE && utilization >= warning_value) 236 else if (check_warning_value==TRUE && utilization >= warning_value)
237 result=STATE_WARNING; 237 result=STATE_WARNING;
238 238
239 asprintf (&output_message, 239 xasprintf (&output_message,
240 _("Load %s - %s %s-min load average = %lu%%|load%s=%lu;%lu;%lu;0;100"), 240 _("Load %s - %s %s-min load average = %lu%%|load%s=%lu;%lu;%lu;0;100"),
241 state_text(result), 241 state_text(result),
242 uptime, 242 uptime,
@@ -264,7 +264,7 @@ main(int argc, char **argv) {
264 else if (check_warning_value==TRUE && current_connections >= warning_value) 264 else if (check_warning_value==TRUE && current_connections >= warning_value)
265 result=STATE_WARNING; 265 result=STATE_WARNING;
266 266
267 asprintf (&output_message, 267 xasprintf (&output_message,
268 _("Conns %s - %lu current connections|Conns=%lu;%lu;%lu;;"), 268 _("Conns %s - %lu current connections|Conns=%lu;%lu;%lu;;"),
269 state_text(result), 269 state_text(result),
270 current_connections, 270 current_connections,
@@ -289,7 +289,7 @@ main(int argc, char **argv) {
289 else if (check_warning_value==TRUE && cache_hits <= warning_value) 289 else if (check_warning_value==TRUE && cache_hits <= warning_value)
290 result=STATE_WARNING; 290 result=STATE_WARNING;
291 291
292 asprintf (&output_message, 292 xasprintf (&output_message,
293 _("%s: Long term cache hits = %lu%%"), 293 _("%s: Long term cache hits = %lu%%"),
294 state_text(result), 294 state_text(result),
295 cache_hits); 295 cache_hits);
@@ -311,7 +311,7 @@ main(int argc, char **argv) {
311 else if (check_warning_value==TRUE && cache_buffers <= warning_value) 311 else if (check_warning_value==TRUE && cache_buffers <= warning_value)
312 result=STATE_WARNING; 312 result=STATE_WARNING;
313 313
314 asprintf (&output_message, 314 xasprintf (&output_message,
315 _("%s: Total cache buffers = %lu|Cachebuffers=%lu;%lu;%lu;;"), 315 _("%s: Total cache buffers = %lu|Cachebuffers=%lu;%lu;%lu;;"),
316 state_text(result), 316 state_text(result),
317 cache_buffers, 317 cache_buffers,
@@ -336,7 +336,7 @@ main(int argc, char **argv) {
336 else if (check_warning_value==TRUE && cache_buffers >= warning_value) 336 else if (check_warning_value==TRUE && cache_buffers >= warning_value)
337 result=STATE_WARNING; 337 result=STATE_WARNING;
338 338
339 asprintf (&output_message, 339 xasprintf (&output_message,
340 _("%s: Dirty cache buffers = %lu|Dirty-Cache-Buffers=%lu;%lu;%lu;;"), 340 _("%s: Dirty cache buffers = %lu|Dirty-Cache-Buffers=%lu;%lu;%lu;;"),
341 state_text(result), 341 state_text(result),
342 cache_buffers, 342 cache_buffers,
@@ -361,7 +361,7 @@ main(int argc, char **argv) {
361 else if (check_warning_value==TRUE && lru_time <= warning_value) 361 else if (check_warning_value==TRUE && lru_time <= warning_value)
362 result=STATE_WARNING; 362 result=STATE_WARNING;
363 363
364 asprintf (&output_message, 364 xasprintf (&output_message,
365 _("%s: LRU sitting time = %lu minutes"), 365 _("%s: LRU sitting time = %lu minutes"),
366 state_text(result), 366 state_text(result),
367 lru_time); 367 lru_time);
@@ -373,13 +373,13 @@ main(int argc, char **argv) {
373 close(sd); 373 close(sd);
374 my_tcp_connect (server_address, server_port, &sd); 374 my_tcp_connect (server_address, server_port, &sd);
375 375
376 asprintf (&send_buffer,"VKF%s\r\n",volume_name); 376 xasprintf (&send_buffer,"VKF%s\r\n",volume_name);
377 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer)); 377 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
378 if (result!=STATE_OK) 378 if (result!=STATE_OK)
379 return result; 379 return result;
380 380
381 if (!strcmp(recv_buffer,"-1\n")) { 381 if (!strcmp(recv_buffer,"-1\n")) {
382 asprintf (&output_message,_("CRITICAL - Volume '%s' does not exist!"),volume_name); 382 xasprintf (&output_message,_("CRITICAL - Volume '%s' does not exist!"),volume_name);
383 result=STATE_CRITICAL; 383 result=STATE_CRITICAL;
384 } else { 384 } else {
385 free_disk_space=strtoul(recv_buffer,NULL,10); 385 free_disk_space=strtoul(recv_buffer,NULL,10);
@@ -387,7 +387,7 @@ main(int argc, char **argv) {
387 result=STATE_CRITICAL; 387 result=STATE_CRITICAL;
388 else if (check_warning_value==TRUE && free_disk_space <= warning_value) 388 else if (check_warning_value==TRUE && free_disk_space <= warning_value)
389 result=STATE_WARNING; 389 result=STATE_WARNING;
390 asprintf (&output_message, 390 xasprintf (&output_message,
391 _("%s%lu KB free on volume %s|KBFree%s=%lu;%lu;%lu;;"), 391 _("%s%lu KB free on volume %s|KBFree%s=%lu;%lu;%lu;;"),
392 (result==STATE_OK)?"":_("Only "), 392 (result==STATE_OK)?"":_("Only "),
393 free_disk_space, 393 free_disk_space,
@@ -401,13 +401,13 @@ main(int argc, char **argv) {
401 /* check MB free space on volume */ 401 /* check MB free space on volume */
402 } else if (vars_to_check==VMF) { 402 } else if (vars_to_check==VMF) {
403 403
404 asprintf (&send_buffer,"VMF%s\r\n",volume_name); 404 xasprintf (&send_buffer,"VMF%s\r\n",volume_name);
405 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer)); 405 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
406 if (result!=STATE_OK) 406 if (result!=STATE_OK)
407 return result; 407 return result;
408 408
409 if (!strcmp(recv_buffer,"-1\n")) { 409 if (!strcmp(recv_buffer,"-1\n")) {
410 asprintf (&output_message,_("CRITICAL - Volume '%s' does not exist!"),volume_name); 410 xasprintf (&output_message,_("CRITICAL - Volume '%s' does not exist!"),volume_name);
411 result=STATE_CRITICAL; 411 result=STATE_CRITICAL;
412 } else { 412 } else {
413 free_disk_space=strtoul(recv_buffer,NULL,10); 413 free_disk_space=strtoul(recv_buffer,NULL,10);
@@ -415,7 +415,7 @@ main(int argc, char **argv) {
415 result=STATE_CRITICAL; 415 result=STATE_CRITICAL;
416 else if (check_warning_value==TRUE && free_disk_space <= warning_value) 416 else if (check_warning_value==TRUE && free_disk_space <= warning_value)
417 result=STATE_WARNING; 417 result=STATE_WARNING;
418 asprintf (&output_message, 418 xasprintf (&output_message,
419 _("%s%lu MB free on volume %s|MBFree%s=%lu;%lu;%lu;;"), 419 _("%s%lu MB free on volume %s|MBFree%s=%lu;%lu;%lu;;"),
420 (result==STATE_OK)?"":_("Only "), 420 (result==STATE_OK)?"":_("Only "),
421 free_disk_space, 421 free_disk_space,
@@ -428,13 +428,13 @@ main(int argc, char **argv) {
428 /* check MB used space on volume */ 428 /* check MB used space on volume */
429 } else if (vars_to_check==VMU) { 429 } else if (vars_to_check==VMU) {
430 430
431 asprintf (&send_buffer,"VMU%s\r\n",volume_name); 431 xasprintf (&send_buffer,"VMU%s\r\n",volume_name);
432 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer)); 432 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
433 if (result!=STATE_OK) 433 if (result!=STATE_OK)
434 return result; 434 return result;
435 435
436 if (!strcmp(recv_buffer,"-1\n")) { 436 if (!strcmp(recv_buffer,"-1\n")) {
437 asprintf (&output_message,_("CRITICAL - Volume '%s' does not exist!"),volume_name); 437 xasprintf (&output_message,_("CRITICAL - Volume '%s' does not exist!"),volume_name);
438 result=STATE_CRITICAL; 438 result=STATE_CRITICAL;
439 } else { 439 } else {
440 free_disk_space=strtoul(recv_buffer,NULL,10); 440 free_disk_space=strtoul(recv_buffer,NULL,10);
@@ -442,7 +442,7 @@ main(int argc, char **argv) {
442 result=STATE_CRITICAL; 442 result=STATE_CRITICAL;
443 else if (check_warning_value==TRUE && free_disk_space <= warning_value) 443 else if (check_warning_value==TRUE && free_disk_space <= warning_value)
444 result=STATE_WARNING; 444 result=STATE_WARNING;
445 asprintf (&output_message, 445 xasprintf (&output_message,
446 _("%s%lu MB used on volume %s|MBUsed%s=%lu;%lu;%lu;;"), 446 _("%s%lu MB used on volume %s|MBUsed%s=%lu;%lu;%lu;;"),
447 (result==STATE_OK)?"":_("Only "), 447 (result==STATE_OK)?"":_("Only "),
448 free_disk_space, 448 free_disk_space,
@@ -460,14 +460,14 @@ main(int argc, char **argv) {
460 close(sd); 460 close(sd);
461 my_tcp_connect (server_address, server_port, &sd); 461 my_tcp_connect (server_address, server_port, &sd);
462 462
463 asprintf (&send_buffer,"VKF%s\r\n",volume_name); 463 xasprintf (&send_buffer,"VKF%s\r\n",volume_name);
464 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer)); 464 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
465 if (result!=STATE_OK) 465 if (result!=STATE_OK)
466 return result; 466 return result;
467 467
468 if (!strcmp(recv_buffer,"-1\n")) { 468 if (!strcmp(recv_buffer,"-1\n")) {
469 469
470 asprintf (&output_message,_("CRITICAL - Volume '%s' does not exist!"),volume_name); 470 xasprintf (&output_message,_("CRITICAL - Volume '%s' does not exist!"),volume_name);
471 result=STATE_CRITICAL; 471 result=STATE_CRITICAL;
472 472
473 } else { 473 } else {
@@ -477,7 +477,7 @@ main(int argc, char **argv) {
477 close(sd); 477 close(sd);
478 my_tcp_connect (server_address, server_port, &sd); 478 my_tcp_connect (server_address, server_port, &sd);
479 479
480 asprintf (&send_buffer,"VKS%s\r\n",volume_name); 480 xasprintf (&send_buffer,"VKS%s\r\n",volume_name);
481 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer)); 481 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
482 if (result!=STATE_OK) 482 if (result!=STATE_OK)
483 return result; 483 return result;
@@ -491,7 +491,7 @@ main(int argc, char **argv) {
491 result=STATE_WARNING; 491 result=STATE_WARNING;
492 free_disk_space/=1024; 492 free_disk_space/=1024;
493 total_disk_space/=1024; 493 total_disk_space/=1024;
494 asprintf (&output_message,_("%lu MB (%lu%%) free on volume %s - total %lu MB|FreeMB%s=%lu;%lu;%lu;0;100"), 494 xasprintf (&output_message,_("%lu MB (%lu%%) free on volume %s - total %lu MB|FreeMB%s=%lu;%lu;%lu;0;100"),
495 free_disk_space, 495 free_disk_space,
496 percent_free_space, 496 percent_free_space,
497 volume_name, 497 volume_name,
@@ -525,7 +525,7 @@ main(int argc, char **argv) {
525 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer)); 525 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
526 temp_buffer=strtok(recv_buffer,"\r\n"); 526 temp_buffer=strtok(recv_buffer,"\r\n");
527 527
528 asprintf (&output_message,_("Directory Services Database is %s (DS version %s)"),(result==STATE_OK)?"open":"closed",temp_buffer); 528 xasprintf (&output_message,_("Directory Services Database is %s (DS version %s)"),(result==STATE_OK)?"open":"closed",temp_buffer);
529 529
530 /* check to see if logins are enabled */ 530 /* check to see if logins are enabled */
531 } else if (vars_to_check==LOGINS) { 531 } else if (vars_to_check==LOGINS) {
@@ -542,13 +542,13 @@ main(int argc, char **argv) {
542 else 542 else
543 result=STATE_WARNING; 543 result=STATE_WARNING;
544 544
545 asprintf (&output_message,_("Logins are %s"),(result==STATE_OK)?_("enabled"):_("disabled")); 545 xasprintf (&output_message,_("Logins are %s"),(result==STATE_OK)?_("enabled"):_("disabled"));
546 546
547 547
548 /* check NRM Health Status Summary*/ 548 /* check NRM Health Status Summary*/
549 } else if (vars_to_check==NRMH) { 549 } else if (vars_to_check==NRMH) {
550 550
551 asprintf (&send_buffer,"NRMH\r\n"); 551 xasprintf (&send_buffer,"NRMH\r\n");
552 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer)); 552 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
553 if (result!=STATE_OK) 553 if (result!=STATE_OK)
554 return result; 554 return result;
@@ -557,15 +557,15 @@ main(int argc, char **argv) {
557 557
558 if (nrm_health_status==2) { 558 if (nrm_health_status==2) {
559 result=STATE_OK; 559 result=STATE_OK;
560 asprintf (&output_message,_("CRITICAL - NRM Status is bad!")); 560 xasprintf (&output_message,_("CRITICAL - NRM Status is bad!"));
561 } 561 }
562 else { 562 else {
563 if (nrm_health_status==1) { 563 if (nrm_health_status==1) {
564 result=STATE_WARNING; 564 result=STATE_WARNING;
565 asprintf (&output_message,_("Warning - NRM Status is suspect!")); 565 xasprintf (&output_message,_("Warning - NRM Status is suspect!"));
566 } 566 }
567 567
568 asprintf (&output_message,_("OK - NRM Status is good!")); 568 xasprintf (&output_message,_("OK - NRM Status is good!"));
569 } 569 }
570 570
571 571
@@ -576,7 +576,7 @@ main(int argc, char **argv) {
576 close(sd); 576 close(sd);
577 my_tcp_connect (server_address, server_port, &sd); 577 my_tcp_connect (server_address, server_port, &sd);
578 578
579 asprintf (&send_buffer,"S15\r\n"); 579 xasprintf (&send_buffer,"S15\r\n");
580 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer)); 580 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
581 if (result!=STATE_OK) 581 if (result!=STATE_OK)
582 return result; 582 return result;
@@ -586,7 +586,7 @@ main(int argc, char **argv) {
586 close(sd); 586 close(sd);
587 my_tcp_connect (server_address, server_port, &sd); 587 my_tcp_connect (server_address, server_port, &sd);
588 588
589 asprintf (&send_buffer,"S16\r\n"); 589 xasprintf (&send_buffer,"S16\r\n");
590 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer)); 590 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
591 if (result!=STATE_OK) 591 if (result!=STATE_OK)
592 return result; 592 return result;
@@ -607,7 +607,7 @@ main(int argc, char **argv) {
607 result=STATE_WARNING; 607 result=STATE_WARNING;
608 } 608 }
609 609
610 asprintf (&output_message,_("%lu of %lu (%lu%%) packet receive buffers used"),used_packet_receive_buffers,max_packet_receive_buffers,percent_used_packet_receive_buffers); 610 xasprintf (&output_message,_("%lu of %lu (%lu%%) packet receive buffers used"),used_packet_receive_buffers,max_packet_receive_buffers,percent_used_packet_receive_buffers);
611 611
612 /* check SAP table entries */ 612 /* check SAP table entries */
613 } else if (vars_to_check==SAPENTRIES) { 613 } else if (vars_to_check==SAPENTRIES) {
@@ -616,9 +616,9 @@ main(int argc, char **argv) {
616 my_tcp_connect (server_address, server_port, &sd); 616 my_tcp_connect (server_address, server_port, &sd);
617 617
618 if (sap_number==-1) 618 if (sap_number==-1)
619 asprintf (&send_buffer,"S9\r\n"); 619 xasprintf (&send_buffer,"S9\r\n");
620 else 620 else
621 asprintf (&send_buffer,"S9.%d\r\n",sap_number); 621 xasprintf (&send_buffer,"S9.%d\r\n",sap_number);
622 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer)); 622 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
623 if (result!=STATE_OK) 623 if (result!=STATE_OK)
624 return result; 624 return result;
@@ -631,9 +631,9 @@ main(int argc, char **argv) {
631 result=STATE_WARNING; 631 result=STATE_WARNING;
632 632
633 if (sap_number==-1) 633 if (sap_number==-1)
634 asprintf (&output_message,_("%lu entries in SAP table"),sap_entries); 634 xasprintf (&output_message,_("%lu entries in SAP table"),sap_entries);
635 else 635 else
636 asprintf (&output_message,_("%lu entries in SAP table for SAP type %d"),sap_entries,sap_number); 636 xasprintf (&output_message,_("%lu entries in SAP table for SAP type %d"),sap_entries,sap_number);
637 637
638 /* check KB purgeable space on volume */ 638 /* check KB purgeable space on volume */
639 } else if (vars_to_check==VKP) { 639 } else if (vars_to_check==VKP) {
@@ -641,13 +641,13 @@ main(int argc, char **argv) {
641 close(sd); 641 close(sd);
642 my_tcp_connect (server_address, server_port, &sd); 642 my_tcp_connect (server_address, server_port, &sd);
643 643
644 asprintf (&send_buffer,"VKP%s\r\n",volume_name); 644 xasprintf (&send_buffer,"VKP%s\r\n",volume_name);
645 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer)); 645 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
646 if (result!=STATE_OK) 646 if (result!=STATE_OK)
647 return result; 647 return result;
648 648
649 if (!strcmp(recv_buffer,"-1\n")) { 649 if (!strcmp(recv_buffer,"-1\n")) {
650 asprintf (&output_message,_("CRITICAL - Volume '%s' does not exist!"),volume_name); 650 xasprintf (&output_message,_("CRITICAL - Volume '%s' does not exist!"),volume_name);
651 result=STATE_CRITICAL; 651 result=STATE_CRITICAL;
652 } else { 652 } else {
653 purgeable_disk_space=strtoul(recv_buffer,NULL,10); 653 purgeable_disk_space=strtoul(recv_buffer,NULL,10);
@@ -655,7 +655,7 @@ main(int argc, char **argv) {
655 result=STATE_CRITICAL; 655 result=STATE_CRITICAL;
656 else if (check_warning_value==TRUE && purgeable_disk_space >= warning_value) 656 else if (check_warning_value==TRUE && purgeable_disk_space >= warning_value)
657 result=STATE_WARNING; 657 result=STATE_WARNING;
658 asprintf (&output_message,_("%s%lu KB purgeable on volume %s|Purge%s=%lu;%lu;%lu;;"), 658 xasprintf (&output_message,_("%s%lu KB purgeable on volume %s|Purge%s=%lu;%lu;%lu;;"),
659 (result==STATE_OK)?"":_("Only "), 659 (result==STATE_OK)?"":_("Only "),
660 purgeable_disk_space, 660 purgeable_disk_space,
661 volume_name, 661 volume_name,
@@ -667,13 +667,13 @@ main(int argc, char **argv) {
667 /* check MB purgeable space on volume */ 667 /* check MB purgeable space on volume */
668 } else if (vars_to_check==VMP) { 668 } else if (vars_to_check==VMP) {
669 669
670 asprintf (&send_buffer,"VMP%s\r\n",volume_name); 670 xasprintf (&send_buffer,"VMP%s\r\n",volume_name);
671 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer)); 671 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
672 if (result!=STATE_OK) 672 if (result!=STATE_OK)
673 return result; 673 return result;
674 674
675 if (!strcmp(recv_buffer,"-1\n")) { 675 if (!strcmp(recv_buffer,"-1\n")) {
676 asprintf (&output_message,_("CRITICAL - Volume '%s' does not exist!"),volume_name); 676 xasprintf (&output_message,_("CRITICAL - Volume '%s' does not exist!"),volume_name);
677 result=STATE_CRITICAL; 677 result=STATE_CRITICAL;
678 } else { 678 } else {
679 purgeable_disk_space=strtoul(recv_buffer,NULL,10); 679 purgeable_disk_space=strtoul(recv_buffer,NULL,10);
@@ -681,7 +681,7 @@ main(int argc, char **argv) {
681 result=STATE_CRITICAL; 681 result=STATE_CRITICAL;
682 else if (check_warning_value==TRUE && purgeable_disk_space >= warning_value) 682 else if (check_warning_value==TRUE && purgeable_disk_space >= warning_value)
683 result=STATE_WARNING; 683 result=STATE_WARNING;
684 asprintf (&output_message,_("%s%lu MB purgeable on volume %s|Purge%s=%lu;%lu;%lu;;"), 684 xasprintf (&output_message,_("%s%lu MB purgeable on volume %s|Purge%s=%lu;%lu;%lu;;"),
685 (result==STATE_OK)?"":_("Only "), 685 (result==STATE_OK)?"":_("Only "),
686 purgeable_disk_space, 686 purgeable_disk_space,
687 volume_name, 687 volume_name,
@@ -697,14 +697,14 @@ main(int argc, char **argv) {
697 close(sd); 697 close(sd);
698 my_tcp_connect (server_address, server_port, &sd); 698 my_tcp_connect (server_address, server_port, &sd);
699 699
700 asprintf (&send_buffer,"VKP%s\r\n",volume_name); 700 xasprintf (&send_buffer,"VKP%s\r\n",volume_name);
701 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer)); 701 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
702 if (result!=STATE_OK) 702 if (result!=STATE_OK)
703 return result; 703 return result;
704 704
705 if (!strcmp(recv_buffer,"-1\n")) { 705 if (!strcmp(recv_buffer,"-1\n")) {
706 706
707 asprintf (&output_message,_("CRITICAL - Volume '%s' does not exist!"),volume_name); 707 xasprintf (&output_message,_("CRITICAL - Volume '%s' does not exist!"),volume_name);
708 result=STATE_CRITICAL; 708 result=STATE_CRITICAL;
709 709
710 } else { 710 } else {
@@ -714,7 +714,7 @@ main(int argc, char **argv) {
714 close(sd); 714 close(sd);
715 my_tcp_connect (server_address, server_port, &sd); 715 my_tcp_connect (server_address, server_port, &sd);
716 716
717 asprintf (&send_buffer,"VKS%s\r\n",volume_name); 717 xasprintf (&send_buffer,"VKS%s\r\n",volume_name);
718 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer)); 718 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
719 if (result!=STATE_OK) 719 if (result!=STATE_OK)
720 return result; 720 return result;
@@ -727,7 +727,7 @@ main(int argc, char **argv) {
727 else if (check_warning_value==TRUE && percent_purgeable_space >= warning_value) 727 else if (check_warning_value==TRUE && percent_purgeable_space >= warning_value)
728 result=STATE_WARNING; 728 result=STATE_WARNING;
729 purgeable_disk_space/=1024; 729 purgeable_disk_space/=1024;
730 asprintf (&output_message,_("%lu MB (%lu%%) purgeable on volume %s|Purgeable%s=%lu;%lu;%lu;0;100"), 730 xasprintf (&output_message,_("%lu MB (%lu%%) purgeable on volume %s|Purgeable%s=%lu;%lu;%lu;0;100"),
731 purgeable_disk_space, 731 purgeable_disk_space,
732 percent_purgeable_space, 732 percent_purgeable_space,
733 volume_name, 733 volume_name,
@@ -744,13 +744,13 @@ main(int argc, char **argv) {
744 close(sd); 744 close(sd);
745 my_tcp_connect (server_address, server_port, &sd); 745 my_tcp_connect (server_address, server_port, &sd);
746 746
747 asprintf (&send_buffer,"VKNP%s\r\n",volume_name); 747 xasprintf (&send_buffer,"VKNP%s\r\n",volume_name);
748 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer)); 748 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
749 if (result!=STATE_OK) 749 if (result!=STATE_OK)
750 return result; 750 return result;
751 751
752 if (!strcmp(recv_buffer,"-1\n")) { 752 if (!strcmp(recv_buffer,"-1\n")) {
753 asprintf (&output_message,_("CRITICAL - Volume '%s' does not exist!"),volume_name); 753 xasprintf (&output_message,_("CRITICAL - Volume '%s' does not exist!"),volume_name);
754 result=STATE_CRITICAL; 754 result=STATE_CRITICAL;
755 } else { 755 } else {
756 non_purgeable_disk_space=strtoul(recv_buffer,NULL,10); 756 non_purgeable_disk_space=strtoul(recv_buffer,NULL,10);
@@ -758,7 +758,7 @@ main(int argc, char **argv) {
758 result=STATE_CRITICAL; 758 result=STATE_CRITICAL;
759 else if (check_warning_value==TRUE && non_purgeable_disk_space >= warning_value) 759 else if (check_warning_value==TRUE && non_purgeable_disk_space >= warning_value)
760 result=STATE_WARNING; 760 result=STATE_WARNING;
761 asprintf (&output_message,_("%s%lu KB not yet purgeable on volume %s"),(result==STATE_OK)?"":_("Only "),non_purgeable_disk_space,volume_name); 761 xasprintf (&output_message,_("%s%lu KB not yet purgeable on volume %s"),(result==STATE_OK)?"":_("Only "),non_purgeable_disk_space,volume_name);
762 } 762 }
763 763
764 /* check % not yet purgeable space on volume */ 764 /* check % not yet purgeable space on volume */
@@ -767,14 +767,14 @@ main(int argc, char **argv) {
767 close(sd); 767 close(sd);
768 my_tcp_connect (server_address, server_port, &sd); 768 my_tcp_connect (server_address, server_port, &sd);
769 769
770 asprintf (&send_buffer,"VKNP%s\r\n",volume_name); 770 xasprintf (&send_buffer,"VKNP%s\r\n",volume_name);
771 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer)); 771 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
772 if (result!=STATE_OK) 772 if (result!=STATE_OK)
773 return result; 773 return result;
774 774
775 if (!strcmp(recv_buffer,"-1\n")) { 775 if (!strcmp(recv_buffer,"-1\n")) {
776 776
777 asprintf (&output_message,_("CRITICAL - Volume '%s' does not exist!"),volume_name); 777 xasprintf (&output_message,_("CRITICAL - Volume '%s' does not exist!"),volume_name);
778 result=STATE_CRITICAL; 778 result=STATE_CRITICAL;
779 779
780 } else { 780 } else {
@@ -784,7 +784,7 @@ main(int argc, char **argv) {
784 close(sd); 784 close(sd);
785 my_tcp_connect (server_address, server_port, &sd); 785 my_tcp_connect (server_address, server_port, &sd);
786 786
787 asprintf (&send_buffer,"VKS%s\r\n",volume_name); 787 xasprintf (&send_buffer,"VKS%s\r\n",volume_name);
788 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer)); 788 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
789 if (result!=STATE_OK) 789 if (result!=STATE_OK)
790 return result; 790 return result;
@@ -797,7 +797,7 @@ main(int argc, char **argv) {
797 else if (check_warning_value==TRUE && percent_non_purgeable_space >= warning_value) 797 else if (check_warning_value==TRUE && percent_non_purgeable_space >= warning_value)
798 result=STATE_WARNING; 798 result=STATE_WARNING;
799 purgeable_disk_space/=1024; 799 purgeable_disk_space/=1024;
800 asprintf (&output_message,_("%lu MB (%lu%%) not yet purgeable on volume %s"),non_purgeable_disk_space,percent_non_purgeable_space,volume_name); 800 xasprintf (&output_message,_("%lu MB (%lu%%) not yet purgeable on volume %s"),non_purgeable_disk_space,percent_non_purgeable_space,volume_name);
801 } 801 }
802 802
803 /* check # of open files */ 803 /* check # of open files */
@@ -806,7 +806,7 @@ main(int argc, char **argv) {
806 close(sd); 806 close(sd);
807 my_tcp_connect (server_address, server_port, &sd); 807 my_tcp_connect (server_address, server_port, &sd);
808 808
809 asprintf (&send_buffer,"S18\r\n"); 809 xasprintf (&send_buffer,"S18\r\n");
810 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer)); 810 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
811 if (result!=STATE_OK) 811 if (result!=STATE_OK)
812 return result; 812 return result;
@@ -818,7 +818,7 @@ main(int argc, char **argv) {
818 else if (check_warning_value==TRUE && open_files >= warning_value) 818 else if (check_warning_value==TRUE && open_files >= warning_value)
819 result=STATE_WARNING; 819 result=STATE_WARNING;
820 820
821 asprintf (&output_message,_("%lu open files|Openfiles=%lu;%lu;%lu;0,0"), 821 xasprintf (&output_message,_("%lu open files|Openfiles=%lu;%lu;%lu;0,0"),
822 open_files, 822 open_files,
823 open_files, 823 open_files,
824 warning_value, 824 warning_value,
@@ -831,7 +831,7 @@ main(int argc, char **argv) {
831 close(sd); 831 close(sd);
832 my_tcp_connect (server_address, server_port, &sd); 832 my_tcp_connect (server_address, server_port, &sd);
833 833
834 asprintf (&send_buffer,"S17\r\n"); 834 xasprintf (&send_buffer,"S17\r\n");
835 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer)); 835 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
836 if (result!=STATE_OK) 836 if (result!=STATE_OK)
837 return result; 837 return result;
@@ -843,7 +843,7 @@ main(int argc, char **argv) {
843 else if (check_warning_value==TRUE && abended_threads >= warning_value) 843 else if (check_warning_value==TRUE && abended_threads >= warning_value)
844 result=STATE_WARNING; 844 result=STATE_WARNING;
845 845
846 asprintf (&output_message,_("%lu abended threads|Abends=%lu;%lu;%lu;;"), 846 xasprintf (&output_message,_("%lu abended threads|Abends=%lu;%lu;%lu;;"),
847 abended_threads, 847 abended_threads,
848 abended_threads, 848 abended_threads,
849 warning_value, 849 warning_value,
@@ -855,7 +855,7 @@ main(int argc, char **argv) {
855 close(sd); 855 close(sd);
856 my_tcp_connect (server_address, server_port, &sd); 856 my_tcp_connect (server_address, server_port, &sd);
857 857
858 asprintf (&send_buffer,"S20\r\n"); 858 xasprintf (&send_buffer,"S20\r\n");
859 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer)); 859 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
860 if (result!=STATE_OK) 860 if (result!=STATE_OK)
861 return result; 861 return result;
@@ -865,7 +865,7 @@ main(int argc, char **argv) {
865 close(sd); 865 close(sd);
866 my_tcp_connect (server_address, server_port, &sd); 866 my_tcp_connect (server_address, server_port, &sd);
867 867
868 asprintf (&send_buffer,"S21\r\n"); 868 xasprintf (&send_buffer,"S21\r\n");
869 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer)); 869 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
870 if (result!=STATE_OK) 870 if (result!=STATE_OK)
871 return result; 871 return result;
@@ -877,7 +877,7 @@ main(int argc, char **argv) {
877 else if (check_warning_value==TRUE && current_service_processes >= warning_value) 877 else if (check_warning_value==TRUE && current_service_processes >= warning_value)
878 result=STATE_WARNING; 878 result=STATE_WARNING;
879 879
880 asprintf (&output_message, 880 xasprintf (&output_message,
881 _("%lu current service processes (%lu max)|Processes=%lu;%lu;%lu;0;%lu"), 881 _("%lu current service processes (%lu max)|Processes=%lu;%lu;%lu;0;%lu"),
882 current_service_processes, 882 current_service_processes,
883 max_service_processes, 883 max_service_processes,
@@ -892,7 +892,7 @@ main(int argc, char **argv) {
892 close(sd); 892 close(sd);
893 my_tcp_connect (server_address, server_port, &sd); 893 my_tcp_connect (server_address, server_port, &sd);
894 894
895 asprintf (&send_buffer,"S22\r\n"); 895 xasprintf (&send_buffer,"S22\r\n");
896 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer)); 896 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
897 if (result!=STATE_OK) 897 if (result!=STATE_OK)
898 return result; 898 return result;
@@ -901,10 +901,10 @@ main(int argc, char **argv) {
901 901
902 if (time_sync_status==0) { 902 if (time_sync_status==0) {
903 result=STATE_CRITICAL; 903 result=STATE_CRITICAL;
904 asprintf (&output_message,_("CRITICAL - Time not in sync with network!")); 904 xasprintf (&output_message,_("CRITICAL - Time not in sync with network!"));
905 } 905 }
906 else { 906 else {
907 asprintf (&output_message,_("OK - Time in sync with network!")); 907 xasprintf (&output_message,_("OK - Time in sync with network!"));
908 } 908 }
909 909
910 910
@@ -927,7 +927,7 @@ main(int argc, char **argv) {
927 result=STATE_CRITICAL; 927 result=STATE_CRITICAL;
928 else if (check_warning_value==TRUE && lru_time <= warning_value) 928 else if (check_warning_value==TRUE && lru_time <= warning_value)
929 result=STATE_WARNING; 929 result=STATE_WARNING;
930 asprintf (&output_message,_("LRU sitting time = %lu seconds"),lru_time); 930 xasprintf (&output_message,_("LRU sitting time = %lu seconds"),lru_time);
931 931
932 932
933 /* check % dirty cacheobuffers as a percentage of the total*/ 933 /* check % dirty cacheobuffers as a percentage of the total*/
@@ -946,7 +946,7 @@ main(int argc, char **argv) {
946 result=STATE_CRITICAL; 946 result=STATE_CRITICAL;
947 else if (check_warning_value==TRUE && dirty_cache_buffers <= warning_value) 947 else if (check_warning_value==TRUE && dirty_cache_buffers <= warning_value)
948 result=STATE_WARNING; 948 result=STATE_WARNING;
949 asprintf (&output_message,_("Dirty cache buffers = %lu%% of the total|DCB=%lu;%lu;%lu;0;100"), 949 xasprintf (&output_message,_("Dirty cache buffers = %lu%% of the total|DCB=%lu;%lu;%lu;0;100"),
950 dirty_cache_buffers, 950 dirty_cache_buffers,
951 dirty_cache_buffers, 951 dirty_cache_buffers,
952 warning_value, 952 warning_value,
@@ -968,7 +968,7 @@ main(int argc, char **argv) {
968 result=STATE_CRITICAL; 968 result=STATE_CRITICAL;
969 else if (check_warning_value==TRUE && total_cache_buffers <= warning_value) 969 else if (check_warning_value==TRUE && total_cache_buffers <= warning_value)
970 result=STATE_WARNING; 970 result=STATE_WARNING;
971 asprintf (&output_message,_("Total cache buffers = %lu%% of the original|TCB=%lu;%lu;%lu;0;100"), 971 xasprintf (&output_message,_("Total cache buffers = %lu%% of the original|TCB=%lu;%lu;%lu;0;100"),
972 total_cache_buffers, 972 total_cache_buffers,
973 total_cache_buffers, 973 total_cache_buffers,
974 warning_value, 974 warning_value,
@@ -979,21 +979,21 @@ main(int argc, char **argv) {
979 close(sd); 979 close(sd);
980 my_tcp_connect (server_address, server_port, &sd); 980 my_tcp_connect (server_address, server_port, &sd);
981 981
982 asprintf (&send_buffer,"S13\r\n"); 982 xasprintf (&send_buffer,"S13\r\n");
983 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer)); 983 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
984 if (result!=STATE_OK) 984 if (result!=STATE_OK)
985 return result; 985 return result;
986 986
987 recv_buffer[strlen(recv_buffer)-1]=0; 987 recv_buffer[strlen(recv_buffer)-1]=0;
988 988
989 asprintf (&output_message,_("NDS Version %s"),recv_buffer); 989 xasprintf (&output_message,_("NDS Version %s"),recv_buffer);
990 990
991 } else if (vars_to_check==UPTIME) { 991 } else if (vars_to_check==UPTIME) {
992 992
993 close(sd); 993 close(sd);
994 my_tcp_connect (server_address, server_port, &sd); 994 my_tcp_connect (server_address, server_port, &sd);
995 995
996 asprintf (&send_buffer,"UPTIME\r\n"); 996 xasprintf (&send_buffer,"UPTIME\r\n");
997 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer)); 997 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
998 if (result!=STATE_OK) 998 if (result!=STATE_OK)
999 return result; 999 return result;
@@ -1002,35 +1002,35 @@ main(int argc, char **argv) {
1002 recv_buffer[sizeof(recv_buffer)-1]=0; 1002 recv_buffer[sizeof(recv_buffer)-1]=0;
1003 recv_buffer[strlen(recv_buffer)-1]=0; 1003 recv_buffer[strlen(recv_buffer)-1]=0;
1004 1004
1005 asprintf (&output_message,_("Up %s"),recv_buffer); 1005 xasprintf (&output_message,_("Up %s"),recv_buffer);
1006 1006
1007 } else if (vars_to_check==NLM) { 1007 } else if (vars_to_check==NLM) {
1008 1008
1009 close(sd); 1009 close(sd);
1010 my_tcp_connect (server_address, server_port, &sd); 1010 my_tcp_connect (server_address, server_port, &sd);
1011 1011
1012 asprintf (&send_buffer,"S24:%s\r\n",nlm_name); 1012 xasprintf (&send_buffer,"S24:%s\r\n",nlm_name);
1013 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer)); 1013 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
1014 if (result!=STATE_OK) 1014 if (result!=STATE_OK)
1015 return result; 1015 return result;
1016 1016
1017 recv_buffer[strlen(recv_buffer)-1]=0; 1017 recv_buffer[strlen(recv_buffer)-1]=0;
1018 if (strcmp(recv_buffer,"-1")) { 1018 if (strcmp(recv_buffer,"-1")) {
1019 asprintf (&output_message,_("Module %s version %s is loaded"),nlm_name,recv_buffer); 1019 xasprintf (&output_message,_("Module %s version %s is loaded"),nlm_name,recv_buffer);
1020 } else { 1020 } else {
1021 result=STATE_CRITICAL; 1021 result=STATE_CRITICAL;
1022 asprintf (&output_message,_("Module %s is not loaded"),nlm_name); 1022 xasprintf (&output_message,_("Module %s is not loaded"),nlm_name);
1023 1023
1024 } 1024 }
1025 } else if (vars_to_check==NRMP) { 1025 } else if (vars_to_check==NRMP) {
1026 1026
1027 asprintf (&send_buffer,"NRMP:%s\r\n",nrmp_name); 1027 xasprintf (&send_buffer,"NRMP:%s\r\n",nrmp_name);
1028 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer)); 1028 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
1029 if (result!=STATE_OK) 1029 if (result!=STATE_OK)
1030 return result; 1030 return result;
1031 1031
1032 if (!strcmp(recv_buffer,"-1\n")) { 1032 if (!strcmp(recv_buffer,"-1\n")) {
1033 asprintf (&output_message,_("CRITICAL - Value '%s' does not exist!"),nrmp_name); 1033 xasprintf (&output_message,_("CRITICAL - Value '%s' does not exist!"),nrmp_name);
1034 result=STATE_CRITICAL; 1034 result=STATE_CRITICAL;
1035 } else { 1035 } else {
1036 nrmp_value=strtoul(recv_buffer,NULL,10); 1036 nrmp_value=strtoul(recv_buffer,NULL,10);
@@ -1038,7 +1038,7 @@ main(int argc, char **argv) {
1038 result=STATE_CRITICAL; 1038 result=STATE_CRITICAL;
1039 else if (check_warning_value==TRUE && nrmp_value <= warning_value) 1039 else if (check_warning_value==TRUE && nrmp_value <= warning_value)
1040 result=STATE_WARNING; 1040 result=STATE_WARNING;
1041 asprintf (&output_message, 1041 xasprintf (&output_message,
1042 _("%s is %lu|%s=%lu;%lu;%lu;;"), 1042 _("%s is %lu|%s=%lu;%lu;%lu;;"),
1043 nrmp_name, 1043 nrmp_name,
1044 nrmp_value, 1044 nrmp_value,
@@ -1050,13 +1050,13 @@ main(int argc, char **argv) {
1050 1050
1051 } else if (vars_to_check==NRMM) { 1051 } else if (vars_to_check==NRMM) {
1052 1052
1053 asprintf (&send_buffer,"NRMM:%s\r\n",nrmm_name); 1053 xasprintf (&send_buffer,"NRMM:%s\r\n",nrmm_name);
1054 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer)); 1054 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
1055 if (result!=STATE_OK) 1055 if (result!=STATE_OK)
1056 return result; 1056 return result;
1057 1057
1058 if (!strcmp(recv_buffer,"-1\n")) { 1058 if (!strcmp(recv_buffer,"-1\n")) {
1059 asprintf (&output_message,_("CRITICAL - Value '%s' does not exist!"),nrmm_name); 1059 xasprintf (&output_message,_("CRITICAL - Value '%s' does not exist!"),nrmm_name);
1060 result=STATE_CRITICAL; 1060 result=STATE_CRITICAL;
1061 } else { 1061 } else {
1062 nrmm_value=strtoul(recv_buffer,NULL,10); 1062 nrmm_value=strtoul(recv_buffer,NULL,10);
@@ -1064,7 +1064,7 @@ main(int argc, char **argv) {
1064 result=STATE_CRITICAL; 1064 result=STATE_CRITICAL;
1065 else if (check_warning_value==TRUE && nrmm_value <= warning_value) 1065 else if (check_warning_value==TRUE && nrmm_value <= warning_value)
1066 result=STATE_WARNING; 1066 result=STATE_WARNING;
1067 asprintf (&output_message, 1067 xasprintf (&output_message,
1068 _("%s is %lu|%s=%lu;%lu;%lu;;"), 1068 _("%s is %lu|%s=%lu;%lu;%lu;;"),
1069 nrmm_name, 1069 nrmm_name,
1070 nrmm_value, 1070 nrmm_value,
@@ -1076,13 +1076,13 @@ main(int argc, char **argv) {
1076 1076
1077 } else if (vars_to_check==NRMS) { 1077 } else if (vars_to_check==NRMS) {
1078 1078
1079 asprintf (&send_buffer,"NRMS:%s\r\n",nrms_name); 1079 xasprintf (&send_buffer,"NRMS:%s\r\n",nrms_name);
1080 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer)); 1080 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
1081 if (result!=STATE_OK) 1081 if (result!=STATE_OK)
1082 return result; 1082 return result;
1083 1083
1084 if (!strcmp(recv_buffer,"-1\n")) { 1084 if (!strcmp(recv_buffer,"-1\n")) {
1085 asprintf (&output_message,_("CRITICAL - Value '%s' does not exist!"),nrms_name); 1085 xasprintf (&output_message,_("CRITICAL - Value '%s' does not exist!"),nrms_name);
1086 result=STATE_CRITICAL; 1086 result=STATE_CRITICAL;
1087 } else { 1087 } else {
1088 nrms_value=strtoul(recv_buffer,NULL,10); 1088 nrms_value=strtoul(recv_buffer,NULL,10);
@@ -1090,7 +1090,7 @@ main(int argc, char **argv) {
1090 result=STATE_CRITICAL; 1090 result=STATE_CRITICAL;
1091 else if (check_warning_value==TRUE && nrms_value >= warning_value) 1091 else if (check_warning_value==TRUE && nrms_value >= warning_value)
1092 result=STATE_WARNING; 1092 result=STATE_WARNING;
1093 asprintf (&output_message, 1093 xasprintf (&output_message,
1094 _("%s is %lu|%s=%lu;%lu;%lu;;"), 1094 _("%s is %lu|%s=%lu;%lu;%lu;;"),
1095 nrms_name, 1095 nrms_name,
1096 nrms_value, 1096 nrms_value,
@@ -1102,13 +1102,13 @@ main(int argc, char **argv) {
1102 1102
1103 } else if (vars_to_check==NSS1) { 1103 } else if (vars_to_check==NSS1) {
1104 1104
1105 asprintf (&send_buffer,"NSS1:%s\r\n",nss1_name); 1105 xasprintf (&send_buffer,"NSS1:%s\r\n",nss1_name);
1106 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer)); 1106 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
1107 if (result!=STATE_OK) 1107 if (result!=STATE_OK)
1108 return result; 1108 return result;
1109 1109
1110 if (!strcmp(recv_buffer,"-1\n")) { 1110 if (!strcmp(recv_buffer,"-1\n")) {
1111 asprintf (&output_message,_("CRITICAL - Value '%s' does not exist!"),nss1_name); 1111 xasprintf (&output_message,_("CRITICAL - Value '%s' does not exist!"),nss1_name);
1112 result=STATE_CRITICAL; 1112 result=STATE_CRITICAL;
1113 } else { 1113 } else {
1114 nss1_value=strtoul(recv_buffer,NULL,10); 1114 nss1_value=strtoul(recv_buffer,NULL,10);
@@ -1116,7 +1116,7 @@ main(int argc, char **argv) {
1116 result=STATE_CRITICAL; 1116 result=STATE_CRITICAL;
1117 else if (check_warning_value==TRUE && nss1_value >= warning_value) 1117 else if (check_warning_value==TRUE && nss1_value >= warning_value)
1118 result=STATE_WARNING; 1118 result=STATE_WARNING;
1119 asprintf (&output_message, 1119 xasprintf (&output_message,
1120 _("%s is %lu|%s=%lu;%lu;%lu;;"), 1120 _("%s is %lu|%s=%lu;%lu;%lu;;"),
1121 nss1_name, 1121 nss1_name,
1122 nss1_value, 1122 nss1_value,
@@ -1128,13 +1128,13 @@ main(int argc, char **argv) {
1128 1128
1129 } else if (vars_to_check==NSS2) { 1129 } else if (vars_to_check==NSS2) {
1130 1130
1131 asprintf (&send_buffer,"NSS2:%s\r\n",nss2_name); 1131 xasprintf (&send_buffer,"NSS2:%s\r\n",nss2_name);
1132 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer)); 1132 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
1133 if (result!=STATE_OK) 1133 if (result!=STATE_OK)
1134 return result; 1134 return result;
1135 1135
1136 if (!strcmp(recv_buffer,"-1\n")) { 1136 if (!strcmp(recv_buffer,"-1\n")) {
1137 asprintf (&output_message,_("CRITICAL - Value '%s' does not exist!"),nss2_name); 1137 xasprintf (&output_message,_("CRITICAL - Value '%s' does not exist!"),nss2_name);
1138 result=STATE_CRITICAL; 1138 result=STATE_CRITICAL;
1139 } else { 1139 } else {
1140 nss2_value=strtoul(recv_buffer,NULL,10); 1140 nss2_value=strtoul(recv_buffer,NULL,10);
@@ -1142,7 +1142,7 @@ main(int argc, char **argv) {
1142 result=STATE_CRITICAL; 1142 result=STATE_CRITICAL;
1143 else if (check_warning_value==TRUE && nss2_value >= warning_value) 1143 else if (check_warning_value==TRUE && nss2_value >= warning_value)
1144 result=STATE_WARNING; 1144 result=STATE_WARNING;
1145 asprintf (&output_message, 1145 xasprintf (&output_message,
1146 _("%s is %lu|%s=%lu;%lu;%lu;;"), 1146 _("%s is %lu|%s=%lu;%lu;%lu;;"),
1147 nss2_name, 1147 nss2_name,
1148 nss2_value, 1148 nss2_value,
@@ -1154,13 +1154,13 @@ main(int argc, char **argv) {
1154 1154
1155 } else if (vars_to_check==NSS3) { 1155 } else if (vars_to_check==NSS3) {
1156 1156
1157 asprintf (&send_buffer,"NSS3:%s\r\n",nss3_name); 1157 xasprintf (&send_buffer,"NSS3:%s\r\n",nss3_name);
1158 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer)); 1158 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
1159 if (result!=STATE_OK) 1159 if (result!=STATE_OK)
1160 return result; 1160 return result;
1161 1161
1162 if (!strcmp(recv_buffer,"-1\n")) { 1162 if (!strcmp(recv_buffer,"-1\n")) {
1163 asprintf (&output_message,_("CRITICAL - Value '%s' does not exist!"),nss3_name); 1163 xasprintf (&output_message,_("CRITICAL - Value '%s' does not exist!"),nss3_name);
1164 result=STATE_CRITICAL; 1164 result=STATE_CRITICAL;
1165 } else { 1165 } else {
1166 nss3_value=strtoul(recv_buffer,NULL,10); 1166 nss3_value=strtoul(recv_buffer,NULL,10);
@@ -1168,7 +1168,7 @@ main(int argc, char **argv) {
1168 result=STATE_CRITICAL; 1168 result=STATE_CRITICAL;
1169 else if (check_warning_value==TRUE && nss3_value >= warning_value) 1169 else if (check_warning_value==TRUE && nss3_value >= warning_value)
1170 result=STATE_WARNING; 1170 result=STATE_WARNING;
1171 asprintf (&output_message, 1171 xasprintf (&output_message,
1172 _("%s is %lu|%s=%lu;%lu;%lu;;"), 1172 _("%s is %lu|%s=%lu;%lu;%lu;;"),
1173 nss3_name, 1173 nss3_name,
1174 nss3_value, 1174 nss3_value,
@@ -1180,13 +1180,13 @@ main(int argc, char **argv) {
1180 1180
1181 } else if (vars_to_check==NSS4) { 1181 } else if (vars_to_check==NSS4) {
1182 1182
1183 asprintf (&send_buffer,"NSS4:%s\r\n",nss4_name); 1183 xasprintf (&send_buffer,"NSS4:%s\r\n",nss4_name);
1184 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer)); 1184 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
1185 if (result!=STATE_OK) 1185 if (result!=STATE_OK)
1186 return result; 1186 return result;
1187 1187
1188 if (!strcmp(recv_buffer,"-1\n")) { 1188 if (!strcmp(recv_buffer,"-1\n")) {
1189 asprintf (&output_message,_("CRITICAL - Value '%s' does not exist!"),nss4_name); 1189 xasprintf (&output_message,_("CRITICAL - Value '%s' does not exist!"),nss4_name);
1190 result=STATE_CRITICAL; 1190 result=STATE_CRITICAL;
1191 } else { 1191 } else {
1192 nss4_value=strtoul(recv_buffer,NULL,10); 1192 nss4_value=strtoul(recv_buffer,NULL,10);
@@ -1194,7 +1194,7 @@ main(int argc, char **argv) {
1194 result=STATE_CRITICAL; 1194 result=STATE_CRITICAL;
1195 else if (check_warning_value==TRUE && nss4_value >= warning_value) 1195 else if (check_warning_value==TRUE && nss4_value >= warning_value)
1196 result=STATE_WARNING; 1196 result=STATE_WARNING;
1197 asprintf (&output_message, 1197 xasprintf (&output_message,
1198 _("%s is %lu|%s=%lu;%lu;%lu;;"), 1198 _("%s is %lu|%s=%lu;%lu;%lu;;"),
1199 nss4_name, 1199 nss4_name,
1200 nss4_value, 1200 nss4_value,
@@ -1206,13 +1206,13 @@ main(int argc, char **argv) {
1206 1206
1207 } else if (vars_to_check==NSS5) { 1207 } else if (vars_to_check==NSS5) {
1208 1208
1209 asprintf (&send_buffer,"NSS5:%s\r\n",nss5_name); 1209 xasprintf (&send_buffer,"NSS5:%s\r\n",nss5_name);
1210 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer)); 1210 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
1211 if (result!=STATE_OK) 1211 if (result!=STATE_OK)
1212 return result; 1212 return result;
1213 1213
1214 if (!strcmp(recv_buffer,"-1\n")) { 1214 if (!strcmp(recv_buffer,"-1\n")) {
1215 asprintf (&output_message,_("CRITICAL - Value '%s' does not exist!"),nss5_name); 1215 xasprintf (&output_message,_("CRITICAL - Value '%s' does not exist!"),nss5_name);
1216 result=STATE_CRITICAL; 1216 result=STATE_CRITICAL;
1217 } else { 1217 } else {
1218 nss5_value=strtoul(recv_buffer,NULL,10); 1218 nss5_value=strtoul(recv_buffer,NULL,10);
@@ -1220,7 +1220,7 @@ main(int argc, char **argv) {
1220 result=STATE_CRITICAL; 1220 result=STATE_CRITICAL;
1221 else if (check_warning_value==TRUE && nss5_value >= warning_value) 1221 else if (check_warning_value==TRUE && nss5_value >= warning_value)
1222 result=STATE_WARNING; 1222 result=STATE_WARNING;
1223 asprintf (&output_message, 1223 xasprintf (&output_message,
1224 _("%s is %lu|%s=%lu;%lu;%lu;;"), 1224 _("%s is %lu|%s=%lu;%lu;%lu;;"),
1225 nss5_name, 1225 nss5_name,
1226 nss5_value, 1226 nss5_value,
@@ -1232,13 +1232,13 @@ main(int argc, char **argv) {
1232 1232
1233 } else if (vars_to_check==NSS6) { 1233 } else if (vars_to_check==NSS6) {
1234 1234
1235 asprintf (&send_buffer,"NSS6:%s\r\n",nss6_name); 1235 xasprintf (&send_buffer,"NSS6:%s\r\n",nss6_name);
1236 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer)); 1236 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
1237 if (result!=STATE_OK) 1237 if (result!=STATE_OK)
1238 return result; 1238 return result;
1239 1239
1240 if (!strcmp(recv_buffer,"-1\n")) { 1240 if (!strcmp(recv_buffer,"-1\n")) {
1241 asprintf (&output_message,_("CRITICAL - Value '%s' does not exist!"),nss6_name); 1241 xasprintf (&output_message,_("CRITICAL - Value '%s' does not exist!"),nss6_name);
1242 result=STATE_CRITICAL; 1242 result=STATE_CRITICAL;
1243 } else { 1243 } else {
1244 nss6_value=strtoul(recv_buffer,NULL,10); 1244 nss6_value=strtoul(recv_buffer,NULL,10);
@@ -1246,7 +1246,7 @@ main(int argc, char **argv) {
1246 result=STATE_CRITICAL; 1246 result=STATE_CRITICAL;
1247 else if (check_warning_value==TRUE && nss6_value >= warning_value) 1247 else if (check_warning_value==TRUE && nss6_value >= warning_value)
1248 result=STATE_WARNING; 1248 result=STATE_WARNING;
1249 asprintf (&output_message, 1249 xasprintf (&output_message,
1250 _("%s is %lu|%s=%lu;%lu;%lu;;"), 1250 _("%s is %lu|%s=%lu;%lu;%lu;;"),
1251 nss6_name, 1251 nss6_name,
1252 nss6_value, 1252 nss6_value,
@@ -1258,13 +1258,13 @@ main(int argc, char **argv) {
1258 1258
1259 } else if (vars_to_check==NSS7) { 1259 } else if (vars_to_check==NSS7) {
1260 1260
1261 asprintf (&send_buffer,"NSS7:%s\r\n",nss7_name); 1261 xasprintf (&send_buffer,"NSS7:%s\r\n",nss7_name);
1262 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer)); 1262 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
1263 if (result!=STATE_OK) 1263 if (result!=STATE_OK)
1264 return result; 1264 return result;
1265 1265
1266 if (!strcmp(recv_buffer,"-1\n")) { 1266 if (!strcmp(recv_buffer,"-1\n")) {
1267 asprintf (&output_message,_("CRITICAL - Value '%s' does not exist!"),nss7_name); 1267 xasprintf (&output_message,_("CRITICAL - Value '%s' does not exist!"),nss7_name);
1268 result=STATE_CRITICAL; 1268 result=STATE_CRITICAL;
1269 } else { 1269 } else {
1270 nss7_value=strtoul(recv_buffer,NULL,10); 1270 nss7_value=strtoul(recv_buffer,NULL,10);
@@ -1272,7 +1272,7 @@ main(int argc, char **argv) {
1272 result=STATE_CRITICAL; 1272 result=STATE_CRITICAL;
1273 else if (check_warning_value==TRUE && nss7_value >= warning_value) 1273 else if (check_warning_value==TRUE && nss7_value >= warning_value)
1274 result=STATE_WARNING; 1274 result=STATE_WARNING;
1275 asprintf (&output_message, 1275 xasprintf (&output_message,
1276 _("%s is %lu|%s=%lu;%lu;%lu;;"), 1276 _("%s is %lu|%s=%lu;%lu;%lu;;"),
1277 nss7_name, 1277 nss7_name,
1278 nss7_value, 1278 nss7_value,
@@ -1591,7 +1591,7 @@ int process_arguments(int argc, char **argv) {
1591void print_help(void) 1591void print_help(void)
1592{ 1592{
1593 char *myport; 1593 char *myport;
1594 asprintf (&myport, "%d", PORT); 1594 xasprintf (&myport, "%d", PORT);
1595 1595
1596 print_revision (progname, NP_VERSION); 1596 print_revision (progname, NP_VERSION);
1597 1597
diff --git a/plugins/check_overcr.c b/plugins/check_overcr.c
index 16ada20..95977e9 100644
--- a/plugins/check_overcr.c
+++ b/plugins/check_overcr.c
@@ -409,7 +409,7 @@ void
409print_help (void) 409print_help (void)
410{ 410{
411 char *myport; 411 char *myport;
412 asprintf (&myport, "%d", PORT); 412 xasprintf (&myport, "%d", PORT);
413 413
414 print_revision (progname, NP_VERSION); 414 print_revision (progname, NP_VERSION);
415 415
diff --git a/plugins/check_pgsql.c b/plugins/check_pgsql.c
index 19c3117..69edae7 100644
--- a/plugins/check_pgsql.c
+++ b/plugins/check_pgsql.c
@@ -417,7 +417,7 @@ print_help (void)
417{ 417{
418 char *myport; 418 char *myport;
419 419
420 asprintf (&myport, "%d", DEFAULT_PORT); 420 xasprintf (&myport, "%d", DEFAULT_PORT);
421 421
422 print_revision (progname, NP_VERSION); 422 print_revision (progname, NP_VERSION);
423 423
diff --git a/plugins/check_ping.c b/plugins/check_ping.c
index ecdd618..eef2195 100644
--- a/plugins/check_ping.c
+++ b/plugins/check_ping.c
@@ -121,12 +121,12 @@ main (int argc, char **argv)
121 /* does the host address of number of packets argument come first? */ 121 /* does the host address of number of packets argument come first? */
122#ifdef PING_PACKETS_FIRST 122#ifdef PING_PACKETS_FIRST
123# ifdef PING_HAS_TIMEOUT 123# ifdef PING_HAS_TIMEOUT
124 asprintf (&cmd, rawcmd, timeout_interval, max_packets, addresses[i]); 124 xasprintf (&cmd, rawcmd, timeout_interval, max_packets, addresses[i]);
125# else 125# else
126 asprintf (&cmd, rawcmd, max_packets, addresses[i]); 126 xasprintf (&cmd, rawcmd, max_packets, addresses[i]);
127# endif 127# endif
128#else 128#else
129 asprintf (&cmd, rawcmd, addresses[i], max_packets); 129 xasprintf (&cmd, rawcmd, addresses[i], max_packets);
130#endif 130#endif
131 131
132 if (verbose >= 2) 132 if (verbose >= 2)
@@ -432,6 +432,7 @@ run_ping (const char *cmd, const char *addr)
432{ 432{
433 char buf[MAX_INPUT_BUFFER]; 433 char buf[MAX_INPUT_BUFFER];
434 int result = STATE_UNKNOWN; 434 int result = STATE_UNKNOWN;
435 int match;
435 436
436 if ((child_process = spopen (cmd)) == NULL) 437 if ((child_process = spopen (cmd)) == NULL)
437 die (STATE_UNKNOWN, _("Could not open pipe: %s\n"), cmd); 438 die (STATE_UNKNOWN, _("Could not open pipe: %s\n"), cmd);
@@ -448,28 +449,29 @@ run_ping (const char *cmd, const char *addr)
448 result = max_state (result, error_scan (buf, addr)); 449 result = max_state (result, error_scan (buf, addr));
449 450
450 /* get the percent loss statistics */ 451 /* get the percent loss statistics */
451 if(sscanf(buf,"%*d packets transmitted, %*d packets received, +%*d errors, %d%% packet loss",&pl)==1 || 452 match = 0;
452 sscanf(buf,"%*d packets transmitted, %*d packets received, +%*d duplicates, %d%% packet loss", &pl) == 1 || 453 if((sscanf(buf,"%*d packets transmitted, %*d packets received, +%*d errors, %d%% packet loss%n",&pl,&match) && match) ||
453 sscanf(buf,"%*d packets transmitted, %*d received, +%*d duplicates, %d%% packet loss", &pl) == 1 || 454 (sscanf(buf,"%*d packets transmitted, %*d packets received, +%*d duplicates, %d%% packet loss%n",&pl,&match) && match) ||
454 sscanf(buf,"%*d packets transmitted, %*d packets received, %d%% packet loss",&pl)==1 || 455 (sscanf(buf,"%*d packets transmitted, %*d received, +%*d duplicates, %d%% packet loss%n",&pl,&match) && match) ||
455 sscanf(buf,"%*d packets transmitted, %*d packets received, %d%% loss, time",&pl)==1 || 456 (sscanf(buf,"%*d packets transmitted, %*d packets received, %d%% packet loss%n",&pl,&match) && match) ||
456 sscanf(buf,"%*d packets transmitted, %*d received, %d%% loss, time", &pl)==1 || 457 (sscanf(buf,"%*d packets transmitted, %*d packets received, %d%% loss, time%n",&pl,&match) && match) ||
457 sscanf(buf,"%*d packets transmitted, %*d received, %d%% packet loss, time", &pl)==1 || 458 (sscanf(buf,"%*d packets transmitted, %*d received, %d%% loss, time%n",&pl,&match) && match) ||
458 sscanf(buf,"%*d packets transmitted, %*d received, +%*d errors, %d%% packet loss", &pl) == 1 || 459 (sscanf(buf,"%*d packets transmitted, %*d received, %d%% packet loss, time%n",&pl,&match) && match) ||
459 sscanf(buf,"%*d packets transmitted %*d received, +%*d errors, %d%% packet loss", &pl) == 1 460 (sscanf(buf,"%*d packets transmitted, %*d received, +%*d errors, %d%% packet loss%n",&pl,&match) && match) ||
461 (sscanf(buf,"%*d packets transmitted %*d received, +%*d errors, %d%% packet loss%n",&pl,&match) && match)
460 ) 462 )
461 continue; 463 continue;
462 464
463 /* get the round trip average */ 465 /* get the round trip average */
464 else 466 else
465 if(sscanf(buf,"round-trip min/avg/max = %*f/%f/%*f",&rta)==1 || 467 if((sscanf(buf,"round-trip min/avg/max = %*f/%f/%*f%n",&rta,&match) && match) ||
466 sscanf(buf,"round-trip min/avg/max/mdev = %*f/%f/%*f/%*f",&rta)==1 || 468 (sscanf(buf,"round-trip min/avg/max/mdev = %*f/%f/%*f/%*f%n",&rta,&match) && match) ||
467 sscanf(buf,"round-trip min/avg/max/sdev = %*f/%f/%*f/%*f",&rta)==1 || 469 (sscanf(buf,"round-trip min/avg/max/sdev = %*f/%f/%*f/%*f%n",&rta,&match) && match) ||
468 sscanf(buf,"round-trip min/avg/max/stddev = %*f/%f/%*f/%*f",&rta)==1 || 470 (sscanf(buf,"round-trip min/avg/max/stddev = %*f/%f/%*f/%*f%n",&rta,&match) && match) ||
469 sscanf(buf,"round-trip min/avg/max/std-dev = %*f/%f/%*f/%*f",&rta)==1 || 471 (sscanf(buf,"round-trip min/avg/max/std-dev = %*f/%f/%*f/%*f%n",&rta,&match) && match) ||
470 sscanf(buf,"round-trip (ms) min/avg/max = %*f/%f/%*f",&rta)==1 || 472 (sscanf(buf,"round-trip (ms) min/avg/max = %*f/%f/%*f%n",&rta,&match) && match) ||
471 sscanf(buf,"round-trip (ms) min/avg/max/stddev = %*f/%f/%*f/%*f",&rta)==1 || 473 (sscanf(buf,"round-trip (ms) min/avg/max/stddev = %*f/%f/%*f/%*f%n",&rta,&match) && match) ||
472 sscanf(buf,"rtt min/avg/max/mdev = %*f/%f/%*f/%*f ms",&rta)==1) 474 (sscanf(buf,"rtt min/avg/max/mdev = %*f/%f/%*f/%*f ms%n",&rta,&match) && match))
473 continue; 475 continue;
474 } 476 }
475 477
@@ -489,7 +491,7 @@ run_ping (const char *cmd, const char *addr)
489 if (warn_text == NULL) { 491 if (warn_text == NULL) {
490 warn_text = strdup(_("System call sent warnings to stderr ")); 492 warn_text = strdup(_("System call sent warnings to stderr "));
491 } else { 493 } else {
492 asprintf(&warn_text, "%s %s", warn_text, _("System call sent warnings to stderr ")); 494 xasprintf(&warn_text, "%s %s", warn_text, _("System call sent warnings to stderr "));
493 } 495 }
494 } 496 }
495 } 497 }
@@ -498,9 +500,7 @@ run_ping (const char *cmd, const char *addr)
498 (void) fclose (child_stderr); 500 (void) fclose (child_stderr);
499 501
500 502
501 /* close the pipe - WARNING if status is set */ 503 spclose (child_process);
502 if (spclose (child_process))
503 result = max_state (result, STATE_WARNING);
504 504
505 if (warn_text == NULL) 505 if (warn_text == NULL)
506 warn_text = strdup(""); 506 warn_text = strdup("");
@@ -516,30 +516,32 @@ error_scan (char buf[MAX_INPUT_BUFFER], const char *addr)
516 if (strstr (buf, "Network is unreachable") || 516 if (strstr (buf, "Network is unreachable") ||
517 strstr (buf, "Destination Net Unreachable") 517 strstr (buf, "Destination Net Unreachable")
518 ) 518 )
519 die (STATE_CRITICAL, _("CRITICAL - Network Unreachable (%s)"), addr); 519 die (STATE_CRITICAL, _("CRITICAL - Network Unreachable (%s)\n"), addr);
520 else if (strstr (buf, "Destination Host Unreachable")) 520 else if (strstr (buf, "Destination Host Unreachable"))
521 die (STATE_CRITICAL, _("CRITICAL - Host Unreachable (%s)"), addr); 521 die (STATE_CRITICAL, _("CRITICAL - Host Unreachable (%s)\n"), addr);
522 else if (strstr (buf, "Destination Port Unreachable")) 522 else if (strstr (buf, "Destination Port Unreachable"))
523 die (STATE_CRITICAL, _("CRITICAL - Bogus ICMP: Port Unreachable (%s)"), addr); 523 die (STATE_CRITICAL, _("CRITICAL - Bogus ICMP: Port Unreachable (%s)\n"), addr);
524 else if (strstr (buf, "Destination Protocol Unreachable")) 524 else if (strstr (buf, "Destination Protocol Unreachable"))
525 die (STATE_CRITICAL, _("CRITICAL - Bogus ICMP: Protocol Unreachable (%s)"), addr); 525 die (STATE_CRITICAL, _("CRITICAL - Bogus ICMP: Protocol Unreachable (%s)\n"), addr);
526 else if (strstr (buf, "Destination Net Prohibited")) 526 else if (strstr (buf, "Destination Net Prohibited"))
527 die (STATE_CRITICAL, _("CRITICAL - Network Prohibited (%s)"), addr); 527 die (STATE_CRITICAL, _("CRITICAL - Network Prohibited (%s)\n"), addr);
528 else if (strstr (buf, "Destination Host Prohibited")) 528 else if (strstr (buf, "Destination Host Prohibited"))
529 die (STATE_CRITICAL, _("CRITICAL - Host Prohibited (%s)"), addr); 529 die (STATE_CRITICAL, _("CRITICAL - Host Prohibited (%s)\n"), addr);
530 else if (strstr (buf, "Packet filtered")) 530 else if (strstr (buf, "Packet filtered"))
531 die (STATE_CRITICAL, _("CRITICAL - Packet Filtered (%s)"), addr); 531 die (STATE_CRITICAL, _("CRITICAL - Packet Filtered (%s)\n"), addr);
532 else if (strstr (buf, "unknown host" )) 532 else if (strstr (buf, "unknown host" ))
533 die (STATE_CRITICAL, _("CRITICAL - Host not found (%s)"), addr); 533 die (STATE_CRITICAL, _("CRITICAL - Host not found (%s)\n"), addr);
534 else if (strstr (buf, "Time to live exceeded")) 534 else if (strstr (buf, "Time to live exceeded"))
535 die (STATE_CRITICAL, _("CRITICAL - Time to live exceeded (%s)"), addr); 535 die (STATE_CRITICAL, _("CRITICAL - Time to live exceeded (%s)\n"), addr);
536 else if (strstr (buf, "Destination unreachable: "))
537 die (STATE_CRITICAL, _("CRITICAL - Destination Unreachable (%s)\n"), addr);
536 538
537 if (strstr (buf, "(DUP!)") || strstr (buf, "DUPLICATES FOUND")) { 539 if (strstr (buf, "(DUP!)") || strstr (buf, "DUPLICATES FOUND")) {
538 if (warn_text == NULL) 540 if (warn_text == NULL)
539 warn_text = strdup (_(WARN_DUPLICATES)); 541 warn_text = strdup (_(WARN_DUPLICATES));
540 else if (! strstr (warn_text, _(WARN_DUPLICATES)) && 542 else if (! strstr (warn_text, _(WARN_DUPLICATES)) &&
541 asprintf (&warn_text, "%s %s", warn_text, _(WARN_DUPLICATES)) == -1) 543 xasprintf (&warn_text, "%s %s", warn_text, _(WARN_DUPLICATES)) == -1)
542 die (STATE_UNKNOWN, _("Unable to realloc warn_text")); 544 die (STATE_UNKNOWN, _("Unable to realloc warn_text\n"));
543 return (STATE_WARNING); 545 return (STATE_WARNING);
544 } 546 }
545 547
diff --git a/plugins/check_procs.c b/plugins/check_procs.c
index d875a61..2f2dcc5 100644
--- a/plugins/check_procs.c
+++ b/plugins/check_procs.c
@@ -137,7 +137,7 @@ main (int argc, char **argv)
137 input_buffer = malloc (MAX_INPUT_BUFFER); 137 input_buffer = malloc (MAX_INPUT_BUFFER);
138 procprog = malloc (MAX_INPUT_BUFFER); 138 procprog = malloc (MAX_INPUT_BUFFER);
139 139
140 asprintf (&metric_name, "PROCS"); 140 xasprintf (&metric_name, "PROCS");
141 metric = METRIC_PROCS; 141 metric = METRIC_PROCS;
142 142
143 /* Parse extra opts if any */ 143 /* Parse extra opts if any */
@@ -176,7 +176,7 @@ main (int argc, char **argv)
176 printf ("%s", input_line); 176 printf ("%s", input_line);
177 177
178 strcpy (procprog, ""); 178 strcpy (procprog, "");
179 asprintf (&procargs, "%s", ""); 179 xasprintf (&procargs, "%s", "");
180 180
181 cols = sscanf (input_line, PS_FORMAT, PS_VARLIST); 181 cols = sscanf (input_line, PS_FORMAT, PS_VARLIST);
182 182
@@ -186,7 +186,7 @@ main (int argc, char **argv)
186 } 186 }
187 if ( cols >= expected_cols ) { 187 if ( cols >= expected_cols ) {
188 resultsum = 0; 188 resultsum = 0;
189 asprintf (&procargs, "%s", input_line + pos); 189 xasprintf (&procargs, "%s", input_line + pos);
190 strip (procargs); 190 strip (procargs);
191 191
192 /* Some ps return full pathname for command. This removes path */ 192 /* Some ps return full pathname for command. This removes path */
@@ -250,12 +250,12 @@ main (int argc, char **argv)
250 if (metric != METRIC_PROCS) { 250 if (metric != METRIC_PROCS) {
251 if (i == STATE_WARNING) { 251 if (i == STATE_WARNING) {
252 warn++; 252 warn++;
253 asprintf (&fails, "%s%s%s", fails, (strcmp(fails,"") ? ", " : ""), procprog); 253 xasprintf (&fails, "%s%s%s", fails, (strcmp(fails,"") ? ", " : ""), procprog);
254 result = max_state (result, i); 254 result = max_state (result, i);
255 } 255 }
256 if (i == STATE_CRITICAL) { 256 if (i == STATE_CRITICAL) {
257 crit++; 257 crit++;
258 asprintf (&fails, "%s%s%s", fails, (strcmp(fails,"") ? ", " : ""), procprog); 258 xasprintf (&fails, "%s%s%s", fails, (strcmp(fails,"") ? ", " : ""), procprog);
259 result = max_state (result, i); 259 result = max_state (result, i);
260 } 260 }
261 } 261 }
@@ -393,7 +393,7 @@ process_arguments (int argc, char **argv)
393 break; 393 break;
394 case 'p': /* process id */ 394 case 'p': /* process id */
395 if (sscanf (optarg, "%d%[^0-9]", &ppid, tmp) == 1) { 395 if (sscanf (optarg, "%d%[^0-9]", &ppid, tmp) == 1) {
396 asprintf (&fmt, "%s%sPPID = %d", (fmt ? fmt : "") , (options ? ", " : ""), ppid); 396 xasprintf (&fmt, "%s%sPPID = %d", (fmt ? fmt : "") , (options ? ", " : ""), ppid);
397 options |= PPID; 397 options |= PPID;
398 break; 398 break;
399 } 399 }
@@ -403,7 +403,7 @@ process_arguments (int argc, char **argv)
403 break; 403 break;
404 else 404 else
405 statopts = optarg; 405 statopts = optarg;
406 asprintf (&fmt, _("%s%sSTATE = %s"), (fmt ? fmt : ""), (options ? ", " : ""), statopts); 406 xasprintf (&fmt, _("%s%sSTATE = %s"), (fmt ? fmt : ""), (options ? ", " : ""), statopts);
407 options |= STAT; 407 options |= STAT;
408 break; 408 break;
409 case 'u': /* user or user id */ 409 case 'u': /* user or user id */
@@ -423,7 +423,7 @@ process_arguments (int argc, char **argv)
423 uid = pw->pw_uid; 423 uid = pw->pw_uid;
424 } 424 }
425 user = pw->pw_name; 425 user = pw->pw_name;
426 asprintf (&fmt, "%s%sUID = %d (%s)", (fmt ? fmt : ""), (options ? ", " : ""), 426 xasprintf (&fmt, "%s%sUID = %d (%s)", (fmt ? fmt : ""), (options ? ", " : ""),
427 uid, user); 427 uid, user);
428 options |= USER; 428 options |= USER;
429 break; 429 break;
@@ -433,7 +433,7 @@ process_arguments (int argc, char **argv)
433 break; 433 break;
434 else 434 else
435 prog = optarg; 435 prog = optarg;
436 asprintf (&fmt, _("%s%scommand name '%s'"), (fmt ? fmt : ""), (options ? ", " : ""), 436 xasprintf (&fmt, _("%s%scommand name '%s'"), (fmt ? fmt : ""), (options ? ", " : ""),
437 prog); 437 prog);
438 options |= PROG; 438 options |= PROG;
439 break; 439 break;
@@ -443,7 +443,7 @@ process_arguments (int argc, char **argv)
443 break; 443 break;
444 else 444 else
445 args = optarg; 445 args = optarg;
446 asprintf (&fmt, "%s%sargs '%s'", (fmt ? fmt : ""), (options ? ", " : ""), args); 446 xasprintf (&fmt, "%s%sargs '%s'", (fmt ? fmt : ""), (options ? ", " : ""), args);
447 options |= ARGS; 447 options |= ARGS;
448 break; 448 break;
449 case CHAR_MAX+1: 449 case CHAR_MAX+1:
@@ -459,19 +459,19 @@ process_arguments (int argc, char **argv)
459 temp_string[i]=','; 459 temp_string[i]=',';
460 i++; 460 i++;
461 } 461 }
462 asprintf (&fmt, "%s%sregex args '%s'", (fmt ? fmt : ""), (options ? ", " : ""), temp_string); 462 xasprintf (&fmt, "%s%sregex args '%s'", (fmt ? fmt : ""), (options ? ", " : ""), temp_string);
463 options |= EREG_ARGS; 463 options |= EREG_ARGS;
464 break; 464 break;
465 case 'r': /* RSS */ 465 case 'r': /* RSS */
466 if (sscanf (optarg, "%d%[^0-9]", &rss, tmp) == 1) { 466 if (sscanf (optarg, "%d%[^0-9]", &rss, tmp) == 1) {
467 asprintf (&fmt, "%s%sRSS >= %d", (fmt ? fmt : ""), (options ? ", " : ""), rss); 467 xasprintf (&fmt, "%s%sRSS >= %d", (fmt ? fmt : ""), (options ? ", " : ""), rss);
468 options |= RSS; 468 options |= RSS;
469 break; 469 break;
470 } 470 }
471 usage4 (_("RSS must be an integer!")); 471 usage4 (_("RSS must be an integer!"));
472 case 'z': /* VSZ */ 472 case 'z': /* VSZ */
473 if (sscanf (optarg, "%d%[^0-9]", &vsz, tmp) == 1) { 473 if (sscanf (optarg, "%d%[^0-9]", &vsz, tmp) == 1) {
474 asprintf (&fmt, "%s%sVSZ >= %d", (fmt ? fmt : ""), (options ? ", " : ""), vsz); 474 xasprintf (&fmt, "%s%sVSZ >= %d", (fmt ? fmt : ""), (options ? ", " : ""), vsz);
475 options |= VSZ; 475 options |= VSZ;
476 break; 476 break;
477 } 477 }
@@ -479,13 +479,13 @@ process_arguments (int argc, char **argv)
479 case 'P': /* PCPU */ 479 case 'P': /* PCPU */
480 /* TODO: -P 1.5.5 is accepted */ 480 /* TODO: -P 1.5.5 is accepted */
481 if (sscanf (optarg, "%f%[^0-9.]", &pcpu, tmp) == 1) { 481 if (sscanf (optarg, "%f%[^0-9.]", &pcpu, tmp) == 1) {
482 asprintf (&fmt, "%s%sPCPU >= %.2f", (fmt ? fmt : ""), (options ? ", " : ""), pcpu); 482 xasprintf (&fmt, "%s%sPCPU >= %.2f", (fmt ? fmt : ""), (options ? ", " : ""), pcpu);
483 options |= PCPU; 483 options |= PCPU;
484 break; 484 break;
485 } 485 }
486 usage4 (_("PCPU must be a float!")); 486 usage4 (_("PCPU must be a float!"));
487 case 'm': 487 case 'm':
488 asprintf (&metric_name, "%s", optarg); 488 xasprintf (&metric_name, "%s", optarg);
489 if ( strcmp(optarg, "PROCS") == 0) { 489 if ( strcmp(optarg, "PROCS") == 0) {
490 metric = METRIC_PROCS; 490 metric = METRIC_PROCS;
491 break; 491 break;
@@ -523,8 +523,8 @@ process_arguments (int argc, char **argv)
523 if (cmax == -1 && argv[c]) 523 if (cmax == -1 && argv[c])
524 cmax = atoi (argv[c++]); 524 cmax = atoi (argv[c++]);
525 if (statopts == NULL && argv[c]) { 525 if (statopts == NULL && argv[c]) {
526 asprintf (&statopts, "%s", argv[c++]); 526 xasprintf (&statopts, "%s", argv[c++]);
527 asprintf (&fmt, _("%s%sSTATE = %s"), (fmt ? fmt : ""), (options ? ", " : ""), statopts); 527 xasprintf (&fmt, _("%s%sSTATE = %s"), (fmt ? fmt : ""), (options ? ", " : ""), statopts);
528 options |= STAT; 528 options |= STAT;
529 } 529 }
530 530
diff --git a/plugins/check_radius.c b/plugins/check_radius.c
index c2c93ee..e54105b 100644
--- a/plugins/check_radius.c
+++ b/plugins/check_radius.c
@@ -328,7 +328,7 @@ void
328print_help (void) 328print_help (void)
329{ 329{
330 char *myport; 330 char *myport;
331 asprintf (&myport, "%d", PW_AUTH_UDP_PORT); 331 xasprintf (&myport, "%d", PW_AUTH_UDP_PORT);
332 332
333 print_revision (progname, NP_VERSION); 333 print_revision (progname, NP_VERSION);
334 334
diff --git a/plugins/check_real.c b/plugins/check_real.c
index d67e190..18240f3 100644
--- a/plugins/check_real.c
+++ b/plugins/check_real.c
@@ -403,7 +403,7 @@ void
403print_help (void) 403print_help (void)
404{ 404{
405 char *myport; 405 char *myport;
406 asprintf (&myport, "%d", PORT); 406 xasprintf (&myport, "%d", PORT);
407 407
408 print_revision (progname, NP_VERSION); 408 print_revision (progname, NP_VERSION);
409 409
diff --git a/plugins/check_smtp.c b/plugins/check_smtp.c
index 494bc2c..a861a71 100644
--- a/plugins/check_smtp.c
+++ b/plugins/check_smtp.c
@@ -41,7 +41,7 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net";
41 41
42#ifdef HAVE_SSL 42#ifdef HAVE_SSL
43int check_cert = FALSE; 43int check_cert = FALSE;
44int days_till_exp; 44int days_till_exp_warn, days_till_exp_crit;
45# define my_recv(buf, len) ((use_ssl && ssl_established) ? np_net_ssl_read(buf, len) : read(sd, buf, len)) 45# define my_recv(buf, len) ((use_ssl && ssl_established) ? np_net_ssl_read(buf, len) : read(sd, buf, len))
46# define my_send(buf, len) ((use_ssl && ssl_established) ? np_net_ssl_write(buf, len) : send(sd, buf, len, 0)) 46# define my_send(buf, len) ((use_ssl && ssl_established) ? np_net_ssl_write(buf, len) : send(sd, buf, len, 0))
47#else /* ifndef HAVE_SSL */ 47#else /* ifndef HAVE_SSL */
@@ -87,9 +87,9 @@ int errcode, excode;
87int server_port = SMTP_PORT; 87int server_port = SMTP_PORT;
88char *server_address = NULL; 88char *server_address = NULL;
89char *server_expect = NULL; 89char *server_expect = NULL;
90int smtp_use_dummycmd = 0;
91char *mail_command = NULL; 90char *mail_command = NULL;
92char *from_arg = NULL; 91char *from_arg = NULL;
92int send_mail_from=0;
93int ncommands=0; 93int ncommands=0;
94int command_size=0; 94int command_size=0;
95int nresponses=0; 95int nresponses=0;
@@ -156,17 +156,17 @@ main (int argc, char **argv)
156 } 156 }
157 } 157 }
158 if(use_ehlo) 158 if(use_ehlo)
159 asprintf (&helocmd, "%s%s%s", SMTP_EHLO, localhostname, "\r\n"); 159 xasprintf (&helocmd, "%s%s%s", SMTP_EHLO, localhostname, "\r\n");
160 else 160 else
161 asprintf (&helocmd, "%s%s%s", SMTP_HELO, localhostname, "\r\n"); 161 xasprintf (&helocmd, "%s%s%s", SMTP_HELO, localhostname, "\r\n");
162 162
163 if (verbose) 163 if (verbose)
164 printf("HELOCMD: %s", helocmd); 164 printf("HELOCMD: %s", helocmd);
165 165
166 /* initialize the MAIL command with optional FROM command */ 166 /* initialize the MAIL command with optional FROM command */
167 asprintf (&cmd_str, "%sFROM: %s%s", mail_command, from_arg, "\r\n"); 167 xasprintf (&cmd_str, "%sFROM:<%s>%s", mail_command, from_arg, "\r\n");
168 168
169 if (verbose && smtp_use_dummycmd) 169 if (verbose && send_mail_from)
170 printf ("FROM CMD: %s", cmd_str); 170 printf ("FROM CMD: %s", cmd_str);
171 171
172 /* initialize alarm signal handling */ 172 /* initialize alarm signal handling */
@@ -275,7 +275,7 @@ main (int argc, char **argv)
275 275
276# ifdef USE_OPENSSL 276# ifdef USE_OPENSSL
277 if ( check_cert ) { 277 if ( check_cert ) {
278 result = np_net_ssl_check_cert(days_till_exp); 278 result = np_net_ssl_check_cert(days_till_exp_warn, days_till_exp_crit);
279 my_close(); 279 my_close();
280 return result; 280 return result;
281 } 281 }
@@ -283,23 +283,14 @@ main (int argc, char **argv)
283 } 283 }
284#endif 284#endif
285 285
286 /* sendmail will syslog a "NOQUEUE" error if session does not attempt 286 if (send_mail_from) {
287 * to do something useful. This can be prevented by giving a command
288 * even if syntax is illegal (MAIL requires a FROM:<...> argument)
289 *
290 * According to rfc821 you can include a null reversepath in the from command
291 * - but a log message is generated on the smtp server.
292 *
293 * Use the -f option to provide a FROM address
294 */
295 if (smtp_use_dummycmd) {
296 my_send(cmd_str, strlen(cmd_str)); 287 my_send(cmd_str, strlen(cmd_str));
297 if (recvlines(buffer, MAX_INPUT_BUFFER) >= 1 && verbose) 288 if (recvlines(buffer, MAX_INPUT_BUFFER) >= 1 && verbose)
298 printf("%s", buffer); 289 printf("%s", buffer);
299 } 290 }
300 291
301 while (n < ncommands) { 292 while (n < ncommands) {
302 asprintf (&cmd_str, "%s%s", commands[n], "\r\n"); 293 xasprintf (&cmd_str, "%s%s", commands[n], "\r\n");
303 my_send(cmd_str, strlen(cmd_str)); 294 my_send(cmd_str, strlen(cmd_str));
304 if (recvlines(buffer, MAX_INPUT_BUFFER) >= 1 && verbose) 295 if (recvlines(buffer, MAX_INPUT_BUFFER) >= 1 && verbose)
305 printf("%s", buffer); 296 printf("%s", buffer);
@@ -336,12 +327,12 @@ main (int argc, char **argv)
336 do { 327 do {
337 if (authuser == NULL) { 328 if (authuser == NULL) {
338 result = STATE_CRITICAL; 329 result = STATE_CRITICAL;
339 asprintf(&error_msg, _("no authuser specified, ")); 330 xasprintf(&error_msg, _("no authuser specified, "));
340 break; 331 break;
341 } 332 }
342 if (authpass == NULL) { 333 if (authpass == NULL) {
343 result = STATE_CRITICAL; 334 result = STATE_CRITICAL;
344 asprintf(&error_msg, _("no authpass specified, ")); 335 xasprintf(&error_msg, _("no authpass specified, "));
345 break; 336 break;
346 } 337 }
347 338
@@ -351,7 +342,7 @@ main (int argc, char **argv)
351 printf (_("sent %s\n"), "AUTH LOGIN"); 342 printf (_("sent %s\n"), "AUTH LOGIN");
352 343
353 if ((ret = recvlines(buffer, MAX_INPUT_BUFFER)) <= 0) { 344 if ((ret = recvlines(buffer, MAX_INPUT_BUFFER)) <= 0) {
354 asprintf(&error_msg, _("recv() failed after AUTH LOGIN, ")); 345 xasprintf(&error_msg, _("recv() failed after AUTH LOGIN, "));
355 result = STATE_WARNING; 346 result = STATE_WARNING;
356 break; 347 break;
357 } 348 }
@@ -360,21 +351,20 @@ main (int argc, char **argv)
360 351
361 if (strncmp (buffer, "334", 3) != 0) { 352 if (strncmp (buffer, "334", 3) != 0) {
362 result = STATE_CRITICAL; 353 result = STATE_CRITICAL;
363 asprintf(&error_msg, _("invalid response received after AUTH LOGIN, ")); 354 xasprintf(&error_msg, _("invalid response received after AUTH LOGIN, "));
364 break; 355 break;
365 } 356 }
366 357
367 /* encode authuser with base64 */ 358 /* encode authuser with base64 */
368 base64_encode_alloc (authuser, strlen(authuser), &abuf); 359 base64_encode_alloc (authuser, strlen(authuser), &abuf);
369 /* FIXME: abuf shouldn't have enough space to strcat a '\r\n' into it. */ 360 xasprintf(&abuf, "%s\r\n", abuf);
370 strcat (abuf, "\r\n");
371 my_send(abuf, strlen(abuf)); 361 my_send(abuf, strlen(abuf));
372 if (verbose) 362 if (verbose)
373 printf (_("sent %s\n"), abuf); 363 printf (_("sent %s\n"), abuf);
374 364
375 if ((ret = recvlines(buffer, MAX_INPUT_BUFFER)) <= 0) { 365 if ((ret = recvlines(buffer, MAX_INPUT_BUFFER)) <= 0) {
376 result = STATE_CRITICAL; 366 result = STATE_CRITICAL;
377 asprintf(&error_msg, _("recv() failed after sending authuser, ")); 367 xasprintf(&error_msg, _("recv() failed after sending authuser, "));
378 break; 368 break;
379 } 369 }
380 if (verbose) { 370 if (verbose) {
@@ -382,20 +372,19 @@ main (int argc, char **argv)
382 } 372 }
383 if (strncmp (buffer, "334", 3) != 0) { 373 if (strncmp (buffer, "334", 3) != 0) {
384 result = STATE_CRITICAL; 374 result = STATE_CRITICAL;
385 asprintf(&error_msg, _("invalid response received after authuser, ")); 375 xasprintf(&error_msg, _("invalid response received after authuser, "));
386 break; 376 break;
387 } 377 }
388 /* encode authpass with base64 */ 378 /* encode authpass with base64 */
389 base64_encode_alloc (authpass, strlen(authpass), &abuf); 379 base64_encode_alloc (authpass, strlen(authpass), &abuf);
390 /* FIXME: abuf shouldn't have enough space to strcat a '\r\n' into it. */ 380 xasprintf(&abuf, "%s\r\n", abuf);
391 strcat (abuf, "\r\n");
392 my_send(abuf, strlen(abuf)); 381 my_send(abuf, strlen(abuf));
393 if (verbose) { 382 if (verbose) {
394 printf (_("sent %s\n"), abuf); 383 printf (_("sent %s\n"), abuf);
395 } 384 }
396 if ((ret = recvlines(buffer, MAX_INPUT_BUFFER)) <= 0) { 385 if ((ret = recvlines(buffer, MAX_INPUT_BUFFER)) <= 0) {
397 result = STATE_CRITICAL; 386 result = STATE_CRITICAL;
398 asprintf(&error_msg, _("recv() failed after sending authpass, ")); 387 xasprintf(&error_msg, _("recv() failed after sending authpass, "));
399 break; 388 break;
400 } 389 }
401 if (verbose) { 390 if (verbose) {
@@ -403,14 +392,14 @@ main (int argc, char **argv)
403 } 392 }
404 if (strncmp (buffer, "235", 3) != 0) { 393 if (strncmp (buffer, "235", 3) != 0) {
405 result = STATE_CRITICAL; 394 result = STATE_CRITICAL;
406 asprintf(&error_msg, _("invalid response received after authpass, ")); 395 xasprintf(&error_msg, _("invalid response received after authpass, "));
407 break; 396 break;
408 } 397 }
409 break; 398 break;
410 } while (0); 399 } while (0);
411 } else { 400 } else {
412 result = STATE_CRITICAL; 401 result = STATE_CRITICAL;
413 asprintf(&error_msg, _("only authtype LOGIN is supported, ")); 402 xasprintf(&error_msg, _("only authtype LOGIN is supported, "));
414 } 403 }
415 } 404 }
416 405
@@ -454,6 +443,7 @@ int
454process_arguments (int argc, char **argv) 443process_arguments (int argc, char **argv)
455{ 444{
456 int c; 445 int c;
446 char* temp;
457 447
458 int option = 0; 448 int option = 0;
459 static struct option longopts[] = { 449 static struct option longopts[] = {
@@ -520,8 +510,9 @@ process_arguments (int argc, char **argv)
520 localhostname = strdup(optarg); 510 localhostname = strdup(optarg);
521 break; 511 break;
522 case 'f': /* from argument */ 512 case 'f': /* from argument */
523 from_arg = optarg; 513 from_arg = optarg + strspn(optarg, "<");
524 smtp_use_dummycmd = 1; 514 from_arg = strndup(from_arg, strcspn(from_arg, ">"));
515 send_mail_from = 1;
525 break; 516 break;
526 case 'A': 517 case 'A':
527 authtype = optarg; 518 authtype = optarg;
@@ -600,12 +591,26 @@ process_arguments (int argc, char **argv)
600 case 'D': 591 case 'D':
601 /* Check SSL cert validity */ 592 /* Check SSL cert validity */
602#ifdef USE_OPENSSL 593#ifdef USE_OPENSSL
603 if (!is_intnonneg (optarg)) 594 if ((temp=strchr(optarg,','))!=NULL) {
604 usage2 ("Invalid certificate expiration period",optarg); 595 *temp='\0';
605 days_till_exp = atoi (optarg); 596 if (!is_intnonneg (temp))
606 check_cert = TRUE; 597 usage2 ("Invalid certificate expiration period", optarg);
598 days_till_exp_warn = atoi(optarg);
599 *temp=',';
600 temp++;
601 if (!is_intnonneg (temp))
602 usage2 (_("Invalid certificate expiration period"), temp);
603 days_till_exp_crit = atoi (temp);
604 }
605 else {
606 days_till_exp_crit=0;
607 if (!is_intnonneg (optarg))
608 usage2 ("Invalid certificate expiration period", optarg);
609 days_till_exp_warn = atoi (optarg);
610 }
611 check_cert = TRUE;
607#else 612#else
608 usage (_("SSL support not available - install OpenSSL and recompile")); 613 usage (_("SSL support not available - install OpenSSL and recompile"));
609#endif 614#endif
610 break; 615 break;
611 case '4': 616 case '4':
@@ -638,7 +643,7 @@ process_arguments (int argc, char **argv)
638 usage2 (_("Invalid hostname/address"), argv[c]); 643 usage2 (_("Invalid hostname/address"), argv[c]);
639 } 644 }
640 else { 645 else {
641 asprintf (&server_address, "127.0.0.1"); 646 xasprintf (&server_address, "127.0.0.1");
642 } 647 }
643 } 648 }
644 649
@@ -771,7 +776,7 @@ void
771print_help (void) 776print_help (void)
772{ 777{
773 char *myport; 778 char *myport;
774 asprintf (&myport, "%d", SMTP_PORT); 779 xasprintf (&myport, "%d", SMTP_PORT);
775 780
776 print_revision (progname, NP_VERSION); 781 print_revision (progname, NP_VERSION);
777 782
@@ -795,14 +800,14 @@ print_help (void)
795 printf (_(" String to expect in first line of server response (default: '%s')\n"), SMTP_EXPECT); 800 printf (_(" String to expect in first line of server response (default: '%s')\n"), SMTP_EXPECT);
796 printf (" %s\n", "-C, --command=STRING"); 801 printf (" %s\n", "-C, --command=STRING");
797 printf (" %s\n", _("SMTP command (may be used repeatedly)")); 802 printf (" %s\n", _("SMTP command (may be used repeatedly)"));
798 printf (" %s\n", "-R, --command=STRING"); 803 printf (" %s\n", "-R, --response=STRING");
799 printf (" %s\n", _("Expected response to command (may be used repeatedly)")); 804 printf (" %s\n", _("Expected response to command (may be used repeatedly)"));
800 printf (" %s\n", "-f, --from=STRING"); 805 printf (" %s\n", "-f, --from=STRING");
801 printf (" %s\n", _("FROM-address to include in MAIL command, required by Exchange 2000")), 806 printf (" %s\n", _("FROM-address to include in MAIL command, required by Exchange 2000")),
802 printf (" %s\n", "-F, --fqdn=STRING"); 807 printf (" %s\n", "-F, --fqdn=STRING");
803 printf (" %s\n", _("FQDN used for HELO")); 808 printf (" %s\n", _("FQDN used for HELO"));
804#ifdef HAVE_SSL 809#ifdef HAVE_SSL
805 printf (" %s\n", "-D, --certificate=INTEGER"); 810 printf (" %s\n", "-D, --certificate=INTEGER[,INTEGER]");
806 printf (" %s\n", _("Minimum number of days a certificate has to be valid.")); 811 printf (" %s\n", _("Minimum number of days a certificate has to be valid."));
807 printf (" %s\n", "-S, --starttls"); 812 printf (" %s\n", "-S, --starttls");
808 printf (" %s\n", _("Use STARTTLS for the connection.")); 813 printf (" %s\n", _("Use STARTTLS for the connection."));
@@ -838,8 +843,8 @@ void
838print_usage (void) 843print_usage (void)
839{ 844{
840 printf ("%s\n", _("Usage:")); 845 printf ("%s\n", _("Usage:"));
841 printf ("%s -H host [-p port] [-e expect] [-C command] [-f from addr]", progname); 846 printf ("%s -H host [-p port] [-4|-6] [-e expect] [-C command] [-R response] [-f from addr]\n", progname);
842 printf ("[-A authtype -U authuser -P authpass] [-w warn] [-c crit] [-t timeout]\n"); 847 printf ("[-A authtype -U authuser -P authpass] [-w warn] [-c crit] [-t timeout] [-q]\n");
843 printf ("[-F fqdn] [-S] [-D days] [-v] [-4|-6] [-q]\n"); 848 printf ("[-F fqdn] [-S] [-D warn days cert expire[,crit days cert expire]] [-v] \n");
844} 849}
845 850
diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c
index 4cd3805..2d9861b 100644
--- a/plugins/check_snmp.c
+++ b/plugins/check_snmp.c
@@ -141,6 +141,7 @@ int calculate_rate = 0;
141int rate_multiplier = 1; 141int rate_multiplier = 1;
142state_data *previous_state; 142state_data *previous_state;
143double previous_value[MAX_OIDS]; 143double previous_value[MAX_OIDS];
144int perf_labels = 1;
144 145
145 146
146int 147int
@@ -169,6 +170,7 @@ main (int argc, char **argv)
169 char *state_string=NULL; 170 char *state_string=NULL;
170 size_t response_length, current_length, string_length; 171 size_t response_length, current_length, string_length;
171 char *temp_string=NULL; 172 char *temp_string=NULL;
173 char *quote_string=NULL;
172 time_t current_time; 174 time_t current_time;
173 double temp_double; 175 double temp_double;
174 time_t duration; 176 time_t duration;
@@ -253,9 +255,9 @@ main (int argc, char **argv)
253 command_line = calloc (9 + numauthpriv + 1 + numoids + 1, sizeof (char *)); 255 command_line = calloc (9 + numauthpriv + 1 + numoids + 1, sizeof (char *));
254 command_line[0] = snmpcmd; 256 command_line[0] = snmpcmd;
255 command_line[1] = strdup ("-t"); 257 command_line[1] = strdup ("-t");
256 asprintf (&command_line[2], "%d", timeout_interval); 258 xasprintf (&command_line[2], "%d", timeout_interval);
257 command_line[3] = strdup ("-r"); 259 command_line[3] = strdup ("-r");
258 asprintf (&command_line[4], "%d", retries); 260 xasprintf (&command_line[4], "%d", retries);
259 command_line[5] = strdup ("-m"); 261 command_line[5] = strdup ("-m");
260 command_line[6] = strdup (miblist); 262 command_line[6] = strdup (miblist);
261 command_line[7] = "-v"; 263 command_line[7] = "-v";
@@ -265,16 +267,16 @@ main (int argc, char **argv)
265 command_line[9 + i] = authpriv[i]; 267 command_line[9 + i] = authpriv[i];
266 } 268 }
267 269
268 asprintf (&command_line[9 + numauthpriv], "%s:%s", server_address, port); 270 xasprintf (&command_line[9 + numauthpriv], "%s:%s", server_address, port);
269 271
270 /* This is just for display purposes, so it can remain a string */ 272 /* This is just for display purposes, so it can remain a string */
271 asprintf(&cl_hidden_auth, "%s -t %d -r %d -m %s -v %s %s %s:%s", 273 xasprintf(&cl_hidden_auth, "%s -t %d -r %d -m %s -v %s %s %s:%s",
272 snmpcmd, timeout_interval, retries, strlen(miblist) ? miblist : "''", proto, "[authpriv]", 274 snmpcmd, timeout_interval, retries, strlen(miblist) ? miblist : "''", proto, "[authpriv]",
273 server_address, port); 275 server_address, port);
274 276
275 for (i = 0; i < numoids; i++) { 277 for (i = 0; i < numoids; i++) {
276 command_line[9 + numauthpriv + 1 + i] = oids[i]; 278 command_line[9 + numauthpriv + 1 + i] = oids[i];
277 asprintf(&cl_hidden_auth, "%s %s", cl_hidden_auth, oids[i]); 279 xasprintf(&cl_hidden_auth, "%s %s", cl_hidden_auth, oids[i]);
278 } 280 }
279 281
280 command_line[9 + numauthpriv + 1 + numoids] = NULL; 282 command_line[9 + numauthpriv + 1 + numoids] = NULL;
@@ -369,14 +371,14 @@ main (int argc, char **argv)
369 if (dq_count) { /* unfinished line */ 371 if (dq_count) { /* unfinished line */
370 /* copy show verbatim first */ 372 /* copy show verbatim first */
371 if (!mult_resp) mult_resp = strdup(""); 373 if (!mult_resp) mult_resp = strdup("");
372 asprintf (&mult_resp, "%s%s:\n%s\n", mult_resp, oids[i], show); 374 xasprintf (&mult_resp, "%s%s:\n%s\n", mult_resp, oids[i], show);
373 /* then strip out unmatched double-quote from single-line output */ 375 /* then strip out unmatched double-quote from single-line output */
374 if (show[0] == '"') show++; 376 if (show[0] == '"') show++;
375 377
376 /* Keep reading until we match end of double-quoted string */ 378 /* Keep reading until we match end of double-quoted string */
377 for (line++; line < chld_out.lines; line++) { 379 for (line++; line < chld_out.lines; line++) {
378 ptr = chld_out.line[line]; 380 ptr = chld_out.line[line];
379 asprintf (&mult_resp, "%s%s\n", mult_resp, ptr); 381 xasprintf (&mult_resp, "%s%s\n", mult_resp, ptr);
380 382
381 COUNT_SEQ(ptr, bk_count, dq_count) 383 COUNT_SEQ(ptr, bk_count, dq_count)
382 while (dq_count && ptr[0] != '\n' && ptr[0] != '\0') { 384 while (dq_count && ptr[0] != '\n' && ptr[0] != '\0') {
@@ -422,11 +424,11 @@ main (int argc, char **argv)
422 /* Convert to per second, then use multiplier */ 424 /* Convert to per second, then use multiplier */
423 temp_double = temp_double/duration*rate_multiplier; 425 temp_double = temp_double/duration*rate_multiplier;
424 iresult = get_status(temp_double, thlds[i]); 426 iresult = get_status(temp_double, thlds[i]);
425 asprintf (&show, conv, temp_double); 427 xasprintf (&show, conv, temp_double);
426 } 428 }
427 } else { 429 } else {
428 iresult = get_status(response_value[i], thlds[i]); 430 iresult = get_status(response_value[i], thlds[i]);
429 asprintf (&show, conv, response_value[i]); 431 xasprintf (&show, conv, response_value[i]);
430 } 432 }
431 } 433 }
432 434
@@ -470,26 +472,37 @@ main (int argc, char **argv)
470 472
471 /* Prepend a label for this OID if there is one */ 473 /* Prepend a label for this OID if there is one */
472 if (nlabels >= (size_t)1 && (size_t)i < nlabels && labels[i] != NULL) 474 if (nlabels >= (size_t)1 && (size_t)i < nlabels && labels[i] != NULL)
473 asprintf (&outbuff, "%s%s%s %s%s%s", outbuff, 475 xasprintf (&outbuff, "%s%s%s %s%s%s", outbuff,
474 (i == 0) ? " " : output_delim, 476 (i == 0) ? " " : output_delim,
475 labels[i], mark (iresult), show, mark (iresult)); 477 labels[i], mark (iresult), show, mark (iresult));
476 else 478 else
477 asprintf (&outbuff, "%s%s%s%s%s", outbuff, (i == 0) ? " " : output_delim, 479 xasprintf (&outbuff, "%s%s%s%s%s", outbuff, (i == 0) ? " " : output_delim,
478 mark (iresult), show, mark (iresult)); 480 mark (iresult), show, mark (iresult));
479 481
480 /* Append a unit string for this OID if there is one */ 482 /* Append a unit string for this OID if there is one */
481 if (nunits > (size_t)0 && (size_t)i < nunits && unitv[i] != NULL) 483 if (nunits > (size_t)0 && (size_t)i < nunits && unitv[i] != NULL)
482 asprintf (&outbuff, "%s %s", outbuff, unitv[i]); 484 xasprintf (&outbuff, "%s %s", outbuff, unitv[i]);
483 485
484 /* Write perfdata with whatever can be parsed by strtod, if possible */ 486 /* Write perfdata with whatever can be parsed by strtod, if possible */
485 ptr = NULL; 487 ptr = NULL;
486 strtod(show, &ptr); 488 strtod(show, &ptr);
487 if (ptr > show) { 489 if (ptr > show) {
488 if (nlabels >= (size_t)1 && (size_t)i < nlabels && labels[i] != NULL) 490 if (perf_labels && nlabels >= (size_t)1 && (size_t)i < nlabels && labels[i] != NULL)
489 temp_string=labels[i]; 491 temp_string=labels[i];
490 else 492 else
491 temp_string=oidname; 493 temp_string=oidname;
492 strncat(perfstr, temp_string, sizeof(perfstr)-strlen(perfstr)-1); 494 if (strpbrk (temp_string, " ='\"") == NULL) {
495 strncat(perfstr, temp_string, sizeof(perfstr)-strlen(perfstr)-1);
496 } else {
497 if (strpbrk (temp_string, "'") == NULL) {
498 quote_string="'";
499 } else {
500 quote_string="\"";
501 }
502 strncat(perfstr, quote_string, sizeof(perfstr)-strlen(perfstr)-1);
503 strncat(perfstr, temp_string, sizeof(perfstr)-strlen(perfstr)-1);
504 strncat(perfstr, quote_string, sizeof(perfstr)-strlen(perfstr)-1);
505 }
493 strncat(perfstr, "=", sizeof(perfstr)-strlen(perfstr)-1); 506 strncat(perfstr, "=", sizeof(perfstr)-strlen(perfstr)-1);
494 len = sizeof(perfstr)-strlen(perfstr)-1; 507 len = sizeof(perfstr)-strlen(perfstr)-1;
495 strncat(perfstr, show, len>ptr-show ? ptr-show : len); 508 strncat(perfstr, show, len>ptr-show ? ptr-show : len);
@@ -510,7 +523,7 @@ main (int argc, char **argv)
510 523
511 current_length=0; 524 current_length=0;
512 for(i=0; i<total_oids; i++) { 525 for(i=0; i<total_oids; i++) {
513 asprintf(&temp_string,"%.0f",response_value[i]); 526 xasprintf(&temp_string,"%.0f",response_value[i]);
514 if(temp_string==NULL) 527 if(temp_string==NULL)
515 die(STATE_UNKNOWN,_("Cannot asprintf()")); 528 die(STATE_UNKNOWN,_("Cannot asprintf()"));
516 response_length = strlen(temp_string); 529 response_length = strlen(temp_string);
@@ -583,6 +596,7 @@ process_arguments (int argc, char **argv)
583 {"rate", no_argument, 0, L_CALCULATE_RATE}, 596 {"rate", no_argument, 0, L_CALCULATE_RATE},
584 {"rate-multiplier", required_argument, 0, L_RATE_MULTIPLIER}, 597 {"rate-multiplier", required_argument, 0, L_RATE_MULTIPLIER},
585 {"invert-search", no_argument, 0, L_INVERT_SEARCH}, 598 {"invert-search", no_argument, 0, L_INVERT_SEARCH},
599 {"perf-oids", no_argument, 0, 'O'},
586 {0, 0, 0, 0} 600 {0, 0, 0, 0}
587 }; 601 };
588 602
@@ -600,7 +614,7 @@ process_arguments (int argc, char **argv)
600 } 614 }
601 615
602 while (1) { 616 while (1) {
603 c = getopt_long (argc, argv, "nhvVt:c:w:H:C:o:e:E:d:D:s:t:R:r:l:u:p:m:P:L:U:a:x:A:X:", 617 c = getopt_long (argc, argv, "nhvVOt:c:w:H:C:o:e:E:d:D:s:t:R:r:l:u:p:m:P:L:U:a:x:A:X:",
604 longopts, &option); 618 longopts, &option);
605 619
606 if (c == -1 || c == EOF) 620 if (c == -1 || c == EOF)
@@ -798,6 +812,9 @@ process_arguments (int argc, char **argv)
798 case L_INVERT_SEARCH: 812 case L_INVERT_SEARCH:
799 invert_search=1; 813 invert_search=1;
800 break; 814 break;
815 case 'O':
816 perf_labels=0;
817 break;
801 } 818 }
802 } 819 }
803 820
@@ -852,7 +869,7 @@ validate_arguments ()
852 die(STATE_UNKNOWN, _("No OIDs specified\n")); 869 die(STATE_UNKNOWN, _("No OIDs specified\n"));
853 870
854 if (proto == NULL) 871 if (proto == NULL)
855 asprintf(&proto, DEFAULT_PROTOCOL); 872 xasprintf(&proto, DEFAULT_PROTOCOL);
856 873
857 if ((strcmp(proto,"1") == 0) || (strcmp(proto, "2c")==0)) { /* snmpv1 or snmpv2c */ 874 if ((strcmp(proto,"1") == 0) || (strcmp(proto, "2c")==0)) { /* snmpv1 or snmpv2c */
858 numauthpriv = 2; 875 numauthpriv = 2;
@@ -862,7 +879,7 @@ validate_arguments ()
862 } 879 }
863 else if ( strcmp (proto, "3") == 0 ) { /* snmpv3 args */ 880 else if ( strcmp (proto, "3") == 0 ) { /* snmpv3 args */
864 if (seclevel == NULL) 881 if (seclevel == NULL)
865 asprintf(&seclevel, "noAuthNoPriv"); 882 xasprintf(&seclevel, "noAuthNoPriv");
866 883
867 if (strcmp(seclevel, "noAuthNoPriv") == 0) { 884 if (strcmp(seclevel, "noAuthNoPriv") == 0) {
868 numauthpriv = 2; 885 numauthpriv = 2;
@@ -875,7 +892,7 @@ validate_arguments ()
875 } 892 }
876 893
877 if (authproto == NULL ) 894 if (authproto == NULL )
878 asprintf(&authproto, DEFAULT_AUTH_PROTOCOL); 895 xasprintf(&authproto, DEFAULT_AUTH_PROTOCOL);
879 896
880 if (secname == NULL) 897 if (secname == NULL)
881 die(STATE_UNKNOWN, _("Required parameter: %s\n"), "secname"); 898 die(STATE_UNKNOWN, _("Required parameter: %s\n"), "secname");
@@ -896,7 +913,7 @@ validate_arguments ()
896 authpriv[7] = strdup (authpasswd); 913 authpriv[7] = strdup (authpasswd);
897 } else if ( strcmp(seclevel, "authPriv") == 0 ) { 914 } else if ( strcmp(seclevel, "authPriv") == 0 ) {
898 if (privproto == NULL ) 915 if (privproto == NULL )
899 asprintf(&privproto, DEFAULT_PRIV_PROTOCOL); 916 xasprintf(&privproto, DEFAULT_PRIV_PROTOCOL);
900 917
901 if (privpasswd == NULL) 918 if (privpasswd == NULL)
902 die(STATE_UNKNOWN, _("Required parameter: %s\n"), "privpasswd"); 919 die(STATE_UNKNOWN, _("Required parameter: %s\n"), "privpasswd");
@@ -1063,6 +1080,9 @@ print_help (void)
1063 printf (" %s\n", "-e, --retries=INTEGER"); 1080 printf (" %s\n", "-e, --retries=INTEGER");
1064 printf (" %s\n", _("Number of retries to be used in the requests")); 1081 printf (" %s\n", _("Number of retries to be used in the requests"));
1065 1082
1083 printf (" %s\n", "-O, --perf-oids");
1084 printf (" %s\n", _("Label performance data with OIDs instead of --label's"));
1085
1066 printf (UT_VERBOSE); 1086 printf (UT_VERBOSE);
1067 1087
1068 printf ("\n"); 1088 printf ("\n");
diff --git a/plugins/check_ssh.c b/plugins/check_ssh.c
index 3bbf44d..4d63394 100644
--- a/plugins/check_ssh.c
+++ b/plugins/check_ssh.c
@@ -241,7 +241,7 @@ ssh_connect (char *haddr, int hport, char *remote_version)
241 ssh_server = ssh_proto + strspn (ssh_proto, "-0123456789. "); 241 ssh_server = ssh_proto + strspn (ssh_proto, "-0123456789. ");
242 ssh_proto[strspn (ssh_proto, "0123456789. ")] = 0; 242 ssh_proto[strspn (ssh_proto, "0123456789. ")] = 0;
243 243
244 asprintf (&buffer, "SSH-%s-check_ssh_%s\r\n", ssh_proto, rev_no); 244 xasprintf (&buffer, "SSH-%s-check_ssh_%s\r\n", ssh_proto, rev_no);
245 send (sd, buffer, strlen (buffer), MSG_DONTWAIT); 245 send (sd, buffer, strlen (buffer), MSG_DONTWAIT);
246 if (verbose) 246 if (verbose)
247 printf ("%s\n", buffer); 247 printf ("%s\n", buffer);
@@ -271,7 +271,7 @@ void
271print_help (void) 271print_help (void)
272{ 272{
273 char *myport; 273 char *myport;
274 asprintf (&myport, "%d", SSH_DFL_PORT); 274 xasprintf (&myport, "%d", SSH_DFL_PORT);
275 275
276 print_revision (progname, NP_VERSION); 276 print_revision (progname, NP_VERSION);
277 277
diff --git a/plugins/check_swap.c b/plugins/check_swap.c
index ce1f602..1b2a8dd 100644
--- a/plugins/check_swap.c
+++ b/plugins/check_swap.c
@@ -129,7 +129,7 @@ main (int argc, char **argv)
129 percent = 100 * (((double) dskused_mb) / ((double) dsktotal_mb)); 129 percent = 100 * (((double) dskused_mb) / ((double) dsktotal_mb));
130 result = max_state (result, check_swap (percent, dskfree_mb)); 130 result = max_state (result, check_swap (percent, dskfree_mb));
131 if (verbose) 131 if (verbose)
132 asprintf (&status, "%s [%.0f (%d%%)]", status, dskfree_mb, 100 - percent); 132 xasprintf (&status, "%s [%.0f (%d%%)]", status, dskfree_mb, 100 - percent);
133 } 133 }
134 } 134 }
135 else if (sscanf (input_buffer, "%*[S]%*[w]%*[a]%*[p]%[TotalFre]%*[:] %f %*[k]%*[B]", str, &tmp_mb)) { 135 else if (sscanf (input_buffer, "%*[S]%*[w]%*[a]%*[p]%[TotalFre]%*[:] %f %*[k]%*[B]", str, &tmp_mb)) {
@@ -152,15 +152,15 @@ main (int argc, char **argv)
152 free_swap_mb = dskfree_mb; 152 free_swap_mb = dskfree_mb;
153#else 153#else
154# ifdef HAVE_SWAP 154# ifdef HAVE_SWAP
155 asprintf(&swap_command, "%s", SWAP_COMMAND); 155 xasprintf(&swap_command, "%s", SWAP_COMMAND);
156 asprintf(&swap_format, "%s", SWAP_FORMAT); 156 xasprintf(&swap_format, "%s", SWAP_FORMAT);
157 157
158/* These override the command used if a summary (and thus ! allswaps) is required */ 158/* These override the command used if a summary (and thus ! allswaps) is required */
159/* The summary flag returns more accurate information about swap usage on these OSes */ 159/* The summary flag returns more accurate information about swap usage on these OSes */
160# ifdef _AIX 160# ifdef _AIX
161 if (!allswaps) { 161 if (!allswaps) {
162 asprintf(&swap_command, "%s", "/usr/sbin/lsps -s"); 162 xasprintf(&swap_command, "%s", "/usr/sbin/lsps -s");
163 asprintf(&swap_format, "%s", "%f%*s %f"); 163 xasprintf(&swap_format, "%s", "%f%*s %f");
164 conv_factor = 1; 164 conv_factor = 1;
165 } 165 }
166# endif 166# endif
@@ -228,7 +228,7 @@ main (int argc, char **argv)
228 percent = 100 * (((double) dskused_mb) / ((double) dsktotal_mb)); 228 percent = 100 * (((double) dskused_mb) / ((double) dsktotal_mb));
229 result = max_state (result, check_swap (percent, dskfree_mb)); 229 result = max_state (result, check_swap (percent, dskfree_mb));
230 if (verbose) 230 if (verbose)
231 asprintf (&status, "%s [%.0f (%d%%)]", status, dskfree_mb, 100 - percent); 231 xasprintf (&status, "%s [%.0f (%d%%)]", status, dskfree_mb, 100 - percent);
232 } 232 }
233 } 233 }
234# ifdef _AIX 234# ifdef _AIX
@@ -290,7 +290,7 @@ main (int argc, char **argv)
290 percent = 100 * (((double) dskused_mb) / ((double) dsktotal_mb)); 290 percent = 100 * (((double) dskused_mb) / ((double) dsktotal_mb));
291 result = max_state (result, check_swap (percent, dskfree_mb)); 291 result = max_state (result, check_swap (percent, dskfree_mb));
292 if (verbose) { 292 if (verbose) {
293 asprintf (&status, "%s [%.0f (%d%%)]", status, dskfree_mb, 100 - percent); 293 xasprintf (&status, "%s [%.0f (%d%%)]", status, dskfree_mb, 100 - percent);
294 } 294 }
295 } 295 }
296 296
@@ -329,7 +329,7 @@ main (int argc, char **argv)
329 percent = 100 * (((double) dskused_mb) / ((double) dsktotal_mb)); 329 percent = 100 * (((double) dskused_mb) / ((double) dsktotal_mb));
330 result = max_state (result, check_swap (percent, dskfree_mb)); 330 result = max_state (result, check_swap (percent, dskfree_mb));
331 if (verbose) { 331 if (verbose) {
332 asprintf (&status, "%s [%.0f (%d%%)]", status, dskfree_mb, 100 - percent); 332 xasprintf (&status, "%s [%.0f (%d%%)]", status, dskfree_mb, 100 - percent);
333 } 333 }
334 } 334 }
335 335
diff --git a/plugins/check_tcp.c b/plugins/check_tcp.c
index d3c92a4..f464b15 100644
--- a/plugins/check_tcp.c
+++ b/plugins/check_tcp.c
@@ -39,7 +39,7 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net";
39 39
40#ifdef HAVE_SSL 40#ifdef HAVE_SSL
41static int check_cert = FALSE; 41static int check_cert = FALSE;
42static int days_till_exp; 42static int days_till_exp_warn, days_till_exp_crit;
43# define my_recv(buf, len) ((flags & FLAG_SSL) ? np_net_ssl_read(buf, len) : read(sd, buf, len)) 43# define my_recv(buf, len) ((flags & FLAG_SSL) ? np_net_ssl_read(buf, len) : read(sd, buf, len))
44# define my_send(buf, len) ((flags & FLAG_SSL) ? np_net_ssl_write(buf, len) : send(sd, buf, len, 0)) 44# define my_send(buf, len) ((flags & FLAG_SSL) ? np_net_ssl_write(buf, len) : send(sd, buf, len, 0))
45#else 45#else
@@ -235,10 +235,10 @@ main (int argc, char **argv)
235 if (flags & FLAG_SSL){ 235 if (flags & FLAG_SSL){
236 result = np_net_ssl_init(sd); 236 result = np_net_ssl_init(sd);
237 if (result == STATE_OK && check_cert == TRUE) { 237 if (result == STATE_OK && check_cert == TRUE) {
238 result = np_net_ssl_check_cert(days_till_exp); 238 result = np_net_ssl_check_cert(days_till_exp_warn, days_till_exp_crit);
239 } 239 }
240 } 240 }
241 if(result != STATE_OK || check_cert == TRUE){ 241 if(result != STATE_OK){
242 np_net_ssl_cleanup(); 242 np_net_ssl_cleanup();
243 if(sd) close(sd); 243 if(sd) close(sd);
244 return result; 244 return result;
@@ -380,6 +380,7 @@ process_arguments (int argc, char **argv)
380{ 380{
381 int c; 381 int c;
382 int escape = 0; 382 int escape = 0;
383 char *temp;
383 384
384 int option = 0; 385 int option = 0;
385 static struct option longopts[] = { 386 static struct option longopts[] = {
@@ -501,7 +502,7 @@ process_arguments (int argc, char **argv)
501 if (escape) 502 if (escape)
502 server_send = np_escaped_string(optarg); 503 server_send = np_escaped_string(optarg);
503 else 504 else
504 asprintf(&server_send, "%s", optarg); 505 xasprintf(&server_send, "%s", optarg);
505 break; 506 break;
506 case 'e': /* expect string (may be repeated) */ 507 case 'e': /* expect string (may be repeated) */
507 flags &= ~FLAG_EXACT_MATCH; 508 flags &= ~FLAG_EXACT_MATCH;
@@ -521,7 +522,7 @@ process_arguments (int argc, char **argv)
521 if (escape) 522 if (escape)
522 server_quit = np_escaped_string(optarg); 523 server_quit = np_escaped_string(optarg);
523 else 524 else
524 asprintf(&server_quit, "%s\r\n", optarg); 525 xasprintf(&server_quit, "%s\r\n", optarg);
525 break; 526 break;
526 case 'r': 527 case 'r':
527 if (!strncmp(optarg,"ok",2)) 528 if (!strncmp(optarg,"ok",2))
@@ -552,9 +553,22 @@ process_arguments (int argc, char **argv)
552 case 'D': /* Check SSL cert validity - days 'til certificate expiration */ 553 case 'D': /* Check SSL cert validity - days 'til certificate expiration */
553#ifdef HAVE_SSL 554#ifdef HAVE_SSL
554# ifdef USE_OPENSSL /* XXX */ 555# ifdef USE_OPENSSL /* XXX */
555 if (!is_intnonneg (optarg)) 556 if ((temp=strchr(optarg,','))!=NULL) {
557 *temp='\0';
558 if (!is_intnonneg (temp))
559 usage2 (_("Invalid certificate expiration period"), optarg); days_till_exp_warn = atoi(optarg);
560 *temp=',';
561 temp++;
562 if (!is_intnonneg (temp))
563 usage2 (_("Invalid certificate expiration period"), temp);
564 days_till_exp_crit = atoi (temp);
565 }
566 else {
567 days_till_exp_crit=0;
568 if (!is_intnonneg (optarg))
556 usage2 (_("Invalid certificate expiration period"), optarg); 569 usage2 (_("Invalid certificate expiration period"), optarg);
557 days_till_exp = atoi (optarg); 570 days_till_exp_warn = atoi (optarg);
571 }
558 check_cert = TRUE; 572 check_cert = TRUE;
559 flags |= FLAG_SSL; 573 flags |= FLAG_SSL;
560 break; 574 break;
@@ -626,8 +640,9 @@ print_help (void)
626 printf (" %s\n", _("Seconds to wait between sending string and polling for response")); 640 printf (" %s\n", _("Seconds to wait between sending string and polling for response"));
627 641
628#ifdef HAVE_SSL 642#ifdef HAVE_SSL
629 printf (" %s\n", "-D, --certificate=INTEGER"); 643 printf (" %s\n", "-D, --certificate=INTEGER[,INTEGER]");
630 printf (" %s\n", _("Minimum number of days a certificate has to be valid.")); 644 printf (" %s\n", _("Minimum number of days a certificate has to be valid."));
645 printf (" %s\n", _("1st is #days for warning, 2nd is critical (if not specified - 0)."));
631 printf (" %s\n", "-S, --ssl"); 646 printf (" %s\n", "-S, --ssl");
632 printf (" %s\n", _("Use SSL for the connection.")); 647 printf (" %s\n", _("Use SSL for the connection."));
633#endif 648#endif
@@ -649,6 +664,6 @@ print_usage (void)
649 printf ("%s -H host -p port [-w <warning time>] [-c <critical time>] [-s <send string>]\n",progname); 664 printf ("%s -H host -p port [-w <warning time>] [-c <critical time>] [-s <send string>]\n",progname);
650 printf ("[-e <expect string>] [-q <quit string>][-m <maximum bytes>] [-d <delay>]\n"); 665 printf ("[-e <expect string>] [-q <quit string>][-m <maximum bytes>] [-d <delay>]\n");
651 printf ("[-t <timeout seconds>] [-r <refuse state>] [-M <mismatch state>] [-v] [-4|-6] [-j]\n"); 666 printf ("[-t <timeout seconds>] [-r <refuse state>] [-M <mismatch state>] [-v] [-4|-6] [-j]\n");
652 printf ("[-D <days to cert expiry>] [-S <use SSL>] [-E]\n"); 667 printf ("[-D <warn days cert expire>[,<crit days cert expire>]] [-S <use SSL>] [-E]\n");
653} 668}
654 669
diff --git a/plugins/check_time.c b/plugins/check_time.c
index 3dcc662..7ee014e 100644
--- a/plugins/check_time.c
+++ b/plugins/check_time.c
@@ -329,7 +329,7 @@ void
329print_help (void) 329print_help (void)
330{ 330{
331 char *myport; 331 char *myport;
332 asprintf (&myport, "%d", TIME_PORT); 332 xasprintf (&myport, "%d", TIME_PORT);
333 333
334 print_revision (progname, NP_VERSION); 334 print_revision (progname, NP_VERSION);
335 335
diff --git a/plugins/check_ups.c b/plugins/check_ups.c
index 30c9357..59dcc26 100644
--- a/plugins/check_ups.c
+++ b/plugins/check_ups.c
@@ -136,56 +136,56 @@ main (int argc, char **argv)
136 result = STATE_OK; 136 result = STATE_OK;
137 137
138 if (status & UPSSTATUS_OFF) { 138 if (status & UPSSTATUS_OFF) {
139 asprintf (&ups_status, "Off"); 139 xasprintf (&ups_status, "Off");
140 result = STATE_CRITICAL; 140 result = STATE_CRITICAL;
141 } 141 }
142 else if ((status & (UPSSTATUS_OB | UPSSTATUS_LB)) == 142 else if ((status & (UPSSTATUS_OB | UPSSTATUS_LB)) ==
143 (UPSSTATUS_OB | UPSSTATUS_LB)) { 143 (UPSSTATUS_OB | UPSSTATUS_LB)) {
144 asprintf (&ups_status, _("On Battery, Low Battery")); 144 xasprintf (&ups_status, _("On Battery, Low Battery"));
145 result = STATE_CRITICAL; 145 result = STATE_CRITICAL;
146 } 146 }
147 else { 147 else {
148 if (status & UPSSTATUS_OL) { 148 if (status & UPSSTATUS_OL) {
149 asprintf (&ups_status, "%s%s", ups_status, _("Online")); 149 xasprintf (&ups_status, "%s%s", ups_status, _("Online"));
150 } 150 }
151 if (status & UPSSTATUS_OB) { 151 if (status & UPSSTATUS_OB) {
152 asprintf (&ups_status, "%s%s", ups_status, _("On Battery")); 152 xasprintf (&ups_status, "%s%s", ups_status, _("On Battery"));
153 result = STATE_WARNING; 153 result = STATE_WARNING;
154 } 154 }
155 if (status & UPSSTATUS_LB) { 155 if (status & UPSSTATUS_LB) {
156 asprintf (&ups_status, "%s%s", ups_status, _(", Low Battery")); 156 xasprintf (&ups_status, "%s%s", ups_status, _(", Low Battery"));
157 result = STATE_WARNING; 157 result = STATE_WARNING;
158 } 158 }
159 if (status & UPSSTATUS_CAL) { 159 if (status & UPSSTATUS_CAL) {
160 asprintf (&ups_status, "%s%s", ups_status, _(", Calibrating")); 160 xasprintf (&ups_status, "%s%s", ups_status, _(", Calibrating"));
161 } 161 }
162 if (status & UPSSTATUS_RB) { 162 if (status & UPSSTATUS_RB) {
163 asprintf (&ups_status, "%s%s", ups_status, _(", Replace Battery")); 163 xasprintf (&ups_status, "%s%s", ups_status, _(", Replace Battery"));
164 result = STATE_WARNING; 164 result = STATE_WARNING;
165 } 165 }
166 if (status & UPSSTATUS_BYPASS) { 166 if (status & UPSSTATUS_BYPASS) {
167 asprintf (&ups_status, "%s%s", ups_status, _(", On Bypass")); 167 xasprintf (&ups_status, "%s%s", ups_status, _(", On Bypass"));
168 } 168 }
169 if (status & UPSSTATUS_OVER) { 169 if (status & UPSSTATUS_OVER) {
170 asprintf (&ups_status, "%s%s", ups_status, _(", Overload")); 170 xasprintf (&ups_status, "%s%s", ups_status, _(", Overload"));
171 } 171 }
172 if (status & UPSSTATUS_TRIM) { 172 if (status & UPSSTATUS_TRIM) {
173 asprintf (&ups_status, "%s%s", ups_status, _(", Trimming")); 173 xasprintf (&ups_status, "%s%s", ups_status, _(", Trimming"));
174 } 174 }
175 if (status & UPSSTATUS_BOOST) { 175 if (status & UPSSTATUS_BOOST) {
176 asprintf (&ups_status, "%s%s", ups_status, _(", Boosting")); 176 xasprintf (&ups_status, "%s%s", ups_status, _(", Boosting"));
177 } 177 }
178 if (status & UPSSTATUS_CHRG) { 178 if (status & UPSSTATUS_CHRG) {
179 asprintf (&ups_status, "%s%s", ups_status, _(", Charging")); 179 xasprintf (&ups_status, "%s%s", ups_status, _(", Charging"));
180 } 180 }
181 if (status & UPSSTATUS_DISCHRG) { 181 if (status & UPSSTATUS_DISCHRG) {
182 asprintf (&ups_status, "%s%s", ups_status, _(", Discharging")); 182 xasprintf (&ups_status, "%s%s", ups_status, _(", Discharging"));
183 } 183 }
184 if (status & UPSSTATUS_UNKOWN) { 184 if (status & UPSSTATUS_UNKOWN) {
185 asprintf (&ups_status, "%s%s", ups_status, _(", Unknown")); 185 xasprintf (&ups_status, "%s%s", ups_status, _(", Unknown"));
186 } 186 }
187 } 187 }
188 asprintf (&message, "%sStatus=%s ", message, ups_status); 188 xasprintf (&message, "%sStatus=%s ", message, ups_status);
189 } 189 }
190 190
191 /* get the ups utility voltage if possible */ 191 /* get the ups utility voltage if possible */
@@ -197,7 +197,7 @@ main (int argc, char **argv)
197 supported_options |= UPS_UTILITY; 197 supported_options |= UPS_UTILITY;
198 198
199 ups_utility_voltage = atof (temp_buffer); 199 ups_utility_voltage = atof (temp_buffer);
200 asprintf (&message, "%sUtility=%3.1fV ", message, ups_utility_voltage); 200 xasprintf (&message, "%sUtility=%3.1fV ", message, ups_utility_voltage);
201 201
202 if (ups_utility_voltage > 120.0) 202 if (ups_utility_voltage > 120.0)
203 ups_utility_deviation = 120.0 - ups_utility_voltage; 203 ups_utility_deviation = 120.0 - ups_utility_voltage;
@@ -211,13 +211,13 @@ main (int argc, char **argv)
211 else if (check_warn==TRUE && ups_utility_deviation>=warning_value) { 211 else if (check_warn==TRUE && ups_utility_deviation>=warning_value) {
212 result = max_state (result, STATE_WARNING); 212 result = max_state (result, STATE_WARNING);
213 } 213 }
214 asprintf (&data, "%s", 214 xasprintf (&data, "%s",
215 perfdata ("voltage", (long)(1000*ups_utility_voltage), "mV", 215 perfdata ("voltage", (long)(1000*ups_utility_voltage), "mV",
216 check_warn, (long)(1000*warning_value), 216 check_warn, (long)(1000*warning_value),
217 check_crit, (long)(1000*critical_value), 217 check_crit, (long)(1000*critical_value),
218 TRUE, 0, FALSE, 0)); 218 TRUE, 0, FALSE, 0));
219 } else { 219 } else {
220 asprintf (&data, "%s", 220 xasprintf (&data, "%s",
221 perfdata ("voltage", (long)(1000*ups_utility_voltage), "mV", 221 perfdata ("voltage", (long)(1000*ups_utility_voltage), "mV",
222 FALSE, 0, FALSE, 0, TRUE, 0, FALSE, 0)); 222 FALSE, 0, FALSE, 0, TRUE, 0, FALSE, 0));
223 } 223 }
@@ -231,7 +231,7 @@ main (int argc, char **argv)
231 else { 231 else {
232 supported_options |= UPS_BATTPCT; 232 supported_options |= UPS_BATTPCT;
233 ups_battery_percent = atof (temp_buffer); 233 ups_battery_percent = atof (temp_buffer);
234 asprintf (&message, "%sBatt=%3.1f%% ", message, ups_battery_percent); 234 xasprintf (&message, "%sBatt=%3.1f%% ", message, ups_battery_percent);
235 235
236 if (check_variable == UPS_BATTPCT) { 236 if (check_variable == UPS_BATTPCT) {
237 if (check_crit==TRUE && ups_battery_percent <= critical_value) { 237 if (check_crit==TRUE && ups_battery_percent <= critical_value) {
@@ -240,13 +240,13 @@ main (int argc, char **argv)
240 else if (check_warn==TRUE && ups_battery_percent<=warning_value) { 240 else if (check_warn==TRUE && ups_battery_percent<=warning_value) {
241 result = max_state (result, STATE_WARNING); 241 result = max_state (result, STATE_WARNING);
242 } 242 }
243 asprintf (&data, "%s %s", data, 243 xasprintf (&data, "%s %s", data,
244 perfdata ("battery", (long)ups_battery_percent, "%", 244 perfdata ("battery", (long)ups_battery_percent, "%",
245 check_warn, (long)(1000*warning_value), 245 check_warn, (long)(1000*warning_value),
246 check_crit, (long)(1000*critical_value), 246 check_crit, (long)(1000*critical_value),
247 TRUE, 0, TRUE, 100)); 247 TRUE, 0, TRUE, 100));
248 } else { 248 } else {
249 asprintf (&data, "%s %s", data, 249 xasprintf (&data, "%s %s", data,
250 perfdata ("battery", (long)ups_battery_percent, "%", 250 perfdata ("battery", (long)ups_battery_percent, "%",
251 FALSE, 0, FALSE, 0, TRUE, 0, TRUE, 100)); 251 FALSE, 0, FALSE, 0, TRUE, 0, TRUE, 100));
252 } 252 }
@@ -260,7 +260,7 @@ main (int argc, char **argv)
260 else { 260 else {
261 supported_options |= UPS_LOADPCT; 261 supported_options |= UPS_LOADPCT;
262 ups_load_percent = atof (temp_buffer); 262 ups_load_percent = atof (temp_buffer);
263 asprintf (&message, "%sLoad=%3.1f%% ", message, ups_load_percent); 263 xasprintf (&message, "%sLoad=%3.1f%% ", message, ups_load_percent);
264 264
265 if (check_variable == UPS_LOADPCT) { 265 if (check_variable == UPS_LOADPCT) {
266 if (check_crit==TRUE && ups_load_percent>=critical_value) { 266 if (check_crit==TRUE && ups_load_percent>=critical_value) {
@@ -269,13 +269,13 @@ main (int argc, char **argv)
269 else if (check_warn==TRUE && ups_load_percent>=warning_value) { 269 else if (check_warn==TRUE && ups_load_percent>=warning_value) {
270 result = max_state (result, STATE_WARNING); 270 result = max_state (result, STATE_WARNING);
271 } 271 }
272 asprintf (&data, "%s %s", data, 272 xasprintf (&data, "%s %s", data,
273 perfdata ("load", (long)ups_load_percent, "%", 273 perfdata ("load", (long)ups_load_percent, "%",
274 check_warn, (long)(1000*warning_value), 274 check_warn, (long)(1000*warning_value),
275 check_crit, (long)(1000*critical_value), 275 check_crit, (long)(1000*critical_value),
276 TRUE, 0, TRUE, 100)); 276 TRUE, 0, TRUE, 100));
277 } else { 277 } else {
278 asprintf (&data, "%s %s", data, 278 xasprintf (&data, "%s %s", data,
279 perfdata ("load", (long)ups_load_percent, "%", 279 perfdata ("load", (long)ups_load_percent, "%",
280 FALSE, 0, FALSE, 0, TRUE, 0, TRUE, 100)); 280 FALSE, 0, FALSE, 0, TRUE, 0, TRUE, 100));
281 } 281 }
@@ -291,12 +291,12 @@ main (int argc, char **argv)
291 if (temp_output_c) { 291 if (temp_output_c) {
292 tunits="degC"; 292 tunits="degC";
293 ups_temperature = atof (temp_buffer); 293 ups_temperature = atof (temp_buffer);
294 asprintf (&message, "%sTemp=%3.1fC", message, ups_temperature); 294 xasprintf (&message, "%sTemp=%3.1fC", message, ups_temperature);
295 } 295 }
296 else { 296 else {
297 tunits="degF"; 297 tunits="degF";
298 ups_temperature = (atof (temp_buffer) * 1.8) + 32; 298 ups_temperature = (atof (temp_buffer) * 1.8) + 32;
299 asprintf (&message, "%sTemp=%3.1fF", message, ups_temperature); 299 xasprintf (&message, "%sTemp=%3.1fF", message, ups_temperature);
300 } 300 }
301 301
302 if (check_variable == UPS_TEMP) { 302 if (check_variable == UPS_TEMP) {
@@ -306,13 +306,13 @@ main (int argc, char **argv)
306 else if (check_warn == TRUE && ups_temperature>=warning_value) { 306 else if (check_warn == TRUE && ups_temperature>=warning_value) {
307 result = max_state (result, STATE_WARNING); 307 result = max_state (result, STATE_WARNING);
308 } 308 }
309 asprintf (&data, "%s %s", data, 309 xasprintf (&data, "%s %s", data,
310 perfdata ("temp", (long)ups_temperature, tunits, 310 perfdata ("temp", (long)ups_temperature, tunits,
311 check_warn, (long)(1000*warning_value), 311 check_warn, (long)(1000*warning_value),
312 check_crit, (long)(1000*critical_value), 312 check_crit, (long)(1000*critical_value),
313 TRUE, 0, FALSE, 0)); 313 TRUE, 0, FALSE, 0));
314 } else { 314 } else {
315 asprintf (&data, "%s %s", data, 315 xasprintf (&data, "%s %s", data,
316 perfdata ("temp", (long)ups_temperature, tunits, 316 perfdata ("temp", (long)ups_temperature, tunits,
317 FALSE, 0, FALSE, 0, TRUE, 0, FALSE, 0)); 317 FALSE, 0, FALSE, 0, TRUE, 0, FALSE, 0));
318 } 318 }
@@ -321,7 +321,7 @@ main (int argc, char **argv)
321 /* if the UPS does not support any options we are looking for, report an error */ 321 /* if the UPS does not support any options we are looking for, report an error */
322 if (supported_options == UPS_NONE) { 322 if (supported_options == UPS_NONE) {
323 result = STATE_CRITICAL; 323 result = STATE_CRITICAL;
324 asprintf (&message, _("UPS does not support any available options\n")); 324 xasprintf (&message, _("UPS does not support any available options\n"));
325 } 325 }
326 326
327 /* reset timeout */ 327 /* reset timeout */
@@ -595,7 +595,7 @@ void
595print_help (void) 595print_help (void)
596{ 596{
597 char *myport; 597 char *myport;
598 asprintf (&myport, "%d", PORT); 598 xasprintf (&myport, "%d", PORT);
599 599
600 print_revision (progname, NP_VERSION); 600 print_revision (progname, NP_VERSION);
601 601
diff --git a/plugins/check_users.c b/plugins/check_users.c
index 8368612..c581fb2 100644
--- a/plugins/check_users.c
+++ b/plugins/check_users.c
@@ -3,7 +3,7 @@
3* Nagios check_users plugin 3* Nagios check_users plugin
4* 4*
5* License: GPL 5* License: GPL
6* Copyright (c) 2000-2007 Nagios Plugins Development Team 6* Copyright (c) 2000-2012 Nagios Plugins Development Team
7* 7*
8* Description: 8* Description:
9* 9*
@@ -35,8 +35,8 @@ const char *copyright = "2000-2007";
35const char *email = "nagiosplug-devel@lists.sourceforge.net"; 35const char *email = "nagiosplug-devel@lists.sourceforge.net";
36 36
37#include "common.h" 37#include "common.h"
38#include "popen.h"
39#include "utils.h" 38#include "utils.h"
39#include <utmpx.h>
40 40
41#define possibly_set(a,b) ((a) == 0 ? (b) : 0) 41#define possibly_set(a,b) ((a) == 0 ? (b) : 0)
42 42
@@ -52,58 +52,33 @@ main (int argc, char **argv)
52{ 52{
53 int users = -1; 53 int users = -1;
54 int result = STATE_UNKNOWN; 54 int result = STATE_UNKNOWN;
55 char input_buffer[MAX_INPUT_BUFFER];
56 char *perf; 55 char *perf;
56 struct utmpx *putmpx;
57 57
58 setlocale (LC_ALL, ""); 58 setlocale (LC_ALL, "");
59 bindtextdomain (PACKAGE, LOCALEDIR); 59 bindtextdomain (PACKAGE, LOCALEDIR);
60 textdomain (PACKAGE); 60 textdomain (PACKAGE);
61 61
62 perf = strdup(""); 62 perf = strdup ("");
63 63
64 /* Parse extra opts if any */ 64 /* Parse extra opts if any */
65 argv=np_extra_opts (&argc, argv, progname); 65 argv = np_extra_opts (&argc, argv, progname);
66 66
67 if (process_arguments (argc, argv) == ERROR) 67 if (process_arguments (argc, argv) == ERROR)
68 usage4 (_("Could not parse arguments")); 68 usage4 (_("Could not parse arguments"));
69 69
70 /* run the command */
71 child_process = spopen (WHO_COMMAND);
72 if (child_process == NULL) {
73 printf (_("Could not open pipe: %s\n"), WHO_COMMAND);
74 return STATE_UNKNOWN;
75 }
76
77 child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r");
78 if (child_stderr == NULL)
79 printf (_("Could not open stderr for %s\n"), WHO_COMMAND);
80
81 users = 0; 70 users = 0;
82 71
83 while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) { 72 /* get currently logged users from utmpx */
73 setutxent ();
84 74
85 /* increment 'users' on all lines except total user count */ 75 while ((putmpx = getutxent ()) != NULL)
86 if (input_buffer[0] != '#') { 76 if (putmpx->ut_type == USER_PROCESS)
87 users++; 77 users++;
88 continue;
89 }
90
91 /* get total logged in users */
92 if (sscanf (input_buffer, _("# users=%d"), &users) == 1)
93 break;
94
95 }
96 78
97 /* check STDERR */ 79 endutxent ();
98 if (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr))
99 result = possibly_set (result, STATE_UNKNOWN);
100 (void) fclose (child_stderr);
101 80
102 /* close the pipe */ 81 /* check the user count against warning and critical thresholds */
103 if (spclose (child_process))
104 result = possibly_set (result, STATE_UNKNOWN);
105
106 /* else check the user count against warning and critical thresholds */
107 if (users > cusers) 82 if (users > cusers)
108 result = STATE_CRITICAL; 83 result = STATE_CRITICAL;
109 else if (users > wusers) 84 else if (users > wusers)
@@ -114,7 +89,7 @@ main (int argc, char **argv)
114 if (result == STATE_UNKNOWN) 89 if (result == STATE_UNKNOWN)
115 printf ("%s\n", _("Unable to read output")); 90 printf ("%s\n", _("Unable to read output"));
116 else { 91 else {
117 asprintf(&perf, "%s", perfdata ("users", users, "", 92 xasprintf (&perf, "%s", perfdata ("users", users, "",
118 TRUE, wusers, 93 TRUE, wusers,
119 TRUE, cusers, 94 TRUE, cusers,
120 TRUE, 0, 95 TRUE, 0,
@@ -126,14 +101,11 @@ main (int argc, char **argv)
126 return result; 101 return result;
127} 102}
128 103
129
130
131/* process command-line arguments */ 104/* process command-line arguments */
132int 105int
133process_arguments (int argc, char **argv) 106process_arguments (int argc, char **argv)
134{ 107{
135 int c; 108 int c;
136
137 int option = 0; 109 int option = 0;
138 static struct option longopts[] = { 110 static struct option longopts[] = {
139 {"critical", required_argument, 0, 'c'}, 111 {"critical", required_argument, 0, 'c'},
@@ -183,7 +155,6 @@ process_arguments (int argc, char **argv)
183 else 155 else
184 wusers = atoi (argv[c++]); 156 wusers = atoi (argv[c++]);
185 } 157 }
186
187 if (cusers == -1 && argc > c) { 158 if (cusers == -1 && argc > c) {
188 if (is_intnonneg (argv[c]) == FALSE) 159 if (is_intnonneg (argv[c]) == FALSE)
189 usage4 (_("Warning threshold must be a positive integer")); 160 usage4 (_("Warning threshold must be a positive integer"));
@@ -194,8 +165,6 @@ process_arguments (int argc, char **argv)
194 return OK; 165 return OK;
195} 166}
196 167
197
198
199void 168void
200print_help (void) 169print_help (void)
201{ 170{
@@ -205,9 +174,9 @@ print_help (void)
205 printf (COPYRIGHT, copyright, email); 174 printf (COPYRIGHT, copyright, email);
206 175
207 printf ("%s\n", _("This plugin checks the number of users currently logged in on the local")); 176 printf ("%s\n", _("This plugin checks the number of users currently logged in on the local"));
208 printf ("%s\n", _("system and generates an error if the number exceeds the thresholds specified.")); 177 printf ("%s\n", _("system and generates an error if the number exceeds the thresholds specified."));
209 178
210 printf ("\n\n"); 179 printf ("\n\n");
211 180
212 print_usage (); 181 print_usage ();
213 182
@@ -215,17 +184,16 @@ print_help (void)
215 printf (UT_EXTRA_OPTS); 184 printf (UT_EXTRA_OPTS);
216 185
217 printf (" %s\n", "-w, --warning=INTEGER"); 186 printf (" %s\n", "-w, --warning=INTEGER");
218 printf (" %s\n", _("Set WARNING status if more than INTEGER users are logged in")); 187 printf (" %s\n", _("Set WARNING status if more than INTEGER users are logged in"));
219 printf (" %s\n", "-c, --critical=INTEGER"); 188 printf (" %s\n", "-c, --critical=INTEGER");
220 printf (" %s\n", _("Set CRITICAL status if more than INTEGER users are logged in")); 189 printf (" %s\n", _("Set CRITICAL status if more than INTEGER users are logged in"));
221 190
222 printf (UT_SUPPORT); 191 printf (UT_SUPPORT);
223} 192}
224 193
225
226void 194void
227print_usage (void) 195print_usage (void)
228{ 196{
229 printf ("%s\n", _("Usage:")); 197 printf ("%s\n", _("Usage:"));
230 printf ("%s -w <users> -c <users>\n", progname); 198 printf ("%s -w <users> -c <users>\n", progname);
231} 199}
diff --git a/plugins/negate.c b/plugins/negate.c
index 96f4557..493988e 100644
--- a/plugins/negate.c
+++ b/plugins/negate.c
@@ -104,7 +104,7 @@ main (int argc, char **argv)
104 *sub = '\0'; 104 *sub = '\0';
105 sub += strlen (state_text (result)); 105 sub += strlen (state_text (result));
106 /* then put everything back together */ 106 /* then put everything back together */
107 asprintf (&chld_out.line[i], "%s%s%s", chld_out.line[i], state_text (state[result]), sub); 107 xasprintf (&chld_out.line[i], "%s%s%s", chld_out.line[i], state_text (state[result]), sub);
108 } 108 }
109 } 109 }
110 printf ("%s\n", chld_out.line[i]); 110 printf ("%s\n", chld_out.line[i]);
diff --git a/plugins/netutils.h b/plugins/netutils.h
index 572a3ae..21017f1 100644
--- a/plugins/netutils.h
+++ b/plugins/netutils.h
@@ -103,7 +103,7 @@ int np_net_ssl_init_with_hostname(int sd, char *host_name);
103void np_net_ssl_cleanup(); 103void np_net_ssl_cleanup();
104int np_net_ssl_write(const void *buf, int num); 104int np_net_ssl_write(const void *buf, int num);
105int np_net_ssl_read(void *buf, int num); 105int np_net_ssl_read(void *buf, int num);
106int np_net_ssl_check_cert(int days_till_exp); 106int np_net_ssl_check_cert(int days_till_exp_warn, int days_till_exp_crit);
107#endif /* HAVE_SSL */ 107#endif /* HAVE_SSL */
108 108
109#endif /* _NETUTILS_H_ */ 109#endif /* _NETUTILS_H_ */
diff --git a/plugins/sslutils.c b/plugins/sslutils.c
index 2157764..a1ce560 100644
--- a/plugins/sslutils.c
+++ b/plugins/sslutils.c
@@ -36,92 +36,97 @@ static SSL_CTX *c=NULL;
36static SSL *s=NULL; 36static SSL *s=NULL;
37static int initialized=0; 37static int initialized=0;
38 38
39int np_net_ssl_init (int sd) { 39int np_net_ssl_init(int sd) {
40 return np_net_ssl_init_with_hostname(sd, NULL); 40 return np_net_ssl_init_with_hostname(sd, NULL);
41} 41}
42 42
43int np_net_ssl_init_with_hostname (int sd, char *host_name) { 43int np_net_ssl_init_with_hostname(int sd, char *host_name) {
44 return np_net_ssl_init_with_hostname_and_version(sd, host_name, 0); 44 return np_net_ssl_init_with_hostname_and_version(sd, host_name, 0);
45} 45}
46 46
47int np_net_ssl_init_with_hostname_and_version (int sd, char *host_name, int version) { 47int np_net_ssl_init_with_hostname_and_version(int sd, char *host_name, int version) {
48 const SSL_METHOD *method = NULL; 48 const SSL_METHOD *method = NULL;
49 49
50 switch (version) { 50 switch (version) {
51 case 0: /* Deafult to auto negotiation */ 51 case 0: /* Deafult to auto negotiation */
52 method = SSLv23_client_method(); 52 method = SSLv23_client_method();
53 break; 53 break;
54 case 1: /* TLSv1 protocol */ 54 case 1: /* TLSv1 protocol */
55 method = TLSv1_client_method(); 55 method = TLSv1_client_method();
56 break; 56 break;
57 case 2: /* SSLv2 protocol */ 57 case 2: /* SSLv2 protocol */
58 method = SSLv2_client_method(); 58#if defined(USE_GNUTLS) || defined(OPENSSL_NO_SSL2)
59 break; 59 printf(("%s\n", _("CRITICAL - SSL protocol version 2 is not supported by your SSL library.")));
60 case 3: /* SSLv3 protocol */ 60 return STATE_CRITICAL;
61 method = SSLv3_client_method(); 61#else
62 break; 62 method = SSLv2_client_method();
63 default: /* Unsupported */ 63#endif
64 printf ("%s\n", _("CRITICAL - Unsupported SSL Protocol Version.")); 64 break;
65 return STATE_CRITICAL; 65 case 3: /* SSLv3 protocol */
66 } 66 method = SSLv3_client_method();
67 if (!initialized) { 67 break;
68 /* Initialize SSL context */ 68 default: /* Unsupported */
69 SSLeay_add_ssl_algorithms (); 69 printf("%s\n", _("CRITICAL - Unsupported SSL protocol version."));
70 SSL_load_error_strings (); 70 return STATE_CRITICAL;
71 OpenSSL_add_all_algorithms (); 71 }
72 initialized = 1; 72 if (!initialized) {
73 } 73 /* Initialize SSL context */
74 if ((c = SSL_CTX_new (method)) == NULL) { 74 SSLeay_add_ssl_algorithms();
75 printf ("%s\n", _("CRITICAL - Cannot create SSL context.")); 75 SSL_load_error_strings();
76 return STATE_CRITICAL; 76 OpenSSL_add_all_algorithms();
77 } 77 initialized = 1;
78 }
79 if ((c = SSL_CTX_new(method)) == NULL) {
80 printf("%s\n", _("CRITICAL - Cannot create SSL context."));
81 return STATE_CRITICAL;
82 }
78#ifdef SSL_OP_NO_TICKET 83#ifdef SSL_OP_NO_TICKET
79 SSL_CTX_set_options(c, SSL_OP_NO_TICKET); 84 SSL_CTX_set_options(c, SSL_OP_NO_TICKET);
80#endif 85#endif
81 if ((s = SSL_new (c)) != NULL){ 86 if ((s = SSL_new(c)) != NULL) {
82#ifdef SSL_set_tlsext_host_name 87#ifdef SSL_set_tlsext_host_name
83 if (host_name != NULL) 88 if (host_name != NULL)
84 SSL_set_tlsext_host_name(s, host_name); 89 SSL_set_tlsext_host_name(s, host_name);
85#endif 90#endif
86 SSL_set_fd (s, sd); 91 SSL_set_fd(s, sd);
87 if (SSL_connect(s) == 1){ 92 if (SSL_connect(s) == 1) {
88 return OK; 93 return OK;
89 } else { 94 } else {
90 printf ("%s\n", _("CRITICAL - Cannot make SSL connection ")); 95 printf("%s\n", _("CRITICAL - Cannot make SSL connection."));
91# ifdef USE_OPENSSL /* XXX look into ERR_error_string */ 96# ifdef USE_OPENSSL /* XXX look into ERR_error_string */
92 ERR_print_errors_fp (stdout); 97 ERR_print_errors_fp(stdout);
93# endif /* USE_OPENSSL */ 98# endif /* USE_OPENSSL */
94 }
95 } else {
96 printf ("%s\n", _("CRITICAL - Cannot initiate SSL handshake."));
97 } 99 }
98 return STATE_CRITICAL; 100 } else {
101 printf("%s\n", _("CRITICAL - Cannot initiate SSL handshake."));
102 }
103 return STATE_CRITICAL;
99} 104}
100 105
101void np_net_ssl_cleanup (){ 106void np_net_ssl_cleanup() {
102 if(s){ 107 if (s) {
103#ifdef SSL_set_tlsext_host_name 108#ifdef SSL_set_tlsext_host_name
104 SSL_set_tlsext_host_name(s, NULL); 109 SSL_set_tlsext_host_name(s, NULL);
105#endif 110#endif
106 SSL_shutdown (s); 111 SSL_shutdown(s);
107 SSL_free (s); 112 SSL_free(s);
108 if(c) { 113 if (c) {
109 SSL_CTX_free (c); 114 SSL_CTX_free(c);
110 c=NULL; 115 c=NULL;
111 }
112 s=NULL;
113 } 116 }
117 s=NULL;
118 }
114} 119}
115 120
116int np_net_ssl_write(const void *buf, int num){ 121int np_net_ssl_write(const void *buf, int num) {
117 return SSL_write(s, buf, num); 122 return SSL_write(s, buf, num);
118} 123}
119 124
120int np_net_ssl_read(void *buf, int num){ 125int np_net_ssl_read(void *buf, int num) {
121 return SSL_read(s, buf, num); 126 return SSL_read(s, buf, num);
122} 127}
123 128
124int np_net_ssl_check_cert(int days_till_exp){ 129int np_net_ssl_check_cert(int days_till_exp_warn, int days_till_exp_crit){
125# ifdef USE_OPENSSL 130# ifdef USE_OPENSSL
126 X509 *certificate=NULL; 131 X509 *certificate=NULL;
127 X509_NAME *subj=NULL; 132 X509_NAME *subj=NULL;
@@ -137,29 +142,29 @@ int np_net_ssl_check_cert(int days_till_exp){
137 char timestamp[17] = ""; 142 char timestamp[17] = "";
138 143
139 certificate=SSL_get_peer_certificate(s); 144 certificate=SSL_get_peer_certificate(s);
140 if(! certificate){ 145 if (!certificate) {
141 printf ("%s\n",_("CRITICAL - Cannot retrieve server certificate.")); 146 printf("%s\n",_("CRITICAL - Cannot retrieve server certificate."));
142 return STATE_CRITICAL; 147 return STATE_CRITICAL;
143 } 148 }
144 149
145 /* Extract CN from certificate subject */ 150 /* Extract CN from certificate subject */
146 subj=X509_get_subject_name(certificate); 151 subj=X509_get_subject_name(certificate);
147 152
148 if(! subj){ 153 if (!subj) {
149 printf ("%s\n",_("CRITICAL - Cannot retrieve certificate subject.")); 154 printf("%s\n",_("CRITICAL - Cannot retrieve certificate subject."));
150 return STATE_CRITICAL; 155 return STATE_CRITICAL;
151 } 156 }
152 cnlen = X509_NAME_get_text_by_NID (subj, NID_commonName, cn, sizeof(cn)); 157 cnlen = X509_NAME_get_text_by_NID(subj, NID_commonName, cn, sizeof(cn));
153 if ( cnlen == -1 ) 158 if (cnlen == -1)
154 strcpy(cn , _("Unknown CN")); 159 strcpy(cn, _("Unknown CN"));
155 160
156 /* Retrieve timestamp of certificate */ 161 /* Retrieve timestamp of certificate */
157 tm = X509_get_notAfter (certificate); 162 tm = X509_get_notAfter(certificate);
158 163
159 /* Generate tm structure to process timestamp */ 164 /* Generate tm structure to process timestamp */
160 if (tm->type == V_ASN1_UTCTIME) { 165 if (tm->type == V_ASN1_UTCTIME) {
161 if (tm->length < 10) { 166 if (tm->length < 10) {
162 printf ("%s\n", _("CRITICAL - Wrong time format in certificate.")); 167 printf("%s\n", _("CRITICAL - Wrong time format in certificate."));
163 return STATE_CRITICAL; 168 return STATE_CRITICAL;
164 } else { 169 } else {
165 stamp.tm_year = (tm->data[0] - '0') * 10 + (tm->data[1] - '0'); 170 stamp.tm_year = (tm->data[0] - '0') * 10 + (tm->data[1] - '0');
@@ -169,7 +174,7 @@ int np_net_ssl_check_cert(int days_till_exp){
169 } 174 }
170 } else { 175 } else {
171 if (tm->length < 12) { 176 if (tm->length < 12) {
172 printf ("%s\n", _("CRITICAL - Wrong time format in certificate.")); 177 printf("%s\n", _("CRITICAL - Wrong time format in certificate."));
173 return STATE_CRITICAL; 178 return STATE_CRITICAL;
174 } else { 179 } else {
175 stamp.tm_year = 180 stamp.tm_year =
@@ -197,23 +202,29 @@ int np_net_ssl_check_cert(int days_till_exp){
197 stamp.tm_mon + 1, 202 stamp.tm_mon + 1,
198 stamp.tm_mday, stamp.tm_year + 1900, stamp.tm_hour, stamp.tm_min); 203 stamp.tm_mday, stamp.tm_year + 1900, stamp.tm_hour, stamp.tm_min);
199 204
200 if (days_left > 0 && days_left <= days_till_exp) { 205 if (days_left > 0 && days_left <= days_till_exp_warn) {
201 printf (_("WARNING - Certificate '%s' expires in %d day(s) (%s).\n"), cn, days_left, timestamp); 206 printf (_("%s - Certificate '%s' expires in %d day(s) (%s).\n"), (days_left>days_till_exp_crit)?"WARNING":"CRITICAL", cn, days_left, timestamp);
202 status=STATE_WARNING; 207 if (days_left > days_till_exp_crit)
208 return STATE_WARNING;
209 else
210 return STATE_CRITICAL;
203 } else if (time_left < 0) { 211 } else if (time_left < 0) {
204 printf (_("CRITICAL - Certificate '%s' expired on %s.\n"), cn, timestamp); 212 printf(_("CRITICAL - Certificate '%s' expired on %s.\n"), cn, timestamp);
205 status=STATE_CRITICAL; 213 status=STATE_CRITICAL;
206 } else if (days_left == 0) { 214 } else if (days_left == 0) {
207 printf (_("WARNING - Certificate '%s' expires today (%s).\n"), cn, timestamp); 215 printf (_("%s - Certificate '%s' expires today (%s).\n"), (days_left>days_till_exp_crit)?"WARNING":"CRITICAL", cn, timestamp);
208 status=STATE_WARNING; 216 if (days_left > days_till_exp_crit)
217 return STATE_WARNING;
218 else
219 return STATE_CRITICAL;
209 } else { 220 } else {
210 printf (_("OK - Certificate '%s' will expire on %s.\n"), cn, timestamp); 221 printf(_("OK - Certificate '%s' will expire on %s.\n"), cn, timestamp);
211 status=STATE_OK; 222 status=STATE_OK;
212 } 223 }
213 X509_free (certificate); 224 X509_free(certificate);
214 return status; 225 return status;
215# else /* ifndef USE_OPENSSL */ 226# else /* ifndef USE_OPENSSL */
216 printf ("%s\n", _("WARNING - Plugin does not support checking certificates.")); 227 printf("%s\n", _("WARNING - Plugin does not support checking certificates."));
217 return STATE_WARNING; 228 return STATE_WARNING;
218# endif /* USE_OPENSSL */ 229# endif /* USE_OPENSSL */
219} 230}
diff --git a/plugins/t/check_by_ssh.t b/plugins/t/check_by_ssh.t
index cca72c9..8d1b190 100644
--- a/plugins/t/check_by_ssh.t
+++ b/plugins/t/check_by_ssh.t
@@ -27,11 +27,11 @@ plan skip_all => "SSH_HOST and SSH_IDENTITY must be defined" unless ($ssh_servic
27plan tests => 42; 27plan tests => 42;
28 28
29# Some random check strings/response 29# Some random check strings/response
30my @responce = ('OK: Everything is fine!', 30my @responce = ('OK: Everything is fine',
31 'WARNING: Hey, pick me, pick me!', 31 'WARNING: Hey, pick me, pick me',
32 'CRITICAL: Shit happens...', 32 'CRITICAL: Shit happens',
33 'UNKNOWN: What can I do for ya?', 33 'UNKNOWN: What can I do for ya',
34 'WOOPS: What did I smoke?', 34 'WOOPS: What did I smoke',
35); 35);
36my @responce_re; 36my @responce_re;
37my @check; 37my @check;
diff --git a/plugins/t/check_http.t b/plugins/t/check_http.t
index 55a5a53..0a25c77 100644
--- a/plugins/t/check_http.t
+++ b/plugins/t/check_http.t
@@ -8,7 +8,7 @@ use strict;
8use Test::More; 8use Test::More;
9use NPTest; 9use NPTest;
10 10
11plan tests => 26; 11plan tests => 28;
12 12
13my $successOutput = '/OK.*HTTP.*second/'; 13my $successOutput = '/OK.*HTTP.*second/';
14 14
@@ -105,6 +105,10 @@ SKIP: {
105 like ( $res->output, "/Certificate 'www.verisign.com' will expire on/", "Output OK" ); 105 like ( $res->output, "/Certificate 'www.verisign.com' will expire on/", "Output OK" );
106 my $saved_cert_output = $res->output; 106 my $saved_cert_output = $res->output;
107 107
108 $res = NPTest->testCmd( "./check_http -C 8000,1 --ssl www.verisign.com" );
109 cmp_ok( $res->return_code, '==', 1, "Checking certificate for www.verisign.com");
110 like ( $res->output, qr/WARNING - Certificate 'www.verisign.com' expires in \d+ day/, "Output Warning" );
111
108 $res = NPTest->testCmd( "./check_http www.verisign.com -C 1" ); 112 $res = NPTest->testCmd( "./check_http www.verisign.com -C 1" );
109 is( $res->return_code, 0, "Old syntax for cert checking okay" ); 113 is( $res->return_code, 0, "Old syntax for cert checking okay" );
110 is( $res->output, $saved_cert_output, "Same output as new syntax" ); 114 is( $res->output, $saved_cert_output, "Same output as new syntax" );
diff --git a/plugins/t/check_tcp.t b/plugins/t/check_tcp.t
index fd2b5dd..75c1e5f 100644
--- a/plugins/t/check_tcp.t
+++ b/plugins/t/check_tcp.t
@@ -30,6 +30,10 @@ $t += checkCmd( "./check_tcp $host_tcp_http -p 80 -wt 300 -ct 600", 0
30$t += checkCmd( "./check_tcp $host_tcp_http -p 81 -wt 0 -ct 0 -to 1", 2 ); # use invalid port for this test 30$t += checkCmd( "./check_tcp $host_tcp_http -p 81 -wt 0 -ct 0 -to 1", 2 ); # use invalid port for this test
31$t += checkCmd( "./check_tcp $host_nonresponsive -p 80 -wt 0 -ct 0 -to 1", 2 ); 31$t += checkCmd( "./check_tcp $host_nonresponsive -p 80 -wt 0 -ct 0 -to 1", 2 );
32$t += checkCmd( "./check_tcp $hostname_invalid -p 80 -wt 0 -ct 0 -to 1", 2 ); 32$t += checkCmd( "./check_tcp $hostname_invalid -p 80 -wt 0 -ct 0 -to 1", 2 );
33$t += checkCmd( "./check_tcp -S -D 1 -H www.verisign.com -p 443", 0 );
34$t += checkCmd( "./check_tcp -S -D 9000,1 -H www.verisign.com -p 443", 0 );
35$t += checkCmd( "./check_tcp -S -D 9000 -H www.verisign.com -p 443", 1 );
36$t += checkCmd( "./check_tcp -S -D 9000,8999 -H www.verisign.com -p 443", 2 );
33 37
34# Need the \r\n to make it more standards compliant with web servers. Need the various quotes 38# Need the \r\n to make it more standards compliant with web servers. Need the various quotes
35# so that perl doesn't interpret the \r\n and is passed onto command line correctly 39# so that perl doesn't interpret the \r\n and is passed onto command line correctly
diff --git a/plugins/tests/check_http.t b/plugins/tests/check_http.t
index 9ae6bbd..8337f52 100755
--- a/plugins/tests/check_http.t
+++ b/plugins/tests/check_http.t
@@ -188,6 +188,10 @@ SKIP: {
188 is( $result->return_code, 1, "$command -p $port_https -S -C 14000" ); 188 is( $result->return_code, 1, "$command -p $port_https -S -C 14000" );
189 like( $result->output, '/WARNING - Certificate \'Ton Voon\' expires in \d+ day\(s\) \(03/03/2019 21:41\)./', "output ok" ); 189 like( $result->output, '/WARNING - Certificate \'Ton Voon\' expires in \d+ day\(s\) \(03/03/2019 21:41\)./', "output ok" );
190 190
191 $result = NPTest->testCmd( "$command -p $port_https -S -C 13960,14000" );
192 is( $result->return_code, 1, "$command -p $port_https -S -C 139600,14000" );
193 like( $result->output, '/CRITICAL - Certificate \'Ton Voon\' expires in \d+ day\(s\) \(03/03/2019 21:41\)./', "output ok" );
194
191 # Expired cert tests 195 # Expired cert tests
192 $result = NPTest->testCmd( "$command -p $port_https_expired -S -C 7" ); 196 $result = NPTest->testCmd( "$command -p $port_https_expired -S -C 7" );
193 is( $result->return_code, 2, "$command -p $port_https_expired -S -C 7" ); 197 is( $result->return_code, 2, "$command -p $port_https_expired -S -C 7" );
diff --git a/plugins/tests/check_snmp.t b/plugins/tests/check_snmp.t
index 2645cc1..1ef0b20 100755
--- a/plugins/tests/check_snmp.t
+++ b/plugins/tests/check_snmp.t
@@ -8,7 +8,7 @@ use Test::More;
8use NPTest; 8use NPTest;
9use FindBin qw($Bin); 9use FindBin qw($Bin);
10 10
11my $tests = 41; 11my $tests = 53;
12# Check that all dependent modules are available 12# Check that all dependent modules are available
13eval { 13eval {
14 require NetSNMP::OID; 14 require NetSNMP::OID;
@@ -144,6 +144,31 @@ is($res->return_code, 0, "OK as no thresholds" );
144is($res->output, "SNMP RATE OK - inoctets 333 | inoctets=333 ", "Check rate decreases due to longer interval"); 144is($res->output, "SNMP RATE OK - inoctets 333 | inoctets=333 ", "Check rate decreases due to longer interval");
145 145
146 146
147# label performance data check
148$res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 -l test" );
149is($res->return_code, 0, "OK as no thresholds" );
150is($res->output, "SNMP OK - test 67996 | test=67996c ", "Check label");
151
152$res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 -l \"test'test\"" );
153is($res->return_code, 0, "OK as no thresholds" );
154is($res->output, "SNMP OK - test'test 68662 | \"test'test\"=68662c ", "Check label");
155
156$res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 -l 'test\"test'" );
157is($res->return_code, 0, "OK as no thresholds" );
158is($res->output, "SNMP OK - test\"test 69328 | 'test\"test'=69328c ", "Check label");
159
160$res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 -l test -O" );
161is($res->return_code, 0, "OK as no thresholds" );
162is($res->output, "SNMP OK - test 69994 | iso.3.6.1.4.1.8072.3.2.67.10=69994c ", "Check label");
163
164$res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10" );
165is($res->return_code, 0, "OK as no thresholds" );
166is($res->output, "SNMP OK - 70660 | iso.3.6.1.4.1.8072.3.2.67.10=70660c ", "Check label");
167
168$res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 -l 'test test'" );
169is($res->return_code, 0, "OK as no thresholds" );
170is($res->output, "SNMP OK - test test 71326 | 'test test'=71326c ", "Check label");
171
147 172
148$res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 --rate -l inoctets_per_minute --rate-multiplier=60" ); 173$res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 --rate -l inoctets_per_minute --rate-multiplier=60" );
149is($res->return_code, 0, "OK for first call" ); 174is($res->return_code, 0, "OK for first call" );
diff --git a/plugins/urlize.c b/plugins/urlize.c
index 6bb42db..30b2a35 100644
--- a/plugins/urlize.c
+++ b/plugins/urlize.c
@@ -102,7 +102,7 @@ main (int argc, char **argv)
102 102
103 cmd = strdup (argv[optind++]); 103 cmd = strdup (argv[optind++]);
104 for (c = optind; c < argc; c++) { 104 for (c = optind; c < argc; c++) {
105 asprintf (&cmd, "%s %s", cmd, argv[c]); 105 xasprintf (&cmd, "%s %s", cmd, argv[c]);
106 } 106 }
107 107
108 child_process = spopen (cmd); 108 child_process = spopen (cmd);
diff --git a/plugins/utils.c b/plugins/utils.c
index 4537390..8827e31 100644
--- a/plugins/utils.c
+++ b/plugins/utils.c
@@ -358,7 +358,7 @@ strscpy (char *dest, const char *src)
358 if (src == NULL) 358 if (src == NULL)
359 return NULL; 359 return NULL;
360 360
361 asprintf (&dest, "%s", src); 361 xasprintf (&dest, "%s", src);
362 362
363 return dest; 363 return dest;
364} 364}
@@ -513,6 +513,33 @@ strpcat (char *dest, const char *src, const char *str)
513 return dest; 513 return dest;
514} 514}
515 515
516
517/******************************************************************************
518 *
519 * asprintf, but die on failure
520 *
521 ******************************************************************************/
522
523int
524xvasprintf (char **strp, const char *fmt, va_list ap)
525{
526 int result = vasprintf (strp, fmt, ap);
527 if (result == -1 || *strp == NULL)
528 die (STATE_UNKNOWN, _("failed malloc in xvasprintf\n"));
529 return result;
530}
531
532int
533xasprintf (char **strp, const char *fmt, ...)
534{
535 va_list ap;
536 int result;
537 va_start (ap, fmt);
538 result = xvasprintf (strp, fmt, ap);
539 va_end (ap);
540 return result;
541}
542
516/****************************************************************************** 543/******************************************************************************
517 * 544 *
518 * Print perfdata in a standard format 545 * Print perfdata in a standard format
@@ -534,25 +561,25 @@ char *perfdata (const char *label,
534 char *data = NULL; 561 char *data = NULL;
535 562
536 if (strpbrk (label, "'= ")) 563 if (strpbrk (label, "'= "))
537 asprintf (&data, "'%s'=%ld%s;", label, val, uom); 564 xasprintf (&data, "'%s'=%ld%s;", label, val, uom);
538 else 565 else
539 asprintf (&data, "%s=%ld%s;", label, val, uom); 566 xasprintf (&data, "%s=%ld%s;", label, val, uom);
540 567
541 if (warnp) 568 if (warnp)
542 asprintf (&data, "%s%ld;", data, warn); 569 xasprintf (&data, "%s%ld;", data, warn);
543 else 570 else
544 asprintf (&data, "%s;", data); 571 xasprintf (&data, "%s;", data);
545 572
546 if (critp) 573 if (critp)
547 asprintf (&data, "%s%ld;", data, crit); 574 xasprintf (&data, "%s%ld;", data, crit);
548 else 575 else
549 asprintf (&data, "%s;", data); 576 xasprintf (&data, "%s;", data);
550 577
551 if (minp) 578 if (minp)
552 asprintf (&data, "%s%ld", data, minv); 579 xasprintf (&data, "%s%ld", data, minv);
553 580
554 if (maxp) 581 if (maxp)
555 asprintf (&data, "%s;%ld", data, maxv); 582 xasprintf (&data, "%s;%ld", data, maxv);
556 583
557 return data; 584 return data;
558} 585}
@@ -573,29 +600,29 @@ char *fperfdata (const char *label,
573 char *data = NULL; 600 char *data = NULL;
574 601
575 if (strpbrk (label, "'= ")) 602 if (strpbrk (label, "'= "))
576 asprintf (&data, "'%s'=", label); 603 xasprintf (&data, "'%s'=", label);
577 else 604 else
578 asprintf (&data, "%s=", label); 605 xasprintf (&data, "%s=", label);
579 606
580 asprintf (&data, "%s%f", data, val); 607 xasprintf (&data, "%s%f", data, val);
581 asprintf (&data, "%s%s;", data, uom); 608 xasprintf (&data, "%s%s;", data, uom);
582 609
583 if (warnp) 610 if (warnp)
584 asprintf (&data, "%s%f", data, warn); 611 xasprintf (&data, "%s%f", data, warn);
585 612
586 asprintf (&data, "%s;", data); 613 xasprintf (&data, "%s;", data);
587 614
588 if (critp) 615 if (critp)
589 asprintf (&data, "%s%f", data, crit); 616 xasprintf (&data, "%s%f", data, crit);
590 617
591 asprintf (&data, "%s;", data); 618 xasprintf (&data, "%s;", data);
592 619
593 if (minp) 620 if (minp)
594 asprintf (&data, "%s%f", data, minv); 621 xasprintf (&data, "%s%f", data, minv);
595 622
596 if (maxp) { 623 if (maxp) {
597 asprintf (&data, "%s;", data); 624 xasprintf (&data, "%s;", data);
598 asprintf (&data, "%s%f", data, maxv); 625 xasprintf (&data, "%s%f", data, maxv);
599 } 626 }
600 627
601 return data; 628 return data;
diff --git a/plugins/utils.h b/plugins/utils.h
index 3c3f189..822be94 100644
--- a/plugins/utils.h
+++ b/plugins/utils.h
@@ -81,6 +81,8 @@ char *strscpy (char *, const char *);
81char *strnl (char *); 81char *strnl (char *);
82char *strpcpy (char *, const char *, const char *); 82char *strpcpy (char *, const char *, const char *);
83char *strpcat (char *, const char *, const char *); 83char *strpcat (char *, const char *, const char *);
84int xvasprintf (char **strp, const char *fmt, va_list ap);
85int xasprintf (char **strp, const char *fmt, ...);
84 86
85int max_state (int a, int b); 87int max_state (int a, int b);
86int max_state_alt (int a, int b); 88int max_state_alt (int a, int b);