Remove variables and assignments with no effect
[yaz-moved-to-github.git] / src / tcpdchk.c
1 /* This file is part of the YAZ toolkit.
2  * Copyright (C) 1995-2011 Index Data
3  * See the file LICENSE for details.
4  */
5 /**
6  * \file tcpdchk.c
7  * \brief Implements TCP WRAPPER check.
8  */
9
10 #if HAVE_CONFIG_H
11 #include <config.h>
12 #endif
13
14 #include <stdio.h>
15 #include <string.h>
16
17 #ifdef WIN32
18 #include <winsock.h>
19 #endif
20
21 #if HAVE_SYS_TYPES_H
22 #include <sys/types.h>
23 #endif
24
25 #if HAVE_NETINET_IN_H
26 #include <netinet/in.h>
27 #endif
28
29 #if HAVE_ARPA_INET_H
30 #include <arpa/inet.h>
31 #endif
32
33 #if HAVE_SYS_SOCKET_H
34 /* freebsd wants this for AF_INET */
35 #include <sys/socket.h>
36 #endif
37
38 #if HAVE_NETDB_H
39 #include <netdb.h>
40 #endif
41
42 #include <yaz/comstack.h>
43 #include <yaz/statserv.h>
44 #include <yaz/log.h>
45
46
47 #if HAVE_TCPD_H
48 #include <syslog.h>
49 #include <tcpd.h>
50
51 int allow_severity = LOG_INFO;  /* not YLOG !! */
52 int deny_severity = LOG_WARNING;
53
54 #ifdef LOG_DEBUG
55 #undef LOG_DEBUG
56 #endif
57 #ifdef LOG_WARN
58 #undef LOG_WARN
59 #endif
60
61 #endif
62
63 int check_ip_tcpd(void *cd, const char *addr, int len, int type)
64 {
65     const char *daemon_name = (const char *) cd;
66
67     if (type == AF_INET)
68     {
69         if (daemon_name && *daemon_name)
70         {
71 #if HAVE_TCPD_H
72             struct request_info request_info;
73             int i;
74             char *host_name = 0, *host_addr = 0;
75             struct hostent *host;
76
77             struct sockaddr_in *addr_in = (struct sockaddr_in *) addr;
78             
79             if ((host = gethostbyaddr((char*)&addr_in->sin_addr,
80                                       sizeof(addr_in->sin_addr),
81                                       AF_INET)))
82                 host_name = (char*) host->h_name;
83             host_addr = inet_ntoa(addr_in->sin_addr);
84             if (host_addr)
85                 request_init(&request_info, RQ_DAEMON, daemon_name,
86                              RQ_CLIENT_NAME, host_name,
87                              RQ_CLIENT_SIN, addr_in,
88                              RQ_CLIENT_ADDR, host_addr, 0);
89             else
90                 request_init(&request_info, RQ_DAEMON, daemon_name,
91                              RQ_CLIENT_SIN, addr_in,
92                              RQ_CLIENT_ADDR, host_addr, 0);
93             i = hosts_access(&request_info);
94             if (!i)
95             {
96                 yaz_log (YLOG_DEBUG, "access denied from %s",
97                          host_name ? host_name : host_addr);
98                 return 1;
99             }
100             yaz_log (YLOG_DEBUG, "access granted from %s",
101                      host_name ? host_name : host_addr);
102 #endif
103         }
104     }
105     return 0;
106 }
107
108 /*
109  * Local variables:
110  * c-basic-offset: 4
111  * c-file-style: "Stroustrup"
112  * indent-tabs-mode: nil
113  * End:
114  * vim: shiftwidth=4 tabstop=8 expandtab
115  */
116