Skip to content

Commit

Permalink
rewind descriptor 0 regardless of MAKE_SEEKABLE setting
Browse files Browse the repository at this point in the history
  • Loading branch information
mbhangui committed Oct 25, 2023
1 parent 087bd68 commit f9f56f7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 58 deletions.
60 changes: 5 additions & 55 deletions indimail-mta-x/autoresponder.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include <tai.h>
#include <constmap.h>
#include <noreturn.h>
#include <mktempfile.h>
#include "hassrs.h"
#ifdef HAVESRS
#include "srs.h"
Expand Down Expand Up @@ -934,59 +935,6 @@ count_history(char *sender, unsigned max)
return 0;
}

int
mkTempFile(int seekfd)
{
char inbuf[2048], outbuf[2048];
char *tmpdir;
static stralloc tmpFile = {0};
struct substdio ssin_t;
struct substdio ssout_t;
int fd;

if (lseek(seekfd, 0, SEEK_SET) == 0)
return (0);
if(errno == EBADF)
strerr_die2sys(111, FATAL, "unable to lseek: ");
if (!(tmpdir = env_get("TMPDIR")))
tmpdir = "/tmp";
if (!stralloc_copys(&tmpFile, tmpdir) ||
!stralloc_cats(&tmpFile, "/qmailFilterXXX") ||
!stralloc_catb(&tmpFile, strnum, fmt_ulong(strnum, (unsigned long) getpid())) ||
!stralloc_0(&tmpFile))
strerr_die2x(111, FATAL, "out of memory");
if ((fd = open(tmpFile.s, O_RDWR | O_EXCL | O_CREAT, 0600)) == -1)
strerr_die3sys(111, FATAL, "unable to open: ", tmpFile.s);
unlink(tmpFile.s);
substdio_fdbuf(&ssout_t, write, fd, outbuf, sizeof(outbuf));
substdio_fdbuf(&ssin_t, read, seekfd, inbuf, sizeof(inbuf));
switch (substdio_copy(&ssout_t, &ssin_t))
{
case -2: /*- read error */
close(fd);
strerr_die2sys(111, FATAL, "unable to read input: ");
case -3: /*- write error */
close(fd);
strerr_die2sys(111, FATAL, "unable to write output: ");
}
if (substdio_flush(&ssout_t) == -1) {
close(fd);
strerr_die2sys(111, FATAL, "unable to write: ");
}
if(fd != seekfd) {
if (dup2(fd, seekfd) == -1) {
close(fd);
strerr_die2sys(111, FATAL, "unable to dup: ");
}
close(fd);
}
if (lseek(seekfd, 0, SEEK_SET) != 0) {
close(seekfd);
strerr_die2sys(111, FATAL, "unable to lseek: ");
}
return (0);
}

/*
* qmail-autoresponder -c -N -n 3 /tmp/test.msg /tmp/abcd < ../scripts/mail.msg |less
*/
Expand Down Expand Up @@ -1031,8 +979,8 @@ main(int argc, char *argv[])
if (srs_domain.len && !stralloc_0(&srs_domain))
strerr_die2x(111, FATAL, "out of memory");
srs_domain.len--; /*- substract length due to stralloc_0 */
if (env_get("MAKE_SEEKABLE") && mkTempFile(0))
strerr_die2sys(111, FATAL, "makeseekable: ");
if (mktempfile(0))
strerr_die2sys(111, FATAL, "mktempfile: ");
get_arguments(argc, argv);
/*- Fail if SENDER or DTLINE are not set */
if (!(sender = env_get("SENDER")))
Expand Down Expand Up @@ -1302,6 +1250,8 @@ getversion_qmail_autoresponder_c()
static char *x = "$Id: autoresponder.c,v 1.39 2023-10-02 17:40:58+05:30 Cprogrammer Exp mbhangui $";

x++;
x = sccsidmktempfileh;
x++;
}

/*
Expand Down
3 changes: 3 additions & 0 deletions indimail-mta-x/doc/ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ o Updated test-indimail-mta with additional tests (SPF, SRS, CHECKSENDER,
62. qmail-queue.c: added feature to negate regexp match
63. create_services.in: added --secureauth option for smtp port 587
64. create_services.in: added --setuser-priv option for slowq service
- 25/10/2023
65. autoresponder.c, indimail-spamfilter.c: rewind descriptor 0 regardless of
MAKE_SEEKABLE setting

* Fri Sep 08 2023 11:58:03 +0000 Manvendra Bhangui <indimail-mta@indimail.org> 3.0.4-1.1%{?dist}
Release 3.0.4-1.1 Start 24/04/2023 End 08/09/2023
Expand Down
5 changes: 2 additions & 3 deletions indimail-mta-x/qmail-spamfilter.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ main(int argc, char **argv)
struct substdio ssin, ssout;
stralloc spamfilterargs = { 0 }, q = { 0 };
char inbuf[2048], outbuf[2048];
char *ptr, *makeseekable, *spamf;
char *ptr, *spamf;
char **Argv;

if (chdir("/") == -1)
Expand Down Expand Up @@ -99,8 +99,7 @@ main(int argc, char **argv)
if (!(Argv = makeargs(spamfilterargs.s)))
_exit(QQ_OUT_OF_MEMORY);
/*- Mail content read from fd 0 */
makeseekable = env_get("MAKE_SEEKABLE");
if (makeseekable && mktempfile(0))
if (mktempfile(0))
_exit(QQ_TMP_FILES);
if (dup2(pipefd[1], 1) == -1)
_exit(QQ_DUP_ERR);
Expand Down

0 comments on commit f9f56f7

Please sign in to comment.