xref: /csrg-svn/usr.sbin/lpr/lprm/lprm.c (revision 25496)
122433Sdist /*
222433Sdist  * Copyright (c) 1983 Regents of the University of California.
322433Sdist  * All rights reserved.  The Berkeley software License Agreement
422433Sdist  * specifies the terms and conditions for redistribution.
522433Sdist  */
622433Sdist 
713954Ssam #ifndef lint
822433Sdist char copyright[] =
922433Sdist "@(#) Copyright (c) 1983 Regents of the University of California.\n\
1022433Sdist  All rights reserved.\n";
1122433Sdist #endif not lint
1213954Ssam 
1322433Sdist #ifndef lint
14*25496Seric static char sccsid[] = "@(#)lprm.c	5.2 (Berkeley) 11/17/85";
1522433Sdist #endif not lint
1622433Sdist 
1712110Sralph /*
1812110Sralph  * lprm - remove the current user's spool entry
1912110Sralph  *
2012110Sralph  * lprm [-] [[job #] [user] ...]
2112110Sralph  *
2212110Sralph  * Using information in the lock file, lprm will kill the
2312110Sralph  * currently active daemon (if necessary), remove the associated files,
2412110Sralph  * and startup a new daemon.  Priviledged users may remove anyone's spool
2512110Sralph  * entries, otherwise one can only remove their own.
2612110Sralph  */
2712110Sralph 
2812110Sralph #include "lp.h"
2912110Sralph 
3012110Sralph /*
3112110Sralph  * Stuff for handling job specifications
3212110Sralph  */
3312877Sralph char	*user[MAXUSERS];	/* users to process */
3412877Sralph int	users;			/* # of users in user array */
3512877Sralph int	requ[MAXREQUESTS];	/* job number of spool entries */
3612877Sralph int	requests;		/* # of spool requests */
3712877Sralph char	*person;		/* name of person doing lprm */
3812110Sralph 
3912877Sralph static char	luser[16];	/* buffer for person */
4012110Sralph 
4112110Sralph struct passwd *getpwuid();
4212110Sralph 
4312110Sralph main(argc, argv)
4412110Sralph 	char *argv[];
4512110Sralph {
4612110Sralph 	register char *arg;
4712110Sralph 	struct passwd *p;
4812110Sralph 	struct direct **files;
4912110Sralph 	int nitems, assasinated = 0;
5012110Sralph 
5112110Sralph 	name = argv[0];
5212110Sralph 	gethostname(host, sizeof(host));
53*25496Seric 	openlog("lpd", 0, LOG_LPR);
5412110Sralph 	if ((p = getpwuid(getuid())) == NULL)
5512110Sralph 		fatal("Who are you?");
5612110Sralph 	if (strlen(p->pw_name) >= sizeof(luser))
5712110Sralph 		fatal("Your name is too long");
5812110Sralph 	strcpy(luser, p->pw_name);
5912110Sralph 	person = luser;
6012110Sralph 	while (--argc) {
6112110Sralph 		if ((arg = *++argv)[0] == '-')
6212110Sralph 			switch (arg[1]) {
6312110Sralph 			case 'P':
6412730Sralph 				if (arg[2])
6512730Sralph 					printer = &arg[2];
6612730Sralph 				else if (argc > 1) {
6712730Sralph 					argc--;
6812730Sralph 					printer = *++argv;
6912730Sralph 				}
7012110Sralph 				break;
7112110Sralph 			case '\0':
7212110Sralph 				if (!users) {
7312110Sralph 					users = -1;
7412110Sralph 					break;
7512110Sralph 				}
7612110Sralph 			default:
7712110Sralph 				usage();
7812110Sralph 			}
7912110Sralph 		else {
8012110Sralph 			if (users < 0)
8112110Sralph 				usage();
8212110Sralph 			if (isdigit(arg[0])) {
8312110Sralph 				if (requests >= MAXREQUESTS)
8412110Sralph 					fatal("Too many requests");
8512110Sralph 				requ[requests++] = atoi(arg);
8612110Sralph 			} else {
8712110Sralph 				if (users >= MAXUSERS)
8812110Sralph 					fatal("Too many users");
8912110Sralph 				user[users++] = arg;
9012110Sralph 			}
9112110Sralph 		}
9212110Sralph 	}
9312110Sralph 	if (printer == NULL && (printer = getenv("PRINTER")) == NULL)
9412110Sralph 		printer = DEFLP;
9512110Sralph 
9612110Sralph 	rmjob();
9712110Sralph }
9812110Sralph 
9912877Sralph static
10012110Sralph usage()
10112110Sralph {
10212110Sralph 	printf("usage: lprm [-] [-Pprinter] [[job #] [user] ...]\n");
10312110Sralph 	exit(2);
10412110Sralph }
105