155682Smarkm/* 2178825Sdfr * Copyright (c) 1997 - 2004 Kungliga Tekniska H�gskolan 355682Smarkm * (Royal Institute of Technology, Stockholm, Sweden). 455682Smarkm * All rights reserved. 555682Smarkm * 655682Smarkm * Redistribution and use in source and binary forms, with or without 755682Smarkm * modification, are permitted provided that the following conditions 855682Smarkm * are met: 955682Smarkm * 1055682Smarkm * 1. Redistributions of source code must retain the above copyright 1155682Smarkm * notice, this list of conditions and the following disclaimer. 1255682Smarkm * 1355682Smarkm * 2. Redistributions in binary form must reproduce the above copyright 1455682Smarkm * notice, this list of conditions and the following disclaimer in the 1555682Smarkm * documentation and/or other materials provided with the distribution. 1655682Smarkm * 1755682Smarkm * 3. Neither the name of the Institute nor the names of its contributors 1855682Smarkm * may be used to endorse or promote products derived from this software 1955682Smarkm * without specific prior written permission. 2055682Smarkm * 2155682Smarkm * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 2255682Smarkm * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2355682Smarkm * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2455682Smarkm * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 2555682Smarkm * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2655682Smarkm * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2755682Smarkm * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2855682Smarkm * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2955682Smarkm * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3055682Smarkm * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3155682Smarkm * SUCH DAMAGE. 3255682Smarkm */ 3355682Smarkm 3455682Smarkm#include <krb5_locl.h> 3555682Smarkm 36178825SdfrRCSID("$Id: mk_req.c 13863 2004-05-25 21:46:46Z lha $"); 3755682Smarkm 38178825Sdfrkrb5_error_code KRB5_LIB_FUNCTION 3972445Sassarkrb5_mk_req_exact(krb5_context context, 4072445Sassar krb5_auth_context *auth_context, 4172445Sassar const krb5_flags ap_req_options, 4272445Sassar const krb5_principal server, 4372445Sassar krb5_data *in_data, 4472445Sassar krb5_ccache ccache, 4572445Sassar krb5_data *outbuf) 4655682Smarkm{ 4757416Smarkm krb5_error_code ret; 4855682Smarkm krb5_creds this_cred, *cred; 4955682Smarkm 5055682Smarkm memset(&this_cred, 0, sizeof(this_cred)); 5155682Smarkm 5257416Smarkm ret = krb5_cc_get_principal(context, ccache, &this_cred.client); 5355682Smarkm 5457416Smarkm if(ret) 5557416Smarkm return ret; 5655682Smarkm 5772445Sassar ret = krb5_copy_principal (context, server, &this_cred.server); 5857416Smarkm if (ret) { 59178825Sdfr krb5_free_cred_contents (context, &this_cred); 6057416Smarkm return ret; 6155682Smarkm } 6255682Smarkm 6355682Smarkm this_cred.times.endtime = 0; 6455682Smarkm if (auth_context && *auth_context && (*auth_context)->keytype) 6555682Smarkm this_cred.session.keytype = (*auth_context)->keytype; 6655682Smarkm 6757416Smarkm ret = krb5_get_credentials (context, 0, ccache, &this_cred, &cred); 68178825Sdfr krb5_free_cred_contents(context, &this_cred); 6957416Smarkm if (ret) 7057416Smarkm return ret; 7155682Smarkm 7290926Snectar ret = krb5_mk_req_extended (context, 7390926Snectar auth_context, 7490926Snectar ap_req_options, 7590926Snectar in_data, 7690926Snectar cred, 7790926Snectar outbuf); 7890926Snectar krb5_free_creds(context, cred); 7990926Snectar return ret; 8055682Smarkm} 8172445Sassar 82178825Sdfrkrb5_error_code KRB5_LIB_FUNCTION 8372445Sassarkrb5_mk_req(krb5_context context, 8472445Sassar krb5_auth_context *auth_context, 8572445Sassar const krb5_flags ap_req_options, 8672445Sassar const char *service, 8772445Sassar const char *hostname, 8872445Sassar krb5_data *in_data, 8972445Sassar krb5_ccache ccache, 9072445Sassar krb5_data *outbuf) 9172445Sassar{ 9272445Sassar krb5_error_code ret; 9372445Sassar char **realms; 9472445Sassar char *real_hostname; 9572445Sassar krb5_principal server; 9672445Sassar 9772445Sassar ret = krb5_expand_hostname_realms (context, hostname, 9872445Sassar &real_hostname, &realms); 9972445Sassar if (ret) 10072445Sassar return ret; 10172445Sassar 10272445Sassar ret = krb5_build_principal (context, &server, 10372445Sassar strlen(*realms), 10472445Sassar *realms, 10572445Sassar service, 10672445Sassar real_hostname, 10772445Sassar NULL); 10872445Sassar free (real_hostname); 10972445Sassar krb5_free_host_realm (context, realms); 11072445Sassar if (ret) 11172445Sassar return ret; 11272445Sassar ret = krb5_mk_req_exact (context, auth_context, ap_req_options, 11372445Sassar server, in_data, ccache, outbuf); 11472445Sassar krb5_free_principal (context, server); 11572445Sassar return ret; 11672445Sassar} 117