1226031Sstas/* 2226031Sstas * Copyright (c) 2009 Kungliga Tekniska H�gskolan 3226031Sstas * (Royal Institute of Technology, Stockholm, Sweden). 4226031Sstas * All rights reserved. 5226031Sstas * 6226031Sstas * Redistribution and use in source and binary forms, with or without 7226031Sstas * modification, are permitted provided that the following conditions 8226031Sstas * are met: 9226031Sstas * 10226031Sstas * 1. Redistributions of source code must retain the above copyright 11226031Sstas * notice, this list of conditions and the following disclaimer. 12226031Sstas * 13226031Sstas * 2. Redistributions in binary form must reproduce the above copyright 14226031Sstas * notice, this list of conditions and the following disclaimer in the 15226031Sstas * documentation and/or other materials provided with the distribution. 16226031Sstas * 17226031Sstas * 3. Neither the name of the Institute nor the names of its contributors 18226031Sstas * may be used to endorse or promote products derived from this software 19226031Sstas * without specific prior written permission. 20226031Sstas * 21226031Sstas * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 22226031Sstas * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23226031Sstas * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24226031Sstas * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 25226031Sstas * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26226031Sstas * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27226031Sstas * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28226031Sstas * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29226031Sstas * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30226031Sstas * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31226031Sstas * SUCH DAMAGE. 32226031Sstas */ 33226031Sstas 34226031Sstas#include "mech_locl.h" 35226031Sstas 36226031SstasGSSAPI_LIB_FUNCTION OM_uint32 GSSAPI_LIB_CALL 37226031Sstasgss_store_cred(OM_uint32 *minor_status, 38226031Sstas gss_cred_id_t input_cred_handle, 39226031Sstas gss_cred_usage_t cred_usage, 40226031Sstas const gss_OID desired_mech, 41226031Sstas OM_uint32 overwrite_cred, 42226031Sstas OM_uint32 default_cred, 43226031Sstas gss_OID_set *elements_stored, 44226031Sstas gss_cred_usage_t *cred_usage_stored) 45226031Sstas{ 46226031Sstas struct _gss_cred *cred = (struct _gss_cred *) input_cred_handle; 47226031Sstas struct _gss_mechanism_cred *mc; 48226031Sstas OM_uint32 maj, junk; 49226031Sstas 50226031Sstas if (minor_status == NULL) 51226031Sstas return GSS_S_FAILURE; 52226031Sstas if (elements_stored) 53226031Sstas *elements_stored = NULL; 54226031Sstas if (cred_usage_stored) 55226031Sstas *cred_usage_stored = 0; 56226031Sstas 57226031Sstas if (cred == NULL) 58226031Sstas return GSS_S_NO_CONTEXT; 59226031Sstas 60226031Sstas if (elements_stored) { 61226031Sstas maj = gss_create_empty_oid_set(minor_status, elements_stored); 62226031Sstas if (maj != GSS_S_COMPLETE) 63226031Sstas return maj; 64226031Sstas } 65226031Sstas 66226031Sstas HEIM_SLIST_FOREACH(mc, &cred->gc_mc, gmc_link) { 67226031Sstas gssapi_mech_interface m = mc->gmc_mech; 68226031Sstas 69226031Sstas if (m == NULL || m->gm_store_cred == NULL) 70226031Sstas continue; 71226031Sstas 72226031Sstas if (desired_mech) { 73226031Sstas maj = gss_oid_equal(&m->gm_mech_oid, desired_mech); 74226031Sstas if (maj != 0) 75226031Sstas continue; 76226031Sstas } 77226031Sstas 78226031Sstas maj = (m->gm_store_cred)(minor_status, mc->gmc_cred, 79226031Sstas cred_usage, desired_mech, overwrite_cred, 80226031Sstas default_cred, NULL, cred_usage_stored); 81226031Sstas if (maj != GSS_S_COMPLETE) { 82226031Sstas gss_release_oid_set(&junk, elements_stored); 83226031Sstas return maj; 84226031Sstas } 85226031Sstas 86226031Sstas if (elements_stored) { 87226031Sstas gss_add_oid_set_member(&junk, 88226031Sstas &m->gm_mech_oid, 89226031Sstas elements_stored); 90226031Sstas } 91226031Sstas 92226031Sstas } 93226031Sstas return GSS_S_COMPLETE; 94226031Sstas} 95