1 /*************************************************
2 * Exim - an Internet mail transport agent *
3 *************************************************/
6 * Exim - SPF lookup module using libspf2
7 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9 * Copyright (c) 2005 Chris Webb, Arachsys Internet Services Ltd
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * Copyright (c) The Exim Maintainers 2016
21 #ifndef EXPERIMENTAL_SPF
22 static void dummy(int x
);
23 static void dummy2(int x
) { dummy(x
-1); }
24 static void dummy(int x
) { dummy2(x
-1); }
27 #include "lf_functions.h"
32 #include <spf2/spf_dns_resolv.h>
33 #include <spf2/spf_dns_cache.h>
36 spf_open(uschar
*filename
, uschar
**errmsg
)
38 SPF_server_t
*spf_server
= NULL
;
39 spf_server
= SPF_server_new(SPF_DNS_CACHE
, 0);
40 if (spf_server
== NULL
) {
41 *errmsg
= US
"SPF_server_new() failed";
44 return (void *) spf_server
;
48 spf_close(void *handle
)
50 SPF_server_t
*spf_server
= handle
;
51 if (spf_server
) SPF_server_free(spf_server
);
55 spf_find(void *handle
, uschar
*filename
, const uschar
*keystring
, int key_len
,
56 uschar
**result
, uschar
**errmsg
, uint
*do_cache
)
58 SPF_server_t
*spf_server
= handle
;
59 SPF_request_t
*spf_request
= NULL
;
60 SPF_response_t
*spf_response
= NULL
;
62 spf_request
= SPF_request_new(spf_server
);
63 if (spf_request
== NULL
) {
64 *errmsg
= US
"SPF_request_new() failed";
68 if (SPF_request_set_ipv4_str(spf_request
, CS filename
)) {
69 *errmsg
= string_sprintf("invalid IP address '%s'", filename
);
72 if (SPF_request_set_env_from(spf_request
, CS keystring
)) {
73 *errmsg
= string_sprintf("invalid envelope from address '%s'", keystring
);
77 SPF_request_query_mailfrom(spf_request
, &spf_response
);
78 *result
= string_copy(US
SPF_strresult(SPF_response_result(spf_response
)));
79 SPF_response_free(spf_response
);
80 SPF_request_free(spf_request
);
85 /*************************************************
86 * Version reporting entry point *
87 *************************************************/
89 /* See local README for interface description. */
91 #include "../version.h"
94 spf_version_report(FILE *f
)
97 fprintf(f
, "Library version: SPF: Exim version %s\n", EXIM_VERSION_STR
);
102 static lookup_info _lookup_info
= {
103 US
"spf", /* lookup name */
104 0, /* not absfile, not query style */
105 spf_open
, /* open function */
106 NULL
, /* no check function */
107 spf_find
, /* find function */
108 spf_close
, /* close function */
109 NULL
, /* no tidy function */
110 NULL
, /* no quoting function */
111 spf_version_report
/* version reporting */
115 #define spf_lookup_module_info _lookup_module_info
118 static lookup_info
*_lookup_list
[] = { &_lookup_info
};
119 lookup_module_info spf_lookup_module_info
= { LOOKUP_MODULE_INFO_MAGIC
, _lookup_list
, 1 };
121 #endif /* EXPERIMENTAL_SPF */