| 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: util.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 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>util.c</h1><a href="util_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">* Author: Sean Comeau <scomeau@obscurity.org></span> |
| 15 |
|
|
00007 <span class="comment">*</span> |
| 16 |
|
|
00008 <span class="comment">* File: util.c</span> |
| 17 |
|
|
00009 <span class="comment">* Desc: Utility functions</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 & 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 <pthread.h></span> <span class="comment">/* pthread_mutex_t */</span> |
| 55 |
|
|
00047 <span class="preprocessor">#endif </span><span class="comment">/* _WITH_PTHREADS */</span> |
| 56 |
|
|
00048 |
| 57 |
|
|
00049 <span class="preprocessor">#include "<a class="code" href="util_8h.html">util.h</a>"</span> <span class="comment">/* Utility functions */</span> |
| 58 |
|
|
00050 <span class="preprocessor">#include "<a class="code" href="dns_8h.html">dns.h</a>"</span> <span class="comment">/* DNS Functions */</span> |
| 59 |
|
|
00051 |
| 60 |
|
|
00052 <span class="preprocessor">#undef VERSION </span><span class="comment">/* autoconf */</span> |
| 61 |
|
|
00053 |
| 62 |
|
|
00054 |
| 63 |
|
|
00055 <span class="preprocessor">#ifdef _WITH_PTHREADS</span> |
| 64 |
|
|
00056 <span class="preprocessor"></span> <span class="comment">/*</span> |
| 65 |
|
|
00057 <span class="comment"> * pthread mutex used to facilitate reentrant competence within the</span> |
| 66 |
|
|
00058 <span class="comment"> * utility functions (generally the debugging functionality, you</span> |
| 67 |
|
|
00059 <span class="comment"> * could (after some poking around) probably safely remove this if</span> |
| 68 |
|
|
00060 <span class="comment"> * debugging was disabled)</span> |
| 69 |
|
|
00061 <span class="comment">*/</span> |
| 70 |
|
|
00062 pthread_mutex_t <a class="code" href="util_8c.html#a0">util_mutex</a>; |
| 71 |
|
|
00063 |
| 72 |
|
|
00064 <span class="preprocessor">#else</span> |
| 73 |
|
|
00065 <span class="preprocessor"></span><span class="comment">/* utility functions dummy pthread mutex wrapper */</span> |
| 74 |
|
|
<a name="l00066"></a><a class="code" href="util_8h.html#a23">00066</a> <span class="keywordtype">void</span> *<a class="code" href="util_8c.html#a0">util_mutex</a>; |
| 75 |
|
|
00067 |
| 76 |
|
|
00068 <span class="preprocessor">#endif </span><span class="comment">/* _WITH_PTHREADS */</span> |
| 77 |
|
|
00069 |
| 78 |
|
|
00070 |
| 79 |
|
|
00071 |
| 80 |
|
|
00072 <span class="comment">/*</span> |
| 81 |
|
|
00073 <span class="comment"> * globals</span> |
| 82 |
|
|
00074 <span class="comment"> *</span> |
| 83 |
|
|
00075 <span class="comment">*/</span> |
| 84 |
|
|
00076 |
| 85 |
|
|
00077 <span class="keyword">extern</span> <span class="keywordtype">int</span> <a class="code" href="util_8c.html#a1">errno</a>; |
| 86 |
|
|
00078 |
| 87 |
|
|
00079 |
| 88 |
|
|
00080 |
| 89 |
|
|
00081 <span class="comment">/* _pprintf_dbg</span> |
| 90 |
|
|
00082 <span class="comment">*</span> |
| 91 |
|
|
00083 <span class="comment">* Author: James Couzens <jcouzens@codeshare.ca></span> |
| 92 |
|
|
00084 <span class="comment">*</span> |
| 93 |
|
|
00085 <span class="comment">* Date: 09/08/04</span> |
| 94 |
|
|
00086 <span class="comment">*</span> |
| 95 |
|
|
00087 <span class="comment">* Desc:</span> |
| 96 |
|
|
00088 <span class="comment">* Handles debugging output when no variadic macro's are desired</span> |
| 97 |
|
|
00089 <span class="comment">* and the caller simply wishes to send a single string to output but</span> |
| 98 |
|
|
00090 <span class="comment">* wishes to have the appropriate function and other identifiers</span> |
| 99 |
|
|
00091 <span class="comment">* prepended.</span> |
| 100 |
|
|
00092 <span class="comment">*</span> |
| 101 |
|
|
00093 <span class="comment">* Referenced by xpprintf (formerly used for profile output)</span> |
| 102 |
|
|
00094 <span class="comment">* and xepprintf.</span> |
| 103 |
|
|
00095 <span class="comment">*</span> |
| 104 |
|
|
00096 <span class="comment">*/</span> |
| 105 |
|
|
<a name="l00097"></a><a class="code" href="util_8h.html#a25">00097</a> <span class="keywordtype">void</span> <a class="code" href="util_8h.html#a25">_pprintf_dbg</a>(u_int8_t level, <span class="keyword">const</span> <span class="keywordtype">char</span> *func, <span class="keyword">const</span> <span class="keywordtype">char</span> * file, |
| 106 |
|
|
00098 <span class="keyword">const</span> size_t line, <span class="keyword">const</span> <span class="keywordtype">char</span> *s) |
| 107 |
|
|
00099 { |
| 108 |
|
|
00100 <span class="keywordtype">char</span> *buf; <span class="comment">/* working buffer */</span> |
| 109 |
|
|
00101 |
| 110 |
|
|
00102 |
| 111 |
|
|
00103 <span class="keywordflow">if</span> (!s) |
| 112 |
|
|
00104 { |
| 113 |
|
|
00105 fprintf(stderr, <span class="stringliteral">"_eprintf_dbg passed a NULL string\n"</span>); |
| 114 |
|
|
00106 fflush(stderr); |
| 115 |
|
|
00107 |
| 116 |
|
|
00108 <span class="keywordflow">return</span>; |
| 117 |
|
|
00109 } |
| 118 |
|
|
00110 |
| 119 |
|
|
00111 buf = <a class="code" href="util_8h.html#a4">xmalloc</a>(<a class="code" href="spf_8h.html#a3">SPF_MAX_DEBUG</a> + 1); |
| 120 |
|
|
00112 snprintf(buf, <a class="code" href="spf_8h.html#a3">SPF_MAX_DEBUG</a>, <span class="stringliteral">"[%s :: %s->%i]; %s"</span>, func, file, line, s); |
| 121 |
|
|
00113 |
| 122 |
|
|
00114 <span class="keywordflow">if</span> (<a class="code" href="util_8h.html#a16">f_bit_set</a>(<a class="code" href="main_8c.html#a0">confg</a>.<a class="code" href="structspf__config__s.html#o0">level</a>, level)) |
| 123 |
|
|
00115 { |
| 124 |
|
|
00116 <span class="keywordflow">if</span> (level == <a class="code" href="main_8h.html#a4">FL_D</a>) <span class="comment">/* xpprintf */</span> |
| 125 |
|
|
00117 { |
| 126 |
|
|
00118 fprintf(stdout, buf); |
| 127 |
|
|
00119 fflush(stdout); |
| 128 |
|
|
00120 } |
| 129 |
|
|
00121 } |
| 130 |
|
|
00122 |
| 131 |
|
|
00123 <span class="keywordflow">if</span> (level == <a class="code" href="main_8h.html#a6">FL_F</a>) <span class="comment">/* xepprintf */</span> |
| 132 |
|
|
00124 { |
| 133 |
|
|
00125 fprintf(stderr, buf); |
| 134 |
|
|
00126 fflush(stderr); |
| 135 |
|
|
00127 } |
| 136 |
|
|
00128 |
| 137 |
|
|
00129 <a class="code" href="util_8h.html#a6">xfree</a>(buf); |
| 138 |
|
|
00130 |
| 139 |
|
|
00131 <span class="keywordflow">return</span>; |
| 140 |
|
|
00132 } |
| 141 |
|
|
00133 |
| 142 |
|
|
00134 |
| 143 |
|
|
00135 <span class="comment">/* _printf_dbg</span> |
| 144 |
|
|
00136 <span class="comment">*</span> |
| 145 |
|
|
00137 <span class="comment">* Author: James Couzens <jcouzens@codeshare.ca></span> |
| 146 |
|
|
00138 <span class="comment">*</span> |
| 147 |
|
|
00139 <span class="comment">* Date: 12/25/03</span> |
| 148 |
|
|
00140 <span class="comment">* Date: 02/18/04 (updated)</span> |
| 149 |
|
|
00141 <span class="comment">*</span> |
| 150 |
|
|
00142 <span class="comment">* Desc:</span> |
| 151 |
|
|
00143 <span class="comment">* Tied to a compile time switch this can instantly and at little</span> |
| 152 |
|
|
00144 <span class="comment">* to no real expense enable a discreet debugging with out hoards of</span> |
| 153 |
|
|
00145 <span class="comment">* #ifdefs all over the place.</span> |
| 154 |
|
|
00146 <span class="comment">*</span> |
| 155 |
|
|
00147 <span class="comment">* Date: 09/08/04 - James Couzens <jcouzens@codeshare.ca></span> |
| 156 |
|
|
00148 <span class="comment">*</span> |
| 157 |
|
|
00149 <span class="comment">* Desc:</span> |
| 158 |
|
|
00150 <span class="comment">* Modified to handle output for xeprintf (behaviour adjusted to call</span> |
| 159 |
|
|
00151 <span class="comment">* here instead) so that its actually clear where errors are being raised from.</span> |
| 160 |
|
|
00152 <span class="comment">*</span> |
| 161 |
|
|
00153 <span class="comment">*/</span> |
| 162 |
|
|
<a name="l00154"></a><a class="code" href="util_8h.html#a24">00154</a> <span class="keywordtype">void</span> <a class="code" href="util_8h.html#a24">_printf_dbg</a>(u_int8_t level, <span class="keyword">const</span> <span class="keywordtype">char</span> *func, <span class="keyword">const</span> <span class="keywordtype">char</span> *file, |
| 163 |
|
|
00155 <span class="keyword">const</span> size_t line, <span class="keyword">const</span> <span class="keywordtype">char</span> *format,...) |
| 164 |
|
|
00156 { |
| 165 |
|
|
00157 <span class="preprocessor">#ifdef _SPF_DEBUG_LOGFILE</span> |
| 166 |
|
|
00158 <span class="preprocessor"></span> FILE *fp = NULL; <span class="comment">/* file pointer */</span> |
| 167 |
|
|
00159 <span class="preprocessor">#endif </span><span class="comment">/* _SPF_DEBUG_LOGFILE */</span> |
| 168 |
|
|
00160 |
| 169 |
|
|
00161 <span class="keywordtype">char</span> *buf; <span class="comment">/* working buffer */</span> |
| 170 |
|
|
00162 <span class="keywordtype">char</span> *tbuf; <span class="comment">/* working buffer for eprintf */</span> |
| 171 |
|
|
00163 |
| 172 |
|
|
00164 va_list argptr; <span class="comment">/* pointer to current argument from array */</span> |
| 173 |
|
|
00165 |
| 174 |
|
|
00166 |
| 175 |
|
|
00167 <a class="code" href="util_8h.html#a14">xpthread_mutex_lock</a>(&<a class="code" href="util_8c.html#a0">util_mutex</a>); |
| 176 |
|
|
00168 |
| 177 |
|
|
00169 <span class="keywordflow">if</span> (!format || *format == <span class="charliteral">'\0'</span>) |
| 178 |
|
|
00170 { |
| 179 |
|
|
00171 fprintf(stderr, <span class="stringliteral">"_printf_dbg passed null format array\n"</span>); |
| 180 |
|
|
00172 fflush(stderr); |
| 181 |
|
|
00173 |
| 182 |
|
|
00174 <span class="keywordflow">return</span>; |
| 183 |
|
|
00175 } |
| 184 |
|
|
00176 |
| 185 |
|
|
00177 buf = <a class="code" href="util_8h.html#a4">xmalloc</a>(<a class="code" href="spf_8h.html#a3">SPF_MAX_DEBUG</a> + 1); |
| 186 |
|
|
00178 tbuf = <a class="code" href="util_8h.html#a4">xmalloc</a>(<a class="code" href="spf_8h.html#a3">SPF_MAX_DEBUG</a> + 1); |
| 187 |
|
|
00179 |
| 188 |
|
|
00180 va_start(argptr, format); |
| 189 |
|
|
00181 vsnprintf(buf, <a class="code" href="spf_8h.html#a3">SPF_MAX_DEBUG</a>, format, argptr); |
| 190 |
|
|
00182 va_end(argptr); |
| 191 |
|
|
00183 |
| 192 |
|
|
00184 snprintf(tbuf, <a class="code" href="spf_8h.html#a3">SPF_MAX_DEBUG</a>, <span class="stringliteral">"[%s :: %s->%i]; %s"</span>, func, file, line, buf); |
| 193 |
|
|
00185 |
| 194 |
|
|
00186 <span class="comment">/* xepprintf */</span> |
| 195 |
|
|
00187 <span class="keywordflow">if</span> (level == <a class="code" href="main_8h.html#a5">FL_E</a>) |
| 196 |
|
|
00188 { |
| 197 |
|
|
00189 fprintf(stderr, tbuf); |
| 198 |
|
|
00190 fflush(stderr); |
| 199 |
|
|
00191 } |
| 200 |
|
|
00192 <span class="keywordflow">else</span> |
| 201 |
|
|
00193 { |
| 202 |
|
|
00194 <span class="keywordflow">if</span> (<a class="code" href="util_8h.html#a16">f_bit_set</a>(<a class="code" href="main_8c.html#a0">confg</a>.<a class="code" href="structspf__config__s.html#o0">level</a>, level)) |
| 203 |
|
|
00195 { |
| 204 |
|
|
00196 <span class="preprocessor">#ifndef _SPF_DEBUG_LOGFILE</span> |
| 205 |
|
|
00197 <span class="preprocessor"></span> fprintf(stdout, tbuf); |
| 206 |
|
|
00198 fflush(stdout); |
| 207 |
|
|
00199 <span class="preprocessor">#else</span> |
| 208 |
|
|
00200 <span class="preprocessor"></span> <span class="keywordflow">if</span> ((fp = fopen(<a class="code" href="util_8h.html#a18">DEBUG_LOG_FILE</a>, <span class="stringliteral">"a"</span>)) != NULL) |
| 209 |
|
|
00201 { |
| 210 |
|
|
00202 fprintf(fp, <span class="stringliteral">"[%s :: %s->%i]; %s"</span>, func, file, line, buf); |
| 211 |
|
|
00203 fclose(fp); |
| 212 |
|
|
00204 } |
| 213 |
|
|
00205 <span class="keywordflow">else</span> |
| 214 |
|
|
00206 { |
| 215 |
|
|
00207 fprintf(stderr, <span class="stringliteral">"libSPF can't open file (%s) for writing!\n"</span>, |
| 216 |
|
|
00208 <a class="code" href="util_8h.html#a18">DEBUG_LOG_FILE</a>); |
| 217 |
|
|
00209 fflush(stderr); |
| 218 |
|
|
00210 perror(func); |
| 219 |
|
|
00211 } |
| 220 |
|
|
00212 <span class="preprocessor">#endif </span><span class="comment">/* _SPF_DEBUG_LOGFILE */</span> |
| 221 |
|
|
00213 } |
| 222 |
|
|
00214 } <span class="comment">/* else */</span> |
| 223 |
|
|
00215 |
| 224 |
|
|
00216 free(buf); |
| 225 |
|
|
00217 free(tbuf); |
| 226 |
|
|
00218 |
| 227 |
|
|
00219 <a class="code" href="util_8h.html#a15">xpthread_mutex_unlock</a>(&<a class="code" href="util_8c.html#a0">util_mutex</a>); |
| 228 |
|
|
00220 |
| 229 |
|
|
00221 <span class="keywordflow">return</span>; |
| 230 |
|
|
00222 } |
| 231 |
|
|
00223 |
| 232 |
|
|
00224 |
| 233 |
|
|
00225 <span class="preprocessor">#ifndef _SPF_DEBUG_LOGFILE</span> |
| 234 |
|
|
00226 <span class="preprocessor"></span><span class="comment">/* dummy_debug</span> |
| 235 |
|
|
00227 <span class="comment">*</span> |
| 236 |
|
|
00228 <span class="comment">* Author: James Couzens <jcouzens@codeshare.ca></span> |
| 237 |
|
|
00229 <span class="comment">*</span> |
| 238 |
|
|
00230 <span class="comment">* Date: 12/25/03</span> |
| 239 |
|
|
00231 <span class="comment">*</span> |
| 240 |
|
|
00232 <span class="comment">* Desc:</span> |
| 241 |
|
|
00233 <span class="comment">* dummy function thats used instead of the _printf_dbg function</span> |
| 242 |
|
|
00234 <span class="comment">* when compiling without debugging</span> |
| 243 |
|
|
00235 <span class="comment">*</span> |
| 244 |
|
|
00236 <span class="comment">*/</span> |
| 245 |
|
|
<a name="l00237"></a><a class="code" href="util_8h.html#a26">00237</a> <span class="keywordtype">void</span> <a class="code" href="util_8h.html#a26">_dummy_debug</a>(<span class="keyword">const</span> u_int8_t level, <span class="keyword">const</span> <span class="keywordtype">char</span> *func, <span class="keyword">const</span> <span class="keywordtype">char</span> *file, |
| 246 |
|
|
00238 <span class="keyword">const</span> size_t line, <span class="keyword">const</span> <span class="keywordtype">char</span> *format,...) |
| 247 |
|
|
00239 { |
| 248 |
|
|
00240 <span class="keywordflow">return</span>; |
| 249 |
|
|
00241 } |
| 250 |
|
|
00242 |
| 251 |
|
|
00243 |
| 252 |
|
|
00244 <span class="comment">/* dummy_debug</span> |
| 253 |
|
|
00245 <span class="comment">*</span> |
| 254 |
|
|
00246 <span class="comment">* Author: James Couzens <jcouzens@codeshare.ca></span> |
| 255 |
|
|
00247 <span class="comment">* </span> |
| 256 |
|
|
00248 <span class="comment">* Date: 12/25/03</span> |
| 257 |
|
|
00249 <span class="comment">* </span> |
| 258 |
|
|
00250 <span class="comment">* Desc:</span> |
| 259 |
|
|
00251 <span class="comment">* dummy function thats used instead of the _printf_dbg function</span> |
| 260 |
|
|
00252 <span class="comment">* when compiling without debugging</span> |
| 261 |
|
|
00253 <span class="comment">* </span> |
| 262 |
|
|
00254 <span class="comment">*/</span> |
| 263 |
|
|
<a name="l00255"></a><a class="code" href="util_8h.html#a27">00255</a> <span class="keywordtype">void</span> <a class="code" href="util_8h.html#a27">_dummy_pdebug</a>(<span class="keyword">const</span> u_int8_t level, <span class="keyword">const</span> <span class="keywordtype">char</span> *func, <span class="keyword">const</span> <span class="keywordtype">char</span> *file, |
| 264 |
|
|
00256 <span class="keyword">const</span> size_t line, <span class="keyword">const</span> <span class="keywordtype">char</span> *s) |
| 265 |
|
|
00257 { |
| 266 |
|
|
00258 <span class="keywordflow">return</span>; |
| 267 |
|
|
00259 } |
| 268 |
|
|
00260 |
| 269 |
|
|
00261 <span class="preprocessor">#endif</span> |
| 270 |
|
|
00262 <span class="preprocessor"></span> |
| 271 |
|
|
00263 |
| 272 |
|
|
00264 <span class="comment">/* UTIL_get_date</span> |
| 273 |
|
|
00265 <span class="comment">*</span> |
| 274 |
|
|
00266 <span class="comment">* Author: James Couzens <jcouzens@codeshare.ca></span> |
| 275 |
|
|
00267 <span class="comment">* Date: Sun Jan 18 06:02:13 PST 2004</span> |
| 276 |
|
|
00268 <span class="comment">*</span> |
| 277 |
|
|
00269 <span class="comment">* Desc:</span> |
| 278 |
|
|
00270 <span class="comment">* Returns in a buffer that must be freed by the caller, the date</span> |
| 279 |
|
|
00271 <span class="comment">* in the format YY-MM-DD HH:MM:SS and is derived from UTC time.</span> |
| 280 |
|
|
00272 <span class="comment">*</span> |
| 281 |
|
|
00273 <span class="comment">* Date: 09/08/04 - James Couzens <jcouzens@codeshare.ca></span> |
| 282 |
|
|
00274 <span class="comment">*</span> |
| 283 |
|
|
00275 <span class="comment">* Desc:</span> |
| 284 |
|
|
00276 <span class="comment">* Added pthread mutex lock during body of this function because it</span> |
| 285 |
|
|
00277 <span class="comment">* appears as those inspite of the use of localtime_r there is some un-safe</span> |
| 286 |
|
|
00278 <span class="comment">* behaviour that goes on here so for now the mutex here appears to solve</span> |
| 287 |
|
|
00279 <span class="comment">* the problem.</span> |
| 288 |
|
|
00280 <span class="comment">*</span> |
| 289 |
|
|
00281 <span class="comment">*/</span> |
| 290 |
|
|
<a name="l00282"></a><a class="code" href="util_8h.html#a32">00282</a> <span class="keywordtype">char</span> *<a class="code" href="util_8c.html#a6">UTIL_get_date</a>(<span class="keywordtype">void</span>) |
| 291 |
|
|
00283 { |
| 292 |
|
|
00284 <span class="keyword">struct </span>tm *now; <span class="comment">/* time in tm struct format */</span> |
| 293 |
|
|
00285 <span class="keyword">struct </span>tm tmbuf; <span class="comment">/* reentrant buffer for localtime_r */</span> |
| 294 |
|
|
00286 |
| 295 |
|
|
00287 time_t curtime; <span class="comment">/* current time time_t struct format */</span> |
| 296 |
|
|
00288 |
| 297 |
|
|
00289 <span class="keywordtype">char</span> *my_time; <span class="comment">/* time in human readable format */</span> |
| 298 |
|
|
00290 |
| 299 |
|
|
00291 |
| 300 |
|
|
00292 <a class="code" href="util_8h.html#a14">xpthread_mutex_lock</a>(&<a class="code" href="util_8c.html#a0">util_mutex</a>); |
| 301 |
|
|
00293 |
| 302 |
|
|
00294 curtime = time(NULL); |
| 303 |
|
|
00295 now = localtime_r(&curtime, &tmbuf); |
| 304 |
|
|
00296 my_time = <a class="code" href="util_8h.html#a4">xmalloc</a>(<a class="code" href="util_8h.html#a1">SPF_MAX_DATETIME</a>); |
| 305 |
|
|
00297 |
| 306 |
|
|
00298 strftime(my_time, <a class="code" href="util_8h.html#a1">SPF_MAX_DATETIME</a>, <span class="stringliteral">"%Y-%m-%d %H:%M:%S "</span>, now); |
| 307 |
|
|
00299 my_time[(<a class="code" href="util_8h.html#a1">SPF_MAX_DATETIME</a> - 1)] = <span class="charliteral">'\0'</span>; |
| 308 |
|
|
00300 |
| 309 |
|
|
00301 <a class="code" href="util_8h.html#a15">xpthread_mutex_unlock</a>(&<a class="code" href="util_8c.html#a0">util_mutex</a>); |
| 310 |
|
|
00302 |
| 311 |
|
|
00303 <span class="keywordflow">return</span>(my_time); |
| 312 |
|
|
00304 } |
| 313 |
|
|
00305 |
| 314 |
|
|
00306 |
| 315 |
|
|
00307 <span class="comment">/* UTIL_log_result</span> |
| 316 |
|
|
00308 <span class="comment">*</span> |
| 317 |
|
|
00309 <span class="comment">* Author: James Couzens <jcouzens@codeshare.ca></span> |
| 318 |
|
|
00310 <span class="comment">*</span> |
| 319 |
|
|
00311 <span class="comment">* Date: 02/04/04</span> |
| 320 |
|
|
00312 <span class="comment">*</span> |
| 321 |
|
|
00313 <span class="comment">* Desc:</span> |
| 322 |
|
|
00314 <span class="comment">* Tied to a compile time switch this can instantly and at little</span> |
| 323 |
|
|
00315 <span class="comment">* to no real expense enable a discreet debugging with out hoards of</span> |
| 324 |
|
|
00316 <span class="comment">* #ifdefs all over the place.</span> |
| 325 |
|
|
00317 <span class="comment">*</span> |
| 326 |
|
|
00318 <span class="comment">* Date: 09/08/04 - James Couzens <jcouzens@codeshare.ca></span> |
| 327 |
|
|
00319 <span class="comment">*</span> |
| 328 |
|
|
00320 <span class="comment">* Desc:</span> |
| 329 |
|
|
00321 <span class="comment">* Added pthread mutex lock during body of this function because it</span> |
| 330 |
|
|
00322 <span class="comment">* is to the detriment of stability to have multiple threads attempting to</span> |
| 331 |
|
|
00323 <span class="comment">* open/write/close the same file at the same time! :-)</span> |
| 332 |
|
|
00324 <span class="comment">*</span> |
| 333 |
|
|
00325 <span class="comment">*/</span> |
| 334 |
|
|
<a name="l00326"></a><a class="code" href="util_8h.html#a31">00326</a> <span class="keywordtype">void</span> <a class="code" href="util_8h.html#a31">UTIL_log_result</a>(<a class="code" href="structpeer__info__s.html">peer_info_t</a> *p) |
| 335 |
|
|
00327 { |
| 336 |
|
|
00328 FILE *fp = NULL; <span class="comment">/* file pointer */</span> |
| 337 |
|
|
00329 |
| 338 |
|
|
00330 <span class="keywordtype">char</span> *buf; <span class="comment">/* working buffer */</span> |
| 339 |
|
|
00331 <span class="keywordtype">char</span> *date; <span class="comment">/* date/time stamp */</span> |
| 340 |
|
|
00332 |
| 341 |
|
|
00333 |
| 342 |
|
|
00334 date = <a class="code" href="util_8c.html#a6">UTIL_get_date</a>(); |
| 343 |
|
|
00335 buf = <a class="code" href="util_8h.html#a4">xmalloc</a>(<a class="code" href="spf_8h.html#a3">SPF_MAX_DEBUG</a>); |
| 344 |
|
|
00336 *(date + (strlen(date) - 1)) = <span class="charliteral">'\0'</span>; |
| 345 |
|
|
00337 |
| 346 |
|
|
00338 <span class="keywordflow">if</span> (p-><a class="code" href="structpeer__info__s.html#o5">spf_ver</a> == 0) |
| 347 |
|
|
00339 { |
| 348 |
|
|
00340 p-><a class="code" href="structpeer__info__s.html#o5">spf_ver</a> = <a class="code" href="spf_8h.html#a1">SPF_VERSION</a>; |
| 349 |
|
|
00341 } |
| 350 |
|
|
00342 |
| 351 |
|
|
00343 <a class="code" href="util_8h.html#a14">xpthread_mutex_lock</a>(&<a class="code" href="util_8c.html#a0">util_mutex</a>); |
| 352 |
|
|
00344 |
| 353 |
|
|
00345 snprintf(buf, <a class="code" href="spf_8h.html#a3">SPF_MAX_DEBUG</a>, |
| 354 |
|
|
00346 <span class="stringliteral">"[%s] result: %s :: %s [%s], ver: %i, depth: %i, error: (%s)\n"</span>, |
| 355 |
|
|
00347 date, p-><a class="code" href="structpeer__info__s.html#o25">spf_result</a>[p-><a class="code" href="structpeer__info__s.html#o1">RES</a>].s, p-><a class="code" href="structpeer__info__s.html#o10">from</a>, |
| 356 |
|
|
00348 p-><a class="code" href="structpeer__info__s.html#o17">r_ip</a>, p-><a class="code" href="structpeer__info__s.html#o27">spf_rlevel</a>, p-><a class="code" href="structpeer__info__s.html#o5">spf_ver</a>, p-><a class="code" href="structpeer__info__s.html#o24">error</a>); |
| 357 |
|
|
00349 |
| 358 |
|
|
00350 <span class="keywordflow">if</span> ((fp = fopen(<a class="code" href="util_8h.html#a19">OUTPUT_LOG_FILE</a>, <span class="stringliteral">"a"</span>)) != NULL) |
| 359 |
|
|
00351 { |
| 360 |
|
|
00352 fprintf(fp, <span class="stringliteral">"%s"</span>, buf); |
| 361 |
|
|
00353 fclose(fp); |
| 362 |
|
|
00354 } |
| 363 |
|
|
00355 |
| 364 |
|
|
00356 <a class="code" href="util_8h.html#a15">xpthread_mutex_unlock</a>(&<a class="code" href="util_8c.html#a0">util_mutex</a>); |
| 365 |
|
|
00357 |
| 366 |
|
|
00358 <a class="code" href="util_8h.html#a6">xfree</a>(date); |
| 367 |
|
|
00359 <a class="code" href="util_8h.html#a6">xfree</a>(buf); |
| 368 |
|
|
00360 |
| 369 |
|
|
00361 <span class="keywordflow">return</span>; |
| 370 |
|
|
00362 } |
| 371 |
|
|
00363 |
| 372 |
|
|
00364 |
| 373 |
|
|
00365 <span class="comment">/* xstrndup</span> |
| 374 |
|
|
00366 <span class="comment">*</span> |
| 375 |
|
|
00367 <span class="comment">* Author: James Couzens <jcouzens@codeshare.ca></span> |
| 376 |
|
|
00368 <span class="comment">*</span> |
| 377 |
|
|
00369 <span class="comment">* Date: 12/25/03</span> |
| 378 |
|
|
00370 <span class="comment">*</span> |
| 379 |
|
|
00371 <span class="comment">* Desc:</span> |
| 380 |
|
|
00372 <span class="comment">* n bytes are allocated and then filled with \0 chars. Char s</span> |
| 381 |
|
|
00373 <span class="comment">* is copied over to the allocated memory writing n -1 bytes leaving the</span> |
| 382 |
|
|
00374 <span class="comment">* new string NULL terminated. This new string is returned upon success</span> |
| 383 |
|
|
00375 <span class="comment">* and NULL upon failure.</span> |
| 384 |
|
|
00376 <span class="comment">*</span> |
| 385 |
|
|
00377 <span class="comment">*/</span> |
| 386 |
|
|
<a name="l00378"></a><a class="code" href="util_8h.html#a33">00378</a> <span class="keywordtype">char</span> *<a class="code" href="util_8h.html#a33">UTIL_strndup</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> *s, <span class="keyword">const</span> size_t n) |
| 387 |
|
|
00379 { |
| 388 |
|
|
00380 <span class="keywordtype">char</span> *ret_ptr = NULL; <span class="comment">/* return buffer */</span> |
| 389 |
|
|
00381 |
| 390 |
|
|
00382 |
| 391 |
|
|
00383 <span class="keywordflow">if</span> ((s == NULL) || (n <= 0)) |
| 392 |
|
|
00384 { |
| 393 |
|
|
00385 <a class="code" href="util_8h.html#a13">xepprintf</a>(<span class="stringliteral">"Passed string is NULL. Abort!.\n"</span>); |
| 394 |
|
|
00386 |
| 395 |
|
|
00387 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a87a49">SPF_FALSE</a>); |
| 396 |
|
|
00388 } |
| 397 |
|
|
00389 |
| 398 |
|
|
00390 ret_ptr = <a class="code" href="util_8h.html#a4">xmalloc</a>(n + 1); |
| 399 |
|
|
00391 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"Allocated %u bytes of memory.\n"</span>, n); |
| 400 |
|
|
00392 snprintf(ret_ptr, n, s); |
| 401 |
|
|
00393 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"leaving function; returning string: (%s)\n"</span>, ret_ptr); |
| 402 |
|
|
00394 |
| 403 |
|
|
00395 <span class="keywordflow">return</span>(ret_ptr); |
| 404 |
|
|
00396 } |
| 405 |
|
|
00397 |
| 406 |
|
|
00398 |
| 407 |
|
|
00399 <span class="comment">/* xstrdup</span> |
| 408 |
|
|
00400 <span class="comment">*</span> |
| 409 |
|
|
00401 <span class="comment">* Author: Patrick Earl (http://patearl.net/)</span> |
| 410 |
|
|
00402 <span class="comment">* Adapted from xstrndup()</span> |
| 411 |
|
|
00403 <span class="comment">*</span> |
| 412 |
|
|
00404 <span class="comment">* Date: 02/04/04</span> |
| 413 |
|
|
00405 <span class="comment">*</span> |
| 414 |
|
|
00406 <span class="comment">* Desc:</span> |
| 415 |
|
|
00407 <span class="comment">* strlen(s)+1 bytes are allocated and s is copied into the</span> |
| 416 |
|
|
00408 <span class="comment">* freshly allocated memory. If the allocation or copy fails, NULL</span> |
| 417 |
|
|
00409 <span class="comment">* NULL will be returned.</span> |
| 418 |
|
|
00410 <span class="comment">*</span> |
| 419 |
|
|
00411 <span class="comment">*/</span> |
| 420 |
|
|
<a name="l00412"></a><a class="code" href="util_8h.html#a34">00412</a> <span class="keywordtype">char</span> *<a class="code" href="util_8h.html#a34">UTIL_strdup</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> *s) |
| 421 |
|
|
00413 { |
| 422 |
|
|
00414 <span class="keywordtype">char</span> *ret_ptr = NULL; <span class="comment">/* return buffer */</span> |
| 423 |
|
|
00415 |
| 424 |
|
|
00416 |
| 425 |
|
|
00417 <span class="keywordflow">if</span> (s == NULL) |
| 426 |
|
|
00418 { |
| 427 |
|
|
00419 <a class="code" href="util_8h.html#a13">xepprintf</a>(<span class="stringliteral">"Passed string is NULL. Abort!.\n"</span>); |
| 428 |
|
|
00420 |
| 429 |
|
|
00421 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a87a49">SPF_FALSE</a>); |
| 430 |
|
|
00422 } |
| 431 |
|
|
00423 |
| 432 |
|
|
00424 <span class="keywordflow">if</span> ((ret_ptr = strdup(s)) == NULL) |
| 433 |
|
|
00425 { |
| 434 |
|
|
00426 <a class="code" href="util_8h.html#a13">xepprintf</a>(<span class="stringliteral">"Unable to allocate memory\n"</span>); |
| 435 |
|
|
00427 } |
| 436 |
|
|
00428 |
| 437 |
|
|
00429 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"leaving function; returning string: (%s)\n"</span>, ret_ptr); |
| 438 |
|
|
00430 |
| 439 |
|
|
00431 <span class="keywordflow">return</span>(ret_ptr); |
| 440 |
|
|
00432 } |
| 441 |
|
|
00433 |
| 442 |
|
|
00434 |
| 443 |
|
|
00435 <span class="comment">/* UTIL_malloc</span> |
| 444 |
|
|
00436 <span class="comment">*</span> |
| 445 |
|
|
00437 <span class="comment">* Author: Travis Anderson <travis@anthrax.ca></span> |
| 446 |
|
|
00438 <span class="comment">* Author: James Couzens <jcouzens@codeshare.ca></span> |
| 447 |
|
|
00439 <span class="comment">*</span> |
| 448 |
|
|
00440 <span class="comment">* Date: 02/17/04</span> |
| 449 |
|
|
00441 <span class="comment">*</span> |
| 450 |
|
|
00442 <span class="comment">* Desc:</span> |
| 451 |
|
|
00443 <span class="comment">* Wrapper for malloc. Upon success, behaves as malloc does.</span> |
| 452 |
|
|
00444 <span class="comment">* Wrapper functionality is to print an error message and exit upon failure.</span> |
| 453 |
|
|
00445 <span class="comment">*</span> |
| 454 |
|
|
00446 <span class="comment">*/</span> |
| 455 |
|
|
<a name="l00447"></a><a class="code" href="util_8h.html#a28">00447</a> <span class="keywordtype">void</span> *<a class="code" href="util_8h.html#a28">UTIL_malloc</a>(<span class="keyword">const</span> int32_t n, <span class="keyword">const</span> <span class="keywordtype">char</span> *file, int32_t line, |
| 456 |
|
|
00448 <span class="keyword">const</span> <span class="keywordtype">char</span> *func) |
| 457 |
|
|
00449 { |
| 458 |
|
|
00450 <span class="keywordtype">void</span> *x = malloc(n); |
| 459 |
|
|
00451 |
| 460 |
|
|
00452 <span class="keywordflow">if</span> (x == NULL) |
| 461 |
|
|
00453 { |
| 462 |
|
|
00454 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"Unable to allocate %i bytes at %s:%i in %s\n"</span>, |
| 463 |
|
|
00455 n, file, line, func); |
| 464 |
|
|
00456 |
| 465 |
|
|
00457 <span class="comment">/*</span> |
| 466 |
|
|
00458 <span class="comment"> * Be advised this is the only place I do this, because quite</span> |
| 467 |
|
|
00459 <span class="comment"> * honestly, if this library can't get a few bytes of memory,</span> |
| 468 |
|
|
00460 <span class="comment"> * your mailserver segfaulting as a result of this exit, or </span> |
| 469 |
|
|
00461 <span class="comment"> * quitting or whatever is the LEAST of your problems!</span> |
| 470 |
|
|
00462 <span class="comment"> */</span> |
| 471 |
|
|
00463 exit(0); |
| 472 |
|
|
00464 } |
| 473 |
|
|
00465 |
| 474 |
|
|
00466 memset(x, <span class="charliteral">'\0'</span>, n); |
| 475 |
|
|
00467 |
| 476 |
|
|
00468 <span class="keywordflow">return</span>(x); |
| 477 |
|
|
00469 } |
| 478 |
|
|
00470 |
| 479 |
|
|
00471 |
| 480 |
|
|
00472 <span class="comment">/* UTIL_realloc</span> |
| 481 |
|
|
00473 <span class="comment">*</span> |
| 482 |
|
|
00474 <span class="comment">* Author: Travis Anderson <travis@anthrax.ca></span> |
| 483 |
|
|
00475 <span class="comment">* Author: James Couzens <jcouzens@codeshare.ca></span> |
| 484 |
|
|
00476 <span class="comment">*</span> |
| 485 |
|
|
00477 <span class="comment">* Date: 02/17/04</span> |
| 486 |
|
|
00478 <span class="comment">*</span> |
| 487 |
|
|
00479 <span class="comment">* Desc:</span> |
| 488 |
|
|
00480 <span class="comment">* Wrapper for realloc. If 'p' is NULL, allocates memory via a call to</span> |
| 489 |
|
|
00481 <span class="comment">* UTIL_malloc, otherwise if 'x' is assigned successfully, the behaviour is</span> |
| 490 |
|
|
00482 <span class="comment">* identical to realloc. Wrapper functionality is to print an error message</span> |
| 491 |
|
|
00483 <span class="comment">* and exit upon failure.</span> |
| 492 |
|
|
00484 <span class="comment">*</span> |
| 493 |
|
|
00485 <span class="comment">*/</span> |
| 494 |
|
|
<a name="l00486"></a><a class="code" href="util_8h.html#a29">00486</a> <span class="keywordtype">void</span> *<a class="code" href="util_8h.html#a29">UTIL_realloc</a>(<span class="keywordtype">void</span> *p, <span class="keyword">const</span> int32_t n, <span class="keyword">const</span> <span class="keywordtype">char</span> *file, |
| 495 |
|
|
00487 <span class="keyword">const</span> int32_t line, <span class="keyword">const</span> <span class="keywordtype">char</span> *func) |
| 496 |
|
|
00488 { |
| 497 |
|
|
00489 <span class="keywordtype">void</span> *x = NULL; |
| 498 |
|
|
00490 |
| 499 |
|
|
00491 <span class="keywordflow">if</span> (p == NULL) |
| 500 |
|
|
00492 { |
| 501 |
|
|
00493 <span class="keywordflow">return</span>(<a class="code" href="util_8h.html#a28">UTIL_malloc</a>(n, file, line, func)); |
| 502 |
|
|
00494 } |
| 503 |
|
|
00495 |
| 504 |
|
|
00496 x = realloc(p, n); |
| 505 |
|
|
00497 <span class="keywordflow">if</span> (x == NULL) |
| 506 |
|
|
00498 { |
| 507 |
|
|
00499 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"Unable to reallocate %i bytes at %s:%i in %s; "</span> \ |
| 508 |
|
|
00500 <span class="stringliteral">"original address 0x%x\n"</span>, n, file, line, func, (uintptr_t)p); |
| 509 |
|
|
00501 |
| 510 |
|
|
00502 exit(0); |
| 511 |
|
|
00503 } |
| 512 |
|
|
00504 |
| 513 |
|
|
00505 <span class="keywordflow">return</span>(x); |
| 514 |
|
|
00506 } |
| 515 |
|
|
00507 |
| 516 |
|
|
00508 |
| 517 |
|
|
00509 <span class="comment">/* UTIL_free</span> |
| 518 |
|
|
00510 <span class="comment">*</span> |
| 519 |
|
|
00511 <span class="comment">* Author: Travis Anderson <travis@anthrax.ca></span> |
| 520 |
|
|
00512 <span class="comment">* Author: James Couzens <jcouzens@codeshare.ca></span> |
| 521 |
|
|
00513 <span class="comment">*</span> |
| 522 |
|
|
00514 <span class="comment">* Date: 02/17/04</span> |
| 523 |
|
|
00515 <span class="comment">*</span> |
| 524 |
|
|
00516 <span class="comment">* Desc:</span> |
| 525 |
|
|
00517 <span class="comment">* Wrapper for free. Upon success, behaves as free does.</span> |
| 526 |
|
|
00518 <span class="comment">* Wrapper functionality is to print an error message and exit upon</span> |
| 527 |
|
|
00519 <span class="comment">* failure.</span> |
| 528 |
|
|
00520 <span class="comment">*</span> |
| 529 |
|
|
00521 <span class="comment">*/</span> |
| 530 |
|
|
<a name="l00522"></a><a class="code" href="util_8h.html#a30">00522</a> <span class="keywordtype">void</span> <a class="code" href="util_8h.html#a30">UTIL_free</a>(<span class="keywordtype">void</span> *p, <span class="keyword">const</span> <span class="keywordtype">char</span> *file, <span class="keyword">const</span> int32_t line, <span class="keyword">const</span> <span class="keywordtype">char</span> *func) |
| 531 |
|
|
00523 { |
| 532 |
|
|
00524 <span class="keywordflow">if</span> (p == NULL) |
| 533 |
|
|
00525 { |
| 534 |
|
|
00526 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"Unable to free() on NULL pointer at %s:%i in %s; "</span> \ |
| 535 |
|
|
00527 <span class="stringliteral">"address 0x%x.\n"</span>, file, line, func, (uintptr_t)p); |
| 536 |
|
|
00528 |
| 537 |
|
|
00529 <span class="keywordflow">return</span>; |
| 538 |
|
|
00530 } |
| 539 |
|
|
00531 |
| 540 |
|
|
00532 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"Free address 0x%x by %s on line %i (%s)\n"</span>, |
| 541 |
|
|
00533 (uintptr_t)p, func, line, file); |
| 542 |
|
|
00534 |
| 543 |
|
|
00535 free(p); |
| 544 |
|
|
00536 |
| 545 |
|
|
00537 <span class="keywordflow">return</span>; |
| 546 |
|
|
00538 } |
| 547 |
|
|
00539 |
| 548 |
|
|
00540 |
| 549 |
|
|
00541 <span class="comment">/* UTIL_index</span> |
| 550 |
|
|
00542 <span class="comment">*</span> |
| 551 |
|
|
00543 <span class="comment">* Author: James Couzens <jcouzens@codeshare.ca></span> |
| 552 |
|
|
00544 <span class="comment">*</span> |
| 553 |
|
|
00545 <span class="comment">* Date: 12/19/03</span> |
| 554 |
|
|
00546 <span class="comment">*</span> |
| 555 |
|
|
00547 <span class="comment">* Desc:</span> |
| 556 |
|
|
00548 <span class="comment">* s is walked until c is found, at which time i is returned</span> |
| 557 |
|
|
00549 <span class="comment">* which is the number of bytes from the left it walked until c was</span> |
| 558 |
|
|
00550 <span class="comment">* found (not including c its self);</span> |
| 559 |
|
|
00551 <span class="comment">*</span> |
| 560 |
|
|
00552 <span class="comment">* Date: 09/01/04 - Roger Moser</span> |
| 561 |
|
|
00553 <span class="comment">*</span> |
| 562 |
|
|
00554 <span class="comment">* Desc:</span> |
| 563 |
|
|
00555 <span class="comment">* The return upon an error (s being NULL for exmaple) is now</span> |
| 564 |
|
|
00556 <span class="comment">* -1 because returning 0 was really ambiguous.</span> |
| 565 |
|
|
00557 <span class="comment">*</span> |
| 566 |
|
|
00558 <span class="comment">* Returns: -1 upon error</span> |
| 567 |
|
|
00559 <span class="comment">* Returns: 0 upon no match</span> |
| 568 |
|
|
00560 <span class="comment">* Returns: > 0 upon success which is the number of bytes from the left</span> |
| 569 |
|
|
00561 <span class="comment">* the string was walked until 'c' was found.</span> |
| 570 |
|
|
00562 <span class="comment">*</span> |
| 571 |
|
|
00563 <span class="comment">*/</span> |
| 572 |
|
|
<a name="l00564"></a><a class="code" href="util_8h.html#a35">00564</a> int16_t <a class="code" href="util_8h.html#a35">UTIL_index</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> *s, <span class="keyword">const</span> <span class="keywordtype">char</span> c) |
| 573 |
|
|
00565 { |
| 574 |
|
|
00566 int16_t i; <span class="comment">/* utility */</span> |
| 575 |
|
|
00567 |
| 576 |
|
|
00568 |
| 577 |
|
|
00569 <span class="keywordflow">if</span> (s == NULL) |
| 578 |
|
|
00570 { |
| 579 |
|
|
00571 <a class="code" href="util_8h.html#a13">xepprintf</a>(<span class="stringliteral">"passed a NULL string. Abort!\n"</span>); |
| 580 |
|
|
00572 |
| 581 |
|
|
00573 <span class="keywordflow">return</span>(-1); |
| 582 |
|
|
00574 } |
| 583 |
|
|
00575 |
| 584 |
|
|
00576 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"called with string: (%s); char: %c\n"</span>, s, c); |
| 585 |
|
|
00577 |
| 586 |
|
|
00578 i = 0; |
| 587 |
|
|
00579 <span class="keywordflow">while</span> (*s) |
| 588 |
|
|
00580 { |
| 589 |
|
|
00581 <span class="keywordflow">if</span> (*s == c) |
| 590 |
|
|
00582 { |
| 591 |
|
|
00583 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"Found search char: (%c); Returning: (%i)\n"</span>, *s, i); |
| 592 |
|
|
00584 |
| 593 |
|
|
00585 <span class="keywordflow">return</span>(i); |
| 594 |
|
|
00586 } |
| 595 |
|
|
00587 i++; |
| 596 |
|
|
00588 s++; |
| 597 |
|
|
00589 } |
| 598 |
|
|
00590 |
| 599 |
|
|
00591 <a class="code" href="util_8h.html#a11">xpprintf</a>(<span class="stringliteral">"leaving function\n"</span>); |
| 600 |
|
|
00592 |
| 601 |
|
|
00593 <span class="keywordflow">return</span>(0); |
| 602 |
|
|
00594 } |
| 603 |
|
|
00595 |
| 604 |
|
|
00596 |
| 605 |
|
|
00597 <span class="comment">/* UTIL_split_str</span> |
| 606 |
|
|
00598 <span class="comment">*</span> |
| 607 |
|
|
00599 <span class="comment">* Author: James Couzens <jcouzens@codeshare.ca></span> |
| 608 |
|
|
00600 <span class="comment">*</span> |
| 609 |
|
|
00601 <span class="comment">* Date: 01/21/04</span> |
| 610 |
|
|
00602 <span class="comment">*</span> |
| 611 |
|
|
00603 <span class="comment">* Desc:</span> |
| 612 |
|
|
00604 <span class="comment">* s is walked through to find 'delim' until it finds 'delim'</span> |
| 613 |
|
|
00605 <span class="comment">* num times. Upon final match it returns the remainder of the string</span> |
| 614 |
|
|
00606 <span class="comment">* in a newly allocated buffer. Upon failure returns NULL.</span> |
| 615 |
|
|
00607 <span class="comment">*</span> |
| 616 |
|
|
00608 <span class="comment">* Date: 09/01/04 - Roger Moser</span> |
| 617 |
|
|
00609 <span class="comment">* </span> |
| 618 |
|
|
00610 <span class="comment">* Desc:</span> |
| 619 |
|
|
00611 <span class="comment">* 'cp' was not being freed upon exiting the function when 'c'</span> |
| 620 |
|
|
00612 <span class="comment">* was not found within the string.</span> |
| 621 |
|
|
00613 <span class="comment">*</span> |
| 622 |
|
|
00614 <span class="comment">*/</span> |
| 623 |
|
|
<a name="l00615"></a><a class="code" href="util_8h.html#a36">00615</a> <span class="keywordtype">char</span> *<a class="code" href="util_8h.html#a36">UTIL_split_str</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> *s, <span class="keyword">const</span> <span class="keywordtype">char</span> c, <span class="keyword">const</span> u_int8_t num) |
| 624 |
|
|
00616 { |
| 625 |
|
|
00617 u_int8_t i; <span class="comment">/* utility */</span> |
| 626 |
|
|
00618 |
| 627 |
|
|
00619 <span class="keywordtype">char</span> *cp; <span class="comment">/* copy buffer of s */</span> |
| 628 |
|
|
00620 <span class="keywordtype">char</span> *p; <span class="comment">/* pointer to copy */</span> |
| 629 |
|
|
00621 <span class="keywordtype">char</span> *ret; <span class="comment">/* return buffer */</span> |
| 630 |
|
|
00622 |
| 631 |
|
|
00623 |
| 632 |
|
|
00624 <span class="keywordflow">if</span> (s == NULL) |
| 633 |
|
|
00625 { |
| 634 |
|
|
00626 <a class="code" href="util_8h.html#a13">xepprintf</a>(<span class="stringliteral">"passed a NULL string. Abort!\n"</span>); |
| 635 |
|
|
00627 |
| 636 |
|
|
00628 <span class="keywordflow">return</span>(NULL); |
| 637 |
|
|
00629 } |
| 638 |
|
|
00630 |
| 639 |
|
|
00631 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"called with string: (%s); char (%c); int: (%i)\n"</span>, |
| 640 |
|
|
00632 s, c, num); |
| 641 |
|
|
00633 |
| 642 |
|
|
00634 p = cp = <a class="code" href="util_8h.html#a8">xstrndup</a>(s, <a class="code" href="spf_8h.html#a5">SPF_MAX_STR</a>); |
| 643 |
|
|
00635 |
| 644 |
|
|
00636 i = 0; |
| 645 |
|
|
00637 <span class="keywordflow">while</span>(*p) |
| 646 |
|
|
00638 { |
| 647 |
|
|
00639 <span class="keywordflow">if</span> (*p == c) |
| 648 |
|
|
00640 { |
| 649 |
|
|
00641 i++; |
| 650 |
|
|
00642 <span class="keywordflow">if</span> (i == num) |
| 651 |
|
|
00643 { |
| 652 |
|
|
00644 p++; |
| 653 |
|
|
00645 ret = <a class="code" href="util_8h.html#a8">xstrndup</a>(p, <a class="code" href="spf_8h.html#a5">SPF_MAX_STR</a>); |
| 654 |
|
|
00646 |
| 655 |
|
|
00647 <a class="code" href="util_8h.html#a6">xfree</a>(cp); |
| 656 |
|
|
00648 |
| 657 |
|
|
00649 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"returning: %s\n"</span>, ret); |
| 658 |
|
|
00650 |
| 659 |
|
|
00651 <span class="keywordflow">return</span>(ret); |
| 660 |
|
|
00652 } |
| 661 |
|
|
00653 } |
| 662 |
|
|
00654 p++; |
| 663 |
|
|
00655 } |
| 664 |
|
|
00656 |
| 665 |
|
|
00657 <a class="code" href="util_8h.html#a6">xfree</a>(cp); |
| 666 |
|
|
00658 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"[%i] returning NULL\n"</span>, i); |
| 667 |
|
|
00659 |
| 668 |
|
|
00660 <span class="keywordflow">return</span>(NULL); |
| 669 |
|
|
00661 } |
| 670 |
|
|
00662 |
| 671 |
|
|
00663 |
| 672 |
|
|
00664 <span class="comment">/* UTIL_split_strr</span> |
| 673 |
|
|
00665 <span class="comment">*</span> |
| 674 |
|
|
00666 <span class="comment">* Author: James Couzens <jcouzens@codeshare.ca></span> |
| 675 |
|
|
00667 <span class="comment">*</span> |
| 676 |
|
|
00668 <span class="comment">* Date: 01/30/04</span> |
| 677 |
|
|
00669 <span class="comment">*</span> |
| 678 |
|
|
00670 <span class="comment">* Desc:</span> |
| 679 |
|
|
00671 <span class="comment">* s is walked to the end of its self, and then is walked back</span> |
| 680 |
|
|
00672 <span class="comment">* towards the beginning of the string until it has found 'c' the</span> |
| 681 |
|
|
00673 <span class="comment">* delimiter, 'num' times. Upon success memory is allocated and the</span> |
| 682 |
|
|
00674 <span class="comment">* remainder of s is returned. Upon failure NULL is returned.</span> |
| 683 |
|
|
00675 <span class="comment">*</span> |
| 684 |
|
|
00676 <span class="comment">* Date: 09/01/04 - Roger Moser</span> |
| 685 |
|
|
00677 <span class="comment">*</span> |
| 686 |
|
|
00678 <span class="comment">* Desc:</span> |
| 687 |
|
|
00679 <span class="comment">* Replaced 'p = (char *)&(s[strlen(s) - 1]);' with a more</span> |
| 688 |
|
|
00680 <span class="comment">* optimized 'p = strchr(s, '\0') - 1;'. Also applied a fix so that</span> |
| 689 |
|
|
00681 <span class="comment">* the function properly returns NULL when 's' is an empty string.</span> |
| 690 |
|
|
00682 <span class="comment">*</span> |
| 691 |
|
|
00683 <span class="comment">*/</span> |
| 692 |
|
|
<a name="l00684"></a><a class="code" href="util_8h.html#a37">00684</a> <span class="keywordtype">char</span> *<a class="code" href="util_8h.html#a37">UTIL_split_strr</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> *s, <span class="keyword">const</span> <span class="keywordtype">char</span> c, <span class="keyword">const</span> u_int8_t num) |
| 693 |
|
|
00685 { |
| 694 |
|
|
00686 u_int8_t i; <span class="comment">/* number of times delim (c) is found */</span> |
| 695 |
|
|
00687 |
| 696 |
|
|
00688 <span class="keywordtype">char</span> *p; <span class="comment">/* pointer to the last character of s before the \0 */</span> |
| 697 |
|
|
00689 <span class="keywordtype">char</span> *ret; <span class="comment">/* return buffer */</span> |
| 698 |
|
|
00690 |
| 699 |
|
|
00691 |
| 700 |
|
|
00692 <span class="keywordflow">if</span> ((s == NULL) || (*s == <span class="charliteral">'\0'</span>)) |
| 701 |
|
|
00693 { |
| 702 |
|
|
00694 <a class="code" href="util_8h.html#a13">xepprintf</a>(<span class="stringliteral">"passed a NULL string. Abort!\n"</span>); |
| 703 |
|
|
00695 |
| 704 |
|
|
00696 <span class="keywordflow">return</span>(NULL); |
| 705 |
|
|
00697 } |
| 706 |
|
|
00698 |
| 707 |
|
|
00699 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"called with (%s)\n"</span>, s); |
| 708 |
|
|
00700 |
| 709 |
|
|
00701 |
| 710 |
|
|
00702 <span class="comment">/* assign 'p' to the last char before the null termination of 's'*/</span> |
| 711 |
|
|
00703 <span class="comment">/*p = (char *)&(s[strlen(s) - 1]);*/</span> |
| 712 |
|
|
00704 p = (strchr(s, <span class="charliteral">'\0'</span>) - 1); |
| 713 |
|
|
00705 |
| 714 |
|
|
00706 i = 0; |
| 715 |
|
|
00707 <span class="keywordflow">while</span>(p != s) |
| 716 |
|
|
00708 { |
| 717 |
|
|
00709 <span class="keywordflow">if</span> (*p == c) |
| 718 |
|
|
00710 { |
| 719 |
|
|
00711 i++; |
| 720 |
|
|
00712 <span class="keywordflow">if</span> (i == num) |
| 721 |
|
|
00713 { |
| 722 |
|
|
00714 <span class="keywordflow">if</span> (*p == <span class="charliteral">'.'</span>) |
| 723 |
|
|
00715 { |
| 724 |
|
|
00716 p++; <span class="comment">/* don't want that period */</span> |
| 725 |
|
|
00717 } |
| 726 |
|
|
00718 |
| 727 |
|
|
00719 ret = <a class="code" href="util_8h.html#a7">xstrdup</a>(p); |
| 728 |
|
|
00720 |
| 729 |
|
|
00721 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"delimiter found (%i) times; returning (%s).\n"</span>, i, ret); |
| 730 |
|
|
00722 |
| 731 |
|
|
00723 <span class="keywordflow">return</span>(ret); |
| 732 |
|
|
00724 } |
| 733 |
|
|
00725 } |
| 734 |
|
|
00726 p--; |
| 735 |
|
|
00727 } |
| 736 |
|
|
00728 |
| 737 |
|
|
00729 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"delimiter (%c) found (%u) times; returing NULL\n"</span>, c, i); |
| 738 |
|
|
00730 |
| 739 |
|
|
00731 <span class="keywordflow">return</span>(NULL); |
| 740 |
|
|
00732 } |
| 741 |
|
|
00733 |
| 742 |
|
|
00734 |
| 743 |
|
|
00735 <span class="comment">/* UTIL_count_delim</span> |
| 744 |
|
|
00736 <span class="comment">*</span> |
| 745 |
|
|
00737 <span class="comment">* Author: James Couzens <jcouzens@codeshare.ca></span> |
| 746 |
|
|
00738 <span class="comment">*</span> |
| 747 |
|
|
00739 <span class="comment">* Date: 01/21/04</span> |
| 748 |
|
|
00740 <span class="comment">*</span> |
| 749 |
|
|
00741 <span class="comment">* Desc:</span> |
| 750 |
|
|
00742 <span class="comment">* s is walked through and each time 'delim' is found a counter is </span> |
| 751 |
|
|
00743 <span class="comment">* incremented and once complete, that integer is returned to the calling </span> |
| 752 |
|
|
00744 <span class="comment">* function. Specifically for the purposes of this project i is limited by its</span> |
| 753 |
|
|
00745 <span class="comment">* type to 255.</span> |
| 754 |
|
|
00746 <span class="comment">*</span> |
| 755 |
|
|
00747 <span class="comment">* Returns: > 0 && <= 255 upon success</span> |
| 756 |
|
|
00748 <span class="comment">* Returns: 0 upon failure</span> |
| 757 |
|
|
00749 <span class="comment">*</span> |
| 758 |
|
|
00750 <span class="comment">*/</span> |
| 759 |
|
|
<a name="l00751"></a><a class="code" href="util_8h.html#a38">00751</a> u_int8_t <a class="code" href="util_8h.html#a38">UTIL_count_delim</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> *s, <span class="keyword">const</span> <span class="keywordtype">char</span> c) |
| 760 |
|
|
00752 { |
| 761 |
|
|
00753 u_int8_t i = 0; <span class="comment">/* utility */</span> |
| 762 |
|
|
00754 |
| 763 |
|
|
00755 |
| 764 |
|
|
00756 <span class="keywordflow">if</span> (s == NULL) |
| 765 |
|
|
00757 { |
| 766 |
|
|
00758 <a class="code" href="util_8h.html#a13">xepprintf</a>(<span class="stringliteral">"passed a NULL string. Abort!\n"</span>); |
| 767 |
|
|
00759 |
| 768 |
|
|
00760 <span class="keywordflow">return</span>(0); |
| 769 |
|
|
00761 } |
| 770 |
|
|
00762 |
| 771 |
|
|
00763 <span class="keywordflow">while</span> (*s && i < <a class="code" href="spf_8h.html#a6">SPF_MAX_DELIM</a>) |
| 772 |
|
|
00764 { |
| 773 |
|
|
00765 <span class="keywordflow">if</span> (*s == c) |
| 774 |
|
|
00766 { |
| 775 |
|
|
00767 i++; |
| 776 |
|
|
00768 } |
| 777 |
|
|
00769 s++; |
| 778 |
|
|
00770 } |
| 779 |
|
|
00771 |
| 780 |
|
|
00772 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"found (%i) number of delimiters; returning.\n"</span>, i); |
| 781 |
|
|
00773 |
| 782 |
|
|
00774 <span class="keywordflow">return</span>(i); |
| 783 |
|
|
00775 } |
| 784 |
|
|
00776 |
| 785 |
|
|
00777 |
| 786 |
|
|
00778 <span class="comment">/* UTIL_is_spf_delim</span> |
| 787 |
|
|
00779 <span class="comment">*</span> |
| 788 |
|
|
00780 <span class="comment">* Author: James Couzens <jcouzens@codeshare.ca></span> |
| 789 |
|
|
00781 <span class="comment">*</span> |
| 790 |
|
|
00782 <span class="comment">* Date: 01/21/04</span> |
| 791 |
|
|
00783 <span class="comment">*</span> |
| 792 |
|
|
00784 <span class="comment">* Desc:</span> |
| 793 |
|
|
00785 <span class="comment">* c is compared against all the valid spf delimiters and</span> |
| 794 |
|
|
00786 <span class="comment">* in the case of a SPF_PASS, the function returns true, otherwise it will</span> |
| 795 |
|
|
00787 <span class="comment">* return false.</span> |
| 796 |
|
|
00788 <span class="comment">*</span> |
| 797 |
|
|
00789 <span class="comment">*/</span> |
| 798 |
|
|
<a name="l00790"></a><a class="code" href="util_8h.html#a39">00790</a> <a class="code" href="spf_8h.html#a35">SPF_BOOL</a> <a class="code" href="util_8h.html#a39">UTIL_is_spf_delim</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> c) |
| 799 |
|
|
00791 { |
| 800 |
|
|
00792 |
| 801 |
|
|
00793 <span class="keywordflow">if</span> (!c) |
| 802 |
|
|
00794 { |
| 803 |
|
|
00795 <a class="code" href="util_8h.html#a13">xepprintf</a>(<span class="stringliteral">"called with a NULL char! Aborting check.\n"</span>); |
| 804 |
|
|
00796 |
| 805 |
|
|
00797 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a87a49">SPF_FALSE</a>); |
| 806 |
|
|
00798 } |
| 807 |
|
|
00799 |
| 808 |
|
|
00800 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"called with char (%c)\n"</span>, c); |
| 809 |
|
|
00801 |
| 810 |
|
|
00802 <span class="keywordflow">if</span> (c == <span class="charliteral">'.'</span> || |
| 811 |
|
|
00803 c == <span class="charliteral">'-'</span> || |
| 812 |
|
|
00804 c == <span class="charliteral">'+'</span> || |
| 813 |
|
|
00805 c == <span class="charliteral">','</span> || |
| 814 |
|
|
00806 c == <span class="charliteral">'|'</span> || |
| 815 |
|
|
00807 c == <span class="charliteral">'_'</span>) |
| 816 |
|
|
00808 { |
| 817 |
|
|
00809 <a class="code" href="util_8h.html#a11">xpprintf</a>(<span class="stringliteral">"leaving function; returning SPF_FALSE\n"</span>); |
| 818 |
|
|
00810 |
| 819 |
|
|
00811 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a87a50">SPF_TRUE</a>); |
| 820 |
|
|
00812 } |
| 821 |
|
|
00813 |
| 822 |
|
|
00814 <a class="code" href="util_8h.html#a11">xpprintf</a>(<span class="stringliteral">"leaving function; returning SPF_FALSE\n"</span>); |
| 823 |
|
|
00815 |
| 824 |
|
|
00816 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a87a49">SPF_FALSE</a>); |
| 825 |
|
|
00817 } |
| 826 |
|
|
00818 |
| 827 |
|
|
00819 |
| 828 |
|
|
00820 <span class="comment">/* UTIL_is_spf_result</span> |
| 829 |
|
|
00821 <span class="comment">*</span> |
| 830 |
|
|
00822 <span class="comment">* Author: James Couzens <jcouzens@codeshare.ca></span> |
| 831 |
|
|
00823 <span class="comment">*</span> |
| 832 |
|
|
00824 <span class="comment">* Date: 01/27/04</span> |
| 833 |
|
|
00825 <span class="comment">*</span> |
| 834 |
|
|
00826 <span class="comment">* Desc:</span> |
| 835 |
|
|
00827 <span class="comment">* c is compared against all the valid spf prefixes and</span> |
| 836 |
|
|
00828 <span class="comment">* in the case of a SPF_PASS, the function returns true, otherwise it will</span> |
| 837 |
|
|
00829 <span class="comment">* return false.</span> |
| 838 |
|
|
00830 <span class="comment">*</span> |
| 839 |
|
|
00831 <span class="comment">*/</span> |
| 840 |
|
|
<a name="l00832"></a><a class="code" href="util_8h.html#a40">00832</a> <a class="code" href="spf_8h.html#a35">SPF_BOOL</a> <a class="code" href="util_8h.html#a40">UTIL_is_spf_result</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> c) |
| 841 |
|
|
00833 { |
| 842 |
|
|
00834 <span class="keywordflow">if</span> (!c) |
| 843 |
|
|
00835 { |
| 844 |
|
|
00836 <a class="code" href="util_8h.html#a11">xpprintf</a>(<span class="stringliteral">"passed a NULL or empty char!\n"</span>); |
| 845 |
|
|
00837 |
| 846 |
|
|
00838 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a87a49">SPF_FALSE</a>); |
| 847 |
|
|
00839 } |
| 848 |
|
|
00840 |
| 849 |
|
|
00841 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"called with char (%c)\n"</span>, c); |
| 850 |
|
|
00842 |
| 851 |
|
|
00843 <span class="keywordflow">if</span> (c == <span class="charliteral">'+'</span> || c == <span class="charliteral">'-'</span> || c == <span class="charliteral">'~'</span> || c == <span class="charliteral">'?'</span>) |
| 852 |
|
|
00844 { |
| 853 |
|
|
00845 <a class="code" href="util_8h.html#a11">xpprintf</a>(<span class="stringliteral">"leaving function; returning SPF_TRUE\n"</span>); |
| 854 |
|
|
00846 |
| 855 |
|
|
00847 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a87a50">SPF_TRUE</a>); |
| 856 |
|
|
00848 } |
| 857 |
|
|
00849 |
| 858 |
|
|
00850 <a class="code" href="util_8h.html#a11">xpprintf</a>(<span class="stringliteral">"leaving function; returning SPF_FALSE\n"</span>); |
| 859 |
|
|
00851 |
| 860 |
|
|
00852 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a87a49">SPF_FALSE</a>); |
| 861 |
|
|
00853 } |
| 862 |
|
|
00854 |
| 863 |
|
|
00855 |
| 864 |
|
|
00856 <span class="comment">/* UTIL_is_macro</span> |
| 865 |
|
|
00857 <span class="comment">*</span> |
| 866 |
|
|
00858 <span class="comment">* Author: James Couzens <jcouzens@codeshare.ca></span> |
| 867 |
|
|
00859 <span class="comment">*</span> |
| 868 |
|
|
00860 <span class="comment">* Date: 01/30/04</span> |
| 869 |
|
|
00861 <span class="comment">*</span> |
| 870 |
|
|
00862 <span class="comment">* Desc:</span> |
| 871 |
|
|
00863 <span class="comment">* s is walked through in search of a macro which consist of</span> |
| 872 |
|
|
00864 <span class="comment">* %{?}, ? being an SPF_UNKNOWN number of chars in between. An instance of</span> |
| 873 |
|
|
00865 <span class="comment">* a macro is searched for. Upon success SPF_TRUE is returned. Upon failure</span> |
| 874 |
|
|
00866 <span class="comment">* to find a macro, SPF_FALSE is returned.</span> |
| 875 |
|
|
00867 <span class="comment">*</span> |
| 876 |
|
|
00868 <span class="comment">*/</span> |
| 877 |
|
|
<a name="l00869"></a><a class="code" href="util_8h.html#a41">00869</a> <a class="code" href="spf_8h.html#a35">SPF_BOOL</a> <a class="code" href="util_8h.html#a41">UTIL_is_macro</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> *s) |
| 878 |
|
|
00870 { |
| 879 |
|
|
00871 <span class="keywordflow">if</span> (s == NULL) |
| 880 |
|
|
00872 { |
| 881 |
|
|
00873 <a class="code" href="util_8h.html#a13">xepprintf</a>(<span class="stringliteral">"passed a NULL string. Abort!\n"</span>); |
| 882 |
|
|
00874 |
| 883 |
|
|
00875 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a87a49">SPF_FALSE</a>); |
| 884 |
|
|
00876 } |
| 885 |
|
|
00877 |
| 886 |
|
|
00878 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"called with string (%s)\n"</span>, s); |
| 887 |
|
|
00879 |
| 888 |
|
|
00880 <span class="keywordflow">while</span> (*s++) |
| 889 |
|
|
00881 { |
| 890 |
|
|
00882 <span class="keywordflow">if</span> ((*s == <span class="charliteral">'%'</span>) && (*(s + 1) == <span class="charliteral">'{'</span>)) |
| 891 |
|
|
00883 { |
| 892 |
|
|
00884 <span class="keywordflow">if</span> (strstr(s, <span class="stringliteral">"}"</span>)) |
| 893 |
|
|
00885 { |
| 894 |
|
|
00886 <a class="code" href="util_8h.html#a11">xpprintf</a>(<span class="stringliteral">"leaving function; returning SPF_TRUE\n"</span>); |
| 895 |
|
|
00887 |
| 896 |
|
|
00888 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a87a50">SPF_TRUE</a>); |
| 897 |
|
|
00889 } |
| 898 |
|
|
00890 } |
| 899 |
|
|
00891 } |
| 900 |
|
|
00892 |
| 901 |
|
|
00893 <a class="code" href="util_8h.html#a11">xpprintf</a>(<span class="stringliteral">"leaving function; returning SPF_FALSE\n"</span>); |
| 902 |
|
|
00894 |
| 903 |
|
|
00895 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a87a49">SPF_FALSE</a>); |
| 904 |
|
|
00896 } |
| 905 |
|
|
00897 |
| 906 |
|
|
00898 |
| 907 |
|
|
00899 <span class="comment">/* UTIL_mx_cmp</span> |
| 908 |
|
|
00900 <span class="comment">*</span> |
| 909 |
|
|
00901 <span class="comment">* Author: James Couzens <jcouzens@codeshare.ca></span> |
| 910 |
|
|
00902 <span class="comment">*</span> |
| 911 |
|
|
00903 <span class="comment">* Date: 01/02/04</span> |
| 912 |
|
|
00904 <span class="comment">*</span> |
| 913 |
|
|
00905 <span class="comment">* Desc:</span> |
| 914 |
|
|
00906 <span class="comment">* Using the domain name found in the passed peer_info</span> |
| 915 |
|
|
00907 <span class="comment">* structure, the associated T_MX records are looked up and then their</span> |
| 916 |
|
|
00908 <span class="comment">* respective hostnames resolved (if they happen to be IP addresses the</span> |
| 917 |
|
|
00909 <span class="comment">* resolver library takes care of this. <3). Each IP is compared</span> |
| 918 |
|
|
00910 <span class="comment">* against the remote peer's IP (from peer_info). Upon success returns</span> |
| 919 |
|
|
00911 <span class="comment">* SPF_TRUE, upon failure returns SPF_FALSE.</span> |
| 920 |
|
|
00912 <span class="comment">*</span> |
| 921 |
|
|
00913 <span class="comment">*/</span> |
| 922 |
|
|
<a name="l00914"></a><a class="code" href="util_8h.html#a42">00914</a> <a class="code" href="spf_8h.html#a35">SPF_BOOL</a> <a class="code" href="util_8h.html#a42">UTIL_mx_cmp</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, <span class="keyword">const</span> int8_t cidr) |
| 923 |
|
|
00915 { |
| 924 |
|
|
00916 <a class="code" href="spf_8h.html#a35">SPF_BOOL</a> MX_SPF_MATCH; <span class="comment">/* true / false */</span> |
| 925 |
|
|
00917 |
| 926 |
|
|
00918 <span class="keywordtype">char</span> *rr_data = NULL; <span class="comment">/* record */</span> |
| 927 |
|
|
00919 <span class="keywordtype">char</span> *token; <span class="comment">/* token for splitting records */</span> |
| 928 |
|
|
00920 <span class="keywordtype">char</span> *token_ptr; <span class="comment">/* working pointer when tokenizing */</span> |
| 929 |
|
|
00921 <span class="keywordtype">char</span> *peer_ip; <span class="comment">/* remote host converted to string */</span> |
| 930 |
|
|
00922 |
| 931 |
|
|
00923 |
| 932 |
|
|
00924 MX_SPF_MATCH = <a class="code" href="spf_8h.html#a87a49">SPF_FALSE</a>; |
| 933 |
|
|
00925 token_ptr = rr_data; |
| 934 |
|
|
00926 |
| 935 |
|
|
00927 <span class="keywordflow">if</span> ((rr_data = <a class="code" href="dns_8h.html#a8">DNS_query</a>(p, s, T_MX, NULL)) == NULL) |
| 936 |
|
|
00928 { |
| 937 |
|
|
00929 <a class="code" href="util_8h.html#a11">xpprintf</a>(<span class="stringliteral">"SPF_ERROR parsing DNS Query\n"</span>); |
| 938 |
|
|
00930 |
| 939 |
|
|
00931 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a87a49">SPF_FALSE</a>); |
| 940 |
|
|
00932 } |
| 941 |
|
|
00933 |
| 942 |
|
|
00934 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"rr_data is: (%s)\n"</span>, rr_data); |
| 943 |
|
|
00935 |
| 944 |
|
|
00936 peer_ip = <a class="code" href="util_8h.html#a8">xstrndup</a>(inet_ntoa(p-><a class="code" href="structpeer__info__s.html#o26">addr</a>), 16); |
| 945 |
|
|
00937 token = strtok_r(rr_data, <span class="stringliteral">" "</span>, &token_ptr); |
| 946 |
|
|
00938 |
| 947 |
|
|
00939 <span class="keywordflow">while</span> (token != NULL) |
| 948 |
|
|
00940 { |
| 949 |
|
|
00941 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"TOKEN: (%s)\n"</span>, token); |
| 950 |
|
|
00942 |
| 951 |
|
|
00943 <span class="keywordflow">if</span> (<a class="code" href="util_8h.html#a54">UTIL_validate_hostname</a>(p, token, cidr) == <a class="code" href="spf_8h.html#a87a50">SPF_TRUE</a>) |
| 952 |
|
|
00944 { |
| 953 |
|
|
00945 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"%s validated via (%s)\n"</span>, p-><a class="code" href="structpeer__info__s.html#o10">from</a>, token); |
| 954 |
|
|
00946 |
| 955 |
|
|
00947 MX_SPF_MATCH = <a class="code" href="spf_8h.html#a87a50">SPF_TRUE</a>; |
| 956 |
|
|
00948 <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); |
| 957 |
|
|
00949 token = NULL; |
| 958 |
|
|
00950 } |
| 959 |
|
|
00951 <span class="keywordflow">else</span> |
| 960 |
|
|
00952 { |
| 961 |
|
|
00953 token = strtok_r(NULL, <span class="stringliteral">" "</span>, &token_ptr); |
| 962 |
|
|
00954 } |
| 963 |
|
|
00955 } |
| 964 |
|
|
00956 |
| 965 |
|
|
00957 <a class="code" href="util_8h.html#a6">xfree</a>(peer_ip); |
| 966 |
|
|
00958 <a class="code" href="util_8h.html#a6">xfree</a>(rr_data); |
| 967 |
|
|
00959 |
| 968 |
|
|
00960 <span class="keywordflow">return</span>(MX_SPF_MATCH); |
| 969 |
|
|
00961 } |
| 970 |
|
|
00962 |
| 971 |
|
|
00963 |
| 972 |
|
|
00964 <span class="comment">/* UTIL_a_cmp</span> |
| 973 |
|
|
00965 <span class="comment">*</span> |
| 974 |
|
|
00966 <span class="comment">* Author: James Couzens <jcouzens@codeshare.ca></span> |
| 975 |
|
|
00967 <span class="comment">*</span> |
| 976 |
|
|
00968 <span class="comment">* Date: 01/02/04</span> |
| 977 |
|
|
00969 <span class="comment">*</span> |
| 978 |
|
|
00970 <span class="comment">* Desc:</span> |
| 979 |
|
|
00971 <span class="comment">* Calls gethostbyname to grab all records associated with a the</span> |
| 980 |
|
|
00972 <span class="comment">* hostname contained within s. On success returns SPF_TRUE, on SPF_ERROR</span> |
| 981 |
|
|
00973 <span class="comment">* returns SPF_FALSE.</span> |
| 982 |
|
|
00974 <span class="comment">*</span> |
| 983 |
|
|
00975 <span class="comment">* Note:</span> |
| 984 |
|
|
00976 <span class="comment">* We need to define and set a limit on the number of recursive</span> |
| 985 |
|
|
00977 <span class="comment">* lookups. I recall seeing this in the RFC, we should discuss this.</span> |
| 986 |
|
|
00978 <span class="comment">*</span> |
| 987 |
|
|
00979 <span class="comment">*/</span> |
| 988 |
|
|
<a name="l00980"></a><a class="code" href="util_8h.html#a43">00980</a> <a class="code" href="spf_8h.html#a35">SPF_BOOL</a> <a class="code" href="util_8h.html#a43">UTIL_a_cmp</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, <span class="keyword">const</span> int8_t cidr) |
| 989 |
|
|
00981 { |
| 990 |
|
|
00982 int16_t pos; <span class="comment">/* position in DNS packet */</span> |
| 991 |
|
|
00983 |
| 992 |
|
|
00984 <span class="keywordtype">int</span> tmp_errno = 0; <span class="comment">/* temporary errno placeholder */</span> |
| 993 |
|
|
00985 |
| 994 |
|
|
00986 size_t s_len; <span class="comment">/* length of s (hostname) */</span> |
| 995 |
|
|
00987 |
| 996 |
|
|
00988 <span class="keywordtype">char</span> *rr_data = NULL; <span class="comment">/* data storage for DNS query */</span> |
| 997 |
|
|
00989 <span class="keywordtype">char</span> *token_ptr = NULL; <span class="comment">/* token pointer */</span> |
| 998 |
|
|
00990 <span class="keywordtype">char</span> *gbuf = NULL; <span class="comment">/* buf for reentrant gethostbyname call */</span> |
| 999 |
|
|
00991 <span class="keywordtype">char</span> *copy = NULL; <span class="comment">/* copy of s */</span> |
| 1000 |
|
|
00992 <span class="keywordtype">char</span> *cp = NULL; <span class="comment">/* pointer to copy of s */</span> |
| 1001 |
|
|
00993 |
| 1002 |
|
|
00994 <span class="keywordtype">char</span> **a; |
| 1003 |
|
|
00995 |
| 1004 |
|
|
00996 <span class="keyword">struct </span>hostent *hp = NULL; <span class="comment">/* hostent structure */</span> |
| 1005 |
|
|
00997 <span class="keyword">struct </span>hostent tmp_hp; <span class="comment">/* temporary hostent (xgethostbyname) */</span> |
| 1006 |
|
|
00998 |
| 1007 |
|
|
00999 <a class="code" href="structpolicy__addr__s.html">policy_addr_t</a> policy_addr; <span class="comment">/* used during CIDR comparisons */</span> |
| 1008 |
|
|
01000 |
| 1009 |
|
|
01001 |
| 1010 |
|
|
01002 <span class="keywordflow">if</span> (s == NULL) |
| 1011 |
|
|
01003 { |
| 1012 |
|
|
01004 <a class="code" href="util_8h.html#a13">xepprintf</a>(<span class="stringliteral">"Passed string is NULL. Abort!.\n"</span>); |
| 1013 |
|
|
01005 |
| 1014 |
|
|
01006 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a87a49">SPF_FALSE</a>); |
| 1015 |
|
|
01007 } |
| 1016 |
|
|
01008 |
| 1017 |
|
|
01009 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"called with (%s) and cidr: %i\n"</span>, s, cidr); |
| 1018 |
|
|
01010 |
| 1019 |
|
|
01011 gbuf = <a class="code" href="util_8h.html#a4">xmalloc</a>(<a class="code" href="util_8h.html#a2">SPF_MAX_GHBNR_DBUF</a>); |
| 1020 |
|
|
01012 s_len = strlen(s); |
| 1021 |
|
|
01013 token_ptr = rr_data; |
| 1022 |
|
|
01014 |
| 1023 |
|
|
01015 <span class="comment">/* we're dealing with a:some.hostname/cidr */</span> |
| 1024 |
|
|
01016 <span class="keywordflow">if</span> ((s_len > 1) && (*(s + 1) == <span class="charliteral">':'</span>)) |
| 1025 |
|
|
01017 { |
| 1026 |
|
|
01018 cp = copy = <a class="code" href="util_8h.html#a8">xstrndup</a>(s, (s_len + 1)); |
| 1027 |
|
|
01019 |
| 1028 |
|
|
01020 <span class="keywordflow">if</span> (cidr != 32) |
| 1029 |
|
|
01021 { |
| 1030 |
|
|
01022 <span class="comment">/* We don't want a netmask, so lets remove it */</span> |
| 1031 |
|
|
01023 cp[s_len - 3] = <span class="charliteral">'\0'</span>; |
| 1032 |
|
|
01024 } |
| 1033 |
|
|
01025 |
| 1034 |
|
|
01026 <span class="keywordflow">if</span> ((pos = <a class="code" href="util_8h.html#a35">UTIL_index</a>(cp, <span class="charliteral">':'</span>)) <= 0) |
| 1035 |
|
|
01027 { |
| 1036 |
|
|
01028 <a class="code" href="util_8h.html#a12">xeprintf</a>(<span class="stringliteral">"ERROR parsing passed mechanism token (%s)\n"</span>, cp); |
| 1037 |
|
|
01029 |
| 1038 |
|
|
01030 <a class="code" href="util_8h.html#a6">xfree</a>(copy); |
| 1039 |
|
|
01031 <a class="code" href="util_8h.html#a6">xfree</a>(gbuf); |
| 1040 |
|
|
01032 |
| 1041 |
|
|
01033 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a87a49">SPF_FALSE</a>); |
| 1042 |
|
|
01034 } |
| 1043 |
|
|
01035 |
| 1044 |
|
|
01036 <span class="comment">/* move passed the mechanism text */</span> |
| 1045 |
|
|
01037 cp += (pos + 1); |
| 1046 |
|
|
01038 } |
| 1047 |
|
|
01039 <span class="keywordflow">else</span> |
| 1048 |
|
|
01040 { |
| 1049 |
|
|
01041 cp = copy = <a class="code" href="util_8h.html#a8">xstrndup</a>(p-><a class="code" href="structpeer__info__s.html#o15">current_domain</a>, <a class="code" href="spf_8h.html#a14">SPF_MAX_HNAME</a>); |
| 1050 |
|
|
01042 } |
| 1051 |
|
|
01043 |
| 1052 |
|
|
01044 <span class="keywordflow">if</span> ((hp = <a class="code" href="dns_8h.html#a4">xgethostbyname</a>(cp, &tmp_hp, gbuf, <a class="code" href="util_8h.html#a2">SPF_MAX_GHBNR_DBUF</a>, |
| 1053 |
|
|
01045 &tmp_errno)) != NULL) |
| 1054 |
|
|
01046 { |
| 1055 |
|
|
01047 <span class="keywordflow">for</span> (a = hp->h_addr_list; *a; a++) |
| 1056 |
|
|
01048 { |
| 1057 |
|
|
01049 memcpy(&policy_addr.addr.s_addr, *a, <a class="code" href="util_8h.html#a3">SIZEOF</a>(<span class="keyword">struct</span> in_addr)); |
| 1058 |
|
|
01050 |
| 1059 |
|
|
01051 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"IN ADDR; Checking: %lu\n"</span>, policy_addr.addr.s_addr); |
| 1060 |
|
|
01052 |
| 1061 |
|
|
01053 <span class="comment">/* cidr is assumed checked by the calling function! */</span> |
| 1062 |
|
|
01054 policy_addr.cidr = cidr; |
| 1063 |
|
|
01055 |
| 1064 |
|
|
01056 <span class="keywordflow">if</span> (<a class="code" href="util_8h.html#a52">UTIL_cidr_cmp</a>(&policy_addr, &p-><a class="code" href="structpeer__info__s.html#o26">addr</a>) == <a class="code" href="spf_8h.html#a87a50">SPF_TRUE</a>) |
| 1065 |
|
|
01057 { |
| 1066 |
|
|
01058 *a = NULL; |
| 1067 |
|
|
01059 |
| 1068 |
|
|
01060 <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); |
| 1069 |
|
|
01061 |
| 1070 |
|
|
01062 <a class="code" href="util_8h.html#a6">xfree</a>(copy); |
| 1071 |
|
|
01063 <a class="code" href="util_8h.html#a6">xfree</a>(gbuf); |
| 1072 |
|
|
01064 |
| 1073 |
|
|
01065 <a class="code" href="dns_8h.html#a5">xgethostbyname_free</a>(); <span class="comment">/* unlock mutex */</span> |
| 1074 |
|
|
01066 |
| 1075 |
|
|
01067 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a87a50">SPF_TRUE</a>); |
| 1076 |
|
|
01068 } |
| 1077 |
|
|
01069 } <span class="comment">/* for */</span> |
| 1078 |
|
|
01070 |
| 1079 |
|
|
01071 <span class="keywordflow">for</span> (a = hp->h_aliases; *a; a++) |
| 1080 |
|
|
01072 { |
| 1081 |
|
|
01073 memcpy(&policy_addr.addr.s_addr, *a, <a class="code" href="util_8h.html#a3">SIZEOF</a>(<span class="keyword">struct</span> in_addr)); |
| 1082 |
|
|
01074 |
| 1083 |
|
|
01075 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"IN CNAME; Checking: %lu\n"</span>, policy_addr.addr.s_addr); |
| 1084 |
|
|
01076 |
| 1085 |
|
|
01077 <span class="comment">/* cidr is assumed checked by the calling function! */</span> |
| 1086 |
|
|
01078 policy_addr.cidr = cidr; |
| 1087 |
|
|
01079 |
| 1088 |
|
|
01080 <span class="keywordflow">if</span> (<a class="code" href="util_8h.html#a52">UTIL_cidr_cmp</a>(&policy_addr, &p-><a class="code" href="structpeer__info__s.html#o26">addr</a>) == <a class="code" href="spf_8h.html#a87a50">SPF_TRUE</a>) |
| 1089 |
|
|
01081 { |
| 1090 |
|
|
01082 *a = NULL; |
| 1091 |
|
|
01083 |
| 1092 |
|
|
01084 <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); |
| 1093 |
|
|
01085 |
| 1094 |
|
|
01086 <a class="code" href="util_8h.html#a6">xfree</a>(copy); |
| 1095 |
|
|
01087 <a class="code" href="util_8h.html#a6">xfree</a>(gbuf); |
| 1096 |
|
|
01088 |
| 1097 |
|
|
01089 <a class="code" href="dns_8h.html#a5">xgethostbyname_free</a>(); <span class="comment">/* unlock mutex */</span> |
| 1098 |
|
|
01090 |
| 1099 |
|
|
01091 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a87a50">SPF_TRUE</a>); |
| 1100 |
|
|
01092 } |
| 1101 |
|
|
01093 } <span class="comment">/* for */</span> |
| 1102 |
|
|
01094 } <span class="comment">/* if .. xgethostbyname */</span> |
| 1103 |
|
|
01095 <span class="keywordflow">else</span> |
| 1104 |
|
|
01096 { |
| 1105 |
|
|
01097 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"No address associated with hostname (%s); Reason: %s\n"</span>, |
| 1106 |
|
|
01098 s, hstrerror(tmp_errno)); |
| 1107 |
|
|
01099 } |
| 1108 |
|
|
01100 |
| 1109 |
|
|
01101 <a class="code" href="util_8h.html#a6">xfree</a>(copy); |
| 1110 |
|
|
01102 <a class="code" href="util_8h.html#a6">xfree</a>(gbuf); |
| 1111 |
|
|
01103 |
| 1112 |
|
|
01104 <a class="code" href="dns_8h.html#a5">xgethostbyname_free</a>(); |
| 1113 |
|
|
01105 |
| 1114 |
|
|
01106 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a87a49">SPF_FALSE</a>); |
| 1115 |
|
|
01107 } |
| 1116 |
|
|
01108 |
| 1117 |
|
|
01109 |
| 1118 |
|
|
01110 <span class="comment">/* UTIL_ptr_cmp</span> |
| 1119 |
|
|
01111 <span class="comment">*</span> |
| 1120 |
|
|
01112 <span class="comment">* Author: James Couzens <jcouzens@codeshare.ca></span> |
| 1121 |
|
|
01113 <span class="comment">*</span> |
| 1122 |
|
|
01114 <span class="comment">* Date: 01/08/04</span> |
| 1123 |
|
|
01115 <span class="comment">*</span> |
| 1124 |
|
|
01116 <span class="comment">* Desc:</span> |
| 1125 |
|
|
01117 <span class="comment">* gethostbyaddr is broken in linux. ?->h_aliases is not NULL,</span> |
| 1126 |
|
|
01118 <span class="comment">* however, it doesn't contain any valid pointers either. It grabs the</span> |
| 1127 |
|
|
01119 <span class="comment">* first (and of course this is random) hostname it gets and thats all.</span> |
| 1128 |
|
|
01120 <span class="comment">* As tested in FreeBSD however this call works. At any rate, I've</span> |
| 1129 |
|
|
01121 <span class="comment">* written a function to deal with this called DNS_ptr_answer. From here</span> |
| 1130 |
|
|
01122 <span class="comment">* that function is called which handles the reverse lookups and then</span> |
| 1131 |
|
|
01123 <span class="comment">* attempts to "validate" each returned hostname by in turn looking it up</span> |
| 1132 |
|
|
01124 <span class="comment">* to confirm if the ip address SPF_MATCHes. Returns SPF_TRUE on succes, and SPF_FALSE</span> |
| 1133 |
|
|
01125 <span class="comment">* on failure.</span> |
| 1134 |
|
|
01126 <span class="comment">*</span> |
| 1135 |
|
|
01127 <span class="comment">* When passed SPF_TRUE copies into p->ptr_mhost, when SPF_FALSE copies</span> |
| 1136 |
|
|
01128 <span class="comment">* into p->r_vhname</span> |
| 1137 |
|
|
01129 <span class="comment">*</span> |
| 1138 |
|
|
01130 <span class="comment">* Note:</span> |
| 1139 |
|
|
01131 <span class="comment">* We need to define and set a limit on the number of recursive</span> |
| 1140 |
|
|
01132 <span class="comment">* lookups. I recall seeing this in the RFC, we should discuss this.</span> |
| 1141 |
|
|
01133 <span class="comment">*</span> |
| 1142 |
|
|
01134 <span class="comment">*/</span> |
| 1143 |
|
|
<a name="l01135"></a><a class="code" href="util_8h.html#a44">01135</a> <a class="code" href="spf_8h.html#a35">SPF_BOOL</a> <a class="code" href="util_8h.html#a44">UTIL_ptr_cmp</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) |
| 1144 |
|
|
01136 { |
| 1145 |
|
|
01137 <span class="keywordtype">char</span> *ptr_addr; <span class="comment">/* reversed address into PTR format */</span> |
| 1146 |
|
|
01138 <span class="keywordtype">char</span> *tmp_ptr; <span class="comment">/* utility pointer */</span> |
| 1147 |
|
|
01139 |
| 1148 |
|
|
01140 |
| 1149 |
|
|
01141 <span class="keywordflow">if</span> (s == NULL) |
| 1150 |
|
|
01142 { |
| 1151 |
|
|
01143 <a class="code" href="util_8h.html#a13">xepprintf</a>(<span class="stringliteral">"Passed string is NULL. Abort!\n"</span>); |
| 1152 |
|
|
01144 |
| 1153 |
|
|
01145 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a87a49">SPF_FALSE</a>); |
| 1154 |
|
|
01146 } |
| 1155 |
|
|
01147 |
| 1156 |
|
|
01148 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"called with (%s)\n"</span>, s); |
| 1157 |
|
|
01149 |
| 1158 |
|
|
01150 <span class="comment">/* reverse of rpeer */</span> |
| 1159 |
|
|
01151 ptr_addr = <a class="code" href="util_8h.html#a50">UTIL_rev_addr</a>(p-><a class="code" href="structpeer__info__s.html#o17">r_ip</a>); |
| 1160 |
|
|
01152 |
| 1161 |
|
|
01153 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"address: %s\n"</span>, ptr_addr); |
| 1162 |
|
|
01154 |
| 1163 |
|
|
01155 <span class="keywordflow">if</span> ((s = strstr(s, <span class="stringliteral">":"</span>)) != NULL) |
| 1164 |
|
|
01156 { |
| 1165 |
|
|
01157 s++; |
| 1166 |
|
|
01158 tmp_ptr = <a class="code" href="util_8h.html#a8">xstrndup</a>(s, (strlen(s) + 1)); |
| 1167 |
|
|
01159 } |
| 1168 |
|
|
01160 <span class="keywordflow">else</span> |
| 1169 |
|
|
01161 { |
| 1170 |
|
|
01162 tmp_ptr = <a class="code" href="util_8h.html#a8">xstrndup</a>(p-><a class="code" href="structpeer__info__s.html#o15">current_domain</a>, <a class="code" href="spf_8h.html#a14">SPF_MAX_HNAME</a>); |
| 1171 |
|
|
01163 } |
| 1172 |
|
|
01164 |
| 1173 |
|
|
01165 <span class="keywordflow">if</span> (<a class="code" href="dns_8h.html#a8">DNS_query</a>(p, ptr_addr, T_PTR, tmp_ptr) != (<span class="keywordtype">char</span> *)<a class="code" href="spf_8h.html#a87a50">SPF_TRUE</a>) |
| 1174 |
|
|
01166 { |
| 1175 |
|
|
01167 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"Failed to pass SPF PTR mechanism check:%s\n"</span>, <span class="stringliteral">""</span>); |
| 1176 |
|
|
01168 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"the domain pointed to by %s is not a valid subdomain of %s\n"</span>, |
| 1177 |
|
|
01169 ptr_addr, tmp_ptr); |
| 1178 |
|
|
01170 |
| 1179 |
|
|
01171 <a class="code" href="util_8h.html#a6">xfree</a>(ptr_addr); |
| 1180 |
|
|
01172 <a class="code" href="util_8h.html#a6">xfree</a>(tmp_ptr); |
| 1181 |
|
|
01173 |
| 1182 |
|
|
01174 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a87a49">SPF_FALSE</a>); |
| 1183 |
|
|
01175 } |
| 1184 |
|
|
01176 |
| 1185 |
|
|
01177 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"PTR lookup succeeded: (%s):(%s)\n"</span>, p-><a class="code" href="structpeer__info__s.html#o7">rs</a>, |
| 1186 |
|
|
01178 p-><a class="code" href="structpeer__info__s.html#o24">error</a>); |
| 1187 |
|
|
01179 |
| 1188 |
|
|
01180 <a class="code" href="util_8h.html#a6">xfree</a>(ptr_addr); |
| 1189 |
|
|
01181 <a class="code" href="util_8h.html#a6">xfree</a>(tmp_ptr); |
| 1190 |
|
|
01182 |
| 1191 |
|
|
01183 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a87a50">SPF_TRUE</a>); |
| 1192 |
|
|
01184 } |
| 1193 |
|
|
01185 |
| 1194 |
|
|
01186 |
| 1195 |
|
|
01187 <span class="comment">/* UTIL_get_policy_mech</span> |
| 1196 |
|
|
01188 <span class="comment">*</span> |
| 1197 |
|
|
01189 <span class="comment">* Author: James Couzens <jcouzens@codeshare.ca></span> |
| 1198 |
|
|
01190 <span class="comment">*</span> |
| 1199 |
|
|
01191 <span class="comment">* Date: 12/19/03</span> |
| 1200 |
|
|
01192 <span class="comment">*</span> |
| 1201 |
|
|
01193 <span class="comment">* Desc:</span> |
| 1202 |
|
|
01194 <span class="comment">* Examins s and attempts to determine which SPF_MECHANISM</span> |
| 1203 |
|
|
01195 <span class="comment">* enumeration the string SPF_MATCHes based on its conent.</span> |
| 1204 |
|
|
01196 <span class="comment">*</span> |
| 1205 |
|
|
01197 <span class="comment">*/</span> |
| 1206 |
|
|
<a name="l01198"></a><a class="code" href="util_8h.html#a45">01198</a> <a class="code" href="spf_8h.html#a38">SPF_MECHANISM</a> <a class="code" href="util_8h.html#a45">UTIL_get_policy_mech</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> *s) |
| 1207 |
|
|
01199 { |
| 1208 |
|
|
01200 <span class="keywordflow">if</span> (s == NULL || !s) |
| 1209 |
|
|
01201 { |
| 1210 |
|
|
01202 <a class="code" href="util_8h.html#a13">xepprintf</a>(<span class="stringliteral">"passed a NULL string. Abort!\n"</span>); |
| 1211 |
|
|
01203 |
| 1212 |
|
|
01204 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a90a63">NO_POLICY</a>); |
| 1213 |
|
|
01205 } |
| 1214 |
|
|
01206 |
| 1215 |
|
|
01207 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"called with: (%s)\n"</span>, s); |
| 1216 |
|
|
01208 |
| 1217 |
|
|
01209 <span class="keywordflow">if</span> (strncmp(s, <span class="stringliteral">"v="</span>, 2) == 0) |
| 1218 |
|
|
01210 { |
| 1219 |
|
|
01211 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"leaving function; returning %i (VERSION)\n"</span>, <a class="code" href="spf_8h.html#a90a64">VERSION</a>); |
| 1220 |
|
|
01212 |
| 1221 |
|
|
01213 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a90a64">VERSION</a>); |
| 1222 |
|
|
01214 } |
| 1223 |
|
|
01215 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strncmp(s, <span class="stringliteral">"ip4:"</span>, 4) == 0 ) |
| 1224 |
|
|
01216 { |
| 1225 |
|
|
01217 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"leaving function; returning %i (IP4)\n"</span>, <a class="code" href="spf_8h.html#a90a70">IP4</a>); |
| 1226 |
|
|
01218 |
| 1227 |
|
|
01219 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a90a70">IP4</a>); |
| 1228 |
|
|
01220 } |
| 1229 |
|
|
01221 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strncmp(s, <span class="stringliteral">"ip6:"</span>, 4) == 0) |
| 1230 |
|
|
01222 { |
| 1231 |
|
|
01223 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"leaving function; returning %i (IP6)\n"</span>, <a class="code" href="spf_8h.html#a90a71">IP6</a>); |
| 1232 |
|
|
01224 |
| 1233 |
|
|
01225 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a90a71">IP6</a>); |
| 1234 |
|
|
01226 } |
| 1235 |
|
|
01227 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strncmp(s, <span class="stringliteral">"all"</span>, 3) == 0) |
| 1236 |
|
|
01228 { |
| 1237 |
|
|
01229 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"leaving function; returning %i (ALL)\n"</span>, <a class="code" href="spf_8h.html#a90a65">ALL</a>); |
| 1238 |
|
|
01230 |
| 1239 |
|
|
01231 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a90a65">ALL</a>); |
| 1240 |
|
|
01232 } |
| 1241 |
|
|
01233 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strncmp(s, <span class="stringliteral">"mx"</span>, 2) == 0) |
| 1242 |
|
|
01234 { |
| 1243 |
|
|
01235 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"leaving function; returning %i (MX)\n"</span>, <a class="code" href="spf_8h.html#a90a68">MX</a>); |
| 1244 |
|
|
01236 |
| 1245 |
|
|
01237 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a90a68">MX</a>); |
| 1246 |
|
|
01238 } |
| 1247 |
|
|
01239 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strncmp(s, <span class="stringliteral">"a:"</span>, 2) == 0 || (*s == <span class="charliteral">'a'</span> && *(s + 1) == <span class="charliteral">'/'</span>) |
| 1248 |
|
|
01240 || ((*s == <span class="charliteral">'a'</span>) && !*(s + 1))) |
| 1249 |
|
|
01241 { |
| 1250 |
|
|
01242 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"leaving function; returning %i (A)\n"</span>, <a class="code" href="spf_8h.html#a90a67">A</a>); |
| 1251 |
|
|
01243 |
| 1252 |
|
|
01244 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a90a67">A</a>); |
| 1253 |
|
|
01245 } |
| 1254 |
|
|
01246 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strncmp(s, <span class="stringliteral">"ptr"</span>, 3) == 0) |
| 1255 |
|
|
01247 { |
| 1256 |
|
|
01248 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"leaving function; returning %i (PTR)\n"</span>, <a class="code" href="spf_8h.html#a90a69">PTR</a>); |
| 1257 |
|
|
01249 |
| 1258 |
|
|
01250 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a90a69">PTR</a>); |
| 1259 |
|
|
01251 } |
| 1260 |
|
|
01252 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strncmp(s, <span class="stringliteral">"include:"</span>, 7) == 0) |
| 1261 |
|
|
01253 { |
| 1262 |
|
|
01254 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"leaving function; returning %i (INCLUDE)\n"</span>, <a class="code" href="spf_8h.html#a90a66">INCLUDE</a>); |
| 1263 |
|
|
01255 |
| 1264 |
|
|
01256 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a90a66">INCLUDE</a>); |
| 1265 |
|
|
01257 } |
| 1266 |
|
|
01258 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strncmp(s, <span class="stringliteral">"exists:"</span>, 6) == 0) |
| 1267 |
|
|
01259 { |
| 1268 |
|
|
01260 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"leaving function; returning %i (EXISTS)\n"</span>, <a class="code" href="spf_8h.html#a90a72">EXISTS</a>); |
| 1269 |
|
|
01261 |
| 1270 |
|
|
01262 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a90a72">EXISTS</a>); |
| 1271 |
|
|
01263 } |
| 1272 |
|
|
01264 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strncmp(s, <span class="stringliteral">"redirect="</span>, 9) == 0) |
| 1273 |
|
|
01265 { |
| 1274 |
|
|
01266 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"leaving function; returning %i (REDIRECT)\n"</span>, <a class="code" href="spf_8h.html#a90a73">REDIRECT</a>); |
| 1275 |
|
|
01267 |
| 1276 |
|
|
01268 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a90a73">REDIRECT</a>); |
| 1277 |
|
|
01269 } |
| 1278 |
|
|
01270 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strncmp(s, <span class="stringliteral">"exp="</span>, 3) == 0) |
| 1279 |
|
|
01271 { |
| 1280 |
|
|
01272 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"leaving function; returning %i (EXPLAIN)\n"</span>, <a class="code" href="spf_8h.html#a90a74">EXPLAIN</a>); |
| 1281 |
|
|
01273 |
| 1282 |
|
|
01274 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a90a74">EXPLAIN</a>); |
| 1283 |
|
|
01275 } |
| 1284 |
|
|
01276 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strncmp(s, <span class="stringliteral">"default"</span>, 7) == 0) |
| 1285 |
|
|
01277 { |
| 1286 |
|
|
01278 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"leaving function; returning %i (DEFAULT)\n"</span>, <a class="code" href="spf_8h.html#a90a75">DEFAULT</a>); |
| 1287 |
|
|
01279 |
| 1288 |
|
|
01280 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a90a75">DEFAULT</a>); |
| 1289 |
|
|
01281 } |
| 1290 |
|
|
01282 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strstr(s, <span class="stringliteral">":"</span>)) |
| 1291 |
|
|
01283 { |
| 1292 |
|
|
01284 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"leaving function; returning %i (UNMECH)\n"</span>, <a class="code" href="spf_8h.html#a90a76">UNMECH</a>); |
| 1293 |
|
|
01285 |
| 1294 |
|
|
01286 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a90a76">UNMECH</a>); |
| 1295 |
|
|
01287 } |
| 1296 |
|
|
01288 |
| 1297 |
|
|
01289 <a class="code" href="util_8h.html#a11">xpprintf</a>(<span class="stringliteral">"leaving function; returning NO_POLICY\n"</span>); |
| 1298 |
|
|
01290 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a90a63">NO_POLICY</a>); |
| 1299 |
|
|
01291 } |
| 1300 |
|
|
01292 |
| 1301 |
|
|
01293 |
| 1302 |
|
|
01294 <span class="comment">/* UTIL_assoc_prefix</span> |
| 1303 |
|
|
01295 <span class="comment">*</span> |
| 1304 |
|
|
01296 <span class="comment">* Author: James Couzens <jcouzens@codeshare.ca></span> |
| 1305 |
|
|
01297 <span class="comment">*</span> |
| 1306 |
|
|
01298 <span class="comment">* Date: 01/28/04</span> |
| 1307 |
|
|
01299 <span class="comment">*</span> |
| 1308 |
|
|
01300 <span class="comment">* Desc:</span> |
| 1309 |
|
|
01301 <span class="comment">* Examins s and attempts to determine which SPF_MECHANISM_PREFIX</span> |
| 1310 |
|
|
01302 <span class="comment">* enumeration the string SPF_MATCHes based on the its contents (which is a</span> |
| 1311 |
|
|
01303 <span class="comment">* single char. Upon a SPF_PASS it stores the appropriate value inside of</span> |
| 1312 |
|
|
01304 <span class="comment">* the passed peer_info structure. SPF_TRUE upon success, SPF_FALSE upon failure.</span> |
| 1313 |
|
|
01305 <span class="comment">* Also upon failure SPF_ERROR (SPF_RESULT_TYPE) is stored in peer_info.</span> |
| 1314 |
|
|
01306 <span class="comment">*</span> |
| 1315 |
|
|
01307 <span class="comment">*</span> |
| 1316 |
|
|
01308 <span class="comment">*/</span> |
| 1317 |
|
|
<a name="l01309"></a><a class="code" href="util_8h.html#a47">01309</a> <a class="code" href="spf_8h.html#a35">SPF_BOOL</a> <a class="code" href="util_8h.html#a47">UTIL_assoc_prefix</a>(<a class="code" href="structpeer__info__s.html">peer_info_t</a> *p, <a class="code" href="spf_8h.html#a36">SPF_RESULT</a> res, <span class="keyword">const</span> <span class="keywordtype">char</span> *s) |
| 1318 |
|
|
01310 { |
| 1319 |
|
|
01311 int16_t pos; <span class="comment">/* position in s string */</span> |
| 1320 |
|
|
01312 |
| 1321 |
|
|
01313 |
| 1322 |
|
|
01314 <span class="comment">/* </span> |
| 1323 |
|
|
01315 <span class="comment"> * for whatever result happens to match the case, a debug string is </span> |
| 1324 |
|
|
01316 <span class="comment"> * printed (if compiled with), the level of recursion is made known through</span> |
| 1325 |
|
|
01317 <span class="comment"> * this. An appropriate SPF_RESULT is assigned to the passed peer_info_t </span> |
| 1326 |
|
|
01318 <span class="comment"> * structure's 'p->RES' variable. In addition a short SPF_RESULT string</span> |
| 1327 |
|
|
01319 <span class="comment"> * (here is an example use of the spf_result_t structure spoke of in SPF_init)</span> |
| 1328 |
|
|
01320 <span class="comment"> * is stored in 'p->rs', and finally an error string is stored in </span> |
| 1329 |
|
|
01321 <span class="comment"> * 'p->error'. This string encompasses all SPF query return types though,</span> |
| 1330 |
|
|
01322 <span class="comment"> * it is not only populated upon a parse error, so don't hesitate to reference</span> |
| 1331 |
|
|
01323 <span class="comment"> * it when looking for a verbose explanation as to the result of an SPF parse.</span> |
| 1332 |
|
|
01324 <span class="comment"> */</span> |
| 1333 |
|
|
01325 |
| 1334 |
|
|
01326 <span class="keywordflow">if</span> (s != NULL) |
| 1335 |
|
|
01327 { |
| 1336 |
|
|
01328 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"Entering function (%i) (%s)\n"</span>, res, s); |
| 1337 |
|
|
01329 |
| 1338 |
|
|
01330 <span class="comment">/* support for old school deprecated mechanism "default" */</span> |
| 1339 |
|
|
01331 <span class="keywordflow">if</span> (strncmp(s, <span class="stringliteral">"default"</span>, 7) == 0 && (pos = <a class="code" href="util_8h.html#a35">UTIL_index</a>(s, <span class="charliteral">'='</span>)) > 0) |
| 1340 |
|
|
01332 { |
| 1341 |
|
|
01333 s += (pos + 1); <span class="comment">/* move past default= */</span> |
| 1342 |
|
|
01334 <span class="keywordflow">if</span> (strncmp(s, <span class="stringliteral">"deny"</span>, 4) == 0) |
| 1343 |
|
|
01335 { |
| 1344 |
|
|
01336 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"Stored SPF_H_FAIL (%i) (%i)\n"</span>, |
| 1345 |
|
|
01337 res, <a class="code" href="spf_8h.html#a88a54">SPF_H_FAIL</a>); |
| 1346 |
|
|
01338 |
| 1347 |
|
|
01339 p-><a class="code" href="structpeer__info__s.html#o1">RES</a> = <a class="code" href="spf_8h.html#a88a54">SPF_H_FAIL</a>; |
| 1348 |
|
|
01340 p-><a class="code" href="structpeer__info__s.html#o7">rs</a> = p-><a class="code" href="structpeer__info__s.html#o25">spf_result</a>[<a class="code" href="spf_8h.html#a88a54">SPF_H_FAIL</a>].<a class="code" href="structspf__result__t.html#o1">s</a>; |
| 1349 |
|
|
01341 |
| 1350 |
|
|
01342 snprintf(p-><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">"policy result: (%s) from rule (%s)"</span>, |
| 1351 |
|
|
01343 p-><a class="code" href="structpeer__info__s.html#o7">rs</a>, p-><a class="code" href="structpeer__info__s.html#o23">last_m</a>); |
| 1352 |
|
|
01344 |
| 1353 |
|
|
01345 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a87a50">SPF_TRUE</a>); |
| 1354 |
|
|
01346 } |
| 1355 |
|
|
01347 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strncmp(s, <span class="stringliteral">"pass"</span>, 4) == 0) |
| 1356 |
|
|
01348 { |
| 1357 |
|
|
01349 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"Stored SPF_PASS (%i) (%i)\n"</span>, |
| 1358 |
|
|
01350 res, <a class="code" href="spf_8h.html#a88a51">SPF_PASS</a>); |
| 1359 |
|
|
01351 |
| 1360 |
|
|
01352 p-><a class="code" href="structpeer__info__s.html#o1">RES</a> = <a class="code" href="spf_8h.html#a88a51">SPF_PASS</a>; |
| 1361 |
|
|
01353 p-><a class="code" href="structpeer__info__s.html#o7">rs</a> = p-><a class="code" href="structpeer__info__s.html#o25">spf_result</a>[<a class="code" href="spf_8h.html#a88a51">SPF_PASS</a>].<a class="code" href="structspf__result__t.html#o1">s</a>; |
| 1362 |
|
|
01354 |
| 1363 |
|
|
01355 snprintf(p-><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">"policy result: (%s) from rule (%s)"</span>, |
| 1364 |
|
|
01356 p-><a class="code" href="structpeer__info__s.html#o7">rs</a>, p-><a class="code" href="structpeer__info__s.html#o23">last_m</a>); |
| 1365 |
|
|
01357 |
| 1366 |
|
|
01358 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a87a50">SPF_TRUE</a>); |
| 1367 |
|
|
01359 } |
| 1368 |
|
|
01360 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strncmp(s, <span class="stringliteral">"softdeny"</span>, 8) == 0) |
| 1369 |
|
|
01361 { |
| 1370 |
|
|
01362 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"Stored SPF_S_FAIL (%i) (%i)\n"</span>, |
| 1371 |
|
|
01363 res, <a class="code" href="spf_8h.html#a88a53">SPF_S_FAIL</a>); |
| 1372 |
|
|
01364 |
| 1373 |
|
|
01365 p-><a class="code" href="structpeer__info__s.html#o1">RES</a> = <a class="code" href="spf_8h.html#a88a53">SPF_S_FAIL</a>; |
| 1374 |
|
|
01366 p-><a class="code" href="structpeer__info__s.html#o7">rs</a> = p-><a class="code" href="structpeer__info__s.html#o25">spf_result</a>[<a class="code" href="spf_8h.html#a88a53">SPF_S_FAIL</a>].<a class="code" href="structspf__result__t.html#o1">s</a>; |
| 1375 |
|
|
01367 |
| 1376 |
|
|
01368 snprintf(p-><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">"policy result: (%s) from rule (%s)"</span>, |
| 1377 |
|
|
01369 p-><a class="code" href="structpeer__info__s.html#o7">rs</a>, p-><a class="code" href="structpeer__info__s.html#o23">last_m</a>); |
| 1378 |
|
|
01370 |
| 1379 |
|
|
01371 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a87a50">SPF_TRUE</a>); |
| 1380 |
|
|
01372 } |
| 1381 |
|
|
01373 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strncmp(s, <span class="stringliteral">"unknown"</span>, 7) == 0) |
| 1382 |
|
|
01374 { |
| 1383 |
|
|
01375 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"Stored SPF_NEUTRAL (%i) (%i)\n"</span>, |
| 1384 |
|
|
01376 res, <a class="code" href="spf_8h.html#a88a56">SPF_NEUTRAL</a>); |
| 1385 |
|
|
01377 |
| 1386 |
|
|
01378 p-><a class="code" href="structpeer__info__s.html#o1">RES</a> = <a class="code" href="spf_8h.html#a88a56">SPF_NEUTRAL</a>; |
| 1387 |
|
|
01379 p-><a class="code" href="structpeer__info__s.html#o7">rs</a> = p-><a class="code" href="structpeer__info__s.html#o25">spf_result</a>[<a class="code" href="spf_8h.html#a88a56">SPF_NEUTRAL</a>].<a class="code" href="structspf__result__t.html#o1">s</a>; |
| 1388 |
|
|
01380 |
| 1389 |
|
|
01381 snprintf(p-><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">"policy result: (%s) from rule (%s)"</span>, |
| 1390 |
|
|
01382 p-><a class="code" href="structpeer__info__s.html#o7">rs</a>, p-><a class="code" href="structpeer__info__s.html#o23">last_m</a>); |
| 1391 |
|
|
01383 |
| 1392 |
|
|
01384 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a87a50">SPF_TRUE</a>); |
| 1393 |
|
|
01385 } |
| 1394 |
|
|
01386 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strncmp(s, <span class="stringliteral">"include"</span>, 7) == 0) |
| 1395 |
|
|
01387 { |
| 1396 |
|
|
01388 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"Stored SPF_UNKNOWN (%i) (%i)\n"</span>, |
| 1397 |
|
|
01389 res, <a class="code" href="spf_8h.html#a88a57">SPF_UNKNOWN</a>); |
| 1398 |
|
|
01390 |
| 1399 |
|
|
01391 p-><a class="code" href="structpeer__info__s.html#o1">RES</a> = <a class="code" href="spf_8h.html#a88a57">SPF_UNKNOWN</a>; |
| 1400 |
|
|
01392 p-><a class="code" href="structpeer__info__s.html#o7">rs</a> = p-><a class="code" href="structpeer__info__s.html#o25">spf_result</a>[<a class="code" href="spf_8h.html#a88a57">SPF_UNKNOWN</a>].<a class="code" href="structspf__result__t.html#o1">s</a>; |
| 1401 |
|
|
01393 |
| 1402 |
|
|
01394 snprintf(p-><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">"policy result: (%s) from rule (%s)"</span>, |
| 1403 |
|
|
01395 p-><a class="code" href="structpeer__info__s.html#o7">rs</a>, p-><a class="code" href="structpeer__info__s.html#o23">last_m</a>); |
| 1404 |
|
|
01396 |
| 1405 |
|
|
01397 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a87a50">SPF_TRUE</a>); |
| 1406 |
|
|
01398 } |
| 1407 |
|
|
01399 <span class="keywordflow">else</span> |
| 1408 |
|
|
01400 { |
| 1409 |
|
|
01401 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"Stored SPF_ERROR (%i) (%i)\n"</span>, |
| 1410 |
|
|
01402 res, <a class="code" href="spf_8h.html#a88a55">SPF_ERROR</a>); |
| 1411 |
|
|
01403 |
| 1412 |
|
|
01404 p-><a class="code" href="structpeer__info__s.html#o1">RES</a> = <a class="code" href="spf_8h.html#a88a57">SPF_UNKNOWN</a>; |
| 1413 |
|
|
01405 p-><a class="code" href="structpeer__info__s.html#o7">rs</a> = p-><a class="code" href="structpeer__info__s.html#o25">spf_result</a>[<a class="code" href="spf_8h.html#a88a57">SPF_UNKNOWN</a>].<a class="code" href="structspf__result__t.html#o1">s</a>; |
| 1414 |
|
|
01406 |
| 1415 |
|
|
01407 snprintf(p-><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">"policy result: (%s) from rule (%s)"</span>, |
| 1416 |
|
|
01408 p-><a class="code" href="structpeer__info__s.html#o7">rs</a>, p-><a class="code" href="structpeer__info__s.html#o23">last_m</a>); |
| 1417 |
|
|
01409 |
| 1418 |
|
|
01410 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a87a49">SPF_FALSE</a>); |
| 1419 |
|
|
01411 } |
| 1420 |
|
|
01412 } |
| 1421 |
|
|
01413 } |
| 1422 |
|
|
01414 |
| 1423 |
|
|
01415 <span class="keywordflow">switch</span> (res) |
| 1424 |
|
|
01416 { |
| 1425 |
|
|
01417 |
| 1426 |
|
|
01418 <span class="comment">/* */</span> |
| 1427 |
|
|
01419 <span class="keywordflow">case</span> <a class="code" href="spf_8h.html#a88a51">SPF_PASS</a>: |
| 1428 |
|
|
01420 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"Stored SPF_PASS (%i) (%i)\n"</span>, |
| 1429 |
|
|
01421 res, <a class="code" href="spf_8h.html#a88a51">SPF_PASS</a>); |
| 1430 |
|
|
01422 |
| 1431 |
|
|
01423 p-><a class="code" href="structpeer__info__s.html#o1">RES</a> = <a class="code" href="spf_8h.html#a88a51">SPF_PASS</a>; |
| 1432 |
|
|
01424 p-><a class="code" href="structpeer__info__s.html#o7">rs</a> = p-><a class="code" href="structpeer__info__s.html#o25">spf_result</a>[<a class="code" href="spf_8h.html#a88a51">SPF_PASS</a>].<a class="code" href="structspf__result__t.html#o1">s</a>; |
| 1433 |
|
|
01425 |
| 1434 |
|
|
01426 snprintf(p-><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">"policy result: (%s) from rule (%s)"</span>, |
| 1435 |
|
|
01427 p-><a class="code" href="structpeer__info__s.html#o7">rs</a>, p-><a class="code" href="structpeer__info__s.html#o23">last_m</a>); |
| 1436 |
|
|
01428 |
| 1437 |
|
|
01429 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a87a50">SPF_TRUE</a>); |
| 1438 |
|
|
01430 |
| 1439 |
|
|
01431 <span class="comment">/* */</span> |
| 1440 |
|
|
01432 <span class="keywordflow">case</span> <a class="code" href="spf_8h.html#a88a52">SPF_NONE</a>: |
| 1441 |
|
|
01433 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"Stored SPF_NONE (%i) (%i)\n"</span>, |
| 1442 |
|
|
01434 res, <a class="code" href="spf_8h.html#a88a52">SPF_NONE</a>); |
| 1443 |
|
|
01435 |
| 1444 |
|
|
01436 p-><a class="code" href="structpeer__info__s.html#o1">RES</a> = <a class="code" href="spf_8h.html#a88a52">SPF_NONE</a>; |
| 1445 |
|
|
01437 p-><a class="code" href="structpeer__info__s.html#o7">rs</a> = p-><a class="code" href="structpeer__info__s.html#o25">spf_result</a>[<a class="code" href="spf_8h.html#a88a52">SPF_NONE</a>].<a class="code" href="structspf__result__t.html#o1">s</a>; |
| 1446 |
|
|
01438 |
| 1447 |
|
|
01439 snprintf(p-><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">"policy result: (%s) from rule (%s)"</span>, |
| 1448 |
|
|
01440 p-><a class="code" href="structpeer__info__s.html#o7">rs</a>, p-><a class="code" href="structpeer__info__s.html#o23">last_m</a>); |
| 1449 |
|
|
01441 |
| 1450 |
|
|
01442 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a87a50">SPF_TRUE</a>); |
| 1451 |
|
|
01443 |
| 1452 |
|
|
01444 <span class="comment">/* */</span> |
| 1453 |
|
|
01445 <span class="keywordflow">case</span> <a class="code" href="spf_8h.html#a88a53">SPF_S_FAIL</a>: |
| 1454 |
|
|
01446 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"Stored SPF_S_FAIL (%i) (%i)\n"</span>, |
| 1455 |
|
|
01447 res, <a class="code" href="spf_8h.html#a88a53">SPF_S_FAIL</a>); |
| 1456 |
|
|
01448 |
| 1457 |
|
|
01449 p-><a class="code" href="structpeer__info__s.html#o1">RES</a> = <a class="code" href="spf_8h.html#a88a53">SPF_S_FAIL</a>; |
| 1458 |
|
|
01450 p-><a class="code" href="structpeer__info__s.html#o7">rs</a> = p-><a class="code" href="structpeer__info__s.html#o25">spf_result</a>[<a class="code" href="spf_8h.html#a88a53">SPF_S_FAIL</a>].<a class="code" href="structspf__result__t.html#o1">s</a>; |
| 1459 |
|
|
01451 |
| 1460 |
|
|
01452 snprintf(p-><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">"policy result: (%s) from rule (%s)"</span>, |
| 1461 |
|
|
01453 p-><a class="code" href="structpeer__info__s.html#o7">rs</a>, p-><a class="code" href="structpeer__info__s.html#o23">last_m</a>); |
| 1462 |
|
|
01454 |
| 1463 |
|
|
01455 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a87a50">SPF_TRUE</a>); |
| 1464 |
|
|
01456 |
| 1465 |
|
|
01457 <span class="comment">/* */</span> |
| 1466 |
|
|
01458 <span class="keywordflow">case</span> <a class="code" href="spf_8h.html#a88a54">SPF_H_FAIL</a>: |
| 1467 |
|
|
01459 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"Stored SPF_H_FAIL (%i) (%i)\n"</span>, |
| 1468 |
|
|
01460 res, <a class="code" href="spf_8h.html#a88a54">SPF_H_FAIL</a>); |
| 1469 |
|
|
01461 |
| 1470 |
|
|
01462 p-><a class="code" href="structpeer__info__s.html#o1">RES</a> = <a class="code" href="spf_8h.html#a88a54">SPF_H_FAIL</a>; |
| 1471 |
|
|
01463 p-><a class="code" href="structpeer__info__s.html#o7">rs</a> = p-><a class="code" href="structpeer__info__s.html#o25">spf_result</a>[<a class="code" href="spf_8h.html#a88a54">SPF_H_FAIL</a>].<a class="code" href="structspf__result__t.html#o1">s</a>; |
| 1472 |
|
|
01464 |
| 1473 |
|
|
01465 snprintf(p-><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">"policy result: (%s) from rule (%s)"</span>, |
| 1474 |
|
|
01466 p-><a class="code" href="structpeer__info__s.html#o7">rs</a>, p-><a class="code" href="structpeer__info__s.html#o23">last_m</a>); |
| 1475 |
|
|
01467 |
| 1476 |
|
|
01468 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a87a50">SPF_TRUE</a>); |
| 1477 |
|
|
01469 |
| 1478 |
|
|
01470 <span class="comment">/* */</span> |
| 1479 |
|
|
01471 <span class="keywordflow">case</span> <a class="code" href="spf_8h.html#a88a56">SPF_NEUTRAL</a>: |
| 1480 |
|
|
01472 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"Stored SPF_NEUTRAL (%i) (%i)\n"</span>, |
| 1481 |
|
|
01473 res, <a class="code" href="spf_8h.html#a88a56">SPF_NEUTRAL</a>); |
| 1482 |
|
|
01474 |
| 1483 |
|
|
01475 p-><a class="code" href="structpeer__info__s.html#o1">RES</a> = <a class="code" href="spf_8h.html#a88a56">SPF_NEUTRAL</a>; |
| 1484 |
|
|
01476 p-><a class="code" href="structpeer__info__s.html#o7">rs</a> = p-><a class="code" href="structpeer__info__s.html#o25">spf_result</a>[<a class="code" href="spf_8h.html#a88a56">SPF_NEUTRAL</a>].<a class="code" href="structspf__result__t.html#o1">s</a>; |
| 1485 |
|
|
01477 |
| 1486 |
|
|
01478 snprintf(p-><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">"policy result: (%s) from rule (%s)"</span>, |
| 1487 |
|
|
01479 p-><a class="code" href="structpeer__info__s.html#o7">rs</a>, p-><a class="code" href="structpeer__info__s.html#o23">last_m</a>); |
| 1488 |
|
|
01480 |
| 1489 |
|
|
01481 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a87a50">SPF_TRUE</a>); |
| 1490 |
|
|
01482 |
| 1491 |
|
|
01483 <span class="comment">/* */</span> |
| 1492 |
|
|
01484 <span class="keywordflow">case</span> <a class="code" href="spf_8h.html#a88a57">SPF_UNKNOWN</a>: |
| 1493 |
|
|
01485 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"Stored SPF_UNKNOWN (%i) (%i)\n"</span>, |
| 1494 |
|
|
01486 res, <a class="code" href="spf_8h.html#a88a57">SPF_UNKNOWN</a>); |
| 1495 |
|
|
01487 |
| 1496 |
|
|
01488 p-><a class="code" href="structpeer__info__s.html#o1">RES</a> = <a class="code" href="spf_8h.html#a88a57">SPF_UNKNOWN</a>; |
| 1497 |
|
|
01489 p-><a class="code" href="structpeer__info__s.html#o7">rs</a> = p-><a class="code" href="structpeer__info__s.html#o25">spf_result</a>[<a class="code" href="spf_8h.html#a88a57">SPF_UNKNOWN</a>].<a class="code" href="structspf__result__t.html#o1">s</a>; |
| 1498 |
|
|
01490 |
| 1499 |
|
|
01491 snprintf(p-><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">"policy result: (%s) from rule (%s)"</span>, |
| 1500 |
|
|
01492 p-><a class="code" href="structpeer__info__s.html#o7">rs</a>, p-><a class="code" href="structpeer__info__s.html#o23">last_m</a>); |
| 1501 |
|
|
01493 |
| 1502 |
|
|
01494 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a87a50">SPF_TRUE</a>); |
| 1503 |
|
|
01495 |
| 1504 |
|
|
01496 <span class="comment">/* */</span> |
| 1505 |
|
|
01497 <span class="keywordflow">case</span> <a class="code" href="spf_8h.html#a88a55">SPF_ERROR</a>: |
| 1506 |
|
|
01498 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"Stored SPF_ERROR (%i) (%i)\n"</span>, |
| 1507 |
|
|
01499 p, <a class="code" href="spf_8h.html#a88a55">SPF_ERROR</a>); |
| 1508 |
|
|
01500 |
| 1509 |
|
|
01501 p-><a class="code" href="structpeer__info__s.html#o1">RES</a> = <a class="code" href="spf_8h.html#a88a55">SPF_ERROR</a>; |
| 1510 |
|
|
01502 p-><a class="code" href="structpeer__info__s.html#o7">rs</a> = p-><a class="code" href="structpeer__info__s.html#o25">spf_result</a>[<a class="code" href="spf_8h.html#a88a55">SPF_ERROR</a>].<a class="code" href="structspf__result__t.html#o1">s</a>; |
| 1511 |
|
|
01503 |
| 1512 |
|
|
01504 snprintf(p-><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">"policy result: (%s) from rule (%s)"</span>, |
| 1513 |
|
|
01505 p-><a class="code" href="structpeer__info__s.html#o7">rs</a>, p-><a class="code" href="structpeer__info__s.html#o23">last_m</a>); |
| 1514 |
|
|
01506 |
| 1515 |
|
|
01507 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a87a50">SPF_TRUE</a>); |
| 1516 |
|
|
01508 |
| 1517 |
|
|
01509 <span class="comment">/* */</span> |
| 1518 |
|
|
01510 <span class="keywordflow">case</span> <a class="code" href="spf_8h.html#a88a58">SPF_UNMECH</a>: |
| 1519 |
|
|
01511 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"Stored SPF_UNMECH (%i) (%i)\n"</span>, |
| 1520 |
|
|
01512 res, <a class="code" href="spf_8h.html#a88a58">SPF_UNMECH</a>); |
| 1521 |
|
|
01513 |
| 1522 |
|
|
01514 p-><a class="code" href="structpeer__info__s.html#o1">RES</a> = <a class="code" href="spf_8h.html#a88a58">SPF_UNMECH</a>; |
| 1523 |
|
|
01515 p-><a class="code" href="structpeer__info__s.html#o7">rs</a> = p-><a class="code" href="structpeer__info__s.html#o25">spf_result</a>[<a class="code" href="spf_8h.html#a88a58">SPF_UNMECH</a>].<a class="code" href="structspf__result__t.html#o1">s</a>; |
| 1524 |
|
|
01516 |
| 1525 |
|
|
01517 snprintf(p-><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">"policy result: (%s) from rule (%s)"</span>, |
| 1526 |
|
|
01518 p-><a class="code" href="structpeer__info__s.html#o7">rs</a>, p-><a class="code" href="structpeer__info__s.html#o23">last_m</a>); |
| 1527 |
|
|
01519 |
| 1528 |
|
|
01520 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a87a50">SPF_TRUE</a>); |
| 1529 |
|
|
01521 |
| 1530 |
|
|
01522 <span class="comment">/* */</span> |
| 1531 |
|
|
01523 <span class="keywordflow">default</span>: |
| 1532 |
|
|
01524 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"Stored SPF_PASS (%i) (%i)\n"</span>, |
| 1533 |
|
|
01525 res, <a class="code" href="spf_8h.html#a88a51">SPF_PASS</a>); |
| 1534 |
|
|
01526 |
| 1535 |
|
|
01527 p-><a class="code" href="structpeer__info__s.html#o1">RES</a> = <a class="code" href="spf_8h.html#a88a51">SPF_PASS</a>; |
| 1536 |
|
|
01528 p-><a class="code" href="structpeer__info__s.html#o7">rs</a> = p-><a class="code" href="structpeer__info__s.html#o25">spf_result</a>[<a class="code" href="spf_8h.html#a88a51">SPF_PASS</a>].<a class="code" href="structspf__result__t.html#o1">s</a>; |
| 1537 |
|
|
01529 |
| 1538 |
|
|
01530 snprintf(p-><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">"policy result: (%s) from rule (%s)"</span>, |
| 1539 |
|
|
01531 p-><a class="code" href="structpeer__info__s.html#o7">rs</a>, p-><a class="code" href="structpeer__info__s.html#o23">last_m</a>); |
| 1540 |
|
|
01532 |
| 1541 |
|
|
01533 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a87a50">SPF_TRUE</a>); |
| 1542 |
|
|
01534 } |
| 1543 |
|
|
01535 |
| 1544 |
|
|
01536 <a class="code" href="util_8h.html#a13">xepprintf</a>(<span class="stringliteral">"leaving function; returning SPF_FALSE.\n"</span>); |
| 1545 |
|
|
01537 |
| 1546 |
|
|
01538 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a87a49">SPF_FALSE</a>); |
| 1547 |
|
|
01539 } |
| 1548 |
|
|
01540 |
| 1549 |
|
|
01541 |
| 1550 |
|
|
01542 <span class="comment">/* UTIL_get_mech_prefix</span> |
| 1551 |
|
|
01543 <span class="comment">*</span> |
| 1552 |
|
|
01544 <span class="comment">* Author: James Couzens <jcouzens@codeshare.ca></span> |
| 1553 |
|
|
01545 <span class="comment">*</span> |
| 1554 |
|
|
01546 <span class="comment">* Date: 12/31/03</span> |
| 1555 |
|
|
01547 <span class="comment">*</span> |
| 1556 |
|
|
01548 <span class="comment">* Desc:</span> |
| 1557 |
|
|
01549 <span class="comment">* Examins s and attempts to determine which SPF_RESULT_P</span> |
| 1558 |
|
|
01550 <span class="comment">* enumeration the string SPF_MATCHes based on the its contents (which is a</span> |
| 1559 |
|
|
01551 <span class="comment">* single char. Returns SPF_PASS if a valid prefix is not specified.</span> |
| 1560 |
|
|
01552 <span class="comment">* Valid prefixes are: + (permit), - (deny), ~ (softfail) and ? (SPF_NEUTRAL).</span> |
| 1561 |
|
|
01553 <span class="comment">*</span> |
| 1562 |
|
|
01554 <span class="comment">*/</span> |
| 1563 |
|
|
<a name="l01555"></a><a class="code" href="util_8h.html#a46">01555</a> <a class="code" href="spf_8h.html#a36">SPF_RESULT</a> <a class="code" href="util_8h.html#a46">UTIL_get_mech_prefix</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) |
| 1564 |
|
|
01556 { |
| 1565 |
|
|
01557 int16_t pos; <span class="comment">/* position in s */</span> |
| 1566 |
|
|
01558 |
| 1567 |
|
|
01559 |
| 1568 |
|
|
01560 <span class="keywordflow">if</span> (s == NULL) |
| 1569 |
|
|
01561 { |
| 1570 |
|
|
01562 <a class="code" href="util_8h.html#a13">xepprintf</a>(<span class="stringliteral">"passed a NULL string. Abort!\n"</span>); |
| 1571 |
|
|
01563 |
| 1572 |
|
|
01564 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a88a55">SPF_ERROR</a>); |
| 1573 |
|
|
01565 } |
| 1574 |
|
|
01566 |
| 1575 |
|
|
01567 <a class="code" href="util_8h.html#a9">xprintf</a>(<span class="stringliteral">"called with char: (%s)\n"</span>, s); |
| 1576 |
|
|
01568 snprintf(p-><a class="code" href="structpeer__info__s.html#o23">last_m</a>, <a class="code" href="spf_8h.html#a14">SPF_MAX_HNAME</a>, <span class="stringliteral">"%s"</span>, s); |
| 1577 |
|
|
01569 |
| 1578 |
|
|
01570 <span class="keywordflow">switch</span> (*s) |
| 1579 |
|
|
01571 { |
| 1580 |
|
|
01572 |
| 1581 |
|
|
01573 <span class="comment">/* */</span> |
| 1582 |
|
|
01574 <span class="keywordflow">case</span> <span class="charliteral">'+'</span>: |
| 1583 |
|
|
01575 p-><a class="code" href="structpeer__info__s.html#o2">RES_P</a> = <a class="code" href="spf_8h.html#a88a51">SPF_PASS</a>; |
| 1584 |
|
|
01576 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"leaving function; returning SPF_PASS (%s) %i\n"</span>, |
| 1585 |
|
|
01577 s, <a class="code" href="spf_8h.html#a88a51">SPF_PASS</a>); |
| 1586 |
|
|
01578 |
| 1587 |
|
|
01579 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a88a51">SPF_PASS</a>); |
| 1588 |
|
|
01580 |
| 1589 |
|
|
01581 |
| 1590 |
|
|
01582 <span class="comment">/* */</span> |
| 1591 |
|
|
01583 <span class="keywordflow">case</span> <span class="charliteral">'-'</span>: |
| 1592 |
|
|
01584 p-><a class="code" href="structpeer__info__s.html#o2">RES_P</a> = <a class="code" href="spf_8h.html#a88a54">SPF_H_FAIL</a>; |
| 1593 |
|
|
01585 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"leaving function; returning SPF_H_FAIL (%s) %i\n"</span>, |
| 1594 |
|
|
01586 s, <a class="code" href="spf_8h.html#a88a54">SPF_H_FAIL</a>); |
| 1595 |
|
|
01587 |
| 1596 |
|
|
01588 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a88a54">SPF_H_FAIL</a>); |
| 1597 |
|
|
01589 |
| 1598 |
|
|
01590 <span class="comment">/* */</span> |
| 1599 |
|
|
01591 <span class="keywordflow">case</span> <span class="charliteral">'?'</span>: |
| 1600 |
|
|
01592 p-><a class="code" href="structpeer__info__s.html#o2">RES_P</a> = <a class="code" href="spf_8h.html#a88a56">SPF_NEUTRAL</a>; |
| 1601 |
|
|
01593 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"leaving function; returning SPF_NEUTRAL (%s) %i\n"</span>, |
| 1602 |
|
|
01594 s, <a class="code" href="spf_8h.html#a88a56">SPF_NEUTRAL</a>); |
| 1603 |
|
|
01595 |
| 1604 |
|
|
01596 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a88a56">SPF_NEUTRAL</a>); |
| 1605 |
|
|
01597 |
| 1606 |
|
|
01598 <span class="comment">/* */</span> |
| 1607 |
|
|
01599 <span class="keywordflow">case</span> <span class="charliteral">'~'</span>: |
| 1608 |
|
|
01600 p-><a class="code" href="structpeer__info__s.html#o2">RES_P</a> = <a class="code" href="spf_8h.html#a88a53">SPF_S_FAIL</a>; |
| 1609 |
|
|
01601 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"leaving function; returning SPF_S_FAIL (%s) %i\n"</span>, |
| 1610 |
|
|
01602 s, <a class="code" href="spf_8h.html#a88a53">SPF_S_FAIL</a>); |
| 1611 |
|
|
01603 |
| 1612 |
|
|
01604 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a88a53">SPF_S_FAIL</a>); |
| 1613 |
|
|
01605 |
| 1614 |
|
|
01606 <span class="comment">/* */</span> |
| 1615 |
|
|
01607 <span class="keywordflow">default</span>: |
| 1616 |
|
|
01608 <span class="keywordflow">if</span> (p-><a class="code" href="structpeer__info__s.html#o0">ALL</a> == <a class="code" href="spf_8h.html#a87a50">SPF_TRUE</a>) |
| 1617 |
|
|
01609 { |
| 1618 |
|
|
01610 p-><a class="code" href="structpeer__info__s.html#o2">RES_P</a> = <a class="code" href="spf_8h.html#a88a56">SPF_NEUTRAL</a>; |
| 1619 |
|
|
01611 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"leaving function; returning (def) SPF_NEUTRAL (%s) %i\n"</span>, |
| 1620 |
|
|
01612 s, <a class="code" href="spf_8h.html#a88a56">SPF_NEUTRAL</a>); |
| 1621 |
|
|
01613 } |
| 1622 |
|
|
01614 <span class="keywordflow">else</span> |
| 1623 |
|
|
01615 { |
| 1624 |
|
|
01616 p-><a class="code" href="structpeer__info__s.html#o2">RES_P</a> = <a class="code" href="spf_8h.html#a88a51">SPF_PASS</a>; |
| 1625 |
|
|
01617 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"leaving function; returning (def) SPF_PASS (%s) %i\n"</span>, |
| 1626 |
|
|
01618 s, <a class="code" href="spf_8h.html#a88a51">SPF_PASS</a>); |
| 1627 |
|
|
01619 } |
| 1628 |
|
|
01620 |
| 1629 |
|
|
01621 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"leaving function; returning (%i)\n"</span>, p-><a class="code" href="structpeer__info__s.html#o2">RES_P</a>); |
| 1630 |
|
|
01622 |
| 1631 |
|
|
01623 <span class="keywordflow">return</span>(p-><a class="code" href="structpeer__info__s.html#o2">RES_P</a>); |
| 1632 |
|
|
01624 } <span class="comment">/* switch */</span> |
| 1633 |
|
|
01625 |
| 1634 |
|
|
01626 <span class="comment">/*</span> |
| 1635 |
|
|
01627 <span class="comment"> * The code in the following statement is for the</span> |
| 1636 |
|
|
01628 <span class="comment"> * deprecated mechanism "default" and is only here to attempt</span> |
| 1637 |
|
|
01629 <span class="comment"> * to support exceptionally tardy early adopters whom likely</span> |
| 1638 |
|
|
01630 <span class="comment"> * at this time no longer exist. As such this code is not</span> |
| 1639 |
|
|
01631 <span class="comment"> * present in the current development versions of this library</span> |
| 1640 |
|
|
01632 <span class="comment"> */</span> |
| 1641 |
|
|
01633 <span class="keywordflow">if</span> ((pos = <a class="code" href="util_8h.html#a35">UTIL_index</a>(s, <span class="charliteral">'='</span>)) > 0) |
| 1642 |
|
|
01634 { |
| 1643 |
|
|
01635 s += (pos + 1); <span class="comment">/* move past default= */</span> |
| 1644 |
|
|
01636 |
| 1645 |
|
|
01637 <span class="keywordflow">if</span> (strncmp(s, <span class="stringliteral">"deny"</span>, 4) == 0) |
| 1646 |
|
|
01638 { |
| 1647 |
|
|
01639 p-><a class="code" href="structpeer__info__s.html#o2">RES_P</a> = <a class="code" href="spf_8h.html#a88a54">SPF_H_FAIL</a>; |
| 1648 |
|
|
01640 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"leaving function; returning SPF_H_FAIL on (%s)\n"</span>, s); |
| 1649 |
|
|
01641 |
| 1650 |
|
|
01642 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a88a54">SPF_H_FAIL</a>); |
| 1651 |
|
|
01643 } |
| 1652 |
|
|
01644 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strncmp(s, <span class="stringliteral">"pass"</span>, 4) == 0) |
| 1653 |
|
|
01645 { |
| 1654 |
|
|
01646 p-><a class="code" href="structpeer__info__s.html#o2">RES_P</a> = <a class="code" href="spf_8h.html#a88a51">SPF_PASS</a>; |
| 1655 |
|
|
01647 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"leaving function; returning SPF_PASS on (%s)\n"</span>, s); |
| 1656 |
|
|
01648 |
| 1657 |
|
|
01649 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a88a51">SPF_PASS</a>); |
| 1658 |
|
|
01650 } |
| 1659 |
|
|
01651 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strncmp(s, <span class="stringliteral">"softdeny"</span>, 8) == 0) |
| 1660 |
|
|
01652 { |
| 1661 |
|
|
01653 p-><a class="code" href="structpeer__info__s.html#o2">RES_P</a> = <a class="code" href="spf_8h.html#a88a53">SPF_S_FAIL</a>; |
| 1662 |
|
|
01654 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"leaving function; returning SPF_S_FAIL on (%s)\n"</span>, s); |
| 1663 |
|
|
01655 |
| 1664 |
|
|
01656 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a88a53">SPF_S_FAIL</a>); |
| 1665 |
|
|
01657 } |
| 1666 |
|
|
01658 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strncmp(s, <span class="stringliteral">"unknown"</span>, 7) == 0) |
| 1667 |
|
|
01659 { |
| 1668 |
|
|
01660 p-><a class="code" href="structpeer__info__s.html#o2">RES_P</a> = <a class="code" href="spf_8h.html#a88a56">SPF_NEUTRAL</a>; |
| 1669 |
|
|
01661 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"leaving function; returning SPF_NEUTRAL on (%s)\n"</span>, s); |
| 1670 |
|
|
01662 |
| 1671 |
|
|
01663 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a88a56">SPF_NEUTRAL</a>); |
| 1672 |
|
|
01664 } |
| 1673 |
|
|
01665 <span class="keywordflow">else</span> |
| 1674 |
|
|
01666 { |
| 1675 |
|
|
01667 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"leaving function; returning SPF_NEUTRAL on (%s)\n"</span>, s); |
| 1676 |
|
|
01668 |
| 1677 |
|
|
01669 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a88a56">SPF_NEUTRAL</a>); |
| 1678 |
|
|
01670 } |
| 1679 |
|
|
01671 } |
| 1680 |
|
|
01672 |
| 1681 |
|
|
01673 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"leaving function; returning SPF_ERROR on (%s)\n"</span>, s); |
| 1682 |
|
|
01674 |
| 1683 |
|
|
01675 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a88a55">SPF_ERROR</a>); |
| 1684 |
|
|
01676 } |
| 1685 |
|
|
01677 |
| 1686 |
|
|
01678 |
| 1687 |
|
|
01679 <span class="comment">/* UTIL_expand_ip</span> |
| 1688 |
|
|
01680 <span class="comment">*</span> |
| 1689 |
|
|
01681 <span class="comment">* Author: James Couzens <jcouzens@codeshare.ca></span> |
| 1690 |
|
|
01682 <span class="comment">*</span> |
| 1691 |
|
|
01683 <span class="comment">* Date: 12/26/03</span> |
| 1692 |
|
|
01684 <span class="comment">*</span> |
| 1693 |
|
|
01685 <span class="comment">* Desc:</span> |
| 1694 |
|
|
01686 <span class="comment">* Expands an ip4 policy mechanism string into a policy_addr_t</span> |
| 1695 |
|
|
01687 <span class="comment">* structure which it allocates memory for and then returns. The RFC</span> |
| 1696 |
|
|
01688 <span class="comment">* specifies that if a cidr block is not specified then /32 isused.</span> |
| 1697 |
|
|
01689 <span class="comment">*</span> |
| 1698 |
|
|
01690 <span class="comment">* On success returns a pointer to a policy_addr_t structure, on</span> |
| 1699 |
|
|
01691 <span class="comment">* SPF_ERROR returns NULL.</span> |
| 1700 |
|
|
01692 <span class="comment">*</span> |
| 1701 |
|
|
01693 <span class="comment">*/</span> |
| 1702 |
|
|
<a name="l01694"></a><a class="code" href="util_8h.html#a48">01694</a> <a class="code" href="structpolicy__addr__s.html">policy_addr_t</a> *<a class="code" href="util_8h.html#a48">UTIL_expand_ip</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> *s) |
| 1703 |
|
|
01695 { |
| 1704 |
|
|
01696 int8_t cidr = 0; <span class="comment">/* temporary storage for netmask */</span> |
| 1705 |
|
|
01697 |
| 1706 |
|
|
01698 size_t len; <span class="comment">/* length of string passed */</span> |
| 1707 |
|
|
01699 size_t pos; <span class="comment">/* position of break points in string */</span> |
| 1708 |
|
|
01700 |
| 1709 |
|
|
01701 <span class="keywordtype">char</span> *ip; <span class="comment">/* temporary storage for ip address */</span> |
| 1710 |
|
|
01702 |
| 1711 |
|
|
01703 <span class="keyword">const</span> <span class="keywordtype">char</span> *token_ptr; <span class="comment">/* our position in the token */</span> |
| 1712 |
|
|
01704 |
| 1713 |
|
|
01705 <a class="code" href="structpolicy__addr__s.html">policy_addr_t</a> *policy_addr; <span class="comment">/* ip/mask return structure */</span> |
| 1714 |
|
|
01706 |
| 1715 |
|
|
01707 |
| 1716 |
|
|
01708 <span class="keywordflow">if</span> (s == NULL) |
| 1717 |
|
|
01709 { |
| 1718 |
|
|
01710 <a class="code" href="util_8h.html#a13">xepprintf</a>(<span class="stringliteral">"passed a NULL string. Abort!\n"</span>); |
| 1719 |
|
|
01711 |
| 1720 |
|
|
01712 <span class="keywordflow">return</span>(NULL); |
| 1721 |
|
|
01713 } |
| 1722 |
|
|
01714 |
| 1723 |
|
|
01715 len = strlen(s); |
| 1724 |
|
|
01716 token_ptr = s; |
| 1725 |
|
|
01717 |
| 1726 |
|
|
01718 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"called with string: (%s)\n"</span>, token_ptr); |
| 1727 |
|
|
01719 |
| 1728 |
|
|
01720 <span class="keywordflow">if</span> ((pos = <a class="code" href="util_8h.html#a35">UTIL_index</a>(token_ptr, <span class="charliteral">':'</span>)) == 0) |
| 1729 |
|
|
01721 { |
| 1730 |
|
|
01722 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"SPF_ERROR: Unable to get position on token (%s)\n"</span>, |
| 1731 |
|
|
01723 token_ptr); |
| 1732 |
|
|
01724 |
| 1733 |
|
|
01725 <span class="keywordflow">return</span>(NULL); |
| 1734 |
|
|
01726 } |
| 1735 |
|
|
01727 |
| 1736 |
|
|
01728 <span class="comment">/* jump past the ip4: portion */</span> |
| 1737 |
|
|
01729 token_ptr += pos + 1; |
| 1738 |
|
|
01730 |
| 1739 |
|
|
01731 policy_addr = <a class="code" href="util_8h.html#a4">xmalloc</a>(<a class="code" href="util_8h.html#a3">SIZEOF</a>(<a class="code" href="structpolicy__addr__s.html">policy_addr_t</a>)); |
| 1740 |
|
|
01732 |
| 1741 |
|
|
01733 <span class="comment">/* jump past the ip4: portion (to get length of ip) */</span> |
| 1742 |
|
|
01734 <span class="keywordflow">if</span> ((pos = <a class="code" href="util_8h.html#a35">UTIL_index</a>(token_ptr, <span class="charliteral">'/'</span>)) == 0) |
| 1743 |
|
|
01735 { |
| 1744 |
|
|
01736 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"Unable to get position on token (%s), assuming /32 cidr "</span> \ |
| 1745 |
|
|
01737 <span class="stringliteral">"block\n"</span>, token_ptr); |
| 1746 |
|
|
01738 |
| 1747 |
|
|
01739 pos = strlen(token_ptr); |
| 1748 |
|
|
01740 cidr = 32; |
| 1749 |
|
|
01741 } |
| 1750 |
|
|
01742 |
| 1751 |
|
|
01743 <span class="comment">/* allocate space and dump the ip address there */</span> |
| 1752 |
|
|
01744 ip = <a class="code" href="util_8h.html#a8">xstrndup</a>(token_ptr, (pos + 1)); |
| 1753 |
|
|
01745 |
| 1754 |
|
|
01746 <span class="comment">/* copy it over to the policy_addr structure */</span> |
| 1755 |
|
|
01747 <span class="keywordflow">if</span> ((inet_pton(AF_INET, ip, &policy_addr-><a class="code" href="structpolicy__addr__s.html#o2">addr</a>)) == 0) |
| 1756 |
|
|
01748 { |
| 1757 |
|
|
01749 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"SPF_ERROR: inet_pton unable to convert ip to binary "</span> \ |
| 1758 |
|
|
01750 <span class="stringliteral">"(%s)\n"</span>, ip); |
| 1759 |
|
|
01751 |
| 1760 |
|
|
01752 <a class="code" href="util_8h.html#a6">xfree</a>(ip); |
| 1761 |
|
|
01753 <span class="keywordflow">return</span>(NULL); |
| 1762 |
|
|
01754 } |
| 1763 |
|
|
01755 |
| 1764 |
|
|
01756 <span class="keywordflow">if</span> (cidr != 32) |
| 1765 |
|
|
01757 { |
| 1766 |
|
|
01758 token_ptr += (pos + 1); <span class="comment">/* skip over the forward slash */</span> |
| 1767 |
|
|
01759 cidr = atoi(token_ptr); <span class="comment">/* convert the string to an integer */</span> |
| 1768 |
|
|
01760 } |
| 1769 |
|
|
01761 |
| 1770 |
|
|
01762 <a class="code" href="util_8h.html#a6">xfree</a>(ip); |
| 1771 |
|
|
01763 |
| 1772 |
|
|
01764 <span class="keywordflow">if</span> ((cidr < 0) || (cidr > 32)) |
| 1773 |
|
|
01765 { |
| 1774 |
|
|
01766 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"ERROR: cidr violation (%u)\n"</span>, cidr); |
| 1775 |
|
|
01767 |
| 1776 |
|
|
01768 <span class="keywordflow">return</span>(NULL); |
| 1777 |
|
|
01769 } |
| 1778 |
|
|
01770 |
| 1779 |
|
|
01771 policy_addr-><a class="code" href="structpolicy__addr__s.html#o1">cidr</a> = cidr; <span class="comment">/* copy it over to the policy_addr structure */</span> |
| 1780 |
|
|
01772 |
| 1781 |
|
|
01773 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"CIDR: (%i) IP: (%s)\n"</span>, |
| 1782 |
|
|
01774 policy_addr-><a class="code" href="structpolicy__addr__s.html#o1">cidr</a>, inet_ntoa(policy_addr-><a class="code" href="structpolicy__addr__s.html#o2">addr</a>)); |
| 1783 |
|
|
01775 |
| 1784 |
|
|
01776 <span class="keywordflow">return</span>(policy_addr); |
| 1785 |
|
|
01777 } |
| 1786 |
|
|
01778 |
| 1787 |
|
|
01779 |
| 1788 |
|
|
01780 <span class="comment">/* UTIL_is_ip</span> |
| 1789 |
|
|
01781 <span class="comment">*</span> |
| 1790 |
|
|
01782 <span class="comment">* Author: James Couzens <jcouzens@codeshare.ca></span> |
| 1791 |
|
|
01783 <span class="comment">*</span> |
| 1792 |
|
|
01784 <span class="comment">* Date: 01/18/04</span> |
| 1793 |
|
|
01785 <span class="comment">*</span> |
| 1794 |
|
|
01786 <span class="comment">* Desc:</span> |
| 1795 |
|
|
01787 <span class="comment">* Is the passed string (limited to between 0 - 255 by type)</span> |
| 1796 |
|
|
01788 <span class="comment">* contains a valid ip address or not. I'm not sure if this is useful</span> |
| 1797 |
|
|
01789 <span class="comment">* anymore but at one point I was using it to tell if the passed macro</span> |
| 1798 |
|
|
01790 <span class="comment">* contained an ip address or not when passed as a string.</span> |
| 1799 |
|
|
01791 <span class="comment">*</span> |
| 1800 |
|
|
01792 <span class="comment">*/</span> |
| 1801 |
|
|
<a name="l01793"></a><a class="code" href="util_8h.html#a49">01793</a> <a class="code" href="spf_8h.html#a35">SPF_BOOL</a> <a class="code" href="util_8h.html#a49">UTIL_is_ip</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> *<span class="keywordtype">id</span>) |
| 1802 |
|
|
01794 { |
| 1803 |
|
|
01795 u_int8_t i = 0; <span class="comment">/* utility */</span> |
| 1804 |
|
|
01796 |
| 1805 |
|
|
01797 <span class="keywordflow">if</span> (!<span class="keywordtype">id</span>) |
| 1806 |
|
|
01798 { |
| 1807 |
|
|
01799 <a class="code" href="util_8h.html#a13">xepprintf</a>(<span class="stringliteral">"called without an IP address!\n"</span>); |
| 1808 |
|
|
01800 |
| 1809 |
|
|
01801 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a87a49">SPF_FALSE</a>); |
| 1810 |
|
|
01802 } |
| 1811 |
|
|
01803 |
| 1812 |
|
|
01804 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"called with address: (%s)\n"</span>, <span class="keywordtype">id</span>); |
| 1813 |
|
|
01805 |
| 1814 |
|
|
01806 <span class="keywordflow">while</span> (*id) |
| 1815 |
|
|
01807 { |
| 1816 |
|
|
01808 <span class="keywordflow">if</span> (*<span class="keywordtype">id</span> == <span class="charliteral">'.'</span>) |
| 1817 |
|
|
01809 { |
| 1818 |
|
|
01810 i++; |
| 1819 |
|
|
01811 } |
| 1820 |
|
|
01812 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (isdigit(*<span class="keywordtype">id</span>) == 0) |
| 1821 |
|
|
01813 { |
| 1822 |
|
|
01814 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a87a49">SPF_FALSE</a>); |
| 1823 |
|
|
01815 } |
| 1824 |
|
|
01816 <span class="keywordtype">id</span>++; |
| 1825 |
|
|
01817 } |
| 1826 |
|
|
01818 |
| 1827 |
|
|
01819 <span class="keywordflow">if</span> (i == 3) |
| 1828 |
|
|
01820 { |
| 1829 |
|
|
01821 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a87a50">SPF_TRUE</a>); |
| 1830 |
|
|
01822 } |
| 1831 |
|
|
01823 |
| 1832 |
|
|
01824 <a class="code" href="util_8h.html#a11">xpprintf</a>(<span class="stringliteral">"leaving function; returning SPF_FALSE\n"</span>); |
| 1833 |
|
|
01825 |
| 1834 |
|
|
01826 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a87a49">SPF_FALSE</a>); |
| 1835 |
|
|
01827 } |
| 1836 |
|
|
01828 |
| 1837 |
|
|
01829 |
| 1838 |
|
|
01830 <span class="comment">/* UTIL_rev_addr</span> |
| 1839 |
|
|
01831 <span class="comment">*</span> |
| 1840 |
|
|
01832 <span class="comment">* Author: James Couzens <jcouzens@codeshare.ca></span> |
| 1841 |
|
|
01833 <span class="comment">*</span> |
| 1842 |
|
|
01834 <span class="comment">* Date: 01/04/04</span> |
| 1843 |
|
|
01835 <span class="comment">*</span> |
| 1844 |
|
|
01836 <span class="comment">* Desc:</span> |
| 1845 |
|
|
01837 <span class="comment">* Using a passed ip address it will reverse it and slap</span> |
| 1846 |
|
|
01838 <span class="comment">* .in-addr.arpa on the end of it making it ready for a proper PTR query</span> |
| 1847 |
|
|
01839 <span class="comment">*</span> |
| 1848 |
|
|
01840 <span class="comment">* Notes: Write additional code to handle IP6 addresses</span> |
| 1849 |
|
|
01841 <span class="comment">*</span> |
| 1850 |
|
|
01842 <span class="comment">*/</span> |
| 1851 |
|
|
<a name="l01843"></a><a class="code" href="util_8h.html#a50">01843</a> <span class="keywordtype">char</span> *<a class="code" href="util_8h.html#a50">UTIL_rev_addr</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> *s) |
| 1852 |
|
|
01844 { |
| 1853 |
|
|
01845 u_int8_t i = 0; <span class="comment">/* utility */</span> |
| 1854 |
|
|
01846 u_int8_t tmp[4][1]; <span class="comment">/* temporary storage for ip integers */</span> |
| 1855 |
|
|
01847 |
| 1856 |
|
|
01848 u_int16_t len = 0; <span class="comment">/* length of to be allocated string */</span> |
| 1857 |
|
|
01849 |
| 1858 |
|
|
01850 <span class="keywordtype">char</span> *cp; <span class="comment">/* copy of passed string */</span> |
| 1859 |
|
|
01851 <span class="keywordtype">char</span> *token; <span class="comment">/* token for splitting apart ip address */</span> |
| 1860 |
|
|
01852 <span class="keywordtype">char</span> *new_addr; <span class="comment">/* allocate string for reversed address */</span> |
| 1861 |
|
|
01853 |
| 1862 |
|
|
01854 |
| 1863 |
|
|
01855 <span class="keywordflow">if</span> (s == NULL) |
| 1864 |
|
|
01856 { |
| 1865 |
|
|
01857 <a class="code" href="util_8h.html#a13">xepprintf</a>(<span class="stringliteral">"passed a null string. Abort!\n"</span>); |
| 1866 |
|
|
01858 |
| 1867 |
|
|
01859 <span class="keywordflow">return</span>(NULL); |
| 1868 |
|
|
01860 } |
| 1869 |
|
|
01861 |
| 1870 |
|
|
01862 len = (strlen(s) + 1); |
| 1871 |
|
|
01863 |
| 1872 |
|
|
01864 <a class="code" href="util_8h.html#a9">xprintf</a>(<span class="stringliteral">"called with: (%s) len: (%i)\n"</span>, s, (len - 1)); |
| 1873 |
|
|
01865 |
| 1874 |
|
|
01866 cp = <a class="code" href="util_8h.html#a8">xstrndup</a>(s, len); |
| 1875 |
|
|
01867 token = strtok(cp, <span class="stringliteral">"."</span>); |
| 1876 |
|
|
01868 |
| 1877 |
|
|
01869 <span class="keywordflow">while</span> ((token != NULL) && (i <= 3)) |
| 1878 |
|
|
01870 { |
| 1879 |
|
|
01871 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"token : (%s)\n"</span>, token); |
| 1880 |
|
|
01872 |
| 1881 |
|
|
01873 tmp[i][0] = atoi(token); |
| 1882 |
|
|
01874 token = strtok(NULL, <span class="stringliteral">"."</span>); |
| 1883 |
|
|
01875 i++; |
| 1884 |
|
|
01876 } |
| 1885 |
|
|
01877 |
| 1886 |
|
|
01878 <a class="code" href="util_8h.html#a6">xfree</a>(cp); |
| 1887 |
|
|
01879 |
| 1888 |
|
|
01880 <span class="comment">/* + .in-addr.arpa\0 */</span> |
| 1889 |
|
|
01881 new_addr = <a class="code" href="util_8h.html#a4">xmalloc</a>(len + 13); |
| 1890 |
|
|
01882 |
| 1891 |
|
|
01883 snprintf(new_addr, (len + 13), <span class="stringliteral">"%u.%u.%u.%u.in-addr.arpa"</span>, |
| 1892 |
|
|
01884 tmp[3][0], tmp[2][0], tmp[1][0], tmp[0][0]); |
| 1893 |
|
|
01885 |
| 1894 |
|
|
01886 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"leaving function; returning reversed ip: %s\n"</span>, new_addr); |
| 1895 |
|
|
01887 |
| 1896 |
|
|
01888 <span class="keywordflow">return</span>(new_addr); |
| 1897 |
|
|
01889 } |
| 1898 |
|
|
01890 |
| 1899 |
|
|
01891 |
| 1900 |
|
|
01892 <span class="comment">/* UTIL_get_dname</span> |
| 1901 |
|
|
01893 <span class="comment">*</span> |
| 1902 |
|
|
01894 <span class="comment">* Author: James Couzens <jcouzens@codeshare.ca></span> |
| 1903 |
|
|
01895 <span class="comment">*</span> |
| 1904 |
|
|
01896 <span class="comment">* Date: 01/27/04</span> |
| 1905 |
|
|
01897 <span class="comment">*</span> |
| 1906 |
|
|
01898 <span class="comment">* Desc:</span> |
| 1907 |
|
|
01899 <span class="comment">* s contains a hostname which is then looked through and split</span> |
| 1908 |
|
|
01900 <span class="comment">* apart, always leaving one '.' delimiter left so you are left with</span> |
| 1909 |
|
|
01901 <span class="comment">* domain.tld. domain.tld is then put into newly allocated memory and</span> |
| 1910 |
|
|
01902 <span class="comment">* returned to the calling function. Upon failure, returns NULL.</span> |
| 1911 |
|
|
01903 <span class="comment">* Calling function is required to free the memory.</span> |
| 1912 |
|
|
01904 <span class="comment">*</span> |
| 1913 |
|
|
01905 <span class="comment">*/</span> |
| 1914 |
|
|
<a name="l01906"></a><a class="code" href="util_8h.html#a51">01906</a> <span class="keywordtype">char</span> *<a class="code" href="util_8h.html#a51">UTIL_get_dname</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> *s) |
| 1915 |
|
|
01907 { |
| 1916 |
|
|
01908 u_int8_t i = 0; <span class="comment">/* how many delimiters in s */</span> |
| 1917 |
|
|
01909 |
| 1918 |
|
|
01910 <span class="keywordtype">char</span> *buf = NULL; <span class="comment">/* return string to be allocated */</span> |
| 1919 |
|
|
01911 |
| 1920 |
|
|
01912 |
| 1921 |
|
|
01913 <span class="keywordflow">if</span> (s == NULL) |
| 1922 |
|
|
01914 { |
| 1923 |
|
|
01915 <a class="code" href="util_8h.html#a13">xepprintf</a>(<span class="stringliteral">"called with NULL. Abort!\n"</span>); |
| 1924 |
|
|
01916 |
| 1925 |
|
|
01917 <span class="keywordflow">return</span>(NULL); |
| 1926 |
|
|
01918 } |
| 1927 |
|
|
01919 |
| 1928 |
|
|
01920 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"called with (%s)\n"</span>, s); |
| 1929 |
|
|
01921 |
| 1930 |
|
|
01922 i = <a class="code" href="util_8h.html#a38">UTIL_count_delim</a>(s, <span class="charliteral">'.'</span>); |
| 1931 |
|
|
01923 |
| 1932 |
|
|
01924 <span class="keywordflow">switch</span> (i) |
| 1933 |
|
|
01925 { |
| 1934 |
|
|
01926 <span class="keywordflow">case</span> 0: |
| 1935 |
|
|
01927 <span class="keywordflow">break</span>; |
| 1936 |
|
|
01928 <span class="keywordflow">case</span> 1: |
| 1937 |
|
|
01929 buf = <a class="code" href="util_8h.html#a8">xstrndup</a>(s, (strlen(s) + 1)); |
| 1938 |
|
|
01930 <a class="code" href="util_8h.html#a9">xprintf</a>(<span class="stringliteral">"leaving function; returning buffer: (%s)\n"</span>, buf); |
| 1939 |
|
|
01931 |
| 1940 |
|
|
01932 <span class="keywordflow">return</span>(buf); |
| 1941 |
|
|
01933 <span class="keywordflow">default</span>: |
| 1942 |
|
|
01934 buf = <a class="code" href="util_8h.html#a36">UTIL_split_str</a>(s, <span class="charliteral">'.'</span>, (i - 1)); |
| 1943 |
|
|
01935 <a class="code" href="util_8h.html#a9">xprintf</a>(<span class="stringliteral">"leaving function; returning buffer: (%s)\n"</span>, buf); |
| 1944 |
|
|
01936 |
| 1945 |
|
|
01937 <span class="keywordflow">return</span>(buf); |
| 1946 |
|
|
01938 } |
| 1947 |
|
|
01939 |
| 1948 |
|
|
01940 <a class="code" href="util_8h.html#a13">xepprintf</a>(<span class="stringliteral">"leaving function; returning NULL\n"</span>); |
| 1949 |
|
|
01941 |
| 1950 |
|
|
01942 <span class="keywordflow">return</span>(NULL); |
| 1951 |
|
|
01943 } |
| 1952 |
|
|
01944 |
| 1953 |
|
|
01945 |
| 1954 |
|
|
01946 <span class="comment">/* UTIL_cidr_cmp</span> |
| 1955 |
|
|
01947 <span class="comment">*</span> |
| 1956 |
|
|
01948 <span class="comment">* Author: James Couzens <jcouzens@codeshare.ca></span> |
| 1957 |
|
|
01949 <span class="comment">*</span> |
| 1958 |
|
|
01950 <span class="comment">* Date: 12/26/03</span> |
| 1959 |
|
|
01951 <span class="comment">*</span> |
| 1960 |
|
|
01952 <span class="comment">* Desc:</span> |
| 1961 |
|
|
01953 <span class="comment">* Compares an IP address (connected peer) against another IP</span> |
| 1962 |
|
|
01954 <span class="comment">* address (found in a policy lookup) using a netmask (also found from</span> |
| 1963 |
|
|
01955 <span class="comment">* a policy lookup) to see if the peer address is legal within that</span> |
| 1964 |
|
|
01956 <span class="comment">* netmask. Returns SPF_TRUE if its valid, SPF_FALSE if not.</span> |
| 1965 |
|
|
01957 <span class="comment">*</span> |
| 1966 |
|
|
01958 <span class="comment">* Notes: Write additional comparisons to handle IP6 addresses</span> |
| 1967 |
|
|
01959 <span class="comment">*</span> |
| 1968 |
|
|
01960 <span class="comment">*/</span> |
| 1969 |
|
|
<a name="l01961"></a><a class="code" href="util_8h.html#a52">01961</a> <a class="code" href="spf_8h.html#a35">SPF_BOOL</a> <a class="code" href="util_8h.html#a52">UTIL_cidr_cmp</a>(<span class="keyword">const</span> <a class="code" href="structpolicy__addr__s.html">policy_addr_t</a> *policy_addr, <span class="keyword">const</span> <span class="keyword">struct</span> in_addr |
| 1970 |
|
|
01962 *peer_addr) |
| 1971 |
|
|
01963 { |
| 1972 |
|
|
01964 u_int32_t a; <span class="comment">/* working buf */</span> |
| 1973 |
|
|
01965 u_int32_t b; <span class="comment">/* working buf */</span> |
| 1974 |
|
|
01966 |
| 1975 |
|
|
01967 <span class="keywordtype">char</span> *peer_ip = NULL; <span class="comment">/* ip address of connected peer */</span> |
| 1976 |
|
|
01968 <span class="keywordtype">char</span> *policy_ip = NULL; <span class="comment">/* ip address of current SPF policy */</span> |
| 1977 |
|
|
01969 |
| 1978 |
|
|
01970 |
| 1979 |
|
|
01971 <span class="keywordflow">if</span> ((policy_addr-><a class="code" href="structpolicy__addr__s.html#o2">addr</a>.s_addr <= 0) && (peer_addr->s_addr <= 0)) |
| 1980 |
|
|
01972 { |
| 1981 |
|
|
01973 <a class="code" href="util_8h.html#a13">xepprintf</a>(<span class="stringliteral">"Passed with NULL chars. Aborting.\n"</span>); |
| 1982 |
|
|
01974 |
| 1983 |
|
|
01975 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a87a49">SPF_FALSE</a>); |
| 1984 |
|
|
01976 } |
| 1985 |
|
|
01977 |
| 1986 |
|
|
01978 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"POL: %lu PEER: %lu CIDR: %i\n"</span>, policy_addr-><a class="code" href="structpolicy__addr__s.html#o2">addr</a>.s_addr, |
| 1987 |
|
|
01979 peer_addr->s_addr, policy_addr-><a class="code" href="structpolicy__addr__s.html#o1">cidr</a>); |
| 1988 |
|
|
01980 |
| 1989 |
|
|
01981 <span class="comment">/*</span> |
| 1990 |
|
|
01982 <span class="comment"> * Packets come in off the wire in whats called "network byte order"</span> |
| 1991 |
|
|
01983 <span class="comment"> * which does't work very well when trying to compute if one address</span> |
| 1992 |
|
|
01984 <span class="comment"> * is masked by another using a CIDR calculation so the 'ntohl' is </span> |
| 1993 |
|
|
01985 <span class="comment"> * issued on them to change their byte order</span> |
| 1994 |
|
|
01986 <span class="comment"> */</span> |
| 1995 |
|
|
01987 a = ntohl(peer_addr->s_addr); |
| 1996 |
|
|
01988 b = ntohl(policy_addr-><a class="code" href="structpolicy__addr__s.html#o2">addr</a>.s_addr); |
| 1997 |
|
|
01989 |
| 1998 |
|
|
01990 <span class="keywordflow">if</span> (policy_addr-><a class="code" href="structpolicy__addr__s.html#o1">cidr</a> != 32) |
| 1999 |
|
|
01991 { |
| 2000 |
|
|
01992 <span class="keywordflow">if</span> ((a&(~0U<<(32-policy_addr-><a class="code" href="structpolicy__addr__s.html#o1">cidr</a>))) != (b&(~0U<<(32-policy_addr-><a class="code" href="structpolicy__addr__s.html#o1">cidr</a>)))) |
| 2001 |
|
|
01993 { |
| 2002 |
|
|
01994 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a87a49">SPF_FALSE</a>); |
| 2003 |
|
|
01995 } |
| 2004 |
|
|
01996 } |
| 2005 |
|
|
01997 <span class="keywordflow">else</span> |
| 2006 |
|
|
01998 { |
| 2007 |
|
|
01999 <span class="keywordflow">if</span> (peer_addr->s_addr != policy_addr-><a class="code" href="structpolicy__addr__s.html#o2">addr</a>.s_addr) |
| 2008 |
|
|
02000 { |
| 2009 |
|
|
02001 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"%lu and %lu using 32 cidr do not match\n"</span>, |
| 2010 |
|
|
02002 peer_addr->s_addr, policy_addr-><a class="code" href="structpolicy__addr__s.html#o2">addr</a>.s_addr); |
| 2011 |
|
|
02003 |
| 2012 |
|
|
02004 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a87a49">SPF_FALSE</a>); |
| 2013 |
|
|
02005 } |
| 2014 |
|
|
02006 } |
| 2015 |
|
|
02007 |
| 2016 |
|
|
02008 <span class="comment">/* these are done here just for debugger remove later */</span> |
| 2017 |
|
|
02009 peer_ip = <a class="code" href="util_8h.html#a8">xstrndup</a>(inet_ntoa(*peer_addr), <a class="code" href="spf_8h.html#a11">SPF_MAX_IP_ADDR</a>); |
| 2018 |
|
|
02010 policy_ip = <a class="code" href="util_8h.html#a8">xstrndup</a>(inet_ntoa(policy_addr-><a class="code" href="structpolicy__addr__s.html#o2">addr</a>), <a class="code" href="spf_8h.html#a11">SPF_MAX_IP_ADDR</a>); |
| 2019 |
|
|
02011 |
| 2020 |
|
|
02012 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"Peer: (%s) matches address %s with network %i\n"</span>, |
| 2021 |
|
|
02013 peer_ip, policy_ip, policy_addr-><a class="code" href="structpolicy__addr__s.html#o1">cidr</a>); |
| 2022 |
|
|
02014 |
| 2023 |
|
|
02015 <a class="code" href="util_8h.html#a6">xfree</a>(peer_ip); |
| 2024 |
|
|
02016 <a class="code" href="util_8h.html#a6">xfree</a>(policy_ip); |
| 2025 |
|
|
02017 |
| 2026 |
|
|
02018 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a87a50">SPF_TRUE</a>); |
| 2027 |
|
|
02019 } |
| 2028 |
|
|
02020 |
| 2029 |
|
|
02021 |
| 2030 |
|
|
02022 <span class="comment">/* UTIL_validate_ptr</span> |
| 2031 |
|
|
02023 <span class="comment">*</span> |
| 2032 |
|
|
02024 <span class="comment">* Author: James Couzens <jcouzens@codeshare.ca></span> |
| 2033 |
|
|
02025 <span class="comment">*</span> |
| 2034 |
|
|
02026 <span class="comment">* Date: 12/26/03</span> |
| 2035 |
|
|
02027 <span class="comment">*</span> |
| 2036 |
|
|
02028 <span class="comment">* Desc:</span> |
| 2037 |
|
|
02029 <span class="comment">* Using the ip address found in the passed peer_info structure,</span> |
| 2038 |
|
|
02030 <span class="comment">* a PTR lookup is made and if a record exists then this is record is compared</span> |
| 2039 |
|
|
02031 <span class="comment">* against the hostname the client wishes to send mail from. If the tld matches</span> |
| 2040 |
|
|
02032 <span class="comment">* the tld found during this query, this would be a 'valdiated' PTR. If a match</span> |
| 2041 |
|
|
02033 <span class="comment">* can not be found we return SPF_FALSE. If a match is made we return SPF_TRUE.</span> |
| 2042 |
|
|
02034 <span class="comment">*</span> |
| 2043 |
|
|
02035 <span class="comment">* Notes: Write additional comparisons to handle IP6 addresses</span> |
| 2044 |
|
|
02036 <span class="comment">*</span> |
| 2045 |
|
|
02037 <span class="comment">*/</span> |
| 2046 |
|
|
<a name="l02038"></a><a class="code" href="util_8h.html#a53">02038</a> <a class="code" href="spf_8h.html#a35">SPF_BOOL</a> <a class="code" href="util_8h.html#a53">UTIL_validate_ptr</a>(<a class="code" href="structpeer__info__s.html">peer_info_t</a> *p) |
| 2047 |
|
|
02039 { |
| 2048 |
|
|
02040 <span class="keywordtype">char</span> *ptr_addr; <span class="comment">/* reversed address into PTR format */</span> |
| 2049 |
|
|
02041 <span class="keywordtype">char</span> *tmp_ptr; <span class="comment">/* utility pointer */</span> |
| 2050 |
|
|
02042 |
| 2051 |
|
|
02043 |
| 2052 |
|
|
02044 <span class="keywordflow">if</span> (!p) |
| 2053 |
|
|
02045 { |
| 2054 |
|
|
02046 <a class="code" href="util_8h.html#a13">xepprintf</a>(<span class="stringliteral">"called with an invalid peer info structure!\n"</span>); |
| 2055 |
|
|
02047 |
| 2056 |
|
|
02048 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a87a49">SPF_FALSE</a>); |
| 2057 |
|
|
02049 } |
| 2058 |
|
|
02050 |
| 2059 |
|
|
02051 <span class="comment">/* reverse of the address in peer_info */</span> |
| 2060 |
|
|
02052 ptr_addr = <a class="code" href="util_8h.html#a50">UTIL_rev_addr</a>(p-><a class="code" href="structpeer__info__s.html#o17">r_ip</a>); |
| 2061 |
|
|
02053 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"[address: %s]\n"</span>, ptr_addr); |
| 2062 |
|
|
02054 |
| 2063 |
|
|
02055 tmp_ptr = <a class="code" href="util_8h.html#a8">xstrndup</a>(p-><a class="code" href="structpeer__info__s.html#o15">current_domain</a>, <a class="code" href="spf_8h.html#a14">SPF_MAX_HNAME</a>); |
| 2064 |
|
|
02056 |
| 2065 |
|
|
02057 <span class="keywordflow">if</span> (<a class="code" href="dns_8h.html#a8">DNS_query</a>(p, ptr_addr, T_PTR, tmp_ptr) != (<span class="keywordtype">char</span> *)<a class="code" href="spf_8h.html#a87a50">SPF_TRUE</a>) |
| 2066 |
|
|
02058 { |
| 2067 |
|
|
02059 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"PTR lookup failed: (%s) (%s)\n"</span>, p-><a class="code" href="structpeer__info__s.html#o7">rs</a>, p-><a class="code" href="structpeer__info__s.html#o24">error</a>); |
| 2068 |
|
|
02060 |
| 2069 |
|
|
02061 <a class="code" href="util_8h.html#a6">xfree</a>(ptr_addr); |
| 2070 |
|
|
02062 <a class="code" href="util_8h.html#a6">xfree</a>(tmp_ptr); |
| 2071 |
|
|
02063 |
| 2072 |
|
|
02064 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a87a49">SPF_FALSE</a>); |
| 2073 |
|
|
02065 } |
| 2074 |
|
|
02066 |
| 2075 |
|
|
02067 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"Peer (%s) successfully validated hostname (%s)\n"</span>, |
| 2076 |
|
|
02068 p-><a class="code" href="structpeer__info__s.html#o17">r_ip</a>, p-><a class="code" href="structpeer__info__s.html#o18">r_vhname</a>); |
| 2077 |
|
|
02069 |
| 2078 |
|
|
02070 <a class="code" href="util_8h.html#a6">xfree</a>(ptr_addr); |
| 2079 |
|
|
02071 <a class="code" href="util_8h.html#a6">xfree</a>(tmp_ptr); |
| 2080 |
|
|
02072 |
| 2081 |
|
|
02073 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a87a50">SPF_TRUE</a>); |
| 2082 |
|
|
02074 } |
| 2083 |
|
|
02075 |
| 2084 |
|
|
02076 |
| 2085 |
|
|
02077 <span class="comment">/* UTIL_validate_hostname</span> |
| 2086 |
|
|
02078 <span class="comment">*</span> |
| 2087 |
|
|
02079 <span class="comment">* Author: James Couzens <jcouzens@codeshare.ca></span> |
| 2088 |
|
|
02080 <span class="comment">*</span> |
| 2089 |
|
|
02081 <span class="comment">* Date: 01/08/04</span> |
| 2090 |
|
|
02082 <span class="comment">*</span> |
| 2091 |
|
|
02083 <span class="comment">* Desc:</span> |
| 2092 |
|
|
02084 <span class="comment">* s contains a hostname which is then looked up to find any</span> |
| 2093 |
|
|
02085 <span class="comment">* of the returned ip addresses SPF_PASS the remote peers. On a successful</span> |
| 2094 |
|
|
02086 <span class="comment">* SPF_PASS returns SPF_TRUE. When no SPF_PASS is made, returns SPF_FALSE.</span> |
| 2095 |
|
|
02087 <span class="comment">*</span> |
| 2096 |
|
|
02088 <span class="comment">* Note:</span> |
| 2097 |
|
|
02089 <span class="comment">* We need to define and set a limit on the number of recursive</span> |
| 2098 |
|
|
02090 <span class="comment">* lookups. I recall seeing this in the RFC, we should discuss this.</span> |
| 2099 |
|
|
02091 <span class="comment">*</span> |
| 2100 |
|
|
02092 <span class="comment">* Date: 08/28/04 by James</span> |
| 2101 |
|
|
02093 <span class="comment">*</span> |
| 2102 |
|
|
02094 <span class="comment">* Desc:</span> |
| 2103 |
|
|
02095 <span class="comment">* Added buffer for reentrant gethostbyname wrapper</span> |
| 2104 |
|
|
02096 <span class="comment">* and change gethostbyname calls to use the MACRO wrapper</span> |
| 2105 |
|
|
02097 <span class="comment">* xgethostbyname()</span> |
| 2106 |
|
|
02098 <span class="comment">*</span> |
| 2107 |
|
|
02099 <span class="comment">*/</span> |
| 2108 |
|
|
<a name="l02100"></a><a class="code" href="util_8h.html#a54">02100</a> <a class="code" href="spf_8h.html#a35">SPF_BOOL</a> <a class="code" href="util_8h.html#a54">UTIL_validate_hostname</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, <span class="keyword">const</span> int8_t cidr) |
| 2109 |
|
|
02101 { |
| 2110 |
|
|
02102 <span class="keywordtype">int</span> tmp_errno = 0; <span class="comment">/* temporary errno placeholder */</span> |
| 2111 |
|
|
02103 |
| 2112 |
|
|
02104 <span class="keywordtype">char</span> **a = NULL; <span class="comment">/* work ptr for list recursion */</span> |
| 2113 |
|
|
02105 |
| 2114 |
|
|
02106 <span class="keywordtype">char</span> *ip = NULL; <span class="comment">/* ip address */</span> |
| 2115 |
|
|
02107 <span class="keywordtype">char</span> *gbuf = NULL; <span class="comment">/* reentrant buffer for gethostbyname_r */</span> |
| 2116 |
|
|
02108 |
| 2117 |
|
|
02109 <span class="keyword">struct </span>in_addr addr; <span class="comment">/* connected peer's address */</span> |
| 2118 |
|
|
02110 <span class="keyword">struct </span>hostent *hp = NULL; <span class="comment">/* hostent structure */</span> |
| 2119 |
|
|
02111 <span class="keyword">struct </span>hostent tmp_hp; <span class="comment">/* temporary hostent structure */</span> |
| 2120 |
|
|
02112 |
| 2121 |
|
|
02113 <a class="code" href="structpolicy__addr__s.html">policy_addr_t</a> policy_addr; <span class="comment">/* used for cidr calculations */</span> |
| 2122 |
|
|
02114 |
| 2123 |
|
|
02115 |
| 2124 |
|
|
02116 <span class="keywordflow">if</span> (s == NULL) |
| 2125 |
|
|
02117 { |
| 2126 |
|
|
02118 <a class="code" href="util_8h.html#a13">xepprintf</a>(<span class="stringliteral">"passed a NULL string.\n"</span>); |
| 2127 |
|
|
02119 |
| 2128 |
|
|
02120 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a87a49">SPF_FALSE</a>); |
| 2129 |
|
|
02121 } |
| 2130 |
|
|
02122 |
| 2131 |
|
|
02123 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"called with: (%lu) and (%s)\n"</span>, p-><a class="code" href="structpeer__info__s.html#o17">r_ip</a>, s); |
| 2132 |
|
|
02124 |
| 2133 |
|
|
02125 gbuf = <a class="code" href="util_8h.html#a4">xmalloc</a>(<a class="code" href="util_8h.html#a2">SPF_MAX_GHBNR_DBUF</a>); |
| 2134 |
|
|
02126 |
| 2135 |
|
|
02127 <span class="keywordflow">if</span> ((hp = <a class="code" href="dns_8h.html#a4">xgethostbyname</a>(s, &tmp_hp, gbuf, <a class="code" href="util_8h.html#a2">SPF_MAX_GHBNR_DBUF</a>, |
| 2136 |
|
|
02128 &tmp_errno)) != NULL) |
| 2137 |
|
|
02129 { |
| 2138 |
|
|
02130 <span class="comment">/* for each hostname in the list, perform CIDR checks */</span> |
| 2139 |
|
|
02131 <span class="keywordflow">for</span> (a = hp->h_addr_list; *a; a++) |
| 2140 |
|
|
02132 { |
| 2141 |
|
|
02133 memcpy(&addr.s_addr, *a, <a class="code" href="util_8h.html#a3">SIZEOF</a>(<span class="keyword">struct</span> in_addr)); |
| 2142 |
|
|
02134 ip = <a class="code" href="util_8h.html#a8">xstrndup</a>(inet_ntoa(addr), <a class="code" href="spf_8h.html#a11">SPF_MAX_IP_ADDR</a>); |
| 2143 |
|
|
02135 |
| 2144 |
|
|
02136 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"CLI: %s (%lu) SRV: %s (%lu)\n"</span>, ip, addr.s_addr, |
| 2145 |
|
|
02137 p-><a class="code" href="structpeer__info__s.html#o17">r_ip</a>, p-><a class="code" href="structpeer__info__s.html#o26">addr</a>.s_addr); |
| 2146 |
|
|
02138 |
| 2147 |
|
|
02139 <span class="keywordflow">if</span> (cidr == 32) |
| 2148 |
|
|
02140 { |
| 2149 |
|
|
02141 <span class="keywordflow">if</span> (((<span class="keyword">struct </span>in_addr *)(*a))->s_addr == p-><a class="code" href="structpeer__info__s.html#o26">addr</a>.s_addr) |
| 2150 |
|
|
02142 { |
| 2151 |
|
|
02143 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"%s (%lu) matches %s (%lu)\n"</span>, ip, |
| 2152 |
|
|
02144 ((<span class="keyword">struct</span> in_addr *)(*a))->s_addr, p-><a class="code" href="structpeer__info__s.html#o17">r_ip</a>, p-><a class="code" href="structpeer__info__s.html#o26">addr</a>.s_addr); |
| 2153 |
|
|
02145 |
| 2154 |
|
|
02146 <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); |
| 2155 |
|
|
02147 |
| 2156 |
|
|
02148 <a class="code" href="util_8h.html#a6">xfree</a>(ip); |
| 2157 |
|
|
02149 <a class="code" href="util_8h.html#a6">xfree</a>(gbuf); |
| 2158 |
|
|
02150 |
| 2159 |
|
|
02151 <a class="code" href="dns_8h.html#a5">xgethostbyname_free</a>(); <span class="comment">/* unlock mutex */</span> |
| 2160 |
|
|
02152 |
| 2161 |
|
|
02153 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a87a50">SPF_TRUE</a>); |
| 2162 |
|
|
02154 } |
| 2163 |
|
|
02155 } |
| 2164 |
|
|
02156 <span class="keywordflow">else</span> <span class="keywordflow">if</span> ((cidr < 32) && (cidr >= 8)) |
| 2165 |
|
|
02157 { |
| 2166 |
|
|
02158 <span class="comment">/* convert from character string to dotted quad notation */</span> |
| 2167 |
|
|
02159 <span class="keywordflow">if</span> ((inet_pton(AF_INET, ip, &policy_addr.addr)) == 0) |
| 2168 |
|
|
02160 { |
| 2169 |
|
|
02161 <a class="code" href="util_8h.html#a13">xepprintf</a>(<span class="stringliteral">"Unable to execute inet_pton()\n"</span>); |
| 2170 |
|
|
02162 } |
| 2171 |
|
|
02163 |
| 2172 |
|
|
02164 policy_addr.cidr = cidr; |
| 2173 |
|
|
02165 |
| 2174 |
|
|
02166 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"Address: %lu with CIDR %i\n"</span>, |
| 2175 |
|
|
02167 policy_addr.addr.s_addr, policy_addr.cidr); |
| 2176 |
|
|
02168 |
| 2177 |
|
|
02169 <span class="comment">/* perform CIDR comparison of 'policy_addr' vs 'p->addr' */</span> |
| 2178 |
|
|
02170 <span class="keywordflow">if</span> ((<a class="code" href="util_8h.html#a52">UTIL_cidr_cmp</a>(&policy_addr, &p-><a class="code" href="structpeer__info__s.html#o26">addr</a>)) == <a class="code" href="spf_8h.html#a87a50">SPF_TRUE</a>) |
| 2179 |
|
|
02171 { |
| 2180 |
|
|
02172 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"(%lu) matches (%lu) with CIDR %u\n"</span>, |
| 2181 |
|
|
02173 policy_addr.addr.s_addr, p-><a class="code" href="structpeer__info__s.html#o26">addr</a>.s_addr, cidr); |
| 2182 |
|
|
02174 |
| 2183 |
|
|
02175 <span class="comment">/* associate an SPF prefix (-,+,~,?) with this check */</span> |
| 2184 |
|
|
02176 <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); |
| 2185 |
|
|
02177 |
| 2186 |
|
|
02178 <a class="code" href="util_8h.html#a6">xfree</a>(ip); |
| 2187 |
|
|
02179 <a class="code" href="util_8h.html#a6">xfree</a>(gbuf); |
| 2188 |
|
|
02180 |
| 2189 |
|
|
02181 <a class="code" href="dns_8h.html#a5">xgethostbyname_free</a>(); |
| 2190 |
|
|
02182 |
| 2191 |
|
|
02183 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a87a50">SPF_TRUE</a>); |
| 2192 |
|
|
02184 } |
| 2193 |
|
|
02185 } <span class="comment">/* else if */</span> |
| 2194 |
|
|
02186 |
| 2195 |
|
|
02187 <a class="code" href="util_8h.html#a6">xfree</a>(ip); |
| 2196 |
|
|
02188 |
| 2197 |
|
|
02189 } <span class="comment">/* for */</span> |
| 2198 |
|
|
02190 |
| 2199 |
|
|
02191 <span class="comment">/* for each alias (CNAME) perform a CIDR check */</span> |
| 2200 |
|
|
02192 <span class="keywordflow">for</span> (a = hp->h_aliases; *a; a++) |
| 2201 |
|
|
02193 { |
| 2202 |
|
|
02194 memcpy(&addr.s_addr, *a, <a class="code" href="util_8h.html#a3">SIZEOF</a>(<span class="keyword">struct</span> in_addr)); |
| 2203 |
|
|
02195 ip = <a class="code" href="util_8h.html#a8">xstrndup</a>(inet_ntoa(addr), <a class="code" href="spf_8h.html#a11">SPF_MAX_IP_ADDR</a>); |
| 2204 |
|
|
02196 |
| 2205 |
|
|
02197 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"client: %s (%lu); policy: %s (%lu)\n"</span>, |
| 2206 |
|
|
02198 ip, addr.s_addr, p-><a class="code" href="structpeer__info__s.html#o17">r_ip</a>, p-><a class="code" href="structpeer__info__s.html#o26">addr</a>.s_addr); |
| 2207 |
|
|
02199 |
| 2208 |
|
|
02200 <span class="keywordflow">if</span> (cidr == 32) |
| 2209 |
|
|
02201 { |
| 2210 |
|
|
02202 <span class="keywordflow">if</span> (((<span class="keyword">struct </span>in_addr *)(*a))->s_addr == p-><a class="code" href="structpeer__info__s.html#o26">addr</a>.s_addr) |
| 2211 |
|
|
02203 { |
| 2212 |
|
|
02204 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"IN A: client: %s (%lu) matches policy: %s (%lu)\n"</span>, |
| 2213 |
|
|
02205 ip, ((<span class="keyword">struct</span> in_addr *)(*a))->s_addr, p-><a class="code" href="structpeer__info__s.html#o17">r_ip</a>, p-><a class="code" href="structpeer__info__s.html#o26">addr</a>.s_addr); |
| 2214 |
|
|
02206 |
| 2215 |
|
|
02207 <a class="code" href="util_8h.html#a6">xfree</a>(ip); |
| 2216 |
|
|
02208 <a class="code" href="util_8h.html#a6">xfree</a>(gbuf); |
| 2217 |
|
|
02209 |
| 2218 |
|
|
02210 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a87a50">SPF_TRUE</a>); |
| 2219 |
|
|
02211 } |
| 2220 |
|
|
02212 } |
| 2221 |
|
|
02213 <span class="keywordflow">else</span> <span class="keywordflow">if</span> ((cidr < 32) && (cidr >= 8)) |
| 2222 |
|
|
02214 { |
| 2223 |
|
|
02215 <span class="keywordflow">if</span> (inet_pton(AF_INET, ip, &policy_addr.addr) == 0) |
| 2224 |
|
|
02216 { |
| 2225 |
|
|
02217 <a class="code" href="util_8h.html#a13">xepprintf</a>(<span class="stringliteral">"Unable to execute inet_pton()\n"</span>); |
| 2226 |
|
|
02218 } |
| 2227 |
|
|
02219 |
| 2228 |
|
|
02220 policy_addr.cidr = cidr; |
| 2229 |
|
|
02221 |
| 2230 |
|
|
02222 <span class="keywordflow">if</span> (<a class="code" href="util_8h.html#a52">UTIL_cidr_cmp</a>(&policy_addr, &p-><a class="code" href="structpeer__info__s.html#o26">addr</a>) == <a class="code" href="spf_8h.html#a87a50">SPF_TRUE</a>) |
| 2231 |
|
|
02223 { |
| 2232 |
|
|
02224 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"client: (%lu) matches policy (%lu) with CIDR %u\n"</span>, |
| 2233 |
|
|
02225 policy_addr.addr.s_addr, p-><a class="code" href="structpeer__info__s.html#o26">addr</a>.s_addr, cidr); |
| 2234 |
|
|
02226 |
| 2235 |
|
|
02227 <a class="code" href="util_8h.html#a6">xfree</a>(ip); |
| 2236 |
|
|
02228 <a class="code" href="util_8h.html#a6">xfree</a>(gbuf); |
| 2237 |
|
|
02229 |
| 2238 |
|
|
02230 <span class="comment">/* associate an SPF prefix (-,+,~,?) with this check */</span> |
| 2239 |
|
|
02231 <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); |
| 2240 |
|
|
02232 |
| 2241 |
|
|
02233 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a87a50">SPF_TRUE</a>); |
| 2242 |
|
|
02234 } |
| 2243 |
|
|
02235 } <span class="comment">/* else */</span> |
| 2244 |
|
|
02236 |
| 2245 |
|
|
02237 <a class="code" href="util_8h.html#a6">xfree</a>(ip); |
| 2246 |
|
|
02238 |
| 2247 |
|
|
02239 } <span class="comment">/* for */</span> |
| 2248 |
|
|
02240 } <span class="comment">/* if .. xgethostbyname() */</span> |
| 2249 |
|
|
02241 <span class="keywordflow">else</span> |
| 2250 |
|
|
02242 { |
| 2251 |
|
|
02243 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"No address associated with hostname (%s); Reason: %s\n"</span>, |
| 2252 |
|
|
02244 s, hstrerror(tmp_errno)); |
| 2253 |
|
|
02245 } |
| 2254 |
|
|
02246 |
| 2255 |
|
|
02247 <a class="code" href="util_8h.html#a6">xfree</a>(gbuf); |
| 2256 |
|
|
02248 |
| 2257 |
|
|
02249 <a class="code" href="dns_8h.html#a5">xgethostbyname_free</a>(); |
| 2258 |
|
|
02250 |
| 2259 |
|
|
02251 <a class="code" href="util_8h.html#a11">xpprintf</a>(<span class="stringliteral">"leaving function; returning SPF_FALSE\n"</span>); |
| 2260 |
|
|
02252 |
| 2261 |
|
|
02253 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a87a49">SPF_FALSE</a>); |
| 2262 |
|
|
02254 } |
| 2263 |
|
|
02255 |
| 2264 |
|
|
02256 |
| 2265 |
|
|
02257 <span class="comment">/* UTIL_url_encode</span> |
| 2266 |
|
|
02258 <span class="comment">*</span> |
| 2267 |
|
|
02259 <span class="comment">* Author: Sean Comeau <scomeau@obscurity.org></span> |
| 2268 |
|
|
02260 <span class="comment">*</span> |
| 2269 |
|
|
02261 <span class="comment">* Date: 01/06/04</span> |
| 2270 |
|
|
02262 <span class="comment">*</span> |
| 2271 |
|
|
02263 <span class="comment">* Desc:</span> |
| 2272 |
|
|
02264 <span class="comment">* "URL-Encode" characters that are "unsafe" or "prohibited" from a URL.</span> |
| 2273 |
|
|
02265 <span class="comment">* Upon success returns a pointer to a newly allocated memory containing the</span> |
| 2274 |
|
|
02266 <span class="comment">* encoded string. Upon failure returns a NULL pointer. Failure</span> |
| 2275 |
|
|
02267 <span class="comment">* indicates either a failure to allocate new memory, or the passed string</span> |
| 2276 |
|
|
02268 <span class="comment">* did not contain any questionable characters and hence did not require</span> |
| 2277 |
|
|
02269 <span class="comment">* encoding.</span> |
| 2278 |
|
|
02270 <span class="comment">*</span> |
| 2279 |
|
|
02271 <span class="comment">*/</span> |
| 2280 |
|
|
<a name="l02272"></a><a class="code" href="util_8h.html#a55">02272</a> <span class="keywordtype">char</span> *<a class="code" href="util_8h.html#a55">UTIL_url_encode</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> *s) |
| 2281 |
|
|
02273 { |
| 2282 |
|
|
02274 <span class="keywordtype">int</span> len; <span class="comment">/* length of passed string * 3*/</span> |
| 2283 |
|
|
02275 |
| 2284 |
|
|
02276 <span class="keywordtype">char</span> *<span class="keyword">new</span>; <span class="comment">/* newly allocated memory */</span> |
| 2285 |
|
|
02277 <span class="keywordtype">char</span> *encoded; <span class="comment">/* encoded return string */</span> |
| 2286 |
|
|
02278 |
| 2287 |
|
|
02279 |
| 2288 |
|
|
02280 <span class="keywordflow">if</span> (s != NULL) |
| 2289 |
|
|
02281 { |
| 2290 |
|
|
02282 <span class="comment">/*</span> |
| 2291 |
|
|
02283 <span class="comment"> * length of the string times 3 is the maximum possible size a</span> |
| 2292 |
|
|
02284 <span class="comment"> * URL encoded string should ever be able to expand to.</span> |
| 2293 |
|
|
02285 <span class="comment"> */</span> |
| 2294 |
|
|
02286 len = (strlen(s) * 3); |
| 2295 |
|
|
02287 } |
| 2296 |
|
|
02288 <span class="keywordflow">else</span> |
| 2297 |
|
|
02289 { |
| 2298 |
|
|
02290 <a class="code" href="util_8h.html#a13">xepprintf</a>(<span class="stringliteral">"passed a NULL string. Abort!\n"</span>); |
| 2299 |
|
|
02291 |
| 2300 |
|
|
02292 <span class="keywordflow">return</span>(NULL); |
| 2301 |
|
|
02293 } |
| 2302 |
|
|
02294 |
| 2303 |
|
|
02295 encoded = <span class="keyword">new</span> = <a class="code" href="util_8h.html#a4">xmalloc</a>(len); |
| 2304 |
|
|
02296 |
| 2305 |
|
|
02297 <span class="keywordflow">while</span> (*s != <span class="charliteral">'\0'</span>) |
| 2306 |
|
|
02298 { |
| 2307 |
|
|
02299 <span class="keywordflow">if</span> (<a class="code" href="util_8h.html#a17">urlchr_test</a>(*s) == 0) |
| 2308 |
|
|
02300 { |
| 2309 |
|
|
02301 *<span class="keyword">new</span>++ = *s++; |
| 2310 |
|
|
02302 } |
| 2311 |
|
|
02303 <span class="keywordflow">else</span> |
| 2312 |
|
|
02304 { |
| 2313 |
|
|
02305 <span class="comment">/* this obviously NULL terminates, do we want this? */</span> |
| 2314 |
|
|
02306 snprintf(<span class="keyword">new</span>, 4, <span class="stringliteral">"%%%x"</span>, *s); |
| 2315 |
|
|
02307 <span class="keyword">new</span> += 3; |
| 2316 |
|
|
02308 s++; |
| 2317 |
|
|
02309 } |
| 2318 |
|
|
02310 } |
| 2319 |
|
|
02311 |
| 2320 |
|
|
02312 *<span class="keyword">new</span>++ = <span class="charliteral">'\0'</span>; |
| 2321 |
|
|
02313 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"leaving function; returning (%s)\n"</span>, encoded); |
| 2322 |
|
|
02314 |
| 2323 |
|
|
02315 <span class="keywordflow">return</span>(encoded); |
| 2324 |
|
|
02316 } |
| 2325 |
|
|
02317 |
| 2326 |
|
|
02318 |
| 2327 |
|
|
02319 <span class="comment">/* UTIL_reverse</span> |
| 2328 |
|
|
02320 <span class="comment">*</span> |
| 2329 |
|
|
02321 <span class="comment">* Author: James Couzens <jcouzens@codeshare.ca></span> |
| 2330 |
|
|
02322 <span class="comment">*</span> |
| 2331 |
|
|
02323 <span class="comment">* Date: 01/06/04</span> |
| 2332 |
|
|
02324 <span class="comment">*</span> |
| 2333 |
|
|
02325 <span class="comment">* Desc:</span> |
| 2334 |
|
|
02326 <span class="comment">* Takes a string and rebuilds it in reverse order using the</span> |
| 2335 |
|
|
02327 <span class="comment">* supplied delimiter. The string will always be rebuilt using a</span> |
| 2336 |
|
|
02328 <span class="comment">* '.' char as per the RFC.</span> |
| 2337 |
|
|
02329 <span class="comment">*</span> |
| 2338 |
|
|
02330 <span class="comment">*/</span> |
| 2339 |
|
|
<a name="l02331"></a><a class="code" href="util_8h.html#a56">02331</a> <span class="keywordtype">char</span> *<a class="code" href="util_8h.html#a56">UTIL_reverse</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> *s, <span class="keyword">const</span> <span class="keywordtype">char</span> delim) |
| 2340 |
|
|
02332 { |
| 2341 |
|
|
02333 size_t len; <span class="comment">/* length of s */</span> |
| 2342 |
|
|
02334 |
| 2343 |
|
|
02335 <span class="keywordtype">char</span> *buf; <span class="comment">/* return buffer */</span> |
| 2344 |
|
|
02336 <span class="keywordtype">char</span> *p; <span class="comment">/* working pointer */</span> |
| 2345 |
|
|
02337 <span class="keywordtype">char</span> *cp; <span class="comment">/* working pointer */</span> |
| 2346 |
|
|
02338 <span class="keywordtype">char</span> *c; <span class="comment">/* working pointer */</span> |
| 2347 |
|
|
02339 |
| 2348 |
|
|
02340 <a class="code" href="structsplit__str__s.html">split_str_t</a> *master; <span class="comment">/* list pointers */</span> |
| 2349 |
|
|
02341 |
| 2350 |
|
|
02342 <a class="code" href="structsplit__str__node__s.html">split_str_node_t</a> *c_node; <span class="comment">/* c_node node */</span> |
| 2351 |
|
|
02343 <a class="code" href="structsplit__str__node__s.html">split_str_node_t</a> *kill_node; <span class="comment">/* temp node used in destruction */</span> |
| 2352 |
|
|
02344 |
| 2353 |
|
|
02345 |
| 2354 |
|
|
02346 <span class="keywordflow">if</span> (s == NULL) |
| 2355 |
|
|
02347 { |
| 2356 |
|
|
02348 <a class="code" href="util_8h.html#a13">xepprintf</a>(<span class="stringliteral">"passed a NULL string. Abort!\n"</span>); |
| 2357 |
|
|
02349 |
| 2358 |
|
|
02350 <span class="keywordflow">return</span>(NULL); |
| 2359 |
|
|
02351 } |
| 2360 |
|
|
02352 |
| 2361 |
|
|
02353 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"called with (%s) and delim (%c)\n"</span>, s, delim); |
| 2362 |
|
|
02354 |
| 2363 |
|
|
02355 len = strlen(s); |
| 2364 |
|
|
02356 cp = c = <a class="code" href="util_8h.html#a8">xstrndup</a>(s, (len + 1)); |
| 2365 |
|
|
02357 |
| 2366 |
|
|
02358 master = <a class="code" href="util_8h.html#a4">xmalloc</a>(<a class="code" href="util_8h.html#a3">SIZEOF</a>(<a class="code" href="structsplit__str__s.html">split_str_t</a>)); |
| 2367 |
|
|
02359 master-><a class="code" href="structsplit__str__s.html#o0">head</a> = NULL; |
| 2368 |
|
|
02360 master-><a class="code" href="structsplit__str__s.html#o1">tail</a> = NULL; |
| 2369 |
|
|
02361 master-><a class="code" href="structsplit__str__s.html#o2">elements</a> = 0; |
| 2370 |
|
|
02362 |
| 2371 |
|
|
02363 <span class="comment">/* </span> |
| 2372 |
|
|
02364 <span class="comment"> * Comment: James Couzens <jcouzens@codeshare.ca></span> |
| 2373 |
|
|
02365 <span class="comment"> *</span> |
| 2374 |
|
|
02366 <span class="comment"> * Date: 01/22/04</span> |
| 2375 |
|
|
02367 <span class="comment"> *</span> |
| 2376 |
|
|
02368 <span class="comment"> * we do not want the trailing delim so the first iteration of this</span> |
| 2377 |
|
|
02369 <span class="comment"> * loop we call UTIL_addnode with 0, which tells it not to allocate</span> |
| 2378 |
|
|
02370 <span class="comment"> * the extra byte for the trailing delimiter. This is done only</span> |
| 2379 |
|
|
02371 <span class="comment"> * when passed an IP address, and this is because when reversing we</span> |
| 2380 |
|
|
02372 <span class="comment"> * want: 1.0.168.192. and not .1.0.168.192</span> |
| 2381 |
|
|
02373 <span class="comment"> *</span> |
| 2382 |
|
|
02374 <span class="comment"> */</span> |
| 2383 |
|
|
02375 |
| 2384 |
|
|
02376 len++; |
| 2385 |
|
|
02377 buf = <a class="code" href="util_8h.html#a4">xmalloc</a>(len); |
| 2386 |
|
|
02378 <span class="keywordflow">while</span> ((p = strrchr(cp, delim)) != NULL) |
| 2387 |
|
|
02379 { |
| 2388 |
|
|
02380 p++; <span class="comment">/* remove period */</span> |
| 2389 |
|
|
02381 <a class="code" href="util_8h.html#a57">UTIL_addnode</a>(master, p, <a class="code" href="spf_8h.html#a87a50">SPF_TRUE</a>); |
| 2390 |
|
|
02382 p--; <span class="comment">/* bring it back */</span> |
| 2391 |
|
|
02383 *p = <span class="charliteral">'\0'</span>; |
| 2392 |
|
|
02384 } |
| 2393 |
|
|
02385 |
| 2394 |
|
|
02386 <a class="code" href="util_8h.html#a57">UTIL_addnode</a>(master, cp, <a class="code" href="spf_8h.html#a87a49">SPF_FALSE</a>); |
| 2395 |
|
|
02387 |
| 2396 |
|
|
02388 c_node = master-><a class="code" href="structsplit__str__s.html#o0">head</a>; |
| 2397 |
|
|
02389 <span class="keywordflow">while</span> ((kill_node = c_node) != NULL) |
| 2398 |
|
|
02390 { |
| 2399 |
|
|
02391 strncat(buf, kill_node-><a class="code" href="structsplit__str__node__s.html#o1">s</a>, kill_node-><a class="code" href="structsplit__str__node__s.html#o0">len</a>); |
| 2400 |
|
|
02392 <a class="code" href="util_8h.html#a6">xfree</a>(kill_node-><a class="code" href="structsplit__str__node__s.html#o1">s</a>); |
| 2401 |
|
|
02393 c_node = c_node-><a class="code" href="structsplit__str__node__s.html#o2">next</a>; |
| 2402 |
|
|
02394 <a class="code" href="util_8h.html#a6">xfree</a>(kill_node); |
| 2403 |
|
|
02395 } |
| 2404 |
|
|
02396 |
| 2405 |
|
|
02397 <a class="code" href="util_8h.html#a6">xfree</a>(cp); |
| 2406 |
|
|
02398 <a class="code" href="util_8h.html#a6">xfree</a>(master); |
| 2407 |
|
|
02399 |
| 2408 |
|
|
02400 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"leaving function; returning (%s)\n"</span>, buf); |
| 2409 |
|
|
02401 |
| 2410 |
|
|
02402 <span class="keywordflow">return</span>(buf); |
| 2411 |
|
|
02403 } |
| 2412 |
|
|
02404 |
| 2413 |
|
|
02405 |
| 2414 |
|
|
02406 <span class="comment">/* UTIL_addnode</span> |
| 2415 |
|
|
02407 <span class="comment">*</span> |
| 2416 |
|
|
02408 <span class="comment">* Author: James Couzens <jcouzens@codeshare.ca></span> |
| 2417 |
|
|
02409 <span class="comment">*</span> |
| 2418 |
|
|
02410 <span class="comment">* Date: 01/18/04</span> |
| 2419 |
|
|
02411 <span class="comment">*</span> |
| 2420 |
|
|
02412 <span class="comment">* Desc:</span> |
| 2421 |
|
|
02413 <span class="comment">* Allocates memory for a new node and slaps it on the end of</span> |
| 2422 |
|
|
02414 <span class="comment">* of the passed list. In the process of doing so, when it comes to</span> |
| 2423 |
|
|
02415 <span class="comment">* the last element in the list, which is indicated by the SPF_BOOL</span> |
| 2424 |
|
|
02416 <span class="comment">* that is passed, a final '.' is either appended (SPF_TRUE) or not</span> |
| 2425 |
|
|
02417 <span class="comment">* (SPF_FALSE). Function returns SPF_TRUE upon success, and SPF_FALSE upon</span> |
| 2426 |
|
|
02418 <span class="comment">* failure.</span> |
| 2427 |
|
|
02419 <span class="comment">*</span> |
| 2428 |
|
|
02420 <span class="comment">*/</span> |
| 2429 |
|
|
<a name="l02421"></a><a class="code" href="util_8h.html#a57">02421</a> <a class="code" href="spf_8h.html#a35">SPF_BOOL</a> <a class="code" href="util_8h.html#a57">UTIL_addnode</a>(<a class="code" href="structsplit__str__s.html">split_str_t</a> *master, <span class="keyword">const</span> <span class="keywordtype">char</span> *s, <a class="code" href="spf_8h.html#a35">SPF_BOOL</a> last) |
| 2430 |
|
|
02422 { |
| 2431 |
|
|
02423 size_t len; <span class="comment">/* length of s */</span> |
| 2432 |
|
|
02424 |
| 2433 |
|
|
02425 <a class="code" href="structsplit__str__node__s.html">split_str_node_t</a> *c_node; <span class="comment">/* c_node working node */</span> |
| 2434 |
|
|
02426 <a class="code" href="structsplit__str__node__s.html">split_str_node_t</a> *new_node; <span class="comment">/* newly allocated node */</span> |
| 2435 |
|
|
02427 <a class="code" href="structsplit__str__node__s.html">split_str_node_t</a> *prev_node; <span class="comment">/* previous working node */</span> |
| 2436 |
|
|
02428 |
| 2437 |
|
|
02429 |
| 2438 |
|
|
02430 <span class="keywordflow">if</span> (!s || (s == NULL)) |
| 2439 |
|
|
02431 { |
| 2440 |
|
|
02432 <a class="code" href="util_8h.html#a13">xepprintf</a>(<span class="stringliteral">"passed a NULL string. Abort!\n"</span>); |
| 2441 |
|
|
02433 |
| 2442 |
|
|
02434 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a87a49">SPF_FALSE</a>); |
| 2443 |
|
|
02435 } |
| 2444 |
|
|
02436 |
| 2445 |
|
|
02437 <a class="code" href="util_8h.html#a10">xvprintf</a>(<span class="stringliteral">"called with string: (%s); boolean: (%s)\n"</span>, s, |
| 2446 |
|
|
02438 last ? <span class="stringliteral">"FALSE"</span> : <span class="stringliteral">"TRUE"</span>); |
| 2447 |
|
|
02439 |
| 2448 |
|
|
02440 len = strlen(s); |
| 2449 |
|
|
02441 |
| 2450 |
|
|
02442 <span class="keywordflow">if</span> (last == <a class="code" href="spf_8h.html#a87a50">SPF_TRUE</a>) |
| 2451 |
|
|
02443 { |
| 2452 |
|
|
02444 len += 2; |
| 2453 |
|
|
02445 } |
| 2454 |
|
|
02446 <span class="keywordflow">else</span> |
| 2455 |
|
|
02447 { |
| 2456 |
|
|
02448 len++; |
| 2457 |
|
|
02449 } |
| 2458 |
|
|
02450 |
| 2459 |
|
|
02451 <span class="comment">/* create new node */</span> |
| 2460 |
|
|
02452 new_node = <a class="code" href="util_8h.html#a4">xmalloc</a>(<a class="code" href="util_8h.html#a3">SIZEOF</a>(<a class="code" href="structsplit__str__node__s.html">split_str_node_t</a>)); |
| 2461 |
|
|
02453 |
| 2462 |
|
|
02454 <span class="comment">/* set the new nodes next value NULL, and store s */</span> |
| 2463 |
|
|
02455 new_node-><a class="code" href="structsplit__str__node__s.html#o2">next</a> = NULL; |
| 2464 |
|
|
02456 |
| 2465 |
|
|
02457 new_node-><a class="code" href="structsplit__str__node__s.html#o1">s</a> = <a class="code" href="util_8h.html#a4">xmalloc</a>(len); |
| 2466 |
|
|
02458 |
| 2467 |
|
|
02459 <span class="comment">/*</span> |
| 2468 |
|
|
02460 <span class="comment"> * Comment: James Couzens <jcouzens@codeshare.ca></span> |
| 2469 |
|
|
02461 <span class="comment"> *</span> |
| 2470 |
|
|
02462 <span class="comment"> * Date: 01/22/04</span> |
| 2471 |
|
|
02463 <span class="comment"> *</span> |
| 2472 |
|
|
02464 <span class="comment"> * section 7.1 (Macro definitions) of the RFC v02.9.5 indicates that we must</span> |
| 2473 |
|
|
02465 <span class="comment"> * always rebuild the macro using the delimiter '.' and not the passed</span> |
| 2474 |
|
|
02466 <span class="comment"> * delimiting character.</span> |
| 2475 |
|
|
02467 <span class="comment"> *</span> |
| 2476 |
|
|
02468 <span class="comment"> */</span> |
| 2477 |
|
|
02469 snprintf(new_node-><a class="code" href="structsplit__str__node__s.html#o1">s</a>, len, <span class="stringliteral">"%s%c"</span>, s, last ? <span class="charliteral">'.'</span> : <span class="charliteral">'\0'</span>); |
| 2478 |
|
|
02470 new_node-><a class="code" href="structsplit__str__node__s.html#o0">len</a> = (len - 1); <span class="comment">/* don't count \0 */</span> |
| 2479 |
|
|
02471 |
| 2480 |
|
|
02472 prev_node = NULL; |
| 2481 |
|
|
02473 c_node = master-><a class="code" href="structsplit__str__s.html#o0">head</a>; |
| 2482 |
|
|
02474 |
| 2483 |
|
|
02475 <span class="comment">/* reorder the list with the NEW element on the end */</span> |
| 2484 |
|
|
02476 <span class="keywordflow">while</span> (c_node != NULL) |
| 2485 |
|
|
02477 { |
| 2486 |
|
|
02478 prev_node = c_node; |
| 2487 |
|
|
02479 c_node = c_node-><a class="code" href="structsplit__str__node__s.html#o2">next</a>; |
| 2488 |
|
|
02480 } |
| 2489 |
|
|
02481 |
| 2490 |
|
|
02482 <span class="keywordflow">if</span> (prev_node != NULL) |
| 2491 |
|
|
02483 { |
| 2492 |
|
|
02484 new_node-><a class="code" href="structsplit__str__node__s.html#o2">next</a> = prev_node-><a class="code" href="structsplit__str__node__s.html#o2">next</a>; |
| 2493 |
|
|
02485 prev_node-><a class="code" href="structsplit__str__node__s.html#o2">next</a> = new_node; |
| 2494 |
|
|
02486 } |
| 2495 |
|
|
02487 <span class="keywordflow">else</span> |
| 2496 |
|
|
02488 { |
| 2497 |
|
|
02489 master-><a class="code" href="structsplit__str__s.html#o0">head</a> = new_node; |
| 2498 |
|
|
02490 } |
| 2499 |
|
|
02491 |
| 2500 |
|
|
02492 master-><a class="code" href="structsplit__str__s.html#o1">tail</a> = new_node; |
| 2501 |
|
|
02493 master-><a class="code" href="structsplit__str__s.html#o2">elements</a>++; |
| 2502 |
|
|
02494 |
| 2503 |
|
|
02495 <a class="code" href="util_8h.html#a11">xpprintf</a>(<span class="stringliteral">"leaving function; returning SPF_TRUE\n"</span>); |
| 2504 |
|
|
02496 |
| 2505 |
|
|
02497 <span class="keywordflow">return</span>(<a class="code" href="spf_8h.html#a87a50">SPF_TRUE</a>); |
| 2506 |
|
|
02498 } |
| 2507 |
|
|
02499 |
| 2508 |
|
|
02500 |
| 2509 |
|
|
02501 <span class="comment">/* _UTIL_pthread_mutex</span> |
| 2510 |
|
|
02502 <span class="comment">*</span> |
| 2511 |
|
|
02503 <span class="comment">* Author: James Couzens <jcouzens@codeshare.ca></span> |
| 2512 |
|
|
02504 <span class="comment">*</span> |
| 2513 |
|
|
02505 <span class="comment">* Date: 09/08/04</span> |
| 2514 |
|
|
02506 <span class="comment">*</span> |
| 2515 |
|
|
02507 <span class="comment">* Desc:</span> |
| 2516 |
|
|
02508 <span class="comment">* Locks or unlocks the passed mutex based on the additional value</span> |
| 2517 |
|
|
02509 <span class="comment">* which is and enumerattion (SPF_BOOL)</span> |
| 2518 |
|
|
02510 <span class="comment">*</span> |
| 2519 |
|
|
02511 <span class="comment">*/</span> |
| 2520 |
|
|
<a name="l02512"></a><a class="code" href="util_8h.html#a58">02512</a> <span class="keywordtype">void</span> <a class="code" href="util_8h.html#a58">_UTIL_pthread_mutex</a>(<span class="keywordtype">void</span> *mutex, <a class="code" href="spf_8h.html#a35">SPF_BOOL</a> action) |
| 2521 |
|
|
02513 { |
| 2522 |
|
|
02514 |
| 2523 |
|
|
02515 <span class="preprocessor">#ifdef _WITH_PTHREADS</span> |
| 2524 |
|
|
02516 <span class="preprocessor"></span> |
| 2525 |
|
|
02517 <span class="keywordflow">switch</span> (action) |
| 2526 |
|
|
02518 { |
| 2527 |
|
|
02519 <span class="keywordflow">case</span> <a class="code" href="spf_8h.html#a87a50">SPF_TRUE</a>: |
| 2528 |
|
|
02520 pthread_mutex_lock((pthread_mutex_t *)mutex); |
| 2529 |
|
|
02521 <span class="keywordflow">return</span>; |
| 2530 |
|
|
02522 |
| 2531 |
|
|
02523 <span class="keywordflow">case</span> <a class="code" href="spf_8h.html#a87a49">SPF_FALSE</a>: |
| 2532 |
|
|
02524 pthread_mutex_unlock((pthread_mutex_t *)mutex); |
| 2533 |
|
|
02525 <span class="keywordflow">return</span>; |
| 2534 |
|
|
02526 } |
| 2535 |
|
|
02527 |
| 2536 |
|
|
02528 <span class="preprocessor">#endif </span><span class="comment">/* _WITH_PTHREADS */</span> |
| 2537 |
|
|
02529 |
| 2538 |
|
|
02530 <span class="keywordflow">return</span>; |
| 2539 |
|
|
02531 } |
| 2540 |
|
|
02532 |
| 2541 |
|
|
02533 |
| 2542 |
|
|
02534 <span class="comment">/* end of util.c */</span> |
| 2543 |
|
|
</div></pre><hr size="1"><address style="align: right;"><small>Generated on Thu Sep 16 18:10:47 2004 for libSPF v1.0 by |
| 2544 |
|
|
<a href="http://www.doxygen.org/index.html"> |
| 2545 |
|
|
<img src="doxygen.png" alt="doxygen" align="middle" border=0 ></a> 1.3.8 </small></address> |
| 2546 |
|
|
</body> |
| 2547 |
|
|
</html> |