Path: blob/main/crypto/heimdal/lib/gssapi/ntlm/creds.c
34914 views
/*1* Copyright (c) 2006 Kungliga Tekniska Högskolan2* (Royal Institute of Technology, Stockholm, Sweden).3* All rights reserved.4*5* Portions Copyright (c) 2009 Apple Inc. All rights reserved.6*7* Redistribution and use in source and binary forms, with or without8* modification, are permitted provided that the following conditions9* are met:10*11* 1. Redistributions of source code must retain the above copyright12* notice, this list of conditions and the following disclaimer.13*14* 2. Redistributions in binary form must reproduce the above copyright15* notice, this list of conditions and the following disclaimer in the16* documentation and/or other materials provided with the distribution.17*18* 3. Neither the name of the Institute nor the names of its contributors19* may be used to endorse or promote products derived from this software20* without specific prior written permission.21*22* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND23* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE24* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE25* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE26* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL27* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS28* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)29* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT30* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY31* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF32* SUCH DAMAGE.33*/3435#include "ntlm.h"3637OM_uint32 GSSAPI_CALLCONV38_gss_ntlm_inquire_cred39(OM_uint32 * minor_status,40const gss_cred_id_t cred_handle,41gss_name_t * name,42OM_uint32 * lifetime,43gss_cred_usage_t * cred_usage,44gss_OID_set * mechanisms45)46{47OM_uint32 ret, junk;4849*minor_status = 0;5051if (cred_handle == NULL)52return GSS_S_NO_CRED;5354if (name) {55ntlm_name n = calloc(1, sizeof(*n));56ntlm_cred c = (ntlm_cred)cred_handle;57if (n) {58n->user = strdup(c->username);59n->domain = strdup(c->domain);60}61if (n == NULL || n->user == NULL || n->domain == NULL) {62if (n)63free(n->user);64*minor_status = ENOMEM;65return GSS_S_FAILURE;66}67*name = (gss_name_t)n;68}69if (lifetime)70*lifetime = GSS_C_INDEFINITE;71if (cred_usage)72*cred_usage = 0;73if (mechanisms)74*mechanisms = GSS_C_NO_OID_SET;7576if (cred_handle == GSS_C_NO_CREDENTIAL)77return GSS_S_NO_CRED;7879if (mechanisms) {80ret = gss_create_empty_oid_set(minor_status, mechanisms);81if (ret)82goto out;83ret = gss_add_oid_set_member(minor_status,84GSS_NTLM_MECHANISM,85mechanisms);86if (ret)87goto out;88}8990return GSS_S_COMPLETE;91out:92gss_release_oid_set(&junk, mechanisms);93return ret;94}9596#ifdef HAVE_KCM97static OM_uint3298_gss_ntlm_destroy_kcm_cred(gss_cred_id_t *cred_handle)99{100krb5_storage *request, *response;101krb5_data response_data;102krb5_context context;103krb5_error_code ret;104ntlm_cred cred;105106cred = (ntlm_cred)*cred_handle;107108ret = krb5_init_context(&context);109if (ret)110return ret;111112ret = krb5_kcm_storage_request(context, KCM_OP_DEL_NTLM_CRED, &request);113if (ret)114goto out;115116ret = krb5_store_stringz(request, cred->username);117if (ret)118goto out;119120ret = krb5_store_stringz(request, cred->domain);121if (ret)122goto out;123124ret = krb5_kcm_call(context, request, &response, &response_data);125if (ret)126goto out;127128krb5_storage_free(request);129krb5_storage_free(response);130krb5_data_free(&response_data);131132out:133krb5_free_context(context);134135return ret;136}137#endif /* HAVE_KCM */138139OM_uint32 GSSAPI_CALLCONV140_gss_ntlm_destroy_cred(OM_uint32 *minor_status,141gss_cred_id_t *cred_handle)142{143#ifdef HAVE_KCM144krb5_error_code ret;145#endif146147if (cred_handle == NULL || *cred_handle == GSS_C_NO_CREDENTIAL)148return GSS_S_COMPLETE;149150#ifdef HAVE_KCM151ret = _gss_ntlm_destroy_kcm_cred(cred_handle);152if (ret) {153*minor_status = ret;154return GSS_S_FAILURE;155}156#endif157158return _gss_ntlm_release_cred(minor_status, cred_handle);159}160161162