]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/tcpwrap.c
sd-daemon: add gcc format string attribute to sd_notifyf
[thirdparty/systemd.git] / src / tcpwrap.c
CommitLineData
0213c3f8
LP
1/*-*- Mode: C; c-basic-offset: 8 -*-*/
2
3/***
4 This file is part of systemd.
5
6 Copyright 2010 Lennart Poettering
7
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
20***/
21
22#include <sys/socket.h>
23#include <sys/un.h>
24
25#ifdef HAVE_LIBWRAP
26#include <tcpd.h>
27#endif
28
29#include "tcpwrap.h"
30#include "log.h"
31
32bool socket_tcpwrap(int fd, const char *name) {
33#ifdef HAVE_LIBWRAP
34 struct request_info req;
35 union {
36 struct sockaddr sa;
37 struct sockaddr_in in;
38 struct sockaddr_in6 in6;
39 struct sockaddr_un un;
40 struct sockaddr_storage storage;
41 } sa_union;
42 socklen_t l = sizeof(sa_union);
43
44 if (getsockname(fd, &sa_union.sa, &l) < 0)
45 return true;
46
47 if (sa_union.sa.sa_family != AF_INET &&
48 sa_union.sa.sa_family != AF_INET6)
49 return true;
50
51 request_init(&req,
52 RQ_DAEMON, name,
53 RQ_FILE, fd,
54 NULL);
55
56 fromhost(&req);
57
58 if (!hosts_access(&req)) {
59 log_warning("Connection refused by tcpwrap.");
60 return false;
61 }
62
63 log_debug("Connection accepted by tcpwrap.");
64#endif
65 return true;
66}