summaryrefslogtreecommitdiffstats
path: root/web/attachments/418216-check_smtp.c.reworked.patch
blob: 729986c8675e746065cd0f866e08fabf1fbee3b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
diff -ru nagios-plugins-1.4.15.orig/plugins/check_smtp.c nagios-plugins-1.4.15/plugins/check_smtp.c
--- nagios-plugins-1.4.15.orig/plugins/check_smtp.c	2010-07-27 20:47:16.000000000 +0000
+++ nagios-plugins-1.4.15/plugins/check_smtp.c	2011-07-15 10:51:11.000000000 +0000
@@ -114,6 +114,7 @@
   TCP_PROTOCOL = 1,
   UDP_PROTOCOL = 2,
 };
+int ignore_send_quit_failure = FALSE;
 
 
 int
@@ -129,6 +130,9 @@
 	char *error_msg = "";
 	struct timeval tv;
 
+	/* catch pipe errors in read.write */
+	(void) signal (SIGPIPE, SIG_IGN);
+
 	setlocale (LC_ALL, "");
 	bindtextdomain (PACKAGE, LOCALEDIR);
 	textdomain (PACKAGE);
@@ -476,6 +480,7 @@
 		{"help", no_argument, 0, 'h'},
 		{"starttls",no_argument,0,'S'},
 		{"certificate",required_argument,0,'D'},
+		{"ignore-quit-failure",no_argument,0,'q'},
 		{0, 0, 0, 0}
 	};
 
@@ -492,7 +497,7 @@
 	}
 
 	while (1) {
-		c = getopt_long (argc, argv, "+hVv46t:p:f:e:c:w:H:C:R:SD:F:A:U:P:",
+		c = getopt_long (argc, argv, "+hVv46t:p:f:e:c:w:H:C:R:SD:F:A:U:P:q",
 		                 longopts, &option);
 
 		if (c == -1 || c == EOF)
@@ -579,6 +584,9 @@
 		case 'v':									/* verbose */
 			verbose++;
 			break;
+        case 'q':
+            ignore_send_quit_failure++;             /* ignore problem sending QUIT */
+            break;
 		case 't':									/* timeout */
 			if (is_intnonneg (optarg)) {
 				socket_timeout = atoi (optarg);
@@ -662,8 +670,21 @@
 smtp_quit(void)
 {
 	int bytes;
+    int n;
+
+	n = my_send(SMTP_QUIT, strlen(SMTP_QUIT));
+	if(n != 0) {
+		if(ignore_send_quit_failure) {
+			if(verbose) {
+				printf(
+					_("Connection closed by server before sending QUIT command\n"));
+			}
+			return;
+		}
+		die (STATE_UNKNOWN,
+			_("Connection closed by server before sending QUIT command\n"));
+	}
 
-	my_send(SMTP_QUIT, strlen(SMTP_QUIT));
 	if (verbose)
 		printf(_("sent %s\n"), "QUIT");
 
@@ -797,7 +818,9 @@
   printf ("    %s\n", _("SMTP AUTH username"));
   printf (" %s\n", "-P, --authpass=STRING");
   printf ("    %s\n", _("SMTP AUTH password"));
-
+  printf (" %s\n", "-q, --ignore-quit-failure");
+  printf ("    %s\n", _("Ignore failure when sending QUIT command to server"));
+   
 	printf (UT_WARN_CRIT);
 
 	printf (UT_TIMEOUT, DEFAULT_SOCKET_TIMEOUT);
@@ -821,6 +844,6 @@
   printf ("%s\n", _("Usage:"));
   printf ("%s -H host [-p port] [-e expect] [-C command] [-f from addr]", progname);
   printf ("[-A authtype -U authuser -P authpass] [-w warn] [-c crit] [-t timeout]\n");
-  printf ("[-F fqdn] [-S] [-D days] [-v] [-4|-6]\n");
+  printf ("[-F fqdn] [-S] [-D days] [-v] [-4|-6] [-q]\n");
 }