File cronie.spec of Package cronie.10664

# spec file for package cronie
# Copyright (c) 2019 SUSE LINUX GmbH, Nuernberg, Germany.
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via

# 3 : we don't need to do something with /etc/sysconfig/cron for now
%define cron_configs \{/etc/pam.d/crond,/etc/crontab,/etc/cron.deny,/etc/omc/srvinfo.d/cron.xml\}

Name:           cronie
BuildRequires:  audit-devel
BuildRequires:  libselinux-devel
BuildRequires:  pam-devel
BuildRequires:  pkgconfig(systemd)
Recommends:     smtp_daemon
Suggests:       postfix
PreReq:         permissions cron
Version:        1.4.11
Release:        0
%{expand: %%define cronie_version %version}
Summary:        Cron Daemon
License:        BSD-3-Clause and GPL-2.0 and MIT
Group:          System/Daemons
Source2:        run-crons
Source3:        sample.root
Source4:        deny.sample
Source5:        cron.xml
Source6:        cronie-rpmlintrc
Source7:        cron_to_cronie.README
Source8:        cron.service
Source9:        sysconfig.cron
# PATCH-FEATURE-OPENSUSE cronie-pam_config.diff added pam config file from old cron
Patch3:         %name-pam_config.diff
# openSUSE set NHEADER_LINES to 3 - old openSUSE cron put three lines of comments 
# in top of crontab file, so we want to hide this junk comments if user edit 
# crontab file with crontab -e command, patch grabbed from old openSUSE cron
Patch4:         %name-nheader_lines.diff
# we use instead of 
Patch5:         %name-crond_pid.diff
# PATCH-FIX-UPSTREAM mention logging disabling for a command in man
Patch7:         cronie-1.4.7-disable_logging.patch
# PATCH-FIX-UPSTREAM use run-crons instead of run-parts for anacron (bnc#689494)
Patch8:         cronie-anacron-1.4.7-run-crons.patch
Patch12:        cronie-piddir.patch
# PATCH-FIX-UPSTREAM bnc#900604 -- fix the loading PAM environment from the pam_env module
Patch13:        cronie-1.4.11-pam_env.patch
Patch14:        cronie-1.4.11-check_user_existence.patch
Patch15:        cronie-1.4.11-pidfile_locking.patch
# PATCH-FIX-UPSTREAM bsc#1128937 bnc#1128935 -- DoS of the crond by loading huge crontab files
Patch16:        cronie-1.4.11-huge_crontab_DoS.patch
Requires(post): %fillup_prereq
Conflicts:      cron <= 4.1
# When finish update protection of sles11 we could uncomment line bellow and drop all
# ugly hacks with subpackage cron needed for proper update proces
# Obsoletes:     cron <=4.x
BuildRoot:      %{_tmppath}/%{name}-%{version}-build

cron automatically starts programs at specific times. Add new entries
with "crontab -e". (See "man 5 crontab" and "man 1 crontab" for

Under /etc, find the directories cron.hourly, cron.daily, cron.weekly,
and cron.monthly.  Scripts and programs that are located there are
started automatically.

%package -n cron
Version:        4.2
Release:        0
Summary:        Auxiliary package
Group:          System/Daemons
Requires:       %{name} = %{cronie_version}-%{release}

%description -n cron
Auxiliary package, needed for proper update from vixie-cron 4.1 to cronie 1.4.4

%package anacron
Summary:        Utility for running regular jobs
Group:          System/Base
Requires:       %{name} = %{cronie_version}

%description anacron
Anacron becames part of cronie. Anacron is used only for running regular jobs.
The default settings execute regular jobs by anacron, however this could be
overloaded in settings.

%setup -q
%patch3 -p1
%patch5 -p1
%patch7 -p1
%patch8 -p1
cp %{S:7} ./cron_to_cronie.README
%patch12 -p1
%patch13 -p1
%patch14 -p1
%patch15 -p1
%patch16 -p1
# fill macro CRON_VERSION it is used in top three lines of crontab file,should be reworked
export CFLAGS="$RPM_OPT_FLAGS -DCRON_VERSION=\\\"%{version}\\\" -O0"
export LDFLAGS="-Wl,-z,relro,-z,now,-z,defs"
%configure --with-audit --enable-anacron --with-pam --with-selinux --with-inotify --enable-pie SPOOL_DIR="/var/spool/cron/tabs"
%{__make} %{?_smp_mflags} 

%{__mkdir_p} -v %{buildroot}%{_localstatedir}/spool/cron/{tabs,lastrun}
%{__mkdir_p} -v %{buildroot}%{_sysconfdir}/cron.{d,hourly,daily,weekly,monthly}
%{__install} -v -m 600 %{SOURCE3} %{buildroot}/etc/crontab
%{__install} -v -m 600 %{SOURCE4} %{buildroot}/etc/cron.deny
%{__install} -v -d %{buildroot}/usr/lib/cron
%{__install} -v %{SOURCE2} %{buildroot}/usr/lib/cron
%{__ln_s} -f ../../sbin/service %{buildroot}/usr/sbin/rccron
%{__install} -v -d %{buildroot}/%{_unitdir}
%{__install} -v -m 644 %{SOURCE8} %{buildroot}/%{_unitdir}
%{__install} -m 644 contrib/anacrontab $RPM_BUILD_ROOT%{_sysconfdir}/anacrontab
%{__install} -c -m755 contrib/0anacron $RPM_BUILD_ROOT%{_sysconfdir}/cron.hourly/0anacron
%{__mkdir_p} $RPM_BUILD_ROOT/var/spool/anacron
%{__mv} %{buildroot}%{_sbindir}/crond %{buildroot}%{_sbindir}/cron 
mkdir -p %{buildroot}%{_localstatedir}/adm/fillup-templates
cp %{SOURCE9} %{buildroot}%{_localstatedir}/adm/fillup-templates/

touch $RPM_BUILD_ROOT/var/spool/anacron/cron.daily
touch $RPM_BUILD_ROOT/var/spool/anacron/cron.weekly
touch $RPM_BUILD_ROOT/var/spool/anacron/cron.monthly

# service xml
%{__install} -v -d %{buildroot}%{_sysconfdir}/omc/srvinfo.d/
%{__install} -v -m644 %{S:5} %{buildroot}%{_sysconfdir}/omc/srvinfo.d/

%pre -n cron
# check if we are doing "ugly" update from old 4.1 vixie-cron
check_cron_mail_feature=`/usr/sbin/cron --help 2>&1 | /usr/bin/grep mail`
# vixie-cron 4.1 doesn't contain mail fature
if [ -e /usr/sbin/cron -a "${check_cron_mail_feature}" == "" ]; then
	# save configs for cronie post-install phase
	touch /var/run/update_from_old_cron
	echo $1
	for conf in	%{cron_configs} 
		%__mv "$conf" "$conf.bk" ||:

if [ -e /var/run/update_from_old_cron ]; then 
	# restore configs
	for conf in %{cron_configs}
		%__mv "$conf.bk" "$conf" ||:
%service_add_pre cron.service

# when we are doing rename then we pretend update with set 2
%set_permissions /etc/crontab /usr/bin/crontab
%{fillup_only -n cron}
%service_add_post cron.service

%verify_permissions -e /etc/crontab -e /usr/bin/crontab

%service_del_preun cron.service

%service_del_postun cron.service

if [ -e /var/run/update_from_old_cron ]; then 
	%{__rm} /var/run/update_from_old_cron ||:

%post anacron
[ -e /var/spool/anacron/cron.daily ] || touch /var/spool/anacron/cron.daily
[ -e /var/spool/anacron/cron.weekly ] || touch /var/spool/anacron/cron.weekly
[ -e /var/spool/anacron/cron.monthly ] || touch /var/spool/anacron/cron.monthly

%dir %attr(700,root,root) /var/spool/cron
%dir %attr(700,root,root) /var/spool/cron/tabs
%dir /var/spool/cron/lastrun
%config /etc/pam.d/crond
%verify(not mode) %config(noreplace) /etc/crontab
%config(noreplace) /etc/cron.deny
%verify(not mode) %attr (4750,root,trusted) /usr/bin/crontab
%attr (755,root,root) %{_sbindir}/cron
%config %{_sysconfdir}/omc/srvinfo.d/cron.xml
%dir %{_sysconfdir}/omc/srvinfo.d/
%dir %{_sysconfdir}/omc/

%files anacron
%attr(0755,root,root) %{_sysconfdir}/cron.hourly/0anacron
%config(noreplace) %{_sysconfdir}/anacrontab
%dir /var/spool/anacron
%ghost %verify(not md5 size mtime) /var/spool/anacron/cron.daily
%ghost %verify(not md5 size mtime) /var/spool/anacron/cron.weekly
%ghost %verify(not md5 size mtime) /var/spool/anacron/cron.monthly

%files -n cron
%doc cron_to_cronie.README

openSUSE Build Service is sponsored by