summaryrefslogtreecommitdiffstats
path: root/usr.sbin/portmap
diff options
context:
space:
mode:
Diffstat (limited to 'usr.sbin/portmap')
-rw-r--r--usr.sbin/portmap/Makefile13
-rw-r--r--usr.sbin/portmap/from_local.c233
-rw-r--r--usr.sbin/portmap/pmap_check.c263
-rw-r--r--usr.sbin/portmap/pmap_check.h41
-rw-r--r--usr.sbin/portmap/pmap_dump/Makefile7
-rw-r--r--usr.sbin/portmap/pmap_dump/pmap_dump.c69
-rw-r--r--usr.sbin/portmap/pmap_set/Makefile7
-rw-r--r--usr.sbin/portmap/pmap_set/pmap_set.c78
-rw-r--r--usr.sbin/portmap/portmap.8122
-rw-r--r--usr.sbin/portmap/portmap.c612
10 files changed, 0 insertions, 1445 deletions
diff --git a/usr.sbin/portmap/Makefile b/usr.sbin/portmap/Makefile
deleted file mode 100644
index b87cf59..0000000
--- a/usr.sbin/portmap/Makefile
+++ /dev/null
@@ -1,13 +0,0 @@
-# @(#)Makefile 8.1 (Berkeley) 6/6/93
-# $FreeBSD$
-
-PROG= portmap
-MAN8= portmap.8
-SRCS= portmap.c from_local.c pmap_check.c
-SUBDIR= pmap_set pmap_dump
-
-CFLAGS+=-DCHECK_PORT -DHOSTS_ACCESS
-DPADD= ${LIBWRAP}
-LDADD= -lwrap
-
-.include <bsd.prog.mk>
diff --git a/usr.sbin/portmap/from_local.c b/usr.sbin/portmap/from_local.c
deleted file mode 100644
index 9886f12..0000000
--- a/usr.sbin/portmap/from_local.c
+++ /dev/null
@@ -1,233 +0,0 @@
- /*
- * Check if an address belongs to the local system. Adapted from:
- *
- * @(#)pmap_svc.c 1.32 91/03/11 Copyright 1984,1990 Sun Microsystems, Inc.
- * @(#)get_myaddress.c 2.1 88/07/29 4.0 RPCSRC.
- */
-
-/*
- * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
- * unrestricted use provided that this legend is included on all tape
- * media and as a part of the software program in whole or part. Users
- * may copy or modify Sun RPC without charge, but are not authorized
- * to license or distribute it to anyone else except as part of a product or
- * program developed by the user or with the express written consent of
- * Sun Microsystems, Inc.
- *
- * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
- * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
- *
- * Sun RPC is provided with no support and without any obligation on the
- * part of Sun Microsystems, Inc. to assist in its use, correction,
- * modification or enhancement.
- *
- * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
- * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
- * OR ANY PART THEREOF.
- *
- * In no event will Sun Microsystems, Inc. be liable for any lost revenue
- * or profits or other special, indirect and consequential damages, even if
- * Sun has been advised of the possibility of such damages.
- *
- * Sun Microsystems, Inc.
- * 2550 Garcia Avenue
- * Mountain View, California 94043
- */
-
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#) from_local.c 1.2 93/11/16 21:50:02";
-#endif
-static const char rcsid[] =
- "$FreeBSD$";
-#endif
-
-#ifdef TEST
-#undef perror
-#endif
-
-#include <sys/types.h>
-#include <sys/ioctl.h>
-#include <sys/socket.h>
-#include <sys/sysctl.h>
-#include <sys/time.h>
-
-#include <netdb.h>
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <syslog.h>
-#include <unistd.h>
-
-#include <net/if.h>
-#include <net/if_dl.h>
-#include <net/route.h>
-#include <netinet/in.h>
-
-#include "pmap_check.h"
-
-#ifndef TRUE
-#define TRUE 1
-#define FALSE 0
-#endif
-
-#define ROUNDUP(x) ((x) ? (1 + (((x) - 1) | (sizeof(long) - 1))) : sizeof(long))
-
-/* How many interfaces could there be on a computer? */
-
-#define ESTIMATED_LOCAL 20
-static int num_local = -1;
-static struct in_addr *addrs;
-
-static void
-rtiparse(struct ifa_msghdr *ifam, struct rt_addrinfo *ai)
-{
- char *wp;
- int rtax;
-
- wp = (char *)(ifam + 1);
-
- ai->rti_addrs = ifam->ifam_addrs;
- for (rtax = 0; rtax < sizeof ai->rti_info / sizeof *ai->rti_info; rtax++)
- if (ifam->ifam_addrs & (1 << rtax)) {
- ai->rti_info[rtax] = (struct sockaddr *)wp;
- wp += ROUNDUP(ai->rti_info[rtax]->sa_len);
- } else
- ai->rti_info[rtax] = NULL;
-}
-
-/* find_local - find all IP addresses for this host */
-
-static int
-find_local()
-{
- int mib[6], n, s, alloced;
- size_t needed;
- char *buf, *end, *ptr;
- struct if_msghdr *ifm;
- struct ifa_msghdr *ifam;
- struct rt_addrinfo ai;
- struct ifreq ifr;
- struct sockaddr_dl *dl;
-
- mib[0] = CTL_NET;
- mib[1] = PF_ROUTE;
- mib[4] = NET_RT_IFLIST;
- mib[2] = mib[3] = mib[5] = 0;
-
- if ((s = socket(PF_INET, SOCK_DGRAM, 0)) < 0) {
- perror("socket");
- return (0);
- }
- if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0) {
- close(s);
- perror("sysctl(NET_RT_IFLIST)");
- return 0;
- }
- if ((buf = (char *)malloc(needed)) == NULL) {
- close(s);
- perror("malloc");
- return 0;
- }
- if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0) {
- close(s);
- free(buf);
- perror("sysctl(NET_RT_IFLIST)(after malloc)");
- return 0;
- }
-
- if (addrs) {
- free(addrs);
- addrs = NULL;
- }
- num_local = 0;
- alloced = 0;
- end = buf + needed;
-
- for (ptr = buf; ptr < end; ptr += ifm->ifm_msglen) {
- ifm = (struct if_msghdr *)ptr;
- dl = (struct sockaddr_dl *)(ifm + 1);
-
- if (ifm->ifm_index != dl->sdl_index || dl->sdl_nlen == 0)
- /* Skip over remaining ifa_msghdrs */
- continue;
-
- n = dl->sdl_nlen > sizeof ifr.ifr_name ?
- sizeof ifr.ifr_name : dl->sdl_nlen;
- strncpy(ifr.ifr_name, dl->sdl_data, n);
- if (n < sizeof ifr.ifr_name)
- ifr.ifr_name[n] = '\0';
-
- /* we only want the first address from each interface */
- if (ioctl(s, SIOCGIFFLAGS, &ifr) < 0)
- fprintf(stderr, "%.*s: SIOCGIFFLAGS: %s\n", n, ifr.ifr_name,
- strerror(errno));
- else if (ifr.ifr_flags & IFF_UP) { /* active interface */
- ifam = (struct ifa_msghdr *)(ptr + ifm->ifm_msglen);
- while ((char *)ifam < end && ifam->ifam_type == RTM_NEWADDR) {
- rtiparse(ifam, &ai);
-
- if (ai.rti_info[RTAX_IFA] != NULL &&
- ai.rti_info[RTAX_IFA]->sa_family == AF_INET) {
- if (alloced < num_local + 1) {
- alloced += ESTIMATED_LOCAL;
- addrs = (struct in_addr *)realloc(addrs, alloced * sizeof addrs[0]);
- if (addrs == NULL) {
- perror("malloc/realloc");
- num_local = 0;
- break;
- }
- }
- addrs[num_local++] = ((struct sockaddr_in *)
- ai.rti_info[RTAX_IFA])->sin_addr;
-
- }
- ifam = (struct ifa_msghdr *)((char *)ifam + ifam->ifam_msglen);
- }
- }
- }
- free(buf);
- close(s);
-
- return num_local;
-}
-
-/* from_local - determine whether request comes from the local system */
-
-int
-from_local(addr)
- struct sockaddr_in *addr;
-{
- int i;
-
- if (num_local == -1 && find_local() == 0)
- syslog(LOG_ERR, "cannot find any active local network interfaces");
-
- for (i = 0; i < num_local; i++) {
- if (memcmp((char *) &(addr->sin_addr), (char *) &(addrs[i]),
- sizeof(struct in_addr)) == 0)
- return (TRUE);
- }
- return (FALSE);
-}
-
-#ifdef TEST
-
-int
-main(argc, argv)
- int argc;
- char **argv;
-{
- char *inet_ntoa();
- int i;
-
- find_local();
- for (i = 0; i < num_local; i++)
- printf("%s\n", inet_ntoa(addrs[i]));
-
- return 0;
-}
-
-#endif
diff --git a/usr.sbin/portmap/pmap_check.c b/usr.sbin/portmap/pmap_check.c
deleted file mode 100644
index 7ad25c9..0000000
--- a/usr.sbin/portmap/pmap_check.c
+++ /dev/null
@@ -1,263 +0,0 @@
- /*
- * pmap_check - additional portmap security.
- *
- * Always reject non-local requests to update the portmapper tables.
- *
- * Refuse to forward mount requests to the nfs mount daemon. Otherwise, the
- * requests would appear to come from the local system, and nfs export
- * restrictions could be bypassed.
- *
- * Refuse to forward requests to the nfsd process.
- *
- * Refuse to forward requests to NIS (YP) daemons; The only exception is the
- * YPPROC_DOMAIN_NONACK broadcast rpc call that is used to establish initial
- * contact with the NIS server.
- *
- * Always allocate an unprivileged port when forwarding a request.
- *
- * If compiled with -DCHECK_PORT, require that requests to register or
- * unregister a privileged port come from a privileged port. This makes it
- * more difficult to replace a critical service by a trojan.
- *
- * If compiled with -DHOSTS_ACCESS, reject requests from hosts that are not
- * authorized by the /etc/hosts.{allow,deny} files. The local system is
- * always treated as an authorized host. The access control tables are never
- * consulted for requests from the local system, and are always consulted
- * for requests from other hosts. Access control is based on IP addresses
- * only; attempts to map an address to a host name might cause the
- * portmapper to hang.
- *
- * Author: Wietse Venema (wietse@wzv.win.tue.nl), dept. of Mathematics and
- * Computing Science, Eindhoven University of Technology, The Netherlands.
- */
-
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#) pmap_check.c 1.6 93/11/21 20:58:59";
-#endif
-static const char rcsid[] =
- "$FreeBSD$";
-#endif
-
-#include <stdio.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-
-#include <rpc/rpc.h>
-#include <rpc/pmap_prot.h>
-#include <syslog.h>
-#include <netdb.h>
-#include <sys/signal.h>
-
-#include "pmap_check.h"
-
-/* Explicit #defines in case the include files are not available. */
-
-#define NFSPROG ((u_long) 100003)
-#define MOUNTPROG ((u_long) 100005)
-#define YPXPROG ((u_long) 100069)
-#define YPPROG ((u_long) 100004)
-#define YPPROC_DOMAIN_NONACK ((u_long) 2)
-#define MOUNTPROC_MNT ((u_long) 1)
-
-static void logit __P((int, struct sockaddr_in *, u_long, u_long, const char *));
-static void toggle_verboselog __P((int));
-
-int verboselog = 0;
-int allow_severity = LOG_INFO;
-int deny_severity = LOG_WARNING;
-
-/* A handful of macros for "readability". */
-
-#define good_client(a) hosts_ctl("portmap", "", inet_ntoa(a->sin_addr), "")
-
-#define legal_port(a,p) \
- (ntohs((a)->sin_port) < IPPORT_RESERVED || (p) >= IPPORT_RESERVED)
-
-#define log_bad_port(addr, proc, prog) \
- logit(deny_severity, addr, proc, prog, ": request from unprivileged port")
-
-#define log_bad_host(addr, proc, prog) \
- logit(deny_severity, addr, proc, prog, ": request from unauthorized host")
-
-#define log_bad_owner(addr, proc, prog) \
- logit(deny_severity, addr, proc, prog, ": request from non-local host")
-
-#define log_no_forward(addr, proc, prog) \
- logit(deny_severity, addr, proc, prog, ": request not forwarded")
-
-#define log_client(addr, proc, prog) \
- logit(allow_severity, addr, proc, prog, "")
-
-/* check_startup - additional startup code */
-
-void
-check_startup()
-{
-
- /*
- * Give up root privileges so that we can never allocate a privileged
- * port when forwarding an rpc request.
- */
- if (setuid(1) == -1) {
- syslog(LOG_ERR, "setuid(1) failed: %m");
- exit(1);
- }
- (void) signal(SIGINT, toggle_verboselog);
-}
-
-/* check_default - additional checks for NULL, DUMP, GETPORT and unknown */
-
-int
-check_default(addr, proc, prog)
- struct sockaddr_in *addr;
- u_long proc, prog;
-{
-#ifdef HOSTS_ACCESS
- if (!(from_local(addr) || good_client(addr))) {
- log_bad_host(addr, proc, prog);
- return (FALSE);
- }
-#endif
- if (verboselog)
- log_client(addr, proc, prog);
- return (TRUE);
-}
-
-/* check_privileged_port - additional checks for privileged-port updates */
-
-int
-check_privileged_port(addr, proc, prog, port)
- struct sockaddr_in *addr;
- u_long proc, prog, port;
-{
-#ifdef CHECK_PORT
- if (!legal_port(addr, port)) {
- log_bad_port(addr, proc, prog);
- return (FALSE);
- }
-#endif
- return (TRUE);
-}
-
-/* check_setunset - additional checks for update requests */
-
-int
-check_setunset(addr, proc, prog, port)
- struct sockaddr_in *addr;
- u_long proc, prog, port;
-{
- if (!from_local(addr)) {
-#ifdef HOSTS_ACCESS
- (void) good_client(addr); /* because of side effects */
-#endif
- log_bad_owner(addr, proc, prog);
- return (FALSE);
- }
- if (port && !check_privileged_port(addr, proc, prog, port))
- return (FALSE);
- if (verboselog)
- log_client(addr, proc, prog);
- return (TRUE);
-}
-
-/* check_callit - additional checks for forwarded requests */
-
-int
-check_callit(addr, proc, prog, aproc)
- struct sockaddr_in *addr;
- u_long proc, prog, aproc;
-{
-#ifdef HOSTS_ACCESS
- if (!(from_local(addr) || good_client(addr))) {
- log_bad_host(addr, proc, prog);
- return (FALSE);
- }
-#endif
- if (prog == PMAPPROG || prog == NFSPROG || prog == YPXPROG ||
- (prog == MOUNTPROG && aproc == MOUNTPROC_MNT) ||
- (prog == YPPROG && aproc != YPPROC_DOMAIN_NONACK)) {
- log_no_forward(addr, proc, prog);
- return (FALSE);
- }
- if (verboselog)
- log_client(addr, proc, prog);
- return (TRUE);
-}
-
-/* toggle_verboselog - toggle verbose logging flag */
-
-static void
-toggle_verboselog(sig)
- int sig;
-{
- (void) signal(sig, toggle_verboselog);
- verboselog = !verboselog;
-}
-
-/* logit - report events of interest via the syslog daemon */
-
-static void
-logit(severity, addr, procnum, prognum, text)
- int severity;
- struct sockaddr_in *addr;
- u_long procnum, prognum;
- const char *text;
-{
- const char *procname;
- char procbuf[4 * sizeof(u_long)];
- const char *progname;
- char progbuf[4 * sizeof(u_long)];
- struct rpcent *rpc;
- struct proc_map {
- u_long code;
- const char *proc;
- };
- struct proc_map *procp;
- static struct proc_map procmap[] = {
- {PMAPPROC_CALLIT, "callit"},
- {PMAPPROC_DUMP, "dump"},
- {PMAPPROC_GETPORT, "getport"},
- {PMAPPROC_NULL, "null"},
- {PMAPPROC_SET, "set"},
- {PMAPPROC_UNSET, "unset"},
- {0, 0},
- };
-
- /*
- * Fork off a process or the portmap daemon might hang while
- * getrpcbynumber() or syslog() does its thing.
- */
-
- if (fork() == 0) {
-
- /* Try to map program number to name. */
-
- if (prognum == 0) {
- progname = "";
- } else if ((rpc = getrpcbynumber((int) prognum))) {
- progname = rpc->r_name;
- } else {
- sprintf(progbuf, "%lu", prognum);
- progname = progbuf;
- }
-
- /* Try to map procedure number to name. */
-
- for (procp = procmap; procp->proc && procp->code != procnum; procp++)
- /* void */ ;
- if ((procname = procp->proc) == 0) {
- sprintf(procbuf, "%lu", (u_long) procnum);
- procname = procbuf;
- }
-
- /* Write syslog record. */
-
- syslog(severity, "connect from %s to %s(%s)%s",
- inet_ntoa(addr->sin_addr), procname, progname, text);
- exit(0);
- }
-}
diff --git a/usr.sbin/portmap/pmap_check.h b/usr.sbin/portmap/pmap_check.h
deleted file mode 100644
index dc454a5..0000000
--- a/usr.sbin/portmap/pmap_check.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/*-
- * Copyright (c) 2000 Brian Somers <brian@Awfulhak.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#) pmap_check.h 1.3 93/11/21 16:18:53
- *
- * $FreeBSD$
- */
-
-extern int from_local __P((struct sockaddr_in *));
-extern void check_startup __P((void));
-extern int check_default __P((struct sockaddr_in *, u_long, u_long));
-extern int check_setunset __P((struct sockaddr_in *, u_long, u_long, u_long));
-extern int check_privileged_port __P((struct sockaddr_in *, u_long, u_long,
- u_long));
-extern int check_callit __P((struct sockaddr_in *, u_long, u_long, u_long));
-
-extern int verboselog;
-extern int allow_severity;
-extern int deny_severity;
diff --git a/usr.sbin/portmap/pmap_dump/Makefile b/usr.sbin/portmap/pmap_dump/Makefile
deleted file mode 100644
index 0064f28..0000000
--- a/usr.sbin/portmap/pmap_dump/Makefile
+++ /dev/null
@@ -1,7 +0,0 @@
-# @(#)Makefile 8.1 (Berkeley) 6/6/93
-
-PROG= pmap_dump
-NOMAN= noman
-
-.include "${.CURDIR}/../../Makefile.inc"
-.include <bsd.prog.mk>
diff --git a/usr.sbin/portmap/pmap_dump/pmap_dump.c b/usr.sbin/portmap/pmap_dump/pmap_dump.c
deleted file mode 100644
index 96fb5c2..0000000
--- a/usr.sbin/portmap/pmap_dump/pmap_dump.c
+++ /dev/null
@@ -1,69 +0,0 @@
- /*
- * pmap_dump - dump portmapper table in format readable by pmap_set
- *
- * Author: Wietse Venema (wietse@wzv.win.tue.nl), dept. of Mathematics and
- * Computing Science, Eindhoven University of Technology, The Netherlands.
- */
-
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#) pmap_dump.c 1.1 92/06/11 22:53:15";
-#endif
-static const char rcsid[] =
- "$FreeBSD$";
-#endif
-
-#include <stdio.h>
-#include <sys/types.h>
-#ifdef SYSV40
-#include <netinet/in.h>
-#include <rpc/rpcent.h>
-#else
-#include <netdb.h>
-#endif
-#include <rpc/rpc.h>
-#include <rpc/pmap_clnt.h>
-#include <rpc/pmap_prot.h>
-
-static const char *protoname __P((u_long));
-
-int
-main(argc, argv)
- int argc;
- char **argv;
-{
- struct sockaddr_in addr;
- register struct pmaplist *list;
- register struct rpcent *rpc;
-
- get_myaddress(&addr);
-
- for (list = pmap_getmaps(&addr); list; list = list->pml_next) {
- rpc = getrpcbynumber((int) list->pml_map.pm_prog);
- printf("%10lu %4lu %5s %6lu %s\n",
- list->pml_map.pm_prog,
- list->pml_map.pm_vers,
- protoname(list->pml_map.pm_prot),
- list->pml_map.pm_port,
- rpc ? rpc->r_name : "");
- }
-#undef perror
- return (fclose(stdout) ? (perror(argv[0]), 1) : 0);
-}
-
-static const char *
-protoname(proto)
- u_long proto;
-{
- static char buf[BUFSIZ];
-
- switch (proto) {
- case IPPROTO_UDP:
- return ("udp");
- case IPPROTO_TCP:
- return ("tcp");
- default:
- sprintf(buf, "%lu", proto);
- return (buf);
- }
-}
diff --git a/usr.sbin/portmap/pmap_set/Makefile b/usr.sbin/portmap/pmap_set/Makefile
deleted file mode 100644
index 987e320..0000000
--- a/usr.sbin/portmap/pmap_set/Makefile
+++ /dev/null
@@ -1,7 +0,0 @@
-# @(#)Makefile 8.1 (Berkeley) 6/6/93
-
-PROG= pmap_set
-NOMAN= noman
-
-.include "${.CURDIR}/../../Makefile.inc"
-.include <bsd.prog.mk>
diff --git a/usr.sbin/portmap/pmap_set/pmap_set.c b/usr.sbin/portmap/pmap_set/pmap_set.c
deleted file mode 100644
index 35a7fbe..0000000
--- a/usr.sbin/portmap/pmap_set/pmap_set.c
+++ /dev/null
@@ -1,78 +0,0 @@
- /*
- * pmap_set - set portmapper table from data produced by pmap_dump
- *
- * Author: Wietse Venema (wietse@wzv.win.tue.nl), dept. of Mathematics and
- * Computing Science, Eindhoven University of Technology, The Netherlands.
- */
-
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#) pmap_set.c 1.1 92/06/11 22:53:16";
-#endif
-static const char rcsid[] =
- "$FreeBSD$";
-#endif
-
-#include <err.h>
-#include <stdio.h>
-#include <sys/types.h>
-#ifdef SYSV40
-#include <netinet/in.h>
-#endif
-#include <rpc/rpc.h>
-#include <rpc/pmap_clnt.h>
-
-static int parse_line __P((char *, u_long *, u_long *, int *, unsigned *));
-
-int
-main(argc, argv)
- int argc;
- char **argv;
-{
- struct sockaddr_in addr;
- char buf[BUFSIZ];
- u_long prog;
- u_long vers;
- int prot;
- unsigned port;
-
- get_myaddress(&addr);
-
- while (fgets(buf, sizeof(buf), stdin)) {
- if (parse_line(buf, &prog, &vers, &prot, &port) == 0) {
- warnx("malformed line: %s", buf);
- return (1);
- }
- if (pmap_set(prog, vers, prot, (unsigned short) port) == 0)
- warnx("not registered: %s", buf);
- }
- return (0);
-}
-
-/* parse_line - convert line to numbers */
-
-static int
-parse_line(buf, prog, vers, prot, port)
- char *buf;
- u_long *prog, *vers;
- int *prot;
- unsigned *port;
-{
- char proto_name[BUFSIZ];
-
- if (sscanf(buf, "%lu %lu %s %u", prog, vers, proto_name, port) != 4) {
- return (0);
- }
- if (strcmp(proto_name, "tcp") == 0) {
- *prot = IPPROTO_TCP;
- return (1);
- }
- if (strcmp(proto_name, "udp") == 0) {
- *prot = IPPROTO_UDP;
- return (1);
- }
- if (sscanf(proto_name, "%d", prot) == 1) {
- return (1);
- }
- return (0);
-}
diff --git a/usr.sbin/portmap/portmap.8 b/usr.sbin/portmap/portmap.8
deleted file mode 100644
index 455ccbd..0000000
--- a/usr.sbin/portmap/portmap.8
+++ /dev/null
@@ -1,122 +0,0 @@
-.\" Copyright (c) 1987 Sun Microsystems
-.\" Copyright (c) 1990, 1991, 1993
-.\" The Regents of the University of California. All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\" notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\" notice, this list of conditions and the following disclaimer in the
-.\" documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\" must display the following acknowledgement:
-.\" This product includes software developed by the University of
-.\" California, Berkeley and its contributors.
-.\" 4. Neither the name of the University nor the names of its contributors
-.\" may be used to endorse or promote products derived from this software
-.\" without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" @(#)portmap.8 8.1 (Berkeley) 6/6/93
-.\" $FreeBSD$
-.\"
-.Dd June 6, 1993
-.Dt PORTMAP 8
-.Os BSD 4.3
-.Sh NAME
-.Nm portmap
-.Nd
-.Tn RPC
-program,version
-to
-.Tn DARPA
-port mapper
-.Sh SYNOPSIS
-.Nm
-.Op Fl d
-.Op Fl v
-.Sh DESCRIPTION
-.Nm Portmap
-is a server that converts
-.Tn RPC
-program numbers into
-.Tn DARPA
-protocol port numbers.
-It must be running in order to make
-.Tn RPC
-calls.
-.Pp
-When an
-.Tn RPC
-server is started, it will tell
-.Nm
-what port number it is listening to, and what
-.Tn RPC
-program numbers it is prepared to serve.
-When a client wishes to make an
-.Tn RPC
-call to a given program number,
-it will first contact
-.Nm
-on the server machine to determine
-the port number where
-.Tn RPC
-packets should be sent.
-.Pp
-.Nm Portmap
-must be started before any
-.Tn RPC
-servers are invoked.
-.Pp
-.Nm Portmap
-uses
-.Xr hosts_access 5
-access control by default.
-Access control patterns may only reference IP addresses.
-.Pp
-Normally
-.Nm
-forks and dissociates itself from the terminal
-like any other daemon.
-.Nm Portmap
-then logs errors using
-.Xr syslog 3 .
-.Pp
-The following options are available:
-.Bl -tag -width indent
-.It Fl d
-Prevent
-.Nm
-from running as a daemon,
-and causes errors and debugging information
-to be printed to the standard error output.
-.It Fl v
-Enable verbose logging of access control checks.
-.El
-.Sh SEE ALSO
-.Xr hosts_access 5 ,
-.Xr inetd.conf 5 ,
-.Xr inetd 8 ,
-.Xr rpcinfo 8
-.Sh BUGS
-If
-.Nm
-crashes, all servers must be restarted.
-.Sh HISTORY
-The
-.Nm
-command appeared in
-.Bx 4.3
diff --git a/usr.sbin/portmap/portmap.c b/usr.sbin/portmap/portmap.c
deleted file mode 100644
index 658b53c..0000000
--- a/usr.sbin/portmap/portmap.c
+++ /dev/null
@@ -1,612 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#ifndef lint
-static const char copyright[] =
-"@(#) Copyright (c) 1990, 1993\n\
- The Regents of the University of California. All rights reserved.\n";
-#endif /* not lint */
-
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)portmap.c 8.1 (Berkeley) 6/6/93";
-#endif
-static const char rcsid[] =
- "$FreeBSD$";
-#endif /* not lint */
-
-/*
-@(#)portmap.c 2.3 88/08/11 4.0 RPCSRC
-static char sccsid[] = "@(#)portmap.c 1.32 87/08/06 Copyr 1984 Sun Micro";
-*/
-
-/*
- * portmap.c, Implements the program,version to port number mapping for
- * rpc.
- */
-
-/*
- * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
- * unrestricted use provided that this legend is included on all tape
- * media and as a part of the software program in whole or part. Users
- * may copy or modify Sun RPC without charge, but are not authorized
- * to license or distribute it to anyone else except as part of a product or
- * program developed by the user.
- *
- * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
- * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
- *
- * Sun RPC is provided with no support and without any obligation on the
- * part of Sun Microsystems, Inc. to assist in its use, correction,
- * modification or enhancement.
- *
- * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
- * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
- * OR ANY PART THEREOF.
- *
- * In no event will Sun Microsystems, Inc. be liable for any lost revenue
- * or profits or other special, indirect and consequential damages, even if
- * Sun has been advised of the possibility of such damages.
- *
- * Sun Microsystems, Inc.
- * 2550 Garcia Avenue
- * Mountain View, California 94043
- */
-
-#include <err.h>
-#include <errno.h>
-#include <netdb.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <syslog.h>
-#include <unistd.h>
-#include <rpc/rpc.h>
-#include <rpc/pmap_prot.h>
-#include <sys/socket.h>
-#include <sys/ioctl.h>
-#include <sys/wait.h>
-#include <sys/signal.h>
-#include <sys/resource.h>
-
-#include "pmap_check.h"
-
-static void reg_service __P((struct svc_req *, SVCXPRT *));
-static void reap __P((int));
-static void callit __P((struct svc_req *, SVCXPRT *));
-static void usage __P((void));
-
-struct pmaplist *pmaplist;
-int debugging = 0;
-
-int
-main(argc, argv)
- int argc;
- char **argv;
-{
- SVCXPRT *xprt;
- int sock, c;
- struct sockaddr_in addr;
- int len = sizeof(struct sockaddr_in);
- register struct pmaplist *pml;
-
- while ((c = getopt(argc, argv, "dv")) != -1) {
- switch (c) {
-
- case 'd':
- debugging = 1;
- break;
-
- case 'v':
- verboselog = 1;
- break;
-
- default:
- usage();
- }
- }
-
- if (!debugging && daemon(0, 0))
- err(1, "fork");
-
- openlog("portmap", debugging ? LOG_PID | LOG_PERROR : LOG_PID,
- LOG_DAEMON);
-
- if ((sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
- syslog(LOG_ERR, "cannot create udp socket: %m");
- exit(1);
- }
-
- addr.sin_addr.s_addr = 0;
- addr.sin_family = AF_INET;
- addr.sin_port = htons(PMAPPORT);
- if (bind(sock, (struct sockaddr *)&addr, len) != 0) {
- syslog(LOG_ERR, "cannot bind udp: %m");
- exit(1);
- }
-
- if ((xprt = svcudp_create(sock)) == (SVCXPRT *)NULL) {
- syslog(LOG_ERR, "couldn't do udp_create");
- exit(1);
- }
- /* make an entry for ourself */
- pml = (struct pmaplist *)malloc((u_int)sizeof(struct pmaplist));
- pml->pml_next = 0;
- pml->pml_map.pm_prog = PMAPPROG;
- pml->pml_map.pm_vers = PMAPVERS;
- pml->pml_map.pm_prot = IPPROTO_UDP;
- pml->pml_map.pm_port = PMAPPORT;
- pmaplist = pml;
-
- if ((sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
- syslog(LOG_ERR, "cannot create tcp socket: %m");
- exit(1);
- }
- if (bind(sock, (struct sockaddr *)&addr, len) != 0) {
- syslog(LOG_ERR, "cannot bind tcp: %m");
- exit(1);
- }
- if ((xprt = svctcp_create(sock, RPCSMALLMSGSIZE, RPCSMALLMSGSIZE))
- == (SVCXPRT *)NULL) {
- syslog(LOG_ERR, "couldn't do tcp_create");
- exit(1);
- }
- /* make an entry for ourself */
- pml = (struct pmaplist *)malloc((u_int)sizeof(struct pmaplist));
- pml->pml_map.pm_prog = PMAPPROG;
- pml->pml_map.pm_vers = PMAPVERS;
- pml->pml_map.pm_prot = IPPROTO_TCP;
- pml->pml_map.pm_port = PMAPPORT;
- pml->pml_next = pmaplist;
- pmaplist = pml;
-
- (void)svc_register(xprt, PMAPPROG, PMAPVERS, reg_service, FALSE);
-
- /* additional initializations */
- check_startup();
- (void)signal(SIGCHLD, reap);
- svc_run();
- syslog(LOG_ERR, "svc_run returned unexpectedly");
- abort();
-}
-
-static void
-usage()
-{
- fprintf(stderr, "usage: portmap [-dv]\n");
- exit(1);
-}
-
-#ifndef lint
-/* need to override perror calls in rpc library */
-void
-perror(what)
- const char *what;
-{
- syslog(LOG_ERR, "%s: %m", what);
-}
-#endif
-
-static struct pmaplist *
-find_service(prog, vers, prot)
- u_long prog, vers, prot;
-{
- register struct pmaplist *hit = NULL;
- register struct pmaplist *pml;
-
- for (pml = pmaplist; pml != NULL; pml = pml->pml_next) {
- if ((pml->pml_map.pm_prog != prog) ||
- (pml->pml_map.pm_prot != prot))
- continue;
- hit = pml;
- if (pml->pml_map.pm_vers == vers)
- break;
- }
- return (hit);
-}
-
-/*
- * 1 OK, 0 not
- */
-static void
-reg_service(rqstp, xprt)
- struct svc_req *rqstp;
- SVCXPRT *xprt;
-{
- struct pmap reg;
- struct pmaplist *pml, *prevpml, *fnd;
- int ans, port;
- caddr_t t;
-
- /*
- * Later wrappers change the logging severity on the fly. Reset to
- * defaults before handling the next request.
- */
- allow_severity = LOG_INFO;
- deny_severity = LOG_WARNING;
-
- if (debugging)
- (void) fprintf(stderr, "server: about to do a switch\n");
- switch (rqstp->rq_proc) {
-
- case PMAPPROC_NULL:
- /*
- * Null proc call
- */
- /* remote host authorization check */
- check_default(svc_getcaller(xprt), rqstp->rq_proc, (u_long) 0);
- if (!svc_sendreply(xprt, xdr_void, (caddr_t)0) && debugging) {
- abort();
- }
- break;
-
- case PMAPPROC_SET:
- /*
- * Set a program,version to port mapping
- */
- if (!svc_getargs(xprt, xdr_pmap, (caddr_t)&reg))
- svcerr_decode(xprt);
- else {
- /* reject non-local requests, protect priv. ports */
- if (!check_setunset(svc_getcaller(xprt),
- rqstp->rq_proc, reg.pm_prog, reg.pm_port)) {
- ans = 0;
- goto done;
- }
- /*
- * check to see if already used
- * find_service returns a hit even if
- * the versions don't match, so check for it
- */
- fnd = find_service(reg.pm_prog, reg.pm_vers, reg.pm_prot);
- if (fnd && fnd->pml_map.pm_vers == reg.pm_vers) {
- if (fnd->pml_map.pm_port == reg.pm_port) {
- ans = 1;
- goto done;
- }
- else {
- ans = 0;
- goto done;
- }
- } else {
- /*
- * add to END of list
- */
- pml = (struct pmaplist *)
- malloc((u_int)sizeof(struct pmaplist));
- pml->pml_map = reg;
- pml->pml_next = 0;
- if (pmaplist == 0) {
- pmaplist = pml;
- } else {
- for (fnd= pmaplist; fnd->pml_next != 0;
- fnd = fnd->pml_next);
- fnd->pml_next = pml;
- }
- ans = 1;
- }
- done:
- if ((!svc_sendreply(xprt, xdr_long, (caddr_t)&ans)) &&
- debugging) {
- (void) fprintf(stderr, "svc_sendreply\n");
- abort();
- }
- }
- break;
-
- case PMAPPROC_UNSET:
- /*
- * Remove a program,version to port mapping.
- */
- if (!svc_getargs(xprt, xdr_pmap, (caddr_t)&reg))
- svcerr_decode(xprt);
- else {
- ans = 0;
- /* reject non-local requests */
- if (!check_setunset(svc_getcaller(xprt),
- rqstp->rq_proc, reg.pm_prog, (u_long) 0))
- goto done;
- for (prevpml = NULL, pml = pmaplist; pml != NULL; ) {
- if ((pml->pml_map.pm_prog != reg.pm_prog) ||
- (pml->pml_map.pm_vers != reg.pm_vers)) {
- /* both pml & prevpml move forwards */
- prevpml = pml;
- pml = pml->pml_next;
- continue;
- }
- /* found it; pml moves forward, prevpml stays */
- /* privileged port check */
- if (!check_privileged_port(svc_getcaller(xprt),
- rqstp->rq_proc,
- reg.pm_prog,
- pml->pml_map.pm_port)) {
- ans = 0;
- break;
- }
- ans = 1;
- t = (caddr_t)pml;
- pml = pml->pml_next;
- if (prevpml == NULL)
- pmaplist = pml;
- else
- prevpml->pml_next = pml;
- free(t);
- }
- if ((!svc_sendreply(xprt, xdr_long, (caddr_t)&ans)) &&
- debugging) {
- (void) fprintf(stderr, "svc_sendreply\n");
- abort();
- }
- }
- break;
-
- case PMAPPROC_GETPORT:
- /*
- * Lookup the mapping for a program,version and return its port
- */
- if (!svc_getargs(xprt, xdr_pmap, (caddr_t)&reg))
- svcerr_decode(xprt);
- else {
- /* remote host authorization check */
- if (!check_default(svc_getcaller(xprt),
- rqstp->rq_proc,
- reg.pm_prog)) {
- ans = 0;
- goto done;
- }
- fnd = find_service(reg.pm_prog, reg.pm_vers, reg.pm_prot);
- if (fnd)
- port = fnd->pml_map.pm_port;
- else
- port = 0;
- if ((!svc_sendreply(xprt, xdr_long, (caddr_t)&port)) &&
- debugging) {
- (void) fprintf(stderr, "svc_sendreply\n");
- abort();
- }
- }
- break;
-
- case PMAPPROC_DUMP:
- /*
- * Return the current set of mapped program,version
- */
- if (!svc_getargs(xprt, xdr_void, NULL))
- svcerr_decode(xprt);
- else {
- /* remote host authorization check */
- struct pmaplist *p;
- if (!check_default(svc_getcaller(xprt),
- rqstp->rq_proc, (u_long) 0)) {
- p = 0; /* send empty list */
- } else {
- p = pmaplist;
- }
- if ((!svc_sendreply(xprt, xdr_pmaplist,
- (caddr_t)&p)) && debugging) {
- (void) fprintf(stderr, "svc_sendreply\n");
- abort();
- }
- }
- break;
-
- case PMAPPROC_CALLIT:
- /*
- * Calls a procedure on the local machine. If the requested
- * procedure is not registered this procedure does not return
- * error information!!
- * This procedure is only supported on rpc/udp and calls via
- * rpc/udp. It passes null authentication parameters.
- */
- callit(rqstp, xprt);
- break;
-
- default:
- /* remote host authorization check */
- check_default(svc_getcaller(xprt), rqstp->rq_proc, (u_long) 0);
- svcerr_noproc(xprt);
- break;
- }
-}
-
-
-/*
- * Stuff for the rmtcall service
- */
-#define ARGSIZE 9000
-
-struct encap_parms {
- u_int arglen;
- char *args;
-};
-
-static bool_t
-xdr_encap_parms(xdrs, epp)
- XDR *xdrs;
- struct encap_parms *epp;
-{
-
- return (xdr_bytes(xdrs, &(epp->args), &(epp->arglen), ARGSIZE));
-}
-
-struct rmtcallargs {
- u_long rmt_prog;
- u_long rmt_vers;
- u_long rmt_port;
- u_long rmt_proc;
- struct encap_parms rmt_args;
-};
-
-static bool_t
-xdr_rmtcall_args(xdrs, cap)
- XDR *xdrs;
- struct rmtcallargs *cap;
-{
-
- /* does not get a port number */
- if (xdr_u_long(xdrs, &(cap->rmt_prog)) &&
- xdr_u_long(xdrs, &(cap->rmt_vers)) &&
- xdr_u_long(xdrs, &(cap->rmt_proc))) {
- return (xdr_encap_parms(xdrs, &(cap->rmt_args)));
- }
- return (FALSE);
-}
-
-static bool_t
-xdr_rmtcall_result(xdrs, cap)
- XDR *xdrs;
- struct rmtcallargs *cap;
-{
- if (xdr_u_long(xdrs, &(cap->rmt_port)))
- return (xdr_encap_parms(xdrs, &(cap->rmt_args)));
- return (FALSE);
-}
-
-/*
- * only worries about the struct encap_parms part of struct rmtcallargs.
- * The arglen must already be set!!
- */
-static bool_t
-xdr_opaque_parms(xdrs, cap)
- XDR *xdrs;
- struct rmtcallargs *cap;
-{
- return (xdr_opaque(xdrs, cap->rmt_args.args, cap->rmt_args.arglen));
-}
-
-/*
- * This routine finds and sets the length of incoming opaque paraters
- * and then calls xdr_opaque_parms.
- */
-static bool_t
-xdr_len_opaque_parms(xdrs, cap)
- XDR *xdrs;
- struct rmtcallargs *cap;
-{
- register u_int beginpos, lowpos, highpos, currpos, pos;
-
- beginpos = lowpos = pos = xdr_getpos(xdrs);
- highpos = lowpos + ARGSIZE;
- while ((int)(highpos - lowpos) >= 0) {
- currpos = (lowpos + highpos) / 2;
- if (xdr_setpos(xdrs, currpos)) {
- pos = currpos;
- lowpos = currpos + 1;
- } else {
- highpos = currpos - 1;
- }
- }
- xdr_setpos(xdrs, beginpos);
- cap->rmt_args.arglen = pos - beginpos;
- return (xdr_opaque_parms(xdrs, cap));
-}
-
-/*
- * Call a remote procedure service
- * This procedure is very quiet when things go wrong.
- * The proc is written to support broadcast rpc. In the broadcast case,
- * a machine should shut-up instead of complain, less the requestor be
- * overrun with complaints at the expense of not hearing a valid reply ...
- *
- * This now forks so that the program & process that it calls can call
- * back to the portmapper.
- */
-static void
-callit(rqstp, xprt)
- struct svc_req *rqstp;
- SVCXPRT *xprt;
-{
- struct rmtcallargs a;
- struct pmaplist *pml;
- u_short port;
- struct sockaddr_in me;
- int pid, so = -1;
- CLIENT *client;
- struct authunix_parms *au = (struct authunix_parms *)rqstp->rq_clntcred;
- struct timeval timeout;
- char buf[ARGSIZE];
-
- timeout.tv_sec = 5;
- timeout.tv_usec = 0;
- a.rmt_args.args = buf;
- if (!svc_getargs(xprt, xdr_rmtcall_args, (caddr_t)&a))
- return;
- /* host and service access control */
- if (!check_callit(svc_getcaller(xprt),
- rqstp->rq_proc, a.rmt_prog, a.rmt_proc))
- return;
- if ((pml = find_service(a.rmt_prog, a.rmt_vers,
- (u_long)IPPROTO_UDP)) == NULL)
- return;
- /*
- * fork a child to do the work. Parent immediately returns.
- * Child exits upon completion.
- */
- if ((pid = fork()) != 0) {
- if (pid < 0)
- syslog(LOG_ERR, "CALLIT (prog %lu): fork: %m",
- a.rmt_prog);
- return;
- }
- port = pml->pml_map.pm_port;
- get_myaddress(&me);
- me.sin_port = htons(port);
- client = clntudp_create(&me, a.rmt_prog, a.rmt_vers, timeout, &so);
- if (client != (CLIENT *)NULL) {
- if (rqstp->rq_cred.oa_flavor == AUTH_UNIX) {
- client->cl_auth = authunix_create(au->aup_machname,
- au->aup_uid, au->aup_gid, au->aup_len, au->aup_gids);
- }
- a.rmt_port = (u_long)port;
- if (clnt_call(client, a.rmt_proc, xdr_opaque_parms, &a,
- xdr_len_opaque_parms, &a, timeout) == RPC_SUCCESS) {
- svc_sendreply(xprt, xdr_rmtcall_result, (caddr_t)&a);
- }
- AUTH_DESTROY(client->cl_auth);
- clnt_destroy(client);
- }
- (void)close(so);
- exit(0);
-}
-
-static void
-reap(sig)
- int sig;
-{
- int save_errno;
-
- save_errno = errno;
- while (wait3((int *)NULL, WNOHANG, (struct rusage *)NULL) > 0);
- errno = save_errno;
-}
OpenPOWER on IntegriCloud