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