summaryrefslogtreecommitdiffstats
path: root/contrib/tcp_wrappers/ptx.c
blob: b9c312b82cdc06c6bebffc69c362179a911c4ce1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
 /*
  * The Dynix/PTX TLI implementation is not quite compatible with System V
  * Release 4. Some important functions are not present so we are limited to
  * IP-based services.
  * 
  * Diagnostics are reported through syslog(3).
  * 
  * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
  */

#ifndef lint
static char sccsid[] = "@(#) ptx.c 1.3 94/12/28 17:42:38";
#endif

#ifdef PTX

/* System libraries. */

#include <sys/types.h>
#include <sys/tiuser.h>
#include <sys/socket.h>
#include <stropts.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdio.h>
#include <syslog.h>

/* Local stuff. */

#include "tcpd.h"

/* Forward declarations. */

static void ptx_sink();

/* tli_host - determine TLI endpoint info, PTX version */

void    tli_host(request)
struct request_info *request;
{
    static struct sockaddr_in client;
    static struct sockaddr_in server;

    /*
     * getpeerinaddr() was suggested by someone at Sequent. It seems to work
     * with connection-oriented (TCP) services such as rlogind and telnetd,
     * but it returns 0.0.0.0 with datagram (UDP) services. No problem: UDP
     * needs special treatment anyway, in case we must refuse service.
     */

    if (getpeerinaddr(request->fd, &client, sizeof(client)) == 0
	&& client.sin_addr.s_addr != 0) {
	request->client->sin = &client;
	if (getmyinaddr(request->fd, &server, sizeof(server)) == 0) {
	    request->server->sin = &server;
	} else {
	    tcpd_warn("warning: getmyinaddr: %m");
	}
	sock_methods(request);

    } else {

	/*
	 * Another suggestion was to temporarily switch to the socket
	 * interface, identify the endpoint addresses with socket calls, then
	 * to switch back to TLI. This seems to works OK with UDP services,
	 * which is exactly what we should be looking at right now.
	 */

#define SWAP_MODULE(f, old, new) (ioctl(f, I_POP, old), ioctl(f, I_PUSH, new))

	if (SWAP_MODULE(request->fd, "timod", "sockmod") != 0)
	    tcpd_warn("replace timod by sockmod: %m");
	sock_host(request);
	if (SWAP_MODULE(request->fd, "sockmod", "timod") != 0)
	    tcpd_warn("replace sockmod by timod: %m");
	if (request->sink != 0)
	    request->sink = ptx_sink;
    }
}

/* ptx_sink - absorb unreceived IP datagram */

static void ptx_sink(fd)
int     fd;
{
    char    buf[BUFSIZ];
    struct sockaddr sa;
    int     size = sizeof(sa);

    /*
     * Eat up the not-yet received datagram. Where needed, switch to the
     * socket programming interface.
     */

    if (ioctl(fd, I_FIND, "timod") != 0)
	ioctl(fd, I_POP, "timod");
    if (ioctl(fd, I_FIND, "sockmod") == 0)
	ioctl(fd, I_PUSH, "sockmod");
    (void) recvfrom(fd, buf, sizeof(buf), 0, &sa, &size);
}

#endif /* PTX */
OpenPOWER on IntegriCloud