s/qmail 4.3.17
Next generation secure email transport
Loading...
Searching...
No Matches
spf.h
Go to the documentation of this file.
1#ifndef SPF_H
2#define SPF_H
3
4#include "stralloc.h"
5#include "ipalloc.h"
6
7/* (Internal) Processing codes */
8
9#define SPF_INIT -1
10#define SPF_EXT -2 /* x */
11#define SPF_ME -3
12#define SPF_EXHAUST -4
13#define SPF_LOOP -5
14#define SPF_MULTIRR -6
15#define SPF_LOCAL -7
16#define SPF_ERROR -8
17#define SPF_NOMEM -9
18#define SPF_SYNTAX -10 /* Setup problem */
19
20/* (External) Resulting codes */
21
22#define SPF_OK 0 /* + Pass */
23#define SPF_NONE 1 /* o None */
24#define SPF_UNKNOWN 2 /* u Unknown method */
25#define SPF_NEUTRAL 3 /* ? Neutral */
26#define SPF_SOFTFAIL 4 /* ~ Softfail */
27#define SPF_FAIL 5 /* - Not Permitted */
28#define SPF_DNSSOFT 6 /* d From DNS; not used */
29
30#define LOOKUP_LIMIT 10
31
32/* spfinfo: S=remoteip|O=mailfrom|C=identity/domain|H=helo|M(echanism)=query|D=redirect|I=domain|P=problem|R:result */
33
34#define SPF_DEFEXP "See http://%{d}/why.html?sender=%{s}&ip=%{i}&receiver=%{r}"
35
36extern int flagip6;
37extern stralloc spfmf;
38extern stralloc spfhelo;
39extern stralloc spfinfo;
40extern stralloc spfdomain;
41extern stralloc dnsname;
42extern stralloc spflocalrules;
43extern stralloc spfrecord;
44extern stralloc expdomain;
45extern stralloc spfexplain;
46extern stralloc spfexpmsg;
47
48/* this table and macro came from wget more or less */
49/* and was in turn stolen by me++ from libspf as is :) */
50
51const static unsigned char urlchr_table[256] =
52{
53 1, 1, 1, 1, 1, 1, 1, 1, /* NUL SOH STX ETX EOT ENQ ACK BEL */
54 1, 1, 1, 1, 1, 1, 1, 1, /* BS HT LF VT FF CR SO SI */
55 1, 1, 1, 1, 1, 1, 1, 1, /* DLE DC1 DC2 DC3 DC4 NAK SYN ETB */
56 1, 1, 1, 1, 1, 1, 1, 1, /* CAN EM SUB ESC FS GS RS US */
57 1, 0, 1, 1, 0, 1, 1, 0, /* SP ! " # $ % & ' */
58 0, 0, 0, 1, 0, 0, 0, 1, /* ( ) * + , - . / */
59 0, 0, 0, 0, 0, 0, 0, 0, /* 0 1 2 3 4 5 6 7 */
60 0, 0, 1, 1, 1, 1, 1, 1, /* 8 9 : ; < = > ? */
61 1, 0, 0, 0, 0, 0, 0, 0, /* @ A B C D E F G */
62 0, 0, 0, 0, 0, 0, 0, 0, /* H I J K L M N O */
63 0, 0, 0, 0, 0, 0, 0, 0, /* P Q R S T U V W */
64 0, 0, 0, 1, 1, 1, 1, 0, /* X Y Z [ \ ] ^ _ */
65 1, 0, 0, 0, 0, 0, 0, 0, /* ` a b c d e f g */
66 0, 0, 0, 0, 0, 0, 0, 0, /* h i j k l m n o */
67 0, 0, 0, 0, 0, 0, 0, 0, /* p q r s t u v w */
68 0, 0, 0, 1, 1, 1, 1, 1, /* x y z { | } ~ DEL */
69
70 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
71 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
72 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
73 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
74
75 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
76 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
77 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
78 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
79};
80
81#define WSPACE(x) ((x) == ' ' || (x) == '\t' || (x) == '\r' || (x) == '\n')
82#define NXTOK(b, p, a) do { (b) = (p); \
83 while((p) < (a)->len && !WSPACE((a)->s[(p)])) ++(p); \
84 while((p) < (a)->len && WSPACE((a)->s[(p)])) (a)->s[(p)++] = 0; \
85 } while(0)
86
87/* spfdnsip.c */
88
89int match_ip4(unsigned char [4],int,char [4]);
90int match_ip6(unsigned char [16],int,char [16]);
91int get_prefix(char *);
92int spf_records(stralloc *,stralloc *);
93int spf_include(char *,char *);
94int spf_a(char *,char *);
95int spf_mx(char *,char *);
96int spf_ptr(char *,char *);
97int spf_ip4(char *,char *);
98int spf_ip6(char *,char *);
99int spf_exists(char *,char *);
100
101/* spf.c */
102
103int spf_query(const char *,const char *,const char *,const char *,const int);
104int spf_lookup(stralloc *);
105int spf_mechanism(char *,char *,char *,char *);
106int spf_parse(stralloc *,char *,char *);
107int spf_macros(stralloc *,char *,char *);
108int spf_info(char *,const char *);
109
110#endif
111
stralloc spfhelo
Definition: spf.c:26
stralloc spfexpmsg
Definition: spf.c:30
stralloc expdomain
Definition: spf.c:31
int spf_ip6(char *, char *)
spf_ip6 (ip6; ip6:fqdn; ip6:fqdn/56) compares AAAA records for SPF info and client host
Definition: spfdnsip.c:368
int spf_a(char *, char *)
spf_a (a; a:fqdns; a:fqdns/56) compares A + AAAA records for SPF info and client host
Definition: spfdnsip.c:145
int spf_lookup(stralloc *)
spf_lookup calles the actual (recursive) SPF DNS query
Definition: spf.c:158
stralloc spfexplain
Definition: spf.c:23
int match_ip4(unsigned char[4], int, char[4])
match_ip compares IPv4/IPv6 addreses up to prefix length
Definition: spfdnsip.c:30
int get_prefix(char *)
get_prefix return integer value of prefix length
Definition: spfdnsip.c:65
int spf_exists(char *, char *)
spf_exists (exists; exists:fqdn) simply looks for a A records only for SPF info and client host
Definition: spfdnsip.c:391
int match_ip6(unsigned char[16], int, char[16])
Definition: spfdnsip.c:44
int spf_mx(char *, char *)
spf_mx (mx; mx:domain; mx:domain/24) compares MX records for SPF info and client host
Definition: spfdnsip.c:192
stralloc spfinfo
Definition: spf.c:17
int spf_parse(stralloc *, char *, char *)
spf_parse parses the substructure of the SPF record and calls spf_macros
Definition: spf.c:461
int spf_ip4(char *, char *)
spf_ip4 (ip4; ip4:fqdn; ip4:fqdn/24) compares A records for SPF info and client host
Definition: spfdnsip.c:345
int spf_mechanism(char *, char *, char *, char *)
spf_mechanism evaluates the provided mechanisms in the SPF record [RFC7208 Sec 5.]
Definition: spf.c:391
int spf_ptr(char *, char *)
spf_ptr (ptr; ptr:fqdn) compares PTR records from SPF info and client host
Definition: spfdnsip.c:235
stralloc spfmf
Definition: spf.c:25
int spf_include(char *, char *)
spf_include deals with recursive evaluation of SPF record [RFC7208 Sec. 5.2]
Definition: spf.c:431
int spf_macros(stralloc *, char *, char *)
spf_macros deals with macros in the SPF specificaton [RFC7208 Sec. 7ff]
Definition: spf.c:502
stralloc spfdomain
stralloc spflocalrules
Definition: spf.c:22
int spf_query(const char *, const char *, const char *, const char *, const int)
spf_query prepares the SPF TXT record query
Definition: spf.c:58
int spf_records(stralloc *, stralloc *)
spf_records get TXT records for domain and extract SPF information
Definition: spfdnsip.c:93
stralloc spfrecord
Definition: spf.c:18
int flagip6
Definition: spf.c:32
stralloc dnsname
Definition: spf.c:27
int spf_info(char *, const char *)
Definition: spf.c:640