1226031Sstas/*-
2226031Sstas * Copyright (c) 2005 Doug Rabson
3226031Sstas * All rights reserved.
4226031Sstas *
5226031Sstas * Redistribution and use in source and binary forms, with or without
6226031Sstas * modification, are permitted provided that the following conditions
7226031Sstas * are met:
8226031Sstas * 1. Redistributions of source code must retain the above copyright
9226031Sstas *    notice, this list of conditions and the following disclaimer.
10226031Sstas * 2. Redistributions in binary form must reproduce the above copyright
11226031Sstas *    notice, this list of conditions and the following disclaimer in the
12226031Sstas *    documentation and/or other materials provided with the distribution.
13226031Sstas *
14226031Sstas * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15226031Sstas * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16226031Sstas * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17226031Sstas * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18226031Sstas * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19226031Sstas * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20226031Sstas * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21226031Sstas * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22226031Sstas * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23226031Sstas * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24226031Sstas * SUCH DAMAGE.
25226031Sstas *
26226031Sstas *	$FreeBSD: src/lib/libgssapi/gss_inquire_context.c,v 1.1 2005/12/29 14:40:20 dfr Exp $
27226031Sstas */
28226031Sstas
29226031Sstas#include "mech_locl.h"
30226031Sstas
31226031SstasGSSAPI_LIB_FUNCTION OM_uint32 GSSAPI_LIB_CALL
32226031Sstasgss_inquire_context(OM_uint32 *minor_status,
33226031Sstas    const gss_ctx_id_t context_handle,
34226031Sstas    gss_name_t *src_name,
35226031Sstas    gss_name_t *targ_name,
36226031Sstas    OM_uint32 *lifetime_rec,
37226031Sstas    gss_OID *mech_type,
38226031Sstas    OM_uint32 *ctx_flags,
39226031Sstas    int *locally_initiated,
40226031Sstas    int *xopen)
41226031Sstas{
42226031Sstas	OM_uint32 major_status;
43226031Sstas	struct _gss_context *ctx = (struct _gss_context *) context_handle;
44226031Sstas	gssapi_mech_interface m = ctx->gc_mech;
45226031Sstas	struct _gss_name *name;
46226031Sstas	gss_name_t src_mn, targ_mn;
47226031Sstas
48226031Sstas	if (locally_initiated)
49226031Sstas	    *locally_initiated = 0;
50226031Sstas	if (xopen)
51226031Sstas	    *xopen = 0;
52226031Sstas	if (lifetime_rec)
53226031Sstas	    *lifetime_rec = 0;
54226031Sstas
55226031Sstas	if (src_name)
56226031Sstas	    *src_name = GSS_C_NO_NAME;
57226031Sstas	if (targ_name)
58226031Sstas	    *targ_name = GSS_C_NO_NAME;
59226031Sstas	if (mech_type)
60226031Sstas	    *mech_type = GSS_C_NO_OID;
61226031Sstas	src_mn = targ_mn = GSS_C_NO_NAME;
62226031Sstas
63226031Sstas	major_status = m->gm_inquire_context(minor_status,
64226031Sstas	    ctx->gc_ctx,
65226031Sstas	    src_name ? &src_mn : NULL,
66226031Sstas	    targ_name ? &targ_mn : NULL,
67226031Sstas	    lifetime_rec,
68226031Sstas	    mech_type,
69226031Sstas	    ctx_flags,
70226031Sstas	    locally_initiated,
71226031Sstas	    xopen);
72226031Sstas
73226031Sstas	if (major_status != GSS_S_COMPLETE) {
74226031Sstas		_gss_mg_error(m, major_status, *minor_status);
75226031Sstas		return (major_status);
76226031Sstas	}
77226031Sstas
78226031Sstas	if (src_name) {
79226031Sstas		name = _gss_make_name(m, src_mn);
80226031Sstas		if (!name) {
81226031Sstas			if (mech_type)
82226031Sstas				*mech_type = GSS_C_NO_OID;
83226031Sstas			m->gm_release_name(minor_status, &src_mn);
84226031Sstas			*minor_status = 0;
85226031Sstas			return (GSS_S_FAILURE);
86226031Sstas		}
87226031Sstas		*src_name = (gss_name_t) name;
88226031Sstas	}
89226031Sstas
90226031Sstas	if (targ_name) {
91226031Sstas		name = _gss_make_name(m, targ_mn);
92226031Sstas		if (!name) {
93226031Sstas			if (mech_type)
94226031Sstas				*mech_type = GSS_C_NO_OID;
95226031Sstas			if (src_name)
96226031Sstas				gss_release_name(minor_status, src_name);
97226031Sstas			m->gm_release_name(minor_status, &targ_mn);
98226031Sstas			*minor_status = 0;
99226031Sstas			return (GSS_S_FAILURE);
100226031Sstas		}
101226031Sstas		*targ_name = (gss_name_t) name;
102226031Sstas	}
103226031Sstas
104226031Sstas	return (GSS_S_COMPLETE);
105226031Sstas}
106