1*ebfedea0SLionel Sambuc /*	$NetBSD: test_princ.c,v 1.1.1.1 2011/04/13 18:15:38 elric Exp $	*/
2*ebfedea0SLionel Sambuc 
3*ebfedea0SLionel Sambuc /*
4*ebfedea0SLionel Sambuc  * Copyright (c) 2003 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 #include "krb5_locl.h"
36*ebfedea0SLionel Sambuc #include <err.h>
37*ebfedea0SLionel Sambuc 
38*ebfedea0SLionel Sambuc /*
39*ebfedea0SLionel Sambuc  * Check that a closed cc still keeps it data and that it's no longer
40*ebfedea0SLionel Sambuc  * there when it's destroyed.
41*ebfedea0SLionel Sambuc  */
42*ebfedea0SLionel Sambuc 
43*ebfedea0SLionel Sambuc static void
test_princ(krb5_context context)44*ebfedea0SLionel Sambuc test_princ(krb5_context context)
45*ebfedea0SLionel Sambuc {
46*ebfedea0SLionel Sambuc     const char *princ = "lha@SU.SE";
47*ebfedea0SLionel Sambuc     const char *princ_short = "lha";
48*ebfedea0SLionel Sambuc     const char *noquote;
49*ebfedea0SLionel Sambuc     krb5_error_code ret;
50*ebfedea0SLionel Sambuc     char *princ_unparsed;
51*ebfedea0SLionel Sambuc     char *princ_reformed = NULL;
52*ebfedea0SLionel Sambuc     const char *realm;
53*ebfedea0SLionel Sambuc 
54*ebfedea0SLionel Sambuc     krb5_principal p, p2;
55*ebfedea0SLionel Sambuc 
56*ebfedea0SLionel Sambuc     ret = krb5_parse_name(context, princ, &p);
57*ebfedea0SLionel Sambuc     if (ret)
58*ebfedea0SLionel Sambuc 	krb5_err(context, 1, ret, "krb5_parse_name");
59*ebfedea0SLionel Sambuc 
60*ebfedea0SLionel Sambuc     ret = krb5_unparse_name(context, p, &princ_unparsed);
61*ebfedea0SLionel Sambuc     if (ret)
62*ebfedea0SLionel Sambuc 	krb5_err(context, 1, ret, "krb5_parse_name");
63*ebfedea0SLionel Sambuc 
64*ebfedea0SLionel Sambuc     if (strcmp(princ, princ_unparsed)) {
65*ebfedea0SLionel Sambuc 	krb5_errx(context, 1, "%s != %s", princ, princ_unparsed);
66*ebfedea0SLionel Sambuc     }
67*ebfedea0SLionel Sambuc 
68*ebfedea0SLionel Sambuc     free(princ_unparsed);
69*ebfedea0SLionel Sambuc 
70*ebfedea0SLionel Sambuc     ret = krb5_unparse_name_flags(context, p,
71*ebfedea0SLionel Sambuc 				  KRB5_PRINCIPAL_UNPARSE_NO_REALM,
72*ebfedea0SLionel Sambuc 				  &princ_unparsed);
73*ebfedea0SLionel Sambuc     if (ret)
74*ebfedea0SLionel Sambuc 	krb5_err(context, 1, ret, "krb5_parse_name");
75*ebfedea0SLionel Sambuc 
76*ebfedea0SLionel Sambuc     if (strcmp(princ_short, princ_unparsed))
77*ebfedea0SLionel Sambuc 	krb5_errx(context, 1, "%s != %s", princ_short, princ_unparsed);
78*ebfedea0SLionel Sambuc     free(princ_unparsed);
79*ebfedea0SLionel Sambuc 
80*ebfedea0SLionel Sambuc     realm = krb5_principal_get_realm(context, p);
81*ebfedea0SLionel Sambuc 
82*ebfedea0SLionel Sambuc     if (asprintf(&princ_reformed, "%s@%s", princ_short, realm) < 0 || princ_reformed == NULL)
83*ebfedea0SLionel Sambuc 	errx(1, "malloc");
84*ebfedea0SLionel Sambuc 
85*ebfedea0SLionel Sambuc     ret = krb5_parse_name(context, princ_reformed, &p2);
86*ebfedea0SLionel Sambuc     free(princ_reformed);
87*ebfedea0SLionel Sambuc     if (ret)
88*ebfedea0SLionel Sambuc 	krb5_err(context, 1, ret, "krb5_parse_name");
89*ebfedea0SLionel Sambuc 
90*ebfedea0SLionel Sambuc     if (!krb5_principal_compare(context, p, p2)) {
91*ebfedea0SLionel Sambuc 	krb5_errx(context, 1, "p != p2");
92*ebfedea0SLionel Sambuc     }
93*ebfedea0SLionel Sambuc 
94*ebfedea0SLionel Sambuc     krb5_free_principal(context, p2);
95*ebfedea0SLionel Sambuc 
96*ebfedea0SLionel Sambuc     ret = krb5_set_default_realm(context, "SU.SE");
97*ebfedea0SLionel Sambuc     if (ret)
98*ebfedea0SLionel Sambuc 	krb5_err(context, 1, ret, "krb5_parse_name");
99*ebfedea0SLionel Sambuc 
100*ebfedea0SLionel Sambuc     ret = krb5_unparse_name_flags(context, p,
101*ebfedea0SLionel Sambuc 				  KRB5_PRINCIPAL_UNPARSE_SHORT,
102*ebfedea0SLionel Sambuc 				  &princ_unparsed);
103*ebfedea0SLionel Sambuc     if (ret)
104*ebfedea0SLionel Sambuc 	krb5_err(context, 1, ret, "krb5_parse_name");
105*ebfedea0SLionel Sambuc 
106*ebfedea0SLionel Sambuc     if (strcmp(princ_short, princ_unparsed))
107*ebfedea0SLionel Sambuc 	krb5_errx(context, 1, "'%s' != '%s'", princ_short, princ_unparsed);
108*ebfedea0SLionel Sambuc     free(princ_unparsed);
109*ebfedea0SLionel Sambuc 
110*ebfedea0SLionel Sambuc     ret = krb5_parse_name(context, princ_short, &p2);
111*ebfedea0SLionel Sambuc     if (ret)
112*ebfedea0SLionel Sambuc 	krb5_err(context, 1, ret, "krb5_parse_name");
113*ebfedea0SLionel Sambuc 
114*ebfedea0SLionel Sambuc     if (!krb5_principal_compare(context, p, p2))
115*ebfedea0SLionel Sambuc 	krb5_errx(context, 1, "p != p2");
116*ebfedea0SLionel Sambuc     krb5_free_principal(context, p2);
117*ebfedea0SLionel Sambuc 
118*ebfedea0SLionel Sambuc     ret = krb5_unparse_name(context, p, &princ_unparsed);
119*ebfedea0SLionel Sambuc     if (ret)
120*ebfedea0SLionel Sambuc 	krb5_err(context, 1, ret, "krb5_parse_name");
121*ebfedea0SLionel Sambuc 
122*ebfedea0SLionel Sambuc     if (strcmp(princ, princ_unparsed))
123*ebfedea0SLionel Sambuc 	krb5_errx(context, 1, "'%s' != '%s'", princ, princ_unparsed);
124*ebfedea0SLionel Sambuc     free(princ_unparsed);
125*ebfedea0SLionel Sambuc 
126*ebfedea0SLionel Sambuc     ret = krb5_set_default_realm(context, "SAMBA.ORG");
127*ebfedea0SLionel Sambuc     if (ret)
128*ebfedea0SLionel Sambuc 	krb5_err(context, 1, ret, "krb5_parse_name");
129*ebfedea0SLionel Sambuc 
130*ebfedea0SLionel Sambuc     ret = krb5_parse_name(context, princ_short, &p2);
131*ebfedea0SLionel Sambuc     if (ret)
132*ebfedea0SLionel Sambuc 	krb5_err(context, 1, ret, "krb5_parse_name");
133*ebfedea0SLionel Sambuc 
134*ebfedea0SLionel Sambuc     if (krb5_principal_compare(context, p, p2))
135*ebfedea0SLionel Sambuc 	krb5_errx(context, 1, "p == p2");
136*ebfedea0SLionel Sambuc 
137*ebfedea0SLionel Sambuc     if (!krb5_principal_compare_any_realm(context, p, p2))
138*ebfedea0SLionel Sambuc 	krb5_errx(context, 1, "(ignoring realms) p != p2");
139*ebfedea0SLionel Sambuc 
140*ebfedea0SLionel Sambuc     ret = krb5_unparse_name(context, p2, &princ_unparsed);
141*ebfedea0SLionel Sambuc     if (ret)
142*ebfedea0SLionel Sambuc 	krb5_err(context, 1, ret, "krb5_parse_name");
143*ebfedea0SLionel Sambuc 
144*ebfedea0SLionel Sambuc     if (strcmp(princ, princ_unparsed) == 0)
145*ebfedea0SLionel Sambuc 	krb5_errx(context, 1, "%s == %s", princ, princ_unparsed);
146*ebfedea0SLionel Sambuc     free(princ_unparsed);
147*ebfedea0SLionel Sambuc 
148*ebfedea0SLionel Sambuc     krb5_free_principal(context, p2);
149*ebfedea0SLionel Sambuc 
150*ebfedea0SLionel Sambuc     ret = krb5_parse_name(context, princ, &p2);
151*ebfedea0SLionel Sambuc     if (ret)
152*ebfedea0SLionel Sambuc 	krb5_err(context, 1, ret, "krb5_parse_name");
153*ebfedea0SLionel Sambuc 
154*ebfedea0SLionel Sambuc     if (!krb5_principal_compare(context, p, p2))
155*ebfedea0SLionel Sambuc 	krb5_errx(context, 1, "p != p2");
156*ebfedea0SLionel Sambuc 
157*ebfedea0SLionel Sambuc     ret = krb5_unparse_name(context, p2, &princ_unparsed);
158*ebfedea0SLionel Sambuc     if (ret)
159*ebfedea0SLionel Sambuc 	krb5_err(context, 1, ret, "krb5_parse_name");
160*ebfedea0SLionel Sambuc 
161*ebfedea0SLionel Sambuc     if (strcmp(princ, princ_unparsed))
162*ebfedea0SLionel Sambuc 	krb5_errx(context, 1, "'%s' != '%s'", princ, princ_unparsed);
163*ebfedea0SLionel Sambuc     free(princ_unparsed);
164*ebfedea0SLionel Sambuc 
165*ebfedea0SLionel Sambuc     krb5_free_principal(context, p2);
166*ebfedea0SLionel Sambuc 
167*ebfedea0SLionel Sambuc     ret = krb5_unparse_name_flags(context, p,
168*ebfedea0SLionel Sambuc 				  KRB5_PRINCIPAL_UNPARSE_SHORT,
169*ebfedea0SLionel Sambuc 				  &princ_unparsed);
170*ebfedea0SLionel Sambuc     if (ret)
171*ebfedea0SLionel Sambuc 	krb5_err(context, 1, ret, "krb5_unparse_name_short");
172*ebfedea0SLionel Sambuc 
173*ebfedea0SLionel Sambuc     if (strcmp(princ, princ_unparsed) != 0)
174*ebfedea0SLionel Sambuc 	krb5_errx(context, 1, "'%s' != '%s'", princ, princ_unparsed);
175*ebfedea0SLionel Sambuc     free(princ_unparsed);
176*ebfedea0SLionel Sambuc 
177*ebfedea0SLionel Sambuc     ret = krb5_unparse_name(context, p, &princ_unparsed);
178*ebfedea0SLionel Sambuc     if (ret)
179*ebfedea0SLionel Sambuc 	krb5_err(context, 1, ret, "krb5_unparse_name_short");
180*ebfedea0SLionel Sambuc 
181*ebfedea0SLionel Sambuc     if (strcmp(princ, princ_unparsed))
182*ebfedea0SLionel Sambuc 	krb5_errx(context, 1, "'%s' != '%s'", princ, princ_unparsed);
183*ebfedea0SLionel Sambuc     free(princ_unparsed);
184*ebfedea0SLionel Sambuc 
185*ebfedea0SLionel Sambuc     ret = krb5_parse_name_flags(context, princ,
186*ebfedea0SLionel Sambuc 				KRB5_PRINCIPAL_PARSE_NO_REALM,
187*ebfedea0SLionel Sambuc 				&p2);
188*ebfedea0SLionel Sambuc     if (!ret)
189*ebfedea0SLionel Sambuc 	krb5_err(context, 1, ret, "Should have failed to parse %s a "
190*ebfedea0SLionel Sambuc 		 "short name", princ);
191*ebfedea0SLionel Sambuc 
192*ebfedea0SLionel Sambuc     ret = krb5_parse_name_flags(context, princ_short,
193*ebfedea0SLionel Sambuc 				KRB5_PRINCIPAL_PARSE_NO_REALM,
194*ebfedea0SLionel Sambuc 				&p2);
195*ebfedea0SLionel Sambuc     if (ret)
196*ebfedea0SLionel Sambuc 	krb5_err(context, 1, ret, "krb5_parse_name");
197*ebfedea0SLionel Sambuc 
198*ebfedea0SLionel Sambuc     ret = krb5_unparse_name_flags(context, p2,
199*ebfedea0SLionel Sambuc 				  KRB5_PRINCIPAL_UNPARSE_NO_REALM,
200*ebfedea0SLionel Sambuc 				  &princ_unparsed);
201*ebfedea0SLionel Sambuc     krb5_free_principal(context, p2);
202*ebfedea0SLionel Sambuc     if (ret)
203*ebfedea0SLionel Sambuc 	krb5_err(context, 1, ret, "krb5_unparse_name_norealm");
204*ebfedea0SLionel Sambuc 
205*ebfedea0SLionel Sambuc     if (strcmp(princ_short, princ_unparsed))
206*ebfedea0SLionel Sambuc 	krb5_errx(context, 1, "'%s' != '%s'", princ_short, princ_unparsed);
207*ebfedea0SLionel Sambuc     free(princ_unparsed);
208*ebfedea0SLionel Sambuc 
209*ebfedea0SLionel Sambuc     ret = krb5_parse_name_flags(context, princ_short,
210*ebfedea0SLionel Sambuc 				KRB5_PRINCIPAL_PARSE_REQUIRE_REALM,
211*ebfedea0SLionel Sambuc 				&p2);
212*ebfedea0SLionel Sambuc     if (!ret)
213*ebfedea0SLionel Sambuc 	krb5_err(context, 1, ret, "Should have failed to parse %s "
214*ebfedea0SLionel Sambuc 		 "because it lacked a realm", princ_short);
215*ebfedea0SLionel Sambuc 
216*ebfedea0SLionel Sambuc     ret = krb5_parse_name_flags(context, princ,
217*ebfedea0SLionel Sambuc 				KRB5_PRINCIPAL_PARSE_REQUIRE_REALM,
218*ebfedea0SLionel Sambuc 				&p2);
219*ebfedea0SLionel Sambuc     if (ret)
220*ebfedea0SLionel Sambuc 	krb5_err(context, 1, ret, "krb5_parse_name");
221*ebfedea0SLionel Sambuc 
222*ebfedea0SLionel Sambuc     if (!krb5_principal_compare(context, p, p2))
223*ebfedea0SLionel Sambuc 	krb5_errx(context, 1, "p != p2");
224*ebfedea0SLionel Sambuc 
225*ebfedea0SLionel Sambuc     ret = krb5_unparse_name_flags(context, p2,
226*ebfedea0SLionel Sambuc 				  KRB5_PRINCIPAL_UNPARSE_NO_REALM,
227*ebfedea0SLionel Sambuc 				  &princ_unparsed);
228*ebfedea0SLionel Sambuc     krb5_free_principal(context, p2);
229*ebfedea0SLionel Sambuc     if (ret)
230*ebfedea0SLionel Sambuc 	krb5_err(context, 1, ret, "krb5_unparse_name_norealm");
231*ebfedea0SLionel Sambuc 
232*ebfedea0SLionel Sambuc     if (strcmp(princ_short, princ_unparsed))
233*ebfedea0SLionel Sambuc 	krb5_errx(context, 1, "'%s' != '%s'", princ_short, princ_unparsed);
234*ebfedea0SLionel Sambuc     free(princ_unparsed);
235*ebfedea0SLionel Sambuc 
236*ebfedea0SLionel Sambuc     krb5_free_principal(context, p);
237*ebfedea0SLionel Sambuc 
238*ebfedea0SLionel Sambuc     /* test quoting */
239*ebfedea0SLionel Sambuc 
240*ebfedea0SLionel Sambuc     princ = "test\\ principal@SU.SE";
241*ebfedea0SLionel Sambuc     noquote = "test principal@SU.SE";
242*ebfedea0SLionel Sambuc 
243*ebfedea0SLionel Sambuc     ret = krb5_parse_name_flags(context, princ, 0, &p);
244*ebfedea0SLionel Sambuc     if (ret)
245*ebfedea0SLionel Sambuc 	krb5_err(context, 1, ret, "krb5_parse_name");
246*ebfedea0SLionel Sambuc 
247*ebfedea0SLionel Sambuc     ret = krb5_unparse_name_flags(context, p, 0, &princ_unparsed);
248*ebfedea0SLionel Sambuc     if (ret)
249*ebfedea0SLionel Sambuc 	krb5_err(context, 1, ret, "krb5_unparse_name_flags");
250*ebfedea0SLionel Sambuc 
251*ebfedea0SLionel Sambuc     if (strcmp(princ, princ_unparsed))
252*ebfedea0SLionel Sambuc 	krb5_errx(context, 1, "q '%s' != '%s'", princ, princ_unparsed);
253*ebfedea0SLionel Sambuc     free(princ_unparsed);
254*ebfedea0SLionel Sambuc 
255*ebfedea0SLionel Sambuc     ret = krb5_unparse_name_flags(context, p, KRB5_PRINCIPAL_UNPARSE_DISPLAY,
256*ebfedea0SLionel Sambuc 				  &princ_unparsed);
257*ebfedea0SLionel Sambuc     if (ret)
258*ebfedea0SLionel Sambuc 	krb5_err(context, 1, ret, "krb5_unparse_name_flags");
259*ebfedea0SLionel Sambuc 
260*ebfedea0SLionel Sambuc     if (strcmp(noquote, princ_unparsed))
261*ebfedea0SLionel Sambuc 	krb5_errx(context, 1, "nq '%s' != '%s'", noquote, princ_unparsed);
262*ebfedea0SLionel Sambuc     free(princ_unparsed);
263*ebfedea0SLionel Sambuc 
264*ebfedea0SLionel Sambuc     krb5_free_principal(context, p);
265*ebfedea0SLionel Sambuc }
266*ebfedea0SLionel Sambuc 
267*ebfedea0SLionel Sambuc static void
test_enterprise(krb5_context context)268*ebfedea0SLionel Sambuc test_enterprise(krb5_context context)
269*ebfedea0SLionel Sambuc {
270*ebfedea0SLionel Sambuc     krb5_error_code ret;
271*ebfedea0SLionel Sambuc     char *unparsed;
272*ebfedea0SLionel Sambuc     krb5_principal p;
273*ebfedea0SLionel Sambuc 
274*ebfedea0SLionel Sambuc     ret = krb5_set_default_realm(context, "SAMBA.ORG");
275*ebfedea0SLionel Sambuc     if (ret)
276*ebfedea0SLionel Sambuc 	krb5_err(context, 1, ret, "krb5_parse_name");
277*ebfedea0SLionel Sambuc 
278*ebfedea0SLionel Sambuc     ret = krb5_parse_name_flags(context, "lha@su.se@WIN.SU.SE",
279*ebfedea0SLionel Sambuc 				KRB5_PRINCIPAL_PARSE_ENTERPRISE, &p);
280*ebfedea0SLionel Sambuc     if (ret)
281*ebfedea0SLionel Sambuc 	krb5_err(context, 1, ret, "krb5_parse_name_flags");
282*ebfedea0SLionel Sambuc 
283*ebfedea0SLionel Sambuc     ret = krb5_unparse_name(context, p, &unparsed);
284*ebfedea0SLionel Sambuc     if (ret)
285*ebfedea0SLionel Sambuc 	krb5_err(context, 1, ret, "krb5_unparse_name");
286*ebfedea0SLionel Sambuc 
287*ebfedea0SLionel Sambuc     krb5_free_principal(context, p);
288*ebfedea0SLionel Sambuc 
289*ebfedea0SLionel Sambuc     if (strcmp(unparsed, "lha\\@su.se@WIN.SU.SE") != 0)
290*ebfedea0SLionel Sambuc 	krb5_errx(context, 1, "enterprise name failed 1");
291*ebfedea0SLionel Sambuc     free(unparsed);
292*ebfedea0SLionel Sambuc 
293*ebfedea0SLionel Sambuc     /*
294*ebfedea0SLionel Sambuc      *
295*ebfedea0SLionel Sambuc      */
296*ebfedea0SLionel Sambuc 
297*ebfedea0SLionel Sambuc     ret = krb5_parse_name_flags(context, "lha\\@su.se@WIN.SU.SE",
298*ebfedea0SLionel Sambuc 				KRB5_PRINCIPAL_PARSE_ENTERPRISE, &p);
299*ebfedea0SLionel Sambuc     if (ret)
300*ebfedea0SLionel Sambuc 	krb5_err(context, 1, ret, "krb5_parse_name_flags");
301*ebfedea0SLionel Sambuc 
302*ebfedea0SLionel Sambuc     ret = krb5_unparse_name(context, p, &unparsed);
303*ebfedea0SLionel Sambuc     if (ret)
304*ebfedea0SLionel Sambuc 	krb5_err(context, 1, ret, "krb5_unparse_name");
305*ebfedea0SLionel Sambuc 
306*ebfedea0SLionel Sambuc     krb5_free_principal(context, p);
307*ebfedea0SLionel Sambuc     if (strcmp(unparsed, "lha\\@su.se\\@WIN.SU.SE@SAMBA.ORG") != 0)
308*ebfedea0SLionel Sambuc 	krb5_errx(context, 1, "enterprise name failed 2: %s", unparsed);
309*ebfedea0SLionel Sambuc     free(unparsed);
310*ebfedea0SLionel Sambuc 
311*ebfedea0SLionel Sambuc     /*
312*ebfedea0SLionel Sambuc      *
313*ebfedea0SLionel Sambuc      */
314*ebfedea0SLionel Sambuc 
315*ebfedea0SLionel Sambuc     ret = krb5_parse_name_flags(context, "lha\\@su.se@WIN.SU.SE", 0, &p);
316*ebfedea0SLionel Sambuc     if (ret)
317*ebfedea0SLionel Sambuc 	krb5_err(context, 1, ret, "krb5_parse_name_flags");
318*ebfedea0SLionel Sambuc 
319*ebfedea0SLionel Sambuc     ret = krb5_unparse_name(context, p, &unparsed);
320*ebfedea0SLionel Sambuc     if (ret)
321*ebfedea0SLionel Sambuc 	krb5_err(context, 1, ret, "krb5_unparse_name");
322*ebfedea0SLionel Sambuc 
323*ebfedea0SLionel Sambuc     krb5_free_principal(context, p);
324*ebfedea0SLionel Sambuc     if (strcmp(unparsed, "lha\\@su.se@WIN.SU.SE") != 0)
325*ebfedea0SLionel Sambuc 	krb5_errx(context, 1, "enterprise name failed 3");
326*ebfedea0SLionel Sambuc     free(unparsed);
327*ebfedea0SLionel Sambuc 
328*ebfedea0SLionel Sambuc     /*
329*ebfedea0SLionel Sambuc      *
330*ebfedea0SLionel Sambuc      */
331*ebfedea0SLionel Sambuc 
332*ebfedea0SLionel Sambuc     ret = krb5_parse_name_flags(context, "lha@su.se",
333*ebfedea0SLionel Sambuc 				KRB5_PRINCIPAL_PARSE_ENTERPRISE, &p);
334*ebfedea0SLionel Sambuc     if (ret)
335*ebfedea0SLionel Sambuc 	krb5_err(context, 1, ret, "krb5_parse_name_flags");
336*ebfedea0SLionel Sambuc 
337*ebfedea0SLionel Sambuc     ret = krb5_unparse_name(context, p, &unparsed);
338*ebfedea0SLionel Sambuc     if (ret)
339*ebfedea0SLionel Sambuc 	krb5_err(context, 1, ret, "krb5_unparse_name");
340*ebfedea0SLionel Sambuc 
341*ebfedea0SLionel Sambuc     krb5_free_principal(context, p);
342*ebfedea0SLionel Sambuc     if (strcmp(unparsed, "lha\\@su.se@SAMBA.ORG") != 0)
343*ebfedea0SLionel Sambuc 	krb5_errx(context, 1, "enterprise name failed 2: %s", unparsed);
344*ebfedea0SLionel Sambuc     free(unparsed);
345*ebfedea0SLionel Sambuc }
346*ebfedea0SLionel Sambuc 
347*ebfedea0SLionel Sambuc 
348*ebfedea0SLionel Sambuc int
main(int argc,char ** argv)349*ebfedea0SLionel Sambuc main(int argc, char **argv)
350*ebfedea0SLionel Sambuc {
351*ebfedea0SLionel Sambuc     krb5_context context;
352*ebfedea0SLionel Sambuc     krb5_error_code ret;
353*ebfedea0SLionel Sambuc 
354*ebfedea0SLionel Sambuc     setprogname(argv[0]);
355*ebfedea0SLionel Sambuc 
356*ebfedea0SLionel Sambuc     ret = krb5_init_context(&context);
357*ebfedea0SLionel Sambuc     if (ret)
358*ebfedea0SLionel Sambuc 	errx (1, "krb5_init_context failed: %d", ret);
359*ebfedea0SLionel Sambuc 
360*ebfedea0SLionel Sambuc     test_princ(context);
361*ebfedea0SLionel Sambuc 
362*ebfedea0SLionel Sambuc     test_enterprise(context);
363*ebfedea0SLionel Sambuc 
364*ebfedea0SLionel Sambuc     krb5_free_context(context);
365*ebfedea0SLionel Sambuc 
366*ebfedea0SLionel Sambuc     return 0;
367*ebfedea0SLionel Sambuc }
368