17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * lib/krb5/krb/rd_req.c
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * Copyright 1990,1991 by the Massachusetts Institute of Technology.
57c478bd9Sstevel@tonic-gate  * All Rights Reserved.
67c478bd9Sstevel@tonic-gate  *
77c478bd9Sstevel@tonic-gate  * Export of this software from the United States of America may
87c478bd9Sstevel@tonic-gate  *   require a specific license from the United States Government.
97c478bd9Sstevel@tonic-gate  *   It is the responsibility of any person or organization contemplating
107c478bd9Sstevel@tonic-gate  *   export to obtain such a license before exporting.
11*55fea89dSDan Cross  *
127c478bd9Sstevel@tonic-gate  * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
137c478bd9Sstevel@tonic-gate  * distribute this software and its documentation for any purpose and
147c478bd9Sstevel@tonic-gate  * without fee is hereby granted, provided that the above copyright
157c478bd9Sstevel@tonic-gate  * notice appear in all copies and that both that copyright notice and
167c478bd9Sstevel@tonic-gate  * this permission notice appear in supporting documentation, and that
177c478bd9Sstevel@tonic-gate  * the name of M.I.T. not be used in advertising or publicity pertaining
187c478bd9Sstevel@tonic-gate  * to distribution of the software without specific, written prior
197c478bd9Sstevel@tonic-gate  * permission.  Furthermore if you modify this software you must label
207c478bd9Sstevel@tonic-gate  * your software as modified software and not distribute it in such a
217c478bd9Sstevel@tonic-gate  * fashion that it might be confused with the original M.I.T. software.
227c478bd9Sstevel@tonic-gate  * M.I.T. makes no representations about the suitability of
237c478bd9Sstevel@tonic-gate  * this software for any purpose.  It is provided "as is" without express
247c478bd9Sstevel@tonic-gate  * or implied warranty.
25*55fea89dSDan Cross  *
267c478bd9Sstevel@tonic-gate  *
277c478bd9Sstevel@tonic-gate  * krb5_rd_req()
287c478bd9Sstevel@tonic-gate  */
297c478bd9Sstevel@tonic-gate 
30159d09a2SMark Phalan #include "k5-int.h"
31159d09a2SMark Phalan #include "auth_con.h"
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate /*
347c478bd9Sstevel@tonic-gate  *  Parses a KRB_AP_REQ message, returning its contents.
35*55fea89dSDan Cross  *
367c478bd9Sstevel@tonic-gate  *  server specifies the expected server's name for the ticket.
37*55fea89dSDan Cross  *
387c478bd9Sstevel@tonic-gate  *  keyproc specifies a procedure to generate a decryption key for the
397c478bd9Sstevel@tonic-gate  *  ticket.  If keyproc is non-NULL, keyprocarg is passed to it, and the result
407c478bd9Sstevel@tonic-gate  *  used as a decryption key. If keyproc is NULL, then fetchfrom is checked;
417c478bd9Sstevel@tonic-gate  *  if it is non-NULL, it specifies a parameter name from which to retrieve the
427c478bd9Sstevel@tonic-gate  *  decryption key.  If fetchfrom is NULL, then the default key store is
437c478bd9Sstevel@tonic-gate  *  consulted.
44*55fea89dSDan Cross  *
457c478bd9Sstevel@tonic-gate  *  returns system errors, encryption errors, replay errors
467c478bd9Sstevel@tonic-gate  */
47159d09a2SMark Phalan 
48505d05c7Sgtb krb5_error_code KRB5_CALLCONV
krb5_rd_req(krb5_context context,krb5_auth_context * auth_context,const krb5_data * inbuf,krb5_const_principal server,krb5_keytab keytab,krb5_flags * ap_req_options,krb5_ticket ** ticket)49505d05c7Sgtb krb5_rd_req(krb5_context context, krb5_auth_context *auth_context, const krb5_data *inbuf, krb5_const_principal server, krb5_keytab keytab, krb5_flags *ap_req_options, krb5_ticket **ticket)
50*55fea89dSDan Cross 
51*55fea89dSDan Cross 
52*55fea89dSDan Cross 
53159d09a2SMark Phalan                                  	/* XXX do we really need this */
54*55fea89dSDan Cross 
55*55fea89dSDan Cross 
56*55fea89dSDan Cross 
577c478bd9Sstevel@tonic-gate {
587c478bd9Sstevel@tonic-gate     krb5_error_code 	  retval;
597c478bd9Sstevel@tonic-gate     krb5_ap_req 	* request;
607c478bd9Sstevel@tonic-gate     krb5_auth_context	  new_auth_context;
617c478bd9Sstevel@tonic-gate     krb5_keytab           new_keytab = NULL;
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate     if (!krb5_is_ap_req(inbuf))
647c478bd9Sstevel@tonic-gate 	return KRB5KRB_AP_ERR_MSG_TYPE;
657c478bd9Sstevel@tonic-gate     if ((retval = decode_krb5_ap_req(inbuf, &request))) {
667c478bd9Sstevel@tonic-gate     	switch (retval) {
677c478bd9Sstevel@tonic-gate 	case KRB5_BADMSGTYPE:
68*55fea89dSDan Cross 	    return KRB5KRB_AP_ERR_BADVERSION;
697c478bd9Sstevel@tonic-gate 	default:
707c478bd9Sstevel@tonic-gate 	    return(retval);
717c478bd9Sstevel@tonic-gate 	}
727c478bd9Sstevel@tonic-gate     }
737c478bd9Sstevel@tonic-gate 
747c478bd9Sstevel@tonic-gate     /* Get an auth context if necessary. */
757c478bd9Sstevel@tonic-gate     new_auth_context = NULL;
767c478bd9Sstevel@tonic-gate     if (*auth_context == NULL) {
777c478bd9Sstevel@tonic-gate 	if ((retval = krb5_auth_con_init(context, &new_auth_context)))
787c478bd9Sstevel@tonic-gate 	    goto cleanup_request;
797c478bd9Sstevel@tonic-gate         *auth_context = new_auth_context;
807c478bd9Sstevel@tonic-gate     }
817c478bd9Sstevel@tonic-gate 
82505d05c7Sgtb     if (!server) {
83505d05c7Sgtb 	server = request->ticket->server;
84505d05c7Sgtb     }
857c478bd9Sstevel@tonic-gate     /* Get an rcache if necessary. */
86505d05c7Sgtb     if (((*auth_context)->rcache == NULL)
87505d05c7Sgtb 	&& ((*auth_context)->auth_context_flags & KRB5_AUTH_CONTEXT_DO_TIME)
88159d09a2SMark Phalan && server) {
897c478bd9Sstevel@tonic-gate 	if ((retval = krb5_get_server_rcache(context,
907c478bd9Sstevel@tonic-gate      krb5_princ_component(context,server,0), &(*auth_context)->rcache)))
917c478bd9Sstevel@tonic-gate 	    goto cleanup_auth_context;
927c478bd9Sstevel@tonic-gate     }
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate     /* Get a keytab if necessary. */
957c478bd9Sstevel@tonic-gate     if (keytab == NULL) {
967c478bd9Sstevel@tonic-gate 	if ((retval = krb5_kt_default(context, &new_keytab)))
977c478bd9Sstevel@tonic-gate 	    goto cleanup_auth_context;
987c478bd9Sstevel@tonic-gate 	keytab = new_keytab;
997c478bd9Sstevel@tonic-gate     }
1007c478bd9Sstevel@tonic-gate 
101*55fea89dSDan Cross     retval = krb5_rd_req_decoded(context, auth_context, request, server,
1027c478bd9Sstevel@tonic-gate 				 keytab, ap_req_options, ticket);
1037c478bd9Sstevel@tonic-gate 
1047c478bd9Sstevel@tonic-gate     if (new_keytab != NULL)
1057c478bd9Sstevel@tonic-gate         (void) krb5_kt_close(context, new_keytab);
1067c478bd9Sstevel@tonic-gate 
1077c478bd9Sstevel@tonic-gate cleanup_auth_context:
1087c478bd9Sstevel@tonic-gate     if (new_auth_context && retval) {
1097c478bd9Sstevel@tonic-gate 	krb5_auth_con_free(context, new_auth_context);
1107c478bd9Sstevel@tonic-gate 	*auth_context = NULL;
1117c478bd9Sstevel@tonic-gate     }
1127c478bd9Sstevel@tonic-gate 
1137c478bd9Sstevel@tonic-gate cleanup_request:
1147c478bd9Sstevel@tonic-gate     krb5_free_ap_req(context, request);
1157c478bd9Sstevel@tonic-gate     return retval;
1167c478bd9Sstevel@tonic-gate }
1177c478bd9Sstevel@tonic-gate 
118