lpr.c (19187) | lpr.c (19202) |
---|---|
1/* 2 * Copyright (c) 1983, 1989, 1993 3 * The Regents of the University of California. All rights reserved. 4 * (c) UNIX System Laboratories, Inc. 5 * All or some portions of this file are derived from material licensed 6 * to the University of California by American Telephone and Telegraph 7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with 8 * the permission of UNIX System Laboratories, Inc. --- 31 unchanged lines hidden (view full) --- 40#ifndef lint 41static char copyright[] = 42"@(#) Copyright (c) 1983, 1989, 1993\n\ 43 The Regents of the University of California. All rights reserved.\n"; 44#endif /* not lint */ 45 46#ifndef lint 47static char sccsid[] = "From: @(#)lpr.c 8.4 (Berkeley) 4/28/95" | 1/* 2 * Copyright (c) 1983, 1989, 1993 3 * The Regents of the University of California. All rights reserved. 4 * (c) UNIX System Laboratories, Inc. 5 * All or some portions of this file are derived from material licensed 6 * to the University of California by American Telephone and Telegraph 7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with 8 * the permission of UNIX System Laboratories, Inc. --- 31 unchanged lines hidden (view full) --- 40#ifndef lint 41static char copyright[] = 42"@(#) Copyright (c) 1983, 1989, 1993\n\ 43 The Regents of the University of California. All rights reserved.\n"; 44#endif /* not lint */ 45 46#ifndef lint 47static char sccsid[] = "From: @(#)lpr.c 8.4 (Berkeley) 4/28/95" |
48 "\n$Id: lpr.c,v 1.8 1996/10/25 18:14:48 imp Exp $\n"; | 48 "\n$Id: lpr.c,v 1.9 1996/10/26 00:46:34 imp Exp $\n"; |
49#endif /* not lint */ 50 51/* 52 * lpr -- off line print 53 * 54 * Allows multiple printers and printers on remote machines by 55 * using information from a printer data base. 56 */ --- 51 unchanged lines hidden (view full) --- 108static char *itoa __P((int)); 109static char *linked __P((char *)); 110static char *lmktemp __P((char *, int, int)); 111static void mktemps __P((void)); 112static int nfile __P((char *)); 113static int test __P((char *)); 114static void usage __P((void)); 115 | 49#endif /* not lint */ 50 51/* 52 * lpr -- off line print 53 * 54 * Allows multiple printers and printers on remote machines by 55 * using information from a printer data base. 56 */ --- 51 unchanged lines hidden (view full) --- 108static char *itoa __P((int)); 109static char *linked __P((char *)); 110static char *lmktemp __P((char *, int, int)); 111static void mktemps __P((void)); 112static int nfile __P((char *)); 113static int test __P((char *)); 114static void usage __P((void)); 115 |
116void | 116int |
117main(argc, argv) 118 int argc; 119 char *argv[]; 120{ 121 struct passwd *pw; 122 struct group *gptr; 123 register char *arg, *cp; 124 char buf[BUFSIZ]; --- 142 unchanged lines hidden (view full) --- 267 } 268 if (*gptr->gr_mem == NULL) 269 fatal2("Not a member of the restricted group"); 270 } 271 } 272 /* 273 * Check to make sure queuing is enabled if userid is not root. 274 */ | 117main(argc, argv) 118 int argc; 119 char *argv[]; 120{ 121 struct passwd *pw; 122 struct group *gptr; 123 register char *arg, *cp; 124 char buf[BUFSIZ]; --- 142 unchanged lines hidden (view full) --- 267 } 268 if (*gptr->gr_mem == NULL) 269 fatal2("Not a member of the restricted group"); 270 } 271 } 272 /* 273 * Check to make sure queuing is enabled if userid is not root. 274 */ |
275 (void) sprintf(buf, "%s/%s", SD, LO); | 275 (void) snprintf(buf, sizeof(buf), "%s/%s", SD, LO); |
276 if (userid && stat(buf, &stb) == 0 && (stb.st_mode & 010)) 277 fatal2("Printer queue is disabled"); 278 /* 279 * Initialize the control file. 280 */ 281 mktemps(); 282 tfd = nfile(tfname); 283 (void) fchown(tfd, DU, -1); /* owned by daemon for protection */ --- 32 unchanged lines hidden (view full) --- 316 copy(0, " "); 317 argv++; 318 continue; 319 } 320 if ((f = test(arg = *argv++)) < 0) 321 continue; /* file unreasonable */ 322 323 if (sflag && (cp = linked(arg)) != NULL) { | 276 if (userid && stat(buf, &stb) == 0 && (stb.st_mode & 010)) 277 fatal2("Printer queue is disabled"); 278 /* 279 * Initialize the control file. 280 */ 281 mktemps(); 282 tfd = nfile(tfname); 283 (void) fchown(tfd, DU, -1); /* owned by daemon for protection */ --- 32 unchanged lines hidden (view full) --- 316 copy(0, " "); 317 argv++; 318 continue; 319 } 320 if ((f = test(arg = *argv++)) < 0) 321 continue; /* file unreasonable */ 322 323 if (sflag && (cp = linked(arg)) != NULL) { |
324 (void) sprintf(buf, "%d %d", statb.st_dev, statb.st_ino); | 324 (void) snprintf(buf, sizeof(buf), "%d %d", statb.st_dev, 325 statb.st_ino); |
325 card('S', buf); 326 if (format == 'p') 327 card('T', title ? title : arg); 328 for (i = 0; i < ncopies; i++) 329 card(format, &dfname[inchar-2]); 330 card('U', &dfname[inchar-2]); 331 if (f) 332 card('U', cp); 333 card('N', arg); 334 dfname[inchar]++; 335 nact++; 336 continue; 337 } 338 if (sflag) 339 printf("%s: %s: not linked, copying instead\n", name, arg); 340 if ((i = open(arg, O_RDONLY)) < 0) { 341 printf("%s: cannot open %s\n", name, arg); | 326 card('S', buf); 327 if (format == 'p') 328 card('T', title ? title : arg); 329 for (i = 0; i < ncopies; i++) 330 card(format, &dfname[inchar-2]); 331 card('U', &dfname[inchar-2]); 332 if (f) 333 card('U', cp); 334 card('N', arg); 335 dfname[inchar]++; 336 nact++; 337 continue; 338 } 339 if (sflag) 340 printf("%s: %s: not linked, copying instead\n", name, arg); 341 if ((i = open(arg, O_RDONLY)) < 0) { 342 printf("%s: cannot open %s\n", name, arg); |
342 continue; | 343 } else { 344 copy(i, arg); 345 (void) close(i); 346 if (f && unlink(arg) < 0) 347 printf("%s: %s: not removed\n", name, arg); |
343 } | 348 } |
344 copy(i, arg); 345 (void) close(i); 346 if (f && unlink(arg) < 0) 347 printf("%s: %s: not removed\n", name, arg); | |
348 } 349 350 if (nact) { 351 (void) close(tfd); 352 tfname[inchar]--; 353 /* 354 * Touch the control file to fix position in the queue. 355 */ --- 73 unchanged lines hidden (view full) --- 429static char * 430linked(file) 431 register char *file; 432{ 433 register char *cp; 434 static char buf[BUFSIZ]; 435 436 if (*file != '/') { | 349 } 350 351 if (nact) { 352 (void) close(tfd); 353 tfname[inchar]--; 354 /* 355 * Touch the control file to fix position in the queue. 356 */ --- 73 unchanged lines hidden (view full) --- 430static char * 431linked(file) 432 register char *file; 433{ 434 register char *cp; 435 static char buf[BUFSIZ]; 436 437 if (*file != '/') { |
437 if (getwd(buf) == NULL) | 438 if (getcwd(buf,sizeof(buf)) == NULL) |
438 return(NULL); 439 while (file[0] == '.') { 440 switch (file[1]) { 441 case '/': 442 file += 2; 443 continue; 444 case '.': 445 if (file[2] == '/') { --- 242 unchanged lines hidden (view full) --- 688 */ 689static void 690mktemps() 691{ 692 register int len, fd, n; 693 register char *cp; 694 char buf[BUFSIZ]; 695 | 439 return(NULL); 440 while (file[0] == '.') { 441 switch (file[1]) { 442 case '/': 443 file += 2; 444 continue; 445 case '.': 446 if (file[2] == '/') { --- 242 unchanged lines hidden (view full) --- 689 */ 690static void 691mktemps() 692{ 693 register int len, fd, n; 694 register char *cp; 695 char buf[BUFSIZ]; 696 |
696 (void) sprintf(buf, "%s/.seq", SD); | 697 (void) snprintf(buf, sizeof(buf), "%s/.seq", SD); |
697 if ((fd = open(buf, O_RDWR|O_CREAT, 0661)) < 0) { 698 printf("%s: cannot create %s\n", name, buf); 699 exit(1); 700 } 701 if (flock(fd, LOCK_EX)) { 702 printf("%s: cannot lock %s\n", name, buf); 703 exit(1); 704 } --- 7 unchanged lines hidden (view full) --- 712 } 713 len = strlen(SD) + strlen(host) + 8; 714 tfname = lmktemp("tf", n, len); 715 cfname = lmktemp("cf", n, len); 716 dfname = lmktemp("df", n, len); 717 inchar = strlen(SD) + 3; 718 n = (n + 1) % 1000; 719 (void) lseek(fd, (off_t)0, 0); | 698 if ((fd = open(buf, O_RDWR|O_CREAT, 0661)) < 0) { 699 printf("%s: cannot create %s\n", name, buf); 700 exit(1); 701 } 702 if (flock(fd, LOCK_EX)) { 703 printf("%s: cannot lock %s\n", name, buf); 704 exit(1); 705 } --- 7 unchanged lines hidden (view full) --- 713 } 714 len = strlen(SD) + strlen(host) + 8; 715 tfname = lmktemp("tf", n, len); 716 cfname = lmktemp("cf", n, len); 717 dfname = lmktemp("df", n, len); 718 inchar = strlen(SD) + 3; 719 n = (n + 1) % 1000; 720 (void) lseek(fd, (off_t)0, 0); |
720 sprintf(buf, "%03d\n", n); | 721 snprintf(buf, sizeof(buf), "%03d\n", n); |
721 (void) write(fd, buf, strlen(buf)); 722 (void) close(fd); /* unlocks as well */ 723} 724 725/* 726 * Make a temp file name. 727 */ 728static char * 729lmktemp(id, num, len) 730 char *id; 731 int num, len; 732{ 733 register char *s; 734 735 if ((s = malloc(len)) == NULL) 736 fatal2("out of memory"); | 722 (void) write(fd, buf, strlen(buf)); 723 (void) close(fd); /* unlocks as well */ 724} 725 726/* 727 * Make a temp file name. 728 */ 729static char * 730lmktemp(id, num, len) 731 char *id; 732 int num, len; 733{ 734 register char *s; 735 736 if ((s = malloc(len)) == NULL) 737 fatal2("out of memory"); |
737 (void) sprintf(s, "%s/%sA%03d%s", SD, id, num, host); | 738 (void) snprintf(s, len, "%s/%sA%03d%s", SD, id, num, host); |
738 return(s); 739} 740 741#if __STDC__ 742#include <stdarg.h> 743#else 744#include <varargs.h> 745#endif --- 22 unchanged lines hidden --- | 739 return(s); 740} 741 742#if __STDC__ 743#include <stdarg.h> 744#else 745#include <varargs.h> 746#endif --- 22 unchanged lines hidden --- |