xref: /csrg-svn/usr.sbin/lpr/lprm/lprm.c (revision 61849)
122433Sdist /*
2*61849Sbostic  * Copyright (c) 1983, 1993
3*61849Sbostic  *	The Regents of the University of California.  All rights reserved.
434203Sbostic  *
556129Selan  *
656254Selan  * %sccs.include.redist.c%
722433Sdist  */
822433Sdist 
913954Ssam #ifndef lint
1056268Selan static char copyright[] =
11*61849Sbostic "@(#) Copyright (c) 1983, 1993\n\
12*61849Sbostic 	The Regents of the University of California.  All rights reserved.\n";
1334203Sbostic #endif /* not lint */
1413954Ssam 
1522433Sdist #ifndef lint
16*61849Sbostic static char sccsid[] = "@(#)lprm.c	8.1 (Berkeley) 06/06/93";
1734203Sbostic #endif /* not lint */
1822433Sdist 
1912110Sralph /*
2012110Sralph  * lprm - remove the current user's spool entry
2112110Sralph  *
2212110Sralph  * lprm [-] [[job #] [user] ...]
2312110Sralph  *
2412110Sralph  * Using information in the lock file, lprm will kill the
2512110Sralph  * currently active daemon (if necessary), remove the associated files,
2612110Sralph  * and startup a new daemon.  Priviledged users may remove anyone's spool
2712110Sralph  * entries, otherwise one can only remove their own.
2812110Sralph  */
2912110Sralph 
3055477Sbostic #include <sys/param.h>
3155477Sbostic 
3255477Sbostic #include <syslog.h>
3355477Sbostic #include <dirent.h>
3455477Sbostic #include <pwd.h>
3555477Sbostic #include <unistd.h>
3655477Sbostic #include <stdlib.h>
3755477Sbostic #include <stdio.h>
3855477Sbostic #include <string.h>
3955477Sbostic #include <ctype.h>
4012110Sralph #include "lp.h"
4155477Sbostic #include "lp.local.h"
4212110Sralph 
4312110Sralph /*
4412110Sralph  * Stuff for handling job specifications
4512110Sralph  */
4656129Selan char	*person;		/* name of person doing lprm */
4756129Selan int	 requ[MAXREQUESTS];	/* job number of spool entries */
4856129Selan int	 requests;		/* # of spool requests */
4912877Sralph char	*user[MAXUSERS];	/* users to process */
5056129Selan int	 users;			/* # of users in user array */
5112110Sralph 
5212877Sralph static char	luser[16];	/* buffer for person */
5312110Sralph 
5455477Sbostic void usage __P((void));
5555477Sbostic 
5655477Sbostic int
main(argc,argv)5712110Sralph main(argc, argv)
5846916Sbostic 	int argc;
5912110Sralph 	char *argv[];
6012110Sralph {
6112110Sralph 	register char *arg;
6212110Sralph 	struct passwd *p;
6312110Sralph 
6412110Sralph 	name = argv[0];
6512110Sralph 	gethostname(host, sizeof(host));
6625496Seric 	openlog("lpd", 0, LOG_LPR);
6712110Sralph 	if ((p = getpwuid(getuid())) == NULL)
6812110Sralph 		fatal("Who are you?");
6912110Sralph 	if (strlen(p->pw_name) >= sizeof(luser))
7012110Sralph 		fatal("Your name is too long");
7112110Sralph 	strcpy(luser, p->pw_name);
7212110Sralph 	person = luser;
7312110Sralph 	while (--argc) {
7412110Sralph 		if ((arg = *++argv)[0] == '-')
7512110Sralph 			switch (arg[1]) {
7612110Sralph 			case 'P':
7712730Sralph 				if (arg[2])
7812730Sralph 					printer = &arg[2];
7912730Sralph 				else if (argc > 1) {
8012730Sralph 					argc--;
8112730Sralph 					printer = *++argv;
8212730Sralph 				}
8312110Sralph 				break;
8412110Sralph 			case '\0':
8512110Sralph 				if (!users) {
8612110Sralph 					users = -1;
8712110Sralph 					break;
8812110Sralph 				}
8912110Sralph 			default:
9012110Sralph 				usage();
9112110Sralph 			}
9212110Sralph 		else {
9312110Sralph 			if (users < 0)
9412110Sralph 				usage();
9512110Sralph 			if (isdigit(arg[0])) {
9612110Sralph 				if (requests >= MAXREQUESTS)
9712110Sralph 					fatal("Too many requests");
9812110Sralph 				requ[requests++] = atoi(arg);
9912110Sralph 			} else {
10012110Sralph 				if (users >= MAXUSERS)
10112110Sralph 					fatal("Too many users");
10212110Sralph 				user[users++] = arg;
10312110Sralph 			}
10412110Sralph 		}
10512110Sralph 	}
10612110Sralph 	if (printer == NULL && (printer = getenv("PRINTER")) == NULL)
10712110Sralph 		printer = DEFLP;
10812110Sralph 
10912110Sralph 	rmjob();
11055477Sbostic 	exit(0);
11112110Sralph }
11212110Sralph 
11355477Sbostic void
usage()11412110Sralph usage()
11512110Sralph {
11646916Sbostic 	fprintf(stderr, "usage: lprm [-] [-Pprinter] [[job #] [user] ...]\n");
11712110Sralph 	exit(2);
11812110Sralph }
119