2 * Copyright (c) 2007 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 the Institute nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 static int version_flag
;
39 struct getargs args
[] = {
40 { "version", 0, arg_flag
, &version_flag
},
41 { "help", 'h', arg_flag
, &help_flag
}
44 const static int num_args
= sizeof(args
) / sizeof(args
[0]);
49 arg_printusage (args
, num_args
, NULL
, "kdc-request-log-file");
54 main(int argc
, char **argv
)
58 krb5_kdc_configuration
*config
;
64 if(getarg(args
, num_args
, argc
, argv
, &optidx
))
75 ret
= krb5_init_context(&context
);
77 errx (1, "krb5_init_context failed to parse configuration file");
79 ret
= krb5_kdc_get_config(context
, &config
);
81 krb5_err(context
, 1, ret
, "krb5_kdc_default_config");
83 kdc_openlog(context
, "kdc-replay", config
);
85 ret
= krb5_kdc_set_dbinfo(context
, config
);
87 krb5_err(context
, 1, ret
, "krb5_kdc_set_dbinfo");
89 if (config
->enable_pkinit
) {
90 if (config
->pkinit_kdc_identity
== NULL
)
91 krb5_errx(context
, 1, "pkinit enabled but no identity");
93 if (config
->pkinit_kdc_anchors
== NULL
)
94 krb5_errx(context
, 1, "pkinit enabled but no X509 anchors");
96 krb5_kdc_pk_initialize(context
, config
,
97 config
->pkinit_kdc_identity
,
98 config
->pkinit_kdc_anchors
,
99 config
->pkinit_kdc_cert_pool
,
100 config
->pkinit_kdc_revoke
);
105 errx(1, "argc != 2");
107 printf("kdc replay\n");
109 fd
= open(argv
[1], O_RDONLY
);
111 err(1, "open: %s", argv
[1]);
113 sp
= krb5_storage_from_fd(fd
);
115 krb5_errx(context
, 1, "krb5_storage_from_fd");
118 struct sockaddr_storage sa
;
119 krb5_socklen_t salen
= sizeof(sa
);
123 uint32_t t
, clty
, tag
;
126 ret
= krb5_ret_uint32(sp
, &t
);
127 if (ret
== HEIM_ERR_EOF
)
130 krb5_errx(context
, 1, "krb5_ret_uint32(version)");
132 krb5_errx(context
, 1, "version not 1");
133 ret
= krb5_ret_uint32(sp
, &t
);
135 krb5_errx(context
, 1, "krb5_ret_uint32(time)");
136 ret
= krb5_ret_address(sp
, &a
);
138 krb5_errx(context
, 1, "krb5_ret_address");
139 ret
= krb5_ret_data(sp
, &d
);
141 krb5_errx(context
, 1, "krb5_ret_data");
142 ret
= krb5_ret_uint32(sp
, &clty
);
144 krb5_errx(context
, 1, "krb5_ret_uint32(class|type)");
145 ret
= krb5_ret_uint32(sp
, &tag
);
147 krb5_errx(context
, 1, "krb5_ret_uint32(tag)");
150 ret
= krb5_addr2sockaddr (context
, &a
, (struct sockaddr
*)&sa
,
152 if (ret
== KRB5_PROG_ATYPE_NOSUPP
)
155 krb5_err(context
, 1, ret
, "krb5_addr2sockaddr");
157 ret
= krb5_print_address(&a
, astr
, sizeof(astr
), NULL
);
159 krb5_err(context
, 1, ret
, "krb5_print_address");
161 printf("processing request from %s, %lu bytes\n",
162 astr
, (unsigned long)d
.length
);
170 krb5_kdc_update_time(&tv
);
171 krb5_set_real_time(context
, tv
.tv_sec
, 0);
173 ret
= krb5_kdc_process_request(context
, config
, d
.data
, d
.length
,
175 (struct sockaddr
*)&sa
, 0);
177 krb5_err(context
, 1, ret
, "krb5_kdc_process_request");
183 ret
= der_get_tag (r
.data
, r
.length
,
184 &cl
, &ty
, &tag2
, NULL
);
185 if (MAKE_TAG(cl
, ty
, 0) != clty
)
186 krb5_errx(context
, 1, "class|type mismatch: %d != %d",
187 (int)MAKE_TAG(cl
, ty
, 0), (int)clty
);
189 krb5_errx(context
, 1, "tag mismatch");
193 if (clty
!= 0xffffffff)
194 krb5_errx(context
, 1, "clty not invalid");
195 if (tag
!= 0xffffffff)
196 krb5_errx(context
, 1, "tag not invalid");
201 krb5_free_address(context
, &a
);
204 krb5_storage_free(sp
);
205 krb5_free_context(context
);