YAZ 5.37.0
tcpdchk.c
Go to the documentation of this file.
1/* This file is part of the YAZ toolkit.
2 * Copyright (C) Index Data
3 * See the file LICENSE for details.
4 */
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/* _GNU_SOURCE: for musl's netdb.h to expose gethostbyaddr */
40#define _GNU_SOURCE
41#include <netdb.h>
42#endif
43
44#include <yaz/comstack.h>
45#include <yaz/statserv.h>
46#include <yaz/log.h>
47
48
49#if HAVE_TCPD_H
50#include <syslog.h>
51#include <tcpd.h>
52
53int allow_severity = LOG_INFO; /* not YLOG !! */
54int deny_severity = LOG_WARNING;
55
56#endif
57
58int check_ip_tcpd(void *cd, const char *addr, int len, int type)
59{
60 const char *daemon_name = (const char *) cd;
61
62 if (type == AF_INET)
63 {
64 if (daemon_name && *daemon_name)
65 {
66#if HAVE_TCPD_H
67 struct request_info request_info;
68 int i;
69 char *host_name = 0, *host_addr = 0;
70 struct hostent *host;
71
72 struct sockaddr_in *addr_in = (struct sockaddr_in *) addr;
73
74 if ((host = gethostbyaddr((char*)&addr_in->sin_addr,
75 sizeof(addr_in->sin_addr),
76 AF_INET)))
77 host_name = (char*) host->h_name;
78 host_addr = inet_ntoa(addr_in->sin_addr);
79 if (host_addr && host_name)
80 request_init(&request_info, RQ_DAEMON, daemon_name,
81 RQ_CLIENT_NAME, host_name,
82 RQ_CLIENT_SIN, addr_in,
83 RQ_CLIENT_ADDR, host_addr, 0);
84 else
85 request_init(&request_info, RQ_DAEMON, daemon_name,
86 RQ_CLIENT_SIN, addr_in, 0);
87 i = hosts_access(&request_info);
88 if (!i)
89 {
90 yaz_log(YLOG_DEBUG, "access denied from %s",
91 host_name ? host_name : host_addr);
92 return 1;
93 }
94 yaz_log(YLOG_DEBUG, "access granted from %s",
95 host_name ? host_name : host_addr);
96#endif
97 }
98 }
99 return 0;
100}
101
102/*
103 * Local variables:
104 * c-basic-offset: 4
105 * c-file-style: "Stroustrup"
106 * indent-tabs-mode: nil
107 * End:
108 * vim: shiftwidth=4 tabstop=8 expandtab
109 */
110
Header for COMSTACK.
enum l_file_type type
Definition log.c:47
void yaz_log(int level, const char *fmt,...)
Writes log message.
Definition log.c:487
Logging utility.
#define YLOG_DEBUG
log level: debugging
Definition log.h:44
Header for GFS (Obsolete. Use yaz/backend.h).
int check_ip_tcpd(void *cd, const char *addr, int len, int type)
Definition tcpdchk.c:58