Upgrade to 2.9
This commit is contained in:
parent
eccdb56dd7
commit
ddcf802236
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=10154
29
libexec/atrun/LEGAL
Normal file
29
libexec/atrun/LEGAL
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
-----BEGIN PGP SIGNED MESSAGE-----
|
||||||
|
|
||||||
|
Sorry for the long wait, but there still were a few things to
|
||||||
|
be ironed out in at, which I've finally done :-)
|
||||||
|
|
||||||
|
The FreeBSD team does have my permission to use at, version 2.9,
|
||||||
|
under the BSD license.
|
||||||
|
|
||||||
|
You'll find it on sunsite.unc.edu's Incoming, hopefully; the
|
||||||
|
md5 checksum is
|
||||||
|
|
||||||
|
3ba2ca3c0e87e1a04feae2c6c1376b0d at-2.9.tgz
|
||||||
|
|
||||||
|
Best regards
|
||||||
|
Thomas
|
||||||
|
- --
|
||||||
|
Thomas Koenig, Thomas.Koenig@ciw.uni-karlsruhe.de, ig25@dkauni2.bitnet.
|
||||||
|
The joy of engineering is to find a straight line on a double
|
||||||
|
logarithmic diagram.
|
||||||
|
|
||||||
|
-----BEGIN PGP SIGNATURE-----
|
||||||
|
Version: 2.6.2i
|
||||||
|
|
||||||
|
iQCVAwUBMCjVrPBu+cbJcKCVAQFNiQP/dpWP57s/E8plVGUD3zfgOXDmKUvg8U7a
|
||||||
|
VwRzJrIMuSgnSJs0wkpvcomc3NLicipfX7hhWLh/xatPM2YbF7O5HZoNdvWvexD2
|
||||||
|
1Y67zJ+0HFb1mPnSBOrS5RFiQAe3KqmGec6E14Rih/qNoFQZBVRFXZ4xxuwP+0Rs
|
||||||
|
e2U+TVTUz6A=
|
||||||
|
=TvyW
|
||||||
|
-----END PGP SIGNATURE-----
|
@ -1,4 +1,4 @@
|
|||||||
# $Id: Makefile,v 1.1 1994/01/05 01:02:56 nate Exp $
|
# $Id: Makefile,v 1.3 1995/08/10 04:06:52 ache Exp $
|
||||||
|
|
||||||
MAINSRC= ${.CURDIR}/../../usr.bin/at
|
MAINSRC= ${.CURDIR}/../../usr.bin/at
|
||||||
|
|
||||||
@ -6,13 +6,14 @@ MAINSRC= ${.CURDIR}/../../usr.bin/at
|
|||||||
|
|
||||||
PROG= atrun
|
PROG= atrun
|
||||||
MAN8= atrun.8
|
MAN8= atrun.8
|
||||||
|
SRCS= atrun.c gloadavg.c
|
||||||
|
|
||||||
BINDIR= $(ATLIB_DIR)
|
BINDIR= $(ATLIB_DIR)
|
||||||
MANSRC= .
|
MANSRC= .
|
||||||
CLEANFILES += ${MAN8}
|
CLEANFILES += ${MAN8}
|
||||||
MANDEPEND = ${MAN8}
|
MANDEPEND = ${MAN8}
|
||||||
|
|
||||||
CFLAGS+= -I$(MAINSRC)
|
CFLAGS+= -I$(MAINSRC) -I{$.CURDIR}
|
||||||
|
|
||||||
${MAN8}: atrun.man
|
${MAN8}: atrun.man
|
||||||
sed -e \
|
sed -e \
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/*
|
/*
|
||||||
* atrun.c - run jobs queued by at; run with root privileges.
|
* atrun.c - run jobs queued by at; run with root privileges.
|
||||||
* Copyright (C) 1993, 1994 Thomas Koenig
|
* Copyright (C) 1993, 1994 Thomas Koenig
|
||||||
*
|
*
|
||||||
@ -14,7 +14,7 @@
|
|||||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
|
||||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
@ -42,17 +42,15 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
#ifndef __FreeBSD__
|
#ifdef __FreeBSD__
|
||||||
#include <getopt.h>
|
|
||||||
#else
|
|
||||||
#include <paths.h>
|
#include <paths.h>
|
||||||
|
#else
|
||||||
|
#include <getopt.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Local headers */
|
/* Local headers */
|
||||||
|
|
||||||
#ifndef __FreeBSD__
|
|
||||||
#include "gloadavg.h"
|
#include "gloadavg.h"
|
||||||
#endif
|
|
||||||
#define MAIN
|
#define MAIN
|
||||||
#include "privs.h"
|
#include "privs.h"
|
||||||
|
|
||||||
@ -73,29 +71,19 @@
|
|||||||
/* File scope variables */
|
/* File scope variables */
|
||||||
|
|
||||||
static char *namep;
|
static char *namep;
|
||||||
static char rcsid[] = "$Id: atrun.c,v 1.3 1995/04/12 19:21:43 ache Exp $";
|
static char rcsid[] = "$Id: atrun.c,v 1.5 1995/08/10 04:06:53 ache Exp $";
|
||||||
static debug = 0;
|
static debug = 0;
|
||||||
|
|
||||||
|
void perr(const char *a);
|
||||||
|
|
||||||
/* Local functions */
|
/* Local functions */
|
||||||
static void
|
|
||||||
perr(const char *a)
|
|
||||||
{
|
|
||||||
if (debug)
|
|
||||||
{
|
|
||||||
perror(a);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
syslog(LOG_ERR, "%s: %m", a);
|
|
||||||
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
write_string(int fd, const char* a)
|
write_string(int fd, const char* a)
|
||||||
{
|
{
|
||||||
return write(fd, a, strlen(a));
|
return write(fd, a, strlen(a));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#undef DEBUG_FORK
|
||||||
#ifdef DEBUG_FORK
|
#ifdef DEBUG_FORK
|
||||||
static pid_t
|
static pid_t
|
||||||
myfork()
|
myfork()
|
||||||
@ -124,10 +112,12 @@ run_file(const char *filename, uid_t uid, gid_t gid)
|
|||||||
char *mailname = NULL;
|
char *mailname = NULL;
|
||||||
FILE *stream;
|
FILE *stream;
|
||||||
int send_mail = 0;
|
int send_mail = 0;
|
||||||
struct stat buf;
|
struct stat buf, lbuf;
|
||||||
off_t size;
|
off_t size;
|
||||||
struct passwd *pentry;
|
struct passwd *pentry;
|
||||||
int fflags;
|
int fflags;
|
||||||
|
long nuid;
|
||||||
|
long ngid;
|
||||||
|
|
||||||
|
|
||||||
PRIV_START
|
PRIV_START
|
||||||
@ -142,8 +132,8 @@ run_file(const char *filename, uid_t uid, gid_t gid)
|
|||||||
pid = fork();
|
pid = fork();
|
||||||
if (pid == -1)
|
if (pid == -1)
|
||||||
perr("Cannot fork");
|
perr("Cannot fork");
|
||||||
|
|
||||||
else if (pid > 0)
|
else if (pid != 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* Let's see who we mail to. Hopefully, we can read it from
|
/* Let's see who we mail to. Hopefully, we can read it from
|
||||||
@ -156,7 +146,7 @@ run_file(const char *filename, uid_t uid, gid_t gid)
|
|||||||
{
|
{
|
||||||
syslog(LOG_ERR,"Userid %lu not found - aborting job %s",
|
syslog(LOG_ERR,"Userid %lu not found - aborting job %s",
|
||||||
(unsigned long) uid, filename);
|
(unsigned long) uid, filename);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
PRIV_START
|
PRIV_START
|
||||||
|
|
||||||
@ -170,32 +160,63 @@ run_file(const char *filename, uid_t uid, gid_t gid)
|
|||||||
if ((fd_in = dup(fileno(stream))) <0)
|
if ((fd_in = dup(fileno(stream))) <0)
|
||||||
perr("Error duplicating input file descriptor");
|
perr("Error duplicating input file descriptor");
|
||||||
|
|
||||||
|
if (fstat(fd_in, &buf) == -1)
|
||||||
|
perr("Error in fstat of input file descriptor");
|
||||||
|
|
||||||
|
if (lstat(filename, &lbuf) == -1)
|
||||||
|
perr("Error in fstat of input file");
|
||||||
|
|
||||||
|
if (S_ISLNK(lbuf.st_mode)) {
|
||||||
|
syslog(LOG_ERR,"Symbolic link encountered in job %s - aborting",
|
||||||
|
filename);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
if ((lbuf.st_dev != buf.st_dev) || (lbuf.st_ino != buf.st_ino) ||
|
||||||
|
(lbuf.st_uid != buf.st_uid) || (lbuf.st_gid != buf.st_gid) ||
|
||||||
|
(lbuf.st_size!=buf.st_size)) {
|
||||||
|
syslog(LOG_ERR,"Somebody changed files from under us for job %s - "
|
||||||
|
"aborting",filename);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
if (buf.st_nlink > 1) {
|
||||||
|
syslog(LOG_ERR,"Someboy is trying to run a linked script for job %s",
|
||||||
|
filename);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
if ((fflags = fcntl(fd_in, F_GETFD)) <0)
|
if ((fflags = fcntl(fd_in, F_GETFD)) <0)
|
||||||
perr("Error in fcntl");
|
perr("Error in fcntl");
|
||||||
|
|
||||||
fcntl(fd_in, F_SETFD, fflags & ~FD_CLOEXEC);
|
fcntl(fd_in, F_SETFD, fflags & ~FD_CLOEXEC);
|
||||||
|
|
||||||
if (fscanf(stream, "#! /bin/sh\n# mail %8s %d", mailbuf, &send_mail) == 2)
|
if (fscanf(stream, "#!/bin/sh\n# atrun uid=%ld gid=%ld\n# mail %8s %d",
|
||||||
|
&nuid, &ngid, mailbuf, &send_mail) != 4)
|
||||||
{
|
{
|
||||||
mailname = mailbuf;
|
syslog(LOG_ERR,"File %s is in wrong format - aborting",
|
||||||
pentry = getpwnam(mailname);
|
filename);
|
||||||
if (pentry == NULL || pentry->pw_uid != uid) {
|
exit(EXIT_FAILURE);
|
||||||
syslog(LOG_ERR,"Userid %lu mismatch name %s - aborting job %s",
|
|
||||||
(unsigned long) uid, mailname, filename);
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
if (mailbuf[0] == '-') {
|
||||||
{
|
syslog(LOG_ERR,"illegal mail name %s in %s",mailbuf,filename);
|
||||||
mailname = pentry->pw_name;
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
mailname = mailbuf;
|
||||||
|
if (nuid != uid) {
|
||||||
|
syslog(LOG_ERR,"Job %s - userid %d does not match file uid %d",
|
||||||
|
filename, nuid, uid);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
if (ngid != gid) {
|
||||||
|
syslog(LOG_ERR,"Job %s - groupid %d does not match file gid %d",
|
||||||
|
filename, ngid, gid);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
fclose(stream);
|
fclose(stream);
|
||||||
if (chdir(ATSPOOL_DIR) < 0)
|
if (chdir(ATSPOOL_DIR) < 0)
|
||||||
perr("Cannot chdir to " ATSPOOL_DIR);
|
perr("Cannot chdir to " ATSPOOL_DIR);
|
||||||
|
|
||||||
/* Create a file to hold the output of the job we are about to run.
|
/* Create a file to hold the output of the job we are about to run.
|
||||||
* Write the mail header.
|
* Write the mail header.
|
||||||
*/
|
*/
|
||||||
if((fd_out=open(filename,
|
if((fd_out=open(filename,
|
||||||
O_WRONLY | O_CREAT | O_EXCL, S_IWUSR | S_IRUSR)) < 0)
|
O_WRONLY | O_CREAT | O_EXCL, S_IWUSR | S_IRUSR)) < 0)
|
||||||
perr("Cannot create output file");
|
perr("Cannot create output file");
|
||||||
@ -209,7 +230,7 @@ run_file(const char *filename, uid_t uid, gid_t gid)
|
|||||||
close(STDIN_FILENO);
|
close(STDIN_FILENO);
|
||||||
close(STDOUT_FILENO);
|
close(STDOUT_FILENO);
|
||||||
close(STDERR_FILENO);
|
close(STDERR_FILENO);
|
||||||
|
|
||||||
pid = fork();
|
pid = fork();
|
||||||
if (pid < 0)
|
if (pid < 0)
|
||||||
perr("Error in fork");
|
perr("Error in fork");
|
||||||
@ -245,8 +266,9 @@ run_file(const char *filename, uid_t uid, gid_t gid)
|
|||||||
PRIV_START
|
PRIV_START
|
||||||
|
|
||||||
nice(tolower(queue) - 'a');
|
nice(tolower(queue) - 'a');
|
||||||
|
|
||||||
chdir(pentry->pw_dir);
|
if (chdir(pentry->pw_dir))
|
||||||
|
chdir("/");
|
||||||
|
|
||||||
if (initgroups(pentry->pw_name,pentry->pw_gid))
|
if (initgroups(pentry->pw_name,pentry->pw_gid))
|
||||||
perr("Cannot delete saved userids");
|
perr("Cannot delete saved userids");
|
||||||
@ -258,7 +280,7 @@ run_file(const char *filename, uid_t uid, gid_t gid)
|
|||||||
perr("Cannot set user id");
|
perr("Cannot set user id");
|
||||||
|
|
||||||
if(execle("/bin/sh","sh",(char *) NULL, nenvp) != 0)
|
if(execle("/bin/sh","sh",(char *) NULL, nenvp) != 0)
|
||||||
perr("Exec failed");
|
perr("Exec failed for /bin/sh");
|
||||||
|
|
||||||
PRIV_END
|
PRIV_END
|
||||||
}
|
}
|
||||||
@ -277,7 +299,21 @@ run_file(const char *filename, uid_t uid, gid_t gid)
|
|||||||
|
|
||||||
unlink(filename);
|
unlink(filename);
|
||||||
if ((buf.st_size != size) || send_mail)
|
if ((buf.st_size != size) || send_mail)
|
||||||
{
|
{
|
||||||
|
PRIV_START
|
||||||
|
|
||||||
|
if (chdir(pentry->pw_dir))
|
||||||
|
chdir("/");
|
||||||
|
|
||||||
|
if (initgroups(pentry->pw_name,pentry->pw_gid))
|
||||||
|
perr("Cannot delete saved userids");
|
||||||
|
|
||||||
|
if (setgid(gid) < 0)
|
||||||
|
perr("Cannot change group");
|
||||||
|
|
||||||
|
if (setuid(uid) < 0)
|
||||||
|
perr("Cannot set user id");
|
||||||
|
|
||||||
#ifdef __FreeBSD__
|
#ifdef __FreeBSD__
|
||||||
execl(_PATH_SENDMAIL, "sendmail", "-F", "Atrun Service",
|
execl(_PATH_SENDMAIL, "sendmail", "-F", "Atrun Service",
|
||||||
"-odi", "-oem",
|
"-odi", "-oem",
|
||||||
@ -285,13 +321,29 @@ run_file(const char *filename, uid_t uid, gid_t gid)
|
|||||||
#else
|
#else
|
||||||
execl(MAIL_CMD, MAIL_CMD, mailname, (char *) NULL);
|
execl(MAIL_CMD, MAIL_CMD, mailname, (char *) NULL);
|
||||||
#endif
|
#endif
|
||||||
perr("Exec failed");
|
perr("Exec failed for mail command");
|
||||||
|
|
||||||
|
PRIV_END
|
||||||
}
|
}
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Global functions */
|
/* Global functions */
|
||||||
|
|
||||||
|
/* Needed in gloadavg.c */
|
||||||
|
void
|
||||||
|
perr(const char *a)
|
||||||
|
{
|
||||||
|
if (debug)
|
||||||
|
{
|
||||||
|
perror(a);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
syslog(LOG_ERR, "%s: %m", a);
|
||||||
|
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
@ -309,6 +361,7 @@ main(int argc, char *argv[])
|
|||||||
struct dirent *dirent;
|
struct dirent *dirent;
|
||||||
struct stat buf;
|
struct stat buf;
|
||||||
unsigned long ctm;
|
unsigned long ctm;
|
||||||
|
unsigned long jobno;
|
||||||
char queue;
|
char queue;
|
||||||
time_t now, run_time;
|
time_t now, run_time;
|
||||||
char batch_name[] = "Z2345678901234";
|
char batch_name[] = "Z2345678901234";
|
||||||
@ -332,7 +385,7 @@ main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
switch (c)
|
switch (c)
|
||||||
{
|
{
|
||||||
case 'l':
|
case 'l':
|
||||||
if (sscanf(optarg, "%lf", &load_avg) != 1)
|
if (sscanf(optarg, "%lf", &load_avg) != 1)
|
||||||
perr("garbled option -l");
|
perr("garbled option -l");
|
||||||
if (load_avg <= 0.)
|
if (load_avg <= 0.)
|
||||||
@ -375,31 +428,28 @@ main(int argc, char *argv[])
|
|||||||
batch_uid = (uid_t) -1;
|
batch_uid = (uid_t) -1;
|
||||||
batch_gid = (gid_t) -1;
|
batch_gid = (gid_t) -1;
|
||||||
|
|
||||||
while ((dirent = readdir(spool)) != NULL)
|
while ((dirent = readdir(spool)) != NULL) {
|
||||||
{
|
|
||||||
if (stat(dirent->d_name,&buf) != 0)
|
if (stat(dirent->d_name,&buf) != 0)
|
||||||
perr("Cannot stat in " ATJOB_DIR);
|
perr("Cannot stat in " ATJOB_DIR);
|
||||||
|
|
||||||
/* We don't want directories
|
/* We don't want directories
|
||||||
*/
|
*/
|
||||||
if (!S_ISREG(buf.st_mode))
|
if (!S_ISREG(buf.st_mode))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (sscanf(dirent->d_name,"%c%8lx",&queue,&ctm) != 2)
|
if (sscanf(dirent->d_name,"%c%5lx%8lx",&queue,&jobno,&ctm) != 3)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
run_time = (time_t) ctm*60;
|
run_time = (time_t) ctm*60;
|
||||||
|
|
||||||
if ((S_IXUSR & buf.st_mode) && (run_time <=now))
|
if ((S_IXUSR & buf.st_mode) && (run_time <=now)) {
|
||||||
{
|
if (isupper(queue) && (strcmp(batch_name,dirent->d_name) > 0)) {
|
||||||
if (isupper(queue) && (strcmp(batch_name,dirent->d_name) > 0))
|
|
||||||
{
|
|
||||||
run_batch = 1;
|
run_batch = 1;
|
||||||
strncpy(batch_name, dirent->d_name, sizeof(batch_name));
|
strncpy(batch_name, dirent->d_name, sizeof(batch_name));
|
||||||
batch_uid = buf.st_uid;
|
batch_uid = buf.st_uid;
|
||||||
batch_gid = buf.st_gid;
|
batch_gid = buf.st_gid;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The file is executable and old enough
|
/* The file is executable and old enough
|
||||||
*/
|
*/
|
||||||
if (islower(queue))
|
if (islower(queue))
|
||||||
@ -412,18 +462,8 @@ main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
/* run the single batch file, if any
|
/* run the single batch file, if any
|
||||||
*/
|
*/
|
||||||
#ifndef __FreeBSD__
|
if (run_batch && (gloadavg() < load_avg))
|
||||||
if (run_batch && (gloadavg() < load_avg)) {
|
run_file(batch_name, batch_uid, batch_gid);
|
||||||
#else
|
|
||||||
if (run_batch) {
|
|
||||||
double la;
|
|
||||||
|
|
||||||
if (getloadavg(&la, 1) != 1)
|
|
||||||
perr("Error in getloadavg");
|
|
||||||
if (la < load_avg)
|
|
||||||
#endif
|
|
||||||
run_file(batch_name, batch_uid, batch_gid);
|
|
||||||
}
|
|
||||||
|
|
||||||
closelog();
|
closelog();
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
|
69
libexec/atrun/gloadavg.c
Normal file
69
libexec/atrun/gloadavg.c
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
/*
|
||||||
|
* gloadavg.c - get load average for Linux
|
||||||
|
* Copyright (C) 1993 Thomas Koenig
|
||||||
|
*
|
||||||
|
* 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. The name of the author(s) may not be used to endorse or promote
|
||||||
|
* products derived from this software without specific prior written
|
||||||
|
* permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``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(S) 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, WETHER 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __FreeBSD__
|
||||||
|
#define _POSIX_SOURCE 1
|
||||||
|
|
||||||
|
/* System Headers */
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#else
|
||||||
|
#include <stdlib.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Local headers */
|
||||||
|
|
||||||
|
#include "gloadavg.h"
|
||||||
|
|
||||||
|
/* File scope variables */
|
||||||
|
|
||||||
|
static char rcsid[] = "$Id: gloadavg.c,v 1.2 1995/08/10 04:06:54 ache Exp $";
|
||||||
|
|
||||||
|
/* Global functions */
|
||||||
|
|
||||||
|
double
|
||||||
|
gloadavg(void)
|
||||||
|
/* return the current load average as a floating point number, or <0 for
|
||||||
|
* error
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
double result;
|
||||||
|
#ifndef __FreeBSD__
|
||||||
|
FILE *fp;
|
||||||
|
|
||||||
|
if((fp=fopen(PROC_DIR "loadavg","r")) == NULL)
|
||||||
|
result = -1.0;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(fscanf(fp,"%lf",&result) != 1)
|
||||||
|
result = -1.0;
|
||||||
|
fclose(fp);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
if (getloadavg(&result, 1) != 1)
|
||||||
|
perr("Error in getloadavg");
|
||||||
|
#endif
|
||||||
|
return result;
|
||||||
|
}
|
29
libexec/atrun/gloadavg.h
Normal file
29
libexec/atrun/gloadavg.h
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
* gloadavg.h - header for atrun(8)
|
||||||
|
* Copyright (C) 1993 Thomas Koenig
|
||||||
|
*
|
||||||
|
* 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. The name of the author(s) may not be used to endorse or promote
|
||||||
|
* products derived from this software without specific prior written
|
||||||
|
* permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``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(S) 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, WETHER 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
double gloadavg(void);
|
||||||
|
#if 0
|
||||||
|
static char atrun_h_rcsid[] = "$Id: gloadavg.h,v 1.2 1995/08/10 04:06:55 ache Exp $";
|
||||||
|
#endif
|
29
usr.bin/at/LEGAL
Normal file
29
usr.bin/at/LEGAL
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
-----BEGIN PGP SIGNED MESSAGE-----
|
||||||
|
|
||||||
|
Sorry for the long wait, but there still were a few things to
|
||||||
|
be ironed out in at, which I've finally done :-)
|
||||||
|
|
||||||
|
The FreeBSD team does have my permission to use at, version 2.9,
|
||||||
|
under the BSD license.
|
||||||
|
|
||||||
|
You'll find it on sunsite.unc.edu's Incoming, hopefully; the
|
||||||
|
md5 checksum is
|
||||||
|
|
||||||
|
3ba2ca3c0e87e1a04feae2c6c1376b0d at-2.9.tgz
|
||||||
|
|
||||||
|
Best regards
|
||||||
|
Thomas
|
||||||
|
- --
|
||||||
|
Thomas Koenig, Thomas.Koenig@ciw.uni-karlsruhe.de, ig25@dkauni2.bitnet.
|
||||||
|
The joy of engineering is to find a straight line on a double
|
||||||
|
logarithmic diagram.
|
||||||
|
|
||||||
|
-----BEGIN PGP SIGNATURE-----
|
||||||
|
Version: 2.6.2i
|
||||||
|
|
||||||
|
iQCVAwUBMCjVrPBu+cbJcKCVAQFNiQP/dpWP57s/E8plVGUD3zfgOXDmKUvg8U7a
|
||||||
|
VwRzJrIMuSgnSJs0wkpvcomc3NLicipfX7hhWLh/xatPM2YbF7O5HZoNdvWvexD2
|
||||||
|
1Y67zJ+0HFb1mPnSBOrS5RFiQAe3KqmGec6E14Rih/qNoFQZBVRFXZ4xxuwP+0Rs
|
||||||
|
e2U+TVTUz6A=
|
||||||
|
=TvyW
|
||||||
|
-----END PGP SIGNATURE-----
|
@ -1,4 +1,4 @@
|
|||||||
VERSION= 2.7a
|
VERSION= 2.9
|
||||||
LOCKFILE = .lockfile
|
LOCKFILE = .lockfile
|
||||||
ATSPOOL_DIR=/var/at/spool
|
ATSPOOL_DIR=/var/at/spool
|
||||||
ATJOB_DIR=/var/at/jobs
|
ATJOB_DIR=/var/at/jobs
|
||||||
|
234
usr.bin/at/at.c
234
usr.bin/at/at.c
@ -1,4 +1,4 @@
|
|||||||
/*
|
/*
|
||||||
* at.c : Put file into atrun queue
|
* at.c : Put file into atrun queue
|
||||||
* Copyright (C) 1993, 1994 Thomas Koenig
|
* Copyright (C) 1993, 1994 Thomas Koenig
|
||||||
*
|
*
|
||||||
@ -17,7 +17,7 @@
|
|||||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
|
||||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
@ -61,7 +61,7 @@
|
|||||||
|
|
||||||
/* Macros */
|
/* Macros */
|
||||||
|
|
||||||
#ifndef ATJOB_DIR
|
#ifndef ATJOB_DIR
|
||||||
#define ATJOB_DIR "/usr/spool/atjobs/"
|
#define ATJOB_DIR "/usr/spool/atjobs/"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -78,9 +78,11 @@
|
|||||||
#define SIZE 255
|
#define SIZE 255
|
||||||
#define TIMESIZE 50
|
#define TIMESIZE 50
|
||||||
|
|
||||||
|
enum { ATQ, ATRM, AT, BATCH, CAT }; /* what program we want to run */
|
||||||
|
|
||||||
/* File scope variables */
|
/* File scope variables */
|
||||||
|
|
||||||
static char rcsid[] = "$Id: at.c,v 1.4 1995/04/27 19:27:41 ache Exp $";
|
static char rcsid[] = "$Id: at.c,v 1.3 1995/08/08 15:24:51 ig25 Exp $";
|
||||||
char *no_export[] =
|
char *no_export[] =
|
||||||
{
|
{
|
||||||
"TERM", "TERMCAP", "DISPLAY", "_"
|
"TERM", "TERMCAP", "DISPLAY", "_"
|
||||||
@ -110,7 +112,7 @@ static void list_jobs(void);
|
|||||||
|
|
||||||
static void sigc(int signo)
|
static void sigc(int signo)
|
||||||
{
|
{
|
||||||
/* If the user presses ^C, remove the spool file and exit
|
/* If the user presses ^C, remove the spool file and exit
|
||||||
*/
|
*/
|
||||||
if (fcreated)
|
if (fcreated)
|
||||||
{
|
{
|
||||||
@ -149,22 +151,47 @@ static char *cwdname(void)
|
|||||||
|
|
||||||
if (getcwd(ptr, size-1) != NULL)
|
if (getcwd(ptr, size-1) != NULL)
|
||||||
return ptr;
|
return ptr;
|
||||||
|
|
||||||
if (errno != ERANGE)
|
if (errno != ERANGE)
|
||||||
perr("Cannot get directory");
|
perr("Cannot get directory");
|
||||||
|
|
||||||
free (ptr);
|
free (ptr);
|
||||||
size += SIZE;
|
size += SIZE;
|
||||||
ptr = (char *) mymalloc(size);
|
ptr = (char *) mymalloc(size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static long
|
||||||
|
nextjob()
|
||||||
|
{
|
||||||
|
long jobno;
|
||||||
|
FILE *fid;
|
||||||
|
|
||||||
|
if ((fid = fopen(ATJOB_DIR ".SEQ", "r+")) != (FILE*)0) {
|
||||||
|
if (fscanf(fid, "%5lx", &jobno) == 1) {
|
||||||
|
rewind(fid);
|
||||||
|
jobno = (1+jobno) % 0xfffff; /* 2^20 jobs enough? */
|
||||||
|
fprintf(fid, "%05lx\n", jobno);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
jobno = EOF;
|
||||||
|
fclose(fid);
|
||||||
|
return jobno;
|
||||||
|
}
|
||||||
|
else if ((fid = fopen(ATJOB_DIR ".SEQ", "w")) != (FILE*)0) {
|
||||||
|
fprintf(fid, "%05lx\n", jobno = 1);
|
||||||
|
fclose(fid);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return EOF;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
writefile(time_t runtimer, char queue)
|
writefile(time_t runtimer, char queue)
|
||||||
{
|
{
|
||||||
/* This does most of the work if at or batch are invoked for writing a job.
|
/* This does most of the work if at or batch are invoked for writing a job.
|
||||||
*/
|
*/
|
||||||
int i;
|
long jobno;
|
||||||
char *ap, *ppos, *mailname;
|
char *ap, *ppos, *mailname;
|
||||||
struct passwd *pass_entry;
|
struct passwd *pass_entry;
|
||||||
struct stat statbuf;
|
struct stat statbuf;
|
||||||
@ -175,7 +202,7 @@ writefile(time_t runtimer, char queue)
|
|||||||
int ch;
|
int ch;
|
||||||
mode_t cmask;
|
mode_t cmask;
|
||||||
struct flock lock;
|
struct flock lock;
|
||||||
|
|
||||||
/* Install the signal handler for SIGINT; terminate after removing the
|
/* Install the signal handler for SIGINT; terminate after removing the
|
||||||
* spool file if necessary
|
* spool file if necessary
|
||||||
*/
|
*/
|
||||||
@ -213,25 +240,19 @@ writefile(time_t runtimer, char queue)
|
|||||||
fcntl(lockdes, F_SETLKW, &lock);
|
fcntl(lockdes, F_SETLKW, &lock);
|
||||||
alarm(0);
|
alarm(0);
|
||||||
|
|
||||||
for(i=0; i<ATJOB_MX; i++)
|
if ((jobno = nextjob()) == EOF)
|
||||||
{
|
perr("Cannot generate job number");
|
||||||
sprintf(ppos, "%c%8lx.%2x", queue,
|
|
||||||
(unsigned long) (runtimer/60), i);
|
|
||||||
for(ap=ppos; *ap != '\0'; ap ++)
|
|
||||||
if (*ap == ' ')
|
|
||||||
*ap = '0';
|
|
||||||
|
|
||||||
if (stat(atfile, &statbuf) != 0)
|
sprintf(ppos, "%c%5lx%8lx", queue,
|
||||||
{
|
jobno, (unsigned long) (runtimer/60));
|
||||||
if (errno == ENOENT)
|
|
||||||
break;
|
|
||||||
else
|
|
||||||
perr("Cannot access " ATJOB_DIR);
|
|
||||||
}
|
|
||||||
} /* for */
|
|
||||||
|
|
||||||
if (i >= ATJOB_MX)
|
for(ap=ppos; *ap != '\0'; ap ++)
|
||||||
panic("Too many jobs already");
|
if (*ap == ' ')
|
||||||
|
*ap = '0';
|
||||||
|
|
||||||
|
if (stat(atfile, &statbuf) != 0)
|
||||||
|
if (errno != ENOENT)
|
||||||
|
perr("Cannot access " ATJOB_DIR);
|
||||||
|
|
||||||
/* Create the file. The x bit is only going to be set after it has
|
/* Create the file. The x bit is only going to be set after it has
|
||||||
* been completely written out, to make sure it is not executed in the
|
* been completely written out, to make sure it is not executed in the
|
||||||
@ -240,7 +261,7 @@ writefile(time_t runtimer, char queue)
|
|||||||
*/
|
*/
|
||||||
cmask = umask(S_IRUSR | S_IWUSR | S_IXUSR);
|
cmask = umask(S_IRUSR | S_IWUSR | S_IXUSR);
|
||||||
if ((fdes = creat(atfile, O_WRONLY)) == -1)
|
if ((fdes = creat(atfile, O_WRONLY)) == -1)
|
||||||
perr("Cannot create atjob file");
|
perr("Cannot create atjob file");
|
||||||
|
|
||||||
if ((fd2 = dup(fdes)) <0)
|
if ((fd2 = dup(fdes)) <0)
|
||||||
perr("Error in dup() of job file");
|
perr("Error in dup() of job file");
|
||||||
@ -256,7 +277,7 @@ writefile(time_t runtimer, char queue)
|
|||||||
|
|
||||||
REDUCE_PRIV(DAEMON_UID, DAEMON_GID)
|
REDUCE_PRIV(DAEMON_UID, DAEMON_GID)
|
||||||
|
|
||||||
/* We've successfully created the file; let's set the flag so it
|
/* We've successfully created the file; let's set the flag so it
|
||||||
* gets removed in case of an interrupt or error.
|
* gets removed in case of an interrupt or error.
|
||||||
*/
|
*/
|
||||||
fcreated = 1;
|
fcreated = 1;
|
||||||
@ -278,10 +299,10 @@ writefile(time_t runtimer, char queue)
|
|||||||
if (mailname == NULL)
|
if (mailname == NULL)
|
||||||
mailname = getenv("LOGNAME");
|
mailname = getenv("LOGNAME");
|
||||||
|
|
||||||
if ((mailname == NULL) || (mailname[0] == '\0')
|
if ((mailname == NULL) || (mailname[0] == '\0')
|
||||||
|| (strlen(mailname) > 8) || (getpwnam(mailname)==NULL))
|
|| (strlen(mailname) > 8) || (getpwnam(mailname)==NULL))
|
||||||
{
|
{
|
||||||
pass_entry = getpwuid(getuid());
|
pass_entry = getpwuid(real_uid);
|
||||||
if (pass_entry != NULL)
|
if (pass_entry != NULL)
|
||||||
mailname = pass_entry->pw_name;
|
mailname = pass_entry->pw_name;
|
||||||
}
|
}
|
||||||
@ -292,7 +313,8 @@ writefile(time_t runtimer, char queue)
|
|||||||
if (fpin == NULL)
|
if (fpin == NULL)
|
||||||
perr("Cannot open input file");
|
perr("Cannot open input file");
|
||||||
}
|
}
|
||||||
fprintf(fp, "#! /bin/sh\n# mail %8s %d\n", mailname, send_mail);
|
fprintf(fp, "#!/bin/sh\n# atrun uid=%ld gid=%ld\n# mail %8s %d\n",
|
||||||
|
(long) real_uid, (long) real_gid, mailname, send_mail);
|
||||||
|
|
||||||
/* Write out the umask at the time of invocation
|
/* Write out the umask at the time of invocation
|
||||||
*/
|
*/
|
||||||
@ -317,7 +339,7 @@ writefile(time_t runtimer, char queue)
|
|||||||
for (i=0; i<sizeof(no_export)/sizeof(no_export[0]); i++)
|
for (i=0; i<sizeof(no_export)/sizeof(no_export[0]); i++)
|
||||||
{
|
{
|
||||||
export = export
|
export = export
|
||||||
&& (strncmp(*atenv, no_export[i],
|
&& (strncmp(*atenv, no_export[i],
|
||||||
(size_t) (eqp-*atenv)) != 0);
|
(size_t) (eqp-*atenv)) != 0);
|
||||||
}
|
}
|
||||||
eqp++;
|
eqp++;
|
||||||
@ -332,18 +354,27 @@ writefile(time_t runtimer, char queue)
|
|||||||
fprintf(fp, "\"\n\"");
|
fprintf(fp, "\"\n\"");
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (*ap != '/' && !isalnum(*ap))
|
if (!isalnum(*ap)) {
|
||||||
fputc('\\', fp);
|
switch (*ap) {
|
||||||
|
case '%': case '/': case '{': case '[':
|
||||||
|
case ']': case '=': case '}': case '@':
|
||||||
|
case '+': case '#': case ',': case '.':
|
||||||
|
case ':': case '-': case '_':
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
fputc('\\', fp);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
fputc(*ap, fp);
|
fputc(*ap, fp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fputs("; export ", fp);
|
fputs("; export ", fp);
|
||||||
fwrite(*atenv, sizeof(char), eqp-*atenv -1, fp);
|
fwrite(*atenv, sizeof(char), eqp-*atenv -1, fp);
|
||||||
fputc('\n', fp);
|
fputc('\n', fp);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Cd to the directory at the time and write out all the
|
/* Cd to the directory at the time and write out all the
|
||||||
* commands the user supplies from stdin.
|
* commands the user supplies from stdin.
|
||||||
*/
|
*/
|
||||||
@ -356,7 +387,7 @@ writefile(time_t runtimer, char queue)
|
|||||||
{
|
{
|
||||||
if (*ap != '/' && !isalnum(*ap))
|
if (*ap != '/' && !isalnum(*ap))
|
||||||
fputc('\\', fp);
|
fputc('\\', fp);
|
||||||
|
|
||||||
fputc(*ap, fp);
|
fputc(*ap, fp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -372,7 +403,7 @@ writefile(time_t runtimer, char queue)
|
|||||||
fprintf(fp, "\n");
|
fprintf(fp, "\n");
|
||||||
if (ferror(fp))
|
if (ferror(fp))
|
||||||
panic("Output error");
|
panic("Output error");
|
||||||
|
|
||||||
if (ferror(stdin))
|
if (ferror(stdin))
|
||||||
panic("Input error");
|
panic("Input error");
|
||||||
|
|
||||||
@ -385,13 +416,13 @@ writefile(time_t runtimer, char queue)
|
|||||||
perr("Cannot give away file");
|
perr("Cannot give away file");
|
||||||
|
|
||||||
close(fd2);
|
close(fd2);
|
||||||
fprintf(stderr, "Job %s will be executed using /bin/sh\n", ppos);
|
fprintf(stderr, "Job %ld will be executed using /bin/sh\n", jobno);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
list_jobs()
|
list_jobs()
|
||||||
{
|
{
|
||||||
/* List all a user's jobs in the queue, by looping through ATJOB_DIR,
|
/* List all a user's jobs in the queue, by looping through ATJOB_DIR,
|
||||||
* or everybody's if we are root
|
* or everybody's if we are root
|
||||||
*/
|
*/
|
||||||
struct passwd *pw;
|
struct passwd *pw;
|
||||||
@ -401,6 +432,7 @@ list_jobs()
|
|||||||
struct tm runtime;
|
struct tm runtime;
|
||||||
unsigned long ctm;
|
unsigned long ctm;
|
||||||
char queue;
|
char queue;
|
||||||
|
long jobno;
|
||||||
time_t runtimer;
|
time_t runtimer;
|
||||||
char timestr[TIMESIZE];
|
char timestr[TIMESIZE];
|
||||||
int first=1;
|
int first=1;
|
||||||
@ -413,12 +445,12 @@ list_jobs()
|
|||||||
if ((spool = opendir(".")) == NULL)
|
if ((spool = opendir(".")) == NULL)
|
||||||
perr("Cannot open " ATJOB_DIR);
|
perr("Cannot open " ATJOB_DIR);
|
||||||
|
|
||||||
/* Loop over every file in the directory
|
/* Loop over every file in the directory
|
||||||
*/
|
*/
|
||||||
while((dirent = readdir(spool)) != NULL) {
|
while((dirent = readdir(spool)) != NULL) {
|
||||||
if (stat(dirent->d_name, &buf) != 0)
|
if (stat(dirent->d_name, &buf) != 0)
|
||||||
perr("Cannot stat in " ATJOB_DIR);
|
perr("Cannot stat in " ATJOB_DIR);
|
||||||
|
|
||||||
/* See it's a regular file and has its x bit turned on and
|
/* See it's a regular file and has its x bit turned on and
|
||||||
* is the user's
|
* is the user's
|
||||||
*/
|
*/
|
||||||
@ -427,7 +459,7 @@ list_jobs()
|
|||||||
|| !(S_IXUSR & buf.st_mode || atverify))
|
|| !(S_IXUSR & buf.st_mode || atverify))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if(sscanf(dirent->d_name, "%c%8lx", &queue, &ctm)!=2)
|
if(sscanf(dirent->d_name, "%c%5lx%8lx", &queue, &jobno, &ctm)!=3)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (atqueue && (queue != atqueue))
|
if (atqueue && (queue != atqueue))
|
||||||
@ -442,42 +474,98 @@ list_jobs()
|
|||||||
}
|
}
|
||||||
pw = getpwuid(buf.st_uid);
|
pw = getpwuid(buf.st_uid);
|
||||||
|
|
||||||
printf("%s\t%s\t%c%s\t%s\n",
|
printf("%s\t%s\t%c%s\t%ld\n",
|
||||||
timestr,
|
timestr,
|
||||||
pw ? pw->pw_name : "???",
|
pw ? pw->pw_name : "???",
|
||||||
queue,
|
queue,
|
||||||
(S_IXUSR & buf.st_mode) ? "":"(done)",
|
(S_IXUSR & buf.st_mode) ? "":"(done)",
|
||||||
dirent->d_name);
|
jobno);
|
||||||
}
|
}
|
||||||
PRIV_END
|
PRIV_END
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
delete_jobs(int argc, char **argv)
|
process_jobs(int argc, char **argv, int what)
|
||||||
{
|
{
|
||||||
/* Delete every argument (job - ID) given
|
/* Delete every argument (job - ID) given
|
||||||
*/
|
*/
|
||||||
int i;
|
int i;
|
||||||
struct stat buf;
|
struct stat buf;
|
||||||
|
DIR *spool;
|
||||||
|
struct dirent *dirent;
|
||||||
|
unsigned long ctm;
|
||||||
|
char queue;
|
||||||
|
long jobno;
|
||||||
|
|
||||||
PRIV_START
|
PRIV_START
|
||||||
|
|
||||||
if (chdir(ATJOB_DIR) != 0)
|
if (chdir(ATJOB_DIR) != 0)
|
||||||
perr("Cannot change to " ATJOB_DIR);
|
perr("Cannot change to " ATJOB_DIR);
|
||||||
|
|
||||||
for (i=optind; i < argc; i++) {
|
if ((spool = opendir(".")) == NULL)
|
||||||
if (stat(argv[i], &buf) != 0) {
|
perr("Cannot open " ATJOB_DIR);
|
||||||
perr(argv[i]);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if ((buf.st_uid != real_uid) && !(real_uid == 0)) {
|
|
||||||
fprintf(stderr, "%s: Not owner\n", argv[i]);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (unlink(argv[i]) != 0)
|
|
||||||
perr(argv[i]);
|
|
||||||
}
|
|
||||||
PRIV_END
|
PRIV_END
|
||||||
|
|
||||||
|
/* Loop over every file in the directory
|
||||||
|
*/
|
||||||
|
while((dirent = readdir(spool)) != NULL) {
|
||||||
|
|
||||||
|
PRIV_START
|
||||||
|
if (stat(dirent->d_name, &buf) != 0)
|
||||||
|
perr("Cannot stat in " ATJOB_DIR);
|
||||||
|
PRIV_END
|
||||||
|
|
||||||
|
if(sscanf(dirent->d_name, "%c%5lx%8lx", &queue, &jobno, &ctm)!=3)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
for (i=optind; i < argc; i++) {
|
||||||
|
if (atoi(argv[i]) == jobno) {
|
||||||
|
if ((buf.st_uid != real_uid) && !(real_uid == 0)) {
|
||||||
|
fprintf(stderr, "%s: Not owner\n", argv[i]);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
switch (what) {
|
||||||
|
case ATRM:
|
||||||
|
|
||||||
|
PRIV_START
|
||||||
|
|
||||||
|
if (unlink(dirent->d_name) != 0)
|
||||||
|
perr(dirent->d_name);
|
||||||
|
|
||||||
|
PRIV_END
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CAT:
|
||||||
|
{
|
||||||
|
FILE *fp;
|
||||||
|
int ch;
|
||||||
|
|
||||||
|
PRIV_START
|
||||||
|
|
||||||
|
fp = fopen(dirent->d_name,"r");
|
||||||
|
|
||||||
|
PRIV_END
|
||||||
|
|
||||||
|
if (!fp) {
|
||||||
|
perr("Cannot open file");
|
||||||
|
}
|
||||||
|
while((ch = getc(fp)) != EOF) {
|
||||||
|
putchar(ch);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
fprintf(stderr,
|
||||||
|
"Internal error, process_jobs = %d\n",what);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
} /* delete_jobs */
|
} /* delete_jobs */
|
||||||
|
|
||||||
/* Global functions */
|
/* Global functions */
|
||||||
@ -502,9 +590,9 @@ main(int argc, char **argv)
|
|||||||
char queue_set = 0;
|
char queue_set = 0;
|
||||||
char *pgm;
|
char *pgm;
|
||||||
|
|
||||||
enum { ATQ, ATRM, AT, BATCH }; /* what program we want to run */
|
enum { ATQ, ATRM, AT, BATCH, CAT }; /* what program we want to run */
|
||||||
int program = AT; /* our default program */
|
int program = AT; /* our default program */
|
||||||
char *options = "q:f:mvldbV"; /* default options for at */
|
char *options = "q:f:mvldbVc"; /* default options for at */
|
||||||
int disp_version = 0;
|
int disp_version = 0;
|
||||||
time_t timer;
|
time_t timer;
|
||||||
|
|
||||||
@ -550,7 +638,7 @@ main(int argc, char **argv)
|
|||||||
case 'f':
|
case 'f':
|
||||||
atinput = optarg;
|
atinput = optarg;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'q': /* specify queue */
|
case 'q': /* specify queue */
|
||||||
if (strlen(optarg) > 1)
|
if (strlen(optarg) > 1)
|
||||||
usage();
|
usage();
|
||||||
@ -590,6 +678,11 @@ main(int argc, char **argv)
|
|||||||
disp_version = 1;
|
disp_version = 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'c':
|
||||||
|
program = CAT;
|
||||||
|
options = "";
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
usage();
|
usage();
|
||||||
break;
|
break;
|
||||||
@ -620,7 +713,12 @@ main(int argc, char **argv)
|
|||||||
|
|
||||||
REDUCE_PRIV(DAEMON_UID, DAEMON_GID)
|
REDUCE_PRIV(DAEMON_UID, DAEMON_GID)
|
||||||
|
|
||||||
delete_jobs(argc, argv);
|
process_jobs(argc, argv, ATRM);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CAT:
|
||||||
|
|
||||||
|
process_jobs(argc, argv, CAT);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AT:
|
case AT:
|
||||||
@ -643,7 +741,7 @@ main(int argc, char **argv)
|
|||||||
timer = parsetime(argc, argv);
|
timer = parsetime(argc, argv);
|
||||||
else
|
else
|
||||||
timer = time(NULL);
|
timer = time(NULL);
|
||||||
|
|
||||||
if (atverify)
|
if (atverify)
|
||||||
{
|
{
|
||||||
struct tm *tm = localtime(&timer);
|
struct tm *tm = localtime(&timer);
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/*
|
/*
|
||||||
* at.h - header for at(1)
|
* at.h - header for at(1)
|
||||||
* Copyright (C) 1993 Thomas Koenig
|
* Copyright (C) 1993 Thomas Koenig
|
||||||
*
|
*
|
||||||
@ -14,7 +14,7 @@
|
|||||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
|
||||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
.\" $Id: at.man,v 1.1 1995/04/12 02:42:31 ache Exp $
|
.\" $Id: at.man,v 1.2 1995/06/24 17:15:55 joerg Exp $
|
||||||
.Dd April 12, 1995
|
.Dd April 12, 1995
|
||||||
.Dt "AT" 1
|
.Dt "AT" 1
|
||||||
.Os "FreeBSD 2.1"
|
.Os "FreeBSD 2.1"
|
||||||
@ -13,6 +13,10 @@
|
|||||||
.Op Fl mldbv
|
.Op Fl mldbv
|
||||||
.Ar time
|
.Ar time
|
||||||
.Pp
|
.Pp
|
||||||
|
.Nm at
|
||||||
|
.Op Fl V
|
||||||
|
.Fl c Ar job Op Ar job ...
|
||||||
|
.Pp
|
||||||
.Nm atq
|
.Nm atq
|
||||||
.Op Fl V
|
.Op Fl V
|
||||||
.Op Fl q Ar queue
|
.Op Fl q Ar queue
|
||||||
@ -215,6 +219,8 @@ For
|
|||||||
.Nm atq ,
|
.Nm atq ,
|
||||||
shows completed but not yet deleted jobs in the queue; otherwise
|
shows completed but not yet deleted jobs in the queue; otherwise
|
||||||
shows the time the job will be executed.
|
shows the time the job will be executed.
|
||||||
|
.It Fl c
|
||||||
|
Cats the jobs listed on the command line to standart output.
|
||||||
.Sh FILES
|
.Sh FILES
|
||||||
.Bl -tag -width _ATJOB_DIR/_LOCKFILE -compact
|
.Bl -tag -width _ATJOB_DIR/_LOCKFILE -compact
|
||||||
.It Pa _ATJOB_DIR
|
.It Pa _ATJOB_DIR
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/*
|
/*
|
||||||
* panic.c - terminate fast in case of error
|
* panic.c - terminate fast in case of error
|
||||||
* Copyright (C) 1993 Thomas Koenig
|
* Copyright (C) 1993 Thomas Koenig
|
||||||
*
|
*
|
||||||
@ -14,7 +14,7 @@
|
|||||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
|
||||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
@ -37,7 +37,7 @@
|
|||||||
|
|
||||||
/* File scope variables */
|
/* File scope variables */
|
||||||
|
|
||||||
static char rcsid[] = "$Id: panic.c,v 1.2 1995/04/12 02:42:32 ache Exp $";
|
static char rcsid[] = "$Id: panic.c,v 1.1 1995/05/24 15:07:32 ig25 Exp $";
|
||||||
|
|
||||||
/* External variables */
|
/* External variables */
|
||||||
|
|
||||||
@ -73,8 +73,9 @@ usage(void)
|
|||||||
/* Print usage and exit.
|
/* Print usage and exit.
|
||||||
*/
|
*/
|
||||||
fprintf(stderr, "Usage: at [-V] [-q x] [-f file] [-m] time\n"
|
fprintf(stderr, "Usage: at [-V] [-q x] [-f file] [-m] time\n"
|
||||||
|
" at [-V] -c job [job ...]\n"
|
||||||
" atq [-V] [-q x] [-v]\n"
|
" atq [-V] [-q x] [-v]\n"
|
||||||
" atrm [-V] [-q x] job ...\n"
|
" atrm [-V] job [job ...]\n"
|
||||||
" batch [-V] [-f file] [-m]\n");
|
" batch [-V] [-f file] [-m]\n");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/*
|
/*
|
||||||
* panic.h - header for at(1)
|
* panic.h - header for at(1)
|
||||||
* Copyright (C) 1993 Thomas Koenig
|
* Copyright (C) 1993 Thomas Koenig
|
||||||
*
|
*
|
||||||
@ -14,7 +14,7 @@
|
|||||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
|
||||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/*
|
/*
|
||||||
* parsetime.c - parse time for at(1)
|
* parsetime.c - parse time for at(1)
|
||||||
* Copyright (C) 1993, 1994 Thomas Koenig
|
* Copyright (C) 1993, 1994 Thomas Koenig
|
||||||
*
|
*
|
||||||
@ -17,7 +17,7 @@
|
|||||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
|
||||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
@ -56,7 +56,7 @@
|
|||||||
|
|
||||||
/* Structures and unions */
|
/* Structures and unions */
|
||||||
|
|
||||||
enum tok { /* symbols */
|
enum { /* symbols */
|
||||||
MIDNIGHT, NOON, TEATIME,
|
MIDNIGHT, NOON, TEATIME,
|
||||||
PM, AM, TOMORROW, TODAY, NOW,
|
PM, AM, TOMORROW, TODAY, NOW,
|
||||||
MINUTES, HOURS, DAYS, WEEKS,
|
MINUTES, HOURS, DAYS, WEEKS,
|
||||||
@ -69,8 +69,8 @@ enum tok { /* symbols */
|
|||||||
/* parse translation table - table driven parsers can be your FRIEND!
|
/* parse translation table - table driven parsers can be your FRIEND!
|
||||||
*/
|
*/
|
||||||
struct {
|
struct {
|
||||||
const char *name; /* token name */
|
char *name; /* token name */
|
||||||
enum tok value; /* token id */
|
int value; /* token id */
|
||||||
int plural; /* is this plural? */
|
int plural; /* is this plural? */
|
||||||
} Specials[] = {
|
} Specials[] = {
|
||||||
{ "midnight", MIDNIGHT,0 }, /* 00:00:00 of today or tomorrow */
|
{ "midnight", MIDNIGHT,0 }, /* 00:00:00 of today or tomorrow */
|
||||||
@ -127,18 +127,18 @@ static int need; /* scanner - need to advance to next argument */
|
|||||||
|
|
||||||
static char *sc_token; /* scanner - token buffer */
|
static char *sc_token; /* scanner - token buffer */
|
||||||
static size_t sc_len; /* scanner - lenght of token buffer */
|
static size_t sc_len; /* scanner - lenght of token buffer */
|
||||||
static enum tok sc_tokid; /* scanner - token id */
|
static int sc_tokid; /* scanner - token id */
|
||||||
static int sc_tokplur; /* scanner - is token plural? */
|
static int sc_tokplur; /* scanner - is token plural? */
|
||||||
|
|
||||||
static char rcsid[] = "$Id: parsetime.c,v 1.4 1995/05/30 06:29:25 rgrimes Exp $";
|
static char rcsid[] = "$Id: parsetime.c,v 1.1 1995/05/24 15:07:32 ig25 Exp $";
|
||||||
|
|
||||||
/* Local functions */
|
/* Local functions */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* parse a token, checking if it's something special to us
|
* parse a token, checking if it's something special to us
|
||||||
*/
|
*/
|
||||||
static enum tok
|
static int
|
||||||
parse_token(const char *arg)
|
parse_token(char *arg)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@ -163,8 +163,8 @@ init_scanner(int argc, char **argv)
|
|||||||
scc = argc;
|
scc = argc;
|
||||||
need = 1;
|
need = 1;
|
||||||
sc_len = 1;
|
sc_len = 1;
|
||||||
while (--argc > 0)
|
while (argc-- > 0)
|
||||||
sc_len += strlen(*++argv);
|
sc_len += strlen(*argv++);
|
||||||
|
|
||||||
sc_token = (char *) mymalloc(sc_len);
|
sc_token = (char *) mymalloc(sc_len);
|
||||||
} /* init_scanner */
|
} /* init_scanner */
|
||||||
@ -172,7 +172,7 @@ init_scanner(int argc, char **argv)
|
|||||||
/*
|
/*
|
||||||
* token() fetches a token from the input stream
|
* token() fetches a token from the input stream
|
||||||
*/
|
*/
|
||||||
static enum tok
|
static int
|
||||||
token()
|
token()
|
||||||
{
|
{
|
||||||
int idx;
|
int idx;
|
||||||
@ -246,11 +246,11 @@ plonk(int tok)
|
|||||||
} /* plonk */
|
} /* plonk */
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* expect() gets a token and dies most horribly if it's not the token we want
|
* expect() gets a token and dies most horribly if it's not the token we want
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
expect(enum tok desired)
|
expect(int desired)
|
||||||
{
|
{
|
||||||
if (token() != desired)
|
if (token() != desired)
|
||||||
plonk(sc_tokid); /* and we die here... */
|
plonk(sc_tokid); /* and we die here... */
|
||||||
@ -417,7 +417,7 @@ assign_date(struct tm *tm, long mday, long mon, long year)
|
|||||||
} /* assign_date */
|
} /* assign_date */
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* month() picks apart a month specification
|
* month() picks apart a month specification
|
||||||
*
|
*
|
||||||
* /[<month> NUMBER [NUMBER]] \
|
* /[<month> NUMBER [NUMBER]] \
|
||||||
@ -489,7 +489,7 @@ month(struct tm *tm)
|
|||||||
token();
|
token();
|
||||||
|
|
||||||
if (sc_tokid == SLASH || sc_tokid == DOT) {
|
if (sc_tokid == SLASH || sc_tokid == DOT) {
|
||||||
enum tok sep;
|
int sep;
|
||||||
|
|
||||||
sep = sc_tokid;
|
sep = sc_tokid;
|
||||||
expect(NUMBER);
|
expect(NUMBER);
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/*
|
/*
|
||||||
* at.h - header for at(1)
|
* at.h - header for at(1)
|
||||||
* Copyright (C) 1993 Thomas Koenig
|
* Copyright (C) 1993 Thomas Koenig
|
||||||
*
|
*
|
||||||
@ -14,7 +14,7 @@
|
|||||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
|
||||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/*
|
/*
|
||||||
* perm.c - check user permission for at(1)
|
* perm.c - check user permission for at(1)
|
||||||
* Copyright (C) 1994 Thomas Koenig
|
* Copyright (C) 1994 Thomas Koenig
|
||||||
*
|
*
|
||||||
@ -14,7 +14,7 @@
|
|||||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
|
||||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
@ -48,7 +48,7 @@
|
|||||||
|
|
||||||
/* File scope variables */
|
/* File scope variables */
|
||||||
|
|
||||||
static char rcsid[] = "$Id: perm.c,v 1.1 1995/04/12 02:42:37 ache Exp $";
|
static char rcsid[] = "$Id: perm.c,v 1.1 1995/05/24 15:07:32 ig25 Exp $";
|
||||||
|
|
||||||
/* Function declarations */
|
/* Function declarations */
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/*
|
/*
|
||||||
* perm.h - header for at(1)
|
* perm.h - header for at(1)
|
||||||
* Copyright (C) 1994 Thomas Koenig
|
* Copyright (C) 1994 Thomas Koenig
|
||||||
*
|
*
|
||||||
@ -14,7 +14,7 @@
|
|||||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
|
||||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
@ -1,20 +1,26 @@
|
|||||||
/*
|
/*
|
||||||
* privs.h - header for privileged operations
|
* privs.h - header for privileged operations
|
||||||
* Copyright (C) 1993 Thomas Koenig
|
* Copyright (C) 1993 Thomas Koenig
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* it under the terms of the GNU General Public License as published by
|
* modification, are permitted provided that the following conditions
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
* are met:
|
||||||
* (at your option) any later version.
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. The name of the author(s) may not be used to endorse or promote
|
||||||
|
* products derived from this software without specific prior written
|
||||||
|
* permission.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful,
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||||
* GNU General Public License for more details.
|
* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
*
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
* You should have received a copy of the GNU General Public License
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
* along with this program; if not, write to the Free Software
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
* THEORY OF LIABILITY, WETHER 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.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _PRIVS_H
|
#ifndef _PRIVS_H
|
||||||
@ -62,7 +68,7 @@ extern
|
|||||||
#endif
|
#endif
|
||||||
uid_t real_uid, effective_uid;
|
uid_t real_uid, effective_uid;
|
||||||
|
|
||||||
#ifndef MAIN
|
#ifndef MAIN
|
||||||
extern
|
extern
|
||||||
#endif
|
#endif
|
||||||
gid_t real_gid, effective_gid;
|
gid_t real_gid, effective_gid;
|
||||||
@ -81,8 +87,8 @@ gid_t real_gid, effective_gid;
|
|||||||
effective_uid = geteuid(); \
|
effective_uid = geteuid(); \
|
||||||
real_gid = (b); \
|
real_gid = (b); \
|
||||||
effective_gid = getegid(); \
|
effective_gid = getegid(); \
|
||||||
setreuid(effective_uid, real_uid); \
|
|
||||||
setregid(effective_gid, real_gid); \
|
setregid(effective_gid, real_gid); \
|
||||||
|
setreuid(effective_uid, real_uid); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define PRIV_START {\
|
#define PRIV_START {\
|
||||||
@ -90,8 +96,8 @@ gid_t real_gid, effective_gid;
|
|||||||
setregid(real_gid, effective_gid);
|
setregid(real_gid, effective_gid);
|
||||||
|
|
||||||
#define PRIV_END \
|
#define PRIV_END \
|
||||||
setreuid(effective_uid, real_uid); \
|
|
||||||
setregid(effective_gid, real_gid); \
|
setregid(effective_gid, real_gid); \
|
||||||
|
setreuid(effective_uid, real_uid); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define REDUCE_PRIV(a,b) {\
|
#define REDUCE_PRIV(a,b) {\
|
||||||
|
Loading…
Reference in New Issue
Block a user