lpq.c revision 1.4
1/* 2 * Copyright (c) 1983, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. All advertising materials mentioning features or use of this software 15 * must display the following acknowledgement: 16 * This product includes software developed by the University of 17 * California, Berkeley and its contributors. 18 * 4. Neither the name of the University nor the names of its contributors 19 * may be used to endorse or promote products derived from this software 20 * without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 */ 34 35#ifndef lint 36static char copyright[] = 37"@(#) Copyright (c) 1983, 1993\n\ 38 The Regents of the University of California. All rights reserved.\n"; 39#endif /* not lint */ 40 41#ifndef lint 42static char sccsid[] = "@(#)lpq.c 8.1 (Berkeley) 6/6/93"; 43#endif /* not lint */ 44 45/* 46 * Spool Queue examination program 47 * 48 * lpq [-l] [-Pprinter] [user...] [job...] 49 * 50 * -l long output 51 * -P used to identify printer as per lpr/lprm 52 */ 53 54#include <sys/param.h> 55 56#include <syslog.h> 57#include <dirent.h> 58#include <unistd.h> 59#include <stdlib.h> 60#include <stdio.h> 61#include <ctype.h> 62#include "lp.h" 63#include "lp.local.h" 64 65int requ[MAXREQUESTS]; /* job number of spool entries */ 66int requests; /* # of spool requests */ 67char *user[MAXUSERS]; /* users to process */ 68int users; /* # of users in user array */ 69 70uid_t uid, euid; 71 72void usage __P((void)); 73 74int 75main(argc, argv) 76 register int argc; 77 register char **argv; 78{ 79 extern char *optarg; 80 extern int optind; 81 int ch, lflag; /* long output option */ 82 83 euid = geteuid(); 84 uid = getuid(); 85 seteuid(uid); 86 name = *argv; 87 if (gethostname(host, sizeof(host))) { 88 perror("lpq: gethostname"); 89 exit(1); 90 } 91 openlog("lpd", 0, LOG_LPR); 92 93 lflag = 0; 94 while ((ch = getopt(argc, argv, "lP:")) != EOF) 95 switch((char)ch) { 96 case 'l': /* long output */ 97 ++lflag; 98 break; 99 case 'P': /* printer name */ 100 printer = optarg; 101 break; 102 case '?': 103 default: 104 usage(); 105 } 106 107 if (printer == NULL && (printer = getenv("PRINTER")) == NULL) 108 printer = DEFLP; 109 110 for (argc -= optind, argv += optind; argc; --argc, ++argv) 111 if (isdigit(argv[0][0])) { 112 if (requests >= MAXREQUESTS) 113 fatal("too many requests"); 114 requ[requests++] = atoi(*argv); 115 } 116 else { 117 if (users >= MAXUSERS) 118 fatal("too many users"); 119 user[users++] = *argv; 120 } 121 122 displayq(lflag); 123 exit(0); 124} 125 126void 127usage() 128{ 129 puts("usage: lpq [-l] [-Pprinter] [user ...] [job ...]"); 130 exit(1); 131} 132