10Sstevel@tonic-gate /*
2*7934SMark.Phalan@Sun.COM * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
30Sstevel@tonic-gate * Use is subject to license terms.
40Sstevel@tonic-gate */
50Sstevel@tonic-gate
60Sstevel@tonic-gate /*
70Sstevel@tonic-gate * kdc/dispatch.c
80Sstevel@tonic-gate *
90Sstevel@tonic-gate * Copyright 1990 by the Massachusetts Institute of Technology.
100Sstevel@tonic-gate *
110Sstevel@tonic-gate * Export of this software from the United States of America may
120Sstevel@tonic-gate * require a specific license from the United States Government.
130Sstevel@tonic-gate * It is the responsibility of any person or organization contemplating
140Sstevel@tonic-gate * export to obtain such a license before exporting.
150Sstevel@tonic-gate *
160Sstevel@tonic-gate * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
170Sstevel@tonic-gate * distribute this software and its documentation for any purpose and
180Sstevel@tonic-gate * without fee is hereby granted, provided that the above copyright
190Sstevel@tonic-gate * notice appear in all copies and that both that copyright notice and
200Sstevel@tonic-gate * this permission notice appear in supporting documentation, and that
210Sstevel@tonic-gate * the name of M.I.T. not be used in advertising or publicity pertaining
220Sstevel@tonic-gate * to distribution of the software without specific, written prior
230Sstevel@tonic-gate * permission. Furthermore if you modify this software you must label
240Sstevel@tonic-gate * your software as modified software and not distribute it in such a
250Sstevel@tonic-gate * fashion that it might be confused with the original M.I.T. software.
260Sstevel@tonic-gate * M.I.T. makes no representations about the suitability of
270Sstevel@tonic-gate * this software for any purpose. It is provided "as is" without express
280Sstevel@tonic-gate * or implied warranty.
290Sstevel@tonic-gate *
300Sstevel@tonic-gate *
310Sstevel@tonic-gate * Dispatch an incoming packet.
320Sstevel@tonic-gate */
330Sstevel@tonic-gate
340Sstevel@tonic-gate
350Sstevel@tonic-gate #include "k5-int.h"
360Sstevel@tonic-gate #include <syslog.h>
370Sstevel@tonic-gate #include "kdc_util.h"
380Sstevel@tonic-gate #include "extern.h"
390Sstevel@tonic-gate #include "adm_proto.h"
400Sstevel@tonic-gate #include <netinet/in.h>
410Sstevel@tonic-gate #include <arpa/inet.h>
420Sstevel@tonic-gate #include <string.h>
430Sstevel@tonic-gate
442881Smp153739 static krb5_int32 last_usec = 0, last_os_random = 0;
450Sstevel@tonic-gate
460Sstevel@tonic-gate krb5_error_code
dispatch(krb5_data * pkt,const krb5_fulladdr * from,krb5_data ** response)472881Smp153739 dispatch(krb5_data *pkt, const krb5_fulladdr *from, krb5_data **response)
480Sstevel@tonic-gate {
490Sstevel@tonic-gate
500Sstevel@tonic-gate krb5_error_code retval;
510Sstevel@tonic-gate krb5_kdc_req *as_req;
522881Smp153739 krb5_int32 now, now_usec;
532881Smp153739
540Sstevel@tonic-gate /* decode incoming packet, and dispatch */
550Sstevel@tonic-gate
560Sstevel@tonic-gate #ifndef NOCACHE
570Sstevel@tonic-gate /* try the replay lookaside buffer */
58*7934SMark.Phalan@Sun.COM if (kdc_check_lookaside(pkt, response)) {
590Sstevel@tonic-gate /* a hit! */
600Sstevel@tonic-gate const char *name = 0;
610Sstevel@tonic-gate char buf[46];
620Sstevel@tonic-gate
630Sstevel@tonic-gate name = (char *) inet_ntop (ADDRTYPE2FAMILY (from->address->addrtype),
640Sstevel@tonic-gate from->address->contents, buf, sizeof (buf));
650Sstevel@tonic-gate if (name == 0)
660Sstevel@tonic-gate name = "[unknown address type]";
670Sstevel@tonic-gate krb5_klog_syslog(LOG_INFO,
682881Smp153739 "DISPATCH: repeated (retransmitted?) request from %s, resending previous response",
692881Smp153739 name);
700Sstevel@tonic-gate return 0;
710Sstevel@tonic-gate }
720Sstevel@tonic-gate #endif
732881Smp153739 /* SUNW14resync XXX */
742881Smp153739 #if 0
752881Smp153739 retval = krb5_crypto_us_timeofday(&now, &now_usec);
762881Smp153739 if (retval == 0) {
772881Smp153739 krb5_int32 usec_difference = now_usec-last_usec;
782881Smp153739 krb5_data data;
792881Smp153739 if(last_os_random == 0)
802881Smp153739 last_os_random = now;
812881Smp153739 /* Grab random data from OS every hour*/
822881Smp153739 if(now-last_os_random >= 60*60) {
832881Smp153739 krb5_c_random_os_entropy(kdc_context, 0, NULL);
842881Smp153739 last_os_random = now;
852881Smp153739 }
862881Smp153739
872881Smp153739 data.length = sizeof(krb5_int32);
882881Smp153739 data.data = (void *) &usec_difference;
892881Smp153739
902881Smp153739 krb5_c_random_add_entropy(kdc_context,
912881Smp153739 KRB5_C_RANDSOURCE_TIMING, &data);
922881Smp153739 last_usec = now_usec;
932881Smp153739 }
942881Smp153739 #endif
950Sstevel@tonic-gate /* try TGS_REQ first; they are more common! */
960Sstevel@tonic-gate
970Sstevel@tonic-gate if (krb5_is_tgs_req(pkt)) {
982881Smp153739 retval = process_tgs_req(pkt, from, response);
990Sstevel@tonic-gate } else if (krb5_is_as_req(pkt)) {
1000Sstevel@tonic-gate if (!(retval = decode_krb5_as_req(pkt, &as_req))) {
1010Sstevel@tonic-gate /*
1020Sstevel@tonic-gate * setup_server_realm() sets up the global realm-specific data
1030Sstevel@tonic-gate * pointer.
1040Sstevel@tonic-gate */
1050Sstevel@tonic-gate if (!(retval = setup_server_realm(as_req->server))) {
106*7934SMark.Phalan@Sun.COM retval = process_as_req(as_req, pkt, from, response);
1070Sstevel@tonic-gate }
1080Sstevel@tonic-gate krb5_free_kdc_req(kdc_context, as_req);
1090Sstevel@tonic-gate }
1100Sstevel@tonic-gate }
1112881Smp153739 #ifdef KRB5_KRB4_COMPAT
1122881Smp153739 else if (pkt->data[0] == 4) /* old version */
1132881Smp153739 retval = process_v4(pkt, from, response);
1142881Smp153739 #endif
1150Sstevel@tonic-gate else
1160Sstevel@tonic-gate retval = KRB5KRB_AP_ERR_MSG_TYPE;
1170Sstevel@tonic-gate #ifndef NOCACHE
1180Sstevel@tonic-gate /* put the response into the lookaside buffer */
1190Sstevel@tonic-gate if (!retval)
120*7934SMark.Phalan@Sun.COM kdc_insert_lookaside(pkt, *response);
1210Sstevel@tonic-gate #endif
1220Sstevel@tonic-gate
1230Sstevel@tonic-gate return retval;
1240Sstevel@tonic-gate }
125