summaryrefslogtreecommitdiff
path: root/libexec/atrun/atrun.c
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2002-05-11 17:45:27 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2002-05-11 17:45:27 +0000
commit5102fea158f4a4887eada3c42c62d6af4f2a0151 (patch)
tree734a4ce67c74e002ef6879291d95b51d13969a69 /libexec/atrun/atrun.c
parent3329890d005e4100cfe791edad68c1d9cb7c7530 (diff)
When opening jobs file, use O_NONBLOCK|O_NOFOLLOW for paranoia's sake.
Diffstat (limited to 'libexec/atrun/atrun.c')
-rw-r--r--libexec/atrun/atrun.c25
1 files changed, 12 insertions, 13 deletions
diff --git a/libexec/atrun/atrun.c b/libexec/atrun/atrun.c
index face2bd2a4a..576ef6843f3 100644
--- a/libexec/atrun/atrun.c
+++ b/libexec/atrun/atrun.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: atrun.c,v 1.16 2002/03/16 18:40:00 millert Exp $ */
+/* $OpenBSD: atrun.c,v 1.17 2002/05/11 17:45:26 millert Exp $ */
/*
* atrun.c - run jobs queued by at; run with root privileges.
@@ -71,7 +71,7 @@
/* File scope variables */
static char *namep;
-static char rcsid[] = "$OpenBSD: atrun.c,v 1.16 2002/03/16 18:40:00 millert Exp $";
+static char rcsid[] = "$OpenBSD: atrun.c,v 1.17 2002/05/11 17:45:26 millert Exp $";
static int debug = 0;
/* Local functions */
@@ -168,11 +168,6 @@ run_file(filename, uid, gid)
filename);
exit(EXIT_FAILURE);
}
- PRIV_START
-
- stream = fopen(filename, "r");
-
- PRIV_END
if (pw->pw_expire && time(NULL) >= pw->pw_expire) {
syslog(LOG_ERR, "Userid %u has expired - aborting job %s",
@@ -180,11 +175,14 @@ run_file(filename, uid, gid)
exit(EXIT_FAILURE);
}
- if (stream == NULL)
- perr("Cannot open input file");
+ PRIV_START
- if ((fd_in = dup(fileno(stream))) < 0)
- perr("Error duplicating input file descriptor");
+ fd_in = open(filename, O_RDONLY|O_NONBLOCK|O_NOFOLLOW, 0);
+
+ PRIV_END
+
+ if (fd_in < 0)
+ perr("Cannot open input file");
if (fstat(fd_in, &buf) == -1)
perr("Error in fstat of input file descriptor");
@@ -224,12 +222,14 @@ run_file(filename, uid, gid)
syslog(LOG_ERR, "out of memory - aborting");
exit(EXIT_FAILURE);
}
+ if ((stream = fdopen(dup(fd_in), "r")) == NULL)
+ perr("Error duplicating input file descriptor");
if (fscanf(stream, fmt, &nuid, &ngid, mailbuf, &send_mail) != 4) {
syslog(LOG_ERR, "File %s is in wrong format - aborting",
filename);
- free(fmt);
exit(EXIT_FAILURE);
}
+ (void) fclose(stream);
free(fmt);
if (mailbuf[0] == '-') {
syslog(LOG_ERR, "illegal mail name %s in %s", mailbuf, filename);
@@ -246,7 +246,6 @@ run_file(filename, uid, gid)
filename, ngid, gid);
exit(EXIT_FAILURE);
}
- (void)fclose(stream);
PRIV_START