122433Sdist /* 222433Sdist * Copyright (c) 1983 Regents of the University of California. 334203Sbostic * All rights reserved. 434203Sbostic * 542802Sbostic * %sccs.include.redist.c% 622433Sdist */ 722433Sdist 813954Ssam #ifndef lint 922433Sdist char copyright[] = 1022433Sdist "@(#) Copyright (c) 1983 Regents of the University of California.\n\ 1122433Sdist All rights reserved.\n"; 1234203Sbostic #endif /* not lint */ 1313954Ssam 1422433Sdist #ifndef lint 15*55477Sbostic static char sccsid[] = "@(#)lprm.c 5.7 (Berkeley) 07/21/92"; 1634203Sbostic #endif /* not lint */ 1722433Sdist 1812110Sralph /* 1912110Sralph * lprm - remove the current user's spool entry 2012110Sralph * 2112110Sralph * lprm [-] [[job #] [user] ...] 2212110Sralph * 2312110Sralph * Using information in the lock file, lprm will kill the 2412110Sralph * currently active daemon (if necessary), remove the associated files, 2512110Sralph * and startup a new daemon. Priviledged users may remove anyone's spool 2612110Sralph * entries, otherwise one can only remove their own. 2712110Sralph */ 2812110Sralph 29*55477Sbostic #include <sys/param.h> 30*55477Sbostic 31*55477Sbostic #include <syslog.h> 32*55477Sbostic #include <dirent.h> 33*55477Sbostic #include <pwd.h> 34*55477Sbostic #include <unistd.h> 35*55477Sbostic #include <stdlib.h> 36*55477Sbostic #include <stdio.h> 37*55477Sbostic #include <string.h> 38*55477Sbostic #include <ctype.h> 3912110Sralph #include "lp.h" 40*55477Sbostic #include "lp.local.h" 4112110Sralph 4212110Sralph /* 4312110Sralph * Stuff for handling job specifications 4412110Sralph */ 4512877Sralph char *user[MAXUSERS]; /* users to process */ 4612877Sralph int users; /* # of users in user array */ 4712877Sralph int requ[MAXREQUESTS]; /* job number of spool entries */ 4812877Sralph int requests; /* # of spool requests */ 4912877Sralph char *person; /* name of person doing lprm */ 5012110Sralph 5112877Sralph static char luser[16]; /* buffer for person */ 5212110Sralph 53*55477Sbostic void usage __P((void)); 54*55477Sbostic 55*55477Sbostic int 5612110Sralph main(argc, argv) 5746916Sbostic int argc; 5812110Sralph char *argv[]; 5912110Sralph { 6012110Sralph register char *arg; 6112110Sralph struct passwd *p; 6212110Sralph 6312110Sralph name = argv[0]; 6412110Sralph gethostname(host, sizeof(host)); 6525496Seric openlog("lpd", 0, LOG_LPR); 6612110Sralph if ((p = getpwuid(getuid())) == NULL) 6712110Sralph fatal("Who are you?"); 6812110Sralph if (strlen(p->pw_name) >= sizeof(luser)) 6912110Sralph fatal("Your name is too long"); 7012110Sralph strcpy(luser, p->pw_name); 7112110Sralph person = luser; 7212110Sralph while (--argc) { 7312110Sralph if ((arg = *++argv)[0] == '-') 7412110Sralph switch (arg[1]) { 7512110Sralph case 'P': 7612730Sralph if (arg[2]) 7712730Sralph printer = &arg[2]; 7812730Sralph else if (argc > 1) { 7912730Sralph argc--; 8012730Sralph printer = *++argv; 8112730Sralph } 8212110Sralph break; 8312110Sralph case '\0': 8412110Sralph if (!users) { 8512110Sralph users = -1; 8612110Sralph break; 8712110Sralph } 8812110Sralph default: 8912110Sralph usage(); 9012110Sralph } 9112110Sralph else { 9212110Sralph if (users < 0) 9312110Sralph usage(); 9412110Sralph if (isdigit(arg[0])) { 9512110Sralph if (requests >= MAXREQUESTS) 9612110Sralph fatal("Too many requests"); 9712110Sralph requ[requests++] = atoi(arg); 9812110Sralph } else { 9912110Sralph if (users >= MAXUSERS) 10012110Sralph fatal("Too many users"); 10112110Sralph user[users++] = arg; 10212110Sralph } 10312110Sralph } 10412110Sralph } 10512110Sralph if (printer == NULL && (printer = getenv("PRINTER")) == NULL) 10612110Sralph printer = DEFLP; 10712110Sralph 10812110Sralph rmjob(); 109*55477Sbostic exit(0); 11012110Sralph } 11112110Sralph 112*55477Sbostic void 11312110Sralph usage() 11412110Sralph { 11546916Sbostic fprintf(stderr, "usage: lprm [-] [-Pprinter] [[job #] [user] ...]\n"); 11612110Sralph exit(2); 11712110Sralph } 118