inquire_context.c revision 178826
197403Sobrien/*
297403Sobrien * Copyright (c) 1997, 2003 Kungliga Tekniska H�gskolan
397403Sobrien * (Royal Institute of Technology, Stockholm, Sweden).
497403Sobrien * All rights reserved.
597403Sobrien *
697403Sobrien * Redistribution and use in source and binary forms, with or without
797403Sobrien * modification, are permitted provided that the following conditions
897403Sobrien * are met:
997403Sobrien *
1097403Sobrien * 1. Redistributions of source code must retain the above copyright
1197403Sobrien *    notice, this list of conditions and the following disclaimer.
1297403Sobrien *
1397403Sobrien * 2. Redistributions in binary form must reproduce the above copyright
1497403Sobrien *    notice, this list of conditions and the following disclaimer in the
1597403Sobrien *    documentation and/or other materials provided with the distribution.
1697403Sobrien *
1797403Sobrien * 3. Neither the name of the Institute nor the names of its contributors
18169691Skan *    may be used to endorse or promote products derived from this software
1997403Sobrien *    without specific prior written permission.
2097403Sobrien *
2197403Sobrien * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
2297403Sobrien * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2397403Sobrien * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2497403Sobrien * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
2597403Sobrien * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2697403Sobrien * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2797403Sobrien * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2897403Sobrien * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2997403Sobrien * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3097403Sobrien * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3197403Sobrien * SUCH DAMAGE.
3297403Sobrien */
3397403Sobrien
3497403Sobrien#include "krb5/gsskrb5_locl.h"
3597403Sobrien
3697403SobrienRCSID("$Id: inquire_context.c 19031 2006-11-13 18:02:57Z lha $");
3797403Sobrien
3897403SobrienOM_uint32 _gsskrb5_inquire_context (
3997403Sobrien    OM_uint32 * minor_status,
4097403Sobrien	const gss_ctx_id_t context_handle,
4197403Sobrien	gss_name_t * src_name,
4297403Sobrien	gss_name_t * targ_name,
4397403Sobrien	OM_uint32 * lifetime_rec,
4497403Sobrien	gss_OID * mech_type,
4597403Sobrien	OM_uint32 * ctx_flags,
4697403Sobrien	int * locally_initiated,
4797403Sobrien	int * open_context
4897403Sobrien    )
4997403Sobrien{
5097403Sobrien    krb5_context context;
5197403Sobrien    OM_uint32 ret;
5297403Sobrien    gsskrb5_ctx ctx = (gsskrb5_ctx)context_handle;
5397403Sobrien    gss_name_t name;
5497403Sobrien
5597403Sobrien    if (src_name)
56169691Skan	*src_name = GSS_C_NO_NAME;
57169691Skan    if (targ_name)
5897403Sobrien	*targ_name = GSS_C_NO_NAME;
5997403Sobrien
60132720Skan    GSSAPI_KRB5_INIT (&context);
61132720Skan
6297403Sobrien    HEIMDAL_MUTEX_lock(&ctx->ctx_id_mutex);
6397403Sobrien
6497403Sobrien    if (src_name) {
6597403Sobrien	name = (gss_name_t)ctx->source;
6697403Sobrien	ret = _gsskrb5_duplicate_name (minor_status, name, src_name);
6797403Sobrien	if (ret)
6897403Sobrien	    goto failed;
69132720Skan    }
70132720Skan
71132720Skan    if (targ_name) {
7297403Sobrien	name = (gss_name_t)ctx->target;
73132720Skan	ret = _gsskrb5_duplicate_name (minor_status, name, targ_name);
74	if (ret)
75	    goto failed;
76    }
77
78    if (lifetime_rec) {
79	ret = _gsskrb5_lifetime_left(minor_status,
80				     context,
81				     ctx->lifetime,
82				     lifetime_rec);
83	if (ret)
84	    goto failed;
85    }
86
87    if (mech_type)
88	*mech_type = GSS_KRB5_MECHANISM;
89
90    if (ctx_flags)
91	*ctx_flags = ctx->flags;
92
93    if (locally_initiated)
94	*locally_initiated = ctx->more_flags & LOCAL;
95
96    if (open_context)
97	*open_context = ctx->more_flags & OPEN;
98
99    *minor_status = 0;
100
101    HEIMDAL_MUTEX_unlock(&ctx->ctx_id_mutex);
102    return GSS_S_COMPLETE;
103
104failed:
105    if (src_name)
106	_gsskrb5_release_name(NULL, src_name);
107    if (targ_name)
108	_gsskrb5_release_name(NULL, targ_name);
109
110    HEIMDAL_MUTEX_unlock(&ctx->ctx_id_mutex);
111    return ret;
112}
113