9 date 93.08.25.17.23.05; author jromine; state Exp;
14 date 93.02.26.22.11.12; author jromine; state Exp;
19 date 92.12.16.22.31.20; author jromine; state Exp;
24 date 92.12.15.00.20.22; author jromine; state Exp;
29 date 92.12.14.17.11.17; author jromine; state Exp;
34 date 92.11.11.22.26.33; author jromine; state Exp;
39 date 92.02.11.18.55.11; author jromine; state Exp;
44 date 92.01.31.22.02.30; author jromine; state Exp;
49 date 90.04.09.09.45.09; author sources; state Exp;
54 date 90.04.05.15.34.33; author sources; state Exp;
59 date 90.04.05.14.53.52; author sources; state Exp;
64 date 90.02.06.13.12.22; author sources; state Exp;
69 date 90.02.05.15.01.40; author sources; state Exp;
74 date 90.02.05.14.07.50; author sources; state Exp;
79 date 90.02.05.13.58.18; author sources; state Exp;
84 date 90.02.05.13.58.08; author sources; state Exp;
95 @off_t fixes for BSD44
98 @/* popd.c - the POP server */
100 static char ident[] = "@@(#)$Id: popd.c,v 1.15 1993/02/26 22:11:12 jromine Exp jromine $";
103 /* Author: Marshall T. Rose <MRose@@UDel> (MTR)
104 Department of Computer Science and Information Sciences
105 University of Delaware
109 Date: Sun Oct 28 16:23:26 1984
115 #include "../h/strings.h"
117 #include <sys/types.h>
118 #include <sys/file.h>
120 #include <sys/ioctl.h>
122 #include <sys/socket.h>
123 #include <sys/time.h>
125 #include <sys/resource.h>
126 #include <sys/wait.h>
128 #include <netinet/in.h>
130 #include <arpa/inet.h>
134 static Key_schedule schedule;
135 static KTEXT_ST ticket;
136 static AUTH_DAT kdata;
144 #define u_short ushort
150 #define NULLCP ((char *) 0)
151 #define NULLRP ((struct rusage *) 0)
153 #define FAST /* fast start-up of BBoards */
160 extern char *sys_errlist[];
161 extern char *sys_siglist[];
166 static int nbits = ((sizeof (int)) * 8);
167 static int options = 0;
170 #define POPSERVICE "pop"
173 char *myname = "popd";
175 static char *myprotocol = "tcp";
176 static char *myservice = POPSERVICE;
178 static struct sockaddr_in in_socket;
179 static struct sockaddr_in *isock = &in_socket;
182 static AUTH_DAT kdata;
185 static TYPESIG chldser ();
186 void padios (), padvise ();
188 static server(), arginit(), envinit();
193 main (argc, argv, envp)
205 struct sockaddr_in out_socket,
206 *osock = &out_socket;
210 i = sizeof(in_socket);
211 if (getpeername(0, &in_socket, &i) < 0)
212 padios("getpeername", "bad status");
214 if ((sp = getservbyname (myservice, myprotocol)) == NULL)
215 padios (NULLCP, "%s/%s: unknown service", myprotocol, myservice);
216 isock -> sin_family = AF_INET;
217 isock -> sin_port = sp -> s_port;
218 isock -> sin_addr.s_addr = INADDR_ANY;
227 #if defined(BSD42) && !defined(WAITINT)
243 (void) wait3 (&status, 0, NULLRP);
244 if (WIFEXITED (status))
245 (void) sprintf (reason, "exit=0%o", status.w_retcode);
247 if (WIFSIGNALED (status))
248 (void) sprintf (reason, "signal=%s%s",
249 status.w_termsig < NSIG
250 ? sys_siglist[status.w_termsig] : "unknown",
251 status.w_coredump ? " (core dumped)" : NULL);
253 (void) strcpy (reason, "stopped(!!)");
254 padvise (NULLCP, LOG_WARNING, "%s/%s server has terminated -- %s",
255 sp -> s_proto, sp -> s_name, reason);
263 openlog (myname, LOG_PID);
265 openlog (myname, LOG_PID, LOG_DAEMON);
267 padvise (NULLCP, LOG_INFO, "restart");
272 if ((sd = socket (AF_INET, SOCK_STREAM, 0)) == NOTOK)
273 padios ("socket", "unable to create");
275 if (options & SO_DEBUG)
276 if (setsockopt (sd, SOL_SOCKET, SO_DEBUG, NULL, 0) == NOTOK)
277 padvise ("SO_DEBUG", LOG_WARNING, "unable to set socket option");
278 if (setsockopt (sd, SOL_SOCKET, SO_KEEPALIVE, NULL, 0) == NOTOK)
279 padvise ("SO_KEEPALIVE", LOG_WARNING, "unable to set socket option");
281 if (options & SO_DEBUG)
282 if (setsockopt (sd, SOL_SOCKET, SO_DEBUG, &on, sizeof on) == NOTOK)
283 padvise ("SO_DEBUG", LOG_WARNING, "unable to set socket option");
284 if (setsockopt (sd, SOL_SOCKET, SO_KEEPALIVE, &on, sizeof on) == NOTOK)
285 padvise ("SO_KEEPALIVE", LOG_WARNING, "unable to set socket option");
287 if (bind (sd, (struct sockaddr *) isock, sizeof *isock) == NOTOK)
288 padios ("socket", "unable to bind");
291 (void) signal (SIGCHLD, chldser);
293 (void) listen (sd, SOMAXCONN);
300 int i = sizeof *osock;
302 if ((fd = accept (sd, (struct sockaddr *) osock, &i)) == NOTOK) {
304 padvise ("socket", LOG_WARNING,
305 "unable to accept connection on");
317 (void) signal (SIGCHLD, SIG_DFL);
323 padvise ("socket", LOG_WARNING,
324 "no forks, so rejecting connection on");
336 static server (fd, sin)
338 struct sockaddr_in *sin;
342 struct in_addr *addr;
346 struct sockaddr_in faddr;
347 char instance[INST_SZ];
354 openlog (myname, LOG_PID);
356 openlog (myname, LOG_PID, LOG_DAEMON);
358 port = ntohs (sin -> sin_port);
359 addr = &sin -> sin_addr;
360 hp = gethostbyaddr ((char *)addr, sizeof *addr, sin -> sin_family);
361 padvise (NULLCP, LOG_INFO, "servicing %s/%d",
362 hp ? hp -> h_name : inet_ntoa (*addr), port);
371 sin_len = sizeof (struct sockaddr_in);
372 if (getpeername(0, &faddr, &sin_len) < 0) {
373 padvise("getpeername", LOG_INFO, "");
376 strcpy(instance, "*");
377 auth = krb_recvauth(0L, 0, &ticket, "pop", instance,
378 &faddr, (struct sockaddr_in *)NULL,
379 &kdata, "", schedule, version);
380 if (auth == KSUCCESS)
381 auth = krb_kntoln(&kdata, user);
383 if (auth != KSUCCESS) {
384 padvise(NULLCP, LOG_INFO, "bad kerberos data, not ok'ing");
385 kpop (0, 1, NULLCP, NULLCP, auth); /* respond(NOTOK, krb_err_txt[auth]); */
387 kpop (0, 1, user, (hp ? hp -> h_name : NULLCP), 0);
390 pop (0, 1, sin -> sin_family == AF_INET && port < IPPORT_RESERVED && hp,
391 hp ? hp -> h_name : NULLCP);
404 if (myname = rindex (*vec, '/'))
406 if (myname == NULL || *myname == 0)
409 (void) gethostname (myhost, sizeof myhost);
410 if (hp = gethostbyname (myhost))
411 (void) strcpy (myhost, hp -> h_name);
415 nbits = getdtablesize ();
418 for (vec++; ap = *vec; vec++) {
426 if ((ap = *++vec) == NULL
428 || (port = atoi (ap)) <= 0)
429 padios (NULLCP, "usage: %s -p portno", myname);
430 isock -> sin_port = htons ((u_short) port);
434 padios (NULLCP, "-%s: unknown switch", ap);
437 padios (NULLCP, "usage: %s [switches]", myname);
448 if (!(debug = isatty (2))) {
449 for (i = 0; i < 5; i++) {
466 if ((sd = open ("/dev/null", O_RDWR)) == NOTOK)
467 padios ("/dev/null", "unable to read");
469 (void) dup2 (sd, 0), (void) close (sd);
473 if ((sd = open ("/dev/tty", O_RDWR)) != NOTOK) {
475 (void) ioctl (sd, TIOCNOTTY, NULLCP);
476 #endif /* TIOCNOTTY */
481 for (sd = 3; sd < nbits; sd++)
485 (void) signal (SIGPIPE, SIG_IGN);
488 openlog (myname, LOG_PID);
490 openlog (myname, LOG_PID, LOG_DAEMON);
492 padvise (NULLCP, LOG_INFO, "starting");
494 padvise (NULLCP, LOG_DEBUG, "options=0x%x port=%d",
495 options, ntohs (isock -> sin_port));
506 static TYPESIG chldser (sig, code, sc)
509 struct sigcontext *sc;
511 #if defined(BSD42) && !defined(WAITINT)
517 while (wait3 (&status, WNOHANG, NULLRP) > 0)
528 void padios (what, fmt, a, b, c, d, e, f, g, h, i, j)
542 padvise (what, LOG_ERR, fmt, a, b, c, d, e, f, g, h, i, j);
550 void padvise (what, code, fmt, a, b, c, d, e, f, g, h, i, j)
568 (void) sprintf (buffer, fmt, a, b, c, d, e, f, g, h, i, j);
570 if (eindex > 0 && eindex < sys_nerr)
571 syslog (code, "%s %s: %s", buffer, what, sys_errlist[eindex]);
573 syslog (code, "%s %s: Error %d", buffer, what, eindex);
575 syslog (code, "%s", buffer);
578 fprintf (stderr, "[%d] %s", code, buffer);
580 (void) fputc (' ', stderr), perror (what);
582 (void) fputc ('\n', stderr);
583 (void) fflush (stderr);
594 case in gethostbyaddr
600 static char ident[] = "@@(#)$Id: popd.c,v 1.14 1992/12/16 22:31:20 jromine Exp jromine $";
603 #ifndef BSD44 /* const */
614 static char ident[] = "@@(#)$Id: popd.c,v 1.13 1992/12/15 00:20:22 jromine Exp jromine $";
619 hp = gethostbyaddr (addr, sizeof *addr, sin -> sin_family);
634 static char ident[] = "@@(#)$Id: popd.c,v 1.12 1992/12/14 17:11:17 jromine Exp jromine $";
637 static int chldser ();
640 static int chldser (sig, code, sc)
651 static char ident[] = "@@(#)$Id: popd.c,v 1.11 1992/11/11 22:26:33 jromine Exp jromine $";
706 @use union wait only on BSD42
711 static char ident[] = "@@(#)$Id: popd.c,v 1.10 1992/02/11 18:55:11 jromine Exp jromine $";
725 @use _NFILE for #fds #ifndef BSD42
730 static char ident[] = "@@(#)$Id: popd.c,v 1.9 1992/01/31 22:02:30 jromine Exp jromine $";
743 static char ident[] = "@@(#)$Id: popd.c,v 1.8 90/04/09 09:45:09 sources Exp Locker: sources $";
756 static char ident[] = "@@(#)$Id: popd.c,v 1.7 90/04/05 15:34:33 sources Exp Locker: sources $";
791 if (myname == NULL || *myname == NULL)
808 static char ident[] = "@@(#)$Id:$";
812 static char *myservice = "pop";
823 static char ident[] = "@@(#)$Id:";
838 @*** empty log message ***