summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/check_apt.c664
-rw-r--r--plugins/check_curl.c2
-rw-r--r--plugins/check_disk.c22
-rw-r--r--plugins/check_fping.c23
-rw-r--r--plugins/check_ide_smart.c6
-rw-r--r--plugins/check_ldap.c42
-rw-r--r--plugins/check_mysql.c42
-rw-r--r--plugins/check_nt.c39
-rw-r--r--plugins/check_ntp.c8
-rw-r--r--plugins/check_nwstat.c48
-rw-r--r--plugins/check_overcr.c31
-rw-r--r--plugins/check_procs.c58
-rw-r--r--plugins/check_radius.c28
-rw-r--r--plugins/check_smtp.c98
-rw-r--r--plugins/check_tcp.c2
-rw-r--r--plugins/check_ups.c10
-rw-r--r--plugins/runcmd.c2
-rw-r--r--plugins/utils.c2
18 files changed, 592 insertions, 535 deletions
diff --git a/plugins/check_apt.c b/plugins/check_apt.c
index 5e4021b5..1eda45dd 100644
--- a/plugins/check_apt.c
+++ b/plugins/check_apt.c
@@ -1,33 +1,33 @@
1/***************************************************************************** 1/*****************************************************************************
2* 2 *
3* Monitoring check_apt plugin 3 * Monitoring check_apt plugin
4* 4 *
5* License: GPL 5 * License: GPL
6* Copyright (c) 2006-2024 Monitoring Plugins Development Team 6 * Copyright (c) 2006-2024 Monitoring Plugins Development Team
7* 7 *
8* Original author: Sean Finney 8 * Original author: Sean Finney
9* 9 *
10* Description: 10 * Description:
11* 11 *
12* This file contains the check_apt plugin 12 * This file contains the check_apt plugin
13* 13 *
14* Check for available updates in apt package management systems 14 * Check for available updates in apt package management systems
15* 15 *
16* 16 *
17* This program is free software: you can redistribute it and/or modify 17 * This program is free software: you can redistribute it and/or modify
18* it under the terms of the GNU General Public License as published by 18 * it under the terms of the GNU General Public License as published by
19* the Free Software Foundation, either version 3 of the License, or 19 * the Free Software Foundation, either version 3 of the License, or
20* (at your option) any later version. 20 * (at your option) any later version.
21* 21 *
22* This program is distributed in the hope that it will be useful, 22 * This program is distributed in the hope that it will be useful,
23* but WITHOUT ANY WARRANTY; without even the implied warranty of 23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25* GNU General Public License for more details. 25 * GNU General Public License for more details.
26* 26 *
27* You should have received a copy of the GNU General Public License 27 * You should have received a copy of the GNU General Public License
28* along with this program. If not, see <http://www.gnu.org/licenses/>. 28 * along with this program. If not, see <http://www.gnu.org/licenses/>.
29* 29 *
30*****************************************************************************/ 30 *****************************************************************************/
31 31
32const char *progname = "check_apt"; 32const char *progname = "check_apt";
33const char *copyright = "2006-2024"; 33const char *copyright = "2006-2024";
@@ -39,17 +39,21 @@ const char *email = "devel@monitoring-plugins.org";
39#include "regex.h" 39#include "regex.h"
40 40
41/* some constants */ 41/* some constants */
42typedef enum { UPGRADE, DIST_UPGRADE, NO_UPGRADE } upgrade_type; 42typedef enum {
43 UPGRADE,
44 DIST_UPGRADE,
45 NO_UPGRADE
46} upgrade_type;
43 47
44/* Character for hidden input file option (for testing). */ 48/* Character for hidden input file option (for testing). */
45#define INPUT_FILE_OPT CHAR_MAX+1 49#define INPUT_FILE_OPT CHAR_MAX + 1
46/* the default opts can be overridden via the cmdline */ 50/* the default opts can be overridden via the cmdline */
47#define UPGRADE_DEFAULT_OPTS "-o 'Debug::NoLocking=true' -s -qq" 51#define UPGRADE_DEFAULT_OPTS "-o 'Debug::NoLocking=true' -s -qq"
48#define UPDATE_DEFAULT_OPTS "-q" 52#define UPDATE_DEFAULT_OPTS "-q"
49/* until i commit the configure.in patch which gets this, i'll define 53/* until i commit the configure.in patch which gets this, i'll define
50 * it here as well */ 54 * it here as well */
51#ifndef PATH_TO_APTGET 55#ifndef PATH_TO_APTGET
52# define PATH_TO_APTGET "/usr/bin/apt-get" 56# define PATH_TO_APTGET "/usr/bin/apt-get"
53#endif /* PATH_TO_APTGET */ 57#endif /* PATH_TO_APTGET */
54/* String found at the beginning of the apt output lines we're interested in */ 58/* String found at the beginning of the apt output lines we're interested in */
55#define PKGINST_PREFIX "Inst " 59#define PKGINST_PREFIX "Inst "
@@ -57,97 +61,108 @@ typedef enum { UPGRADE, DIST_UPGRADE, NO_UPGRADE } upgrade_type;
57#define SECURITY_RE "^[^\\(]*\\(.* (Debian-Security:|Ubuntu:[^/]*/[^-]*-security)" 61#define SECURITY_RE "^[^\\(]*\\(.* (Debian-Security:|Ubuntu:[^/]*/[^-]*-security)"
58 62
59/* some standard functions */ 63/* some standard functions */
60int process_arguments(int, char **); 64static int process_arguments(int /*argc*/, char ** /*argv*/);
61void print_help(void); 65static void print_help(void);
62void print_usage(void); 66void print_usage(void);
63 67
64/* construct the appropriate apt-get cmdline */ 68/* construct the appropriate apt-get cmdline */
65char* construct_cmdline(upgrade_type u, const char *opts); 69static char *construct_cmdline(upgrade_type u, const char *opts);
66/* run an apt-get update */ 70/* run an apt-get update */
67int run_update(void); 71static int run_update(void);
72
73typedef struct {
74 int errorcode;
75 int package_count;
76 int security_package_count;
77 char **packages_list;
78 char **secpackages_list;
79} run_upgrade_result;
80
68/* run an apt-get upgrade */ 81/* run an apt-get upgrade */
69int run_upgrade(int *pkgcount, int *secpkgcount, char ***pkglist, char ***secpkglist); 82static run_upgrade_result run_upgrade(void);
83
70/* add another clause to a regexp */ 84/* add another clause to a regexp */
71char* add_to_regexp(char *expr, const char *next); 85static char *add_to_regexp(char *expr, const char *next);
72/* extract package name from Inst line */ 86/* extract package name from Inst line */
73char* pkg_name(char *line); 87static char *pkg_name(char *line);
74/* string comparison function for qsort */ 88/* string comparison function for qsort */
75int cmpstringp(const void *p1, const void *p2); 89static int cmpstringp(const void *p1, const void *p2);
76 90
77/* configuration variables */ 91/* configuration variables */
78static int verbose = 0; /* -v */ 92static int verbose = 0; /* -v */
79static bool list = false; /* list packages available for upgrade */ 93static bool list = false; /* list packages available for upgrade */
80static bool do_update = false; /* whether to call apt-get update */ 94static bool do_update = false; /* whether to call apt-get update */
81static bool only_critical = false; /* whether to warn about non-critical updates */ 95static bool only_critical = false; /* whether to warn about non-critical updates */
82static upgrade_type upgrade = UPGRADE; /* which type of upgrade to do */ 96static upgrade_type upgrade = UPGRADE; /* which type of upgrade to do */
83static char *upgrade_opts = NULL; /* options to override defaults for upgrade */ 97static char *upgrade_opts = NULL; /* options to override defaults for upgrade */
84static char *update_opts = NULL; /* options to override defaults for update */ 98static char *update_opts = NULL; /* options to override defaults for update */
85static char *do_include = NULL; /* regexp to only include certain packages */ 99static char *do_include = NULL; /* regexp to only include certain packages */
86static char *do_exclude = NULL; /* regexp to only exclude certain packages */ 100static char *do_exclude = NULL; /* regexp to only exclude certain packages */
87static char *do_critical = NULL; /* regexp specifying critical packages */ 101static char *do_critical = NULL; /* regexp specifying critical packages */
88static char *input_filename = NULL; /* input filename for testing */ 102static char *input_filename = NULL; /* input filename for testing */
89/* number of packages available for upgrade to return WARNING status */ 103/* number of packages available for upgrade to return WARNING status */
90static int packages_warning = 1; 104static int packages_warning = 1;
91 105
92/* other global variables */ 106/* other global variables */
93static int stderr_warning = 0; /* if a cmd issued output on stderr */ 107static int stderr_warning = 0; /* if a cmd issued output on stderr */
94static int exec_warning = 0; /* if a cmd exited non-zero */ 108static int exec_warning = 0; /* if a cmd exited non-zero */
95
96int main (int argc, char **argv) {
97 int result=STATE_UNKNOWN, packages_available=0, sec_count=0;
98 char **packages_list=NULL, **secpackages_list=NULL;
99 109
110int main(int argc, char **argv) {
100 /* Parse extra opts if any */ 111 /* Parse extra opts if any */
101 argv=np_extra_opts(&argc, argv, progname); 112 argv = np_extra_opts(&argc, argv, progname);
102 113
103 if (process_arguments(argc, argv) == ERROR) 114 if (process_arguments(argc, argv) == ERROR) {
104 usage_va(_("Could not parse arguments")); 115 usage_va(_("Could not parse arguments"));
116 }
105 117
106 /* Set signal handling and alarm timeout */ 118 /* Set signal handling and alarm timeout */
107 if (signal (SIGALRM, timeout_alarm_handler) == SIG_ERR) { 119 if (signal(SIGALRM, timeout_alarm_handler) == SIG_ERR) {
108 usage_va(_("Cannot catch SIGALRM")); 120 usage_va(_("Cannot catch SIGALRM"));
109 } 121 }
110 122
111 /* handle timeouts gracefully... */ 123 /* handle timeouts gracefully... */
112 alarm (timeout_interval); 124 alarm(timeout_interval);
113 125
126 int result = STATE_UNKNOWN;
114 /* if they want to run apt-get update first... */ 127 /* if they want to run apt-get update first... */
115 if(do_update) result = run_update(); 128 if (do_update) {
129 result = run_update();
130 }
116 131
117 /* apt-get upgrade */ 132 /* apt-get upgrade */
118 result = max_state(result, run_upgrade(&packages_available, &sec_count, &packages_list, &secpackages_list)); 133 run_upgrade_result upgrad_res = run_upgrade();
119 134
120 if(sec_count > 0){ 135 result = max_state(result, upgrad_res.errorcode);
136 int packages_available = upgrad_res.package_count;
137 int sec_count = upgrad_res.security_package_count;
138 char **packages_list = upgrad_res.packages_list;
139 char **secpackages_list = upgrad_res.secpackages_list;
140
141 if (sec_count > 0) {
121 result = max_state(result, STATE_CRITICAL); 142 result = max_state(result, STATE_CRITICAL);
122 } else if(packages_available >= packages_warning && only_critical == false){ 143 } else if (packages_available >= packages_warning && only_critical == false) {
123 result = max_state(result, STATE_WARNING); 144 result = max_state(result, STATE_WARNING);
124 } else if(result > STATE_UNKNOWN){ 145 } else if (result > STATE_UNKNOWN) {
125 result = STATE_UNKNOWN; 146 result = STATE_UNKNOWN;
126 } 147 }
127 148
128 printf(_("APT %s: %d packages available for %s (%d critical updates). %s%s%s%s|available_upgrades=%d;;;0 critical_updates=%d;;;0\n"), 149 printf(_("APT %s: %d packages available for %s (%d critical updates). %s%s%s%s|available_upgrades=%d;;;0 critical_updates=%d;;;0\n"),
129 state_text(result), 150 state_text(result), packages_available, (upgrade == DIST_UPGRADE) ? "dist-upgrade" : "upgrade", sec_count,
130 packages_available, 151 (stderr_warning) ? " warnings detected" : "", (stderr_warning && exec_warning) ? "," : "",
131 (upgrade==DIST_UPGRADE)?"dist-upgrade":"upgrade", 152 (exec_warning) ? " errors detected" : "", (stderr_warning || exec_warning) ? "." : "", packages_available, sec_count);
132 sec_count, 153
133 (stderr_warning)?" warnings detected":"", 154 if (list) {
134 (stderr_warning && exec_warning)?",":"", 155 qsort(secpackages_list, sec_count, sizeof(char *), cmpstringp);
135 (exec_warning)?" errors detected":"", 156 qsort(packages_list, packages_available - sec_count, sizeof(char *), cmpstringp);
136 (stderr_warning||exec_warning)?".":"", 157
137 packages_available, 158 for (int i = 0; i < sec_count; i++) {
138 sec_count
139 );
140
141 if(list) {
142 qsort(secpackages_list, sec_count, sizeof(char*), cmpstringp);
143 qsort(packages_list, packages_available-sec_count, sizeof(char*), cmpstringp);
144
145 for(int i = 0; i < sec_count; i++)
146 printf("%s (security)\n", secpackages_list[i]); 159 printf("%s (security)\n", secpackages_list[i]);
160 }
147 161
148 if (only_critical == false) { 162 if (only_critical == false) {
149 for(int i = 0; i < packages_available - sec_count; i++) 163 for (int i = 0; i < packages_available - sec_count; i++) {
150 printf("%s\n", packages_list[i]); 164 printf("%s\n", packages_list[i]);
165 }
151 } 166 }
152 } 167 }
153 168
@@ -155,34 +170,32 @@ int main (int argc, char **argv) {
155} 170}
156 171
157/* process command-line arguments */ 172/* process command-line arguments */
158int process_arguments (int argc, char **argv) { 173int process_arguments(int argc, char **argv) {
159 int c; 174 static struct option longopts[] = {{"version", no_argument, 0, 'V'},
160 175 {"help", no_argument, 0, 'h'},
161 static struct option longopts[] = { 176 {"verbose", no_argument, 0, 'v'},
162 {"version", no_argument, 0, 'V'}, 177 {"timeout", required_argument, 0, 't'},
163 {"help", no_argument, 0, 'h'}, 178 {"update", optional_argument, 0, 'u'},
164 {"verbose", no_argument, 0, 'v'}, 179 {"upgrade", optional_argument, 0, 'U'},
165 {"timeout", required_argument, 0, 't'}, 180 {"no-upgrade", no_argument, 0, 'n'},
166 {"update", optional_argument, 0, 'u'}, 181 {"dist-upgrade", optional_argument, 0, 'd'},
167 {"upgrade", optional_argument, 0, 'U'}, 182 {"list", no_argument, false, 'l'},
168 {"no-upgrade", no_argument, 0, 'n'}, 183 {"include", required_argument, 0, 'i'},
169 {"dist-upgrade", optional_argument, 0, 'd'}, 184 {"exclude", required_argument, 0, 'e'},
170 {"list", no_argument, false, 'l'}, 185 {"critical", required_argument, 0, 'c'},
171 {"include", required_argument, 0, 'i'}, 186 {"only-critical", no_argument, 0, 'o'},
172 {"exclude", required_argument, 0, 'e'}, 187 {"input-file", required_argument, 0, INPUT_FILE_OPT},
173 {"critical", required_argument, 0, 'c'}, 188 {"packages-warning", required_argument, 0, 'w'},
174 {"only-critical", no_argument, 0, 'o'}, 189 {0, 0, 0, 0}};
175 {"input-file", required_argument, 0, INPUT_FILE_OPT}, 190
176 {"packages-warning", required_argument, 0, 'w'}, 191 while (true) {
177 {0, 0, 0, 0} 192 int option_char = getopt_long(argc, argv, "hVvt:u::U::d::nli:e:c:ow:", longopts, NULL);
178 }; 193
179 194 if (option_char == -1 || option_char == EOF || option_char == 1) {
180 while(1) { 195 break;
181 c = getopt_long(argc, argv, "hVvt:u::U::d::nli:e:c:ow:", longopts, NULL); 196 }
182
183 if(c == -1 || c == EOF || c == 1) break;
184 197
185 switch(c) { 198 switch (option_char) {
186 case 'h': 199 case 'h':
187 print_help(); 200 print_help();
188 exit(STATE_UNKNOWN); 201 exit(STATE_UNKNOWN);
@@ -193,46 +206,52 @@ int process_arguments (int argc, char **argv) {
193 verbose++; 206 verbose++;
194 break; 207 break;
195 case 't': 208 case 't':
196 timeout_interval=atoi(optarg); 209 timeout_interval = atoi(optarg);
197 break; 210 break;
198 case 'd': 211 case 'd':
199 upgrade=DIST_UPGRADE; 212 upgrade = DIST_UPGRADE;
200 if(optarg!=NULL){ 213 if (optarg != NULL) {
201 upgrade_opts=strdup(optarg); 214 upgrade_opts = strdup(optarg);
202 if(upgrade_opts==NULL) die(STATE_UNKNOWN, "strdup failed"); 215 if (upgrade_opts == NULL) {
216 die(STATE_UNKNOWN, "strdup failed");
217 }
203 } 218 }
204 break; 219 break;
205 case 'U': 220 case 'U':
206 upgrade=UPGRADE; 221 upgrade = UPGRADE;
207 if(optarg!=NULL){ 222 if (optarg != NULL) {
208 upgrade_opts=strdup(optarg); 223 upgrade_opts = strdup(optarg);
209 if(upgrade_opts==NULL) die(STATE_UNKNOWN, "strdup failed"); 224 if (upgrade_opts == NULL) {
225 die(STATE_UNKNOWN, "strdup failed");
226 }
210 } 227 }
211 break; 228 break;
212 case 'n': 229 case 'n':
213 upgrade=NO_UPGRADE; 230 upgrade = NO_UPGRADE;
214 break; 231 break;
215 case 'u': 232 case 'u':
216 do_update=true; 233 do_update = true;
217 if(optarg!=NULL){ 234 if (optarg != NULL) {
218 update_opts=strdup(optarg); 235 update_opts = strdup(optarg);
219 if(update_opts==NULL) die(STATE_UNKNOWN, "strdup failed"); 236 if (update_opts == NULL) {
237 die(STATE_UNKNOWN, "strdup failed");
238 }
220 } 239 }
221 break; 240 break;
222 case 'l': 241 case 'l':
223 list=true; 242 list = true;
224 break; 243 break;
225 case 'i': 244 case 'i':
226 do_include=add_to_regexp(do_include, optarg); 245 do_include = add_to_regexp(do_include, optarg);
227 break; 246 break;
228 case 'e': 247 case 'e':
229 do_exclude=add_to_regexp(do_exclude, optarg); 248 do_exclude = add_to_regexp(do_exclude, optarg);
230 break; 249 break;
231 case 'c': 250 case 'c':
232 do_critical=add_to_regexp(do_critical, optarg); 251 do_critical = add_to_regexp(do_critical, optarg);
233 break; 252 break;
234 case 'o': 253 case 'o':
235 only_critical=true; 254 only_critical = true;
236 break; 255 break;
237 case INPUT_FILE_OPT: 256 case INPUT_FILE_OPT:
238 input_filename = optarg; 257 input_filename = optarg;
@@ -249,68 +268,78 @@ int process_arguments (int argc, char **argv) {
249 return OK; 268 return OK;
250} 269}
251 270
252
253/* run an apt-get upgrade */ 271/* run an apt-get upgrade */
254int run_upgrade(int *pkgcount, int *secpkgcount, char ***pkglist, char ***secpkglist){ 272run_upgrade_result run_upgrade(void) {
255 int result=STATE_UNKNOWN, regres=0, pc=0, spc=0; 273 regex_t ereg;
256 struct output chld_out, chld_err;
257 regex_t ireg, ereg, sreg;
258 char *cmdline=NULL, rerrbuf[64];
259
260 /* initialize ereg as it is possible it is printed while uninitialized */ 274 /* initialize ereg as it is possible it is printed while uninitialized */
261 memset(&ereg, '\0', sizeof(ereg.buffer)); 275 memset(&ereg, '\0', sizeof(ereg.buffer));
262 276
263 if(upgrade==NO_UPGRADE) return STATE_OK; 277 run_upgrade_result result = {
278 .errorcode = STATE_UNKNOWN,
279 };
264 280
281 if (upgrade == NO_UPGRADE) {
282 result.errorcode = STATE_OK;
283 return result;
284 }
285
286 int regres = 0;
287 regex_t ireg;
288 char rerrbuf[64];
265 /* compile the regexps */ 289 /* compile the regexps */
266 if (do_include != NULL) { 290 if (do_include != NULL) {
267 regres=regcomp(&ireg, do_include, REG_EXTENDED); 291 regres = regcomp(&ireg, do_include, REG_EXTENDED);
268 if (regres!=0) { 292 if (regres != 0) {
269 regerror(regres, &ireg, rerrbuf, 64); 293 regerror(regres, &ireg, rerrbuf, 64);
270 die(STATE_UNKNOWN, _("%s: Error compiling regexp: %s"), progname, rerrbuf); 294 die(STATE_UNKNOWN, _("%s: Error compiling regexp: %s"), progname, rerrbuf);
271 } 295 }
272 } 296 }
273 297
274 if(do_exclude!=NULL){ 298 if (do_exclude != NULL) {
275 regres=regcomp(&ereg, do_exclude, REG_EXTENDED); 299 regres = regcomp(&ereg, do_exclude, REG_EXTENDED);
276 if(regres!=0) { 300 if (regres != 0) {
277 regerror(regres, &ereg, rerrbuf, 64); 301 regerror(regres, &ereg, rerrbuf, 64);
278 die(STATE_UNKNOWN, _("%s: Error compiling regexp: %s"), 302 die(STATE_UNKNOWN, _("%s: Error compiling regexp: %s"), progname, rerrbuf);
279 progname, rerrbuf);
280 } 303 }
281 } 304 }
282 305
306 regex_t sreg;
283 const char *crit_ptr = (do_critical != NULL) ? do_critical : SECURITY_RE; 307 const char *crit_ptr = (do_critical != NULL) ? do_critical : SECURITY_RE;
284 regres=regcomp(&sreg, crit_ptr, REG_EXTENDED); 308 regres = regcomp(&sreg, crit_ptr, REG_EXTENDED);
285 if(regres!=0) { 309 if (regres != 0) {
286 regerror(regres, &ereg, rerrbuf, 64); 310 regerror(regres, &ereg, rerrbuf, 64);
287 die(STATE_UNKNOWN, _("%s: Error compiling regexp: %s"), 311 die(STATE_UNKNOWN, _("%s: Error compiling regexp: %s"), progname, rerrbuf);
288 progname, rerrbuf);
289 } 312 }
290 313
291 cmdline=construct_cmdline(upgrade, upgrade_opts); 314 struct output chld_out;
315 struct output chld_err;
316 char *cmdline = NULL;
317 cmdline = construct_cmdline(upgrade, upgrade_opts);
292 if (input_filename != NULL) { 318 if (input_filename != NULL) {
293 /* read input from a file for testing */ 319 /* read input from a file for testing */
294 result = cmd_file_read(input_filename, &chld_out, 0); 320 result.errorcode = cmd_file_read(input_filename, &chld_out, 0);
295 } else { 321 } else {
296 /* run the upgrade */ 322 /* run the upgrade */
297 result = np_runcmd(cmdline, &chld_out, &chld_err, 0); 323 result.errorcode = np_runcmd(cmdline, &chld_out, &chld_err, 0);
298 } 324 }
299 325
300 /* apt-get upgrade only changes exit status if there is an 326 /* apt-get upgrade only changes exit status if there is an
301 * internal error when run in dry-run mode. therefore we will 327 * internal error when run in dry-run mode. therefore we will
302 * treat such an error as UNKNOWN */ 328 * treat such an error as UNKNOWN */
303 if(result != 0){ 329 if (result.errorcode != STATE_OK) {
304 exec_warning=1; 330 exec_warning = 1;
305 result = STATE_UNKNOWN; 331 result.errorcode = STATE_UNKNOWN;
306 fprintf(stderr, _("'%s' exited with non-zero status.\n"), 332 fprintf(stderr, _("'%s' exited with non-zero status.\n"), cmdline);
307 cmdline);
308 } 333 }
309 334
310 *pkglist=malloc(sizeof(char *) * chld_out.lines); 335 char **pkglist = malloc(sizeof(char *) * chld_out.lines);
311 if(!pkglist) die(STATE_UNKNOWN, "malloc failed!\n"); 336 if (!pkglist) {
312 *secpkglist=malloc(sizeof(char *) * chld_out.lines); 337 die(STATE_UNKNOWN, "malloc failed!\n");
313 if(!secpkglist) die(STATE_UNKNOWN, "malloc failed!\n"); 338 }
339 char **secpkglist = malloc(sizeof(char *) * chld_out.lines);
340 if (!secpkglist) {
341 die(STATE_UNKNOWN, "malloc failed!\n");
342 }
314 343
315 /* parse the output, which should only consist of lines like 344 /* parse the output, which should only consist of lines like
316 * 345 *
@@ -321,82 +350,91 @@ int run_upgrade(int *pkgcount, int *secpkgcount, char ***pkglist, char ***secpkg
321 * we may need to switch to the --print-uris output format, 350 * we may need to switch to the --print-uris output format,
322 * in which case the logic here will slightly change. 351 * in which case the logic here will slightly change.
323 */ 352 */
324 for(size_t i = 0; i < chld_out.lines; i++) { 353 int package_counter = 0;
325 if(verbose){ 354 int security_package_counter = 0;
355 for (size_t i = 0; i < chld_out.lines; i++) {
356 if (verbose) {
326 printf("%s\n", chld_out.line[i]); 357 printf("%s\n", chld_out.line[i]);
327 } 358 }
328 /* if it is a package we care about */ 359 /* if it is a package we care about */
329 if (strncmp(PKGINST_PREFIX, chld_out.line[i], strlen(PKGINST_PREFIX)) == 0 && 360 if (strncmp(PKGINST_PREFIX, chld_out.line[i], strlen(PKGINST_PREFIX)) == 0 &&
330 (do_include == NULL || regexec(&ireg, chld_out.line[i], 0, NULL, 0) == 0)) { 361 (do_include == NULL || regexec(&ireg, chld_out.line[i], 0, NULL, 0) == 0)) {
331 /* if we're not excluding, or it's not in the 362 /* if we're not excluding, or it's not in the
332 * list of stuff to exclude */ 363 * list of stuff to exclude */
333 if(do_exclude==NULL || 364 if (do_exclude == NULL || regexec(&ereg, chld_out.line[i], 0, NULL, 0) != 0) {
334 regexec(&ereg, chld_out.line[i], 0, NULL, 0)!=0){ 365 package_counter++;
335 pc++; 366 if (regexec(&sreg, chld_out.line[i], 0, NULL, 0) == 0) {
336 if(regexec(&sreg, chld_out.line[i], 0, NULL, 0)==0){ 367 security_package_counter++;
337 spc++; 368 if (verbose) {
338 if(verbose) printf("*"); 369 printf("*");
339 (*secpkglist)[spc-1] = pkg_name(chld_out.line[i]); 370 }
371 (secpkglist)[security_package_counter - 1] = pkg_name(chld_out.line[i]);
340 } else { 372 } else {
341 (*pkglist)[pc-spc-1] = pkg_name(chld_out.line[i]); 373 (pkglist)[package_counter - security_package_counter - 1] = pkg_name(chld_out.line[i]);
342 } 374 }
343 if(verbose){ 375 if (verbose) {
344 printf("*%s\n", chld_out.line[i]); 376 printf("*%s\n", chld_out.line[i]);
345 } 377 }
346 } 378 }
347 } 379 }
348 } 380 }
349 *pkgcount=pc; 381 result.package_count = package_counter;
350 *secpkgcount=spc; 382 result.security_package_count = security_package_counter;
383 result.packages_list = pkglist;
384 result.secpackages_list = secpkglist;
351 385
352 /* If we get anything on stderr, at least set warning */ 386 /* If we get anything on stderr, at least set warning */
353 if (input_filename == NULL && chld_err.buflen) { 387 if (input_filename == NULL && chld_err.buflen) {
354 stderr_warning=1; 388 stderr_warning = 1;
355 result = max_state(result, STATE_WARNING); 389 result.errorcode = max_state(result.errorcode, STATE_WARNING);
356 if(verbose){ 390 if (verbose) {
357 for(size_t i = 0; i < chld_err.lines; i++) { 391 for (size_t i = 0; i < chld_err.lines; i++) {
358 fprintf(stderr, "%s\n", chld_err.line[i]); 392 fprintf(stderr, "%s\n", chld_err.line[i]);
359 } 393 }
360 } 394 }
361 } 395 }
362 if (do_include != NULL) regfree(&ireg); 396 if (do_include != NULL) {
397 regfree(&ireg);
398 }
363 regfree(&sreg); 399 regfree(&sreg);
364 if(do_exclude!=NULL) regfree(&ereg); 400 if (do_exclude != NULL) {
401 regfree(&ereg);
402 }
365 free(cmdline); 403 free(cmdline);
366 return result; 404 return result;
367} 405}
368 406
369/* run an apt-get update (needs root) */ 407/* run an apt-get update (needs root) */
370int run_update(void){ 408int run_update(void) {
371 int result=STATE_UNKNOWN; 409 int result = STATE_UNKNOWN;
372 struct output chld_out, chld_err;
373 char *cmdline; 410 char *cmdline;
374
375 /* run the update */ 411 /* run the update */
376 cmdline = construct_cmdline(NO_UPGRADE, update_opts); 412 cmdline = construct_cmdline(NO_UPGRADE, update_opts);
413
414 struct output chld_out;
415 struct output chld_err;
377 result = np_runcmd(cmdline, &chld_out, &chld_err, 0); 416 result = np_runcmd(cmdline, &chld_out, &chld_err, 0);
378 /* apt-get update changes exit status if it can't fetch packages. 417 /* apt-get update changes exit status if it can't fetch packages.
379 * since we were explicitly asked to do so, this is treated as 418 * since we were explicitly asked to do so, this is treated as
380 * a critical error. */ 419 * a critical error. */
381 if(result != 0){ 420 if (result != 0) {
382 exec_warning=1; 421 exec_warning = 1;
383 result = STATE_CRITICAL; 422 result = STATE_CRITICAL;
384 fprintf(stderr, _("'%s' exited with non-zero status.\n"), 423 fprintf(stderr, _("'%s' exited with non-zero status.\n"), cmdline);
385 cmdline);
386 } 424 }
387 425
388 if(verbose){ 426 if (verbose) {
389 for(size_t i = 0; i < chld_out.lines; i++) { 427 for (size_t i = 0; i < chld_out.lines; i++) {
390 printf("%s\n", chld_out.line[i]); 428 printf("%s\n", chld_out.line[i]);
391 } 429 }
392 } 430 }
393 431
394 /* If we get anything on stderr, at least set warning */ 432 /* If we get anything on stderr, at least set warning */
395 if(chld_err.buflen){ 433 if (chld_err.buflen) {
396 stderr_warning=1; 434 stderr_warning = 1;
397 result = max_state(result, STATE_WARNING); 435 result = max_state(result, STATE_WARNING);
398 if(verbose){ 436 if (verbose) {
399 for(size_t i = 0; i < chld_err.lines; i++) { 437 for (size_t i = 0; i < chld_err.lines; i++) {
400 fprintf(stderr, "%s\n", chld_err.line[i]); 438 fprintf(stderr, "%s\n", chld_err.line[i]);
401 } 439 }
402 } 440 }
@@ -405,158 +443,166 @@ int run_update(void){
405 return result; 443 return result;
406} 444}
407 445
408char* pkg_name(char *line){ 446char *pkg_name(char *line) {
409 char *start=NULL, *space=NULL, *pkg=NULL; 447 char *start = line + strlen(PKGINST_PREFIX);
410 int len=0;
411 448
412 start = line + strlen(PKGINST_PREFIX); 449 int len = strlen(start);
413 len = strlen(start);
414 450
415 space = index(start, ' '); 451 char *space = index(start, ' ');
416 if(space!=NULL){ 452 if (space != NULL) {
417 len = space - start; 453 len = space - start;
418 } 454 }
419 455
420 pkg=malloc(sizeof(char)*(len+1)); 456 char *pkg = malloc(sizeof(char) * (len + 1));
421 if(!pkg) die(STATE_UNKNOWN, "malloc failed!\n"); 457 if (!pkg) {
458 die(STATE_UNKNOWN, "malloc failed!\n");
459 }
422 460
423 strncpy(pkg, start, len); 461 strncpy(pkg, start, len);
424 pkg[len]='\0'; 462 pkg[len] = '\0';
425 463
426 return pkg; 464 return pkg;
427} 465}
428 466
429int cmpstringp(const void *p1, const void *p2){ 467int cmpstringp(const void *p1, const void *p2) { return strcmp(*(char *const *)p1, *(char *const *)p2); }
430 return strcmp(* (char * const *) p1, * (char * const *) p2);
431}
432 468
433char* add_to_regexp(char *expr, const char *next){ 469char *add_to_regexp(char *expr, const char *next) {
434 char *re=NULL; 470 char *re = NULL;
435 471
436 if(expr==NULL){ 472 if (expr == NULL) {
437 re=malloc(sizeof(char)*(strlen("()")+strlen(next)+1)); 473 re = malloc(sizeof(char) * (strlen("()") + strlen(next) + 1));
438 if(!re) die(STATE_UNKNOWN, "malloc failed!\n"); 474 if (!re) {
475 die(STATE_UNKNOWN, "malloc failed!\n");
476 }
439 sprintf(re, "(%s)", next); 477 sprintf(re, "(%s)", next);
440 } else { 478 } else {
441 /* resize it, adding an extra char for the new '|' separator */ 479 /* resize it, adding an extra char for the new '|' separator */
442 re=realloc(expr, sizeof(char)*(strlen(expr)+1+strlen(next)+1)); 480 re = realloc(expr, sizeof(char) * (strlen(expr) + 1 + strlen(next) + 1));
443 if(!re) die(STATE_UNKNOWN, "realloc failed!\n"); 481 if (!re) {
482 die(STATE_UNKNOWN, "realloc failed!\n");
483 }
444 /* append it starting at ')' in the old re */ 484 /* append it starting at ')' in the old re */
445 sprintf((char*)(re+strlen(re)-1), "|%s)", next); 485 sprintf((char *)(re + strlen(re) - 1), "|%s)", next);
446 } 486 }
447 487
448 return re; 488 return re;
449} 489}
450 490
451char* construct_cmdline(upgrade_type u, const char *opts){ 491char *construct_cmdline(upgrade_type u, const char *opts) {
452 int len=0; 492 const char *opts_ptr = NULL;
453 const char *opts_ptr=NULL, *aptcmd=NULL; 493 const char *aptcmd = NULL;
454 char *cmd=NULL;
455 494
456 switch(u){ 495 switch (u) {
457 case UPGRADE: 496 case UPGRADE:
458 if(opts==NULL) opts_ptr=UPGRADE_DEFAULT_OPTS; 497 if (opts == NULL) {
459 else opts_ptr=opts; 498 opts_ptr = UPGRADE_DEFAULT_OPTS;
460 aptcmd="upgrade"; 499 } else {
500 opts_ptr = opts;
501 }
502 aptcmd = "upgrade";
461 break; 503 break;
462 case DIST_UPGRADE: 504 case DIST_UPGRADE:
463 if(opts==NULL) opts_ptr=UPGRADE_DEFAULT_OPTS; 505 if (opts == NULL) {
464 else opts_ptr=opts; 506 opts_ptr = UPGRADE_DEFAULT_OPTS;
465 aptcmd="dist-upgrade"; 507 } else {
508 opts_ptr = opts;
509 }
510 aptcmd = "dist-upgrade";
466 break; 511 break;
467 case NO_UPGRADE: 512 case NO_UPGRADE:
468 if(opts==NULL) opts_ptr=UPDATE_DEFAULT_OPTS; 513 if (opts == NULL) {
469 else opts_ptr=opts; 514 opts_ptr = UPDATE_DEFAULT_OPTS;
470 aptcmd="update"; 515 } else {
516 opts_ptr = opts;
517 }
518 aptcmd = "update";
471 break; 519 break;
472 } 520 }
473 521
474 len+=strlen(PATH_TO_APTGET)+1; /* "/usr/bin/apt-get " */ 522 int len = 0;
475 len+=strlen(opts_ptr)+1; /* "opts " */ 523 len += strlen(PATH_TO_APTGET) + 1; /* "/usr/bin/apt-get " */
476 len+=strlen(aptcmd)+1; /* "upgrade\0" */ 524 len += strlen(opts_ptr) + 1; /* "opts " */
525 len += strlen(aptcmd) + 1; /* "upgrade\0" */
477 526
478 cmd=(char*)malloc(sizeof(char)*len); 527 char *cmd = (char *)malloc(sizeof(char) * len);
479 if(cmd==NULL) die(STATE_UNKNOWN, "malloc failed"); 528 if (cmd == NULL) {
529 die(STATE_UNKNOWN, "malloc failed");
530 }
480 sprintf(cmd, "%s %s %s", PATH_TO_APTGET, opts_ptr, aptcmd); 531 sprintf(cmd, "%s %s %s", PATH_TO_APTGET, opts_ptr, aptcmd);
481 return cmd; 532 return cmd;
482} 533}
483 534
484/* informative help message */ 535/* informative help message */
485void 536void print_help(void) {
486print_help (void) 537 print_revision(progname, NP_VERSION);
487{ 538
488 print_revision(progname, NP_VERSION); 539 printf(_(COPYRIGHT), copyright, email);
489 540
490 printf(_(COPYRIGHT), copyright, email); 541 printf("%s\n", _("This plugin checks for software updates on systems that use"));
491 542 printf("%s\n", _("package management systems based on the apt-get(8) command"));
492 printf("%s\n", _("This plugin checks for software updates on systems that use")); 543 printf("%s\n", _("found in Debian GNU/Linux"));
493 printf("%s\n", _("package management systems based on the apt-get(8) command")); 544
494 printf("%s\n", _("found in Debian GNU/Linux")); 545 printf("\n\n");
495 546
496 printf ("\n\n"); 547 print_usage();
497 548
498 print_usage(); 549 printf(UT_HELP_VRSN);
499 550 printf(UT_EXTRA_OPTS);
500 printf(UT_HELP_VRSN); 551
501 printf(UT_EXTRA_OPTS); 552 printf(UT_PLUG_TIMEOUT, timeout_interval);
502 553
503 printf(UT_PLUG_TIMEOUT, timeout_interval); 554 printf(" %s\n", "-n, --no-upgrade");
504 555 printf(" %s\n", _("Do not run the upgrade. Probably not useful (without -u at least)."));
505 printf (" %s\n", "-n, --no-upgrade"); 556 printf(" %s\n", "-l, --list");
506 printf (" %s\n", _("Do not run the upgrade. Probably not useful (without -u at least).")); 557 printf(" %s\n", _("List packages available for upgrade. Packages are printed sorted by"));
507 printf (" %s\n", "-l, --list"); 558 printf(" %s\n", _("name with security packages listed first."));
508 printf (" %s\n", _("List packages available for upgrade. Packages are printed sorted by")); 559 printf(" %s\n", "-i, --include=REGEXP");
509 printf (" %s\n", _("name with security packages listed first.")); 560 printf(" %s\n", _("Include only packages matching REGEXP. Can be specified multiple times"));
510 printf (" %s\n", "-i, --include=REGEXP"); 561 printf(" %s\n", _("the values will be combined together. Any packages matching this list"));
511 printf (" %s\n", _("Include only packages matching REGEXP. Can be specified multiple times")); 562 printf(" %s\n", _("cause the plugin to return WARNING status. Others will be ignored."));
512 printf (" %s\n", _("the values will be combined together. Any packages matching this list")); 563 printf(" %s\n", _("Default is to include all packages."));
513 printf (" %s\n", _("cause the plugin to return WARNING status. Others will be ignored.")); 564 printf(" %s\n", "-e, --exclude=REGEXP");
514 printf (" %s\n", _("Default is to include all packages.")); 565 printf(" %s\n", _("Exclude packages matching REGEXP from the list of packages that would"));
515 printf (" %s\n", "-e, --exclude=REGEXP"); 566 printf(" %s\n", _("otherwise be included. Can be specified multiple times; the values"));
516 printf (" %s\n", _("Exclude packages matching REGEXP from the list of packages that would")); 567 printf(" %s\n", _("will be combined together. Default is to exclude no packages."));
517 printf (" %s\n", _("otherwise be included. Can be specified multiple times; the values")); 568 printf(" %s\n", "-c, --critical=REGEXP");
518 printf (" %s\n", _("will be combined together. Default is to exclude no packages.")); 569 printf(" %s\n", _("If the full package information of any of the upgradable packages match"));
519 printf (" %s\n", "-c, --critical=REGEXP"); 570 printf(" %s\n", _("this REGEXP, the plugin will return CRITICAL status. Can be specified"));
520 printf (" %s\n", _("If the full package information of any of the upgradable packages match")); 571 printf(" %s\n", _("multiple times like above. Default is a regexp matching security"));
521 printf (" %s\n", _("this REGEXP, the plugin will return CRITICAL status. Can be specified")); 572 printf(" %s\n", _("upgrades for Debian and Ubuntu:"));
522 printf (" %s\n", _("multiple times like above. Default is a regexp matching security")); 573 printf(" \t%s\n", SECURITY_RE);
523 printf (" %s\n", _("upgrades for Debian and Ubuntu:")); 574 printf(" %s\n", _("Note that the package must first match the include list before its"));
524 printf (" \t%s\n", SECURITY_RE); 575 printf(" %s\n", _("information is compared against the critical list."));
525 printf (" %s\n", _("Note that the package must first match the include list before its")); 576 printf(" %s\n", "-o, --only-critical");
526 printf (" %s\n", _("information is compared against the critical list.")); 577 printf(" %s\n", _("Only warn about upgrades matching the critical list. The total number"));
527 printf (" %s\n", "-o, --only-critical"); 578 printf(" %s\n", _("of upgrades will be printed, but any non-critical upgrades will not cause"));
528 printf (" %s\n", _("Only warn about upgrades matching the critical list. The total number")); 579 printf(" %s\n", _("the plugin to return WARNING status."));
529 printf (" %s\n", _("of upgrades will be printed, but any non-critical upgrades will not cause")); 580 printf(" %s\n", "-w, --packages-warning");
530 printf (" %s\n", _("the plugin to return WARNING status.")); 581 printf(" %s\n", _("Minimum number of packages available for upgrade to return WARNING status."));
531 printf (" %s\n", "-w, --packages-warning"); 582 printf(" %s\n\n", _("Default is 1 package."));
532 printf (" %s\n", _("Minimum number of packages available for upgrade to return WARNING status.")); 583
533 printf (" %s\n\n", _("Default is 1 package.")); 584 printf("%s\n\n", _("The following options require root privileges and should be used with care:"));
534 585 printf(" %s\n", "-u, --update=OPTS");
535 printf ("%s\n\n", _("The following options require root privileges and should be used with care:")); 586 printf(" %s\n", _("First perform an 'apt-get update'. An optional OPTS parameter overrides"));
536 printf (" %s\n", "-u, --update=OPTS"); 587 printf(" %s\n", _("the default options. Note: you may also need to adjust the global"));
537 printf (" %s\n", _("First perform an 'apt-get update'. An optional OPTS parameter overrides")); 588 printf(" %s\n", _("timeout (with -t) to prevent the plugin from timing out if apt-get"));
538 printf (" %s\n", _("the default options. Note: you may also need to adjust the global")); 589 printf(" %s\n", _("upgrade is expected to take longer than the default timeout."));
539 printf (" %s\n", _("timeout (with -t) to prevent the plugin from timing out if apt-get")); 590 printf(" %s\n", "-U, --upgrade=OPTS");
540 printf (" %s\n", _("upgrade is expected to take longer than the default timeout.")); 591 printf(" %s\n", _("Perform an upgrade. If an optional OPTS argument is provided,"));
541 printf (" %s\n", "-U, --upgrade=OPTS"); 592 printf(" %s\n", _("apt-get will be run with these command line options instead of the"));
542 printf (" %s\n", _("Perform an upgrade. If an optional OPTS argument is provided,")); 593 printf(" %s", _("default "));
543 printf (" %s\n", _("apt-get will be run with these command line options instead of the")); 594 printf("(%s).\n", UPGRADE_DEFAULT_OPTS);
544 printf (" %s", _("default ")); 595 printf(" %s\n", _("Note that you may be required to have root privileges if you do not use"));
545 printf ("(%s).\n", UPGRADE_DEFAULT_OPTS); 596 printf(" %s\n", _("the default options, which will only run a simulation and NOT perform the upgrade"));
546 printf (" %s\n", _("Note that you may be required to have root privileges if you do not use")); 597 printf(" %s\n", "-d, --dist-upgrade=OPTS");
547 printf (" %s\n", _("the default options, which will only run a simulation and NOT perform the upgrade")); 598 printf(" %s\n", _("Perform a dist-upgrade instead of normal upgrade. Like with -U OPTS"));
548 printf (" %s\n", "-d, --dist-upgrade=OPTS"); 599 printf(" %s\n", _("can be provided to override the default options."));
549 printf (" %s\n", _("Perform a dist-upgrade instead of normal upgrade. Like with -U OPTS")); 600
550 printf (" %s\n", _("can be provided to override the default options.")); 601 printf(UT_SUPPORT);
551
552 printf(UT_SUPPORT);
553} 602}
554 603
555
556/* simple usage heading */ 604/* simple usage heading */
557void 605void print_usage(void) {
558print_usage(void) 606 printf("%s\n", _("Usage:"));
559{ 607 printf("%s [[-d|-u|-U]opts] [-n] [-l] [-t timeout] [-w packages-warning]\n", progname);
560 printf ("%s\n", _("Usage:"));
561 printf ("%s [[-d|-u|-U]opts] [-n] [-l] [-t timeout] [-w packages-warning]\n", progname);
562} 608}
diff --git a/plugins/check_curl.c b/plugins/check_curl.c
index 1d27da28..8ea73ce1 100644
--- a/plugins/check_curl.c
+++ b/plugins/check_curl.c
@@ -525,7 +525,7 @@ int check_http(void) {
525 // use the host_name later on to make SNI happy 525 // use the host_name later on to make SNI happy
526 if (use_ssl && host_name != NULL) { 526 if (use_ssl && host_name != NULL) {
527 if ((res = lookup_host(server_address, addrstr, DEFAULT_BUFFER_SIZE / 2)) != 0) { 527 if ((res = lookup_host(server_address, addrstr, DEFAULT_BUFFER_SIZE / 2)) != 0) {
528 snprintf(msg, DEFAULT_BUFFER_SIZE, _("Unable to lookup IP address for '%s': getaddrinfo returned %d - %d"), server_address, res, 528 snprintf(msg, DEFAULT_BUFFER_SIZE, _("Unable to lookup IP address for '%s': getaddrinfo returned %d - %s"), server_address, res,
529 gai_strerror(res)); 529 gai_strerror(res));
530 die(STATE_CRITICAL, "HTTP CRITICAL - %s\n", msg); 530 die(STATE_CRITICAL, "HTTP CRITICAL - %s\n", msg);
531 } 531 }
diff --git a/plugins/check_disk.c b/plugins/check_disk.c
index d1d1b92a..037a6f7a 100644
--- a/plugins/check_disk.c
+++ b/plugins/check_disk.c
@@ -156,20 +156,20 @@ static struct name_list *seen = NULL;
156int main(int argc, char **argv) { 156int main(int argc, char **argv) {
157 int result = STATE_UNKNOWN; 157 int result = STATE_UNKNOWN;
158 int disk_result = STATE_UNKNOWN; 158 int disk_result = STATE_UNKNOWN;
159 char *output; 159 char *output = NULL;
160 char *ignored; 160 char *ignored = NULL;
161 char *details; 161 char *details = NULL;
162 char *perf; 162 char *perf = NULL;
163 char *perf_ilabel; 163 char *perf_ilabel = NULL;
164 char *preamble = " - free space:"; 164 char *preamble = " - free space:";
165 char *ignored_preamble = " - ignored paths:"; 165 char *ignored_preamble = " - ignored paths:";
166 char *flag_header; 166 char *flag_header = NULL;
167 int temp_result; 167 int temp_result = STATE_UNKNOWN;
168 168
169 struct mount_entry *me; 169 struct mount_entry *me = NULL;
170 struct fs_usage fsp; 170 struct fs_usage fsp = {0};
171 struct parameter_list *temp_list; 171 struct parameter_list *temp_list = NULL;
172 struct parameter_list *path; 172 struct parameter_list *path = NULL;
173 173
174#ifdef __CYGWIN__ 174#ifdef __CYGWIN__
175 char mountdir[32]; 175 char mountdir[32];
diff --git a/plugins/check_fping.c b/plugins/check_fping.c
index 49235e28..c1d03ece 100644
--- a/plugins/check_fping.c
+++ b/plugins/check_fping.c
@@ -7,7 +7,7 @@
7 * 7 *
8 * Description: 8 * Description:
9 * 9 *
10 * This file contains the check_disk plugin 10 * This file contains the check_fping plugin
11 * 11 *
12 * This plugin will use the fping command to ping the specified host for a 12 * This plugin will use the fping command to ping the specified host for a
13 * fast check 13 * fast check
@@ -60,6 +60,8 @@ static int packet_count = PACKET_COUNT;
60static int target_timeout = 0; 60static int target_timeout = 0;
61static int packet_interval = 0; 61static int packet_interval = 0;
62static bool verbose = false; 62static bool verbose = false;
63static bool dontfrag = false;
64static bool randomize_packet_data = false;
63static int cpl; 65static int cpl;
64static int wpl; 66static int wpl;
65static double crta; 67static double crta;
@@ -103,6 +105,11 @@ int main(int argc, char **argv) {
103 xasprintf(&option_string, "%s-S %s ", option_string, sourceip); 105 xasprintf(&option_string, "%s-S %s ", option_string, sourceip);
104 if (sourceif) 106 if (sourceif)
105 xasprintf(&option_string, "%s-I %s ", option_string, sourceif); 107 xasprintf(&option_string, "%s-I %s ", option_string, sourceif);
108 if (dontfrag)
109 xasprintf(&option_string, "%s-M ", option_string);
110 if (randomize_packet_data)
111 xasprintf(&option_string, "%s-R ", option_string);
112
106 113
107#ifdef PATH_TO_FPING6 114#ifdef PATH_TO_FPING6
108 if (address_family != AF_INET && is_inet6_addr(server)) 115 if (address_family != AF_INET && is_inet6_addr(server))
@@ -279,6 +286,8 @@ int process_arguments(int argc, char **argv) {
279 {"help", no_argument, 0, 'h'}, 286 {"help", no_argument, 0, 'h'},
280 {"use-ipv4", no_argument, 0, '4'}, 287 {"use-ipv4", no_argument, 0, '4'},
281 {"use-ipv6", no_argument, 0, '6'}, 288 {"use-ipv6", no_argument, 0, '6'},
289 {"dontfrag", no_argument, 0, 'M'},
290 {"random", no_argument, 0, 'R'},
282 {0, 0, 0, 0}}; 291 {0, 0, 0, 0}};
283 292
284 rv[PL] = NULL; 293 rv[PL] = NULL;
@@ -295,7 +304,7 @@ int process_arguments(int argc, char **argv) {
295 } 304 }
296 305
297 while (1) { 306 while (1) {
298 c = getopt_long(argc, argv, "+hVvaH:S:c:w:b:n:T:i:I:46", longopts, &option); 307 c = getopt_long(argc, argv, "+hVvaH:S:c:w:b:n:T:i:I:M:R:46", longopts, &option);
299 308
300 if (c == -1 || c == EOF || c == 1) 309 if (c == -1 || c == EOF || c == 1)
301 break; 310 break;
@@ -390,6 +399,12 @@ int process_arguments(int argc, char **argv) {
390 else 399 else
391 usage(_("Interval must be a positive integer")); 400 usage(_("Interval must be a positive integer"));
392 break; 401 break;
402 case 'R':
403 randomize_packet_data = true;
404 break;
405 case 'M':
406 dontfrag = true;
407 break;
393 } 408 }
394 } 409 }
395 410
@@ -470,6 +485,10 @@ void print_help(void) {
470 printf(" %s\n", _("name or IP Address of sourceip")); 485 printf(" %s\n", _("name or IP Address of sourceip"));
471 printf(" %s\n", "-I, --sourceif=IF"); 486 printf(" %s\n", "-I, --sourceif=IF");
472 printf(" %s\n", _("source interface name")); 487 printf(" %s\n", _("source interface name"));
488 printf(" %s\n", "-M, --dontfrag");
489 printf(" %s\n", _("set the Don't Fragment flag"));
490 printf(" %s\n", "-R, --random");
491 printf(" %s\n", _("random packet data (to foil link data compression)"));
473 printf(UT_VERBOSE); 492 printf(UT_VERBOSE);
474 printf("\n"); 493 printf("\n");
475 printf(" %s\n", _("THRESHOLD is <rta>,<pl>%% where <rta> is the round trip average travel time (ms)")); 494 printf(" %s\n", _("THRESHOLD is <rta>,<pl>%% where <rta> is the round trip average travel time (ms)"));
diff --git a/plugins/check_ide_smart.c b/plugins/check_ide_smart.c
index 381dbd80..9640ef70 100644
--- a/plugins/check_ide_smart.c
+++ b/plugins/check_ide_smart.c
@@ -113,12 +113,10 @@ typedef struct values_s {
113 __u8 checksum; 113 __u8 checksum;
114} __attribute__((packed)) values_t; 114} __attribute__((packed)) values_t;
115 115
116struct { 116static struct {
117 __u8 value; 117 __u8 value;
118 char *text; 118 char *text;
119} 119} offline_status_text[] = {{0x00, "NeverStarted"}, {0x02, "Completed"}, {0x04, "Suspended"},
120
121static offline_status_text[] = {{0x00, "NeverStarted"}, {0x02, "Completed"}, {0x04, "Suspended"},
122 {0x05, "Aborted"}, {0x06, "Failed"}, {0, 0}}; 120 {0x05, "Aborted"}, {0x06, "Failed"}, {0, 0}};
123 121
124static struct { 122static struct {
diff --git a/plugins/check_ldap.c b/plugins/check_ldap.c
index 1c728292..87818da6 100644
--- a/plugins/check_ldap.c
+++ b/plugins/check_ldap.c
@@ -47,37 +47,37 @@ enum {
47 DEFAULT_PORT = 389 47 DEFAULT_PORT = 389
48}; 48};
49 49
50int process_arguments (int, char **); 50static int process_arguments (int, char **);
51int validate_arguments (void); 51static int validate_arguments (void);
52void print_help (void); 52static void print_help (void);
53void print_usage (void); 53void print_usage (void);
54 54
55char ld_defattr[] = "(objectclass=*)"; 55static char ld_defattr[] = "(objectclass=*)";
56char *ld_attr = ld_defattr; 56static char *ld_attr = ld_defattr;
57char *ld_host = NULL; 57static char *ld_host = NULL;
58char *ld_base = NULL; 58static char *ld_base = NULL;
59char *ld_passwd = NULL; 59static char *ld_passwd = NULL;
60char *ld_binddn = NULL; 60static char *ld_binddn = NULL;
61int ld_port = -1; 61static int ld_port = -1;
62#ifdef HAVE_LDAP_SET_OPTION 62#ifdef HAVE_LDAP_SET_OPTION
63int ld_protocol = DEFAULT_PROTOCOL; 63static int ld_protocol = DEFAULT_PROTOCOL;
64#endif 64#endif
65#ifndef LDAP_OPT_SUCCESS 65#ifndef LDAP_OPT_SUCCESS
66# define LDAP_OPT_SUCCESS LDAP_SUCCESS 66# define LDAP_OPT_SUCCESS LDAP_SUCCESS
67#endif 67#endif
68double warn_time = UNDEFINED; 68static double warn_time = UNDEFINED;
69double crit_time = UNDEFINED; 69static double crit_time = UNDEFINED;
70thresholds *entries_thresholds = NULL; 70static thresholds *entries_thresholds = NULL;
71struct timeval tv; 71static struct timeval tv;
72char* warn_entries = NULL; 72static char* warn_entries = NULL;
73char* crit_entries = NULL; 73static char* crit_entries = NULL;
74bool starttls = false; 74static bool starttls = false;
75bool ssl_on_connect = false; 75static bool ssl_on_connect = false;
76bool verbose = false; 76static bool verbose = false;
77 77
78/* for ldap tls */ 78/* for ldap tls */
79 79
80char *SERVICE = "LDAP"; 80static char *SERVICE = "LDAP";
81 81
82int 82int
83main (int argc, char *argv[]) 83main (int argc, char *argv[])
diff --git a/plugins/check_mysql.c b/plugins/check_mysql.c
index 1f0b7099..8a73772d 100644
--- a/plugins/check_mysql.c
+++ b/plugins/check_mysql.c
@@ -45,23 +45,23 @@ const char *email = "devel@monitoring-plugins.org";
45#include <mysqld_error.h> 45#include <mysqld_error.h>
46#include <errmsg.h> 46#include <errmsg.h>
47 47
48char *db_user = NULL; 48static char *db_user = NULL;
49char *db_host = NULL; 49static char *db_host = NULL;
50char *db_socket = NULL; 50static char *db_socket = NULL;
51char *db_pass = NULL; 51static char *db_pass = NULL;
52char *db = NULL; 52static char *db = NULL;
53char *ca_cert = NULL; 53static char *ca_cert = NULL;
54char *ca_dir = NULL; 54static char *ca_dir = NULL;
55char *cert = NULL; 55static char *cert = NULL;
56char *key = NULL; 56static char *key = NULL;
57char *ciphers = NULL; 57static char *ciphers = NULL;
58bool ssl = false; 58static bool ssl = false;
59char *opt_file = NULL; 59static char *opt_file = NULL;
60char *opt_group = NULL; 60static char *opt_group = NULL;
61unsigned int db_port = MYSQL_PORT; 61static unsigned int db_port = MYSQL_PORT;
62bool check_slave = false; 62static bool check_slave = false;
63bool ignore_auth = false; 63static bool ignore_auth = false;
64int verbose = 0; 64static int verbose = 0;
65 65
66static double warning_time = 0; 66static double warning_time = 0;
67static double critical_time = 0; 67static double critical_time = 0;
@@ -91,11 +91,11 @@ static const char *metric_counter[LENGTH_METRIC_COUNTER] = {
91 91
92#define MYSQLDUMP_THREADS_QUERY "SELECT COUNT(1) mysqldumpThreads FROM information_schema.processlist WHERE info LIKE 'SELECT /*!40001 SQL_NO_CACHE */%'" 92#define MYSQLDUMP_THREADS_QUERY "SELECT COUNT(1) mysqldumpThreads FROM information_schema.processlist WHERE info LIKE 'SELECT /*!40001 SQL_NO_CACHE */%'"
93 93
94thresholds *my_threshold = NULL; 94static thresholds *my_threshold = NULL;
95 95
96int process_arguments (int, char **); 96static int process_arguments (int, char **);
97int validate_arguments (void); 97static int validate_arguments (void);
98void print_help (void); 98static void print_help (void);
99void print_usage (void); 99void print_usage (void);
100 100
101int 101int
diff --git a/plugins/check_nt.c b/plugins/check_nt.c
index 413aad6b..dec0b668 100644
--- a/plugins/check_nt.c
+++ b/plugins/check_nt.c
@@ -59,26 +59,25 @@ enum {
59 PORT = 1248 59 PORT = 1248
60}; 60};
61 61
62char *server_address = NULL; 62static char *server_address = NULL;
63char *volume_name = NULL; 63static int server_port = PORT;
64int server_port = PORT; 64static char *value_list = NULL;
65char *value_list = NULL; 65static char *req_password = NULL;
66char *req_password = NULL; 66static unsigned long lvalue_list[MAX_VALUE_LIST];
67unsigned long lvalue_list[MAX_VALUE_LIST]; 67static unsigned long warning_value = 0L;
68unsigned long warning_value = 0L; 68static unsigned long critical_value = 0L;
69unsigned long critical_value = 0L; 69static bool check_warning_value = false;
70bool check_warning_value = false; 70static bool check_critical_value = false;
71bool check_critical_value = false; 71static enum checkvars vars_to_check = CHECK_NONE;
72enum checkvars vars_to_check = CHECK_NONE; 72static bool show_all = false;
73bool show_all = false; 73
74 74static char recv_buffer[MAX_INPUT_BUFFER];
75char recv_buffer[MAX_INPUT_BUFFER]; 75
76 76static void fetch_data(const char *address, int port, const char *sendb);
77void fetch_data(const char *address, int port, const char *sendb); 77static int process_arguments(int /*argc*/, char ** /*argv*/);
78int process_arguments(int, char **); 78static void preparelist(char *string);
79void preparelist(char *string); 79static bool strtoularray(unsigned long *array, char *string, const char *delim);
80bool strtoularray(unsigned long *array, char *string, const char *delim); 80static void print_help(void);
81void print_help(void);
82void print_usage(void); 81void print_usage(void);
83 82
84int main(int argc, char **argv) { 83int main(int argc, char **argv) {
diff --git a/plugins/check_ntp.c b/plugins/check_ntp.c
index 55a49460..d33f8786 100644
--- a/plugins/check_ntp.c
+++ b/plugins/check_ntp.c
@@ -47,10 +47,10 @@ static bool do_jitter = false;
47static char *jwarn="5000"; 47static char *jwarn="5000";
48static char *jcrit="10000"; 48static char *jcrit="10000";
49 49
50int process_arguments (int, char **); 50static int process_arguments (int /*argc*/, char ** /*argv*/);
51thresholds *offset_thresholds = NULL; 51static thresholds *offset_thresholds = NULL;
52thresholds *jitter_thresholds = NULL; 52static thresholds *jitter_thresholds = NULL;
53void print_help (void); 53static void print_help (void);
54void print_usage (void); 54void print_usage (void);
55 55
56/* number of times to perform each request to get a good average. */ 56/* number of times to perform each request to get a good average. */
diff --git a/plugins/check_nwstat.c b/plugins/check_nwstat.c
index 3af63603..176dfbc8 100644
--- a/plugins/check_nwstat.c
+++ b/plugins/check_nwstat.c
@@ -89,30 +89,30 @@ enum {
89 PORT = 9999 89 PORT = 9999
90}; 90};
91 91
92char *server_address = NULL; 92static char *server_address = NULL;
93char *volume_name = NULL; 93static char *volume_name = NULL;
94char *nlm_name = NULL; 94static char *nlm_name = NULL;
95char *nrmp_name = NULL; 95static char *nrmp_name = NULL;
96char *nrmm_name = NULL; 96static char *nrmm_name = NULL;
97char *nrms_name = NULL; 97static char *nrms_name = NULL;
98char *nss1_name = NULL; 98static char *nss1_name = NULL;
99char *nss2_name = NULL; 99static char *nss2_name = NULL;
100char *nss3_name = NULL; 100static char *nss3_name = NULL;
101char *nss4_name = NULL; 101static char *nss4_name = NULL;
102char *nss5_name = NULL; 102static char *nss5_name = NULL;
103char *nss6_name = NULL; 103static char *nss6_name = NULL;
104char *nss7_name = NULL; 104static char *nss7_name = NULL;
105int server_port = PORT; 105static int server_port = PORT;
106unsigned long warning_value = 0L; 106static unsigned long warning_value = 0L;
107unsigned long critical_value = 0L; 107static unsigned long critical_value = 0L;
108bool check_warning_value = false; 108static bool check_warning_value = false;
109bool check_critical_value = false; 109static bool check_critical_value = false;
110bool check_netware_version = false; 110static bool check_netware_version = false;
111enum checkvar vars_to_check = NONE; 111static enum checkvar vars_to_check = NONE;
112int sap_number = -1; 112static int sap_number = -1;
113 113
114int process_arguments(int, char **); 114static int process_arguments(int /*argc*/, char ** /*argv*/);
115void print_help(void); 115static void print_help(void);
116void print_usage(void); 116void print_usage(void);
117 117
118int main(int argc, char **argv) { 118int main(int argc, char **argv) {
diff --git a/plugins/check_overcr.c b/plugins/check_overcr.c
index e80d4775..599540b7 100644
--- a/plugins/check_overcr.c
+++ b/plugins/check_overcr.c
@@ -52,23 +52,22 @@ enum {
52 PORT = 2000 52 PORT = 2000
53}; 53};
54 54
55char *server_address = NULL; 55static char *server_address = NULL;
56int server_port = PORT; 56static int server_port = PORT;
57double warning_value = 0L; 57static double warning_value = 0L;
58double critical_value = 0L; 58static double critical_value = 0L;
59bool check_warning_value = false; 59static bool check_warning_value = false;
60bool check_critical_value = false; 60static bool check_critical_value = false;
61enum checkvar vars_to_check = NONE; 61static enum checkvar vars_to_check = NONE;
62int cmd_timeout = 1; 62
63 63static int netstat_port = 0;
64int netstat_port = 0; 64static char *disk_name = NULL;
65char *disk_name = NULL; 65static char *process_name = NULL;
66char *process_name = NULL; 66static char send_buffer[MAX_INPUT_BUFFER];
67char send_buffer[MAX_INPUT_BUFFER]; 67
68 68static int process_arguments(int, char **);
69int process_arguments(int, char **);
70void print_usage(void); 69void print_usage(void);
71void print_help(void); 70static void print_help(void);
72 71
73int main(int argc, char **argv) { 72int main(int argc, char **argv) {
74 int result = STATE_UNKNOWN; 73 int result = STATE_UNKNOWN;
diff --git a/plugins/check_procs.c b/plugins/check_procs.c
index 5777ba07..1d78ccee 100644
--- a/plugins/check_procs.c
+++ b/plugins/check_procs.c
@@ -51,17 +51,17 @@ const char *email = "devel@monitoring-plugins.org";
51#include <sys/stat.h> 51#include <sys/stat.h>
52#endif 52#endif
53 53
54int process_arguments (int, char **); 54static int process_arguments (int /*argc*/, char ** /*argv*/);
55int validate_arguments (void); 55static int validate_arguments (void);
56int convert_to_seconds (char *); 56static int convert_to_seconds (char * /*etime*/);
57void print_help (void); 57static void print_help (void);
58void print_usage (void); 58void print_usage (void);
59 59
60char *warning_range = NULL; 60static char *warning_range = NULL;
61char *critical_range = NULL; 61static char *critical_range = NULL;
62thresholds *procs_thresholds = NULL; 62static thresholds *procs_thresholds = NULL;
63 63
64int options = 0; /* bitmask of filter criteria to test against */ 64static int options = 0; /* bitmask of filter criteria to test against */
65#define ALL 1 65#define ALL 1
66#define STAT 2 66#define STAT 2
67#define PPID 4 67#define PPID 4
@@ -89,27 +89,25 @@ enum metric {
89}; 89};
90enum metric metric = METRIC_PROCS; 90enum metric metric = METRIC_PROCS;
91 91
92int verbose = 0; 92static int verbose = 0;
93int uid; 93static int uid;
94pid_t ppid; 94static pid_t ppid;
95int vsz; 95static int vsz;
96int rss; 96static int rss;
97float pcpu; 97static float pcpu;
98char *statopts; 98static char *statopts;
99char *prog; 99static char *prog;
100char *exclude_progs; 100static char *exclude_progs;
101char **exclude_progs_arr = NULL; 101static char **exclude_progs_arr = NULL;
102char exclude_progs_counter = 0; 102static char exclude_progs_counter = 0;
103char *args; 103static char *args;
104char *input_filename = NULL; 104static char *input_filename = NULL;
105regex_t re_args; 105static regex_t re_args;
106char *fmt; 106static char *fmt;
107char *fails; 107static char *fails;
108char tmp[MAX_INPUT_BUFFER]; 108static char tmp[MAX_INPUT_BUFFER];
109int kthread_filter = 0; 109static int kthread_filter = 0;
110int usepid = 0; /* whether to test for pid or /proc/pid/exe */ 110static int usepid = 0; /* whether to test for pid or /proc/pid/exe */
111
112FILE *ps_input = NULL;
113 111
114static int 112static int
115stat_exe (const pid_t pid, struct stat *buf) { 113stat_exe (const pid_t pid, struct stat *buf) {
@@ -834,7 +832,7 @@ be the total number of running processes\n\n"));
834 printf (" %s\n", "check_procs -w 50000 -c 100000 --metric=VSZ"); 832 printf (" %s\n", "check_procs -w 50000 -c 100000 --metric=VSZ");
835 printf (" %s\n\n", _("Alert if VSZ of any processes over 50K or 100K")); 833 printf (" %s\n\n", _("Alert if VSZ of any processes over 50K or 100K"));
836 printf (" %s\n", "check_procs -w 10 -c 20 --metric=CPU"); 834 printf (" %s\n", "check_procs -w 10 -c 20 --metric=CPU");
837 printf (" %s\n", _("Alert if CPU of any processes over 10\% or 20\%")); 835 printf (" %s\n", _("Alert if CPU of any processes over 10%% or 20%%"));
838 836
839 printf (UT_SUPPORT); 837 printf (UT_SUPPORT);
840} 838}
diff --git a/plugins/check_radius.c b/plugins/check_radius.c
index 8ed19e55..d9ff8fa7 100644
--- a/plugins/check_radius.c
+++ b/plugins/check_radius.c
@@ -46,8 +46,8 @@ const char *email = "devel@monitoring-plugins.org";
46#include <radiusclient.h> 46#include <radiusclient.h>
47#endif 47#endif
48 48
49int process_arguments (int, char **); 49static int process_arguments (int /*argc*/, char ** /*argv*/);
50void print_help (void); 50static void print_help (void);
51void print_usage (void); 51void print_usage (void);
52 52
53#if defined(HAVE_LIBFREERADIUS_CLIENT) || defined(HAVE_LIBRADIUSCLIENT_NG) || defined(HAVE_LIBRADCLI) 53#if defined(HAVE_LIBFREERADIUS_CLIENT) || defined(HAVE_LIBRADIUSCLIENT_NG) || defined(HAVE_LIBRADCLI)
@@ -78,22 +78,22 @@ void print_usage (void);
78#define REJECT_RC BADRESP_RC 78#define REJECT_RC BADRESP_RC
79#endif 79#endif
80 80
81int my_rc_read_config(char *); 81static int my_rc_read_config(char * /*a*/);
82 82
83#if defined(HAVE_LIBFREERADIUS_CLIENT) || defined(HAVE_LIBRADIUSCLIENT_NG) || defined(HAVE_LIBRADCLI) 83#if defined(HAVE_LIBFREERADIUS_CLIENT) || defined(HAVE_LIBRADIUSCLIENT_NG) || defined(HAVE_LIBRADCLI)
84rc_handle *rch = NULL; 84static rc_handle *rch = NULL;
85#endif 85#endif
86 86
87char *server = NULL; 87static char *server = NULL;
88char *username = NULL; 88static char *username = NULL;
89char *password = NULL; 89static char *password = NULL;
90char *nasid = NULL; 90static char *nasid = NULL;
91char *nasipaddress = NULL; 91static char *nasipaddress = NULL;
92char *expect = NULL; 92static char *expect = NULL;
93char *config_file = NULL; 93static char *config_file = NULL;
94unsigned short port = PW_AUTH_UDP_PORT; 94static unsigned short port = PW_AUTH_UDP_PORT;
95int retries = 1; 95static int retries = 1;
96bool verbose = false; 96static bool verbose = false;
97 97
98/****************************************************************************** 98/******************************************************************************
99 99
diff --git a/plugins/check_smtp.c b/plugins/check_smtp.c
index bc175287..e6369e63 100644
--- a/plugins/check_smtp.c
+++ b/plugins/check_smtp.c
@@ -40,8 +40,8 @@ const char *email = "devel@monitoring-plugins.org";
40#include <ctype.h> 40#include <ctype.h>
41 41
42#ifdef HAVE_SSL 42#ifdef HAVE_SSL
43bool check_cert = false; 43static bool check_cert = false;
44int days_till_exp_warn, days_till_exp_crit; 44static int days_till_exp_warn, days_till_exp_crit;
45# define my_recv(buf, len) (((use_starttls || use_ssl) && ssl_established) ? np_net_ssl_read(buf, len) : read(sd, buf, len)) 45# define my_recv(buf, len) (((use_starttls || use_ssl) && ssl_established) ? np_net_ssl_read(buf, len) : read(sd, buf, len))
46# define my_send(buf, len) (((use_starttls || use_ssl) && ssl_established) ? np_net_ssl_write(buf, len) : send(sd, buf, len, 0)) 46# define my_send(buf, len) (((use_starttls || 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 */
@@ -64,61 +64,59 @@ enum {
64 64
65#define EHLO_SUPPORTS_STARTTLS 1 65#define EHLO_SUPPORTS_STARTTLS 1
66 66
67int process_arguments (int, char **); 67static int process_arguments (int, char **);
68int validate_arguments (void); 68static int validate_arguments (void);
69void print_help (void); 69static void print_help (void);
70void print_usage (void); 70void print_usage (void);
71void smtp_quit(void); 71static void smtp_quit(void);
72int recvline(char *, size_t); 72static int recvline(char *, size_t);
73int recvlines(char *, size_t); 73static int recvlines(char *, size_t);
74int my_close(void); 74static int my_close(void);
75 75
76#include "regex.h" 76#include "regex.h"
77char regex_expect[MAX_INPUT_BUFFER] = ""; 77static regex_t preg;
78regex_t preg; 78static regmatch_t pmatch[10];
79regmatch_t pmatch[10]; 79static char errbuf[MAX_INPUT_BUFFER];
80char timestamp[20] = ""; 80static int cflags = REG_EXTENDED | REG_NOSUB | REG_NEWLINE;
81char errbuf[MAX_INPUT_BUFFER]; 81static int eflags = 0;
82int cflags = REG_EXTENDED | REG_NOSUB | REG_NEWLINE; 82static int errcode, excode;
83int eflags = 0; 83
84int errcode, excode; 84static int server_port = SMTP_PORT;
85 85static int server_port_option = 0;
86int server_port = SMTP_PORT; 86static char *server_address = NULL;
87int server_port_option = 0; 87static char *server_expect = NULL;
88char *server_address = NULL; 88static char *mail_command = NULL;
89char *server_expect = NULL; 89static char *from_arg = NULL;
90char *mail_command = NULL; 90static int send_mail_from=0;
91char *from_arg = NULL; 91static int ncommands=0;
92int send_mail_from=0; 92static int command_size=0;
93int ncommands=0; 93static int nresponses=0;
94int command_size=0; 94static int response_size=0;
95int nresponses=0; 95static char **commands = NULL;
96int response_size=0; 96static char **responses = NULL;
97char **commands = NULL; 97static char *authtype = NULL;
98char **responses = NULL; 98static char *authuser = NULL;
99char *authtype = NULL; 99static char *authpass = NULL;
100char *authuser = NULL; 100static double warning_time = 0;
101char *authpass = NULL; 101static bool check_warning_time = false;
102double warning_time = 0; 102static double critical_time = 0;
103bool check_warning_time = false; 103static bool check_critical_time = false;
104double critical_time = 0; 104static int verbose = 0;
105bool check_critical_time = false; 105static bool use_ssl = false;
106int verbose = 0; 106static bool use_starttls = false;
107bool use_ssl = false; 107static bool use_sni = false;
108bool use_starttls = false; 108static bool use_proxy_prefix = false;
109bool use_sni = false; 109static bool use_ehlo = false;
110bool use_proxy_prefix = false; 110static bool use_lhlo = false;
111bool use_ehlo = false; 111static bool ssl_established = false;
112bool use_lhlo = false; 112static char *localhostname = NULL;
113bool ssl_established = false; 113static int sd;
114char *localhostname = NULL; 114static char buffer[MAX_INPUT_BUFFER];
115int sd;
116char buffer[MAX_INPUT_BUFFER];
117enum { 115enum {
118 TCP_PROTOCOL = 1, 116 TCP_PROTOCOL = 1,
119 UDP_PROTOCOL = 2, 117 UDP_PROTOCOL = 2,
120}; 118};
121bool ignore_send_quit_failure = false; 119static bool ignore_send_quit_failure = false;
122 120
123 121
124int 122int
diff --git a/plugins/check_tcp.c b/plugins/check_tcp.c
index c13ac767..49ad096c 100644
--- a/plugins/check_tcp.c
+++ b/plugins/check_tcp.c
@@ -119,7 +119,7 @@ int main(int argc, char **argv) {
119 119
120 /* set up a reasonable buffer at first (will be realloc()'ed if 120 /* set up a reasonable buffer at first (will be realloc()'ed if
121 * user specifies other options) */ 121 * user specifies other options) */
122 server_expect = calloc(sizeof(char *), 2); 122 server_expect = calloc(2, sizeof(char *));
123 123
124 /* determine defaults for this service's protocol */ 124 /* determine defaults for this service's protocol */
125 if (!strncmp(SERVICE, "UDP", 3)) { 125 if (!strncmp(SERVICE, "UDP", 3)) {
diff --git a/plugins/check_ups.c b/plugins/check_ups.c
index adb7ab81..526a29df 100644
--- a/plugins/check_ups.c
+++ b/plugins/check_ups.c
@@ -97,12 +97,12 @@ ups_config ups_config_init(void) {
97} 97}
98 98
99// Forward declarations 99// Forward declarations
100int determine_status(ups_config *, int *supported_options); 100static int determine_status(ups_config * /*config*/, int *supported_options);
101int get_ups_variable(const char *, char *, const ups_config config); 101static int get_ups_variable(const char * /*varname*/, char * /*buf*/, ups_config config);
102 102
103int process_arguments(int, char **, ups_config *); 103static int process_arguments(int /*argc*/, char ** /*argv*/, ups_config * /*config*/);
104int validate_arguments(ups_config); 104static int validate_arguments(ups_config /*config*/);
105void print_help(void); 105static void print_help(void);
106void print_usage(void); 106void print_usage(void);
107 107
108int main(int argc, char **argv) { 108int main(int argc, char **argv) {
diff --git a/plugins/runcmd.c b/plugins/runcmd.c
index 2e53dc0b..74843149 100644
--- a/plugins/runcmd.c
+++ b/plugins/runcmd.c
@@ -130,7 +130,7 @@ static int np_runcmd_open(const char *cmdstring, int *pfd, int *pfderr) {
130 /* each arg must be whitespace-separated, so args can be a maximum 130 /* each arg must be whitespace-separated, so args can be a maximum
131 * of (len / 2) + 1. We add 1 extra to the mix for NULL termination */ 131 * of (len / 2) + 1. We add 1 extra to the mix for NULL termination */
132 argc = (cmdlen >> 1) + 2; 132 argc = (cmdlen >> 1) + 2;
133 argv = calloc(sizeof(char *), argc); 133 argv = calloc(argc, sizeof(char *));
134 134
135 if (argv == NULL) { 135 if (argv == NULL) {
136 printf("%s\n", _("Could not malloc argv array in popen()")); 136 printf("%s\n", _("Could not malloc argv array in popen()"));
diff --git a/plugins/utils.c b/plugins/utils.c
index f11db731..6d366e3d 100644
--- a/plugins/utils.c
+++ b/plugins/utils.c
@@ -185,7 +185,7 @@ bool is_percentage_expression(const char str[]) {
185 return false; 185 return false;
186 } 186 }
187 187
188 char *foo = calloc(sizeof(char), len + 1); 188 char *foo = calloc(len + 1, sizeof(char));
189 189
190 if (!foo) { 190 if (!foo) {
191 die(STATE_UNKNOWN, _("calloc failed \n")); 191 die(STATE_UNKNOWN, _("calloc failed \n"));