Make popper timeout after 120 seconds.
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@204 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
@@ -84,6 +84,11 @@ char ** argmessage;
|
||||
trace_file_name = optarg;
|
||||
break;
|
||||
|
||||
/* Timeout value passed. Default changed */
|
||||
case 'T':
|
||||
pop_timeout = atoi(optarg);
|
||||
break;
|
||||
|
||||
/* Unknown option received */
|
||||
default:
|
||||
errflag++;
|
||||
|
@@ -88,6 +88,8 @@ POP * p;
|
||||
strcat(tmpbuf, "\n");
|
||||
if (strlen(tmpbuf) < MAXMSGLINELEN) {
|
||||
pop_sendline (p,tmpbuf);
|
||||
if (hangup)
|
||||
return (pop_msg (p,POP_FAILURE,"SIGHUP or SIGPIPE flagged"));
|
||||
return_path_sent++;
|
||||
}
|
||||
}
|
||||
@@ -107,6 +109,8 @@ POP * p;
|
||||
end of the header. sendline() converts this to a NULL,
|
||||
so that's what we look for. */
|
||||
if (*buffer == 0) break;
|
||||
if (hangup)
|
||||
return (pop_msg (p,POP_FAILURE,"SIGHUP or SIGPIPE flagged"));
|
||||
}
|
||||
/* Send the message body */
|
||||
while (fgets(buffer,MAXMSGLINELEN,p->drop)) {
|
||||
@@ -115,6 +119,8 @@ POP * p;
|
||||
/* Decrement the lines sent (for a TOP command) */
|
||||
if (msg_lines >= 0 && msg_lines-- == 0) break;
|
||||
pop_sendline(p,buffer);
|
||||
if (hangup)
|
||||
return (pop_msg (p,POP_FAILURE,"SIGHUP or SIGPIPE flagged"));
|
||||
}
|
||||
/* "." signals the end of a multi-line transmission */
|
||||
(void)fputs(".\r\n",p->output);
|
||||
|
@@ -11,10 +11,52 @@ static char SccsId[] = "@(#)@(#)popper.c 2.1 2.1 3/18/91";
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <signal.h>
|
||||
#include <setjmp.h>
|
||||
#include "popper.h"
|
||||
|
||||
extern state_table * pop_get_command();
|
||||
|
||||
int hangup = FALSE ;
|
||||
|
||||
static int
|
||||
catchSIGHUP()
|
||||
{
|
||||
hangup = TRUE ;
|
||||
|
||||
/* This should not be a problem on BSD systems */
|
||||
signal(SIGHUP, (void *)catchSIGHUP);
|
||||
signal(SIGPIPE, (void *)catchSIGHUP);
|
||||
}
|
||||
|
||||
int pop_timeout = POP_TIMEOUT;
|
||||
|
||||
jmp_buf env;
|
||||
|
||||
static int
|
||||
ring()
|
||||
{
|
||||
longjmp(env,1);
|
||||
}
|
||||
|
||||
/*
|
||||
* fgets, but with a timeout
|
||||
*/
|
||||
static char *
|
||||
tgets(char *str, int size, FILE *fp, int timeout)
|
||||
{
|
||||
int ring();
|
||||
(void) signal(SIGALRM, (void *)ring);
|
||||
alarm(timeout);
|
||||
if (setjmp(env))
|
||||
str = NULL;
|
||||
else
|
||||
str = fgets(str,size,fp);
|
||||
alarm(0);
|
||||
signal(SIGALRM,SIG_DFL);
|
||||
return(str);
|
||||
}
|
||||
|
||||
/*
|
||||
* popper: Handle a Post Office Protocol version 3 session
|
||||
*/
|
||||
@@ -26,6 +68,9 @@ char ** argv;
|
||||
state_table * s;
|
||||
char message[MAXLINELEN];
|
||||
|
||||
(void) signal(SIGHUP,(void *)catchSIGHUP);
|
||||
(void) signal(SIGPIPE,(void *)catchSIGHUP);
|
||||
|
||||
/* Start things rolling */
|
||||
pop_init(&p,argc,argv);
|
||||
|
||||
@@ -40,11 +85,16 @@ char ** argv;
|
||||
until the client quits or an error occurs. */
|
||||
|
||||
for (p.CurrentState=auth1;p.CurrentState!=halt&&p.CurrentState!=error;) {
|
||||
|
||||
/* Obtain a line from the client */
|
||||
if (fgets(message,MAXLINELEN,p.input) == NULL) {
|
||||
if (hangup) {
|
||||
pop_msg(&p,POP_FAILURE,"POP hangup",p.myhost);
|
||||
if (p.CurrentState > auth2 && !pop_updt(&p))
|
||||
pop_msg(&p,POP_FAILURE,"POP mailbox update failed.",p.myhost);
|
||||
p.CurrentState = error;
|
||||
} else if (tgets(message,MAXLINELEN,p.input,pop_timeout) == NULL) {
|
||||
pop_msg(&p,POP_FAILURE,"POP timeout",p.myhost);
|
||||
if (p.CurrentState > auth2 && !pop_updt(&p))
|
||||
pop_msg(&p,POP_FAILURE,"POP mailbox update failed!",p.myhost);
|
||||
p.CurrentState = error;
|
||||
pop_msg(&p,POP_FAILURE,"POP server at %s signing off.",p.myhost);
|
||||
}
|
||||
else {
|
||||
/* Search for the command in the command/state table */
|
||||
|
@@ -75,9 +75,14 @@
|
||||
#define POP_SUCCESS 1
|
||||
#define POP_FAILURE 0
|
||||
#define POP_TERMINATE '.'
|
||||
#define POP_TIMEOUT 120 /* timeout connection after this many secs */
|
||||
|
||||
extern int errno;
|
||||
|
||||
extern int pop_timeout;
|
||||
|
||||
extern int hangup;
|
||||
|
||||
#define pop_command pop_parm[0] /* POP command is first token */
|
||||
#define pop_subcommand pop_parm[1] /* POP XTND subcommand is the
|
||||
second token */
|
||||
|
Reference in New Issue
Block a user