1 | /* |
---|
2 | * Copyright (c) 1983 Regents of the University of California. |
---|
3 | * All rights reserved. The Berkeley software License Agreement |
---|
4 | * specifies the terms and conditions for redistribution. |
---|
5 | */ |
---|
6 | |
---|
7 | #ifndef lint |
---|
8 | char copyright[] = |
---|
9 | "@(#) Copyright (c) 1983 Regents of the University of California.\n\ |
---|
10 | All rights reserved.\n"; |
---|
11 | #endif not lint |
---|
12 | |
---|
13 | #ifndef lint |
---|
14 | static char sccsid[] = "@(#)lprm.c 5.2 (Berkeley) 11/17/85"; |
---|
15 | #endif not lint |
---|
16 | |
---|
17 | #ifdef OPERATOR |
---|
18 | #define GETUID geteuid |
---|
19 | #else |
---|
20 | #define GETUID getuid |
---|
21 | #endif |
---|
22 | |
---|
23 | /* |
---|
24 | * lprm - remove the current user's spool entry |
---|
25 | * |
---|
26 | * lprm [-] [[job #] [user] ...] |
---|
27 | * |
---|
28 | * Using information in the lock file, lprm will kill the |
---|
29 | * currently active daemon (if necessary), remove the associated files, |
---|
30 | * and startup a new daemon. Priviledged users may remove anyone's spool |
---|
31 | * entries, otherwise one can only remove their own. |
---|
32 | * A special version of lprm can be compiled with OPERATOR #defined that will |
---|
33 | * allow anyone to access it as the superuser. It also logs all such actions. |
---|
34 | * o_lprm should be installed suid root, group execute operator only. |
---|
35 | */ |
---|
36 | |
---|
37 | #include "lp.h" |
---|
38 | |
---|
39 | #if defined(KERBEROS) |
---|
40 | int use_kerberos; |
---|
41 | int kerberos_override = -1; |
---|
42 | #endif /* KERBEROS */ |
---|
43 | |
---|
44 | /* |
---|
45 | * Stuff for handling job specifications |
---|
46 | */ |
---|
47 | char *user[MAXUSERS]; /* users to process */ |
---|
48 | int users; /* # of users in user array */ |
---|
49 | int requ[MAXREQUESTS]; /* job number of spool entries */ |
---|
50 | int requests; /* # of spool requests */ |
---|
51 | char *person; /* name of person doing lprm */ |
---|
52 | |
---|
53 | static char luser[16]; /* buffer for person */ |
---|
54 | |
---|
55 | struct passwd *getpwuid(); |
---|
56 | |
---|
57 | main(argc, argv) |
---|
58 | char *argv[]; |
---|
59 | { |
---|
60 | register char *arg; |
---|
61 | struct passwd *p; |
---|
62 | struct hostent *hp; |
---|
63 | |
---|
64 | #ifdef OPERATOR |
---|
65 | #ifdef LOG_AUTH |
---|
66 | openlog("lprm", 0, LOG_AUTH); |
---|
67 | #else |
---|
68 | openlog("lprm", 0); |
---|
69 | #endif |
---|
70 | #endif |
---|
71 | |
---|
72 | name = argv[0]; |
---|
73 | gethostname(host, sizeof(host)); |
---|
74 | hp = gethostbyname(host); |
---|
75 | if (hp) strcpy(host, hp -> h_name); |
---|
76 | |
---|
77 | #ifndef OPERATOR |
---|
78 | #ifdef LOG_LPR |
---|
79 | openlog("lprm", 0, LOG_LPR); |
---|
80 | #else |
---|
81 | openlog("lprm", 0); |
---|
82 | #endif |
---|
83 | #endif |
---|
84 | |
---|
85 | if ((p = getpwuid(GETUID())) == NULL) |
---|
86 | fatal("Who are you?"); |
---|
87 | if (strlen(p->pw_name) >= sizeof(luser)) |
---|
88 | fatal("Your name is too long"); |
---|
89 | strcpy(luser, p->pw_name); |
---|
90 | person = luser; |
---|
91 | while (--argc) { |
---|
92 | if ((arg = *++argv)[0] == '-') |
---|
93 | switch (arg[1]) { |
---|
94 | case 'P': |
---|
95 | if (arg[2]) |
---|
96 | printer = &arg[2]; |
---|
97 | else if (argc > 1) { |
---|
98 | argc--; |
---|
99 | printer = *++argv; |
---|
100 | } |
---|
101 | break; |
---|
102 | #if defined(KERBEROS) |
---|
103 | case 'u': |
---|
104 | kerberos_override = 0; |
---|
105 | break; |
---|
106 | case 'k': |
---|
107 | kerberos_override = 1; |
---|
108 | break; |
---|
109 | #endif /* KERBEROS */ |
---|
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 | #ifdef OPERATOR |
---|
135 | log(requ, requests, user, users, printer); |
---|
136 | #endif |
---|
137 | rmjob(); |
---|
138 | } |
---|
139 | |
---|
140 | static |
---|
141 | usage() |
---|
142 | { |
---|
143 | printf("usage: lprm [-] [-Pprinter] [[job #] [user] ...]\n"); |
---|
144 | exit(2); |
---|
145 | } |
---|
146 | #ifdef OPERATOR |
---|
147 | log(jobs, jobnums, users, usernums, printer) |
---|
148 | int jobs[], jobnums; |
---|
149 | char *users[]; |
---|
150 | int usernums; |
---|
151 | char *printer; |
---|
152 | { |
---|
153 | struct passwd *pwentry; |
---|
154 | char *name; |
---|
155 | char logbuf[512]; |
---|
156 | char scratch[512]; |
---|
157 | register int i; |
---|
158 | /* note getuid() returns real uid */ |
---|
159 | pwentry = getpwuid(getuid()); /* get password entry for invoker */ |
---|
160 | name = pwentry->pw_name; /* get his name */ |
---|
161 | |
---|
162 | sprintf(logbuf,"%s LPRM'd ",name); |
---|
163 | if (jobnums > 0) { |
---|
164 | strcat(logbuf,"jobs "); |
---|
165 | for (i=0; i<jobnums; i++) { |
---|
166 | sprintf(scratch, "%d ",jobs[i]); |
---|
167 | strcat(logbuf, scratch); |
---|
168 | } |
---|
169 | } |
---|
170 | if (usernums > 0) { |
---|
171 | if (jobnums > 0) { |
---|
172 | strcat(logbuf,"and "); |
---|
173 | } |
---|
174 | strcat(logbuf, "users "); |
---|
175 | for (i=0; i<usernums; i++) { |
---|
176 | sprintf(scratch, "%s ",users[i]); |
---|
177 | strcat(logbuf, scratch); |
---|
178 | } |
---|
179 | } |
---|
180 | sprintf(scratch, "on printer %s.",printer); |
---|
181 | strcat(logbuf, scratch); |
---|
182 | |
---|
183 | syslog(LOG_INFO, logbuf); |
---|
184 | return(0); |
---|
185 | } |
---|
186 | #endif |
---|