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"
36 import_cred(OM_uint32
*minor_status
,
38 gss_cred_id_t
*cred_handle
,
39 const gss_buffer_t value
)
43 krb5_principal keytab_principal
= NULL
;
44 krb5_keytab keytab
= NULL
;
45 krb5_storage
*sp
= NULL
;
46 krb5_ccache id
= NULL
;
49 if (cred_handle
== NULL
|| *cred_handle
!= GSS_C_NO_CREDENTIAL
) {
54 sp
= krb5_storage_from_mem(value
->value
, value
->length
);
60 /* credential cache name */
61 ret
= krb5_ret_string(sp
, &str
);
64 major_stat
= GSS_S_FAILURE
;
68 ret
= krb5_cc_resolve(context
, str
, &id
);
71 major_stat
= GSS_S_FAILURE
;
78 /* keytab principal name */
79 ret
= krb5_ret_string(sp
, &str
);
80 if (ret
== 0 && str
[0])
81 ret
= krb5_parse_name(context
, str
, &keytab_principal
);
84 major_stat
= GSS_S_FAILURE
;
90 /* keytab principal */
91 ret
= krb5_ret_string(sp
, &str
);
94 major_stat
= GSS_S_FAILURE
;
98 ret
= krb5_kt_resolve(context
, str
, &keytab
);
101 major_stat
= GSS_S_FAILURE
;
108 major_stat
= _gsskrb5_krb5_import_cred(minor_status
, id
, keytab_principal
,
109 keytab
, cred_handle
);
112 krb5_cc_close(context
, id
);
113 if (keytab_principal
)
114 krb5_free_principal(context
, keytab_principal
);
116 krb5_kt_close(context
, keytab
);
120 krb5_storage_free(sp
);
127 allowed_enctypes(OM_uint32
*minor_status
,
128 krb5_context context
,
129 gss_cred_id_t
*cred_handle
,
130 const gss_buffer_t value
)
132 OM_uint32 major_stat
;
135 krb5_enctype
*enctypes
= NULL
;
136 krb5_storage
*sp
= NULL
;
139 if (cred_handle
== NULL
|| *cred_handle
== GSS_C_NO_CREDENTIAL
) {
141 return GSS_S_FAILURE
;
144 cred
= (gsskrb5_cred
)*cred_handle
;
146 if ((value
->length
% 4) != 0) {
148 major_stat
= GSS_S_FAILURE
;
152 len
= value
->length
/ 4;
153 enctypes
= malloc((len
+ 1) * 4);
154 if (enctypes
== NULL
) {
155 *minor_status
= ENOMEM
;
156 major_stat
= GSS_S_FAILURE
;
160 sp
= krb5_storage_from_mem(value
->value
, value
->length
);
162 *minor_status
= ENOMEM
;
163 major_stat
= GSS_S_FAILURE
;
167 for (i
= 0; i
< len
; i
++) {
170 ret
= krb5_ret_uint32(sp
, &e
);
173 major_stat
= GSS_S_FAILURE
;
181 free(cred
->enctypes
);
182 cred
->enctypes
= enctypes
;
184 krb5_storage_free(sp
);
186 return GSS_S_COMPLETE
;
190 krb5_storage_free(sp
);
198 no_ci_flags(OM_uint32
*minor_status
,
199 krb5_context context
,
200 gss_cred_id_t
*cred_handle
,
201 const gss_buffer_t value
)
205 if (cred_handle
== NULL
|| *cred_handle
== GSS_C_NO_CREDENTIAL
) {
207 return GSS_S_FAILURE
;
210 cred
= (gsskrb5_cred
)*cred_handle
;
211 cred
->cred_flags
|= GSS_CF_NO_CI_FLAGS
;
214 return GSS_S_COMPLETE
;
219 OM_uint32 GSSAPI_CALLCONV
220 _gsskrb5_set_cred_option
221 (OM_uint32
*minor_status
,
222 gss_cred_id_t
*cred_handle
,
223 const gss_OID desired_object
,
224 const gss_buffer_t value
)
226 krb5_context context
;
228 GSSAPI_KRB5_INIT (&context
);
230 if (value
== GSS_C_NO_BUFFER
) {
231 *minor_status
= EINVAL
;
232 return GSS_S_FAILURE
;
235 if (gss_oid_equal(desired_object
, GSS_KRB5_IMPORT_CRED_X
))
236 return import_cred(minor_status
, context
, cred_handle
, value
);
238 if (gss_oid_equal(desired_object
, GSS_KRB5_SET_ALLOWABLE_ENCTYPES_X
))
239 return allowed_enctypes(minor_status
, context
, cred_handle
, value
);
241 if (gss_oid_equal(desired_object
, GSS_KRB5_CRED_NO_CI_FLAGS_X
)) {
242 return no_ci_flags(minor_status
, context
, cred_handle
, value
);
246 *minor_status
= EINVAL
;
247 return GSS_S_FAILURE
;