Added status elements for backend delete result set handler.
[yaz-moved-to-github.git] / server / tcpdchk.c
1 /*
2  * Copyright (c) 1995-1999, Index Data
3  * See the file LICENSE for details.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Log: tcpdchk.c,v $
7  * Revision 1.3  1999-08-27 09:40:32  adam
8  * Renamed logf function to yaz_log. Removed VC++ project files.
9  *
10  * Revision 1.2  1999/04/20 09:56:48  adam
11  * Added 'name' paramter to encoder/decoder routines (typedef Odr_fun).
12  * Modified all encoders/decoders to reflect this change.
13  *
14  * Revision 1.1  1999/04/16 14:45:55  adam
15  * Added interface for tcpd wrapper for access control.
16  *
17  */
18
19 #include <stdio.h>
20 #include <string.h>
21
22 #if HAVE_TCPD_H
23 #include <syslog.h>
24 #include <tcpd.h>
25
26 int allow_severity = LOG_INFO;
27 int deny_severity = LOG_WARNING;
28
29 #ifdef LOG_DEBUG
30 #undef LOG_DEBUG
31 #endif
32 #ifdef LOG_WARN
33 #undef LOG_WARN
34 #endif
35
36 #endif
37
38 #ifdef WIN32
39 #include <winsock.h>
40 #else
41 #include <unistd.h>
42 #endif
43
44 #include <comstack.h>
45 #include <statserv.h>
46 #include <log.h>
47
48 int check_ip_tcpd(void *cd, const char *addr, int len, int type)
49 {
50     const char *daemon_name = (const char *) cd;
51
52     if (type == AF_INET)
53     {
54         if (daemon_name && *daemon_name)
55         {
56 #if HAVE_TCPD_H
57             struct request_info request_info;
58             int i;
59 #endif
60             char *host_name = 0, *host_addr = 0;
61             struct hostent *host;
62
63             struct sockaddr_in *addr_in = (struct sockaddr_in *) addr;
64             
65             if ((host = gethostbyaddr((char*)&addr_in->sin_addr,
66                                       sizeof(addr_in->sin_addr),
67                                       AF_INET)))
68                 host_name = (char*) host->h_name;
69             host_addr = inet_ntoa(addr_in->sin_addr);
70 #if HAVE_TCPD_H
71             if (host_addr)
72                 request_init(&request_info, RQ_DAEMON, daemon_name,
73                              RQ_CLIENT_NAME, host_name,
74                              RQ_CLIENT_SIN, addr_in,
75                              RQ_CLIENT_ADDR, host_addr, 0);
76             else
77                 request_init(&request_info, RQ_DAEMON, daemon_name,
78                              RQ_CLIENT_SIN, addr_in,
79                              RQ_CLIENT_ADDR, host_addr, 0);
80             i = hosts_access(&request_info);
81             if (!i)
82             {
83                 yaz_log (LOG_DEBUG, "access denied from %s",
84                          host_name ? host_name : host_addr);
85                 return 1;
86             }
87             yaz_log (LOG_DEBUG, "access granted from %s",
88                      host_name ? host_name : host_addr);
89 #endif
90         }
91     }
92     return 0;
93 }
94