summaryrefslogtreecommitdiffstats
path: root/utils/statd/simu.c
blob: 7df04d9080abaf406c393a79f6dee7128e6c4b1a (plain)
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
/*
 * Copyright (C) 1995, 1997-1999 Jeffrey A. Uphoff
 *
 * NSM for Linux.
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <arpa/inet.h>

#include "rpcmisc.h"
#include "statd.h"
#include "notlist.h"

extern void my_svc_exit (void);


/*
 * Services SM_SIMU_CRASH requests.
 */
void *
sm_simu_crash_1_svc (void *argp, struct svc_req *rqstp)
{
  struct sockaddr_in *sin = nfs_getrpccaller_in(rqstp->rq_xprt);
  static char *result = NULL;
  struct in_addr caller;

  xlog(D_CALL, "Received SM_SIMU_CRASH");

  if (sin->sin_family != AF_INET) {
    xlog_warn("Call to statd from non-AF_INET address");
    goto failure;
  }

  caller = sin->sin_addr;
  if (caller.s_addr != htonl(INADDR_LOOPBACK)) {
    xlog_warn("Call to statd from non-local host %s",
      inet_ntoa(caller));
    goto failure;
  }

  if (ntohs(sin->sin_port) >= 1024) {
    xlog_warn("Call to statd-simu-crash from unprivileged port");
    goto failure;
  }

  xlog_warn("*** SIMULATING CRASH! ***");
  my_svc_exit ();

  if (rtnl)
    nlist_kill (&rtnl);

 failure:
  return ((void *)&result);
}