xref: /csrg-svn/usr.sbin/lpr/lprm/lprm.c (revision 42802)
122433Sdist /*
222433Sdist  * Copyright (c) 1983 Regents of the University of California.
334203Sbostic  * All rights reserved.
434203Sbostic  *
5*42802Sbostic  * %sccs.include.redist.c%
622433Sdist  */
722433Sdist 
813954Ssam #ifndef lint
922433Sdist char copyright[] =
1022433Sdist "@(#) Copyright (c) 1983 Regents of the University of California.\n\
1122433Sdist  All rights reserved.\n";
1234203Sbostic #endif /* not lint */
1313954Ssam 
1422433Sdist #ifndef lint
15*42802Sbostic static char sccsid[] = "@(#)lprm.c	5.5 (Berkeley) 06/01/90";
1634203Sbostic #endif /* not lint */
1722433Sdist 
1812110Sralph /*
1912110Sralph  * lprm - remove the current user's spool entry
2012110Sralph  *
2112110Sralph  * lprm [-] [[job #] [user] ...]
2212110Sralph  *
2312110Sralph  * Using information in the lock file, lprm will kill the
2412110Sralph  * currently active daemon (if necessary), remove the associated files,
2512110Sralph  * and startup a new daemon.  Priviledged users may remove anyone's spool
2612110Sralph  * entries, otherwise one can only remove their own.
2712110Sralph  */
2812110Sralph 
2912110Sralph #include "lp.h"
3012110Sralph 
3112110Sralph /*
3212110Sralph  * Stuff for handling job specifications
3312110Sralph  */
3412877Sralph char	*user[MAXUSERS];	/* users to process */
3512877Sralph int	users;			/* # of users in user array */
3612877Sralph int	requ[MAXREQUESTS];	/* job number of spool entries */
3712877Sralph int	requests;		/* # of spool requests */
3812877Sralph char	*person;		/* name of person doing lprm */
3912110Sralph 
4012877Sralph static char	luser[16];	/* buffer for person */
4112110Sralph 
4212110Sralph struct passwd *getpwuid();
4312110Sralph 
4412110Sralph main(argc, argv)
4512110Sralph 	char *argv[];
4612110Sralph {
4712110Sralph 	register char *arg;
4812110Sralph 	struct passwd *p;
4912110Sralph 	struct direct **files;
5012110Sralph 	int nitems, assasinated = 0;
5112110Sralph 
5212110Sralph 	name = argv[0];
5312110Sralph 	gethostname(host, sizeof(host));
5425496Seric 	openlog("lpd", 0, LOG_LPR);
5512110Sralph 	if ((p = getpwuid(getuid())) == NULL)
5612110Sralph 		fatal("Who are you?");
5712110Sralph 	if (strlen(p->pw_name) >= sizeof(luser))
5812110Sralph 		fatal("Your name is too long");
5912110Sralph 	strcpy(luser, p->pw_name);
6012110Sralph 	person = luser;
6112110Sralph 	while (--argc) {
6212110Sralph 		if ((arg = *++argv)[0] == '-')
6312110Sralph 			switch (arg[1]) {
6412110Sralph 			case 'P':
6512730Sralph 				if (arg[2])
6612730Sralph 					printer = &arg[2];
6712730Sralph 				else if (argc > 1) {
6812730Sralph 					argc--;
6912730Sralph 					printer = *++argv;
7012730Sralph 				}
7112110Sralph 				break;
7212110Sralph 			case '\0':
7312110Sralph 				if (!users) {
7412110Sralph 					users = -1;
7512110Sralph 					break;
7612110Sralph 				}
7712110Sralph 			default:
7812110Sralph 				usage();
7912110Sralph 			}
8012110Sralph 		else {
8112110Sralph 			if (users < 0)
8212110Sralph 				usage();
8312110Sralph 			if (isdigit(arg[0])) {
8412110Sralph 				if (requests >= MAXREQUESTS)
8512110Sralph 					fatal("Too many requests");
8612110Sralph 				requ[requests++] = atoi(arg);
8712110Sralph 			} else {
8812110Sralph 				if (users >= MAXUSERS)
8912110Sralph 					fatal("Too many users");
9012110Sralph 				user[users++] = arg;
9112110Sralph 			}
9212110Sralph 		}
9312110Sralph 	}
9412110Sralph 	if (printer == NULL && (printer = getenv("PRINTER")) == NULL)
9512110Sralph 		printer = DEFLP;
9612110Sralph 
9712110Sralph 	rmjob();
9812110Sralph }
9912110Sralph 
10012877Sralph static
10112110Sralph usage()
10212110Sralph {
10312110Sralph 	printf("usage: lprm [-] [-Pprinter] [[job #] [user] ...]\n");
10412110Sralph 	exit(2);
10512110Sralph }
106