g_init_sec_context.c [plain text]
#include "mglueP.h"
#include <stdio.h>
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#include <string.h>
#define g_OID_equal(o1,o2) \
(((o1)->length == (o2)->length) && \
(memcmp((o1)->elements,(o2)->elements,(int) (o1)->length) == 0))
OM_uint32 KRB5_CALLCONV
gss_init_sec_context (minor_status,
claimant_cred_handle,
context_handle,
target_name,
req_mech_type,
req_flags,
time_req,
input_chan_bindings,
input_token,
actual_mech_type,
output_token,
ret_flags,
time_rec)
OM_uint32 * minor_status;
gss_cred_id_t claimant_cred_handle;
gss_ctx_id_t * context_handle;
gss_name_t target_name;
gss_OID req_mech_type;
OM_uint32 req_flags;
OM_uint32 time_req;
gss_channel_bindings_t input_chan_bindings;
gss_buffer_t input_token;
gss_OID * actual_mech_type;
gss_buffer_t output_token;
OM_uint32 * ret_flags;
OM_uint32 * time_rec;
{
OM_uint32 status, temp_status, temp_minor_status;
gss_union_name_t union_name;
gss_union_cred_t union_cred;
gss_name_t internal_name;
gss_union_ctx_id_t union_ctx_id;
gss_OID mech_type = (gss_OID) req_mech_type;
gss_mechanism mech;
gss_cred_id_t input_cred_handle;
gss_initialize();
if (context_handle == NULL)
return GSS_S_NO_CONTEXT;
union_name = (gss_union_name_t) target_name;
if ((mech_type == GSS_C_NULL_OID) && union_name->mech_type)
mech_type = union_name->mech_type;
mech = __gss_get_mechanism (mech_type);
if (mech == NULL)
return (GSS_S_BAD_MECH);
if (mech_type == GSS_C_NULL_OID)
mech_type = &mech->mech_type;
if (union_name->mech_type) {
if (!g_OID_equal(union_name->mech_type, mech_type))
return (GSS_S_BAD_MECH);
internal_name = union_name->mech_name;
} else {
if ((temp_status = __gss_import_internal_name(minor_status, mech_type,
union_name,
&internal_name)))
return (GSS_S_BAD_NAME);
}
if(*context_handle == GSS_C_NO_CONTEXT) {
union_ctx_id = (gss_union_ctx_id_t)
malloc(sizeof(gss_union_ctx_id_desc));
union_ctx_id->mech_type = (gss_OID)
malloc(sizeof(gss_OID_desc));
union_ctx_id->mech_type->elements = (void *)
malloc(mech_type->length);
union_ctx_id->mech_type->length = mech_type->length;
memcpy(union_ctx_id->mech_type->elements, mech_type->elements,
mech_type->length);
union_ctx_id->internal_ctx_id = *context_handle;
} else
union_ctx_id = *context_handle;
union_cred = (gss_union_cred_t) claimant_cred_handle;
input_cred_handle = __gss_get_mechanism_cred(union_cred, mech_type);
if (mech->gss_init_sec_context) {
status = mech->gss_init_sec_context(
mech->context,
minor_status,
input_cred_handle,
&union_ctx_id->internal_ctx_id,
internal_name,
mech_type,
req_flags,
time_req,
input_chan_bindings,
input_token,
actual_mech_type,
output_token,
ret_flags,
time_rec);
if (*context_handle == GSS_C_NO_CONTEXT)
*context_handle = (gss_ctx_id_t) union_ctx_id;
} else
status = GSS_S_BAD_BINDINGS;
if (!union_name->mech_type) {
(void) __gss_release_internal_name(&temp_minor_status,
mech_type, &internal_name);
}
return(status);
}