head 1.16; access; symbols; locks; strict; comment @ * @; 1.16 date 93.08.25.17.23.05; author jromine; state Exp; branches; next 1.15; 1.15 date 93.02.26.22.11.12; author jromine; state Exp; branches; next 1.14; 1.14 date 92.12.16.22.31.20; author jromine; state Exp; branches; next 1.13; 1.13 date 92.12.15.00.20.22; author jromine; state Exp; branches; next 1.12; 1.12 date 92.12.14.17.11.17; author jromine; state Exp; branches; next 1.11; 1.11 date 92.11.11.22.26.33; author jromine; state Exp; branches; next 1.10; 1.10 date 92.02.11.18.55.11; author jromine; state Exp; branches; next 1.9; 1.9 date 92.01.31.22.02.30; author jromine; state Exp; branches; next 1.8; 1.8 date 90.04.09.09.45.09; author sources; state Exp; branches; next 1.7; 1.7 date 90.04.05.15.34.33; author sources; state Exp; branches; next 1.6; 1.6 date 90.04.05.14.53.52; author sources; state Exp; branches; next 1.5; 1.5 date 90.02.06.13.12.22; author sources; state Exp; branches; next 1.4; 1.4 date 90.02.05.15.01.40; author sources; state Exp; branches; next 1.3; 1.3 date 90.02.05.14.07.50; author sources; state Exp; branches; next 1.2; 1.2 date 90.02.05.13.58.18; author sources; state Exp; branches; next 1.1; 1.1 date 90.02.05.13.58.08; author sources; state Exp; branches; next ; desc @@ 1.16 log @off_t fixes for BSD44 @ text @/* popd.c - the POP server */ #ifndef lint static char ident[] = "@@(#)$Id: popd.c,v 1.15 1993/02/26 22:11:12 jromine Exp jromine $"; #endif /* lint */ /* Author: Marshall T. Rose (MTR) Department of Computer Science and Information Sciences University of Delaware Newark, DE 19716 302/451-1951 Date: Sun Oct 28 16:23:26 1984 */ #include #include #include #include "../h/strings.h" #include "syslog.h" #include #include #ifndef NOIOCTLH #include #endif #include #include #ifdef SIGTSTP #include #include #endif #include #include #include #ifdef KPOP #include static Key_schedule schedule; static KTEXT_ST ticket; static AUTH_DAT kdata; #endif #ifdef SYS5 #include #endif #ifdef SYS5 #define u_short ushort #endif #define NOTOK (-1) #define OK 0 #define NULLCP ((char *) 0) #define NULLRP ((struct rusage *) 0) #define FAST /* fast start-up of BBoards */ /* */ extern int errno; #ifndef BSD44 extern int sys_nerr; extern char *sys_errlist[]; extern char *sys_siglist[]; #endif int debug = 0; static int nbits = ((sizeof (int)) * 8); static int options = 0; #ifndef POPSERVICE #define POPSERVICE "pop" #endif char *myname = "popd"; char myhost[BUFSIZ]; static char *myprotocol = "tcp"; static char *myservice = POPSERVICE; static struct sockaddr_in in_socket; static struct sockaddr_in *isock = &in_socket; #ifdef KPOP static AUTH_DAT kdata; #endif static TYPESIG chldser (); void padios (), padvise (); static server(), arginit(), envinit(); /* */ /* ARGSUSED */ main (argc, argv, envp) int argc; char **argv, **envp; { #ifdef KPOP int i; #else int fd, sd; int on = 1; struct servent *sp; struct sockaddr_in out_socket, *osock = &out_socket; #endif #ifdef KPOP i = sizeof(in_socket); if (getpeername(0, &in_socket, &i) < 0) padios("getpeername", "bad status"); #else if ((sp = getservbyname (myservice, myprotocol)) == NULL) padios (NULLCP, "%s/%s: unknown service", myprotocol, myservice); isock -> sin_family = AF_INET; isock -> sin_port = sp -> s_port; isock -> sin_addr.s_addr = INADDR_ANY; #endif arginit (argv); envinit (); #ifndef KPOP #ifdef RESTART for (;;) { char reason[BUFSIZ]; #if defined(BSD42) && !defined(WAITINT) union wait status; #else int status; #endif switch (fork ()) { case NOTOK: sleep (5); continue; case OK: break; default: sleep (60); (void) wait3 (&status, 0, NULLRP); if (WIFEXITED (status)) (void) sprintf (reason, "exit=0%o", status.w_retcode); else if (WIFSIGNALED (status)) (void) sprintf (reason, "signal=%s%s", status.w_termsig < NSIG ? sys_siglist[status.w_termsig] : "unknown", status.w_coredump ? " (core dumped)" : NULL); else (void) strcpy (reason, "stopped(!!)"); padvise (NULLCP, LOG_WARNING, "%s/%s server has terminated -- %s", sp -> s_proto, sp -> s_name, reason); continue; } break; } closelog (); #ifndef BSD43 openlog (myname, LOG_PID); #else /* BSD43 */ openlog (myname, LOG_PID, LOG_DAEMON); #endif /* BSD43 */ padvise (NULLCP, LOG_INFO, "restart"); #endif /* RESTART */ /* */ if ((sd = socket (AF_INET, SOCK_STREAM, 0)) == NOTOK) padios ("socket", "unable to create"); #ifndef BSD43 if (options & SO_DEBUG) if (setsockopt (sd, SOL_SOCKET, SO_DEBUG, NULL, 0) == NOTOK) padvise ("SO_DEBUG", LOG_WARNING, "unable to set socket option"); if (setsockopt (sd, SOL_SOCKET, SO_KEEPALIVE, NULL, 0) == NOTOK) padvise ("SO_KEEPALIVE", LOG_WARNING, "unable to set socket option"); #else /* BSD43 */ if (options & SO_DEBUG) if (setsockopt (sd, SOL_SOCKET, SO_DEBUG, &on, sizeof on) == NOTOK) padvise ("SO_DEBUG", LOG_WARNING, "unable to set socket option"); if (setsockopt (sd, SOL_SOCKET, SO_KEEPALIVE, &on, sizeof on) == NOTOK) padvise ("SO_KEEPALIVE", LOG_WARNING, "unable to set socket option"); #endif /* BSD43 */ if (bind (sd, (struct sockaddr *) isock, sizeof *isock) == NOTOK) padios ("socket", "unable to bind"); #ifdef SIGCHLD (void) signal (SIGCHLD, chldser); #endif /* SIGCHLD */ (void) listen (sd, SOMAXCONN); #endif /* KPOP */ #ifdef FAST popinit (); #endif /* FAST */ #ifndef KPOP for (;;) { int i = sizeof *osock; if ((fd = accept (sd, (struct sockaddr *) osock, &i)) == NOTOK) { if (errno != EINTR) padvise ("socket", LOG_WARNING, "unable to accept connection on"); continue; } #endif #ifdef FAST popassert (); #endif /* FAST */ #ifndef KPOP switch (fork ()) { case OK: (void) close (sd); #ifdef SIGCHLD (void) signal (SIGCHLD, SIG_DFL); #endif /* SIGCHLD */ server (fd, osock); _exit (0); case NOTOK: padvise ("socket", LOG_WARNING, "no forks, so rejecting connection on"); default: (void) close (fd); } } #else server (0, isock); #endif } /* */ static server (fd, sin) int fd; struct sockaddr_in *sin; { u_short port; struct hostent *hp; struct in_addr *addr; #ifdef KPOP int auth; int sin_len; struct sockaddr_in faddr; char instance[INST_SZ]; char version[9]; char user[ANAME_SZ]; #endif closelog (); #ifndef BSD43 openlog (myname, LOG_PID); #else /* BSD43 */ openlog (myname, LOG_PID, LOG_DAEMON); #endif /* BSD43 */ port = ntohs (sin -> sin_port); addr = &sin -> sin_addr; hp = gethostbyaddr ((char *)addr, sizeof *addr, sin -> sin_family); padvise (NULLCP, LOG_INFO, "servicing %s/%d", hp ? hp -> h_name : inet_ntoa (*addr), port); if (fd != 0) { (void) dup2 (fd, 0); (void) close (fd); } (void) dup2 (0, 1); #ifdef KPOP sin_len = sizeof (struct sockaddr_in); if (getpeername(0, &faddr, &sin_len) < 0) { padvise("getpeername", LOG_INFO, ""); exit(1); } strcpy(instance, "*"); auth = krb_recvauth(0L, 0, &ticket, "pop", instance, &faddr, (struct sockaddr_in *)NULL, &kdata, "", schedule, version); if (auth == KSUCCESS) auth = krb_kntoln(&kdata, user); if (auth != KSUCCESS) { padvise(NULLCP, LOG_INFO, "bad kerberos data, not ok'ing"); kpop (0, 1, NULLCP, NULLCP, auth); /* respond(NOTOK, krb_err_txt[auth]); */ } else { kpop (0, 1, user, (hp ? hp -> h_name : NULLCP), 0); } #else pop (0, 1, sin -> sin_family == AF_INET && port < IPPORT_RESERVED && hp, hp ? hp -> h_name : NULLCP); #endif } /* */ static arginit (vec) char **vec; { int port; register char *ap; struct hostent *hp; if (myname = rindex (*vec, '/')) myname++; if (myname == NULL || *myname == 0) myname = *vec; (void) gethostname (myhost, sizeof myhost); if (hp = gethostbyname (myhost)) (void) strcpy (myhost, hp -> h_name); #ifndef BSD42 nbits = _NFILE; #else /* BSD42 */ nbits = getdtablesize (); #endif /* BSD42 */ for (vec++; ap = *vec; vec++) { if (*ap == '-') switch (*++ap) { case 'd': options |= SO_DEBUG; continue; case 'p': if ((ap = *++vec) == NULL || *ap == '-' || (port = atoi (ap)) <= 0) padios (NULLCP, "usage: %s -p portno", myname); isock -> sin_port = htons ((u_short) port); continue; default: padios (NULLCP, "-%s: unknown switch", ap); } padios (NULLCP, "usage: %s [switches]", myname); } } /* */ static envinit () { #ifndef KPOP int i, sd; if (!(debug = isatty (2))) { for (i = 0; i < 5; i++) { switch (fork ()) { case NOTOK: sleep (5); continue; case OK: break; default: _exit (0); } break; } (void) chdir ("/"); if ((sd = open ("/dev/null", O_RDWR)) == NOTOK) padios ("/dev/null", "unable to read"); if (sd != 0) (void) dup2 (sd, 0), (void) close (sd); (void) dup2 (0, 1); (void) dup2 (0, 2); if ((sd = open ("/dev/tty", O_RDWR)) != NOTOK) { #ifdef TIOCNOTTY (void) ioctl (sd, TIOCNOTTY, NULLCP); #endif /* TIOCNOTTY */ (void) close (sd); } } for (sd = 3; sd < nbits; sd++) (void) close (sd); #endif /* KPOP */ (void) signal (SIGPIPE, SIG_IGN); #ifndef BSD43 openlog (myname, LOG_PID); #else /* BSD43 */ openlog (myname, LOG_PID, LOG_DAEMON); #endif /* BSD43 */ padvise (NULLCP, LOG_INFO, "starting"); if (debug) padvise (NULLCP, LOG_DEBUG, "options=0x%x port=%d", options, ntohs (isock -> sin_port)); } /* */ #ifndef KPOP /* ARGSUSED */ #ifdef SIGCHLD static TYPESIG chldser (sig, code, sc) int sig; long code; struct sigcontext *sc; { #if defined(BSD42) && !defined(WAITINT) union wait status; #else int status; #endif while (wait3 (&status, WNOHANG, NULLRP) > 0) continue; } #endif /* SIGCHLD */ #endif /* KPOP */ /* */ /* VARARGS2 */ void padios (what, fmt, a, b, c, d, e, f, g, h, i, j) char *what, *fmt, *a, *b, *c, *d, *e, *f, *g, *h, *i, *j; { padvise (what, LOG_ERR, fmt, a, b, c, d, e, f, g, h, i, j); _exit (1); } /* */ /* VARARGS3 */ void padvise (what, code, fmt, a, b, c, d, e, f, g, h, i, j) char *what, *fmt, *a, *b, *c, *d, *e, *f, *g, *h, *i, *j; int code; { int eindex = errno; char buffer[BUFSIZ]; (void) sprintf (buffer, fmt, a, b, c, d, e, f, g, h, i, j); if (what) if (eindex > 0 && eindex < sys_nerr) syslog (code, "%s %s: %s", buffer, what, sys_errlist[eindex]); else syslog (code, "%s %s: Error %d", buffer, what, eindex); else syslog (code, "%s", buffer); if (debug) { fprintf (stderr, "[%d] %s", code, buffer); if (what) (void) fputc (' ', stderr), perror (what); else (void) fputc ('\n', stderr); (void) fflush (stderr); } errno = eindex; } @ 1.15 log @BSD44 case in gethostbyaddr typo @ text @d3 1 a3 1 static char ident[] = "@@(#)$Id: popd.c,v 1.14 1992/12/16 22:31:20 jromine Exp jromine $"; d61 1 a63 1 #ifndef BSD44 /* const */ @ 1.14 log @TYPESIG fixups @ text @d3 1 a3 1 static char ident[] = "@@(#)$Id: popd.c,v 1.13 1992/12/15 00:20:22 jromine Exp jromine $"; d63 1 d65 1 d263 1 a263 1 hp = gethostbyaddr (addr, sizeof *addr, sin -> sin_family); d415 2 a417 2 #else union wait status; @ 1.13 log @endif sugar @ text @d3 1 a3 1 static char ident[] = "@@(#)$Id: popd.c,v 1.12 1992/12/14 17:11:17 jromine Exp jromine $"; d86 1 a86 1 static int chldser (); d407 1 a407 1 static int chldser (sig, code, sc) @ 1.12 log @WAITINT ifdef @ text @d3 2 a4 2 static char ident[] = "@@(#)$Id: popd.c,v 1.11 1992/11/11 22:26:33 jromine Exp jromine $"; #endif lint d165 1 a165 1 #else BSD43 d167 1 a167 1 #endif BSD43 d169 1 a169 1 #endif RESTART d181 1 a181 1 #else BSD43 d187 1 a187 1 #endif BSD43 d193 1 a193 1 #endif SIGCHLD d198 1 a198 1 #endif FAST d212 1 a212 1 #endif FAST d219 1 a219 1 #endif SIGCHLD d256 1 a256 1 #else BSD43 d258 1 a258 1 #endif BSD43 d315 1 a315 1 #else BSD42 d317 1 a317 1 #endif BSD42 d377 1 a377 1 #endif TIOCNOTTY d390 1 a390 1 #else BSD43 d392 1 a392 1 #endif BSD43 @ 1.11 log @use union wait only on BSD42 @ text @d3 1 a3 1 static char ident[] = "@@(#)$Id: popd.c,v 1.10 1992/02/11 18:55:11 jromine Exp jromine $"; d128 1 d130 3 d412 3 a414 1 #ifdef BSD42 a415 2 #else int status; @ 1.10 log @use _NFILE for #fds #ifndef BSD42 @ text @d3 1 a3 1 static char ident[] = "@@(#)$Id: popd.c,v 1.9 1992/01/31 22:02:30 jromine Exp jromine $"; d408 1 d410 3 @ 1.9 log @kerberos @ text @d3 1 a3 1 static char ident[] = "@@(#)$Id: popd.c,v 1.8 90/04/09 09:45:09 sources Exp Locker: sources $"; d309 3 d313 1 @ 1.8 log @POPSERVICE define @ text @d3 1 a3 1 static char ident[] = "@@(#)$Id: popd.c,v 1.7 90/04/05 15:34:33 sources Exp Locker: sources $"; d24 1 a24 1 #endif NOIOCTLH d30 1 a30 1 #endif SIGTSTP d34 7 d43 1 a43 1 #endif SYS5 d48 1 a48 1 #endif SYS5 d82 3 d99 3 d108 1 d110 5 d120 1 d124 1 d191 1 d195 1 d205 1 d209 1 d226 3 d240 8 d260 5 a264 3 (void) dup2 (fd, 0); (void) close (fd); d267 20 d289 1 d303 1 a303 1 if (myname == NULL || *myname == NULL) d337 1 d376 1 d393 2 d410 2 a411 1 #endif SIGCHLD @ 1.7 log @add ID @ text @d3 1 a3 1 static char ident[] = "@@(#)$Id:$"; d63 3 d70 1 a70 1 static char *myservice = "pop"; @ 1.6 log @add ID @ text @d3 1 a3 1 static char ident[] = "@@(#)$Id:"; @ 1.5 log @ANSI Compilance @ text @d2 3 @ 1.4 log @*** empty log message *** @ text @d70 1 a70 1 int chldser (); d73 1 @ 1.3 log @SYS5 fixes @ text @d19 1 d21 1 @ 1.2 log @SYS5 fix @ text @d15 2 a16 2 #include #include d22 1 d25 1 d157 1 d159 1 d179 1 d181 1 d298 1 d300 1 d325 2 d337 2 @ 1.1 log @Initial revision @ text @d27 3 d31 4 @