1 /* $NetBSD: process.c,v 1.1.1.2 2014/04/24 12:45:27 pettai Exp $ */
4 * Copyright (c) 1997-2005 Kungliga Tekniska Högskolan
5 * (Royal Institute of Technology, Stockholm, Sweden).
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
20 * 3. Neither the name of the Institute nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
44 krb5_kdc_update_time(struct timeval
*tv
)
47 gettimeofday(&_kdc_now
, NULL
);
52 static krb5_error_code
53 kdc_as_req(krb5_context context
,
54 krb5_kdc_configuration
*config
,
55 krb5_data
*req_buffer
,
58 struct sockaddr
*addr
,
66 ret
= decode_AS_REQ(req_buffer
->data
, req_buffer
->length
, &req
, &len
);
72 ret
= _kdc_as_rep(context
, config
, &req
, req_buffer
,
73 reply
, from
, addr
, datagram_reply
);
79 static krb5_error_code
80 kdc_tgs_req(krb5_context context
,
81 krb5_kdc_configuration
*config
,
82 krb5_data
*req_buffer
,
85 struct sockaddr
*addr
,
93 ret
= decode_TGS_REQ(req_buffer
->data
, req_buffer
->length
, &req
, &len
);
99 ret
= _kdc_tgs_rep(context
, config
, &req
, reply
,
100 from
, addr
, datagram_reply
);
107 static krb5_error_code
108 kdc_digest(krb5_context context
,
109 krb5_kdc_configuration
*config
,
110 krb5_data
*req_buffer
,
113 struct sockaddr
*addr
,
121 ret
= decode_DigestREQ(req_buffer
->data
, req_buffer
->length
,
128 ret
= _kdc_do_digest(context
, config
, &digestreq
, reply
, from
, addr
);
129 free_DigestREQ(&digestreq
);
137 static krb5_error_code
138 kdc_kx509(krb5_context context
,
139 krb5_kdc_configuration
*config
,
140 krb5_data
*req_buffer
,
143 struct sockaddr
*addr
,
147 Kx509Request kx509req
;
151 ret
= _kdc_try_kx509_request(req_buffer
->data
, req_buffer
->length
,
158 ret
= _kdc_do_kx509(context
, config
, &kx509req
, reply
, from
, addr
);
159 free_Kx509Request(&kx509req
);
166 static struct krb5_kdc_service services
[] = {
167 { KS_KRB5
, kdc_as_req
},
168 { KS_KRB5
, kdc_tgs_req
},
179 * handle the request in `buf, len', from `addr' (or `from' as a string),
180 * sending a reply in `reply'.
184 krb5_kdc_process_request(krb5_context context
,
185 krb5_kdc_configuration
*config
,
189 krb5_boolean
*prependlength
,
191 struct sockaddr
*addr
,
196 krb5_data req_buffer
;
199 req_buffer
.data
= buf
;
200 req_buffer
.length
= len
;
202 for (i
= 0; services
[i
].process
!= NULL
; i
++) {
203 ret
= (*services
[i
].process
)(context
, config
, &req_buffer
,
204 reply
, from
, addr
, datagram_reply
,
207 if (services
[i
].flags
& KS_NO_LENGTH
)
217 * handle the request in `buf, len', from `addr' (or `from' as a string),
218 * sending a reply in `reply'.
220 * This only processes krb5 requests
224 krb5_kdc_process_krb5_request(krb5_context context
,
225 krb5_kdc_configuration
*config
,
230 struct sockaddr
*addr
,
235 krb5_data req_buffer
;
238 req_buffer
.data
= buf
;
239 req_buffer
.length
= len
;
241 for (i
= 0; services
[i
].process
!= NULL
; i
++) {
242 if ((services
[i
].flags
& KS_KRB5
) == 0)
244 ret
= (*services
[i
].process
)(context
, config
, &req_buffer
,
245 reply
, from
, addr
, datagram_reply
,
259 krb5_kdc_save_request(krb5_context context
,
261 const unsigned char *buf
,
263 const krb5_data
*reply
,
264 const struct sockaddr
*sa
)
272 memset(&a
, 0, sizeof(a
));
274 d
.data
= rk_UNCONST(buf
);
278 fd
= open(fn
, O_WRONLY
|O_CREAT
|O_APPEND
, 0600);
280 int saved_errno
= errno
;
281 krb5_set_error_message(context
, saved_errno
, "Failed to open: %s", fn
);
285 sp
= krb5_storage_from_fd(fd
);
288 krb5_set_error_message(context
, ENOMEM
, "Storage failed to open fd");
292 ret
= krb5_sockaddr2address(context
, sa
, &a
);
296 krb5_store_uint32(sp
, 1);
297 krb5_store_uint32(sp
, t
);
298 krb5_store_address(sp
, a
);
299 krb5_store_data(sp
, d
);
304 ret
= der_get_tag (reply
->data
, reply
->length
,
305 &cl
, &ty
, &tag
, NULL
);
307 krb5_store_uint32(sp
, 0xffffffff);
308 krb5_store_uint32(sp
, 0xffffffff);
310 krb5_store_uint32(sp
, MAKE_TAG(cl
, ty
, 0));
311 krb5_store_uint32(sp
, tag
);
315 krb5_free_address(context
, &a
);
317 krb5_storage_free(sp
);