summaryrefslogtreecommitdiffstats
path: root/usr.sbin
diff options
context:
space:
mode:
authormillert <millert@openbsd.org>2003-02-20 20:38:08 +0000
committermillert <millert@openbsd.org>2003-02-20 20:38:08 +0000
commite134e629cd1e299296fd9725b6801def739e4470 (patch)
treece8b3a5892e67fb83e3f096176bb45053eae8987 /usr.sbin
parentbad jmc, did not nroff? (diff)
downloadwireguard-openbsd-e134e629cd1e299296fd9725b6801def739e4470.tar.xz
wireguard-openbsd-e134e629cd1e299296fd9725b6801def739e4470.zip
Sync with ISC cron-current + my at(1) integration.
The at(1) code is now more tightly integrated into the cron codebase.
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/cron/atrun.c91
-rw-r--r--usr.sbin/cron/config.h23
-rw-r--r--usr.sbin/cron/cron.834
-rw-r--r--usr.sbin/cron/cron.c45
-rw-r--r--usr.sbin/cron/crontab.14
-rw-r--r--usr.sbin/cron/crontab.54
-rw-r--r--usr.sbin/cron/crontab.c44
-rw-r--r--usr.sbin/cron/database.c7
-rw-r--r--usr.sbin/cron/do_command.c23
-rw-r--r--usr.sbin/cron/entry.c17
-rw-r--r--usr.sbin/cron/env.c5
-rw-r--r--usr.sbin/cron/externs.h17
-rw-r--r--usr.sbin/cron/funcs.h3
-rw-r--r--usr.sbin/cron/globals.h4
-rw-r--r--usr.sbin/cron/job.c5
-rw-r--r--usr.sbin/cron/macros.h16
-rw-r--r--usr.sbin/cron/misc.c114
-rw-r--r--usr.sbin/cron/pathnames.h58
-rw-r--r--usr.sbin/cron/popen.c26
-rw-r--r--usr.sbin/cron/user.c5
20 files changed, 312 insertions, 233 deletions
diff --git a/usr.sbin/cron/atrun.c b/usr.sbin/cron/atrun.c
index 0af77580d1b..a3d4cdb3770 100644
--- a/usr.sbin/cron/atrun.c
+++ b/usr.sbin/cron/atrun.c
@@ -1,42 +1,39 @@
-/* $OpenBSD: atrun.c,v 1.5 2002/08/10 20:28:51 millert Exp $ */
+/* $OpenBSD: atrun.c,v 1.6 2003/02/20 20:38:08 millert Exp $ */
/*
- * Copyright (c) 2002 Todd C. Miller <Todd.Miller@courtesan.com>
- * All rights reserved.
+ * Copyright (c) 2002-2003 Todd C. Miller <Todd.Miller@courtesan.com>
*
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
+ * 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.
*
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
- * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * THE SOFTWARE IS PROVIDED "AS IS" AND TODD C. MILLER DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL TODD C. MILLER 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[] = "$OpenBSD: atrun.c,v 1.5 2002/08/10 20:28:51 millert Exp $";
+static const char rcsid[] = "$OpenBSD: atrun.c,v 1.6 2003/02/20 20:38:08 millert Exp $";
#endif
#include "cron.h"
+#include <limits.h>
#include <sys/resource.h>
static void unlink_job(at_db *, atjob *);
static void run_job(atjob *, char *);
+#ifndef UID_MAX
+#define UID_MAX INT_MAX
+#endif
+#ifndef GID_MAX
+#define GID_MAX INT_MAX
+#endif
+
/*
* Scan the at jobs dir and build up a list of jobs found.
*/
@@ -55,8 +52,8 @@ scan_atjobs(at_db *old_db, struct timeval *tv)
Debug(DLOAD, ("[%ld] scan_atjobs()\n", (long)getpid()))
- if (stat(_PATH_ATJOBS, &statbuf) != 0) {
- log_it("CRON", getpid(), "CAN'T STAT", _PATH_ATJOBS);
+ if (stat(AT_DIR, &statbuf) != 0) {
+ log_it("CRON", getpid(), "CAN'T STAT", AT_DIR);
return (0);
}
@@ -72,13 +69,11 @@ scan_atjobs(at_db *old_db, struct timeval *tv)
return (0);
}
- if (chdir(_PATH_ATJOBS) != 0 || (atdir = opendir(".")) == NULL) {
+ if (chdir(AT_DIR) != 0 || (atdir = opendir(".")) == NULL) {
if (atdir == NULL)
- log_it("CRON", getpid(), "OPENDIR FAILED",
- _PATH_ATJOBS);
+ log_it("CRON", getpid(), "OPENDIR FAILED", AT_DIR);
else
- log_it("CRON", getpid(), "CHDIR FAILED",
- _PATH_ATJOBS);
+ log_it("CRON", getpid(), "CHDIR FAILED", AT_DIR);
fchdir(cwd);
close(cwd);
return (0);
@@ -99,10 +94,11 @@ scan_atjobs(at_db *old_db, struct timeval *tv)
* QUEUE is a letter that designates the job's queue
*/
l = strtol(file->d_name, &ep, 10);
- if (*ep != '.' || !isalpha(*(ep + 1)) || l < 0 || l >= INT_MAX)
+ if (ep[0] != '.' || !isalpha((unsigned char)ep[1]) || l < 0 ||
+ l >= INT_MAX)
continue;
run_time = (TIME_T)l;
- queue = *(ep + 1);
+ queue = ep[1];
if (!isalpha(queue))
continue;
@@ -157,7 +153,7 @@ scan_atjobs(at_db *old_db, struct timeval *tv)
void
atrun(at_db *db, double batch_maxload, TIME_T now)
{
- char atfile[PATH_MAX];
+ char atfile[MAX_FNAME];
struct stat statbuf;
double la;
atjob *job, *batch;
@@ -169,7 +165,7 @@ atrun(at_db *db, double batch_maxload, TIME_T now)
if (job->run_time > now)
continue;
- snprintf(atfile, sizeof(atfile), "%s/%ld.%c", _PATH_ATJOBS,
+ snprintf(atfile, sizeof(atfile), "%s/%ld.%c", AT_DIR,
(long)job->run_time, job->queue);
if (stat(atfile, &statbuf) != 0)
@@ -197,9 +193,13 @@ atrun(at_db *db, double batch_maxload, TIME_T now)
}
/* Run a single batch job if there is one pending. */
- if (batch != NULL && (batch_maxload == 0.0 ||
- ((getloadavg(&la, 1) == 1) && la <= batch_maxload))) {
- snprintf(atfile, sizeof(atfile), "%s/%ld.%c", _PATH_ATJOBS,
+ if (batch != NULL
+#ifdef HAVE_GETLOADAVG
+ && (batch_maxload == 0.0 ||
+ ((getloadavg(&la, 1) == 1) && la <= batch_maxload))
+#endif
+ ) {
+ snprintf(atfile, sizeof(atfile), "%s/%ld.%c", AT_DIR,
(long)batch->run_time, batch->queue);
run_job(batch, atfile);
unlink_job(db, batch);
@@ -280,12 +280,13 @@ run_job(atjob *job, char *atfile)
log_it("CRON", getpid(), "ORPHANED JOB", atfile);
_exit(ERROR_EXIT);
}
- /* XXX - is this needed now that we do auth_approval? */
+#if (defined(BSD)) && (BSD >= 199103)
if (pw->pw_expire && time(NULL) >= pw->pw_expire) {
log_it(pw->pw_name, getpid(), "ACCOUNT EXPIRED, JOB ABORTED",
atfile);
_exit(ERROR_EXIT);
}
+#endif
/* Sanity checks */
if (fstat(fd, &statbuf) < OK) {
@@ -349,16 +350,16 @@ run_job(atjob *job, char *atfile)
strncmp(buf, "# mail ", 7) != 0)
goto bad_file;
cp = buf + 7;
- while (isspace(*cp))
+ while (isspace((unsigned char)*cp))
cp++;
ep = cp;
- while (!isspace(*ep) && *ep != '\0')
+ while (!isspace((unsigned char)*ep) && *ep != '\0')
ep++;
if (*ep == '\0' || *ep != ' ' || ep - cp >= sizeof(mailto))
goto bad_file;
memcpy(mailto, cp, ep - cp);
mailto[ep - cp] = '\0';
- always_mail = *(ep + 1) == '1';
+ always_mail = ep[1] == '1';
(void)fclose(fp);
if (!safe_p(pw->pw_name, mailto))
@@ -461,7 +462,9 @@ run_job(atjob *job, char *atfile)
#else
setgid(pw->pw_gid);
initgroups(pw->pw_name, pw->pw_gid);
+#if (defined(BSD)) && (BSD >= 199103)
setlogin(pw->pw_name);
+#endif
setuid(pw->pw_uid);
#endif /* LOGIN_CAP */
@@ -539,8 +542,8 @@ run_job(atjob *job, char *atfile)
#ifdef MAIL_DATE
fprintf(mail, "Date: %s\n", arpadate(&StartTime));
#endif /*MAIL_DATE*/
- fprintf(mail, "\nYour \"at\" job on %s\n\"%s\"\n",
- hostname, atfile);
+ fprintf(mail, "\nYour \"at\" job on %s\n\"%s/%s\"\n",
+ hostname, CRONDIR, atfile);
fprintf(mail, "\nproduced the following output:\n\n");
/* Pipe the job's output to sendmail. */
diff --git a/usr.sbin/cron/config.h b/usr.sbin/cron/config.h
index 33944a2ed24..74a30b3b62d 100644
--- a/usr.sbin/cron/config.h
+++ b/usr.sbin/cron/config.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: config.h,v 1.14 2003/02/20 19:12:16 millert Exp $ */
+/* $OpenBSD: config.h,v 1.15 2003/02/20 20:38:08 millert Exp $ */
/* Copyright 1988,1990,1993,1994 by Paul Vixie
* All rights reserved
@@ -21,7 +21,7 @@
* SOFTWARE.
*/
-/* config.h - configurables for ISC cron
+/* config.h - configurables for ISC Cron
*/
/*
@@ -80,8 +80,14 @@
*/
#define SYSLOG /*-*/
+ /* if you want cron to capitalize its name in ps
+ * when running a job. Does not work on SYSV.
+ */
#define CAPITALIZE_FOR_PS /*-*/
+ /* if you have a tm_gmtoff member in struct tm.
+ * If not, we will have to compute the value ourselves.
+ */
#define HAVE_TM_GMTOFF /*-*/
/* if your OS supports a BSD-style login.conf file */
@@ -90,5 +96,16 @@
/* if your OS supports BSD authentication */
#define BSD_AUTH /*-*/
+ /* if your OS has a getloadavg() function */
+#define HAVE_GETLOADAVG /*-*/
+
/* maximum load at which batch jobs will still run */
-#define BATCH_MAXLOAD 1.5
+#define BATCH_MAXLOAD 1.5 /*-*/
+
+ /* Define this to run crontab setgid instead of
+ * setuid root. Group access will be used to read
+ * the tabs/atjobs dirs and the allow/deny files.
+ * If this is not defined then crontab and at
+ * must be setuid root.
+ */
+#define CRON_GROUP "crontab" /*-*/
diff --git a/usr.sbin/cron/cron.8 b/usr.sbin/cron/cron.8
index 515e306da2c..c4dc4ad023d 100644
--- a/usr.sbin/cron/cron.8
+++ b/usr.sbin/cron/cron.8
@@ -1,30 +1,20 @@
.\"
-.\" Copyright (c) 2002 Todd C. Miller <Todd.Miller@courtesan.com>
+.\" Copyright (c) 2002-2003 Todd C. Miller <Todd.Miller@courtesan.com>
.\" All rights reserved.
.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\" notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\" notice, this list of conditions and the following disclaimer in the
-.\" documentation and/or other materials provided with the distribution.
-.\" 3. The name of the author may not be used to endorse or promote products
-.\" derived from this software without specific prior written permission.
+.\" 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.
.\"
-.\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
-.\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
-.\" AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
-.\" THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-.\" EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-.\" PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-.\" OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-.\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
-.\" ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+.\" THE SOFTWARE IS PROVIDED "AS IS" AND TODD C. MILLER DISCLAIMS ALL
+.\" WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+.\" OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL TODD C. MILLER 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.
.\"
-.\" $OpenBSD: cron.8,v 1.20 2003/02/19 23:45:46 millert Exp $
+.\" $OpenBSD: cron.8,v 1.21 2003/02/20 20:38:08 millert Exp $
.\"
.Dd July 6, 2002
.Dt CRON 8
diff --git a/usr.sbin/cron/cron.c b/usr.sbin/cron/cron.c
index 56ecef1c5a1..47ef4dc5f2f 100644
--- a/usr.sbin/cron/cron.c
+++ b/usr.sbin/cron/cron.c
@@ -1,4 +1,5 @@
-/* $OpenBSD: cron.c,v 1.30 2003/02/18 02:43:06 millert Exp $ */
+/* $OpenBSD: cron.c,v 1.31 2003/02/20 20:38:08 millert Exp $ */
+
/* Copyright 1988,1990,1993,1994 by Paul Vixie
* All rights reserved
*/
@@ -21,14 +22,12 @@
*/
#if !defined(lint) && !defined(LINT)
-static const char rcsid[] = "$OpenBSD: cron.c,v 1.30 2003/02/18 02:43:06 millert Exp $";
+static const char rcsid[] = "$OpenBSD: cron.c,v 1.31 2003/02/20 20:38:08 millert Exp $";
#endif
#define MAIN_PROGRAM
#include "cron.h"
-#include <sys/socket.h>
-#include <sys/un.h>
enum timejump { negative, small, medium, large };
@@ -88,19 +87,19 @@ main(int argc, char *argv[]) {
(void) sigaction(SIGCHLD, &sact, NULL);
sact.sa_handler = sighup_handler;
(void) sigaction(SIGHUP, &sact, NULL);
- sact.sa_handler = SIG_IGN;
- (void) sigaction(SIGPIPE, &sact, NULL);
- (void) sigaction(SIGUSR1, &sact, NULL); /* XXX */
sact.sa_handler = quit;
(void) sigaction(SIGINT, &sact, NULL);
(void) sigaction(SIGTERM, &sact, NULL);
+ sact.sa_handler = SIG_IGN;
+ (void) sigaction(SIGPIPE, &sact, NULL);
+ (void) sigaction(SIGUSR1, &sact, NULL); /* XXX */
acquire_daemonlock(0);
set_cron_uid();
set_cron_cwd();
- if (putenv("PATH="_PATH_DEFPATH) == -1) {
- log_it("CRON",getpid(),"DEATH","can't malloc");
+ if (putenv("PATH="_PATH_DEFPATH) < 0) {
+ log_it("CRON", getpid(), "DEATH", "can't malloc");
exit(1);
}
@@ -144,7 +143,7 @@ main(int argc, char *argv[]) {
at_database.tail = NULL;
at_database.mtime = (time_t) 0;
scan_atjobs(&at_database, NULL);
- set_time(1);
+ set_time(TRUE);
run_reboot_jobs(&database);
timeRunning = virtualTime = clockTime;
@@ -165,7 +164,7 @@ main(int argc, char *argv[]) {
/* ... wait for the time (in minutes) to change ... */
do {
cron_sleep(timeRunning + 1);
- set_time(0);
+ set_time(FALSE);
} while (clockTime == timeRunning);
timeRunning = clockTime;
@@ -232,7 +231,7 @@ main(int argc, char *argv[]) {
virtualTime++;
find_jobs(virtualTime, &database,
FALSE, TRUE);
- set_time(0);
+ set_time(FALSE);
} while (virtualTime< timeRunning &&
clockTime == timeRunning);
break;
@@ -326,8 +325,8 @@ find_jobs(int vtime, cron_db *db, int doWild, int doNonWild) {
for (u = db->head; u != NULL; u = u->next) {
for (e = u->crontab; e != NULL; e = e->next) {
Debug(DSCH|DEXT, ("user [%s:%ld:%ld:...] cmd=\"%s\"\n",
- e->pwd->pw_name, (long)e->pwd->pw_uid,
- (long)e->pwd->pw_gid, e->cmd))
+ e->pwd->pw_name, (long)e->pwd->pw_uid,
+ (long)e->pwd->pw_gid, e->cmd))
if (bit_test(e->minute, minute) &&
bit_test(e->hour, hour) &&
bit_test(e->month, month) &&
@@ -352,16 +351,18 @@ find_jobs(int vtime, cron_db *db, int doWild, int doNonWild) {
*/
static void
set_time(int initialize) {
- struct tm *tm;
+ struct tm tm;
static int isdst;
StartTime = time(NULL);
/* We adjust the time to GMT so we can catch DST changes. */
- tm = localtime(&StartTime);
- if (initialize || tm->tm_isdst != isdst) {
- isdst = tm->tm_isdst;
- GMToff = get_gmtoff(&StartTime, tm);
+ tm = *localtime(&StartTime);
+ if (initialize || tm.tm_isdst != isdst) {
+ isdst = tm.tm_isdst;
+ GMToff = get_gmtoff(&StartTime, &tm);
+ Debug(DSCH, ("[%ld] GMToff=%ld\n",
+ (long)getpid(), (long)GMToff))
}
clockTime = (StartTime + GMToff) / (time_t)SECONDS_PER_MINUTE;
}
@@ -374,7 +375,7 @@ cron_sleep(int target) {
int fd, nfds;
unsigned char poke;
struct timeval t1, t2, tv;
- struct sockaddr_un sun;
+ struct sockaddr_un s_un;
socklen_t sunlen;
static fd_set *fdsr;
@@ -404,7 +405,7 @@ cron_sleep(int target) {
if (nfds > 0) {
Debug(DSCH, ("[%ld] Got a poke on the socket\n",
(long)getpid()))
- fd = accept(cronSock, (struct sockaddr *)&sun, &sunlen);
+ fd = accept(cronSock, (struct sockaddr *)&s_un, &sunlen);
if (fd >= 0) {
(void) read(fd, &poke, 1);
close(fd);
@@ -464,7 +465,7 @@ quit(int x) {
}
static void
-sigchld_reaper() {
+sigchld_reaper(void) {
WAIT_T waiter;
PID_T pid;
diff --git a/usr.sbin/cron/crontab.1 b/usr.sbin/cron/crontab.1
index 50b3616f262..be73a0b7c32 100644
--- a/usr.sbin/cron/crontab.1
+++ b/usr.sbin/cron/crontab.1
@@ -2,6 +2,8 @@
.\" * All rights reserved
.\" */
.\"
+.\" Copyright (c) 1997,2000 by Internet Software Consortium, Inc.
+.\"
.\" 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.
@@ -15,7 +17,7 @@
.\" ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
.\" SOFTWARE.
.\"
-.\" $OpenBSD: crontab.1,v 1.18 2003/02/20 19:12:16 millert Exp $
+.\" $OpenBSD: crontab.1,v 1.19 2003/02/20 20:38:08 millert Exp $
.\"
.Dd June 8, 1999
.Dt CRONTAB 1
diff --git a/usr.sbin/cron/crontab.5 b/usr.sbin/cron/crontab.5
index 089c68e9fa3..2eeb0653bf1 100644
--- a/usr.sbin/cron/crontab.5
+++ b/usr.sbin/cron/crontab.5
@@ -2,6 +2,8 @@
.\" * All rights reserved
.\" */
.\"
+.\" Copyright (c) 1997,2000 by Internet Software Consortium, Inc.
+.\"
.\" 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.
@@ -15,7 +17,7 @@
.\" ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
.\" SOFTWARE.
.\"
-.\" $OpenBSD: crontab.5,v 1.17 2002/07/08 18:11:02 millert Exp $
+.\" $OpenBSD: crontab.5,v 1.18 2003/02/20 20:38:08 millert Exp $
.\"
.Dd June 8, 1999
.Dt CRONTAB 5
diff --git a/usr.sbin/cron/crontab.c b/usr.sbin/cron/crontab.c
index 9accc8d24d9..151c418004a 100644
--- a/usr.sbin/cron/crontab.c
+++ b/usr.sbin/cron/crontab.c
@@ -1,4 +1,5 @@
-/* $OpenBSD: crontab.c,v 1.39 2003/02/20 19:12:16 millert Exp $ */
+/* $OpenBSD: crontab.c,v 1.40 2003/02/20 20:38:08 millert Exp $ */
+
/* Copyright 1988,1990,1993,1994 by Paul Vixie
* All rights reserved
*/
@@ -21,7 +22,7 @@
*/
#if !defined(lint) && !defined(LINT)
-static char const rcsid[] = "$OpenBSD: crontab.c,v 1.39 2003/02/20 19:12:16 millert Exp $";
+static char const rcsid[] = "$OpenBSD: crontab.c,v 1.40 2003/02/20 20:38:08 millert Exp $";
#endif
/* crontab - install and manage per-user crontab files
@@ -32,8 +33,6 @@ static char const rcsid[] = "$OpenBSD: crontab.c,v 1.39 2003/02/20 19:12:16 mill
#define MAIN_PROGRAM
#include "cron.h"
-#include <sys/socket.h>
-#include <sys/un.h>
#define NHEADER_LINES 3
@@ -56,7 +55,6 @@ static struct passwd *pw;
static void list_cmd(void),
delete_cmd(void),
edit_cmd(void),
- poke_daemon(void),
check_error(const char *),
parse_args(int c, char *v[]),
die(int);
@@ -88,7 +86,7 @@ main(int argc, char *argv[]) {
#endif
parse_args(argc, argv); /* sets many globals, opens a file */
set_cron_cwd();
- if (!allowed(RealUser, ALLOW_FILE, DENY_FILE)) {
+ if (!allowed(RealUser, CRON_ALLOW, CRON_DENY)) {
fprintf(stderr,
"You (%s) are not allowed to use this program (%s)\n",
User, ProgramName);
@@ -273,7 +271,7 @@ delete_cmd(void) {
perror(n);
exit(ERROR_EXIT);
}
- poke_daemon();
+ poke_daemon(SPOOL_DIR, RELOAD_CRON);
}
static void
@@ -624,7 +622,7 @@ replace_cmd(void) {
TempFilename[0] = '\0';
log_it(RealUser, Pid, "REPLACE", User);
- poke_daemon();
+ poke_daemon(SPOOL_DIR, RELOAD_CRON);
done:
(void) signal(SIGHUP, SIG_DFL);
@@ -638,36 +636,6 @@ done:
}
static void
-poke_daemon() {
- int sock, flags;
- unsigned char poke;
- struct sockaddr_un sun;
-
- if (utime(SPOOL_DIR, NULL) < OK) {
- fprintf(stderr, "crontab: can't update mtime on spooldir\n");
- perror(SPOOL_DIR);
- return;
- }
-
- /* Failure to poke the daemon socket is not a fatal error. */
- (void) signal(SIGPIPE, SIG_IGN);
- if (glue_strings(sun.sun_path, sizeof sun.sun_path, SPOOL_DIR,
- CRONSOCK, '/')) {
- sun.sun_family = AF_UNIX;
- sun.sun_len = SUN_LEN(&sun);
- if ((sock = socket(AF_UNIX, SOCK_STREAM, 0)) >= 0 &&
- connect(sock, (struct sockaddr *)&sun, sizeof(sun)) == 0) {
- poke = RELOAD_CRON;
- write(sock, &poke, 1);
- close(sock);
- } else
- fprintf(stderr, "Warning, cron does not appear to be running.\n");
-
- }
- (void) signal(SIGPIPE, SIG_DFL);
-}
-
-static void
die(int x) {
if (TempFilename[0])
(void) unlink(TempFilename);
diff --git a/usr.sbin/cron/database.c b/usr.sbin/cron/database.c
index ff5ad462c50..52668b2ba63 100644
--- a/usr.sbin/cron/database.c
+++ b/usr.sbin/cron/database.c
@@ -1,4 +1,5 @@
-/* $OpenBSD: database.c,v 1.11 2002/08/10 20:28:51 millert Exp $ */
+/* $OpenBSD: database.c,v 1.12 2003/02/20 20:38:08 millert Exp $ */
+
/* Copyright 1988,1990,1993,1994 by Paul Vixie
* All rights reserved
*/
@@ -21,7 +22,7 @@
*/
#if !defined(lint) && !defined(LINT)
-static char const rcsid[] = "$OpenBSD: database.c,v 1.11 2002/08/10 20:28:51 millert Exp $";
+static char const rcsid[] = "$OpenBSD: database.c,v 1.12 2003/02/20 20:38:08 millert Exp $";
#endif
/* vix 26jan87 [RCS has the log]
@@ -212,7 +213,7 @@ process_crontab(const char *uname, const char *fname, const char *tabname,
log_it(fname, getpid(), "BAD FILE MODE", tabname);
goto next_crontab;
}
- if (statbuf->st_uid != 0 && (pw == NULL ||
+ if (statbuf->st_uid != ROOT_UID && (pw == NULL ||
statbuf->st_uid != pw->pw_uid || strcmp(uname, pw->pw_name) != 0)) {
log_it(fname, getpid(), "WRONG FILE OWNER", tabname);
goto next_crontab;
diff --git a/usr.sbin/cron/do_command.c b/usr.sbin/cron/do_command.c
index 6eb2c5388a2..05363d67b95 100644
--- a/usr.sbin/cron/do_command.c
+++ b/usr.sbin/cron/do_command.c
@@ -1,4 +1,5 @@
-/* $OpenBSD: do_command.c,v 1.22 2002/08/08 18:17:50 millert Exp $ */
+/* $OpenBSD: do_command.c,v 1.23 2003/02/20 20:38:08 millert Exp $ */
+
/* Copyright 1988,1990,1993,1994 by Paul Vixie
* All rights reserved
*/
@@ -21,7 +22,7 @@
*/
#if !defined(lint) && !defined(LINT)
-static char const rcsid[] = "$OpenBSD: do_command.c,v 1.22 2002/08/08 18:17:50 millert Exp $";
+static char const rcsid[] = "$OpenBSD: do_command.c,v 1.23 2003/02/20 20:38:08 millert Exp $";
#endif
#include "cron.h"
@@ -63,8 +64,7 @@ do_command(entry *e, user *u) {
static void
child_process(entry *e, user *u) {
int stdin_pipe[2], stdout_pipe[2];
- char *usernm;
- char *input_data, *mailto;
+ char *input_data, *usernm, *mailto;
int children = 0;
Debug(DPROC, ("[%ld] child_process('%s')\n", (long)getpid(), e->cmd))
@@ -208,7 +208,9 @@ child_process(entry *e, user *u) {
_exit(ERROR_EXIT);
}
if (setusercontext(lc, e->pwd, e->pwd->pw_uid, LOGIN_SETALL) < 0) {
- fprintf(stderr, "setusercontext failed for %s\n", e->pwd->pw_name);
+ fprintf(stderr,
+ "setusercontext failed for %s\n",
+ e->pwd->pw_name);
_exit(ERROR_EXIT);
}
#ifdef BSD_AUTH
@@ -242,7 +244,9 @@ child_process(entry *e, user *u) {
#else
setgid(e->pwd->pw_gid);
initgroups(usernm, e->pwd->pw_gid);
+#if (defined(BSD)) && (BSD >= 199103)
setlogin(usernm);
+#endif /* BSD */
setuid(e->pwd->pw_uid); /* we aren't root after this... */
#endif /* LOGIN_CAP */
@@ -380,7 +384,7 @@ child_process(entry *e, user *u) {
/* get name of recipient. this is MAILTO if set to a
* valid local username; USER otherwise.
*/
- if (mailto && safe_p(usernm, mailto)) {
+ if (mailto) {
/* MAILTO was present in the environment
*/
if (!*mailto) {
@@ -399,7 +403,7 @@ child_process(entry *e, user *u) {
* up the mail command and subjects and stuff...
*/
- if (mailto) {
+ if (mailto && safe_p(usernm, mailto)) {
char **env;
char mailcmd[MAX_COMMAND];
char hostname[MAXHOSTNAMELEN];
@@ -490,10 +494,9 @@ child_process(entry *e, user *u) {
Debug(DPROC, ("[%ld] waiting for grandchild #%d to finish\n",
(long)getpid(), children))
- pid = wait(&waiter);
+ while ((pid = wait(&waiter)) < OK && errno == EINTR)
+ ;
if (pid < OK) {
- if (errno == EINTR)
- continue;
Debug(DPROC,
("[%ld] no more grandchildren--mail written?\n",
(long)getpid()))
diff --git a/usr.sbin/cron/entry.c b/usr.sbin/cron/entry.c
index 32d96d4577f..6a6863f3e53 100644
--- a/usr.sbin/cron/entry.c
+++ b/usr.sbin/cron/entry.c
@@ -1,4 +1,5 @@
-/* $OpenBSD: entry.c,v 1.15 2002/08/10 20:28:51 millert Exp $ */
+/* $OpenBSD: entry.c,v 1.16 2003/02/20 20:38:08 millert Exp $ */
+
/*
* Copyright 1988,1990,1993,1994 by Paul Vixie
* All rights reserved
@@ -22,7 +23,7 @@
*/
#if !defined(lint) && !defined(LINT)
-static char const rcsid[] = "$OpenBSD: entry.c,v 1.15 2002/08/10 20:28:51 millert Exp $";
+static char const rcsid[] = "$OpenBSD: entry.c,v 1.16 2003/02/20 20:38:08 millert Exp $";
#endif
/* vix 26jan87 [RCS'd; rest of log is in RCS file]
@@ -248,7 +249,8 @@ load_entry(FILE *file, void (*error_func)(), struct passwd *pw, char **envp) {
goto eof;
}
- if ((pw = getpwnam(username)) == NULL) {
+ pw = getpwnam(username);
+ if (pw == NULL) {
ecode = e_username;
goto eof;
}
@@ -294,7 +296,8 @@ load_entry(FILE *file, void (*error_func)(), struct passwd *pw, char **envp) {
} else
log_it("CRON", getpid(), "error", "can't set HOME");
}
-#ifdef LOGIN_CAP
+#ifndef LOGIN_CAP
+ /* If login.conf is in use we will get the default PATH later. */
if (!env_get("PATH", e->envp)) {
if (glue_strings(envstr, sizeof envstr, "PATH",
_PATH_DEFPATH, '=')) {
@@ -316,7 +319,7 @@ load_entry(FILE *file, void (*error_func)(), struct passwd *pw, char **envp) {
e->envp = tenvp;
} else
log_it("CRON", getpid(), "error", "can't set LOGNAME");
-#if defined(BSD)
+#if defined(BSD) || defined(__linux)
if (glue_strings(envstr, sizeof envstr, "USER",
pw->pw_name, '=')) {
if ((tenvp = env_set(e->envp, envstr)) == NULL) {
@@ -519,13 +522,13 @@ get_number(int *numptr, int low, const char *names[], char ch, FILE *file) {
pc = temp;
len = 0;
all_digits = TRUE;
- while (isalnum(ch)) {
+ while (isalnum((unsigned char)ch)) {
if (++len >= MAX_TEMPSTR)
return (EOF);
*pc++ = ch;
- if (!isdigit(ch))
+ if (!isdigit((unsigned char)ch))
all_digits = FALSE;
ch = get_char(file);
diff --git a/usr.sbin/cron/env.c b/usr.sbin/cron/env.c
index 51070680e14..6599c5d0d5d 100644
--- a/usr.sbin/cron/env.c
+++ b/usr.sbin/cron/env.c
@@ -1,4 +1,5 @@
-/* $OpenBSD: env.c,v 1.13 2002/07/11 20:15:40 millert Exp $ */
+/* $OpenBSD: env.c,v 1.14 2003/02/20 20:38:08 millert Exp $ */
+
/* Copyright 1988,1990,1993,1994 by Paul Vixie
* All rights reserved
*/
@@ -21,7 +22,7 @@
*/
#if !defined(lint) && !defined(LINT)
-static char const rcsid[] = "$OpenBSD: env.c,v 1.13 2002/07/11 20:15:40 millert Exp $";
+static char const rcsid[] = "$OpenBSD: env.c,v 1.14 2003/02/20 20:38:08 millert Exp $";
#endif
#include "cron.h"
diff --git a/usr.sbin/cron/externs.h b/usr.sbin/cron/externs.h
index 9ede7f9644b..d8d1268e430 100644
--- a/usr.sbin/cron/externs.h
+++ b/usr.sbin/cron/externs.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: externs.h,v 1.8 2002/07/17 22:10:56 millert Exp $ */
+/* $OpenBSD: externs.h,v 1.9 2003/02/20 20:38:08 millert Exp $ */
/* Copyright 1993,1994 by Paul Vixie
* All rights reserved
@@ -25,13 +25,13 @@
#include <sys/param.h>
#include <sys/types.h>
-#if !defined(AIX) && !defined(UNICOS)
#include <sys/time.h>
-#endif
#include <sys/wait.h>
#include <sys/fcntl.h>
#include <sys/file.h>
#include <sys/stat.h>
+#include <sys/socket.h>
+#include <sys/un.h>
#include <bitstring.h>
#include <ctype.h>
@@ -42,7 +42,6 @@
#include <errno.h>
#include <fcntl.h>
#include <grp.h>
-#include <limits.h>
#include <locale.h>
#include <pwd.h>
#include <signal.h>
@@ -59,11 +58,11 @@
#endif
#if defined(LOGIN_CAP)
-#include <login_cap.h>
+# include <login_cap.h>
#endif /*LOGIN_CAP*/
#if defined(BSD_AUTH)
-#include <bsd_auth.h>
+# include <bsd_auth.h>
#endif /*BSD_AUTH*/
#define DIR_T struct dirent
@@ -77,13 +76,13 @@ extern char *tzname[2];
#endif
#define TZONE(tm) tzname[(tm).tm_isdst]
-#if (BSD >= 198606)
+#if (defined(BSD)) && (BSD >= 198606) || defined(__linux)
# define HAVE_FCHOWN
# define HAVE_FCHMOD
#endif
-#if (BSD >= 199103)
-# define HAVE_SAVED_GIDS
+#if (defined(BSD)) && (BSD >= 199103) || defined(__linux)
+# define HAVE_SAVED_UIDS
#endif
#define MY_UID(pw) getuid()
diff --git a/usr.sbin/cron/funcs.h b/usr.sbin/cron/funcs.h
index e7dc347d500..63c71ee0f46 100644
--- a/usr.sbin/cron/funcs.h
+++ b/usr.sbin/cron/funcs.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: funcs.h,v 1.9 2003/02/20 19:12:16 millert Exp $ */
+/* $OpenBSD: funcs.h,v 1.10 2003/02/20 20:38:08 millert Exp $ */
/*
* Copyright (c) 1997,2000 by Internet Software Consortium, Inc.
@@ -39,6 +39,7 @@ void set_cron_uid(void),
skip_comments(FILE *),
log_it(const char *, int, const char *, const char *),
log_close(void),
+ poke_daemon(const char *, unsigned char),
atrun(at_db *, double, time_t);
int job_runqueue(void),
diff --git a/usr.sbin/cron/globals.h b/usr.sbin/cron/globals.h
index edd3d4a82d7..9ea6ad7558a 100644
--- a/usr.sbin/cron/globals.h
+++ b/usr.sbin/cron/globals.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: globals.h,v 1.5 2003/02/17 18:40:11 millert Exp $ */
+/* $OpenBSD: globals.h,v 1.6 2003/02/20 20:38:08 millert Exp $ */
/*
* Copyright (c) 1997,2000 by Internet Software Consortium, Inc.
@@ -70,5 +70,5 @@ XTRN const char *DebugFlagNames[]
#endif
;
#else
-#define DebugFlags 0
+#define DebugFlags 0
#endif /* DEBUGGING */
diff --git a/usr.sbin/cron/job.c b/usr.sbin/cron/job.c
index 9e8a15fdb50..e5ddc7d9101 100644
--- a/usr.sbin/cron/job.c
+++ b/usr.sbin/cron/job.c
@@ -1,4 +1,5 @@
-/* $OpenBSD: job.c,v 1.5 2002/07/11 20:15:40 millert Exp $ */
+/* $OpenBSD: job.c,v 1.6 2003/02/20 20:38:08 millert Exp $ */
+
/* Copyright 1988,1990,1993,1994 by Paul Vixie
* All rights reserved
*/
@@ -21,7 +22,7 @@
*/
#if !defined(lint) && !defined(LINT)
-static char const rcsid[] = "$OpenBSD: job.c,v 1.5 2002/07/11 20:15:40 millert Exp $";
+static char const rcsid[] = "$OpenBSD: job.c,v 1.6 2003/02/20 20:38:08 millert Exp $";
#endif
#include "cron.h"
diff --git a/usr.sbin/cron/macros.h b/usr.sbin/cron/macros.h
index 452334c0ec2..959a6d3cffc 100644
--- a/usr.sbin/cron/macros.h
+++ b/usr.sbin/cron/macros.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: macros.h,v 1.3 2002/07/15 19:13:29 millert Exp $ */
+/* $OpenBSD: macros.h,v 1.4 2003/02/20 20:38:08 millert Exp $ */
/*
* Copyright (c) 1997,2000 by Internet Software Consortium, Inc.
@@ -94,14 +94,14 @@
}
/* Data values used on cron socket */
-#define RELOAD_CRON 0x2
-#define RELOAD_AT 0x4
+#define RELOAD_CRON 0x2
+#define RELOAD_AT 0x4
#ifdef HAVE_TM_GMTOFF
-#define get_gmtoff(c, t) (t->tm_gmtoff)
+#define get_gmtoff(c, t) ((t)->tm_gmtoff)
#endif
-#define SECONDS_PER_MINUTE 60
+#define SECONDS_PER_MINUTE 60
#define FIRST_MINUTE 0
#define LAST_MINUTE 59
@@ -123,9 +123,3 @@
#define FIRST_DOW 0
#define LAST_DOW 7
#define DOW_COUNT (LAST_DOW - FIRST_DOW + 1)
-
- /* each user's crontab will be held as a list of
- * the following structure.
- *
- * These are the cron commands.
- */
diff --git a/usr.sbin/cron/misc.c b/usr.sbin/cron/misc.c
index b234f1cabeb..0cad49f7a82 100644
--- a/usr.sbin/cron/misc.c
+++ b/usr.sbin/cron/misc.c
@@ -1,4 +1,5 @@
-/* $OpenBSD: misc.c,v 1.25 2003/02/20 19:12:16 millert Exp $ */
+/* $OpenBSD: misc.c,v 1.26 2003/02/20 20:38:08 millert Exp $ */
+
/* Copyright 1988,1990,1993,1994 by Paul Vixie
* All rights reserved
*/
@@ -21,7 +22,7 @@
*/
#if !defined(lint) && !defined(LINT)
-static char const rcsid[] = "$OpenBSD: misc.c,v 1.25 2003/02/20 19:12:16 millert Exp $";
+static char const rcsid[] = "$OpenBSD: misc.c,v 1.26 2003/02/20 20:38:08 millert Exp $";
#endif
/* vix 26jan87 [RCS has the rest of the log]
@@ -29,8 +30,7 @@ static char const rcsid[] = "$OpenBSD: misc.c,v 1.25 2003/02/20 19:12:16 millert
*/
#include "cron.h"
-#include <sys/socket.h>
-#include <sys/un.h>
+#include <limits.h>
#if defined(SYSLOG) && defined(LOG_FILE)
# undef LOG_FILE
@@ -114,7 +114,7 @@ strdtb(char *s) {
* or the last non-blank in the string, whichever comes first.
*/
do {x--;}
- while (x >= s && isspace(*x));
+ while (x >= s && isspace((unsigned char)*x));
/* one character beyond where we stopped above is where the null
* goes.
@@ -208,12 +208,16 @@ set_cron_uid(void) {
void
set_cron_cwd(void) {
struct stat sb;
+ struct group *grp = NULL;
+#ifdef CRON_GROUP
+ grp = getgrnam(CRON_GROUP);
+#endif
/* first check for CRONDIR ("/var/cron" or some such)
*/
if (stat(CRONDIR, &sb) < OK && errno == ENOENT) {
perror(CRONDIR);
- if (OK == mkdir(CRONDIR, 0700)) {
+ if (OK == mkdir(CRONDIR, 0710)) {
fprintf(stderr, "%s: created\n", CRONDIR);
stat(CRONDIR, &sb);
} else {
@@ -222,7 +226,7 @@ set_cron_cwd(void) {
exit(ERROR_EXIT);
}
}
- if ((sb.st_mode & S_IFDIR) == 0) {
+ if (!S_ISDIR(sb.st_mode)) {
fprintf(stderr, "'%s' is not a directory, bailing out.\n",
CRONDIR);
exit(ERROR_EXIT);
@@ -246,11 +250,42 @@ set_cron_cwd(void) {
exit(ERROR_EXIT);
}
}
- if ((sb.st_mode & S_IFDIR) == 0) {
+ if (!S_ISDIR(sb.st_mode)) {
fprintf(stderr, "'%s' is not a directory, bailing out.\n",
SPOOL_DIR);
exit(ERROR_EXIT);
}
+ if (grp != NULL) {
+ if (sb.st_gid != grp->gr_gid)
+ chown(SPOOL_DIR, -1, grp->gr_gid);
+ if (sb.st_mode != 01730)
+ chmod(SPOOL_DIR, 01730);
+ }
+
+ /* finally, look at AT_DIR ("atjobs" or some such)
+ */
+ if (stat(AT_DIR, &sb) < OK && errno == ENOENT) {
+ perror(AT_DIR);
+ if (OK == mkdir(AT_DIR, 0700)) {
+ fprintf(stderr, "%s: created\n", AT_DIR);
+ stat(AT_DIR, &sb);
+ } else {
+ fprintf(stderr, "%s: ", AT_DIR);
+ perror("mkdir");
+ exit(ERROR_EXIT);
+ }
+ }
+ if (!S_ISDIR(sb.st_mode)) {
+ fprintf(stderr, "'%s' is not a directory, bailing out.\n",
+ AT_DIR);
+ exit(ERROR_EXIT);
+ }
+ if (grp != NULL) {
+ if (sb.st_gid != grp->gr_gid)
+ chown(AT_DIR, -1, grp->gr_gid);
+ if (sb.st_mode != 01770)
+ chmod(AT_DIR, 01770);
+ }
}
/* acquire_daemonlock() - write our PID into /etc/cron.pid, unless
@@ -423,9 +458,9 @@ in_file(const char *string, FILE *file, int error)
if (*endp != '\n')
return (error);
*endp = '\0';
+ if (0 == strcmp(line, string))
+ return (TRUE);
}
- if (0 == strcmp(line, string))
- return (TRUE);
}
if (ferror(file))
return (error);
@@ -662,16 +697,21 @@ arpadate(clock)
}
#endif /*MAIL_DATE*/
-#ifdef HAVE_SAVED_GIDS
+#ifdef HAVE_SAVED_UIDS
static gid_t save_egid;
int swap_gids() { save_egid = getegid(); return (setegid(getgid())); }
int swap_gids_back() { return (setegid(save_egid)); }
-#else /*HAVE_SAVED_GIDS*/
+#else /*HAVE_SAVED_UIDS*/
int swap_gids() { return (setregid(getegid(), getgid())); }
int swap_gids_back() { return (swap_gids()); }
-#endif /*HAVE_SAVED_GIDS*/
+#endif /*HAVE_SAVED_UIDS*/
-/* Return the offset from GMT in seconds (algorithm taken from sendmail). */
+/* Return the offset from GMT in seconds (algorithm taken from sendmail).
+ *
+ * warning:
+ * clobbers the static storage space used by localtime() and gmtime().
+ * If the local pointer is non-NULL it *must* point to a local copy.
+ */
#ifndef HAVE_TM_GMTOFF
long get_gmtoff(time_t *clock, struct tm *local)
{
@@ -708,7 +748,7 @@ open_socket()
{
int sock;
mode_t omask;
- struct sockaddr_un sun;
+ struct sockaddr_un s_un;
sock = socket(AF_UNIX, SOCK_STREAM, 0);
if (sock == -1) {
@@ -717,18 +757,20 @@ open_socket()
log_it("CRON", getpid(), "DEATH", "can't create socket");
exit(ERROR_EXIT);
}
- if (!glue_strings(sun.sun_path, sizeof sun.sun_path, SPOOL_DIR,
+ if (!glue_strings(s_un.sun_path, sizeof s_un.sun_path, SPOOL_DIR,
CRONSOCK, '/')) {
fprintf(stderr, "%s/%s: path too long\n", SPOOL_DIR, CRONSOCK);
log_it("CRON", getpid(), "DEATH", "path too long");
exit(ERROR_EXIT);
}
- unlink(sun.sun_path);
- sun.sun_family = AF_UNIX;
- sun.sun_len = SUN_LEN(&sun);
+ unlink(s_un.sun_path);
+ s_un.sun_family = AF_UNIX;
+#ifdef SUN_LEN
+ s_un.sun_len = SUN_LEN(&s_un);
+#endif
omask = umask(007);
- if (bind(sock, (struct sockaddr *)&sun, sizeof(sun))) {
+ if (bind(sock, (struct sockaddr *)&s_un, sizeof(s_un))) {
fprintf(stderr, "%s: can't bind socket: %s\n",
ProgramName, strerror(errno));
log_it("CRON", getpid(), "DEATH", "can't bind socket");
@@ -740,8 +782,38 @@ open_socket()
log_it("CRON", getpid(), "DEATH", "can't listen on socket");
exit(ERROR_EXIT);
}
- chmod(sun.sun_path, 0660);
+ chmod(s_un.sun_path, 0660);
umask(omask);
return(sock);
}
+
+void
+poke_daemon(const char *spool_dir, unsigned char cookie) {
+ int sock = -1;
+ struct sockaddr_un s_un;
+
+ if (utime(spool_dir, NULL) < 0) {
+ fprintf(stderr, "%s: unable to update mtime on %s\n",
+ ProgramName, spool_dir);
+ return;
+ }
+
+ if (glue_strings(s_un.sun_path, sizeof s_un.sun_path, SPOOL_DIR,
+ CRONSOCK, '/')) {
+ s_un.sun_family = AF_UNIX;
+#ifdef SUN_LEN
+ s_un.sun_len = SUN_LEN(&s_un);
+#endif
+ (void) signal(SIGPIPE, SIG_IGN);
+ if ((sock = socket(AF_UNIX, SOCK_STREAM, 0)) >= 0 &&
+ connect(sock, (struct sockaddr *)&s_un, sizeof(s_un)) == 0)
+ write(sock, &cookie, 1);
+ else
+ fprintf(stderr, "%s: warning, cron does not appear to be "
+ "running.\n", ProgramName);
+ if (sock >= 0)
+ close(sock);
+ (void) signal(SIGPIPE, SIG_DFL);
+ }
+}
diff --git a/usr.sbin/cron/pathnames.h b/usr.sbin/cron/pathnames.h
index 2164d99fd53..e1a2ce1be7b 100644
--- a/usr.sbin/cron/pathnames.h
+++ b/usr.sbin/cron/pathnames.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: pathnames.h,v 1.9 2003/02/19 22:11:42 millert Exp $ */
+/* $OpenBSD: pathnames.h,v 1.10 2003/02/20 20:38:08 millert Exp $ */
/* Copyright 1993,1994 by Paul Vixie
* All rights reserved
@@ -27,10 +27,10 @@
#if (defined(BSD)) && (BSD >= 199103) || defined(__linux) || defined(AIX)
# include <paths.h>
#endif /*BSD*/
-
+
#ifndef CRONDIR
/* CRONDIR is where cron(8) and crontab(1) both chdir
- * to; SPOOL_DIR, ALLOW_FILE, DENY_FILE, and LOG_FILE
+ * to; SPOOL_DIR, CRON_ALLOW, CRON_DENY, and LOG_FILE
* are all relative to this directory.
*/
#define CRONDIR "/var/cron"
@@ -46,22 +46,39 @@
*/
#define SPOOL_DIR "tabs"
- /* CRONSOCK is the name of the socket used by crontab
- * to poke cron while it is sleeping to re-read the
- * cron spool files. It lives in the spool directory.
+ /* ATDIR is where the at jobs live (relative to CRONDIR)
+ * This directory will have its modtime updated
+ * whenever at(1) changes a crontab; this is
+ * the signal for cron(8) to look for changes in the
+ * jobs directory (new, changed or jobs).
+ */
+#define AT_DIR "atjobs"
+
+ /* CRONSOCK is the name of the socket used by at and
+ * crontab to poke cron to re-read the at and cron
+ * spool files while cron is asleep.
+ * It lives in the spool directory.
+ */
+#define CRONSOCK ".sock"
+
+ /* cron allow/deny file. At least cron.deny must
+ * exist for ordinary users to run crontab.
+ */
+#define CRON_ALLOW "cron.allow"
+#define CRON_DENY "cron.deny"
+
+ /* at allow/deny file. At least at.deny must
+ * exist for ordinary users to run at.
*/
-#define CRONSOCK ".sock"
+#define AT_ALLOW "at.allow"
+#define AT_DENY "at.deny"
- /* undefining these turns off their features. note
- * 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. Note that if
+ /* undefining this turns off logging to a file. If
+ * neither LOG_FILE or SYSLOG is defined, we don't log.
+ * If 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 "cron.allow"
-#define DENY_FILE "cron.deny"
#define LOG_FILE "log"
/* where should the daemon stick its PID?
@@ -87,6 +104,10 @@
# define EDITOR "/usr/ucb/vi"
#endif
+#ifndef _PATH_SENDMAIL
+# define _PATH_SENDMAIL "/usr/lib/sendmail"
+#endif
+
#ifndef _PATH_BSHELL
# define _PATH_BSHELL "/bin/sh"
#endif
@@ -103,13 +124,4 @@
# define _PATH_DEVNULL "/dev/null"
#endif
-#if !defined(_PATH_SENDMAIL)
-# define _PATH_SENDMAIL "/usr/lib/sendmail"
-#endif /*SENDMAIL*/
-
-/* XXX */
-#define _PATH_ATJOBS "/var/cron/atjobs"
-#define _PATH_AT_ALLOW "/var/cron/at.allow"
-#define _PATH_AT_DENY "/var/cron/at.deny"
-
#endif /* _PATHNAMES_H_ */
diff --git a/usr.sbin/cron/popen.c b/usr.sbin/cron/popen.c
index e8f5cfdd3c1..7baf392127f 100644
--- a/usr.sbin/cron/popen.c
+++ b/usr.sbin/cron/popen.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: popen.c,v 1.17 2002/07/15 19:13:29 millert Exp $ */
+/* $OpenBSD: popen.c,v 1.18 2003/02/20 20:38:08 millert Exp $ */
/*
* Copyright (c) 1988, 1993, 1994
@@ -42,7 +42,7 @@
#if 0
static const sccsid[] = "@(#)popen.c 8.3 (Berkeley) 4/6/94";
#else
-static const char rcsid[] = "$OpenBSD: popen.c,v 1.17 2002/07/15 19:13:29 millert Exp $";
+static const char rcsid[] = "$OpenBSD: popen.c,v 1.18 2003/02/20 20:38:08 millert Exp $";
#endif
#endif /* not lint */
@@ -94,7 +94,7 @@ cron_popen(char *program, char *type, struct passwd *pw) {
/* NOTREACHED */
case 0: /* child */
if (pw) {
-#if defined(LOGIN_CAP)
+#ifdef LOGIN_CAP
if (setusercontext(0, pw, pw->pw_uid, LOGIN_SETALL) < 0) {
fprintf(stderr,
"setusercontext failed for %s\n",
@@ -102,14 +102,22 @@ cron_popen(char *program, char *type, struct passwd *pw) {
_exit(ERROR_EXIT);
}
#else
- if (setgid(pw->pw_gid) ||
- setgroups(0, NULL) ||
- initgroups(pw->pw_name, pw->pw_gid))
- _exit(1);
+ if (setgid(pw->pw_gid) < 0 ||
+ initgroups(pw->pw_name, pw->pw_gid) < 0) {
+ fprintf(stderr,
+ "unable to set groups for %s\n",
+ pw->pw_name);
+ _exit(1);
+ }
+#if (defined(BSD)) && (BSD >= 199103)
setlogin(pw->pw_name);
- if (setuid(pw->pw_uid))
+#endif /* BSD */
+ if (setuid(pw->pw_uid)) {
+ fprintf(stderr,
+ "unable to set uid for %s\n",
+ pw->pw_name);
_exit(1);
- chdir(pw->pw_dir);
+ }
#endif /* LOGIN_CAP */
}
if (*type == 'r') {
diff --git a/usr.sbin/cron/user.c b/usr.sbin/cron/user.c
index de60ed83eb6..f7a7806c254 100644
--- a/usr.sbin/cron/user.c
+++ b/usr.sbin/cron/user.c
@@ -1,4 +1,5 @@
-/* $OpenBSD: user.c,v 1.5 2002/07/11 20:15:40 millert Exp $ */
+/* $OpenBSD: user.c,v 1.6 2003/02/20 20:38:08 millert Exp $ */
+
/* Copyright 1988,1990,1993,1994 by Paul Vixie
* All rights reserved
*/
@@ -21,7 +22,7 @@
*/
#if !defined(lint) && !defined(LINT)
-static const char rcsid[] = "$OpenBSD: user.c,v 1.5 2002/07/11 20:15:40 millert Exp $";
+static const char rcsid[] = "$OpenBSD: user.c,v 1.6 2003/02/20 20:38:08 millert Exp $";
#endif
/* vix 26jan87 [log is in RCS file]