From 89b7b67a13ebb7965cc7f13ad0595e2194a2d34c Mon Sep 17 00:00:00 2001 From: Jannis Hoffmann Date: Wed, 3 Jul 2024 15:48:04 +0200 Subject: add sqmail-4.2.29a --- src/qmail-badloadertypes.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 src/qmail-badloadertypes.c (limited to 'src/qmail-badloadertypes.c') diff --git a/src/qmail-badloadertypes.c b/src/qmail-badloadertypes.c new file mode 100644 index 0000000..3472fd5 --- /dev/null +++ b/src/qmail-badloadertypes.c @@ -0,0 +1,68 @@ +#include +#include +#include +#include "logmsg.h" +#include "stralloc.h" +#include "buffer.h" +#include "getln.h" +#include "exit.h" +#include "open.h" +#include "auto_qmail.h" +#include "cdbmake.h" + +#define WHO "qmail-badloadertypes" +#define LOADER_LEN 5 + +int rename(const char *,const char *); // stdio.h + +void die_read() +{ + logmsg(WHO,111,FATAL,"unable to read control/badloadertypes"); +} +void die_write() +{ + logmsg(WHO,111,FATAL,"unable to write to control/badloadertypes.tmp"); +} + +char inbuf[1024]; +buffer b; + +int fd; +int fdtemp; + +struct cdb_make cdb; +stralloc line = {0}; +int match; + +int main() +{ + umask(033); + if (chdir(auto_qmail) == -1) + logmsg(WHO,111,FATAL,B("unable to chdir to: ",auto_qmail)); + + fd = open_read("control/badloadertypes"); + if (fd == -1) die_read(); + + buffer_init(&b,read,fd,inbuf,sizeof(inbuf)); + + fdtemp = open_trunc("control/badloadertypes.tmp"); + if (fdtemp == -1) die_write(); + + if (cdb_make_start(&cdb,fdtemp) == -1) die_write(); + + for (;;) { + if (getln(&b,&line,&match,'\n') != 0) die_read(); + if (line.s[0] != '#' && line.len > LOADER_LEN) + if (cdb_make_add(&cdb,line.s,LOADER_LEN,"",0) == -1) + die_write(); + if (!match) break; + } + + if (cdb_make_finish(&cdb) == -1) die_write(); + if (fsync(fdtemp) == -1) die_write(); + if (close(fdtemp) == -1) die_write(); /* NFS stupidity */ + if (rename("control/badloadertypes.tmp","control/badloadertypes.cdb") == -1) + logmsg(WHO,111,FATAL,"unable to move control/badloadertypes.tmp to control/badloadertypes.cdb"); + + _exit(0); +} -- cgit v1.2.3