From 57df2ff1cc6c66c91d22e92d94435a714db9267c Mon Sep 17 00:00:00 2001 From: Luke Howard Date: Wed, 2 Jan 2019 16:44:12 +1100 Subject: [PATCH] gssapi: ntlm mech should use _gss_ntlm_copy_cred() to dup cred --- lib/gssapi/ntlm/duplicate_cred.c | 24 ++++-------------------- lib/gssapi/ntlm/init_sec_context.c | 7 ++++--- 2 files changed, 8 insertions(+), 23 deletions(-) diff --git a/lib/gssapi/ntlm/duplicate_cred.c b/lib/gssapi/ntlm/duplicate_cred.c index acb772043..e0263a393 100644 --- a/lib/gssapi/ntlm/duplicate_cred.c +++ b/lib/gssapi/ntlm/duplicate_cred.c @@ -49,25 +49,9 @@ _gss_ntlm_duplicate_cred(OM_uint32 *minor_status, NULL); *output_cred_handle = GSS_C_NO_CREDENTIAL; - if ((new_cred = calloc(1, sizeof(*new_cred))) == NULL) { - *minor_status = ENOMEM; - return GSS_S_FAILURE; - } - - new_cred->usage = cred->usage; - new_cred->username = strdup(cred->username); - new_cred->domain = strdup(cred->domain); - new_cred->key.data = malloc(cred->key.length); - if (new_cred->username == NULL || new_cred->domain == NULL || - new_cred->key.data == NULL) { - *output_cred_handle = (gss_cred_id_t) new_cred; - _gss_ntlm_release_cred(&junk, output_cred_handle); - *minor_status = ENOMEM; - return GSS_S_FAILURE; - } - memcpy(new_cred->key.data, cred->key.data, cred->key.length); - new_cred->key.length = cred->key.length; - *output_cred_handle = (gss_cred_id_t) new_cred; - return GSS_S_COMPLETE; + *minor_status = _gss_ntlm_copy_cred((ntlm_cred)input_cred_handle, + (ntlm_cred *)output_cred_handle); + + return *minor_status == 0 ? GSS_S_COMPLETE : GSS_S_FAILURE; } diff --git a/lib/gssapi/ntlm/init_sec_context.c b/lib/gssapi/ntlm/init_sec_context.c index 53a07dd80..5135f7bbf 100644 --- a/lib/gssapi/ntlm/init_sec_context.c +++ b/lib/gssapi/ntlm/init_sec_context.c @@ -215,12 +215,13 @@ _gss_ntlm_get_user_cred(const ntlm_name target_name, return ret; } -static int -_gss_copy_cred(ntlm_cred from, ntlm_cred *to) +int +_gss_ntlm_copy_cred(ntlm_cred from, ntlm_cred *to) { *to = calloc(1, sizeof(**to)); if (*to == NULL) return ENOMEM; + (*to)->usage = from->usage; (*to)->username = strdup(from->username); if ((*to)->username == NULL) { free(*to); @@ -289,7 +290,7 @@ _gss_ntlm_init_sec_context if (initiator_cred_handle != GSS_C_NO_CREDENTIAL) { ntlm_cred cred = (ntlm_cred)initiator_cred_handle; - ret = _gss_copy_cred(cred, &ctx->client); + ret = _gss_ntlm_copy_cred(cred, &ctx->client); } else ret = _gss_ntlm_get_user_cred(name, &ctx->client);