3669f35
%if 0%{?rhel} >= 8 || 0%{?fedora}
a1c0026
%global use_subpackages 1
a1c0026
%endif
a1c0026
a1c0026
Name: sshguard
9bab56b
Version: 2.4.3
7e2b3a1
Release: %autorelease
9bab56b
# The entire source code is BSD-3-Clause
9bab56b
# except src/parser/attack_parser.{h,c} is GPL-3.0-or-later
a1c0026
# except src/blocker/hash_32a.c & src/blocker/fnv.h which are Public Domain
a1c0026
# the latter two get compiled in, the license is thus superseded
a1c0026
# src/parser/* is compiled into its own binary %%{_libexecdir}/%%{name}/sshg_parser
aa5341a
License: BSD-3-Clause AND GPL-3.0-or-later AND LicenseRef-Fedora-Public-Domain
a1c0026
Summary: Protects hosts from brute-force attacks against SSH and other services
a1c0026
Url: http://www.sshguard.net
a1c0026
Source0: http://downloads.sourceforge.net/%{name}/%{name}-%{version}.tar.gz
a1c0026
Source1: %{name}.conf.in
a1c0026
Source2: %{name}.whitelist
67ea584
Patch1: 0001-fix-backend-path-in-example.patch
a1c0026
a1c0026
# fnv is a very small implementation of the fnv hash algorithm not worth splitting
a1c0026
# into its own package. It has not seen updates since 2012, and upstream does not
a1c0026
# distribute it as a stand-alone library
9bab56b
# Public Domain license
a1c0026
Provides: bundled(fnv) = 5.0.2
a1c0026
# simclist is a small library not worth splitting into its own package, and has not
a1c0026
# seen updates since 2011
9bab56b
# BSD-3-Clause license
a1c0026
Provides: bundled(simclist) = 1.4.4
a1c0026
a1c0026
%if 0%{?use_subpackages}
3669f35
# Require a firewall backend
3669f35
Requires: %{name}-config = %{version}-%{release}
a1c0026
# Autoinstall appropriate firewall backends
a1c0026
Recommends: (%{name}-firewalld if firewalld)
a1c0026
Recommends: (%{name}-iptables if iptables-services)
a1c0026
Recommends: (%{name}-nftables if nftables)
a1c0026
%endif
a1c0026
6bc7efa
BuildRequires: make
a1c0026
BuildRequires: gcc
a1c0026
BuildRequires: flex
a1c0026
BuildRequires: byacc
a1c0026
Requires: coreutils
a1c0026
Requires: grep
a1c0026
a1c0026
Requires: systemd
a1c0026
# for systemd service installation support
a1c0026
%if 0%{?fedora} > 29
a1c0026
BuildRequires: systemd-rpm-macros
a1c0026
%else
a1c0026
BuildRequires: systemd
a1c0026
%endif
a1c0026
a1c0026
%description
a1c0026
Sshguard protects hosts from brute-force attacks against SSH and other
a1c0026
services. It aggregates system logs and blocks repeat offenders using one of
a1c0026
several firewall backends.
a1c0026
a1c0026
Sshguard can read log messages from standard input or monitor one or more log
a1c0026
files. Log messages are parsed, line-by-line, for recognized patterns. If an
a1c0026
attack, such as several login failures within a few seconds, is detected, the
a1c0026
offending IP is blocked. Offenders are unblocked after a set interval, but can
a1c0026
be semi-permanently banned using the blacklist option.
a1c0026
a1c0026
%if 0%{?use_subpackages}
a1c0026
%package iptables
3669f35
Requires: iptables-services
1942195
Requires: %{name}%{?_isa} = %{version}-%{release}
3669f35
Provides: %{name}-config = %{version}-%{release}
a1c0026
Conflicts: %{name}-firewalld %{name}-nftables
a1c0026
Summary: Configuration for iptables backend of SSHGuard
a1c0026
RemovePathPostfixes: .iptables
a1c0026
%description iptables
a1c0026
Sshguard-iptables provides a configuration file for SSHGuard to use iptables
a1c0026
as the firewall backend.
a1c0026
a1c0026
%package firewalld
3669f35
Requires: firewalld ipset
1942195
Requires: %{name}%{?_isa} = %{version}-%{release}
3669f35
Provides: %{name}-config = %{version}-%{release}
a1c0026
Conflicts: %{name}-iptables %{name}-nftables
a1c0026
Summary: Configuration for firewalld backend of SSHGuard
a1c0026
RemovePathPostfixes: .firewalld
a1c0026
%description firewalld
a1c0026
Sshguard-firewalld provides a configuration file for SSHGuard to use firewalld
a1c0026
as the firewall backend.
a1c0026
a1c0026
%package nftables
3669f35
Requires: nftables
1942195
Requires: %{name}%{?_isa} = %{version}-%{release}
3669f35
Provides: %{name}-config = %{version}-%{release}
a1c0026
Conflicts: %{name}-firewalld %{name}-iptables
a1c0026
Summary: Configuration for nftables backend of SSHGuard
a1c0026
RemovePathPostfixes: .nftables
a1c0026
%description nftables
a1c0026
Sshguard-nftables provides a configuration file for SSHGuard to use nftables
a1c0026
as the firewall backend.
a1c0026
%endif
a1c0026
a1c0026
#-- PREP, BUILD & INSTALL -----------------------------------------------------#
a1c0026
%prep
a1c0026
%autosetup -p1
a1c0026
a1c0026
sed -i -e "s|%%{_bindir}|%{_bindir}|g" \
a1c0026
       -e "s|%%{_sbindir}|%{_sbindir}|g" \
a1c0026
       -e "s|%%{_libexecdir}|%{_libexecdir}|g" \
a1c0026
       -e "s|%%{_sysconfdir}|%{_sysconfdir}|g" \
a1c0026
       -e "s|%%{_initddir}|%{_initddir}|g" \
a1c0026
       -e "s|%%{_localstatedir}|%{_localstatedir}|g" \
a1c0026
       -e "s|%%{_sharedstatedir}|%{_sharedstatedir}|g" \
a1c0026
       -e "s|%%{_rundir}|%{_rundir}|g" \
a1c0026
       -e "s|%%{_pkgdocdir}|%{_pkgdocdir}|g" \
a1c0026
       -e "s|%%{name}|%{name}|g" \
fc221f7
       %{SOURCE1} %{SOURCE2}
a1c0026
a1c0026
%build
a1c0026
%{configure} --prefix=%{_prefix} --sysconfdir=%{_sysconfdir} --sbindir=%{_sbindir} --libexecdir=%{_libexecdir}/%{name}
a1c0026
%{make_build}
a1c0026
a1c0026
%install
a1c0026
%{make_install}
53affff
install -p -d -m 0755 %{buildroot}%{_pkgdocdir}/
53affff
install -p -d -m 0755 %{buildroot}%{_sysconfdir}/
53affff
install -p -d -m 0755 %{buildroot}%{_sharedstatedir}/%{name}/
a1c0026
%if 0%{?use_subpackages}
53affff
sed -e "s|__BACKEND__|sshg-fw-firewalld|g" %{SOURCE1} > %{buildroot}%{_sysconfdir}/%{name}.conf.firewalld
53affff
sed -e "s|__BACKEND__|sshg-fw-nft-sets|g" %{SOURCE1} > %{buildroot}%{_sysconfdir}/%{name}.conf.nftables
53affff
sed -e "s|__BACKEND__|sshg-fw-iptables|g" %{SOURCE1} > %{buildroot}%{_sysconfdir}/%{name}.conf.iptables
53affff
chmod 0644 %{buildroot}%{_sysconfdir}/%{name}.conf.*
a1c0026
%endif
53affff
install -p -m 0644 %{SOURCE2} %{buildroot}%{_sysconfdir}/%{name}.whitelist
53affff
install -p -d -m 0755 %{buildroot}%{_unitdir}
a1c0026
sed -i -e "/ExecStartPre=/d" examples/%{name}.service
a1c0026
sed -i -e "s|ExecStart=/usr/local/sbin/sshguard|ExecStart=%{_sbindir}/%{name}|g" examples/%{name}.service
53affff
install -p -m 0644 examples/%{name}.service %{buildroot}%{_unitdir}/
a1c0026
a1c0026
# cleanup
a1c0026
# *.plist is only relevant for MacOS systems
a1c0026
rm examples/net.sshguard.plist
a1c0026
# we already ship a service file
a1c0026
rm examples/sshguard.service
a1c0026
a1c0026
%check
a1c0026
make check
a1c0026
a1c0026
#-- SCRIPTLETS -----------------------------------------------------------------#
a1c0026
%post
a1c0026
%systemd_post %{name}.service
a1c0026
a1c0026
%if 0%{?use_subpackages}
a1c0026
# with iptables backend, sshguard does not auto-create its tables, so we do that here
a1c0026
%post iptables
a1c0026
if [[ $1 -eq 1 ]]; then
a1c0026
  iptables -N sshguard
a1c0026
  iptables -A INPUT -j sshguard
a1c0026
  iptables-save > /etc/sysconfig/iptables
a1c0026
  ip6tables -N sshguard
a1c0026
  ip6tables -A INPUT -j sshguard
a1c0026
  ip6tables-save > /etc/sysconfig/ip6tables
a1c0026
fi
a1c0026
exit 0
a1c0026
%endif
a1c0026
a1c0026
%preun
a1c0026
%systemd_preun %{name}.service
a1c0026
a1c0026
%postun
a1c0026
%systemd_postun_with_restart %{name}.service
a1c0026
a1c0026
#-- FILES ---------------------------------------------------------------------#
a1c0026
%files
a1c0026
%doc examples
a1c0026
%doc README.rst
a1c0026
%doc CONTRIBUTING.rst
a1c0026
%license COPYING
a1c0026
%{_sbindir}/%{name}
a1c0026
%{_mandir}/man8/%{name}*
a1c0026
%{_mandir}/man7/%{name}*
a1c0026
%dir %{_sharedstatedir}/%{name}/
a1c0026
%dir %{_libexecdir}/%{name}/
a1c0026
%{_libexecdir}/%{name}/sshg-logtail
a1c0026
%{_libexecdir}/%{name}/sshg-parser
a1c0026
%{_libexecdir}/%{name}/sshg-blocker
a1c0026
%{_libexecdir}/%{name}/sshg-fw-firewalld
a1c0026
%{_libexecdir}/%{name}/sshg-fw-hosts
a1c0026
%{_libexecdir}/%{name}/sshg-fw-ipfilter
a1c0026
%{_libexecdir}/%{name}/sshg-fw-ipfw
a1c0026
%{_libexecdir}/%{name}/sshg-fw-ipset
a1c0026
%{_libexecdir}/%{name}/sshg-fw-iptables
a1c0026
%{_libexecdir}/%{name}/sshg-fw-null
a1c0026
%{_libexecdir}/%{name}/sshg-fw-pf
a1c0026
%{_libexecdir}/%{name}/sshg-fw-nft-sets
a1c0026
%{_unitdir}/%{name}.service
a1c0026
%config(noreplace) %{_sysconfdir}/%{name}.whitelist
a1c0026
a1c0026
%if 0%{?use_subpackages}
a1c0026
%files iptables
a1c0026
%config(noreplace) %{_sysconfdir}/%{name}.conf.iptables
a1c0026
a1c0026
%files firewalld
a1c0026
%config(noreplace) %{_sysconfdir}/%{name}.conf.firewalld
a1c0026
a1c0026
%files nftables
a1c0026
%config(noreplace) %{_sysconfdir}/%{name}.conf.nftables
a1c0026
%endif
a1c0026
a1c0026
#-- CHANGELOG -----------------------------------------------------------------#
a1c0026
%changelog
7e2b3a1
%autochangelog