Name:              openslp
Version:           2.0.0
Release:           26
Summary:           Open-source inplementation of the IETF Service Location Protocol
License:           BSD
URL:               https://sourceforge.net/projects/openslp/
Source0:           https://downloads.sf.net/openslp/openslp-%{version}.tar.gz
Source2:           slpd.8.gz
Source3:           slptool.1.gz
Source4:           slpd.service

Patch1:            openslp-2.0.0-multicast-set.patch
Patch2:            openslp-2.0.0-notify-systemd-of-start-up.patch
Patch3:            openslp-2.0.0-null-pointer-deref.patch
Patch4:            openslp-2.0.0-openssl-1.1-fix.patch
Patch5:            openslp-2.0.0-cve-2016-7567.patch
Patch6:            openslp-2.0.0-cve-2017-17833.patch
Patch6000:         CVE-2012-4428-fix-handling-of-string-list-in-slp_common-c.patch
Patch6001:         Fix-slp_iface-c-comma-expression-so-it-works-as-designed.patch
Patch6002:         Daemon-sends-wrong-service-reply-when-security-is-enabled.patch
Patch6003:         Fix-DAAddresses-hostname-resolution-issue.patch
Patch6004:         Change-default-slpreg-connection-from-UDP-to-TCP.patch
Patch6005:         Fix-interface-parsing-code-to-look-for-null-ifc-addrs.patch
Patch6006:         Fix-broadcast-functionality.patch
Patch6007:         Properly-initialize-xcastsocks-for-error-exit.patch
Patch6008:         Fix-xrealloc-to-properly-free-original-pointer-on-resize.patch
Patch6009:         CVE-2019-5544.patch

BuildRequires:     automake libtool bison flex openssl-devel systemd-units systemd-devel 

%description
Service Location Protocol (SLP) is an Internet Engineering Task Force (IETF) standards track protocol\
that provides a framework to allow networking applications to discover the existence, location,\
and configuration of networked services in enterprise networks.

%package devel
Summary: Provide headers and libraries for openslp
Requires: %{name} = %{version}-%{release}

%description devel
Provide header files and libraries of openslp

%package server
Summary: OpenSLP server daemon
Requires: %{name} = %{version}-%{release}
Requires: iproute

%description server
Provides a framework for applications to discover information about corporate network.

%package_help

%prep
%autosetup -n %{name}-%{version} -p1

autoreconf -fi
find . -name "CVS" | xargs rm -rf

%build
export CFLAGS="-fPIC -fno-strict-aliasing -fPIE -DPIE $RPM_OPT_FLAGS"
export LDFLAGS="-pie -Wl,-z,now"

%configure \
  --prefix=%{_prefix} --libdir=%{_libdir} --sysconfdir=%{_sysconfdir} \
  --localstatedir=/var --disable-dependency-tracking  --disable-rpath\
  --enable-slpv2-security --enable-async-api

%make_build

%install
%make_install
mkdir -p ${RPM_BUILD_ROOT}/%{_sysconfdir}/slp.reg.d
mkdir -p ${RPM_BUILD_ROOT}/usr/lib/%{name}-server
install -m 0755 etc/slpd.all_init ${RPM_BUILD_ROOT}/usr/lib/%{name}-server/slp-multicast-set.sh
mkdir -p ${RPM_BUILD_ROOT}/%{_unitdir}
install -p -m 644 %{SOURCE4} ${RPM_BUILD_ROOT}/%{_unitdir}/slpd.service
mkdir -p ${RPM_BUILD_ROOT}/%{_mandir}/man1/
mkdir -p ${RPM_BUILD_ROOT}/%{_mandir}/man8/
cp %SOURCE2 ${RPM_BUILD_ROOT}/%{_mandir}/man8/
cp %SOURCE3 ${RPM_BUILD_ROOT}/%{_mandir}/man1/

rm -rf $RPM_BUILD_ROOT/usr/doc
%delete_la

%ldconfig_scriptlets

%post server
%systemd_post slpd.service

%preun server
%systemd_preun slpd.service

%postun server
%systemd_postun_with_restart slpd.service

%files
%defattr(-,root,root)
%doc AUTHORS
%license COPYING
%config(noreplace) %{_sysconfdir}/slp.conf
%{_bindir}/slptool
%{_libdir}/libslp.so.1*
/usr/lib/%{name}-server/*.sh

%files server
%defattr(-,root,root)
%config(noreplace) %{_sysconfdir}/slp.reg
%config(noreplace) %{_sysconfdir}/slp.spi
%{_sbindir}/slpd
/usr/lib/%{name}-server/slp-multicast-set.sh
%{_unitdir}/slpd.service

%files devel
%defattr(-,root,root)
%{_includedir}/*.h
%{_libdir}/*.so
%{_libdir}/*.a

%files help
%defattr(-,root,root)
%doc FAQ NEWS README THANKS
%doc doc/doc/html/*
%doc doc/doc/rfc/*.txt
%{_mandir}/man1/slptool.*
%{_mandir}/man8/slpd.*

%changelog
* Fri Jul 30 2021 chenyanpanHW <chenyanpan@huawei.com> - 2.0.0-26
- DESC: delete -S git from %autosetup, and delete BuildRequires git

* Tue Mar 2 2021 hanzhijun <hanzhijun1@huawei.com> - 2.0.0-25
- Type:bugfix
- ID:NA
- SUG:NA
- DESC:remove excess service file

* Sat Jan 11 2020 zhangrui<zhangrui182@huawei.com> - 2.0.0-24
- Type:NA
- ID:NA
- SUG:NA
- DESC: fix build fail

* Sat Jan 11 2020 zhangrui<zhangrui182@huawei.com> - 2.0.0-23
- Type:cves
- ID:CVE-2019-5544
- SUG:restart
- DESC: fix CVE-2019-5544

* Mon Oct 21 2019 openEuler Buildteam <buildteam@openeuler.org> - 2.0.0-22
- Type:enhancement
- Id:NA
- SUG:NA
- DESC:modify the location of COPYING

* Wed Sep 11 2019 openEuler Buildteam <buildteam@openeuler.org> - 2.0.0-21
- Package init
