lpd.c (74127) | lpd.c (78146) |
---|---|
1/* 2 * Copyright (c) 1983, 1993, 1994 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: --- 29 unchanged lines hidden (view full) --- 38 The Regents of the University of California. All rights reserved.\n"; 39#endif /* not lint */ 40 41#ifndef lint 42#if 0 43static char sccsid[] = "@(#)lpd.c 8.7 (Berkeley) 5/10/95"; 44#endif 45static const char rcsid[] = | 1/* 2 * Copyright (c) 1983, 1993, 1994 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: --- 29 unchanged lines hidden (view full) --- 38 The Regents of the University of California. All rights reserved.\n"; 39#endif /* not lint */ 40 41#ifndef lint 42#if 0 43static char sccsid[] = "@(#)lpd.c 8.7 (Berkeley) 5/10/95"; 44#endif 45static const char rcsid[] = |
46 "$FreeBSD: head/usr.sbin/lpr/lpd/lpd.c 74127 2001-03-12 02:03:53Z gad $"; | 46 "$FreeBSD: head/usr.sbin/lpr/lpd/lpd.c 78146 2001-06-12 16:38:20Z gad $"; |
47#endif /* not lint */ 48 49/* 50 * lpd -- line printer daemon. 51 * 52 * Listen for a connection and perform the requested operation. 53 * Operations are: 54 * \1printer\n --- 47 unchanged lines hidden (view full) --- 102#include "lp.local.h" 103#include "pathnames.h" 104#include "extern.h" 105 106int lflag; /* log requests flag */ 107int pflag; /* no incoming port flag */ 108int from_remote; /* from remote socket */ 109 | 47#endif /* not lint */ 48 49/* 50 * lpd -- line printer daemon. 51 * 52 * Listen for a connection and perform the requested operation. 53 * Operations are: 54 * \1printer\n --- 47 unchanged lines hidden (view full) --- 102#include "lp.local.h" 103#include "pathnames.h" 104#include "extern.h" 105 106int lflag; /* log requests flag */ 107int pflag; /* no incoming port flag */ 108int from_remote; /* from remote socket */ 109 |
110int main __P((int, char **)); 111static void reapchild __P((int)); 112static void mcleanup __P((int)); 113static void doit __P((void)); 114static void startup __P((void)); 115static void chkhost __P((struct sockaddr *)); 116static int ckqueue __P((struct printer *)); 117static void usage __P((void)); 118static int *socksetup __P((int, int)); | 110int main(int argc, char **_argv); 111static void reapchild(int _signo); 112static void mcleanup(int _signo); 113static void doit(void); 114static void startup(void); 115static void chkhost(struct sockaddr *_f); 116static int ckqueue(struct printer *_pp); 117static void usage(void); 118static int *socksetup(int _af, int _options); |
119 120/* XXX from libc/net/rcmd.c */ 121extern int __ivaliduser_sa __P((FILE *, struct sockaddr *, socklen_t, 122 const char *, const char *)); 123 124uid_t uid, euid; 125 126int | 119 120/* XXX from libc/net/rcmd.c */ 121extern int __ivaliduser_sa __P((FILE *, struct sockaddr *, socklen_t, 122 const char *, const char *)); 123 124uid_t uid, euid; 125 126int |
127main(argc, argv) 128 int argc; 129 char **argv; | 127main(int argc, char **argv) |
130{ 131 int errs, f, funix, *finet, fromlen, i, options, socket_debug; 132 fd_set defreadfds; 133 struct sockaddr_un un, fromunix; 134 struct sockaddr_storage frominet; 135 int lfd; 136 sigset_t omask, nmask; 137 struct servent *sp, serv; --- 239 unchanged lines hidden (view full) --- 377 doit(); 378 exit(0); 379 } 380 (void) close(s); 381 } 382} 383 384static void | 128{ 129 int errs, f, funix, *finet, fromlen, i, options, socket_debug; 130 fd_set defreadfds; 131 struct sockaddr_un un, fromunix; 132 struct sockaddr_storage frominet; 133 int lfd; 134 sigset_t omask, nmask; 135 struct servent *sp, serv; --- 239 unchanged lines hidden (view full) --- 375 doit(); 376 exit(0); 377 } 378 (void) close(s); 379 } 380} 381 382static void |
385reapchild(signo) 386 int signo; | 383reapchild(int signo __unused) |
387{ 388 union wait status; 389 390 while (wait3((int *)&status, WNOHANG, 0) > 0) 391 ; 392} 393 394static void | 384{ 385 union wait status; 386 387 while (wait3((int *)&status, WNOHANG, 0) > 0) 388 ; 389} 390 391static void |
395mcleanup(signo) 396 int signo; | 392mcleanup(int signo) |
397{ 398 /* 399 * XXX syslog(3) is not signal-safe. 400 */ 401 if (lflag) { 402 if (signo) 403 syslog(LOG_INFO, "exiting on signal %d", signo); 404 else --- 9 unchanged lines hidden (view full) --- 414char *user[MAXUSERS]; /* users to process */ 415int users; /* # of users in user array */ 416int requ[MAXREQUESTS]; /* job number of spool entries */ 417int requests; /* # of spool requests */ 418char *person; /* name of person doing lprm */ 419 420char fromb[MAXHOSTNAMELEN]; /* buffer for client's machine name */ 421char cbuf[BUFSIZ]; /* command line buffer */ | 393{ 394 /* 395 * XXX syslog(3) is not signal-safe. 396 */ 397 if (lflag) { 398 if (signo) 399 syslog(LOG_INFO, "exiting on signal %d", signo); 400 else --- 9 unchanged lines hidden (view full) --- 410char *user[MAXUSERS]; /* users to process */ 411int users; /* # of users in user array */ 412int requ[MAXREQUESTS]; /* job number of spool entries */ 413int requests; /* # of spool requests */ 414char *person; /* name of person doing lprm */ 415 416char fromb[MAXHOSTNAMELEN]; /* buffer for client's machine name */ 417char cbuf[BUFSIZ]; /* command line buffer */ |
422char *cmdnames[] = { | 418const char *cmdnames[] = { |
423 "null", 424 "printjob", 425 "recvjob", 426 "displayq short", 427 "displayq long", 428 "rmjob" 429}; 430 431static void | 419 "null", 420 "printjob", 421 "recvjob", 422 "displayq short", 423 "displayq long", 424 "rmjob" 425}; 426 427static void |
432doit() | 428doit(void) |
433{ 434 char *cp, *printer; 435 int n; 436 int status; 437 struct printer myprinter, *pp = &myprinter; 438 439 init_printer(&myprinter); 440 --- 97 unchanged lines hidden (view full) --- 538 } 539} 540 541/* 542 * Make a pass through the printcap database and start printing any 543 * files left from the last time the machine went down. 544 */ 545static void | 429{ 430 char *cp, *printer; 431 int n; 432 int status; 433 struct printer myprinter, *pp = &myprinter; 434 435 init_printer(&myprinter); 436 --- 97 unchanged lines hidden (view full) --- 534 } 535} 536 537/* 538 * Make a pass through the printcap database and start printing any 539 * files left from the last time the machine went down. 540 */ 541static void |
546startup() | 542startup(void) |
547{ 548 int pid, status, more; 549 struct printer myprinter, *pp = &myprinter; 550 551 more = firstprinter(pp, &status); 552 if (status) 553 goto errloop; 554 while (more) { --- 24 unchanged lines hidden (view full) --- 579 } while (more && status); 580 } 581} 582 583/* 584 * Make sure there's some work to do before forking off a child 585 */ 586static int | 543{ 544 int pid, status, more; 545 struct printer myprinter, *pp = &myprinter; 546 547 more = firstprinter(pp, &status); 548 if (status) 549 goto errloop; 550 while (more) { --- 24 unchanged lines hidden (view full) --- 575 } while (more && status); 576 } 577} 578 579/* 580 * Make sure there's some work to do before forking off a child 581 */ 582static int |
587ckqueue(pp) 588 struct printer *pp; | 583ckqueue(struct printer *pp) |
589{ 590 register struct dirent *d; 591 DIR *dirp; 592 char *spooldir; 593 594 spooldir = pp->spool_dir; 595 if ((dirp = opendir(spooldir)) == NULL) 596 return (-1); --- 8 unchanged lines hidden (view full) --- 605} 606 607#define DUMMY ":nobody::" 608 609/* 610 * Check to see if the from host has access to the line printer. 611 */ 612static void | 584{ 585 register struct dirent *d; 586 DIR *dirp; 587 char *spooldir; 588 589 spooldir = pp->spool_dir; 590 if ((dirp = opendir(spooldir)) == NULL) 591 return (-1); --- 8 unchanged lines hidden (view full) --- 600} 601 602#define DUMMY ":nobody::" 603 604/* 605 * Check to see if the from host has access to the line printer. 606 */ 607static void |
613chkhost(f) 614 struct sockaddr *f; | 608chkhost(struct sockaddr *f) |
615{ 616 struct addrinfo hints, *res, *r; 617 register FILE *hostf; 618 int first = 1; 619 int good = 0; 620 char host[NI_MAXHOST], ip[NI_MAXHOST]; 621 char serv[NI_MAXSERV]; 622 int error, addrlen; --- 78 unchanged lines hidden (view full) --- 701 fatal(0, "Your host does not have line printer access"); 702 /*NOTREACHED*/ 703} 704 705/* setup server socket for specified address family */ 706/* if af is PF_UNSPEC more than one socket may be returned */ 707/* the returned list is dynamically allocated, so caller needs to free it */ 708static int * | 609{ 610 struct addrinfo hints, *res, *r; 611 register FILE *hostf; 612 int first = 1; 613 int good = 0; 614 char host[NI_MAXHOST], ip[NI_MAXHOST]; 615 char serv[NI_MAXSERV]; 616 int error, addrlen; --- 78 unchanged lines hidden (view full) --- 695 fatal(0, "Your host does not have line printer access"); 696 /*NOTREACHED*/ 697} 698 699/* setup server socket for specified address family */ 700/* if af is PF_UNSPEC more than one socket may be returned */ 701/* the returned list is dynamically allocated, so caller needs to free it */ 702static int * |
709socksetup(af, options) 710 int af, options; | 703socksetup(int af, int options) |
711{ 712 struct addrinfo hints, *res, *r; 713 int error, maxs, *s, *socks; 714 const int on = 1; 715 716 memset(&hints, 0, sizeof(hints)); 717 hints.ai_flags = AI_PASSIVE; 718 hints.ai_family = af; --- 62 unchanged lines hidden (view full) --- 781 syslog(LOG_ERR, "Couldn't bind to any socket"); 782 free(socks); 783 mcleanup(0); 784 } 785 return(socks); 786} 787 788static void | 704{ 705 struct addrinfo hints, *res, *r; 706 int error, maxs, *s, *socks; 707 const int on = 1; 708 709 memset(&hints, 0, sizeof(hints)); 710 hints.ai_flags = AI_PASSIVE; 711 hints.ai_family = af; --- 62 unchanged lines hidden (view full) --- 774 syslog(LOG_ERR, "Couldn't bind to any socket"); 775 free(socks); 776 mcleanup(0); 777 } 778 return(socks); 779} 780 781static void |
789usage() | 782usage(void) |
790{ 791#ifdef INET6 792 fprintf(stderr, "usage: lpd [-dlp46] [port#]\n"); 793#else 794 fprintf(stderr, "usage: lpd [-dlp] [port#]\n"); 795#endif 796 exit(EX_USAGE); 797} | 783{ 784#ifdef INET6 785 fprintf(stderr, "usage: lpd [-dlp46] [port#]\n"); 786#else 787 fprintf(stderr, "usage: lpd [-dlp] [port#]\n"); 788#endif 789 exit(EX_USAGE); 790} |