1178828Sdfr/*
2178828Sdfr * Copyright (c) 2004, PADL Software Pty Ltd.
3178828Sdfr * All rights reserved.
4178828Sdfr *
5178828Sdfr * Redistribution and use in source and binary forms, with or without
6178828Sdfr * modification, are permitted provided that the following conditions
7178828Sdfr * are met:
8178828Sdfr *
9178828Sdfr * 1. Redistributions of source code must retain the above copyright
10178828Sdfr *    notice, this list of conditions and the following disclaimer.
11178828Sdfr *
12178828Sdfr * 2. Redistributions in binary form must reproduce the above copyright
13178828Sdfr *    notice, this list of conditions and the following disclaimer in the
14178828Sdfr *    documentation and/or other materials provided with the distribution.
15178828Sdfr *
16178828Sdfr * 3. Neither the name of PADL Software nor the names of its contributors
17178828Sdfr *    may be used to endorse or promote products derived from this software
18178828Sdfr *    without specific prior written permission.
19178828Sdfr *
20178828Sdfr * THIS SOFTWARE IS PROVIDED BY PADL SOFTWARE AND CONTRIBUTORS ``AS IS'' AND
21178828Sdfr * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22178828Sdfr * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23178828Sdfr * ARE DISCLAIMED.  IN NO EVENT SHALL PADL SOFTWARE OR CONTRIBUTORS BE LIABLE
24178828Sdfr * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25178828Sdfr * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26178828Sdfr * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27178828Sdfr * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28178828Sdfr * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29178828Sdfr * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30178828Sdfr * SUCH DAMAGE.
31178828Sdfr */
32178828Sdfr/* $FreeBSD$ */
33178828Sdfr/* RCSID("$Id: gss_set_sec_context_option.c 19928 2007-01-16 10:37:54Z lha $"); */
34178828Sdfr
35178828Sdfr#include <gssapi/gssapi.h>
36178828Sdfr
37178828Sdfr#include "mech_switch.h"
38178828Sdfr#include "context.h"
39178828Sdfr
40178828SdfrOM_uint32
41178828Sdfrgss_set_sec_context_option (OM_uint32 *minor_status,
42178828Sdfr			    gss_ctx_id_t *context_handle,
43178828Sdfr			    const gss_OID object,
44178828Sdfr			    const gss_buffer_t value)
45178828Sdfr{
46178828Sdfr	struct _gss_context	*ctx;
47178828Sdfr	OM_uint32		major_status;
48178828Sdfr	struct _gss_mech_switch	*m;
49178828Sdfr	int			one_ok = 0;
50178828Sdfr
51178828Sdfr	*minor_status = 0;
52178828Sdfr
53178828Sdfr	if (context_handle == NULL) {
54178828Sdfr		_gss_load_mech();
55178828Sdfr		major_status = GSS_S_BAD_MECH;
56178828Sdfr		SLIST_FOREACH(m, &_gss_mechs, gm_link) {
57178828Sdfr			if (!m->gm_set_sec_context_option)
58178828Sdfr				continue;
59178828Sdfr			major_status = m->gm_set_sec_context_option(
60178828Sdfr				minor_status,
61178828Sdfr				NULL, object, value);
62178828Sdfr			if (major_status == GSS_S_COMPLETE)
63178828Sdfr				one_ok = 1;
64178828Sdfr		}
65178828Sdfr		if (one_ok) {
66178828Sdfr			*minor_status = 0;
67178828Sdfr			return (GSS_S_COMPLETE);
68178828Sdfr		}
69178828Sdfr		return (major_status);
70178828Sdfr	}
71178828Sdfr
72178828Sdfr	ctx = (struct _gss_context *) *context_handle;
73178828Sdfr
74178828Sdfr	if (ctx == NULL)
75178828Sdfr		return (GSS_S_NO_CONTEXT);
76178828Sdfr
77178828Sdfr	m = ctx->gc_mech;
78178828Sdfr
79178828Sdfr	if (m == NULL)
80178828Sdfr		return (GSS_S_BAD_MECH);
81178828Sdfr
82178828Sdfr	if (m->gm_set_sec_context_option != NULL) {
83178828Sdfr		major_status = m->gm_set_sec_context_option(minor_status,
84178828Sdfr		    &ctx->gc_ctx, object, value);
85178828Sdfr		if (major_status != GSS_S_COMPLETE)
86178828Sdfr			_gss_mg_error(m, major_status, *minor_status);
87178828Sdfr	} else
88178828Sdfr		major_status = (GSS_S_BAD_MECH);
89178828Sdfr
90178828Sdfr	return (major_status);
91178828Sdfr}
92178828Sdfr
93