TLS: Whine to log on client config of SNI under too-old OpenSSL version
[exim.git] / src / src / lookups / spf.c
CommitLineData
92f1b170
TK
1/*************************************************
2* Exim - an Internet mail transport agent *
3*************************************************/
4
5/*
6 * Exim - SPF lookup module using libspf2
7 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8 *
9 * Copyright (c) 2005 Chris Webb, Arachsys Internet Services Ltd
10 *
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.
15 *
16 */
17
18#include "../exim.h"
19
20#ifndef EXPERIMENTAL_SPF
e1d15f5e
JH
21static void dummy(int x);
22static void dummy2(int x) { dummy(x-1); }
23static void dummy(int x) { dummy2(x-1); }
92f1b170
TK
24#else
25
26#include "lf_functions.h"
56dda33c
TK
27#ifndef HAVE_NS_TYPE
28#define HAVE_NS_TYPE
29#endif
92f1b170
TK
30#include <spf2/spf.h>
31#include <spf2/spf_dns_resolv.h>
32#include <spf2/spf_dns_cache.h>
33
14b3c5bc
JH
34static void *
35spf_open(uschar *filename, uschar **errmsg)
36{
92f1b170
TK
37 SPF_server_t *spf_server = NULL;
38 spf_server = SPF_server_new(SPF_DNS_CACHE, 0);
39 if (spf_server == NULL) {
40 *errmsg = US"SPF_server_new() failed";
41 return NULL;
42 }
43 return (void *) spf_server;
44}
45
14b3c5bc
JH
46static void
47spf_close(void *handle)
48{
92f1b170
TK
49 SPF_server_t *spf_server = handle;
50 if (spf_server) SPF_server_free(spf_server);
51}
52
14b3c5bc
JH
53static int
54spf_find(void *handle, uschar *filename, uschar *keystring, int key_len,
55 uschar **result, uschar **errmsg, uint *do_cache)
56{
92f1b170
TK
57 SPF_server_t *spf_server = handle;
58 SPF_request_t *spf_request = NULL;
59 SPF_response_t *spf_response = NULL;
60
61 spf_request = SPF_request_new(spf_server);
62 if (spf_request == NULL) {
63 *errmsg = US"SPF_request_new() failed";
64 return FAIL;
65 }
66
ab75a2db 67 if (SPF_request_set_ipv4_str(spf_request, CS filename)) {
92f1b170
TK
68 *errmsg = string_sprintf("invalid IP address '%s'", filename);
69 return FAIL;
70 }
ab75a2db 71 if (SPF_request_set_env_from(spf_request, CS keystring)) {
92f1b170
TK
72 *errmsg = string_sprintf("invalid envelope from address '%s'", keystring);
73 return FAIL;
74 }
75
76 SPF_request_query_mailfrom(spf_request, &spf_response);
77 *result = string_copy(US SPF_strresult(SPF_response_result(spf_response)));
78 SPF_response_free(spf_response);
79 SPF_request_free(spf_request);
80 return OK;
81}
82
6545de78
PP
83
84/*************************************************
85* Version reporting entry point *
86*************************************************/
87
88/* See local README for interface description. */
89
90#include "../version.h"
91
92void
93spf_version_report(FILE *f)
94{
95#ifdef DYNLOOKUP
96fprintf(f, "Library version: SPF: Exim version %s\n", EXIM_VERSION_STR);
97#endif
98}
99
100
e6d225ae
DW
101static lookup_info _lookup_info = {
102 US"spf", /* lookup name */
103 0, /* not absfile, not query style */
104 spf_open, /* open function */
105 NULL, /* no check function */
106 spf_find, /* find function */
107 spf_close, /* close function */
108 NULL, /* no tidy function */
6545de78
PP
109 NULL, /* no quoting function */
110 spf_version_report /* version reporting */
e6d225ae
DW
111};
112
113#ifdef DYNLOOKUP
114#define spf_lookup_module_info _lookup_module_info
115#endif
116
117static lookup_info *_lookup_list[] = { &_lookup_info };
118lookup_module_info spf_lookup_module_info = { LOOKUP_MODULE_INFO_MAGIC, _lookup_list, 1 };
119
92f1b170 120#endif /* EXPERIMENTAL_SPF */