File: try-from.c

package info (click to toggle)
tcp-wrappers 7.6.q-28
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,760 kB
  • sloc: ansic: 17,677; makefile: 1,868; sh: 53
file content (85 lines) | stat: -rw-r--r-- 2,062 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
 /*
  * This program can be called via a remote shell command to find out if the
  * hostname and address are properly recognized, if username lookup works,
  * and (SysV only) if the TLI on top of IP heuristics work.
  * 
  * Example: "rsh host /some/where/try-from".
  * 
  * Diagnostics are reported through syslog(3) and redirected to stderr.
  * 
  * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
  */

#ifndef lint
static char sccsid[] = "@(#) try-from.c 1.2 94/12/28 17:42:55";
#endif

/* System libraries. */

#include <sys/types.h>
#include <stdio.h>
#include <syslog.h>
#include <string.h>

#ifdef TLI
#include <sys/tiuser.h>
#include <stropts.h>
#endif

#ifndef STDIN_FILENO
#define	STDIN_FILENO	0
#endif

/* Local stuff. */

#include "tcpd.h"

int     allow_severity = SEVERITY;	/* run-time adjustable */
int     deny_severity = LOG_WARNING;	/* ditto */

int main(argc, argv)
int     argc;
char  **argv;
{
    struct request_info request;
    char    buf[BUFSIZ];
    char   *cp;

    /*
     * Simplify the process name, just like tcpd would.
     */
    if ((cp = strrchr(argv[0], '/')) != 0)
	argv[0] = cp + 1;

    /*
     * Turn on the "IP-underneath-TLI" detection heuristics.
     */
#ifdef TLI
    if (ioctl(0, I_FIND, "timod") == 0)
	ioctl(0, I_PUSH, "timod");
#endif /* TLI */

    /*
     * Look up the endpoint information.
     */
    request_init(&request, RQ_DAEMON, argv[0], RQ_FILE, STDIN_FILENO, 0);
    (void) fromhost(&request);

    /*
     * Show some results. Name and address information is looked up when we
     * ask for it.
     */

#define EXPAND(str) percent_x(buf, sizeof(buf), str, &request)

    puts(EXPAND("client address  (%%a): %a"));
    puts(EXPAND("client hostname (%%n): %n"));
    puts(EXPAND("client username (%%u): %u"));
    puts(EXPAND("client info     (%%c): %c"));
    puts(EXPAND("server address  (%%A): %A"));
    puts(EXPAND("server hostname (%%N): %N"));
    puts(EXPAND("server process  (%%d): %d"));
    puts(EXPAND("server info     (%%s): %s"));

    return (0);
}