Name:      firewalld
Version:   1.0.2
Release:   8
Summary:   A firewall daemon with D-Bus interface providing a dynamic firewall
License:   GPLv2+
URL:       http://www.firewalld.org
Source0:   https://github.com/firewalld/firewalld/releases/download/v%{version}/%{name}-%{version}.tar.gz
#backport from gnome
Patch0:    firewalld-0.2.6-MDNS-default.patch
Patch1:    repair-test-cases.patch
Patch2:    add-Restart-on-failure-on-firewalld.service.patch

Patch3:    backport-fix-zone-combined-forward-must-not-default-to-True.patch
Patch4:    backport-fix-fw_icmptype-don-t-alter-ipvs-in-io_object.patch
Patch5:    backport-fix-check-config-use-the-dictionary-variants.patch
Patch6:    backport-fix-functions-check-config-fails-if-direct.xml-exists.patch
Patch7:    backport-fix-service-adding-includes-to-a-built-in-service.patch
Patch8:    0001-fix-config-Specify-the-translation-encoding-format-a.patch

Patch9:    backport-chore-nftables-add-delete-table-helper.patch
Patch10:   backport-fix-nftables-always-flush-main-table-on-start.patch

BuildArch:     noarch
BuildRequires: autoconf automake desktop-file-utils gettext intltool glib2 glib2-devel systemd-units docbook-style-xsl
BuildRequires: libxslt iptables ebtables ipset python3-devel


Requires:  iptables iptables-nft ipset systemd
%if %{?openEuler:1}0
Requires:  hicolor-icon-theme python3-gobject NetworkManager-libnm dbus-x11 gtk3
%endif
Requires:  python3-firewall  = %{version}-%{release}
Suggests:  iptables-nft

Obsoletes: firewalld-selinux < 0.4.4.2-2
Conflicts: selinux-policy < 3.14.1-28
Conflicts: cockpit-ws < 173-2
Recommends: polkit

Provides:  variant_config(Server)
Provides:  variant_config(Workstation)

Obsoletes: firewalld-config-standard <= 0.3.15
Obsoletes: firewalld-config-cloud <= 0.3.15
Obsoletes: firewalld-config-server <= 0.3.15
Obsoletes: firewalld-config-workstation <= 0.3.15

Provides:  firewalld-filesystem = %{version}-%{release} firewall-config = %{version}-%{release}
Obsoletes: firewalld-filesystem < %{version}-%{release} firewall-config < %{version}-%{release}

%description
firewalld is a firewall service daemon that provides a dynamic customizable
firewall with a D-Bus interface.

%package doc
Summary: Documentation for firewalld
%description doc
Documentation for firewalld.


%package -n python3-firewall
Summary: Python3 bindings for firewalld

%{?python_provide:%python_provide python3-firewall}

Obsoletes: python-firewall < 0.5.2-2
Obsoletes: python2-firewall < 0.5.2-2
Requires: python3-dbus python3-gobject-base python3-nftables

%description -n python3-firewall
Python3 bindings for firewalld.

%package -n firewalld-test
Summary: Firewalld testsuite

%description -n firewalld-test
This package provides the firewalld testsuite.


%prep
%autosetup -n %{name}-%{version} -p1
./autogen.sh



%build
%configure --enable-sysconfig --enable-rpmmacros PYTHON="%{__python3} %{py3_shbang_opts}"

%make_build

%install
%make_install

desktop-file-install --delete-original \
  --dir %{buildroot}%{_sysconfdir}/xdg/autostart \
  %{buildroot}%{_sysconfdir}/xdg/autostart/firewall-applet.desktop
desktop-file-install --delete-original \
  --dir %{buildroot}%{_datadir}/applications \
  %{buildroot}%{_datadir}/applications/firewall-config.desktop


mv %{buildroot}%{_sysconfdir}/firewalld/firewalld.conf \
    %{buildroot}%{_sysconfdir}/firewalld/firewalld-standard.conf


%find_lang %{name} --all-name

dd if=/dev/zero of=$RPM_BUILD_ROOT/%{_datadir}/firewalld/firewalld-tmp-mmap bs=4096 count=1

%check

%pre

%preun
%systemd_preun firewalld.service


%post
%systemd_post firewalld.service


%postun
%systemd_postun_with_restart firewalld.service

%posttrans
# If we don't yet have a symlink or existing file for firewalld.conf,
# create it. Note: this will intentionally reset the policykit policy
# at the same time, so they are in sync.

# Import /etc/os-release to get the variant definition
. /etc/os-release || :

if [ ! -e %{_sysconfdir}/firewalld/firewalld.conf ]; then
    case "$VARIANT_ID" in
        server)
            ln -sf firewalld-server.conf %{_sysconfdir}/firewalld/firewalld.conf || :
            ;;
        workstation)
            ln -sf firewalld-workstation.conf %{_sysconfdir}/firewalld/firewalld.conf || :
            ;;
        *)
            ln -sf firewalld-standard.conf %{_sysconfdir}/firewalld/firewalld.conf
            ;;
    esac
fi

if [ ! -e %{_datadir}/polkit-1/actions/org.fedoraproject.FirewallD1.policy ]; then
    case "$VARIANT_ID" in
        workstation)
            ln -sf org.fedoraproject.FirewallD1.desktop.policy.choice %{_datadir}/polkit-1/actions/org.fedoraproject.FirewallD1.policy || :
            ;;
        *)
            # For all other editions, we'll use the Server polkit policy
            ln -sf org.fedoraproject.FirewallD1.server.policy.choice %{_datadir}/polkit-1/actions/org.fedoraproject.FirewallD1.policy || :
    esac
fi

sed -i "s/CleanupModulesOnExit=no/CleanupModulesOnExit=yes/g" %{_sysconfdir}/firewalld/firewalld.conf

%files -f %{name}.lang
%doc COPYING README
%{_sbindir}/firewalld
%if %{?openEuler:1}0
%{_bindir}/firewall-config
%endif
%{_bindir}/firewall-cmd
%{_bindir}/firewall-offline-cmd
%{_datadir}/bash-completion/completions/firewall-cmd
%dir %{_datadir}/zsh/site-functions
%{_datadir}/zsh/site-functions/_firewalld
%{_prefix}/lib/firewalld/*
%attr(0750,root,root) %dir %{_sysconfdir}/firewalld/
%config(noreplace) %{_sysconfdir}/firewalld/firewalld-standard.conf
%attr(0750,root,root) %dir %{_sysconfdir}/firewalld/helpers
%attr(0750,root,root) %dir %{_sysconfdir}/firewalld/icmptypes
%attr(0750,root,root) %dir %{_sysconfdir}/firewalld/ipsets
%attr(0750,root,root) %dir %{_sysconfdir}/firewalld/services
%attr(0750,root,root) %dir %{_sysconfdir}/firewalld/policies
%attr(0750,root,root) %dir %{_sysconfdir}/firewalld/zones
%ghost %config(noreplace) %{_sysconfdir}/firewalld/firewalld.conf
%config(noreplace) %{_sysconfdir}/firewalld/lockdown-whitelist.xml
%defattr(0644,root,root)
%config(noreplace) %{_sysconfdir}/sysconfig/firewalld
%{_unitdir}/firewalld.service
%config(noreplace) %{_datadir}/dbus-1/system.d/FirewallD.conf
%{_datadir}/polkit-1/actions/org.fedoraproject.FirewallD1.desktop.policy.choice
%{_datadir}/polkit-1/actions/org.fedoraproject.FirewallD1.server.policy.choice
%ghost %{_datadir}/polkit-1/actions/org.fedoraproject.FirewallD1.policy
%{_sysconfdir}/modprobe.d/firewalld-sysctls.conf
%if %{!?openEuler:1}0
%attr (0700,root,root) %{_datadir}/firewalld/firewalld-tmp-mmap
%endif
%config(noreplace) %{_sysconfdir}/logrotate.d/firewalld
%{_rpmconfigdir}/macros.d/macros.firewalld

#we don't need applet
%exclude %{_bindir}/firewall-applet
%exclude %{_sysconfdir}/xdg/autostart/firewall-applet.desktop
%exclude %dir %{_sysconfdir}/firewall
%exclude %{_sysconfdir}/firewall/applet.conf
%exclude %{_datadir}/icons/hicolor/*/apps/firewall-applet*.*
%exclude %{_mandir}/man1/firewall-applet*.1*

%if %{?openEuler:1}0
%defattr(0644,root,root)
%attr (0700,root,root) %{_datadir}/firewalld/firewalld-tmp-mmap
%{_datadir}/firewalld/*
%{_datadir}/applications/firewall-config.desktop
%{_datadir}/metainfo/firewall-config.appdata.xml
%{_datadir}/icons/hicolor/*/apps/firewall-config*.*
%{_datadir}/glib-2.0/schemas/org.fedoraproject.FirewallConfig.gschema.xml
%else
%exclude %{_bindir}/firewall-config
%exclude %{_datadir}/firewalld/*
%exclude %{_datadir}/applications/firewall-config.desktop
%exclude %{_datadir}/metainfo/firewall-config.appdata.xml
%exclude %{_datadir}/icons/hicolor/*/apps/firewall-config*.*
%exclude %{_datadir}/glib-2.0/schemas/org.fedoraproject.FirewallConfig.gschema.xml
%endif
%exclude %{_datadir}/firewalld/testsuite/*

%files  doc
%{_mandir}/man1/firewall*
%{_mandir}/man5/firewall*


%files -n python3-firewall
%defattr(-,root,root)
%{python3_sitelib}/firewall/*

%files -n firewalld-test
%dir %{_datadir}/firewalld/testsuite
%{_datadir}/firewalld/testsuite/README
%{_datadir}/firewalld/testsuite/testsuite
%dir %{_datadir}/firewalld/testsuite/integration
%{_datadir}/firewalld/testsuite/integration/testsuite
%dir %{_datadir}/firewalld/testsuite/python
%{_datadir}/firewalld/testsuite/python/firewalld_config.py
%{_datadir}/firewalld/testsuite/python/firewalld_direct.py
%{_datadir}/firewalld/testsuite/python/firewalld_rich.py
%{_datadir}/firewalld/testsuite/python/firewalld_test.py

%changelog
* Fri Jun 07 2024 zhouyihang <zhouyihang3@h-partners.com> - 1.0.2-8
- Type:requirement
- ID:NA
- SUG:NA
- DESC:To reduce unnecessary loading of ebtables-related kernel modules

* Tue Nov 28 2023 zhanghao <zhanghao383@huawei.com> - 1.0.2-7
- Type:requirement
- ID:NA
- SUG:NA
- DESC:Firewall startup is to set CleanupModuleOnxit=yes to unload
       related ko when stopping firewalld service

* Tue Sep 26 2023 zhanghao <zhanghao383@huawei.com> - 1.0.2-6
- Type:bugfix
- ID:NA
- SUG:NA
- DESC:chore nftables add delete table helper
       nftables always flush main table on start

* Mon Nov 14 2022 luoqing <luoqing@kylinsec.com.cn> - 1.0.2-5
- Type:bugfix
- ID:NA
- SUG:NA
- DESC:Specify the translation encoding format as UTF-8

* Thu Sep 01 2022 xinghe <xinghe2@h-partnres.com> - 1.0.2-4
- Type:bugfix
- ID:NA
- SUG:NA
- DESC:fix zone combined forward must not default to True
       fix fw icmptype don't alter ipvs in io_object
       fix check config use the dictionary variants
       fix functions check config fails if direct.xml exists
       fix service adding includes

* Thu Jun 30 2022 gaihuiying <eaglegai@163.com> - 1.0.2-3
- Type:bugfix
- ID:NA
- SUG:NA
- DESC:add macros to control if need gtk hicolor-icon-theme, etc.

* Tue Jan 25 2022 yanglu <yanglu72@huawei.com> - 1.0.2-2
- Type:bugfix
- ID:NA
- SUG:NA
- DESC:add-Restart-on-failure-on-firewalld.service

* Sat Dec 11 2021 gaihuiying <gaihuiying1@huawei.com> - 1.0.2-1
- Type:requirement
- ID:NA
- SUG:NA
- DESC:update to 1.0.2

* Thu Jul 22 2021 gaihuiying <gaihuiying1@huawei.com> - 0.9.4-1
- Type:requirement
- ID:NA
- SUG:NA
- DESC:update to 0.9.4

* Thu Dec 17 2020 Anakin Zhang <benjamin93@163.com> - 0.8.3-3
- Type:requirement
- ID:NA
- SUG:NA
- DESC:create firewalld temporary file

* Wed Sep 09 2020 gaihuiying <gaihuiying1@huawei.com> - 0.8.3-2
- Type:bugfix
- ID:NA
- SUG:restart
- DESC:remove unuselful patch:patch to default to iptables
       add new featuer to fix command error when use with non-existen ipset

* Wed Apr 29 2020 zhouyihang <zhouyihang3@huawei.com> - 0.8.3-1
- Type:requirement
- ID:NA
- SUG:NA
- DESC:update firewalld version to 0.8.3

* Wed Jan 15 2020 zhangrui <zhangrui182@huawei.com> - 0.6.2-4
- create firewalld.conf file

* Sat Sep 28 2019 huzhiyu <huzhiyu1@huawei.com> - 0.6.2-3
- create firewalld.conf file

* Thu Sep 5 2019 hufeng <solar.hu@huawei.com> - 0.6.2.2
- Create firewalld spec.
