144743Smarkm /* 244743Smarkm * This program can be called via a remote shell command to find out if the 344743Smarkm * hostname and address are properly recognized, if username lookup works, 444743Smarkm * and (SysV only) if the TLI on top of IP heuristics work. 544743Smarkm * 644743Smarkm * Example: "rsh host /some/where/try-from". 744743Smarkm * 844743Smarkm * Diagnostics are reported through syslog(3) and redirected to stderr. 944743Smarkm * 1044743Smarkm * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands. 1144743Smarkm */ 1244743Smarkm 1344743Smarkm#ifndef lint 1444743Smarkmstatic char sccsid[] = "@(#) try-from.c 1.2 94/12/28 17:42:55"; 1544743Smarkm#endif 1644743Smarkm 1744743Smarkm/* System libraries. */ 1844743Smarkm 1944743Smarkm#include <sys/types.h> 2044743Smarkm#include <stdio.h> 2144743Smarkm#include <syslog.h> 2244743Smarkm#include <string.h> 2344743Smarkm 2444743Smarkm#ifdef TLI 2544743Smarkm#include <sys/tiuser.h> 2644743Smarkm#include <stropts.h> 2744743Smarkm#endif 2844743Smarkm 2944743Smarkm#ifndef STDIN_FILENO 3044743Smarkm#define STDIN_FILENO 0 3144743Smarkm#endif 3244743Smarkm 3344743Smarkm/* Local stuff. */ 3444743Smarkm 3544743Smarkm#include "tcpd.h" 3644743Smarkm 3744743Smarkmint allow_severity = SEVERITY; /* run-time adjustable */ 3844743Smarkmint deny_severity = LOG_WARNING; /* ditto */ 3944743Smarkm 4044743Smarkmmain(argc, argv) 4144743Smarkmint argc; 4244743Smarkmchar **argv; 4344743Smarkm{ 4444743Smarkm struct request_info request; 4544743Smarkm char buf[BUFSIZ]; 4644743Smarkm char *cp; 4744743Smarkm 4844743Smarkm /* 4944743Smarkm * Simplify the process name, just like tcpd would. 5044743Smarkm */ 5144743Smarkm if ((cp = strrchr(argv[0], '/')) != 0) 5244743Smarkm argv[0] = cp + 1; 5344743Smarkm 5444743Smarkm /* 5544743Smarkm * Turn on the "IP-underneath-TLI" detection heuristics. 5644743Smarkm */ 5744743Smarkm#ifdef TLI 5844743Smarkm if (ioctl(0, I_FIND, "timod") == 0) 5944743Smarkm ioctl(0, I_PUSH, "timod"); 6044743Smarkm#endif /* TLI */ 6144743Smarkm 6244743Smarkm /* 6344743Smarkm * Look up the endpoint information. 6444743Smarkm */ 6544743Smarkm request_init(&request, RQ_DAEMON, argv[0], RQ_FILE, STDIN_FILENO, 0); 6644743Smarkm (void) fromhost(&request); 6744743Smarkm 6844743Smarkm /* 6944743Smarkm * Show some results. Name and address information is looked up when we 7044743Smarkm * ask for it. 7144743Smarkm */ 7244743Smarkm 7344743Smarkm#define EXPAND(str) percent_x(buf, sizeof(buf), str, &request) 7444743Smarkm 7544743Smarkm puts(EXPAND("client address (%%a): %a")); 7644743Smarkm puts(EXPAND("client hostname (%%n): %n")); 7744743Smarkm puts(EXPAND("client username (%%u): %u")); 7844743Smarkm puts(EXPAND("client info (%%c): %c")); 7944743Smarkm puts(EXPAND("server address (%%A): %A")); 8044743Smarkm puts(EXPAND("server hostname (%%N): %N")); 8144743Smarkm puts(EXPAND("server process (%%d): %d")); 8244743Smarkm puts(EXPAND("server info (%%s): %s")); 8344743Smarkm 8444743Smarkm return (0); 8544743Smarkm} 86