Line data Source code
1 : /*-
2 : * Copyright (c) 2005 Doug Rabson
3 : * All rights reserved.
4 : *
5 : * Portions Copyright (c) 2009 Apple Inc. All rights reserved.
6 : * Portions Copyright (c) 2019 AuriStor, Inc. All rights reserved.
7 : *
8 : * Redistribution and use in source and binary forms, with or without
9 : * modification, are permitted provided that the following conditions
10 : * are met:
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.
16 : *
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
27 : * SUCH DAMAGE.
28 : */
29 :
30 : #include "mech_locl.h"
31 :
32 : GSSAPI_LIB_FUNCTION OM_uint32 GSSAPI_LIB_CALL
33 0 : 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,
39 : OM_uint32 req_flags,
40 : gss_const_buffer_t meta_data)
41 : {
42 0 : OM_uint32 major_status, junk;
43 0 : gssapi_mech_interface m;
44 0 : struct _gss_name *name = (struct _gss_name *) target_name;
45 0 : struct _gss_mechanism_name *mn;
46 0 : struct _gss_context *ctx = (struct _gss_context *) *context_handle;
47 0 : gss_cred_id_t cred_handle;
48 0 : int allocated_ctx;
49 0 : gss_const_OID mech_type = input_mech_type;
50 :
51 0 : *minor_status = 0;
52 :
53 0 : if (mech_type == GSS_C_NO_OID)
54 0 : return GSS_S_BAD_MECH;
55 :
56 0 : if (ctx == NULL) {
57 0 : ctx = calloc(1, sizeof(struct _gss_context));
58 0 : if (ctx == NULL) {
59 0 : *minor_status = ENOMEM;
60 0 : return GSS_S_FAILURE;
61 : }
62 :
63 0 : m = ctx->gc_mech = __gss_get_mechanism(mech_type);
64 0 : if (m == NULL) {
65 0 : free(ctx);
66 0 : return GSS_S_BAD_MECH;
67 : }
68 0 : allocated_ctx = 1;
69 : } else {
70 0 : m = ctx->gc_mech;
71 0 : mech_type = &m->gm_mech_oid;
72 0 : allocated_ctx = 0;
73 : }
74 :
75 0 : if (m->gm_exchange_meta_data == NULL) {
76 0 : major_status = GSS_S_BAD_MECH;
77 0 : goto cleanup;
78 : }
79 :
80 0 : major_status = _gss_find_mn(minor_status, name, mech_type, &mn);
81 0 : if (major_status != GSS_S_COMPLETE)
82 0 : goto cleanup;
83 :
84 0 : if (m->gm_flags & GM_USE_MG_CRED)
85 0 : cred_handle = input_cred_handle;
86 : else
87 0 : cred_handle = _gss_mg_find_mech_cred(input_cred_handle, mech_type);
88 :
89 0 : if (input_cred_handle != GSS_C_NO_CREDENTIAL &&
90 0 : cred_handle == NULL) {
91 0 : major_status = GSS_S_NO_CRED;
92 0 : goto cleanup;
93 : }
94 :
95 : /* note: mechanism is not obligated to allocate a context on success */
96 0 : major_status = m->gm_exchange_meta_data(minor_status,
97 : mech_type,
98 : cred_handle,
99 0 : &ctx->gc_ctx,
100 0 : mn ? mn->gmn_name : GSS_C_NO_NAME,
101 : req_flags,
102 : meta_data);
103 0 : if (major_status != GSS_S_COMPLETE)
104 0 : _gss_mg_error(m, *minor_status);
105 :
106 0 : cleanup:
107 0 : if (allocated_ctx && major_status != GSS_S_COMPLETE)
108 0 : gss_delete_sec_context(&junk, (gss_ctx_id_t *)&ctx, GSS_C_NO_BUFFER);
109 :
110 0 : *context_handle = (gss_ctx_id_t) ctx;
111 :
112 0 : _gss_mg_log(10, "gss-emd: return %d/%d", (int)major_status, (int)*minor_status);
113 :
114 0 : return major_status;
115 : }
|