summaryrefslogtreecommitdiffstats
path: root/usr.sbin/cron
diff options
context:
space:
mode:
authordds <dds@FreeBSD.org>2004-09-14 19:01:19 +0000
committerdds <dds@FreeBSD.org>2004-09-14 19:01:19 +0000
commit19e905d90f22055d474c4b6e75204f4864d69eb7 (patch)
tree588889350f69c71553e507851a3422ba0da4ae78 /usr.sbin/cron
parent64433e6598e2215959c1a572ab2b00fd51c91d2f (diff)
downloadFreeBSD-src-19e905d90f22055d474c4b6e75204f4864d69eb7.zip
FreeBSD-src-19e905d90f22055d474c4b6e75204f4864d69eb7.tar.gz
Ensure that edits that do not span a clock tick are not lost.
PR: bin/22612 MT5: 4 weeks MT4: 2 weeks
Diffstat (limited to 'usr.sbin/cron')
-rw-r--r--usr.sbin/cron/crontab/Makefile4
-rw-r--r--usr.sbin/cron/crontab/crontab.c17
2 files changed, 15 insertions, 6 deletions
diff --git a/usr.sbin/cron/crontab/Makefile b/usr.sbin/cron/crontab/Makefile
index 96a4bd6..2c1bfc0 100644
--- a/usr.sbin/cron/crontab/Makefile
+++ b/usr.sbin/cron/crontab/Makefile
@@ -10,7 +10,7 @@ INSTALLFLAGS=-fschg
CFLAGS+= -I${.CURDIR}/../cron
-DPADD= ${LIBCRON} ${LIBUTIL}
-LDADD= ${LIBCRON} -lutil
+DPADD= ${LIBCRON} ${LIBMD} ${LIBUTIL}
+LDADD= ${LIBCRON} -lmd -lutil
.include <bsd.prog.mk>
diff --git a/usr.sbin/cron/crontab/crontab.c b/usr.sbin/cron/crontab/crontab.c
index 50268d6..5d61ea7 100644
--- a/usr.sbin/cron/crontab/crontab.c
+++ b/usr.sbin/cron/crontab/crontab.c
@@ -31,6 +31,7 @@ static const char rcsid[] =
#include "cron.h"
#include <errno.h>
#include <fcntl.h>
+#include <md5.h>
#include <paths.h>
#include <sys/file.h>
#include <sys/stat.h>
@@ -44,7 +45,7 @@ static const char rcsid[] =
# include <locale.h>
#endif
-
+#define MD5_SIZE 33
#define NHEADER_LINES 3
@@ -312,11 +313,12 @@ edit_cmd() {
FILE *f;
int t;
struct stat statbuf, fsbuf;
- time_t mtime;
WAIT_T waiter;
PID_T pid, xpid;
mode_t um;
int syntax_error = 0;
+ char orig_md5[MD5_SIZE];
+ char new_md5[MD5_SIZE];
log_it(RealUser, Pid, "BEGIN EDIT", User);
(void) sprintf(n, CRON_TAB(User));
@@ -365,7 +367,10 @@ edit_cmd() {
}
if (statbuf.st_dev != fsbuf.st_dev || statbuf.st_ino != fsbuf.st_ino)
errx(ERROR_EXIT, "temp file must be edited in place");
- mtime = statbuf.st_mtime;
+ if (MD5File(Filename, orig_md5) == NULL) {
+ warn("MD5");
+ goto fatal;
+ }
if ((!(editor = getenv("VISUAL")))
&& (!(editor = getenv("EDITOR")))
@@ -431,7 +436,11 @@ edit_cmd() {
}
if (statbuf.st_dev != fsbuf.st_dev || statbuf.st_ino != fsbuf.st_ino)
errx(ERROR_EXIT, "temp file must be edited in place");
- if (mtime == statbuf.st_mtime && !syntax_error) {
+ if (MD5File(Filename, new_md5) == NULL) {
+ warn("MD5");
+ goto fatal;
+ }
+ if (strcmp(orig_md5, new_md5) == 0 && !syntax_error) {
warnx("no changes made to crontab");
goto remove;
}
OpenPOWER on IntegriCloud