Changeset View
Changeset View
Standalone View
Standalone View
usr.sbin/lpr/lpd/lpd.c
Show First 20 Lines • Show All 98 Lines • ▼ Show 20 Lines | |||||
#include <ctype.h> | #include <ctype.h> | ||||
#include "lp.h" | #include "lp.h" | ||||
#include "lp.local.h" | #include "lp.local.h" | ||||
#include "pathnames.h" | #include "pathnames.h" | ||||
#include "extern.h" | #include "extern.h" | ||||
int lflag; /* log requests flag */ | int lflag; /* log requests flag */ | ||||
int sflag; /* no incoming port flag */ | int sflag; /* no incoming port flag */ | ||||
int Fflag; /* run in foreground flag */ | |||||
int from_remote; /* from remote socket */ | int from_remote; /* from remote socket */ | ||||
int main(int argc, char **_argv); | int main(int argc, char **_argv); | ||||
static void reapchild(int _signo); | static void reapchild(int _signo); | ||||
static void mcleanup(int _signo); | static void mcleanup(int _signo); | ||||
static void doit(void); | static void doit(void); | ||||
static void startup(void); | static void startup(void); | ||||
static void chkhost(struct sockaddr *_f, int _ch_opts); | static void chkhost(struct sockaddr *_f, int _ch_opts); | ||||
Show All 32 Lines | main(int argc, char **argv) | ||||
gethostname(local_host, sizeof(local_host)); | gethostname(local_host, sizeof(local_host)); | ||||
progname = "lpd"; | progname = "lpd"; | ||||
if (euid != 0) | if (euid != 0) | ||||
errx(EX_NOPERM,"must run as root"); | errx(EX_NOPERM,"must run as root"); | ||||
errs = 0; | errs = 0; | ||||
while ((i = getopt(argc, argv, "cdlpswW46")) != -1) | while ((i = getopt(argc, argv, "cdlpswFW46")) != -1) | ||||
switch (i) { | switch (i) { | ||||
case 'c': | case 'c': | ||||
/* log all kinds of connection-errors to syslog */ | /* log all kinds of connection-errors to syslog */ | ||||
ch_options |= LPD_LOGCONNERR; | ch_options |= LPD_LOGCONNERR; | ||||
break; | break; | ||||
case 'd': | case 'd': | ||||
socket_debug++; | socket_debug++; | ||||
break; | break; | ||||
Show All 15 Lines | case 'w': /* netbsd uses -w for maxwait */ | ||||
* is just a warning, so we won't suddenly break lpd | * is just a warning, so we won't suddenly break lpd | ||||
* for anyone who is currently using the option. | * for anyone who is currently using the option. | ||||
*/ | */ | ||||
syslog(LOG_WARNING, | syslog(LOG_WARNING, | ||||
"NOTE: the -w option has been renamed -W"); | "NOTE: the -w option has been renamed -W"); | ||||
syslog(LOG_WARNING, | syslog(LOG_WARNING, | ||||
"NOTE: please change your lpd config to use -W"); | "NOTE: please change your lpd config to use -W"); | ||||
/* FALLTHROUGH */ | /* FALLTHROUGH */ | ||||
case 'F': | |||||
Fflag++; | |||||
break; | |||||
case 'W': | case 'W': | ||||
/* allow connections coming from a non-reserved port */ | /* allow connections coming from a non-reserved port */ | ||||
/* (done by some lpr-implementations for MS-Windows) */ | /* (done by some lpr-implementations for MS-Windows) */ | ||||
ch_options |= LPD_NOPORTCHK; | ch_options |= LPD_NOPORTCHK; | ||||
break; | break; | ||||
case '4': | case '4': | ||||
family = PF_INET; | family = PF_INET; | ||||
inet_flag++; | inet_flag++; | ||||
▲ Show 20 Lines • Show All 64 Lines • ▼ Show 20 Lines | */ | ||||
if (waitpid(pid, &status, 0) < 0) { | if (waitpid(pid, &status, 0) < 0) { | ||||
err(EX_OSERR, "cannot wait"); | err(EX_OSERR, "cannot wait"); | ||||
} | } | ||||
if (WIFEXITED(status) && WEXITSTATUS(status) != 0) | if (WIFEXITED(status) && WEXITSTATUS(status) != 0) | ||||
errx(EX_OSFILE, "%d errors in printcap file, exiting", | errx(EX_OSFILE, "%d errors in printcap file, exiting", | ||||
WEXITSTATUS(status)); | WEXITSTATUS(status)); | ||||
} | } | ||||
#ifndef DEBUG | #ifdef DEBUG | ||||
Fflag++; | |||||
#endif | |||||
/* | /* | ||||
* Set up standard environment by detaching from the parent. | * Set up standard environment by detaching from the parent | ||||
* if -F not specified | |||||
*/ | */ | ||||
if (Fflag == 0) { | |||||
daemon(0, 0); | daemon(0, 0); | ||||
#endif | } | ||||
openlog("lpd", LOG_PID, LOG_LPR); | openlog("lpd", LOG_PID, LOG_LPR); | ||||
syslog(LOG_INFO, "lpd startup: logging=%d%s%s", lflag, | syslog(LOG_INFO, "lpd startup: logging=%d%s%s", lflag, | ||||
socket_debug ? " dbg" : "", sflag ? " net-secure" : ""); | socket_debug ? " dbg" : "", sflag ? " net-secure" : ""); | ||||
(void) umask(0); | (void) umask(0); | ||||
/* | /* | ||||
* NB: This depends on O_NONBLOCK semantics doing the right thing; | * NB: This depends on O_NONBLOCK semantics doing the right thing; | ||||
* i.e., applying only to the O_EXLOCK and not to the rest of the | * i.e., applying only to the O_EXLOCK and not to the rest of the | ||||
▲ Show 20 Lines • Show All 646 Lines • ▼ Show 20 Lines | socksetup(int af, int debuglvl) | ||||
} | } | ||||
return(socks); | return(socks); | ||||
} | } | ||||
static void | static void | ||||
usage(void) | usage(void) | ||||
{ | { | ||||
#ifdef INET6 | #ifdef INET6 | ||||
fprintf(stderr, "usage: lpd [-cdlsW46] [port#]\n"); | fprintf(stderr, "usage: lpd [-cdlsFW46] [port#]\n"); | ||||
#else | #else | ||||
fprintf(stderr, "usage: lpd [-cdlsW] [port#]\n"); | fprintf(stderr, "usage: lpd [-cdlsFW] [port#]\n"); | ||||
#endif | #endif | ||||
exit(EX_USAGE); | exit(EX_USAGE); | ||||
} | } |