⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 accept_sec_context.c

📁 samba最新软件
💻 C
📖 第 1 页 / 共 2 页
字号:
	    ctx->verified_mic = 1;	}	if (buf.value)	    free(buf.value);    } else	*get_mic = verify_mic = 0;        return GSS_S_COMPLETE;}static OM_uint32acceptor_start	   (OM_uint32 * minor_status,	    gss_ctx_id_t * context_handle,	    const gss_cred_id_t acceptor_cred_handle,	    const gss_buffer_t input_token_buffer,	    const gss_channel_bindings_t input_chan_bindings,	    gss_name_t * src_name,	    gss_OID * mech_type,	    gss_buffer_t output_token,	    OM_uint32 * ret_flags,	    OM_uint32 * time_rec,	    gss_cred_id_t *delegated_cred_handle	   ){    OM_uint32 ret, junk;    NegotiationToken nt;    size_t nt_len;    NegTokenInit *ni;    int i;    gss_buffer_desc data;    gss_buffer_t mech_input_token = GSS_C_NO_BUFFER;    gss_buffer_desc mech_output_token;    gss_buffer_desc mech_buf;    gss_OID preferred_mech_type = GSS_C_NO_OID;    gssspnego_ctx ctx;    gssspnego_cred acceptor_cred = (gssspnego_cred)acceptor_cred_handle;    int get_mic = 0;    int first_ok = 0;    mech_output_token.value = NULL;    mech_output_token.length = 0;    mech_buf.value = NULL;    if (input_token_buffer->length == 0)	return send_supported_mechs (minor_status, output_token);	    ret = _gss_spnego_alloc_sec_context(minor_status, context_handle);    if (ret != GSS_S_COMPLETE)	return ret;    ctx = (gssspnego_ctx)*context_handle;    /*     * The GSS-API encapsulation is only present on the initial     * context token (negTokenInit).     */    ret = gss_decapsulate_token (input_token_buffer,				 GSS_SPNEGO_MECHANISM,				 &data);    if (ret)	return ret;    ret = decode_NegotiationToken(data.value, data.length, &nt, &nt_len);    gss_release_buffer(minor_status, &data);    if (ret) {	*minor_status = ret;	return GSS_S_DEFECTIVE_TOKEN;    }    if (nt.element != choice_NegotiationToken_negTokenInit) {	*minor_status = 0;	return GSS_S_DEFECTIVE_TOKEN;    }    ni = &nt.u.negTokenInit;    if (ni->mechTypes.len < 1) {	free_NegotiationToken(&nt);	*minor_status = 0;	return GSS_S_DEFECTIVE_TOKEN;    }    HEIMDAL_MUTEX_lock(&ctx->ctx_id_mutex);    ret = copy_MechTypeList(&ni->mechTypes, &ctx->initiator_mech_types);    if (ret) {	HEIMDAL_MUTEX_unlock(&ctx->ctx_id_mutex);	free_NegotiationToken(&nt);	*minor_status = ret;	return GSS_S_FAILURE;    }    /*     * First we try the opportunistic token if we have support for it,     * don't try to verify we have credential for the token,     * gss_accept_sec_context() will (hopefully) tell us that.     * If that failes,      */    ret = select_mech(minor_status,		      &ni->mechTypes.val[0], 		      0,		      &preferred_mech_type);    if (ret == 0 && ni->mechToken != NULL) {	gss_cred_id_t mech_delegated_cred = GSS_C_NO_CREDENTIAL;	gss_cred_id_t mech_cred;	gss_buffer_desc ibuf;	ibuf.length = ni->mechToken->length;	ibuf.value = ni->mechToken->data;	mech_input_token = &ibuf;	if (acceptor_cred != NULL)	    mech_cred = acceptor_cred->negotiated_cred_id;	else	    mech_cred = GSS_C_NO_CREDENTIAL;		if (ctx->mech_src_name != GSS_C_NO_NAME)	    gss_release_name(&junk, &ctx->mech_src_name);		if (ctx->delegated_cred_id != GSS_C_NO_CREDENTIAL)	    _gss_spnego_release_cred(&junk, &ctx->delegated_cred_id);		ret = gss_accept_sec_context(minor_status,				     &ctx->negotiated_ctx_id,				     mech_cred,				     mech_input_token,				     input_chan_bindings,				     &ctx->mech_src_name,				     &ctx->negotiated_mech_type,				     &mech_output_token,				     &ctx->mech_flags,				     &ctx->mech_time_rec,				     &mech_delegated_cred);	if (ret == GSS_S_COMPLETE || ret == GSS_S_CONTINUE_NEEDED) {	    ctx->preferred_mech_type = preferred_mech_type;	    ctx->negotiated_mech_type = preferred_mech_type;	    if (ret == GSS_S_COMPLETE)		ctx->open = 1;	    if (mech_delegated_cred && delegated_cred_handle)		ret = _gss_spnego_alloc_cred(&junk,					     mech_delegated_cred,					     delegated_cred_handle);	    else		gss_release_cred(&junk, &mech_delegated_cred);	    ret = acceptor_complete(minor_status,				    ctx,				    &get_mic,				    &mech_buf,				    mech_input_token,				    &mech_output_token,				    ni->mechListMIC,				    output_token);	    if (ret != GSS_S_COMPLETE)		goto out;	    first_ok = 1;	} else {	    gss_mg_collect_error(preferred_mech_type, ret, *minor_status);	}    }    /*     * If opportunistic token failed, lets try the other mechs.     */    if (!first_ok && ni->mechToken != NULL) {	preferred_mech_type = GSS_C_NO_OID;	/* Call glue layer to find first mech we support */	for (i = 1; i < ni->mechTypes.len; ++i) {	    ret = select_mech(minor_status,			      &ni->mechTypes.val[i],			      1,			      &preferred_mech_type);	    if (ret == 0)		break;	}	if (preferred_mech_type == GSS_C_NO_OID) {	    HEIMDAL_MUTEX_unlock(&ctx->ctx_id_mutex);	    free_NegotiationToken(&nt);	    return ret;	}	ctx->preferred_mech_type = preferred_mech_type;	ctx->negotiated_mech_type = preferred_mech_type;    }    /*     * The initial token always have a response     */    ret = send_accept (minor_status,		       ctx,		       &mech_output_token,		       1,		       get_mic ? &mech_buf : NULL,		       output_token);    if (ret)	goto out;    out:    if (mech_output_token.value != NULL)	gss_release_buffer(&junk, &mech_output_token);    if (mech_buf.value != NULL) {	free(mech_buf.value);	mech_buf.value = NULL;    }    free_NegotiationToken(&nt);    if (ret == GSS_S_COMPLETE) {	if (src_name != NULL && ctx->mech_src_name != NULL) {	    spnego_name name;	    name = calloc(1, sizeof(*name));	    if (name) {		name->mech = ctx->mech_src_name;		ctx->mech_src_name = NULL;		*src_name = (gss_name_t)name;	    }	}        if (delegated_cred_handle != NULL) {	    *delegated_cred_handle = ctx->delegated_cred_id;	    ctx->delegated_cred_id = GSS_C_NO_CREDENTIAL;	}    }        if (mech_type != NULL)	*mech_type = ctx->negotiated_mech_type;    if (ret_flags != NULL)	*ret_flags = ctx->mech_flags;    if (time_rec != NULL)	*time_rec = ctx->mech_time_rec;    if (ret == GSS_S_COMPLETE || ret == GSS_S_CONTINUE_NEEDED) {	HEIMDAL_MUTEX_unlock(&ctx->ctx_id_mutex); 	return ret;    }    _gss_spnego_internal_delete_sec_context(&junk, context_handle,					    GSS_C_NO_BUFFER);        return ret;}static OM_uint32acceptor_continue	   (OM_uint32 * minor_status,	    gss_ctx_id_t * context_handle,	    const gss_cred_id_t acceptor_cred_handle,	    const gss_buffer_t input_token_buffer,	    const gss_channel_bindings_t input_chan_bindings,	    gss_name_t * src_name,	    gss_OID * mech_type,	    gss_buffer_t output_token,	    OM_uint32 * ret_flags,	    OM_uint32 * time_rec,	    gss_cred_id_t *delegated_cred_handle	   ){    OM_uint32 ret, ret2, minor;    NegotiationToken nt;    size_t nt_len;    NegTokenResp *na;    unsigned int negResult = accept_incomplete;    gss_buffer_t mech_input_token = GSS_C_NO_BUFFER;    gss_buffer_t mech_output_token = GSS_C_NO_BUFFER;    gss_buffer_desc mech_buf;    gssspnego_ctx ctx;    gssspnego_cred acceptor_cred = (gssspnego_cred)acceptor_cred_handle;    mech_buf.value = NULL;    ctx = (gssspnego_ctx)*context_handle;    /*     * The GSS-API encapsulation is only present on the initial     * context token (negTokenInit).     */    ret = decode_NegotiationToken(input_token_buffer->value, 				  input_token_buffer->length,				  &nt, &nt_len);    if (ret) {	*minor_status = ret;	return GSS_S_DEFECTIVE_TOKEN;    }    if (nt.element != choice_NegotiationToken_negTokenResp) {	*minor_status = 0;	return GSS_S_DEFECTIVE_TOKEN;    }    na = &nt.u.negTokenResp;    if (na->negResult != NULL) {	negResult = *(na->negResult);    }    HEIMDAL_MUTEX_lock(&ctx->ctx_id_mutex);    {	gss_buffer_desc ibuf, obuf;	int require_mic, get_mic = 0;	int require_response;	heim_octet_string *mic;	if (na->responseToken != NULL) {	    ibuf.length = na->responseToken->length;	    ibuf.value = na->responseToken->data;	    mech_input_token = &ibuf;	} else {	    ibuf.value = NULL;	    ibuf.length = 0;	}	if (mech_input_token != GSS_C_NO_BUFFER) {	    gss_cred_id_t mech_cred;	    gss_cred_id_t mech_delegated_cred;	    gss_cred_id_t *mech_delegated_cred_p;	    if (acceptor_cred != NULL)		mech_cred = acceptor_cred->negotiated_cred_id;	    else		mech_cred = GSS_C_NO_CREDENTIAL;	    if (delegated_cred_handle != NULL) {		mech_delegated_cred = GSS_C_NO_CREDENTIAL;		mech_delegated_cred_p = &mech_delegated_cred;	    } else {		mech_delegated_cred_p = NULL;	    }	    if (ctx->mech_src_name != GSS_C_NO_NAME)		gss_release_name(&minor, &ctx->mech_src_name);	    if (ctx->delegated_cred_id != GSS_C_NO_CREDENTIAL)		_gss_spnego_release_cred(&minor, &ctx->delegated_cred_id);	    ret = gss_accept_sec_context(&minor,					 &ctx->negotiated_ctx_id,					 mech_cred,					 mech_input_token,					 input_chan_bindings,					 &ctx->mech_src_name,					 &ctx->negotiated_mech_type,					 &obuf,					 &ctx->mech_flags,					 &ctx->mech_time_rec,					 mech_delegated_cred_p);	    if (ret == GSS_S_COMPLETE || ret == GSS_S_CONTINUE_NEEDED) {		if (mech_delegated_cred_p != NULL &&		    mech_delegated_cred != GSS_C_NO_CREDENTIAL) {		    ret2 = _gss_spnego_alloc_cred(minor_status,						  mech_delegated_cred,						  &ctx->delegated_cred_id);		    if (ret2 != GSS_S_COMPLETE)			ret = ret2;		}		mech_output_token = &obuf;	    }	    if (ret != GSS_S_COMPLETE && ret != GSS_S_CONTINUE_NEEDED) {		free_NegotiationToken(&nt);		gss_mg_collect_error(ctx->negotiated_mech_type, ret, minor);		send_reject (minor_status, output_token);		HEIMDAL_MUTEX_unlock(&ctx->ctx_id_mutex);		return ret;	    }	    if (ret == GSS_S_COMPLETE)		ctx->open = 1;	} else	    ret = GSS_S_COMPLETE;	ret2 = _gss_spnego_require_mechlist_mic(minor_status, 						ctx,						&require_mic);	if (ret2)	    goto out;	ctx->require_mic = require_mic;	mic = na->mechListMIC;	if (mic != NULL)	    require_mic = 1;	if (ret == GSS_S_COMPLETE)	    ret = acceptor_complete(minor_status,				    ctx,				    &get_mic,				    &mech_buf,				    mech_input_token,				    mech_output_token,				    na->mechListMIC,				    output_token);	if (ctx->mech_flags & GSS_C_DCE_STYLE)	    require_response = (negResult != accept_completed);	else	    require_response = 0;	/*	 * Check whether we need to send a result: there should be only	 * one accept_completed response sent in the entire negotiation	 */	if ((mech_output_token != GSS_C_NO_BUFFER &&	     mech_output_token->length != 0)	    || (ctx->open && negResult == accept_incomplete)	    || require_response	    || get_mic) {	    ret2 = send_accept (minor_status,				ctx,				mech_output_token,				0,				get_mic ? &mech_buf : NULL,				output_token);	    if (ret2)		goto out;	}     out:	if (ret2 != GSS_S_COMPLETE)	    ret = ret2;	if (mech_output_token != NULL)	    gss_release_buffer(&minor, mech_output_token);	if (mech_buf.value != NULL)	    free(mech_buf.value);	free_NegotiationToken(&nt);    }    if (ret == GSS_S_COMPLETE) {	if (src_name != NULL && ctx->mech_src_name != NULL) {	    spnego_name name;	    name = calloc(1, sizeof(*name));	    if (name) {		name->mech = ctx->mech_src_name;		ctx->mech_src_name = NULL;		*src_name = (gss_name_t)name;	    }	}        if (delegated_cred_handle != NULL) {	    *delegated_cred_handle = ctx->delegated_cred_id;	    ctx->delegated_cred_id = GSS_C_NO_CREDENTIAL;	}    }    if (mech_type != NULL)	*mech_type = ctx->negotiated_mech_type;    if (ret_flags != NULL)	*ret_flags = ctx->mech_flags;    if (time_rec != NULL)	*time_rec = ctx->mech_time_rec;    if (ret == GSS_S_COMPLETE || ret == GSS_S_CONTINUE_NEEDED) {	HEIMDAL_MUTEX_unlock(&ctx->ctx_id_mutex); 	return ret;    }    _gss_spnego_internal_delete_sec_context(&minor, context_handle,				   GSS_C_NO_BUFFER);    return ret;}OM_uint32_gss_spnego_accept_sec_context	   (OM_uint32 * minor_status,	    gss_ctx_id_t * context_handle,	    const gss_cred_id_t acceptor_cred_handle,	    const gss_buffer_t input_token_buffer,	    const gss_channel_bindings_t input_chan_bindings,	    gss_name_t * src_name,	    gss_OID * mech_type,	    gss_buffer_t output_token,	    OM_uint32 * ret_flags,	    OM_uint32 * time_rec,	    gss_cred_id_t *delegated_cred_handle	   ){    _gss_accept_sec_context_t *func;    *minor_status = 0;    output_token->length = 0;    output_token->value  = NULL;    if (src_name != NULL)	*src_name = GSS_C_NO_NAME;    if (mech_type != NULL)	*mech_type = GSS_C_NO_OID;    if (ret_flags != NULL)	*ret_flags = 0;    if (time_rec != NULL)	*time_rec = 0;    if (delegated_cred_handle != NULL)	*delegated_cred_handle = GSS_C_NO_CREDENTIAL;    if (*context_handle == GSS_C_NO_CONTEXT) 	func = acceptor_start;    else	func = acceptor_continue;        return (*func)(minor_status, context_handle, acceptor_cred_handle,		   input_token_buffer, input_chan_bindings,		   src_name, mech_type, output_token, ret_flags,		   time_rec, delegated_cred_handle);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -