2 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
9 * Copyright 1990 by the Massachusetts Institute of Technology.
11 * Export of this software from the United States of America may
12 * require a specific license from the United States Government.
13 * It is the responsibility of any person or organization contemplating
14 * export to obtain such a license before exporting.
16 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
17 * distribute this software and its documentation for any purpose and
18 * without fee is hereby granted, provided that the above copyright
19 * notice appear in all copies and that both that copyright notice and
20 * this permission notice appear in supporting documentation, and that
21 * the name of M.I.T. not be used in advertising or publicity pertaining
22 * to distribution of the software without specific, written prior
23 * permission. Furthermore if you modify this software you must label
24 * your software as modified software and not distribute it in such a
25 * fashion that it might be confused with the original M.I.T. software.
26 * M.I.T. makes no representations about the suitability of
27 * this software for any purpose. It is provided "as is" without express
28 * or implied warranty.
31 * Dispatch an incoming packet.
39 #include "adm_proto.h"
40 #include <netinet/in.h>
41 #include <arpa/inet.h>
44 static krb5_int32 last_usec
= 0, last_os_random
= 0;
47 dispatch(krb5_data
*pkt
, const krb5_fulladdr
*from
, krb5_data
**response
)
50 krb5_error_code retval
;
52 krb5_int32 now
, now_usec
;
54 /* decode incoming packet, and dispatch */
57 /* try the replay lookaside buffer */
58 if (kdc_check_lookaside(pkt
, response
)) {
63 name
= (char *) inet_ntop (ADDRTYPE2FAMILY (from
->address
->addrtype
),
64 from
->address
->contents
, buf
, sizeof (buf
));
66 name
= "[unknown address type]";
67 krb5_klog_syslog(LOG_INFO
,
68 "DISPATCH: repeated (retransmitted?) request from %s, resending previous response",
73 /* SUNW14resync XXX */
75 retval
= krb5_crypto_us_timeofday(&now
, &now_usec
);
77 krb5_int32 usec_difference
= now_usec
-last_usec
;
79 if(last_os_random
== 0)
81 /* Grab random data from OS every hour*/
82 if(now
-last_os_random
>= 60*60) {
83 krb5_c_random_os_entropy(kdc_context
, 0, NULL
);
87 data
.length
= sizeof(krb5_int32
);
88 data
.data
= (void *) &usec_difference
;
90 krb5_c_random_add_entropy(kdc_context
,
91 KRB5_C_RANDSOURCE_TIMING
, &data
);
95 /* try TGS_REQ first; they are more common! */
97 if (krb5_is_tgs_req(pkt
)) {
98 retval
= process_tgs_req(pkt
, from
, response
);
99 } else if (krb5_is_as_req(pkt
)) {
100 if (!(retval
= decode_krb5_as_req(pkt
, &as_req
))) {
102 * setup_server_realm() sets up the global realm-specific data
105 if (!(retval
= setup_server_realm(as_req
->server
))) {
106 retval
= process_as_req(as_req
, pkt
, from
, response
);
108 krb5_free_kdc_req(kdc_context
, as_req
);
111 #ifdef KRB5_KRB4_COMPAT
112 else if (pkt
->data
[0] == 4) /* old version */
113 retval
= process_v4(pkt
, from
, response
);
116 retval
= KRB5KRB_AP_ERR_MSG_TYPE
;
118 /* put the response into the lookaside buffer */
120 kdc_insert_lookaside(pkt
, *response
);