| 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: spfquery.c Source File</title> |
| 4 |
|
|
<link href="doxygen.css" rel="stylesheet" type="text/css"> |
| 5 |
|
|
</head><body> |
| 6 |
|
|
<!-- Generated by Doxygen 1.3.7 --> |
| 7 |
|
|
<div class="qindex"> <form class="search" action="search.php" method="get"> |
| 8 |
|
|
<a class="qindex" href="main.html">Main Page</a> | <a class="qindex" href="annotated.html">Data Structures</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="functions.html">Data Fields</a> | <a class="qindex" href="globals.html">Globals</a> | <span class="search"><u>S</u>earch for <input class="search" type="text" name="query" value="" size="20" accesskey="s"/></span></form></div> |
| 9 |
|
|
<h1>spfquery.c</h1><a href="spfquery_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 <jcouzens@codeshare.ca></span> |
| 14 |
|
|
00006 <span class="comment">*</span> |
| 15 |
|
|
00007 <span class="comment">* File: spfquery.c</span> |
| 16 |
|
|
00008 <span class="comment">* Desc: SPF Query Tool (an example implementation of libSPF)</span> |
| 17 |
|
|
00009 <span class="comment">*</span> |
| 18 |
|
|
00010 <span class="comment">* License:</span> |
| 19 |
|
|
00011 <span class="comment">*</span> |
| 20 |
|
|
00012 <span class="comment">* The libspf Software License, Version 1.0</span> |
| 21 |
|
|
00013 <span class="comment">*</span> |
| 22 |
|
|
00014 <span class="comment">* Copyright (c) 2004 James Couzens & Sean Comeau All rights</span> |
| 23 |
|
|
00015 <span class="comment">* reserved.</span> |
| 24 |
|
|
00016 <span class="comment">*</span> |
| 25 |
|
|
00017 <span class="comment">* Redistribution and use in source and binary forms, with or without</span> |
| 26 |
|
|
00018 <span class="comment">* modification, are permitted provided that the following conditions</span> |
| 27 |
|
|
00019 <span class="comment">* are met:</span> |
| 28 |
|
|
00020 <span class="comment">*</span> |
| 29 |
|
|
00021 <span class="comment">* 1. Redistributions of source code must retain the above copyright</span> |
| 30 |
|
|
00022 <span class="comment">* notice, this list of conditions and the following disclaimer.</span> |
| 31 |
|
|
00023 <span class="comment">*</span> |
| 32 |
|
|
00024 <span class="comment">* 2. Redistributions in binary form must reproduce the above copyright</span> |
| 33 |
|
|
00025 <span class="comment">* notice, this list of conditions and the following disclaimer in</span> |
| 34 |
|
|
00026 <span class="comment">* the documentation and/or other materials provided with the</span> |
| 35 |
|
|
00027 <span class="comment">* distribution.</span> |
| 36 |
|
|
00028 <span class="comment">*</span> |
| 37 |
|
|
00029 <span class="comment">* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED</span> |
| 38 |
|
|
00030 <span class="comment">* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES</span> |
| 39 |
|
|
00031 <span class="comment">* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE</span> |
| 40 |
|
|
00032 <span class="comment">* DISCLAIMED. IN NO EVENT SHALL THE AUTHORS MAKING USE OF THIS LICESEN</span> |
| 41 |
|
|
00033 <span class="comment">* OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,</span> |
| 42 |
|
|
00034 <span class="comment">* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT</span> |
| 43 |
|
|
00035 <span class="comment">* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF</span> |
| 44 |
|
|
00036 <span class="comment">* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND</span> |
| 45 |
|
|
00037 <span class="comment">* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,</span> |
| 46 |
|
|
00038 <span class="comment">* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT</span> |
| 47 |
|
|
00039 <span class="comment">* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF</span> |
| 48 |
|
|
00040 <span class="comment">* SUCH DAMAGE.</span> |
| 49 |
|
|
00041 <span class="comment">*</span> |
| 50 |
|
|
00042 <span class="comment">*/</span> |
| 51 |
|
|
00043 |
| 52 |
|
|
00044 <span class="preprocessor">#include "<a class="code" href="spfquery_8h.html">spfquery.h</a>"</span> |
| 53 |
|
|
00045 |
| 54 |
|
|
00046 |
| 55 |
|
|
00047 <span class="comment">/* SPF_usage</span> |
| 56 |
|
|
00048 <span class="comment">*</span> |
| 57 |
|
|
00049 <span class="comment">* Author: James Couzens <jcouzens@6o4.ca></span> |
| 58 |
|
|
00050 <span class="comment">*</span> |
| 59 |
|
|
00051 <span class="comment">* Date: 07/04/04</span> |
| 60 |
|
|
00052 <span class="comment">*</span> |
| 61 |
|
|
00053 <span class="comment">* Desc:</span> |
| 62 |
|
|
00054 <span class="comment">* Main function, allocates memory and makes calls to the libSPF </span> |
| 63 |
|
|
00055 <span class="comment">* library which parses the "fake" query.</span> |
| 64 |
|
|
00056 <span class="comment">*</span> |
| 65 |
|
|
00057 <span class="comment">*/</span> |
| 66 |
|
|
<a name="l00058"></a><a class="code" href="spfquery_8h.html#a4">00058</a> <span class="keywordtype">int</span> <a class="code" href="spfquery_8h.html#a4">main</a>(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> *argv[]) |
| 67 |
|
|
00059 { |
| 68 |
|
|
00060 <a class="code" href="spf_8h.html#a35">u_int8_t</a> i = 0; <span class="comment">/* utility */</span> |
| 69 |
|
|
00061 <a class="code" href="spf_8h.html#a35">u_int8_t</a> res = 0; <span class="comment">/* libSPF result code */</span> |
| 70 |
|
|
00062 |
| 71 |
|
|
00063 <span class="keywordtype">char</span> *margv = NULL; <span class="comment">/* pointer to current argv element */</span> |
| 72 |
|
|
00064 <span class="keywordtype">char</span> *ip = NULL; <span class="comment">/* ip address to test connecting from */</span> |
| 73 |
|
|
00065 <span class="keywordtype">char</span> *address = NULL; <span class="comment">/* email address to test sending from */</span> |
| 74 |
|
|
00066 <span class="keywordtype">char</span> *helo = NULL; <span class="comment">/* helo hostname to test sending from */</span> |
| 75 |
|
|
00067 |
| 76 |
|
|
00068 <span class="keywordtype">char</span> *tmp = NULL; <span class="comment">/* utility pointer */</span> |
| 77 |
|
|
00069 |
| 78 |
|
|
00070 <a class="code" href="structpeer__info__s.html">peer_info_t</a> *pinfo = NULL; <span class="comment">/* libSPF peer_info structure */</span> |
| 79 |
|
|
00071 |
| 80 |
|
|
00072 <span class="keywordflow">if</span> (argc <= 1) |
| 81 |
|
|
00073 { |
| 82 |
|
|
00074 <a class="code" href="spfquery_8c.html#a1">SPF_usage</a>(); |
| 83 |
|
|
00075 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a92a53">FALSE</a>); |
| 84 |
|
|
00076 } |
| 85 |
|
|
00077 |
| 86 |
|
|
00078 <span class="keywordflow">for</span> (i = 1; i < argc; i++) |
| 87 |
|
|
00079 { |
| 88 |
|
|
00080 tmp = argv[i]; |
| 89 |
|
|
00081 |
| 90 |
|
|
00082 <span class="keywordflow">if</span> (*tmp == <span class="charliteral">'-'</span>) |
| 91 |
|
|
00083 { |
| 92 |
|
|
00084 margv = (tmp + 3); |
| 93 |
|
|
00085 |
| 94 |
|
|
00086 <span class="keywordflow">switch</span> (*(tmp + 1)) |
| 95 |
|
|
00087 { |
| 96 |
|
|
00088 <span class="keywordflow">case</span> <span class="charliteral">'d'</span> : |
| 97 |
|
|
00089 <a class="code" href="main_8c.html#a0">confg</a>.<a class="code" href="structspf__config__s.html#o0">level</a> = atoi(margv); |
| 98 |
|
|
00090 <span class="keywordflow">break</span>; |
| 99 |
|
|
00091 <span class="keywordflow">case</span> <span class="charliteral">'i'</span> : |
| 100 |
|
|
00092 ip = strdup(margv); |
| 101 |
|
|
00093 <span class="keywordflow">break</span>; |
| 102 |
|
|
00094 <span class="keywordflow">case</span> <span class="charliteral">'s'</span> : |
| 103 |
|
|
00095 address = strdup(margv); |
| 104 |
|
|
00096 <span class="keywordflow">break</span>; |
| 105 |
|
|
00097 <span class="keywordflow">case</span> <span class="charliteral">'h'</span> : |
| 106 |
|
|
00098 helo = strdup(margv); |
| 107 |
|
|
00099 <span class="keywordflow">break</span>; |
| 108 |
|
|
00100 } |
| 109 |
|
|
00101 } |
| 110 |
|
|
00102 } |
| 111 |
|
|
00103 |
| 112 |
|
|
00104 <span class="keywordflow">if</span> (ip == NULL) |
| 113 |
|
|
00105 { |
| 114 |
|
|
00106 printf(<span class="stringliteral">"You need to specify an IP Address to test against\n\n"</span>); |
| 115 |
|
|
00107 <a class="code" href="spfquery_8c.html#a1">SPF_usage</a>(); |
| 116 |
|
|
00108 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a92a53">FALSE</a>); |
| 117 |
|
|
00109 } |
| 118 |
|
|
00110 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (address == NULL) |
| 119 |
|
|
00111 { |
| 120 |
|
|
00112 printf(<span class="stringliteral">"You need to specify a from email address\n\n"</span>); |
| 121 |
|
|
00113 <a class="code" href="spfquery_8c.html#a1">SPF_usage</a>(); |
| 122 |
|
|
00114 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a92a53">FALSE</a>); |
| 123 |
|
|
00115 } |
| 124 |
|
|
00116 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (helo == NULL) |
| 125 |
|
|
00117 { |
| 126 |
|
|
00118 helo = strdup(<a class="code" href="spfquery_8h.html#a2">HELO_HOST</a>); |
| 127 |
|
|
00119 printf(<span class="stringliteral">"You didn't give me a helo host, using (%s)\n"</span>, helo); |
| 128 |
|
|
00120 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a92a53">FALSE</a>); |
| 129 |
|
|
00121 } |
| 130 |
|
|
00122 |
| 131 |
|
|
00123 <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#a0">confg</a>.<a class="code" href="structspf__config__s.html#o0">level</a> >= 1) |
| 132 |
|
|
00124 { |
| 133 |
|
|
00125 printf(<span class="stringliteral">"SPF Query v%s - James Couzens <jcouzens@codeshare.ca>\n\n"</span>, |
| 134 |
|
|
00126 <a class="code" href="spfquery_8h.html#a1">SPFQUERY_VERSION</a>); |
| 135 |
|
|
00127 |
| 136 |
|
|
00128 printf(<span class="stringliteral">"DEBUG: %u\n"</span>, <a class="code" href="main_8c.html#a0">confg</a>.<a class="code" href="structspf__config__s.html#o0">level</a>); |
| 137 |
|
|
00129 printf(<span class="stringliteral">"IP address: %s\n"</span>, ip); |
| 138 |
|
|
00130 printf(<span class="stringliteral">"MAIL FROM: %s\n"</span>, address); |
| 139 |
|
|
00131 printf(<span class="stringliteral">"HELO: %s\n"</span>, helo); |
| 140 |
|
|
00132 } |
| 141 |
|
|
00133 |
| 142 |
|
|
00134 <span class="keywordflow">if</span> ((pinfo = <a class="code" href="spf_8h.html#a82">SPF_init</a>(helo, ip, NULL, NULL, NULL, <a class="code" href="spf_8h.html#a92a53">FALSE</a>, <a class="code" href="spf_8h.html#a92a53">FALSE</a>)) != NULL) |
| 143 |
|
|
00135 { |
| 144 |
|
|
00136 <span class="comment">/* perform fake HELO */</span> |
| 145 |
|
|
00137 <a class="code" href="spf_8h.html#a89">SPF_smtp_helo</a>(pinfo, helo); |
| 146 |
|
|
00138 |
| 147 |
|
|
00139 <span class="comment">/* perform fake MAIL FROM */</span> |
| 148 |
|
|
00140 <a class="code" href="spf_8h.html#a88">SPF_smtp_from</a>(pinfo, address); |
| 149 |
|
|
00141 |
| 150 |
|
|
00142 <span class="comment">/* perform SPF parse */</span> |
| 151 |
|
|
00143 pinfo-><a class="code" href="structpeer__info__s.html#o3">RES</a> = <a class="code" href="spf_8h.html#a84">SPF_policy_main</a>(pinfo); |
| 152 |
|
|
00144 |
| 153 |
|
|
00145 <span class="comment">/* assign result of SPF parse */</span> |
| 154 |
|
|
00146 res = pinfo-><a class="code" href="structpeer__info__s.html#o3">RES</a>; |
| 155 |
|
|
00147 |
| 156 |
|
|
00148 <span class="comment">/* print the results */</span> |
| 157 |
|
|
00149 printf( <span class="stringliteral">"%s\n%s\n%s\n"</span>, |
| 158 |
|
|
00150 pinfo-><a class="code" href="structpeer__info__s.html#o5">rs</a> ? pinfo-><a class="code" href="structpeer__info__s.html#o5">rs</a> : <span class="stringliteral">"NULL"</span>, |
| 159 |
|
|
00151 pinfo-><a class="code" href="structpeer__info__s.html#o26">error</a> ? pinfo-><a class="code" href="structpeer__info__s.html#o26">error</a> : <span class="stringliteral">"NULL"</span>, |
| 160 |
|
|
00152 pinfo-><a class="code" href="structpeer__info__s.html#o12">explain</a> ? pinfo-><a class="code" href="structpeer__info__s.html#o12">explain</a> : <span class="stringliteral">"NULL"</span>); |
| 161 |
|
|
00153 |
| 162 |
|
|
00154 <span class="comment">/* close SPF session (free memory associated with parse) */</span> |
| 163 |
|
|
00155 <a class="code" href="spf_8h.html#a83">SPF_close</a>(pinfo); |
| 164 |
|
|
00156 |
| 165 |
|
|
00157 } |
| 166 |
|
|
00158 |
| 167 |
|
|
00159 free(ip); |
| 168 |
|
|
00160 free(address); |
| 169 |
|
|
00161 free(helo); |
| 170 |
|
|
00162 |
| 171 |
|
|
00163 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a92a53">FALSE</a>); |
| 172 |
|
|
00164 } |
| 173 |
|
|
00165 |
| 174 |
|
|
00166 |
| 175 |
|
|
00167 <span class="comment">/* SPF_usage</span> |
| 176 |
|
|
00168 <span class="comment">*</span> |
| 177 |
|
|
00169 <span class="comment">* Author: James Couzens <jcouzens@6o4.ca></span> |
| 178 |
|
|
00170 <span class="comment">*</span> |
| 179 |
|
|
00171 <span class="comment">* Date: 12/25/03</span> |
| 180 |
|
|
00172 <span class="comment">*</span> |
| 181 |
|
|
00173 <span class="comment">* Desc:</span> |
| 182 |
|
|
00174 <span class="comment">* Displays usage help information when the binary is called with</span> |
| 183 |
|
|
00175 <span class="comment">* no arguments.</span> |
| 184 |
|
|
00176 <span class="comment">*</span> |
| 185 |
|
|
00177 <span class="comment">*/</span> |
| 186 |
|
|
<a name="l00178"></a><a class="code" href="spfquery_8h.html#a5">00178</a> <span class="keywordtype">void</span> <a class="code" href="spfquery_8c.html#a1">SPF_usage</a>() |
| 187 |
|
|
00179 { |
| 188 |
|
|
00180 printf(<span class="stringliteral">"Usage:\n"</span>); |
| 189 |
|
|
00181 printf(<span class="stringliteral">"\n"</span>); |
| 190 |
|
|
00182 printf(<span class="stringliteral">"spfquery [dish]\n"</span>); |
| 191 |
|
|
00183 printf(<span class="stringliteral">"\n"</span>); |
| 192 |
|
|
00184 printf(<span class="stringliteral">"-d [x] - DEBUG where x is a number between 1 and 255\n"</span>); |
| 193 |
|
|
00185 printf(<span class="stringliteral">"-i [addr] - IP Address where the fake connection will come from\n"</span>); |
| 194 |
|
|
00186 printf(<span class="stringliteral">"-s [email] - What email address to test with\n"</span>); |
| 195 |
|
|
00187 printf(<span class="stringliteral">"-h [host] - HELO hostname to test with\n"</span>); |
| 196 |
|
|
00188 printf(<span class="stringliteral">"\n"</span>); |
| 197 |
|
|
00189 printf(<span class="stringliteral">"spfquery -i 10.0.0.2 -s jcouzens@6o4.ca -h spftools.net\n"</span>); |
| 198 |
|
|
00190 |
| 199 |
|
|
00191 <span class="keywordflow">return</span>; |
| 200 |
|
|
00192 } |
| 201 |
|
|
00193 |
| 202 |
|
|
00194 <span class="comment">/* end spfquery.c */</span> |
| 203 |
|
|
</div></pre><hr size="1"><address style="align: right;"><small>Generated on Sun Aug 8 11:36:48 2004 for libspf v1.0 by |
| 204 |
|
|
<a href="http://www.doxygen.org/index.html"> |
| 205 |
|
|
<img src="doxygen.png" alt="doxygen" align="middle" border=0 ></a> 1.3.7 </small></address> |
| 206 |
|
|
</body> |
| 207 |
|
|
</html> |