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