Commit Graph

196 Commits

Author SHA1 Message Date
Kevin Lo
784bddbc5b Cleanup of userland __P use 2007-11-07 10:53:41 +00:00
Ruslan Ermilov
0376869747 Fixed static linkage (build with -DNO_SHARED).
Approved by:	re (kensmith)
2007-10-01 18:17:24 +00:00
Yaroslav Tykhiy
997c6eefd8 Add PAM support to cron(8). Now cron(8) will skip commands scheduled
by unavailable accounts, e.g., those locked, expired, not allowed in at
the moment by nologin(5), or whatever, depending on cron's pam.conf(5).
This applies to personal crontabs only, /etc/crontab is unaffected.

In other words, now the account management policy will apply to
commands scheduled by users via crontab(1) so that a user can no
longer use cron(8) to set up a delayed backdoor and run commands
during periods when the admin doesn't want him to.

The PAM check is done just before running a command, not when loading
a crontab, because accounts can get locked, expired, and re-enabled
any time with no changes to their crontabs.  E.g., imagine that you
provide a system with payed access, or better a cluster of such
systems with centralized account management via PAM.  When a user
pays for some days of access, you set his expire field respectively.
If the account expires before its owner pays more, its crontab
commands won't run until the next payment is made.  Then it'll be
enough to set the expire field in future for the commands to run
again.  And so on.

Document this change in the cron(8) manpage, which includes adding
a FILES section and touching the document date.

X-Security: should benefit as users have access to cron(8) by default
2007-06-17 17:25:53 +00:00
Will Andrews
2ba44ac557 Fix a bug where HOME was not allowed to be overridden by an user's crontab
as crontab(5) states it can be.  This is supported by all vixie-cron derived
implementations; not sure why FreeBSD was any different.

PR:		bin/106442
MFC after:	2 weeks
2007-03-08 07:00:42 +00:00
Brian Somers
cf2603700e Behave as documented when reading fields saying "X/Y" where X != *
rather than mis-parsing them as "X".

MFC after: 1 day
2006-09-26 18:06:09 +00:00
Ruslan Ermilov
405a44d326 Use a #define to refer to /etc/crontab. 2006-09-03 17:52:19 +00:00
Stefan Farfeleder
531c70a642 Don't use "implicit int". Move the opening { of the functions to the next
line while there.
2006-07-20 09:11:08 +00:00
Maxim Konovalov
708f27a157 o Finally learn how to spell "privileges".
English trainer:	ceri
2006-06-11 21:13:49 +00:00
Maxim Konovalov
b608e56d62 o Spell "privledges" correctly. Re-style comment. 2006-06-11 20:17:18 +00:00
Maxim Konovalov
bb0aa1a544 o Better be safe than sorry: check return code from setuid(2),
setgid(2), setlogin(2) and initgroups(3).  In theory they could
fail for root with some third party mac(4) policies.

Submitted by:	Kostik Belousov
MFC after:	1 month
2006-06-01 15:03:06 +00:00
Brooks Davis
9896de5a67 /etc/crontab is similar enough to parse as correct if you run
"crontab /etc/crontab", but not the same format due to the who field.
Add some limited anti-foot-shooting support and refuse to load
/etc/crontab as someone's crontab.  Users wishing shoot their foot in
this manner may copy /etc/crontab elsewhere. :)

MFC After:	1 week
2006-01-10 05:56:32 +00:00
Pawel Jakub Dawidek
8b28aef238 Pidfiles should be created with permission preventing users from opening
them for reading. When user can open file for reading, he can also
flock(2) it, which can lead to confusions.

Pointed out by:	green
2005-09-16 11:24:28 +00:00
Pawel Jakub Dawidek
78735592f5 Use pidfile(3) in cron(8).
Note, that when cron(8) cannot create pidfile, it'll exit. I didn't
changed this behaviour, but its better to ignore errors other than
EEXIST, so daemon can be started on systems where /var/ file system
doesn't support locking (like NFS without rpc.lockd(8)).
2005-08-24 17:51:36 +00:00
Christian Brueffer
48193882ad Mention the default value of PATH and that it may be overridden.
Submitted by:	Roman Divacky
MFC after:	3 days
2005-07-31 13:41:23 +00:00
Dag-Erling Smørgrav
ee66677a7a Remove kludges intended to support src trees with partial obj trees.
Discussed with:	ru
2005-06-10 06:12:53 +00:00
Xin LI
d159401da0 Fix parsing of '0' and non-alphanumerics in steps. Previously, an
entry having stepping value of zero can cause crontab to hang there,
and if the main crontab is being changed in this way, then cron(8)
will keep spining.

Obtained from:	OpenBSD [src/usr.sbin/cron/entry.c,v 1.17]
PR:		68683 (my own, but forgot to commit it...)
MFC After:	1 week
2005-02-14 14:09:21 +00:00
Ruslan Ermilov
36a142c455 Expand contractions. 2005-02-13 23:45:54 +00:00
Ruslan Ermilov
0227791b40 Expand *n't contractions. 2005-02-13 22:25:33 +00:00
Stefan Farfeleder
93931378d9 Properly initialise the variable `deny'. 2005-02-09 13:02:43 +00:00
Ruslan Ermilov
59a3c79da6 Sort sections. 2005-01-18 20:02:45 +00:00
Ruslan Ermilov
dee651eb15 Introduce the PRECIOUSPROG knob in bsd.prog.mk, similar
to PRECIOUSLIB from bsd.lib.mk.  The side effect of this
is making installing the world under jail(8) possible by
using another knob, NOFSCHG.

Reviewed by:	oliver
2004-11-03 18:01:21 +00:00
Ruslan Ermilov
a35d88931c For variables that are only checked with defined(), don't provide
any fake value.
2004-10-24 15:33:08 +00:00
Diomidis Spinellis
0cd2e3abe5 Ensure that edits that do not span a clock tick are not lost.
PR:	bin/22612
MT5:	4 weeks
MT4:	2 weeks
2004-09-14 19:01:19 +00:00
Diomidis Spinellis
9a2ef7d172 Refactoring: move two similar code blocks into a seprate function. 2004-09-13 21:04:30 +00:00
Diomidis Spinellis
08e019a888 Fix for the following behavior:
$ crontab -e
[Add an entry with an error in the crontab file.]
crontab: errors in crontab file, can't install
Do you want to retry the same edit? yes
[Exit the editor without any changes.]
crontab: no changes made to crontab
[Entry is lost.]

Now crontab will loop until the error is fixed, or the
user answers no.
2004-09-13 18:39:04 +00:00
Ruslan Ermilov
07bfccd71e Mechanically kill hard sentence breaks. 2004-07-02 23:13:00 +00:00
Ruslan Ermilov
31a06a8e6c Trim whitespace at EOL. 2004-06-04 19:24:21 +00:00
Ruslan Ermilov
b18b186e57 Markup nits. 2004-06-04 19:23:12 +00:00
Yaroslav Tykhiy
f5896baf9c Add two new options to cron(8), -J and -j. They allow to specify
the maximum amount of time jitter for root and other users, respectively.
Before starting a job, cron(8) will sleep a random number of seconds,
from 0 to the amount specified.  This can help to smooth down load spikes
when a lot of jobs are to start at the beginning of a particular minute
(e.g., the first minute of an hour.)

PR:		bin/66474
Submitted by:	Dmitry Morozovsky <marck <@> rinet.ru>
2004-05-16 19:29:33 +00:00
Tom Rhodes
aaa66740bf Eliminate hard sentence breaks.
General markup fixes (use the .Dq macro).
2004-03-04 19:12:27 +00:00
Tom Rhodes
8030199c71 Discuss the 'MAILTO' option.
PR:		58783
Submitted by:	Marc Silver <marcs@draenor.org>
2004-01-12 20:20:29 +00:00
Hartmut Brandt
b9ff618c3a Mention the fact that our crontab is not fully POSIX.2 conform, because
it doesn't allow the dangerous variant of calling it without any
argument.
2003-10-24 13:02:39 +00:00
Mike Silbersack
9be756b54b Fix a coredump that would occur when fdopen was unable to
return a valid fd.

PR:		49096
Submitted by:	demon
MFC after:	3 days
2003-06-19 20:04:51 +00:00
Thomas Quinot
6ced08bfa6 Allow inner whitespace in the right-hand side of an environment variable
assignment even if it is not quoted (as advertised by the man page).
This fixes a regression wrt RELENG_4 introduced in rev. 1.11.

Problem noted and patch tested by:	CHOI Junho <cjh@kr.FreeBSD.org>
Reviewed by:		roberto
2003-02-10 11:20:58 +00:00
Jens Schweikhardt
57bd0fc6e8 english(4) police. 2002-12-27 12:15:40 +00:00
Dima Dorfman
e9d295bf0b Actually use the exitstatus value that we maintain.
PR:		43562
Submitted by:	Marc Olzheim <marcolz@ilse.nl>
2002-10-01 22:59:11 +00:00
Tim J. Robbins
526b145c23 Never allow a user to use crontab if opening /var/cron/{allow,deny} fails
for any reason other than ENOENT (think resource limits). Close allow and
deny files before allowed() returns to stop the user's EDITOR being able to
read them.

Obtained from:	OpenBSD (partially)
2002-08-04 04:32:27 +00:00
Philippe Charnier
490d5836b5 The .Nm utility 2002-07-14 14:47:15 +00:00
Ollivier Robert
bb817201ed load_env(), the function that attempts to parse a crontab
line as an environment variable assignment, is broken
and not conformant to its description in the manual page.

I think it is worthwhile to have that fix in 4.6.

PR:             bin/38374
Submitted by:   Thomas Quinot <thomas@cuivre.fr.eu.org>
MFC after:      2 days
2002-05-23 13:16:30 +00:00
Ruslan Ermilov
423e9124d9 Mark all internal libraries with INTERNALLIB. 2002-05-13 11:24:03 +00:00
Philippe Charnier
7f94b8deee Use `The .Nm utility' 2002-04-20 12:27:18 +00:00
David Malone
879e98b647 Only remove the '\n' at the end of a line if there is one.
I missed this as part of the fix to the PR below.

PR:		31265
Submitted by:	Matthew D. Fuller <fullermd@over-yonder.net>
MFC after:	1 week
2002-04-10 22:01:37 +00:00
Giorgos Keramidas
cbbc2d594e Be a bit more verbose. "modtime" means nothing.
"modification time" is a lot better.

MFC after:      3 days
2002-03-24 00:56:38 +00:00
Giorgos Keramidas
4188e02521 Grammar fix: "When at least one of the fields .. matches ...".
MFC after:      3 days
2002-03-24 00:48:07 +00:00
David Malone
377a2e036f Describe the format of the allow and deny files. This is more-or-less
the patch Matthew submitted, but I broke the lines in a more FreeBSD
way and made one small wording change.

PR:		31265
Submitted by:	Matthew D. Fuller <fullermd@over-yonder.net>
MFC after:	3 weeks
2002-03-17 14:03:17 +00:00
Rob Braun
af71ab4f58 Make cron actually build without defining LOGIN_CAP.
Reviewed by: jkh
2002-02-06 02:00:07 +00:00
Ruslan Ermilov
3b1057ce33 Document the -x debugging option.
PR:		docs/33784
Submitted by:	Mike Makonnen <mike_makonnen@yahoo.com>
2002-01-16 14:12:02 +00:00
Mike Heffner
93cbb1d1cc Fix the @monthly and @weekly shortcuts so that they actually run
monthly and weekly, respectively. Also fix the @yearly shortcut so
that it doesn't execute daily during January. OpenBSD and NetBSD also
appear to have this bug.

PR:		bin/21152
2001-08-16 14:23:59 +00:00
Ruslan Ermilov
753d686d34 mdoc(7) police: s/BSD/.Bx/ where appropriate. 2001-08-14 10:01:54 +00:00
Ruslan Ermilov
c75526d5a0 mdoc(7) police: fixed the "new sentence" bogons. 2001-08-10 15:03:10 +00:00
Bill Fumerola
fd522d40d8 fix misspelling introduced in rev 1.14 (sames as -> same as) 2001-07-25 04:13:01 +00:00
David Nugent
4a9e66b57b Fix a possible NULL reference that would be triggered
by invalid input in /etc/crontab.

MFC after:	2 days
2001-07-20 06:46:48 +00:00
David E. O'Brien
90e655ea4e Perform a major cleanup of the usr.sbin Makefiles.
These are not perfectly in agreement with each other style-wise, but they
are orders of orders of magnitude more consistent style-wise than before.
2001-07-20 06:20:32 +00:00
Dima Dorfman
b30f37abbb Remove an unused variable, and don't try to print a char[] using %d.
Submitted by:	Mark Peek <mark@whistle.com>
2001-07-18 11:49:45 +00:00
Dima Dorfman
5d3e1fcab1 free_entry(): Don't free e->envp if it's already NULL; likewise for
e->cmd.  free_entry() now does the right thing with
partially-initialized structures.

load_entry(): Don't call env_free() on e->envp throughout the routine
before jumping to eof; the free_entry() call at that label will take
care of it.  The previous behavior resulted in e->envp being free'd
twice (well, the second time would usually result in a crash, but
that's besides the point); once in load_entry(), and once in
free_entry() after the former called the latter.  Also note that the
check added to free_entry() (above) doesn't help, since e->envp wasn't
reset to NULL after env_free().

Submitted by:	Mark Peek <mark@whistle.com>
2001-07-18 11:48:00 +00:00
Dima Dorfman
f247324df7 Remove whitespace at EOL. 2001-07-15 08:06:20 +00:00
Brian Somers
7bc6d0158f Fix the type of the NULL arg to execl()
Idea from: Theo de Raadt <deraadt@openbsd.org>
2001-07-09 09:24:06 +00:00
Peter Wemm
d952a14dbb Where is the pointy hat? Fix cut/paste error. (hey, it compiled! :-) 2001-06-16 03:16:52 +00:00
Dima Dorfman
fa0590b3d3 Plug two memory leaks: call login_close() after login_getclass(), and
use free_entry() instead of free() to free a struct _entry.

PR:		28108
Submitted by:	Mark Peek <mark@whistle.com>
2001-06-13 05:49:37 +00:00
Peter Wemm
8966f5046e Remove the 'DO NOT EDIT THIS FILE' crud that we spit out with 'crontab -l'.
Otherwise, "crontab -l > file; vi file; crontab file" adds an extra set
of "DO NOT EDIT" markers each and every time which is a bit silly.
2001-04-13 01:45:22 +00:00
Ruslan Ermilov
345e52e742 - Backout botched attempt to introduce MANSECT feature.
- MAN[1-9] -> MAN.
2001-03-26 14:42:20 +00:00
Ruslan Ermilov
c73e22c3d4 Set the default manual section for usr.sbin/ to 8. 2001-03-20 18:17:26 +00:00
Peter Wemm
c7517d5af9 Stop cron from shouting in the syslog. Use setproctitle() instead, since
smashing argv[0] doesn't have the intended effect of changing the ps(1)
output these days.

PR:		25850
2001-03-17 00:21:54 +00:00
Ruslan Ermilov
ac94747952 mdoc(7) police revision 1.15:
- replaced Oo/Oc enclosures with Op;
- removed hard sentence breaks;
- removed doubled space.
2001-03-09 11:02:01 +00:00
Sergey Babkin
404363cc17 The new version of the daylight time saving support. This time it works
for any change of the time zone offset from GMT. To enable use the
option -s.
2001-03-09 03:14:09 +00:00
Peter Wemm
1db78faf47 Properly detach at startup. We could be passing revoked fd's to
child processes or starting children with no fd 0 (stdin) at all etc.
This is currently breaking on hub.freebsd.org.
2001-03-07 10:38:46 +00:00
Jeroen Ruigrok van der Werven
1a6e52d0e9 Fix typo: seperate -> separate.
Seperate does not exist in the english language.
2001-02-06 11:21:58 +00:00
Ruslan Ermilov
610a5778c5 mdoc(7) police: split punctuation characters + misc fixes. 2001-02-01 16:44:04 +00:00
Sergey Babkin
6548bd5646 Backed out the DST support changes. 2001-01-23 01:17:40 +00:00
Ruslan Ermilov
9c11143f2c mdoc(7) police: ``Ds'' is not certified (no macro with such name exist)
to be used as the -width parameter, it is provided solely for backwards
compatibility with old mdoc(7).  To make this work, mdocNG is forced to
provide a dummy ``Ds'' macro.
2001-01-22 10:27:07 +00:00
Sergey Babkin
be821963c1 Made the special handling of the daylight time switches optional,
enabled by the option "-s" (for dSt). This returned the default behavior
to its original form.

The new option name is not "-d" because that would cause associations with
"debug" and cron already has "-x" for debugging, so this would cause
confusion.
2001-01-22 01:54:51 +00:00
Sergey Babkin
08b2398e6d Added sensible handling of switch to and from daylight saving time
for the jobs that fall into the disappearing or duplicated time
interval.

PR:		bin/24494
2001-01-20 21:28:16 +00:00
Ruslan Ermilov
c5083414f8 mdoc(7) police: removed leading whitespaces that are not inside
Bd/Ed; these hardly degrade the quality of the produced output.
2001-01-19 14:15:40 +00:00
Ruslan Ermilov
1bfea903ed Prepare for mdoc(7)NG. 2001-01-16 09:39:23 +00:00
David E. O'Brien
1a37aa566b Add `_PATH_DEVZERO'.
Use _PATH_* where where possible.
2000-12-09 09:35:55 +00:00
Kris Kennaway
f313a39933 Correct definition of MAXHOSTNAMELEN in ifdef'ed out code 2000-11-26 22:21:39 +00:00
Ruslan Ermilov
e97407b4f2 mdoc(7) police: use the new features of the Nm macro. 2000-11-20 20:10:44 +00:00
Ruslan Ermilov
726b61ab5f Avoid use of direct troff requests in mdoc(7) manual pages. 2000-11-10 17:46:15 +00:00
David Malone
25e9ca2b19 Attempt to fix problem with users being able to convince the crontab
program to read any file which is a valid crontab file.

The fix is based on that used in NetBSD and OpenBSD - we keep the
file open while the user is editing it. This means that files must
be edited in place. Cron attempts to warn you if your editor does
not do this. The fact that the file must be edited in place is also
noted in the man page.

This patch has been confirmed to work by atleast one person on
-security and has been tested locally.

Obtained from:	OpenBSD
2000-11-06 11:17:37 +00:00
Paul Richards
30cfb24129 Since -e and -r are right next to each other prompt before clobbering
a crontab you were planning to edit.
2000-10-15 00:35:34 +00:00
Andrey A. Chernov
3d99cebff4 Call login_close() to prevent parent from memory leaking in some
cases due to vfork()
2000-07-02 04:15:15 +00:00
Andrey A. Chernov
fe46d6a8f3 Prevent user from breaking his limits and restrictions or
abusing sendmail by any other way via MAILTO tag (since sendmail is running
from daemon). Now run sendmail from user, as any other cron user command.

Obtained from:	Inspired by OpenBSD, but implementation is different
2000-07-01 22:58:16 +00:00
Andrey A. Chernov
c38d808de1 Make sure argv gets NULL terminated if cron entry has >= MAX_ARGS arguments
Obtained from:	OpenBSD popen.c v1.3
2000-07-01 22:37:02 +00:00
Andrey A. Chernov
5e4a74ec02 Enable SIGCHLD to stop childs complaining to SIG_IGN of it.
It helps perl f.e.

Obtained from:	OpenBSD do_command.c v1.7
2000-07-01 21:25:33 +00:00
Guy Helmer
64ae78cb9d Catch and report fdopen failures. 2000-05-23 13:46:04 +00:00
Guy Helmer
5c7cba96bc Catch and report memory allocation failures. 2000-05-23 13:44:00 +00:00
Guy Helmer
d02e530b50 Allocate space for arrays of type "char *", not "char **".
Rev 1.8 made the type consistently incorrect.

Noted by:	Ben Smithurst <ben@scientia.demon.co.uk>
2000-04-30 15:57:00 +00:00
Guy Helmer
8261236de4 Fix a situation where a pointer which should point to dynamically
allocated memory was instead pointed to a static string.  A later
free() on the value of the pointer was a possible source of reported
"warning: pointer to wrong page" messages from cron.

Use consistent types in sizeof when malloc'ing memory for the
environment.

PR:		kern/12248, bin/11169, bin/9722
2000-04-28 15:31:28 +00:00
Sheldon Hearn
c3e1da6b96 Revive rev 1.12 (NetBSD improvements including @ shortcuts). 2000-03-14 14:51:55 +00:00
Guy Helmer
5b0e9f8cb1 Fix parsing of commands after @ keywords (@hourly, @daily, etc.).
Fix setting of "hour" bitmap when @hourly keyword is specified.

MFC candidate after 4.0-RELEASE.

Problem-found-by: Sheldon Hearn <sheldonh@uunet.co.za>
2000-03-13 19:21:17 +00:00
Sheldon Hearn
465c6ce100 Back out previous commit. The code is not ready for it. 2000-03-13 19:13:48 +00:00
Sheldon Hearn
874072c7bb Merge in NetBSD improvements:
* Clarify quoting value in of name = value pairs.
	* Describe the @reboot, @yearly, @annually, @monthly, @weekly,
	  @daily, @midnight and @hourly extensions.

PR:		17261
Submitted by:	MIHIRA Yoshiro <sanpei@sanpei.org>
Obtained from:	NetBSD
2000-03-08 11:48:01 +00:00
Peter Wemm
97d92980a9 $Id$ -> $FreeBSD$ 1999-08-28 01:35:59 +00:00
Chris Costello
866d7f2809 Bad reference of su(8) changed to su(1). 1999-08-14 06:34:50 +00:00
Sheldon Hearn
81f4b03663 Christen a BUGS section for an explanation of the impact of Daylight
Savings Time on cron(8). If we ever introduce some work-around code for
handling jobs scheduled for a time that "doesn't happen" due to DST,
the section should be renamed to IMPLEMENTATION NOTES.

PR:	10947
Reported by:	Scott Drassinower <scottd@cloud9.net>
Submitted by:	Seth Bromberger <seth@freebie.dp.ny.frb.org>
Reviewed by:	mpp
1999-08-11 13:00:19 +00:00
Nick Hibma
d2a864e4ba Changed 'overriding what /etc/passwd says' to 'overriding default set
by cron'

PR:		12520
Submitted by:	(not specified)
1999-07-27 16:39:02 +00:00
Peter Wemm
5ef4895832 This is a hack. Cron runs with stdin/out/err pointing to /dev/console,
which init thoughtfully revoke()'s when starting a getty on ttyv0.  This
Cron's popen() was passing these fd's through to cron children (ie:
sendmail, *not* normal cron jobs).  The side effects were usually
not noticed, but it tripped up postfix which did a sanity check to see
that stdin/out/err were open, and got EBADF even thought the fd's were
in use.  I seem to recall sendmail itself has hacks to work around
this problem, it had a checkfd012() function, possibly for this same
problem.  (Postfix has a workaround too now though..)

This is a hack, not a fix.  It's probably best to check and perhaps
close/reopen() /dev/console if needed each time around the event loop.
It would probably be useful to actually see any error messages from cron.
1999-04-06 04:31:23 +00:00
Daniel O'Callaghan
b9a1702cc2 y2k nit: print 4 digit years correctly.
PR:		9506
Submitted by:	Peter Jeremy <peter.jeremy@alcatel.com.au>
1999-01-16 01:51:03 +00:00
Matthew Dillon
4ef875d707 PR: bin/5572
Prevent cron from going crazy if the time steps.  For example, if you
    have a system with hundreds of users and lots of different crontabs
    and your time steps back an hour, the old cron would then attempt to
    run an hours worth of cron jobs in a few seconds.
1998-12-13 06:07:38 +00:00
Bruce Evans
78cda23056 Fixed printf format errors. 1998-07-06 20:28:08 +00:00