displayq.c (216372) | displayq.c (241852) |
---|---|
1/* 2 * Copyright (c) 1983, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 20 unchanged lines hidden (view full) --- 29 30#if 0 31#ifndef lint 32static char sccsid[] = "@(#)displayq.c 8.4 (Berkeley) 4/28/95"; 33#endif /* not lint */ 34#endif 35 36#include "lp.cdefs.h" /* A cross-platform version of <sys/cdefs.h> */ | 1/* 2 * Copyright (c) 1983, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 20 unchanged lines hidden (view full) --- 29 30#if 0 31#ifndef lint 32static char sccsid[] = "@(#)displayq.c 8.4 (Berkeley) 4/28/95"; 33#endif /* not lint */ 34#endif 35 36#include "lp.cdefs.h" /* A cross-platform version of <sys/cdefs.h> */ |
37__FBSDID("$FreeBSD: head/usr.sbin/lpr/common_source/displayq.c 216372 2010-12-11 09:38:12Z joel $"); | 37__FBSDID("$FreeBSD: head/usr.sbin/lpr/common_source/displayq.c 241852 2012-10-22 03:31:22Z eadler $"); |
38 39#include <sys/param.h> 40#include <sys/stat.h> 41 42#include <ctype.h> 43#include <dirent.h> | 38 39#include <sys/param.h> 40#include <sys/stat.h> 41 42#include <ctype.h> 43#include <dirent.h> |
44#include <err.h> |
|
44#include <errno.h> 45#include <fcntl.h> 46#include <signal.h> 47#include <stdio.h> 48#include <stdlib.h> 49#include <string.h> 50#define psignal foil_gcc_psignal 51#define sys_siglist foil_gcc_siglist --- 33 unchanged lines hidden (view full) --- 85static int rank; /* order to be printed (-1=none, 0=active) */ 86static long totsize; /* total print job size in bytes */ 87 88static const char *head0 = "Rank Owner Job Files"; 89static const char *head1 = "Total Size\n"; 90 91static void alarmhandler(int _signo); 92static void filtered_write(char *_obuffer, int _wlen, FILE *_wstream); | 45#include <errno.h> 46#include <fcntl.h> 47#include <signal.h> 48#include <stdio.h> 49#include <stdlib.h> 50#include <string.h> 51#define psignal foil_gcc_psignal 52#define sys_siglist foil_gcc_siglist --- 33 unchanged lines hidden (view full) --- 86static int rank; /* order to be printed (-1=none, 0=active) */ 87static long totsize; /* total print job size in bytes */ 88 89static const char *head0 = "Rank Owner Job Files"; 90static const char *head1 = "Total Size\n"; 91 92static void alarmhandler(int _signo); 93static void filtered_write(char *_obuffer, int _wlen, FILE *_wstream); |
93static void warn(const struct printer *_pp); | 94static void daemonwarn(const struct printer *_pp); |
94 95/* 96 * Display the current state of the queue. Format = 1 if long format. 97 */ 98void 99displayq(struct printer *pp, int format) 100{ 101 register struct jobqueue *q; --- 12 unchanged lines hidden (view full) --- 114 printf("Warning: %s\n", cp); 115 free(cp); 116 } 117 118 /* 119 * Print out local queue 120 * Find all the control files in the spooling directory 121 */ | 95 96/* 97 * Display the current state of the queue. Format = 1 if long format. 98 */ 99void 100displayq(struct printer *pp, int format) 101{ 102 register struct jobqueue *q; --- 12 unchanged lines hidden (view full) --- 115 printf("Warning: %s\n", cp); 116 free(cp); 117 } 118 119 /* 120 * Print out local queue 121 * Find all the control files in the spooling directory 122 */ |
122 seteuid(euid); | 123 PRIV_START |
123 if (chdir(pp->spool_dir) < 0) 124 fatal(pp, "cannot chdir to spooling directory: %s", 125 strerror(errno)); | 124 if (chdir(pp->spool_dir) < 0) 125 fatal(pp, "cannot chdir to spooling directory: %s", 126 strerror(errno)); |
126 seteuid(uid); | 127 PRIV_END |
127 if ((nitems = getq(pp, &queue)) < 0) 128 fatal(pp, "cannot examine spooling area\n"); | 128 if ((nitems = getq(pp, &queue)) < 0) 129 fatal(pp, "cannot examine spooling area\n"); |
129 seteuid(euid); | 130 PRIV_START |
130 ret = stat(pp->lock_file, &statb); | 131 ret = stat(pp->lock_file, &statb); |
131 seteuid(uid); | 132 PRIV_END |
132 if (ret >= 0) { 133 if (statb.st_mode & LFM_PRINT_DIS) { 134 if (pp->remote) 135 printf("%s: ", local_host); 136 printf("Warning: %s is down: ", pp->printer); | 133 if (ret >= 0) { 134 if (statb.st_mode & LFM_PRINT_DIS) { 135 if (pp->remote) 136 printf("%s: ", local_host); 137 printf("Warning: %s is down: ", pp->printer); |
137 seteuid(euid); | 138 PRIV_START |
138 fd = open(pp->status_file, O_RDONLY|O_SHLOCK); | 139 fd = open(pp->status_file, O_RDONLY|O_SHLOCK); |
139 seteuid(uid); | 140 PRIV_END |
140 if (fd >= 0) { 141 while ((i = read(fd, line, sizeof(line))) > 0) 142 (void) fwrite(line, 1, i, stdout); 143 (void) close(fd); /* unlocks as well */ 144 } else 145 putchar('\n'); 146 } 147 if (statb.st_mode & LFM_QUEUE_DIS) { 148 if (pp->remote) 149 printf("%s: ", local_host); 150 printf("Warning: %s queue is turned off\n", 151 pp->printer); 152 } 153 } 154 155 if (nitems) { | 141 if (fd >= 0) { 142 while ((i = read(fd, line, sizeof(line))) > 0) 143 (void) fwrite(line, 1, i, stdout); 144 (void) close(fd); /* unlocks as well */ 145 } else 146 putchar('\n'); 147 } 148 if (statb.st_mode & LFM_QUEUE_DIS) { 149 if (pp->remote) 150 printf("%s: ", local_host); 151 printf("Warning: %s queue is turned off\n", 152 pp->printer); 153 } 154 } 155 156 if (nitems) { |
156 seteuid(euid); | 157 PRIV_START |
157 fp = fopen(pp->lock_file, "r"); | 158 fp = fopen(pp->lock_file, "r"); |
158 seteuid(uid); | 159 PRIV_END |
159 if (fp == NULL) | 160 if (fp == NULL) |
160 warn(pp); | 161 daemonwarn(pp); |
161 else { 162 /* get daemon pid */ 163 cp = current; 164 endp = cp + sizeof(current) - 1; 165 while ((i = getc(fp)) != EOF && i != '\n') { 166 if (cp < endp) 167 *cp++ = i; 168 } 169 *cp = '\0'; 170 i = atoi(current); 171 if (i <= 0) { 172 ret = -1; 173 } else { | 162 else { 163 /* get daemon pid */ 164 cp = current; 165 endp = cp + sizeof(current) - 1; 166 while ((i = getc(fp)) != EOF && i != '\n') { 167 if (cp < endp) 168 *cp++ = i; 169 } 170 *cp = '\0'; 171 i = atoi(current); 172 if (i <= 0) { 173 ret = -1; 174 } else { |
174 seteuid(euid); | 175 PRIV_START |
175 ret = kill(i, 0); | 176 ret = kill(i, 0); |
176 seteuid(uid); | 177 PRIV_END |
177 } 178 if (ret < 0) { | 178 } 179 if (ret < 0) { |
179 warn(pp); | 180 daemonwarn(pp); |
180 } else { 181 /* read current file name */ 182 cp = current; 183 endp = cp + sizeof(current) - 1; 184 while ((i = getc(fp)) != EOF && i != '\n') { 185 if (cp < endp) 186 *cp++ = i; 187 } 188 *cp = '\0'; 189 /* 190 * Print the status file. 191 */ 192 if (pp->remote) 193 printf("%s: ", local_host); | 181 } else { 182 /* read current file name */ 183 cp = current; 184 endp = cp + sizeof(current) - 1; 185 while ((i = getc(fp)) != EOF && i != '\n') { 186 if (cp < endp) 187 *cp++ = i; 188 } 189 *cp = '\0'; 190 /* 191 * Print the status file. 192 */ 193 if (pp->remote) 194 printf("%s: ", local_host); |
194 seteuid(euid); | 195 PRIV_START |
195 fd = open(pp->status_file, O_RDONLY|O_SHLOCK); | 196 fd = open(pp->status_file, O_RDONLY|O_SHLOCK); |
196 seteuid(uid); | 197 PRIV_END |
197 if (fd >= 0) { 198 while ((i = read(fd, line, 199 sizeof(line))) > 0) 200 fwrite(line, 1, i, stdout); 201 close(fd); /* unlocks as well */ 202 } else 203 putchar('\n'); 204 } --- 150 unchanged lines hidden (view full) --- 355 lastchar = destbuf[destlen - 1]; 356 } 357} 358 359/* 360 * Print a warning message if there is no daemon present. 361 */ 362static void | 198 if (fd >= 0) { 199 while ((i = read(fd, line, 200 sizeof(line))) > 0) 201 fwrite(line, 1, i, stdout); 202 close(fd); /* unlocks as well */ 203 } else 204 putchar('\n'); 205 } --- 150 unchanged lines hidden (view full) --- 356 lastchar = destbuf[destlen - 1]; 357 } 358} 359 360/* 361 * Print a warning message if there is no daemon present. 362 */ 363static void |
363warn(const struct printer *pp) | 364daemonwarn(const struct printer *pp) |
364{ 365 if (pp->remote) 366 printf("%s: ", local_host); 367 puts("Warning: no daemon present"); 368 current[0] = '\0'; 369} 370 371/* --- 14 unchanged lines hidden (view full) --- 386 int copycnt, jnum; 387 char savedname[MAXPATHLEN+1]; 388 FILE *cfp; 389 390 /* 391 * There's a chance the control file has gone away 392 * in the meantime; if this is the case just keep going 393 */ | 365{ 366 if (pp->remote) 367 printf("%s: ", local_host); 368 puts("Warning: no daemon present"); 369 current[0] = '\0'; 370} 371 372/* --- 14 unchanged lines hidden (view full) --- 387 int copycnt, jnum; 388 char savedname[MAXPATHLEN+1]; 389 FILE *cfp; 390 391 /* 392 * There's a chance the control file has gone away 393 * in the meantime; if this is the case just keep going 394 */ |
394 seteuid(euid); | 395 PRIV_START |
395 if ((cfp = fopen(cf, "r")) == NULL) 396 return; | 396 if ((cfp = fopen(cf, "r")) == NULL) 397 return; |
397 seteuid(uid); | 398 PRIV_END |
398 399 if (rank < 0) 400 rank = 0; 401 if (pp->remote || garbage || strcmp(cf, current)) 402 rank++; 403 404 /* 405 * The cf-file may include commands to print more than one datafile --- 167 unchanged lines hidden (view full) --- 573 } else { 574 if (!first) 575 printf(", "); 576 printf("%s", nfile); 577 col += nlen + fill; 578 } 579 first = 0; 580 | 399 400 if (rank < 0) 401 rank = 0; 402 if (pp->remote || garbage || strcmp(cf, current)) 403 rank++; 404 405 /* 406 * The cf-file may include commands to print more than one datafile --- 167 unchanged lines hidden (view full) --- 574 } else { 575 if (!first) 576 printf(", "); 577 printf("%s", nfile); 578 col += nlen + fill; 579 } 580 first = 0; 581 |
581 seteuid(euid); | 582 PRIV_START |
582 if (*datafile && !stat(datafile, &lbuf)) 583 totsize += copies * lbuf.st_size; | 583 if (*datafile && !stat(datafile, &lbuf)) 584 totsize += copies * lbuf.st_size; |
584 seteuid(uid); | 585 PRIV_END |
585} 586 587/* 588 * Print the long info about the file 589 */ 590void 591ldump(const char *nfile, const char *datafile, int copies) 592{ --- 45 unchanged lines hidden --- | 586} 587 588/* 589 * Print the long info about the file 590 */ 591void 592ldump(const char *nfile, const char *datafile, int copies) 593{ --- 45 unchanged lines hidden --- |