xref: /illumos-gate/usr/src/cmd/tcpd/try-from.c (revision 55fea89d)
17c478bd9Sstevel@tonic-gate  /*
27c478bd9Sstevel@tonic-gate   * This program can be called via a remote shell command to find out if the
37c478bd9Sstevel@tonic-gate   * hostname and address are properly recognized, if username lookup works,
47c478bd9Sstevel@tonic-gate   * and (SysV only) if the TLI on top of IP heuristics work.
5*55fea89dSDan Cross   *
67c478bd9Sstevel@tonic-gate   * Example: "rsh host /some/where/try-from".
7*55fea89dSDan Cross   *
87c478bd9Sstevel@tonic-gate   * Diagnostics are reported through syslog(3) and redirected to stderr.
9*55fea89dSDan Cross   *
107c478bd9Sstevel@tonic-gate   * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
117c478bd9Sstevel@tonic-gate   */
127c478bd9Sstevel@tonic-gate 
137c478bd9Sstevel@tonic-gate #ifndef lint
147c478bd9Sstevel@tonic-gate static char sccsid[] = "@(#) try-from.c 1.2 94/12/28 17:42:55";
157c478bd9Sstevel@tonic-gate #endif
167c478bd9Sstevel@tonic-gate 
177c478bd9Sstevel@tonic-gate /* System libraries. */
187c478bd9Sstevel@tonic-gate 
197c478bd9Sstevel@tonic-gate #include <sys/types.h>
207c478bd9Sstevel@tonic-gate #include <stdio.h>
217c478bd9Sstevel@tonic-gate #include <syslog.h>
227c478bd9Sstevel@tonic-gate #include <string.h>
237c478bd9Sstevel@tonic-gate 
247c478bd9Sstevel@tonic-gate #ifdef TLI
257c478bd9Sstevel@tonic-gate #include <sys/tiuser.h>
267c478bd9Sstevel@tonic-gate #include <stropts.h>
277c478bd9Sstevel@tonic-gate #endif
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #ifndef STDIN_FILENO
307c478bd9Sstevel@tonic-gate #define	STDIN_FILENO	0
317c478bd9Sstevel@tonic-gate #endif
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate /* Local stuff. */
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate #include "tcpd.h"
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate int     allow_severity = SEVERITY;	/* run-time adjustable */
387c478bd9Sstevel@tonic-gate int     deny_severity = LOG_WARNING;	/* ditto */
397c478bd9Sstevel@tonic-gate 
409455584cSIgor Kozhukhov int
main(argc,argv)417c478bd9Sstevel@tonic-gate main(argc, argv)
427c478bd9Sstevel@tonic-gate int     argc;
437c478bd9Sstevel@tonic-gate char  **argv;
447c478bd9Sstevel@tonic-gate {
457c478bd9Sstevel@tonic-gate     struct request_info request;
467c478bd9Sstevel@tonic-gate     char    buf[BUFSIZ];
477c478bd9Sstevel@tonic-gate     char   *cp;
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate     /*
507c478bd9Sstevel@tonic-gate      * Simplify the process name, just like tcpd would.
517c478bd9Sstevel@tonic-gate      */
527c478bd9Sstevel@tonic-gate     if ((cp = strrchr(argv[0], '/')) != 0)
537c478bd9Sstevel@tonic-gate 	argv[0] = cp + 1;
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate     /*
567c478bd9Sstevel@tonic-gate      * Turn on the "IP-underneath-TLI" detection heuristics.
577c478bd9Sstevel@tonic-gate      */
587c478bd9Sstevel@tonic-gate #ifdef TLI
597c478bd9Sstevel@tonic-gate     if (ioctl(0, I_FIND, "timod") == 0)
607c478bd9Sstevel@tonic-gate 	ioctl(0, I_PUSH, "timod");
617c478bd9Sstevel@tonic-gate #endif /* TLI */
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate     /*
647c478bd9Sstevel@tonic-gate      * Look up the endpoint information.
657c478bd9Sstevel@tonic-gate      */
667c478bd9Sstevel@tonic-gate     request_init(&request, RQ_DAEMON, argv[0], RQ_FILE, STDIN_FILENO, 0);
677c478bd9Sstevel@tonic-gate     (void) fromhost(&request);
687c478bd9Sstevel@tonic-gate 
697c478bd9Sstevel@tonic-gate     /*
707c478bd9Sstevel@tonic-gate      * Show some results. Name and address information is looked up when we
717c478bd9Sstevel@tonic-gate      * ask for it.
727c478bd9Sstevel@tonic-gate      */
737c478bd9Sstevel@tonic-gate 
747c478bd9Sstevel@tonic-gate #define EXPAND(str) percent_x(buf, sizeof(buf), str, &request)
757c478bd9Sstevel@tonic-gate 
767c478bd9Sstevel@tonic-gate     puts(EXPAND("client address  (%%a): %a"));
777c478bd9Sstevel@tonic-gate     puts(EXPAND("client hostname (%%n): %n"));
787c478bd9Sstevel@tonic-gate     puts(EXPAND("client username (%%u): %u"));
797c478bd9Sstevel@tonic-gate     puts(EXPAND("client info     (%%c): %c"));
807c478bd9Sstevel@tonic-gate     puts(EXPAND("server address  (%%A): %A"));
817c478bd9Sstevel@tonic-gate     puts(EXPAND("server hostname (%%N): %N"));
827c478bd9Sstevel@tonic-gate     puts(EXPAND("server process  (%%d): %d"));
837c478bd9Sstevel@tonic-gate     puts(EXPAND("server info     (%%s): %s"));
847c478bd9Sstevel@tonic-gate 
857c478bd9Sstevel@tonic-gate     return (0);
867c478bd9Sstevel@tonic-gate }
87