File: decode_smtp.c

package info (click to toggle)
dsniff 2.5a2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,104 kB
  • sloc: ansic: 13,081; sh: 152; makefile: 140
file content (80 lines) | stat: -rw-r--r-- 1,558 bytes parent folder | download
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
/*
 * decode_smtp.c
 *
 * Simple Mail Transfer Protocol.
 *
 * Copyright (c) 2000 Dug Song <dugsong@monkey.org>
 *
 * $Id: decode_smtp.c,v 1.3 2001/03/15 08:33:02 dugsong Exp $
 */

#include "config.h"

#include <sys/types.h>

#include <stdio.h>
#include <string.h>
#include <strlcat.h>

#include "base64.h"
#include "options.h"
#include "decode.h"

extern struct _dc_meta dc_meta;

int
decode_smtp(u_char *buf, int len, u_char *obuf, int olen)
{
	char *p, *s;
	int i, j, login = 0;
	int found = 0;
	
	obuf[0] = '\0';
	for (p = strtok(buf, "\r\n"); p != NULL; p = strtok(NULL, "\r\n")) {
		if ((strncmp(p, "MAIL ", 5) == 0) || (strncmp(p, "RCPT ", 5) == 0)) {
			if (!Opt_verbose)
				break;
			if (obuf[0] != '\0')
				strlcat(obuf, "\n", olen);
			strlcat(obuf, p+5, olen);
			if (++found >= 2)
				break;
			continue;
		}
		if ((strncmp(p, "DATA", 4) == 0) || (strncmp(p, "QUIT", 4) == 0))
			break;

		if (login == 0) {
			if (strncmp(p, "AUTH LOGIN", 10) != 0)
				continue;
		
			strlcat(obuf, p, olen);
			p += 10;
			i = base64_pton(p, p, strlen(p));
			if (i > 0) {
				p[i] = '\0';
				j = strlen(obuf);
				snprintf(obuf + j, olen - j, " [%s]", p);
			} else {
				strlcat(obuf, " ", olen);
				login = 1;
			}
			dc_meta.is_hot = 1;
			continue;
		}

		strlcat(obuf, p, olen);
		// USER: <base64>
		// PASS: <base64>
		// <base64>
		if ((s = strchr(p, ' ')) != NULL)
			p = ++s;
		i = base64_pton(p, p, strlen(p));
		if (i > 0) {
			p[i] = '\0';
			j = strlen(obuf);
			snprintf(obuf + j, olen - j, " [%s] ", p);
		}
	}
	return (strlen(obuf));
}