summaryrefslogtreecommitdiffstats
path: root/web/attachments/115229-check_tcp.c.diff
blob: bd40d794fe1219de73d1d98653dd93642331624b (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
91
92
93
94
95
96
97
98
99
100
101
102
--- check_tcp.c.orig	Thu Jan  6 12:20:54 2005
+++ check_tcp.c	Thu Jan  6 12:31:24 2005
@@ -63,6 +63,11 @@
 	MAXBUF = 1024
 };
 
+enum {
+	CRLF = 1,
+	LF   = 2
+};
+
 int process_arguments (int, char **);
 int my_recv (void);
 void print_help (void);
@@ -100,6 +105,7 @@
 int sd = 0;
 char *buffer;
 int expect_mismatch_state = STATE_WARNING;
+int lineterm = CRLF;
 int exact_matching = TRUE;
 
 int
@@ -312,7 +318,9 @@
 		while ((i = my_recv ()) > 0) {
 			buffer[i] = '\0';
 			asprintf (&status, "%s%s", status, buffer);
-			if (buffer[i-2] == '\r' && buffer[i-1] == '\n')
+			if (buffer[i-2] == '\r' && buffer[i-1] == '\n' && lineterm == CRLF)
+				break;
+			if (buffer[i-1] == '\n' && lineterm == LF)
 				break;
 			if (maxbytes>0 && strlen(status) >= (unsigned)maxbytes)
 				break;
@@ -421,6 +429,7 @@
 		{"delay", required_argument, 0, 'd'},
 		{"refuse", required_argument, 0, 'r'},
 		{"mismatch", required_argument, 0, 'M'},
+		{"lineterm", required_argument, 0, 'l'},
 		{"use-ipv4", no_argument, 0, '4'},
 		{"use-ipv6", no_argument, 0, '6'},
 		{"verbose", no_argument, 0, 'v'},
@@ -454,7 +463,7 @@
 	}
 
 	while (1) {
-		c = getopt_long (argc, argv, "+hVv46H:s:e:q:m:c:w:t:p:C:W:d:Sr:jD:M:",
+		c = getopt_long (argc, argv, "+hVv46H:s:e:q:m:c:w:t:p:C:W:d:Sr:jD:M:l:",
 		                 longopts, &option);
 
 		if (c == -1 || c == EOF || c == 1)
@@ -566,13 +575,31 @@
 			else
 				usage4 (_("Mismatch must be one of ok, warn, crit"));
 			break;
+		case 'l':
+			if (is_intpos (optarg)) {
+				int num = atoi(optarg);
+
+				switch (num) {
+					case 1:
+						lineterm = CRLF;
+						break;
+					case 2:
+						lineterm = LF;
+						break;
+					default:
+						usage4 (_("Line termination must be 1 (CRLF) or 2 (LF)"));
+					break;
+				}
+			} else
+				usage4 (_("Line termination must be a positive integer"));
+			break;
 		case 'd':
 			if (is_intpos (optarg))
 				delay = atoi (optarg);
 			else
 				usage4 (_("Delay must be a positive integer"));
 			break;
-                 case 'D': /* Check SSL cert validity - days 'til certificate expiration */
+		case 'D': /* Check SSL cert validity - days 'til certificate expiration */
 #ifdef HAVE_SSL
 			if (!is_intnonneg (optarg))
 				usage2 ("invalid certificate expiration period", optarg);
@@ -784,6 +811,8 @@
     Accept tcp refusals with states ok, warn, crit (default: crit)\n\
  -M, --mismatch=ok|warn|crit\n\
     Accept expected string mismatches with states ok, warn, crit (default: warn)\n\
+ -l, --lineterm=1|2\r\
+    Line termination expected from remote peer (1 is CRLF; 2 is LF only)\n\
  -j, --jail\n\
     Hide output from TCP socket\n\
  -m, --maxbytes=INTEGER\n\
@@ -817,6 +846,7 @@
 Usage: %s -H host -p port [-w <warning time>] [-c <critical time>]\n\
                   [-s <send string>] [-e <expect string>] [-q <quit string>]\n\
                   [-m <maximum bytes>] [-d <delay>] [-t <timeout seconds>]\n\
-                  [-r <refuse state>] [-M <mismatch state>] [-v] [-4|-6] [-j]\n\
-                  [-D <days to cert expiry>] [-S <use SSL>]\n", progname);		  
+                  [-r <refuse state>] [-M <mismatch state>] [-l <1|2>] [-v]\n\
+                  [-4|-6] [-j] [-D <days to cert expiry>] [-S <use SSL>]\n",
+	        progname);		  
 }