1 /* $NetBSD: set_cred_option.c,v 1.1.1.2 2014/04/24 12:45:29 pettai Exp $ */
4 * Copyright (c) 2004, PADL Software Pty Ltd.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of PADL Software nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY PADL SOFTWARE AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL PADL SOFTWARE OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 #include "gsskrb5_locl.h"
38 import_cred(OM_uint32
*minor_status
,
40 gss_cred_id_t
*cred_handle
,
41 const gss_buffer_t value
)
45 krb5_principal keytab_principal
= NULL
;
46 krb5_keytab keytab
= NULL
;
47 krb5_storage
*sp
= NULL
;
48 krb5_ccache id
= NULL
;
51 if (cred_handle
== NULL
|| *cred_handle
!= GSS_C_NO_CREDENTIAL
) {
56 sp
= krb5_storage_from_mem(value
->value
, value
->length
);
62 /* credential cache name */
63 ret
= krb5_ret_string(sp
, &str
);
66 major_stat
= GSS_S_FAILURE
;
70 ret
= krb5_cc_resolve(context
, str
, &id
);
73 major_stat
= GSS_S_FAILURE
;
80 /* keytab principal name */
81 ret
= krb5_ret_string(sp
, &str
);
82 if (ret
== 0 && str
[0])
83 ret
= krb5_parse_name(context
, str
, &keytab_principal
);
86 major_stat
= GSS_S_FAILURE
;
92 /* keytab principal */
93 ret
= krb5_ret_string(sp
, &str
);
96 major_stat
= GSS_S_FAILURE
;
100 ret
= krb5_kt_resolve(context
, str
, &keytab
);
103 major_stat
= GSS_S_FAILURE
;
110 major_stat
= _gsskrb5_krb5_import_cred(minor_status
, id
, keytab_principal
,
111 keytab
, cred_handle
);
114 krb5_cc_close(context
, id
);
115 if (keytab_principal
)
116 krb5_free_principal(context
, keytab_principal
);
118 krb5_kt_close(context
, keytab
);
122 krb5_storage_free(sp
);
129 allowed_enctypes(OM_uint32
*minor_status
,
130 krb5_context context
,
131 gss_cred_id_t
*cred_handle
,
132 const gss_buffer_t value
)
134 OM_uint32 major_stat
;
137 krb5_enctype
*enctypes
= NULL
;
138 krb5_storage
*sp
= NULL
;
141 if (cred_handle
== NULL
|| *cred_handle
== GSS_C_NO_CREDENTIAL
) {
143 return GSS_S_FAILURE
;
146 cred
= (gsskrb5_cred
)*cred_handle
;
148 if ((value
->length
% 4) != 0) {
150 major_stat
= GSS_S_FAILURE
;
154 len
= value
->length
/ 4;
155 enctypes
= malloc((len
+ 1) * 4);
156 if (enctypes
== NULL
) {
157 *minor_status
= ENOMEM
;
158 major_stat
= GSS_S_FAILURE
;
162 sp
= krb5_storage_from_mem(value
->value
, value
->length
);
164 *minor_status
= ENOMEM
;
165 major_stat
= GSS_S_FAILURE
;
169 for (i
= 0; i
< len
; i
++) {
172 ret
= krb5_ret_uint32(sp
, &e
);
175 major_stat
= GSS_S_FAILURE
;
183 free(cred
->enctypes
);
184 cred
->enctypes
= enctypes
;
186 krb5_storage_free(sp
);
188 return GSS_S_COMPLETE
;
192 krb5_storage_free(sp
);
200 no_ci_flags(OM_uint32
*minor_status
,
201 krb5_context context
,
202 gss_cred_id_t
*cred_handle
,
203 const gss_buffer_t value
)
207 if (cred_handle
== NULL
|| *cred_handle
== GSS_C_NO_CREDENTIAL
) {
209 return GSS_S_FAILURE
;
212 cred
= (gsskrb5_cred
)*cred_handle
;
213 cred
->cred_flags
|= GSS_CF_NO_CI_FLAGS
;
216 return GSS_S_COMPLETE
;
221 OM_uint32 GSSAPI_CALLCONV
222 _gsskrb5_set_cred_option
223 (OM_uint32
*minor_status
,
224 gss_cred_id_t
*cred_handle
,
225 const gss_OID desired_object
,
226 const gss_buffer_t value
)
228 krb5_context context
;
230 GSSAPI_KRB5_INIT (&context
);
232 if (value
== GSS_C_NO_BUFFER
) {
233 *minor_status
= EINVAL
;
234 return GSS_S_FAILURE
;
237 if (gss_oid_equal(desired_object
, GSS_KRB5_IMPORT_CRED_X
))
238 return import_cred(minor_status
, context
, cred_handle
, value
);
240 if (gss_oid_equal(desired_object
, GSS_KRB5_SET_ALLOWABLE_ENCTYPES_X
))
241 return allowed_enctypes(minor_status
, context
, cred_handle
, value
);
243 if (gss_oid_equal(desired_object
, GSS_KRB5_CRED_NO_CI_FLAGS_X
)) {
244 return no_ci_flags(minor_status
, context
, cred_handle
, value
);
248 *minor_status
= EINVAL
;
249 return GSS_S_FAILURE
;