File: decode_nntp.c

package info (click to toggle)
dsniff 2.4b1%2Bdebian-29
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 2,020 kB
  • sloc: ansic: 10,803; sh: 152; makefile: 126
file content (62 lines) | stat: -rw-r--r-- 1,216 bytes parent folder | download | duplicates (7)
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
/*
 * decode_nntp.c
 *
 * Network News Transport Protocol.
 *
 * Copyright (c) 2000 Felix von Leitner <felix@convergence.de>
 * Copyright (c) 2000 Dug Song <dugsong@monkey.org>
 *
 * $Id: decode_nntp.c,v 1.5 2001/03/15 08:33:01 dugsong Exp $
 */

#include "config.h"

#include <sys/types.h>

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

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

int
decode_nntp(u_char *buf, int len, u_char *obuf, int olen)
{
	char *p;
	int i, simple, dpa;
	
	obuf[0] = '\0';
	simple = dpa = 0;
	
	for (p = strtok(buf, "\r\n"); p != NULL; p = strtok(NULL, "\r\n")) {
		if (simple == 1) {
			strlcat(obuf, p, olen);
			strlcat(obuf, "\n", olen);
			simple = 0;
		}			
		else if (strncasecmp(p, "AUTHINFO ", 9) == 0) {
			strlcat(obuf, p, olen);
			
			if (strncasecmp(p + 9, "SIMPLE", 6) == 0) {
				simple = 1;
			}
			else if (strncasecmp(p + 9, "GENERIC ", 8) == 0) {
				if (strncasecmp(p + 17, "DPA", 3) == 0) {
					dpa = 1;
				}
				else if (dpa == 1) {
					p += 17;
					i = base64_pton(p, p, strlen(p));
					p[i] = '\0';
					i = strlen(obuf);
					snprintf(obuf + i, olen - i,
						 " [%s]", p);
				}
			}
			strlcat(obuf, "\n", olen);
		}
	}
	return (strlen(obuf));
}