2 * Copyright (c) 2002 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of KTH nor the names of its contributors may be
18 * used to endorse or promote products derived from this software without
19 * specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY KTH AND ITS CONTRIBUTORS ``AS IS'' AND ANY
22 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KTH OR ITS CONTRIBUTORS BE
25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
28 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
33 #include "krb5_locl.h"
35 RCSID("$Id: name-45-test.c,v 1.2 2002/08/31 03:33:07 assar Exp $");
37 enum { MAX_COMPONENTS = 3 };
39 static struct testcase {
46 char *comp_val[MAX_COMPONENTS];
48 const char *config_file;
49 krb5_error_code ret; /* expected error code from 524 */
51 krb5_error_code ret2; /* expected error code from 425 */
53 {"", "", "", "", 1, {""}, NULL, 0, 0},
54 {"a", "", "", "", 1, {"a"}, NULL, 0, 0},
55 {"a", "b", "", "", 2, {"a", "b"}, NULL, 0, 0},
56 {"a", "b", "c", "c", 2, {"a", "b"}, NULL, 0, 0},
58 {"krbtgt", "FOO.SE", "FOO.SE", "FOO.SE", 2,
59 {"krbtgt", "FOO.SE"}, NULL, 0, 0},
61 {"foo", "bar", "BAZ", "BAZ", 2,
62 {"foo", "bar"}, NULL, 0, 0},
63 {"foo", "bar", "BAZ", "BAZ", 2,
66 " v4_name_convert = {\n"
71 HEIM_ERR_V4_PRINC_NO_CONV, 0},
72 {"foo", "bar", "BAZ", "BAZ", 2,
76 " v4_name_convert = {\n"
81 " v4_instance_convert = {\n"
87 {"rcmd", "foo", "realm", "realm", 2, {"host", "foo"}, NULL,
88 HEIM_ERR_V4_PRINC_NO_CONV, 0},
89 {"rcmd", "foo", "realm", "realm", 2, {"host", "foo.realm"},
92 " v4_instance_convert = {\n"
98 {"pop", "mail0", "NADA.KTH.SE", "NADA.KTH.SE", 2,
99 {"pop", "mail0.nada.kth.se"}, NULL, HEIM_ERR_V4_PRINC_NO_CONV, 0},
100 {"pop", "mail0", "NADA.KTH.SE", "NADA.KTH.SE", 2,
101 {"pop", "mail0.nada.kth.se"},
104 " default_domain = nada.kth.se\n"
107 {"pop", "mail0", "NADA.KTH.SE", "NADA.KTH.SE", 2,
108 {"pop", "mail0.nada.kth.se"},
110 " v4_instance_resolve = true\n",
111 HEIM_ERR_V4_PRINC_NO_CONV, 0},
113 {"rcmd", "ratatosk", "NADA.KTH.SE", "NADA.KTH.SE", 2,
114 {"host", "ratatosk.pdc.kth.se"}, NULL, HEIM_ERR_V4_PRINC_NO_CONV, 0},
115 {"rcmd", "ratatosk", "NADA.KTH.SE", "NADA.KTH.SE", 2,
116 {"host", "ratatosk.pdc.kth.se"},
118 " v4_instance_resolve = true\n"
121 " v4_name_convert = {\n"
126 " default_domain = pdc.kth.se\n"
130 {"0123456789012345678901234567890123456789",
131 "0123456789012345678901234567890123456789",
132 "0123456789012345678901234567890123456789",
133 "0123456789012345678901234567890123456789",
134 2, {"0123456789012345678901234567890123456789",
135 "0123456789012345678901234567890123456789"}, NULL,
136 0, KRB5_PARSE_MALFORMED},
138 {"012345678901234567890123456789012345678",
139 "012345678901234567890123456789012345678",
140 "012345678901234567890123456789012345678",
141 "012345678901234567890123456789012345678",
142 2, {"012345678901234567890123456789012345678",
143 "012345678901234567890123456789012345678"}, NULL,
146 {NULL, NULL, NULL, NULL, 0, {}, NULL, 0}
150 main(int argc, char **argv)
153 krb5_context context;
157 for (t = tests; t->v4_name; ++t) {
158 krb5_principal princ;
160 char name[40], inst[40], realm[40];
161 char printable_princ[256];
163 ret = krb5_init_context (&context);
165 errx (1, "krb5_init_context failed: %d", ret);
167 if (t->config_file != NULL) {
168 char template[] = "/tmp/krb5-conf-XXXXXX";
169 int fd = mkstemp(template);
173 krb5_err (context, 1, errno, "mkstemp %s", template);
175 if (write (fd, t->config_file, strlen(t->config_file))
176 != strlen(t->config_file))
177 krb5_err (context, 1, errno, "write %s", template);
182 ret = krb5_set_config_files (context, files);
185 krb5_err (context, 1, ret, "krb5_set_config_files");
188 ret = krb5_425_conv_principal (context,
195 krb5_warn (context, ret,
196 "krb5_425_conv_principal %s.%s@%s",
197 t->v4_name, t->v4_inst, t->v4_realm);
203 "krb5_425_conv_principal %s.%s@%s "
205 t->v4_name, t->v4_inst, t->v4_realm);
214 if (strcmp (t->v5_realm, princ->realm) != 0) {
215 printf ("wrong realm (\"%s\" should be \"%s\")"
216 " for \"%s.%s@%s\"\n",
217 princ->realm, t->v5_realm,
224 if (t->ncomponents != princ->name.name_string.len) {
225 printf ("wrong number of components (%u should be %u)"
226 " for \"%s.%s@%s\"\n",
227 princ->name.name_string.len, t->ncomponents,
233 for (i = 0; i < t->ncomponents; ++i) {
234 if (strcmp(t->comp_val[i],
235 princ->name.name_string.val[i]) != 0) {
236 printf ("bad component %d (\"%s\" should be \"%s\")"
237 " for \"%s.%s@%s\"\n",
239 princ->name.name_string.val[i],
248 ret = krb5_524_conv_principal (context, princ,
250 if (krb5_unparse_name_fixed(context, princ,
251 printable_princ, sizeof(printable_princ)))
252 strlcpy(printable_princ, "unknown principal",
253 sizeof(printable_princ));
255 if (ret != t->ret2) {
256 krb5_warn (context, ret,
257 "krb5_524_conv_principal %s", printable_princ);
263 "krb5_524_conv_principal %s "
264 "passed unexpected", printable_princ);
270 krb5_free_principal (context, princ);
274 krb5_free_principal (context, princ);