Back to index

courier  0.68.2
testspf.c
Go to the documentation of this file.
00001 /*
00002 ** Copyright 2004 Double Precision, Inc.
00003 ** See COPYING for distribution information.
00004 */
00005 
00006 #include      "config.h"
00007 #include      "rfc1035.h"
00008 #include      "spf.h"
00009 #include      <stdio.h>
00010 #include      <stdlib.h>
00011 #include      <string.h>
00012 
00013 
00014 static struct testsuite_s {
00015        const char *mailfrom;
00016        const char *tcpremoteip;
00017        const char *tcpremotehost;
00018        const char *helodomain;
00019        const char *mydomain;
00020 } testsuite[]={
00021        {"spf1.email-scan.com","192.168.1.10","spf1.email-scan.com","spf1","example.com"},
00022        {"spf2.email-scan.com","192.168.1.10","spf1.email-scan.com","spf1","example.com"},
00023        {"spf3.email-scan.com","192.168.1.10","spf1.email-scan.com","spf1","example.com"},
00024        {"spf3.email-scan.com","191.168.2.10","spf1.email-scan.com","spf3.test","example.com"},
00025        {"spf3.email-scan.com","1234:5678::9ABC","spf1.email-scan.com","spf1","example.com"},
00026        {"spf4.email-scan.com","192.168.2.10","spf1.email-scan.com","10-1-168-192","example.com"},
00027        {"spf5.email-scan.com","::ffff:192.168.1.0","spf5.email-scan.com","helo","example.com"},
00028        {"spf5.email-scan.com","::ffff:192.168.1.1","spf5.email-scan.com","helo","example.com"},
00029        {"spf6.email-scan.com","::ffff:192.168.1.0","spf5.email-scan.com","helo","example.com"},
00030        {"spf6.email-scan.com","::ffff:192.168.1.1","spf5.email-scan.com","helo","example.com"},
00031        {"spf7.email-scan.com","::ffff:192.168.1.1","spf5.email-scan.com","helo","example.com"},
00032        {"spf7.email-scan.com","::ffff:192.168.2.1","spf5.email-scan.com","helo","example.com"},
00033        {"spf7.email-scan.com","::ffff:192.168.1.255","spf5.email-scan.com","helo","example.com"},
00034        {"spf8.email-scan.com","::ffff:192.168.1.1","spf5.email-scan.com","helo","example.com"},
00035        {"spf8.email-scan.com","::ffff:192.168.2.1","spf5.email-scan.com","helo","example.com"},
00036        {"spf8.email-scan.com","::ffff:192.168.1.255","spf5.email-scan.com","helo","example.com"},
00037        {"spf9.email-scan.com","::ffff:192.168.1.130","spf5.email-scan.com","helo","example.com"},
00038        {"spf9.email-scan.com","::ffff:192.168.1.129","spf5.email-scan.com","helo","example.com"},
00039        {"spf9.email-scan.com","::ffff:192.168.1.10","spf5.email-scan.com","helo","example.com"},
00040        {"spf10.email-scan.com","::ffff:192.168.1.10","spf10.email-scan.com","helo","example.com"},
00041        {"spf10.email-scan.com","::ffff:192.168.1.50","spf10.email-scan.com","helo","example.com"},
00042        {"spf11.email-scan.com","::ffff:192.168.0.1","spf10.email-scan.com","helo","example.com"},
00043        {"spf11.email-scan.com","::ffff:192.168.0.2","spf10.email-scan.com","helo","example.com"},
00044        {"spf12.email-scan.com","::ffff:192.168.0.1","spf10.email-scan.com","helo","example.com"},
00045        {"spf12.email-scan.com","::ffff:192.168.1.1","spf10.email-scan.com","helo","example.com"},
00046        {"spf13.email-scan.com","::ffff:192.168.1.1","spf10.email-scan.com","spf1","example.com"},
00047        {"spf13.email-scan.com","::ffff:192.168.1.1","spf10.email-scan.com","spf50","example.com"},
00048        {"spf14.email-scan.com","::ffff:192.168.2.0","spf10.email-scan.com","helo","example.com"},
00049        {"spf14.email-scan.com","::ffff:192.168.2.1","spf10.email-scan.com","helo","example.com"},
00050        {"spf14.email-scan.com","::ffff:192.168.2.1","spf10.email-scan.com","spf11","example.com"},
00051        {"spf14.email-scan.com","::ffff:192.168.0.1","spf10.email-scan.com","spf11","example.com"},
00052        {"spf15.email-scan.com","::ffff:192.168.0.1","spf10.email-scan.com","spf11","example.com"}
00053 };
00054 
00055 static int testspf(const char *mailfrom,
00056                  const char *tcpremoteip,
00057                  const char *tcpremotehost,
00058                  const char *helodomain,
00059                  const char *mydomain)
00060 {
00061        char buf[256];
00062 
00063        switch (rfc1035_spf_lookup(mailfrom, tcpremoteip, tcpremotehost,
00064                                helodomain, mydomain, buf, sizeof(buf))) {
00065        case SPF_NONE:
00066               printf("none\n");
00067               break;
00068        case SPF_NEUTRAL:
00069               printf("neutral\n");
00070               break;
00071        case SPF_PASS:
00072               printf("pass\n");
00073               break;
00074        case SPF_FAIL:
00075               printf("fail: %s\n", buf);
00076               break;
00077        case SPF_SOFTFAIL:
00078               printf("softfail\n");
00079               break;
00080        case SPF_ERROR:
00081               printf("error\n");
00082               break;
00083        default:
00084               printf("unknown\n");
00085        }
00086        return 0;
00087 }
00088 
00089 int main(int argc, char **argv)
00090 {
00091        if (argc == 2 && strncmp(argv[1], "-test=", 6) == 0)
00092        {
00093               int loop_cnt=atoi(argv[1]+6);
00094               int i;
00095 
00096               for (i=0;i<loop_cnt;i++)
00097               {
00098                      int j;
00099 
00100                      for (j=0; j<sizeof(testsuite)/sizeof(testsuite[0]);
00101                           j++)
00102                             testspf(testsuite[j].mailfrom,
00103                                    testsuite[j].tcpremoteip,
00104                                    testsuite[j].tcpremotehost,
00105                                    testsuite[j].helodomain,
00106                                    testsuite[j].mydomain);
00107               }
00108               return 0;
00109        }
00110 
00111        if (argc < 6)
00112        {
00113               printf("Usage: %s mailfrom remoteip remotehost helo me\n",
00114                      argv[0]);
00115               exit(1);
00116        }
00117 
00118        return testspf(argv[1], argv[2], argv[3], argv[4], argv[5]);
00119 }
00120