Rewrite gss_add_cred() (fix #413)

It turns out gss_add_cred() really needed a complete rewrite.  It's much
better to first have a gss_duplicate_cred() (which has been needed for
other reasons anyways), and use that when the input_cred_handle is not
GSS_C_NO_CREDENTIAL and output_cred_handle is not NULL, then mutate that
duplicate credential handle (or the input_cred_handle if
output_cred_handle is NULL).
This commit is contained in:
Nicolas Williams
2018-12-26 17:24:08 -06:00
committed by Nico Williams
parent 134b53ead1
commit e6d1c10808
17 changed files with 737 additions and 161 deletions

View File

@@ -0,0 +1,54 @@
/*
* Copyright (c) 2010-2018 Kungliga Tekniska Högskolan
* (Royal Institute of Technology, Stockholm, Sweden).
* All rights reserved.
*
* Portions Copyright (c) 2010 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include "netlogon.h"
OM_uint32
_netlogon_duplicate_cred(OM_uint32 *minor_status,
gss_const_cred_id_t input_cred_handle,
gss_cred_id_t *output_cred_handle)
{
gssnetlogon_const_cred src = (gssnetlogon_const_cred)input_cred_handle;
gssnetlogon_cred dst;
dst = calloc(1, sizeof(*dst));
if (dst == NULL) {
*minor_status = ENOMEM;
return GSS_S_FAILURE;
}
*dst = *src;
return _netlogon_duplicate_name(minor_status, (gss_name_t)&src->Name, &dst->Name)
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010 Kungliga Tekniska Högskolan
* Copyright (c) 2010-2018 Kungliga Tekniska Högskolan
* (Royal Institute of Technology, Stockholm, Sweden).
* All rights reserved.
*
@@ -77,11 +77,28 @@ static gssapi_mech_interface_desc netlogon_mech = {
_netlogon_wrap_iov,
_netlogon_unwrap_iov,
_netlogon_wrap_iov_length,
NULL,
NULL,
NULL,
NULL,
NULL
NULL, /* gm_store_cred */
NULL, /* gm_export_cred */
NULL, /* gm_import_cred */
NULL, /* gm_acquire_cred_ext */
NULL, /* gm_iter_creds */
NULL, /* gm_destroy_cred */
NULL, /* gm_cred_hold */
NULL, /* gm_cred_unhold */
NULL, /* gm_cred_label_get */
NULL, /* gm_cred_label_set */
NULL, /* gm_mo */
0, /* gm_mo_num */
NULL, /* gm_localname */
NULL, /* gm_authorize_localname */
NULL, /* gm_display_name_ext */
NULL, /* gm_inquire_name */
NULL, /* gm_get_name_attribute */
NULL, /* gm_set_name_attribute */
NULL, /* gm_delete_name_attribute */
NULL, /* gm_export_name_composite */
NULL, /* gm_duplicate_cred */
NULL /* gm_compat */
};
gssapi_mech_interface

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010 Kungliga Tekniska Högskolan
* Copyright (c) 2010-2018 Kungliga Tekniska Högskolan
* (Royal Institute of Technology, Stockholm, Sweden).
* All rights reserved.
*
@@ -121,6 +121,7 @@ typedef struct gssnetlogon_name {
gss_buffer_desc NetbiosName;
gss_buffer_desc DnsName;
} *gssnetlogon_name;
typedef const struct gssnetlogon_name *gssnetlogon_const_name;
typedef struct gssnetlogon_cred {
gssnetlogon_name *Name;
@@ -128,6 +129,7 @@ typedef struct gssnetlogon_cred {
uint16_t SealAlgorithm;
uint8_t SessionKey[16];
} *gssnetlogon_cred;
typedef const struct gssnetlogon_cred *gssnetlogon_const_cred;
typedef struct gssnetlogon_ctx {
HEIMDAL_MUTEX Mutex;