#include <string.h>
#include <unistd.h>
+#include "subafn.h"
#include "subrou.h"
#include "unidns.h"
/*
\f
*/
-/************************************************/
-/* */
-/* Procedure to query DNS information */
-/* */
-/************************************************/
+/********************************************************/
+/* */
+/* Procedure to query DNS information */
+/* */
+/********************************************************/
static int myquery(const char *dname,int class,int type,
unsigned char *answer, int anslen)
/*
\f
*/
-/************************************************/
-/* */
-/* Procedure to extract text information */
-/* from DNS record. */
-/* SMTP client status. */
-/* */
-/************************************************/
+/********************************************************/
+/* */
+/* Procedure to extract text information */
+/* from DNS record. */
+/* */
+/********************************************************/
static char **extracting(RSPTYP *rsp,int rsplen,char *request,char *field)
{
/*
^L
*/
-/************************************************/
-/* */
-/* Procedure to extract a domain TXT */
-/* If the domain doesn't exist or domain */
-/* do not have a TXT, a void pointer is */
-/* returned. */
-/* */
-/* */
-/************************************************/
+/********************************************************/
+/* */
+/* Procedure to extract a domain TXT */
+/* If the domain doesn't exist or domain */
+/* do not have a TXT, a void pointer is */
+/* returned. */
+/* */
+/********************************************************/
static char **gettxt(char *domain,int ttype,char *field)
{
/*
^L
*/
-/************************************************/
-/* */
-/* Procedure to extract a hostname SPF */
-/* Search first for an SPF record, if not */
-/* implemented search for a TXT record */
-/* If the domain doesn't exist or domain */
-/* do not have a TXT or SPF, a void pointer*/
-/* is returned. */
-/* */
-/* */
-/************************************************/
+/********************************************************/
+/* */
+/* Procedure to extract a hostname SPF */
+/* Search first for an SPF record, if not */
+/* implemented search for a TXT record */
+/* If the domain doesn't exist or domain */
+/* do not have a TXT or SPF, a void pointer */
+/* is returned. */
+/* */
+/********************************************************/
static char **getspf(char *domain)
{
/*
^L
*/
-/************************************************/
-/* */
-/* Procedure to extract a hostname TXT */
-/* If the domain doesn't exist or domain */
+/********************************************************/
+/* */
+/* Procedure to return check if an IP is part of */
+/* spf allowed IP */
+/* */
+/********************************************************/
+static SPFENU is_peerip_ok(char *peerip,char *spfrec)
+
+{
+SPFENU spf;
+AFNTYP *afnnum;
+int phase;
+_Bool proceed;
+
+phase=0;
+proceed=true;
+while (proceed==true) {
+ switch (phase) {
+ case 0 : //Converting the IP number
+ afnnum=afn_getipnum(peerip);
+ break;
+ default : //SAFE Guard
+ proceed=false;
+ break;
+ }
+ phase++;
+ }
+spf=spf_neutral;
+return spf;
+}
/*
^L
*/
/* Procedure to return the SPF status string value */
/* */
/********************************************************/
-PUBLIC const char *dns_spfascii(SPFENU spf)
+PUBLIC const char *dns_spfASCII(SPFENU spf)
{
+#define OPEP "unidns.c:dns_spfASCII"
static char *spfascii[]=
{
"spf_pass",
"spf_neutral",
"spf_timeout",
"spf_missing",
+ "spf_permerr",
"spf_unknown"
};
case spf_neutral :
case spf_timeout :
case spf_missing :
+ case spf_permerr :
case spf_unknown :
ascii=spfascii[spf];
break;
default :
+ (void) rou_alert(0,"%s, Unexpected '%d' SPF status (Bug!)",OPEP,spf);
break;
}
return ascii;
+
+#undef OPEP
}
/*
^L
int phase;
_Bool proceed;
-spf=spf_unknown;
+spf=spf_permerr;
list=(char **)0;
phase=0;
proceed=true;
}
break;
case 1 : //get the spf LIST related to SPF
- if ((list=getspf(domain))==(char **)0) {
- phase=999;
- }
+ if ((list=getspf(domain))==(char **)0)
+ phase=999; //trouble trouble
break;
- case 2 : //gett the spf LIST related to SPF
- if (list!=(char **)0) {
- char **ptr;
-
- ptr=list;
- while (*ptr!=(char *)0) {
- (void) printf("JMPDBG <%s>\n",*ptr);
- ptr++;
- }
- list=(char **)rou_freelist((void **)list,(freehandler_t)rou_freestr);
+ case 2 : //check if we have onlye ONE SPF entry
+ if (rou_nbrlist((void **)list)>1) {
+ (void) rou_alert(0,"%s more than 1 SPF record for domain <%s>",
+ OPEP,domain);
+ phase=999; //trouble trouble
}
break;
+ case 3 : //gett the spf LIST related to SPF
+ spf=is_peerip_ok(peerip,list[0]);
+ list=(char **)rou_freelist((void **)list,(freehandler_t)rou_freestr);
+ break;
default : //SAFE guard
proceed=false;
break;
status=0;
if (mode!=modopen) {
(void) rou_modesubrou(mode);
+ (void) afn_modesubafn(mode);
switch ((int)mode) {
case true :
break;