2 * Copyright (c) 1999 - 2001 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
);
73 memset (*context_handle
, 0, sizeof(**context_handle
));
75 kret
= krb5_auth_con_init (gssapi_krb5_context
,
76 &(*context_handle
)->auth_context
);
78 gssapi_krb5_set_error_string ();
86 krb5_ret_int32 (sp
, &flags
);
88 /* retrieve the auth context */
90 ac
= (*context_handle
)->auth_context
;
91 krb5_ret_int32 (sp
, &ac
->flags
);
92 if (flags
& SC_LOCAL_ADDRESS
)
93 krb5_ret_address (sp
, localp
= &local
);
96 if (flags
& SC_REMOTE_ADDRESS
)
97 krb5_ret_address (sp
, remotep
= &remote
);
100 krb5_auth_con_setaddrs (gssapi_krb5_context
, ac
, localp
, remotep
);
102 krb5_free_address (gssapi_krb5_context
, localp
);
104 krb5_free_address (gssapi_krb5_context
, remotep
);
105 krb5_ret_int16 (sp
, &ac
->local_port
);
106 krb5_ret_int16 (sp
, &ac
->remote_port
);
107 if (flags
& SC_KEYBLOCK
) {
108 krb5_ret_keyblock (sp
, &keyblock
);
109 krb5_auth_con_setkey (gssapi_krb5_context
, ac
, &keyblock
);
110 krb5_free_keyblock_contents (gssapi_krb5_context
, &keyblock
);
112 if (flags
& SC_LOCAL_SUBKEY
) {
113 krb5_ret_keyblock (sp
, &keyblock
);
114 krb5_auth_con_setlocalsubkey (gssapi_krb5_context
, ac
, &keyblock
);
115 krb5_free_keyblock_contents (gssapi_krb5_context
, &keyblock
);
117 if (flags
& SC_REMOTE_SUBKEY
) {
118 krb5_ret_keyblock (sp
, &keyblock
);
119 krb5_auth_con_setremotesubkey (gssapi_krb5_context
, ac
, &keyblock
);
120 krb5_free_keyblock_contents (gssapi_krb5_context
, &keyblock
);
122 krb5_ret_int32 (sp
, &ac
->local_seqnumber
);
123 krb5_ret_int32 (sp
, &ac
->remote_seqnumber
);
129 krb5_ret_data (sp
, &data
);
130 ac
->authenticator
= malloc (sizeof (*ac
->authenticator
));
131 if (ac
->authenticator
== NULL
) {
132 *minor_status
= ENOMEM
;
137 kret
= decode_Authenticator (data
.data
, data
.length
,
138 ac
->authenticator
, &sz
);
139 krb5_data_free (&data
);
141 *minor_status
= kret
;
148 krb5_ret_int32 (sp
, &tmp
);
150 krb5_ret_int32 (sp
, &tmp
);
155 krb5_ret_data (sp
, &data
);
156 buffer
.value
= data
.data
;
157 buffer
.length
= data
.length
;
159 ret
= gss_import_name (minor_status
, &buffer
, GSS_C_NO_OID
,
160 &(*context_handle
)->source
);
161 krb5_data_free (&data
);
165 krb5_ret_data (sp
, &data
);
166 buffer
.value
= data
.data
;
167 buffer
.length
= data
.length
;
169 ret
= gss_import_name (minor_status
, &buffer
, GSS_C_NO_OID
,
170 &(*context_handle
)->target
);
171 krb5_data_free (&data
);
175 krb5_ret_int32 (sp
, &tmp
);
176 (*context_handle
)->flags
= tmp
;
177 krb5_ret_int32 (sp
, &tmp
);
178 (*context_handle
)->more_flags
= tmp
;
180 return GSS_S_COMPLETE
;
183 krb5_auth_con_free (gssapi_krb5_context
,
184 (*context_handle
)->auth_context
);
185 if ((*context_handle
)->source
!= NULL
)
186 gss_release_name(&minor
, &(*context_handle
)->source
);
187 if ((*context_handle
)->target
!= NULL
)
188 gss_release_name(&minor
, &(*context_handle
)->target
);
189 free (*context_handle
);
190 *context_handle
= GSS_C_NO_CONTEXT
;