Sophie

Sophie

distrib > Mandriva > 2009.0 > i586 > by-pkgid > 67175cc1070f1ce6eca24d02f1679c68 > files > 2

dcron-3.2-3mdv2009.0.src.rpm

diff -Naur dcron/defs.h dcron.oden/defs.h
--- dcron/defs.h	2002-12-17 21:06:51.000000000 +0100
+++ dcron.oden/defs.h	2005-07-30 18:35:48.000000000 +0200
@@ -26,7 +26,7 @@
 #define arysize(ary)	(sizeof(ary)/sizeof((ary)[0]))
 
 #ifndef CRONTABS
-#define CRONTABS	"/var/spool/cron/crontabs"
+#define CRONTABS	"/var/spool/dcron/crontabs"
 #endif
 #ifndef TMPDIR
 #define TMPDIR		"/tmp"
@@ -47,7 +47,10 @@
 #define MAXLINES	256		/* max lines in non-root crontabs */
 #endif
 #ifndef PATH_VI
-#define PATH_VI		"/usr/bin/vi"	/* location of vi	*/
+#define PATH_VI		"/bin/vi"	/* location of vi	*/
+#endif
+#ifndef PIDFILE
+#define PIDFILE		"/var/run/dcron/dcron.pid"
 #endif
 
 
diff -Naur dcron/subs.c dcron.oden/subs.c
--- dcron/subs.c	1999-02-10 07:31:46.000000000 +0100
+++ dcron.oden/subs.c	2005-07-30 18:34:51.000000000 +0200
@@ -11,7 +11,7 @@
 Prototype void log(int level, const char *ctl, ...);
 Prototype void log9(const char *ctl, ...);
 Prototype void logfd(int fd, const char *ctl, ...);
-Prototype void fdprintf(int fd, const char *ctl, ...);
+Prototype void printffd(int fd, const char *ctl, ...);
 Prototype int ChangeUser(const char *user, short dochdir);
 Prototype void vlog(int level, int fd, const char *ctl, va_list va);
 Prototype int slog(char *buf, const char *ctl, int nmax, va_list va, short useDate);
@@ -47,7 +47,7 @@
 }
 
 void 
-fdprintf(int fd, const char *ctl, ...)
+printffd(int fd, const char *ctl, ...)
 {
     va_list va;
     char buf[2048];
--- dcron/crond.8	2006-04-29 10:17:00.000000000 -0700
+++ dcron/crond.8.new	2007-08-16 15:36:36.000000000 -0700
@@ -4,7 +4,7 @@
 .SH NAME
 crond \- cron daemon (Dillon's Cron)
 .SH SYNOPSIS
-.B crond [-l#] [-d[#]] [-f] [-b] [-c directory]
+.B crond [-l#] [-d[#]] [-f] [-b] [-c directory] [-m mailer] [-p pidfile]
 .SH OPTIONS
 .B crond
 is a background daemon that parses individual crontab files and
@@ -30,6 +30,14 @@ specify directory containing crontab fil
 .B "-s directory "
 specify directory containing system-wide crontab files.  By
 default, /etc/cron.d is checked.
+.TP 0.5i
+.B "-m mailer "
+specify program for sending mail and additional parameters which should be
+passed to it (default: "/usr/lib/sendmail -t -oem -i").
+.TP 0.5i
+.B "-p pidfile"
+specify file which the pid of crond should be written into (default:
+/var/run/dcron/dcron.pid).
 .SH DESCRIPTION
 .B crond 
 is responsible for scanning the crontab files and running
@@ -56,7 +64,8 @@ under the ownership of the daemon to pre
 it.  Upon job completion, crond verifies the secureness of the mail file
 and, if it has been appended to, mails to the file to user.  The
 .B sendmail
-program is run under the user's uid to prevent mail related security holes.  
+program or any program specified through commandline switch -m (see above) is
+run under the user's uid to prevent mail related security holes.  
 Unlike
 .B crontab
 , the crond program does not leave an open descriptor to the file for the
--- dcron/job.c	2006-04-29 09:49:48.000000000 -0700
+++ dcron/job.c.new	2007-08-16 15:39:55.000000000 -0700
@@ -10,6 +10,9 @@
 
 Prototype void RunJob(CronFile *file, CronLine *line);
 Prototype void EndJob(CronFile *file, CronLine *line);
+Prototype void GetMailer(char *cmdline);
+
+char **mailer = NULL;
 
 void
 RunJob(CronFile *file, CronLine *line)
@@ -30,7 +33,7 @@ RunJob(CronFile *file, CronLine *line)
 
     if (mailFd >= 0) {
 	line->cl_MailFlag = 1;
-	fdprintf(mailFd, "To: %s\nSubject: cron: %s\n\n", 
+	printffd(mailFd, "To: %s\nSubject: cron: %s\n\n", 
 	    file->cf_UserName,
 	    line->cl_Shell
 	);
@@ -91,7 +94,7 @@ RunJob(CronFile *file, CronLine *line)
 	    file->cf_UserName,
 	    line->cl_Shell
 	);
-	fdprintf(1, "Exec failed: /bin/sh -c %s\n", line->cl_Shell);
+	printffd(1, "Exec failed: /bin/sh -c %s\n", line->cl_Shell);
 	exit(0);
     } else if (line->cl_Pid < 0) {
 	/*
@@ -209,13 +212,21 @@ EndJob(CronFile *file, CronLine *line)
 	dup2(1, 2);
 	close(mailFd);
 
+	if (mailer) {
+	    execv(mailer[0], mailer);
+	    logfd(8, "unable to exec %s, user %s, "
+		"using default mailer " SENDMAIL "\n",
+		mailer[0],
+		file->cf_UserName
+	    );
+	    free(mailer);
+	}
 	execl(SENDMAIL, SENDMAIL, SENDMAIL_ARGS, NULL, NULL);
 	/*
 	 * note: 8 is a file descriptor
 	 */
-	logfd(8, "unable to exec %s %s, user %s, output to sink null", 
-	    SENDMAIL,
-	    SENDMAIL_ARGS,
+	logfd(8,
+	    "unable to exec " SENDMAIL ", user %s, output to sink null\n", 
 	    file->cf_UserName
 	);
 	exit(0);
@@ -233,3 +244,40 @@ EndJob(CronFile *file, CronLine *line)
     close(mailFd);
 }
 
+/*
+ * GetMailer - parses cmdline argument (-m) and sets mailer (to NULL on failure)
+ */
+
+void
+GetMailer(char *cmdline)
+{
+  int argc = 0; /* number of arguments passed to the mail program */
+  char *space = cmdline;
+
+  while (space) {
+    /*
+     * get memory for the array of strings
+     */
+    if (!(mailer = realloc(mailer, (argc + 2) * sizeof(char*)))) {
+      logfd(8, "realloc failed, using default mailer " SENDMAIL "\n");
+      mailer = NULL;
+      return;
+    }
+
+    /*
+     * eg. cmdline arg (-m) = "/var/qmail/bin/qmail-inject -A -fcron"
+     * mailer[0] = "/var/qmail/bin/qmail-inject"
+     * mailer[1] = "-A"
+     * mailer[2] = "-fcron"
+     */
+    *(mailer + argc) = space;
+    ++argc;
+
+    if ((space = strchr(space, ' '))) *space++ = '\0';
+  }
+
+  /*
+   * mailer[3] = NULL
+   */
+  *(mailer + argc) = NULL;
+}
--- dcron/main.c	2006-04-29 09:47:26.000000000 -0700
+++ dcron/main.c.new	2007-08-16 15:42:53.000000000 -0700
@@ -27,6 +27,7 @@ const char  *CDir = CRONTABS;
 const char  *SCDir = SCRONTABS;
 uid_t DaemonUid;
 int InSyncFileRoot;
+char *pidfile = PIDFILE;
 
 int
 main(int ac, char **av)
@@ -65,6 +66,14 @@ main(int ac, char **av)
 	    case 's':
 		SCDir = (*ptr) ? ptr : av[++i];
 		continue;
+	    case 'm':
+		if (!*ptr) ptr = av[++i];
+		GetMailer(ptr);
+		continue;
+	    case 'p':
+		if (!*ptr) ptr = av[++i];
+		pidfile = ptr;
+		continue;
 	    default:
 		break;
 	    }
@@ -80,7 +89,7 @@ main(int ac, char **av)
         if (i > ac)
             puts("expected argument for option");
 	printf("dcron " VERSION "\n");
-	printf("dcron -d[#] -l[#] -f -b -c dir -s dir\n");
+	printf("dcron -d[#] -l[#] -f -b -c dir -s dir -m mailer -p pidfile\n");
 	exit(1);
     }
 
@@ -122,6 +131,12 @@ main(int ac, char **av)
         }
         if (pid > 0)
             exit(0);
+
+	if ((fd = open(pidfile, O_WRONLY | O_CREAT | O_TRUNC,
+	  S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP)) >= 0) {
+	    printffd(fd, "%i\n", getpid());
+	    close(fd);
+	}
     }
 
     /*