1 /* 2 * Copyright (c) 1983 Regents of the University of California. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms are permitted 6 * provided that this notice is preserved and that due credit is given 7 * to the University of California at Berkeley. The name of the University 8 * may not be used to endorse or promote products derived from this 9 * software without specific prior written permission. This software 10 * is provided ``as is'' without express or implied warranty. 11 */ 12 13 #ifndef lint 14 char copyright[] = 15 "@(#) Copyright (c) 1983 Regents of the University of California.\n\ 16 All rights reserved.\n"; 17 #endif /* not lint */ 18 19 #ifndef lint 20 static char sccsid[] = "@(#)lprm.c 5.3 (Berkeley) 05/05/88"; 21 #endif /* not lint */ 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 */ 33 34 #include "lp.h" 35 36 /* 37 * Stuff for handling job specifications 38 */ 39 char *user[MAXUSERS]; /* users to process */ 40 int users; /* # of users in user array */ 41 int requ[MAXREQUESTS]; /* job number of spool entries */ 42 int requests; /* # of spool requests */ 43 char *person; /* name of person doing lprm */ 44 45 static char luser[16]; /* buffer for person */ 46 47 struct passwd *getpwuid(); 48 49 main(argc, argv) 50 char *argv[]; 51 { 52 register char *arg; 53 struct passwd *p; 54 struct direct **files; 55 int nitems, assasinated = 0; 56 57 name = argv[0]; 58 gethostname(host, sizeof(host)); 59 openlog("lpd", 0, LOG_LPR); 60 if ((p = getpwuid(getuid())) == NULL) 61 fatal("Who are you?"); 62 if (strlen(p->pw_name) >= sizeof(luser)) 63 fatal("Your name is too long"); 64 strcpy(luser, p->pw_name); 65 person = luser; 66 while (--argc) { 67 if ((arg = *++argv)[0] == '-') 68 switch (arg[1]) { 69 case 'P': 70 if (arg[2]) 71 printer = &arg[2]; 72 else if (argc > 1) { 73 argc--; 74 printer = *++argv; 75 } 76 break; 77 case '\0': 78 if (!users) { 79 users = -1; 80 break; 81 } 82 default: 83 usage(); 84 } 85 else { 86 if (users < 0) 87 usage(); 88 if (isdigit(arg[0])) { 89 if (requests >= MAXREQUESTS) 90 fatal("Too many requests"); 91 requ[requests++] = atoi(arg); 92 } else { 93 if (users >= MAXUSERS) 94 fatal("Too many users"); 95 user[users++] = arg; 96 } 97 } 98 } 99 if (printer == NULL && (printer = getenv("PRINTER")) == NULL) 100 printer = DEFLP; 101 102 rmjob(); 103 } 104 105 static 106 usage() 107 { 108 printf("usage: lprm [-] [-Pprinter] [[job #] [user] ...]\n"); 109 exit(2); 110 } 111