xref: /csrg-svn/usr.sbin/lpr/lprm/lprm.c (revision 34203)
122433Sdist /*
222433Sdist  * Copyright (c) 1983 Regents of the University of California.
3*34203Sbostic  * All rights reserved.
4*34203Sbostic  *
5*34203Sbostic  * Redistribution and use in source and binary forms are permitted
6*34203Sbostic  * provided that this notice is preserved and that due credit is given
7*34203Sbostic  * to the University of California at Berkeley. The name of the University
8*34203Sbostic  * may not be used to endorse or promote products derived from this
9*34203Sbostic  * software without specific prior written permission. This software
10*34203Sbostic  * is provided ``as is'' without express or implied warranty.
1122433Sdist  */
1222433Sdist 
1313954Ssam #ifndef lint
1422433Sdist char copyright[] =
1522433Sdist "@(#) Copyright (c) 1983 Regents of the University of California.\n\
1622433Sdist  All rights reserved.\n";
17*34203Sbostic #endif /* not lint */
1813954Ssam 
1922433Sdist #ifndef lint
20*34203Sbostic static char sccsid[] = "@(#)lprm.c	5.3 (Berkeley) 05/05/88";
21*34203Sbostic #endif /* not lint */
2222433Sdist 
2312110Sralph /*
2412110Sralph  * lprm - remove the current user's spool entry
2512110Sralph  *
2612110Sralph  * lprm [-] [[job #] [user] ...]
2712110Sralph  *
2812110Sralph  * Using information in the lock file, lprm will kill the
2912110Sralph  * currently active daemon (if necessary), remove the associated files,
3012110Sralph  * and startup a new daemon.  Priviledged users may remove anyone's spool
3112110Sralph  * entries, otherwise one can only remove their own.
3212110Sralph  */
3312110Sralph 
3412110Sralph #include "lp.h"
3512110Sralph 
3612110Sralph /*
3712110Sralph  * Stuff for handling job specifications
3812110Sralph  */
3912877Sralph char	*user[MAXUSERS];	/* users to process */
4012877Sralph int	users;			/* # of users in user array */
4112877Sralph int	requ[MAXREQUESTS];	/* job number of spool entries */
4212877Sralph int	requests;		/* # of spool requests */
4312877Sralph char	*person;		/* name of person doing lprm */
4412110Sralph 
4512877Sralph static char	luser[16];	/* buffer for person */
4612110Sralph 
4712110Sralph struct passwd *getpwuid();
4812110Sralph 
4912110Sralph main(argc, argv)
5012110Sralph 	char *argv[];
5112110Sralph {
5212110Sralph 	register char *arg;
5312110Sralph 	struct passwd *p;
5412110Sralph 	struct direct **files;
5512110Sralph 	int nitems, assasinated = 0;
5612110Sralph 
5712110Sralph 	name = argv[0];
5812110Sralph 	gethostname(host, sizeof(host));
5925496Seric 	openlog("lpd", 0, LOG_LPR);
6012110Sralph 	if ((p = getpwuid(getuid())) == NULL)
6112110Sralph 		fatal("Who are you?");
6212110Sralph 	if (strlen(p->pw_name) >= sizeof(luser))
6312110Sralph 		fatal("Your name is too long");
6412110Sralph 	strcpy(luser, p->pw_name);
6512110Sralph 	person = luser;
6612110Sralph 	while (--argc) {
6712110Sralph 		if ((arg = *++argv)[0] == '-')
6812110Sralph 			switch (arg[1]) {
6912110Sralph 			case 'P':
7012730Sralph 				if (arg[2])
7112730Sralph 					printer = &arg[2];
7212730Sralph 				else if (argc > 1) {
7312730Sralph 					argc--;
7412730Sralph 					printer = *++argv;
7512730Sralph 				}
7612110Sralph 				break;
7712110Sralph 			case '\0':
7812110Sralph 				if (!users) {
7912110Sralph 					users = -1;
8012110Sralph 					break;
8112110Sralph 				}
8212110Sralph 			default:
8312110Sralph 				usage();
8412110Sralph 			}
8512110Sralph 		else {
8612110Sralph 			if (users < 0)
8712110Sralph 				usage();
8812110Sralph 			if (isdigit(arg[0])) {
8912110Sralph 				if (requests >= MAXREQUESTS)
9012110Sralph 					fatal("Too many requests");
9112110Sralph 				requ[requests++] = atoi(arg);
9212110Sralph 			} else {
9312110Sralph 				if (users >= MAXUSERS)
9412110Sralph 					fatal("Too many users");
9512110Sralph 				user[users++] = arg;
9612110Sralph 			}
9712110Sralph 		}
9812110Sralph 	}
9912110Sralph 	if (printer == NULL && (printer = getenv("PRINTER")) == NULL)
10012110Sralph 		printer = DEFLP;
10112110Sralph 
10212110Sralph 	rmjob();
10312110Sralph }
10412110Sralph 
10512877Sralph static
10612110Sralph usage()
10712110Sralph {
10812110Sralph 	printf("usage: lprm [-] [-Pprinter] [[job #] [user] ...]\n");
10912110Sralph 	exit(2);
11012110Sralph }
111