diff options
-rw-r--r-- | lib/Makefile.am | 4 | ||||
-rw-r--r-- | lib/base64.c | 50 | ||||
-rw-r--r-- | lib/base64.h | 4 | ||||
-rw-r--r-- | plugins/check_http.c | 45 | ||||
-rw-r--r-- | plugins/check_smtp.c | 42 |
5 files changed, 59 insertions, 86 deletions
diff --git a/lib/Makefile.am b/lib/Makefile.am index 9dd3a0c2..1b309846 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am | |||
@@ -5,8 +5,8 @@ SUBDIRS = tests | |||
5 | noinst_LIBRARIES = libnagiosplug.a | 5 | noinst_LIBRARIES = libnagiosplug.a |
6 | 6 | ||
7 | 7 | ||
8 | libnagiosplug_a_SOURCES = utils_base.c utils_disk.c utils_tcp.c utils_cmd.c | 8 | libnagiosplug_a_SOURCES = utils_base.c utils_disk.c utils_tcp.c utils_cmd.c base64.c |
9 | EXTRA_DIST = utils_base.h utils_disk.h utils_tcp.h utils_cmd.h | 9 | EXTRA_DIST = utils_base.h utils_disk.h utils_tcp.h utils_cmd.h base64.h |
10 | 10 | ||
11 | INCLUDES = -I$(srcdir) -I$(top_srcdir)/gl -I$(top_srcdir)/intl -I$(top_srcdir)/plugins | 11 | INCLUDES = -I$(srcdir) -I$(top_srcdir)/gl -I$(top_srcdir)/intl -I$(top_srcdir)/plugins |
12 | 12 | ||
diff --git a/lib/base64.c b/lib/base64.c new file mode 100644 index 00000000..1f1fcb8c --- /dev/null +++ b/lib/base64.c | |||
@@ -0,0 +1,50 @@ | |||
1 | /**************************************************************************** | ||
2 | * Function to encode in Base64 | ||
3 | * | ||
4 | * Written by Lauri Alanko | ||
5 | * | ||
6 | *****************************************************************************/ | ||
7 | |||
8 | #include "common.h" | ||
9 | #include "base64.h" | ||
10 | |||
11 | char * | ||
12 | base64 (const char *bin, size_t len) | ||
13 | { | ||
14 | |||
15 | char *buf = (char *) malloc ((len + 2) / 3 * 4 + 1); | ||
16 | size_t i = 0, j = 0; | ||
17 | |||
18 | char BASE64_END = '='; | ||
19 | char base64_table[64]; | ||
20 | strncpy (base64_table, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", 64); | ||
21 | |||
22 | while (j < len - 2) { | ||
23 | buf[i++] = base64_table[bin[j] >> 2]; | ||
24 | buf[i++] = base64_table[((bin[j] & 3) << 4) | (bin[j + 1] >> 4)]; | ||
25 | buf[i++] = base64_table[((bin[j + 1] & 15) << 2) | (bin[j + 2] >> 6)]; | ||
26 | buf[i++] = base64_table[bin[j + 2] & 63]; | ||
27 | j += 3; | ||
28 | } | ||
29 | |||
30 | switch (len - j) { | ||
31 | case 1: | ||
32 | buf[i++] = base64_table[bin[j] >> 2]; | ||
33 | buf[i++] = base64_table[(bin[j] & 3) << 4]; | ||
34 | buf[i++] = BASE64_END; | ||
35 | buf[i++] = BASE64_END; | ||
36 | break; | ||
37 | case 2: | ||
38 | buf[i++] = base64_table[bin[j] >> 2]; | ||
39 | buf[i++] = base64_table[((bin[j] & 3) << 4) | (bin[j + 1] >> 4)]; | ||
40 | buf[i++] = base64_table[(bin[j + 1] & 15) << 2]; | ||
41 | buf[i++] = BASE64_END; | ||
42 | break; | ||
43 | case 0: | ||
44 | break; | ||
45 | } | ||
46 | |||
47 | buf[i] = '\0'; | ||
48 | return buf; | ||
49 | } | ||
50 | |||
diff --git a/lib/base64.h b/lib/base64.h new file mode 100644 index 00000000..1e0a0b04 --- /dev/null +++ b/lib/base64.h | |||
@@ -0,0 +1,4 @@ | |||
1 | /* Header file for base64.c */ | ||
2 | |||
3 | char *base64 (const char *bin, size_t len); | ||
4 | |||
diff --git a/plugins/check_http.c b/plugins/check_http.c index 901f6b66..36374233 100644 --- a/plugins/check_http.c +++ b/plugins/check_http.c | |||
@@ -48,6 +48,7 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net"; | |||
48 | #include "common.h" | 48 | #include "common.h" |
49 | #include "netutils.h" | 49 | #include "netutils.h" |
50 | #include "utils.h" | 50 | #include "utils.h" |
51 | #include "base64.h" | ||
51 | 52 | ||
52 | #define INPUT_DELIMITER ";" | 53 | #define INPUT_DELIMITER ";" |
53 | 54 | ||
@@ -125,7 +126,6 @@ char *http_content_type; | |||
125 | char buffer[MAX_INPUT_BUFFER]; | 126 | char buffer[MAX_INPUT_BUFFER]; |
126 | 127 | ||
127 | int process_arguments (int, char **); | 128 | int process_arguments (int, char **); |
128 | static char *base64 (const char *bin, size_t len); | ||
129 | int check_http (void); | 129 | int check_http (void); |
130 | void redir (char *pos, char *status_line); | 130 | void redir (char *pos, char *status_line); |
131 | int server_type_check(const char *type); | 131 | int server_type_check(const char *type); |
@@ -455,49 +455,6 @@ process_arguments (int argc, char **argv) | |||
455 | 455 | ||
456 | 456 | ||
457 | 457 | ||
458 | /* written by lauri alanko */ | ||
459 | static char * | ||
460 | base64 (const char *bin, size_t len) | ||
461 | { | ||
462 | |||
463 | char *buf = (char *) malloc ((len + 2) / 3 * 4 + 1); | ||
464 | size_t i = 0, j = 0; | ||
465 | |||
466 | char BASE64_END = '='; | ||
467 | char base64_table[64]; | ||
468 | strncpy (base64_table, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", 64); | ||
469 | |||
470 | while (j < len - 2) { | ||
471 | buf[i++] = base64_table[bin[j] >> 2]; | ||
472 | buf[i++] = base64_table[((bin[j] & 3) << 4) | (bin[j + 1] >> 4)]; | ||
473 | buf[i++] = base64_table[((bin[j + 1] & 15) << 2) | (bin[j + 2] >> 6)]; | ||
474 | buf[i++] = base64_table[bin[j + 2] & 63]; | ||
475 | j += 3; | ||
476 | } | ||
477 | |||
478 | switch (len - j) { | ||
479 | case 1: | ||
480 | buf[i++] = base64_table[bin[j] >> 2]; | ||
481 | buf[i++] = base64_table[(bin[j] & 3) << 4]; | ||
482 | buf[i++] = BASE64_END; | ||
483 | buf[i++] = BASE64_END; | ||
484 | break; | ||
485 | case 2: | ||
486 | buf[i++] = base64_table[bin[j] >> 2]; | ||
487 | buf[i++] = base64_table[((bin[j] & 3) << 4) | (bin[j + 1] >> 4)]; | ||
488 | buf[i++] = base64_table[(bin[j + 1] & 15) << 2]; | ||
489 | buf[i++] = BASE64_END; | ||
490 | break; | ||
491 | case 0: | ||
492 | break; | ||
493 | } | ||
494 | |||
495 | buf[i] = '\0'; | ||
496 | return buf; | ||
497 | } | ||
498 | |||
499 | |||
500 | |||
501 | /* Returns 1 if we're done processing the document body; 0 to keep going */ | 458 | /* Returns 1 if we're done processing the document body; 0 to keep going */ |
502 | static int | 459 | static int |
503 | document_headers_done (char *full_page) | 460 | document_headers_done (char *full_page) |
diff --git a/plugins/check_smtp.c b/plugins/check_smtp.c index 79c7cd35..f44e5331 100644 --- a/plugins/check_smtp.c +++ b/plugins/check_smtp.c | |||
@@ -45,6 +45,7 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net"; | |||
45 | #include "common.h" | 45 | #include "common.h" |
46 | #include "netutils.h" | 46 | #include "netutils.h" |
47 | #include "utils.h" | 47 | #include "utils.h" |
48 | #include "base64.h" | ||
48 | 49 | ||
49 | #ifdef HAVE_SSL | 50 | #ifdef HAVE_SSL |
50 | int check_cert = FALSE; | 51 | int check_cert = FALSE; |
@@ -122,46 +123,6 @@ enum { | |||
122 | UDP_PROTOCOL = 2, | 123 | UDP_PROTOCOL = 2, |
123 | }; | 124 | }; |
124 | 125 | ||
125 | /* written by lauri alanko */ | ||
126 | static char * | ||
127 | base64 (const char *bin, size_t len) | ||
128 | { | ||
129 | |||
130 | char *buf = (char *) malloc ((len + 2) / 3 * 4 + 1); | ||
131 | size_t i = 0, j = 0; | ||
132 | |||
133 | char BASE64_END = '='; | ||
134 | char base64_table[64]; | ||
135 | strncpy (base64_table, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", 64); | ||
136 | |||
137 | while (j < len - 2) { | ||
138 | buf[i++] = base64_table[bin[j] >> 2]; | ||
139 | buf[i++] = base64_table[((bin[j] & 3) << 4) | (bin[j + 1] >> 4)]; | ||
140 | buf[i++] = base64_table[((bin[j + 1] & 15) << 2) | (bin[j + 2] >> 6)]; | ||
141 | buf[i++] = base64_table[bin[j + 2] & 63]; | ||
142 | j += 3; | ||
143 | } | ||
144 | |||
145 | switch (len - j) { | ||
146 | case 1: | ||
147 | buf[i++] = base64_table[bin[j] >> 2]; | ||
148 | buf[i++] = base64_table[(bin[j] & 3) << 4]; | ||
149 | buf[i++] = BASE64_END; | ||
150 | buf[i++] = BASE64_END; | ||
151 | break; | ||
152 | case 2: | ||
153 | buf[i++] = base64_table[bin[j] >> 2]; | ||
154 | buf[i++] = base64_table[((bin[j] & 3) << 4) | (bin[j + 1] >> 4)]; | ||
155 | buf[i++] = base64_table[(bin[j + 1] & 15) << 2]; | ||
156 | buf[i++] = BASE64_END; | ||
157 | break; | ||
158 | case 0: | ||
159 | break; | ||
160 | } | ||
161 | |||
162 | buf[i] = '\0'; | ||
163 | return buf; | ||
164 | } | ||
165 | 126 | ||
166 | int | 127 | int |
167 | main (int argc, char **argv) | 128 | main (int argc, char **argv) |
@@ -567,6 +528,7 @@ process_arguments (int argc, char **argv) | |||
567 | break; | 528 | break; |
568 | case 'A': | 529 | case 'A': |
569 | authtype = optarg; | 530 | authtype = optarg; |
531 | use_ehlo = TRUE; | ||
570 | break; | 532 | break; |
571 | case 'U': | 533 | case 'U': |
572 | authuser = optarg; | 534 | authuser = optarg; |