2 * Copyright (c) 1997-2005 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
6 * Portions Copyright (c) 2009 Apple Inc. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of the Institute nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 static krb5_kdc_configuration
*kdc_config
;
39 static krb5_context kdc_context
;
43 static struct sockaddr_storage sa
;
44 static krb5_socklen_t salen
= sizeof(sa
);
45 static const char *astr
= "0.0.0.0";
48 send_to_kdc(krb5_context context
)
52 ret
= krb5_kdc_process_request(kdc_context
, kdc_config
,
55 (struct sockaddr
*)&sa
, 0);
57 krb5_err(context
, 1, ret
, "krb5_kdc_process_request");
66 eval_kinit(heim_dict_t o
)
68 heim_string_t user
, password
;
69 krb5_init_creds_context ctx
;
70 krb5_principal client
;
73 user
= heim_dict_get_value(o
, HSTR("client"));
75 krb5_errx(kdc_context
, 1, "no client");
76 password
= heim_dict_get_value(o
, HSTR("password"));
78 krb5_errx(kdc_context
, 1, "no password");
80 ret
= krb5_parse_name(kdc_context
, heim_string_get_utf8(user
), &client
);
82 krb5_err(kdc_context
, 1, ret
, "krb5_unparse_name");
84 ret
= krb5_init_creds_init(kdc_context
, client
, NULL
, NULL
, 0, NULL
, &ctx
);
86 krb5_err(kdc_context
, 1, ret
, "krb5_init_creds_init");
88 ret
= krb5_init_creds_set_password(kdc_context
, ctx
,
89 heim_string_get_utf8(password
));
91 krb5_err(kdc_context
, 1, ret
, "krb5_init_creds_set_password");
94 ret
= krb5_init_creds_get(kdc_context
, ctx
);
96 krb5_err(kdc_context
, 1, ret
, "krb5_init_creds_get");
98 krb5_init_creds_free(kdc_context
, ctx
);
105 static void eval_object(heim_object_t
);
108 eval_array_element(heim_object_t o
, void *ptr
)
114 eval_object(heim_object_t o
)
116 heim_tid_t t
= heim_get_tid(o
);
118 if (t
== heim_array_get_type_id()) {
119 heim_array_iterate_f(o
, NULL
, eval_array_element
);
120 } else if (t
== heim_dict_get_type_id()) {
121 const char *op
= heim_dict_get_value(o
, HSTR("op"));
123 heim_assert(op
!= NULL
, "op missing");
125 printf("op: %s\n", op
);
127 if (strcmp(op
, "repeat") == 0) {
128 heim_object_t
or = heim_dict_get_value(o
, HSTR("value"));
129 heim_number_t n
= heim_dict_get_value(o
, HSTR("num"));
132 heim_assert(or != NULL
, "value missing");
133 heim_assert(n
!= NULL
, "num missing");
135 num
= heim_number_get_int(n
);
136 heim_assert(num
>= 0, "num >= 0");
138 printf("num %d\n", num
);
140 for (i
= 0; i
< num
; i
++)
143 } else if (strcmp(op
, "kinit") == 0) {
146 errx(1, "unsupported ops %s", op
);
150 errx(1, "unsupported");
155 main(int argc
, char **argv
)
160 setprogname(argv
[0]);
162 ret
= krb5_init_context(&kdc_context
);
163 if (ret
== KRB5_CONFIG_BADFORMAT
)
164 errx (1, "krb5_init_context failed to parse configuration file");
166 errx (1, "krb5_init_context failed: %d", ret
);
168 ret
= krb5_kt_register(kdc_context
, &hdb_kt_ops
);
170 errx (1, "krb5_kt_register(HDB) failed: %d", ret
);
172 kdc_config
= configure(kdc_context
, argc
, argv
, &optidx
);
178 errx(1, "missing operations");
185 if (rk_undumpdata(argv
[0], &buf
, &size
))
186 errx(1, "undumpdata: %s", argv
[0]);
188 o
= heim_json_create_with_bytes(buf
, size
, NULL
);
191 errx(1, "heim_json");
201 krb5_free_context(kdc_context
);