xref: /csrg-svn/usr.sbin/lpr/lprm/lprm.c (revision 12877)
1*12877Sralph /*	lprm.c	4.4	83/06/02	*/
212110Sralph /*
312110Sralph  * lprm - remove the current user's spool entry
412110Sralph  *
512110Sralph  * lprm [-] [[job #] [user] ...]
612110Sralph  *
712110Sralph  * Using information in the lock file, lprm will kill the
812110Sralph  * currently active daemon (if necessary), remove the associated files,
912110Sralph  * and startup a new daemon.  Priviledged users may remove anyone's spool
1012110Sralph  * entries, otherwise one can only remove their own.
1112110Sralph  */
1212110Sralph 
1312110Sralph #include "lp.h"
1412110Sralph 
1512110Sralph /*
1612110Sralph  * Stuff for handling job specifications
1712110Sralph  */
18*12877Sralph char	*user[MAXUSERS];	/* users to process */
19*12877Sralph int	users;			/* # of users in user array */
20*12877Sralph int	requ[MAXREQUESTS];	/* job number of spool entries */
21*12877Sralph int	requests;		/* # of spool requests */
22*12877Sralph char	*person;		/* name of person doing lprm */
2312110Sralph 
24*12877Sralph static char	luser[16];	/* buffer for person */
2512110Sralph 
2612110Sralph struct passwd *getpwuid();
2712110Sralph 
2812110Sralph main(argc, argv)
2912110Sralph 	char *argv[];
3012110Sralph {
3112110Sralph 	register char *arg;
3212110Sralph 	struct passwd *p;
3312110Sralph 	struct direct **files;
3412110Sralph 	int nitems, assasinated = 0;
3512110Sralph 
3612110Sralph 	name = argv[0];
3712110Sralph 	gethostname(host, sizeof(host));
3812110Sralph 	if ((p = getpwuid(getuid())) == NULL)
3912110Sralph 		fatal("Who are you?");
4012110Sralph 	if (strlen(p->pw_name) >= sizeof(luser))
4112110Sralph 		fatal("Your name is too long");
4212110Sralph 	strcpy(luser, p->pw_name);
4312110Sralph 	person = luser;
4412110Sralph 	while (--argc) {
4512110Sralph 		if ((arg = *++argv)[0] == '-')
4612110Sralph 			switch (arg[1]) {
4712110Sralph 			case 'P':
4812730Sralph 				if (arg[2])
4912730Sralph 					printer = &arg[2];
5012730Sralph 				else if (argc > 1) {
5112730Sralph 					argc--;
5212730Sralph 					printer = *++argv;
5312730Sralph 				}
5412110Sralph 				break;
5512110Sralph 			case '\0':
5612110Sralph 				if (!users) {
5712110Sralph 					users = -1;
5812110Sralph 					break;
5912110Sralph 				}
6012110Sralph 			default:
6112110Sralph 				usage();
6212110Sralph 			}
6312110Sralph 		else {
6412110Sralph 			if (users < 0)
6512110Sralph 				usage();
6612110Sralph 			if (isdigit(arg[0])) {
6712110Sralph 				if (requests >= MAXREQUESTS)
6812110Sralph 					fatal("Too many requests");
6912110Sralph 				requ[requests++] = atoi(arg);
7012110Sralph 			} else {
7112110Sralph 				if (users >= MAXUSERS)
7212110Sralph 					fatal("Too many users");
7312110Sralph 				user[users++] = arg;
7412110Sralph 			}
7512110Sralph 		}
7612110Sralph 	}
7712110Sralph 	if (printer == NULL && (printer = getenv("PRINTER")) == NULL)
7812110Sralph 		printer = DEFLP;
7912110Sralph 
8012110Sralph 	rmjob();
8112110Sralph }
8212110Sralph 
83*12877Sralph static
8412110Sralph usage()
8512110Sralph {
8612110Sralph 	printf("usage: lprm [-] [-Pprinter] [[job #] [user] ...]\n");
8712110Sralph 	exit(2);
8812110Sralph }
89