r19644: Merge up to current lorikeet-heimdal, incling adding
[Samba.git] / source / heimdal / lib / gssapi / krb5 / set_sec_context_option.c
blobdc1495efc1be1ee9215ef3157ab29240f3f7b7fc
1 /*
2 * Copyright (c) 2004, PADL Software Pty Ltd.
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of PADL Software nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY PADL SOFTWARE AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL PADL SOFTWARE OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
34 * glue routine for _gsskrb5_inquire_sec_context_by_oid
37 #include "krb5/gsskrb5_locl.h"
39 RCSID("$Id: set_sec_context_option.c,v 1.8 2006/11/08 23:06:42 lha Exp $");
41 static OM_uint32
42 get_bool(OM_uint32 *minor_status,
43 const gss_buffer_t value,
44 int *flag)
46 if (value->value == NULL || value->length != 1) {
47 *minor_status = EINVAL;
48 return GSS_S_FAILURE;
50 *flag = *((const char *)value->value) != 0;
51 return GSS_S_COMPLETE;
54 OM_uint32
55 _gsskrb5_set_sec_context_option
56 (OM_uint32 *minor_status,
57 gss_ctx_id_t *context_handle,
58 const gss_OID desired_object,
59 const gss_buffer_t value)
61 OM_uint32 maj_stat;
63 GSSAPI_KRB5_INIT ();
65 if (value == GSS_C_NO_BUFFER) {
66 *minor_status = EINVAL;
67 return GSS_S_FAILURE;
70 if (gss_oid_equal(desired_object, GSS_KRB5_COMPAT_DES3_MIC_X)) {
71 gsskrb5_ctx ctx;
72 int flag;
74 if (*context_handle == GSS_C_NO_CONTEXT) {
75 *minor_status = EINVAL;
76 return GSS_S_NO_CONTEXT;
79 maj_stat = get_bool(minor_status, value, &flag);
80 if (maj_stat != GSS_S_COMPLETE)
81 return maj_stat;
83 ctx = (gsskrb5_ctx)*context_handle;
84 HEIMDAL_MUTEX_lock(&ctx->ctx_id_mutex);
85 if (flag)
86 ctx->more_flags |= COMPAT_OLD_DES3;
87 else
88 ctx->more_flags &= ~COMPAT_OLD_DES3;
89 ctx->more_flags |= COMPAT_OLD_DES3_SELECTED;
90 HEIMDAL_MUTEX_unlock(&ctx->ctx_id_mutex);
91 return GSS_S_COMPLETE;
92 } else if (gss_oid_equal(desired_object, GSS_KRB5_SET_DNS_CANONICALIZE_X)) {
93 int flag;
95 maj_stat = get_bool(minor_status, value, &flag);
96 if (maj_stat != GSS_S_COMPLETE)
97 return maj_stat;
99 krb5_set_dns_canonicalize_hostname(_gsskrb5_context, flag);
100 return GSS_S_COMPLETE;
102 } else if (gss_oid_equal(desired_object, GSS_KRB5_REGISTER_ACCEPTOR_IDENTITY_X)) {
103 char *str;
105 if (value == NULL || value->length == 0) {
106 str = NULL;
107 } else {
108 str = malloc(value->length + 1);
109 if (str) {
110 *minor_status = 0;
111 return GSS_S_UNAVAILABLE;
113 memcpy(str, value->value, value->length);
114 str[value->length] = '\0';
117 _gsskrb5_register_acceptor_identity(str);
118 free(str);
120 *minor_status = 0;
121 return GSS_S_COMPLETE;
123 } else if (gss_oid_equal(desired_object, GSS_KRB5_SET_DEFAULT_REALM_X)) {
124 char *str;
126 if (value == NULL || value->length == 0) {
127 *minor_status = 0;
128 return GSS_S_CALL_INACCESSIBLE_READ;
130 str = malloc(value->length + 1);
131 if (str) {
132 *minor_status = 0;
133 return GSS_S_UNAVAILABLE;
135 memcpy(str, value->value, value->length);
136 str[value->length] = '\0';
138 krb5_set_default_realm(_gsskrb5_context, str);
139 free(str);
141 *minor_status = 0;
142 return GSS_S_COMPLETE;
144 } else if (gss_oid_equal(desired_object, GSS_KRB5_SEND_TO_KDC_X)) {
146 if (value == NULL || value->length == 0) {
147 krb5_set_send_to_kdc_func(_gsskrb5_context, NULL, NULL);
148 } else {
149 struct gsskrb5_send_to_kdc c;
151 if (value->length != sizeof(c)) {
152 *minor_status = EINVAL;
153 return GSS_S_FAILURE;
155 memcpy(&c, value->value, sizeof(c));
156 krb5_set_send_to_kdc_func(_gsskrb5_context,
157 (krb5_send_to_kdc_func)c.func,
158 c.ptr);
161 *minor_status = 0;
162 return GSS_S_COMPLETE;
166 *minor_status = EINVAL;
167 return GSS_S_FAILURE;