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 gss_export_sec_context
31 #include <mechglueP.h>
32 #include "gssapiP_generic.h"
40 OM_uint32
*minor_status
,
41 gss_buffer_t interprocess_token
,
42 gss_ctx_id_t
*context_handle
)
45 /* Initialize outputs. */
46 if (minor_status
!= NULL
)
49 if (context_handle
!= NULL
)
50 *context_handle
= GSS_C_NO_CONTEXT
;
52 /* Validate arguments. */
54 if (minor_status
== NULL
)
55 return (GSS_S_CALL_INACCESSIBLE_WRITE
);
57 if (context_handle
== NULL
)
58 return (GSS_S_CALL_INACCESSIBLE_WRITE
);
60 if (interprocess_token
== GSS_C_NO_BUFFER
)
61 return (GSS_S_CALL_INACCESSIBLE_READ
| GSS_S_DEFECTIVE_TOKEN
);
63 if (GSS_EMPTY_BUFFER(interprocess_token
))
64 return (GSS_S_CALL_INACCESSIBLE_READ
| GSS_S_DEFECTIVE_TOKEN
);
66 return (GSS_S_COMPLETE
);
70 gss_import_sec_context(minor_status
,
74 OM_uint32
* minor_status
;
75 const gss_buffer_t interprocess_token
;
76 gss_ctx_id_t
*context_handle
;
82 gss_union_ctx_id_t ctx
;
83 gss_buffer_desc token
;
86 status
= val_imp_sec_ctx_args(minor_status
,
87 interprocess_token
, context_handle
);
88 if (status
!= GSS_S_COMPLETE
)
91 /* Initial value needed below. */
92 status
= GSS_S_FAILURE
;
94 ctx
= (gss_union_ctx_id_t
)malloc(sizeof (gss_union_ctx_id_desc
));
96 return (GSS_S_FAILURE
);
98 ctx
->mech_type
= (gss_OID
) malloc(sizeof (gss_OID_desc
));
99 if (!ctx
->mech_type
) {
101 return (GSS_S_FAILURE
);
104 if (interprocess_token
->length
>= sizeof (OM_uint32
)) {
105 p
= interprocess_token
->value
;
106 length
= (OM_uint32
)*p
++;
107 length
= (OM_uint32
)(length
<< 8) + *p
++;
108 length
= (OM_uint32
)(length
<< 8) + *p
++;
109 length
= (OM_uint32
)(length
<< 8) + *p
++;
113 length
> (interprocess_token
->length
- sizeof (OM_uint32
))) {
115 return (GSS_S_CALL_BAD_STRUCTURE
| GSS_S_DEFECTIVE_TOKEN
);
118 ctx
->mech_type
->length
= length
;
119 ctx
->mech_type
->elements
= malloc(length
);
120 if (!ctx
->mech_type
->elements
) {
123 (void) memcpy(ctx
->mech_type
->elements
, p
, length
);
126 token
.length
= interprocess_token
->length
- sizeof (OM_uint32
) - length
;
130 * select the approprate underlying mechanism routine and
134 mech
= __gss_get_mechanism(ctx
->mech_type
);
136 status
= GSS_S_BAD_MECH
;
139 if (!mech
->gss_import_sec_context
) {
140 status
= GSS_S_UNAVAILABLE
;
144 status
= mech
->gss_import_sec_context(mech
->context
, minor_status
,
145 &token
, &ctx
->internal_ctx_id
);
147 if (status
== GSS_S_COMPLETE
) {
148 *context_handle
= (gss_ctx_id_t
)ctx
;
149 return (GSS_S_COMPLETE
);
151 map_error(minor_status
, mech
);
155 if (ctx
->mech_type
) {
156 if (ctx
->mech_type
->elements
)
157 free(ctx
->mech_type
->elements
);
158 free(ctx
->mech_type
);
164 #endif /* LEAN_CLIENT */