dsniff  2.4b2
About: A collection of tools for network auditing
  Fossies Dox: dsniff-2.4b2.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

decode_ftp.c
Go to the documentation of this file.
1 /*
2  * decode_ftp.c
3  *
4  * File Transfer Protocol.
5  *
6  * Copyright (c) 2000 Dug Song <dugsong@monkey.org>
7  *
8  * $Id: decode_ftp.c,v 1.7 2001/03/15 08:32:59 dugsong Exp $
9  */
10 
11 #include "config.h"
12 
13 #include <sys/types.h>
14 
15 #include <stdio.h>
16 #include <string.h>
17 
18 #include "options.h"
19 #include "buf.h"
20 #include "decode.h"
21 
22 int
23 decode_ftp(u_char *buf, int len, u_char *obuf, int olen)
24 {
25  struct buf *line, inbuf, outbuf;
26  int i, n;
27 
28  if ((len = strip_telopts(buf, len)) == 0)
29  return (0);
30 
31  buf_init(&inbuf, buf, len);
32  buf_init(&outbuf, obuf, olen);
33 
34  if (!buf_isascii(&inbuf))
35  return (0);
36 
37  n = 0;
38 
39  while ((i = buf_index(&inbuf, "\n", 1)) != -1) {
40  line = buf_tok(&inbuf, NULL, i);
41  buf_skip(&inbuf, 1);
42 
43  if (i > 0 && line->base[i - 1] == '\r')
44  line->end--;
45  line->base[line->end] = '\0';
46 
47  if (strncasecmp(buf_ptr(line), "USER ", 5) == 0 ||
48  strncasecmp(buf_ptr(line), "ACCT ", 5) == 0 ||
49  strncasecmp(buf_ptr(line), "PASS ", 5) == 0) {
50  buf_putf(&outbuf, "%s\n", buf_ptr(line));
51  n++;
52  }
53  }
54  if (n < 2) return (0);
55 
56  buf_end(&outbuf);
57 
58  return (buf_len(&outbuf));
59 }
60 
strip_telopts
int strip_telopts(u_char *buf, int len)
Definition: decode.c:110
buf_putf
int buf_putf(buf_t buf, const char *fmt,...)
Definition: buf.c:106
buf_isascii
int buf_isascii(buf_t buf)
Definition: buf.c:253
buf_init
void buf_init(buf_t buf, u_char *data, int len)
Definition: buf.c:24
buf_end
void buf_end(buf_t buf)
Definition: buf.c:121
options.h
decode.h
buf.h
decode_ftp
int decode_ftp(u_char *buf, int len, u_char *obuf, int olen)
Definition: decode_ftp.c:23
buf
Definition: buf.h:14
buf_tok
buf_t buf_tok(buf_t buf, void *sep, int len)
Definition: buf.c:167
buf_ptr
#define buf_ptr(b)
Definition: buf.h:31
line
Definition: sshow.c:62
buf_skip
#define buf_skip(b, l)
Definition: buf.h:47
config.h
obuf
static char obuf[4096]
Definition: trigger.c:43
buf_len
#define buf_len(b)
Definition: buf.h:34
buf_index
int buf_index(buf_t buf, void *ptr, int len)
Definition: buf.c:128