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