4 * Copyright 1990 by the Massachusetts Institute of Technology.
6 * Export of this software from the United States of America may
7 * require a specific license from the United States Government.
8 * It is the responsibility of any person or organization contemplating
9 * export to obtain such a license before exporting.
11 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
12 * distribute this software and its documentation for any purpose and
13 * without fee is hereby granted, provided that the above copyright
14 * notice appear in all copies and that both that copyright notice and
15 * this permission notice appear in supporting documentation, and that
16 * the name of M.I.T. not be used in advertising or publicity pertaining
17 * to distribution of the software without specific, written prior
18 * permission. Furthermore if you modify this software you must label
19 * your software as modified software and not distribute it in such a
20 * fashion that it might be confused with the original M.I.T. software.
21 * M.I.T. makes no representations about the suitability of
22 * this software for any purpose. It is provided "as is" without express
23 * or implied warranty.
26 * Dispatch an incoming packet.
33 #include "adm_proto.h"
34 #include <netinet/in.h>
35 #include <arpa/inet.h>
38 static krb5_int32 last_usec = 0, last_os_random = 0;
41 dispatch(krb5_data *pkt, const krb5_fulladdr *from, krb5_data **response)
44 krb5_error_code retval;
46 krb5_int32 now, now_usec;
48 /* decode incoming packet, and dispatch */
51 /* try the replay lookaside buffer */
52 if (kdc_check_lookaside(pkt, response)) {
57 name = inet_ntop (ADDRTYPE2FAMILY (from->address->addrtype),
58 from->address->contents, buf, sizeof (buf));
60 name = "[unknown address type]";
61 krb5_klog_syslog(LOG_INFO,
62 "DISPATCH: repeated (retransmitted?) request from %s, resending previous response",
67 retval = krb5_crypto_us_timeofday(&now, &now_usec);
69 krb5_int32 usec_difference = now_usec-last_usec;
71 if(last_os_random == 0)
73 /* Grab random data from OS every hour*/
74 if(now-last_os_random >= 60*60) {
75 krb5_c_random_os_entropy(kdc_context, 0, NULL);
79 data.length = sizeof(krb5_int32);
80 data.data = (void *) &usec_difference;
82 krb5_c_random_add_entropy(kdc_context,
83 KRB5_C_RANDSOURCE_TIMING, &data);
86 /* try TGS_REQ first; they are more common! */
88 if (krb5_is_tgs_req(pkt)) {
89 retval = process_tgs_req(pkt, from, response);
90 } else if (krb5_is_as_req(pkt)) {
91 if (!(retval = decode_krb5_as_req(pkt, &as_req))) {
93 * setup_server_realm() sets up the global realm-specific data
95 * process_as_req frees the request if it is called
97 if (!(retval = setup_server_realm(as_req->server))) {
98 retval = process_as_req(as_req, pkt, from, response);
100 else krb5_free_kdc_req(kdc_context, as_req);
104 retval = KRB5KRB_AP_ERR_MSG_TYPE;
106 /* put the response into the lookaside buffer */
107 if (!retval && *response != NULL)
108 kdc_insert_lookaside(pkt, *response);