summaryrefslogtreecommitdiff
path: root/rpc.ypxfrd/ypxfrd_svc.c
blob: 8e66f941b696d7978406add568dac62bbb5c36e6 (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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/* Copyright (c) 1996, 1997, 1998, 1999, 2001, 2004, 2012, 2014, 2015 Thorsten Kukuk
   Author: Thorsten Kukuk <kukuk@suse.de>

   The YP Server is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public License
   version 2 as published by the Free Software Foundation.

   The YP Server is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public
   License along with the YP Server; see the file COPYING. If
   not, write to the Free Software Foundation, Inc., 51 Franklin Street,
   Suite 500, Boston, MA 02110-1335, USA. */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <stdio.h>
#include <stdlib.h>
#include <rpc/rpc.h>
#include <string.h>
#include <signal.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <memory.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <syslog.h>
#include <arpa/inet.h>
#include <rpcsvc/yp_prot.h>
#include "ypxfrd.h"
#include "log_msg.h"

#define _RPCSVC_CLOSEDOWN 120

extern int _rpcsvcdirty;	/* Still serving ? */

static
void _msgout(char* msg)
{
  log_msg ("%s", msg);
}

void
ypxfrd_freebsd_prog_1 (struct svc_req *rqstp, SVCXPRT *transp)
{
  union {
    ypxfr_mapname ypxfrd_getmap_1_arg;
  } argument;
  char *result;
  xdrproc_t xdr_argument, xdr_result;
  char *(*local)(char *, struct svc_req *);

  _rpcsvcdirty = 1;
  switch (rqstp->rq_proc)
    {
    case NULLPROC:
      svc_sendreply(transp, (xdrproc_t) xdr_void, NULL);
      _rpcsvcdirty = 0;
      return;

    case YPXFRD_GETMAP:
      xdr_argument = (xdrproc_t) xdr_ypxfr_mapname;
      xdr_result = (xdrproc_t) xdr_xfr;
      local = (char *(*)(char *, struct svc_req *)) ypxfrd_getmap_1_svc;
      break;

    default:
      svcerr_noproc(transp);
      _rpcsvcdirty = 0;
      return;
    }
  memset(&argument, 0, sizeof (argument));
  if (!svc_getargs(transp, xdr_argument, (caddr_t) &argument))
    {
      char namebuf6[INET6_ADDRSTRLEN];
      struct netconfig *nconf;
      const struct netbuf *nbuf = svc_getrpccaller (rqstp->rq_xprt);

      nconf = getnetconfigent (rqstp->rq_xprt->xp_netid);

      log_msg ("cannot decode arguments for %d from %s",
              rqstp->rq_proc, taddr2ipstr (nconf, nbuf,
					   namebuf6, sizeof (namebuf6)));
      /* try to free already allocated memory during decoding */
      svc_freeargs (transp, xdr_argument, (caddr_t) &argument);

      freenetconfigent (nconf);
      svcerr_decode(transp);
      _rpcsvcdirty = 0;
      return;
    }
  result = (*local)((char *)&argument, rqstp);
  if (result != NULL && !svc_sendreply (transp, xdr_result, result))
    svcerr_systemerr (transp);

  if (!svc_freeargs (transp, xdr_argument, (caddr_t) &argument))
    {
      _msgout ("unable to free arguments");
      exit (1);
    }
  _rpcsvcdirty = 0;
  return;
}