summaryrefslogtreecommitdiffstats
path: root/plugins/check_smtp.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/check_smtp.c')
-rw-r--r--plugins/check_smtp.c102
1 files changed, 50 insertions, 52 deletions
diff --git a/plugins/check_smtp.c b/plugins/check_smtp.c
index 986c3e1..e6369e6 100644
--- a/plugins/check_smtp.c
+++ b/plugins/check_smtp.c
@@ -3,7 +3,7 @@
3* Monitoring check_smtp plugin 3* Monitoring check_smtp plugin
4* 4*
5* License: GPL 5* License: GPL
6* Copyright (c) 2000-2023 Monitoring Plugins Development Team 6* Copyright (c) 2000-2024 Monitoring Plugins Development Team
7* 7*
8* Description: 8* Description:
9* 9*
@@ -29,7 +29,7 @@
29*****************************************************************************/ 29*****************************************************************************/
30 30
31const char *progname = "check_smtp"; 31const char *progname = "check_smtp";
32const char *copyright = "2000-2007"; 32const char *copyright = "2000-2024";
33const char *email = "devel@monitoring-plugins.org"; 33const char *email = "devel@monitoring-plugins.org";
34 34
35#include "common.h" 35#include "common.h"
@@ -40,8 +40,8 @@ const char *email = "devel@monitoring-plugins.org";
40#include <ctype.h> 40#include <ctype.h>
41 41
42#ifdef HAVE_SSL 42#ifdef HAVE_SSL
43bool check_cert = false; 43static bool check_cert = false;
44int days_till_exp_warn, days_till_exp_crit; 44static int days_till_exp_warn, days_till_exp_crit;
45# define my_recv(buf, len) (((use_starttls || use_ssl) && ssl_established) ? np_net_ssl_read(buf, len) : read(sd, buf, len)) 45# define my_recv(buf, len) (((use_starttls || use_ssl) && ssl_established) ? np_net_ssl_read(buf, len) : read(sd, buf, len))
46# define my_send(buf, len) (((use_starttls || use_ssl) && ssl_established) ? np_net_ssl_write(buf, len) : send(sd, buf, len, 0)) 46# define my_send(buf, len) (((use_starttls || use_ssl) && ssl_established) ? np_net_ssl_write(buf, len) : send(sd, buf, len, 0))
47#else /* ifndef HAVE_SSL */ 47#else /* ifndef HAVE_SSL */
@@ -64,61 +64,59 @@ enum {
64 64
65#define EHLO_SUPPORTS_STARTTLS 1 65#define EHLO_SUPPORTS_STARTTLS 1
66 66
67int process_arguments (int, char **); 67static int process_arguments (int, char **);
68int validate_arguments (void); 68static int validate_arguments (void);
69void print_help (void); 69static void print_help (void);
70void print_usage (void); 70void print_usage (void);
71void smtp_quit(void); 71static void smtp_quit(void);
72int recvline(char *, size_t); 72static int recvline(char *, size_t);
73int recvlines(char *, size_t); 73static int recvlines(char *, size_t);
74int my_close(void); 74static int my_close(void);
75 75
76#include "regex.h" 76#include "regex.h"
77char regex_expect[MAX_INPUT_BUFFER] = ""; 77static regex_t preg;
78regex_t preg; 78static regmatch_t pmatch[10];
79regmatch_t pmatch[10]; 79static char errbuf[MAX_INPUT_BUFFER];
80char timestamp[20] = ""; 80static int cflags = REG_EXTENDED | REG_NOSUB | REG_NEWLINE;
81char errbuf[MAX_INPUT_BUFFER]; 81static int eflags = 0;
82int cflags = REG_EXTENDED | REG_NOSUB | REG_NEWLINE; 82static int errcode, excode;
83int eflags = 0; 83
84int errcode, excode; 84static int server_port = SMTP_PORT;
85 85static int server_port_option = 0;
86int server_port = SMTP_PORT; 86static char *server_address = NULL;
87int server_port_option = 0; 87static char *server_expect = NULL;
88char *server_address = NULL; 88static char *mail_command = NULL;
89char *server_expect = NULL; 89static char *from_arg = NULL;
90char *mail_command = NULL; 90static int send_mail_from=0;
91char *from_arg = NULL; 91static int ncommands=0;
92int send_mail_from=0; 92static int command_size=0;
93int ncommands=0; 93static int nresponses=0;
94int command_size=0; 94static int response_size=0;
95int nresponses=0; 95static char **commands = NULL;
96int response_size=0; 96static char **responses = NULL;
97char **commands = NULL; 97static char *authtype = NULL;
98char **responses = NULL; 98static char *authuser = NULL;
99char *authtype = NULL; 99static char *authpass = NULL;
100char *authuser = NULL; 100static double warning_time = 0;
101char *authpass = NULL; 101static bool check_warning_time = false;
102double warning_time = 0; 102static double critical_time = 0;
103bool check_warning_time = false; 103static bool check_critical_time = false;
104double critical_time = 0; 104static int verbose = 0;
105bool check_critical_time = false; 105static bool use_ssl = false;
106int verbose = 0; 106static bool use_starttls = false;
107bool use_ssl = false; 107static bool use_sni = false;
108bool use_starttls = false; 108static bool use_proxy_prefix = false;
109bool use_sni = false; 109static bool use_ehlo = false;
110bool use_proxy_prefix = false; 110static bool use_lhlo = false;
111bool use_ehlo = false; 111static bool ssl_established = false;
112bool use_lhlo = false; 112static char *localhostname = NULL;
113bool ssl_established = false; 113static int sd;
114char *localhostname = NULL; 114static char buffer[MAX_INPUT_BUFFER];
115int sd;
116char buffer[MAX_INPUT_BUFFER];
117enum { 115enum {
118 TCP_PROTOCOL = 1, 116 TCP_PROTOCOL = 1,
119 UDP_PROTOCOL = 2, 117 UDP_PROTOCOL = 2,
120}; 118};
121bool ignore_send_quit_failure = false; 119static bool ignore_send_quit_failure = false;
122 120
123 121
124int 122int