xref: /original-bsd/usr.sbin/lpr/lprm/lprm.c (revision 8ca26665)
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.5 (Berkeley) 06/01/90";
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 struct passwd *getpwuid();
43 
44 main(argc, argv)
45 	char *argv[];
46 {
47 	register char *arg;
48 	struct passwd *p;
49 	struct direct **files;
50 	int nitems, assasinated = 0;
51 
52 	name = argv[0];
53 	gethostname(host, sizeof(host));
54 	openlog("lpd", 0, LOG_LPR);
55 	if ((p = getpwuid(getuid())) == NULL)
56 		fatal("Who are you?");
57 	if (strlen(p->pw_name) >= sizeof(luser))
58 		fatal("Your name is too long");
59 	strcpy(luser, p->pw_name);
60 	person = luser;
61 	while (--argc) {
62 		if ((arg = *++argv)[0] == '-')
63 			switch (arg[1]) {
64 			case 'P':
65 				if (arg[2])
66 					printer = &arg[2];
67 				else if (argc > 1) {
68 					argc--;
69 					printer = *++argv;
70 				}
71 				break;
72 			case '\0':
73 				if (!users) {
74 					users = -1;
75 					break;
76 				}
77 			default:
78 				usage();
79 			}
80 		else {
81 			if (users < 0)
82 				usage();
83 			if (isdigit(arg[0])) {
84 				if (requests >= MAXREQUESTS)
85 					fatal("Too many requests");
86 				requ[requests++] = atoi(arg);
87 			} else {
88 				if (users >= MAXUSERS)
89 					fatal("Too many users");
90 				user[users++] = arg;
91 			}
92 		}
93 	}
94 	if (printer == NULL && (printer = getenv("PRINTER")) == NULL)
95 		printer = DEFLP;
96 
97 	rmjob();
98 }
99 
100 static
101 usage()
102 {
103 	printf("usage: lprm [-] [-Pprinter] [[job #] [user] ...]\n");
104 	exit(2);
105 }
106