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_mountd.c
Go to the documentation of this file.
1 /*
2  * decode_mountd.c
3  *
4  * RPC mountd.
5  *
6  * Outputs filehandle in nfsshell format. :-)
7  *
8  * Copyright (c) 2000 Dug Song <dugsong@monkey.org>
9  *
10  * $Id: decode_mountd.c,v 1.7 2001/03/15 08:33:01 dugsong Exp $
11  */
12 
13 #include "config.h"
14 
15 #include <sys/param.h>
16 #include <sys/types.h>
17 #include <rpc/rpc.h>
18 
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
22 
23 #include "buf.h"
24 #include "mount.h"
25 #include "rpc.h"
26 #include "decode.h"
27 
28 int
29 decode_mountd(u_char *buf, int len, u_char *obuf, int olen)
30 {
31  XDR xdrs;
32  struct buf outbuf;
33  struct rpc_msg msg;
34  struct xid_map *xm;
35  struct fhstatus fhstat;
36  char *p, *dir;
37  int i, hdrlen;
38 
39  buf_init(&outbuf, obuf, olen);
40 
41  if ((hdrlen = rpc_decode(buf, len, &msg)) == 0)
42  return (0);
43 
44  if (msg.rm_direction == CALL &&
45  msg.rm_call.cb_prog == MOUNTPROG &&
46  msg.rm_call.cb_proc == MOUNTPROC_MNT) {
47  xdrmem_create(&xdrs, buf + hdrlen, len - hdrlen, XDR_DECODE);
48  dir = NULL;
49  if (xdr_string(&xdrs, &dir, MAXPATHLEN)) {
50  xid_map_enter(msg.rm_xid, MOUNTPROG, MOUNTVERS,
51  MOUNTPROC_MNT, (void *) dir);
52  }
53  xdr_destroy(&xdrs);
54  }
55  else if (msg.rm_direction == REPLY &&
56  (xm = xid_map_find(msg.rm_xid)) != NULL) {
57  if (msg.rm_reply.rp_stat == MSG_ACCEPTED &&
58  msg.acpted_rply.ar_stat == SUCCESS) {
59  xdrmem_create(&xdrs, buf + hdrlen, len - hdrlen,
60  XDR_DECODE);
61  if (xdr_fhstatus(&xdrs, &fhstat)) {
62  if (fhstat.fhs_status == 0) {
63  buf_putf(&outbuf, "%s [",
64  (char *)xm->data);
65 
66  p = fhstat.fhstatus_u.fhs_fhandle;
67 
68  for (i = 0; i < FHSIZE; i++) {
69  buf_putf(&outbuf, "%.2x ",
70  p[i] & 0xff);
71  }
72  buf_put(&outbuf, "]\n", 2);
73  }
74  }
75  xdr_destroy(&xdrs);
76  }
77  free(xm->data);
78  memset(xm, 0, sizeof(*xm));
79  }
80  buf_end(&outbuf);
81 
82  return (buf_len(&outbuf));
83 }
buf_putf
int buf_putf(buf_t buf, const char *fmt,...)
Definition: buf.c:106
xid_map
Definition: rpc.h:17
buf_init
void buf_init(buf_t buf, u_char *data, int len)
Definition: buf.c:24
xid_map_enter
void xid_map_enter(u_int32_t xid, u_int32_t prog, u_int32_t vers, u_int32_t proc, void *data)
Definition: rpc.c:30
buf_end
void buf_end(buf_t buf)
Definition: buf.c:121
buf_put
int buf_put(buf_t buf, void *src, int len)
Definition: buf.c:93
xid_map_find
struct xid_map * xid_map_find(int xid)
Definition: rpc.c:48
decode.h
buf.h
rpc.h
buf
Definition: buf.h:14
decode_mountd
int decode_mountd(u_char *buf, int len, u_char *obuf, int olen)
Definition: decode_mountd.c:29
xid_map::data
void * data
Definition: rpc.h:22
config.h
obuf
static char obuf[4096]
Definition: trigger.c:43
buf_len
#define buf_len(b)
Definition: buf.h:34
rpc_decode
int rpc_decode(u_char *buf, int len, struct rpc_msg *msg)
Definition: rpc.c:70