2 * Copyright (c) 1997, 1998, 1999 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"
38 static krb5_keytab gss_keytab
;
41 gsskrb5_register_acceptor_identity (char *identity
)
44 if(gss_keytab
!= NULL
) {
45 krb5_kt_close(gssapi_krb5_context
, gss_keytab
);
48 asprintf(&p
, "FILE:%s", identity
);
51 krb5_kt_resolve(gssapi_krb5_context
, p
, &gss_keytab
);
53 return GSS_S_COMPLETE
;
56 OM_uint32 gss_accept_sec_context
57 (OM_uint32
* minor_status
,
58 gss_ctx_id_t
* context_handle
,
59 const gss_cred_id_t acceptor_cred_handle
,
60 const gss_buffer_t input_token_buffer
,
61 const gss_channel_bindings_t input_chan_bindings
,
62 gss_name_t
* src_name
,
64 gss_buffer_t output_token
,
65 OM_uint32
* ret_flags
,
67 gss_cred_id_t
* delegated_cred_handle
73 krb5_flags ap_options
;
75 krb5_ticket
*ticket
= NULL
;
76 krb5_keytab keytab
= NULL
;
80 if (*context_handle
== GSS_C_NO_CONTEXT
) {
81 *context_handle
= malloc(sizeof(**context_handle
));
82 if (*context_handle
== GSS_C_NO_CONTEXT
) {
83 *minor_status
= ENOMEM
;
88 (*context_handle
)->auth_context
= NULL
;
89 (*context_handle
)->source
= NULL
;
90 (*context_handle
)->target
= NULL
;
91 (*context_handle
)->flags
= 0;
92 (*context_handle
)->more_flags
= 0;
93 (*context_handle
)->ticket
= NULL
;
95 kret
= krb5_auth_con_init (gssapi_krb5_context
,
96 &(*context_handle
)->auth_context
);
105 krb5_auth_con_getflags(gssapi_krb5_context
,
106 (*context_handle
)->auth_context
,
108 tmp
|= KRB5_AUTH_CONTEXT_DO_SEQUENCE
;
109 krb5_auth_con_setflags(gssapi_krb5_context
,
110 (*context_handle
)->auth_context
,
114 ret
= gssapi_krb5_decapsulate (input_token_buffer
,
122 if (acceptor_cred_handle
== GSS_C_NO_CREDENTIAL
) {
123 if (gss_keytab
!= NULL
) {
126 } else if (acceptor_cred_handle
->keytab
!= NULL
) {
127 keytab
= acceptor_cred_handle
->keytab
;
130 kret
= krb5_rd_req (gssapi_krb5_context
,
131 &(*context_handle
)->auth_context
,
133 (acceptor_cred_handle
== GSS_C_NO_CREDENTIAL
) ? NULL
134 : acceptor_cred_handle
->principal
,
143 kret
= krb5_copy_principal (gssapi_krb5_context
,
145 &(*context_handle
)->source
);
152 kret
= krb5_copy_principal (gssapi_krb5_context
,
162 krb5_authenticator authenticator
;
164 kret
= krb5_auth_getauthenticator(gssapi_krb5_context
,
165 (*context_handle
)->auth_context
,
172 kret
= gssapi_krb5_verify_8003_checksum(input_chan_bindings
,
173 authenticator
->cksum
,
175 krb5_free_authenticator(gssapi_krb5_context
, &authenticator
);
184 (*context_handle
)->flags
= flags
;
185 (*context_handle
)->more_flags
|= OPEN
;
188 *mech_type
= GSS_KRB5_MECHANISM
;
191 *time_rec
= GSS_C_INDEFINITE
;
193 if(flags
& GSS_C_MUTUAL_FLAG
) {
196 kret
= krb5_mk_rep (gssapi_krb5_context
,
197 &(*context_handle
)->auth_context
,
200 krb5_data_free (&outbuf
);
204 ret
= gssapi_krb5_encapsulate (&outbuf
,
212 output_token
->length
= 0;
215 (*context_handle
)->ticket
= ticket
;
219 krb5_free_ticket (context
, ticket
);
222 return GSS_S_COMPLETE
;
226 krb5_free_ticket (gssapi_krb5_context
, ticket
);
227 krb5_auth_con_free (gssapi_krb5_context
,
228 (*context_handle
)->auth_context
);
229 if((*context_handle
)->source
)
230 krb5_free_principal (gssapi_krb5_context
,
231 (*context_handle
)->source
);
232 if((*context_handle
)->target
)
233 krb5_free_principal (gssapi_krb5_context
,
234 (*context_handle
)->target
);
235 free (*context_handle
);
236 *context_handle
= GSS_C_NO_CONTEXT
;
237 *minor_status
= kret
;
238 return GSS_S_FAILURE
;