4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
26 * glue routine for gss_export_sec_context
30 #include <mechglueP.h>
31 #include "gssapiP_generic.h"
39 static OM_uint32
val_exp_sec_ctx_args(
40 OM_uint32
*minor_status
,
41 gss_ctx_id_t
*context_handle
,
42 gss_buffer_t interprocess_token
)
45 /* Initialize outputs. */
47 if (minor_status
!= NULL
)
50 if (interprocess_token
!= GSS_C_NO_BUFFER
) {
51 interprocess_token
->length
= 0;
52 interprocess_token
->value
= NULL
;
55 /* Validate arguments. */
57 if (minor_status
== NULL
)
58 return (GSS_S_CALL_INACCESSIBLE_WRITE
);
60 if (context_handle
== NULL
|| *context_handle
== GSS_C_NO_CONTEXT
)
61 return (GSS_S_CALL_INACCESSIBLE_READ
| GSS_S_NO_CONTEXT
);
63 if (interprocess_token
== GSS_C_NO_BUFFER
)
64 return (GSS_S_CALL_INACCESSIBLE_WRITE
);
66 return (GSS_S_COMPLETE
);
70 gss_export_sec_context(minor_status
,
74 OM_uint32
*minor_status
;
75 gss_ctx_id_t
*context_handle
;
76 gss_buffer_t interprocess_token
;
81 gss_union_ctx_id_t ctx
;
83 gss_buffer_desc token
;
86 status
= val_exp_sec_ctx_args(minor_status
,
87 context_handle
, interprocess_token
);
88 if (status
!= GSS_S_COMPLETE
)
92 * select the approprate underlying mechanism routine and
96 ctx
= (gss_union_ctx_id_t
)*context_handle
;
97 mech
= __gss_get_mechanism(ctx
->mech_type
);
99 return (GSS_S_BAD_MECH
);
100 if (!mech
->gss_export_sec_context
)
101 return (GSS_S_UNAVAILABLE
);
103 status
= mech
->gss_export_sec_context(mech
->context
, minor_status
,
104 &ctx
->internal_ctx_id
, &token
);
105 if (status
!= GSS_S_COMPLETE
) {
106 map_error(minor_status
, mech
);
110 length
= token
.length
+ 4 + ctx
->mech_type
->length
;
111 interprocess_token
->length
= length
;
112 interprocess_token
->value
= malloc(length
);
113 if (interprocess_token
->value
== 0) {
114 (void) gss_release_buffer(minor_status
, &token
);
115 return (GSS_S_FAILURE
);
117 buf
= interprocess_token
->value
;
118 length
= ctx
->mech_type
->length
;
119 buf
[3] = (unsigned char) (length
& 0xFF);
121 buf
[2] = (unsigned char) (length
& 0xFF);
123 buf
[1] = (unsigned char) (length
& 0xFF);
125 buf
[0] = (unsigned char) (length
& 0xFF);
126 (void) memcpy(buf
+4, ctx
->mech_type
->elements
,
127 (size_t)ctx
->mech_type
->length
);
128 (void) memcpy(buf
+4+ctx
->mech_type
->length
, token
.value
, token
.length
);
130 (void) gss_release_buffer(minor_status
, &token
);
132 free(ctx
->mech_type
->elements
);
133 free(ctx
->mech_type
);
137 return (GSS_S_COMPLETE
);
139 #endif /*LEAN_CLIENT */