1 #pragma ident "%Z%%M% %I% %E% SMI" 2 /* 3 * lib/krb5/krb/rd_req.c 4 * 5 * Copyright 1990,1991 by the Massachusetts Institute of Technology. 6 * All Rights Reserved. 7 * 8 * Export of this software from the United States of America may 9 * require a specific license from the United States Government. 10 * It is the responsibility of any person or organization contemplating 11 * export to obtain such a license before exporting. 12 * 13 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and 14 * distribute this software and its documentation for any purpose and 15 * without fee is hereby granted, provided that the above copyright 16 * notice appear in all copies and that both that copyright notice and 17 * this permission notice appear in supporting documentation, and that 18 * the name of M.I.T. not be used in advertising or publicity pertaining 19 * to distribution of the software without specific, written prior 20 * permission. Furthermore if you modify this software you must label 21 * your software as modified software and not distribute it in such a 22 * fashion that it might be confused with the original M.I.T. software. 23 * M.I.T. makes no representations about the suitability of 24 * this software for any purpose. It is provided "as is" without express 25 * or implied warranty. 26 * 27 * 28 * krb5_rd_req() 29 */ 30 31 #include <k5-int.h> 32 #include <auth_con.h> 33 34 /* 35 * Parses a KRB_AP_REQ message, returning its contents. 36 * 37 * server specifies the expected server's name for the ticket. 38 * 39 * keyproc specifies a procedure to generate a decryption key for the 40 * ticket. If keyproc is non-NULL, keyprocarg is passed to it, and the result 41 * used as a decryption key. If keyproc is NULL, then fetchfrom is checked; 42 * if it is non-NULL, it specifies a parameter name from which to retrieve the 43 * decryption key. If fetchfrom is NULL, then the default key store is 44 * consulted. 45 * 46 * returns system errors, encryption errors, replay errors 47 */ 48 49 KRB5_DLLIMP krb5_error_code KRB5_CALLCONV 50 krb5_rd_req(context, auth_context, inbuf, server, keytab, 51 ap_req_options, ticket) 52 krb5_context context; 53 krb5_auth_context FAR * auth_context; 54 const krb5_data FAR * inbuf; 55 krb5_const_principal server; /* XXX do we really need this */ 56 krb5_keytab keytab; 57 krb5_flags FAR * ap_req_options; 58 krb5_ticket FAR *FAR * ticket; 59 { 60 krb5_error_code retval; 61 krb5_ap_req * request; 62 krb5_auth_context new_auth_context; 63 krb5_keytab new_keytab = NULL; 64 65 if (!krb5_is_ap_req(inbuf)) 66 return KRB5KRB_AP_ERR_MSG_TYPE; 67 if ((retval = decode_krb5_ap_req(inbuf, &request))) { 68 switch (retval) { 69 case KRB5_BADMSGTYPE: 70 return KRB5KRB_AP_ERR_BADVERSION; 71 default: 72 return(retval); 73 } 74 } 75 76 /* Get an auth context if necessary. */ 77 new_auth_context = NULL; 78 if (*auth_context == NULL) { 79 if ((retval = krb5_auth_con_init(context, &new_auth_context))) 80 goto cleanup_request; 81 *auth_context = new_auth_context; 82 } 83 84 /* Get an rcache if necessary. */ 85 if (((*auth_context)->rcache == NULL) && server) { 86 if ((retval = krb5_get_server_rcache(context, 87 krb5_princ_component(context,server,0), &(*auth_context)->rcache))) 88 goto cleanup_auth_context; 89 } 90 91 /* Get a keytab if necessary. */ 92 if (keytab == NULL) { 93 if ((retval = krb5_kt_default(context, &new_keytab))) 94 goto cleanup_auth_context; 95 keytab = new_keytab; 96 } 97 98 retval = krb5_rd_req_decoded(context, auth_context, request, server, 99 keytab, ap_req_options, ticket); 100 101 if (new_keytab != NULL) 102 (void) krb5_kt_close(context, new_keytab); 103 104 cleanup_auth_context: 105 if (new_auth_context && retval) { 106 krb5_auth_con_free(context, new_auth_context); 107 *auth_context = NULL; 108 } 109 110 cleanup_request: 111 krb5_free_ap_req(context, request); 112 return retval; 113 } 114 115