122433Sdist /* 222433Sdist * Copyright (c) 1983 Regents of the University of California. 334203Sbostic * All rights reserved. 434203Sbostic * 5*56129Selan * Redistribution and use in source and binary forms, with or without 6*56129Selan * modification, are permitted provided that the following conditions 7*56129Selan * are met: 8*56129Selan * 1. Redistributions of source code must retain the above copyright 9*56129Selan * notice, this list of conditions and the following disclaimer. 10*56129Selan * 2. Redistributions in binary form must reproduce the above copyright 11*56129Selan * notice, this list of conditions and the following disclaimer in the 12*56129Selan * documentation and/or other materials provided with the distribution. 13*56129Selan * 3. All advertising materials mentioning features or use of this software 14*56129Selan * must display the following acknowledgement: 15*56129Selan * This product includes software developed by the University of 16*56129Selan * California, Berkeley and its contributors. 17*56129Selan * 4. Neither the name of the University nor the names of its contributors 18*56129Selan * may be used to endorse or promote products derived from this software 19*56129Selan * without specific prior written permission. 20*56129Selan * 21*56129Selan * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22*56129Selan * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23*56129Selan * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24*56129Selan * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25*56129Selan * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26*56129Selan * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27*56129Selan * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28*56129Selan * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29*56129Selan * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30*56129Selan * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31*56129Selan * SUCH DAMAGE. 3222433Sdist */ 3322433Sdist 3413954Ssam #ifndef lint 3522433Sdist char copyright[] = 3622433Sdist "@(#) Copyright (c) 1983 Regents of the University of California.\n\ 3722433Sdist All rights reserved.\n"; 3834203Sbostic #endif /* not lint */ 3913954Ssam 4022433Sdist #ifndef lint 41*56129Selan static char sccsid[] = "@(#)lprm.c 5.8 (Berkeley) 8/6/92"; 4234203Sbostic #endif /* not lint */ 4322433Sdist 4412110Sralph /* 4512110Sralph * lprm - remove the current user's spool entry 4612110Sralph * 4712110Sralph * lprm [-] [[job #] [user] ...] 4812110Sralph * 4912110Sralph * Using information in the lock file, lprm will kill the 5012110Sralph * currently active daemon (if necessary), remove the associated files, 5112110Sralph * and startup a new daemon. Priviledged users may remove anyone's spool 5212110Sralph * entries, otherwise one can only remove their own. 5312110Sralph */ 5412110Sralph 5555477Sbostic #include <sys/param.h> 5655477Sbostic 5755477Sbostic #include <syslog.h> 5855477Sbostic #include <dirent.h> 5955477Sbostic #include <pwd.h> 6055477Sbostic #include <unistd.h> 6155477Sbostic #include <stdlib.h> 6255477Sbostic #include <stdio.h> 6355477Sbostic #include <string.h> 6455477Sbostic #include <ctype.h> 6512110Sralph #include "lp.h" 6655477Sbostic #include "lp.local.h" 6712110Sralph 6812110Sralph /* 6912110Sralph * Stuff for handling job specifications 7012110Sralph */ 71*56129Selan char *person; /* name of person doing lprm */ 72*56129Selan int requ[MAXREQUESTS]; /* job number of spool entries */ 73*56129Selan int requests; /* # of spool requests */ 7412877Sralph char *user[MAXUSERS]; /* users to process */ 75*56129Selan int users; /* # of users in user array */ 7612110Sralph 7712877Sralph static char luser[16]; /* buffer for person */ 7812110Sralph 7955477Sbostic void usage __P((void)); 8055477Sbostic 8155477Sbostic int 8212110Sralph main(argc, argv) 8346916Sbostic int argc; 8412110Sralph char *argv[]; 8512110Sralph { 8612110Sralph register char *arg; 8712110Sralph struct passwd *p; 8812110Sralph 8912110Sralph name = argv[0]; 9012110Sralph gethostname(host, sizeof(host)); 9125496Seric openlog("lpd", 0, LOG_LPR); 9212110Sralph if ((p = getpwuid(getuid())) == NULL) 9312110Sralph fatal("Who are you?"); 9412110Sralph if (strlen(p->pw_name) >= sizeof(luser)) 9512110Sralph fatal("Your name is too long"); 9612110Sralph strcpy(luser, p->pw_name); 9712110Sralph person = luser; 9812110Sralph while (--argc) { 9912110Sralph if ((arg = *++argv)[0] == '-') 10012110Sralph switch (arg[1]) { 10112110Sralph case 'P': 10212730Sralph if (arg[2]) 10312730Sralph printer = &arg[2]; 10412730Sralph else if (argc > 1) { 10512730Sralph argc--; 10612730Sralph printer = *++argv; 10712730Sralph } 10812110Sralph break; 10912110Sralph case '\0': 11012110Sralph if (!users) { 11112110Sralph users = -1; 11212110Sralph break; 11312110Sralph } 11412110Sralph default: 11512110Sralph usage(); 11612110Sralph } 11712110Sralph else { 11812110Sralph if (users < 0) 11912110Sralph usage(); 12012110Sralph if (isdigit(arg[0])) { 12112110Sralph if (requests >= MAXREQUESTS) 12212110Sralph fatal("Too many requests"); 12312110Sralph requ[requests++] = atoi(arg); 12412110Sralph } else { 12512110Sralph if (users >= MAXUSERS) 12612110Sralph fatal("Too many users"); 12712110Sralph user[users++] = arg; 12812110Sralph } 12912110Sralph } 13012110Sralph } 13112110Sralph if (printer == NULL && (printer = getenv("PRINTER")) == NULL) 13212110Sralph printer = DEFLP; 13312110Sralph 13412110Sralph rmjob(); 13555477Sbostic exit(0); 13612110Sralph } 13712110Sralph 13855477Sbostic void 13912110Sralph usage() 14012110Sralph { 14146916Sbostic fprintf(stderr, "usage: lprm [-] [-Pprinter] [[job #] [user] ...]\n"); 14212110Sralph exit(2); 14312110Sralph } 144