ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libspf/docs/API/doxygen/html/main_8c-source.html
Revision: 1.1
Committed: Tue Nov 13 00:51:28 2007 UTC (18 years, 10 months ago) by root
Content type: text/html
Branch: MAIN
CVS Tags: HEAD
Log Message:
initial import of libspf-1.0.0-p5 from freebsd ports

File Contents

# User Rev Content
1 root 1.1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2     <html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
3     <title>libSPF v1.0: main.c Source File</title>
4     <link href="doxygen.css" rel="stylesheet" type="text/css">
5     </head><body>
6     <!-- Generated by Doxygen 1.3.8 -->
7     <div class="qindex"> <form class="search" action="search.php" method="get">
8     <a class="qindex" href="main.html">Main&nbsp;Page</a> | <a class="qindex" href="annotated.html">Data&nbsp;Structures</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="functions.html">Data&nbsp;Fields</a> | <a class="qindex" href="globals.html">Globals</a> | <span class="search"><u>S</u>earch&nbsp;for&nbsp;<input class="search" type="text" name="query" value="" size="20" accesskey="s"/></span></form></div>
9     <h1>main.c</h1><a href="main_8c.html">Go to the documentation of this file.</a><pre class="fragment"><div>00001 <span class="comment">/* libspf - Sender Policy Framework library</span>
10     00002 <span class="comment">*</span>
11     00003 <span class="comment">* ANSI C implementation of spf-draft-200405.txt</span>
12     00004 <span class="comment">*</span>
13     00005 <span class="comment">* Author: James Couzens &lt;jcouzens@codeshare.ca&gt;</span>
14     00006 <span class="comment">* Author: Sean Comeau &lt;scomeau@obscurity.org&gt;</span>
15     00007 <span class="comment">*</span>
16     00008 <span class="comment">* File: spf.c</span>
17     00009 <span class="comment">* Desc: Main library functionality</span>
18     00010 <span class="comment">*</span>
19     00011 <span class="comment">* License:</span>
20     00012 <span class="comment">*</span>
21     00013 <span class="comment">* The libspf Software License, Version 1.0</span>
22     00014 <span class="comment">*</span>
23     00015 <span class="comment">* Copyright (c) 2004 James Couzens &amp; Sean Comeau All rights</span>
24     00016 <span class="comment">* reserved.</span>
25     00017 <span class="comment">*</span>
26     00018 <span class="comment">* Redistribution and use in source and binary forms, with or without</span>
27     00019 <span class="comment">* modification, are permitted provided that the following conditions</span>
28     00020 <span class="comment">* are met:</span>
29     00021 <span class="comment">*</span>
30     00022 <span class="comment">* 1. Redistributions of source code must retain the above copyright</span>
31     00023 <span class="comment">* notice, this list of conditions and the following disclaimer.</span>
32     00024 <span class="comment">*</span>
33     00025 <span class="comment">* 2. Redistributions in binary form must reproduce the above copyright</span>
34     00026 <span class="comment">* notice, this list of conditions and the following disclaimer in</span>
35     00027 <span class="comment">* the documentation and/or other materials provided with the</span>
36     00028 <span class="comment">* distribution.</span>
37     00029 <span class="comment">*</span>
38     00030 <span class="comment">* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED</span>
39     00031 <span class="comment">* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES</span>
40     00032 <span class="comment">* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE</span>
41     00033 <span class="comment">* DISCLAIMED. IN NO EVENT SHALL THE AUTHORS MAKING USE OF THIS LICESEN</span>
42     00034 <span class="comment">* OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,</span>
43     00035 <span class="comment">* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT</span>
44     00036 <span class="comment">* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF</span>
45     00037 <span class="comment">* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND</span>
46     00038 <span class="comment">* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,</span>
47     00039 <span class="comment">* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT</span>
48     00040 <span class="comment">* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF</span>
49     00041 <span class="comment">* SUCH DAMAGE.</span>
50     00042 <span class="comment">*</span>
51     00043 <span class="comment">*/</span>
52     00044
53     00045 <span class="preprocessor">#ifdef _WITH_PTHREADS</span>
54     00046 <span class="preprocessor"></span><span class="preprocessor">#include &lt;pthread.h&gt;</span> <span class="comment">/* pthread_mutex */</span>
55     00047 <span class="preprocessor">#endif </span><span class="comment">/* _WITH_PTHREDS */</span>
56     00048
57     00049 <span class="preprocessor">#include "../../config.h"</span> <span class="comment">/* autoconf */</span>
58     00050 <span class="preprocessor">#include "<a class="code" href="main_8h.html">main.h</a>"</span> <span class="comment">/* our header */</span>
59     00051 <span class="preprocessor">#include "<a class="code" href="util_8h.html">util.h</a>"</span> <span class="comment">/* Utility functions */</span>
60     00052 <span class="preprocessor">#include "<a class="code" href="dns_8h.html">dns.h</a>"</span> <span class="comment">/* DNS functions */</span>
61     00053 <span class="preprocessor">#include "<a class="code" href="macro_8h.html">macro.h</a>"</span> <span class="comment">/* MACRO parsing functions */</span>
62     00054
63     00055 <span class="preprocessor">#undef VERSION </span><span class="comment">/* autoconf */</span>
64     00056
65     <a name="l00057"></a><a class="code" href="spf_8h.html#a47">00057</a> <a class="code" href="structspf__config__s.html">spf_config_t</a> <a class="code" href="main_8c.html#a0">confg</a>; <span class="comment">/* global config struct */</span>
66     00058
67     <a name="l00059"></a><a class="code" href="main_8c.html#a1">00059</a> <span class="keywordtype">int</span> <a class="code" href="dns_8h.html#a6">h_errno</a>; <span class="comment">/* error handling */</span>
68     00060
69     00061 <span class="preprocessor">#ifdef _WITH_PTHREADS</span>
70     00062 <span class="preprocessor"></span><span class="comment">/* mutex for _DNS_gethostbyname_r wrapper */</span>
71     00063 <span class="keyword">extern</span> pthread_mutex_t <a class="code" href="dns_8c.html#a0">dns_mutex</a>;
72     00064 <span class="preprocessor">#endif </span><span class="comment">/* _WITH_PTHREADS */</span>
73     00065
74     00066 <span class="keyword">static</span> <a class="code" href="spf_8h.html#a35">SPF_BOOL</a> <a class="code" href="main_8c.html#a2">_SPF_clear_holdbufs</a>(<a class="code" href="structpeer__info__s.html">peer_info_t</a> *);
75     00067
76     00068 <span class="comment">/* SPF_init</span>
77     00069 <span class="comment">*</span>
78     00070 <span class="comment">* Author: James Couzens &lt;jcouzens@codeshare.ca&gt;</span>
79     00071 <span class="comment">*</span>
80     00072 <span class="comment">* Date: 12/25/03</span>
81     00073 <span class="comment">*</span>
82     00074 <span class="comment">* Desc:</span>
83     00075 <span class="comment">* Applies config options and returns allocated memory to a peer_info_t</span>
84     00076 <span class="comment">* structure. Malloc returns NULL on a failure, and as such this function exits</span>
85     00077 <span class="comment">* with NULL upon failure to allocate memory which there by results in a</span>
86     00078 <span class="comment">* complete failure of the entire library.</span>
87     00079 <span class="comment">*</span>
88     00080 <span class="comment">*/</span>
89     <a name="l00081"></a><a class="code" href="spf_8h.html#a77">00081</a> <a class="code" href="structpeer__info__s.html">peer_info_t</a> *<a class="code" href="spf_8h.html#a77">SPF_init</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> *local, <span class="keyword">const</span> <span class="keywordtype">char</span> *rip, <span class="keyword">const</span> <span class="keywordtype">char</span> *expl,
90     00082 <span class="keyword">const</span> <span class="keywordtype">char</span> *tf, <span class="keyword">const</span> <span class="keywordtype">char</span> *guess, u_int32_t use_trust, u_int32_t use_guess)
91     00083 {
92     00084 time_t curtime; <span class="comment">/* time */</span>
93     00085
94     00086 <span class="keywordtype">char</span> *cur_utc_time; <span class="comment">/* time */</span>
95     00087
96     00088 <a class="code" href="structpeer__info__s.html">peer_info_t</a> *p = NULL; <span class="comment">/* return structure buffer */</span>
97     00089
98     00090 <span class="comment">/*</span>
99     00091 <span class="comment"> * spf_result struct including header texts. This structure is used</span>
100     00092 <span class="comment"> * during message header generation and has intended future purposes. </span>
101     00093 <span class="comment"> * Each string has associated with it its actual size which is used </span>
102     00094 <span class="comment"> * to provide some measure of protection against overflowing the strings</span>
103     00095 <span class="comment"> * as they are (currently) statically defined in util.h</span>
104     00096 <span class="comment"> */</span>
105     00097 <span class="keyword">static</span> <a class="code" href="structspf__result__t.html">spf_result_t</a> spf_result[] =
106     00098 {{<a class="code" href="util_8h.html#a3">SIZEOF</a>(<a class="code" href="spf_8h.html#a24">HR_PASS</a>), <a class="code" href="spf_8h.html#a24">HR_PASS</a>, <a class="code" href="spf_8h.html#a88a51">SPF_PASS</a>, <a class="code" href="util_8h.html#a3">SIZEOF</a>(<a class="code" href="main_8h.html#a17">HDR_PASS</a>), <a class="code" href="main_8h.html#a17">HDR_PASS</a>, <span class="charliteral">'+'</span> },
107     00099 {<a class="code" href="util_8h.html#a3">SIZEOF</a>(<a class="code" href="spf_8h.html#a25">HR_NONE</a>), <a class="code" href="spf_8h.html#a25">HR_NONE</a>, <a class="code" href="spf_8h.html#a88a52">SPF_NONE</a>, <a class="code" href="util_8h.html#a3">SIZEOF</a>(<a class="code" href="main_8h.html#a18">HDR_NONE</a>), <a class="code" href="main_8h.html#a18">HDR_NONE</a>, <span class="charliteral">'\0'</span>},
108     00100 {<a class="code" href="util_8h.html#a3">SIZEOF</a>(<a class="code" href="spf_8h.html#a26">HR_S_FAIL</a>), <a class="code" href="spf_8h.html#a26">HR_S_FAIL</a>, <a class="code" href="spf_8h.html#a88a53">SPF_S_FAIL</a>, <a class="code" href="util_8h.html#a3">SIZEOF</a>(<a class="code" href="main_8h.html#a19">HDR_S_FAIL</a>), <a class="code" href="main_8h.html#a19">HDR_S_FAIL</a>, <span class="charliteral">'~'</span> },
109     00101 {<a class="code" href="util_8h.html#a3">SIZEOF</a>(<a class="code" href="spf_8h.html#a27">HR_H_FAIL</a>), <a class="code" href="spf_8h.html#a27">HR_H_FAIL</a>, <a class="code" href="spf_8h.html#a88a54">SPF_H_FAIL</a>, <a class="code" href="util_8h.html#a3">SIZEOF</a>(<a class="code" href="main_8h.html#a20">HDR_H_FAIL</a>), <a class="code" href="main_8h.html#a20">HDR_H_FAIL</a>, <span class="charliteral">'-'</span> },
110     00102 {<a class="code" href="util_8h.html#a3">SIZEOF</a>(<a class="code" href="spf_8h.html#a28">HR_ERROR</a>), <a class="code" href="spf_8h.html#a28">HR_ERROR</a>, <a class="code" href="spf_8h.html#a88a55">SPF_ERROR</a>, <a class="code" href="util_8h.html#a3">SIZEOF</a>(<a class="code" href="main_8h.html#a21">HDR_ERROR</a>), <a class="code" href="main_8h.html#a21">HDR_ERROR</a>, <span class="charliteral">'\0'</span>},
111     00103 {<a class="code" href="util_8h.html#a3">SIZEOF</a>(<a class="code" href="spf_8h.html#a29">HR_NEUTRAL</a>), <a class="code" href="spf_8h.html#a29">HR_NEUTRAL</a>, <a class="code" href="spf_8h.html#a88a56">SPF_NEUTRAL</a>, <a class="code" href="util_8h.html#a3">SIZEOF</a>(<a class="code" href="main_8h.html#a22">HDR_NEUTRAL</a>), <a class="code" href="main_8h.html#a22">HDR_NEUTRAL</a>, <span class="charliteral">'?'</span> },
112     00104 {<a class="code" href="util_8h.html#a3">SIZEOF</a>(<a class="code" href="spf_8h.html#a30">HR_UNKNOWN</a>), <a class="code" href="spf_8h.html#a30">HR_UNKNOWN</a>, <a class="code" href="spf_8h.html#a88a57">SPF_UNKNOWN</a>, <a class="code" href="util_8h.html#a3">SIZEOF</a>(<a class="code" href="main_8h.html#a23">HDR_UNKNOWN</a>), <a class="code" href="main_8h.html#a23">HDR_UNKNOWN</a>, <span class="charliteral">'\0'</span>},
113     00105 {<a class="code" href="util_8h.html#a3">SIZEOF</a>(<a class="code" href="spf_8h.html#a31">HR_UNMECH</a>), <a class="code" href="spf_8h.html#a31">HR_UNMECH</a>, <a class="code" href="spf_8h.html#a88a58">SPF_UNMECH</a>, <a class="code" href="util_8h.html#a3">SIZEOF</a>(<a class="code" href="main_8h.html#a24">HDR_UNMECH</a>), <a class="code" href="main_8h.html#a24">HDR_UNMECH</a>, <span class="charliteral">'\0'</span>}};
114     00106
115     00107 <span class="comment">/*</span>
116     00108 <span class="comment"> * This structure here is the heart and soul or effectively the 'context' </span>
117     00109 <span class="comment"> * of libSPF. This structure is passed back and forth between nearly </span>
118     00110 <span class="comment"> * every function which will operate on it in one way or another.</span>
119     00111 <span class="comment"> */</span>
120     00112 p = <a class="code" href="util_8h.html#a4">xmalloc</a>(<a class="code" href="util_8h.html#a3">SIZEOF</a>(<a class="code" href="structpeer__info__s.html">peer_info_t</a>));
121     00113
122     00114 p-&gt;<a class="code" href="structpeer__info__s.html#o25">spf_result</a> = spf_result;
123     00115
124     00116
125     00117 <span class="comment">/*</span>
126     00118 <span class="comment"> * Set the SPF query recursion level to zero. This counter is</span>
127     00119 <span class="comment"> * incremeneted to a maximum of SPF_MAX_RECURSE (default value of</span>
128     00120 <span class="comment"> * that macro is 20) to provide a limit of recursiveness. Not only does</span>
129     00121 <span class="comment"> * it astound me to see people creating infinite loops unintentionally</span>
130     00122 <span class="comment"> * through the use of the 'include' and 'redirect' facilities within SPF,</span>
131     00123 <span class="comment"> * but there is also the greater than average chance that a skriptkiddie</span>
132     00124 <span class="comment"> * or some other individual with malicious intentions would use a lack of</span>
133     00125 <span class="comment"> * such a level (or a poorly set one, you REALLY should not raise this</span>
134     00126 <span class="comment"> * above 20) to faciliate a very effective DoS or dDoS attack against your</span>
135     00127 <span class="comment"> * server using SPF checks.</span>
136     00128 <span class="comment"> */</span>
137     00129 p-&gt;<a class="code" href="structpeer__info__s.html#o27">spf_rlevel</a> = 0;
138     00130
139     00131 <span class="comment">/*</span>
140     00132 <span class="comment"> * RFC2821 (pre-DATA) related variables</span>
141     00133 <span class="comment"> *</span>
142     00134 <span class="comment"> */</span>
143     00135
144     00136 p-&gt;<a class="code" href="structpeer__info__s.html#o8">helo</a> = NULL;
145     00137 p-&gt;<a class="code" href="structpeer__info__s.html#o9">ehlo</a> = NULL;
146     00138 p-&gt;<a class="code" href="structpeer__info__s.html#o10">from</a> = NULL;
147     00139
148     00140 <span class="keywordflow">if</span> (local != NULL &amp;&amp; (*local &amp;&amp; *(local + 1)))
149     00141 {
150     00142 p-&gt;<a class="code" href="structpeer__info__s.html#o16">mta_hname</a> = <a class="code" href="util_8h.html#a8">xstrndup</a>(local, <a class="code" href="spf_8h.html#a7">SPF_MAX_LOCAL_PART</a>);
151     00143 p-&gt;<a class="code" href="structpeer__info__s.html#o18">r_vhname</a> = <a class="code" href="util_8h.html#a8">xstrndup</a>(local, <a class="code" href="spf_8h.html#a7">SPF_MAX_LOCAL_PART</a>);
152     00144 }
153     00145 <span class="keywordflow">else</span>
154     00146 {
155     00147 p-&gt;<a class="code" href="structpeer__info__s.html#o16">mta_hname</a> = NULL;
156     00148 p-&gt;<a class="code" href="structpeer__info__s.html#o18">r_vhname</a> = NULL;
157     00149 <a class="code" href="util_8h.html#a13">xepprintf</a>(<span class="stringliteral">"Warning: Invalid local-part detected (DSN or NULL?)\n"</span>);
158     00150 }
159     00151
160     00152 <span class="comment">/* don't change this, this is for Solaris which can't print NULL strings */</span>
161     00153 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"Called with: (%s) (%s) (%s) (%s) (%s) %u:%u\n"</span>,
162     00154 local ? local : <span class="stringliteral">"NULL"</span>,
163     00155 rip ? rip : <span class="stringliteral">"NULL"</span>,
164     00156 expl ? expl : <span class="stringliteral">"NULL"</span>,
165     00157 tf ? tf : <span class="stringliteral">"NULL"</span>,
166     00158 guess ? guess : <span class="stringliteral">"NULL"</span>,
167     00159 use_trust, use_guess);
168     00160
169     00161 <span class="comment">/*</span>
170     00162 <span class="comment"> * Set the default SPF version level to zero. This is important because</span>
171     00163 <span class="comment"> * the lack of a valid SPF version here is relied upon within SPF_parse_policy</span>
172     00164 <span class="comment"> * to determine an appropriate exit enforcing the RFC requirement that each</span>
173     00165 <span class="comment"> * SPF record publish a valid version within their SPF query.</span>
174     00166 <span class="comment"> */</span>
175     00167 p-&gt;<a class="code" href="structpeer__info__s.html#o5">spf_ver</a> = 0;
176     00168
177     00169 <span class="comment">/* </span>
178     00170 <span class="comment"> * "Trusted Forwarder" enabled? This is also what you could use if you wanted to</span>
179     00171 <span class="comment"> * operate an 'in-house' whitelist for your server. For more information about</span>
180     00172 <span class="comment"> * the officla "Trusted Forwarder" service visit http://trustedforwarder.org </span>
181     00173 <span class="comment"> */</span>
182     00174 <span class="keywordflow">if</span> (use_trust == <a class="code" href="spf_8h.html#a87a50">SPF_TRUE</a>)
183     00175 {
184     00176 p-&gt;<a class="code" href="structpeer__info__s.html#o3">use_trust</a> = <a class="code" href="spf_8h.html#a87a50">SPF_TRUE</a>;
185     00177 }
186     00178 <span class="keywordflow">else</span>
187     00179 {
188     00180 p-&gt;<a class="code" href="structpeer__info__s.html#o3">use_trust</a> = <a class="code" href="spf_8h.html#a87a49">SPF_FALSE</a>;
189     00181 }
190     00182
191     00183 <span class="comment">/*</span>
192     00184 <span class="comment"> * "Best Guess" enabled? This is a great way to provide a "generic" SPF check</span>
193     00185 <span class="comment"> * against domains who do not publish SPF either through ignorance or refusal</span>
194     00186 <span class="comment"> * to do so. The default best guess is defined in spf.h and is comprised of</span>
195     00187 <span class="comment"> * SPF syntax facilitating 'a', 'mx', and 'ptr' checks against the connected</span>
196     00188 <span class="comment"> * host when enabled in an attempt to validate them</span>
197     00189 <span class="comment"> */</span>
198     00190 <span class="keywordflow">if</span> (use_guess == <a class="code" href="spf_8h.html#a87a50">SPF_TRUE</a>)
199     00191 {
200     00192 p-&gt;<a class="code" href="structpeer__info__s.html#o4">use_guess</a> = <a class="code" href="spf_8h.html#a87a50">SPF_TRUE</a>;
201     00193 }
202     00194 <span class="keywordflow">else</span>
203     00195 {
204     00196 p-&gt;<a class="code" href="structpeer__info__s.html#o4">use_guess</a> = <a class="code" href="spf_8h.html#a87a49">SPF_FALSE</a>;
205     00197 }
206     00198
207     00199 p-&gt;<a class="code" href="structpeer__info__s.html#o0">ALL</a> = <a class="code" href="spf_8h.html#a87a49">SPF_FALSE</a>;
208     00200 p-&gt;<a class="code" href="structpeer__info__s.html#o6">p</a> = NULL;
209     00201
210     00202 <span class="comment">/*</span>
211     00203 <span class="comment"> * SPF Explanation. This can be optionally pre-pended to the RFC2822</span>
212     00204 <span class="comment"> * message body as a means of informing a client when rejecting their</span>
213     00205 <span class="comment"> * message for a failure to appropriate pass a desired SPF level.</span>
214     00206 <span class="comment"> */</span>
215     00207 <span class="keywordflow">if</span> (expl != NULL &amp;&amp; (*expl &amp;&amp; *(expl + 1)))
216     00208 {
217     00209 p-&gt;<a class="code" href="structpeer__info__s.html#o11">explain</a> = <a class="code" href="util_8h.html#a8">xstrndup</a>(expl, (strlen(expl) + 1));
218     00210 }
219     00211 <span class="keywordflow">else</span>
220     00212 {
221     00213 p-&gt;<a class="code" href="structpeer__info__s.html#o11">explain</a> = NULL;
222     00214 }
223     00215
224     00216 <span class="keywordflow">if</span> (guess != NULL &amp;&amp; (*guess &amp;&amp; *(guess + 1)))
225     00217 {
226     00218 p-&gt;<a class="code" href="structpeer__info__s.html#o12">guess</a> = <a class="code" href="util_8h.html#a8">xstrndup</a>(guess, (strlen(guess) + 1));
227     00219 }
228     00220 <span class="keywordflow">else</span>
229     00221 {
230     00222 p-&gt;<a class="code" href="structpeer__info__s.html#o12">guess</a> = <a class="code" href="util_8h.html#a8">xstrndup</a>(<a class="code" href="spf_8h.html#a33">SPF_GUESS</a>, (<a class="code" href="util_8h.html#a3">SIZEOF</a>(<a class="code" href="spf_8h.html#a33">SPF_GUESS</a>) + 1));
231     00223 }
232     00224
233     00225 <span class="keywordflow">if</span> ((tf != NULL) &amp;&amp; (*tf &amp;&amp; *(tf + 1)))
234     00226 {
235     00227 p-&gt;<a class="code" href="structpeer__info__s.html#o13">trusted</a> = <a class="code" href="util_8h.html#a8">xstrndup</a>(tf, (strlen(tf) + 1));
236     00228 }
237     00229 <span class="keywordflow">else</span>
238     00230 {
239     00231 p-&gt;<a class="code" href="structpeer__info__s.html#o13">trusted</a> = <a class="code" href="util_8h.html#a8">xstrndup</a>(<a class="code" href="spf_8h.html#a34">SPF_TRUSTED</a>, (<a class="code" href="util_8h.html#a3">SIZEOF</a>(<a class="code" href="spf_8h.html#a34">SPF_TRUSTED</a>) + 1));
240     00232 }
241     00233
242     00234 p-&gt;<a class="code" href="structpeer__info__s.html#o14">ptr_mhost</a> = NULL; <span class="comment">/* MTA hostname */</span>
243     00235 p-&gt;<a class="code" href="structpeer__info__s.html#o15">current_domain</a> = NULL; <span class="comment">/* Current domain name (of client) */</span>
244     00236 p-&gt;<a class="code" href="structpeer__info__s.html#o19">cur_eaddr</a> = NULL; <span class="comment">/* Current email-address (of client) */</span>
245     00237
246     00238 <span class="comment">/* </span>
247     00239 <span class="comment"> * inet_pton is used to convert the IP address of the remotely connected</span>
248     00240 <span class="comment"> * client into a network address structure which will be used during</span>
249     00241 <span class="comment"> * and SPF parse to perform CIDR calculations against a variety of SPF</span>
250     00242 <span class="comment"> * mechanisms ('ip4', 'ip6', etc.). Currently hard set for IPv4.</span>
251     00243 <span class="comment"> *</span>
252     00244 <span class="comment"> * A character version of the remote peer is retained within the </span>
253     00245 <span class="comment"> * peer_info_t structure by reason that there is no sense not doign</span>
254     00246 <span class="comment"> * so since we will need to reference it in a human readable form,</span>
255     00247 <span class="comment"> * and since the MTA has already performed the labour necessary to</span>
256     00248 <span class="comment"> * get it into this form, we might as well keep it.</span>
257     00249 <span class="comment"> */</span>
258     00250 <span class="keywordflow">if</span> (((rip != NULL) &amp;&amp; (*rip &amp;&amp; *(rip + 1))) &amp;&amp; (inet_pton(AF_INET, rip,
259     00251 &amp;p-&gt;<a class="code" href="structpeer__info__s.html#o26">addr</a>) &gt;= 0))
260     00252 {
261     00253 p-&gt;<a class="code" href="structpeer__info__s.html#o17">r_ip</a> = <a class="code" href="util_8h.html#a8">xstrndup</a>(rip, <a class="code" href="spf_8h.html#a11">SPF_MAX_IP_ADDR</a>);
262     00254 }
263     00255 <span class="keywordflow">else</span>
264     00256 {
265     00257 <a class="code" href="util_8h.html#a13">xepprintf</a>(<span class="stringliteral">"Warning: Unable to execute inet_print (bad passed ipaddr?)\n"</span>);
266     00258 <a class="code" href="spf_8h.html#a78">SPF_close</a>(p);
267     00259
268     00260 <span class="keywordflow">return</span>(NULL);
269     00261 }
270     00262
271     00263 <span class="comment">/* </span>
272     00264 <span class="comment"> * 'ip_ver' is the Internet Address protocol version being used</span>
273     00265 <span class="comment"> * at any given time during an SPF parse. Whilst this is intended to </span>
274     00266 <span class="comment"> * support IPv6 at this time it is hard set to IPv4 (AF_INET)</span>
275     00267 <span class="comment"> */</span>
276     00268 snprintf(p-&gt;<a class="code" href="structpeer__info__s.html#o20">ip_ver</a>, <a class="code" href="spf_8h.html#a11">SPF_MAX_IP_ADDR</a>, <span class="stringliteral">"in-addr"</span>);
277     00269
278     00270 <span class="comment">/*</span>
279     00271 <span class="comment"> * Obtain the number of seconds since the UNIX Epoch or UTC time</span>
280     00272 <span class="comment"> * which we may optionally be used when pre-pending the Received-SPF</span>
281     00273 <span class="comment"> * header after an SPF parse</span>
282     00274 <span class="comment"> */</span>
283     00275 cur_utc_time = <a class="code" href="util_8h.html#a4">xmalloc</a>(<a class="code" href="util_8h.html#a1">SPF_MAX_DATETIME</a>);
284     00276 snprintf(cur_utc_time, <a class="code" href="util_8h.html#a1">SPF_MAX_DATETIME</a>, <span class="stringliteral">"%lu"</span>, time(&amp;curtime));
285     00277 memcpy(p-&gt;<a class="code" href="structpeer__info__s.html#o22">utc_time</a>, cur_utc_time, <a class="code" href="util_8h.html#a1">SPF_MAX_DATETIME</a>);
286     00278 <a class="code" href="util_8h.html#a6">xfree</a>(cur_utc_time);
287     00279
288     00280 <span class="comment">/*</span>
289     00281 <span class="comment"> * As per the SPF RFC, localhost shall always be considered exempt from</span>
290     00282 <span class="comment"> * any SPF checks. There is no facility to override this, nor should</span>
291     00283 <span class="comment"> * you.</span>
292     00284 <span class="comment"> */</span>
293     00285 <span class="keywordflow">if</span> ((strcmp(rip, <span class="stringliteral">"127.0.0.1"</span>) == 0) || (strcmp(rip, <span class="stringliteral">"localhost"</span>) == 0))
294     00286 {
295     00287 <a class="code" href="util_8h.html#a47">UTIL_assoc_prefix</a>(p, <a class="code" href="spf_8h.html#a88a51">SPF_PASS</a>, NULL);
296     00288 }
297     00289 <span class="keywordflow">else</span>
298     00290 {
299     00291 <a class="code" href="util_8h.html#a47">UTIL_assoc_prefix</a>(p, <a class="code" href="spf_8h.html#a88a56">SPF_NEUTRAL</a>, NULL);
300     00292 }
301     00293
302     00294 <a class="code" href="util_8h.html#a9">xprintf</a>(<span class="stringliteral">"libspf initialized succesfully. (%i bytes allocated)\n"</span>,
303     00295 <a class="code" href="util_8h.html#a3">SIZEOF</a>(<a class="code" href="structpeer__info__s.html">peer_info_t</a>));
304     00296
305     00297 <span class="keywordflow">return</span>(p);
306     00298 }
307     00299
308     00300
309     00301 <span class="comment">/* SPF_close</span>
310     00302 <span class="comment">*</span>
311     00303 <span class="comment">* Author: James Couzens &lt;jcouzens@codeshare.ca&gt;</span>
312     00304 <span class="comment">*</span>
313     00305 <span class="comment">* Date: 12/25/03</span>
314     00306 <span class="comment">*</span>
315     00307 <span class="comment">* Desc:</span>
316     00308 <span class="comment">* Free memory associated with passed peer_info_t structure.</span>
317     00309 <span class="comment">* p _MUST_ be nulled, checks in the various MTA code rely</span>
318     00310 <span class="comment">* on it to be NULL for various checks.</span>
319     00311 <span class="comment">*</span>
320     00312 <span class="comment">*/</span>
321     <a name="l00313"></a><a class="code" href="spf_8h.html#a78">00313</a> <a class="code" href="structpeer__info__s.html">peer_info_t</a> *<a class="code" href="spf_8h.html#a78">SPF_close</a>(<a class="code" href="structpeer__info__s.html">peer_info_t</a> *p)
322     00314 {
323     00315 <span class="keywordflow">if</span> (p == NULL)
324     00316 {
325     00317 <a class="code" href="util_8h.html#a13">xepprintf</a>(<span class="stringliteral">"peer structure null. Aborting!\n"</span>);
326     00318
327     00319 <span class="keywordflow">return</span>(NULL);
328     00320 }
329     00321
330     00322 <a class="code" href="util_8h.html#a6">xfree</a>(p-&gt;<a class="code" href="structpeer__info__s.html#o16">mta_hname</a>);
331     00323 <a class="code" href="util_8h.html#a6">xfree</a>(p-&gt;<a class="code" href="structpeer__info__s.html#o8">helo</a>);
332     00324 <a class="code" href="util_8h.html#a6">xfree</a>(p-&gt;<a class="code" href="structpeer__info__s.html#o10">from</a>);
333     00325 <a class="code" href="util_8h.html#a6">xfree</a>(p-&gt;<a class="code" href="structpeer__info__s.html#o15">current_domain</a>);
334     00326 <a class="code" href="util_8h.html#a6">xfree</a>(p-&gt;<a class="code" href="structpeer__info__s.html#o17">r_ip</a>);
335     00327 <a class="code" href="util_8h.html#a6">xfree</a>(p-&gt;<a class="code" href="structpeer__info__s.html#o14">ptr_mhost</a>);
336     00328 <a class="code" href="util_8h.html#a6">xfree</a>(p-&gt;<a class="code" href="structpeer__info__s.html#o19">cur_eaddr</a>);
337     00329 <a class="code" href="util_8h.html#a6">xfree</a>(p-&gt;<a class="code" href="structpeer__info__s.html#o13">trusted</a>);
338     00330 <a class="code" href="util_8h.html#a6">xfree</a>(p-&gt;<a class="code" href="structpeer__info__s.html#o12">guess</a>);
339     00331 <a class="code" href="util_8h.html#a6">xfree</a>(p-&gt;<a class="code" href="structpeer__info__s.html#o11">explain</a>);
340     00332 <a class="code" href="util_8h.html#a6">xfree</a>(p-&gt;<a class="code" href="structpeer__info__s.html#o18">r_vhname</a>);
341     00333
342     00334 <a class="code" href="util_8h.html#a6">xfree</a>(p);
343     00335 p = NULL;
344     00336
345     00337 <span class="keywordflow">return</span>(p);
346     00338 }
347     00339
348     00340
349     00341 <span class="comment">/* SPF_policy_main</span>
350     00342 <span class="comment">*</span>
351     00343 <span class="comment">* Author: James Couzens &lt;jcouzens@codeshare.ca&gt;</span>
352     00344 <span class="comment">*</span>
353     00345 <span class="comment">* Date: 12/10/03</span>
354     00346 <span class="comment">* Date: 01/24/04 by James &lt;jcouzens@codeshare.ca&gt;</span>
355     00347 <span class="comment">* Date: 05/02/04 by Teddy &lt;teddy@teddy.ch&gt;</span>
356     00348 <span class="comment">*</span>
357     00349 <span class="comment">* Desc:</span>
358     00350 <span class="comment">* This calls only the recursive version SPF_policy_main.</span>
359     00351 <span class="comment">* In earlier versions, SPF_policy_main was not able to handle CNAME</span>
360     00352 <span class="comment">*</span>
361     00353 <span class="comment">*/</span>
362     00354 <span class="comment">/*</span>
363     00355 <span class="comment">SPF_RESULT SPF_policy_main(peer_info_t *p)</span>
364     00356 <span class="comment">{</span>
365     00357 <span class="comment"> return(SPF_policy_main(p, 0));</span>
366     00358 <span class="comment">}</span>
367     00359 <span class="comment">*/</span>
368     00360
369     00361
370     00362 <span class="comment">/* SPF_policy_main</span>
371     00363 <span class="comment">*</span>
372     00364 <span class="comment">* Author: James Couzens &lt;jcouzens@codeshare.ca&gt;</span>
373     00365 <span class="comment">*</span>
374     00366 <span class="comment">* Date: 09/08/04 by James &lt;jcouzens@codeshare.ca&gt;</span>
375     00367 <span class="comment">*</span>
376     00368 <span class="comment">* Desc:</span>
377     00369 <span class="comment">* This is the primary SPF function from which effectively all underlying</span>
378     00370 <span class="comment">* operation of the library is manipulated. Passed a 'peer_info_t' structure when</span>
379     00371 <span class="comment">* properly populated DNS queries of T_TXT and T_CNAME are made to obtain and </span>
380     00372 <span class="comment">* recusrively follow SPF records through DNS up to a limit hard set through</span>
381     00373 <span class="comment">* the macro 'SPF_MAX_RECURSE'.</span>
382     00374 <span class="comment">*</span>
383     00375 <span class="comment">* As per the RFC 'include' and 'redirect' are cached until all other mechanisms</span>
384     00376 <span class="comment">* and modifiers of a particular SPF query are exhausted before being attempted</span>
385     00377 <span class="comment">* as they are the most expensive SPF operations.</span>
386     00378 <span class="comment">*</span>
387     00379 <span class="comment">* Returns 'SPF_RESULT' which describes the overall outcome of however many </span>
388     00380 <span class="comment">* actual parses may have been involved. Based on this outcome the calling</span>
389     00381 <span class="comment">* function is expected to further call SPF_build_header and SPF_get_explain,</span>
390     00382 <span class="comment">* and finally SPF_close to finalize their SPF query.</span>
391     00383 <span class="comment">*</span>
392     00384 <span class="comment">* SPF return types are often represented by single characters however not all</span>
393     00385 <span class="comment">* SPF_RESULT return types may be references this way. The characters are</span>
394     00386 <span class="comment">* as follows:</span>
395     00387 <span class="comment">*</span>
396     00388 <span class="comment">* '+' - SPF_PASS (pass)</span>
397     00389 <span class="comment">* '-' - SPF_HARD_FAIL (fail)</span>
398     00390 <span class="comment">* '~' - SPF_SOFT_FAIL (softfail)</span>
399     00391 <span class="comment">* '?' - SPF_NEUTRAL (neutral)</span>
400     00392 <span class="comment">*</span>
401     00393 <span class="comment">* These chars and default error messages related to them are all managed</span>
402     00394 <span class="comment">* through the structure spf_result_t so if you wish to modify them</span>
403     00395 <span class="comment">* you will need to seek out the various macro's that are referenced</span>
404     00396 <span class="comment">* through this structure (which is declared within the SPF_init function).</span>
405     00397 <span class="comment">*</span>
406     00398 <span class="comment">*/</span>
407     <a name="l00399"></a><a class="code" href="spf_8h.html#a79">00399</a> <a class="code" href="spf_8h.html#a36">SPF_RESULT</a> <a class="code" href="spf_8h.html#a79">SPF_policy_main</a>(<a class="code" href="structpeer__info__s.html">peer_info_t</a> *p)
408     00400 {
409     00401 <a class="code" href="spf_8h.html#a36">SPF_RESULT</a> res; <span class="comment">/* result of an SPF parse */</span>
410     00402
411     00403 <span class="keywordtype">char</span> *tmp = NULL; <span class="comment">/* temporary pointer */</span>
412     00404 <span class="keywordtype">char</span> *cname_buf = NULL; <span class="comment">/* tmp cname placeholder */</span>
413     00405 <span class="keywordtype">char</span> *include_buf = NULL; <span class="comment">/* tmp include placeholder */</span>
414     00406 <span class="keywordtype">char</span> *redirect_buf = NULL; <span class="comment">/* tmp redirect placeholder */</span>
415     00407
416     00408
417     00409 <span class="keywordflow">if</span> (p == NULL)
418     00410 {
419     00411 <a class="code" href="util_8h.html#a13">xepprintf</a>(<span class="stringliteral">"Unable to continue with a NULL peer_info_t structure!\n"</span>);
420     00412
421     00413 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a88a57">SPF_UNKNOWN</a>);
422     00414 }
423     00415
424     00416 <span class="keywordflow">if</span> (p-&gt;<a class="code" href="structpeer__info__s.html#o27">spf_rlevel</a> &gt;= <a class="code" href="main_8h.html#a8">SPF_MAX_RECURSE</a>)
425     00417 {
426     00418 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"recursion level exceeded (%u) levels; Aborting.\n"</span>,
427     00419 p-&gt;<a class="code" href="structpeer__info__s.html#o27">spf_rlevel</a>);
428     00420
429     00421 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a88a57">SPF_UNKNOWN</a>);
430     00422 }
431     00423
432     00424 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"[%i] current domain: (%s)\n"</span>, p-&gt;<a class="code" href="structpeer__info__s.html#o27">spf_rlevel</a>, p-&gt;<a class="code" href="structpeer__info__s.html#o15">current_domain</a>);
433     00425 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"[%i] include buffer: (%s)\n"</span>, p-&gt;<a class="code" href="structpeer__info__s.html#o27">spf_rlevel</a>, p-&gt;<a class="code" href="structpeer__info__s.html#o29">include_buf</a>);
434     00426 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"[%i] redirect buffer: (%s)\n"</span>, p-&gt;<a class="code" href="structpeer__info__s.html#o27">spf_rlevel</a>, p-&gt;<a class="code" href="structpeer__info__s.html#o30">redirect_buf</a>);
435     00427
436     00428 <span class="comment">/* increment recursion count */</span>
437     00429 p-&gt;<a class="code" href="structpeer__info__s.html#o27">spf_rlevel</a>++;
438     00430
439     00431 <span class="comment">/*</span>
440     00432 <span class="comment"> * ensure that our buffer placeholders are clean within our</span>
441     00433 <span class="comment"> * peer_info_t structure otherwise you will get exceptionally</span>
442     00434 <span class="comment"> * negative and unpredictable results from the rest of this </span>
443     00435 <span class="comment"> * function!</span>
444     00436 <span class="comment"> */</span>
445     00437 <a class="code" href="main_8c.html#a2">_SPF_clear_holdbufs</a>(p);
446     00438
447     00439 <span class="comment">/* fire off a peer_info_t structure for an SPF policy parse */</span>
448     00440 res = <a class="code" href="spf_8h.html#a80">SPF_policy_main_rec</a>(p);
449     00441
450     00442 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"result of SPF parse is %i\n"</span>, res);
451     00443
452     00444 <span class="comment">/* store these here for now, we'll take them back in a moment */</span>
453     00445 cname_buf = p-&gt;<a class="code" href="structpeer__info__s.html#o28">cname_buf</a>;
454     00446 include_buf = p-&gt;<a class="code" href="structpeer__info__s.html#o29">include_buf</a>;
455     00447 redirect_buf = p-&gt;<a class="code" href="structpeer__info__s.html#o30">redirect_buf</a>;
456     00448
457     00449 <span class="comment">/* play it safe */</span>
458     00450 p-&gt;<a class="code" href="structpeer__info__s.html#o28">cname_buf</a> = NULL;
459     00451 p-&gt;<a class="code" href="structpeer__info__s.html#o29">include_buf</a> = NULL;
460     00452 p-&gt;<a class="code" href="structpeer__info__s.html#o30">redirect_buf</a> = NULL;
461     00453
462     00454 <span class="keywordflow">if</span> (res != <a class="code" href="spf_8h.html#a88a51">SPF_PASS</a>)
463     00455 {
464     00456 <span class="comment">/* store this here for now, we'll take it back in a moment */</span>
465     00457 tmp = p-&gt;<a class="code" href="structpeer__info__s.html#o15">current_domain</a>;
466     00458
467     00459 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"tmp is holding the current domain: (%s)\n"</span>, tmp);
468     00460
469     00461 <span class="comment">/*</span>
470     00462 <span class="comment"> * First the CNAME is looked at, and separate from the 'include'</span>
471     00463 <span class="comment"> * and 'redirect' buffer placeholders because its not possible</span>
472     00464 <span class="comment"> * to have either 'include' or 'redirect' if you have a CNAME!</span>
473     00465 <span class="comment"> */</span>
474     00466 <span class="keywordflow">if</span> (cname_buf != NULL)
475     00467 {
476     00468 p-&gt;<a class="code" href="structpeer__info__s.html#o15">current_domain</a> = cname_buf;
477     00469
478     00470 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"Current domain: (%s); CNAME Buffer: (%s)\n"</span>,
479     00471 p-&gt;<a class="code" href="structpeer__info__s.html#o15">current_domain</a>, cname_buf);
480     00472
481     00473 res = <a class="code" href="spf_8h.html#a79">SPF_policy_main</a>(p);
482     00474 }
483     00475 <span class="keywordflow">else</span>
484     00476 {
485     00477 <span class="comment">/*</span>
486     00478 <span class="comment"> * In the event that during our original parse we happend</span>
487     00479 <span class="comment"> * upon either the 'include' or 'redirect' markers, we would</span>
488     00480 <span class="comment"> * have saved their contents in the placeholder buffer within</span>
489     00481 <span class="comment"> * the peer_info_t structure until after the entire other </span>
490     00482 <span class="comment"> * items within the SPF language have been exhausted. Once</span>
491     00483 <span class="comment"> * this has taken place we perform a brand new parse with the</span>
492     00484 <span class="comment"> * contents of either of the two buffers shouldl they have</span>
493     00485 <span class="comment"> * any data.</span>
494     00486 <span class="comment"> */</span>
495     00487 <span class="keywordflow">if</span> (include_buf != NULL)
496     00488 {
497     00489 p-&gt;<a class="code" href="structpeer__info__s.html#o15">current_domain</a> = include_buf;
498     00490
499     00491 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"current domain is now (%s) from INCLUDE\n"</span>,
500     00492 p-&gt;<a class="code" href="structpeer__info__s.html#o15">current_domain</a>);
501     00493
502     00494 res = <a class="code" href="spf_8h.html#a79">SPF_policy_main</a>(p);
503     00495
504     00496 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"result of SPF parse was %i\n"</span>, res);
505     00497
506     00498 <span class="comment">/*</span>
507     00499 <span class="comment"> * this is quick hack and should go somewhere else but I</span>
508     00500 <span class="comment"> * don't have time to do that right now. If an include</span>
509     00501 <span class="comment"> * results in SPF_NONE then the RFC states we must return</span>
510     00502 <span class="comment"> * 'unknown'</span>
511     00503 <span class="comment"> */</span>
512     00504 <span class="keywordflow">if</span> (res == <a class="code" href="spf_8h.html#a88a52">SPF_NONE</a>)
513     00505 {
514     00506 <a class="code" href="util_8h.html#a11">xpprintf</a>(<span class="stringliteral">"INCLUDE resulted in SPF_NONE, returning UNKNOWN\n"</span>);
515     00507 res = <a class="code" href="spf_8h.html#a88a57">SPF_UNKNOWN</a>;
516     00508 <a class="code" href="util_8h.html#a47">UTIL_assoc_prefix</a>(p, <a class="code" href="spf_8h.html#a88a57">SPF_UNKNOWN</a>, NULL);
517     00509 }
518     00510 }
519     00511
520     00512 <span class="comment">/*</span>
521     00513 <span class="comment"> * The 'include_buf' induced SPF parse may have resulted in</span>
522     00514 <span class="comment"> * an SPF_PASS result. In the event that it didn't we then</span>
523     00515 <span class="comment"> * examine the 'redirect_buf' and send it off if necessary</span>
524     00516 <span class="comment"> * trying again with a brand new SPF query (effectively).</span>
525     00517 <span class="comment"> */</span>
526     00518 <span class="keywordflow">if</span> ((res != <a class="code" href="spf_8h.html#a88a51">SPF_PASS</a>) &amp;&amp; (redirect_buf != NULL))
527     00519 {
528     00520 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"found a redirect buffer with valid data (%s)\n"</span>,
529     00521 redirect_buf);
530     00522
531     00523 p-&gt;<a class="code" href="structpeer__info__s.html#o15">current_domain</a> = redirect_buf;
532     00524
533     00525 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"current domain is now: (%s) from REDIRECT\n"</span>,
534     00526 p-&gt;<a class="code" href="structpeer__info__s.html#o15">current_domain</a>);
535     00527
536     00528 res = <a class="code" href="spf_8h.html#a79">SPF_policy_main</a>(p);
537     00529
538     00530 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"result of SPF parse was %i\n"</span>, res);
539     00531 }
540     00532 }
541     00533
542     00534 <span class="comment">/* reset our original domain */</span>
543     00535 p-&gt;<a class="code" href="structpeer__info__s.html#o15">current_domain</a> = tmp;
544     00536
545     00537 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"current domain is now: (%s); received back from tmp\n"</span>,
546     00538 p-&gt;<a class="code" href="structpeer__info__s.html#o15">current_domain</a>);
547     00539 }
548     00540
549     00541 <span class="comment">/* place the old values back into our peer_info_t structure */</span>
550     00542 p-&gt;<a class="code" href="structpeer__info__s.html#o28">cname_buf</a> = cname_buf;
551     00543 p-&gt;<a class="code" href="structpeer__info__s.html#o29">include_buf</a> = include_buf;
552     00544 p-&gt;<a class="code" href="structpeer__info__s.html#o30">redirect_buf</a> = redirect_buf;
553     00545
554     00546 <a class="code" href="main_8c.html#a2">_SPF_clear_holdbufs</a>(p);
555     00547
556     00548 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"leaving function; returning with value: (%i)\n"</span>, res);
557     00549
558     00550 <span class="keywordflow">return</span>(res);
559     00551 }
560     00552
561     00553
562     00554
563     00555 <span class="comment">/* SPF_policy_main</span>
564     00556 <span class="comment">*</span>
565     00557 <span class="comment">* Author: James Couzens &lt;jcouzens@codeshare.ca&gt;</span>
566     00558 <span class="comment">*</span>
567     00559 <span class="comment">* Date: 12/10/03</span>
568     00560 <span class="comment">* Date: 01/24/04 by James &lt;jcouzens@codeshare.ca&gt;</span>
569     00561 <span class="comment">* Date: 05/02/04 by Teddy &lt;teddy@teddy.ch&gt;</span>
570     00562 <span class="comment">*</span>
571     00563 <span class="comment">* Desc:</span>
572     00564 <span class="comment">* Fetches the SERVER_POLICY records from the FQDN's NS server</span>
573     00565 <span class="comment">* and returns an SPF_RESULT enumeration indicating the level of</span>
574     00566 <span class="comment">* compliance with an SPF policy (match, fail, error etc.. see spf.h)</span>
575     00567 <span class="comment">* Recursion inserted by Teddy</span>
576     00568 <span class="comment">*</span>
577     00569 <span class="comment">*/</span>
578     <a name="l00570"></a><a class="code" href="spf_8h.html#a80">00570</a> <a class="code" href="spf_8h.html#a36">SPF_RESULT</a> <a class="code" href="spf_8h.html#a80">SPF_policy_main_rec</a>(<a class="code" href="structpeer__info__s.html">peer_info_t</a> *p)
579     00571 {
580     00572 <a class="code" href="spf_8h.html#a36">SPF_RESULT</a> res = <a class="code" href="spf_8h.html#a88a56">SPF_NEUTRAL</a>; <span class="comment">/* SPF parse result */</span>
581     00573 <span class="keywordtype">char</span> *rr_data = NULL; <span class="comment">/* record */</span>
582     00574
583     00575
584     00576 <span class="keywordflow">if</span> (p == NULL)
585     00577 {
586     00578 <a class="code" href="util_8h.html#a13">xepprintf</a>(<span class="stringliteral">"Error peer structure is NULL. Aborting\n"</span>);
587     00579
588     00580 <a class="code" href="util_8h.html#a47">UTIL_assoc_prefix</a>(p, <a class="code" href="spf_8h.html#a88a55">SPF_ERROR</a>, NULL);
589     00581
590     00582 <span class="preprocessor">#ifdef _SPF_LOGFILE_STATS</span>
591     00583 <span class="preprocessor"></span> <a class="code" href="util_8h.html#a31">UTIL_log_result</a>(p);
592     00584 <span class="preprocessor">#endif </span><span class="comment">/* _SPF_LOGFILE_STATS */</span>
593     00585
594     00586
595     00587 <a class="code" href="util_8h.html#a13">xepprintf</a>(<span class="stringliteral">"leaving function; returning SPF_ERROR\n"</span>);
596     00588
597     00589 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a88a55">SPF_ERROR</a>);
598     00590 }
599     00591 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (p-&gt;<a class="code" href="structpeer__info__s.html#o26">addr</a>.s_addr &lt;= 0)
600     00592 {
601     00593 <a class="code" href="util_8h.html#a13">xepprintf</a>(<span class="stringliteral">"Error no idea who the remote peer is. Abort!\n"</span>);
602     00594
603     00595 <a class="code" href="util_8h.html#a47">UTIL_assoc_prefix</a>(p, <a class="code" href="spf_8h.html#a88a55">SPF_ERROR</a>, NULL);
604     00596
605     00597 <span class="preprocessor">#ifdef _SPF_LOGFILE_STATS</span>
606     00598 <span class="preprocessor"></span> <a class="code" href="util_8h.html#a31">UTIL_log_result</a>(p);
607     00599 <span class="preprocessor">#endif </span><span class="comment">/* _SPF_LOGFILE_STATS */</span>
608     00600
609     00601 <a class="code" href="util_8h.html#a13">xepprintf</a>(<span class="stringliteral">"leaving function; returning SPF_ERROR\n"</span>);
610     00602
611     00603 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a88a55">SPF_ERROR</a>);
612     00604 }
613     00605
614     00606 <span class="comment">/*</span>
615     00607 <span class="comment"> * As is stated in SPF_init, localhost is always exempt from SPF</span>
616     00608 <span class="comment"> * checks. A check for this was done in SPF_init and to keep</span>
617     00609 <span class="comment"> * actions being brought about by the proper functions p-&gt;RES</span>
618     00610 <span class="comment"> * would have been intentionally set to SPF_PASS and we check</span>
619     00611 <span class="comment"> * for that here.</span>
620     00612 <span class="comment"> */</span>
621     00613 <span class="keywordflow">if</span> (p-&gt;<a class="code" href="structpeer__info__s.html#o1">RES</a> == <a class="code" href="spf_8h.html#a88a51">SPF_PASS</a>)
622     00614 {
623     00615 <span class="preprocessor">#ifdef _SPF_LOGFILE_STATS</span>
624     00616 <span class="preprocessor"></span> <a class="code" href="util_8h.html#a31">UTIL_log_result</a>(p);
625     00617 <span class="preprocessor">#endif </span><span class="comment">/* _SPF_LOGFILE_STATS */</span>
626     00618
627     00619 <a class="code" href="util_8h.html#a11">xpprintf</a>(<span class="stringliteral">"localhost exempt from SPF checks; returning SPF_PASS\n"</span>);
628     00620
629     00621 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a88a51">SPF_PASS</a>);
630     00622 }
631     00623
632     00624 <span class="keywordflow">if</span> ((rr_data = <a class="code" href="dns_8h.html#a8">DNS_query</a>(p, p-&gt;<a class="code" href="structpeer__info__s.html#o15">current_domain</a>, T_TXT, NULL)) != NULL)
633     00625 {
634     00626 <a class="code" href="util_8h.html#a9">xprintf</a>(<span class="stringliteral">"DNS_query returned with answer: (%s)\n"</span>, rr_data);
635     00627
636     00628 <a class="code" href="spf_8h.html#a81">SPF_parse_policy</a>(p, rr_data);
637     00629
638     00630 <a class="code" href="util_8h.html#a6">xfree</a>(rr_data);
639     00631 }
640     00632 <span class="keywordflow">else</span> <span class="keywordflow">if</span> ((rr_data = <a class="code" href="dns_8h.html#a8">DNS_query</a>(p, p-&gt;<a class="code" href="structpeer__info__s.html#o15">current_domain</a>, T_CNAME, NULL)) != NULL)
641     00633 {
642     00634 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"domain (%s) is CNAME of (%s). Restarting SPF_policy_main."</span>,
643     00635 p-&gt;<a class="code" href="structpeer__info__s.html#o15">current_domain</a>, rr_data);
644     00636
645     00637 <span class="comment">/* store the result of the CNAME lookup in the CNAME buf */</span>
646     00638 p-&gt;<a class="code" href="structpeer__info__s.html#o28">cname_buf</a> = rr_data;
647     00639 } <span class="comment">/* if rr_data */</span>
648     00640
649     00641 <span class="comment">/*</span>
650     00642 <span class="comment"> * If either of the three placeholder buffers have anything in</span>
651     00643 <span class="comment"> * them check the peer_info_t structure for an SPF parse result</span>
652     00644 <span class="comment"> * and return it.</span>
653     00645 <span class="comment"> */</span>
654     00646 <span class="keywordflow">if</span> (p-&gt;<a class="code" href="structpeer__info__s.html#o28">cname_buf</a> || p-&gt;<a class="code" href="structpeer__info__s.html#o29">include_buf</a> || p-&gt;<a class="code" href="structpeer__info__s.html#o30">redirect_buf</a>)
655     00647 {
656     00648 <span class="keywordflow">if</span> (p-&gt;<a class="code" href="structpeer__info__s.html#o1">RES</a> != <a class="code" href="spf_8h.html#a88a51">SPF_PASS</a>)
657     00649 {
658     00650 <a class="code" href="util_8h.html#a9">xprintf</a>(<span class="stringliteral">"leaving function; returning (%i)\n"</span>, p-&gt;<a class="code" href="structpeer__info__s.html#o1">RES</a>);
659     00651
660     00652 <span class="keywordflow">return</span>(p-&gt;<a class="code" href="structpeer__info__s.html#o1">RES</a>);
661     00653 }
662     00654 }
663     00655
664     00656 <span class="comment">/*</span>
665     00657 <span class="comment"> * this is intentionally outside of the above statements so it can be</span>
666     00658 <span class="comment"> * called if the user has decided to implement best guess but has</span>
667     00659 <span class="comment"> * disabled trusted forwarder.</span>
668     00660 <span class="comment"> */</span>
669     00661 <span class="keywordflow">if</span> ((p-&gt;<a class="code" href="structpeer__info__s.html#o1">RES</a> != <a class="code" href="spf_8h.html#a88a51">SPF_PASS</a>) &amp;&amp; (p-&gt;<a class="code" href="structpeer__info__s.html#o3">use_trust</a> == <a class="code" href="spf_8h.html#a87a50">SPF_TRUE</a>))
670     00662 {
671     00663 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"Error obtaining record, trying Trusted Fwdr (%s)\n"</span>,
672     00664 p-&gt;<a class="code" href="structpeer__info__s.html#o13">trusted</a>);
673     00665
674     00666 res = <a class="code" href="spf_8h.html#a81">SPF_parse_policy</a>(p, p-&gt;<a class="code" href="structpeer__info__s.html#o13">trusted</a>);
675     00667
676     00668 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"SPF_parse_policy returned %i\n"</span>, res);
677     00669 }
678     00670
679     00671 <span class="keywordflow">if</span> ((p-&gt;<a class="code" href="structpeer__info__s.html#o1">RES</a> != <a class="code" href="spf_8h.html#a88a51">SPF_PASS</a>) &amp;&amp; (p-&gt;<a class="code" href="structpeer__info__s.html#o29">include_buf</a> || p-&gt;<a class="code" href="structpeer__info__s.html#o30">redirect_buf</a>))
680     00672 {
681     00673 <span class="keywordflow">return</span>(p-&gt;<a class="code" href="structpeer__info__s.html#o1">RES</a>);
682     00674 }
683     00675
684     00676 <span class="keywordflow">if</span> ((p-&gt;<a class="code" href="structpeer__info__s.html#o1">RES</a> != <a class="code" href="spf_8h.html#a88a51">SPF_PASS</a>) &amp;&amp; (p-&gt;<a class="code" href="structpeer__info__s.html#o4">use_guess</a> == <a class="code" href="spf_8h.html#a87a50">SPF_TRUE</a>))
685     00677 {
686     00678 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"Attempting a best guess effort as a last resort "</span>
687     00679 <span class="stringliteral">"using: (%s)\n"</span>, p-&gt;<a class="code" href="structpeer__info__s.html#o12">guess</a>);
688     00680
689     00681 res = <a class="code" href="spf_8h.html#a81">SPF_parse_policy</a>(p, p-&gt;<a class="code" href="structpeer__info__s.html#o12">guess</a>);
690     00682
691     00683 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"SPF_parse_policy returned %i\n"</span>, res);
692     00684 }
693     00685
694     00686 <span class="keywordflow">if</span> ((p-&gt;<a class="code" href="structpeer__info__s.html#o1">RES</a> != <a class="code" href="spf_8h.html#a88a51">SPF_PASS</a>) &amp;&amp; (p-&gt;<a class="code" href="structpeer__info__s.html#o29">include_buf</a> || p-&gt;<a class="code" href="structpeer__info__s.html#o30">redirect_buf</a>))
695     00687 {
696     00688 <span class="keywordflow">return</span>(p-&gt;<a class="code" href="structpeer__info__s.html#o1">RES</a>);
697     00689 }
698     00690
699     00691 <a class="code" href="util_8h.html#a9">xprintf</a>(<span class="stringliteral">"Return policy %i on mech: (%s) with outcome: (%s)\n"</span>,
700     00692 p-&gt;<a class="code" href="structpeer__info__s.html#o1">RES</a>, p-&gt;<a class="code" href="structpeer__info__s.html#o23">last_m</a>, p-&gt;<a class="code" href="structpeer__info__s.html#o7">rs</a>);
701     00693
702     00694 <span class="comment">/*</span>
703     00695 <span class="comment"> * If logging is enabled this will write to a statistics log </span>
704     00696 <span class="comment"> * at (by default) /var/log/spflog.txt where you can over time</span>
705     00697 <span class="comment"> * get a good idea of how SPF performs on your network.</span>
706     00698 <span class="comment"> *</span>
707     00699 <span class="comment"> */</span>
708     00700 <span class="preprocessor">#ifdef _SPF_LOGFILE_STATS</span>
709     00701 <span class="preprocessor"></span> <a class="code" href="util_8h.html#a31">UTIL_log_result</a>(p);
710     00702 <span class="preprocessor">#endif </span><span class="comment">/* _SPF_LOGFILE_STATS */</span>
711     00703
712     00704 <span class="keywordflow">return</span>(p-&gt;<a class="code" href="structpeer__info__s.html#o1">RES</a>);
713     00705 }
714     00706
715     00707
716     00708 <span class="comment">/* SPF_parse_policy</span>
717     00709 <span class="comment">*</span>
718     00710 <span class="comment">* Author: James Couzens &lt;jcouzens@codeshare.ca&gt;</span>
719     00711 <span class="comment">*</span>
720     00712 <span class="comment">* Date: 12/19/03</span>
721     00713 <span class="comment">*</span>
722     00714 <span class="comment">* Desc:</span>
723     00715 <span class="comment">* Parses the passed 'policy' and interprets the policies</span>
724     00716 <span class="comment">* contained within it to decide if based on various comparisons against</span>
725     00717 <span class="comment">* r_ip (remote peer's ipaddress) whether or not it meets the SPF</span>
726     00718 <span class="comment">* policy.</span>
727     00719 <span class="comment">*</span>
728     00720 <span class="comment">*/</span>
729     <a name="l00721"></a><a class="code" href="spf_8h.html#a81">00721</a> <a class="code" href="spf_8h.html#a35">SPF_BOOL</a> <a class="code" href="spf_8h.html#a81">SPF_parse_policy</a>(<a class="code" href="structpeer__info__s.html">peer_info_t</a> *p, <span class="keyword">const</span> <span class="keywordtype">char</span> *policy)
730     00722 {
731     00723 <a class="code" href="spf_8h.html#a38">SPF_MECHANISM</a> POLICY_TYPE; <span class="comment">/* SPF policy mechanism type */</span>
732     00724
733     00725 <a class="code" href="spf_8h.html#a36">SPF_RESULT</a> PREFIX_TYPE; <span class="comment">/* SPF mechanism prefix type */</span>
734     00726
735     00727 <a class="code" href="spf_8h.html#a35">SPF_BOOL</a> POLICY_MATCH; <span class="comment">/* T / F on a policy match */</span>
736     00728 <a class="code" href="spf_8h.html#a35">SPF_BOOL</a> POLICY_ERROR; <span class="comment">/* T / F for errors to return early */</span>
737     00729
738     00730 int16_t pos; <span class="comment">/* position in the policy */</span>
739     00731 int16_t s_pos; <span class="comment">/* position in a policy token */</span>
740     00732
741     00733 size_t p_len; <span class="comment">/* length of passed policy string */</span>
742     00734
743     00735 <span class="keywordtype">char</span> *copy; <span class="comment">/* storage container for passed policy */</span>
744     00736 <span class="keywordtype">char</span> *cp; <span class="comment">/* working pointer to passed policy */</span>
745     00737
746     00738 <span class="keywordtype">char</span> *token; <span class="comment">/* token pointer to piece of policy */</span>
747     00739 <span class="keywordtype">char</span> *token_ptr; <span class="comment">/* working pointer for token */</span>
748     00740
749     00741 <span class="keywordtype">char</span> *tmp_ptr; <span class="comment">/* temporary utility pointer */</span>
750     00742 <span class="keywordtype">char</span> *tmp_ptr2; <span class="comment">/* 2nd temporary utility pointer */</span>
751     00743 <span class="keywordtype">char</span> *macro; <span class="comment">/* expanded macro storage container */</span>
752     00744
753     00745 <span class="comment">/* include */</span>
754     00746 <a class="code" href="structpeer__info__s.html">peer_info_t</a> *i_p; <span class="comment">/* copy of p with replaced domain */</span>
755     00747
756     00748 <a class="code" href="structpolicy__addr__s.html">policy_addr_t</a> *policy_ip; <span class="comment">/* ip address of a policy record */</span>
757     00749
758     00750
759     00751 POLICY_MATCH = <a class="code" href="spf_8h.html#a87a49">SPF_FALSE</a>;
760     00752 POLICY_ERROR = <a class="code" href="spf_8h.html#a87a49">SPF_FALSE</a>;
761     00753 PREFIX_TYPE = <a class="code" href="spf_8h.html#a88a56">SPF_NEUTRAL</a>;
762     00754
763     00755 policy_ip = NULL;
764     00756 i_p = NULL;
765     00757 pos = 0;
766     00758 token = NULL;
767     00759 token_ptr = NULL;
768     00760 macro = NULL;
769     00761
770     00762 <span class="keywordflow">if</span> ((policy == NULL) || (p == NULL))
771     00763 {
772     00764 <a class="code" href="util_8h.html#a13">xepprintf</a>(<span class="stringliteral">"Unable to continue called with NULL structure\n"</span>);
773     00765
774     00766 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a87a49">SPF_FALSE</a>);
775     00767 }
776     00768
777     00769 <span class="keywordflow">if</span> (p-&gt;<a class="code" href="structpeer__info__s.html#o27">spf_rlevel</a> &gt;= <a class="code" href="main_8h.html#a8">SPF_MAX_RECURSE</a>)
778     00770 {
779     00771 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"recursion breach (%i levels); Terminated.\n"</span>,
780     00772 p-&gt;<a class="code" href="structpeer__info__s.html#o27">spf_rlevel</a>);
781     00773
782     00774 snprintf(p-&gt;<a class="code" href="structpeer__info__s.html#o24">error</a>, <a class="code" href="spf_8h.html#a16">SPF_MAX_ERROR</a>, <span class="stringliteral">"Recursion loop, terminated."</span>);
783     00775 <a class="code" href="util_8h.html#a47">UTIL_assoc_prefix</a>(p, <a class="code" href="spf_8h.html#a88a57">SPF_UNKNOWN</a>, NULL);
784     00776
785     00777 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a87a49">SPF_FALSE</a>);
786     00778 }
787     00779
788     00780 p_len = strlen(policy);
789     00781
790     00782 <a class="code" href="util_8h.html#a9">xprintf</a>(<span class="stringliteral">"about to parse (%s) of len: %i (%s)\n"</span>,
791     00783 policy, p_len, p-&gt;<a class="code" href="structpeer__info__s.html#o25">spf_result</a>[p-&gt;<a class="code" href="structpeer__info__s.html#o1">RES</a>].s);
792     00784
793     00785 <span class="comment">/* allocate memory and assign working pointer for policy */</span>
794     00786 cp = copy = <a class="code" href="util_8h.html#a8">xstrndup</a>(policy, (p_len + 1));
795     00787
796     00788 <span class="comment">/* loops through the entire policy string until its exhausted */</span>
797     00789 <span class="keywordflow">while</span> (*cp)
798     00790 {
799     00791 <span class="comment">/* skip white space */</span>
800     00792 <span class="keywordflow">while</span> ((*cp == <span class="charliteral">' '</span>) &amp;&amp; (*(cp + 1) == <span class="charliteral">' '</span>))
801     00793 {
802     00794 cp++;
803     00795 }
804     00796 pos = <a class="code" href="util_8h.html#a35">UTIL_index</a>(cp, <span class="charliteral">' '</span>);
805     00797
806     00798 <span class="keywordflow">if</span> (!*(cp + 1))
807     00799 {
808     00800 <a class="code" href="util_8h.html#a6">xfree</a>(copy);
809     00801 <a class="code" href="util_8h.html#a11">xpprintf</a>(<span class="stringliteral">"leaving function; nothing more to parse, returning SPF_TRUE\n"</span>);
810     00802
811     00803 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a87a50">SPF_TRUE</a>);
812     00804 }
813     00805
814     00806 token = <a class="code" href="util_8h.html#a8">xstrndup</a>(cp, (pos + 1));
815     00807 token_ptr = token;
816     00808 s_pos = 0;
817     00809
818     00810 <span class="comment">/* look for a mechanism modifier prefix */</span>
819     00811 <span class="keywordflow">if</span> (<a class="code" href="util_8h.html#a40">UTIL_is_spf_result</a>(*token_ptr) ||
820     00812 (strncmp(token_ptr, <span class="stringliteral">"default"</span>, 7) == 0))
821     00813 {
822     00814 PREFIX_TYPE = <a class="code" href="util_8h.html#a46">UTIL_get_mech_prefix</a>(p, token_ptr);
823     00815 snprintf(p-&gt;<a class="code" href="structpeer__info__s.html#o23">last_m</a>, <a class="code" href="spf_8h.html#a20">SPF_MAX_MECHANISM</a>, <span class="stringliteral">"%s"</span>, token_ptr);
824     00816
825     00817 <span class="keywordflow">if</span> (*token_ptr != <span class="charliteral">'d'</span>)
826     00818 {
827     00819 <span class="comment">/* move ahead one because a prefix was specified */</span>
828     00820 token_ptr++;
829     00821 }
830     00822 }
831     00823 <span class="keywordflow">else</span>
832     00824 {
833     00825 snprintf(p-&gt;<a class="code" href="structpeer__info__s.html#o23">last_m</a>, <a class="code" href="spf_8h.html#a20">SPF_MAX_MECHANISM</a>, <span class="stringliteral">"%s"</span>, token_ptr);
834     00826 PREFIX_TYPE = <a class="code" href="spf_8h.html#a88a51">SPF_PASS</a>;
835     00827 }
836     00828
837     00829 <span class="comment">/* figure out what sort of mechanism we're working with */</span>
838     00830 POLICY_TYPE = <a class="code" href="util_8h.html#a45">UTIL_get_policy_mech</a>(token_ptr);
839     00831
840     00832 <a class="code" href="util_8h.html#a9">xprintf</a>(<span class="stringliteral">"SPF Policy Mechanism: %i (token: %s) (pos: %i)\n"</span>,
841     00833 POLICY_TYPE, token_ptr, pos);
842     00834
843     00835 <span class="keywordflow">switch</span> (POLICY_TYPE)
844     00836 {
845     00837
846     00838 <span class="comment">/*</span>
847     00839 <span class="comment"> * no policy set</span>
848     00840 <span class="comment"> */</span>
849     00841 <span class="keywordflow">case</span> <a class="code" href="spf_8h.html#a90a63">NO_POLICY</a>:
850     00842 <span class="keywordflow">break</span>;
851     00843
852     00844 <span class="comment">/*</span>
853     00845 <span class="comment"> * unrecognized mechanism</span>
854     00846 <span class="comment"> */</span>
855     00847 <span class="keywordflow">case</span> <a class="code" href="spf_8h.html#a90a76">UNMECH</a>:
856     00848 <a class="code" href="util_8h.html#a47">UTIL_assoc_prefix</a>(p, <a class="code" href="spf_8h.html#a88a58">SPF_UNMECH</a>, NULL);
857     00849
858     00850 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"Unrecognized mechanism (%s); returning SPF_FALSE\n"</span>, token);
859     00851
860     00852 <a class="code" href="util_8h.html#a6">xfree</a>(token);
861     00853 <a class="code" href="util_8h.html#a6">xfree</a>(copy);
862     00854
863     00855 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a87a49">SPF_FALSE</a>);
864     00856
865     00857 <span class="comment">/*</span>
866     00858 <span class="comment"> * 'version' mechanism </span>
867     00859 <span class="comment"> */</span>
868     00860 <span class="keywordflow">case</span> <a class="code" href="spf_8h.html#a90a64">VERSION</a>:
869     00861 <a class="code" href="util_8h.html#a9">xprintf</a>(<span class="stringliteral">"policy mechanism is version (%s)\n"</span>, token_ptr);
870     00862
871     00863 <span class="keywordflow">if</span> ((s_pos = <a class="code" href="util_8h.html#a35">UTIL_index</a>(token_ptr, <span class="charliteral">'='</span>)) &gt; 0)
872     00864 {
873     00865 token_ptr += s_pos + 4; <span class="comment">/* skip =spf */</span>
874     00866
875     00867 <span class="keywordflow">if</span> (atoi(token_ptr) &gt; <a class="code" href="spf_8h.html#a1">SPF_VERSION</a>)
876     00868 {
877     00869 <a class="code" href="util_8h.html#a47">UTIL_assoc_prefix</a>(p, <a class="code" href="spf_8h.html#a88a52">SPF_NONE</a>, NULL);
878     00870
879     00871 <a class="code" href="util_8h.html#a6">xfree</a>(token);
880     00872 <a class="code" href="util_8h.html#a6">xfree</a>(copy);
881     00873
882     00874 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a87a49">SPF_FALSE</a>);
883     00875 }
884     00876
885     00877 p-&gt;<a class="code" href="structpeer__info__s.html#o5">spf_ver</a> = atoi(token_ptr);
886     00878
887     00879 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"SPF Version defined as: %u\n"</span>, p-&gt;<a class="code" href="structpeer__info__s.html#o5">spf_ver</a>);
888     00880 }
889     00881 <span class="keywordflow">else</span>
890     00882 {
891     00883 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"SPF version redefined! (%u)\n"</span>, p-&gt;<a class="code" href="structpeer__info__s.html#o5">spf_ver</a>);
892     00884 <a class="code" href="util_8h.html#a47">UTIL_assoc_prefix</a>(p, <a class="code" href="spf_8h.html#a88a53">SPF_S_FAIL</a>, NULL);
893     00885
894     00886 <a class="code" href="util_8h.html#a6">xfree</a>(token);
895     00887 <a class="code" href="util_8h.html#a6">xfree</a>(copy);
896     00888
897     00889 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a87a49">SPF_FALSE</a>);
898     00890 }
899     00891
900     00892 <span class="keywordflow">break</span>;
901     00893
902     00894 <span class="comment">/*</span>
903     00895 <span class="comment"> * 'all' mechanism</span>
904     00896 <span class="comment"> */</span>
905     00897 <span class="keywordflow">case</span> <a class="code" href="spf_8h.html#a90a65">ALL</a>:
906     00898 <a class="code" href="util_8h.html#a9">xprintf</a>(<span class="stringliteral">"policy mechanism is all (%s) policy: (%i)\n"</span>,
907     00899 token_ptr, POLICY_TYPE);
908     00900
909     00901 <a class="code" href="util_8h.html#a47">UTIL_assoc_prefix</a>(p, PREFIX_TYPE, NULL);
910     00902 POLICY_MATCH = <a class="code" href="spf_8h.html#a87a50">SPF_TRUE</a>;
911     00903 p-&gt;<a class="code" href="structpeer__info__s.html#o0">ALL</a> = <a class="code" href="spf_8h.html#a87a50">SPF_TRUE</a>;
912     00904
913     00905 <span class="keywordflow">break</span>;
914     00906
915     00907 <span class="comment">/*</span>
916     00908 <span class="comment"> * 'default' policy</span>
917     00909 <span class="comment"> */</span>
918     00910 <span class="keywordflow">case</span> <a class="code" href="spf_8h.html#a90a75">DEFAULT</a>:
919     00911 <a class="code" href="util_8h.html#a9">xprintf</a>(<span class="stringliteral">"policy mechanism is default (%s) policy: (%i)\n"</span>,
920     00912 token_ptr, POLICY_TYPE);
921     00913
922     00914 POLICY_MATCH = <a class="code" href="spf_8h.html#a87a50">SPF_TRUE</a>;
923     00915 p-&gt;<a class="code" href="structpeer__info__s.html#o0">ALL</a> = <a class="code" href="spf_8h.html#a87a50">SPF_TRUE</a>;
924     00916
925     00917 <span class="keywordflow">break</span>;
926     00918
927     00919 <span class="comment">/*</span>
928     00920 <span class="comment"> * 'include' mechanism </span>
929     00921 <span class="comment"> */</span>
930     00922 <span class="keywordflow">case</span> <a class="code" href="spf_8h.html#a90a66">INCLUDE</a>:
931     00923 <a class="code" href="util_8h.html#a9">xprintf</a>(<span class="stringliteral">"policy mechanism is include (%s)\n"</span>, token_ptr);
932     00924
933     00925 <span class="keywordflow">if</span> ((tmp_ptr = strstr(token_ptr, <span class="stringliteral">":"</span>)) != NULL)
934     00926 {
935     00927 tmp_ptr++;
936     00928
937     00929 <span class="keywordflow">if</span> (<a class="code" href="util_8h.html#a41">UTIL_is_macro</a>(tmp_ptr) == <a class="code" href="spf_8h.html#a87a50">SPF_TRUE</a>)
938     00930 {
939     00931 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"this INCLUDE mechanism contained macros (%s)\n"</span>, tmp_ptr);
940     00932
941     00933 <span class="keywordflow">if</span> (p-&gt;<a class="code" href="structpeer__info__s.html#o29">include_buf</a> == NULL)
942     00934 {
943     00935 <span class="keywordflow">if</span> ((macro = <a class="code" href="macro_8h.html#a1">MACRO_expand</a>(p, tmp_ptr)) != NULL)
944     00936 {
945     00937 p-&gt;<a class="code" href="structpeer__info__s.html#o29">include_buf</a> = <a class="code" href="util_8h.html#a8">xstrndup</a>(macro, <a class="code" href="spf_8h.html#a5">SPF_MAX_STR</a>);
946     00938
947     00939 <a class="code" href="util_8h.html#a6">xfree</a>(macro);
948     00940 }
949     00941 }
950     00942 <span class="keywordflow">else</span>
951     00943 {
952     00944 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"Got include=%s, but include already set. Ignoring.\n"</span>,
953     00945 tmp_ptr);
954     00946 }
955     00947 }
956     00948 <span class="keywordflow">else</span>
957     00949 {
958     00950 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"storing INCLUDE (%s) for later...\n"</span>, tmp_ptr);
959     00951
960     00952 <span class="keywordflow">if</span> (p-&gt;<a class="code" href="structpeer__info__s.html#o29">include_buf</a> == NULL)
961     00953 {
962     00954 p-&gt;<a class="code" href="structpeer__info__s.html#o29">include_buf</a> = <a class="code" href="util_8h.html#a8">xstrndup</a>(tmp_ptr, <a class="code" href="spf_8h.html#a5">SPF_MAX_STR</a>);
963     00955 }
964     00956 <span class="keywordflow">else</span>
965     00957 {
966     00958 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"Got include=%s, but include already set. Ignoring.\n"</span>,
967     00959 tmp_ptr);
968     00960 }
969     00961 }
970     00962 }
971     00963 <span class="keywordflow">else</span>
972     00964 {
973     00965 <span class="comment">/* 'include' with no options returns unknown */</span>
974     00966 POLICY_MATCH = <a class="code" href="spf_8h.html#a87a50">SPF_TRUE</a>;
975     00967 <a class="code" href="util_8h.html#a47">UTIL_assoc_prefix</a>(p, <a class="code" href="spf_8h.html#a88a57">SPF_UNKNOWN</a>, token_ptr);
976     00968
977     00969 <a class="code" href="util_8h.html#a6">xfree</a>(token);
978     00970 <a class="code" href="util_8h.html#a6">xfree</a>(copy);
979     00971
980     00972 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a87a50">SPF_TRUE</a>);
981     00973 }
982     00974 <span class="keywordflow">break</span>;
983     00975
984     00976 <span class="comment">/*</span>
985     00977 <span class="comment"> * 'a' mechanism</span>
986     00978 <span class="comment"> */</span>
987     00979 <span class="keywordflow">case</span> <a class="code" href="spf_8h.html#a90a67">A</a>:
988     00980 <a class="code" href="util_8h.html#a9">xprintf</a>(<span class="stringliteral">"policy mechanism is A (%s)\n"</span>, token_ptr);
989     00981
990     00982 <span class="keywordflow">if</span> ((tmp_ptr = strstr(token_ptr, <span class="stringliteral">"/"</span>)) != NULL)
991     00983 {
992     00984 tmp_ptr++;
993     00985 POLICY_MATCH = <a class="code" href="util_8h.html#a43">UTIL_a_cmp</a>(p, token_ptr, atoi(tmp_ptr));
994     00986 }
995     00987 <span class="keywordflow">else</span>
996     00988 {
997     00989 POLICY_MATCH = <a class="code" href="util_8h.html#a43">UTIL_a_cmp</a>(p, token_ptr, 32);
998     00990 }
999     00991
1000     00992 <span class="comment">/* mechanism was supplied with a - indicating a failure on */</span>
1001     00993 <span class="keywordflow">if</span> ((PREFIX_TYPE == <a class="code" href="spf_8h.html#a88a54">SPF_H_FAIL</a>) &amp;&amp; (POLICY_MATCH == <a class="code" href="spf_8h.html#a87a50">SPF_TRUE</a>))
1002     00994 {
1003     00995 <a class="code" href="util_8h.html#a11">xpprintf</a>(<span class="stringliteral">"Found a match on a negative prefix. Halting parse.\n"</span>);
1004     00996 <a class="code" href="util_8h.html#a47">UTIL_assoc_prefix</a>(p, <a class="code" href="spf_8h.html#a88a54">SPF_H_FAIL</a>, token_ptr);
1005     00997
1006     00998 <a class="code" href="util_8h.html#a6">xfree</a>(token);
1007     00999 <a class="code" href="util_8h.html#a6">xfree</a>(copy);
1008     01000
1009     01001 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a87a49">SPF_FALSE</a>);
1010     01002 }
1011     01003
1012     01004 <span class="keywordflow">break</span>;
1013     01005
1014     01006 <span class="comment">/*</span>
1015     01007 <span class="comment"> * 'mx' mechanism</span>
1016     01008 <span class="comment"> */</span>
1017     01009 <span class="keywordflow">case</span> <a class="code" href="spf_8h.html#a90a68">MX</a>:
1018     01010 <a class="code" href="util_8h.html#a9">xprintf</a>(<span class="stringliteral">"policy mechanism is mx (%s)\n"</span>, token_ptr);
1019     01011
1020     01012 <span class="comment">/* we've been supplied an MX to use instead.. grab it */</span>
1021     01013 <span class="comment">/* use tmp_ptr2 so we can use tmp_ptr again */</span>
1022     01014 <span class="keywordflow">if</span> ((tmp_ptr = strstr(token_ptr, <span class="stringliteral">":"</span>)) != NULL)
1023     01015 {
1024     01016 tmp_ptr++;
1025     01017 tmp_ptr2 = tmp_ptr;
1026     01018 }
1027     01019 <span class="keywordflow">else</span>
1028     01020 {
1029     01021 tmp_ptr2 = p-&gt;<a class="code" href="structpeer__info__s.html#o15">current_domain</a>;
1030     01022 }
1031     01023
1032     01024 <span class="keywordflow">if</span> ((tmp_ptr = strstr(token_ptr, <span class="stringliteral">"/"</span>)) != NULL)
1033     01025 {
1034     01026 tmp_ptr++;
1035     01027 POLICY_MATCH = <a class="code" href="util_8h.html#a42">UTIL_mx_cmp</a>(p, tmp_ptr2, atoi(tmp_ptr));
1036     01028 }
1037     01029 <span class="keywordflow">else</span>
1038     01030 {
1039     01031 POLICY_MATCH = <a class="code" href="util_8h.html#a42">UTIL_mx_cmp</a>(p, tmp_ptr2, 32);
1040     01032 }
1041     01033
1042     01034 <span class="comment">/* mechanism was supplied with a - indicating a failure on */</span>
1043     01035 <span class="keywordflow">if</span> ((PREFIX_TYPE == <a class="code" href="spf_8h.html#a88a54">SPF_H_FAIL</a>) &amp;&amp; (POLICY_MATCH == <a class="code" href="spf_8h.html#a87a50">SPF_TRUE</a>))
1044     01036 {
1045     01037 <a class="code" href="util_8h.html#a11">xpprintf</a>(<span class="stringliteral">"Found a match on a negative prefix. Halting parse.\n"</span>);
1046     01038
1047     01039 <a class="code" href="util_8h.html#a47">UTIL_assoc_prefix</a>(p, <a class="code" href="spf_8h.html#a88a54">SPF_H_FAIL</a>, token_ptr);
1048     01040
1049     01041 <a class="code" href="util_8h.html#a6">xfree</a>(token);
1050     01042 <a class="code" href="util_8h.html#a6">xfree</a>(copy);
1051     01043
1052     01044 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a87a49">SPF_FALSE</a>);
1053     01045 }
1054     01046
1055     01047 <span class="keywordflow">break</span>;
1056     01048
1057     01049 <span class="comment">/*</span>
1058     01050 <span class="comment"> * 'ptr' mechanism</span>
1059     01051 <span class="comment"> */</span>
1060     01052 <span class="keywordflow">case</span> <a class="code" href="spf_8h.html#a90a69">PTR</a>:
1061     01053 <a class="code" href="util_8h.html#a9">xprintf</a>(<span class="stringliteral">"policy mechanism is ptr (%s)\n"</span>, token_ptr);
1062     01054
1063     01055 POLICY_MATCH = <a class="code" href="util_8h.html#a44">UTIL_ptr_cmp</a>(p, token_ptr);
1064     01056
1065     01057 <span class="comment">/* mechanism was supplied with a - indicating a failure on */</span>
1066     01058 <span class="keywordflow">if</span> ((PREFIX_TYPE == <a class="code" href="spf_8h.html#a88a54">SPF_H_FAIL</a>) &amp;&amp; (POLICY_MATCH == <a class="code" href="spf_8h.html#a87a50">SPF_TRUE</a>))
1067     01059 {
1068     01060 <a class="code" href="util_8h.html#a11">xpprintf</a>(<span class="stringliteral">"Found a match on a negative prefix. Halting parse.\n"</span>);
1069     01061
1070     01062 <span class="keywordflow">break</span>;
1071     01063 }
1072     01064
1073     01065 <span class="keywordflow">break</span>;
1074     01066
1075     01067
1076     01068 <span class="comment">/*</span>
1077     01069 <span class="comment"> * 'ip4' mechanism </span>
1078     01070 <span class="comment"> */</span>
1079     01071 <span class="keywordflow">case</span> <a class="code" href="spf_8h.html#a90a70">IP4</a>:
1080     01072 <a class="code" href="util_8h.html#a9">xprintf</a>(<span class="stringliteral">"policy mechanism is ip4 (%s)\n"</span>, token_ptr);
1081     01073
1082     01074 <span class="keywordflow">if</span> ((policy_ip = <a class="code" href="util_8h.html#a48">UTIL_expand_ip</a>(token_ptr)) == NULL)
1083     01075 {
1084     01076 <a class="code" href="util_8h.html#a11">xpprintf</a>(<span class="stringliteral">"ERROR: inet_pton unable to convert ip to binary\n"</span>);
1085     01077
1086     01078 <span class="keywordflow">break</span>;
1087     01079 }
1088     01080
1089     01081 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"POL: %lu (%s) PEER: %lu (%s)\n"</span>,
1090     01082 policy_ip-&gt;<a class="code" href="structpolicy__addr__s.html#o2">addr</a>.s_addr, token_ptr, p-&gt;<a class="code" href="structpeer__info__s.html#o26">addr</a>.s_addr, p-&gt;<a class="code" href="structpeer__info__s.html#o17">r_ip</a>);
1091     01083
1092     01084 POLICY_MATCH = <a class="code" href="util_8h.html#a52">UTIL_cidr_cmp</a>(policy_ip, &amp;p-&gt;<a class="code" href="structpeer__info__s.html#o26">addr</a>);
1093     01085 <a class="code" href="util_8h.html#a6">xfree</a>(policy_ip);
1094     01086
1095     01087 <span class="comment">/* mechanism was supplied with a - indicating a failure on */</span>
1096     01088 <span class="keywordflow">if</span> ((PREFIX_TYPE == <a class="code" href="spf_8h.html#a88a54">SPF_H_FAIL</a>) &amp;&amp; (POLICY_MATCH == <a class="code" href="spf_8h.html#a87a50">SPF_TRUE</a>))
1097     01089 {
1098     01090 <a class="code" href="util_8h.html#a11">xpprintf</a>(<span class="stringliteral">"Found a match on a negative prefix. Halting parse.\n"</span>);
1099     01091 <a class="code" href="util_8h.html#a47">UTIL_assoc_prefix</a>(p, <a class="code" href="spf_8h.html#a88a54">SPF_H_FAIL</a>, token_ptr);
1100     01092
1101     01093 <a class="code" href="util_8h.html#a6">xfree</a>(token);
1102     01094 <a class="code" href="util_8h.html#a6">xfree</a>(copy);
1103     01095
1104     01096 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a87a49">SPF_FALSE</a>);
1105     01097 }
1106     01098
1107     01099 <span class="keywordflow">break</span>;
1108     01100
1109     01101 <span class="comment">/* </span>
1110     01102 <span class="comment"> * 'ip6' mechanism</span>
1111     01103 <span class="comment"> */</span>
1112     01104 <span class="keywordflow">case</span> <a class="code" href="spf_8h.html#a90a71">IP6</a>:
1113     01105 <a class="code" href="util_8h.html#a9">xprintf</a>(<span class="stringliteral">"policy mechanism is ip6 (%s)\n"</span>, token_ptr);
1114     01106
1115     01107 <span class="keywordflow">break</span>;
1116     01108
1117     01109 <span class="comment">/*</span>
1118     01110 <span class="comment"> * 'exists' mechanism</span>
1119     01111 <span class="comment"> */</span>
1120     01112 <span class="keywordflow">case</span> <a class="code" href="spf_8h.html#a90a72">EXISTS</a>:
1121     01113 <a class="code" href="util_8h.html#a9">xprintf</a>(<span class="stringliteral">"policy mechanism is exists (%s)\n"</span>, token_ptr);
1122     01114
1123     01115 <span class="keywordflow">if</span> ((tmp_ptr = strstr(token_ptr, <span class="stringliteral">":"</span>)) != NULL)
1124     01116 {
1125     01117 tmp_ptr++;
1126     01118
1127     01119 <span class="keywordflow">if</span> ((macro = <a class="code" href="macro_8h.html#a1">MACRO_expand</a>(p, tmp_ptr)) == NULL)
1128     01120 {
1129     01121 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"Unable to expand macro (%s). Aborting.\n"</span>, tmp_ptr);
1130     01122
1131     01123 <span class="keywordflow">break</span>;
1132     01124 }
1133     01125
1134     01126 <span class="keywordflow">if</span> (<a class="code" href="dns_8h.html#a8">DNS_query</a>(p, macro, T_A, NULL) == (<span class="keywordtype">char</span> *)<a class="code" href="spf_8h.html#a87a50">SPF_TRUE</a>)
1135     01127 {
1136     01128 POLICY_MATCH = <a class="code" href="spf_8h.html#a87a50">SPF_TRUE</a>;
1137     01129 }
1138     01130
1139     01131 <a class="code" href="util_8h.html#a6">xfree</a>(macro);
1140     01132 }
1141     01133 <span class="keywordflow">break</span>;
1142     01134
1143     01135 <span class="comment">/*</span>
1144     01136 <span class="comment"> * 'redirect' modifier</span>
1145     01137 <span class="comment"> */</span>
1146     01138 <span class="keywordflow">case</span> <a class="code" href="spf_8h.html#a90a73">REDIRECT</a>:
1147     01139 <a class="code" href="util_8h.html#a9">xprintf</a>(<span class="stringliteral">"modifier is redirect (%s)\n"</span>, token_ptr);
1148     01140
1149     01141 <span class="keywordflow">if</span> ((tmp_ptr = strstr(token_ptr, <span class="stringliteral">"="</span>)) != NULL)
1150     01142 {
1151     01143 tmp_ptr++;
1152     01144
1153     01145 <span class="keywordflow">if</span> (<a class="code" href="util_8h.html#a41">UTIL_is_macro</a>(tmp_ptr) == <a class="code" href="spf_8h.html#a87a50">SPF_TRUE</a>)
1154     01146 {
1155     01147 <span class="keywordflow">if</span> (p-&gt;<a class="code" href="structpeer__info__s.html#o30">redirect_buf</a> == NULL)
1156     01148 {
1157     01149 <span class="keywordflow">if</span> ((macro = <a class="code" href="macro_8h.html#a1">MACRO_expand</a>(p, tmp_ptr)) != NULL)
1158     01150 {
1159     01151 p-&gt;<a class="code" href="structpeer__info__s.html#o30">redirect_buf</a> = <a class="code" href="util_8h.html#a8">xstrndup</a>(macro, <a class="code" href="spf_8h.html#a5">SPF_MAX_STR</a>);
1160     01152 <a class="code" href="util_8h.html#a6">xfree</a>(macro);
1161     01153 }
1162     01154 }
1163     01155 <span class="keywordflow">else</span>
1164     01156 {
1165     01157 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"Got redir=%s, but redirect already set. Ignoring.\n"</span>,
1166     01158 tmp_ptr);
1167     01159 }
1168     01160 }
1169     01161 <span class="keywordflow">else</span>
1170     01162 {
1171     01163 <span class="keywordflow">if</span> (p-&gt;<a class="code" href="structpeer__info__s.html#o30">redirect_buf</a> == NULL)
1172     01164 {
1173     01165 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"setting redirect_buf to %s\n"</span>, tmp_ptr);
1174     01166 p-&gt;<a class="code" href="structpeer__info__s.html#o30">redirect_buf</a> = <a class="code" href="util_8h.html#a8">xstrndup</a>(tmp_ptr, <a class="code" href="spf_8h.html#a5">SPF_MAX_STR</a>);
1175     01167 }
1176     01168 <span class="keywordflow">else</span>
1177     01169 {
1178     01170 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"Got redir=%s, but redirect already set. Ignoring.\n"</span>,
1179     01171 tmp_ptr);
1180     01172 }
1181     01173 }
1182     01174 }
1183     01175 <span class="keywordflow">break</span>;
1184     01176
1185     01177 <span class="comment">/*</span>
1186     01178 <span class="comment"> * 'explain' mechanism </span>
1187     01179 <span class="comment"> */</span>
1188     01180 <span class="keywordflow">case</span> <a class="code" href="spf_8h.html#a90a74">EXPLAIN</a>:
1189     01181 <a class="code" href="util_8h.html#a9">xprintf</a>(<span class="stringliteral">"policy mechanism is explain (%s)\n"</span>, token_ptr);
1190     01182
1191     01183 <span class="keywordflow">if</span> ((tmp_ptr = strstr(token_ptr, <span class="stringliteral">"="</span>)) != NULL)
1192     01184 {
1193     01185 tmp_ptr++;
1194     01186
1195     01187 <span class="keywordflow">if</span> ((macro = <a class="code" href="macro_8h.html#a1">MACRO_expand</a>(p, tmp_ptr)) == NULL)
1196     01188 {
1197     01189 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"Unable to expand macro (%s). Aborting.\n"</span>, tmp_ptr);
1198     01190
1199     01191 <span class="keywordflow">break</span>;
1200     01192 }
1201     01193
1202     01194 p-&gt;<a class="code" href="structpeer__info__s.html#o11">explain</a> = <a class="code" href="util_8h.html#a8">xstrndup</a>(macro, (strlen(macro) + 1));
1203     01195 <a class="code" href="util_8h.html#a6">xfree</a>(macro);
1204     01196 }
1205     01197 <span class="keywordflow">else</span>
1206     01198 {
1207     01199 <a class="code" href="util_8h.html#a11">xpprintf</a>(<span class="stringliteral">"EXPLAIN modifier must be accompanied "</span> \
1208     01200 <span class="stringliteral">"by arguments and I found none."</span>);
1209     01201
1210     01202 <span class="comment">/* 'include' with no options returns unknown */</span>
1211     01203 POLICY_MATCH = <a class="code" href="spf_8h.html#a87a50">SPF_TRUE</a>;
1212     01204 <a class="code" href="util_8h.html#a47">UTIL_assoc_prefix</a>(p, <a class="code" href="spf_8h.html#a88a57">SPF_UNKNOWN</a>, token_ptr);
1213     01205
1214     01206 <a class="code" href="util_8h.html#a6">xfree</a>(token);
1215     01207 <a class="code" href="util_8h.html#a6">xfree</a>(copy);
1216     01208
1217     01209 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a87a50">SPF_TRUE</a>);
1218     01210 }
1219     01211
1220     01212 <span class="keywordflow">break</span>;
1221     01213 } <span class="comment">/* switch */</span>
1222     01214
1223     01215 <a class="code" href="util_8h.html#a6">xfree</a>(token);
1224     01216 cp += pos + 1; <span class="comment">/* move over to the next mechanism */</span>
1225     01217
1226     01218 <span class="keywordflow">if</span> ((POLICY_MATCH == <a class="code" href="spf_8h.html#a87a50">SPF_TRUE</a>) &amp;&amp; (p-&gt;<a class="code" href="structpeer__info__s.html#o5">spf_ver</a> &gt; 0))
1227     01219 {
1228     01220 <span class="comment">/*p-&gt;RES = SPF_PASS;*/</span>
1229     01221 <a class="code" href="util_8h.html#a47">UTIL_assoc_prefix</a>(p, PREFIX_TYPE, p-&gt;<a class="code" href="structpeer__info__s.html#o23">last_m</a>);
1230     01222 p-&gt;<a class="code" href="structpeer__info__s.html#o2">RES_P</a> = p-&gt;<a class="code" href="structpeer__info__s.html#o1">RES</a>;
1231     01223
1232     01224 <a class="code" href="util_8h.html#a11">xpprintf</a>(<span class="stringliteral">"returning SPF_TRUE\n"</span>);
1233     01225 <a class="code" href="util_8h.html#a6">xfree</a>(copy);
1234     01226
1235     01227 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a87a50">SPF_TRUE</a>);
1236     01228 }
1237     01229 } <span class="comment">/* while parsing policy */</span>
1238     01230
1239     01231 <a class="code" href="util_8h.html#a6">xfree</a>(copy);
1240     01232
1241     01233 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a87a49">SPF_FALSE</a>);
1242     01234 }
1243     01235
1244     01236
1245     01237 <span class="comment">/* SPF_result</span>
1246     01238 <span class="comment">*</span>
1247     01239 <span class="comment">* Author: James Couzens &lt;jcouzens@codeshare.ca&gt;</span>
1248     01240 <span class="comment">*</span>
1249     01241 <span class="comment">* Date: 02/02/04</span>
1250     01242 <span class="comment">*</span>
1251     01243 <span class="comment">* Desc:</span>
1252     01244 <span class="comment">* Returns a string of allocated memory detailing a response</span>
1253     01245 <span class="comment">* that the MTA will return to the client based on the result</span>
1254     01246 <span class="comment">* received from an SPF query.</span>
1255     01247 <span class="comment">*</span>
1256     01248 <span class="comment">*/</span>
1257     <a name="l01249"></a><a class="code" href="spf_8h.html#a82">01249</a> <span class="keywordtype">char</span> *<a class="code" href="spf_8h.html#a82">SPF_result</a>(<a class="code" href="structpeer__info__s.html">peer_info_t</a> *p)
1258     01250 {
1259     01251 <span class="keywordtype">char</span> *buf; <span class="comment">/* return buffer */</span>
1260     01252
1261     01253
1262     01254 buf = <a class="code" href="util_8h.html#a4">xmalloc</a>(<a class="code" href="spf_8h.html#a21">SPF_MAX_HEADER</a>);
1263     01255
1264     01256 <span class="keywordflow">switch</span> (p-&gt;<a class="code" href="structpeer__info__s.html#o1">RES</a>)
1265     01257 {
1266     01258 <span class="keywordflow">case</span> <a class="code" href="spf_8h.html#a88a51">SPF_PASS</a>:
1267     01259 snprintf(buf, <a class="code" href="spf_8h.html#a22">SPF_MAX_SMTP_RES</a>, <a class="code" href="main_8h.html#a9">RES_PASS</a>, p-&gt;<a class="code" href="structpeer__info__s.html#o10">from</a>, p-&gt;<a class="code" href="structpeer__info__s.html#o17">r_ip</a>);
1268     01260 <span class="keywordflow">break</span>;
1269     01261
1270     01262 <span class="keywordflow">case</span> <a class="code" href="spf_8h.html#a88a52">SPF_NONE</a>:
1271     01263 snprintf(buf, <a class="code" href="spf_8h.html#a22">SPF_MAX_SMTP_RES</a>, <a class="code" href="main_8h.html#a10">RES_NONE</a>, p-&gt;<a class="code" href="structpeer__info__s.html#o10">from</a>);
1272     01264 <span class="keywordflow">break</span>;
1273     01265
1274     01266 <span class="keywordflow">case</span> <a class="code" href="spf_8h.html#a88a53">SPF_S_FAIL</a>:
1275     01267 snprintf(buf, <a class="code" href="spf_8h.html#a22">SPF_MAX_SMTP_RES</a>, <a class="code" href="main_8h.html#a11">RES_S_FAIL</a>, p-&gt;<a class="code" href="structpeer__info__s.html#o10">from</a>, p-&gt;<a class="code" href="structpeer__info__s.html#o17">r_ip</a>);
1276     01268 <span class="keywordflow">break</span>;
1277     01269
1278     01270 <span class="keywordflow">case</span> <a class="code" href="spf_8h.html#a88a54">SPF_H_FAIL</a>:
1279     01271 snprintf(buf, <a class="code" href="spf_8h.html#a22">SPF_MAX_SMTP_RES</a>, <a class="code" href="main_8h.html#a12">RES_H_FAIL</a>, p-&gt;<a class="code" href="structpeer__info__s.html#o10">from</a>, p-&gt;<a class="code" href="structpeer__info__s.html#o17">r_ip</a>);
1280     01272 <span class="keywordflow">break</span>;
1281     01273
1282     01274 <span class="keywordflow">case</span> <a class="code" href="spf_8h.html#a88a55">SPF_ERROR</a>:
1283     01275 snprintf(buf, <a class="code" href="spf_8h.html#a22">SPF_MAX_SMTP_RES</a>, <a class="code" href="main_8h.html#a13">RES_ERROR</a>, p-&gt;<a class="code" href="structpeer__info__s.html#o10">from</a>);
1284     01276 <span class="keywordflow">break</span>;
1285     01277
1286     01278 <span class="keywordflow">case</span> <a class="code" href="spf_8h.html#a88a56">SPF_NEUTRAL</a>:
1287     01279 snprintf(buf, <a class="code" href="spf_8h.html#a22">SPF_MAX_SMTP_RES</a>, <a class="code" href="main_8h.html#a14">RES_NEUTRAL</a>, p-&gt;<a class="code" href="structpeer__info__s.html#o17">r_ip</a>, p-&gt;<a class="code" href="structpeer__info__s.html#o10">from</a>);
1288     01280 <span class="keywordflow">break</span>;
1289     01281
1290     01282 <span class="keywordflow">case</span> <a class="code" href="spf_8h.html#a88a57">SPF_UNKNOWN</a>:
1291     01283 snprintf(buf, <a class="code" href="spf_8h.html#a22">SPF_MAX_SMTP_RES</a>, <a class="code" href="main_8h.html#a15">RES_UNKNOWN</a>, p-&gt;<a class="code" href="structpeer__info__s.html#o10">from</a>);
1292     01284 <span class="keywordflow">break</span>;
1293     01285
1294     01286 <span class="keywordflow">case</span> <a class="code" href="spf_8h.html#a88a58">SPF_UNMECH</a>:
1295     01287 snprintf(buf, <a class="code" href="spf_8h.html#a22">SPF_MAX_SMTP_RES</a>, <a class="code" href="main_8h.html#a16">RES_UNMECH</a>, p-&gt;<a class="code" href="structpeer__info__s.html#o10">from</a>);
1296     01288 <span class="keywordflow">break</span>;
1297     01289 }
1298     01290
1299     01291 <a class="code" href="util_8h.html#a9">xprintf</a>(<span class="stringliteral">"response: (%s)\n"</span>, buf);
1300     01292
1301     01293 <span class="keywordflow">return</span>(buf);
1302     01294 }
1303     01295
1304     01296
1305     01297 <span class="comment">/* SPF_get_explain</span>
1306     01298 <span class="comment">*</span>
1307     01299 <span class="comment">* Author: James Couzens &lt;jcouzens@codeshare.ca&gt;</span>
1308     01300 <span class="comment">*</span>
1309     01301 <span class="comment">* Date: 01/25/04</span>
1310     01302 <span class="comment">*</span>
1311     01303 <span class="comment">* Desc:</span>
1312     01304 <span class="comment">* Takes the contents of a returned explain parse (if any),</span>
1313     01305 <span class="comment">* allocates memory for it and returns that memory with the contents of</span>
1314     01306 <span class="comment">* that string. Calling function is required to free this memory.</span>
1315     01307 <span class="comment">*</span>
1316     01308 <span class="comment">*</span>
1317     01309 <span class="comment">*/</span>
1318     <a name="l01310"></a><a class="code" href="spf_8h.html#a86">01310</a> <span class="keywordtype">char</span> *<a class="code" href="spf_8h.html#a86">SPF_get_explain</a>(<a class="code" href="structpeer__info__s.html">peer_info_t</a> *p)
1319     01311 {
1320     01312 <span class="keywordtype">char</span> *buf = NULL; <span class="comment">/* return buffer */</span>
1321     01313
1322     01314
1323     01315 <span class="keywordflow">if</span> (p-&gt;<a class="code" href="structpeer__info__s.html#o11">explain</a> != NULL)
1324     01316 {
1325     01317 <span class="keywordflow">if</span> ((buf = <a class="code" href="macro_8h.html#a1">MACRO_expand</a>(p, <a class="code" href="spf_8h.html#a32">SPF_EXPLAIN</a>)) != NULL)
1326     01318 {
1327     01319 <a class="code" href="util_8h.html#a9">xprintf</a>(<span class="stringliteral">"Prepending explain: (%s)\n"</span>, buf);
1328     01320
1329     01321 <span class="keywordflow">return</span>(buf);
1330     01322 }
1331     01323 }
1332     01324
1333     01325 <span class="keywordflow">return</span>(NULL);
1334     01326 }
1335     01327
1336     01328
1337     01329 <span class="comment">/* SPF_build_header</span>
1338     01330 <span class="comment">*</span>
1339     01331 <span class="comment">* Author: James Couzens &lt;jcouzens@codeshare.ca&gt;</span>
1340     01332 <span class="comment">*</span>
1341     01333 <span class="comment">* Date: 01/25/04</span>
1342     01334 <span class="comment">*</span>
1343     01335 <span class="comment">* Desc:</span>
1344     01336 <span class="comment">* Allocates memory and builds a string which contains a</span>
1345     01337 <span class="comment">* Received-SPF header. The calling function is responsible to free</span>
1346     01338 <span class="comment">* this memory.</span>
1347     01339 <span class="comment">*</span>
1348     01340 <span class="comment">*</span>
1349     01341 <span class="comment">*/</span>
1350     <a name="l01342"></a><a class="code" href="spf_8h.html#a85">01342</a> <span class="keywordtype">char</span> *<a class="code" href="spf_8h.html#a85">SPF_build_header</a>(<a class="code" href="structpeer__info__s.html">peer_info_t</a> *p)
1351     01343 {
1352     01344 <span class="keywordtype">char</span> *buf; <span class="comment">/* return buffer */</span>
1353     01345
1354     01346 buf = <a class="code" href="util_8h.html#a4">xmalloc</a>(<a class="code" href="spf_8h.html#a21">SPF_MAX_HEADER</a>);
1355     01347
1356     01348 <span class="keywordflow">switch</span> (p-&gt;<a class="code" href="structpeer__info__s.html#o1">RES</a>)
1357     01349 {
1358     01350 <span class="comment">/* */</span>
1359     01351 <span class="keywordflow">case</span> <a class="code" href="spf_8h.html#a88a51">SPF_PASS</a>:
1360     01352 snprintf(buf, <a class="code" href="spf_8h.html#a21">SPF_MAX_HEADER</a>, p-&gt;<a class="code" href="structpeer__info__s.html#o25">spf_result</a>[<a class="code" href="spf_8h.html#a88a51">SPF_PASS</a>].h,
1361     01353 p-&gt;<a class="code" href="structpeer__info__s.html#o16">mta_hname</a>, p-&gt;<a class="code" href="structpeer__info__s.html#o10">from</a>, p-&gt;<a class="code" href="structpeer__info__s.html#o17">r_ip</a>, p-&gt;<a class="code" href="structpeer__info__s.html#o16">mta_hname</a>,
1362     01354 p-&gt;<a class="code" href="structpeer__info__s.html#o17">r_ip</a>, p-&gt;<a class="code" href="structpeer__info__s.html#o10">from</a>);
1363     01355 <span class="keywordflow">break</span>;
1364     01356
1365     01357 <span class="comment">/* */</span>
1366     01358 <span class="keywordflow">case</span> <a class="code" href="spf_8h.html#a88a52">SPF_NONE</a>:
1367     01359 snprintf(buf, <a class="code" href="spf_8h.html#a21">SPF_MAX_HEADER</a>, p-&gt;<a class="code" href="structpeer__info__s.html#o25">spf_result</a>[<a class="code" href="spf_8h.html#a88a52">SPF_NONE</a>].h,
1368     01360 p-&gt;<a class="code" href="structpeer__info__s.html#o16">mta_hname</a>, p-&gt;<a class="code" href="structpeer__info__s.html#o10">from</a>);
1369     01361 <span class="keywordflow">break</span>;
1370     01362
1371     01363 <span class="comment">/* */</span>
1372     01364 <span class="keywordflow">case</span> <a class="code" href="spf_8h.html#a88a53">SPF_S_FAIL</a>:
1373     01365 snprintf(buf, <a class="code" href="spf_8h.html#a21">SPF_MAX_HEADER</a>, p-&gt;<a class="code" href="structpeer__info__s.html#o25">spf_result</a>[<a class="code" href="spf_8h.html#a88a53">SPF_S_FAIL</a>].h,
1374     01366 p-&gt;<a class="code" href="structpeer__info__s.html#o16">mta_hname</a>, p-&gt;<a class="code" href="structpeer__info__s.html#o10">from</a>, p-&gt;<a class="code" href="structpeer__info__s.html#o17">r_ip</a>, p-&gt;<a class="code" href="structpeer__info__s.html#o16">mta_hname</a>,
1375     01367 p-&gt;<a class="code" href="structpeer__info__s.html#o17">r_ip</a>, p-&gt;<a class="code" href="structpeer__info__s.html#o10">from</a>);
1376     01368 <span class="keywordflow">break</span>;
1377     01369
1378     01370 <span class="comment">/* */</span>
1379     01371 <span class="keywordflow">case</span> <a class="code" href="spf_8h.html#a88a54">SPF_H_FAIL</a>:
1380     01372 snprintf(buf, <a class="code" href="spf_8h.html#a21">SPF_MAX_HEADER</a>, p-&gt;<a class="code" href="structpeer__info__s.html#o25">spf_result</a>[<a class="code" href="spf_8h.html#a88a54">SPF_H_FAIL</a>].h,
1381     01373 p-&gt;<a class="code" href="structpeer__info__s.html#o16">mta_hname</a>, p-&gt;<a class="code" href="structpeer__info__s.html#o10">from</a>, p-&gt;<a class="code" href="structpeer__info__s.html#o17">r_ip</a>, p-&gt;<a class="code" href="structpeer__info__s.html#o16">mta_hname</a>,
1382     01374 p-&gt;<a class="code" href="structpeer__info__s.html#o17">r_ip</a>, p-&gt;<a class="code" href="structpeer__info__s.html#o10">from</a>);
1383     01375 <span class="keywordflow">break</span>;
1384     01376
1385     01377 <span class="comment">/* */</span>
1386     01378 <span class="keywordflow">case</span> <a class="code" href="spf_8h.html#a88a55">SPF_ERROR</a>:
1387     01379 snprintf(buf, <a class="code" href="spf_8h.html#a21">SPF_MAX_HEADER</a>, p-&gt;<a class="code" href="structpeer__info__s.html#o25">spf_result</a>[<a class="code" href="spf_8h.html#a88a55">SPF_ERROR</a>].h,
1388     01380 p-&gt;<a class="code" href="structpeer__info__s.html#o16">mta_hname</a>, p-&gt;<a class="code" href="structpeer__info__s.html#o10">from</a>, p-&gt;<a class="code" href="structpeer__info__s.html#o24">error</a>);
1389     01381 <span class="keywordflow">break</span>;
1390     01382
1391     01383 <span class="comment">/* */</span>
1392     01384 <span class="keywordflow">case</span> <a class="code" href="spf_8h.html#a88a56">SPF_NEUTRAL</a>:
1393     01385 snprintf(buf, <a class="code" href="spf_8h.html#a21">SPF_MAX_HEADER</a>, p-&gt;<a class="code" href="structpeer__info__s.html#o25">spf_result</a>[<a class="code" href="spf_8h.html#a88a56">SPF_NEUTRAL</a>].h,
1394     01386 p-&gt;<a class="code" href="structpeer__info__s.html#o16">mta_hname</a>, p-&gt;<a class="code" href="structpeer__info__s.html#o10">from</a>, p-&gt;<a class="code" href="structpeer__info__s.html#o17">r_ip</a>);
1395     01387 <span class="keywordflow">break</span>;
1396     01388
1397     01389 <span class="comment">/* */</span>
1398     01390 <span class="keywordflow">case</span> <a class="code" href="spf_8h.html#a88a57">SPF_UNKNOWN</a>:
1399     01391 snprintf(buf, <a class="code" href="spf_8h.html#a21">SPF_MAX_HEADER</a>, p-&gt;<a class="code" href="structpeer__info__s.html#o25">spf_result</a>[<a class="code" href="spf_8h.html#a88a57">SPF_UNKNOWN</a>].h,
1400     01392 p-&gt;<a class="code" href="structpeer__info__s.html#o16">mta_hname</a>, p-&gt;<a class="code" href="structpeer__info__s.html#o10">from</a>, p-&gt;<a class="code" href="structpeer__info__s.html#o15">current_domain</a>, p-&gt;<a class="code" href="structpeer__info__s.html#o23">last_m</a>);
1401     01393 <span class="keywordflow">break</span>;
1402     01394
1403     01395 <span class="comment">/* */</span>
1404     01396 <span class="keywordflow">case</span> <a class="code" href="spf_8h.html#a88a58">SPF_UNMECH</a>:
1405     01397 snprintf(buf, <a class="code" href="spf_8h.html#a21">SPF_MAX_HEADER</a>, p-&gt;<a class="code" href="structpeer__info__s.html#o25">spf_result</a>[<a class="code" href="spf_8h.html#a88a58">SPF_UNMECH</a>].h,
1406     01398 p-&gt;<a class="code" href="structpeer__info__s.html#o23">last_m</a>, p-&gt;<a class="code" href="structpeer__info__s.html#o16">mta_hname</a>, p-&gt;<a class="code" href="structpeer__info__s.html#o10">from</a>);
1407     01399 <span class="keywordflow">break</span>;
1408     01400 }
1409     01401
1410     01402 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"Prepending header string: (%s)\n"</span>, buf);
1411     01403
1412     01404 <span class="keywordflow">return</span>(buf);
1413     01405 }
1414     01406
1415     01407
1416     01408 <span class="comment">/* SPF_smtp_helo</span>
1417     01409 <span class="comment">*</span>
1418     01410 <span class="comment">* Author: Sean Comeau &lt;scomeau@obscurity.org&gt;</span>
1419     01411 <span class="comment">* James Couzens &lt;jcouzens@codeshare.ca&gt;</span>
1420     01412 <span class="comment">* Patrick Earl (http://patearl.net/)</span>
1421     01413 <span class="comment">*</span>
1422     01414 <span class="comment">* Date: 12/10/03</span>
1423     01415 <span class="comment">* 12/25/03 (modified / renamed)</span>
1424     01416 <span class="comment">* 02/04/04 (modified)</span>
1425     01417 <span class="comment">*</span>
1426     01418 <span class="comment">* Desc:</span>
1427     01419 <span class="comment">* Fetches the HELO from MTA and places into the global</span>
1428     01420 <span class="comment">* p structure.</span>
1429     01421 <span class="comment">*</span>
1430     01422 <span class="comment">*/</span>
1431     <a name="l01423"></a><a class="code" href="spf_8h.html#a84">01423</a> <a class="code" href="spf_8h.html#a35">SPF_BOOL</a> <a class="code" href="spf_8h.html#a84">SPF_smtp_helo</a>(<a class="code" href="structpeer__info__s.html">peer_info_t</a> *p, <span class="keyword">const</span> <span class="keywordtype">char</span> *s)
1432     01424 {
1433     01425
1434     01426 <a class="code" href="util_8h.html#a9">xprintf</a>(<span class="stringliteral">"called with (%s)\n"</span>, s);
1435     01427
1436     01428 <span class="keywordflow">if</span> (p-&gt;<a class="code" href="structpeer__info__s.html#o8">helo</a>)
1437     01429 {
1438     01430 <a class="code" href="util_8h.html#a6">xfree</a>(p-&gt;<a class="code" href="structpeer__info__s.html#o8">helo</a>);
1439     01431 }
1440     01432
1441     01433 p-&gt;<a class="code" href="structpeer__info__s.html#o8">helo</a> = <a class="code" href="util_8h.html#a7">xstrdup</a>(s);
1442     01434 p-&gt;<a class="code" href="structpeer__info__s.html#o9">ehlo</a> = p-&gt;<a class="code" href="structpeer__info__s.html#o8">helo</a>;
1443     01435
1444     01436 <span class="keywordflow">return</span> (strlen(p-&gt;<a class="code" href="structpeer__info__s.html#o8">helo</a>) &gt; 0);
1445     01437 }
1446     01438
1447     01439
1448     01440 <span class="comment">/* SPF_smtp_from</span>
1449     01441 <span class="comment">*</span>
1450     01442 <span class="comment">* Author: James Couzens &lt;jcouzens@codeshare.ca&gt;</span>
1451     01443 <span class="comment">* Patrick Earl (http://patearl.net/)</span>
1452     01444 <span class="comment">*</span>
1453     01445 <span class="comment">* Date: 12/10/03</span>
1454     01446 <span class="comment">* Date: 12/25/03 James Couzens &lt;jcouzens@codeshare.ca&gt; (rewrite)</span>
1455     01447 <span class="comment">* Date: 02/04/04 Patrick Earl (http://patearl.net) (modified)</span>
1456     01448 <span class="comment">* Date: 02/05/04 Teddy &lt;teddy@teddy.ch&gt;</span>
1457     01449 <span class="comment">*</span>
1458     01450 <span class="comment">* Desc:</span>
1459     01451 <span class="comment">* Fetches the FROM from MTA and places into the global</span>
1460     01452 <span class="comment">* peer_info_t structure.</span>
1461     01453 <span class="comment">*</span>
1462     01454 <span class="comment">*</span>
1463     01455 <span class="comment">*/</span>
1464     <a name="l01456"></a><a class="code" href="spf_8h.html#a83">01456</a> <a class="code" href="spf_8h.html#a35">SPF_BOOL</a> <a class="code" href="spf_8h.html#a83">SPF_smtp_from</a>(<a class="code" href="structpeer__info__s.html">peer_info_t</a> *p, <span class="keyword">const</span> <span class="keywordtype">char</span> *s)
1465     01457 {
1466     01458 <span class="keywordtype">int</span> len; <span class="comment">/* utility */</span>
1467     01459
1468     01460 <span class="keywordtype">char</span> *pos; <span class="comment">/* position in string */</span>
1469     01461
1470     01462
1471     01463 <a class="code" href="util_8h.html#a6">xfree</a>(p-&gt;<a class="code" href="structpeer__info__s.html#o10">from</a>);
1472     01464 <a class="code" href="util_8h.html#a6">xfree</a>(p-&gt;<a class="code" href="structpeer__info__s.html#o15">current_domain</a>);
1473     01465
1474     01466 <span class="keywordflow">if</span> (s == NULL)
1475     01467 {
1476     01468 <span class="keywordflow">if</span> (*(p-&gt;<a class="code" href="structpeer__info__s.html#o8">helo</a>) == <span class="charliteral">'\0'</span>)
1477     01469 {
1478     01470 p-&gt;<a class="code" href="structpeer__info__s.html#o10">from</a> = <a class="code" href="util_8h.html#a8">xstrndup</a>(<span class="stringliteral">"unknown"</span>, 7);
1479     01471 }
1480     01472 <span class="keywordflow">else</span>
1481     01473 {
1482     01474 p-&gt;<a class="code" href="structpeer__info__s.html#o10">from</a> = <a class="code" href="util_8h.html#a8">xstrndup</a>(p-&gt;<a class="code" href="structpeer__info__s.html#o8">helo</a>, <a class="code" href="spf_8h.html#a13">SPF_MAX_ENV_HELO</a>);
1483     01475 }
1484     01476
1485     01477 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"NULL or invalid MAIL FROM rcvd. Using %s from now on.\n"</span>,
1486     01478 p-&gt;<a class="code" href="structpeer__info__s.html#o10">from</a> ? p-&gt;<a class="code" href="structpeer__info__s.html#o10">from</a> : p-&gt;<a class="code" href="structpeer__info__s.html#o8">helo</a>);
1487     01479
1488     01480 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a87a49">SPF_FALSE</a>);
1489     01481 }
1490     01482
1491     01483 p-&gt;<a class="code" href="structpeer__info__s.html#o10">from</a> = <a class="code" href="util_8h.html#a8">xstrndup</a>(s, <a class="code" href="spf_8h.html#a5">SPF_MAX_STR</a>);
1492     01484
1493     01485 <span class="comment">/* strips &lt; and &gt; from E-Mail-Address */</span>
1494     01486 <span class="keywordflow">if</span> (*p-&gt;<a class="code" href="structpeer__info__s.html#o10">from</a> == 60)
1495     01487 {
1496     01488 pos = p-&gt;<a class="code" href="structpeer__info__s.html#o10">from</a>;
1497     01489 (*(p-&gt;<a class="code" href="structpeer__info__s.html#o10">from</a> + strlen(p-&gt;<a class="code" href="structpeer__info__s.html#o10">from</a>) - 1)) = <span class="charliteral">'\0'</span>;
1498     01490 p-&gt;<a class="code" href="structpeer__info__s.html#o10">from</a>++;
1499     01491 p-&gt;<a class="code" href="structpeer__info__s.html#o10">from</a> = <a class="code" href="util_8h.html#a8">xstrndup</a>(p-&gt;<a class="code" href="structpeer__info__s.html#o10">from</a>, <a class="code" href="spf_8h.html#a5">SPF_MAX_STR</a>);
1500     01492
1501     01493 <a class="code" href="util_8h.html#a6">xfree</a>(pos);
1502     01494 }
1503     01495
1504     01496 <span class="keywordflow">if</span> (*p-&gt;<a class="code" href="structpeer__info__s.html#o10">from</a> == <span class="charliteral">'\0'</span>)
1505     01497 {
1506     01498 <span class="keywordflow">if</span> (*(p-&gt;<a class="code" href="structpeer__info__s.html#o8">helo</a>) == <span class="charliteral">'\0'</span>)
1507     01499 {
1508     01500 p-&gt;<a class="code" href="structpeer__info__s.html#o10">from</a> = <a class="code" href="util_8h.html#a8">xstrndup</a>(<span class="stringliteral">"unknown"</span>, 7);
1509     01501 }
1510     01502 <span class="keywordflow">else</span>
1511     01503 {
1512     01504 p-&gt;<a class="code" href="structpeer__info__s.html#o10">from</a> = <a class="code" href="util_8h.html#a8">xstrndup</a>(p-&gt;<a class="code" href="structpeer__info__s.html#o8">helo</a>, <a class="code" href="spf_8h.html#a13">SPF_MAX_ENV_HELO</a>);
1513     01505 }
1514     01506 }
1515     01507
1516     01508 pos = p-&gt;<a class="code" href="structpeer__info__s.html#o10">from</a>;
1517     01509
1518     01510 <a class="code" href="util_8h.html#a9">xprintf</a>(<span class="stringliteral">"MAIL-FROM: (%s) (called with: %s)\n"</span>, p-&gt;<a class="code" href="structpeer__info__s.html#o10">from</a>, s);
1519     01511
1520     01512 <span class="keywordflow">if</span> ((pos = strstr(pos, <span class="stringliteral">"@"</span>)) != NULL)
1521     01513 {
1522     01514 len = (pos - p-&gt;<a class="code" href="structpeer__info__s.html#o10">from</a>);
1523     01515
1524     01516 <span class="keywordflow">if</span> (len &gt;= <a class="code" href="spf_8h.html#a7">SPF_MAX_LOCAL_PART</a>)
1525     01517 {
1526     01518 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"%i is &gt;= %i causing data overrun\n"</span>, len, <a class="code" href="spf_8h.html#a7">SPF_MAX_LOCAL_PART</a>);
1527     01519 }
1528     01520
1529     01521 <span class="comment">/* Copy everything up to the @ into local_part. Do not include the @. */</span>
1530     01522 memcpy(p-&gt;<a class="code" href="structpeer__info__s.html#o21">local_part</a>, p-&gt;<a class="code" href="structpeer__info__s.html#o10">from</a>, len);
1531     01523 p-&gt;<a class="code" href="structpeer__info__s.html#o21">local_part</a>[len] = <span class="charliteral">'\0'</span>;
1532     01524
1533     01525 pos++; <span class="comment">/* skip past the @ */</span>
1534     01526 p-&gt;<a class="code" href="structpeer__info__s.html#o15">current_domain</a> = <a class="code" href="util_8h.html#a8">xstrndup</a>(pos, <a class="code" href="spf_8h.html#a5">SPF_MAX_STR</a>);
1535     01527
1536     01528 <a class="code" href="util_8h.html#a9">xprintf</a>(<span class="stringliteral">"Current domain: (%s)\n"</span>, p-&gt;<a class="code" href="structpeer__info__s.html#o15">current_domain</a>);
1537     01529
1538     01530 }
1539     01531 <span class="keywordflow">else</span>
1540     01532 {
1541     01533 snprintf(p-&gt;<a class="code" href="structpeer__info__s.html#o21">local_part</a>, 11, <span class="stringliteral">"postmaster"</span>);
1542     01534 p-&gt;<a class="code" href="structpeer__info__s.html#o15">current_domain</a> = <a class="code" href="util_8h.html#a8">xstrndup</a>(p-&gt;<a class="code" href="structpeer__info__s.html#o10">from</a>, <a class="code" href="spf_8h.html#a5">SPF_MAX_STR</a>);
1543     01535 }
1544     01536
1545     01537 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"local-part: (%s); domain: (%s); sender: (%s)\n"</span>,
1546     01538 p-&gt;<a class="code" href="structpeer__info__s.html#o21">local_part</a>, p-&gt;<a class="code" href="structpeer__info__s.html#o15">current_domain</a>, p-&gt;<a class="code" href="structpeer__info__s.html#o10">from</a>);
1547     01539
1548     01540 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a87a50">SPF_TRUE</a>);
1549     01541 }
1550     01542
1551     01543
1552     01544 <span class="comment">/* _SPF_clear_holdbufs</span>
1553     01545 <span class="comment">*</span>
1554     01546 <span class="comment">* Author: Travis Anderson &lt;tanderson@codeshare.ca&gt;</span>
1555     01547 <span class="comment">* Author: James Couzens &lt;jcouzens@codeshare.ca&gt;</span>
1556     01548 <span class="comment">*</span>
1557     01549 <span class="comment">* Date: 09/11/04 </span>
1558     01550 <span class="comment">*</span>
1559     01551 <span class="comment">* Desc:</span>
1560     01552 <span class="comment">* There are three possible 'holding' buffers that are used</span>
1561     01553 <span class="comment">* only after an original parse comes back negative (ie anything other</span>
1562     01554 <span class="comment">* that SPF_PASS), and this function simply goes through and free's</span>
1563     01555 <span class="comment">* any memory they might have associated and assigns them a NULL</span>
1564     01556 <span class="comment">* pointer.</span>
1565     01557 <span class="comment">*</span>
1566     01558 <span class="comment">* This function is *PRIVATE* and you will never need to call it, </span>
1567     01559 <span class="comment">* nor can it be referenced outside of this file, its purely</span>
1568     01560 <span class="comment">* written for the benefit for SPF_parse_policy when dealing with</span>
1569     01561 <span class="comment">* recursion for INCLUDE, REDIRECT, and CNAME.</span>
1570     01562 <span class="comment">*</span>
1571     01563 <span class="comment">*/</span>
1572     <a name="l01564"></a><a class="code" href="main_8c.html#a2">01564</a> <span class="keyword">static</span> <a class="code" href="spf_8h.html#a35">SPF_BOOL</a> <a class="code" href="main_8c.html#a2">_SPF_clear_holdbufs</a>(<a class="code" href="structpeer__info__s.html">peer_info_t</a> *p)
1573     01565 {
1574     01566 <span class="keywordflow">if</span> (p == NULL)
1575     01567 {
1576     01568 <a class="code" href="util_8h.html#a13">xepprintf</a>(<span class="stringliteral">"peer_info_t structure was NULL! Aborting!\n"</span>);
1577     01569
1578     01570 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a87a49">SPF_FALSE</a>);
1579     01571 }
1580     01572
1581     01573 <span class="keywordflow">if</span> (p-&gt;<a class="code" href="structpeer__info__s.html#o28">cname_buf</a> != NULL)
1582     01574 {
1583     01575 <a class="code" href="util_8h.html#a6">xfree</a>(p-&gt;<a class="code" href="structpeer__info__s.html#o28">cname_buf</a>);
1584     01576 p-&gt;<a class="code" href="structpeer__info__s.html#o28">cname_buf</a> = NULL;
1585     01577 }
1586     01578
1587     01579 <span class="keywordflow">if</span> (p-&gt;<a class="code" href="structpeer__info__s.html#o29">include_buf</a> != NULL)
1588     01580 {
1589     01581 <a class="code" href="util_8h.html#a6">xfree</a>(p-&gt;<a class="code" href="structpeer__info__s.html#o29">include_buf</a>);
1590     01582 p-&gt;<a class="code" href="structpeer__info__s.html#o29">include_buf</a> = NULL;
1591     01583 }
1592     01584
1593     01585 <span class="keywordflow">if</span> (p-&gt;<a class="code" href="structpeer__info__s.html#o30">redirect_buf</a>)
1594     01586 {
1595     01587 <a class="code" href="util_8h.html#a6">xfree</a>(p-&gt;<a class="code" href="structpeer__info__s.html#o30">redirect_buf</a>);
1596     01588 p-&gt;<a class="code" href="structpeer__info__s.html#o30">redirect_buf</a> = NULL;
1597     01589 }
1598     01590
1599     01591 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a87a50">SPF_TRUE</a>);
1600     01592 }
1601     01593
1602     01594 <span class="comment">/* end spf.c */</span>
1603     </div></pre><hr size="1"><address style="align: right;"><small>Generated on Thu Sep 16 18:10:46 2004 for libSPF v1.0 by
1604     <a href="http://www.doxygen.org/index.html">
1605     <img src="doxygen.png" alt="doxygen" align="middle" border=0 ></a> 1.3.8 </small></address>
1606     </body>
1607     </html>