| 
    Qsmtp
    0.30dev
    
   | 
 
functions to query and parse SPF entries More...
#include <qsmtpd/antispam.h>#include <fmt.h>#include <libowfatconn.h>#include <match.h>#include <mime_chars.h>#include <netio.h>#include <qsmtpd/qsmtpd.h>#include <sstring.h>#include <arpa/inet.h>#include <assert.h>#include <ctype.h>#include <errno.h>#include <netinet/in.h>#include <string.h>#include <time.h>#include <unistd.h>Macros | |
| #define | _GNU_SOURCE /* for strcasestr() */ | 
| #define | WRITEl(fd, s, l) if ( (rc = write((fd), (s), (l))) < 0 ) return rc | 
| #define | WRITE(fd, s) WRITEl((fd), (s), strlen(s)) | 
| #define | APPEND(addlen, addstr) | 
| #define | PARSEERR do { free(*res); return -SPF_PERMERROR; } while (0) | 
| #define | APPEND(addlen, addstr) | 
Enumerations | |
| enum | spf_makro_expansion {  SPF_MAKRO_NONE, SPF_MAKRO_PERCENT, SPF_MAKRO_BRACE, SPF_MAKRO_LETTER, SPF_MAKRO_TRANSFORMER, SPF_MAKRO_DELIMITER }  | 
Functions | |
| int | spfreceived (int fd, const int spf) | 
| static int | spf_makroparam (const char *token, int *num, int *r, int *delim) | 
| static int | urlencode (const char *token, char **result) | 
| URL-encode a given string.  More... | |
| static int | spf_appendmakro (char **res, unsigned int *l, const char *const s, const unsigned int sl, int num, const int r, const int delim) | 
| static int | validate_domain (char ***domainlist) | 
| static int | spf_makroletter (const char *p, const char *domain, int ex, char **res, unsigned int *l) | 
| int | spf_makro (const char *token, const char *domain, int ex, char **result) | 
| static int | spf_domainspec (const char *domain, const char *token, char **domainspec, int *ip4cidr, int *ip6cidr) | 
| parse the domainspec  More... | |
| static int | may_have_domainspec (const char *token) | 
| check if a domainspec is present  More... | |
| static int | spfmx (const char *domain, const char *token) | 
| static int | spfa (const char *domain, const char *token) | 
| static int | spfexists (const char *domain, const char *token) | 
| static int | spfptr (const char *domain, const char *token) | 
| static int | spfip4 (const char *domain) | 
| static int | spfip6 (const char *domain) | 
| static int | txtlookup (char **txt, const char *domain) | 
| lookup TXT record taking SPF specialities into account  More... | |
| static size_t | match_mechanism (const char *token, const char *mechanism, const char *delimiters) | 
| check if the token matches the given mechanism  More... | |
| static size_t | spf_modifier_name (const char *token) | 
| static void | record_bad_token (const char *token) | 
| static const char * | find_modifier (const char *s, const char *mod) | 
| find the given modifier in the given string  More... | |
| static int | spflookup (const char *domain, unsigned int *queries) | 
| int | check_host (const char *domain) | 
Variables | |
| static const char | spf_delimiters [] = ".-+,/_=" | 
functions to query and parse SPF entries
| #define APPEND | ( | addlen, | |
| addstr | |||
| ) | 
| #define APPEND | ( | addlen, | |
| addstr | |||
| ) | 
| int check_host | ( | const char * | domain | ) | 
look up SPF records for domain
This works a like the check_host in the SPF draft but takes two arguments less. The remote ip and the full sender address can be taken directly from xmitstat.
| domain | no idea what this might be for ;) | 
      
  | 
  static | 
find the given modifier in the given string
| s | the string to search | 
| mod | the modifier to search | 
| NULL | modifier was not found | 
      
  | 
  static | 
check if the token matches the given mechanism
| token | current token to match | 
| mechanism | the mechanism string to match | 
| delimiters | the delimiters that may be present after the token | 
| 0 | mechanism did not match | 
      
  | 
  static | 
check if a domainspec is present
| token | the token to check | 
| 0 | no domainspec present | 
| 1 | domainspec is present | 
| -SPF_PERMERROR | invalid characters detected | 
This does not check the domainspec itself, it only checks if one is given.
      
  | 
  static | 
write the bad token to the SPF explanation record
| token | the current token string | 
      
  | 
  static | 
append a makro content to the result
| res | result string | 
| l | current length of res | 
| s | the raw string to appended, does not need to be terminated by '\0' | 
| sl | strlen(s), must not be 0 | 
| num | DIGIT | 
| r | Bit 1: reverse of not; Bit 2: use URL encoding | 
| delim | bit mask of delimiters | 
      
  | 
  static | 
parse the domainspec
| domain | the current domain string | 
| token | pointer to the string after the token | 
| domainspec | here the expanded domain string is stored (memory will be malloced) | 
| ip4cidr | the length of the IPv4 net (parsed if present in token, -1 if none given) | 
| ip6cidr | same for IPv6 net length | 
| -1 | error (ENOMEM) | 
| SPF_PERMERROR | domainspec is syntactically invalid | 
| 0 | everything is fine, domainspec is set | 
| int spf_makro | ( | const char * | token, | 
| const char * | domain, | ||
| int | ex, | ||
| char ** | result | ||
| ) | 
expand a SPF makro
| token | the token to parse | 
| domain | the current domain string | 
| ex | if this is an exp string | 
| result | the resulting string is stored here | 
| 0 | makro is valid, result is set | 
| -1 | internal error (ENOMEM) | 
| SPF_PERMERROR | syntax error | 
not static, is called from targets/testspf.c
      
  | 
  static | 
expand a SPF makro letter
| p | the token to parse | 
| domain | the current domain string | 
| ex | if this is an exp string | 
| res | the resulting string is stored here | 
| l | offset into res | 
      
  | 
  static | 
parse the options in an SPF macro
| token | token to parse | 
| num | DIGIT | 
| r | if reverse is given | 
| delim | bitmask of delimiters | 
      
  | 
  static | 
check if the given token is a valid SPF modifier-name
| token | the token to parse | 
| 0 | the given token is no valid modifier-name | 
      
  | 
  static | 
look up SPF records for domain
| domain | no idea what this might be for | 
| queries | number of DNS queries done | 
| int spfreceived | ( | int | fd, | 
| const int | spf | ||
| ) | 
print "Received-SPF:" to message header
| fd | file descriptor of message body | 
| spf | SPF status of mail transaction | 
      
  | 
  static | 
lookup TXT record taking SPF specialities into account
| txt | result pointer | 
| domain | domain token to look up | 
This will take two SPF specific contraints into account:
      
  | 
  static | 
URL-encode a given string.
| token | the token to encode | 
| result | storage of the result | 
| 0 | the string was recoded | 
| 1 | the string does not need to be recoded | 
| -1 | memory allocation error | 
      
  | 
  static | 
build a list of validated domain names for the connected host
| domainlist | where to store the array | 
If this functions returns 0 all lookups were successfully, but no validated domain names were found.
 1.8.10