Compare commits

..

15 commits

Author SHA1 Message Date
Ondřej Pohořelský
f412c7853b Use systemd_tmpfiles to create files in /var directory
This is needed so Cronie works as expected in bootc
2025-12-17 12:05:29 +01:00
Ondřej Pohořelský
4a2f558b36 Forward XDG_SESSION_CLASS to PAM for session classification 2025-12-08 11:41:07 +01:00
Ondřej Pohořelský
05b2e8364b Fix backup failure when ~/.cache directory is missing 2025-08-06 15:26:33 +02:00
Fedora Release Engineering
d933913cca Rebuilt for https://fedoraproject.org/wiki/Fedora_43_Mass_Rebuild 2025-07-23 18:50:18 +00:00
Ondřej Pohořelský
480a306600 tests: migrate from STI to TMT
Related: https://fedoraproject.org/wiki/Changes/DisableSTI
2025-07-07 15:59:57 +02:00
Ondřej Pohořelský
e32eaecd64 Move parsing code before separator check 2025-05-13 07:56:02 +02:00
Ondřej Pohořelský
c4ababaa6b Install crond.service into /usr/lib
The old installation path (bare /lib prefix) is probably a leftover
from before the /usr path migration.
2025-04-23 10:06:35 +02:00
Ondřej Pohořelský
cecc2437a1 Fix range parsing
Adds patch from this PR:
https://github.com/cronie-crond/cronie/pull/200
2025-04-07 18:52:00 +02:00
Ondřej Pohořelský
016dbce149 Remove sbin mentions from spec file 2025-01-27 14:59:43 +01:00
Ondřej Pohořelský
7bb78d8b2c Resolve build failure with GCC15 2025-01-27 14:46:00 +01:00
Fedora Release Engineering
d49463ff02 Rebuilt for https://fedoraproject.org/wiki/Fedora_42_Mass_Rebuild 2025-01-16 14:52:49 +00:00
Ondřej Pohořelský
3efab80e2b Create anacron timestamp files with correct permissions 2024-12-09 16:24:40 +01:00
Fedora Release Engineering
a2b306c77a Rebuilt for https://fedoraproject.org/wiki/Fedora_41_Mass_Rebuild 2024-07-17 20:12:45 +00:00
Jan Staněk
218115d9c9
Update to version 1.7.2 (rhbz#2294896)
- Polish bconds to use newer macros
- Patch leaks found by SAST scan
2024-07-01 14:59:23 +02:00
Ondřej Pohořelský
cfe037d46d Update to 1.7.1 2024-02-26 09:37:41 +01:00
60 changed files with 495 additions and 851 deletions

1
.fmf/version Normal file
View file

@ -0,0 +1 @@
1

View file

@ -0,0 +1,9 @@
# systemd-tmpfiles configuration for cronie-anacron
# Create the anacron spool directory
d /var/spool/anacron 0755 root root -
# Create anacron timestamp files
f /var/spool/anacron/cron.daily 0600 root root -
f /var/spool/anacron/cron.weekly 0600 root root -
f /var/spool/anacron/cron.monthly 0600 root root -

4
cronie-tmpfiles.conf Normal file
View file

@ -0,0 +1,4 @@
# systemd-tmpfiles configuration for cronie
# Create the cron spool directory
d /var/spool/cron 0700 root root -

View file

@ -10,8 +10,20 @@ Release: %autorelease
License: GPL-2.0-or-later AND BSD-3-Clause AND BSD-2-Clause AND ISC AND LGPL-2.1-or-later
URL: https://github.com/cronie-crond/cronie
Source0: https://github.com/cronie-crond/cronie/releases/download/cronie-%{version}/cronie-%{version}.tar.gz
Source1: cronie-tmpfiles.conf
Source2: cronie-anacron-tmpfiles.conf
Patch: 0001-do-no-leak-file-descriptors.patch
# https://github.com/cronie-crond/cronie/issues/193
Patch: make_error_func_prototype_complete.patch
# https://github.com/cronie-crond/cronie/pull/200
Patch: fix_range_parsing.patch
# https://github.com/cronie-crond/cronie/pull/201
Patch: move_parsing_code.patch
# https://github.com/cronie-crond/cronie/pull/206
Patch: crontab-fix-backup-failure.patch
# https://github.com/cronie-crond/cronie/pull/210
Patch: forward-XDG_SESSION_CLASS-to-PAM-for-session-classification.patch
Requires: dailyjobs
@ -94,7 +106,6 @@ extra features.
%install
%make_install DESTMAN=$RPM_BUILD_ROOT%{_mandir}
mkdir -pm700 $RPM_BUILD_ROOT%{_localstatedir}/spool/cron
mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig/
mkdir -pm755 $RPM_BUILD_ROOT%{_sysconfdir}/cron.d/
%if ! %{with pam}
@ -106,26 +117,26 @@ install -m 644 contrib/anacrontab $RPM_BUILD_ROOT%{_sysconfdir}/anacrontab
install -c -m755 contrib/0hourly $RPM_BUILD_ROOT%{_sysconfdir}/cron.d/0hourly
mkdir -pm 755 $RPM_BUILD_ROOT%{_sysconfdir}/cron.hourly
install -c -m755 contrib/0anacron $RPM_BUILD_ROOT%{_sysconfdir}/cron.hourly/0anacron
mkdir -p $RPM_BUILD_ROOT/var/spool/anacron
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
# noanacron package
install -m 644 contrib/dailyjobs $RPM_BUILD_ROOT/%{_sysconfdir}/cron.d/dailyjobs
# install systemd initscript
mkdir -p $RPM_BUILD_ROOT/lib/systemd/system/
install -m 644 contrib/cronie.systemd $RPM_BUILD_ROOT/lib/systemd/system/crond.service
install -m 644 -D contrib/cronie.systemd $RPM_BUILD_ROOT/usr/lib/systemd/system/crond.service
# install tmpfiles.d configuration for bootc compatibility
install -m 644 -D %{SOURCE1} $RPM_BUILD_ROOT%{_tmpfilesdir}/cronie.conf
install -m 644 -D %{SOURCE2} $RPM_BUILD_ROOT%{_tmpfilesdir}/cronie-anacron.conf
%post
# run after an installation
%systemd_post crond.service
# create directories via tmpfiles.d for bootc compatibility
systemd-tmpfiles --create %{_tmpfilesdir}/cronie.conf 2>/dev/null || :
%post anacron
[ -e /var/spool/anacron/cron.daily ] || touch /var/spool/anacron/cron.daily 2>/dev/null || :
[ -e /var/spool/anacron/cron.weekly ] || touch /var/spool/anacron/cron.weekly 2>/dev/null || :
[ -e /var/spool/anacron/cron.monthly ] || touch /var/spool/anacron/cron.monthly 2>/dev/null || :
# create directories and files via tmpfiles.d for bootc compatibility
systemd-tmpfiles --create %{_tmpfilesdir}/cronie-anacron.conf 2>/dev/null || :
%preun
# run before a package is removed
@ -153,7 +164,7 @@ exit 0
# The package is allowed to autostart:
/bin/systemctl enable crond.service >/dev/null 2>&1
/sbin/chkconfig --del crond >/dev/null 2>&1 || :
/bin/chkconfig --del crond >/dev/null 2>&1 || :
/bin/systemctl try-restart crond.service >/dev/null 2>&1 || :
/bin/systemctl daemon-reload >/dev/null 2>&1 || :
@ -166,7 +177,7 @@ exit 0
%doc AUTHORS README ChangeLog
%{!?_licensedir:%global license %%doc}
%license COPYING
%attr(755,root,root) %{_sbindir}/crond
%attr(755,root,root) %{_bindir}/crond
%attr(4755,root,root) %{_bindir}/crontab
%attr(755,root,root) %{_bindir}/cronnext
%{_mandir}/man8/crond.*
@ -174,7 +185,6 @@ exit 0
%{_mandir}/man5/crontab.*
%{_mandir}/man1/crontab.*
%{_mandir}/man1/cronnext.*
%dir %{_localstatedir}/spool/cron
%dir %{_sysconfdir}/cron.d
%if %{with pam}
%attr(0644,root,root) %config(noreplace) %{_sysconfdir}/pam.d/crond
@ -182,18 +192,21 @@ exit 0
%config(noreplace) %{_sysconfdir}/sysconfig/crond
%config(noreplace,missingok) %{_sysconfdir}/cron.deny
%attr(0644,root,root) %config(noreplace) %{_sysconfdir}/cron.d/0hourly
%attr(0644,root,root) /lib/systemd/system/crond.service
%attr(0644,root,root) /usr/lib/systemd/system/crond.service
%{_tmpfilesdir}/cronie.conf
%ghost %dir %attr(0700,root,root) %{_localstatedir}/spool/cron
%files anacron
%{_sbindir}/anacron
%{_bindir}/anacron
%attr(0755,root,root) %{_sysconfdir}/cron.hourly/0anacron
%config(noreplace) %{_sysconfdir}/anacrontab
%dir /var/spool/anacron
%ghost %dir %attr(0755,root,root) /var/spool/anacron
%ghost %attr(0600,root,root) %verify(not md5 size mtime) /var/spool/anacron/cron.daily
%ghost %attr(0600,root,root) %verify(not md5 size mtime) /var/spool/anacron/cron.weekly
%ghost %attr(0600,root,root) %verify(not md5 size mtime) /var/spool/anacron/cron.monthly
%{_mandir}/man5/anacrontab.*
%{_mandir}/man8/anacron.*
%{_tmpfilesdir}/cronie-anacron.conf
%files noanacron
%attr(0644,root,root) %config(noreplace) %{_sysconfdir}/cron.d/dailyjobs

View file

@ -0,0 +1,38 @@
From fd56df9b6d5fa9932edc6bd41d307e2453a6b442 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ond=C5=99ej=20Poho=C5=99elsk=C3=BD?= <opohorel@redhat.com>
Date: Wed, 30 Jul 2025 12:40:17 +0200
Subject: [PATCH] crontab: Fix backup failure when ~/.cache directory missing
Create ~/.cache parent directory before creating ~/.cache/crontab backup
directory to prevent "mkdir: No such file or directory" errors when users
edit crontabs and their cache directory doesn't exist.
---
src/crontab.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/src/crontab.c b/src/crontab.c
index c11dc81..14d02dd 100644
--- a/src/crontab.c
+++ b/src/crontab.c
@@ -578,7 +578,21 @@ static int backup_crontab(const char *crontab_path) {
exit(ERROR_EXIT);
}
+ /* Ensure the backup directory and its parent exist, creating them if necessary */
if (stat(backup_dir, &sb) < OK && errno == ENOENT) {
+ char *last_slash = strrchr(backup_dir, '/');
+ if (last_slash && last_slash != backup_dir) {
+ char parent_dir[MAX_FNAME];
+ size_t parent_len = last_slash - backup_dir;
+ if (parent_len < sizeof(parent_dir)) {
+ strncpy(parent_dir, backup_dir, parent_len);
+ parent_dir[parent_len] = '\0';
+ /* Check if parent directory exists before creating */
+ if (stat(parent_dir, &sb) < OK && errno == ENOENT) {
+ mkdir(parent_dir, 0700);
+ }
+ }
+ }
if (OK != mkdir(backup_dir, 0755)) {
fprintf(stderr, "%s: ", backup_dir);
perror("mkdir");

26
fix_range_parsing.patch Normal file
View file

@ -0,0 +1,26 @@
From d037042129eacdd9d7760d74437842ee5a2d116e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ond=C5=99ej=20Poho=C5=99elsk=C3=BD?= <opohorel@redhat.com>
Date: Tue, 11 Mar 2025 15:12:38 +0100
Subject: [PATCH] get_range() fix range parsing for Sunday as 0 or 7
In fc8b0e5, we changed how the ranges are parsed. This created a
regression for parsing Sunday at the end of the range. This commit adds
the logic to correctly handle Sunday as the end of the range.
---
src/entry.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/src/entry.c b/src/entry.c
index a2077e8..30bedb3 100644
--- a/src/entry.c
+++ b/src/entry.c
@@ -642,6 +642,9 @@ get_range(bitstr_t * bits, int low, int high, const char *names[],
state = R_FINISH;
break;
}
+ if (low_ > high_ && high_ == 0) {
+ high_ = 7;
+ }
return (EOF);
case R_RANDOM:

View file

@ -0,0 +1,70 @@
From 5f9f16b5663becefdd0dd70df31c0ef5ac36f943 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ond=C5=99ej=20Poho=C5=99elsk=C3=BD?= <opohorel@redhat.com>
Date: Thu, 27 Nov 2025 14:38:47 +0100
Subject: [PATCH] Forward XDG_SESSION_CLASS to PAM for session classification
Allow users to set the XDG_SESSION_CLASS environment variable in their
crontab to control the systemd session class for cron jobs. When set,
this value is forwarded to the PAM environment so that pam_systemd can
use it for session classification (e.g., "background-light").
This enables cron jobs to run in lighter-weight sessions that consume
fewer system resources.
---
man/crontab.5 | 10 ++++++++++
src/security.c | 21 +++++++++++++++++++++
2 files changed, 31 insertions(+)
diff --git a/man/crontab.5 b/man/crontab.5
index 68380c6..7487cc5 100644
--- a/man/crontab.5
+++ b/man/crontab.5
@@ -157,6 +157,16 @@ upper limit specified by the variable. The random scaling factor is
determined during the cron daemon startup so it remains constant for
the whole run time of the daemon.
.PP
+The
+.I XDG_SESSION_CLASS
+variable specifies the session class to be used when PAM creates a systemd
+session for the cron job. If set (e.g., to "background-light"), this value
+is forwarded to the PAM environment so that
+.BR pam_systemd (8)
+can use it for session classification. This allows cron jobs to run in
+lighter-weight sessions that consume fewer system resources. This variable
+has no effect if crond was built without PAM support.
+.PP
The format of a cron command is similar to the V7 standard, with a number
of upward-compatible extensions. Each line has five time-and-date fields
followed by a
diff --git a/src/security.c b/src/security.c
index 14a514a..67b6d26 100644
--- a/src/security.c
+++ b/src/security.c
@@ -131,6 +131,27 @@ int cron_set_job_security_context(entry *e, user *u ATTRIBUTE_UNUSED,
pam_strerror(pamh, ret), 0);
return -1;
}
+
+ /* Forward XDG_SESSION_CLASS from crontab environment to PAM
+ * so that pam_systemd.so can use it for session classification */
+#ifdef HAVE_PAM_PUTENV
+ if (pamh != NULL) {
+ char *xdg_session_class = env_get("XDG_SESSION_CLASS", e->envp);
+ if (xdg_session_class != NULL) {
+ char *xdg_session_class_env = NULL;
+ if (asprintf(&xdg_session_class_env, "XDG_SESSION_CLASS=%s",
+ xdg_session_class) >= 0) {
+ ret = pam_putenv(pamh, xdg_session_class_env);
+ if (ret != PAM_SUCCESS) {
+ log_it(e->pwd->pw_name, getpid(),
+ "WARNING: Failed to set XDG_SESSION_CLASS in PAM environment",
+ pam_strerror(pamh, ret), 0);
+ }
+ free(xdg_session_class_env);
+ }
+ }
+ }
+#endif
#endif
#ifdef WITH_SELINUX

View file

@ -0,0 +1,37 @@
From 09c630c654b2aeff06a90a412cce0a60ab4955a4 Mon Sep 17 00:00:00 2001
From: Tomas Mraz <tmraz@fedoraproject.org>
Date: Mon, 18 Nov 2024 21:02:30 +0100
Subject: [PATCH] load_entry(): Make error_func prototype complete
Fixes #193
---
src/entry.c | 2 +-
src/funcs.h | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/entry.c b/src/entry.c
index 586eb9d..a2077e8 100644
--- a/src/entry.c
+++ b/src/entry.c
@@ -90,7 +90,7 @@ void free_entry(entry * e) {
/* return NULL if eof or syntax error occurs;
* otherwise return a pointer to a new entry.
*/
-entry *load_entry(FILE * file, void (*error_func) (), struct passwd *pw,
+entry *load_entry(FILE * file, void (*error_func) (const char *), struct passwd *pw,
char **envp) {
/* this function reads one crontab entry -- the next -- from a file.
* it skips any leading blank lines, ignores comments, and returns
diff --git a/src/funcs.h b/src/funcs.h
index 427e027..f28d634 100644
--- a/src/funcs.h
+++ b/src/funcs.h
@@ -89,7 +89,7 @@ char *env_get(const char *, char **),
user *load_user(int, struct passwd *, const char *, const char *, const char *),
*find_user(cron_db *, const char *, const char *);
-entry *load_entry(FILE *, void (*)(), struct passwd *, char **);
+entry *load_entry(FILE *, void (*)(const char *), struct passwd *, char **);
FILE *cron_popen(char *, const char *, struct passwd *, char **);

36
move_parsing_code.patch Normal file
View file

@ -0,0 +1,36 @@
From e6c2853856c3103a4add4c3673b3306cc21d341e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ond=C5=99ej=20Poho=C5=99elsk=C3=BD?= <opohorel@redhat.com>
Date: Wed, 7 May 2025 13:25:19 +0200
Subject: [PATCH] get_range() move parsing code before separator check
In the previous commit the parsing fix was added after a separator check
by accident, making it not execute properly. This commit moves it into the
right place.
---
src/entry.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/entry.c b/src/entry.c
index 30bedb3..da1a02c 100644
--- a/src/entry.c
+++ b/src/entry.c
@@ -638,13 +638,13 @@ get_range(bitstr_t * bits, int low, int high, const char *names[],
state = R_STEP;
break;
}
+ if (low_ > high_ && high_ == 0) {
+ high_ = 7;
+ }
if (is_separator(ch)) {
state = R_FINISH;
break;
}
- if (low_ > high_ && high_ == 0) {
- high_ = 7;
- }
return (EOF);
case R_RANDOM:
--
2.49.0

5
plans/default.fmf Normal file
View file

@ -0,0 +1,5 @@
summary: Default plan for cronie tests
discover:
how: fmf
execute:
how: tmt

View file

@ -0,0 +1,13 @@
summary: Test for Can't remove crontab from expired accounts
description: ''
contact: Karel Volny <kvolny@redhat.com>
component:
- cronie
test: ./runtest.sh
framework: beakerlib
recommend:
- cronie
duration: 5m
extra-summary:
/CoreOS/cronie/Regression/Can-t-remove-crontab-from-expired-accounts
extra-task: /CoreOS/cronie/Regression/Can-t-remove-crontab-from-expired-accounts

View file

@ -26,7 +26,6 @@
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Include Beaker environment
. /usr/bin/rhts-environment.sh || exit 1
. /usr/share/beakerlib/beakerlib.sh || exit 1
PACKAGE="cronie"

View file

@ -0,0 +1,14 @@
summary: Test for Cron does uid lookups for non-existent users
description: "Bug summary: Cron does uid lookups for non-existent users\n"
contact: Vaclav Danek <vdanek@redhat.com>
component:
- cronie
test: ./runtest.sh
framework: beakerlib
recommend:
- cronie
duration: 5m
extra-summary:
/CoreOS/cronie/Regression/Cron-does-uid-lookups-for-non-existent-users
extra-task:
/CoreOS/cronie/Regression/Cron-does-uid-lookups-for-non-existent-users

View file

@ -26,7 +26,6 @@
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Include Beaker environment
. /usr/bin/rhts-environment.sh || exit 1
. /usr/share/beakerlib/beakerlib.sh || exit 1
PACKAGE="cronie"
@ -39,8 +38,8 @@ rlJournalStart
rlPhaseEnd
rlPhaseStartTest
rlRun "sleep 61 | crontab -" 0
rlRun -s "tail /var/log/cron" 0
rlRun "sleep 61 | crontab -" 0 "when you run crontab -, it creates a tmp file in /var/spool/cron/"
rlRun -s "tail /var/log/cron" 0,1 "crond should not do uid lookup against the name of the file"
rlAssertNotGrep "ORPHAN (no passwd entry)" $rlRun_LOG
rm -f $rlRun_LOG
rlPhaseEnd

View file

@ -1,62 +0,0 @@
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# Makefile of /CoreOS/cronie/Regression/MAILTO-problem-with-anacron
# Description: Test for MAILTO problem with anacron
# Author: Karel Volny <kvolny@redhat.com>
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# Copyright (c) 2017 Red Hat, Inc.
#
# This program is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation, either version 2 of
# the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
# PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see http://www.gnu.org/licenses/.
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
export TEST=/CoreOS/cronie/Regression/MAILTO-problem-with-anacron
export TESTVERSION=1.0
BUILT_FILES=
FILES=$(METADATA) runtest.sh Makefile PURPOSE anacrontab
.PHONY: all install download clean
run: $(FILES) build
./runtest.sh
build: $(BUILT_FILES)
test -x runtest.sh || chmod a+x runtest.sh
clean:
rm -f *~ $(BUILT_FILES)
include /usr/share/rhts/lib/rhts-make.include
$(METADATA): Makefile
@echo "Owner: Karel Volny <kvolny@redhat.com>" > $(METADATA)
@echo "Name: $(TEST)" >> $(METADATA)
@echo "TestVersion: $(TESTVERSION)" >> $(METADATA)
@echo "Path: $(TEST_DIR)" >> $(METADATA)
@echo "Description: Test for MAILTO problem with anacron" >> $(METADATA)
@echo "Type: Regression" >> $(METADATA)
@echo "TestTime: 15m" >> $(METADATA)
@echo "RunFor: cronie" >> $(METADATA)
@echo "Requires: cronie" >> $(METADATA)
@echo "Priority: Normal" >> $(METADATA)
@echo "License: GPLv2+" >> $(METADATA)
@echo "Confidential: no" >> $(METADATA)
@echo "Destructive: no" >> $(METADATA)
rhts-lint $(METADATA)

View file

@ -1,4 +0,0 @@
PURPOSE of /CoreOS/cronie/Regression/MAILTO-problem-with-anacron
Description: Test for MAILTO problem with anacron
Author: Karel Volny <kvolny@redhat.com>
Bug summary: MAILTO problem with anacron

View file

@ -1,5 +0,0 @@
SHELL=/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=testuser1
1 0 test echo "Hello anacron!"

View file

@ -1,155 +0,0 @@
#!/bin/bash
# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# runtest.sh of /CoreOS/cronie/Regression/MAILTO-problem-with-anacron
# Description: Test for MAILTO problem with anacron
# Author: Karel Volny <kvolny@redhat.com>
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# Copyright (c) 2017 Red Hat, Inc.
#
# This program is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation, either version 2 of
# the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
# PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see http://www.gnu.org/licenses/.
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Include Beaker environment
. /usr/bin/rhts-environment.sh || exit 1
. /usr/share/beakerlib/beakerlib.sh || exit 1
PACKAGE="cronie"
TestDir=$PWD
rlJournalStart
rlPhaseStartSetup
rlAssertRpm $PACKAGE
rlRun "TmpDir=\$(mktemp -d)" 0 "Creating tmp directory"
rlRun "pushd $TmpDir"
rlRun "useradd testuser1" 0 "Adding the testing user"
rlFileBackup --clean /var/spool/mail/root /var/log/cron
# stop cron not to interfere with our logs
rlServiceStop crond
rlPhaseEnd
# email should be sent to user specified via MAILTO (testuser1)
rlPhaseStartTest anacronmail
rlRun "truncate --size 0 /var/spool/mail/testuser1" 0 "Truncating mail queue for the user 'testuser1'"
rlRun "truncate --size 0 /var/log/cron" 0 "Truncating cron log"
# DEBUG
echo "anacrontab:"
echo "***********"
cat ${TestDir}/anacrontab
rlRun "anacron -f -n -d -t ${TestDir}/anacrontab" 0 "Forcing anacron to run job"
sleep 5
# DEBUG
echo "/var/spool/mail/testuser1:"
echo "**************************"
cat /var/spool/mail/testuser1
rlAssertGrep "anacron" "/var/spool/mail/testuser1"
rlAssertGrep "To: testuser1" "/var/spool/mail/testuser1"
# DEBUG
echo "/var/log/cron:"
echo "**************"
cat /var/log/cron
rlAssertGrep "\(produced output\)" /var/log/cron
rlAssertNotGrep "not mailing" /var/log/cron -i
rlPhaseEnd
# email should NOT be sent with empty MAILTO
rlPhaseStartTest noanacronmail-empty
rlRun "truncate --size 0 /var/spool/mail/root" 0 "Truncating mail queue for root"
rlRun "truncate --size 0 /var/log/cron" 0 "Truncating cron log"
rlRun "sed -i -e 's/MAILTO=testuser1/MAILTO=/' ${TestDir}/anacrontab" 0 "Removing mailto user from anacrontab"
# DEBUG
echo "anacrontab:"
echo "***********"
cat ${TestDir}/anacrontab
rlRun "anacron -f -n -d -t ${TestDir}/anacrontab" 0 "Forcing anacron to run job"
sleep 5
# DEBUG
echo "/var/spool/mail/root:"
echo "*********************"
cat /var/spool/mail/root
rlAssertNotGrep "anacron" "/var/spool/mail/root"
# DEBUG
echo "/var/log/cron:"
echo "**************"
cat /var/log/cron
rlAssertGrep "\(produced output\)" /var/log/cron
rlAssertGrep "not mailing" /var/log/cron -i
rlPhaseEnd
# email should be sent to nonexisting user double-doublequotes, as the string after '=' is treated literally
rlPhaseStartTest anacronmail-quotes
rlRun "truncate --size 0 /var/spool/mail/root" 0 "Truncating mail queue for root"
rlRun "truncate --size 0 /var/log/cron" 0 "Truncating cron log"
rlRun "sed -i -e 's/MAILTO=/MAILTO=\"\"/' ${TestDir}/anacrontab" 0 "Setting mailto to double quotes in anacrontab"
# DEBUG
echo "anacrontab:"
echo "***********"
cat ${TestDir}/anacrontab
rlRun "anacron -f -n -d -t ${TestDir}/anacrontab" 0 "Forcing anacron to run job"
sleep 5
# DEBUG
echo "/var/spool/mail/root:"
echo "*********************"
cat /var/spool/mail/root
rlAssertGrep "anacron" "/var/spool/mail/root"
#rlAssertGrep "To: \"\"" "/var/spool/mail/root"
# ^ this doesn't work in Beaker for some reason, check the quotes in 'Received: ... for "";'
rlAssertGrep "for \"\"" "/var/spool/mail/root"
# DEBUG
echo "/var/log/cron:"
echo "**************"
cat /var/log/cron
rlAssertGrep "\(produced output\)" /var/log/cron
rlAssertNotGrep "not mailing" /var/log/cron -i
rlPhaseEnd
# email should be sent to the user running anacron, when MAILTO is missing
rlPhaseStartTest anacronmail-missing
rlRun "truncate --size 0 /var/spool/mail/root" 0 "Truncating mail queue for root"
rlRun "truncate --size 0 /var/log/cron" 0 "Truncating cron log"
rlRun "sed -i -e '/MAILTO/d' ${TestDir}/anacrontab" 0 "Removing mailto from anacrontab"
# DEBUG
echo "anacrontab:"
echo "***********"
cat ${TestDir}/anacrontab
rlRun "anacron -f -n -d -t ${TestDir}/anacrontab" 0 "Forcing anacron to run job"
sleep 5
# DEBUG
echo "/var/spool/mail/root:"
echo "*********************"
cat /var/spool/mail/root
rlAssertGrep "anacron" "/var/spool/mail/root"
# DEBUG
echo "/var/log/cron:"
echo "**************"
cat /var/log/cron
rlAssertGrep "\(produced output\)" /var/log/cron
rlAssertNotGrep "not mailing" /var/log/cron -i
rlPhaseEnd
rlPhaseStartCleanup
rlRun "userdel testuser1"
rlServiceRestore crond
rlFileRestore
rlRun "popd"
rlRun "rm -r $TmpDir" 0 "Removing tmp directory"
#avoid systemd failing to start crond due start-limit
sleep 10
rlPhaseEnd
rlJournalPrintText
rlJournalEnd

View file

@ -0,0 +1,13 @@
summary: What the test does
description: ''
contact: Jakub Prokes <jprokes@redhat.com>
component:
- cronie
test: ./runtest.sh
framework: beakerlib
recommend:
- cronie
- elfutils
duration: 5m
extra-summary: /CoreOS/Regression/Make-crontab-a-PIE
extra-task: /CoreOS/Regression/Make-crontab-a-PIE

1
tests/Make-crontab-a-PIE/runtest.sh Normal file → Executable file
View file

@ -27,7 +27,6 @@
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Include Beaker environment
. /usr/bin/rhts-environment.sh || exit 1
. /usr/share/beakerlib/beakerlib.sh || exit 1
PACKAGES="cronie vixie-cron"

View file

@ -0,0 +1,14 @@
summary: try some invalid configs for anacron to check config parser
description: ''
contact: Jakub Prokes <jprokes@redhat.com>
component:
- cronie
test: ./runtest.sh
framework: beakerlib
recommend:
- cronie
duration: 5m
extra-summary:
/CoreOS/cronie/Regression/anacron-segfaults-with-certain-config-data-2
extra-task:
/CoreOS/cronie/Regression/anacron-segfaults-with-certain-config-data-2

View file

@ -26,7 +26,6 @@
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Include Beaker environment
. /usr/bin/rhts-environment.sh || exit 1
. /usr/share/beakerlib/beakerlib.sh || exit 1
assertRpms() {

View file

@ -0,0 +1,13 @@
summary: Test for anacron segfaults with certain config data
description: ''
contact: Robin Hack <rhack@redhat.com>
component:
- cronie
test: ./runtest.sh
framework: beakerlib
recommend:
- cronie
duration: 20m
extra-summary:
/CoreOS/cronie/Regression/anacron-segfaults-with-certain-config-data
extra-task: /CoreOS/cronie/Regression/anacron-segfaults-with-certain-config-data

View file

@ -26,7 +26,6 @@
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Include Beaker environment
. /usr/bin/rhts-environment.sh || exit 1
. /usr/share/beakerlib/beakerlib.sh || exit 1
PACKAGE="cronie"

1
tests/config-parsing-issue/runtest.sh Normal file → Executable file
View file

@ -26,7 +26,6 @@
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Include Beaker environment
. /usr/bin/rhts-environment.sh || exit 1
. /usr/share/beakerlib/beakerlib.sh || exit 1
PACKAGE="cronie-anacron"

View file

@ -0,0 +1,14 @@
summary: Test for cron daemon fails to log that it is shutting down.
description: "Bug summary: cron daemon fails to log that it is shutting down.\n"
contact: Robin Hack <rhack@redhat.com>
component:
- cronie
test: ./runtest.sh
framework: beakerlib
recommend:
- cronie
duration: 20m
extra-summary:
/CoreOS/cronie/Regression/cron-daemon-fails-to-log-that-it-is-shutting-down
extra-task:
/CoreOS/cronie/Regression/cron-daemon-fails-to-log-that-it-is-shutting-down

View file

@ -26,7 +26,6 @@
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Include Beaker environment
. /usr/bin/rhts-environment.sh || exit 1
. /usr/share/beakerlib/beakerlib.sh || exit 1
PACKAGE="cronie"

View file

@ -0,0 +1,13 @@
summary: Test for crond is missing RELRO flags
description: "Bug summary: crond is missing RELRO flags\n\n"
contact: Martin Cermak <mcermak@redhat.com>
component:
- cronie
test: ./runtest.sh
framework: beakerlib
recommend:
- cronie
- elfutils
duration: 15m
extra-summary: /CoreOS/cronie/Regression/crond-is-missing-RELRO-flags
extra-task: /CoreOS/cronie/Regression/crond-is-missing-RELRO-flags

1
tests/crond-is-missing-RELRO-flags/runtest.sh Normal file → Executable file
View file

@ -27,7 +27,6 @@
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Include rhts environment
. /usr/bin/rhts-environment.sh || exit 1
. /usr/share/beakerlib/beakerlib.sh || exit 1
PACKAGE="cronie"

View file

@ -0,0 +1,15 @@
summary: Test for crond subtask abnormal termination removes pid
description: "Bug summary: crond subtask abnormal termination removes pid file in
error\n"
contact: Robin Hack <rhack@redhat.com>
component:
- cronie
test: ./runtest.sh
framework: beakerlib
recommend:
- cronie
duration: 20m
extra-summary:
/CoreOS/cronie/Regression/crond-subtask-abnormal-termination-removes-pid-file-in-error
extra-task:
/CoreOS/cronie/Regression/crond-subtask-abnormal-termination-removes-pid-file-in-error

View file

@ -26,7 +26,6 @@
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Include Beaker environment
. /usr/bin/rhts-environment.sh || exit 1
. /usr/share/beakerlib/beakerlib.sh || exit 1
PACKAGE="cronie"

View file

@ -1,63 +0,0 @@
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# Makefile of /CoreOS/cronie/Regression/cronie-jobs-environment
# Description: testing EUID with jobs are executed and if LANG is correctly set
# Author: Jakub Prokes <jprokes@redhat.com>
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# Copyright (c) 2013 Red Hat, Inc. All rights reserved.
#
# This copyrighted material is made available to anyone wishing
# to use, modify, copy, or redistribute it subject to the terms
# and conditions of the GNU General Public License version 2.
#
# This program is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
# PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public
# License along with this program; if not, write to the Free
# Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301, USA.
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
export TEST=/CoreOS/cronie/Regression/cronie-jobs-environment
export TESTVERSION=1.0
BUILT_FILES=
FILES=$(METADATA) runtest.sh Makefile PURPOSE libfaketime-0.9.1.tar.gz crontab.temp cron_test.sh
.PHONY: all install download clean
run: $(FILES) build
./runtest.sh
build: $(BUILT_FILES)
test -x runtest.sh || chmod a+x runtest.sh
clean:
rm -f *~ $(BUILT_FILES)
include /usr/share/rhts/lib/rhts-make.include
$(METADATA): Makefile
@echo "Owner: Jakub Prokes <jprokes@redhat.com>" > $(METADATA)
@echo "Name: $(TEST)" >> $(METADATA)
@echo "TestVersion: $(TESTVERSION)" >> $(METADATA)
@echo "Path: $(TEST_DIR)" >> $(METADATA)
@echo "Description: testing EUID with jobs are executed and if LANG is correctly set" >> $(METADATA)
@echo "Type: Regression" >> $(METADATA)
@echo "TestTime: 10m" >> $(METADATA)
@echo "RunFor: cronie" >> $(METADATA)
@echo "Requires: cronie" >> $(METADATA)
@echo "Priority: Normal" >> $(METADATA)
@echo "License: GPLv2" >> $(METADATA)
@echo "Confidential: no" >> $(METADATA)
@echo "Destructive: no" >> $(METADATA)
rhts-lint $(METADATA)

View file

@ -1,3 +0,0 @@
PURPOSE of /CoreOS/cronie/Regression/cronie-jobs-environment
Description: testing EUID with jobs are executed and if LANG is correctly set
Author: Jakub Prokes <jprokes@redhat.com>

View file

@ -1,5 +0,0 @@
#!/bin/bash
printf "LANG=$LANG\n" > /tmp/cronie-jobs-environment.log;
printf "EUID=$EUID\n" >> /tmp/cronie-jobs-environment.log;

View file

@ -1,12 +0,0 @@
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * command to be executed
CRON_CORRECT_MAIL_HEADER=1
* * * * * %TMPDIR/cron_test.sh

View file

@ -1,124 +0,0 @@
#!/bin/bash
# vim: dict=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# runtest.sh of /CoreOS/cronie/Regression/cronie-jobs-environment
# Description: testing EUID with jobs are executed and if LANG is correctly set
# Author: Jakub Prokes <jprokes@redhat.com>
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# Copyright (c) 2013 Red Hat, Inc. All rights reserved.
#
# This copyrighted material is made available to anyone wishing
# to use, modify, copy, or redistribute it subject to the terms
# and conditions of the GNU General Public License version 2.
#
# This program is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
# PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public
# License along with this program; if not, write to the Free
# Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301, USA.
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Include Beaker environment
. /usr/bin/rhts-environment.sh || exit 1
. /usr/share/beakerlib/beakerlib.sh || exit 1
## Is nice to know when things going wrong
trap 'errorHandler ${LINENO}' ERR;
function errorHandler() {
local code="${?}";
local lineNO="$1";
case $code in
127)
rlFail "Command not found on line $lineNO"
;;
*)
rlFail "Unhandled error $code near line $lineNO";
;;
esac
}
function makeUser() {
local userName="$(tr -dc "[:lower:]" < /dev/urandom | head -c 5 | sed 's/^/qa_/')";
while getent passwd $userName; do
userName="$(tr -dc "[:lower:]" < /dev/urandom | head -c 5 | sed 's/^/qa_/')";
done
useradd -d $tmpDir $userName;
echo $userName;
}
PACKAGE="cronie"
declare -r LIBFAKETTIMEPACKAGE="libfaketime-0.9.1.tar.gz";
declare -r LIBFAKETIME="libfaketime.so.1";
rlJournalStart
rlPhaseStartSetup "Setup test environment"
rlAssertRpm $PACKAGE
rlRun "tmpDir=\$(mktemp -d)" 0 "Creating tmp directory";
testDir="$(pwd)";
rlRun "chmod 755 $tmpDir" 0 "Setting permissions for tmp directory";
ls -lahdZ $tmpDir;
rlRun "pushd $tmpDir"
testUser="$(makeUser)";
rlRun "getent passwd $testUser" 0 "Test user $testUser created";
rlServiceStop crond;
rlPhaseEnd
rlPhaseStartSetup "Prepare libfaketime";
rlRun "cp ${testDir}/$LIBFAKETTIMEPACKAGE ./" 0 "Get library sources";
rlRun "tar -xvzf $LIBFAKETTIMEPACKAGE" 0 "Unpack library sources";
pushd ${LIBFAKETTIMEPACKAGE%.tar.gz};
rlRun "make &>/dev/null" 0 "Building library from sources";
rlRun "cp ./src/$LIBFAKETIME ../" 0 "Coping library to working directory";
popd;
LD_PRELOAD=./libfaketime.so.1 FAKETIME='1994-07-29 12:00:01' date +%G | { year="$(cat)"; [[ $year -eq 1994 ]]; };
rlAssert0 "Library preloading working well" $?;
rlPhaseEnd
rlPhaseStartSetup "Prepare tests";
rlRun "sed 's#%TMPDIR#$tmpDir#' $testDir/crontab.temp > crontab.source" #0 "Crontab prepared from template";
rlRun "crontab -u $testUser crontab.source" 0 "Set crontab for test user";
crontab -lu $testUser;
rlRun "cp $testDir/cron_test.sh ./" 0 "Copyed script for cron job";
rlRun "chmod a+x cron_test.sh" 0 "Permissions to executed set";
rlRun "[[ -e /var/spool/mail/$testUser ]] && printf '' > /var/spool/mail/$testUser" 0 "Clean up mails"
rlLog "Execute crond with faked time";
LD_PRELOAD=./libfaketime.so.1 FAKETIME='@1994-07-29 12:12:50' /usr/sbin/crond -n -x sch &
cronPID=$!;
pstree -Aph
rlRun "kill -0 $cronPID" 0 "crond is running";
rlLog "Security timeout for 30 sec to ensure all configs are loaded and crontab is succesfully processed";
sleep 30;
rlPhaseEnd
rlPhaseStartTest "cronie drops \$LANG and never passes it on to jobs run"
rlRun "[[ $(sed -n '/^LANG/s/LANG=//p' /tmp/cronie-jobs-environment.log) = $LANG ]]" 0 "LANG is set"
rlPhaseEnd
rlPhaseStartTest "cronie doesn't drop privileges before popen"
rlRun "[[ $(sed -n '/^EUID/s/EUID=//p' /tmp/cronie-jobs-environment.log) -eq $(id -u $testUser) ]]" 0 \
"Crontab is executed with correct EUID";
rlPhaseEnd
rlPhaseStartCleanup
rlRun "kill $cronPID" 0 "Terminating crond"
rlRun "crontab -ru $testUser" 0 "Crontab removed"
rlRun "popd"
rlRun "rm -r $tmpDir" 0 "Removing tmp directory"
rlRun "userdel -rf $testUser";
rlServiceRestore crond;
#avoid systemd failing to start crond due start-limit
sleep 10
rlPhaseEnd
rlJournalPrintText
rlJournalEnd

View file

@ -0,0 +1,14 @@
summary: Test for Cron does uid lookups for non-existent users
description: "Bug summary: Cron does uid lookups for non-existent users\n"
contact: Jakub Prokes <jprokes@redhat.com>
component:
- cronie
test: ./runtest.sh
framework: beakerlib
recommend:
- cronie
duration: 10m
extra-summary:
/CoreOS/cronie/Regression/crontab-can-invoke-lookup-for-nonexisted-user
extra-task:
/CoreOS/cronie/Regression/crontab-can-invoke-lookup-for-nonexisted-user

View file

@ -26,7 +26,6 @@
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Include Beaker environment
. /usr/bin/rhts-environment.sh || exit 1
. /usr/share/beakerlib/beakerlib.sh || exit 1
PACKAGE="cronie"

View file

@ -0,0 +1,12 @@
summary: What the test does
description: ''
contact: Jakub Prokes <jprokes@redhat.com>
component:
- cronie
test: ./runtest.sh
framework: beakerlib
recommend:
- cronie
duration: 5m
extra-summary: /CoreOS/cronie/Regression/crontab-has-wrong-permissions
extra-task: /CoreOS/cronie/Regression/crontab-has-wrong-permissions

1
tests/crontab-has-wrong-permissions/runtest.sh Normal file → Executable file
View file

@ -27,7 +27,6 @@
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Include Beaker environment
. /usr/bin/rhts-environment.sh || exit 1
. /usr/share/beakerlib/beakerlib.sh || exit 1
PACKAGES="cronie vixie-cron"

View file

@ -0,0 +1,12 @@
summary: Test for echos "OK" twice in init script
description: ''
contact: Martin Cermak <mcermak@redhat.com>
component:
- cronie
test: ./runtest.sh
framework: beakerlib
recommend:
- cronie
duration: 15m
extra-summary: /CoreOS/cronie/Regression/echos-OK-twice-in-init-script
extra-task: /CoreOS/cronie/Regression/echos-OK-twice-in-init-script

57
tests/echos-OK-twice-in-init-script/runtest.sh Normal file → Executable file
View file

@ -27,50 +27,45 @@
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Include rhts environment
. /usr/bin/rhts-environment.sh
. /usr/lib/beakerlib/beakerlib.sh
. /usr/share/beakerlib/beakerlib.sh || exit 1
PACKAGE="cronie"
function makeUser() {
local userName="$(tr -dc "[:lower:]" < /dev/urandom | head -c 5 | sed 's/^/qa_/')";
while getent passwd $userName; do
userName="$(tr -dc "[:lower:]" < /dev/urandom | head -c 5 | sed 's/^/qa_/')";
done
useradd -d $tmpDir $userName;
echo $userName;
}
rlJournalStart
rlPhaseStartSetup
rlAssertRpm $PACKAGE
rlRun "TEMPDIR=\`mktemp -d\`" 0 "Creating tmp directory"
rlRun "pushd $TEMPDIR"
rlFileBackup "/etc/rc.d/init.d/crond"
rlServiceStop crond
cat > /etc/rc.d/init.d/functions2 <<EOF1
success() {
echo OK >> $TEMPDIR/log.txt
}
EOF1
rlRun "cat /etc/rc.d/init.d/functions2"
sed -i "s/^\..*$/\0\n\. \/etc\/rc\.d\/init\.d\/functions2/" /etc/rc.d/init.d/crond
rlRun "grep ^\\\. /etc/rc.d/init.d/crond"
rlRun "tmpDir=\$(mktemp -d)" 0 "Creating tmp directory";
testUser="$(makeUser)";
rlPhaseEnd
rlPhaseStartTest
rlAssertNotExists log.txt
rlServiceStart crond
rlAssertExists log.txt
rlRun "TIMES_PRINTED_OK=`grep OK log.txt | wc -l`"
rlRun "test $TIMES_PRINTED_OK -eq 1"
rlServiceStop crond
rlRun -s "service crond restart"
rlAssertNotGrep "FAILED" $rlRun_LOG
rlPhaseEnd
if ! rpm -q systemd &>/dev/null; then
rlPhaseStartTest
su -l $testUser -c "service crond restart";
rlAssertEquals "Expected result of call initscript by unprivileged user is 4" $? 4
rlPhaseEnd
fi
rlPhaseStartCleanup
rlBundleLogs TESTLOGS /etc/rc.d/init.d/functions2 /etc/rc.d/init.d/crond
rlRun "rm -f /etc/rc.d/init.d/functions2"
rlFileRestore
rm -f $rlRun_LOG
rm -rf $tmpDir;
userdel -rf $testUser;
rlServiceRestore crond
rlRun "popd"
rlRun "rm -r $TEMPDIR" 0 "Removing tmp directory"
#avoid systemd failing to start crond due start-limit
sleep 10
rlPhaseEnd
rlJournalPrintText
rlJournalEnd

View file

@ -0,0 +1,12 @@
summary: Testing some init script failures
description: ''
contact: Jakub Prokes <jprokes@redhat.com>
component:
- cronie
test: ./runtest.sh
framework: beakerlib
recommend:
- cronie
duration: 5m
extra-summary: /CoreOS/cronie/Regression/init-script-failure
extra-task: /CoreOS/cronie/Regression/init-script-failure

1
tests/init-script-failure/runtest.sh Normal file → Executable file
View file

@ -27,7 +27,6 @@
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Include Beaker environment
. /usr/bin/rhts-environment.sh || exit 1
. /usr/share/beakerlib/beakerlib.sh || exit 1
PACKAGE="cronie"

View file

@ -0,0 +1,12 @@
summary: Init script should meet LSB specifications
description: ''
contact: Petr Sklenar <psklenar@redhat.com>
component:
- cronie
test: ./runtest.sh
framework: shell
recommend:
- cronie
duration: 5m
extra-summary: /CoreOS/cronie/Sanity/init-script-LSB
extra-task: /CoreOS/cronie/Sanity/init-script-LSB

3
tests/init-scripts-LSB/runtest.sh Normal file → Executable file
View file

@ -27,8 +27,7 @@
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Include rhts environment
. /usr/bin/rhts-environment.sh
. /usr/share/rhts-library/rhtslib.sh
. /usr/share/beakerlib/beakerlib.sh || exit 1
PACKAGE="cronie"

View file

@ -1,63 +0,0 @@
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# Makefile of /CoreOS/cronie/Regression/ldap-users
# Description: Test for cronie not creating jobs for ldap users if ldap
# Author: Jakub Prokes <jprokes@redhat.com>
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# Copyright (c) 2016 Red Hat, Inc.
#
# This program is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation, either version 2 of
# the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
# PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see http://www.gnu.org/licenses/.
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
export TEST=/CoreOS/cronie/Regression/ldap-users
export TESTVERSION=1.0
BUILT_FILES=
FILES=$(METADATA) runtest.sh Makefile PURPOSE data.ldif slapd.conf user1.cron
.PHONY: all install download clean
run: $(FILES) build
./runtest.sh
build: $(BUILT_FILES)
test -x runtest.sh || chmod a+x runtest.sh
clean:
rm -f *~ $(BUILT_FILES)
include /usr/share/rhts/lib/rhts-make.include
$(METADATA): Makefile
@echo "Owner: Jakub Prokes <jprokes@redhat.com>" > $(METADATA)
@echo "Name: $(TEST)" >> $(METADATA)
@echo "TestVersion: $(TESTVERSION)" >> $(METADATA)
@echo "Path: $(TEST_DIR)" >> $(METADATA)
@echo "Description: Test for cronie not creating jobs for ldap users if ldap" >> $(METADATA)
@echo "Type: Regression" >> $(METADATA)
@echo "TestTime: 10m" >> $(METADATA)
@echo "RunFor: cronie openldap" >> $(METADATA)
@echo "Requires: cronie authconfig openldap openldap-servers openldap-clients sssd sssd-ldap" >> $(METADATA)
@echo "RhtsRequires: library(authconfig/basic)" >> $(METADATA)
@echo "Priority: Normal" >> $(METADATA)
@echo "License: GPLv2+" >> $(METADATA)
@echo "Confidential: no" >> $(METADATA)
@echo "Destructive: no" >> $(METADATA)
rhts-lint $(METADATA)

View file

@ -1,5 +0,0 @@
PURPOSE of /CoreOS/cronie/Regression/ldap-users
Description: Test for cronie not creating jobs for ldap users if ldap
Author: Jakub Prokes <jprokes@redhat.com>
Bug summary: cronie not creating jobs for ldap users if ldap server is temporarily down.

View file

@ -1,26 +0,0 @@
dn: dc=foo,dc=bar,dc=com
dc: foo
objectClass: top
objectClass: domain
dn: ou=people,dc=foo,dc=bar,dc=com
ou: people
objectClass: top
objectClass: organizationalUnit
dn: uid=user1,ou=people,dc=foo,dc=bar,dc=com
uid: user1
cn: user1
objectClass: account
objectClass: posixAccount
objectClass: top
objectClass: shadowAccount
userPassword: {CRYPT}hebc0ErNA0uXY
shadowLastChange: 14460
shadowMax: 99999
shadowWarning: 7
loginShell: /bin/bash
uidNumber: 1001
gidNumber: 1000
homeDirectory: /home/ldap/user1
gecos: user1

View file

@ -1,133 +0,0 @@
#!/bin/bash
# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# runtest.sh of /CoreOS/cronie/Regression/ldap-users
# Description: Test for cronie not creating jobs for ldap users if ldap
# Author: Jakub Prokes <jprokes@redhat.com>
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# Copyright (c) 2016 Red Hat, Inc.
#
# This program is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation, either version 2 of
# the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
# PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see http://www.gnu.org/licenses/.
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Include Beaker environment
. /usr/bin/rhts-environment.sh || exit 1
. /usr/share/beakerlib/beakerlib.sh || exit 1
PACKAGE="cronie"
rlJournalStart
rlPhaseStart FAIL "General Setup"
rlAssertRpm $PACKAGE
rlRun "tmpDir=\$(mktemp -d)" 0 "Creating tmp directory"
rlRun "testDir=\"$(pwd)\""
rlRun "pushd $tmpDir"
rlRun "rlImport --all"
rlServiceStart "crond"
rlFileBackup /var/log/cron
echo > /var/log/cron
/bin/kill -HUP $(cat /var/run/syslogd.pid)
rlRun "getent passwd user1" 2
rlPhaseEnd
rlPhaseStart FAIL "LDAP Server Setup"
rlServiceStop "slapd"
rlFileBackup --clean "/etc/openldap"
rlFileBackup --clean "/var/run/openldap"
rlFileBackup --clean "/var/lib/ldap"
rlRun "rm -rf /etc/openldap/slapd.d/* /var/lib/ldap/* /var/run/openldap/*" 0 "Cleaning LDAP directories"
rlRun "slapadd -l ${testDir}/data.ldif -f ${testDir}/slapd.conf" 0 "Importing testing user into LDAP"
rlRun "chown ldap:ldap /var/run/openldap/*" 0 "Fixing permissions on '/var/run/openldap/*'"
rlRun "restorecon -Rv /etc/" 0 "Fixing SELinux contexts"
rlRun "slaptest -f ${testDir}/slapd.conf -F /etc/openldap/slapd.d" 0 "Importing LDAP configuration"
rlRun "chown -R ldap:ldap /etc/openldap/slapd.d" 0 "Fixing permissions on '/etc/openldap/slapd.d'"
rlServiceStart "slapd"
rlPhaseEnd
rlPhaseStart FAIL "LDAP auth setup"
rlServiceStop "sssd"
rlRun "authconfig_setup"
rlRun "authconfig --savebackup=CoreOS_cronie_Regression_ldap-users"
rlRun "authconfig --enableldap --enableldapauth --ldapserver=ldap://127.0.0.1/ \
--ldapbasedn=dc=foo,dc=bar,dc=com --update"
rlRun "getent passwd user1"
rlRun "mkdir -p /home/ldap/user1"
rlRun "chown user1 /home/ldap/user1"
rlPhaseEnd
rlPhaseStartTest
rlRun "su user1 -c 'crontab ${testDir}/user1.cron'" 0 "Creating user cronjob" && \
cat ${testDir}/user1.cron;
rlFileBackup /etc/crontab
rlRun "rlServiceStop slapd"
rlRun "service sssd stop"
rlRun "rm -rf /var/lib/sss/db/*"
rlRun "service sssd start"
rlRun "getent passwd user1" 2
rlRun "echo \"* * * * * user1 /bin/echo foo > /tmp/cron.out\" > /etc/crontab" 0 \
"Create record in system crontab"
cat /etc/crontab
rlRun "service crond restart"
rlRun "rlServiceStart slapd"
rlRun "service sssd stop"
rlRun "rm -rf /var/lib/sss/db/*"
rlRun "service sssd start"
waitCounter=60;
echo "Waiting for LDAP"
while ! getent passwd user1; do
sleep 1;
echo -n .
[[ waitCounter -le 0 ]] && break;
waitCounter=$((waitCounter-1));
done
echo;
rlRun "getent passwd user1"
rm -f /home/ldap/user1/cron.out
echo "Waiting for cronjob execution"
sleep 65;
if rlRun "[[ -f /home/ldap/user1/cron.out ]]" 0 "User cronjob executed successfully"; then
rlAssertGrep "foo" /home/ldap/user1/cron.out;
fi
if rlRun "[[ -f /tmp/cron.out ]]" 0 "Crontab cronjob executed successfully"; then
rlAssertGrep "foo" /tmp/cron.out;
fi
rlRun "service crond stop"
cat /var/log/cron
rlPhaseEnd
rlPhaseStart WARN "Cleanup"
rlRun "service crond restart"
rlRun "crontab -r -u user1"
rlRun "rlServiceStop slapd"
rlRun "authconfig --disableldap --disableldapauth --update"
rlRun "authconfig --restorebackup=CoreOS_cronie_Regression_ldap-users"
rlRun "authconfig_cleanup"
rlRun "popd"
rlRun "rm -r $tmpDir" 0 "Removing tmp directory"
rlRun "rm -r /home/ldap/user1"
rlRun "rm -r /home/ldap"
rlFileRestore
rlServiceRestore slapd
rlServiceRestore sssd
/bin/kill -HUP $(cat /var/run/syslogd.pid)
rlServiceRestore crond
#avoid systemd failing to start crond due start-limit
sleep 10
rlPhaseEnd
rlJournalPrintText
rlJournalEnd

View file

@ -1,32 +0,0 @@
include /etc/openldap/schema/core.schema
include /etc/openldap/schema/cosine.schema
include /etc/openldap/schema/inetorgperson.schema
include /etc/openldap/schema/nis.schema
allow bind_v2
pidfile /var/run/openldap/slapd.pid
argsfile /var/run/openldap/slapd.args
database bdb
suffix "dc=foo,dc=bar,dc=com"
rootdn "cn=admin,dc=foo,dc=bar,dc=com"
# Password is 'x'.
rootpw {SSHA}GPhzu7pTYP4I+nGeujpBkODiPxX0v8n8
directory /var/run/openldap/
index objectClass eq,pres
index ou,cn,mail,surname,givenname eq,pres,sub
index uidNumber,gidNumber,loginShell eq,pres
index uid,memberUid eq,pres,sub
index nisMapName,nisMapEntry eq,pres,sub
index entryCSN,entryUUID eq
access to attrs=shadowLastChange,userPassword
by self write
by * auth
access to *
by * read

View file

@ -1,10 +0,0 @@
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * command to be executed
* * * * * /bin/echo foo > $HOME/cron.out

View file

@ -0,0 +1,14 @@
summary: When crond is running in multiple instance, then cron jobs are executed
multiple times. Is neccesary to prevent multiple instances of crond running
in time.
description: ''
contact: Jakub Prokes <jprokes@redhat.com>
component:
- cronie
test: ./runtest.sh
framework: beakerlib
recommend:
- cronie
duration: 5m
extra-summary: /CoreOS/cronie/Regression/only-one-running-instance-in-time
extra-task: /CoreOS/cronie/Regression/only-one-running-instance-in-time

1
tests/only-one-running-instance-in-time/runtest.sh Normal file → Executable file
View file

@ -27,7 +27,6 @@
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Include Beaker environment
. /usr/bin/rhts-environment.sh || exit 1
. /usr/share/beakerlib/beakerlib.sh || exit 1
PACKAGE="cronie"

View file

@ -0,0 +1,13 @@
summary: Test for cronie has a bug when run with syslog flag
description: "Bug summary: cronie has a bug when run with syslog flag\n"
contact: Jakub Prokes <jprokes@redhat.com>
component:
- cronie
test: ./runtest.sh
framework: beakerlib
recommend:
- cronie
- rsyslog
duration: 10m
extra-summary: /CoreOS/cronie/Regression/run-with-syslog-flag
extra-task: /CoreOS/cronie/Regression/run-with-syslog-flag

1
tests/run-with-syslog-flag/runtest.sh Normal file → Executable file
View file

@ -26,7 +26,6 @@
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Include Beaker environment
. /usr/bin/rhts-environment.sh || exit 1
. /usr/share/beakerlib/beakerlib.sh || exit 1
PACKAGE="cronie"

View file

@ -1,82 +0,0 @@
---
# Tests to run in a classic environment
- hosts: localhost
roles:
- role: standard-test-beakerlib
tags:
- classic
tests:
- anacron-segfaults-with-certain-config-data
- anacron-segfaults-with-certain-config-data-2
- Can-t-remove-crontab-from-expired-accounts
- Cron-does-uid-lookups-for-non-existent-users
- cron-daemon-fails-to-log-that-it-is-shutting-down
- crond-is-missing-RELRO-flags
- crond-subtask-abnormal-termination-removes-pid-file-in-error
- config-parsing-issue
- cronie-jobs-environment
- crontab-can-invoke-lookup-for-nonexisted-user
- crontab-has-wrong-permissions
# - echos-OK-twice-in-init-script Does not work on Fedora-26
- init-script-failure
# - init-scripts-LSB Does not work on Fedora-26
# - ldap-users Does not work on Fedora-26
# - MAILTO-problem-with-anacron Does not work on Fedora-26
- Make-crontab-a-PIE
- only-one-running-instance-in-time
- run-with-syslog-flag
- usr-bin-crontab-has-wrong-permissions
required_packages:
- authconfig # ldap-users needs this package
- findutils # beakerlib needs find command
- elfutils # crond-is-missing-RELRO-flags needs eu-readelf tool
- gcc # cronie-jobs-environment needs gcc command
- openldap # ldap-users needs this package
- openldap-servers # ldap-users needs this package
- openldap-clients # ldap-users needs this package
- procps-ng # multiple tests need ps and pidof commands
- psmisc # multiple tests need killall command
- rsyslog # run-with-syslog-flag requires this package
- sendmail # MAILTO-problem-with-anacron needs sendmail command
- sssd # ldap-users needs this package
- sssd-ldap # ldap-users needs this package
# Tests to run in a container environment
- hosts: localhost
roles:
- role: standard-test-beakerlib
tags:
- container
tests:
- Can-t-remove-crontab-from-expired-accounts
- Make-crontab-a-PIE
- config-parsing-issue
- crond-is-missing-RELRO-flags
- crontab-has-wrong-permissions
- usr-bin-crontab-has-wrong-permissions
required_packages:
- cronie # everything needs cronie package
- findutils # beakerlib needs find command
- procps-ng # multiple tests need ps and pidof commands
- psmisc # multiple tests need killall command
- elfutils # multiple tests need eu-readelf tool
# Tests to run in an Atomic Host VM
- hosts: localhost
roles:
- role: standard-test-beakerlib
tags:
- atomic
tests:
- Can-t-remove-crontab-from-expired-accounts
- Make-crontab-a-PIE
- config-parsing-issue
- crond-is-missing-RELRO-flags
- crontab-has-wrong-permissions
- usr-bin-crontab-has-wrong-permissions
required_packages:
- cronie # everything needs cronie package
- findutils # beakerlib needs find command
- procps-ng # multiple tests need ps and pidof commands
- psmisc # multiple tests need killall command
- elfutils # multiple tests need eu-readelf tool

View file

@ -0,0 +1,12 @@
summary: Test for /usr/bin/crontab has wrong permissions
description: "Bug summary: /usr/bin/crontab has wrong permissions\n\n"
contact: Martin Cermak <mcermak@redhat.com>
component:
- cronie
test: ./runtest.sh
framework: beakerlib
recommend:
- cronie
duration: 15m
extra-summary: /CoreOS/cronie/Regression/usr-bin-crontab-has-wrong-permissions
extra-task: /CoreOS/cronie/Regression/usr-bin-crontab-has-wrong-permissions

3
tests/usr-bin-crontab-has-wrong-permissions/runtest.sh Normal file → Executable file
View file

@ -27,8 +27,7 @@
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Include rhts environment
. /usr/bin/rhts-environment.sh
. /usr/lib/beakerlib/beakerlib.sh
. /usr/share/beakerlib/beakerlib.sh || exit 1
PACKAGE="cronie"