--- pdns-recursor.spec.orig
+++ pdns-recursor.spec
@@ -1,5 +1,5 @@
 #
-# spec file for package pdns-recursor (Version 3.2)
+# spec file for package pdns-recursor
 #
 # Copyright (c) 2007 SUSE LINUX Products GmbH, Nuernberg, Germany.
 # This file and all modifications and additions to the pristine
@@ -9,29 +9,59 @@
 #
 
 # norootforbuild
-
+%{?!rhel:%define rhel 0}
+%if 0%{?rhel} == 5
+%define hardening no
+%else
+%define hardening yes
+%endif
+Version:	4.1.16
 Name:           pdns-recursor
-Version:        3.2
-Release:        102
-%define pkg_version    3.2
+Release:        105
+%define pkg_version    %{version}
 #
 Group:          Productivity/Networking/DNS/Servers
 License:        GPL v2 or later
 #
 %define home           %{_var}/lib/pdns
 %define _localstatedir %{_var}/run/pdns
-BuildRequires:  boost-devel gcc-c++
+BuildRequires:  boost-devel gcc-c++ openssl-devel
+%if %{!?_without_lua:1}%{?_without_lua:0}
+BuildRequires:          lua-devel >= 5.1
+Requires:               lua >= 5.1
+%if 0%{?suse_version}
+%define lua_libs_config LUA_LIBS_CONFIG=-llua
+%define cxx_boost CXXFLAGS=-I./boost_1_39_0/
+%else
+%define lua_libs_config LUA_LIBS_CONFIG=-llua-5.1
+%define cxx_boost CXXFLAGS=-I./boost_1_39_0/
+%endif
+%endif
+%if 0%{?suse_version}
+BuildRequires:	pwdutils
+Requires:	pwdutils
+%endif
 BuildRoot:      %{_tmppath}/%{name}-%{version}-build
+%if 0%{?suse_version} >= 1210 || 0%{?sles_version} >= 12 || 0%{?rhel} >= 7
+BuildRequires:  systemd
+%{?systemd_requires}
+%define has_systemd 1
+%endif
+%if 0%{?suse_version}
 PreReq:         %insserv_prereq %fillup_prereq /usr/sbin/useradd /usr/sbin/groupadd
+%endif
 #
 Url:            http://www.powerdns.com/
 Source:         http://downloads.powerdns.com/releases/%{name}-%{pkg_version}.tar.bz2
 Source1:        pdns-recursor.init
 Source2:        recursor.conf
-Patch:          pdns-recursor-%{version}_config.patch
-Patch1:         pdns-recursor-%{version}-strip.patch
+Source3:	boost_1_39_0.tar.bz2
+Source4:	pdns-recursor.cron
+Patch1:         pdns-recursor-3.7.0-disable-secpoll.patch
+#Patch2:		pdns-recursor-init-rh.patch
 #
 Summary:        Modern, advanced and high performance recursing/non authoritative nameserver
+Provides:	powerdns-recursor
 
 %description
 PowerDNS Recursor is a non authoritative/recursing DNS server. Use this
@@ -44,21 +74,39 @@ Authors:
     http://www.powerdns.com
 
 %prep
-%setup -n %{name}-%{pkg_version}
-%patch
-%patch1
-
+%setup -n %{name}-%{pkg_version} -a 3
+%patch1 -p2 -b .disable-secpoll
+##patch2
 %build
-%{__make} OPTFLAGS="%{optflags} -D_GNU_SOURCE"
+export HARDENING=%{hardening}
+%{cxx_boost} %configure --sysconfdir=/etc/pdns --localstatedir=/var/run/pdns
+%{cxx_boost} %__make clean
+%if %{!?_without_lua:1}%{?_without_lua:0}
+%{cxx_boost} LUA=1 LUA_CPPFLAGS_CONFIG= %{lua_libs_config} OPTFLAGS="%{optflags}" LDFLAGS="%{?__global_ldflags}" %__make SYSCONFDIR="%{_sysconfdir}/pdns" BINDIR="%{_sbindir}" STRIP_BINARIES=0 all
+%else
+CXXFLAGS=-I./boost_1_39_0/ OPTFLAGS="%{optflags}" LDFLAGS="%{?__global_ldflags}" %__make SYSCONFDIR="%{_sysconfdir}/pdns" BINDIR="%{_sbindir}" STRIP_BINARIES=0 all
+%endif
 
 %install
 %{__install} -Dd -m 0755 %{buildroot}{%{home},%{_localstatedir}}
-%makeinstall CONFIGDIR="%{_sysconfdir}/pdns" BINDIR="%{_sbindir}"
+STRIP_BINARIES=0 %__make DESTDIR=%{buildroot} install SYSCONFDIR="%{_sysconfdir}/pdns" BINDIR="%{_sbindir}"
 %{__install} -D -m 0644 %{S:2} %{buildroot}%{_sysconfdir}/pdns/recursor.conf
+%if 0%{?has_systemd}
+%{__install} -D -m 0644 contrib/systemd-pdns-recursor.service %{buildroot}%{_unitdir}/pdns-recursor.service
+rm -rf %{buildroot}%{_sysconfdir}/init.d/%{name}
+%else
+%if 0%{?suse_version}
 %{__install} -D -m 0755 %{S:1} %{buildroot}%{_sysconfdir}/init.d/%{name}
+%else
+%{__install} -D -m 0755 pdns-recursor.init.d %{buildroot}%{_sysconfdir}/init.d/%{name}
+%endif
 %{__ln_s} -f %{_sysconfdir}/init.d/%{name} %{buildroot}%{_sbindir}/rc%{name}
+%endif
 %{__install} -m 0755 -d %{buildroot}%{_datadir}/%{name}
 cp -R rrd %{buildroot}%{_datadir}/%{name}/
+%{__install} -d %{buildroot}%{_sysconfdir}/cron.d/
+%{__install} -p %{SOURCE4} %{buildroot}%{_sysconfdir}/cron.d/%{name}
+
 %clean
 %{__rm} -rf %{buildroot}
 
@@ -66,23 +114,51 @@ cp -R rrd %{buildroot}%{_datadir}/%{name
 /usr/sbin/groupadd -r pdns &>/dev/null || :
 /usr/sbin/useradd -o -g pdns -s /bin/false -r -c "pdns" -d %{home} pdns &>/dev/null || :
 
+%if 0%{?has_systemd}
+%service_add_pre pdns-recursor.service
+%endif
+
 %post
+%if 0%{?suse_version}
 %{fillup_and_insserv pdns-recursor}
+%endif
+%if 0%{?has_systemd}
+%service_add_post pdns-recursor.service
+%endif
+if [ "$1" == "1" ]; then
+    cd %{_datadir}/%{name}/rrd
+    ./create >/dev/null 2>&1 || :
+fi
 
 %preun
+%if 0%{?suse_version}
 %stop_on_removal pdns-recursor
+%endif
+%if 0%{?has_systemd}
+%service_del_preun pdns-recursor.service
+%endif
 
 %postun
+%if 0%{?suse_version}
 %restart_on_update pdns-recursor
 %insserv_cleanup
+%endif
+%if 0%{?has_systemd}
+%service_del_postun pdns-recursor.service
+%endif
 
 %files
 %defattr (-,root,root,-)
 %dir %{_sysconfdir}/pdns/
 %config(noreplace) %{_sysconfdir}/pdns/recursor.conf
 %config %{_sysconfdir}/pdns/recursor.conf-dist
+%config %attr(644,root,root) %{_sysconfdir}/cron.d/%{name}
+%if 0%{?has_systemd}
+%{_unitdir}/pdns-recursor.service
+%else
 %{_sysconfdir}/init.d/%{name}
 %{_sbindir}/rcpdns-recursor
+%endif
 %{_sbindir}/pdns_recursor
 %{_sbindir}/rec_control
 %{_mandir}/man1/pdns_recursor.1*
@@ -98,79 +174,3 @@ cp -R rrd %{buildroot}%{_datadir}/%{name
 %dir %{_localstatedir}
 
 %changelog
-* Mon Mar 08 2010 Carsten Schoene <cs@linux-administrator.com> - 3.2-1
-- update to release 3.2
- - This version contains a new "packet cache", which delivers a major performance boost.
- - Multiple threads can now be used to actually benefit from all available CPUs.
- - There are many new features, enhancements, and bugfixes.
-
-* Thu Jan 07 2010 Carsten Schoene <cs@linux-administrator.com> - 3.1.7.2
-- new release 3.1.7.2
- - fixes a number of security issus
-
-* Mon Aug 03 2009 Carsten Schoene <cs@linux-administrator.com> - 3.1.7.1
-- new release 3.1.7.1
- - fixes tiny bugs
- - compatibility with latest versions of gcc, boost and solaris 10
-
-* Thu Jun 26 2008 Carsten Schoene <cs@linux-administrator.com>
-- new release 3.1.7
- - This version adds powerful Lua scripting abilities, 
-   allowing operators to modify DNS queries before and after processing.
- - One important bug in dealing with changed delegations was fixed, plus a handful of small issues. 
- - Finally, this version compiles out of the box on recent versions of OS X.
-
-* Thu May 08 2008 Carsten Schoene <cs@linux-administrator.com>
-- new release 3.1.6
- - Version 3.1.5 had problems resolving several slightly misconfigured domains, 
-   including for a time 'juniper.net'. Nameserver timeouts were not being processed correctly, 
-   leading PowerDNS to not update the internal clock, which in turn meant that any queries 
-   immediately following an error would time out as well. 
-   Because of retries, this would usually not be a problem except on very busy servers, 
-   for domains with different nameservers at different levels of the DNS-hierarchy, like 'juniper.net'.
- - The new high-quality random generator was not used for all random numbers, 
-   especially in source port selection. This means that 3.1.5 is still a lot more secure than 3.1.4 was, 
-   and its algorithms more secure than most other nameservers, 
-   but it also means 3.1.5 is not as secure as it could be. A quick upgrade is recommended.
-
-* Mon Mar 31 2008 Carsten Schoene <cs@linux-administrator.com>
-- build 3.1.5
-* Sun Mar 28 2008 Carsten Schoene <cs@linux-administrator.com>
-- build 3.1.5-rc1
-- removed/adapted some patches to new version
- 
-* Sun Oct 28 2007 - mrueckert@suse.de
-- added pdns-recursor-3.1.4_gcc43.patch:
-  fix all warnings in pdns-recursor. (patch is upstream)
-* Wed Jul 25 2007 - mrueckert@suse.de
-- added pdns-recursor-3.1.4_r965.patch:
-  fix building on 10.0
-* Wed Feb 28 2007 - mrueckert@suse.de
-- added pdns-recursor-3.1.4_atomicity.patch:
-  The optimized code in recursor_cache.cc is included in gcc 4.2.
-  Proper #if to use it only with older gcc.
-- added pdns-recursor-3.1.4_char_casting.patch
-  Don't cast string constants to char*.
-* Tue Nov 14 2006 - mrueckert@suse.de
-- update to version 3.1.4
-  This release contains two important security fixes, which should also solve
-  the very rare reports of stability problems. Additionally, a new class of
-  misconfigured domains will now always be resolved correctly, instead of
-  intermittently.
-- removed patches applied upstream:
-  pdns-recursor-3.1.3_2006-02.patch
-  pdns-recursor-3.1.3_cve-2006-4251.patch
-  pdns-recursor-3.1.3_implicit_declarations.patch
-* Mon Nov 13 2006 - mrueckert@suse.de
-- added pdns-recursor-3.1.3_2006-02.patch:
-  fix an endless recursion in CNAME handling [#219355]
-* Sat Nov 11 2006 - mrueckert@suse.de
-- added pdns-recursor-3.1.3_cve-2006-4251.patch:
-  fix a stack corruption with malformed packages [#219355]
-- added pdns-recursor-3.1.3_implicit_declarations.patch:
-  fix an implicit declaration warning from gcc
-  http://wiki.powerdns.com/cgi-bin/trac.fcgi/changeset/920
-* Mon Nov 06 2006 - schwab@suse.de
-- Don't strip binaries.
-* Mon Oct 23 2006 - mrueckert@suse.de
-- initial package of version 3.1.3
