xref: /original-bsd/usr.sbin/lpr/lprm/lprm.c (revision 64e9b6bb)
1c637876cSdist /*
2*64e9b6bbSbostic  * Copyright (c) 1983, 1993
3*64e9b6bbSbostic  *	The Regents of the University of California.  All rights reserved.
4b1f76507Sbostic  *
54ac68488Selan  *
6af2af436Selan  * %sccs.include.redist.c%
7c637876cSdist  */
8c637876cSdist 
9bcfd12f6Ssam #ifndef lint
10fd60a40fSelan static char copyright[] =
11*64e9b6bbSbostic "@(#) Copyright (c) 1983, 1993\n\
12*64e9b6bbSbostic 	The Regents of the University of California.  All rights reserved.\n";
13b1f76507Sbostic #endif /* not lint */
14c637876cSdist 
15c637876cSdist #ifndef lint
16*64e9b6bbSbostic static char sccsid[] = "@(#)lprm.c	8.1 (Berkeley) 06/06/93";
17b1f76507Sbostic #endif /* not lint */
18bcfd12f6Ssam 
194b270adcSralph /*
204b270adcSralph  * lprm - remove the current user's spool entry
214b270adcSralph  *
224b270adcSralph  * lprm [-] [[job #] [user] ...]
234b270adcSralph  *
244b270adcSralph  * Using information in the lock file, lprm will kill the
254b270adcSralph  * currently active daemon (if necessary), remove the associated files,
264b270adcSralph  * and startup a new daemon.  Priviledged users may remove anyone's spool
274b270adcSralph  * entries, otherwise one can only remove their own.
284b270adcSralph  */
294b270adcSralph 
30a35143e1Sbostic #include <sys/param.h>
31a35143e1Sbostic 
32a35143e1Sbostic #include <syslog.h>
33a35143e1Sbostic #include <dirent.h>
34a35143e1Sbostic #include <pwd.h>
35a35143e1Sbostic #include <unistd.h>
36a35143e1Sbostic #include <stdlib.h>
37a35143e1Sbostic #include <stdio.h>
38a35143e1Sbostic #include <string.h>
39a35143e1Sbostic #include <ctype.h>
404b270adcSralph #include "lp.h"
41a35143e1Sbostic #include "lp.local.h"
424b270adcSralph 
434b270adcSralph /*
444b270adcSralph  * Stuff for handling job specifications
454b270adcSralph  */
464ac68488Selan char	*person;		/* name of person doing lprm */
474b270adcSralph int	 requ[MAXREQUESTS];	/* job number of spool entries */
484b270adcSralph int	 requests;		/* # of spool requests */
494ac68488Selan char	*user[MAXUSERS];	/* users to process */
504ac68488Selan int	 users;			/* # of users in user array */
514b270adcSralph 
528b886c7dSralph static char	luser[16];	/* buffer for person */
534b270adcSralph 
54a35143e1Sbostic void usage __P((void));
55a35143e1Sbostic 
56a35143e1Sbostic int
main(argc,argv)574b270adcSralph main(argc, argv)
58553af9c5Sbostic 	int argc;
594b270adcSralph 	char *argv[];
604b270adcSralph {
614b270adcSralph 	register char *arg;
624b270adcSralph 	struct passwd *p;
634b270adcSralph 
644b270adcSralph 	name = argv[0];
654b270adcSralph 	gethostname(host, sizeof(host));
6624dd0490Seric 	openlog("lpd", 0, LOG_LPR);
674b270adcSralph 	if ((p = getpwuid(getuid())) == NULL)
684b270adcSralph 		fatal("Who are you?");
694b270adcSralph 	if (strlen(p->pw_name) >= sizeof(luser))
704b270adcSralph 		fatal("Your name is too long");
714b270adcSralph 	strcpy(luser, p->pw_name);
724b270adcSralph 	person = luser;
734b270adcSralph 	while (--argc) {
744b270adcSralph 		if ((arg = *++argv)[0] == '-')
754b270adcSralph 			switch (arg[1]) {
764b270adcSralph 			case 'P':
77d776782bSralph 				if (arg[2])
784b270adcSralph 					printer = &arg[2];
79d776782bSralph 				else if (argc > 1) {
80d776782bSralph 					argc--;
81d776782bSralph 					printer = *++argv;
82d776782bSralph 				}
834b270adcSralph 				break;
844b270adcSralph 			case '\0':
854b270adcSralph 				if (!users) {
864b270adcSralph 					users = -1;
874b270adcSralph 					break;
884b270adcSralph 				}
894b270adcSralph 			default:
904b270adcSralph 				usage();
914b270adcSralph 			}
924b270adcSralph 		else {
934b270adcSralph 			if (users < 0)
944b270adcSralph 				usage();
954b270adcSralph 			if (isdigit(arg[0])) {
964b270adcSralph 				if (requests >= MAXREQUESTS)
974b270adcSralph 					fatal("Too many requests");
984b270adcSralph 				requ[requests++] = atoi(arg);
994b270adcSralph 			} else {
1004b270adcSralph 				if (users >= MAXUSERS)
1014b270adcSralph 					fatal("Too many users");
1024b270adcSralph 				user[users++] = arg;
1034b270adcSralph 			}
1044b270adcSralph 		}
1054b270adcSralph 	}
1064b270adcSralph 	if (printer == NULL && (printer = getenv("PRINTER")) == NULL)
1074b270adcSralph 		printer = DEFLP;
1084b270adcSralph 
1094b270adcSralph 	rmjob();
110a35143e1Sbostic 	exit(0);
1114b270adcSralph }
1124b270adcSralph 
113a35143e1Sbostic void
usage()1144b270adcSralph usage()
1154b270adcSralph {
116553af9c5Sbostic 	fprintf(stderr, "usage: lprm [-] [-Pprinter] [[job #] [user] ...]\n");
1174b270adcSralph 	exit(2);
1184b270adcSralph }
119