2 * Copyright (c) 1999 - 2000 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_import_sec_context (
40 OM_uint32
* minor_status
,
41 const gss_buffer_t interprocess_token
,
42 gss_ctx_id_t
* context_handle
45 OM_uint32 ret
= GSS_S_FAILURE
;
49 krb5_address local
, remote
;
50 krb5_address
*localp
, *remotep
;
52 gss_buffer_desc buffer
;
53 krb5_keyblock keyblock
;
60 sp
= krb5_storage_from_mem (interprocess_token
->value
,
61 interprocess_token
->length
);
63 *minor_status
= ENOMEM
;
67 *context_handle
= malloc(sizeof(**context_handle
));
68 if (*context_handle
== NULL
) {
69 *minor_status
= ENOMEM
;
70 krb5_storage_free (sp
);
74 kret
= krb5_auth_con_init (gssapi_krb5_context
,
75 &(*context_handle
)->auth_context
);
84 krb5_ret_int32 (sp
, &flags
);
86 /* retrieve the auth context */
88 ac
= (*context_handle
)->auth_context
;
89 krb5_ret_int32 (sp
, &ac
->flags
);
90 if (flags
& SC_LOCAL_ADDRESS
)
91 krb5_ret_address (sp
, localp
= &local
);
94 if (flags
& SC_REMOTE_ADDRESS
)
95 krb5_ret_address (sp
, remotep
= &remote
);
98 krb5_auth_con_setaddrs (gssapi_krb5_context
, ac
, localp
, remotep
);
100 krb5_free_address (gssapi_krb5_context
, localp
);
102 krb5_free_address (gssapi_krb5_context
, remotep
);
103 krb5_ret_int16 (sp
, &ac
->local_port
);
104 krb5_ret_int16 (sp
, &ac
->remote_port
);
105 if (flags
& SC_KEYBLOCK
) {
106 krb5_ret_keyblock (sp
, &keyblock
);
107 krb5_auth_con_setkey (gssapi_krb5_context
, ac
, &keyblock
);
108 krb5_free_keyblock_contents (gssapi_krb5_context
, &keyblock
);
110 if (flags
& SC_LOCAL_SUBKEY
) {
111 krb5_ret_keyblock (sp
, &keyblock
);
112 krb5_auth_con_setlocalsubkey (gssapi_krb5_context
, ac
, &keyblock
);
113 krb5_free_keyblock_contents (gssapi_krb5_context
, &keyblock
);
115 if (flags
& SC_REMOTE_SUBKEY
) {
116 krb5_ret_keyblock (sp
, &keyblock
);
117 krb5_auth_con_setremotesubkey (gssapi_krb5_context
, ac
, &keyblock
);
118 krb5_free_keyblock_contents (gssapi_krb5_context
, &keyblock
);
120 krb5_ret_int32 (sp
, &ac
->local_seqnumber
);
121 krb5_ret_int32 (sp
, &ac
->remote_seqnumber
);
124 krb5_ret_data (sp
, &data
);
125 ac
->authenticator
= malloc (sizeof (*ac
->authenticator
));
126 if (ac
->authenticator
== NULL
) {
127 *minor_status
= ENOMEM
;
132 kret
= decode_Authenticator (data
.data
, data
.length
,
133 ac
->authenticator
, &sz
);
134 krb5_data_free (&data
);
136 *minor_status
= kret
;
142 krb5_ret_int32 (sp
, &tmp
);
144 krb5_ret_int32 (sp
, &tmp
);
149 krb5_ret_data (sp
, &data
);
150 buffer
.value
= data
.data
;
151 buffer
.length
= data
.length
;
153 gss_import_name (minor_status
, &buffer
, GSS_C_NO_OID
,
154 &(*context_handle
)->source
);
155 krb5_data_free (&data
);
157 krb5_ret_data (sp
, &data
);
158 buffer
.value
= data
.data
;
159 buffer
.length
= data
.length
;
161 gss_import_name (minor_status
, &buffer
, GSS_C_NO_OID
,
162 &(*context_handle
)->target
);
163 krb5_data_free (&data
);
165 krb5_ret_int32 (sp
, &tmp
);
166 (*context_handle
)->flags
= tmp
;
167 krb5_ret_int32 (sp
, &tmp
);
168 (*context_handle
)->more_flags
= tmp
;
170 (*context_handle
)->ticket
= NULL
;
172 return GSS_S_COMPLETE
;
175 krb5_auth_con_free (gssapi_krb5_context
,
176 (*context_handle
)->auth_context
);
177 free (*context_handle
);
178 *context_handle
= GSS_C_NO_CONTEXT
;