History log of /openbsd-current/usr.sbin/cron/entry.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.59 19-Jul-2023 millert

Fix skipping of white space after the username in /etc/crontab.
Only a single white space character was consumed, we should be
consuming all white space between fields. This change makes things
consistent with how lines without a username are parsed.
OK deraadt@ sthen@


# 1.58 13-Jun-2023 millert

Upstream fixes for @yearly, @monthly, @weekly, @daily and @hourly.
The bit_nset() macro was being called with the high value one too
large for the special strings. There is no security impact due to
the layout of the bit strings but this was somewhat lucky. This
introduces a set_range() function that performs range checks before
calling bit_nset().


# 1.57 04-Jun-2023 millert

Correct the comment in get_range() describing the range syntax.


# 1.56 08-May-2023 millert

cron: bounds check the high and low bounds for in a random range.
The bounds are checked for normal ranges in set_element() but in
the case of random ranges this is too late. As a result, a random
range with an invalid high/low bounds would only result in a syntax
error if the randomized value was out of bounds. This means the
entry would be "randomly" rejected by cron or crontab. OK kn@


# 1.55 07-May-2023 millert

cron: check for garbage after the '~' in a random range.
A bug in the parsing of the optional number after the '~' in a
random range prevented proper syntax checking. OK kn@


# 1.54 06-May-2023 millert

Support random offsets when using ranges with a step value in cron.
This extends the random range syntax to support step values. Instead
of choosing a random number between the high and low values, the
field is treated as a range with a random offset less than the step
value. This can be used to avoid thundering herd problems where
multiple machines contact a server all at the same time via cron jobs.

The syntax is similar to the existing range/step syntax but uses a
random range. For example, instead of "0-59/10" in the minutes
field, "0~59/10" can be used to run a command every 10 minutes where
the first command starts at a random offset in the range [0,9].
The high and low numbers are optional, "~/10" can be used instead.

Requested by job@, OK phessler@


Revision tags: OPENBSD_7_2_BASE OPENBSD_7_3_BASE
# 1.53 21-May-2022 deraadt

repair a few more backwards compares that create headaches
ok millert


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE OPENBSD_7_1_BASE
# 1.52 18-Apr-2020 deraadt

Rewrite the flag-parsing code to be getopt-like. Tight formations like
-ns are now possible, as well as (useless) repetition like -nnn.
ok millert


# 1.51 16-Apr-2020 millert

Add a mechanism to prevent cron jobs from running concurrently.
This adds a new "-s" flag to the command field which indicates that
only a single instance of the job should run concurrenty.
OK beck@ job@ deraadt@


# 1.50 15-Apr-2020 millert

Add support for random values using the '~' operator.
For example "0~30" will result in a random value between 0 and 30
inclusive. If either (or both) of the numbers on either side of
the '~' are omitted, the appropriate limit (low or high) for the
field will be used. OK deraadt@ beck@ jmc@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.49 13-Jun-2018 job

Add crontab entry option -n for "No mail when run successful"

OK jmc@ millert@


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.48 14-Nov-2015 millert

Remove log_it() and call syslog(3) directly using the same format:
"(username) WHAT (details)". Logs due to normal operation (e.g.
crontab operations or running commands) are logged at LOG_INFO like
before. Actual errors are logged at LOG_ERR, less important things
are logged at LOG_WARNING OR LOG_NOTICE. Also ignore SIGHUP now
that there is no log file to reopen.


# 1.47 09-Nov-2015 millert

Remove unused xpid argument to log_it().


# 1.46 08-Nov-2015 millert

Quiet silly clang analyzer warning in calloc() usage.


# 1.45 04-Nov-2015 millert

Change cron from including all headers in every file to only including
what each .c file needs. I have not removed cron.h since it will
be used in a future clean up of the cron's .h files. OK nicm@


# 1.44 04-Nov-2015 millert

Change some globals from extern to static when they are not used
outside their respective .c files. Also remove some unused defines.
OK jung@


# 1.43 26-Oct-2015 millert

Remove some useless defines and the set_cron_uid() function.
OK jung@


# 1.42 06-Oct-2015 tedu

clear out some more legacy code and whatnot


# 1.41 03-Oct-2015 tedu

unifdef some features we will always have. ok benno zhuk


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.40 09-Feb-2015 deraadt

correct copyright, upon approval from paul vixie via todd miller. the
head copyright assertion was seperated from the remaining ones.


# 1.39 23-Jan-2015 tedu

braces to open a function go on their own line like god intended


# 1.38 23-Jan-2015 tedu

Remove the OK and ERR macros. They obfuscate the code and don't
help legibility. (unix system calls use 0 for ok, but hundreds of
other projects use 1 to indicate success.) Despite the name, many
system calls (e.g., open) also return not OK values for success.
It also cleans up some weird code like int crontab_fd = OK - 1;
This diff is mechanical in nature. Later I will fix the bugs it reveals.
ok deraadt


# 1.37 23-Jan-2015 tedu

remove debug code.
I think the level of debug code in cron is excessive for a program
that has reached feature complete. If cron needs to provide more
information to the user about its operational status, I think syslog
would be more appropriate. (The debug flags also disable forking
into the background, so they aren't even that useful for debugging a
live system.)
ok deraadt millert


# 1.36 22-Jan-2015 tedu

delete useless casts. ok deraadt guenther millert


# 1.35 14-Jan-2015 millert

Use HAVE_FOO for BSD-specific features instead of relying on the
BSD macro from sys/param.h.


# 1.34 25-Aug-2014 doug

Delete secret or secret-derived data with explicit_bzero.

concept ok deraadt@
diff looks ok tedu@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.33 19-May-2011 phessler

Fix some possible NULL pointer dereferences, and a little bit of cleanup.

From Lawrence Teo (thanks!)

OK krw@


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.32 29-Oct-2009 markus

do not discard the first character of the command after the -q option
ok millert@


# 1.31 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


Revision tags: OPENBSD_3_7_BASE OPENBSD_3_8_BASE OPENBSD_3_9_BASE OPENBSD_4_0_BASE OPENBSD_4_1_BASE OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.30 30-Jan-2005 millert

fix some whitespace


Revision tags: OPENBSD_3_6_BASE
# 1.29 22-Jun-2004 avsm

Recent glue_strings change reversed a few checks; fix up conditionals
to check for overflow as others do by convention.

Noticed by Andreas Kahari <ak+openbsd at freeshell.org>, millert@ ok


# 1.28 22-Jun-2004 avsm

use snprintf(3) instead of home-grown glue_strings() function
millert@ ok


# 1.27 17-Jun-2004 millert

UUpdate ISC copyright year to 2004
Remove unused macros Skip_Line and MkLower
Remove trailing whitespace


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE
# 1.26 26-Jun-2003 deraadt

two missing protos


# 1.25 17-Apr-2003 millert

Change a few return values from char to int since these functions
can return EOF. Fixes gcc warnings (and potential problems) on ppc.


Revision tags: OPENBSD_3_3_BASE
# 1.24 12-Mar-2003 millert

Move range sanity check out of get_number() and into get_range() since
it was causing problems with symbolic names (and get_range() is really
where it belongs anyway). Also allow a range to be followed by a ','
as pointed out by mpech@


# 1.23 11-Mar-2003 millert

Catch more syntax errors that were previously ignored. I've rewritten
get_number() to be more careful about what it accepts and to take
a string of terminating characters so it knows what is valid. Also
added a range check so that ranges like "60-50" where the first
number is greater than the second are now flagged.
Thanks to mpech@ for testing finding ways to abuse the parser :-)


# 1.22 10-Mar-2003 millert

Change a e_username to e_cmd.


# 1.21 10-Mar-2003 millert

Back out changes to get_number() that I didn't intend to commit.


# 1.20 10-Mar-2003 millert

Do the check for missing command before the un_getchar(); otherwise
the error messages will say line 0. This is because un_getchar('\n', file)
will decrement the line count. Noticed by mpech@


# 1.19 09-Mar-2003 millert

Fix error line number reporting for syntax errors (noticed by mpech@).
This is relatively tricky due to the way EOF is overloaded. Seems to
give a correct line number for all errors I threw at it.


# 1.18 04-Mar-2003 millert

Deref the correct passwd pointer in a Debug statement.


# 1.17 27-Feb-2003 millert

Fix parsing of '0' and non-alphanumerics in steps; found by mpech@


# 1.16 20-Feb-2003 millert

Sync with ISC cron-current + my at(1) integration.
The at(1) code is now more tightly integrated into the cron codebase.


Revision tags: OPENBSD_3_2_BASE
# 1.15 10-Aug-2002 millert

Just zero out pw_passwd in the pw_dup()'d copy. There's no need
to do this elsewhere and my previous commit in this area caused
problems on systems with an /etc/crontab file.


# 1.14 07-Aug-2002 millert

paranoia: zero out pw_passwd since we don't need it


# 1.13 15-Jul-2002 millert

Move atrun(8) functionality into cron(8) proper. This fixes the
long-standing annoyance that atrun's granularity is 10 minutes.
Most at jobs run with a 1 minute granularity. Jobs submitted via
"at now" or "batch" will run immediately. Includes a rewritten
cron(8) man page. at(1) will be integrated more closely into
cron at a future date.

Upgrading notes:
the atrun job in root's crontab should be removed.
the /var/at/spool directory is no longer used


# 1.12 11-Jul-2002 millert

More syncing with my cron 4.0 patch tree, basically cosmetic:
o change an instance of e_none to e_memory that I missed (forgot?)
o kill some whitespace
o modify malloc failure recovery a bit


# 1.11 11-Jul-2002 millert

Add a new error code for memory allocation failures, e_memory and
use that instead of e_none when we run out of memory.


# 1.10 08-Jul-2002 millert

Merge in some changes from Paul Vixie's tree; most are cosmetic
o ANSI function headers
o return (foo) not return foo
o add -oi to sendmail flags
o update email address in man pages
o make some strings const
o completely remove globbing cruft from popen.c
o whitespace changes
o add DOW_STAR to flags for "monthly", "weekly", and "daily" cron entries


# 1.9 14-Jun-2002 todd

spelling; from Brian Poole <raj@cerias.purdue.edu>


Revision tags: OPENBSD_2_9_BASE OPENBSD_3_0_BASE OPENBSD_3_1_BASE
# 1.8 18-Feb-2001 millert

Update to ISC cron 4.0b1 + our patches. This is now under a BSD license.
I also fixed the signal handlers while I was at it.


Revision tags: OPENBSD_2_8_BASE
# 1.7 21-Aug-2000 deraadt

snprintf sprinkles; solar@false.com & I


Revision tags: OPENBSD_2_7_BASE
# 1.6 18-Mar-2000 deraadt

fix parsing of commands after @ keywords and hourly bitmap handling;
sheldonh@uunet.co.za


Revision tags: OPENBSD_2_3_BASE OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE
# 1.5 22-Dec-1997 deraadt

handle timing normally except when clock jumps between 1 and 3 hours. If it
jumps, attempt as best as possible to gaurantee that jobs DO run, but only
run ONCE; patch by thompson@.tgsoft.com


Revision tags: OPENBSD_2_1_BASE OPENBSD_2_2_BASE
# 1.4 16-Dec-1996 deraadt

avoid more oflows; at this stage paranoia exceeds reality by a lot since our passwd suite is fascist


# 1.3 14-Dec-1996 millert

Check to make sure first char of command is not '*' since that will
alway be a syntax error.


# 1.2 01-Nov-1996 millert

Check malloc/strdup ret val and deal.


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.58 13-Jun-2023 millert

Upstream fixes for @yearly, @monthly, @weekly, @daily and @hourly.
The bit_nset() macro was being called with the high value one too
large for the special strings. There is no security impact due to
the layout of the bit strings but this was somewhat lucky. This
introduces a set_range() function that performs range checks before
calling bit_nset().


# 1.57 04-Jun-2023 millert

Correct the comment in get_range() describing the range syntax.


# 1.56 08-May-2023 millert

cron: bounds check the high and low bounds for in a random range.
The bounds are checked for normal ranges in set_element() but in
the case of random ranges this is too late. As a result, a random
range with an invalid high/low bounds would only result in a syntax
error if the randomized value was out of bounds. This means the
entry would be "randomly" rejected by cron or crontab. OK kn@


# 1.55 07-May-2023 millert

cron: check for garbage after the '~' in a random range.
A bug in the parsing of the optional number after the '~' in a
random range prevented proper syntax checking. OK kn@


# 1.54 06-May-2023 millert

Support random offsets when using ranges with a step value in cron.
This extends the random range syntax to support step values. Instead
of choosing a random number between the high and low values, the
field is treated as a range with a random offset less than the step
value. This can be used to avoid thundering herd problems where
multiple machines contact a server all at the same time via cron jobs.

The syntax is similar to the existing range/step syntax but uses a
random range. For example, instead of "0-59/10" in the minutes
field, "0~59/10" can be used to run a command every 10 minutes where
the first command starts at a random offset in the range [0,9].
The high and low numbers are optional, "~/10" can be used instead.

Requested by job@, OK phessler@


Revision tags: OPENBSD_7_2_BASE OPENBSD_7_3_BASE
# 1.53 21-May-2022 deraadt

repair a few more backwards compares that create headaches
ok millert


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE OPENBSD_7_1_BASE
# 1.52 18-Apr-2020 deraadt

Rewrite the flag-parsing code to be getopt-like. Tight formations like
-ns are now possible, as well as (useless) repetition like -nnn.
ok millert


# 1.51 16-Apr-2020 millert

Add a mechanism to prevent cron jobs from running concurrently.
This adds a new "-s" flag to the command field which indicates that
only a single instance of the job should run concurrenty.
OK beck@ job@ deraadt@


# 1.50 15-Apr-2020 millert

Add support for random values using the '~' operator.
For example "0~30" will result in a random value between 0 and 30
inclusive. If either (or both) of the numbers on either side of
the '~' are omitted, the appropriate limit (low or high) for the
field will be used. OK deraadt@ beck@ jmc@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.49 13-Jun-2018 job

Add crontab entry option -n for "No mail when run successful"

OK jmc@ millert@


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.48 14-Nov-2015 millert

Remove log_it() and call syslog(3) directly using the same format:
"(username) WHAT (details)". Logs due to normal operation (e.g.
crontab operations or running commands) are logged at LOG_INFO like
before. Actual errors are logged at LOG_ERR, less important things
are logged at LOG_WARNING OR LOG_NOTICE. Also ignore SIGHUP now
that there is no log file to reopen.


# 1.47 09-Nov-2015 millert

Remove unused xpid argument to log_it().


# 1.46 08-Nov-2015 millert

Quiet silly clang analyzer warning in calloc() usage.


# 1.45 04-Nov-2015 millert

Change cron from including all headers in every file to only including
what each .c file needs. I have not removed cron.h since it will
be used in a future clean up of the cron's .h files. OK nicm@


# 1.44 04-Nov-2015 millert

Change some globals from extern to static when they are not used
outside their respective .c files. Also remove some unused defines.
OK jung@


# 1.43 26-Oct-2015 millert

Remove some useless defines and the set_cron_uid() function.
OK jung@


# 1.42 06-Oct-2015 tedu

clear out some more legacy code and whatnot


# 1.41 03-Oct-2015 tedu

unifdef some features we will always have. ok benno zhuk


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.40 09-Feb-2015 deraadt

correct copyright, upon approval from paul vixie via todd miller. the
head copyright assertion was seperated from the remaining ones.


# 1.39 23-Jan-2015 tedu

braces to open a function go on their own line like god intended


# 1.38 23-Jan-2015 tedu

Remove the OK and ERR macros. They obfuscate the code and don't
help legibility. (unix system calls use 0 for ok, but hundreds of
other projects use 1 to indicate success.) Despite the name, many
system calls (e.g., open) also return not OK values for success.
It also cleans up some weird code like int crontab_fd = OK - 1;
This diff is mechanical in nature. Later I will fix the bugs it reveals.
ok deraadt


# 1.37 23-Jan-2015 tedu

remove debug code.
I think the level of debug code in cron is excessive for a program
that has reached feature complete. If cron needs to provide more
information to the user about its operational status, I think syslog
would be more appropriate. (The debug flags also disable forking
into the background, so they aren't even that useful for debugging a
live system.)
ok deraadt millert


# 1.36 22-Jan-2015 tedu

delete useless casts. ok deraadt guenther millert


# 1.35 14-Jan-2015 millert

Use HAVE_FOO for BSD-specific features instead of relying on the
BSD macro from sys/param.h.


# 1.34 25-Aug-2014 doug

Delete secret or secret-derived data with explicit_bzero.

concept ok deraadt@
diff looks ok tedu@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.33 19-May-2011 phessler

Fix some possible NULL pointer dereferences, and a little bit of cleanup.

From Lawrence Teo (thanks!)

OK krw@


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.32 29-Oct-2009 markus

do not discard the first character of the command after the -q option
ok millert@


# 1.31 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


Revision tags: OPENBSD_3_7_BASE OPENBSD_3_8_BASE OPENBSD_3_9_BASE OPENBSD_4_0_BASE OPENBSD_4_1_BASE OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.30 30-Jan-2005 millert

fix some whitespace


Revision tags: OPENBSD_3_6_BASE
# 1.29 22-Jun-2004 avsm

Recent glue_strings change reversed a few checks; fix up conditionals
to check for overflow as others do by convention.

Noticed by Andreas Kahari <ak+openbsd at freeshell.org>, millert@ ok


# 1.28 22-Jun-2004 avsm

use snprintf(3) instead of home-grown glue_strings() function
millert@ ok


# 1.27 17-Jun-2004 millert

UUpdate ISC copyright year to 2004
Remove unused macros Skip_Line and MkLower
Remove trailing whitespace


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE
# 1.26 26-Jun-2003 deraadt

two missing protos


# 1.25 17-Apr-2003 millert

Change a few return values from char to int since these functions
can return EOF. Fixes gcc warnings (and potential problems) on ppc.


Revision tags: OPENBSD_3_3_BASE
# 1.24 12-Mar-2003 millert

Move range sanity check out of get_number() and into get_range() since
it was causing problems with symbolic names (and get_range() is really
where it belongs anyway). Also allow a range to be followed by a ','
as pointed out by mpech@


# 1.23 11-Mar-2003 millert

Catch more syntax errors that were previously ignored. I've rewritten
get_number() to be more careful about what it accepts and to take
a string of terminating characters so it knows what is valid. Also
added a range check so that ranges like "60-50" where the first
number is greater than the second are now flagged.
Thanks to mpech@ for testing finding ways to abuse the parser :-)


# 1.22 10-Mar-2003 millert

Change a e_username to e_cmd.


# 1.21 10-Mar-2003 millert

Back out changes to get_number() that I didn't intend to commit.


# 1.20 10-Mar-2003 millert

Do the check for missing command before the un_getchar(); otherwise
the error messages will say line 0. This is because un_getchar('\n', file)
will decrement the line count. Noticed by mpech@


# 1.19 09-Mar-2003 millert

Fix error line number reporting for syntax errors (noticed by mpech@).
This is relatively tricky due to the way EOF is overloaded. Seems to
give a correct line number for all errors I threw at it.


# 1.18 04-Mar-2003 millert

Deref the correct passwd pointer in a Debug statement.


# 1.17 27-Feb-2003 millert

Fix parsing of '0' and non-alphanumerics in steps; found by mpech@


# 1.16 20-Feb-2003 millert

Sync with ISC cron-current + my at(1) integration.
The at(1) code is now more tightly integrated into the cron codebase.


Revision tags: OPENBSD_3_2_BASE
# 1.15 10-Aug-2002 millert

Just zero out pw_passwd in the pw_dup()'d copy. There's no need
to do this elsewhere and my previous commit in this area caused
problems on systems with an /etc/crontab file.


# 1.14 07-Aug-2002 millert

paranoia: zero out pw_passwd since we don't need it


# 1.13 15-Jul-2002 millert

Move atrun(8) functionality into cron(8) proper. This fixes the
long-standing annoyance that atrun's granularity is 10 minutes.
Most at jobs run with a 1 minute granularity. Jobs submitted via
"at now" or "batch" will run immediately. Includes a rewritten
cron(8) man page. at(1) will be integrated more closely into
cron at a future date.

Upgrading notes:
the atrun job in root's crontab should be removed.
the /var/at/spool directory is no longer used


# 1.12 11-Jul-2002 millert

More syncing with my cron 4.0 patch tree, basically cosmetic:
o change an instance of e_none to e_memory that I missed (forgot?)
o kill some whitespace
o modify malloc failure recovery a bit


# 1.11 11-Jul-2002 millert

Add a new error code for memory allocation failures, e_memory and
use that instead of e_none when we run out of memory.


# 1.10 08-Jul-2002 millert

Merge in some changes from Paul Vixie's tree; most are cosmetic
o ANSI function headers
o return (foo) not return foo
o add -oi to sendmail flags
o update email address in man pages
o make some strings const
o completely remove globbing cruft from popen.c
o whitespace changes
o add DOW_STAR to flags for "monthly", "weekly", and "daily" cron entries


# 1.9 14-Jun-2002 todd

spelling; from Brian Poole <raj@cerias.purdue.edu>


Revision tags: OPENBSD_2_9_BASE OPENBSD_3_0_BASE OPENBSD_3_1_BASE
# 1.8 18-Feb-2001 millert

Update to ISC cron 4.0b1 + our patches. This is now under a BSD license.
I also fixed the signal handlers while I was at it.


Revision tags: OPENBSD_2_8_BASE
# 1.7 21-Aug-2000 deraadt

snprintf sprinkles; solar@false.com & I


Revision tags: OPENBSD_2_7_BASE
# 1.6 18-Mar-2000 deraadt

fix parsing of commands after @ keywords and hourly bitmap handling;
sheldonh@uunet.co.za


Revision tags: OPENBSD_2_3_BASE OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE
# 1.5 22-Dec-1997 deraadt

handle timing normally except when clock jumps between 1 and 3 hours. If it
jumps, attempt as best as possible to gaurantee that jobs DO run, but only
run ONCE; patch by thompson@.tgsoft.com


Revision tags: OPENBSD_2_1_BASE OPENBSD_2_2_BASE
# 1.4 16-Dec-1996 deraadt

avoid more oflows; at this stage paranoia exceeds reality by a lot since our passwd suite is fascist


# 1.3 14-Dec-1996 millert

Check to make sure first char of command is not '*' since that will
alway be a syntax error.


# 1.2 01-Nov-1996 millert

Check malloc/strdup ret val and deal.


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.53 21-May-2022 deraadt

repair a few more backwards compares that create headaches
ok millert


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE OPENBSD_7_1_BASE
# 1.52 18-Apr-2020 deraadt

Rewrite the flag-parsing code to be getopt-like. Tight formations like
-ns are now possible, as well as (useless) repetition like -nnn.
ok millert


# 1.51 16-Apr-2020 millert

Add a mechanism to prevent cron jobs from running concurrently.
This adds a new "-s" flag to the command field which indicates that
only a single instance of the job should run concurrenty.
OK beck@ job@ deraadt@


# 1.50 15-Apr-2020 millert

Add support for random values using the '~' operator.
For example "0~30" will result in a random value between 0 and 30
inclusive. If either (or both) of the numbers on either side of
the '~' are omitted, the appropriate limit (low or high) for the
field will be used. OK deraadt@ beck@ jmc@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.49 13-Jun-2018 job

Add crontab entry option -n for "No mail when run successful"

OK jmc@ millert@


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.48 14-Nov-2015 millert

Remove log_it() and call syslog(3) directly using the same format:
"(username) WHAT (details)". Logs due to normal operation (e.g.
crontab operations or running commands) are logged at LOG_INFO like
before. Actual errors are logged at LOG_ERR, less important things
are logged at LOG_WARNING OR LOG_NOTICE. Also ignore SIGHUP now
that there is no log file to reopen.


# 1.47 09-Nov-2015 millert

Remove unused xpid argument to log_it().


# 1.46 08-Nov-2015 millert

Quiet silly clang analyzer warning in calloc() usage.


# 1.45 04-Nov-2015 millert

Change cron from including all headers in every file to only including
what each .c file needs. I have not removed cron.h since it will
be used in a future clean up of the cron's .h files. OK nicm@


# 1.44 04-Nov-2015 millert

Change some globals from extern to static when they are not used
outside their respective .c files. Also remove some unused defines.
OK jung@


# 1.43 26-Oct-2015 millert

Remove some useless defines and the set_cron_uid() function.
OK jung@


# 1.42 06-Oct-2015 tedu

clear out some more legacy code and whatnot


# 1.41 03-Oct-2015 tedu

unifdef some features we will always have. ok benno zhuk


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.40 09-Feb-2015 deraadt

correct copyright, upon approval from paul vixie via todd miller. the
head copyright assertion was seperated from the remaining ones.


# 1.39 23-Jan-2015 tedu

braces to open a function go on their own line like god intended


# 1.38 23-Jan-2015 tedu

Remove the OK and ERR macros. They obfuscate the code and don't
help legibility. (unix system calls use 0 for ok, but hundreds of
other projects use 1 to indicate success.) Despite the name, many
system calls (e.g., open) also return not OK values for success.
It also cleans up some weird code like int crontab_fd = OK - 1;
This diff is mechanical in nature. Later I will fix the bugs it reveals.
ok deraadt


# 1.37 23-Jan-2015 tedu

remove debug code.
I think the level of debug code in cron is excessive for a program
that has reached feature complete. If cron needs to provide more
information to the user about its operational status, I think syslog
would be more appropriate. (The debug flags also disable forking
into the background, so they aren't even that useful for debugging a
live system.)
ok deraadt millert


# 1.36 22-Jan-2015 tedu

delete useless casts. ok deraadt guenther millert


# 1.35 14-Jan-2015 millert

Use HAVE_FOO for BSD-specific features instead of relying on the
BSD macro from sys/param.h.


# 1.34 25-Aug-2014 doug

Delete secret or secret-derived data with explicit_bzero.

concept ok deraadt@
diff looks ok tedu@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.33 19-May-2011 phessler

Fix some possible NULL pointer dereferences, and a little bit of cleanup.

From Lawrence Teo (thanks!)

OK krw@


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.32 29-Oct-2009 markus

do not discard the first character of the command after the -q option
ok millert@


# 1.31 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


Revision tags: OPENBSD_3_7_BASE OPENBSD_3_8_BASE OPENBSD_3_9_BASE OPENBSD_4_0_BASE OPENBSD_4_1_BASE OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.30 30-Jan-2005 millert

fix some whitespace


Revision tags: OPENBSD_3_6_BASE
# 1.29 22-Jun-2004 avsm

Recent glue_strings change reversed a few checks; fix up conditionals
to check for overflow as others do by convention.

Noticed by Andreas Kahari <ak+openbsd at freeshell.org>, millert@ ok


# 1.28 22-Jun-2004 avsm

use snprintf(3) instead of home-grown glue_strings() function
millert@ ok


# 1.27 17-Jun-2004 millert

UUpdate ISC copyright year to 2004
Remove unused macros Skip_Line and MkLower
Remove trailing whitespace


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE
# 1.26 26-Jun-2003 deraadt

two missing protos


# 1.25 17-Apr-2003 millert

Change a few return values from char to int since these functions
can return EOF. Fixes gcc warnings (and potential problems) on ppc.


Revision tags: OPENBSD_3_3_BASE
# 1.24 12-Mar-2003 millert

Move range sanity check out of get_number() and into get_range() since
it was causing problems with symbolic names (and get_range() is really
where it belongs anyway). Also allow a range to be followed by a ','
as pointed out by mpech@


# 1.23 11-Mar-2003 millert

Catch more syntax errors that were previously ignored. I've rewritten
get_number() to be more careful about what it accepts and to take
a string of terminating characters so it knows what is valid. Also
added a range check so that ranges like "60-50" where the first
number is greater than the second are now flagged.
Thanks to mpech@ for testing finding ways to abuse the parser :-)


# 1.22 10-Mar-2003 millert

Change a e_username to e_cmd.


# 1.21 10-Mar-2003 millert

Back out changes to get_number() that I didn't intend to commit.


# 1.20 10-Mar-2003 millert

Do the check for missing command before the un_getchar(); otherwise
the error messages will say line 0. This is because un_getchar('\n', file)
will decrement the line count. Noticed by mpech@


# 1.19 09-Mar-2003 millert

Fix error line number reporting for syntax errors (noticed by mpech@).
This is relatively tricky due to the way EOF is overloaded. Seems to
give a correct line number for all errors I threw at it.


# 1.18 04-Mar-2003 millert

Deref the correct passwd pointer in a Debug statement.


# 1.17 27-Feb-2003 millert

Fix parsing of '0' and non-alphanumerics in steps; found by mpech@


# 1.16 20-Feb-2003 millert

Sync with ISC cron-current + my at(1) integration.
The at(1) code is now more tightly integrated into the cron codebase.


Revision tags: OPENBSD_3_2_BASE
# 1.15 10-Aug-2002 millert

Just zero out pw_passwd in the pw_dup()'d copy. There's no need
to do this elsewhere and my previous commit in this area caused
problems on systems with an /etc/crontab file.


# 1.14 07-Aug-2002 millert

paranoia: zero out pw_passwd since we don't need it


# 1.13 15-Jul-2002 millert

Move atrun(8) functionality into cron(8) proper. This fixes the
long-standing annoyance that atrun's granularity is 10 minutes.
Most at jobs run with a 1 minute granularity. Jobs submitted via
"at now" or "batch" will run immediately. Includes a rewritten
cron(8) man page. at(1) will be integrated more closely into
cron at a future date.

Upgrading notes:
the atrun job in root's crontab should be removed.
the /var/at/spool directory is no longer used


# 1.12 11-Jul-2002 millert

More syncing with my cron 4.0 patch tree, basically cosmetic:
o change an instance of e_none to e_memory that I missed (forgot?)
o kill some whitespace
o modify malloc failure recovery a bit


# 1.11 11-Jul-2002 millert

Add a new error code for memory allocation failures, e_memory and
use that instead of e_none when we run out of memory.


# 1.10 08-Jul-2002 millert

Merge in some changes from Paul Vixie's tree; most are cosmetic
o ANSI function headers
o return (foo) not return foo
o add -oi to sendmail flags
o update email address in man pages
o make some strings const
o completely remove globbing cruft from popen.c
o whitespace changes
o add DOW_STAR to flags for "monthly", "weekly", and "daily" cron entries


# 1.9 14-Jun-2002 todd

spelling; from Brian Poole <raj@cerias.purdue.edu>


Revision tags: OPENBSD_2_9_BASE OPENBSD_3_0_BASE OPENBSD_3_1_BASE
# 1.8 18-Feb-2001 millert

Update to ISC cron 4.0b1 + our patches. This is now under a BSD license.
I also fixed the signal handlers while I was at it.


Revision tags: OPENBSD_2_8_BASE
# 1.7 21-Aug-2000 deraadt

snprintf sprinkles; solar@false.com & I


Revision tags: OPENBSD_2_7_BASE
# 1.6 18-Mar-2000 deraadt

fix parsing of commands after @ keywords and hourly bitmap handling;
sheldonh@uunet.co.za


Revision tags: OPENBSD_2_3_BASE OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE
# 1.5 22-Dec-1997 deraadt

handle timing normally except when clock jumps between 1 and 3 hours. If it
jumps, attempt as best as possible to gaurantee that jobs DO run, but only
run ONCE; patch by thompson@.tgsoft.com


Revision tags: OPENBSD_2_1_BASE OPENBSD_2_2_BASE
# 1.4 16-Dec-1996 deraadt

avoid more oflows; at this stage paranoia exceeds reality by a lot since our passwd suite is fascist


# 1.3 14-Dec-1996 millert

Check to make sure first char of command is not '*' since that will
alway be a syntax error.


# 1.2 01-Nov-1996 millert

Check malloc/strdup ret val and deal.


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.52 18-Apr-2020 deraadt

Rewrite the flag-parsing code to be getopt-like. Tight formations like
-ns are now possible, as well as (useless) repetition like -nnn.
ok millert


# 1.51 16-Apr-2020 millert

Add a mechanism to prevent cron jobs from running concurrently.
This adds a new "-s" flag to the command field which indicates that
only a single instance of the job should run concurrenty.
OK beck@ job@ deraadt@


# 1.50 15-Apr-2020 millert

Add support for random values using the '~' operator.
For example "0~30" will result in a random value between 0 and 30
inclusive. If either (or both) of the numbers on either side of
the '~' are omitted, the appropriate limit (low or high) for the
field will be used. OK deraadt@ beck@ jmc@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.49 13-Jun-2018 job

Add crontab entry option -n for "No mail when run successful"

OK jmc@ millert@


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.48 14-Nov-2015 millert

Remove log_it() and call syslog(3) directly using the same format:
"(username) WHAT (details)". Logs due to normal operation (e.g.
crontab operations or running commands) are logged at LOG_INFO like
before. Actual errors are logged at LOG_ERR, less important things
are logged at LOG_WARNING OR LOG_NOTICE. Also ignore SIGHUP now
that there is no log file to reopen.


# 1.47 09-Nov-2015 millert

Remove unused xpid argument to log_it().


# 1.46 08-Nov-2015 millert

Quiet silly clang analyzer warning in calloc() usage.


# 1.45 04-Nov-2015 millert

Change cron from including all headers in every file to only including
what each .c file needs. I have not removed cron.h since it will
be used in a future clean up of the cron's .h files. OK nicm@


# 1.44 04-Nov-2015 millert

Change some globals from extern to static when they are not used
outside their respective .c files. Also remove some unused defines.
OK jung@


# 1.43 26-Oct-2015 millert

Remove some useless defines and the set_cron_uid() function.
OK jung@


# 1.42 06-Oct-2015 tedu

clear out some more legacy code and whatnot


# 1.41 03-Oct-2015 tedu

unifdef some features we will always have. ok benno zhuk


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.40 09-Feb-2015 deraadt

correct copyright, upon approval from paul vixie via todd miller. the
head copyright assertion was seperated from the remaining ones.


# 1.39 23-Jan-2015 tedu

braces to open a function go on their own line like god intended


# 1.38 23-Jan-2015 tedu

Remove the OK and ERR macros. They obfuscate the code and don't
help legibility. (unix system calls use 0 for ok, but hundreds of
other projects use 1 to indicate success.) Despite the name, many
system calls (e.g., open) also return not OK values for success.
It also cleans up some weird code like int crontab_fd = OK - 1;
This diff is mechanical in nature. Later I will fix the bugs it reveals.
ok deraadt


# 1.37 23-Jan-2015 tedu

remove debug code.
I think the level of debug code in cron is excessive for a program
that has reached feature complete. If cron needs to provide more
information to the user about its operational status, I think syslog
would be more appropriate. (The debug flags also disable forking
into the background, so they aren't even that useful for debugging a
live system.)
ok deraadt millert


# 1.36 22-Jan-2015 tedu

delete useless casts. ok deraadt guenther millert


# 1.35 14-Jan-2015 millert

Use HAVE_FOO for BSD-specific features instead of relying on the
BSD macro from sys/param.h.


# 1.34 25-Aug-2014 doug

Delete secret or secret-derived data with explicit_bzero.

concept ok deraadt@
diff looks ok tedu@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.33 19-May-2011 phessler

Fix some possible NULL pointer dereferences, and a little bit of cleanup.

From Lawrence Teo (thanks!)

OK krw@


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.32 29-Oct-2009 markus

do not discard the first character of the command after the -q option
ok millert@


# 1.31 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


Revision tags: OPENBSD_3_7_BASE OPENBSD_3_8_BASE OPENBSD_3_9_BASE OPENBSD_4_0_BASE OPENBSD_4_1_BASE OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.30 30-Jan-2005 millert

fix some whitespace


Revision tags: OPENBSD_3_6_BASE
# 1.29 22-Jun-2004 avsm

Recent glue_strings change reversed a few checks; fix up conditionals
to check for overflow as others do by convention.

Noticed by Andreas Kahari <ak+openbsd at freeshell.org>, millert@ ok


# 1.28 22-Jun-2004 avsm

use snprintf(3) instead of home-grown glue_strings() function
millert@ ok


# 1.27 17-Jun-2004 millert

UUpdate ISC copyright year to 2004
Remove unused macros Skip_Line and MkLower
Remove trailing whitespace


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE
# 1.26 26-Jun-2003 deraadt

two missing protos


# 1.25 17-Apr-2003 millert

Change a few return values from char to int since these functions
can return EOF. Fixes gcc warnings (and potential problems) on ppc.


Revision tags: OPENBSD_3_3_BASE
# 1.24 12-Mar-2003 millert

Move range sanity check out of get_number() and into get_range() since
it was causing problems with symbolic names (and get_range() is really
where it belongs anyway). Also allow a range to be followed by a ','
as pointed out by mpech@


# 1.23 11-Mar-2003 millert

Catch more syntax errors that were previously ignored. I've rewritten
get_number() to be more careful about what it accepts and to take
a string of terminating characters so it knows what is valid. Also
added a range check so that ranges like "60-50" where the first
number is greater than the second are now flagged.
Thanks to mpech@ for testing finding ways to abuse the parser :-)


# 1.22 10-Mar-2003 millert

Change a e_username to e_cmd.


# 1.21 10-Mar-2003 millert

Back out changes to get_number() that I didn't intend to commit.


# 1.20 10-Mar-2003 millert

Do the check for missing command before the un_getchar(); otherwise
the error messages will say line 0. This is because un_getchar('\n', file)
will decrement the line count. Noticed by mpech@


# 1.19 09-Mar-2003 millert

Fix error line number reporting for syntax errors (noticed by mpech@).
This is relatively tricky due to the way EOF is overloaded. Seems to
give a correct line number for all errors I threw at it.


# 1.18 04-Mar-2003 millert

Deref the correct passwd pointer in a Debug statement.


# 1.17 27-Feb-2003 millert

Fix parsing of '0' and non-alphanumerics in steps; found by mpech@


# 1.16 20-Feb-2003 millert

Sync with ISC cron-current + my at(1) integration.
The at(1) code is now more tightly integrated into the cron codebase.


Revision tags: OPENBSD_3_2_BASE
# 1.15 10-Aug-2002 millert

Just zero out pw_passwd in the pw_dup()'d copy. There's no need
to do this elsewhere and my previous commit in this area caused
problems on systems with an /etc/crontab file.


# 1.14 07-Aug-2002 millert

paranoia: zero out pw_passwd since we don't need it


# 1.13 15-Jul-2002 millert

Move atrun(8) functionality into cron(8) proper. This fixes the
long-standing annoyance that atrun's granularity is 10 minutes.
Most at jobs run with a 1 minute granularity. Jobs submitted via
"at now" or "batch" will run immediately. Includes a rewritten
cron(8) man page. at(1) will be integrated more closely into
cron at a future date.

Upgrading notes:
the atrun job in root's crontab should be removed.
the /var/at/spool directory is no longer used


# 1.12 11-Jul-2002 millert

More syncing with my cron 4.0 patch tree, basically cosmetic:
o change an instance of e_none to e_memory that I missed (forgot?)
o kill some whitespace
o modify malloc failure recovery a bit


# 1.11 11-Jul-2002 millert

Add a new error code for memory allocation failures, e_memory and
use that instead of e_none when we run out of memory.


# 1.10 08-Jul-2002 millert

Merge in some changes from Paul Vixie's tree; most are cosmetic
o ANSI function headers
o return (foo) not return foo
o add -oi to sendmail flags
o update email address in man pages
o make some strings const
o completely remove globbing cruft from popen.c
o whitespace changes
o add DOW_STAR to flags for "monthly", "weekly", and "daily" cron entries


# 1.9 14-Jun-2002 todd

spelling; from Brian Poole <raj@cerias.purdue.edu>


Revision tags: OPENBSD_2_9_BASE OPENBSD_3_0_BASE OPENBSD_3_1_BASE
# 1.8 18-Feb-2001 millert

Update to ISC cron 4.0b1 + our patches. This is now under a BSD license.
I also fixed the signal handlers while I was at it.


Revision tags: OPENBSD_2_8_BASE
# 1.7 21-Aug-2000 deraadt

snprintf sprinkles; solar@false.com & I


Revision tags: OPENBSD_2_7_BASE
# 1.6 18-Mar-2000 deraadt

fix parsing of commands after @ keywords and hourly bitmap handling;
sheldonh@uunet.co.za


Revision tags: OPENBSD_2_3_BASE OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE
# 1.5 22-Dec-1997 deraadt

handle timing normally except when clock jumps between 1 and 3 hours. If it
jumps, attempt as best as possible to gaurantee that jobs DO run, but only
run ONCE; patch by thompson@.tgsoft.com


Revision tags: OPENBSD_2_1_BASE OPENBSD_2_2_BASE
# 1.4 16-Dec-1996 deraadt

avoid more oflows; at this stage paranoia exceeds reality by a lot since our passwd suite is fascist


# 1.3 14-Dec-1996 millert

Check to make sure first char of command is not '*' since that will
alway be a syntax error.


# 1.2 01-Nov-1996 millert

Check malloc/strdup ret val and deal.


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.51 16-Apr-2020 millert

Add a mechanism to prevent cron jobs from running concurrently.
This adds a new "-s" flag to the command field which indicates that
only a single instance of the job should run concurrenty.
OK beck@ job@ deraadt@


# 1.50 15-Apr-2020 millert

Add support for random values using the '~' operator.
For example "0~30" will result in a random value between 0 and 30
inclusive. If either (or both) of the numbers on either side of
the '~' are omitted, the appropriate limit (low or high) for the
field will be used. OK deraadt@ beck@ jmc@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.49 13-Jun-2018 job

Add crontab entry option -n for "No mail when run successful"

OK jmc@ millert@


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.48 14-Nov-2015 millert

Remove log_it() and call syslog(3) directly using the same format:
"(username) WHAT (details)". Logs due to normal operation (e.g.
crontab operations or running commands) are logged at LOG_INFO like
before. Actual errors are logged at LOG_ERR, less important things
are logged at LOG_WARNING OR LOG_NOTICE. Also ignore SIGHUP now
that there is no log file to reopen.


# 1.47 09-Nov-2015 millert

Remove unused xpid argument to log_it().


# 1.46 08-Nov-2015 millert

Quiet silly clang analyzer warning in calloc() usage.


# 1.45 04-Nov-2015 millert

Change cron from including all headers in every file to only including
what each .c file needs. I have not removed cron.h since it will
be used in a future clean up of the cron's .h files. OK nicm@


# 1.44 04-Nov-2015 millert

Change some globals from extern to static when they are not used
outside their respective .c files. Also remove some unused defines.
OK jung@


# 1.43 26-Oct-2015 millert

Remove some useless defines and the set_cron_uid() function.
OK jung@


# 1.42 06-Oct-2015 tedu

clear out some more legacy code and whatnot


# 1.41 03-Oct-2015 tedu

unifdef some features we will always have. ok benno zhuk


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.40 09-Feb-2015 deraadt

correct copyright, upon approval from paul vixie via todd miller. the
head copyright assertion was seperated from the remaining ones.


# 1.39 23-Jan-2015 tedu

braces to open a function go on their own line like god intended


# 1.38 23-Jan-2015 tedu

Remove the OK and ERR macros. They obfuscate the code and don't
help legibility. (unix system calls use 0 for ok, but hundreds of
other projects use 1 to indicate success.) Despite the name, many
system calls (e.g., open) also return not OK values for success.
It also cleans up some weird code like int crontab_fd = OK - 1;
This diff is mechanical in nature. Later I will fix the bugs it reveals.
ok deraadt


# 1.37 23-Jan-2015 tedu

remove debug code.
I think the level of debug code in cron is excessive for a program
that has reached feature complete. If cron needs to provide more
information to the user about its operational status, I think syslog
would be more appropriate. (The debug flags also disable forking
into the background, so they aren't even that useful for debugging a
live system.)
ok deraadt millert


# 1.36 22-Jan-2015 tedu

delete useless casts. ok deraadt guenther millert


# 1.35 14-Jan-2015 millert

Use HAVE_FOO for BSD-specific features instead of relying on the
BSD macro from sys/param.h.


# 1.34 25-Aug-2014 doug

Delete secret or secret-derived data with explicit_bzero.

concept ok deraadt@
diff looks ok tedu@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.33 19-May-2011 phessler

Fix some possible NULL pointer dereferences, and a little bit of cleanup.

From Lawrence Teo (thanks!)

OK krw@


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.32 29-Oct-2009 markus

do not discard the first character of the command after the -q option
ok millert@


# 1.31 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


Revision tags: OPENBSD_3_7_BASE OPENBSD_3_8_BASE OPENBSD_3_9_BASE OPENBSD_4_0_BASE OPENBSD_4_1_BASE OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.30 30-Jan-2005 millert

fix some whitespace


Revision tags: OPENBSD_3_6_BASE
# 1.29 22-Jun-2004 avsm

Recent glue_strings change reversed a few checks; fix up conditionals
to check for overflow as others do by convention.

Noticed by Andreas Kahari <ak+openbsd at freeshell.org>, millert@ ok


# 1.28 22-Jun-2004 avsm

use snprintf(3) instead of home-grown glue_strings() function
millert@ ok


# 1.27 17-Jun-2004 millert

UUpdate ISC copyright year to 2004
Remove unused macros Skip_Line and MkLower
Remove trailing whitespace


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE
# 1.26 26-Jun-2003 deraadt

two missing protos


# 1.25 17-Apr-2003 millert

Change a few return values from char to int since these functions
can return EOF. Fixes gcc warnings (and potential problems) on ppc.


Revision tags: OPENBSD_3_3_BASE
# 1.24 12-Mar-2003 millert

Move range sanity check out of get_number() and into get_range() since
it was causing problems with symbolic names (and get_range() is really
where it belongs anyway). Also allow a range to be followed by a ','
as pointed out by mpech@


# 1.23 11-Mar-2003 millert

Catch more syntax errors that were previously ignored. I've rewritten
get_number() to be more careful about what it accepts and to take
a string of terminating characters so it knows what is valid. Also
added a range check so that ranges like "60-50" where the first
number is greater than the second are now flagged.
Thanks to mpech@ for testing finding ways to abuse the parser :-)


# 1.22 10-Mar-2003 millert

Change a e_username to e_cmd.


# 1.21 10-Mar-2003 millert

Back out changes to get_number() that I didn't intend to commit.


# 1.20 10-Mar-2003 millert

Do the check for missing command before the un_getchar(); otherwise
the error messages will say line 0. This is because un_getchar('\n', file)
will decrement the line count. Noticed by mpech@


# 1.19 09-Mar-2003 millert

Fix error line number reporting for syntax errors (noticed by mpech@).
This is relatively tricky due to the way EOF is overloaded. Seems to
give a correct line number for all errors I threw at it.


# 1.18 04-Mar-2003 millert

Deref the correct passwd pointer in a Debug statement.


# 1.17 27-Feb-2003 millert

Fix parsing of '0' and non-alphanumerics in steps; found by mpech@


# 1.16 20-Feb-2003 millert

Sync with ISC cron-current + my at(1) integration.
The at(1) code is now more tightly integrated into the cron codebase.


Revision tags: OPENBSD_3_2_BASE
# 1.15 10-Aug-2002 millert

Just zero out pw_passwd in the pw_dup()'d copy. There's no need
to do this elsewhere and my previous commit in this area caused
problems on systems with an /etc/crontab file.


# 1.14 07-Aug-2002 millert

paranoia: zero out pw_passwd since we don't need it


# 1.13 15-Jul-2002 millert

Move atrun(8) functionality into cron(8) proper. This fixes the
long-standing annoyance that atrun's granularity is 10 minutes.
Most at jobs run with a 1 minute granularity. Jobs submitted via
"at now" or "batch" will run immediately. Includes a rewritten
cron(8) man page. at(1) will be integrated more closely into
cron at a future date.

Upgrading notes:
the atrun job in root's crontab should be removed.
the /var/at/spool directory is no longer used


# 1.12 11-Jul-2002 millert

More syncing with my cron 4.0 patch tree, basically cosmetic:
o change an instance of e_none to e_memory that I missed (forgot?)
o kill some whitespace
o modify malloc failure recovery a bit


# 1.11 11-Jul-2002 millert

Add a new error code for memory allocation failures, e_memory and
use that instead of e_none when we run out of memory.


# 1.10 08-Jul-2002 millert

Merge in some changes from Paul Vixie's tree; most are cosmetic
o ANSI function headers
o return (foo) not return foo
o add -oi to sendmail flags
o update email address in man pages
o make some strings const
o completely remove globbing cruft from popen.c
o whitespace changes
o add DOW_STAR to flags for "monthly", "weekly", and "daily" cron entries


# 1.9 14-Jun-2002 todd

spelling; from Brian Poole <raj@cerias.purdue.edu>


Revision tags: OPENBSD_2_9_BASE OPENBSD_3_0_BASE OPENBSD_3_1_BASE
# 1.8 18-Feb-2001 millert

Update to ISC cron 4.0b1 + our patches. This is now under a BSD license.
I also fixed the signal handlers while I was at it.


Revision tags: OPENBSD_2_8_BASE
# 1.7 21-Aug-2000 deraadt

snprintf sprinkles; solar@false.com & I


Revision tags: OPENBSD_2_7_BASE
# 1.6 18-Mar-2000 deraadt

fix parsing of commands after @ keywords and hourly bitmap handling;
sheldonh@uunet.co.za


Revision tags: OPENBSD_2_3_BASE OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE
# 1.5 22-Dec-1997 deraadt

handle timing normally except when clock jumps between 1 and 3 hours. If it
jumps, attempt as best as possible to gaurantee that jobs DO run, but only
run ONCE; patch by thompson@.tgsoft.com


Revision tags: OPENBSD_2_1_BASE OPENBSD_2_2_BASE
# 1.4 16-Dec-1996 deraadt

avoid more oflows; at this stage paranoia exceeds reality by a lot since our passwd suite is fascist


# 1.3 14-Dec-1996 millert

Check to make sure first char of command is not '*' since that will
alway be a syntax error.


# 1.2 01-Nov-1996 millert

Check malloc/strdup ret val and deal.


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.50 15-Apr-2020 millert

Add support for random values using the '~' operator.
For example "0~30" will result in a random value between 0 and 30
inclusive. If either (or both) of the numbers on either side of
the '~' are omitted, the appropriate limit (low or high) for the
field will be used. OK deraadt@ beck@ jmc@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.49 13-Jun-2018 job

Add crontab entry option -n for "No mail when run successful"

OK jmc@ millert@


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.48 14-Nov-2015 millert

Remove log_it() and call syslog(3) directly using the same format:
"(username) WHAT (details)". Logs due to normal operation (e.g.
crontab operations or running commands) are logged at LOG_INFO like
before. Actual errors are logged at LOG_ERR, less important things
are logged at LOG_WARNING OR LOG_NOTICE. Also ignore SIGHUP now
that there is no log file to reopen.


# 1.47 09-Nov-2015 millert

Remove unused xpid argument to log_it().


# 1.46 08-Nov-2015 millert

Quiet silly clang analyzer warning in calloc() usage.


# 1.45 04-Nov-2015 millert

Change cron from including all headers in every file to only including
what each .c file needs. I have not removed cron.h since it will
be used in a future clean up of the cron's .h files. OK nicm@


# 1.44 04-Nov-2015 millert

Change some globals from extern to static when they are not used
outside their respective .c files. Also remove some unused defines.
OK jung@


# 1.43 26-Oct-2015 millert

Remove some useless defines and the set_cron_uid() function.
OK jung@


# 1.42 06-Oct-2015 tedu

clear out some more legacy code and whatnot


# 1.41 03-Oct-2015 tedu

unifdef some features we will always have. ok benno zhuk


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.40 09-Feb-2015 deraadt

correct copyright, upon approval from paul vixie via todd miller. the
head copyright assertion was seperated from the remaining ones.


# 1.39 23-Jan-2015 tedu

braces to open a function go on their own line like god intended


# 1.38 23-Jan-2015 tedu

Remove the OK and ERR macros. They obfuscate the code and don't
help legibility. (unix system calls use 0 for ok, but hundreds of
other projects use 1 to indicate success.) Despite the name, many
system calls (e.g., open) also return not OK values for success.
It also cleans up some weird code like int crontab_fd = OK - 1;
This diff is mechanical in nature. Later I will fix the bugs it reveals.
ok deraadt


# 1.37 23-Jan-2015 tedu

remove debug code.
I think the level of debug code in cron is excessive for a program
that has reached feature complete. If cron needs to provide more
information to the user about its operational status, I think syslog
would be more appropriate. (The debug flags also disable forking
into the background, so they aren't even that useful for debugging a
live system.)
ok deraadt millert


# 1.36 22-Jan-2015 tedu

delete useless casts. ok deraadt guenther millert


# 1.35 14-Jan-2015 millert

Use HAVE_FOO for BSD-specific features instead of relying on the
BSD macro from sys/param.h.


# 1.34 25-Aug-2014 doug

Delete secret or secret-derived data with explicit_bzero.

concept ok deraadt@
diff looks ok tedu@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.33 19-May-2011 phessler

Fix some possible NULL pointer dereferences, and a little bit of cleanup.

From Lawrence Teo (thanks!)

OK krw@


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.32 29-Oct-2009 markus

do not discard the first character of the command after the -q option
ok millert@


# 1.31 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


Revision tags: OPENBSD_3_7_BASE OPENBSD_3_8_BASE OPENBSD_3_9_BASE OPENBSD_4_0_BASE OPENBSD_4_1_BASE OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.30 30-Jan-2005 millert

fix some whitespace


Revision tags: OPENBSD_3_6_BASE
# 1.29 22-Jun-2004 avsm

Recent glue_strings change reversed a few checks; fix up conditionals
to check for overflow as others do by convention.

Noticed by Andreas Kahari <ak+openbsd at freeshell.org>, millert@ ok


# 1.28 22-Jun-2004 avsm

use snprintf(3) instead of home-grown glue_strings() function
millert@ ok


# 1.27 17-Jun-2004 millert

UUpdate ISC copyright year to 2004
Remove unused macros Skip_Line and MkLower
Remove trailing whitespace


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE
# 1.26 26-Jun-2003 deraadt

two missing protos


# 1.25 17-Apr-2003 millert

Change a few return values from char to int since these functions
can return EOF. Fixes gcc warnings (and potential problems) on ppc.


Revision tags: OPENBSD_3_3_BASE
# 1.24 12-Mar-2003 millert

Move range sanity check out of get_number() and into get_range() since
it was causing problems with symbolic names (and get_range() is really
where it belongs anyway). Also allow a range to be followed by a ','
as pointed out by mpech@


# 1.23 11-Mar-2003 millert

Catch more syntax errors that were previously ignored. I've rewritten
get_number() to be more careful about what it accepts and to take
a string of terminating characters so it knows what is valid. Also
added a range check so that ranges like "60-50" where the first
number is greater than the second are now flagged.
Thanks to mpech@ for testing finding ways to abuse the parser :-)


# 1.22 10-Mar-2003 millert

Change a e_username to e_cmd.


# 1.21 10-Mar-2003 millert

Back out changes to get_number() that I didn't intend to commit.


# 1.20 10-Mar-2003 millert

Do the check for missing command before the un_getchar(); otherwise
the error messages will say line 0. This is because un_getchar('\n', file)
will decrement the line count. Noticed by mpech@


# 1.19 09-Mar-2003 millert

Fix error line number reporting for syntax errors (noticed by mpech@).
This is relatively tricky due to the way EOF is overloaded. Seems to
give a correct line number for all errors I threw at it.


# 1.18 04-Mar-2003 millert

Deref the correct passwd pointer in a Debug statement.


# 1.17 27-Feb-2003 millert

Fix parsing of '0' and non-alphanumerics in steps; found by mpech@


# 1.16 20-Feb-2003 millert

Sync with ISC cron-current + my at(1) integration.
The at(1) code is now more tightly integrated into the cron codebase.


Revision tags: OPENBSD_3_2_BASE
# 1.15 10-Aug-2002 millert

Just zero out pw_passwd in the pw_dup()'d copy. There's no need
to do this elsewhere and my previous commit in this area caused
problems on systems with an /etc/crontab file.


# 1.14 07-Aug-2002 millert

paranoia: zero out pw_passwd since we don't need it


# 1.13 15-Jul-2002 millert

Move atrun(8) functionality into cron(8) proper. This fixes the
long-standing annoyance that atrun's granularity is 10 minutes.
Most at jobs run with a 1 minute granularity. Jobs submitted via
"at now" or "batch" will run immediately. Includes a rewritten
cron(8) man page. at(1) will be integrated more closely into
cron at a future date.

Upgrading notes:
the atrun job in root's crontab should be removed.
the /var/at/spool directory is no longer used


# 1.12 11-Jul-2002 millert

More syncing with my cron 4.0 patch tree, basically cosmetic:
o change an instance of e_none to e_memory that I missed (forgot?)
o kill some whitespace
o modify malloc failure recovery a bit


# 1.11 11-Jul-2002 millert

Add a new error code for memory allocation failures, e_memory and
use that instead of e_none when we run out of memory.


# 1.10 08-Jul-2002 millert

Merge in some changes from Paul Vixie's tree; most are cosmetic
o ANSI function headers
o return (foo) not return foo
o add -oi to sendmail flags
o update email address in man pages
o make some strings const
o completely remove globbing cruft from popen.c
o whitespace changes
o add DOW_STAR to flags for "monthly", "weekly", and "daily" cron entries


# 1.9 14-Jun-2002 todd

spelling; from Brian Poole <raj@cerias.purdue.edu>


Revision tags: OPENBSD_2_9_BASE OPENBSD_3_0_BASE OPENBSD_3_1_BASE
# 1.8 18-Feb-2001 millert

Update to ISC cron 4.0b1 + our patches. This is now under a BSD license.
I also fixed the signal handlers while I was at it.


Revision tags: OPENBSD_2_8_BASE
# 1.7 21-Aug-2000 deraadt

snprintf sprinkles; solar@false.com & I


Revision tags: OPENBSD_2_7_BASE
# 1.6 18-Mar-2000 deraadt

fix parsing of commands after @ keywords and hourly bitmap handling;
sheldonh@uunet.co.za


Revision tags: OPENBSD_2_3_BASE OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE
# 1.5 22-Dec-1997 deraadt

handle timing normally except when clock jumps between 1 and 3 hours. If it
jumps, attempt as best as possible to gaurantee that jobs DO run, but only
run ONCE; patch by thompson@.tgsoft.com


Revision tags: OPENBSD_2_1_BASE OPENBSD_2_2_BASE
# 1.4 16-Dec-1996 deraadt

avoid more oflows; at this stage paranoia exceeds reality by a lot since our passwd suite is fascist


# 1.3 14-Dec-1996 millert

Check to make sure first char of command is not '*' since that will
alway be a syntax error.


# 1.2 01-Nov-1996 millert

Check malloc/strdup ret val and deal.


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.49 13-Jun-2018 job

Add crontab entry option -n for "No mail when run successful"

OK jmc@ millert@


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.48 14-Nov-2015 millert

Remove log_it() and call syslog(3) directly using the same format:
"(username) WHAT (details)". Logs due to normal operation (e.g.
crontab operations or running commands) are logged at LOG_INFO like
before. Actual errors are logged at LOG_ERR, less important things
are logged at LOG_WARNING OR LOG_NOTICE. Also ignore SIGHUP now
that there is no log file to reopen.


# 1.47 09-Nov-2015 millert

Remove unused xpid argument to log_it().


# 1.46 08-Nov-2015 millert

Quiet silly clang analyzer warning in calloc() usage.


# 1.45 04-Nov-2015 millert

Change cron from including all headers in every file to only including
what each .c file needs. I have not removed cron.h since it will
be used in a future clean up of the cron's .h files. OK nicm@


# 1.44 04-Nov-2015 millert

Change some globals from extern to static when they are not used
outside their respective .c files. Also remove some unused defines.
OK jung@


# 1.43 26-Oct-2015 millert

Remove some useless defines and the set_cron_uid() function.
OK jung@


# 1.42 06-Oct-2015 tedu

clear out some more legacy code and whatnot


# 1.41 03-Oct-2015 tedu

unifdef some features we will always have. ok benno zhuk


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.40 09-Feb-2015 deraadt

correct copyright, upon approval from paul vixie via todd miller. the
head copyright assertion was seperated from the remaining ones.


# 1.39 23-Jan-2015 tedu

braces to open a function go on their own line like god intended


# 1.38 23-Jan-2015 tedu

Remove the OK and ERR macros. They obfuscate the code and don't
help legibility. (unix system calls use 0 for ok, but hundreds of
other projects use 1 to indicate success.) Despite the name, many
system calls (e.g., open) also return not OK values for success.
It also cleans up some weird code like int crontab_fd = OK - 1;
This diff is mechanical in nature. Later I will fix the bugs it reveals.
ok deraadt


# 1.37 23-Jan-2015 tedu

remove debug code.
I think the level of debug code in cron is excessive for a program
that has reached feature complete. If cron needs to provide more
information to the user about its operational status, I think syslog
would be more appropriate. (The debug flags also disable forking
into the background, so they aren't even that useful for debugging a
live system.)
ok deraadt millert


# 1.36 22-Jan-2015 tedu

delete useless casts. ok deraadt guenther millert


# 1.35 14-Jan-2015 millert

Use HAVE_FOO for BSD-specific features instead of relying on the
BSD macro from sys/param.h.


# 1.34 25-Aug-2014 doug

Delete secret or secret-derived data with explicit_bzero.

concept ok deraadt@
diff looks ok tedu@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.33 19-May-2011 phessler

Fix some possible NULL pointer dereferences, and a little bit of cleanup.

From Lawrence Teo (thanks!)

OK krw@


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.32 29-Oct-2009 markus

do not discard the first character of the command after the -q option
ok millert@


# 1.31 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


Revision tags: OPENBSD_3_7_BASE OPENBSD_3_8_BASE OPENBSD_3_9_BASE OPENBSD_4_0_BASE OPENBSD_4_1_BASE OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.30 30-Jan-2005 millert

fix some whitespace


Revision tags: OPENBSD_3_6_BASE
# 1.29 22-Jun-2004 avsm

Recent glue_strings change reversed a few checks; fix up conditionals
to check for overflow as others do by convention.

Noticed by Andreas Kahari <ak+openbsd at freeshell.org>, millert@ ok


# 1.28 22-Jun-2004 avsm

use snprintf(3) instead of home-grown glue_strings() function
millert@ ok


# 1.27 17-Jun-2004 millert

UUpdate ISC copyright year to 2004
Remove unused macros Skip_Line and MkLower
Remove trailing whitespace


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE
# 1.26 26-Jun-2003 deraadt

two missing protos


# 1.25 17-Apr-2003 millert

Change a few return values from char to int since these functions
can return EOF. Fixes gcc warnings (and potential problems) on ppc.


Revision tags: OPENBSD_3_3_BASE
# 1.24 12-Mar-2003 millert

Move range sanity check out of get_number() and into get_range() since
it was causing problems with symbolic names (and get_range() is really
where it belongs anyway). Also allow a range to be followed by a ','
as pointed out by mpech@


# 1.23 11-Mar-2003 millert

Catch more syntax errors that were previously ignored. I've rewritten
get_number() to be more careful about what it accepts and to take
a string of terminating characters so it knows what is valid. Also
added a range check so that ranges like "60-50" where the first
number is greater than the second are now flagged.
Thanks to mpech@ for testing finding ways to abuse the parser :-)


# 1.22 10-Mar-2003 millert

Change a e_username to e_cmd.


# 1.21 10-Mar-2003 millert

Back out changes to get_number() that I didn't intend to commit.


# 1.20 10-Mar-2003 millert

Do the check for missing command before the un_getchar(); otherwise
the error messages will say line 0. This is because un_getchar('\n', file)
will decrement the line count. Noticed by mpech@


# 1.19 09-Mar-2003 millert

Fix error line number reporting for syntax errors (noticed by mpech@).
This is relatively tricky due to the way EOF is overloaded. Seems to
give a correct line number for all errors I threw at it.


# 1.18 04-Mar-2003 millert

Deref the correct passwd pointer in a Debug statement.


# 1.17 27-Feb-2003 millert

Fix parsing of '0' and non-alphanumerics in steps; found by mpech@


# 1.16 20-Feb-2003 millert

Sync with ISC cron-current + my at(1) integration.
The at(1) code is now more tightly integrated into the cron codebase.


Revision tags: OPENBSD_3_2_BASE
# 1.15 10-Aug-2002 millert

Just zero out pw_passwd in the pw_dup()'d copy. There's no need
to do this elsewhere and my previous commit in this area caused
problems on systems with an /etc/crontab file.


# 1.14 07-Aug-2002 millert

paranoia: zero out pw_passwd since we don't need it


# 1.13 15-Jul-2002 millert

Move atrun(8) functionality into cron(8) proper. This fixes the
long-standing annoyance that atrun's granularity is 10 minutes.
Most at jobs run with a 1 minute granularity. Jobs submitted via
"at now" or "batch" will run immediately. Includes a rewritten
cron(8) man page. at(1) will be integrated more closely into
cron at a future date.

Upgrading notes:
the atrun job in root's crontab should be removed.
the /var/at/spool directory is no longer used


# 1.12 11-Jul-2002 millert

More syncing with my cron 4.0 patch tree, basically cosmetic:
o change an instance of e_none to e_memory that I missed (forgot?)
o kill some whitespace
o modify malloc failure recovery a bit


# 1.11 11-Jul-2002 millert

Add a new error code for memory allocation failures, e_memory and
use that instead of e_none when we run out of memory.


# 1.10 08-Jul-2002 millert

Merge in some changes from Paul Vixie's tree; most are cosmetic
o ANSI function headers
o return (foo) not return foo
o add -oi to sendmail flags
o update email address in man pages
o make some strings const
o completely remove globbing cruft from popen.c
o whitespace changes
o add DOW_STAR to flags for "monthly", "weekly", and "daily" cron entries


# 1.9 14-Jun-2002 todd

spelling; from Brian Poole <raj@cerias.purdue.edu>


Revision tags: OPENBSD_2_9_BASE OPENBSD_3_0_BASE OPENBSD_3_1_BASE
# 1.8 18-Feb-2001 millert

Update to ISC cron 4.0b1 + our patches. This is now under a BSD license.
I also fixed the signal handlers while I was at it.


Revision tags: OPENBSD_2_8_BASE
# 1.7 21-Aug-2000 deraadt

snprintf sprinkles; solar@false.com & I


Revision tags: OPENBSD_2_7_BASE
# 1.6 18-Mar-2000 deraadt

fix parsing of commands after @ keywords and hourly bitmap handling;
sheldonh@uunet.co.za


Revision tags: OPENBSD_2_3_BASE OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE
# 1.5 22-Dec-1997 deraadt

handle timing normally except when clock jumps between 1 and 3 hours. If it
jumps, attempt as best as possible to gaurantee that jobs DO run, but only
run ONCE; patch by thompson@.tgsoft.com


Revision tags: OPENBSD_2_1_BASE OPENBSD_2_2_BASE
# 1.4 16-Dec-1996 deraadt

avoid more oflows; at this stage paranoia exceeds reality by a lot since our passwd suite is fascist


# 1.3 14-Dec-1996 millert

Check to make sure first char of command is not '*' since that will
alway be a syntax error.


# 1.2 01-Nov-1996 millert

Check malloc/strdup ret val and deal.


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.48 14-Nov-2015 millert

Remove log_it() and call syslog(3) directly using the same format:
"(username) WHAT (details)". Logs due to normal operation (e.g.
crontab operations or running commands) are logged at LOG_INFO like
before. Actual errors are logged at LOG_ERR, less important things
are logged at LOG_WARNING OR LOG_NOTICE. Also ignore SIGHUP now
that there is no log file to reopen.


# 1.47 09-Nov-2015 millert

Remove unused xpid argument to log_it().


# 1.46 08-Nov-2015 millert

Quiet silly clang analyzer warning in calloc() usage.


# 1.45 04-Nov-2015 millert

Change cron from including all headers in every file to only including
what each .c file needs. I have not removed cron.h since it will
be used in a future clean up of the cron's .h files. OK nicm@


# 1.44 04-Nov-2015 millert

Change some globals from extern to static when they are not used
outside their respective .c files. Also remove some unused defines.
OK jung@


# 1.43 26-Oct-2015 millert

Remove some useless defines and the set_cron_uid() function.
OK jung@


# 1.42 06-Oct-2015 tedu

clear out some more legacy code and whatnot


# 1.41 03-Oct-2015 tedu

unifdef some features we will always have. ok benno zhuk


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.40 09-Feb-2015 deraadt

correct copyright, upon approval from paul vixie via todd miller. the
head copyright assertion was seperated from the remaining ones.


# 1.39 23-Jan-2015 tedu

braces to open a function go on their own line like god intended


# 1.38 23-Jan-2015 tedu

Remove the OK and ERR macros. They obfuscate the code and don't
help legibility. (unix system calls use 0 for ok, but hundreds of
other projects use 1 to indicate success.) Despite the name, many
system calls (e.g., open) also return not OK values for success.
It also cleans up some weird code like int crontab_fd = OK - 1;
This diff is mechanical in nature. Later I will fix the bugs it reveals.
ok deraadt


# 1.37 23-Jan-2015 tedu

remove debug code.
I think the level of debug code in cron is excessive for a program
that has reached feature complete. If cron needs to provide more
information to the user about its operational status, I think syslog
would be more appropriate. (The debug flags also disable forking
into the background, so they aren't even that useful for debugging a
live system.)
ok deraadt millert


# 1.36 22-Jan-2015 tedu

delete useless casts. ok deraadt guenther millert


# 1.35 14-Jan-2015 millert

Use HAVE_FOO for BSD-specific features instead of relying on the
BSD macro from sys/param.h.


# 1.34 25-Aug-2014 doug

Delete secret or secret-derived data with explicit_bzero.

concept ok deraadt@
diff looks ok tedu@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.33 19-May-2011 phessler

Fix some possible NULL pointer dereferences, and a little bit of cleanup.

From Lawrence Teo (thanks!)

OK krw@


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.32 29-Oct-2009 markus

do not discard the first character of the command after the -q option
ok millert@


# 1.31 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


Revision tags: OPENBSD_3_7_BASE OPENBSD_3_8_BASE OPENBSD_3_9_BASE OPENBSD_4_0_BASE OPENBSD_4_1_BASE OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.30 30-Jan-2005 millert

fix some whitespace


Revision tags: OPENBSD_3_6_BASE
# 1.29 22-Jun-2004 avsm

Recent glue_strings change reversed a few checks; fix up conditionals
to check for overflow as others do by convention.

Noticed by Andreas Kahari <ak+openbsd at freeshell.org>, millert@ ok


# 1.28 22-Jun-2004 avsm

use snprintf(3) instead of home-grown glue_strings() function
millert@ ok


# 1.27 17-Jun-2004 millert

UUpdate ISC copyright year to 2004
Remove unused macros Skip_Line and MkLower
Remove trailing whitespace


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE
# 1.26 26-Jun-2003 deraadt

two missing protos


# 1.25 17-Apr-2003 millert

Change a few return values from char to int since these functions
can return EOF. Fixes gcc warnings (and potential problems) on ppc.


Revision tags: OPENBSD_3_3_BASE
# 1.24 12-Mar-2003 millert

Move range sanity check out of get_number() and into get_range() since
it was causing problems with symbolic names (and get_range() is really
where it belongs anyway). Also allow a range to be followed by a ','
as pointed out by mpech@


# 1.23 11-Mar-2003 millert

Catch more syntax errors that were previously ignored. I've rewritten
get_number() to be more careful about what it accepts and to take
a string of terminating characters so it knows what is valid. Also
added a range check so that ranges like "60-50" where the first
number is greater than the second are now flagged.
Thanks to mpech@ for testing finding ways to abuse the parser :-)


# 1.22 10-Mar-2003 millert

Change a e_username to e_cmd.


# 1.21 10-Mar-2003 millert

Back out changes to get_number() that I didn't intend to commit.


# 1.20 10-Mar-2003 millert

Do the check for missing command before the un_getchar(); otherwise
the error messages will say line 0. This is because un_getchar('\n', file)
will decrement the line count. Noticed by mpech@


# 1.19 09-Mar-2003 millert

Fix error line number reporting for syntax errors (noticed by mpech@).
This is relatively tricky due to the way EOF is overloaded. Seems to
give a correct line number for all errors I threw at it.


# 1.18 04-Mar-2003 millert

Deref the correct passwd pointer in a Debug statement.


# 1.17 27-Feb-2003 millert

Fix parsing of '0' and non-alphanumerics in steps; found by mpech@


# 1.16 20-Feb-2003 millert

Sync with ISC cron-current + my at(1) integration.
The at(1) code is now more tightly integrated into the cron codebase.


Revision tags: OPENBSD_3_2_BASE
# 1.15 10-Aug-2002 millert

Just zero out pw_passwd in the pw_dup()'d copy. There's no need
to do this elsewhere and my previous commit in this area caused
problems on systems with an /etc/crontab file.


# 1.14 07-Aug-2002 millert

paranoia: zero out pw_passwd since we don't need it


# 1.13 15-Jul-2002 millert

Move atrun(8) functionality into cron(8) proper. This fixes the
long-standing annoyance that atrun's granularity is 10 minutes.
Most at jobs run with a 1 minute granularity. Jobs submitted via
"at now" or "batch" will run immediately. Includes a rewritten
cron(8) man page. at(1) will be integrated more closely into
cron at a future date.

Upgrading notes:
the atrun job in root's crontab should be removed.
the /var/at/spool directory is no longer used


# 1.12 11-Jul-2002 millert

More syncing with my cron 4.0 patch tree, basically cosmetic:
o change an instance of e_none to e_memory that I missed (forgot?)
o kill some whitespace
o modify malloc failure recovery a bit


# 1.11 11-Jul-2002 millert

Add a new error code for memory allocation failures, e_memory and
use that instead of e_none when we run out of memory.


# 1.10 08-Jul-2002 millert

Merge in some changes from Paul Vixie's tree; most are cosmetic
o ANSI function headers
o return (foo) not return foo
o add -oi to sendmail flags
o update email address in man pages
o make some strings const
o completely remove globbing cruft from popen.c
o whitespace changes
o add DOW_STAR to flags for "monthly", "weekly", and "daily" cron entries


# 1.9 14-Jun-2002 todd

spelling; from Brian Poole <raj@cerias.purdue.edu>


Revision tags: OPENBSD_2_9_BASE OPENBSD_3_0_BASE OPENBSD_3_1_BASE
# 1.8 18-Feb-2001 millert

Update to ISC cron 4.0b1 + our patches. This is now under a BSD license.
I also fixed the signal handlers while I was at it.


Revision tags: OPENBSD_2_8_BASE
# 1.7 21-Aug-2000 deraadt

snprintf sprinkles; solar@false.com & I


Revision tags: OPENBSD_2_7_BASE
# 1.6 18-Mar-2000 deraadt

fix parsing of commands after @ keywords and hourly bitmap handling;
sheldonh@uunet.co.za


Revision tags: OPENBSD_2_3_BASE OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE
# 1.5 22-Dec-1997 deraadt

handle timing normally except when clock jumps between 1 and 3 hours. If it
jumps, attempt as best as possible to gaurantee that jobs DO run, but only
run ONCE; patch by thompson@.tgsoft.com


Revision tags: OPENBSD_2_1_BASE OPENBSD_2_2_BASE
# 1.4 16-Dec-1996 deraadt

avoid more oflows; at this stage paranoia exceeds reality by a lot since our passwd suite is fascist


# 1.3 14-Dec-1996 millert

Check to make sure first char of command is not '*' since that will
alway be a syntax error.


# 1.2 01-Nov-1996 millert

Check malloc/strdup ret val and deal.


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision