-
Notifications
You must be signed in to change notification settings - Fork 2
/
decode_ftp.c
58 lines (42 loc) · 1.06 KB
/
decode_ftp.c
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
/*
decode_ftp.c
File Transfer Protocol.
Copyright (c) 2000 Dug Song <[email protected]>
$Id: decode_ftp.c,v 1.6 2000/11/16 07:00:08 dugsong Exp $
*/
#include "config.h"
#include <sys/types.h>
#include <stdio.h>
#include <string.h>
#include "options.h"
#include "buf.h"
#include "decode.h"
int
decode_ftp(u_char *buf, int len, u_char *obuf, int olen)
{
struct buf *line, inbuf, outbuf;
int i, n;
if ((len = strip_telopts(buf, len)) == 0)
return (0);
buf_init(&inbuf, buf, len);
buf_init(&outbuf, obuf, olen);
if (!buf_isascii(&inbuf))
return (0);
n = 0;
while ((i = buf_index(&inbuf, "\n", 1)) != -1) {
line = buf_tok(&inbuf, NULL, i);
buf_skip(&inbuf, 1);
if (i > 0 && line->base[i - 1] == '\r')
line->end--;
line->base[line->end] = '\0';
if (strncasecmp(buf_ptr(line), "USER ", 5) == 0 ||
strncasecmp(buf_ptr(line), "ACCT ", 5) == 0 ||
strncasecmp(buf_ptr(line), "PASS ", 5) == 0) {
buf_putf(&outbuf, "%s\n", buf_ptr(line));
n++;
}
}
if (n < 2) return (0);
buf_end(&outbuf);
return (buf_len(&outbuf));
}