--- Begin Message ---
Package: cron
Version: 3.0pl1-73
Severity: wishlist
Tags: upstream patch
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi,
I wrote a little patch for crond, which allows the user to sepcify flags
in the crontab after the time.
They can be entered in "getopt-style-syntax", for example "-abc" or
"-ab -c". (Currently) only three flags are supported:
l: Do not log "(user) CMD (command)" to syslog
m: Do not write a mail, if the command gave an output
p: Do not use PAM (this is useful to suppress the "session
open..."-messages)
The flags are *completely* optional, if the sequencing command *should*
begin with a dash, you can write a "--" before it, for example:
* * * * * -lm -p -- -command
Would be nice, if you'd include the patch,
Sebastian
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)
iD8DBQE+GIHsvBVic1oTsEgRAiwyAJ9LAzh7FRnHswFQGq4CuN2sQ++LCgCeKiwW
tws/mJ7ayfCjaBf5tMNWNw4=
=PcHw
-----END PGP SIGNATURE-----
diff -Nur orig/cron.h patched/cron.h
--- orig/cron.h 2003-01-05 19:18:06.000000000 +0100
+++ patched/cron.h 2003-01-05 19:32:11.000000000 +0100
@@ -166,6 +166,11 @@
#define WHEN_REBOOT 0x04
#define MIN_STAR 0x08
#define HR_STAR 0x10
+#define NOLOG 0x20
+#define NOMAIL 0x40
+#if defined(USE_PAM)
+#define NOPAM 0x80
+#endif
} entry;
/* the crontab database will be a list of the
diff -Nur orig/crontab.5 patched/crontab.5
--- orig/crontab.5 2003-01-05 19:18:06.000000000 +0100
+++ patched/crontab.5 2003-01-05 19:53:11.000000000 +0100
@@ -142,6 +142,18 @@
after the first % will be sent to the command as standard
input.
.PP
+Instead of the sixth field one or more flags can appear. They can be
+combined (``-abc'') or written apartly (``-a -bc''). Everything after
+a ``--'' is ignored and treated as a shell command.
+.br
+Flags may be
+.B -l
+for not using syslog,
+.B -m
+for not mailing the output to the user to which the crontab belongs or
+.B -p
+for not using PAM.
+.PP
Note: The day of a command's execution can be specified by two
fields \(em day of month, and day of week. If both fields are
restricted (ie, aren't *), the command will be run when
@@ -183,12 +195,12 @@
# mail any output to `paul', no matter whose crontab this is
MAILTO=paul
#
-# run five minutes after midnight, every day
-5 0 * * * $HOME/bin/daily.job >> $HOME/tmp/out 2>&1
+# run five minutes after midnight, every day but do not log
+5 0 * * * -l $HOME/bin/daily.job >> $HOME/tmp/out 2>&1
# run at 2:15pm on the first of every month -- output mailed to paul
15 14 1 * * $HOME/bin/monthly
-# run at 10 pm on weekdays, annoy Joe
-0 22 * * 1-5 mail -s "It's 10pm" joe%Joe,%%Where are your kids?%
+# run at 10 pm on weekdays, annoy Joe, but don't use PAM and do not log
+0 22 * * 1-5 -lp mail -s "It's 10pm" joe%Joe,%%Where are your kids?%
23 0-23/2 * * * echo "run 23 minutes after midn, 2am, 4am ..., everyday"
5 4 * * sun echo "run at 5 after 4 every sunday"
.fi
diff -Nur orig/do_command.c patched/do_command.c
--- orig/do_command.c 2003-01-05 19:18:06.000000000 +0100
+++ patched/do_command.c 2003-01-05 19:34:36.000000000 +0100
@@ -189,15 +189,16 @@
}
#if defined(USE_PAM)
- retcode = pam_start("cron", usernm, &conv, &pamh);
- PAM_FAIL_CHECK;
- retcode = pam_acct_mgmt(pamh, PAM_SILENT);
- PAM_FAIL_CHECK;
- retcode = pam_open_session(pamh, PAM_SILENT);
- PAM_FAIL_CHECK;
- retcode = pam_setcred(pamh, PAM_ESTABLISH_CRED | PAM_SILENT);
- PAM_FAIL_CHECK;
-
+ if (!(e->flags & NOPAM)) {
+ retcode = pam_start("cron", usernm, &conv, &pamh);
+ PAM_FAIL_CHECK;
+ retcode = pam_acct_mgmt(pamh, PAM_SILENT);
+ PAM_FAIL_CHECK;
+ retcode = pam_open_session(pamh, PAM_SILENT);
+ PAM_FAIL_CHECK;
+ retcode = pam_setcred(pamh, PAM_ESTABLISH_CRED | PAM_SILENT);
+ PAM_FAIL_CHECK;
+ }
#endif
/* fork again, this time so we can exec the user's command.
@@ -216,7 +217,7 @@
* the actual user command shell was going to get and the
* PID is part of the log message.
*/
- /*local*/{
+ if (!(e->flags & NOLOG)) {
char *x = mkprints((u_char *)e->cmd, strlen(e->cmd));
log_it(usernm, getpid(), "CMD", x);
@@ -439,9 +440,16 @@
(void) gethostname(hostname, MAXHOSTNAMELEN);
(void) snprintf(mailcmd, sizeof(mailcmd),
MAILARGS, MAILCMD, mailto);
- if (!(mail = cron_popen(mailcmd, "w", e))) {
- perror(MAILCMD);
- (void) _exit(ERROR_EXIT);
+ if (e->flags & NOMAIL) {
+ f (!(mail = fopen("/dev/null", "w"))) {
+ perror("/dev/null");
+ (void) _exit(ERROR_EXIT);
+ }
+ } else {
+ if (!(mail = cron_popen(mailcmd, "w", e))) {
+ perror(MAILCMD);
+ (void) _exit(ERROR_EXIT);
+ }
}
fprintf(mail, "From: root (Cron Daemon)\n");
fprintf(mail, "To: %s\n", mailto);
@@ -493,7 +501,7 @@
* log the facts so the poor user can figure out
* what's going on.
*/
- if (mailto && status) {
+ if (mailto && status && !(e->flags & NOMAIL)) {
char buf[MAX_TEMPSTR];
snprintf(buf, MAX_TEMPSTR,
@@ -532,9 +540,11 @@
Debug(DPROC, ("\n"))
}
#if defined(USE_PAM)
- pam_setcred(pamh, PAM_DELETE_CRED | PAM_SILENT);
- retcode = pam_close_session(pamh, PAM_SILENT);
- pam_end(pamh, retcode);
+ if (!(e->flags & NOPAM)) {
+ pam_setcred(pamh, PAM_DELETE_CRED | PAM_SILENT);
+ retcode = pam_close_session(pamh, PAM_SILENT);
+ pam_end(pamh, retcode);
+ }
#endif
}
diff -Nur orig/entry.c patched/entry.c
--- orig/entry.c 2003-01-05 19:18:06.000000000 +0100
+++ patched/entry.c 2003-01-05 19:39:54.000000000 +0100
@@ -31,7 +31,7 @@
typedef enum ecode {
e_none, e_minute, e_hour, e_dom, e_month, e_dow,
- e_cmd, e_timespec, e_username
+ e_cmd, e_timespec, e_username, e_flag
} ecode_e;
static char get_list __P((bitstr_t *, int, int, char *[], int, FILE *)),
@@ -50,6 +50,7 @@
"bad command",
"bad time specifier",
"bad username",
+ "bad flag"
};
@@ -92,6 +93,7 @@
char cmd[MAX_COMMAND];
char envstr[MAX_ENVSTR];
char **tenvp;
+ int flagctrl = 0;
Debug(DPARS, ("load_entry()...about to eat comments\n"))
@@ -256,6 +258,83 @@
goto eof;
}
+ /* parse flags here. flags is one of:
+ * 'l': no log
+ * 'm': no mail
+ * 'p': no PAM (ignored if compiled without pam support)
+ * flags begin with '-', for example:
+ * -lmp
+ * or
+ * -lm -p
+ * If the following command begins with a '-',
+ * add '--' after the flags to tell the parser,
+ * that the following string doesn't begin a
+ * flag sequence (... -lm -- -foobarcommand)
+ *
+ * -- yath, 01/2003 */
+
+ if (ch == ' ' || ch == '\t') {
+ Skip_Blanks(ch, file);
+ unget_char(ch, file);
+ }
+
+ ch = get_string(cmd, MAX_COMMAND, file, " \t\n");
+ if (ch == EOF) {
+ ecode = e_cmd; /* e_cmd because flags are optional */
+ goto eof;
+ }
+
+ /* meaning of flagctrl:
+ * 1: got "--", stop parsing
+ * 2: current string begins with '-', parse it
+ * 3: string doesn't begin with '-' (and is not "--"),
+ * stop parsing and unget the string (including a space)
+ */
+
+ while(1) {
+ if (!strcmp(cmd, "--")) {
+ flagctrl = 1;
+ break;
+ }
+
+ if (flagctrl == 2) {
+ for (ch = 1; ch < strlen(cmd); ch++)
+ switch(cmd[ch]) {
+ case 'l':
+ e->flags |= NOLOG;
+ break;
+ case 'm':
+ e->flags |= NOMAIL;
+ break;
+ case 'p':
+#if defined(USE_PAM)
+ e->flags |= NOPAM;
+#endif
+ break;
+ default:
+ ecode = e_flag;
+ goto eof;
+ }
+ ch = get_string(cmd, MAX_COMMAND, file, " \t\n");
+ if (ch == EOF) {
+ ecode = e_cmd; /* same as above */
+ goto eof;
+ }
+ flagctrl = 0;
+ } else if (cmd[0] == '-')
+ flagctrl = 2;
+ else {
+ flagctrl = 3;
+ break;
+ }
+ }
+
+ if (flagctrl == 3) {
+ unget_char(' ', file);
+ for (ch = strlen(cmd)-1; ch >= 0; ch--)
+ unget_char(cmd[ch], file);
+ }
+
e->uid = pw->pw_uid;
e->gid = pw->pw_gid;
--- End Message ---
--- Begin Message ---
Hi Sebastian,
I am closing the bug report #175470; please feel free to reopen it if it
deserves attention. If you reopen it, please reply also the previous
e-mail, sent ten days ago, which is cited below.
Best regards, Georges.
Georges Khaznadar a écrit :
> tags 175470 + moreinfo
>
> Hi Sebastian,
>
> I am the new maintainer for cron package, willing to hunt bugs:
>
> You wrote a patch against cron in year 2003, which extends the syntax of
> crontab lines, allowing one to insert l, m, and p switches to control
> respectively logging to syslog, mailing to the user and using PAM.
>
> This patch seems shiny, from my point of view. However 20 years passed,
> without a response from the maintainer, and earth is still spinning,
> without this patch.
>
> So, please answer a few questions if you do not mind:
>
> - are you currently still using such a patched crontab format? Or are
> you using some other workaround/solution?
>
> - I wish to implement tests to prevent regressions, when some important
> feature is added to cron/crontab. Please have you suggestions to build
> a comprehensive test for your enhancements?
>
> Best regards, Georges.
>
> --
> Georges KHAZNADAR et Jocelyne FOURNIER
> 22 rue des mouettes, 59240 Dunkerque France.
> Téléphone +33 (0)3 28 29 17 70
>
--
Georges KHAZNADAR et Jocelyne FOURNIER
22 rue des mouettes, 59240 Dunkerque France.
Téléphone +33 (0)3 28 29 17 70
signature.asc
Description: PGP signature
--- End Message ---