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
decode_poppass(u_char * buf,int len,u_char * obuf,int olen)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
decode_pop(u_char * buf,int len,u_char * obuf,int olen)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
78