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 "gsskrb5_locl.h"
35 /* 1.2.752.43.13.17 */
36 static gss_OID_desc gss_krb5_cred_no_ci_flags_x_oid_desc
=
37 {6, rk_UNCONST("\x2a\x85\x70\x2b\x0d\x11")};
39 gss_OID GSS_KRB5_CRED_NO_CI_FLAGS_X
= &gss_krb5_cred_no_ci_flags_x_oid_desc
;
41 /* 1.2.752.43.13.18 */
42 static gss_OID_desc gss_krb5_import_cred_x_oid_desc
=
43 {6, rk_UNCONST("\x2a\x85\x70\x2b\x0d\x12")};
45 gss_OID GSS_KRB5_IMPORT_CRED_X
= &gss_krb5_import_cred_x_oid_desc
;
50 import_cred(OM_uint32
*minor_status
,
52 gss_cred_id_t
*cred_handle
,
53 const gss_buffer_t value
)
57 krb5_principal keytab_principal
= NULL
;
58 krb5_keytab keytab
= NULL
;
59 krb5_storage
*sp
= NULL
;
60 krb5_ccache id
= NULL
;
63 if (cred_handle
== NULL
|| *cred_handle
!= GSS_C_NO_CREDENTIAL
) {
68 sp
= krb5_storage_from_mem(value
->value
, value
->length
);
74 /* credential cache name */
75 ret
= krb5_ret_string(sp
, &str
);
78 major_stat
= GSS_S_FAILURE
;
82 ret
= krb5_cc_resolve(context
, str
, &id
);
85 major_stat
= GSS_S_FAILURE
;
92 /* keytab principal name */
93 ret
= krb5_ret_string(sp
, &str
);
94 if (ret
== 0 && str
[0])
95 ret
= krb5_parse_name(context
, str
, &keytab_principal
);
98 major_stat
= GSS_S_FAILURE
;
104 /* keytab principal */
105 ret
= krb5_ret_string(sp
, &str
);
108 major_stat
= GSS_S_FAILURE
;
112 ret
= krb5_kt_resolve(context
, str
, &keytab
);
115 major_stat
= GSS_S_FAILURE
;
122 major_stat
= _gsskrb5_import_cred(minor_status
, id
, keytab_principal
,
123 keytab
, cred_handle
);
126 krb5_cc_close(context
, id
);
127 if (keytab_principal
)
128 krb5_free_principal(context
, keytab_principal
);
130 krb5_kt_close(context
, keytab
);
134 krb5_storage_free(sp
);
141 allowed_enctypes(OM_uint32
*minor_status
,
142 krb5_context context
,
143 gss_cred_id_t
*cred_handle
,
144 const gss_buffer_t value
)
146 OM_uint32 major_stat
;
149 krb5_enctype
*enctypes
= NULL
;
150 krb5_storage
*sp
= NULL
;
153 if (cred_handle
== NULL
|| *cred_handle
== GSS_C_NO_CREDENTIAL
) {
155 return GSS_S_FAILURE
;
158 cred
= (gsskrb5_cred
)*cred_handle
;
160 if ((value
->length
% 4) != 0) {
162 major_stat
= GSS_S_FAILURE
;
166 len
= value
->length
/ 4;
167 enctypes
= malloc((len
+ 1) * 4);
168 if (enctypes
== NULL
) {
169 *minor_status
= ENOMEM
;
170 major_stat
= GSS_S_FAILURE
;
174 sp
= krb5_storage_from_mem(value
->value
, value
->length
);
176 *minor_status
= ENOMEM
;
177 major_stat
= GSS_S_FAILURE
;
181 for (i
= 0; i
< len
; i
++) {
184 ret
= krb5_ret_uint32(sp
, &e
);
187 major_stat
= GSS_S_FAILURE
;
195 free(cred
->enctypes
);
196 cred
->enctypes
= enctypes
;
198 krb5_storage_free(sp
);
200 return GSS_S_COMPLETE
;
204 krb5_storage_free(sp
);
212 no_ci_flags(OM_uint32
*minor_status
,
213 krb5_context context
,
214 gss_cred_id_t
*cred_handle
,
215 const gss_buffer_t value
)
219 if (cred_handle
== NULL
|| *cred_handle
== GSS_C_NO_CREDENTIAL
) {
221 return GSS_S_FAILURE
;
224 cred
= (gsskrb5_cred
)*cred_handle
;
225 cred
->cred_flags
|= GSS_CF_NO_CI_FLAGS
;
228 return GSS_S_COMPLETE
;
234 _gsskrb5_set_cred_option
235 (OM_uint32
*minor_status
,
236 gss_cred_id_t
*cred_handle
,
237 const gss_OID desired_object
,
238 const gss_buffer_t value
)
240 krb5_context context
;
242 GSSAPI_KRB5_INIT (&context
);
244 if (value
== GSS_C_NO_BUFFER
) {
245 *minor_status
= EINVAL
;
246 return GSS_S_FAILURE
;
249 if (gss_oid_equal(desired_object
, GSS_KRB5_IMPORT_CRED_X
))
250 return import_cred(minor_status
, context
, cred_handle
, value
);
252 if (gss_oid_equal(desired_object
, GSS_KRB5_SET_ALLOWABLE_ENCTYPES_X
))
253 return allowed_enctypes(minor_status
, context
, cred_handle
, value
);
255 if (gss_oid_equal(desired_object
, GSS_KRB5_CRED_NO_CI_FLAGS_X
)) {
256 return no_ci_flags(minor_status
, context
, cred_handle
, value
);
260 *minor_status
= EINVAL
;
261 return GSS_S_FAILURE
;