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_pop.c
Go to the documentation of this file.
1 /*
2  * decode_pop.c
3  *
4  * Post Office Protocol.
5  *
6  * Copyright (c) 2000 Dug Song <dugsong@monkey.org>
7  *
8  * $Id: decode_pop.c,v 1.4 2001/03/15 08:33:02 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 "base64.h"
19 #include "options.h"
20 #include "decode.h"
21 
22 int
23 decode_poppass(u_char *buf, int len, u_char *obuf, int olen)
24 {
25  char *p;
26 
27  obuf[0] = '\0';
28 
29  for (p = strtok(buf, "\r\n"); p != NULL; p = strtok(NULL, "\r\n")) {
30  if (strncasecmp(p, "user ", 5) == 0 ||
31  strncasecmp(p, "pass ", 5) == 0 ||
32  strncasecmp(p, "newpass ", 8) == 0) {
33  strlcat(obuf, p, olen);
34  strlcat(obuf, "\n", olen);
35  }
36  }
37  if (strip_lines(obuf, Opt_lines) < 3)
38  return (0);
39 
40  return (strlen(obuf));
41 }
42 
43 int
44 decode_pop(u_char *buf, int len, u_char *obuf, int olen)
45 {
46  char *p;
47  int i, j;
48 
49  obuf[0] = '\0';
50 
51  for (p = strtok(buf, "\r\n"); p != NULL; p = strtok(NULL, "\r\n")) {
52  if (strncasecmp(p, "AUTH PLAIN", 10) == 0 ||
53  strncasecmp(p, "AUTH LOGIN", 10) == 0) {
54  strlcat(obuf, p, olen);
55  strlcat(obuf, "\n", olen);
56 
57  /* Decode SASL auth. */
58  for (i = 0; i < 2 && (p = strtok(NULL, "\r\n")); i++) {
59  strlcat(obuf, p, olen);
60  j = base64_pton(p, p, strlen(p));
61  p[j] = '\0';
62  strlcat(obuf, " [", olen);
63  strlcat(obuf, p, olen);
64  strlcat(obuf, "]\n", olen);
65  }
66  }
67  /* Save regular POP2, POP3 auth info. */
68  else if (strncasecmp(p, "USER ", 5) == 0 ||
69  strncasecmp(p, "PASS ", 5) == 0 ||
70  strncasecmp(p, "HELO ", 5) == 0) {
71  strlcat(obuf, p, olen);
72  strlcat(obuf, "\n", olen);
73  }
74  }
75  return (strlen(obuf));
76 }
77 
options.h
strip_lines
int strip_lines(char *buf, int max_lines)
Definition: decode.c:159
decode.h
Opt_lines
int Opt_lines
Definition: dsniff.c:43
buf
Definition: buf.h:14
base64.h
decode_poppass
int decode_poppass(u_char *buf, int len, u_char *obuf, int olen)
Definition: decode_pop.c:23
base64_pton
int base64_pton(char const *src, u_char *target, size_t targsize)
Definition: base64.c:128
config.h
obuf
static char obuf[4096]
Definition: trigger.c:43
strlcat
size_t strlcat(char *dst, const char *src, size_t siz)
Definition: strlcat.c:44
decode_pop
int decode_pop(u_char *buf, int len, u_char *obuf, int olen)
Definition: decode_pop.c:44