summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2002-07-08 18:11:03 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2002-07-08 18:11:03 +0000
commit3cff17a919cce3de2bd55032665acd6875b22020 (patch)
treeff7e42585206580846d318ec21dc5a79dbcf05fe /usr.sbin
parent50ed485ee90e432e7b61ef4ba5439790c4cc70b8 (diff)
Merge in some changes from Paul Vixie's tree; most are cosmetic
o ANSI function headers o return (foo) not return foo o add -oi to sendmail flags o update email address in man pages o make some strings const o completely remove globbing cruft from popen.c o whitespace changes o add DOW_STAR to flags for "monthly", "weekly", and "daily" cron entries
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/cron/config.h5
-rw-r--r--usr.sbin/cron/cron.84
-rw-r--r--usr.sbin/cron/cron.c4
-rw-r--r--usr.sbin/cron/crontab.14
-rw-r--r--usr.sbin/cron/crontab.54
-rw-r--r--usr.sbin/cron/crontab.c20
-rw-r--r--usr.sbin/cron/database.c4
-rw-r--r--usr.sbin/cron/do_command.c4
-rw-r--r--usr.sbin/cron/entry.c117
-rw-r--r--usr.sbin/cron/env.c61
-rw-r--r--usr.sbin/cron/externs.h9
-rw-r--r--usr.sbin/cron/funcs.h13
-rw-r--r--usr.sbin/cron/job.c21
-rw-r--r--usr.sbin/cron/misc.c162
-rw-r--r--usr.sbin/cron/popen.c73
-rw-r--r--usr.sbin/cron/structs.h3
-rw-r--r--usr.sbin/cron/user.c4
17 files changed, 182 insertions, 330 deletions
diff --git a/usr.sbin/cron/config.h b/usr.sbin/cron/config.h
index 956157274f0..fc3371c0824 100644
--- a/usr.sbin/cron/config.h
+++ b/usr.sbin/cron/config.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: config.h,v 1.10 2001/05/29 21:41:33 millert Exp $ */
+/* $OpenBSD: config.h,v 1.11 2002/07/08 18:11:02 millert Exp $ */
/* Copyright 1988,1990,1993,1994 by Paul Vixie
* All rights reserved
@@ -40,10 +40,11 @@
* (hint: MAILTO= was added for this reason).
*/
-#define MAILFMT "%s -FCronDaemon -odi -oem -t" /*-*/
+#define MAILFMT "%s -FCronDaemon -odi -oem -oi -t" /*-*/
/* -Fx = set full-name of sender
* -odi = Option Deliverymode Interactive
* -oem = Option Errors Mailedtosender
+ * -oi = Ignore "." alone on a line
* -t = Get recipient from headers
*/
#define MAILARG _PATH_SENDMAIL /*-*/
diff --git a/usr.sbin/cron/cron.8 b/usr.sbin/cron/cron.8
index cb7c60a2696..70b1c7a2dec 100644
--- a/usr.sbin/cron/cron.8
+++ b/usr.sbin/cron/cron.8
@@ -17,7 +17,7 @@
.\" ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
.\" SOFTWARE.
.\"
-.\" $OpenBSD: cron.8,v 1.14 2002/05/09 21:22:01 millert Exp $
+.\" $OpenBSD: cron.8,v 1.15 2002/07/08 18:11:02 millert Exp $
.\"
.Dd June 6, 1999
.Dt CRON 8
@@ -128,4 +128,4 @@ to check for crontab changes immediately
.Xr syslog 3 ,
.Xr crontab 5
.Sh AUTHORS
-Paul Vixie <paul@vix.com>
+Paul Vixie <vixie@isc.org>
diff --git a/usr.sbin/cron/cron.c b/usr.sbin/cron/cron.c
index bf06c0a30f3..7bdcb953445 100644
--- a/usr.sbin/cron/cron.c
+++ b/usr.sbin/cron/cron.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cron.c,v 1.24 2002/05/28 01:20:19 deraadt Exp $ */
+/* $OpenBSD: cron.c,v 1.25 2002/07/08 18:11:02 millert Exp $ */
/* Copyright 1988,1990,1993,1994 by Paul Vixie
* All rights reserved
*/
@@ -21,7 +21,7 @@
*/
#if !defined(lint) && !defined(LINT)
-static char rcsid[] = "$OpenBSD: cron.c,v 1.24 2002/05/28 01:20:19 deraadt Exp $";
+static const char rcsid[] = "$OpenBSD: cron.c,v 1.25 2002/07/08 18:11:02 millert Exp $";
#endif
#define MAIN_PROGRAM
diff --git a/usr.sbin/cron/crontab.1 b/usr.sbin/cron/crontab.1
index e351da16326..d0d7de14d4c 100644
--- a/usr.sbin/cron/crontab.1
+++ b/usr.sbin/cron/crontab.1
@@ -15,7 +15,7 @@
.\" ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
.\" SOFTWARE.
.\"
-.\" $OpenBSD: crontab.1,v 1.13 2002/05/11 22:08:51 millert Exp $
+.\" $OpenBSD: crontab.1,v 1.14 2002/07/08 18:11:02 millert Exp $
.\"
.Dd June 8, 1999
.Dt CRONTAB 1
@@ -141,4 +141,4 @@ specification.
A fairly informative usage message appears if you run it with a bad command
line.
.Sh AUTHORS
-Paul Vixie <paul@vix.com>
+Paul Vixie <vixie@isc.org>
diff --git a/usr.sbin/cron/crontab.5 b/usr.sbin/cron/crontab.5
index 62fea1b9338..089c68e9fa3 100644
--- a/usr.sbin/cron/crontab.5
+++ b/usr.sbin/cron/crontab.5
@@ -15,7 +15,7 @@
.\" ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
.\" SOFTWARE.
.\"
-.\" $OpenBSD: crontab.5,v 1.16 2001/08/22 23:14:27 hugh Exp $
+.\" $OpenBSD: crontab.5,v 1.17 2002/07/08 18:11:02 millert Exp $
.\"
.Dd June 8, 1999
.Dt CRONTAB 5
@@ -409,4 +409,4 @@ All of the
commands that can appear in place of the first five fields
are extensions.
.Sh AUTHORS
-Paul Vixie <paul@vix.com>
+Paul Vixie <vixie@isc.org>
diff --git a/usr.sbin/cron/crontab.c b/usr.sbin/cron/crontab.c
index ecbe6caa143..2190eeb76c9 100644
--- a/usr.sbin/cron/crontab.c
+++ b/usr.sbin/cron/crontab.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: crontab.c,v 1.30 2002/05/09 22:14:37 millert Exp $ */
+/* $OpenBSD: crontab.c,v 1.31 2002/07/08 18:11:02 millert Exp $ */
/* Copyright 1988,1990,1993,1994 by Paul Vixie
* All rights reserved
*/
@@ -21,7 +21,7 @@
*/
#if !defined(lint) && !defined(LINT)
-static char rcsid[] = "$OpenBSD: crontab.c,v 1.30 2002/05/09 22:14:37 millert Exp $";
+static char const rcsid[] = "$OpenBSD: crontab.c,v 1.31 2002/07/08 18:11:02 millert Exp $";
#endif
/* crontab - install and manage per-user crontab files
@@ -76,7 +76,7 @@ usage(const char *msg) {
int
main(int argc, char *argv[]) {
- int exitstatus;
+ int exitstatus;
Pid = getpid();
ProgramName = argv[0];
@@ -229,7 +229,6 @@ parse_args(int argc, char *argv[]) {
User, Filename, Options[(int)Option]))
}
-
static void
list_cmd(void) {
char n[MAX_FNAME];
@@ -344,10 +343,8 @@ edit_cmd(void) {
/* ignore the top few comments since we probably put them there.
*/
- for (x = 0; x < NHEADER_LINES; x++) {
- ch = get_char(f);
- if (EOF == ch)
- break;
+ x = 0;
+ while (EOF != (ch = get_char(f))) {
if ('#' != ch) {
putc(ch, NewCrontab);
break;
@@ -355,7 +352,7 @@ edit_cmd(void) {
while (EOF != (ch = get_char(f)))
if (ch == '\n')
break;
- if (EOF == ch)
+ if (++x >= NHEADER_LINES)
break;
}
@@ -470,10 +467,12 @@ edit_cmd(void) {
fflush(stdout);
q[0] = '\0';
(void) fgets(q, sizeof q, stdin);
- switch (islower(q[0]) ? q[0] : tolower(q[0])) {
+ switch (q[0]) {
case 'y':
+ case 'Y':
goto again;
case 'n':
+ case 'N':
goto abandon;
default:
fprintf(stderr, "Enter Y or N\n");
@@ -496,7 +495,6 @@ edit_cmd(void) {
log_it(RealUser, Pid, "END EDIT", User);
}
-
/* returns 0 on success
* -1 on syntax error
* -2 on install error
diff --git a/usr.sbin/cron/database.c b/usr.sbin/cron/database.c
index d575465ddc6..fca3d81225c 100644
--- a/usr.sbin/cron/database.c
+++ b/usr.sbin/cron/database.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: database.c,v 1.6 2002/05/09 21:22:01 millert Exp $ */
+/* $OpenBSD: database.c,v 1.7 2002/07/08 18:11:02 millert Exp $ */
/* Copyright 1988,1990,1993,1994 by Paul Vixie
* All rights reserved
*/
@@ -21,7 +21,7 @@
*/
#if !defined(lint) && !defined(LINT)
-static char rcsid[] = "$OpenBSD: database.c,v 1.6 2002/05/09 21:22:01 millert Exp $";
+static char const rcsid[] = "$OpenBSD: database.c,v 1.7 2002/07/08 18:11:02 millert Exp $";
#endif
/* vix 26jan87 [RCS has the log]
diff --git a/usr.sbin/cron/do_command.c b/usr.sbin/cron/do_command.c
index c11b207d1c8..bf95a32a762 100644
--- a/usr.sbin/cron/do_command.c
+++ b/usr.sbin/cron/do_command.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: do_command.c,v 1.16 2002/06/23 03:07:19 deraadt Exp $ */
+/* $OpenBSD: do_command.c,v 1.17 2002/07/08 18:11:02 millert Exp $ */
/* Copyright 1988,1990,1993,1994 by Paul Vixie
* All rights reserved
*/
@@ -21,7 +21,7 @@
*/
#if !defined(lint) && !defined(LINT)
-static char rcsid[] = "$OpenBSD: do_command.c,v 1.16 2002/06/23 03:07:19 deraadt Exp $";
+static char const rcsid[] = "$OpenBSD: do_command.c,v 1.17 2002/07/08 18:11:02 millert Exp $";
#endif
#include "cron.h"
diff --git a/usr.sbin/cron/entry.c b/usr.sbin/cron/entry.c
index fceec2a91a6..4173f996387 100644
--- a/usr.sbin/cron/entry.c
+++ b/usr.sbin/cron/entry.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: entry.c,v 1.9 2002/06/14 21:35:01 todd Exp $ */
+/* $OpenBSD: entry.c,v 1.10 2002/07/08 18:11:02 millert Exp $ */
/*
* Copyright 1988,1990,1993,1994 by Paul Vixie
* All rights reserved
@@ -22,7 +22,7 @@
*/
#if !defined(lint) && !defined(LINT)
-static char rcsid[] = "$OpenBSD: entry.c,v 1.9 2002/06/14 21:35:01 todd Exp $";
+static char const rcsid[] = "$OpenBSD: entry.c,v 1.10 2002/07/08 18:11:02 millert Exp $";
#endif
/* vix 26jan87 [RCS'd; rest of log is in RCS file]
@@ -31,10 +31,8 @@ static char rcsid[] = "$OpenBSD: entry.c,v 1.9 2002/06/14 21:35:01 todd Exp $";
* vix 30dec86 [written]
*/
-
#include "cron.h"
-
typedef enum ecode {
e_none, e_minute, e_hour, e_dom, e_month, e_dow,
e_cmd, e_timespec, e_username, e_option
@@ -54,31 +52,23 @@ static const char *ecodes[] =
"bad option"
};
-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 char get_list(bitstr_t *, int, int, const char *[], char, FILE *),
+ get_range(bitstr_t *, int, int, const char *[], char, FILE *),
+ get_number(int *, int, const char *[], char, FILE *);
static int set_element(bitstr_t *, int, int, int);
void
-free_entry(e)
- entry *e;
-{
+free_entry(entry *e) {
free(e->cmd);
env_free(e->envp);
free(e);
}
-
/* return NULL if eof or syntax error occurs;
* otherwise return a pointer to a new entry.
*/
entry *
-load_entry(file, error_func, pw, envp)
- FILE *file;
- void (*error_func)();
- struct passwd *pw;
- char **envp;
-{
+load_entry(FILE *file, void (*error_func)(), struct passwd *pw, char **envp) {
/* this function reads one crontab entry -- the next -- from a file.
* it skips any leading blank lines, ignores comments, and returns
* EOF if for any reason the entry can't be read and parsed.
@@ -93,11 +83,11 @@ load_entry(file, error_func, pw, envp)
*/
ecode_e ecode = e_none;
- entry *e;
- int ch;
- char cmd[MAX_COMMAND];
- char envstr[MAX_ENVSTR];
- char **tenvp;
+ entry *e;
+ int ch;
+ char cmd[MAX_COMMAND];
+ char envstr[MAX_ENVSTR];
+ char **tenvp;
Debug(DPARS, ("load_entry()...about to eat comments\n"))
@@ -105,7 +95,7 @@ load_entry(file, error_func, pw, envp)
ch = get_char(file);
if (ch == EOF)
- return NULL;
+ return (NULL);
/* ch is now the first useful character of a useful line.
* it may be an @special or it may be the first character
@@ -136,18 +126,21 @@ load_entry(file, error_func, pw, envp)
bit_set(e->dom, 0);
bit_set(e->month, 0);
bit_nset(e->dow, 0, (LAST_DOW-FIRST_DOW+1));
+ e->flags |= DOW_STAR;
} else if (!strcmp("monthly", cmd)) {
bit_set(e->minute, 0);
bit_set(e->hour, 0);
bit_set(e->dom, 0);
bit_nset(e->month, 0, (LAST_MONTH-FIRST_MONTH+1));
bit_nset(e->dow, 0, (LAST_DOW-FIRST_DOW+1));
+ e->flags |= DOW_STAR;
} else if (!strcmp("weekly", cmd)) {
bit_set(e->minute, 0);
bit_set(e->hour, 0);
bit_nset(e->dom, 0, (LAST_DOM-FIRST_DOM+1));
bit_nset(e->month, 0, (LAST_MONTH-FIRST_MONTH+1));
bit_set(e->dow, 0);
+ e->flags |= DOW_STAR;
} else if (!strcmp("daily", cmd) || !strcmp("midnight", cmd)) {
bit_set(e->minute, 0);
bit_set(e->hour, 0);
@@ -378,7 +371,7 @@ load_entry(file, error_func, pw, envp)
/* success, fini, return pointer to the entry we just created...
*/
- return e;
+ return (e);
eof:
if (e->envp)
@@ -390,17 +383,12 @@ load_entry(file, error_func, pw, envp)
(*error_func)(ecodes[(int)ecode]);
while (ch != EOF && ch != '\n')
ch = get_char(file);
- return NULL;
+ return (NULL);
}
-
static char
-get_list(bits, low, high, names, ch, file)
- bitstr_t *bits; /* one bit per flag, default=FALSE */
- int low, high; /* bounds, impl. offset for bitstr */
- const char *names[]; /* NULL or *[] of names for these elements */
- int ch; /* current character being processed */
- FILE *file; /* file being read */
+get_list(bitstr_t *bits, int low, int high, const char *names[],
+ char ch, FILE *file)
{
int done;
@@ -437,22 +425,18 @@ get_list(bits, low, high, names, ch, file)
Debug(DPARS|DEXT, ("get_list()...exiting w/ %02x\n", ch))
- return ch;
+ return (ch);
}
static char
-get_range(bits, low, high, names, ch, file)
- bitstr_t *bits; /* one bit per flag, default=FALSE */
- int low, high; /* bounds, impl. offset for bitstr */
- const char *names[]; /* NULL or names of elements */
- int ch; /* current character being processed */
- FILE *file; /* file being read */
+get_range(bitstr_t *bits, int low, int high, const char *names[],
+ char ch, FILE *file)
{
/* range = number | number "-" number [ "/" number ]
*/
- int i, num1, num2, num3;
+ int i, num1, num2, num3;
Debug(DPARS|DEXT, ("get_range()...entering, exit won't show\n"))
@@ -463,29 +447,29 @@ get_range(bits, low, high, names, ch, file)
num2 = high;
ch = get_char(file);
if (ch == EOF)
- return EOF;
+ return (EOF);
} else {
if (EOF == (ch = get_number(&num1, low, names, ch, file)))
- return EOF;
+ return (EOF);
if (ch != '-') {
/* not a range, it's a single number.
*/
if (EOF == set_element(bits, low, high, num1))
- return EOF;
- return ch;
+ return (EOF);
+ return (ch);
} else {
/* eat the dash
*/
ch = get_char(file);
if (ch == EOF)
- return EOF;
+ return (EOF);
/* get the number following the dash
*/
ch = get_number(&num2, low, names, ch, file);
if (ch == EOF)
- return EOF;
+ return (EOF);
}
}
@@ -496,7 +480,7 @@ get_range(bits, low, high, names, ch, file)
*/
ch = get_char(file);
if (ch == EOF)
- return EOF;
+ return (EOF);
/* get the step size -- note: we don't pass the
* names here, because the number is not an
@@ -505,7 +489,7 @@ get_range(bits, low, high, names, ch, file)
*/
ch = get_number(&num3, 0, PPC_NULL, ch, file);
if (ch == EOF)
- return EOF;
+ return (EOF);
} else {
/* no step. default==1.
*/
@@ -519,22 +503,15 @@ get_range(bits, low, high, names, ch, file)
*/
for (i = num1; i <= num2; i += num3)
if (EOF == set_element(bits, low, high, i))
- return EOF;
+ return (EOF);
- return ch;
+ return (ch);
}
-
static char
-get_number(numptr, low, names, ch, file)
- int *numptr; /* where does the result go? */
- int low; /* offset applied to enum result */
- const char *names[]; /* symbolic names, if any, for enums */
- int ch; /* current character */
- FILE *file; /* source */
-{
- char temp[MAX_TEMPSTR], *pc;
- int len, i, all_digits;
+get_number(int *numptr, int low, const char *names[], char ch, FILE *file) {
+ char temp[MAX_TEMPSTR], *pc;
+ int len, i, all_digits;
/* collect alphanumerics into our fixed-size temp array
*/
@@ -543,7 +520,7 @@ get_number(numptr, low, names, ch, file)
all_digits = TRUE;
while (isalnum(ch)) {
if (++len >= MAX_TEMPSTR)
- return EOF;
+ return (EOF);
*pc++ = ch;
@@ -562,7 +539,7 @@ get_number(numptr, low, names, ch, file)
("get_num, compare(%s,%s)\n", names[i], temp))
if (!strcasecmp(names[i], temp)) {
*numptr = i+low;
- return ch;
+ return (ch);
}
}
}
@@ -573,25 +550,19 @@ get_number(numptr, low, names, ch, file)
*/
if (all_digits) {
*numptr = atoi(temp);
- return ch;
+ return (ch);
}
- return EOF;
+ return (EOF);
}
-
static int
-set_element(bits, low, high, number)
- bitstr_t *bits; /* one bit per flag, default=FALSE */
- int low;
- int high;
- int number;
-{
+set_element(bitstr_t *bits, int low, int high, int number) {
Debug(DPARS|DEXT, ("set_element(?,%d,%d,%d)\n", low, high, number))
if (number < low || number > high)
- return EOF;
+ return (EOF);
bit_set(bits, (number-low));
- return OK;
+ return (OK);
}
diff --git a/usr.sbin/cron/env.c b/usr.sbin/cron/env.c
index 48d0b8ffe56..f6cf2ebbcb9 100644
--- a/usr.sbin/cron/env.c
+++ b/usr.sbin/cron/env.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: env.c,v 1.9 2001/02/18 20:17:20 millert Exp $ */
+/* $OpenBSD: env.c,v 1.10 2002/07/08 18:11:02 millert Exp $ */
/* Copyright 1988,1990,1993,1994 by Paul Vixie
* All rights reserved
*/
@@ -21,16 +21,13 @@
*/
#if !defined(lint) && !defined(LINT)
-static char rcsid[] = "$OpenBSD: env.c,v 1.9 2001/02/18 20:17:20 millert Exp $";
+static char const rcsid[] = "$OpenBSD: env.c,v 1.10 2002/07/08 18:11:02 millert Exp $";
#endif
-
#include "cron.h"
-
char **
-env_init()
-{
+env_init(void) {
char **p = (char **) malloc(sizeof(char **));
if (p != NULL)
@@ -38,28 +35,22 @@ env_init()
return (p);
}
-
void
-env_free(envp)
- char **envp;
-{
+env_free(char **envp) {
char **p;
- for (p = envp; *p; p++)
+ for (p = envp; *p != NULL; p++)
free(*p);
free(envp);
}
-
char **
-env_copy(envp)
- char **envp;
-{
- int count, i, save_errno;
- char **p;
+env_copy(char **envp) {
+ int count, i, save_errno;
+ char **p;
for (count = 0; envp[count] != NULL; count++)
- ;
+ NULL;
p = (char **) malloc((count+1) * sizeof(char *)); /* 1 for the NULL */
if (p != NULL) {
for (i = 0; i < count; i++)
@@ -76,14 +67,10 @@ env_copy(envp)
return (p);
}
-
char **
-env_set(envp, envstr)
- char **envp;
- char *envstr;
-{
- int count, found;
- char **p, *cp;
+env_set(char **envp, char *envstr) {
+ int count, found;
+ char **p, *cp;
/*
* count the number of elements, including the null pointer;
@@ -126,20 +113,16 @@ env_set(envp, envstr)
return (p);
}
-
/* return ERR = end of file
* FALSE = not an env setting (file was repositioned)
* TRUE = was an env setting
*/
int
-load_env(envstr, f)
- char *envstr;
- FILE *f;
-{
- long filepos;
- int fileline;
- char name[MAX_ENVSTR], val[MAX_ENVSTR];
- int fields;
+load_env(char *envstr, FILE *f) {
+ long filepos;
+ int fileline;
+ char name[MAX_ENVSTR], val[MAX_ENVSTR];
+ int fields;
filepos = ftell(f);
fileline = LineNumber;
@@ -187,14 +170,10 @@ load_env(envstr, f)
return (TRUE);
}
-
char *
-env_get(name, envp)
- char *name;
- char **envp;
-{
- int len = strlen(name);
- char *p, *q;
+env_get(char *name, char **envp) {
+ int len = strlen(name);
+ char *p, *q;
while ((p = *envp++) != NULL) {
if (!(q = strchr(p, '=')))
diff --git a/usr.sbin/cron/externs.h b/usr.sbin/cron/externs.h
index 4d3c0625ca8..7f8400f3533 100644
--- a/usr.sbin/cron/externs.h
+++ b/usr.sbin/cron/externs.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: externs.h,v 1.4 2002/05/09 21:22:01 millert Exp $ */
+/* $OpenBSD: externs.h,v 1.5 2002/07/08 18:11:02 millert Exp $ */
/* Copyright 1993,1994 by Paul Vixie
* All rights reserved
@@ -34,6 +34,9 @@
#include <bitstring.h>
#include <ctype.h>
+#ifndef isascii
+#define isascii(c) ((unsigned)(c)<=0177)
+#endif
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
@@ -125,3 +128,7 @@ extern int flock(int, int);
#ifndef LOCK_UN
# define LOCK_UN 8
#endif
+
+#ifndef WCOREDUMP
+# define WCOREDUMP(st) (((st) & 0200) != 0)
+#endif
diff --git a/usr.sbin/cron/funcs.h b/usr.sbin/cron/funcs.h
index 83991e51aaf..7d11afd97ac 100644
--- a/usr.sbin/cron/funcs.h
+++ b/usr.sbin/cron/funcs.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: funcs.h,v 1.6 2002/05/09 22:15:18 millert Exp $ */
+/* $OpenBSD: funcs.h,v 1.7 2002/07/08 18:11:02 millert Exp $ */
/*
* Copyright (c) 1997,2000 by Internet Software Consortium, Inc.
@@ -41,16 +41,16 @@ void set_cron_uid(void),
log_close(void);
int job_runqueue(void),
- set_debug_flags(char *),
+ set_debug_flags(const char *),
get_char(FILE *),
get_string(char *, int, FILE *, char *),
swap_gids(void),
swap_gids_back(void),
load_env(char *, FILE *),
cron_pclose(FILE *),
- glue_strings(char *, int, char *, char *, int),
- strcmp_until(const char *, const char *, int),
- allowed(char *),
+ glue_strings(char *, size_t, const char *, const char *, char),
+ strcmp_until(const char *, const char *, char),
+ allowed(const char *),
strdtb(char *),
open_socket(void);
@@ -65,8 +65,7 @@ char *env_get(char *, char **),
user *load_user(int, struct passwd *, const char *),
*find_user(cron_db *, const char *);
-entry *load_entry(FILE *, void (*)(),
- struct passwd *, char **);
+entry *load_entry(FILE *, void (*)(), struct passwd *, char **);
FILE *cron_popen(char *, char *, entry *);
diff --git a/usr.sbin/cron/job.c b/usr.sbin/cron/job.c
index c85c7270d53..876fa2c0c83 100644
--- a/usr.sbin/cron/job.c
+++ b/usr.sbin/cron/job.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: job.c,v 1.3 2001/02/18 19:48:35 millert Exp $ */
+/* $OpenBSD: job.c,v 1.4 2002/07/08 18:11:02 millert Exp $ */
/* Copyright 1988,1990,1993,1994 by Paul Vixie
* All rights reserved
*/
@@ -21,28 +21,21 @@
*/
#if !defined(lint) && !defined(LINT)
-static char rcsid[] = "$OpenBSD: job.c,v 1.3 2001/02/18 19:48:35 millert Exp $";
+static char const rcsid[] = "$OpenBSD: job.c,v 1.4 2002/07/08 18:11:02 millert Exp $";
#endif
-
#include "cron.h"
-
typedef struct _job {
struct _job *next;
entry *e;
user *u;
} job;
-
static job *jhead = NULL, *jtail = NULL;
-
void
-job_add(e, u)
- entry *e;
- user *u;
-{
+job_add(entry *e, user *u) {
job *j;
/* if already on queue, keep going */
@@ -65,12 +58,10 @@ job_add(e, u)
jtail = j;
}
-
int
-job_runqueue()
-{
- job *j, *jn;
- int run = 0;
+job_runqueue(void) {
+ job *j, *jn;
+ int run = 0;
for (j = jhead; j; j = jn) {
do_command(j->e, j->u);
diff --git a/usr.sbin/cron/misc.c b/usr.sbin/cron/misc.c
index f1cadbbb99d..55d1caef2e5 100644
--- a/usr.sbin/cron/misc.c
+++ b/usr.sbin/cron/misc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: misc.c,v 1.19 2002/05/28 02:03:01 millert Exp $ */
+/* $OpenBSD: misc.c,v 1.20 2002/07/08 18:11:02 millert Exp $ */
/* Copyright 1988,1990,1993,1994 by Paul Vixie
* All rights reserved
*/
@@ -21,20 +21,18 @@
*/
#if !defined(lint) && !defined(LINT)
-static char rcsid[] = "$OpenBSD: misc.c,v 1.19 2002/05/28 02:03:01 millert Exp $";
+static char const rcsid[] = "$OpenBSD: misc.c,v 1.20 2002/07/08 18:11:02 millert Exp $";
#endif
/* vix 26jan87 [RCS has the rest of the log]
* vix 30dec86 [written]
*/
-
#include "cron.h"
#include <sys/socket.h>
#include <sys/un.h>
-
-#if defined(LOG_CRON) && defined(LOG_FILE)
+#if defined(SYSLOG) && defined(LOG_FILE)
# undef LOG_FILE
#endif
@@ -42,8 +40,11 @@ static char rcsid[] = "$OpenBSD: misc.c,v 1.19 2002/05/28 02:03:01 millert Exp $
# define LOG_CRON LOG_DAEMON
#endif
+#ifndef FACILITY
+#define FACILITY LOG_CRON
+#endif
-static int LogFD = ERR;
+static int LogFD = ERR;
/*
* glue_strings is the overflow-safe equivalent of
@@ -53,12 +54,8 @@ static int LogFD = ERR;
* glue_strings fails.
*/
int
-glue_strings(buffer, buffer_size, a, b, separator)
- char *buffer;
- int buffer_size;
- char *a;
- char *b;
- int separator;
+glue_strings(char *buffer, size_t buffer_size, const char *a, const char *b,
+ char separator)
{
char *buf;
char *buf_end;
@@ -85,7 +82,7 @@ glue_strings(buffer, buffer_size, a, b, separator)
}
int
-strcmp_until(const char *left, const char *right, int until) {
+strcmp_until(const char *left, const char *right, char until) {
while (*left && *left != until && *left == *right) {
left++;
right++;
@@ -98,13 +95,10 @@ strcmp_until(const char *left, const char *right, int until) {
return (*left - *right);
}
-
/* strdtb(s) - delete trailing blanks in string 's' and return new length
*/
int
-strdtb(s)
- char *s;
-{
+strdtb(char *s) {
char *x = s;
/* scan forward to the null
@@ -129,11 +123,8 @@ strdtb(s)
return (x - s);
}
-
int
-set_debug_flags(flags)
- char *flags;
-{
+set_debug_flags(const char *flags) {
/* debug flags are of the form flag[,flag ...]
*
* if an error occurs, print a message to stdout and return FALSE.
@@ -147,7 +138,7 @@ set_debug_flags(flags)
#else /* DEBUGGING */
- char *pc = flags;
+ const char *pc = flags;
DebugFlags = 0;
@@ -157,11 +148,10 @@ set_debug_flags(flags)
/* try to find debug flag name in our list.
*/
- for ( test = DebugFlagNames, mask = 1;
- *test != NULL && strcmp_until(*test, pc, ',');
- test++, mask <<= 1
- )
- ;
+ for (test = DebugFlagNames, mask = 1;
+ *test != NULL && strcmp_until(*test, pc, ',');
+ test++, mask <<= 1)
+ continue;
if (!*test) {
fprintf(stderr,
@@ -181,7 +171,7 @@ set_debug_flags(flags)
}
if (DebugFlags) {
- int flag;
+ int flag;
fprintf(stderr, "debug flags enabled:");
@@ -196,10 +186,8 @@ set_debug_flags(flags)
#endif /* DEBUGGING */
}
-
void
-set_cron_uid()
-{
+set_cron_uid(void) {
#if defined(BSD) || defined(POSIX)
if (seteuid(ROOT_UID) < OK) {
perror("seteuid");
@@ -213,11 +201,9 @@ set_cron_uid()
#endif
}
-
void
-set_cron_cwd()
-{
- struct stat sb;
+set_cron_cwd(void) {
+ struct stat sb;
/* first check for CRONDIR ("/var/cron" or some such)
*/
@@ -232,7 +218,7 @@ set_cron_cwd()
exit(ERROR_EXIT);
}
}
- if (!(sb.st_mode & S_IFDIR)) {
+ if ((sb.st_mode & S_IFDIR) == 0) {
fprintf(stderr, "'%s' is not a directory, bailing out.\n",
CRONDIR);
exit(ERROR_EXIT);
@@ -256,14 +242,13 @@ set_cron_cwd()
exit(ERROR_EXIT);
}
}
- if (!(sb.st_mode & S_IFDIR)) {
+ if ((sb.st_mode & S_IFDIR) == 0) {
fprintf(stderr, "'%s' is not a directory, bailing out.\n",
SPOOL_DIR);
exit(ERROR_EXIT);
}
}
-
/* acquire_daemonlock() - write our PID into /etc/cron.pid, unless
* another daemon is already running, which we detect here.
*
@@ -272,15 +257,13 @@ set_cron_cwd()
* can rewrite our PID into the PIDFILE after the fork.
*/
void
-acquire_daemonlock(closeflag)
- int closeflag;
-{
- static int fd = -1;
- char buf[3*MAX_FNAME];
- char pidfile[MAX_FNAME];
- char *ep;
- long otherpid;
- ssize_t num;
+acquire_daemonlock(int closeflag) {
+ static int fd = -1;
+ char buf[3*MAX_FNAME];
+ char pidfile[MAX_FNAME];
+ char *ep;
+ long otherpid;
+ ssize_t num;
if (closeflag) {
/* close stashed fd for child so we don't leak it. */
@@ -346,10 +329,8 @@ acquire_daemonlock(closeflag)
/* get_char(file) : like getc() but increment LineNumber on newlines
*/
int
-get_char(file)
- FILE *file;
-{
- int ch;
+get_char(FILE *file) {
+ int ch;
ch = getc(file);
if (ch == '\n')
@@ -357,20 +338,15 @@ get_char(file)
return (ch);
}
-
/* unget_char(ch, file) : like ungetc but do LineNumber processing
*/
void
-unget_char(ch, file)
- int ch;
- FILE *file;
-{
+unget_char(int ch, FILE *file) {
ungetc(ch, file);
if (ch == '\n')
Set_LineNum(LineNumber - 1)
}
-
/* get_string(str, max, file, termstr) : like fgets() but
* (1) has terminator string which should include \n
* (2) will always leave room for the null
@@ -378,13 +354,8 @@ unget_char(ch, file)
* (4) returns EOF or terminating character, whichever
*/
int
-get_string(string, size, file, terms)
- char *string;
- int size;
- FILE *file;
- char *terms;
-{
- int ch;
+get_string(char *string, int size, FILE *file, char *terms) {
+ int ch;
while (EOF != (ch = get_char(file)) && !strchr(terms, ch)) {
if (size > 1) {
@@ -399,14 +370,11 @@ get_string(string, size, file, terms)
return (ch);
}
-
/* skip_comments(file) : read past comment (if any)
*/
void
-skip_comments(file)
- FILE *file;
-{
- int ch;
+skip_comments(FILE *file) {
+ int ch;
while (EOF != (ch = get_char(file))) {
/* ch is now the first character of a line.
@@ -439,16 +407,12 @@ skip_comments(file)
unget_char(ch, file);
}
-
-/* int in_file(char *string, FILE *file)
+/* int in_file(const char *string, FILE *file, int error)
* return TRUE if one of the lines in file matches string exactly,
* FALSE if no lines match, and error on error.
*/
static int
-in_file(string, file, error)
- char *string;
- FILE *file;
- int error;
+in_file(const char *string, FILE *file, int error)
{
char line[MAX_TEMPSTR];
char *endp;
@@ -470,16 +434,13 @@ in_file(string, file, error)
return (FALSE);
}
-
-/* int allowed(char *username)
+/* int allowed(const char *username)
* returns TRUE if (ALLOW_FILE exists and user is listed)
* or (DENY_FILE exists and user is NOT listed)
* or (neither file exists but user=="root" so it's okay)
*/
int
-allowed(username)
- char *username;
-{
+allowed(const char *username) {
FILE *allow = NULL;
FILE *deny = NULL;
int isallowed;
@@ -519,26 +480,20 @@ out:
return (isallowed);
}
-
void
-log_it(username, xpid, event, detail)
- const char *username;
- int xpid;
- const char *event;
- const char *detail;
-{
+log_it(const char *username, PID_T 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;
- size_t msglen;
- TIME_T now = time((TIME_T) 0);
- struct tm *t = localtime(&now);
+ char *msg;
+ size_t msglen;
+ 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)
@@ -584,7 +539,7 @@ log_it(username, xpid, event, detail)
#if defined(SYSLOG)
if (!syslog_open) {
# ifdef LOG_DAEMON
- openlog(ProgramName, LOG_PID, LOG_CRON);
+ openlog(ProgramName, LOG_PID, FACILITY);
# else
openlog(ProgramName, LOG_PID);
# endif
@@ -603,25 +558,25 @@ log_it(username, xpid, event, detail)
#endif
}
-
void
-log_close() {
+log_close(void) {
if (LogFD != ERR) {
close(LogFD);
LogFD = ERR;
}
}
-
-/* two warnings:
+/* char *first_word(char *s, char *t)
+ * return pointer to first word
+ * parameters:
+ * s - string we want the first word of
+ * t - terminators, implicitly including \0
+ * warnings:
* (1) this routine is fairly slow
* (2) it returns a pointer to static storage
*/
char *
-first_word(s, t)
- char *s; /* string we want the first word of */
- char *t; /* terminators, implicitly including \0 */
-{
+first_word(char *s, char *t) {
static char retbuf[2][MAX_TEMPSTR + 1]; /* sure wish C had GC */
static int retsel = 0;
char *rb, *rp;
@@ -646,7 +601,6 @@ first_word(s, t)
return (rb);
}
-
/* warning:
* heavily ascii-dependent.
*/
@@ -681,7 +635,6 @@ mkprint(dst, src, len)
*dst = '\0';
}
-
/* warning:
* returns a pointer to malloc'd storage, you must call free yourself.
*/
@@ -698,7 +651,6 @@ mkprints(src, len)
return (dst);
}
-
#ifdef MAIL_DATE
/* Sat, 27 Feb 1993 11:44:51 -0800 (CST)
* 1234567890123456789012345678901234567
diff --git a/usr.sbin/cron/popen.c b/usr.sbin/cron/popen.c
index 582cf709976..3e5e8344f8c 100644
--- a/usr.sbin/cron/popen.c
+++ b/usr.sbin/cron/popen.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: popen.c,v 1.14 2002/06/23 03:07:19 deraadt Exp $ */
+/* $OpenBSD: popen.c,v 1.15 2002/07/08 18:11:02 millert Exp $ */
/*
* Copyright (c) 1988, 1993, 1994
@@ -34,11 +34,15 @@
*
*/
+/* this came out of the ftpd sources; it's been modified to avoid the
+ * globbing stuff since we don't need it. also execvp instead of execv.
+ */
+
#ifndef lint
#if 0
-static char sccsid[] = "@(#)popen.c 8.3 (Berkeley) 4/6/94";
+static const sccsid[] = "@(#)popen.c 8.3 (Berkeley) 4/6/94";
#else
-static char rcsid[] = "$OpenBSD: popen.c,v 1.14 2002/06/23 03:07:19 deraadt Exp $";
+static const char rcsid[] = "$OpenBSD: popen.c,v 1.15 2002/07/08 18:11:02 millert Exp $";
#endif
#endif /* not lint */
@@ -46,7 +50,6 @@ static char rcsid[] = "$OpenBSD: popen.c,v 1.14 2002/06/23 03:07:19 deraadt Exp
#define MAX_ARGV 100
#define MAX_GARGV 1000
-#define WANT_GLOBBING 0
/*
* Special version of popen which avoids call to shell. This ensures noone
@@ -57,28 +60,20 @@ static PID_T *pids;
static int fds;
FILE *
-cron_popen(program, type, e)
- char *program;
- char *type;
- entry *e;
-{
+cron_popen(char *program, char *type, entry *e) {
char *cp;
FILE *iop;
int argc, pdes[2];
PID_T pid;
char *argv[MAX_ARGV];
-#if WANT_GLOBBING
- char **pop, *gargv[MAX_GARGV];
- int gargc;
-#endif
- if ((*type != 'r' && *type != 'w') || type[1])
+ if ((*type != 'r' && *type != 'w') || type[1] != '\0')
return (NULL);
if (!pids) {
if ((fds = sysconf(_SC_OPEN_MAX)) <= 0)
return (NULL);
- if (!(pids = (PID_T *)malloc((size_t)(fds * sizeof(int)))))
+ if (!(pids = (PID_T *)malloc((size_t)(fds * sizeof(PID_T)))))
return (NULL);
bzero(pids, fds * sizeof(PID_T));
}
@@ -86,45 +81,16 @@ cron_popen(program, type, e)
return (NULL);
/* break up string into pieces */
- for (argc = 0, cp = program;argc < MAX_ARGV-1; cp = NULL)
+ for (argc = 0, cp = program; argc < MAX_ARGV - 1; cp = NULL)
if (!(argv[argc++] = strtok(cp, " \t\n")))
break;
argv[MAX_ARGV-1] = NULL;
-#if WANT_GLOBBING
- /* glob each piece */
- gargv[0] = argv[0];
- for (gargc = argc = 1; argv[argc]; argc++) {
- glob_t gl;
-
- bzero(&gl, sizeof(gl));
- if (glob(argv[argc],
- GLOB_BRACE|GLOB_NOCHECK|GLOB_QUOTE|GLOB_TILDE|GLOB_LIMIT,
- NULL, &gl)) {
- if (gargc < MAX_GARGV-1) {
- gargv[gargc++] = strdup(argv[argc]);
- if (gargv[gargc -1] == NULL)
- fatal ("Out of memory");
- }
-
- } else
- for (pop = gl.gl_pathv; *pop && gargc < MAX_GARGV-1; pop++) {
- gargv[gargc++] = strdup(*pop);
- if (gargv[gargc - 1] == NULL)
- fatal ("Out of memory");
- }
- globfree(&gl);
- }
- gargv[gargc] = NULL;
-#endif
-
- iop = NULL;
-
- switch(pid = fork()) {
+ switch (pid = fork()) {
case -1: /* error */
(void)close(pdes[0]);
(void)close(pdes[1]);
- goto pfree;
+ return (NULL);
/* NOTREACHED */
case 0: /* child */
if (e) {
@@ -166,11 +132,7 @@ cron_popen(program, type, e)
}
(void)close(pdes[1]);
}
-#if WANT_GLOBBING
- execvp(gargv[0], gargv);
-#else
execvp(argv[0], argv);
-#endif
_exit(1);
}
@@ -184,18 +146,11 @@ cron_popen(program, type, e)
}
pids[fileno(iop)] = pid;
-pfree:
-#if WANT_GLOBBING
-for (argc = 1; gargv[argc] != NULL; argc++)
- free(gargv[argc]);
-#endif
return (iop);
}
int
-cron_pclose(iop)
- FILE *iop;
-{
+cron_pclose(FILE *iop) {
int fdes;
PID_T pid;
WAIT_T status;
diff --git a/usr.sbin/cron/structs.h b/usr.sbin/cron/structs.h
index f0a4aee5f10..a0920f7249e 100644
--- a/usr.sbin/cron/structs.h
+++ b/usr.sbin/cron/structs.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: structs.h,v 1.2 2001/02/19 14:33:33 millert Exp $ */
+/* $OpenBSD: structs.h,v 1.3 2002/07/08 18:11:02 millert Exp $ */
/*
* Copyright (c) 1997,2000 by Internet Software Consortium, Inc.
@@ -59,4 +59,3 @@ typedef struct _cron_db {
* variables for the main program, just
* extern them elsewhere.
*/
-
diff --git a/usr.sbin/cron/user.c b/usr.sbin/cron/user.c
index 7ef42d9271d..12f7e375cd0 100644
--- a/usr.sbin/cron/user.c
+++ b/usr.sbin/cron/user.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: user.c,v 1.3 2001/02/18 19:48:36 millert Exp $ */
+/* $OpenBSD: user.c,v 1.4 2002/07/08 18:11:02 millert Exp $ */
/* Copyright 1988,1990,1993,1994 by Paul Vixie
* All rights reserved
*/
@@ -21,7 +21,7 @@
*/
#if !defined(lint) && !defined(LINT)
-static char rcsid[] = "$OpenBSD: user.c,v 1.3 2001/02/18 19:48:36 millert Exp $";
+static const char rcsid[] = "$OpenBSD: user.c,v 1.4 2002/07/08 18:11:02 millert Exp $";
#endif
/* vix 26jan87 [log is in RCS file]