xref: /onnv-gate/usr/src/cmd/krb5/krb5kdc/dispatch.c (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
3*0Sstevel@tonic-gate  * Use is subject to license terms.
4*0Sstevel@tonic-gate  */
5*0Sstevel@tonic-gate 
6*0Sstevel@tonic-gate /*
7*0Sstevel@tonic-gate  * kdc/dispatch.c
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * Copyright 1990 by the Massachusetts Institute of Technology.
10*0Sstevel@tonic-gate  *
11*0Sstevel@tonic-gate  * Export of this software from the United States of America may
12*0Sstevel@tonic-gate  *   require a specific license from the United States Government.
13*0Sstevel@tonic-gate  *   It is the responsibility of any person or organization contemplating
14*0Sstevel@tonic-gate  *   export to obtain such a license before exporting.
15*0Sstevel@tonic-gate  *
16*0Sstevel@tonic-gate  * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
17*0Sstevel@tonic-gate  * distribute this software and its documentation for any purpose and
18*0Sstevel@tonic-gate  * without fee is hereby granted, provided that the above copyright
19*0Sstevel@tonic-gate  * notice appear in all copies and that both that copyright notice and
20*0Sstevel@tonic-gate  * this permission notice appear in supporting documentation, and that
21*0Sstevel@tonic-gate  * the name of M.I.T. not be used in advertising or publicity pertaining
22*0Sstevel@tonic-gate  * to distribution of the software without specific, written prior
23*0Sstevel@tonic-gate  * permission.  Furthermore if you modify this software you must label
24*0Sstevel@tonic-gate  * your software as modified software and not distribute it in such a
25*0Sstevel@tonic-gate  * fashion that it might be confused with the original M.I.T. software.
26*0Sstevel@tonic-gate  * M.I.T. makes no representations about the suitability of
27*0Sstevel@tonic-gate  * this software for any purpose.  It is provided "as is" without express
28*0Sstevel@tonic-gate  * or implied warranty.
29*0Sstevel@tonic-gate  *
30*0Sstevel@tonic-gate  *
31*0Sstevel@tonic-gate  * Dispatch an incoming packet.
32*0Sstevel@tonic-gate  */
33*0Sstevel@tonic-gate 
34*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
35*0Sstevel@tonic-gate 
36*0Sstevel@tonic-gate #define NEED_SOCKETS
37*0Sstevel@tonic-gate #include "k5-int.h"
38*0Sstevel@tonic-gate #include <syslog.h>
39*0Sstevel@tonic-gate #include "kdc_util.h"
40*0Sstevel@tonic-gate #include "extern.h"
41*0Sstevel@tonic-gate #include "adm_proto.h"
42*0Sstevel@tonic-gate #include <netinet/in.h>
43*0Sstevel@tonic-gate #include <arpa/inet.h>
44*0Sstevel@tonic-gate #include <string.h>
45*0Sstevel@tonic-gate 
46*0Sstevel@tonic-gate extern krb5_error_code setup_server_realm(krb5_principal);
47*0Sstevel@tonic-gate 
48*0Sstevel@tonic-gate krb5_error_code
49*0Sstevel@tonic-gate dispatch(krb5_data *pkt, const krb5_fulladdr *from, int portnum,
50*0Sstevel@tonic-gate 	krb5_data **response)
51*0Sstevel@tonic-gate {
52*0Sstevel@tonic-gate 
53*0Sstevel@tonic-gate     krb5_error_code retval;
54*0Sstevel@tonic-gate     krb5_kdc_req *as_req;
55*0Sstevel@tonic-gate 
56*0Sstevel@tonic-gate     /* decode incoming packet, and dispatch */
57*0Sstevel@tonic-gate 
58*0Sstevel@tonic-gate #ifndef NOCACHE
59*0Sstevel@tonic-gate     /* try the replay lookaside buffer */
60*0Sstevel@tonic-gate     if (kdc_check_lookaside(pkt, from, response)) {
61*0Sstevel@tonic-gate 	/* a hit! */
62*0Sstevel@tonic-gate 	const char *name = 0;
63*0Sstevel@tonic-gate 	char buf[46];
64*0Sstevel@tonic-gate 
65*0Sstevel@tonic-gate 	name = (char *) inet_ntop (ADDRTYPE2FAMILY (from->address->addrtype),
66*0Sstevel@tonic-gate 			  from->address->contents, buf, sizeof (buf));
67*0Sstevel@tonic-gate 	if (name == 0)
68*0Sstevel@tonic-gate 	    name = "[unknown address type]";
69*0Sstevel@tonic-gate 	krb5_klog_syslog(LOG_INFO,
70*0Sstevel@tonic-gate 			 "DISPATCH: repeated (retransmitted?) request from %s port %d, resending previous response",
71*0Sstevel@tonic-gate 			 name, portnum);
72*0Sstevel@tonic-gate 	return 0;
73*0Sstevel@tonic-gate     }
74*0Sstevel@tonic-gate #endif
75*0Sstevel@tonic-gate     /* try TGS_REQ first; they are more common! */
76*0Sstevel@tonic-gate 
77*0Sstevel@tonic-gate     if (krb5_is_tgs_req(pkt)) {
78*0Sstevel@tonic-gate 	retval = process_tgs_req(pkt, from, portnum, response);
79*0Sstevel@tonic-gate     } else if (krb5_is_as_req(pkt)) {
80*0Sstevel@tonic-gate 	if (!(retval = decode_krb5_as_req(pkt, &as_req))) {
81*0Sstevel@tonic-gate 	    /*
82*0Sstevel@tonic-gate 	     * setup_server_realm() sets up the global realm-specific data
83*0Sstevel@tonic-gate 	     * pointer.
84*0Sstevel@tonic-gate 	     */
85*0Sstevel@tonic-gate 	    if (!(retval = setup_server_realm(as_req->server))) {
86*0Sstevel@tonic-gate 		retval = process_as_req(as_req, from, portnum, response);
87*0Sstevel@tonic-gate 	    }
88*0Sstevel@tonic-gate 	    krb5_free_kdc_req(kdc_context, as_req);
89*0Sstevel@tonic-gate 	}
90*0Sstevel@tonic-gate     }
91*0Sstevel@tonic-gate     else
92*0Sstevel@tonic-gate 	retval = KRB5KRB_AP_ERR_MSG_TYPE;
93*0Sstevel@tonic-gate #ifndef NOCACHE
94*0Sstevel@tonic-gate     /* put the response into the lookaside buffer */
95*0Sstevel@tonic-gate     if (!retval)
96*0Sstevel@tonic-gate 	kdc_insert_lookaside(pkt, from, *response);
97*0Sstevel@tonic-gate #endif
98*0Sstevel@tonic-gate 
99*0Sstevel@tonic-gate     return retval;
100*0Sstevel@tonic-gate }
101