xref: /freebsd/contrib/tcp_wrappers/try-from.c (revision e32fecd0c2c3ee37c47ee100f169e7eb0282a873)
1  /*
2   * This program can be called via a remote shell command to find out if the
3   * hostname and address are properly recognized, if username lookup works,
4   * and (SysV only) if the TLI on top of IP heuristics work.
5   *
6   * Example: "rsh host /some/where/try-from".
7   *
8   * Diagnostics are reported through syslog(3) and redirected to stderr.
9   *
10   * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
11   */
12 
13 #ifndef lint
14 static char sccsid[] = "@(#) try-from.c 1.2 94/12/28 17:42:55";
15 #endif
16 
17 /* System libraries. */
18 
19 #include <sys/types.h>
20 #include <stdio.h>
21 #include <syslog.h>
22 #include <string.h>
23 
24 #ifdef TLI
25 #include <sys/tiuser.h>
26 #include <stropts.h>
27 #endif
28 
29 #ifndef STDIN_FILENO
30 #define	STDIN_FILENO	0
31 #endif
32 
33 /* Local stuff. */
34 
35 #include "tcpd.h"
36 
37 int     allow_severity = SEVERITY;	/* run-time adjustable */
38 int     deny_severity = LOG_WARNING;	/* ditto */
39 
40 main(int argc, char **argv)
41 {
42     struct request_info request;
43     char    buf[BUFSIZ];
44     char   *cp;
45 
46     /*
47      * Simplify the process name, just like tcpd would.
48      */
49     if ((cp = strrchr(argv[0], '/')) != 0)
50 	argv[0] = cp + 1;
51 
52     /*
53      * Turn on the "IP-underneath-TLI" detection heuristics.
54      */
55 #ifdef TLI
56     if (ioctl(0, I_FIND, "timod") == 0)
57 	ioctl(0, I_PUSH, "timod");
58 #endif /* TLI */
59 
60     /*
61      * Look up the endpoint information.
62      */
63     request_init(&request, RQ_DAEMON, argv[0], RQ_FILE, STDIN_FILENO, 0);
64     (void) fromhost(&request);
65 
66     /*
67      * Show some results. Name and address information is looked up when we
68      * ask for it.
69      */
70 
71 #define EXPAND(str) percent_x(buf, sizeof(buf), str, &request)
72 
73     puts(EXPAND("client address  (%%a): %a"));
74     puts(EXPAND("client hostname (%%n): %n"));
75     puts(EXPAND("client username (%%u): %u"));
76     puts(EXPAND("client info     (%%c): %c"));
77     puts(EXPAND("server address  (%%A): %A"));
78     puts(EXPAND("server hostname (%%N): %N"));
79     puts(EXPAND("server process  (%%d): %d"));
80     puts(EXPAND("server info     (%%s): %s"));
81 
82     return (0);
83 }
84