xref: /original-bsd/usr.sbin/lpr/lprm/lprm.c (revision e59fb703)
1 /*
2  * Copyright (c) 1983 Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  */
7 
8 #ifndef lint
9 char copyright[] =
10 "@(#) Copyright (c) 1983 Regents of the University of California.\n\
11  All rights reserved.\n";
12 #endif /* not lint */
13 
14 #ifndef lint
15 static char sccsid[] = "@(#)lprm.c	5.6 (Berkeley) 03/02/91";
16 #endif /* not lint */
17 
18 /*
19  * lprm - remove the current user's spool entry
20  *
21  * lprm [-] [[job #] [user] ...]
22  *
23  * Using information in the lock file, lprm will kill the
24  * currently active daemon (if necessary), remove the associated files,
25  * and startup a new daemon.  Priviledged users may remove anyone's spool
26  * entries, otherwise one can only remove their own.
27  */
28 
29 #include "lp.h"
30 
31 /*
32  * Stuff for handling job specifications
33  */
34 char	*user[MAXUSERS];	/* users to process */
35 int	users;			/* # of users in user array */
36 int	requ[MAXREQUESTS];	/* job number of spool entries */
37 int	requests;		/* # of spool requests */
38 char	*person;		/* name of person doing lprm */
39 
40 static char	luser[16];	/* buffer for person */
41 
42 main(argc, argv)
43 	int argc;
44 	char *argv[];
45 {
46 	register char *arg;
47 	struct passwd *p;
48 	struct direct **files;
49 	int nitems, assasinated = 0;
50 
51 	name = argv[0];
52 	gethostname(host, sizeof(host));
53 	openlog("lpd", 0, LOG_LPR);
54 	if ((p = getpwuid(getuid())) == NULL)
55 		fatal("Who are you?");
56 	if (strlen(p->pw_name) >= sizeof(luser))
57 		fatal("Your name is too long");
58 	strcpy(luser, p->pw_name);
59 	person = luser;
60 	while (--argc) {
61 		if ((arg = *++argv)[0] == '-')
62 			switch (arg[1]) {
63 			case 'P':
64 				if (arg[2])
65 					printer = &arg[2];
66 				else if (argc > 1) {
67 					argc--;
68 					printer = *++argv;
69 				}
70 				break;
71 			case '\0':
72 				if (!users) {
73 					users = -1;
74 					break;
75 				}
76 			default:
77 				usage();
78 			}
79 		else {
80 			if (users < 0)
81 				usage();
82 			if (isdigit(arg[0])) {
83 				if (requests >= MAXREQUESTS)
84 					fatal("Too many requests");
85 				requ[requests++] = atoi(arg);
86 			} else {
87 				if (users >= MAXUSERS)
88 					fatal("Too many users");
89 				user[users++] = arg;
90 			}
91 		}
92 	}
93 	if (printer == NULL && (printer = getenv("PRINTER")) == NULL)
94 		printer = DEFLP;
95 
96 	rmjob();
97 }
98 
99 usage()
100 {
101 	fprintf(stderr, "usage: lprm [-] [-Pprinter] [[job #] [user] ...]\n");
102 	exit(2);
103 }
104