2 * Copyright (c) 2004, PADL Software Pty Ltd.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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
33 #include "krb5/gsskrb5_locl.h"
37 /* 1.2.752.43.13.17 */
38 static gss_OID_desc gss_krb5_cred_no_ci_flags_x_oid_desc
=
39 {6, rk_UNCONST("\x2a\x85\x70\x2b\x0d\x11")};
41 gss_OID GSS_KRB5_CRED_NO_CI_FLAGS_X
= &gss_krb5_cred_no_ci_flags_x_oid_desc
;
43 /* 1.2.752.43.13.18 */
44 static gss_OID_desc gss_krb5_import_cred_x_oid_desc
=
45 {6, rk_UNCONST("\x2a\x85\x70\x2b\x0d\x12")};
47 gss_OID GSS_KRB5_IMPORT_CRED_X
= &gss_krb5_import_cred_x_oid_desc
;
52 import_cred(OM_uint32
*minor_status
,
54 gss_cred_id_t
*cred_handle
,
55 const gss_buffer_t value
)
59 krb5_principal keytab_principal
= NULL
;
60 krb5_keytab keytab
= NULL
;
61 krb5_storage
*sp
= NULL
;
62 krb5_ccache id
= NULL
;
65 if (cred_handle
== NULL
|| *cred_handle
!= GSS_C_NO_CREDENTIAL
) {
70 sp
= krb5_storage_from_mem(value
->value
, value
->length
);
76 /* credential cache name */
77 ret
= krb5_ret_string(sp
, &str
);
80 major_stat
= GSS_S_FAILURE
;
84 ret
= krb5_cc_resolve(context
, str
, &id
);
87 major_stat
= GSS_S_FAILURE
;
94 /* keytab principal name */
95 ret
= krb5_ret_string(sp
, &str
);
96 if (ret
== 0 && str
[0])
97 ret
= krb5_parse_name(context
, str
, &keytab_principal
);
100 major_stat
= GSS_S_FAILURE
;
106 /* keytab principal */
107 ret
= krb5_ret_string(sp
, &str
);
110 major_stat
= GSS_S_FAILURE
;
114 ret
= krb5_kt_resolve(context
, str
, &keytab
);
117 major_stat
= GSS_S_FAILURE
;
124 major_stat
= _gsskrb5_import_cred(minor_status
, id
, keytab_principal
,
125 keytab
, cred_handle
);
128 krb5_cc_close(context
, id
);
129 if (keytab_principal
)
130 krb5_free_principal(context
, keytab_principal
);
132 krb5_kt_close(context
, keytab
);
136 krb5_storage_free(sp
);
143 allowed_enctypes(OM_uint32
*minor_status
,
144 krb5_context context
,
145 gss_cred_id_t
*cred_handle
,
146 const gss_buffer_t value
)
148 OM_uint32 major_stat
;
151 krb5_enctype
*enctypes
= NULL
;
152 krb5_storage
*sp
= NULL
;
155 if (cred_handle
== NULL
|| *cred_handle
== GSS_C_NO_CREDENTIAL
) {
157 return GSS_S_FAILURE
;
160 cred
= (gsskrb5_cred
)*cred_handle
;
162 if ((value
->length
% 4) != 0) {
164 major_stat
= GSS_S_FAILURE
;
168 len
= value
->length
/ 4;
169 enctypes
= malloc((len
+ 1) * 4);
170 if (enctypes
== NULL
) {
171 *minor_status
= ENOMEM
;
172 major_stat
= GSS_S_FAILURE
;
176 sp
= krb5_storage_from_mem(value
->value
, value
->length
);
178 *minor_status
= ENOMEM
;
179 major_stat
= GSS_S_FAILURE
;
183 for (i
= 0; i
< len
; i
++) {
186 ret
= krb5_ret_uint32(sp
, &e
);
189 major_stat
= GSS_S_FAILURE
;
197 free(cred
->enctypes
);
198 cred
->enctypes
= enctypes
;
200 krb5_storage_free(sp
);
202 return GSS_S_COMPLETE
;
206 krb5_storage_free(sp
);
214 no_ci_flags(OM_uint32
*minor_status
,
215 krb5_context context
,
216 gss_cred_id_t
*cred_handle
,
217 const gss_buffer_t value
)
221 if (cred_handle
== NULL
|| *cred_handle
== GSS_C_NO_CREDENTIAL
) {
223 return GSS_S_FAILURE
;
226 cred
= (gsskrb5_cred
)*cred_handle
;
227 cred
->cred_flags
|= GSS_CF_NO_CI_FLAGS
;
230 return GSS_S_COMPLETE
;
236 _gsskrb5_set_cred_option
237 (OM_uint32
*minor_status
,
238 gss_cred_id_t
*cred_handle
,
239 const gss_OID desired_object
,
240 const gss_buffer_t value
)
242 krb5_context context
;
244 GSSAPI_KRB5_INIT (&context
);
246 if (value
== GSS_C_NO_BUFFER
) {
247 *minor_status
= EINVAL
;
248 return GSS_S_FAILURE
;
251 if (gss_oid_equal(desired_object
, GSS_KRB5_IMPORT_CRED_X
))
252 return import_cred(minor_status
, context
, cred_handle
, value
);
254 if (gss_oid_equal(desired_object
, GSS_KRB5_SET_ALLOWABLE_ENCTYPES_X
))
255 return allowed_enctypes(minor_status
, context
, cred_handle
, value
);
257 if (gss_oid_equal(desired_object
, GSS_KRB5_CRED_NO_CI_FLAGS_X
)) {
258 return no_ci_flags(minor_status
, context
, cred_handle
, value
);
262 *minor_status
= EINVAL
;
263 return GSS_S_FAILURE
;