xref: /minix3/crypto/external/bsd/heimdal/dist/lib/ntlm/test_ntlm.c (revision ebfedea0ce5bbe81e252ddf32d732e40fb633fae)
1*ebfedea0SLionel Sambuc /*	$NetBSD: test_ntlm.c,v 1.1.1.1 2011/04/13 18:15:39 elric Exp $	*/
2*ebfedea0SLionel Sambuc 
3*ebfedea0SLionel Sambuc /*
4*ebfedea0SLionel Sambuc  * Copyright (c) 2006 - 2007 Kungliga Tekniska Högskolan
5*ebfedea0SLionel Sambuc  * (Royal Institute of Technology, Stockholm, Sweden).
6*ebfedea0SLionel Sambuc  * All rights reserved.
7*ebfedea0SLionel Sambuc  *
8*ebfedea0SLionel Sambuc  * Redistribution and use in source and binary forms, with or without
9*ebfedea0SLionel Sambuc  * modification, are permitted provided that the following conditions
10*ebfedea0SLionel Sambuc  * are met:
11*ebfedea0SLionel Sambuc  *
12*ebfedea0SLionel Sambuc  * 1. Redistributions of source code must retain the above copyright
13*ebfedea0SLionel Sambuc  *    notice, this list of conditions and the following disclaimer.
14*ebfedea0SLionel Sambuc  *
15*ebfedea0SLionel Sambuc  * 2. Redistributions in binary form must reproduce the above copyright
16*ebfedea0SLionel Sambuc  *    notice, this list of conditions and the following disclaimer in the
17*ebfedea0SLionel Sambuc  *    documentation and/or other materials provided with the distribution.
18*ebfedea0SLionel Sambuc  *
19*ebfedea0SLionel Sambuc  * 3. Neither the name of KTH nor the names of its contributors may be
20*ebfedea0SLionel Sambuc  *    used to endorse or promote products derived from this software without
21*ebfedea0SLionel Sambuc  *    specific prior written permission.
22*ebfedea0SLionel Sambuc  *
23*ebfedea0SLionel Sambuc  * THIS SOFTWARE IS PROVIDED BY KTH AND ITS CONTRIBUTORS ``AS IS'' AND ANY
24*ebfedea0SLionel Sambuc  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25*ebfedea0SLionel Sambuc  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26*ebfedea0SLionel Sambuc  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KTH OR ITS CONTRIBUTORS BE
27*ebfedea0SLionel Sambuc  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28*ebfedea0SLionel Sambuc  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29*ebfedea0SLionel Sambuc  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
30*ebfedea0SLionel Sambuc  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
31*ebfedea0SLionel Sambuc  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
32*ebfedea0SLionel Sambuc  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
33*ebfedea0SLionel Sambuc  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34*ebfedea0SLionel Sambuc  */
35*ebfedea0SLionel Sambuc 
36*ebfedea0SLionel Sambuc #include "config.h"
37*ebfedea0SLionel Sambuc 
38*ebfedea0SLionel Sambuc #include <stdio.h>
39*ebfedea0SLionel Sambuc #include <err.h>
40*ebfedea0SLionel Sambuc #include <krb5/roken.h>
41*ebfedea0SLionel Sambuc #include <krb5/getarg.h>
42*ebfedea0SLionel Sambuc 
43*ebfedea0SLionel Sambuc #include <krb5/krb5-types.h> /* or <inttypes.h> */
44*ebfedea0SLionel Sambuc #include <krb5/heimntlm.h>
45*ebfedea0SLionel Sambuc 
46*ebfedea0SLionel Sambuc static int
test_parse(void)47*ebfedea0SLionel Sambuc test_parse(void)
48*ebfedea0SLionel Sambuc {
49*ebfedea0SLionel Sambuc     const char *user = "foo",
50*ebfedea0SLionel Sambuc 	*domain = "mydomain",
51*ebfedea0SLionel Sambuc 	*password = "digestpassword",
52*ebfedea0SLionel Sambuc 	*target = "DOMAIN";
53*ebfedea0SLionel Sambuc     struct ntlm_type1 type1;
54*ebfedea0SLionel Sambuc     struct ntlm_type2 type2;
55*ebfedea0SLionel Sambuc     struct ntlm_type3 type3;
56*ebfedea0SLionel Sambuc     struct ntlm_buf data;
57*ebfedea0SLionel Sambuc     int ret, flags;
58*ebfedea0SLionel Sambuc 
59*ebfedea0SLionel Sambuc     memset(&type1, 0, sizeof(type1));
60*ebfedea0SLionel Sambuc 
61*ebfedea0SLionel Sambuc     type1.flags = NTLM_NEG_UNICODE|NTLM_NEG_TARGET|NTLM_NEG_NTLM;
62*ebfedea0SLionel Sambuc     type1.domain = rk_UNCONST(domain);
63*ebfedea0SLionel Sambuc     type1.hostname = NULL;
64*ebfedea0SLionel Sambuc     type1.os[0] = 0;
65*ebfedea0SLionel Sambuc     type1.os[1] = 0;
66*ebfedea0SLionel Sambuc 
67*ebfedea0SLionel Sambuc     ret = heim_ntlm_encode_type1(&type1, &data);
68*ebfedea0SLionel Sambuc     if (ret)
69*ebfedea0SLionel Sambuc 	errx(1, "heim_ntlm_encode_type1");
70*ebfedea0SLionel Sambuc 
71*ebfedea0SLionel Sambuc     memset(&type1, 0, sizeof(type1));
72*ebfedea0SLionel Sambuc 
73*ebfedea0SLionel Sambuc     ret = heim_ntlm_decode_type1(&data, &type1);
74*ebfedea0SLionel Sambuc     free(data.data);
75*ebfedea0SLionel Sambuc     if (ret)
76*ebfedea0SLionel Sambuc 	errx(1, "heim_ntlm_encode_type1");
77*ebfedea0SLionel Sambuc 
78*ebfedea0SLionel Sambuc     heim_ntlm_free_type1(&type1);
79*ebfedea0SLionel Sambuc 
80*ebfedea0SLionel Sambuc     /*
81*ebfedea0SLionel Sambuc      *
82*ebfedea0SLionel Sambuc      */
83*ebfedea0SLionel Sambuc 
84*ebfedea0SLionel Sambuc     memset(&type2, 0, sizeof(type2));
85*ebfedea0SLionel Sambuc 
86*ebfedea0SLionel Sambuc     flags = NTLM_NEG_UNICODE | NTLM_NEG_NTLM | NTLM_TARGET_DOMAIN;
87*ebfedea0SLionel Sambuc     type2.flags = flags;
88*ebfedea0SLionel Sambuc 
89*ebfedea0SLionel Sambuc     memset(type2.challenge, 0x7f, sizeof(type2.challenge));
90*ebfedea0SLionel Sambuc     type2.targetname = rk_UNCONST(target);
91*ebfedea0SLionel Sambuc     type2.targetinfo.data = NULL;
92*ebfedea0SLionel Sambuc     type2.targetinfo.length = 0;
93*ebfedea0SLionel Sambuc 
94*ebfedea0SLionel Sambuc     ret = heim_ntlm_encode_type2(&type2, &data);
95*ebfedea0SLionel Sambuc     if (ret)
96*ebfedea0SLionel Sambuc 	errx(1, "heim_ntlm_encode_type2");
97*ebfedea0SLionel Sambuc 
98*ebfedea0SLionel Sambuc     memset(&type2, 0, sizeof(type2));
99*ebfedea0SLionel Sambuc 
100*ebfedea0SLionel Sambuc     ret = heim_ntlm_decode_type2(&data, &type2);
101*ebfedea0SLionel Sambuc     free(data.data);
102*ebfedea0SLionel Sambuc     if (ret)
103*ebfedea0SLionel Sambuc 	errx(1, "heim_ntlm_decode_type2");
104*ebfedea0SLionel Sambuc 
105*ebfedea0SLionel Sambuc     heim_ntlm_free_type2(&type2);
106*ebfedea0SLionel Sambuc 
107*ebfedea0SLionel Sambuc     /*
108*ebfedea0SLionel Sambuc      *
109*ebfedea0SLionel Sambuc      */
110*ebfedea0SLionel Sambuc 
111*ebfedea0SLionel Sambuc     memset(&type3, 0, sizeof(type3));
112*ebfedea0SLionel Sambuc 
113*ebfedea0SLionel Sambuc     type3.flags = flags;
114*ebfedea0SLionel Sambuc     type3.username = rk_UNCONST(user);
115*ebfedea0SLionel Sambuc     type3.targetname = rk_UNCONST(target);
116*ebfedea0SLionel Sambuc     type3.ws = rk_UNCONST("workstation");
117*ebfedea0SLionel Sambuc 
118*ebfedea0SLionel Sambuc     {
119*ebfedea0SLionel Sambuc 	struct ntlm_buf key;
120*ebfedea0SLionel Sambuc 	heim_ntlm_nt_key(password, &key);
121*ebfedea0SLionel Sambuc 
122*ebfedea0SLionel Sambuc 	heim_ntlm_calculate_ntlm1(key.data, key.length,
123*ebfedea0SLionel Sambuc 				  type2.challenge,
124*ebfedea0SLionel Sambuc 				  &type3.ntlm);
125*ebfedea0SLionel Sambuc 	free(key.data);
126*ebfedea0SLionel Sambuc     }
127*ebfedea0SLionel Sambuc 
128*ebfedea0SLionel Sambuc     ret = heim_ntlm_encode_type3(&type3, &data);
129*ebfedea0SLionel Sambuc     if (ret)
130*ebfedea0SLionel Sambuc 	errx(1, "heim_ntlm_encode_type3");
131*ebfedea0SLionel Sambuc 
132*ebfedea0SLionel Sambuc     free(type3.ntlm.data);
133*ebfedea0SLionel Sambuc 
134*ebfedea0SLionel Sambuc     memset(&type3, 0, sizeof(type3));
135*ebfedea0SLionel Sambuc 
136*ebfedea0SLionel Sambuc     ret = heim_ntlm_decode_type3(&data, 1, &type3);
137*ebfedea0SLionel Sambuc     free(data.data);
138*ebfedea0SLionel Sambuc     if (ret)
139*ebfedea0SLionel Sambuc 	errx(1, "heim_ntlm_decode_type3");
140*ebfedea0SLionel Sambuc 
141*ebfedea0SLionel Sambuc     if (strcmp("workstation", type3.ws) != 0)
142*ebfedea0SLionel Sambuc 	errx(1, "type3 ws wrong");
143*ebfedea0SLionel Sambuc 
144*ebfedea0SLionel Sambuc     if (strcmp(target, type3.targetname) != 0)
145*ebfedea0SLionel Sambuc 	errx(1, "type3 targetname wrong");
146*ebfedea0SLionel Sambuc 
147*ebfedea0SLionel Sambuc     if (strcmp(user, type3.username) != 0)
148*ebfedea0SLionel Sambuc 	errx(1, "type3 username wrong");
149*ebfedea0SLionel Sambuc 
150*ebfedea0SLionel Sambuc 
151*ebfedea0SLionel Sambuc     heim_ntlm_free_type3(&type3);
152*ebfedea0SLionel Sambuc 
153*ebfedea0SLionel Sambuc     /*
154*ebfedea0SLionel Sambuc      * NTLMv2
155*ebfedea0SLionel Sambuc      */
156*ebfedea0SLionel Sambuc 
157*ebfedea0SLionel Sambuc     memset(&type2, 0, sizeof(type2));
158*ebfedea0SLionel Sambuc 
159*ebfedea0SLionel Sambuc     flags = NTLM_NEG_UNICODE | NTLM_NEG_NTLM | NTLM_TARGET_DOMAIN;
160*ebfedea0SLionel Sambuc     type2.flags = flags;
161*ebfedea0SLionel Sambuc 
162*ebfedea0SLionel Sambuc     memset(type2.challenge, 0x7f, sizeof(type2.challenge));
163*ebfedea0SLionel Sambuc     type2.targetname = rk_UNCONST(target);
164*ebfedea0SLionel Sambuc     type2.targetinfo.data = "\x00\x00";
165*ebfedea0SLionel Sambuc     type2.targetinfo.length = 2;
166*ebfedea0SLionel Sambuc 
167*ebfedea0SLionel Sambuc     ret = heim_ntlm_encode_type2(&type2, &data);
168*ebfedea0SLionel Sambuc     if (ret)
169*ebfedea0SLionel Sambuc 	errx(1, "heim_ntlm_encode_type2");
170*ebfedea0SLionel Sambuc 
171*ebfedea0SLionel Sambuc     memset(&type2, 0, sizeof(type2));
172*ebfedea0SLionel Sambuc 
173*ebfedea0SLionel Sambuc     ret = heim_ntlm_decode_type2(&data, &type2);
174*ebfedea0SLionel Sambuc     free(data.data);
175*ebfedea0SLionel Sambuc     if (ret)
176*ebfedea0SLionel Sambuc 	errx(1, "heim_ntlm_decode_type2");
177*ebfedea0SLionel Sambuc 
178*ebfedea0SLionel Sambuc     heim_ntlm_free_type2(&type2);
179*ebfedea0SLionel Sambuc 
180*ebfedea0SLionel Sambuc     return 0;
181*ebfedea0SLionel Sambuc }
182*ebfedea0SLionel Sambuc 
183*ebfedea0SLionel Sambuc static int
test_keys(void)184*ebfedea0SLionel Sambuc test_keys(void)
185*ebfedea0SLionel Sambuc {
186*ebfedea0SLionel Sambuc     const char
187*ebfedea0SLionel Sambuc 	*username = "test",
188*ebfedea0SLionel Sambuc 	*password = "test1234",
189*ebfedea0SLionel Sambuc 	*target = "TESTNT";
190*ebfedea0SLionel Sambuc     const unsigned char
191*ebfedea0SLionel Sambuc 	serverchallenge[8] = "\x67\x7f\x1c\x55\x7a\x5e\xe9\x6c";
192*ebfedea0SLionel Sambuc     struct ntlm_buf infotarget, infotarget2, answer, key;
193*ebfedea0SLionel Sambuc     unsigned char ntlmv2[16], ntlmv2_1[16];
194*ebfedea0SLionel Sambuc     int ret;
195*ebfedea0SLionel Sambuc 
196*ebfedea0SLionel Sambuc     infotarget.length = 70;
197*ebfedea0SLionel Sambuc     infotarget.data =
198*ebfedea0SLionel Sambuc 	"\x02\x00\x0c\x00\x54\x00\x45\x00\x53\x00\x54\x00\x4e\x00\x54\x00"
199*ebfedea0SLionel Sambuc 	"\x01\x00\x0c\x00\x4d\x00\x45\x00\x4d\x00\x42\x00\x45\x00\x52\x00"
200*ebfedea0SLionel Sambuc 	"\x03\x00\x1e\x00\x6d\x00\x65\x00\x6d\x00\x62\x00\x65\x00\x72\x00"
201*ebfedea0SLionel Sambuc 	    "\x2e\x00\x74\x00\x65\x00\x73\x00\x74\x00\x2e\x00\x63\x00\x6f"
202*ebfedea0SLionel Sambuc 	    "\x00\x6d\x00"
203*ebfedea0SLionel Sambuc 	"\x00\x00\x00\x00";
204*ebfedea0SLionel Sambuc 
205*ebfedea0SLionel Sambuc     answer.length = 0;
206*ebfedea0SLionel Sambuc     answer.data = NULL;
207*ebfedea0SLionel Sambuc 
208*ebfedea0SLionel Sambuc     heim_ntlm_nt_key(password, &key);
209*ebfedea0SLionel Sambuc 
210*ebfedea0SLionel Sambuc     ret = heim_ntlm_calculate_ntlm2(key.data,
211*ebfedea0SLionel Sambuc 				    key.length,
212*ebfedea0SLionel Sambuc 				    username,
213*ebfedea0SLionel Sambuc 				    target,
214*ebfedea0SLionel Sambuc 				    serverchallenge,
215*ebfedea0SLionel Sambuc 				    &infotarget,
216*ebfedea0SLionel Sambuc 				    ntlmv2,
217*ebfedea0SLionel Sambuc 				    &answer);
218*ebfedea0SLionel Sambuc     if (ret)
219*ebfedea0SLionel Sambuc 	errx(1, "heim_ntlm_calculate_ntlm2");
220*ebfedea0SLionel Sambuc 
221*ebfedea0SLionel Sambuc     ret = heim_ntlm_verify_ntlm2(key.data,
222*ebfedea0SLionel Sambuc 				 key.length,
223*ebfedea0SLionel Sambuc 				 username,
224*ebfedea0SLionel Sambuc 				 target,
225*ebfedea0SLionel Sambuc 				 0,
226*ebfedea0SLionel Sambuc 				 serverchallenge,
227*ebfedea0SLionel Sambuc 				 &answer,
228*ebfedea0SLionel Sambuc 				 &infotarget2,
229*ebfedea0SLionel Sambuc 				 ntlmv2_1);
230*ebfedea0SLionel Sambuc     if (ret)
231*ebfedea0SLionel Sambuc 	errx(1, "heim_ntlm_verify_ntlm2");
232*ebfedea0SLionel Sambuc 
233*ebfedea0SLionel Sambuc     if (memcmp(ntlmv2, ntlmv2_1, sizeof(ntlmv2)) != 0)
234*ebfedea0SLionel Sambuc 	errx(1, "ntlm master key not same");
235*ebfedea0SLionel Sambuc 
236*ebfedea0SLionel Sambuc     if (infotarget.length > infotarget2.length)
237*ebfedea0SLionel Sambuc 	errx(1, "infotarget length");
238*ebfedea0SLionel Sambuc 
239*ebfedea0SLionel Sambuc     if (memcmp(infotarget.data, infotarget2.data, infotarget.length) != 0)
240*ebfedea0SLionel Sambuc 	errx(1, "infotarget not the same");
241*ebfedea0SLionel Sambuc 
242*ebfedea0SLionel Sambuc     free(key.data);
243*ebfedea0SLionel Sambuc     free(answer.data);
244*ebfedea0SLionel Sambuc     free(infotarget2.data);
245*ebfedea0SLionel Sambuc 
246*ebfedea0SLionel Sambuc     return 0;
247*ebfedea0SLionel Sambuc }
248*ebfedea0SLionel Sambuc 
249*ebfedea0SLionel Sambuc static int
test_ntlm2_session_resp(void)250*ebfedea0SLionel Sambuc test_ntlm2_session_resp(void)
251*ebfedea0SLionel Sambuc {
252*ebfedea0SLionel Sambuc     int ret;
253*ebfedea0SLionel Sambuc     struct ntlm_buf lm, ntlm;
254*ebfedea0SLionel Sambuc 
255*ebfedea0SLionel Sambuc     const unsigned char lm_resp[24] =
256*ebfedea0SLionel Sambuc 	"\xff\xff\xff\x00\x11\x22\x33\x44"
257*ebfedea0SLionel Sambuc 	"\x00\x00\x00\x00\x00\x00\x00\x00"
258*ebfedea0SLionel Sambuc 	"\x00\x00\x00\x00\x00\x00\x00\x00";
259*ebfedea0SLionel Sambuc     const unsigned char ntlm2_sess_resp[24] =
260*ebfedea0SLionel Sambuc 	"\x10\xd5\x50\x83\x2d\x12\xb2\xcc"
261*ebfedea0SLionel Sambuc 	"\xb7\x9d\x5a\xd1\xf4\xee\xd3\xdf"
262*ebfedea0SLionel Sambuc 	"\x82\xac\xa4\xc3\x68\x1d\xd4\x55";
263*ebfedea0SLionel Sambuc 
264*ebfedea0SLionel Sambuc     const unsigned char client_nonce[8] =
265*ebfedea0SLionel Sambuc 	"\xff\xff\xff\x00\x11\x22\x33\x44";
266*ebfedea0SLionel Sambuc     const unsigned char server_challenge[8] =
267*ebfedea0SLionel Sambuc 	"\x01\x23\x45\x67\x89\xab\xcd\xef";
268*ebfedea0SLionel Sambuc 
269*ebfedea0SLionel Sambuc     const unsigned char ntlm_hash[16] =
270*ebfedea0SLionel Sambuc 	"\xcd\x06\xca\x7c\x7e\x10\xc9\x9b"
271*ebfedea0SLionel Sambuc 	"\x1d\x33\xb7\x48\x5a\x2e\xd8\x08";
272*ebfedea0SLionel Sambuc 
273*ebfedea0SLionel Sambuc     ret = heim_ntlm_calculate_ntlm2_sess(client_nonce,
274*ebfedea0SLionel Sambuc 					 server_challenge,
275*ebfedea0SLionel Sambuc 					 ntlm_hash,
276*ebfedea0SLionel Sambuc 					 &lm,
277*ebfedea0SLionel Sambuc 					 &ntlm);
278*ebfedea0SLionel Sambuc     if (ret)
279*ebfedea0SLionel Sambuc 	errx(1, "heim_ntlm_calculate_ntlm2_sess_resp");
280*ebfedea0SLionel Sambuc 
281*ebfedea0SLionel Sambuc     if (lm.length != 24 || memcmp(lm.data, lm_resp, 24) != 0)
282*ebfedea0SLionel Sambuc 	errx(1, "lm_resp wrong");
283*ebfedea0SLionel Sambuc     if (ntlm.length != 24 || memcmp(ntlm.data, ntlm2_sess_resp, 24) != 0)
284*ebfedea0SLionel Sambuc 	errx(1, "ntlm2_sess_resp wrong");
285*ebfedea0SLionel Sambuc 
286*ebfedea0SLionel Sambuc     free(lm.data);
287*ebfedea0SLionel Sambuc     free(ntlm.data);
288*ebfedea0SLionel Sambuc 
289*ebfedea0SLionel Sambuc 
290*ebfedea0SLionel Sambuc     return 0;
291*ebfedea0SLionel Sambuc }
292*ebfedea0SLionel Sambuc 
293*ebfedea0SLionel Sambuc static int
test_targetinfo(void)294*ebfedea0SLionel Sambuc test_targetinfo(void)
295*ebfedea0SLionel Sambuc {
296*ebfedea0SLionel Sambuc     struct ntlm_targetinfo ti;
297*ebfedea0SLionel Sambuc     struct ntlm_buf buf;
298*ebfedea0SLionel Sambuc     const char *dnsservername = "dnsservername";
299*ebfedea0SLionel Sambuc     int ret;
300*ebfedea0SLionel Sambuc 
301*ebfedea0SLionel Sambuc     memset(&ti, 0, sizeof(ti));
302*ebfedea0SLionel Sambuc 
303*ebfedea0SLionel Sambuc     ti.dnsservername = rk_UNCONST(dnsservername);
304*ebfedea0SLionel Sambuc     ti.avflags = 1;
305*ebfedea0SLionel Sambuc     ret = heim_ntlm_encode_targetinfo(&ti, 1, &buf);
306*ebfedea0SLionel Sambuc     if (ret)
307*ebfedea0SLionel Sambuc 	return ret;
308*ebfedea0SLionel Sambuc 
309*ebfedea0SLionel Sambuc     memset(&ti, 0, sizeof(ti));
310*ebfedea0SLionel Sambuc 
311*ebfedea0SLionel Sambuc     ret = heim_ntlm_decode_targetinfo(&buf, 1, &ti);
312*ebfedea0SLionel Sambuc     if (ret)
313*ebfedea0SLionel Sambuc 	return ret;
314*ebfedea0SLionel Sambuc 
315*ebfedea0SLionel Sambuc     if (ti.dnsservername == NULL ||
316*ebfedea0SLionel Sambuc 	strcmp(ti.dnsservername, dnsservername) != 0)
317*ebfedea0SLionel Sambuc 	errx(1, "ti.dnshostname != %s", dnsservername);
318*ebfedea0SLionel Sambuc     if (ti.avflags != 1)
319*ebfedea0SLionel Sambuc 	errx(1, "ti.avflags != 1");
320*ebfedea0SLionel Sambuc 
321*ebfedea0SLionel Sambuc     heim_ntlm_free_targetinfo(&ti);
322*ebfedea0SLionel Sambuc 
323*ebfedea0SLionel Sambuc     return 0;
324*ebfedea0SLionel Sambuc }
325*ebfedea0SLionel Sambuc 
326*ebfedea0SLionel Sambuc static int verbose_flag = 0;
327*ebfedea0SLionel Sambuc static int version_flag = 0;
328*ebfedea0SLionel Sambuc static int help_flag	= 0;
329*ebfedea0SLionel Sambuc 
330*ebfedea0SLionel Sambuc static struct getargs args[] = {
331*ebfedea0SLionel Sambuc     {"verbose",	0,	arg_flag,	&verbose_flag, "verbose printing", NULL },
332*ebfedea0SLionel Sambuc     {"version",	0,	arg_flag,	&version_flag, "print version", NULL },
333*ebfedea0SLionel Sambuc     {"help",	0,	arg_flag,	&help_flag,  NULL, NULL }
334*ebfedea0SLionel Sambuc };
335*ebfedea0SLionel Sambuc 
336*ebfedea0SLionel Sambuc static void
usage(int ret)337*ebfedea0SLionel Sambuc usage (int ret)
338*ebfedea0SLionel Sambuc {
339*ebfedea0SLionel Sambuc     arg_printusage (args, sizeof(args)/sizeof(*args),
340*ebfedea0SLionel Sambuc 		    NULL, "");
341*ebfedea0SLionel Sambuc     exit (ret);
342*ebfedea0SLionel Sambuc }
343*ebfedea0SLionel Sambuc 
344*ebfedea0SLionel Sambuc int
main(int argc,char ** argv)345*ebfedea0SLionel Sambuc main(int argc, char **argv)
346*ebfedea0SLionel Sambuc {
347*ebfedea0SLionel Sambuc     int ret = 0, optind = 0;
348*ebfedea0SLionel Sambuc 
349*ebfedea0SLionel Sambuc     setprogname(argv[0]);
350*ebfedea0SLionel Sambuc 
351*ebfedea0SLionel Sambuc     if(getarg(args, sizeof(args) / sizeof(args[0]), argc, argv, &optind))
352*ebfedea0SLionel Sambuc 	usage(1);
353*ebfedea0SLionel Sambuc 
354*ebfedea0SLionel Sambuc     if (help_flag)
355*ebfedea0SLionel Sambuc 	usage (0);
356*ebfedea0SLionel Sambuc 
357*ebfedea0SLionel Sambuc     if(version_flag){
358*ebfedea0SLionel Sambuc 	print_version(NULL);
359*ebfedea0SLionel Sambuc 	exit(0);
360*ebfedea0SLionel Sambuc     }
361*ebfedea0SLionel Sambuc 
362*ebfedea0SLionel Sambuc     argc -= optind;
363*ebfedea0SLionel Sambuc     argv += optind;
364*ebfedea0SLionel Sambuc 
365*ebfedea0SLionel Sambuc     if (verbose_flag)
366*ebfedea0SLionel Sambuc 	printf("test_parse\n");
367*ebfedea0SLionel Sambuc 
368*ebfedea0SLionel Sambuc     ret += test_parse();
369*ebfedea0SLionel Sambuc     if (verbose_flag)
370*ebfedea0SLionel Sambuc 	printf("test_keys\n");
371*ebfedea0SLionel Sambuc 
372*ebfedea0SLionel Sambuc     ret += test_keys();
373*ebfedea0SLionel Sambuc     if (verbose_flag)
374*ebfedea0SLionel Sambuc 	printf("test_ntlm2_session_resp\n");
375*ebfedea0SLionel Sambuc     ret += test_ntlm2_session_resp();
376*ebfedea0SLionel Sambuc 
377*ebfedea0SLionel Sambuc     if (verbose_flag)
378*ebfedea0SLionel Sambuc 	printf("test_targetinfo\n");
379*ebfedea0SLionel Sambuc     ret += test_targetinfo();
380*ebfedea0SLionel Sambuc 
381*ebfedea0SLionel Sambuc     return ret;
382*ebfedea0SLionel Sambuc }
383