2 * Copyright (c) 2005 Doug Rabson
5 * Portions Copyright (c) 2009 Apple Inc. All rights reserved.
6 * Portions Copyright (c) 2019 AuriStor, Inc. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 #include "mech_locl.h"
32 GSSAPI_LIB_FUNCTION OM_uint32 GSSAPI_LIB_CALL
33 gssspi_exchange_meta_data(
34 OM_uint32 *minor_status,
35 gss_const_OID input_mech_type,
36 gss_cred_id_t input_cred_handle,
37 gss_ctx_id_t *context_handle,
38 gss_const_name_t target_name,
40 gss_const_buffer_t meta_data)
42 OM_uint32 major_status, junk;
43 gssapi_mech_interface m;
44 struct _gss_name *name = (struct _gss_name *) target_name;
45 struct _gss_mechanism_name *mn;
46 struct _gss_context *ctx = (struct _gss_context *) *context_handle;
47 gss_cred_id_t cred_handle;
49 gss_const_OID mech_type = input_mech_type;
53 if (mech_type == GSS_C_NO_OID)
54 return GSS_S_BAD_MECH;
57 ctx = calloc(1, sizeof(struct _gss_context));
59 *minor_status = ENOMEM;
63 m = ctx->gc_mech = __gss_get_mechanism(mech_type);
66 return GSS_S_BAD_MECH;
71 mech_type = &m->gm_mech_oid;
75 if (m->gm_exchange_meta_data == NULL) {
76 major_status = GSS_S_BAD_MECH;
80 major_status = _gss_find_mn(minor_status, name, mech_type, &mn);
81 if (major_status != GSS_S_COMPLETE)
84 if (m->gm_flags & GM_USE_MG_CRED)
85 cred_handle = input_cred_handle;
87 cred_handle = _gss_mg_find_mech_cred(input_cred_handle, mech_type);
89 if (input_cred_handle != GSS_C_NO_CREDENTIAL &&
90 cred_handle == NULL) {
91 major_status = GSS_S_NO_CRED;
95 /* note: mechanism is not obligated to allocate a context on success */
96 major_status = m->gm_exchange_meta_data(minor_status,
100 mn ? mn->gmn_name : GSS_C_NO_NAME,
103 if (major_status != GSS_S_COMPLETE)
104 _gss_mg_error(m, *minor_status);
107 if (allocated_ctx && major_status != GSS_S_COMPLETE)
108 gss_delete_sec_context(&junk, (gss_ctx_id_t *)&ctx, GSS_C_NO_BUFFER);
110 *context_handle = (gss_ctx_id_t) ctx;
112 _gss_mg_log(10, "gss-emd: return %d/%d", (int)major_status, (int)*minor_status);