atrm.c revision 2b52f2afd5bf4e315cee202285165b6ff78cc6c2
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* Copyright (c) 1983 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* synopsis: atrm [-f] [-i] [-a] [[job #] [user] ...]
*
*
* Remove "at" jobs.
*/
#include <stdio.h>
#include <pwd.h>
#include <ctype.h>
#include <dirent.h>
#include <errno.h>
#include <unistd.h>
#include <locale.h>
#include <strings.h>
#include <stdlib.h>
#include <libintl.h>
#include "cron.h"
#include "getresponse.h"
extern char *errmsg();
extern void audit_at_delete(char *, char *, int);
#define SUPERUSER 0 /* is user super-user? */
#define CANTCD "can't change directory to the at directory"
#define NOREADDIR "can't read the at directory"
int fflag = 0; /* suppress announcements? */
int iflag = 0; /* run interactively? */
#define INVALIDUSER "you are not a valid user (no entry in /etc/passwd)"
#define NOTALLOWED "you are not authorized to use at. Sorry."
#define NAMETOOLONG "login name too long"
static void usage(void);
static void atabortperror(char *msg);
int
{
int i; /* for loop index */
int numjobs; /* # of jobs in spooling area */
int allflag = 0; /* remove all jobs belonging to user? */
int jobexists; /* does a requested job exist? */
char *pp;
/*
* If job number, user name, or "-" is not specified, just print
* usage info and exit.
*/
(void) textdomain(TEXT_DOMAIN);
if (argc < 2)
usage();
>= sizeof (NAMETOOLONG))
/*
* Process command line flags.
* Special case the "-" option so that others may be grouped.
*/
*(*argv)++;
while (**argv) {
switch (*(*argv)++) {
case 'a': ++allflag;
break;
case 'f': ++fflag;
break;
case 'i': ++iflag;
break;
default: usage();
}
}
}
/*
* If all jobs are to be removed and extra command line arguments
* are given, print usage info and exit.
*/
usage();
/*
* If only certain jobs are to be removed and no job #'s or user
* names are specified, print usage info and exit.
*/
usage();
/*
* If interactive removal and quiet removal are requested, override
* quiet removal and run interactively.
*/
fflag = 0;
/*
* Move to spooling directory and get a list of the files in the
* spooling area.
*/
/*
* If all jobs belonging to the user are to be removed, compare
* the user's id to the owner of the file. If they match, remove
* the file. If the user is the super-user, don't bother comparing
* the id's. After all files are removed, exit (status 0).
*/
if (allflag) {
for (i = 0; i < numjobs; ++i) {
}
exit(0);
}
/*
* If only certain jobs are to be removed, interpret each command
* line argument. A check is done to see if it is a user's name or
* a job number (inode #). If it's a user's name, compare the argument
* to the files owner. If it's a job number, compare the argument to
* the file name. In either case, if a match occurs, try to
* remove the file.
*/
while (argc--) {
jobexists = 0;
for (i = 0; i < numjobs; ++i) {
/* if the inode number is 0, this entry was removed */
continue;
/*
* the uid of the owner of the file......
*/
continue;
/*
* otherwise, we assume that the argv is a job # and
* thus compare argv to the file name.
*/
} else {
continue;
}
++jobexists;
/*
* if the entry is ultimately removed, don't
* try to remove it again later.
*/
user)) {
}
}
/*
* If a requested argument doesn't exist, print a message.
*/
*argv);
}
++argv;
}
return (0);
}
/*
* Print usage info and exit.
*/
static void
usage(void)
{
exit(1);
}
/*
* Remove an entry from the queue. The access of the file is checked for
* write permission (since all jobs are mode 644). If access is granted,
* unlink the file. If the fflag (suppress announcements) is not set,
* print the job number that we are removing and the result of the access
* check (either "permission denied" or "removed"). If we are running
* interactively (iflag), prompt the user before we unlink the file. If
* it is removed. Return TRUE if file removed, else FALSE.
*/
int
{
char *pp;
int r;
if (init_yes() < 0) {
exit(1);
}
if (!fflag)
if (!fflag) {
printf("permission denied\n");
}
return (0);
} else {
if (iflag) {
printf("\t(owned by ");
printf(") ");
}
if (yes() == 0)
return (0);
}
sizeof (login))
}
if (!fflag) {
}
return (0);
}
printf("removed\n");
return (1);
}
}
/*
* Print the owner of the job. This is the owner of the spoolfile.
* If we run into trouble getting the name, we'll just print "???".
*/
static void
{
char *getname();
return;
}
}
int
int (*sortfunc)())
{
int numjobs;
int i;
extern int filewanted(); /* should a file be listed in queue? */
/*
* Get a list of the files in the spooling area.
*/
if ((statlist =
== NULL)
atabort("Out of memory");
/*
* Build an array of pointers to the file stats for all jobs in
* the spooling area.
*/
for (i = 0; i < numjobs; ++i) {
atabort("Out of memory");
continue;
}
}
return (numjobs);
}
/*
*/
char *
{
return ("???");
}
static void
{
}
static void
{
}
static void
{
}
static void
{
exit(1);
}
static void
atabortperror(char *msg)
{
exit(1);
}