1 --- portmap-5.orig/Makefile
4 # if you disagree. See `man 3 syslog' for examples. Some syslog versions
5 # do not provide this flexibility.
10 # To disable tcp-wrapper style access control, comment out the following
11 # macro definitions. Access control can also be turned off by providing
13 # daemon, is always treated as an authorized host.
15 HOSTS_ACCESS= -DHOSTS_ACCESS
16 -WRAP_LIB = $(WRAP_DIR)/libwrap.a
17 +#WRAP_LIB = $(WRAP_DIR)/libwrap.a
20 # Comment out if your RPC library does not allocate privileged ports for
21 # requests from processes with root privilege, or the new portmap will
23 # With verbose logging on, HP-UX 9.x and AIX 4.1 leave zombies behind when
24 # SIGCHLD is not ignored. Enable next macro for a fix.
26 -# ZOMBIES = -DIGNORE_SIGCHLD # AIX 4.x, HP-UX 9.x
27 +ZOMBIES = -DIGNORE_SIGCHLD # AIX 4.x, HP-UX 9.x
29 # Uncomment the following macro if your system does not have u_long.
32 # libwrap.a object library. WRAP_DIR should specify the directory with
35 -WRAP_DIR= ../tcp_wrappers
36 +WRAP_DIR= $(TCPD_DIR)
38 # Auxiliary object files that may be missing from your C library.
40 -AUX = daemon.o strerror.o
41 +#AUX = daemon.o strerror.o
43 +# glibc has strerror() (it's POSIX) and daemon() (when compiling -D_BSD_SOURCE)
46 # NEXTSTEP is a little different. The following seems to work with NS 3.2
50 # Comment out if your compiler talks ANSI and understands const
55 ### End of configurable stuff.
56 ##############################
58 +GLIBC=$(shell grep -s -c __GLIBC__ /usr/include/features.h)
69 -COPT = $(CONST) -Dperror=xperror $(HOSTS_ACCESS) $(CHECK_PORT) \
70 +COPT = $(CONST) $(HOSTS_ACCESS) $(CHECK_PORT) \
71 $(SYS) -DFACILITY=$(FACILITY) $(ULONG) $(ZOMBIES) $(SA_LEN) \
72 $(LOOPBACK) $(SETPGRP)
73 -CFLAGS = $(COPT) -O $(NSARCHS)
74 +CFLAGS = -Wall $(COPT) -O2 $(NSARCHS)
75 OBJECTS = portmap.o pmap_check.o from_local.o $(AUX)
77 all: portmap pmap_dump pmap_set
79 -portmap: $(OBJECTS) $(WRAP_DIR)/libwrap.a
80 +portmap: $(OBJECTS) # $(WRAP_DIR)/libwrap.a
81 $(CC) $(CFLAGS) -o $@ $(OBJECTS) $(WRAP_LIB) $(LIBS)
83 pmap_dump: pmap_dump.c
85 get_myaddress: get_myaddress.c
86 cc $(CFLAGS) -DTEST -o $@ get_myaddress.c $(LIBS)
89 + install -o root -g root -m 0755 -s portmap ${BASEDIR}/sbin
90 + install -o root -g root -m 0755 -s pmap_dump ${BASEDIR}/sbin
91 + install -o root -g root -m 0755 -s pmap_set ${BASEDIR}/sbin
92 + install -o root -g root -m 0644 portmap.8 ${BASEDIR}/usr/share/man/man8
93 + install -o root -g root -m 0644 pmap_dump.8 ${BASEDIR}/usr/share/man/man8
94 + install -o root -g root -m 0644 pmap_set.8 ${BASEDIR}/usr/share/man/man8
95 + cat BLURB >${BASEDIR}/usr/share/doc/portmap/portmapper.txt
96 + gzip -9f ${BASEDIR}/usr/share/doc/portmap/portmapper.txt
100 lint $(COPT) $(OBJECTS:%.o=%.c)
102 --- portmap-5.orig/daemon.c
103 +++ portmap-5/daemon.c
105 #endif /* LIBC_SCCS and not lint */
110 -#define STDIN_FILENO 0
111 -#define STDOUT_FILENO 1
112 -#define STDERR_FILENO 2
114 +#include <sys/types.h>
117 #define _PATH_DEVNULL "/dev/null"
118 --- portmap-5.orig/pmap_check.c
119 +++ portmap-5/pmap_check.c
123 #include <sys/signal.h>
126 #include <netinet/in.h>
127 #include <rpc/rpcent.h>
129 +#include <sys/types.h>
133 extern char *inet_ntoa();
135 @@ -101,15 +105,25 @@
136 * Give up root privileges so that we can never allocate a privileged
137 * port when forwarding an rpc request.
139 + if (setgid(1) == -1) {
140 + syslog(LOG_ERR, "setgid(1) failed: %m");
143 + if (setgroups(0, 0) == -1) {
144 + syslog(LOG_ERR, "setgroups(0, 0) failed: %m");
147 if (setuid(1) == -1) {
148 syslog(LOG_ERR, "setuid(1) failed: %m");
152 (void) signal(SIGINT, toggle_verboselog);
155 /* check_default - additional checks for NULL, DUMP, GETPORT and unknown */
158 check_default(addr, proc, prog)
159 struct sockaddr_in *addr;
163 /* check_privileged_port - additional checks for privileged-port updates */
166 check_privileged_port(addr, proc, prog, port)
167 struct sockaddr_in *addr;
174 check_setunset(addr, proc, prog, port)
175 struct sockaddr_in *addr;
179 /* check_callit - additional checks for forwarded requests */
182 check_callit(addr, proc, prog, aproc)
183 struct sockaddr_in *addr;
185 @@ -249,13 +266,13 @@
187 struct proc_map *procp;
188 static struct proc_map procmap[] = {
189 - PMAPPROC_CALLIT, "callit",
190 - PMAPPROC_DUMP, "dump",
191 - PMAPPROC_GETPORT, "getport",
192 - PMAPPROC_NULL, "null",
193 - PMAPPROC_SET, "set",
194 - PMAPPROC_UNSET, "unset",
196 + {PMAPPROC_CALLIT, "callit"},
197 + {PMAPPROC_DUMP, "dump"},
198 + {PMAPPROC_GETPORT, "getport"},
199 + {PMAPPROC_NULL, "null"},
200 + {PMAPPROC_SET, "set"},
201 + {PMAPPROC_UNSET, "unset"},
210 - } else if (rpc = getrpcbynumber((int) prognum)) {
211 + } else if ((rpc = getrpcbynumber((int) prognum))) {
212 progname = rpc->r_name;
214 sprintf(progname = progbuf, "%lu", prognum);
215 --- portmap-5.orig/from_local.c
216 +++ portmap-5/from_local.c
219 #include <sys/ioctl.h>
229 /* find_local - find all IP addresses for this host */
237 /* from_local - determine whether request comes from the local system */
241 struct sockaddr_in *addr;
243 --- portmap-5.orig/pmap_dump.c
244 +++ portmap-5/pmap_dump.c
247 static char *protoname();
249 +#ifndef INADDR_LOOPBACK
250 +#define INADDR_LOOPBACK ntohl(inet_addr("127.0.0.1"))
253 +static void get_myloopaddress(addrp)
254 +struct sockaddr_in *addrp;
256 + memset((char *) addrp, 0, sizeof(*addrp));
257 + addrp->sin_family = AF_INET;
258 + addrp->sin_port = htons(PMAPPORT);
259 + addrp->sin_addr.s_addr = htonl(INADDR_LOOPBACK);
267 register struct pmaplist *list;
268 register struct rpcent *rpc;
270 - get_myaddress(&addr);
271 + get_myloopaddress(&addr);
273 for (list = pmap_getmaps(&addr); list; list = list->pml_next) {
274 rpc = getrpcbynumber((int) list->pml_map.pm_prog);
275 --- portmap-5.orig/pmap_set.c
276 +++ portmap-5/pmap_set.c
279 #include <rpc/pmap_clnt.h>
281 +int parse_line(char *buf, u_long *prog, u_long *vers, int *prot,
290 /* parse_line - convert line to numbers */
293 parse_line(buf, prog, vers, prot, port)
300 - char proto_name[BUFSIZ];
301 + char proto_name[256];
303 - if (sscanf(buf, "%lu %lu %s %u", prog, vers, proto_name, port) != 4) {
304 + if (sscanf(buf, "%lu %lu %255s %u", prog, vers, proto_name, port) != 4) {
307 if (strcmp(proto_name, "tcp") == 0) {
313 --- portmap-5.orig/portmap.c
314 +++ portmap-5/portmap.c
316 * Mountain View, California 94043
319 +#if defined(__GLIBC__)
320 +#define _BSD_SOURCE 1 /* for daemon(3) */
321 +#include <rpc/xdr.h>
322 +#endif /* __GLIBC__ */
324 #include <rpc/pmap_prot.h>
327 #include <sys/signal.h>
328 #include <sys/time.h>
329 #include <sys/resource.h>
331 #include <netinet/in.h>
333 +#include <sys/types.h>
337 +#include <arpa/inet.h>
339 -extern char *strerror();
344 static void callit();
345 struct pmaplist *pmaplist;
349 #include "pmap_check.h"
359 @@ -157,22 +163,31 @@
360 struct sockaddr_in addr;
361 int len = sizeof(struct sockaddr_in);
362 register struct pmaplist *pml;
363 + char *chroot_path = NULL;
364 + struct in_addr bindaddr;
365 + int have_bindaddr = 0;
367 - while ((c = getopt(argc, argv, "dv")) != EOF) {
368 + while ((c = getopt(argc, argv, "dt:vi:")) != EOF) {
376 + chroot_path = optarg;
383 + have_bindaddr = inet_aton(optarg, &bindaddr);
386 - (void) fprintf(stderr, "usage: %s [-dv]\n", argv[0]);
387 + (void) fprintf(stderr, "usage: %s [-dv] [-t path] [-i address]\n", argv[0]);
388 (void) fprintf(stderr, "-d: debugging mode\n");
389 + (void) fprintf(stderr, "-t path: chroot into path\n");
390 (void) fprintf(stderr, "-v: verbose logging\n");
391 + (void) fprintf(stderr, "-i address: bind to address\n");
396 addr.sin_addr.s_addr = 0;
397 addr.sin_family = AF_INET;
398 addr.sin_port = htons(PMAPPORT);
400 + memcpy(&addr.sin_addr, &bindaddr, sizeof(bindaddr));
402 if (bind(sock, (struct sockaddr *)&addr, len) != 0) {
403 syslog(LOG_ERR, "cannot bind udp: %m");
406 setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof on);
408 if (bind(sock, (struct sockaddr *)&addr, len) != 0) {
409 - syslog(LOG_ERR, "cannot bind udp: %m");
410 + syslog(LOG_ERR, "cannot bind tcp: %m");
413 if ((xprt = svctcp_create(sock, RPCSMALLMSGSIZE, RPCSMALLMSGSIZE))
415 (void)svc_register(xprt, PMAPPROG, PMAPVERS, reg_service, FALSE);
417 /* additional initializations */
420 + if (-1 == chroot(chroot_path))
422 + syslog(LOG_ERR, "couldn't do chroot");
427 #ifdef IGNORE_SIGCHLD /* Lionel Cons <cons@dxcern.cern.ch> */
428 (void)signal(SIGCHLD, SIG_IGN);
431 /* remote host authorization check */
432 check_default(svc_getcaller(xprt), rqstp->rq_proc, (u_long) 0);
433 - if (!svc_sendreply(xprt, xdr_void, (caddr_t)0) && debugging) {
434 + if (!svc_sendreply(xprt, (xdrproc_t) xdr_void, (caddr_t)0) && debugging) {
440 * Set a program,version to port mapping
442 - if (!svc_getargs(xprt, xdr_pmap, ®))
443 + if (!svc_getargs(xprt, (xdrproc_t) xdr_pmap, (caddr_t) ®))
446 /* reject non-local requests, protect priv. ports */
451 - if ((!svc_sendreply(xprt, xdr_int, (caddr_t)&ans)) &&
452 + if ((!svc_sendreply(xprt, (xdrproc_t) xdr_int, (caddr_t)&ans)) &&
454 (void) fprintf(stderr, "svc_sendreply\n");
458 * Remove a program,version to port mapping.
460 - if (!svc_getargs(xprt, xdr_pmap, ®))
461 + if (!svc_getargs(xprt, (xdrproc_t) xdr_pmap, (caddr_t) ®))
466 prevpml->pml_next = pml;
469 - if ((!svc_sendreply(xprt, xdr_int, (caddr_t)&ans)) &&
470 + if ((!svc_sendreply(xprt, (xdrproc_t) xdr_int, (caddr_t)&ans)) &&
472 (void) fprintf(stderr, "svc_sendreply\n");
476 * Lookup the mapping for a program,version and return its port
478 - if (!svc_getargs(xprt, xdr_pmap, ®))
479 + if (!svc_getargs(xprt, (xdrproc_t) xdr_pmap, (caddr_t) ®))
482 /* remote host authorization check */
484 port = fnd->pml_map.pm_port;
487 - if ((!svc_sendreply(xprt, xdr_int, (caddr_t)&port)) &&
488 + if ((!svc_sendreply(xprt, (xdrproc_t) xdr_int, (caddr_t)&port)) &&
490 (void) fprintf(stderr, "svc_sendreply\n");
494 * Return the current set of mapped program,version
496 - if (!svc_getargs(xprt, xdr_void, NULL))
497 + if (!svc_getargs(xprt, (xdrproc_t) xdr_void, (caddr_t) NULL))
500 /* remote host authorization check */
505 - if ((!svc_sendreply(xprt, xdr_pmaplist,
506 + if ((!svc_sendreply(xprt, (xdrproc_t) xdr_pmaplist,
507 (caddr_t)&p)) && debugging) {
508 (void) fprintf(stderr, "svc_sendreply\n");
513 a.rmt_args.args = buf;
514 - if (!svc_getargs(xprt, xdr_rmtcall_args, &a))
515 + if (!svc_getargs(xprt, (xdrproc_t) xdr_rmtcall_args, (caddr_t) &a))
517 /* host and service access control */
518 if (!check_callit(svc_getcaller(xprt),
520 au->aup_uid, au->aup_gid, au->aup_len, au->aup_gids);
522 a.rmt_port = (u_long)port;
523 - if (clnt_call(client, a.rmt_proc, xdr_opaque_parms, &a,
524 - xdr_len_opaque_parms, &a, timeout) == RPC_SUCCESS) {
525 - svc_sendreply(xprt, xdr_rmtcall_result, (caddr_t)&a);
526 + if (clnt_call(client, a.rmt_proc, (xdrproc_t) xdr_opaque_parms, (char*) &a,
527 + (xdrproc_t) xdr_len_opaque_parms, (char*) &a, timeout) == RPC_SUCCESS) {
528 + svc_sendreply(xprt, (xdrproc_t) xdr_rmtcall_result, (caddr_t)&a);
530 AUTH_DESTROY(client->cl_auth);
531 clnt_destroy(client);