lprm.c revision 1.3 1 /*
2 * Copyright (c) 1983, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by the University of
17 * California, Berkeley and its contributors.
18 * 4. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 */
34
35 #ifndef lint
36 static char copyright[] =
37 "@(#) Copyright (c) 1983, 1993\n\
38 The Regents of the University of California. All rights reserved.\n";
39 #endif /* not lint */
40
41 #ifndef lint
42 static char sccsid[] = "@(#)lprm.c 8.1 (Berkeley) 6/6/93";
43 #endif /* not lint */
44
45 /*
46 * lprm - remove the current user's spool entry
47 *
48 * lprm [-] [[job #] [user] ...]
49 *
50 * Using information in the lock file, lprm will kill the
51 * currently active daemon (if necessary), remove the associated files,
52 * and startup a new daemon. Priviledged users may remove anyone's spool
53 * entries, otherwise one can only remove their own.
54 */
55
56 #include <sys/param.h>
57
58 #include <syslog.h>
59 #include <dirent.h>
60 #include <pwd.h>
61 #include <unistd.h>
62 #include <stdlib.h>
63 #include <stdio.h>
64 #include <string.h>
65 #include <ctype.h>
66 #include "lp.h"
67 #include "lp.local.h"
68
69 /*
70 * Stuff for handling job specifications
71 */
72 char *person; /* name of person doing lprm */
73 int requ[MAXREQUESTS]; /* job number of spool entries */
74 int requests; /* # of spool requests */
75 char *user[MAXUSERS]; /* users to process */
76 int users; /* # of users in user array */
77
78 static char luser[16]; /* buffer for person */
79
80 void usage __P((void));
81
82 int
83 main(argc, argv)
84 int argc;
85 char *argv[];
86 {
87 register char *arg;
88 struct passwd *p;
89
90 name = argv[0];
91 gethostname(host, sizeof(host));
92 openlog("lpd", 0, LOG_LPR);
93 if ((p = getpwuid(getuid())) == NULL)
94 fatal("Who are you?");
95 if (strlen(p->pw_name) >= sizeof(luser))
96 fatal("Your name is too long");
97 strcpy(luser, p->pw_name);
98 person = luser;
99 while (--argc) {
100 if ((arg = *++argv)[0] == '-')
101 switch (arg[1]) {
102 case 'P':
103 if (arg[2])
104 printer = &arg[2];
105 else if (argc > 1) {
106 argc--;
107 printer = *++argv;
108 }
109 break;
110 case '\0':
111 if (!users) {
112 users = -1;
113 break;
114 }
115 default:
116 usage();
117 }
118 else {
119 if (users < 0)
120 usage();
121 if (isdigit(arg[0])) {
122 if (requests >= MAXREQUESTS)
123 fatal("Too many requests");
124 requ[requests++] = atoi(arg);
125 } else {
126 if (users >= MAXUSERS)
127 fatal("Too many users");
128 user[users++] = arg;
129 }
130 }
131 }
132 if (printer == NULL && (printer = getenv("PRINTER")) == NULL)
133 printer = DEFLP;
134
135 rmjob();
136 exit(0);
137 }
138
139 void
140 usage()
141 {
142 fprintf(stderr, "usage: lprm [-] [-Pprinter] [[job #] [user] ...]\n");
143 exit(2);
144 }
145