diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/extra_opts.c | 149 | ||||
-rw-r--r-- | lib/extra_opts.h | 1 | ||||
-rw-r--r-- | lib/maxfd.c | 32 | ||||
-rw-r--r-- | lib/maxfd.h | 6 | ||||
-rw-r--r-- | lib/parse_ini.c | 135 | ||||
-rw-r--r-- | lib/parse_ini.h | 1 | ||||
-rw-r--r-- | lib/tests/test_base64.c | 308 | ||||
-rw-r--r-- | lib/tests/test_cmd.c | 261 | ||||
-rw-r--r-- | lib/tests/test_disk.c | 180 | ||||
-rwxr-xr-x | lib/tests/test_generic_output | bin | 0 -> 143808 bytes | |||
-rw-r--r-- | lib/tests/test_ini1.c | 116 | ||||
-rw-r--r-- | lib/tests/test_ini3.c | 37 | ||||
-rw-r--r-- | lib/tests/test_opts1.c | 105 | ||||
-rw-r--r-- | lib/tests/test_opts2.c | 124 | ||||
-rw-r--r-- | lib/tests/test_opts3.c | 37 | ||||
-rw-r--r-- | lib/tests/test_tcp.c | 48 | ||||
-rw-r--r-- | lib/tests/test_utils.c | 491 | ||||
-rw-r--r-- | lib/utils_base.c | 451 | ||||
-rw-r--r-- | lib/utils_base.h | 61 | ||||
-rw-r--r-- | lib/utils_cmd.c | 280 | ||||
-rw-r--r-- | lib/utils_cmd.h | 20 | ||||
-rw-r--r-- | lib/utils_disk.c | 397 | ||||
-rw-r--r-- | lib/utils_disk.h | 66 | ||||
-rw-r--r-- | lib/utils_tcp.c | 78 | ||||
-rw-r--r-- | lib/utils_tcp.h | 11 |
25 files changed, 1605 insertions, 1790 deletions
diff --git a/lib/extra_opts.c b/lib/extra_opts.c index 771621d..8878733 100644 --- a/lib/extra_opts.c +++ b/lib/extra_opts.c | |||
@@ -1,24 +1,24 @@ | |||
1 | /***************************************************************************** | 1 | /***************************************************************************** |
2 | * | 2 | * |
3 | * Monitoring Plugins extra_opts library | 3 | * Monitoring Plugins extra_opts library |
4 | * | 4 | * |
5 | * License: GPL | 5 | * License: GPL |
6 | * Copyright (c) 2007 Monitoring Plugins Development Team | 6 | * Copyright (c) 2007 - 2024 Monitoring Plugins Development Team |
7 | * | 7 | * |
8 | * This program is free software: you can redistribute it and/or modify | 8 | * This program is free software: you can redistribute it and/or modify |
9 | * it under the terms of the GNU General Public License as published by | 9 | * it under the terms of the GNU General Public License as published by |
10 | * the Free Software Foundation, either version 3 of the License, or | 10 | * the Free Software Foundation, either version 3 of the License, or |
11 | * (at your option) any later version. | 11 | * (at your option) any later version. |
12 | * | 12 | * |
13 | * This program is distributed in the hope that it will be useful, | 13 | * This program is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU General Public License for more details. | 16 | * GNU General Public License for more details. |
17 | * | 17 | * |
18 | * You should have received a copy of the GNU General Public License | 18 | * You should have received a copy of the GNU General Public License |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
20 | * | 20 | * |
21 | *****************************************************************************/ | 21 | *****************************************************************************/ |
22 | 22 | ||
23 | #include "common.h" | 23 | #include "common.h" |
24 | #include "utils_base.h" | 24 | #include "utils_base.h" |
@@ -26,110 +26,115 @@ | |||
26 | #include "extra_opts.h" | 26 | #include "extra_opts.h" |
27 | 27 | ||
28 | /* FIXME: copied from utils.h; we should move a bunch of libs! */ | 28 | /* FIXME: copied from utils.h; we should move a bunch of libs! */ |
29 | bool is_option2 (char *str) | 29 | bool is_option2(char *str) { |
30 | { | ||
31 | if (!str) | 30 | if (!str) |
32 | return false; | 31 | return false; |
33 | else if (strspn (str, "-") == 1 || strspn (str, "-") == 2) | 32 | else if (strspn(str, "-") == 1 || strspn(str, "-") == 2) |
34 | return true; | 33 | return true; |
35 | else | 34 | else |
36 | return false; | 35 | return false; |
37 | } | 36 | } |
38 | 37 | ||
39 | /* this is the externally visible function used by plugins */ | 38 | /* this is the externally visible function used by plugins */ |
40 | char **np_extra_opts(int *argc, char **argv, const char *plugin_name){ | 39 | char **np_extra_opts(int *argc, char **argv, const char *plugin_name) { |
41 | np_arg_list *extra_args=NULL, *ea1=NULL, *ea_tmp=NULL; | 40 | np_arg_list *extra_args = NULL, *ea1 = NULL, *ea_tmp = NULL; |
42 | char **argv_new=NULL; | 41 | char **argv_new = NULL; |
43 | char *argptr=NULL; | 42 | char *argptr = NULL; |
44 | int i, j, optfound, argc_new, ea_num=*argc; | 43 | int i, j, optfound, argc_new, ea_num = *argc; |
45 | 44 | ||
46 | if(*argc<2) { | 45 | if (*argc < 2) { |
47 | /* No arguments provided */ | 46 | /* No arguments provided */ |
48 | return argv; | 47 | return argv; |
49 | } | 48 | } |
50 | 49 | ||
51 | for(i=1; i<*argc; i++){ | 50 | for (i = 1; i < *argc; i++) { |
52 | argptr=NULL; | 51 | argptr = NULL; |
53 | optfound=0; | 52 | optfound = 0; |
54 | 53 | ||
55 | /* Do we have an extra-opts parameter? */ | 54 | /* Do we have an extra-opts parameter? */ |
56 | if(strncmp(argv[i], "--extra-opts=", 13)==0){ | 55 | if (strncmp(argv[i], "--extra-opts=", 13) == 0) { |
57 | /* It is a single argument with value */ | 56 | /* It is a single argument with value */ |
58 | argptr=argv[i]+13; | 57 | argptr = argv[i] + 13; |
59 | /* Delete the extra opts argument */ | 58 | /* Delete the extra opts argument */ |
60 | for(j=i;j<*argc;j++) argv[j]=argv[j+1]; | 59 | for (j = i; j < *argc; j++) |
60 | argv[j] = argv[j + 1]; | ||
61 | i--; | 61 | i--; |
62 | *argc-=1; | 62 | *argc -= 1; |
63 | }else if(strcmp(argv[i], "--extra-opts")==0){ | 63 | } else if (strcmp(argv[i], "--extra-opts") == 0) { |
64 | if((i+1<*argc)&&!is_option2(argv[i+1])){ | 64 | if ((i + 1 < *argc) && !is_option2(argv[i + 1])) { |
65 | /* It is a argument with separate value */ | 65 | /* It is a argument with separate value */ |
66 | argptr=argv[i+1]; | 66 | argptr = argv[i + 1]; |
67 | /* Delete the extra-opts argument/value */ | 67 | /* Delete the extra-opts argument/value */ |
68 | for(j=i;j<*argc-1;j++) argv[j]=argv[j+2]; | 68 | for (j = i; j < *argc - 1; j++) |
69 | i-=2; | 69 | argv[j] = argv[j + 2]; |
70 | *argc-=2; | 70 | i -= 2; |
71 | *argc -= 2; | ||
71 | ea_num--; | 72 | ea_num--; |
72 | }else{ | 73 | } else { |
73 | /* It has no value */ | 74 | /* It has no value */ |
74 | optfound=1; | 75 | optfound = 1; |
75 | /* Delete the extra opts argument */ | 76 | /* Delete the extra opts argument */ |
76 | for(j=i;j<*argc;j++) argv[j]=argv[j+1]; | 77 | for (j = i; j < *argc; j++) |
78 | argv[j] = argv[j + 1]; | ||
77 | i--; | 79 | i--; |
78 | *argc-=1; | 80 | *argc -= 1; |
79 | } | 81 | } |
80 | } | 82 | } |
81 | 83 | ||
82 | /* If we found extra-opts, expand them and store them for later*/ | 84 | /* If we found extra-opts, expand them and store them for later*/ |
83 | if(argptr||optfound){ | 85 | if (argptr || optfound) { |
84 | /* Process ini section, returning a linked list of arguments */ | 86 | /* Process ini section, returning a linked list of arguments */ |
85 | ea1=np_get_defaults(argptr, plugin_name); | 87 | ea1 = np_get_defaults(argptr, plugin_name); |
86 | if(ea1==NULL) { | 88 | if (ea1 == NULL) { |
87 | /* no extra args (empty section)? */ | 89 | /* no extra args (empty section)? */ |
88 | ea_num--; | 90 | ea_num--; |
89 | continue; | 91 | continue; |
90 | } | 92 | } |
91 | 93 | ||
92 | /* append the list to extra_args */ | 94 | /* append the list to extra_args */ |
93 | if(extra_args==NULL){ | 95 | if (extra_args == NULL) { |
94 | extra_args=ea1; | 96 | extra_args = ea1; |
95 | while((ea1 = ea1->next)) ea_num++; | 97 | while ((ea1 = ea1->next)) |
96 | }else{ | 98 | ea_num++; |
97 | ea_tmp=extra_args; | 99 | } else { |
98 | while(ea_tmp->next) { | 100 | ea_tmp = extra_args; |
99 | ea_tmp=ea_tmp->next; | 101 | while (ea_tmp->next) { |
102 | ea_tmp = ea_tmp->next; | ||
100 | } | 103 | } |
101 | ea_tmp->next=ea1; | 104 | ea_tmp->next = ea1; |
102 | while((ea1 = ea1->next)) ea_num++; | 105 | while ((ea1 = ea1->next)) |
106 | ea_num++; | ||
103 | } | 107 | } |
104 | ea1=ea_tmp=NULL; | 108 | ea1 = ea_tmp = NULL; |
105 | } | 109 | } |
106 | } /* lather, rince, repeat */ | 110 | } /* lather, rince, repeat */ |
107 | 111 | ||
108 | if(ea_num==*argc && extra_args==NULL){ | 112 | if (ea_num == *argc && extra_args == NULL) { |
109 | /* No extra-opts */ | 113 | /* No extra-opts */ |
110 | return argv; | 114 | return argv; |
111 | } | 115 | } |
112 | 116 | ||
113 | /* done processing arguments. now create a new argv array... */ | 117 | /* done processing arguments. now create a new argv array... */ |
114 | argv_new=(char**)malloc((ea_num+1)*sizeof(char**)); | 118 | argv_new = (char **)malloc((ea_num + 1) * sizeof(char **)); |
115 | if(argv_new==NULL) die(STATE_UNKNOWN, _("malloc() failed!\n")); | 119 | if (argv_new == NULL) |
120 | die(STATE_UNKNOWN, _("malloc() failed!\n")); | ||
116 | 121 | ||
117 | /* starting with program name */ | 122 | /* starting with program name */ |
118 | argv_new[0]=argv[0]; | 123 | argv_new[0] = argv[0]; |
119 | argc_new=1; | 124 | argc_new = 1; |
120 | /* then parsed ini opts (frying them up in the same run) */ | 125 | /* then parsed ini opts (frying them up in the same run) */ |
121 | while(extra_args){ | 126 | while (extra_args) { |
122 | argv_new[argc_new++]=extra_args->arg; | 127 | argv_new[argc_new++] = extra_args->arg; |
123 | ea1=extra_args; | 128 | ea1 = extra_args; |
124 | extra_args=extra_args->next; | 129 | extra_args = extra_args->next; |
125 | free(ea1); | 130 | free(ea1); |
126 | } | 131 | } |
127 | /* finally the rest of the argv array */ | 132 | /* finally the rest of the argv array */ |
128 | for (i=1; i<*argc; i++) argv_new[argc_new++]=argv[i]; | 133 | for (i = 1; i < *argc; i++) |
129 | *argc=argc_new; | 134 | argv_new[argc_new++] = argv[i]; |
135 | *argc = argc_new; | ||
130 | /* and terminate. */ | 136 | /* and terminate. */ |
131 | argv_new[argc_new]=NULL; | 137 | argv_new[argc_new] = NULL; |
132 | 138 | ||
133 | return argv_new; | 139 | return argv_new; |
134 | } | 140 | } |
135 | |||
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 @@ | |||
20 | char **np_extra_opts(int *argc, char **argv, const char *plugin_name); | 20 | char **np_extra_opts(int *argc, char **argv, const char *plugin_name); |
21 | 21 | ||
22 | #endif /* _EXTRA_OPTS_H_ */ | 22 | #endif /* _EXTRA_OPTS_H_ */ |
23 | |||
diff --git a/lib/maxfd.c b/lib/maxfd.c index 529b356..ca5b6e5 100644 --- a/lib/maxfd.c +++ b/lib/maxfd.c | |||
@@ -1,7 +1,27 @@ | |||
1 | /***************************************************************************** | ||
2 | * | ||
3 | * License: GPL | ||
4 | * Copyright (c) 2024 Monitoring Plugins Development Team | ||
5 | * | ||
6 | * This program is free software: you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License as published by | ||
8 | * the Free Software Foundation, either version 3 of the License, or | ||
9 | * (at your option) any later version. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | * GNU General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License | ||
17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
18 | * | ||
19 | *****************************************************************************/ | ||
20 | |||
1 | #include "./maxfd.h" | 21 | #include "./maxfd.h" |
2 | #include <errno.h> | 22 | #include <errno.h> |
3 | 23 | ||
4 | long mp_open_max (void) { | 24 | long mp_open_max(void) { |
5 | long maxfd = 0L; | 25 | long maxfd = 0L; |
6 | /* Try sysconf(_SC_OPEN_MAX) first, as it can be higher than OPEN_MAX. | 26 | /* Try sysconf(_SC_OPEN_MAX) first, as it can be higher than OPEN_MAX. |
7 | * If that fails and the macro isn't defined, we fall back to an educated | 27 | * If that fails and the macro isn't defined, we fall back to an educated |
@@ -10,17 +30,17 @@ long mp_open_max (void) { | |||
10 | 30 | ||
11 | #ifdef _SC_OPEN_MAX | 31 | #ifdef _SC_OPEN_MAX |
12 | errno = 0; | 32 | errno = 0; |
13 | if ((maxfd = sysconf (_SC_OPEN_MAX)) < 0) { | 33 | if ((maxfd = sysconf(_SC_OPEN_MAX)) < 0) { |
14 | if (errno == 0) | 34 | if (errno == 0) |
15 | maxfd = DEFAULT_MAXFD; /* it's indeterminate */ | 35 | maxfd = DEFAULT_MAXFD; /* it's indeterminate */ |
16 | else | 36 | else |
17 | die (STATE_UNKNOWN, _("sysconf error for _SC_OPEN_MAX\n")); | 37 | die(STATE_UNKNOWN, _("sysconf error for _SC_OPEN_MAX\n")); |
18 | } | 38 | } |
19 | #elif defined(OPEN_MAX) | 39 | #elif defined(OPEN_MAX) |
20 | return OPEN_MAX | 40 | return OPEN_MAX |
21 | #else /* sysconf macro unavailable, so guess (may be wildly inaccurate) */ | 41 | #else /* sysconf macro unavailable, so guess (may be wildly inaccurate) */ |
22 | return DEFAULT_MAXFD; | 42 | return DEFAULT_MAXFD; |
23 | #endif | 43 | #endif |
24 | 44 | ||
25 | return(maxfd); | 45 | return (maxfd); |
26 | } | 46 | } |
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 @@ | |||
1 | #ifndef _MAXFD_ | 1 | #ifndef _MAXFD_ |
2 | #define _MAXFD_ | 2 | #define _MAXFD_ |
3 | 3 | ||
4 | #define DEFAULT_MAXFD 256 /* fallback value if no max open files value is set */ | 4 | #define DEFAULT_MAXFD 256 /* fallback value if no max open files value is set */ |
5 | #define MAXFD_LIMIT 8192 /* upper limit of open files */ | 5 | #define MAXFD_LIMIT 8192 /* upper limit of open files */ |
6 | 6 | ||
7 | long mp_open_max (void); | 7 | long mp_open_max(void); |
8 | 8 | ||
9 | #endif // _MAXFD_ | 9 | #endif // _MAXFD_ |
diff --git a/lib/parse_ini.c b/lib/parse_ini.c index 09c0dc4..1289aae 100644 --- a/lib/parse_ini.c +++ b/lib/parse_ini.c | |||
@@ -1,25 +1,25 @@ | |||
1 | /***************************************************************************** | 1 | /***************************************************************************** |
2 | * | 2 | * |
3 | * Monitoring Plugins parse_ini library | 3 | * Monitoring Plugins parse_ini library |
4 | * | 4 | * |
5 | * License: GPL | 5 | * License: GPL |
6 | * Copyright (c) 2007 Monitoring Plugins Development Team | 6 | * Copyright (c) 2007 - 2024 Monitoring Plugins Development Team |
7 | * | 7 | * |
8 | * This program is free software: you can redistribute it and/or modify | 8 | * This program is free software: you can redistribute it and/or modify |
9 | * it under the terms of the GNU General Public License as published by | 9 | * it under the terms of the GNU General Public License as published by |
10 | * the Free Software Foundation, either version 3 of the License, or | 10 | * the Free Software Foundation, either version 3 of the License, or |
11 | * (at your option) any later version. | 11 | * (at your option) any later version. |
12 | * | 12 | * |
13 | * This program is distributed in the hope that it will be useful, | 13 | * This program is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU General Public License for more details. | 16 | * GNU General Public License for more details. |
17 | * | 17 | * |
18 | * You should have received a copy of the GNU General Public License | 18 | * You should have received a copy of the GNU General Public License |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
20 | * | 20 | * |
21 | * | 21 | * |
22 | *****************************************************************************/ | 22 | *****************************************************************************/ |
23 | 23 | ||
24 | #include "common.h" | 24 | #include "common.h" |
25 | #include "idpriv.h" | 25 | #include "idpriv.h" |
@@ -40,31 +40,20 @@ typedef struct { | |||
40 | char *stanza; | 40 | char *stanza; |
41 | } np_ini_info; | 41 | } np_ini_info; |
42 | 42 | ||
43 | static char *default_ini_file_names[] = { | 43 | static char *default_ini_file_names[] = {"monitoring-plugins.ini", "plugins.ini", "nagios-plugins.ini", NULL}; |
44 | "monitoring-plugins.ini", | ||
45 | "plugins.ini", | ||
46 | "nagios-plugins.ini", | ||
47 | NULL | ||
48 | }; | ||
49 | 44 | ||
50 | static char *default_ini_path_names[] = { | 45 | static char *default_ini_path_names[] = { |
51 | "/usr/local/etc/monitoring-plugins/monitoring-plugins.ini", | 46 | "/usr/local/etc/monitoring-plugins/monitoring-plugins.ini", "/usr/local/etc/monitoring-plugins.ini", |
52 | "/usr/local/etc/monitoring-plugins.ini", | 47 | "/etc/monitoring-plugins/monitoring-plugins.ini", "/etc/monitoring-plugins.ini", |
53 | "/etc/monitoring-plugins/monitoring-plugins.ini", | ||
54 | "/etc/monitoring-plugins.ini", | ||
55 | /* deprecated path names (for backward compatibility): */ | 48 | /* deprecated path names (for backward compatibility): */ |
56 | "/etc/nagios/plugins.ini", | 49 | "/etc/nagios/plugins.ini", "/usr/local/nagios/etc/plugins.ini", "/usr/local/etc/nagios/plugins.ini", "/etc/opt/nagios/plugins.ini", |
57 | "/usr/local/nagios/etc/plugins.ini", | 50 | "/etc/nagios-plugins.ini", "/usr/local/etc/nagios-plugins.ini", "/etc/opt/nagios-plugins.ini", NULL}; |
58 | "/usr/local/etc/nagios/plugins.ini", | ||
59 | "/etc/opt/nagios/plugins.ini", | ||
60 | "/etc/nagios-plugins.ini", | ||
61 | "/usr/local/etc/nagios-plugins.ini", | ||
62 | "/etc/opt/nagios-plugins.ini", | ||
63 | NULL | ||
64 | }; | ||
65 | 51 | ||
66 | /* eat all characters from a FILE pointer until n is encountered */ | 52 | /* eat all characters from a FILE pointer until n is encountered */ |
67 | #define GOBBLE_TO(f, c, n) do { (c)=fgetc((f)); } while((c)!=EOF && (c)!=(n)) | 53 | #define GOBBLE_TO(f, c, n) \ |
54 | do { \ | ||
55 | (c) = fgetc((f)); \ | ||
56 | } while ((c) != EOF && (c) != (n)) | ||
68 | 57 | ||
69 | /* internal function that returns the constructed defaults options */ | 58 | /* internal function that returns the constructed defaults options */ |
70 | static int read_defaults(FILE *f, const char *stanza, np_arg_list **opts); | 59 | static int read_defaults(FILE *f, const char *stanza, np_arg_list **opts); |
@@ -81,9 +70,7 @@ static char *default_file_in_path(void); | |||
81 | * [stanza][@filename] | 70 | * [stanza][@filename] |
82 | * into its separate parts. | 71 | * into its separate parts. |
83 | */ | 72 | */ |
84 | static void | 73 | static void parse_locator(const char *locator, const char *def_stanza, np_ini_info *i) { |
85 | parse_locator(const char *locator, const char *def_stanza, np_ini_info *i) | ||
86 | { | ||
87 | size_t locator_len = 0, stanza_len = 0; | 74 | size_t locator_len = 0, stanza_len = 0; |
88 | 75 | ||
89 | /* if locator is NULL we'll use default values */ | 76 | /* if locator is NULL we'll use default values */ |
@@ -96,7 +83,7 @@ parse_locator(const char *locator, const char *def_stanza, np_ini_info *i) | |||
96 | i->stanza = malloc(sizeof(char) * (stanza_len + 1)); | 83 | i->stanza = malloc(sizeof(char) * (stanza_len + 1)); |
97 | strncpy(i->stanza, locator, stanza_len); | 84 | strncpy(i->stanza, locator, stanza_len); |
98 | i->stanza[stanza_len] = '\0'; | 85 | i->stanza[stanza_len] = '\0'; |
99 | } else {/* otherwise we use the default stanza */ | 86 | } else { /* otherwise we use the default stanza */ |
100 | i->stanza = strdup(def_stanza); | 87 | i->stanza = strdup(def_stanza); |
101 | } | 88 | } |
102 | 89 | ||
@@ -105,7 +92,7 @@ parse_locator(const char *locator, const char *def_stanza, np_ini_info *i) | |||
105 | 92 | ||
106 | /* check whether there's an @file part */ | 93 | /* check whether there's an @file part */ |
107 | if (stanza_len == locator_len) { | 94 | if (stanza_len == locator_len) { |
108 | i->file = default_file(); | 95 | i->file = default_file(); |
109 | i->file_string_on_heap = false; | 96 | i->file_string_on_heap = false; |
110 | } else { | 97 | } else { |
111 | i->file = strdup(&(locator[stanza_len + 1])); | 98 | i->file = strdup(&(locator[stanza_len + 1])); |
@@ -113,35 +100,28 @@ parse_locator(const char *locator, const char *def_stanza, np_ini_info *i) | |||
113 | } | 100 | } |
114 | 101 | ||
115 | if (i->file == NULL || i->file[0] == '\0') | 102 | if (i->file == NULL || i->file[0] == '\0') |
116 | die(STATE_UNKNOWN, | 103 | die(STATE_UNKNOWN, _("Cannot find config file in any standard location.\n")); |
117 | _("Cannot find config file in any standard location.\n")); | ||
118 | } | 104 | } |
119 | 105 | ||
120 | /* | 106 | /* |
121 | * This is the externally visible function used by extra_opts. | 107 | * This is the externally visible function used by extra_opts. |
122 | */ | 108 | */ |
123 | np_arg_list * | 109 | np_arg_list *np_get_defaults(const char *locator, const char *default_section) { |
124 | np_get_defaults(const char *locator, const char *default_section) | ||
125 | { | ||
126 | FILE *inifile = NULL; | 110 | FILE *inifile = NULL; |
127 | np_arg_list *defaults = NULL; | 111 | np_arg_list *defaults = NULL; |
128 | np_ini_info i; | 112 | np_ini_info i; |
129 | int is_suid_plugin = mp_suid(); | 113 | int is_suid_plugin = mp_suid(); |
130 | 114 | ||
131 | if (is_suid_plugin && idpriv_temp_drop() == -1) | 115 | if (is_suid_plugin && idpriv_temp_drop() == -1) |
132 | die(STATE_UNKNOWN, _("Cannot drop privileges: %s\n"), | 116 | die(STATE_UNKNOWN, _("Cannot drop privileges: %s\n"), strerror(errno)); |
133 | strerror(errno)); | ||
134 | 117 | ||
135 | parse_locator(locator, default_section, &i); | 118 | parse_locator(locator, default_section, &i); |
136 | inifile = strcmp(i.file, "-") == 0 ? stdin : fopen(i.file, "r"); | 119 | inifile = strcmp(i.file, "-") == 0 ? stdin : fopen(i.file, "r"); |
137 | 120 | ||
138 | if (inifile == NULL) | 121 | if (inifile == NULL) |
139 | die(STATE_UNKNOWN, _("Can't read config file: %s\n"), | 122 | die(STATE_UNKNOWN, _("Can't read config file: %s\n"), strerror(errno)); |
140 | strerror(errno)); | ||
141 | if (!read_defaults(inifile, i.stanza, &defaults)) | 123 | if (!read_defaults(inifile, i.stanza, &defaults)) |
142 | die(STATE_UNKNOWN, | 124 | die(STATE_UNKNOWN, _("Invalid section '%s' in config file '%s'\n"), i.stanza, i.file); |
143 | _("Invalid section '%s' in config file '%s'\n"), i.stanza, | ||
144 | i.file); | ||
145 | 125 | ||
146 | if (i.file_string_on_heap) { | 126 | if (i.file_string_on_heap) { |
147 | free(i.file); | 127 | free(i.file); |
@@ -151,8 +131,7 @@ np_get_defaults(const char *locator, const char *default_section) | |||
151 | fclose(inifile); | 131 | fclose(inifile); |
152 | free(i.stanza); | 132 | free(i.stanza); |
153 | if (is_suid_plugin && idpriv_temp_restore() == -1) | 133 | if (is_suid_plugin && idpriv_temp_restore() == -1) |
154 | die(STATE_UNKNOWN, _("Cannot restore privileges: %s\n"), | 134 | die(STATE_UNKNOWN, _("Cannot restore privileges: %s\n"), strerror(errno)); |
155 | strerror(errno)); | ||
156 | 135 | ||
157 | return defaults; | 136 | return defaults; |
158 | } | 137 | } |
@@ -164,13 +143,15 @@ np_get_defaults(const char *locator, const char *default_section) | |||
164 | * be extra careful about user-supplied input (i.e. avoiding possible | 143 | * be extra careful about user-supplied input (i.e. avoiding possible |
165 | * format string vulnerabilities, etc). | 144 | * format string vulnerabilities, etc). |
166 | */ | 145 | */ |
167 | static int | 146 | static int read_defaults(FILE *f, const char *stanza, np_arg_list **opts) { |
168 | read_defaults(FILE *f, const char *stanza, np_arg_list **opts) | ||
169 | { | ||
170 | int c = 0; | 147 | int c = 0; |
171 | bool status = false; | 148 | bool status = false; |
172 | size_t i, stanza_len; | 149 | size_t i, stanza_len; |
173 | enum { NOSTANZA, WRONGSTANZA, RIGHTSTANZA } stanzastate = NOSTANZA; | 150 | enum { |
151 | NOSTANZA, | ||
152 | WRONGSTANZA, | ||
153 | RIGHTSTANZA | ||
154 | } stanzastate = NOSTANZA; | ||
174 | 155 | ||
175 | stanza_len = strlen(stanza); | 156 | stanza_len = strlen(stanza); |
176 | 157 | ||
@@ -217,8 +198,7 @@ read_defaults(FILE *f, const char *stanza, np_arg_list **opts) | |||
217 | * we're dealing with a config error | 198 | * we're dealing with a config error |
218 | */ | 199 | */ |
219 | case NOSTANZA: | 200 | case NOSTANZA: |
220 | die(STATE_UNKNOWN, "%s\n", | 201 | die(STATE_UNKNOWN, "%s\n", _("Config file error")); |
221 | _("Config file error")); | ||
222 | /* we're in a stanza, but for a different plugin */ | 202 | /* we're in a stanza, but for a different plugin */ |
223 | case WRONGSTANZA: | 203 | case WRONGSTANZA: |
224 | GOBBLE_TO(f, c, '\n'); | 204 | GOBBLE_TO(f, c, '\n'); |
@@ -227,8 +207,7 @@ read_defaults(FILE *f, const char *stanza, np_arg_list **opts) | |||
227 | case RIGHTSTANZA: | 207 | case RIGHTSTANZA: |
228 | ungetc(c, f); | 208 | ungetc(c, f); |
229 | if (add_option(f, opts)) { | 209 | if (add_option(f, opts)) { |
230 | die(STATE_UNKNOWN, "%s\n", | 210 | die(STATE_UNKNOWN, "%s\n", _("Config file error")); |
231 | _("Config file error")); | ||
232 | } | 211 | } |
233 | status = true; | 212 | status = true; |
234 | break; | 213 | break; |
@@ -246,9 +225,7 @@ read_defaults(FILE *f, const char *stanza, np_arg_list **opts) | |||
246 | * --option[=value] | 225 | * --option[=value] |
247 | * appending it to the linked list optbuf. | 226 | * appending it to the linked list optbuf. |
248 | */ | 227 | */ |
249 | static int | 228 | static int add_option(FILE *f, np_arg_list **optlst) { |
250 | add_option(FILE *f, np_arg_list **optlst) | ||
251 | { | ||
252 | np_arg_list *opttmp = *optlst, *optnew; | 229 | np_arg_list *opttmp = *optlst, *optnew; |
253 | char *linebuf = NULL, *lineend = NULL, *optptr = NULL, *optend = NULL; | 230 | char *linebuf = NULL, *lineend = NULL, *optptr = NULL, *optend = NULL; |
254 | char *eqptr = NULL, *valptr = NULL, *valend = NULL; | 231 | char *eqptr = NULL, *valptr = NULL, *valend = NULL; |
@@ -295,8 +272,7 @@ add_option(FILE *f, np_arg_list **optlst) | |||
295 | if (optptr == eqptr) | 272 | if (optptr == eqptr) |
296 | die(STATE_UNKNOWN, "%s\n", _("Config file error")); | 273 | die(STATE_UNKNOWN, "%s\n", _("Config file error")); |
297 | /* continue from '=' to start of value or EOL */ | 274 | /* continue from '=' to start of value or EOL */ |
298 | for (valptr = eqptr + 1; valptr < lineend && isspace(*valptr); | 275 | for (valptr = eqptr + 1; valptr < lineend && isspace(*valptr); valptr++) |
299 | valptr++) | ||
300 | continue; | 276 | continue; |
301 | /* continue to the end of value */ | 277 | /* continue to the end of value */ |
302 | for (valend = valptr; valend < lineend; valend++) | 278 | for (valend = valptr; valend < lineend; valend++) |
@@ -365,13 +341,10 @@ add_option(FILE *f, np_arg_list **optlst) | |||
365 | return 0; | 341 | return 0; |
366 | } | 342 | } |
367 | 343 | ||
368 | static char * | 344 | static char *default_file(void) { |
369 | default_file(void) | 345 | char *ini_file; |
370 | { | ||
371 | char *ini_file; | ||
372 | 346 | ||
373 | if ((ini_file = getenv("MP_CONFIG_FILE")) != NULL || | 347 | if ((ini_file = getenv("MP_CONFIG_FILE")) != NULL || (ini_file = default_file_in_path()) != NULL) { |
374 | (ini_file = default_file_in_path()) != NULL) { | ||
375 | return ini_file; | 348 | return ini_file; |
376 | } | 349 | } |
377 | 350 | ||
@@ -383,9 +356,7 @@ default_file(void) | |||
383 | return NULL; | 356 | return NULL; |
384 | } | 357 | } |
385 | 358 | ||
386 | static char * | 359 | static char *default_file_in_path(void) { |
387 | default_file_in_path(void) | ||
388 | { | ||
389 | char *config_path, **file; | 360 | char *config_path, **file; |
390 | char *dir, *ini_file, *tokens; | 361 | char *dir, *ini_file, *tokens; |
391 | 362 | ||
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 { | |||
19 | np_arg_list *np_get_defaults(const char *locator, const char *default_section); | 19 | np_arg_list *np_get_defaults(const char *locator, const char *default_section); |
20 | 20 | ||
21 | #endif /* _PARSE_INI_H_ */ | 21 | #endif /* _PARSE_INI_H_ */ |
22 | |||
diff --git a/lib/tests/test_base64.c b/lib/tests/test_base64.c index 05dd794..94cb5aa 100644 --- a/lib/tests/test_base64.c +++ b/lib/tests/test_base64.c | |||
@@ -1,29 +1,27 @@ | |||
1 | /***************************************************************************** | 1 | /***************************************************************************** |
2 | * | 2 | * |
3 | * This program is free software: you can redistribute it and/or modify | 3 | * This program is free software: you can redistribute it and/or modify |
4 | * it under the terms of the GNU General Public License as published by | 4 | * it under the terms of the GNU General Public License as published by |
5 | * the Free Software Foundation, either version 3 of the License, or | 5 | * the Free Software Foundation, either version 3 of the License, or |
6 | * (at your option) any later version. | 6 | * (at your option) any later version. |
7 | * | 7 | * |
8 | * This program is distributed in the hope that it will be useful, | 8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. | 11 | * GNU General Public License for more details. |
12 | * | 12 | * |
13 | * You should have received a copy of the GNU General Public License | 13 | * You should have received a copy of the GNU General Public License |
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
15 | * | 15 | * |
16 | * | 16 | * |
17 | *****************************************************************************/ | 17 | *****************************************************************************/ |
18 | 18 | ||
19 | #include "common.h" | 19 | #include "common.h" |
20 | #include "gl/base64.h" | 20 | #include "gl/base64.h" |
21 | #include "tap.h" | 21 | #include "tap.h" |
22 | 22 | ||
23 | int | 23 | int main(int argc, char **argv) { |
24 | main (int argc, char **argv) | 24 | #if 0 /* The current base64 function doesn't work on 8bit data */ |
25 | { | ||
26 | #if 0 /* The current base64 function doesn't work on 8bit data */ | ||
27 | char random[1024] = { | 25 | char random[1024] = { |
28 | 0x8b,0xb0,0xc4,0xe2,0xfc,0x22,0x9f,0x0d,0x85,0xe7,0x2c,0xaa,0x39,0xa1,0x46,0x88, | 26 | 0x8b,0xb0,0xc4,0xe2,0xfc,0x22,0x9f,0x0d,0x85,0xe7,0x2c,0xaa,0x39,0xa1,0x46,0x88, |
29 | 0x50,0xe6,0x34,0x37,0x0b,0x45,0x4b,0xb8,0xb2,0x86,0x7a,0x3e,0x7f,0x0c,0x40,0x18, | 27 | 0x50,0xe6,0x34,0x37,0x0b,0x45,0x4b,0xb8,0xb2,0x86,0x7a,0x3e,0x7f,0x0c,0x40,0x18, |
@@ -182,168 +180,124 @@ main (int argc, char **argv) | |||
182 | #endif | 180 | #endif |
183 | 181 | ||
184 | char random[1024] = { | 182 | char random[1024] = { |
185 | 0x0b,0x30,0x44,0x62,0x7c,0x22,0x1f,0x0d,0x05,0x67,0x2c,0x2a,0x39,0x21,0x46,0x08, | 183 | 0x0b, 0x30, 0x44, 0x62, 0x7c, 0x22, 0x1f, 0x0d, 0x05, 0x67, 0x2c, 0x2a, 0x39, 0x21, 0x46, 0x08, 0x50, 0x66, 0x34, 0x37, 0x0b, 0x45, |
186 | 0x50,0x66,0x34,0x37,0x0b,0x45,0x4b,0x38,0x32,0x06,0x7a,0x3e,0x7f,0x0c,0x40,0x18, | 184 | 0x4b, 0x38, 0x32, 0x06, 0x7a, 0x3e, 0x7f, 0x0c, 0x40, 0x18, 0x6b, 0x2d, 0x60, 0x4c, 0x60, 0x0c, 0x23, 0x43, 0x3b, 0x3e, 0x1b, 0x16, |
187 | 0x6b,0x2d,0x60,0x4c,0x60,0x0c,0x23,0x43,0x3b,0x3e,0x1b,0x16,0x04,0x46,0x58,0x3f, | 185 | 0x04, 0x46, 0x58, 0x3f, 0x40, 0x6a, 0x11, 0x05, 0x63, 0x71, 0x14, 0x35, 0x47, 0x79, 0x13, 0x6f, 0x6b, 0x27, 0x18, 0x5b, 0x48, 0x27, |
188 | 0x40,0x6a,0x11,0x05,0x63,0x71,0x14,0x35,0x47,0x79,0x13,0x6f,0x6b,0x27,0x18,0x5b, | 186 | 0x3e, 0x6f, 0x15, 0x33, 0x4f, 0x3e, 0x5e, 0x51, 0x73, 0x68, 0x25, 0x0f, 0x06, 0x5b, 0x7c, 0x72, 0x75, 0x3e, 0x3f, 0x1b, 0x5c, 0x6d, |
189 | 0x48,0x27,0x3e,0x6f,0x15,0x33,0x4f,0x3e,0x5e,0x51,0x73,0x68,0x25,0x0f,0x06,0x5b, | 187 | 0x6a, 0x39, 0x7c, 0x63, 0x63, 0x60, 0x6c, 0x7a, 0x33, 0x76, 0x52, 0x13, 0x25, 0x33, 0x7d, 0x65, 0x23, 0x27, 0x11, 0x06, 0x06, 0x47, |
190 | 0x7c,0x72,0x75,0x3e,0x3f,0x1b,0x5c,0x6d,0x6a,0x39,0x7c,0x63,0x63,0x60,0x6c,0x7a, | 188 | 0x71, 0x1e, 0x14, 0x74, 0x63, 0x70, 0x2d, 0x15, 0x27, 0x18, 0x51, 0x06, 0x05, 0x33, 0x11, 0x2c, 0x6b, 0x00, 0x2d, 0x77, 0x20, 0x48, |
191 | 0x33,0x76,0x52,0x13,0x25,0x33,0x7d,0x65,0x23,0x27,0x11,0x06,0x06,0x47,0x71,0x1e, | 189 | 0x0d, 0x73, 0x51, 0x45, 0x25, 0x7f, 0x7f, 0x35, 0x26, 0x2e, 0x26, 0x53, 0x24, 0x68, 0x1e, 0x0e, 0x58, 0x3a, 0x59, 0x50, 0x56, 0x37, |
192 | 0x14,0x74,0x63,0x70,0x2d,0x15,0x27,0x18,0x51,0x06,0x05,0x33,0x11,0x2c,0x6b,0x00, | 190 | 0x5f, 0x66, 0x01, 0x4c, 0x5a, 0x64, 0x32, 0x50, 0x7b, 0x6a, 0x20, 0x72, 0x2b, 0x1d, 0x7e, 0x43, 0x7b, 0x61, 0x42, 0x0b, 0x61, 0x73, |
193 | 0x2d,0x77,0x20,0x48,0x0d,0x73,0x51,0x45,0x25,0x7f,0x7f,0x35,0x26,0x2e,0x26,0x53, | 191 | 0x24, 0x79, 0x3a, 0x6b, 0x4a, 0x79, 0x6e, 0x09, 0x0f, 0x27, 0x2d, 0x0c, 0x5e, 0x32, 0x4b, 0x0d, 0x79, 0x46, 0x39, 0x21, 0x0a, 0x26, |
194 | 0x24,0x68,0x1e,0x0e,0x58,0x3a,0x59,0x50,0x56,0x37,0x5f,0x66,0x01,0x4c,0x5a,0x64, | 192 | 0x5f, 0x3a, 0x00, 0x26, 0x3f, 0x13, 0x2e, 0x7e, 0x50, 0x2b, 0x67, 0x46, 0x72, 0x3f, 0x3b, 0x01, 0x46, 0x1b, 0x0b, 0x35, 0x49, 0x39, |
195 | 0x32,0x50,0x7b,0x6a,0x20,0x72,0x2b,0x1d,0x7e,0x43,0x7b,0x61,0x42,0x0b,0x61,0x73, | 193 | 0x19, 0x70, 0x3d, 0x02, 0x41, 0x0e, 0x38, 0x05, 0x76, 0x65, 0x4f, 0x31, 0x6c, 0x5e, 0x17, 0x04, 0x15, 0x36, 0x26, 0x64, 0x34, 0x14, |
196 | 0x24,0x79,0x3a,0x6b,0x4a,0x79,0x6e,0x09,0x0f,0x27,0x2d,0x0c,0x5e,0x32,0x4b,0x0d, | 194 | 0x17, 0x7c, 0x0e, 0x0b, 0x5b, 0x55, 0x53, 0x6b, 0x00, 0x42, 0x41, 0x4f, 0x02, 0x5c, 0x13, 0x0a, 0x2c, 0x2c, 0x3e, 0x10, 0x14, 0x33, |
197 | 0x79,0x46,0x39,0x21,0x0a,0x26,0x5f,0x3a,0x00,0x26,0x3f,0x13,0x2e,0x7e,0x50,0x2b, | 195 | 0x45, 0x7c, 0x7a, 0x5a, 0x31, 0x61, 0x39, 0x08, 0x22, 0x6a, 0x1e, 0x0f, 0x6f, 0x1b, 0x6c, 0x13, 0x5e, 0x79, 0x20, 0x79, 0x50, 0x62, |
198 | 0x67,0x46,0x72,0x3f,0x3b,0x01,0x46,0x1b,0x0b,0x35,0x49,0x39,0x19,0x70,0x3d,0x02, | 196 | 0x06, 0x2c, 0x76, 0x17, 0x04, 0x2b, 0x2a, 0x75, 0x1f, 0x0c, 0x37, 0x4e, 0x0f, 0x7b, 0x2d, 0x34, 0x75, 0x60, 0x31, 0x74, 0x2e, 0x0a, |
199 | 0x41,0x0e,0x38,0x05,0x76,0x65,0x4f,0x31,0x6c,0x5e,0x17,0x04,0x15,0x36,0x26,0x64, | 197 | 0x4a, 0x11, 0x6c, 0x49, 0x25, 0x01, 0x3a, 0x3d, 0x22, 0x1e, 0x6d, 0x18, 0x51, 0x78, 0x2d, 0x62, 0x31, 0x4c, 0x50, 0x40, 0x17, 0x4b, |
200 | 0x34,0x14,0x17,0x7c,0x0e,0x0b,0x5b,0x55,0x53,0x6b,0x00,0x42,0x41,0x4f,0x02,0x5c, | 198 | 0x6f, 0x22, 0x00, 0x7f, 0x61, 0x2a, 0x34, 0x3e, 0x00, 0x5f, 0x2f, 0x5f, 0x2f, 0x14, 0x2a, 0x55, 0x27, 0x1f, 0x46, 0x1f, 0x12, 0x46, |
201 | 0x13,0x0a,0x2c,0x2c,0x3e,0x10,0x14,0x33,0x45,0x7c,0x7a,0x5a,0x31,0x61,0x39,0x08, | 199 | 0x5e, 0x1e, 0x0c, 0x7c, 0x38, 0x01, 0x61, 0x64, 0x76, 0x22, 0x6e, 0x08, 0x20, 0x38, 0x4f, 0x73, 0x72, 0x55, 0x12, 0x42, 0x19, 0x50, |
202 | 0x22,0x6a,0x1e,0x0f,0x6f,0x1b,0x6c,0x13,0x5e,0x79,0x20,0x79,0x50,0x62,0x06,0x2c, | 200 | 0x61, 0x43, 0x77, 0x7d, 0x41, 0x2e, 0x35, 0x4f, 0x3d, 0x31, 0x28, 0x58, 0x67, 0x1b, 0x03, 0x51, 0x20, 0x32, 0x1c, 0x08, 0x6e, 0x37, |
203 | 0x76,0x17,0x04,0x2b,0x2a,0x75,0x1f,0x0c,0x37,0x4e,0x0f,0x7b,0x2d,0x34,0x75,0x60, | 201 | 0x75, 0x37, 0x44, 0x4f, 0x68, 0x19, 0x07, 0x64, 0x14, 0x28, 0x25, 0x2b, 0x69, 0x35, 0x18, 0x27, 0x26, 0x14, 0x13, 0x70, 0x42, 0x19, |
204 | 0x31,0x74,0x2e,0x0a,0x4a,0x11,0x6c,0x49,0x25,0x01,0x3a,0x3d,0x22,0x1e,0x6d,0x18, | 202 | 0x12, 0x75, 0x3e, 0x02, 0x5d, 0x7c, 0x13, 0x1f, 0x16, 0x53, 0x3b, 0x74, 0x48, 0x3c, 0x5e, 0x39, 0x6c, 0x1c, 0x1c, 0x74, 0x39, 0x1f, |
205 | 0x51,0x78,0x2d,0x62,0x31,0x4c,0x50,0x40,0x17,0x4b,0x6f,0x22,0x00,0x7f,0x61,0x2a, | 203 | 0x00, 0x1b, 0x06, 0x0a, 0x68, 0x3b, 0x52, 0x4f, 0x1e, 0x6e, 0x3c, 0x35, 0x0c, 0x38, 0x0e, 0x0b, 0x3b, 0x1a, 0x76, 0x23, 0x29, 0x53, |
206 | 0x34,0x3e,0x00,0x5f,0x2f,0x5f,0x2f,0x14,0x2a,0x55,0x27,0x1f,0x46,0x1f,0x12,0x46, | 204 | 0x1e, 0x5f, 0x41, 0x0c, 0x4b, 0x0a, 0x65, 0x28, 0x78, 0x67, 0x48, 0x59, 0x26, 0x6d, 0x31, 0x76, 0x23, 0x70, 0x61, 0x64, 0x3b, 0x38, |
207 | 0x5e,0x1e,0x0c,0x7c,0x38,0x01,0x61,0x64,0x76,0x22,0x6e,0x08,0x20,0x38,0x4f,0x73, | 205 | 0x79, 0x66, 0x74, 0x53, 0x2c, 0x64, 0x64, 0x54, 0x03, 0x54, 0x65, 0x44, 0x4c, 0x18, 0x4f, 0x48, 0x20, 0x4f, 0x72, 0x10, 0x3f, 0x0c, |
208 | 0x72,0x55,0x12,0x42,0x19,0x50,0x61,0x43,0x77,0x7d,0x41,0x2e,0x35,0x4f,0x3d,0x31, | 206 | 0x52, 0x2d, 0x03, 0x14, 0x03, 0x51, 0x42, 0x10, 0x77, 0x6a, 0x34, 0x06, 0x32, 0x03, 0x72, 0x14, 0x7c, 0x08, 0x5d, 0x52, 0x1a, 0x62, |
209 | 0x28,0x58,0x67,0x1b,0x03,0x51,0x20,0x32,0x1c,0x08,0x6e,0x37,0x75,0x37,0x44,0x4f, | 207 | 0x7c, 0x3e, 0x30, 0x7e, 0x5f, 0x7f, 0x54, 0x0f, 0x44, 0x49, 0x5d, 0x5e, 0x10, 0x6a, 0x06, 0x2b, 0x06, 0x53, 0x10, 0x39, 0x37, 0x32, |
210 | 0x68,0x19,0x07,0x64,0x14,0x28,0x25,0x2b,0x69,0x35,0x18,0x27,0x26,0x14,0x13,0x70, | 208 | 0x4a, 0x4e, 0x3d, 0x2b, 0x65, 0x38, 0x39, 0x07, 0x72, 0x54, 0x64, 0x4d, 0x56, 0x6a, 0x03, 0x22, 0x70, 0x7b, 0x5f, 0x60, 0x0b, 0x2a, |
211 | 0x42,0x19,0x12,0x75,0x3e,0x02,0x5d,0x7c,0x13,0x1f,0x16,0x53,0x3b,0x74,0x48,0x3c, | 209 | 0x0b, 0x6b, 0x10, 0x64, 0x14, 0x05, 0x22, 0x00, 0x73, 0x40, 0x23, 0x5b, 0x51, 0x1f, 0x2b, 0x1a, 0x5d, 0x69, 0x7a, 0x46, 0x0c, 0x5f, |
212 | 0x5e,0x39,0x6c,0x1c,0x1c,0x74,0x39,0x1f,0x00,0x1b,0x06,0x0a,0x68,0x3b,0x52,0x4f, | 210 | 0x32, 0x4b, 0x4a, 0x28, 0x52, 0x79, 0x5b, 0x12, 0x42, 0x18, 0x00, 0x5d, 0x27, 0x31, 0x53, 0x3c, 0x4c, 0x36, 0x4e, 0x38, 0x3f, 0x72, |
213 | 0x1e,0x6e,0x3c,0x35,0x0c,0x38,0x0e,0x0b,0x3b,0x1a,0x76,0x23,0x29,0x53,0x1e,0x5f, | 211 | 0x03, 0x71, 0x02, 0x5b, 0x36, 0x59, 0x7f, 0x75, 0x6e, 0x08, 0x54, 0x0d, 0x34, 0x1c, 0x34, 0x57, 0x5d, 0x69, 0x48, 0x00, 0x3b, 0x05, |
214 | 0x41,0x0c,0x4b,0x0a,0x65,0x28,0x78,0x67,0x48,0x59,0x26,0x6d,0x31,0x76,0x23,0x70, | 212 | 0x07, 0x6e, 0x27, 0x65, 0x6e, 0x40, 0x3d, 0x3a, 0x4f, 0x72, 0x5d, 0x39, 0x16, 0x0f, 0x63, 0x12, 0x12, 0x15, 0x3a, 0x70, 0x0d, 0x57, |
215 | 0x61,0x64,0x3b,0x38,0x79,0x66,0x74,0x53,0x2c,0x64,0x64,0x54,0x03,0x54,0x65,0x44, | 213 | 0x18, 0x0d, 0x5e, 0x3d, 0x22, 0x68, 0x68, 0x7c, 0x6d, 0x4f, 0x0c, 0x7b, 0x09, 0x2d, 0x4a, 0x73, 0x20, 0x47, 0x07, 0x57, 0x75, 0x5d, |
216 | 0x4c,0x18,0x4f,0x48,0x20,0x4f,0x72,0x10,0x3f,0x0c,0x52,0x2d,0x03,0x14,0x03,0x51, | 214 | 0x53, 0x70, 0x34, 0x21, 0x40, 0x57, 0x51, 0x5e, 0x49, 0x44, 0x00, 0x54, 0x27, 0x04, 0x68, 0x7e, 0x59, 0x56, 0x58, 0x74, 0x14, 0x3c, |
217 | 0x42,0x10,0x77,0x6a,0x34,0x06,0x32,0x03,0x72,0x14,0x7c,0x08,0x5d,0x52,0x1a,0x62, | 215 | 0x16, 0x33, 0x41, 0x16, 0x4b, 0x2f, 0x49, 0x37, 0x0a, 0x54, 0x08, 0x08, 0x1f, 0x39, 0x67, 0x76, 0x28, 0x28, 0x07, 0x1d, 0x61, 0x47, |
218 | 0x7c,0x3e,0x30,0x7e,0x5f,0x7f,0x54,0x0f,0x44,0x49,0x5d,0x5e,0x10,0x6a,0x06,0x2b, | 216 | 0x51, 0x4d, 0x75, 0x26, 0x52, 0x47, 0x47, 0x0c, 0x57, 0x58, 0x74, 0x3e, 0x62, 0x6c, 0x58, 0x3a, 0x44, 0x1e, 0x16, 0x2e, 0x21, 0x1c, |
219 | 0x06,0x53,0x10,0x39,0x37,0x32,0x4a,0x4e,0x3d,0x2b,0x65,0x38,0x39,0x07,0x72,0x54, | 217 | 0x73, 0x45, 0x67, 0x74, 0x4f, 0x33, 0x66, 0x0e, 0x74, 0x66, 0x26, 0x1f, 0x2e, 0x38, 0x44, 0x40, 0x7e, 0x2a, 0x50, 0x52, 0x5e, 0x43, |
220 | 0x64,0x4d,0x56,0x6a,0x03,0x22,0x70,0x7b,0x5f,0x60,0x0b,0x2a,0x0b,0x6b,0x10,0x64, | 218 | 0x01, 0x7a, 0x38, 0x49, 0x3c, 0x55, 0x4d, 0x5a, 0x44, 0x08, 0x26, 0x59, 0x4d, 0x45, 0x0b, 0x48, 0x0a, 0x33, 0x5e, 0x4a, 0x4d, 0x75, |
221 | 0x14,0x05,0x22,0x00,0x73,0x40,0x23,0x5b,0x51,0x1f,0x2b,0x1a,0x5d,0x69,0x7a,0x46, | 219 | 0x16, 0x17, 0x63, 0x46, 0x01, 0x2a, 0x55, 0x7b, 0x0f, 0x02, 0x73, 0x6a, 0x4b, 0x7f, 0x75, 0x65, 0x3c, 0x4c, 0x33, 0x39, 0x6c, 0x74, |
222 | 0x0c,0x5f,0x32,0x4b,0x4a,0x28,0x52,0x79,0x5b,0x12,0x42,0x18,0x00,0x5d,0x27,0x31, | 220 | 0x05, 0x60, 0x0f, 0x7f, 0x2d, 0x41, 0x4d, 0x4d, 0x46, 0x71, 0x09, 0x6f, 0x4f, 0x60, 0x15, 0x0f, 0x46, 0x73, 0x63, 0x4c, 0x5e, 0x74, |
223 | 0x53,0x3c,0x4c,0x36,0x4e,0x38,0x3f,0x72,0x03,0x71,0x02,0x5b,0x36,0x59,0x7f,0x75, | 221 | 0x30, 0x0d, 0x28, 0x43, 0x08, 0x72, 0x32, 0x04, 0x2e, 0x31, 0x29, 0x27, 0x44, 0x6d, 0x13, 0x17, 0x48, 0x0f, 0x49, 0x52, 0x10, 0x13, |
224 | 0x6e,0x08,0x54,0x0d,0x34,0x1c,0x34,0x57,0x5d,0x69,0x48,0x00,0x3b,0x05,0x07,0x6e, | 222 | 0x7f, 0x17, 0x16, 0x62, 0x79, 0x35, 0x78, 0x3e, 0x01, 0x7c, 0x2e, 0x0f, 0x76, 0x3e, 0x5e, 0x53, 0x6c, 0x5b, 0x5f, 0x7c, 0x19, 0x41, |
225 | 0x27,0x65,0x6e,0x40,0x3d,0x3a,0x4f,0x72,0x5d,0x39,0x16,0x0f,0x63,0x12,0x12,0x15, | 223 | 0x02, 0x2f, 0x17, 0x64, 0x41, 0x75, 0x10, 0x04, 0x47, 0x7c, 0x3d, 0x4b, 0x52, 0x00, 0x10, 0x5d, 0x51, 0x4e, 0x7a, 0x27, 0x25, 0x55, |
226 | 0x3a,0x70,0x0d,0x57,0x18,0x0d,0x5e,0x3d,0x22,0x68,0x68,0x7c,0x6d,0x4f,0x0c,0x7b, | 224 | 0x40, 0x12, 0x35, 0x60, 0x05, 0x1b, 0x34, 0x2d, 0x04, 0x7a, 0x6a, 0x69, 0x02, 0x79, 0x03, 0x3a, 0x2f, 0x06, 0x0a, 0x79, 0x7b, 0x12, |
227 | 0x09,0x2d,0x4a,0x73,0x20,0x47,0x07,0x57,0x75,0x5d,0x53,0x70,0x34,0x21,0x40,0x57, | 225 | 0x5d, 0x7c, 0x52, 0x29, 0x47, 0x58, 0x12, 0x73, 0x3f, 0x27, 0x56, 0x05, 0x0c, 0x48, 0x32, 0x58, 0x6b, 0x57, 0x5c, 0x03, 0x64, 0x56, |
228 | 0x51,0x5e,0x49,0x44,0x00,0x54,0x27,0x04,0x68,0x7e,0x59,0x56,0x58,0x74,0x14,0x3c, | 226 | 0x11, 0x52, 0x7a, 0x30, 0x36, 0x29, 0x17, 0x3b, 0x68, 0x7a, 0x7c, 0x05, 0x6b, 0x6b, 0x13, 0x6a, 0x24, 0x5c, 0x68, 0x42, 0x18, 0x32, |
229 | 0x16,0x33,0x41,0x16,0x4b,0x2f,0x49,0x37,0x0a,0x54,0x08,0x08,0x1f,0x39,0x67,0x76, | 227 | 0x03, 0x73, 0x6e, 0x04, 0x21, 0x2e, 0x01, 0x04, 0x63, 0x7d, 0x44, 0x41, 0x12, 0x31, 0x0b, 0x15, 0x1f, 0x70, 0x00, 0x2e, 0x66, 0x14, |
230 | 0x28,0x28,0x07,0x1d,0x61,0x47,0x51,0x4d,0x75,0x26,0x52,0x47,0x47,0x0c,0x57,0x58, | 228 | 0x3c, 0x7f, 0x2b, 0x00, 0x1f, 0x0c, 0x28, 0x59, 0x0a, 0x16, 0x49, 0x5a, 0x5c, 0x64, 0x65, 0x4b, 0x11, 0x29, 0x15, 0x36, 0x5a, 0x65, |
231 | 0x74,0x3e,0x62,0x6c,0x58,0x3a,0x44,0x1e,0x16,0x2e,0x21,0x1c,0x73,0x45,0x67,0x74, | 229 | 0x19, 0x4f, 0x60, 0x23, 0x3a, 0x3a, 0x13, 0x25, 0x02, 0x78, 0x4c, 0x54}; |
232 | 0x4f,0x33,0x66,0x0e,0x74,0x66,0x26,0x1f,0x2e,0x38,0x44,0x40,0x7e,0x2a,0x50,0x52, | 230 | char b64_known[1369] = { |
233 | 0x5e,0x43,0x01,0x7a,0x38,0x49,0x3c,0x55,0x4d,0x5a,0x44,0x08,0x26,0x59,0x4d,0x45, | 231 | 0x43, 0x7a, 0x42, 0x45, 0x59, 0x6e, 0x77, 0x69, 0x48, 0x77, 0x30, 0x46, 0x5a, 0x79, 0x77, 0x71, 0x4f, 0x53, 0x46, 0x47, 0x43, 0x46, |
234 | 0x0b,0x48,0x0a,0x33,0x5e,0x4a,0x4d,0x75,0x16,0x17,0x63,0x46,0x01,0x2a,0x55,0x7b, | 232 | 0x42, 0x6d, 0x4e, 0x44, 0x63, 0x4c, 0x52, 0x55, 0x73, 0x34, 0x4d, 0x67, 0x5a, 0x36, 0x50, 0x6e, 0x38, 0x4d, 0x51, 0x42, 0x68, 0x72, |
235 | 0x0f,0x02,0x73,0x6a,0x4b,0x7f,0x75,0x65,0x3c,0x4c,0x33,0x39,0x6c,0x74,0x05,0x60, | 233 | 0x4c, 0x57, 0x42, 0x4d, 0x59, 0x41, 0x77, 0x6a, 0x51, 0x7a, 0x73, 0x2b, 0x47, 0x78, 0x59, 0x45, 0x52, 0x6c, 0x67, 0x2f, 0x51, 0x47, |
236 | 0x0f,0x7f,0x2d,0x41,0x4d,0x4d,0x46,0x71,0x09,0x6f,0x4f,0x60,0x15,0x0f,0x46,0x73, | 234 | 0x6f, 0x52, 0x42, 0x57, 0x4e, 0x78, 0x46, 0x44, 0x56, 0x48, 0x65, 0x52, 0x4e, 0x76, 0x61, 0x79, 0x63, 0x59, 0x57, 0x30, 0x67, 0x6e, |
237 | 0x63,0x4c,0x5e,0x74,0x30,0x0d,0x28,0x43,0x08,0x72,0x32,0x04,0x2e,0x31,0x29,0x27, | 235 | 0x50, 0x6d, 0x38, 0x56, 0x4d, 0x30, 0x38, 0x2b, 0x58, 0x6c, 0x46, 0x7a, 0x61, 0x43, 0x55, 0x50, 0x42, 0x6c, 0x74, 0x38, 0x63, 0x6e, |
238 | 0x44,0x6d,0x13,0x17,0x48,0x0f,0x49,0x52,0x10,0x13,0x7f,0x17,0x16,0x62,0x79,0x35, | 236 | 0x55, 0x2b, 0x50, 0x78, 0x74, 0x63, 0x62, 0x57, 0x6f, 0x35, 0x66, 0x47, 0x4e, 0x6a, 0x59, 0x47, 0x78, 0x36, 0x4d, 0x33, 0x5a, 0x53, |
239 | 0x78,0x3e,0x01,0x7c,0x2e,0x0f,0x76,0x3e,0x5e,0x53,0x6c,0x5b,0x5f,0x7c,0x19,0x41, | 237 | 0x45, 0x79, 0x55, 0x7a, 0x66, 0x57, 0x55, 0x6a, 0x4a, 0x78, 0x45, 0x47, 0x42, 0x6b, 0x64, 0x78, 0x48, 0x68, 0x52, 0x30, 0x59, 0x33, |
240 | 0x02,0x2f,0x17,0x64,0x41,0x75,0x10,0x04,0x47,0x7c,0x3d,0x4b,0x52,0x00,0x10,0x5d, | 238 | 0x41, 0x74, 0x46, 0x53, 0x63, 0x59, 0x55, 0x51, 0x59, 0x46, 0x4d, 0x78, 0x45, 0x73, 0x61, 0x77, 0x41, 0x74, 0x64, 0x79, 0x42, 0x49, |
241 | 0x51,0x4e,0x7a,0x27,0x25,0x55,0x40,0x12,0x35,0x60,0x05,0x1b,0x34,0x2d,0x04,0x7a, | 239 | 0x44, 0x58, 0x4e, 0x52, 0x52, 0x53, 0x56, 0x2f, 0x66, 0x7a, 0x55, 0x6d, 0x4c, 0x69, 0x5a, 0x54, 0x4a, 0x47, 0x67, 0x65, 0x44, 0x6c, |
242 | 0x6a,0x69,0x02,0x79,0x03,0x3a,0x2f,0x06,0x0a,0x79,0x7b,0x12,0x5d,0x7c,0x52,0x29, | 240 | 0x67, 0x36, 0x57, 0x56, 0x42, 0x57, 0x4e, 0x31, 0x39, 0x6d, 0x41, 0x55, 0x78, 0x61, 0x5a, 0x44, 0x4a, 0x51, 0x65, 0x32, 0x6f, 0x67, |
243 | 0x47,0x58,0x12,0x73,0x3f,0x27,0x56,0x05,0x0c,0x48,0x32,0x58,0x6b,0x57,0x5c,0x03, | 241 | 0x63, 0x69, 0x73, 0x64, 0x66, 0x6b, 0x4e, 0x37, 0x59, 0x55, 0x49, 0x4c, 0x59, 0x58, 0x4d, 0x6b, 0x65, 0x54, 0x70, 0x72, 0x53, 0x6e, |
244 | 0x64,0x56,0x11,0x52,0x7a,0x30,0x36,0x29,0x17,0x3b,0x68,0x7a,0x7c,0x05,0x6b,0x6b, | 242 | 0x6c, 0x75, 0x43, 0x51, 0x38, 0x6e, 0x4c, 0x51, 0x78, 0x65, 0x4d, 0x6b, 0x73, 0x4e, 0x65, 0x55, 0x59, 0x35, 0x49, 0x51, 0x6f, 0x6d, |
245 | 0x13,0x6a,0x24,0x5c,0x68,0x42,0x18,0x32,0x03,0x73,0x6e,0x04,0x21,0x2e,0x01,0x04, | 243 | 0x58, 0x7a, 0x6f, 0x41, 0x4a, 0x6a, 0x38, 0x54, 0x4c, 0x6e, 0x35, 0x51, 0x4b, 0x32, 0x64, 0x47, 0x63, 0x6a, 0x38, 0x37, 0x41, 0x55, |
246 | 0x63,0x7d,0x44,0x41,0x12,0x31,0x0b,0x15,0x1f,0x70,0x00,0x2e,0x66,0x14,0x3c,0x7f, | 244 | 0x59, 0x62, 0x43, 0x7a, 0x56, 0x4a, 0x4f, 0x52, 0x6c, 0x77, 0x50, 0x51, 0x4a, 0x42, 0x44, 0x6a, 0x67, 0x46, 0x64, 0x6d, 0x56, 0x50, |
247 | 0x2b,0x00,0x1f,0x0c,0x28,0x59,0x0a,0x16,0x49,0x5a,0x5c,0x64,0x65,0x4b,0x11,0x29, | 245 | 0x4d, 0x57, 0x78, 0x65, 0x46, 0x77, 0x51, 0x56, 0x4e, 0x69, 0x5a, 0x6b, 0x4e, 0x42, 0x51, 0x58, 0x66, 0x41, 0x34, 0x4c, 0x57, 0x31, |
248 | 0x15,0x36,0x5a,0x65,0x19,0x4f,0x60,0x23,0x3a,0x3a,0x13,0x25,0x02,0x78,0x4c,0x54 | 246 | 0x56, 0x54, 0x61, 0x77, 0x42, 0x43, 0x51, 0x55, 0x38, 0x43, 0x58, 0x42, 0x4d, 0x4b, 0x4c, 0x43, 0x77, 0x2b, 0x45, 0x42, 0x51, 0x7a, |
249 | }; | 247 | 0x52, 0x58, 0x78, 0x36, 0x57, 0x6a, 0x46, 0x68, 0x4f, 0x51, 0x67, 0x69, 0x61, 0x68, 0x34, 0x50, 0x62, 0x78, 0x74, 0x73, 0x45, 0x31, |
250 | char b64_known[1369] = { | 248 | 0x35, 0x35, 0x49, 0x48, 0x6c, 0x51, 0x59, 0x67, 0x59, 0x73, 0x64, 0x68, 0x63, 0x45, 0x4b, 0x79, 0x70, 0x31, 0x48, 0x77, 0x77, 0x33, |
251 | 0x43,0x7a,0x42,0x45,0x59,0x6e,0x77,0x69,0x48,0x77,0x30,0x46,0x5a,0x79,0x77,0x71, | 249 | 0x54, 0x67, 0x39, 0x37, 0x4c, 0x54, 0x52, 0x31, 0x59, 0x44, 0x46, 0x30, 0x4c, 0x67, 0x70, 0x4b, 0x45, 0x57, 0x78, 0x4a, 0x4a, 0x51, |
252 | 0x4f,0x53,0x46,0x47,0x43,0x46,0x42,0x6d,0x4e,0x44,0x63,0x4c,0x52,0x55,0x73,0x34, | 250 | 0x45, 0x36, 0x50, 0x53, 0x49, 0x65, 0x62, 0x52, 0x68, 0x52, 0x65, 0x43, 0x31, 0x69, 0x4d, 0x55, 0x78, 0x51, 0x51, 0x42, 0x64, 0x4c, |
253 | 0x4d,0x67,0x5a,0x36,0x50,0x6e,0x38,0x4d,0x51,0x42,0x68,0x72,0x4c,0x57,0x42,0x4d, | 251 | 0x62, 0x79, 0x49, 0x41, 0x66, 0x32, 0x45, 0x71, 0x4e, 0x44, 0x34, 0x41, 0x58, 0x79, 0x39, 0x66, 0x4c, 0x78, 0x51, 0x71, 0x56, 0x53, |
254 | 0x59,0x41,0x77,0x6a,0x51,0x7a,0x73,0x2b,0x47,0x78,0x59,0x45,0x52,0x6c,0x67,0x2f, | 252 | 0x63, 0x66, 0x52, 0x68, 0x38, 0x53, 0x52, 0x6c, 0x34, 0x65, 0x44, 0x48, 0x77, 0x34, 0x41, 0x57, 0x46, 0x6b, 0x64, 0x69, 0x4a, 0x75, |
255 | 0x51,0x47,0x6f,0x52,0x42,0x57,0x4e,0x78,0x46,0x44,0x56,0x48,0x65,0x52,0x4e,0x76, | 253 | 0x43, 0x43, 0x41, 0x34, 0x54, 0x33, 0x4e, 0x79, 0x56, 0x52, 0x4a, 0x43, 0x47, 0x56, 0x42, 0x68, 0x51, 0x33, 0x64, 0x39, 0x51, 0x53, |
256 | 0x61,0x79,0x63,0x59,0x57,0x30,0x67,0x6e,0x50,0x6d,0x38,0x56,0x4d,0x30,0x38,0x2b, | 254 | 0x34, 0x31, 0x54, 0x7a, 0x30, 0x78, 0x4b, 0x46, 0x68, 0x6e, 0x47, 0x77, 0x4e, 0x52, 0x49, 0x44, 0x49, 0x63, 0x43, 0x47, 0x34, 0x33, |
257 | 0x58,0x6c,0x46,0x7a,0x61,0x43,0x55,0x50,0x42,0x6c,0x74,0x38,0x63,0x6e,0x55,0x2b, | 255 | 0x64, 0x54, 0x64, 0x45, 0x54, 0x32, 0x67, 0x5a, 0x42, 0x32, 0x51, 0x55, 0x4b, 0x43, 0x55, 0x72, 0x61, 0x54, 0x55, 0x59, 0x4a, 0x79, |
258 | 0x50,0x78,0x74,0x63,0x62,0x57,0x6f,0x35,0x66,0x47,0x4e,0x6a,0x59,0x47,0x78,0x36, | 256 | 0x59, 0x55, 0x45, 0x33, 0x42, 0x43, 0x47, 0x52, 0x4a, 0x31, 0x50, 0x67, 0x4a, 0x64, 0x66, 0x42, 0x4d, 0x66, 0x46, 0x6c, 0x4d, 0x37, |
259 | 0x4d,0x33,0x5a,0x53,0x45,0x79,0x55,0x7a,0x66,0x57,0x55,0x6a,0x4a,0x78,0x45,0x47, | 257 | 0x64, 0x45, 0x67, 0x38, 0x58, 0x6a, 0x6c, 0x73, 0x48, 0x42, 0x78, 0x30, 0x4f, 0x52, 0x38, 0x41, 0x47, 0x77, 0x59, 0x4b, 0x61, 0x44, |
260 | 0x42,0x6b,0x64,0x78,0x48,0x68,0x52,0x30,0x59,0x33,0x41,0x74,0x46,0x53,0x63,0x59, | 258 | 0x74, 0x53, 0x54, 0x78, 0x35, 0x75, 0x50, 0x44, 0x55, 0x4d, 0x4f, 0x41, 0x34, 0x4c, 0x4f, 0x78, 0x70, 0x32, 0x49, 0x79, 0x6c, 0x54, |
261 | 0x55,0x51,0x59,0x46,0x4d,0x78,0x45,0x73,0x61,0x77,0x41,0x74,0x64,0x79,0x42,0x49, | 259 | 0x48, 0x6c, 0x39, 0x42, 0x44, 0x45, 0x73, 0x4b, 0x5a, 0x53, 0x68, 0x34, 0x5a, 0x30, 0x68, 0x5a, 0x4a, 0x6d, 0x30, 0x78, 0x64, 0x69, |
262 | 0x44,0x58,0x4e,0x52,0x52,0x53,0x56,0x2f,0x66,0x7a,0x55,0x6d,0x4c,0x69,0x5a,0x54, | 260 | 0x4e, 0x77, 0x59, 0x57, 0x51, 0x37, 0x4f, 0x48, 0x6c, 0x6d, 0x64, 0x46, 0x4d, 0x73, 0x5a, 0x47, 0x52, 0x55, 0x41, 0x31, 0x52, 0x6c, |
263 | 0x4a,0x47,0x67,0x65,0x44,0x6c,0x67,0x36,0x57,0x56,0x42,0x57,0x4e,0x31,0x39,0x6d, | 261 | 0x52, 0x45, 0x77, 0x59, 0x54, 0x30, 0x67, 0x67, 0x54, 0x33, 0x49, 0x51, 0x50, 0x77, 0x78, 0x53, 0x4c, 0x51, 0x4d, 0x55, 0x41, 0x31, |
264 | 0x41,0x55,0x78,0x61,0x5a,0x44,0x4a,0x51,0x65,0x32,0x6f,0x67,0x63,0x69,0x73,0x64, | 262 | 0x46, 0x43, 0x45, 0x48, 0x64, 0x71, 0x4e, 0x41, 0x59, 0x79, 0x41, 0x33, 0x49, 0x55, 0x66, 0x41, 0x68, 0x64, 0x55, 0x68, 0x70, 0x69, |
265 | 0x66,0x6b,0x4e,0x37,0x59,0x55,0x49,0x4c,0x59,0x58,0x4d,0x6b,0x65,0x54,0x70,0x72, | 263 | 0x66, 0x44, 0x34, 0x77, 0x66, 0x6c, 0x39, 0x2f, 0x56, 0x41, 0x39, 0x45, 0x53, 0x56, 0x31, 0x65, 0x45, 0x47, 0x6f, 0x47, 0x4b, 0x77, |
266 | 0x53,0x6e,0x6c,0x75,0x43,0x51,0x38,0x6e,0x4c,0x51,0x78,0x65,0x4d,0x6b,0x73,0x4e, | 264 | 0x5a, 0x54, 0x45, 0x44, 0x6b, 0x33, 0x4d, 0x6b, 0x70, 0x4f, 0x50, 0x53, 0x74, 0x6c, 0x4f, 0x44, 0x6b, 0x48, 0x63, 0x6c, 0x52, 0x6b, |
267 | 0x65,0x55,0x59,0x35,0x49,0x51,0x6f,0x6d,0x58,0x7a,0x6f,0x41,0x4a,0x6a,0x38,0x54, | 265 | 0x54, 0x56, 0x5a, 0x71, 0x41, 0x79, 0x4a, 0x77, 0x65, 0x31, 0x39, 0x67, 0x43, 0x79, 0x6f, 0x4c, 0x61, 0x78, 0x42, 0x6b, 0x46, 0x41, |
268 | 0x4c,0x6e,0x35,0x51,0x4b,0x32,0x64,0x47,0x63,0x6a,0x38,0x37,0x41,0x55,0x59,0x62, | 266 | 0x55, 0x69, 0x41, 0x48, 0x4e, 0x41, 0x49, 0x31, 0x74, 0x52, 0x48, 0x79, 0x73, 0x61, 0x58, 0x57, 0x6c, 0x36, 0x52, 0x67, 0x78, 0x66, |
269 | 0x43,0x7a,0x56,0x4a,0x4f,0x52,0x6c,0x77,0x50,0x51,0x4a,0x42,0x44,0x6a,0x67,0x46, | 267 | 0x4d, 0x6b, 0x74, 0x4b, 0x4b, 0x46, 0x4a, 0x35, 0x57, 0x78, 0x4a, 0x43, 0x47, 0x41, 0x42, 0x64, 0x4a, 0x7a, 0x46, 0x54, 0x50, 0x45, |
270 | 0x64,0x6d,0x56,0x50,0x4d,0x57,0x78,0x65,0x46,0x77,0x51,0x56,0x4e,0x69,0x5a,0x6b, | 268 | 0x77, 0x32, 0x54, 0x6a, 0x67, 0x2f, 0x63, 0x67, 0x4e, 0x78, 0x41, 0x6c, 0x73, 0x32, 0x57, 0x58, 0x39, 0x31, 0x62, 0x67, 0x68, 0x55, |
271 | 0x4e,0x42,0x51,0x58,0x66,0x41,0x34,0x4c,0x57,0x31,0x56,0x54,0x61,0x77,0x42,0x43, | 269 | 0x44, 0x54, 0x51, 0x63, 0x4e, 0x46, 0x64, 0x64, 0x61, 0x55, 0x67, 0x41, 0x4f, 0x77, 0x55, 0x48, 0x62, 0x69, 0x64, 0x6c, 0x62, 0x6b, |
272 | 0x51,0x55,0x38,0x43,0x58,0x42,0x4d,0x4b,0x4c,0x43,0x77,0x2b,0x45,0x42,0x51,0x7a, | 270 | 0x41, 0x39, 0x4f, 0x6b, 0x39, 0x79, 0x58, 0x54, 0x6b, 0x57, 0x44, 0x32, 0x4d, 0x53, 0x45, 0x68, 0x55, 0x36, 0x63, 0x41, 0x31, 0x58, |
273 | 0x52,0x58,0x78,0x36,0x57,0x6a,0x46,0x68,0x4f,0x51,0x67,0x69,0x61,0x68,0x34,0x50, | 271 | 0x47, 0x41, 0x31, 0x65, 0x50, 0x53, 0x4a, 0x6f, 0x61, 0x48, 0x78, 0x74, 0x54, 0x77, 0x78, 0x37, 0x43, 0x53, 0x31, 0x4b, 0x63, 0x79, |
274 | 0x62,0x78,0x74,0x73,0x45,0x31,0x35,0x35,0x49,0x48,0x6c,0x51,0x59,0x67,0x59,0x73, | 272 | 0x42, 0x48, 0x42, 0x31, 0x64, 0x31, 0x58, 0x56, 0x4e, 0x77, 0x4e, 0x43, 0x46, 0x41, 0x56, 0x31, 0x46, 0x65, 0x53, 0x55, 0x51, 0x41, |
275 | 0x64,0x68,0x63,0x45,0x4b,0x79,0x70,0x31,0x48,0x77,0x77,0x33,0x54,0x67,0x39,0x37, | 273 | 0x56, 0x43, 0x63, 0x45, 0x61, 0x48, 0x35, 0x5a, 0x56, 0x6c, 0x68, 0x30, 0x46, 0x44, 0x77, 0x57, 0x4d, 0x30, 0x45, 0x57, 0x53, 0x79, |
276 | 0x4c,0x54,0x52,0x31,0x59,0x44,0x46,0x30,0x4c,0x67,0x70,0x4b,0x45,0x57,0x78,0x4a, | 274 | 0x39, 0x4a, 0x4e, 0x77, 0x70, 0x55, 0x43, 0x41, 0x67, 0x66, 0x4f, 0x57, 0x64, 0x32, 0x4b, 0x43, 0x67, 0x48, 0x48, 0x57, 0x46, 0x48, |
277 | 0x4a,0x51,0x45,0x36,0x50,0x53,0x49,0x65,0x62,0x52,0x68,0x52,0x65,0x43,0x31,0x69, | 275 | 0x55, 0x55, 0x31, 0x31, 0x4a, 0x6c, 0x4a, 0x48, 0x52, 0x77, 0x78, 0x58, 0x57, 0x48, 0x51, 0x2b, 0x59, 0x6d, 0x78, 0x59, 0x4f, 0x6b, |
278 | 0x4d,0x55,0x78,0x51,0x51,0x42,0x64,0x4c,0x62,0x79,0x49,0x41,0x66,0x32,0x45,0x71, | 276 | 0x51, 0x65, 0x46, 0x69, 0x34, 0x68, 0x48, 0x48, 0x4e, 0x46, 0x5a, 0x33, 0x52, 0x50, 0x4d, 0x32, 0x59, 0x4f, 0x64, 0x47, 0x59, 0x6d, |
279 | 0x4e,0x44,0x34,0x41,0x58,0x79,0x39,0x66,0x4c,0x78,0x51,0x71,0x56,0x53,0x63,0x66, | 277 | 0x48, 0x79, 0x34, 0x34, 0x52, 0x45, 0x42, 0x2b, 0x4b, 0x6c, 0x42, 0x53, 0x58, 0x6b, 0x4d, 0x42, 0x65, 0x6a, 0x68, 0x4a, 0x50, 0x46, |
280 | 0x52,0x68,0x38,0x53,0x52,0x6c,0x34,0x65,0x44,0x48,0x77,0x34,0x41,0x57,0x46,0x6b, | 278 | 0x56, 0x4e, 0x57, 0x6b, 0x51, 0x49, 0x4a, 0x6c, 0x6c, 0x4e, 0x52, 0x51, 0x74, 0x49, 0x43, 0x6a, 0x4e, 0x65, 0x53, 0x6b, 0x31, 0x31, |
281 | 0x64,0x69,0x4a,0x75,0x43,0x43,0x41,0x34,0x54,0x33,0x4e,0x79,0x56,0x52,0x4a,0x43, | 279 | 0x46, 0x68, 0x64, 0x6a, 0x52, 0x67, 0x45, 0x71, 0x56, 0x58, 0x73, 0x50, 0x41, 0x6e, 0x4e, 0x71, 0x53, 0x33, 0x39, 0x31, 0x5a, 0x54, |
282 | 0x47,0x56,0x42,0x68,0x51,0x33,0x64,0x39,0x51,0x53,0x34,0x31,0x54,0x7a,0x30,0x78, | 280 | 0x78, 0x4d, 0x4d, 0x7a, 0x6c, 0x73, 0x64, 0x41, 0x56, 0x67, 0x44, 0x33, 0x38, 0x74, 0x51, 0x55, 0x31, 0x4e, 0x52, 0x6e, 0x45, 0x4a, |
283 | 0x4b,0x46,0x68,0x6e,0x47,0x77,0x4e,0x52,0x49,0x44,0x49,0x63,0x43,0x47,0x34,0x33, | 281 | 0x62, 0x30, 0x39, 0x67, 0x46, 0x51, 0x39, 0x47, 0x63, 0x32, 0x4e, 0x4d, 0x58, 0x6e, 0x51, 0x77, 0x44, 0x53, 0x68, 0x44, 0x43, 0x48, |
284 | 0x64,0x54,0x64,0x45,0x54,0x32,0x67,0x5a,0x42,0x32,0x51,0x55,0x4b,0x43,0x55,0x72, | 282 | 0x49, 0x79, 0x42, 0x43, 0x34, 0x78, 0x4b, 0x53, 0x64, 0x45, 0x62, 0x52, 0x4d, 0x58, 0x53, 0x41, 0x39, 0x4a, 0x55, 0x68, 0x41, 0x54, |
285 | 0x61,0x54,0x55,0x59,0x4a,0x79,0x59,0x55,0x45,0x33,0x42,0x43,0x47,0x52,0x4a,0x31, | 283 | 0x66, 0x78, 0x63, 0x57, 0x59, 0x6e, 0x6b, 0x31, 0x65, 0x44, 0x34, 0x42, 0x66, 0x43, 0x34, 0x50, 0x64, 0x6a, 0x35, 0x65, 0x55, 0x32, |
286 | 0x50,0x67,0x4a,0x64,0x66,0x42,0x4d,0x66,0x46,0x6c,0x4d,0x37,0x64,0x45,0x67,0x38, | 284 | 0x78, 0x62, 0x58, 0x33, 0x77, 0x5a, 0x51, 0x51, 0x49, 0x76, 0x46, 0x32, 0x52, 0x42, 0x64, 0x52, 0x41, 0x45, 0x52, 0x33, 0x77, 0x39, |
287 | 0x58,0x6a,0x6c,0x73,0x48,0x42,0x78,0x30,0x4f,0x52,0x38,0x41,0x47,0x77,0x59,0x4b, | 285 | 0x53, 0x31, 0x49, 0x41, 0x45, 0x46, 0x31, 0x52, 0x54, 0x6e, 0x6f, 0x6e, 0x4a, 0x56, 0x56, 0x41, 0x45, 0x6a, 0x56, 0x67, 0x42, 0x52, |
288 | 0x61,0x44,0x74,0x53,0x54,0x78,0x35,0x75,0x50,0x44,0x55,0x4d,0x4f,0x41,0x34,0x4c, | 286 | 0x73, 0x30, 0x4c, 0x51, 0x52, 0x36, 0x61, 0x6d, 0x6b, 0x43, 0x65, 0x51, 0x4d, 0x36, 0x4c, 0x77, 0x59, 0x4b, 0x65, 0x58, 0x73, 0x53, |
289 | 0x4f,0x78,0x70,0x32,0x49,0x79,0x6c,0x54,0x48,0x6c,0x39,0x42,0x44,0x45,0x73,0x4b, | 287 | 0x58, 0x58, 0x78, 0x53, 0x4b, 0x55, 0x64, 0x59, 0x45, 0x6e, 0x4d, 0x2f, 0x4a, 0x31, 0x59, 0x46, 0x44, 0x45, 0x67, 0x79, 0x57, 0x47, |
290 | 0x5a,0x53,0x68,0x34,0x5a,0x30,0x68,0x5a,0x4a,0x6d,0x30,0x78,0x64,0x69,0x4e,0x77, | 288 | 0x74, 0x58, 0x58, 0x41, 0x4e, 0x6b, 0x56, 0x68, 0x46, 0x53, 0x65, 0x6a, 0x41, 0x32, 0x4b, 0x52, 0x63, 0x37, 0x61, 0x48, 0x70, 0x38, |
291 | 0x59,0x57,0x51,0x37,0x4f,0x48,0x6c,0x6d,0x64,0x46,0x4d,0x73,0x5a,0x47,0x52,0x55, | 289 | 0x42, 0x57, 0x74, 0x72, 0x45, 0x32, 0x6f, 0x6b, 0x58, 0x47, 0x68, 0x43, 0x47, 0x44, 0x49, 0x44, 0x63, 0x32, 0x34, 0x45, 0x49, 0x53, |
292 | 0x41,0x31,0x52,0x6c,0x52,0x45,0x77,0x59,0x54,0x30,0x67,0x67,0x54,0x33,0x49,0x51, | 290 | 0x34, 0x42, 0x42, 0x47, 0x4e, 0x39, 0x52, 0x45, 0x45, 0x53, 0x4d, 0x51, 0x73, 0x56, 0x48, 0x33, 0x41, 0x41, 0x4c, 0x6d, 0x59, 0x55, |
293 | 0x50,0x77,0x78,0x53,0x4c,0x51,0x4d,0x55,0x41,0x31,0x46,0x43,0x45,0x48,0x64,0x71, | 291 | 0x50, 0x48, 0x38, 0x72, 0x41, 0x42, 0x38, 0x4d, 0x4b, 0x46, 0x6b, 0x4b, 0x46, 0x6b, 0x6c, 0x61, 0x58, 0x47, 0x52, 0x6c, 0x53, 0x78, |
294 | 0x4e,0x41,0x59,0x79,0x41,0x33,0x49,0x55,0x66,0x41,0x68,0x64,0x55,0x68,0x70,0x69, | 292 | 0x45, 0x70, 0x46, 0x54, 0x5a, 0x61, 0x5a, 0x52, 0x6c, 0x50, 0x59, 0x43, 0x4d, 0x36, 0x4f, 0x68, 0x4d, 0x6c, 0x41, 0x6e, 0x68, 0x4d, |
295 | 0x66,0x44,0x34,0x77,0x66,0x6c,0x39,0x2f,0x56,0x41,0x39,0x45,0x53,0x56,0x31,0x65, | 293 | 0x56, 0x41, 0x3d, 0x3d, 0x00}; |
296 | 0x45,0x47,0x6f,0x47,0x4b,0x77,0x5a,0x54,0x45,0x44,0x6b,0x33,0x4d,0x6b,0x70,0x4f, | ||
297 | 0x50,0x53,0x74,0x6c,0x4f,0x44,0x6b,0x48,0x63,0x6c,0x52,0x6b,0x54,0x56,0x5a,0x71, | ||
298 | 0x41,0x79,0x4a,0x77,0x65,0x31,0x39,0x67,0x43,0x79,0x6f,0x4c,0x61,0x78,0x42,0x6b, | ||
299 | 0x46,0x41,0x55,0x69,0x41,0x48,0x4e,0x41,0x49,0x31,0x74,0x52,0x48,0x79,0x73,0x61, | ||
300 | 0x58,0x57,0x6c,0x36,0x52,0x67,0x78,0x66,0x4d,0x6b,0x74,0x4b,0x4b,0x46,0x4a,0x35, | ||
301 | 0x57,0x78,0x4a,0x43,0x47,0x41,0x42,0x64,0x4a,0x7a,0x46,0x54,0x50,0x45,0x77,0x32, | ||
302 | 0x54,0x6a,0x67,0x2f,0x63,0x67,0x4e,0x78,0x41,0x6c,0x73,0x32,0x57,0x58,0x39,0x31, | ||
303 | 0x62,0x67,0x68,0x55,0x44,0x54,0x51,0x63,0x4e,0x46,0x64,0x64,0x61,0x55,0x67,0x41, | ||
304 | 0x4f,0x77,0x55,0x48,0x62,0x69,0x64,0x6c,0x62,0x6b,0x41,0x39,0x4f,0x6b,0x39,0x79, | ||
305 | 0x58,0x54,0x6b,0x57,0x44,0x32,0x4d,0x53,0x45,0x68,0x55,0x36,0x63,0x41,0x31,0x58, | ||
306 | 0x47,0x41,0x31,0x65,0x50,0x53,0x4a,0x6f,0x61,0x48,0x78,0x74,0x54,0x77,0x78,0x37, | ||
307 | 0x43,0x53,0x31,0x4b,0x63,0x79,0x42,0x48,0x42,0x31,0x64,0x31,0x58,0x56,0x4e,0x77, | ||
308 | 0x4e,0x43,0x46,0x41,0x56,0x31,0x46,0x65,0x53,0x55,0x51,0x41,0x56,0x43,0x63,0x45, | ||
309 | 0x61,0x48,0x35,0x5a,0x56,0x6c,0x68,0x30,0x46,0x44,0x77,0x57,0x4d,0x30,0x45,0x57, | ||
310 | 0x53,0x79,0x39,0x4a,0x4e,0x77,0x70,0x55,0x43,0x41,0x67,0x66,0x4f,0x57,0x64,0x32, | ||
311 | 0x4b,0x43,0x67,0x48,0x48,0x57,0x46,0x48,0x55,0x55,0x31,0x31,0x4a,0x6c,0x4a,0x48, | ||
312 | 0x52,0x77,0x78,0x58,0x57,0x48,0x51,0x2b,0x59,0x6d,0x78,0x59,0x4f,0x6b,0x51,0x65, | ||
313 | 0x46,0x69,0x34,0x68,0x48,0x48,0x4e,0x46,0x5a,0x33,0x52,0x50,0x4d,0x32,0x59,0x4f, | ||
314 | 0x64,0x47,0x59,0x6d,0x48,0x79,0x34,0x34,0x52,0x45,0x42,0x2b,0x4b,0x6c,0x42,0x53, | ||
315 | 0x58,0x6b,0x4d,0x42,0x65,0x6a,0x68,0x4a,0x50,0x46,0x56,0x4e,0x57,0x6b,0x51,0x49, | ||
316 | 0x4a,0x6c,0x6c,0x4e,0x52,0x51,0x74,0x49,0x43,0x6a,0x4e,0x65,0x53,0x6b,0x31,0x31, | ||
317 | 0x46,0x68,0x64,0x6a,0x52,0x67,0x45,0x71,0x56,0x58,0x73,0x50,0x41,0x6e,0x4e,0x71, | ||
318 | 0x53,0x33,0x39,0x31,0x5a,0x54,0x78,0x4d,0x4d,0x7a,0x6c,0x73,0x64,0x41,0x56,0x67, | ||
319 | 0x44,0x33,0x38,0x74,0x51,0x55,0x31,0x4e,0x52,0x6e,0x45,0x4a,0x62,0x30,0x39,0x67, | ||
320 | 0x46,0x51,0x39,0x47,0x63,0x32,0x4e,0x4d,0x58,0x6e,0x51,0x77,0x44,0x53,0x68,0x44, | ||
321 | 0x43,0x48,0x49,0x79,0x42,0x43,0x34,0x78,0x4b,0x53,0x64,0x45,0x62,0x52,0x4d,0x58, | ||
322 | 0x53,0x41,0x39,0x4a,0x55,0x68,0x41,0x54,0x66,0x78,0x63,0x57,0x59,0x6e,0x6b,0x31, | ||
323 | 0x65,0x44,0x34,0x42,0x66,0x43,0x34,0x50,0x64,0x6a,0x35,0x65,0x55,0x32,0x78,0x62, | ||
324 | 0x58,0x33,0x77,0x5a,0x51,0x51,0x49,0x76,0x46,0x32,0x52,0x42,0x64,0x52,0x41,0x45, | ||
325 | 0x52,0x33,0x77,0x39,0x53,0x31,0x49,0x41,0x45,0x46,0x31,0x52,0x54,0x6e,0x6f,0x6e, | ||
326 | 0x4a,0x56,0x56,0x41,0x45,0x6a,0x56,0x67,0x42,0x52,0x73,0x30,0x4c,0x51,0x52,0x36, | ||
327 | 0x61,0x6d,0x6b,0x43,0x65,0x51,0x4d,0x36,0x4c,0x77,0x59,0x4b,0x65,0x58,0x73,0x53, | ||
328 | 0x58,0x58,0x78,0x53,0x4b,0x55,0x64,0x59,0x45,0x6e,0x4d,0x2f,0x4a,0x31,0x59,0x46, | ||
329 | 0x44,0x45,0x67,0x79,0x57,0x47,0x74,0x58,0x58,0x41,0x4e,0x6b,0x56,0x68,0x46,0x53, | ||
330 | 0x65,0x6a,0x41,0x32,0x4b,0x52,0x63,0x37,0x61,0x48,0x70,0x38,0x42,0x57,0x74,0x72, | ||
331 | 0x45,0x32,0x6f,0x6b,0x58,0x47,0x68,0x43,0x47,0x44,0x49,0x44,0x63,0x32,0x34,0x45, | ||
332 | 0x49,0x53,0x34,0x42,0x42,0x47,0x4e,0x39,0x52,0x45,0x45,0x53,0x4d,0x51,0x73,0x56, | ||
333 | 0x48,0x33,0x41,0x41,0x4c,0x6d,0x59,0x55,0x50,0x48,0x38,0x72,0x41,0x42,0x38,0x4d, | ||
334 | 0x4b,0x46,0x6b,0x4b,0x46,0x6b,0x6c,0x61,0x58,0x47,0x52,0x6c,0x53,0x78,0x45,0x70, | ||
335 | 0x46,0x54,0x5a,0x61,0x5a,0x52,0x6c,0x50,0x59,0x43,0x4d,0x36,0x4f,0x68,0x4d,0x6c, | ||
336 | 0x41,0x6e,0x68,0x4d,0x56,0x41,0x3d,0x3d,0x00 | ||
337 | }; | ||
338 | char *b64_test; | 294 | char *b64_test; |
339 | 295 | ||
340 | plan_tests(1); | 296 | plan_tests(1); |
341 | 297 | ||
342 | base64_encode_alloc (random, 1024, &b64_test); | 298 | base64_encode_alloc(random, 1024, &b64_test); |
343 | 299 | ||
344 | ok(strcmp(b64_known, b64_test) == 0, | 300 | ok(strcmp(b64_known, b64_test) == 0, "Test matching a base64 encoded 1024 bytes random string"); |
345 | "Test matching a base64 encoded 1024 bytes random string"); | ||
346 | 301 | ||
347 | return exit_status(); | 302 | return exit_status(); |
348 | } | 303 | } |
349 | |||
diff --git a/lib/tests/test_cmd.c b/lib/tests/test_cmd.c index 02ae11f..c8867df 100644 --- a/lib/tests/test_cmd.c +++ b/lib/tests/test_cmd.c | |||
@@ -1,20 +1,20 @@ | |||
1 | /***************************************************************************** | 1 | /***************************************************************************** |
2 | * | 2 | * |
3 | * This program is free software: you can redistribute it and/or modify | 3 | * This program is free software: you can redistribute it and/or modify |
4 | * it under the terms of the GNU General Public License as published by | 4 | * it under the terms of the GNU General Public License as published by |
5 | * the Free Software Foundation, either version 3 of the License, or | 5 | * the Free Software Foundation, either version 3 of the License, or |
6 | * (at your option) any later version. | 6 | * (at your option) any later version. |
7 | * | 7 | * |
8 | * This program is distributed in the hope that it will be useful, | 8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. | 11 | * GNU General Public License for more details. |
12 | * | 12 | * |
13 | * You should have received a copy of the GNU General Public License | 13 | * You should have received a copy of the GNU General Public License |
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
15 | * | 15 | * |
16 | * | 16 | * |
17 | *****************************************************************************/ | 17 | *****************************************************************************/ |
18 | 18 | ||
19 | #include "common.h" | 19 | #include "common.h" |
20 | #include "utils_cmd.h" | 20 | #include "utils_cmd.h" |
@@ -22,27 +22,23 @@ | |||
22 | #include "tap.h" | 22 | #include "tap.h" |
23 | 23 | ||
24 | #define COMMAND_LINE 1024 | 24 | #define COMMAND_LINE 1024 |
25 | #define UNSET 65530 | 25 | #define UNSET 65530 |
26 | 26 | ||
27 | char * | 27 | char *get_command(char *const *line) { |
28 | get_command (char *const *line) | ||
29 | { | ||
30 | char *cmd; | 28 | char *cmd; |
31 | int i = 0; | 29 | int i = 0; |
32 | 30 | ||
33 | asprintf (&cmd, " %s", line[i++]); | 31 | asprintf(&cmd, " %s", line[i++]); |
34 | while (line[i] != NULL) { | 32 | while (line[i] != NULL) { |
35 | asprintf (&cmd, "%s %s", cmd, line[i]); | 33 | asprintf(&cmd, "%s %s", cmd, line[i]); |
36 | i++; | 34 | i++; |
37 | } | 35 | } |
38 | 36 | ||
39 | return cmd; | 37 | return cmd; |
40 | } | 38 | } |
41 | 39 | ||
42 | int | 40 | int main(int argc, char **argv) { |
43 | main (int argc, char **argv) | 41 | char **command_line = malloc(sizeof(char *) * COMMAND_LINE); |
44 | { | ||
45 | char **command_line = malloc (sizeof (char *) * COMMAND_LINE); | ||
46 | char *command = NULL; | 42 | char *command = NULL; |
47 | char *perl; | 43 | char *perl; |
48 | output chld_out, chld_err; | 44 | output chld_out, chld_err; |
@@ -51,183 +47,154 @@ main (int argc, char **argv) | |||
51 | 47 | ||
52 | plan_tests(51); | 48 | plan_tests(51); |
53 | 49 | ||
54 | diag ("Running plain echo command, set one"); | 50 | diag("Running plain echo command, set one"); |
55 | 51 | ||
56 | /* ensure everything is empty before we begin */ | 52 | /* ensure everything is empty before we begin */ |
57 | memset (&chld_out, 0, sizeof (output)); | 53 | memset(&chld_out, 0, sizeof(output)); |
58 | memset (&chld_err, 0, sizeof (output)); | 54 | memset(&chld_err, 0, sizeof(output)); |
59 | ok (chld_out.lines == 0, "(initialised) Checking stdout is reset"); | 55 | ok(chld_out.lines == 0, "(initialised) Checking stdout is reset"); |
60 | ok (chld_err.lines == 0, "(initialised) Checking stderr is reset"); | 56 | ok(chld_err.lines == 0, "(initialised) Checking stderr is reset"); |
61 | ok (result == UNSET, "(initialised) Checking exit code is reset"); | 57 | ok(result == UNSET, "(initialised) Checking exit code is reset"); |
62 | 58 | ||
63 | command_line[0] = strdup ("/bin/echo"); | 59 | command_line[0] = strdup("/bin/echo"); |
64 | command_line[1] = strdup ("this"); | 60 | command_line[1] = strdup("this"); |
65 | command_line[2] = strdup ("is"); | 61 | command_line[2] = strdup("is"); |
66 | command_line[3] = strdup ("test"); | 62 | command_line[3] = strdup("test"); |
67 | command_line[4] = strdup ("one"); | 63 | command_line[4] = strdup("one"); |
68 | 64 | ||
69 | command = get_command (command_line); | 65 | command = get_command(command_line); |
70 | 66 | ||
71 | result = cmd_run_array (command_line, &chld_out, &chld_err, 0); | 67 | result = cmd_run_array(command_line, &chld_out, &chld_err, 0); |
72 | ok (chld_out.lines == 1, | 68 | ok(chld_out.lines == 1, "(array) Check for expected number of stdout lines"); |
73 | "(array) Check for expected number of stdout lines"); | 69 | ok(chld_err.lines == 0, "(array) Check for expected number of stderr lines"); |
74 | ok (chld_err.lines == 0, | 70 | ok(strcmp(chld_out.line[0], "this is test one") == 0, "(array) Check for expected stdout output"); |
75 | "(array) Check for expected number of stderr lines"); | 71 | ok(result == 0, "(array) Checking exit code"); |
76 | ok (strcmp (chld_out.line[0], "this is test one") == 0, | ||
77 | "(array) Check for expected stdout output"); | ||
78 | ok (result == 0, "(array) Checking exit code"); | ||
79 | 72 | ||
80 | /* ensure everything is empty again */ | 73 | /* ensure everything is empty again */ |
81 | memset (&chld_out, 0, sizeof (output)); | 74 | memset(&chld_out, 0, sizeof(output)); |
82 | memset (&chld_err, 0, sizeof (output)); | 75 | memset(&chld_err, 0, sizeof(output)); |
83 | result = UNSET; | 76 | result = UNSET; |
84 | ok (chld_out.lines == 0, "(initialised) Checking stdout is reset"); | 77 | ok(chld_out.lines == 0, "(initialised) Checking stdout is reset"); |
85 | ok (chld_err.lines == 0, "(initialised) Checking stderr is reset"); | 78 | ok(chld_err.lines == 0, "(initialised) Checking stderr is reset"); |
86 | ok (result == UNSET, "(initialised) Checking exit code is reset"); | 79 | ok(result == UNSET, "(initialised) Checking exit code is reset"); |
87 | 80 | ||
88 | result = cmd_run (command, &chld_out, &chld_err, 0); | 81 | result = cmd_run(command, &chld_out, &chld_err, 0); |
89 | 82 | ||
90 | ok (chld_out.lines == 1, | 83 | ok(chld_out.lines == 1, "(string) Check for expected number of stdout lines"); |
91 | "(string) Check for expected number of stdout lines"); | 84 | ok(chld_err.lines == 0, "(string) Check for expected number of stderr lines"); |
92 | ok (chld_err.lines == 0, | 85 | ok(strcmp(chld_out.line[0], "this is test one") == 0, "(string) Check for expected stdout output"); |
93 | "(string) Check for expected number of stderr lines"); | 86 | ok(result == 0, "(string) Checking exit code"); |
94 | ok (strcmp (chld_out.line[0], "this is test one") == 0, | ||
95 | "(string) Check for expected stdout output"); | ||
96 | ok (result == 0, "(string) Checking exit code"); | ||
97 | 87 | ||
98 | diag ("Running plain echo command, set two"); | 88 | diag("Running plain echo command, set two"); |
99 | 89 | ||
100 | /* ensure everything is empty again */ | 90 | /* ensure everything is empty again */ |
101 | memset (&chld_out, 0, sizeof (output)); | 91 | memset(&chld_out, 0, sizeof(output)); |
102 | memset (&chld_err, 0, sizeof (output)); | 92 | memset(&chld_err, 0, sizeof(output)); |
103 | result = UNSET; | 93 | result = UNSET; |
104 | ok (chld_out.lines == 0, "(initialised) Checking stdout is reset"); | 94 | ok(chld_out.lines == 0, "(initialised) Checking stdout is reset"); |
105 | ok (chld_err.lines == 0, "(initialised) Checking stderr is reset"); | 95 | ok(chld_err.lines == 0, "(initialised) Checking stderr is reset"); |
106 | ok (result == UNSET, "(initialised) Checking exit code is reset"); | 96 | ok(result == UNSET, "(initialised) Checking exit code is reset"); |
107 | 97 | ||
108 | command_line[0] = strdup ("/bin/echo"); | 98 | command_line[0] = strdup("/bin/echo"); |
109 | command_line[1] = strdup ("this is test two"); | 99 | command_line[1] = strdup("this is test two"); |
110 | command_line[2] = NULL; | 100 | command_line[2] = NULL; |
111 | command_line[3] = NULL; | 101 | command_line[3] = NULL; |
112 | command_line[4] = NULL; | 102 | command_line[4] = NULL; |
113 | 103 | ||
114 | result = cmd_run_array (command_line, &chld_out, &chld_err, 0); | 104 | result = cmd_run_array(command_line, &chld_out, &chld_err, 0); |
115 | ok (chld_out.lines == 1, | 105 | ok(chld_out.lines == 1, "(array) Check for expected number of stdout lines"); |
116 | "(array) Check for expected number of stdout lines"); | 106 | ok(chld_err.lines == 0, "(array) Check for expected number of stderr lines"); |
117 | ok (chld_err.lines == 0, | 107 | ok(strcmp(chld_out.line[0], "this is test two") == 0, "(array) Check for expected stdout output"); |
118 | "(array) Check for expected number of stderr lines"); | 108 | ok(result == 0, "(array) Checking exit code"); |
119 | ok (strcmp (chld_out.line[0], "this is test two") == 0, | ||
120 | "(array) Check for expected stdout output"); | ||
121 | ok (result == 0, "(array) Checking exit code"); | ||
122 | 109 | ||
123 | /* ensure everything is empty again */ | 110 | /* ensure everything is empty again */ |
124 | memset (&chld_out, 0, sizeof (output)); | 111 | memset(&chld_out, 0, sizeof(output)); |
125 | memset (&chld_err, 0, sizeof (output)); | 112 | memset(&chld_err, 0, sizeof(output)); |
126 | result = UNSET; | 113 | result = UNSET; |
127 | ok (chld_out.lines == 0, "(initialised) Checking stdout is reset"); | 114 | ok(chld_out.lines == 0, "(initialised) Checking stdout is reset"); |
128 | ok (chld_err.lines == 0, "(initialised) Checking stderr is reset"); | 115 | ok(chld_err.lines == 0, "(initialised) Checking stderr is reset"); |
129 | ok (result == UNSET, "(initialised) Checking exit code is reset"); | 116 | ok(result == UNSET, "(initialised) Checking exit code is reset"); |
130 | |||
131 | result = cmd_run (command, &chld_out, &chld_err, 0); | ||
132 | 117 | ||
133 | ok (chld_out.lines == 1, | 118 | result = cmd_run(command, &chld_out, &chld_err, 0); |
134 | "(string) Check for expected number of stdout lines"); | ||
135 | ok (chld_err.lines == 0, | ||
136 | "(string) Check for expected number of stderr lines"); | ||
137 | ok (strcmp (chld_out.line[0], "this is test one") == 0, | ||
138 | "(string) Check for expected stdout output"); | ||
139 | ok (result == 0, "(string) Checking exit code"); | ||
140 | 119 | ||
120 | ok(chld_out.lines == 1, "(string) Check for expected number of stdout lines"); | ||
121 | ok(chld_err.lines == 0, "(string) Check for expected number of stderr lines"); | ||
122 | ok(strcmp(chld_out.line[0], "this is test one") == 0, "(string) Check for expected stdout output"); | ||
123 | ok(result == 0, "(string) Checking exit code"); | ||
141 | 124 | ||
142 | /* ensure everything is empty again */ | 125 | /* ensure everything is empty again */ |
143 | memset (&chld_out, 0, sizeof (output)); | 126 | memset(&chld_out, 0, sizeof(output)); |
144 | memset (&chld_err, 0, sizeof (output)); | 127 | memset(&chld_err, 0, sizeof(output)); |
145 | result = UNSET; | 128 | result = UNSET; |
146 | ok (chld_out.lines == 0, "(initialised) Checking stdout is reset"); | 129 | ok(chld_out.lines == 0, "(initialised) Checking stdout is reset"); |
147 | ok (chld_err.lines == 0, "(initialised) Checking stderr is reset"); | 130 | ok(chld_err.lines == 0, "(initialised) Checking stderr is reset"); |
148 | ok (result == UNSET, "(initialised) Checking exit code is reset"); | 131 | ok(result == UNSET, "(initialised) Checking exit code is reset"); |
149 | 132 | ||
150 | /* Pass linefeeds via parameters through - those should be evaluated by echo to give multi line output */ | 133 | /* Pass linefeeds via parameters through - those should be evaluated by echo to give multi line output */ |
151 | command_line[0] = strdup("/bin/echo"); | 134 | command_line[0] = strdup("/bin/echo"); |
152 | command_line[1] = strdup("this is a test via echo\nline two\nit's line 3"); | 135 | command_line[1] = strdup("this is a test via echo\nline two\nit's line 3"); |
153 | command_line[2] = strdup("and (note space between '3' and 'and') $$ will not get evaluated"); | 136 | command_line[2] = strdup("and (note space between '3' and 'and') $$ will not get evaluated"); |
154 | 137 | ||
155 | result = cmd_run_array (command_line, &chld_out, &chld_err, 0); | 138 | result = cmd_run_array(command_line, &chld_out, &chld_err, 0); |
156 | ok (chld_out.lines == 3, | 139 | ok(chld_out.lines == 3, "(array) Check for expected number of stdout lines"); |
157 | "(array) Check for expected number of stdout lines"); | 140 | ok(chld_err.lines == 0, "(array) Check for expected number of stderr lines"); |
158 | ok (chld_err.lines == 0, | 141 | ok(strcmp(chld_out.line[0], "this is a test via echo") == 0, "(array) Check line 1 for expected stdout output"); |
159 | "(array) Check for expected number of stderr lines"); | 142 | ok(strcmp(chld_out.line[1], "line two") == 0, "(array) Check line 2 for expected stdout output"); |
160 | ok (strcmp (chld_out.line[0], "this is a test via echo") == 0, | 143 | ok(strcmp(chld_out.line[2], "it's line 3 and (note space between '3' and 'and') $$ will not get evaluated") == 0, |
161 | "(array) Check line 1 for expected stdout output"); | 144 | "(array) Check line 3 for expected stdout output"); |
162 | ok (strcmp (chld_out.line[1], "line two") == 0, | 145 | ok(result == 0, "(array) Checking exit code"); |
163 | "(array) Check line 2 for expected stdout output"); | ||
164 | ok (strcmp (chld_out.line[2], "it's line 3 and (note space between '3' and 'and') $$ will not get evaluated") == 0, | ||
165 | "(array) Check line 3 for expected stdout output"); | ||
166 | ok (result == 0, "(array) Checking exit code"); | ||
167 | |||
168 | |||
169 | 146 | ||
170 | /* ensure everything is empty again */ | 147 | /* ensure everything is empty again */ |
171 | memset (&chld_out, 0, sizeof (output)); | 148 | memset(&chld_out, 0, sizeof(output)); |
172 | memset (&chld_err, 0, sizeof (output)); | 149 | memset(&chld_err, 0, sizeof(output)); |
173 | result = UNSET; | 150 | result = UNSET; |
174 | ok (chld_out.lines == 0, "(initialised) Checking stdout is reset"); | 151 | ok(chld_out.lines == 0, "(initialised) Checking stdout is reset"); |
175 | ok (chld_err.lines == 0, "(initialised) Checking stderr is reset"); | 152 | ok(chld_err.lines == 0, "(initialised) Checking stderr is reset"); |
176 | ok (result == UNSET, "(initialised) Checking exit code is reset"); | 153 | ok(result == UNSET, "(initialised) Checking exit code is reset"); |
177 | 154 | ||
178 | command = (char *)malloc(COMMAND_LINE); | 155 | command = (char *)malloc(COMMAND_LINE); |
179 | strcpy(command, "/bin/echo3456 non-existent command"); | 156 | strcpy(command, "/bin/echo3456 non-existent command"); |
180 | result = cmd_run (command, &chld_out, &chld_err, 0); | 157 | result = cmd_run(command, &chld_out, &chld_err, 0); |
181 | |||
182 | ok (chld_out.lines == 0, | ||
183 | "Non existent command, so no output"); | ||
184 | ok (chld_err.lines == 0, | ||
185 | "No stderr either"); | ||
186 | ok (result == 3, "Get return code 3 (?) for non-existent command"); | ||
187 | 158 | ||
159 | ok(chld_out.lines == 0, "Non existent command, so no output"); | ||
160 | ok(chld_err.lines == 0, "No stderr either"); | ||
161 | ok(result == 3, "Get return code 3 (?) for non-existent command"); | ||
188 | 162 | ||
189 | /* ensure everything is empty again */ | 163 | /* ensure everything is empty again */ |
190 | memset (&chld_out, 0, sizeof (output)); | 164 | memset(&chld_out, 0, sizeof(output)); |
191 | memset (&chld_err, 0, sizeof (output)); | 165 | memset(&chld_err, 0, sizeof(output)); |
192 | result = UNSET; | 166 | result = UNSET; |
193 | 167 | ||
194 | command = (char *)malloc(COMMAND_LINE); | 168 | command = (char *)malloc(COMMAND_LINE); |
195 | strcpy(command, "/bin/sh non-existent-file"); | 169 | strcpy(command, "/bin/sh non-existent-file"); |
196 | result = cmd_run (command, &chld_out, &chld_err, 0); | 170 | result = cmd_run(command, &chld_out, &chld_err, 0); |
197 | |||
198 | ok (chld_out.lines == 0, | ||
199 | "/bin/sh returns no stdout when file is missing..."); | ||
200 | ok (chld_err.lines == 1, | ||
201 | "...but does give an error line"); | ||
202 | ok (strstr(chld_err.line[0],"non-existent-file") != NULL, "And missing filename is in error message"); | ||
203 | ok (result != 0, "Get non-zero return code from /bin/sh"); | ||
204 | 171 | ||
172 | ok(chld_out.lines == 0, "/bin/sh returns no stdout when file is missing..."); | ||
173 | ok(chld_err.lines == 1, "...but does give an error line"); | ||
174 | ok(strstr(chld_err.line[0], "non-existent-file") != NULL, "And missing filename is in error message"); | ||
175 | ok(result != 0, "Get non-zero return code from /bin/sh"); | ||
205 | 176 | ||
206 | /* ensure everything is empty again */ | 177 | /* ensure everything is empty again */ |
207 | result = UNSET; | 178 | result = UNSET; |
208 | 179 | ||
209 | command = (char *)malloc(COMMAND_LINE); | 180 | command = (char *)malloc(COMMAND_LINE); |
210 | strcpy(command, "/bin/sh -c 'exit 7'"); | 181 | strcpy(command, "/bin/sh -c 'exit 7'"); |
211 | result = cmd_run (command, NULL, NULL, 0); | 182 | result = cmd_run(command, NULL, NULL, 0); |
212 | |||
213 | ok (result == 7, "Get return code 7 from /bin/sh"); | ||
214 | 183 | ||
184 | ok(result == 7, "Get return code 7 from /bin/sh"); | ||
215 | 185 | ||
216 | /* ensure everything is empty again */ | 186 | /* ensure everything is empty again */ |
217 | memset (&chld_out, 0, sizeof (output)); | 187 | memset(&chld_out, 0, sizeof(output)); |
218 | memset (&chld_err, 0, sizeof (output)); | 188 | memset(&chld_err, 0, sizeof(output)); |
219 | result = UNSET; | 189 | result = UNSET; |
220 | 190 | ||
221 | command = (char *)malloc(COMMAND_LINE); | 191 | command = (char *)malloc(COMMAND_LINE); |
222 | strcpy(command, "/bin/non-existent-command"); | 192 | strcpy(command, "/bin/non-existent-command"); |
223 | result = cmd_run (command, &chld_out, &chld_err, 0); | 193 | result = cmd_run(command, &chld_out, &chld_err, 0); |
224 | |||
225 | ok (chld_out.lines == 0, | ||
226 | "/bin/non-existent-command returns no stdout..."); | ||
227 | ok (chld_err.lines == 0, | ||
228 | "...and no stderr output either"); | ||
229 | ok (result == 3, "Get return code 3 = UNKNOWN when command does not exist"); | ||
230 | 194 | ||
195 | ok(chld_out.lines == 0, "/bin/non-existent-command returns no stdout..."); | ||
196 | ok(chld_err.lines == 0, "...and no stderr output either"); | ||
197 | ok(result == 3, "Get return code 3 = UNKNOWN when command does not exist"); | ||
231 | 198 | ||
232 | return exit_status (); | 199 | return exit_status(); |
233 | } | 200 | } |
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 @@ | |||
1 | /***************************************************************************** | 1 | /***************************************************************************** |
2 | * | 2 | * |
3 | * This program is free software: you can redistribute it and/or modify | 3 | * This program is free software: you can redistribute it and/or modify |
4 | * it under the terms of the GNU General Public License as published by | 4 | * it under the terms of the GNU General Public License as published by |
5 | * the Free Software Foundation, either version 3 of the License, or | 5 | * the Free Software Foundation, either version 3 of the License, or |
6 | * (at your option) any later version. | 6 | * (at your option) any later version. |
7 | * | 7 | * |
8 | * This program is distributed in the hope that it will be useful, | 8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. | 11 | * GNU General Public License for more details. |
12 | * | 12 | * |
13 | * You should have received a copy of the GNU General Public License | 13 | * You should have received a copy of the GNU General Public License |
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
15 | * | 15 | * |
16 | * | 16 | * |
17 | *****************************************************************************/ | 17 | *****************************************************************************/ |
18 | 18 | ||
19 | #include "common.h" | 19 | #include "common.h" |
20 | #include "utils_disk.h" | 20 | #include "utils_disk.h" |
21 | #include "tap.h" | 21 | #include "tap.h" |
22 | #include "regex.h" | 22 | #include "regex.h" |
23 | 23 | ||
24 | void np_test_mount_entry_regex (struct mount_entry *dummy_mount_list, | 24 | void np_test_mount_entry_regex(struct mount_entry *dummy_mount_list, char *regstr, int cflags, int expect, char *desc); |
25 | char *regstr, int cflags, int expect, | ||
26 | char *desc); | ||
27 | 25 | ||
28 | 26 | int main(int argc, char **argv) { | |
29 | int | 27 | struct name_list *exclude_filesystem = NULL; |
30 | main (int argc, char **argv) | 28 | struct name_list *exclude_fstype = NULL; |
31 | { | ||
32 | struct name_list *exclude_filesystem=NULL; | ||
33 | struct name_list *exclude_fstype=NULL; | ||
34 | struct name_list *dummy_mountlist = NULL; | 29 | struct name_list *dummy_mountlist = NULL; |
35 | struct name_list *temp_name; | 30 | struct name_list *temp_name; |
36 | struct parameter_list *paths = NULL; | 31 | struct parameter_list *paths = NULL; |
@@ -44,19 +39,19 @@ main (int argc, char **argv) | |||
44 | 39 | ||
45 | plan_tests(33); | 40 | plan_tests(33); |
46 | 41 | ||
47 | ok( np_find_name(exclude_filesystem, "/var/log") == false, "/var/log not in list"); | 42 | ok(np_find_name(exclude_filesystem, "/var/log") == false, "/var/log not in list"); |
48 | np_add_name(&exclude_filesystem, "/var/log"); | 43 | np_add_name(&exclude_filesystem, "/var/log"); |
49 | ok( np_find_name(exclude_filesystem, "/var/log") == true, "is in list now"); | 44 | ok(np_find_name(exclude_filesystem, "/var/log") == true, "is in list now"); |
50 | ok( np_find_name(exclude_filesystem, "/home") == false, "/home not in list"); | 45 | ok(np_find_name(exclude_filesystem, "/home") == false, "/home not in list"); |
51 | np_add_name(&exclude_filesystem, "/home"); | 46 | np_add_name(&exclude_filesystem, "/home"); |
52 | ok( np_find_name(exclude_filesystem, "/home") == true, "is in list now"); | 47 | ok(np_find_name(exclude_filesystem, "/home") == true, "is in list now"); |
53 | ok( np_find_name(exclude_filesystem, "/var/log") == true, "/var/log still in list"); | 48 | ok(np_find_name(exclude_filesystem, "/var/log") == true, "/var/log still in list"); |
54 | 49 | ||
55 | ok( np_find_name(exclude_fstype, "iso9660") == false, "iso9660 not in list"); | 50 | ok(np_find_name(exclude_fstype, "iso9660") == false, "iso9660 not in list"); |
56 | np_add_name(&exclude_fstype, "iso9660"); | 51 | np_add_name(&exclude_fstype, "iso9660"); |
57 | ok( np_find_name(exclude_fstype, "iso9660") == true, "is in list now"); | 52 | ok(np_find_name(exclude_fstype, "iso9660") == true, "is in list now"); |
58 | 53 | ||
59 | ok( np_find_name(exclude_filesystem, "iso9660") == false, "Make sure no clashing in variables"); | 54 | ok(np_find_name(exclude_filesystem, "iso9660") == false, "Make sure no clashing in variables"); |
60 | 55 | ||
61 | /* | 56 | /* |
62 | for (temp_name = exclude_filesystem; temp_name; temp_name = temp_name->next) { | 57 | for (temp_name = exclude_filesystem; temp_name; temp_name = temp_name->next) { |
@@ -64,55 +59,35 @@ main (int argc, char **argv) | |||
64 | } | 59 | } |
65 | */ | 60 | */ |
66 | 61 | ||
67 | me = (struct mount_entry *) malloc(sizeof *me); | 62 | me = (struct mount_entry *)malloc(sizeof *me); |
68 | me->me_devname = strdup("/dev/c0t0d0s0"); | 63 | me->me_devname = strdup("/dev/c0t0d0s0"); |
69 | me->me_mountdir = strdup("/"); | 64 | me->me_mountdir = strdup("/"); |
70 | *mtail = me; | 65 | *mtail = me; |
71 | mtail = &me->me_next; | 66 | mtail = &me->me_next; |
72 | 67 | ||
73 | me = (struct mount_entry *) malloc(sizeof *me); | 68 | me = (struct mount_entry *)malloc(sizeof *me); |
74 | me->me_devname = strdup("/dev/c1t0d1s0"); | 69 | me->me_devname = strdup("/dev/c1t0d1s0"); |
75 | me->me_mountdir = strdup("/var"); | 70 | me->me_mountdir = strdup("/var"); |
76 | *mtail = me; | 71 | *mtail = me; |
77 | mtail = &me->me_next; | 72 | mtail = &me->me_next; |
78 | 73 | ||
79 | me = (struct mount_entry *) malloc(sizeof *me); | 74 | me = (struct mount_entry *)malloc(sizeof *me); |
80 | me->me_devname = strdup("/dev/c2t0d0s0"); | 75 | me->me_devname = strdup("/dev/c2t0d0s0"); |
81 | me->me_mountdir = strdup("/home"); | 76 | me->me_mountdir = strdup("/home"); |
82 | *mtail = me; | 77 | *mtail = me; |
83 | mtail = &me->me_next; | 78 | mtail = &me->me_next; |
84 | 79 | ||
85 | np_test_mount_entry_regex(dummy_mount_list, strdup("/"), | 80 | np_test_mount_entry_regex(dummy_mount_list, strdup("/"), cflags, 3, strdup("a")); |
86 | cflags, 3, strdup("a")); | 81 | np_test_mount_entry_regex(dummy_mount_list, strdup("/dev"), cflags, 3, strdup("regex on dev names:")); |
87 | np_test_mount_entry_regex(dummy_mount_list, strdup("/dev"), | 82 | np_test_mount_entry_regex(dummy_mount_list, strdup("/foo"), cflags, 0, strdup("regex on non existent dev/path:")); |
88 | cflags, 3,strdup("regex on dev names:")); | 83 | np_test_mount_entry_regex(dummy_mount_list, strdup("/Foo"), cflags | REG_ICASE, 0, strdup("regi on non existent dev/path:")); |
89 | np_test_mount_entry_regex(dummy_mount_list, strdup("/foo"), | 84 | np_test_mount_entry_regex(dummy_mount_list, strdup("/c.t0"), cflags, 3, strdup("partial devname regex match:")); |
90 | cflags, 0, | 85 | np_test_mount_entry_regex(dummy_mount_list, strdup("c0t0"), cflags, 1, strdup("partial devname regex match:")); |
91 | strdup("regex on non existent dev/path:")); | 86 | np_test_mount_entry_regex(dummy_mount_list, strdup("C0t0"), cflags | REG_ICASE, 1, strdup("partial devname regi match:")); |
92 | np_test_mount_entry_regex(dummy_mount_list, strdup("/Foo"), | 87 | np_test_mount_entry_regex(dummy_mount_list, strdup("home"), cflags, 1, strdup("partial pathname regex match:")); |
93 | cflags | REG_ICASE,0, | 88 | np_test_mount_entry_regex(dummy_mount_list, strdup("hOme"), cflags | REG_ICASE, 1, strdup("partial pathname regi match:")); |
94 | strdup("regi on non existent dev/path:")); | 89 | np_test_mount_entry_regex(dummy_mount_list, strdup("(/home)|(/var)"), cflags, 2, strdup("grouped regex pathname match:")); |
95 | np_test_mount_entry_regex(dummy_mount_list, strdup("/c.t0"), | 90 | np_test_mount_entry_regex(dummy_mount_list, strdup("(/homE)|(/Var)"), cflags | REG_ICASE, 2, strdup("grouped regi pathname match:")); |
96 | cflags, 3, | ||
97 | strdup("partial devname regex match:")); | ||
98 | np_test_mount_entry_regex(dummy_mount_list, strdup("c0t0"), | ||
99 | cflags, 1, | ||
100 | strdup("partial devname regex match:")); | ||
101 | np_test_mount_entry_regex(dummy_mount_list, strdup("C0t0"), | ||
102 | cflags | REG_ICASE, 1, | ||
103 | strdup("partial devname regi match:")); | ||
104 | np_test_mount_entry_regex(dummy_mount_list, strdup("home"), | ||
105 | cflags, 1, | ||
106 | strdup("partial pathname regex match:")); | ||
107 | np_test_mount_entry_regex(dummy_mount_list, strdup("hOme"), | ||
108 | cflags | REG_ICASE, 1, | ||
109 | strdup("partial pathname regi match:")); | ||
110 | np_test_mount_entry_regex(dummy_mount_list, strdup("(/home)|(/var)"), | ||
111 | cflags, 2, | ||
112 | strdup("grouped regex pathname match:")); | ||
113 | np_test_mount_entry_regex(dummy_mount_list, strdup("(/homE)|(/Var)"), | ||
114 | cflags | REG_ICASE, 2, | ||
115 | strdup("grouped regi pathname match:")); | ||
116 | 91 | ||
117 | np_add_parameter(&paths, "/home/groups"); | 92 | np_add_parameter(&paths, "/home/groups"); |
118 | np_add_parameter(&paths, "/var"); | 93 | np_add_parameter(&paths, "/var"); |
@@ -124,20 +99,20 @@ main (int argc, char **argv) | |||
124 | for (p = paths; p; p = p->name_next) { | 99 | for (p = paths; p; p = p->name_next) { |
125 | struct mount_entry *temp_me; | 100 | struct mount_entry *temp_me; |
126 | temp_me = p->best_match; | 101 | temp_me = p->best_match; |
127 | if (! strcmp(p->name, "/home/groups")) { | 102 | if (!strcmp(p->name, "/home/groups")) { |
128 | ok( temp_me && !strcmp(temp_me->me_mountdir, "/home"), "/home/groups got right best match: /home"); | 103 | ok(temp_me && !strcmp(temp_me->me_mountdir, "/home"), "/home/groups got right best match: /home"); |
129 | } else if (! strcmp(p->name, "/var")) { | 104 | } else if (!strcmp(p->name, "/var")) { |
130 | ok( temp_me && !strcmp(temp_me->me_mountdir, "/var"), "/var got right best match: /var"); | 105 | ok(temp_me && !strcmp(temp_me->me_mountdir, "/var"), "/var got right best match: /var"); |
131 | } else if (! strcmp(p->name, "/tmp")) { | 106 | } else if (!strcmp(p->name, "/tmp")) { |
132 | ok( temp_me && !strcmp(temp_me->me_mountdir, "/"), "/tmp got right best match: /"); | 107 | ok(temp_me && !strcmp(temp_me->me_mountdir, "/"), "/tmp got right best match: /"); |
133 | } else if (! strcmp(p->name, "/home/tonvoon")) { | 108 | } else if (!strcmp(p->name, "/home/tonvoon")) { |
134 | ok( temp_me && !strcmp(temp_me->me_mountdir, "/home"), "/home/tonvoon got right best match: /home"); | 109 | ok(temp_me && !strcmp(temp_me->me_mountdir, "/home"), "/home/tonvoon got right best match: /home"); |
135 | } else if (! strcmp(p->name, "/dev/c2t0d0s0")) { | 110 | } else if (!strcmp(p->name, "/dev/c2t0d0s0")) { |
136 | ok( temp_me && !strcmp(temp_me->me_devname, "/dev/c2t0d0s0"), "/dev/c2t0d0s0 got right best match: /dev/c2t0d0s0"); | 111 | ok(temp_me && !strcmp(temp_me->me_devname, "/dev/c2t0d0s0"), "/dev/c2t0d0s0 got right best match: /dev/c2t0d0s0"); |
137 | } | 112 | } |
138 | } | 113 | } |
139 | 114 | ||
140 | paths = NULL; /* Bad boy - should free, but this is a test suite */ | 115 | paths = NULL; /* Bad boy - should free, but this is a test suite */ |
141 | np_add_parameter(&paths, "/home/groups"); | 116 | np_add_parameter(&paths, "/home/groups"); |
142 | np_add_parameter(&paths, "/var"); | 117 | np_add_parameter(&paths, "/var"); |
143 | np_add_parameter(&paths, "/tmp"); | 118 | np_add_parameter(&paths, "/tmp"); |
@@ -146,31 +121,31 @@ main (int argc, char **argv) | |||
146 | 121 | ||
147 | np_set_best_match(paths, dummy_mount_list, true); | 122 | np_set_best_match(paths, dummy_mount_list, true); |
148 | for (p = paths; p; p = p->name_next) { | 123 | for (p = paths; p; p = p->name_next) { |
149 | if (! strcmp(p->name, "/home/groups")) { | 124 | if (!strcmp(p->name, "/home/groups")) { |
150 | ok( ! p->best_match , "/home/groups correctly not found"); | 125 | ok(!p->best_match, "/home/groups correctly not found"); |
151 | } else if (! strcmp(p->name, "/var")) { | 126 | } else if (!strcmp(p->name, "/var")) { |
152 | ok( p->best_match, "/var found"); | 127 | ok(p->best_match, "/var found"); |
153 | } else if (! strcmp(p->name, "/tmp")) { | 128 | } else if (!strcmp(p->name, "/tmp")) { |
154 | ok(! p->best_match, "/tmp correctly not found"); | 129 | ok(!p->best_match, "/tmp correctly not found"); |
155 | } else if (! strcmp(p->name, "/home/tonvoon")) { | 130 | } else if (!strcmp(p->name, "/home/tonvoon")) { |
156 | ok(! p->best_match, "/home/tonvoon not found"); | 131 | ok(!p->best_match, "/home/tonvoon not found"); |
157 | } else if (! strcmp(p->name, "/home")) { | 132 | } else if (!strcmp(p->name, "/home")) { |
158 | ok( p->best_match, "/home found"); | 133 | ok(p->best_match, "/home found"); |
159 | } | 134 | } |
160 | } | 135 | } |
161 | 136 | ||
162 | /* test deleting first element in paths */ | 137 | /* test deleting first element in paths */ |
163 | paths = np_del_parameter(paths, NULL); | 138 | paths = np_del_parameter(paths, NULL); |
164 | for (p = paths; p; p = p->name_next) { | 139 | for (p = paths; p; p = p->name_next) { |
165 | if (! strcmp(p->name, "/home/groups")) | 140 | if (!strcmp(p->name, "/home/groups")) |
166 | found = 1; | 141 | found = 1; |
167 | } | 142 | } |
168 | ok(found == 0, "first element successfully deleted"); | 143 | ok(found == 0, "first element successfully deleted"); |
169 | found = 0; | 144 | found = 0; |
170 | 145 | ||
171 | p=paths; | 146 | p = paths; |
172 | while (p) { | 147 | while (p) { |
173 | if (! strcmp(p->name, "/tmp")) | 148 | if (!strcmp(p->name, "/tmp")) |
174 | p = np_del_parameter(p, prev); | 149 | p = np_del_parameter(p, prev); |
175 | else { | 150 | else { |
176 | prev = p; | 151 | prev = p; |
@@ -179,7 +154,7 @@ main (int argc, char **argv) | |||
179 | } | 154 | } |
180 | 155 | ||
181 | for (p = paths; p; p = p->name_next) { | 156 | for (p = paths; p; p = p->name_next) { |
182 | if (! strcmp(p->name, "/tmp")) | 157 | if (!strcmp(p->name, "/tmp")) |
183 | found = 1; | 158 | found = 1; |
184 | if (p->name_next) | 159 | if (p->name_next) |
185 | prev = p; | 160 | prev = p; |
@@ -190,7 +165,7 @@ main (int argc, char **argv) | |||
190 | 165 | ||
191 | p = np_del_parameter(last, prev); | 166 | p = np_del_parameter(last, prev); |
192 | for (p = paths; p; p = p->name_next) { | 167 | for (p = paths; p; p = p->name_next) { |
193 | if (! strcmp(p->name, "/home")) | 168 | if (!strcmp(p->name, "/home")) |
194 | found = 1; | 169 | found = 1; |
195 | last = p; | 170 | last = p; |
196 | count++; | 171 | count++; |
@@ -198,27 +173,20 @@ main (int argc, char **argv) | |||
198 | ok(found == 0, "last (/home) element successfully deleted"); | 173 | ok(found == 0, "last (/home) element successfully deleted"); |
199 | ok(count == 2, "two elements remaining"); | 174 | ok(count == 2, "two elements remaining"); |
200 | 175 | ||
201 | |||
202 | return exit_status(); | 176 | return exit_status(); |
203 | } | 177 | } |
204 | 178 | ||
205 | 179 | void np_test_mount_entry_regex(struct mount_entry *dummy_mount_list, char *regstr, int cflags, int expect, char *desc) { | |
206 | void | ||
207 | np_test_mount_entry_regex (struct mount_entry *dummy_mount_list, char *regstr, int cflags, int expect, char *desc) | ||
208 | { | ||
209 | int matches = 0; | 180 | int matches = 0; |
210 | regex_t re; | 181 | regex_t re; |
211 | struct mount_entry *me; | 182 | struct mount_entry *me; |
212 | if (regcomp(&re,regstr, cflags) == 0) { | 183 | if (regcomp(&re, regstr, cflags) == 0) { |
213 | for (me = dummy_mount_list; me; me= me->me_next) { | 184 | for (me = dummy_mount_list; me; me = me->me_next) { |
214 | if(np_regex_match_mount_entry(me,&re)) | 185 | if (np_regex_match_mount_entry(me, &re)) |
215 | matches++; | 186 | matches++; |
216 | } | 187 | } |
217 | ok( matches == expect, | 188 | ok(matches == expect, "%s '%s' matched %i/3 entries. ok: %i/3", desc, regstr, expect, matches); |
218 | "%s '%s' matched %i/3 entries. ok: %i/3", | ||
219 | desc, regstr, expect, matches); | ||
220 | 189 | ||
221 | } else | 190 | } else |
222 | ok ( false, "regex '%s' not compilable", regstr); | 191 | ok(false, "regex '%s' not compilable", regstr); |
223 | } | 192 | } |
224 | |||
diff --git a/lib/tests/test_generic_output b/lib/tests/test_generic_output new file mode 100755 index 0000000..51e299a --- /dev/null +++ b/lib/tests/test_generic_output | |||
Binary files differ | |||
diff --git a/lib/tests/test_ini1.c b/lib/tests/test_ini1.c index 6843bac..246c125 100644 --- a/lib/tests/test_ini1.c +++ b/lib/tests/test_ini1.c | |||
@@ -1,20 +1,20 @@ | |||
1 | /***************************************************************************** | 1 | /***************************************************************************** |
2 | * | 2 | * |
3 | * This program is free software: you can redistribute it and/or modify | 3 | * This program is free software: you can redistribute it and/or modify |
4 | * it under the terms of the GNU General Public License as published by | 4 | * it under the terms of the GNU General Public License as published by |
5 | * the Free Software Foundation, either version 3 of the License, or | 5 | * the Free Software Foundation, either version 3 of the License, or |
6 | * (at your option) any later version. | 6 | * (at your option) any later version. |
7 | * | 7 | * |
8 | * This program is distributed in the hope that it will be useful, | 8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. | 11 | * GNU General Public License for more details. |
12 | * | 12 | * |
13 | * You should have received a copy of the GNU General Public License | 13 | * You should have received a copy of the GNU General Public License |
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
15 | * | 15 | * |
16 | * | 16 | * |
17 | *****************************************************************************/ | 17 | *****************************************************************************/ |
18 | 18 | ||
19 | #include "common.h" | 19 | #include "common.h" |
20 | #include "utils_base.h" | 20 | #include "utils_base.h" |
@@ -29,81 +29,93 @@ void my_free(char *string) { | |||
29 | } | 29 | } |
30 | } | 30 | } |
31 | 31 | ||
32 | char* | 32 | char *list2str(np_arg_list *optlst) { |
33 | list2str(np_arg_list *optlst) | 33 | char *optstr = NULL; |
34 | { | ||
35 | char *optstr=NULL; | ||
36 | np_arg_list *optltmp; | 34 | np_arg_list *optltmp; |
37 | 35 | ||
38 | /* Put everything as a space-separated string */ | 36 | /* Put everything as a space-separated string */ |
39 | asprintf(&optstr, ""); | 37 | asprintf(&optstr, ""); |
40 | while (optlst) { | 38 | while (optlst) { |
41 | asprintf(&optstr, "%s%s ", optstr, optlst->arg); | 39 | asprintf(&optstr, "%s%s ", optstr, optlst->arg); |
42 | optltmp=optlst; | 40 | optltmp = optlst; |
43 | optlst=optlst->next; | 41 | optlst = optlst->next; |
44 | free(optltmp); | 42 | free(optltmp); |
45 | } | 43 | } |
46 | /* Strip last whitespace */ | 44 | /* Strip last whitespace */ |
47 | if (strlen(optstr)>1) optstr[strlen(optstr)-1]='\0'; | 45 | if (strlen(optstr) > 1) |
46 | optstr[strlen(optstr) - 1] = '\0'; | ||
48 | 47 | ||
49 | return optstr; | 48 | return optstr; |
50 | } | 49 | } |
51 | 50 | ||
52 | int | 51 | int main(int argc, char **argv) { |
53 | main (int argc, char **argv) | 52 | char *optstr = NULL; |
54 | { | ||
55 | char *optstr=NULL; | ||
56 | 53 | ||
57 | plan_tests(12); | 54 | plan_tests(12); |
58 | 55 | ||
59 | optstr=list2str(np_get_defaults("section@./config-tiny.ini", "check_disk")); | 56 | optstr = list2str(np_get_defaults("section@./config-tiny.ini", "check_disk")); |
60 | ok( !strcmp(optstr, "--one=two --Foo=Bar --this=Your Mother! --blank"), "config-tiny.ini's section as expected"); | 57 | ok(!strcmp(optstr, "--one=two --Foo=Bar --this=Your Mother! --blank"), "config-tiny.ini's section as expected"); |
61 | my_free(optstr); | 58 | my_free(optstr); |
62 | 59 | ||
63 | optstr=list2str(np_get_defaults("@./config-tiny.ini", "section")); | 60 | optstr = list2str(np_get_defaults("@./config-tiny.ini", "section")); |
64 | ok( !strcmp(optstr, "--one=two --Foo=Bar --this=Your Mother! --blank"), "Used default section name, without specific"); | 61 | ok(!strcmp(optstr, "--one=two --Foo=Bar --this=Your Mother! --blank"), "Used default section name, without specific"); |
65 | my_free(optstr); | 62 | my_free(optstr); |
66 | 63 | ||
67 | optstr=list2str(np_get_defaults("Section Two@./config-tiny.ini", "check_disk")); | 64 | optstr = list2str(np_get_defaults("Section Two@./config-tiny.ini", "check_disk")); |
68 | ok( !strcmp(optstr, "--something else=blah --remove=whitespace"), "config-tiny.ini's Section Two as expected"); | 65 | ok(!strcmp(optstr, "--something else=blah --remove=whitespace"), "config-tiny.ini's Section Two as expected"); |
69 | my_free(optstr); | 66 | my_free(optstr); |
70 | 67 | ||
71 | optstr=list2str(np_get_defaults("/path/to/file.txt@./config-tiny.ini", "check_disk")); | 68 | optstr = list2str(np_get_defaults("/path/to/file.txt@./config-tiny.ini", "check_disk")); |
72 | ok( !strcmp(optstr, "--this=that"), "config-tiny.ini's filename as section name"); | 69 | ok(!strcmp(optstr, "--this=that"), "config-tiny.ini's filename as section name"); |
73 | my_free(optstr); | 70 | my_free(optstr); |
74 | 71 | ||
75 | optstr=list2str(np_get_defaults("section2@./config-tiny.ini", "check_disk")); | 72 | optstr = list2str(np_get_defaults("section2@./config-tiny.ini", "check_disk")); |
76 | ok( !strcmp(optstr, "--this=that"), "config-tiny.ini's section2 with whitespace before section name"); | 73 | ok(!strcmp(optstr, "--this=that"), "config-tiny.ini's section2 with whitespace before section name"); |
77 | my_free(optstr); | 74 | my_free(optstr); |
78 | 75 | ||
79 | optstr=list2str(np_get_defaults("section3@./config-tiny.ini", "check_disk")); | 76 | optstr = list2str(np_get_defaults("section3@./config-tiny.ini", "check_disk")); |
80 | ok( !strcmp(optstr, "--this=that"), "config-tiny.ini's section3 with whitespace after section name"); | 77 | ok(!strcmp(optstr, "--this=that"), "config-tiny.ini's section3 with whitespace after section name"); |
81 | my_free(optstr); | 78 | my_free(optstr); |
82 | 79 | ||
83 | optstr=list2str(np_get_defaults("check_mysql@./plugin.ini", "check_disk")); | 80 | optstr = list2str(np_get_defaults("check_mysql@./plugin.ini", "check_disk")); |
84 | ok( !strcmp(optstr, "--username=operator --password=secret"), "plugin.ini's check_mysql as expected"); | 81 | ok(!strcmp(optstr, "--username=operator --password=secret"), "plugin.ini's check_mysql as expected"); |
85 | my_free(optstr); | 82 | my_free(optstr); |
86 | 83 | ||
87 | optstr=list2str(np_get_defaults("check_mysql2@./plugin.ini", "check_disk")); | 84 | optstr = list2str(np_get_defaults("check_mysql2@./plugin.ini", "check_disk")); |
88 | ok( !strcmp(optstr, "-u=admin -p=secret"), "plugin.ini's check_mysql2 as expected"); | 85 | ok(!strcmp(optstr, "-u=admin -p=secret"), "plugin.ini's check_mysql2 as expected"); |
89 | my_free(optstr); | 86 | my_free(optstr); |
90 | 87 | ||
91 | optstr=list2str(np_get_defaults("check space_and_flags@./plugin.ini", "check_disk")); | 88 | optstr = list2str(np_get_defaults("check space_and_flags@./plugin.ini", "check_disk")); |
92 | ok( !strcmp(optstr, "--foo=bar -a -b --bar"), "plugin.ini space in stanza and flag arguments"); | 89 | ok(!strcmp(optstr, "--foo=bar -a -b --bar"), "plugin.ini space in stanza and flag arguments"); |
93 | my_free(optstr); | 90 | my_free(optstr); |
94 | 91 | ||
95 | optstr=list2str(np_get_defaults("Section Two@./config-dos.ini", "check_disk")); | 92 | optstr = list2str(np_get_defaults("Section Two@./config-dos.ini", "check_disk")); |
96 | ok( !strcmp(optstr, "--something else=blah --remove=whitespace"), "config-dos.ini's Section Two as expected"); | 93 | ok(!strcmp(optstr, "--something else=blah --remove=whitespace"), "config-dos.ini's Section Two as expected"); |
97 | my_free(optstr); | 94 | my_free(optstr); |
98 | 95 | ||
99 | optstr=list2str(np_get_defaults("section_twice@./plugin.ini", "check_disk")); | 96 | optstr = list2str(np_get_defaults("section_twice@./plugin.ini", "check_disk")); |
100 | ok( !strcmp(optstr, "--foo=bar --bar=foo"), "plugin.ini's section_twice defined twice in the file"); | 97 | ok(!strcmp(optstr, "--foo=bar --bar=foo"), "plugin.ini's section_twice defined twice in the file"); |
101 | my_free(optstr); | 98 | my_free(optstr); |
102 | 99 | ||
103 | optstr=list2str(np_get_defaults("tcp_long_lines@plugins.ini", "check_tcp")); | 100 | optstr = list2str(np_get_defaults("tcp_long_lines@plugins.ini", "check_tcp")); |
104 | 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"); | 101 | 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 " |
102 | "BAZ yadda yadda yadda Foo bar BAZ yadda yadda " | ||
103 | "yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda " | ||
104 | "yadda yadda Foo bar BAZ yadda yadda yadda Foo " | ||
105 | "bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda " | ||
106 | "yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ " | ||
107 | "yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda --expect=Foo bar BAZ yadda yadda " | ||
108 | "yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ " | ||
109 | "yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo " | ||
110 | "bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda " | ||
111 | "yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda " | ||
112 | "yadda yadda Foo bar BAZ yadda yadda yadda Foo " | ||
113 | "bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda " | ||
114 | "yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ " | ||
115 | "yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo " | ||
116 | "bar BAZ yadda yadda yadda --jail"), | ||
117 | "Long options"); | ||
105 | my_free(optstr); | 118 | my_free(optstr); |
106 | 119 | ||
107 | return exit_status(); | 120 | return exit_status(); |
108 | } | 121 | } |
109 | |||
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 @@ | |||
1 | /***************************************************************************** | 1 | /***************************************************************************** |
2 | * | 2 | * |
3 | * This program is free software: you can redistribute it and/or modify | 3 | * This program is free software: you can redistribute it and/or modify |
4 | * it under the terms of the GNU General Public License as published by | 4 | * it under the terms of the GNU General Public License as published by |
5 | * the Free Software Foundation, either version 3 of the License, or | 5 | * the Free Software Foundation, either version 3 of the License, or |
6 | * (at your option) any later version. | 6 | * (at your option) any later version. |
7 | * | 7 | * |
8 | * This program is distributed in the hope that it will be useful, | 8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. | 11 | * GNU General Public License for more details. |
12 | * | 12 | * |
13 | * You should have received a copy of the GNU General Public License | 13 | * You should have received a copy of the GNU General Public License |
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
15 | * | 15 | * |
16 | * | 16 | * |
17 | *****************************************************************************/ | 17 | *****************************************************************************/ |
18 | 18 | ||
19 | #include "parse_ini.h" | 19 | #include "parse_ini.h" |
20 | 20 | ||
21 | int | 21 | int main(int argc, char **argv) { |
22 | main (int argc, char **argv) | ||
23 | { | ||
24 | 22 | ||
25 | /* | 23 | /* |
26 | * This is for testing arguments expected to die. | 24 | * This is for testing arguments expected to die. |
@@ -30,4 +28,3 @@ main (int argc, char **argv) | |||
30 | 28 | ||
31 | return 0; | 29 | return 0; |
32 | } | 30 | } |
33 | |||
diff --git a/lib/tests/test_opts1.c b/lib/tests/test_opts1.c index 077c5b6..984183d 100644 --- a/lib/tests/test_opts1.c +++ b/lib/tests/test_opts1.c | |||
@@ -1,19 +1,19 @@ | |||
1 | /***************************************************************************** | 1 | /***************************************************************************** |
2 | * | 2 | * |
3 | * This program is free software: you can redistribute it and/or modify | 3 | * This program is free software: you can redistribute it and/or modify |
4 | * it under the terms of the GNU General Public License as published by | 4 | * it under the terms of the GNU General Public License as published by |
5 | * the Free Software Foundation, either version 3 of the License, or | 5 | * the Free Software Foundation, either version 3 of the License, or |
6 | * (at your option) any later version. | 6 | * (at your option) any later version. |
7 | * | 7 | * |
8 | * This program is distributed in the hope that it will be useful, | 8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. | 11 | * GNU General Public License for more details. |
12 | * | 12 | * |
13 | * You should have received a copy of the GNU General Public License | 13 | * You should have received a copy of the GNU General Public License |
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
15 | * | 15 | * |
16 | *****************************************************************************/ | 16 | *****************************************************************************/ |
17 | 17 | ||
18 | #include "common.h" | 18 | #include "common.h" |
19 | #include "utils_base.h" | 19 | #include "utils_base.h" |
@@ -40,23 +40,24 @@ void my_free(int *argc, char **newargv, char **argv) { | |||
40 | #else | 40 | #else |
41 | void my_free(int *argc, char **newargv, char **argv) { | 41 | void my_free(int *argc, char **newargv, char **argv) { |
42 | /* Free stuff (and print while we're at it) */ | 42 | /* Free stuff (and print while we're at it) */ |
43 | int i, freeflag=1; | 43 | int i, freeflag = 1; |
44 | printf (" Arg(%i): ", *argc+1); | 44 | printf(" Arg(%i): ", *argc + 1); |
45 | printf ("'%s' ", newargv[0]); | 45 | printf("'%s' ", newargv[0]); |
46 | for (i=1; i<*argc; i++) { | 46 | for (i = 1; i < *argc; i++) { |
47 | printf ("'%s' ", newargv[i]); | 47 | printf("'%s' ", newargv[i]); |
48 | /* Stop freeing when we get to the start of the original array */ | 48 | /* Stop freeing when we get to the start of the original array */ |
49 | if (freeflag) { | 49 | if (freeflag) { |
50 | if (newargv[i] == argv[1]) | 50 | if (newargv[i] == argv[1]) |
51 | freeflag=0; | 51 | freeflag = 0; |
52 | else | 52 | else |
53 | free(newargv[i]); | 53 | free(newargv[i]); |
54 | } | 54 | } |
55 | } | 55 | } |
56 | printf ("\n"); | 56 | printf("\n"); |
57 | /* Free only if it's a different array */ | 57 | /* Free only if it's a different array */ |
58 | if (newargv != argv) free(newargv); | 58 | if (newargv != argv) |
59 | *argc=0; | 59 | free(newargv); |
60 | *argc = 0; | ||
60 | } | 61 | } |
61 | #endif | 62 | #endif |
62 | 63 | ||
@@ -67,9 +68,10 @@ int array_diff(int i1, char **a1, int i2, char **a2) { | |||
67 | printf(" Argument count doesn't match!\n"); | 68 | printf(" Argument count doesn't match!\n"); |
68 | return 0; | 69 | return 0; |
69 | } | 70 | } |
70 | for (i=0; i<=i1; i++) { | 71 | for (i = 0; i <= i1; i++) { |
71 | if (a1[i]==NULL && a2[i]==NULL) continue; | 72 | if (a1[i] == NULL && a2[i] == NULL) |
72 | if (a1[i]==NULL || a2[i]==NULL) { | 73 | continue; |
74 | if (a1[i] == NULL || a2[i] == NULL) { | ||
73 | printf(" Argument # %i null in one array!\n", i); | 75 | printf(" Argument # %i null in one array!\n", i); |
74 | return 0; | 76 | return 0; |
75 | } | 77 | } |
@@ -81,59 +83,58 @@ int array_diff(int i1, char **a1, int i2, char **a2) { | |||
81 | return 1; | 83 | return 1; |
82 | } | 84 | } |
83 | 85 | ||
84 | int | 86 | int main(int argc, char **argv) { |
85 | main (int argc, char **argv) | 87 | char **argv_new = NULL; |
86 | { | ||
87 | char **argv_new=NULL; | ||
88 | int i, argc_test; | 88 | int i, argc_test; |
89 | 89 | ||
90 | plan_tests(5); | 90 | plan_tests(5); |
91 | 91 | ||
92 | { | 92 | { |
93 | char *argv_test[] = {"prog_name", (char *) NULL}; | 93 | char *argv_test[] = {"prog_name", (char *)NULL}; |
94 | argc_test=1; | 94 | argc_test = 1; |
95 | char *argv_known[] = {"prog_name", (char *) NULL}; | 95 | char *argv_known[] = {"prog_name", (char *)NULL}; |
96 | argv_new=np_extra_opts(&argc_test, argv_test, "check_disk"); | 96 | argv_new = np_extra_opts(&argc_test, argv_test, "check_disk"); |
97 | ok(array_diff(argc_test, argv_new, 1, argv_known), "No opts, returns correct argv/argc"); | 97 | ok(array_diff(argc_test, argv_new, 1, argv_known), "No opts, returns correct argv/argc"); |
98 | my_free(&argc_test, argv_new, argv_test); | 98 | my_free(&argc_test, argv_new, argv_test); |
99 | } | 99 | } |
100 | 100 | ||
101 | { | 101 | { |
102 | char *argv_test[] = {"prog_name", "arg1", "--arg2=val1", "--arg3", "val2", (char *) NULL}; | 102 | char *argv_test[] = {"prog_name", "arg1", "--arg2=val1", "--arg3", "val2", (char *)NULL}; |
103 | argc_test=5; | 103 | argc_test = 5; |
104 | char *argv_known[] = {"prog_name", "arg1", "--arg2=val1", "--arg3", "val2", (char *) NULL}; | 104 | char *argv_known[] = {"prog_name", "arg1", "--arg2=val1", "--arg3", "val2", (char *)NULL}; |
105 | argv_new=np_extra_opts(&argc_test, argv_test, "check_disk"); | 105 | argv_new = np_extra_opts(&argc_test, argv_test, "check_disk"); |
106 | ok(array_diff(argc_test, argv_new, 5, argv_known), "No extra opts, verbatim copy of argv"); | 106 | ok(array_diff(argc_test, argv_new, 5, argv_known), "No extra opts, verbatim copy of argv"); |
107 | my_free(&argc_test, argv_new, argv_test); | 107 | my_free(&argc_test, argv_new, argv_test); |
108 | } | 108 | } |
109 | 109 | ||
110 | { | 110 | { |
111 | char *argv_test[] = {"prog_name", "--extra-opts=@./config-opts.ini", (char *) NULL}; | 111 | char *argv_test[] = {"prog_name", "--extra-opts=@./config-opts.ini", (char *)NULL}; |
112 | argc_test=2; | 112 | argc_test = 2; |
113 | char *argv_known[] = {"prog_name", "--foo=Bar", "--this=Your Mother!", "--blank", (char *) NULL}; | 113 | char *argv_known[] = {"prog_name", "--foo=Bar", "--this=Your Mother!", "--blank", (char *)NULL}; |
114 | argv_new=np_extra_opts(&argc_test, argv_test, "check_disk"); | 114 | argv_new = np_extra_opts(&argc_test, argv_test, "check_disk"); |
115 | ok(array_diff(argc_test, argv_new, 4, argv_known), "Only extra opts using default section"); | 115 | ok(array_diff(argc_test, argv_new, 4, argv_known), "Only extra opts using default section"); |
116 | my_free(&argc_test, argv_new, argv_test); | 116 | my_free(&argc_test, argv_new, argv_test); |
117 | } | 117 | } |
118 | 118 | ||
119 | { | 119 | { |
120 | char *argv_test[] = {"prog_name", "--extra-opts=sect1@./config-opts.ini", "--extra-opts", "sect2@./config-opts.ini", (char *) NULL}; | 120 | char *argv_test[] = {"prog_name", "--extra-opts=sect1@./config-opts.ini", "--extra-opts", "sect2@./config-opts.ini", (char *)NULL}; |
121 | argc_test=4; | 121 | argc_test = 4; |
122 | char *argv_known[] = {"prog_name", "--one=two", "--something else=oops", "--this=that", (char *) NULL}; | 122 | char *argv_known[] = {"prog_name", "--one=two", "--something else=oops", "--this=that", (char *)NULL}; |
123 | argv_new=np_extra_opts(&argc_test, argv_test, "check_disk"); | 123 | argv_new = np_extra_opts(&argc_test, argv_test, "check_disk"); |
124 | ok(array_diff(argc_test, argv_new, 4, argv_known), "Only extra opts specified twice"); | 124 | ok(array_diff(argc_test, argv_new, 4, argv_known), "Only extra opts specified twice"); |
125 | my_free(&argc_test, argv_new, argv_test); | 125 | my_free(&argc_test, argv_new, argv_test); |
126 | } | 126 | } |
127 | 127 | ||
128 | { | 128 | { |
129 | char *argv_test[] = {"prog_name", "--arg1=val1", "--extra-opts=@./config-opts.ini", "--extra-opts", "sect1@./config-opts.ini", "--arg2", (char *) NULL}; | 129 | char *argv_test[] = {"prog_name", "--arg1=val1", "--extra-opts=@./config-opts.ini", "--extra-opts", "sect1@./config-opts.ini", |
130 | argc_test=6; | 130 | "--arg2", (char *)NULL}; |
131 | char *argv_known[] = {"prog_name", "--foo=Bar", "--this=Your Mother!", "--blank", "--one=two", "--arg1=val1", "--arg2", (char *) NULL}; | 131 | argc_test = 6; |
132 | argv_new=np_extra_opts(&argc_test, argv_test, "check_disk"); | 132 | char *argv_known[] = {"prog_name", "--foo=Bar", "--this=Your Mother!", "--blank", "--one=two", |
133 | "--arg1=val1", "--arg2", (char *)NULL}; | ||
134 | argv_new = np_extra_opts(&argc_test, argv_test, "check_disk"); | ||
133 | ok(array_diff(argc_test, argv_new, 7, argv_known), "twice extra opts using two sections"); | 135 | ok(array_diff(argc_test, argv_new, 7, argv_known), "twice extra opts using two sections"); |
134 | my_free(&argc_test, argv_new, argv_test); | 136 | my_free(&argc_test, argv_new, argv_test); |
135 | } | 137 | } |
136 | 138 | ||
137 | return exit_status(); | 139 | return exit_status(); |
138 | } | 140 | } |
139 | |||
diff --git a/lib/tests/test_opts2.c b/lib/tests/test_opts2.c index 780220e..2349661 100644 --- a/lib/tests/test_opts2.c +++ b/lib/tests/test_opts2.c | |||
@@ -1,19 +1,19 @@ | |||
1 | /***************************************************************************** | 1 | /***************************************************************************** |
2 | * | 2 | * |
3 | * This program is free software: you can redistribute it and/or modify | 3 | * This program is free software: you can redistribute it and/or modify |
4 | * it under the terms of the GNU General Public License as published by | 4 | * it under the terms of the GNU General Public License as published by |
5 | * the Free Software Foundation, either version 3 of the License, or | 5 | * the Free Software Foundation, either version 3 of the License, or |
6 | * (at your option) any later version. | 6 | * (at your option) any later version. |
7 | * | 7 | * |
8 | * This program is distributed in the hope that it will be useful, | 8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. | 11 | * GNU General Public License for more details. |
12 | * | 12 | * |
13 | * You should have received a copy of the GNU General Public License | 13 | * You should have received a copy of the GNU General Public License |
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
15 | * | 15 | * |
16 | *****************************************************************************/ | 16 | *****************************************************************************/ |
17 | 17 | ||
18 | #include "common.h" | 18 | #include "common.h" |
19 | #include "utils_base.h" | 19 | #include "utils_base.h" |
@@ -23,23 +23,24 @@ | |||
23 | 23 | ||
24 | void my_free(int *argc, char **newargv, char **argv) { | 24 | void my_free(int *argc, char **newargv, char **argv) { |
25 | /* Free stuff (and print while we're at it) */ | 25 | /* Free stuff (and print while we're at it) */ |
26 | int i, freeflag=1; | 26 | int i, freeflag = 1; |
27 | printf (" Arg(%i): ", *argc+1); | 27 | printf(" Arg(%i): ", *argc + 1); |
28 | printf ("'%s' ", newargv[0]); | 28 | printf("'%s' ", newargv[0]); |
29 | for (i=1; i<*argc; i++) { | 29 | for (i = 1; i < *argc; i++) { |
30 | printf ("'%s' ", newargv[i]); | 30 | printf("'%s' ", newargv[i]); |
31 | /* Stop freeing when we get to the start of the original array */ | 31 | /* Stop freeing when we get to the start of the original array */ |
32 | if (freeflag) { | 32 | if (freeflag) { |
33 | if (newargv[i] == argv[1]) | 33 | if (newargv[i] == argv[1]) |
34 | freeflag=0; | 34 | freeflag = 0; |
35 | else | 35 | else |
36 | free(newargv[i]); | 36 | free(newargv[i]); |
37 | } | 37 | } |
38 | } | 38 | } |
39 | printf ("\n"); | 39 | printf("\n"); |
40 | /* Free only if it's a different array */ | 40 | /* Free only if it's a different array */ |
41 | if (newargv != argv) free(newargv); | 41 | if (newargv != argv) |
42 | *argc=0; | 42 | free(newargv); |
43 | *argc = 0; | ||
43 | } | 44 | } |
44 | 45 | ||
45 | int array_diff(int i1, char **a1, int i2, char **a2) { | 46 | 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) { | |||
49 | printf(" Argument count doesn't match!\n"); | 50 | printf(" Argument count doesn't match!\n"); |
50 | return 0; | 51 | return 0; |
51 | } | 52 | } |
52 | for (i=0; i<=i1; i++) { | 53 | for (i = 0; i <= i1; i++) { |
53 | if (a1[i]==NULL && a2[i]==NULL) continue; | 54 | if (a1[i] == NULL && a2[i] == NULL) |
54 | if (a1[i]==NULL || a2[i]==NULL) { | 55 | continue; |
56 | if (a1[i] == NULL || a2[i] == NULL) { | ||
55 | printf(" Argument # %i null in one array!\n", i); | 57 | printf(" Argument # %i null in one array!\n", i); |
56 | return 0; | 58 | return 0; |
57 | } | 59 | } |
@@ -63,59 +65,77 @@ int array_diff(int i1, char **a1, int i2, char **a2) { | |||
63 | return 1; | 65 | return 1; |
64 | } | 66 | } |
65 | 67 | ||
66 | int | 68 | int main(int argc, char **argv) { |
67 | main (int argc, char **argv) | 69 | char **argv_new = NULL; |
68 | { | ||
69 | char **argv_new=NULL; | ||
70 | int i, argc_test; | 70 | int i, argc_test; |
71 | 71 | ||
72 | plan_tests(5); | 72 | plan_tests(5); |
73 | 73 | ||
74 | { | 74 | { |
75 | char *argv_test[] = {"prog_name", "arg1", "--extra-opts", "--arg3", "val2", (char *) NULL}; | 75 | char *argv_test[] = {"prog_name", "arg1", "--extra-opts", "--arg3", "val2", (char *)NULL}; |
76 | argc_test=5; | 76 | argc_test = 5; |
77 | char *argv_known[] = {"prog_name", "--foo=bar", "arg1", "--arg3", "val2", (char *) NULL}; | 77 | char *argv_known[] = {"prog_name", "--foo=bar", "arg1", "--arg3", "val2", (char *)NULL}; |
78 | argv_new=np_extra_opts(&argc_test, argv_test, "check_disk"); | 78 | argv_new = np_extra_opts(&argc_test, argv_test, "check_disk"); |
79 | ok(array_diff(argc_test, argv_new, 5, argv_known), "Default section 1"); | 79 | ok(array_diff(argc_test, argv_new, 5, argv_known), "Default section 1"); |
80 | my_free(&argc_test, argv_new, argv_test); | 80 | my_free(&argc_test, argv_new, argv_test); |
81 | } | 81 | } |
82 | 82 | ||
83 | { | 83 | { |
84 | char *argv_test[] = {"prog_name", "--extra-opts", (char *) NULL}; | 84 | char *argv_test[] = {"prog_name", "--extra-opts", (char *)NULL}; |
85 | argc_test=2; | 85 | argc_test = 2; |
86 | char *argv_known[] = {"prog_name", "--foo=bar", (char *) NULL}; | 86 | char *argv_known[] = {"prog_name", "--foo=bar", (char *)NULL}; |
87 | argv_new=np_extra_opts(&argc_test, argv_test, "check_disk"); | 87 | argv_new = np_extra_opts(&argc_test, argv_test, "check_disk"); |
88 | ok(array_diff(argc_test, argv_new, 2, argv_known), "Default section 2"); | 88 | ok(array_diff(argc_test, argv_new, 2, argv_known), "Default section 2"); |
89 | my_free(&argc_test, argv_new, argv_test); | 89 | my_free(&argc_test, argv_new, argv_test); |
90 | } | 90 | } |
91 | 91 | ||
92 | { | 92 | { |
93 | char *argv_test[] = {"prog_name", "arg1", "--extra-opts=section1", "--arg3", "val2", (char *) NULL}; | 93 | char *argv_test[] = {"prog_name", "arg1", "--extra-opts=section1", "--arg3", "val2", (char *)NULL}; |
94 | argc_test=5; | 94 | argc_test = 5; |
95 | char *argv_known[] = {"prog_name", "--foobar=baz", "arg1", "--arg3", "val2", (char *) NULL}; | 95 | char *argv_known[] = {"prog_name", "--foobar=baz", "arg1", "--arg3", "val2", (char *)NULL}; |
96 | argv_new=np_extra_opts(&argc_test, argv_test, "check_disk"); | 96 | argv_new = np_extra_opts(&argc_test, argv_test, "check_disk"); |
97 | ok(array_diff(argc_test, argv_new, 5, argv_known), "Default section 3"); | 97 | ok(array_diff(argc_test, argv_new, 5, argv_known), "Default section 3"); |
98 | my_free(&argc_test, argv_new, argv_test); | 98 | my_free(&argc_test, argv_new, argv_test); |
99 | } | 99 | } |
100 | 100 | ||
101 | { | 101 | { |
102 | char *argv_test[] = {"prog_name", "arg1", "--extra-opts", "-arg3", "val2", (char *) NULL}; | 102 | char *argv_test[] = {"prog_name", "arg1", "--extra-opts", "-arg3", "val2", (char *)NULL}; |
103 | argc_test=5; | 103 | argc_test = 5; |
104 | char *argv_known[] = {"prog_name", "--foo=bar", "arg1", "-arg3", "val2", (char *) NULL}; | 104 | char *argv_known[] = {"prog_name", "--foo=bar", "arg1", "-arg3", "val2", (char *)NULL}; |
105 | argv_new=np_extra_opts(&argc_test, argv_test, "check_disk"); | 105 | argv_new = np_extra_opts(&argc_test, argv_test, "check_disk"); |
106 | ok(array_diff(argc_test, argv_new, 5, argv_known), "Default section 4"); | 106 | ok(array_diff(argc_test, argv_new, 5, argv_known), "Default section 4"); |
107 | my_free(&argc_test, argv_new, argv_test); | 107 | my_free(&argc_test, argv_new, argv_test); |
108 | } | 108 | } |
109 | 109 | ||
110 | { | 110 | { |
111 | char *argv_test[] = {"check_tcp", "--extra-opts", "--extra-opts=tcp_long_lines", (char *) NULL}; | 111 | char *argv_test[] = {"check_tcp", "--extra-opts", "--extra-opts=tcp_long_lines", (char *)NULL}; |
112 | argc_test=3; | 112 | argc_test = 3; |
113 | 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}; | 113 | char *argv_known[] = { |
114 | argv_new=np_extra_opts(&argc_test, argv_test, "check_tcp"); | 114 | "check_tcp", |
115 | "--timeout=10", | ||
116 | "--escape", | ||
117 | "--send=Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda " | ||
118 | "yadda Foo bar BAZ yadda " | ||
119 | "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 " | ||
120 | "yadda Foo bar BAZ " | ||
121 | "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 " | ||
122 | "yadda yadda Foo bar " | ||
123 | "BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda", | ||
124 | "--expect=Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda " | ||
125 | "yadda Foo bar BAZ yadda " | ||
126 | "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 " | ||
127 | "yadda Foo bar BAZ " | ||
128 | "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 " | ||
129 | "yadda yadda Foo bar " | ||
130 | "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 " | ||
131 | "yadda yadda yadda Foo " | ||
132 | "bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda", | ||
133 | "--jail", | ||
134 | (char *)NULL}; | ||
135 | argv_new = np_extra_opts(&argc_test, argv_test, "check_tcp"); | ||
115 | ok(array_diff(argc_test, argv_new, 6, argv_known), "Long lines test"); | 136 | ok(array_diff(argc_test, argv_new, 6, argv_known), "Long lines test"); |
116 | my_free(&argc_test, argv_new, argv_test); | 137 | my_free(&argc_test, argv_new, argv_test); |
117 | } | 138 | } |
118 | 139 | ||
119 | return exit_status(); | 140 | return exit_status(); |
120 | } | 141 | } |
121 | |||
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 @@ | |||
1 | /***************************************************************************** | 1 | /***************************************************************************** |
2 | * | 2 | * |
3 | * This program is free software: you can redistribute it and/or modify | 3 | * This program is free software: you can redistribute it and/or modify |
4 | * it under the terms of the GNU General Public License as published by | 4 | * it under the terms of the GNU General Public License as published by |
5 | * the Free Software Foundation, either version 3 of the License, or | 5 | * the Free Software Foundation, either version 3 of the License, or |
6 | * (at your option) any later version. | 6 | * (at your option) any later version. |
7 | * | 7 | * |
8 | * This program is distributed in the hope that it will be useful, | 8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. | 11 | * GNU General Public License for more details. |
12 | * | 12 | * |
13 | * You should have received a copy of the GNU General Public License | 13 | * You should have received a copy of the GNU General Public License |
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
15 | * | 15 | * |
16 | *****************************************************************************/ | 16 | *****************************************************************************/ |
17 | 17 | ||
18 | #include "extra_opts.h" | 18 | #include "extra_opts.h" |
19 | 19 | ||
20 | int | 20 | int main(int argc, char **argv) { |
21 | main (int argc, char **argv) | ||
22 | { | ||
23 | 21 | ||
24 | /* | 22 | /* |
25 | * This is for testing arguments expected to die. | 23 | * This is for testing arguments expected to die. |
26 | */ | 24 | */ |
27 | argv=np_extra_opts(&argc, argv, argv[0]); | 25 | argv = np_extra_opts(&argc, argv, argv[0]); |
28 | 26 | ||
29 | return 0; | 27 | return 0; |
30 | } | 28 | } |
31 | |||
diff --git a/lib/tests/test_tcp.c b/lib/tests/test_tcp.c index 1954b0f..1b3003e 100644 --- a/lib/tests/test_tcp.c +++ b/lib/tests/test_tcp.c | |||
@@ -1,34 +1,32 @@ | |||
1 | /***************************************************************************** | 1 | /***************************************************************************** |
2 | * | 2 | * |
3 | * This program is free software: you can redistribute it and/or modify | 3 | * This program is free software: you can redistribute it and/or modify |
4 | * it under the terms of the GNU General Public License as published by | 4 | * it under the terms of the GNU General Public License as published by |
5 | * the Free Software Foundation, either version 3 of the License, or | 5 | * the Free Software Foundation, either version 3 of the License, or |
6 | * (at your option) any later version. | 6 | * (at your option) any later version. |
7 | * | 7 | * |
8 | * This program is distributed in the hope that it will be useful, | 8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. | 11 | * GNU General Public License for more details. |
12 | * | 12 | * |
13 | * You should have received a copy of the GNU General Public License | 13 | * You should have received a copy of the GNU General Public License |
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
15 | * | 15 | * |
16 | * | 16 | * |
17 | *****************************************************************************/ | 17 | *****************************************************************************/ |
18 | 18 | ||
19 | #include "common.h" | 19 | #include "common.h" |
20 | #include "utils_tcp.h" | 20 | #include "utils_tcp.h" |
21 | #include "tap.h" | 21 | #include "tap.h" |
22 | 22 | ||
23 | int | 23 | int main(void) { |
24 | main(void) | ||
25 | { | ||
26 | char **server_expect; | 24 | char **server_expect; |
27 | int server_expect_count = 3; | 25 | int server_expect_count = 3; |
28 | 26 | ||
29 | plan_tests(9); | 27 | plan_tests(9); |
30 | 28 | ||
31 | server_expect = malloc(sizeof(char*) * server_expect_count); | 29 | server_expect = malloc(sizeof(char *) * server_expect_count); |
32 | 30 | ||
33 | server_expect[0] = strdup("AA"); | 31 | server_expect[0] = strdup("AA"); |
34 | server_expect[1] = strdup("bb"); | 32 | server_expect[1] = strdup("bb"); |
@@ -42,17 +40,13 @@ main(void) | |||
42 | "Test matching any string at the beginning (substring match)"); | 40 | "Test matching any string at the beginning (substring match)"); |
43 | ok(np_expect_match("XX bb AA CC XX", server_expect, server_expect_count, NP_MATCH_EXACT) == NP_MATCH_FAILURE, | 41 | ok(np_expect_match("XX bb AA CC XX", server_expect, server_expect_count, NP_MATCH_EXACT) == NP_MATCH_FAILURE, |
44 | "Test with strings not matching at the beginning"); | 42 | "Test with strings not matching at the beginning"); |
45 | ok(np_expect_match("XX CC XX", server_expect, server_expect_count, NP_MATCH_EXACT) == NP_MATCH_FAILURE, | 43 | ok(np_expect_match("XX CC XX", server_expect, server_expect_count, NP_MATCH_EXACT) == NP_MATCH_FAILURE, "Test matching any string"); |
46 | "Test matching any string"); | 44 | ok(np_expect_match("XX", server_expect, server_expect_count, 0) == NP_MATCH_RETRY, "Test not matching any string"); |
47 | ok(np_expect_match("XX", server_expect, server_expect_count, 0) == NP_MATCH_RETRY, | ||
48 | "Test not matching any string"); | ||
49 | ok(np_expect_match("XX AA bb CC XX", server_expect, server_expect_count, NP_MATCH_ALL) == NP_MATCH_SUCCESS, | 45 | ok(np_expect_match("XX AA bb CC XX", server_expect, server_expect_count, NP_MATCH_ALL) == NP_MATCH_SUCCESS, |
50 | "Test matching all strings"); | 46 | "Test matching all strings"); |
51 | ok(np_expect_match("XX bb CC XX", server_expect, server_expect_count, NP_MATCH_ALL) == NP_MATCH_RETRY, | 47 | ok(np_expect_match("XX bb CC XX", server_expect, server_expect_count, NP_MATCH_ALL) == NP_MATCH_RETRY, "Test not matching all strings"); |
52 | "Test not matching all strings"); | ||
53 | ok(np_expect_match("XX XX", server_expect, server_expect_count, NP_MATCH_ALL) == NP_MATCH_RETRY, | 48 | ok(np_expect_match("XX XX", server_expect, server_expect_count, NP_MATCH_ALL) == NP_MATCH_RETRY, |
54 | "Test not matching any string (testing all)"); | 49 | "Test not matching any string (testing all)"); |
55 | 50 | ||
56 | |||
57 | return exit_status(); | 51 | return exit_status(); |
58 | } | 52 | } |
diff --git a/lib/tests/test_utils.c b/lib/tests/test_utils.c index 01afacd..c3150f0 100644 --- a/lib/tests/test_utils.c +++ b/lib/tests/test_utils.c | |||
@@ -1,20 +1,20 @@ | |||
1 | /***************************************************************************** | 1 | /***************************************************************************** |
2 | * | 2 | * |
3 | * This program is free software: you can redistribute it and/or modify | 3 | * This program is free software: you can redistribute it and/or modify |
4 | * it under the terms of the GNU General Public License as published by | 4 | * it under the terms of the GNU General Public License as published by |
5 | * the Free Software Foundation, either version 3 of the License, or | 5 | * the Free Software Foundation, either version 3 of the License, or |
6 | * (at your option) any later version. | 6 | * (at your option) any later version. |
7 | * | 7 | * |
8 | * This program is distributed in the hope that it will be useful, | 8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. | 11 | * GNU General Public License for more details. |
12 | * | 12 | * |
13 | * You should have received a copy of the GNU General Public License | 13 | * You should have received a copy of the GNU General Public License |
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
15 | * | 15 | * |
16 | * | 16 | * |
17 | *****************************************************************************/ | 17 | *****************************************************************************/ |
18 | 18 | ||
19 | #include "common.h" | 19 | #include "common.h" |
20 | #include "utils_base.h" | 20 | #include "utils_base.h" |
@@ -27,331 +27,323 @@ | |||
27 | 27 | ||
28 | #include "utils_base.c" | 28 | #include "utils_base.c" |
29 | 29 | ||
30 | int | 30 | int main(int argc, char **argv) { |
31 | main (int argc, char **argv) | ||
32 | { | ||
33 | char state_path[1024]; | 31 | char state_path[1024]; |
34 | range *range; | 32 | range *range; |
35 | double temp; | 33 | double temp; |
36 | thresholds *thresholds = NULL; | 34 | thresholds *thresholds = NULL; |
37 | int i, rc; | 35 | int i, rc; |
38 | char *temp_string; | 36 | char *temp_string; |
39 | state_key *temp_state_key = NULL; | 37 | state_key *temp_state_key = NULL; |
40 | state_data *temp_state_data; | 38 | state_data *temp_state_data; |
41 | time_t current_time; | 39 | time_t current_time; |
42 | 40 | ||
43 | plan_tests(185); | 41 | plan_tests(185); |
44 | 42 | ||
45 | ok( this_monitoring_plugin==NULL, "monitoring_plugin not initialised"); | 43 | ok(this_monitoring_plugin == NULL, "monitoring_plugin not initialised"); |
46 | 44 | ||
47 | np_init( "check_test", argc, argv ); | 45 | np_init("check_test", argc, argv); |
48 | 46 | ||
49 | ok( this_monitoring_plugin!=NULL, "monitoring_plugin now initialised"); | 47 | ok(this_monitoring_plugin != NULL, "monitoring_plugin now initialised"); |
50 | ok( !strcmp(this_monitoring_plugin->plugin_name, "check_test"), "plugin name initialised" ); | 48 | ok(!strcmp(this_monitoring_plugin->plugin_name, "check_test"), "plugin name initialised"); |
51 | 49 | ||
52 | ok( this_monitoring_plugin->argc==argc, "Argc set" ); | 50 | ok(this_monitoring_plugin->argc == argc, "Argc set"); |
53 | ok( this_monitoring_plugin->argv==argv, "Argv set" ); | 51 | ok(this_monitoring_plugin->argv == argv, "Argv set"); |
54 | 52 | ||
55 | np_set_args(0,0); | 53 | np_set_args(0, 0); |
56 | 54 | ||
57 | ok( this_monitoring_plugin->argc==0, "argc changed" ); | 55 | ok(this_monitoring_plugin->argc == 0, "argc changed"); |
58 | ok( this_monitoring_plugin->argv==0, "argv changed" ); | 56 | ok(this_monitoring_plugin->argv == 0, "argv changed"); |
59 | 57 | ||
60 | np_set_args(argc, argv); | 58 | np_set_args(argc, argv); |
61 | 59 | ||
62 | range = parse_range_string("6"); | 60 | range = parse_range_string("6"); |
63 | ok( range != NULL, "'6' is valid range"); | 61 | ok(range != NULL, "'6' is valid range"); |
64 | ok( range->start == 0, "Start correct"); | 62 | ok(range->start == 0, "Start correct"); |
65 | ok( range->start_infinity == false, "Not using negative infinity"); | 63 | ok(range->start_infinity == false, "Not using negative infinity"); |
66 | ok( range->end == 6, "End correct"); | 64 | ok(range->end == 6, "End correct"); |
67 | ok( range->end_infinity == false, "Not using infinity"); | 65 | ok(range->end_infinity == false, "Not using infinity"); |
68 | free(range); | 66 | free(range); |
69 | 67 | ||
70 | range = parse_range_string("1:12%%"); | 68 | range = parse_range_string("1:12%%"); |
71 | ok( range != NULL, "'1:12%%' is valid - percentages are ignored"); | 69 | ok(range != NULL, "'1:12%%' is valid - percentages are ignored"); |
72 | ok( range->start == 1, "Start correct"); | 70 | ok(range->start == 1, "Start correct"); |
73 | ok( range->start_infinity == false, "Not using negative infinity"); | 71 | ok(range->start_infinity == false, "Not using negative infinity"); |
74 | ok( range->end == 12, "End correct"); | 72 | ok(range->end == 12, "End correct"); |
75 | ok( range->end_infinity == false, "Not using infinity"); | 73 | ok(range->end_infinity == false, "Not using infinity"); |
76 | free(range); | 74 | free(range); |
77 | 75 | ||
78 | range = parse_range_string("-7:23"); | 76 | range = parse_range_string("-7:23"); |
79 | ok( range != NULL, "'-7:23' is valid range"); | 77 | ok(range != NULL, "'-7:23' is valid range"); |
80 | ok( range->start == -7, "Start correct"); | 78 | ok(range->start == -7, "Start correct"); |
81 | ok( range->start_infinity == false, "Not using negative infinity"); | 79 | ok(range->start_infinity == false, "Not using negative infinity"); |
82 | ok( range->end == 23, "End correct"); | 80 | ok(range->end == 23, "End correct"); |
83 | ok( range->end_infinity == false, "Not using infinity"); | 81 | ok(range->end_infinity == false, "Not using infinity"); |
84 | free(range); | 82 | free(range); |
85 | 83 | ||
86 | range = parse_range_string(":5.75"); | 84 | range = parse_range_string(":5.75"); |
87 | ok( range != NULL, "':5.75' is valid range"); | 85 | ok(range != NULL, "':5.75' is valid range"); |
88 | ok( range->start == 0, "Start correct"); | 86 | ok(range->start == 0, "Start correct"); |
89 | ok( range->start_infinity == false, "Not using negative infinity"); | 87 | ok(range->start_infinity == false, "Not using negative infinity"); |
90 | ok( range->end == 5.75, "End correct"); | 88 | ok(range->end == 5.75, "End correct"); |
91 | ok( range->end_infinity == false, "Not using infinity"); | 89 | ok(range->end_infinity == false, "Not using infinity"); |
92 | free(range); | 90 | free(range); |
93 | 91 | ||
94 | range = parse_range_string("~:-95.99"); | 92 | range = parse_range_string("~:-95.99"); |
95 | ok( range != NULL, "~:-95.99' is valid range"); | 93 | ok(range != NULL, "~:-95.99' is valid range"); |
96 | ok( range->start_infinity == true, "Using negative infinity"); | 94 | ok(range->start_infinity == true, "Using negative infinity"); |
97 | ok( range->end == -95.99, "End correct (with rounding errors)"); | 95 | ok(range->end == -95.99, "End correct (with rounding errors)"); |
98 | ok( range->end_infinity == false, "Not using infinity"); | 96 | ok(range->end_infinity == false, "Not using infinity"); |
99 | free(range); | 97 | free(range); |
100 | 98 | ||
101 | range = parse_range_string("12345678901234567890:"); | 99 | range = parse_range_string("12345678901234567890:"); |
102 | temp = atof("12345678901234567890"); /* Can't just use this because number too large */ | 100 | temp = atof("12345678901234567890"); /* Can't just use this because number too large */ |
103 | ok( range != NULL, "'12345678901234567890:' is valid range"); | 101 | ok(range != NULL, "'12345678901234567890:' is valid range"); |
104 | ok( range->start == temp, "Start correct"); | 102 | ok(range->start == temp, "Start correct"); |
105 | ok( range->start_infinity == false, "Not using negative infinity"); | 103 | ok(range->start_infinity == false, "Not using negative infinity"); |
106 | ok( range->end_infinity == true, "Using infinity"); | 104 | ok(range->end_infinity == true, "Using infinity"); |
107 | /* Cannot do a "-1" on temp, as it appears to be same value */ | 105 | /* Cannot do a "-1" on temp, as it appears to be same value */ |
108 | ok( check_range(temp/1.1, range) == true, "12345678901234567890/1.1 - alert"); | 106 | ok(check_range(temp / 1.1, range) == true, "12345678901234567890/1.1 - alert"); |
109 | ok( check_range(temp, range) == false, "12345678901234567890 - no alert"); | 107 | ok(check_range(temp, range) == false, "12345678901234567890 - no alert"); |
110 | ok( check_range(temp*2, range) == false, "12345678901234567890*2 - no alert"); | 108 | ok(check_range(temp * 2, range) == false, "12345678901234567890*2 - no alert"); |
111 | free(range); | 109 | free(range); |
112 | 110 | ||
113 | range = parse_range_string("~:0"); | 111 | range = parse_range_string("~:0"); |
114 | ok( range != NULL, "'~:0' is valid range"); | 112 | ok(range != NULL, "'~:0' is valid range"); |
115 | ok( range->start_infinity == true, "Using negative infinity"); | 113 | ok(range->start_infinity == true, "Using negative infinity"); |
116 | ok( range->end == 0, "End correct"); | 114 | ok(range->end == 0, "End correct"); |
117 | ok( range->end_infinity == false, "Not using infinity"); | 115 | ok(range->end_infinity == false, "Not using infinity"); |
118 | ok( range->alert_on == OUTSIDE, "Will alert on outside of this range"); | 116 | ok(range->alert_on == OUTSIDE, "Will alert on outside of this range"); |
119 | ok( check_range(0.5, range) == true, "0.5 - alert"); | 117 | ok(check_range(0.5, range) == true, "0.5 - alert"); |
120 | ok( check_range(-10, range) == false, "-10 - no alert"); | 118 | ok(check_range(-10, range) == false, "-10 - no alert"); |
121 | ok( check_range(0, range) == false, "0 - no alert"); | 119 | ok(check_range(0, range) == false, "0 - no alert"); |
122 | free(range); | 120 | free(range); |
123 | 121 | ||
124 | range = parse_range_string("@0:657.8210567"); | 122 | range = parse_range_string("@0:657.8210567"); |
125 | ok( range != 0, "@0:657.8210567' is a valid range"); | 123 | ok(range != 0, "@0:657.8210567' is a valid range"); |
126 | ok( range->start == 0, "Start correct"); | 124 | ok(range->start == 0, "Start correct"); |
127 | ok( range->start_infinity == false, "Not using negative infinity"); | 125 | ok(range->start_infinity == false, "Not using negative infinity"); |
128 | ok( range->end == 657.8210567, "End correct"); | 126 | ok(range->end == 657.8210567, "End correct"); |
129 | ok( range->end_infinity == false, "Not using infinity"); | 127 | ok(range->end_infinity == false, "Not using infinity"); |
130 | ok( range->alert_on == INSIDE, "Will alert on inside of this range" ); | 128 | ok(range->alert_on == INSIDE, "Will alert on inside of this range"); |
131 | ok( check_range(32.88, range) == true, "32.88 - alert"); | 129 | ok(check_range(32.88, range) == true, "32.88 - alert"); |
132 | ok( check_range(-2, range) == false, "-2 - no alert"); | 130 | ok(check_range(-2, range) == false, "-2 - no alert"); |
133 | ok( check_range(657.8210567, range) == true, "657.8210567 - alert"); | 131 | ok(check_range(657.8210567, range) == true, "657.8210567 - alert"); |
134 | ok( check_range(0, range) == true, "0 - alert"); | 132 | ok(check_range(0, range) == true, "0 - alert"); |
135 | free(range); | 133 | free(range); |
136 | 134 | ||
137 | range = parse_range_string("@1:1"); | 135 | range = parse_range_string("@1:1"); |
138 | ok( range != NULL, "'@1:1' is a valid range"); | 136 | ok(range != NULL, "'@1:1' is a valid range"); |
139 | ok( range->start == 1, "Start correct"); | 137 | ok(range->start == 1, "Start correct"); |
140 | ok( range->start_infinity == false, "Not using negative infinity"); | 138 | ok(range->start_infinity == false, "Not using negative infinity"); |
141 | ok( range->end == 1, "End correct"); | 139 | ok(range->end == 1, "End correct"); |
142 | ok( range->end_infinity == false, "Not using infinity"); | 140 | ok(range->end_infinity == false, "Not using infinity"); |
143 | ok( range->alert_on == INSIDE, "Will alert on inside of this range" ); | 141 | ok(range->alert_on == INSIDE, "Will alert on inside of this range"); |
144 | ok( check_range(0.5, range) == false, "0.5 - no alert"); | 142 | ok(check_range(0.5, range) == false, "0.5 - no alert"); |
145 | ok( check_range(1, range) == true, "1 - alert"); | 143 | ok(check_range(1, range) == true, "1 - alert"); |
146 | ok( check_range(5.2, range) == false, "5.2 - no alert"); | 144 | ok(check_range(5.2, range) == false, "5.2 - no alert"); |
147 | free(range); | 145 | free(range); |
148 | 146 | ||
149 | range = parse_range_string("1:1"); | 147 | range = parse_range_string("1:1"); |
150 | ok( range != NULL, "'1:1' is a valid range"); | 148 | ok(range != NULL, "'1:1' is a valid range"); |
151 | ok( range->start == 1, "Start correct"); | 149 | ok(range->start == 1, "Start correct"); |
152 | ok( range->start_infinity == false, "Not using negative infinity"); | 150 | ok(range->start_infinity == false, "Not using negative infinity"); |
153 | ok( range->end == 1, "End correct"); | 151 | ok(range->end == 1, "End correct"); |
154 | ok( range->end_infinity == false, "Not using infinity"); | 152 | ok(range->end_infinity == false, "Not using infinity"); |
155 | ok( check_range(0.5, range) == true, "0.5 - alert"); | 153 | ok(check_range(0.5, range) == true, "0.5 - alert"); |
156 | ok( check_range(1, range) == false, "1 - no alert"); | 154 | ok(check_range(1, range) == false, "1 - no alert"); |
157 | ok( check_range(5.2, range) == true, "5.2 - alert"); | 155 | ok(check_range(5.2, range) == true, "5.2 - alert"); |
158 | free(range); | 156 | free(range); |
159 | 157 | ||
160 | range = parse_range_string("2:1"); | 158 | range = parse_range_string("2:1"); |
161 | ok( range == NULL, "'2:1' rejected"); | 159 | ok(range == NULL, "'2:1' rejected"); |
162 | 160 | ||
163 | rc = _set_thresholds(&thresholds, NULL, NULL); | 161 | rc = _set_thresholds(&thresholds, NULL, NULL); |
164 | ok( rc == 0, "Thresholds (NULL, NULL) set"); | 162 | ok(rc == 0, "Thresholds (NULL, NULL) set"); |
165 | ok( thresholds->warning == NULL, "Warning not set"); | 163 | ok(thresholds->warning == NULL, "Warning not set"); |
166 | ok( thresholds->critical == NULL, "Critical not set"); | 164 | ok(thresholds->critical == NULL, "Critical not set"); |
167 | 165 | ||
168 | rc = _set_thresholds(&thresholds, NULL, "80"); | 166 | rc = _set_thresholds(&thresholds, NULL, "80"); |
169 | ok( rc == 0, "Thresholds (NULL, '80') set"); | 167 | ok(rc == 0, "Thresholds (NULL, '80') set"); |
170 | ok( thresholds->warning == NULL, "Warning not set"); | 168 | ok(thresholds->warning == NULL, "Warning not set"); |
171 | ok( thresholds->critical->end == 80, "Critical set correctly"); | 169 | ok(thresholds->critical->end == 80, "Critical set correctly"); |
172 | 170 | ||
173 | rc = _set_thresholds(&thresholds, "5:33", NULL); | 171 | rc = _set_thresholds(&thresholds, "5:33", NULL); |
174 | ok( rc == 0, "Thresholds ('5:33', NULL) set"); | 172 | ok(rc == 0, "Thresholds ('5:33', NULL) set"); |
175 | ok( thresholds->warning->start == 5, "Warning start set"); | 173 | ok(thresholds->warning->start == 5, "Warning start set"); |
176 | ok( thresholds->warning->end == 33, "Warning end set"); | 174 | ok(thresholds->warning->end == 33, "Warning end set"); |
177 | ok( thresholds->critical == NULL, "Critical not set"); | 175 | ok(thresholds->critical == NULL, "Critical not set"); |
178 | 176 | ||
179 | rc = _set_thresholds(&thresholds, "30", "60"); | 177 | rc = _set_thresholds(&thresholds, "30", "60"); |
180 | ok( rc == 0, "Thresholds ('30', '60') set"); | 178 | ok(rc == 0, "Thresholds ('30', '60') set"); |
181 | ok( thresholds->warning->end == 30, "Warning set correctly"); | 179 | ok(thresholds->warning->end == 30, "Warning set correctly"); |
182 | ok( thresholds->critical->end == 60, "Critical set correctly"); | 180 | ok(thresholds->critical->end == 60, "Critical set correctly"); |
183 | ok( get_status(15.3, thresholds) == STATE_OK, "15.3 - ok"); | 181 | ok(get_status(15.3, thresholds) == STATE_OK, "15.3 - ok"); |
184 | ok( get_status(30.0001, thresholds) == STATE_WARNING, "30.0001 - warning"); | 182 | ok(get_status(30.0001, thresholds) == STATE_WARNING, "30.0001 - warning"); |
185 | ok( get_status(69, thresholds) == STATE_CRITICAL, "69 - critical"); | 183 | ok(get_status(69, thresholds) == STATE_CRITICAL, "69 - critical"); |
186 | 184 | ||
187 | rc = _set_thresholds(&thresholds, "-10:-2", "-30:20"); | 185 | rc = _set_thresholds(&thresholds, "-10:-2", "-30:20"); |
188 | ok( rc == 0, "Thresholds ('-30:20', '-10:-2') set"); | 186 | ok(rc == 0, "Thresholds ('-30:20', '-10:-2') set"); |
189 | ok( thresholds->warning->start == -10, "Warning start set correctly"); | 187 | ok(thresholds->warning->start == -10, "Warning start set correctly"); |
190 | ok( thresholds->warning->end == -2, "Warning end set correctly"); | 188 | ok(thresholds->warning->end == -2, "Warning end set correctly"); |
191 | ok( thresholds->critical->start == -30, "Critical start set correctly"); | 189 | ok(thresholds->critical->start == -30, "Critical start set correctly"); |
192 | ok( thresholds->critical->end == 20, "Critical end set correctly"); | 190 | ok(thresholds->critical->end == 20, "Critical end set correctly"); |
193 | ok( get_status(-31, thresholds) == STATE_CRITICAL, "-31 - critical"); | 191 | ok(get_status(-31, thresholds) == STATE_CRITICAL, "-31 - critical"); |
194 | ok( get_status(-29, thresholds) == STATE_WARNING, "-29 - warning"); | 192 | ok(get_status(-29, thresholds) == STATE_WARNING, "-29 - warning"); |
195 | ok( get_status(-11, thresholds) == STATE_WARNING, "-11 - warning"); | 193 | ok(get_status(-11, thresholds) == STATE_WARNING, "-11 - warning"); |
196 | ok( get_status(-10, thresholds) == STATE_OK, "-10 - ok"); | 194 | ok(get_status(-10, thresholds) == STATE_OK, "-10 - ok"); |
197 | ok( get_status(-2, thresholds) == STATE_OK, "-2 - ok"); | 195 | ok(get_status(-2, thresholds) == STATE_OK, "-2 - ok"); |
198 | ok( get_status(-1, thresholds) == STATE_WARNING, "-1 - warning"); | 196 | ok(get_status(-1, thresholds) == STATE_WARNING, "-1 - warning"); |
199 | ok( get_status(19, thresholds) == STATE_WARNING, "19 - warning"); | 197 | ok(get_status(19, thresholds) == STATE_WARNING, "19 - warning"); |
200 | ok( get_status(21, thresholds) == STATE_CRITICAL, "21 - critical"); | 198 | ok(get_status(21, thresholds) == STATE_CRITICAL, "21 - critical"); |
201 | 199 | ||
202 | char *test; | 200 | char *test; |
203 | test = np_escaped_string("bob\\n"); | 201 | test = np_escaped_string("bob\\n"); |
204 | ok( strcmp(test, "bob\n") == 0, "bob\\n ok"); | 202 | ok(strcmp(test, "bob\n") == 0, "bob\\n ok"); |
205 | free(test); | 203 | free(test); |
206 | 204 | ||
207 | test = np_escaped_string("rhuba\\rb"); | 205 | test = np_escaped_string("rhuba\\rb"); |
208 | ok( strcmp(test, "rhuba\rb") == 0, "rhuba\\rb okay"); | 206 | ok(strcmp(test, "rhuba\rb") == 0, "rhuba\\rb okay"); |
209 | free(test); | 207 | free(test); |
210 | 208 | ||
211 | test = np_escaped_string("ba\\nge\\r"); | 209 | test = np_escaped_string("ba\\nge\\r"); |
212 | ok( strcmp(test, "ba\nge\r") == 0, "ba\\nge\\r okay"); | 210 | ok(strcmp(test, "ba\nge\r") == 0, "ba\\nge\\r okay"); |
213 | free(test); | 211 | free(test); |
214 | 212 | ||
215 | test = np_escaped_string("\\rabbi\\t"); | 213 | test = np_escaped_string("\\rabbi\\t"); |
216 | ok( strcmp(test, "\rabbi\t") == 0, "\\rabbi\\t okay"); | 214 | ok(strcmp(test, "\rabbi\t") == 0, "\\rabbi\\t okay"); |
217 | free(test); | 215 | free(test); |
218 | 216 | ||
219 | test = np_escaped_string("and\\\\or"); | 217 | test = np_escaped_string("and\\\\or"); |
220 | ok( strcmp(test, "and\\or") == 0, "and\\\\or okay"); | 218 | ok(strcmp(test, "and\\or") == 0, "and\\\\or okay"); |
221 | free(test); | 219 | free(test); |
222 | 220 | ||
223 | test = np_escaped_string("bo\\gus"); | 221 | test = np_escaped_string("bo\\gus"); |
224 | ok( strcmp(test, "bogus") == 0, "bo\\gus okay"); | 222 | ok(strcmp(test, "bogus") == 0, "bo\\gus okay"); |
225 | free(test); | 223 | free(test); |
226 | 224 | ||
227 | test = np_escaped_string("everything"); | 225 | test = np_escaped_string("everything"); |
228 | ok( strcmp(test, "everything") == 0, "everything okay"); | 226 | ok(strcmp(test, "everything") == 0, "everything okay"); |
229 | 227 | ||
230 | /* np_extract_ntpvar tests (23) */ | 228 | /* np_extract_ntpvar tests (23) */ |
231 | test=np_extract_ntpvar("foo=bar, bar=foo, foobar=barfoo\n", "foo"); | 229 | test = np_extract_ntpvar("foo=bar, bar=foo, foobar=barfoo\n", "foo"); |
232 | ok(test && !strcmp(test, "bar"), "1st test as expected"); | 230 | ok(test && !strcmp(test, "bar"), "1st test as expected"); |
233 | free(test); | 231 | free(test); |
234 | 232 | ||
235 | test=np_extract_ntpvar("foo=bar,bar=foo,foobar=barfoo\n", "bar"); | 233 | test = np_extract_ntpvar("foo=bar,bar=foo,foobar=barfoo\n", "bar"); |
236 | ok(test && !strcmp(test, "foo"), "2nd test as expected"); | 234 | ok(test && !strcmp(test, "foo"), "2nd test as expected"); |
237 | free(test); | 235 | free(test); |
238 | 236 | ||
239 | test=np_extract_ntpvar("foo=bar, bar=foo, foobar=barfoo\n", "foobar"); | 237 | test = np_extract_ntpvar("foo=bar, bar=foo, foobar=barfoo\n", "foobar"); |
240 | ok(test && !strcmp(test, "barfoo"), "3rd test as expected"); | 238 | ok(test && !strcmp(test, "barfoo"), "3rd test as expected"); |
241 | free(test); | 239 | free(test); |
242 | 240 | ||
243 | test=np_extract_ntpvar("foo=bar\n", "foo"); | 241 | test = np_extract_ntpvar("foo=bar\n", "foo"); |
244 | ok(test && !strcmp(test, "bar"), "Single test as expected"); | 242 | ok(test && !strcmp(test, "bar"), "Single test as expected"); |
245 | free(test); | 243 | free(test); |
246 | 244 | ||
247 | test=np_extract_ntpvar("foo=bar, bar=foo, foobar=barfooi\n", "abcd"); | 245 | test = np_extract_ntpvar("foo=bar, bar=foo, foobar=barfooi\n", "abcd"); |
248 | ok(!test, "Key not found 1"); | 246 | ok(!test, "Key not found 1"); |
249 | 247 | ||
250 | test=np_extract_ntpvar("foo=bar\n", "abcd"); | 248 | test = np_extract_ntpvar("foo=bar\n", "abcd"); |
251 | ok(!test, "Key not found 2"); | 249 | ok(!test, "Key not found 2"); |
252 | 250 | ||
253 | test=np_extract_ntpvar("foo=bar=foobar", "foo"); | 251 | test = np_extract_ntpvar("foo=bar=foobar", "foo"); |
254 | ok(test && !strcmp(test, "bar=foobar"), "Strange string 1"); | 252 | ok(test && !strcmp(test, "bar=foobar"), "Strange string 1"); |
255 | free(test); | 253 | free(test); |
256 | 254 | ||
257 | test=np_extract_ntpvar("foo", "foo"); | 255 | test = np_extract_ntpvar("foo", "foo"); |
258 | ok(!test, "Malformed string 1"); | 256 | ok(!test, "Malformed string 1"); |
259 | 257 | ||
260 | test=np_extract_ntpvar("foo,", "foo"); | 258 | test = np_extract_ntpvar("foo,", "foo"); |
261 | ok(!test, "Malformed string 2"); | 259 | ok(!test, "Malformed string 2"); |
262 | 260 | ||
263 | test=np_extract_ntpvar("foo=", "foo"); | 261 | test = np_extract_ntpvar("foo=", "foo"); |
264 | ok(!test, "Malformed string 3"); | 262 | ok(!test, "Malformed string 3"); |
265 | 263 | ||
266 | test=np_extract_ntpvar("foo=,bar=foo", "foo"); | 264 | test = np_extract_ntpvar("foo=,bar=foo", "foo"); |
267 | ok(!test, "Malformed string 4"); | 265 | ok(!test, "Malformed string 4"); |
268 | 266 | ||
269 | test=np_extract_ntpvar(",foo", "foo"); | 267 | test = np_extract_ntpvar(",foo", "foo"); |
270 | ok(!test, "Malformed string 5"); | 268 | ok(!test, "Malformed string 5"); |
271 | 269 | ||
272 | test=np_extract_ntpvar("=foo", "foo"); | 270 | test = np_extract_ntpvar("=foo", "foo"); |
273 | ok(!test, "Malformed string 6"); | 271 | ok(!test, "Malformed string 6"); |
274 | 272 | ||
275 | test=np_extract_ntpvar("=foo,", "foo"); | 273 | test = np_extract_ntpvar("=foo,", "foo"); |
276 | ok(!test, "Malformed string 7"); | 274 | ok(!test, "Malformed string 7"); |
277 | 275 | ||
278 | test=np_extract_ntpvar(",,,", "foo"); | 276 | test = np_extract_ntpvar(",,,", "foo"); |
279 | ok(!test, "Malformed string 8"); | 277 | ok(!test, "Malformed string 8"); |
280 | 278 | ||
281 | test=np_extract_ntpvar("===", "foo"); | 279 | test = np_extract_ntpvar("===", "foo"); |
282 | ok(!test, "Malformed string 9"); | 280 | ok(!test, "Malformed string 9"); |
283 | 281 | ||
284 | test=np_extract_ntpvar(",=,=,", "foo"); | 282 | test = np_extract_ntpvar(",=,=,", "foo"); |
285 | ok(!test, "Malformed string 10"); | 283 | ok(!test, "Malformed string 10"); |
286 | 284 | ||
287 | test=np_extract_ntpvar("=,=,=", "foo"); | 285 | test = np_extract_ntpvar("=,=,=", "foo"); |
288 | ok(!test, "Malformed string 11"); | 286 | ok(!test, "Malformed string 11"); |
289 | 287 | ||
290 | test=np_extract_ntpvar(" foo=bar ,\n bar=foo\n , foobar=barfoo \n ", "foo"); | 288 | test = np_extract_ntpvar(" foo=bar ,\n bar=foo\n , foobar=barfoo \n ", "foo"); |
291 | ok(test && !strcmp(test, "bar"), "Random spaces and newlines 1"); | 289 | ok(test && !strcmp(test, "bar"), "Random spaces and newlines 1"); |
292 | free(test); | 290 | free(test); |
293 | 291 | ||
294 | test=np_extract_ntpvar(" foo=bar ,\n bar=foo\n , foobar=barfoo \n ", "bar"); | 292 | test = np_extract_ntpvar(" foo=bar ,\n bar=foo\n , foobar=barfoo \n ", "bar"); |
295 | ok(test && !strcmp(test, "foo"), "Random spaces and newlines 2"); | 293 | ok(test && !strcmp(test, "foo"), "Random spaces and newlines 2"); |
296 | free(test); | 294 | free(test); |
297 | 295 | ||
298 | test=np_extract_ntpvar(" foo=bar ,\n bar=foo\n , foobar=barfoo \n ", "foobar"); | 296 | test = np_extract_ntpvar(" foo=bar ,\n bar=foo\n , foobar=barfoo \n ", "foobar"); |
299 | ok(test && !strcmp(test, "barfoo"), "Random spaces and newlines 3"); | 297 | ok(test && !strcmp(test, "barfoo"), "Random spaces and newlines 3"); |
300 | free(test); | 298 | free(test); |
301 | 299 | ||
302 | test=np_extract_ntpvar(" foo=bar ,\n bar\n \n= \n foo\n , foobar=barfoo \n ", "bar"); | 300 | test = np_extract_ntpvar(" foo=bar ,\n bar\n \n= \n foo\n , foobar=barfoo \n ", "bar"); |
303 | ok(test && !strcmp(test, "foo"), "Random spaces and newlines 4"); | 301 | ok(test && !strcmp(test, "foo"), "Random spaces and newlines 4"); |
304 | free(test); | 302 | free(test); |
305 | 303 | ||
306 | test=np_extract_ntpvar("", "foo"); | 304 | test = np_extract_ntpvar("", "foo"); |
307 | ok(!test, "Empty string return NULL"); | 305 | ok(!test, "Empty string return NULL"); |
308 | 306 | ||
309 | |||
310 | /* This is the result of running ./test_utils */ | 307 | /* This is the result of running ./test_utils */ |
311 | temp_string = (char *) _np_state_generate_key(); | 308 | temp_string = (char *)_np_state_generate_key(); |
312 | ok(!strcmp(temp_string, "e2d17f995fd4c020411b85e3e3d0ff7306d4147e"), "Got hash with exe and no parameters" ) || | 309 | ok(!strcmp(temp_string, "e2d17f995fd4c020411b85e3e3d0ff7306d4147e"), "Got hash with exe and no parameters") || |
313 | diag( "You are probably running in wrong directory. Must run as ./test_utils" ); | 310 | diag("You are probably running in wrong directory. Must run as ./test_utils"); |
314 | |||
315 | 311 | ||
316 | this_monitoring_plugin->argc=4; | 312 | this_monitoring_plugin->argc = 4; |
317 | this_monitoring_plugin->argv[0] = "./test_utils"; | 313 | this_monitoring_plugin->argv[0] = "./test_utils"; |
318 | this_monitoring_plugin->argv[1] = "here"; | 314 | this_monitoring_plugin->argv[1] = "here"; |
319 | this_monitoring_plugin->argv[2] = "--and"; | 315 | this_monitoring_plugin->argv[2] = "--and"; |
320 | this_monitoring_plugin->argv[3] = "now"; | 316 | this_monitoring_plugin->argv[3] = "now"; |
321 | temp_string = (char *) _np_state_generate_key(); | 317 | temp_string = (char *)_np_state_generate_key(); |
322 | ok(!strcmp(temp_string, "bd72da9f78ff1419fad921ea5e43ce56508aef6c"), "Got based on expected argv" ); | 318 | ok(!strcmp(temp_string, "bd72da9f78ff1419fad921ea5e43ce56508aef6c"), "Got based on expected argv"); |
323 | 319 | ||
324 | unsetenv("MP_STATE_PATH"); | 320 | unsetenv("MP_STATE_PATH"); |
325 | temp_string = (char *) _np_state_calculate_location_prefix(); | 321 | temp_string = (char *)_np_state_calculate_location_prefix(); |
326 | ok(!strcmp(temp_string, NP_STATE_DIR_PREFIX), "Got default directory" ); | 322 | ok(!strcmp(temp_string, NP_STATE_DIR_PREFIX), "Got default directory"); |
327 | 323 | ||
328 | setenv("MP_STATE_PATH", "", 1); | 324 | setenv("MP_STATE_PATH", "", 1); |
329 | temp_string = (char *) _np_state_calculate_location_prefix(); | 325 | temp_string = (char *)_np_state_calculate_location_prefix(); |
330 | ok(!strcmp(temp_string, NP_STATE_DIR_PREFIX), "Got default directory even with empty string" ); | 326 | ok(!strcmp(temp_string, NP_STATE_DIR_PREFIX), "Got default directory even with empty string"); |
331 | 327 | ||
332 | setenv("MP_STATE_PATH", "/usr/local/nagios/var", 1); | 328 | setenv("MP_STATE_PATH", "/usr/local/nagios/var", 1); |
333 | temp_string = (char *) _np_state_calculate_location_prefix(); | 329 | temp_string = (char *)_np_state_calculate_location_prefix(); |
334 | ok(!strcmp(temp_string, "/usr/local/nagios/var"), "Got default directory" ); | 330 | ok(!strcmp(temp_string, "/usr/local/nagios/var"), "Got default directory"); |
335 | |||
336 | 331 | ||
332 | ok(temp_state_key == NULL, "temp_state_key initially empty"); | ||
337 | 333 | ||
338 | ok(temp_state_key==NULL, "temp_state_key initially empty"); | 334 | this_monitoring_plugin->argc = 1; |
339 | |||
340 | this_monitoring_plugin->argc=1; | ||
341 | this_monitoring_plugin->argv[0] = "./test_utils"; | 335 | this_monitoring_plugin->argv[0] = "./test_utils"; |
342 | np_enable_state(NULL, 51); | 336 | np_enable_state(NULL, 51); |
343 | temp_state_key = this_monitoring_plugin->state; | 337 | temp_state_key = this_monitoring_plugin->state; |
344 | ok( !strcmp(temp_state_key->plugin_name, "check_test"), "Got plugin name" ); | 338 | ok(!strcmp(temp_state_key->plugin_name, "check_test"), "Got plugin name"); |
345 | ok( !strcmp(temp_state_key->name, "e2d17f995fd4c020411b85e3e3d0ff7306d4147e"), "Got generated filename" ); | 339 | ok(!strcmp(temp_state_key->name, "e2d17f995fd4c020411b85e3e3d0ff7306d4147e"), "Got generated filename"); |
346 | |||
347 | 340 | ||
348 | np_enable_state("allowedchars_in_keyname", 77); | 341 | np_enable_state("allowedchars_in_keyname", 77); |
349 | temp_state_key = this_monitoring_plugin->state; | 342 | temp_state_key = this_monitoring_plugin->state; |
350 | sprintf(state_path, "/usr/local/nagios/var/%lu/check_test/allowedchars_in_keyname", (unsigned long)geteuid()); | 343 | sprintf(state_path, "/usr/local/nagios/var/%lu/check_test/allowedchars_in_keyname", (unsigned long)geteuid()); |
351 | ok( !strcmp(temp_state_key->plugin_name, "check_test"), "Got plugin name" ); | 344 | ok(!strcmp(temp_state_key->plugin_name, "check_test"), "Got plugin name"); |
352 | ok( !strcmp(temp_state_key->name, "allowedchars_in_keyname"), "Got key name with valid chars" ); | 345 | ok(!strcmp(temp_state_key->name, "allowedchars_in_keyname"), "Got key name with valid chars"); |
353 | ok( !strcmp(temp_state_key->_filename, state_path), "Got internal filename" ); | 346 | ok(!strcmp(temp_state_key->_filename, state_path), "Got internal filename"); |
354 | |||
355 | 347 | ||
356 | /* Don't do this test just yet. Will die */ | 348 | /* Don't do this test just yet. Will die */ |
357 | /* | 349 | /* |
@@ -363,73 +355,65 @@ main (int argc, char **argv) | |||
363 | np_enable_state("funnykeyname", 54); | 355 | np_enable_state("funnykeyname", 54); |
364 | temp_state_key = this_monitoring_plugin->state; | 356 | temp_state_key = this_monitoring_plugin->state; |
365 | sprintf(state_path, "/usr/local/nagios/var/%lu/check_test/funnykeyname", (unsigned long)geteuid()); | 357 | sprintf(state_path, "/usr/local/nagios/var/%lu/check_test/funnykeyname", (unsigned long)geteuid()); |
366 | ok( !strcmp(temp_state_key->plugin_name, "check_test"), "Got plugin name" ); | 358 | ok(!strcmp(temp_state_key->plugin_name, "check_test"), "Got plugin name"); |
367 | ok( !strcmp(temp_state_key->name, "funnykeyname"), "Got key name" ); | 359 | ok(!strcmp(temp_state_key->name, "funnykeyname"), "Got key name"); |
368 | 360 | ||
369 | 361 | ok(!strcmp(temp_state_key->_filename, state_path), "Got internal filename"); | |
370 | 362 | ok(temp_state_key->data_version == 54, "Version set"); | |
371 | ok( !strcmp(temp_state_key->_filename, state_path), "Got internal filename" ); | ||
372 | ok( temp_state_key->data_version==54, "Version set" ); | ||
373 | 363 | ||
374 | temp_state_data = np_state_read(); | 364 | temp_state_data = np_state_read(); |
375 | ok( temp_state_data==NULL, "Got no state data as file does not exist" ); | 365 | ok(temp_state_data == NULL, "Got no state data as file does not exist"); |
376 | |||
377 | 366 | ||
378 | /* | 367 | /* |
379 | temp_fp = fopen("var/statefile", "r"); | 368 | temp_fp = fopen("var/statefile", "r"); |
380 | if (temp_fp==NULL) | 369 | if (temp_fp==NULL) |
381 | printf("Error opening. errno=%d\n", errno); | 370 | printf("Error opening. errno=%d\n", errno); |
382 | printf("temp_fp=%s\n", temp_fp); | 371 | printf("temp_fp=%s\n", temp_fp); |
383 | ok( _np_state_read_file(temp_fp) == true, "Can read state file" ); | 372 | ok( _np_state_read_file(temp_fp) == true, "Can read state file" ); |
384 | fclose(temp_fp); | 373 | fclose(temp_fp); |
385 | */ | 374 | */ |
386 | 375 | ||
387 | temp_state_key->_filename="var/statefile"; | 376 | temp_state_key->_filename = "var/statefile"; |
388 | temp_state_data = np_state_read(); | 377 | temp_state_data = np_state_read(); |
389 | 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"); | 378 | ok(this_monitoring_plugin->state->state_data != NULL, "Got state data now") || |
390 | ok( this_monitoring_plugin->state->state_data->time==1234567890, "Got time" ); | 379 | diag("Are you running in right directory? Will get coredump next if not"); |
391 | ok( !strcmp((char *)this_monitoring_plugin->state->state_data->data, "String to read"), "Data as expected" ); | 380 | ok(this_monitoring_plugin->state->state_data->time == 1234567890, "Got time"); |
381 | ok(!strcmp((char *)this_monitoring_plugin->state->state_data->data, "String to read"), "Data as expected"); | ||
392 | 382 | ||
393 | temp_state_key->data_version=53; | 383 | temp_state_key->data_version = 53; |
394 | temp_state_data = np_state_read(); | 384 | temp_state_data = np_state_read(); |
395 | ok( temp_state_data==NULL, "Older data version gives NULL" ); | 385 | ok(temp_state_data == NULL, "Older data version gives NULL"); |
396 | temp_state_key->data_version=54; | 386 | temp_state_key->data_version = 54; |
397 | 387 | ||
398 | temp_state_key->_filename="var/nonexistent"; | 388 | temp_state_key->_filename = "var/nonexistent"; |
399 | temp_state_data = np_state_read(); | 389 | temp_state_data = np_state_read(); |
400 | ok( temp_state_data==NULL, "Missing file gives NULL" ); | 390 | ok(temp_state_data == NULL, "Missing file gives NULL"); |
401 | ok( this_monitoring_plugin->state->state_data==NULL, "No state information" ); | 391 | ok(this_monitoring_plugin->state->state_data == NULL, "No state information"); |
402 | 392 | ||
403 | temp_state_key->_filename="var/oldformat"; | 393 | temp_state_key->_filename = "var/oldformat"; |
404 | temp_state_data = np_state_read(); | 394 | temp_state_data = np_state_read(); |
405 | ok( temp_state_data==NULL, "Old file format gives NULL" ); | 395 | ok(temp_state_data == NULL, "Old file format gives NULL"); |
406 | 396 | ||
407 | temp_state_key->_filename="var/baddate"; | 397 | temp_state_key->_filename = "var/baddate"; |
408 | temp_state_data = np_state_read(); | 398 | temp_state_data = np_state_read(); |
409 | ok( temp_state_data==NULL, "Bad date gives NULL" ); | 399 | ok(temp_state_data == NULL, "Bad date gives NULL"); |
410 | 400 | ||
411 | temp_state_key->_filename="var/missingdataline"; | 401 | temp_state_key->_filename = "var/missingdataline"; |
412 | temp_state_data = np_state_read(); | 402 | temp_state_data = np_state_read(); |
413 | ok( temp_state_data==NULL, "Missing data line gives NULL" ); | 403 | ok(temp_state_data == NULL, "Missing data line gives NULL"); |
414 | |||
415 | |||
416 | |||
417 | 404 | ||
418 | unlink("var/generated"); | 405 | unlink("var/generated"); |
419 | temp_state_key->_filename="var/generated"; | 406 | temp_state_key->_filename = "var/generated"; |
420 | current_time=1234567890; | 407 | current_time = 1234567890; |
421 | np_state_write_string(current_time, "String to read"); | 408 | np_state_write_string(current_time, "String to read"); |
422 | ok(system("cmp var/generated var/statefile")==0, "Generated file same as expected"); | 409 | ok(system("cmp var/generated var/statefile") == 0, "Generated file same as expected"); |
423 | |||
424 | |||
425 | |||
426 | 410 | ||
427 | unlink("var/generated_directory/statefile"); | 411 | unlink("var/generated_directory/statefile"); |
428 | unlink("var/generated_directory"); | 412 | unlink("var/generated_directory"); |
429 | temp_state_key->_filename="var/generated_directory/statefile"; | 413 | temp_state_key->_filename = "var/generated_directory/statefile"; |
430 | current_time=1234567890; | 414 | current_time = 1234567890; |
431 | np_state_write_string(current_time, "String to read"); | 415 | np_state_write_string(current_time, "String to read"); |
432 | ok(system("cmp var/generated_directory/statefile var/statefile")==0, "Have created directory"); | 416 | ok(system("cmp var/generated_directory/statefile var/statefile") == 0, "Have created directory"); |
433 | 417 | ||
434 | /* This test to check cannot write to dir - can't automate yet */ | 418 | /* This test to check cannot write to dir - can't automate yet */ |
435 | /* | 419 | /* |
@@ -438,15 +422,13 @@ main (int argc, char **argv) | |||
438 | np_state_write_string(current_time, "String to read"); | 422 | np_state_write_string(current_time, "String to read"); |
439 | */ | 423 | */ |
440 | 424 | ||
441 | 425 | temp_state_key->_filename = "var/generated"; | |
442 | temp_state_key->_filename="var/generated"; | ||
443 | time(¤t_time); | 426 | time(¤t_time); |
444 | np_state_write_string(0, "String to read"); | 427 | np_state_write_string(0, "String to read"); |
445 | temp_state_data = np_state_read(); | 428 | temp_state_data = np_state_read(); |
446 | /* Check time is set to current_time */ | 429 | /* Check time is set to current_time */ |
447 | ok(system("cmp var/generated var/statefile > /dev/null")!=0, "Generated file should be different this time"); | 430 | ok(system("cmp var/generated var/statefile > /dev/null") != 0, "Generated file should be different this time"); |
448 | ok(this_monitoring_plugin->state->state_data->time-current_time<=1, "Has time generated from current time"); | 431 | ok(this_monitoring_plugin->state->state_data->time - current_time <= 1, "Has time generated from current time"); |
449 | |||
450 | 432 | ||
451 | /* Don't know how to automatically test this. Need to be able to redefine die and catch the error */ | 433 | /* Don't know how to automatically test this. Need to be able to redefine die and catch the error */ |
452 | /* | 434 | /* |
@@ -454,23 +436,16 @@ main (int argc, char **argv) | |||
454 | np_state_write_string(0, "Bad file"); | 436 | np_state_write_string(0, "Bad file"); |
455 | */ | 437 | */ |
456 | 438 | ||
457 | |||
458 | np_cleanup(); | 439 | np_cleanup(); |
459 | 440 | ||
460 | ok(this_monitoring_plugin==NULL, "Free'd this_monitoring_plugin"); | 441 | ok(this_monitoring_plugin == NULL, "Free'd this_monitoring_plugin"); |
461 | 442 | ||
462 | ok(mp_suid() == false, "Test aren't suid"); | 443 | ok(mp_suid() == false, "Test aren't suid"); |
463 | 444 | ||
464 | /* base states with random case */ | 445 | /* base states with random case */ |
465 | char *states[] = { | 446 | char *states[] = {"Ok", "wArnINg", "cRiTIcaL", "UnKNoWN", NULL}; |
466 | "Ok", | 447 | |
467 | "wArnINg", | 448 | for (i = 0; states[i] != NULL; i++) { |
468 | "cRiTIcaL", | ||
469 | "UnKNoWN", | ||
470 | NULL | ||
471 | }; | ||
472 | |||
473 | for (i=0; states[i]!=NULL; i++) { | ||
474 | /* out of the random case states, create the lower and upper versions + numeric string one */ | 449 | /* out of the random case states, create the lower and upper versions + numeric string one */ |
475 | char *statelower = strdup(states[i]); | 450 | char *statelower = strdup(states[i]); |
476 | char *stateupper = strdup(states[i]); | 451 | char *stateupper = strdup(states[i]); |
@@ -488,23 +463,23 @@ main (int argc, char **argv) | |||
488 | char testname[64] = "Translate state string: "; | 463 | char testname[64] = "Translate state string: "; |
489 | int tlen = strlen(testname); | 464 | int tlen = strlen(testname); |
490 | 465 | ||
491 | strcpy(testname+tlen, states[i]); | 466 | strcpy(testname + tlen, states[i]); |
492 | ok(i==mp_translate_state(states[i]), testname); | 467 | ok(i == mp_translate_state(states[i]), testname); |
493 | 468 | ||
494 | strcpy(testname+tlen, statelower); | 469 | strcpy(testname + tlen, statelower); |
495 | ok(i==mp_translate_state(statelower), testname); | 470 | ok(i == mp_translate_state(statelower), testname); |
496 | 471 | ||
497 | strcpy(testname+tlen, stateupper); | 472 | strcpy(testname + tlen, stateupper); |
498 | ok(i==mp_translate_state(stateupper), testname); | 473 | ok(i == mp_translate_state(stateupper), testname); |
499 | 474 | ||
500 | strcpy(testname+tlen, statenum); | 475 | strcpy(testname + tlen, statenum); |
501 | ok(i==mp_translate_state(statenum), testname); | 476 | ok(i == mp_translate_state(statenum), testname); |
502 | } | 477 | } |
503 | ok(ERROR==mp_translate_state("warningfewgw"), "Translate state string with garbage"); | 478 | ok(ERROR == mp_translate_state("warningfewgw"), "Translate state string with garbage"); |
504 | ok(ERROR==mp_translate_state("00"), "Translate state string: bad numeric string 1"); | 479 | ok(ERROR == mp_translate_state("00"), "Translate state string: bad numeric string 1"); |
505 | ok(ERROR==mp_translate_state("01"), "Translate state string: bad numeric string 2"); | 480 | ok(ERROR == mp_translate_state("01"), "Translate state string: bad numeric string 2"); |
506 | ok(ERROR==mp_translate_state("10"), "Translate state string: bad numeric string 3"); | 481 | ok(ERROR == mp_translate_state("10"), "Translate state string: bad numeric string 3"); |
507 | ok(ERROR==mp_translate_state(""), "Translate state string: empty string"); | 482 | ok(ERROR == mp_translate_state(""), "Translate state string: empty string"); |
508 | 483 | ||
509 | return exit_status(); | 484 | return exit_status(); |
510 | } | 485 | } |
diff --git a/lib/utils_base.c b/lib/utils_base.c index f8592f4..90a4aaa 100644 --- a/lib/utils_base.c +++ b/lib/utils_base.c | |||
@@ -1,28 +1,28 @@ | |||
1 | /***************************************************************************** | 1 | /***************************************************************************** |
2 | * | 2 | * |
3 | * utils_base.c | 3 | * utils_base.c |
4 | * | 4 | * |
5 | * License: GPL | 5 | * License: GPL |
6 | * Copyright (c) 2006 Monitoring Plugins Development Team | 6 | * Copyright (c) 2006 - 2024 Monitoring Plugins Development Team |
7 | * | 7 | * |
8 | * Library of useful functions for plugins | 8 | * Library of useful functions for plugins |
9 | * | 9 | * |
10 | * | 10 | * |
11 | * This program is free software: you can redistribute it and/or modify | 11 | * This program is free software: you can redistribute it and/or modify |
12 | * it under the terms of the GNU General Public License as published by | 12 | * it under the terms of the GNU General Public License as published by |
13 | * the Free Software Foundation, either version 3 of the License, or | 13 | * the Free Software Foundation, either version 3 of the License, or |
14 | * (at your option) any later version. | 14 | * (at your option) any later version. |
15 | * | 15 | * |
16 | * This program is distributed in the hope that it will be useful, | 16 | * This program is distributed in the hope that it will be useful, |
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
19 | * GNU General Public License for more details. | 19 | * GNU General Public License for more details. |
20 | * | 20 | * |
21 | * You should have received a copy of the GNU General Public License | 21 | * You should have received a copy of the GNU General Public License |
22 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 22 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
23 | * | 23 | * |
24 | * | 24 | * |
25 | *****************************************************************************/ | 25 | *****************************************************************************/ |
26 | 26 | ||
27 | #include "../plugins/common.h" | 27 | #include "../plugins/common.h" |
28 | #include <stdarg.h> | 28 | #include <stdarg.h> |
@@ -33,43 +33,47 @@ | |||
33 | #include <unistd.h> | 33 | #include <unistd.h> |
34 | #include <sys/types.h> | 34 | #include <sys/types.h> |
35 | 35 | ||
36 | #define np_free(ptr) { if(ptr) { free(ptr); ptr = NULL; } } | 36 | #define np_free(ptr) \ |
37 | { \ | ||
38 | if (ptr) { \ | ||
39 | free(ptr); \ | ||
40 | ptr = NULL; \ | ||
41 | } \ | ||
42 | } | ||
37 | 43 | ||
38 | monitoring_plugin *this_monitoring_plugin=NULL; | 44 | monitoring_plugin *this_monitoring_plugin = NULL; |
39 | 45 | ||
40 | int timeout_state = STATE_CRITICAL; | 46 | int timeout_state = STATE_CRITICAL; |
41 | unsigned int timeout_interval = DEFAULT_SOCKET_TIMEOUT; | 47 | unsigned int timeout_interval = DEFAULT_SOCKET_TIMEOUT; |
42 | 48 | ||
43 | bool _np_state_read_file(FILE *); | 49 | bool _np_state_read_file(FILE *); |
44 | 50 | ||
45 | void np_init( char *plugin_name, int argc, char **argv ) { | 51 | void np_init(char *plugin_name, int argc, char **argv) { |
46 | if (this_monitoring_plugin==NULL) { | 52 | if (this_monitoring_plugin == NULL) { |
47 | this_monitoring_plugin = calloc(1, sizeof(monitoring_plugin)); | 53 | this_monitoring_plugin = calloc(1, sizeof(monitoring_plugin)); |
48 | if (this_monitoring_plugin==NULL) { | 54 | if (this_monitoring_plugin == NULL) { |
49 | die(STATE_UNKNOWN, _("Cannot allocate memory: %s"), | 55 | die(STATE_UNKNOWN, _("Cannot allocate memory: %s"), strerror(errno)); |
50 | strerror(errno)); | ||
51 | } | 56 | } |
52 | this_monitoring_plugin->plugin_name = strdup(plugin_name); | 57 | this_monitoring_plugin->plugin_name = strdup(plugin_name); |
53 | if (this_monitoring_plugin->plugin_name==NULL) | 58 | if (this_monitoring_plugin->plugin_name == NULL) |
54 | die(STATE_UNKNOWN, _("Cannot execute strdup: %s"), strerror(errno)); | 59 | die(STATE_UNKNOWN, _("Cannot execute strdup: %s"), strerror(errno)); |
55 | this_monitoring_plugin->argc = argc; | 60 | this_monitoring_plugin->argc = argc; |
56 | this_monitoring_plugin->argv = argv; | 61 | this_monitoring_plugin->argv = argv; |
57 | } | 62 | } |
58 | } | 63 | } |
59 | 64 | ||
60 | void np_set_args( int argc, char **argv ) { | 65 | void np_set_args(int argc, char **argv) { |
61 | if (this_monitoring_plugin==NULL) | 66 | if (this_monitoring_plugin == NULL) |
62 | die(STATE_UNKNOWN, _("This requires np_init to be called")); | 67 | die(STATE_UNKNOWN, _("This requires np_init to be called")); |
63 | 68 | ||
64 | this_monitoring_plugin->argc = argc; | 69 | this_monitoring_plugin->argc = argc; |
65 | this_monitoring_plugin->argv = argv; | 70 | this_monitoring_plugin->argv = argv; |
66 | } | 71 | } |
67 | 72 | ||
68 | |||
69 | void np_cleanup() { | 73 | void np_cleanup() { |
70 | if (this_monitoring_plugin!=NULL) { | 74 | if (this_monitoring_plugin != NULL) { |
71 | if(this_monitoring_plugin->state!=NULL) { | 75 | if (this_monitoring_plugin->state != NULL) { |
72 | if(this_monitoring_plugin->state->state_data) { | 76 | if (this_monitoring_plugin->state->state_data) { |
73 | np_free(this_monitoring_plugin->state->state_data->data); | 77 | np_free(this_monitoring_plugin->state->state_data->data); |
74 | np_free(this_monitoring_plugin->state->state_data); | 78 | np_free(this_monitoring_plugin->state->state_data); |
75 | } | 79 | } |
@@ -79,48 +83,43 @@ void np_cleanup() { | |||
79 | np_free(this_monitoring_plugin->plugin_name); | 83 | np_free(this_monitoring_plugin->plugin_name); |
80 | np_free(this_monitoring_plugin); | 84 | np_free(this_monitoring_plugin); |
81 | } | 85 | } |
82 | this_monitoring_plugin=NULL; | 86 | this_monitoring_plugin = NULL; |
83 | } | 87 | } |
84 | 88 | ||
85 | /* Hidden function to get a pointer to this_monitoring_plugin for testing */ | 89 | /* Hidden function to get a pointer to this_monitoring_plugin for testing */ |
86 | void _get_monitoring_plugin( monitoring_plugin **pointer ){ | 90 | void _get_monitoring_plugin(monitoring_plugin **pointer) { *pointer = this_monitoring_plugin; } |
87 | *pointer = this_monitoring_plugin; | ||
88 | } | ||
89 | 91 | ||
90 | void | 92 | void die(int result, const char *fmt, ...) { |
91 | die (int result, const char *fmt, ...) | 93 | if (fmt != NULL) { |
92 | { | ||
93 | if(fmt!=NULL) { | ||
94 | va_list ap; | 94 | va_list ap; |
95 | va_start (ap, fmt); | 95 | va_start(ap, fmt); |
96 | vprintf (fmt, ap); | 96 | vprintf(fmt, ap); |
97 | va_end (ap); | 97 | va_end(ap); |
98 | } | 98 | } |
99 | 99 | ||
100 | if(this_monitoring_plugin!=NULL) { | 100 | if (this_monitoring_plugin != NULL) { |
101 | np_cleanup(); | 101 | np_cleanup(); |
102 | } | 102 | } |
103 | exit (result); | 103 | exit(result); |
104 | } | 104 | } |
105 | 105 | ||
106 | void set_range_start (range *this, double value) { | 106 | void set_range_start(range *this, double value) { |
107 | this->start = value; | 107 | this->start = value; |
108 | this->start_infinity = false; | 108 | this->start_infinity = false; |
109 | } | 109 | } |
110 | 110 | ||
111 | void set_range_end (range *this, double value) { | 111 | void set_range_end(range *this, double value) { |
112 | this->end = value; | 112 | this->end = value; |
113 | this->end_infinity = false; | 113 | this->end_infinity = false; |
114 | } | 114 | } |
115 | 115 | ||
116 | range | 116 | range *parse_range_string(char *str) { |
117 | *parse_range_string (char *str) { | ||
118 | range *temp_range; | 117 | range *temp_range; |
119 | double start; | 118 | double start; |
120 | double end; | 119 | double end; |
121 | char *end_str; | 120 | char *end_str; |
122 | 121 | ||
123 | temp_range = (range *) calloc(1, sizeof(range)); | 122 | temp_range = (range *)calloc(1, sizeof(range)); |
124 | 123 | ||
125 | /* Set defaults */ | 124 | /* Set defaults */ |
126 | temp_range->start = 0; | 125 | temp_range->start = 0; |
@@ -140,10 +139,10 @@ range | |||
140 | if (str[0] == '~') { | 139 | if (str[0] == '~') { |
141 | temp_range->start_infinity = true; | 140 | temp_range->start_infinity = true; |
142 | } else { | 141 | } else { |
143 | start = strtod(str, NULL); /* Will stop at the ':' */ | 142 | start = strtod(str, NULL); /* Will stop at the ':' */ |
144 | set_range_start(temp_range, start); | 143 | set_range_start(temp_range, start); |
145 | } | 144 | } |
146 | end_str++; /* Move past the ':' */ | 145 | end_str++; /* Move past the ':' */ |
147 | } else { | 146 | } else { |
148 | end_str = str; | 147 | end_str = str; |
149 | } | 148 | } |
@@ -152,9 +151,7 @@ range | |||
152 | set_range_end(temp_range, end); | 151 | set_range_end(temp_range, end); |
153 | } | 152 | } |
154 | 153 | ||
155 | if (temp_range->start_infinity == true || | 154 | if (temp_range->start_infinity == true || temp_range->end_infinity == true || temp_range->start <= temp_range->end) { |
156 | temp_range->end_infinity == true || | ||
157 | temp_range->start <= temp_range->end) { | ||
158 | return temp_range; | 155 | return temp_range; |
159 | } | 156 | } |
160 | free(temp_range); | 157 | free(temp_range); |
@@ -162,14 +159,11 @@ range | |||
162 | } | 159 | } |
163 | 160 | ||
164 | /* returns 0 if okay, otherwise 1 */ | 161 | /* returns 0 if okay, otherwise 1 */ |
165 | int | 162 | int _set_thresholds(thresholds **my_thresholds, char *warn_string, char *critical_string) { |
166 | _set_thresholds(thresholds **my_thresholds, char *warn_string, char *critical_string) | ||
167 | { | ||
168 | thresholds *temp_thresholds = NULL; | 163 | thresholds *temp_thresholds = NULL; |
169 | 164 | ||
170 | if ((temp_thresholds = calloc(1, sizeof(thresholds))) == NULL) | 165 | if ((temp_thresholds = calloc(1, sizeof(thresholds))) == NULL) |
171 | die(STATE_UNKNOWN, _("Cannot allocate memory: %s"), | 166 | die(STATE_UNKNOWN, _("Cannot allocate memory: %s"), strerror(errno)); |
172 | strerror(errno)); | ||
173 | 167 | ||
174 | temp_thresholds->warning = NULL; | 168 | temp_thresholds->warning = NULL; |
175 | temp_thresholds->critical = NULL; | 169 | temp_thresholds->critical = NULL; |
@@ -190,9 +184,7 @@ _set_thresholds(thresholds **my_thresholds, char *warn_string, char *critical_st | |||
190 | return 0; | 184 | return 0; |
191 | } | 185 | } |
192 | 186 | ||
193 | void | 187 | void set_thresholds(thresholds **my_thresholds, char *warn_string, char *critical_string) { |
194 | set_thresholds(thresholds **my_thresholds, char *warn_string, char *critical_string) | ||
195 | { | ||
196 | switch (_set_thresholds(my_thresholds, warn_string, critical_string)) { | 188 | switch (_set_thresholds(my_thresholds, warn_string, critical_string)) { |
197 | case 0: | 189 | case 0: |
198 | return; | 190 | return; |
@@ -206,7 +198,7 @@ set_thresholds(thresholds **my_thresholds, char *warn_string, char *critical_str | |||
206 | 198 | ||
207 | void print_thresholds(const char *threshold_name, thresholds *my_threshold) { | 199 | void print_thresholds(const char *threshold_name, thresholds *my_threshold) { |
208 | printf("%s - ", threshold_name); | 200 | printf("%s - ", threshold_name); |
209 | if (! my_threshold) { | 201 | if (!my_threshold) { |
210 | printf("Threshold not set"); | 202 | printf("Threshold not set"); |
211 | } else { | 203 | } else { |
212 | if (my_threshold->warning) { | 204 | if (my_threshold->warning) { |
@@ -224,8 +216,7 @@ void print_thresholds(const char *threshold_name, thresholds *my_threshold) { | |||
224 | } | 216 | } |
225 | 217 | ||
226 | /* Returns true if alert should be raised based on the range */ | 218 | /* Returns true if alert should be raised based on the range */ |
227 | bool check_range(double value, range *my_range) | 219 | bool check_range(double value, range *my_range) { |
228 | { | ||
229 | bool no = false; | 220 | bool no = false; |
230 | bool yes = true; | 221 | bool yes = true; |
231 | 222 | ||
@@ -258,9 +249,7 @@ bool check_range(double value, range *my_range) | |||
258 | } | 249 | } |
259 | 250 | ||
260 | /* Returns status */ | 251 | /* Returns status */ |
261 | int | 252 | int get_status(double value, thresholds *my_thresholds) { |
262 | get_status(double value, thresholds *my_thresholds) | ||
263 | { | ||
264 | if (my_thresholds->critical != NULL) { | 253 | if (my_thresholds->critical != NULL) { |
265 | if (check_range(value, my_thresholds->critical) == true) { | 254 | if (check_range(value, my_thresholds->critical) == true) { |
266 | return STATE_CRITICAL; | 255 | return STATE_CRITICAL; |
@@ -274,27 +263,27 @@ get_status(double value, thresholds *my_thresholds) | |||
274 | return STATE_OK; | 263 | return STATE_OK; |
275 | } | 264 | } |
276 | 265 | ||
277 | char *np_escaped_string (const char *string) { | 266 | char *np_escaped_string(const char *string) { |
278 | char *data; | 267 | char *data; |
279 | int i, j=0; | 268 | int i, j = 0; |
280 | data = strdup(string); | 269 | data = strdup(string); |
281 | for (i=0; data[i]; i++) { | 270 | for (i = 0; data[i]; i++) { |
282 | if (data[i] == '\\') { | 271 | if (data[i] == '\\') { |
283 | switch(data[++i]) { | 272 | switch (data[++i]) { |
284 | case 'n': | 273 | case 'n': |
285 | data[j++] = '\n'; | 274 | data[j++] = '\n'; |
286 | break; | 275 | break; |
287 | case 'r': | 276 | case 'r': |
288 | data[j++] = '\r'; | 277 | data[j++] = '\r'; |
289 | break; | 278 | break; |
290 | case 't': | 279 | case 't': |
291 | data[j++] = '\t'; | 280 | data[j++] = '\t'; |
292 | break; | 281 | break; |
293 | case '\\': | 282 | case '\\': |
294 | data[j++] = '\\'; | 283 | data[j++] = '\\'; |
295 | break; | 284 | break; |
296 | default: | 285 | default: |
297 | data[j++] = data[i]; | 286 | data[j++] = data[i]; |
298 | } | 287 | } |
299 | } else { | 288 | } else { |
300 | data[j++] = data[i]; | 289 | data[j++] = data[i]; |
@@ -313,33 +302,38 @@ int np_check_if_root(void) { return (geteuid() == 0); } | |||
313 | * data strings. | 302 | * data strings. |
314 | */ | 303 | */ |
315 | char *np_extract_value(const char *varlist, const char *name, char sep) { | 304 | char *np_extract_value(const char *varlist, const char *name, char sep) { |
316 | char *tmp=NULL, *value=NULL; | 305 | char *tmp = NULL, *value = NULL; |
317 | int i; | 306 | int i; |
318 | 307 | ||
319 | while (1) { | 308 | while (1) { |
320 | /* Strip any leading space */ | 309 | /* Strip any leading space */ |
321 | for (; isspace(varlist[0]); varlist++); | 310 | for (; isspace(varlist[0]); varlist++) |
311 | ; | ||
322 | 312 | ||
323 | if (strncmp(name, varlist, strlen(name)) == 0) { | 313 | if (strncmp(name, varlist, strlen(name)) == 0) { |
324 | varlist += strlen(name); | 314 | varlist += strlen(name); |
325 | /* strip trailing spaces */ | 315 | /* strip trailing spaces */ |
326 | for (; isspace(varlist[0]); varlist++); | 316 | for (; isspace(varlist[0]); varlist++) |
317 | ; | ||
327 | 318 | ||
328 | if (varlist[0] == '=') { | 319 | if (varlist[0] == '=') { |
329 | /* We matched the key, go past the = sign */ | 320 | /* We matched the key, go past the = sign */ |
330 | varlist++; | 321 | varlist++; |
331 | /* strip leading spaces */ | 322 | /* strip leading spaces */ |
332 | for (; isspace(varlist[0]); varlist++); | 323 | for (; isspace(varlist[0]); varlist++) |
324 | ; | ||
333 | 325 | ||
334 | if ((tmp = index(varlist, sep))) { | 326 | if ((tmp = index(varlist, sep))) { |
335 | /* Value is delimited by a comma */ | 327 | /* Value is delimited by a comma */ |
336 | if (tmp-varlist == 0) continue; | 328 | if (tmp - varlist == 0) |
337 | value = (char *)calloc(1, tmp-varlist+1); | 329 | continue; |
338 | strncpy(value, varlist, tmp-varlist); | 330 | value = (char *)calloc(1, tmp - varlist + 1); |
339 | value[tmp-varlist] = '\0'; | 331 | strncpy(value, varlist, tmp - varlist); |
332 | value[tmp - varlist] = '\0'; | ||
340 | } else { | 333 | } else { |
341 | /* Value is delimited by a \0 */ | 334 | /* Value is delimited by a \0 */ |
342 | if (strlen(varlist) == 0) continue; | 335 | if (strlen(varlist) == 0) |
336 | continue; | ||
343 | value = (char *)calloc(1, strlen(varlist) + 1); | 337 | value = (char *)calloc(1, strlen(varlist) + 1); |
344 | strncpy(value, varlist, strlen(varlist)); | 338 | strncpy(value, varlist, strlen(varlist)); |
345 | value[strlen(varlist)] = '\0'; | 339 | value[strlen(varlist)] = '\0'; |
@@ -357,14 +351,14 @@ char *np_extract_value(const char *varlist, const char *name, char sep) { | |||
357 | } | 351 | } |
358 | 352 | ||
359 | /* Clean-up trailing spaces/newlines */ | 353 | /* Clean-up trailing spaces/newlines */ |
360 | if (value) for (i=strlen(value)-1; isspace(value[i]); i--) value[i] = '\0'; | 354 | if (value) |
355 | for (i = strlen(value) - 1; isspace(value[i]); i--) | ||
356 | value[i] = '\0'; | ||
361 | 357 | ||
362 | return value; | 358 | return value; |
363 | } | 359 | } |
364 | 360 | ||
365 | const char * | 361 | const char *state_text(int result) { |
366 | state_text (int result) | ||
367 | { | ||
368 | switch (result) { | 362 | switch (result) { |
369 | case STATE_OK: | 363 | case STATE_OK: |
370 | return "OK"; | 364 | return "OK"; |
@@ -383,14 +377,14 @@ state_text (int result) | |||
383 | * Read a string representing a state (ok, warning... or numeric: 0, 1) and | 377 | * Read a string representing a state (ok, warning... or numeric: 0, 1) and |
384 | * return the corresponding STATE_ value or ERROR) | 378 | * return the corresponding STATE_ value or ERROR) |
385 | */ | 379 | */ |
386 | int mp_translate_state (char *state_text) { | 380 | int mp_translate_state(char *state_text) { |
387 | if (!strcasecmp(state_text,"OK") || !strcmp(state_text,"0")) | 381 | if (!strcasecmp(state_text, "OK") || !strcmp(state_text, "0")) |
388 | return STATE_OK; | 382 | return STATE_OK; |
389 | if (!strcasecmp(state_text,"WARNING") || !strcmp(state_text,"1")) | 383 | if (!strcasecmp(state_text, "WARNING") || !strcmp(state_text, "1")) |
390 | return STATE_WARNING; | 384 | return STATE_WARNING; |
391 | if (!strcasecmp(state_text,"CRITICAL") || !strcmp(state_text,"2")) | 385 | if (!strcasecmp(state_text, "CRITICAL") || !strcmp(state_text, "2")) |
392 | return STATE_CRITICAL; | 386 | return STATE_CRITICAL; |
393 | if (!strcasecmp(state_text,"UNKNOWN") || !strcmp(state_text,"3")) | 387 | if (!strcasecmp(state_text, "UNKNOWN") || !strcmp(state_text, "3")) |
394 | return STATE_UNKNOWN; | 388 | return STATE_UNKNOWN; |
395 | return ERROR; | 389 | return ERROR; |
396 | } | 390 | } |
@@ -404,7 +398,7 @@ char *_np_state_generate_key() { | |||
404 | int i; | 398 | int i; |
405 | char **argv = this_monitoring_plugin->argv; | 399 | char **argv = this_monitoring_plugin->argv; |
406 | char keyname[41]; | 400 | char keyname[41]; |
407 | char *p=NULL; | 401 | char *p = NULL; |
408 | 402 | ||
409 | unsigned char result[256]; | 403 | unsigned char result[256]; |
410 | 404 | ||
@@ -418,7 +412,7 @@ char *_np_state_generate_key() { | |||
418 | 412 | ||
419 | EVP_DigestInit(ctx, EVP_sha256()); | 413 | EVP_DigestInit(ctx, EVP_sha256()); |
420 | 414 | ||
421 | for(i=0; i<this_monitoring_plugin->argc; i++) { | 415 | for (i = 0; i < this_monitoring_plugin->argc; i++) { |
422 | EVP_DigestUpdate(ctx, argv[i], strlen(argv[i])); | 416 | EVP_DigestUpdate(ctx, argv[i], strlen(argv[i])); |
423 | } | 417 | } |
424 | 418 | ||
@@ -427,28 +421,28 @@ char *_np_state_generate_key() { | |||
427 | 421 | ||
428 | struct sha256_ctx ctx; | 422 | struct sha256_ctx ctx; |
429 | 423 | ||
430 | for(i=0; i<this_monitoring_plugin->argc; i++) { | 424 | for (i = 0; i < this_monitoring_plugin->argc; i++) { |
431 | sha256_process_bytes(argv[i], strlen(argv[i]), &ctx); | 425 | sha256_process_bytes(argv[i], strlen(argv[i]), &ctx); |
432 | } | 426 | } |
433 | 427 | ||
434 | sha256_finish_ctx(&ctx, result); | 428 | sha256_finish_ctx(&ctx, result); |
435 | #endif // FOUNDOPENSSL | 429 | #endif // FOUNDOPENSSL |
436 | 430 | ||
437 | for (i=0; i<20; ++i) { | 431 | for (i = 0; i < 20; ++i) { |
438 | sprintf(&keyname[2*i], "%02x", result[i]); | 432 | sprintf(&keyname[2 * i], "%02x", result[i]); |
439 | } | 433 | } |
440 | 434 | ||
441 | keyname[40]='\0'; | 435 | keyname[40] = '\0'; |
442 | 436 | ||
443 | p = strdup(keyname); | 437 | p = strdup(keyname); |
444 | if(p==NULL) { | 438 | if (p == NULL) { |
445 | die(STATE_UNKNOWN, _("Cannot execute strdup: %s"), strerror(errno)); | 439 | die(STATE_UNKNOWN, _("Cannot execute strdup: %s"), strerror(errno)); |
446 | } | 440 | } |
447 | return p; | 441 | return p; |
448 | } | 442 | } |
449 | 443 | ||
450 | void _cleanup_state_data() { | 444 | void _cleanup_state_data() { |
451 | if (this_monitoring_plugin->state->state_data!=NULL) { | 445 | if (this_monitoring_plugin->state->state_data != NULL) { |
452 | np_free(this_monitoring_plugin->state->state_data->data); | 446 | np_free(this_monitoring_plugin->state->state_data->data); |
453 | np_free(this_monitoring_plugin->state->state_data); | 447 | np_free(this_monitoring_plugin->state->state_data); |
454 | } | 448 | } |
@@ -459,18 +453,18 @@ void _cleanup_state_data() { | |||
459 | * envvar NAGIOS_PLUGIN_STATE_DIRECTORY | 453 | * envvar NAGIOS_PLUGIN_STATE_DIRECTORY |
460 | * statically compiled shared state directory | 454 | * statically compiled shared state directory |
461 | */ | 455 | */ |
462 | char* _np_state_calculate_location_prefix(){ | 456 | char *_np_state_calculate_location_prefix() { |
463 | char *env_dir; | 457 | char *env_dir; |
464 | 458 | ||
465 | /* Do not allow passing MP_STATE_PATH in setuid plugins | 459 | /* Do not allow passing MP_STATE_PATH in setuid plugins |
466 | * for security reasons */ | 460 | * for security reasons */ |
467 | if (!mp_suid()) { | 461 | if (!mp_suid()) { |
468 | env_dir = getenv("MP_STATE_PATH"); | 462 | env_dir = getenv("MP_STATE_PATH"); |
469 | if(env_dir && env_dir[0] != '\0') | 463 | if (env_dir && env_dir[0] != '\0') |
470 | return env_dir; | 464 | return env_dir; |
471 | /* This is the former ENV, for backward-compatibility */ | 465 | /* This is the former ENV, for backward-compatibility */ |
472 | env_dir = getenv("NAGIOS_PLUGIN_STATE_DIRECTORY"); | 466 | env_dir = getenv("NAGIOS_PLUGIN_STATE_DIRECTORY"); |
473 | if(env_dir && env_dir[0] != '\0') | 467 | if (env_dir && env_dir[0] != '\0') |
474 | return env_dir; | 468 | return env_dir; |
475 | } | 469 | } |
476 | 470 | ||
@@ -486,46 +480,43 @@ void np_enable_state(char *keyname, int expected_data_version) { | |||
486 | state_key *this_state = NULL; | 480 | state_key *this_state = NULL; |
487 | char *temp_filename = NULL; | 481 | char *temp_filename = NULL; |
488 | char *temp_keyname = NULL; | 482 | char *temp_keyname = NULL; |
489 | char *p=NULL; | 483 | char *p = NULL; |
490 | int ret; | 484 | int ret; |
491 | 485 | ||
492 | if(this_monitoring_plugin==NULL) | 486 | if (this_monitoring_plugin == NULL) |
493 | die(STATE_UNKNOWN, _("This requires np_init to be called")); | 487 | die(STATE_UNKNOWN, _("This requires np_init to be called")); |
494 | 488 | ||
495 | this_state = (state_key *) calloc(1, sizeof(state_key)); | 489 | this_state = (state_key *)calloc(1, sizeof(state_key)); |
496 | if(this_state==NULL) | 490 | if (this_state == NULL) |
497 | die(STATE_UNKNOWN, _("Cannot allocate memory: %s"), | 491 | die(STATE_UNKNOWN, _("Cannot allocate memory: %s"), strerror(errno)); |
498 | strerror(errno)); | ||
499 | 492 | ||
500 | if(keyname==NULL) { | 493 | if (keyname == NULL) { |
501 | temp_keyname = _np_state_generate_key(); | 494 | temp_keyname = _np_state_generate_key(); |
502 | } else { | 495 | } else { |
503 | temp_keyname = strdup(keyname); | 496 | temp_keyname = strdup(keyname); |
504 | if(temp_keyname==NULL) | 497 | if (temp_keyname == NULL) |
505 | die(STATE_UNKNOWN, _("Cannot execute strdup: %s"), strerror(errno)); | 498 | die(STATE_UNKNOWN, _("Cannot execute strdup: %s"), strerror(errno)); |
506 | } | 499 | } |
507 | /* Die if invalid characters used for keyname */ | 500 | /* Die if invalid characters used for keyname */ |
508 | p = temp_keyname; | 501 | p = temp_keyname; |
509 | while(*p!='\0') { | 502 | while (*p != '\0') { |
510 | if(! (isalnum(*p) || *p == '_')) { | 503 | if (!(isalnum(*p) || *p == '_')) { |
511 | die(STATE_UNKNOWN, _("Invalid character for keyname - only alphanumerics or '_'")); | 504 | die(STATE_UNKNOWN, _("Invalid character for keyname - only alphanumerics or '_'")); |
512 | } | 505 | } |
513 | p++; | 506 | p++; |
514 | } | 507 | } |
515 | this_state->name=temp_keyname; | 508 | this_state->name = temp_keyname; |
516 | this_state->plugin_name=this_monitoring_plugin->plugin_name; | 509 | this_state->plugin_name = this_monitoring_plugin->plugin_name; |
517 | this_state->data_version=expected_data_version; | 510 | this_state->data_version = expected_data_version; |
518 | this_state->state_data=NULL; | 511 | this_state->state_data = NULL; |
519 | 512 | ||
520 | /* Calculate filename */ | 513 | /* Calculate filename */ |
521 | ret = asprintf(&temp_filename, "%s/%lu/%s/%s", | 514 | ret = asprintf(&temp_filename, "%s/%lu/%s/%s", _np_state_calculate_location_prefix(), (unsigned long)geteuid(), |
522 | _np_state_calculate_location_prefix(), (unsigned long)geteuid(), | 515 | this_monitoring_plugin->plugin_name, this_state->name); |
523 | this_monitoring_plugin->plugin_name, this_state->name); | ||
524 | if (ret < 0) | 516 | if (ret < 0) |
525 | die(STATE_UNKNOWN, _("Cannot allocate memory: %s"), | 517 | die(STATE_UNKNOWN, _("Cannot allocate memory: %s"), strerror(errno)); |
526 | strerror(errno)); | ||
527 | 518 | ||
528 | this_state->_filename=temp_filename; | 519 | this_state->_filename = temp_filename; |
529 | 520 | ||
530 | this_monitoring_plugin->state = this_state; | 521 | this_monitoring_plugin->state = this_state; |
531 | } | 522 | } |
@@ -538,23 +529,22 @@ void np_enable_state(char *keyname, int expected_data_version) { | |||
538 | * if exceptional error. | 529 | * if exceptional error. |
539 | */ | 530 | */ |
540 | state_data *np_state_read() { | 531 | state_data *np_state_read() { |
541 | state_data *this_state_data=NULL; | 532 | state_data *this_state_data = NULL; |
542 | FILE *statefile; | 533 | FILE *statefile; |
543 | bool rc = false; | 534 | bool rc = false; |
544 | 535 | ||
545 | if(this_monitoring_plugin==NULL) | 536 | if (this_monitoring_plugin == NULL) |
546 | die(STATE_UNKNOWN, _("This requires np_init to be called")); | 537 | die(STATE_UNKNOWN, _("This requires np_init to be called")); |
547 | 538 | ||
548 | /* Open file. If this fails, no previous state found */ | 539 | /* Open file. If this fails, no previous state found */ |
549 | statefile = fopen( this_monitoring_plugin->state->_filename, "r" ); | 540 | statefile = fopen(this_monitoring_plugin->state->_filename, "r"); |
550 | if(statefile!=NULL) { | 541 | if (statefile != NULL) { |
551 | 542 | ||
552 | this_state_data = (state_data *) calloc(1, sizeof(state_data)); | 543 | this_state_data = (state_data *)calloc(1, sizeof(state_data)); |
553 | if(this_state_data==NULL) | 544 | if (this_state_data == NULL) |
554 | die(STATE_UNKNOWN, _("Cannot allocate memory: %s"), | 545 | die(STATE_UNKNOWN, _("Cannot allocate memory: %s"), strerror(errno)); |
555 | strerror(errno)); | ||
556 | 546 | ||
557 | this_state_data->data=NULL; | 547 | this_state_data->data = NULL; |
558 | this_monitoring_plugin->state->state_data = this_state_data; | 548 | this_monitoring_plugin->state->state_data = this_state_data; |
559 | 549 | ||
560 | rc = _np_state_read_file(statefile); | 550 | rc = _np_state_read_file(statefile); |
@@ -562,7 +552,7 @@ state_data *np_state_read() { | |||
562 | fclose(statefile); | 552 | fclose(statefile); |
563 | } | 553 | } |
564 | 554 | ||
565 | if(!rc) { | 555 | if (!rc) { |
566 | _cleanup_state_data(); | 556 | _cleanup_state_data(); |
567 | } | 557 | } |
568 | 558 | ||
@@ -577,60 +567,65 @@ bool _np_state_read_file(FILE *f) { | |||
577 | size_t pos; | 567 | size_t pos; |
578 | char *line; | 568 | char *line; |
579 | int i; | 569 | int i; |
580 | int failure=0; | 570 | int failure = 0; |
581 | time_t current_time, data_time; | 571 | time_t current_time, data_time; |
582 | enum { STATE_FILE_VERSION, STATE_DATA_VERSION, STATE_DATA_TIME, STATE_DATA_TEXT, STATE_DATA_END } expected=STATE_FILE_VERSION; | 572 | enum { |
573 | STATE_FILE_VERSION, | ||
574 | STATE_DATA_VERSION, | ||
575 | STATE_DATA_TIME, | ||
576 | STATE_DATA_TEXT, | ||
577 | STATE_DATA_END | ||
578 | } expected = STATE_FILE_VERSION; | ||
583 | 579 | ||
584 | time(¤t_time); | 580 | time(¤t_time); |
585 | 581 | ||
586 | /* Note: This introduces a limit of 1024 bytes in the string data */ | 582 | /* Note: This introduces a limit of 1024 bytes in the string data */ |
587 | line = (char *) calloc(1, 1024); | 583 | line = (char *)calloc(1, 1024); |
588 | if(line==NULL) | 584 | if (line == NULL) |
589 | die(STATE_UNKNOWN, _("Cannot allocate memory: %s"), | 585 | die(STATE_UNKNOWN, _("Cannot allocate memory: %s"), strerror(errno)); |
590 | strerror(errno)); | 586 | |
591 | 587 | while (!failure && (fgets(line, 1024, f)) != NULL) { | |
592 | while(!failure && (fgets(line,1024,f))!=NULL){ | 588 | pos = strlen(line); |
593 | pos=strlen(line); | 589 | if (line[pos - 1] == '\n') { |
594 | if(line[pos-1]=='\n') { | 590 | line[pos - 1] = '\0'; |
595 | line[pos-1]='\0'; | ||
596 | } | 591 | } |
597 | 592 | ||
598 | if(line[0] == '#') continue; | 593 | if (line[0] == '#') |
594 | continue; | ||
599 | 595 | ||
600 | switch(expected) { | 596 | switch (expected) { |
601 | case STATE_FILE_VERSION: | 597 | case STATE_FILE_VERSION: |
602 | i=atoi(line); | 598 | i = atoi(line); |
603 | if(i!=NP_STATE_FORMAT_VERSION) | 599 | if (i != NP_STATE_FORMAT_VERSION) |
604 | failure++; | 600 | failure++; |
605 | else | 601 | else |
606 | expected=STATE_DATA_VERSION; | 602 | expected = STATE_DATA_VERSION; |
607 | break; | 603 | break; |
608 | case STATE_DATA_VERSION: | 604 | case STATE_DATA_VERSION: |
609 | i=atoi(line); | 605 | i = atoi(line); |
610 | if(i != this_monitoring_plugin->state->data_version) | 606 | if (i != this_monitoring_plugin->state->data_version) |
611 | failure++; | 607 | failure++; |
612 | else | 608 | else |
613 | expected=STATE_DATA_TIME; | 609 | expected = STATE_DATA_TIME; |
614 | break; | 610 | break; |
615 | case STATE_DATA_TIME: | 611 | case STATE_DATA_TIME: |
616 | /* If time > now, error */ | 612 | /* If time > now, error */ |
617 | data_time=strtoul(line,NULL,10); | 613 | data_time = strtoul(line, NULL, 10); |
618 | if(data_time > current_time) | 614 | if (data_time > current_time) |
619 | failure++; | 615 | failure++; |
620 | else { | 616 | else { |
621 | this_monitoring_plugin->state->state_data->time = data_time; | 617 | this_monitoring_plugin->state->state_data->time = data_time; |
622 | expected=STATE_DATA_TEXT; | 618 | expected = STATE_DATA_TEXT; |
623 | } | 619 | } |
624 | break; | 620 | break; |
625 | case STATE_DATA_TEXT: | 621 | case STATE_DATA_TEXT: |
626 | this_monitoring_plugin->state->state_data->data = strdup(line); | 622 | this_monitoring_plugin->state->state_data->data = strdup(line); |
627 | if(this_monitoring_plugin->state->state_data->data==NULL) | 623 | if (this_monitoring_plugin->state->state_data->data == NULL) |
628 | die(STATE_UNKNOWN, _("Cannot execute strdup: %s"), strerror(errno)); | 624 | die(STATE_UNKNOWN, _("Cannot execute strdup: %s"), strerror(errno)); |
629 | expected=STATE_DATA_END; | 625 | expected = STATE_DATA_END; |
630 | status=true; | 626 | status = true; |
631 | break; | 627 | break; |
632 | case STATE_DATA_END: | 628 | case STATE_DATA_END:; |
633 | ; | ||
634 | } | 629 | } |
635 | } | 630 | } |
636 | 631 | ||
@@ -647,77 +642,75 @@ bool _np_state_read_file(FILE *f) { | |||
647 | */ | 642 | */ |
648 | void np_state_write_string(time_t data_time, char *data_string) { | 643 | void np_state_write_string(time_t data_time, char *data_string) { |
649 | FILE *fp; | 644 | FILE *fp; |
650 | char *temp_file=NULL; | 645 | char *temp_file = NULL; |
651 | int fd=0, result=0; | 646 | int fd = 0, result = 0; |
652 | time_t current_time; | 647 | time_t current_time; |
653 | char *directories=NULL; | 648 | char *directories = NULL; |
654 | char *p=NULL; | 649 | char *p = NULL; |
655 | 650 | ||
656 | if(data_time==0) | 651 | if (data_time == 0) |
657 | time(¤t_time); | 652 | time(¤t_time); |
658 | else | 653 | else |
659 | current_time=data_time; | 654 | current_time = data_time; |
660 | 655 | ||
661 | /* If file doesn't currently exist, create directories */ | 656 | /* If file doesn't currently exist, create directories */ |
662 | if(access(this_monitoring_plugin->state->_filename,F_OK)!=0) { | 657 | if (access(this_monitoring_plugin->state->_filename, F_OK) != 0) { |
663 | result = asprintf(&directories, "%s", this_monitoring_plugin->state->_filename); | 658 | result = asprintf(&directories, "%s", this_monitoring_plugin->state->_filename); |
664 | if(result < 0) | 659 | if (result < 0) |
665 | die(STATE_UNKNOWN, _("Cannot allocate memory: %s"), | 660 | die(STATE_UNKNOWN, _("Cannot allocate memory: %s"), strerror(errno)); |
666 | strerror(errno)); | 661 | |
667 | 662 | for (p = directories + 1; *p; p++) { | |
668 | for(p=directories+1; *p; p++) { | 663 | if (*p == '/') { |
669 | if(*p=='/') { | 664 | *p = '\0'; |
670 | *p='\0'; | 665 | if ((access(directories, F_OK) != 0) && (mkdir(directories, S_IRWXU) != 0)) { |
671 | if((access(directories,F_OK)!=0) && (mkdir(directories, S_IRWXU)!=0)) { | ||
672 | /* Can't free this! Otherwise error message is wrong! */ | 666 | /* Can't free this! Otherwise error message is wrong! */ |
673 | /* np_free(directories); */ | 667 | /* np_free(directories); */ |
674 | die(STATE_UNKNOWN, _("Cannot create directory: %s"), directories); | 668 | die(STATE_UNKNOWN, _("Cannot create directory: %s"), directories); |
675 | } | 669 | } |
676 | *p='/'; | 670 | *p = '/'; |
677 | } | 671 | } |
678 | } | 672 | } |
679 | np_free(directories); | 673 | np_free(directories); |
680 | } | 674 | } |
681 | 675 | ||
682 | result = asprintf(&temp_file,"%s.XXXXXX",this_monitoring_plugin->state->_filename); | 676 | result = asprintf(&temp_file, "%s.XXXXXX", this_monitoring_plugin->state->_filename); |
683 | if(result < 0) | 677 | if (result < 0) |
684 | die(STATE_UNKNOWN, _("Cannot allocate memory: %s"), | 678 | die(STATE_UNKNOWN, _("Cannot allocate memory: %s"), strerror(errno)); |
685 | strerror(errno)); | ||
686 | 679 | ||
687 | if((fd=mkstemp(temp_file))==-1) { | 680 | if ((fd = mkstemp(temp_file)) == -1) { |
688 | np_free(temp_file); | 681 | np_free(temp_file); |
689 | die(STATE_UNKNOWN, _("Cannot create temporary filename")); | 682 | die(STATE_UNKNOWN, _("Cannot create temporary filename")); |
690 | } | 683 | } |
691 | 684 | ||
692 | fp=(FILE *)fdopen(fd,"w"); | 685 | fp = (FILE *)fdopen(fd, "w"); |
693 | if(fp==NULL) { | 686 | if (fp == NULL) { |
694 | close(fd); | 687 | close(fd); |
695 | unlink(temp_file); | 688 | unlink(temp_file); |
696 | np_free(temp_file); | 689 | np_free(temp_file); |
697 | die(STATE_UNKNOWN, _("Unable to open temporary state file")); | 690 | die(STATE_UNKNOWN, _("Unable to open temporary state file")); |
698 | } | 691 | } |
699 | 692 | ||
700 | fprintf(fp,"# NP State file\n"); | 693 | fprintf(fp, "# NP State file\n"); |
701 | fprintf(fp,"%d\n",NP_STATE_FORMAT_VERSION); | 694 | fprintf(fp, "%d\n", NP_STATE_FORMAT_VERSION); |
702 | fprintf(fp,"%d\n",this_monitoring_plugin->state->data_version); | 695 | fprintf(fp, "%d\n", this_monitoring_plugin->state->data_version); |
703 | fprintf(fp,"%lu\n",current_time); | 696 | fprintf(fp, "%lu\n", current_time); |
704 | fprintf(fp,"%s\n",data_string); | 697 | fprintf(fp, "%s\n", data_string); |
705 | 698 | ||
706 | fchmod(fd, S_IRUSR | S_IWUSR | S_IRGRP); | 699 | fchmod(fd, S_IRUSR | S_IWUSR | S_IRGRP); |
707 | 700 | ||
708 | fflush(fp); | 701 | fflush(fp); |
709 | 702 | ||
710 | result=fclose(fp); | 703 | result = fclose(fp); |
711 | 704 | ||
712 | fsync(fd); | 705 | fsync(fd); |
713 | 706 | ||
714 | if(result!=0) { | 707 | if (result != 0) { |
715 | unlink(temp_file); | 708 | unlink(temp_file); |
716 | np_free(temp_file); | 709 | np_free(temp_file); |
717 | die(STATE_UNKNOWN, _("Error writing temp file")); | 710 | die(STATE_UNKNOWN, _("Error writing temp file")); |
718 | } | 711 | } |
719 | 712 | ||
720 | if(rename(temp_file, this_monitoring_plugin->state->_filename)!=0) { | 713 | if (rename(temp_file, this_monitoring_plugin->state->_filename) != 0) { |
721 | unlink(temp_file); | 714 | unlink(temp_file); |
722 | np_free(temp_file); | 715 | np_free(temp_file); |
723 | die(STATE_UNKNOWN, _("Cannot rename state temp file")); | 716 | 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 @@ | |||
3 | /* Header file for Monitoring Plugins utils_base.c */ | 3 | /* Header file for Monitoring Plugins utils_base.c */ |
4 | 4 | ||
5 | #ifndef USE_OPENSSL | 5 | #ifndef USE_OPENSSL |
6 | # include "sha256.h" | 6 | # include "sha256.h" |
7 | #endif | 7 | #endif |
8 | 8 | ||
9 | /* This file holds header information for thresholds - use this in preference to | 9 | /* This file holds header information for thresholds - use this in preference to |
@@ -20,44 +20,43 @@ | |||
20 | #define INSIDE 1 | 20 | #define INSIDE 1 |
21 | 21 | ||
22 | typedef struct range_struct { | 22 | typedef struct range_struct { |
23 | double start; | 23 | double start; |
24 | bool start_infinity; | 24 | bool start_infinity; |
25 | double end; | 25 | double end; |
26 | int end_infinity; | 26 | int end_infinity; |
27 | int alert_on; /* OUTSIDE (default) or INSIDE */ | 27 | int alert_on; /* OUTSIDE (default) or INSIDE */ |
28 | char* text; /* original unparsed text input */ | 28 | char *text; /* original unparsed text input */ |
29 | } range; | 29 | } range; |
30 | 30 | ||
31 | typedef struct thresholds_struct { | 31 | typedef struct thresholds_struct { |
32 | range *warning; | 32 | range *warning; |
33 | range *critical; | 33 | range *critical; |
34 | } thresholds; | 34 | } thresholds; |
35 | 35 | ||
36 | #define NP_STATE_FORMAT_VERSION 1 | 36 | #define NP_STATE_FORMAT_VERSION 1 |
37 | 37 | ||
38 | typedef struct state_data_struct { | 38 | typedef struct state_data_struct { |
39 | time_t time; | 39 | time_t time; |
40 | void *data; | 40 | void *data; |
41 | int length; /* Of binary data */ | 41 | int length; /* Of binary data */ |
42 | } state_data; | 42 | } state_data; |
43 | |||
44 | 43 | ||
45 | typedef struct state_key_struct { | 44 | typedef struct state_key_struct { |
46 | char *name; | 45 | char *name; |
47 | char *plugin_name; | 46 | char *plugin_name; |
48 | int data_version; | 47 | int data_version; |
49 | char *_filename; | 48 | char *_filename; |
50 | state_data *state_data; | 49 | state_data *state_data; |
51 | } state_key; | 50 | } state_key; |
52 | 51 | ||
53 | typedef struct np_struct { | 52 | typedef struct np_struct { |
54 | char *plugin_name; | 53 | char *plugin_name; |
55 | state_key *state; | 54 | state_key *state; |
56 | int argc; | 55 | int argc; |
57 | char **argv; | 56 | char **argv; |
58 | } monitoring_plugin; | 57 | } monitoring_plugin; |
59 | 58 | ||
60 | range *parse_range_string (char *); | 59 | range *parse_range_string(char *); |
61 | int _set_thresholds(thresholds **, char *, char *); | 60 | int _set_thresholds(thresholds **, char *, char *); |
62 | void set_thresholds(thresholds **, char *, char *); | 61 | void set_thresholds(thresholds **, char *, char *); |
63 | void print_thresholds(const char *, thresholds *); | 62 | void print_thresholds(const char *, thresholds *); |
@@ -71,13 +70,13 @@ extern unsigned int timeout_interval; | |||
71 | /* All possible characters in a threshold range */ | 70 | /* All possible characters in a threshold range */ |
72 | #define NP_THRESHOLDS_CHARS "-0123456789.:@~" | 71 | #define NP_THRESHOLDS_CHARS "-0123456789.:@~" |
73 | 72 | ||
74 | char *np_escaped_string (const char *); | 73 | char *np_escaped_string(const char *); |
75 | 74 | ||
76 | void die (int, const char *, ...) __attribute__((noreturn,format(printf, 2, 3))); | 75 | void die(int, const char *, ...) __attribute__((noreturn, format(printf, 2, 3))); |
77 | 76 | ||
78 | /* Return codes for _set_thresholds */ | 77 | /* Return codes for _set_thresholds */ |
79 | #define NP_RANGE_UNPARSEABLE 1 | 78 | #define NP_RANGE_UNPARSEABLE 1 |
80 | #define NP_WARN_WITHIN_CRIT 2 | 79 | #define NP_WARN_WITHIN_CRIT 2 |
81 | 80 | ||
82 | /* a simple check to see if we're running as root. | 81 | /* a simple check to see if we're running as root. |
83 | * returns zero on failure, nonzero on success */ | 82 | * returns zero on failure, nonzero on success */ |
@@ -93,7 +92,7 @@ int np_check_if_root(void); | |||
93 | * This function can be used to parse NTP control packet data and performance | 92 | * This function can be used to parse NTP control packet data and performance |
94 | * data strings. | 93 | * data strings. |
95 | */ | 94 | */ |
96 | char *np_extract_value(const char*, const char*, char); | 95 | char *np_extract_value(const char *, const char *, char); |
97 | 96 | ||
98 | /* | 97 | /* |
99 | * Same as np_extract_value with separator suitable for NTP control packet | 98 | * 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); | |||
105 | * Read a string representing a state (ok, warning... or numeric: 0, 1) and | 104 | * Read a string representing a state (ok, warning... or numeric: 0, 1) and |
106 | * return the corresponding NP_STATE or ERROR) | 105 | * return the corresponding NP_STATE or ERROR) |
107 | */ | 106 | */ |
108 | int mp_translate_state (char *); | 107 | int mp_translate_state(char *); |
109 | 108 | ||
110 | void np_enable_state(char *, int); | 109 | void np_enable_state(char *, int); |
111 | state_data *np_state_read(); | 110 | state_data *np_state_read(); |
@@ -114,6 +113,6 @@ void np_state_write_string(time_t, char *); | |||
114 | void np_init(char *, int argc, char **argv); | 113 | void np_init(char *, int argc, char **argv); |
115 | void np_set_args(int argc, char **argv); | 114 | void np_set_args(int argc, char **argv); |
116 | void np_cleanup(); | 115 | void np_cleanup(); |
117 | const char *state_text (int); | 116 | const char *state_text(int); |
118 | 117 | ||
119 | #endif /* _UTILS_BASE_ */ | 118 | #endif /* _UTILS_BASE_ */ |
diff --git a/lib/utils_cmd.c b/lib/utils_cmd.c index 7957ec1..18350ac 100644 --- a/lib/utils_cmd.c +++ b/lib/utils_cmd.c | |||
@@ -1,40 +1,40 @@ | |||
1 | /***************************************************************************** | 1 | /***************************************************************************** |
2 | * | 2 | * |
3 | * Monitoring run command utilities | 3 | * Monitoring run command utilities |
4 | * | 4 | * |
5 | * License: GPL | 5 | * License: GPL |
6 | * Copyright (c) 2005-2006 Monitoring Plugins Development Team | 6 | * Copyright (c) 2005-2024 Monitoring Plugins Development Team |
7 | * | 7 | * |
8 | * Description : | 8 | * Description : |
9 | * | 9 | * |
10 | * A simple interface to executing programs from other programs, using an | 10 | * A simple interface to executing programs from other programs, using an |
11 | * optimized and safe popen()-like implementation. It is considered safe | 11 | * optimized and safe popen()-like implementation. It is considered safe |
12 | * in that no shell needs to be spawned and the environment passed to the | 12 | * in that no shell needs to be spawned and the environment passed to the |
13 | * execve()'d program is essentially empty. | 13 | * execve()'d program is essentially empty. |
14 | * | 14 | * |
15 | * The code in this file is a derivative of popen.c which in turn was taken | 15 | * The code in this file is a derivative of popen.c which in turn was taken |
16 | * from "Advanced Programming for the Unix Environment" by W. Richard Stevens. | 16 | * from "Advanced Programming for the Unix Environment" by W. Richard Stevens. |
17 | * | 17 | * |
18 | * Care has been taken to make sure the functions are async-safe. The one | 18 | * Care has been taken to make sure the functions are async-safe. The one |
19 | * function which isn't is cmd_init() which it doesn't make sense to | 19 | * function which isn't is cmd_init() which it doesn't make sense to |
20 | * call twice anyway, so the api as a whole should be considered async-safe. | 20 | * call twice anyway, so the api as a whole should be considered async-safe. |
21 | * | 21 | * |
22 | * | 22 | * |
23 | * This program is free software: you can redistribute it and/or modify | 23 | * This program is free software: you can redistribute it and/or modify |
24 | * it under the terms of the GNU General Public License as published by | 24 | * it under the terms of the GNU General Public License as published by |
25 | * the Free Software Foundation, either version 3 of the License, or | 25 | * the Free Software Foundation, either version 3 of the License, or |
26 | * (at your option) any later version. | 26 | * (at your option) any later version. |
27 | * | 27 | * |
28 | * This program is distributed in the hope that it will be useful, | 28 | * This program is distributed in the hope that it will be useful, |
29 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 29 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
30 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 30 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
31 | * GNU General Public License for more details. | 31 | * GNU General Public License for more details. |
32 | * | 32 | * |
33 | * You should have received a copy of the GNU General Public License | 33 | * You should have received a copy of the GNU General Public License |
34 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 34 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
35 | * | 35 | * |
36 | * | 36 | * |
37 | *****************************************************************************/ | 37 | *****************************************************************************/ |
38 | 38 | ||
39 | #define NAGIOSPLUG_API_C 1 | 39 | #define NAGIOSPLUG_API_C 1 |
40 | 40 | ||
@@ -59,7 +59,7 @@ static pid_t *_cmd_pids = NULL; | |||
59 | #include <fcntl.h> | 59 | #include <fcntl.h> |
60 | 60 | ||
61 | #ifdef HAVE_SYS_WAIT_H | 61 | #ifdef HAVE_SYS_WAIT_H |
62 | # include <sys/wait.h> | 62 | # include <sys/wait.h> |
63 | #endif | 63 | #endif |
64 | 64 | ||
65 | /* used in _cmd_open to pass the environment to commands */ | 65 | /* used in _cmd_open to pass the environment to commands */ |
@@ -67,57 +67,48 @@ extern char **environ; | |||
67 | 67 | ||
68 | /** macros **/ | 68 | /** macros **/ |
69 | #ifndef WEXITSTATUS | 69 | #ifndef WEXITSTATUS |
70 | # define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8) | 70 | # define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8) |
71 | #endif | 71 | #endif |
72 | 72 | ||
73 | #ifndef WIFEXITED | 73 | #ifndef WIFEXITED |
74 | # define WIFEXITED(stat_val) (((stat_val) & 255) == 0) | 74 | # define WIFEXITED(stat_val) (((stat_val)&255) == 0) |
75 | #endif | 75 | #endif |
76 | 76 | ||
77 | /* 4.3BSD Reno <signal.h> doesn't define SIG_ERR */ | 77 | /* 4.3BSD Reno <signal.h> doesn't define SIG_ERR */ |
78 | #if defined(SIG_IGN) && !defined(SIG_ERR) | 78 | #if defined(SIG_IGN) && !defined(SIG_ERR) |
79 | # define SIG_ERR ((Sigfunc *)-1) | 79 | # define SIG_ERR ((Sigfunc *)-1) |
80 | #endif | 80 | #endif |
81 | 81 | ||
82 | /** prototypes **/ | 82 | /** prototypes **/ |
83 | static int _cmd_open (char *const *, int *, int *) | 83 | static int _cmd_open(char *const *, int *, int *) __attribute__((__nonnull__(1, 2, 3))); |
84 | __attribute__ ((__nonnull__ (1, 2, 3))); | ||
85 | 84 | ||
86 | static int _cmd_fetch_output (int, output *, int) | 85 | static int _cmd_fetch_output(int, output *, int) __attribute__((__nonnull__(2))); |
87 | __attribute__ ((__nonnull__ (2))); | ||
88 | 86 | ||
89 | static int _cmd_close (int); | 87 | static int _cmd_close(int); |
90 | 88 | ||
91 | /* prototype imported from utils.h */ | 89 | /* prototype imported from utils.h */ |
92 | extern void die (int, const char *, ...) | 90 | extern void die(int, const char *, ...) __attribute__((__noreturn__, __format__(__printf__, 2, 3))); |
93 | __attribute__ ((__noreturn__, __format__ (__printf__, 2, 3))); | ||
94 | |||
95 | 91 | ||
96 | /* this function is NOT async-safe. It is exported so multithreaded | 92 | /* this function is NOT async-safe. It is exported so multithreaded |
97 | * plugins (or other apps) can call it prior to running any commands | 93 | * plugins (or other apps) can call it prior to running any commands |
98 | * through this api and thus achieve async-safeness throughout the api */ | 94 | * through this api and thus achieve async-safeness throughout the api */ |
99 | void | 95 | void cmd_init(void) { |
100 | cmd_init (void) | ||
101 | { | ||
102 | long maxfd = mp_open_max(); | 96 | long maxfd = mp_open_max(); |
103 | 97 | ||
104 | /* if maxfd is unnaturally high, we force it to a lower value | 98 | /* if maxfd is unnaturally high, we force it to a lower value |
105 | * ( e.g. on SunOS, when ulimit is set to unlimited: 2147483647 this would cause | 99 | * ( e.g. on SunOS, when ulimit is set to unlimited: 2147483647 this would cause |
106 | * a segfault when following calloc is called ... ) */ | 100 | * a segfault when following calloc is called ... ) */ |
107 | 101 | ||
108 | if ( maxfd > MAXFD_LIMIT ) { | 102 | if (maxfd > MAXFD_LIMIT) { |
109 | maxfd = MAXFD_LIMIT; | 103 | maxfd = MAXFD_LIMIT; |
110 | } | 104 | } |
111 | 105 | ||
112 | if (!_cmd_pids) | 106 | if (!_cmd_pids) |
113 | _cmd_pids = calloc (maxfd, sizeof (pid_t)); | 107 | _cmd_pids = calloc(maxfd, sizeof(pid_t)); |
114 | } | 108 | } |
115 | 109 | ||
116 | |||
117 | /* Start running a command, array style */ | 110 | /* Start running a command, array style */ |
118 | static int | 111 | static int _cmd_open(char *const *argv, int *pfd, int *pfderr) { |
119 | _cmd_open (char *const *argv, int *pfd, int *pfderr) | ||
120 | { | ||
121 | pid_t pid; | 112 | pid_t pid; |
122 | #ifdef RLIMIT_CORE | 113 | #ifdef RLIMIT_CORE |
123 | struct rlimit limit; | 114 | struct rlimit limit; |
@@ -130,26 +121,26 @@ _cmd_open (char *const *argv, int *pfd, int *pfderr) | |||
130 | 121 | ||
131 | setenv("LC_ALL", "C", 1); | 122 | setenv("LC_ALL", "C", 1); |
132 | 123 | ||
133 | if (pipe (pfd) < 0 || pipe (pfderr) < 0 || (pid = fork ()) < 0) | 124 | if (pipe(pfd) < 0 || pipe(pfderr) < 0 || (pid = fork()) < 0) |
134 | return -1; /* errno set by the failing function */ | 125 | return -1; /* errno set by the failing function */ |
135 | 126 | ||
136 | /* child runs exceve() and _exit. */ | 127 | /* child runs exceve() and _exit. */ |
137 | if (pid == 0) { | 128 | if (pid == 0) { |
138 | #ifdef RLIMIT_CORE | 129 | #ifdef RLIMIT_CORE |
139 | /* the program we execve shouldn't leave core files */ | 130 | /* the program we execve shouldn't leave core files */ |
140 | getrlimit (RLIMIT_CORE, &limit); | 131 | getrlimit(RLIMIT_CORE, &limit); |
141 | limit.rlim_cur = 0; | 132 | limit.rlim_cur = 0; |
142 | setrlimit (RLIMIT_CORE, &limit); | 133 | setrlimit(RLIMIT_CORE, &limit); |
143 | #endif | 134 | #endif |
144 | close (pfd[0]); | 135 | close(pfd[0]); |
145 | if (pfd[1] != STDOUT_FILENO) { | 136 | if (pfd[1] != STDOUT_FILENO) { |
146 | dup2 (pfd[1], STDOUT_FILENO); | 137 | dup2(pfd[1], STDOUT_FILENO); |
147 | close (pfd[1]); | 138 | close(pfd[1]); |
148 | } | 139 | } |
149 | close (pfderr[0]); | 140 | close(pfderr[0]); |
150 | if (pfderr[1] != STDERR_FILENO) { | 141 | if (pfderr[1] != STDERR_FILENO) { |
151 | dup2 (pfderr[1], STDERR_FILENO); | 142 | dup2(pfderr[1], STDERR_FILENO); |
152 | close (pfderr[1]); | 143 | close(pfderr[1]); |
153 | } | 144 | } |
154 | 145 | ||
155 | /* close all descriptors in _cmd_pids[] | 146 | /* close all descriptors in _cmd_pids[] |
@@ -158,16 +149,16 @@ _cmd_open (char *const *argv, int *pfd, int *pfderr) | |||
158 | long maxfd = mp_open_max(); | 149 | long maxfd = mp_open_max(); |
159 | for (i = 0; i < maxfd; i++) | 150 | for (i = 0; i < maxfd; i++) |
160 | if (_cmd_pids[i] > 0) | 151 | if (_cmd_pids[i] > 0) |
161 | close (i); | 152 | close(i); |
162 | 153 | ||
163 | execve (argv[0], argv, environ); | 154 | execve(argv[0], argv, environ); |
164 | _exit (STATE_UNKNOWN); | 155 | _exit(STATE_UNKNOWN); |
165 | } | 156 | } |
166 | 157 | ||
167 | /* parent picks up execution here */ | 158 | /* parent picks up execution here */ |
168 | /* close children descriptors in our address space */ | 159 | /* close children descriptors in our address space */ |
169 | close (pfd[1]); | 160 | close(pfd[1]); |
170 | close (pfderr[1]); | 161 | close(pfderr[1]); |
171 | 162 | ||
172 | /* tag our file's entry in the pid-list and return it */ | 163 | /* tag our file's entry in the pid-list and return it */ |
173 | _cmd_pids[pfd[0]] = pid; | 164 | _cmd_pids[pfd[0]] = pid; |
@@ -175,9 +166,7 @@ _cmd_open (char *const *argv, int *pfd, int *pfderr) | |||
175 | return pfd[0]; | 166 | return pfd[0]; |
176 | } | 167 | } |
177 | 168 | ||
178 | static int | 169 | static int _cmd_close(int fd) { |
179 | _cmd_close (int fd) | ||
180 | { | ||
181 | int status; | 170 | int status; |
182 | pid_t pid; | 171 | pid_t pid; |
183 | 172 | ||
@@ -187,40 +176,37 @@ _cmd_close (int fd) | |||
187 | return -1; | 176 | return -1; |
188 | 177 | ||
189 | _cmd_pids[fd] = 0; | 178 | _cmd_pids[fd] = 0; |
190 | if (close (fd) == -1) | 179 | if (close(fd) == -1) |
191 | return -1; | 180 | return -1; |
192 | 181 | ||
193 | /* EINTR is ok (sort of), everything else is bad */ | 182 | /* EINTR is ok (sort of), everything else is bad */ |
194 | while (waitpid (pid, &status, 0) < 0) | 183 | while (waitpid(pid, &status, 0) < 0) |
195 | if (errno != EINTR) | 184 | if (errno != EINTR) |
196 | return -1; | 185 | return -1; |
197 | 186 | ||
198 | /* return child's termination status */ | 187 | /* return child's termination status */ |
199 | return (WIFEXITED (status)) ? WEXITSTATUS (status) : -1; | 188 | return (WIFEXITED(status)) ? WEXITSTATUS(status) : -1; |
200 | } | 189 | } |
201 | 190 | ||
202 | 191 | static int _cmd_fetch_output(int fd, output *op, int flags) { | |
203 | static int | ||
204 | _cmd_fetch_output (int fd, output * op, int flags) | ||
205 | { | ||
206 | size_t len = 0, i = 0, lineno = 0; | 192 | size_t len = 0, i = 0, lineno = 0; |
207 | size_t rsf = 6, ary_size = 0; /* rsf = right shift factor, dec'ed uncond once */ | 193 | size_t rsf = 6, ary_size = 0; /* rsf = right shift factor, dec'ed uncond once */ |
208 | char *buf = NULL; | 194 | char *buf = NULL; |
209 | int ret; | 195 | int ret; |
210 | char tmpbuf[4096]; | 196 | char tmpbuf[4096]; |
211 | 197 | ||
212 | op->buf = NULL; | 198 | op->buf = NULL; |
213 | op->buflen = 0; | 199 | op->buflen = 0; |
214 | while ((ret = read (fd, tmpbuf, sizeof (tmpbuf))) > 0) { | 200 | while ((ret = read(fd, tmpbuf, sizeof(tmpbuf))) > 0) { |
215 | len = (size_t) ret; | 201 | len = (size_t)ret; |
216 | op->buf = realloc (op->buf, op->buflen + len + 1); | 202 | op->buf = realloc(op->buf, op->buflen + len + 1); |
217 | memcpy (op->buf + op->buflen, tmpbuf, len); | 203 | memcpy(op->buf + op->buflen, tmpbuf, len); |
218 | op->buflen += len; | 204 | op->buflen += len; |
219 | i++; | 205 | i++; |
220 | } | 206 | } |
221 | 207 | ||
222 | if (ret < 0) { | 208 | if (ret < 0) { |
223 | printf ("read() returned %d: %s\n", ret, strerror (errno)); | 209 | printf("read() returned %d: %s\n", ret, strerror(errno)); |
224 | return ret; | 210 | return ret; |
225 | } | 211 | } |
226 | 212 | ||
@@ -231,10 +217,9 @@ _cmd_fetch_output (int fd, output * op, int flags) | |||
231 | 217 | ||
232 | /* and some may want both */ | 218 | /* and some may want both */ |
233 | if (flags & CMD_NO_ASSOC) { | 219 | if (flags & CMD_NO_ASSOC) { |
234 | buf = malloc (op->buflen); | 220 | buf = malloc(op->buflen); |
235 | memcpy (buf, op->buf, op->buflen); | 221 | memcpy(buf, op->buf, op->buflen); |
236 | } | 222 | } else |
237 | else | ||
238 | buf = op->buf; | 223 | buf = op->buf; |
239 | 224 | ||
240 | op->line = NULL; | 225 | op->line = NULL; |
@@ -248,8 +233,8 @@ _cmd_fetch_output (int fd, output * op, int flags) | |||
248 | ary_size = op->buflen >> --rsf; | 233 | ary_size = op->buflen >> --rsf; |
249 | } while (!ary_size); | 234 | } while (!ary_size); |
250 | 235 | ||
251 | op->line = realloc (op->line, ary_size * sizeof (char *)); | 236 | op->line = realloc(op->line, ary_size * sizeof(char *)); |
252 | op->lens = realloc (op->lens, ary_size * sizeof (size_t)); | 237 | op->lens = realloc(op->lens, ary_size * sizeof(size_t)); |
253 | } | 238 | } |
254 | 239 | ||
255 | /* set the pointer to the string */ | 240 | /* set the pointer to the string */ |
@@ -261,7 +246,7 @@ _cmd_fetch_output (int fd, output * op, int flags) | |||
261 | buf[i] = '\0'; | 246 | buf[i] = '\0'; |
262 | 247 | ||
263 | /* calculate the string length using pointer difference */ | 248 | /* calculate the string length using pointer difference */ |
264 | op->lens[lineno] = (size_t) & buf[i] - (size_t) op->line[lineno]; | 249 | op->lens[lineno] = (size_t)&buf[i] - (size_t)op->line[lineno]; |
265 | 250 | ||
266 | lineno++; | 251 | lineno++; |
267 | i++; | 252 | i++; |
@@ -270,10 +255,7 @@ _cmd_fetch_output (int fd, output * op, int flags) | |||
270 | return lineno; | 255 | return lineno; |
271 | } | 256 | } |
272 | 257 | ||
273 | 258 | int cmd_run(const char *cmdstring, output *out, output *err, int flags) { | |
274 | int | ||
275 | cmd_run (const char *cmdstring, output * out, output * err, int flags) | ||
276 | { | ||
277 | int i = 0, argc; | 259 | int i = 0, argc; |
278 | size_t cmdlen; | 260 | size_t cmdlen; |
279 | char **argv = NULL; | 261 | char **argv = NULL; |
@@ -285,120 +267,114 @@ cmd_run (const char *cmdstring, output * out, output * err, int flags) | |||
285 | 267 | ||
286 | /* initialize the structs */ | 268 | /* initialize the structs */ |
287 | if (out) | 269 | if (out) |
288 | memset (out, 0, sizeof (output)); | 270 | memset(out, 0, sizeof(output)); |
289 | if (err) | 271 | if (err) |
290 | memset (err, 0, sizeof (output)); | 272 | memset(err, 0, sizeof(output)); |
291 | 273 | ||
292 | /* make copy of command string so strtok() doesn't silently modify it */ | 274 | /* make copy of command string so strtok() doesn't silently modify it */ |
293 | /* (the calling program may want to access it later) */ | 275 | /* (the calling program may want to access it later) */ |
294 | cmdlen = strlen (cmdstring); | 276 | cmdlen = strlen(cmdstring); |
295 | if ((cmd = malloc (cmdlen + 1)) == NULL) | 277 | if ((cmd = malloc(cmdlen + 1)) == NULL) |
296 | return -1; | 278 | return -1; |
297 | memcpy (cmd, cmdstring, cmdlen); | 279 | memcpy(cmd, cmdstring, cmdlen); |
298 | cmd[cmdlen] = '\0'; | 280 | cmd[cmdlen] = '\0'; |
299 | 281 | ||
300 | /* This is not a shell, so we don't handle "???" */ | 282 | /* This is not a shell, so we don't handle "???" */ |
301 | if (strstr (cmdstring, "\"")) return -1; | 283 | if (strstr(cmdstring, "\"")) |
284 | return -1; | ||
302 | 285 | ||
303 | /* allow single quotes, but only if non-whitesapce doesn't occur on both sides */ | 286 | /* allow single quotes, but only if non-whitesapce doesn't occur on both sides */ |
304 | if (strstr (cmdstring, " ' ") || strstr (cmdstring, "'''")) | 287 | if (strstr(cmdstring, " ' ") || strstr(cmdstring, "'''")) |
305 | return -1; | 288 | return -1; |
306 | 289 | ||
307 | /* each arg must be whitespace-separated, so args can be a maximum | 290 | /* each arg must be whitespace-separated, so args can be a maximum |
308 | * of (len / 2) + 1. We add 1 extra to the mix for NULL termination */ | 291 | * of (len / 2) + 1. We add 1 extra to the mix for NULL termination */ |
309 | argc = (cmdlen >> 1) + 2; | 292 | argc = (cmdlen >> 1) + 2; |
310 | argv = calloc (sizeof (char *), argc); | 293 | argv = calloc((size_t)argc, sizeof(char *)); |
311 | 294 | ||
312 | if (argv == NULL) { | 295 | if (argv == NULL) { |
313 | printf ("%s\n", _("Could not malloc argv array in popen()")); | 296 | printf("%s\n", _("Could not malloc argv array in popen()")); |
314 | return -1; | 297 | return -1; |
315 | } | 298 | } |
316 | 299 | ||
317 | /* get command arguments (stupidly, but fairly quickly) */ | 300 | /* get command arguments (stupidly, but fairly quickly) */ |
318 | while (cmd) { | 301 | while (cmd) { |
319 | str = cmd; | 302 | str = cmd; |
320 | str += strspn (str, " \t\r\n"); /* trim any leading whitespace */ | 303 | str += strspn(str, " \t\r\n"); /* trim any leading whitespace */ |
321 | 304 | ||
322 | if (strstr (str, "'") == str) { /* handle SIMPLE quoted strings */ | 305 | if (strstr(str, "'") == str) { /* handle SIMPLE quoted strings */ |
323 | str++; | 306 | str++; |
324 | if (!strstr (str, "'")) | 307 | if (!strstr(str, "'")) |
325 | return -1; /* balanced? */ | 308 | return -1; /* balanced? */ |
326 | cmd = 1 + strstr (str, "'"); | 309 | cmd = 1 + strstr(str, "'"); |
327 | str[strcspn (str, "'")] = 0; | 310 | str[strcspn(str, "'")] = 0; |
328 | } | 311 | } else { |
329 | else { | 312 | if (strpbrk(str, " \t\r\n")) { |
330 | if (strpbrk (str, " \t\r\n")) { | 313 | cmd = 1 + strpbrk(str, " \t\r\n"); |
331 | cmd = 1 + strpbrk (str, " \t\r\n"); | 314 | str[strcspn(str, " \t\r\n")] = 0; |
332 | str[strcspn (str, " \t\r\n")] = 0; | 315 | } else { |
333 | } | ||
334 | else { | ||
335 | cmd = NULL; | 316 | cmd = NULL; |
336 | } | 317 | } |
337 | } | 318 | } |
338 | 319 | ||
339 | if (cmd && strlen (cmd) == strspn (cmd, " \t\r\n")) | 320 | if (cmd && strlen(cmd) == strspn(cmd, " \t\r\n")) |
340 | cmd = NULL; | 321 | cmd = NULL; |
341 | 322 | ||
342 | argv[i++] = str; | 323 | argv[i++] = str; |
343 | } | 324 | } |
344 | 325 | ||
345 | return cmd_run_array (argv, out, err, flags); | 326 | return cmd_run_array(argv, out, err, flags); |
346 | } | 327 | } |
347 | 328 | ||
348 | int | 329 | int cmd_run_array(char *const *argv, output *out, output *err, int flags) { |
349 | cmd_run_array (char *const *argv, output * out, output * err, int flags) | ||
350 | { | ||
351 | int fd, pfd_out[2], pfd_err[2]; | 330 | int fd, pfd_out[2], pfd_err[2]; |
352 | 331 | ||
353 | /* initialize the structs */ | 332 | /* initialize the structs */ |
354 | if (out) | 333 | if (out) |
355 | memset (out, 0, sizeof (output)); | 334 | memset(out, 0, sizeof(output)); |
356 | if (err) | 335 | if (err) |
357 | memset (err, 0, sizeof (output)); | 336 | memset(err, 0, sizeof(output)); |
358 | 337 | ||
359 | if ((fd = _cmd_open (argv, pfd_out, pfd_err)) == -1) | 338 | if ((fd = _cmd_open(argv, pfd_out, pfd_err)) == -1) |
360 | die (STATE_UNKNOWN, _("Could not open pipe: %s\n"), argv[0]); | 339 | die(STATE_UNKNOWN, _("Could not open pipe: %s\n"), argv[0]); |
361 | 340 | ||
362 | if (out) | 341 | if (out) |
363 | out->lines = _cmd_fetch_output (pfd_out[0], out, flags); | 342 | out->lines = _cmd_fetch_output(pfd_out[0], out, flags); |
364 | if (err) | 343 | if (err) |
365 | err->lines = _cmd_fetch_output (pfd_err[0], err, flags); | 344 | err->lines = _cmd_fetch_output(pfd_err[0], err, flags); |
366 | 345 | ||
367 | return _cmd_close (fd); | 346 | return _cmd_close(fd); |
368 | } | 347 | } |
369 | 348 | ||
370 | int | 349 | int cmd_file_read(char *filename, output *out, int flags) { |
371 | cmd_file_read ( char *filename, output *out, int flags) | ||
372 | { | ||
373 | int fd; | 350 | int fd; |
374 | if(out) | 351 | if (out) |
375 | memset (out, 0, sizeof(output)); | 352 | memset(out, 0, sizeof(output)); |
376 | 353 | ||
377 | if ((fd = open(filename, O_RDONLY)) == -1) { | 354 | if ((fd = open(filename, O_RDONLY)) == -1) { |
378 | die( STATE_UNKNOWN, _("Error opening %s: %s"), filename, strerror(errno) ); | 355 | die(STATE_UNKNOWN, _("Error opening %s: %s"), filename, strerror(errno)); |
379 | } | 356 | } |
380 | 357 | ||
381 | if(out) | 358 | if (out) |
382 | out->lines = _cmd_fetch_output (fd, out, flags); | 359 | out->lines = _cmd_fetch_output(fd, out, flags); |
383 | 360 | ||
384 | if (close(fd) == -1) | 361 | if (close(fd) == -1) |
385 | die( STATE_UNKNOWN, _("Error closing %s: %s"), filename, strerror(errno) ); | 362 | die(STATE_UNKNOWN, _("Error closing %s: %s"), filename, strerror(errno)); |
386 | 363 | ||
387 | return 0; | 364 | return 0; |
388 | } | 365 | } |
389 | 366 | ||
390 | void | 367 | void timeout_alarm_handler(int signo) { |
391 | timeout_alarm_handler (int signo) | ||
392 | { | ||
393 | if (signo == SIGALRM) { | 368 | if (signo == SIGALRM) { |
394 | printf (_("%s - Plugin timed out after %d seconds\n"), | 369 | printf(_("%s - Plugin timed out after %d seconds\n"), state_text(timeout_state), timeout_interval); |
395 | state_text(timeout_state), timeout_interval); | ||
396 | 370 | ||
397 | long maxfd = mp_open_max(); | 371 | long maxfd = mp_open_max(); |
398 | if(_cmd_pids) for(long int i = 0; i < maxfd; i++) { | 372 | if (_cmd_pids) |
399 | if(_cmd_pids[i] != 0) kill(_cmd_pids[i], SIGKILL); | 373 | for (long int i = 0; i < maxfd; i++) { |
400 | } | 374 | if (_cmd_pids[i] != 0) |
375 | kill(_cmd_pids[i], SIGKILL); | ||
376 | } | ||
401 | 377 | ||
402 | exit (timeout_state); | 378 | exit(timeout_state); |
403 | } | 379 | } |
404 | } | 380 | } |
diff --git a/lib/utils_cmd.h b/lib/utils_cmd.h index 061f5d4..d00069c 100644 --- a/lib/utils_cmd.h +++ b/lib/utils_cmd.h | |||
@@ -4,12 +4,10 @@ | |||
4 | /* | 4 | /* |
5 | * Header file for Monitoring Plugins utils_cmd.c | 5 | * Header file for Monitoring Plugins utils_cmd.c |
6 | * | 6 | * |
7 | * | ||
8 | */ | 7 | */ |
9 | 8 | ||
10 | /** types **/ | 9 | /** types **/ |
11 | struct output | 10 | struct output { |
12 | { | ||
13 | char *buf; /* output buffer */ | 11 | char *buf; /* output buffer */ |
14 | size_t buflen; /* output buffer content length */ | 12 | size_t buflen; /* output buffer content length */ |
15 | char **line; /* array of lines (points to buf) */ | 13 | char **line; /* array of lines (points to buf) */ |
@@ -20,20 +18,18 @@ struct output | |||
20 | typedef struct output output; | 18 | typedef struct output output; |
21 | 19 | ||
22 | /** prototypes **/ | 20 | /** prototypes **/ |
23 | int cmd_run (const char *, output *, output *, int); | 21 | int cmd_run(const char *, output *, output *, int); |
24 | int cmd_run_array (char *const *, output *, output *, int); | 22 | int cmd_run_array(char *const *, output *, output *, int); |
25 | int cmd_file_read (char *, output *, int); | 23 | int cmd_file_read(char *, output *, int); |
26 | 24 | ||
27 | /* only multi-threaded plugins need to bother with this */ | 25 | /* only multi-threaded plugins need to bother with this */ |
28 | void cmd_init (void); | 26 | void cmd_init(void); |
29 | #define CMD_INIT cmd_init() | 27 | #define CMD_INIT cmd_init() |
30 | 28 | ||
31 | /* possible flags for cmd_run()'s fourth argument */ | 29 | /* possible flags for cmd_run()'s fourth argument */ |
32 | #define CMD_NO_ARRAYS 0x01 /* don't populate arrays at all */ | 30 | #define CMD_NO_ARRAYS 0x01 /* don't populate arrays at all */ |
33 | #define CMD_NO_ASSOC 0x02 /* output.line won't point to buf */ | 31 | #define CMD_NO_ASSOC 0x02 /* output.line won't point to buf */ |
34 | |||
35 | |||
36 | void timeout_alarm_handler (int); | ||
37 | 32 | ||
33 | void timeout_alarm_handler(int); | ||
38 | 34 | ||
39 | #endif /* _UTILS_CMD_ */ | 35 | #endif /* _UTILS_CMD_ */ |
diff --git a/lib/utils_disk.c b/lib/utils_disk.c index 483be06..2b761f5 100644 --- a/lib/utils_disk.c +++ b/lib/utils_disk.c | |||
@@ -1,44 +1,42 @@ | |||
1 | /***************************************************************************** | 1 | /***************************************************************************** |
2 | * | 2 | * |
3 | * Library for check_disk | 3 | * Library for check_disk |
4 | * | 4 | * |
5 | * License: GPL | 5 | * License: GPL |
6 | * Copyright (c) 1999-2007 Monitoring Plugins Development Team | 6 | * Copyright (c) 1999-2024 Monitoring Plugins Development Team |
7 | * | 7 | * |
8 | * Description: | 8 | * Description: |
9 | * | 9 | * |
10 | * This file contains utilities for check_disk. These are tested by libtap | 10 | * This file contains utilities for check_disk. These are tested by libtap |
11 | * | 11 | * |
12 | * | 12 | * |
13 | * This program is free software: you can redistribute it and/or modify | 13 | * This program is free software: you can redistribute it and/or modify |
14 | * it under the terms of the GNU General Public License as published by | 14 | * it under the terms of the GNU General Public License as published by |
15 | * the Free Software Foundation, either version 3 of the License, or | 15 | * the Free Software Foundation, either version 3 of the License, or |
16 | * (at your option) any later version. | 16 | * (at your option) any later version. |
17 | * | 17 | * |
18 | * This program is distributed in the hope that it will be useful, | 18 | * This program is distributed in the hope that it will be useful, |
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
21 | * GNU General Public License for more details. | 21 | * GNU General Public License for more details. |
22 | * | 22 | * |
23 | * You should have received a copy of the GNU General Public License | 23 | * You should have received a copy of the GNU General Public License |
24 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 24 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
25 | * | 25 | * |
26 | * | 26 | * |
27 | *****************************************************************************/ | 27 | *****************************************************************************/ |
28 | 28 | ||
29 | #include "common.h" | 29 | #include "common.h" |
30 | #include "utils_disk.h" | 30 | #include "utils_disk.h" |
31 | #include "gl/fsusage.h" | 31 | #include "gl/fsusage.h" |
32 | #include <string.h> | 32 | #include <string.h> |
33 | 33 | ||
34 | void | 34 | void np_add_name(struct name_list **list, const char *name) { |
35 | np_add_name (struct name_list **list, const char *name) | 35 | struct name_list *new_entry; |
36 | { | 36 | new_entry = (struct name_list *)malloc(sizeof *new_entry); |
37 | struct name_list *new_entry; | 37 | new_entry->name = (char *)name; |
38 | new_entry = (struct name_list *) malloc (sizeof *new_entry); | 38 | new_entry->next = *list; |
39 | new_entry->name = (char *) name; | 39 | *list = new_entry; |
40 | new_entry->next = *list; | ||
41 | *list = new_entry; | ||
42 | } | 40 | } |
43 | 41 | ||
44 | /* @brief Initialises a new regex at the begin of list via regcomp(3) | 42 | /* @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) | |||
50 | * @param regex the string containing the regex which should be inserted into the list | 48 | * @param regex the string containing the regex which should be inserted into the list |
51 | * @param clags the cflags parameter for regcomp(3) | 49 | * @param clags the cflags parameter for regcomp(3) |
52 | */ | 50 | */ |
53 | int | 51 | int np_add_regex(struct regex_list **list, const char *regex, int cflags) { |
54 | np_add_regex (struct regex_list **list, const char *regex, int cflags) | 52 | struct regex_list *new_entry = (struct regex_list *)malloc(sizeof *new_entry); |
55 | { | ||
56 | struct regex_list *new_entry = (struct regex_list *) malloc (sizeof *new_entry); | ||
57 | 53 | ||
58 | if (new_entry == NULL) { | 54 | if (new_entry == NULL) { |
59 | die(STATE_UNKNOWN, _("Cannot allocate memory: %s"), | 55 | die(STATE_UNKNOWN, _("Cannot allocate memory: %s"), strerror(errno)); |
60 | strerror(errno)); | ||
61 | } | 56 | } |
62 | 57 | ||
63 | int regcomp_result = regcomp(&new_entry->regex, regex, cflags); | 58 | int regcomp_result = regcomp(&new_entry->regex, regex, cflags); |
64 | 59 | ||
65 | if (!regcomp_result) { | 60 | if (!regcomp_result) { |
66 | // regcomp succeeded | 61 | // regcomp succeeded |
@@ -74,197 +69,187 @@ np_add_regex (struct regex_list **list, const char *regex, int cflags) | |||
74 | 69 | ||
75 | return regcomp_result; | 70 | return regcomp_result; |
76 | } | 71 | } |
77 | |||
78 | } | 72 | } |
79 | 73 | ||
80 | /* Initialises a new parameter at the end of list */ | 74 | /* Initialises a new parameter at the end of list */ |
81 | struct parameter_list * | 75 | struct parameter_list *np_add_parameter(struct parameter_list **list, const char *name) { |
82 | np_add_parameter(struct parameter_list **list, const char *name) | 76 | struct parameter_list *current = *list; |
83 | { | 77 | struct parameter_list *new_path; |
84 | struct parameter_list *current = *list; | 78 | new_path = (struct parameter_list *)malloc(sizeof *new_path); |
85 | struct parameter_list *new_path; | 79 | new_path->name = (char *)malloc(strlen(name) + 1); |
86 | new_path = (struct parameter_list *) malloc (sizeof *new_path); | 80 | new_path->best_match = NULL; |
87 | new_path->name = (char *) malloc(strlen(name) + 1); | 81 | new_path->name_next = NULL; |
88 | new_path->best_match = NULL; | 82 | new_path->name_prev = NULL; |
89 | new_path->name_next = NULL; | 83 | new_path->freespace_bytes = NULL; |
90 | new_path->name_prev = NULL; | 84 | new_path->freespace_units = NULL; |
91 | new_path->freespace_bytes = NULL; | 85 | new_path->freespace_percent = NULL; |
92 | new_path->freespace_units = NULL; | 86 | new_path->usedspace_bytes = NULL; |
93 | new_path->freespace_percent = NULL; | 87 | new_path->usedspace_units = NULL; |
94 | new_path->usedspace_bytes = NULL; | 88 | new_path->usedspace_percent = NULL; |
95 | new_path->usedspace_units = NULL; | 89 | new_path->usedinodes_percent = NULL; |
96 | new_path->usedspace_percent = NULL; | 90 | new_path->freeinodes_percent = NULL; |
97 | new_path->usedinodes_percent = NULL; | 91 | new_path->group = NULL; |
98 | new_path->freeinodes_percent = NULL; | 92 | new_path->dfree_pct = -1; |
99 | new_path->group = NULL; | 93 | new_path->dused_pct = -1; |
100 | new_path->dfree_pct = -1; | 94 | new_path->total = 0; |
101 | new_path->dused_pct = -1; | 95 | new_path->available = 0; |
102 | new_path->total = 0; | 96 | new_path->available_to_root = 0; |
103 | new_path->available = 0; | 97 | new_path->used = 0; |
104 | new_path->available_to_root = 0; | 98 | new_path->dused_units = 0; |
105 | new_path->used = 0; | 99 | new_path->dfree_units = 0; |
106 | new_path->dused_units = 0; | 100 | new_path->dtotal_units = 0; |
107 | new_path->dfree_units = 0; | 101 | new_path->inodes_total = 0; |
108 | new_path->dtotal_units = 0; | 102 | new_path->inodes_free = 0; |
109 | new_path->inodes_total = 0; | 103 | new_path->inodes_free_to_root = 0; |
110 | new_path->inodes_free = 0; | 104 | new_path->inodes_used = 0; |
111 | new_path->inodes_free_to_root = 0; | 105 | new_path->dused_inodes_percent = 0; |
112 | new_path->inodes_used = 0; | 106 | new_path->dfree_inodes_percent = 0; |
113 | new_path->dused_inodes_percent = 0; | 107 | |
114 | new_path->dfree_inodes_percent = 0; | 108 | strcpy(new_path->name, name); |
115 | 109 | ||
116 | strcpy(new_path->name, name); | 110 | if (current == NULL) { |
117 | 111 | *list = new_path; | |
118 | if (current == NULL) { | 112 | new_path->name_prev = NULL; |
119 | *list = new_path; | 113 | } else { |
120 | new_path->name_prev = NULL; | 114 | while (current->name_next) { |
121 | } else { | 115 | current = current->name_next; |
122 | while (current->name_next) { | 116 | } |
123 | current = current->name_next; | 117 | current->name_next = new_path; |
124 | } | 118 | new_path->name_prev = current; |
125 | current->name_next = new_path; | 119 | } |
126 | new_path->name_prev = current; | 120 | return new_path; |
127 | } | ||
128 | return new_path; | ||
129 | } | 121 | } |
130 | 122 | ||
131 | /* Delete a given parameter from list and return pointer to next element*/ | 123 | /* Delete a given parameter from list and return pointer to next element*/ |
132 | struct parameter_list * | 124 | struct parameter_list *np_del_parameter(struct parameter_list *item, struct parameter_list *prev) { |
133 | np_del_parameter(struct parameter_list *item, struct parameter_list *prev) | 125 | if (item == NULL) { |
134 | { | 126 | return NULL; |
135 | if (item == NULL) { | 127 | } |
136 | return NULL; | 128 | struct parameter_list *next; |
137 | } | 129 | |
138 | struct parameter_list *next; | 130 | if (item->name_next) |
139 | 131 | next = item->name_next; | |
140 | if (item->name_next) | 132 | else |
141 | next = item->name_next; | 133 | next = NULL; |
142 | else | 134 | |
143 | next = NULL; | 135 | if (next) |
144 | 136 | next->name_prev = prev; | |
145 | if (next) | ||
146 | next->name_prev = prev; | ||
147 | |||
148 | if (prev) | ||
149 | prev->name_next = next; | ||
150 | |||
151 | if (item->name) { | ||
152 | free(item->name); | ||
153 | } | ||
154 | free(item); | ||
155 | |||
156 | return next; | ||
157 | } | ||
158 | 137 | ||
138 | if (prev) | ||
139 | prev->name_next = next; | ||
140 | |||
141 | if (item->name) { | ||
142 | free(item->name); | ||
143 | } | ||
144 | free(item); | ||
145 | |||
146 | return next; | ||
147 | } | ||
159 | 148 | ||
160 | /* returns a pointer to the struct found in the list */ | 149 | /* returns a pointer to the struct found in the list */ |
161 | struct parameter_list * | 150 | struct parameter_list *np_find_parameter(struct parameter_list *list, const char *name) { |
162 | np_find_parameter(struct parameter_list *list, const char *name) | 151 | struct parameter_list *temp_list; |
163 | { | 152 | for (temp_list = list; temp_list; temp_list = temp_list->name_next) { |
164 | struct parameter_list *temp_list; | 153 | if (!strcmp(temp_list->name, name)) |
165 | for (temp_list = list; temp_list; temp_list = temp_list->name_next) { | 154 | return temp_list; |
166 | if (! strcmp(temp_list->name, name)) | 155 | } |
167 | return temp_list; | 156 | |
168 | } | 157 | return NULL; |
169 | |||
170 | return NULL; | ||
171 | } | 158 | } |
172 | 159 | ||
173 | void np_set_best_match(struct parameter_list *desired, struct mount_entry *mount_list, bool exact) { | 160 | void np_set_best_match(struct parameter_list *desired, struct mount_entry *mount_list, bool exact) { |
174 | struct parameter_list *d; | 161 | struct parameter_list *d; |
175 | for (d = desired; d; d= d->name_next) { | 162 | for (d = desired; d; d = d->name_next) { |
176 | if (! d->best_match) { | 163 | if (!d->best_match) { |
177 | struct mount_entry *me; | 164 | struct mount_entry *me; |
178 | size_t name_len = strlen(d->name); | 165 | size_t name_len = strlen(d->name); |
179 | size_t best_match_len = 0; | 166 | size_t best_match_len = 0; |
180 | struct mount_entry *best_match = NULL; | 167 | struct mount_entry *best_match = NULL; |
181 | struct fs_usage fsp; | 168 | struct fs_usage fsp; |
182 | 169 | ||
183 | /* set best match if path name exactly matches a mounted device name */ | 170 | /* set best match if path name exactly matches a mounted device name */ |
184 | for (me = mount_list; me; me = me->me_next) { | 171 | for (me = mount_list; me; me = me->me_next) { |
185 | if (strcmp(me->me_devname, d->name)==0) { | 172 | if (strcmp(me->me_devname, d->name) == 0) { |
186 | if (get_fs_usage(me->me_mountdir, me->me_devname, &fsp) >= 0) { | 173 | if (get_fs_usage(me->me_mountdir, me->me_devname, &fsp) >= 0) { |
187 | best_match = me; | 174 | best_match = me; |
188 | } | 175 | } |
189 | } | 176 | } |
190 | } | 177 | } |
191 | 178 | ||
192 | /* set best match by directory name if no match was found by devname */ | 179 | /* set best match by directory name if no match was found by devname */ |
193 | if (! best_match) { | 180 | if (!best_match) { |
194 | for (me = mount_list; me; me = me->me_next) { | 181 | for (me = mount_list; me; me = me->me_next) { |
195 | size_t len = strlen (me->me_mountdir); | 182 | size_t len = strlen(me->me_mountdir); |
196 | if ((!exact && (best_match_len <= len && len <= name_len && | 183 | if ((!exact && |
197 | (len == 1 || strncmp (me->me_mountdir, d->name, len) == 0))) | 184 | (best_match_len <= len && len <= name_len && (len == 1 || strncmp(me->me_mountdir, d->name, len) == 0))) || |
198 | || (exact && strcmp(me->me_mountdir, d->name)==0)) | 185 | (exact && strcmp(me->me_mountdir, d->name) == 0)) { |
199 | { | 186 | if (get_fs_usage(me->me_mountdir, me->me_devname, &fsp) >= 0) { |
200 | if (get_fs_usage(me->me_mountdir, me->me_devname, &fsp) >= 0) { | 187 | best_match = me; |
201 | best_match = me; | 188 | best_match_len = len; |
202 | best_match_len = len; | 189 | } |
203 | } | 190 | } |
204 | } | 191 | } |
205 | } | 192 | } |
206 | } | 193 | |
207 | 194 | if (best_match) { | |
208 | if (best_match) { | 195 | d->best_match = best_match; |
209 | d->best_match = best_match; | 196 | } else { |
210 | } else { | 197 | d->best_match = NULL; /* Not sure why this is needed as it should be null on initialisation */ |
211 | d->best_match = NULL; /* Not sure why this is needed as it should be null on initialisation */ | 198 | } |
212 | } | 199 | } |
213 | } | 200 | } |
214 | } | ||
215 | } | 201 | } |
216 | 202 | ||
217 | /* Returns true if name is in list */ | 203 | /* Returns true if name is in list */ |
218 | bool np_find_name (struct name_list *list, const char *name) { | 204 | bool np_find_name(struct name_list *list, const char *name) { |
219 | const struct name_list *n; | 205 | const struct name_list *n; |
220 | 206 | ||
221 | if (list == NULL || name == NULL) { | 207 | if (list == NULL || name == NULL) { |
222 | return false; | 208 | return false; |
223 | } | 209 | } |
224 | for (n = list; n; n = n->next) { | 210 | for (n = list; n; n = n->next) { |
225 | if (!strcmp(name, n->name)) { | 211 | if (!strcmp(name, n->name)) { |
226 | return true; | 212 | return true; |
227 | } | 213 | } |
228 | } | 214 | } |
229 | return false; | 215 | return false; |
230 | } | 216 | } |
231 | 217 | ||
232 | /* Returns true if name is in list */ | 218 | /* Returns true if name is in list */ |
233 | bool np_find_regmatch (struct regex_list *list, const char *name) { | 219 | bool np_find_regmatch(struct regex_list *list, const char *name) { |
234 | int len; | 220 | int len; |
235 | regmatch_t m; | 221 | regmatch_t m; |
236 | 222 | ||
237 | if (name == NULL) { | 223 | if (name == NULL) { |
238 | return false; | 224 | return false; |
239 | } | 225 | } |
240 | 226 | ||
241 | len = strlen(name); | 227 | len = strlen(name); |
242 | 228 | ||
243 | for (; list; list = list->next) { | 229 | for (; list; list = list->next) { |
244 | /* Emulate a full match as if surrounded with ^( )$ | 230 | /* Emulate a full match as if surrounded with ^( )$ |
245 | by checking whether the match spans the whole name */ | 231 | by checking whether the match spans the whole name */ |
246 | if (!regexec(&list->regex, name, 1, &m, 0) && m.rm_so == 0 && m.rm_eo == len) { | 232 | if (!regexec(&list->regex, name, 1, &m, 0) && m.rm_so == 0 && m.rm_eo == len) { |
247 | return true; | 233 | return true; |
248 | } | 234 | } |
249 | } | 235 | } |
250 | 236 | ||
251 | return false; | 237 | return false; |
252 | } | 238 | } |
253 | 239 | ||
254 | bool np_seen_name(struct name_list *list, const char *name) { | 240 | bool np_seen_name(struct name_list *list, const char *name) { |
255 | const struct name_list *s; | 241 | const struct name_list *s; |
256 | for (s = list; s; s=s->next) { | 242 | for (s = list; s; s = s->next) { |
257 | if (!strcmp(s->name, name)) { | 243 | if (!strcmp(s->name, name)) { |
258 | return true; | 244 | return true; |
259 | } | 245 | } |
260 | } | 246 | } |
261 | return false; | 247 | return false; |
262 | } | 248 | } |
263 | 249 | ||
264 | bool np_regex_match_mount_entry (struct mount_entry* me, regex_t* re) { | 250 | bool np_regex_match_mount_entry(struct mount_entry *me, regex_t *re) { |
265 | if (regexec(re, me->me_devname, (size_t) 0, NULL, 0) == 0 || | 251 | if (regexec(re, me->me_devname, (size_t)0, NULL, 0) == 0 || regexec(re, me->me_mountdir, (size_t)0, NULL, 0) == 0) { |
266 | regexec(re, me->me_mountdir, (size_t) 0, NULL, 0) == 0 ) { | 252 | return true; |
267 | return true; | 253 | } |
268 | } | ||
269 | return false; | 254 | return false; |
270 | } | 255 | } |
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 @@ | |||
4 | #include "utils_base.h" | 4 | #include "utils_base.h" |
5 | #include "regex.h" | 5 | #include "regex.h" |
6 | 6 | ||
7 | struct name_list | 7 | struct name_list { |
8 | { | 8 | char *name; |
9 | char *name; | 9 | struct name_list *next; |
10 | struct name_list *next; | ||
11 | }; | 10 | }; |
12 | 11 | ||
13 | struct regex_list | 12 | struct regex_list { |
14 | { | 13 | regex_t regex; |
15 | regex_t regex; | 14 | struct regex_list *next; |
16 | struct regex_list *next; | ||
17 | }; | 15 | }; |
18 | 16 | ||
19 | struct parameter_list | 17 | struct parameter_list { |
20 | { | 18 | char *name; |
21 | char *name; | 19 | thresholds *freespace_bytes; |
22 | thresholds *freespace_bytes; | 20 | thresholds *freespace_units; |
23 | thresholds *freespace_units; | 21 | thresholds *freespace_percent; |
24 | thresholds *freespace_percent; | 22 | thresholds *usedspace_bytes; |
25 | thresholds *usedspace_bytes; | 23 | thresholds *usedspace_units; |
26 | thresholds *usedspace_units; | 24 | thresholds *usedspace_percent; |
27 | thresholds *usedspace_percent; | 25 | thresholds *usedinodes_percent; |
28 | thresholds *usedinodes_percent; | 26 | thresholds *freeinodes_percent; |
29 | thresholds *freeinodes_percent; | 27 | char *group; |
30 | char *group; | 28 | struct mount_entry *best_match; |
31 | struct mount_entry *best_match; | 29 | struct parameter_list *name_next; |
32 | struct parameter_list *name_next; | 30 | struct parameter_list *name_prev; |
33 | struct parameter_list *name_prev; | 31 | uintmax_t total, available, available_to_root, used, inodes_free, inodes_free_to_root, inodes_used, inodes_total; |
34 | uintmax_t total, available, available_to_root, used, | 32 | double dfree_pct, dused_pct; |
35 | inodes_free, inodes_free_to_root, inodes_used, inodes_total; | 33 | uint64_t dused_units, dfree_units, dtotal_units; |
36 | double dfree_pct, dused_pct; | 34 | double dused_inodes_percent, dfree_inodes_percent; |
37 | uint64_t dused_units, dfree_units, dtotal_units; | ||
38 | double dused_inodes_percent, dfree_inodes_percent; | ||
39 | }; | 35 | }; |
40 | 36 | ||
41 | void np_add_name (struct name_list **list, const char *name); | 37 | void np_add_name(struct name_list **list, const char *name); |
42 | bool np_find_name (struct name_list *list, const char *name); | 38 | bool np_find_name(struct name_list *list, const char *name); |
43 | bool np_seen_name (struct name_list *list, const char *name); | 39 | bool np_seen_name(struct name_list *list, const char *name); |
44 | int np_add_regex (struct regex_list **list, const char *regex, int cflags); | 40 | int np_add_regex(struct regex_list **list, const char *regex, int cflags); |
45 | bool np_find_regmatch (struct regex_list *list, const char *name); | 41 | bool np_find_regmatch(struct regex_list *list, const char *name); |
46 | struct parameter_list *np_add_parameter(struct parameter_list **list, const char *name); | 42 | struct parameter_list *np_add_parameter(struct parameter_list **list, const char *name); |
47 | struct parameter_list *np_find_parameter(struct parameter_list *list, const char *name); | 43 | struct parameter_list *np_find_parameter(struct parameter_list *list, const char *name); |
48 | struct parameter_list *np_del_parameter(struct parameter_list *item, struct parameter_list *prev); | 44 | struct parameter_list *np_del_parameter(struct parameter_list *item, struct parameter_list *prev); |
49 | 45 | ||
50 | int search_parameter_list (struct parameter_list *list, const char *name); | 46 | int search_parameter_list(struct parameter_list *list, const char *name); |
51 | void np_set_best_match(struct parameter_list *desired, struct mount_entry *mount_list, bool exact); | 47 | void np_set_best_match(struct parameter_list *desired, struct mount_entry *mount_list, bool exact); |
52 | bool np_regex_match_mount_entry (struct mount_entry* me, regex_t* re); | 48 | 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..daae1d5 100644 --- a/lib/utils_tcp.c +++ b/lib/utils_tcp.c | |||
@@ -1,51 +1,46 @@ | |||
1 | /***************************************************************************** | 1 | /***************************************************************************** |
2 | * | 2 | * |
3 | * Library for check_tcp | 3 | * Library for check_tcp |
4 | * | 4 | * |
5 | * License: GPL | 5 | * License: GPL |
6 | * Copyright (c) 1999-2013 Monitoring Plugins Development Team | 6 | * Copyright (c) 1999-2024 Monitoring Plugins Development Team |
7 | * | 7 | * |
8 | * Description: | 8 | * Description: |
9 | * | 9 | * |
10 | * This file contains utilities for check_tcp. These are tested by libtap | 10 | * This file contains utilities for check_tcp. These are tested by libtap |
11 | * | 11 | * |
12 | * | 12 | * |
13 | * This program is free software: you can redistribute it and/or modify | 13 | * This program is free software: you can redistribute it and/or modify |
14 | * it under the terms of the GNU General Public License as published by | 14 | * it under the terms of the GNU General Public License as published by |
15 | * the Free Software Foundation, either version 3 of the License, or | 15 | * the Free Software Foundation, either version 3 of the License, or |
16 | * (at your option) any later version. | 16 | * (at your option) any later version. |
17 | * | 17 | * |
18 | * This program is distributed in the hope that it will be useful, | 18 | * This program is distributed in the hope that it will be useful, |
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
21 | * GNU General Public License for more details. | 21 | * GNU General Public License for more details. |
22 | * | 22 | * |
23 | * You should have received a copy of the GNU General Public License | 23 | * You should have received a copy of the GNU General Public License |
24 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 24 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
25 | * | 25 | * |
26 | * | 26 | * |
27 | *****************************************************************************/ | 27 | *****************************************************************************/ |
28 | 28 | ||
29 | #include "common.h" | 29 | #include "common.h" |
30 | #include "utils_tcp.h" | 30 | #include "utils_tcp.h" |
31 | 31 | ||
32 | #define VERBOSE(message) \ | 32 | #define VERBOSE(message) \ |
33 | do { \ | 33 | do { \ |
34 | if (flags & NP_MATCH_VERBOSE) \ | 34 | if (flags & NP_MATCH_VERBOSE) \ |
35 | puts(message); \ | 35 | puts(message); \ |
36 | } while (0) | 36 | } while (0) |
37 | 37 | ||
38 | enum np_match_result | 38 | enum np_match_result np_expect_match(char *status, char **server_expect, int expect_count, int flags) { |
39 | np_expect_match(char *status, char **server_expect, int expect_count, int flags) | ||
40 | { | ||
41 | int i, match = 0, partial = 0; | 39 | int i, match = 0, partial = 0; |
42 | 40 | ||
43 | for (i = 0; i < expect_count; i++) { | 41 | for (i = 0; i < expect_count; i++) { |
44 | if (flags & NP_MATCH_VERBOSE) | 42 | if (flags & NP_MATCH_VERBOSE) |
45 | printf("looking for [%s] %s [%s]\n", server_expect[i], | 43 | printf("looking for [%s] %s [%s]\n", server_expect[i], (flags & NP_MATCH_EXACT) ? "in beginning of" : "anywhere in", status); |
46 | (flags & NP_MATCH_EXACT) ? | ||
47 | "in beginning of" : "anywhere in", | ||
48 | status); | ||
49 | 44 | ||
50 | if (flags & NP_MATCH_EXACT) { | 45 | if (flags & NP_MATCH_EXACT) { |
51 | if (strncmp(status, server_expect[i], strlen(server_expect[i])) == 0) { | 46 | 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) | |||
58 | continue; | 53 | continue; |
59 | } | 54 | } |
60 | } else if (strstr(status, server_expect[i]) != NULL) { | 55 | } else if (strstr(status, server_expect[i]) != NULL) { |
61 | VERBOSE("found it"); | 56 | VERBOSE("found it"); |
62 | match++; | 57 | match++; |
63 | continue; | 58 | continue; |
64 | } | 59 | } |
65 | VERBOSE("couldn't find it"); | 60 | VERBOSE("couldn't find it"); |
66 | } | 61 | } |
67 | 62 | ||
68 | if ((flags & NP_MATCH_ALL && match == expect_count) || | 63 | if ((flags & NP_MATCH_ALL && match == expect_count) || (!(flags & NP_MATCH_ALL) && match >= 1)) |
69 | (!(flags & NP_MATCH_ALL) && match >= 1)) | ||
70 | return NP_MATCH_SUCCESS; | 64 | return NP_MATCH_SUCCESS; |
71 | else if (partial > 0 || !(flags & NP_MATCH_EXACT)) | 65 | else if (partial > 0 || !(flags & NP_MATCH_EXACT)) |
72 | return NP_MATCH_RETRY; | 66 | return NP_MATCH_RETRY; |
diff --git a/lib/utils_tcp.h b/lib/utils_tcp.h index 0328a9c..d5999e9 100644 --- a/lib/utils_tcp.h +++ b/lib/utils_tcp.h | |||
@@ -1,8 +1,8 @@ | |||
1 | /* Header file for utils_tcp */ | 1 | /* Header file for utils_tcp */ |
2 | 2 | ||
3 | #define NP_MATCH_ALL 0x1 | 3 | #define NP_MATCH_ALL 0x1 |
4 | #define NP_MATCH_EXACT 0x2 | 4 | #define NP_MATCH_EXACT 0x2 |
5 | #define NP_MATCH_VERBOSE 0x4 | 5 | #define NP_MATCH_VERBOSE 0x4 |
6 | 6 | ||
7 | /* | 7 | /* |
8 | * The NP_MATCH_RETRY state indicates that matching might succeed if | 8 | * The NP_MATCH_RETRY state indicates that matching might succeed if |
@@ -16,7 +16,4 @@ enum np_match_result { | |||
16 | NP_MATCH_RETRY | 16 | NP_MATCH_RETRY |
17 | }; | 17 | }; |
18 | 18 | ||
19 | enum np_match_result np_expect_match(char *status, | 19 | enum np_match_result np_expect_match(char *status, char **server_expect, int server_expect_count, int flags); |
20 | char **server_expect, | ||
21 | int server_expect_count, | ||
22 | int flags); | ||