xref: /titanic_41/usr/src/cmd/krb5/krb5kdc/dispatch.c (revision 1ae0874509b6811fdde1dfd46f0d93fd09867a3f)
1 /*
2  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 
6 /*
7  * kdc/dispatch.c
8  *
9  * Copyright 1990 by the Massachusetts Institute of Technology.
10  *
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.
15  *
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.
29  *
30  *
31  * Dispatch an incoming packet.
32  */
33 
34 #pragma ident	"%Z%%M%	%I%	%E% SMI"
35 
36 #define NEED_SOCKETS
37 #include "k5-int.h"
38 #include <syslog.h>
39 #include "kdc_util.h"
40 #include "extern.h"
41 #include "adm_proto.h"
42 #include <netinet/in.h>
43 #include <arpa/inet.h>
44 #include <string.h>
45 
46 extern krb5_error_code setup_server_realm(krb5_principal);
47 
48 krb5_error_code
49 dispatch(krb5_data *pkt, const krb5_fulladdr *from, int portnum,
50 	krb5_data **response)
51 {
52 
53     krb5_error_code retval;
54     krb5_kdc_req *as_req;
55 
56     /* decode incoming packet, and dispatch */
57 
58 #ifndef NOCACHE
59     /* try the replay lookaside buffer */
60     if (kdc_check_lookaside(pkt, from, response)) {
61 	/* a hit! */
62 	const char *name = 0;
63 	char buf[46];
64 
65 	name = (char *) inet_ntop (ADDRTYPE2FAMILY (from->address->addrtype),
66 			  from->address->contents, buf, sizeof (buf));
67 	if (name == 0)
68 	    name = "[unknown address type]";
69 	krb5_klog_syslog(LOG_INFO,
70 			 "DISPATCH: repeated (retransmitted?) request from %s port %d, resending previous response",
71 			 name, portnum);
72 	return 0;
73     }
74 #endif
75     /* try TGS_REQ first; they are more common! */
76 
77     if (krb5_is_tgs_req(pkt)) {
78 	retval = process_tgs_req(pkt, from, portnum, response);
79     } else if (krb5_is_as_req(pkt)) {
80 	if (!(retval = decode_krb5_as_req(pkt, &as_req))) {
81 	    /*
82 	     * setup_server_realm() sets up the global realm-specific data
83 	     * pointer.
84 	     */
85 	    if (!(retval = setup_server_realm(as_req->server))) {
86 		retval = process_as_req(as_req, from, portnum, response);
87 	    }
88 	    krb5_free_kdc_req(kdc_context, as_req);
89 	}
90     }
91     else
92 	retval = KRB5KRB_AP_ERR_MSG_TYPE;
93 #ifndef NOCACHE
94     /* put the response into the lookaside buffer */
95     if (!retval)
96 	kdc_insert_lookaside(pkt, from, *response);
97 #endif
98 
99     return retval;
100 }
101