00001
00002
00003
00004
00010 #include <stdio.h>
00011 #include <string.h>
00012
00013 #if HAVE_SYS_TYPES_H
00014 #include <sys/types.h>
00015 #endif
00016
00017 #ifdef WIN32
00018 #include <winsock.h>
00019 #else
00020 #include <netinet/in.h>
00021 #include <netdb.h>
00022 #include <arpa/inet.h>
00023 #include <netinet/tcp.h>
00024 #endif
00025
00026 #if HAVE_SYS_SOCKET_H
00027 #include <sys/socket.h>
00028 #endif
00029
00030 #include <yaz/yconfig.h>
00031 #include <yaz/comstack.h>
00032 #include <yaz/statserv.h>
00033 #include <yaz/log.h>
00034
00035
00036 #if HAVE_TCPD_H
00037 #include <syslog.h>
00038 #include <tcpd.h>
00039
00040 int allow_severity = LOG_INFO;
00041 int deny_severity = LOG_WARNING;
00042
00043 #ifdef LOG_DEBUG
00044 #undef LOG_DEBUG
00045 #endif
00046 #ifdef LOG_WARN
00047 #undef LOG_WARN
00048 #endif
00049
00050 #endif
00051
00052 int check_ip_tcpd(void *cd, const char *addr, int len, int type)
00053 {
00054 const char *daemon_name = (const char *) cd;
00055
00056 if (type == AF_INET)
00057 {
00058 if (daemon_name && *daemon_name)
00059 {
00060 #if HAVE_TCPD_H
00061 struct request_info request_info;
00062 int i;
00063 #endif
00064 char *host_name = 0, *host_addr = 0;
00065 struct hostent *host;
00066
00067 struct sockaddr_in *addr_in = (struct sockaddr_in *) addr;
00068
00069 if ((host = gethostbyaddr((char*)&addr_in->sin_addr,
00070 sizeof(addr_in->sin_addr),
00071 AF_INET)))
00072 host_name = (char*) host->h_name;
00073 host_addr = inet_ntoa(addr_in->sin_addr);
00074 #if HAVE_TCPD_H
00075 if (host_addr)
00076 request_init(&request_info, RQ_DAEMON, daemon_name,
00077 RQ_CLIENT_NAME, host_name,
00078 RQ_CLIENT_SIN, addr_in,
00079 RQ_CLIENT_ADDR, host_addr, 0);
00080 else
00081 request_init(&request_info, RQ_DAEMON, daemon_name,
00082 RQ_CLIENT_SIN, addr_in,
00083 RQ_CLIENT_ADDR, host_addr, 0);
00084 i = hosts_access(&request_info);
00085 if (!i)
00086 {
00087 yaz_log (YLOG_DEBUG, "access denied from %s",
00088 host_name ? host_name : host_addr);
00089 return 1;
00090 }
00091 yaz_log (YLOG_DEBUG, "access granted from %s",
00092 host_name ? host_name : host_addr);
00093 #endif
00094 }
00095 }
00096 return 0;
00097 }
00098
00099
00100
00101
00102
00103
00104
00105
00106