File: wantconn.c

package info (click to toggle)
zmailer 2.99.55-3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 19,516 kB
  • ctags: 9,694
  • sloc: ansic: 120,953; sh: 3,862; makefile: 3,166; perl: 2,695; python: 115; awk: 22
file content (79 lines) | stat: -rw-r--r-- 2,073 bytes parent folder | download
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
/*
 * NAME
 * 
 * wantconn - build tcpd access control into any TCP or UDP application
 * 
 * SYNOPSIS
 * 
 * extern int wantconn(int sock, char *progname)
 * 
 * extern int allow_severity;
 * 
 * extern int deny_severity;
 * 
 * DESCRIPTION
 * 
 * wantconn() returns a non-zero value when the client in sock is allowed to
 * talk to the daemon in progname. As a side effect of calling wantconn(),
 * the syslog severity levels in the global variables allow_severity and
 * deny_severity may be updated.
 * 
 * wantconn() is not "paranoid", i.e. it does not autmoatically refuse clients
 * whose host name is inconsistent with their address.
 * 
 * AUTHOR
 * 
 * Wietse Venema, Eindhoven University of Technology, The Netherlands
 */

/*
 *  Integration into ZMailer autoconfiguration environment by
 *  Matti Aarnio  <mea@nic.funet.fi>
 */

#include "hostenv.h"
#ifdef USE_TCPWRAPPER
#ifdef HAVE_TCPD_H	/* The hall-mark of having tcp-wrapper things around */

#ifdef __hpux
#define request_info tcpd_request_info
#endif

#ifndef ALLOW_SEVERITY
#define ALLOW_SEVERITY	LOG_INFO
#define DENY_SEVERITY	LOG_WARNING
#endif

#include "zsyslog.h"

#include "tcpd.h"

int     allow_severity = ALLOW_SEVERITY;	/* run-time adjustable */
int     deny_severity  = DENY_SEVERITY;		/* ditto */

int     wantconn(sock, progname)
int     sock;
char   *progname;
{
    struct request_info request;

    /*
     * Reset the logging level in case we are called from a program that
     * responds to multiple clients.
     */
    allow_severity = ALLOW_SEVERITY;
    deny_severity = DENY_SEVERITY;

    /*
     * The user will expect that this will work as if sendmail is run under
     * control of the tcpd program. For perfect emulation we must be prepared
     * to do our own username lookup and whatever else tcpd may want to do in
     * the future. The cost is a small hit in performance.
     */
    request_init(&request, RQ_FILE, sock, RQ_DAEMON, progname, 0);
    fromhost(&request);
    return (hosts_access(&request));
}

#endif /* HAVE_TCPD_H    */
#endif /* USE_TCPWRAPPER */