diff --git a/usr.sbin/cron/crontab/Makefile b/usr.sbin/cron/crontab/Makefile index 96a4bd6c8b8a..2c1bfc01a2e4 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 diff --git a/usr.sbin/cron/crontab/crontab.c b/usr.sbin/cron/crontab/crontab.c index 50268d6f12c0..5d61ea71ba46 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 #include +#include #include #include #include @@ -44,7 +45,7 @@ static const char rcsid[] = # include #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; }