summaryrefslogtreecommitdiff
path: root/sqmail-4.3.07/src/qmail-recipients.c
diff options
context:
space:
mode:
authorErwin Hoffmann <feh@fehcom.de>2024-01-14 17:55:54 +0100
committerErwin Hoffmann <feh@fehcom.de>2024-01-14 17:55:54 +0100
commita293489ee83c8b05d845a162dc2a4de026f3775d (patch)
treed50ab15afde698ad2d32bfc251753e5e89204f25 /sqmail-4.3.07/src/qmail-recipients.c
s/qmail 4.3.07
Diffstat (limited to 'sqmail-4.3.07/src/qmail-recipients.c')
-rw-r--r--sqmail-4.3.07/src/qmail-recipients.c77
1 files changed, 77 insertions, 0 deletions
diff --git a/sqmail-4.3.07/src/qmail-recipients.c b/sqmail-4.3.07/src/qmail-recipients.c
new file mode 100644
index 0000000..058994a
--- /dev/null
+++ b/sqmail-4.3.07/src/qmail-recipients.c
@@ -0,0 +1,77 @@
+#include <unistd.h>
+#include <sys/stat.h>
+#include "logmsg.h"
+#include "stralloc.h"
+#include "buffer.h"
+#include "getln.h"
+#include "exit.h"
+#include "open.h"
+#include "case.h"
+#include "auto_qmail.h"
+#include "cdbmake.h"
+
+#define WHO "qmail-recipients"
+
+int rename(const char *,const char *); // stdio.h
+
+void die_read()
+{
+ logmsg(WHO,111,ERROR,"unable to read users/recipients");
+}
+void die_write()
+{
+ logmsg(WHO,111,ERROR,"unable to write to users/recipients.tmp");
+}
+
+char inbuf[1024];
+buffer b;
+
+int fd;
+int fdtemp;
+
+struct cdb_make cdb;
+stralloc line = {0};
+stralloc key = {0};
+int match;
+
+int main()
+{
+ umask(033);
+ if (chdir(auto_qmail) == -1)
+ logmsg(WHO,110,ERROR,B("unable to chdir to: ",auto_qmail));
+
+ fd = open_read("users/recipients");
+ if (fd == -1) die_read();
+
+ buffer_init(&b,read,fd,inbuf,sizeof(inbuf));
+
+ fdtemp = open_trunc("users/recipients.tmp");
+ if (fdtemp == -1) die_write();
+
+ if (cdb_make_start(&cdb,fdtemp) == -1) die_write();
+
+ for (;;) {
+ stralloc_copys(&key,":");
+ if (getln(&b,&line,&match,'\n') != 0) die_read();
+ while (line.len) {
+ if (line.s[line.len - 1] == ' ') { --line.len; continue; }
+ if (line.s[line.len - 1] == '\n') { --line.len; continue; }
+ if (line.s[line.len - 1] == '\t') { --line.len; continue; }
+ if (line.s[0] != '#' && stralloc_cat(&key,&line)) {
+ case_lowerb(key.s,key.len);
+ if (cdb_make_add(&cdb,key.s,key.len,"",0) == -1)
+ die_write();
+ }
+ break;
+ }
+ 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("users/recipients.tmp","users/recipients.cdb") == -1)
+ logmsg(WHO,111,ERROR,"unable to move users/recipients.tmp to users/recipients.cdb");
+
+ _exit(0);
+}