1 /* 2 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 3 * Use is subject to license terms. 4 */ 5 6 7 /* 8 * lib/krb5/krb/mk_req.c 9 * 10 * Copyright 1990,1991 by the Massachusetts Institute of Technology. 11 * All Rights Reserved. 12 * 13 * Export of this software from the United States of America may 14 * require a specific license from the United States Government. 15 * It is the responsibility of any person or organization contemplating 16 * export to obtain such a license before exporting. 17 * 18 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and 19 * distribute this software and its documentation for any purpose and 20 * without fee is hereby granted, provided that the above copyright 21 * notice appear in all copies and that both that copyright notice and 22 * this permission notice appear in supporting documentation, and that 23 * the name of M.I.T. not be used in advertising or publicity pertaining 24 * to distribution of the software without specific, written prior 25 * permission. Furthermore if you modify this software you must label 26 * your software as modified software and not distribute it in such a 27 * fashion that it might be confused with the original M.I.T. software. 28 * M.I.T. makes no representations about the suitability of 29 * this software for any purpose. It is provided "as is" without express 30 * or implied warranty. 31 * 32 * 33 * krb5_mk_req() routine. 34 */ 35 36 #include "k5-int.h" 37 #include "auth_con.h" 38 39 /* 40 Formats a KRB_AP_REQ message into outbuf. 41 42 server specifies the principal of the server to receive the message; if 43 credentials are not present in the credentials cache for this server, the 44 TGS request with default parameters is used in an attempt to obtain 45 such credentials, and they are stored in ccache. 46 47 kdc_options specifies the options requested for the 48 ap_req_options specifies the KRB_AP_REQ options desired. 49 50 checksum specifies the checksum to be used in the authenticator. 51 52 The outbuf buffer storage is allocated, and should be freed by the 53 caller when finished. 54 55 returns system errors 56 */ 57 58 krb5_error_code KRB5_CALLCONV 59 krb5_mk_req(krb5_context context, krb5_auth_context *auth_context, 60 krb5_flags ap_req_options, char *service, char *hostname, 61 krb5_data *in_data, krb5_ccache ccache, krb5_data *outbuf) 62 { 63 krb5_error_code retval; 64 krb5_principal server; 65 krb5_creds * credsp; 66 krb5_creds creds; 67 68 retval = krb5_sname_to_principal(context, hostname, service, 69 KRB5_NT_SRV_HST, &server); 70 if (retval) 71 return retval; 72 73 /* obtain ticket & session key */ 74 memset((char *)&creds, 0, sizeof(creds)); 75 if ((retval = krb5_copy_principal(context, server, &creds.server))) 76 goto cleanup_princ; 77 78 /* Solaris Kerberos */ 79 if ((retval = krb5_cc_get_principal(context, ccache, &creds.client)) != 0) 80 goto cleanup_creds; 81 82 /* Solaris Kerberos */ 83 if ((retval = krb5_get_credentials(context, 0, 84 ccache, &creds, &credsp)) != 0) 85 goto cleanup_creds; 86 87 retval = krb5_mk_req_extended(context, auth_context, ap_req_options, 88 in_data, credsp, outbuf); 89 90 krb5_free_creds(context, credsp); 91 92 cleanup_creds: 93 krb5_free_cred_contents(context, &creds); 94 95 cleanup_princ: 96 krb5_free_principal(context, server); 97 98 return retval; 99 } 100