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 "gssapi_locl.h"
39 gss_export_sec_context (
40 OM_uint32
* minor_status
,
41 gss_ctx_id_t
* context_handle
,
42 gss_buffer_t interprocess_token
47 OM_uint32 ret
= GSS_S_COMPLETE
;
49 gss_buffer_desc buffer
;
56 HEIMDAL_MUTEX_lock(&(*context_handle
)->ctx_id_mutex
);
58 if (!((*context_handle
)->flags
& GSS_C_TRANS_FLAG
)) {
59 HEIMDAL_MUTEX_unlock(&(*context_handle
)->ctx_id_mutex
);
61 return GSS_S_UNAVAILABLE
;
64 sp
= krb5_storage_emem ();
66 HEIMDAL_MUTEX_unlock(&(*context_handle
)->ctx_id_mutex
);
67 *minor_status
= ENOMEM
;
70 ac
= (*context_handle
)->auth_context
;
72 /* flagging included fields */
75 if (ac
->local_address
)
76 flags
|= SC_LOCAL_ADDRESS
;
77 if (ac
->remote_address
)
78 flags
|= SC_REMOTE_ADDRESS
;
82 flags
|= SC_LOCAL_SUBKEY
;
83 if (ac
->remote_subkey
)
84 flags
|= SC_REMOTE_SUBKEY
;
86 kret
= krb5_store_int32 (sp
, flags
);
92 /* marshall auth context */
94 kret
= krb5_store_int32 (sp
, ac
->flags
);
99 if (ac
->local_address
) {
100 kret
= krb5_store_address (sp
, *ac
->local_address
);
102 *minor_status
= kret
;
106 if (ac
->remote_address
) {
107 kret
= krb5_store_address (sp
, *ac
->remote_address
);
109 *minor_status
= kret
;
113 kret
= krb5_store_int16 (sp
, ac
->local_port
);
115 *minor_status
= kret
;
118 kret
= krb5_store_int16 (sp
, ac
->remote_port
);
120 *minor_status
= kret
;
124 kret
= krb5_store_keyblock (sp
, *ac
->keyblock
);
126 *minor_status
= kret
;
130 if (ac
->local_subkey
) {
131 kret
= krb5_store_keyblock (sp
, *ac
->local_subkey
);
133 *minor_status
= kret
;
137 if (ac
->remote_subkey
) {
138 kret
= krb5_store_keyblock (sp
, *ac
->remote_subkey
);
140 *minor_status
= kret
;
144 kret
= krb5_store_int32 (sp
, ac
->local_seqnumber
);
146 *minor_status
= kret
;
149 kret
= krb5_store_int32 (sp
, ac
->remote_seqnumber
);
151 *minor_status
= kret
;
155 kret
= krb5_store_int32 (sp
, ac
->keytype
);
157 *minor_status
= kret
;
160 kret
= krb5_store_int32 (sp
, ac
->cksumtype
);
162 *minor_status
= kret
;
168 ret
= gss_export_name (minor_status
, (*context_handle
)->source
, &buffer
);
171 data
.data
= buffer
.value
;
172 data
.length
= buffer
.length
;
173 kret
= krb5_store_data (sp
, data
);
174 gss_release_buffer (&minor
, &buffer
);
176 *minor_status
= kret
;
180 ret
= gss_export_name (minor_status
, (*context_handle
)->target
, &buffer
);
183 data
.data
= buffer
.value
;
184 data
.length
= buffer
.length
;
188 kret
= krb5_store_data (sp
, data
);
189 gss_release_buffer (&minor
, &buffer
);
191 *minor_status
= kret
;
195 kret
= krb5_store_int32 (sp
, (*context_handle
)->flags
);
197 *minor_status
= kret
;
200 kret
= krb5_store_int32 (sp
, (*context_handle
)->more_flags
);
202 *minor_status
= kret
;
205 kret
= krb5_store_int32 (sp
, (*context_handle
)->lifetime
);
207 *minor_status
= kret
;
211 kret
= krb5_storage_to_data (sp
, &data
);
212 krb5_storage_free (sp
);
214 HEIMDAL_MUTEX_unlock(&(*context_handle
)->ctx_id_mutex
);
215 *minor_status
= kret
;
216 return GSS_S_FAILURE
;
218 interprocess_token
->length
= data
.length
;
219 interprocess_token
->value
= data
.data
;
220 HEIMDAL_MUTEX_unlock(&(*context_handle
)->ctx_id_mutex
);
221 ret
= gss_delete_sec_context (minor_status
, context_handle
,
223 if (ret
!= GSS_S_COMPLETE
)
224 gss_release_buffer (NULL
, interprocess_token
);
228 HEIMDAL_MUTEX_unlock(&(*context_handle
)->ctx_id_mutex
);
229 krb5_storage_free (sp
);