summaryrefslogtreecommitdiff
path: root/net/wireshark/patches/patch-ad
blob: 06c4150bbda3ac1435a5c06c6134942e3de1bcf1 (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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
$NetBSD: patch-ad,v 1.1 2008/11/25 22:53:55 tron Exp $

--- epan/dissectors/packet-smtp.c.orig	2008-10-20 20:19:31.000000000 +0100
+++ epan/dissectors/packet-smtp.c	2008-11-25 22:30:30.000000000 +0000
@@ -101,10 +101,6 @@
 	"DATA fragments"
 };
 
-/* Define media_type/Content type table */
-static dissector_table_t media_type_dissector_table;
-
-
 static  dissector_handle_t imf_handle = NULL;
 
 /*
@@ -179,6 +175,7 @@
     gint                    length_remaining;
     gboolean                eom_seen = FALSE;
     gint                    next_offset;
+    gint                    loffset;
     gboolean                is_continuation_line;
     int                     cmdlen;
     fragment_data           *frag_msg = NULL;
@@ -221,21 +218,6 @@
      * longer than what's in the buffer, so the "tvb_get_ptr()" call
      * won't throw an exception.
      */
-    linelen = tvb_find_line_end(tvb, offset, -1, &next_offset,
-      smtp_desegment && pinfo->can_desegment);
-    if (linelen == -1) {
-      /*
-       * We didn't find a line ending, and we're doing desegmentation;
-       * tell the TCP dissector where the data for this message starts
-       * in the data it handed us, and tell it we need one more byte
-       * (we may need more, but we'll try again if what we get next
-       * isn't enough), and return.
-       */
-      pinfo->desegment_offset = offset;
-      pinfo->desegment_len = 1;
-      return;
-    }
-    line = tvb_get_ptr(tvb, offset, linelen);
 
     frame_data = p_get_proto_data(pinfo->fd, proto_smtp);
 
@@ -271,6 +253,42 @@
 
       }
 
+      if(request) {
+	frame_data = se_alloc(sizeof(struct smtp_proto_data));
+
+	frame_data->conversation_id = conversation->index;
+	frame_data->more_frags = TRUE;
+
+	p_add_proto_data(pinfo->fd, proto_smtp, frame_data);	
+
+      }
+
+    loffset = offset;
+    while (tvb_offset_exists(tvb, loffset)) {
+
+    linelen = tvb_find_line_end(tvb, loffset, -1, &next_offset,
+      smtp_desegment && pinfo->can_desegment);
+    if (linelen == -1) {
+
+      if(offset == loffset) {
+      /*
+       * We didn't find a line ending, and we're doing desegmentation;
+       * tell the TCP dissector where the data for this message starts
+       * in the data it handed us, and tell it we need one more byte
+       * (we may need more, but we'll try again if what we get next
+       * isn't enough), and return.
+       */
+      pinfo->desegment_offset = loffset;
+      pinfo->desegment_len = 1;
+      return;
+      }
+      else {
+	linelen = tvb_length_remaining(tvb, loffset);
+	next_offset = loffset + linelen;
+      }
+    }
+    line = tvb_get_ptr(tvb, loffset, linelen);
+
       /*
        * Check whether or not this packet is an end of message packet
        * We should look for CRLF.CRLF and they may be split.
@@ -286,16 +304,16 @@
 	 * .CRLF at the begining of the same packet.
 	 */
 
-	if ((request_val->crlf_seen && tvb_strneql(tvb, offset, ".\r\n", 3) == 0) ||
-	    tvb_strneql(tvb, offset, "\r\n.\r\n", 5) == 0) {
+	if ((request_val->crlf_seen && tvb_strneql(tvb, loffset, ".\r\n", 3) == 0) ||
+	    tvb_strneql(tvb, loffset, "\r\n.\r\n", 5) == 0) {
 
 	  eom_seen = TRUE;
 
-	}
+	} 
 
-	length_remaining = tvb_length_remaining(tvb, offset);
-	if (length_remaining == tvb_reported_length_remaining(tvb, offset) &&
-	    tvb_strneql(tvb, offset + length_remaining - 2, "\r\n", 2) == 0) {
+	length_remaining = tvb_length_remaining(tvb, loffset);
+	if (length_remaining == tvb_reported_length_remaining(tvb, loffset) &&
+	    tvb_strneql(tvb, loffset + length_remaining - 2, "\r\n", 2) == 0) {
 
 	  request_val->crlf_seen = TRUE;
 
@@ -314,11 +332,6 @@
 
       if (request) {
 
-	frame_data = se_alloc(sizeof(struct smtp_proto_data));
-
-	frame_data->conversation_id = conversation->index;
-	frame_data->more_frags = TRUE;
-
 	if (request_val->reading_data) {
 	  /*
 	   * This is message data.
@@ -333,6 +346,9 @@
 	     */
 	    frame_data->pdu_type = SMTP_PDU_EOM;
 	    request_val->reading_data = FALSE;
+	    
+	    break;
+	    
 	  } else {
 	    /*
 	     * Message data with no EOM.
@@ -344,7 +360,7 @@
 	       * We are handling a BDAT message.
 	       * Check if we have reached end of the data chunk.
 	       */
-	      request_val->msg_read_len += tvb_length_remaining(tvb, offset);
+	      request_val->msg_read_len += tvb_length_remaining(tvb, loffset);
 
               if (request_val->msg_read_len == request_val->msg_tot_len) {
 		/* 
@@ -360,6 +376,8 @@
 		   */
 		  frame_data->more_frags = FALSE;
 		}
+		
+		break; /* no need to go through the remaining lines */
 	      }
 	    }
 	  }
@@ -450,12 +468,15 @@
 	    frame_data->pdu_type = request_val->data_seen ? SMTP_PDU_MESSAGE : SMTP_PDU_CMD;
 
 	  }
-
 	}
+      }
 
-	p_add_proto_data(pinfo->fd, proto_smtp, frame_data);
+      /*
+       * Step past this line.
+       */
+      loffset = next_offset;
 
-      }
+    }
     }
 
     /*
@@ -467,6 +488,7 @@
       col_set_str(pinfo->cinfo, COL_PROTOCOL, "SMTP");
 
     if (check_col(pinfo->cinfo, COL_INFO)) {  /* Add the appropriate type here */
+      col_clear(pinfo->cinfo, COL_INFO);
 
       /*
        * If it is a request, we have to look things up, otherwise, just
@@ -481,21 +503,38 @@
 	case SMTP_PDU_MESSAGE:
 
 	  length_remaining = tvb_length_remaining(tvb, offset);
-	  col_set_str(pinfo->cinfo, COL_INFO, smtp_data_desegment ? "DATA fragment" : "Message Body");
+	  col_set_str(pinfo->cinfo, COL_INFO, smtp_data_desegment ? "C: DATA fragment" : "C: Message Body");
 	  col_append_fstr(pinfo->cinfo, COL_INFO, ", %d byte%s", length_remaining,
 			  plurality (length_remaining, "", "s"));
 	  break;
 
 	case SMTP_PDU_EOM:
 
-	  col_add_fstr(pinfo->cinfo, COL_INFO, "EOM: %s",
-	      format_text(line, linelen));
+	  col_set_str(pinfo->cinfo, COL_INFO, "C: .");
+
 	  break;
 
 	case SMTP_PDU_CMD:
 
-	  col_add_fstr(pinfo->cinfo, COL_INFO, "Command: %s",
-	      format_text(line, linelen));
+	  loffset = offset;
+	  while (tvb_offset_exists(tvb, loffset)) {
+	    /*
+	     * Find the end of the line.
+	     */
+	    linelen = tvb_find_line_end(tvb, loffset, -1, &next_offset, FALSE);
+	    line = tvb_get_ptr(tvb, loffset, linelen);
+
+	    if(loffset == offset) 
+	      col_append_fstr(pinfo->cinfo, COL_INFO, "C: %s",
+			   format_text(line, linelen));
+	    else {
+	      col_append_fstr(pinfo->cinfo, COL_INFO, " | %s",
+			   format_text(line, linelen));
+	    }
+
+	    loffset = next_offset;
+
+	  }
 	  break;
 
 	}
@@ -503,9 +542,24 @@
       }
       else {
 
-	col_add_fstr(pinfo->cinfo, COL_INFO, "Response: %s",
-	    format_text(line, linelen));
+	  loffset = offset;
+	  while (tvb_offset_exists(tvb, loffset)) {
+	    /*
+	     * Find the end of the line.
+	     */
+	    linelen = tvb_find_line_end(tvb, loffset, -1, &next_offset, FALSE);
+	    line = tvb_get_ptr(tvb, loffset, linelen);
+
+	    if(loffset == offset) 
+	      col_append_fstr(pinfo->cinfo, COL_INFO, "S: %s",
+			   format_text(line, linelen));
+	    else {
+	      col_append_fstr(pinfo->cinfo, COL_INFO, " | %s",
+			   format_text(line, linelen));
+	    }
 
+	    loffset = next_offset;
+	  }
       }
     }
 
@@ -560,8 +614,7 @@
 	   * DATA command this terminates before sending another
 	   * request, but we should probably handle it.
 	   */
-	  proto_tree_add_text(smtp_tree, tvb, offset, linelen,
-	      "EOM: %s", format_text(line, linelen));
+	  proto_tree_add_text(smtp_tree, tvb, offset, linelen, "C: .");
 
 	  if(smtp_data_desegment) {
 
@@ -582,6 +635,15 @@
 	   * previous command before sending another request, but we
 	   * should probably handle it.
 	   */
+
+	  loffset = offset;
+	while (tvb_offset_exists(tvb, loffset)) {
+
+	  /*
+	   * Find the end of the line.
+	   */
+	  linelen = tvb_find_line_end(tvb, loffset, -1, &next_offset, FALSE);
+
 	  if (linelen >= 4)
 	    cmdlen = 4;
 	  else
@@ -591,16 +653,16 @@
 	  /*
 	   * Put the command line into the protocol tree.
 	   */
-	  ti = proto_tree_add_text(smtp_tree, tvb, offset, next_offset - offset,
+	  ti = proto_tree_add_text(smtp_tree, tvb, loffset, next_offset - loffset,
 	        "Command: %s",
-		tvb_format_text(tvb, offset, next_offset - offset));
+		tvb_format_text(tvb, loffset, next_offset - loffset));
 	  cmdresp_tree = proto_item_add_subtree(ti, ett_smtp_cmdresp);
 
 	  proto_tree_add_item(cmdresp_tree, hf_smtp_req_command, tvb,
-			      offset, cmdlen, FALSE);
+			      loffset, cmdlen, FALSE);
 	  if (linelen > 5) {
 	    proto_tree_add_item(cmdresp_tree, hf_smtp_req_parameter, tvb,
-				offset + 5, linelen - 5, FALSE);
+				loffset + 5, linelen - 5, FALSE);
 	  }
 
 	  if (smtp_data_desegment && !frame_data->more_frags) {
@@ -609,6 +671,13 @@
 	    frag_msg = fragment_end_seq_next (pinfo, frame_data->conversation_id, smtp_data_segment_table,
 					      smtp_data_reassembled_table);
 	  }
+
+	  /*
+	   * Step past this line.
+	   */
+	  loffset = next_offset;
+	  
+	}
 	}
 
 	if (smtp_data_desegment) {
@@ -693,8 +762,8 @@
 	  /*
 	   * If it's not a continuation line, quit.
 	   */
-	  if (!is_continuation_line)
-	    break;
+	  /* if (!is_continuation_line)
+	     break; */
 
 	}
 
@@ -775,7 +844,6 @@
   };
   module_t *smtp_module;
 
-
   proto_smtp = proto_register_protocol("Simple Mail Transfer Protocol",
 				       "SMTP", "smtp");
 
@@ -812,11 +880,6 @@
   dissector_add("tcp.port", TCP_PORT_SMTP, smtp_handle);
   dissector_add("tcp.port", TCP_PORT_SUBMISSION, smtp_handle);
 
-  /*
-   * Get the content type and Internet media type table
-   */
-  media_type_dissector_table = find_dissector_table("media_type");
-
   /* find the IMF dissector */
   imf_handle = find_dissector("imf");