1*86d7f5d3SJohn Marino /*
2*86d7f5d3SJohn Marino * The Dynix/PTX TLI implementation is not quite compatible with System V
3*86d7f5d3SJohn Marino * Release 4. Some important functions are not present so we are limited to
4*86d7f5d3SJohn Marino * IP-based services.
5*86d7f5d3SJohn Marino *
6*86d7f5d3SJohn Marino * Diagnostics are reported through syslog(3).
7*86d7f5d3SJohn Marino *
8*86d7f5d3SJohn Marino * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
9*86d7f5d3SJohn Marino */
10*86d7f5d3SJohn Marino
11*86d7f5d3SJohn Marino #ifndef lint
12*86d7f5d3SJohn Marino static char sccsid[] = "@(#) ptx.c 1.3 94/12/28 17:42:38";
13*86d7f5d3SJohn Marino #endif
14*86d7f5d3SJohn Marino
15*86d7f5d3SJohn Marino #ifdef PTX
16*86d7f5d3SJohn Marino
17*86d7f5d3SJohn Marino /* System libraries. */
18*86d7f5d3SJohn Marino
19*86d7f5d3SJohn Marino #include <sys/types.h>
20*86d7f5d3SJohn Marino #include <sys/tiuser.h>
21*86d7f5d3SJohn Marino #include <sys/socket.h>
22*86d7f5d3SJohn Marino #include <stropts.h>
23*86d7f5d3SJohn Marino #include <netinet/in.h>
24*86d7f5d3SJohn Marino #include <netdb.h>
25*86d7f5d3SJohn Marino #include <stdio.h>
26*86d7f5d3SJohn Marino #include <syslog.h>
27*86d7f5d3SJohn Marino
28*86d7f5d3SJohn Marino /* Local stuff. */
29*86d7f5d3SJohn Marino
30*86d7f5d3SJohn Marino #include "tcpd.h"
31*86d7f5d3SJohn Marino
32*86d7f5d3SJohn Marino /* Forward declarations. */
33*86d7f5d3SJohn Marino
34*86d7f5d3SJohn Marino static void ptx_sink();
35*86d7f5d3SJohn Marino
36*86d7f5d3SJohn Marino /* tli_host - determine TLI endpoint info, PTX version */
37*86d7f5d3SJohn Marino
tli_host(request)38*86d7f5d3SJohn Marino void tli_host(request)
39*86d7f5d3SJohn Marino struct request_info *request;
40*86d7f5d3SJohn Marino {
41*86d7f5d3SJohn Marino static struct sockaddr_in client;
42*86d7f5d3SJohn Marino static struct sockaddr_in server;
43*86d7f5d3SJohn Marino
44*86d7f5d3SJohn Marino /*
45*86d7f5d3SJohn Marino * getpeerinaddr() was suggested by someone at Sequent. It seems to work
46*86d7f5d3SJohn Marino * with connection-oriented (TCP) services such as rlogind and telnetd,
47*86d7f5d3SJohn Marino * but it returns 0.0.0.0 with datagram (UDP) services. No problem: UDP
48*86d7f5d3SJohn Marino * needs special treatment anyway, in case we must refuse service.
49*86d7f5d3SJohn Marino */
50*86d7f5d3SJohn Marino
51*86d7f5d3SJohn Marino if (getpeerinaddr(request->fd, &client, sizeof(client)) == 0
52*86d7f5d3SJohn Marino && client.sin_addr.s_addr != 0) {
53*86d7f5d3SJohn Marino request->client->sin = &client;
54*86d7f5d3SJohn Marino if (getmyinaddr(request->fd, &server, sizeof(server)) == 0) {
55*86d7f5d3SJohn Marino request->server->sin = &server;
56*86d7f5d3SJohn Marino } else {
57*86d7f5d3SJohn Marino tcpd_warn("warning: getmyinaddr: %m");
58*86d7f5d3SJohn Marino }
59*86d7f5d3SJohn Marino sock_methods(request);
60*86d7f5d3SJohn Marino
61*86d7f5d3SJohn Marino } else {
62*86d7f5d3SJohn Marino
63*86d7f5d3SJohn Marino /*
64*86d7f5d3SJohn Marino * Another suggestion was to temporarily switch to the socket
65*86d7f5d3SJohn Marino * interface, identify the endpoint addresses with socket calls, then
66*86d7f5d3SJohn Marino * to switch back to TLI. This seems to works OK with UDP services,
67*86d7f5d3SJohn Marino * which is exactly what we should be looking at right now.
68*86d7f5d3SJohn Marino */
69*86d7f5d3SJohn Marino
70*86d7f5d3SJohn Marino #define SWAP_MODULE(f, old, new) (ioctl(f, I_POP, old), ioctl(f, I_PUSH, new))
71*86d7f5d3SJohn Marino
72*86d7f5d3SJohn Marino if (SWAP_MODULE(request->fd, "timod", "sockmod") != 0)
73*86d7f5d3SJohn Marino tcpd_warn("replace timod by sockmod: %m");
74*86d7f5d3SJohn Marino sock_host(request);
75*86d7f5d3SJohn Marino if (SWAP_MODULE(request->fd, "sockmod", "timod") != 0)
76*86d7f5d3SJohn Marino tcpd_warn("replace sockmod by timod: %m");
77*86d7f5d3SJohn Marino if (request->sink != 0)
78*86d7f5d3SJohn Marino request->sink = ptx_sink;
79*86d7f5d3SJohn Marino }
80*86d7f5d3SJohn Marino }
81*86d7f5d3SJohn Marino
82*86d7f5d3SJohn Marino /* ptx_sink - absorb unreceived IP datagram */
83*86d7f5d3SJohn Marino
ptx_sink(fd)84*86d7f5d3SJohn Marino static void ptx_sink(fd)
85*86d7f5d3SJohn Marino int fd;
86*86d7f5d3SJohn Marino {
87*86d7f5d3SJohn Marino char buf[BUFSIZ];
88*86d7f5d3SJohn Marino struct sockaddr sa;
89*86d7f5d3SJohn Marino int size = sizeof(sa);
90*86d7f5d3SJohn Marino
91*86d7f5d3SJohn Marino /*
92*86d7f5d3SJohn Marino * Eat up the not-yet received datagram. Where needed, switch to the
93*86d7f5d3SJohn Marino * socket programming interface.
94*86d7f5d3SJohn Marino */
95*86d7f5d3SJohn Marino
96*86d7f5d3SJohn Marino if (ioctl(fd, I_FIND, "timod") != 0)
97*86d7f5d3SJohn Marino ioctl(fd, I_POP, "timod");
98*86d7f5d3SJohn Marino if (ioctl(fd, I_FIND, "sockmod") == 0)
99*86d7f5d3SJohn Marino ioctl(fd, I_PUSH, "sockmod");
100*86d7f5d3SJohn Marino (void) recvfrom(fd, buf, sizeof(buf), 0, &sa, &size);
101*86d7f5d3SJohn Marino }
102*86d7f5d3SJohn Marino
103*86d7f5d3SJohn Marino #endif /* PTX */
104