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