summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/check_apt.c19
-rw-r--r--plugins/check_by_ssh.c15
-rw-r--r--plugins/check_curl.c13
-rw-r--r--plugins/check_dns.c6
-rw-r--r--plugins/check_http.c2
-rw-r--r--plugins/check_procs.c4
-rw-r--r--plugins/check_smtp.c11
-rw-r--r--plugins/check_snmp.c35
-rw-r--r--plugins/check_tcp.c27
-rw-r--r--plugins/check_ups.c50
-rw-r--r--plugins/check_users.c21
-rw-r--r--plugins/negate.c5
-rw-r--r--plugins/runcmd.c3
-rw-r--r--plugins/t/check_users.t5
-rw-r--r--plugins/utils.c10
15 files changed, 144 insertions, 82 deletions
diff --git a/plugins/check_apt.c b/plugins/check_apt.c
index fa982ae..5c0f6e2 100644
--- a/plugins/check_apt.c
+++ b/plugins/check_apt.c
@@ -94,7 +94,7 @@ static int stderr_warning = 0; /* if a cmd issued output on stderr */
94static int exec_warning = 0; /* if a cmd exited non-zero */ 94static int exec_warning = 0; /* if a cmd exited non-zero */
95 95
96int main (int argc, char **argv) { 96int main (int argc, char **argv) {
97 int result=STATE_UNKNOWN, packages_available=0, sec_count=0, i=0; 97 int result=STATE_UNKNOWN, packages_available=0, sec_count=0;
98 char **packages_list=NULL, **secpackages_list=NULL; 98 char **packages_list=NULL, **secpackages_list=NULL;
99 99
100 /* Parse extra opts if any */ 100 /* Parse extra opts if any */
@@ -142,10 +142,11 @@ int main (int argc, char **argv) {
142 qsort(secpackages_list, sec_count, sizeof(char*), cmpstringp); 142 qsort(secpackages_list, sec_count, sizeof(char*), cmpstringp);
143 qsort(packages_list, packages_available-sec_count, sizeof(char*), cmpstringp); 143 qsort(packages_list, packages_available-sec_count, sizeof(char*), cmpstringp);
144 144
145 for(i = 0; i < sec_count; i++) 145 for(int i = 0; i < sec_count; i++)
146 printf("%s (security)\n", secpackages_list[i]); 146 printf("%s (security)\n", secpackages_list[i]);
147
147 if (only_critical == false) { 148 if (only_critical == false) {
148 for(i = 0; i < packages_available - sec_count; i++) 149 for(int i = 0; i < packages_available - sec_count; i++)
149 printf("%s\n", packages_list[i]); 150 printf("%s\n", packages_list[i]);
150 } 151 }
151 } 152 }
@@ -251,7 +252,7 @@ int process_arguments (int argc, char **argv) {
251 252
252/* run an apt-get upgrade */ 253/* run an apt-get upgrade */
253int run_upgrade(int *pkgcount, int *secpkgcount, char ***pkglist, char ***secpkglist){ 254int run_upgrade(int *pkgcount, int *secpkgcount, char ***pkglist, char ***secpkglist){
254 int i=0, result=STATE_UNKNOWN, regres=0, pc=0, spc=0; 255 int result=STATE_UNKNOWN, regres=0, pc=0, spc=0;
255 struct output chld_out, chld_err; 256 struct output chld_out, chld_err;
256 regex_t ireg, ereg, sreg; 257 regex_t ireg, ereg, sreg;
257 char *cmdline=NULL, rerrbuf[64]; 258 char *cmdline=NULL, rerrbuf[64];
@@ -320,7 +321,7 @@ int run_upgrade(int *pkgcount, int *secpkgcount, char ***pkglist, char ***secpkg
320 * we may need to switch to the --print-uris output format, 321 * we may need to switch to the --print-uris output format,
321 * in which case the logic here will slightly change. 322 * in which case the logic here will slightly change.
322 */ 323 */
323 for(i = 0; i < chld_out.lines; i++) { 324 for(size_t i = 0; i < chld_out.lines; i++) {
324 if(verbose){ 325 if(verbose){
325 printf("%s\n", chld_out.line[i]); 326 printf("%s\n", chld_out.line[i]);
326 } 327 }
@@ -353,7 +354,7 @@ int run_upgrade(int *pkgcount, int *secpkgcount, char ***pkglist, char ***secpkg
353 stderr_warning=1; 354 stderr_warning=1;
354 result = max_state(result, STATE_WARNING); 355 result = max_state(result, STATE_WARNING);
355 if(verbose){ 356 if(verbose){
356 for(i = 0; i < chld_err.lines; i++) { 357 for(size_t i = 0; i < chld_err.lines; i++) {
357 fprintf(stderr, "%s\n", chld_err.line[i]); 358 fprintf(stderr, "%s\n", chld_err.line[i]);
358 } 359 }
359 } 360 }
@@ -367,7 +368,7 @@ int run_upgrade(int *pkgcount, int *secpkgcount, char ***pkglist, char ***secpkg
367 368
368/* run an apt-get update (needs root) */ 369/* run an apt-get update (needs root) */
369int run_update(void){ 370int run_update(void){
370 int i=0, result=STATE_UNKNOWN; 371 int result=STATE_UNKNOWN;
371 struct output chld_out, chld_err; 372 struct output chld_out, chld_err;
372 char *cmdline; 373 char *cmdline;
373 374
@@ -385,7 +386,7 @@ int run_update(void){
385 } 386 }
386 387
387 if(verbose){ 388 if(verbose){
388 for(i = 0; i < chld_out.lines; i++) { 389 for(size_t i = 0; i < chld_out.lines; i++) {
389 printf("%s\n", chld_out.line[i]); 390 printf("%s\n", chld_out.line[i]);
390 } 391 }
391 } 392 }
@@ -395,7 +396,7 @@ int run_update(void){
395 stderr_warning=1; 396 stderr_warning=1;
396 result = max_state(result, STATE_WARNING); 397 result = max_state(result, STATE_WARNING);
397 if(verbose){ 398 if(verbose){
398 for(i = 0; i < chld_err.lines; i++) { 399 for(size_t i = 0; i < chld_err.lines; i++) {
399 fprintf(stderr, "%s\n", chld_err.line[i]); 400 fprintf(stderr, "%s\n", chld_err.line[i]);
400 } 401 }
401 } 402 }
diff --git a/plugins/check_by_ssh.c b/plugins/check_by_ssh.c
index 1f5f72d..2a23b39 100644
--- a/plugins/check_by_ssh.c
+++ b/plugins/check_by_ssh.c
@@ -68,7 +68,6 @@ main (int argc, char **argv)
68 char *status_text; 68 char *status_text;
69 int cresult; 69 int cresult;
70 int result = STATE_UNKNOWN; 70 int result = STATE_UNKNOWN;
71 int i;
72 time_t local_time; 71 time_t local_time;
73 FILE *fp = NULL; 72 FILE *fp = NULL;
74 output chld_out, chld_err; 73 output chld_out, chld_err;
@@ -96,7 +95,7 @@ main (int argc, char **argv)
96 /* run the command */ 95 /* run the command */
97 if (verbose) { 96 if (verbose) {
98 printf ("Command: %s\n", commargv[0]); 97 printf ("Command: %s\n", commargv[0]);
99 for (i=1; i<commargc; i++) 98 for (int i = 1; i < commargc; i++)
100 printf ("Argument %i: %s\n", i, commargv[i]); 99 printf ("Argument %i: %s\n", i, commargv[i]);
101 } 100 }
102 101
@@ -110,9 +109,9 @@ main (int argc, char **argv)
110 } 109 }
111 110
112 if (verbose) { 111 if (verbose) {
113 for(i = 0; i < chld_out.lines; i++) 112 for(size_t i = 0; i < chld_out.lines; i++)
114 printf("stdout: %s\n", chld_out.line[i]); 113 printf("stdout: %s\n", chld_out.line[i]);
115 for(i = 0; i < chld_err.lines; i++) 114 for(size_t i = 0; i < chld_err.lines; i++)
116 printf("stderr: %s\n", chld_err.line[i]); 115 printf("stderr: %s\n", chld_err.line[i]);
117 } 116 }
118 117
@@ -122,7 +121,7 @@ main (int argc, char **argv)
122 skip_stderr = chld_err.lines; 121 skip_stderr = chld_err.lines;
123 122
124 /* UNKNOWN or worse if (non-skipped) output found on stderr */ 123 /* UNKNOWN or worse if (non-skipped) output found on stderr */
125 if(chld_err.lines > skip_stderr) { 124 if(chld_err.lines > (size_t)skip_stderr) {
126 printf (_("Remote command execution failed: %s\n"), 125 printf (_("Remote command execution failed: %s\n"),
127 chld_err.line[skip_stderr]); 126 chld_err.line[skip_stderr]);
128 if ( warn_on_stderr ) 127 if ( warn_on_stderr )
@@ -134,8 +133,8 @@ main (int argc, char **argv)
134 /* this is simple if we're not supposed to be passive. 133 /* this is simple if we're not supposed to be passive.
135 * Wrap up quickly and keep the tricks below */ 134 * Wrap up quickly and keep the tricks below */
136 if(!passive) { 135 if(!passive) {
137 if (chld_out.lines > skip_stdout) 136 if (chld_out.lines > (size_t)skip_stdout)
138 for (i = skip_stdout; i < chld_out.lines; i++) 137 for (size_t i = skip_stdout; i < chld_out.lines; i++)
139 puts (chld_out.line[i]); 138 puts (chld_out.line[i]);
140 else 139 else
141 printf (_("%s - check_by_ssh: Remote command '%s' returned status %d\n"), 140 printf (_("%s - check_by_ssh: Remote command '%s' returned status %d\n"),
@@ -156,7 +155,7 @@ main (int argc, char **argv)
156 155
157 local_time = time (NULL); 156 local_time = time (NULL);
158 commands = 0; 157 commands = 0;
159 for(i = skip_stdout; i < chld_out.lines; i++) { 158 for(size_t i = skip_stdout; i < chld_out.lines; i++) {
160 status_text = chld_out.line[i++]; 159 status_text = chld_out.line[i++];
161 if (i == chld_out.lines || strstr (chld_out.line[i], "STATUS CODE: ") == NULL) 160 if (i == chld_out.lines || strstr (chld_out.line[i], "STATUS CODE: ") == NULL)
162 die (STATE_UNKNOWN, _("%s: Error parsing output\n"), progname); 161 die (STATE_UNKNOWN, _("%s: Error parsing output\n"), progname);
diff --git a/plugins/check_curl.c b/plugins/check_curl.c
index c59fa7e..8f9a21d 100644
--- a/plugins/check_curl.c
+++ b/plugins/check_curl.c
@@ -1186,16 +1186,16 @@ int
1186uri_strcmp (const UriTextRangeA range, const char* s) 1186uri_strcmp (const UriTextRangeA range, const char* s)
1187{ 1187{
1188 if (!range.first) return -1; 1188 if (!range.first) return -1;
1189 if (range.afterLast - range.first < strlen (s)) return -1; 1189 if ( (size_t)(range.afterLast - range.first) < strlen (s) ) return -1;
1190 return strncmp (s, range.first, min( range.afterLast - range.first, strlen (s))); 1190 return strncmp (s, range.first, min( (size_t)(range.afterLast - range.first), strlen (s)));
1191} 1191}
1192 1192
1193char* 1193char*
1194uri_string (const UriTextRangeA range, char* buf, size_t buflen) 1194uri_string (const UriTextRangeA range, char* buf, size_t buflen)
1195{ 1195{
1196 if (!range.first) return "(null)"; 1196 if (!range.first) return "(null)";
1197 strncpy (buf, range.first, max (buflen-1, range.afterLast - range.first)); 1197 strncpy (buf, range.first, max (buflen-1, (size_t)(range.afterLast - range.first)));
1198 buf[max (buflen-1, range.afterLast - range.first)] = '\0'; 1198 buf[max (buflen-1, (size_t)(range.afterLast - range.first))] = '\0';
1199 buf[range.afterLast - range.first] = '\0'; 1199 buf[range.afterLast - range.first] = '\0';
1200 return buf; 1200 return buf;
1201} 1201}
@@ -2368,8 +2368,7 @@ remove_newlines (char *s)
2368char * 2368char *
2369get_header_value (const struct phr_header* headers, const size_t nof_headers, const char* header) 2369get_header_value (const struct phr_header* headers, const size_t nof_headers, const char* header)
2370{ 2370{
2371 int i; 2371 for(size_t i = 0; i < nof_headers; i++ ) {
2372 for( i = 0; i < nof_headers; i++ ) {
2373 if(headers[i].name != NULL && strncasecmp( header, headers[i].name, max( headers[i].name_len, 4 ) ) == 0 ) { 2372 if(headers[i].name != NULL && strncasecmp( header, headers[i].name, max( headers[i].name_len, 4 ) ) == 0 ) {
2374 return strndup( headers[i].value, headers[i].value_len ); 2373 return strndup( headers[i].value, headers[i].value_len );
2375 } 2374 }
@@ -2471,7 +2470,7 @@ check_document_dates (const curlhelp_write_curlbuf *header_buf, char (*msg)[DEFA
2471int 2470int
2472get_content_length (const curlhelp_write_curlbuf* header_buf, const curlhelp_write_curlbuf* body_buf) 2471get_content_length (const curlhelp_write_curlbuf* header_buf, const curlhelp_write_curlbuf* body_buf)
2473{ 2472{
2474 int content_length = 0; 2473 size_t content_length = 0;
2475 struct phr_header headers[255]; 2474 struct phr_header headers[255];
2476 size_t nof_headers = 255; 2475 size_t nof_headers = 255;
2477 size_t msglen; 2476 size_t msglen;
diff --git a/plugins/check_dns.c b/plugins/check_dns.c
index 82dc264..5e20214 100644
--- a/plugins/check_dns.c
+++ b/plugins/check_dns.c
@@ -122,7 +122,7 @@ main (int argc, char **argv)
122 } 122 }
123 123
124 /* scan stdout */ 124 /* scan stdout */
125 for(i = 0; i < chld_out.lines; i++) { 125 for(size_t i = 0; i < chld_out.lines; i++) {
126 if (addresses == NULL) 126 if (addresses == NULL)
127 addresses = malloc(sizeof(*addresses)*10); 127 addresses = malloc(sizeof(*addresses)*10);
128 else if (!(n_addresses % 10)) 128 else if (!(n_addresses % 10))
@@ -197,7 +197,7 @@ main (int argc, char **argv)
197 } 197 }
198 198
199 /* scan stderr */ 199 /* scan stderr */
200 for(i = 0; i < chld_err.lines; i++) { 200 for(size_t i = 0; i < chld_err.lines; i++) {
201 if (verbose) 201 if (verbose)
202 puts(chld_err.line[i]); 202 puts(chld_err.line[i]);
203 203
@@ -241,7 +241,7 @@ main (int argc, char **argv)
241 unsigned long expect_match = (1 << expected_address_cnt) - 1; 241 unsigned long expect_match = (1 << expected_address_cnt) - 1;
242 unsigned long addr_match = (1 << n_addresses) - 1; 242 unsigned long addr_match = (1 << n_addresses) - 1;
243 243
244 for (i=0; i<expected_address_cnt; i++) { 244 for (int i=0; i<expected_address_cnt; i++) {
245 int j; 245 int j;
246 /* check if we get a match on 'raw' ip or cidr */ 246 /* check if we get a match on 'raw' ip or cidr */
247 for (j=0; j<n_addresses; j++) { 247 for (j=0; j<n_addresses; j++) {
diff --git a/plugins/check_http.c b/plugins/check_http.c
index b9d8145..110f118 100644
--- a/plugins/check_http.c
+++ b/plugins/check_http.c
@@ -471,7 +471,7 @@ bool process_arguments (int argc, char **argv)
471 free(http_method); 471 free(http_method);
472 http_method = strdup (optarg); 472 http_method = strdup (optarg);
473 char *tmp; 473 char *tmp;
474 if ((tmp = strstr(http_method, ":")) > 0) { 474 if ((tmp = strstr(http_method, ":")) != NULL) {
475 tmp[0] = '\0'; 475 tmp[0] = '\0';
476 http_method = http_method; 476 http_method = http_method;
477 http_method_proxy = ++tmp; 477 http_method_proxy = ++tmp;
diff --git a/plugins/check_procs.c b/plugins/check_procs.c
index 1637e3e..6e3feae 100644
--- a/plugins/check_procs.c
+++ b/plugins/check_procs.c
@@ -153,7 +153,7 @@ main (int argc, char **argv)
153 int expected_cols = PS_COLS - 1; 153 int expected_cols = PS_COLS - 1;
154 int warn = 0; /* number of processes in warn state */ 154 int warn = 0; /* number of processes in warn state */
155 int crit = 0; /* number of processes in crit state */ 155 int crit = 0; /* number of processes in crit state */
156 int i = 0, j = 0; 156 int i = 0;
157 int result = STATE_UNKNOWN; 157 int result = STATE_UNKNOWN;
158 int ret = 0; 158 int ret = 0;
159 output chld_out, chld_err; 159 output chld_out, chld_err;
@@ -207,7 +207,7 @@ main (int argc, char **argv)
207 } 207 }
208 208
209 /* flush first line: j starts at 1 */ 209 /* flush first line: j starts at 1 */
210 for (j = 1; j < chld_out.lines; j++) { 210 for (size_t j = 1; j < chld_out.lines; j++) {
211 input_line = chld_out.line[j]; 211 input_line = chld_out.line[j];
212 212
213 if (verbose >= 3) 213 if (verbose >= 3)
diff --git a/plugins/check_smtp.c b/plugins/check_smtp.c
index d1c2466..986c3e1 100644
--- a/plugins/check_smtp.c
+++ b/plugins/check_smtp.c
@@ -480,6 +480,8 @@ process_arguments (int argc, char **argv)
480 int c; 480 int c;
481 char* temp; 481 char* temp;
482 482
483 bool implicit_tls = false;
484
483 enum { 485 enum {
484 SNI_OPTION 486 SNI_OPTION
485 }; 487 };
@@ -650,6 +652,8 @@ process_arguments (int argc, char **argv)
650#else 652#else
651 usage (_("SSL support not available - install OpenSSL and recompile")); 653 usage (_("SSL support not available - install OpenSSL and recompile"));
652#endif 654#endif
655 implicit_tls = true;
656 // fallthrough
653 case 's': 657 case 's':
654 /* ssl */ 658 /* ssl */
655 use_ssl = true; 659 use_ssl = true;
@@ -717,7 +721,12 @@ process_arguments (int argc, char **argv)
717 from_arg = strdup(" "); 721 from_arg = strdup(" ");
718 722
719 if (use_starttls && use_ssl) { 723 if (use_starttls && use_ssl) {
720 usage4 (_("Set either -s/--ssl/--tls or -S/--starttls")); 724 if (implicit_tls) {
725 use_ssl = false;
726 server_port = SMTP_PORT;
727 } else {
728 usage4 (_("Set either -s/--ssl/--tls or -S/--starttls"));
729 }
721 } 730 }
722 731
723 if (server_port_option != 0) { 732 if (server_port_option != 0) {
diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c
index 405ede3..7ee9d0c 100644
--- a/plugins/check_snmp.c
+++ b/plugins/check_snmp.c
@@ -131,7 +131,7 @@ size_t nlabels = 0;
131size_t labels_size = OID_COUNT_STEP; 131size_t labels_size = OID_COUNT_STEP;
132size_t nunits = 0; 132size_t nunits = 0;
133size_t unitv_size = OID_COUNT_STEP; 133size_t unitv_size = OID_COUNT_STEP;
134int numoids = 0; 134size_t numoids = 0;
135int numauthpriv = 0; 135int numauthpriv = 0;
136int numcontext = 0; 136int numcontext = 0;
137int verbose = 0; 137int verbose = 0;
@@ -187,7 +187,8 @@ static char *fix_snmp_range(char *th)
187int 187int
188main (int argc, char **argv) 188main (int argc, char **argv)
189{ 189{
190 int i, len, line, total_oids; 190 int len, total_oids;
191 size_t line;
191 unsigned int bk_count = 0, dq_count = 0; 192 unsigned int bk_count = 0, dq_count = 0;
192 int iresult = STATE_UNKNOWN; 193 int iresult = STATE_UNKNOWN;
193 int result = STATE_UNKNOWN; 194 int result = STATE_UNKNOWN;
@@ -253,14 +254,16 @@ main (int argc, char **argv)
253 if(calculate_rate) { 254 if(calculate_rate) {
254 if (!strcmp(label, "SNMP")) 255 if (!strcmp(label, "SNMP"))
255 label = strdup("SNMP RATE"); 256 label = strdup("SNMP RATE");
256 i=0; 257
258 size_t i = 0;
259
257 previous_state = np_state_read(); 260 previous_state = np_state_read();
258 if(previous_state!=NULL) { 261 if(previous_state!=NULL) {
259 /* Split colon separated values */ 262 /* Split colon separated values */
260 previous_string = strdup((char *) previous_state->data); 263 previous_string = strdup((char *) previous_state->data);
261 while((ap = strsep(&previous_string, ":")) != NULL) { 264 while((ap = strsep(&previous_string, ":")) != NULL) {
262 if(verbose>2) 265 if(verbose>2)
263 printf("State for %d=%s\n", i, ap); 266 printf("State for %zd=%s\n", i, ap);
264 while (i >= previous_size) { 267 while (i >= previous_size) {
265 previous_size += OID_COUNT_STEP; 268 previous_size += OID_COUNT_STEP;
266 previous_value = realloc(previous_value, previous_size * sizeof(*previous_value)); 269 previous_value = realloc(previous_value, previous_size * sizeof(*previous_value));
@@ -273,7 +276,7 @@ main (int argc, char **argv)
273 /* Populate the thresholds */ 276 /* Populate the thresholds */
274 th_warn=warning_thresholds; 277 th_warn=warning_thresholds;
275 th_crit=critical_thresholds; 278 th_crit=critical_thresholds;
276 for (i=0; i<numoids; i++) { 279 for (size_t i = 0; i < numoids; i++) {
277 char *w = th_warn ? strndup(th_warn, strcspn(th_warn, ",")) : NULL; 280 char *w = th_warn ? strndup(th_warn, strcspn(th_warn, ",")) : NULL;
278 char *c = th_crit ? strndup(th_crit, strcspn(th_crit, ",")) : NULL; 281 char *c = th_crit ? strndup(th_crit, strcspn(th_crit, ",")) : NULL;
279 /* translate "2:1" to "@1:2" for backwards compatibility */ 282 /* translate "2:1" to "@1:2" for backwards compatibility */
@@ -333,11 +336,11 @@ main (int argc, char **argv)
333 } 336 }
334 337
335 338
336 for (i = 0; i < numcontext; i++) { 339 for (int i = 0; i < numcontext; i++) {
337 command_line[index++] = contextargs[i]; 340 command_line[index++] = contextargs[i];
338 } 341 }
339 342
340 for (i = 0; i < numauthpriv; i++) { 343 for (int i = 0; i < numauthpriv; i++) {
341 command_line[index++] = authpriv[i]; 344 command_line[index++] = authpriv[i];
342 } 345 }
343 346
@@ -348,7 +351,7 @@ main (int argc, char **argv)
348 server_address, 351 server_address,
349 port); 352 port);
350 353
351 for (i = 0; i < numoids; i++) { 354 for (size_t i = 0; i < numoids; i++) {
352 command_line[index++] = oids[i]; 355 command_line[index++] = oids[i];
353 xasprintf(&cl_hidden_auth, "%s %s", cl_hidden_auth, oids[i]); 356 xasprintf(&cl_hidden_auth, "%s %s", cl_hidden_auth, oids[i]);
354 } 357 }
@@ -382,7 +385,7 @@ main (int argc, char **argv)
382 if (external_error) { 385 if (external_error) {
383 if (chld_err.lines > 0) { 386 if (chld_err.lines > 0) {
384 printf (_("External command error: %s\n"), chld_err.line[0]); 387 printf (_("External command error: %s\n"), chld_err.line[0]);
385 for (i = 1; i < chld_err.lines; i++) { 388 for (size_t i = 1; i < chld_err.lines; i++) {
386 printf ("%s\n", chld_err.line[i]); 389 printf ("%s\n", chld_err.line[i]);
387 } 390 }
388 } else { 391 } else {
@@ -392,12 +395,14 @@ main (int argc, char **argv)
392 } 395 }
393 396
394 if (verbose) { 397 if (verbose) {
395 for (i = 0; i < chld_out.lines; i++) { 398 for (size_t i = 0; i < chld_out.lines; i++) {
396 printf ("%s\n", chld_out.line[i]); 399 printf ("%s\n", chld_out.line[i]);
397 } 400 }
398 } 401 }
399 402
400 for (line=0, i=0; line < chld_out.lines && i < numoids ; line++, i++) { 403 line = 0;
404 total_oids = 0;
405 for (size_t i = 0; line < chld_out.lines && i < numoids ; line++, i++, total_oids++) {
401 if(calculate_rate) 406 if(calculate_rate)
402 conv = "%.10g"; 407 conv = "%.10g";
403 else 408 else
@@ -410,7 +415,7 @@ main (int argc, char **argv)
410 break; 415 break;
411 416
412 if (verbose > 2) { 417 if (verbose > 2) {
413 printf("Processing oid %i (line %i)\n oidname: %s\n response: %s\n", i+1, line+1, oidname, response); 418 printf("Processing oid %zi (line %zi)\n oidname: %s\n response: %s\n", i+1, line+1, oidname, response);
414 } 419 }
415 420
416 /* Clean up type array - Sol10 does not necessarily zero it out */ 421 /* Clean up type array - Sol10 does not necessarily zero it out */
@@ -634,7 +639,6 @@ main (int argc, char **argv)
634 strncat(perfstr, " ", sizeof(perfstr)-strlen(perfstr)-1); 639 strncat(perfstr, " ", sizeof(perfstr)-strlen(perfstr)-1);
635 } 640 }
636 } 641 }
637 total_oids=i;
638 642
639 /* Save state data, as all data collected now */ 643 /* Save state data, as all data collected now */
640 if(calculate_rate) { 644 if(calculate_rate) {
@@ -644,7 +648,7 @@ main (int argc, char **argv)
644 die(STATE_UNKNOWN, _("Cannot malloc")); 648 die(STATE_UNKNOWN, _("Cannot malloc"));
645 649
646 current_length=0; 650 current_length=0;
647 for(i=0; i<total_oids; i++) { 651 for(int i = 0; i < total_oids; i++) {
648 xasprintf(&temp_string,"%.0f",response_value[i]); 652 xasprintf(&temp_string,"%.0f",response_value[i]);
649 if(temp_string==NULL) 653 if(temp_string==NULL)
650 die(STATE_UNKNOWN,_("Cannot asprintf()")); 654 die(STATE_UNKNOWN,_("Cannot asprintf()"));
@@ -687,7 +691,8 @@ process_arguments (int argc, char **argv)
687{ 691{
688 char *ptr; 692 char *ptr;
689 int c = 1; 693 int c = 1;
690 int j = 0, jj = 0, ii = 0; 694 int ii = 0;
695 size_t j = 0, jj = 0;
691 696
692 int option = 0; 697 int option = 0;
693 static struct option longopts[] = { 698 static struct option longopts[] = {
diff --git a/plugins/check_tcp.c b/plugins/check_tcp.c
index a1a14b4..01dd35e 100644
--- a/plugins/check_tcp.c
+++ b/plugins/check_tcp.c
@@ -70,7 +70,7 @@ static char *server_send = NULL;
70static char *server_quit = NULL; 70static char *server_quit = NULL;
71static char **server_expect; 71static char **server_expect;
72static size_t server_expect_count = 0; 72static size_t server_expect_count = 0;
73static size_t maxbytes = 0; 73static ssize_t maxbytes = 0;
74static char **warn_codes = NULL; 74static char **warn_codes = NULL;
75static size_t warn_codes_count = 0; 75static size_t warn_codes_count = 0;
76static char **crit_codes = NULL; 76static char **crit_codes = NULL;
@@ -102,11 +102,9 @@ int
102main (int argc, char **argv) 102main (int argc, char **argv)
103{ 103{
104 int result = STATE_UNKNOWN; 104 int result = STATE_UNKNOWN;
105 int i;
106 char *status = NULL; 105 char *status = NULL;
107 struct timeval tv; 106 struct timeval tv;
108 struct timeval timeout; 107 struct timeval timeout;
109 size_t len;
110 int match = -1; 108 int match = -1;
111 fd_set rfds; 109 fd_set rfds;
112 110
@@ -121,10 +119,10 @@ main (int argc, char **argv)
121 if(progname != NULL) progname++; 119 if(progname != NULL) progname++;
122 else progname = argv[0]; 120 else progname = argv[0];
123 121
124 len = strlen(progname); 122 size_t prog_name_len = strlen(progname);
125 if(len > 6 && !memcmp(progname, "check_", 6)) { 123 if(prog_name_len > 6 && !memcmp(progname, "check_", 6)) {
126 SERVICE = strdup(progname + 6); 124 SERVICE = strdup(progname + 6);
127 for(i = 0; i < len - 6; i++) 125 for(size_t i = 0; i < prog_name_len - 6; i++)
128 SERVICE[i] = toupper(SERVICE[i]); 126 SERVICE[i] = toupper(SERVICE[i]);
129 } 127 }
130 128
@@ -275,19 +273,21 @@ main (int argc, char **argv)
275 printf("Quit string: %s\n", server_quit); 273 printf("Quit string: %s\n", server_quit);
276 } 274 }
277 printf("server_expect_count: %d\n", (int)server_expect_count); 275 printf("server_expect_count: %d\n", (int)server_expect_count);
278 for(i = 0; i < server_expect_count; i++) 276 for(size_t i = 0; i < server_expect_count; i++)
279 printf("\t%d: %s\n", i, server_expect[i]); 277 printf("\t%zd: %s\n", i, server_expect[i]);
280 } 278 }
281 279
282 /* if(len) later on, we know we have a non-NULL response */ 280 /* if(len) later on, we know we have a non-NULL response */
283 len = 0; 281 ssize_t len = 0;
282
284 if (server_expect_count) { 283 if (server_expect_count) {
284 ssize_t received = 0;
285 285
286 /* watch for the expect string */ 286 /* watch for the expect string */
287 while ((i = my_recv(buffer, sizeof(buffer))) > 0) { 287 while ((received = my_recv(buffer, sizeof(buffer))) > 0) {
288 status = realloc(status, len + i + 1); 288 status = realloc(status, len + received + 1);
289 memcpy(&status[len], buffer, i); 289 memcpy(&status[len], buffer, received);
290 len += i; 290 len += received;
291 status[len] = '\0'; 291 status[len] = '\0';
292 292
293 /* stop reading if user-forced */ 293 /* stop reading if user-forced */
@@ -307,6 +307,7 @@ main (int argc, char **argv)
307 if(select(sd + 1, &rfds, NULL, NULL, &timeout) <= 0) 307 if(select(sd + 1, &rfds, NULL, NULL, &timeout) <= 0)
308 break; 308 break;
309 } 309 }
310
310 if (match == NP_MATCH_RETRY) 311 if (match == NP_MATCH_RETRY)
311 match = NP_MATCH_FAILURE; 312 match = NP_MATCH_FAILURE;
312 313
diff --git a/plugins/check_ups.c b/plugins/check_ups.c
index d1ded62..2fb04ee 100644
--- a/plugins/check_ups.c
+++ b/plugins/check_ups.c
@@ -46,12 +46,13 @@ enum {
46 46
47#define CHECK_NONE 0 47#define CHECK_NONE 0
48 48
49#define UPS_NONE 0 /* no supported options */ 49#define UPS_NONE 0 /* no supported options */
50#define UPS_UTILITY 1 /* supports utility line voltage */ 50#define UPS_UTILITY 1 /* supports utility line */
51#define UPS_BATTPCT 2 /* supports percent battery remaining */ 51#define UPS_BATTPCT 2 /* supports percent battery remaining */
52#define UPS_STATUS 4 /* supports UPS status */ 52#define UPS_STATUS 4 /* supports UPS status */
53#define UPS_TEMP 8 /* supports UPS temperature */ 53#define UPS_TEMP 8 /* supports UPS temperature */
54#define UPS_LOADPCT 16 /* supports load percent */ 54#define UPS_LOADPCT 16 /* supports load percent */
55#define UPS_REALPOWER 32 /* supports real power */
55 56
56#define UPSSTATUS_NONE 0 57#define UPSSTATUS_NONE 0
57#define UPSSTATUS_OFF 1 58#define UPSSTATUS_OFF 1
@@ -85,6 +86,7 @@ double ups_utility_voltage = 0.0;
85double ups_battery_percent = 0.0; 86double ups_battery_percent = 0.0;
86double ups_load_percent = 0.0; 87double ups_load_percent = 0.0;
87double ups_temperature = 0.0; 88double ups_temperature = 0.0;
89double ups_realpower = 0.0;
88char *ups_status; 90char *ups_status;
89bool temp_output_c = false; 91bool temp_output_c = false;
90 92
@@ -318,6 +320,35 @@ main (int argc, char **argv)
318 } 320 }
319 } 321 }
320 322
323 /* get the ups real power if possible */
324 res=get_ups_variable ("ups.realpower", temp_buffer);
325 if ( res == NOSUCHVAR ) supported_options &= ~UPS_REALPOWER;
326 else if ( res != OK)
327 return STATE_CRITICAL;
328 else {
329 supported_options |= UPS_REALPOWER;
330 ups_realpower = atof (temp_buffer);
331 xasprintf (&message, "%sReal power=%3.1fW ", message, ups_realpower);
332
333 if (check_variable == UPS_REALPOWER) {
334 if (check_crit && ups_realpower>=critical_value) {
335 result = STATE_CRITICAL;
336 }
337 else if (check_warn && ups_realpower>=warning_value) {
338 result = max_state (result, STATE_WARNING);
339 }
340 xasprintf (&data, "%s %s", data,
341 perfdata ("realpower", (long)ups_realpower, "W",
342 check_warn, (long)(warning_value),
343 check_crit, (long)(critical_value),
344 true, 0, false, 0));
345 } else {
346 xasprintf (&data, "%s %s", data,
347 perfdata ("realpower", (long)ups_realpower, "W",
348 false, 0, false, 0, true, 0, false, 0));
349 }
350 }
351
321 /* if the UPS does not support any options we are looking for, report an error */ 352 /* if the UPS does not support any options we are looking for, report an error */
322 if (supported_options == UPS_NONE) { 353 if (supported_options == UPS_NONE) {
323 result = STATE_CRITICAL; 354 result = STATE_CRITICAL;
@@ -402,7 +433,8 @@ get_ups_variable (const char *varname, char *buf)
402 433
403 /* create the command string to send to the UPS daemon */ 434 /* create the command string to send to the UPS daemon */
404 /* Add LOGOUT to avoid read failure logs */ 435 /* Add LOGOUT to avoid read failure logs */
405 if (snprintf (send_buffer, sizeof(send_buffer), "GET VAR %s %s\nLOGOUT\n", ups_name, varname) >= sizeof(send_buffer)) { 436 int res = snprintf (send_buffer, sizeof(send_buffer), "GET VAR %s %s\nLOGOUT\n", ups_name, varname);
437 if ( (res > 0) && ((size_t)res >= sizeof(send_buffer))) {
406 printf("%s\n", _("UPS name to long for buffer")); 438 printf("%s\n", _("UPS name to long for buffer"));
407 return ERROR; 439 return ERROR;
408 } 440 }
@@ -548,6 +580,8 @@ process_arguments (int argc, char **argv)
548 check_variable = UPS_BATTPCT; 580 check_variable = UPS_BATTPCT;
549 else if (!strcmp (optarg, "LOADPCT")) 581 else if (!strcmp (optarg, "LOADPCT"))
550 check_variable = UPS_LOADPCT; 582 check_variable = UPS_LOADPCT;
583 else if (!strcmp (optarg, "REALPOWER"))
584 check_variable = UPS_REALPOWER;
551 else 585 else
552 usage2 (_("Unrecognized UPS variable"), optarg); 586 usage2 (_("Unrecognized UPS variable"), optarg);
553 break; 587 break;
@@ -624,7 +658,7 @@ print_help (void)
624 printf (" %s\n", "-T, --temperature"); 658 printf (" %s\n", "-T, --temperature");
625 printf (" %s\n", _("Output of temperatures in Celsius")); 659 printf (" %s\n", _("Output of temperatures in Celsius"));
626 printf (" %s\n", "-v, --variable=STRING"); 660 printf (" %s\n", "-v, --variable=STRING");
627 printf (" %s %s\n", _("Valid values for STRING are"), "LINE, TEMP, BATTPCT or LOADPCT"); 661 printf (" %s %s\n", _("Valid values for STRING are"), "LINE, TEMP, BATTPCT, LOADPCT or REALPOWER");
628 662
629 printf (UT_WARN_CRIT); 663 printf (UT_WARN_CRIT);
630 664
diff --git a/plugins/check_users.c b/plugins/check_users.c
index 7cf7a2c..89b9536 100644
--- a/plugins/check_users.c
+++ b/plugins/check_users.c
@@ -227,18 +227,23 @@ process_arguments (int argc, char **argv)
227 } 227 }
228 228
229 c = optind; 229 c = optind;
230
230 if (warning_range == NULL && argc > c) 231 if (warning_range == NULL && argc > c)
231 warning_range = argv[c++]; 232 warning_range = argv[c++];
233
232 if (critical_range == NULL && argc > c) 234 if (critical_range == NULL && argc > c)
233 critical_range = argv[c++]; 235 critical_range = argv[c++];
234 236
235 /* this will abort in case of invalid ranges */ 237 /* this will abort in case of invalid ranges */
236 set_thresholds (&thlds, warning_range, critical_range); 238 set_thresholds (&thlds, warning_range, critical_range);
237 239
238 if (thlds->warning->end < 0) 240 if (!thlds->warning) {
239 usage4 (_("Warning threshold must be a positive integer")); 241 usage4 (_("Warning threshold must be a valid range expression"));
240 if (thlds->critical->end < 0) 242 }
241 usage4 (_("Critical threshold must be a positive integer")); 243
244 if (!thlds->critical) {
245 usage4 (_("Critical threshold must be a valid range expression"));
246 }
242 247
243 return OK; 248 return OK;
244} 249}
@@ -261,10 +266,10 @@ print_help (void)
261 printf (UT_HELP_VRSN); 266 printf (UT_HELP_VRSN);
262 printf (UT_EXTRA_OPTS); 267 printf (UT_EXTRA_OPTS);
263 268
264 printf (" %s\n", "-w, --warning=INTEGER"); 269 printf (" %s\n", "-w, --warning=RANGE_EXPRESSION");
265 printf (" %s\n", _("Set WARNING status if more than INTEGER users are logged in")); 270 printf (" %s\n", _("Set WARNING status if number of logged in users violates RANGE_EXPRESSION"));
266 printf (" %s\n", "-c, --critical=INTEGER"); 271 printf (" %s\n", "-c, --critical=RANGE_EXPRESSION");
267 printf (" %s\n", _("Set CRITICAL status if more than INTEGER users are logged in")); 272 printf (" %s\n", _("Set CRITICAL status if number of logged in users violates RANGE_EXPRESSION"));
268 273
269 printf (UT_SUPPORT); 274 printf (UT_SUPPORT);
270} 275}
diff --git a/plugins/negate.c b/plugins/negate.c
index 79cca7e..745c12a 100644
--- a/plugins/negate.c
+++ b/plugins/negate.c
@@ -63,7 +63,6 @@ main (int argc, char **argv)
63 char *sub; 63 char *sub;
64 char **command_line; 64 char **command_line;
65 output chld_out, chld_err; 65 output chld_out, chld_err;
66 int i;
67 66
68 setlocale (LC_ALL, ""); 67 setlocale (LC_ALL, "");
69 bindtextdomain (PACKAGE, LOCALEDIR); 68 bindtextdomain (PACKAGE, LOCALEDIR);
@@ -86,7 +85,7 @@ main (int argc, char **argv)
86 result = cmd_run_array (command_line, &chld_out, &chld_err, 0); 85 result = cmd_run_array (command_line, &chld_out, &chld_err, 0);
87 } 86 }
88 if (chld_err.lines > 0) { 87 if (chld_err.lines > 0) {
89 for (i = 0; i < chld_err.lines; i++) { 88 for (size_t i = 0; i < chld_err.lines; i++) {
90 fprintf (stderr, "%s\n", chld_err.line[i]); 89 fprintf (stderr, "%s\n", chld_err.line[i]);
91 } 90 }
92 } 91 }
@@ -95,7 +94,7 @@ main (int argc, char **argv)
95 if (chld_out.lines == 0) 94 if (chld_out.lines == 0)
96 die (max_state_alt (result, STATE_UNKNOWN), _("No data returned from command\n")); 95 die (max_state_alt (result, STATE_UNKNOWN), _("No data returned from command\n"));
97 96
98 for (i = 0; i < chld_out.lines; i++) { 97 for (size_t i = 0; i < chld_out.lines; i++) {
99 if (subst_text && result >= 0 && result <= 4 && result != state[result]) { 98 if (subst_text && result >= 0 && result <= 4 && result != state[result]) {
100 /* Loop over each match found */ 99 /* Loop over each match found */
101 while ((sub = strstr (chld_out.line[i], state_text (result)))) { 100 while ((sub = strstr (chld_out.line[i], state_text (result)))) {
diff --git a/plugins/runcmd.c b/plugins/runcmd.c
index 4f3e349..32fd6b9 100644
--- a/plugins/runcmd.c
+++ b/plugins/runcmd.c
@@ -240,13 +240,12 @@ np_runcmd_close(int fd)
240void 240void
241runcmd_timeout_alarm_handler (int signo) 241runcmd_timeout_alarm_handler (int signo)
242{ 242{
243 size_t i;
244 243
245 if (signo == SIGALRM) 244 if (signo == SIGALRM)
246 puts(_("CRITICAL - Plugin timed out while executing system call")); 245 puts(_("CRITICAL - Plugin timed out while executing system call"));
247 246
248 long maxfd = mp_open_max(); 247 long maxfd = mp_open_max();
249 if(np_pids) for(i = 0; i < maxfd; i++) { 248 if(np_pids) for(long int i = 0; i < maxfd; i++) {
250 if(np_pids[i] != 0) kill(np_pids[i], SIGKILL); 249 if(np_pids[i] != 0) kill(np_pids[i], SIGKILL);
251 } 250 }
252 251
diff --git a/plugins/t/check_users.t b/plugins/t/check_users.t
index 9ebc2fc..21c3e53 100644
--- a/plugins/t/check_users.t
+++ b/plugins/t/check_users.t
@@ -13,10 +13,11 @@ use Test;
13use NPTest; 13use NPTest;
14 14
15use vars qw($tests); 15use vars qw($tests);
16BEGIN {$tests = 8; plan tests => $tests} 16BEGIN {$tests = 12; plan tests => $tests}
17 17
18my $successOutput = '/^USERS OK - [0-9]+ users currently logged in/'; 18my $successOutput = '/^USERS OK - [0-9]+ users currently logged in/';
19my $failureOutput = '/^USERS CRITICAL - [0-9]+ users currently logged in/'; 19my $failureOutput = '/^USERS CRITICAL - [0-9]+ users currently logged in/';
20my $wrongOptionOutput = '/Usage:/';
20 21
21my $t; 22my $t;
22 23
@@ -24,6 +25,8 @@ $t += checkCmd( "./check_users 1000 1000", 0, $successOutput );
24$t += checkCmd( "./check_users 0 0", 2, $failureOutput ); 25$t += checkCmd( "./check_users 0 0", 2, $failureOutput );
25$t += checkCmd( "./check_users -w 0:1000 -c 0:1000", 0, $successOutput ); 26$t += checkCmd( "./check_users -w 0:1000 -c 0:1000", 0, $successOutput );
26$t += checkCmd( "./check_users -w 0:0 -c 0:0", 2, $failureOutput ); 27$t += checkCmd( "./check_users -w 0:0 -c 0:0", 2, $failureOutput );
28$t += checkCmd( "./check_users -w 0:1000", 3, $wrongOptionOutput);
29$t += checkCmd( "./check_users", 3, $wrongOptionOutput);
27 30
28exit(0) if defined($Test::Harness::VERSION); 31exit(0) if defined($Test::Harness::VERSION);
29exit($tests - $t); 32exit($tests - $t);
diff --git a/plugins/utils.c b/plugins/utils.c
index 7e14b6e..e871c5f 100644
--- a/plugins/utils.c
+++ b/plugins/utils.c
@@ -230,13 +230,21 @@ bool is_intnonneg (char *number) {
230 */ 230 */
231bool is_int64(char *number, int64_t *target) { 231bool is_int64(char *number, int64_t *target) {
232 errno = 0; 232 errno = 0;
233 uint64_t tmp = strtoll(number, NULL, 10); 233 char *endptr = { 0 };
234
235 int64_t tmp = strtoll(number, &endptr, 10);
234 if (errno != 0) { 236 if (errno != 0) {
235 return false; 237 return false;
236 } 238 }
239
240 if (*endptr == '\0') {
241 return 0;
242 }
243
237 if (tmp < INT64_MIN || tmp > INT64_MAX) { 244 if (tmp < INT64_MIN || tmp > INT64_MAX) {
238 return false; 245 return false;
239 } 246 }
247
240 if (target != NULL) { 248 if (target != NULL) {
241 *target = tmp; 249 *target = tmp;
242 } 250 }