summaryrefslogtreecommitdiff
path: root/rcpthosts.c
diff options
context:
space:
mode:
authorJohn Denker <jsd@av8n.com>2012-06-01 18:58:45 -0700
committerJohn Denker <jsd@av8n.com>2012-06-01 18:58:45 -0700
commitb732a73bc773789894466b0e5320b2f1fe42c7e9 (patch)
tree385358983f064a1f10a5080b33a3ba13010886db /rcpthosts.c
parent634d365a03cb0581a062cd3cf4db9ae69f1cde26 (diff)
original, as downloaded from http://www.qmail.org/netqmail-1.06.tar.gz
Diffstat (limited to 'rcpthosts.c')
-rw-r--r--rcpthosts.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/rcpthosts.c b/rcpthosts.c
new file mode 100644
index 0000000..1bc3018
--- /dev/null
+++ b/rcpthosts.c
@@ -0,0 +1,60 @@
+#include "cdb.h"
+#include "byte.h"
+#include "open.h"
+#include "error.h"
+#include "control.h"
+#include "constmap.h"
+#include "stralloc.h"
+#include "rcpthosts.h"
+
+static int flagrh = 0;
+static stralloc rh = {0};
+static struct constmap maprh;
+static int fdmrh;
+
+int rcpthosts_init()
+{
+ flagrh = control_readfile(&rh,"control/rcpthosts",0);
+ if (flagrh != 1) return flagrh;
+ if (!constmap_init(&maprh,rh.s,rh.len,0)) return flagrh = -1;
+ fdmrh = open_read("control/morercpthosts.cdb");
+ if (fdmrh == -1) if (errno != error_noent) return flagrh = -1;
+ return 0;
+}
+
+static stralloc host = {0};
+
+int rcpthosts(buf,len)
+char *buf;
+int len;
+{
+ int j;
+
+ if (flagrh != 1) return 1;
+
+ j = byte_rchr(buf,len,'@');
+ if (j >= len) return 1; /* presumably envnoathost is acceptable */
+
+ ++j; buf += j; len -= j;
+
+ if (!stralloc_copyb(&host,buf,len)) return -1;
+ buf = host.s;
+ case_lowerb(buf,len);
+
+ for (j = 0;j < len;++j)
+ if (!j || (buf[j] == '.'))
+ if (constmap(&maprh,buf + j,len - j)) return 1;
+
+ if (fdmrh != -1) {
+ uint32 dlen;
+ int r;
+
+ for (j = 0;j < len;++j)
+ if (!j || (buf[j] == '.')) {
+ r = cdb_seek(fdmrh,buf + j,len - j,&dlen);
+ if (r) return r;
+ }
+ }
+
+ return 0;
+}