diff -urNp vpopmail-5.1.10/Makefile.am vpopmail-5.1.10-patched/Makefile.am --- vpopmail-5.1.10/Makefile.am Wed Jan 23 10:02:21 2002 +++ vpopmail-5.1.10-patched/Makefile.am Wed Jan 30 13:52:30 2002 @@ -4,7 +4,7 @@ SUBDIRS=cdb noinst_LIBRARIES=libvpopmail.a -COMMONSOURCES=vpopmail.c md5.c bigdir.c vauth.c file_lock.c vpalias.c +COMMONSOURCES=vpopmail.c md5.c bigdir.c vauth.c file_lock.c vpalias.c seek.c CONFIG_CLEAN_FILES=vauth.c libvpopmail_a_SOURCES=$(COMMONSOURCES) diff -urNp vpopmail-5.1.10/Makefile.in vpopmail-5.1.10-patched/Makefile.in --- vpopmail-5.1.10/Makefile.in Thu Jan 24 14:34:46 2002 +++ vpopmail-5.1.10-patched/Makefile.in Wed Jan 30 13:52:30 2002 @@ -76,7 +76,7 @@ SUBDIRS = cdb noinst_LIBRARIES = libvpopmail.a -COMMONSOURCES = vpopmail.c md5.c bigdir.c vauth.c file_lock.c vpalias.c +COMMONSOURCES = vpopmail.c md5.c bigdir.c vauth.c file_lock.c vpalias.c seek.c CONFIG_CLEAN_FILES = vauth.c libvpopmail_a_SOURCES = $(COMMONSOURCES) @@ -165,7 +165,7 @@ LDFLAGS = @LDFLAGS@ LIBS = @LIBS@ libvpopmail_a_DEPENDENCIES = cdb/*.o libvpopmail_a_OBJECTS = vpopmail.o md5.o bigdir.o vauth.o file_lock.o \ -vpalias.o +vpalias.o seek.o AR = ar PROGRAMS = $(vpopmailbin_PROGRAMS) diff -urNp vpopmail-5.1.10/seek.c vpopmail-5.1.10-patched/seek.c --- vpopmail-5.1.10/seek.c Wed Dec 31 19:00:00 1969 +++ vpopmail-5.1.10-patched/seek.c Wed Jan 30 13:52:30 2002 @@ -0,0 +1,87 @@ +/* + * Copyright (c) 1987 University of Maryland Computer Science Department. + * All rights reserved. + * Permission to copy for any purpose is hereby granted so long as this + * copyright notice remains intact. + * + * Changed MakeSeekable to use tmpfile() - marcus@quintic.co.uk + */ + +/* + * Seekable is a predicate which returns true iff a Unix fd is seekable. + * + * MakeSeekable forces an input stdio file to be seekable, by copying to + * a temporary file if necessary. + */ + +#include +#include +#include +#include +#include +#include + +long lseek(); +char *getenv(); + +int +Seekable(fd) + int fd; +{ + + return (lseek(fd, 0L, 1) >= 0 && !isatty(fd)); +} + +int +MakeSeekable(f) + register FILE *f; +{ + register int tf, n; + FILE *tmpf; + int blksize; +#ifdef MAXBSIZE + char buf[MAXBSIZE]; + struct stat st; +#else + char buf[BUFSIZ]; +#endif + + if (Seekable(fileno(f))) + return (0); + + tmpf = tmpfile(); /* tmpfile() is not safe on all systems */ + tf = fileno(tmpf); + + /* copy from input file to temp file */ +#ifdef MAXBSIZE + if (fstat(tf, &st)) /* how can this ever fail? */ + blksize = MAXBSIZE; + else + blksize = MIN(MAXBSIZE, st.st_blksize); +#else + blksize = BUFSIZ; +#endif + while ((n = fread(buf, 1, blksize, f)) > 0) { + if (write(tf, buf, n) != n) { + (void) close(tf); + return (-1); + } + } + /* ferror() is broken in Ultrix 1.2; hence the && */ + if (ferror(f) && !feof(f)) { + (void) close(tf); + return (-1); + } + + /* + * Now switch f to point at the temp file. Since we hit EOF, there + * is nothing in f's stdio buffers, so we can play a dirty trick: + */ + clearerr(f); + if (dup2(tf, fileno(f))) { + (void) close(tf); + return (-1); + } + (void) close(tf); + return (0); +} diff -urNp vpopmail-5.1.10/seek.h vpopmail-5.1.10-patched/seek.h --- vpopmail-5.1.10/seek.h Wed Dec 31 19:00:00 1969 +++ vpopmail-5.1.10-patched/seek.h Wed Jan 30 13:52:30 2002 @@ -0,0 +1,16 @@ +/* + * Copyright (c) 1987 University of Maryland Computer Science Department. + * All rights reserved. + * Permission to copy for any purpose is hereby granted so long as this + * copyright notice remains intact. + */ + +/* + * Seekable is a predicate which returns true iff a Unix fd is seekable. + * + * MakeSeekable forces an input stdio file to be seekable, by copying to + * a temporary file if necessary. + */ + +int Seekable(int fd); +int MakeSeekable(register FILE *f); diff -urNp vpopmail-5.1.10/vdelivermail.c vpopmail-5.1.10-patched/vdelivermail.c --- vpopmail-5.1.10/vdelivermail.c Sat Jan 26 13:45:20 2002 +++ vpopmail-5.1.10-patched/vdelivermail.c Wed Jan 30 13:52:30 2002 @@ -36,6 +36,7 @@ #include "vpopmail.h" #include "vauth.h" #include "maildirquota.h" +#include "seek.h" /* Globals */ #define AUTH_SIZE 300 @@ -498,6 +499,9 @@ int deliver_mail(char *address, char *qu "%sDelivered-To: %s\n", getenv("RPLINE"), dtline); } + if (!Seekable(0)) + MakeSeekable(stdin); + if ( lseek(0, 0L, SEEK_SET) < 0 ) { printf("lseek errno=%d\n", errno); return(errno); @@ -679,6 +683,9 @@ void run_command(char *prog) while (*prog==' ') ++prog; while (*prog=='|') ++prog; + if (!Seekable(0)) + MakeSeekable(stdin); + if ( lseek(0, 0L, SEEK_SET) < 0 ) { printf("lseek errno=%d\n", errno); return; @@ -729,6 +736,9 @@ int is_looping( char *address ) return(1); } + if (!Seekable(0)) + MakeSeekable(stdin); + lseek(0,0L,SEEK_SET); while(fgets(loop_buf,sizeof(loop_buf),stdin)!=NULL){ @@ -795,6 +805,9 @@ off_t get_message_size() { ssize_t message_size; ssize_t bytes; + + if (!Seekable(0)) + MakeSeekable(stdin); if ( lseek(0, 0L,SEEK_SET) < 0 ) { printf("lseek error %d\n", errno); diff -urNp vpopmail-5.1.10/vqmaillocal.c vpopmail-5.1.10-patched/vqmaillocal.c --- vpopmail-5.1.10/vqmaillocal.c Sat Jan 26 13:45:45 2002 +++ vpopmail-5.1.10-patched/vqmaillocal.c Wed Jan 30 14:01:20 2002 @@ -401,6 +401,10 @@ int deliver_mail(char *address, char *qu printf("message is looping %s\n", address ); return(-3); } + + /* at this point we know the message size - if its 0 drop out silently */ + if (message_size==0) + return(0); /* This is a directory/Maildir location */ if ( *address == '/' ) {