From ee1ba3209993b72e90f5fe30a16ad951f1e2402d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20K=C3=A4stle?= Date: Thu, 17 Oct 2024 17:57:50 +0200 Subject: lib: clang-format diff --git a/lib/extra_opts.c b/lib/extra_opts.c index 771621d..82460e9 100644 --- a/lib/extra_opts.c +++ b/lib/extra_opts.c @@ -1,24 +1,24 @@ /***************************************************************************** -* -* Monitoring Plugins extra_opts library -* -* License: GPL -* Copyright (c) 2007 Monitoring Plugins Development Team -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -* -*****************************************************************************/ + * + * Monitoring Plugins extra_opts library + * + * License: GPL + * Copyright (c) 2007 Monitoring Plugins Development Team + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + *****************************************************************************/ #include "common.h" #include "utils_base.h" @@ -26,110 +26,115 @@ #include "extra_opts.h" /* FIXME: copied from utils.h; we should move a bunch of libs! */ -bool is_option2 (char *str) -{ +bool is_option2(char *str) { if (!str) return false; - else if (strspn (str, "-") == 1 || strspn (str, "-") == 2) + else if (strspn(str, "-") == 1 || strspn(str, "-") == 2) return true; else return false; } /* this is the externally visible function used by plugins */ -char **np_extra_opts(int *argc, char **argv, const char *plugin_name){ - np_arg_list *extra_args=NULL, *ea1=NULL, *ea_tmp=NULL; - char **argv_new=NULL; - char *argptr=NULL; - int i, j, optfound, argc_new, ea_num=*argc; +char **np_extra_opts(int *argc, char **argv, const char *plugin_name) { + np_arg_list *extra_args = NULL, *ea1 = NULL, *ea_tmp = NULL; + char **argv_new = NULL; + char *argptr = NULL; + int i, j, optfound, argc_new, ea_num = *argc; - if(*argc<2) { + if (*argc < 2) { /* No arguments provided */ return argv; } - for(i=1; i<*argc; i++){ - argptr=NULL; - optfound=0; + for (i = 1; i < *argc; i++) { + argptr = NULL; + optfound = 0; /* Do we have an extra-opts parameter? */ - if(strncmp(argv[i], "--extra-opts=", 13)==0){ + if (strncmp(argv[i], "--extra-opts=", 13) == 0) { /* It is a single argument with value */ - argptr=argv[i]+13; + argptr = argv[i] + 13; /* Delete the extra opts argument */ - for(j=i;j<*argc;j++) argv[j]=argv[j+1]; + for (j = i; j < *argc; j++) + argv[j] = argv[j + 1]; i--; - *argc-=1; - }else if(strcmp(argv[i], "--extra-opts")==0){ - if((i+1<*argc)&&!is_option2(argv[i+1])){ + *argc -= 1; + } else if (strcmp(argv[i], "--extra-opts") == 0) { + if ((i + 1 < *argc) && !is_option2(argv[i + 1])) { /* It is a argument with separate value */ - argptr=argv[i+1]; + argptr = argv[i + 1]; /* Delete the extra-opts argument/value */ - for(j=i;j<*argc-1;j++) argv[j]=argv[j+2]; - i-=2; - *argc-=2; + for (j = i; j < *argc - 1; j++) + argv[j] = argv[j + 2]; + i -= 2; + *argc -= 2; ea_num--; - }else{ + } else { /* It has no value */ - optfound=1; + optfound = 1; /* Delete the extra opts argument */ - for(j=i;j<*argc;j++) argv[j]=argv[j+1]; + for (j = i; j < *argc; j++) + argv[j] = argv[j + 1]; i--; - *argc-=1; + *argc -= 1; } } /* If we found extra-opts, expand them and store them for later*/ - if(argptr||optfound){ + if (argptr || optfound) { /* Process ini section, returning a linked list of arguments */ - ea1=np_get_defaults(argptr, plugin_name); - if(ea1==NULL) { + ea1 = np_get_defaults(argptr, plugin_name); + if (ea1 == NULL) { /* no extra args (empty section)? */ ea_num--; continue; } /* append the list to extra_args */ - if(extra_args==NULL){ - extra_args=ea1; - while((ea1 = ea1->next)) ea_num++; - }else{ - ea_tmp=extra_args; - while(ea_tmp->next) { - ea_tmp=ea_tmp->next; + if (extra_args == NULL) { + extra_args = ea1; + while ((ea1 = ea1->next)) + ea_num++; + } else { + ea_tmp = extra_args; + while (ea_tmp->next) { + ea_tmp = ea_tmp->next; } - ea_tmp->next=ea1; - while((ea1 = ea1->next)) ea_num++; + ea_tmp->next = ea1; + while ((ea1 = ea1->next)) + ea_num++; } - ea1=ea_tmp=NULL; + ea1 = ea_tmp = NULL; } } /* lather, rince, repeat */ - if(ea_num==*argc && extra_args==NULL){ + if (ea_num == *argc && extra_args == NULL) { /* No extra-opts */ return argv; } /* done processing arguments. now create a new argv array... */ - argv_new=(char**)malloc((ea_num+1)*sizeof(char**)); - if(argv_new==NULL) die(STATE_UNKNOWN, _("malloc() failed!\n")); + argv_new = (char **)malloc((ea_num + 1) * sizeof(char **)); + if (argv_new == NULL) + die(STATE_UNKNOWN, _("malloc() failed!\n")); /* starting with program name */ - argv_new[0]=argv[0]; - argc_new=1; + argv_new[0] = argv[0]; + argc_new = 1; /* then parsed ini opts (frying them up in the same run) */ - while(extra_args){ - argv_new[argc_new++]=extra_args->arg; - ea1=extra_args; - extra_args=extra_args->next; + while (extra_args) { + argv_new[argc_new++] = extra_args->arg; + ea1 = extra_args; + extra_args = extra_args->next; free(ea1); } /* finally the rest of the argv array */ - for (i=1; i<*argc; i++) argv_new[argc_new++]=argv[i]; - *argc=argc_new; + for (i = 1; i < *argc; i++) + argv_new[argc_new++] = argv[i]; + *argc = argc_new; /* and terminate. */ - argv_new[argc_new]=NULL; + argv_new[argc_new] = NULL; return argv_new; } - diff --git a/lib/extra_opts.h b/lib/extra_opts.h index 8ff14a1..3f64360 100644 --- a/lib/extra_opts.h +++ b/lib/extra_opts.h @@ -20,4 +20,3 @@ char **np_extra_opts(int *argc, char **argv, const char *plugin_name); #endif /* _EXTRA_OPTS_H_ */ - diff --git a/lib/maxfd.c b/lib/maxfd.c index 529b356..c39d427 100644 --- a/lib/maxfd.c +++ b/lib/maxfd.c @@ -1,7 +1,7 @@ #include "./maxfd.h" #include -long mp_open_max (void) { +long mp_open_max(void) { long maxfd = 0L; /* Try sysconf(_SC_OPEN_MAX) first, as it can be higher than OPEN_MAX. * If that fails and the macro isn't defined, we fall back to an educated @@ -10,17 +10,17 @@ long mp_open_max (void) { #ifdef _SC_OPEN_MAX errno = 0; - if ((maxfd = sysconf (_SC_OPEN_MAX)) < 0) { + if ((maxfd = sysconf(_SC_OPEN_MAX)) < 0) { if (errno == 0) - maxfd = DEFAULT_MAXFD; /* it's indeterminate */ + maxfd = DEFAULT_MAXFD; /* it's indeterminate */ else - die (STATE_UNKNOWN, _("sysconf error for _SC_OPEN_MAX\n")); + die(STATE_UNKNOWN, _("sysconf error for _SC_OPEN_MAX\n")); } #elif defined(OPEN_MAX) return OPEN_MAX -#else /* sysconf macro unavailable, so guess (may be wildly inaccurate) */ +#else /* sysconf macro unavailable, so guess (may be wildly inaccurate) */ return DEFAULT_MAXFD; #endif - return(maxfd); + return (maxfd); } diff --git a/lib/maxfd.h b/lib/maxfd.h index 45218d0..8fcd62d 100644 --- a/lib/maxfd.h +++ b/lib/maxfd.h @@ -1,9 +1,9 @@ #ifndef _MAXFD_ #define _MAXFD_ -#define DEFAULT_MAXFD 256 /* fallback value if no max open files value is set */ -#define MAXFD_LIMIT 8192 /* upper limit of open files */ +#define DEFAULT_MAXFD 256 /* fallback value if no max open files value is set */ +#define MAXFD_LIMIT 8192 /* upper limit of open files */ -long mp_open_max (void); +long mp_open_max(void); #endif // _MAXFD_ diff --git a/lib/parse_ini.c b/lib/parse_ini.c index 09c0dc4..150df7b 100644 --- a/lib/parse_ini.c +++ b/lib/parse_ini.c @@ -1,25 +1,25 @@ /***************************************************************************** -* -* Monitoring Plugins parse_ini library -* -* License: GPL -* Copyright (c) 2007 Monitoring Plugins Development Team -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -* -* -*****************************************************************************/ + * + * Monitoring Plugins parse_ini library + * + * License: GPL + * Copyright (c) 2007 Monitoring Plugins Development Team + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * + *****************************************************************************/ #include "common.h" #include "idpriv.h" @@ -40,31 +40,19 @@ typedef struct { char *stanza; } np_ini_info; -static char *default_ini_file_names[] = { - "monitoring-plugins.ini", - "plugins.ini", - "nagios-plugins.ini", - NULL -}; - -static char *default_ini_path_names[] = { - "/usr/local/etc/monitoring-plugins/monitoring-plugins.ini", - "/usr/local/etc/monitoring-plugins.ini", - "/etc/monitoring-plugins/monitoring-plugins.ini", - "/etc/monitoring-plugins.ini", - /* deprecated path names (for backward compatibility): */ - "/etc/nagios/plugins.ini", - "/usr/local/nagios/etc/plugins.ini", - "/usr/local/etc/nagios/plugins.ini", - "/etc/opt/nagios/plugins.ini", - "/etc/nagios-plugins.ini", - "/usr/local/etc/nagios-plugins.ini", - "/etc/opt/nagios-plugins.ini", - NULL -}; +static char *default_ini_file_names[] = {"monitoring-plugins.ini", "plugins.ini", "nagios-plugins.ini", NULL}; + +static char *default_ini_path_names[] = {"/usr/local/etc/monitoring-plugins/monitoring-plugins.ini", "/usr/local/etc/monitoring-plugins.ini", + "/etc/monitoring-plugins/monitoring-plugins.ini", "/etc/monitoring-plugins.ini", + /* deprecated path names (for backward compatibility): */ + "/etc/nagios/plugins.ini", "/usr/local/nagios/etc/plugins.ini", "/usr/local/etc/nagios/plugins.ini", "/etc/opt/nagios/plugins.ini", + "/etc/nagios-plugins.ini", "/usr/local/etc/nagios-plugins.ini", "/etc/opt/nagios-plugins.ini", NULL}; /* eat all characters from a FILE pointer until n is encountered */ -#define GOBBLE_TO(f, c, n) do { (c)=fgetc((f)); } while((c)!=EOF && (c)!=(n)) +#define GOBBLE_TO(f, c, n) \ + do { \ + (c) = fgetc((f)); \ + } while ((c) != EOF && (c) != (n)) /* internal function that returns the constructed defaults options */ static int read_defaults(FILE *f, const char *stanza, np_arg_list **opts); @@ -81,9 +69,7 @@ static char *default_file_in_path(void); * [stanza][@filename] * into its separate parts. */ -static void -parse_locator(const char *locator, const char *def_stanza, np_ini_info *i) -{ +static void parse_locator(const char *locator, const char *def_stanza, np_ini_info *i) { size_t locator_len = 0, stanza_len = 0; /* if locator is NULL we'll use default values */ @@ -96,7 +82,7 @@ parse_locator(const char *locator, const char *def_stanza, np_ini_info *i) i->stanza = malloc(sizeof(char) * (stanza_len + 1)); strncpy(i->stanza, locator, stanza_len); i->stanza[stanza_len] = '\0'; - } else {/* otherwise we use the default stanza */ + } else { /* otherwise we use the default stanza */ i->stanza = strdup(def_stanza); } @@ -105,7 +91,7 @@ parse_locator(const char *locator, const char *def_stanza, np_ini_info *i) /* check whether there's an @file part */ if (stanza_len == locator_len) { - i->file = default_file(); + i->file = default_file(); i->file_string_on_heap = false; } else { i->file = strdup(&(locator[stanza_len + 1])); @@ -113,35 +99,28 @@ parse_locator(const char *locator, const char *def_stanza, np_ini_info *i) } if (i->file == NULL || i->file[0] == '\0') - die(STATE_UNKNOWN, - _("Cannot find config file in any standard location.\n")); + die(STATE_UNKNOWN, _("Cannot find config file in any standard location.\n")); } /* * This is the externally visible function used by extra_opts. */ -np_arg_list * -np_get_defaults(const char *locator, const char *default_section) -{ +np_arg_list *np_get_defaults(const char *locator, const char *default_section) { FILE *inifile = NULL; np_arg_list *defaults = NULL; np_ini_info i; int is_suid_plugin = mp_suid(); if (is_suid_plugin && idpriv_temp_drop() == -1) - die(STATE_UNKNOWN, _("Cannot drop privileges: %s\n"), - strerror(errno)); + die(STATE_UNKNOWN, _("Cannot drop privileges: %s\n"), strerror(errno)); parse_locator(locator, default_section, &i); inifile = strcmp(i.file, "-") == 0 ? stdin : fopen(i.file, "r"); if (inifile == NULL) - die(STATE_UNKNOWN, _("Can't read config file: %s\n"), - strerror(errno)); + die(STATE_UNKNOWN, _("Can't read config file: %s\n"), strerror(errno)); if (!read_defaults(inifile, i.stanza, &defaults)) - die(STATE_UNKNOWN, - _("Invalid section '%s' in config file '%s'\n"), i.stanza, - i.file); + die(STATE_UNKNOWN, _("Invalid section '%s' in config file '%s'\n"), i.stanza, i.file); if (i.file_string_on_heap) { free(i.file); @@ -151,8 +130,7 @@ np_get_defaults(const char *locator, const char *default_section) fclose(inifile); free(i.stanza); if (is_suid_plugin && idpriv_temp_restore() == -1) - die(STATE_UNKNOWN, _("Cannot restore privileges: %s\n"), - strerror(errno)); + die(STATE_UNKNOWN, _("Cannot restore privileges: %s\n"), strerror(errno)); return defaults; } @@ -164,9 +142,7 @@ np_get_defaults(const char *locator, const char *default_section) * be extra careful about user-supplied input (i.e. avoiding possible * format string vulnerabilities, etc). */ -static int -read_defaults(FILE *f, const char *stanza, np_arg_list **opts) -{ +static int read_defaults(FILE *f, const char *stanza, np_arg_list **opts) { int c = 0; bool status = false; size_t i, stanza_len; @@ -217,8 +193,7 @@ read_defaults(FILE *f, const char *stanza, np_arg_list **opts) * we're dealing with a config error */ case NOSTANZA: - die(STATE_UNKNOWN, "%s\n", - _("Config file error")); + die(STATE_UNKNOWN, "%s\n", _("Config file error")); /* we're in a stanza, but for a different plugin */ case WRONGSTANZA: GOBBLE_TO(f, c, '\n'); @@ -227,8 +202,7 @@ read_defaults(FILE *f, const char *stanza, np_arg_list **opts) case RIGHTSTANZA: ungetc(c, f); if (add_option(f, opts)) { - die(STATE_UNKNOWN, "%s\n", - _("Config file error")); + die(STATE_UNKNOWN, "%s\n", _("Config file error")); } status = true; break; @@ -246,9 +220,7 @@ read_defaults(FILE *f, const char *stanza, np_arg_list **opts) * --option[=value] * appending it to the linked list optbuf. */ -static int -add_option(FILE *f, np_arg_list **optlst) -{ +static int add_option(FILE *f, np_arg_list **optlst) { np_arg_list *opttmp = *optlst, *optnew; char *linebuf = NULL, *lineend = NULL, *optptr = NULL, *optend = NULL; char *eqptr = NULL, *valptr = NULL, *valend = NULL; @@ -295,8 +267,7 @@ add_option(FILE *f, np_arg_list **optlst) if (optptr == eqptr) die(STATE_UNKNOWN, "%s\n", _("Config file error")); /* continue from '=' to start of value or EOL */ - for (valptr = eqptr + 1; valptr < lineend && isspace(*valptr); - valptr++) + for (valptr = eqptr + 1; valptr < lineend && isspace(*valptr); valptr++) continue; /* continue to the end of value */ for (valend = valptr; valend < lineend; valend++) @@ -365,13 +336,10 @@ add_option(FILE *f, np_arg_list **optlst) return 0; } -static char * -default_file(void) -{ - char *ini_file; +static char *default_file(void) { + char *ini_file; - if ((ini_file = getenv("MP_CONFIG_FILE")) != NULL || - (ini_file = default_file_in_path()) != NULL) { + if ((ini_file = getenv("MP_CONFIG_FILE")) != NULL || (ini_file = default_file_in_path()) != NULL) { return ini_file; } @@ -383,9 +351,7 @@ default_file(void) return NULL; } -static char * -default_file_in_path(void) -{ +static char *default_file_in_path(void) { char *config_path, **file; char *dir, *ini_file, *tokens; diff --git a/lib/parse_ini.h b/lib/parse_ini.h index e37601b..d17409e 100644 --- a/lib/parse_ini.h +++ b/lib/parse_ini.h @@ -19,4 +19,3 @@ typedef struct np_arg_el { np_arg_list *np_get_defaults(const char *locator, const char *default_section); #endif /* _PARSE_INI_H_ */ - diff --git a/lib/tests/test_base64.c b/lib/tests/test_base64.c index 05dd794..48e5ed6 100644 --- a/lib/tests/test_base64.c +++ b/lib/tests/test_base64.c @@ -1,29 +1,27 @@ /***************************************************************************** -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -* -* -*****************************************************************************/ + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * + *****************************************************************************/ #include "common.h" #include "gl/base64.h" #include "tap.h" -int -main (int argc, char **argv) -{ -#if 0 /* The current base64 function doesn't work on 8bit data */ +int main(int argc, char **argv) { +#if 0 /* The current base64 function doesn't work on 8bit data */ char random[1024] = { 0x8b,0xb0,0xc4,0xe2,0xfc,0x22,0x9f,0x0d,0x85,0xe7,0x2c,0xaa,0x39,0xa1,0x46,0x88, 0x50,0xe6,0x34,0x37,0x0b,0x45,0x4b,0xb8,0xb2,0x86,0x7a,0x3e,0x7f,0x0c,0x40,0x18, @@ -182,168 +180,100 @@ main (int argc, char **argv) #endif char random[1024] = { - 0x0b,0x30,0x44,0x62,0x7c,0x22,0x1f,0x0d,0x05,0x67,0x2c,0x2a,0x39,0x21,0x46,0x08, - 0x50,0x66,0x34,0x37,0x0b,0x45,0x4b,0x38,0x32,0x06,0x7a,0x3e,0x7f,0x0c,0x40,0x18, - 0x6b,0x2d,0x60,0x4c,0x60,0x0c,0x23,0x43,0x3b,0x3e,0x1b,0x16,0x04,0x46,0x58,0x3f, - 0x40,0x6a,0x11,0x05,0x63,0x71,0x14,0x35,0x47,0x79,0x13,0x6f,0x6b,0x27,0x18,0x5b, - 0x48,0x27,0x3e,0x6f,0x15,0x33,0x4f,0x3e,0x5e,0x51,0x73,0x68,0x25,0x0f,0x06,0x5b, - 0x7c,0x72,0x75,0x3e,0x3f,0x1b,0x5c,0x6d,0x6a,0x39,0x7c,0x63,0x63,0x60,0x6c,0x7a, - 0x33,0x76,0x52,0x13,0x25,0x33,0x7d,0x65,0x23,0x27,0x11,0x06,0x06,0x47,0x71,0x1e, - 0x14,0x74,0x63,0x70,0x2d,0x15,0x27,0x18,0x51,0x06,0x05,0x33,0x11,0x2c,0x6b,0x00, - 0x2d,0x77,0x20,0x48,0x0d,0x73,0x51,0x45,0x25,0x7f,0x7f,0x35,0x26,0x2e,0x26,0x53, - 0x24,0x68,0x1e,0x0e,0x58,0x3a,0x59,0x50,0x56,0x37,0x5f,0x66,0x01,0x4c,0x5a,0x64, - 0x32,0x50,0x7b,0x6a,0x20,0x72,0x2b,0x1d,0x7e,0x43,0x7b,0x61,0x42,0x0b,0x61,0x73, - 0x24,0x79,0x3a,0x6b,0x4a,0x79,0x6e,0x09,0x0f,0x27,0x2d,0x0c,0x5e,0x32,0x4b,0x0d, - 0x79,0x46,0x39,0x21,0x0a,0x26,0x5f,0x3a,0x00,0x26,0x3f,0x13,0x2e,0x7e,0x50,0x2b, - 0x67,0x46,0x72,0x3f,0x3b,0x01,0x46,0x1b,0x0b,0x35,0x49,0x39,0x19,0x70,0x3d,0x02, - 0x41,0x0e,0x38,0x05,0x76,0x65,0x4f,0x31,0x6c,0x5e,0x17,0x04,0x15,0x36,0x26,0x64, - 0x34,0x14,0x17,0x7c,0x0e,0x0b,0x5b,0x55,0x53,0x6b,0x00,0x42,0x41,0x4f,0x02,0x5c, - 0x13,0x0a,0x2c,0x2c,0x3e,0x10,0x14,0x33,0x45,0x7c,0x7a,0x5a,0x31,0x61,0x39,0x08, - 0x22,0x6a,0x1e,0x0f,0x6f,0x1b,0x6c,0x13,0x5e,0x79,0x20,0x79,0x50,0x62,0x06,0x2c, - 0x76,0x17,0x04,0x2b,0x2a,0x75,0x1f,0x0c,0x37,0x4e,0x0f,0x7b,0x2d,0x34,0x75,0x60, - 0x31,0x74,0x2e,0x0a,0x4a,0x11,0x6c,0x49,0x25,0x01,0x3a,0x3d,0x22,0x1e,0x6d,0x18, - 0x51,0x78,0x2d,0x62,0x31,0x4c,0x50,0x40,0x17,0x4b,0x6f,0x22,0x00,0x7f,0x61,0x2a, - 0x34,0x3e,0x00,0x5f,0x2f,0x5f,0x2f,0x14,0x2a,0x55,0x27,0x1f,0x46,0x1f,0x12,0x46, - 0x5e,0x1e,0x0c,0x7c,0x38,0x01,0x61,0x64,0x76,0x22,0x6e,0x08,0x20,0x38,0x4f,0x73, - 0x72,0x55,0x12,0x42,0x19,0x50,0x61,0x43,0x77,0x7d,0x41,0x2e,0x35,0x4f,0x3d,0x31, - 0x28,0x58,0x67,0x1b,0x03,0x51,0x20,0x32,0x1c,0x08,0x6e,0x37,0x75,0x37,0x44,0x4f, - 0x68,0x19,0x07,0x64,0x14,0x28,0x25,0x2b,0x69,0x35,0x18,0x27,0x26,0x14,0x13,0x70, - 0x42,0x19,0x12,0x75,0x3e,0x02,0x5d,0x7c,0x13,0x1f,0x16,0x53,0x3b,0x74,0x48,0x3c, - 0x5e,0x39,0x6c,0x1c,0x1c,0x74,0x39,0x1f,0x00,0x1b,0x06,0x0a,0x68,0x3b,0x52,0x4f, - 0x1e,0x6e,0x3c,0x35,0x0c,0x38,0x0e,0x0b,0x3b,0x1a,0x76,0x23,0x29,0x53,0x1e,0x5f, - 0x41,0x0c,0x4b,0x0a,0x65,0x28,0x78,0x67,0x48,0x59,0x26,0x6d,0x31,0x76,0x23,0x70, - 0x61,0x64,0x3b,0x38,0x79,0x66,0x74,0x53,0x2c,0x64,0x64,0x54,0x03,0x54,0x65,0x44, - 0x4c,0x18,0x4f,0x48,0x20,0x4f,0x72,0x10,0x3f,0x0c,0x52,0x2d,0x03,0x14,0x03,0x51, - 0x42,0x10,0x77,0x6a,0x34,0x06,0x32,0x03,0x72,0x14,0x7c,0x08,0x5d,0x52,0x1a,0x62, - 0x7c,0x3e,0x30,0x7e,0x5f,0x7f,0x54,0x0f,0x44,0x49,0x5d,0x5e,0x10,0x6a,0x06,0x2b, - 0x06,0x53,0x10,0x39,0x37,0x32,0x4a,0x4e,0x3d,0x2b,0x65,0x38,0x39,0x07,0x72,0x54, - 0x64,0x4d,0x56,0x6a,0x03,0x22,0x70,0x7b,0x5f,0x60,0x0b,0x2a,0x0b,0x6b,0x10,0x64, - 0x14,0x05,0x22,0x00,0x73,0x40,0x23,0x5b,0x51,0x1f,0x2b,0x1a,0x5d,0x69,0x7a,0x46, - 0x0c,0x5f,0x32,0x4b,0x4a,0x28,0x52,0x79,0x5b,0x12,0x42,0x18,0x00,0x5d,0x27,0x31, - 0x53,0x3c,0x4c,0x36,0x4e,0x38,0x3f,0x72,0x03,0x71,0x02,0x5b,0x36,0x59,0x7f,0x75, - 0x6e,0x08,0x54,0x0d,0x34,0x1c,0x34,0x57,0x5d,0x69,0x48,0x00,0x3b,0x05,0x07,0x6e, - 0x27,0x65,0x6e,0x40,0x3d,0x3a,0x4f,0x72,0x5d,0x39,0x16,0x0f,0x63,0x12,0x12,0x15, - 0x3a,0x70,0x0d,0x57,0x18,0x0d,0x5e,0x3d,0x22,0x68,0x68,0x7c,0x6d,0x4f,0x0c,0x7b, - 0x09,0x2d,0x4a,0x73,0x20,0x47,0x07,0x57,0x75,0x5d,0x53,0x70,0x34,0x21,0x40,0x57, - 0x51,0x5e,0x49,0x44,0x00,0x54,0x27,0x04,0x68,0x7e,0x59,0x56,0x58,0x74,0x14,0x3c, - 0x16,0x33,0x41,0x16,0x4b,0x2f,0x49,0x37,0x0a,0x54,0x08,0x08,0x1f,0x39,0x67,0x76, - 0x28,0x28,0x07,0x1d,0x61,0x47,0x51,0x4d,0x75,0x26,0x52,0x47,0x47,0x0c,0x57,0x58, - 0x74,0x3e,0x62,0x6c,0x58,0x3a,0x44,0x1e,0x16,0x2e,0x21,0x1c,0x73,0x45,0x67,0x74, - 0x4f,0x33,0x66,0x0e,0x74,0x66,0x26,0x1f,0x2e,0x38,0x44,0x40,0x7e,0x2a,0x50,0x52, - 0x5e,0x43,0x01,0x7a,0x38,0x49,0x3c,0x55,0x4d,0x5a,0x44,0x08,0x26,0x59,0x4d,0x45, - 0x0b,0x48,0x0a,0x33,0x5e,0x4a,0x4d,0x75,0x16,0x17,0x63,0x46,0x01,0x2a,0x55,0x7b, - 0x0f,0x02,0x73,0x6a,0x4b,0x7f,0x75,0x65,0x3c,0x4c,0x33,0x39,0x6c,0x74,0x05,0x60, - 0x0f,0x7f,0x2d,0x41,0x4d,0x4d,0x46,0x71,0x09,0x6f,0x4f,0x60,0x15,0x0f,0x46,0x73, - 0x63,0x4c,0x5e,0x74,0x30,0x0d,0x28,0x43,0x08,0x72,0x32,0x04,0x2e,0x31,0x29,0x27, - 0x44,0x6d,0x13,0x17,0x48,0x0f,0x49,0x52,0x10,0x13,0x7f,0x17,0x16,0x62,0x79,0x35, - 0x78,0x3e,0x01,0x7c,0x2e,0x0f,0x76,0x3e,0x5e,0x53,0x6c,0x5b,0x5f,0x7c,0x19,0x41, - 0x02,0x2f,0x17,0x64,0x41,0x75,0x10,0x04,0x47,0x7c,0x3d,0x4b,0x52,0x00,0x10,0x5d, - 0x51,0x4e,0x7a,0x27,0x25,0x55,0x40,0x12,0x35,0x60,0x05,0x1b,0x34,0x2d,0x04,0x7a, - 0x6a,0x69,0x02,0x79,0x03,0x3a,0x2f,0x06,0x0a,0x79,0x7b,0x12,0x5d,0x7c,0x52,0x29, - 0x47,0x58,0x12,0x73,0x3f,0x27,0x56,0x05,0x0c,0x48,0x32,0x58,0x6b,0x57,0x5c,0x03, - 0x64,0x56,0x11,0x52,0x7a,0x30,0x36,0x29,0x17,0x3b,0x68,0x7a,0x7c,0x05,0x6b,0x6b, - 0x13,0x6a,0x24,0x5c,0x68,0x42,0x18,0x32,0x03,0x73,0x6e,0x04,0x21,0x2e,0x01,0x04, - 0x63,0x7d,0x44,0x41,0x12,0x31,0x0b,0x15,0x1f,0x70,0x00,0x2e,0x66,0x14,0x3c,0x7f, - 0x2b,0x00,0x1f,0x0c,0x28,0x59,0x0a,0x16,0x49,0x5a,0x5c,0x64,0x65,0x4b,0x11,0x29, - 0x15,0x36,0x5a,0x65,0x19,0x4f,0x60,0x23,0x3a,0x3a,0x13,0x25,0x02,0x78,0x4c,0x54 - }; - char b64_known[1369] = { - 0x43,0x7a,0x42,0x45,0x59,0x6e,0x77,0x69,0x48,0x77,0x30,0x46,0x5a,0x79,0x77,0x71, - 0x4f,0x53,0x46,0x47,0x43,0x46,0x42,0x6d,0x4e,0x44,0x63,0x4c,0x52,0x55,0x73,0x34, - 0x4d,0x67,0x5a,0x36,0x50,0x6e,0x38,0x4d,0x51,0x42,0x68,0x72,0x4c,0x57,0x42,0x4d, - 0x59,0x41,0x77,0x6a,0x51,0x7a,0x73,0x2b,0x47,0x78,0x59,0x45,0x52,0x6c,0x67,0x2f, - 0x51,0x47,0x6f,0x52,0x42,0x57,0x4e,0x78,0x46,0x44,0x56,0x48,0x65,0x52,0x4e,0x76, - 0x61,0x79,0x63,0x59,0x57,0x30,0x67,0x6e,0x50,0x6d,0x38,0x56,0x4d,0x30,0x38,0x2b, - 0x58,0x6c,0x46,0x7a,0x61,0x43,0x55,0x50,0x42,0x6c,0x74,0x38,0x63,0x6e,0x55,0x2b, - 0x50,0x78,0x74,0x63,0x62,0x57,0x6f,0x35,0x66,0x47,0x4e,0x6a,0x59,0x47,0x78,0x36, - 0x4d,0x33,0x5a,0x53,0x45,0x79,0x55,0x7a,0x66,0x57,0x55,0x6a,0x4a,0x78,0x45,0x47, - 0x42,0x6b,0x64,0x78,0x48,0x68,0x52,0x30,0x59,0x33,0x41,0x74,0x46,0x53,0x63,0x59, - 0x55,0x51,0x59,0x46,0x4d,0x78,0x45,0x73,0x61,0x77,0x41,0x74,0x64,0x79,0x42,0x49, - 0x44,0x58,0x4e,0x52,0x52,0x53,0x56,0x2f,0x66,0x7a,0x55,0x6d,0x4c,0x69,0x5a,0x54, - 0x4a,0x47,0x67,0x65,0x44,0x6c,0x67,0x36,0x57,0x56,0x42,0x57,0x4e,0x31,0x39,0x6d, - 0x41,0x55,0x78,0x61,0x5a,0x44,0x4a,0x51,0x65,0x32,0x6f,0x67,0x63,0x69,0x73,0x64, - 0x66,0x6b,0x4e,0x37,0x59,0x55,0x49,0x4c,0x59,0x58,0x4d,0x6b,0x65,0x54,0x70,0x72, - 0x53,0x6e,0x6c,0x75,0x43,0x51,0x38,0x6e,0x4c,0x51,0x78,0x65,0x4d,0x6b,0x73,0x4e, - 0x65,0x55,0x59,0x35,0x49,0x51,0x6f,0x6d,0x58,0x7a,0x6f,0x41,0x4a,0x6a,0x38,0x54, - 0x4c,0x6e,0x35,0x51,0x4b,0x32,0x64,0x47,0x63,0x6a,0x38,0x37,0x41,0x55,0x59,0x62, - 0x43,0x7a,0x56,0x4a,0x4f,0x52,0x6c,0x77,0x50,0x51,0x4a,0x42,0x44,0x6a,0x67,0x46, - 0x64,0x6d,0x56,0x50,0x4d,0x57,0x78,0x65,0x46,0x77,0x51,0x56,0x4e,0x69,0x5a,0x6b, - 0x4e,0x42,0x51,0x58,0x66,0x41,0x34,0x4c,0x57,0x31,0x56,0x54,0x61,0x77,0x42,0x43, - 0x51,0x55,0x38,0x43,0x58,0x42,0x4d,0x4b,0x4c,0x43,0x77,0x2b,0x45,0x42,0x51,0x7a, - 0x52,0x58,0x78,0x36,0x57,0x6a,0x46,0x68,0x4f,0x51,0x67,0x69,0x61,0x68,0x34,0x50, - 0x62,0x78,0x74,0x73,0x45,0x31,0x35,0x35,0x49,0x48,0x6c,0x51,0x59,0x67,0x59,0x73, - 0x64,0x68,0x63,0x45,0x4b,0x79,0x70,0x31,0x48,0x77,0x77,0x33,0x54,0x67,0x39,0x37, - 0x4c,0x54,0x52,0x31,0x59,0x44,0x46,0x30,0x4c,0x67,0x70,0x4b,0x45,0x57,0x78,0x4a, - 0x4a,0x51,0x45,0x36,0x50,0x53,0x49,0x65,0x62,0x52,0x68,0x52,0x65,0x43,0x31,0x69, - 0x4d,0x55,0x78,0x51,0x51,0x42,0x64,0x4c,0x62,0x79,0x49,0x41,0x66,0x32,0x45,0x71, - 0x4e,0x44,0x34,0x41,0x58,0x79,0x39,0x66,0x4c,0x78,0x51,0x71,0x56,0x53,0x63,0x66, - 0x52,0x68,0x38,0x53,0x52,0x6c,0x34,0x65,0x44,0x48,0x77,0x34,0x41,0x57,0x46,0x6b, - 0x64,0x69,0x4a,0x75,0x43,0x43,0x41,0x34,0x54,0x33,0x4e,0x79,0x56,0x52,0x4a,0x43, - 0x47,0x56,0x42,0x68,0x51,0x33,0x64,0x39,0x51,0x53,0x34,0x31,0x54,0x7a,0x30,0x78, - 0x4b,0x46,0x68,0x6e,0x47,0x77,0x4e,0x52,0x49,0x44,0x49,0x63,0x43,0x47,0x34,0x33, - 0x64,0x54,0x64,0x45,0x54,0x32,0x67,0x5a,0x42,0x32,0x51,0x55,0x4b,0x43,0x55,0x72, - 0x61,0x54,0x55,0x59,0x4a,0x79,0x59,0x55,0x45,0x33,0x42,0x43,0x47,0x52,0x4a,0x31, - 0x50,0x67,0x4a,0x64,0x66,0x42,0x4d,0x66,0x46,0x6c,0x4d,0x37,0x64,0x45,0x67,0x38, - 0x58,0x6a,0x6c,0x73,0x48,0x42,0x78,0x30,0x4f,0x52,0x38,0x41,0x47,0x77,0x59,0x4b, - 0x61,0x44,0x74,0x53,0x54,0x78,0x35,0x75,0x50,0x44,0x55,0x4d,0x4f,0x41,0x34,0x4c, - 0x4f,0x78,0x70,0x32,0x49,0x79,0x6c,0x54,0x48,0x6c,0x39,0x42,0x44,0x45,0x73,0x4b, - 0x5a,0x53,0x68,0x34,0x5a,0x30,0x68,0x5a,0x4a,0x6d,0x30,0x78,0x64,0x69,0x4e,0x77, - 0x59,0x57,0x51,0x37,0x4f,0x48,0x6c,0x6d,0x64,0x46,0x4d,0x73,0x5a,0x47,0x52,0x55, - 0x41,0x31,0x52,0x6c,0x52,0x45,0x77,0x59,0x54,0x30,0x67,0x67,0x54,0x33,0x49,0x51, - 0x50,0x77,0x78,0x53,0x4c,0x51,0x4d,0x55,0x41,0x31,0x46,0x43,0x45,0x48,0x64,0x71, - 0x4e,0x41,0x59,0x79,0x41,0x33,0x49,0x55,0x66,0x41,0x68,0x64,0x55,0x68,0x70,0x69, - 0x66,0x44,0x34,0x77,0x66,0x6c,0x39,0x2f,0x56,0x41,0x39,0x45,0x53,0x56,0x31,0x65, - 0x45,0x47,0x6f,0x47,0x4b,0x77,0x5a,0x54,0x45,0x44,0x6b,0x33,0x4d,0x6b,0x70,0x4f, - 0x50,0x53,0x74,0x6c,0x4f,0x44,0x6b,0x48,0x63,0x6c,0x52,0x6b,0x54,0x56,0x5a,0x71, - 0x41,0x79,0x4a,0x77,0x65,0x31,0x39,0x67,0x43,0x79,0x6f,0x4c,0x61,0x78,0x42,0x6b, - 0x46,0x41,0x55,0x69,0x41,0x48,0x4e,0x41,0x49,0x31,0x74,0x52,0x48,0x79,0x73,0x61, - 0x58,0x57,0x6c,0x36,0x52,0x67,0x78,0x66,0x4d,0x6b,0x74,0x4b,0x4b,0x46,0x4a,0x35, - 0x57,0x78,0x4a,0x43,0x47,0x41,0x42,0x64,0x4a,0x7a,0x46,0x54,0x50,0x45,0x77,0x32, - 0x54,0x6a,0x67,0x2f,0x63,0x67,0x4e,0x78,0x41,0x6c,0x73,0x32,0x57,0x58,0x39,0x31, - 0x62,0x67,0x68,0x55,0x44,0x54,0x51,0x63,0x4e,0x46,0x64,0x64,0x61,0x55,0x67,0x41, - 0x4f,0x77,0x55,0x48,0x62,0x69,0x64,0x6c,0x62,0x6b,0x41,0x39,0x4f,0x6b,0x39,0x79, - 0x58,0x54,0x6b,0x57,0x44,0x32,0x4d,0x53,0x45,0x68,0x55,0x36,0x63,0x41,0x31,0x58, - 0x47,0x41,0x31,0x65,0x50,0x53,0x4a,0x6f,0x61,0x48,0x78,0x74,0x54,0x77,0x78,0x37, - 0x43,0x53,0x31,0x4b,0x63,0x79,0x42,0x48,0x42,0x31,0x64,0x31,0x58,0x56,0x4e,0x77, - 0x4e,0x43,0x46,0x41,0x56,0x31,0x46,0x65,0x53,0x55,0x51,0x41,0x56,0x43,0x63,0x45, - 0x61,0x48,0x35,0x5a,0x56,0x6c,0x68,0x30,0x46,0x44,0x77,0x57,0x4d,0x30,0x45,0x57, - 0x53,0x79,0x39,0x4a,0x4e,0x77,0x70,0x55,0x43,0x41,0x67,0x66,0x4f,0x57,0x64,0x32, - 0x4b,0x43,0x67,0x48,0x48,0x57,0x46,0x48,0x55,0x55,0x31,0x31,0x4a,0x6c,0x4a,0x48, - 0x52,0x77,0x78,0x58,0x57,0x48,0x51,0x2b,0x59,0x6d,0x78,0x59,0x4f,0x6b,0x51,0x65, - 0x46,0x69,0x34,0x68,0x48,0x48,0x4e,0x46,0x5a,0x33,0x52,0x50,0x4d,0x32,0x59,0x4f, - 0x64,0x47,0x59,0x6d,0x48,0x79,0x34,0x34,0x52,0x45,0x42,0x2b,0x4b,0x6c,0x42,0x53, - 0x58,0x6b,0x4d,0x42,0x65,0x6a,0x68,0x4a,0x50,0x46,0x56,0x4e,0x57,0x6b,0x51,0x49, - 0x4a,0x6c,0x6c,0x4e,0x52,0x51,0x74,0x49,0x43,0x6a,0x4e,0x65,0x53,0x6b,0x31,0x31, - 0x46,0x68,0x64,0x6a,0x52,0x67,0x45,0x71,0x56,0x58,0x73,0x50,0x41,0x6e,0x4e,0x71, - 0x53,0x33,0x39,0x31,0x5a,0x54,0x78,0x4d,0x4d,0x7a,0x6c,0x73,0x64,0x41,0x56,0x67, - 0x44,0x33,0x38,0x74,0x51,0x55,0x31,0x4e,0x52,0x6e,0x45,0x4a,0x62,0x30,0x39,0x67, - 0x46,0x51,0x39,0x47,0x63,0x32,0x4e,0x4d,0x58,0x6e,0x51,0x77,0x44,0x53,0x68,0x44, - 0x43,0x48,0x49,0x79,0x42,0x43,0x34,0x78,0x4b,0x53,0x64,0x45,0x62,0x52,0x4d,0x58, - 0x53,0x41,0x39,0x4a,0x55,0x68,0x41,0x54,0x66,0x78,0x63,0x57,0x59,0x6e,0x6b,0x31, - 0x65,0x44,0x34,0x42,0x66,0x43,0x34,0x50,0x64,0x6a,0x35,0x65,0x55,0x32,0x78,0x62, - 0x58,0x33,0x77,0x5a,0x51,0x51,0x49,0x76,0x46,0x32,0x52,0x42,0x64,0x52,0x41,0x45, - 0x52,0x33,0x77,0x39,0x53,0x31,0x49,0x41,0x45,0x46,0x31,0x52,0x54,0x6e,0x6f,0x6e, - 0x4a,0x56,0x56,0x41,0x45,0x6a,0x56,0x67,0x42,0x52,0x73,0x30,0x4c,0x51,0x52,0x36, - 0x61,0x6d,0x6b,0x43,0x65,0x51,0x4d,0x36,0x4c,0x77,0x59,0x4b,0x65,0x58,0x73,0x53, - 0x58,0x58,0x78,0x53,0x4b,0x55,0x64,0x59,0x45,0x6e,0x4d,0x2f,0x4a,0x31,0x59,0x46, - 0x44,0x45,0x67,0x79,0x57,0x47,0x74,0x58,0x58,0x41,0x4e,0x6b,0x56,0x68,0x46,0x53, - 0x65,0x6a,0x41,0x32,0x4b,0x52,0x63,0x37,0x61,0x48,0x70,0x38,0x42,0x57,0x74,0x72, - 0x45,0x32,0x6f,0x6b,0x58,0x47,0x68,0x43,0x47,0x44,0x49,0x44,0x63,0x32,0x34,0x45, - 0x49,0x53,0x34,0x42,0x42,0x47,0x4e,0x39,0x52,0x45,0x45,0x53,0x4d,0x51,0x73,0x56, - 0x48,0x33,0x41,0x41,0x4c,0x6d,0x59,0x55,0x50,0x48,0x38,0x72,0x41,0x42,0x38,0x4d, - 0x4b,0x46,0x6b,0x4b,0x46,0x6b,0x6c,0x61,0x58,0x47,0x52,0x6c,0x53,0x78,0x45,0x70, - 0x46,0x54,0x5a,0x61,0x5a,0x52,0x6c,0x50,0x59,0x43,0x4d,0x36,0x4f,0x68,0x4d,0x6c, - 0x41,0x6e,0x68,0x4d,0x56,0x41,0x3d,0x3d,0x00 - }; + 0x0b, 0x30, 0x44, 0x62, 0x7c, 0x22, 0x1f, 0x0d, 0x05, 0x67, 0x2c, 0x2a, 0x39, 0x21, 0x46, 0x08, 0x50, 0x66, 0x34, 0x37, 0x0b, 0x45, 0x4b, 0x38, 0x32, 0x06, 0x7a, 0x3e, + 0x7f, 0x0c, 0x40, 0x18, 0x6b, 0x2d, 0x60, 0x4c, 0x60, 0x0c, 0x23, 0x43, 0x3b, 0x3e, 0x1b, 0x16, 0x04, 0x46, 0x58, 0x3f, 0x40, 0x6a, 0x11, 0x05, 0x63, 0x71, 0x14, 0x35, + 0x47, 0x79, 0x13, 0x6f, 0x6b, 0x27, 0x18, 0x5b, 0x48, 0x27, 0x3e, 0x6f, 0x15, 0x33, 0x4f, 0x3e, 0x5e, 0x51, 0x73, 0x68, 0x25, 0x0f, 0x06, 0x5b, 0x7c, 0x72, 0x75, 0x3e, + 0x3f, 0x1b, 0x5c, 0x6d, 0x6a, 0x39, 0x7c, 0x63, 0x63, 0x60, 0x6c, 0x7a, 0x33, 0x76, 0x52, 0x13, 0x25, 0x33, 0x7d, 0x65, 0x23, 0x27, 0x11, 0x06, 0x06, 0x47, 0x71, 0x1e, + 0x14, 0x74, 0x63, 0x70, 0x2d, 0x15, 0x27, 0x18, 0x51, 0x06, 0x05, 0x33, 0x11, 0x2c, 0x6b, 0x00, 0x2d, 0x77, 0x20, 0x48, 0x0d, 0x73, 0x51, 0x45, 0x25, 0x7f, 0x7f, 0x35, + 0x26, 0x2e, 0x26, 0x53, 0x24, 0x68, 0x1e, 0x0e, 0x58, 0x3a, 0x59, 0x50, 0x56, 0x37, 0x5f, 0x66, 0x01, 0x4c, 0x5a, 0x64, 0x32, 0x50, 0x7b, 0x6a, 0x20, 0x72, 0x2b, 0x1d, + 0x7e, 0x43, 0x7b, 0x61, 0x42, 0x0b, 0x61, 0x73, 0x24, 0x79, 0x3a, 0x6b, 0x4a, 0x79, 0x6e, 0x09, 0x0f, 0x27, 0x2d, 0x0c, 0x5e, 0x32, 0x4b, 0x0d, 0x79, 0x46, 0x39, 0x21, + 0x0a, 0x26, 0x5f, 0x3a, 0x00, 0x26, 0x3f, 0x13, 0x2e, 0x7e, 0x50, 0x2b, 0x67, 0x46, 0x72, 0x3f, 0x3b, 0x01, 0x46, 0x1b, 0x0b, 0x35, 0x49, 0x39, 0x19, 0x70, 0x3d, 0x02, + 0x41, 0x0e, 0x38, 0x05, 0x76, 0x65, 0x4f, 0x31, 0x6c, 0x5e, 0x17, 0x04, 0x15, 0x36, 0x26, 0x64, 0x34, 0x14, 0x17, 0x7c, 0x0e, 0x0b, 0x5b, 0x55, 0x53, 0x6b, 0x00, 0x42, + 0x41, 0x4f, 0x02, 0x5c, 0x13, 0x0a, 0x2c, 0x2c, 0x3e, 0x10, 0x14, 0x33, 0x45, 0x7c, 0x7a, 0x5a, 0x31, 0x61, 0x39, 0x08, 0x22, 0x6a, 0x1e, 0x0f, 0x6f, 0x1b, 0x6c, 0x13, + 0x5e, 0x79, 0x20, 0x79, 0x50, 0x62, 0x06, 0x2c, 0x76, 0x17, 0x04, 0x2b, 0x2a, 0x75, 0x1f, 0x0c, 0x37, 0x4e, 0x0f, 0x7b, 0x2d, 0x34, 0x75, 0x60, 0x31, 0x74, 0x2e, 0x0a, + 0x4a, 0x11, 0x6c, 0x49, 0x25, 0x01, 0x3a, 0x3d, 0x22, 0x1e, 0x6d, 0x18, 0x51, 0x78, 0x2d, 0x62, 0x31, 0x4c, 0x50, 0x40, 0x17, 0x4b, 0x6f, 0x22, 0x00, 0x7f, 0x61, 0x2a, + 0x34, 0x3e, 0x00, 0x5f, 0x2f, 0x5f, 0x2f, 0x14, 0x2a, 0x55, 0x27, 0x1f, 0x46, 0x1f, 0x12, 0x46, 0x5e, 0x1e, 0x0c, 0x7c, 0x38, 0x01, 0x61, 0x64, 0x76, 0x22, 0x6e, 0x08, + 0x20, 0x38, 0x4f, 0x73, 0x72, 0x55, 0x12, 0x42, 0x19, 0x50, 0x61, 0x43, 0x77, 0x7d, 0x41, 0x2e, 0x35, 0x4f, 0x3d, 0x31, 0x28, 0x58, 0x67, 0x1b, 0x03, 0x51, 0x20, 0x32, + 0x1c, 0x08, 0x6e, 0x37, 0x75, 0x37, 0x44, 0x4f, 0x68, 0x19, 0x07, 0x64, 0x14, 0x28, 0x25, 0x2b, 0x69, 0x35, 0x18, 0x27, 0x26, 0x14, 0x13, 0x70, 0x42, 0x19, 0x12, 0x75, + 0x3e, 0x02, 0x5d, 0x7c, 0x13, 0x1f, 0x16, 0x53, 0x3b, 0x74, 0x48, 0x3c, 0x5e, 0x39, 0x6c, 0x1c, 0x1c, 0x74, 0x39, 0x1f, 0x00, 0x1b, 0x06, 0x0a, 0x68, 0x3b, 0x52, 0x4f, + 0x1e, 0x6e, 0x3c, 0x35, 0x0c, 0x38, 0x0e, 0x0b, 0x3b, 0x1a, 0x76, 0x23, 0x29, 0x53, 0x1e, 0x5f, 0x41, 0x0c, 0x4b, 0x0a, 0x65, 0x28, 0x78, 0x67, 0x48, 0x59, 0x26, 0x6d, + 0x31, 0x76, 0x23, 0x70, 0x61, 0x64, 0x3b, 0x38, 0x79, 0x66, 0x74, 0x53, 0x2c, 0x64, 0x64, 0x54, 0x03, 0x54, 0x65, 0x44, 0x4c, 0x18, 0x4f, 0x48, 0x20, 0x4f, 0x72, 0x10, + 0x3f, 0x0c, 0x52, 0x2d, 0x03, 0x14, 0x03, 0x51, 0x42, 0x10, 0x77, 0x6a, 0x34, 0x06, 0x32, 0x03, 0x72, 0x14, 0x7c, 0x08, 0x5d, 0x52, 0x1a, 0x62, 0x7c, 0x3e, 0x30, 0x7e, + 0x5f, 0x7f, 0x54, 0x0f, 0x44, 0x49, 0x5d, 0x5e, 0x10, 0x6a, 0x06, 0x2b, 0x06, 0x53, 0x10, 0x39, 0x37, 0x32, 0x4a, 0x4e, 0x3d, 0x2b, 0x65, 0x38, 0x39, 0x07, 0x72, 0x54, + 0x64, 0x4d, 0x56, 0x6a, 0x03, 0x22, 0x70, 0x7b, 0x5f, 0x60, 0x0b, 0x2a, 0x0b, 0x6b, 0x10, 0x64, 0x14, 0x05, 0x22, 0x00, 0x73, 0x40, 0x23, 0x5b, 0x51, 0x1f, 0x2b, 0x1a, + 0x5d, 0x69, 0x7a, 0x46, 0x0c, 0x5f, 0x32, 0x4b, 0x4a, 0x28, 0x52, 0x79, 0x5b, 0x12, 0x42, 0x18, 0x00, 0x5d, 0x27, 0x31, 0x53, 0x3c, 0x4c, 0x36, 0x4e, 0x38, 0x3f, 0x72, + 0x03, 0x71, 0x02, 0x5b, 0x36, 0x59, 0x7f, 0x75, 0x6e, 0x08, 0x54, 0x0d, 0x34, 0x1c, 0x34, 0x57, 0x5d, 0x69, 0x48, 0x00, 0x3b, 0x05, 0x07, 0x6e, 0x27, 0x65, 0x6e, 0x40, + 0x3d, 0x3a, 0x4f, 0x72, 0x5d, 0x39, 0x16, 0x0f, 0x63, 0x12, 0x12, 0x15, 0x3a, 0x70, 0x0d, 0x57, 0x18, 0x0d, 0x5e, 0x3d, 0x22, 0x68, 0x68, 0x7c, 0x6d, 0x4f, 0x0c, 0x7b, + 0x09, 0x2d, 0x4a, 0x73, 0x20, 0x47, 0x07, 0x57, 0x75, 0x5d, 0x53, 0x70, 0x34, 0x21, 0x40, 0x57, 0x51, 0x5e, 0x49, 0x44, 0x00, 0x54, 0x27, 0x04, 0x68, 0x7e, 0x59, 0x56, + 0x58, 0x74, 0x14, 0x3c, 0x16, 0x33, 0x41, 0x16, 0x4b, 0x2f, 0x49, 0x37, 0x0a, 0x54, 0x08, 0x08, 0x1f, 0x39, 0x67, 0x76, 0x28, 0x28, 0x07, 0x1d, 0x61, 0x47, 0x51, 0x4d, + 0x75, 0x26, 0x52, 0x47, 0x47, 0x0c, 0x57, 0x58, 0x74, 0x3e, 0x62, 0x6c, 0x58, 0x3a, 0x44, 0x1e, 0x16, 0x2e, 0x21, 0x1c, 0x73, 0x45, 0x67, 0x74, 0x4f, 0x33, 0x66, 0x0e, + 0x74, 0x66, 0x26, 0x1f, 0x2e, 0x38, 0x44, 0x40, 0x7e, 0x2a, 0x50, 0x52, 0x5e, 0x43, 0x01, 0x7a, 0x38, 0x49, 0x3c, 0x55, 0x4d, 0x5a, 0x44, 0x08, 0x26, 0x59, 0x4d, 0x45, + 0x0b, 0x48, 0x0a, 0x33, 0x5e, 0x4a, 0x4d, 0x75, 0x16, 0x17, 0x63, 0x46, 0x01, 0x2a, 0x55, 0x7b, 0x0f, 0x02, 0x73, 0x6a, 0x4b, 0x7f, 0x75, 0x65, 0x3c, 0x4c, 0x33, 0x39, + 0x6c, 0x74, 0x05, 0x60, 0x0f, 0x7f, 0x2d, 0x41, 0x4d, 0x4d, 0x46, 0x71, 0x09, 0x6f, 0x4f, 0x60, 0x15, 0x0f, 0x46, 0x73, 0x63, 0x4c, 0x5e, 0x74, 0x30, 0x0d, 0x28, 0x43, + 0x08, 0x72, 0x32, 0x04, 0x2e, 0x31, 0x29, 0x27, 0x44, 0x6d, 0x13, 0x17, 0x48, 0x0f, 0x49, 0x52, 0x10, 0x13, 0x7f, 0x17, 0x16, 0x62, 0x79, 0x35, 0x78, 0x3e, 0x01, 0x7c, + 0x2e, 0x0f, 0x76, 0x3e, 0x5e, 0x53, 0x6c, 0x5b, 0x5f, 0x7c, 0x19, 0x41, 0x02, 0x2f, 0x17, 0x64, 0x41, 0x75, 0x10, 0x04, 0x47, 0x7c, 0x3d, 0x4b, 0x52, 0x00, 0x10, 0x5d, + 0x51, 0x4e, 0x7a, 0x27, 0x25, 0x55, 0x40, 0x12, 0x35, 0x60, 0x05, 0x1b, 0x34, 0x2d, 0x04, 0x7a, 0x6a, 0x69, 0x02, 0x79, 0x03, 0x3a, 0x2f, 0x06, 0x0a, 0x79, 0x7b, 0x12, + 0x5d, 0x7c, 0x52, 0x29, 0x47, 0x58, 0x12, 0x73, 0x3f, 0x27, 0x56, 0x05, 0x0c, 0x48, 0x32, 0x58, 0x6b, 0x57, 0x5c, 0x03, 0x64, 0x56, 0x11, 0x52, 0x7a, 0x30, 0x36, 0x29, + 0x17, 0x3b, 0x68, 0x7a, 0x7c, 0x05, 0x6b, 0x6b, 0x13, 0x6a, 0x24, 0x5c, 0x68, 0x42, 0x18, 0x32, 0x03, 0x73, 0x6e, 0x04, 0x21, 0x2e, 0x01, 0x04, 0x63, 0x7d, 0x44, 0x41, + 0x12, 0x31, 0x0b, 0x15, 0x1f, 0x70, 0x00, 0x2e, 0x66, 0x14, 0x3c, 0x7f, 0x2b, 0x00, 0x1f, 0x0c, 0x28, 0x59, 0x0a, 0x16, 0x49, 0x5a, 0x5c, 0x64, 0x65, 0x4b, 0x11, 0x29, + 0x15, 0x36, 0x5a, 0x65, 0x19, 0x4f, 0x60, 0x23, 0x3a, 0x3a, 0x13, 0x25, 0x02, 0x78, 0x4c, 0x54}; + char b64_known[1369] = { + 0x43, 0x7a, 0x42, 0x45, 0x59, 0x6e, 0x77, 0x69, 0x48, 0x77, 0x30, 0x46, 0x5a, 0x79, 0x77, 0x71, 0x4f, 0x53, 0x46, 0x47, 0x43, 0x46, 0x42, 0x6d, 0x4e, 0x44, 0x63, 0x4c, + 0x52, 0x55, 0x73, 0x34, 0x4d, 0x67, 0x5a, 0x36, 0x50, 0x6e, 0x38, 0x4d, 0x51, 0x42, 0x68, 0x72, 0x4c, 0x57, 0x42, 0x4d, 0x59, 0x41, 0x77, 0x6a, 0x51, 0x7a, 0x73, 0x2b, + 0x47, 0x78, 0x59, 0x45, 0x52, 0x6c, 0x67, 0x2f, 0x51, 0x47, 0x6f, 0x52, 0x42, 0x57, 0x4e, 0x78, 0x46, 0x44, 0x56, 0x48, 0x65, 0x52, 0x4e, 0x76, 0x61, 0x79, 0x63, 0x59, + 0x57, 0x30, 0x67, 0x6e, 0x50, 0x6d, 0x38, 0x56, 0x4d, 0x30, 0x38, 0x2b, 0x58, 0x6c, 0x46, 0x7a, 0x61, 0x43, 0x55, 0x50, 0x42, 0x6c, 0x74, 0x38, 0x63, 0x6e, 0x55, 0x2b, + 0x50, 0x78, 0x74, 0x63, 0x62, 0x57, 0x6f, 0x35, 0x66, 0x47, 0x4e, 0x6a, 0x59, 0x47, 0x78, 0x36, 0x4d, 0x33, 0x5a, 0x53, 0x45, 0x79, 0x55, 0x7a, 0x66, 0x57, 0x55, 0x6a, + 0x4a, 0x78, 0x45, 0x47, 0x42, 0x6b, 0x64, 0x78, 0x48, 0x68, 0x52, 0x30, 0x59, 0x33, 0x41, 0x74, 0x46, 0x53, 0x63, 0x59, 0x55, 0x51, 0x59, 0x46, 0x4d, 0x78, 0x45, 0x73, + 0x61, 0x77, 0x41, 0x74, 0x64, 0x79, 0x42, 0x49, 0x44, 0x58, 0x4e, 0x52, 0x52, 0x53, 0x56, 0x2f, 0x66, 0x7a, 0x55, 0x6d, 0x4c, 0x69, 0x5a, 0x54, 0x4a, 0x47, 0x67, 0x65, + 0x44, 0x6c, 0x67, 0x36, 0x57, 0x56, 0x42, 0x57, 0x4e, 0x31, 0x39, 0x6d, 0x41, 0x55, 0x78, 0x61, 0x5a, 0x44, 0x4a, 0x51, 0x65, 0x32, 0x6f, 0x67, 0x63, 0x69, 0x73, 0x64, + 0x66, 0x6b, 0x4e, 0x37, 0x59, 0x55, 0x49, 0x4c, 0x59, 0x58, 0x4d, 0x6b, 0x65, 0x54, 0x70, 0x72, 0x53, 0x6e, 0x6c, 0x75, 0x43, 0x51, 0x38, 0x6e, 0x4c, 0x51, 0x78, 0x65, + 0x4d, 0x6b, 0x73, 0x4e, 0x65, 0x55, 0x59, 0x35, 0x49, 0x51, 0x6f, 0x6d, 0x58, 0x7a, 0x6f, 0x41, 0x4a, 0x6a, 0x38, 0x54, 0x4c, 0x6e, 0x35, 0x51, 0x4b, 0x32, 0x64, 0x47, + 0x63, 0x6a, 0x38, 0x37, 0x41, 0x55, 0x59, 0x62, 0x43, 0x7a, 0x56, 0x4a, 0x4f, 0x52, 0x6c, 0x77, 0x50, 0x51, 0x4a, 0x42, 0x44, 0x6a, 0x67, 0x46, 0x64, 0x6d, 0x56, 0x50, + 0x4d, 0x57, 0x78, 0x65, 0x46, 0x77, 0x51, 0x56, 0x4e, 0x69, 0x5a, 0x6b, 0x4e, 0x42, 0x51, 0x58, 0x66, 0x41, 0x34, 0x4c, 0x57, 0x31, 0x56, 0x54, 0x61, 0x77, 0x42, 0x43, + 0x51, 0x55, 0x38, 0x43, 0x58, 0x42, 0x4d, 0x4b, 0x4c, 0x43, 0x77, 0x2b, 0x45, 0x42, 0x51, 0x7a, 0x52, 0x58, 0x78, 0x36, 0x57, 0x6a, 0x46, 0x68, 0x4f, 0x51, 0x67, 0x69, + 0x61, 0x68, 0x34, 0x50, 0x62, 0x78, 0x74, 0x73, 0x45, 0x31, 0x35, 0x35, 0x49, 0x48, 0x6c, 0x51, 0x59, 0x67, 0x59, 0x73, 0x64, 0x68, 0x63, 0x45, 0x4b, 0x79, 0x70, 0x31, + 0x48, 0x77, 0x77, 0x33, 0x54, 0x67, 0x39, 0x37, 0x4c, 0x54, 0x52, 0x31, 0x59, 0x44, 0x46, 0x30, 0x4c, 0x67, 0x70, 0x4b, 0x45, 0x57, 0x78, 0x4a, 0x4a, 0x51, 0x45, 0x36, + 0x50, 0x53, 0x49, 0x65, 0x62, 0x52, 0x68, 0x52, 0x65, 0x43, 0x31, 0x69, 0x4d, 0x55, 0x78, 0x51, 0x51, 0x42, 0x64, 0x4c, 0x62, 0x79, 0x49, 0x41, 0x66, 0x32, 0x45, 0x71, + 0x4e, 0x44, 0x34, 0x41, 0x58, 0x79, 0x39, 0x66, 0x4c, 0x78, 0x51, 0x71, 0x56, 0x53, 0x63, 0x66, 0x52, 0x68, 0x38, 0x53, 0x52, 0x6c, 0x34, 0x65, 0x44, 0x48, 0x77, 0x34, + 0x41, 0x57, 0x46, 0x6b, 0x64, 0x69, 0x4a, 0x75, 0x43, 0x43, 0x41, 0x34, 0x54, 0x33, 0x4e, 0x79, 0x56, 0x52, 0x4a, 0x43, 0x47, 0x56, 0x42, 0x68, 0x51, 0x33, 0x64, 0x39, + 0x51, 0x53, 0x34, 0x31, 0x54, 0x7a, 0x30, 0x78, 0x4b, 0x46, 0x68, 0x6e, 0x47, 0x77, 0x4e, 0x52, 0x49, 0x44, 0x49, 0x63, 0x43, 0x47, 0x34, 0x33, 0x64, 0x54, 0x64, 0x45, + 0x54, 0x32, 0x67, 0x5a, 0x42, 0x32, 0x51, 0x55, 0x4b, 0x43, 0x55, 0x72, 0x61, 0x54, 0x55, 0x59, 0x4a, 0x79, 0x59, 0x55, 0x45, 0x33, 0x42, 0x43, 0x47, 0x52, 0x4a, 0x31, + 0x50, 0x67, 0x4a, 0x64, 0x66, 0x42, 0x4d, 0x66, 0x46, 0x6c, 0x4d, 0x37, 0x64, 0x45, 0x67, 0x38, 0x58, 0x6a, 0x6c, 0x73, 0x48, 0x42, 0x78, 0x30, 0x4f, 0x52, 0x38, 0x41, + 0x47, 0x77, 0x59, 0x4b, 0x61, 0x44, 0x74, 0x53, 0x54, 0x78, 0x35, 0x75, 0x50, 0x44, 0x55, 0x4d, 0x4f, 0x41, 0x34, 0x4c, 0x4f, 0x78, 0x70, 0x32, 0x49, 0x79, 0x6c, 0x54, + 0x48, 0x6c, 0x39, 0x42, 0x44, 0x45, 0x73, 0x4b, 0x5a, 0x53, 0x68, 0x34, 0x5a, 0x30, 0x68, 0x5a, 0x4a, 0x6d, 0x30, 0x78, 0x64, 0x69, 0x4e, 0x77, 0x59, 0x57, 0x51, 0x37, + 0x4f, 0x48, 0x6c, 0x6d, 0x64, 0x46, 0x4d, 0x73, 0x5a, 0x47, 0x52, 0x55, 0x41, 0x31, 0x52, 0x6c, 0x52, 0x45, 0x77, 0x59, 0x54, 0x30, 0x67, 0x67, 0x54, 0x33, 0x49, 0x51, + 0x50, 0x77, 0x78, 0x53, 0x4c, 0x51, 0x4d, 0x55, 0x41, 0x31, 0x46, 0x43, 0x45, 0x48, 0x64, 0x71, 0x4e, 0x41, 0x59, 0x79, 0x41, 0x33, 0x49, 0x55, 0x66, 0x41, 0x68, 0x64, + 0x55, 0x68, 0x70, 0x69, 0x66, 0x44, 0x34, 0x77, 0x66, 0x6c, 0x39, 0x2f, 0x56, 0x41, 0x39, 0x45, 0x53, 0x56, 0x31, 0x65, 0x45, 0x47, 0x6f, 0x47, 0x4b, 0x77, 0x5a, 0x54, + 0x45, 0x44, 0x6b, 0x33, 0x4d, 0x6b, 0x70, 0x4f, 0x50, 0x53, 0x74, 0x6c, 0x4f, 0x44, 0x6b, 0x48, 0x63, 0x6c, 0x52, 0x6b, 0x54, 0x56, 0x5a, 0x71, 0x41, 0x79, 0x4a, 0x77, + 0x65, 0x31, 0x39, 0x67, 0x43, 0x79, 0x6f, 0x4c, 0x61, 0x78, 0x42, 0x6b, 0x46, 0x41, 0x55, 0x69, 0x41, 0x48, 0x4e, 0x41, 0x49, 0x31, 0x74, 0x52, 0x48, 0x79, 0x73, 0x61, + 0x58, 0x57, 0x6c, 0x36, 0x52, 0x67, 0x78, 0x66, 0x4d, 0x6b, 0x74, 0x4b, 0x4b, 0x46, 0x4a, 0x35, 0x57, 0x78, 0x4a, 0x43, 0x47, 0x41, 0x42, 0x64, 0x4a, 0x7a, 0x46, 0x54, + 0x50, 0x45, 0x77, 0x32, 0x54, 0x6a, 0x67, 0x2f, 0x63, 0x67, 0x4e, 0x78, 0x41, 0x6c, 0x73, 0x32, 0x57, 0x58, 0x39, 0x31, 0x62, 0x67, 0x68, 0x55, 0x44, 0x54, 0x51, 0x63, + 0x4e, 0x46, 0x64, 0x64, 0x61, 0x55, 0x67, 0x41, 0x4f, 0x77, 0x55, 0x48, 0x62, 0x69, 0x64, 0x6c, 0x62, 0x6b, 0x41, 0x39, 0x4f, 0x6b, 0x39, 0x79, 0x58, 0x54, 0x6b, 0x57, + 0x44, 0x32, 0x4d, 0x53, 0x45, 0x68, 0x55, 0x36, 0x63, 0x41, 0x31, 0x58, 0x47, 0x41, 0x31, 0x65, 0x50, 0x53, 0x4a, 0x6f, 0x61, 0x48, 0x78, 0x74, 0x54, 0x77, 0x78, 0x37, + 0x43, 0x53, 0x31, 0x4b, 0x63, 0x79, 0x42, 0x48, 0x42, 0x31, 0x64, 0x31, 0x58, 0x56, 0x4e, 0x77, 0x4e, 0x43, 0x46, 0x41, 0x56, 0x31, 0x46, 0x65, 0x53, 0x55, 0x51, 0x41, + 0x56, 0x43, 0x63, 0x45, 0x61, 0x48, 0x35, 0x5a, 0x56, 0x6c, 0x68, 0x30, 0x46, 0x44, 0x77, 0x57, 0x4d, 0x30, 0x45, 0x57, 0x53, 0x79, 0x39, 0x4a, 0x4e, 0x77, 0x70, 0x55, + 0x43, 0x41, 0x67, 0x66, 0x4f, 0x57, 0x64, 0x32, 0x4b, 0x43, 0x67, 0x48, 0x48, 0x57, 0x46, 0x48, 0x55, 0x55, 0x31, 0x31, 0x4a, 0x6c, 0x4a, 0x48, 0x52, 0x77, 0x78, 0x58, + 0x57, 0x48, 0x51, 0x2b, 0x59, 0x6d, 0x78, 0x59, 0x4f, 0x6b, 0x51, 0x65, 0x46, 0x69, 0x34, 0x68, 0x48, 0x48, 0x4e, 0x46, 0x5a, 0x33, 0x52, 0x50, 0x4d, 0x32, 0x59, 0x4f, + 0x64, 0x47, 0x59, 0x6d, 0x48, 0x79, 0x34, 0x34, 0x52, 0x45, 0x42, 0x2b, 0x4b, 0x6c, 0x42, 0x53, 0x58, 0x6b, 0x4d, 0x42, 0x65, 0x6a, 0x68, 0x4a, 0x50, 0x46, 0x56, 0x4e, + 0x57, 0x6b, 0x51, 0x49, 0x4a, 0x6c, 0x6c, 0x4e, 0x52, 0x51, 0x74, 0x49, 0x43, 0x6a, 0x4e, 0x65, 0x53, 0x6b, 0x31, 0x31, 0x46, 0x68, 0x64, 0x6a, 0x52, 0x67, 0x45, 0x71, + 0x56, 0x58, 0x73, 0x50, 0x41, 0x6e, 0x4e, 0x71, 0x53, 0x33, 0x39, 0x31, 0x5a, 0x54, 0x78, 0x4d, 0x4d, 0x7a, 0x6c, 0x73, 0x64, 0x41, 0x56, 0x67, 0x44, 0x33, 0x38, 0x74, + 0x51, 0x55, 0x31, 0x4e, 0x52, 0x6e, 0x45, 0x4a, 0x62, 0x30, 0x39, 0x67, 0x46, 0x51, 0x39, 0x47, 0x63, 0x32, 0x4e, 0x4d, 0x58, 0x6e, 0x51, 0x77, 0x44, 0x53, 0x68, 0x44, + 0x43, 0x48, 0x49, 0x79, 0x42, 0x43, 0x34, 0x78, 0x4b, 0x53, 0x64, 0x45, 0x62, 0x52, 0x4d, 0x58, 0x53, 0x41, 0x39, 0x4a, 0x55, 0x68, 0x41, 0x54, 0x66, 0x78, 0x63, 0x57, + 0x59, 0x6e, 0x6b, 0x31, 0x65, 0x44, 0x34, 0x42, 0x66, 0x43, 0x34, 0x50, 0x64, 0x6a, 0x35, 0x65, 0x55, 0x32, 0x78, 0x62, 0x58, 0x33, 0x77, 0x5a, 0x51, 0x51, 0x49, 0x76, + 0x46, 0x32, 0x52, 0x42, 0x64, 0x52, 0x41, 0x45, 0x52, 0x33, 0x77, 0x39, 0x53, 0x31, 0x49, 0x41, 0x45, 0x46, 0x31, 0x52, 0x54, 0x6e, 0x6f, 0x6e, 0x4a, 0x56, 0x56, 0x41, + 0x45, 0x6a, 0x56, 0x67, 0x42, 0x52, 0x73, 0x30, 0x4c, 0x51, 0x52, 0x36, 0x61, 0x6d, 0x6b, 0x43, 0x65, 0x51, 0x4d, 0x36, 0x4c, 0x77, 0x59, 0x4b, 0x65, 0x58, 0x73, 0x53, + 0x58, 0x58, 0x78, 0x53, 0x4b, 0x55, 0x64, 0x59, 0x45, 0x6e, 0x4d, 0x2f, 0x4a, 0x31, 0x59, 0x46, 0x44, 0x45, 0x67, 0x79, 0x57, 0x47, 0x74, 0x58, 0x58, 0x41, 0x4e, 0x6b, + 0x56, 0x68, 0x46, 0x53, 0x65, 0x6a, 0x41, 0x32, 0x4b, 0x52, 0x63, 0x37, 0x61, 0x48, 0x70, 0x38, 0x42, 0x57, 0x74, 0x72, 0x45, 0x32, 0x6f, 0x6b, 0x58, 0x47, 0x68, 0x43, + 0x47, 0x44, 0x49, 0x44, 0x63, 0x32, 0x34, 0x45, 0x49, 0x53, 0x34, 0x42, 0x42, 0x47, 0x4e, 0x39, 0x52, 0x45, 0x45, 0x53, 0x4d, 0x51, 0x73, 0x56, 0x48, 0x33, 0x41, 0x41, + 0x4c, 0x6d, 0x59, 0x55, 0x50, 0x48, 0x38, 0x72, 0x41, 0x42, 0x38, 0x4d, 0x4b, 0x46, 0x6b, 0x4b, 0x46, 0x6b, 0x6c, 0x61, 0x58, 0x47, 0x52, 0x6c, 0x53, 0x78, 0x45, 0x70, + 0x46, 0x54, 0x5a, 0x61, 0x5a, 0x52, 0x6c, 0x50, 0x59, 0x43, 0x4d, 0x36, 0x4f, 0x68, 0x4d, 0x6c, 0x41, 0x6e, 0x68, 0x4d, 0x56, 0x41, 0x3d, 0x3d, 0x00}; char *b64_test; plan_tests(1); - base64_encode_alloc (random, 1024, &b64_test); + base64_encode_alloc(random, 1024, &b64_test); - ok(strcmp(b64_known, b64_test) == 0, - "Test matching a base64 encoded 1024 bytes random string"); + ok(strcmp(b64_known, b64_test) == 0, "Test matching a base64 encoded 1024 bytes random string"); return exit_status(); } - diff --git a/lib/tests/test_cmd.c b/lib/tests/test_cmd.c index 02ae11f..a60b64e 100644 --- a/lib/tests/test_cmd.c +++ b/lib/tests/test_cmd.c @@ -1,20 +1,20 @@ /***************************************************************************** -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -* -* -*****************************************************************************/ + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * + *****************************************************************************/ #include "common.h" #include "utils_cmd.h" @@ -22,27 +22,23 @@ #include "tap.h" #define COMMAND_LINE 1024 -#define UNSET 65530 +#define UNSET 65530 -char * -get_command (char *const *line) -{ +char *get_command(char *const *line) { char *cmd; int i = 0; - asprintf (&cmd, " %s", line[i++]); + asprintf(&cmd, " %s", line[i++]); while (line[i] != NULL) { - asprintf (&cmd, "%s %s", cmd, line[i]); + asprintf(&cmd, "%s %s", cmd, line[i]); i++; } return cmd; } -int -main (int argc, char **argv) -{ - char **command_line = malloc (sizeof (char *) * COMMAND_LINE); +int main(int argc, char **argv) { + char **command_line = malloc(sizeof(char *) * COMMAND_LINE); char *command = NULL; char *perl; output chld_out, chld_err; @@ -51,183 +47,153 @@ main (int argc, char **argv) plan_tests(51); - diag ("Running plain echo command, set one"); + diag("Running plain echo command, set one"); /* ensure everything is empty before we begin */ - memset (&chld_out, 0, sizeof (output)); - memset (&chld_err, 0, sizeof (output)); - ok (chld_out.lines == 0, "(initialised) Checking stdout is reset"); - ok (chld_err.lines == 0, "(initialised) Checking stderr is reset"); - ok (result == UNSET, "(initialised) Checking exit code is reset"); - - command_line[0] = strdup ("/bin/echo"); - command_line[1] = strdup ("this"); - command_line[2] = strdup ("is"); - command_line[3] = strdup ("test"); - command_line[4] = strdup ("one"); - - command = get_command (command_line); - - result = cmd_run_array (command_line, &chld_out, &chld_err, 0); - ok (chld_out.lines == 1, - "(array) Check for expected number of stdout lines"); - ok (chld_err.lines == 0, - "(array) Check for expected number of stderr lines"); - ok (strcmp (chld_out.line[0], "this is test one") == 0, - "(array) Check for expected stdout output"); - ok (result == 0, "(array) Checking exit code"); + memset(&chld_out, 0, sizeof(output)); + memset(&chld_err, 0, sizeof(output)); + ok(chld_out.lines == 0, "(initialised) Checking stdout is reset"); + ok(chld_err.lines == 0, "(initialised) Checking stderr is reset"); + ok(result == UNSET, "(initialised) Checking exit code is reset"); + + command_line[0] = strdup("/bin/echo"); + command_line[1] = strdup("this"); + command_line[2] = strdup("is"); + command_line[3] = strdup("test"); + command_line[4] = strdup("one"); + + command = get_command(command_line); + + result = cmd_run_array(command_line, &chld_out, &chld_err, 0); + ok(chld_out.lines == 1, "(array) Check for expected number of stdout lines"); + ok(chld_err.lines == 0, "(array) Check for expected number of stderr lines"); + ok(strcmp(chld_out.line[0], "this is test one") == 0, "(array) Check for expected stdout output"); + ok(result == 0, "(array) Checking exit code"); /* ensure everything is empty again */ - memset (&chld_out, 0, sizeof (output)); - memset (&chld_err, 0, sizeof (output)); + memset(&chld_out, 0, sizeof(output)); + memset(&chld_err, 0, sizeof(output)); result = UNSET; - ok (chld_out.lines == 0, "(initialised) Checking stdout is reset"); - ok (chld_err.lines == 0, "(initialised) Checking stderr is reset"); - ok (result == UNSET, "(initialised) Checking exit code is reset"); + ok(chld_out.lines == 0, "(initialised) Checking stdout is reset"); + ok(chld_err.lines == 0, "(initialised) Checking stderr is reset"); + ok(result == UNSET, "(initialised) Checking exit code is reset"); - result = cmd_run (command, &chld_out, &chld_err, 0); + result = cmd_run(command, &chld_out, &chld_err, 0); - ok (chld_out.lines == 1, - "(string) Check for expected number of stdout lines"); - ok (chld_err.lines == 0, - "(string) Check for expected number of stderr lines"); - ok (strcmp (chld_out.line[0], "this is test one") == 0, - "(string) Check for expected stdout output"); - ok (result == 0, "(string) Checking exit code"); + ok(chld_out.lines == 1, "(string) Check for expected number of stdout lines"); + ok(chld_err.lines == 0, "(string) Check for expected number of stderr lines"); + ok(strcmp(chld_out.line[0], "this is test one") == 0, "(string) Check for expected stdout output"); + ok(result == 0, "(string) Checking exit code"); - diag ("Running plain echo command, set two"); + diag("Running plain echo command, set two"); /* ensure everything is empty again */ - memset (&chld_out, 0, sizeof (output)); - memset (&chld_err, 0, sizeof (output)); + memset(&chld_out, 0, sizeof(output)); + memset(&chld_err, 0, sizeof(output)); result = UNSET; - ok (chld_out.lines == 0, "(initialised) Checking stdout is reset"); - ok (chld_err.lines == 0, "(initialised) Checking stderr is reset"); - ok (result == UNSET, "(initialised) Checking exit code is reset"); + ok(chld_out.lines == 0, "(initialised) Checking stdout is reset"); + ok(chld_err.lines == 0, "(initialised) Checking stderr is reset"); + ok(result == UNSET, "(initialised) Checking exit code is reset"); - command_line[0] = strdup ("/bin/echo"); - command_line[1] = strdup ("this is test two"); + command_line[0] = strdup("/bin/echo"); + command_line[1] = strdup("this is test two"); command_line[2] = NULL; command_line[3] = NULL; command_line[4] = NULL; - result = cmd_run_array (command_line, &chld_out, &chld_err, 0); - ok (chld_out.lines == 1, - "(array) Check for expected number of stdout lines"); - ok (chld_err.lines == 0, - "(array) Check for expected number of stderr lines"); - ok (strcmp (chld_out.line[0], "this is test two") == 0, - "(array) Check for expected stdout output"); - ok (result == 0, "(array) Checking exit code"); + result = cmd_run_array(command_line, &chld_out, &chld_err, 0); + ok(chld_out.lines == 1, "(array) Check for expected number of stdout lines"); + ok(chld_err.lines == 0, "(array) Check for expected number of stderr lines"); + ok(strcmp(chld_out.line[0], "this is test two") == 0, "(array) Check for expected stdout output"); + ok(result == 0, "(array) Checking exit code"); /* ensure everything is empty again */ - memset (&chld_out, 0, sizeof (output)); - memset (&chld_err, 0, sizeof (output)); + memset(&chld_out, 0, sizeof(output)); + memset(&chld_err, 0, sizeof(output)); result = UNSET; - ok (chld_out.lines == 0, "(initialised) Checking stdout is reset"); - ok (chld_err.lines == 0, "(initialised) Checking stderr is reset"); - ok (result == UNSET, "(initialised) Checking exit code is reset"); - - result = cmd_run (command, &chld_out, &chld_err, 0); + ok(chld_out.lines == 0, "(initialised) Checking stdout is reset"); + ok(chld_err.lines == 0, "(initialised) Checking stderr is reset"); + ok(result == UNSET, "(initialised) Checking exit code is reset"); - ok (chld_out.lines == 1, - "(string) Check for expected number of stdout lines"); - ok (chld_err.lines == 0, - "(string) Check for expected number of stderr lines"); - ok (strcmp (chld_out.line[0], "this is test one") == 0, - "(string) Check for expected stdout output"); - ok (result == 0, "(string) Checking exit code"); + result = cmd_run(command, &chld_out, &chld_err, 0); + ok(chld_out.lines == 1, "(string) Check for expected number of stdout lines"); + ok(chld_err.lines == 0, "(string) Check for expected number of stderr lines"); + ok(strcmp(chld_out.line[0], "this is test one") == 0, "(string) Check for expected stdout output"); + ok(result == 0, "(string) Checking exit code"); /* ensure everything is empty again */ - memset (&chld_out, 0, sizeof (output)); - memset (&chld_err, 0, sizeof (output)); + memset(&chld_out, 0, sizeof(output)); + memset(&chld_err, 0, sizeof(output)); result = UNSET; - ok (chld_out.lines == 0, "(initialised) Checking stdout is reset"); - ok (chld_err.lines == 0, "(initialised) Checking stderr is reset"); - ok (result == UNSET, "(initialised) Checking exit code is reset"); + ok(chld_out.lines == 0, "(initialised) Checking stdout is reset"); + ok(chld_err.lines == 0, "(initialised) Checking stderr is reset"); + ok(result == UNSET, "(initialised) Checking exit code is reset"); /* Pass linefeeds via parameters through - those should be evaluated by echo to give multi line output */ command_line[0] = strdup("/bin/echo"); command_line[1] = strdup("this is a test via echo\nline two\nit's line 3"); command_line[2] = strdup("and (note space between '3' and 'and') $$ will not get evaluated"); - result = cmd_run_array (command_line, &chld_out, &chld_err, 0); - ok (chld_out.lines == 3, - "(array) Check for expected number of stdout lines"); - ok (chld_err.lines == 0, - "(array) Check for expected number of stderr lines"); - ok (strcmp (chld_out.line[0], "this is a test via echo") == 0, - "(array) Check line 1 for expected stdout output"); - ok (strcmp (chld_out.line[1], "line two") == 0, - "(array) Check line 2 for expected stdout output"); - ok (strcmp (chld_out.line[2], "it's line 3 and (note space between '3' and 'and') $$ will not get evaluated") == 0, - "(array) Check line 3 for expected stdout output"); - ok (result == 0, "(array) Checking exit code"); - - + result = cmd_run_array(command_line, &chld_out, &chld_err, 0); + ok(chld_out.lines == 3, "(array) Check for expected number of stdout lines"); + ok(chld_err.lines == 0, "(array) Check for expected number of stderr lines"); + ok(strcmp(chld_out.line[0], "this is a test via echo") == 0, "(array) Check line 1 for expected stdout output"); + ok(strcmp(chld_out.line[1], "line two") == 0, "(array) Check line 2 for expected stdout output"); + ok(strcmp(chld_out.line[2], "it's line 3 and (note space between '3' and 'and') $$ will not get evaluated") == 0, "(array) Check line 3 for expected stdout output"); + ok(result == 0, "(array) Checking exit code"); /* ensure everything is empty again */ - memset (&chld_out, 0, sizeof (output)); - memset (&chld_err, 0, sizeof (output)); + memset(&chld_out, 0, sizeof(output)); + memset(&chld_err, 0, sizeof(output)); result = UNSET; - ok (chld_out.lines == 0, "(initialised) Checking stdout is reset"); - ok (chld_err.lines == 0, "(initialised) Checking stderr is reset"); - ok (result == UNSET, "(initialised) Checking exit code is reset"); + ok(chld_out.lines == 0, "(initialised) Checking stdout is reset"); + ok(chld_err.lines == 0, "(initialised) Checking stderr is reset"); + ok(result == UNSET, "(initialised) Checking exit code is reset"); command = (char *)malloc(COMMAND_LINE); strcpy(command, "/bin/echo3456 non-existent command"); - result = cmd_run (command, &chld_out, &chld_err, 0); - - ok (chld_out.lines == 0, - "Non existent command, so no output"); - ok (chld_err.lines == 0, - "No stderr either"); - ok (result == 3, "Get return code 3 (?) for non-existent command"); + result = cmd_run(command, &chld_out, &chld_err, 0); + ok(chld_out.lines == 0, "Non existent command, so no output"); + ok(chld_err.lines == 0, "No stderr either"); + ok(result == 3, "Get return code 3 (?) for non-existent command"); /* ensure everything is empty again */ - memset (&chld_out, 0, sizeof (output)); - memset (&chld_err, 0, sizeof (output)); + memset(&chld_out, 0, sizeof(output)); + memset(&chld_err, 0, sizeof(output)); result = UNSET; command = (char *)malloc(COMMAND_LINE); strcpy(command, "/bin/sh non-existent-file"); - result = cmd_run (command, &chld_out, &chld_err, 0); - - ok (chld_out.lines == 0, - "/bin/sh returns no stdout when file is missing..."); - ok (chld_err.lines == 1, - "...but does give an error line"); - ok (strstr(chld_err.line[0],"non-existent-file") != NULL, "And missing filename is in error message"); - ok (result != 0, "Get non-zero return code from /bin/sh"); + result = cmd_run(command, &chld_out, &chld_err, 0); + ok(chld_out.lines == 0, "/bin/sh returns no stdout when file is missing..."); + ok(chld_err.lines == 1, "...but does give an error line"); + ok(strstr(chld_err.line[0], "non-existent-file") != NULL, "And missing filename is in error message"); + ok(result != 0, "Get non-zero return code from /bin/sh"); /* ensure everything is empty again */ result = UNSET; command = (char *)malloc(COMMAND_LINE); - strcpy(command, "/bin/sh -c 'exit 7'"); - result = cmd_run (command, NULL, NULL, 0); - - ok (result == 7, "Get return code 7 from /bin/sh"); + strcpy(command, "/bin/sh -c 'exit 7'"); + result = cmd_run(command, NULL, NULL, 0); + ok(result == 7, "Get return code 7 from /bin/sh"); /* ensure everything is empty again */ - memset (&chld_out, 0, sizeof (output)); - memset (&chld_err, 0, sizeof (output)); + memset(&chld_out, 0, sizeof(output)); + memset(&chld_err, 0, sizeof(output)); result = UNSET; command = (char *)malloc(COMMAND_LINE); strcpy(command, "/bin/non-existent-command"); - result = cmd_run (command, &chld_out, &chld_err, 0); - - ok (chld_out.lines == 0, - "/bin/non-existent-command returns no stdout..."); - ok (chld_err.lines == 0, - "...and no stderr output either"); - ok (result == 3, "Get return code 3 = UNKNOWN when command does not exist"); + result = cmd_run(command, &chld_out, &chld_err, 0); + ok(chld_out.lines == 0, "/bin/non-existent-command returns no stdout..."); + ok(chld_err.lines == 0, "...and no stderr output either"); + ok(result == 3, "Get return code 3 = UNKNOWN when command does not exist"); - return exit_status (); + return exit_status(); } diff --git a/lib/tests/test_disk.c b/lib/tests/test_disk.c index e283fe2..c18db7a 100644 --- a/lib/tests/test_disk.c +++ b/lib/tests/test_disk.c @@ -1,36 +1,31 @@ /***************************************************************************** -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -* -* -*****************************************************************************/ + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * + *****************************************************************************/ #include "common.h" #include "utils_disk.h" #include "tap.h" #include "regex.h" -void np_test_mount_entry_regex (struct mount_entry *dummy_mount_list, - char *regstr, int cflags, int expect, - char *desc); +void np_test_mount_entry_regex(struct mount_entry *dummy_mount_list, char *regstr, int cflags, int expect, char *desc); - -int -main (int argc, char **argv) -{ - struct name_list *exclude_filesystem=NULL; - struct name_list *exclude_fstype=NULL; +int main(int argc, char **argv) { + struct name_list *exclude_filesystem = NULL; + struct name_list *exclude_fstype = NULL; struct name_list *dummy_mountlist = NULL; struct name_list *temp_name; struct parameter_list *paths = NULL; @@ -44,19 +39,19 @@ main (int argc, char **argv) plan_tests(33); - ok( np_find_name(exclude_filesystem, "/var/log") == false, "/var/log not in list"); + ok(np_find_name(exclude_filesystem, "/var/log") == false, "/var/log not in list"); np_add_name(&exclude_filesystem, "/var/log"); - ok( np_find_name(exclude_filesystem, "/var/log") == true, "is in list now"); - ok( np_find_name(exclude_filesystem, "/home") == false, "/home not in list"); + ok(np_find_name(exclude_filesystem, "/var/log") == true, "is in list now"); + ok(np_find_name(exclude_filesystem, "/home") == false, "/home not in list"); np_add_name(&exclude_filesystem, "/home"); - ok( np_find_name(exclude_filesystem, "/home") == true, "is in list now"); - ok( np_find_name(exclude_filesystem, "/var/log") == true, "/var/log still in list"); + ok(np_find_name(exclude_filesystem, "/home") == true, "is in list now"); + ok(np_find_name(exclude_filesystem, "/var/log") == true, "/var/log still in list"); - ok( np_find_name(exclude_fstype, "iso9660") == false, "iso9660 not in list"); + ok(np_find_name(exclude_fstype, "iso9660") == false, "iso9660 not in list"); np_add_name(&exclude_fstype, "iso9660"); - ok( np_find_name(exclude_fstype, "iso9660") == true, "is in list now"); + ok(np_find_name(exclude_fstype, "iso9660") == true, "is in list now"); - ok( np_find_name(exclude_filesystem, "iso9660") == false, "Make sure no clashing in variables"); + ok(np_find_name(exclude_filesystem, "iso9660") == false, "Make sure no clashing in variables"); /* for (temp_name = exclude_filesystem; temp_name; temp_name = temp_name->next) { @@ -64,55 +59,35 @@ main (int argc, char **argv) } */ - me = (struct mount_entry *) malloc(sizeof *me); + me = (struct mount_entry *)malloc(sizeof *me); me->me_devname = strdup("/dev/c0t0d0s0"); me->me_mountdir = strdup("/"); *mtail = me; mtail = &me->me_next; - me = (struct mount_entry *) malloc(sizeof *me); + me = (struct mount_entry *)malloc(sizeof *me); me->me_devname = strdup("/dev/c1t0d1s0"); me->me_mountdir = strdup("/var"); *mtail = me; mtail = &me->me_next; - me = (struct mount_entry *) malloc(sizeof *me); + me = (struct mount_entry *)malloc(sizeof *me); me->me_devname = strdup("/dev/c2t0d0s0"); me->me_mountdir = strdup("/home"); *mtail = me; mtail = &me->me_next; - np_test_mount_entry_regex(dummy_mount_list, strdup("/"), - cflags, 3, strdup("a")); - np_test_mount_entry_regex(dummy_mount_list, strdup("/dev"), - cflags, 3,strdup("regex on dev names:")); - np_test_mount_entry_regex(dummy_mount_list, strdup("/foo"), - cflags, 0, - strdup("regex on non existent dev/path:")); - np_test_mount_entry_regex(dummy_mount_list, strdup("/Foo"), - cflags | REG_ICASE,0, - strdup("regi on non existent dev/path:")); - np_test_mount_entry_regex(dummy_mount_list, strdup("/c.t0"), - cflags, 3, - strdup("partial devname regex match:")); - np_test_mount_entry_regex(dummy_mount_list, strdup("c0t0"), - cflags, 1, - strdup("partial devname regex match:")); - np_test_mount_entry_regex(dummy_mount_list, strdup("C0t0"), - cflags | REG_ICASE, 1, - strdup("partial devname regi match:")); - np_test_mount_entry_regex(dummy_mount_list, strdup("home"), - cflags, 1, - strdup("partial pathname regex match:")); - np_test_mount_entry_regex(dummy_mount_list, strdup("hOme"), - cflags | REG_ICASE, 1, - strdup("partial pathname regi match:")); - np_test_mount_entry_regex(dummy_mount_list, strdup("(/home)|(/var)"), - cflags, 2, - strdup("grouped regex pathname match:")); - np_test_mount_entry_regex(dummy_mount_list, strdup("(/homE)|(/Var)"), - cflags | REG_ICASE, 2, - strdup("grouped regi pathname match:")); + np_test_mount_entry_regex(dummy_mount_list, strdup("/"), cflags, 3, strdup("a")); + np_test_mount_entry_regex(dummy_mount_list, strdup("/dev"), cflags, 3, strdup("regex on dev names:")); + np_test_mount_entry_regex(dummy_mount_list, strdup("/foo"), cflags, 0, strdup("regex on non existent dev/path:")); + np_test_mount_entry_regex(dummy_mount_list, strdup("/Foo"), cflags | REG_ICASE, 0, strdup("regi on non existent dev/path:")); + np_test_mount_entry_regex(dummy_mount_list, strdup("/c.t0"), cflags, 3, strdup("partial devname regex match:")); + np_test_mount_entry_regex(dummy_mount_list, strdup("c0t0"), cflags, 1, strdup("partial devname regex match:")); + np_test_mount_entry_regex(dummy_mount_list, strdup("C0t0"), cflags | REG_ICASE, 1, strdup("partial devname regi match:")); + np_test_mount_entry_regex(dummy_mount_list, strdup("home"), cflags, 1, strdup("partial pathname regex match:")); + np_test_mount_entry_regex(dummy_mount_list, strdup("hOme"), cflags | REG_ICASE, 1, strdup("partial pathname regi match:")); + np_test_mount_entry_regex(dummy_mount_list, strdup("(/home)|(/var)"), cflags, 2, strdup("grouped regex pathname match:")); + np_test_mount_entry_regex(dummy_mount_list, strdup("(/homE)|(/Var)"), cflags | REG_ICASE, 2, strdup("grouped regi pathname match:")); np_add_parameter(&paths, "/home/groups"); np_add_parameter(&paths, "/var"); @@ -124,20 +99,20 @@ main (int argc, char **argv) for (p = paths; p; p = p->name_next) { struct mount_entry *temp_me; temp_me = p->best_match; - if (! strcmp(p->name, "/home/groups")) { - ok( temp_me && !strcmp(temp_me->me_mountdir, "/home"), "/home/groups got right best match: /home"); - } else if (! strcmp(p->name, "/var")) { - ok( temp_me && !strcmp(temp_me->me_mountdir, "/var"), "/var got right best match: /var"); - } else if (! strcmp(p->name, "/tmp")) { - ok( temp_me && !strcmp(temp_me->me_mountdir, "/"), "/tmp got right best match: /"); - } else if (! strcmp(p->name, "/home/tonvoon")) { - ok( temp_me && !strcmp(temp_me->me_mountdir, "/home"), "/home/tonvoon got right best match: /home"); - } else if (! strcmp(p->name, "/dev/c2t0d0s0")) { - ok( temp_me && !strcmp(temp_me->me_devname, "/dev/c2t0d0s0"), "/dev/c2t0d0s0 got right best match: /dev/c2t0d0s0"); + if (!strcmp(p->name, "/home/groups")) { + ok(temp_me && !strcmp(temp_me->me_mountdir, "/home"), "/home/groups got right best match: /home"); + } else if (!strcmp(p->name, "/var")) { + ok(temp_me && !strcmp(temp_me->me_mountdir, "/var"), "/var got right best match: /var"); + } else if (!strcmp(p->name, "/tmp")) { + ok(temp_me && !strcmp(temp_me->me_mountdir, "/"), "/tmp got right best match: /"); + } else if (!strcmp(p->name, "/home/tonvoon")) { + ok(temp_me && !strcmp(temp_me->me_mountdir, "/home"), "/home/tonvoon got right best match: /home"); + } else if (!strcmp(p->name, "/dev/c2t0d0s0")) { + ok(temp_me && !strcmp(temp_me->me_devname, "/dev/c2t0d0s0"), "/dev/c2t0d0s0 got right best match: /dev/c2t0d0s0"); } } - paths = NULL; /* Bad boy - should free, but this is a test suite */ + paths = NULL; /* Bad boy - should free, but this is a test suite */ np_add_parameter(&paths, "/home/groups"); np_add_parameter(&paths, "/var"); np_add_parameter(&paths, "/tmp"); @@ -146,31 +121,31 @@ main (int argc, char **argv) np_set_best_match(paths, dummy_mount_list, true); for (p = paths; p; p = p->name_next) { - if (! strcmp(p->name, "/home/groups")) { - ok( ! p->best_match , "/home/groups correctly not found"); - } else if (! strcmp(p->name, "/var")) { - ok( p->best_match, "/var found"); - } else if (! strcmp(p->name, "/tmp")) { - ok(! p->best_match, "/tmp correctly not found"); - } else if (! strcmp(p->name, "/home/tonvoon")) { - ok(! p->best_match, "/home/tonvoon not found"); - } else if (! strcmp(p->name, "/home")) { - ok( p->best_match, "/home found"); + if (!strcmp(p->name, "/home/groups")) { + ok(!p->best_match, "/home/groups correctly not found"); + } else if (!strcmp(p->name, "/var")) { + ok(p->best_match, "/var found"); + } else if (!strcmp(p->name, "/tmp")) { + ok(!p->best_match, "/tmp correctly not found"); + } else if (!strcmp(p->name, "/home/tonvoon")) { + ok(!p->best_match, "/home/tonvoon not found"); + } else if (!strcmp(p->name, "/home")) { + ok(p->best_match, "/home found"); } } /* test deleting first element in paths */ paths = np_del_parameter(paths, NULL); for (p = paths; p; p = p->name_next) { - if (! strcmp(p->name, "/home/groups")) + if (!strcmp(p->name, "/home/groups")) found = 1; } ok(found == 0, "first element successfully deleted"); found = 0; - p=paths; + p = paths; while (p) { - if (! strcmp(p->name, "/tmp")) + if (!strcmp(p->name, "/tmp")) p = np_del_parameter(p, prev); else { prev = p; @@ -179,7 +154,7 @@ main (int argc, char **argv) } for (p = paths; p; p = p->name_next) { - if (! strcmp(p->name, "/tmp")) + if (!strcmp(p->name, "/tmp")) found = 1; if (p->name_next) prev = p; @@ -190,7 +165,7 @@ main (int argc, char **argv) p = np_del_parameter(last, prev); for (p = paths; p; p = p->name_next) { - if (! strcmp(p->name, "/home")) + if (!strcmp(p->name, "/home")) found = 1; last = p; count++; @@ -198,27 +173,20 @@ main (int argc, char **argv) ok(found == 0, "last (/home) element successfully deleted"); ok(count == 2, "two elements remaining"); - return exit_status(); } - -void -np_test_mount_entry_regex (struct mount_entry *dummy_mount_list, char *regstr, int cflags, int expect, char *desc) -{ +void np_test_mount_entry_regex(struct mount_entry *dummy_mount_list, char *regstr, int cflags, int expect, char *desc) { int matches = 0; regex_t re; struct mount_entry *me; - if (regcomp(&re,regstr, cflags) == 0) { - for (me = dummy_mount_list; me; me= me->me_next) { - if(np_regex_match_mount_entry(me,&re)) + if (regcomp(&re, regstr, cflags) == 0) { + for (me = dummy_mount_list; me; me = me->me_next) { + if (np_regex_match_mount_entry(me, &re)) matches++; } - ok( matches == expect, - "%s '%s' matched %i/3 entries. ok: %i/3", - desc, regstr, expect, matches); + ok(matches == expect, "%s '%s' matched %i/3 entries. ok: %i/3", desc, regstr, expect, matches); } else - ok ( false, "regex '%s' not compilable", regstr); + ok(false, "regex '%s' not compilable", regstr); } - diff --git a/lib/tests/test_ini1.c b/lib/tests/test_ini1.c index 6843bac..711fef9 100644 --- a/lib/tests/test_ini1.c +++ b/lib/tests/test_ini1.c @@ -1,20 +1,20 @@ /***************************************************************************** -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -* -* -*****************************************************************************/ + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * + *****************************************************************************/ #include "common.h" #include "utils_base.h" @@ -29,81 +29,86 @@ void my_free(char *string) { } } -char* -list2str(np_arg_list *optlst) -{ - char *optstr=NULL; +char *list2str(np_arg_list *optlst) { + char *optstr = NULL; np_arg_list *optltmp; /* Put everything as a space-separated string */ asprintf(&optstr, ""); while (optlst) { asprintf(&optstr, "%s%s ", optstr, optlst->arg); - optltmp=optlst; - optlst=optlst->next; + optltmp = optlst; + optlst = optlst->next; free(optltmp); } /* Strip last whitespace */ - if (strlen(optstr)>1) optstr[strlen(optstr)-1]='\0'; + if (strlen(optstr) > 1) + optstr[strlen(optstr) - 1] = '\0'; return optstr; } -int -main (int argc, char **argv) -{ - char *optstr=NULL; +int main(int argc, char **argv) { + char *optstr = NULL; plan_tests(12); - optstr=list2str(np_get_defaults("section@./config-tiny.ini", "check_disk")); - ok( !strcmp(optstr, "--one=two --Foo=Bar --this=Your Mother! --blank"), "config-tiny.ini's section as expected"); + optstr = list2str(np_get_defaults("section@./config-tiny.ini", "check_disk")); + ok(!strcmp(optstr, "--one=two --Foo=Bar --this=Your Mother! --blank"), "config-tiny.ini's section as expected"); my_free(optstr); - optstr=list2str(np_get_defaults("@./config-tiny.ini", "section")); - ok( !strcmp(optstr, "--one=two --Foo=Bar --this=Your Mother! --blank"), "Used default section name, without specific"); + optstr = list2str(np_get_defaults("@./config-tiny.ini", "section")); + ok(!strcmp(optstr, "--one=two --Foo=Bar --this=Your Mother! --blank"), "Used default section name, without specific"); my_free(optstr); - optstr=list2str(np_get_defaults("Section Two@./config-tiny.ini", "check_disk")); - ok( !strcmp(optstr, "--something else=blah --remove=whitespace"), "config-tiny.ini's Section Two as expected"); + optstr = list2str(np_get_defaults("Section Two@./config-tiny.ini", "check_disk")); + ok(!strcmp(optstr, "--something else=blah --remove=whitespace"), "config-tiny.ini's Section Two as expected"); my_free(optstr); - optstr=list2str(np_get_defaults("/path/to/file.txt@./config-tiny.ini", "check_disk")); - ok( !strcmp(optstr, "--this=that"), "config-tiny.ini's filename as section name"); + optstr = list2str(np_get_defaults("/path/to/file.txt@./config-tiny.ini", "check_disk")); + ok(!strcmp(optstr, "--this=that"), "config-tiny.ini's filename as section name"); my_free(optstr); - optstr=list2str(np_get_defaults("section2@./config-tiny.ini", "check_disk")); - ok( !strcmp(optstr, "--this=that"), "config-tiny.ini's section2 with whitespace before section name"); + optstr = list2str(np_get_defaults("section2@./config-tiny.ini", "check_disk")); + ok(!strcmp(optstr, "--this=that"), "config-tiny.ini's section2 with whitespace before section name"); my_free(optstr); - optstr=list2str(np_get_defaults("section3@./config-tiny.ini", "check_disk")); - ok( !strcmp(optstr, "--this=that"), "config-tiny.ini's section3 with whitespace after section name"); + optstr = list2str(np_get_defaults("section3@./config-tiny.ini", "check_disk")); + ok(!strcmp(optstr, "--this=that"), "config-tiny.ini's section3 with whitespace after section name"); my_free(optstr); - optstr=list2str(np_get_defaults("check_mysql@./plugin.ini", "check_disk")); - ok( !strcmp(optstr, "--username=operator --password=secret"), "plugin.ini's check_mysql as expected"); + optstr = list2str(np_get_defaults("check_mysql@./plugin.ini", "check_disk")); + ok(!strcmp(optstr, "--username=operator --password=secret"), "plugin.ini's check_mysql as expected"); my_free(optstr); - optstr=list2str(np_get_defaults("check_mysql2@./plugin.ini", "check_disk")); - ok( !strcmp(optstr, "-u=admin -p=secret"), "plugin.ini's check_mysql2 as expected"); + optstr = list2str(np_get_defaults("check_mysql2@./plugin.ini", "check_disk")); + ok(!strcmp(optstr, "-u=admin -p=secret"), "plugin.ini's check_mysql2 as expected"); my_free(optstr); - optstr=list2str(np_get_defaults("check space_and_flags@./plugin.ini", "check_disk")); - ok( !strcmp(optstr, "--foo=bar -a -b --bar"), "plugin.ini space in stanza and flag arguments"); + optstr = list2str(np_get_defaults("check space_and_flags@./plugin.ini", "check_disk")); + ok(!strcmp(optstr, "--foo=bar -a -b --bar"), "plugin.ini space in stanza and flag arguments"); my_free(optstr); - optstr=list2str(np_get_defaults("Section Two@./config-dos.ini", "check_disk")); - ok( !strcmp(optstr, "--something else=blah --remove=whitespace"), "config-dos.ini's Section Two as expected"); + optstr = list2str(np_get_defaults("Section Two@./config-dos.ini", "check_disk")); + ok(!strcmp(optstr, "--something else=blah --remove=whitespace"), "config-dos.ini's Section Two as expected"); my_free(optstr); - optstr=list2str(np_get_defaults("section_twice@./plugin.ini", "check_disk")); - ok( !strcmp(optstr, "--foo=bar --bar=foo"), "plugin.ini's section_twice defined twice in the file"); + optstr = list2str(np_get_defaults("section_twice@./plugin.ini", "check_disk")); + ok(!strcmp(optstr, "--foo=bar --bar=foo"), "plugin.ini's section_twice defined twice in the file"); my_free(optstr); - optstr=list2str(np_get_defaults("tcp_long_lines@plugins.ini", "check_tcp")); - ok( !strcmp(optstr, "--escape --send=Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda --expect=Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda --jail"), "Long options"); + optstr = list2str(np_get_defaults("tcp_long_lines@plugins.ini", "check_tcp")); + ok(!strcmp(optstr, + "--escape --send=Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda " + "yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo " + "bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ " + "yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda --expect=Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ " + "yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda " + "yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo " + "bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ " + "yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda --jail"), + "Long options"); my_free(optstr); return exit_status(); } - diff --git a/lib/tests/test_ini3.c b/lib/tests/test_ini3.c index 8a2a041..2186e4b 100644 --- a/lib/tests/test_ini3.c +++ b/lib/tests/test_ini3.c @@ -1,26 +1,24 @@ /***************************************************************************** -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -* -* -*****************************************************************************/ + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * + *****************************************************************************/ #include "parse_ini.h" -int -main (int argc, char **argv) -{ +int main(int argc, char **argv) { /* * This is for testing arguments expected to die. @@ -30,4 +28,3 @@ main (int argc, char **argv) return 0; } - diff --git a/lib/tests/test_opts1.c b/lib/tests/test_opts1.c index 077c5b6..e32115c 100644 --- a/lib/tests/test_opts1.c +++ b/lib/tests/test_opts1.c @@ -1,19 +1,19 @@ /***************************************************************************** -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -* -*****************************************************************************/ + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + *****************************************************************************/ #include "common.h" #include "utils_base.h" @@ -40,23 +40,24 @@ void my_free(int *argc, char **newargv, char **argv) { #else void my_free(int *argc, char **newargv, char **argv) { /* Free stuff (and print while we're at it) */ - int i, freeflag=1; - printf (" Arg(%i): ", *argc+1); - printf ("'%s' ", newargv[0]); - for (i=1; i<*argc; i++) { - printf ("'%s' ", newargv[i]); + int i, freeflag = 1; + printf(" Arg(%i): ", *argc + 1); + printf("'%s' ", newargv[0]); + for (i = 1; i < *argc; i++) { + printf("'%s' ", newargv[i]); /* Stop freeing when we get to the start of the original array */ if (freeflag) { if (newargv[i] == argv[1]) - freeflag=0; + freeflag = 0; else free(newargv[i]); } } - printf ("\n"); + printf("\n"); /* Free only if it's a different array */ - if (newargv != argv) free(newargv); - *argc=0; + if (newargv != argv) + free(newargv); + *argc = 0; } #endif @@ -67,9 +68,10 @@ int array_diff(int i1, char **a1, int i2, char **a2) { printf(" Argument count doesn't match!\n"); return 0; } - for (i=0; i<=i1; i++) { - if (a1[i]==NULL && a2[i]==NULL) continue; - if (a1[i]==NULL || a2[i]==NULL) { + for (i = 0; i <= i1; i++) { + if (a1[i] == NULL && a2[i] == NULL) + continue; + if (a1[i] == NULL || a2[i] == NULL) { printf(" Argument # %i null in one array!\n", i); return 0; } @@ -81,59 +83,56 @@ int array_diff(int i1, char **a1, int i2, char **a2) { return 1; } -int -main (int argc, char **argv) -{ - char **argv_new=NULL; +int main(int argc, char **argv) { + char **argv_new = NULL; int i, argc_test; plan_tests(5); { - char *argv_test[] = {"prog_name", (char *) NULL}; - argc_test=1; - char *argv_known[] = {"prog_name", (char *) NULL}; - argv_new=np_extra_opts(&argc_test, argv_test, "check_disk"); + char *argv_test[] = {"prog_name", (char *)NULL}; + argc_test = 1; + char *argv_known[] = {"prog_name", (char *)NULL}; + argv_new = np_extra_opts(&argc_test, argv_test, "check_disk"); ok(array_diff(argc_test, argv_new, 1, argv_known), "No opts, returns correct argv/argc"); my_free(&argc_test, argv_new, argv_test); } { - char *argv_test[] = {"prog_name", "arg1", "--arg2=val1", "--arg3", "val2", (char *) NULL}; - argc_test=5; - char *argv_known[] = {"prog_name", "arg1", "--arg2=val1", "--arg3", "val2", (char *) NULL}; - argv_new=np_extra_opts(&argc_test, argv_test, "check_disk"); + char *argv_test[] = {"prog_name", "arg1", "--arg2=val1", "--arg3", "val2", (char *)NULL}; + argc_test = 5; + char *argv_known[] = {"prog_name", "arg1", "--arg2=val1", "--arg3", "val2", (char *)NULL}; + argv_new = np_extra_opts(&argc_test, argv_test, "check_disk"); ok(array_diff(argc_test, argv_new, 5, argv_known), "No extra opts, verbatim copy of argv"); my_free(&argc_test, argv_new, argv_test); } { - char *argv_test[] = {"prog_name", "--extra-opts=@./config-opts.ini", (char *) NULL}; - argc_test=2; - char *argv_known[] = {"prog_name", "--foo=Bar", "--this=Your Mother!", "--blank", (char *) NULL}; - argv_new=np_extra_opts(&argc_test, argv_test, "check_disk"); + char *argv_test[] = {"prog_name", "--extra-opts=@./config-opts.ini", (char *)NULL}; + argc_test = 2; + char *argv_known[] = {"prog_name", "--foo=Bar", "--this=Your Mother!", "--blank", (char *)NULL}; + argv_new = np_extra_opts(&argc_test, argv_test, "check_disk"); ok(array_diff(argc_test, argv_new, 4, argv_known), "Only extra opts using default section"); my_free(&argc_test, argv_new, argv_test); } { - char *argv_test[] = {"prog_name", "--extra-opts=sect1@./config-opts.ini", "--extra-opts", "sect2@./config-opts.ini", (char *) NULL}; - argc_test=4; - char *argv_known[] = {"prog_name", "--one=two", "--something else=oops", "--this=that", (char *) NULL}; - argv_new=np_extra_opts(&argc_test, argv_test, "check_disk"); + char *argv_test[] = {"prog_name", "--extra-opts=sect1@./config-opts.ini", "--extra-opts", "sect2@./config-opts.ini", (char *)NULL}; + argc_test = 4; + char *argv_known[] = {"prog_name", "--one=two", "--something else=oops", "--this=that", (char *)NULL}; + argv_new = np_extra_opts(&argc_test, argv_test, "check_disk"); ok(array_diff(argc_test, argv_new, 4, argv_known), "Only extra opts specified twice"); my_free(&argc_test, argv_new, argv_test); } { - char *argv_test[] = {"prog_name", "--arg1=val1", "--extra-opts=@./config-opts.ini", "--extra-opts", "sect1@./config-opts.ini", "--arg2", (char *) NULL}; - argc_test=6; - char *argv_known[] = {"prog_name", "--foo=Bar", "--this=Your Mother!", "--blank", "--one=two", "--arg1=val1", "--arg2", (char *) NULL}; - argv_new=np_extra_opts(&argc_test, argv_test, "check_disk"); + char *argv_test[] = {"prog_name", "--arg1=val1", "--extra-opts=@./config-opts.ini", "--extra-opts", "sect1@./config-opts.ini", "--arg2", (char *)NULL}; + argc_test = 6; + char *argv_known[] = {"prog_name", "--foo=Bar", "--this=Your Mother!", "--blank", "--one=two", "--arg1=val1", "--arg2", (char *)NULL}; + argv_new = np_extra_opts(&argc_test, argv_test, "check_disk"); ok(array_diff(argc_test, argv_new, 7, argv_known), "twice extra opts using two sections"); my_free(&argc_test, argv_new, argv_test); } return exit_status(); } - diff --git a/lib/tests/test_opts2.c b/lib/tests/test_opts2.c index 780220e..95c6505 100644 --- a/lib/tests/test_opts2.c +++ b/lib/tests/test_opts2.c @@ -1,19 +1,19 @@ /***************************************************************************** -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -* -*****************************************************************************/ + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + *****************************************************************************/ #include "common.h" #include "utils_base.h" @@ -23,23 +23,24 @@ void my_free(int *argc, char **newargv, char **argv) { /* Free stuff (and print while we're at it) */ - int i, freeflag=1; - printf (" Arg(%i): ", *argc+1); - printf ("'%s' ", newargv[0]); - for (i=1; i<*argc; i++) { - printf ("'%s' ", newargv[i]); + int i, freeflag = 1; + printf(" Arg(%i): ", *argc + 1); + printf("'%s' ", newargv[0]); + for (i = 1; i < *argc; i++) { + printf("'%s' ", newargv[i]); /* Stop freeing when we get to the start of the original array */ if (freeflag) { if (newargv[i] == argv[1]) - freeflag=0; + freeflag = 0; else free(newargv[i]); } } - printf ("\n"); + printf("\n"); /* Free only if it's a different array */ - if (newargv != argv) free(newargv); - *argc=0; + if (newargv != argv) + free(newargv); + *argc = 0; } int array_diff(int i1, char **a1, int i2, char **a2) { @@ -49,9 +50,10 @@ int array_diff(int i1, char **a1, int i2, char **a2) { printf(" Argument count doesn't match!\n"); return 0; } - for (i=0; i<=i1; i++) { - if (a1[i]==NULL && a2[i]==NULL) continue; - if (a1[i]==NULL || a2[i]==NULL) { + for (i = 0; i <= i1; i++) { + if (a1[i] == NULL && a2[i] == NULL) + continue; + if (a1[i] == NULL || a2[i] == NULL) { printf(" Argument # %i null in one array!\n", i); return 0; } @@ -63,59 +65,69 @@ int array_diff(int i1, char **a1, int i2, char **a2) { return 1; } -int -main (int argc, char **argv) -{ - char **argv_new=NULL; +int main(int argc, char **argv) { + char **argv_new = NULL; int i, argc_test; plan_tests(5); { - char *argv_test[] = {"prog_name", "arg1", "--extra-opts", "--arg3", "val2", (char *) NULL}; - argc_test=5; - char *argv_known[] = {"prog_name", "--foo=bar", "arg1", "--arg3", "val2", (char *) NULL}; - argv_new=np_extra_opts(&argc_test, argv_test, "check_disk"); + char *argv_test[] = {"prog_name", "arg1", "--extra-opts", "--arg3", "val2", (char *)NULL}; + argc_test = 5; + char *argv_known[] = {"prog_name", "--foo=bar", "arg1", "--arg3", "val2", (char *)NULL}; + argv_new = np_extra_opts(&argc_test, argv_test, "check_disk"); ok(array_diff(argc_test, argv_new, 5, argv_known), "Default section 1"); my_free(&argc_test, argv_new, argv_test); } { - char *argv_test[] = {"prog_name", "--extra-opts", (char *) NULL}; - argc_test=2; - char *argv_known[] = {"prog_name", "--foo=bar", (char *) NULL}; - argv_new=np_extra_opts(&argc_test, argv_test, "check_disk"); + char *argv_test[] = {"prog_name", "--extra-opts", (char *)NULL}; + argc_test = 2; + char *argv_known[] = {"prog_name", "--foo=bar", (char *)NULL}; + argv_new = np_extra_opts(&argc_test, argv_test, "check_disk"); ok(array_diff(argc_test, argv_new, 2, argv_known), "Default section 2"); my_free(&argc_test, argv_new, argv_test); } { - char *argv_test[] = {"prog_name", "arg1", "--extra-opts=section1", "--arg3", "val2", (char *) NULL}; - argc_test=5; - char *argv_known[] = {"prog_name", "--foobar=baz", "arg1", "--arg3", "val2", (char *) NULL}; - argv_new=np_extra_opts(&argc_test, argv_test, "check_disk"); + char *argv_test[] = {"prog_name", "arg1", "--extra-opts=section1", "--arg3", "val2", (char *)NULL}; + argc_test = 5; + char *argv_known[] = {"prog_name", "--foobar=baz", "arg1", "--arg3", "val2", (char *)NULL}; + argv_new = np_extra_opts(&argc_test, argv_test, "check_disk"); ok(array_diff(argc_test, argv_new, 5, argv_known), "Default section 3"); my_free(&argc_test, argv_new, argv_test); } { - char *argv_test[] = {"prog_name", "arg1", "--extra-opts", "-arg3", "val2", (char *) NULL}; - argc_test=5; - char *argv_known[] = {"prog_name", "--foo=bar", "arg1", "-arg3", "val2", (char *) NULL}; - argv_new=np_extra_opts(&argc_test, argv_test, "check_disk"); + char *argv_test[] = {"prog_name", "arg1", "--extra-opts", "-arg3", "val2", (char *)NULL}; + argc_test = 5; + char *argv_known[] = {"prog_name", "--foo=bar", "arg1", "-arg3", "val2", (char *)NULL}; + argv_new = np_extra_opts(&argc_test, argv_test, "check_disk"); ok(array_diff(argc_test, argv_new, 5, argv_known), "Default section 4"); my_free(&argc_test, argv_new, argv_test); } { - char *argv_test[] = {"check_tcp", "--extra-opts", "--extra-opts=tcp_long_lines", (char *) NULL}; - argc_test=3; - char *argv_known[] = {"check_tcp", "--timeout=10", "--escape", "--send=Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda", "--expect=Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda", "--jail", (char *) NULL}; - argv_new=np_extra_opts(&argc_test, argv_test, "check_tcp"); + char *argv_test[] = {"check_tcp", "--extra-opts", "--extra-opts=tcp_long_lines", (char *)NULL}; + argc_test = 3; + char *argv_known[] = {"check_tcp", + "--timeout=10", + "--escape", + "--send=Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda " + "yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ " + "yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar " + "BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda", + "--expect=Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda " + "yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ " + "yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar " + "BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo " + "bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda", + "--jail", + (char *)NULL}; + argv_new = np_extra_opts(&argc_test, argv_test, "check_tcp"); ok(array_diff(argc_test, argv_new, 6, argv_known), "Long lines test"); my_free(&argc_test, argv_new, argv_test); } return exit_status(); } - diff --git a/lib/tests/test_opts3.c b/lib/tests/test_opts3.c index b64270d..cecea43 100644 --- a/lib/tests/test_opts3.c +++ b/lib/tests/test_opts3.c @@ -1,31 +1,28 @@ /***************************************************************************** -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -* -*****************************************************************************/ + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + *****************************************************************************/ #include "extra_opts.h" -int -main (int argc, char **argv) -{ +int main(int argc, char **argv) { /* * This is for testing arguments expected to die. */ - argv=np_extra_opts(&argc, argv, argv[0]); + argv = np_extra_opts(&argc, argv, argv[0]); return 0; } - diff --git a/lib/tests/test_tcp.c b/lib/tests/test_tcp.c index 1954b0f..b09c005 100644 --- a/lib/tests/test_tcp.c +++ b/lib/tests/test_tcp.c @@ -1,58 +1,46 @@ /***************************************************************************** -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -* -* -*****************************************************************************/ + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * + *****************************************************************************/ #include "common.h" #include "utils_tcp.h" #include "tap.h" -int -main(void) -{ +int main(void) { char **server_expect; int server_expect_count = 3; plan_tests(9); - server_expect = malloc(sizeof(char*) * server_expect_count); + server_expect = malloc(sizeof(char *) * server_expect_count); server_expect[0] = strdup("AA"); server_expect[1] = strdup("bb"); server_expect[2] = strdup("CC"); - ok(np_expect_match("AA bb CC XX", server_expect, server_expect_count, NP_MATCH_EXACT) == NP_MATCH_SUCCESS, - "Test matching any string at the beginning (first expect string)"); - ok(np_expect_match("bb AA CC XX", server_expect, server_expect_count, NP_MATCH_EXACT) == NP_MATCH_SUCCESS, - "Test matching any string at the beginning (second expect string)"); - ok(np_expect_match("b", server_expect, server_expect_count, NP_MATCH_EXACT) == NP_MATCH_RETRY, - "Test matching any string at the beginning (substring match)"); - ok(np_expect_match("XX bb AA CC XX", server_expect, server_expect_count, NP_MATCH_EXACT) == NP_MATCH_FAILURE, - "Test with strings not matching at the beginning"); - ok(np_expect_match("XX CC XX", server_expect, server_expect_count, NP_MATCH_EXACT) == NP_MATCH_FAILURE, - "Test matching any string"); - ok(np_expect_match("XX", server_expect, server_expect_count, 0) == NP_MATCH_RETRY, - "Test not matching any string"); - ok(np_expect_match("XX AA bb CC XX", server_expect, server_expect_count, NP_MATCH_ALL) == NP_MATCH_SUCCESS, - "Test matching all strings"); - ok(np_expect_match("XX bb CC XX", server_expect, server_expect_count, NP_MATCH_ALL) == NP_MATCH_RETRY, - "Test not matching all strings"); - ok(np_expect_match("XX XX", server_expect, server_expect_count, NP_MATCH_ALL) == NP_MATCH_RETRY, - "Test not matching any string (testing all)"); - + ok(np_expect_match("AA bb CC XX", server_expect, server_expect_count, NP_MATCH_EXACT) == NP_MATCH_SUCCESS, "Test matching any string at the beginning (first expect string)"); + ok(np_expect_match("bb AA CC XX", server_expect, server_expect_count, NP_MATCH_EXACT) == NP_MATCH_SUCCESS, "Test matching any string at the beginning (second expect string)"); + ok(np_expect_match("b", server_expect, server_expect_count, NP_MATCH_EXACT) == NP_MATCH_RETRY, "Test matching any string at the beginning (substring match)"); + ok(np_expect_match("XX bb AA CC XX", server_expect, server_expect_count, NP_MATCH_EXACT) == NP_MATCH_FAILURE, "Test with strings not matching at the beginning"); + ok(np_expect_match("XX CC XX", server_expect, server_expect_count, NP_MATCH_EXACT) == NP_MATCH_FAILURE, "Test matching any string"); + ok(np_expect_match("XX", server_expect, server_expect_count, 0) == NP_MATCH_RETRY, "Test not matching any string"); + ok(np_expect_match("XX AA bb CC XX", server_expect, server_expect_count, NP_MATCH_ALL) == NP_MATCH_SUCCESS, "Test matching all strings"); + ok(np_expect_match("XX bb CC XX", server_expect, server_expect_count, NP_MATCH_ALL) == NP_MATCH_RETRY, "Test not matching all strings"); + ok(np_expect_match("XX XX", server_expect, server_expect_count, NP_MATCH_ALL) == NP_MATCH_RETRY, "Test not matching any string (testing all)"); return exit_status(); } diff --git a/lib/tests/test_utils.c b/lib/tests/test_utils.c index 01afacd..901e0cc 100644 --- a/lib/tests/test_utils.c +++ b/lib/tests/test_utils.c @@ -1,20 +1,20 @@ /***************************************************************************** -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -* -* -*****************************************************************************/ + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * + *****************************************************************************/ #include "common.h" #include "utils_base.h" @@ -27,331 +27,323 @@ #include "utils_base.c" -int -main (int argc, char **argv) -{ +int main(int argc, char **argv) { char state_path[1024]; - range *range; - double temp; + range *range; + double temp; thresholds *thresholds = NULL; - int i, rc; - char *temp_string; + int i, rc; + char *temp_string; state_key *temp_state_key = NULL; state_data *temp_state_data; - time_t current_time; + time_t current_time; plan_tests(185); - ok( this_monitoring_plugin==NULL, "monitoring_plugin not initialised"); + ok(this_monitoring_plugin == NULL, "monitoring_plugin not initialised"); - np_init( "check_test", argc, argv ); + np_init("check_test", argc, argv); - ok( this_monitoring_plugin!=NULL, "monitoring_plugin now initialised"); - ok( !strcmp(this_monitoring_plugin->plugin_name, "check_test"), "plugin name initialised" ); + ok(this_monitoring_plugin != NULL, "monitoring_plugin now initialised"); + ok(!strcmp(this_monitoring_plugin->plugin_name, "check_test"), "plugin name initialised"); - ok( this_monitoring_plugin->argc==argc, "Argc set" ); - ok( this_monitoring_plugin->argv==argv, "Argv set" ); + ok(this_monitoring_plugin->argc == argc, "Argc set"); + ok(this_monitoring_plugin->argv == argv, "Argv set"); - np_set_args(0,0); + np_set_args(0, 0); - ok( this_monitoring_plugin->argc==0, "argc changed" ); - ok( this_monitoring_plugin->argv==0, "argv changed" ); + ok(this_monitoring_plugin->argc == 0, "argc changed"); + ok(this_monitoring_plugin->argv == 0, "argv changed"); np_set_args(argc, argv); range = parse_range_string("6"); - ok( range != NULL, "'6' is valid range"); - ok( range->start == 0, "Start correct"); - ok( range->start_infinity == false, "Not using negative infinity"); - ok( range->end == 6, "End correct"); - ok( range->end_infinity == false, "Not using infinity"); + ok(range != NULL, "'6' is valid range"); + ok(range->start == 0, "Start correct"); + ok(range->start_infinity == false, "Not using negative infinity"); + ok(range->end == 6, "End correct"); + ok(range->end_infinity == false, "Not using infinity"); free(range); range = parse_range_string("1:12%%"); - ok( range != NULL, "'1:12%%' is valid - percentages are ignored"); - ok( range->start == 1, "Start correct"); - ok( range->start_infinity == false, "Not using negative infinity"); - ok( range->end == 12, "End correct"); - ok( range->end_infinity == false, "Not using infinity"); + ok(range != NULL, "'1:12%%' is valid - percentages are ignored"); + ok(range->start == 1, "Start correct"); + ok(range->start_infinity == false, "Not using negative infinity"); + ok(range->end == 12, "End correct"); + ok(range->end_infinity == false, "Not using infinity"); free(range); range = parse_range_string("-7:23"); - ok( range != NULL, "'-7:23' is valid range"); - ok( range->start == -7, "Start correct"); - ok( range->start_infinity == false, "Not using negative infinity"); - ok( range->end == 23, "End correct"); - ok( range->end_infinity == false, "Not using infinity"); + ok(range != NULL, "'-7:23' is valid range"); + ok(range->start == -7, "Start correct"); + ok(range->start_infinity == false, "Not using negative infinity"); + ok(range->end == 23, "End correct"); + ok(range->end_infinity == false, "Not using infinity"); free(range); range = parse_range_string(":5.75"); - ok( range != NULL, "':5.75' is valid range"); - ok( range->start == 0, "Start correct"); - ok( range->start_infinity == false, "Not using negative infinity"); - ok( range->end == 5.75, "End correct"); - ok( range->end_infinity == false, "Not using infinity"); + ok(range != NULL, "':5.75' is valid range"); + ok(range->start == 0, "Start correct"); + ok(range->start_infinity == false, "Not using negative infinity"); + ok(range->end == 5.75, "End correct"); + ok(range->end_infinity == false, "Not using infinity"); free(range); range = parse_range_string("~:-95.99"); - ok( range != NULL, "~:-95.99' is valid range"); - ok( range->start_infinity == true, "Using negative infinity"); - ok( range->end == -95.99, "End correct (with rounding errors)"); - ok( range->end_infinity == false, "Not using infinity"); + ok(range != NULL, "~:-95.99' is valid range"); + ok(range->start_infinity == true, "Using negative infinity"); + ok(range->end == -95.99, "End correct (with rounding errors)"); + ok(range->end_infinity == false, "Not using infinity"); free(range); range = parse_range_string("12345678901234567890:"); - temp = atof("12345678901234567890"); /* Can't just use this because number too large */ - ok( range != NULL, "'12345678901234567890:' is valid range"); - ok( range->start == temp, "Start correct"); - ok( range->start_infinity == false, "Not using negative infinity"); - ok( range->end_infinity == true, "Using infinity"); + temp = atof("12345678901234567890"); /* Can't just use this because number too large */ + ok(range != NULL, "'12345678901234567890:' is valid range"); + ok(range->start == temp, "Start correct"); + ok(range->start_infinity == false, "Not using negative infinity"); + ok(range->end_infinity == true, "Using infinity"); /* Cannot do a "-1" on temp, as it appears to be same value */ - ok( check_range(temp/1.1, range) == true, "12345678901234567890/1.1 - alert"); - ok( check_range(temp, range) == false, "12345678901234567890 - no alert"); - ok( check_range(temp*2, range) == false, "12345678901234567890*2 - no alert"); + ok(check_range(temp / 1.1, range) == true, "12345678901234567890/1.1 - alert"); + ok(check_range(temp, range) == false, "12345678901234567890 - no alert"); + ok(check_range(temp * 2, range) == false, "12345678901234567890*2 - no alert"); free(range); range = parse_range_string("~:0"); - ok( range != NULL, "'~:0' is valid range"); - ok( range->start_infinity == true, "Using negative infinity"); - ok( range->end == 0, "End correct"); - ok( range->end_infinity == false, "Not using infinity"); - ok( range->alert_on == OUTSIDE, "Will alert on outside of this range"); - ok( check_range(0.5, range) == true, "0.5 - alert"); - ok( check_range(-10, range) == false, "-10 - no alert"); - ok( check_range(0, range) == false, "0 - no alert"); + ok(range != NULL, "'~:0' is valid range"); + ok(range->start_infinity == true, "Using negative infinity"); + ok(range->end == 0, "End correct"); + ok(range->end_infinity == false, "Not using infinity"); + ok(range->alert_on == OUTSIDE, "Will alert on outside of this range"); + ok(check_range(0.5, range) == true, "0.5 - alert"); + ok(check_range(-10, range) == false, "-10 - no alert"); + ok(check_range(0, range) == false, "0 - no alert"); free(range); range = parse_range_string("@0:657.8210567"); - ok( range != 0, "@0:657.8210567' is a valid range"); - ok( range->start == 0, "Start correct"); - ok( range->start_infinity == false, "Not using negative infinity"); - ok( range->end == 657.8210567, "End correct"); - ok( range->end_infinity == false, "Not using infinity"); - ok( range->alert_on == INSIDE, "Will alert on inside of this range" ); - ok( check_range(32.88, range) == true, "32.88 - alert"); - ok( check_range(-2, range) == false, "-2 - no alert"); - ok( check_range(657.8210567, range) == true, "657.8210567 - alert"); - ok( check_range(0, range) == true, "0 - alert"); + ok(range != 0, "@0:657.8210567' is a valid range"); + ok(range->start == 0, "Start correct"); + ok(range->start_infinity == false, "Not using negative infinity"); + ok(range->end == 657.8210567, "End correct"); + ok(range->end_infinity == false, "Not using infinity"); + ok(range->alert_on == INSIDE, "Will alert on inside of this range"); + ok(check_range(32.88, range) == true, "32.88 - alert"); + ok(check_range(-2, range) == false, "-2 - no alert"); + ok(check_range(657.8210567, range) == true, "657.8210567 - alert"); + ok(check_range(0, range) == true, "0 - alert"); free(range); range = parse_range_string("@1:1"); - ok( range != NULL, "'@1:1' is a valid range"); - ok( range->start == 1, "Start correct"); - ok( range->start_infinity == false, "Not using negative infinity"); - ok( range->end == 1, "End correct"); - ok( range->end_infinity == false, "Not using infinity"); - ok( range->alert_on == INSIDE, "Will alert on inside of this range" ); - ok( check_range(0.5, range) == false, "0.5 - no alert"); - ok( check_range(1, range) == true, "1 - alert"); - ok( check_range(5.2, range) == false, "5.2 - no alert"); + ok(range != NULL, "'@1:1' is a valid range"); + ok(range->start == 1, "Start correct"); + ok(range->start_infinity == false, "Not using negative infinity"); + ok(range->end == 1, "End correct"); + ok(range->end_infinity == false, "Not using infinity"); + ok(range->alert_on == INSIDE, "Will alert on inside of this range"); + ok(check_range(0.5, range) == false, "0.5 - no alert"); + ok(check_range(1, range) == true, "1 - alert"); + ok(check_range(5.2, range) == false, "5.2 - no alert"); free(range); range = parse_range_string("1:1"); - ok( range != NULL, "'1:1' is a valid range"); - ok( range->start == 1, "Start correct"); - ok( range->start_infinity == false, "Not using negative infinity"); - ok( range->end == 1, "End correct"); - ok( range->end_infinity == false, "Not using infinity"); - ok( check_range(0.5, range) == true, "0.5 - alert"); - ok( check_range(1, range) == false, "1 - no alert"); - ok( check_range(5.2, range) == true, "5.2 - alert"); + ok(range != NULL, "'1:1' is a valid range"); + ok(range->start == 1, "Start correct"); + ok(range->start_infinity == false, "Not using negative infinity"); + ok(range->end == 1, "End correct"); + ok(range->end_infinity == false, "Not using infinity"); + ok(check_range(0.5, range) == true, "0.5 - alert"); + ok(check_range(1, range) == false, "1 - no alert"); + ok(check_range(5.2, range) == true, "5.2 - alert"); free(range); range = parse_range_string("2:1"); - ok( range == NULL, "'2:1' rejected"); + ok(range == NULL, "'2:1' rejected"); rc = _set_thresholds(&thresholds, NULL, NULL); - ok( rc == 0, "Thresholds (NULL, NULL) set"); - ok( thresholds->warning == NULL, "Warning not set"); - ok( thresholds->critical == NULL, "Critical not set"); + ok(rc == 0, "Thresholds (NULL, NULL) set"); + ok(thresholds->warning == NULL, "Warning not set"); + ok(thresholds->critical == NULL, "Critical not set"); rc = _set_thresholds(&thresholds, NULL, "80"); - ok( rc == 0, "Thresholds (NULL, '80') set"); - ok( thresholds->warning == NULL, "Warning not set"); - ok( thresholds->critical->end == 80, "Critical set correctly"); + ok(rc == 0, "Thresholds (NULL, '80') set"); + ok(thresholds->warning == NULL, "Warning not set"); + ok(thresholds->critical->end == 80, "Critical set correctly"); rc = _set_thresholds(&thresholds, "5:33", NULL); - ok( rc == 0, "Thresholds ('5:33', NULL) set"); - ok( thresholds->warning->start == 5, "Warning start set"); - ok( thresholds->warning->end == 33, "Warning end set"); - ok( thresholds->critical == NULL, "Critical not set"); + ok(rc == 0, "Thresholds ('5:33', NULL) set"); + ok(thresholds->warning->start == 5, "Warning start set"); + ok(thresholds->warning->end == 33, "Warning end set"); + ok(thresholds->critical == NULL, "Critical not set"); rc = _set_thresholds(&thresholds, "30", "60"); - ok( rc == 0, "Thresholds ('30', '60') set"); - ok( thresholds->warning->end == 30, "Warning set correctly"); - ok( thresholds->critical->end == 60, "Critical set correctly"); - ok( get_status(15.3, thresholds) == STATE_OK, "15.3 - ok"); - ok( get_status(30.0001, thresholds) == STATE_WARNING, "30.0001 - warning"); - ok( get_status(69, thresholds) == STATE_CRITICAL, "69 - critical"); + ok(rc == 0, "Thresholds ('30', '60') set"); + ok(thresholds->warning->end == 30, "Warning set correctly"); + ok(thresholds->critical->end == 60, "Critical set correctly"); + ok(get_status(15.3, thresholds) == STATE_OK, "15.3 - ok"); + ok(get_status(30.0001, thresholds) == STATE_WARNING, "30.0001 - warning"); + ok(get_status(69, thresholds) == STATE_CRITICAL, "69 - critical"); rc = _set_thresholds(&thresholds, "-10:-2", "-30:20"); - ok( rc == 0, "Thresholds ('-30:20', '-10:-2') set"); - ok( thresholds->warning->start == -10, "Warning start set correctly"); - ok( thresholds->warning->end == -2, "Warning end set correctly"); - ok( thresholds->critical->start == -30, "Critical start set correctly"); - ok( thresholds->critical->end == 20, "Critical end set correctly"); - ok( get_status(-31, thresholds) == STATE_CRITICAL, "-31 - critical"); - ok( get_status(-29, thresholds) == STATE_WARNING, "-29 - warning"); - ok( get_status(-11, thresholds) == STATE_WARNING, "-11 - warning"); - ok( get_status(-10, thresholds) == STATE_OK, "-10 - ok"); - ok( get_status(-2, thresholds) == STATE_OK, "-2 - ok"); - ok( get_status(-1, thresholds) == STATE_WARNING, "-1 - warning"); - ok( get_status(19, thresholds) == STATE_WARNING, "19 - warning"); - ok( get_status(21, thresholds) == STATE_CRITICAL, "21 - critical"); + ok(rc == 0, "Thresholds ('-30:20', '-10:-2') set"); + ok(thresholds->warning->start == -10, "Warning start set correctly"); + ok(thresholds->warning->end == -2, "Warning end set correctly"); + ok(thresholds->critical->start == -30, "Critical start set correctly"); + ok(thresholds->critical->end == 20, "Critical end set correctly"); + ok(get_status(-31, thresholds) == STATE_CRITICAL, "-31 - critical"); + ok(get_status(-29, thresholds) == STATE_WARNING, "-29 - warning"); + ok(get_status(-11, thresholds) == STATE_WARNING, "-11 - warning"); + ok(get_status(-10, thresholds) == STATE_OK, "-10 - ok"); + ok(get_status(-2, thresholds) == STATE_OK, "-2 - ok"); + ok(get_status(-1, thresholds) == STATE_WARNING, "-1 - warning"); + ok(get_status(19, thresholds) == STATE_WARNING, "19 - warning"); + ok(get_status(21, thresholds) == STATE_CRITICAL, "21 - critical"); char *test; test = np_escaped_string("bob\\n"); - ok( strcmp(test, "bob\n") == 0, "bob\\n ok"); + ok(strcmp(test, "bob\n") == 0, "bob\\n ok"); free(test); test = np_escaped_string("rhuba\\rb"); - ok( strcmp(test, "rhuba\rb") == 0, "rhuba\\rb okay"); + ok(strcmp(test, "rhuba\rb") == 0, "rhuba\\rb okay"); free(test); test = np_escaped_string("ba\\nge\\r"); - ok( strcmp(test, "ba\nge\r") == 0, "ba\\nge\\r okay"); + ok(strcmp(test, "ba\nge\r") == 0, "ba\\nge\\r okay"); free(test); test = np_escaped_string("\\rabbi\\t"); - ok( strcmp(test, "\rabbi\t") == 0, "\\rabbi\\t okay"); + ok(strcmp(test, "\rabbi\t") == 0, "\\rabbi\\t okay"); free(test); test = np_escaped_string("and\\\\or"); - ok( strcmp(test, "and\\or") == 0, "and\\\\or okay"); + ok(strcmp(test, "and\\or") == 0, "and\\\\or okay"); free(test); test = np_escaped_string("bo\\gus"); - ok( strcmp(test, "bogus") == 0, "bo\\gus okay"); + ok(strcmp(test, "bogus") == 0, "bo\\gus okay"); free(test); test = np_escaped_string("everything"); - ok( strcmp(test, "everything") == 0, "everything okay"); + ok(strcmp(test, "everything") == 0, "everything okay"); /* np_extract_ntpvar tests (23) */ - test=np_extract_ntpvar("foo=bar, bar=foo, foobar=barfoo\n", "foo"); + test = np_extract_ntpvar("foo=bar, bar=foo, foobar=barfoo\n", "foo"); ok(test && !strcmp(test, "bar"), "1st test as expected"); free(test); - test=np_extract_ntpvar("foo=bar,bar=foo,foobar=barfoo\n", "bar"); + test = np_extract_ntpvar("foo=bar,bar=foo,foobar=barfoo\n", "bar"); ok(test && !strcmp(test, "foo"), "2nd test as expected"); free(test); - test=np_extract_ntpvar("foo=bar, bar=foo, foobar=barfoo\n", "foobar"); + test = np_extract_ntpvar("foo=bar, bar=foo, foobar=barfoo\n", "foobar"); ok(test && !strcmp(test, "barfoo"), "3rd test as expected"); free(test); - test=np_extract_ntpvar("foo=bar\n", "foo"); + test = np_extract_ntpvar("foo=bar\n", "foo"); ok(test && !strcmp(test, "bar"), "Single test as expected"); free(test); - test=np_extract_ntpvar("foo=bar, bar=foo, foobar=barfooi\n", "abcd"); + test = np_extract_ntpvar("foo=bar, bar=foo, foobar=barfooi\n", "abcd"); ok(!test, "Key not found 1"); - test=np_extract_ntpvar("foo=bar\n", "abcd"); + test = np_extract_ntpvar("foo=bar\n", "abcd"); ok(!test, "Key not found 2"); - test=np_extract_ntpvar("foo=bar=foobar", "foo"); + test = np_extract_ntpvar("foo=bar=foobar", "foo"); ok(test && !strcmp(test, "bar=foobar"), "Strange string 1"); free(test); - test=np_extract_ntpvar("foo", "foo"); + test = np_extract_ntpvar("foo", "foo"); ok(!test, "Malformed string 1"); - test=np_extract_ntpvar("foo,", "foo"); + test = np_extract_ntpvar("foo,", "foo"); ok(!test, "Malformed string 2"); - test=np_extract_ntpvar("foo=", "foo"); + test = np_extract_ntpvar("foo=", "foo"); ok(!test, "Malformed string 3"); - test=np_extract_ntpvar("foo=,bar=foo", "foo"); + test = np_extract_ntpvar("foo=,bar=foo", "foo"); ok(!test, "Malformed string 4"); - test=np_extract_ntpvar(",foo", "foo"); + test = np_extract_ntpvar(",foo", "foo"); ok(!test, "Malformed string 5"); - test=np_extract_ntpvar("=foo", "foo"); + test = np_extract_ntpvar("=foo", "foo"); ok(!test, "Malformed string 6"); - test=np_extract_ntpvar("=foo,", "foo"); + test = np_extract_ntpvar("=foo,", "foo"); ok(!test, "Malformed string 7"); - test=np_extract_ntpvar(",,,", "foo"); + test = np_extract_ntpvar(",,,", "foo"); ok(!test, "Malformed string 8"); - test=np_extract_ntpvar("===", "foo"); + test = np_extract_ntpvar("===", "foo"); ok(!test, "Malformed string 9"); - test=np_extract_ntpvar(",=,=,", "foo"); + test = np_extract_ntpvar(",=,=,", "foo"); ok(!test, "Malformed string 10"); - test=np_extract_ntpvar("=,=,=", "foo"); + test = np_extract_ntpvar("=,=,=", "foo"); ok(!test, "Malformed string 11"); - test=np_extract_ntpvar(" foo=bar ,\n bar=foo\n , foobar=barfoo \n ", "foo"); + test = np_extract_ntpvar(" foo=bar ,\n bar=foo\n , foobar=barfoo \n ", "foo"); ok(test && !strcmp(test, "bar"), "Random spaces and newlines 1"); free(test); - test=np_extract_ntpvar(" foo=bar ,\n bar=foo\n , foobar=barfoo \n ", "bar"); + test = np_extract_ntpvar(" foo=bar ,\n bar=foo\n , foobar=barfoo \n ", "bar"); ok(test && !strcmp(test, "foo"), "Random spaces and newlines 2"); free(test); - test=np_extract_ntpvar(" foo=bar ,\n bar=foo\n , foobar=barfoo \n ", "foobar"); + test = np_extract_ntpvar(" foo=bar ,\n bar=foo\n , foobar=barfoo \n ", "foobar"); ok(test && !strcmp(test, "barfoo"), "Random spaces and newlines 3"); free(test); - test=np_extract_ntpvar(" foo=bar ,\n bar\n \n= \n foo\n , foobar=barfoo \n ", "bar"); + test = np_extract_ntpvar(" foo=bar ,\n bar\n \n= \n foo\n , foobar=barfoo \n ", "bar"); ok(test && !strcmp(test, "foo"), "Random spaces and newlines 4"); free(test); - test=np_extract_ntpvar("", "foo"); + test = np_extract_ntpvar("", "foo"); ok(!test, "Empty string return NULL"); - /* This is the result of running ./test_utils */ - temp_string = (char *) _np_state_generate_key(); - ok(!strcmp(temp_string, "e2d17f995fd4c020411b85e3e3d0ff7306d4147e"), "Got hash with exe and no parameters" ) || - diag( "You are probably running in wrong directory. Must run as ./test_utils" ); - + temp_string = (char *)_np_state_generate_key(); + ok(!strcmp(temp_string, "e2d17f995fd4c020411b85e3e3d0ff7306d4147e"), "Got hash with exe and no parameters") || + diag("You are probably running in wrong directory. Must run as ./test_utils"); - this_monitoring_plugin->argc=4; + this_monitoring_plugin->argc = 4; this_monitoring_plugin->argv[0] = "./test_utils"; this_monitoring_plugin->argv[1] = "here"; this_monitoring_plugin->argv[2] = "--and"; this_monitoring_plugin->argv[3] = "now"; - temp_string = (char *) _np_state_generate_key(); - ok(!strcmp(temp_string, "bd72da9f78ff1419fad921ea5e43ce56508aef6c"), "Got based on expected argv" ); + temp_string = (char *)_np_state_generate_key(); + ok(!strcmp(temp_string, "bd72da9f78ff1419fad921ea5e43ce56508aef6c"), "Got based on expected argv"); unsetenv("MP_STATE_PATH"); - temp_string = (char *) _np_state_calculate_location_prefix(); - ok(!strcmp(temp_string, NP_STATE_DIR_PREFIX), "Got default directory" ); + temp_string = (char *)_np_state_calculate_location_prefix(); + ok(!strcmp(temp_string, NP_STATE_DIR_PREFIX), "Got default directory"); setenv("MP_STATE_PATH", "", 1); - temp_string = (char *) _np_state_calculate_location_prefix(); - ok(!strcmp(temp_string, NP_STATE_DIR_PREFIX), "Got default directory even with empty string" ); + temp_string = (char *)_np_state_calculate_location_prefix(); + ok(!strcmp(temp_string, NP_STATE_DIR_PREFIX), "Got default directory even with empty string"); setenv("MP_STATE_PATH", "/usr/local/nagios/var", 1); - temp_string = (char *) _np_state_calculate_location_prefix(); - ok(!strcmp(temp_string, "/usr/local/nagios/var"), "Got default directory" ); - + temp_string = (char *)_np_state_calculate_location_prefix(); + ok(!strcmp(temp_string, "/usr/local/nagios/var"), "Got default directory"); + ok(temp_state_key == NULL, "temp_state_key initially empty"); - ok(temp_state_key==NULL, "temp_state_key initially empty"); - - this_monitoring_plugin->argc=1; + this_monitoring_plugin->argc = 1; this_monitoring_plugin->argv[0] = "./test_utils"; np_enable_state(NULL, 51); temp_state_key = this_monitoring_plugin->state; - ok( !strcmp(temp_state_key->plugin_name, "check_test"), "Got plugin name" ); - ok( !strcmp(temp_state_key->name, "e2d17f995fd4c020411b85e3e3d0ff7306d4147e"), "Got generated filename" ); - + ok(!strcmp(temp_state_key->plugin_name, "check_test"), "Got plugin name"); + ok(!strcmp(temp_state_key->name, "e2d17f995fd4c020411b85e3e3d0ff7306d4147e"), "Got generated filename"); np_enable_state("allowedchars_in_keyname", 77); temp_state_key = this_monitoring_plugin->state; sprintf(state_path, "/usr/local/nagios/var/%lu/check_test/allowedchars_in_keyname", (unsigned long)geteuid()); - ok( !strcmp(temp_state_key->plugin_name, "check_test"), "Got plugin name" ); - ok( !strcmp(temp_state_key->name, "allowedchars_in_keyname"), "Got key name with valid chars" ); - ok( !strcmp(temp_state_key->_filename, state_path), "Got internal filename" ); - + ok(!strcmp(temp_state_key->plugin_name, "check_test"), "Got plugin name"); + ok(!strcmp(temp_state_key->name, "allowedchars_in_keyname"), "Got key name with valid chars"); + ok(!strcmp(temp_state_key->_filename, state_path), "Got internal filename"); /* Don't do this test just yet. Will die */ /* @@ -363,73 +355,64 @@ main (int argc, char **argv) np_enable_state("funnykeyname", 54); temp_state_key = this_monitoring_plugin->state; sprintf(state_path, "/usr/local/nagios/var/%lu/check_test/funnykeyname", (unsigned long)geteuid()); - ok( !strcmp(temp_state_key->plugin_name, "check_test"), "Got plugin name" ); - ok( !strcmp(temp_state_key->name, "funnykeyname"), "Got key name" ); + ok(!strcmp(temp_state_key->plugin_name, "check_test"), "Got plugin name"); + ok(!strcmp(temp_state_key->name, "funnykeyname"), "Got key name"); - - - ok( !strcmp(temp_state_key->_filename, state_path), "Got internal filename" ); - ok( temp_state_key->data_version==54, "Version set" ); + ok(!strcmp(temp_state_key->_filename, state_path), "Got internal filename"); + ok(temp_state_key->data_version == 54, "Version set"); temp_state_data = np_state_read(); - ok( temp_state_data==NULL, "Got no state data as file does not exist" ); - + ok(temp_state_data == NULL, "Got no state data as file does not exist"); -/* - temp_fp = fopen("var/statefile", "r"); - if (temp_fp==NULL) - printf("Error opening. errno=%d\n", errno); - printf("temp_fp=%s\n", temp_fp); - ok( _np_state_read_file(temp_fp) == true, "Can read state file" ); - fclose(temp_fp); -*/ + /* + temp_fp = fopen("var/statefile", "r"); + if (temp_fp==NULL) + printf("Error opening. errno=%d\n", errno); + printf("temp_fp=%s\n", temp_fp); + ok( _np_state_read_file(temp_fp) == true, "Can read state file" ); + fclose(temp_fp); + */ - temp_state_key->_filename="var/statefile"; + temp_state_key->_filename = "var/statefile"; temp_state_data = np_state_read(); - ok( this_monitoring_plugin->state->state_data!=NULL, "Got state data now" ) || diag("Are you running in right directory? Will get coredump next if not"); - ok( this_monitoring_plugin->state->state_data->time==1234567890, "Got time" ); - ok( !strcmp((char *)this_monitoring_plugin->state->state_data->data, "String to read"), "Data as expected" ); + ok(this_monitoring_plugin->state->state_data != NULL, "Got state data now") || diag("Are you running in right directory? Will get coredump next if not"); + ok(this_monitoring_plugin->state->state_data->time == 1234567890, "Got time"); + ok(!strcmp((char *)this_monitoring_plugin->state->state_data->data, "String to read"), "Data as expected"); - temp_state_key->data_version=53; + temp_state_key->data_version = 53; temp_state_data = np_state_read(); - ok( temp_state_data==NULL, "Older data version gives NULL" ); - temp_state_key->data_version=54; + ok(temp_state_data == NULL, "Older data version gives NULL"); + temp_state_key->data_version = 54; - temp_state_key->_filename="var/nonexistent"; + temp_state_key->_filename = "var/nonexistent"; temp_state_data = np_state_read(); - ok( temp_state_data==NULL, "Missing file gives NULL" ); - ok( this_monitoring_plugin->state->state_data==NULL, "No state information" ); + ok(temp_state_data == NULL, "Missing file gives NULL"); + ok(this_monitoring_plugin->state->state_data == NULL, "No state information"); - temp_state_key->_filename="var/oldformat"; + temp_state_key->_filename = "var/oldformat"; temp_state_data = np_state_read(); - ok( temp_state_data==NULL, "Old file format gives NULL" ); + ok(temp_state_data == NULL, "Old file format gives NULL"); - temp_state_key->_filename="var/baddate"; + temp_state_key->_filename = "var/baddate"; temp_state_data = np_state_read(); - ok( temp_state_data==NULL, "Bad date gives NULL" ); + ok(temp_state_data == NULL, "Bad date gives NULL"); - temp_state_key->_filename="var/missingdataline"; + temp_state_key->_filename = "var/missingdataline"; temp_state_data = np_state_read(); - ok( temp_state_data==NULL, "Missing data line gives NULL" ); - - - + ok(temp_state_data == NULL, "Missing data line gives NULL"); unlink("var/generated"); - temp_state_key->_filename="var/generated"; - current_time=1234567890; + temp_state_key->_filename = "var/generated"; + current_time = 1234567890; np_state_write_string(current_time, "String to read"); - ok(system("cmp var/generated var/statefile")==0, "Generated file same as expected"); - - - + ok(system("cmp var/generated var/statefile") == 0, "Generated file same as expected"); unlink("var/generated_directory/statefile"); unlink("var/generated_directory"); - temp_state_key->_filename="var/generated_directory/statefile"; - current_time=1234567890; + temp_state_key->_filename = "var/generated_directory/statefile"; + current_time = 1234567890; np_state_write_string(current_time, "String to read"); - ok(system("cmp var/generated_directory/statefile var/statefile")==0, "Have created directory"); + ok(system("cmp var/generated_directory/statefile var/statefile") == 0, "Have created directory"); /* This test to check cannot write to dir - can't automate yet */ /* @@ -438,15 +421,13 @@ main (int argc, char **argv) np_state_write_string(current_time, "String to read"); */ - - temp_state_key->_filename="var/generated"; + temp_state_key->_filename = "var/generated"; time(¤t_time); np_state_write_string(0, "String to read"); temp_state_data = np_state_read(); /* Check time is set to current_time */ - ok(system("cmp var/generated var/statefile > /dev/null")!=0, "Generated file should be different this time"); - ok(this_monitoring_plugin->state->state_data->time-current_time<=1, "Has time generated from current time"); - + ok(system("cmp var/generated var/statefile > /dev/null") != 0, "Generated file should be different this time"); + ok(this_monitoring_plugin->state->state_data->time - current_time <= 1, "Has time generated from current time"); /* Don't know how to automatically test this. Need to be able to redefine die and catch the error */ /* @@ -454,23 +435,16 @@ main (int argc, char **argv) np_state_write_string(0, "Bad file"); */ - np_cleanup(); - ok(this_monitoring_plugin==NULL, "Free'd this_monitoring_plugin"); + ok(this_monitoring_plugin == NULL, "Free'd this_monitoring_plugin"); ok(mp_suid() == false, "Test aren't suid"); /* base states with random case */ - char *states[] = { - "Ok", - "wArnINg", - "cRiTIcaL", - "UnKNoWN", - NULL - }; - - for (i=0; states[i]!=NULL; i++) { + char *states[] = {"Ok", "wArnINg", "cRiTIcaL", "UnKNoWN", NULL}; + + for (i = 0; states[i] != NULL; i++) { /* out of the random case states, create the lower and upper versions + numeric string one */ char *statelower = strdup(states[i]); char *stateupper = strdup(states[i]); @@ -488,23 +462,23 @@ main (int argc, char **argv) char testname[64] = "Translate state string: "; int tlen = strlen(testname); - strcpy(testname+tlen, states[i]); - ok(i==mp_translate_state(states[i]), testname); + strcpy(testname + tlen, states[i]); + ok(i == mp_translate_state(states[i]), testname); - strcpy(testname+tlen, statelower); - ok(i==mp_translate_state(statelower), testname); + strcpy(testname + tlen, statelower); + ok(i == mp_translate_state(statelower), testname); - strcpy(testname+tlen, stateupper); - ok(i==mp_translate_state(stateupper), testname); + strcpy(testname + tlen, stateupper); + ok(i == mp_translate_state(stateupper), testname); - strcpy(testname+tlen, statenum); - ok(i==mp_translate_state(statenum), testname); + strcpy(testname + tlen, statenum); + ok(i == mp_translate_state(statenum), testname); } - ok(ERROR==mp_translate_state("warningfewgw"), "Translate state string with garbage"); - ok(ERROR==mp_translate_state("00"), "Translate state string: bad numeric string 1"); - ok(ERROR==mp_translate_state("01"), "Translate state string: bad numeric string 2"); - ok(ERROR==mp_translate_state("10"), "Translate state string: bad numeric string 3"); - ok(ERROR==mp_translate_state(""), "Translate state string: empty string"); + ok(ERROR == mp_translate_state("warningfewgw"), "Translate state string with garbage"); + ok(ERROR == mp_translate_state("00"), "Translate state string: bad numeric string 1"); + ok(ERROR == mp_translate_state("01"), "Translate state string: bad numeric string 2"); + ok(ERROR == mp_translate_state("10"), "Translate state string: bad numeric string 3"); + ok(ERROR == mp_translate_state(""), "Translate state string: empty string"); return exit_status(); } diff --git a/lib/utils_base.c b/lib/utils_base.c index f8592f4..cd13583 100644 --- a/lib/utils_base.c +++ b/lib/utils_base.c @@ -1,28 +1,28 @@ /***************************************************************************** -* -* utils_base.c -* -* License: GPL -* Copyright (c) 2006 Monitoring Plugins Development Team -* -* Library of useful functions for plugins -* -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -* -* -*****************************************************************************/ + * + * utils_base.c + * + * License: GPL + * Copyright (c) 2006 Monitoring Plugins Development Team + * + * Library of useful functions for plugins + * + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * + *****************************************************************************/ #include "../plugins/common.h" #include @@ -33,43 +33,47 @@ #include #include -#define np_free(ptr) { if(ptr) { free(ptr); ptr = NULL; } } +#define np_free(ptr) \ + { \ + if (ptr) { \ + free(ptr); \ + ptr = NULL; \ + } \ + } -monitoring_plugin *this_monitoring_plugin=NULL; +monitoring_plugin *this_monitoring_plugin = NULL; int timeout_state = STATE_CRITICAL; unsigned int timeout_interval = DEFAULT_SOCKET_TIMEOUT; bool _np_state_read_file(FILE *); -void np_init( char *plugin_name, int argc, char **argv ) { - if (this_monitoring_plugin==NULL) { +void np_init(char *plugin_name, int argc, char **argv) { + if (this_monitoring_plugin == NULL) { this_monitoring_plugin = calloc(1, sizeof(monitoring_plugin)); - if (this_monitoring_plugin==NULL) { - die(STATE_UNKNOWN, _("Cannot allocate memory: %s"), - strerror(errno)); + if (this_monitoring_plugin == NULL) { + die(STATE_UNKNOWN, _("Cannot allocate memory: %s"), strerror(errno)); } this_monitoring_plugin->plugin_name = strdup(plugin_name); - if (this_monitoring_plugin->plugin_name==NULL) + if (this_monitoring_plugin->plugin_name == NULL) die(STATE_UNKNOWN, _("Cannot execute strdup: %s"), strerror(errno)); this_monitoring_plugin->argc = argc; this_monitoring_plugin->argv = argv; } } -void np_set_args( int argc, char **argv ) { - if (this_monitoring_plugin==NULL) +void np_set_args(int argc, char **argv) { + if (this_monitoring_plugin == NULL) die(STATE_UNKNOWN, _("This requires np_init to be called")); this_monitoring_plugin->argc = argc; this_monitoring_plugin->argv = argv; } - void np_cleanup() { - if (this_monitoring_plugin!=NULL) { - if(this_monitoring_plugin->state!=NULL) { - if(this_monitoring_plugin->state->state_data) { + if (this_monitoring_plugin != NULL) { + if (this_monitoring_plugin->state != NULL) { + if (this_monitoring_plugin->state->state_data) { np_free(this_monitoring_plugin->state->state_data->data); np_free(this_monitoring_plugin->state->state_data); } @@ -79,48 +83,43 @@ void np_cleanup() { np_free(this_monitoring_plugin->plugin_name); np_free(this_monitoring_plugin); } - this_monitoring_plugin=NULL; + this_monitoring_plugin = NULL; } /* Hidden function to get a pointer to this_monitoring_plugin for testing */ -void _get_monitoring_plugin( monitoring_plugin **pointer ){ - *pointer = this_monitoring_plugin; -} +void _get_monitoring_plugin(monitoring_plugin **pointer) { *pointer = this_monitoring_plugin; } -void -die (int result, const char *fmt, ...) -{ - if(fmt!=NULL) { +void die(int result, const char *fmt, ...) { + if (fmt != NULL) { va_list ap; - va_start (ap, fmt); - vprintf (fmt, ap); - va_end (ap); + va_start(ap, fmt); + vprintf(fmt, ap); + va_end(ap); } - if(this_monitoring_plugin!=NULL) { + if (this_monitoring_plugin != NULL) { np_cleanup(); } - exit (result); + exit(result); } -void set_range_start (range *this, double value) { +void set_range_start(range *this, double value) { this->start = value; this->start_infinity = false; } -void set_range_end (range *this, double value) { +void set_range_end(range *this, double value) { this->end = value; this->end_infinity = false; } -range -*parse_range_string (char *str) { +range *parse_range_string(char *str) { range *temp_range; double start; double end; char *end_str; - temp_range = (range *) calloc(1, sizeof(range)); + temp_range = (range *)calloc(1, sizeof(range)); /* Set defaults */ temp_range->start = 0; @@ -140,10 +139,10 @@ range if (str[0] == '~') { temp_range->start_infinity = true; } else { - start = strtod(str, NULL); /* Will stop at the ':' */ + start = strtod(str, NULL); /* Will stop at the ':' */ set_range_start(temp_range, start); } - end_str++; /* Move past the ':' */ + end_str++; /* Move past the ':' */ } else { end_str = str; } @@ -152,9 +151,7 @@ range set_range_end(temp_range, end); } - if (temp_range->start_infinity == true || - temp_range->end_infinity == true || - temp_range->start <= temp_range->end) { + if (temp_range->start_infinity == true || temp_range->end_infinity == true || temp_range->start <= temp_range->end) { return temp_range; } free(temp_range); @@ -162,14 +159,11 @@ range } /* returns 0 if okay, otherwise 1 */ -int -_set_thresholds(thresholds **my_thresholds, char *warn_string, char *critical_string) -{ +int _set_thresholds(thresholds **my_thresholds, char *warn_string, char *critical_string) { thresholds *temp_thresholds = NULL; if ((temp_thresholds = calloc(1, sizeof(thresholds))) == NULL) - die(STATE_UNKNOWN, _("Cannot allocate memory: %s"), - strerror(errno)); + die(STATE_UNKNOWN, _("Cannot allocate memory: %s"), strerror(errno)); temp_thresholds->warning = NULL; temp_thresholds->critical = NULL; @@ -190,9 +184,7 @@ _set_thresholds(thresholds **my_thresholds, char *warn_string, char *critical_st return 0; } -void -set_thresholds(thresholds **my_thresholds, char *warn_string, char *critical_string) -{ +void set_thresholds(thresholds **my_thresholds, char *warn_string, char *critical_string) { switch (_set_thresholds(my_thresholds, warn_string, critical_string)) { case 0: return; @@ -206,7 +198,7 @@ set_thresholds(thresholds **my_thresholds, char *warn_string, char *critical_str void print_thresholds(const char *threshold_name, thresholds *my_threshold) { printf("%s - ", threshold_name); - if (! my_threshold) { + if (!my_threshold) { printf("Threshold not set"); } else { if (my_threshold->warning) { @@ -224,8 +216,7 @@ void print_thresholds(const char *threshold_name, thresholds *my_threshold) { } /* Returns true if alert should be raised based on the range */ -bool check_range(double value, range *my_range) -{ +bool check_range(double value, range *my_range) { bool no = false; bool yes = true; @@ -258,9 +249,7 @@ bool check_range(double value, range *my_range) } /* Returns status */ -int -get_status(double value, thresholds *my_thresholds) -{ +int get_status(double value, thresholds *my_thresholds) { if (my_thresholds->critical != NULL) { if (check_range(value, my_thresholds->critical) == true) { return STATE_CRITICAL; @@ -274,27 +263,27 @@ get_status(double value, thresholds *my_thresholds) return STATE_OK; } -char *np_escaped_string (const char *string) { +char *np_escaped_string(const char *string) { char *data; - int i, j=0; + int i, j = 0; data = strdup(string); - for (i=0; data[i]; i++) { + for (i = 0; data[i]; i++) { if (data[i] == '\\') { - switch(data[++i]) { - case 'n': - data[j++] = '\n'; - break; - case 'r': - data[j++] = '\r'; - break; - case 't': - data[j++] = '\t'; - break; - case '\\': - data[j++] = '\\'; - break; - default: - data[j++] = data[i]; + switch (data[++i]) { + case 'n': + data[j++] = '\n'; + break; + case 'r': + data[j++] = '\r'; + break; + case 't': + data[j++] = '\t'; + break; + case '\\': + data[j++] = '\\'; + break; + default: + data[j++] = data[i]; } } else { data[j++] = data[i]; @@ -313,33 +302,38 @@ int np_check_if_root(void) { return (geteuid() == 0); } * data strings. */ char *np_extract_value(const char *varlist, const char *name, char sep) { - char *tmp=NULL, *value=NULL; + char *tmp = NULL, *value = NULL; int i; while (1) { /* Strip any leading space */ - for (; isspace(varlist[0]); varlist++); + for (; isspace(varlist[0]); varlist++) + ; if (strncmp(name, varlist, strlen(name)) == 0) { varlist += strlen(name); /* strip trailing spaces */ - for (; isspace(varlist[0]); varlist++); + for (; isspace(varlist[0]); varlist++) + ; if (varlist[0] == '=') { /* We matched the key, go past the = sign */ varlist++; /* strip leading spaces */ - for (; isspace(varlist[0]); varlist++); + for (; isspace(varlist[0]); varlist++) + ; if ((tmp = index(varlist, sep))) { /* Value is delimited by a comma */ - if (tmp-varlist == 0) continue; - value = (char *)calloc(1, tmp-varlist+1); - strncpy(value, varlist, tmp-varlist); - value[tmp-varlist] = '\0'; + if (tmp - varlist == 0) + continue; + value = (char *)calloc(1, tmp - varlist + 1); + strncpy(value, varlist, tmp - varlist); + value[tmp - varlist] = '\0'; } else { /* Value is delimited by a \0 */ - if (strlen(varlist) == 0) continue; + if (strlen(varlist) == 0) + continue; value = (char *)calloc(1, strlen(varlist) + 1); strncpy(value, varlist, strlen(varlist)); value[strlen(varlist)] = '\0'; @@ -357,14 +351,14 @@ char *np_extract_value(const char *varlist, const char *name, char sep) { } /* Clean-up trailing spaces/newlines */ - if (value) for (i=strlen(value)-1; isspace(value[i]); i--) value[i] = '\0'; + if (value) + for (i = strlen(value) - 1; isspace(value[i]); i--) + value[i] = '\0'; return value; } -const char * -state_text (int result) -{ +const char *state_text(int result) { switch (result) { case STATE_OK: return "OK"; @@ -383,14 +377,14 @@ state_text (int result) * Read a string representing a state (ok, warning... or numeric: 0, 1) and * return the corresponding STATE_ value or ERROR) */ -int mp_translate_state (char *state_text) { - if (!strcasecmp(state_text,"OK") || !strcmp(state_text,"0")) +int mp_translate_state(char *state_text) { + if (!strcasecmp(state_text, "OK") || !strcmp(state_text, "0")) return STATE_OK; - if (!strcasecmp(state_text,"WARNING") || !strcmp(state_text,"1")) + if (!strcasecmp(state_text, "WARNING") || !strcmp(state_text, "1")) return STATE_WARNING; - if (!strcasecmp(state_text,"CRITICAL") || !strcmp(state_text,"2")) + if (!strcasecmp(state_text, "CRITICAL") || !strcmp(state_text, "2")) return STATE_CRITICAL; - if (!strcasecmp(state_text,"UNKNOWN") || !strcmp(state_text,"3")) + if (!strcasecmp(state_text, "UNKNOWN") || !strcmp(state_text, "3")) return STATE_UNKNOWN; return ERROR; } @@ -404,7 +398,7 @@ char *_np_state_generate_key() { int i; char **argv = this_monitoring_plugin->argv; char keyname[41]; - char *p=NULL; + char *p = NULL; unsigned char result[256]; @@ -418,7 +412,7 @@ char *_np_state_generate_key() { EVP_DigestInit(ctx, EVP_sha256()); - for(i=0; iargc; i++) { + for (i = 0; i < this_monitoring_plugin->argc; i++) { EVP_DigestUpdate(ctx, argv[i], strlen(argv[i])); } @@ -427,28 +421,28 @@ char *_np_state_generate_key() { struct sha256_ctx ctx; - for(i=0; iargc; i++) { + for (i = 0; i < this_monitoring_plugin->argc; i++) { sha256_process_bytes(argv[i], strlen(argv[i]), &ctx); } sha256_finish_ctx(&ctx, result); #endif // FOUNDOPENSSL - for (i=0; i<20; ++i) { - sprintf(&keyname[2*i], "%02x", result[i]); + for (i = 0; i < 20; ++i) { + sprintf(&keyname[2 * i], "%02x", result[i]); } - keyname[40]='\0'; + keyname[40] = '\0'; p = strdup(keyname); - if(p==NULL) { + if (p == NULL) { die(STATE_UNKNOWN, _("Cannot execute strdup: %s"), strerror(errno)); } return p; } void _cleanup_state_data() { - if (this_monitoring_plugin->state->state_data!=NULL) { + if (this_monitoring_plugin->state->state_data != NULL) { np_free(this_monitoring_plugin->state->state_data->data); np_free(this_monitoring_plugin->state->state_data); } @@ -459,18 +453,18 @@ void _cleanup_state_data() { * envvar NAGIOS_PLUGIN_STATE_DIRECTORY * statically compiled shared state directory */ -char* _np_state_calculate_location_prefix(){ +char *_np_state_calculate_location_prefix() { char *env_dir; /* Do not allow passing MP_STATE_PATH in setuid plugins * for security reasons */ if (!mp_suid()) { env_dir = getenv("MP_STATE_PATH"); - if(env_dir && env_dir[0] != '\0') + if (env_dir && env_dir[0] != '\0') return env_dir; /* This is the former ENV, for backward-compatibility */ env_dir = getenv("NAGIOS_PLUGIN_STATE_DIRECTORY"); - if(env_dir && env_dir[0] != '\0') + if (env_dir && env_dir[0] != '\0') return env_dir; } @@ -486,46 +480,42 @@ void np_enable_state(char *keyname, int expected_data_version) { state_key *this_state = NULL; char *temp_filename = NULL; char *temp_keyname = NULL; - char *p=NULL; + char *p = NULL; int ret; - if(this_monitoring_plugin==NULL) + if (this_monitoring_plugin == NULL) die(STATE_UNKNOWN, _("This requires np_init to be called")); - this_state = (state_key *) calloc(1, sizeof(state_key)); - if(this_state==NULL) - die(STATE_UNKNOWN, _("Cannot allocate memory: %s"), - strerror(errno)); + this_state = (state_key *)calloc(1, sizeof(state_key)); + if (this_state == NULL) + die(STATE_UNKNOWN, _("Cannot allocate memory: %s"), strerror(errno)); - if(keyname==NULL) { + if (keyname == NULL) { temp_keyname = _np_state_generate_key(); } else { temp_keyname = strdup(keyname); - if(temp_keyname==NULL) + if (temp_keyname == NULL) die(STATE_UNKNOWN, _("Cannot execute strdup: %s"), strerror(errno)); } /* Die if invalid characters used for keyname */ p = temp_keyname; - while(*p!='\0') { - if(! (isalnum(*p) || *p == '_')) { + while (*p != '\0') { + if (!(isalnum(*p) || *p == '_')) { die(STATE_UNKNOWN, _("Invalid character for keyname - only alphanumerics or '_'")); } p++; } - this_state->name=temp_keyname; - this_state->plugin_name=this_monitoring_plugin->plugin_name; - this_state->data_version=expected_data_version; - this_state->state_data=NULL; + this_state->name = temp_keyname; + this_state->plugin_name = this_monitoring_plugin->plugin_name; + this_state->data_version = expected_data_version; + this_state->state_data = NULL; /* Calculate filename */ - ret = asprintf(&temp_filename, "%s/%lu/%s/%s", - _np_state_calculate_location_prefix(), (unsigned long)geteuid(), - this_monitoring_plugin->plugin_name, this_state->name); + ret = asprintf(&temp_filename, "%s/%lu/%s/%s", _np_state_calculate_location_prefix(), (unsigned long)geteuid(), this_monitoring_plugin->plugin_name, this_state->name); if (ret < 0) - die(STATE_UNKNOWN, _("Cannot allocate memory: %s"), - strerror(errno)); + die(STATE_UNKNOWN, _("Cannot allocate memory: %s"), strerror(errno)); - this_state->_filename=temp_filename; + this_state->_filename = temp_filename; this_monitoring_plugin->state = this_state; } @@ -538,23 +528,22 @@ void np_enable_state(char *keyname, int expected_data_version) { * if exceptional error. */ state_data *np_state_read() { - state_data *this_state_data=NULL; + state_data *this_state_data = NULL; FILE *statefile; bool rc = false; - if(this_monitoring_plugin==NULL) + if (this_monitoring_plugin == NULL) die(STATE_UNKNOWN, _("This requires np_init to be called")); /* Open file. If this fails, no previous state found */ - statefile = fopen( this_monitoring_plugin->state->_filename, "r" ); - if(statefile!=NULL) { + statefile = fopen(this_monitoring_plugin->state->_filename, "r"); + if (statefile != NULL) { - this_state_data = (state_data *) calloc(1, sizeof(state_data)); - if(this_state_data==NULL) - die(STATE_UNKNOWN, _("Cannot allocate memory: %s"), - strerror(errno)); + this_state_data = (state_data *)calloc(1, sizeof(state_data)); + if (this_state_data == NULL) + die(STATE_UNKNOWN, _("Cannot allocate memory: %s"), strerror(errno)); - this_state_data->data=NULL; + this_state_data->data = NULL; this_monitoring_plugin->state->state_data = this_state_data; rc = _np_state_read_file(statefile); @@ -562,7 +551,7 @@ state_data *np_state_read() { fclose(statefile); } - if(!rc) { + if (!rc) { _cleanup_state_data(); } @@ -577,60 +566,59 @@ bool _np_state_read_file(FILE *f) { size_t pos; char *line; int i; - int failure=0; + int failure = 0; time_t current_time, data_time; - enum { STATE_FILE_VERSION, STATE_DATA_VERSION, STATE_DATA_TIME, STATE_DATA_TEXT, STATE_DATA_END } expected=STATE_FILE_VERSION; + enum { STATE_FILE_VERSION, STATE_DATA_VERSION, STATE_DATA_TIME, STATE_DATA_TEXT, STATE_DATA_END } expected = STATE_FILE_VERSION; time(¤t_time); /* Note: This introduces a limit of 1024 bytes in the string data */ - line = (char *) calloc(1, 1024); - if(line==NULL) - die(STATE_UNKNOWN, _("Cannot allocate memory: %s"), - strerror(errno)); - - while(!failure && (fgets(line,1024,f))!=NULL){ - pos=strlen(line); - if(line[pos-1]=='\n') { - line[pos-1]='\0'; + line = (char *)calloc(1, 1024); + if (line == NULL) + die(STATE_UNKNOWN, _("Cannot allocate memory: %s"), strerror(errno)); + + while (!failure && (fgets(line, 1024, f)) != NULL) { + pos = strlen(line); + if (line[pos - 1] == '\n') { + line[pos - 1] = '\0'; } - if(line[0] == '#') continue; + if (line[0] == '#') + continue; - switch(expected) { - case STATE_FILE_VERSION: - i=atoi(line); - if(i!=NP_STATE_FORMAT_VERSION) - failure++; - else - expected=STATE_DATA_VERSION; - break; - case STATE_DATA_VERSION: - i=atoi(line); - if(i != this_monitoring_plugin->state->data_version) - failure++; - else - expected=STATE_DATA_TIME; - break; - case STATE_DATA_TIME: - /* If time > now, error */ - data_time=strtoul(line,NULL,10); - if(data_time > current_time) - failure++; - else { - this_monitoring_plugin->state->state_data->time = data_time; - expected=STATE_DATA_TEXT; - } - break; - case STATE_DATA_TEXT: - this_monitoring_plugin->state->state_data->data = strdup(line); - if(this_monitoring_plugin->state->state_data->data==NULL) - die(STATE_UNKNOWN, _("Cannot execute strdup: %s"), strerror(errno)); - expected=STATE_DATA_END; - status=true; - break; - case STATE_DATA_END: - ; + switch (expected) { + case STATE_FILE_VERSION: + i = atoi(line); + if (i != NP_STATE_FORMAT_VERSION) + failure++; + else + expected = STATE_DATA_VERSION; + break; + case STATE_DATA_VERSION: + i = atoi(line); + if (i != this_monitoring_plugin->state->data_version) + failure++; + else + expected = STATE_DATA_TIME; + break; + case STATE_DATA_TIME: + /* If time > now, error */ + data_time = strtoul(line, NULL, 10); + if (data_time > current_time) + failure++; + else { + this_monitoring_plugin->state->state_data->time = data_time; + expected = STATE_DATA_TEXT; + } + break; + case STATE_DATA_TEXT: + this_monitoring_plugin->state->state_data->data = strdup(line); + if (this_monitoring_plugin->state->state_data->data == NULL) + die(STATE_UNKNOWN, _("Cannot execute strdup: %s"), strerror(errno)); + expected = STATE_DATA_END; + status = true; + break; + case STATE_DATA_END:; } } @@ -647,77 +635,75 @@ bool _np_state_read_file(FILE *f) { */ void np_state_write_string(time_t data_time, char *data_string) { FILE *fp; - char *temp_file=NULL; - int fd=0, result=0; + char *temp_file = NULL; + int fd = 0, result = 0; time_t current_time; - char *directories=NULL; - char *p=NULL; + char *directories = NULL; + char *p = NULL; - if(data_time==0) + if (data_time == 0) time(¤t_time); else - current_time=data_time; + current_time = data_time; /* If file doesn't currently exist, create directories */ - if(access(this_monitoring_plugin->state->_filename,F_OK)!=0) { + if (access(this_monitoring_plugin->state->_filename, F_OK) != 0) { result = asprintf(&directories, "%s", this_monitoring_plugin->state->_filename); - if(result < 0) - die(STATE_UNKNOWN, _("Cannot allocate memory: %s"), - strerror(errno)); - - for(p=directories+1; *p; p++) { - if(*p=='/') { - *p='\0'; - if((access(directories,F_OK)!=0) && (mkdir(directories, S_IRWXU)!=0)) { + if (result < 0) + die(STATE_UNKNOWN, _("Cannot allocate memory: %s"), strerror(errno)); + + for (p = directories + 1; *p; p++) { + if (*p == '/') { + *p = '\0'; + if ((access(directories, F_OK) != 0) && (mkdir(directories, S_IRWXU) != 0)) { /* Can't free this! Otherwise error message is wrong! */ /* np_free(directories); */ die(STATE_UNKNOWN, _("Cannot create directory: %s"), directories); } - *p='/'; + *p = '/'; } } np_free(directories); } - result = asprintf(&temp_file,"%s.XXXXXX",this_monitoring_plugin->state->_filename); - if(result < 0) - die(STATE_UNKNOWN, _("Cannot allocate memory: %s"), - strerror(errno)); + result = asprintf(&temp_file, "%s.XXXXXX", this_monitoring_plugin->state->_filename); + if (result < 0) + die(STATE_UNKNOWN, _("Cannot allocate memory: %s"), strerror(errno)); - if((fd=mkstemp(temp_file))==-1) { + if ((fd = mkstemp(temp_file)) == -1) { np_free(temp_file); die(STATE_UNKNOWN, _("Cannot create temporary filename")); } - fp=(FILE *)fdopen(fd,"w"); - if(fp==NULL) { + fp = (FILE *)fdopen(fd, "w"); + if (fp == NULL) { close(fd); unlink(temp_file); np_free(temp_file); die(STATE_UNKNOWN, _("Unable to open temporary state file")); } - fprintf(fp,"# NP State file\n"); - fprintf(fp,"%d\n",NP_STATE_FORMAT_VERSION); - fprintf(fp,"%d\n",this_monitoring_plugin->state->data_version); - fprintf(fp,"%lu\n",current_time); - fprintf(fp,"%s\n",data_string); + fprintf(fp, "# NP State file\n"); + fprintf(fp, "%d\n", NP_STATE_FORMAT_VERSION); + fprintf(fp, "%d\n", this_monitoring_plugin->state->data_version); + fprintf(fp, "%lu\n", current_time); + fprintf(fp, "%s\n", data_string); fchmod(fd, S_IRUSR | S_IWUSR | S_IRGRP); fflush(fp); - result=fclose(fp); + result = fclose(fp); fsync(fd); - if(result!=0) { + if (result != 0) { unlink(temp_file); np_free(temp_file); die(STATE_UNKNOWN, _("Error writing temp file")); } - if(rename(temp_file, this_monitoring_plugin->state->_filename)!=0) { + if (rename(temp_file, this_monitoring_plugin->state->_filename) != 0) { unlink(temp_file); np_free(temp_file); die(STATE_UNKNOWN, _("Cannot rename state temp file")); diff --git a/lib/utils_base.h b/lib/utils_base.h index 9d4dffe..a209cb6 100644 --- a/lib/utils_base.h +++ b/lib/utils_base.h @@ -3,7 +3,7 @@ /* Header file for Monitoring Plugins utils_base.c */ #ifndef USE_OPENSSL -# include "sha256.h" +# include "sha256.h" #endif /* This file holds header information for thresholds - use this in preference to @@ -20,44 +20,43 @@ #define INSIDE 1 typedef struct range_struct { - double start; + double start; bool start_infinity; - double end; - int end_infinity; - int alert_on; /* OUTSIDE (default) or INSIDE */ - char* text; /* original unparsed text input */ - } range; + double end; + int end_infinity; + int alert_on; /* OUTSIDE (default) or INSIDE */ + char *text; /* original unparsed text input */ +} range; typedef struct thresholds_struct { - range *warning; - range *critical; - } thresholds; + range *warning; + range *critical; +} thresholds; #define NP_STATE_FORMAT_VERSION 1 typedef struct state_data_struct { - time_t time; - void *data; - int length; /* Of binary data */ - } state_data; - + time_t time; + void *data; + int length; /* Of binary data */ +} state_data; typedef struct state_key_struct { - char *name; - char *plugin_name; - int data_version; - char *_filename; + char *name; + char *plugin_name; + int data_version; + char *_filename; state_data *state_data; - } state_key; +} state_key; typedef struct np_struct { - char *plugin_name; + char *plugin_name; state_key *state; - int argc; - char **argv; - } monitoring_plugin; + int argc; + char **argv; +} monitoring_plugin; -range *parse_range_string (char *); +range *parse_range_string(char *); int _set_thresholds(thresholds **, char *, char *); void set_thresholds(thresholds **, char *, char *); void print_thresholds(const char *, thresholds *); @@ -71,13 +70,13 @@ extern unsigned int timeout_interval; /* All possible characters in a threshold range */ #define NP_THRESHOLDS_CHARS "-0123456789.:@~" -char *np_escaped_string (const char *); +char *np_escaped_string(const char *); -void die (int, const char *, ...) __attribute__((noreturn,format(printf, 2, 3))); +void die(int, const char *, ...) __attribute__((noreturn, format(printf, 2, 3))); /* Return codes for _set_thresholds */ #define NP_RANGE_UNPARSEABLE 1 -#define NP_WARN_WITHIN_CRIT 2 +#define NP_WARN_WITHIN_CRIT 2 /* a simple check to see if we're running as root. * returns zero on failure, nonzero on success */ @@ -93,7 +92,7 @@ int np_check_if_root(void); * This function can be used to parse NTP control packet data and performance * data strings. */ -char *np_extract_value(const char*, const char*, char); +char *np_extract_value(const char *, const char *, char); /* * Same as np_extract_value with separator suitable for NTP control packet @@ -105,7 +104,7 @@ char *np_extract_value(const char*, const char*, char); * Read a string representing a state (ok, warning... or numeric: 0, 1) and * return the corresponding NP_STATE or ERROR) */ -int mp_translate_state (char *); +int mp_translate_state(char *); void np_enable_state(char *, int); state_data *np_state_read(); @@ -114,6 +113,6 @@ void np_state_write_string(time_t, char *); void np_init(char *, int argc, char **argv); void np_set_args(int argc, char **argv); void np_cleanup(); -const char *state_text (int); +const char *state_text(int); #endif /* _UTILS_BASE_ */ diff --git a/lib/utils_cmd.c b/lib/utils_cmd.c index 7957ec1..25d5678 100644 --- a/lib/utils_cmd.c +++ b/lib/utils_cmd.c @@ -1,40 +1,40 @@ /***************************************************************************** -* -* Monitoring run command utilities -* -* License: GPL -* Copyright (c) 2005-2006 Monitoring Plugins Development Team -* -* Description : -* -* A simple interface to executing programs from other programs, using an -* optimized and safe popen()-like implementation. It is considered safe -* in that no shell needs to be spawned and the environment passed to the -* execve()'d program is essentially empty. -* -* The code in this file is a derivative of popen.c which in turn was taken -* from "Advanced Programming for the Unix Environment" by W. Richard Stevens. -* -* Care has been taken to make sure the functions are async-safe. The one -* function which isn't is cmd_init() which it doesn't make sense to -* call twice anyway, so the api as a whole should be considered async-safe. -* -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -* -* -*****************************************************************************/ + * + * Monitoring run command utilities + * + * License: GPL + * Copyright (c) 2005-2006 Monitoring Plugins Development Team + * + * Description : + * + * A simple interface to executing programs from other programs, using an + * optimized and safe popen()-like implementation. It is considered safe + * in that no shell needs to be spawned and the environment passed to the + * execve()'d program is essentially empty. + * + * The code in this file is a derivative of popen.c which in turn was taken + * from "Advanced Programming for the Unix Environment" by W. Richard Stevens. + * + * Care has been taken to make sure the functions are async-safe. The one + * function which isn't is cmd_init() which it doesn't make sense to + * call twice anyway, so the api as a whole should be considered async-safe. + * + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * + *****************************************************************************/ #define NAGIOSPLUG_API_C 1 @@ -59,7 +59,7 @@ static pid_t *_cmd_pids = NULL; #include #ifdef HAVE_SYS_WAIT_H -# include +# include #endif /* used in _cmd_open to pass the environment to commands */ @@ -67,57 +67,48 @@ extern char **environ; /** macros **/ #ifndef WEXITSTATUS -# define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8) +# define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8) #endif #ifndef WIFEXITED -# define WIFEXITED(stat_val) (((stat_val) & 255) == 0) +# define WIFEXITED(stat_val) (((stat_val)&255) == 0) #endif /* 4.3BSD Reno doesn't define SIG_ERR */ #if defined(SIG_IGN) && !defined(SIG_ERR) -# define SIG_ERR ((Sigfunc *)-1) +# define SIG_ERR ((Sigfunc *)-1) #endif /** prototypes **/ -static int _cmd_open (char *const *, int *, int *) - __attribute__ ((__nonnull__ (1, 2, 3))); +static int _cmd_open(char *const *, int *, int *) __attribute__((__nonnull__(1, 2, 3))); -static int _cmd_fetch_output (int, output *, int) - __attribute__ ((__nonnull__ (2))); +static int _cmd_fetch_output(int, output *, int) __attribute__((__nonnull__(2))); -static int _cmd_close (int); +static int _cmd_close(int); /* prototype imported from utils.h */ -extern void die (int, const char *, ...) - __attribute__ ((__noreturn__, __format__ (__printf__, 2, 3))); - +extern void die(int, const char *, ...) __attribute__((__noreturn__, __format__(__printf__, 2, 3))); /* this function is NOT async-safe. It is exported so multithreaded * plugins (or other apps) can call it prior to running any commands * through this api and thus achieve async-safeness throughout the api */ -void -cmd_init (void) -{ +void cmd_init(void) { long maxfd = mp_open_max(); /* if maxfd is unnaturally high, we force it to a lower value * ( e.g. on SunOS, when ulimit is set to unlimited: 2147483647 this would cause * a segfault when following calloc is called ... ) */ - if ( maxfd > MAXFD_LIMIT ) { + if (maxfd > MAXFD_LIMIT) { maxfd = MAXFD_LIMIT; } if (!_cmd_pids) - _cmd_pids = calloc (maxfd, sizeof (pid_t)); + _cmd_pids = calloc(maxfd, sizeof(pid_t)); } - /* Start running a command, array style */ -static int -_cmd_open (char *const *argv, int *pfd, int *pfderr) -{ +static int _cmd_open(char *const *argv, int *pfd, int *pfderr) { pid_t pid; #ifdef RLIMIT_CORE struct rlimit limit; @@ -130,26 +121,26 @@ _cmd_open (char *const *argv, int *pfd, int *pfderr) setenv("LC_ALL", "C", 1); - if (pipe (pfd) < 0 || pipe (pfderr) < 0 || (pid = fork ()) < 0) - return -1; /* errno set by the failing function */ + if (pipe(pfd) < 0 || pipe(pfderr) < 0 || (pid = fork()) < 0) + return -1; /* errno set by the failing function */ /* child runs exceve() and _exit. */ if (pid == 0) { -#ifdef RLIMIT_CORE +#ifdef RLIMIT_CORE /* the program we execve shouldn't leave core files */ - getrlimit (RLIMIT_CORE, &limit); + getrlimit(RLIMIT_CORE, &limit); limit.rlim_cur = 0; - setrlimit (RLIMIT_CORE, &limit); + setrlimit(RLIMIT_CORE, &limit); #endif - close (pfd[0]); + close(pfd[0]); if (pfd[1] != STDOUT_FILENO) { - dup2 (pfd[1], STDOUT_FILENO); - close (pfd[1]); + dup2(pfd[1], STDOUT_FILENO); + close(pfd[1]); } - close (pfderr[0]); + close(pfderr[0]); if (pfderr[1] != STDERR_FILENO) { - dup2 (pfderr[1], STDERR_FILENO); - close (pfderr[1]); + dup2(pfderr[1], STDERR_FILENO); + close(pfderr[1]); } /* close all descriptors in _cmd_pids[] @@ -158,16 +149,16 @@ _cmd_open (char *const *argv, int *pfd, int *pfderr) long maxfd = mp_open_max(); for (i = 0; i < maxfd; i++) if (_cmd_pids[i] > 0) - close (i); + close(i); - execve (argv[0], argv, environ); - _exit (STATE_UNKNOWN); + execve(argv[0], argv, environ); + _exit(STATE_UNKNOWN); } /* parent picks up execution here */ /* close children descriptors in our address space */ - close (pfd[1]); - close (pfderr[1]); + close(pfd[1]); + close(pfderr[1]); /* tag our file's entry in the pid-list and return it */ _cmd_pids[pfd[0]] = pid; @@ -175,9 +166,7 @@ _cmd_open (char *const *argv, int *pfd, int *pfderr) return pfd[0]; } -static int -_cmd_close (int fd) -{ +static int _cmd_close(int fd) { int status; pid_t pid; @@ -187,40 +176,37 @@ _cmd_close (int fd) return -1; _cmd_pids[fd] = 0; - if (close (fd) == -1) + if (close(fd) == -1) return -1; /* EINTR is ok (sort of), everything else is bad */ - while (waitpid (pid, &status, 0) < 0) + while (waitpid(pid, &status, 0) < 0) if (errno != EINTR) return -1; /* return child's termination status */ - return (WIFEXITED (status)) ? WEXITSTATUS (status) : -1; + return (WIFEXITED(status)) ? WEXITSTATUS(status) : -1; } - -static int -_cmd_fetch_output (int fd, output * op, int flags) -{ +static int _cmd_fetch_output(int fd, output *op, int flags) { size_t len = 0, i = 0, lineno = 0; - size_t rsf = 6, ary_size = 0; /* rsf = right shift factor, dec'ed uncond once */ + size_t rsf = 6, ary_size = 0; /* rsf = right shift factor, dec'ed uncond once */ char *buf = NULL; int ret; char tmpbuf[4096]; op->buf = NULL; op->buflen = 0; - while ((ret = read (fd, tmpbuf, sizeof (tmpbuf))) > 0) { - len = (size_t) ret; - op->buf = realloc (op->buf, op->buflen + len + 1); - memcpy (op->buf + op->buflen, tmpbuf, len); + while ((ret = read(fd, tmpbuf, sizeof(tmpbuf))) > 0) { + len = (size_t)ret; + op->buf = realloc(op->buf, op->buflen + len + 1); + memcpy(op->buf + op->buflen, tmpbuf, len); op->buflen += len; i++; } if (ret < 0) { - printf ("read() returned %d: %s\n", ret, strerror (errno)); + printf("read() returned %d: %s\n", ret, strerror(errno)); return ret; } @@ -231,10 +217,9 @@ _cmd_fetch_output (int fd, output * op, int flags) /* and some may want both */ if (flags & CMD_NO_ASSOC) { - buf = malloc (op->buflen); - memcpy (buf, op->buf, op->buflen); - } - else + buf = malloc(op->buflen); + memcpy(buf, op->buf, op->buflen); + } else buf = op->buf; op->line = NULL; @@ -248,8 +233,8 @@ _cmd_fetch_output (int fd, output * op, int flags) ary_size = op->buflen >> --rsf; } while (!ary_size); - op->line = realloc (op->line, ary_size * sizeof (char *)); - op->lens = realloc (op->lens, ary_size * sizeof (size_t)); + op->line = realloc(op->line, ary_size * sizeof(char *)); + op->lens = realloc(op->lens, ary_size * sizeof(size_t)); } /* set the pointer to the string */ @@ -261,7 +246,7 @@ _cmd_fetch_output (int fd, output * op, int flags) buf[i] = '\0'; /* calculate the string length using pointer difference */ - op->lens[lineno] = (size_t) & buf[i] - (size_t) op->line[lineno]; + op->lens[lineno] = (size_t)&buf[i] - (size_t)op->line[lineno]; lineno++; i++; @@ -270,10 +255,7 @@ _cmd_fetch_output (int fd, output * op, int flags) return lineno; } - -int -cmd_run (const char *cmdstring, output * out, output * err, int flags) -{ +int cmd_run(const char *cmdstring, output *out, output *err, int flags) { int i = 0, argc; size_t cmdlen; char **argv = NULL; @@ -285,120 +267,114 @@ cmd_run (const char *cmdstring, output * out, output * err, int flags) /* initialize the structs */ if (out) - memset (out, 0, sizeof (output)); + memset(out, 0, sizeof(output)); if (err) - memset (err, 0, sizeof (output)); + memset(err, 0, sizeof(output)); /* make copy of command string so strtok() doesn't silently modify it */ /* (the calling program may want to access it later) */ - cmdlen = strlen (cmdstring); - if ((cmd = malloc (cmdlen + 1)) == NULL) + cmdlen = strlen(cmdstring); + if ((cmd = malloc(cmdlen + 1)) == NULL) return -1; - memcpy (cmd, cmdstring, cmdlen); + memcpy(cmd, cmdstring, cmdlen); cmd[cmdlen] = '\0'; /* This is not a shell, so we don't handle "???" */ - if (strstr (cmdstring, "\"")) return -1; + if (strstr(cmdstring, "\"")) + return -1; /* allow single quotes, but only if non-whitesapce doesn't occur on both sides */ - if (strstr (cmdstring, " ' ") || strstr (cmdstring, "'''")) + if (strstr(cmdstring, " ' ") || strstr(cmdstring, "'''")) return -1; /* each arg must be whitespace-separated, so args can be a maximum * of (len / 2) + 1. We add 1 extra to the mix for NULL termination */ argc = (cmdlen >> 1) + 2; - argv = calloc (sizeof (char *), argc); + argv = calloc(sizeof(char *), argc); if (argv == NULL) { - printf ("%s\n", _("Could not malloc argv array in popen()")); + printf("%s\n", _("Could not malloc argv array in popen()")); return -1; } /* get command arguments (stupidly, but fairly quickly) */ while (cmd) { str = cmd; - str += strspn (str, " \t\r\n"); /* trim any leading whitespace */ + str += strspn(str, " \t\r\n"); /* trim any leading whitespace */ - if (strstr (str, "'") == str) { /* handle SIMPLE quoted strings */ + if (strstr(str, "'") == str) { /* handle SIMPLE quoted strings */ str++; - if (!strstr (str, "'")) - return -1; /* balanced? */ - cmd = 1 + strstr (str, "'"); - str[strcspn (str, "'")] = 0; - } - else { - if (strpbrk (str, " \t\r\n")) { - cmd = 1 + strpbrk (str, " \t\r\n"); - str[strcspn (str, " \t\r\n")] = 0; - } - else { + if (!strstr(str, "'")) + return -1; /* balanced? */ + cmd = 1 + strstr(str, "'"); + str[strcspn(str, "'")] = 0; + } else { + if (strpbrk(str, " \t\r\n")) { + cmd = 1 + strpbrk(str, " \t\r\n"); + str[strcspn(str, " \t\r\n")] = 0; + } else { cmd = NULL; } } - if (cmd && strlen (cmd) == strspn (cmd, " \t\r\n")) + if (cmd && strlen(cmd) == strspn(cmd, " \t\r\n")) cmd = NULL; argv[i++] = str; } - return cmd_run_array (argv, out, err, flags); + return cmd_run_array(argv, out, err, flags); } -int -cmd_run_array (char *const *argv, output * out, output * err, int flags) -{ +int cmd_run_array(char *const *argv, output *out, output *err, int flags) { int fd, pfd_out[2], pfd_err[2]; /* initialize the structs */ if (out) - memset (out, 0, sizeof (output)); + memset(out, 0, sizeof(output)); if (err) - memset (err, 0, sizeof (output)); + memset(err, 0, sizeof(output)); - if ((fd = _cmd_open (argv, pfd_out, pfd_err)) == -1) - die (STATE_UNKNOWN, _("Could not open pipe: %s\n"), argv[0]); + if ((fd = _cmd_open(argv, pfd_out, pfd_err)) == -1) + die(STATE_UNKNOWN, _("Could not open pipe: %s\n"), argv[0]); if (out) - out->lines = _cmd_fetch_output (pfd_out[0], out, flags); + out->lines = _cmd_fetch_output(pfd_out[0], out, flags); if (err) - err->lines = _cmd_fetch_output (pfd_err[0], err, flags); + err->lines = _cmd_fetch_output(pfd_err[0], err, flags); - return _cmd_close (fd); + return _cmd_close(fd); } -int -cmd_file_read ( char *filename, output *out, int flags) -{ +int cmd_file_read(char *filename, output *out, int flags) { int fd; - if(out) - memset (out, 0, sizeof(output)); + if (out) + memset(out, 0, sizeof(output)); if ((fd = open(filename, O_RDONLY)) == -1) { - die( STATE_UNKNOWN, _("Error opening %s: %s"), filename, strerror(errno) ); + die(STATE_UNKNOWN, _("Error opening %s: %s"), filename, strerror(errno)); } - if(out) - out->lines = _cmd_fetch_output (fd, out, flags); + if (out) + out->lines = _cmd_fetch_output(fd, out, flags); if (close(fd) == -1) - die( STATE_UNKNOWN, _("Error closing %s: %s"), filename, strerror(errno) ); + die(STATE_UNKNOWN, _("Error closing %s: %s"), filename, strerror(errno)); return 0; } -void -timeout_alarm_handler (int signo) -{ +void timeout_alarm_handler(int signo) { if (signo == SIGALRM) { - printf (_("%s - Plugin timed out after %d seconds\n"), - state_text(timeout_state), timeout_interval); + printf(_("%s - Plugin timed out after %d seconds\n"), state_text(timeout_state), timeout_interval); long maxfd = mp_open_max(); - if(_cmd_pids) for(long int i = 0; i < maxfd; i++) { - if(_cmd_pids[i] != 0) kill(_cmd_pids[i], SIGKILL); - } + if (_cmd_pids) + for (long int i = 0; i < maxfd; i++) { + if (_cmd_pids[i] != 0) + kill(_cmd_pids[i], SIGKILL); + } - exit (timeout_state); + exit(timeout_state); } } diff --git a/lib/utils_cmd.h b/lib/utils_cmd.h index 061f5d4..0fc0917 100644 --- a/lib/utils_cmd.h +++ b/lib/utils_cmd.h @@ -8,8 +8,7 @@ */ /** types **/ -struct output -{ +struct output { char *buf; /* output buffer */ size_t buflen; /* output buffer content length */ char **line; /* array of lines (points to buf) */ @@ -20,20 +19,18 @@ struct output typedef struct output output; /** prototypes **/ -int cmd_run (const char *, output *, output *, int); -int cmd_run_array (char *const *, output *, output *, int); -int cmd_file_read (char *, output *, int); +int cmd_run(const char *, output *, output *, int); +int cmd_run_array(char *const *, output *, output *, int); +int cmd_file_read(char *, output *, int); /* only multi-threaded plugins need to bother with this */ -void cmd_init (void); +void cmd_init(void); #define CMD_INIT cmd_init() /* possible flags for cmd_run()'s fourth argument */ -#define CMD_NO_ARRAYS 0x01 /* don't populate arrays at all */ -#define CMD_NO_ASSOC 0x02 /* output.line won't point to buf */ - - -void timeout_alarm_handler (int); +#define CMD_NO_ARRAYS 0x01 /* don't populate arrays at all */ +#define CMD_NO_ASSOC 0x02 /* output.line won't point to buf */ +void timeout_alarm_handler(int); #endif /* _UTILS_CMD_ */ diff --git a/lib/utils_disk.c b/lib/utils_disk.c index 483be06..a317f7d 100644 --- a/lib/utils_disk.c +++ b/lib/utils_disk.c @@ -1,44 +1,42 @@ /***************************************************************************** -* -* Library for check_disk -* -* License: GPL -* Copyright (c) 1999-2007 Monitoring Plugins Development Team -* -* Description: -* -* This file contains utilities for check_disk. These are tested by libtap -* -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -* -* -*****************************************************************************/ + * + * Library for check_disk + * + * License: GPL + * Copyright (c) 1999-2007 Monitoring Plugins Development Team + * + * Description: + * + * This file contains utilities for check_disk. These are tested by libtap + * + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * + *****************************************************************************/ #include "common.h" #include "utils_disk.h" #include "gl/fsusage.h" #include -void -np_add_name (struct name_list **list, const char *name) -{ - struct name_list *new_entry; - new_entry = (struct name_list *) malloc (sizeof *new_entry); - new_entry->name = (char *) name; - new_entry->next = *list; - *list = new_entry; +void np_add_name(struct name_list **list, const char *name) { + struct name_list *new_entry; + new_entry = (struct name_list *)malloc(sizeof *new_entry); + new_entry->name = (char *)name; + new_entry->next = *list; + *list = new_entry; } /* @brief Initialises a new regex at the begin of list via regcomp(3) @@ -50,17 +48,14 @@ np_add_name (struct name_list **list, const char *name) * @param regex the string containing the regex which should be inserted into the list * @param clags the cflags parameter for regcomp(3) */ -int -np_add_regex (struct regex_list **list, const char *regex, int cflags) -{ - struct regex_list *new_entry = (struct regex_list *) malloc (sizeof *new_entry); +int np_add_regex(struct regex_list **list, const char *regex, int cflags) { + struct regex_list *new_entry = (struct regex_list *)malloc(sizeof *new_entry); if (new_entry == NULL) { - die(STATE_UNKNOWN, _("Cannot allocate memory: %s"), - strerror(errno)); + die(STATE_UNKNOWN, _("Cannot allocate memory: %s"), strerror(errno)); } - int regcomp_result = regcomp(&new_entry->regex, regex, cflags); + int regcomp_result = regcomp(&new_entry->regex, regex, cflags); if (!regcomp_result) { // regcomp succeeded @@ -74,197 +69,186 @@ np_add_regex (struct regex_list **list, const char *regex, int cflags) return regcomp_result; } - } /* Initialises a new parameter at the end of list */ -struct parameter_list * -np_add_parameter(struct parameter_list **list, const char *name) -{ - struct parameter_list *current = *list; - struct parameter_list *new_path; - new_path = (struct parameter_list *) malloc (sizeof *new_path); - new_path->name = (char *) malloc(strlen(name) + 1); - new_path->best_match = NULL; - new_path->name_next = NULL; - new_path->name_prev = NULL; - new_path->freespace_bytes = NULL; - new_path->freespace_units = NULL; - new_path->freespace_percent = NULL; - new_path->usedspace_bytes = NULL; - new_path->usedspace_units = NULL; - new_path->usedspace_percent = NULL; - new_path->usedinodes_percent = NULL; - new_path->freeinodes_percent = NULL; - new_path->group = NULL; - new_path->dfree_pct = -1; - new_path->dused_pct = -1; - new_path->total = 0; - new_path->available = 0; - new_path->available_to_root = 0; - new_path->used = 0; - new_path->dused_units = 0; - new_path->dfree_units = 0; - new_path->dtotal_units = 0; - new_path->inodes_total = 0; - new_path->inodes_free = 0; - new_path->inodes_free_to_root = 0; - new_path->inodes_used = 0; - new_path->dused_inodes_percent = 0; - new_path->dfree_inodes_percent = 0; - - strcpy(new_path->name, name); - - if (current == NULL) { - *list = new_path; - new_path->name_prev = NULL; - } else { - while (current->name_next) { - current = current->name_next; - } - current->name_next = new_path; - new_path->name_prev = current; - } - return new_path; +struct parameter_list *np_add_parameter(struct parameter_list **list, const char *name) { + struct parameter_list *current = *list; + struct parameter_list *new_path; + new_path = (struct parameter_list *)malloc(sizeof *new_path); + new_path->name = (char *)malloc(strlen(name) + 1); + new_path->best_match = NULL; + new_path->name_next = NULL; + new_path->name_prev = NULL; + new_path->freespace_bytes = NULL; + new_path->freespace_units = NULL; + new_path->freespace_percent = NULL; + new_path->usedspace_bytes = NULL; + new_path->usedspace_units = NULL; + new_path->usedspace_percent = NULL; + new_path->usedinodes_percent = NULL; + new_path->freeinodes_percent = NULL; + new_path->group = NULL; + new_path->dfree_pct = -1; + new_path->dused_pct = -1; + new_path->total = 0; + new_path->available = 0; + new_path->available_to_root = 0; + new_path->used = 0; + new_path->dused_units = 0; + new_path->dfree_units = 0; + new_path->dtotal_units = 0; + new_path->inodes_total = 0; + new_path->inodes_free = 0; + new_path->inodes_free_to_root = 0; + new_path->inodes_used = 0; + new_path->dused_inodes_percent = 0; + new_path->dfree_inodes_percent = 0; + + strcpy(new_path->name, name); + + if (current == NULL) { + *list = new_path; + new_path->name_prev = NULL; + } else { + while (current->name_next) { + current = current->name_next; + } + current->name_next = new_path; + new_path->name_prev = current; + } + return new_path; } /* Delete a given parameter from list and return pointer to next element*/ -struct parameter_list * -np_del_parameter(struct parameter_list *item, struct parameter_list *prev) -{ - if (item == NULL) { - return NULL; - } - struct parameter_list *next; - - if (item->name_next) - next = item->name_next; - else - next = NULL; - - if (next) - next->name_prev = prev; - - if (prev) - prev->name_next = next; - - if (item->name) { - free(item->name); - } - free(item); - - return next; -} +struct parameter_list *np_del_parameter(struct parameter_list *item, struct parameter_list *prev) { + if (item == NULL) { + return NULL; + } + struct parameter_list *next; + + if (item->name_next) + next = item->name_next; + else + next = NULL; + + if (next) + next->name_prev = prev; + if (prev) + prev->name_next = next; + + if (item->name) { + free(item->name); + } + free(item); + + return next; +} /* returns a pointer to the struct found in the list */ -struct parameter_list * -np_find_parameter(struct parameter_list *list, const char *name) -{ - struct parameter_list *temp_list; - for (temp_list = list; temp_list; temp_list = temp_list->name_next) { - if (! strcmp(temp_list->name, name)) - return temp_list; - } - - return NULL; +struct parameter_list *np_find_parameter(struct parameter_list *list, const char *name) { + struct parameter_list *temp_list; + for (temp_list = list; temp_list; temp_list = temp_list->name_next) { + if (!strcmp(temp_list->name, name)) + return temp_list; + } + + return NULL; } void np_set_best_match(struct parameter_list *desired, struct mount_entry *mount_list, bool exact) { - struct parameter_list *d; - for (d = desired; d; d= d->name_next) { - if (! d->best_match) { - struct mount_entry *me; - size_t name_len = strlen(d->name); - size_t best_match_len = 0; - struct mount_entry *best_match = NULL; - struct fs_usage fsp; - - /* set best match if path name exactly matches a mounted device name */ - for (me = mount_list; me; me = me->me_next) { - if (strcmp(me->me_devname, d->name)==0) { - if (get_fs_usage(me->me_mountdir, me->me_devname, &fsp) >= 0) { - best_match = me; - } - } - } - - /* set best match by directory name if no match was found by devname */ - if (! best_match) { - for (me = mount_list; me; me = me->me_next) { - size_t len = strlen (me->me_mountdir); - if ((!exact && (best_match_len <= len && len <= name_len && - (len == 1 || strncmp (me->me_mountdir, d->name, len) == 0))) - || (exact && strcmp(me->me_mountdir, d->name)==0)) - { - if (get_fs_usage(me->me_mountdir, me->me_devname, &fsp) >= 0) { - best_match = me; - best_match_len = len; - } - } - } - } - - if (best_match) { - d->best_match = best_match; - } else { - d->best_match = NULL; /* Not sure why this is needed as it should be null on initialisation */ - } - } - } + struct parameter_list *d; + for (d = desired; d; d = d->name_next) { + if (!d->best_match) { + struct mount_entry *me; + size_t name_len = strlen(d->name); + size_t best_match_len = 0; + struct mount_entry *best_match = NULL; + struct fs_usage fsp; + + /* set best match if path name exactly matches a mounted device name */ + for (me = mount_list; me; me = me->me_next) { + if (strcmp(me->me_devname, d->name) == 0) { + if (get_fs_usage(me->me_mountdir, me->me_devname, &fsp) >= 0) { + best_match = me; + } + } + } + + /* set best match by directory name if no match was found by devname */ + if (!best_match) { + for (me = mount_list; me; me = me->me_next) { + size_t len = strlen(me->me_mountdir); + if ((!exact && (best_match_len <= len && len <= name_len && (len == 1 || strncmp(me->me_mountdir, d->name, len) == 0))) || + (exact && strcmp(me->me_mountdir, d->name) == 0)) { + if (get_fs_usage(me->me_mountdir, me->me_devname, &fsp) >= 0) { + best_match = me; + best_match_len = len; + } + } + } + } + + if (best_match) { + d->best_match = best_match; + } else { + d->best_match = NULL; /* Not sure why this is needed as it should be null on initialisation */ + } + } + } } /* Returns true if name is in list */ -bool np_find_name (struct name_list *list, const char *name) { - const struct name_list *n; - - if (list == NULL || name == NULL) { - return false; - } - for (n = list; n; n = n->next) { - if (!strcmp(name, n->name)) { - return true; - } - } - return false; +bool np_find_name(struct name_list *list, const char *name) { + const struct name_list *n; + + if (list == NULL || name == NULL) { + return false; + } + for (n = list; n; n = n->next) { + if (!strcmp(name, n->name)) { + return true; + } + } + return false; } /* Returns true if name is in list */ -bool np_find_regmatch (struct regex_list *list, const char *name) { - int len; - regmatch_t m; +bool np_find_regmatch(struct regex_list *list, const char *name) { + int len; + regmatch_t m; - if (name == NULL) { - return false; - } + if (name == NULL) { + return false; + } - len = strlen(name); + len = strlen(name); - for (; list; list = list->next) { - /* Emulate a full match as if surrounded with ^( )$ - by checking whether the match spans the whole name */ - if (!regexec(&list->regex, name, 1, &m, 0) && m.rm_so == 0 && m.rm_eo == len) { - return true; - } - } + for (; list; list = list->next) { + /* Emulate a full match as if surrounded with ^( )$ + by checking whether the match spans the whole name */ + if (!regexec(&list->regex, name, 1, &m, 0) && m.rm_so == 0 && m.rm_eo == len) { + return true; + } + } - return false; + return false; } bool np_seen_name(struct name_list *list, const char *name) { - const struct name_list *s; - for (s = list; s; s=s->next) { - if (!strcmp(s->name, name)) { - return true; - } - } - return false; + const struct name_list *s; + for (s = list; s; s = s->next) { + if (!strcmp(s->name, name)) { + return true; + } + } + return false; } -bool np_regex_match_mount_entry (struct mount_entry* me, regex_t* re) { - if (regexec(re, me->me_devname, (size_t) 0, NULL, 0) == 0 || - regexec(re, me->me_mountdir, (size_t) 0, NULL, 0) == 0 ) { - return true; - } +bool np_regex_match_mount_entry(struct mount_entry *me, regex_t *re) { + if (regexec(re, me->me_devname, (size_t)0, NULL, 0) == 0 || regexec(re, me->me_mountdir, (size_t)0, NULL, 0) == 0) { + return true; + } return false; } diff --git a/lib/utils_disk.h b/lib/utils_disk.h index 5b2caf2..c5e81dc 100644 --- a/lib/utils_disk.h +++ b/lib/utils_disk.h @@ -4,49 +4,45 @@ #include "utils_base.h" #include "regex.h" -struct name_list -{ - char *name; - struct name_list *next; +struct name_list { + char *name; + struct name_list *next; }; -struct regex_list -{ - regex_t regex; - struct regex_list *next; +struct regex_list { + regex_t regex; + struct regex_list *next; }; -struct parameter_list -{ - char *name; - thresholds *freespace_bytes; - thresholds *freespace_units; - thresholds *freespace_percent; - thresholds *usedspace_bytes; - thresholds *usedspace_units; - thresholds *usedspace_percent; - thresholds *usedinodes_percent; - thresholds *freeinodes_percent; - char *group; - struct mount_entry *best_match; - struct parameter_list *name_next; - struct parameter_list *name_prev; - uintmax_t total, available, available_to_root, used, - inodes_free, inodes_free_to_root, inodes_used, inodes_total; - double dfree_pct, dused_pct; - uint64_t dused_units, dfree_units, dtotal_units; - double dused_inodes_percent, dfree_inodes_percent; +struct parameter_list { + char *name; + thresholds *freespace_bytes; + thresholds *freespace_units; + thresholds *freespace_percent; + thresholds *usedspace_bytes; + thresholds *usedspace_units; + thresholds *usedspace_percent; + thresholds *usedinodes_percent; + thresholds *freeinodes_percent; + char *group; + struct mount_entry *best_match; + struct parameter_list *name_next; + struct parameter_list *name_prev; + uintmax_t total, available, available_to_root, used, inodes_free, inodes_free_to_root, inodes_used, inodes_total; + double dfree_pct, dused_pct; + uint64_t dused_units, dfree_units, dtotal_units; + double dused_inodes_percent, dfree_inodes_percent; }; -void np_add_name (struct name_list **list, const char *name); -bool np_find_name (struct name_list *list, const char *name); -bool np_seen_name (struct name_list *list, const char *name); -int np_add_regex (struct regex_list **list, const char *regex, int cflags); -bool np_find_regmatch (struct regex_list *list, const char *name); +void np_add_name(struct name_list **list, const char *name); +bool np_find_name(struct name_list *list, const char *name); +bool np_seen_name(struct name_list *list, const char *name); +int np_add_regex(struct regex_list **list, const char *regex, int cflags); +bool np_find_regmatch(struct regex_list *list, const char *name); struct parameter_list *np_add_parameter(struct parameter_list **list, const char *name); struct parameter_list *np_find_parameter(struct parameter_list *list, const char *name); struct parameter_list *np_del_parameter(struct parameter_list *item, struct parameter_list *prev); -int search_parameter_list (struct parameter_list *list, const char *name); +int search_parameter_list(struct parameter_list *list, const char *name); void np_set_best_match(struct parameter_list *desired, struct mount_entry *mount_list, bool exact); -bool np_regex_match_mount_entry (struct mount_entry* me, regex_t* re); +bool np_regex_match_mount_entry(struct mount_entry *me, regex_t *re); diff --git a/lib/utils_tcp.c b/lib/utils_tcp.c index 23ee4a9..ffb351e 100644 --- a/lib/utils_tcp.c +++ b/lib/utils_tcp.c @@ -1,51 +1,46 @@ /***************************************************************************** -* -* Library for check_tcp -* -* License: GPL -* Copyright (c) 1999-2013 Monitoring Plugins Development Team -* -* Description: -* -* This file contains utilities for check_tcp. These are tested by libtap -* -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -* -* -*****************************************************************************/ + * + * Library for check_tcp + * + * License: GPL + * Copyright (c) 1999-2013 Monitoring Plugins Development Team + * + * Description: + * + * This file contains utilities for check_tcp. These are tested by libtap + * + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * + *****************************************************************************/ #include "common.h" #include "utils_tcp.h" -#define VERBOSE(message) \ - do { \ - if (flags & NP_MATCH_VERBOSE) \ - puts(message); \ +#define VERBOSE(message) \ + do { \ + if (flags & NP_MATCH_VERBOSE) \ + puts(message); \ } while (0) -enum np_match_result -np_expect_match(char *status, char **server_expect, int expect_count, int flags) -{ +enum np_match_result np_expect_match(char *status, char **server_expect, int expect_count, int flags) { int i, match = 0, partial = 0; for (i = 0; i < expect_count; i++) { if (flags & NP_MATCH_VERBOSE) - printf("looking for [%s] %s [%s]\n", server_expect[i], - (flags & NP_MATCH_EXACT) ? - "in beginning of" : "anywhere in", - status); + printf("looking for [%s] %s [%s]\n", server_expect[i], (flags & NP_MATCH_EXACT) ? "in beginning of" : "anywhere in", status); if (flags & NP_MATCH_EXACT) { if (strncmp(status, server_expect[i], strlen(server_expect[i])) == 0) { @@ -58,15 +53,14 @@ np_expect_match(char *status, char **server_expect, int expect_count, int flags) continue; } } else if (strstr(status, server_expect[i]) != NULL) { - VERBOSE("found it"); - match++; - continue; + VERBOSE("found it"); + match++; + continue; } VERBOSE("couldn't find it"); } - if ((flags & NP_MATCH_ALL && match == expect_count) || - (!(flags & NP_MATCH_ALL) && match >= 1)) + if ((flags & NP_MATCH_ALL && match == expect_count) || (!(flags & NP_MATCH_ALL) && match >= 1)) return NP_MATCH_SUCCESS; else if (partial > 0 || !(flags & NP_MATCH_EXACT)) return NP_MATCH_RETRY; diff --git a/lib/utils_tcp.h b/lib/utils_tcp.h index 0328a9c..6543377 100644 --- a/lib/utils_tcp.h +++ b/lib/utils_tcp.h @@ -1,8 +1,8 @@ /* Header file for utils_tcp */ -#define NP_MATCH_ALL 0x1 -#define NP_MATCH_EXACT 0x2 -#define NP_MATCH_VERBOSE 0x4 +#define NP_MATCH_ALL 0x1 +#define NP_MATCH_EXACT 0x2 +#define NP_MATCH_VERBOSE 0x4 /* * The NP_MATCH_RETRY state indicates that matching might succeed if @@ -10,13 +10,6 @@ * caller to decide whether it makes sense to wait for additional data from the * server. */ -enum np_match_result { - NP_MATCH_FAILURE, - NP_MATCH_SUCCESS, - NP_MATCH_RETRY -}; +enum np_match_result { NP_MATCH_FAILURE, NP_MATCH_SUCCESS, NP_MATCH_RETRY }; -enum np_match_result np_expect_match(char *status, - char **server_expect, - int server_expect_count, - int flags); +enum np_match_result np_expect_match(char *status, char **server_expect, int server_expect_count, int flags); -- cgit v0.10-9-g596f