Import vixie cron 4.0

Specifically, import the diff from commit e745bd4c10ab to
commit 83563783cc2 in https://github.com/vixie/cron.git

My sole motivation is changing to the common MIT license.
The old license, especially the "buildable source" clause,
is unfriendly for commercial users of this code.  Simply
changing the license without importing [most of] the code
accompanying that license seemed legally dubious.

The most regrettable change is losing Paul's uucp path.
I partially atone for this loss by restoring the upstream
$Id$ tags, since $FreeBSD$ is no longer useful.

This is [intended to be] a complete list of the functional
changes in this commit.  Some changes were made so that we
could consider vixie cron to be our upstream and reduce our
diffs against it, while others were simply a good idea.

- main() - use putenv instead of setenv for PATH
- open_pidfile no longer needs snprintf to build pidfile
- crontab main() - abort() on impossible errors
- check for truncation when building strings with snprintf
- getdtablesize() -> sysconf(_SC_OPEN_MAX)

These changes were not taken from upstream's 4.0 diff because
they [could] actually change behavior.  Some of them might be
beneficial, but should be taken separately.

- config.h - sendmail args: remove -oi and add -or0s
- call setlocale(LC_ALL, "") at the top of main()
- acquire_daemonlock - we already use pidfile
- cast getpid(), uid_t, and gid_t to long for printf
- remove unnecessary braces - I consider them beneficial
- BSDi support
- glue_strings() - use snprintf(), as we often already did

MFC after:	on demand
Sponsored by:	Dell EMC Isilon
Differential Revision:	https://reviews.freebsd.org/D40260
This commit is contained in:
Eric van Gyzen 2023-06-01 14:14:07 -05:00
parent be75e57854
commit fe590ffe40
26 changed files with 1099 additions and 1406 deletions

View File

@ -1,136 +0,0 @@
/* Copyright 1993,1994 by Paul Vixie
* All rights reserved
*
* Distribute freely, except: don't remove my name from the source or
* documentation (don't take credit for my work), mark your changes (don't
* get me blamed for your possible bugs), don't alter or remove this
* notice. May be sold if buildable source is provided to buyer. No
* warrantee of any kind, express or implied, is included with this
* software; use at your own risk, responsibility for damages (if any) to
* anyone resulting from the use of this software rests entirely with the
* user.
*
* Send bug reports, bug fixes, enhancements, requests, flames, etc., and
* I'll try to keep a version up to date. I can be reached as follows:
* Paul Vixie <paul@vix.com> uunet!decwrl!vixie!paul
*/
/*
* $FreeBSD$
*/
#ifndef __P
# ifdef __STDC__
# define __P(x) x
# else
# define __P(x) ()
# define const
# endif
#endif
#if defined(UNIXPC) || defined(unixpc)
# define UNIXPC 1
# define ATT 1
#endif
#if defined(hpux) || defined(_hpux) || defined(__hpux)
# define HPUX 1
# define seteuid(e) setresuid(-1,e,-1)
# define setreuid(r,e) setresuid(r,e,-1)
#endif
#if defined(_IBMR2)
# define AIX 1
#endif
#if defined(__convex__)
# define CONVEX 1
#endif
#if defined(sgi) || defined(_sgi) || defined(__sgi)
# define IRIX 1
/* IRIX 4 hdrs are broken: one cannot #include both <stdio.h>
* and <stdlib.h> because they disagree on system(), perror().
* Therefore we must zap the "const" keyword BEFORE including
* either of them.
*/
# define const
#endif
#if defined(_UNICOS)
# define UNICOS 1
#endif
#ifndef POSIX
# if (BSD >= 199103) || defined(__linux) || defined(ultrix) || defined(AIX) ||\
defined(HPUX) || defined(CONVEX) || defined(IRIX)
# define POSIX
# endif
#endif
#ifndef BSD
# if defined(ultrix)
# define BSD 198902
# endif
#endif
/*****************************************************************/
#if (!defined(BSD) || (BSD < 198902)) && !defined(__linux) && \
!defined(IRIX) && !defined(NeXT) && !defined(HPUX)
# define NEED_STRCASECMP
#endif
#if (!defined(BSD) || (BSD < 198911)) && !defined(__linux) &&\
!defined(IRIX) && !defined(UNICOS) && !defined(HPUX)
# define NEED_STRDUP
#endif
#if (!defined(BSD) || (BSD < 198911)) && !defined(POSIX) && !defined(NeXT)
# define NEED_STRERROR
#endif
#if defined(HPUX) || defined(AIX) || defined(UNIXPC)
# define NEED_FLOCK
#endif
#ifndef POSIX
# define NEED_SETSID
#endif
#if (defined(POSIX) && !defined(BSD)) && !defined(__linux)
# define NEED_GETDTABLESIZE
#endif
#ifdef POSIX
#include <unistd.h>
#ifdef _POSIX_SAVED_IDS
# define HAVE_SAVED_UIDS
#endif
#endif
#if !defined(ATT) && !defined(__linux) && !defined(IRIX) && !defined(UNICOS)
# define USE_SIGCHLD
#endif
#if !defined(AIX) && !defined(UNICOS)
# define SYS_TIME_H 1
#else
# define SYS_TIME_H 0
#endif
#if defined(BSD) && !defined(POSIX)
# define USE_UTIMES
#endif
#if defined(AIX) || defined(HPUX) || defined(IRIX)
# define NEED_SETENV
#endif
#if !defined(UNICOS) && !defined(UNIXPC)
# define HAS_FCHOWN
#endif
#if !defined(UNICOS) && !defined(UNIXPC)
# define HAS_FCHMOD
#endif

View File

@ -1,29 +1,29 @@
/* Copyright 1988,1990,1993,1994 by Paul Vixie
* All rights reserved
*/
/*
* Copyright (c) 1997 by Internet Software Consortium
*
* Distribute freely, except: don't remove my name from the source or
* documentation (don't take credit for my work), mark your changes (don't
* get me blamed for your possible bugs), don't alter or remove this
* notice. May be sold if buildable source is provided to buyer. No
* warrantee of any kind, express or implied, is included with this
* software; use at your own risk, responsibility for damages (if any) to
* anyone resulting from the use of this software rests entirely with the
* user.
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* Send bug reports, bug fixes, enhancements, requests, flames, etc., and
* I'll try to keep a version up to date. I can be reached as follows:
* Paul Vixie <paul@vix.com> uunet!decwrl!vixie!paul
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
* SOFTWARE.
*/
/* config.h - configurables for Vixie Cron
*
* $FreeBSD$
* $Id: config.h,v 1.2 1998/08/14 00:32:36 vixie Exp $
*/
#if !defined(_PATH_SENDMAIL)
# define _PATH_SENDMAIL "/usr/lib/sendmail"
#endif /*SENDMAIL*/
/*
* these are site-dependent
*/
@ -33,35 +33,35 @@
#endif
/*
* choose one of these MAILCMD commands. I use
* choose one of these mailer commands. some use
* /bin/mail for speed; it makes biff bark but doesn't
* do aliasing. /usr/lib/sendmail does aliasing but is
* do aliasing. sendmail does do aliasing but is
* a hog for short messages. aliasing is not needed
* if you make use of the MAILTO= feature in crontabs.
* (hint: MAILTO= was added for this reason).
*/
#define MAILCMD _PATH_SENDMAIL /*-*/
#define MAILARGS "%s -FCronDaemon -odi -oem -oi -t" /*-*/
#define MAILFMT "%s -FCronDaemon -odi -oem -oi -t" /*-*/
/* -Fx = set full-name of sender
* -odi = Option Deliverymode Interactive
* -oem = Option Errors Mailedtosender
* -oi = Option dot message terminator
* -t = read recipients from header of message
* -or0s = Option Readtimeout -- don't time out
* -t = Get recipient from headers
*/
#define MAILARG _PATH_SENDMAIL /*-*/
/* #define MAILCMD "/bin/mail" */ /*-*/
/* #define MAILARGS "%s -d %s" */ /*-*/
/* #define MAILFMT "%s -d %s" */ /*-*/
/* -d = undocumented but common flag: deliver locally?
*/
/* #define MAILARG "/bin/mail",mailto */
/* #define MAILCMD "/usr/mmdf/bin/submit" */ /*-*/
/* #define MAILARGS "%s -mlrxto %s" */ /*-*/
/* #define MAILFMT "%s -mlrxto %s" */ /*-*/
/* #define MAILARG "/usr/mmdf/bin/submit",mailto */ /*-*/
/* #define MAIL_DATE */ /*-*/
/* should we include an ersatz Date: header in
* generated mail? if you are using sendmail
* for MAILCMD, it is better to let sendmail
* as the mailer, it is better to let sendmail
* generate the Date: header.
*/
@ -69,7 +69,7 @@
* defined but neither exists, should crontab(1) be
* usable only by root?
*/
/* #define ALLOW_ONLY_ROOT */ /*-*/
/*#define ALLOW_ONLY_ROOT */ /*-*/
/* if you want to use syslog(3) instead of appending
* to CRONDIR/LOG_FILE (/var/cron/log, e.g.), define

View File

@ -1,21 +1,23 @@
.\"/* Copyright 1988,1990,1993 by Paul Vixie
.\"/* Copyright 1988,1990,1993,1996 by Paul Vixie
.\" * All rights reserved
.\" *
.\" * Distribute freely, except: don't remove my name from the source or
.\" * documentation (don't take credit for my work), mark your changes (don't
.\" * get me blamed for your possible bugs), don't alter or remove this
.\" * notice. May be sold if buildable source is provided to buyer. No
.\" * warrantee of any kind, express or implied, is included with this
.\" * software; use at your own risk, responsibility for damages (if any) to
.\" * anyone resulting from the use of this software rests entirely with the
.\" * user.
.\" *
.\" * Send bug reports, bug fixes, enhancements, requests, flames, etc., and
.\" * I'll try to keep a version up to date. I can be reached as follows:
.\" * Paul Vixie <paul@vix.com> uunet!decwrl!vixie!paul
.\" */
.\"
.\" $FreeBSD$
.\"Copyright (c) 1997 by Internet Software Consortium
.\"
.\"Permission to use, copy, modify, and distribute this software for any
.\"purpose with or without fee is hereby granted, provided that the above
.\"copyright notice and this permission notice appear in all copies.
.\"
.\"THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
.\"ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
.\"OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
.\"CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
.\"DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
.\"PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
.\"ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
.\"SOFTWARE.
.\"
.\" $Id: cron.8,v 1.2 1998/08/14 00:32:36 vixie Exp $
.\"
.Dd February 9, 2022
.Dt CRON 8

View File

@ -1,37 +1,33 @@
/* Copyright 1988,1990,1993,1994 by Paul Vixie
* All rights reserved
*/
/*
* Copyright (c) 1997 by Internet Software Consortium
*
* Distribute freely, except: don't remove my name from the source or
* documentation (don't take credit for my work), mark your changes (don't
* get me blamed for your possible bugs), don't alter or remove this
* notice. May be sold if buildable source is provided to buyer. No
* warrantee of any kind, express or implied, is included with this
* software; use at your own risk, responsibility for damages (if any) to
* anyone resulting from the use of this software rests entirely with the
* user.
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* Send bug reports, bug fixes, enhancements, requests, flames, etc., and
* I'll try to keep a version up to date. I can be reached as follows:
* Paul Vixie <paul@vix.com> uunet!decwrl!vixie!paul
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
* SOFTWARE.
*/
#if !defined(lint) && !defined(LINT)
static const char rcsid[] =
"$FreeBSD$";
"$Id: cron.c,v 1.3 1998/08/14 00:32:36 vixie Exp $";
#endif
#define MAIN_PROGRAM
#include "cron.h"
#include <sys/mman.h>
#include <sys/signal.h>
#if SYS_TIME_H
# include <sys/time.h>
#else
# include <time.h>
#endif
static void usage(void),
run_reboot_jobs(cron_db *),
@ -39,9 +35,7 @@ static void usage(void),
cron_sync(int),
cron_sleep(cron_db *, int),
cron_clean(cron_db *),
#ifdef USE_SIGCHLD
sigchld_handler(int),
#endif
sighup_handler(int),
parse_args(int c, char *v[]);
@ -58,7 +52,7 @@ static void
usage(void)
{
#if DEBUGGING
char **dflags;
const char **dflags;
#endif
fprintf(stderr, "usage: cron [-j jitter] [-J rootjitter] "
@ -66,7 +60,7 @@ usage(void)
#if DEBUGGING
fprintf(stderr, "\ndebugflags: ");
for(dflags = DebugFlagNames; *dflags; dflags++) {
for (dflags = DebugFlagNames; *dflags; dflags++) {
fprintf(stderr, "%s ", *dflags);
}
fprintf(stderr, "\n");
@ -78,11 +72,10 @@ usage(void)
static void
open_pidfile(void)
{
char pidfile[MAX_FNAME];
const char *pidfile = PIDDIR PIDFILE;
char buf[MAX_TEMPSTR];
int otherpid;
(void) snprintf(pidfile, sizeof(pidfile), PIDFILE, PIDDIR);
pfh = pidfile_open(pidfile, 0600, &otherpid);
if (pfh == NULL) {
if (errno == EEXIST) {
@ -114,20 +107,14 @@ main(int argc, char *argv[])
parse_args(argc, argv);
#ifdef USE_SIGCHLD
(void) signal(SIGCHLD, sigchld_handler);
#else
(void) signal(SIGCLD, SIG_IGN);
#endif
(void) signal(SIGHUP, sighup_handler);
open_pidfile();
set_cron_uid();
set_cron_cwd();
#if defined(POSIX)
setenv("PATH", _PATH_DEFPATH, 1);
#endif
putenv("PATH="_PATH_DEFPATH);
/* if there are no debug flags turned on, fork as a daemon should.
*/
@ -197,15 +184,14 @@ main(int argc, char *argv[])
}
}
static void
run_reboot_jobs(cron_db *db)
{
register user *u;
register entry *e;
user *u;
entry *e;
for (u = db->head; u != NULL; u = u->next) {
for (e = u->crontab; e != NULL; e = e->next) {
for (u = db->head; u != NULL; u = u->next) {
for (e = u->crontab; e != NULL; e = e->next) {
if (e->flags & WHEN_REBOOT) {
job_add(e, u);
}
@ -217,19 +203,21 @@ run_reboot_jobs(cron_db *db)
(void) job_runqueue();
}
static void
cron_tick(cron_db *db, int secres)
{
static struct tm lasttm;
static time_t diff = 0, /* time difference in seconds from the last offset change */
difflimit = 0; /* end point for the time zone correction */
struct tm otztm; /* time in the old time zone */
int otzsecond, otzminute, otzhour, otzdom, otzmonth, otzdow;
register struct tm *tm = localtime(&TargetTime);
register int second, minute, hour, dom, month, dow;
register user *u;
register entry *e;
static struct tm lasttm;
/* time difference in seconds from the last offset change */
static time_t diff = 0;
/* end point for the time zone correction */
static time_t difflimit = 0;
/* time in the old time zone */
struct tm otztm;
int otzsecond, otzminute, otzhour, otzdom, otzmonth, otzdow;
struct tm *tm = localtime(&TargetTime);
int second, minute, hour, dom, month, dow;
user *u;
entry *e;
/* make 0-based values out of these so we can use them as indices
*/
@ -252,8 +240,8 @@ cron_tick(cron_db *db, int secres)
if ( diff > 0 ) { /* ST->DST */
/* mark jobs for an earlier run */
difflimit = TargetTime + diff;
for (u = db->head; u != NULL; u = u->next) {
for (e = u->crontab; e != NULL; e = e->next) {
for (u = db->head; u != NULL; u = u->next) {
for (e = u->crontab; e != NULL; e = e->next) {
e->flags &= ~NOT_UNTIL;
if ( e->lastrun >= TargetTime )
e->lastrun = 0;
@ -267,8 +255,8 @@ cron_tick(cron_db *db, int secres)
} else { /* diff < 0 : DST->ST */
/* mark jobs for skipping */
difflimit = TargetTime - diff;
for (u = db->head; u != NULL; u = u->next) {
for (e = u->crontab; e != NULL; e = e->next) {
for (u = db->head; u != NULL; u = u->next) {
for (e = u->crontab; e != NULL; e = e->next) {
e->flags |= NOT_UNTIL;
e->flags &= ~RUN_AT;
}
@ -282,8 +270,8 @@ cron_tick(cron_db *db, int secres)
/* disable the TZ switch checks */
diff = 0;
difflimit = 0;
for (u = db->head; u != NULL; u = u->next) {
for (e = u->crontab; e != NULL; e = e->next) {
for (u = db->head; u != NULL; u = u->next) {
for (e = u->crontab; e != NULL; e = e->next) {
e->flags &= ~(RUN_AT|NOT_UNTIL);
}
}
@ -309,8 +297,8 @@ cron_tick(cron_db *db, int secres)
* is why we keep 'e->dow_star' and 'e->dom_star'. yes, it's bizarre.
* like many bizarre things, it's the standard.
*/
for (u = db->head; u != NULL; u = u->next) {
for (e = u->crontab; e != NULL; e = e->next) {
for (u = db->head; u != NULL; u = u->next) {
for (e = u->crontab; e != NULL; e = e->next) {
Debug(DSCH|DEXT, ("user [%s:%d:%d:...] cmd=\"%s\"\n",
env_get("LOGNAME", e->envp),
e->uid, e->gid, e->cmd))
@ -323,11 +311,11 @@ cron_tick(cron_db *db, int secres)
}
if ( diff != 0 && (e->flags & (RUN_AT|NOT_UNTIL)) ) {
if (bit_test(e->second, otzsecond)
&& bit_test(e->minute, otzminute)
&& bit_test(e->hour, otzhour)
&& bit_test(e->month, otzmonth)
&& ( ((e->flags & DOM_STAR) || (e->flags & DOW_STAR))
if (bit_test(e->second, otzsecond) &&
bit_test(e->minute, otzminute) &&
bit_test(e->hour, otzhour) &&
bit_test(e->month, otzmonth) &&
( ((e->flags & DOM_STAR) || (e->flags & DOW_STAR))
? (bit_test(e->dow,otzdow) && bit_test(e->dom,otzdom))
: (bit_test(e->dow,otzdow) || bit_test(e->dom,otzdom))
)
@ -343,11 +331,11 @@ cron_tick(cron_db *db, int secres)
continue;
}
if (bit_test(e->second, second)
&& bit_test(e->minute, minute)
&& bit_test(e->hour, hour)
&& bit_test(e->month, month)
&& ( ((e->flags & DOM_STAR) || (e->flags & DOW_STAR))
if (bit_test(e->second, second) &&
bit_test(e->minute, minute) &&
bit_test(e->hour, hour) &&
bit_test(e->month, month) &&
( ((e->flags & DOM_STAR) || (e->flags & DOW_STAR))
? (bit_test(e->dow,dow) && bit_test(e->dom,dom))
: (bit_test(e->dow,dow) || bit_test(e->dom,dom))
)
@ -363,7 +351,6 @@ cron_tick(cron_db *db, int secres)
lasttm = *tm;
}
/* the task here is to figure out how long it's going to be until :00 of the
* following minute and initialize TargetTime to this value. TargetTime
* will subsequently slide 60 seconds at a time, with correction applied
@ -375,7 +362,7 @@ cron_tick(cron_db *db, int secres)
*/
static void
cron_sync(int secres) {
struct tm *tm;
struct tm *tm;
TargetTime = time((time_t*)0);
if (secres != 0) {
@ -474,19 +461,14 @@ cron_clean(cron_db *db)
}
}
#ifdef USE_SIGCHLD
static void
sigchld_handler(int x)
{
WAIT_T waiter;
PID_T pid;
WAIT_T waiter;
PID_T pid;
for (;;) {
#ifdef POSIX
pid = waitpid(-1, &waiter, WNOHANG);
#else
pid = wait3(&waiter, WNOHANG, (struct rusage *)0);
#endif
switch (pid) {
case -1:
Debug(DPROC,
@ -504,8 +486,6 @@ sigchld_handler(int x)
}
}
}
#endif /*USE_SIGCHLD*/
static void
sighup_handler(int x)
@ -513,12 +493,11 @@ sighup_handler(int x)
log_close();
}
static void
parse_args(int argc, char *argv[])
{
int argch;
char *endp;
int argch;
char *endp;
while ((argch = getopt(argc, argv, "j:J:m:nosx:")) != -1) {
switch (argch) {

View File

@ -1,318 +1,37 @@
/* Copyright 1988,1990,1993,1994 by Paul Vixie
* All rights reserved
*/
/*
* Copyright (c) 1997 by Internet Software Consortium
*
* Distribute freely, except: don't remove my name from the source or
* documentation (don't take credit for my work), mark your changes (don't
* get me blamed for your possible bugs), don't alter or remove this
* notice. May be sold if buildable source is provided to buyer. No
* warrantee of any kind, express or implied, is included with this
* software; use at your own risk, responsibility for damages (if any) to
* anyone resulting from the use of this software rests entirely with the
* user.
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* Send bug reports, bug fixes, enhancements, requests, flames, etc., and
* I'll try to keep a version up to date. I can be reached as follows:
* Paul Vixie <paul@vix.com> uunet!decwrl!vixie!paul
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
* SOFTWARE.
*/
/* cron.h - header for vixie's cron
*
* $FreeBSD$
* $Id: cron.h,v 1.3 1998/08/14 00:32:37 vixie Exp $
*
* vix 14nov88 [rest of log is in RCS]
* vix 14jan87 [0 or 7 can be sunday; thanks, mwm@berkeley]
* vix 30dec86 [written]
*/
/* reorder these #include's at your peril */
#include <sys/types.h>
#include <sys/param.h>
#include "compat.h"
#include <bitstring.h>
#include <ctype.h>
#include <err.h>
#include <errno.h>
#include <libutil.h>
#include <pwd.h>
#include <signal.h>
#include <stdio.h>
#include <time.h>
#include <sys/wait.h>
#include "pathnames.h"
#include "config.h"
#include "externs.h"
/* these are really immutable, and are
* defined for symbolic convenience only
* TRUE, FALSE, and ERR must be distinct
* ERR must be < OK.
*/
#define TRUE 1
#define FALSE 0
/* system calls return this on success */
#define OK 0
/* or this on error */
#define ERR (-1)
/* turn this on to get '-x' code */
#ifndef DEBUGGING
#define DEBUGGING FALSE
#endif
#define READ_PIPE 0 /* which end of a pipe pair do you read? */
#define WRITE_PIPE 1 /* or write to? */
#define STDIN 0 /* what is stdin's file descriptor? */
#define STDOUT 1 /* stdout's? */
#define STDERR 2 /* stderr's? */
#define ERROR_EXIT 1 /* exit() with this will scare the shell */
#define OK_EXIT 0 /* exit() with this is considered 'normal' */
#define MAX_FNAME 100 /* max length of internally generated fn */
#define MAX_COMMAND 1000 /* max length of internally generated cmd */
#define MAX_ENVSTR 1000 /* max length of envvar=value\0 strings */
#define MAX_TEMPSTR 100 /* obvious */
#define ROOT_UID 0 /* don't change this, it really must be root */
#define ROOT_USER "root" /* ditto */
#define SYS_NAME "*system*" /* magic owner name for system crontab */
/* NOTE: these correspond to DebugFlagNames,
* defined below.
*/
#define DEXT 0x0001 /* extend flag for other debug masks */
#define DSCH 0x0002 /* scheduling debug mask */
#define DPROC 0x0004 /* process control debug mask */
#define DPARS 0x0008 /* parsing debug mask */
#define DLOAD 0x0010 /* database loading debug mask */
#define DMISC 0x0020 /* misc debug mask */
#define DTEST 0x0040 /* test mode: don't execute any commands */
#define DBIT 0x0080 /* bit twiddling shown (long) */
#define CRON_TAB(u) "%s/%s", SPOOL_DIR, u
#define REG register
#define PPC_NULL ((char **)NULL)
#ifndef MAXHOSTNAMELEN
#define MAXHOSTNAMELEN 256
#endif
#define Skip_Blanks(c, f) \
while (c == '\t' || c == ' ') \
c = get_char(f);
#define Skip_Nonblanks(c, f) \
while (c!='\t' && c!=' ' && c!='\n' && c != EOF) \
c = get_char(f);
#define Skip_Line(c, f) \
do {c = get_char(f);} while (c != '\n' && c != EOF);
#if DEBUGGING
# define Debug(mask, message) \
if ( (DebugFlags & (mask) ) == (mask) ) \
printf message;
#else /* !DEBUGGING */
# define Debug(mask, message) \
;
#endif /* DEBUGGING */
#define MkLower(ch) (isupper(ch) ? tolower(ch) : ch)
#define MkUpper(ch) (islower(ch) ? toupper(ch) : ch)
#define Set_LineNum(ln) {Debug(DPARS|DEXT,("linenum=%d\n",ln)); \
LineNumber = ln; \
}
#define FIRST_SECOND 0
#define LAST_SECOND 59
#define SECOND_COUNT (LAST_SECOND - FIRST_SECOND + 1)
#define FIRST_MINUTE 0
#define LAST_MINUTE 59
#define MINUTE_COUNT (LAST_MINUTE - FIRST_MINUTE + 1)
#define FIRST_HOUR 0
#define LAST_HOUR 23
#define HOUR_COUNT (LAST_HOUR - FIRST_HOUR + 1)
#define FIRST_DOM 1
#define LAST_DOM 31
#define DOM_COUNT (LAST_DOM - FIRST_DOM + 1)
#define FIRST_MONTH 1
#define LAST_MONTH 12
#define MONTH_COUNT (LAST_MONTH - FIRST_MONTH + 1)
/* note on DOW: 0 and 7 are both Sunday, for compatibility reasons. */
#define FIRST_DOW 0
#define LAST_DOW 7
#define DOW_COUNT (LAST_DOW - FIRST_DOW + 1)
#ifdef LOGIN_CAP
/* see init.c */
#define RESOURCE_RC "daemon"
#endif
/* each user's crontab will be held as a list of
* the following structure.
*
* These are the cron commands.
*/
typedef struct _entry {
struct _entry *next;
uid_t uid;
gid_t gid;
#ifdef LOGIN_CAP
char *class;
#endif
char **envp;
char *cmd;
union {
struct {
bitstr_t bit_decl(second, SECOND_COUNT);
bitstr_t bit_decl(minute, MINUTE_COUNT);
bitstr_t bit_decl(hour, HOUR_COUNT);
bitstr_t bit_decl(dom, DOM_COUNT);
bitstr_t bit_decl(month, MONTH_COUNT);
bitstr_t bit_decl(dow, DOW_COUNT);
};
struct {
time_t lastexit;
time_t interval;
pid_t child;
};
};
int flags;
#define DOM_STAR 0x01
#define DOW_STAR 0x02
#define WHEN_REBOOT 0x04
#define RUN_AT 0x08
#define NOT_UNTIL 0x10
#define SEC_RES 0x20
#define INTERVAL 0x40
#define DONT_LOG 0x80
#define MAIL_WHEN_ERR 0x100
time_t lastrun;
} entry;
/* the crontab database will be a list of the
* following structure, one element per user
* plus one for the system.
*
* These are the crontabs.
*/
typedef struct _user {
struct _user *next, *prev; /* links */
char *name;
time_t mtime; /* last modtime of crontab */
entry *crontab; /* this person's crontab */
} user;
typedef struct _cron_db {
user *head, *tail; /* links */
time_t mtime; /* last modtime on spooldir */
} cron_db;
void set_cron_uid(void),
set_cron_cwd(void),
load_database(cron_db *),
open_logfile(void),
sigpipe_func(void),
job_add(entry *, user *),
do_command(entry *, user *),
link_user(cron_db *, user *),
unlink_user(cron_db *, user *),
free_user(user *),
env_free(char **),
unget_char(int, FILE *),
free_entry(entry *),
skip_comments(FILE *),
log_it(char *, int, char *, const char *),
log_close(void);
int job_runqueue(void),
set_debug_flags(char *),
get_char(FILE *),
get_string(char *, int, FILE *, char *),
swap_uids(void),
swap_uids_back(void),
load_env(char *, FILE *),
cron_pclose(FILE *),
strcmp_until(char *, char *, int),
allowed(char *),
strdtb(char *);
char *env_get(char *, char **),
*arpadate(time_t *),
*mkprints(unsigned char *, unsigned int),
*first_word(char *, char *),
**env_init(void),
**env_copy(char **),
**env_set(char **, char *);
user *load_user(int, struct passwd *, char *),
*find_user(cron_db *, char *);
entry *load_entry(FILE *, void (*)(char *),
struct passwd *, char **);
FILE *cron_popen(char *, char *, entry *, PID_T *);
/* in the C tradition, we only create
* variables for the main program, just
* extern them elsewhere.
*/
#ifdef MAIN_PROGRAM
# if !defined(LINT) && !defined(lint)
char *copyright[] = {
"@(#) Copyright 1988,1989,1990,1993,1994 by Paul Vixie",
"@(#) All rights reserved"
};
# endif
char *MonthNames[] = {
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
NULL
};
char *DowNames[] = {
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun",
NULL
};
char *ProgramName,
*defmailto;
int LineNumber;
unsigned Jitter,
RootJitter;
time_t TargetTime;
# if DEBUGGING
int DebugFlags;
char *DebugFlagNames[] = { /* sync with #defines */
"ext", "sch", "proc", "pars", "load", "misc", "test", "bit",
NULL /* NULL must be last element */
};
# endif /* DEBUGGING */
#else /*MAIN_PROGRAM*/
extern char *copyright[],
*MonthNames[],
*DowNames[],
*ProgramName,
*defmailto;
extern int LineNumber;
extern unsigned Jitter,
RootJitter;
extern time_t TargetTime;
extern struct pidfh *pfh;
# if DEBUGGING
extern int DebugFlags;
extern char *DebugFlagNames[];
# endif /* DEBUGGING */
#endif /*MAIN_PROGRAM*/
#include "pathnames.h"
#include "macros.h"
#include "structs.h"
#include "funcs.h"
#include "globals.h"

View File

@ -1,53 +1,49 @@
/* Copyright 1988,1990,1993,1994 by Paul Vixie
* All rights reserved
*/
/*
* Copyright (c) 1997 by Internet Software Consortium
*
* Distribute freely, except: don't remove my name from the source or
* documentation (don't take credit for my work), mark your changes (don't
* get me blamed for your possible bugs), don't alter or remove this
* notice. May be sold if buildable source is provided to buyer. No
* warrantee of any kind, express or implied, is included with this
* software; use at your own risk, responsibility for damages (if any) to
* anyone resulting from the use of this software rests entirely with the
* user.
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* Send bug reports, bug fixes, enhancements, requests, flames, etc., and
* I'll try to keep a version up to date. I can be reached as follows:
* Paul Vixie <paul@vix.com> uunet!decwrl!vixie!paul
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
* SOFTWARE.
*/
#if !defined(lint) && !defined(LINT)
static const char rcsid[] =
"$FreeBSD$";
"$Id: database.c,v 1.3 1998/08/14 00:32:38 vixie Exp $";
#endif
/* vix 26jan87 [RCS has the log]
*/
#include "cron.h"
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/file.h>
#define TMAX(a,b) ((a)>(b)?(a):(b))
static void process_crontab(char *, char *, char *,
struct stat *,
cron_db *, cron_db *);
static void process_crontab(const char *, const char *,
const char *, struct stat *,
cron_db *, cron_db *);
void
load_database(cron_db *old_db)
{
DIR *dir;
struct stat statbuf;
struct stat syscron_stat, st;
time_t maxmtime;
DIR_T *dp;
cron_db new_db;
user *u, *nu;
struct stat statbuf, syscron_stat, st;
cron_db new_db;
DIR_T *dp;
DIR *dir;
user *u, *nu;
time_t maxmtime;
struct {
const char *name;
struct stat st;
@ -156,8 +152,7 @@ load_database(cron_db *old_db)
}
while (NULL != (dp = readdir(dir))) {
char fname[MAXNAMLEN+1],
tabname[MAXNAMLEN+1];
char fname[MAXNAMLEN+1], tabname[MAXNAMLEN+1];
/* avoid file names beginning with ".". this is good
* because we would otherwise waste two guaranteed calls
@ -169,7 +164,10 @@ load_database(cron_db *old_db)
(void) strncpy(fname, dp->d_name, sizeof(fname));
fname[sizeof(fname)-1] = '\0';
(void) snprintf(tabname, sizeof tabname, CRON_TAB(fname));
if (snprintf(tabname, sizeof tabname, CRON_TAB(fname))
>= sizeof(tabname))
continue; /* XXX log? */
process_crontab(fname, fname, tabname,
&statbuf, &new_db, old_db);
@ -198,7 +196,6 @@ load_database(cron_db *old_db)
Debug(DLOAD, ("load_database is done\n"))
}
void
link_user(cron_db *db, user *u)
{
@ -211,7 +208,6 @@ link_user(cron_db *db, user *u)
db->tail = u;
}
void
unlink_user(cron_db *db, user *u)
{
@ -226,30 +222,28 @@ unlink_user(cron_db *db, user *u)
u->next->prev = u->prev;
}
user *
find_user(cron_db *db, char *name)
find_user(cron_db *db, const char *name)
{
user *u;
user *u;
for (u = db->head; u != NULL; u = u->next)
if (!strcmp(u->name, name))
if (strcmp(u->name, name) == 0)
break;
return u;
return (u);
}
static void
process_crontab(char *uname, char *fname, char *tabname, struct stat *statbuf,
cron_db *new_db, cron_db *old_db)
process_crontab(const char *uname, const char *fname, const char *tabname,
struct stat *statbuf, cron_db *new_db, cron_db *old_db)
{
struct passwd *pw = NULL;
int crontab_fd = OK - 1;
user *u;
entry *e;
time_t now;
struct passwd *pw = NULL;
int crontab_fd = OK - 1;
user *u;
entry *e;
time_t now;
if (strcmp(fname, SYS_NAME) && !(pw = getpwnam(uname))) {
if (strcmp(fname, SYS_NAME) != 0 && !(pw = getpwnam(uname))) {
/* file doesn't have a user in passwd file.
*/
log_it(fname, getpid(), "ORPHAN", "no passwd entry");
@ -314,7 +308,7 @@ process_crontab(char *uname, char *fname, char *tabname, struct stat *statbuf,
link_user(new_db, u);
}
next_crontab:
next_crontab:
if (crontab_fd >= OK) {
Debug(DLOAD, (" [done]\n"))
close(crontab_fd);

View File

@ -1,34 +1,30 @@
/* Copyright 1988,1990,1993,1994 by Paul Vixie
* All rights reserved
*/
/*
* Copyright (c) 1997 by Internet Software Consortium
*
* Distribute freely, except: don't remove my name from the source or
* documentation (don't take credit for my work), mark your changes (don't
* get me blamed for your possible bugs), don't alter or remove this
* notice. May be sold if buildable source is provided to buyer. No
* warrantee of any kind, express or implied, is included with this
* software; use at your own risk, responsibility for damages (if any) to
* anyone resulting from the use of this software rests entirely with the
* user.
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* Send bug reports, bug fixes, enhancements, requests, flames, etc., and
* I'll try to keep a version up to date. I can be reached as follows:
* Paul Vixie <paul@vix.com> uunet!decwrl!vixie!paul
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
* SOFTWARE.
*/
#if !defined(lint) && !defined(LINT)
static const char rcsid[] =
"$FreeBSD$";
"$Id: do_command.c,v 1.3 1998/08/14 00:32:39 vixie Exp $";
#endif
#include "cron.h"
#include <sys/signal.h>
#if defined(sequent)
# include <sys/universe.h>
#endif
#if defined(SYSLOG)
# include <syslog.h>
#endif
#if defined(LOGIN_CAP)
# include <login_cap.h>
#endif
@ -37,9 +33,7 @@ static const char rcsid[] =
# include <security/openpam.h>
#endif
static void child_process(entry *, user *);
static WAIT_T wait_on_child(PID_T, const char *);
extern char *environ;
@ -58,7 +52,7 @@ do_command(entry *e, user *u)
*/
switch ((pid = fork())) {
case -1:
log_it("CRON",getpid(),"error","can't fork");
log_it("CRON", getpid(), "error", "can't fork");
if (e->flags & INTERVAL)
e->lastexit = time(NULL);
break;
@ -86,16 +80,16 @@ do_command(entry *e, user *u)
static void
child_process(entry *e, user *u)
{
int stdin_pipe[2], stdout_pipe[2];
register char *input_data;
char *usernm, *mailto, *mailfrom;
PID_T jobpid, stdinjob, mailpid;
register FILE *mail;
register int bytes = 1;
int status = 0;
const char *homedir = NULL;
int stdin_pipe[2], stdout_pipe[2];
char *input_data;
const char *usernm, *mailto, *mailfrom;
PID_T jobpid, stdinjob, mailpid;
FILE *mail;
int bytes = 1;
int status = 0;
const char *homedir = NULL;
# if defined(LOGIN_CAP)
struct passwd *pwd;
struct passwd *pwd;
login_cap_t *lc;
# endif
@ -154,20 +148,12 @@ child_process(entry *e, user *u)
}
#endif
#ifdef USE_SIGCHLD
/* our parent is watching for our death by catching SIGCHLD. we
* do not care to watch for our children's deaths this way -- we
* use wait() explicitly. so we have to disable the signal (which
* was inherited from the parent).
*/
(void) signal(SIGCHLD, SIG_DFL);
#else
/* on system-V systems, we are ignoring SIGCLD. we have to stop
* ignoring it now or the wait() in cron_pclose() won't work.
* because of this, we have to wait() for our children here, as well.
*/
(void) signal(SIGCLD, SIG_DFL);
#endif /*BSD*/
/* create some pipes to talk to our future child
*/
@ -187,14 +173,15 @@ child_process(entry *e, user *u)
* If there are escaped %'s, remove the escape character.
*/
/*local*/{
register int escaped = FALSE;
register int ch;
register char *p;
int escaped = FALSE;
int ch;
char *p;
for (input_data = p = e->cmd; (ch = *input_data);
for (input_data = p = e->cmd;
(ch = *input_data) != '\0';
input_data++, p++) {
if (p != input_data)
*p = ch;
*p = ch;
if (escaped) {
if (ch == '%' || ch == '\\')
*--p = ch;
@ -217,7 +204,7 @@ child_process(entry *e, user *u)
*/
switch (jobpid = fork()) {
case -1:
log_it("CRON",getpid(),"error","can't fork");
log_it("CRON", getpid(), "error", "can't fork");
exit(ERROR_EXIT);
/*NOTREACHED*/
case 0:
@ -312,13 +299,11 @@ child_process(entry *e, user *u)
"error", "setgid failed");
_exit(ERROR_EXIT);
}
# if defined(BSD)
if (initgroups(usernm, e->gid) != 0) {
log_it(usernm, getpid(),
"error", "initgroups failed");
_exit(ERROR_EXIT);
}
# endif
if (setlogin(usernm) != 0) {
log_it(usernm, getpid(),
"error", "setlogin failed");
@ -437,10 +422,10 @@ child_process(entry *e, user *u)
*/
if (*input_data && (stdinjob = fork()) == 0) {
register FILE *out = fdopen(stdin_pipe[WRITE_PIPE], "w");
register int need_newline = FALSE;
register int escaped = FALSE;
register int ch;
FILE *out = fdopen(stdin_pipe[WRITE_PIPE], "w");
int need_newline = FALSE;
int escaped = FALSE;
int ch;
if (out == NULL) {
warn("fdopen failed in child2");
@ -459,7 +444,7 @@ child_process(entry *e, user *u)
* % -> \n
* \x -> \x for all x != %
*/
while ((ch = *input_data++)) {
while ((ch = *input_data++) != '\0') {
if (escaped) {
if (ch != '%')
putc('\\', out);
@ -502,8 +487,8 @@ child_process(entry *e, user *u)
Debug(DPROC, ("[%d] child reading output from grandchild\n", getpid()))
/*local*/{
register FILE *in = fdopen(stdout_pipe[READ_PIPE], "r");
register int ch;
FILE *in = fdopen(stdout_pipe[READ_PIPE], "r");
int ch;
if (in == NULL) {
warn("fdopen failed in child");
@ -539,17 +524,20 @@ child_process(entry *e, user *u)
*/
if (mailto) {
register char **env;
auto char mailcmd[MAX_COMMAND];
auto char hostname[MAXHOSTNAMELEN];
char **env;
char mailcmd[MAX_COMMAND];
char hostname[MAXHOSTNAMELEN];
if (gethostname(hostname, MAXHOSTNAMELEN) == -1)
hostname[0] = '\0';
hostname[sizeof(hostname) - 1] = '\0';
(void) snprintf(mailcmd, sizeof(mailcmd),
MAILARGS, MAILCMD);
if (snprintf(mailcmd, sizeof(mailcmd), MAILFMT,
MAILARG) >= sizeof(mailcmd)) {
warnx("mail command too long");
(void) _exit(ERROR_EXIT);
}
if (!(mail = cron_popen(mailcmd, "w", e, &mailpid))) {
warn("%s", MAILCMD);
warn("%s", mailcmd);
(void) _exit(ERROR_EXIT);
}
if (mailfrom == NULL || *mailfrom == '\0')
@ -562,10 +550,10 @@ child_process(entry *e, user *u)
fprintf(mail, "Subject: Cron <%s@%s> %s\n",
usernm, first_word(hostname, "."),
e->cmd);
# if defined(MAIL_DATE)
#ifdef MAIL_DATE
fprintf(mail, "Date: %s\n",
arpadate(&TargetTime));
# endif /* MAIL_DATE */
#endif /*MAIL_DATE*/
for (env = e->envp; *env; env++)
fprintf(mail, "X-Cron-Env: <%s>\n",
*env);
@ -598,7 +586,7 @@ child_process(entry *e, user *u)
/* wait for children to die.
*/
if (jobpid > 0) {
WAIT_T waiter;
WAIT_T waiter;
waiter = wait_on_child(jobpid, "grandchild command job");
@ -615,7 +603,6 @@ child_process(entry *e, user *u)
mail = NULL;
}
/* only close pipe if we opened it -- i.e., we're
* mailing...
*/
@ -652,9 +639,10 @@ child_process(entry *e, user *u)
}
static WAIT_T
wait_on_child(PID_T childpid, const char *name) {
WAIT_T waiter;
PID_T pid;
wait_on_child(PID_T childpid, const char *name)
{
WAIT_T waiter;
PID_T pid;
Debug(DPROC, ("[%d] waiting for %s (%d) to finish\n",
getpid(), name, childpid))

View File

@ -1,69 +1,96 @@
/* $FreeBSD$ */
/* Copyright 1993,1994 by Paul Vixie
* All rights reserved
*
* Distribute freely, except: don't remove my name from the source or
* documentation (don't take credit for my work), mark your changes (don't
* get me blamed for your possible bugs), don't alter or remove this
* notice. May be sold if buildable source is provided to buyer. No
* warrantee of any kind, express or implied, is included with this
* software; use at your own risk, responsibility for damages (if any) to
* anyone resulting from the use of this software rests entirely with the
* user.
*
* Send bug reports, bug fixes, enhancements, requests, flames, etc., and
* I'll try to keep a version up to date. I can be reached as follows:
* Paul Vixie <paul@vix.com> uunet!decwrl!vixie!paul
*/
#if defined(POSIX) || defined(ATT)
# include <stdlib.h>
# include <unistd.h>
# include <string.h>
# include <dirent.h>
# define DIR_T struct dirent
# define WAIT_T int
# define WAIT_IS_INT 1
/*
* Copyright (c) 1997 by Internet Software Consortium
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
* SOFTWARE.
*/
/* reorder these #include's at your peril */
#include <sys/param.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/wait.h>
#include <sys/fcntl.h>
#include <sys/file.h>
#include <sys/stat.h>
#include <bitstring.h>
#include <ctype.h>
#include <dirent.h>
#include <err.h>
#include <errno.h>
#include <fcntl.h>
#include <grp.h>
#include <libutil.h>
#include <locale.h>
#include <pwd.h>
#include <signal.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <utime.h>
#if defined(SYSLOG)
# include <syslog.h>
#endif
#if (defined(BSD)) && (BSD >= 199103) || defined(__linux) || defined(AIX)
# include <paths.h>
#endif /*BSD*/
#if !defined(_PATH_SENDMAIL)
# define _PATH_SENDMAIL "/usr/lib/sendmail"
#endif /*SENDMAIL*/
#if defined(__bsdi__) && (_BSDI_VERSION > 199510)
#include <login_cap.h>
#endif /* __bsdi__ */
#define DIR_T struct dirent
#define WAIT_T int
#define SIG_T sig_t
#define TIME_T time_t
#define PID_T pid_t
#ifndef TZNAME_ALREADY_DEFINED
extern char *tzname[2];
# define TZONE(tm) tzname[(tm).tm_isdst]
#endif
#define TZONE(tm) tzname[(tm).tm_isdst]
#if (BSD >= 198606)
# define HAVE_FCHOWN
# define HAVE_FCHMOD
#endif
#if defined(UNIXPC)
# undef WAIT_T
# undef WAIT_IS_INT
# define WAIT_T union wait
#if (BSD >= 199103)
# define HAVE_SAVED_UIDS
#endif
#if defined(POSIX)
# define SIG_T sig_t
# define TIME_T time_t
# define PID_T pid_t
#endif
#define MY_UID(pw) getuid()
#define MY_GID(pw) getgid()
#if defined(ATT)
# define SIG_T void
# define TIME_T long
# define PID_T int
#endif
#if !defined(POSIX) && !defined(ATT)
/* classic BSD */
extern time_t time();
extern unsigned sleep();
extern struct tm *localtime();
extern struct passwd *getpwnam();
extern int errno;
extern void perror(), exit(), free();
extern char *getenv(), *strcpy(), *strchr(), *strtok();
extern void *malloc(), *realloc();
# define SIG_T void
# define TIME_T long
# define PID_T int
# define WAIT_T union wait
# define DIR_T struct direct
# include <sys/dir.h>
# define TZONE(tm) (tm).tm_zone
#if !defined(AIX) && !defined(UNICOS)
# define SYS_TIME_H 1
#else
# define SYS_TIME_H 0
#endif
/* getopt() isn't part of POSIX. some systems define it in <stdlib.h> anyway.
@ -72,7 +99,7 @@ extern void *malloc(), *realloc();
* in ways that we cannot predict or comprehend, yet do not define the adjunct
* external variables needed for the interface.
*/
#if (!defined(BSD) || (BSD < 198911)) && !defined(ATT) && !defined(UNICOS)
#if (!defined(BSD) || (BSD < 198911))
int getopt(int, char * const *, const char *);
#endif
@ -81,63 +108,21 @@ extern char *optarg;
extern int optind, opterr, optopt;
#endif
#if WAIT_IS_INT
# ifndef WEXITSTATUS
# define WEXITSTATUS(x) (((x) >> 8) & 0xff)
# endif
# ifndef WTERMSIG
# define WTERMSIG(x) ((x) & 0x7f)
# endif
# ifndef WCOREDUMP
# define WCOREDUMP(x) ((x) & 0x80)
# endif
#else /*WAIT_IS_INT*/
# ifndef WEXITSTATUS
# define WEXITSTATUS(x) ((x).w_retcode)
# endif
# ifndef WTERMSIG
# define WTERMSIG(x) ((x).w_termsig)
# endif
# ifndef WCOREDUMP
# define WCOREDUMP(x) ((x).w_coredump)
# endif
#endif /*WAIT_IS_INT*/
#ifndef WIFSIGNALED
#define WIFSIGNALED(x) (WTERMSIG(x) != 0)
#endif
#ifndef WIFEXITED
#define WIFEXITED(x) (WTERMSIG(x) == 0)
#endif
#ifdef NEED_STRCASECMP
extern int strcasecmp(char *, char *);
#endif
#ifdef NEED_STRDUP
extern char *strdup(char *);
#endif
#ifdef NEED_STRERROR
extern char *strerror(int);
#endif
#ifdef NEED_FLOCK
/* digital unix needs this but does not give us a way to identify it.
*/
extern int flock(int, int);
/* not all systems who provice flock() provide these definitions.
*/
#ifndef LOCK_SH
# define LOCK_SH 1
#endif
#ifndef LOCK_EX
# define LOCK_EX 2
#endif
#ifndef LOCK_NB
# define LOCK_NB 4
#endif
#ifndef LOCK_UN
# define LOCK_UN 8
#endif
#ifdef NEED_SETSID
extern int setsid(void);
#endif
#ifdef NEED_GETDTABLESIZE
extern int getdtablesize(void);
#endif
#ifdef NEED_SETENV
extern int setenv(char *, char *, int);
#endif

View File

@ -0,0 +1,70 @@
/*
* $Id: funcs.h,v 1.1 1998/08/14 00:31:24 vixie Exp $
*/
/*
* Copyright (c) 1997 by Internet Software Consortium
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
* SOFTWARE.
*/
/* Notes:
* This file has to be included by cron.h after data structure defs.
* We should reorg this into sections by module.
*/
void set_cron_uid(void),
set_cron_cwd(void),
load_database(cron_db *),
open_logfile(void),
sigpipe_func(void),
job_add(entry *, user *),
do_command(entry *, user *),
link_user(cron_db *, user *),
unlink_user(cron_db *, user *),
free_user(user *),
env_free(char **),
unget_char(int, FILE *),
free_entry(entry *),
skip_comments(FILE *),
log_it(const char *, int, const char *, const char *),
log_close(void);
int job_runqueue(void),
set_debug_flags(char *),
get_char(FILE *),
get_string(char *, int, FILE *, char *),
swap_uids(void),
swap_uids_back(void),
load_env(char *, FILE *),
cron_pclose(FILE *),
strcmp_until(const char *, const char *, int),
allowed(char *),
strdtb(char *);
char *env_get(char *, char **),
*arpadate(time_t *),
*mkprints(unsigned char *, unsigned int),
*first_word(char *, char *),
**env_init(void),
**env_copy(char **),
**env_set(char **, char *);
user *load_user(int, struct passwd *, const char *),
*find_user(cron_db *, const char *);
entry *load_entry(FILE *, void (*)(const char *),
struct passwd *, char **);
FILE *cron_popen(char *, char *, entry *, PID_T *);

View File

@ -0,0 +1,78 @@
/*
* $Id: globals.h,v 1.1 1998/08/14 00:31:23 vixie Exp $
*/
/*
* Copyright (c) 1997 by Internet Software Consortium
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
* SOFTWARE.
*/
#ifdef MAIN_PROGRAM
# define XTRN
# define INIT(x) = x
#else
# define XTRN extern
# define INIT(x)
#endif
XTRN const char *copyright[]
#ifdef MAIN_PROGRAM
= {
"@(#) Copyright 1988,1989,1990,1993,1994 by Paul Vixie",
"@(#) Copyright 1997 by Internet Software Consortium",
"@(#) All rights reserved",
NULL
}
#endif
;
XTRN const char *MonthNames[]
#ifdef MAIN_PROGRAM
= {
"Jan", "Feb", "Mar", "Apr", "May", "Jun",\
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec",\
NULL
}
#endif
;
XTRN const char *DowNames[]
#ifdef MAIN_PROGRAM
= {
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun",\
NULL
}
#endif
;
XTRN const char *ProgramName INIT("amnesia");
XTRN const char *defmailto;
XTRN int LineNumber INIT(0);
XTRN unsigned Jitter;
XTRN unsigned RootJitter;
XTRN time_t TargetTime INIT(0);
XTRN struct pidfh *pfh;
#if DEBUGGING
XTRN int DebugFlags INIT(0);
XTRN const char *DebugFlagNames[]
#ifdef MAIN_PROGRAM
= {
"ext", "sch", "proc", "pars", "load", "misc", "test", "bit",\
NULL
}
#endif
;
#endif /* DEBUGGING */

View File

@ -1,23 +1,26 @@
/* Copyright 1988,1990,1993,1994 by Paul Vixie
* All rights reserved
*/
/*
* Copyright (c) 1997 by Internet Software Consortium
*
* Distribute freely, except: don't remove my name from the source or
* documentation (don't take credit for my work), mark your changes (don't
* get me blamed for your possible bugs), don't alter or remove this
* notice. May be sold if buildable source is provided to buyer. No
* warrantee of any kind, express or implied, is included with this
* software; use at your own risk, responsibility for damages (if any) to
* anyone resulting from the use of this software rests entirely with the
* user.
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* Send bug reports, bug fixes, enhancements, requests, flames, etc., and
* I'll try to keep a version up to date. I can be reached as follows:
* Paul Vixie <paul@vix.com> uunet!decwrl!vixie!paul
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
* SOFTWARE.
*/
#if !defined(lint) && !defined(LINT)
static const char rcsid[] =
"$FreeBSD$";
static const char rcsid[] = "$Id: job.c,v 1.2 1998/08/14 00:32:40 vixie Exp $";
#endif
@ -37,11 +40,12 @@ static job *jhead = NULL, *jtail = NULL;
void
job_add(entry *e, user *u)
{
register job *j;
job *j;
/* if already on queue, keep going */
for (j=jhead; j; j=j->next)
if (j->e == e && j->u == u) { return; }
for (j = jhead; j != NULL; j = j->next)
if (j->e == e && j->u == u)
return;
/* build a job queue element */
if ((j = (job*)malloc(sizeof(job))) == NULL)
@ -51,8 +55,10 @@ job_add(entry *e, user *u)
j->u = u;
/* add it to the tail */
if (!jhead) { jhead=j; }
else { jtail->next=j; }
if (jhead == NULL)
jhead = j;
else
jtail->next = j;
jtail = j;
}
@ -60,15 +66,15 @@ job_add(entry *e, user *u)
int
job_runqueue(void)
{
register job *j, *jn;
register int run = 0;
job *j, *jn;
int run = 0;
for (j=jhead; j; j=jn) {
for (j = jhead; j; j = jn) {
do_command(j->e, j->u);
jn = j->next;
free(j);
run++;
}
jhead = jtail = NULL;
return run;
return (run);
}

134
usr.sbin/cron/cron/macros.h Normal file
View File

@ -0,0 +1,134 @@
/*
* $Id: macros.h,v 1.1 1998/08/14 00:31:24 vixie Exp $
*/
/*
* Copyright (c) 1997 by Internet Software Consortium
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
* SOFTWARE.
*/
/* these are really immutable, and are
* defined for symbolic convenience only
* TRUE, FALSE, and ERR must be distinct
* ERR must be < OK.
*/
#define TRUE 1
#define FALSE 0
/* system calls return this on success */
#define OK 0
/* or this on error */
#define ERR (-1)
/* turn this on to get '-x' code */
#ifndef DEBUGGING
#define DEBUGGING FALSE
#endif
#define READ_PIPE 0 /* which end of a pipe pair do you read? */
#define WRITE_PIPE 1 /* or write to? */
#define STDIN 0 /* what is stdin's file descriptor? */
#define STDOUT 1 /* stdout's? */
#define STDERR 2 /* stderr's? */
#define ERROR_EXIT 1 /* exit() with this will scare the shell */
#define OK_EXIT 0 /* exit() with this is considered 'normal' */
#define MAX_FNAME 100 /* max length of internally generated fn */
#define MAX_COMMAND 1000 /* max length of internally generated cmd */
#define MAX_ENVSTR 1000 /* max length of envvar=value\0 strings */
#define MAX_TEMPSTR 100 /* obvious */
#define ROOT_UID 0 /* don't change this, it really must be root */
#define ROOT_USER "root" /* ditto */
#define SYS_NAME "*system*" /* magic owner name for system crontab */
/* NOTE: these correspond to DebugFlagNames,
* defined below.
*/
#define DEXT 0x0001 /* extend flag for other debug masks */
#define DSCH 0x0002 /* scheduling debug mask */
#define DPROC 0x0004 /* process control debug mask */
#define DPARS 0x0008 /* parsing debug mask */
#define DLOAD 0x0010 /* database loading debug mask */
#define DMISC 0x0020 /* misc debug mask */
#define DTEST 0x0040 /* test mode: don't execute any commands */
#define DBIT 0x0080 /* bit twiddling shown (long) */
#define CRON_TAB(u) "%s/%s", SPOOL_DIR, u
#define PPC_NULL ((const char **)NULL)
#ifndef MAXHOSTNAMELEN
#define MAXHOSTNAMELEN 256
#endif
#define Skip_Blanks(c, f) \
while (c == '\t' || c == ' ') \
c = get_char(f);
#define Skip_Nonblanks(c, f) \
while (c!='\t' && c!=' ' && c!='\n' && c != EOF) \
c = get_char(f);
#define Skip_Line(c, f) \
do {c = get_char(f);} while (c != '\n' && c != EOF);
#if DEBUGGING
# define Debug(mask, message) \
if ( (DebugFlags & (mask) ) == (mask) ) \
printf message;
#else /* !DEBUGGING */
# define Debug(mask, message) \
;
#endif /* DEBUGGING */
#define MkLower(ch) (isupper(ch) ? tolower(ch) : ch)
#define MkUpper(ch) (islower(ch) ? toupper(ch) : ch)
#define Set_LineNum(ln) {Debug(DPARS|DEXT,("linenum=%d\n",ln)); \
LineNumber = ln; \
}
#define FIRST_SECOND 0
#define LAST_SECOND 59
#define SECOND_COUNT (LAST_SECOND - FIRST_SECOND + 1)
#define FIRST_MINUTE 0
#define LAST_MINUTE 59
#define MINUTE_COUNT (LAST_MINUTE - FIRST_MINUTE + 1)
#define FIRST_HOUR 0
#define LAST_HOUR 23
#define HOUR_COUNT (LAST_HOUR - FIRST_HOUR + 1)
#define FIRST_DOM 1
#define LAST_DOM 31
#define DOM_COUNT (LAST_DOM - FIRST_DOM + 1)
#define FIRST_MONTH 1
#define LAST_MONTH 12
#define MONTH_COUNT (LAST_MONTH - FIRST_MONTH + 1)
/* note on DOW: 0 and 7 are both Sunday, for compatibility reasons. */
#define FIRST_DOW 0
#define LAST_DOW 7
#define DOW_COUNT (LAST_DOW - FIRST_DOW + 1)
#ifdef LOGIN_CAP
/* see init.c */
#define RESOURCE_RC "daemon"
#endif
/* each user's crontab will be held as a list of
* the following structure.
*
* These are the cron commands.
*/

View File

@ -1,27 +1,27 @@
/* Copyright 1993,1994 by Paul Vixie
* All rights reserved
*
* Distribute freely, except: don't remove my name from the source or
* documentation (don't take credit for my work), mark your changes (don't
* get me blamed for your possible bugs), don't alter or remove this
* notice. May be sold if buildable source is provided to buyer. No
* warrantee of any kind, express or implied, is included with this
* software; use at your own risk, responsibility for damages (if any) to
* anyone resulting from the use of this software rests entirely with the
* user.
*
* Send bug reports, bug fixes, enhancements, requests, flames, etc., and
* I'll try to keep a version up to date. I can be reached as follows:
* Paul Vixie <paul@vix.com> uunet!decwrl!vixie!paul
*/
/*
* $FreeBSD$
* Copyright (c) 1997 by Internet Software Consortium
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
* SOFTWARE.
*/
#if (defined(BSD)) && (BSD >= 199103) || defined(__linux) || defined(AIX)
# include <paths.h>
#endif /*BSD*/
/*
* $Id: pathnames.h,v 1.4 1998/08/14 00:32:41 vixie Exp $
*/
#ifndef CRONDIR
/* CRONDIR is where crond(8) and crontab(1) both chdir
@ -45,16 +45,18 @@
* that ALLOW_FILE and DENY_FILE must both be defined
* in order to enable the allow/deny code. If neither
* LOG_FILE or SYSLOG is defined, we don't log. If
* both are defined, we log both ways.
* both are defined, we log both ways. Note that if
* LOG_CRON is defined by <syslog.h>, LOG_FILE will not
* be used.
*/
#define ALLOW_FILE "allow" /*-*/
#define DENY_FILE "deny" /*-*/
/*#define LOG_FILE "log"*/ /*-*/
#define ALLOW_FILE "allow"
#define DENY_FILE "deny"
#define LOG_FILE "log"
/* where should the daemon stick its PID?
*/
#define PIDDIR _PATH_VARRUN
#define PIDFILE "%scron.pid"
#define PIDFILE "cron.pid"
/* 4.3BSD-style crontab */
#define SYSCRONTAB "/etc/crontab"

View File

@ -24,25 +24,18 @@
*/
#ifndef lint
#if 0
static char sccsid[] = "@(#)popen.c 5.7 (Berkeley) 2/14/89";
#endif
static const char rcsid[] =
"$FreeBSD$";
"$Id: popen.c,v 1.3 1998/08/14 00:32:41 vixie Exp $";
#if 0
static const char sccsid[] = "@(#)popen.c 5.7 (Berkeley) 2/14/89";
#endif
#endif /* not lint */
#include "cron.h"
#include <sys/signal.h>
#include <fcntl.h>
#include <paths.h>
#if defined(SYSLOG)
# include <syslog.h>
#endif
#if defined(LOGIN_CAP)
# include <login_cap.h>
#endif
#define MAX_ARGS 100
#define WANT_GLOBBING 0
@ -57,7 +50,7 @@ static int fds;
FILE *
cron_popen(char *program, char *type, entry *e, PID_T *pidptr)
{
register char *cp;
char *cp;
FILE *iop;
int argc, pdes[2];
PID_T pid;
@ -74,17 +67,17 @@ cron_popen(char *program, char *type, entry *e, PID_T *pidptr)
extern char **glob(), **copyblk();
#endif
if ((*type != 'r' && *type != 'w') || type[1])
return(NULL);
if ((*type != 'r' && *type != 'w') || type[1] != '\0')
return (NULL);
if (!pids) {
if ((fds = getdtablesize()) <= 0)
return(NULL);
if ((fds = sysconf(_SC_OPEN_MAX)) <= 0)
return (NULL);
if (!(pids = calloc(fds, sizeof(PID_T))))
return(NULL);
return (NULL);
}
if (pipe(pdes) < 0)
return(NULL);
return (NULL);
/* break up string into pieces */
for (argc = 0, cp = program; argc < MAX_ARGS; cp = NULL)
@ -219,13 +212,13 @@ cron_popen(char *program, char *type, entry *e, PID_T *pidptr)
*pidptr = pid;
return(iop);
return (iop);
}
int
cron_pclose(FILE *iop)
{
register int fdes;
int fdes;
int omask;
WAIT_T stat_loc;
PID_T pid;
@ -235,7 +228,7 @@ cron_pclose(FILE *iop)
* `popened' command, or, if already `pclosed'.
*/
if (pids == 0 || pids[fdes = fileno(iop)] == 0)
return(-1);
return (-1);
(void)fclose(iop);
omask = sigblock(sigmask(SIGINT)|sigmask(SIGQUIT)|sigmask(SIGHUP));
while ((pid = wait(&stat_loc)) != pids[fdes] && pid != -1)

View File

@ -0,0 +1,81 @@
/*
* $Id: structs.h,v 1.1 1998/08/14 00:31:24 vixie Exp $
*/
/*
* Copyright (c) 1997 by Internet Software Consortium
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
* SOFTWARE.
*/
typedef struct _entry {
struct _entry *next;
uid_t uid;
gid_t gid;
#ifdef LOGIN_CAP
char *class;
#endif
char **envp;
char *cmd;
union {
struct {
bitstr_t bit_decl(second, SECOND_COUNT);
bitstr_t bit_decl(minute, MINUTE_COUNT);
bitstr_t bit_decl(hour, HOUR_COUNT);
bitstr_t bit_decl(dom, DOM_COUNT);
bitstr_t bit_decl(month, MONTH_COUNT);
bitstr_t bit_decl(dow, DOW_COUNT);
};
struct {
time_t lastexit;
time_t interval;
pid_t child;
};
};
int flags;
#define DOM_STAR 0x01
#define DOW_STAR 0x02
#define WHEN_REBOOT 0x04
#define DONT_LOG 0x08
#define NOT_UNTIL 0x10
#define SEC_RES 0x20
#define INTERVAL 0x40
#define RUN_AT 0x80
#define MAIL_WHEN_ERR 0x100
time_t lastrun;
} entry;
/* the crontab database will be a list of the
* following structure, one element per user
* plus one for the system.
*
* These are the crontabs.
*/
typedef struct _user {
struct _user *next, *prev; /* links */
char *name;
time_t mtime; /* last modtime of crontab */
entry *crontab; /* this person's crontab */
} user;
typedef struct _cron_db {
user *head, *tail; /* links */
time_t mtime; /* last modtime on spooldir */
} cron_db;
/* in the C tradition, we only create
* variables for the main program, just
* extern them elsewhere.
*/

View File

@ -1,29 +1,31 @@
/* Copyright 1988,1990,1993,1994 by Paul Vixie
* All rights reserved
*/
/*
* Copyright (c) 1997 by Internet Software Consortium
*
* Distribute freely, except: don't remove my name from the source or
* documentation (don't take credit for my work), mark your changes (don't
* get me blamed for your possible bugs), don't alter or remove this
* notice. May be sold if buildable source is provided to buyer. No
* warrantee of any kind, express or implied, is included with this
* software; use at your own risk, responsibility for damages (if any) to
* anyone resulting from the use of this software rests entirely with the
* user.
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* Send bug reports, bug fixes, enhancements, requests, flames, etc., and
* I'll try to keep a version up to date. I can be reached as follows:
* Paul Vixie <paul@vix.com> uunet!decwrl!vixie!paul
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
* SOFTWARE.
*/
#if !defined(lint) && !defined(LINT)
static const char rcsid[] =
"$FreeBSD$";
static const char rcsid[] = "$Id: user.c,v 1.2 1998/08/14 00:32:41 vixie Exp $";
#endif
/* vix 26jan87 [log is in RCS file]
*/
#include "cron.h"
static char *User_name;
@ -31,7 +33,7 @@ static char *User_name;
void
free_user(user *u)
{
entry *e, *ne;
entry *e, *ne;
free(u->name);
for (e = u->crontab; e != NULL; e = ne) {
@ -42,25 +44,25 @@ free_user(user *u)
}
static void
log_error(char *msg)
log_error(const char *msg)
{
log_it(User_name, getpid(), "PARSE", msg);
}
/* NULL pw implies syscrontab */
user *
load_user(int crontab_fd, struct passwd *pw, char *name)
load_user(int crontab_fd, struct passwd *pw, const char *name)
{
char envstr[MAX_ENVSTR];
FILE *file;
user *u;
entry *e;
int status;
char **envp, **tenvp;
char envstr[MAX_ENVSTR];
FILE *file;
user *u;
entry *e;
int status;
char **envp, **tenvp;
if (!(file = fdopen(crontab_fd, "r"))) {
warn("fdopen on crontab_fd in load_user");
return NULL;
return (NULL);
}
Debug(DPARS, ("load_user()\n"))
@ -69,12 +71,12 @@ load_user(int crontab_fd, struct passwd *pw, char *name)
*/
if ((u = (user *) malloc(sizeof(user))) == NULL) {
errno = ENOMEM;
return NULL;
return (NULL);
}
if ((u->name = strdup(name)) == NULL) {
free(u);
errno = ENOMEM;
return NULL;
return (NULL);
}
u->crontab = NULL;
@ -84,7 +86,7 @@ load_user(int crontab_fd, struct passwd *pw, char *name)
if ((envp = env_init()) == NULL) {
free(u->name);
free(u);
return NULL;
return (NULL);
}
/*
@ -120,5 +122,5 @@ load_user(int crontab_fd, struct passwd *pw, char *name)
env_free(envp);
fclose(file);
Debug(DPARS, ("...load_user() done\n"))
return u;
return (u);
}

View File

@ -1,21 +1,23 @@
.\"/* Copyright 1988,1990,1993 by Paul Vixie
.\" * All rights reserved
.\" *
.\" * Distribute freely, except: don't remove my name from the source or
.\" * documentation (don't take credit for my work), mark your changes (don't
.\" * get me blamed for your possible bugs), don't alter or remove this
.\" * notice. May be sold if buildable source is provided to buyer. No
.\" * warrantee of any kind, express or implied, is included with this
.\" * software; use at your own risk, responsibility for damages (if any) to
.\" * anyone resulting from the use of this software rests entirely with the
.\" * user.
.\" *
.\" * Send bug reports, bug fixes, enhancements, requests, flames, etc., and
.\" * I'll try to keep a version up to date. I can be reached as follows:
.\" * Paul Vixie <paul@vix.com> uunet!decwrl!vixie!paul
.\" */
.\"
.\" $FreeBSD$
.\"Copyright (c) 1997 by Internet Software Consortium
.\"
.\"Permission to use, copy, modify, and distribute this software for any
.\"purpose with or without fee is hereby granted, provided that the above
.\"copyright notice and this permission notice appear in all copies.
.\"
.\"THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
.\"ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
.\"OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
.\"CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
.\"DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
.\"PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
.\"ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
.\"SOFTWARE.
.\"
.\" $Id: crontab.1,v 1.2 1998/08/14 00:32:37 vixie Exp $
.\"
.Dd December 20, 2016
.Dt CRONTAB 1

View File

@ -1,21 +1,23 @@
.\"/* Copyright 1988,1990,1993,1994 by Paul Vixie
.\" * All rights reserved
.\" *
.\" * Distribute freely, except: don't remove my name from the source or
.\" * documentation (don't take credit for my work), mark your changes (don't
.\" * get me blamed for your possible bugs), don't alter or remove this
.\" * notice. May be sold if buildable source is provided to buyer. No
.\" * warrantee of any kind, express or implied, is included with this
.\" * software; use at your own risk, responsibility for damages (if any) to
.\" * anyone resulting from the use of this software rests entirely with the
.\" * user.
.\" *
.\" * Send bug reports, bug fixes, enhancements, requests, flames, etc., and
.\" * I'll try to keep a version up to date. I can be reached as follows:
.\" * Paul Vixie <paul@vix.com> uunet!decwrl!vixie!paul
.\" */
.\"
.\" $FreeBSD$
.\"Copyright (c) 1997 by Internet Software Consortium
.\"
.\"Permission to use, copy, modify, and distribute this software for any
.\"purpose with or without fee is hereby granted, provided that the above
.\"copyright notice and this permission notice appear in all copies.
.\"
.\"THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
.\"ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
.\"OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
.\"CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
.\"DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
.\"PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
.\"ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
.\"SOFTWARE.
.\"
.\" $Id: crontab.5,v 1.2 1998/08/14 00:32:38 vixie Exp $
.\"
.Dd March 29, 2020
.Dt CRONTAB 5

View File

@ -1,24 +1,27 @@
/* Copyright 1988,1990,1993,1994 by Paul Vixie
* All rights reserved
*/
/*
* Copyright (c) 1997 by Internet Software Consortium
*
* Distribute freely, except: don't remove my name from the source or
* documentation (don't take credit for my work), mark your changes (don't
* get me blamed for your possible bugs), don't alter or remove this
* notice. May be sold if buildable source is provided to buyer. No
* warrantee of any kind, express or implied, is included with this
* software; use at your own risk, responsibility for damages (if any) to
* anyone resulting from the use of this software rests entirely with the
* user.
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* Send bug reports, bug fixes, enhancements, requests, flames, etc., and
* I'll try to keep a version up to date. I can be reached as follows:
* Paul Vixie <paul@vix.com> uunet!decwrl!vixie!paul
* From Id: crontab.c,v 2.13 1994/01/17 03:20:37 vixie Exp
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
* SOFTWARE.
*/
#if !defined(lint) && !defined(LINT)
static const char rcsid[] =
"$FreeBSD$";
"$Id: crontab.c,v 1.3 1998/08/14 00:32:38 vixie Exp $";
#endif
/* crontab - install and manage per-user crontab files
@ -28,35 +31,18 @@ static const char rcsid[] =
#define MAIN_PROGRAM
#include <sys/param.h>
#include "cron.h"
#include <errno.h>
#include <fcntl.h>
#include <md5.h>
#include <paths.h>
#include <sys/file.h>
#include <sys/stat.h>
#ifdef USE_UTIMES
# include <sys/time.h>
#else
# include <time.h>
# include <utime.h>
#endif
#if defined(POSIX)
# include <locale.h>
#endif
#define MD5_SIZE 33
#define NHEADER_LINES 3
enum opt_t { opt_unknown, opt_list, opt_delete, opt_edit, opt_replace };
#if DEBUGGING
static char *Options[] = { "???", "list", "delete", "edit", "replace" };
#endif
static PID_T Pid;
static char User[MAXLOGNAME], RealUser[MAXLOGNAME];
static char Filename[MAX_FNAME];
@ -69,13 +55,12 @@ static void list_cmd(void),
delete_cmd(void),
edit_cmd(void),
poke_daemon(void),
check_error(char *),
check_error(const char *),
parse_args(int c, char *v[]);
static int replace_cmd(void);
static void
usage(char *msg)
usage(const char *msg)
{
fprintf(stderr, "crontab: usage error: %s\n", msg);
fprintf(stderr, "%s\n%s\n",
@ -84,7 +69,6 @@ usage(char *msg)
exit(ERROR_EXIT);
}
int
main(int argc, char *argv[])
{
@ -93,9 +77,7 @@ main(int argc, char *argv[])
Pid = getpid();
ProgramName = argv[0];
#if defined(POSIX)
setlocale(LC_ALL, "");
#endif
#if defined(BSD)
setlinebuf(stderr);
@ -110,28 +92,32 @@ main(int argc, char *argv[])
}
exitstatus = OK_EXIT;
switch (Option) {
case opt_list: list_cmd();
break;
case opt_delete: delete_cmd();
break;
case opt_edit: edit_cmd();
break;
case opt_replace: if (replace_cmd() < 0)
exitstatus = ERROR_EXIT;
break;
case opt_list:
list_cmd();
break;
case opt_delete:
delete_cmd();
break;
case opt_edit:
edit_cmd();
break;
case opt_replace:
if (replace_cmd() < 0)
exitstatus = ERROR_EXIT;
break;
case opt_unknown:
break;
default:
abort();
}
exit(exitstatus);
/*NOTREACHED*/
}
static void
parse_args(int argc, char *argv[])
{
int argch;
char resolved_path[PATH_MAX];
int argch;
char resolved_path[PATH_MAX];
if (!(pw = getpwuid(getuid())))
errx(ERROR_EXIT, "your UID isn't in the passwd file, bailing out");
@ -230,13 +216,14 @@ parse_args(int argc, char *argv[])
}
static void
copy_file(FILE *in, FILE *out) {
int x, ch;
copy_file(FILE *in, FILE *out)
{
int x, ch;
Set_LineNum(1)
/* ignore the top few comments since we probably put them there.
*/
for (x = 0; x < NHEADER_LINES; x++) {
for (x = 0; x < NHEADER_LINES; x++) {
ch = get_char(in);
if (EOF == ch)
break;
@ -261,8 +248,8 @@ copy_file(FILE *in, FILE *out) {
static void
list_cmd(void)
{
char n[MAX_FNAME];
FILE *f;
char n[MAX_FNAME];
FILE *f;
log_it(RealUser, Pid, "LIST", User);
(void) snprintf(n, sizeof(n), CRON_TAB(User));
@ -279,11 +266,10 @@ list_cmd(void)
fclose(f);
}
static void
delete_cmd(void)
{
char n[MAX_FNAME];
char n[MAX_FNAME];
int ch, first;
if (!fflag && isatty(STDIN_FILENO)) {
@ -296,8 +282,9 @@ delete_cmd(void)
}
log_it(RealUser, Pid, "DELETE", User);
(void) snprintf(n, sizeof(n), CRON_TAB(User));
if (unlink(n)) {
if (snprintf(n, sizeof(n), CRON_TAB(User)) >= (int)sizeof(n))
errx(ERROR_EXIT, "path too long");
if (unlink(n) != 0) {
if (errno == ENOENT)
errx(ERROR_EXIT, "no crontab for %s", User);
else
@ -306,31 +293,30 @@ delete_cmd(void)
poke_daemon();
}
static void
check_error(char *msg)
check_error(const char *msg)
{
CheckErrorCount++;
fprintf(stderr, "\"%s\":%d: %s\n", Filename, LineNumber-1, msg);
}
static void
edit_cmd(void)
{
char n[MAX_FNAME], q[MAX_TEMPSTR], *editor;
FILE *f;
int t;
struct stat statbuf, fsbuf;
WAIT_T waiter;
PID_T pid, xpid;
mode_t um;
int syntax_error = 0;
char orig_md5[MD5_SIZE];
char new_md5[MD5_SIZE];
char n[MAX_FNAME], q[MAX_TEMPSTR], *editor;
FILE *f;
int t;
struct stat statbuf, fsbuf;
WAIT_T waiter;
PID_T pid, xpid;
mode_t um;
int syntax_error = 0;
char orig_md5[MD5_SIZE];
char new_md5[MD5_SIZE];
log_it(RealUser, Pid, "BEGIN EDIT", User);
(void) snprintf(n, sizeof(n), CRON_TAB(User));
if (snprintf(n, sizeof(n), CRON_TAB(User)) >= (int)sizeof(n))
errx(ERROR_EXIT, "path too long");
if (!(f = fopen(n, "r"))) {
if (errno != ENOENT)
err(ERROR_EXIT, "%s", n);
@ -373,7 +359,8 @@ edit_cmd(void)
err(ERROR_EXIT, "swapping uids");
if (stat(Filename, &statbuf) < 0) {
warn("stat");
fatal: unlink(Filename);
fatal:
unlink(Filename);
exit(ERROR_EXIT);
}
if (swap_uids_back() < OK)
@ -385,9 +372,8 @@ edit_cmd(void)
goto fatal;
}
if ((!(editor = getenv("VISUAL")))
&& (!(editor = getenv("EDITOR")))
) {
if ((editor = getenv("VISUAL")) == NULL &&
(editor = getenv("EDITOR")) == NULL) {
editor = EDITOR;
}
@ -504,12 +490,12 @@ edit_cmd(void)
static int
replace_cmd(void)
{
char n[MAX_FNAME], envstr[MAX_ENVSTR], tn[MAX_FNAME];
FILE *tmp;
int ch, eof;
entry *e;
time_t now = time(NULL);
char **envp = env_init();
char n[MAX_FNAME], envstr[MAX_ENVSTR], tn[MAX_FNAME];
FILE *tmp;
int ch, eof;
entry *e;
time_t now = time(NULL);
char **envp = env_init();
if (envp == NULL) {
warnx("cannot allocate memory");
@ -517,7 +503,10 @@ replace_cmd(void)
}
(void) snprintf(n, sizeof(n), "tmp.%d", Pid);
(void) snprintf(tn, sizeof(tn), CRON_TAB(n));
if (snprintf(tn, sizeof(tn), CRON_TAB(n)) >= (int)sizeof(tn)) {
warnx("path too long");
return (-2);
}
if (!(tmp = fopen(tn, "w+"))) {
warn("%s", tn);
@ -605,7 +594,12 @@ replace_cmd(void)
return (-2);
}
(void) snprintf(n, sizeof(n), CRON_TAB(User));
if (snprintf(n, sizeof(n), CRON_TAB(User)) >= (int)sizeof(n)) {
warnx("path too long");
unlink(tn);
return (-2);
}
if (rename(tn, n)) {
warn("error renaming %s to %s", tn, n);
unlink(tn);
@ -628,23 +622,11 @@ replace_cmd(void)
return (0);
}
static void
poke_daemon(void)
{
#ifdef USE_UTIMES
struct timeval tvs[2];
(void)gettimeofday(&tvs[0], NULL);
tvs[1] = tvs[0];
if (utimes(SPOOL_DIR, tvs) < OK) {
warn("can't update mtime on spooldir %s", SPOOL_DIR);
return;
}
#else
if (utime(SPOOL_DIR, NULL) < OK) {
warn("can't update mtime on spooldir %s", SPOOL_DIR);
return;
}
#endif /*USE_UTIMES*/
}

View File

@ -1,21 +1,25 @@
/* Copyright 1993,1994 by Paul Vixie
* All rights reserved
*
* Distribute freely, except: don't remove my name from the source or
* documentation (don't take credit for my work), mark your changes (don't
* get me blamed for your possible bugs), don't alter or remove this
* notice. May be sold if buildable source is provided to buyer. No
* warrantee of any kind, express or implied, is included with this
* software; use at your own risk, responsibility for damages (if any) to
* anyone resulting from the use of this software rests entirely with the
* user.
*
* Send bug reports, bug fixes, enhancements, requests, flames, etc., and
* I'll try to keep a version up to date. I can be reached as follows:
* Paul Vixie <paul@vix.com> uunet!decwrl!vixie!paul
*/
$FreeBSD$
/*
* Copyright (c) 1997 by Internet Software Consortium
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
* SOFTWARE.
*/
$Id: INSTALL,v 1.2 1998/08/14 00:32:35 vixie Exp $
Read the comments at the top of the Makefile, then edit the area marked
'configurable stuff'.

View File

@ -1,23 +1,25 @@
#/* Copyright 1988,1990,1993,1994 by Paul Vixie
# * All rights reserved
# *
# * Distribute freely, except: don't remove my name from the source or
# * documentation (don't take credit for my work), mark your changes (don't
# * get me blamed for your possible bugs), don't alter or remove this
# * notice. May be sold if buildable source is provided to buyer. No
# * warrantee of any kind, express or implied, is included with this
# * software; use at your own risk, responsibility for damages (if any) to
# * anyone resulting from the use of this software rests entirely with the
# * user.
# *
# * Send bug reports, bug fixes, enhancements, requests, flames, etc., and
# * I'll try to keep a version up to date. I can be reached as follows:
# * Paul Vixie <paul@vix.com> uunet!decwrl!vixie!paul
# */
## Copyright (c) 1997 by Internet Software Consortium.
##
## Permission to use, copy, modify, and distribute this software for any
## purpose with or without fee is hereby granted, provided that the above
## copyright notice and this permission notice appear in all copies.
##
## THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
## ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
## OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
## CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
## DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
## PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
## ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
## SOFTWARE.
# Makefile for vixie's cron
#
# $FreeBSD$
# $Id: Makefile,v 1.2 1998/08/14 00:32:35 vixie Exp $
#
# vix 03mar88 [moved to RCS, rest of log is in there]
# vix 30mar87 [goodbye, time.c; hello, getopt]
@ -35,7 +37,7 @@
# SHELL is for the 'augumented make' systems where 'make' imports
# SHELL from the environment and then uses it to run its commands.
# if your environment SHELL variable is /bin/csh, make goes real
# slow and sometimes does the wrong thing.
# slow and sometimes does the wrong thing.
#
# this package needs the 'bitstring macros' library, which is
# available from me or from the comp.sources.unix archive. if you
@ -57,19 +59,12 @@ INCLUDE = -I.
#<<need getopt()>>
LIBS =
#<<optimize or debug?>>
#OPTIM = -O
OPTIM = -g
#<<ATT or BSD or POSIX?>>
# (ATT untested)
#COMPAT = -DATT
#(BSD is only needed if <sys/params.h> does not define it, as on ULTRIX)
#COMPAT = -DBSD
# (POSIX)
#COMPAT = -DPOSIX
#CDEBUG = -O
CDEBUG = -g
#<<lint flags of choice?>>
LINTFLAGS = -hbxa $(INCLUDE) $(COMPAT) $(DEBUGGING)
LINTFLAGS = -hbxa $(INCLUDE) $(DEBUGGING)
#<<want to use a nonstandard CC?>>
#CC = vcc
CC = gcc -Wall -Wno-unused -Wno-comment
#<<manifest defines>>
DEFS =
#(SGI IRIX systems need this)
@ -82,21 +77,20 @@ LDFLAGS =
#################################### end configurable stuff
SHELL = /bin/sh
CFLAGS = $(OPTIM) $(INCLUDE) $(COMPAT) $(DEFS)
CFLAGS = $(CDEBUG) $(INCLUDE) $(DEFS)
INFOS = README CHANGES FEATURES INSTALL CONVERSION THANKS MAIL
MANPAGES = bitstring.3 crontab.5 crontab.1 cron.8 putman.sh
HEADERS = bitstring.h cron.h config.h pathnames.h \
externs.h compat.h
HEADERS = bitstring.h cron.h config.h pathnames.h externs.h
SOURCES = cron.c crontab.c database.c do_command.c entry.c \
env.c job.c user.c popen.c misc.c compat.c
env.c job.c user.c popen.c misc.c
SHAR_SOURCE = $(INFOS) $(MANPAGES) Makefile $(HEADERS) $(SOURCES)
LINT_CRON = cron.c database.c user.c entry.c compat.c \
LINT_CRON = cron.c database.c user.c entry.c \
misc.c job.c do_command.c env.c popen.c
LINT_CRONTAB = crontab.c misc.c entry.c env.c compat.c
LINT_CRONTAB = crontab.c misc.c entry.c env.c
CRON_OBJ = cron.o database.o user.o entry.o job.o do_command.o \
misc.o env.o popen.o compat.o
CRONTAB_OBJ = crontab.o misc.o entry.o env.o compat.o
misc.o env.o popen.o
CRONTAB_OBJ = crontab.o misc.o entry.o env.o
all : cron crontab
@ -121,8 +115,10 @@ install : all
clean :; rm -f *.o cron crontab a.out core tags *~ #*
tags :; ctags ${SOURCES}
kit : $(SHAR_SOURCE)
makekit -m -s99k $(SHAR_SOURCE)
$(CRON_OBJ) : cron.h compat.h config.h externs.h pathnames.h Makefile
$(CRONTAB_OBJ) : cron.h compat.h config.h externs.h pathnames.h Makefile
$(CRON_OBJ) : cron.h config.h externs.h pathnames.h Makefile
$(CRONTAB_OBJ) : cron.h config.h externs.h pathnames.h Makefile

View File

@ -1,22 +1,25 @@
#/* Copyright 1988,1990,1993 by Paul Vixie
#/* Copyright 1988,1990,1993 by Paul Vixie <paul@vix.com>
# * All rights reserved
# *
# * Distribute freely, except: don't remove my name from the source or
# * documentation (don't take credit for my work), mark your changes (don't
# * get me blamed for your possible bugs), don't alter or remove this
# * notice. May be sold if buildable source is provided to buyer. No
# * warrantee of any kind, express or implied, is included with this
# * software; use at your own risk, responsibility for damages (if any) to
# * anyone resulting from the use of this software rests entirely with the
# * user.
# *
# * Send bug reports, bug fixes, enhancements, requests, flames, etc., and
# * I'll try to keep a version up to date. I can be reached as follows:
# * Paul Vixie <paul@vix.com> uunet!decwrl!vixie!paul
# */
Vixie Cron V3.0
December 27, 1993
## Copyright (c) 1997 by Internet Software Consortium.
##
## Permission to use, copy, modify, and distribute this software for any
## purpose with or without fee is hereby granted, provided that the above
## copyright notice and this permission notice appear in all copies.
##
## THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
## ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
## OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
## CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
## DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
## PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
## ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
## SOFTWARE.
Vixie Cron V4.0 - September 7, 1997
[V3.1 was some time after 1993]
[V3.0 was December 27, 1993]
[V2.2 was some time in 1992]
[V2.1 was May 29, 1991]
[V2.0 was July 5, 1990]
@ -24,7 +27,7 @@ December 27, 1993
[V1.0 was May 6, 1987]
Paul Vixie
This is a version of 'cron' that is known to run on BSD 4.[23] systems. It
This is a version of 'cron' that is known to run on most systems. It
is functionally based on the SysV cron, which means that each user can have
their own crontab file (all crontab files are stored in a read-protected
directory, usually /var/cron/tabs). No direct support is provided for
@ -36,13 +39,6 @@ A messages is logged each time a command is executed; also, the files
"crontab" command (which installs crontabs). It hasn't been tested on
SysV, although some effort has gone into making the port an easy one.
This is more or less the copyright that USENET contributed software usually
has. Since ATT couldn't use this version if they had to freely distribute
source, and since I'd love to see them use it, I'll offer some rediculously
low license fee just to have them take it. In the unlikely event that they
do this, I will continue to support and distribute the pseudo-PD version, so
please, don't flame me for wanting my work to see a wider distribution.
To use this: Sorry, folks, there is no cutesy 'Configure' script. You'll
have to go edit a couple of files... So, here's the checklist:
@ -69,4 +65,4 @@ have to go edit a couple of files... So, here's the checklist:
if you like it, change your /etc/{rc,rc.local} to use it instead of
the old one.
$FreeBSD$
$Id: README,v 1.2 1998/08/14 00:32:35 vixie Exp $

View File

@ -1,225 +0,0 @@
/* Copyright 1988,1990,1993,1994 by Paul Vixie
* All rights reserved
*
* Distribute freely, except: don't remove my name from the source or
* documentation (don't take credit for my work), mark your changes (don't
* get me blamed for your possible bugs), don't alter or remove this
* notice. May be sold if buildable source is provided to buyer. No
* warrantee of any kind, express or implied, is included with this
* software; use at your own risk, responsibility for damages (if any) to
* anyone resulting from the use of this software rests entirely with the
* user.
*
* Send bug reports, bug fixes, enhancements, requests, flames, etc., and
* I'll try to keep a version up to date. I can be reached as follows:
* Paul Vixie <paul@vix.com> uunet!decwrl!vixie!paul
*/
#if !defined(lint) && !defined(LINT)
static char rcsid[] = "$FreeBSD$";
#endif
/* vix 30dec93 [broke this out of misc.c - see RCS log for history]
* vix 15jan87 [added TIOCNOTTY, thanks csg@pyramid]
*/
#include "cron.h"
#ifdef NEED_GETDTABLESIZE
# include <limits.h>
#endif
#if defined(NEED_SETSID) && defined(BSD)
# include <sys/ioctl.h>
#endif
#include <errno.h>
#include <paths.h>
#ifdef NEED_STRDUP
char *
strdup(str)
char *str;
{
char *temp;
if ((temp = malloc(strlen(str) + 1)) == NULL) {
errno = ENOMEM;
return NULL;
}
(void) strcpy(temp, str);
return temp;
}
#endif
#ifdef NEED_STRERROR
char *
strerror(error)
int error;
{
extern char *sys_errlist[];
extern int sys_nerr;
static char buf[32];
if ((error <= sys_nerr) && (error > 0)) {
return sys_errlist[error];
}
sprintf(buf, "Unknown error: %d", error);
return buf;
}
#endif
#ifdef NEED_STRCASECMP
int
strcasecmp(left, right)
char *left;
char *right;
{
while (*left && (MkLower(*left) == MkLower(*right))) {
left++;
right++;
}
return MkLower(*left) - MkLower(*right);
}
#endif
#ifdef NEED_SETSID
int
setsid()
{
int newpgrp;
# if defined(BSD)
int fd;
# if defined(POSIX)
newpgrp = setpgid((pid_t)0, getpid());
# else
newpgrp = setpgrp(0, getpid());
# endif
if ((fd = open(_PATH_TTY, 2)) >= 0)
{
(void) ioctl(fd, TIOCNOTTY, (char*)0);
(void) close(fd);
}
# else /*BSD*/
newpgrp = setpgrp();
(void) close(STDIN); (void) open(_PATH_DEVNULL, 0);
(void) close(STDOUT); (void) open(_PATH_DEVNULL, 1);
(void) close(STDERR); (void) open(_PATH_DEVNULL, 2);
# endif /*BSD*/
return newpgrp;
}
#endif /*NEED_SETSID*/
#ifdef NEED_GETDTABLESIZE
int
getdtablesize() {
#ifdef _SC_OPEN_MAX
return sysconf(_SC_OPEN_MAX);
#else
return _POSIX_OPEN_MAX;
#endif
}
#endif
#ifdef NEED_FLOCK
/* The following flock() emulation snarfed intact *) from the HP-UX
* "BSD to HP-UX porting tricks" maintained by
* system@alchemy.chem.utoronto.ca (System Admin (Mike Peterson))
* from the version "last updated: 11-Jan-1993"
* Snarfage done by Jarkko Hietaniemi <Jarkko.Hietaniemi@hut.fi>
* *) well, almost, had to K&R the function entry, HPUX "cc"
* does not grok ANSI function prototypes */
/*
* flock (fd, operation)
*
* This routine performs some file locking like the BSD 'flock'
* on the object described by the int file descriptor 'fd',
* which must already be open.
*
* The operations that are available are:
*
* LOCK_SH - get a shared lock.
* LOCK_EX - get an exclusive lock.
* LOCK_NB - don't block (must be ORed with LOCK_SH or LOCK_EX).
* LOCK_UN - release a lock.
*
* Return value: 0 if lock successful, -1 if failed.
*
* Note that whether the locks are enforced or advisory is
* controlled by the presence or absence of the SETGID bit on
* the executable.
*
* Note that there is no difference between shared and exclusive
* locks, since the 'lockf' system call in SYSV doesn't make any
* distinction.
*
* The file "<sys/file.h>" should be modified to contain the definitions
* of the available operations, which must be added manually (see below
* for the values).
*/
/* this code has been reformatted by vixie */
int
flock(fd, operation)
int fd;
int operation;
{
int i;
switch (operation) {
case LOCK_SH: /* get a shared lock */
case LOCK_EX: /* get an exclusive lock */
i = lockf (fd, F_LOCK, 0);
break;
case LOCK_SH|LOCK_NB: /* get a non-blocking shared lock */
case LOCK_EX|LOCK_NB: /* get a non-blocking exclusive lock */
i = lockf (fd, F_TLOCK, 0);
if (i == -1)
if ((errno == EAGAIN) || (errno == EACCES))
errno = EWOULDBLOCK;
break;
case LOCK_UN: /* unlock */
i = lockf (fd, F_ULOCK, 0);
break;
default: /* can't decipher operation */
i = -1;
errno = EINVAL;
break;
}
return (i);
}
#endif /*NEED_FLOCK*/
#ifdef NEED_SETENV
int
setenv(name, value, overwrite)
char *name, *value;
int overwrite;
{
char *tmp;
if (overwrite && getenv(name))
return -1;
if (!(tmp = malloc(strlen(name) + strlen(value) + 2))) {
errno = ENOMEM;
return -1;
}
sprintf(tmp, "%s=%s", name, value);
return putenv(tmp); /* intentionally orphan 'tmp' storage */
}
#endif

View File

@ -1,23 +1,28 @@
/* Copyright 1988,1990,1993,1994 by Paul Vixie
/*
* Copyright 1988,1990,1993,1994 by Paul Vixie
* All rights reserved
*/
/*
* Copyright (c) 1997 by Internet Software Consortium
*
* Distribute freely, except: don't remove my name from the source or
* documentation (don't take credit for my work), mark your changes (don't
* get me blamed for your possible bugs), don't alter or remove this
* notice. May be sold if buildable source is provided to buyer. No
* warrantee of any kind, express or implied, is included with this
* software; use at your own risk, responsibility for damages (if any) to
* anyone resulting from the use of this software rests entirely with the
* user.
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* Send bug reports, bug fixes, enhancements, requests, flames, etc., and
* I'll try to keep a version up to date. I can be reached as follows:
* Paul Vixie <paul@vix.com> uunet!decwrl!vixie!paul
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
* SOFTWARE.
*/
#if !defined(lint) && !defined(LINT)
static const char rcsid[] =
"$FreeBSD$";
"$Id: entry.c,v 1.3 1998/08/14 00:32:39 vixie Exp $";
#endif
/* vix 26jan87 [RCS'd; rest of log is in RCS file]
@ -42,12 +47,7 @@ typedef enum ecode {
#endif
} ecode_e;
static char get_list(bitstr_t *, int, int, char *[], int, FILE *),
get_range(bitstr_t *, int, int, char *[], int, FILE *),
get_number(int *, int, char *[], int, FILE *);
static int set_element(bitstr_t *, int, int, int);
static char *ecodes[] =
static const char *ecodes[] =
{
"no error",
"bad minute",
@ -66,6 +66,10 @@ static char *ecodes[] =
#endif
};
static char get_list(bitstr_t *, int, int, const char *[], int, FILE *),
get_range(bitstr_t *, int, int, const char *[], int, FILE *),
get_number(int *, int, const char *[], int, FILE *);
static int set_element(bitstr_t *, int, int, int);
void
free_entry(entry *e)
@ -86,7 +90,7 @@ free_entry(entry *e)
* otherwise return a pointer to a new entry.
*/
entry *
load_entry(FILE *file, void (*error_func)(char *), struct passwd *pw,
load_entry(FILE *file, void (*error_func)(const char *), struct passwd *pw,
char **envp)
{
/* this function reads one crontab entry -- the next -- from a file.
@ -105,6 +109,7 @@ load_entry(FILE *file, void (*error_func)(char *), struct passwd *pw,
ecode_e ecode = e_none;
entry *e;
int ch;
int len;
char cmd[MAX_COMMAND];
char envstr[MAX_ENVSTR];
char **prev_env;
@ -379,10 +384,9 @@ load_entry(FILE *file, void (*error_func)(char *), struct passwd *pw,
}
if (!env_get("SHELL", e->envp)) {
prev_env = e->envp;
sprintf(envstr, "SHELL=%s", _PATH_BSHELL);
e->envp = env_set(e->envp, envstr);
e->envp = env_set(e->envp, "SHELL=" _PATH_BSHELL);
if (e->envp == NULL) {
warn("env_set(%s)", envstr);
warn("env_set(%s)", "SHELL=" _PATH_BSHELL);
env_free(prev_env);
ecode = e_mem;
goto eof;
@ -394,9 +398,10 @@ load_entry(FILE *file, void (*error_func)(char *), struct passwd *pw,
#ifndef LOGIN_CAP
if (!env_get("HOME", e->envp)) {
prev_env = e->envp;
sprintf(envstr, "HOME=%s", pw->pw_dir);
e->envp = env_set(e->envp, envstr);
if (e->envp == NULL) {
len = snprintf(envstr, sizeof(envstr), "HOME=%s", pw->pw_dir);
if (len < sizeof(envstr))
e->envp = env_set(e->envp, envstr);
if (len >= sizeof(envstr) || e->envp == NULL) {
warn("env_set(%s)", envstr);
env_free(prev_env);
ecode = e_mem;
@ -405,9 +410,10 @@ load_entry(FILE *file, void (*error_func)(char *), struct passwd *pw,
}
#endif
prev_env = e->envp;
sprintf(envstr, "%s=%s", "LOGNAME", pw->pw_name);
e->envp = env_set(e->envp, envstr);
if (e->envp == NULL) {
len = snprintf(envstr, sizeof(envstr), "LOGNAME=%s", pw->pw_name);
if (len < (int)sizeof(envstr))
e->envp = env_set(e->envp, envstr);
if (len >= (int)sizeof(envstr) || e->envp == NULL) {
warn("env_set(%s)", envstr);
env_free(prev_env);
ecode = e_mem;
@ -415,9 +421,10 @@ load_entry(FILE *file, void (*error_func)(char *), struct passwd *pw,
}
#if defined(BSD)
prev_env = e->envp;
sprintf(envstr, "%s=%s", "USER", pw->pw_name);
e->envp = env_set(e->envp, envstr);
if (e->envp == NULL) {
len = snprintf(envstr, sizeof(envstr), "USER=%s", pw->pw_name);
if (len < (int)sizeof(envstr))
e->envp = env_set(e->envp, envstr);
if (len >= (int)sizeof(envstr) || e->envp == NULL) {
warn("env_set(%s)", envstr);
env_free(prev_env);
ecode = e_mem;
@ -477,7 +484,6 @@ load_entry(FILE *file, void (*error_func)(char *), struct passwd *pw,
/* Everything up to the next \n or EOF is part of the command...
* too bad we don't know in advance how long it will be, since we
* need to malloc a string for it... so, we limit it to MAX_COMMAND.
* XXX - should use realloc().
*/
ch = get_string(cmd, MAX_COMMAND, file, "\n");
@ -512,10 +518,18 @@ load_entry(FILE *file, void (*error_func)(char *), struct passwd *pw,
}
/*
* bits one bit per flag, default=FALSE
* low, high bounds, impl. offset for bitstr
* names NULL or names for these elements
* ch current character being processed
* file file being read
*/
static char
get_list(bitstr_t *bits, int low, int high, char *names[], int ch, FILE *file)
get_list(bitstr_t *bits, int low, int high, const char *names[], int ch,
FILE *file)
{
register int done;
int done;
/* we know that we point to a non-blank character here;
* must do a Skip_Blanks before we exit, so that the
@ -554,14 +568,21 @@ get_list(bitstr_t *bits, int low, int high, char *names[], int ch, FILE *file)
}
/*
* bits one bit per flag, default=FALSE
* low, high bounds, impl. offset for bitstr
* names NULL or names for these elements
* ch current character being processed
* file file being read
*/
static char
get_range(bitstr_t *bits, int low, int high, char *names[], int ch, FILE *file)
get_range(bitstr_t *bits, int low, int high, const char *names[], int ch,
FILE *file)
{
/* range = number | number "-" number [ "/" number ]
*/
register int i;
auto int num1, num2, num3;
int i, num1, num2, num3;
Debug(DPARS|DEXT, ("get_range()...entering, exit won't show\n"))
@ -636,8 +657,15 @@ get_range(bitstr_t *bits, int low, int high, char *names[], int ch, FILE *file)
}
/*
* numptr where does the result go?
* low offset applied to enum result
* names symbolic names, if any, for enums
* ch current character
* file source
*/
static char
get_number(int *numptr, int low, char *names[], int ch, FILE *file)
get_number(int *numptr, int low, const char *names[], int ch, FILE *file)
{
char temp[MAX_TEMPSTR], *pc;
int len, i, all_digits;

View File

@ -1,23 +1,26 @@
/* Copyright 1988,1990,1993,1994 by Paul Vixie
* All rights reserved
*/
/*
* Copyright (c) 1997 by Internet Software Consortium
*
* Distribute freely, except: don't remove my name from the source or
* documentation (don't take credit for my work), mark your changes (don't
* get me blamed for your possible bugs), don't alter or remove this
* notice. May be sold if buildable source is provided to buyer. No
* warrantee of any kind, express or implied, is included with this
* software; use at your own risk, responsibility for damages (if any) to
* anyone resulting from the use of this software rests entirely with the
* user.
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* Send bug reports, bug fixes, enhancements, requests, flames, etc., and
* I'll try to keep a version up to date. I can be reached as follows:
* Paul Vixie <paul@vix.com> uunet!decwrl!vixie!paul
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
* SOFTWARE.
*/
#if !defined(lint) && !defined(LINT)
static const char rcsid[] =
"$FreeBSD$";
static const char rcsid[] = "$Id: env.c,v 1.3 1998/08/14 00:32:39 vixie Exp $";
#endif
@ -27,7 +30,7 @@ static const char rcsid[] =
char **
env_init(void)
{
register char **p = (char **) malloc(sizeof(char *));
char **p = (char **) malloc(sizeof(char **));
if (p)
p[0] = NULL;
@ -50,8 +53,8 @@ env_free(char **envp)
char **
env_copy(char **envp)
{
register int count, i;
register char **p;
int count, i;
char **p;
for (count = 0; envp[count] != NULL; count++)
;
@ -76,9 +79,9 @@ env_copy(char **envp)
char **
env_set(char **envp, char *envstr)
{
register int count, found;
register char **p;
char *q;
int count, found;
char **p;
char *q;
/*
* count the number of elements, including the null pointer;
@ -237,9 +240,8 @@ load_env(char *envstr, FILE *f)
/* 2 fields from parser; looks like an env setting */
if (strlen(name) + 1 + strlen(val) >= MAX_ENVSTR-1)
if (snprintf(envstr, MAX_ENVSTR, "%s=%s", name, val) >= MAX_ENVSTR)
return (FALSE);
(void) sprintf(envstr, "%s=%s", name, val);
Debug(DPARS, ("load_env, <%s> <%s> -> <%s>\n", name, val, envstr))
return (TRUE);
}
@ -248,10 +250,10 @@ load_env(char *envstr, FILE *f)
char *
env_get(char *name, char **envp)
{
register int len = strlen(name);
register char *p, *q;
int len = strlen(name);
char *p, *q;
while ((p = *envp++)) {
while ((p = *envp++) != NULL) {
if (!(q = strchr(p, '=')))
continue;
if ((q - p) == len && !strncmp(p, name, len))

View File

@ -1,23 +1,26 @@
/* Copyright 1988,1990,1993,1994 by Paul Vixie
* All rights reserved
*/
/*
* Copyright (c) 1997 by Internet Software Consortium
*
* Distribute freely, except: don't remove my name from the source or
* documentation (don't take credit for my work), mark your changes (don't
* get me blamed for your possible bugs), don't alter or remove this
* notice. May be sold if buildable source is provided to buyer. No
* warrantee of any kind, express or implied, is included with this
* software; use at your own risk, responsibility for damages (if any) to
* anyone resulting from the use of this software rests entirely with the
* user.
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* Send bug reports, bug fixes, enhancements, requests, flames, etc., and
* I'll try to keep a version up to date. I can be reached as follows:
* Paul Vixie <paul@vix.com> uunet!decwrl!vixie!paul
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
* SOFTWARE.
*/
#if !defined(lint) && !defined(LINT)
static const char rcsid[] =
"$FreeBSD$";
static const char rcsid[] = "$Id: misc.c,v 1.5 1998/08/14 00:32:40 vixie Exp $";
#endif
/* vix 26jan87 [RCS has the rest of the log]
@ -33,7 +36,6 @@ static const char rcsid[] =
#endif
#include <sys/file.h>
#include <sys/stat.h>
#include <err.h>
#include <errno.h>
#include <string.h>
#include <fcntl.h>
@ -42,8 +44,12 @@ static const char rcsid[] =
#endif
#if defined(LOG_CRON) && defined(LOG_FILE)
# undef LOG_FILE
#endif
#if defined(LOG_DAEMON) && !defined(LOG_CRON)
#define LOG_CRON LOG_DAEMON
# define LOG_CRON LOG_DAEMON
#endif
@ -51,10 +57,8 @@ static int LogFD = ERR;
int
strcmp_until(char *left, char *right, int until)
strcmp_until(const char *left, const char *right, int until)
{
register int diff;
while (*left && *left != until && *left == *right) {
left++;
right++;
@ -62,12 +66,9 @@ strcmp_until(char *left, char *right, int until)
if ((*left=='\0' || *left == until) &&
(*right=='\0' || *right == until)) {
diff = 0;
} else {
diff = *left - *right;
return (0);
}
return diff;
return (*left - *right);
}
@ -122,13 +123,13 @@ set_debug_flags(char *flags)
DebugFlags = 0;
while (*pc) {
char **test;
int mask;
const char **test;
int mask;
/* try to find debug flag name in our list.
*/
for ( test = DebugFlagNames, mask = 1;
*test && strcmp_until(*test, pc, ',');
*test != NULL && strcmp_until(*test, pc, ',');
test++, mask <<= 1
)
;
@ -371,19 +372,19 @@ out: if (allow)
void
log_it(char *username, int xpid, char *event, const char *detail)
log_it(const char *username, int xpid, const char *event, const char *detail)
{
#if defined(LOG_FILE) || DEBUGGING
PID_T pid = xpid;
PID_T pid = xpid;
#endif
#if defined(LOG_FILE)
char *msg;
TIME_T now = time((TIME_T) 0);
register struct tm *t = localtime(&now);
char *msg;
TIME_T now = time((TIME_T) 0);
struct tm *t = localtime(&now);
#endif /*LOG_FILE*/
#if defined(SYSLOG)
static int syslog_open = 0;
static int syslog_open = 0;
#endif
#if defined(LOG_FILE)
@ -469,13 +470,16 @@ log_close(void)
/* two warnings:
* (1) this routine is fairly slow
* (2) it returns a pointer to static storage
* parameters:
* s: string we want the first word of
* t: terminators, implicitly including \0
*/
char *
first_word(char *s, char *t)
{
static char retbuf[2][MAX_TEMPSTR + 1]; /* sure wish C had GC */
static int retsel = 0;
register char *rb, *rp;
char *rb, *rp;
/* select a return buffer */
retsel = 1-retsel;
@ -502,11 +506,16 @@ first_word(char *s, char *t)
* heavily ascii-dependent.
*/
static void
mkprint(register char *dst, register unsigned char *src, register int len)
mkprint(char *dst, unsigned char *src, int len)
{
/*
* XXX
* We know this routine can't overflow the dst buffer because mkprints()
* allocated enough space for the worst case.
*/
while (len-- > 0)
{
register unsigned char ch = *src++;
unsigned char ch = *src++;
if (ch < ' ') { /* control character */
*dst++ = '^';
@ -531,7 +540,7 @@ mkprint(register char *dst, register unsigned char *src, register int len)
char *
mkprints(unsigned char *src, unsigned int len)
{
register char *dst = malloc(len*4 + 1);
char *dst = malloc(len*4 + 1);
if (dst != NULL)
mkprint(dst, src, len);
@ -549,7 +558,7 @@ arpadate(time_t *clock)
{
time_t t = clock ?*clock :time(0L);
struct tm *tm = localtime(&t);
static char ret[32]; /* zone name might be >3 chars */
static char ret[60]; /* zone name might be >3 chars */
if (tm->tm_year >= 100)
tm->tm_year += 1900;