2 * Copyright (c) 1999 - 2003 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * 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 * 3. Neither the name of the Institute nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 #include "gsskrb5_locl.h"
36 OM_uint32 GSSAPI_CALLCONV
37 _gsskrb5_export_sec_context(
38 OM_uint32
*minor_status
,
39 gss_ctx_id_t
*context_handle
,
40 gss_buffer_t interprocess_token
44 const gsskrb5_ctx ctx
= (const gsskrb5_ctx
) *context_handle
;
47 OM_uint32 ret
= GSS_S_COMPLETE
;
53 GSSAPI_KRB5_INIT (&context
);
55 HEIMDAL_MUTEX_lock(&ctx
->ctx_id_mutex
);
57 if (!(ctx
->flags
& GSS_C_TRANS_FLAG
)) {
58 HEIMDAL_MUTEX_unlock(&ctx
->ctx_id_mutex
);
60 return GSS_S_UNAVAILABLE
;
63 sp
= krb5_storage_emem ();
65 HEIMDAL_MUTEX_unlock(&ctx
->ctx_id_mutex
);
66 *minor_status
= ENOMEM
;
69 ac
= ctx
->auth_context
;
71 krb5_storage_set_byteorder(sp
, KRB5_STORAGE_BYTEORDER_PACKED
);
72 krb5_storage_set_flags(sp
, KRB5_STORAGE_PRINCIPAL_NO_NAME_TYPE
);
74 /* flagging included fields */
77 if (ac
->local_address
)
78 flags
|= SC_LOCAL_ADDRESS
;
79 if (ac
->remote_address
)
80 flags
|= SC_REMOTE_ADDRESS
;
84 flags
|= SC_LOCAL_SUBKEY
;
85 if (ac
->remote_subkey
)
86 flags
|= SC_REMOTE_SUBKEY
;
87 if (ac
->authenticator
)
88 flags
|= SC_AUTHENTICATOR
;
90 flags
|= SC_SOURCE_NAME
;
92 flags
|= SC_TARGET_NAME
;
96 kret
= krb5_store_int32 (sp
, flags
);
102 /* marshall auth context */
104 kret
= krb5_store_int32 (sp
, ac
->flags
);
106 *minor_status
= kret
;
109 if (ac
->local_address
) {
110 kret
= krb5_store_address (sp
, *ac
->local_address
);
112 *minor_status
= kret
;
116 if (ac
->remote_address
) {
117 kret
= krb5_store_address (sp
, *ac
->remote_address
);
119 *minor_status
= kret
;
123 kret
= krb5_store_int16 (sp
, ac
->local_port
);
125 *minor_status
= kret
;
128 kret
= krb5_store_int16 (sp
, ac
->remote_port
);
130 *minor_status
= kret
;
134 kret
= krb5_store_keyblock (sp
, *ac
->keyblock
);
136 *minor_status
= kret
;
140 if (ac
->local_subkey
) {
141 kret
= krb5_store_keyblock (sp
, *ac
->local_subkey
);
143 *minor_status
= kret
;
147 if (ac
->remote_subkey
) {
148 kret
= krb5_store_keyblock (sp
, *ac
->remote_subkey
);
150 *minor_status
= kret
;
154 kret
= krb5_store_int32 (sp
, ac
->local_seqnumber
);
156 *minor_status
= kret
;
159 kret
= krb5_store_int32 (sp
, ac
->remote_seqnumber
);
161 *minor_status
= kret
;
164 if (ac
->authenticator
) {
165 kret
= krb5_store_int64(sp
, ac
->authenticator
->ctime
);
167 *minor_status
= kret
;
170 kret
= krb5_store_int32(sp
, ac
->authenticator
->cusec
);
172 *minor_status
= kret
;
177 kret
= krb5_store_int32 (sp
, ac
->keytype
);
179 *minor_status
= kret
;
182 kret
= krb5_store_int32 (sp
, ac
->cksumtype
);
184 *minor_status
= kret
;
190 kret
= krb5_store_principal(sp
, ctx
->source
);
192 *minor_status
= kret
;
198 kret
= krb5_store_principal(sp
, ctx
->target
);
200 *minor_status
= kret
;
205 kret
= krb5_store_int32 (sp
, ctx
->flags
);
207 *minor_status
= kret
;
210 kret
= krb5_store_int32 (sp
, ctx
->more_flags
);
212 *minor_status
= kret
;
215 kret
= krb5_store_int32 (sp
, ctx
->state
);
217 *minor_status
= kret
;
221 * XXX We should put a 64-bit int here, but we don't have a
222 * krb5_store_int64() yet.
224 kret
= krb5_store_int32 (sp
, ctx
->endtime
);
226 *minor_status
= kret
;
230 kret
= _gssapi_msg_order_export(sp
, ctx
->order
);
232 *minor_status
= kret
;
237 kret
= krb5_storage_to_data (sp
, &data
);
238 krb5_storage_free (sp
);
240 HEIMDAL_MUTEX_unlock(&ctx
->ctx_id_mutex
);
241 *minor_status
= kret
;
242 return GSS_S_FAILURE
;
244 interprocess_token
->length
= data
.length
;
245 interprocess_token
->value
= data
.data
;
246 HEIMDAL_MUTEX_unlock(&ctx
->ctx_id_mutex
);
247 ret
= _gsskrb5_delete_sec_context (minor_status
, context_handle
,
249 if (ret
!= GSS_S_COMPLETE
)
250 _gss_secure_release_buffer (&minor
, interprocess_token
);
254 HEIMDAL_MUTEX_unlock(&ctx
->ctx_id_mutex
);
255 krb5_storage_free (sp
);