try=0;
afnnum=afn_getipnum(peerip);
spf=spf_getstatus(&try,domain,afnnum);
-if (strcmp(spfstr,spf_spfASCII(spf))!=0)
+if (strcmp(spfstr,spf_spfASCII(spf))!=0) {
+ (void) rou_alert(2,"expected SPF status=<%s>, got<%s>",
+ spfstr,spf_spfASCII(spf));
status=false;
+ }
afnnum=afn_freeipnum(afnnum);
return status;
}
typedef enum { //mechanism definition
mch_all, //"all"
- mch_a, //'a'
+ mch_addr, //'a'
mch_exists, //"existe"
mch_include, //"include"
mch_ip4, //"ip4"
static void dbgspf(int dbg,char *proc,char *domain,AFNTYP *afnnum,char *seq,SPFENU status)
{
-if (debug>-dbg) {
+if (debug>=dbg) {
(void) rou_alert(dbg,"Origin=\"%s\"\n"
"\tCurrent SPF Value <%s>\n"
"\tPeer IP=[%s]\n"
*/
/********************************************************/
/* */
+/* Procedure to check the SPF A value againt the */
+/* current afnnum. */
+/* return true if successful. */
+/* */
+/********************************************************/
+static _Bool checkaddr(char *domain,AFNTYP *afnnum,char *addr)
+
+{
+#define OPEP "gesspf.c:checkaddr"
+
+_Bool found;
+int cidr;
+char *addrdom;
+int phase;
+_Bool proceed;
+
+found=false;
+cidr=128;
+addrdom=domain;
+phase=0;
+proceed=true;
+while (proceed==true) {
+ switch (phase) {
+ case 0 : //getting the list of MX
+ if (addrdom!=(char *)0) { //always
+ char *ptr;
+
+ if ((ptr=strchr(addrdom,'/'))!=(char *)0) {
+ *ptr='\000';
+ cidr=atoi(ptr+1);
+ }
+ if ((ptr=strchr(addrdom,':'))!=(char *)0) {
+ *ptr='\000';
+ addrdom=ptr+1;
+ }
+ }
+ break;
+ case 1 : //getting the list of MX for mxdomain
+ (void) printf("JMPDBG, checkaddr got <%s> cidr='%d'",addrdom,cidr);
+ break;
+ default : //SAFE guard
+ proceed=false;
+ break;
+ }
+ phase++;
+ }
+return found;
+
+#undef OPEP
+}
+/*
+\f
+*/
+/********************************************************/
+/* */
/* Procedure to check the SPF MX values againt the */
/* current afnnum. */
/* return true if successful. */
OPEP,mxlist[i]->mxname);
continue;
}
+ (void) printf("JMPDBG addr=<%s> peer=<%s> cidr='%d'\n",
+ addrnum->strnumip,afnnum->strnumip,cidr);
switch (afn_cmpipnum(addrnum,afnnum,cidr)) {
case false : //not found
break;
case mch_all : //usually last in sequence
spf=locspf;
break;
+ case mch_addr : //check IP addr
+ if (checkaddr(domain,afnnum,seq)==true)
+ spf=locspf;
+ break;
case mch_mx : //This is a MX refrence
if (checkmx(domain,afnnum,seq)==true)
spf=locspf;
case mch_ip6 : //This is IPV6 number
if (checkip(domain,afnnum,seq+1)==true)
spf=locspf;
- (void) dbgspf(2,"checkip",domain,afnnum,seq+1,spf);
+ (void) dbgspf(5,"checkip",domain,afnnum,seq+1,spf);
break;
case mch_include : //include sub domain
if (seq[0]==':') {
if (spf!=spf_neutral)
break; //Found a pass status, breaking loop
}
- (void) dbgspf(2,"is_peerip_ok",domain,afnnum,ref,spf);
+ (void) dbgspf(5,"is_peerip_ok",domain,afnnum,ref,spf);
}
break;
default : //SAFE Guard
}
if (ptr!=(u_char *)0)
(void) memmove(afnnum->ip,ptr,afnnum->afnmask/8);
+ afnnum->strnumip=afn_getstrip(afnnum);
}
return afnnum;
}
break;
case 1 : /*lets say ip format ok */
afnnum=(AFNTYP *)calloc(1,sizeof(AFNTYP));
- afnnum->strnumip=strdup(cleanipstr);
afnnum->afntype=AF_INET;
afnnum->afnmask=32;
if (strchr(cleanipstr,':')==(char *)0)
cleanipstr=ZIPV4;
break;
case 4 : //lets convert it
- if (inet_pton(afnnum->afntype,cleanipstr,afnnum->ip)<=0)
+ if (inet_pton(afnnum->afntype,cleanipstr,afnnum->ip)<=0) {
afnnum=afn_freeipnum(afnnum);
+ phase=999; //no need to go further
+ }
+ break;
+ case 5 : //lets convert it
+ afnnum->strnumip=afn_getstrip(afnnum);
break;
default : /*SAFE guard */
proceed=false;
return afnnum;
#undef ZIPV4
+#undef OPEP
+}
+/*
+^L
+*/
+/********************************************************/
+/* */
+/* Procedure to normalize IP number format */
+/* Memory allocated need to be freed later */
+/* on. */
+/* */
+/* */
+/********************************************************/
+char *afn_getstrip(AFNTYP *afnnum)
+
+{
+#define OPEP "subafn.c:afn_getstrip"
+
+char *ipnorm;
+char buffer[300];
+
+ipnorm=(char *)0;
+(void) strcpy(buffer,"");
+if (afnnum!=(AFNTYP *)0) {
+ switch (afnnum->afntype) {
+ case AF_INET :
+ (void) snprintf(buffer,sizeof(buffer),"%03d.%03d.%03d.%03d",
+ afnnum->ip[0],afnnum->ip[1],
+ afnnum->ip[2],afnnum->ip[3]);
+ break;
+ case AF_INET6 :
+ (void) snprintf(buffer,sizeof(buffer),"%02x%02x:%02x%02x:%02x%02x:%02x%02x:"
+ "%02x%02x:%02x%02x:%02x%02x:%02x%02x",
+ afnnum->ip[0],afnnum->ip[1],
+ afnnum->ip[2],afnnum->ip[3],
+ afnnum->ip[4],afnnum->ip[5],
+ afnnum->ip[6],afnnum->ip[7],
+ afnnum->ip[8],afnnum->ip[9],
+ afnnum->ip[10],afnnum->ip[11],
+ afnnum->ip[12],afnnum->ip[13],
+ afnnum->ip[14],afnnum->ip[15]);
+ break;
+ default :
+ (void) fprintf(stderr,"%s, unable to fin IP type (bug?)",OPEP);
+ }
+ }
+if (strlen(buffer)>0)
+ ipnorm=strdup(buffer);
+return ipnorm;
+
#undef OPEP
}
/*
//IP number
extern char *afn_stripnum(AFNTYP *afnnum);
+//procedure to extract a dynamic string with the
+//clean IP number from a AFNTYP struct.
+extern char *afn_getstrip(AFNTYP *afnnum);
+
//procedure to convert a addrinfo struct to an
//IP number in AFNTYP structure.
extern AFNTYP *afn_getaddrinfo(struct addrinfo *rp);
//version definition
#define VERSION "0.4.2"
-#define RELEASE "22"
+#define RELEASE "23"
//Public variables
PUBLIC int debug=0; //debug level