xref: /freebsd/crypto/heimdal/doc/doxyout/ntlm/html/test__ntlm_8c-example.html (revision 6be3386466ab79a84b48429ae66244f21526d3df)
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
3<title>Heimdalntlmlibrary: test_ntlm.c</title>
4<link href="doxygen.css" rel="stylesheet" type="text/css">
5<link href="tabs.css" rel="stylesheet" type="text/css">
6</head><body>
7<p>
8<a href="http://www.h5l.org/"><img src="http://www.h5l.org/keyhole-heimdal.png" alt="keyhole logo"/></a>
9</p>
10<!-- end of header marker -->
11<!-- Generated by Doxygen 1.5.6 -->
12<div class="navigation" id="top">
13  <div class="tabs">
14    <ul>
15      <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
16      <li><a href="modules.html"><span>Modules</span></a></li>
17      <li><a href="annotated.html"><span>Data&nbsp;Structures</span></a></li>
18      <li><a href="examples.html"><span>Examples</span></a></li>
19    </ul>
20  </div>
21</div>
22<div class="contents">
23<h1>test_ntlm.c</h1>Example how to use the NTLM primitives.<p>
24<div class="fragment"><pre class="fragment"><span class="comment">/*</span>
25<span class="comment"> * Copyright (c) 2006 - 2007 Kungliga Tekniska Högskolan</span>
26<span class="comment"> * (Royal Institute of Technology, Stockholm, Sweden).</span>
27<span class="comment"> * All rights reserved.</span>
28<span class="comment"> *</span>
29<span class="comment"> * Redistribution and use in source and binary forms, with or without</span>
30<span class="comment"> * modification, are permitted provided that the following conditions</span>
31<span class="comment"> * are met:</span>
32<span class="comment"> *</span>
33<span class="comment"> * 1. Redistributions of source code must retain the above copyright</span>
34<span class="comment"> *    notice, this list of conditions and the following disclaimer.</span>
35<span class="comment"> *</span>
36<span class="comment"> * 2. Redistributions in binary form must reproduce the above copyright</span>
37<span class="comment"> *    notice, this list of conditions and the following disclaimer in the</span>
38<span class="comment"> *    documentation and/or other materials provided with the distribution.</span>
39<span class="comment"> *</span>
40<span class="comment"> * 3. Neither the name of KTH nor the names of its contributors may be</span>
41<span class="comment"> *    used to endorse or promote products derived from this software without</span>
42<span class="comment"> *    specific prior written permission.</span>
43<span class="comment"> *</span>
44<span class="comment"> * THIS SOFTWARE IS PROVIDED BY KTH AND ITS CONTRIBUTORS ``AS IS'' AND ANY</span>
45<span class="comment"> * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE</span>
46<span class="comment"> * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR</span>
47<span class="comment"> * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KTH OR ITS CONTRIBUTORS BE</span>
48<span class="comment"> * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR</span>
49<span class="comment"> * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF</span>
50<span class="comment"> * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR</span>
51<span class="comment"> * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,</span>
52<span class="comment"> * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR</span>
53<span class="comment"> * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF</span>
54<span class="comment"> * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</span>
55<span class="comment"> */</span>
56
57<span class="preprocessor">#include "config.h"</span>
58
59<span class="preprocessor">#include &lt;stdio.h&gt;</span>
60<span class="preprocessor">#include &lt;err.h&gt;</span>
61<span class="preprocessor">#include &lt;roken.h&gt;</span>
62<span class="preprocessor">#include &lt;getarg.h&gt;</span>
63
64<span class="preprocessor">#include &lt;krb5-types.h&gt;</span> <span class="comment">/* or &lt;inttypes.h&gt; */</span>
65<span class="preprocessor">#include &lt;heimntlm.h&gt;</span>
66
67<span class="keyword">static</span> <span class="keywordtype">int</span>
68test_parse(<span class="keywordtype">void</span>)
69{
70    <span class="keyword">const</span> <span class="keywordtype">char</span> *user = <span class="stringliteral">"foo"</span>,
71        *domain = <span class="stringliteral">"mydomain"</span>,
72        *password = <span class="stringliteral">"digestpassword"</span>,
73        *target = <span class="stringliteral">"DOMAIN"</span>;
74    <span class="keyword">struct </span><a name="_a0"></a><a class="code" href="structntlm__type1.html">ntlm_type1</a> type1;
75    <span class="keyword">struct </span><a name="_a1"></a><a class="code" href="structntlm__type2.html">ntlm_type2</a> type2;
76    <span class="keyword">struct </span><a name="_a2"></a><a class="code" href="structntlm__type3.html">ntlm_type3</a> type3;
77    <span class="keyword">struct </span><a name="_a3"></a><a class="code" href="structntlm__buf.html">ntlm_buf</a> data;
78    <span class="keywordtype">int</span> ret, flags;
79
80    memset(&amp;type1, 0, <span class="keyword">sizeof</span>(type1));
81
82    type1.<a name="a4"></a><a class="code" href="structntlm__type1.html#e2f4bbf968f7dde8f1cd2a71396a06fb">flags</a> = NTLM_NEG_UNICODE|NTLM_NEG_TARGET|NTLM_NEG_NTLM;
83    type1.<a name="a5"></a><a class="code" href="structntlm__type1.html#7d99f4da91742cd5bd94f1af1713c075">domain</a> = rk_UNCONST(domain);
84    type1.<a name="a6"></a><a class="code" href="structntlm__type1.html#63e2c0e1d31b93802670e677b89ae7e8">hostname</a> = NULL;
85    type1.<a name="a7"></a><a class="code" href="structntlm__type1.html#3f0a2c98b021a211c030b09b37d35fa3">os</a>[0] = 0;
86    type1.<a class="code" href="structntlm__type1.html#3f0a2c98b021a211c030b09b37d35fa3">os</a>[1] = 0;
87
88    ret = <a name="a8"></a><a class="code" href="group__ntlm__core.html#g0107727234287ac61a8801b0faff9dff">heim_ntlm_encode_type1</a>(&amp;type1, &amp;data);
89    <span class="keywordflow">if</span> (ret)
90        errx(1, <span class="stringliteral">"heim_ntlm_encode_type1"</span>);
91
92    memset(&amp;type1, 0, <span class="keyword">sizeof</span>(type1));
93
94    ret = heim_ntlm_decode_type1(&amp;data, &amp;type1);
95    free(data.<a name="a9"></a><a class="code" href="structntlm__buf.html#0cb7caf04f8f80326491b45edcdd2687">data</a>);
96    <span class="keywordflow">if</span> (ret)
97        errx(1, <span class="stringliteral">"heim_ntlm_encode_type1"</span>);
98
99    <a name="a10"></a><a class="code" href="group__ntlm__core.html#g76fa6caf3f539e24008e31613f5eb663">heim_ntlm_free_type1</a>(&amp;type1);
100
101    <span class="comment">/*</span>
102<span class="comment">     *</span>
103<span class="comment">     */</span>
104
105    memset(&amp;type2, 0, <span class="keyword">sizeof</span>(type2));
106
107    flags = NTLM_NEG_UNICODE | NTLM_NEG_NTLM | NTLM_TARGET_DOMAIN;
108    type2.<a name="a11"></a><a class="code" href="structntlm__type2.html#7f52e5d5e1e31e369d88d1cfb738a9ff">flags</a> = flags;
109
110    memset(type2.<a name="a12"></a><a class="code" href="structntlm__type2.html#12c5c7a960c60bbd54dbf49527856bab">challenge</a>, 0x7f, <span class="keyword">sizeof</span>(type2.<a class="code" href="structntlm__type2.html#12c5c7a960c60bbd54dbf49527856bab">challenge</a>));
111    type2.<a name="a13"></a><a class="code" href="structntlm__type2.html#7ed7a5246d77d4358e6fa459c6263a10">targetname</a> = rk_UNCONST(target);
112    type2.<a name="a14"></a><a class="code" href="structntlm__type2.html#d468bf3c5f042a893f3d118a9cb50a34">targetinfo</a>.<a class="code" href="structntlm__buf.html#0cb7caf04f8f80326491b45edcdd2687">data</a> = NULL;
113    type2.<a class="code" href="structntlm__type2.html#d468bf3c5f042a893f3d118a9cb50a34">targetinfo</a>.<a name="a15"></a><a class="code" href="structntlm__buf.html#1ca1856fd5b4ac0197320d7723c73bd0">length</a> = 0;
114
115    ret = <a name="a16"></a><a class="code" href="group__ntlm__core.html#g2860c6f6d497255eb433adc8cacc49dd">heim_ntlm_encode_type2</a>(&amp;type2, &amp;data);
116    <span class="keywordflow">if</span> (ret)
117        errx(1, <span class="stringliteral">"heim_ntlm_encode_type2"</span>);
118
119    memset(&amp;type2, 0, <span class="keyword">sizeof</span>(type2));
120
121    ret = heim_ntlm_decode_type2(&amp;data, &amp;type2);
122    free(data.<a class="code" href="structntlm__buf.html#0cb7caf04f8f80326491b45edcdd2687">data</a>);
123    <span class="keywordflow">if</span> (ret)
124        errx(1, <span class="stringliteral">"heim_ntlm_decode_type2"</span>);
125
126    <a name="a17"></a><a class="code" href="group__ntlm__core.html#g8fde84c86f1c7c9f730f7fb4acedcb43">heim_ntlm_free_type2</a>(&amp;type2);
127
128    <span class="comment">/*</span>
129<span class="comment">     *</span>
130<span class="comment">     */</span>
131
132    memset(&amp;type3, 0, <span class="keyword">sizeof</span>(type3));
133
134    type3.<a name="a18"></a><a class="code" href="structntlm__type3.html#65347e68a22b66fc65c299f2cda2cf2d">flags</a> = flags;
135    type3.<a name="a19"></a><a class="code" href="structntlm__type3.html#c6e99229102b238c4aad9b93fabe95b7">username</a> = rk_UNCONST(user);
136    type3.<a name="a20"></a><a class="code" href="structntlm__type3.html#89d7688f04cb1362ffa5a81759d28716">targetname</a> = rk_UNCONST(target);
137    type3.<a name="a21"></a><a class="code" href="structntlm__type3.html#ffbe974b5c93e47e2c8bf6f5a767c82d">ws</a> = rk_UNCONST(<span class="stringliteral">"workstation"</span>);
138
139    {
140        <span class="keyword">struct </span><a class="code" href="structntlm__buf.html">ntlm_buf</a> key;
141        <a name="a22"></a><a class="code" href="group__ntlm__core.html#g254ee0a4d5a2594833e36697ad575d7e">heim_ntlm_nt_key</a>(password, &amp;key);
142
143        <a name="a23"></a><a class="code" href="group__ntlm__core.html#ge3b634802ef94233a175291abd2ea14d">heim_ntlm_calculate_ntlm1</a>(key.<a class="code" href="structntlm__buf.html#0cb7caf04f8f80326491b45edcdd2687">data</a>, key.<a class="code" href="structntlm__buf.html#1ca1856fd5b4ac0197320d7723c73bd0">length</a>,
144                                  type2.<a class="code" href="structntlm__type2.html#12c5c7a960c60bbd54dbf49527856bab">challenge</a>,
145                                  &amp;type3.<a name="a24"></a><a class="code" href="structntlm__type3.html#7b496ad8682fbd4a5fe06c32da7621c7">ntlm</a>);
146        free(key.<a class="code" href="structntlm__buf.html#0cb7caf04f8f80326491b45edcdd2687">data</a>);
147    }
148
149    ret = <a name="a25"></a><a class="code" href="group__ntlm__core.html#g9cf026be6e602c22d62aa9e47e85c7c2">heim_ntlm_encode_type3</a>(&amp;type3, &amp;data);
150    <span class="keywordflow">if</span> (ret)
151        errx(1, <span class="stringliteral">"heim_ntlm_encode_type3"</span>);
152
153    free(type3.<a class="code" href="structntlm__type3.html#7b496ad8682fbd4a5fe06c32da7621c7">ntlm</a>.<a class="code" href="structntlm__buf.html#0cb7caf04f8f80326491b45edcdd2687">data</a>);
154
155    memset(&amp;type3, 0, <span class="keyword">sizeof</span>(type3));
156
157    ret = heim_ntlm_decode_type3(&amp;data, 1, &amp;type3);
158    free(data.<a class="code" href="structntlm__buf.html#0cb7caf04f8f80326491b45edcdd2687">data</a>);
159    <span class="keywordflow">if</span> (ret)
160        errx(1, <span class="stringliteral">"heim_ntlm_decode_type3"</span>);
161
162    <span class="keywordflow">if</span> (strcmp(<span class="stringliteral">"workstation"</span>, type3.<a class="code" href="structntlm__type3.html#ffbe974b5c93e47e2c8bf6f5a767c82d">ws</a>) != 0)
163        errx(1, <span class="stringliteral">"type3 ws wrong"</span>);
164
165    <span class="keywordflow">if</span> (strcmp(target, type3.<a class="code" href="structntlm__type3.html#89d7688f04cb1362ffa5a81759d28716">targetname</a>) != 0)
166        errx(1, <span class="stringliteral">"type3 targetname wrong"</span>);
167
168    <span class="keywordflow">if</span> (strcmp(user, type3.<a class="code" href="structntlm__type3.html#c6e99229102b238c4aad9b93fabe95b7">username</a>) != 0)
169        errx(1, <span class="stringliteral">"type3 username wrong"</span>);
170
171
172    <a name="a26"></a><a class="code" href="group__ntlm__core.html#gc4e6d01e5247b8540d41ccbbf1031319">heim_ntlm_free_type3</a>(&amp;type3);
173
174    <span class="comment">/*</span>
175<span class="comment">     * NTLMv2</span>
176<span class="comment">     */</span>
177
178    memset(&amp;type2, 0, <span class="keyword">sizeof</span>(type2));
179
180    flags = NTLM_NEG_UNICODE | NTLM_NEG_NTLM | NTLM_TARGET_DOMAIN;
181    type2.<a class="code" href="structntlm__type2.html#7f52e5d5e1e31e369d88d1cfb738a9ff">flags</a> = flags;
182
183    memset(type2.<a class="code" href="structntlm__type2.html#12c5c7a960c60bbd54dbf49527856bab">challenge</a>, 0x7f, <span class="keyword">sizeof</span>(type2.<a class="code" href="structntlm__type2.html#12c5c7a960c60bbd54dbf49527856bab">challenge</a>));
184    type2.<a class="code" href="structntlm__type2.html#7ed7a5246d77d4358e6fa459c6263a10">targetname</a> = rk_UNCONST(target);
185    type2.<a class="code" href="structntlm__type2.html#d468bf3c5f042a893f3d118a9cb50a34">targetinfo</a>.<a class="code" href="structntlm__buf.html#0cb7caf04f8f80326491b45edcdd2687">data</a> = <span class="stringliteral">"\x00\x00"</span>;
186    type2.<a class="code" href="structntlm__type2.html#d468bf3c5f042a893f3d118a9cb50a34">targetinfo</a>.<a class="code" href="structntlm__buf.html#1ca1856fd5b4ac0197320d7723c73bd0">length</a> = 2;
187
188    ret = <a class="code" href="group__ntlm__core.html#g2860c6f6d497255eb433adc8cacc49dd">heim_ntlm_encode_type2</a>(&amp;type2, &amp;data);
189    <span class="keywordflow">if</span> (ret)
190        errx(1, <span class="stringliteral">"heim_ntlm_encode_type2"</span>);
191
192    memset(&amp;type2, 0, <span class="keyword">sizeof</span>(type2));
193
194    ret = heim_ntlm_decode_type2(&amp;data, &amp;type2);
195    free(data.<a class="code" href="structntlm__buf.html#0cb7caf04f8f80326491b45edcdd2687">data</a>);
196    <span class="keywordflow">if</span> (ret)
197        errx(1, <span class="stringliteral">"heim_ntlm_decode_type2"</span>);
198
199    <a class="code" href="group__ntlm__core.html#g8fde84c86f1c7c9f730f7fb4acedcb43">heim_ntlm_free_type2</a>(&amp;type2);
200
201    <span class="keywordflow">return</span> 0;
202}
203
204<span class="keyword">static</span> <span class="keywordtype">int</span>
205test_keys(<span class="keywordtype">void</span>)
206{
207    <span class="keyword">const</span> <span class="keywordtype">char</span>
208        *username = <span class="stringliteral">"test"</span>,
209        *password = <span class="stringliteral">"test1234"</span>,
210        *target = <span class="stringliteral">"TESTNT"</span>;
211    <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>
212        serverchallenge[8] = <span class="stringliteral">"\x67\x7f\x1c\x55\x7a\x5e\xe9\x6c"</span>;
213    <span class="keyword">struct </span><a class="code" href="structntlm__buf.html">ntlm_buf</a> infotarget, infotarget2, answer, key;
214    <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> ntlmv2[16], ntlmv2_1[16];
215    <span class="keywordtype">int</span> ret;
216
217    infotarget.length = 70;
218    infotarget.data =
219        <span class="stringliteral">"\x02\x00\x0c\x00\x54\x00\x45\x00\x53\x00\x54\x00\x4e\x00\x54\x00"</span>
220        <span class="stringliteral">"\x01\x00\x0c\x00\x4d\x00\x45\x00\x4d\x00\x42\x00\x45\x00\x52\x00"</span>
221        <span class="stringliteral">"\x03\x00\x1e\x00\x6d\x00\x65\x00\x6d\x00\x62\x00\x65\x00\x72\x00"</span>
222            <span class="stringliteral">"\x2e\x00\x74\x00\x65\x00\x73\x00\x74\x00\x2e\x00\x63\x00\x6f"</span>
223            <span class="stringliteral">"\x00\x6d\x00"</span>
224        <span class="stringliteral">"\x00\x00\x00\x00"</span>;
225
226    answer.length = 0;
227    answer.data = NULL;
228
229    <a class="code" href="group__ntlm__core.html#g254ee0a4d5a2594833e36697ad575d7e">heim_ntlm_nt_key</a>(password, &amp;key);
230
231    ret = <a name="a27"></a><a class="code" href="group__ntlm__core.html#ga8f07fb71a0d5f095cde3fb9fb40d10c">heim_ntlm_calculate_ntlm2</a>(key.data,
232                                    key.length,
233                                    username,
234                                    target,
235                                    serverchallenge,
236                                    &amp;infotarget,
237                                    ntlmv2,
238                                    &amp;answer);
239    <span class="keywordflow">if</span> (ret)
240        errx(1, <span class="stringliteral">"heim_ntlm_calculate_ntlm2"</span>);
241
242    ret = <a name="a28"></a><a class="code" href="group__ntlm__core.html#g3b3d6a5187cab6bfe656afa7a8273ca6">heim_ntlm_verify_ntlm2</a>(key.data,
243                                 key.length,
244                                 username,
245                                 target,
246                                 0,
247                                 serverchallenge,
248                                 &amp;answer,
249                                 &amp;infotarget2,
250                                 ntlmv2_1);
251    <span class="keywordflow">if</span> (ret)
252        errx(1, <span class="stringliteral">"heim_ntlm_verify_ntlm2"</span>);
253
254    <span class="keywordflow">if</span> (memcmp(ntlmv2, ntlmv2_1, <span class="keyword">sizeof</span>(ntlmv2)) != 0)
255        errx(1, <span class="stringliteral">"ntlm master key not same"</span>);
256
257    <span class="keywordflow">if</span> (infotarget.length &gt; infotarget2.length)
258        errx(1, <span class="stringliteral">"infotarget length"</span>);
259
260    <span class="keywordflow">if</span> (memcmp(infotarget.data, infotarget2.data, infotarget.length) != 0)
261        errx(1, <span class="stringliteral">"infotarget not the same"</span>);
262
263    free(key.data);
264    free(answer.data);
265    free(infotarget2.data);
266
267    <span class="keywordflow">return</span> 0;
268}
269
270<span class="keyword">static</span> <span class="keywordtype">int</span>
271test_ntlm2_session_resp(<span class="keywordtype">void</span>)
272{
273    <span class="keywordtype">int</span> ret;
274    <span class="keyword">struct </span><a class="code" href="structntlm__buf.html">ntlm_buf</a> lm, ntlm;
275
276    <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> lm_resp[24] =
277        <span class="stringliteral">"\xff\xff\xff\x00\x11\x22\x33\x44"</span>
278        <span class="stringliteral">"\x00\x00\x00\x00\x00\x00\x00\x00"</span>
279        <span class="stringliteral">"\x00\x00\x00\x00\x00\x00\x00\x00"</span>;
280    <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> ntlm2_sess_resp[24] =
281        <span class="stringliteral">"\x10\xd5\x50\x83\x2d\x12\xb2\xcc"</span>
282        <span class="stringliteral">"\xb7\x9d\x5a\xd1\xf4\xee\xd3\xdf"</span>
283        <span class="stringliteral">"\x82\xac\xa4\xc3\x68\x1d\xd4\x55"</span>;
284
285    <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> client_nonce[8] =
286        <span class="stringliteral">"\xff\xff\xff\x00\x11\x22\x33\x44"</span>;
287    <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> server_challenge[8] =
288        <span class="stringliteral">"\x01\x23\x45\x67\x89\xab\xcd\xef"</span>;
289
290    <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> ntlm_hash[16] =
291        <span class="stringliteral">"\xcd\x06\xca\x7c\x7e\x10\xc9\x9b"</span>
292        <span class="stringliteral">"\x1d\x33\xb7\x48\x5a\x2e\xd8\x08"</span>;
293
294    ret = heim_ntlm_calculate_ntlm2_sess(client_nonce,
295                                         server_challenge,
296                                         ntlm_hash,
297                                         &amp;lm,
298                                         &amp;ntlm);
299    <span class="keywordflow">if</span> (ret)
300        errx(1, <span class="stringliteral">"heim_ntlm_calculate_ntlm2_sess_resp"</span>);
301
302    <span class="keywordflow">if</span> (lm.length != 24 || memcmp(lm.data, lm_resp, 24) != 0)
303        errx(1, <span class="stringliteral">"lm_resp wrong"</span>);
304    <span class="keywordflow">if</span> (ntlm.length != 24 || memcmp(ntlm.data, ntlm2_sess_resp, 24) != 0)
305        errx(1, <span class="stringliteral">"ntlm2_sess_resp wrong"</span>);
306
307    free(lm.data);
308    free(ntlm.data);
309
310
311    <span class="keywordflow">return</span> 0;
312}
313
314<span class="keyword">static</span> <span class="keywordtype">int</span>
315test_targetinfo(<span class="keywordtype">void</span>)
316{
317    <span class="keyword">struct </span>ntlm_targetinfo ti;
318    <span class="keyword">struct </span><a class="code" href="structntlm__buf.html">ntlm_buf</a> buf;
319    <span class="keyword">const</span> <span class="keywordtype">char</span> *dnsservername = <span class="stringliteral">"dnsservername"</span>;
320    <span class="keywordtype">int</span> ret;
321
322    memset(&amp;ti, 0, <span class="keyword">sizeof</span>(ti));
323
324    ti.dnsservername = rk_UNCONST(dnsservername);
325    ti.avflags = 1;
326    ret = <a name="a29"></a><a class="code" href="group__ntlm__core.html#g2881747fad2ac2979a28d3bd050b0fa8">heim_ntlm_encode_targetinfo</a>(&amp;ti, 1, &amp;buf);
327    <span class="keywordflow">if</span> (ret)
328        <span class="keywordflow">return</span> ret;
329
330    memset(&amp;ti, 0, <span class="keyword">sizeof</span>(ti));
331
332    ret = <a name="a30"></a><a class="code" href="group__ntlm__core.html#gf1d4de2faec8b1c1070a55fd2e6e630f">heim_ntlm_decode_targetinfo</a>(&amp;buf, 1, &amp;ti);
333    <span class="keywordflow">if</span> (ret)
334        <span class="keywordflow">return</span> ret;
335
336    <span class="keywordflow">if</span> (ti.dnsservername == NULL ||
337        strcmp(ti.dnsservername, dnsservername) != 0)
338        errx(1, <span class="stringliteral">"ti.dnshostname != %s"</span>, dnsservername);
339    <span class="keywordflow">if</span> (ti.avflags != 1)
340        errx(1, <span class="stringliteral">"ti.avflags != 1"</span>);
341
342    <a name="a31"></a><a class="code" href="group__ntlm__core.html#g704ec8c5dba05ef57186d242ff165565">heim_ntlm_free_targetinfo</a>(&amp;ti);
343
344    <span class="keywordflow">return</span> 0;
345}
346
347<span class="keyword">static</span> <span class="keywordtype">int</span> verbose_flag = 0;
348<span class="keyword">static</span> <span class="keywordtype">int</span> version_flag = 0;
349<span class="keyword">static</span> <span class="keywordtype">int</span> help_flag    = 0;
350
351<span class="keyword">static</span> <span class="keyword">struct </span>getargs args[] = {
352    {<span class="stringliteral">"verbose"</span>, 0,      arg_flag,       &amp;verbose_flag, <span class="stringliteral">"verbose printing"</span>, NULL },
353    {<span class="stringliteral">"version"</span>, 0,      arg_flag,       &amp;version_flag, <span class="stringliteral">"print version"</span>, NULL },
354    {<span class="stringliteral">"help"</span>,    0,      arg_flag,       &amp;help_flag,  NULL, NULL }
355};
356
357<span class="keyword">static</span> <span class="keywordtype">void</span>
358usage (<span class="keywordtype">int</span> ret)
359{
360    arg_printusage (args, <span class="keyword">sizeof</span>(args)/<span class="keyword">sizeof</span>(*args),
361                    NULL, <span class="stringliteral">""</span>);
362    exit (ret);
363}
364
365<span class="keywordtype">int</span>
366main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> **argv)
367{
368    <span class="keywordtype">int</span> ret = 0, optind = 0;
369
370    setprogname(argv[0]);
371
372    <span class="keywordflow">if</span>(getarg(args, <span class="keyword">sizeof</span>(args) / <span class="keyword">sizeof</span>(args[0]), argc, argv, &amp;optind))
373        usage(1);
374
375    <span class="keywordflow">if</span> (help_flag)
376        usage (0);
377
378    <span class="keywordflow">if</span>(version_flag){
379        print_version(NULL);
380        exit(0);
381    }
382
383    argc -= optind;
384    argv += optind;
385
386    <span class="keywordflow">if</span> (verbose_flag)
387        printf(<span class="stringliteral">"test_parse\n"</span>);
388
389    ret += test_parse();
390    <span class="keywordflow">if</span> (verbose_flag)
391        printf(<span class="stringliteral">"test_keys\n"</span>);
392
393    ret += test_keys();
394    <span class="keywordflow">if</span> (verbose_flag)
395        printf(<span class="stringliteral">"test_ntlm2_session_resp\n"</span>);
396    ret += test_ntlm2_session_resp();
397
398    <span class="keywordflow">if</span> (verbose_flag)
399        printf(<span class="stringliteral">"test_targetinfo\n"</span>);
400    ret += test_targetinfo();
401
402    <span class="keywordflow">return</span> ret;
403}
404</pre></div> </div>
405<hr size="1"><address style="text-align: right;"><small>
406Generated on Wed Jan 11 14:07:50 2012 for Heimdalntlmlibrary by&nbsp;<a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.6</small></address>
407</body>
408</html>
409