File: decode_portmap.c

package info (click to toggle)
dsniff 2.4b1+debian-29
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 2,020 kB
  • sloc: ansic: 10,803; sh: 152; makefile: 126
file content (70 lines) | stat: -rw-r--r-- 1,591 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
63
64
65
66
67
68
69
70
/*
 * decode_portmap.c
 *
 * RPC portmap.
 *
 * Copyright (c) 2000 Dug Song <dugsong@monkey.org>
 *
 * $Id: decode_portmap.c,v 1.8 2001/03/15 08:33:02 dugsong Exp $
 */

#include "config.h"

#include <sys/types.h>
#include <rpc/rpc.h>
#include <rpc/pmap_prot.h>

#include <stdio.h>
#include <stdlib.h>
#include <libnet.h>
#include <nids.h>

#include "rpc.h"
#include "trigger.h"
#include "decode.h"

int
decode_portmap(u_char *buf, int len, u_char *obuf, int olen)
{
	XDR xdrs;
	struct rpc_msg msg;
	struct pmap *pm, pmap;
	struct xid_map *xm;
	int hdrlen;

	if ((hdrlen = rpc_decode(buf, len, &msg)) == 0)
		return (0);
	
	if (msg.rm_direction == CALL &&
	    msg.rm_call.cb_prog == PMAPPROG &&
	    msg.rm_call.cb_proc == PMAPPROC_GETPORT) {
		xdrmem_create(&xdrs, buf + hdrlen, len - hdrlen, XDR_DECODE);
		if (xdr_pmap(&xdrs, &pmap)) {
			if ((pm = malloc(sizeof(*pm))) != NULL) {
				*pm = pmap;
				xid_map_enter(msg.rm_xid, PMAPPROG, PMAPVERS,
					      PMAPPROC_GETPORT, (void *) pm);
			}
		}
		xdr_destroy(&xdrs);
	}
	else if (msg.rm_direction == REPLY &&
		 (xm = xid_map_find(msg.rm_xid)) != NULL) {
		if (msg.rm_reply.rp_stat == MSG_ACCEPTED &&
		    msg.acpted_rply.ar_stat == SUCCESS) {
			pm = (struct pmap *)xm->data;
			xdrmem_create(&xdrs, buf + hdrlen, len - hdrlen,
				      XDR_DECODE);
			if (xdr_u_long(&xdrs, &pm->pm_port)) {
				trigger_rpc(pm->pm_prog, pm->pm_prot,
					    pm->pm_port);
				trigger_rpc(pm->pm_prog, pm->pm_prot,
					    0 - (int) pm->pm_port);
			}
			xdr_destroy(&xdrs);
		}
		free(xm->data);
		memset(xm, 0, sizeof(*xm));
	}
	return (0);
}