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